ohci-at91.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. }
  198. /*-------------------------------------------------------------------------*/
  199. static int
  200. ohci_at91_reset (struct usb_hcd *hcd)
  201. {
  202. struct at91_usbh_data *board = dev_get_platdata(hcd->self.controller);
  203. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  204. int ret;
  205. if ((ret = ohci_init(ohci)) < 0)
  206. return ret;
  207. ohci->num_ports = board->ports;
  208. return 0;
  209. }
  210. static int
  211. ohci_at91_start (struct usb_hcd *hcd)
  212. {
  213. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  214. int ret;
  215. if ((ret = ohci_run(ohci)) < 0) {
  216. dev_err(hcd->self.controller, "can't start %s\n",
  217. hcd->self.bus_name);
  218. ohci_stop(hcd);
  219. return ret;
  220. }
  221. return 0;
  222. }
  223. static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
  224. {
  225. if (!valid_port(port))
  226. return;
  227. if (!gpio_is_valid(pdata->vbus_pin[port]))
  228. return;
  229. gpio_set_value(pdata->vbus_pin[port],
  230. pdata->vbus_pin_active_low[port] ^ enable);
  231. }
  232. static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
  233. {
  234. if (!valid_port(port))
  235. return -EINVAL;
  236. if (!gpio_is_valid(pdata->vbus_pin[port]))
  237. return -EINVAL;
  238. return gpio_get_value(pdata->vbus_pin[port]) ^
  239. pdata->vbus_pin_active_low[port];
  240. }
  241. /*
  242. * Update the status data from the hub with the over-current indicator change.
  243. */
  244. static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
  245. {
  246. struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
  247. int length = ohci_hub_status_data(hcd, buf);
  248. int port;
  249. at91_for_each_port(port) {
  250. if (pdata->overcurrent_changed[port]) {
  251. if (!length)
  252. length = 1;
  253. buf[0] |= 1 << (port + 1);
  254. }
  255. }
  256. return length;
  257. }
  258. /*
  259. * Look at the control requests to the root hub and see if we need to override.
  260. */
  261. static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  262. u16 wIndex, char *buf, u16 wLength)
  263. {
  264. struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
  265. struct usb_hub_descriptor *desc;
  266. int ret = -EINVAL;
  267. u32 *data = (u32 *)buf;
  268. dev_dbg(hcd->self.controller,
  269. "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
  270. hcd, typeReq, wValue, wIndex, buf, wLength);
  271. wIndex--;
  272. switch (typeReq) {
  273. case SetPortFeature:
  274. if (wValue == USB_PORT_FEAT_POWER) {
  275. dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
  276. if (valid_port(wIndex)) {
  277. ohci_at91_usb_set_power(pdata, wIndex, 1);
  278. ret = 0;
  279. }
  280. goto out;
  281. }
  282. break;
  283. case ClearPortFeature:
  284. switch (wValue) {
  285. case USB_PORT_FEAT_C_OVER_CURRENT:
  286. dev_dbg(hcd->self.controller,
  287. "ClearPortFeature: C_OVER_CURRENT\n");
  288. if (valid_port(wIndex)) {
  289. pdata->overcurrent_changed[wIndex] = 0;
  290. pdata->overcurrent_status[wIndex] = 0;
  291. }
  292. goto out;
  293. case USB_PORT_FEAT_OVER_CURRENT:
  294. dev_dbg(hcd->self.controller,
  295. "ClearPortFeature: OVER_CURRENT\n");
  296. if (valid_port(wIndex))
  297. pdata->overcurrent_status[wIndex] = 0;
  298. goto out;
  299. case USB_PORT_FEAT_POWER:
  300. dev_dbg(hcd->self.controller,
  301. "ClearPortFeature: POWER\n");
  302. if (valid_port(wIndex)) {
  303. ohci_at91_usb_set_power(pdata, wIndex, 0);
  304. return 0;
  305. }
  306. }
  307. break;
  308. }
  309. ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
  310. if (ret)
  311. goto out;
  312. switch (typeReq) {
  313. case GetHubDescriptor:
  314. /* update the hub's descriptor */
  315. desc = (struct usb_hub_descriptor *)buf;
  316. dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
  317. desc->wHubCharacteristics);
  318. /* remove the old configurations for power-switching, and
  319. * over-current protection, and insert our new configuration
  320. */
  321. desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
  322. desc->wHubCharacteristics |= cpu_to_le16(0x0001);
  323. if (pdata->overcurrent_supported) {
  324. desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
  325. desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
  326. }
  327. dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
  328. desc->wHubCharacteristics);
  329. return ret;
  330. case GetPortStatus:
  331. /* check port status */
  332. dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
  333. if (valid_port(wIndex)) {
  334. if (!ohci_at91_usb_get_power(pdata, wIndex))
  335. *data &= ~cpu_to_le32(RH_PS_PPS);
  336. if (pdata->overcurrent_changed[wIndex])
  337. *data |= cpu_to_le32(RH_PS_OCIC);
  338. if (pdata->overcurrent_status[wIndex])
  339. *data |= cpu_to_le32(RH_PS_POCI);
  340. }
  341. }
  342. out:
  343. return ret;
  344. }
  345. /*-------------------------------------------------------------------------*/
  346. static const struct hc_driver ohci_at91_hc_driver = {
  347. .description = hcd_name,
  348. .product_desc = "AT91 OHCI",
  349. .hcd_priv_size = sizeof(struct ohci_hcd),
  350. /*
  351. * generic hardware linkage
  352. */
  353. .irq = ohci_irq,
  354. .flags = HCD_USB11 | HCD_MEMORY,
  355. /*
  356. * basic lifecycle operations
  357. */
  358. .reset = ohci_at91_reset,
  359. .start = ohci_at91_start,
  360. .stop = ohci_stop,
  361. .shutdown = ohci_shutdown,
  362. /*
  363. * managing i/o requests and associated device resources
  364. */
  365. .urb_enqueue = ohci_urb_enqueue,
  366. .urb_dequeue = ohci_urb_dequeue,
  367. .endpoint_disable = ohci_endpoint_disable,
  368. /*
  369. * scheduling support
  370. */
  371. .get_frame_number = ohci_get_frame,
  372. /*
  373. * root hub support
  374. */
  375. .hub_status_data = ohci_at91_hub_status_data,
  376. .hub_control = ohci_at91_hub_control,
  377. #ifdef CONFIG_PM
  378. .bus_suspend = ohci_bus_suspend,
  379. .bus_resume = ohci_bus_resume,
  380. #endif
  381. .start_port_reset = ohci_start_port_reset,
  382. };
  383. /*-------------------------------------------------------------------------*/
  384. static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
  385. {
  386. struct platform_device *pdev = data;
  387. struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
  388. int val, gpio, port;
  389. /* From the GPIO notifying the over-current situation, find
  390. * out the corresponding port */
  391. at91_for_each_port(port) {
  392. if (gpio_is_valid(pdata->overcurrent_pin[port]) &&
  393. gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
  394. gpio = pdata->overcurrent_pin[port];
  395. break;
  396. }
  397. }
  398. if (port == AT91_MAX_USBH_PORTS) {
  399. dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
  400. return IRQ_HANDLED;
  401. }
  402. val = gpio_get_value(gpio);
  403. /* When notified of an over-current situation, disable power
  404. on the corresponding port, and mark this port in
  405. over-current. */
  406. if (!val) {
  407. ohci_at91_usb_set_power(pdata, port, 0);
  408. pdata->overcurrent_status[port] = 1;
  409. pdata->overcurrent_changed[port] = 1;
  410. }
  411. dev_dbg(& pdev->dev, "overcurrent situation %s\n",
  412. val ? "exited" : "notified");
  413. return IRQ_HANDLED;
  414. }
  415. #ifdef CONFIG_OF
  416. static const struct of_device_id at91_ohci_dt_ids[] = {
  417. { .compatible = "atmel,at91rm9200-ohci" },
  418. { /* sentinel */ }
  419. };
  420. MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
  421. static int ohci_at91_of_init(struct platform_device *pdev)
  422. {
  423. struct device_node *np = pdev->dev.of_node;
  424. int i, gpio, ret;
  425. enum of_gpio_flags flags;
  426. struct at91_usbh_data *pdata;
  427. u32 ports;
  428. if (!np)
  429. return 0;
  430. /* Right now device-tree probed devices don't get dma_mask set.
  431. * Since shared usb code relies on it, set it here for now.
  432. * Once we have dma capability bindings this can go away.
  433. */
  434. ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  435. if (ret)
  436. return ret;
  437. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  438. if (!pdata)
  439. return -ENOMEM;
  440. if (!of_property_read_u32(np, "num-ports", &ports))
  441. pdata->ports = ports;
  442. at91_for_each_port(i) {
  443. gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags);
  444. pdata->vbus_pin[i] = gpio;
  445. if (!gpio_is_valid(gpio))
  446. continue;
  447. pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
  448. }
  449. at91_for_each_port(i)
  450. pdata->overcurrent_pin[i] =
  451. of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
  452. pdev->dev.platform_data = pdata;
  453. return 0;
  454. }
  455. #else
  456. static int ohci_at91_of_init(struct platform_device *pdev)
  457. {
  458. return 0;
  459. }
  460. #endif
  461. /*-------------------------------------------------------------------------*/
  462. static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
  463. {
  464. struct at91_usbh_data *pdata;
  465. int i;
  466. int gpio;
  467. int ret;
  468. ret = ohci_at91_of_init(pdev);
  469. if (ret)
  470. return ret;
  471. pdata = dev_get_platdata(&pdev->dev);
  472. if (pdata) {
  473. at91_for_each_port(i) {
  474. /*
  475. * do not configure PIO if not in relation with
  476. * real USB port on board
  477. */
  478. if (i >= pdata->ports) {
  479. pdata->vbus_pin[i] = -EINVAL;
  480. pdata->overcurrent_pin[i] = -EINVAL;
  481. break;
  482. }
  483. if (!gpio_is_valid(pdata->vbus_pin[i]))
  484. continue;
  485. gpio = pdata->vbus_pin[i];
  486. ret = gpio_request(gpio, "ohci_vbus");
  487. if (ret) {
  488. dev_err(&pdev->dev,
  489. "can't request vbus gpio %d\n", gpio);
  490. continue;
  491. }
  492. ret = gpio_direction_output(gpio,
  493. !pdata->vbus_pin_active_low[i]);
  494. if (ret) {
  495. dev_err(&pdev->dev,
  496. "can't put vbus gpio %d as output %d\n",
  497. gpio, !pdata->vbus_pin_active_low[i]);
  498. gpio_free(gpio);
  499. continue;
  500. }
  501. ohci_at91_usb_set_power(pdata, i, 1);
  502. }
  503. at91_for_each_port(i) {
  504. if (!gpio_is_valid(pdata->overcurrent_pin[i]))
  505. continue;
  506. gpio = pdata->overcurrent_pin[i];
  507. ret = gpio_request(gpio, "ohci_overcurrent");
  508. if (ret) {
  509. dev_err(&pdev->dev,
  510. "can't request overcurrent gpio %d\n",
  511. gpio);
  512. continue;
  513. }
  514. ret = gpio_direction_input(gpio);
  515. if (ret) {
  516. dev_err(&pdev->dev,
  517. "can't configure overcurrent gpio %d as input\n",
  518. gpio);
  519. gpio_free(gpio);
  520. continue;
  521. }
  522. ret = request_irq(gpio_to_irq(gpio),
  523. ohci_hcd_at91_overcurrent_irq,
  524. IRQF_SHARED, "ohci_overcurrent", pdev);
  525. if (ret) {
  526. gpio_free(gpio);
  527. dev_err(&pdev->dev,
  528. "can't get gpio IRQ for overcurrent\n");
  529. }
  530. }
  531. }
  532. device_init_wakeup(&pdev->dev, 1);
  533. return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
  534. }
  535. static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
  536. {
  537. struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
  538. int i;
  539. if (pdata) {
  540. at91_for_each_port(i) {
  541. if (!gpio_is_valid(pdata->vbus_pin[i]))
  542. continue;
  543. ohci_at91_usb_set_power(pdata, i, 0);
  544. gpio_free(pdata->vbus_pin[i]);
  545. }
  546. at91_for_each_port(i) {
  547. if (!gpio_is_valid(pdata->overcurrent_pin[i]))
  548. continue;
  549. free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
  550. gpio_free(pdata->overcurrent_pin[i]);
  551. }
  552. }
  553. device_init_wakeup(&pdev->dev, 0);
  554. usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
  555. return 0;
  556. }
  557. #ifdef CONFIG_PM
  558. static int
  559. ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
  560. {
  561. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  562. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  563. if (device_may_wakeup(&pdev->dev))
  564. enable_irq_wake(hcd->irq);
  565. /*
  566. * The integrated transceivers seem unable to notice disconnect,
  567. * reconnect, or wakeup without the 48 MHz clock active. so for
  568. * correctness, always discard connection state (using reset).
  569. *
  570. * REVISIT: some boards will be able to turn VBUS off...
  571. */
  572. if (at91_suspend_entering_slow_clock()) {
  573. ohci_usb_reset (ohci);
  574. /* flush the writes */
  575. (void) ohci_readl (ohci, &ohci->regs->control);
  576. at91_stop_clock();
  577. }
  578. return 0;
  579. }
  580. static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
  581. {
  582. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  583. if (device_may_wakeup(&pdev->dev))
  584. disable_irq_wake(hcd->irq);
  585. if (!clocked)
  586. at91_start_clock();
  587. ohci_resume(hcd, false);
  588. return 0;
  589. }
  590. #else
  591. #define ohci_hcd_at91_drv_suspend NULL
  592. #define ohci_hcd_at91_drv_resume NULL
  593. #endif
  594. MODULE_ALIAS("platform:at91_ohci");
  595. static struct platform_driver ohci_hcd_at91_driver = {
  596. .probe = ohci_hcd_at91_drv_probe,
  597. .remove = ohci_hcd_at91_drv_remove,
  598. .shutdown = usb_hcd_platform_shutdown,
  599. .suspend = ohci_hcd_at91_drv_suspend,
  600. .resume = ohci_hcd_at91_drv_resume,
  601. .driver = {
  602. .name = "at91_ohci",
  603. .owner = THIS_MODULE,
  604. .of_match_table = of_match_ptr(at91_ohci_dt_ids),
  605. },
  606. };