forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/usb/musb/davinci.c
....@@ -13,7 +13,7 @@
1313 #include <linux/clk.h>
1414 #include <linux/err.h>
1515 #include <linux/io.h>
16
-#include <linux/gpio.h>
16
+#include <linux/gpio/consumer.h>
1717 #include <linux/platform_device.h>
1818 #include <linux/dma-mapping.h>
1919 #include <linux/usb/usb_phy_generic.h>
....@@ -24,10 +24,6 @@
2424 #include <asm/mach-types.h>
2525
2626 #include "musb_core.h"
27
-
28
-#ifdef CONFIG_MACH_DAVINCI_EVM
29
-#define GPIO_nVBUS_DRV 160
30
-#endif
3127
3228 #include "davinci.h"
3329 #include "cppi_dma.h"
....@@ -40,6 +36,9 @@
4036 struct device *dev;
4137 struct platform_device *musb;
4238 struct clk *clk;
39
+ bool vbus_state;
40
+ struct gpio_desc *vbus;
41
+ struct work_struct vbus_work;
4342 };
4443
4544 /* REVISIT (PM) we should be able to keep the PHY in low power mode most
....@@ -135,43 +134,44 @@
135134 * when J10 is out, and TI documents it as handling OTG.
136135 */
137136
138
-#ifdef CONFIG_MACH_DAVINCI_EVM
139
-
140
-static int vbus_state = -1;
141
-
142137 /* I2C operations are always synchronous, and require a task context.
143138 * With unloaded systems, using the shared workqueue seems to suffice
144139 * to satisfy the 100msec A_WAIT_VRISE timeout...
145140 */
146
-static void evm_deferred_drvvbus(struct work_struct *ignored)
141
+static void evm_deferred_drvvbus(struct work_struct *work)
147142 {
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;
150148 }
151149
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)
155152 {
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
+
157159 if (is_on)
158160 is_on = 1;
159161
160
- if (vbus_state == is_on)
162
+ if (glue->vbus_state == is_on)
161163 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;
163166
164167 if (machine_is_davinci_evm()) {
165
- static DECLARE_WORK(evm_vbus_work, evm_deferred_drvvbus);
166
-
167168 if (immediate)
168
- gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state);
169
+ gpiod_set_value_cansleep(glue->vbus, glue->vbus_state);
169170 else
170
- schedule_work(&evm_vbus_work);
171
+ schedule_work(&glue->vbus_work);
171172 }
172173 if (immediate)
173
- vbus_state = is_on;
174
-#endif
174
+ glue->vbus_state = is_on;
175175 }
176176
177177 static void davinci_musb_set_vbus(struct musb *musb, int is_on)
....@@ -524,6 +524,15 @@
524524
525525 pdata->platform_ops = &davinci_ops;
526526
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
+
527536 usb_phy_generic_register();
528537 platform_set_drvdata(pdev, glue);
529538