Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Freescale 83xx USB SOC setup code |
| 3 | * |
| 4 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 5 | * Author: Li Yang |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <linux/stddef.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/prom.h> |
| 20 | #include <sysdev/fsl_soc.h> |
| 21 | |
| 22 | #include "mpc83xx.h" |
| 23 | |
| 24 | |
Kumar Gala | b38308a | 2008-01-28 10:52:15 -0600 | [diff] [blame] | 25 | #ifdef CONFIG_PPC_MPC834x |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 26 | int mpc834x_usb_cfg(void) |
| 27 | { |
| 28 | unsigned long sccr, sicrl, sicrh; |
| 29 | void __iomem *immap; |
| 30 | struct device_node *np = NULL; |
| 31 | int port0_is_dr = 0, port1_is_dr = 0; |
| 32 | const void *prop, *dr_mode; |
| 33 | |
| 34 | immap = ioremap(get_immrbase(), 0x1000); |
| 35 | if (!immap) |
| 36 | return -ENOMEM; |
| 37 | |
| 38 | /* Read registers */ |
| 39 | /* Note: DR and MPH must use the same clock setting in SCCR */ |
| 40 | sccr = in_be32(immap + MPC83XX_SCCR_OFFS) & ~MPC83XX_SCCR_USB_MASK; |
| 41 | sicrl = in_be32(immap + MPC83XX_SICRL_OFFS) & ~MPC834X_SICRL_USB_MASK; |
| 42 | sicrh = in_be32(immap + MPC83XX_SICRH_OFFS) & ~MPC834X_SICRH_USB_UTMI; |
| 43 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 44 | np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr"); |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 45 | if (np) { |
| 46 | sccr |= MPC83XX_SCCR_USB_DRCM_11; /* 1:3 */ |
| 47 | |
| 48 | prop = of_get_property(np, "phy_type", NULL); |
| 49 | if (prop && (!strcmp(prop, "utmi") || |
| 50 | !strcmp(prop, "utmi_wide"))) { |
| 51 | sicrl |= MPC834X_SICRL_USB0 | MPC834X_SICRL_USB1; |
| 52 | sicrh |= MPC834X_SICRH_USB_UTMI; |
| 53 | port1_is_dr = 1; |
| 54 | } else if (prop && !strcmp(prop, "serial")) { |
| 55 | dr_mode = of_get_property(np, "dr_mode", NULL); |
| 56 | if (dr_mode && !strcmp(dr_mode, "otg")) { |
| 57 | sicrl |= MPC834X_SICRL_USB0 | MPC834X_SICRL_USB1; |
| 58 | port1_is_dr = 1; |
| 59 | } else { |
| 60 | sicrl |= MPC834X_SICRL_USB0; |
| 61 | } |
| 62 | } else if (prop && !strcmp(prop, "ulpi")) { |
| 63 | sicrl |= MPC834X_SICRL_USB0; |
| 64 | } else { |
| 65 | printk(KERN_WARNING "834x USB PHY type not supported\n"); |
| 66 | } |
| 67 | port0_is_dr = 1; |
| 68 | of_node_put(np); |
| 69 | } |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 70 | np = of_find_compatible_node(NULL, NULL, "fsl-usb2-mph"); |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 71 | if (np) { |
| 72 | sccr |= MPC83XX_SCCR_USB_MPHCM_11; /* 1:3 */ |
| 73 | |
| 74 | prop = of_get_property(np, "port0", NULL); |
| 75 | if (prop) { |
| 76 | if (port0_is_dr) |
| 77 | printk(KERN_WARNING |
| 78 | "834x USB port0 can't be used by both DR and MPH!\n"); |
jacmet@sunsite.dk | 39db0fd | 2007-09-28 16:21:14 +0200 | [diff] [blame] | 79 | sicrl &= ~MPC834X_SICRL_USB0; |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 80 | } |
| 81 | prop = of_get_property(np, "port1", NULL); |
| 82 | if (prop) { |
| 83 | if (port1_is_dr) |
| 84 | printk(KERN_WARNING |
| 85 | "834x USB port1 can't be used by both DR and MPH!\n"); |
jacmet@sunsite.dk | 39db0fd | 2007-09-28 16:21:14 +0200 | [diff] [blame] | 86 | sicrl &= ~MPC834X_SICRL_USB1; |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 87 | } |
| 88 | of_node_put(np); |
| 89 | } |
| 90 | |
| 91 | /* Write back */ |
| 92 | out_be32(immap + MPC83XX_SCCR_OFFS, sccr); |
| 93 | out_be32(immap + MPC83XX_SICRL_OFFS, sicrl); |
| 94 | out_be32(immap + MPC83XX_SICRH_OFFS, sicrh); |
| 95 | |
| 96 | iounmap(immap); |
| 97 | return 0; |
| 98 | } |
Kumar Gala | b38308a | 2008-01-28 10:52:15 -0600 | [diff] [blame] | 99 | #endif /* CONFIG_PPC_MPC834x */ |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 100 | |
| 101 | #ifdef CONFIG_PPC_MPC831x |
| 102 | int mpc831x_usb_cfg(void) |
| 103 | { |
| 104 | u32 temp; |
| 105 | void __iomem *immap, *usb_regs; |
| 106 | struct device_node *np = NULL; |
Kim Phillips | b74a7e5 | 2008-01-30 12:46:19 -0600 | [diff] [blame] | 107 | struct device_node *immr_node = NULL; |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 108 | const void *prop; |
| 109 | struct resource res; |
| 110 | int ret = 0; |
| 111 | #ifdef CONFIG_USB_OTG |
| 112 | const void *dr_mode; |
| 113 | #endif |
| 114 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 115 | np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr"); |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 116 | if (!np) |
| 117 | return -ENODEV; |
| 118 | prop = of_get_property(np, "phy_type", NULL); |
| 119 | |
| 120 | /* Map IMMR space for pin and clock settings */ |
| 121 | immap = ioremap(get_immrbase(), 0x1000); |
| 122 | if (!immap) { |
| 123 | of_node_put(np); |
| 124 | return -ENOMEM; |
| 125 | } |
| 126 | |
| 127 | /* Configure clock */ |
Kim Phillips | b74a7e5 | 2008-01-30 12:46:19 -0600 | [diff] [blame] | 128 | immr_node = of_get_parent(np); |
| 129 | if (immr_node && of_device_is_compatible(immr_node, "fsl,mpc8315-immr")) |
| 130 | clrsetbits_be32(immap + MPC83XX_SCCR_OFFS, |
| 131 | MPC8315_SCCR_USB_MASK, |
Anton Vorontsov | 1a9ebc0 | 2008-04-09 17:59:25 +0400 | [diff] [blame] | 132 | MPC8315_SCCR_USB_DRCM_01); |
Kim Phillips | b74a7e5 | 2008-01-30 12:46:19 -0600 | [diff] [blame] | 133 | else |
| 134 | clrsetbits_be32(immap + MPC83XX_SCCR_OFFS, |
| 135 | MPC83XX_SCCR_USB_MASK, |
| 136 | MPC83XX_SCCR_USB_DRCM_11); |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 137 | |
| 138 | /* Configure pin mux for ULPI. There is no pin mux for UTMI */ |
Cyrill Gorcunov | 7ac3341 | 2007-11-15 21:47:06 +0300 | [diff] [blame] | 139 | if (prop && !strcmp(prop, "ulpi")) { |
Anton Vorontsov | c0a2015 | 2008-07-08 21:36:32 +0400 | [diff] [blame] | 140 | if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr")) { |
| 141 | clrsetbits_be32(immap + MPC83XX_SICRL_OFFS, |
| 142 | MPC8315_SICRL_USB_MASK, |
| 143 | MPC8315_SICRL_USB_ULPI); |
| 144 | clrsetbits_be32(immap + MPC83XX_SICRH_OFFS, |
| 145 | MPC8315_SICRH_USB_MASK, |
| 146 | MPC8315_SICRH_USB_ULPI); |
| 147 | } else { |
| 148 | clrsetbits_be32(immap + MPC83XX_SICRL_OFFS, |
| 149 | MPC831X_SICRL_USB_MASK, |
| 150 | MPC831X_SICRL_USB_ULPI); |
| 151 | clrsetbits_be32(immap + MPC83XX_SICRH_OFFS, |
| 152 | MPC831X_SICRH_USB_MASK, |
| 153 | MPC831X_SICRH_USB_ULPI); |
| 154 | } |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | iounmap(immap); |
| 158 | |
Kim Phillips | b74a7e5 | 2008-01-30 12:46:19 -0600 | [diff] [blame] | 159 | if (immr_node) |
| 160 | of_node_put(immr_node); |
| 161 | |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 162 | /* Map USB SOC space */ |
| 163 | ret = of_address_to_resource(np, 0, &res); |
| 164 | if (ret) { |
| 165 | of_node_put(np); |
| 166 | return ret; |
| 167 | } |
| 168 | usb_regs = ioremap(res.start, res.end - res.start + 1); |
| 169 | |
| 170 | /* Using on-chip PHY */ |
Cyrill Gorcunov | 7ac3341 | 2007-11-15 21:47:06 +0300 | [diff] [blame] | 171 | if (prop && (!strcmp(prop, "utmi_wide") || |
| 172 | !strcmp(prop, "utmi"))) { |
Anton Vorontsov | 1a9ebc0 | 2008-04-09 17:59:25 +0400 | [diff] [blame] | 173 | u32 refsel; |
| 174 | |
| 175 | if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr")) |
| 176 | refsel = CONTROL_REFSEL_24MHZ; |
| 177 | else |
| 178 | refsel = CONTROL_REFSEL_48MHZ; |
| 179 | /* Set UTMI_PHY_EN and REFSEL */ |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 180 | out_be32(usb_regs + FSL_USB2_CONTROL_OFFS, |
Anton Vorontsov | 1a9ebc0 | 2008-04-09 17:59:25 +0400 | [diff] [blame] | 181 | CONTROL_UTMI_PHY_EN | refsel); |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 182 | /* Using external UPLI PHY */ |
Cyrill Gorcunov | 7ac3341 | 2007-11-15 21:47:06 +0300 | [diff] [blame] | 183 | } else if (prop && !strcmp(prop, "ulpi")) { |
Li Yang | e5a94af | 2007-07-03 17:43:16 +0800 | [diff] [blame] | 184 | /* Set PHY_CLK_SEL to ULPI */ |
| 185 | temp = CONTROL_PHY_CLK_SEL_ULPI; |
| 186 | #ifdef CONFIG_USB_OTG |
| 187 | /* Set OTG_PORT */ |
| 188 | dr_mode = of_get_property(np, "dr_mode", NULL); |
| 189 | if (dr_mode && !strcmp(dr_mode, "otg")) |
| 190 | temp |= CONTROL_OTG_PORT; |
| 191 | #endif /* CONFIG_USB_OTG */ |
| 192 | out_be32(usb_regs + FSL_USB2_CONTROL_OFFS, temp); |
| 193 | } else { |
| 194 | printk(KERN_WARNING "831x USB PHY type not supported\n"); |
| 195 | ret = -EINVAL; |
| 196 | } |
| 197 | |
| 198 | iounmap(usb_regs); |
| 199 | of_node_put(np); |
| 200 | return ret; |
| 201 | } |
| 202 | #endif /* CONFIG_PPC_MPC831x */ |
Li Yang | e10241d | 2008-01-08 15:18:45 +0800 | [diff] [blame] | 203 | |
| 204 | #ifdef CONFIG_PPC_MPC837x |
| 205 | int mpc837x_usb_cfg(void) |
| 206 | { |
| 207 | void __iomem *immap; |
| 208 | struct device_node *np = NULL; |
| 209 | const void *prop; |
| 210 | int ret = 0; |
| 211 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 212 | np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr"); |
Li Yang | e10241d | 2008-01-08 15:18:45 +0800 | [diff] [blame] | 213 | if (!np) |
| 214 | return -ENODEV; |
| 215 | prop = of_get_property(np, "phy_type", NULL); |
| 216 | |
| 217 | if (!prop || (strcmp(prop, "ulpi") && strcmp(prop, "serial"))) { |
| 218 | printk(KERN_WARNING "837x USB PHY type not supported\n"); |
| 219 | of_node_put(np); |
| 220 | return -EINVAL; |
| 221 | } |
| 222 | |
| 223 | /* Map IMMR space for pin and clock settings */ |
| 224 | immap = ioremap(get_immrbase(), 0x1000); |
| 225 | if (!immap) { |
| 226 | of_node_put(np); |
| 227 | return -ENOMEM; |
| 228 | } |
| 229 | |
| 230 | /* Configure clock */ |
| 231 | clrsetbits_be32(immap + MPC83XX_SCCR_OFFS, MPC837X_SCCR_USB_DRCM_11, |
| 232 | MPC837X_SCCR_USB_DRCM_11); |
| 233 | |
| 234 | /* Configure pin mux for ULPI/serial */ |
| 235 | clrsetbits_be32(immap + MPC83XX_SICRL_OFFS, MPC837X_SICRL_USB_MASK, |
| 236 | MPC837X_SICRL_USB_ULPI); |
| 237 | |
| 238 | iounmap(immap); |
| 239 | of_node_put(np); |
| 240 | return ret; |
| 241 | } |
| 242 | #endif /* CONFIG_PPC_MPC837x */ |