Skip to content

Commit 6cb9310

Browse files
Roger Quadrosgregkh
authored andcommitted
usb: phy: omap: Add new device types and remove omap_control_usb3_phy_power()
Add support for new device types and in the process rid of "ti,type" device tree property. The correct type of device will be determined from the compatible string instead. Introduce a compatible string for each device type. At the moment we support 4 types OTGHS, USB2, PIPE3 (e.g. USB3) and DRA7USB2. Update DT binding information to reflect these changes. Also get rid of omap_control_usb3_phy_power(). Just one function i.e. omap_control_usb_phy_power() will now take care of all PHY types. Signed-off-by: Roger Quadros <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4fd06af commit 6cb9310

File tree

4 files changed

+130
-103
lines changed

4 files changed

+130
-103
lines changed

Documentation/devicetree/bindings/usb/omap-usb.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,22 @@ omap_dwc3 {
8383
OMAP CONTROL USB
8484

8585
Required properties:
86-
- compatible: Should be "ti,omap-control-usb"
86+
- compatible: Should be one of
87+
"ti,control-phy-otghs" - if it has otghs_control mailbox register as on OMAP4.
88+
"ti,control-phy-usb2" - if it has Power down bit in control_dev_conf register
89+
e.g. USB2_PHY on OMAP5.
90+
"ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power control
91+
e.g. USB3 PHY and SATA PHY on OMAP5.
92+
"ti,control-phy-dra7usb2" - if it has power down register like USB2 PHY on
93+
DRA7 platform.
8794
- reg : Address and length of the register set for the device. It contains
88-
the address of "control_dev_conf" and "otghs_control" or "phy_power_usb"
89-
depending upon omap4 or omap5.
90-
- reg-names: The names of the register addresses corresponding to the registers
91-
filled in "reg".
92-
- ti,type: This is used to differentiate whether the control module has
93-
usb mailbox or usb3 phy power. omap4 has usb mailbox in control module to
94-
notify events to the musb core and omap5 has usb3 phy power register to
95-
power on usb3 phy. Should be "1" if it has mailbox and "2" if it has usb3
96-
phy power.
95+
the address of "otghs_control" for control-phy-otghs or "power" register
96+
for other types.
97+
- reg-names: should be "otghs_control" control-phy-otghs and "power" for
98+
other types.
9799

98100
omap_control_usb: omap-control-usb@4a002300 {
99-
compatible = "ti,omap-control-usb";
100-
reg = <0x4a002300 0x4>,
101-
<0x4a00233c 0x4>;
102-
reg-names = "control_dev_conf", "otghs_control";
103-
ti,type = <1>;
101+
compatible = "ti,control-phy-otghs";
102+
reg = <0x4a00233c 0x4>;
103+
reg-names = "otghs_control";
104104
};

drivers/usb/phy/phy-omap-control.c

Lines changed: 100 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/platform_device.h>
2121
#include <linux/slab.h>
2222
#include <linux/of.h>
23+
#include <linux/of_device.h>
2324
#include <linux/err.h>
2425
#include <linux/io.h>
2526
#include <linux/clk.h>
@@ -46,61 +47,70 @@ struct device *omap_get_control_dev(void)
4647
EXPORT_SYMBOL_GPL(omap_get_control_dev);
4748

4849
/**
49-
* omap_control_usb3_phy_power - power on/off the serializer using control
50-
* module
50+
* omap_control_usb_phy_power - power on/off the phy using control module reg
5151
* @dev: the control module device
52-
* @on: 0 to off and 1 to on based on powering on or off the PHY
53-
*
54-
* usb3 PHY driver should call this API to power on or off the PHY.
52+
* @on: 0 or 1, based on powering on or off the PHY
5553
*/
56-
void omap_control_usb3_phy_power(struct device *dev, bool on)
54+
void omap_control_usb_phy_power(struct device *dev, int on)
5755
{
5856
u32 val;
5957
unsigned long rate;
60-
struct omap_control_usb *control_usb = dev_get_drvdata(dev);
58+
struct omap_control_usb *control_usb;
6159

62-
if (control_usb->type != OMAP_CTRL_DEV_TYPE2)
60+
if (IS_ERR(dev) || !dev) {
61+
pr_err("%s: invalid device\n", __func__);
6362
return;
63+
}
6464

65-
rate = clk_get_rate(control_usb->sys_clk);
66-
rate = rate/1000000;
67-
68-
val = readl(control_usb->phy_power);
69-
70-
if (on) {
71-
val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
72-
OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
73-
val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
74-
OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
75-
val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
76-
} else {
77-
val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
78-
val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
79-
OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
65+
control_usb = dev_get_drvdata(dev);
66+
if (!control_usb) {
67+
dev_err(dev, "%s: invalid control usb device\n", __func__);
68+
return;
8069
}
8170

82-
writel(val, control_usb->phy_power);
83-
}
84-
EXPORT_SYMBOL_GPL(omap_control_usb3_phy_power);
71+
if (control_usb->type == OMAP_CTRL_TYPE_OTGHS)
72+
return;
8573

86-
/**
87-
* omap_control_usb_phy_power - power on/off the phy using control module reg
88-
* @dev: the control module device
89-
* @on: 0 or 1, based on powering on or off the PHY
90-
*/
91-
void omap_control_usb_phy_power(struct device *dev, int on)
92-
{
93-
u32 val;
94-
struct omap_control_usb *control_usb = dev_get_drvdata(dev);
74+
val = readl(control_usb->power);
75+
76+
switch (control_usb->type) {
77+
case OMAP_CTRL_TYPE_USB2:
78+
if (on)
79+
val &= ~OMAP_CTRL_DEV_PHY_PD;
80+
else
81+
val |= OMAP_CTRL_DEV_PHY_PD;
82+
break;
9583

96-
val = readl(control_usb->dev_conf);
84+
case OMAP_CTRL_TYPE_PIPE3:
85+
rate = clk_get_rate(control_usb->sys_clk);
86+
rate = rate/1000000;
87+
88+
if (on) {
89+
val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
90+
OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
91+
val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
92+
OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
93+
val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
94+
} else {
95+
val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
96+
val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
97+
OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
98+
}
99+
break;
97100

98-
if (on)
99-
val &= ~OMAP_CTRL_DEV_PHY_PD;
100-
else
101-
val |= OMAP_CTRL_DEV_PHY_PD;
101+
case OMAP_CTRL_TYPE_DRA7USB2:
102+
if (on)
103+
val &= ~OMAP_CTRL_USB2_PHY_PD;
104+
else
105+
val |= OMAP_CTRL_USB2_PHY_PD;
106+
break;
107+
default:
108+
dev_err(dev, "%s: type %d not recognized\n",
109+
__func__, control_usb->type);
110+
break;
111+
}
102112

103-
writel(val, control_usb->dev_conf);
113+
writel(val, control_usb->power);
104114
}
105115
EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
106116

@@ -172,7 +182,7 @@ void omap_control_usb_set_mode(struct device *dev,
172182
{
173183
struct omap_control_usb *ctrl_usb;
174184

175-
if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_DEV_TYPE1)
185+
if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_TYPE_OTGHS)
176186
return;
177187

178188
ctrl_usb = dev_get_drvdata(dev);
@@ -193,10 +203,45 @@ void omap_control_usb_set_mode(struct device *dev,
193203
}
194204
EXPORT_SYMBOL_GPL(omap_control_usb_set_mode);
195205

206+
#ifdef CONFIG_OF
207+
208+
static const enum omap_control_usb_type otghs_data = OMAP_CTRL_TYPE_OTGHS;
209+
static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2;
210+
static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3;
211+
static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2;
212+
213+
static const struct of_device_id omap_control_usb_id_table[] = {
214+
{
215+
.compatible = "ti,control-phy-otghs",
216+
.data = &otghs_data,
217+
},
218+
{
219+
.compatible = "ti,control-phy-usb2",
220+
.data = &usb2_data,
221+
},
222+
{
223+
.compatible = "ti,control-phy-pipe3",
224+
.data = &pipe3_data,
225+
},
226+
{
227+
.compatible = "ti,control-phy-dra7usb2",
228+
.data = &dra7usb2_data,
229+
},
230+
{},
231+
};
232+
MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
233+
#endif
234+
235+
196236
static int omap_control_usb_probe(struct platform_device *pdev)
197237
{
198238
struct resource *res;
199-
struct device_node *np = pdev->dev.of_node;
239+
const struct of_device_id *of_id;
240+
241+
of_id = of_match_device(of_match_ptr(omap_control_usb_id_table),
242+
&pdev->dev);
243+
if (!of_id)
244+
return -EINVAL;
200245

201246
control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
202247
GFP_KERNEL);
@@ -205,36 +250,27 @@ static int omap_control_usb_probe(struct platform_device *pdev)
205250
return -ENOMEM;
206251
}
207252

208-
if (np)
209-
of_property_read_u32(np, "ti,type", &control_usb->type);
210-
else
211-
return -EINVAL; /* We only support DT boot */
212-
213-
control_usb->dev = &pdev->dev;
253+
control_usb->dev = &pdev->dev;
254+
control_usb->type = *(enum omap_control_usb_type *)of_id->data;
214255

215-
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
216-
"control_dev_conf");
217-
control_usb->dev_conf = devm_ioremap_resource(&pdev->dev, res);
218-
if (IS_ERR(control_usb->dev_conf))
219-
return PTR_ERR(control_usb->dev_conf);
220-
221-
if (control_usb->type == OMAP_CTRL_DEV_TYPE1) {
256+
if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) {
222257
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
223258
"otghs_control");
224259
control_usb->otghs_control = devm_ioremap_resource(
225260
&pdev->dev, res);
226261
if (IS_ERR(control_usb->otghs_control))
227262
return PTR_ERR(control_usb->otghs_control);
228-
}
229-
230-
if (control_usb->type == OMAP_CTRL_DEV_TYPE2) {
263+
} else {
231264
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
232-
"phy_power_usb");
233-
control_usb->phy_power = devm_ioremap_resource(
234-
&pdev->dev, res);
235-
if (IS_ERR(control_usb->phy_power))
236-
return PTR_ERR(control_usb->phy_power);
265+
"power");
266+
control_usb->power = devm_ioremap_resource(&pdev->dev, res);
267+
if (IS_ERR(control_usb->power)) {
268+
dev_err(&pdev->dev, "Couldn't get power register\n");
269+
return PTR_ERR(control_usb->power);
270+
}
271+
}
237272

