Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 1 | /* |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 2 | * driver for NXP USB Host devices |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 3 | * |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 4 | * Currently supported OHCI host devices: |
| 5 | * - Philips PNX4008 |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 6 | * - NXP LPC32xx |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 7 | * |
| 8 | * Authors: Dmitry Chigirev <source@mvista.com> |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 9 | * Vitaly Wool <vitalywool@gmail.com> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 10 | * |
| 11 | * register initialization is based on code examples provided by Philips |
| 12 | * Copyright (c) 2005 Koninklijke Philips Electronics N.V. |
| 13 | * |
| 14 | * NOTE: This driver does not have suspend/resume functionality |
| 15 | * This driver is intended for engineering development purposes only |
| 16 | * |
| 17 | * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under |
| 18 | * the terms of the GNU General Public License version 2. This program |
| 19 | * is licensed "as is" without any warranty of any kind, whether express |
| 20 | * or implied. |
| 21 | */ |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/i2c.h> |
Roland Stigge | 2265efe | 2012-04-29 16:47:03 +0200 | [diff] [blame] | 25 | #include <linux/of.h> |
Roland Stigge | 73108aa | 2012-04-29 16:47:06 +0200 | [diff] [blame] | 26 | #include <linux/usb/isp1301.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/hardware.h> |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 29 | #include <asm/mach-types.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 30 | #include <asm/io.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 31 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/platform.h> |
| 33 | #include <mach/irqs.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 34 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 35 | #define USB_CONFIG_BASE 0x31020000 |
| 36 | #define PWRMAN_BASE 0x40004000 |
| 37 | |
| 38 | #define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 39 | |
| 40 | /* USB_CTRL bit defines */ |
| 41 | #define USB_SLAVE_HCLK_EN (1 << 24) |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 42 | #define USB_DEV_NEED_CLK_EN (1 << 22) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 43 | #define USB_HOST_NEED_CLK_EN (1 << 21) |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 44 | #define PAD_CONTROL_LAST_DRIVEN (1 << 19) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 45 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 46 | #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 47 | |
| 48 | /* USB_OTG_STAT_CONTROL bit defines */ |
| 49 | #define TRANSPARENT_I2C_EN (1 << 7) |
| 50 | #define HOST_EN (1 << 0) |
| 51 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 52 | /* On LPC32xx, those are undefined */ |
| 53 | #ifndef start_int_set_falling_edge |
| 54 | #define start_int_set_falling_edge(irq) |
| 55 | #define start_int_set_rising_edge(irq) |
| 56 | #define start_int_ack(irq) |
| 57 | #define start_int_mask(irq) |
| 58 | #define start_int_umask(irq) |
| 59 | #endif |
| 60 | |
Jean Delvare | 09ce497 | 2009-10-01 19:03:13 +0200 | [diff] [blame] | 61 | static struct i2c_client *isp1301_i2c_client; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 62 | |
| 63 | extern int usb_disabled(void); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 64 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 65 | static struct clk *usb_pll_clk; |
| 66 | static struct clk *usb_dev_clk; |
| 67 | static struct clk *usb_otg_clk; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 68 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 69 | static void isp1301_configure_pnx4008(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 70 | { |
| 71 | /* PNX4008 only supports DAT_SE0 USB mode */ |
| 72 | /* PNX4008 R2A requires setting the MAX603 to output 3.6V */ |
| 73 | /* Power up externel charge-pump */ |
| 74 | |
Roland Stigge | a6a3600 | 2012-03-12 22:54:52 +0100 | [diff] [blame] | 75 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 76 | ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0 | MC1_SPEED_REG); |
| 77 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 78 | ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, |
| 79 | ~(MC1_DAT_SE0 | MC1_SPEED_REG)); |
| 80 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 81 | ISP1301_I2C_MODE_CONTROL_2, |
| 82 | MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL); |
| 83 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 84 | ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR, |
| 85 | ~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL)); |
| 86 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 87 | ISP1301_I2C_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN); |
| 88 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 89 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, |
| 90 | ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); |
| 91 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 92 | ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, 0xFF); |
| 93 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 94 | ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR, |
| 95 | 0xFF); |
| 96 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 97 | ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, |
| 98 | 0xFF); |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 99 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 100 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 101 | static void isp1301_configure_lpc32xx(void) |
| 102 | { |
| 103 | /* LPC32XX only supports DAT_SE0 USB mode */ |
| 104 | /* This sequence is important */ |
| 105 | |
| 106 | /* Disable transparent UART mode first */ |
| 107 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 108 | (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 109 | MC1_UART_EN); |
| 110 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 111 | (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 112 | ~MC1_SPEED_REG); |
| 113 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 114 | ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG); |
| 115 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 116 | (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 117 | ~0); |
| 118 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 119 | ISP1301_I2C_MODE_CONTROL_2, |
| 120 | (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL)); |
| 121 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 122 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0); |
| 123 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 124 | ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0); |
| 125 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 126 | ISP1301_I2C_OTG_CONTROL_1, |
| 127 | (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); |
| 128 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 129 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 130 | (OTG1_DM_PULLUP | OTG1_DP_PULLUP)); |
| 131 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 132 | ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
| 133 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 134 | ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR, |
| 135 | ~0); |
| 136 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 137 | ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
| 138 | |
| 139 | /* Enable usb_need_clk clock after transceiver is initialized */ |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 140 | __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL); |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 141 | |
| 142 | printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n", |
| 143 | i2c_smbus_read_word_data(isp1301_i2c_client, 0x00)); |
| 144 | printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n", |
| 145 | i2c_smbus_read_word_data(isp1301_i2c_client, 0x02)); |
| 146 | printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n", |
| 147 | i2c_smbus_read_word_data(isp1301_i2c_client, 0x14)); |
| 148 | } |
| 149 | |
| 150 | static void isp1301_configure(void) |
| 151 | { |
| 152 | if (machine_is_pnx4008()) |
| 153 | isp1301_configure_pnx4008(); |
| 154 | else |
| 155 | isp1301_configure_lpc32xx(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static inline void isp1301_vbus_on(void) |
| 159 | { |
Roland Stigge | a6a3600 | 2012-03-12 22:54:52 +0100 | [diff] [blame] | 160 | i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1, |
| 161 | OTG1_VBUS_DRV); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static inline void isp1301_vbus_off(void) |
| 165 | { |
Roland Stigge | a6a3600 | 2012-03-12 22:54:52 +0100 | [diff] [blame] | 166 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 167 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, |
| 168 | OTG1_VBUS_DRV); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 169 | } |
| 170 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 171 | static void nxp_start_hc(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 172 | { |
| 173 | unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; |
| 174 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
| 175 | isp1301_vbus_on(); |
| 176 | } |
| 177 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 178 | static void nxp_stop_hc(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 179 | { |
| 180 | unsigned long tmp; |
| 181 | isp1301_vbus_off(); |
| 182 | tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN; |
| 183 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
| 184 | } |
| 185 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 186 | static int __devinit ohci_nxp_start(struct usb_hcd *hcd) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 187 | { |
| 188 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 189 | int ret; |
| 190 | |
| 191 | if ((ret = ohci_init(ohci)) < 0) |
| 192 | return ret; |
| 193 | |
| 194 | if ((ret = ohci_run(ohci)) < 0) { |
| 195 | dev_err(hcd->self.controller, "can't start\n"); |
| 196 | ohci_stop(hcd); |
| 197 | return ret; |
| 198 | } |
| 199 | return 0; |
| 200 | } |
| 201 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 202 | static const struct hc_driver ohci_nxp_hc_driver = { |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 203 | .description = hcd_name, |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 204 | .product_desc = "nxp OHCI", |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 205 | |
| 206 | /* |
| 207 | * generic hardware linkage |
| 208 | */ |
| 209 | .irq = ohci_irq, |
| 210 | .flags = HCD_USB11 | HCD_MEMORY, |
| 211 | |
| 212 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 213 | /* |
| 214 | * basic lifecycle operations |
| 215 | */ |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 216 | .start = ohci_nxp_start, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 217 | .stop = ohci_stop, |
David Brownell | 8442ae0 | 2006-10-02 07:20:10 -0700 | [diff] [blame] | 218 | .shutdown = ohci_shutdown, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * managing i/o requests and associated device resources |
| 222 | */ |
| 223 | .urb_enqueue = ohci_urb_enqueue, |
| 224 | .urb_dequeue = ohci_urb_dequeue, |
| 225 | .endpoint_disable = ohci_endpoint_disable, |
| 226 | |
| 227 | /* |
| 228 | * scheduling support |
| 229 | */ |
| 230 | .get_frame_number = ohci_get_frame, |
| 231 | |
| 232 | /* |
| 233 | * root hub support |
| 234 | */ |
| 235 | .hub_status_data = ohci_hub_status_data, |
| 236 | .hub_control = ohci_hub_control, |
David Brownell | 8442ae0 | 2006-10-02 07:20:10 -0700 | [diff] [blame] | 237 | #ifdef CONFIG_PM |
| 238 | .bus_suspend = ohci_bus_suspend, |
| 239 | .bus_resume = ohci_bus_resume, |
| 240 | #endif |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 241 | .start_port_reset = ohci_start_port_reset, |
| 242 | }; |
| 243 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 244 | static void nxp_set_usb_bits(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 245 | { |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 246 | if (machine_is_pnx4008()) { |
| 247 | start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N); |
| 248 | start_int_ack(SE_USB_OTG_ATX_INT_N); |
| 249 | start_int_umask(SE_USB_OTG_ATX_INT_N); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 250 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 251 | start_int_set_rising_edge(SE_USB_OTG_TIMER_INT); |
| 252 | start_int_ack(SE_USB_OTG_TIMER_INT); |
| 253 | start_int_umask(SE_USB_OTG_TIMER_INT); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 254 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 255 | start_int_set_rising_edge(SE_USB_I2C_INT); |
| 256 | start_int_ack(SE_USB_I2C_INT); |
| 257 | start_int_umask(SE_USB_I2C_INT); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 258 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 259 | start_int_set_rising_edge(SE_USB_INT); |
| 260 | start_int_ack(SE_USB_INT); |
| 261 | start_int_umask(SE_USB_INT); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 262 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 263 | start_int_set_rising_edge(SE_USB_NEED_CLK_INT); |
| 264 | start_int_ack(SE_USB_NEED_CLK_INT); |
| 265 | start_int_umask(SE_USB_NEED_CLK_INT); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 266 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 267 | start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT); |
| 268 | start_int_ack(SE_USB_AHB_NEED_CLK_INT); |
| 269 | start_int_umask(SE_USB_AHB_NEED_CLK_INT); |
| 270 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 271 | } |
| 272 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 273 | static void nxp_unset_usb_bits(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 274 | { |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 275 | if (machine_is_pnx4008()) { |
| 276 | start_int_mask(SE_USB_OTG_ATX_INT_N); |
| 277 | start_int_mask(SE_USB_OTG_TIMER_INT); |
| 278 | start_int_mask(SE_USB_I2C_INT); |
| 279 | start_int_mask(SE_USB_INT); |
| 280 | start_int_mask(SE_USB_NEED_CLK_INT); |
| 281 | start_int_mask(SE_USB_AHB_NEED_CLK_INT); |
| 282 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 283 | } |
| 284 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 285 | static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 286 | { |
| 287 | struct usb_hcd *hcd = 0; |
| 288 | struct ohci_hcd *ohci; |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 289 | const struct hc_driver *driver = &ohci_nxp_hc_driver; |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 290 | struct resource *res; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 291 | int ret = 0, irq; |
Roland Stigge | 73108aa | 2012-04-29 16:47:06 +0200 | [diff] [blame] | 292 | struct device_node *isp1301_node; |
| 293 | |
| 294 | if (pdev->dev.of_node) { |
| 295 | isp1301_node = of_parse_phandle(pdev->dev.of_node, |
| 296 | "transceiver", 0); |
| 297 | } else { |
| 298 | isp1301_node = NULL; |
| 299 | } |
| 300 | |
| 301 | isp1301_i2c_client = isp1301_get_client(isp1301_node); |
| 302 | if (!isp1301_i2c_client) { |
| 303 | ret = -EPROBE_DEFER; |
| 304 | goto out; |
| 305 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 306 | |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 307 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 308 | pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; |
| 309 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 310 | dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 311 | if (usb_disabled()) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 312 | dev_err(&pdev->dev, "USB is disabled\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 313 | ret = -ENODEV; |
| 314 | goto out; |
| 315 | } |
| 316 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 317 | /* Enable AHB slave USB clock, needed for further USB clock control */ |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 318 | __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 319 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 320 | /* Enable USB PLL */ |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 321 | usb_pll_clk = clk_get(&pdev->dev, "ck_pll5"); |
| 322 | if (IS_ERR(usb_pll_clk)) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 323 | dev_err(&pdev->dev, "failed to acquire USB PLL\n"); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 324 | ret = PTR_ERR(usb_pll_clk); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 325 | goto out1; |
| 326 | } |
| 327 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 328 | ret = clk_enable(usb_pll_clk); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 329 | if (ret < 0) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 330 | dev_err(&pdev->dev, "failed to start USB PLL\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 331 | goto out2; |
| 332 | } |
| 333 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 334 | ret = clk_set_rate(usb_pll_clk, 48000); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 335 | if (ret < 0) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 336 | dev_err(&pdev->dev, "failed to set USB clock rate\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 337 | goto out3; |
| 338 | } |
| 339 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 340 | /* Enable USB device clock */ |
| 341 | usb_dev_clk = clk_get(&pdev->dev, "ck_usbd"); |
| 342 | if (IS_ERR(usb_dev_clk)) { |
| 343 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); |
| 344 | ret = PTR_ERR(usb_dev_clk); |
| 345 | goto out4; |
| 346 | } |
| 347 | |
| 348 | ret = clk_enable(usb_dev_clk); |
| 349 | if (ret < 0) { |
| 350 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); |
| 351 | goto out5; |
| 352 | } |
| 353 | |
| 354 | /* Enable USB otg clocks */ |
| 355 | usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg"); |
| 356 | if (IS_ERR(usb_otg_clk)) { |
| 357 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); |
Julia Lawall | 2ec15a6 | 2012-08-25 21:57:07 +0200 | [diff] [blame^] | 358 | ret = PTR_ERR(usb_otg_clk); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 359 | goto out6; |
| 360 | } |
| 361 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 362 | __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL); |
| 363 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 364 | ret = clk_enable(usb_otg_clk); |
| 365 | if (ret < 0) { |
| 366 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); |
| 367 | goto out7; |
| 368 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 369 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 370 | isp1301_configure(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 371 | |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 372 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 373 | if (!hcd) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 374 | dev_err(&pdev->dev, "Failed to allocate HC buffer\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 375 | ret = -ENOMEM; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 376 | goto out8; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* Set all USB bits in the Start Enable register */ |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 380 | nxp_set_usb_bits(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 381 | |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 382 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 383 | if (!res) { |
| 384 | dev_err(&pdev->dev, "Failed to get MEM resource\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 385 | ret = -ENOMEM; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 386 | goto out8; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 387 | } |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 388 | |
| 389 | hcd->regs = devm_request_and_ioremap(&pdev->dev, res); |
| 390 | if (!hcd->regs) { |
| 391 | dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n"); |
| 392 | ret = -ENOMEM; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 393 | goto out8; |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 394 | } |
| 395 | hcd->rsrc_start = res->start; |
| 396 | hcd->rsrc_len = resource_size(res); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 397 | |
| 398 | irq = platform_get_irq(pdev, 0); |
| 399 | if (irq < 0) { |
| 400 | ret = -ENXIO; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 401 | goto out8; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 402 | } |
| 403 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 404 | nxp_start_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 405 | platform_set_drvdata(pdev, hcd); |
| 406 | ohci = hcd_to_ohci(hcd); |
| 407 | ohci_hcd_init(ohci); |
| 408 | |
| 409 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 410 | ret = usb_add_hcd(hcd, irq, 0); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 411 | if (ret == 0) |
| 412 | return ret; |
| 413 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 414 | nxp_stop_hc(); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 415 | out8: |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 416 | nxp_unset_usb_bits(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 417 | usb_put_hcd(hcd); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 418 | out7: |
| 419 | clk_disable(usb_otg_clk); |
| 420 | out6: |
| 421 | clk_put(usb_otg_clk); |
| 422 | out5: |
| 423 | clk_disable(usb_dev_clk); |
| 424 | out4: |
| 425 | clk_put(usb_dev_clk); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 426 | out3: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 427 | clk_disable(usb_pll_clk); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 428 | out2: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 429 | clk_put(usb_pll_clk); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 430 | out1: |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 431 | isp1301_i2c_client = NULL; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 432 | out: |
| 433 | return ret; |
| 434 | } |
| 435 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 436 | static int usb_hcd_nxp_remove(struct platform_device *pdev) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 437 | { |
| 438 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 439 | |
| 440 | usb_remove_hcd(hcd); |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 441 | nxp_stop_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 442 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 443 | usb_put_hcd(hcd); |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 444 | nxp_unset_usb_bits(); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 445 | clk_disable(usb_pll_clk); |
| 446 | clk_put(usb_pll_clk); |
| 447 | clk_disable(usb_dev_clk); |
| 448 | clk_put(usb_dev_clk); |
Luotao Fu | 8740cc7 | 2010-02-19 15:42:00 +0100 | [diff] [blame] | 449 | i2c_unregister_device(isp1301_i2c_client); |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 450 | isp1301_i2c_client = NULL; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 451 | |
| 452 | platform_set_drvdata(pdev, NULL); |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 457 | /* work with hotplug and coldplug */ |
| 458 | MODULE_ALIAS("platform:usb-ohci"); |
| 459 | |
Roland Stigge | 2265efe | 2012-04-29 16:47:03 +0200 | [diff] [blame] | 460 | #ifdef CONFIG_OF |
| 461 | static const struct of_device_id usb_hcd_nxp_match[] = { |
| 462 | { .compatible = "nxp,ohci-nxp" }, |
| 463 | {}, |
| 464 | }; |
| 465 | MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match); |
| 466 | #endif |
| 467 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 468 | static struct platform_driver usb_hcd_nxp_driver = { |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 469 | .driver = { |
| 470 | .name = "usb-ohci", |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 471 | .owner = THIS_MODULE, |
Roland Stigge | 2265efe | 2012-04-29 16:47:03 +0200 | [diff] [blame] | 472 | .of_match_table = of_match_ptr(usb_hcd_nxp_match), |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 473 | }, |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 474 | .probe = usb_hcd_nxp_probe, |
| 475 | .remove = usb_hcd_nxp_remove, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 476 | }; |
| 477 | |