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 |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 6 | * |
| 7 | * Authors: Dmitry Chigirev <source@mvista.com> |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 8 | * Vitaly Wool <vitalywool@gmail.com> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 9 | * |
| 10 | * register initialization is based on code examples provided by Philips |
| 11 | * Copyright (c) 2005 Koninklijke Philips Electronics N.V. |
| 12 | * |
| 13 | * NOTE: This driver does not have suspend/resume functionality |
| 14 | * This driver is intended for engineering development purposes only |
| 15 | * |
| 16 | * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under |
| 17 | * the terms of the GNU General Public License version 2. This program |
| 18 | * is licensed "as is" without any warranty of any kind, whether express |
| 19 | * or implied. |
| 20 | */ |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/i2c.h> |
| 24 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/hardware.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 26 | #include <asm/io.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/platform.h> |
| 29 | #include <mach/irqs.h> |
Russell King | db3f728 | 2011-07-26 10:58:41 +0100 | [diff] [blame] | 30 | #include <asm/gpio.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 31 | |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 32 | #define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 33 | |
| 34 | /* USB_CTRL bit defines */ |
| 35 | #define USB_SLAVE_HCLK_EN (1 << 24) |
| 36 | #define USB_HOST_NEED_CLK_EN (1 << 21) |
| 37 | |
| 38 | #define USB_OTG_CLK_CTRL IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0xFF4) |
| 39 | #define USB_OTG_CLK_STAT IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0xFF8) |
| 40 | |
| 41 | /* USB_OTG_CLK_CTRL bit defines */ |
| 42 | #define AHB_M_CLOCK_ON (1 << 4) |
| 43 | #define OTG_CLOCK_ON (1 << 3) |
| 44 | #define I2C_CLOCK_ON (1 << 2) |
| 45 | #define DEV_CLOCK_ON (1 << 1) |
| 46 | #define HOST_CLOCK_ON (1 << 0) |
| 47 | |
| 48 | #define USB_OTG_STAT_CONTROL IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0x110) |
| 49 | |
| 50 | /* USB_OTG_STAT_CONTROL bit defines */ |
| 51 | #define TRANSPARENT_I2C_EN (1 << 7) |
| 52 | #define HOST_EN (1 << 0) |
| 53 | |
| 54 | /* ISP1301 USB transceiver I2C registers */ |
| 55 | #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */ |
| 56 | |
| 57 | #define MC1_SPEED_REG (1 << 0) |
| 58 | #define MC1_SUSPEND_REG (1 << 1) |
| 59 | #define MC1_DAT_SE0 (1 << 2) |
| 60 | #define MC1_TRANSPARENT (1 << 3) |
| 61 | #define MC1_BDIS_ACON_EN (1 << 4) |
| 62 | #define MC1_OE_INT_EN (1 << 5) |
| 63 | #define MC1_UART_EN (1 << 6) |
| 64 | #define MC1_MASK 0x7f |
| 65 | |
| 66 | #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */ |
| 67 | |
| 68 | #define MC2_GLOBAL_PWR_DN (1 << 0) |
| 69 | #define MC2_SPD_SUSP_CTRL (1 << 1) |
| 70 | #define MC2_BI_DI (1 << 2) |
| 71 | #define MC2_TRANSP_BDIR0 (1 << 3) |
| 72 | #define MC2_TRANSP_BDIR1 (1 << 4) |
| 73 | #define MC2_AUDIO_EN (1 << 5) |
| 74 | #define MC2_PSW_EN (1 << 6) |
| 75 | #define MC2_EN2V7 (1 << 7) |
| 76 | |
| 77 | #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */ |
| 78 | # define OTG1_DP_PULLUP (1 << 0) |
| 79 | # define OTG1_DM_PULLUP (1 << 1) |
| 80 | # define OTG1_DP_PULLDOWN (1 << 2) |
| 81 | # define OTG1_DM_PULLDOWN (1 << 3) |
| 82 | # define OTG1_ID_PULLDOWN (1 << 4) |
| 83 | # define OTG1_VBUS_DRV (1 << 5) |
| 84 | # define OTG1_VBUS_DISCHRG (1 << 6) |
| 85 | # define OTG1_VBUS_CHRG (1 << 7) |
| 86 | #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */ |
| 87 | # define OTG_B_SESS_END (1 << 6) |
| 88 | # define OTG_B_SESS_VLD (1 << 7) |
| 89 | |
| 90 | #define ISP1301_I2C_ADDR 0x2C |
| 91 | |
| 92 | #define ISP1301_I2C_MODE_CONTROL_1 0x4 |
| 93 | #define ISP1301_I2C_MODE_CONTROL_2 0x12 |
| 94 | #define ISP1301_I2C_OTG_CONTROL_1 0x6 |
| 95 | #define ISP1301_I2C_OTG_CONTROL_2 0x10 |
| 96 | #define ISP1301_I2C_INTERRUPT_SOURCE 0x8 |
| 97 | #define ISP1301_I2C_INTERRUPT_LATCH 0xA |
| 98 | #define ISP1301_I2C_INTERRUPT_FALLING 0xC |
| 99 | #define ISP1301_I2C_INTERRUPT_RISING 0xE |
| 100 | #define ISP1301_I2C_REG_CLEAR_ADDR 1 |
| 101 | |
Jean Delvare | 09ce497 | 2009-10-01 19:03:13 +0200 | [diff] [blame] | 102 | static struct i2c_driver isp1301_driver; |
| 103 | static struct i2c_client *isp1301_i2c_client; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 104 | |
| 105 | extern int usb_disabled(void); |
| 106 | extern int ocpi_enable(void); |
| 107 | |
| 108 | static struct clk *usb_clk; |
| 109 | |
Jean Delvare | 2cdddeb | 2008-01-27 18:14:47 +0100 | [diff] [blame] | 110 | static const unsigned short normal_i2c[] = |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 111 | { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END }; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 112 | |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 113 | static int isp1301_probe(struct i2c_client *client, |
| 114 | const struct i2c_device_id *id) |
| 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static int isp1301_remove(struct i2c_client *client) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
| 123 | |
Jean Delvare | 09ce497 | 2009-10-01 19:03:13 +0200 | [diff] [blame] | 124 | static const struct i2c_device_id isp1301_id[] = { |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 125 | { "isp1301_nxp", 0 }, |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 126 | { } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 127 | }; |
| 128 | |
Jean Delvare | 09ce497 | 2009-10-01 19:03:13 +0200 | [diff] [blame] | 129 | static struct i2c_driver isp1301_driver = { |
Jean Delvare | 64b3d6d | 2008-06-18 14:46:27 +0200 | [diff] [blame] | 130 | .driver = { |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 131 | .name = "isp1301_nxp", |
Jean Delvare | 64b3d6d | 2008-06-18 14:46:27 +0200 | [diff] [blame] | 132 | }, |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 133 | .probe = isp1301_probe, |
| 134 | .remove = isp1301_remove, |
| 135 | .id_table = isp1301_id, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 136 | }; |
| 137 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 138 | static void i2c_write(u8 buf, u8 subaddr) |
| 139 | { |
| 140 | char tmpbuf[2]; |
| 141 | |
| 142 | tmpbuf[0] = subaddr; /*register number */ |
| 143 | tmpbuf[1] = buf; /*register data */ |
| 144 | i2c_master_send(isp1301_i2c_client, &tmpbuf[0], 2); |
| 145 | } |
| 146 | |
| 147 | static void isp1301_configure(void) |
| 148 | { |
| 149 | /* PNX4008 only supports DAT_SE0 USB mode */ |
| 150 | /* PNX4008 R2A requires setting the MAX603 to output 3.6V */ |
| 151 | /* Power up externel charge-pump */ |
| 152 | |
| 153 | i2c_write(MC1_DAT_SE0 | MC1_SPEED_REG, ISP1301_I2C_MODE_CONTROL_1); |
| 154 | i2c_write(~(MC1_DAT_SE0 | MC1_SPEED_REG), |
| 155 | ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR); |
| 156 | i2c_write(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL, |
| 157 | ISP1301_I2C_MODE_CONTROL_2); |
| 158 | i2c_write(~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL), |
| 159 | ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR); |
| 160 | i2c_write(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN, |
| 161 | ISP1301_I2C_OTG_CONTROL_1); |
| 162 | i2c_write(~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN), |
| 163 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR); |
| 164 | i2c_write(0xFF, |
| 165 | ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR); |
| 166 | i2c_write(0xFF, |
| 167 | ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR); |
| 168 | i2c_write(0xFF, |
| 169 | ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR); |
| 170 | |
| 171 | } |
| 172 | |
| 173 | static inline void isp1301_vbus_on(void) |
| 174 | { |
| 175 | i2c_write(OTG1_VBUS_DRV, ISP1301_I2C_OTG_CONTROL_1); |
| 176 | } |
| 177 | |
| 178 | static inline void isp1301_vbus_off(void) |
| 179 | { |
| 180 | i2c_write(OTG1_VBUS_DRV, |
| 181 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR); |
| 182 | } |
| 183 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 184 | static void nxp_start_hc(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 185 | { |
| 186 | unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; |
| 187 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
| 188 | isp1301_vbus_on(); |
| 189 | } |
| 190 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 191 | static void nxp_stop_hc(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 192 | { |
| 193 | unsigned long tmp; |
| 194 | isp1301_vbus_off(); |
| 195 | tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN; |
| 196 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
| 197 | } |
| 198 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 199 | static int __devinit ohci_nxp_start(struct usb_hcd *hcd) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 200 | { |
| 201 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 202 | int ret; |
| 203 | |
| 204 | if ((ret = ohci_init(ohci)) < 0) |
| 205 | return ret; |
| 206 | |
| 207 | if ((ret = ohci_run(ohci)) < 0) { |
| 208 | dev_err(hcd->self.controller, "can't start\n"); |
| 209 | ohci_stop(hcd); |
| 210 | return ret; |
| 211 | } |
| 212 | return 0; |
| 213 | } |
| 214 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 215 | static const struct hc_driver ohci_nxp_hc_driver = { |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 216 | .description = hcd_name, |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 217 | .product_desc = "nxp OHCI", |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 218 | |
| 219 | /* |
| 220 | * generic hardware linkage |
| 221 | */ |
| 222 | .irq = ohci_irq, |
| 223 | .flags = HCD_USB11 | HCD_MEMORY, |
| 224 | |
| 225 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 226 | /* |
| 227 | * basic lifecycle operations |
| 228 | */ |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 229 | .start = ohci_nxp_start, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 230 | .stop = ohci_stop, |
David Brownell | 8442ae0 | 2006-10-02 07:20:10 -0700 | [diff] [blame] | 231 | .shutdown = ohci_shutdown, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * managing i/o requests and associated device resources |
| 235 | */ |
| 236 | .urb_enqueue = ohci_urb_enqueue, |
| 237 | .urb_dequeue = ohci_urb_dequeue, |
| 238 | .endpoint_disable = ohci_endpoint_disable, |
| 239 | |
| 240 | /* |
| 241 | * scheduling support |
| 242 | */ |
| 243 | .get_frame_number = ohci_get_frame, |
| 244 | |
| 245 | /* |
| 246 | * root hub support |
| 247 | */ |
| 248 | .hub_status_data = ohci_hub_status_data, |
| 249 | .hub_control = ohci_hub_control, |
David Brownell | 8442ae0 | 2006-10-02 07:20:10 -0700 | [diff] [blame] | 250 | #ifdef CONFIG_PM |
| 251 | .bus_suspend = ohci_bus_suspend, |
| 252 | .bus_resume = ohci_bus_resume, |
| 253 | #endif |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 254 | .start_port_reset = ohci_start_port_reset, |
| 255 | }; |
| 256 | |
| 257 | #define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON) |
| 258 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 259 | static void nxp_set_usb_bits(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 260 | { |
| 261 | start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N); |
| 262 | start_int_ack(SE_USB_OTG_ATX_INT_N); |
| 263 | start_int_umask(SE_USB_OTG_ATX_INT_N); |
| 264 | |
| 265 | start_int_set_rising_edge(SE_USB_OTG_TIMER_INT); |
| 266 | start_int_ack(SE_USB_OTG_TIMER_INT); |
| 267 | start_int_umask(SE_USB_OTG_TIMER_INT); |
| 268 | |
| 269 | start_int_set_rising_edge(SE_USB_I2C_INT); |
| 270 | start_int_ack(SE_USB_I2C_INT); |
| 271 | start_int_umask(SE_USB_I2C_INT); |
| 272 | |
| 273 | start_int_set_rising_edge(SE_USB_INT); |
| 274 | start_int_ack(SE_USB_INT); |
| 275 | start_int_umask(SE_USB_INT); |
| 276 | |
| 277 | start_int_set_rising_edge(SE_USB_NEED_CLK_INT); |
| 278 | start_int_ack(SE_USB_NEED_CLK_INT); |
| 279 | start_int_umask(SE_USB_NEED_CLK_INT); |
| 280 | |
| 281 | start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT); |
| 282 | start_int_ack(SE_USB_AHB_NEED_CLK_INT); |
| 283 | start_int_umask(SE_USB_AHB_NEED_CLK_INT); |
| 284 | } |
| 285 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 286 | static void nxp_unset_usb_bits(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 287 | { |
| 288 | start_int_mask(SE_USB_OTG_ATX_INT_N); |
| 289 | start_int_mask(SE_USB_OTG_TIMER_INT); |
| 290 | start_int_mask(SE_USB_I2C_INT); |
| 291 | start_int_mask(SE_USB_INT); |
| 292 | start_int_mask(SE_USB_NEED_CLK_INT); |
| 293 | start_int_mask(SE_USB_AHB_NEED_CLK_INT); |
| 294 | } |
| 295 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 296 | static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 297 | { |
| 298 | struct usb_hcd *hcd = 0; |
| 299 | struct ohci_hcd *ohci; |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 300 | const struct hc_driver *driver = &ohci_nxp_hc_driver; |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 301 | struct i2c_adapter *i2c_adap; |
| 302 | struct i2c_board_info i2c_info; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 303 | |
| 304 | int ret = 0, irq; |
| 305 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 306 | dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 307 | if (usb_disabled()) { |
| 308 | err("USB is disabled"); |
| 309 | ret = -ENODEV; |
| 310 | goto out; |
| 311 | } |
| 312 | |
| 313 | if (pdev->num_resources != 2 |
| 314 | || pdev->resource[0].flags != IORESOURCE_MEM |
| 315 | || pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 316 | err("Invalid resource configuration"); |
| 317 | ret = -ENODEV; |
| 318 | goto out; |
| 319 | } |
| 320 | |
| 321 | /* Enable AHB slave USB clock, needed for further USB clock control */ |
| 322 | __raw_writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL); |
| 323 | |
| 324 | ret = i2c_add_driver(&isp1301_driver); |
| 325 | if (ret < 0) { |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 326 | err("failed to add ISP1301 driver"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 327 | goto out; |
| 328 | } |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 329 | i2c_adap = i2c_get_adapter(2); |
| 330 | memset(&i2c_info, 0, sizeof(struct i2c_board_info)); |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 331 | strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE); |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 332 | isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, |
Jean Delvare | 9a94241 | 2010-08-11 18:20:56 +0200 | [diff] [blame] | 333 | normal_i2c, NULL); |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 334 | i2c_put_adapter(i2c_adap); |
| 335 | if (!isp1301_i2c_client) { |
| 336 | err("failed to connect I2C to ISP1301 USB Transceiver"); |
| 337 | ret = -ENODEV; |
| 338 | goto out_i2c_driver; |
| 339 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 340 | |
| 341 | isp1301_configure(); |
| 342 | |
| 343 | /* Enable USB PLL */ |
| 344 | usb_clk = clk_get(&pdev->dev, "ck_pll5"); |
| 345 | if (IS_ERR(usb_clk)) { |
| 346 | err("failed to acquire USB PLL"); |
| 347 | ret = PTR_ERR(usb_clk); |
| 348 | goto out1; |
| 349 | } |
| 350 | |
| 351 | ret = clk_enable(usb_clk); |
| 352 | if (ret < 0) { |
| 353 | err("failed to start USB PLL"); |
| 354 | goto out2; |
| 355 | } |
| 356 | |
| 357 | ret = clk_set_rate(usb_clk, 48000); |
| 358 | if (ret < 0) { |
| 359 | err("failed to set USB clock rate"); |
| 360 | goto out3; |
| 361 | } |
| 362 | |
| 363 | __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL); |
| 364 | |
| 365 | /* Set to enable all needed USB clocks */ |
| 366 | __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL); |
| 367 | |
| 368 | while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) != |
| 369 | USB_CLOCK_MASK) ; |
| 370 | |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 371 | hcd = usb_create_hcd (driver, &pdev->dev, dev_name(&pdev->dev)); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 372 | if (!hcd) { |
| 373 | err("Failed to allocate HC buffer"); |
| 374 | ret = -ENOMEM; |
| 375 | goto out3; |
| 376 | } |
| 377 | |
| 378 | /* Set all USB bits in the Start Enable register */ |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 379 | nxp_set_usb_bits(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 380 | |
| 381 | hcd->rsrc_start = pdev->resource[0].start; |
| 382 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 383 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 384 | dev_dbg(&pdev->dev, "request_mem_region failed\n"); |
| 385 | ret = -ENOMEM; |
| 386 | goto out4; |
| 387 | } |
| 388 | hcd->regs = (void __iomem *)pdev->resource[0].start; |
| 389 | |
| 390 | irq = platform_get_irq(pdev, 0); |
| 391 | if (irq < 0) { |
| 392 | ret = -ENXIO; |
| 393 | goto out4; |
| 394 | } |
| 395 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 396 | nxp_start_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 397 | platform_set_drvdata(pdev, hcd); |
| 398 | ohci = hcd_to_ohci(hcd); |
| 399 | ohci_hcd_init(ohci); |
| 400 | |
| 401 | 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] | 402 | ret = usb_add_hcd(hcd, irq, 0); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 403 | if (ret == 0) |
| 404 | return ret; |
| 405 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 406 | nxp_stop_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 407 | out4: |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 408 | nxp_unset_usb_bits(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 409 | usb_put_hcd(hcd); |
| 410 | out3: |
| 411 | clk_disable(usb_clk); |
| 412 | out2: |
| 413 | clk_put(usb_clk); |
| 414 | out1: |
Luotao Fu | 8740cc7 | 2010-02-19 15:42:00 +0100 | [diff] [blame] | 415 | i2c_unregister_device(isp1301_i2c_client); |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 416 | isp1301_i2c_client = NULL; |
| 417 | out_i2c_driver: |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 418 | i2c_del_driver(&isp1301_driver); |
| 419 | out: |
| 420 | return ret; |
| 421 | } |
| 422 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 423 | static int usb_hcd_nxp_remove(struct platform_device *pdev) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 424 | { |
| 425 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 426 | |
| 427 | usb_remove_hcd(hcd); |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 428 | nxp_stop_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 429 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 430 | usb_put_hcd(hcd); |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 431 | nxp_unset_usb_bits(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 432 | clk_disable(usb_clk); |
| 433 | clk_put(usb_clk); |
Luotao Fu | 8740cc7 | 2010-02-19 15:42:00 +0100 | [diff] [blame] | 434 | i2c_unregister_device(isp1301_i2c_client); |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 435 | isp1301_i2c_client = NULL; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 436 | i2c_del_driver(&isp1301_driver); |
| 437 | |
| 438 | platform_set_drvdata(pdev, NULL); |
| 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 443 | /* work with hotplug and coldplug */ |
| 444 | MODULE_ALIAS("platform:usb-ohci"); |
| 445 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 446 | static struct platform_driver usb_hcd_nxp_driver = { |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 447 | .driver = { |
| 448 | .name = "usb-ohci", |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 449 | .owner = THIS_MODULE, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 450 | }, |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame^] | 451 | .probe = usb_hcd_nxp_probe, |
| 452 | .remove = usb_hcd_nxp_remove, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 453 | }; |
| 454 | |