Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 1 | /* |
| 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 Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 14 | #include <linux/err.h> |
| 15 | #include <linux/io.h> |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 16 | #include <linux/delay.h> |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 17 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 18 | #include "ci_hdrc_imx.h" |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 19 | |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 20 | #define MX25_USB_PHY_CTRL_OFFSET 0x08 |
| 21 | #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) |
| 22 | |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 23 | #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 Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 43 | #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 Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 47 | #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 48 | #define MX53_USB_OTG_PHY_CTRL_1_OFFSET 0x0c |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 49 | #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 Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 54 | #define MX53_USB_PHYCTRL1_PLLDIV_MASK 0x3 |
| 55 | #define MX53_USB_PLL_DIV_24_MHZ 0x01 |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 56 | |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 57 | #define MX6_BM_OVER_CUR_DIS BIT(7) |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 58 | #define MX6_BM_WAKEUP_ENABLE BIT(10) |
| 59 | #define MX6_BM_ID_WAKEUP BIT(16) |
| 60 | #define MX6_BM_VBUS_WAKEUP BIT(17) |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 61 | #define MX6SX_BM_DPDM_WAKEUP_EN BIT(29) |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 62 | #define MX6_BM_WAKEUP_INTR BIT(31) |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 63 | #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 Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 71 | |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 72 | #define VF610_OVER_CUR_DIS BIT(7) |
| 73 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 74 | struct 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 Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 79 | /* It's called when we need to enable/disable usb wakeup */ |
| 80 | int (*set_wakeup)(struct imx_usbmisc_data *data, bool enabled); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 81 | }; |
| 82 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 83 | struct imx_usbmisc { |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 84 | void __iomem *base; |
| 85 | spinlock_t lock; |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 86 | const struct usbmisc_ops *ops; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 87 | }; |
| 88 | |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 89 | static int usbmisc_imx25_init(struct imx_usbmisc_data *data) |
| 90 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 91 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 92 | 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 Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 123 | static int usbmisc_imx25_post(struct imx_usbmisc_data *data) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 124 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 125 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 126 | void __iomem *reg; |
| 127 | unsigned long flags; |
| 128 | u32 val; |
| 129 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 130 | if (data->index > 2) |
| 131 | return -EINVAL; |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 132 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 133 | if (data->evdo) { |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 134 | spin_lock_irqsave(&usbmisc->lock, flags); |
Fabio Estevam | 8d1dc4d | 2014-11-26 13:44:25 +0800 | [diff] [blame] | 135 | reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET; |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 136 | 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 Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 145 | static int usbmisc_imx27_init(struct imx_usbmisc_data *data) |
| 146 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 147 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 148 | 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 Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 176 | static int usbmisc_imx53_init(struct imx_usbmisc_data *data) |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 177 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 178 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 179 | void __iomem *reg = NULL; |
| 180 | unsigned long flags; |
| 181 | u32 val = 0; |
| 182 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 183 | if (data->index > 3) |
| 184 | return -EINVAL; |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 185 | |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 186 | /* Select a 24 MHz reference clock for the PHY */ |
Fabio Estevam | 4a1d6cf | 2014-11-26 13:44:26 +0800 | [diff] [blame] | 187 | val = readl(usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET); |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 188 | 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 Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 192 | if (data->disable_oc) { |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 193 | spin_lock_irqsave(&usbmisc->lock, flags); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 194 | switch (data->index) { |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 195 | 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 Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 220 | static 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 Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 249 | static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 250 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 251 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 252 | unsigned long flags; |
| 253 | u32 reg; |
| 254 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 255 | if (data->index > 3) |
| 256 | return -EINVAL; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 257 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 258 | if (data->disable_oc) { |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 259 | spin_lock_irqsave(&usbmisc->lock, flags); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 260 | reg = readl(usbmisc->base + data->index * 4); |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 261 | writel(reg | MX6_BM_OVER_CUR_DIS, |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 262 | usbmisc->base + data->index * 4); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 263 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 264 | } |
| 265 | |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 266 | usbmisc_imx6q_set_wakeup(data, false); |
| 267 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 271 | static 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 Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 277 | |
| 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 robot | 1fcefbd | 2015-03-25 07:23:52 +0100 | [diff] [blame] | 296 | return 0; |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 297 | } |
| 298 | |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 299 | static 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 Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 319 | static const struct usbmisc_ops imx25_usbmisc_ops = { |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 320 | .init = usbmisc_imx25_init, |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 321 | .post = usbmisc_imx25_post, |
| 322 | }; |
| 323 | |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 324 | static const struct usbmisc_ops imx27_usbmisc_ops = { |
| 325 | .init = usbmisc_imx27_init, |
| 326 | }; |
| 327 | |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 328 | static const struct usbmisc_ops imx53_usbmisc_ops = { |
| 329 | .init = usbmisc_imx53_init, |
| 330 | }; |
| 331 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 332 | static const struct usbmisc_ops imx6q_usbmisc_ops = { |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 333 | .set_wakeup = usbmisc_imx6q_set_wakeup, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 334 | .init = usbmisc_imx6q_init, |
| 335 | }; |
| 336 | |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 337 | static const struct usbmisc_ops vf610_usbmisc_ops = { |
| 338 | .init = usbmisc_vf610_init, |
| 339 | }; |
| 340 | |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 341 | static const struct usbmisc_ops imx6sx_usbmisc_ops = { |
| 342 | .set_wakeup = usbmisc_imx6q_set_wakeup, |
| 343 | .init = usbmisc_imx6sx_init, |
| 344 | }; |
| 345 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 346 | int imx_usbmisc_init(struct imx_usbmisc_data *data) |
| 347 | { |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 348 | struct imx_usbmisc *usbmisc; |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 349 | |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 350 | if (!data) |
| 351 | return 0; |
| 352 | |
| 353 | usbmisc = dev_get_drvdata(data->dev); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 354 | if (!usbmisc->ops->init) |
| 355 | return 0; |
| 356 | return usbmisc->ops->init(data); |
| 357 | } |
| 358 | EXPORT_SYMBOL_GPL(imx_usbmisc_init); |
| 359 | |
| 360 | int imx_usbmisc_init_post(struct imx_usbmisc_data *data) |
| 361 | { |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 362 | struct imx_usbmisc *usbmisc; |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 363 | |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 364 | if (!data) |
| 365 | return 0; |
| 366 | |
| 367 | usbmisc = dev_get_drvdata(data->dev); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 368 | if (!usbmisc->ops->post) |
| 369 | return 0; |
| 370 | return usbmisc->ops->post(data); |
| 371 | } |
| 372 | EXPORT_SYMBOL_GPL(imx_usbmisc_init_post); |
| 373 | |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 374 | int 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 | } |
| 386 | EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup); |
| 387 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 388 | static const struct of_device_id usbmisc_imx_dt_ids[] = { |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 389 | { |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 390 | .compatible = "fsl,imx25-usbmisc", |
| 391 | .data = &imx25_usbmisc_ops, |
| 392 | }, |
| 393 | { |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 394 | .compatible = "fsl,imx35-usbmisc", |
| 395 | .data = &imx25_usbmisc_ops, |
| 396 | }, |
| 397 | { |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 398 | .compatible = "fsl,imx27-usbmisc", |
| 399 | .data = &imx27_usbmisc_ops, |
| 400 | }, |
| 401 | { |
Alexander Shiyan | c4962e0 | 2013-12-06 16:35:15 +0800 | [diff] [blame] | 402 | .compatible = "fsl,imx51-usbmisc", |
| 403 | .data = &imx53_usbmisc_ops, |
| 404 | }, |
| 405 | { |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 406 | .compatible = "fsl,imx53-usbmisc", |
| 407 | .data = &imx53_usbmisc_ops, |
| 408 | }, |
| 409 | { |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 410 | .compatible = "fsl,imx6q-usbmisc", |
| 411 | .data = &imx6q_usbmisc_ops, |
| 412 | }, |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 413 | { |
| 414 | .compatible = "fsl,vf610-usbmisc", |
| 415 | .data = &vf610_usbmisc_ops, |
| 416 | }, |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 417 | { |
| 418 | .compatible = "fsl,imx6sx-usbmisc", |
| 419 | .data = &imx6sx_usbmisc_ops, |
| 420 | }, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 421 | { /* sentinel */ } |
| 422 | }; |
Arnaud Patard (Rtp) | 269b83d | 2013-06-20 23:33:25 +0200 | [diff] [blame] | 423 | MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 424 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 425 | static int usbmisc_imx_probe(struct platform_device *pdev) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 426 | { |
| 427 | struct resource *res; |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 428 | struct imx_usbmisc *data; |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 429 | struct of_device_id *tmp_dev; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 430 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 431 | 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 Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 438 | data->base = devm_ioremap_resource(&pdev->dev, res); |
| 439 | if (IS_ERR(data->base)) |
| 440 | return PTR_ERR(data->base); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 441 | |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 442 | 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 Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 445 | platform_set_drvdata(pdev, data); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 446 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 450 | static int usbmisc_imx_remove(struct platform_device *pdev) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 451 | { |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 455 | static struct platform_driver usbmisc_imx_driver = { |
| 456 | .probe = usbmisc_imx_probe, |
| 457 | .remove = usbmisc_imx_remove, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 458 | .driver = { |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 459 | .name = "usbmisc_imx", |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 460 | .of_match_table = usbmisc_imx_dt_ids, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 461 | }, |
| 462 | }; |
| 463 | |
Philipp Zabel | 0404ae0 | 2013-06-13 17:59:59 +0300 | [diff] [blame] | 464 | module_platform_driver(usbmisc_imx_driver); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 465 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 466 | MODULE_ALIAS("platform:usbmisc-imx"); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 467 | MODULE_LICENSE("GPL v2"); |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 468 | MODULE_DESCRIPTION("driver for imx usb non-core registers"); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 469 | MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>"); |