Skip to content

Commit 1542d9c

Browse files
Peter Chengregkh
authored andcommitted
usb: chipidea: move vbus regulator operation to core
The vbus regulator is a common element for USB vbus operation, So, move it from glue layer to core. Tested-by: Marek Vasut <[email protected]> Signed-off-by: Michael Grzeschik <[email protected]> Signed-off-by: Peter Chen <[email protected]> Signed-off-by: Alexander Shishkin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6a6243b commit 1542d9c

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

drivers/usb/chipidea/ci_hdrc_imx.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/dma-mapping.h>
2020
#include <linux/usb/chipidea.h>
2121
#include <linux/clk.h>
22-
#include <linux/regulator/consumer.h>
2322

2423
#include "ci.h"
2524
#include "ci_hdrc_imx.h"
@@ -28,7 +27,6 @@ struct ci_hdrc_imx_data {
2827
struct usb_phy *phy;
2928
struct platform_device *ci_pdev;
3029
struct clk *clk;
31-
struct regulator *reg_vbus;
3230
};
3331

3432
static const struct usbmisc_ops *usbmisc_ops;
@@ -131,20 +129,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
131129
goto err_clk;
132130
}
133131

134-
/* we only support host now, so enable vbus here */
135-
data->reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
136-
if (!IS_ERR(data->reg_vbus)) {
137-
ret = regulator_enable(data->reg_vbus);
138-
if (ret) {
139-
dev_err(&pdev->dev,
140-
"Failed to enable vbus regulator, err=%d\n",
141-
ret);
142-
goto err_clk;
143-
}
144-
} else {
145-
data->reg_vbus = NULL;
146-
}
147-
148132
pdata.phy = data->phy;
149133

150134
if (!pdev->dev.dma_mask)
@@ -157,7 +141,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
157141
if (ret) {
158142
dev_err(&pdev->dev,
159143
"usbmisc init failed, ret=%d\n", ret);
160-
goto err;
144+
goto err_clk;
161145
}
162146
}
163147

@@ -169,7 +153,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
169153
dev_err(&pdev->dev,
170154
"Can't register ci_hdrc platform device, err=%d\n",
171155
ret);
172-
goto err;
156+
goto err_clk;
173157
}
174158

175159
if (usbmisc_ops && usbmisc_ops->post) {
@@ -190,9 +174,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
190174

191175
disable_device:
192176
ci_hdrc_remove_device(data->ci_pdev);
193-
err:
194-
if (data->reg_vbus)
195-
regulator_disable(data->reg_vbus);
196177
err_clk:
197178
clk_disable_unprepare(data->clk);
198179
return ret;
@@ -205,9 +186,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
205186
pm_runtime_disable(&pdev->dev);
206187
ci_hdrc_remove_device(data->ci_pdev);
207188

208-
if (data->reg_vbus)
209-
regulator_disable(data->reg_vbus);
210-
211189
if (data->phy)
212190
usb_phy_shutdown(data->phy);
213191

drivers/usb/chipidea/core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <linux/usb/chipidea.h>
6666
#include <linux/usb/of.h>
6767
#include <linux/phy.h>
68+
#include <linux/regulator/consumer.h>
6869

6970
#include "ci.h"
7071
#include "udc.h"
@@ -342,6 +343,24 @@ static irqreturn_t ci_irq(int irq, void *data)
342343
return ret;
343344
}
344345

346+
static int ci_get_platdata(struct device *dev,
347+
struct ci_hdrc_platform_data *platdata)
348+
{
349+
/* Get the vbus regulator */
350+
platdata->reg_vbus = devm_regulator_get(dev, "vbus");
351+
if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
352+
return -EPROBE_DEFER;
353+
} else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
354+
platdata->reg_vbus = NULL; /* no vbus regualator is needed */
355+
} else if (IS_ERR(platdata->reg_vbus)) {
356+
dev_err(dev, "Getting regulator error: %ld\n",
357+
PTR_ERR(platdata->reg_vbus));
358+
return PTR_ERR(platdata->reg_vbus);
359+
}
360+
361+
return 0;
362+
}
363+
345364
static DEFINE_IDA(ci_ida);
346365

347366
struct platform_device *ci_hdrc_add_device(struct device *dev,
@@ -351,6 +370,10 @@ struct platform_device *ci_hdrc_add_device(struct device *dev,
351370
struct platform_device *pdev;
352371
int id, ret;
353372

373+
ret = ci_get_platdata(dev, platdata);
374+
if (ret)
375+
return ERR_PTR(ret);
376+
354377
id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
355378
if (id < 0)
356379
return ERR_PTR(id);

include/linux/usb/chipidea.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ci_hdrc_platform_data {
2424
#define CI_HDRC_CONTROLLER_RESET_EVENT 0
2525
#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
2626
void (*notify_event) (struct ci_hdrc *ci, unsigned event);
27+
struct regulator *reg_vbus;
2728
};
2829

2930
/* Default offset of capability registers */

0 commit comments

Comments
 (0)