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 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 gpio_desc *gpio;
65 struct tusb1210 *tusb;
69 tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
73 gpio = devm_gpiod_get(&ulpi->dev, "reset");
75 ret = gpiod_direction_output(gpio, 0);
78 gpiod_set_value_cansleep(gpio, 1);
79 tusb->gpio_reset = gpio;
82 gpio = devm_gpiod_get(&ulpi->dev, "cs");
84 ret = gpiod_direction_output(gpio, 0);
87 gpiod_set_value_cansleep(gpio, 1);
92 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
93 * diagram optimization and DP/DM swap.
96 /* High speed output drive strength configuration */
97 device_property_read_u8(&ulpi->dev, "ihstx", &val);
98 reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT;
100 /* High speed output impedance configuration */
101 device_property_read_u8(&ulpi->dev, "zhsdrv", &val);
102 reg |= val << TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT;
104 /* DP/DM swap control */
105 device_property_read_u8(&ulpi->dev, "datapolarity", &val);
106 reg |= val << TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT;
109 ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg);
110 tusb->vendor_specific2 = reg;
113 tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
114 if (IS_ERR(tusb->phy))
115 return PTR_ERR(tusb->phy);
119 phy_set_drvdata(tusb->phy, tusb);
120 ulpi_set_drvdata(ulpi, tusb);
124 static void tusb1210_remove(struct ulpi *ulpi)
126 struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
128 ulpi_phy_destroy(ulpi, tusb->phy);
131 #define TI_VENDOR_ID 0x0451
133 static const struct ulpi_device_id tusb1210_ulpi_id[] = {
134 { TI_VENDOR_ID, 0x1507, },
137 MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
139 static struct ulpi_driver tusb1210_driver = {
140 .id_table = tusb1210_ulpi_id,
141 .probe = tusb1210_probe,
142 .remove = tusb1210_remove,
145 .owner = THIS_MODULE,
149 module_ulpi_driver(tusb1210_driver);
151 MODULE_AUTHOR("Intel Corporation");
152 MODULE_LICENSE("GPL v2");
153 MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");