Skip to content

Commit ca784be

Browse files
kishonFelipe Balbi
authored andcommitted
usb: start using the control module driver
Start using the control module driver for powering on the PHY and for writing to the mailbox instead of writing to the control module registers on their own. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
1 parent 01658f0 commit ca784be

8 files changed

Lines changed: 40 additions & 95 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
33
OMAP MUSB GLUE
44
- compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
55
- ti,hwmods : must be "usb_otg_hs"
6+
- ti,has-mailbox : to specify that omap uses an external mailbox
7+
(in control module) to communicate with the musb core during device connect
8+
and disconnect.
69
- multipoint : Should be "1" indicating the musb controller supports
710
multipoint. This is a MUSB configuration-specific setting.
811
- num_eps : Specifies the number of endpoints. This is also a
@@ -24,6 +27,7 @@ SOC specific device node entry
2427
usb_otg_hs: usb_otg_hs@4a0ab000 {
2528
compatible = "ti,omap4-musb";
2629
ti,hwmods = "usb_otg_hs";
30+
ti,has-mailbox;
2731
multipoint = <1>;
2832
num_eps = <16>;
2933
ram_bits = <12>;

‎Documentation/devicetree/bindings/usb/usb-phy.txt‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ OMAP USB2 PHY
44

55
Required properties:
66
- compatible: Should be "ti,omap-usb2"
7-
- reg : Address and length of the register set for the device. Also
8-
add the address of control module dev conf register until a driver for
9-
control module is added
7+
- reg : Address and length of the register set for the device.
108

119
Optional properties:
1210
- ctrl-module : phandle of the control module used by PHY driver to power on
@@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected.
1614

1715
usb2phy@4a0ad080 {
1816
compatible = "ti,omap-usb2";
19-
reg = <0x4a0ad080 0x58>,
20-
<0x4a002300 0x4>;
17+
reg = <0x4a0ad080 0x58>;
2118
ctrl-module = <&omap_control_usb>;
2219
};

‎drivers/usb/musb/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config USB_MUSB_HDRC
1111
select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX)
1212
select TWL4030_USB if MACH_OMAP_3430SDP
1313
select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
14+
select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
1415
select USB_OTG_UTILS
1516
help
1617
Say Y here if your system has a dual role high speed USB

‎drivers/usb/musb/omap2430.c‎

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/err.h>
3838
#include <linux/delay.h>
3939
#include <linux/usb/musb-omap.h>
40+
#include <linux/usb/omap_control_usb.h>
4041

4142
#include "musb_core.h"
4243
#include "omap2430.h"
@@ -46,34 +47,14 @@ struct omap2430_glue {
4647
struct platform_device *musb;
4748
enum omap_musb_vbus_id_status status;
4849
struct work_struct omap_musb_mailbox_work;
49-
u32 __iomem *control_otghs;
50+
struct device *control_otghs;
5051
};
5152
#define glue_to_musb(g) platform_get_drvdata(g->musb)
5253

5354
struct omap2430_glue *_glue;
5455

5556
static struct timer_list musb_idle_timer;
5657

57-
/**
58-
* omap4_usb_phy_mailbox - write to usb otg mailbox
59-
* @glue: struct omap2430_glue *
60-
* @val: the value to be written to the mailbox
61-
*
62-
* On detection of a device (ID pin is grounded), this API should be called
63-
* to set AVALID, VBUSVALID and ID pin is grounded.
64-
*
65-
* When OMAP is connected to a host (OMAP in device mode), this API
66-
* is called to set AVALID, VBUSVALID and ID pin in high impedance.
67-
*
68-
* XXX: This function will be removed once we have a seperate driver for
69-
* control module
70-
*/
71-
static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val)
72-
{
73-
if (glue->control_otghs)
74-
writel(val, glue->control_otghs);
75-
}
76-
7758
static void musb_do_idle(unsigned long _musb)
7859
{
7960
struct musb *musb = (void *)_musb;
@@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);
269250

