Merge tag 'ceph-for-4.13-rc8' of git://github.com/ceph/ceph-client
[linux/fpc-iii.git] / drivers / usb / host / ohci-nxp.c
blob6df8e2ed40fd9966229bf6487d34b2eb331b8d28
1 /*
2 * driver for NXP USB Host devices
4 * Currently supported OHCI host devices:
5 * - NXP LPC32xx
7 * Authors: Dmitry Chigirev <source@mvista.com>
8 * Vitaly Wool <vitalywool@gmail.com>
10 * register initialization is based on code examples provided by Philips
11 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
13 * NOTE: This driver does not have suspend/resume functionality
14 * This driver is intended for engineering development purposes only
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.
21 #include <linux/clk.h>
22 #include <linux/dma-mapping.h>
23 #include <linux/io.h>
24 #include <linux/i2c.h>
25 #include <linux/module.h>
26 #include <linux/of.h>
27 #include <linux/platform_device.h>
28 #include <linux/usb/isp1301.h>
29 #include <linux/usb.h>
30 #include <linux/usb/hcd.h>
32 #include "ohci.h"
34 #include <mach/hardware.h>
36 #define USB_CONFIG_BASE 0x31020000
37 #define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
39 /* USB_OTG_STAT_CONTROL bit defines */
40 #define TRANSPARENT_I2C_EN (1 << 7)
41 #define HOST_EN (1 << 0)
43 /* On LPC32xx, those are undefined */
44 #ifndef start_int_set_falling_edge
45 #define start_int_set_falling_edge(irq)
46 #define start_int_set_rising_edge(irq)
47 #define start_int_ack(irq)
48 #define start_int_mask(irq)
49 #define start_int_umask(irq)
50 #endif
52 #define DRIVER_DESC "OHCI NXP driver"
54 static const char hcd_name[] = "ohci-nxp";
55 static struct hc_driver __read_mostly ohci_nxp_hc_driver;
57 static struct i2c_client *isp1301_i2c_client;
59 static struct clk *usb_host_clk;
61 static void isp1301_configure_lpc32xx(void)
63 /* LPC32XX only supports DAT_SE0 USB mode */
64 /* This sequence is important */
66 /* Disable transparent UART mode first */
67 i2c_smbus_write_byte_data(isp1301_i2c_client,
68 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
69 MC1_UART_EN);
70 i2c_smbus_write_byte_data(isp1301_i2c_client,
71 (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
72 ~MC1_SPEED_REG);
73 i2c_smbus_write_byte_data(isp1301_i2c_client,
74 ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
75 i2c_smbus_write_byte_data(isp1301_i2c_client,
76 (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
77 ~0);
78 i2c_smbus_write_byte_data(isp1301_i2c_client,
79 ISP1301_I2C_MODE_CONTROL_2,
80 (MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
81 i2c_smbus_write_byte_data(isp1301_i2c_client,
82 (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
83 i2c_smbus_write_byte_data(isp1301_i2c_client,
84 ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
85 i2c_smbus_write_byte_data(isp1301_i2c_client,
86 ISP1301_I2C_OTG_CONTROL_1,
87 (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_PULLUP | OTG1_DP_PULLUP));
91 i2c_smbus_write_byte_data(isp1301_i2c_client,
92 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
93 i2c_smbus_write_byte_data(isp1301_i2c_client,
94 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
95 ~0);
96 i2c_smbus_write_byte_data(isp1301_i2c_client,
97 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
99 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
100 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
101 printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
102 i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
103 printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
104 i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
107 static void isp1301_configure(void)
109 isp1301_configure_lpc32xx();
112 static inline void isp1301_vbus_on(void)
114 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
115 OTG1_VBUS_DRV);
118 static inline void isp1301_vbus_off(void)
120 i2c_smbus_write_byte_data(isp1301_i2c_client,
121 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
122 OTG1_VBUS_DRV);
125 static void ohci_nxp_start_hc(void)
127 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
129 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
130 isp1301_vbus_on();
133 static void ohci_nxp_stop_hc(void)
135 unsigned long tmp;
137 isp1301_vbus_off();
138 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
139 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
142 static int ohci_hcd_nxp_probe(struct platform_device *pdev)
144 struct usb_hcd *hcd = 0;
145 const struct hc_driver *driver = &ohci_nxp_hc_driver;
146 struct resource *res;
147 int ret = 0, irq;
148 struct device_node *isp1301_node;
150 if (pdev->dev.of_node) {
151 isp1301_node = of_parse_phandle(pdev->dev.of_node,
152 "transceiver", 0);
153 } else {
154 isp1301_node = NULL;
157 isp1301_i2c_client = isp1301_get_client(isp1301_node);
158 if (!isp1301_i2c_client)
159 return -EPROBE_DEFER;
161 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
162 if (ret)
163 goto fail_disable;
165 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
166 if (usb_disabled()) {
167 dev_err(&pdev->dev, "USB is disabled\n");
168 ret = -ENODEV;
169 goto fail_disable;
172 /* Enable USB host clock */
173 usb_host_clk = devm_clk_get(&pdev->dev, NULL);
174 if (IS_ERR(usb_host_clk)) {
175 dev_err(&pdev->dev, "failed to acquire USB OHCI clock\n");
176 ret = PTR_ERR(usb_host_clk);
177 goto fail_disable;
180 ret = clk_prepare_enable(usb_host_clk);
181 if (ret < 0) {
182 dev_err(&pdev->dev, "failed to start USB OHCI clock\n");
183 goto fail_disable;
186 isp1301_configure();
188 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
189 if (!hcd) {
190 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
191 ret = -ENOMEM;
192 goto fail_hcd;
195 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
196 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
197 if (IS_ERR(hcd->regs)) {
198 ret = PTR_ERR(hcd->regs);
199 goto fail_resource;
201 hcd->rsrc_start = res->start;
202 hcd->rsrc_len = resource_size(res);
204 irq = platform_get_irq(pdev, 0);
205 if (irq < 0) {
206 ret = -ENXIO;
207 goto fail_resource;
210 ohci_nxp_start_hc();
211 platform_set_drvdata(pdev, hcd);
213 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
214 ret = usb_add_hcd(hcd, irq, 0);
215 if (ret == 0) {
216 device_wakeup_enable(hcd->self.controller);
217 return ret;
220 ohci_nxp_stop_hc();
221 fail_resource:
222 usb_put_hcd(hcd);
223 fail_hcd:
224 clk_disable_unprepare(usb_host_clk);
225 fail_disable:
226 isp1301_i2c_client = NULL;
227 return ret;
230 static int ohci_hcd_nxp_remove(struct platform_device *pdev)
232 struct usb_hcd *hcd = platform_get_drvdata(pdev);
234 usb_remove_hcd(hcd);
235 ohci_nxp_stop_hc();
236 usb_put_hcd(hcd);
237 clk_disable_unprepare(usb_host_clk);
238 isp1301_i2c_client = NULL;
240 return 0;
243 /* work with hotplug and coldplug */
244 MODULE_ALIAS("platform:usb-ohci");
246 #ifdef CONFIG_OF
247 static const struct of_device_id ohci_hcd_nxp_match[] = {
248 { .compatible = "nxp,ohci-nxp" },
251 MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
252 #endif
254 static struct platform_driver ohci_hcd_nxp_driver = {
255 .driver = {
256 .name = "usb-ohci",
257 .of_match_table = of_match_ptr(ohci_hcd_nxp_match),
259 .probe = ohci_hcd_nxp_probe,
260 .remove = ohci_hcd_nxp_remove,
263 static int __init ohci_nxp_init(void)
265 if (usb_disabled())
266 return -ENODEV;
268 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
270 ohci_init_driver(&ohci_nxp_hc_driver, NULL);
271 return platform_driver_register(&ohci_hcd_nxp_driver);
273 module_init(ohci_nxp_init);
275 static void __exit ohci_nxp_cleanup(void)
277 platform_driver_unregister(&ohci_hcd_nxp_driver);
279 module_exit(ohci_nxp_cleanup);
281 MODULE_DESCRIPTION(DRIVER_DESC);
282 MODULE_LICENSE("GPL v2");