linux: platform 裝置的註冊__linux

來源:互聯網
上載者:User
platform device註冊順序

在linux2.6裝置模型中,關心匯流排,裝置,驅動這三個實體,匯流排將裝置和驅動綁定,在系統每註冊一個裝置的時候,會尋找與之匹配的驅動。相反,在系統每註冊一個驅動的時候,尋找與之匹配的裝置,匹配是由匯流排來完成的。 

 

一個現實的Linux 裝置和驅動通常都需要掛接在一種匯流排上,對於本身依附於PCI、USB、I2C、SPI 等的裝置而言,這自然不是問題,但是在嵌入式系統裡面,SoC 系統中整合的獨立的外設控制器、掛接在SoC 記憶體空間的外設等確不依附於此類匯流排。基於這一背景,Linux 發明了一種虛擬匯流排,稱為platform 匯流排。SOC系統中整合的獨立外設單元(LCD,RTC,WDT等)都被當作平台裝置來處理,而它們本身是字元型裝置。

 

platform_driver_register(struct platform_driver *drv) --> driver_register(struct device_driver *drv) --> bus_add_driver(struct device_driver *drv)

  一. 平台裝置struct platform_device

以omap4430為例:kernel/arch/arm/mach-omap2/board-4430sdp.c

static struct platform_device sdp4430_disp_led = {
 .name = "display_led",
 .id = -1,
 .dev = {
  .platform_data = &sdp4430_disp_led_data,
 },
};

 

struct platform_device nec_infrared_remote = {
        .name           = "infrared-gpio",
        .id             = -1,
};

向系統添加platform device裝置:

platform_add_devices(struct platform_device **devs, int num);

  二. 平台驅動struct platform_driver

kernel/drivers/input/iabox-ir.c:

static struct platform_driver infrared_gpio_driver = {
    .probe      = infrared_gpio_probe,
    .remove     = infrared_gpio_remove,
    .suspend    = infrared_gpio_suspend,
    .resume     = infrared_gpio_resume,
    .driver     = {
        .owner  = THIS_MODULE,
        .name   = "infrared-gpio",
    },
};

 

驅動的註冊:

static int __init infrared_receiver_init(void)
{
  int ret;
 
  ret = platform_driver_register( &infrared_gpio_driver);
 
  if(!ret)
      printk(KERN_INFO"infrared gpio receiver driver\n");
     
   return ret;
}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.