除了註冊裝置的程式碼是無效的註解外,
GPIO 腳位定義不對,
但是改完後還是沒出現該有的裝置。
原因可能是在手動加入的 kernel .config 項目被自動刪除。
還不能動的原始碼另開一個 branch https://github.com/rexct/kernel-pdk7105/tree/leds
最後加映可能是加上 fdma 韌體、加入編譯參數 CFLAGS="-m4a -pipe -O3 -ffast-math" 以及更新 cross-compile 環境到 2013/11/03 時,
對執行速度的影響。
以 Documentation/gpio.txt 中的關鍵字 leds-gpio 找到下面兩篇:
1. GPIO LEDS - ArmadeusWiki
2. android 使用 linux LED driver 來控制GPIO 的LED行為 | 易春木
在 連結1 有指出要選擇的 menuconfig 項目
Device Drivers
LED support
LED Class Support
LED Support for GPIO connected LEDs
Platform device bindings for GPIO LEDs
要支援相關的 trigger 模式:
Device Drivers
LED support
LED Trigger support
LED Timer Trigger
LED Heartbeat Trigger
LED backlight Trigger
LED Default ON Trigger
之後把 arch/sh/boards/mach-pdk7105/setup.c 中定義的GPIO腳位修正,
並參考兩個連結內容及補齊可以控制的項目
static struct platform_device pdk7105_leds = {
.name = "leds-gpio",
.id = 0,
.dev.platform_data = &(struct gpio_led_platform_data) {
.num_leds = 2,
.leds = (struct gpio_led[]) {
{
.name = "LD5",
.default_trigger = "heartbeat",
.gpio = stm_gpio(0, 4), //stpio_to_gpio(2, 4),
.active_low=1,
.retain_state_suspended = 1,
.default_state = 0, /* 0:on 1:off 2:keep */
},
{
.name = "LD6",
.default_trigger = "ide-disk",
.gpio = stm_gpio(0, 5), //stpio_to_gpio(2, 3),
.active_low = 1, .retain_state_suspended = 1, .default_state = 1, /* 0:on 1:off 2:keep */
},
},
},
};
追程式碼到 include/linux/leds.h 可以在142行看到預設及可用變數:
* For the leds-gpio driver */
struct gpio_led {
const char *name;
const char *default_trigger;
unsigned gpio;
unsigned active_low : 1;
unsigned retain_state_suspended : 1;
unsigned default_state : 2;
/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
};
#define LEDS_GPIO_DEFSTATE_OFF 0
#define LEDS_GPIO_DEFSTATE_ON 1
#define LEDS_GPIO_DEFSTATE_KEEP 2
default_state 依照原本的網樂通狀態設定藍燈亮(0),紅燈熄(1)
retain_state_suspended 設定1 讓 suspend 時不會以為關機斷電了。
default_trigger 設定成 heartbeat 可以隨著cpu使用率閃爍,
設定成 ide-disk 希望能知道磁碟讀取狀態,
這樣就可以清楚了解什時候開機完成了。
問題在於程式寫完後,
找不到上面列出的 menuconfig 項目:
LED Support for GPIO connected LEDs
Platform device bindings for GPIO LEDs
第一個連結中有以下這行:
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
就自行在 .config 中加入 CONFIG_LEDS_GPIO=y
結果編譯時被自動刪除。
用 使用Linux内核自带的GPIO 按键驱动 - [凌云嵌入式] - 嵌入式新手入门区 - 嵌入式开发联盟 中寫的方式找 CONFIG_LEDS_GPIO 有相關的檔案:
$find `pwd` -type f |xargs grep CONFIG_LEDS_GPIO
找到有 drivers/leds/leds-gpio.c 這個檔案,
可是卻在編譯時沒有編成 leds-gpio.o 。
定義是否要編譯 leds-gpio.o 的檔案是 drivers/leds/Makefile
obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
之後的方向可以先從把drivers/leds/Makefile 中 CONFIG_LEDS_GPIO 改成 CONFIG_KEYBOARD_GPIO,
借用這個設定來驗證 platfrom device 的 LED 。
再來找如何正確加入 CONFIG_LEDS_GPIO。
另外可能還有相關的定義是CONFIG_LEDS_GPIO_PLATFORM。
因為這次陸續編了不少測試用kernel,
而且還有更新cross-compile 的環境,
附上使用 php-bench mark 的測試數據:
不確定是否因為沒重編 modules 使得不正確的 modules 拖慢系統,
依結果看來是加fdma韌體後變慢,
採用CFLAGS="-m4a -pipe -O3 -ffast-math"最佳化編譯後有快約1%,
更新cross-compile 環境到 2013/11/13 後變慢。
比較基準 stlinux24 cross-compile 環境第一版最小ISO安裝編譯出的kernel
<pre>--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2013-11-05 13:38:06
Server : @
PHP version : 5.5.1
Platform : Linux
--------------------------------------
test_math : 57.494 sec.
test_stringmanipulation : 57.052 sec.
test_loops : 22.253 sec.
test_ifelse : 13.611 sec.
--------------------------------------
Total time: : 150.41 sec.
同第一個 stlinux24 環境,增加 fdma 韌體
<pre>--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2013-11-05 13:59:05
Server : @
PHP version : 5.5.1
Platform : Linux
--------------------------------------
test_math : 60.304 sec.
test_stringmanipulation : 58.822 sec.
test_loops : 22.238 sec.
test_ifelse : 13.595 sec.
--------------------------------------
Total time: : 154.959 sec.
同第一個 stlinux24 環境,增加 fdma 韌體,
增加編譯參數 CFLAGS="-m4a -pipe -O3 -ffast-math"
<pre>--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2013-11-05 14:18:59
Server : @
PHP version : 5.5.1
Platform : Linux
--------------------------------------
test_math : 59.955 sec.
test_stringmanipulation : 57.736 sec.
test_loops : 22.304 sec.
test_ifelse : 13.654 sec.
--------------------------------------
Total time: : 153.649 sec.
更新 stlinux24 cross-compile 環境到 2013/11/03 ,增加fdma韌體,
增加編譯參數 CFLAGS="-m4a -pipe -O3 -ffast-math"
<pre>--------------------------------------
| PHP BENCHMARK SCRIPT |
--------------------------------------
Start : 2013-11-05 13:14:48
Server : @
PHP version : 5.5.1
Platform : Linux
--------------------------------------
test_math : 63.694 sec.
test_stringmanipulation : 61.918 sec.
test_loops : 25.014 sec.
test_ifelse : 14.150 sec.
--------------------------------------
Total time: : 164.776 sec.</pre>
沒有留言:
張貼留言