ohci-at91.c 17 KB

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