ohci-at91.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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, ret;
  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. ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  389. if (ret)
  390. return ret;
  391. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  392. if (!pdata)
  393. return -ENOMEM;
  394. if (!of_property_read_u32(np, "num-ports", &ports))
  395. pdata->ports = ports;
  396. at91_for_each_port(i) {
  397. gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags);
  398. pdata->vbus_pin[i] = gpio;
  399. if (!gpio_is_valid(gpio))
  400. continue;
  401. pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
  402. }
  403. at91_for_each_port(i)
  404. pdata->overcurrent_pin[i] =
  405. of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
  406. pdev->dev.platform_data = pdata;
  407. return 0;
  408. }
  409. #else
  410. static int ohci_at91_of_init(struct platform_device *pdev)
  411. {
  412. return 0;
  413. }
  414. #endif
  415. /*-------------------------------------------------------------------------*/
  416. static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
  417. {
  418. struct at91_usbh_data *pdata;
  419. int i;
  420. int gpio;
  421. int ret;
  422. ret = ohci_at91_of_init(pdev);
  423. if (ret)
  424. return ret;
  425. pdata = dev_get_platdata(&pdev->dev);
  426. if (pdata) {
  427. at91_for_each_port(i) {
  428. /*
  429. * do not configure PIO if not in relation with
  430. * real USB port on board
  431. */
  432. if (i >= pdata->ports) {
  433. pdata->vbus_pin[i] = -EINVAL;
  434. pdata->overcurrent_pin[i] = -EINVAL;
  435. break;
  436. }
  437. if (!gpio_is_valid(pdata->vbus_pin[i]))
  438. continue;
  439. gpio = pdata->vbus_pin[i];
  440. ret = gpio_request(gpio, "ohci_vbus");
  441. if (ret) {
  442. dev_err(&pdev->dev,
  443. "can't request vbus gpio %d\n", gpio);
  444. continue;
  445. }
  446. ret = gpio_direction_output(gpio,
  447. !pdata->vbus_pin_active_low[i]);
  448. if (ret) {
  449. dev_err(&pdev->dev,
  450. "can't put vbus gpio %d as output %d\n",
  451. gpio, !pdata->vbus_pin_active_low[i]);
  452. gpio_free(gpio);
  453. continue;
  454. }
  455. ohci_at91_usb_set_power(pdata, i, 1);
  456. }
  457. at91_for_each_port(i) {
  458. if (!gpio_is_valid(pdata->overcurrent_pin[i]))
  459. continue;
  460. gpio = pdata->overcurrent_pin[i];
  461. ret = gpio_request(gpio, "ohci_overcurrent");
  462. if (ret) {
  463. dev_err(&pdev->dev,
  464. "can't request overcurrent gpio %d\n",
  465. gpio);
  466. continue;
  467. }
  468. ret = gpio_direction_input(gpio);
  469. if (ret) {
  470. dev_err(&pdev->dev,
  471. "can't configure overcurrent gpio %d as input\n",
  472. gpio);
  473. gpio_free(gpio);
  474. continue;
  475. }
  476. ret = request_irq(gpio_to_irq(gpio),
  477. ohci_hcd_at91_overcurrent_irq,
  478. IRQF_SHARED, "ohci_overcurrent", pdev);
  479. if (ret) {
  480. gpio_free(gpio);
  481. dev_err(&pdev->dev,
  482. "can't get gpio IRQ for overcurrent\n");
  483. }
  484. }
  485. }
  486. device_init_wakeup(&pdev->dev, 1);
  487. return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
  488. }
  489. static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
  490. {
  491. struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
  492. int i;
  493. if (pdata) {
  494. at91_for_each_port(i) {
  495. if (!gpio_is_valid(pdata->vbus_pin[i]))
  496. continue;
  497. ohci_at91_usb_set_power(pdata, i, 0);
  498. gpio_free(pdata->vbus_pin[i]);
  499. }
  500. at91_for_each_port(i) {
  501. if (!gpio_is_valid(pdata->overcurrent_pin[i]))
  502. continue;
  503. free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
  504. gpio_free(pdata->overcurrent_pin[i]);
  505. }
  506. }
  507. device_init_wakeup(&pdev->dev, 0);
  508. usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
  509. return 0;
  510. }
  511. #ifdef CONFIG_PM
  512. static int
  513. ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
  514. {
  515. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  516. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  517. if (device_may_wakeup(&pdev->dev))
  518. enable_irq_wake(hcd->irq);
  519. /*
  520. * The integrated transceivers seem unable to notice disconnect,
  521. * reconnect, or wakeup without the 48 MHz clock active. so for
  522. * correctness, always discard connection state (using reset).
  523. *
  524. * REVISIT: some boards will be able to turn VBUS off...
  525. */
  526. if (at91_suspend_entering_slow_clock()) {
  527. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  528. ohci->hc_control &= OHCI_CTRL_RWC;
  529. ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
  530. ohci->rh_state = OHCI_RH_HALTED;
  531. /* flush the writes */
  532. (void) ohci_readl (ohci, &ohci->regs->control);
  533. at91_stop_clock();
  534. }
  535. return 0;
  536. }
  537. static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
  538. {
  539. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  540. if (device_may_wakeup(&pdev->dev))
  541. disable_irq_wake(hcd->irq);
  542. if (!clocked)
  543. at91_start_clock();
  544. ohci_resume(hcd, false);
  545. return 0;
  546. }
  547. #else
  548. #define ohci_hcd_at91_drv_suspend NULL
  549. #define ohci_hcd_at91_drv_resume NULL
  550. #endif
  551. static struct platform_driver ohci_hcd_at91_driver = {
  552. .probe = ohci_hcd_at91_drv_probe,
  553. .remove = ohci_hcd_at91_drv_remove,
  554. .shutdown = usb_hcd_platform_shutdown,
  555. .suspend = ohci_hcd_at91_drv_suspend,
  556. .resume = ohci_hcd_at91_drv_resume,
  557. .driver = {
  558. .name = "at91_ohci",
  559. .owner = THIS_MODULE,
  560. .of_match_table = of_match_ptr(at91_ohci_dt_ids),
  561. },
  562. };
  563. static int __init ohci_at91_init(void)
  564. {
  565. if (usb_disabled())
  566. return -ENODEV;
  567. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  568. ohci_init_driver(&ohci_at91_hc_driver, NULL);
  569. /*
  570. * The Atmel HW has some unusual quirks, which require Atmel-specific
  571. * workarounds. We override certain hc_driver functions here to
  572. * achieve that. We explicitly do not enhance ohci_driver_overrides to
  573. * allow this more easily, since this is an unusual case, and we don't
  574. * want to encourage others to override these functions by making it
  575. * too easy.
  576. */
  577. orig_ohci_hub_control = ohci_at91_hc_driver.hub_control;
  578. orig_ohci_hub_status_data = ohci_at91_hc_driver.hub_status_data;
  579. ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data;
  580. ohci_at91_hc_driver.hub_control = ohci_at91_hub_control;
  581. return platform_driver_register(&ohci_hcd_at91_driver);
  582. }
  583. module_init(ohci_at91_init);
  584. static void __exit ohci_at91_cleanup(void)
  585. {
  586. platform_driver_unregister(&ohci_hcd_at91_driver);
  587. }
  588. module_exit(ohci_at91_cleanup);
  589. MODULE_DESCRIPTION(DRIVER_DESC);
  590. MODULE_LICENSE("GPL");
  591. MODULE_ALIAS("platform:at91_ohci");