1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright 2012 Freescale Semiconductor, Inc. 4 */ 5 6 #include <linux/module.h> 7 #include <linux/of_platform.h> 8 #include <linux/err.h> 9 #include <linux/io.h> 10 #include <linux/delay.h> 11 12 #include "ci_hdrc_imx.h" 13 14 #define MX25_USB_PHY_CTRL_OFFSET 0x08 15 #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) 16 17 #define MX25_EHCI_INTERFACE_SINGLE_UNI (2 << 0) 18 #define MX25_EHCI_INTERFACE_DIFF_UNI (0 << 0) 19 #define MX25_EHCI_INTERFACE_MASK (0xf) 20 21 #define MX25_OTG_SIC_SHIFT 29 22 #define MX25_OTG_SIC_MASK (0x3 << MX25_OTG_SIC_SHIFT) 23 #define MX25_OTG_PM_BIT BIT(24) 24 #define MX25_OTG_PP_BIT BIT(11) 25 #define MX25_OTG_OCPOL_BIT BIT(3) 26 27 #define MX25_H1_SIC_SHIFT 21 28 #define MX25_H1_SIC_MASK (0x3 << MX25_H1_SIC_SHIFT) 29 #define MX25_H1_PP_BIT BIT(18) 30 #define MX25_H1_PM_BIT BIT(16) 31 #define MX25_H1_IPPUE_UP_BIT BIT(7) 32 #define MX25_H1_IPPUE_DOWN_BIT BIT(6) 33 #define MX25_H1_TLL_BIT BIT(5) 34 #define MX25_H1_USBTE_BIT BIT(4) 35 #define MX25_H1_OCPOL_BIT BIT(2) 36 37 #define MX27_H1_PM_BIT BIT(8) 38 #define MX27_H2_PM_BIT BIT(16) 39 #define MX27_OTG_PM_BIT BIT(24) 40 41 #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 42 #define MX53_USB_OTG_PHY_CTRL_1_OFFSET 0x0c 43 #define MX53_USB_CTRL_1_OFFSET 0x10 44 #define MX53_USB_CTRL_1_H2_XCVR_CLK_SEL_MASK (0x11 << 2) 45 #define MX53_USB_CTRL_1_H2_XCVR_CLK_SEL_ULPI BIT(2) 46 #define MX53_USB_CTRL_1_H3_XCVR_CLK_SEL_MASK (0x11 << 6) 47 #define MX53_USB_CTRL_1_H3_XCVR_CLK_SEL_ULPI BIT(6) 48 #define MX53_USB_UH2_CTRL_OFFSET 0x14 49 #define MX53_USB_UH3_CTRL_OFFSET 0x18 50 #define MX53_USB_CLKONOFF_CTRL_OFFSET 0x24 51 #define MX53_USB_CLKONOFF_CTRL_H2_INT60CKOFF BIT(21) 52 #define MX53_USB_CLKONOFF_CTRL_H3_INT60CKOFF BIT(22) 53 #define MX53_BM_OVER_CUR_DIS_H1 BIT(5) 54 #define MX53_BM_OVER_CUR_DIS_OTG BIT(8) 55 #define MX53_BM_OVER_CUR_DIS_UHx BIT(30) 56 #define MX53_USB_CTRL_1_UH2_ULPI_EN BIT(26) 57 #define MX53_USB_CTRL_1_UH3_ULPI_EN BIT(27) 58 #define MX53_USB_UHx_CTRL_WAKE_UP_EN BIT(7) 59 #define MX53_USB_UHx_CTRL_ULPI_INT_EN BIT(8) 60 #define MX53_USB_PHYCTRL1_PLLDIV_MASK 0x3 61 #define MX53_USB_PLL_DIV_24_MHZ 0x01 62 63 #define MX6_BM_NON_BURST_SETTING BIT(1) 64 #define MX6_BM_OVER_CUR_DIS BIT(7) 65 #define MX6_BM_OVER_CUR_POLARITY BIT(8) 66 #define MX6_BM_WAKEUP_ENABLE BIT(10) 67 #define MX6_BM_ID_WAKEUP BIT(16) 68 #define MX6_BM_VBUS_WAKEUP BIT(17) 69 #define MX6SX_BM_DPDM_WAKEUP_EN BIT(29) 70 #define MX6_BM_WAKEUP_INTR BIT(31) 71 #define MX6_USB_OTG1_PHY_CTRL 0x18 72 /* For imx6dql, it is host-only controller, for later imx6, it is otg's */ 73 #define MX6_USB_OTG2_PHY_CTRL 0x1c 74 #define MX6SX_USB_VBUS_WAKEUP_SOURCE(v) (v << 8) 75 #define MX6SX_USB_VBUS_WAKEUP_SOURCE_VBUS MX6SX_USB_VBUS_WAKEUP_SOURCE(0) 76 #define MX6SX_USB_VBUS_WAKEUP_SOURCE_AVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(1) 77 #define MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(2) 78 #define MX6SX_USB_VBUS_WAKEUP_SOURCE_SESS_END MX6SX_USB_VBUS_WAKEUP_SOURCE(3) 79 80 #define VF610_OVER_CUR_DIS BIT(7) 81 82 #define MX7D_USBNC_USB_CTRL2 0x4 83 #define MX7D_USB_VBUS_WAKEUP_SOURCE_MASK 0x3 84 #define MX7D_USB_VBUS_WAKEUP_SOURCE(v) (v << 0) 85 #define MX7D_USB_VBUS_WAKEUP_SOURCE_VBUS MX7D_USB_VBUS_WAKEUP_SOURCE(0) 86 #define MX7D_USB_VBUS_WAKEUP_SOURCE_AVALID MX7D_USB_VBUS_WAKEUP_SOURCE(1) 87 #define MX7D_USB_VBUS_WAKEUP_SOURCE_BVALID MX7D_USB_VBUS_WAKEUP_SOURCE(2) 88 #define MX7D_USB_VBUS_WAKEUP_SOURCE_SESS_END MX7D_USB_VBUS_WAKEUP_SOURCE(3) 89 90 struct usbmisc_ops { 91 /* It's called once when probe a usb device */ 92 int (*init)(struct imx_usbmisc_data *data); 93 /* It's called once after adding a usb device */ 94 int (*post)(struct imx_usbmisc_data *data); 95 /* It's called when we need to enable/disable usb wakeup */ 96 int (*set_wakeup)(struct imx_usbmisc_data *data, bool enabled); 97 }; 98 99 struct imx_usbmisc { 100 void __iomem *base; 101 spinlock_t lock; 102 const struct usbmisc_ops *ops; 103 }; 104 105 static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data); 106 107 static int usbmisc_imx25_init(struct imx_usbmisc_data *data) 108 { 109 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 110 unsigned long flags; 111 u32 val = 0; 112 113 if (data->index > 1) 114 return -EINVAL; 115 116 spin_lock_irqsave(&usbmisc->lock, flags); 117 switch (data->index) { 118 case 0: 119 val = readl(usbmisc->base); 120 val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT); 121 val |= (MX25_EHCI_INTERFACE_DIFF_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT; 122 val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT); 123 writel(val, usbmisc->base); 124 break; 125 case 1: 126 val = readl(usbmisc->base); 127 val &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT | MX25_H1_IPPUE_UP_BIT); 128 val |= (MX25_EHCI_INTERFACE_SINGLE_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT; 129 val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | 130 MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT); 131 132 writel(val, usbmisc->base); 133 134 break; 135 } 136 spin_unlock_irqrestore(&usbmisc->lock, flags); 137 138 return 0; 139 } 140 141 static int usbmisc_imx25_post(struct imx_usbmisc_data *data) 142 { 143 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 144 void __iomem *reg; 145 unsigned long flags; 146 u32 val; 147 148 if (data->index > 2) 149 return -EINVAL; 150 151 if (data->evdo) { 152 spin_lock_irqsave(&usbmisc->lock, flags); 153 reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET; 154 val = readl(reg); 155 writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg); 156 spin_unlock_irqrestore(&usbmisc->lock, flags); 157 usleep_range(5000, 10000); /* needed to stabilize voltage */ 158 } 159 160 return 0; 161 } 162 163 static int usbmisc_imx27_init(struct imx_usbmisc_data *data) 164 { 165 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 166 unsigned long flags; 167 u32 val; 168 169 switch (data->index) { 170 case 0: 171 val = MX27_OTG_PM_BIT; 172 break; 173 case 1: 174 val = MX27_H1_PM_BIT; 175 break; 176 case 2: 177 val = MX27_H2_PM_BIT; 178 break; 179 default: 180 return -EINVAL; 181 } 182 183 spin_lock_irqsave(&usbmisc->lock, flags); 184 if (data->disable_oc) 185 val = readl(usbmisc->base) | val; 186 else 187 val = readl(usbmisc->base) & ~val; 188 writel(val, usbmisc->base); 189 spin_unlock_irqrestore(&usbmisc->lock, flags); 190 191 return 0; 192 } 193 194 static int usbmisc_imx53_init(struct imx_usbmisc_data *data) 195 { 196 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 197 void __iomem *reg = NULL; 198 unsigned long flags; 199 u32 val = 0; 200 201 if (data->index > 3) 202 return -EINVAL; 203 204 /* Select a 24 MHz reference clock for the PHY */ 205 val = readl(usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET); 206 val &= ~MX53_USB_PHYCTRL1_PLLDIV_MASK; 207 val |= MX53_USB_PLL_DIV_24_MHZ; 208 writel(val, usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET); 209 210 spin_lock_irqsave(&usbmisc->lock, flags); 211 212 switch (data->index) { 213 case 0: 214 if (data->disable_oc) { 215 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; 216 val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG; 217 writel(val, reg); 218 } 219 break; 220 case 1: 221 if (data->disable_oc) { 222 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; 223 val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1; 224 writel(val, reg); 225 } 226 break; 227 case 2: 228 if (data->ulpi) { 229 /* set USBH2 into ULPI-mode. */ 230 reg = usbmisc->base + MX53_USB_CTRL_1_OFFSET; 231 val = readl(reg) | MX53_USB_CTRL_1_UH2_ULPI_EN; 232 /* select ULPI clock */ 233 val &= ~MX53_USB_CTRL_1_H2_XCVR_CLK_SEL_MASK; 234 val |= MX53_USB_CTRL_1_H2_XCVR_CLK_SEL_ULPI; 235 writel(val, reg); 236 /* Set interrupt wake up enable */ 237 reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET; 238 val = readl(reg) | MX53_USB_UHx_CTRL_WAKE_UP_EN 239 | MX53_USB_UHx_CTRL_ULPI_INT_EN; 240 writel(val, reg); 241 if (is_imx53_usbmisc(data)) { 242 /* Disable internal 60Mhz clock */ 243 reg = usbmisc->base + 244 MX53_USB_CLKONOFF_CTRL_OFFSET; 245 val = readl(reg) | 246 MX53_USB_CLKONOFF_CTRL_H2_INT60CKOFF; 247 writel(val, reg); 248 } 249 250 } 251 if (data->disable_oc) { 252 reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET; 253 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx; 254 writel(val, reg); 255 } 256 break; 257 case 3: 258 if (data->ulpi) { 259 /* set USBH3 into ULPI-mode. */ 260 reg = usbmisc->base + MX53_USB_CTRL_1_OFFSET; 261 val = readl(reg) | MX53_USB_CTRL_1_UH3_ULPI_EN; 262 /* select ULPI clock */ 263 val &= ~MX53_USB_CTRL_1_H3_XCVR_CLK_SEL_MASK; 264 val |= MX53_USB_CTRL_1_H3_XCVR_CLK_SEL_ULPI; 265 writel(val, reg); 266 /* Set interrupt wake up enable */ 267 reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET; 268 val = readl(reg) | MX53_USB_UHx_CTRL_WAKE_UP_EN 269 | MX53_USB_UHx_CTRL_ULPI_INT_EN; 270 writel(val, reg); 271 272 if (is_imx53_usbmisc(data)) { 273 /* Disable internal 60Mhz clock */ 274 reg = usbmisc->base + 275 MX53_USB_CLKONOFF_CTRL_OFFSET; 276 val = readl(reg) | 277 MX53_USB_CLKONOFF_CTRL_H3_INT60CKOFF; 278 writel(val, reg); 279 } 280 } 281 if (data->disable_oc) { 282 reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET; 283 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx; 284 writel(val, reg); 285 } 286 break; 287 } 288 289 spin_unlock_irqrestore(&usbmisc->lock, flags); 290 291 return 0; 292 } 293 294 static int usbmisc_imx6q_set_wakeup 295 (struct imx_usbmisc_data *data, bool enabled) 296 { 297 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 298 unsigned long flags; 299 u32 val; 300 u32 wakeup_setting = (MX6_BM_WAKEUP_ENABLE | 301 MX6_BM_VBUS_WAKEUP | MX6_BM_ID_WAKEUP); 302 int ret = 0; 303 304 if (data->index > 3) 305 return -EINVAL; 306 307 spin_lock_irqsave(&usbmisc->lock, flags); 308 val = readl(usbmisc->base + data->index * 4); 309 if (enabled) { 310 val |= wakeup_setting; 311 writel(val, usbmisc->base + data->index * 4); 312 } else { 313 if (val & MX6_BM_WAKEUP_INTR) 314 pr_debug("wakeup int at ci_hdrc.%d\n", data->index); 315 val &= ~wakeup_setting; 316 writel(val, usbmisc->base + data->index * 4); 317 } 318 spin_unlock_irqrestore(&usbmisc->lock, flags); 319 320 return ret; 321 } 322 323 static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) 324 { 325 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 326 unsigned long flags; 327 u32 reg; 328 329 if (data->index > 3) 330 return -EINVAL; 331 332 spin_lock_irqsave(&usbmisc->lock, flags); 333 334 reg = readl(usbmisc->base + data->index * 4); 335 if (data->disable_oc) { 336 reg |= MX6_BM_OVER_CUR_DIS; 337 } else if (data->oc_polarity == 1) { 338 /* High active */ 339 reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); 340 } 341 writel(reg, usbmisc->base + data->index * 4); 342 343 /* SoC non-burst setting */ 344 reg = readl(usbmisc->base + data->index * 4); 345 writel(reg | MX6_BM_NON_BURST_SETTING, 346 usbmisc->base + data->index * 4); 347 348 spin_unlock_irqrestore(&usbmisc->lock, flags); 349 350 usbmisc_imx6q_set_wakeup(data, false); 351 352 return 0; 353 } 354 355 static int usbmisc_imx6sx_init(struct imx_usbmisc_data *data) 356 { 357 void __iomem *reg = NULL; 358 unsigned long flags; 359 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 360 u32 val; 361 362 usbmisc_imx6q_init(data); 363 364 if (data->index == 0 || data->index == 1) { 365 reg = usbmisc->base + MX6_USB_OTG1_PHY_CTRL + data->index * 4; 366 spin_lock_irqsave(&usbmisc->lock, flags); 367 /* Set vbus wakeup source as bvalid */ 368 val = readl(reg); 369 writel(val | MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID, reg); 370 /* 371 * Disable dp/dm wakeup in device mode when vbus is 372 * not there. 373 */ 374 val = readl(usbmisc->base + data->index * 4); 375 writel(val & ~MX6SX_BM_DPDM_WAKEUP_EN, 376 usbmisc->base + data->index * 4); 377 spin_unlock_irqrestore(&usbmisc->lock, flags); 378 } 379 380 return 0; 381 } 382 383 static int usbmisc_vf610_init(struct imx_usbmisc_data *data) 384 { 385 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 386 u32 reg; 387 388 /* 389 * Vybrid only has one misc register set, but in two different 390 * areas. These is reflected in two instances of this driver. 391 */ 392 if (data->index >= 1) 393 return -EINVAL; 394 395 if (data->disable_oc) { 396 reg = readl(usbmisc->base); 397 writel(reg | VF610_OVER_CUR_DIS, usbmisc->base); 398 } 399 400 return 0; 401 } 402 403 static int usbmisc_imx7d_set_wakeup 404 (struct imx_usbmisc_data *data, bool enabled) 405 { 406 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 407 unsigned long flags; 408 u32 val; 409 u32 wakeup_setting = (MX6_BM_WAKEUP_ENABLE | 410 MX6_BM_VBUS_WAKEUP | MX6_BM_ID_WAKEUP); 411 412 spin_lock_irqsave(&usbmisc->lock, flags); 413 val = readl(usbmisc->base); 414 if (enabled) { 415 writel(val | wakeup_setting, usbmisc->base); 416 } else { 417 if (val & MX6_BM_WAKEUP_INTR) 418 dev_dbg(data->dev, "wakeup int\n"); 419 writel(val & ~wakeup_setting, usbmisc->base); 420 } 421 spin_unlock_irqrestore(&usbmisc->lock, flags); 422 423 return 0; 424 } 425 426 static int usbmisc_imx7d_init(struct imx_usbmisc_data *data) 427 { 428 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 429 unsigned long flags; 430 u32 reg; 431 432 if (data->index >= 1) 433 return -EINVAL; 434 435 spin_lock_irqsave(&usbmisc->lock, flags); 436 reg = readl(usbmisc->base); 437 if (data->disable_oc) { 438 reg |= MX6_BM_OVER_CUR_DIS; 439 } else if (data->oc_polarity == 1) { 440 /* High active */ 441 reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); 442 } 443 writel(reg, usbmisc->base); 444 445 reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2); 446 reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK; 447 writel(reg | MX7D_USB_VBUS_WAKEUP_SOURCE_BVALID, 448 usbmisc->base + MX7D_USBNC_USB_CTRL2); 449 spin_unlock_irqrestore(&usbmisc->lock, flags); 450 451 usbmisc_imx7d_set_wakeup(data, false); 452 453 return 0; 454 } 455 456 static const struct usbmisc_ops imx25_usbmisc_ops = { 457 .init = usbmisc_imx25_init, 458 .post = usbmisc_imx25_post, 459 }; 460 461 static const struct usbmisc_ops imx27_usbmisc_ops = { 462 .init = usbmisc_imx27_init, 463 }; 464 465 static const struct usbmisc_ops imx51_usbmisc_ops = { 466 .init = usbmisc_imx53_init, 467 }; 468 469 static const struct usbmisc_ops imx53_usbmisc_ops = { 470 .init = usbmisc_imx53_init, 471 }; 472 473 static const struct usbmisc_ops imx6q_usbmisc_ops = { 474 .set_wakeup = usbmisc_imx6q_set_wakeup, 475 .init = usbmisc_imx6q_init, 476 }; 477 478 static const struct usbmisc_ops vf610_usbmisc_ops = { 479 .init = usbmisc_vf610_init, 480 }; 481 482 static const struct usbmisc_ops imx6sx_usbmisc_ops = { 483 .set_wakeup = usbmisc_imx6q_set_wakeup, 484 .init = usbmisc_imx6sx_init, 485 }; 486 487 static const struct usbmisc_ops imx7d_usbmisc_ops = { 488 .init = usbmisc_imx7d_init, 489 .set_wakeup = usbmisc_imx7d_set_wakeup, 490 }; 491 492 static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data) 493 { 494 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 495 496 return usbmisc->ops == &imx53_usbmisc_ops; 497 } 498 499 int imx_usbmisc_init(struct imx_usbmisc_data *data) 500 { 501 struct imx_usbmisc *usbmisc; 502 503 if (!data) 504 return 0; 505 506 usbmisc = dev_get_drvdata(data->dev); 507 if (!usbmisc->ops->init) 508 return 0; 509 return usbmisc->ops->init(data); 510 } 511 EXPORT_SYMBOL_GPL(imx_usbmisc_init); 512 513 int imx_usbmisc_init_post(struct imx_usbmisc_data *data) 514 { 515 struct imx_usbmisc *usbmisc; 516 517 if (!data) 518 return 0; 519 520 usbmisc = dev_get_drvdata(data->dev); 521 if (!usbmisc->ops->post) 522 return 0; 523 return usbmisc->ops->post(data); 524 } 525 EXPORT_SYMBOL_GPL(imx_usbmisc_init_post); 526 527 int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled) 528 { 529 struct imx_usbmisc *usbmisc; 530 531 if (!data) 532 return 0; 533 534 usbmisc = dev_get_drvdata(data->dev); 535 if (!usbmisc->ops->set_wakeup) 536 return 0; 537 return usbmisc->ops->set_wakeup(data, enabled); 538 } 539 EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup); 540 541 static const struct of_device_id usbmisc_imx_dt_ids[] = { 542 { 543 .compatible = "fsl,imx25-usbmisc", 544 .data = &imx25_usbmisc_ops, 545 }, 546 { 547 .compatible = "fsl,imx35-usbmisc", 548 .data = &imx25_usbmisc_ops, 549 }, 550 { 551 .compatible = "fsl,imx27-usbmisc", 552 .data = &imx27_usbmisc_ops, 553 }, 554 { 555 .compatible = "fsl,imx51-usbmisc", 556 .data = &imx51_usbmisc_ops, 557 }, 558 { 559 .compatible = "fsl,imx53-usbmisc", 560 .data = &imx53_usbmisc_ops, 561 }, 562 { 563 .compatible = "fsl,imx6q-usbmisc", 564 .data = &imx6q_usbmisc_ops, 565 }, 566 { 567 .compatible = "fsl,vf610-usbmisc", 568 .data = &vf610_usbmisc_ops, 569 }, 570 { 571 .compatible = "fsl,imx6sx-usbmisc", 572 .data = &imx6sx_usbmisc_ops, 573 }, 574 { 575 .compatible = "fsl,imx6ul-usbmisc", 576 .data = &imx6sx_usbmisc_ops, 577 }, 578 { 579 .compatible = "fsl,imx7d-usbmisc", 580 .data = &imx7d_usbmisc_ops, 581 }, 582 { /* sentinel */ } 583 }; 584 MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); 585 586 static int usbmisc_imx_probe(struct platform_device *pdev) 587 { 588 struct resource *res; 589 struct imx_usbmisc *data; 590 const struct of_device_id *of_id; 591 592 of_id = of_match_device(usbmisc_imx_dt_ids, &pdev->dev); 593 if (!of_id) 594 return -ENODEV; 595 596 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 597 if (!data) 598 return -ENOMEM; 599 600 spin_lock_init(&data->lock); 601 602 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 603 data->base = devm_ioremap_resource(&pdev->dev, res); 604 if (IS_ERR(data->base)) 605 return PTR_ERR(data->base); 606 607 data->ops = (const struct usbmisc_ops *)of_id->data; 608 platform_set_drvdata(pdev, data); 609 610 return 0; 611 } 612 613 static int usbmisc_imx_remove(struct platform_device *pdev) 614 { 615 return 0; 616 } 617 618 static struct platform_driver usbmisc_imx_driver = { 619 .probe = usbmisc_imx_probe, 620 .remove = usbmisc_imx_remove, 621 .driver = { 622 .name = "usbmisc_imx", 623 .of_match_table = usbmisc_imx_dt_ids, 624 }, 625 }; 626 627 module_platform_driver(usbmisc_imx_driver); 628 629 MODULE_ALIAS("platform:usbmisc-imx"); 630 MODULE_LICENSE("GPL v2"); 631 MODULE_DESCRIPTION("driver for imx usb non-core registers"); 632 MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>"); 633