Skip to content

Commit 6afad76

Browse files
Albert Wangbgcngm
Albert Wang
authored andcommitted
usb: new attributes implementation to enable/disable usb data
Bug: 184613044 Test: driver probe and attributes access normally Signed-off-by: Albert Wang <[email protected]> Change-Id: Ia34cfd8e76a21f7239e356608e46ddeebd6fa10a
1 parent 93c252a commit 6afad76

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
What: /sys/class/udc/<udc name>/device/usb_data_enabled
2+
Date: December 2020
3+
Contact: "Ray Chi" <[email protected]>
4+
Description:
5+
The attribute can allow user space can check and modify
6+
the value to enable or disable usb functionality. Therefore,
7+
if the attritube is set to 0, USB host and USB peripheral
8+
modes wouldn't be working.
9+
10+
Example:
11+
Enable USB data functionality
12+
# echo 1 > /sys/class/udc/.../device/usb_data_enabled
13+
14+
Disable USB data functionality
15+
# echo 0 > /sys/class/udc/.../device/usb_data_enabled
16+

drivers/usb/dwc3/dwc3-msm.c

+39-1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ struct dwc3_msm {
335335
dma_addr_t dummy_gsi_db_dma;
336336
u64 *dummy_gevntcnt;
337337
dma_addr_t dummy_gevntcnt_dma;
338+
bool usb_data_enabled;
338339
};
339340

340341
#define USB_HSPHY_3P3_VOL_MIN 3050000 /* uV */
@@ -3243,6 +3244,9 @@ static int dwc3_msm_id_notifier(struct notifier_block *nb,
32433244
struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3);
32443245
enum dwc3_id_state id;
32453246

3247+
if (!mdwc->usb_data_enabled)
3248+
return NOTIFY_DONE;
3249+
32463250
id = event ? DWC3_ID_GROUND : DWC3_ID_FLOAT;
32473251

32483252
dev_dbg(mdwc->dev, "host:%ld (id:%d) event received\n", event, id);
@@ -3301,6 +3305,9 @@ static int dwc3_msm_vbus_notifier(struct notifier_block *nb,
33013305
struct dwc3_msm *mdwc = container_of(nb, struct dwc3_msm, vbus_nb);
33023306
struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3);
33033307

3308+
if (!mdwc->usb_data_enabled)
3309+
return NOTIFY_DONE;
3310+
33043311
dev_dbg(mdwc->dev, "vbus:%ld event received\n", event);
33053312

33063313
if (mdwc->vbus_active == event)
@@ -3642,9 +3649,35 @@ static ssize_t xhci_link_compliance_store(struct device *dev,
36423649

36433650
return ret;
36443651
}
3645-
36463652
static DEVICE_ATTR_RW(xhci_link_compliance);
36473653

3654+
static ssize_t usb_data_enabled_show(struct device *dev,
3655+
struct device_attribute *attr, char *buf)
3656+
{
3657+
struct dwc3_msm *mdwc = dev_get_drvdata(dev);
3658+
3659+
return sysfs_emit(buf, "%s\n",
3660+
mdwc->usb_data_enabled ? "enabled" : "disabled");
3661+
}
3662+
3663+
static ssize_t usb_data_enabled_store(struct device *dev,
3664+
struct device_attribute *attr, const char *buf, size_t count)
3665+
{
3666+
struct dwc3_msm *mdwc = dev_get_drvdata(dev);
3667+
3668+
if (kstrtobool(buf, &mdwc->usb_data_enabled))
3669+
return -EINVAL;
3670+
3671+
if (!mdwc->usb_data_enabled) {
3672+
mdwc->vbus_active = false;
3673+
mdwc->id_state = DWC3_ID_FLOAT;
3674+
dwc3_ext_event_notify(mdwc);
3675+
}
3676+
3677+
return count;
3678+
}
3679+
static DEVICE_ATTR_RW(usb_data_enabled);
3680+
36483681
static int dwc3_msm_probe(struct platform_device *pdev)
36493682
{
36503683
struct device_node *node = pdev->dev.of_node, *dwc3_node;
@@ -4002,10 +4035,13 @@ static int dwc3_msm_probe(struct platform_device *pdev)
40024035
dev_info(mdwc->dev, "charger detection in progress\n");
40034036
}
40044037

4038+
/* set the initial value */
4039+
mdwc->usb_data_enabled = true;
40054040
device_create_file(&pdev->dev, &dev_attr_mode);
40064041
device_create_file(&pdev->dev, &dev_attr_speed);
40074042
device_create_file(&pdev->dev, &dev_attr_usb_compliance_mode);
40084043
device_create_file(&pdev->dev, &dev_attr_xhci_link_compliance);
4044+
device_create_file(&pdev->dev, &dev_attr_usb_data_enabled);
40094045

40104046
host_mode = usb_get_dr_mode(&mdwc->dwc3->dev) == USB_DR_MODE_HOST;
40114047
if (!dwc->is_drd && host_mode) {
@@ -4046,6 +4082,8 @@ static int dwc3_msm_remove(struct platform_device *pdev)
40464082

40474083
device_remove_file(&pdev->dev, &dev_attr_mode);
40484084
device_remove_file(&pdev->dev, &dev_attr_xhci_link_compliance);
4085+
device_create_file(&pdev->dev, &dev_attr_usb_data_enabled);
4086+
40494087
if (mdwc->usb_psy)
40504088
power_supply_put(mdwc->usb_psy);
40514089

0 commit comments

Comments
 (0)