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)
4647EXPORT_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}
105115EXPORT_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}
194204EXPORT_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+
196236static 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-
260287static struct platform_driver omap_control_usb_driver = {
261288 .probe = omap_control_usb_probe ,
262289 .driver = {
0 commit comments