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: |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 5 | * - NXP LPC32xx |
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> |
Roland Stigge | 2265efe | 2012-04-29 16:47:03 +0200 | [diff] [blame] | 24 | #include <linux/of.h> |
Roland Stigge | 73108aa | 2012-04-29 16:47:06 +0200 | [diff] [blame] | 25 | #include <linux/usb/isp1301.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 26 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/hardware.h> |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 29 | #include <asm/io.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 30 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 31 | #include <mach/platform.h> |
| 32 | #include <mach/irqs.h> |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 33 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 34 | #define USB_CONFIG_BASE 0x31020000 |
| 35 | #define PWRMAN_BASE 0x40004000 |
| 36 | |
| 37 | #define USB_CTRL IO_ADDRESS(PWRMAN_BASE + 0x64) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 38 | |
| 39 | /* USB_CTRL bit defines */ |
| 40 | #define USB_SLAVE_HCLK_EN (1 << 24) |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 41 | #define USB_DEV_NEED_CLK_EN (1 << 22) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 42 | #define USB_HOST_NEED_CLK_EN (1 << 21) |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 43 | #define PAD_CONTROL_LAST_DRIVEN (1 << 19) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 44 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 45 | #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 46 | |
| 47 | /* USB_OTG_STAT_CONTROL bit defines */ |
| 48 | #define TRANSPARENT_I2C_EN (1 << 7) |
| 49 | #define HOST_EN (1 << 0) |
| 50 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 51 | /* On LPC32xx, those are undefined */ |
| 52 | #ifndef start_int_set_falling_edge |
| 53 | #define start_int_set_falling_edge(irq) |
| 54 | #define start_int_set_rising_edge(irq) |
| 55 | #define start_int_ack(irq) |
| 56 | #define start_int_mask(irq) |
| 57 | #define start_int_umask(irq) |
| 58 | #endif |
| 59 | |
Jean Delvare | 09ce497 | 2009-10-01 19:03:13 +0200 | [diff] [blame] | 60 | static struct i2c_client *isp1301_i2c_client; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 61 | |
| 62 | extern int usb_disabled(void); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 63 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 64 | static struct clk *usb_pll_clk; |
| 65 | static struct clk *usb_dev_clk; |
| 66 | static struct clk *usb_otg_clk; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 67 | |
Roland Stigge | 53dc25a | 2012-03-12 22:54:51 +0100 | [diff] [blame] | 68 | static void isp1301_configure_lpc32xx(void) |
| 69 | { |
| 70 | /* LPC32XX only supports DAT_SE0 USB mode */ |
| 71 | /* This sequence is important */ |
| 72 | |
| 73 | /* Disable transparent UART mode first */ |
| 74 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 75 | (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 76 | MC1_UART_EN); |
| 77 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 78 | (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 79 | ~MC1_SPEED_REG); |
| 80 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 81 | ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG); |
| 82 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 83 | (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 84 | ~0); |
| 85 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 86 | ISP1301_I2C_MODE_CONTROL_2, |
| 87 | (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL)); |
| 88 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 89 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0); |
| 90 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 91 | ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0); |
| 92 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 93 | ISP1301_I2C_OTG_CONTROL_1, |
| 94 | (OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); |
| 95 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 96 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
| 97 | (OTG1_DM_PULLUP | OTG1_DP_PULLUP)); |
| 98 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 99 | ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
| 100 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 101 | ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR, |
| 102 | ~0); |
| 103 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 104 | ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
| 105 | |
| 106 | /* Enable usb_need_clk clock after transceiver is initialized */ |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 107 | __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] | 108 | |
| 109 | printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n", |
| 110 | i2c_smbus_read_word_data(isp1301_i2c_client, 0x00)); |
| 111 | printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n", |
| 112 | i2c_smbus_read_word_data(isp1301_i2c_client, 0x02)); |
| 113 | printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n", |
| 114 | i2c_smbus_read_word_data(isp1301_i2c_client, 0x14)); |
| 115 | } |
| 116 | |
| 117 | static void isp1301_configure(void) |
| 118 | { |
Roland Stigge | d684f05 | 2012-08-26 16:30:37 +0200 | [diff] [blame] | 119 | isp1301_configure_lpc32xx(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static inline void isp1301_vbus_on(void) |
| 123 | { |
Roland Stigge | a6a3600 | 2012-03-12 22:54:52 +0100 | [diff] [blame] | 124 | i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1, |
| 125 | OTG1_VBUS_DRV); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static inline void isp1301_vbus_off(void) |
| 129 | { |
Roland Stigge | a6a3600 | 2012-03-12 22:54:52 +0100 | [diff] [blame] | 130 | i2c_smbus_write_byte_data(isp1301_i2c_client, |
| 131 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, |
| 132 | OTG1_VBUS_DRV); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 133 | } |
| 134 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 135 | static void nxp_start_hc(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 136 | { |
| 137 | unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; |
| 138 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
| 139 | isp1301_vbus_on(); |
| 140 | } |
| 141 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 142 | static void nxp_stop_hc(void) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 143 | { |
| 144 | unsigned long tmp; |
| 145 | isp1301_vbus_off(); |
| 146 | tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN; |
| 147 | __raw_writel(tmp, USB_OTG_STAT_CONTROL); |
| 148 | } |
| 149 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 150 | static int ohci_nxp_start(struct usb_hcd *hcd) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 151 | { |
| 152 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 153 | int ret; |
| 154 | |
| 155 | if ((ret = ohci_init(ohci)) < 0) |
| 156 | return ret; |
| 157 | |
| 158 | if ((ret = ohci_run(ohci)) < 0) { |
| 159 | dev_err(hcd->self.controller, "can't start\n"); |
| 160 | ohci_stop(hcd); |
| 161 | return ret; |
| 162 | } |
| 163 | return 0; |
| 164 | } |
| 165 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 166 | static const struct hc_driver ohci_nxp_hc_driver = { |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 167 | .description = hcd_name, |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 168 | .product_desc = "nxp OHCI", |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * generic hardware linkage |
| 172 | */ |
| 173 | .irq = ohci_irq, |
| 174 | .flags = HCD_USB11 | HCD_MEMORY, |
| 175 | |
| 176 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 177 | /* |
| 178 | * basic lifecycle operations |
| 179 | */ |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 180 | .start = ohci_nxp_start, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 181 | .stop = ohci_stop, |
David Brownell | 8442ae0 | 2006-10-02 07:20:10 -0700 | [diff] [blame] | 182 | .shutdown = ohci_shutdown, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * managing i/o requests and associated device resources |
| 186 | */ |
| 187 | .urb_enqueue = ohci_urb_enqueue, |
| 188 | .urb_dequeue = ohci_urb_dequeue, |
| 189 | .endpoint_disable = ohci_endpoint_disable, |
| 190 | |
| 191 | /* |
| 192 | * scheduling support |
| 193 | */ |
| 194 | .get_frame_number = ohci_get_frame, |
| 195 | |
| 196 | /* |
| 197 | * root hub support |
| 198 | */ |
| 199 | .hub_status_data = ohci_hub_status_data, |
| 200 | .hub_control = ohci_hub_control, |
David Brownell | 8442ae0 | 2006-10-02 07:20:10 -0700 | [diff] [blame] | 201 | #ifdef CONFIG_PM |
| 202 | .bus_suspend = ohci_bus_suspend, |
| 203 | .bus_resume = ohci_bus_resume, |
| 204 | #endif |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 205 | .start_port_reset = ohci_start_port_reset, |
| 206 | }; |
| 207 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 208 | static int usb_hcd_nxp_probe(struct platform_device *pdev) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 209 | { |
| 210 | struct usb_hcd *hcd = 0; |
| 211 | struct ohci_hcd *ohci; |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 212 | const struct hc_driver *driver = &ohci_nxp_hc_driver; |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 213 | struct resource *res; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 214 | int ret = 0, irq; |
Roland Stigge | 73108aa | 2012-04-29 16:47:06 +0200 | [diff] [blame] | 215 | struct device_node *isp1301_node; |
| 216 | |
| 217 | if (pdev->dev.of_node) { |
| 218 | isp1301_node = of_parse_phandle(pdev->dev.of_node, |
| 219 | "transceiver", 0); |
| 220 | } else { |
| 221 | isp1301_node = NULL; |
| 222 | } |
| 223 | |
| 224 | isp1301_i2c_client = isp1301_get_client(isp1301_node); |
| 225 | if (!isp1301_i2c_client) { |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 226 | return -EPROBE_DEFER; |
Roland Stigge | 73108aa | 2012-04-29 16:47:06 +0200 | [diff] [blame] | 227 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 228 | |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 229 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 230 | pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; |
| 231 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 232 | dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 233 | if (usb_disabled()) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 234 | dev_err(&pdev->dev, "USB is disabled\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 235 | ret = -ENODEV; |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 236 | goto fail_disable; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 237 | } |
| 238 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 239 | /* Enable AHB slave USB clock, needed for further USB clock control */ |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 240 | __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 241 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 242 | /* Enable USB PLL */ |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 243 | usb_pll_clk = clk_get(&pdev->dev, "ck_pll5"); |
| 244 | if (IS_ERR(usb_pll_clk)) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 245 | dev_err(&pdev->dev, "failed to acquire USB PLL\n"); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 246 | ret = PTR_ERR(usb_pll_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 247 | goto fail_pll; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 248 | } |
| 249 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 250 | ret = clk_enable(usb_pll_clk); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 251 | if (ret < 0) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 252 | dev_err(&pdev->dev, "failed to start USB PLL\n"); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 253 | goto fail_pllen; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 254 | } |
| 255 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 256 | ret = clk_set_rate(usb_pll_clk, 48000); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 257 | if (ret < 0) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 258 | dev_err(&pdev->dev, "failed to set USB clock rate\n"); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 259 | goto fail_rate; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 260 | } |
| 261 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 262 | /* Enable USB device clock */ |
| 263 | usb_dev_clk = clk_get(&pdev->dev, "ck_usbd"); |
| 264 | if (IS_ERR(usb_dev_clk)) { |
| 265 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); |
| 266 | ret = PTR_ERR(usb_dev_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 267 | goto fail_dev; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | ret = clk_enable(usb_dev_clk); |
| 271 | if (ret < 0) { |
| 272 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 273 | goto fail_deven; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* Enable USB otg clocks */ |
| 277 | usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg"); |
| 278 | if (IS_ERR(usb_otg_clk)) { |
| 279 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); |
Julia Lawall | 2ec15a6 | 2012-08-25 21:57:07 +0200 | [diff] [blame] | 280 | ret = PTR_ERR(usb_otg_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 281 | goto fail_otg; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 282 | } |
| 283 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 284 | __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL); |
| 285 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 286 | ret = clk_enable(usb_otg_clk); |
| 287 | if (ret < 0) { |
| 288 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 289 | goto fail_otgen; |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 290 | } |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 291 | |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 292 | isp1301_configure(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 293 | |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 294 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 295 | if (!hcd) { |
Greg Kroah-Hartman | b6c227e | 2012-04-27 11:24:41 -0700 | [diff] [blame] | 296 | dev_err(&pdev->dev, "Failed to allocate HC buffer\n"); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 297 | ret = -ENOMEM; |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 298 | goto fail_hcd; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 299 | } |
| 300 | |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 301 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 302 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 303 | if (IS_ERR(hcd->regs)) { |
| 304 | ret = PTR_ERR(hcd->regs); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 305 | goto fail_resource; |
Roland Stigge | a6a99cf | 2012-04-29 16:47:02 +0200 | [diff] [blame] | 306 | } |
| 307 | hcd->rsrc_start = res->start; |
| 308 | hcd->rsrc_len = resource_size(res); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 309 | |
| 310 | irq = platform_get_irq(pdev, 0); |
| 311 | if (irq < 0) { |
| 312 | ret = -ENXIO; |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 313 | goto fail_resource; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 314 | } |
| 315 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 316 | nxp_start_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 317 | platform_set_drvdata(pdev, hcd); |
| 318 | ohci = hcd_to_ohci(hcd); |
| 319 | ohci_hcd_init(ohci); |
| 320 | |
| 321 | 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] | 322 | ret = usb_add_hcd(hcd, irq, 0); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 323 | if (ret == 0) |
| 324 | return ret; |
| 325 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 326 | nxp_stop_hc(); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 327 | fail_resource: |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 328 | usb_put_hcd(hcd); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 329 | fail_hcd: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 330 | clk_disable(usb_otg_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 331 | fail_otgen: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 332 | clk_put(usb_otg_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 333 | fail_otg: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 334 | clk_disable(usb_dev_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 335 | fail_deven: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 336 | clk_put(usb_dev_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 337 | fail_dev: |
| 338 | fail_rate: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 339 | clk_disable(usb_pll_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 340 | fail_pllen: |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 341 | clk_put(usb_pll_clk); |
Libo Chen | b3517d5 | 2013-05-10 14:22:42 +0800 | [diff] [blame] | 342 | fail_pll: |
| 343 | fail_disable: |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 344 | isp1301_i2c_client = NULL; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 348 | static int usb_hcd_nxp_remove(struct platform_device *pdev) |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 349 | { |
| 350 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 351 | |
| 352 | usb_remove_hcd(hcd); |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 353 | nxp_stop_hc(); |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 354 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 355 | usb_put_hcd(hcd); |
Alexandre Pereira da Silva | 78091dc | 2012-06-20 09:02:23 -0300 | [diff] [blame] | 356 | clk_disable(usb_pll_clk); |
| 357 | clk_put(usb_pll_clk); |
| 358 | clk_disable(usb_dev_clk); |
| 359 | clk_put(usb_dev_clk); |
Luotao Fu | 8740cc7 | 2010-02-19 15:42:00 +0100 | [diff] [blame] | 360 | i2c_unregister_device(isp1301_i2c_client); |
Jean Delvare | 3a407e7 | 2008-11-13 18:57:53 +0100 | [diff] [blame] | 361 | isp1301_i2c_client = NULL; |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 362 | |
| 363 | platform_set_drvdata(pdev, NULL); |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 368 | /* work with hotplug and coldplug */ |
| 369 | MODULE_ALIAS("platform:usb-ohci"); |
| 370 | |
Roland Stigge | 2265efe | 2012-04-29 16:47:03 +0200 | [diff] [blame] | 371 | #ifdef CONFIG_OF |
| 372 | static const struct of_device_id usb_hcd_nxp_match[] = { |
| 373 | { .compatible = "nxp,ohci-nxp" }, |
| 374 | {}, |
| 375 | }; |
| 376 | MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match); |
| 377 | #endif |
| 378 | |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 379 | static struct platform_driver usb_hcd_nxp_driver = { |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 380 | .driver = { |
| 381 | .name = "usb-ohci", |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 382 | .owner = THIS_MODULE, |
Roland Stigge | 2265efe | 2012-04-29 16:47:03 +0200 | [diff] [blame] | 383 | .of_match_table = of_match_ptr(usb_hcd_nxp_match), |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 384 | }, |
Roland Stigge | 2864310 | 2012-03-12 22:54:50 +0100 | [diff] [blame] | 385 | .probe = usb_hcd_nxp_probe, |
| 386 | .remove = usb_hcd_nxp_remove, |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 387 | }; |
| 388 | |