blob: 708c2eaba81c277ea59b433a23d3a1532f2bca77 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Alexander Shishkine443b332012-05-11 17:25:46 +03002/*
3 * core.c - ChipIdea USB IP core family device controller
4 *
5 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
6 *
7 * Author: David Lopo
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14/*
15 * Description: ChipIdea USB IP core family device controller
16 *
17 * This driver is composed of several blocks:
18 * - HW: hardware interface
19 * - DBG: debug facilities (optional)
20 * - UTIL: utilities
21 * - ISR: interrupts handling
22 * - ENDPT: endpoint operations (Gadget API)
23 * - GADGET: gadget operations (Gadget API)
24 * - BUS: bus glue code, bus abstraction layer
25 *
26 * Compile Options
Alexander Shishkine443b332012-05-11 17:25:46 +030027 * - STALL_IN: non-empty bulk-in pipes cannot be halted
28 * if defined mass storage compliance succeeds but with warnings
29 * => case 4: Hi > Dn
30 * => case 5: Hi > Di
31 * => case 8: Hi <> Do
32 * if undefined usbtest 13 fails
33 * - TRACE: enable function tracing (depends on DEBUG)
34 *
35 * Main Features
36 * - Chapter 9 & Mass Storage Compliance with Gadget File Storage
37 * - Chapter 9 Compliance with Gadget Zero (STALL_IN undefined)
38 * - Normal & LPM support
39 *
40 * USBTEST Report
41 * - OK: 0-12, 13 (STALL_IN defined) & 14
42 * - Not Supported: 15 & 16 (ISO)
43 *
44 * TODO List
Alexander Shishkine443b332012-05-11 17:25:46 +030045 * - Suspend & Remote Wakeup
46 */
47#include <linux/delay.h>
48#include <linux/device.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030049#include <linux/dma-mapping.h>
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +030050#include <linux/extcon.h>
Antoine Tenart1e5e2d32014-10-30 18:41:19 +010051#include <linux/phy/phy.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030052#include <linux/platform_device.h>
53#include <linux/module.h>
Richard Zhaofe6e1252012-07-07 22:56:42 +080054#include <linux/idr.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030055#include <linux/interrupt.h>
56#include <linux/io.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030057#include <linux/kernel.h>
58#include <linux/slab.h>
59#include <linux/pm_runtime.h>
60#include <linux/usb/ch9.h>
61#include <linux/usb/gadget.h>
62#include <linux/usb/otg.h>
63#include <linux/usb/chipidea.h>
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +030064#include <linux/usb/of.h>
Michael Grzeschik4f6743d2014-02-19 13:41:43 +080065#include <linux/of.h>
Peter Chen1542d9c2013-08-14 12:44:03 +030066#include <linux/regulator/consumer.h>
Peter Chen8022d3d2014-10-30 09:15:15 +080067#include <linux/usb/ehci_def.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030068
69#include "ci.h"
70#include "udc.h"
71#include "bits.h"
Alexander Shishkineb70e5a2012-05-11 17:25:54 +030072#include "host.h"
Peter Chenc10b4f02013-08-14 12:44:06 +030073#include "otg.h"
Li Jun4dcf7202014-04-23 15:56:50 +080074#include "otg_fsm.h"
Alexander Shishkine443b332012-05-11 17:25:46 +030075
Alexander Shishkin5f36e232012-05-11 17:25:47 +030076/* Controller register map */
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +080077static const u8 ci_regs_nolpm[] = {
78 [CAP_CAPLENGTH] = 0x00U,
79 [CAP_HCCPARAMS] = 0x08U,
80 [CAP_DCCPARAMS] = 0x24U,
81 [CAP_TESTMODE] = 0x38U,
82 [OP_USBCMD] = 0x00U,
83 [OP_USBSTS] = 0x04U,
84 [OP_USBINTR] = 0x08U,
85 [OP_DEVICEADDR] = 0x14U,
86 [OP_ENDPTLISTADDR] = 0x18U,
Peter Chen28362672015-06-18 11:51:53 +080087 [OP_TTCTRL] = 0x1CU,
Peter Chen96625ea2015-03-17 17:32:45 +080088 [OP_BURSTSIZE] = 0x20U,
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -080089 [OP_ULPI_VIEWPORT] = 0x30U,
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +080090 [OP_PORTSC] = 0x44U,
91 [OP_DEVLC] = 0x84U,
92 [OP_OTGSC] = 0x64U,
93 [OP_USBMODE] = 0x68U,
94 [OP_ENDPTSETUPSTAT] = 0x6CU,
95 [OP_ENDPTPRIME] = 0x70U,
96 [OP_ENDPTFLUSH] = 0x74U,
97 [OP_ENDPTSTAT] = 0x78U,
98 [OP_ENDPTCOMPLETE] = 0x7CU,
99 [OP_ENDPTCTRL] = 0x80U,
Alexander Shishkine443b332012-05-11 17:25:46 +0300100};
101
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +0800102static const u8 ci_regs_lpm[] = {
103 [CAP_CAPLENGTH] = 0x00U,
104 [CAP_HCCPARAMS] = 0x08U,
105 [CAP_DCCPARAMS] = 0x24U,
106 [CAP_TESTMODE] = 0xFCU,
107 [OP_USBCMD] = 0x00U,
108 [OP_USBSTS] = 0x04U,
109 [OP_USBINTR] = 0x08U,
110 [OP_DEVICEADDR] = 0x14U,
111 [OP_ENDPTLISTADDR] = 0x18U,
Peter Chen28362672015-06-18 11:51:53 +0800112 [OP_TTCTRL] = 0x1CU,
Peter Chen96625ea2015-03-17 17:32:45 +0800113 [OP_BURSTSIZE] = 0x20U,
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800114 [OP_ULPI_VIEWPORT] = 0x30U,
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +0800115 [OP_PORTSC] = 0x44U,
116 [OP_DEVLC] = 0x84U,
117 [OP_OTGSC] = 0xC4U,
118 [OP_USBMODE] = 0xC8U,
119 [OP_ENDPTSETUPSTAT] = 0xD8U,
120 [OP_ENDPTPRIME] = 0xDCU,
121 [OP_ENDPTFLUSH] = 0xE0U,
122 [OP_ENDPTSTAT] = 0xE4U,
123 [OP_ENDPTCOMPLETE] = 0xE8U,
124 [OP_ENDPTCTRL] = 0xECU,
Alexander Shishkine443b332012-05-11 17:25:46 +0300125};
126
Nicholas Krause158ec072015-06-27 00:34:48 -0400127static void hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm)
Alexander Shishkine443b332012-05-11 17:25:46 +0300128{
129 int i;
130
Alexander Shishkine443b332012-05-11 17:25:46 +0300131 for (i = 0; i < OP_ENDPTCTRL; i++)
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300132 ci->hw_bank.regmap[i] =
133 (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) +
Alexander Shishkine443b332012-05-11 17:25:46 +0300134 (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]);
135
136 for (; i <= OP_LAST; i++)
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300137 ci->hw_bank.regmap[i] = ci->hw_bank.op +
Alexander Shishkine443b332012-05-11 17:25:46 +0300138 4 * (i - OP_ENDPTCTRL) +
139 (is_lpm
140 ? ci_regs_lpm[OP_ENDPTCTRL]
141 : ci_regs_nolpm[OP_ENDPTCTRL]);
142
Alexander Shishkine443b332012-05-11 17:25:46 +0300143}
144
Peter Chencb271f32015-02-11 12:44:55 +0800145static enum ci_revision ci_get_revision(struct ci_hdrc *ci)
146{
147 int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION);
148 enum ci_revision rev = CI_REVISION_UNKNOWN;
149
150 if (ver == 0x2) {
151 rev = hw_read_id_reg(ci, ID_ID, REVISION)
152 >> __ffs(REVISION);
153 rev += CI_REVISION_20;
154 } else if (ver == 0x0) {
155 rev = CI_REVISION_1X;
156 }
157
158 return rev;
159}
160
Alexander Shishkine443b332012-05-11 17:25:46 +0300161/**
Li Jun36304b02014-04-23 15:56:39 +0800162 * hw_read_intr_enable: returns interrupt enable register
163 *
Peter Chen19353882014-09-22 08:14:17 +0800164 * @ci: the controller
165 *
Li Jun36304b02014-04-23 15:56:39 +0800166 * This function returns register data
167 */
168u32 hw_read_intr_enable(struct ci_hdrc *ci)
169{
170 return hw_read(ci, OP_USBINTR, ~0);
171}
172
173/**
174 * hw_read_intr_status: returns interrupt status register
175 *
Peter Chen19353882014-09-22 08:14:17 +0800176 * @ci: the controller
177 *
Li Jun36304b02014-04-23 15:56:39 +0800178 * This function returns register data
179 */
180u32 hw_read_intr_status(struct ci_hdrc *ci)
181{
182 return hw_read(ci, OP_USBSTS, ~0);
183}
184
185/**
Alexander Shishkine443b332012-05-11 17:25:46 +0300186 * hw_port_test_set: writes port test mode (execute without interruption)
187 * @mode: new value
188 *
189 * This function returns an error code
190 */
Alexander Shishkin8e229782013-06-24 14:46:36 +0300191int hw_port_test_set(struct ci_hdrc *ci, u8 mode)
Alexander Shishkine443b332012-05-11 17:25:46 +0300192{
193 const u8 TEST_MODE_MAX = 7;
194
195 if (mode > TEST_MODE_MAX)
196 return -EINVAL;
197
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200198 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC));
Alexander Shishkine443b332012-05-11 17:25:46 +0300199 return 0;
200}
201
202/**
203 * hw_port_test_get: reads port test mode value
204 *
Peter Chen19353882014-09-22 08:14:17 +0800205 * @ci: the controller
206 *
Alexander Shishkine443b332012-05-11 17:25:46 +0300207 * This function returns port test mode value
208 */
Alexander Shishkin8e229782013-06-24 14:46:36 +0300209u8 hw_port_test_get(struct ci_hdrc *ci)
Alexander Shishkine443b332012-05-11 17:25:46 +0300210{
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200211 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
Alexander Shishkine443b332012-05-11 17:25:46 +0300212}
213
Peter Chenb82613c2014-11-26 13:44:28 +0800214static void hw_wait_phy_stable(void)
215{
216 /*
217 * The phy needs some delay to output the stable status from low
218 * power mode. And for OTGSC, the status inputs are debounced
219 * using a 1 ms time constant, so, delay 2ms for controller to get
220 * the stable status, like vbus and id when the phy leaves low power.
221 */
222 usleep_range(2000, 2500);
223}
224
Peter Chen864cf942013-09-24 12:47:55 +0800225/* The PHY enters/leaves low power mode */
226static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable)
227{
228 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC;
229 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm)));
230
Peter Chen6d037db2014-11-26 13:44:27 +0800231 if (enable && !lpm)
Peter Chen864cf942013-09-24 12:47:55 +0800232 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
233 PORTSC_PHCD(ci->hw_bank.lpm));
Peter Chen6d037db2014-11-26 13:44:27 +0800234 else if (!enable && lpm)
Peter Chen864cf942013-09-24 12:47:55 +0800235 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
236 0);
Peter Chen864cf942013-09-24 12:47:55 +0800237}
238
Alexander Shishkin8e229782013-06-24 14:46:36 +0300239static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
Alexander Shishkine443b332012-05-11 17:25:46 +0300240{
241 u32 reg;
242
243 /* bank is a module variable */
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300244 ci->hw_bank.abs = base;
Alexander Shishkine443b332012-05-11 17:25:46 +0300245
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300246 ci->hw_bank.cap = ci->hw_bank.abs;
Richard Zhao77c44002012-06-29 17:48:53 +0800247 ci->hw_bank.cap += ci->platdata->capoffset;
Svetoslav Neykov938d3232013-03-30 12:54:03 +0200248 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff);
Alexander Shishkine443b332012-05-11 17:25:46 +0300249
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300250 hw_alloc_regmap(ci, false);
251 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200252 __ffs(HCCPARAMS_LEN);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300253 ci->hw_bank.lpm = reg;
Chris Ruehlaeb2c122013-12-06 16:35:12 +0800254 if (reg)
255 hw_alloc_regmap(ci, !!reg);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300256 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs;
257 ci->hw_bank.size += OP_LAST;
258 ci->hw_bank.size /= sizeof(u32);
Alexander Shishkine443b332012-05-11 17:25:46 +0300259
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300260 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200261 __ffs(DCCPARAMS_DEN);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300262 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
Alexander Shishkine443b332012-05-11 17:25:46 +0300263
Richard Zhao09c94e62012-05-15 21:58:18 +0800264 if (ci->hw_ep_max > ENDPT_MAX)
Alexander Shishkine443b332012-05-11 17:25:46 +0300265 return -ENODEV;
266
Peter Chen864cf942013-09-24 12:47:55 +0800267 ci_hdrc_enter_lpm(ci, false);
268
Peter Chenc344b512013-08-14 12:44:09 +0300269 /* Disable all interrupts bits */
270 hw_write(ci, OP_USBINTR, 0xffffffff, 0);
271
272 /* Clear all interrupts status bits*/
273 hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff);
274
Peter Chencb271f32015-02-11 12:44:55 +0800275 ci->rev = ci_get_revision(ci);
276
277 dev_dbg(ci->dev,
278 "ChipIdea HDRC found, revision: %d, lpm: %d; cap: %p op: %p\n",
279 ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op);
Alexander Shishkine443b332012-05-11 17:25:46 +0300280
281 /* setup lock mode ? */
282
283 /* ENDPTSETUPSTAT is '0' by default */
284
285 /* HCSPARAMS.bf.ppc SHOULD BE zero for device */
286
287 return 0;
288}
289
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800290void hw_phymode_configure(struct ci_hdrc *ci)
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300291{
Chris Ruehl3b5d3e62014-01-10 13:51:29 +0800292 u32 portsc, lpm, sts = 0;
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300293
294 switch (ci->platdata->phy_mode) {
295 case USBPHY_INTERFACE_MODE_UTMI:
296 portsc = PORTSC_PTS(PTS_UTMI);
297 lpm = DEVLC_PTS(PTS_UTMI);
298 break;
299 case USBPHY_INTERFACE_MODE_UTMIW:
300 portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
301 lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
302 break;
303 case USBPHY_INTERFACE_MODE_ULPI:
304 portsc = PORTSC_PTS(PTS_ULPI);
305 lpm = DEVLC_PTS(PTS_ULPI);
306 break;
307 case USBPHY_INTERFACE_MODE_SERIAL:
308 portsc = PORTSC_PTS(PTS_SERIAL);
309 lpm = DEVLC_PTS(PTS_SERIAL);
310 sts = 1;
311 break;
312 case USBPHY_INTERFACE_MODE_HSIC:
313 portsc = PORTSC_PTS(PTS_HSIC);
314 lpm = DEVLC_PTS(PTS_HSIC);
315 break;
316 default:
317 return;
318 }
319
320 if (ci->hw_bank.lpm) {
321 hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
Chris Ruehl3b5d3e62014-01-10 13:51:29 +0800322 if (sts)
323 hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS);
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300324 } else {
325 hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc);
Chris Ruehl3b5d3e62014-01-10 13:51:29 +0800326 if (sts)
327 hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS);
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300328 }
329}
Stephen Boyd11893da2016-12-28 14:57:06 -0800330EXPORT_SYMBOL_GPL(hw_phymode_configure);
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300331
Alexander Shishkine443b332012-05-11 17:25:46 +0300332/**
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100333 * _ci_usb_phy_init: initialize phy taking in account both phy and usb_phy
334 * interfaces
335 * @ci: the controller
336 *
337 * This function returns an error code if the phy failed to init
338 */
339static int _ci_usb_phy_init(struct ci_hdrc *ci)
340{
341 int ret;
342
343 if (ci->phy) {
344 ret = phy_init(ci->phy);
345 if (ret)
346 return ret;
347
348 ret = phy_power_on(ci->phy);
349 if (ret) {
350 phy_exit(ci->phy);
351 return ret;
352 }
353 } else {
354 ret = usb_phy_init(ci->usb_phy);
355 }
356
357 return ret;
358}
359
360/**
361 * _ci_usb_phy_exit: deinitialize phy taking in account both phy and usb_phy
362 * interfaces
363 * @ci: the controller
364 */
365static void ci_usb_phy_exit(struct ci_hdrc *ci)
366{
Stephen Boyd8feb3682016-12-28 14:56:52 -0800367 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL)
368 return;
369
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100370 if (ci->phy) {
371 phy_power_off(ci->phy);
372 phy_exit(ci->phy);
373 } else {
374 usb_phy_shutdown(ci->usb_phy);
375 }
376}
377
378/**
Peter Chend03cccf2014-04-23 15:56:37 +0800379 * ci_usb_phy_init: initialize phy according to different phy type
380 * @ci: the controller
Peter Chen19353882014-09-22 08:14:17 +0800381 *
Peter Chend03cccf2014-04-23 15:56:37 +0800382 * This function returns an error code if usb_phy_init has failed
383 */
384static int ci_usb_phy_init(struct ci_hdrc *ci)
385{
386 int ret;
387
Stephen Boyd8feb3682016-12-28 14:56:52 -0800388 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL)
389 return 0;
390
Peter Chend03cccf2014-04-23 15:56:37 +0800391 switch (ci->platdata->phy_mode) {
392 case USBPHY_INTERFACE_MODE_UTMI:
393 case USBPHY_INTERFACE_MODE_UTMIW:
394 case USBPHY_INTERFACE_MODE_HSIC:
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100395 ret = _ci_usb_phy_init(ci);
Peter Chenb82613c2014-11-26 13:44:28 +0800396 if (!ret)
397 hw_wait_phy_stable();
398 else
Peter Chend03cccf2014-04-23 15:56:37 +0800399 return ret;
400 hw_phymode_configure(ci);
401 break;
402 case USBPHY_INTERFACE_MODE_ULPI:
403 case USBPHY_INTERFACE_MODE_SERIAL:
404 hw_phymode_configure(ci);
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100405 ret = _ci_usb_phy_init(ci);
Peter Chend03cccf2014-04-23 15:56:37 +0800406 if (ret)
407 return ret;
408 break;
409 default:
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100410 ret = _ci_usb_phy_init(ci);
Peter Chenb82613c2014-11-26 13:44:28 +0800411 if (!ret)
412 hw_wait_phy_stable();
Peter Chend03cccf2014-04-23 15:56:37 +0800413 }
414
415 return ret;
416}
417
Peter Chenbf9c85e2015-03-17 10:40:50 +0800418
419/**
420 * ci_platform_configure: do controller configure
421 * @ci: the controller
422 *
423 */
424void ci_platform_configure(struct ci_hdrc *ci)
425{
Peter Chen8022d3d2014-10-30 09:15:15 +0800426 bool is_device_mode, is_host_mode;
427
428 is_device_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_DC;
429 is_host_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_HC;
430
Stephen Boyd490b63e2017-01-25 14:32:43 -0800431 if (is_device_mode) {
432 phy_set_mode(ci->phy, PHY_MODE_USB_DEVICE);
Peter Chen8022d3d2014-10-30 09:15:15 +0800433
Stephen Boyd490b63e2017-01-25 14:32:43 -0800434 if (ci->platdata->flags & CI_HDRC_DISABLE_DEVICE_STREAMING)
435 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS,
436 USBMODE_CI_SDIS);
437 }
438
439 if (is_host_mode) {
440 phy_set_mode(ci->phy, PHY_MODE_USB_HOST);
441
442 if (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING)
443 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS,
444 USBMODE_CI_SDIS);
445 }
Peter Chenbf9c85e2015-03-17 10:40:50 +0800446
447 if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) {
448 if (ci->hw_bank.lpm)
449 hw_write(ci, OP_DEVLC, DEVLC_PFSC, DEVLC_PFSC);
450 else
451 hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC);
452 }
453
454 if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA)
455 hw_write(ci, OP_TTCTRL, TTCTRL_TTHA_MASK, TTCTRL_TTHA);
Peter Chendf96ed82014-09-22 16:45:39 +0800456
457 hw_write(ci, OP_USBCMD, 0xff0000, ci->platdata->itc_setting << 16);
458
Peter Chen65668712015-03-17 14:21:00 +0800459 if (ci->platdata->flags & CI_HDRC_OVERRIDE_AHB_BURST)
460 hw_write_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK,
461 ci->platdata->ahb_burst_config);
Peter Chen96625ea2015-03-17 17:32:45 +0800462
463 /* override burst size, take effect only when ahb_burst_config is 0 */
464 if (!hw_read_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK)) {
465 if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST)
466 hw_write(ci, OP_BURSTSIZE, TX_BURST_MASK,
467 ci->platdata->tx_burst_size << __ffs(TX_BURST_MASK));
468
469 if (ci->platdata->flags & CI_HDRC_OVERRIDE_RX_BURST)
470 hw_write(ci, OP_BURSTSIZE, RX_BURST_MASK,
471 ci->platdata->rx_burst_size);
472 }
Peter Chenbf9c85e2015-03-17 10:40:50 +0800473}
474
Peter Chend03cccf2014-04-23 15:56:37 +0800475/**
Peter Chencdd278f2014-11-26 13:44:32 +0800476 * hw_controller_reset: do controller reset
Alexander Shishkine443b332012-05-11 17:25:46 +0300477 * @ci: the controller
478 *
479 * This function returns an error code
480 */
Peter Chencdd278f2014-11-26 13:44:32 +0800481static int hw_controller_reset(struct ci_hdrc *ci)
482{
483 int count = 0;
484
485 hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST);
486 while (hw_read(ci, OP_USBCMD, USBCMD_RST)) {
487 udelay(10);
488 if (count++ > 1000)
489 return -ETIMEDOUT;
490 }
491
492 return 0;
493}
494
495/**
496 * hw_device_reset: resets chip (execute without interruption)
497 * @ci: the controller
498 *
499 * This function returns an error code
500 */
Peter Chen5b157302014-11-26 13:44:33 +0800501int hw_device_reset(struct ci_hdrc *ci)
Alexander Shishkine443b332012-05-11 17:25:46 +0300502{
Peter Chencdd278f2014-11-26 13:44:32 +0800503 int ret;
504
Alexander Shishkine443b332012-05-11 17:25:46 +0300505 /* should flush & stop before reset */
506 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0);
507 hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
508
Peter Chencdd278f2014-11-26 13:44:32 +0800509 ret = hw_controller_reset(ci);
510 if (ret) {
511 dev_err(ci->dev, "error resetting controller, ret=%d\n", ret);
512 return ret;
513 }
Alexander Shishkine443b332012-05-11 17:25:46 +0300514
Stephen Boyd11893da2016-12-28 14:57:06 -0800515 if (ci->platdata->notify_event) {
516 ret = ci->platdata->notify_event(ci,
Alexander Shishkin8e229782013-06-24 14:46:36 +0300517 CI_HDRC_CONTROLLER_RESET_EVENT);
Stephen Boyd11893da2016-12-28 14:57:06 -0800518 if (ret)
519 return ret;
520 }
Alexander Shishkine443b332012-05-11 17:25:46 +0300521
Alexander Shishkine443b332012-05-11 17:25:46 +0300522 /* USBMODE should be configured step by step */
523 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
Peter Chen5b157302014-11-26 13:44:33 +0800524 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_DC);
Alexander Shishkine443b332012-05-11 17:25:46 +0300525 /* HW >= 2.3 */
526 hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM);
527
Peter Chen5b157302014-11-26 13:44:33 +0800528 if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) {
529 pr_err("cannot enter in %s device mode", ci_role(ci)->name);
Alexander Shishkine443b332012-05-11 17:25:46 +0300530 pr_err("lpm = %i", ci->hw_bank.lpm);
531 return -ENODEV;
532 }
533
Peter Chenbf9c85e2015-03-17 10:40:50 +0800534 ci_platform_configure(ci);
535
Alexander Shishkine443b332012-05-11 17:25:46 +0300536 return 0;
537}
538
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300539static irqreturn_t ci_irq(int irq, void *data)
540{
Alexander Shishkin8e229782013-06-24 14:46:36 +0300541 struct ci_hdrc *ci = data;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300542 irqreturn_t ret = IRQ_NONE;
Richard Zhaob183c192012-09-12 14:58:11 +0300543 u32 otgsc = 0;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300544
Peter Chen1f874ed2015-02-11 12:44:45 +0800545 if (ci->in_lpm) {
546 disable_irq_nosync(irq);
547 ci->wakeup_int = true;
548 pm_runtime_get(ci->dev);
549 return IRQ_HANDLED;
550 }
551
Li Jun4dcf7202014-04-23 15:56:50 +0800552 if (ci->is_otg) {
Li Jun0c33bf72014-04-23 15:56:38 +0800553 otgsc = hw_read_otgsc(ci, ~0);
Li Jun4dcf7202014-04-23 15:56:50 +0800554 if (ci_otg_is_fsm_mode(ci)) {
555 ret = ci_otg_fsm_irq(ci);
556 if (ret == IRQ_HANDLED)
557 return ret;
558 }
559 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300560
Peter Chena107f8c2013-08-14 12:44:11 +0300561 /*
562 * Handle id change interrupt, it indicates device/host function
563 * switch.
564 */
565 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) {
566 ci->id_event = true;
Li Jun0c33bf72014-04-23 15:56:38 +0800567 /* Clear ID change irq status */
568 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS);
Peter Chenbe6b0c12014-05-23 08:12:49 +0800569 ci_otg_queue_work(ci);
Peter Chena107f8c2013-08-14 12:44:11 +0300570 return IRQ_HANDLED;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300571 }
572
Peter Chena107f8c2013-08-14 12:44:11 +0300573 /*
574 * Handle vbus change interrupt, it indicates device connection
575 * and disconnection events.
576 */
577 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) {
578 ci->b_sess_valid_event = true;
Li Jun0c33bf72014-04-23 15:56:38 +0800579 /* Clear BSV irq */
580 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS);
Peter Chenbe6b0c12014-05-23 08:12:49 +0800581 ci_otg_queue_work(ci);
Peter Chena107f8c2013-08-14 12:44:11 +0300582 return IRQ_HANDLED;
583 }
584
585 /* Handle device/host interrupt */
586 if (ci->role != CI_ROLE_END)
587 ret = ci_role(ci)->irq(ci);
588
Richard Zhaob183c192012-09-12 14:58:11 +0300589 return ret;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300590}
591
Stephen Boyd5cc49262017-01-20 15:11:55 +0800592static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
593 void *ptr)
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300594{
Stephen Boyd5cc49262017-01-20 15:11:55 +0800595 struct ci_hdrc_cable *cbl = container_of(nb, struct ci_hdrc_cable, nb);
596 struct ci_hdrc *ci = cbl->ci;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300597
Stephen Boyd5cc49262017-01-20 15:11:55 +0800598 cbl->connected = event;
599 cbl->changed = true;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300600
601 ci_irq(ci->irq, ci);
602 return NOTIFY_DONE;
603}
604
Peter Chen1542d9c2013-08-14 12:44:03 +0300605static int ci_get_platdata(struct device *dev,
606 struct ci_hdrc_platform_data *platdata)
607{
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300608 struct extcon_dev *ext_vbus, *ext_id;
609 struct ci_hdrc_cable *cable;
Li Jun79742352015-07-09 15:18:45 +0800610 int ret;
611
Peter Chenc22600c2013-09-17 12:37:22 +0800612 if (!platdata->phy_mode)
613 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
614
615 if (!platdata->dr_mode)
Heikki Krogerus06e71142015-09-21 11:14:34 +0300616 platdata->dr_mode = usb_get_dr_mode(dev);
Peter Chenc22600c2013-09-17 12:37:22 +0800617
618 if (platdata->dr_mode == USB_DR_MODE_UNKNOWN)
619 platdata->dr_mode = USB_DR_MODE_OTG;
620
Peter Chenc2ec3a72013-10-30 09:19:29 +0800621 if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) {
622 /* Get the vbus regulator */
623 platdata->reg_vbus = devm_regulator_get(dev, "vbus");
624 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
625 return -EPROBE_DEFER;
626 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
Mickael Maison66294672014-11-26 13:44:38 +0800627 /* no vbus regulator is needed */
Peter Chenc2ec3a72013-10-30 09:19:29 +0800628 platdata->reg_vbus = NULL;
629 } else if (IS_ERR(platdata->reg_vbus)) {
630 dev_err(dev, "Getting regulator error: %ld\n",
631 PTR_ERR(platdata->reg_vbus));
632 return PTR_ERR(platdata->reg_vbus);
633 }
Peter Chenf6a9ff02014-08-19 09:51:56 +0800634 /* Get TPL support */
635 if (!platdata->tpl_support)
636 platdata->tpl_support =
637 of_usb_host_tpl_support(dev->of_node);
Peter Chenc2ec3a72013-10-30 09:19:29 +0800638 }
639
Li Jun79742352015-07-09 15:18:45 +0800640 if (platdata->dr_mode == USB_DR_MODE_OTG) {
641 /* We can support HNP and SRP of OTG 2.0 */
642 platdata->ci_otg_caps.otg_rev = 0x0200;
643 platdata->ci_otg_caps.hnp_support = true;
644 platdata->ci_otg_caps.srp_support = true;
645
646 /* Update otg capabilities by DT properties */
647 ret = of_usb_update_otg_caps(dev->of_node,
648 &platdata->ci_otg_caps);
649 if (ret)
650 return ret;
651 }
652
Heikki Krogerus63863b92015-09-21 11:14:32 +0300653 if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
Michael Grzeschik4f6743d2014-02-19 13:41:43 +0800654 platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
655
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530656 of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
Fabio Estevam1fbf4622015-09-08 22:18:14 -0300657 &platdata->phy_clkgate_delay_us);
658
Peter Chendf96ed82014-09-22 16:45:39 +0800659 platdata->itc_setting = 1;
Peter Chendf96ed82014-09-22 16:45:39 +0800660
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530661 of_property_read_u32(dev->of_node, "itc-setting",
662 &platdata->itc_setting);
663
664 ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
665 &platdata->ahb_burst_config);
666 if (!ret) {
Peter Chen65668712015-03-17 14:21:00 +0800667 platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530668 } else if (ret != -EINVAL) {
669 dev_err(dev, "failed to get ahb-burst-config\n");
670 return ret;
Peter Chen65668712015-03-17 14:21:00 +0800671 }
672
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530673 ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
674 &platdata->tx_burst_size);
675 if (!ret) {
Peter Chen96625ea2015-03-17 17:32:45 +0800676 platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530677 } else if (ret != -EINVAL) {
678 dev_err(dev, "failed to get tx-burst-size-dword\n");
679 return ret;
Peter Chen96625ea2015-03-17 17:32:45 +0800680 }
681
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530682 ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
683 &platdata->rx_burst_size);
684 if (!ret) {
Peter Chen96625ea2015-03-17 17:32:45 +0800685 platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530686 } else if (ret != -EINVAL) {
687 dev_err(dev, "failed to get rx-burst-size-dword\n");
688 return ret;
Peter Chen96625ea2015-03-17 17:32:45 +0800689 }
690
Peter Chenaa738182016-02-01 14:23:44 +0800691 if (of_find_property(dev->of_node, "non-zero-ttctrl-ttha", NULL))
692 platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA;
693
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300694 ext_id = ERR_PTR(-ENODEV);
695 ext_vbus = ERR_PTR(-ENODEV);
696 if (of_property_read_bool(dev->of_node, "extcon")) {
697 /* Each one of them is not mandatory */
698 ext_vbus = extcon_get_edev_by_phandle(dev, 0);
699 if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV)
700 return PTR_ERR(ext_vbus);
701
702 ext_id = extcon_get_edev_by_phandle(dev, 1);
703 if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV)
704 return PTR_ERR(ext_id);
705 }
706
707 cable = &platdata->vbus_extcon;
Stephen Boyd5cc49262017-01-20 15:11:55 +0800708 cable->nb.notifier_call = ci_cable_notifier;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300709 cable->edev = ext_vbus;
710
711 if (!IS_ERR(ext_vbus)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900712 ret = extcon_get_state(cable->edev, EXTCON_USB);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300713 if (ret)
Stephen Boyd5cc49262017-01-20 15:11:55 +0800714 cable->connected = true;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300715 else
Stephen Boyd5cc49262017-01-20 15:11:55 +0800716 cable->connected = false;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300717 }
718
719 cable = &platdata->id_extcon;
Stephen Boyd5cc49262017-01-20 15:11:55 +0800720 cable->nb.notifier_call = ci_cable_notifier;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300721 cable->edev = ext_id;
722
723 if (!IS_ERR(ext_id)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900724 ret = extcon_get_state(cable->edev, EXTCON_USB_HOST);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300725 if (ret)
Stephen Boyd5cc49262017-01-20 15:11:55 +0800726 cable->connected = true;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300727 else
Stephen Boyd5cc49262017-01-20 15:11:55 +0800728 cable->connected = false;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300729 }
Peter Chen1542d9c2013-08-14 12:44:03 +0300730 return 0;
731}
732
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300733static int ci_extcon_register(struct ci_hdrc *ci)
734{
735 struct ci_hdrc_cable *id, *vbus;
736 int ret;
737
738 id = &ci->platdata->id_extcon;
739 id->ci = ci;
Peter Chen7c3a8b82017-06-23 14:39:27 +0800740 if (!IS_ERR_OR_NULL(id->edev)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900741 ret = devm_extcon_register_notifier(ci->dev, id->edev,
742 EXTCON_USB_HOST, &id->nb);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300743 if (ret < 0) {
744 dev_err(ci->dev, "register ID failed\n");
745 return ret;
746 }
747 }
748
749 vbus = &ci->platdata->vbus_extcon;
750 vbus->ci = ci;
Peter Chen7c3a8b82017-06-23 14:39:27 +0800751 if (!IS_ERR_OR_NULL(vbus->edev)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900752 ret = devm_extcon_register_notifier(ci->dev, vbus->edev,
753 EXTCON_USB, &vbus->nb);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300754 if (ret < 0) {
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300755 dev_err(ci->dev, "register VBUS failed\n");
756 return ret;
757 }
758 }
759
760 return 0;
761}
762
Richard Zhaofe6e1252012-07-07 22:56:42 +0800763static DEFINE_IDA(ci_ida);
764
Alexander Shishkin8e229782013-06-24 14:46:36 +0300765struct platform_device *ci_hdrc_add_device(struct device *dev,
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800766 struct resource *res, int nres,
Alexander Shishkin8e229782013-06-24 14:46:36 +0300767 struct ci_hdrc_platform_data *platdata)
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800768{
769 struct platform_device *pdev;
Richard Zhaofe6e1252012-07-07 22:56:42 +0800770 int id, ret;
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800771
Peter Chen1542d9c2013-08-14 12:44:03 +0300772 ret = ci_get_platdata(dev, platdata);
773 if (ret)
774 return ERR_PTR(ret);
775
Richard Zhaofe6e1252012-07-07 22:56:42 +0800776 id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
777 if (id < 0)
778 return ERR_PTR(id);
779
780 pdev = platform_device_alloc("ci_hdrc", id);
781 if (!pdev) {
782 ret = -ENOMEM;
783 goto put_id;
784 }
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800785
786 pdev->dev.parent = dev;
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800787
788 ret = platform_device_add_resources(pdev, res, nres);
789 if (ret)
790 goto err;
791
792 ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
793 if (ret)
794 goto err;
795
796 ret = platform_device_add(pdev);
797 if (ret)
798 goto err;
799
800 return pdev;
801
802err:
803 platform_device_put(pdev);
Richard Zhaofe6e1252012-07-07 22:56:42 +0800804put_id:
805 ida_simple_remove(&ci_ida, id);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800806 return ERR_PTR(ret);
807}
Alexander Shishkin8e229782013-06-24 14:46:36 +0300808EXPORT_SYMBOL_GPL(ci_hdrc_add_device);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800809
Alexander Shishkin8e229782013-06-24 14:46:36 +0300810void ci_hdrc_remove_device(struct platform_device *pdev)
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800811{
Lothar Waßmann98c35532012-11-22 10:11:25 +0100812 int id = pdev->id;
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800813 platform_device_unregister(pdev);
Lothar Waßmann98c35532012-11-22 10:11:25 +0100814 ida_simple_remove(&ci_ida, id);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800815}
Alexander Shishkin8e229782013-06-24 14:46:36 +0300816EXPORT_SYMBOL_GPL(ci_hdrc_remove_device);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800817
Peter Chen3f124d22013-08-14 12:44:07 +0300818static inline void ci_role_destroy(struct ci_hdrc *ci)
819{
820 ci_hdrc_gadget_destroy(ci);
821 ci_hdrc_host_destroy(ci);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +0800822 if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
Peter Chencbec6bd2013-08-14 12:44:10 +0300823 ci_hdrc_otg_destroy(ci);
Peter Chen3f124d22013-08-14 12:44:07 +0300824}
825
Peter Chen577b2322013-08-14 12:44:08 +0300826static void ci_get_otg_capable(struct ci_hdrc *ci)
827{
828 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)
829 ci->is_otg = false;
830 else
831 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS,
832 DCCPARAMS_DC | DCCPARAMS_HC)
833 == (DCCPARAMS_DC | DCCPARAMS_HC));
Peter Chen2e37cfd2015-02-11 12:44:51 +0800834 if (ci->is_otg) {
Peter Chen577b2322013-08-14 12:44:08 +0300835 dev_dbg(ci->dev, "It is OTG capable controller\n");
Peter Chen2e37cfd2015-02-11 12:44:51 +0800836 /* Disable and clear all OTG irq */
837 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
838 OTGSC_INT_STATUS_BITS);
839 }
Peter Chen577b2322013-08-14 12:44:08 +0300840}
841
Peter Chena932a802017-03-27 10:54:27 +0800842static ssize_t ci_role_show(struct device *dev, struct device_attribute *attr,
843 char *buf)
844{
845 struct ci_hdrc *ci = dev_get_drvdata(dev);
846
Michael Thalmeiercbb22eb2017-05-19 10:32:09 +0200847 if (ci->role != CI_ROLE_END)
848 return sprintf(buf, "%s\n", ci_role(ci)->name);
849
850 return 0;
Peter Chena932a802017-03-27 10:54:27 +0800851}
852
853static ssize_t ci_role_store(struct device *dev,
854 struct device_attribute *attr, const char *buf, size_t n)
855{
856 struct ci_hdrc *ci = dev_get_drvdata(dev);
857 enum ci_role role;
858 int ret;
859
860 if (!(ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET])) {
861 dev_warn(dev, "Current configuration is not dual-role, quit\n");
862 return -EPERM;
863 }
864
865 for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
866 if (!strncmp(buf, ci->roles[role]->name,
867 strlen(ci->roles[role]->name)))
868 break;
869
870 if (role == CI_ROLE_END || role == ci->role)
871 return -EINVAL;
872
873 pm_runtime_get_sync(dev);
874 disable_irq(ci->irq);
875 ci_role_stop(ci);
876 ret = ci_role_start(ci, role);
877 if (!ret && ci->role == CI_ROLE_GADGET)
878 ci_handle_vbus_change(ci);
879 enable_irq(ci->irq);
880 pm_runtime_put_sync(dev);
881
882 return (ret == 0) ? n : ret;
883}
884static DEVICE_ATTR(role, 0644, ci_role_show, ci_role_store);
885
886static struct attribute *ci_attrs[] = {
887 &dev_attr_role.attr,
888 NULL,
889};
890
Arvind Yadava351a2b2017-08-04 17:36:38 +0530891static const struct attribute_group ci_attr_group = {
Peter Chena932a802017-03-27 10:54:27 +0800892 .attrs = ci_attrs,
893};
894
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500895static int ci_hdrc_probe(struct platform_device *pdev)
Alexander Shishkine443b332012-05-11 17:25:46 +0300896{
897 struct device *dev = &pdev->dev;
Alexander Shishkin8e229782013-06-24 14:46:36 +0300898 struct ci_hdrc *ci;
Alexander Shishkine443b332012-05-11 17:25:46 +0300899 struct resource *res;
900 void __iomem *base;
901 int ret;
Sascha Hauer691962d2013-06-13 17:59:57 +0300902 enum usb_dr_mode dr_mode;
Alexander Shishkine443b332012-05-11 17:25:46 +0300903
Jingoo Hanfad56742014-02-19 13:41:42 +0800904 if (!dev_get_platdata(dev)) {
Alexander Shishkine443b332012-05-11 17:25:46 +0300905 dev_err(dev, "platform data missing\n");
906 return -ENODEV;
907 }
908
909 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbi19290812013-03-30 02:46:27 +0200910 base = devm_ioremap_resource(dev, res);
911 if (IS_ERR(base))
912 return PTR_ERR(base);
Alexander Shishkine443b332012-05-11 17:25:46 +0300913
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300914 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
Fabio Estevamd0f99242014-11-26 13:44:23 +0800915 if (!ci)
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300916 return -ENOMEM;
Alexander Shishkine443b332012-05-11 17:25:46 +0300917
Peter Chena5d906b2016-11-15 18:05:33 +0800918 spin_lock_init(&ci->lock);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300919 ci->dev = dev;
Jingoo Hanfad56742014-02-19 13:41:42 +0800920 ci->platdata = dev_get_platdata(dev);
Peter Chened8f8312014-01-10 13:51:27 +0800921 ci->imx28_write_fix = !!(ci->platdata->flags &
922 CI_HDRC_IMX28_WRITE_FIX);
Peter Chen1f874ed2015-02-11 12:44:45 +0800923 ci->supports_runtime_pm = !!(ci->platdata->flags &
924 CI_HDRC_SUPPORTS_RUNTIME_PM);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800925 platform_set_drvdata(pdev, ci);
Alexander Shishkine443b332012-05-11 17:25:46 +0300926
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300927 ret = hw_device_init(ci, base);
928 if (ret < 0) {
929 dev_err(dev, "can't initialize hardware\n");
930 return -ENODEV;
931 }
932
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800933 ret = ci_ulpi_init(ci);
934 if (ret)
935 return ret;
936
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100937 if (ci->platdata->phy) {
938 ci->phy = ci->platdata->phy;
939 } else if (ci->platdata->usb_phy) {
Antoine Tenartef44cb42014-10-30 18:41:16 +0100940 ci->usb_phy = ci->platdata->usb_phy;
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100941 } else {
Antoine Tenart21a5b572014-11-26 13:44:35 +0800942 ci->phy = devm_phy_get(dev->parent, "usb-phy");
943 ci->usb_phy = devm_usb_get_phy(dev->parent, USB_PHY_TYPE_USB2);
Peter Chenc859aa652014-02-19 13:41:40 +0800944
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100945 /* if both generic PHY and USB PHY layers aren't enabled */
946 if (PTR_ERR(ci->phy) == -ENOSYS &&
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800947 PTR_ERR(ci->usb_phy) == -ENXIO) {
948 ret = -ENXIO;
949 goto ulpi_exit;
950 }
Peter Chenc859aa652014-02-19 13:41:40 +0800951
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800952 if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) {
953 ret = -EPROBE_DEFER;
954 goto ulpi_exit;
955 }
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100956
957 if (IS_ERR(ci->phy))
958 ci->phy = NULL;
959 else if (IS_ERR(ci->usb_phy))
960 ci->usb_phy = NULL;
Peter Chenc859aa652014-02-19 13:41:40 +0800961 }
962
Peter Chend03cccf2014-04-23 15:56:37 +0800963 ret = ci_usb_phy_init(ci);
Peter Chen74475ed2013-09-24 12:47:53 +0800964 if (ret) {
965 dev_err(dev, "unable to init phy: %d\n", ret);
966 return ret;
967 }
968
Alexander Shishkineb70e5a2012-05-11 17:25:54 +0300969 ci->hw_bank.phys = res->start;
970
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300971 ci->irq = platform_get_irq(pdev, 0);
972 if (ci->irq < 0) {
973 dev_err(dev, "missing IRQ\n");
Fabio Estevam42d18212014-02-19 13:41:44 +0800974 ret = ci->irq;
Peter Chenc859aa652014-02-19 13:41:40 +0800975 goto deinit_phy;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300976 }
977
Peter Chen577b2322013-08-14 12:44:08 +0300978 ci_get_otg_capable(ci);
979
Sascha Hauer691962d2013-06-13 17:59:57 +0300980 dr_mode = ci->platdata->dr_mode;
981 /* initialize role(s) before the interrupt is requested */
982 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
983 ret = ci_hdrc_host_init(ci);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +0800984 if (ret) {
985 if (ret == -ENXIO)
986 dev_info(dev, "doesn't support host\n");
987 else
988 goto deinit_phy;
989 }
Sascha Hauer691962d2013-06-13 17:59:57 +0300990 }
991
992 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
993 ret = ci_hdrc_gadget_init(ci);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +0800994 if (ret) {
995 if (ret == -ENXIO)
996 dev_info(dev, "doesn't support gadget\n");
997 else
998 goto deinit_host;
999 }
Sascha Hauer691962d2013-06-13 17:59:57 +03001000 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001001
1002 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
1003 dev_err(dev, "no supported roles\n");
Peter Chen74475ed2013-09-24 12:47:53 +08001004 ret = -ENODEV;
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +08001005 goto deinit_gadget;
Peter Chencbec6bd2013-08-14 12:44:10 +03001006 }
1007
Peter Chen27c62c22014-09-22 08:14:16 +08001008 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) {
Peter Chencbec6bd2013-08-14 12:44:10 +03001009 ret = ci_hdrc_otg_init(ci);
1010 if (ret) {
1011 dev_err(dev, "init otg fails, ret = %d\n", ret);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +08001012 goto deinit_gadget;
Peter Chencbec6bd2013-08-14 12:44:10 +03001013 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001014 }
1015
1016 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
Peter Chen577b2322013-08-14 12:44:08 +03001017 if (ci->is_otg) {
Peter Chen577b2322013-08-14 12:44:08 +03001018 ci->role = ci_otg_role(ci);
Li Jun0c33bf72014-04-23 15:56:38 +08001019 /* Enable ID change irq */
1020 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE);
Peter Chen577b2322013-08-14 12:44:08 +03001021 } else {
1022 /*
1023 * If the controller is not OTG capable, but support
1024 * role switch, the defalt role is gadget, and the
1025 * user can switch it through debugfs.
1026 */
1027 ci->role = CI_ROLE_GADGET;
1028 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001029 } else {
1030 ci->role = ci->roles[CI_ROLE_HOST]
1031 ? CI_ROLE_HOST
1032 : CI_ROLE_GADGET;
1033 }
1034
Li Jun4dcf7202014-04-23 15:56:50 +08001035 if (!ci_otg_is_fsm_mode(ci)) {
Li Jun961ea492015-02-11 12:45:03 +08001036 /* only update vbus status for peripheral */
1037 if (ci->role == CI_ROLE_GADGET)
1038 ci_handle_vbus_change(ci);
1039
Li Jun4dcf7202014-04-23 15:56:50 +08001040 ret = ci_role_start(ci, ci->role);
1041 if (ret) {
1042 dev_err(dev, "can't start %s role\n",
1043 ci_role(ci)->name);
1044 goto stop;
1045 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001046 }
1047
Peter Chen4c503dd2014-11-26 13:44:22 +08001048 ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED,
1049 ci->platdata->name, ci);
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001050 if (ret)
1051 goto stop;
1052
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +03001053 ret = ci_extcon_register(ci);
1054 if (ret)
1055 goto stop;
1056
Peter Chen1f874ed2015-02-11 12:44:45 +08001057 if (ci->supports_runtime_pm) {
1058 pm_runtime_set_active(&pdev->dev);
1059 pm_runtime_enable(&pdev->dev);
1060 pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
1061 pm_runtime_mark_last_busy(ci->dev);
1062 pm_runtime_use_autosuspend(&pdev->dev);
1063 }
1064
Li Jun4dcf7202014-04-23 15:56:50 +08001065 if (ci_otg_is_fsm_mode(ci))
1066 ci_hdrc_otg_fsm_start(ci);
1067
Peter Chenf8efa762015-02-11 12:44:48 +08001068 device_set_wakeup_capable(&pdev->dev, true);
Alexander Shishkinadf0f732013-03-30 12:53:53 +02001069 ret = dbg_create_files(ci);
Peter Chena932a802017-03-27 10:54:27 +08001070 if (ret)
1071 goto stop;
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001072
Peter Chena932a802017-03-27 10:54:27 +08001073 ret = sysfs_create_group(&dev->kobj, &ci_attr_group);
1074 if (ret)
1075 goto remove_debug;
1076
1077 return 0;
1078
1079remove_debug:
1080 dbg_remove_files(ci);
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001081stop:
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +08001082 if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
1083 ci_hdrc_otg_destroy(ci);
1084deinit_gadget:
1085 ci_hdrc_gadget_destroy(ci);
1086deinit_host:
1087 ci_hdrc_host_destroy(ci);
Peter Chenc859aa652014-02-19 13:41:40 +08001088deinit_phy:
Antoine Tenart1e5e2d32014-10-30 18:41:19 +01001089 ci_usb_phy_exit(ci);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001090ulpi_exit:
1091 ci_ulpi_exit(ci);
Alexander Shishkine443b332012-05-11 17:25:46 +03001092
1093 return ret;
1094}
1095
Bill Pembertonfb4e98a2012-11-19 13:26:20 -05001096static int ci_hdrc_remove(struct platform_device *pdev)
Alexander Shishkine443b332012-05-11 17:25:46 +03001097{
Alexander Shishkin8e229782013-06-24 14:46:36 +03001098 struct ci_hdrc *ci = platform_get_drvdata(pdev);
Alexander Shishkine443b332012-05-11 17:25:46 +03001099
Peter Chen1f874ed2015-02-11 12:44:45 +08001100 if (ci->supports_runtime_pm) {
1101 pm_runtime_get_sync(&pdev->dev);
1102 pm_runtime_disable(&pdev->dev);
1103 pm_runtime_put_noidle(&pdev->dev);
1104 }
1105
Alexander Shishkinadf0f732013-03-30 12:53:53 +02001106 dbg_remove_files(ci);
Peter Chena932a802017-03-27 10:54:27 +08001107 sysfs_remove_group(&ci->dev->kobj, &ci_attr_group);
Peter Chen3f124d22013-08-14 12:44:07 +03001108 ci_role_destroy(ci);
Peter Chen864cf942013-09-24 12:47:55 +08001109 ci_hdrc_enter_lpm(ci, true);
Antoine Tenart1e5e2d32014-10-30 18:41:19 +01001110 ci_usb_phy_exit(ci);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001111 ci_ulpi_exit(ci);
Alexander Shishkine443b332012-05-11 17:25:46 +03001112
1113 return 0;
1114}
1115
Peter Chen1f874ed2015-02-11 12:44:45 +08001116#ifdef CONFIG_PM
Li Jun961ea492015-02-11 12:45:03 +08001117/* Prepare wakeup by SRP before suspend */
1118static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci)
1119{
1120 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
1121 !hw_read_otgsc(ci, OTGSC_ID)) {
1122 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP,
1123 PORTSC_PP);
1124 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN,
1125 PORTSC_WKCN);
1126 }
1127}
1128
1129/* Handle SRP when wakeup by data pulse */
1130static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci)
1131{
1132 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
1133 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) {
1134 if (!hw_read_otgsc(ci, OTGSC_ID)) {
1135 ci->fsm.a_srp_det = 1;
1136 ci->fsm.a_bus_drop = 0;
1137 } else {
1138 ci->fsm.id = 1;
1139 }
1140 ci_otg_queue_work(ci);
1141 }
1142}
1143
Peter Chen80769322014-11-26 13:44:29 +08001144static void ci_controller_suspend(struct ci_hdrc *ci)
1145{
Peter Chen1f874ed2015-02-11 12:44:45 +08001146 disable_irq(ci->irq);
Peter Chen80769322014-11-26 13:44:29 +08001147 ci_hdrc_enter_lpm(ci, true);
Fabio Estevam1fbf4622015-09-08 22:18:14 -03001148 if (ci->platdata->phy_clkgate_delay_us)
1149 usleep_range(ci->platdata->phy_clkgate_delay_us,
1150 ci->platdata->phy_clkgate_delay_us + 50);
Peter Chen1f874ed2015-02-11 12:44:45 +08001151 usb_phy_set_suspend(ci->usb_phy, 1);
1152 ci->in_lpm = true;
1153 enable_irq(ci->irq);
Peter Chen80769322014-11-26 13:44:29 +08001154}
1155
1156static int ci_controller_resume(struct device *dev)
1157{
1158 struct ci_hdrc *ci = dev_get_drvdata(dev);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001159 int ret;
Peter Chen80769322014-11-26 13:44:29 +08001160
1161 dev_dbg(dev, "at %s\n", __func__);
1162
Peter Chen1f874ed2015-02-11 12:44:45 +08001163 if (!ci->in_lpm) {
1164 WARN_ON(1);
1165 return 0;
1166 }
Peter Chen80769322014-11-26 13:44:29 +08001167
Peter Chen1f874ed2015-02-11 12:44:45 +08001168 ci_hdrc_enter_lpm(ci, false);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001169
1170 ret = ci_ulpi_resume(ci);
1171 if (ret)
1172 return ret;
1173
Peter Chen80769322014-11-26 13:44:29 +08001174 if (ci->usb_phy) {
1175 usb_phy_set_suspend(ci->usb_phy, 0);
1176 usb_phy_set_wakeup(ci->usb_phy, false);
1177 hw_wait_phy_stable();
1178 }
1179
Peter Chen1f874ed2015-02-11 12:44:45 +08001180 ci->in_lpm = false;
1181 if (ci->wakeup_int) {
1182 ci->wakeup_int = false;
1183 pm_runtime_mark_last_busy(ci->dev);
1184 pm_runtime_put_autosuspend(ci->dev);
1185 enable_irq(ci->irq);
Li Jun961ea492015-02-11 12:45:03 +08001186 if (ci_otg_is_fsm_mode(ci))
1187 ci_otg_fsm_wakeup_by_srp(ci);
Peter Chen1f874ed2015-02-11 12:44:45 +08001188 }
1189
Peter Chen80769322014-11-26 13:44:29 +08001190 return 0;
1191}
1192
Peter Chen1f874ed2015-02-11 12:44:45 +08001193#ifdef CONFIG_PM_SLEEP
Peter Chen80769322014-11-26 13:44:29 +08001194static int ci_suspend(struct device *dev)
1195{
1196 struct ci_hdrc *ci = dev_get_drvdata(dev);
1197
1198 if (ci->wq)
1199 flush_workqueue(ci->wq);
Peter Chen1f874ed2015-02-11 12:44:45 +08001200 /*
1201 * Controller needs to be active during suspend, otherwise the core
1202 * may run resume when the parent is at suspend if other driver's
1203 * suspend fails, it occurs before parent's suspend has not started,
1204 * but the core suspend has finished.
1205 */
1206 if (ci->in_lpm)
1207 pm_runtime_resume(dev);
1208
1209 if (ci->in_lpm) {
1210 WARN_ON(1);
1211 return 0;
1212 }
Peter Chen80769322014-11-26 13:44:29 +08001213
Peter Chenf8efa762015-02-11 12:44:48 +08001214 if (device_may_wakeup(dev)) {
Li Jun961ea492015-02-11 12:45:03 +08001215 if (ci_otg_is_fsm_mode(ci))
1216 ci_otg_fsm_suspend_for_srp(ci);
1217
Peter Chenf8efa762015-02-11 12:44:48 +08001218 usb_phy_set_wakeup(ci->usb_phy, true);
1219 enable_irq_wake(ci->irq);
1220 }
1221
Peter Chen80769322014-11-26 13:44:29 +08001222 ci_controller_suspend(ci);
1223
1224 return 0;
1225}
1226
1227static int ci_resume(struct device *dev)
1228{
Peter Chen1f874ed2015-02-11 12:44:45 +08001229 struct ci_hdrc *ci = dev_get_drvdata(dev);
1230 int ret;
1231
Peter Chenf8efa762015-02-11 12:44:48 +08001232 if (device_may_wakeup(dev))
1233 disable_irq_wake(ci->irq);
1234
Peter Chen1f874ed2015-02-11 12:44:45 +08001235 ret = ci_controller_resume(dev);
1236 if (ret)
1237 return ret;
1238
1239 if (ci->supports_runtime_pm) {
1240 pm_runtime_disable(dev);
1241 pm_runtime_set_active(dev);
1242 pm_runtime_enable(dev);
1243 }
1244
1245 return ret;
Peter Chen80769322014-11-26 13:44:29 +08001246}
1247#endif /* CONFIG_PM_SLEEP */
1248
Peter Chen1f874ed2015-02-11 12:44:45 +08001249static int ci_runtime_suspend(struct device *dev)
1250{
1251 struct ci_hdrc *ci = dev_get_drvdata(dev);
1252
1253 dev_dbg(dev, "at %s\n", __func__);
1254
1255 if (ci->in_lpm) {
1256 WARN_ON(1);
1257 return 0;
1258 }
1259
Li Jun961ea492015-02-11 12:45:03 +08001260 if (ci_otg_is_fsm_mode(ci))
1261 ci_otg_fsm_suspend_for_srp(ci);
1262
Peter Chen1f874ed2015-02-11 12:44:45 +08001263 usb_phy_set_wakeup(ci->usb_phy, true);
1264 ci_controller_suspend(ci);
1265
1266 return 0;
1267}
1268
1269static int ci_runtime_resume(struct device *dev)
1270{
1271 return ci_controller_resume(dev);
1272}
1273
1274#endif /* CONFIG_PM */
Peter Chen80769322014-11-26 13:44:29 +08001275static const struct dev_pm_ops ci_pm_ops = {
1276 SET_SYSTEM_SLEEP_PM_OPS(ci_suspend, ci_resume)
Peter Chen1f874ed2015-02-11 12:44:45 +08001277 SET_RUNTIME_PM_OPS(ci_runtime_suspend, ci_runtime_resume, NULL)
Peter Chen80769322014-11-26 13:44:29 +08001278};
Peter Chen1f874ed2015-02-11 12:44:45 +08001279
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001280static struct platform_driver ci_hdrc_driver = {
1281 .probe = ci_hdrc_probe,
Bill Pemberton76904172012-11-19 13:21:08 -05001282 .remove = ci_hdrc_remove,
Alexander Shishkine443b332012-05-11 17:25:46 +03001283 .driver = {
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001284 .name = "ci_hdrc",
Peter Chen80769322014-11-26 13:44:29 +08001285 .pm = &ci_pm_ops,
Alexander Shishkine443b332012-05-11 17:25:46 +03001286 },
1287};
1288
Peter Chen2f01a332015-07-21 09:51:29 +08001289static int __init ci_hdrc_platform_register(void)
1290{
1291 ci_hdrc_host_driver_init();
1292 return platform_driver_register(&ci_hdrc_driver);
1293}
1294module_init(ci_hdrc_platform_register);
1295
1296static void __exit ci_hdrc_platform_unregister(void)
1297{
1298 platform_driver_unregister(&ci_hdrc_driver);
1299}
1300module_exit(ci_hdrc_platform_unregister);
Alexander Shishkine443b332012-05-11 17:25:46 +03001301
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001302MODULE_ALIAS("platform:ci_hdrc");
Alexander Shishkine443b332012-05-11 17:25:46 +03001303MODULE_LICENSE("GPL v2");
1304MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001305MODULE_DESCRIPTION("ChipIdea HDRC Driver");