Skip to content

Commit 1ea1859

Browse files
linuswgregkh
authored andcommitted
usb: musb: davinci: Convert to use GPIO descriptor
The DaVinci MUSB glue contains an optional GPIO line to control VBUS power, convert this to use a GPIO descriptor and augment the EVM board file to provide this descriptor. I can't get this driver to compile properly and it depends on broken but when I didn get it to compile brokenly, it did at least not complain about THIS code being broken so I don't think I broke the driver any more than what it already is. I did away with the ifdefs that do not work with multiplatform anyway so the day someone decides to resurrect the code, the path to get it working should be easier as well since DaVinci is now multiplatform. Cc: Sekhar Nori <[email protected]> Cc: Bartosz Golaszewski <[email protected]> Cc: Tony Lindgren <[email protected]> Signed-off-by: Linus Walleij <[email protected]> [[email protected]: fixed one instance still ref to global variable vbus_state] Signed-off-by: Bin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0990366 commit 1ea1859

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

arch/arm/mach-davinci/board-dm644x-evm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,17 @@ static int davinci_phy_fixup(struct phy_device *phydev)
823823

824824
#define HAS_NAND IS_ENABLED(CONFIG_MTD_NAND_DAVINCI)
825825

826+
#define GPIO_nVBUS_DRV 160
827+
828+
static struct gpiod_lookup_table dm644evm_usb_gpio_table = {
829+
.dev_id = "musb-davinci",
830+
.table = {
831+
GPIO_LOOKUP("davinci_gpio", GPIO_nVBUS_DRV, NULL,
832+
GPIO_ACTIVE_HIGH),
833+
{ }
834+
},
835+
};
836+
826837
static __init void davinci_evm_init(void)
827838
{
828839
int ret;
@@ -875,6 +886,7 @@ static __init void davinci_evm_init(void)
875886
dm644x_init_asp();
876887

877888
/* irlml6401 switches over 1A, in under 8 msec */
889+
gpiod_add_lookup_table(&dm644evm_usb_gpio_table);
878890
davinci_setup_usb(1000, 8);
879891

880892
if (IS_BUILTIN(CONFIG_PHYLIB)) {

drivers/usb/musb/davinci.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
@@ -25,10 +25,6 @@
2525

2626
#include "musb_core.h"
2727

28-
#ifdef CONFIG_MACH_DAVINCI_EVM
29-
#define GPIO_nVBUS_DRV 160
30-
#endif
31-
3228
#include "davinci.h"
3329
#include "cppi_dma.h"
3430

@@ -40,6 +36,9 @@ struct davinci_glue {
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 @@ static void davinci_musb_disable(struct musb *musb)
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;
150-
}
143+
struct davinci_glue *glue = container_of(work, struct davinci_glue,
144+
vbus_work);
151145

152-
#endif /* EVM */
146+
gpiod_set_value_cansleep(glue->vbus, glue->vbus_state);
147+
glue->vbus_state = !glue->vbus_state;
148+
}
153149

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 @@ static int davinci_probe(struct platform_device *pdev)
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

0 commit comments

Comments
 (0)