Some imx usb charger dectection need software implement the whole process, during which, pull up&down DP line via usb core is required. Signed-off-by: Li Jun <jun.li@xxxxxxx> --- drivers/usb/chipidea/ci_hdrc_imx.c | 43 ++++++++++++++++++++++++++++++++++++++ drivers/usb/chipidea/ci_hdrc_imx.h | 3 +++ drivers/usb/chipidea/usbmisc_imx.c | 33 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index dedc33e..83a59d6 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -244,6 +244,38 @@ static void imx_disable_unprepare_clks(struct device *dev) } } +static enum usb_charger_type imx_usb_charger_det(struct ci_hdrc *ci) +{ + struct device *dev = ci->dev->parent; + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + struct imx_usbmisc_data *mdata = data->usbmisc_data; + int ret = UNKNOWN_TYPE; + + if (!mdata || !ci->gadget.charger) + return ret; + + if (ci->vbus_active) + ret = imx_usbmisc_charger_det(mdata); + + return ret; +} + +static enum usb_charger_type imx_usb_charger_secondary_det(struct ci_hdrc *ci) +{ + struct device *dev = ci->dev->parent; + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + struct imx_usbmisc_data *mdata = data->usbmisc_data; + int ret = UNKNOWN_TYPE; + + if (!mdata || !ci->gadget.charger) + return ret; + + if (ci->vbus_active) + ret = imx_usbmisc_charger_secondary_det(mdata); + + return ret; +} + static int ci_hdrc_imx_probe(struct platform_device *pdev) { struct ci_hdrc_imx_data *data; @@ -254,6 +286,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) int ret; const struct of_device_id *of_id; const struct ci_hdrc_imx_platform_flag *imx_platform_flag; + struct device_node *np = pdev->dev.of_node; of_id = of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev); if (!of_id) @@ -292,6 +325,16 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM) data->supports_runtime_pm = true; + if (of_find_property(np, "usb-charger-detection", NULL) && + data->usbmisc_data) { + pdata.usb_charger_det = imx_usb_charger_det; + if (imx_platform_flag->flags & CI_HDRC_PULL_DP_FOR_CHARGER) { + pdata.pull_dp_for_charger = true; + pdata.usb_charger_secondary_det = + imx_usb_charger_secondary_det; + } + } + ret = imx_usbmisc_init(data->usbmisc_data); if (ret) { dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", ret); diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h index 635717e..e34c284 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.h +++ b/drivers/usb/chipidea/ci_hdrc_imx.h @@ -23,5 +23,8 @@ struct imx_usbmisc_data { int imx_usbmisc_init(struct imx_usbmisc_data *); int imx_usbmisc_init_post(struct imx_usbmisc_data *); int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *, bool); +enum usb_charger_type imx_usbmisc_charger_det(struct imx_usbmisc_data *data); +enum usb_charger_type imx_usbmisc_charger_secondary_det( + struct imx_usbmisc_data *data); #endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H */ diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index ab8b027..3d70712 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -14,6 +14,7 @@ #include <linux/err.h> #include <linux/io.h> #include <linux/delay.h> +#include <linux/usb/charger.h> #include "ci_hdrc_imx.h" @@ -87,6 +88,9 @@ struct usbmisc_ops { int (*post)(struct imx_usbmisc_data *data); /* It's called when we need to enable/disable usb wakeup */ int (*set_wakeup)(struct imx_usbmisc_data *data, bool enabled); + enum usb_charger_type (*charger_det)(struct imx_usbmisc_data *data); + enum usb_charger_type (*charger_secondary_det) + (struct imx_usbmisc_data *data); }; struct imx_usbmisc { @@ -455,6 +459,35 @@ int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled) } EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup); +enum usb_charger_type imx_usbmisc_charger_det(struct imx_usbmisc_data *data) +{ + struct imx_usbmisc *usbmisc; + + if (!data) + return -EINVAL; + + usbmisc = dev_get_drvdata(data->dev); + if (!usbmisc->ops->charger_det) + return -EINVAL; + return usbmisc->ops->charger_det(data); +} +EXPORT_SYMBOL_GPL(imx_usbmisc_charger_det); + +enum usb_charger_type imx_usbmisc_charger_secondary_det( + struct imx_usbmisc_data *data) +{ + struct imx_usbmisc *usbmisc; + + if (!data) + return -EINVAL; + + usbmisc = dev_get_drvdata(data->dev); + if (!usbmisc->ops->charger_secondary_det) + return -EINVAL; + return usbmisc->ops->charger_secondary_det(data); +} +EXPORT_SYMBOL_GPL(imx_usbmisc_charger_secondary_det); + static const struct of_device_id usbmisc_imx_dt_ids[] = { { .compatible = "fsl,imx25-usbmisc", -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html