2 * tusb1210.c - TUSB1210 USB ULPI PHY driver
4 * Copyright (C) 2015 Intel Corporation
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
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.
12 #include <linux/module.h>
13 #include <linux/ulpi/driver.h>
14 #include <linux/gpio/consumer.h>
18 #define TUSB1210_VENDOR_SPECIFIC2 0x80
19 #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0
20 #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
21 #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6
26 struct gpio_desc
*gpio_reset
;
27 struct gpio_desc
*gpio_cs
;
31 static int tusb1210_power_on(struct phy
*phy
)
33 struct tusb1210
*tusb
= phy_get_drvdata(phy
);
35 gpiod_set_value_cansleep(tusb
->gpio_reset
, 1);
36 gpiod_set_value_cansleep(tusb
->gpio_cs
, 1);
38 /* Restore the optional eye diagram optimization value */
39 if (tusb
->vendor_specific2
)
40 ulpi_write(tusb
->ulpi
, TUSB1210_VENDOR_SPECIFIC2
,
41 tusb
->vendor_specific2
);
46 static int tusb1210_power_off(struct phy
*phy
)
48 struct tusb1210
*tusb
= phy_get_drvdata(phy
);
50 gpiod_set_value_cansleep(tusb
->gpio_reset
, 0);
51 gpiod_set_value_cansleep(tusb
->gpio_cs
, 0);
56 static const struct phy_ops phy_ops
= {
57 .power_on
= tusb1210_power_on
,
58 .power_off
= tusb1210_power_off
,
62 static int tusb1210_probe(struct ulpi
*ulpi
)
64 struct tusb1210
*tusb
;
67 tusb
= devm_kzalloc(&ulpi
->dev
, sizeof(*tusb
), GFP_KERNEL
);
71 tusb
->gpio_reset
= devm_gpiod_get_optional(&ulpi
->dev
, "reset",
73 if (IS_ERR(tusb
->gpio_reset
))
74 return PTR_ERR(tusb
->gpio_reset
);
76 gpiod_set_value_cansleep(tusb
->gpio_reset
, 1);
78 tusb
->gpio_cs
= devm_gpiod_get_optional(&ulpi
->dev
, "cs",
80 if (IS_ERR(tusb
->gpio_cs
))
81 return PTR_ERR(tusb
->gpio_cs
);
83 gpiod_set_value_cansleep(tusb
->gpio_cs
, 1);
86 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
87 * diagram optimization and DP/DM swap.
90 /* High speed output drive strength configuration */
91 device_property_read_u8(&ulpi
->dev
, "ihstx", &val
);
92 reg
= val
<< TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT
;
94 /* High speed output impedance configuration */
95 device_property_read_u8(&ulpi
->dev
, "zhsdrv", &val
);
96 reg
|= val
<< TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT
;
98 /* DP/DM swap control */
99 device_property_read_u8(&ulpi
->dev
, "datapolarity", &val
);
100 reg
|= val
<< TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT
;
103 ulpi_write(ulpi
, TUSB1210_VENDOR_SPECIFIC2
, reg
);
104 tusb
->vendor_specific2
= reg
;
107 tusb
->phy
= ulpi_phy_create(ulpi
, &phy_ops
);
108 if (IS_ERR(tusb
->phy
))
109 return PTR_ERR(tusb
->phy
);
113 phy_set_drvdata(tusb
->phy
, tusb
);
114 ulpi_set_drvdata(ulpi
, tusb
);
118 static void tusb1210_remove(struct ulpi
*ulpi
)
120 struct tusb1210
*tusb
= ulpi_get_drvdata(ulpi
);
122 ulpi_phy_destroy(ulpi
, tusb
->phy
);
125 #define TI_VENDOR_ID 0x0451
127 static const struct ulpi_device_id tusb1210_ulpi_id
[] = {
128 { TI_VENDOR_ID
, 0x1507, },
131 MODULE_DEVICE_TABLE(ulpi
, tusb1210_ulpi_id
);
133 static struct ulpi_driver tusb1210_driver
= {
134 .id_table
= tusb1210_ulpi_id
,
135 .probe
= tusb1210_probe
,
136 .remove
= tusb1210_remove
,
139 .owner
= THIS_MODULE
,
143 module_ulpi_driver(tusb1210_driver
);
145 MODULE_AUTHOR("Intel Corporation");
146 MODULE_LICENSE("GPL v2");
147 MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");