273+
if (control_usb->type == OMAP_CTRL_TYPE_PIPE3) {
238274
control_usb->sys_clk = devm_clk_get(control_usb->dev,
239275
"sys_clkin");
240276
if (IS_ERR(control_usb->sys_clk)) {
@@ -243,20 +279,11 @@ static int omap_control_usb_probe(struct platform_device *pdev)
243279
}
244280
}
245281

246-
247282
dev_set_drvdata(control_usb->dev, control_usb);
248283

249284
return 0;
250285
}
251286

252-
#ifdef CONFIG_OF
253-
static const struct of_device_id omap_control_usb_id_table[] = {
254-
{ .compatible = "ti,omap-control-usb" },
255-
{}
256-
};
257-
MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
258-
#endif
259-
260287
static struct platform_driver omap_control_usb_driver = {
261288
.probe = omap_control_usb_probe,
262289
.driver = {

drivers/usb/phy/phy-omap-usb3.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static int omap_usb3_suspend(struct usb_phy *x, int suspend)
100100
udelay(1);
101101
} while (--timeout);
102102

103-
omap_control_usb3_phy_power(phy->control_dev, 0);
103+
omap_control_usb_phy_power(phy->control_dev, 0);
104104

105105
phy->is_suspended = 1;
106106
} else if (!suspend && phy->is_suspended) {
@@ -189,7 +189,7 @@ static int omap_usb3_init(struct usb_phy *x)
189189
if (ret)
190190
return ret;
191191

192-
omap_control_usb3_phy_power(phy->control_dev, 1);
192+
omap_control_usb_phy_power(phy->control_dev, 1);
193193

194194
return 0;
195195
}
@@ -245,7 +245,7 @@ static int omap_usb3_probe(struct platform_device *pdev)
245245
return -ENODEV;
246246
}
247247

