linux 板级文件信息的注册流程

来源:互联网 发布:elise兔兔的淘宝店 编辑:程序博客网 时间:2024/05/30 05:00
作为驱动工程师,板级信息的注册再常见不过了,因其简单,都不屑于去分析,闲来无事跟踪一下这些简单的代码。

1.bluetooth资源结构体

static struct mt6622_platform_data mt6622_platdata = {
    .power_gpio         = { // BT_REG_ON
        .io             = RK30_PIN3_PC7, // set io to INVALID_GPIO for disable it
        .enable         = GPIO_HIGH,
        .iomux          = {
            .name       = NULL,
        },
    },

    .reset_gpio         = { // BT_RST
        .io             = RK30_PIN3_PD1,
        .enable         = GPIO_LOW,
        .iomux          = {
            .name       = NULL,
        },
    },


    .irq_gpio           = {
        .io             = RK30_PIN6_PA7,
        .enable         = GPIO_HIGH,
        .iomux          = {
            .name       = NULL,
        },
    }
};

2.bluetooth资源结构体作为platform设备的私有数据

static struct platform_device device_mt6622 = {
    .name   = "mt6622",
    .id     = -1,
    .dev    = {
        .platform_data = &mt6622_platdata,
    },
};

3.platform设备结构体体填充platform结构体数组以备统一注册

devices结构体数组:

static struct platform_device *devices[] __initdata = {
&rk29_device_backlight,
&device_fb,
&device_ion,
&rk29_device_vibrator,
&rk29_device_gpio_leds,
&irda_device,
&rk29sdk_wifi_device,
&rk30_device_modem,
&rk29_device_mu509,
&rk29_device_mw100,
&rk29_device_mt6229,
&rk30_device_sew868,
  &rk30_device_adc_battery,
&device_rfkill_rk,
&device_mt6622,
&pwm_regulator_device[0],
};


4.在板级初始化函数中统一注册platform device结构体

static void __init machine_rk30_board_init(void)

{
.........................

//申请电源启动引脚,如果被占用会申请失败

gpio_request(POWER_ON_PIN, "poweronpin");  

//设置电源引脚为输出引脚

gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);

//给电源管理的系统关闭函数赋函数指针

pm_power_off = rk30_pm_power_off;

//注册I2C的板及信息

rk30_i2c_register_board_info();

//注册SPI的板级信息

spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));

//注册platform的板级信息

platform_add_devices(devices, ARRAY_SIZE(devices));

//初始化USB的检测引脚

board_usb_detect_init(RK30_PIN6_PA3);

.................................

}

 ARRAY_SIZE(x)  //计算数组中有多少个数组成员

原型:#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))


5.板级设备函数被赋值给struct machine_desc以备在板子启动时候调用该注册函数

struct machine_desc被放置在__section__(".arch.info.init")段,kernel启动的起来之后将被抛弃。

如下:

MACHINE_START(RK30, "RK30board")
.boot_params = PLAT_PHYS_OFFSET + 0x800,
.fixup = rk30_fixup,
.reserve = &rk30_reserve,
.map_io = rk30_map_io,
.init_irq = rk30_init_irq,
.timer = &rk30_timer,
.init_machine = machine_rk30_board_init,
MACHINE_END