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