core.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities
  26. * - STALL_IN: non-empty bulk-in pipes cannot be halted
  27. * if defined mass storage compliance succeeds but with warnings
  28. * => case 4: Hi > Dn
  29. * => case 5: Hi > Di
  30. * => case 8: Hi <> Do
  31. * if undefined usbtest 13 fails
  32. * - TRACE: enable function tracing (depends on DEBUG)
  33. *
  34. * Main Features
  35. * - Chapter 9 & Mass Storage Compliance with Gadget File Storage
  36. * - Chapter 9 Compliance with Gadget Zero (STALL_IN undefined)
  37. * - Normal & LPM support
  38. *
  39. * USBTEST Report
  40. * - OK: 0-12, 13 (STALL_IN defined) & 14
  41. * - Not Supported: 15 & 16 (ISO)
  42. *
  43. * TODO List
  44. * - OTG
  45. * - Interrupt Traffic
  46. * - GET_STATUS(device) - always reports 0
  47. * - Gadget API (majority of optional features)
  48. * - Suspend & Remote Wakeup
  49. */
  50. #include <linux/delay.h>
  51. #include <linux/device.h>
  52. #include <linux/dma-mapping.h>
  53. #include <linux/platform_device.h>
  54. #include <linux/module.h>
  55. #include <linux/idr.h>
  56. #include <linux/interrupt.h>
  57. #include <linux/io.h>
  58. #include <linux/kernel.h>
  59. #include <linux/slab.h>
  60. #include <linux/pm_runtime.h>
  61. #include <linux/usb/ch9.h>
  62. #include <linux/usb/gadget.h>
  63. #include <linux/usb/otg.h>
  64. #include <linux/usb/chipidea.h>
  65. #include <linux/usb/of.h>
  66. #include <linux/phy.h>
  67. #include <linux/regulator/consumer.h>
  68. #include "ci.h"
  69. #include "udc.h"
  70. #include "bits.h"
  71. #include "host.h"
  72. #include "debug.h"
  73. #include "otg.h"
  74. /* Controller register map */
  75. static uintptr_t ci_regs_nolpm[] = {
  76. [CAP_CAPLENGTH] = 0x000UL,
  77. [CAP_HCCPARAMS] = 0x008UL,
  78. [CAP_DCCPARAMS] = 0x024UL,
  79. [CAP_TESTMODE] = 0x038UL,
  80. [OP_USBCMD] = 0x000UL,
  81. [OP_USBSTS] = 0x004UL,
  82. [OP_USBINTR] = 0x008UL,
  83. [OP_DEVICEADDR] = 0x014UL,
  84. [OP_ENDPTLISTADDR] = 0x018UL,
  85. [OP_PORTSC] = 0x044UL,
  86. [OP_DEVLC] = 0x084UL,
  87. [OP_OTGSC] = 0x064UL,
  88. [OP_USBMODE] = 0x068UL,
  89. [OP_ENDPTSETUPSTAT] = 0x06CUL,
  90. [OP_ENDPTPRIME] = 0x070UL,
  91. [OP_ENDPTFLUSH] = 0x074UL,
  92. [OP_ENDPTSTAT] = 0x078UL,
  93. [OP_ENDPTCOMPLETE] = 0x07CUL,
  94. [OP_ENDPTCTRL] = 0x080UL,
  95. };
  96. static uintptr_t ci_regs_lpm[] = {
  97. [CAP_CAPLENGTH] = 0x000UL,
  98. [CAP_HCCPARAMS] = 0x008UL,
  99. [CAP_DCCPARAMS] = 0x024UL,
  100. [CAP_TESTMODE] = 0x0FCUL,
  101. [OP_USBCMD] = 0x000UL,
  102. [OP_USBSTS] = 0x004UL,
  103. [OP_USBINTR] = 0x008UL,
  104. [OP_DEVICEADDR] = 0x014UL,
  105. [OP_ENDPTLISTADDR] = 0x018UL,
  106. [OP_PORTSC] = 0x044UL,
  107. [OP_DEVLC] = 0x084UL,
  108. [OP_OTGSC] = 0x0C4UL,
  109. [OP_USBMODE] = 0x0C8UL,
  110. [OP_ENDPTSETUPSTAT] = 0x0D8UL,
  111. [OP_ENDPTPRIME] = 0x0DCUL,
  112. [OP_ENDPTFLUSH] = 0x0E0UL,
  113. [OP_ENDPTSTAT] = 0x0E4UL,
  114. [OP_ENDPTCOMPLETE] = 0x0E8UL,
  115. [OP_ENDPTCTRL] = 0x0ECUL,
  116. };
  117. static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm)
  118. {
  119. int i;
  120. kfree(ci->hw_bank.regmap);
  121. ci->hw_bank.regmap = kzalloc((OP_LAST + 1) * sizeof(void *),
  122. GFP_KERNEL);
  123. if (!ci->hw_bank.regmap)
  124. return -ENOMEM;
  125. for (i = 0; i < OP_ENDPTCTRL; i++)
  126. ci->hw_bank.regmap[i] =
  127. (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) +
  128. (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]);
  129. for (; i <= OP_LAST; i++)
  130. ci->hw_bank.regmap[i] = ci->hw_bank.op +
  131. 4 * (i - OP_ENDPTCTRL) +
  132. (is_lpm
  133. ? ci_regs_lpm[OP_ENDPTCTRL]
  134. : ci_regs_nolpm[OP_ENDPTCTRL]);
  135. return 0;
  136. }
  137. /**
  138. * hw_port_test_set: writes port test mode (execute without interruption)
  139. * @mode: new value
  140. *
  141. * This function returns an error code
  142. */
  143. int hw_port_test_set(struct ci_hdrc *ci, u8 mode)
  144. {
  145. const u8 TEST_MODE_MAX = 7;
  146. if (mode > TEST_MODE_MAX)
  147. return -EINVAL;
  148. hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC));
  149. return 0;
  150. }
  151. /**
  152. * hw_port_test_get: reads port test mode value
  153. *
  154. * This function returns port test mode value
  155. */
  156. u8 hw_port_test_get(struct ci_hdrc *ci)
  157. {
  158. return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
  159. }
  160. static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
  161. {
  162. u32 reg;
  163. /* bank is a module variable */
  164. ci->hw_bank.abs = base;
  165. ci->hw_bank.cap = ci->hw_bank.abs;
  166. ci->hw_bank.cap += ci->platdata->capoffset;
  167. ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff);
  168. hw_alloc_regmap(ci, false);
  169. reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
  170. __ffs(HCCPARAMS_LEN);
  171. ci->hw_bank.lpm = reg;
  172. hw_alloc_regmap(ci, !!reg);
  173. ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs;
  174. ci->hw_bank.size += OP_LAST;
  175. ci->hw_bank.size /= sizeof(u32);
  176. reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
  177. __ffs(DCCPARAMS_DEN);
  178. ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
  179. if (ci->hw_ep_max > ENDPT_MAX)
  180. return -ENODEV;
  181. /* Disable all interrupts bits */
  182. hw_write(ci, OP_USBINTR, 0xffffffff, 0);
  183. /* Clear all interrupts status bits*/
  184. hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff);
  185. dev_dbg(ci->dev, "ChipIdea HDRC found, lpm: %d; cap: %p op: %p\n",
  186. ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op);
  187. /* setup lock mode ? */
  188. /* ENDPTSETUPSTAT is '0' by default */
  189. /* HCSPARAMS.bf.ppc SHOULD BE zero for device */
  190. return 0;
  191. }
  192. static void hw_phymode_configure(struct ci_hdrc *ci)
  193. {
  194. u32 portsc, lpm, sts;
  195. switch (ci->platdata->phy_mode) {
  196. case USBPHY_INTERFACE_MODE_UTMI:
  197. portsc = PORTSC_PTS(PTS_UTMI);
  198. lpm = DEVLC_PTS(PTS_UTMI);
  199. break;
  200. case USBPHY_INTERFACE_MODE_UTMIW:
  201. portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
  202. lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
  203. break;
  204. case USBPHY_INTERFACE_MODE_ULPI:
  205. portsc = PORTSC_PTS(PTS_ULPI);
  206. lpm = DEVLC_PTS(PTS_ULPI);
  207. break;
  208. case USBPHY_INTERFACE_MODE_SERIAL:
  209. portsc = PORTSC_PTS(PTS_SERIAL);
  210. lpm = DEVLC_PTS(PTS_SERIAL);
  211. sts = 1;
  212. break;
  213. case USBPHY_INTERFACE_MODE_HSIC:
  214. portsc = PORTSC_PTS(PTS_HSIC);
  215. lpm = DEVLC_PTS(PTS_HSIC);
  216. break;
  217. default:
  218. return;
  219. }
  220. if (ci->hw_bank.lpm) {
  221. hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
  222. hw_write(ci, OP_DEVLC, DEVLC_STS, sts);
  223. } else {
  224. hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc);
  225. hw_write(ci, OP_PORTSC, PORTSC_STS, sts);
  226. }
  227. }
  228. /**
  229. * hw_device_reset: resets chip (execute without interruption)
  230. * @ci: the controller
  231. *
  232. * This function returns an error code
  233. */
  234. int hw_device_reset(struct ci_hdrc *ci, u32 mode)
  235. {
  236. /* should flush & stop before reset */
  237. hw_write(ci, OP_ENDPTFLUSH, ~0, ~0);
  238. hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
  239. hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST);
  240. while (hw_read(ci, OP_USBCMD, USBCMD_RST))
  241. udelay(10); /* not RTOS friendly */
  242. if (ci->platdata->notify_event)
  243. ci->platdata->notify_event(ci,
  244. CI_HDRC_CONTROLLER_RESET_EVENT);
  245. if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
  246. hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
  247. /* USBMODE should be configured step by step */
  248. hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
  249. hw_write(ci, OP_USBMODE, USBMODE_CM, mode);
  250. /* HW >= 2.3 */
  251. hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM);
  252. if (hw_read(ci, OP_USBMODE, USBMODE_CM) != mode) {
  253. pr_err("cannot enter in %s mode", ci_role(ci)->name);
  254. pr_err("lpm = %i", ci->hw_bank.lpm);
  255. return -ENODEV;
  256. }
  257. return 0;
  258. }
  259. /**
  260. * hw_wait_reg: wait the register value
  261. *
  262. * Sometimes, it needs to wait register value before going on.
  263. * Eg, when switch to device mode, the vbus value should be lower
  264. * than OTGSC_BSV before connects to host.
  265. *
  266. * @ci: the controller
  267. * @reg: register index
  268. * @mask: mast bit
  269. * @value: the bit value to wait
  270. * @timeout_ms: timeout in millisecond
  271. *
  272. * This function returns an error code if timeout
  273. */
  274. int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask,
  275. u32 value, unsigned int timeout_ms)
  276. {
  277. unsigned long elapse = jiffies + msecs_to_jiffies(timeout_ms);
  278. while (hw_read(ci, reg, mask) != value) {
  279. if (time_after(jiffies, elapse)) {
  280. dev_err(ci->dev, "timeout waiting for %08x in %d\n",
  281. mask, reg);
  282. return -ETIMEDOUT;
  283. }
  284. msleep(20);
  285. }
  286. return 0;
  287. }
  288. static irqreturn_t ci_irq(int irq, void *data)
  289. {
  290. struct ci_hdrc *ci = data;
  291. irqreturn_t ret = IRQ_NONE;
  292. u32 otgsc = 0;
  293. if (ci->is_otg)
  294. otgsc = hw_read(ci, OP_OTGSC, ~0);
  295. /*
  296. * Handle id change interrupt, it indicates device/host function
  297. * switch.
  298. */
  299. if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) {
  300. ci->id_event = true;
  301. ci_clear_otg_interrupt(ci, OTGSC_IDIS);
  302. disable_irq_nosync(ci->irq);
  303. queue_work(ci->wq, &ci->work);
  304. return IRQ_HANDLED;
  305. }
  306. /*
  307. * Handle vbus change interrupt, it indicates device connection
  308. * and disconnection events.
  309. */
  310. if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) {
  311. ci->b_sess_valid_event = true;
  312. ci_clear_otg_interrupt(ci, OTGSC_BSVIS);
  313. disable_irq_nosync(ci->irq);
  314. queue_work(ci->wq, &ci->work);
  315. return IRQ_HANDLED;
  316. }
  317. /* Handle device/host interrupt */
  318. if (ci->role != CI_ROLE_END)
  319. ret = ci_role(ci)->irq(ci);
  320. return ret;
  321. }
  322. static int ci_get_platdata(struct device *dev,
  323. struct ci_hdrc_platform_data *platdata)
  324. {
  325. /* Get the vbus regulator */
  326. platdata->reg_vbus = devm_regulator_get(dev, "vbus");
  327. if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
  328. return -EPROBE_DEFER;
  329. } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
  330. platdata->reg_vbus = NULL; /* no vbus regualator is needed */
  331. } else if (IS_ERR(platdata->reg_vbus)) {
  332. dev_err(dev, "Getting regulator error: %ld\n",
  333. PTR_ERR(platdata->reg_vbus));
  334. return PTR_ERR(platdata->reg_vbus);
  335. }
  336. return 0;
  337. }
  338. static DEFINE_IDA(ci_ida);
  339. struct platform_device *ci_hdrc_add_device(struct device *dev,
  340. struct resource *res, int nres,
  341. struct ci_hdrc_platform_data *platdata)
  342. {
  343. struct platform_device *pdev;
  344. int id, ret;
  345. ret = ci_get_platdata(dev, platdata);
  346. if (ret)
  347. return ERR_PTR(ret);
  348. id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
  349. if (id < 0)
  350. return ERR_PTR(id);
  351. pdev = platform_device_alloc("ci_hdrc", id);
  352. if (!pdev) {
  353. ret = -ENOMEM;
  354. goto put_id;
  355. }
  356. pdev->dev.parent = dev;
  357. pdev->dev.dma_mask = dev->dma_mask;
  358. pdev->dev.dma_parms = dev->dma_parms;
  359. dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
  360. ret = platform_device_add_resources(pdev, res, nres);
  361. if (ret)
  362. goto err;
  363. ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
  364. if (ret)
  365. goto err;
  366. ret = platform_device_add(pdev);
  367. if (ret)
  368. goto err;
  369. return pdev;
  370. err:
  371. platform_device_put(pdev);
  372. put_id:
  373. ida_simple_remove(&ci_ida, id);
  374. return ERR_PTR(ret);
  375. }
  376. EXPORT_SYMBOL_GPL(ci_hdrc_add_device);
  377. void ci_hdrc_remove_device(struct platform_device *pdev)
  378. {
  379. int id = pdev->id;
  380. platform_device_unregister(pdev);
  381. ida_simple_remove(&ci_ida, id);
  382. }
  383. EXPORT_SYMBOL_GPL(ci_hdrc_remove_device);
  384. static inline void ci_role_destroy(struct ci_hdrc *ci)
  385. {
  386. ci_hdrc_gadget_destroy(ci);
  387. ci_hdrc_host_destroy(ci);
  388. if (ci->is_otg)
  389. ci_hdrc_otg_destroy(ci);
  390. }
  391. static void ci_get_otg_capable(struct ci_hdrc *ci)
  392. {
  393. if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)
  394. ci->is_otg = false;
  395. else
  396. ci->is_otg = (hw_read(ci, CAP_DCCPARAMS,
  397. DCCPARAMS_DC | DCCPARAMS_HC)
  398. == (DCCPARAMS_DC | DCCPARAMS_HC));
  399. if (ci->is_otg) {
  400. dev_dbg(ci->dev, "It is OTG capable controller\n");
  401. ci_disable_otg_interrupt(ci, OTGSC_INT_EN_BITS);
  402. ci_clear_otg_interrupt(ci, OTGSC_INT_STATUS_BITS);
  403. }
  404. }
  405. static int ci_hdrc_probe(struct platform_device *pdev)
  406. {
  407. struct device *dev = &pdev->dev;
  408. struct ci_hdrc *ci;
  409. struct resource *res;
  410. void __iomem *base;
  411. int ret;
  412. enum usb_dr_mode dr_mode;
  413. struct device_node *of_node = dev->of_node ?: dev->parent->of_node;
  414. if (!dev->platform_data) {
  415. dev_err(dev, "platform data missing\n");
  416. return -ENODEV;
  417. }
  418. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  419. base = devm_ioremap_resource(dev, res);
  420. if (IS_ERR(base))
  421. return PTR_ERR(base);
  422. ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
  423. if (!ci) {
  424. dev_err(dev, "can't allocate device\n");
  425. return -ENOMEM;
  426. }
  427. ci->dev = dev;
  428. ci->platdata = dev->platform_data;
  429. if (ci->platdata->phy)
  430. ci->transceiver = ci->platdata->phy;
  431. else
  432. ci->global_phy = true;
  433. ret = hw_device_init(ci, base);
  434. if (ret < 0) {
  435. dev_err(dev, "can't initialize hardware\n");
  436. return -ENODEV;
  437. }
  438. ci->hw_bank.phys = res->start;
  439. ci->irq = platform_get_irq(pdev, 0);
  440. if (ci->irq < 0) {
  441. dev_err(dev, "missing IRQ\n");
  442. return -ENODEV;
  443. }
  444. ci_get_otg_capable(ci);
  445. if (!ci->platdata->phy_mode)
  446. ci->platdata->phy_mode = of_usb_get_phy_mode(of_node);
  447. hw_phymode_configure(ci);
  448. if (!ci->platdata->dr_mode)
  449. ci->platdata->dr_mode = of_usb_get_dr_mode(of_node);
  450. if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN)
  451. ci->platdata->dr_mode = USB_DR_MODE_OTG;
  452. dr_mode = ci->platdata->dr_mode;
  453. /* initialize role(s) before the interrupt is requested */
  454. if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
  455. ret = ci_hdrc_host_init(ci);
  456. if (ret)
  457. dev_info(dev, "doesn't support host\n");
  458. }
  459. if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
  460. ret = ci_hdrc_gadget_init(ci);
  461. if (ret)
  462. dev_info(dev, "doesn't support gadget\n");
  463. }
  464. if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
  465. dev_err(dev, "no supported roles\n");
  466. return -ENODEV;
  467. }
  468. if (ci->is_otg) {
  469. ret = ci_hdrc_otg_init(ci);
  470. if (ret) {
  471. dev_err(dev, "init otg fails, ret = %d\n", ret);
  472. goto stop;
  473. }
  474. }
  475. if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
  476. if (ci->is_otg) {
  477. /*
  478. * ID pin needs 1ms debouce time,
  479. * we delay 2ms for safe.
  480. */
  481. mdelay(2);
  482. ci->role = ci_otg_role(ci);
  483. ci_enable_otg_interrupt(ci, OTGSC_IDIE);
  484. } else {
  485. /*
  486. * If the controller is not OTG capable, but support
  487. * role switch, the defalt role is gadget, and the
  488. * user can switch it through debugfs.
  489. */
  490. ci->role = CI_ROLE_GADGET;
  491. }
  492. } else {
  493. ci->role = ci->roles[CI_ROLE_HOST]
  494. ? CI_ROLE_HOST
  495. : CI_ROLE_GADGET;
  496. }
  497. ret = ci_role_start(ci, ci->role);
  498. if (ret) {
  499. dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
  500. goto stop;
  501. }
  502. platform_set_drvdata(pdev, ci);
  503. ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->platdata->name,
  504. ci);
  505. if (ret)
  506. goto stop;
  507. ret = dbg_create_files(ci);
  508. if (!ret)
  509. return 0;
  510. free_irq(ci->irq, ci);
  511. stop:
  512. ci_role_destroy(ci);
  513. return ret;
  514. }
  515. static int ci_hdrc_remove(struct platform_device *pdev)
  516. {
  517. struct ci_hdrc *ci = platform_get_drvdata(pdev);
  518. dbg_remove_files(ci);
  519. free_irq(ci->irq, ci);
  520. ci_role_destroy(ci);
  521. return 0;
  522. }
  523. static struct platform_driver ci_hdrc_driver = {
  524. .probe = ci_hdrc_probe,
  525. .remove = ci_hdrc_remove,
  526. .driver = {
  527. .name = "ci_hdrc",
  528. },
  529. };
  530. module_platform_driver(ci_hdrc_driver);
  531. MODULE_ALIAS("platform:ci_hdrc");
  532. MODULE_LICENSE("GPL v2");
  533. MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
  534. MODULE_DESCRIPTION("ChipIdea HDRC Driver");