blob: 85fc6db48e449214e092c7a36443995d7544b713 [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
Alexander Shishkine443b332012-05-11 17:25:46 +03008 */
9
10/*
11 * Description: ChipIdea USB IP core family device controller
12 *
13 * This driver is composed of several blocks:
14 * - HW: hardware interface
15 * - DBG: debug facilities (optional)
16 * - UTIL: utilities
17 * - ISR: interrupts handling
18 * - ENDPT: endpoint operations (Gadget API)
19 * - GADGET: gadget operations (Gadget API)
20 * - BUS: bus glue code, bus abstraction layer
21 *
22 * Compile Options
Alexander Shishkine443b332012-05-11 17:25:46 +030023 * - STALL_IN: non-empty bulk-in pipes cannot be halted
24 * if defined mass storage compliance succeeds but with warnings
25 * => case 4: Hi > Dn
26 * => case 5: Hi > Di
27 * => case 8: Hi <> Do
28 * if undefined usbtest 13 fails
29 * - TRACE: enable function tracing (depends on DEBUG)
30 *
31 * Main Features
32 * - Chapter 9 & Mass Storage Compliance with Gadget File Storage
33 * - Chapter 9 Compliance with Gadget Zero (STALL_IN undefined)
34 * - Normal & LPM support
35 *
36 * USBTEST Report
37 * - OK: 0-12, 13 (STALL_IN defined) & 14
38 * - Not Supported: 15 & 16 (ISO)
39 *
40 * TODO List
Alexander Shishkine443b332012-05-11 17:25:46 +030041 * - Suspend & Remote Wakeup
42 */
43#include <linux/delay.h>
44#include <linux/device.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030045#include <linux/dma-mapping.h>
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +030046#include <linux/extcon.h>
Antoine Tenart1e5e2d32014-10-30 18:41:19 +010047#include <linux/phy/phy.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030048#include <linux/platform_device.h>
49#include <linux/module.h>
Richard Zhaofe6e1252012-07-07 22:56:42 +080050#include <linux/idr.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030051#include <linux/interrupt.h>
52#include <linux/io.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030053#include <linux/kernel.h>
54#include <linux/slab.h>
55#include <linux/pm_runtime.h>
56#include <linux/usb/ch9.h>
57#include <linux/usb/gadget.h>
58#include <linux/usb/otg.h>
59#include <linux/usb/chipidea.h>
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +030060#include <linux/usb/of.h>
Michael Grzeschik4f6743d2014-02-19 13:41:43 +080061#include <linux/of.h>
Peter Chen1542d9c2013-08-14 12:44:03 +030062#include <linux/regulator/consumer.h>
Peter Chen8022d3d2014-10-30 09:15:15 +080063#include <linux/usb/ehci_def.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030064
65#include "ci.h"
66#include "udc.h"
67#include "bits.h"
Alexander Shishkineb70e5a2012-05-11 17:25:54 +030068#include "host.h"
Peter Chenc10b4f02013-08-14 12:44:06 +030069#include "otg.h"
Li Jun4dcf7202014-04-23 15:56:50 +080070#include "otg_fsm.h"
Alexander Shishkine443b332012-05-11 17:25:46 +030071
Alexander Shishkin5f36e232012-05-11 17:25:47 +030072/* Controller register map */
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +080073static const u8 ci_regs_nolpm[] = {
74 [CAP_CAPLENGTH] = 0x00U,
75 [CAP_HCCPARAMS] = 0x08U,
76 [CAP_DCCPARAMS] = 0x24U,
77 [CAP_TESTMODE] = 0x38U,
78 [OP_USBCMD] = 0x00U,
79 [OP_USBSTS] = 0x04U,
80 [OP_USBINTR] = 0x08U,
81 [OP_DEVICEADDR] = 0x14U,
82 [OP_ENDPTLISTADDR] = 0x18U,
Peter Chen28362672015-06-18 11:51:53 +080083 [OP_TTCTRL] = 0x1CU,
Peter Chen96625ea2015-03-17 17:32:45 +080084 [OP_BURSTSIZE] = 0x20U,
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -080085 [OP_ULPI_VIEWPORT] = 0x30U,
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +080086 [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,
Alexander Shishkine443b332012-05-11 17:25:46 +030096};
97
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +080098static const u8 ci_regs_lpm[] = {
99 [CAP_CAPLENGTH] = 0x00U,
100 [CAP_HCCPARAMS] = 0x08U,
101 [CAP_DCCPARAMS] = 0x24U,
102 [CAP_TESTMODE] = 0xFCU,
103 [OP_USBCMD] = 0x00U,
104 [OP_USBSTS] = 0x04U,
105 [OP_USBINTR] = 0x08U,
106 [OP_DEVICEADDR] = 0x14U,
107 [OP_ENDPTLISTADDR] = 0x18U,
Peter Chen28362672015-06-18 11:51:53 +0800108 [OP_TTCTRL] = 0x1CU,
Peter Chen96625ea2015-03-17 17:32:45 +0800109 [OP_BURSTSIZE] = 0x20U,
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800110 [OP_ULPI_VIEWPORT] = 0x30U,
Marc Kleine-Budde987e7bc2014-01-06 10:10:39 +0800111 [OP_PORTSC] = 0x44U,
112 [OP_DEVLC] = 0x84U,
113 [OP_OTGSC] = 0xC4U,
114 [OP_USBMODE] = 0xC8U,
115 [OP_ENDPTSETUPSTAT] = 0xD8U,
116 [OP_ENDPTPRIME] = 0xDCU,
117 [OP_ENDPTFLUSH] = 0xE0U,
118 [OP_ENDPTSTAT] = 0xE4U,
119 [OP_ENDPTCOMPLETE] = 0xE8U,
120 [OP_ENDPTCTRL] = 0xECU,
Alexander Shishkine443b332012-05-11 17:25:46 +0300121};
122
Nicholas Krause158ec072015-06-27 00:34:48 -0400123static void hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm)
Alexander Shishkine443b332012-05-11 17:25:46 +0300124{
125 int i;
126
Alexander Shishkine443b332012-05-11 17:25:46 +0300127 for (i = 0; i < OP_ENDPTCTRL; i++)
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300128 ci->hw_bank.regmap[i] =
129 (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) +
Alexander Shishkine443b332012-05-11 17:25:46 +0300130 (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]);
131
132 for (; i <= OP_LAST; i++)
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300133 ci->hw_bank.regmap[i] = ci->hw_bank.op +
Alexander Shishkine443b332012-05-11 17:25:46 +0300134 4 * (i - OP_ENDPTCTRL) +
135 (is_lpm
136 ? ci_regs_lpm[OP_ENDPTCTRL]
137 : ci_regs_nolpm[OP_ENDPTCTRL]);
138
Alexander Shishkine443b332012-05-11 17:25:46 +0300139}
140
Peter Chencb271f32015-02-11 12:44:55 +0800141static enum ci_revision ci_get_revision(struct ci_hdrc *ci)
142{
143 int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION);
144 enum ci_revision rev = CI_REVISION_UNKNOWN;
145
146 if (ver == 0x2) {
147 rev = hw_read_id_reg(ci, ID_ID, REVISION)
148 >> __ffs(REVISION);
149 rev += CI_REVISION_20;
150 } else if (ver == 0x0) {
151 rev = CI_REVISION_1X;
152 }
153
154 return rev;
155}
156
Alexander Shishkine443b332012-05-11 17:25:46 +0300157/**
Li Jun36304b02014-04-23 15:56:39 +0800158 * hw_read_intr_enable: returns interrupt enable register
159 *
Peter Chen19353882014-09-22 08:14:17 +0800160 * @ci: the controller
161 *
Li Jun36304b02014-04-23 15:56:39 +0800162 * This function returns register data
163 */
164u32 hw_read_intr_enable(struct ci_hdrc *ci)
165{
166 return hw_read(ci, OP_USBINTR, ~0);
167}
168
169/**
170 * hw_read_intr_status: returns interrupt status register
171 *
Peter Chen19353882014-09-22 08:14:17 +0800172 * @ci: the controller
173 *
Li Jun36304b02014-04-23 15:56:39 +0800174 * This function returns register data
175 */
176u32 hw_read_intr_status(struct ci_hdrc *ci)
177{
178 return hw_read(ci, OP_USBSTS, ~0);
179}
180
181/**
Alexander Shishkine443b332012-05-11 17:25:46 +0300182 * hw_port_test_set: writes port test mode (execute without interruption)
183 * @mode: new value
184 *
185 * This function returns an error code
186 */
Alexander Shishkin8e229782013-06-24 14:46:36 +0300187int hw_port_test_set(struct ci_hdrc *ci, u8 mode)
Alexander Shishkine443b332012-05-11 17:25:46 +0300188{
189 const u8 TEST_MODE_MAX = 7;
190
191 if (mode > TEST_MODE_MAX)
192 return -EINVAL;
193
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200194 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC));
Alexander Shishkine443b332012-05-11 17:25:46 +0300195 return 0;
196}
197
198/**
199 * hw_port_test_get: reads port test mode value
200 *
Peter Chen19353882014-09-22 08:14:17 +0800201 * @ci: the controller
202 *
Alexander Shishkine443b332012-05-11 17:25:46 +0300203 * This function returns port test mode value
204 */
Alexander Shishkin8e229782013-06-24 14:46:36 +0300205u8 hw_port_test_get(struct ci_hdrc *ci)
Alexander Shishkine443b332012-05-11 17:25:46 +0300206{
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200207 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
Alexander Shishkine443b332012-05-11 17:25:46 +0300208}
209
Peter Chenb82613c2014-11-26 13:44:28 +0800210static void hw_wait_phy_stable(void)
211{
212 /*
213 * The phy needs some delay to output the stable status from low
214 * power mode. And for OTGSC, the status inputs are debounced
215 * using a 1 ms time constant, so, delay 2ms for controller to get
216 * the stable status, like vbus and id when the phy leaves low power.
217 */
218 usleep_range(2000, 2500);
219}
220
Peter Chen864cf942013-09-24 12:47:55 +0800221/* The PHY enters/leaves low power mode */
222static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable)
223{
224 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC;
225 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm)));
226
Peter Chen6d037db2014-11-26 13:44:27 +0800227 if (enable && !lpm)
Peter Chen864cf942013-09-24 12:47:55 +0800228 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
229 PORTSC_PHCD(ci->hw_bank.lpm));
Peter Chen6d037db2014-11-26 13:44:27 +0800230 else if (!enable && lpm)
Peter Chen864cf942013-09-24 12:47:55 +0800231 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
232 0);
Peter Chen864cf942013-09-24 12:47:55 +0800233}
234
Alexander Shishkin8e229782013-06-24 14:46:36 +0300235static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
Alexander Shishkine443b332012-05-11 17:25:46 +0300236{
237 u32 reg;
238
239 /* bank is a module variable */
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300240 ci->hw_bank.abs = base;
Alexander Shishkine443b332012-05-11 17:25:46 +0300241
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300242 ci->hw_bank.cap = ci->hw_bank.abs;
Richard Zhao77c44002012-06-29 17:48:53 +0800243 ci->hw_bank.cap += ci->platdata->capoffset;
Svetoslav Neykov938d3232013-03-30 12:54:03 +0200244 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff);
Alexander Shishkine443b332012-05-11 17:25:46 +0300245
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300246 hw_alloc_regmap(ci, false);
247 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200248 __ffs(HCCPARAMS_LEN);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300249 ci->hw_bank.lpm = reg;
Chris Ruehlaeb2c122013-12-06 16:35:12 +0800250 if (reg)
251 hw_alloc_regmap(ci, !!reg);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300252 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs;
253 ci->hw_bank.size += OP_LAST;
254 ci->hw_bank.size /= sizeof(u32);
Alexander Shishkine443b332012-05-11 17:25:46 +0300255
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300256 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
Felipe Balbi727b4dd2013-03-30 12:53:55 +0200257 __ffs(DCCPARAMS_DEN);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300258 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
Alexander Shishkine443b332012-05-11 17:25:46 +0300259
Richard Zhao09c94e62012-05-15 21:58:18 +0800260 if (ci->hw_ep_max > ENDPT_MAX)
Alexander Shishkine443b332012-05-11 17:25:46 +0300261 return -ENODEV;
262
Peter Chen864cf942013-09-24 12:47:55 +0800263 ci_hdrc_enter_lpm(ci, false);
264
Peter Chenc344b512013-08-14 12:44:09 +0300265 /* Disable all interrupts bits */
266 hw_write(ci, OP_USBINTR, 0xffffffff, 0);
267
268 /* Clear all interrupts status bits*/
269 hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff);
270
Peter Chencb271f32015-02-11 12:44:55 +0800271 ci->rev = ci_get_revision(ci);
272
273 dev_dbg(ci->dev,
274 "ChipIdea HDRC found, revision: %d, lpm: %d; cap: %p op: %p\n",
275 ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op);
Alexander Shishkine443b332012-05-11 17:25:46 +0300276
277 /* setup lock mode ? */
278
279 /* ENDPTSETUPSTAT is '0' by default */
280
281 /* HCSPARAMS.bf.ppc SHOULD BE zero for device */
282
283 return 0;
284}
285
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800286void hw_phymode_configure(struct ci_hdrc *ci)
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300287{
Chris Ruehl3b5d3e62014-01-10 13:51:29 +0800288 u32 portsc, lpm, sts = 0;
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300289
290 switch (ci->platdata->phy_mode) {
291 case USBPHY_INTERFACE_MODE_UTMI:
292 portsc = PORTSC_PTS(PTS_UTMI);
293 lpm = DEVLC_PTS(PTS_UTMI);
294 break;
295 case USBPHY_INTERFACE_MODE_UTMIW:
296 portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
297 lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
298 break;
299 case USBPHY_INTERFACE_MODE_ULPI:
300 portsc = PORTSC_PTS(PTS_ULPI);
301 lpm = DEVLC_PTS(PTS_ULPI);
302 break;
303 case USBPHY_INTERFACE_MODE_SERIAL:
304 portsc = PORTSC_PTS(PTS_SERIAL);
305 lpm = DEVLC_PTS(PTS_SERIAL);
306 sts = 1;
307 break;
308 case USBPHY_INTERFACE_MODE_HSIC:
309 portsc = PORTSC_PTS(PTS_HSIC);
310 lpm = DEVLC_PTS(PTS_HSIC);
311 break;
312 default:
313 return;
314 }
315
316 if (ci->hw_bank.lpm) {
317 hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
Chris Ruehl3b5d3e62014-01-10 13:51:29 +0800318 if (sts)
319 hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS);
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300320 } else {
321 hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc);
Chris Ruehl3b5d3e62014-01-10 13:51:29 +0800322 if (sts)
323 hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS);
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300324 }
325}
Stephen Boyd11893da2016-12-28 14:57:06 -0800326EXPORT_SYMBOL_GPL(hw_phymode_configure);
Michael Grzeschik40dcd0e2013-06-13 17:59:56 +0300327
Alexander Shishkine443b332012-05-11 17:25:46 +0300328/**
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100329 * _ci_usb_phy_init: initialize phy taking in account both phy and usb_phy
330 * interfaces
331 * @ci: the controller
332 *
333 * This function returns an error code if the phy failed to init
334 */
335static int _ci_usb_phy_init(struct ci_hdrc *ci)
336{
337 int ret;
338
339 if (ci->phy) {
340 ret = phy_init(ci->phy);
341 if (ret)
342 return ret;
343
344 ret = phy_power_on(ci->phy);
345 if (ret) {
346 phy_exit(ci->phy);
347 return ret;
348 }
349 } else {
350 ret = usb_phy_init(ci->usb_phy);
351 }
352
353 return ret;
354}
355
356/**
357 * _ci_usb_phy_exit: deinitialize phy taking in account both phy and usb_phy
358 * interfaces
359 * @ci: the controller
360 */
361static void ci_usb_phy_exit(struct ci_hdrc *ci)
362{
Stephen Boyd8feb3682016-12-28 14:56:52 -0800363 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL)
364 return;
365
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100366 if (ci->phy) {
367 phy_power_off(ci->phy);
368 phy_exit(ci->phy);
369 } else {
370 usb_phy_shutdown(ci->usb_phy);
371 }
372}
373
374/**
Peter Chend03cccf2014-04-23 15:56:37 +0800375 * ci_usb_phy_init: initialize phy according to different phy type
376 * @ci: the controller
Peter Chen19353882014-09-22 08:14:17 +0800377 *
Peter Chend03cccf2014-04-23 15:56:37 +0800378 * This function returns an error code if usb_phy_init has failed
379 */
380static int ci_usb_phy_init(struct ci_hdrc *ci)
381{
382 int ret;
383
Stephen Boyd8feb3682016-12-28 14:56:52 -0800384 if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL)
385 return 0;
386
Peter Chend03cccf2014-04-23 15:56:37 +0800387 switch (ci->platdata->phy_mode) {
388 case USBPHY_INTERFACE_MODE_UTMI:
389 case USBPHY_INTERFACE_MODE_UTMIW:
390 case USBPHY_INTERFACE_MODE_HSIC:
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100391 ret = _ci_usb_phy_init(ci);
Peter Chenb82613c2014-11-26 13:44:28 +0800392 if (!ret)
393 hw_wait_phy_stable();
394 else
Peter Chend03cccf2014-04-23 15:56:37 +0800395 return ret;
396 hw_phymode_configure(ci);
397 break;
398 case USBPHY_INTERFACE_MODE_ULPI:
399 case USBPHY_INTERFACE_MODE_SERIAL:
400 hw_phymode_configure(ci);
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100401 ret = _ci_usb_phy_init(ci);
Peter Chend03cccf2014-04-23 15:56:37 +0800402 if (ret)
403 return ret;
404 break;
405 default:
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100406 ret = _ci_usb_phy_init(ci);
Peter Chenb82613c2014-11-26 13:44:28 +0800407 if (!ret)
408 hw_wait_phy_stable();
Peter Chend03cccf2014-04-23 15:56:37 +0800409 }
410
411 return ret;
412}
413
Peter Chenbf9c85e2015-03-17 10:40:50 +0800414
415/**
416 * ci_platform_configure: do controller configure
417 * @ci: the controller
418 *
419 */
420void ci_platform_configure(struct ci_hdrc *ci)
421{
Peter Chen8022d3d2014-10-30 09:15:15 +0800422 bool is_device_mode, is_host_mode;
423
424 is_device_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_DC;
425 is_host_mode = hw_read(ci, OP_USBMODE, USBMODE_CM) == USBMODE_CM_HC;
426
Stephen Boyd490b63e2017-01-25 14:32:43 -0800427 if (is_device_mode) {
428 phy_set_mode(ci->phy, PHY_MODE_USB_DEVICE);
Peter Chen8022d3d2014-10-30 09:15:15 +0800429
Stephen Boyd490b63e2017-01-25 14:32:43 -0800430 if (ci->platdata->flags & CI_HDRC_DISABLE_DEVICE_STREAMING)
431 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS,
432 USBMODE_CI_SDIS);
433 }
434
435 if (is_host_mode) {
436 phy_set_mode(ci->phy, PHY_MODE_USB_HOST);
437
438 if (ci->platdata->flags & CI_HDRC_DISABLE_HOST_STREAMING)
439 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS,
440 USBMODE_CI_SDIS);
441 }
Peter Chenbf9c85e2015-03-17 10:40:50 +0800442
443 if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) {
444 if (ci->hw_bank.lpm)
445 hw_write(ci, OP_DEVLC, DEVLC_PFSC, DEVLC_PFSC);
446 else
447 hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC);
448 }
449
450 if (ci->platdata->flags & CI_HDRC_SET_NON_ZERO_TTHA)
451 hw_write(ci, OP_TTCTRL, TTCTRL_TTHA_MASK, TTCTRL_TTHA);
Peter Chendf96ed82014-09-22 16:45:39 +0800452
453 hw_write(ci, OP_USBCMD, 0xff0000, ci->platdata->itc_setting << 16);
454
Peter Chen65668712015-03-17 14:21:00 +0800455 if (ci->platdata->flags & CI_HDRC_OVERRIDE_AHB_BURST)
456 hw_write_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK,
457 ci->platdata->ahb_burst_config);
Peter Chen96625ea2015-03-17 17:32:45 +0800458
459 /* override burst size, take effect only when ahb_burst_config is 0 */
460 if (!hw_read_id_reg(ci, ID_SBUSCFG, AHBBRST_MASK)) {
461 if (ci->platdata->flags & CI_HDRC_OVERRIDE_TX_BURST)
462 hw_write(ci, OP_BURSTSIZE, TX_BURST_MASK,
463 ci->platdata->tx_burst_size << __ffs(TX_BURST_MASK));
464
465 if (ci->platdata->flags & CI_HDRC_OVERRIDE_RX_BURST)
466 hw_write(ci, OP_BURSTSIZE, RX_BURST_MASK,
467 ci->platdata->rx_burst_size);
468 }
Peter Chenbf9c85e2015-03-17 10:40:50 +0800469}
470
Peter Chend03cccf2014-04-23 15:56:37 +0800471/**
Peter Chencdd278f2014-11-26 13:44:32 +0800472 * hw_controller_reset: do controller reset
Alexander Shishkine443b332012-05-11 17:25:46 +0300473 * @ci: the controller
474 *
475 * This function returns an error code
476 */
Peter Chencdd278f2014-11-26 13:44:32 +0800477static int hw_controller_reset(struct ci_hdrc *ci)
478{
479 int count = 0;
480
481 hw_write(ci, OP_USBCMD, USBCMD_RST, USBCMD_RST);
482 while (hw_read(ci, OP_USBCMD, USBCMD_RST)) {
483 udelay(10);
484 if (count++ > 1000)
485 return -ETIMEDOUT;
486 }
487
488 return 0;
489}
490
491/**
492 * hw_device_reset: resets chip (execute without interruption)
493 * @ci: the controller
494 *
495 * This function returns an error code
496 */
Peter Chen5b157302014-11-26 13:44:33 +0800497int hw_device_reset(struct ci_hdrc *ci)
Alexander Shishkine443b332012-05-11 17:25:46 +0300498{
Peter Chencdd278f2014-11-26 13:44:32 +0800499 int ret;
500
Alexander Shishkine443b332012-05-11 17:25:46 +0300501 /* should flush & stop before reset */
502 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0);
503 hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
504
Peter Chencdd278f2014-11-26 13:44:32 +0800505 ret = hw_controller_reset(ci);
506 if (ret) {
507 dev_err(ci->dev, "error resetting controller, ret=%d\n", ret);
508 return ret;
509 }
Alexander Shishkine443b332012-05-11 17:25:46 +0300510
Stephen Boyd11893da2016-12-28 14:57:06 -0800511 if (ci->platdata->notify_event) {
512 ret = ci->platdata->notify_event(ci,
Alexander Shishkin8e229782013-06-24 14:46:36 +0300513 CI_HDRC_CONTROLLER_RESET_EVENT);
Stephen Boyd11893da2016-12-28 14:57:06 -0800514 if (ret)
515 return ret;
516 }
Alexander Shishkine443b332012-05-11 17:25:46 +0300517
Alexander Shishkine443b332012-05-11 17:25:46 +0300518 /* USBMODE should be configured step by step */
519 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
Peter Chen5b157302014-11-26 13:44:33 +0800520 hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_DC);
Alexander Shishkine443b332012-05-11 17:25:46 +0300521 /* HW >= 2.3 */
522 hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM);
523
Peter Chen5b157302014-11-26 13:44:33 +0800524 if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) {
525 pr_err("cannot enter in %s device mode", ci_role(ci)->name);
Alexander Shishkine443b332012-05-11 17:25:46 +0300526 pr_err("lpm = %i", ci->hw_bank.lpm);
527 return -ENODEV;
528 }
529
Peter Chenbf9c85e2015-03-17 10:40:50 +0800530 ci_platform_configure(ci);
531
Alexander Shishkine443b332012-05-11 17:25:46 +0300532 return 0;
533}
534
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300535static irqreturn_t ci_irq(int irq, void *data)
536{
Alexander Shishkin8e229782013-06-24 14:46:36 +0300537 struct ci_hdrc *ci = data;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300538 irqreturn_t ret = IRQ_NONE;
Richard Zhaob183c192012-09-12 14:58:11 +0300539 u32 otgsc = 0;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300540
Peter Chen1f874ed2015-02-11 12:44:45 +0800541 if (ci->in_lpm) {
542 disable_irq_nosync(irq);
543 ci->wakeup_int = true;
544 pm_runtime_get(ci->dev);
545 return IRQ_HANDLED;
546 }
547
Li Jun4dcf7202014-04-23 15:56:50 +0800548 if (ci->is_otg) {
Li Jun0c33bf72014-04-23 15:56:38 +0800549 otgsc = hw_read_otgsc(ci, ~0);
Li Jun4dcf7202014-04-23 15:56:50 +0800550 if (ci_otg_is_fsm_mode(ci)) {
551 ret = ci_otg_fsm_irq(ci);
552 if (ret == IRQ_HANDLED)
553 return ret;
554 }
555 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300556
Peter Chena107f8c2013-08-14 12:44:11 +0300557 /*
558 * Handle id change interrupt, it indicates device/host function
559 * switch.
560 */
561 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) {
562 ci->id_event = true;
Li Jun0c33bf72014-04-23 15:56:38 +0800563 /* Clear ID change irq status */
564 hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS);
Peter Chenbe6b0c12014-05-23 08:12:49 +0800565 ci_otg_queue_work(ci);
Peter Chena107f8c2013-08-14 12:44:11 +0300566 return IRQ_HANDLED;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300567 }
568
Peter Chena107f8c2013-08-14 12:44:11 +0300569 /*
570 * Handle vbus change interrupt, it indicates device connection
571 * and disconnection events.
572 */
573 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) {
574 ci->b_sess_valid_event = true;
Li Jun0c33bf72014-04-23 15:56:38 +0800575 /* Clear BSV irq */
576 hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS);
Peter Chenbe6b0c12014-05-23 08:12:49 +0800577 ci_otg_queue_work(ci);
Peter Chena107f8c2013-08-14 12:44:11 +0300578 return IRQ_HANDLED;
579 }
580
581 /* Handle device/host interrupt */
582 if (ci->role != CI_ROLE_END)
583 ret = ci_role(ci)->irq(ci);
584
Richard Zhaob183c192012-09-12 14:58:11 +0300585 return ret;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300586}
587
Stephen Boyd5cc49262017-01-20 15:11:55 +0800588static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
589 void *ptr)
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300590{
Stephen Boyd5cc49262017-01-20 15:11:55 +0800591 struct ci_hdrc_cable *cbl = container_of(nb, struct ci_hdrc_cable, nb);
592 struct ci_hdrc *ci = cbl->ci;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300593
Stephen Boyd5cc49262017-01-20 15:11:55 +0800594 cbl->connected = event;
595 cbl->changed = true;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300596
597 ci_irq(ci->irq, ci);
598 return NOTIFY_DONE;
599}
600
Peter Chen1542d9c2013-08-14 12:44:03 +0300601static int ci_get_platdata(struct device *dev,
602 struct ci_hdrc_platform_data *platdata)
603{
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300604 struct extcon_dev *ext_vbus, *ext_id;
605 struct ci_hdrc_cable *cable;
Li Jun79742352015-07-09 15:18:45 +0800606 int ret;
607
Peter Chenc22600c2013-09-17 12:37:22 +0800608 if (!platdata->phy_mode)
609 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
610
611 if (!platdata->dr_mode)
Heikki Krogerus06e71142015-09-21 11:14:34 +0300612 platdata->dr_mode = usb_get_dr_mode(dev);
Peter Chenc22600c2013-09-17 12:37:22 +0800613
614 if (platdata->dr_mode == USB_DR_MODE_UNKNOWN)
615 platdata->dr_mode = USB_DR_MODE_OTG;
616
Peter Chenc2ec3a72013-10-30 09:19:29 +0800617 if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) {
618 /* Get the vbus regulator */
619 platdata->reg_vbus = devm_regulator_get(dev, "vbus");
620 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
621 return -EPROBE_DEFER;
622 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
Mickael Maison66294672014-11-26 13:44:38 +0800623 /* no vbus regulator is needed */
Peter Chenc2ec3a72013-10-30 09:19:29 +0800624 platdata->reg_vbus = NULL;
625 } else if (IS_ERR(platdata->reg_vbus)) {
626 dev_err(dev, "Getting regulator error: %ld\n",
627 PTR_ERR(platdata->reg_vbus));
628 return PTR_ERR(platdata->reg_vbus);
629 }
Peter Chenf6a9ff02014-08-19 09:51:56 +0800630 /* Get TPL support */
631 if (!platdata->tpl_support)
632 platdata->tpl_support =
633 of_usb_host_tpl_support(dev->of_node);
Peter Chenc2ec3a72013-10-30 09:19:29 +0800634 }
635
Li Jun79742352015-07-09 15:18:45 +0800636 if (platdata->dr_mode == USB_DR_MODE_OTG) {
637 /* We can support HNP and SRP of OTG 2.0 */
638 platdata->ci_otg_caps.otg_rev = 0x0200;
639 platdata->ci_otg_caps.hnp_support = true;
640 platdata->ci_otg_caps.srp_support = true;
641
642 /* Update otg capabilities by DT properties */
643 ret = of_usb_update_otg_caps(dev->of_node,
644 &platdata->ci_otg_caps);
645 if (ret)
646 return ret;
647 }
648
Heikki Krogerus63863b92015-09-21 11:14:32 +0300649 if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
Michael Grzeschik4f6743d2014-02-19 13:41:43 +0800650 platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
651
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530652 of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
Fabio Estevam1fbf4622015-09-08 22:18:14 -0300653 &platdata->phy_clkgate_delay_us);
654
Peter Chendf96ed82014-09-22 16:45:39 +0800655 platdata->itc_setting = 1;
Peter Chendf96ed82014-09-22 16:45:39 +0800656
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530657 of_property_read_u32(dev->of_node, "itc-setting",
658 &platdata->itc_setting);
659
660 ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
661 &platdata->ahb_burst_config);
662 if (!ret) {
Peter Chen65668712015-03-17 14:21:00 +0800663 platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530664 } else if (ret != -EINVAL) {
665 dev_err(dev, "failed to get ahb-burst-config\n");
666 return ret;
Peter Chen65668712015-03-17 14:21:00 +0800667 }
668
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530669 ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
670 &platdata->tx_burst_size);
671 if (!ret) {
Peter Chen96625ea2015-03-17 17:32:45 +0800672 platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530673 } else if (ret != -EINVAL) {
674 dev_err(dev, "failed to get tx-burst-size-dword\n");
675 return ret;
Peter Chen96625ea2015-03-17 17:32:45 +0800676 }
677
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530678 ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
679 &platdata->rx_burst_size);
680 if (!ret) {
Peter Chen96625ea2015-03-17 17:32:45 +0800681 platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
Saurabh Sengar4b19b782015-11-18 09:40:12 +0530682 } else if (ret != -EINVAL) {
683 dev_err(dev, "failed to get rx-burst-size-dword\n");
684 return ret;
Peter Chen96625ea2015-03-17 17:32:45 +0800685 }
686
Peter Chenaa738182016-02-01 14:23:44 +0800687 if (of_find_property(dev->of_node, "non-zero-ttctrl-ttha", NULL))
688 platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA;
689
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300690 ext_id = ERR_PTR(-ENODEV);
691 ext_vbus = ERR_PTR(-ENODEV);
692 if (of_property_read_bool(dev->of_node, "extcon")) {
693 /* Each one of them is not mandatory */
694 ext_vbus = extcon_get_edev_by_phandle(dev, 0);
695 if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV)
696 return PTR_ERR(ext_vbus);
697
698 ext_id = extcon_get_edev_by_phandle(dev, 1);
699 if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV)
700 return PTR_ERR(ext_id);
701 }
702
703 cable = &platdata->vbus_extcon;
Stephen Boyd5cc49262017-01-20 15:11:55 +0800704 cable->nb.notifier_call = ci_cable_notifier;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300705 cable->edev = ext_vbus;
706
707 if (!IS_ERR(ext_vbus)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900708 ret = extcon_get_state(cable->edev, EXTCON_USB);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300709 if (ret)
Stephen Boyd5cc49262017-01-20 15:11:55 +0800710 cable->connected = true;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300711 else
Stephen Boyd5cc49262017-01-20 15:11:55 +0800712 cable->connected = false;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300713 }
714
715 cable = &platdata->id_extcon;
Stephen Boyd5cc49262017-01-20 15:11:55 +0800716 cable->nb.notifier_call = ci_cable_notifier;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300717 cable->edev = ext_id;
718
719 if (!IS_ERR(ext_id)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900720 ret = extcon_get_state(cable->edev, EXTCON_USB_HOST);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300721 if (ret)
Stephen Boyd5cc49262017-01-20 15:11:55 +0800722 cable->connected = true;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300723 else
Stephen Boyd5cc49262017-01-20 15:11:55 +0800724 cable->connected = false;
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300725 }
Peter Chen1542d9c2013-08-14 12:44:03 +0300726 return 0;
727}
728
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300729static int ci_extcon_register(struct ci_hdrc *ci)
730{
731 struct ci_hdrc_cable *id, *vbus;
732 int ret;
733
734 id = &ci->platdata->id_extcon;
735 id->ci = ci;
Peter Chen7c3a8b82017-06-23 14:39:27 +0800736 if (!IS_ERR_OR_NULL(id->edev)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900737 ret = devm_extcon_register_notifier(ci->dev, id->edev,
738 EXTCON_USB_HOST, &id->nb);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300739 if (ret < 0) {
740 dev_err(ci->dev, "register ID failed\n");
741 return ret;
742 }
743 }
744
745 vbus = &ci->platdata->vbus_extcon;
746 vbus->ci = ci;
Peter Chen7c3a8b82017-06-23 14:39:27 +0800747 if (!IS_ERR_OR_NULL(vbus->edev)) {
Chanwoo Choi3f991aa2016-11-30 14:57:33 +0900748 ret = devm_extcon_register_notifier(ci->dev, vbus->edev,
749 EXTCON_USB, &vbus->nb);
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300750 if (ret < 0) {
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +0300751 dev_err(ci->dev, "register VBUS failed\n");
752 return ret;
753 }
754 }
755
756 return 0;
757}
758
Richard Zhaofe6e1252012-07-07 22:56:42 +0800759static DEFINE_IDA(ci_ida);
760
Alexander Shishkin8e229782013-06-24 14:46:36 +0300761struct platform_device *ci_hdrc_add_device(struct device *dev,
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800762 struct resource *res, int nres,
Alexander Shishkin8e229782013-06-24 14:46:36 +0300763 struct ci_hdrc_platform_data *platdata)
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800764{
765 struct platform_device *pdev;
Richard Zhaofe6e1252012-07-07 22:56:42 +0800766 int id, ret;
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800767
Peter Chen1542d9c2013-08-14 12:44:03 +0300768 ret = ci_get_platdata(dev, platdata);
769 if (ret)
770 return ERR_PTR(ret);
771
Richard Zhaofe6e1252012-07-07 22:56:42 +0800772 id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
773 if (id < 0)
774 return ERR_PTR(id);
775
776 pdev = platform_device_alloc("ci_hdrc", id);
777 if (!pdev) {
778 ret = -ENOMEM;
779 goto put_id;
780 }
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800781
782 pdev->dev.parent = dev;
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800783
784 ret = platform_device_add_resources(pdev, res, nres);
785 if (ret)
786 goto err;
787
788 ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
789 if (ret)
790 goto err;
791
792 ret = platform_device_add(pdev);
793 if (ret)
794 goto err;
795
796 return pdev;
797
798err:
799 platform_device_put(pdev);
Richard Zhaofe6e1252012-07-07 22:56:42 +0800800put_id:
801 ida_simple_remove(&ci_ida, id);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800802 return ERR_PTR(ret);
803}
Alexander Shishkin8e229782013-06-24 14:46:36 +0300804EXPORT_SYMBOL_GPL(ci_hdrc_add_device);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800805
Alexander Shishkin8e229782013-06-24 14:46:36 +0300806void ci_hdrc_remove_device(struct platform_device *pdev)
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800807{
Lothar Waßmann98c35532012-11-22 10:11:25 +0100808 int id = pdev->id;
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800809 platform_device_unregister(pdev);
Lothar Waßmann98c35532012-11-22 10:11:25 +0100810 ida_simple_remove(&ci_ida, id);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800811}
Alexander Shishkin8e229782013-06-24 14:46:36 +0300812EXPORT_SYMBOL_GPL(ci_hdrc_remove_device);
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800813
Peter Chen3f124d22013-08-14 12:44:07 +0300814static inline void ci_role_destroy(struct ci_hdrc *ci)
815{
816 ci_hdrc_gadget_destroy(ci);
817 ci_hdrc_host_destroy(ci);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +0800818 if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
Peter Chencbec6bd2013-08-14 12:44:10 +0300819 ci_hdrc_otg_destroy(ci);
Peter Chen3f124d22013-08-14 12:44:07 +0300820}
821
Peter Chen577b2322013-08-14 12:44:08 +0300822static void ci_get_otg_capable(struct ci_hdrc *ci)
823{
824 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)
825 ci->is_otg = false;
826 else
827 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS,
828 DCCPARAMS_DC | DCCPARAMS_HC)
829 == (DCCPARAMS_DC | DCCPARAMS_HC));
Peter Chen2e37cfd2015-02-11 12:44:51 +0800830 if (ci->is_otg) {
Peter Chen577b2322013-08-14 12:44:08 +0300831 dev_dbg(ci->dev, "It is OTG capable controller\n");
Peter Chen2e37cfd2015-02-11 12:44:51 +0800832 /* Disable and clear all OTG irq */
833 hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
834 OTGSC_INT_STATUS_BITS);
835 }
Peter Chen577b2322013-08-14 12:44:08 +0300836}
837
Greg Kroah-Hartmaned5bd7a2018-01-23 11:24:05 +0100838static ssize_t role_show(struct device *dev, struct device_attribute *attr,
Peter Chena932a802017-03-27 10:54:27 +0800839 char *buf)
840{
841 struct ci_hdrc *ci = dev_get_drvdata(dev);
842
Michael Thalmeiercbb22eb2017-05-19 10:32:09 +0200843 if (ci->role != CI_ROLE_END)
844 return sprintf(buf, "%s\n", ci_role(ci)->name);
845
846 return 0;
Peter Chena932a802017-03-27 10:54:27 +0800847}
848
Greg Kroah-Hartmaned5bd7a2018-01-23 11:24:05 +0100849static ssize_t role_store(struct device *dev,
Peter Chena932a802017-03-27 10:54:27 +0800850 struct device_attribute *attr, const char *buf, size_t n)
851{
852 struct ci_hdrc *ci = dev_get_drvdata(dev);
853 enum ci_role role;
854 int ret;
855
856 if (!(ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET])) {
857 dev_warn(dev, "Current configuration is not dual-role, quit\n");
858 return -EPERM;
859 }
860
861 for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
862 if (!strncmp(buf, ci->roles[role]->name,
863 strlen(ci->roles[role]->name)))
864 break;
865
866 if (role == CI_ROLE_END || role == ci->role)
867 return -EINVAL;
868
869 pm_runtime_get_sync(dev);
870 disable_irq(ci->irq);
871 ci_role_stop(ci);
872 ret = ci_role_start(ci, role);
873 if (!ret && ci->role == CI_ROLE_GADGET)
874 ci_handle_vbus_change(ci);
875 enable_irq(ci->irq);
876 pm_runtime_put_sync(dev);
877
878 return (ret == 0) ? n : ret;
879}
Greg Kroah-Hartmaned5bd7a2018-01-23 11:24:05 +0100880static DEVICE_ATTR_RW(role);
Peter Chena932a802017-03-27 10:54:27 +0800881
882static struct attribute *ci_attrs[] = {
883 &dev_attr_role.attr,
884 NULL,
885};
886
Arvind Yadava351a2b2017-08-04 17:36:38 +0530887static const struct attribute_group ci_attr_group = {
Peter Chena932a802017-03-27 10:54:27 +0800888 .attrs = ci_attrs,
889};
890
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500891static int ci_hdrc_probe(struct platform_device *pdev)
Alexander Shishkine443b332012-05-11 17:25:46 +0300892{
893 struct device *dev = &pdev->dev;
Alexander Shishkin8e229782013-06-24 14:46:36 +0300894 struct ci_hdrc *ci;
Alexander Shishkine443b332012-05-11 17:25:46 +0300895 struct resource *res;
896 void __iomem *base;
897 int ret;
Sascha Hauer691962d2013-06-13 17:59:57 +0300898 enum usb_dr_mode dr_mode;
Alexander Shishkine443b332012-05-11 17:25:46 +0300899
Jingoo Hanfad56742014-02-19 13:41:42 +0800900 if (!dev_get_platdata(dev)) {
Alexander Shishkine443b332012-05-11 17:25:46 +0300901 dev_err(dev, "platform data missing\n");
902 return -ENODEV;
903 }
904
905 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbi19290812013-03-30 02:46:27 +0200906 base = devm_ioremap_resource(dev, res);
907 if (IS_ERR(base))
908 return PTR_ERR(base);
Alexander Shishkine443b332012-05-11 17:25:46 +0300909
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300910 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
Fabio Estevamd0f99242014-11-26 13:44:23 +0800911 if (!ci)
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300912 return -ENOMEM;
Alexander Shishkine443b332012-05-11 17:25:46 +0300913
Peter Chena5d906b2016-11-15 18:05:33 +0800914 spin_lock_init(&ci->lock);
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300915 ci->dev = dev;
Jingoo Hanfad56742014-02-19 13:41:42 +0800916 ci->platdata = dev_get_platdata(dev);
Peter Chened8f8312014-01-10 13:51:27 +0800917 ci->imx28_write_fix = !!(ci->platdata->flags &
918 CI_HDRC_IMX28_WRITE_FIX);
Peter Chen1f874ed2015-02-11 12:44:45 +0800919 ci->supports_runtime_pm = !!(ci->platdata->flags &
920 CI_HDRC_SUPPORTS_RUNTIME_PM);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800921 platform_set_drvdata(pdev, ci);
Alexander Shishkine443b332012-05-11 17:25:46 +0300922
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300923 ret = hw_device_init(ci, base);
924 if (ret < 0) {
925 dev_err(dev, "can't initialize hardware\n");
926 return -ENODEV;
927 }
928
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800929 ret = ci_ulpi_init(ci);
930 if (ret)
931 return ret;
932
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100933 if (ci->platdata->phy) {
934 ci->phy = ci->platdata->phy;
935 } else if (ci->platdata->usb_phy) {
Antoine Tenartef44cb42014-10-30 18:41:16 +0100936 ci->usb_phy = ci->platdata->usb_phy;
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100937 } else {
Antoine Tenart21a5b572014-11-26 13:44:35 +0800938 ci->phy = devm_phy_get(dev->parent, "usb-phy");
939 ci->usb_phy = devm_usb_get_phy(dev->parent, USB_PHY_TYPE_USB2);
Peter Chenc859aa652014-02-19 13:41:40 +0800940
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100941 /* if both generic PHY and USB PHY layers aren't enabled */
942 if (PTR_ERR(ci->phy) == -ENOSYS &&
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800943 PTR_ERR(ci->usb_phy) == -ENXIO) {
944 ret = -ENXIO;
945 goto ulpi_exit;
946 }
Peter Chenc859aa652014-02-19 13:41:40 +0800947
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -0800948 if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) {
949 ret = -EPROBE_DEFER;
950 goto ulpi_exit;
951 }
Antoine Tenart1e5e2d32014-10-30 18:41:19 +0100952
953 if (IS_ERR(ci->phy))
954 ci->phy = NULL;
955 else if (IS_ERR(ci->usb_phy))
956 ci->usb_phy = NULL;
Peter Chenc859aa652014-02-19 13:41:40 +0800957 }
958
Peter Chend03cccf2014-04-23 15:56:37 +0800959 ret = ci_usb_phy_init(ci);
Peter Chen74475ed2013-09-24 12:47:53 +0800960 if (ret) {
961 dev_err(dev, "unable to init phy: %d\n", ret);
962 return ret;
963 }
964
Alexander Shishkineb70e5a2012-05-11 17:25:54 +0300965 ci->hw_bank.phys = res->start;
966
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300967 ci->irq = platform_get_irq(pdev, 0);
968 if (ci->irq < 0) {
969 dev_err(dev, "missing IRQ\n");
Fabio Estevam42d18212014-02-19 13:41:44 +0800970 ret = ci->irq;
Peter Chenc859aa652014-02-19 13:41:40 +0800971 goto deinit_phy;
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300972 }
973
Peter Chen577b2322013-08-14 12:44:08 +0300974 ci_get_otg_capable(ci);
975
Sascha Hauer691962d2013-06-13 17:59:57 +0300976 dr_mode = ci->platdata->dr_mode;
977 /* initialize role(s) before the interrupt is requested */
978 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
979 ret = ci_hdrc_host_init(ci);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +0800980 if (ret) {
981 if (ret == -ENXIO)
982 dev_info(dev, "doesn't support host\n");
983 else
984 goto deinit_phy;
985 }
Sascha Hauer691962d2013-06-13 17:59:57 +0300986 }
987
988 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
989 ret = ci_hdrc_gadget_init(ci);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +0800990 if (ret) {
991 if (ret == -ENXIO)
992 dev_info(dev, "doesn't support gadget\n");
993 else
994 goto deinit_host;
995 }
Sascha Hauer691962d2013-06-13 17:59:57 +0300996 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +0300997
998 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
999 dev_err(dev, "no supported roles\n");
Peter Chen74475ed2013-09-24 12:47:53 +08001000 ret = -ENODEV;
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +08001001 goto deinit_gadget;
Peter Chencbec6bd2013-08-14 12:44:10 +03001002 }
1003
Peter Chen27c62c22014-09-22 08:14:16 +08001004 if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) {
Peter Chencbec6bd2013-08-14 12:44:10 +03001005 ret = ci_hdrc_otg_init(ci);
1006 if (ret) {
1007 dev_err(dev, "init otg fails, ret = %d\n", ret);
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +08001008 goto deinit_gadget;
Peter Chencbec6bd2013-08-14 12:44:10 +03001009 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001010 }
1011
1012 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
Peter Chen577b2322013-08-14 12:44:08 +03001013 if (ci->is_otg) {
Peter Chen577b2322013-08-14 12:44:08 +03001014 ci->role = ci_otg_role(ci);
Li Jun0c33bf72014-04-23 15:56:38 +08001015 /* Enable ID change irq */
1016 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE);
Peter Chen577b2322013-08-14 12:44:08 +03001017 } else {
1018 /*
1019 * If the controller is not OTG capable, but support
1020 * role switch, the defalt role is gadget, and the
1021 * user can switch it through debugfs.
1022 */
1023 ci->role = CI_ROLE_GADGET;
1024 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001025 } else {
1026 ci->role = ci->roles[CI_ROLE_HOST]
1027 ? CI_ROLE_HOST
1028 : CI_ROLE_GADGET;
1029 }
1030
Li Jun4dcf7202014-04-23 15:56:50 +08001031 if (!ci_otg_is_fsm_mode(ci)) {
Li Jun961ea492015-02-11 12:45:03 +08001032 /* only update vbus status for peripheral */
1033 if (ci->role == CI_ROLE_GADGET)
1034 ci_handle_vbus_change(ci);
1035
Li Jun4dcf7202014-04-23 15:56:50 +08001036 ret = ci_role_start(ci, ci->role);
1037 if (ret) {
1038 dev_err(dev, "can't start %s role\n",
1039 ci_role(ci)->name);
1040 goto stop;
1041 }
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001042 }
1043
Peter Chen4c503dd2014-11-26 13:44:22 +08001044 ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED,
1045 ci->platdata->name, ci);
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001046 if (ret)
1047 goto stop;
1048
Ivan T. Ivanov3ecb3e02015-09-07 14:45:25 +03001049 ret = ci_extcon_register(ci);
1050 if (ret)
1051 goto stop;
1052
Peter Chen1f874ed2015-02-11 12:44:45 +08001053 if (ci->supports_runtime_pm) {
1054 pm_runtime_set_active(&pdev->dev);
1055 pm_runtime_enable(&pdev->dev);
1056 pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
1057 pm_runtime_mark_last_busy(ci->dev);
1058 pm_runtime_use_autosuspend(&pdev->dev);
1059 }
1060
Li Jun4dcf7202014-04-23 15:56:50 +08001061 if (ci_otg_is_fsm_mode(ci))
1062 ci_hdrc_otg_fsm_start(ci);
1063
Peter Chenf8efa762015-02-11 12:44:48 +08001064 device_set_wakeup_capable(&pdev->dev, true);
Greg Kroah-Hartmana61b75d2018-05-29 17:30:58 +02001065 dbg_create_files(ci);
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001066
Peter Chena932a802017-03-27 10:54:27 +08001067 ret = sysfs_create_group(&dev->kobj, &ci_attr_group);
1068 if (ret)
1069 goto remove_debug;
1070
1071 return 0;
1072
1073remove_debug:
1074 dbg_remove_files(ci);
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001075stop:
Jisheng Zhangc4a0bbb2017-04-26 16:59:34 +08001076 if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
1077 ci_hdrc_otg_destroy(ci);
1078deinit_gadget:
1079 ci_hdrc_gadget_destroy(ci);
1080deinit_host:
1081 ci_hdrc_host_destroy(ci);
Peter Chenc859aa652014-02-19 13:41:40 +08001082deinit_phy:
Antoine Tenart1e5e2d32014-10-30 18:41:19 +01001083 ci_usb_phy_exit(ci);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001084ulpi_exit:
1085 ci_ulpi_exit(ci);
Alexander Shishkine443b332012-05-11 17:25:46 +03001086
1087 return ret;
1088}
1089
Bill Pembertonfb4e98a2012-11-19 13:26:20 -05001090static int ci_hdrc_remove(struct platform_device *pdev)
Alexander Shishkine443b332012-05-11 17:25:46 +03001091{
Alexander Shishkin8e229782013-06-24 14:46:36 +03001092 struct ci_hdrc *ci = platform_get_drvdata(pdev);
Alexander Shishkine443b332012-05-11 17:25:46 +03001093
Peter Chen1f874ed2015-02-11 12:44:45 +08001094 if (ci->supports_runtime_pm) {
1095 pm_runtime_get_sync(&pdev->dev);
1096 pm_runtime_disable(&pdev->dev);
1097 pm_runtime_put_noidle(&pdev->dev);
1098 }
1099
Alexander Shishkinadf0f732013-03-30 12:53:53 +02001100 dbg_remove_files(ci);
Peter Chena932a802017-03-27 10:54:27 +08001101 sysfs_remove_group(&ci->dev->kobj, &ci_attr_group);
Peter Chen3f124d22013-08-14 12:44:07 +03001102 ci_role_destroy(ci);
Peter Chen864cf942013-09-24 12:47:55 +08001103 ci_hdrc_enter_lpm(ci, true);
Antoine Tenart1e5e2d32014-10-30 18:41:19 +01001104 ci_usb_phy_exit(ci);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001105 ci_ulpi_exit(ci);
Alexander Shishkine443b332012-05-11 17:25:46 +03001106
1107 return 0;
1108}
1109
Peter Chen1f874ed2015-02-11 12:44:45 +08001110#ifdef CONFIG_PM
Li Jun961ea492015-02-11 12:45:03 +08001111/* Prepare wakeup by SRP before suspend */
1112static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci)
1113{
1114 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
1115 !hw_read_otgsc(ci, OTGSC_ID)) {
1116 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP,
1117 PORTSC_PP);
1118 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN,
1119 PORTSC_WKCN);
1120 }
1121}
1122
1123/* Handle SRP when wakeup by data pulse */
1124static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci)
1125{
1126 if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) &&
1127 (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) {
1128 if (!hw_read_otgsc(ci, OTGSC_ID)) {
1129 ci->fsm.a_srp_det = 1;
1130 ci->fsm.a_bus_drop = 0;
1131 } else {
1132 ci->fsm.id = 1;
1133 }
1134 ci_otg_queue_work(ci);
1135 }
1136}
1137
Peter Chen80769322014-11-26 13:44:29 +08001138static void ci_controller_suspend(struct ci_hdrc *ci)
1139{
Peter Chen1f874ed2015-02-11 12:44:45 +08001140 disable_irq(ci->irq);
Peter Chen80769322014-11-26 13:44:29 +08001141 ci_hdrc_enter_lpm(ci, true);
Fabio Estevam1fbf4622015-09-08 22:18:14 -03001142 if (ci->platdata->phy_clkgate_delay_us)
1143 usleep_range(ci->platdata->phy_clkgate_delay_us,
1144 ci->platdata->phy_clkgate_delay_us + 50);
Peter Chen1f874ed2015-02-11 12:44:45 +08001145 usb_phy_set_suspend(ci->usb_phy, 1);
1146 ci->in_lpm = true;
1147 enable_irq(ci->irq);
Peter Chen80769322014-11-26 13:44:29 +08001148}
1149
1150static int ci_controller_resume(struct device *dev)
1151{
1152 struct ci_hdrc *ci = dev_get_drvdata(dev);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001153 int ret;
Peter Chen80769322014-11-26 13:44:29 +08001154
1155 dev_dbg(dev, "at %s\n", __func__);
1156
Peter Chen1f874ed2015-02-11 12:44:45 +08001157 if (!ci->in_lpm) {
1158 WARN_ON(1);
1159 return 0;
1160 }
Peter Chen80769322014-11-26 13:44:29 +08001161
Peter Chen1f874ed2015-02-11 12:44:45 +08001162 ci_hdrc_enter_lpm(ci, false);
Stephen Boyd7bb7e9b2016-12-28 14:56:55 -08001163
1164 ret = ci_ulpi_resume(ci);
1165 if (ret)
1166 return ret;
1167
Peter Chen80769322014-11-26 13:44:29 +08001168 if (ci->usb_phy) {
1169 usb_phy_set_suspend(ci->usb_phy, 0);
1170 usb_phy_set_wakeup(ci->usb_phy, false);
1171 hw_wait_phy_stable();
1172 }
1173
Peter Chen1f874ed2015-02-11 12:44:45 +08001174 ci->in_lpm = false;
1175 if (ci->wakeup_int) {
1176 ci->wakeup_int = false;
1177 pm_runtime_mark_last_busy(ci->dev);
1178 pm_runtime_put_autosuspend(ci->dev);
1179 enable_irq(ci->irq);
Li Jun961ea492015-02-11 12:45:03 +08001180 if (ci_otg_is_fsm_mode(ci))
1181 ci_otg_fsm_wakeup_by_srp(ci);
Peter Chen1f874ed2015-02-11 12:44:45 +08001182 }
1183
Peter Chen80769322014-11-26 13:44:29 +08001184 return 0;
1185}
1186
Peter Chen1f874ed2015-02-11 12:44:45 +08001187#ifdef CONFIG_PM_SLEEP
Peter Chen80769322014-11-26 13:44:29 +08001188static int ci_suspend(struct device *dev)
1189{
1190 struct ci_hdrc *ci = dev_get_drvdata(dev);
1191
1192 if (ci->wq)
1193 flush_workqueue(ci->wq);
Peter Chen1f874ed2015-02-11 12:44:45 +08001194 /*
1195 * Controller needs to be active during suspend, otherwise the core
1196 * may run resume when the parent is at suspend if other driver's
1197 * suspend fails, it occurs before parent's suspend has not started,
1198 * but the core suspend has finished.
1199 */
1200 if (ci->in_lpm)
1201 pm_runtime_resume(dev);
1202
1203 if (ci->in_lpm) {
1204 WARN_ON(1);
1205 return 0;
1206 }
Peter Chen80769322014-11-26 13:44:29 +08001207
Peter Chenf8efa762015-02-11 12:44:48 +08001208 if (device_may_wakeup(dev)) {
Li Jun961ea492015-02-11 12:45:03 +08001209 if (ci_otg_is_fsm_mode(ci))
1210 ci_otg_fsm_suspend_for_srp(ci);
1211
Peter Chenf8efa762015-02-11 12:44:48 +08001212 usb_phy_set_wakeup(ci->usb_phy, true);
1213 enable_irq_wake(ci->irq);
1214 }
1215
Peter Chen80769322014-11-26 13:44:29 +08001216 ci_controller_suspend(ci);
1217
1218 return 0;
1219}
1220
1221static int ci_resume(struct device *dev)
1222{
Peter Chen1f874ed2015-02-11 12:44:45 +08001223 struct ci_hdrc *ci = dev_get_drvdata(dev);
1224 int ret;
1225
Peter Chenf8efa762015-02-11 12:44:48 +08001226 if (device_may_wakeup(dev))
1227 disable_irq_wake(ci->irq);
1228
Peter Chen1f874ed2015-02-11 12:44:45 +08001229 ret = ci_controller_resume(dev);
1230 if (ret)
1231 return ret;
1232
1233 if (ci->supports_runtime_pm) {
1234 pm_runtime_disable(dev);
1235 pm_runtime_set_active(dev);
1236 pm_runtime_enable(dev);
1237 }
1238
1239 return ret;
Peter Chen80769322014-11-26 13:44:29 +08001240}
1241#endif /* CONFIG_PM_SLEEP */
1242
Peter Chen1f874ed2015-02-11 12:44:45 +08001243static int ci_runtime_suspend(struct device *dev)
1244{
1245 struct ci_hdrc *ci = dev_get_drvdata(dev);
1246
1247 dev_dbg(dev, "at %s\n", __func__);
1248
1249 if (ci->in_lpm) {
1250 WARN_ON(1);
1251 return 0;
1252 }
1253
Li Jun961ea492015-02-11 12:45:03 +08001254 if (ci_otg_is_fsm_mode(ci))
1255 ci_otg_fsm_suspend_for_srp(ci);
1256
Peter Chen1f874ed2015-02-11 12:44:45 +08001257 usb_phy_set_wakeup(ci->usb_phy, true);
1258 ci_controller_suspend(ci);
1259
1260 return 0;
1261}
1262
1263static int ci_runtime_resume(struct device *dev)
1264{
1265 return ci_controller_resume(dev);
1266}
1267
1268#endif /* CONFIG_PM */
Peter Chen80769322014-11-26 13:44:29 +08001269static const struct dev_pm_ops ci_pm_ops = {
1270 SET_SYSTEM_SLEEP_PM_OPS(ci_suspend, ci_resume)
Peter Chen1f874ed2015-02-11 12:44:45 +08001271 SET_RUNTIME_PM_OPS(ci_runtime_suspend, ci_runtime_resume, NULL)
Peter Chen80769322014-11-26 13:44:29 +08001272};
Peter Chen1f874ed2015-02-11 12:44:45 +08001273
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001274static struct platform_driver ci_hdrc_driver = {
1275 .probe = ci_hdrc_probe,
Bill Pemberton76904172012-11-19 13:21:08 -05001276 .remove = ci_hdrc_remove,
Alexander Shishkine443b332012-05-11 17:25:46 +03001277 .driver = {
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001278 .name = "ci_hdrc",
Peter Chen80769322014-11-26 13:44:29 +08001279 .pm = &ci_pm_ops,
Alexander Shishkine443b332012-05-11 17:25:46 +03001280 },
1281};
1282
Peter Chen2f01a332015-07-21 09:51:29 +08001283static int __init ci_hdrc_platform_register(void)
1284{
1285 ci_hdrc_host_driver_init();
1286 return platform_driver_register(&ci_hdrc_driver);
1287}
1288module_init(ci_hdrc_platform_register);
1289
1290static void __exit ci_hdrc_platform_unregister(void)
1291{
1292 platform_driver_unregister(&ci_hdrc_driver);
1293}
1294module_exit(ci_hdrc_platform_unregister);
Alexander Shishkine443b332012-05-11 17:25:46 +03001295
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001296MODULE_ALIAS("platform:ci_hdrc");
Alexander Shishkine443b332012-05-11 17:25:46 +03001297MODULE_LICENSE("GPL v2");
1298MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
Alexander Shishkin5f36e232012-05-11 17:25:47 +03001299MODULE_DESCRIPTION("ChipIdea HDRC Driver");