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

Commit 5966b1e3 authored by Pratham Pratap's avatar Pratham Pratap
Browse files

usb: pd: Register dual_role based on connector type



Since PD is not supported with microUSB connector,
do not register dual_role_instance if connector type is
microUSB as charger driver will take care of it.

Change-Id: Ib7d145dd353fa15828617a2cd5b70aae95e0703b
Signed-off-by: default avatarPratham Pratap <prathampratap@codeaurora.org>
parent e77f22c4
Loading
Loading
Loading
Loading
+27 −5
Original line number Diff line number Diff line
@@ -509,6 +509,21 @@ enum plug_orientation usbpd_get_plug_orientation(struct usbpd *pd)
}
EXPORT_SYMBOL(usbpd_get_plug_orientation);

static unsigned int get_connector_type(struct usbpd *pd)
{
	int ret;
	union power_supply_propval val;

	ret = power_supply_get_property(pd->usb_psy,
		POWER_SUPPLY_PROP_CONNECTOR_TYPE, &val);

	if (ret) {
		dev_err(&pd->dev, "Unable to read CONNECTOR TYPE: %d\n", ret);
		return ret;
	}
	return val.intval;
}

static inline void stop_usb_host(struct usbpd *pd)
{
	extcon_set_state_sync(pd->extcon, EXTCON_USB_HOST, 0);
@@ -4552,12 +4567,19 @@ struct usbpd *usbpd_create(struct device *parent)
	pd->dr_desc.set_property = usbpd_dr_set_property;
	pd->dr_desc.property_is_writeable = usbpd_dr_prop_writeable;

	ret = get_connector_type(pd);

	if (ret < 0)
		goto put_psy;

	/* For non-TypeC connector, it will be handled elsewhere */
	if (ret != POWER_SUPPLY_CONNECTOR_MICRO_USB) {
		pd->dual_role = devm_dual_role_instance_register(&pd->dev,
				&pd->dr_desc);
		if (IS_ERR(pd->dual_role)) {
			usbpd_err(&pd->dev, "could not register dual_role instance\n");
			goto put_psy;
	} else {
		}
		pd->dual_role->drv_data = pd;
	}

+3 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ static void dual_role_changed_work(struct work_struct *work)

void dual_role_instance_changed(struct dual_role_phy_instance *dual_role)
{
	if (!dual_role)
		return;

	dev_dbg(&dual_role->dev, "%s\n", __func__);
	pm_wakeup_event(&dual_role->dev, DUAL_ROLE_NOTIFICATION_TIMEOUT);
	schedule_work(&dual_role->changed_work);