From df63e899d9d8298b05656a9c3511756f58837afd Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 18 Feb 2020 13:36:40 +0900 Subject: [PATCH] usb: dwc2: gadget: Set extcon state for usb cable as always true To inform to userspace as enable usb features always, set extcon state for usb cable as connected permanently. To enable this, add "g-extcon-always-on" property on dt. Signed-off-by: Dongwoo Lee [mszyprow: ported and adapted to v6.6 kernel release] Signed-off-by: Marek Szyprowski Change-Id: Ib0e9982b426fda7deed510e482d6731a2f23d0b1 --- drivers/usb/dwc2/core.h | 3 +++ drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ drivers/usb/dwc2/params.c | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index c92a1da..faf40c1 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -497,6 +497,9 @@ struct dwc2_core_params { u32 g_rx_fifo_size; u32 g_np_tx_fifo_size; u32 g_tx_fifo_size[MAX_EPS_CHANNELS]; +#if IS_ENABLED(CONFIG_EXTCON) + bool g_extcon_always_on; +#endif bool change_speed_quirk; }; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index b517a72..68292c2 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -5060,6 +5061,25 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg) dwc2_hsotg_dump(hsotg); +#if IS_ENABLED(CONFIG_EXTCON) + if (hsotg->params.g_extcon_always_on) { + struct extcon_dev *edev; + static const unsigned int supported_cable[] = { + EXTCON_USB, + EXTCON_NONE, + }; + + edev = devm_extcon_dev_allocate(dev, supported_cable); + if (IS_ERR(edev)) + return PTR_ERR(edev); + + ret = devm_extcon_dev_register(dev, edev); + if (ret) + return ret; + + extcon_set_state_sync(edev, EXTCON_USB, true); + } +#endif return 0; } diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c index 93f52e3..d0508a0 100644 --- a/drivers/usb/dwc2/params.c +++ b/drivers/usb/dwc2/params.c @@ -546,6 +546,11 @@ static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg) &p->g_np_tx_fifo_size); num = device_property_count_u32(hsotg->dev, "g-tx-fifo-size"); +#if IS_ENABLED(CONFIG_EXTCON) + if (of_find_property(hsotg->dev->of_node, + "g-extcon-always-on", NULL)) + p->g_extcon_always_on = 1; +#endif if (num > 0) { num = min(num, 15); memset(p->g_tx_fifo_size, 0, -- 2.7.4