248-
omap_control_usb3_phy_power(phy->control_dev, 0);
248+
omap_control_usb_phy_power(phy->control_dev, 0);
249249
usb_add_phy_dev(&phy->phy);
250250

251251
platform_set_drvdata(pdev, phy);

include/linux/usb/omap_control_usb.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@
1919
#ifndef __OMAP_CONTROL_USB_H__
2020
#define __OMAP_CONTROL_USB_H__
2121

22+
enum omap_control_usb_type {
23+
OMAP_CTRL_TYPE_OTGHS = 1, /* Mailbox OTGHS_CONTROL */
24+
OMAP_CTRL_TYPE_USB2, /* USB2_PHY, power down in CONTROL_DEV_CONF */
25+
OMAP_CTRL_TYPE_PIPE3, /* PIPE3 PHY, DPLL & seperate Rx/Tx power */
26+
OMAP_CTRL_TYPE_DRA7USB2, /* USB2 PHY, power and power_aux e.g. DRA7 */
27+
};
28+
2229
struct omap_control_usb {
2330
struct device *dev;
2431

25-
u32 __iomem *dev_conf;
2632
u32 __iomem *otghs_control;
27-
u32 __iomem *phy_power;
33+
u32 __iomem *power;
34+
u32 __iomem *power_aux;
2835

2936
struct clk *sys_clk;
3037

31-
u32 type;
38+
enum omap_control_usb_type type;
3239
};
3340