270251
static void omap_musb_set_mailbox(struct omap2430_glue *glue)
271252
{
272-
u32 val;
273253
struct musb *musb = glue_to_musb(glue);
274254
struct device *dev = musb->controller;
275255
struct musb_hdrc_platform_data *pdata = dev->platform_data;
@@ -285,8 +265,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
285265
musb->xceiv->last_event = USB_EVENT_ID;
286266
if (musb->gadget_driver) {
287267
pm_runtime_get_sync(dev);
288-
val = AVALID | VBUSVALID;
289-
omap4_usb_phy_mailbox(glue, val);
268+
omap_control_usb_set_mode(glue->control_otghs,
269+
USB_MODE_HOST);
290270
omap2430_musb_set_vbus(musb, 1);
291271
}
292272
break;
@@ -299,8 +279,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
299279
musb->xceiv->last_event = USB_EVENT_VBUS;
300280
if (musb->gadget_driver)
301281
pm_runtime_get_sync(dev);
302-
val = IDDIG | AVALID | VBUSVALID;
303-
omap4_usb_phy_mailbox(glue, val);
282+
omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
304283
break;
305284

306285
case OMAP_MUSB_ID_FLOAT:
@@ -317,8 +296,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
317296
if (musb->xceiv->otg->set_vbus)
318297
otg_set_vbus(musb->xceiv->otg, 0);
319298
}
320-
val = SESSEND | IDDIG;
321-
omap4_usb_phy_mailbox(glue, val);
299+
omap_control_usb_set_mode(glue->control_otghs,
300+
USB_MODE_DISCONNECT);
322301
break;
323302
default:
324303
dev_dbg(dev, "ID float\n");
@@ -415,7 +394,6 @@ static int omap2430_musb_init(struct musb *musb)
415394
static void omap2430_musb_enable(struct musb *musb)
416395
{
417396
u8 devctl;
418-
u32 val;
419397
unsigned long timeout = jiffies + msecs_to_jiffies(1000);
420398
struct device *dev = musb->controller;
421399
struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
@@ -425,8 +403,7 @@ static void omap2430_musb_enable(struct musb *musb)
425403
switch (glue->status) {
426404

427405
case OMAP_MUSB_ID_GROUND:
428-
val = AVALID | VBUSVALID;
429-
omap4_usb_phy_mailbox(glue, val);
406+
omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST);
430407
if (data->interface_type != MUSB_INTERFACE_UTMI)
431408
break;
432409
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -445,8 +422,7 @@ static void omap2430_musb_enable(struct musb *musb)
445422
break;
446423

447424
case OMAP_MUSB_VBUS_VALID:
448-
val = IDDIG | AVALID | VBUSVALID;
449-
omap4_usb_phy_mailbox(glue, val);
425+
omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
450426
break;
451427

452428
default:
@@ -456,14 +432,12 @@ static void omap2430_musb_enable(struct musb *musb)
456432

457433
static void omap2430_musb_disable(struct musb *musb)
458434
{
459-
u32 val;
460435
struct device *dev = musb->controller;
461436
struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
462437

463-
if (glue->status != OMAP_MUSB_UNKNOWN) {
464-
val = SESSEND | IDDIG;
465-
omap4_usb_phy_mailbox(glue, val);
466-
}
438+
if (glue->status != OMAP_MUSB_UNKNOWN)
439+
omap_control_usb_set_mode(glue->control_otghs,
440+
USB_MODE_DISCONNECT);
467441
}
468442

469443
static int omap2430_musb_exit(struct musb *musb)
@@ -498,7 +472,6 @@ static int omap2430_probe(struct platform_device *pdev)
498472
struct omap2430_glue *glue;
499473
struct device_node *np = pdev->dev.of_node;
500474
struct musb_hdrc_config *config;
501-
struct resource *res;
502475
int ret = -ENOMEM;
503476

504477
glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
@@ -521,12 +494,6 @@ static int omap2430_probe(struct platform_device *pdev)
521494
glue->musb = musb;
522495
glue->status = OMAP_MUSB_UNKNOWN;
523496

524-
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
525-
526-
glue->control_otghs = devm_request_and_ioremap(&pdev->dev, res);
527-
if (glue->control_otghs == NULL)
528-
dev_dbg(&pdev->dev, "Failed to obtain control memory\n");
529-
530497
if (np) {
531498
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
532499
if (!pdata) {
@@ -558,11 +525,22 @@ static int omap2430_probe(struct platform_device *pdev)
558525
of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits);
559526
of_property_read_u32(np, "power", (u32 *)&pdata->power);
560527
config->multipoint = of_property_read_bool(np, "multipoint");
528+
pdata->has_mailbox = of_property_read_bool(np,
529+
"ti,has-mailbox");
561530

562531
pdata->board_data = data;
563532
pdata->config = config;
564533
}
565534

535+
if (pdata->has_mailbox) {
536+
glue->control_otghs = omap_get_control_dev();
537+
if (IS_ERR(glue->control_otghs)) {
538+
dev_vdbg(&pdev->dev, "Failed to get control device\n");
539+
return -ENODEV;
540+
}
541+
} else {
542+
glue->control_otghs = ERR_PTR(-ENODEV);
543+
}
566544
pdata->platform_ops = &omap2430_ops;
567545

568546
platform_set_drvdata(pdev, glue);

‎drivers/usb/musb/omap2430.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,4 @@
4949
#define OTG_FORCESTDBY 0x414
5050
# define ENABLEFORCE (1 << 0)
5151

52-
/*
53-
* Control Module bit definitions
54-
* XXX: Will be removed once we have a driver for control module.
55-
*/
56-
#define AVALID BIT(0)
57-
#define BVALID BIT(1)
58-
#define VBUSVALID BIT(2)
59-
#define SESSEND BIT(3)
60-
#define IDDIG BIT(4)
6152
#endif /* __MUSB_OMAP243X_H__ */

‎drivers/usb/phy/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config OMAP_USB2
88
tristate "OMAP USB2 PHY Driver"
99
depends on ARCH_OMAP2PLUS
1010
select USB_OTG_UTILS
11+
select OMAP_CONTROL_USB
1112
help
1213
Enable this to support the transceiver that is part of SOC. This
1314
driver takes care of all the PHY functionality apart from comparator.

‎drivers/usb/phy/omap-usb2.c‎

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/err.h>
2828
#include <linux/pm_runtime.h>
2929
#include <linux/delay.h>
30+
#include <linux/usb/omap_control_usb.h>
3031

3132
/**
3233
* omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -52,29 +53,6 @@ int omap_usb2_set_comparator(struct phy_companion *comparator)
5253
}
5354
EXPORT_SYMBOL_GPL(omap_usb2_set_comparator);
5455

55-
/**
56-
* omap_usb_phy_power - power on/off the phy using control module reg
57-
* @phy: struct omap_usb *
58-
* @on: 0 or 1, based on powering on or off the PHY
59-
*
60-
* XXX: Remove this function once control module driver gets merged
61-
*/
62-
static void omap_usb_phy_power(struct omap_usb *phy, int on)
63-
{
64-
u32 val;
65-
66-
if (on) {
67-
val = readl(phy->control_dev);
68-
if (val & PHY_PD) {
69-
writel(~PHY_PD, phy->control_dev);
70-
/* XXX: add proper documentation for this delay */
71-
mdelay(200);
72-
}
73-
} else {
74-
writel(PHY_PD, phy->control_dev);
75-
}
76-
}
77-
7856
static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled)
7957
{
8058
struct omap_usb *phy = phy_to_omapusb(otg->phy);
@@ -124,7 +102,7 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
124102
struct omap_usb *phy = phy_to_omapusb(x);
125103

126104
if (suspend && !phy->is_suspended) {
127-
omap_usb_phy_power(phy, 0);
105+
omap_control_usb_phy_power(phy->control_dev, 0);
128106
pm_runtime_put_sync(phy->dev);
129107
phy->is_suspended = 1;
130108
} else if (!suspend && phy->is_suspended) {
@@ -134,7 +112,7 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
134112
ret);
135113
return ret;
136114
}
137-
omap_usb_phy_power(phy, 1);
115+
omap_control_usb_phy_power(phy->control_dev, 1);
138116
phy->is_suspended = 0;
139117
}
140118

