onboard_usb_dev.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for onboard USB devices
  4. *
  5. * Copyright (c) 2022, Google LLC
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/device.h>
  9. #include <linux/export.h>
  10. #include <linux/err.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/init.h>
  13. #include <linux/i2c.h>
  14. #include <linux/kernel.h>
  15. #include <linux/list.h>
  16. #include <linux/module.h>
  17. #include <linux/mutex.h>
  18. #include <linux/of.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/slab.h>
  23. #include <linux/suspend.h>
  24. #include <linux/sysfs.h>
  25. #include <linux/usb.h>
  26. #include <linux/usb/hcd.h>
  27. #include <linux/usb/onboard_dev.h>
  28. #include <linux/workqueue.h>
  29. #include "onboard_usb_dev.h"
  30. /* USB5744 register offset and mask */
  31. #define USB5744_CMD_ATTACH 0xAA
  32. #define USB5744_CMD_ATTACH_LSB 0x56
  33. #define USB5744_CMD_CREG_ACCESS 0x99
  34. #define USB5744_CMD_CREG_ACCESS_LSB 0x37
  35. #define USB5744_CREG_MEM_ADDR 0x00
  36. #define USB5744_CREG_MEM_RD_ADDR 0x04
  37. #define USB5744_CREG_WRITE 0x00
  38. #define USB5744_CREG_READ 0x01
  39. #define USB5744_CREG_RUNTIMEFLAGS2 0x411D
  40. #define USB5744_CREG_BYPASS_UDC_SUSPEND BIT(3)
  41. static void onboard_dev_attach_usb_driver(struct work_struct *work);
  42. static struct usb_device_driver onboard_dev_usbdev_driver;
  43. static DECLARE_WORK(attach_usb_driver_work, onboard_dev_attach_usb_driver);
  44. /************************** Platform driver **************************/
  45. struct usbdev_node {
  46. struct usb_device *udev;
  47. struct list_head list;
  48. };
  49. struct onboard_dev {
  50. struct regulator_bulk_data supplies[MAX_SUPPLIES];
  51. struct device *dev;
  52. const struct onboard_dev_pdata *pdata;
  53. struct gpio_desc *reset_gpio;
  54. bool always_powered_in_suspend;
  55. bool is_powered_on;
  56. bool going_away;
  57. struct list_head udev_list;
  58. struct mutex lock;
  59. struct clk *clk;
  60. };
  61. static int onboard_dev_get_regulators(struct onboard_dev *onboard_dev)
  62. {
  63. const char * const *supply_names = onboard_dev->pdata->supply_names;
  64. unsigned int num_supplies = onboard_dev->pdata->num_supplies;
  65. struct device *dev = onboard_dev->dev;
  66. unsigned int i;
  67. int err;
  68. if (num_supplies > MAX_SUPPLIES)
  69. return dev_err_probe(dev, -EINVAL, "max %d supplies supported!\n",
  70. MAX_SUPPLIES);
  71. for (i = 0; i < num_supplies; i++)
  72. onboard_dev->supplies[i].supply = supply_names[i];
  73. err = devm_regulator_bulk_get(dev, num_supplies, onboard_dev->supplies);
  74. if (err)
  75. dev_err(dev, "Failed to get regulator supplies: %pe\n",
  76. ERR_PTR(err));
  77. return err;
  78. }
  79. static int onboard_dev_power_on(struct onboard_dev *onboard_dev)
  80. {
  81. int err;
  82. err = clk_prepare_enable(onboard_dev->clk);
  83. if (err) {
  84. dev_err(onboard_dev->dev, "failed to enable clock: %pe\n",
  85. ERR_PTR(err));
  86. return err;
  87. }
  88. err = regulator_bulk_enable(onboard_dev->pdata->num_supplies,
  89. onboard_dev->supplies);
  90. if (err) {
  91. dev_err(onboard_dev->dev, "failed to enable supplies: %pe\n",
  92. ERR_PTR(err));
  93. goto disable_clk;
  94. }
  95. fsleep(onboard_dev->pdata->reset_us);
  96. gpiod_set_value_cansleep(onboard_dev->reset_gpio, 0);
  97. fsleep(onboard_dev->pdata->power_on_delay_us);
  98. onboard_dev->is_powered_on = true;
  99. return 0;
  100. disable_clk:
  101. clk_disable_unprepare(onboard_dev->clk);
  102. return err;
  103. }
  104. static int onboard_dev_power_off(struct onboard_dev *onboard_dev)
  105. {
  106. int err;
  107. gpiod_set_value_cansleep(onboard_dev->reset_gpio, 1);
  108. err = regulator_bulk_disable(onboard_dev->pdata->num_supplies,
  109. onboard_dev->supplies);
  110. if (err) {
  111. dev_err(onboard_dev->dev, "failed to disable supplies: %pe\n",
  112. ERR_PTR(err));
  113. return err;
  114. }
  115. clk_disable_unprepare(onboard_dev->clk);
  116. onboard_dev->is_powered_on = false;
  117. return 0;
  118. }
  119. static int __maybe_unused onboard_dev_suspend(struct device *dev)
  120. {
  121. struct onboard_dev *onboard_dev = dev_get_drvdata(dev);
  122. struct usbdev_node *node;
  123. bool power_off = true;
  124. if (onboard_dev->always_powered_in_suspend)
  125. return 0;
  126. mutex_lock(&onboard_dev->lock);
  127. list_for_each_entry(node, &onboard_dev->udev_list, list) {
  128. if (!device_may_wakeup(node->udev->bus->controller))
  129. continue;
  130. if (usb_wakeup_enabled_descendants(node->udev)) {
  131. power_off = false;
  132. break;
  133. }
  134. }
  135. mutex_unlock(&onboard_dev->lock);
  136. if (!power_off)
  137. return 0;
  138. return onboard_dev_power_off(onboard_dev);
  139. }
  140. static int __maybe_unused onboard_dev_resume(struct device *dev)
  141. {
  142. struct onboard_dev *onboard_dev = dev_get_drvdata(dev);
  143. if (onboard_dev->is_powered_on)
  144. return 0;
  145. return onboard_dev_power_on(onboard_dev);
  146. }
  147. static inline void get_udev_link_name(const struct usb_device *udev, char *buf,
  148. size_t size)
  149. {
  150. snprintf(buf, size, "usb_dev.%s", dev_name(&udev->dev));
  151. }
  152. static int onboard_dev_add_usbdev(struct onboard_dev *onboard_dev,
  153. struct usb_device *udev)
  154. {
  155. struct usbdev_node *node;
  156. char link_name[64];
  157. int err;
  158. mutex_lock(&onboard_dev->lock);
  159. if (onboard_dev->going_away) {
  160. err = -EINVAL;
  161. goto error;
  162. }
  163. node = kzalloc(sizeof(*node), GFP_KERNEL);
  164. if (!node) {
  165. err = -ENOMEM;
  166. goto error;
  167. }
  168. node->udev = udev;
  169. list_add(&node->list, &onboard_dev->udev_list);
  170. mutex_unlock(&onboard_dev->lock);
  171. get_udev_link_name(udev, link_name, sizeof(link_name));
  172. WARN_ON(sysfs_create_link(&onboard_dev->dev->kobj, &udev->dev.kobj,
  173. link_name));
  174. return 0;
  175. error:
  176. mutex_unlock(&onboard_dev->lock);
  177. return err;
  178. }
  179. static void onboard_dev_remove_usbdev(struct onboard_dev *onboard_dev,
  180. const struct usb_device *udev)
  181. {
  182. struct usbdev_node *node;
  183. char link_name[64];
  184. get_udev_link_name(udev, link_name, sizeof(link_name));
  185. sysfs_remove_link(&onboard_dev->dev->kobj, link_name);
  186. mutex_lock(&onboard_dev->lock);
  187. list_for_each_entry(node, &onboard_dev->udev_list, list) {
  188. if (node->udev == udev) {
  189. list_del(&node->list);
  190. kfree(node);
  191. break;
  192. }
  193. }
  194. mutex_unlock(&onboard_dev->lock);
  195. }
  196. static ssize_t always_powered_in_suspend_show(struct device *dev,
  197. struct device_attribute *attr,
  198. char *buf)
  199. {
  200. const struct onboard_dev *onboard_dev = dev_get_drvdata(dev);
  201. return sysfs_emit(buf, "%d\n", onboard_dev->always_powered_in_suspend);
  202. }
  203. static ssize_t always_powered_in_suspend_store(struct device *dev,
  204. struct device_attribute *attr,
  205. const char *buf, size_t count)
  206. {
  207. struct onboard_dev *onboard_dev = dev_get_drvdata(dev);
  208. bool val;
  209. int ret;
  210. ret = kstrtobool(buf, &val);
  211. if (ret < 0)
  212. return ret;
  213. onboard_dev->always_powered_in_suspend = val;
  214. return count;
  215. }
  216. static DEVICE_ATTR_RW(always_powered_in_suspend);
  217. static struct attribute *onboard_dev_attrs[] = {
  218. &dev_attr_always_powered_in_suspend.attr,
  219. NULL,
  220. };
  221. static umode_t onboard_dev_attrs_are_visible(struct kobject *kobj,
  222. struct attribute *attr,
  223. int n)
  224. {
  225. struct device *dev = kobj_to_dev(kobj);
  226. struct onboard_dev *onboard_dev = dev_get_drvdata(dev);
  227. if (attr == &dev_attr_always_powered_in_suspend.attr &&
  228. !onboard_dev->pdata->is_hub)
  229. return 0;
  230. return attr->mode;
  231. }
  232. static const struct attribute_group onboard_dev_group = {
  233. .is_visible = onboard_dev_attrs_are_visible,
  234. .attrs = onboard_dev_attrs,
  235. };
  236. __ATTRIBUTE_GROUPS(onboard_dev);
  237. static void onboard_dev_attach_usb_driver(struct work_struct *work)
  238. {
  239. int err;
  240. err = driver_attach(&onboard_dev_usbdev_driver.driver);
  241. if (err)
  242. pr_err("Failed to attach USB driver: %pe\n", ERR_PTR(err));
  243. }
  244. #if IS_ENABLED(CONFIG_USB_ONBOARD_DEV_USB5744)
  245. static int onboard_dev_5744_i2c_read_byte(struct i2c_client *client, u16 addr, u8 *data)
  246. {
  247. struct i2c_msg msg[2];
  248. u8 rd_buf[3];
  249. int ret;
  250. u8 wr_buf[7] = {0, USB5744_CREG_MEM_ADDR, 4,
  251. USB5744_CREG_READ, 1,
  252. addr >> 8 & 0xff,
  253. addr & 0xff};
  254. msg[0].addr = client->addr;
  255. msg[0].flags = 0;
  256. msg[0].len = sizeof(wr_buf);
  257. msg[0].buf = wr_buf;
  258. ret = i2c_transfer(client->adapter, msg, 1);
  259. if (ret < 0)
  260. return ret;
  261. wr_buf[0] = USB5744_CMD_CREG_ACCESS;
  262. wr_buf[1] = USB5744_CMD_CREG_ACCESS_LSB;
  263. wr_buf[2] = 0;
  264. msg[0].len = 3;
  265. ret = i2c_transfer(client->adapter, msg, 1);
  266. if (ret < 0)
  267. return ret;
  268. wr_buf[0] = 0;
  269. wr_buf[1] = USB5744_CREG_MEM_RD_ADDR;
  270. msg[0].len = 2;
  271. msg[1].addr = client->addr;
  272. msg[1].flags = I2C_M_RD;
  273. msg[1].len = 2;
  274. msg[1].buf = rd_buf;
  275. ret = i2c_transfer(client->adapter, msg, 2);
  276. if (ret < 0)
  277. return ret;
  278. *data = rd_buf[1];
  279. return 0;
  280. }
  281. static int onboard_dev_5744_i2c_write_byte(struct i2c_client *client, u16 addr, u8 data)
  282. {
  283. struct i2c_msg msg[2];
  284. int ret;
  285. u8 wr_buf[8] = {0, USB5744_CREG_MEM_ADDR, 5,
  286. USB5744_CREG_WRITE, 1,
  287. addr >> 8 & 0xff,
  288. addr & 0xff,
  289. data};
  290. msg[0].addr = client->addr;
  291. msg[0].flags = 0;
  292. msg[0].len = sizeof(wr_buf);
  293. msg[0].buf = wr_buf;
  294. ret = i2c_transfer(client->adapter, msg, 1);
  295. if (ret < 0)
  296. return ret;
  297. msg[0].len = 3;
  298. wr_buf[0] = USB5744_CMD_CREG_ACCESS;
  299. wr_buf[1] = USB5744_CMD_CREG_ACCESS_LSB;
  300. wr_buf[2] = 0;
  301. ret = i2c_transfer(client->adapter, msg, 1);
  302. if (ret < 0)
  303. return ret;
  304. return 0;
  305. }
  306. static int onboard_dev_5744_i2c_init(struct i2c_client *client)
  307. {
  308. struct device *dev = &client->dev;
  309. int ret;
  310. u8 reg;
  311. /*
  312. * Set BYPASS_UDC_SUSPEND bit to ensure MCU is always enabled
  313. * and ready to respond to SMBus runtime commands.
  314. * The command writes 5 bytes to memory and single data byte in
  315. * configuration register.
  316. */
  317. ret = onboard_dev_5744_i2c_read_byte(client,
  318. USB5744_CREG_RUNTIMEFLAGS2, &reg);
  319. if (ret)
  320. return dev_err_probe(dev, ret, "CREG_RUNTIMEFLAGS2 read failed\n");
  321. reg |= USB5744_CREG_BYPASS_UDC_SUSPEND;
  322. ret = onboard_dev_5744_i2c_write_byte(client,
  323. USB5744_CREG_RUNTIMEFLAGS2, reg);
  324. if (ret)
  325. return dev_err_probe(dev, ret, "BYPASS_UDC_SUSPEND bit configuration failed\n");
  326. /* Send SMBus command to boot hub. */
  327. ret = i2c_smbus_write_word_data(client, USB5744_CMD_ATTACH,
  328. USB5744_CMD_ATTACH_LSB);
  329. if (ret < 0)
  330. return dev_err_probe(dev, ret, "USB Attach with SMBus command failed\n");
  331. return ret;
  332. }
  333. #else
  334. static int onboard_dev_5744_i2c_init(struct i2c_client *client)
  335. {
  336. return -ENODEV;
  337. }
  338. #endif
  339. static int onboard_dev_probe(struct platform_device *pdev)
  340. {
  341. struct device *dev = &pdev->dev;
  342. struct onboard_dev *onboard_dev;
  343. struct device_node *i2c_node;
  344. int err;
  345. onboard_dev = devm_kzalloc(dev, sizeof(*onboard_dev), GFP_KERNEL);
  346. if (!onboard_dev)
  347. return -ENOMEM;
  348. onboard_dev->pdata = device_get_match_data(dev);
  349. if (!onboard_dev->pdata)
  350. return -EINVAL;
  351. if (!onboard_dev->pdata->is_hub)
  352. onboard_dev->always_powered_in_suspend = true;
  353. onboard_dev->dev = dev;
  354. err = onboard_dev_get_regulators(onboard_dev);
  355. if (err)
  356. return err;
  357. onboard_dev->clk = devm_clk_get_optional(dev, NULL);
  358. if (IS_ERR(onboard_dev->clk))
  359. return dev_err_probe(dev, PTR_ERR(onboard_dev->clk),
  360. "failed to get clock\n");
  361. onboard_dev->reset_gpio = devm_gpiod_get_optional(dev, "reset",
  362. GPIOD_OUT_HIGH);
  363. if (IS_ERR(onboard_dev->reset_gpio))
  364. return dev_err_probe(dev, PTR_ERR(onboard_dev->reset_gpio),
  365. "failed to get reset GPIO\n");
  366. mutex_init(&onboard_dev->lock);
  367. INIT_LIST_HEAD(&onboard_dev->udev_list);
  368. dev_set_drvdata(dev, onboard_dev);
  369. err = onboard_dev_power_on(onboard_dev);
  370. if (err)
  371. return err;
  372. i2c_node = of_parse_phandle(pdev->dev.of_node, "i2c-bus", 0);
  373. if (i2c_node) {
  374. struct i2c_client *client = NULL;
  375. #if IS_ENABLED(CONFIG_USB_ONBOARD_DEV_USB5744)
  376. client = of_find_i2c_device_by_node(i2c_node);
  377. #endif
  378. of_node_put(i2c_node);
  379. if (!client) {
  380. err = -EPROBE_DEFER;
  381. goto err_power_off;
  382. }
  383. if (of_device_is_compatible(pdev->dev.of_node, "usb424,2744") ||
  384. of_device_is_compatible(pdev->dev.of_node, "usb424,5744")) {
  385. err = onboard_dev_5744_i2c_init(client);
  386. onboard_dev->always_powered_in_suspend = true;
  387. }
  388. put_device(&client->dev);
  389. if (err < 0)
  390. goto err_power_off;
  391. }
  392. /*
  393. * The USB driver might have been detached from the USB devices by
  394. * onboard_dev_remove() (e.g. through an 'unbind' by userspace),
  395. * make sure to re-attach it if needed.
  396. *
  397. * This needs to be done deferred to avoid self-deadlocks on systems
  398. * with nested onboard hubs.
  399. */
  400. schedule_work(&attach_usb_driver_work);
  401. return 0;
  402. err_power_off:
  403. onboard_dev_power_off(onboard_dev);
  404. return err;
  405. }
  406. static void onboard_dev_remove(struct platform_device *pdev)
  407. {
  408. struct onboard_dev *onboard_dev = dev_get_drvdata(&pdev->dev);
  409. struct usbdev_node *node;
  410. struct usb_device *udev;
  411. onboard_dev->going_away = true;
  412. mutex_lock(&onboard_dev->lock);
  413. /* unbind the USB devices to avoid dangling references to this device */
  414. while (!list_empty(&onboard_dev->udev_list)) {
  415. node = list_first_entry(&onboard_dev->udev_list,
  416. struct usbdev_node, list);
  417. udev = node->udev;
  418. /*
  419. * Unbinding the driver will call onboard_dev_remove_usbdev(),
  420. * which acquires onboard_dev->lock. We must release the lock
  421. * first.
  422. */
  423. get_device(&udev->dev);
  424. mutex_unlock(&onboard_dev->lock);
  425. device_release_driver(&udev->dev);
  426. put_device(&udev->dev);
  427. mutex_lock(&onboard_dev->lock);
  428. }
  429. mutex_unlock(&onboard_dev->lock);
  430. onboard_dev_power_off(onboard_dev);
  431. }
  432. MODULE_DEVICE_TABLE(of, onboard_dev_match);
  433. static const struct dev_pm_ops __maybe_unused onboard_dev_pm_ops = {
  434. SET_LATE_SYSTEM_SLEEP_PM_OPS(onboard_dev_suspend, onboard_dev_resume)
  435. };
  436. static struct platform_driver onboard_dev_driver = {
  437. .probe = onboard_dev_probe,
  438. .remove_new = onboard_dev_remove,
  439. .driver = {
  440. .name = "onboard-usb-dev",
  441. .of_match_table = onboard_dev_match,
  442. .pm = pm_ptr(&onboard_dev_pm_ops),
  443. .dev_groups = onboard_dev_groups,
  444. },
  445. };
  446. /************************** USB driver **************************/
  447. #define VENDOR_ID_CYPRESS 0x04b4
  448. #define VENDOR_ID_GENESYS 0x05e3
  449. #define VENDOR_ID_MICROCHIP 0x0424
  450. #define VENDOR_ID_REALTEK 0x0bda
  451. #define VENDOR_ID_TI 0x0451
  452. #define VENDOR_ID_VIA 0x2109
  453. #define VENDOR_ID_XMOS 0x20B1
  454. /*
  455. * Returns the onboard_dev platform device that is associated with the USB
  456. * device passed as parameter.
  457. */
  458. static struct onboard_dev *_find_onboard_dev(struct device *dev)
  459. {
  460. struct platform_device *pdev;
  461. struct device_node *np;
  462. struct onboard_dev *onboard_dev;
  463. pdev = of_find_device_by_node(dev->of_node);
  464. if (!pdev) {
  465. np = of_parse_phandle(dev->of_node, "peer-hub", 0);
  466. if (!np) {
  467. dev_err(dev, "failed to find device node for peer hub\n");
  468. return ERR_PTR(-EINVAL);
  469. }
  470. pdev = of_find_device_by_node(np);
  471. of_node_put(np);
  472. if (!pdev)
  473. return ERR_PTR(-ENODEV);
  474. }
  475. onboard_dev = dev_get_drvdata(&pdev->dev);
  476. put_device(&pdev->dev);
  477. /*
  478. * The presence of drvdata indicates that the platform driver finished
  479. * probing. This handles the case where (conceivably) we could be
  480. * running at the exact same time as the platform driver's probe. If
  481. * we detect the race we request probe deferral and we'll come back and
  482. * try again.
  483. */
  484. if (!onboard_dev)
  485. return ERR_PTR(-EPROBE_DEFER);
  486. return onboard_dev;
  487. }
  488. static bool onboard_dev_usbdev_match(struct usb_device *udev)
  489. {
  490. /* Onboard devices using this driver must have a device tree node */
  491. return !!udev->dev.of_node;
  492. }
  493. static int onboard_dev_usbdev_probe(struct usb_device *udev)
  494. {
  495. struct device *dev = &udev->dev;
  496. struct onboard_dev *onboard_dev;
  497. int err;
  498. onboard_dev = _find_onboard_dev(dev);
  499. if (IS_ERR(onboard_dev))
  500. return PTR_ERR(onboard_dev);
  501. dev_set_drvdata(dev, onboard_dev);
  502. err = onboard_dev_add_usbdev(onboard_dev, udev);
  503. if (err)
  504. return err;
  505. return 0;
  506. }
  507. static void onboard_dev_usbdev_disconnect(struct usb_device *udev)
  508. {
  509. struct onboard_dev *onboard_dev = dev_get_drvdata(&udev->dev);
  510. onboard_dev_remove_usbdev(onboard_dev, udev);
  511. }
  512. static const struct usb_device_id onboard_dev_id_table[] = {
  513. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6500) }, /* CYUSB330x 3.0 HUB */
  514. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6502) }, /* CYUSB330x 2.0 HUB */
  515. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6503) }, /* CYUSB33{0,1}x 2.0 HUB, Vendor Mode */
  516. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6504) }, /* CYUSB331x 3.0 HUB */
  517. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6506) }, /* CYUSB331x 2.0 HUB */
  518. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6507) }, /* CYUSB332x 2.0 HUB, Vendor Mode */
  519. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6508) }, /* CYUSB332x 3.0 HUB */
  520. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x650a) }, /* CYUSB332x 2.0 HUB */
  521. { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6570) }, /* CY7C6563x 2.0 HUB */
  522. { USB_DEVICE(VENDOR_ID_GENESYS, 0x0608) }, /* Genesys Logic GL850G USB 2.0 HUB */
  523. { USB_DEVICE(VENDOR_ID_GENESYS, 0x0610) }, /* Genesys Logic GL852G USB 2.0 HUB */
  524. { USB_DEVICE(VENDOR_ID_GENESYS, 0x0620) }, /* Genesys Logic GL3523 USB 3.1 HUB */
  525. { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2412) }, /* USB2412 USB 2.0 HUB */
  526. { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 HUB */
  527. { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2517) }, /* USB2517 USB 2.0 HUB */
  528. { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2744) }, /* USB5744 USB 2.0 HUB */
  529. { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x5744) }, /* USB5744 USB 3.0 HUB */
  530. { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 HUB */
  531. { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 HUB */
  532. { USB_DEVICE(VENDOR_ID_REALTEK, 0x0414) }, /* RTS5414 USB 3.2 HUB */
  533. { USB_DEVICE(VENDOR_ID_REALTEK, 0x5414) }, /* RTS5414 USB 2.1 HUB */
  534. { USB_DEVICE(VENDOR_ID_TI, 0x8025) }, /* TI USB8020B 3.0 HUB */
  535. { USB_DEVICE(VENDOR_ID_TI, 0x8027) }, /* TI USB8020B 2.0 HUB */
  536. { USB_DEVICE(VENDOR_ID_TI, 0x8140) }, /* TI USB8041 3.0 HUB */
  537. { USB_DEVICE(VENDOR_ID_TI, 0x8142) }, /* TI USB8041 2.0 HUB */
  538. { USB_DEVICE(VENDOR_ID_VIA, 0x0817) }, /* VIA VL817 3.1 HUB */
  539. { USB_DEVICE(VENDOR_ID_VIA, 0x2817) }, /* VIA VL817 2.0 HUB */
  540. { USB_DEVICE(VENDOR_ID_XMOS, 0x0013) }, /* XMOS XVF3500 Voice Processor */
  541. {}
  542. };
  543. MODULE_DEVICE_TABLE(usb, onboard_dev_id_table);
  544. static struct usb_device_driver onboard_dev_usbdev_driver = {
  545. .name = "onboard-usb-dev",
  546. .match = onboard_dev_usbdev_match,
  547. .probe = onboard_dev_usbdev_probe,
  548. .disconnect = onboard_dev_usbdev_disconnect,
  549. .generic_subclass = 1,
  550. .supports_autosuspend = 1,
  551. .id_table = onboard_dev_id_table,
  552. };
  553. static int __init onboard_dev_init(void)
  554. {
  555. int ret;
  556. ret = usb_register_device_driver(&onboard_dev_usbdev_driver, THIS_MODULE);
  557. if (ret)
  558. return ret;
  559. ret = platform_driver_register(&onboard_dev_driver);
  560. if (ret)
  561. usb_deregister_device_driver(&onboard_dev_usbdev_driver);
  562. return ret;
  563. }
  564. module_init(onboard_dev_init);
  565. static void __exit onboard_dev_exit(void)
  566. {
  567. usb_deregister_device_driver(&onboard_dev_usbdev_driver);
  568. platform_driver_unregister(&onboard_dev_driver);
  569. cancel_work_sync(&attach_usb_driver_work);
  570. }
  571. module_exit(onboard_dev_exit);
  572. MODULE_AUTHOR("Matthias Kaehlcke <mka@chromium.org>");
  573. MODULE_DESCRIPTION("Driver for discrete onboard USB devices");
  574. MODULE_LICENSE("GPL v2");