From: richard.zhao@freescale.com (Richard Zhao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 10/11] USB: chipidea: add set_vbus_power support
Date: Tue, 28 Aug 2012 15:03:16 +0800 [thread overview]
Message-ID: <1346137397-32374-11-git-send-email-richard.zhao@freescale.com> (raw)
In-Reply-To: <1346137397-32374-1-git-send-email-richard.zhao@freescale.com>
set_vbus_power is used to enable or disable vbus power for usb host.
[Marc Kleine-Budde <mkl@pengutronix.de>: fix regulator unbalance disable]
Signed-off-by: Richard Zhao <richard.zhao@freescale.com>
---
drivers/usb/chipidea/ci13xxx_imx.c | 44 +++++++++++++++++++++---------------
drivers/usb/chipidea/host.c | 8 +++++++
include/linux/usb/chipidea.h | 2 ++
3 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
index 0f5ca4b..5c0be08 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -27,6 +27,8 @@
#define pdev_to_phy(pdev) \
((struct usb_phy *)platform_get_drvdata(pdev))
+#define ci_to_imx_data(ci) \
+ ((struct ci13xxx_imx_data *)dev_get_drvdata(ci->dev->parent))
struct ci13xxx_imx_data {
struct device_node *phy_np;
@@ -85,12 +87,32 @@ EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
/* End of common functions shared by usbmisc drivers*/
+static int ci13xxx_imx_vbus(struct ci13xxx *ci, int enable)
+{
+ struct ci13xxx_imx_data *data = ci_to_imx_data(ci);
+ int ret;
+
+ if (!data->reg_vbus)
+ return 0;
+
+ if (enable)
+ ret = regulator_enable(data->reg_vbus);
+ else
+ ret = regulator_disable(data->reg_vbus);
+ if (ret)
+ dev_err(ci->dev, "ci13xxx_imx_vbus failed, enable:%d err:%d\n",
+ enable, ret);
+
+ return ret;
+}
+
static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata = {
.name = "ci13xxx_imx",
.flags = CI13XXX_REQUIRE_TRANSCEIVER |
CI13XXX_PULLUP_ON_VBUS |
CI13XXX_DISABLE_STREAMING,
.capoffset = DEF_CAPOFFSET,
+ .set_vbus_power = ci13xxx_imx_vbus,
};
static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
@@ -153,20 +175,11 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
}
}
- /* we only support host now, so enable vbus here */
reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
- if (!IS_ERR(reg_vbus)) {
- ret = regulator_enable(reg_vbus);
- if (ret) {
- dev_err(&pdev->dev,
- "Failed to enable vbus regulator, err=%d\n",
- ret);
- goto put_np;
- }
+ if (!IS_ERR(reg_vbus))
data->reg_vbus = reg_vbus;
- } else {
+ else
reg_vbus = NULL;
- }
ci13xxx_imx_platdata.phy = data->phy;
@@ -191,6 +204,8 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
}
}
+ platform_set_drvdata(pdev, data);
+
plat_ci = ci13xxx_add_device(&pdev->dev,
pdev->resource, pdev->num_resources,
&ci13xxx_imx_platdata);
@@ -203,7 +218,6 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
}
data->ci_pdev = plat_ci;
- platform_set_drvdata(pdev, data);
pm_runtime_no_callbacks(&pdev->dev);
pm_runtime_enable(&pdev->dev);
@@ -211,9 +225,6 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
return 0;
err:
- if (reg_vbus)
- regulator_disable(reg_vbus);
-put_np:
if (phy_np)
of_node_put(phy_np);
clk_disable_unprepare(data->clk);
@@ -227,9 +238,6 @@ static int __devexit ci13xxx_imx_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
ci13xxx_remove_device(data->ci_pdev);
- if (data->reg_vbus)
- regulator_disable(data->reg_vbus);
-
if (data->phy) {
usb_phy_shutdown(data->phy);
module_put(data->phy->dev->driver->owner);
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index ebff9f4..e091147 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -106,6 +106,12 @@ static int host_start(struct ci13xxx *ci)
if (usb_disabled())
return -ENODEV;
+ if (ci->platdata->set_vbus_power) {
+ ret = ci->platdata->set_vbus_power(ci, 1);
+ if (ret)
+ return ret;
+ }
+
hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
if (!hcd)
return -ENOMEM;
@@ -138,6 +144,8 @@ static void host_stop(struct ci13xxx *ci)
usb_remove_hcd(hcd);
usb_put_hcd(hcd);
+ if (ci->platdata->set_vbus_power)
+ ci->platdata->set_vbus_power(ci, 0);
}
int ci_hdrc_host_init(struct ci13xxx *ci)
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 544825d..080f479 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -23,6 +23,8 @@ struct ci13xxx_platform_data {
#define CI13XXX_CONTROLLER_RESET_EVENT 0
#define CI13XXX_CONTROLLER_STOPPED_EVENT 1
void (*notify_event) (struct ci13xxx *ci, unsigned event);
+ /* set vbus power, it must be called in non-atomic context */
+ int (*set_vbus_power) (struct ci13xxx *ci, int enable);
};
/* Default offset of capability registers */
--
1.7.9.5
next prev parent reply other threads:[~2012-08-28 7:03 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-28 7:03 [PATCH v2 00/11] chipidea/imx: add otg support and some bug fix Richard Zhao
2012-08-28 7:03 ` [PATCH v2 01/11] USB: chipidea: imx: add pinctrl support Richard Zhao
2012-08-28 7:03 ` [PATCH v2 02/11] USB: chipidea: delay 2ms before read ID status at probe time Richard Zhao
2012-08-28 7:03 ` [PATCH v2 03/11] USB: chipidea: move OTGSC_IDIS clearing from ci_role_work to irq handler Richard Zhao
2012-08-28 7:03 ` [PATCH v2 04/11] USB: chipidea: clear gadget struct at udc_start fail path Richard Zhao
2012-08-28 8:29 ` Alexander Shishkin
2012-08-28 9:09 ` Richard Zhao
2012-08-29 8:03 ` Alexander Shishkin
2012-08-29 8:22 ` Richard Zhao
2012-08-29 9:44 ` Alexander Shishkin
2012-08-29 10:37 ` Richard Zhao
2012-08-28 7:03 ` [PATCH v2 05/11] USB: chipidea: don't let probe fail if otg controller start one role failed Richard Zhao
2012-08-28 8:38 ` Alexander Shishkin
2012-08-28 9:27 ` Richard Zhao
2012-08-29 8:10 ` Alexander Shishkin
2012-08-29 8:33 ` Richard Zhao
2012-08-29 9:48 ` Alexander Shishkin
2012-08-29 10:46 ` Richard Zhao
2012-09-04 14:17 ` Richard Zhao
2012-09-11 7:23 ` Alexander Shishkin
2012-09-11 8:18 ` Richard Zhao
2012-09-12 10:47 ` Alexander Shishkin
2012-09-14 8:35 ` Richard Zhao
2012-09-14 10:25 ` Alexander Shishkin
2012-09-17 8:59 ` Richard Zhao
2012-08-28 7:03 ` [PATCH v2 06/11] USB: mxs-phy: add basic otg support Richard Zhao
2012-09-11 9:05 ` Felipe Balbi
2012-09-12 10:39 ` Heikki Krogerus
2012-09-14 8:30 ` Richard Zhao
2012-09-14 8:56 ` Chen Peter-B29397
2012-09-14 10:53 ` Richard Zhao
2012-08-28 7:03 ` [PATCH v2 07/11] USB: chipidea: add vbus detect for udc Richard Zhao
2012-08-28 7:03 ` [PATCH v2 08/11] USB: chipidea: convert to use devm_request_irq Richard Zhao
2012-08-28 7:03 ` [PATCH v2 09/11] USB: chipidea: add -DDEBUG if CONFIG_USB_CHIPIDEA_DEBUG Richard Zhao
2012-08-28 7:03 ` Richard Zhao [this message]
2012-09-19 1:25 ` [PATCH v2 10/11] USB: chipidea: add set_vbus_power support Richard Zhao
2012-08-28 7:03 ` [PATCH v2 11/11] USB: chipidea: re-order irq handling to avoid unhandled irq Richard Zhao
2012-09-05 14:27 ` [PATCH v2 00/11] chipidea/imx: add otg support and some bug fix Marc Kleine-Budde
2012-09-05 15:01 ` Michael Grzeschik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1346137397-32374-11-git-send-email-richard.zhao@freescale.com \
--to=richard.zhao@freescale.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).