diff options
author | Robert Jarzmik <robert.jarzmik@free.fr> | 2014-12-06 16:05:13 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2015-01-12 13:13:29 -0500 |
commit | e9f2cefb0cdc2aea8b70dbf68a3f78b88e57cf34 (patch) | |
tree | 68ed0c31987ffa61c5e86045683c357c5570d7f9 | |
parent | e3a912a124c380db61eff762faa0547ea4c90eb4 (diff) |
usb: phy: generic: migrate to gpio_desc
Change internal gpio handling from integer gpios into gpio
descriptors. This change only addresses the internal API and
device-tree/ACPI, while the legacy platform data remains integer space
based.
This change is only build compile tested, and very prone to error. I
leave this comment for now in the commit message so that this patch gets
some testing as I'm pretty sure it's buggy.
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/phy/phy-generic.c | 61 | ||||
-rw-r--r-- | drivers/usb/phy/phy-generic.h | 4 |
2 files changed, 21 insertions, 44 deletions
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index f1b719b45a53..d53928f3a6ea 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c | |||
@@ -59,16 +59,8 @@ static int nop_set_suspend(struct usb_phy *x, int suspend) | |||
59 | 59 | ||
60 | static void nop_reset_set(struct usb_phy_generic *nop, int asserted) | 60 | static void nop_reset_set(struct usb_phy_generic *nop, int asserted) |
61 | { | 61 | { |
62 | int value; | 62 | if (nop->gpiod_reset) |
63 | 63 | gpiod_set_value(nop->gpiod_reset, asserted); | |
64 | if (!gpio_is_valid(nop->gpio_reset)) | ||
65 | return; | ||
66 | |||
67 | value = asserted; | ||
68 | if (nop->reset_active_low) | ||
69 | value = !value; | ||
70 | |||
71 | gpio_set_value_cansleep(nop->gpio_reset, value); | ||
72 | 64 | ||
73 | if (!asserted) | 65 | if (!asserted) |
74 | usleep_range(10000, 20000); | 66 | usleep_range(10000, 20000); |
@@ -143,35 +135,38 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, | |||
143 | struct usb_phy_generic_platform_data *pdata) | 135 | struct usb_phy_generic_platform_data *pdata) |
144 | { | 136 | { |
145 | enum usb_phy_type type = USB_PHY_TYPE_USB2; | 137 | enum usb_phy_type type = USB_PHY_TYPE_USB2; |
146 | int err; | 138 | int err = 0; |
147 | 139 | ||
148 | u32 clk_rate = 0; | 140 | u32 clk_rate = 0; |
149 | bool needs_vcc = false; | 141 | bool needs_vcc = false; |
150 | 142 | ||
151 | nop->reset_active_low = true; /* default behaviour */ | ||
152 | |||
153 | if (dev->of_node) { | 143 | if (dev->of_node) { |
154 | struct device_node *node = dev->of_node; | 144 | struct device_node *node = dev->of_node; |
155 | enum of_gpio_flags flags = 0; | ||
156 | 145 | ||
157 | if (of_property_read_u32(node, "clock-frequency", &clk_rate)) | 146 | if (of_property_read_u32(node, "clock-frequency", &clk_rate)) |
158 | clk_rate = 0; | 147 | clk_rate = 0; |
159 | 148 | ||
160 | needs_vcc = of_property_read_bool(node, "vcc-supply"); | 149 | needs_vcc = of_property_read_bool(node, "vcc-supply"); |
161 | nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios", | 150 | nop->gpiod_reset = devm_gpiod_get(dev, "reset-gpios"); |
162 | 0, &flags); | 151 | err = PTR_ERR(nop->gpiod_reset); |
163 | if (nop->gpio_reset == -EPROBE_DEFER) | ||
164 | return -EPROBE_DEFER; | ||
165 | |||
166 | nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW; | ||
167 | |||
168 | } else if (pdata) { | 152 | } else if (pdata) { |
169 | type = pdata->type; | 153 | type = pdata->type; |
170 | clk_rate = pdata->clk_rate; | 154 | clk_rate = pdata->clk_rate; |
171 | needs_vcc = pdata->needs_vcc; | 155 | needs_vcc = pdata->needs_vcc; |
172 | nop->gpio_reset = pdata->gpio_reset; | 156 | if (gpio_is_valid(gpio->gpio_reset)) { |
173 | } else { | 157 | err = devm_gpio_request_one(dev, pdata->gpio_reset, 0, |
174 | nop->gpio_reset = -1; | 158 | dev_name(dev)); |
159 | if (!err) | ||
160 | nop->gpiod_reset = | ||
161 | gpio_to_desc(pdata->gpio_reset); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | if (err == -EPROBE_DEFER) | ||
166 | return -EPROBE_DEFER; | ||
167 | if (err) { | ||
168 | dev_err(dev, "Error requesting RESET GPIO\n"); | ||
169 | return err; | ||
175 | } | 170 | } |
176 | 171 | ||
177 | nop->phy.otg = devm_kzalloc(dev, sizeof(*nop->phy.otg), | 172 | nop->phy.otg = devm_kzalloc(dev, sizeof(*nop->phy.otg), |
@@ -201,24 +196,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, | |||
201 | return -EPROBE_DEFER; | 196 | return -EPROBE_DEFER; |
202 | } | 197 | } |
203 | 198 | ||
204 | if (gpio_is_valid(nop->gpio_reset)) { | ||
205 | unsigned long gpio_flags; | ||
206 | |||
207 | /* Assert RESET */ | ||
208 | if (nop->reset_active_low) | ||
209 | gpio_flags = GPIOF_OUT_INIT_LOW; | ||
210 | else | ||
211 | gpio_flags = GPIOF_OUT_INIT_HIGH; | ||
212 | |||
213 | err = devm_gpio_request_one(dev, nop->gpio_reset, | ||
214 | gpio_flags, dev_name(dev)); | ||
215 | if (err) { | ||
216 | dev_err(dev, "Error requesting RESET GPIO %d\n", | ||
217 | nop->gpio_reset); | ||
218 | return err; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | nop->dev = dev; | 199 | nop->dev = dev; |
223 | nop->phy.dev = nop->dev; | 200 | nop->phy.dev = nop->dev; |
224 | nop->phy.label = "nop-xceiv"; | 201 | nop->phy.label = "nop-xceiv"; |
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h index d8feacc0b7fb..09924fdaaabe 100644 --- a/drivers/usb/phy/phy-generic.h +++ b/drivers/usb/phy/phy-generic.h | |||
@@ -2,14 +2,14 @@ | |||
2 | #define _PHY_GENERIC_H_ | 2 | #define _PHY_GENERIC_H_ |
3 | 3 | ||
4 | #include <linux/usb/usb_phy_generic.h> | 4 | #include <linux/usb/usb_phy_generic.h> |
5 | #include <linux/gpio/consumer.h> | ||
5 | 6 | ||
6 | struct usb_phy_generic { | 7 | struct usb_phy_generic { |
7 | struct usb_phy phy; | 8 | struct usb_phy phy; |
8 | struct device *dev; | 9 | struct device *dev; |
9 | struct clk *clk; | 10 | struct clk *clk; |
10 | struct regulator *vcc; | 11 | struct regulator *vcc; |
11 | int gpio_reset; | 12 | struct gpio_desc *gpiod_reset; |
12 | bool reset_active_low; | ||
13 | }; | 13 | }; |
14 | 14 | ||
15 | int usb_gen_phy_init(struct usb_phy *phy); | 15 | int usb_gen_phy_init(struct usb_phy *phy); |