core.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /*
  2. * core.c - ChipIdea USB IP core family device controller
  3. *
  4. * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
  5. *
  6. * Author: David Lopo
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. /*
  13. * Description: ChipIdea USB IP core family device controller
  14. *
  15. * This driver is composed of several blocks:
  16. * - HW: hardware interface
  17. * - DBG: debug facilities (optional)
  18. * - UTIL: utilities
  19. * - ISR: interrupts handling
  20. * - ENDPT: endpoint operations (Gadget API)
  21. * - GADGET: gadget operations (Gadget API)
  22. * - BUS: bus glue code, bus abstraction layer
  23. *
  24. * Compile Options
  25. * - STALL_IN: non-empty bulk-in pipes cannot be halted
  26. * if defined mass storage compliance succeeds but with warnings
  27. * => case 4: Hi > Dn
  28. * => case 5: Hi > Di
  29. * => case 8: Hi <> Do
  30. * if undefined usbtest 13 fails
  31. * - TRACE: enable function tracing (depends on DEBUG)
  32. *
  33. * Main Features
  34. * - Chapter 9 & Mass Storage Compliance with Gadget File Storage
  35. * - Chapter 9 Compliance with Gadget Zero (STALL_IN undefined)
  36. * - Normal & LPM support
  37. *
  38. * USBTEST Report
  39. * - OK: 0-12, 13 (STALL_IN defined) & 14
  40. * - Not Supported: 15 & 16 (ISO)
  41. *
  42. * TODO List
  43. * - Suspend & Remote Wakeup
  44. */
  45. #include <linux/delay.h>
  46. #include <linux/device.h>
  47. #include <linux/dma-mapping.h>
  48. #include <linux/extcon.h>
  49. #include <linux/phy/phy.h>
  50. #include <linux/platform_device.h>
  51. #include <linux/module.h>
  52. #include <linux/idr.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/io.h>
  55. #include <linux/kernel.h>
  56. #include <linux/slab.h>
  57. #include <linux/pm_runtime.h>
  58. #include <linux/usb/ch9.h>
  59. #include <linux/usb/gadget.h>
  60. #include <linux/usb/otg.h>
  61. #include <linux/usb/chipidea.h>
  62. #include <linux/usb/of.h>
  63. #include <linux/of.h>
  64. #include <linux/phy.h>
  65. #include <linux/regulator/consumer.h>
  66. #include <linux/usb/ehci_def.h>
  67. #include "ci.h"
  68. #include "udc.h"
  69. #include "bits.h"
  70. #include "host.h"
  71. #include "otg.h"
  72. #include "otg_fsm.h"
  73. /* Controller register map */
  74. static const u8 ci_regs_nolpm[] = {
  75. [CAP_CAPLENGTH] = 0x00U,
  76. [CAP_HCCPARAMS] = 0x08U,
  77. [CAP_DCCPARAMS] = 0x24U,
  78. [CAP_TESTMODE] = 0x38U,
  79. [OP_USBCMD] = 0x00U,
  80. [OP_USBSTS] = 0x04U,
  81. [OP_USBINTR] = 0x08U,
  82. [OP_DEVICEADDR] = 0x14U,
  83. [OP_ENDPTLISTADDR] = 0x18U,
  84. [OP_TTCTRL] = 0x1CU,
  85. [OP_BURSTSIZE] = 0x20U,
  86. [OP_PORTSC] = 0x44U,
  87. [OP_DEVLC] = 0x84U,
  88. [OP_OTGSC] = 0x64U,
  89. [OP_USBMODE] = 0x68U,
  90. [OP_ENDPTSETUPSTAT] = 0x6CU,
  91. [OP_ENDPTPRIME] = 0x70U,
  92. [OP_ENDPTFLUSH] = 0x74U,
  93. [OP_ENDPTSTAT] = 0x78U,
  94. [OP_ENDPTCOMPLETE] = 0x7CU,
  95. [OP_ENDPTCTRL] = 0x80U,
  96. };
  97. static const u8 ci_regs_lpm[] = {
  98. [CAP_CAPLENGTH] = 0x00U,
  99. [CAP_HCCPARAMS] = 0x08U,
  100. [CAP_DCCPARAMS] = 0x24U,
  101. [CAP_TESTMODE] = 0xFCU,
  102. [OP_USBCMD] = 0x00U,
  103. [OP_USBSTS] = 0x04U,
  104. [OP_USBINTR] = 0x08U,
  105. [OP_DEVICEADDR] = 0x14U,
  106. [OP_ENDPTLISTADDR] = 0x18U,
  107. [OP_TTCTRL] = 0x1CU,
  108. [OP_BURSTSIZE] = 0x20U,
  109. [OP_PORTSC] = 0x44U,
  110. [OP_DEVLC] = 0x84U,
  111. [OP_OTGSC] = 0xC4U,
  112. [OP_USBMODE] = 0xC8U,
  113. [OP_ENDPTSETUPSTAT] = 0xD8U,
  114. [OP_ENDPTPRIME] = 0xDCU,
  115. [OP_ENDPTFLUSH] = 0xE0U,
  116. [OP_ENDPTSTAT] = 0xE4U,
  117. [OP_ENDPTCOMPLETE] = 0xE8U,
  118. [OP_ENDPTCTRL] = 0xECU,
  119. };
  120. static void hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm)
  121. {
  122. int i;
  123. for (i = 0; i < OP_ENDPTCTRL; i++)
  124. ci->hw_bank.regmap[i] =
  125. (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) +
  126. (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]);
  127. for (; i <= OP_LAST; i++)
  128. ci->hw_bank.regmap[i] = ci->hw_bank.op +
  129. 4 * (i - OP_ENDPTCTRL) +
  130. (is_lpm
  131. ? ci_regs_lpm[OP_ENDPTCTRL]
  132. : ci_regs_nolpm[OP_ENDPTCTRL]);
  133. }
  134. static enum ci_revision ci_get_revision(struct ci_hdrc *ci)
  135. {
  136. int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION);
  137. enum ci_revision rev = CI_REVISION_UNKNOWN;
  138. if (ver == 0x2) {
  139. rev = hw_read_id_reg(ci, ID_ID, REVISION)
  140. >> __ffs(REVISION);
  141. rev += CI_REVISION_20;
  142. } else if (ver == 0x0) {
  143. rev = CI_REVISION_1X;
  144. }
  145. return rev;
  146. }
  147. /**
  148. * hw_read_intr_enable: returns interrupt enable register
  149. *
  150. * @ci: the controller
  151. *
  152. * This function returns register data
  153. */
  154. u32 hw_read_intr_enable(struct ci_hdrc *ci)
  155. {
  156. return hw_read(ci, OP_USBINTR, ~0);
  157. }
  158. /**
  159. * hw_read_intr_status: returns interrupt status register
  160. *
  161. * @ci: the controller
  162. *
  163. * This function returns register data
  164. */
  165. u32 hw_read_intr_status(struct ci_hdrc *ci)
  166. {
  167. return hw_read(ci, OP_USBSTS, ~0);
  168. }
  169. /**
  170. * hw_port_test_set: writes port test mode (execute without interruption)
  171. * @mode: new value
  172. *
  173. * This function returns an error code
  174. */
  175. int hw_port_test_set(struct ci_hdrc *ci, u8 mode)
  176. {
  177. const u8 TEST_MODE_MAX = 7;
  178. if (mode > TEST_MODE_MAX)
  179. return -EINVAL;
  180. hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC));
  181. return 0;
  182. }
  183. /**
  184. * hw_port_test_get: reads port test mode value
  185. *
  186. * @ci: the controller
  187. *
  188. * This function returns port test mode value
  189. */
  190. u8 hw_port_test_get(struct ci_hdrc *ci)
  191. {
  192. return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
  193. }
  194. static void hw_wait_phy_stable(void)
  195. {
  196. /*
  197. * The phy needs some delay to output the stable status from low
  198. * power mode. And for OTGSC, the status inputs are debounced
  199. * using a 1 ms time constant, so, delay 2ms for controller to get
  200. * the stable status, like vbus and id when the phy leaves low power.
  201. */
  202. usleep_range(2000, 2500);
  203. }
  204. /* The PHY enters/leaves low power mode */
  205. static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable)
  206. {
  207. enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC;
  208. bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm)));
  209. if (enable && !lpm)
  210. hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
  211. PORTSC_PHCD(ci->hw_bank.lpm));
  212. else if (!enable && lpm)
  213. hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
  214. 0);
  215. }
  216. static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
  217. {
  218. u32 reg;
  219. /* bank is a module variable */
  220. ci->hw_bank.abs = base;
  221. ci->hw_bank.cap = ci->hw_bank.abs;
  222. ci->hw_bank.cap += ci->platdata->capoffset;
  223. ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff);
  224. hw_alloc_regmap(ci, false);
  225. reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
  226. __ffs(HCCPARAMS_LEN);
  227. ci->hw_bank.lpm = reg;
  228. if (reg)
  229. hw_alloc_regmap(ci, !!reg);
  230. ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs;
  231. ci->hw_bank.size += OP_LAST;
  232. ci->hw_bank.size /= sizeof(u32);
  233. reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
  234. __ffs(DCCPARAMS_DEN);
  235. ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
  236. if (ci->hw_ep_max > ENDPT_MAX)
  237. return -ENODEV;
  238. ci_hdrc_enter_lpm(ci, false);
  239. /* Disable all interrupts bits */
  240. hw_write(ci, OP_USBINTR, 0xffffffff, 0);
  241. /* Clear all interrupts status bits*/
  242. hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff);
  243. ci->rev = ci_get_revision(ci);
  244. dev_dbg(ci->dev,
  245. "ChipIdea HDRC found, revision: %d, lpm: %d; cap: %p op: %p\n",
  246. ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op);
  247. /* setup lock mode ? */
  248. /* ENDPTSETUPSTAT is '0' by default */
  249. /* HCSPARAMS.bf.ppc SHOULD BE zero for device */
  250. return 0;
  251. }
  252. static void hw_phymode_configure(struct ci_hdrc *ci)
  253. {
  254. u32 portsc, lpm, sts = 0;
  255. switch (ci->platdata->phy_mode) {
  256. case USBPHY_INTERFACE_MODE_UTMI:
  257. portsc = PORTSC_PTS(PTS_UTMI);
  258. lpm = DEVLC_PTS(PTS_UTMI);
  259. break;
  260. case USBPHY_INTERFACE_MODE_UTMIW:
  261. portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
  262. lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
  263. break;
  264. case USBPHY_INTERFACE_MODE_ULPI:
  265. portsc = PORTSC_PTS(PTS_ULPI);
  266. lpm = DEVLC_PTS(PTS_ULPI);
  267. break;
  268. case USBPHY_INTERFACE_MODE_SERIAL:
  269. portsc = PORTSC_PTS(PTS_SERIAL);
  270. lpm = DEVLC_PTS(PTS_SERIAL);
  271. sts = 1;
  272. break;
  273. case USBPHY_INTERFACE_MODE_HSIC:
  274. portsc = PORTSC_PTS(PTS_HSIC);
  275. lpm = DEVLC_PTS(PTS_HSIC);
  276. break;
  277. default:
  278. return;
  279. }
  280. if (ci->hw_bank.lpm) {
  281. hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
  282. if (sts)
  283. hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS);
  284. } else {
  285. hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc);
  286. if (sts)
  287. hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS);
  288. }
  289. }
  290. /**
  291. * _ci_usb_phy_init: initialize phy taking in account both phy and usb_phy
  292. * interfaces
  293. * @ci: the controller
  294. *
  295. * This function returns an error code if the phy failed to init
  296. */
  297. static int _ci_usb_phy_init(struct ci_hdrc *ci)
  298. {
  299. int ret;
  300. if (ci->phy) {
  301. ret = phy_init(ci->phy);
  302. if (ret)
  303. return ret;
  304. ret = phy_power_on(ci->phy);
  305. if (ret) {
  306. phy_exit(ci->phy);
  307. return ret;
  308. }
  309. } else {
  310. ret = usb_phy_init(ci->usb_phy);
  311. }
  312. return ret;
  313. }
  314. /**
  315. * _ci_usb_phy_exit: deinitialize phy taking in account both phy and usb_phy
  316. * interfaces
  317. * @ci: the controller
  318. */
  319. static void ci_usb_phy_exit(struct ci_hdrc *ci)
  320. {
  321. if (ci->phy) {
  322. phy_power_off(ci->phy);
  323. phy_exit(ci->phy);
  324. } else {
  325. usb_phy_shutdown(ci->usb_phy);
  326. }
  327. }
  328. /**
  329. * ci_usb_phy_init: initialize phy according to different phy type
  330. * @ci: the controller
  331. *
  332. * This function returns an error code if usb_phy_init has failed
  333. */
  334. static int ci_usb_phy_init(struct ci_hdrc *ci)
  335. {
  336. int ret;
  337. switch (ci->platdata->phy_mode) {
  338. case USBPHY_INTERFACE_MODE_UTMI:
  339. case USBPHY_INTERFACE_MODE_UTMIW:
  340. case USBPHY_INTERFACE_MODE_HSIC:
  341. ret = _ci_usb_phy_init(ci);
  342. if (!ret)
  343. hw_wait_phy_stable();
  344. else
  345. return ret;
  346. hw_phymode_configure(ci);
  347. break;
  348. case USBPHY_INTERFACE_MODE_ULPI:
  349. case USBPHY_INTERFACE_MODE_SERIAL:
  350. hw_phymode_configure(ci);
  351. ret = _ci_usb_phy_init(ci);
  352. if (ret)
  353. return ret;
  354. break;
  355. default:
  356. ret = _ci_usb_phy_init(ci);
  357. if (!ret)
  358. hw_wait_phy_stable();
  359. }
  360. return ret;
  361. }
  362. /**
  363. * ci_platform_configure: do controller configure
  364. * @ci: the controller
  365. *
  366. */
  367. void ci_platform_configure(struct ci_hdrc *ci)
  368. {
  369. bool is_device_mode, is_host_mode;
  370. is_device_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_DC;
  371. is_host_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_HC;
  372. if (is_device_mode &&
  373. (ci->platdata->flags & CI_HDRC_DISABLE_DEVICE_STREAMING))
  374. hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
  375. if (is_host_mode &&
  376. (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING))
  377. hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
  378. if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) {
  379. if (ci->hw_bank.lpm)
  380. hw_write(ci, OP_DEVLC, DEVLC_PFSC, DEVLC_PFSC);
  381. else
  382. hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC);
  383. }
  384. if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA)
  385. hw_write(ci, OP_TTCTRL, TTCTRL_TTHA_MASK, TTCTRL_TTHA);
  386. hw_write(ci, OP_USBCMD, 0xff0000, ci->platdata->itc_setting << 16);
  387. if (ci->platdata->flags & CI_HDRC_OVERRIDE_AHB_BURST)
  388. hw_write_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK,
  389. ci->platdata->ahb_burst_config);
  390. /* override burst size, take effect only when ahb_burst_config is 0 */
  391. if (!hw_read_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK)) {
  392. if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST)
  393. hw_write(ci, OP_BURSTSIZE, TX_BURST_MASK,
  394. ci->platdata->tx_burst_size << __ffs(TX_BURST_MASK));
  395. if (ci->platdata->flags & CI_HDRC_OVERRIDE_RX_BURST)
  396. hw_write(ci, OP_BURSTSIZE, RX_BURST_MASK,
  397. ci->platdata->rx_burst_size);
  398. }
  399. }
  400. /**
  401. * hw_controller_reset: do controller reset
  402. * @ci: the controller
  403. *
  404. * This function returns an error code
  405. */
  406. static int hw_controller_reset(struct ci_hdrc *ci)
  407. {
  408. int count = 0;
  409. hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST);
  410. while (hw_read(ci, OP_USBCMD, USBCMD_RST)) {
  411. udelay(10);
  412. if (count++ > 1000)
  413. return -ETIMEDOUT;
  414. }
  415. return 0;
  416. }
  417. /**
  418. * hw_device_reset: resets chip (execute without interruption)
  419. * @ci: the controller
  420. *
  421. * This function returns an error code
  422. */
  423. int hw_device_reset(struct ci_hdrc *ci)
  424. {
  425. int ret;
  426. /* should flush & stop before reset */
  427. hw_write(ci, OP_ENDPTFLUSH, ~0, ~0);
  428. hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
  429. ret = hw_controller_reset(ci);
  430. if (ret) {
  431. dev_err(ci->dev, "error resetting controller, ret=%d\n", ret);
  432. return ret;
  433. }
  434. if (ci->platdata->notify_event)
  435. ci->platdata->notify_event(ci,
  436. CI_HDRC_CONTROLLER_RESET_EVENT);
  437. /* USBMODE should be configured step by step */
  438. hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
  439. hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_DC);
  440. /* HW >= 2.3 */
  441. hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM);
  442. if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) {
  443. pr_err("cannot enter in %s device mode", ci_role(ci)->name);
  444. pr_err("lpm = %i", ci->hw_bank.lpm);
  445. return -ENODEV;
  446. }
  447. ci_platform_configure(ci);
  448. return 0;
  449. }
  450. static irqreturn_t ci_irq(int irq, void *data)
  451. {
  452. struct ci_hdrc *ci = data;
  453. irqreturn_t ret = IRQ_NONE;
  454. u32 otgsc = 0;
  455. if (ci->in_lpm) {
  456. disable_irq_nosync(irq);
  457. ci->wakeup_int = true;
  458. pm_runtime_get(ci->dev);
  459. return IRQ_HANDLED;
  460. }
  461. if (ci->is_otg) {
  462. otgsc = hw_read_otgsc(ci, ~0);
  463. if (ci_otg_is_fsm_mode(ci)) {
  464. ret = ci_otg_fsm_irq(ci);
  465. if (ret == IRQ_HANDLED)
  466. return ret;
  467. }
  468. }
  469. /*
  470. * Handle id change interrupt, it indicates device/host function
  471. * switch.
  472. */
  473. if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) {
  474. ci->id_event = true;
  475. /* Clear ID change irq status */
  476. hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS);
  477. ci_otg_queue_work(ci);
  478. return IRQ_HANDLED;
  479. }
  480. /*
  481. * Handle vbus change interrupt, it indicates device connection
  482. * and disconnection events.
  483. */
  484. if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) {
  485. ci->b_sess_valid_event = true;
  486. /* Clear BSV irq */
  487. hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS);
  488. ci_otg_queue_work(ci);
  489. return IRQ_HANDLED;
  490. }
  491. /* Handle device/host interrupt */
  492. if (ci->role != CI_ROLE_END)
  493. ret = ci_role(ci)->irq(ci);
  494. return ret;
  495. }
  496. static int ci_vbus_notifier(struct notifier_block *nb, unsigned long event,
  497. void *ptr)
  498. {
  499. struct ci_hdrc_cable *vbus = container_of(nb, struct ci_hdrc_cable, nb);
  500. struct ci_hdrc *ci = vbus->ci;
  501. if (event)
  502. vbus->state = true;
  503. else
  504. vbus->state = false;
  505. vbus->changed = true;
  506. ci_irq(ci->irq, ci);
  507. return NOTIFY_DONE;
  508. }
  509. static int ci_id_notifier(struct notifier_block *nb, unsigned long event,
  510. void *ptr)
  511. {
  512. struct ci_hdrc_cable *id = container_of(nb, struct ci_hdrc_cable, nb);
  513. struct ci_hdrc *ci = id->ci;
  514. if (event)
  515. id->state = false;
  516. else
  517. id->state = true;
  518. id->changed = true;
  519. ci_irq(ci->irq, ci);
  520. return NOTIFY_DONE;
  521. }
  522. static int ci_get_platdata(struct device *dev,
  523. struct ci_hdrc_platform_data *platdata)
  524. {
  525. struct extcon_dev *ext_vbus, *ext_id;
  526. struct ci_hdrc_cable *cable;
  527. int ret;
  528. if (!platdata->phy_mode)
  529. platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
  530. if (!platdata->dr_mode)
  531. platdata->dr_mode = usb_get_dr_mode(dev);
  532. if (platdata->dr_mode == USB_DR_MODE_UNKNOWN)
  533. platdata->dr_mode = USB_DR_MODE_OTG;
  534. if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) {
  535. /* Get the vbus regulator */
  536. platdata->reg_vbus = devm_regulator_get(dev, "vbus");
  537. if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
  538. return -EPROBE_DEFER;
  539. } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
  540. /* no vbus regulator is needed */
  541. platdata->reg_vbus = NULL;
  542. } else if (IS_ERR(platdata->reg_vbus)) {
  543. dev_err(dev, "Getting regulator error: %ld\n",
  544. PTR_ERR(platdata->reg_vbus));
  545. return PTR_ERR(platdata->reg_vbus);
  546. }
  547. /* Get TPL support */
  548. if (!platdata->tpl_support)
  549. platdata->tpl_support =
  550. of_usb_host_tpl_support(dev->of_node);
  551. }
  552. if (platdata->dr_mode == USB_DR_MODE_OTG) {
  553. /* We can support HNP and SRP of OTG 2.0 */
  554. platdata->ci_otg_caps.otg_rev = 0x0200;
  555. platdata->ci_otg_caps.hnp_support = true;
  556. platdata->ci_otg_caps.srp_support = true;
  557. /* Update otg capabilities by DT properties */
  558. ret = of_usb_update_otg_caps(dev->of_node,
  559. &platdata->ci_otg_caps);
  560. if (ret)
  561. return ret;
  562. }
  563. if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
  564. platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
  565. of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
  566. &platdata->phy_clkgate_delay_us);
  567. platdata->itc_setting = 1;
  568. of_property_read_u32(dev->of_node, "itc-setting",
  569. &platdata->itc_setting);
  570. ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
  571. &platdata->ahb_burst_config);
  572. if (!ret) {
  573. platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
  574. } else if (ret != -EINVAL) {
  575. dev_err(dev, "failed to get ahb-burst-config\n");
  576. return ret;
  577. }
  578. ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
  579. &platdata->tx_burst_size);
  580. if (!ret) {
  581. platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
  582. } else if (ret != -EINVAL) {
  583. dev_err(dev, "failed to get tx-burst-size-dword\n");
  584. return ret;
  585. }
  586. ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
  587. &platdata->rx_burst_size);
  588. if (!ret) {
  589. platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
  590. } else if (ret != -EINVAL) {
  591. dev_err(dev, "failed to get rx-burst-size-dword\n");
  592. return ret;
  593. }
  594. if (of_find_property(dev->of_node, "non-zero-ttctrl-ttha", NULL))
  595. platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA;
  596. ext_id = ERR_PTR(-ENODEV);
  597. ext_vbus = ERR_PTR(-ENODEV);
  598. if (of_property_read_bool(dev->of_node, "extcon")) {
  599. /* Each one of them is not mandatory */
  600. ext_vbus = extcon_get_edev_by_phandle(dev, 0);
  601. if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV)
  602. return PTR_ERR(ext_vbus);
  603. ext_id = extcon_get_edev_by_phandle(dev, 1);
  604. if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV)
  605. return PTR_ERR(ext_id);
  606. }
  607. cable = &platdata->vbus_extcon;
  608. cable->nb.notifier_call = ci_vbus_notifier;
  609. cable->edev = ext_vbus;
  610. if (!IS_ERR(ext_vbus)) {
  611. ret = extcon_get_cable_state_(cable->edev, EXTCON_USB);
  612. if (ret)
  613. cable->state = true;
  614. else
  615. cable->state = false;
  616. }
  617. cable = &platdata->id_extcon;
  618. cable->nb.notifier_call = ci_id_notifier;
  619. cable->edev = ext_id;
  620. if (!IS_ERR(ext_id)) {
  621. ret = extcon_get_cable_state_(cable->edev, EXTCON_USB_HOST);
  622. if (ret)
  623. cable->state = false;
  624. else
  625. cable->state = true;
  626. }
  627. return 0;
  628. }
  629. static int ci_extcon_register(struct ci_hdrc *ci)
  630. {
  631. struct ci_hdrc_cable *id, *vbus;
  632. int ret;
  633. id = &ci->platdata->id_extcon;
  634. id->ci = ci;
  635. if (!IS_ERR(id->edev)) {
  636. ret = extcon_register_notifier(id->edev, EXTCON_USB_HOST,
  637. &id->nb);
  638. if (ret < 0) {
  639. dev_err(ci->dev, "register ID failed\n");
  640. return ret;
  641. }
  642. }
  643. vbus = &ci->platdata->vbus_extcon;
  644. vbus->ci = ci;
  645. if (!IS_ERR(vbus->edev)) {
  646. ret = extcon_register_notifier(vbus->edev, EXTCON_USB,
  647. &vbus->nb);
  648. if (ret < 0) {
  649. extcon_unregister_notifier(id->edev, EXTCON_USB_HOST,
  650. &id->nb);
  651. dev_err(ci->dev, "register VBUS failed\n");
  652. return ret;
  653. }
  654. }
  655. return 0;
  656. }
  657. static void ci_extcon_unregister(struct ci_hdrc *ci)
  658. {
  659. struct ci_hdrc_cable *cable;
  660. cable = &ci->platdata->id_extcon;
  661. if (!IS_ERR(cable->edev))
  662. extcon_unregister_notifier(cable->edev, EXTCON_USB_HOST,
  663. &cable->nb);
  664. cable = &ci->platdata->vbus_extcon;
  665. if (!IS_ERR(cable->edev))
  666. extcon_unregister_notifier(cable->edev, EXTCON_USB, &cable->nb);
  667. }
  668. static DEFINE_IDA(ci_ida);
  669. struct platform_device *ci_hdrc_add_device(struct device *dev,
  670. struct resource *res, int nres,
  671. struct ci_hdrc_platform_data *platdata)
  672. {
  673. struct platform_device *pdev;
  674. int id, ret;
  675. ret = ci_get_platdata(dev, platdata);
  676. if (ret)
  677. return ERR_PTR(ret);
  678. id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
  679. if (id < 0)
  680. return ERR_PTR(id);
  681. pdev = platform_device_alloc("ci_hdrc", id);
  682. if (!pdev) {
  683. ret = -ENOMEM;
  684. goto put_id;
  685. }
  686. pdev->dev.parent = dev;
  687. pdev->dev.dma_mask = dev->dma_mask;
  688. pdev->dev.dma_parms = dev->dma_parms;
  689. dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
  690. ret = platform_device_add_resources(pdev, res, nres);
  691. if (ret)
  692. goto err;
  693. ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
  694. if (ret)
  695. goto err;
  696. ret = platform_device_add(pdev);
  697. if (ret)
  698. goto err;
  699. return pdev;
  700. err:
  701. platform_device_put(pdev);
  702. put_id:
  703. ida_simple_remove(&ci_ida, id);
  704. return ERR_PTR(ret);
  705. }
  706. EXPORT_SYMBOL_GPL(ci_hdrc_add_device);
  707. void ci_hdrc_remove_device(struct platform_device *pdev)
  708. {
  709. int id = pdev->id;
  710. platform_device_unregister(pdev);
  711. ida_simple_remove(&ci_ida, id);
  712. }
  713. EXPORT_SYMBOL_GPL(ci_hdrc_remove_device);
  714. static inline void ci_role_destroy(struct ci_hdrc *ci)
  715. {
  716. ci_hdrc_gadget_destroy(ci);
  717. ci_hdrc_host_destroy(ci);
  718. if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
  719. ci_hdrc_otg_destroy(ci);
  720. }
  721. static void ci_get_otg_capable(struct ci_hdrc *ci)
  722. {
  723. if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)
  724. ci->is_otg = false;
  725. else
  726. ci->is_otg = (hw_read(ci, CAP_DCCPARAMS,
  727. DCCPARAMS_DC | DCCPARAMS_HC)
  728. == (DCCPARAMS_DC | DCCPARAMS_HC));
  729. if (ci->is_otg) {
  730. dev_dbg(ci->dev, "It is OTG capable controller\n");
  731. /* Disable and clear all OTG irq */
  732. hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
  733. OTGSC_INT_STATUS_BITS);
  734. }
  735. }
  736. static int ci_hdrc_probe(struct platform_device *pdev)
  737. {
  738. struct device *dev = &pdev->dev;
  739. struct ci_hdrc *ci;
  740. struct resource *res;
  741. void __iomem *base;
  742. int ret;
  743. enum usb_dr_mode dr_mode;
  744. if (!dev_get_platdata(dev)) {
  745. dev_err(dev, "platform data missing\n");
  746. return -ENODEV;
  747. }
  748. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  749. base = devm_ioremap_resource(dev, res);
  750. if (IS_ERR(base))
  751. return PTR_ERR(base);
  752. ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
  753. if (!ci)
  754. return -ENOMEM;
  755. spin_lock_init(&ci->lock);
  756. ci->dev = dev;
  757. ci->platdata = dev_get_platdata(dev);
  758. ci->imx28_write_fix = !!(ci->platdata->flags &
  759. CI_HDRC_IMX28_WRITE_FIX);
  760. ci->supports_runtime_pm = !!(ci->platdata->flags &
  761. CI_HDRC_SUPPORTS_RUNTIME_PM);
  762. ret = hw_device_init(ci, base);
  763. if (ret < 0) {
  764. dev_err(dev, "can't initialize hardware\n");
  765. return -ENODEV;
  766. }
  767. if (ci->platdata->phy) {
  768. ci->phy = ci->platdata->phy;
  769. } else if (ci->platdata->usb_phy) {
  770. ci->usb_phy = ci->platdata->usb_phy;
  771. } else {
  772. ci->phy = devm_phy_get(dev->parent, "usb-phy");
  773. ci->usb_phy = devm_usb_get_phy(dev->parent, USB_PHY_TYPE_USB2);
  774. /* if both generic PHY and USB PHY layers aren't enabled */
  775. if (PTR_ERR(ci->phy) == -ENOSYS &&
  776. PTR_ERR(ci->usb_phy) == -ENXIO)
  777. return -ENXIO;
  778. if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy))
  779. return -EPROBE_DEFER;
  780. if (IS_ERR(ci->phy))
  781. ci->phy = NULL;
  782. else if (IS_ERR(ci->usb_phy))
  783. ci->usb_phy = NULL;
  784. }
  785. ret = ci_usb_phy_init(ci);
  786. if (ret) {
  787. dev_err(dev, "unable to init phy: %d\n", ret);
  788. return ret;
  789. }
  790. ci->hw_bank.phys = res->start;
  791. ci->irq = platform_get_irq(pdev, 0);
  792. if (ci->irq < 0) {
  793. dev_err(dev, "missing IRQ\n");
  794. ret = ci->irq;
  795. goto deinit_phy;
  796. }
  797. ci_get_otg_capable(ci);
  798. dr_mode = ci->platdata->dr_mode;
  799. /* initialize role(s) before the interrupt is requested */
  800. if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
  801. ret = ci_hdrc_host_init(ci);
  802. if (ret) {
  803. if (ret == -ENXIO)
  804. dev_info(dev, "doesn't support host\n");
  805. else
  806. goto deinit_phy;
  807. }
  808. }
  809. if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
  810. ret = ci_hdrc_gadget_init(ci);
  811. if (ret) {
  812. if (ret == -ENXIO)
  813. dev_info(dev, "doesn't support gadget\n");
  814. else
  815. goto deinit_host;
  816. }
  817. }
  818. if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
  819. dev_err(dev, "no supported roles\n");
  820. ret = -ENODEV;
  821. goto deinit_gadget;
  822. }
  823. if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) {
  824. ret = ci_hdrc_otg_init(ci);
  825. if (ret) {
  826. dev_err(dev, "init otg fails, ret = %d\n", ret);
  827. goto deinit_gadget;
  828. }
  829. }
  830. if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
  831. if (ci->is_otg) {
  832. ci->role = ci_otg_role(ci);
  833. /* Enable ID change irq */
  834. hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE);
  835. } else {
  836. /*
  837. * If the controller is not OTG capable, but support
  838. * role switch, the defalt role is gadget, and the
  839. * user can switch it through debugfs.
  840. */
  841. ci->role = CI_ROLE_GADGET;
  842. }
  843. } else {
  844. ci->role = ci->roles[CI_ROLE_HOST]
  845. ? CI_ROLE_HOST
  846. : CI_ROLE_GADGET;
  847. }
  848. if (!ci_otg_is_fsm_mode(ci)) {
  849. /* only update vbus status for peripheral */
  850. if (ci->role == CI_ROLE_GADGET)
  851. ci_handle_vbus_change(ci);
  852. ret = ci_role_start(ci, ci->role);
  853. if (ret) {
  854. dev_err(dev, "can't start %s role\n",
  855. ci_role(ci)->name);
  856. goto stop;
  857. }
  858. }
  859. platform_set_drvdata(pdev, ci);
  860. ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED,
  861. ci->platdata->name, ci);
  862. if (ret)
  863. goto stop;
  864. ret = ci_extcon_register(ci);
  865. if (ret)
  866. goto stop;
  867. if (ci->supports_runtime_pm) {
  868. pm_runtime_set_active(&pdev->dev);
  869. pm_runtime_enable(&pdev->dev);
  870. pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
  871. pm_runtime_mark_last_busy(ci->dev);
  872. pm_runtime_use_autosuspend(&pdev->dev);
  873. }
  874. if (ci_otg_is_fsm_mode(ci))
  875. ci_hdrc_otg_fsm_start(ci);
  876. device_set_wakeup_capable(&pdev->dev, true);
  877. ret = dbg_create_files(ci);
  878. if (!ret)
  879. return 0;
  880. ci_extcon_unregister(ci);
  881. stop:
  882. if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
  883. ci_hdrc_otg_destroy(ci);
  884. deinit_gadget:
  885. ci_hdrc_gadget_destroy(ci);
  886. deinit_host:
  887. ci_hdrc_host_destroy(ci);
  888. deinit_phy:
  889. ci_usb_phy_exit(ci);
  890. return ret;
  891. }
  892. static int ci_hdrc_remove(struct platform_device *pdev)
  893. {
  894. struct ci_hdrc *ci = platform_get_drvdata(pdev);
  895. if (ci->supports_runtime_pm) {
  896. pm_runtime_get_sync(&pdev->dev);
  897. pm_runtime_disable(&pdev->dev);
  898. pm_runtime_put_noidle(&pdev->dev);
  899. }
  900. dbg_remove_files(ci);
  901. ci_extcon_unregister(ci);
  902. ci_role_destroy(ci);
  903. ci_hdrc_enter_lpm(ci, true);
  904. ci_usb_phy_exit(ci);
  905. return 0;
  906. }
  907. #ifdef CONFIG_PM
  908. /* Prepare wakeup by SRP before suspend */
  909. static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci)
  910. {
  911. if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
  912. !hw_read_otgsc(ci, OTGSC_ID)) {
  913. hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP,
  914. PORTSC_PP);
  915. hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN,
  916. PORTSC_WKCN);
  917. }
  918. }
  919. /* Handle SRP when wakeup by data pulse */
  920. static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci)
  921. {
  922. if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
  923. (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) {
  924. if (!hw_read_otgsc(ci, OTGSC_ID)) {
  925. ci->fsm.a_srp_det = 1;
  926. ci->fsm.a_bus_drop = 0;
  927. } else {
  928. ci->fsm.id = 1;
  929. }
  930. ci_otg_queue_work(ci);
  931. }
  932. }
  933. static void ci_controller_suspend(struct ci_hdrc *ci)
  934. {
  935. disable_irq(ci->irq);
  936. ci_hdrc_enter_lpm(ci, true);
  937. if (ci->platdata->phy_clkgate_delay_us)
  938. usleep_range(ci->platdata->phy_clkgate_delay_us,
  939. ci->platdata->phy_clkgate_delay_us + 50);
  940. usb_phy_set_suspend(ci->usb_phy, 1);
  941. ci->in_lpm = true;
  942. enable_irq(ci->irq);
  943. }
  944. static int ci_controller_resume(struct device *dev)
  945. {
  946. struct ci_hdrc *ci = dev_get_drvdata(dev);
  947. dev_dbg(dev, "at %s\n", __func__);
  948. if (!ci->in_lpm) {
  949. WARN_ON(1);
  950. return 0;
  951. }
  952. ci_hdrc_enter_lpm(ci, false);
  953. if (ci->usb_phy) {
  954. usb_phy_set_suspend(ci->usb_phy, 0);
  955. usb_phy_set_wakeup(ci->usb_phy, false);
  956. hw_wait_phy_stable();
  957. }
  958. ci->in_lpm = false;
  959. if (ci->wakeup_int) {
  960. ci->wakeup_int = false;
  961. pm_runtime_mark_last_busy(ci->dev);
  962. pm_runtime_put_autosuspend(ci->dev);
  963. enable_irq(ci->irq);
  964. if (ci_otg_is_fsm_mode(ci))
  965. ci_otg_fsm_wakeup_by_srp(ci);
  966. }
  967. return 0;
  968. }
  969. #ifdef CONFIG_PM_SLEEP
  970. static int ci_suspend(struct device *dev)
  971. {
  972. struct ci_hdrc *ci = dev_get_drvdata(dev);
  973. if (ci->wq)
  974. flush_workqueue(ci->wq);
  975. /*
  976. * Controller needs to be active during suspend, otherwise the core
  977. * may run resume when the parent is at suspend if other driver's
  978. * suspend fails, it occurs before parent's suspend has not started,
  979. * but the core suspend has finished.
  980. */
  981. if (ci->in_lpm)
  982. pm_runtime_resume(dev);
  983. if (ci->in_lpm) {
  984. WARN_ON(1);
  985. return 0;
  986. }
  987. if (device_may_wakeup(dev)) {
  988. if (ci_otg_is_fsm_mode(ci))
  989. ci_otg_fsm_suspend_for_srp(ci);
  990. usb_phy_set_wakeup(ci->usb_phy, true);
  991. enable_irq_wake(ci->irq);
  992. }
  993. ci_controller_suspend(ci);
  994. return 0;
  995. }
  996. static int ci_resume(struct device *dev)
  997. {
  998. struct ci_hdrc *ci = dev_get_drvdata(dev);
  999. int ret;
  1000. if (device_may_wakeup(dev))
  1001. disable_irq_wake(ci->irq);
  1002. ret = ci_controller_resume(dev);
  1003. if (ret)
  1004. return ret;
  1005. if (ci->supports_runtime_pm) {
  1006. pm_runtime_disable(dev);
  1007. pm_runtime_set_active(dev);
  1008. pm_runtime_enable(dev);
  1009. }
  1010. return ret;
  1011. }
  1012. #endif /* CONFIG_PM_SLEEP */
  1013. static int ci_runtime_suspend(struct device *dev)
  1014. {
  1015. struct ci_hdrc *ci = dev_get_drvdata(dev);
  1016. dev_dbg(dev, "at %s\n", __func__);
  1017. if (ci->in_lpm) {
  1018. WARN_ON(1);
  1019. return 0;
  1020. }
  1021. if (ci_otg_is_fsm_mode(ci))
  1022. ci_otg_fsm_suspend_for_srp(ci);
  1023. usb_phy_set_wakeup(ci->usb_phy, true);
  1024. ci_controller_suspend(ci);
  1025. return 0;
  1026. }
  1027. static int ci_runtime_resume(struct device *dev)
  1028. {
  1029. return ci_controller_resume(dev);
  1030. }
  1031. #endif /* CONFIG_PM */
  1032. static const struct dev_pm_ops ci_pm_ops = {
  1033. SET_SYSTEM_SLEEP_PM_OPS(ci_suspend, ci_resume)
  1034. SET_RUNTIME_PM_OPS(ci_runtime_suspend, ci_runtime_resume, NULL)
  1035. };
  1036. static struct platform_driver ci_hdrc_driver = {
  1037. .probe = ci_hdrc_probe,
  1038. .remove = ci_hdrc_remove,
  1039. .driver = {
  1040. .name = "ci_hdrc",
  1041. .pm = &ci_pm_ops,
  1042. },
  1043. };
  1044. static int __init ci_hdrc_platform_register(void)
  1045. {
  1046. ci_hdrc_host_driver_init();
  1047. return platform_driver_register(&ci_hdrc_driver);
  1048. }
  1049. module_init(ci_hdrc_platform_register);
  1050. static void __exit ci_hdrc_platform_unregister(void)
  1051. {
  1052. platform_driver_unregister(&ci_hdrc_driver);
  1053. }
  1054. module_exit(ci_hdrc_platform_unregister);
  1055. MODULE_ALIAS("platform:ci_hdrc");
  1056. MODULE_LICENSE("GPL v2");
  1057. MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
  1058. MODULE_DESCRIPTION("ChipIdea HDRC Driver");