Linux bt gamepad 连接流程
3.4.x 内核
HIDP(net/bluetooth/hidp)
此目录下的文件:
— core.c
— sock.c
core.c 中init:
1198static const struct hid_device_id hidp_table[] = {
1199 { HID_BLUETOOTH_DEVICE(HID_ANY_ID, HID_ANY_ID) },
1200 { }
1201};
1203static struct hid_driver hidp_driver = {
1204 .name = "generic-bluetooth",
1205 .id_table = hidp_table,
1206};
1207
1208static int __init hidp_init(void)
1209{
1210 int ret;
1211
1212 BT_INFO("HIDP (Human Interface Emulation) ver %s", VERSION);
1213
1214 ret = hid_register_driver(&hidp_driver);
1215 if (ret)
1216 goto err;
1217
1218 ret = hidp_init_sockets();
1219 if (ret)
1220 goto err_drv;
1221
1222 return 0;
1223err_drv:
1224 hid_unregister_driver(&hidp_driver);
1225err:
1226 return ret;
1227}
注册的hidp_driver 中只有一个id table,没有对应的probe等函数。
按照hid_register_driver() 继续,在include/linux/hid.h 中
723#define hid_register_driver(driver) \
724 __hid_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
725
定义在/drivers/hid/hid-core.c
2161int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
2162 const char *mod_name)
2163{
2164 int ret;
2165
2166 hdrv->driver.name = hdrv->name;
2167 hdrv->driver.bus = &hid_bus_type;
2168 hdrv->driver.owner = owner;
2169 hdrv->driver.mod_name = mod_name;
2170
2171 INIT_LIST_HEAD(&hdrv->dyn_list);
2172 spin_lock_init(&hdrv->dyn_lock);
2173
2174 ret = driver_register(&hdrv->driver);
bluetooth hidp重新作为hid driver包装,并指定bus类型为hid_bus_type
1778static struct bus_type hid_bus_type = {
1779 .name = "hid",
1780 .match = hid_bus_match,
1781 .probe = hid_device_probe,
1782 .remove = hid_device_remove,
1783 .uevent = hid_uevent,
1784};
1785
probe 函数:
1696static int hid_device_probe(struct device *dev)
1697{
...
1717 hdev->driver = hdrv;
1718 if (hdrv->probe) {
1719 ret = hdrv->probe(hdev, id);
1720 } else { /* default probe */
1721 ret = hid_parse(hdev);
1722 if (!ret)
1723 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1724 }
...
没有定义probe 函数,因此走hid_parse 和 hid_hw_start(进行connect-add设备节点):
/include/linux/hid.h
834static inline int __must_check hid_hw_start(struct hid_device *hdev,
835 unsigned int connect_mask)
836{
837 int ret = hdev->ll_driver->start(hdev);
838 if (ret || !connect_mask)
839 return ret;
840 ret = hid_connect(hdev, connect_mask);
841 if (ret)
842 hdev->ll_driver->stop(hdev);
843 return ret;
844}
845
/drivers/hid/hid-core.c
经过hid_connect 之后, 设备节点会被创建:
1213int