diff options
author | Haribabu Narayanan <hnarayanan@nvidia.com> | 2014-03-04 00:52:56 -0800 |
---|---|---|
committer | Haribabu Narayanan <hnarayanan@nvidia.com> | 2014-03-11 18:56:47 -0700 |
commit | 8921a2c370014e997df95818802ceb487084fadb (patch) | |
tree | 53a5fa0c7ff7a13d6e8397f6ac165b7981ecda20 /drivers/usb | |
parent | 997c7fd326a54135a4892c4ff17fd1569b8fe4e0 (diff) |
usb: otg: tegra: sysfs-setting for gadget mode
Add ability to set the OTG port to device mode through sysfs.
Bug 1463801
Bug 1380254
Bug 1435985
Change-Id: I7bf5a3d8576e88ffb399a0bab2d43b446d6753c8
Signed-off-by: Haribabu Narayanan <hnarayanan@nvidia.com>
Reviewed-on: http://git-master/r/334332
(cherry picked from commit 56f0bff3d377b9aafa4c78764de820494ae34634)
Signed-off-by: Haribabu Narayanan <hnarayanan@nvidia.com>
Reviewed-on: http://git-master/r/353704
(cherry picked from commit ed1112a4153655e51913bf27e948e23b10278452)
Signed-off-by: Haribabu Narayanan <hnarayanan@nvidia.com>
Reviewed-on: http://git-master/r/377073
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/phy/tegra-otg.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/drivers/usb/phy/tegra-otg.c b/drivers/usb/phy/tegra-otg.c index 47a5ed7b9cb9..1b3b95d55134 100644 --- a/drivers/usb/phy/tegra-otg.c +++ b/drivers/usb/phy/tegra-otg.c @@ -553,8 +553,11 @@ static ssize_t show_host_en(struct device *dev, struct device_attribute *attr, { struct platform_device *pdev = to_platform_device(dev); struct tegra_otg *tegra = platform_get_drvdata(pdev); + struct usb_otg *otg = tegra->phy.otg; + + *buf = ((!tegra->interrupt_mode) && + (otg->phy->state == OTG_STATE_A_HOST)) ? '1' : '0'; - *buf = tegra->interrupt_mode ? '0': '1'; strcat(buf, "\n"); return strlen(buf); } @@ -571,6 +574,7 @@ static ssize_t store_host_en(struct device *dev, struct device_attribute *attr, if (host) { enable_interrupt(tegra, false); + tegra->interrupt_mode = true; tegra_change_otg_state(tegra, OTG_STATE_A_SUSPEND); tegra_change_otg_state(tegra, OTG_STATE_A_HOST); tegra->interrupt_mode = false; @@ -585,6 +589,48 @@ static ssize_t store_host_en(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR(enable_host, 0644, show_host_en, store_host_en); +static ssize_t show_device_en(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct platform_device *pdev = to_platform_device(dev); + struct tegra_otg *tegra = platform_get_drvdata(pdev); + struct usb_otg *otg = tegra->phy.otg; + + *buf = ((!tegra->interrupt_mode) && + otg->phy->state == OTG_STATE_B_PERIPHERAL) ? '1' : '0'; + + strcat(buf, "\n"); + return strlen(buf); +} + +static ssize_t store_device_en(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct platform_device *pdev = to_platform_device(dev); + struct tegra_otg *tegra = platform_get_drvdata(pdev); + unsigned long device; + + if (sscanf(buf, "%lu", &device) != 1 || device < 0 || device > 1) + return -EINVAL; + + if (device) { + enable_interrupt(tegra, false); + tegra->interrupt_mode = true; + tegra_change_otg_state(tegra, OTG_STATE_A_SUSPEND); + tegra_change_otg_state(tegra, OTG_STATE_B_PERIPHERAL); + tegra->interrupt_mode = false; + } else { + tegra->interrupt_mode = true; + tegra_change_otg_state(tegra, OTG_STATE_A_SUSPEND); + enable_interrupt(tegra, true); + } + + return count; +} + +static DEVICE_ATTR(enable_device, 0644, show_device_en, store_device_en); + static int tegra_otg_set_power(struct usb_phy *phy, unsigned mA) { return 0; @@ -844,7 +890,15 @@ static int tegra_otg_probe(struct platform_device *pdev) && !tegra->support_gpio_id) { err = device_create_file(&pdev->dev, &dev_attr_enable_host); if (err) { - dev_warn(&pdev->dev, "Can't register sysfs attribute\n"); + dev_warn(&pdev->dev, + "Can't register host-sysfs attribute\n"); + goto err; + } + err = device_create_file(&pdev->dev, &dev_attr_enable_device); + if (err) { + dev_warn(&pdev->dev, + "Can't register device-sysfs attribute\n"); + device_remove_file(&pdev->dev, &dev_attr_enable_host); goto err; } } |