.. | .. |
---|
13 | 13 | #include <linux/clk.h> |
---|
14 | 14 | #include <linux/err.h> |
---|
15 | 15 | #include <linux/io.h> |
---|
16 | | -#include <linux/gpio.h> |
---|
| 16 | +#include <linux/gpio/consumer.h> |
---|
17 | 17 | #include <linux/platform_device.h> |
---|
18 | 18 | #include <linux/dma-mapping.h> |
---|
19 | 19 | #include <linux/usb/usb_phy_generic.h> |
---|
.. | .. |
---|
24 | 24 | #include <asm/mach-types.h> |
---|
25 | 25 | |
---|
26 | 26 | #include "musb_core.h" |
---|
27 | | - |
---|
28 | | -#ifdef CONFIG_MACH_DAVINCI_EVM |
---|
29 | | -#define GPIO_nVBUS_DRV 160 |
---|
30 | | -#endif |
---|
31 | 27 | |
---|
32 | 28 | #include "davinci.h" |
---|
33 | 29 | #include "cppi_dma.h" |
---|
.. | .. |
---|
40 | 36 | struct device *dev; |
---|
41 | 37 | struct platform_device *musb; |
---|
42 | 38 | struct clk *clk; |
---|
| 39 | + bool vbus_state; |
---|
| 40 | + struct gpio_desc *vbus; |
---|
| 41 | + struct work_struct vbus_work; |
---|
43 | 42 | }; |
---|
44 | 43 | |
---|
45 | 44 | /* REVISIT (PM) we should be able to keep the PHY in low power mode most |
---|
.. | .. |
---|
135 | 134 | * when J10 is out, and TI documents it as handling OTG. |
---|
136 | 135 | */ |
---|
137 | 136 | |
---|
138 | | -#ifdef CONFIG_MACH_DAVINCI_EVM |
---|
139 | | - |
---|
140 | | -static int vbus_state = -1; |
---|
141 | | - |
---|
142 | 137 | /* I2C operations are always synchronous, and require a task context. |
---|
143 | 138 | * With unloaded systems, using the shared workqueue seems to suffice |
---|
144 | 139 | * to satisfy the 100msec A_WAIT_VRISE timeout... |
---|
145 | 140 | */ |
---|
146 | | -static void evm_deferred_drvvbus(struct work_struct *ignored) |
---|
| 141 | +static void evm_deferred_drvvbus(struct work_struct *work) |
---|
147 | 142 | { |
---|
148 | | - gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state); |
---|
149 | | - vbus_state = !vbus_state; |
---|
| 143 | + struct davinci_glue *glue = container_of(work, struct davinci_glue, |
---|
| 144 | + vbus_work); |
---|
| 145 | + |
---|
| 146 | + gpiod_set_value_cansleep(glue->vbus, glue->vbus_state); |
---|
| 147 | + glue->vbus_state = !glue->vbus_state; |
---|
150 | 148 | } |
---|
151 | 149 | |
---|
152 | | -#endif /* EVM */ |
---|
153 | | - |
---|
154 | | -static void davinci_musb_source_power(struct musb *musb, int is_on, int immediate) |
---|
| 150 | +static void davinci_musb_source_power(struct musb *musb, int is_on, |
---|
| 151 | + int immediate) |
---|
155 | 152 | { |
---|
156 | | -#ifdef CONFIG_MACH_DAVINCI_EVM |
---|
| 153 | + struct davinci_glue *glue = dev_get_drvdata(musb->controller->parent); |
---|
| 154 | + |
---|
| 155 | + /* This GPIO handling is entirely optional */ |
---|
| 156 | + if (!glue->vbus) |
---|
| 157 | + return; |
---|
| 158 | + |
---|
157 | 159 | if (is_on) |
---|
158 | 160 | is_on = 1; |
---|
159 | 161 | |
---|
160 | | - if (vbus_state == is_on) |
---|
| 162 | + if (glue->vbus_state == is_on) |
---|
161 | 163 | return; |
---|
162 | | - vbus_state = !is_on; /* 0/1 vs "-1 == unknown/init" */ |
---|
| 164 | + /* 0/1 vs "-1 == unknown/init" */ |
---|
| 165 | + glue->vbus_state = !is_on; |
---|
163 | 166 | |
---|
164 | 167 | if (machine_is_davinci_evm()) { |
---|
165 | | - static DECLARE_WORK(evm_vbus_work, evm_deferred_drvvbus); |
---|
166 | | - |
---|
167 | 168 | if (immediate) |
---|
168 | | - gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state); |
---|
| 169 | + gpiod_set_value_cansleep(glue->vbus, glue->vbus_state); |
---|
169 | 170 | else |
---|
170 | | - schedule_work(&evm_vbus_work); |
---|
| 171 | + schedule_work(&glue->vbus_work); |
---|
171 | 172 | } |
---|
172 | 173 | if (immediate) |
---|
173 | | - vbus_state = is_on; |
---|
174 | | -#endif |
---|
| 174 | + glue->vbus_state = is_on; |
---|
175 | 175 | } |
---|
176 | 176 | |
---|
177 | 177 | static void davinci_musb_set_vbus(struct musb *musb, int is_on) |
---|
.. | .. |
---|
524 | 524 | |
---|
525 | 525 | pdata->platform_ops = &davinci_ops; |
---|
526 | 526 | |
---|
| 527 | + glue->vbus = devm_gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW); |
---|
| 528 | + if (IS_ERR(glue->vbus)) { |
---|
| 529 | + ret = PTR_ERR(glue->vbus); |
---|
| 530 | + goto err0; |
---|
| 531 | + } else { |
---|
| 532 | + glue->vbus_state = -1; |
---|
| 533 | + INIT_WORK(&glue->vbus_work, evm_deferred_drvvbus); |
---|
| 534 | + } |
---|
| 535 | + |
---|
527 | 536 | usb_phy_generic_register(); |
---|
528 | 537 | platform_set_drvdata(pdev, glue); |
---|
529 | 538 | |
---|