Some usb module implementations has functionality of detect usb charger type, it can be used by usb charger framework to report max current drawn from charger in different situations. Signed-off-by: Li Jun <jun.li@xxxxxxx> --- drivers/usb/chipidea/udc.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/usb/chipidea.h | 4 ++++ 2 files changed, 44 insertions(+) diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 065f5d9..4d2187e 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1510,6 +1510,37 @@ static const struct usb_ep_ops usb_ep_ops = { /****************************************************************************** * GADGET block *****************************************************************************/ +static enum usb_charger_type ci_usb_charger_det(struct usb_charger *charger) +{ + struct ci_hdrc *ci; + enum usb_charger_type ret = UNKNOWN_TYPE; + + if (!charger || !charger->gadget) + return ret; + + ci = container_of(charger->gadget, struct ci_hdrc, gadget); + if (ci->vbus_active) { + if (ci->platdata->usb_charger_det) { + ret = ci->platdata->usb_charger_det(ci); + if (ret != UNKNOWN_TYPE) + return ret; + } + + if (ci->platdata->pull_dp_for_charger) { + hw_device_reset(ci); + hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); + } + + if (ci->platdata->usb_charger_secondary_det) + ret = ci->platdata->usb_charger_secondary_det(ci); + + if (ci->platdata->pull_dp_for_charger) + hw_write(ci, OP_USBCMD, USBCMD_RS, 0); + } + + return ret; +} + static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) { struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); @@ -1522,6 +1553,9 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) gadget_ready = 1; spin_unlock_irqrestore(&ci->lock, flags); + if (_gadget->charger && is_active) + usb_charger_detect_type(_gadget->charger); + if (gadget_ready) { if (is_active) { pm_runtime_get_sync(&_gadget->dev); @@ -1922,6 +1956,9 @@ static int udc_start(struct ci_hdrc *ci) if (retval) goto destroy_eps; + if (ci->gadget.charger && ci->platdata->usb_charger_det) + ci->gadget.charger->charger_detect = ci_usb_charger_det; + pm_runtime_no_callbacks(&ci->gadget.dev); pm_runtime_enable(&ci->gadget.dev); @@ -1946,6 +1983,9 @@ void ci_hdrc_gadget_destroy(struct ci_hdrc *ci) if (!ci->roles[CI_ROLE_GADGET]) return; + if (ci->gadget.charger) + ci->gadget.charger->charger_detect = NULL; + usb_del_gadget_udc(&ci->gadget); destroy_eps(ci); diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 5dd75fa..7fc781d 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -55,10 +55,14 @@ struct ci_hdrc_platform_data { #define CI_HDRC_OVERRIDE_AHB_BURST BIT(9) #define CI_HDRC_OVERRIDE_TX_BURST BIT(10) #define CI_HDRC_OVERRIDE_RX_BURST BIT(11) +#define CI_HDRC_PULL_DP_FOR_CHARGER BIT(12) enum usb_dr_mode dr_mode; #define CI_HDRC_CONTROLLER_RESET_EVENT 0 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1 void (*notify_event) (struct ci_hdrc *ci, unsigned event); + enum usb_charger_type (*usb_charger_det)(struct ci_hdrc *ci); + bool pull_dp_for_charger; + enum usb_charger_type (*usb_charger_secondary_det)(struct ci_hdrc *ci); struct regulator *reg_vbus; struct usb_otg_caps ci_otg_caps; bool tpl_support; -- 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