详解Linux2.6内核中基于platform机制的驱动模型 (经典) (12)

该函数创建了一个名为 “platform”的设备,后续platform的设备都会以此为parent。在sysfs中表示为:所有platform类型的设备都会添加在 platform_bus所代表的目录下,即 /sys/devices/platform下面。
-sh-3.1# ls /sys/devices/platform/   
Fixed MDIO bus.0     fsl-i2c.0            serial8250
fsl-ehci.0           fsl-i2c.1            serial8250.0
fsl-gianfar.0        mpc83xx_spi.0        uevent
fsl-gianfar.1        mpc83xx_wdt.0
fsl-gianfar_mdio.-5  power

-sh-3.1# ls /sys/
block/    class/    firmware/ kernel/   power/    
bus/      devices/  fs/       module/   
-sh-3.1# ls /sys/bus/
i2c/         of_platform/ pci_express/ scsi/        usb/         
mdio_bus/    pci/         platform/    spi/         
-sh-3.1# ls /sys/bus/i2c/
devices/           drivers_autoprobe  uevent             
drivers/           drivers_probe   

-sh-3.1# ls /sys/bus/platform/devices/
Fixed MDIO bus.0/    fsl-gianfar_mdio.-5/ mpc83xx_wdt.0/
fsl-ehci.0/          fsl-i2c.0/           serial8250/
fsl-gianfar.0/       fsl-i2c.1/           serial8250.0/
fsl-gianfar.1/       mpc83xx_spi.0/       
-sh-3.1# ls /sys/bus/platform/drivers 
drivers/           drivers_autoprobe  drivers_probe      
-sh-3.1# ls /sys/bus/platform/drivers/
fsl-ehci/         fsl-gianfar_mdio/ mpc83xx_spi/      serial8250/
fsl-gianfar/      fsl-i2c/          mpc83xx_wdt/    

platform_bus必须在系统注册任何platform driver和platform device之前初始化,那么这是如何实现的呢?

14/**
  15 * driver_init - initialize driver model.
  16 *
  17 * Call the driver model init functions to initialize their
  18 * subsystems. Called early from init/main.c.
  19 */
  20void __init driver_init(void)
  21{
  22        /* These are the core pieces */
  23        devices_init();
  24        buses_init();
  25        classes_init();
  26        firmware_init();
  27        hypervisor_init();
  28
  29        /* These are also core pieces, but must come after the
  30         * core core pieces.
  31         */
  32        platform_bus_init();
  33        system_bus_init();
  34        cpu_dev_init();
  35        memory_dev_init();
  36}

init/main.c
start_kernel  》 rest_init  》 kernel_init  》 do_basic_setup》driver_init 》platform_bus_init


724/*
 725 * Ok, the machine is now initialized. None of the devices
 726 * have been touched yet, but the CPU subsystem is up and
 727 * running, and memory and process management works.
 728 *
 729 * Now we can finally start doing some real work..
 730 */
 731static void __init do_basic_setup(void)
 732{
 733        /* drivers will send hotplug events */
 734        init_workqueues();
 735        usermodehelper_init();
 736        driver_init();
 737        init_irq_proc();
 738        do_initcalls();
 739}

platform driver和platform device的初始化是在do_initcalls中进行的。

8.2    定义platform_device
中定义了系统的资源,是一个高度可移植的文件,大部分板级资源都在这里集中定义。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwjjds.html