ohci-at91.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2004 SAN People (Pty) Ltd.
  5. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  6. *
  7. * AT91 Bus Glue
  8. *
  9. * Based on fragments of 2.4 driver by Rick Bronson.
  10. * Based on ohci-omap.c
  11. *
  12. * This file is licenced under the GPL.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/platform_data/atmel.h>
  20. #include <linux/io.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/hcd.h>
  25. #include <mach/hardware.h>
  26. #include <asm/gpio.h>
  27. #include <mach/cpu.h>
  28. #include "ohci.h"
  29. #define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
  30. #define at91_for_each_port(index) \
  31. for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
  32. /* interface, function and usb clocks; sometimes also an AHB clock */
  33. static struct clk *iclk, *fclk, *uclk, *hclk;
  34. /* interface and function clocks; sometimes also an AHB clock */
  35. #define DRIVER_DESC "OHCI Atmel driver"
  36. static const char hcd_name[] = "ohci-atmel";
  37. static struct hc_driver __read_mostly ohci_at91_hc_driver;
  38. static int clocked;
  39. static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
  40. u16 wValue, u16 wIndex, char *buf, u16 wLength);
  41. static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
  42. extern int usb_disabled(void);
  43. /*-------------------------------------------------------------------------*/
  44. static void at91_start_clock(void)
  45. {
  46. if (IS_ENABLED(CONFIG_COMMON_CLK)) {
  47. clk_set_rate(uclk, 48000000);
  48. clk_prepare_enable(uclk);
  49. }
  50. clk_prepare_enable(hclk);
  51. clk_prepare_enable(iclk);
  52. clk_prepare_enable(fclk);
  53. clocked = 1;
  54. }
  55. static void at91_stop_clock(void)
  56. {
  57. clk_disable_unprepare(fclk);
  58. clk_disable_unprepare(iclk);
  59. clk_disable_unprepare(hclk);
  60. if (IS_ENABLED(CONFIG_COMMON_CLK))
  61. clk_disable_unprepare(uclk);
  62. clocked = 0;
  63. }
  64. static void at91_start_hc(struct platform_device *pdev)
  65. {
  66. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  67. struct ohci_regs __iomem *regs = hcd->regs;
  68. dev_dbg(&pdev->dev, "start\n");
  69. /*
  70. * Start the USB clocks.
  71. */
  72. at91_start_clock();
  73. /*
  74. * The USB host controller must remain in reset.
  75. */
  76. writel(0, &regs->control);
  77. }
  78. static void at91_stop_hc(struct platform_device *pdev)
  79. {
  80. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  81. struct ohci_regs __iomem *regs = hcd->regs;
  82. dev_dbg(&pdev->dev, "stop\n");
  83. /*
  84. * Put the USB host controller into reset.
  85. */
  86. writel(0, &regs->control);
  87. /*
  88. * Stop the USB clocks.
  89. */
  90. at91_stop_clock();
  91. }
  92. /*-------------------------------------------------------------------------*/
  93. static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
  94. /* configure so an HC device and id are always provided */
  95. /* always called with process context; sleeping is OK */
  96. /**
  97. * usb_hcd_at91_probe - initialize AT91-based HCDs
  98. * Context: !in_interrupt()
  99. *
  100. * Allocates basic resources for this USB host controller, and
  101. * then invokes the start() method for the HCD associated with it
  102. * through the hotplug entry's driver_data.
  103. */
  104. static int usb_hcd_at91_probe(const struct hc_driver *driver,
  105. struct platform_device *pdev)
  106. {
  107. struct at91_usbh_data *board;
  108. struct ohci_hcd *ohci;
  109. int retval;
  110. struct usb_hcd *hcd = NULL;
  111. if (pdev->num_resources != 2) {
  112. pr_debug("hcd probe: invalid num_resources");
  113. return -ENODEV;
  114. }
  115. if ((pdev->resource[0].flags != IORESOURCE_MEM)
  116. || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
  117. pr_debug("hcd probe: invalid resource type\n");
  118. return -ENODEV;
  119. }
  120. hcd = usb_create_hcd(driver, &pdev->dev, "at91");
  121. if (!hcd)
  122. return -ENOMEM;
  123. hcd->rsrc_start = pdev->resource[0].start;
  124. hcd->rsrc_len = resource_size(&pdev->resource[0]);
  125. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  126. pr_debug("request_mem_region failed\n");
  127. retval = -EBUSY;
  128. goto err1;
  129. }
  130. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  131. if (!hcd->regs) {
  132. pr_debug("ioremap failed\n");
  133. retval = -EIO;
  134. goto err2;
  135. }
  136. iclk = clk_get(&pdev->dev, "ohci_clk");
  137. if (IS_ERR(iclk)) {
  138. dev_err(&pdev->dev, "failed to get ohci_clk\n");
  139. retval = PTR_ERR(iclk);
  140. goto err3;
  141. }
  142. fclk = clk_get(&pdev->dev, "uhpck");
  143. if (IS_ERR(fclk)) {
  144. dev_err(&pdev->dev, "failed to get uhpck\n");
  145. retval = PTR_ERR(fclk);
  146. goto err4;
  147. }
  148. hclk = clk_get(&pdev->dev, "hclk");
  149. if (IS_ERR(hclk)) {
  150. dev_err(&pdev->dev, "failed to get hclk\n");
  151. retval = PTR_ERR(hclk);
  152. goto err5;
  153. }
  154. if (IS_ENABLED(CONFIG_COMMON_CLK)) {
  155. uclk = clk_get(&pdev->dev, "usb_clk");
  156. if (IS_ERR(uclk)) {
  157. dev_err(&pdev->dev, "failed to get uclk\n");
  158. retval = PTR_ERR(uclk);
  159. goto err6;
  160. }
  161. }
  162. board = hcd->self.controller->platform_data;
  163. ohci = hcd_to_ohci(hcd);
  164. ohci->num_ports = board->ports;
  165. at91_start_hc(pdev);
  166. retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
  167. if (retval == 0)
  168. return retval;
  169. /* Error handling */
  170. at91_stop_hc(pdev);
  171. if (IS_ENABLED(CONFIG_COMMON_CLK))
  172. clk_put(uclk);
  173. err6:
  174. clk_put(hclk);
  175. err5:
  176. clk_put(fclk);
  177. err4:
  178. clk_put(iclk);
  179. err3:
  180. iounmap(hcd->regs);
  181. err2:
  182. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  183. err1:
  184. usb_put_hcd(hcd);
  185. return retval;
  186. }
  187. /* may be called with controller, bus, and devices active */
  188. /**
  189. * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
  190. * @dev: USB Host Controller being removed
  191. * Context: !in_interrupt()
  192. *
  193. * Reverses the effect of usb_hcd_at91_probe(), first invoking
  194. * the HCD's stop() method. It is always called from a thread
  195. * context, "rmmod" or something similar.
  196. *
  197. */
  198. static void usb_hcd_at91_remove(struct usb_hcd *hcd,
  199. struct platform_device *pdev)
  200. {
  201. usb_remove_hcd(hcd);
  202. at91_stop_hc(pdev);
  203. iounmap(hcd->regs);
  204. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  205. usb_put_hcd(hcd);
  206. if (IS_ENABLED(CONFIG_COMMON_CLK))
  207. clk_put(uclk);
  208. clk_put(hclk);
  209. clk_put(fclk);
  210. clk_put(iclk);
  211. fclk = iclk = hclk = NULL;
  212. }
  213. /*-------------------------------------------------------------------------*/
  214. static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
  215. {
  216. if (!valid_port(port))
  217. return;
  218. if (!gpio_is_valid(pdata->vbus_pin[port]))
  219. return;
  220. gpio_set_value(pdata->vbus_pin[port],
  221. pdata->vbus_pin_active_low[port] ^ enable);
  222. }
  223. static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
  224. {
  225. if (!valid_port(port))
  226. return -EINVAL;
  227. if (!gpio_is_valid(pdata->vbus_pin[port]))
  228. return -EINVAL;
  229. return gpio_get_value(pdata->vbus_pin[port]) ^
  230. pdata->vbus_pin_active_low[port];
  231. }
  232. /*
  233. * Update the status data from the hub with the over-current indicator change.
  234. */
  235. static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
  236. {
  237. struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
  238. int length = orig_ohci_hub_status_data(hcd, buf);
  239. int port;
  240. at91_for_each_port(port) {
  241. if (pdata->overcurrent_changed[port]) {
  242. if (!length)
  243. length = 1;
  244. buf[0] |= 1 << (port + 1);
  245. }
  246. }
  247. return length;
  248. }
  249. /*
  250. * Look at the control requests to the root hub and see if we need to override.
  251. */
  252. static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  253. u16 wIndex, char *buf, u16 wLength)
  254. {
  255. struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
  256. struct usb_hub_descriptor *desc;
  257. int ret = -EINVAL;
  258. u32 *data = (u32 *)buf;
  259. dev_dbg(hcd->self.controller,
  260. "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
  261. hcd, typeReq, wValue, wIndex, buf, wLength);
  262. wIndex--;
  263. switch (typeReq) {
  264. case SetPortFeature:
  265. if (wValue == USB_PORT_FEAT_POWER) {
  266. dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
  267. if (valid_port(wIndex)) {
  268. ohci_at91_usb_set_power(pdata, wIndex, 1);
  269. ret = 0;
  270. }
  271. goto out;
  272. }
  273. break;
  274. case ClearPortFeature:
  275. switch (wValue) {
  276. case USB_PORT_FEAT_C_OVER_CURRENT:
  277. dev_dbg(hcd->self.controller,
  278. "ClearPortFeature: C_OVER_CURRENT\n");
  279. if (valid_port(wIndex)) {
  280. pdata->overcurrent_changed[wIndex] = 0;
  281. pdata->overcurrent_status[wIndex] = 0;
  282. }
  283. goto out;
  284. case USB_PORT_FEAT_OVER_CURRENT:
  285. dev_dbg(hcd->self.controller,
  286. "ClearPortFeature: OVER_CURRENT\n");
  287. if (valid_port(wIndex))
  288. pdata->overcurrent_status[wIndex] = 0;
  289. goto out;
  290. case USB_PORT_FEAT_POWER:
  291. dev_dbg(hcd->self.controller,
  292. "ClearPortFeature: POWER\n");
  293. if (valid_port(wIndex)) {
  294. ohci_at91_usb_set_power(pdata, wIndex, 0);
  295. return 0;
  296. }
  297. }
  298. break;
  299. }
  300. ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex + 1,
  301. buf, wLength);
  302. if (ret)
  303. goto out;
  304. switch (typeReq) {
  305. case GetHubDescriptor:
  306. /* update the hub's descriptor */
  307. desc = (struct usb_hub_descriptor *)buf;
  308. dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
  309. desc->wHubCharacteristics);
  310. /* remove the old configurations for power-switching, and
  311. * over-current protection, and insert our new configuration
  312. */
  313. desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
  314. desc->wHubCharacteristics |= cpu_to_le16(0x0001);
  315. if (pdata->overcurrent_supported) {
  316. desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
  317. desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
  318. }
  319. dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
  320. desc->wHubCharacteristics);
  321. return ret;
  322. case GetPortStatus:
  323. /* check port status */
  324. dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
  325. if (valid_port(wIndex)) {
  326. if (!ohci_at91_usb_get_power(pdata, wIndex))
  327. *data &= ~cpu_to_le32(RH_PS_PPS);
  328. if (pdata->overcurrent_changed[wIndex])
  329. *data |= cpu_to_le32(RH_PS_OCIC);
  330. if (pdata->overcurrent_status[wIndex])
  331. *data |= cpu_to_le32(RH_PS_POCI);
  332. }
  333. }
  334. out:
  335. return ret;
  336. }
  337. /*-------------------------------------------------------------------------*/
  338. static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
  339. {
  340. struct platform_device *pdev = data;
  341. struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
  342. int val, gpio, port;
  343. /* From the GPIO notifying the over-current situation, find
  344. * out the corresponding port */
  345. at91_for_each_port(port) {
  346. if (gpio_is_valid(pdata->overcurrent_pin[port]) &&
  347. gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
  348. gpio = pdata->overcurrent_pin[port];
  349. break;
  350. }
  351. }
  352. if (port == AT91_MAX_USBH_PORTS) {
  353. dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
  354. return IRQ_HANDLED;
  355. }
  356. val = gpio_get_value(gpio);
  357. /* When notified of an over-current situation, disable power
  358. on the corresponding port, and mark this port in
  359. over-current. */
  360. if (!val) {
  361. ohci_at91_usb_set_power(pdata, port, 0);
  362. pdata->overcurrent_status[port] = 1;
  363. pdata->overcurrent_changed[port] = 1;
  364. }
  365. dev_dbg(& pdev->dev, "overcurrent situation %s\n",
  366. val ? "exited" : "notified");
  367. return IRQ_HANDLED;
  368. }
  369. #ifdef CONFIG_OF
  370. static const struct of_device_id at91_ohci_dt_ids[] = {
  371. { .compatible = "atmel,at91rm9200-ohci" },
  372. { /* sentinel */ }
  373. };
  374. MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
  375. static int ohci_at91_of_init(struct platform_device *pdev)
  376. {
  377. struct device_node *np = pdev->dev.of_node;
  378. int i, gpio;
  379. enum of_gpio_flags flags;
  380. struct at91_usbh_data *pdata;
  381. u32 ports;
  382. if (!np)
  383. return 0;
  384. /* Right now device-tree probed devices don't get dma_mask set.
  385. * Since shared usb code relies on it, set it here for now.
  386. * Once we have dma capability bindings this can go away.
  387. */
  388. if (!pdev->dev.dma_mask)
  389. pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  390. if (!pdev->dev.coherent_dma_mask)
  391. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  392. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  393. if (!pdata)
  394. return -ENOMEM;
  395. if (!of_property_read_u32(np, "num-ports", &ports))
  396. pdata->ports = ports;
  397. at91_for_each_port(i) {
  398. gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags);
  399. pdata->vbus_pin[i] = gpio;
  400. if (!gpio_is_valid(gpio))
  401. continue;
  402. pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
  403. }
  404. at91_for_each_port(i)
  405. pdata->overcurrent_pin[i] =
  406. of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
  407. pdev->dev.platform_data = pdata;
  408. return 0;
  409. }
  410. #else
  411. static int ohci_at91_of_init(struct platform_device *pdev)
  412. {
  413. return 0;
  414. }
  415. #endif
  416. /*-------------------------------------------------------------------------*/
  417. static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
  418. {
  419. struct at91_usbh_data *pdata;
  420. int i;
  421. int gpio;
  422. int ret;
  423. ret = ohci_at91_of_init(pdev);
  424. if (ret)
  425. return ret;
  426. pdata = dev_get_platdata(&pdev->dev);
  427. if (pdata) {
  428. at91_for_each_port(i) {
  429. /*
  430. * do not configure PIO if not in relation with
  431. * real USB port on board
  432. */
  433. if (i >= pdata->ports) {
  434. pdata->vbus_pin[i] = -EINVAL;
  435. pdata->overcurrent_pin[i] = -EINVAL;
  436. break;
  437. }
  438. if (!gpio_is_valid(pdata->vbus_pin[i]))
  439. continue;
  440. gpio = pdata->vbus_pin[i];
  441. ret = gpio_request(gpio, "ohci_vbus");
  442. if (ret) {
  443. dev_err(&pdev->dev,
  444. "can't request vbus gpio %d\n", gpio);
  445. continue;
  446. }
  447. ret = gpio_direction_output(gpio,
  448. !pdata->vbus_pin_active_low[i]);
  449. if (ret) {
  450. dev_err(&pdev->dev,
  451. "can't put vbus gpio %d as output %d\n",
  452. gpio, !pdata->vbus_pin_active_low[i]);
  453. gpio_free(gpio);
  454. continue;
  455. }
  456. ohci_at91_usb_set_power(pdata, i, 1);
  457. }
  458. at91_for_each_port(i) {
  459. if (!gpio_is_valid(pdata->overcurrent_pin[i]))
  460. continue;
  461. gpio = pdata->overcurrent_pin[i];
  462. ret = gpio_request(gpio, "ohci_overcurrent");
  463. if (ret) {
  464. dev_err(&pdev->dev,
  465. "can't request overcurrent gpio %d\n",
  466. gpio);
  467. continue;
  468. }
  469. ret = gpio_direction_input(gpio);
  470. if (ret) {
  471. dev_err(&pdev->dev,
  472. "can't configure overcurrent gpio %d as input\n",
  473. gpio);
  474. gpio_free(gpio);
  475. continue;
  476. }
  477. ret = request_irq(gpio_to_irq(gpio),
  478. ohci_hcd_at91_overcurrent_irq,
  479. IRQF_SHARED, "ohci_overcurrent", pdev);
  480. if (ret) {
  481. gpio_free(gpio);
  482. dev_err(&pdev->dev,
  483. "can't get gpio IRQ for overcurrent\n");
  484. }
  485. }
  486. }
  487. device_init_wakeup(&pdev->dev, 1);
  488. return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
  489. }
  490. static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
  491. {
  492. struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
  493. int i;
  494. if (pdata) {
  495. at91_for_each_port(i) {
  496. if (!gpio_is_valid(pdata->vbus_pin[i]))
  497. continue;
  498. ohci_at91_usb_set_power(pdata, i, 0);
  499. gpio_free(pdata->vbus_pin[i]);
  500. }
  501. at91_for_each_port(i) {
  502. if (!gpio_is_valid(pdata->overcurrent_pin[i]))
  503. continue;
  504. free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
  505. gpio_free(pdata->overcurrent_pin[i]);
  506. }
  507. }
  508. device_init_wakeup(&pdev->dev, 0);
  509. usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
  510. return 0;
  511. }
  512. #ifdef CONFIG_PM
  513. static int
  514. ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
  515. {
  516. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  517. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  518. bool do_wakeup = device_may_wakeup(&pdev->dev);
  519. int ret;
  520. ret = ohci_suspend(hcd, do_wakeup);
  521. if (ret)
  522. return ret;
  523. if (do_wakeup)
  524. enable_irq_wake(hcd->irq);
  525. /*
  526. * The integrated transceivers seem unable to notice disconnect,
  527. * reconnect, or wakeup without the 48 MHz clock active. so for
  528. * correctness, always discard connection state (using reset).
  529. *
  530. * REVISIT: some boards will be able to turn VBUS off...
  531. */
  532. if (at91_suspend_entering_slow_clock()) {
  533. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  534. ohci->hc_control &= OHCI_CTRL_RWC;
  535. ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
  536. ohci->rh_state = OHCI_RH_HALTED;
  537. /* flush the writes */
  538. (void) ohci_readl (ohci, &ohci->regs->control);
  539. at91_stop_clock();
  540. }
  541. return ret;
  542. }
  543. static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
  544. {
  545. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  546. if (device_may_wakeup(&pdev->dev))
  547. disable_irq_wake(hcd->irq);
  548. if (!clocked)
  549. at91_start_clock();
  550. ohci_resume(hcd, false);
  551. return 0;
  552. }
  553. #else
  554. #define ohci_hcd_at91_drv_suspend NULL
  555. #define ohci_hcd_at91_drv_resume NULL
  556. #endif
  557. static struct platform_driver ohci_hcd_at91_driver = {
  558. .probe = ohci_hcd_at91_drv_probe,
  559. .remove = ohci_hcd_at91_drv_remove,
  560. .shutdown = usb_hcd_platform_shutdown,
  561. .suspend = ohci_hcd_at91_drv_suspend,
  562. .resume = ohci_hcd_at91_drv_resume,
  563. .driver = {
  564. .name = "at91_ohci",
  565. .owner = THIS_MODULE,
  566. .of_match_table = of_match_ptr(at91_ohci_dt_ids),
  567. },
  568. };
  569. static int __init ohci_at91_init(void)
  570. {
  571. if (usb_disabled())
  572. return -ENODEV;
  573. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  574. ohci_init_driver(&ohci_at91_hc_driver, NULL);
  575. /*
  576. * The Atmel HW has some unusual quirks, which require Atmel-specific
  577. * workarounds. We override certain hc_driver functions here to
  578. * achieve that. We explicitly do not enhance ohci_driver_overrides to
  579. * allow this more easily, since this is an unusual case, and we don't
  580. * want to encourage others to override these functions by making it
  581. * too easy.
  582. */
  583. orig_ohci_hub_control = ohci_at91_hc_driver.hub_control;
  584. orig_ohci_hub_status_data = ohci_at91_hc_driver.hub_status_data;
  585. ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data;
  586. ohci_at91_hc_driver.hub_control = ohci_at91_hub_control;
  587. return platform_driver_register(&ohci_hcd_at91_driver);
  588. }
  589. module_init(ohci_at91_init);
  590. static void __exit ohci_at91_cleanup(void)
  591. {
  592. platform_driver_unregister(&ohci_hcd_at91_driver);
  593. }
  594. module_exit(ohci_at91_cleanup);
  595. MODULE_DESCRIPTION(DRIVER_DESC);
  596. MODULE_LICENSE("GPL");
  597. MODULE_ALIAS("platform:at91_ohci");