1 From 5c627d8e7660c170c591ef281184fd11d0493440 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Fri, 11 Dec 2015 16:32:17 +0100
4 Subject: [PATCH] phy-sun4i-usb: Use of_match_node to get model specific config
7 Use of_match_node instead of calling of_device_is_compatible a ton of
8 times to get model specific config data.
10 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
11 Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
13 drivers/phy/phy-sun4i-usb.c | 121 +++++++++++++++++++++++++++++---------------
14 1 file changed, 79 insertions(+), 42 deletions(-)
16 --- a/drivers/phy/phy-sun4i-usb.c
17 +++ b/drivers/phy/phy-sun4i-usb.c
19 #include <linux/mutex.h>
21 #include <linux/of_address.h>
22 +#include <linux/of_device.h>
23 #include <linux/of_gpio.h>
24 #include <linux/phy/phy.h>
25 #include <linux/phy/phy-sun4i-usb.h>
27 #define DEBOUNCE_TIME msecs_to_jiffies(50)
28 #define POLL_TIME msecs_to_jiffies(250)
30 +enum sun4i_usb_phy_type {
35 +struct sun4i_usb_phy_cfg {
37 + enum sun4i_usb_phy_type type;
40 + bool dedicated_clocks;
43 struct sun4i_usb_phy_data {
45 + const struct sun4i_usb_phy_cfg *cfg;
49 - bool has_a33_phyctl;
50 struct sun4i_usb_phy {
53 @@ -159,17 +171,14 @@ static void sun4i_usb_phy_write(struct s
55 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
56 u32 temp, usbc_bit = BIT(phy->index * 2);
58 + void *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
61 mutex_lock(&phy_data->mutex);
63 - if (phy_data->has_a33_phyctl) {
64 - phyctl = phy_data->base + REG_PHYCTL_A33;
65 + if (phy_data->cfg->type == sun8i_a33_phy) {
66 /* A33 needs us to set phyctl to 0 explicitly */
69 - phyctl = phy_data->base + REG_PHYCTL_A10;
72 for (i = 0; i < len; i++) {
73 @@ -249,7 +258,8 @@ static int sun4i_usb_phy_init(struct phy
74 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
76 /* Disconnect threshold adjustment */
77 - sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2);
78 + sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
79 + data->cfg->disc_thresh, 2);
81 sun4i_usb_phy_passby(phy, 1);
83 @@ -476,7 +486,7 @@ static struct phy *sun4i_usb_phy_xlate(s
85 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
87 - if (args->args[0] >= data->num_phys)
88 + if (args->args[0] >= data->cfg->num_phys)
89 return ERR_PTR(-ENODEV);
91 return data->phys[args->args[0]].phy;
92 @@ -511,7 +521,6 @@ static int sun4i_usb_phy_probe(struct pl
93 struct device *dev = &pdev->dev;
94 struct device_node *np = dev->of_node;
95 struct phy_provider *phy_provider;
96 - bool dedicated_clocks;
100 @@ -522,29 +531,9 @@ static int sun4i_usb_phy_probe(struct pl
101 mutex_init(&data->mutex);
102 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
103 dev_set_drvdata(dev, data);
105 - if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
106 - of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
107 - of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
108 - data->num_phys = 2;
110 - data->num_phys = 3;
112 - if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
113 - of_device_is_compatible(np, "allwinner,sun7i-a20-usb-phy"))
114 - data->disc_thresh = 2;
116 - data->disc_thresh = 3;
118 - if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") ||
119 - of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
120 - of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
121 - dedicated_clocks = true;
123 - dedicated_clocks = false;
125 - if (of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
126 - data->has_a33_phyctl = true;
127 + data->cfg = of_device_get_match_data(dev);
131 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
132 data->base = devm_ioremap_resource(dev, res);
133 @@ -590,7 +579,7 @@ static int sun4i_usb_phy_probe(struct pl
137 - for (i = 0; i < data->num_phys; i++) {
138 + for (i = 0; i < data->cfg->num_phys; i++) {
139 struct sun4i_usb_phy *phy = data->phys + i;
142 @@ -602,7 +591,7 @@ static int sun4i_usb_phy_probe(struct pl
146 - if (dedicated_clocks)
147 + if (data->cfg->dedicated_clocks)
148 snprintf(name, sizeof(name), "usb%d_phy", i);
150 strlcpy(name, "usb_phy", sizeof(name));
151 @@ -689,13 +678,61 @@ static int sun4i_usb_phy_probe(struct pl
155 +static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
157 + .type = sun4i_a10_phy,
159 + .phyctl_offset = REG_PHYCTL_A10,
160 + .dedicated_clocks = false,
163 +static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
165 + .type = sun4i_a10_phy,
167 + .phyctl_offset = REG_PHYCTL_A10,
168 + .dedicated_clocks = false,
171 +static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
173 + .type = sun4i_a10_phy,
175 + .phyctl_offset = REG_PHYCTL_A10,
176 + .dedicated_clocks = true,
179 +static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
181 + .type = sun4i_a10_phy,
183 + .phyctl_offset = REG_PHYCTL_A10,
184 + .dedicated_clocks = false,
187 +static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
189 + .type = sun4i_a10_phy,
191 + .phyctl_offset = REG_PHYCTL_A10,
192 + .dedicated_clocks = true,
195 +static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
197 + .type = sun8i_a33_phy,
199 + .phyctl_offset = REG_PHYCTL_A33,
200 + .dedicated_clocks = true,
203 static const struct of_device_id sun4i_usb_phy_of_match[] = {
204 - { .compatible = "allwinner,sun4i-a10-usb-phy" },
205 - { .compatible = "allwinner,sun5i-a13-usb-phy" },
206 - { .compatible = "allwinner,sun6i-a31-usb-phy" },
207 - { .compatible = "allwinner,sun7i-a20-usb-phy" },
208 - { .compatible = "allwinner,sun8i-a23-usb-phy" },
209 - { .compatible = "allwinner,sun8i-a33-usb-phy" },
210 + { .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg },
211 + { .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg },
212 + { .compatible = "allwinner,sun6i-a31-usb-phy", .data = &sun6i_a31_cfg },
213 + { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg },
214 + { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
215 + { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
218 MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);