3441
enum omap_control_usb_mode {
@@ -38,10 +45,6 @@ enum omap_control_usb_mode {
3845
USB_MODE_DISCONNECT,
3946
};
4047

41-
/* To differentiate ctrl module IP having either mailbox or USB3 PHY power */
42-
#define OMAP_CTRL_DEV_TYPE1 0x1
43-
#define OMAP_CTRL_DEV_TYPE2 0x2
44-
4548
#define OMAP_CTRL_DEV_PHY_PD BIT(0)
4649

4750
#define OMAP_CTRL_DEV_AVALID BIT(0)
@@ -59,10 +62,11 @@ enum omap_control_usb_mode {
5962
#define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3
6063
#define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0
6164

65+
#define OMAP_CTRL_USB2_PHY_PD BIT(28)
66+
6267
#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
6368
extern struct device *omap_get_control_dev(void);
6469
extern void omap_control_usb_phy_power(struct device *dev, int on);
65-
extern void omap_control_usb3_phy_power(struct device *dev, bool on);
6670
extern void omap_control_usb_set_mode(struct device *dev,
6771
enum omap_control_usb_mode mode);
6872
#else
@@ -75,10 +79,6 @@ static inline void omap_control_usb_phy_power(struct device *dev, int on)
7579
{
7680
}
7781

78-
static inline void omap_control_usb3_phy_power(struct device *dev, int on)
79-
{
80-
}
81-
8282
static inline void omap_control_usb_set_mode(struct device *dev,
8383
enum omap_control_usb_mode mode)
8484
{

0 commit comments

Comments
 (0)