From 822eb0fe8b6b51756f37fd905bc9442b32fb6b23 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Mon, 8 Oct 2018 17:43:45 +0800 Subject: [PATCH] MLK-19850-6 usb: chipidea: introduce flag for enable USB PHY charger detection Some platforms may want to use USB PHY charger detection function when VBUS is there, add one flag for it. The user can enable it at firmware. Reviewed-by: Jun Li Signed-off-by: Peter Chen --- Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 1 + drivers/usb/chipidea/core.c | 6 ++++++ drivers/usb/chipidea/udc.c | 4 ++++ include/linux/usb/chipidea.h | 2 ++ 4 files changed, 13 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt index 2bff168f83bc..b886791b2e2c 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt @@ -79,6 +79,7 @@ Optional properties: maximum_periodic_data_per_frame. The use case is multiple transactions, but less frame rate. - ci-disable-lpm: Some chipidea hardware need to disable low power mode +- phy-charger-detection: enable USB PHY charger detection function i.mx specific properties - fsl,usbmisc: phandler of non-core register device, with one diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index b850178694b6..7d8002d92249 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -690,6 +690,12 @@ static int ci_get_platdata(struct device *dev, if (of_find_property(dev->of_node, "non-zero-ttctrl-ttha", NULL)) platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA; + /* "imx-usb-charger-detection is legacy compatible */ + if (of_find_property(dev->of_node, "phy-charger-detection", NULL) || + of_find_property(dev->of_node, "imx-usb-charger-detection", + NULL)) + platdata->flags |= CI_HDRC_PHY_CHARGER_DETECTION; + ext_id = ERR_PTR(-ENODEV); ext_vbus = ERR_PTR(-ENODEV); if (of_property_read_bool(dev->of_node, "extcon")) { diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index da9bfe831afa..0a54bed64ee3 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -2016,6 +2016,9 @@ int ci_usb_charger_connect(struct ci_hdrc *ci, int is_active) if (is_active) pm_runtime_get_sync(ci->dev); + if (!(ci->platdata->flags & CI_HDRC_PHY_CHARGER_DETECTION)) + goto out; + if (ci->usb_phy->charger_detect) { usb_phy_set_charger_state(ci->usb_phy, is_active ? USB_CHARGER_PRESENT : USB_CHARGER_ABSENT); @@ -2036,6 +2039,7 @@ int ci_usb_charger_connect(struct ci_hdrc *ci, int is_active) } schedule_work(&ci->usb_phy->chg_work); } +out: if (!is_active) pm_runtime_put_sync(ci->dev); diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 91250f54d2d2..ba2c49047434 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -64,6 +64,8 @@ struct ci_hdrc_platform_data { #define CI_HDRC_IMX_IS_HSIC BIT(15) /* need request pmqos during low power */ #define CI_HDRC_PMQOS BIT(16) +/* Using PHY's charger detection */ +#define CI_HDRC_PHY_CHARGER_DETECTION BIT(17) enum usb_dr_mode dr_mode; #define CI_HDRC_CONTROLLER_RESET_EVENT 0 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1