blob: bb3fb031c478da13fc070c49701b926b7dc1ed17 [file] [log] [blame]
Heikki Krogerus1c149052015-05-13 15:26:53 +03001/**
2 * tusb1210.c - TUSB1210 USB ULPI PHY driver
3 *
4 * Copyright (C) 2015 Intel Corporation
5 *
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
7 *
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.
11 */
12#include <linux/module.h>
13#include <linux/ulpi/driver.h>
14#include <linux/gpio/consumer.h>
Vivek Gautam858edde2017-05-11 12:17:41 +053015#include <linux/phy/ulpi_phy.h>
Heikki Krogerus1c149052015-05-13 15:26:53 +030016
17#define TUSB1210_VENDOR_SPECIFIC2 0x80
18#define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0
19#define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
20#define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6
21
22struct tusb1210 {
23 struct ulpi *ulpi;
24 struct phy *phy;
25 struct gpio_desc *gpio_reset;
26 struct gpio_desc *gpio_cs;
27 u8 vendor_specific2;
28};
29
30static int tusb1210_power_on(struct phy *phy)
31{
32 struct tusb1210 *tusb = phy_get_drvdata(phy);
33
34 gpiod_set_value_cansleep(tusb->gpio_reset, 1);
35 gpiod_set_value_cansleep(tusb->gpio_cs, 1);
36
37 /* Restore the optional eye diagram optimization value */
38 if (tusb->vendor_specific2)
39 ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
40 tusb->vendor_specific2);
41
42 return 0;
43}
44
45static int tusb1210_power_off(struct phy *phy)
46{
47 struct tusb1210 *tusb = phy_get_drvdata(phy);
48
49 gpiod_set_value_cansleep(tusb->gpio_reset, 0);
50 gpiod_set_value_cansleep(tusb->gpio_cs, 0);
51
52 return 0;
53}
54
Axel Lin4a9e5ca2015-07-15 15:33:51 +080055static const struct phy_ops phy_ops = {
Heikki Krogerus1c149052015-05-13 15:26:53 +030056 .power_on = tusb1210_power_on,
57 .power_off = tusb1210_power_off,
58 .owner = THIS_MODULE,
59};
60
61static int tusb1210_probe(struct ulpi *ulpi)
62{
Heikki Krogerus1c149052015-05-13 15:26:53 +030063 struct tusb1210 *tusb;
64 u8 val, reg;
Heikki Krogerus1c149052015-05-13 15:26:53 +030065
66 tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
67 if (!tusb)
68 return -ENOMEM;
69
Uwe Kleine-König8e71c682015-06-12 08:55:30 +020070 tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset",
71 GPIOD_OUT_LOW);
72 if (IS_ERR(tusb->gpio_reset))
73 return PTR_ERR(tusb->gpio_reset);
Heikki Krogerus1c149052015-05-13 15:26:53 +030074
Uwe Kleine-König8e71c682015-06-12 08:55:30 +020075 gpiod_set_value_cansleep(tusb->gpio_reset, 1);
76
77 tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs",
78 GPIOD_OUT_LOW);
79 if (IS_ERR(tusb->gpio_cs))
80 return PTR_ERR(tusb->gpio_cs);
81
82 gpiod_set_value_cansleep(tusb->gpio_cs, 1);
Heikki Krogerus1c149052015-05-13 15:26:53 +030083
84 /*
85 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
86 * diagram optimization and DP/DM swap.
87 */
88
89 /* High speed output drive strength configuration */
90 device_property_read_u8(&ulpi->dev, "ihstx", &val);
91 reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT;
92
93 /* High speed output impedance configuration */
94 device_property_read_u8(&ulpi->dev, "zhsdrv", &val);
95 reg |= val << TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT;
96
97 /* DP/DM swap control */
98 device_property_read_u8(&ulpi->dev, "datapolarity", &val);
99 reg |= val << TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT;
100
101 if (reg) {
102 ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg);
103 tusb->vendor_specific2 = reg;
104 }
105
106 tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
107 if (IS_ERR(tusb->phy))
108 return PTR_ERR(tusb->phy);
109
110 tusb->ulpi = ulpi;
111
112 phy_set_drvdata(tusb->phy, tusb);
113 ulpi_set_drvdata(ulpi, tusb);
114 return 0;
115}
116
117static void tusb1210_remove(struct ulpi *ulpi)
118{
119 struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
120
121 ulpi_phy_destroy(ulpi, tusb->phy);
122}
123
124#define TI_VENDOR_ID 0x0451
125
126static const struct ulpi_device_id tusb1210_ulpi_id[] = {
127 { TI_VENDOR_ID, 0x1507, },
128 { },
129};
130MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
131
132static struct ulpi_driver tusb1210_driver = {
133 .id_table = tusb1210_ulpi_id,
134 .probe = tusb1210_probe,
135 .remove = tusb1210_remove,
136 .driver = {
137 .name = "tusb1210",
138 .owner = THIS_MODULE,
139 },
140};
141
142module_ulpi_driver(tusb1210_driver);
143
144MODULE_AUTHOR("Intel Corporation");
145MODULE_LICENSE("GPL v2");
146MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");