core.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  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_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_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 = devm_extcon_register_notifier(ci->dev, id->edev,
  637. EXTCON_USB_HOST, &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 = devm_extcon_register_notifier(ci->dev, vbus->edev,
  647. EXTCON_USB, &vbus->nb);
  648. if (ret < 0) {
  649. dev_err(ci->dev, "register VBUS failed\n");
  650. return ret;
  651. }
  652. }
  653. return 0;
  654. }
  655. static DEFINE_IDA(ci_ida);
  656. struct platform_device *ci_hdrc_add_device(struct device *dev,
  657. struct resource *res, int nres,
  658. struct ci_hdrc_platform_data *platdata)
  659. {
  660. struct platform_device *pdev;
  661. int id, ret;
  662. ret = ci_get_platdata(dev, platdata);
  663. if (ret)
  664. return ERR_PTR(ret);
  665. id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
  666. if (id < 0)
  667. return ERR_PTR(id);
  668. pdev = platform_device_alloc("ci_hdrc", id);
  669. if (!pdev) {
  670. ret = -ENOMEM;
  671. goto put_id;
  672. }
  673. pdev->dev.parent = dev;
  674. pdev->dev.dma_mask = dev->dma_mask;
  675. pdev->dev.dma_parms = dev->dma_parms;
  676. dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
  677. ret = platform_device_add_resources(pdev, res, nres);
  678. if (ret)
  679. goto err;
  680. ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
  681. if (ret)
  682. goto err;
  683. ret = platform_device_add(pdev);
  684. if (ret)
  685. goto err;
  686. return pdev;
  687. err:
  688. platform_device_put(pdev);
  689. put_id:
  690. ida_simple_remove(&ci_ida, id);
  691. return ERR_PTR(ret);
  692. }
  693. EXPORT_SYMBOL_GPL(ci_hdrc_add_device);
  694. void ci_hdrc_remove_device(struct platform_device *pdev)
  695. {
  696. int id = pdev->id;
  697. platform_device_unregister(pdev);
  698. ida_simple_remove(&ci_ida, id);
  699. }
  700. EXPORT_SYMBOL_GPL(ci_hdrc_remove_device);
  701. static inline void ci_role_destroy(struct ci_hdrc *ci)
  702. {
  703. ci_hdrc_gadget_destroy(ci);
  704. ci_hdrc_host_destroy(ci);
  705. if (ci->is_otg)
  706. ci_hdrc_otg_destroy(ci);
  707. }
  708. static void ci_get_otg_capable(struct ci_hdrc *ci)
  709. {
  710. if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)
  711. ci->is_otg = false;
  712. else
  713. ci->is_otg = (hw_read(ci, CAP_DCCPARAMS,
  714. DCCPARAMS_DC | DCCPARAMS_HC)
  715. == (DCCPARAMS_DC | DCCPARAMS_HC));
  716. if (ci->is_otg) {
  717. dev_dbg(ci->dev, "It is OTG capable controller\n");
  718. /* Disable and clear all OTG irq */
  719. hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
  720. OTGSC_INT_STATUS_BITS);
  721. }
  722. }
  723. static int ci_hdrc_probe(struct platform_device *pdev)
  724. {
  725. struct device *dev = &pdev->dev;
  726. struct ci_hdrc *ci;
  727. struct resource *res;
  728. void __iomem *base;
  729. int ret;
  730. enum usb_dr_mode dr_mode;
  731. if (!dev_get_platdata(dev)) {
  732. dev_err(dev, "platform data missing\n");
  733. return -ENODEV;
  734. }
  735. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  736. base = devm_ioremap_resource(dev, res);
  737. if (IS_ERR(base))
  738. return PTR_ERR(base);
  739. ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
  740. if (!ci)
  741. return -ENOMEM;
  742. spin_lock_init(&ci->lock);
  743. ci->dev = dev;
  744. ci->platdata = dev_get_platdata(dev);
  745. ci->imx28_write_fix = !!(ci->platdata->flags &
  746. CI_HDRC_IMX28_WRITE_FIX);
  747. ci->supports_runtime_pm = !!(ci->platdata->flags &
  748. CI_HDRC_SUPPORTS_RUNTIME_PM);
  749. ret = hw_device_init(ci, base);
  750. if (ret < 0) {
  751. dev_err(dev, "can't initialize hardware\n");
  752. return -ENODEV;
  753. }
  754. if (ci->platdata->phy) {
  755. ci->phy = ci->platdata->phy;
  756. } else if (ci->platdata->usb_phy) {
  757. ci->usb_phy = ci->platdata->usb_phy;
  758. } else {
  759. ci->phy = devm_phy_get(dev->parent, "usb-phy");
  760. ci->usb_phy = devm_usb_get_phy(dev->parent, USB_PHY_TYPE_USB2);
  761. /* if both generic PHY and USB PHY layers aren't enabled */
  762. if (PTR_ERR(ci->phy) == -ENOSYS &&
  763. PTR_ERR(ci->usb_phy) == -ENXIO)
  764. return -ENXIO;
  765. if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy))
  766. return -EPROBE_DEFER;
  767. if (IS_ERR(ci->phy))
  768. ci->phy = NULL;
  769. else if (IS_ERR(ci->usb_phy))
  770. ci->usb_phy = NULL;
  771. }
  772. ret = ci_usb_phy_init(ci);
  773. if (ret) {
  774. dev_err(dev, "unable to init phy: %d\n", ret);
  775. return ret;
  776. }
  777. ci->hw_bank.phys = res->start;
  778. ci->irq = platform_get_irq(pdev, 0);
  779. if (ci->irq < 0) {
  780. dev_err(dev, "missing IRQ\n");
  781. ret = ci->irq;
  782. goto deinit_phy;
  783. }
  784. ci_get_otg_capable(ci);
  785. dr_mode = ci->platdata->dr_mode;
  786. /* initialize role(s) before the interrupt is requested */
  787. if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
  788. ret = ci_hdrc_host_init(ci);
  789. if (ret)
  790. dev_info(dev, "doesn't support host\n");
  791. }
  792. if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
  793. ret = ci_hdrc_gadget_init(ci);
  794. if (ret)
  795. dev_info(dev, "doesn't support gadget\n");
  796. }
  797. if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
  798. dev_err(dev, "no supported roles\n");
  799. ret = -ENODEV;
  800. goto deinit_phy;
  801. }
  802. if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) {
  803. ret = ci_hdrc_otg_init(ci);
  804. if (ret) {
  805. dev_err(dev, "init otg fails, ret = %d\n", ret);
  806. goto stop;
  807. }
  808. }
  809. if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
  810. if (ci->is_otg) {
  811. ci->role = ci_otg_role(ci);
  812. /* Enable ID change irq */
  813. hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE);
  814. } else {
  815. /*
  816. * If the controller is not OTG capable, but support
  817. * role switch, the defalt role is gadget, and the
  818. * user can switch it through debugfs.
  819. */
  820. ci->role = CI_ROLE_GADGET;
  821. }
  822. } else {
  823. ci->role = ci->roles[CI_ROLE_HOST]
  824. ? CI_ROLE_HOST
  825. : CI_ROLE_GADGET;
  826. }
  827. if (!ci_otg_is_fsm_mode(ci)) {
  828. /* only update vbus status for peripheral */
  829. if (ci->role == CI_ROLE_GADGET)
  830. ci_handle_vbus_change(ci);
  831. ret = ci_role_start(ci, ci->role);
  832. if (ret) {
  833. dev_err(dev, "can't start %s role\n",
  834. ci_role(ci)->name);
  835. goto stop;
  836. }
  837. }
  838. platform_set_drvdata(pdev, ci);
  839. ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED,
  840. ci->platdata->name, ci);
  841. if (ret)
  842. goto stop;
  843. ret = ci_extcon_register(ci);
  844. if (ret)
  845. goto stop;
  846. if (ci->supports_runtime_pm) {
  847. pm_runtime_set_active(&pdev->dev);
  848. pm_runtime_enable(&pdev->dev);
  849. pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
  850. pm_runtime_mark_last_busy(ci->dev);
  851. pm_runtime_use_autosuspend(&pdev->dev);
  852. }
  853. if (ci_otg_is_fsm_mode(ci))
  854. ci_hdrc_otg_fsm_start(ci);
  855. device_set_wakeup_capable(&pdev->dev, true);
  856. ret = dbg_create_files(ci);
  857. if (!ret)
  858. return 0;
  859. stop:
  860. ci_role_destroy(ci);
  861. deinit_phy:
  862. ci_usb_phy_exit(ci);
  863. return ret;
  864. }
  865. static int ci_hdrc_remove(struct platform_device *pdev)
  866. {
  867. struct ci_hdrc *ci = platform_get_drvdata(pdev);
  868. if (ci->supports_runtime_pm) {
  869. pm_runtime_get_sync(&pdev->dev);
  870. pm_runtime_disable(&pdev->dev);
  871. pm_runtime_put_noidle(&pdev->dev);
  872. }
  873. dbg_remove_files(ci);
  874. ci_role_destroy(ci);
  875. ci_hdrc_enter_lpm(ci, true);
  876. ci_usb_phy_exit(ci);
  877. return 0;
  878. }
  879. #ifdef CONFIG_PM
  880. /* Prepare wakeup by SRP before suspend */
  881. static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci)
  882. {
  883. if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
  884. !hw_read_otgsc(ci, OTGSC_ID)) {
  885. hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP,
  886. PORTSC_PP);
  887. hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN,
  888. PORTSC_WKCN);
  889. }
  890. }
  891. /* Handle SRP when wakeup by data pulse */
  892. static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci)
  893. {
  894. if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
  895. (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) {
  896. if (!hw_read_otgsc(ci, OTGSC_ID)) {
  897. ci->fsm.a_srp_det = 1;
  898. ci->fsm.a_bus_drop = 0;
  899. } else {
  900. ci->fsm.id = 1;
  901. }
  902. ci_otg_queue_work(ci);
  903. }
  904. }
  905. static void ci_controller_suspend(struct ci_hdrc *ci)
  906. {
  907. disable_irq(ci->irq);
  908. ci_hdrc_enter_lpm(ci, true);
  909. if (ci->platdata->phy_clkgate_delay_us)
  910. usleep_range(ci->platdata->phy_clkgate_delay_us,
  911. ci->platdata->phy_clkgate_delay_us + 50);
  912. usb_phy_set_suspend(ci->usb_phy, 1);
  913. ci->in_lpm = true;
  914. enable_irq(ci->irq);
  915. }
  916. static int ci_controller_resume(struct device *dev)
  917. {
  918. struct ci_hdrc *ci = dev_get_drvdata(dev);
  919. dev_dbg(dev, "at %s\n", __func__);
  920. if (!ci->in_lpm) {
  921. WARN_ON(1);
  922. return 0;
  923. }
  924. ci_hdrc_enter_lpm(ci, false);
  925. if (ci->usb_phy) {
  926. usb_phy_set_suspend(ci->usb_phy, 0);
  927. usb_phy_set_wakeup(ci->usb_phy, false);
  928. hw_wait_phy_stable();
  929. }
  930. ci->in_lpm = false;
  931. if (ci->wakeup_int) {
  932. ci->wakeup_int = false;
  933. pm_runtime_mark_last_busy(ci->dev);
  934. pm_runtime_put_autosuspend(ci->dev);
  935. enable_irq(ci->irq);
  936. if (ci_otg_is_fsm_mode(ci))
  937. ci_otg_fsm_wakeup_by_srp(ci);
  938. }
  939. return 0;
  940. }
  941. #ifdef CONFIG_PM_SLEEP
  942. static int ci_suspend(struct device *dev)
  943. {
  944. struct ci_hdrc *ci = dev_get_drvdata(dev);
  945. if (ci->wq)
  946. flush_workqueue(ci->wq);
  947. /*
  948. * Controller needs to be active during suspend, otherwise the core
  949. * may run resume when the parent is at suspend if other driver's
  950. * suspend fails, it occurs before parent's suspend has not started,
  951. * but the core suspend has finished.
  952. */
  953. if (ci->in_lpm)
  954. pm_runtime_resume(dev);
  955. if (ci->in_lpm) {
  956. WARN_ON(1);
  957. return 0;
  958. }
  959. if (device_may_wakeup(dev)) {
  960. if (ci_otg_is_fsm_mode(ci))
  961. ci_otg_fsm_suspend_for_srp(ci);
  962. usb_phy_set_wakeup(ci->usb_phy, true);
  963. enable_irq_wake(ci->irq);
  964. }
  965. ci_controller_suspend(ci);
  966. return 0;
  967. }
  968. static int ci_resume(struct device *dev)
  969. {
  970. struct ci_hdrc *ci = dev_get_drvdata(dev);
  971. int ret;
  972. if (device_may_wakeup(dev))
  973. disable_irq_wake(ci->irq);
  974. ret = ci_controller_resume(dev);
  975. if (ret)
  976. return ret;
  977. if (ci->supports_runtime_pm) {
  978. pm_runtime_disable(dev);
  979. pm_runtime_set_active(dev);
  980. pm_runtime_enable(dev);
  981. }
  982. return ret;
  983. }
  984. #endif /* CONFIG_PM_SLEEP */
  985. static int ci_runtime_suspend(struct device *dev)
  986. {
  987. struct ci_hdrc *ci = dev_get_drvdata(dev);
  988. dev_dbg(dev, "at %s\n", __func__);
  989. if (ci->in_lpm) {
  990. WARN_ON(1);
  991. return 0;
  992. }
  993. if (ci_otg_is_fsm_mode(ci))
  994. ci_otg_fsm_suspend_for_srp(ci);
  995. usb_phy_set_wakeup(ci->usb_phy, true);
  996. ci_controller_suspend(ci);
  997. return 0;
  998. }
  999. static int ci_runtime_resume(struct device *dev)
  1000. {
  1001. return ci_controller_resume(dev);
  1002. }
  1003. #endif /* CONFIG_PM */
  1004. static const struct dev_pm_ops ci_pm_ops = {
  1005. SET_SYSTEM_SLEEP_PM_OPS(ci_suspend, ci_resume)
  1006. SET_RUNTIME_PM_OPS(ci_runtime_suspend, ci_runtime_resume, NULL)
  1007. };
  1008. static struct platform_driver ci_hdrc_driver = {
  1009. .probe = ci_hdrc_probe,
  1010. .remove = ci_hdrc_remove,
  1011. .driver = {
  1012. .name = "ci_hdrc",
  1013. .pm = &ci_pm_ops,
  1014. },
  1015. };
  1016. static int __init ci_hdrc_platform_register(void)
  1017. {
  1018. ci_hdrc_host_driver_init();
  1019. return platform_driver_register(&ci_hdrc_driver);
  1020. }
  1021. module_init(ci_hdrc_platform_register);
  1022. static void __exit ci_hdrc_platform_unregister(void)
  1023. {
  1024. platform_driver_unregister(&ci_hdrc_driver);
  1025. }
  1026. module_exit(ci_hdrc_platform_unregister);
  1027. MODULE_ALIAS("platform:ci_hdrc");
  1028. MODULE_LICENSE("GPL v2");
  1029. MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
  1030. MODULE_DESCRIPTION("ChipIdea HDRC Driver");