Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b099f39b authored by Azhar Shaikh's avatar Azhar Shaikh
Browse files

usb: dwc3: msm: Rework dwc3_gadget_vbus_draw()



Since dwc3_gadget_vbus_draw() was merely calling
dwc3_otg_set_power() through usb_otg. Use notify_event() to notify
controller driver and call dwc3_msm_gadget_vbus_draw() which sets
the current to be drawn from USB.
This helps to remove the dependency on dwc3_otg from
dwc3_gadget.

Change-Id: Ie9000ddabedce667dd3251e9a0321c89fe12f602
Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
Signed-off-by: default avatarAzhar Shaikh <azhars@codeaurora.org>
parent ad216608
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -733,6 +733,7 @@ struct dwc3_scratchpad_array {
#define DWC3_CONTROLLER_POST_INITIALIZATION_EVENT	7
#define DWC3_CONTROLLER_CONNDONE_EVENT			8
#define DWC3_CONTROLLER_NOTIFY_OTG_EVENT		9
#define DWC3_CONTROLLER_SET_CURRENT_DRAW_EVENT		10

#define MAX_INTR_STATS					10
/**
@@ -807,6 +808,7 @@ struct dwc3_scratchpad_array {
 * @bh_handled_evt_cnt: no. of events handled by tasklet per interrupt
 * @bh_dbg_index: index for capturing bh_completion_time and bh_handled_evt_cnt
 * @wait_linkstate: waitqueue for waiting LINK to move into required state
 * @vbus_draw: current to be drawn from USB
 */
struct dwc3 {
	struct usb_ctrlrequest	*ctrl_req;
@@ -937,6 +939,7 @@ struct dwc3 {
	atomic_t		in_lpm;
	int			tx_fifo_size;
	bool			b_suspend;
	unsigned		vbus_draw;

	/* IRQ timing statistics */
	int			irq;
+17 −13
Original line number Diff line number Diff line
@@ -1176,6 +1176,8 @@ static void dwc3_msm_qscratch_reg_init(struct dwc3_msm *mdwc)
		dwc3_msm_read_reg(mdwc->base, QSCRATCH_CTRL_REG);
}

static int dwc3_msm_gadget_vbus_draw(struct dwc3_msm *mdwc, unsigned mA);

static void dwc3_msm_notify_event(struct dwc3 *dwc, unsigned event)
{
	struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent);
@@ -1261,6 +1263,10 @@ static void dwc3_msm_notify_event(struct dwc3 *dwc, unsigned event)
			schedule_delayed_work(&mdwc->resume_work, 0);
		}
		break;
	case DWC3_CONTROLLER_SET_CURRENT_DRAW_EVENT:
		dev_dbg(mdwc->dev, "DWC3_CONTROLLER_SET_CURRENT_DRAW_EVENT received\n");
		dwc3_msm_gadget_vbus_draw(mdwc, dwc->vbus_draw);
		break;
	default:
		dev_dbg(mdwc->dev, "unknown dwc3 event\n");
		break;
@@ -3358,17 +3364,15 @@ static void dwc3_otg_notify_host_mode(struct dwc3_msm *mdwc, int host_mode)
			POWER_SUPPLY_SCOPE_DEVICE);
}