@@ -145,7 +123,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
145123
{
146124
struct omap_usb *phy;
147125
struct usb_otg *otg;
148-
struct resource *res;
149126

150127
phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
151128
if (!phy) {
@@ -166,16 +143,14 @@ static int omap_usb2_probe(struct platform_device *pdev)
166143
phy->phy.set_suspend = omap_usb2_suspend;
167144
phy->phy.otg = otg;
168145

169-
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
170-
171-
phy->control_dev = devm_request_and_ioremap(&pdev->dev, res);
172-
if (phy->control_dev == NULL) {
173-
dev_err(&pdev->dev, "Failed to obtain io memory\n");
174-
return -ENXIO;
146+
phy->control_dev = omap_get_control_dev();
147+
if (IS_ERR(phy->control_dev)) {
148+
dev_dbg(&pdev->dev, "Failed to get control device\n");
149+
return -ENODEV;
175150
}
176151

177152
phy->is_suspended = 1;
178-
omap_usb_phy_power(phy, 0);
153+
omap_control_usb_phy_power(phy->control_dev, 0);
179154

180155
otg->set_host = omap_usb_set_host;
181156
otg->set_peripheral = omap_usb_set_peripheral;

‎include/linux/usb/omap_usb.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ struct omap_usb {
2525
struct usb_phy phy;
2626
struct phy_companion *comparator;
2727
struct device *dev;
28-
u32 __iomem *control_dev;
28+
struct device *control_dev;
2929
struct clk *wkupclk;
3030
u8 is_suspended:1;
3131
};
3232

33-
#define PHY_PD 0x1
34-
3533
#define phy_to_omapusb(x) container_of((x), struct omap_usb, phy)
3634

3735
#if defined(CONFIG_OMAP_USB2) || defined(CONFIG_OMAP_USB2_MODULE)

0 commit comments

Comments
 (0)