model)之平台总线(bus),驱动(driver),设备((4)

1 static int platform_match(struct device * dev, struct device_driver * drv) 2 { 3 struct platform_device *pdev = container_of(dev, struct platform_device, dev); 4 5 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 6 }

platform_device->name == platform_driver->driver->name 即他们的名字就是:“gpio-keys”

一旦匹配,就会调用

static int platform_drv_probe(struct device *_dev)
{
    struct platform_driver *drv = to_platform_driver(_dev->driver);
    struct platform_device *dev = to_platform_device(_dev);

return drv->probe(dev);
}

drv->probe() = platform_driver->probe() = gpio_keys_probe()

这样平台驱动(platform_driver)就可以获得平台设备(platform_device)的 struct platform_device结构的数据了,即keys_platform_dev,从这个结构就可以获得相关配置,以使能平台驱动(platform_driver) gpio_keys.c中相应的IO和中断。

实验现象:

# insmod gpio_keys.ko //安装平台驱动(platform_driver) # insmod keys_dev.ko //安装平台设备(platform_device) input: gpio-keys as /class/input/input1 # ./platform_test //运行应用测试程序 Ver:0x10000 //用ioctl获取输入子系统的版本号 type: 0x1 code: 0x2e value: 0x1 //按下"C"键 type: 0x0 code: 0x0 value: 0x0 //因为调用了input_sync() type: 0x1 code: 0x2e value: 0x0 //松开(弹起)"C"键 type: 0x0 code: 0x0 value: 0x0 //因为调用了input_sync() type: 0x1 code: 0x30 value: 0x1 //... ... type: 0x0 code: 0x0 value: 0x0 type: 0x1 code: 0x30 value: 0x0 type: 0x0 code: 0x0 value: 0x0 type: 0x1 code: 0x1e value: 0x1 type: 0x0 code: 0x0 value: 0x0 type: 0x1 code: 0x1e value: 0x0 type: 0x0 code: 0x0 value: 0x0 type: 0x1 code: 0x20 value: 0x1 type: 0x0 code: 0x0 value: 0x0 type: 0x1 code: 0x20 value: 0x0 type: 0x0 code: 0x0 value: 0x0 time out time out time out

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

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