關於使用platform和file_operations開發驅動的不同

來源:互聯網
上載者:User

最近在看2.6.22核心中內建的led驅動,使用platform的方式寫的,platform的裝置和驅動匹配的過程可以在網上找到資料。通過對platform驅動架構的瞭解能夠知道整個led的驅動的入口函數是leds_s3c24xx.c中的s3c24xx_led_probe函數,可是翻遍了整個檔案都沒有看到有定義file_operations結構體,那麼就產生了如何使用這個驅動的疑問。翻了很多資料都沒有找到答案,在這個地方看到了一個博文,可以看到使用方法。http://blog.chinaunix.net/space.php?uid=20723576&do=blog&id=1887064

 

為了翻查方便,先轉過來。

 

在 menuconfig 裡必須選取
Device Driver --->
[*] LED Support --->
[*] LED Trigger support

在 LED 設定的 struct 中,有一個變數為 def_trigger

表示控制 led 的名稱

static struct s3c24xx_led_platdata smdk_pdata_led_blue = {

.gpio = S3C2410_GPB1,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-blue",
.def_trigger = "nand-disk",
}

表示控制 LED 藍燈的名稱是 "nand-disk"

在 linxu/drivers/mtd/nand/nand_base.c
註冊: led_trigger_register_simple("nand-disk", &nand_led_trigger);

取消註冊: led_trigger_unregister_simple(nand_led_trigger);

控制: led_trigger_event(nand_led_trigger, LED_FULL);


現在 只要對 nand flash 操作,藍燈就會亮

在 linux/drivers/leds/leds-s3c24xx.c 中

會呼叫
static void s3c24xx_led_set(struct led_classdev *led_cdev, enum led_brightness value)

{
struct s3c24xx_gpio_led *led = to_gpio(led_cdev);
struct s3c24xx_led_platdata *pd = led->pdata;

/* there will be a short delay between setting the output and

* going from output to input when using tristate. */

s3c2410_gpio_setpin(pd->gpio, (value ? 1 : 0) ^(pd->flags & S3C24XX_LEDF_ACTLOW));

if (pd->flags & S3C24XX_LEDF_TRISTATE)
s3c2410_gpio_cfgpin(pd->gpio,value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT);

}

從這個例子大概可以看出來,核心開發人員為led的驅動重新開發了一個小架構,提供了一個介面led_trigger_register_simple給上層調用。具體的過程還需要進一步研究。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.