1 #include <linux/module.h>
2 #include <linux/platform_device.h>
6 #include <linux/delay.h>
7 #include "am35x-phy-control.h"
9 struct am335x_control_usb
{
11 void __iomem
*phy_reg
;
14 struct phy_control phy_ctrl
;
17 #define AM335X_USB0_CTRL 0x0
18 #define AM335X_USB1_CTRL 0x8
19 #define AM335x_USB_WKUP 0x0
21 #define USBPHY_CM_PWRDN (1 << 0)
22 #define USBPHY_OTG_PWRDN (1 << 1)
23 #define USBPHY_OTGVDET_EN (1 << 19)
24 #define USBPHY_OTGSESSEND_EN (1 << 20)
26 #define AM335X_PHY0_WK_EN (1 << 0)
27 #define AM335X_PHY1_WK_EN (1 << 8)
29 static void am335x_phy_wkup(struct phy_control
*phy_ctrl
, u32 id
, bool on
)
31 struct am335x_control_usb
*usb_ctrl
;
35 usb_ctrl
= container_of(phy_ctrl
, struct am335x_control_usb
, phy_ctrl
);
39 reg
= AM335X_PHY0_WK_EN
;
42 reg
= AM335X_PHY1_WK_EN
;
49 spin_lock(&usb_ctrl
->lock
);
50 val
= readl(usb_ctrl
->wkup
);
57 writel(val
, usb_ctrl
->wkup
);
58 spin_unlock(&usb_ctrl
->lock
);
61 static void am335x_phy_power(struct phy_control
*phy_ctrl
, u32 id
, bool on
)
63 struct am335x_control_usb
*usb_ctrl
;
67 usb_ctrl
= container_of(phy_ctrl
, struct am335x_control_usb
, phy_ctrl
);
71 reg
= AM335X_USB0_CTRL
;
74 reg
= AM335X_USB1_CTRL
;
81 val
= readl(usb_ctrl
->phy_reg
+ reg
);
83 val
&= ~(USBPHY_CM_PWRDN
| USBPHY_OTG_PWRDN
);
84 val
|= USBPHY_OTGVDET_EN
| USBPHY_OTGSESSEND_EN
;
86 val
|= USBPHY_CM_PWRDN
| USBPHY_OTG_PWRDN
;
89 writel(val
, usb_ctrl
->phy_reg
+ reg
);
92 * Give the PHY ~1ms to complete the power up operation.
93 * Tests have shown unstable behaviour if other USB PHY related
94 * registers are written too shortly after such a transition.
100 static const struct phy_control ctrl_am335x
= {
101 .phy_power
= am335x_phy_power
,
102 .phy_wkup
= am335x_phy_wkup
,
105 static const struct of_device_id omap_control_usb_id_table
[] = {
106 { .compatible
= "ti,am335x-usb-ctrl-module", .data
= &ctrl_am335x
},
109 MODULE_DEVICE_TABLE(of
, omap_control_usb_id_table
);
111 static struct platform_driver am335x_control_driver
;
112 static int match(struct device
*dev
, void *data
)
114 struct device_node
*node
= (struct device_node
*)data
;
115 return dev
->of_node
== node
&&
116 dev
->driver
== &am335x_control_driver
.driver
;
119 struct phy_control
*am335x_get_phy_control(struct device
*dev
)
121 struct device_node
*node
;
122 struct am335x_control_usb
*ctrl_usb
;
124 node
= of_parse_phandle(dev
->of_node
, "ti,ctrl_mod", 0);
128 dev
= bus_find_device(&platform_bus_type
, NULL
, node
, match
);
132 ctrl_usb
= dev_get_drvdata(dev
);
135 return &ctrl_usb
->phy_ctrl
;
137 EXPORT_SYMBOL_GPL(am335x_get_phy_control
);
139 static int am335x_control_usb_probe(struct platform_device
*pdev
)
141 struct resource
*res
;
142 struct am335x_control_usb
*ctrl_usb
;
143 const struct of_device_id
*of_id
;
144 const struct phy_control
*phy_ctrl
;
146 of_id
= of_match_node(omap_control_usb_id_table
, pdev
->dev
.of_node
);
150 phy_ctrl
= of_id
->data
;
152 ctrl_usb
= devm_kzalloc(&pdev
->dev
, sizeof(*ctrl_usb
), GFP_KERNEL
);
156 ctrl_usb
->dev
= &pdev
->dev
;
158 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "phy_ctrl");
159 ctrl_usb
->phy_reg
= devm_ioremap_resource(&pdev
->dev
, res
);
160 if (IS_ERR(ctrl_usb
->phy_reg
))
161 return PTR_ERR(ctrl_usb
->phy_reg
);
163 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "wakeup");
164 ctrl_usb
->wkup
= devm_ioremap_resource(&pdev
->dev
, res
);
165 if (IS_ERR(ctrl_usb
->wkup
))
166 return PTR_ERR(ctrl_usb
->wkup
);
168 spin_lock_init(&ctrl_usb
->lock
);
169 ctrl_usb
->phy_ctrl
= *phy_ctrl
;
171 dev_set_drvdata(ctrl_usb
->dev
, ctrl_usb
);
175 static struct platform_driver am335x_control_driver
= {
176 .probe
= am335x_control_usb_probe
,
178 .name
= "am335x-control-usb",
179 .of_match_table
= omap_control_usb_id_table
,
183 module_platform_driver(am335x_control_driver
);
184 MODULE_LICENSE("GPL v2");