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

Commit 5cc49268 authored by Stephen Boyd's avatar Stephen Boyd Committed by Peter Chen
Browse files

usb: chipidea: Consolidate extcon notifiers



The two extcon notifiers are almost the same except for the
variable name for the cable structure and the id notifier inverts
the cable->state logic. Make it the same and replace two
functions with one to save some lines. This also makes it so that
the id cable state is true when the id pin is pulled low, so we
change the name of ->state to ->connected to properly reflect
that we're interested in the cable being connected.

Acked-by: default avatarPeter Chen <peter.chen@nxp.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Ivan T. Ivanov" <iivanov.xz@gmail.com>
Signed-off-by: default avatarStephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
parent 7bb7e9b1
Loading
Loading
Loading
Loading
+12 −33
Original line number Original line Diff line number Diff line
@@ -577,35 +577,14 @@ static irqreturn_t ci_irq(int irq, void *data)
	return ret;
	return ret;
}
}


static int ci_vbus_notifier(struct notifier_block *nb, unsigned long event,
static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
			     void *ptr)
			     void *ptr)
{
{
	struct ci_hdrc_cable *vbus = container_of(nb, struct ci_hdrc_cable, nb);
	struct ci_hdrc_cable *cbl = container_of(nb, struct ci_hdrc_cable, nb);
	struct ci_hdrc *ci = vbus->ci;
	struct ci_hdrc *ci = cbl->ci;


	if (event)
	cbl->connected = event;
		vbus->state = true;
	cbl->changed = true;
	else
		vbus->state = false;

	vbus->changed = true;

	ci_irq(ci->irq, ci);
	return NOTIFY_DONE;
}

static int ci_id_notifier(struct notifier_block *nb, unsigned long event,
			  void *ptr)
{
	struct ci_hdrc_cable *id = container_of(nb, struct ci_hdrc_cable, nb);
	struct ci_hdrc *ci = id->ci;

	if (event)
		id->state = false;
	else
		id->state = true;

	id->changed = true;


	ci_irq(ci->irq, ci);
	ci_irq(ci->irq, ci);
	return NOTIFY_DONE;
	return NOTIFY_DONE;
@@ -714,27 +693,27 @@ static int ci_get_platdata(struct device *dev,
	}
	}


	cable = &platdata->vbus_extcon;
	cable = &platdata->vbus_extcon;
	cable->nb.notifier_call = ci_vbus_notifier;
	cable->nb.notifier_call = ci_cable_notifier;
	cable->edev = ext_vbus;
	cable->edev = ext_vbus;


	if (!IS_ERR(ext_vbus)) {
	if (!IS_ERR(ext_vbus)) {
		ret = extcon_get_state(cable->edev, EXTCON_USB);
		ret = extcon_get_state(cable->edev, EXTCON_USB);
		if (ret)
		if (ret)
			cable->state = true;
			cable->connected = true;
		else
		else
			cable->state = false;
			cable->connected = false;
	}
	}


	cable = &platdata->id_extcon;
	cable = &platdata->id_extcon;
	cable->nb.notifier_call = ci_id_notifier;
	cable->nb.notifier_call = ci_cable_notifier;
	cable->edev = ext_id;
	cable->edev = ext_id;


	if (!IS_ERR(ext_id)) {
	if (!IS_ERR(ext_id)) {
		ret = extcon_get_state(cable->edev, EXTCON_USB_HOST);
		ret = extcon_get_state(cable->edev, EXTCON_USB_HOST);
		if (ret)
		if (ret)
			cable->state = false;
			cable->connected = true;
		else
		else
			cable->state = true;
			cable->connected = false;
	}
	}
	return 0;
	return 0;
}
}
+4 −4
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
		else
		else
			val &= ~OTGSC_BSVIS;
			val &= ~OTGSC_BSVIS;


		if (cable->state)
		if (cable->connected)
			val |= OTGSC_BSV;
			val |= OTGSC_BSV;
		else
		else
			val &= ~OTGSC_BSV;
			val &= ~OTGSC_BSV;
@@ -62,10 +62,10 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
		else
		else
			val &= ~OTGSC_IDIS;
			val &= ~OTGSC_IDIS;


		if (cable->state)
		if (cable->connected)
			val |= OTGSC_ID;
			val &= ~OTGSC_ID; /* host */
		else
		else
			val &= ~OTGSC_ID;
			val |= OTGSC_ID; /* device */


		if (cable->enabled)
		if (cable->enabled)
			val |= OTGSC_IDIE;
			val |= OTGSC_IDIE;
+2 −2
Original line number Original line Diff line number Diff line
@@ -12,7 +12,7 @@ struct ci_hdrc;


/**
/**
 * struct ci_hdrc_cable - structure for external connector cable state tracking
 * struct ci_hdrc_cable - structure for external connector cable state tracking
 * @state: current state of the line
 * @connected: true if cable is connected, false otherwise
 * @changed: set to true when extcon event happen
 * @changed: set to true when extcon event happen
 * @enabled: set to true if we've enabled the vbus or id interrupt
 * @enabled: set to true if we've enabled the vbus or id interrupt
 * @edev: device which generate events
 * @edev: device which generate events
@@ -21,7 +21,7 @@ struct ci_hdrc;
 * @conn: used for notification registration
 * @conn: used for notification registration
 */
 */
struct ci_hdrc_cable {
struct ci_hdrc_cable {
	bool				state;
	bool				connected;
	bool				changed;
	bool				changed;
	bool				enabled;
	bool				enabled;
	struct extcon_dev		*edev;
	struct extcon_dev		*edev;