x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / usb / phy / phy-isp1301.c
blob8a55b37d1a024687f6be8078ef4f54f60cdc5111
1 /*
2 * NXP ISP1301 USB transceiver driver
4 * Copyright (C) 2012 Roland Stigge
6 * Author: Roland Stigge <stigge@antcom.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/mutex.h>
15 #include <linux/i2c.h>
16 #include <linux/usb/phy.h>
17 #include <linux/usb/isp1301.h>
19 #define DRV_NAME "isp1301"
21 struct isp1301 {
22 struct usb_phy phy;
23 struct mutex mutex;
25 struct i2c_client *client;
28 #define phy_to_isp(p) (container_of((p), struct isp1301, phy))
30 static const struct i2c_device_id isp1301_id[] = {
31 { "isp1301", 0 },
32 { }
35 static struct i2c_client *isp1301_i2c_client;
37 static int __isp1301_write(struct isp1301 *isp, u8 reg, u8 value, u8 clear)
39 return i2c_smbus_write_byte_data(isp->client, reg | clear, value);
42 static int isp1301_write(struct isp1301 *isp, u8 reg, u8 value)
44 return __isp1301_write(isp, reg, value, 0);
47 static int isp1301_clear(struct isp1301 *isp, u8 reg, u8 value)
49 return __isp1301_write(isp, reg, value, ISP1301_I2C_REG_CLEAR_ADDR);
52 static int isp1301_phy_init(struct usb_phy *phy)
54 struct isp1301 *isp = phy_to_isp(phy);
56 /* Disable transparent UART mode first */
57 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_UART_EN);
58 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, ~MC1_SPEED_REG);
59 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
60 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_2, ~0);
61 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_PSW_EN
62 | MC2_SPD_SUSP_CTRL));
64 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, ~0);
65 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
66 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLDOWN
67 | OTG1_DP_PULLDOWN));
68 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLUP
69 | OTG1_DP_PULLUP));
71 /* mask all interrupts */
72 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_LATCH, ~0);
73 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_FALLING, ~0);
74 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_RISING, ~0);
76 return 0;
79 static int isp1301_phy_set_vbus(struct usb_phy *phy, int on)
81 struct isp1301 *isp = phy_to_isp(phy);
83 if (on)
84 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
85 else
86 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
88 return 0;
91 static int isp1301_probe(struct i2c_client *client,
92 const struct i2c_device_id *i2c_id)
94 struct isp1301 *isp;
95 struct usb_phy *phy;
97 isp = devm_kzalloc(&client->dev, sizeof(*isp), GFP_KERNEL);
98 if (!isp)
99 return -ENOMEM;
101 isp->client = client;
102 mutex_init(&isp->mutex);
104 phy = &isp->phy;
105 phy->dev = &client->dev;
106 phy->label = DRV_NAME;
107 phy->init = isp1301_phy_init;
108 phy->set_vbus = isp1301_phy_set_vbus;
109 phy->type = USB_PHY_TYPE_USB2;
111 i2c_set_clientdata(client, isp);
112 usb_add_phy_dev(phy);
114 isp1301_i2c_client = client;
116 return 0;
119 static int isp1301_remove(struct i2c_client *client)
121 struct isp1301 *isp = i2c_get_clientdata(client);
123 usb_remove_phy(&isp->phy);
124 isp1301_i2c_client = NULL;
126 return 0;
129 static struct i2c_driver isp1301_driver = {
130 .driver = {
131 .name = DRV_NAME,
133 .probe = isp1301_probe,
134 .remove = isp1301_remove,
135 .id_table = isp1301_id,
138 module_i2c_driver(isp1301_driver);
140 static int match(struct device *dev, void *data)
142 struct device_node *node = (struct device_node *)data;
143 return (dev->of_node == node) &&
144 (dev->driver == &isp1301_driver.driver);
147 struct i2c_client *isp1301_get_client(struct device_node *node)
149 if (node) { /* reference of ISP1301 I2C node via DT */
150 struct device *dev = bus_find_device(&i2c_bus_type, NULL,
151 node, match);
152 if (!dev)
153 return NULL;
154 return to_i2c_client(dev);
155 } else { /* non-DT: only one ISP1301 chip supported */
156 return isp1301_i2c_client;
159 EXPORT_SYMBOL_GPL(isp1301_get_client);
161 MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
162 MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
163 MODULE_LICENSE("GPL");