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

Unverified Commit 18e266da authored by Albert Wang's avatar Albert Wang Committed by Michael Bestas
Browse files

usb: new attributes implementation to enable/disable usb data



Bug: 188760285
Test: driver probe and attributes access normally
Signed-off-by: default avatarAlbert Wang <albertccwang@google.com>
Change-Id: I0aec98eebff9454cdec065bb09825f6442ac013b
parent 82145766
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
What:		/sys/class/udc/<udc name>/device/usb_data_enabled
Date:		December 2020
Contact:	"Ray Chi" <raychi@google.com>
Description:
		The attribute can allow user space can check and modify
		the value to enable or disable usb functionality. Therefore,
		if the attritube is set to 0, USB host and USB peripheral
		modes wouldn't be working.

		Example:
		Enable USB data functionality
		# echo 1 > /sys/class/udc/.../device/usb_data_enabled

		Disable USB data functionality
		# echo 0 > /sys/class/udc/.../device/usb_data_enabled
+40 −0
Original line number Original line Diff line number Diff line
@@ -359,6 +359,7 @@ struct dwc3_msm {
	u64			dummy_gsi_db;
	u64			dummy_gsi_db;
	dma_addr_t		dummy_gsi_db_dma;
	dma_addr_t		dummy_gsi_db_dma;
	int			orientation_override;
	int			orientation_override;
	bool			usb_data_enabled;
};
};


#define USB_HSPHY_3P3_VOL_MIN		3050000 /* uV */
#define USB_HSPHY_3P3_VOL_MIN		3050000 /* uV */
@@ -3293,6 +3294,9 @@ static int dwc3_msm_id_notifier(struct notifier_block *nb,
	if (!edev || !mdwc)
	if (!edev || !mdwc)
		return NOTIFY_DONE;
		return NOTIFY_DONE;


	if (!mdwc->usb_data_enabled)
		return NOTIFY_DONE;

	dwc = platform_get_drvdata(mdwc->dwc3);
	dwc = platform_get_drvdata(mdwc->dwc3);


	dbg_event(0xFF, "extcon idx", enb->idx);
	dbg_event(0xFF, "extcon idx", enb->idx);
@@ -3354,6 +3358,9 @@ static int dwc3_msm_vbus_notifier(struct notifier_block *nb,
	if (!edev || !mdwc)
	if (!edev || !mdwc)
		return NOTIFY_DONE;
		return NOTIFY_DONE;


	if (!mdwc->usb_data_enabled)
		return NOTIFY_DONE;

	dwc = platform_get_drvdata(mdwc->dwc3);
	dwc = platform_get_drvdata(mdwc->dwc3);


	dbg_event(0xFF, "extcon idx", enb->idx);
	dbg_event(0xFF, "extcon idx", enb->idx);
@@ -3685,6 +3692,35 @@ static int dwc_dpdm_cb(struct notifier_block *nb, unsigned long evt, void *p)


	return NOTIFY_OK;
	return NOTIFY_OK;
}
}

static ssize_t usb_data_enabled_show(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct dwc3_msm *mdwc = dev_get_drvdata(dev);

	return sysfs_emit(buf, "%s\n",
			  mdwc->usb_data_enabled ? "enabled" : "disabled");
}

static ssize_t usb_data_enabled_store(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{
	struct dwc3_msm *mdwc = dev_get_drvdata(dev);

	if (kstrtobool(buf, &mdwc->usb_data_enabled))
		return -EINVAL;

	if (!mdwc->usb_data_enabled) {
		mdwc->vbus_active = false;
		mdwc->id_state = DWC3_ID_FLOAT;
		dwc3_ext_event_notify(mdwc);
	}

	return count;
}
static DEVICE_ATTR_RW(usb_data_enabled);

static int dwc3_msm_probe(struct platform_device *pdev)
static int dwc3_msm_probe(struct platform_device *pdev)
{
{
	struct device_node *node = pdev->dev.of_node, *dwc3_node;
	struct device_node *node = pdev->dev.of_node, *dwc3_node;
@@ -4057,11 +4093,14 @@ static int dwc3_msm_probe(struct platform_device *pdev)
		dwc3_ext_event_notify(mdwc);
		dwc3_ext_event_notify(mdwc);
	}
	}


	/* set the initial value */
	mdwc->usb_data_enabled = true;
	device_create_file(&pdev->dev, &dev_attr_orientation);
	device_create_file(&pdev->dev, &dev_attr_orientation);
	device_create_file(&pdev->dev, &dev_attr_mode);
	device_create_file(&pdev->dev, &dev_attr_mode);
	device_create_file(&pdev->dev, &dev_attr_speed);
	device_create_file(&pdev->dev, &dev_attr_speed);
	device_create_file(&pdev->dev, &dev_attr_usb_compliance_mode);
	device_create_file(&pdev->dev, &dev_attr_usb_compliance_mode);
	device_create_file(&pdev->dev, &dev_attr_bus_vote);
	device_create_file(&pdev->dev, &dev_attr_bus_vote);
	device_create_file(&pdev->dev, &dev_attr_usb_data_enabled);


	return 0;
	return 0;


@@ -4084,6 +4123,7 @@ static int dwc3_msm_remove(struct platform_device *pdev)
	int ret_pm;
	int ret_pm;


	device_remove_file(&pdev->dev, &dev_attr_mode);
	device_remove_file(&pdev->dev, &dev_attr_mode);
	device_remove_file(&pdev->dev, &dev_attr_usb_data_enabled);


	if (mdwc->dpdm_nb.notifier_call) {
	if (mdwc->dpdm_nb.notifier_call) {
		regulator_unregister_notifier(mdwc->dpdm_reg, &mdwc->dpdm_nb);
		regulator_unregister_notifier(mdwc->dpdm_reg, &mdwc->dpdm_nb);