ohci-at91.c 17 KB

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