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"
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
[] = {
34 MODULE_DEVICE_TABLE(i2c
, isp1301_id
);
36 static const struct of_device_id isp1301_of_match
[] = {
37 {.compatible
= "nxp,isp1301" },
40 MODULE_DEVICE_TABLE(of
, isp1301_of_match
);
42 static struct i2c_client
*isp1301_i2c_client
;
44 static int __isp1301_write(struct isp1301
*isp
, u8 reg
, u8 value
, u8 clear
)
46 return i2c_smbus_write_byte_data(isp
->client
, reg
| clear
, value
);
49 static int isp1301_write(struct isp1301
*isp
, u8 reg
, u8 value
)
51 return __isp1301_write(isp
, reg
, value
, 0);
54 static int isp1301_clear(struct isp1301
*isp
, u8 reg
, u8 value
)
56 return __isp1301_write(isp
, reg
, value
, ISP1301_I2C_REG_CLEAR_ADDR
);
59 static int isp1301_phy_init(struct usb_phy
*phy
)
61 struct isp1301
*isp
= phy_to_isp(phy
);
63 /* Disable transparent UART mode first */
64 isp1301_clear(isp
, ISP1301_I2C_MODE_CONTROL_1
, MC1_UART_EN
);
65 isp1301_clear(isp
, ISP1301_I2C_MODE_CONTROL_1
, ~MC1_SPEED_REG
);
66 isp1301_write(isp
, ISP1301_I2C_MODE_CONTROL_1
, MC1_SPEED_REG
);
67 isp1301_clear(isp
, ISP1301_I2C_MODE_CONTROL_2
, ~0);
68 isp1301_write(isp
, ISP1301_I2C_MODE_CONTROL_2
, (MC2_BI_DI
| MC2_PSW_EN
69 | MC2_SPD_SUSP_CTRL
));
71 isp1301_clear(isp
, ISP1301_I2C_OTG_CONTROL_1
, ~0);
72 isp1301_write(isp
, ISP1301_I2C_MODE_CONTROL_1
, MC1_DAT_SE0
);
73 isp1301_write(isp
, ISP1301_I2C_OTG_CONTROL_1
, (OTG1_DM_PULLDOWN
75 isp1301_clear(isp
, ISP1301_I2C_OTG_CONTROL_1
, (OTG1_DM_PULLUP
78 /* mask all interrupts */
79 isp1301_clear(isp
, ISP1301_I2C_INTERRUPT_LATCH
, ~0);
80 isp1301_clear(isp
, ISP1301_I2C_INTERRUPT_FALLING
, ~0);
81 isp1301_clear(isp
, ISP1301_I2C_INTERRUPT_RISING
, ~0);
86 static int isp1301_phy_set_vbus(struct usb_phy
*phy
, int on
)
88 struct isp1301
*isp
= phy_to_isp(phy
);
91 isp1301_write(isp
, ISP1301_I2C_OTG_CONTROL_1
, OTG1_VBUS_DRV
);
93 isp1301_clear(isp
, ISP1301_I2C_OTG_CONTROL_1
, OTG1_VBUS_DRV
);
98 static int isp1301_probe(struct i2c_client
*client
,
99 const struct i2c_device_id
*i2c_id
)
104 isp
= devm_kzalloc(&client
->dev
, sizeof(*isp
), GFP_KERNEL
);
108 isp
->client
= client
;
109 mutex_init(&isp
->mutex
);
112 phy
->dev
= &client
->dev
;
113 phy
->label
= DRV_NAME
;
114 phy
->init
= isp1301_phy_init
;
115 phy
->set_vbus
= isp1301_phy_set_vbus
;
116 phy
->type
= USB_PHY_TYPE_USB2
;
118 i2c_set_clientdata(client
, isp
);
119 usb_add_phy_dev(phy
);
121 isp1301_i2c_client
= client
;
126 static int isp1301_remove(struct i2c_client
*client
)
128 struct isp1301
*isp
= i2c_get_clientdata(client
);
130 usb_remove_phy(&isp
->phy
);
131 isp1301_i2c_client
= NULL
;
136 static struct i2c_driver isp1301_driver
= {
139 .of_match_table
= of_match_ptr(isp1301_of_match
),
141 .probe
= isp1301_probe
,
142 .remove
= isp1301_remove
,
143 .id_table
= isp1301_id
,
146 module_i2c_driver(isp1301_driver
);
148 static int match(struct device
*dev
, void *data
)
150 struct device_node
*node
= (struct device_node
*)data
;
151 return (dev
->of_node
== node
) &&
152 (dev
->driver
== &isp1301_driver
.driver
);
155 struct i2c_client
*isp1301_get_client(struct device_node
*node
)
157 if (node
) { /* reference of ISP1301 I2C node via DT */
158 struct device
*dev
= bus_find_device(&i2c_bus_type
, NULL
,
162 return to_i2c_client(dev
);
163 } else { /* non-DT: only one ISP1301 chip supported */
164 return isp1301_i2c_client
;
167 EXPORT_SYMBOL_GPL(isp1301_get_client
);
169 MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
170 MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
171 MODULE_LICENSE("GPL");