120-usb-isp116x-hcd-add-of-binding.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. --- a/drivers/usb/host/isp116x-hcd.c
  2. +++ b/drivers/usb/host/isp116x-hcd.c
  3. @@ -1533,6 +1533,7 @@ static struct hc_driver isp116x_hc_drive
  4. /*----------------------------------------------------------------*/
  5. +#ifdef CONFIG_USB_ISP116X_HCD_PLATFORM
  6. static int isp116x_remove(struct platform_device *pdev)
  7. {
  8. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  9. @@ -1711,4 +1712,251 @@ static struct platform_driver isp116x_dr
  10. },
  11. };
  12. -module_platform_driver(isp116x_driver);
  13. +static inline int isp116x_platform_register(void)
  14. +{
  15. + return platform_driver_register(&isp116x_driver);
  16. +}
  17. +
  18. +static inline void isp116x_platform_unregister(void)
  19. +{
  20. + platform_driver_unregister(&isp116x_driver);
  21. +}
  22. +#else
  23. +static inline int isp116x_platform_register(void) { return 0; };
  24. +static void isp116x_platform_unregister(void) {};
  25. +#endif /* CONFIG_USB_ISP116X_PLATFORM */
  26. +
  27. +/*-----------------------------------------------------------------*/
  28. +
  29. +#ifdef CONFIG_USB_ISP116X_HCD_OF
  30. +
  31. +/* TODO: rework platform probe instead of using a separate probe */
  32. +
  33. +#include <linux/of_platform.h>
  34. +
  35. +#ifdef USE_PLATFORM_DELAY
  36. +static void isp116x_of_delay(struct device *ddev, int delay)
  37. +{
  38. + ndelay(delay);
  39. +}
  40. +#else
  41. +#define isp116x_of_delay NULL
  42. +#endif
  43. +
  44. +static int isp116x_of_probe(struct platform_device *op)
  45. +{
  46. + struct device_node *dn = op->dev.of_node;
  47. + struct usb_hcd *hcd;
  48. + struct isp116x *isp116x;
  49. + struct resource addr, data;
  50. + struct isp116x_platform_data *board;
  51. + void __iomem *addr_reg;
  52. + void __iomem *data_reg;
  53. + int irq;
  54. + int ret = 0;
  55. + unsigned long irqflags;
  56. +
  57. + ret = of_address_to_resource(dn, 0, &data);
  58. + if (ret)
  59. + return ret;
  60. +
  61. + ret = of_address_to_resource(dn, 1, &addr);
  62. + if (ret)
  63. + return ret;
  64. +
  65. + board = kzalloc(sizeof(struct isp116x_platform_data), GFP_KERNEL);
  66. + if (board == NULL)
  67. + return -ENOMEM;
  68. +
  69. + if (!request_mem_region(addr.start, resource_size(&addr), hcd_name)) {
  70. + ret = -EBUSY;
  71. + goto err_free_board;
  72. + }
  73. +
  74. + addr_reg = ioremap_nocache(addr.start, resource_size(&addr));
  75. + if (addr_reg == NULL) {
  76. + ret = -ENOMEM;
  77. + goto err_release_addr;
  78. + }
  79. +
  80. + if (!request_mem_region(data.start, resource_size(&data), hcd_name)) {
  81. + ret = -EBUSY;
  82. + goto err_unmap_addr;
  83. + }
  84. +
  85. + data_reg = ioremap_nocache(data.start, resource_size(&data));
  86. + if (data_reg == NULL) {
  87. + ret = -ENOMEM;
  88. + goto err_release_data;
  89. + }
  90. +
  91. + irq = irq_of_parse_and_map(dn, 0);
  92. + if (irq == NO_IRQ) {
  93. + ret = -EINVAL;
  94. + goto err_unmap_data;
  95. + }
  96. +
  97. + /* allocate and initialize hcd */
  98. + hcd = usb_create_hcd(&isp116x_hc_driver, &op->dev, dev_name(&op->dev));
  99. + if (!hcd) {
  100. + ret = -ENOMEM;
  101. + goto err_irq_dispose;
  102. + }
  103. +
  104. + /* this rsrc_start is bogus */
  105. + hcd->rsrc_start = addr.start;
  106. + isp116x = hcd_to_isp116x(hcd);
  107. + isp116x->data_reg = data_reg;
  108. + isp116x->addr_reg = addr_reg;
  109. + isp116x->board = board;
  110. + spin_lock_init(&isp116x->lock);
  111. + INIT_LIST_HEAD(&isp116x->async);
  112. +
  113. + board->delay = isp116x_of_delay;
  114. + if (of_get_property(dn, "sel15Kres", NULL))
  115. + board->sel15Kres = 1;
  116. + if (of_get_property(dn, "oc_enable", NULL))
  117. + board->oc_enable = 1;
  118. + if (of_get_property(dn, "remote_wakeup_enable", NULL))
  119. + board->remote_wakeup_enable = 1;
  120. +
  121. + if (of_get_property(dn, "int_act_high", NULL))
  122. + board->int_act_high = 1;
  123. + if (of_get_property(dn, "int_edge_triggered", NULL))
  124. + board->int_edge_triggered = 1;
  125. +
  126. + if (board->int_edge_triggered)
  127. + irqflags = board->int_act_high ? IRQF_TRIGGER_RISING :
  128. + IRQF_TRIGGER_FALLING;
  129. + else
  130. + irqflags = board->int_act_high ? IRQF_TRIGGER_HIGH :
  131. + IRQF_TRIGGER_LOW;
  132. +
  133. + ret = usb_add_hcd(hcd, irq, irqflags | IRQF_DISABLED);
  134. + if (ret)
  135. + goto err_put_hcd;
  136. +
  137. + ret = create_debug_file(isp116x);
  138. + if (ret) {
  139. + ERR("Couldn't create debugfs entry\n");
  140. + goto err_remove_hcd;
  141. + }
  142. +
  143. + return 0;
  144. +
  145. + err_remove_hcd:
  146. + usb_remove_hcd(hcd);
  147. + err_put_hcd:
  148. + usb_put_hcd(hcd);
  149. + err_irq_dispose:
  150. + irq_dispose_mapping(irq);
  151. + err_unmap_data:
  152. + iounmap(data_reg);
  153. + err_release_data:
  154. + release_mem_region(data.start, resource_size(&data));
  155. + err_unmap_addr:
  156. + iounmap(addr_reg);
  157. + err_release_addr:
  158. + release_mem_region(addr.start, resource_size(&addr));
  159. + err_free_board:
  160. + kfree(board);
  161. + return ret;
  162. +}
  163. +
  164. +static int isp116x_of_remove(struct platform_device *op)
  165. +{
  166. + struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  167. + struct isp116x *isp116x;
  168. + struct resource res;
  169. +
  170. + if (!hcd)
  171. + return 0;
  172. +
  173. + dev_set_drvdata(&op->dev, NULL);
  174. +
  175. + isp116x = hcd_to_isp116x(hcd);
  176. + remove_debug_file(isp116x);
  177. + usb_remove_hcd(hcd);
  178. +
  179. + irq_dispose_mapping(hcd->irq);
  180. +
  181. + iounmap(isp116x->data_reg);
  182. + (void) of_address_to_resource(op->dev.of_node, 0, &res);
  183. + release_mem_region(res.start, resource_size(&res));
  184. +
  185. + iounmap(isp116x->addr_reg);
  186. + (void) of_address_to_resource(op->dev.of_node, 1, &res);
  187. + release_mem_region(res.start, resource_size(&res));
  188. +
  189. + kfree(isp116x->board);
  190. + usb_put_hcd(hcd);
  191. +
  192. + return 0;
  193. +}
  194. +
  195. +static struct of_device_id isp116x_of_match[] = {
  196. + { .compatible = "isp116x-hcd", },
  197. + {},
  198. +};
  199. +
  200. +static struct platform_driver isp116x_of_platform_driver = {
  201. + .probe = isp116x_of_probe,
  202. + .remove = isp116x_of_remove,
  203. + .driver = {
  204. + .name = "isp116x-hcd-of",
  205. + .owner = THIS_MODULE,
  206. + .of_match_table = isp116x_of_match,
  207. + },
  208. +};
  209. +
  210. +static int __init isp116x_of_register(void)
  211. +{
  212. + return platform_driver_register(&isp116x_of_platform_driver);
  213. +}
  214. +
  215. +static void __exit isp116x_of_unregister(void)
  216. +{
  217. + platform_driver_unregister(&isp116x_of_platform_driver);
  218. +}
  219. +
  220. +MODULE_DEVICE_TABLE(of, isp116x_of_match);
  221. +
  222. +#else
  223. +static inline int isp116x_of_register(void) { return 0; };
  224. +static void isp116x_of_unregister(void) {};
  225. +#endif /* CONFIG_USB_ISP116X_HCD_OF */
  226. +
  227. +/*-----------------------------------------------------------------*/
  228. +
  229. +static int __init isp116x_init(void)
  230. +{
  231. + int ret;
  232. +
  233. + if (usb_disabled())
  234. + return -ENODEV;
  235. +
  236. + INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
  237. + ret = isp116x_platform_register();
  238. + if (ret)
  239. + return ret;
  240. +
  241. + ret = isp116x_of_register();
  242. + if (ret)
  243. + goto err_platform_unregister;
  244. +
  245. + return 0;
  246. +
  247. + err_platform_unregister:
  248. + isp116x_platform_unregister();
  249. + return ret;
  250. +}
  251. +
  252. +module_init(isp116x_init);
  253. +
  254. +static void __exit isp116x_cleanup(void)
  255. +{
  256. + isp116x_of_unregister();
  257. + isp116x_platform_unregister();
  258. +}
  259. +
  260. +module_exit(isp116x_cleanup);
  261. --- a/drivers/usb/host/Kconfig
  262. +++ b/drivers/usb/host/Kconfig
  263. @@ -327,6 +327,24 @@ config USB_ISP116X_HCD
  264. To compile this driver as a module, choose M here: the
  265. module will be called isp116x-hcd.
  266. +config USB_ISP116X_HCD_PLATFORM
  267. + bool "ISP116X support for controllers on platform bus"
  268. + depends on USB_ISP116X_HCD
  269. + default n if PPC_OF
  270. + default y
  271. + ---help---
  272. + Enables support for the ISP116x USB controller present on the
  273. + platform bus.
  274. +
  275. +config USB_ISP116X_HCD_OF
  276. + bool "ISP116X support for controllers on OF platform bus"
  277. + depends on USB_ISP116X_HCD && PPC_OF
  278. + default y if PPC_OF
  279. + default n
  280. + ---help---
  281. + Enables support for the ISP116x USB controller present on the
  282. + OpenFirmware platform bus.
  283. +
  284. config USB_ISP1760_HCD
  285. tristate "ISP 1760 HCD support"
  286. ---help---