]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/usb/host/ohci-nxp.c
USB: OHCI: nxp: remove useless extern declaration
[mirror_ubuntu-jammy-kernel.git] / drivers / usb / host / ohci-nxp.c
CommitLineData
60bbfc84 1/*
28643104 2 * driver for NXP USB Host devices
60bbfc84 3 *
28643104 4 * Currently supported OHCI host devices:
53dc25ad 5 * - NXP LPC32xx
60bbfc84
VW
6 *
7 * Authors: Dmitry Chigirev <source@mvista.com>
dd9048af 8 * Vitaly Wool <vitalywool@gmail.com>
60bbfc84
VW
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>
30330b8f
MG
22#include <linux/dma-mapping.h>
23#include <linux/io.h>
60bbfc84 24#include <linux/i2c.h>
30330b8f 25#include <linux/module.h>
2265efea 26#include <linux/of.h>
30330b8f 27#include <linux/platform_device.h>
73108aa9 28#include <linux/usb/isp1301.h>
30330b8f
MG
29#include <linux/usb.h>
30#include <linux/usb/hcd.h>
31
32#include "ohci.h"
33
a09e64fb 34#include <mach/hardware.h>
60bbfc84 35
53dc25ad 36#define USB_CONFIG_BASE 0x31020000
53dc25ad 37#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
60bbfc84
VW
38
39/* USB_OTG_STAT_CONTROL bit defines */
40#define TRANSPARENT_I2C_EN (1 << 7)
41#define HOST_EN (1 << 0)
42
53dc25ad
RS
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
51
30330b8f
MG
52#define DRIVER_DESC "OHCI NXP driver"
53
54static const char hcd_name[] = "ohci-nxp";
55static struct hc_driver __read_mostly ohci_nxp_hc_driver;
56
09ce497e 57static struct i2c_client *isp1301_i2c_client;
60bbfc84 58
83253b3b 59static struct clk *usb_host_clk;
60bbfc84 60
53dc25ad
RS
61static void isp1301_configure_lpc32xx(void)
62{
63 /* LPC32XX only supports DAT_SE0 USB mode */
64 /* This sequence is important */
65
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);
98
53dc25ad
RS
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));
105}
106
107static void isp1301_configure(void)
108{
d684f05f 109 isp1301_configure_lpc32xx();
60bbfc84
VW
110}
111
112static inline void isp1301_vbus_on(void)
113{
a6a36008
RS
114 i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
115 OTG1_VBUS_DRV);
60bbfc84
VW
116}
117
118static inline void isp1301_vbus_off(void)
119{
a6a36008
RS
120 i2c_smbus_write_byte_data(isp1301_i2c_client,
121 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
122 OTG1_VBUS_DRV);
60bbfc84
VW
123}
124
30330b8f 125static void ohci_nxp_start_hc(void)
60bbfc84
VW
126{
127 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
128 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
129 isp1301_vbus_on();
130}
131
30330b8f 132static void ohci_nxp_stop_hc(void)
60bbfc84
VW
133{
134 unsigned long tmp;
135 isp1301_vbus_off();
136 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
137 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
138}
139
30330b8f 140static int ohci_hcd_nxp_probe(struct platform_device *pdev)
60bbfc84
VW
141{
142 struct usb_hcd *hcd = 0;
28643104 143 const struct hc_driver *driver = &ohci_nxp_hc_driver;
a6a99cf0 144 struct resource *res;
60bbfc84 145 int ret = 0, irq;
73108aa9
RS
146 struct device_node *isp1301_node;
147
148 if (pdev->dev.of_node) {
149 isp1301_node = of_parse_phandle(pdev->dev.of_node,
150 "transceiver", 0);
151 } else {
152 isp1301_node = NULL;
153 }
154
155 isp1301_i2c_client = isp1301_get_client(isp1301_node);
156 if (!isp1301_i2c_client) {
b3517d5d 157 return -EPROBE_DEFER;
73108aa9 158 }
60bbfc84 159
e1fd7341 160 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
22d9d8e8
RK
161 if (ret)
162 goto fail_disable;
a6a99cf0 163
28643104 164 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
60bbfc84 165 if (usb_disabled()) {
b6c227ed 166 dev_err(&pdev->dev, "USB is disabled\n");
60bbfc84 167 ret = -ENODEV;
b3517d5d 168 goto fail_disable;
60bbfc84
VW
169 }
170
83253b3b
VZ
171 /* Enable USB host clock */
172 usb_host_clk = devm_clk_get(&pdev->dev, NULL);
173 if (IS_ERR(usb_host_clk)) {
174 dev_err(&pdev->dev, "failed to acquire USB OHCI clock\n");
175 ret = PTR_ERR(usb_host_clk);
ac8d81f3 176 goto fail_disable;
60bbfc84
VW
177 }
178
83253b3b 179 ret = clk_prepare_enable(usb_host_clk);
60bbfc84 180 if (ret < 0) {
83253b3b 181 dev_err(&pdev->dev, "failed to start USB OHCI clock\n");
ac8d81f3 182 goto fail_disable;
60bbfc84
VW
183 }
184
78091dc2 185 isp1301_configure();
60bbfc84 186
a6a99cf0 187 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
60bbfc84 188 if (!hcd) {
b6c227ed 189 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
60bbfc84 190 ret = -ENOMEM;
b3517d5d 191 goto fail_hcd;
60bbfc84
VW
192 }
193
a6a99cf0 194 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
148e1134
TR
195 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
196 if (IS_ERR(hcd->regs)) {
197 ret = PTR_ERR(hcd->regs);
b3517d5d 198 goto fail_resource;
60bbfc84 199 }
a6a99cf0
RS
200 hcd->rsrc_start = res->start;
201 hcd->rsrc_len = resource_size(res);
60bbfc84
VW
202
203 irq = platform_get_irq(pdev, 0);
204 if (irq < 0) {
205 ret = -ENXIO;
b3517d5d 206 goto fail_resource;
60bbfc84
VW
207 }
208
30330b8f 209 ohci_nxp_start_hc();
60bbfc84 210 platform_set_drvdata(pdev, hcd);
60bbfc84
VW
211
212 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
b5dd18d8 213 ret = usb_add_hcd(hcd, irq, 0);
3c9740a1
PC
214 if (ret == 0) {
215 device_wakeup_enable(hcd->self.controller);
60bbfc84 216 return ret;
3c9740a1 217 }
60bbfc84 218
30330b8f 219 ohci_nxp_stop_hc();
b3517d5d 220fail_resource:
60bbfc84 221 usb_put_hcd(hcd);
b3517d5d 222fail_hcd:
83253b3b 223 clk_disable_unprepare(usb_host_clk);
b3517d5d 224fail_disable:
3a407e73 225 isp1301_i2c_client = NULL;
60bbfc84
VW
226 return ret;
227}
228
30330b8f 229static int ohci_hcd_nxp_remove(struct platform_device *pdev)
60bbfc84
VW
230{
231 struct usb_hcd *hcd = platform_get_drvdata(pdev);
232
233 usb_remove_hcd(hcd);
30330b8f 234 ohci_nxp_stop_hc();
60bbfc84 235 usb_put_hcd(hcd);
83253b3b 236 clk_disable_unprepare(usb_host_clk);
3a407e73 237 isp1301_i2c_client = NULL;
60bbfc84 238
60bbfc84
VW
239 return 0;
240}
241
f4fce61d
KS
242/* work with hotplug and coldplug */
243MODULE_ALIAS("platform:usb-ohci");
244
2265efea 245#ifdef CONFIG_OF
30330b8f 246static const struct of_device_id ohci_hcd_nxp_match[] = {
2265efea
RS
247 { .compatible = "nxp,ohci-nxp" },
248 {},
249};
30330b8f 250MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
2265efea
RS
251#endif
252
30330b8f 253static struct platform_driver ohci_hcd_nxp_driver = {
60bbfc84
VW
254 .driver = {
255 .name = "usb-ohci",
30330b8f 256 .of_match_table = of_match_ptr(ohci_hcd_nxp_match),
60bbfc84 257 },
30330b8f
MG
258 .probe = ohci_hcd_nxp_probe,
259 .remove = ohci_hcd_nxp_remove,
60bbfc84
VW
260};
261
30330b8f
MG
262static int __init ohci_nxp_init(void)
263{
264 if (usb_disabled())
265 return -ENODEV;
266
267 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
268
269 ohci_init_driver(&ohci_nxp_hc_driver, NULL);
270 return platform_driver_register(&ohci_hcd_nxp_driver);
271}
272module_init(ohci_nxp_init);
273
274static void __exit ohci_nxp_cleanup(void)
275{
276 platform_driver_unregister(&ohci_hcd_nxp_driver);
277}
278module_exit(ohci_nxp_cleanup);
279
280MODULE_DESCRIPTION(DRIVER_DESC);
281MODULE_LICENSE("GPL v2");