static int dwc3_otg_set_power(struct usb_phy *phy, unsigned mA)
static int dwc3_msm_gadget_vbus_draw(struct dwc3_msm *mdwc, unsigned mA)
{
	enum power_supply_property power_supply_type;
	struct dwc3_otg *dotg = container_of(phy->otg, struct dwc3_otg, otg);
	struct dwc3_msm *mdwc = container_of(dotg, struct dwc3_msm, dotg);
	enum power_supply_type power_supply_type;

	if (mdwc->skip_chg_detect || mdwc->charging_disabled)
		return 0;

	if (mdwc->chg_type != DWC3_INVALID_CHARGER) {
		dev_dbg(phy->dev,
		dev_dbg(mdwc->dev,
			"SKIP setting power supply type again,chg_type = %d\n",
			mdwc->chg_type);
		goto skip_psy_type;
@@ -3394,7 +3398,7 @@ skip_psy_type:
	if (mdwc->max_power == mA)
		return 0;

	dev_info(phy->dev, "Avail curr from USB = %u\n", mA);
	dev_info(mdwc->dev, "Avail curr from USB = %u\n", mA);

	if (mdwc->max_power <= 2 && mA > 2) {
		/* Enable Charging */
@@ -3421,7 +3425,7 @@ skip_psy_type:
	return 0;

psy_error:
	dev_dbg(phy->dev, "power supply error when setting property\n");
	dev_dbg(mdwc->dev, "power supply error when setting property\n");
	return -ENXIO;
}

@@ -3513,11 +3517,11 @@ static void dwc3_otg_sm_work(struct work_struct *w)
				case DWC3_DCP_CHARGER:
				case DWC3_PROPRIETARY_CHARGER:
					dev_dbg(phy->dev, "lpm, DCP charger\n");
					dwc3_otg_set_power(phy,
					dwc3_msm_gadget_vbus_draw(mdwc,
							dcp_max_current);
					break;
				case DWC3_CDP_CHARGER:
					dwc3_otg_set_power(phy,
					dwc3_msm_gadget_vbus_draw(mdwc,
							DWC3_IDEV_CHG_MAX);
					/* fall through */
				case DWC3_SDP_CHARGER:
@@ -3548,7 +3552,8 @@ static void dwc3_otg_sm_work(struct work_struct *w)
					 */
					if (mdwc->retry_count ==
						max_chgr_retry_count) {
						dwc3_otg_set_power(phy, 0);
						dwc3_msm_gadget_vbus_draw(
								mdwc, 0);
						break;
					}
					dwc3_start_chg_det(mdwc, false);
@@ -3596,7 +3601,7 @@ static void dwc3_otg_sm_work(struct work_struct *w)
				dwc3_start_chg_det(mdwc, false);

			mdwc->retry_count = 0;
			dwc3_otg_set_power(phy, 0);
			dwc3_msm_gadget_vbus_draw(mdwc, 0);
			dev_dbg(phy->dev, "No device, allowing suspend\n");
		}
		break;
@@ -3740,7 +3745,6 @@ int dwc3_otg_init(struct dwc3 *dwc)

	dotg->otg.phy->otg = &dotg->otg;
	dotg->otg.phy->dev = dwc->dev;
	dotg->otg.phy->set_power = dwc3_otg_set_power;
	dotg->otg.set_peripheral = dwc3_otg_set_peripheral;
	dotg->otg.phy->state = OTG_STATE_UNDEFINED;

+5 −9
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
#include <linux/usb/ch9.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
#include <linux/usb/otg.h>

#include "debug.h"
#include "core.h"
@@ -1895,12 +1894,11 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
static int dwc3_gadget_vbus_draw(struct usb_gadget *g, unsigned mA)
{
	struct dwc3		*dwc = gadget_to_dwc(g);
	struct dwc3_otg		*dotg = dwc->dotg;

	if (dotg && dotg->otg.phy)
		return usb_phy_set_power(dotg->otg.phy, mA);

	return -ENOTSUPP;
	dwc->vbus_draw = mA;
	dev_dbg(dwc->dev, "Notify controller from %s. mA = %d\n", __func__, mA);
	dwc3_notify_event(dwc, DWC3_CONTROLLER_SET_CURRENT_DRAW_EVENT);
	return 0;
}

static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
@@ -2808,7 +2806,6 @@ void dwc3_gadget_usb3_phy_suspend(struct dwc3 *dwc, int suspend)
static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
{
	u32			reg;
	struct dwc3_otg		*dotg = dwc->dotg;

	/*
	 * WORKAROUND: DWC3 revisions <1.88a have an issue which
@@ -2851,8 +2848,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)

	dwc3_gadget_usb3_phy_suspend(dwc, false);

	if (dotg && dotg->otg.phy)
		usb_phy_set_power(dotg->otg.phy, 0);
	usb_gadget_vbus_draw(&dwc->gadget, 0);

	if (dwc->gadget.speed != USB_SPEED_UNKNOWN)
		dwc3_disconnect_gadget(dwc);