Tony Lindgren | b5e8905 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Platform level USB initialization for FS USB OTG controller on omap1 and 24xx |
| 3 | * |
| 4 | * Copyright (C) 2004 Texas Instruments, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/platform_device.h> |
Tony Lindgren | 9809383 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 27 | #include <linux/clk.h> |
| 28 | #include <linux/err.h> |
Tony Lindgren | b5e8905 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 29 | |
| 30 | #include <asm/irq.h> |
| 31 | |
| 32 | #include <plat/control.h> |
| 33 | #include <plat/mux.h> |
| 34 | #include <plat/usb.h> |
| 35 | #include <plat/board.h> |
| 36 | |
| 37 | #define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN |
| 38 | #define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO |
| 39 | #define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO |
| 40 | #define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN |
| 41 | #define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG |
| 42 | |
| 43 | #if defined(CONFIG_ARCH_OMAP2) |
| 44 | |
| 45 | #ifdef CONFIG_USB_GADGET_OMAP |
| 46 | |
| 47 | static struct resource udc_resources[] = { |
| 48 | /* order is significant! */ |
| 49 | { /* registers */ |
| 50 | .start = UDC_BASE, |
| 51 | .end = UDC_BASE + 0xff, |
| 52 | .flags = IORESOURCE_MEM, |
| 53 | }, { /* general IRQ */ |
| 54 | .start = INT_USB_IRQ_GEN, |
| 55 | .flags = IORESOURCE_IRQ, |
| 56 | }, { /* PIO IRQ */ |
| 57 | .start = INT_USB_IRQ_NISO, |
| 58 | .flags = IORESOURCE_IRQ, |
| 59 | }, { /* SOF IRQ */ |
| 60 | .start = INT_USB_IRQ_ISO, |
| 61 | .flags = IORESOURCE_IRQ, |
| 62 | }, |
| 63 | }; |
| 64 | |
| 65 | static u64 udc_dmamask = ~(u32)0; |
| 66 | |
| 67 | static struct platform_device udc_device = { |
| 68 | .name = "omap_udc", |
| 69 | .id = -1, |
| 70 | .dev = { |
| 71 | .dma_mask = &udc_dmamask, |
| 72 | .coherent_dma_mask = 0xffffffff, |
| 73 | }, |
| 74 | .num_resources = ARRAY_SIZE(udc_resources), |
| 75 | .resource = udc_resources, |
| 76 | }; |
| 77 | |
| 78 | static inline void udc_device_init(struct omap_usb_config *pdata) |
| 79 | { |
| 80 | pdata->udc_device = &udc_device; |
| 81 | } |
| 82 | |
| 83 | #else |
| 84 | |
| 85 | static inline void udc_device_init(struct omap_usb_config *pdata) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | #endif |
| 90 | |
| 91 | #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) |
| 92 | |
| 93 | /* The dmamask must be set for OHCI to work */ |
| 94 | static u64 ohci_dmamask = ~(u32)0; |
| 95 | |
| 96 | static struct resource ohci_resources[] = { |
| 97 | { |
| 98 | .start = OMAP_OHCI_BASE, |
| 99 | .end = OMAP_OHCI_BASE + 0xff, |
| 100 | .flags = IORESOURCE_MEM, |
| 101 | }, |
| 102 | { |
| 103 | .start = INT_USB_IRQ_HGEN, |
| 104 | .flags = IORESOURCE_IRQ, |
| 105 | }, |
| 106 | }; |
| 107 | |
| 108 | static struct platform_device ohci_device = { |
| 109 | .name = "ohci", |
| 110 | .id = -1, |
| 111 | .dev = { |
| 112 | .dma_mask = &ohci_dmamask, |
| 113 | .coherent_dma_mask = 0xffffffff, |
| 114 | }, |
| 115 | .num_resources = ARRAY_SIZE(ohci_resources), |
| 116 | .resource = ohci_resources, |
| 117 | }; |
| 118 | |
| 119 | static inline void ohci_device_init(struct omap_usb_config *pdata) |
| 120 | { |
| 121 | pdata->ohci_device = &ohci_device; |
| 122 | } |
| 123 | |
| 124 | #else |
| 125 | |
| 126 | static inline void ohci_device_init(struct omap_usb_config *pdata) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | #endif |
| 131 | |
| 132 | #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG) |
| 133 | |
| 134 | static struct resource otg_resources[] = { |
| 135 | /* order is significant! */ |
| 136 | { |
| 137 | .start = OTG_BASE, |
| 138 | .end = OTG_BASE + 0xff, |
| 139 | .flags = IORESOURCE_MEM, |
| 140 | }, { |
| 141 | .start = INT_USB_IRQ_OTG, |
| 142 | .flags = IORESOURCE_IRQ, |
| 143 | }, |
| 144 | }; |
| 145 | |
| 146 | static struct platform_device otg_device = { |
| 147 | .name = "omap_otg", |
| 148 | .id = -1, |
| 149 | .num_resources = ARRAY_SIZE(otg_resources), |
| 150 | .resource = otg_resources, |
| 151 | }; |
| 152 | |
| 153 | static inline void otg_device_init(struct omap_usb_config *pdata) |
| 154 | { |
| 155 | pdata->otg_device = &otg_device; |
| 156 | } |
| 157 | |
| 158 | #else |
| 159 | |
| 160 | static inline void otg_device_init(struct omap_usb_config *pdata) |
| 161 | { |
| 162 | } |
| 163 | |
| 164 | #endif |
| 165 | |
| 166 | static void omap2_usb_devconf_clear(u8 port, u32 mask) |
| 167 | { |
| 168 | u32 r; |
| 169 | |
| 170 | r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 171 | r &= ~USBTXWRMODEI(port, mask); |
| 172 | omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0); |
| 173 | } |
| 174 | |
| 175 | static void omap2_usb_devconf_set(u8 port, u32 mask) |
| 176 | { |
| 177 | u32 r; |
| 178 | |
| 179 | r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 180 | r |= USBTXWRMODEI(port, mask); |
| 181 | omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0); |
| 182 | } |
| 183 | |
| 184 | static void omap2_usb2_disable_5pinbitll(void) |
| 185 | { |
| 186 | u32 r; |
| 187 | |
| 188 | r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 189 | r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI); |
| 190 | omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0); |
| 191 | } |
| 192 | |
| 193 | static void omap2_usb2_enable_5pinunitll(void) |
| 194 | { |
| 195 | u32 r; |
| 196 | |
| 197 | r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 198 | r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI; |
| 199 | omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0); |
| 200 | } |
| 201 | |
| 202 | static u32 __init omap2_usb0_init(unsigned nwires, unsigned is_device) |
| 203 | { |
| 204 | u32 syscon1 = 0; |
| 205 | |
| 206 | omap2_usb_devconf_clear(0, USB_BIDIR_TLL); |
| 207 | |
| 208 | if (nwires == 0) |
| 209 | return 0; |
| 210 | |
| 211 | if (is_device) |
| 212 | omap_cfg_reg(J20_24XX_USB0_PUEN); |
| 213 | |
| 214 | omap_cfg_reg(K18_24XX_USB0_DAT); |
| 215 | omap_cfg_reg(K19_24XX_USB0_TXEN); |
| 216 | omap_cfg_reg(J14_24XX_USB0_SE0); |
| 217 | if (nwires != 3) |
| 218 | omap_cfg_reg(J18_24XX_USB0_RCV); |
| 219 | |
| 220 | switch (nwires) { |
| 221 | case 3: |
| 222 | syscon1 = 2; |
| 223 | omap2_usb_devconf_set(0, USB_BIDIR); |
| 224 | break; |
| 225 | case 4: |
| 226 | syscon1 = 1; |
| 227 | omap2_usb_devconf_set(0, USB_BIDIR); |
| 228 | break; |
| 229 | case 6: |
| 230 | syscon1 = 3; |
| 231 | omap_cfg_reg(J19_24XX_USB0_VP); |
| 232 | omap_cfg_reg(K20_24XX_USB0_VM); |
| 233 | omap2_usb_devconf_set(0, USB_UNIDIR); |
| 234 | break; |
| 235 | default: |
| 236 | printk(KERN_ERR "illegal usb%d %d-wire transceiver\n", |
| 237 | 0, nwires); |
| 238 | } |
| 239 | |
| 240 | return syscon1 << 16; |
| 241 | } |
| 242 | |
| 243 | static u32 __init omap2_usb1_init(unsigned nwires) |
| 244 | { |
| 245 | u32 syscon1 = 0; |
| 246 | |
| 247 | omap2_usb_devconf_clear(1, USB_BIDIR_TLL); |
| 248 | |
| 249 | if (nwires == 0) |
| 250 | return 0; |
| 251 | |
| 252 | /* NOTE: board-specific code must set up pin muxing for usb1, |
| 253 | * since each signal could come out on either of two balls. |
| 254 | */ |
| 255 | |
| 256 | switch (nwires) { |
| 257 | case 2: |
| 258 | /* NOTE: board-specific code must override this setting if |
| 259 | * this TLL link is not using DP/DM |
| 260 | */ |
| 261 | syscon1 = 1; |
| 262 | omap2_usb_devconf_set(1, USB_BIDIR_TLL); |
| 263 | break; |
| 264 | case 3: |
| 265 | syscon1 = 2; |
| 266 | omap2_usb_devconf_set(1, USB_BIDIR); |
| 267 | break; |
| 268 | case 4: |
| 269 | syscon1 = 1; |
| 270 | omap2_usb_devconf_set(1, USB_BIDIR); |
| 271 | break; |
| 272 | case 6: |
| 273 | default: |
| 274 | printk(KERN_ERR "illegal usb%d %d-wire transceiver\n", |
| 275 | 1, nwires); |
| 276 | } |
| 277 | |
| 278 | return syscon1 << 20; |
| 279 | } |
| 280 | |
| 281 | static u32 __init omap2_usb2_init(unsigned nwires, unsigned alt_pingroup) |
| 282 | { |
| 283 | u32 syscon1 = 0; |
| 284 | |
| 285 | omap2_usb2_disable_5pinbitll(); |
| 286 | alt_pingroup = 0; |
| 287 | |
| 288 | /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */ |
| 289 | if (alt_pingroup || nwires == 0) |
| 290 | return 0; |
| 291 | |
| 292 | omap_cfg_reg(Y11_24XX_USB2_DAT); |
| 293 | omap_cfg_reg(AA10_24XX_USB2_SE0); |
| 294 | if (nwires > 2) |
| 295 | omap_cfg_reg(AA12_24XX_USB2_TXEN); |
| 296 | if (nwires > 3) |
| 297 | omap_cfg_reg(AA6_24XX_USB2_RCV); |
| 298 | |
| 299 | switch (nwires) { |
| 300 | case 2: |
| 301 | /* NOTE: board-specific code must override this setting if |
| 302 | * this TLL link is not using DP/DM |
| 303 | */ |
| 304 | syscon1 = 1; |
| 305 | omap2_usb_devconf_set(2, USB_BIDIR_TLL); |
| 306 | break; |
| 307 | case 3: |
| 308 | syscon1 = 2; |
| 309 | omap2_usb_devconf_set(2, USB_BIDIR); |
| 310 | break; |
| 311 | case 4: |
| 312 | syscon1 = 1; |
| 313 | omap2_usb_devconf_set(2, USB_BIDIR); |
| 314 | break; |
| 315 | case 5: |
| 316 | omap_cfg_reg(AA4_24XX_USB2_TLLSE0); |
| 317 | /* NOTE: board-specific code must override this setting if |
| 318 | * this TLL link is not using DP/DM. Something must also |
| 319 | * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED} |
| 320 | */ |
| 321 | syscon1 = 3; |
| 322 | omap2_usb2_enable_5pinunitll(); |
| 323 | break; |
| 324 | case 6: |
| 325 | default: |
| 326 | printk(KERN_ERR "illegal usb%d %d-wire transceiver\n", |
| 327 | 2, nwires); |
| 328 | } |
| 329 | |
| 330 | return syscon1 << 24; |
| 331 | } |
| 332 | |
| 333 | void __init omap2_usbfs_init(struct omap_usb_config *pdata) |
| 334 | { |
Tony Lindgren | 9809383 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 335 | struct clk *ick; |
| 336 | |
Tony Lindgren | b5e8905 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 337 | if (!cpu_is_omap24xx()) |
| 338 | return; |
| 339 | |
Tony Lindgren | 9809383 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 340 | ick = clk_get(NULL, "usb_l4_ick"); |
| 341 | if (IS_ERR(ick)) |
| 342 | return; |
| 343 | |
| 344 | clk_enable(ick); |
Tony Lindgren | b5e8905 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 345 | pdata->usb0_init = omap2_usb0_init; |
| 346 | pdata->usb1_init = omap2_usb1_init; |
| 347 | pdata->usb2_init = omap2_usb2_init; |
| 348 | udc_device_init(pdata); |
| 349 | ohci_device_init(pdata); |
| 350 | otg_device_init(pdata); |
| 351 | omap_otg_init(pdata); |
Tony Lindgren | 9809383 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 352 | clk_disable(ick); |
| 353 | clk_put(ick); |
Tony Lindgren | b5e8905 | 2010-07-05 16:31:29 +0300 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | #endif |