1 // SPDX-License-Identifier: GPL-2.0
3 * NXP ISP1301 USB transceiver driver
5 * Copyright (C) 2012 Roland Stigge
7 * Author: Roland Stigge <stigge@antcom.de>
10 #include <linux/module.h>
11 #include <linux/mutex.h>
12 #include <linux/i2c.h>
13 #include <linux/usb/phy.h>
14 #include <linux/usb/isp1301.h>
16 #define DRV_NAME "isp1301"
22 struct i2c_client *client;
25 #define phy_to_isp(p) (container_of((p), struct isp1301, phy))
27 static const struct i2c_device_id isp1301_id[] = {
31 MODULE_DEVICE_TABLE(i2c, isp1301_id);
33 static const struct of_device_id isp1301_of_match[] = {
34 {.compatible = "nxp,isp1301" },
37 MODULE_DEVICE_TABLE(of, isp1301_of_match);
39 static struct i2c_client *isp1301_i2c_client;
41 static int __isp1301_write(struct isp1301 *isp, u8 reg, u8 value, u8 clear)
43 return i2c_smbus_write_byte_data(isp->client, reg | clear, value);
46 static int isp1301_write(struct isp1301 *isp, u8 reg, u8 value)
48 return __isp1301_write(isp, reg, value, 0);
51 static int isp1301_clear(struct isp1301 *isp, u8 reg, u8 value)
53 return __isp1301_write(isp, reg, value, ISP1301_I2C_REG_CLEAR_ADDR);
56 static int isp1301_phy_init(struct usb_phy *phy)
58 struct isp1301 *isp = phy_to_isp(phy);
60 /* Disable transparent UART mode first */
61 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_UART_EN);
62 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, ~MC1_SPEED_REG);
63 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
64 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_2, ~0);
65 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_PSW_EN
66 | MC2_SPD_SUSP_CTRL));
68 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, ~0);
69 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
70 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLDOWN
72 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLUP
75 /* mask all interrupts */
76 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_LATCH, ~0);
77 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_FALLING, ~0);
78 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_RISING, ~0);
83 static int isp1301_phy_set_vbus(struct usb_phy *phy, int on)
85 struct isp1301 *isp = phy_to_isp(phy);
88 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
90 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
95 static int isp1301_probe(struct i2c_client *client)
100 isp = devm_kzalloc(&client->dev, sizeof(*isp), GFP_KERNEL);
104 isp->client = client;
105 mutex_init(&isp->mutex);
108 phy->dev = &client->dev;
109 phy->label = DRV_NAME;
110 phy->init = isp1301_phy_init;
111 phy->set_vbus = isp1301_phy_set_vbus;
112 phy->type = USB_PHY_TYPE_USB2;
114 i2c_set_clientdata(client, isp);
115 usb_add_phy_dev(phy);
117 isp1301_i2c_client = client;
122 static void isp1301_remove(struct i2c_client *client)
124 struct isp1301 *isp = i2c_get_clientdata(client);
126 usb_remove_phy(&isp->phy);
127 isp1301_i2c_client = NULL;
130 static struct i2c_driver isp1301_driver = {
133 .of_match_table = isp1301_of_match,
135 .probe = isp1301_probe,
136 .remove = isp1301_remove,
137 .id_table = isp1301_id,
140 module_i2c_driver(isp1301_driver);
142 struct i2c_client *isp1301_get_client(struct device_node *node)
144 struct i2c_client *client;
146 /* reference of ISP1301 I2C node via DT */
147 client = of_find_i2c_device_by_node(node);
151 /* non-DT: only one ISP1301 chip supported */
152 return isp1301_i2c_client;
154 EXPORT_SYMBOL_GPL(isp1301_get_client);
156 MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
157 MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
158 MODULE_LICENSE("GPL");