1 // SPDX-License-Identifier: GPL-2.0-only
3 * tusb1210.c - TUSB1210 USB ULPI PHY driver
5 * Copyright (C) 2015 Intel Corporation
7 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
9 #include <linux/module.h>
10 #include <linux/ulpi/driver.h>
11 #include <linux/ulpi/regs.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/phy/ulpi_phy.h>
15 #define TUSB1210_VENDOR_SPECIFIC2 0x80
16 #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0
17 #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
18 #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6
23 struct gpio_desc
*gpio_reset
;
24 struct gpio_desc
*gpio_cs
;
28 static int tusb1210_power_on(struct phy
*phy
)
30 struct tusb1210
*tusb
= phy_get_drvdata(phy
);
32 gpiod_set_value_cansleep(tusb
->gpio_reset
, 1);
33 gpiod_set_value_cansleep(tusb
->gpio_cs
, 1);
35 /* Restore the optional eye diagram optimization value */
36 if (tusb
->vendor_specific2
)
37 ulpi_write(tusb
->ulpi
, TUSB1210_VENDOR_SPECIFIC2
,
38 tusb
->vendor_specific2
);
43 static int tusb1210_power_off(struct phy
*phy
)
45 struct tusb1210
*tusb
= phy_get_drvdata(phy
);
47 gpiod_set_value_cansleep(tusb
->gpio_reset
, 0);
48 gpiod_set_value_cansleep(tusb
->gpio_cs
, 0);
53 static int tusb1210_set_mode(struct phy
*phy
, enum phy_mode mode
, int submode
)
55 struct tusb1210
*tusb
= phy_get_drvdata(phy
);
58 ret
= ulpi_read(tusb
->ulpi
, ULPI_OTG_CTRL
);
63 case PHY_MODE_USB_HOST
:
64 ret
|= (ULPI_OTG_CTRL_DRVVBUS_EXT
65 | ULPI_OTG_CTRL_ID_PULLUP
66 | ULPI_OTG_CTRL_DP_PULLDOWN
67 | ULPI_OTG_CTRL_DM_PULLDOWN
);
68 ulpi_write(tusb
->ulpi
, ULPI_OTG_CTRL
, ret
);
69 ret
|= ULPI_OTG_CTRL_DRVVBUS
;
71 case PHY_MODE_USB_DEVICE
:
72 ret
&= ~(ULPI_OTG_CTRL_DRVVBUS
73 | ULPI_OTG_CTRL_DP_PULLDOWN
74 | ULPI_OTG_CTRL_DM_PULLDOWN
);
75 ulpi_write(tusb
->ulpi
, ULPI_OTG_CTRL
, ret
);
76 ret
&= ~ULPI_OTG_CTRL_DRVVBUS_EXT
;
83 return ulpi_write(tusb
->ulpi
, ULPI_OTG_CTRL
, ret
);
86 static const struct phy_ops phy_ops
= {
87 .power_on
= tusb1210_power_on
,
88 .power_off
= tusb1210_power_off
,
89 .set_mode
= tusb1210_set_mode
,
93 static int tusb1210_probe(struct ulpi
*ulpi
)
95 struct tusb1210
*tusb
;
98 tusb
= devm_kzalloc(&ulpi
->dev
, sizeof(*tusb
), GFP_KERNEL
);
102 tusb
->gpio_reset
= devm_gpiod_get_optional(&ulpi
->dev
, "reset",
104 if (IS_ERR(tusb
->gpio_reset
))
105 return PTR_ERR(tusb
->gpio_reset
);
107 gpiod_set_value_cansleep(tusb
->gpio_reset
, 1);
109 tusb
->gpio_cs
= devm_gpiod_get_optional(&ulpi
->dev
, "cs",
111 if (IS_ERR(tusb
->gpio_cs
))
112 return PTR_ERR(tusb
->gpio_cs
);
114 gpiod_set_value_cansleep(tusb
->gpio_cs
, 1);
117 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
118 * diagram optimization and DP/DM swap.
121 /* High speed output drive strength configuration */
122 device_property_read_u8(&ulpi
->dev
, "ihstx", &val
);
123 reg
= val
<< TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT
;
125 /* High speed output impedance configuration */
126 device_property_read_u8(&ulpi
->dev
, "zhsdrv", &val
);
127 reg
|= val
<< TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT
;
129 /* DP/DM swap control */
130 device_property_read_u8(&ulpi
->dev
, "datapolarity", &val
);
131 reg
|= val
<< TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT
;
134 ulpi_write(ulpi
, TUSB1210_VENDOR_SPECIFIC2
, reg
);
135 tusb
->vendor_specific2
= reg
;
138 tusb
->phy
= ulpi_phy_create(ulpi
, &phy_ops
);
139 if (IS_ERR(tusb
->phy
))
140 return PTR_ERR(tusb
->phy
);
144 phy_set_drvdata(tusb
->phy
, tusb
);
145 ulpi_set_drvdata(ulpi
, tusb
);
149 static void tusb1210_remove(struct ulpi
*ulpi
)
151 struct tusb1210
*tusb
= ulpi_get_drvdata(ulpi
);
153 ulpi_phy_destroy(ulpi
, tusb
->phy
);
156 #define TI_VENDOR_ID 0x0451
158 static const struct ulpi_device_id tusb1210_ulpi_id
[] = {
159 { TI_VENDOR_ID
, 0x1507, }, /* TUSB1210 */
160 { TI_VENDOR_ID
, 0x1508, }, /* TUSB1211 */
163 MODULE_DEVICE_TABLE(ulpi
, tusb1210_ulpi_id
);
165 static struct ulpi_driver tusb1210_driver
= {
166 .id_table
= tusb1210_ulpi_id
,
167 .probe
= tusb1210_probe
,
168 .remove
= tusb1210_remove
,
171 .owner
= THIS_MODULE
,
175 module_ulpi_driver(tusb1210_driver
);
177 MODULE_AUTHOR("Intel Corporation");
178 MODULE_LICENSE("GPL v2");
179 MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");