blob: 140945cb124f51056673dd3b52085fc73689e2ca [file] [log] [blame]
Richard Zhaod142d6b2012-09-12 14:58:05 +03001/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/module.h>
13#include <linux/of_platform.h>
Richard Zhaod142d6b2012-09-12 14:58:05 +030014#include <linux/err.h>
15#include <linux/io.h>
Michael Grzeschika0685332013-03-30 12:54:01 +020016#include <linux/delay.h>
Richard Zhaod142d6b2012-09-12 14:58:05 +030017
Alexander Shishkin8e229782013-06-24 14:46:36 +030018#include "ci_hdrc_imx.h"
Richard Zhaod142d6b2012-09-12 14:58:05 +030019
Michael Grzeschika0685332013-03-30 12:54:01 +020020#define MX25_USB_PHY_CTRL_OFFSET 0x08
21#define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23)
22
Denis Carikli72ee92d2014-04-23 15:56:36 +080023#define MX25_EHCI_INTERFACE_SINGLE_UNI (2 << 0)
24#define MX25_EHCI_INTERFACE_DIFF_UNI (0 << 0)
25#define MX25_EHCI_INTERFACE_MASK (0xf)
26
27#define MX25_OTG_SIC_SHIFT 29
28#define MX25_OTG_SIC_MASK (0x3 << MX25_OTG_SIC_SHIFT)
29#define MX25_OTG_PM_BIT BIT(24)
30#define MX25_OTG_PP_BIT BIT(11)
31#define MX25_OTG_OCPOL_BIT BIT(3)
32
33#define MX25_H1_SIC_SHIFT 21
34#define MX25_H1_SIC_MASK (0x3 << MX25_H1_SIC_SHIFT)
35#define MX25_H1_PP_BIT BIT(18)
36#define MX25_H1_PM_BIT BIT(16)
37#define MX25_H1_IPPUE_UP_BIT BIT(7)
38#define MX25_H1_IPPUE_DOWN_BIT BIT(6)
39#define MX25_H1_TLL_BIT BIT(5)
40#define MX25_H1_USBTE_BIT BIT(4)
41#define MX25_H1_OCPOL_BIT BIT(2)
42
Alexander Shiyan9f90e112013-12-06 16:35:14 +080043#define MX27_H1_PM_BIT BIT(8)
44#define MX27_H2_PM_BIT BIT(16)
45#define MX27_OTG_PM_BIT BIT(24)
46
Michael Grzeschikf0c910b2013-03-30 12:54:00 +020047#define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08
Fabio Estevam33f92a82014-05-04 09:24:39 +080048#define MX53_USB_OTG_PHY_CTRL_1_OFFSET 0x0c
Michael Grzeschikf0c910b2013-03-30 12:54:00 +020049#define MX53_USB_UH2_CTRL_OFFSET 0x14
50#define MX53_USB_UH3_CTRL_OFFSET 0x18
51#define MX53_BM_OVER_CUR_DIS_H1 BIT(5)
52#define MX53_BM_OVER_CUR_DIS_OTG BIT(8)
53#define MX53_BM_OVER_CUR_DIS_UHx BIT(30)
Fabio Estevam33f92a82014-05-04 09:24:39 +080054#define MX53_USB_PHYCTRL1_PLLDIV_MASK 0x3
55#define MX53_USB_PLL_DIV_24_MHZ 0x01
Michael Grzeschikf0c910b2013-03-30 12:54:00 +020056
Marc Kleine-Buddee6091082013-03-30 12:53:59 +020057#define MX6_BM_OVER_CUR_DIS BIT(7)
Peter Chenf636cec2015-02-11 12:44:46 +080058#define MX6_BM_WAKEUP_ENABLE BIT(10)
59#define MX6_BM_ID_WAKEUP BIT(16)
60#define MX6_BM_VBUS_WAKEUP BIT(17)
Peter Chen8721a752015-02-11 12:44:53 +080061#define MX6SX_BM_DPDM_WAKEUP_EN BIT(29)
Peter Chenf636cec2015-02-11 12:44:46 +080062#define MX6_BM_WAKEUP_INTR BIT(31)
Peter Chen8721a752015-02-11 12:44:53 +080063#define MX6_USB_OTG1_PHY_CTRL 0x18
64/* For imx6dql, it is host-only controller, for later imx6, it is otg's */
65#define MX6_USB_OTG2_PHY_CTRL 0x1c
66#define MX6SX_USB_VBUS_WAKEUP_SOURCE(v) (v << 8)
67#define MX6SX_USB_VBUS_WAKEUP_SOURCE_VBUS MX6SX_USB_VBUS_WAKEUP_SOURCE(0)
68#define MX6SX_USB_VBUS_WAKEUP_SOURCE_AVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(1)
69#define MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(2)
70#define MX6SX_USB_VBUS_WAKEUP_SOURCE_SESS_END MX6SX_USB_VBUS_WAKEUP_SOURCE(3)
Richard Zhaod142d6b2012-09-12 14:58:05 +030071
Stefan Agnerf40017e2014-09-22 08:14:15 +080072#define VF610_OVER_CUR_DIS BIT(7)
73
Sascha Hauer05986ba2013-08-14 12:44:16 +030074struct usbmisc_ops {
75 /* It's called once when probe a usb device */
76 int (*init)(struct imx_usbmisc_data *data);
77 /* It's called once after adding a usb device */
78 int (*post)(struct imx_usbmisc_data *data);
Peter Chenf636cec2015-02-11 12:44:46 +080079 /* It's called when we need to enable/disable usb wakeup */
80 int (*set_wakeup)(struct imx_usbmisc_data *data, bool enabled);
Sascha Hauer05986ba2013-08-14 12:44:16 +030081};
82
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +020083struct imx_usbmisc {
Richard Zhaod142d6b2012-09-12 14:58:05 +030084 void __iomem *base;
85 spinlock_t lock;
Marc Kleine-Buddee6091082013-03-30 12:53:59 +020086 const struct usbmisc_ops *ops;
Richard Zhaod142d6b2012-09-12 14:58:05 +030087};
88
Denis Carikli72ee92d2014-04-23 15:56:36 +080089static int usbmisc_imx25_init(struct imx_usbmisc_data *data)
90{
Stefan Agnerf40017e2014-09-22 08:14:15 +080091 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
Denis Carikli72ee92d2014-04-23 15:56:36 +080092 unsigned long flags;
93 u32 val = 0;
94
95 if (data->index > 1)
96 return -EINVAL;
97
98 spin_lock_irqsave(&usbmisc->lock, flags);
99 switch (data->index) {
100 case 0:
101 val = readl(usbmisc->base);
102 val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT);
103 val |= (MX25_EHCI_INTERFACE_DIFF_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT;
104 val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT);
105 writel(val, usbmisc->base);
106 break;
107 case 1:
108 val = readl(usbmisc->base);
109 val &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT | MX25_H1_IPPUE_UP_BIT);
110 val |= (MX25_EHCI_INTERFACE_SINGLE_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT;
111 val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT |
112 MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT);
113
114 writel(val, usbmisc->base);
115
116 break;
117 }
118 spin_unlock_irqrestore(&usbmisc->lock, flags);
119
120 return 0;
121}
122
Sascha Hauer05986ba2013-08-14 12:44:16 +0300123static int usbmisc_imx25_post(struct imx_usbmisc_data *data)
Richard Zhaod142d6b2012-09-12 14:58:05 +0300124{
Stefan Agnerf40017e2014-09-22 08:14:15 +0800125 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
Michael Grzeschika0685332013-03-30 12:54:01 +0200126 void __iomem *reg;
127 unsigned long flags;
128 u32 val;
129
Sascha Hauer05986ba2013-08-14 12:44:16 +0300130 if (data->index > 2)
131 return -EINVAL;
Michael Grzeschika0685332013-03-30 12:54:01 +0200132
Sascha Hauer05986ba2013-08-14 12:44:16 +0300133 if (data->evdo) {
Michael Grzeschika0685332013-03-30 12:54:01 +0200134 spin_lock_irqsave(&usbmisc->lock, flags);
Fabio Estevam8d1dc4d2014-11-26 13:44:25 +0800135 reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
Michael Grzeschika0685332013-03-30 12:54:01 +0200136 val = readl(reg);
137 writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
138 spin_unlock_irqrestore(&usbmisc->lock, flags);
139 usleep_range(5000, 10000); /* needed to stabilize voltage */
140 }
141
142 return 0;
143}
144
Alexander Shiyan9f90e112013-12-06 16:35:14 +0800145static int usbmisc_imx27_init(struct imx_usbmisc_data *data)
146{
Stefan Agnerf40017e2014-09-22 08:14:15 +0800147 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
Alexander Shiyan9f90e112013-12-06 16:35:14 +0800148 unsigned long flags;
149 u32 val;
150
151 switch (data->index) {
152 case 0:
153 val = MX27_OTG_PM_BIT;
154 break;
155 case 1:
156 val = MX27_H1_PM_BIT;
157 break;
158 case 2:
159 val = MX27_H2_PM_BIT;
160 break;
161 default:
162 return -EINVAL;
163 };
164
165 spin_lock_irqsave(&usbmisc->lock, flags);
166 if (data->disable_oc)
167 val = readl(usbmisc->base) | val;
168 else
169 val = readl(usbmisc->base) & ~val;
170 writel(val, usbmisc->base);
171 spin_unlock_irqrestore(&usbmisc->lock, flags);
172
173 return 0;
174}
175
Sascha Hauer05986ba2013-08-14 12:44:16 +0300176static int usbmisc_imx53_init(struct imx_usbmisc_data *data)
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200177{
Stefan Agnerf40017e2014-09-22 08:14:15 +0800178 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200179 void __iomem *reg = NULL;
180 unsigned long flags;
181 u32 val = 0;
182
Sascha Hauer05986ba2013-08-14 12:44:16 +0300183 if (data->index > 3)
184 return -EINVAL;
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200185
Fabio Estevam33f92a82014-05-04 09:24:39 +0800186 /* Select a 24 MHz reference clock for the PHY */
Fabio Estevam4a1d6cf2014-11-26 13:44:26 +0800187 val = readl(usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET);
Fabio Estevam33f92a82014-05-04 09:24:39 +0800188 val &= ~MX53_USB_PHYCTRL1_PLLDIV_MASK;
189 val |= MX53_USB_PLL_DIV_24_MHZ;
190 writel(val, usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET);
191
Sascha Hauer05986ba2013-08-14 12:44:16 +0300192 if (data->disable_oc) {
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200193 spin_lock_irqsave(&usbmisc->lock, flags);
Sascha Hauer05986ba2013-08-14 12:44:16 +0300194 switch (data->index) {
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200195 case 0:
196 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
197 val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG;
198 break;
199 case 1:
200 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
201 val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1;
202 break;
203 case 2:
204 reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET;
205 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
206 break;
207 case 3:
208 reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET;
209 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
210 break;
211 }
212 if (reg && val)
213 writel(val, reg);
214 spin_unlock_irqrestore(&usbmisc->lock, flags);
215 }
216
217 return 0;
218}
219
Peter Chenf636cec2015-02-11 12:44:46 +0800220static int usbmisc_imx6q_set_wakeup
221 (struct imx_usbmisc_data *data, bool enabled)
222{
223 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
224 unsigned long flags;
225 u32 val;
226 u32 wakeup_setting = (MX6_BM_WAKEUP_ENABLE |
227 MX6_BM_VBUS_WAKEUP | MX6_BM_ID_WAKEUP);
228 int ret = 0;
229
230 if (data->index > 3)
231 return -EINVAL;
232
233 spin_lock_irqsave(&usbmisc->lock, flags);
234 val = readl(usbmisc->base + data->index * 4);
235 if (enabled) {
236 val |= wakeup_setting;
237 writel(val, usbmisc->base + data->index * 4);
238 } else {
239 if (val & MX6_BM_WAKEUP_INTR)
240 pr_debug("wakeup int at ci_hdrc.%d\n", data->index);
241 val &= ~wakeup_setting;
242 writel(val, usbmisc->base + data->index * 4);
243 }
244 spin_unlock_irqrestore(&usbmisc->lock, flags);
245
246 return ret;
247}
248
Sascha Hauer05986ba2013-08-14 12:44:16 +0300249static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
Richard Zhaod142d6b2012-09-12 14:58:05 +0300250{
Stefan Agnerf40017e2014-09-22 08:14:15 +0800251 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
Richard Zhaod142d6b2012-09-12 14:58:05 +0300252 unsigned long flags;
253 u32 reg;
254
Sascha Hauer05986ba2013-08-14 12:44:16 +0300255 if (data->index > 3)
256 return -EINVAL;
Richard Zhaod142d6b2012-09-12 14:58:05 +0300257
Sascha Hauer05986ba2013-08-14 12:44:16 +0300258 if (data->disable_oc) {
Richard Zhaod142d6b2012-09-12 14:58:05 +0300259 spin_lock_irqsave(&usbmisc->lock, flags);
Sascha Hauer05986ba2013-08-14 12:44:16 +0300260 reg = readl(usbmisc->base + data->index * 4);
Marc Kleine-Buddee6091082013-03-30 12:53:59 +0200261 writel(reg | MX6_BM_OVER_CUR_DIS,
Sascha Hauer05986ba2013-08-14 12:44:16 +0300262 usbmisc->base + data->index * 4);
Richard Zhaod142d6b2012-09-12 14:58:05 +0300263 spin_unlock_irqrestore(&usbmisc->lock, flags);
264 }
265
Peter Chenf636cec2015-02-11 12:44:46 +0800266 usbmisc_imx6q_set_wakeup(data, false);
267
Richard Zhaod142d6b2012-09-12 14:58:05 +0300268 return 0;
269}
270
Peter Chen8721a752015-02-11 12:44:53 +0800271static int usbmisc_imx6sx_init(struct imx_usbmisc_data *data)
272{
273 void __iomem *reg = NULL;
274 unsigned long flags;
275 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
276 u32 val;
Peter Chen8721a752015-02-11 12:44:53 +0800277
278 usbmisc_imx6q_init(data);
279
280 if (data->index == 0 || data->index == 1) {
281 reg = usbmisc->base + MX6_USB_OTG1_PHY_CTRL + data->index * 4;
282 spin_lock_irqsave(&usbmisc->lock, flags);
283 /* Set vbus wakeup source as bvalid */
284 val = readl(reg);
285 writel(val | MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID, reg);
286 /*
287 * Disable dp/dm wakeup in device mode when vbus is
288 * not there.
289 */
290 val = readl(usbmisc->base + data->index * 4);
291 writel(val & ~MX6SX_BM_DPDM_WAKEUP_EN,
292 usbmisc->base + data->index * 4);
293 spin_unlock_irqrestore(&usbmisc->lock, flags);
294 }
295
kbuild test robot1fcefbd2015-03-25 07:23:52 +0100296 return 0;
Peter Chen8721a752015-02-11 12:44:53 +0800297}
298
Stefan Agnerf40017e2014-09-22 08:14:15 +0800299static int usbmisc_vf610_init(struct imx_usbmisc_data *data)
300{
301 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
302 u32 reg;
303
304 /*
305 * Vybrid only has one misc register set, but in two different
306 * areas. These is reflected in two instances of this driver.
307 */
308 if (data->index >= 1)
309 return -EINVAL;
310
311 if (data->disable_oc) {
312 reg = readl(usbmisc->base);
313 writel(reg | VF610_OVER_CUR_DIS, usbmisc->base);
314 }
315
316 return 0;
317}
318
Michael Grzeschika0685332013-03-30 12:54:01 +0200319static const struct usbmisc_ops imx25_usbmisc_ops = {
Denis Carikli72ee92d2014-04-23 15:56:36 +0800320 .init = usbmisc_imx25_init,
Michael Grzeschika0685332013-03-30 12:54:01 +0200321 .post = usbmisc_imx25_post,
322};
323
Alexander Shiyan9f90e112013-12-06 16:35:14 +0800324static const struct usbmisc_ops imx27_usbmisc_ops = {
325 .init = usbmisc_imx27_init,
326};
327
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200328static const struct usbmisc_ops imx53_usbmisc_ops = {
329 .init = usbmisc_imx53_init,
330};
331
Richard Zhaod142d6b2012-09-12 14:58:05 +0300332static const struct usbmisc_ops imx6q_usbmisc_ops = {
Peter Chenf636cec2015-02-11 12:44:46 +0800333 .set_wakeup = usbmisc_imx6q_set_wakeup,
Richard Zhaod142d6b2012-09-12 14:58:05 +0300334 .init = usbmisc_imx6q_init,
335};
336
Stefan Agnerf40017e2014-09-22 08:14:15 +0800337static const struct usbmisc_ops vf610_usbmisc_ops = {
338 .init = usbmisc_vf610_init,
339};
340
Peter Chen8721a752015-02-11 12:44:53 +0800341static const struct usbmisc_ops imx6sx_usbmisc_ops = {
342 .set_wakeup = usbmisc_imx6q_set_wakeup,
343 .init = usbmisc_imx6sx_init,
344};
345
Sascha Hauer05986ba2013-08-14 12:44:16 +0300346int imx_usbmisc_init(struct imx_usbmisc_data *data)
347{
Peter Chena4cf1b12015-02-11 12:44:44 +0800348 struct imx_usbmisc *usbmisc;
Stefan Agnerf40017e2014-09-22 08:14:15 +0800349
Peter Chena4cf1b12015-02-11 12:44:44 +0800350 if (!data)
351 return 0;
352
353 usbmisc = dev_get_drvdata(data->dev);
Sascha Hauer05986ba2013-08-14 12:44:16 +0300354 if (!usbmisc->ops->init)
355 return 0;
356 return usbmisc->ops->init(data);
357}
358EXPORT_SYMBOL_GPL(imx_usbmisc_init);
359
360int imx_usbmisc_init_post(struct imx_usbmisc_data *data)
361{
Peter Chena4cf1b12015-02-11 12:44:44 +0800362 struct imx_usbmisc *usbmisc;
Stefan Agnerf40017e2014-09-22 08:14:15 +0800363
Peter Chena4cf1b12015-02-11 12:44:44 +0800364 if (!data)
365 return 0;
366
367 usbmisc = dev_get_drvdata(data->dev);
Sascha Hauer05986ba2013-08-14 12:44:16 +0300368 if (!usbmisc->ops->post)
369 return 0;
370 return usbmisc->ops->post(data);
371}
372EXPORT_SYMBOL_GPL(imx_usbmisc_init_post);
373
Peter Chenf636cec2015-02-11 12:44:46 +0800374int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled)
375{
376 struct imx_usbmisc *usbmisc;
377
378 if (!data)
379 return 0;
380
381 usbmisc = dev_get_drvdata(data->dev);
382 if (!usbmisc->ops->set_wakeup)
383 return 0;
384 return usbmisc->ops->set_wakeup(data, enabled);
385}
386EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup);
387
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200388static const struct of_device_id usbmisc_imx_dt_ids[] = {
Marc Kleine-Buddee6091082013-03-30 12:53:59 +0200389 {
Michael Grzeschika0685332013-03-30 12:54:01 +0200390 .compatible = "fsl,imx25-usbmisc",
391 .data = &imx25_usbmisc_ops,
392 },
393 {
Denis Carikli72ee92d2014-04-23 15:56:36 +0800394 .compatible = "fsl,imx35-usbmisc",
395 .data = &imx25_usbmisc_ops,
396 },
397 {
Alexander Shiyan9f90e112013-12-06 16:35:14 +0800398 .compatible = "fsl,imx27-usbmisc",
399 .data = &imx27_usbmisc_ops,
400 },
401 {
Alexander Shiyanc4962e02013-12-06 16:35:15 +0800402 .compatible = "fsl,imx51-usbmisc",
403 .data = &imx53_usbmisc_ops,
404 },
405 {
Michael Grzeschikf0c910b2013-03-30 12:54:00 +0200406 .compatible = "fsl,imx53-usbmisc",
407 .data = &imx53_usbmisc_ops,
408 },
409 {
Marc Kleine-Buddee6091082013-03-30 12:53:59 +0200410 .compatible = "fsl,imx6q-usbmisc",
411 .data = &imx6q_usbmisc_ops,
412 },
Stefan Agnerf40017e2014-09-22 08:14:15 +0800413 {
414 .compatible = "fsl,vf610-usbmisc",
415 .data = &vf610_usbmisc_ops,
416 },
Peter Chen8721a752015-02-11 12:44:53 +0800417 {
418 .compatible = "fsl,imx6sx-usbmisc",
419 .data = &imx6sx_usbmisc_ops,
420 },
Richard Zhaod142d6b2012-09-12 14:58:05 +0300421 { /* sentinel */ }
422};
Arnaud Patard (Rtp)269b83d2013-06-20 23:33:25 +0200423MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
Richard Zhaod142d6b2012-09-12 14:58:05 +0300424
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200425static int usbmisc_imx_probe(struct platform_device *pdev)
Richard Zhaod142d6b2012-09-12 14:58:05 +0300426{
427 struct resource *res;
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200428 struct imx_usbmisc *data;
Marc Kleine-Buddee6091082013-03-30 12:53:59 +0200429 struct of_device_id *tmp_dev;
Richard Zhaod142d6b2012-09-12 14:58:05 +0300430
Richard Zhaod142d6b2012-09-12 14:58:05 +0300431 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
432 if (!data)
433 return -ENOMEM;
434
435 spin_lock_init(&data->lock);
436
437 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Reding148e1132013-01-21 11:09:22 +0100438 data->base = devm_ioremap_resource(&pdev->dev, res);
439 if (IS_ERR(data->base))
440 return PTR_ERR(data->base);
Richard Zhaod142d6b2012-09-12 14:58:05 +0300441
Marc Kleine-Buddee6091082013-03-30 12:53:59 +0200442 tmp_dev = (struct of_device_id *)
443 of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
444 data->ops = (const struct usbmisc_ops *)tmp_dev->data;
Stefan Agnerf40017e2014-09-22 08:14:15 +0800445 platform_set_drvdata(pdev, data);
Richard Zhaod142d6b2012-09-12 14:58:05 +0300446
Richard Zhaod142d6b2012-09-12 14:58:05 +0300447 return 0;
448}
449
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200450static int usbmisc_imx_remove(struct platform_device *pdev)
Richard Zhaod142d6b2012-09-12 14:58:05 +0300451{
Richard Zhaod142d6b2012-09-12 14:58:05 +0300452 return 0;
453}
454
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200455static struct platform_driver usbmisc_imx_driver = {
456 .probe = usbmisc_imx_probe,
457 .remove = usbmisc_imx_remove,
Richard Zhaod142d6b2012-09-12 14:58:05 +0300458 .driver = {
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200459 .name = "usbmisc_imx",
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200460 .of_match_table = usbmisc_imx_dt_ids,
Richard Zhaod142d6b2012-09-12 14:58:05 +0300461 },
462};
463
Philipp Zabel0404ae02013-06-13 17:59:59 +0300464module_platform_driver(usbmisc_imx_driver);
Richard Zhaod142d6b2012-09-12 14:58:05 +0300465
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200466MODULE_ALIAS("platform:usbmisc-imx");
Richard Zhaod142d6b2012-09-12 14:58:05 +0300467MODULE_LICENSE("GPL v2");
Michael Grzeschika7bc2fd2013-03-30 12:53:56 +0200468MODULE_DESCRIPTION("driver for imx usb non-core registers");
Richard Zhaod142d6b2012-09-12 14:58:05 +0300469MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");