Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * driver for NXP USB Host devices
  4 *
  5 * Currently supported OHCI host devices:
 
  6 * - NXP LPC32xx
  7 *
  8 * Authors: Dmitry Chigirev <source@mvista.com>
  9 *	    Vitaly Wool <vitalywool@gmail.com>
 10 *
 11 * register initialization is based on code examples provided by Philips
 12 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
 13 *
 14 * NOTE: This driver does not have suspend/resume functionality
 15 * This driver is intended for engineering development purposes only
 16 *
 17 * 2005-2006 (c) MontaVista Software, Inc.
 
 
 
 18 */
 19#include <linux/clk.h>
 20#include <linux/dma-mapping.h>
 21#include <linux/io.h>
 22#include <linux/i2c.h>
 23#include <linux/module.h>
 24#include <linux/of.h>
 25#include <linux/platform_device.h>
 26#include <linux/usb/isp1301.h>
 27#include <linux/usb.h>
 28#include <linux/usb/hcd.h>
 29
 30#include "ohci.h"
 
 
 
 
 
 31
 32#define USB_CONFIG_BASE		0x31020000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 33
 34/* USB_OTG_STAT_CONTROL bit defines */
 35#define TRANSPARENT_I2C_EN	(1 << 7)
 36#define HOST_EN			(1 << 0)
 37
 38/* On LPC32xx, those are undefined */
 39#ifndef start_int_set_falling_edge
 40#define start_int_set_falling_edge(irq)
 41#define start_int_set_rising_edge(irq)
 42#define start_int_ack(irq)
 43#define start_int_mask(irq)
 44#define start_int_umask(irq)
 45#endif
 46
 47#define DRIVER_DESC "OHCI NXP driver"
 48
 49static const char hcd_name[] = "ohci-nxp";
 50static struct hc_driver __read_mostly ohci_nxp_hc_driver;
 51
 52static struct i2c_client *isp1301_i2c_client;
 53
 54static struct clk *usb_host_clk;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 55
 56static void isp1301_configure_lpc32xx(void)
 57{
 58	/* LPC32XX only supports DAT_SE0 USB mode */
 59	/* This sequence is important */
 60
 61	/* Disable transparent UART mode first */
 62	i2c_smbus_write_byte_data(isp1301_i2c_client,
 63		(ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
 64		MC1_UART_EN);
 65	i2c_smbus_write_byte_data(isp1301_i2c_client,
 66		(ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
 67		~MC1_SPEED_REG);
 68	i2c_smbus_write_byte_data(isp1301_i2c_client,
 69				  ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
 70	i2c_smbus_write_byte_data(isp1301_i2c_client,
 71		  (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
 72		  ~0);
 73	i2c_smbus_write_byte_data(isp1301_i2c_client,
 74		ISP1301_I2C_MODE_CONTROL_2,
 75		(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
 76	i2c_smbus_write_byte_data(isp1301_i2c_client,
 77		(ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
 78	i2c_smbus_write_byte_data(isp1301_i2c_client,
 79		ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
 80	i2c_smbus_write_byte_data(isp1301_i2c_client,
 81		ISP1301_I2C_OTG_CONTROL_1,
 82		(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
 83	i2c_smbus_write_byte_data(isp1301_i2c_client,
 84		(ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
 85		(OTG1_DM_PULLUP | OTG1_DP_PULLUP));
 86	i2c_smbus_write_byte_data(isp1301_i2c_client,
 87		ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
 88	i2c_smbus_write_byte_data(isp1301_i2c_client,
 89		ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
 90		~0);
 91	i2c_smbus_write_byte_data(isp1301_i2c_client,
 92		ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
 93
 
 
 
 94	printk(KERN_INFO "ISP1301 Vendor ID  : 0x%04x\n",
 95	      i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
 96	printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
 97	      i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
 98	printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
 99	      i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
100}
101
102static void isp1301_configure(void)
103{
104	isp1301_configure_lpc32xx();
 
 
 
105}
106
107static inline void isp1301_vbus_on(void)
108{
109	i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
110				  OTG1_VBUS_DRV);
111}
112
113static inline void isp1301_vbus_off(void)
114{
115	i2c_smbus_write_byte_data(isp1301_i2c_client,
116		ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
117		OTG1_VBUS_DRV);
118}
119
120static void ohci_nxp_start_hc(void)
121{
122	void __iomem *usb_otg_stat_control = ioremap(USB_CONFIG_BASE + 0x110, 4);
123	unsigned long tmp;
 
 
124
125	if (WARN_ON(!usb_otg_stat_control))
126		return;
 
 
 
 
 
127
128	tmp = __raw_readl(usb_otg_stat_control) | HOST_EN;
 
 
 
129
130	__raw_writel(tmp, usb_otg_stat_control);
131	isp1301_vbus_on();
132
133	iounmap(usb_otg_stat_control);
 
 
 
 
 
134}
135
136static void ohci_nxp_stop_hc(void)
137{
138	void __iomem *usb_otg_stat_control = ioremap(USB_CONFIG_BASE + 0x110, 4);
139	unsigned long tmp;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
141	if (WARN_ON(!usb_otg_stat_control))
142		return;
143
144	isp1301_vbus_off();
145	tmp = __raw_readl(usb_otg_stat_control) & ~HOST_EN;
146	__raw_writel(tmp, usb_otg_stat_control);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
148	iounmap(usb_otg_stat_control);
 
 
 
 
 
 
 
 
 
149}
150
151static int ohci_hcd_nxp_probe(struct platform_device *pdev)
152{
153	struct usb_hcd *hcd = NULL;
 
154	const struct hc_driver *driver = &ohci_nxp_hc_driver;
155	struct resource *res;
156	int ret = 0, irq;
157	struct device_node *isp1301_node;
158
159	if (pdev->dev.of_node) {
160		isp1301_node = of_parse_phandle(pdev->dev.of_node,
161						"transceiver", 0);
162	} else {
163		isp1301_node = NULL;
164	}
165
166	isp1301_i2c_client = isp1301_get_client(isp1301_node);
167	of_node_put(isp1301_node);
168	if (!isp1301_i2c_client)
169		return -EPROBE_DEFER;
170
171	ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
172	if (ret)
173		goto fail_disable;
174
175	dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
176	if (usb_disabled()) {
177		dev_err(&pdev->dev, "USB is disabled\n");
178		ret = -ENODEV;
179		goto fail_disable;
180	}
181
182	/* Enable USB host clock */
183	usb_host_clk = devm_clk_get(&pdev->dev, NULL);
184	if (IS_ERR(usb_host_clk)) {
185		dev_err(&pdev->dev, "failed to acquire USB OHCI clock\n");
186		ret = PTR_ERR(usb_host_clk);
187		goto fail_disable;
 
 
 
 
 
188	}
189
190	ret = clk_prepare_enable(usb_host_clk);
191	if (ret < 0) {
192		dev_err(&pdev->dev, "failed to start USB OHCI clock\n");
193		goto fail_disable;
194	}
195
196	isp1301_configure();
 
 
 
 
 
 
 
 
 
 
 
 
197
198	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
199	if (!hcd) {
200		dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
201		ret = -ENOMEM;
202		goto fail_hcd;
203	}
204
205	hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
206	if (IS_ERR(hcd->regs)) {
207		ret = PTR_ERR(hcd->regs);
208		goto fail_resource;
 
 
 
 
 
 
 
 
 
 
 
209	}
210	hcd->rsrc_start = res->start;
211	hcd->rsrc_len = resource_size(res);
212
213	irq = platform_get_irq(pdev, 0);
214	if (irq < 0) {
215		ret = -ENXIO;
216		goto fail_resource;
217	}
218
219	ohci_nxp_start_hc();
220	platform_set_drvdata(pdev, hcd);
 
 
221
222	dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
223	ret = usb_add_hcd(hcd, irq, 0);
224	if (ret == 0) {
225		device_wakeup_enable(hcd->self.controller);
226		return ret;
227	}
228
229	ohci_nxp_stop_hc();
230fail_resource:
 
231	usb_put_hcd(hcd);
232fail_hcd:
233	clk_disable_unprepare(usb_host_clk);
234fail_disable:
 
 
235	isp1301_i2c_client = NULL;
 
236	return ret;
237}
238
239static void ohci_hcd_nxp_remove(struct platform_device *pdev)
240{
241	struct usb_hcd *hcd = platform_get_drvdata(pdev);
242
243	usb_remove_hcd(hcd);
244	ohci_nxp_stop_hc();
 
245	usb_put_hcd(hcd);
246	clk_disable_unprepare(usb_host_clk);
 
 
 
247	isp1301_i2c_client = NULL;
 
 
 
 
248}
249
250/* work with hotplug and coldplug */
251MODULE_ALIAS("platform:usb-ohci");
252
253#ifdef CONFIG_OF
254static const struct of_device_id ohci_hcd_nxp_match[] = {
255	{ .compatible = "nxp,ohci-nxp" },
256	{},
257};
258MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
259#endif
260
261static struct platform_driver ohci_hcd_nxp_driver = {
262	.driver = {
263		.name = "usb-ohci",
264		.of_match_table = of_match_ptr(ohci_hcd_nxp_match),
 
265	},
266	.probe = ohci_hcd_nxp_probe,
267	.remove_new = ohci_hcd_nxp_remove,
268};
269
270static int __init ohci_nxp_init(void)
271{
272	if (usb_disabled())
273		return -ENODEV;
274
275	ohci_init_driver(&ohci_nxp_hc_driver, NULL);
276	return platform_driver_register(&ohci_hcd_nxp_driver);
277}
278module_init(ohci_nxp_init);
279
280static void __exit ohci_nxp_cleanup(void)
281{
282	platform_driver_unregister(&ohci_hcd_nxp_driver);
283}
284module_exit(ohci_nxp_cleanup);
285
286MODULE_DESCRIPTION(DRIVER_DESC);
287MODULE_LICENSE("GPL v2");
v3.5.6
 
  1/*
  2 * driver for NXP USB Host devices
  3 *
  4 * Currently supported OHCI host devices:
  5 * - Philips PNX4008
  6 * - NXP LPC32xx
  7 *
  8 * Authors: Dmitry Chigirev <source@mvista.com>
  9 *	    Vitaly Wool <vitalywool@gmail.com>
 10 *
 11 * register initialization is based on code examples provided by Philips
 12 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
 13 *
 14 * NOTE: This driver does not have suspend/resume functionality
 15 * This driver is intended for engineering development purposes only
 16 *
 17 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
 18 * the terms of the GNU General Public License version 2. This program
 19 * is licensed "as is" without any warranty of any kind, whether express
 20 * or implied.
 21 */
 22#include <linux/clk.h>
 23#include <linux/platform_device.h>
 
 24#include <linux/i2c.h>
 
 25#include <linux/of.h>
 
 26#include <linux/usb/isp1301.h>
 
 
 27
 28#include <mach/hardware.h>
 29#include <asm/mach-types.h>
 30#include <asm/io.h>
 31
 32#include <mach/platform.h>
 33#include <mach/irqs.h>
 34
 35#define USB_CONFIG_BASE		0x31020000
 36#define PWRMAN_BASE		0x40004000
 37
 38#define USB_CTRL		IO_ADDRESS(PWRMAN_BASE + 0x64)
 39
 40/* USB_CTRL bit defines */
 41#define USB_SLAVE_HCLK_EN	(1 << 24)
 42#define USB_DEV_NEED_CLK_EN	(1 << 22)
 43#define USB_HOST_NEED_CLK_EN	(1 << 21)
 44#define PAD_CONTROL_LAST_DRIVEN	(1 << 19)
 45
 46#define USB_OTG_CLK_CTRL	IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
 47#define USB_OTG_CLK_STAT	IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
 48
 49/* USB_OTG_CLK_CTRL bit defines */
 50#define AHB_M_CLOCK_ON		(1 << 4)
 51#define OTG_CLOCK_ON		(1 << 3)
 52#define I2C_CLOCK_ON		(1 << 2)
 53#define DEV_CLOCK_ON		(1 << 1)
 54#define HOST_CLOCK_ON		(1 << 0)
 55
 56#define USB_OTG_STAT_CONTROL	IO_ADDRESS(USB_CONFIG_BASE + 0x110)
 57
 58/* USB_OTG_STAT_CONTROL bit defines */
 59#define TRANSPARENT_I2C_EN	(1 << 7)
 60#define HOST_EN			(1 << 0)
 61
 62/* On LPC32xx, those are undefined */
 63#ifndef start_int_set_falling_edge
 64#define start_int_set_falling_edge(irq)
 65#define start_int_set_rising_edge(irq)
 66#define start_int_ack(irq)
 67#define start_int_mask(irq)
 68#define start_int_umask(irq)
 69#endif
 70
 71static struct i2c_client *isp1301_i2c_client;
 72
 73extern int usb_disabled(void);
 
 74
 75static struct clk *usb_clk;
 76
 77static void isp1301_configure_pnx4008(void)
 78{
 79	/* PNX4008 only supports DAT_SE0 USB mode */
 80	/* PNX4008 R2A requires setting the MAX603 to output 3.6V */
 81	/* Power up externel charge-pump */
 82
 83	i2c_smbus_write_byte_data(isp1301_i2c_client,
 84		ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0 | MC1_SPEED_REG);
 85	i2c_smbus_write_byte_data(isp1301_i2c_client,
 86		ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
 87		~(MC1_DAT_SE0 | MC1_SPEED_REG));
 88	i2c_smbus_write_byte_data(isp1301_i2c_client,
 89		ISP1301_I2C_MODE_CONTROL_2,
 90		MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL);
 91	i2c_smbus_write_byte_data(isp1301_i2c_client,
 92		ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR,
 93		~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
 94	i2c_smbus_write_byte_data(isp1301_i2c_client,
 95		ISP1301_I2C_OTG_CONTROL_1, OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
 96	i2c_smbus_write_byte_data(isp1301_i2c_client,
 97		ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
 98		~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
 99	i2c_smbus_write_byte_data(isp1301_i2c_client,
100		ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, 0xFF);
101	i2c_smbus_write_byte_data(isp1301_i2c_client,
102		ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
103		0xFF);
104	i2c_smbus_write_byte_data(isp1301_i2c_client,
105		ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR,
106		0xFF);
107}
108
109static void isp1301_configure_lpc32xx(void)
110{
111	/* LPC32XX only supports DAT_SE0 USB mode */
112	/* This sequence is important */
113
114	/* Disable transparent UART mode first */
115	i2c_smbus_write_byte_data(isp1301_i2c_client,
116		(ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
117		MC1_UART_EN);
118	i2c_smbus_write_byte_data(isp1301_i2c_client,
119		(ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
120		~MC1_SPEED_REG);
121	i2c_smbus_write_byte_data(isp1301_i2c_client,
122				  ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
123	i2c_smbus_write_byte_data(isp1301_i2c_client,
124		  (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR),
125		  ~0);
126	i2c_smbus_write_byte_data(isp1301_i2c_client,
127		ISP1301_I2C_MODE_CONTROL_2,
128		(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL));
129	i2c_smbus_write_byte_data(isp1301_i2c_client,
130		(ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0);
131	i2c_smbus_write_byte_data(isp1301_i2c_client,
132		ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
133	i2c_smbus_write_byte_data(isp1301_i2c_client,
134		ISP1301_I2C_OTG_CONTROL_1,
135		(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
136	i2c_smbus_write_byte_data(isp1301_i2c_client,
137		(ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR),
138		(OTG1_DM_PULLUP | OTG1_DP_PULLUP));
139	i2c_smbus_write_byte_data(isp1301_i2c_client,
140		ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
141	i2c_smbus_write_byte_data(isp1301_i2c_client,
142		ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR,
143		~0);
144	i2c_smbus_write_byte_data(isp1301_i2c_client,
145		ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
146
147	/* Enable usb_need_clk clock after transceiver is initialized */
148	__raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
149
150	printk(KERN_INFO "ISP1301 Vendor ID  : 0x%04x\n",
151	      i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
152	printk(KERN_INFO "ISP1301 Product ID : 0x%04x\n",
153	      i2c_smbus_read_word_data(isp1301_i2c_client, 0x02));
154	printk(KERN_INFO "ISP1301 Version ID : 0x%04x\n",
155	      i2c_smbus_read_word_data(isp1301_i2c_client, 0x14));
156}
157
158static void isp1301_configure(void)
159{
160	if (machine_is_pnx4008())
161		isp1301_configure_pnx4008();
162	else
163		isp1301_configure_lpc32xx();
164}
165
166static inline void isp1301_vbus_on(void)
167{
168	i2c_smbus_write_byte_data(isp1301_i2c_client, ISP1301_I2C_OTG_CONTROL_1,
169				  OTG1_VBUS_DRV);
170}
171
172static inline void isp1301_vbus_off(void)
173{
174	i2c_smbus_write_byte_data(isp1301_i2c_client,
175		ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR,
176		OTG1_VBUS_DRV);
177}
178
179static void nxp_start_hc(void)
180{
181	unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
182	__raw_writel(tmp, USB_OTG_STAT_CONTROL);
183	isp1301_vbus_on();
184}
185
186static void nxp_stop_hc(void)
187{
188	unsigned long tmp;
189	isp1301_vbus_off();
190	tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
191	__raw_writel(tmp, USB_OTG_STAT_CONTROL);
192}
193
194static int __devinit ohci_nxp_start(struct usb_hcd *hcd)
195{
196	struct ohci_hcd *ohci = hcd_to_ohci(hcd);
197	int ret;
198
199	if ((ret = ohci_init(ohci)) < 0)
200		return ret;
201
202	if ((ret = ohci_run(ohci)) < 0) {
203		dev_err(hcd->self.controller, "can't start\n");
204		ohci_stop(hcd);
205		return ret;
206	}
207	return 0;
208}
209
210static const struct hc_driver ohci_nxp_hc_driver = {
211	.description = hcd_name,
212	.product_desc =		"nxp OHCI",
213
214	/*
215	 * generic hardware linkage
216	 */
217	.irq = ohci_irq,
218	.flags = HCD_USB11 | HCD_MEMORY,
219
220	.hcd_priv_size =	sizeof(struct ohci_hcd),
221	/*
222	 * basic lifecycle operations
223	 */
224	.start = ohci_nxp_start,
225	.stop = ohci_stop,
226	.shutdown = ohci_shutdown,
227
228	/*
229	 * managing i/o requests and associated device resources
230	 */
231	.urb_enqueue = ohci_urb_enqueue,
232	.urb_dequeue = ohci_urb_dequeue,
233	.endpoint_disable = ohci_endpoint_disable,
234
235	/*
236	 * scheduling support
237	 */
238	.get_frame_number = ohci_get_frame,
239
240	/*
241	 * root hub support
242	 */
243	.hub_status_data = ohci_hub_status_data,
244	.hub_control = ohci_hub_control,
245#ifdef	CONFIG_PM
246	.bus_suspend = ohci_bus_suspend,
247	.bus_resume = ohci_bus_resume,
248#endif
249	.start_port_reset = ohci_start_port_reset,
250};
251
252#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
 
253
254static void nxp_set_usb_bits(void)
255{
256	if (machine_is_pnx4008()) {
257		start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
258		start_int_ack(SE_USB_OTG_ATX_INT_N);
259		start_int_umask(SE_USB_OTG_ATX_INT_N);
260
261		start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
262		start_int_ack(SE_USB_OTG_TIMER_INT);
263		start_int_umask(SE_USB_OTG_TIMER_INT);
264
265		start_int_set_rising_edge(SE_USB_I2C_INT);
266		start_int_ack(SE_USB_I2C_INT);
267		start_int_umask(SE_USB_I2C_INT);
268
269		start_int_set_rising_edge(SE_USB_INT);
270		start_int_ack(SE_USB_INT);
271		start_int_umask(SE_USB_INT);
272
273		start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
274		start_int_ack(SE_USB_NEED_CLK_INT);
275		start_int_umask(SE_USB_NEED_CLK_INT);
276
277		start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
278		start_int_ack(SE_USB_AHB_NEED_CLK_INT);
279		start_int_umask(SE_USB_AHB_NEED_CLK_INT);
280	}
281}
282
283static void nxp_unset_usb_bits(void)
284{
285	if (machine_is_pnx4008()) {
286		start_int_mask(SE_USB_OTG_ATX_INT_N);
287		start_int_mask(SE_USB_OTG_TIMER_INT);
288		start_int_mask(SE_USB_I2C_INT);
289		start_int_mask(SE_USB_INT);
290		start_int_mask(SE_USB_NEED_CLK_INT);
291		start_int_mask(SE_USB_AHB_NEED_CLK_INT);
292	}
293}
294
295static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
296{
297	struct usb_hcd *hcd = 0;
298	struct ohci_hcd *ohci;
299	const struct hc_driver *driver = &ohci_nxp_hc_driver;
300	struct resource *res;
301	int ret = 0, irq;
302	struct device_node *isp1301_node;
303
304	if (pdev->dev.of_node) {
305		isp1301_node = of_parse_phandle(pdev->dev.of_node,
306						"transceiver", 0);
307	} else {
308		isp1301_node = NULL;
309	}
310
311	isp1301_i2c_client = isp1301_get_client(isp1301_node);
312	if (!isp1301_i2c_client) {
313		ret = -EPROBE_DEFER;
314		goto out;
315	}
316
317	pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
318	pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
319
320	dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
321	if (usb_disabled()) {
322		dev_err(&pdev->dev, "USB is disabled\n");
323		ret = -ENODEV;
324		goto out;
325	}
326
327	/* Enable AHB slave USB clock, needed for further USB clock control */
328	__raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
329
330	isp1301_configure();
331
332	/* Enable USB PLL */
333	usb_clk = clk_get(&pdev->dev, "ck_pll5");
334	if (IS_ERR(usb_clk)) {
335		dev_err(&pdev->dev, "failed to acquire USB PLL\n");
336		ret = PTR_ERR(usb_clk);
337		goto out1;
338	}
339
340	ret = clk_enable(usb_clk);
341	if (ret < 0) {
342		dev_err(&pdev->dev, "failed to start USB PLL\n");
343		goto out2;
344	}
345
346	ret = clk_set_rate(usb_clk, 48000);
347	if (ret < 0) {
348		dev_err(&pdev->dev, "failed to set USB clock rate\n");
349		goto out3;
350	}
351
352	__raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
353
354	/* Set to enable all needed USB clocks */
355	__raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
356
357	while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
358	       USB_CLOCK_MASK) ;
359
360	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
361	if (!hcd) {
362		dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
363		ret = -ENOMEM;
364		goto out3;
365	}
366
367	/* Set all USB bits in the Start Enable register */
368	nxp_set_usb_bits();
369
370	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
371	if (!res) {
372		dev_err(&pdev->dev, "Failed to get MEM resource\n");
373		ret =  -ENOMEM;
374		goto out4;
375	}
376
377	hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
378	if (!hcd->regs) {
379		dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
380		ret =  -ENOMEM;
381		goto out4;
382	}
383	hcd->rsrc_start = res->start;
384	hcd->rsrc_len = resource_size(res);
385
386	irq = platform_get_irq(pdev, 0);
387	if (irq < 0) {
388		ret = -ENXIO;
389		goto out4;
390	}
391
392	nxp_start_hc();
393	platform_set_drvdata(pdev, hcd);
394	ohci = hcd_to_ohci(hcd);
395	ohci_hcd_init(ohci);
396
397	dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
398	ret = usb_add_hcd(hcd, irq, 0);
399	if (ret == 0)
 
400		return ret;
 
401
402	nxp_stop_hc();
403out4:
404	nxp_unset_usb_bits();
405	usb_put_hcd(hcd);
406out3:
407	clk_disable(usb_clk);
408out2:
409	clk_put(usb_clk);
410out1:
411	isp1301_i2c_client = NULL;
412out:
413	return ret;
414}
415
416static int usb_hcd_nxp_remove(struct platform_device *pdev)
417{
418	struct usb_hcd *hcd = platform_get_drvdata(pdev);
419
420	usb_remove_hcd(hcd);
421	nxp_stop_hc();
422	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
423	usb_put_hcd(hcd);
424	nxp_unset_usb_bits();
425	clk_disable(usb_clk);
426	clk_put(usb_clk);
427	i2c_unregister_device(isp1301_i2c_client);
428	isp1301_i2c_client = NULL;
429
430	platform_set_drvdata(pdev, NULL);
431
432	return 0;
433}
434
435/* work with hotplug and coldplug */
436MODULE_ALIAS("platform:usb-ohci");
437
438#ifdef CONFIG_OF
439static const struct of_device_id usb_hcd_nxp_match[] = {
440	{ .compatible = "nxp,ohci-nxp" },
441	{},
442};
443MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
444#endif
445
446static struct platform_driver usb_hcd_nxp_driver = {
447	.driver = {
448		.name = "usb-ohci",
449		.owner	= THIS_MODULE,
450		.of_match_table = of_match_ptr(usb_hcd_nxp_match),
451	},
452	.probe = usb_hcd_nxp_probe,
453	.remove = usb_hcd_nxp_remove,
454};
455