aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Haslam <ahaslam@baylibre.com>2016-11-23 13:06:46 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-11-29 11:31:35 -0500
commitf3c56fb39658a3f81ffe878628109075a023c935 (patch)
tree7289964ac490a6fd503892bcbf2165cd09d26c46
parentc7a4f9f35b5770263f984ab7a6ca2dcf5de1f24f (diff)
USB: ohci: da8xx: Add wrappers for platform callbacks
To migrate to a DT based boot, we will remove the use of platform callbacks, in favor of using the regulator framework to handle vbus and over current. In preparation to use a regulator instead of callbacks, move the platform data callbacks into separate functions. This provides well defined place to for the regulator API to coexist with the platform callbacks before all users are converted. Signed-off-by: Axel Haslam <ahaslam@baylibre.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/host/ohci-da8xx.c125
1 files changed, 102 insertions, 23 deletions
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index aa6f904fd1dd..90763ad5c4eb 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -81,6 +81,72 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)
81 clk_disable_unprepare(da8xx_ohci->usb11_clk); 81 clk_disable_unprepare(da8xx_ohci->usb11_clk);
82} 82}
83 83
84static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
85{
86 struct device *dev = hcd->self.controller;
87 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
88
89 if (hub && hub->set_power)
90 return hub->set_power(1, on);
91
92 return 0;
93}
94
95static int ohci_da8xx_get_power(struct usb_hcd *hcd)
96{
97 struct device *dev = hcd->self.controller;
98 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
99
100 if (hub && hub->get_power)
101 return hub->get_power(1);
102
103 return 1;
104}
105
106static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
107{
108 struct device *dev = hcd->self.controller;
109 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
110
111 if (hub && hub->get_oci)
112 return hub->get_oci(1);
113
114 return 0;
115}
116
117static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
118{
119 struct device *dev = hcd->self.controller;
120 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
121
122 if (hub && hub->set_power)
123 return 1;
124
125 return 0;
126}
127
128static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
129{
130 struct device *dev = hcd->self.controller;
131 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
132
133 if (hub && hub->get_oci)
134 return 1;
135
136 return 0;
137}
138
139static int ohci_da8xx_has_potpgt(struct usb_hcd *hcd)
140{
141 struct device *dev = hcd->self.controller;
142 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
143
144 if (hub && hub->potpgt)
145 return 1;
146
147 return 0;
148}
149
84/* 150/*
85 * Handle the port over-current indicator change. 151 * Handle the port over-current indicator change.
86 */ 152 */
@@ -94,6 +160,26 @@ static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub,
94 hub->set_power(port, 0); 160 hub->set_power(port, 0);
95} 161}
96 162
163static int ohci_da8xx_register_notify(struct usb_hcd *hcd)
164{
165 struct device *dev = hcd->self.controller;
166 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
167
168 if (hub && hub->ocic_notify)
169 return hub->ocic_notify(ohci_da8xx_ocic_handler);
170
171 return 0;
172}
173
174static void ohci_da8xx_unregister_notify(struct usb_hcd *hcd)
175{
176 struct device *dev = hcd->self.controller;
177 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
178
179 if (hub && hub->ocic_notify)
180 hub->ocic_notify(NULL);
181}
182
97static int ohci_da8xx_reset(struct usb_hcd *hcd) 183static int ohci_da8xx_reset(struct usb_hcd *hcd)
98{ 184{
99 struct device *dev = hcd->self.controller; 185 struct device *dev = hcd->self.controller;
@@ -127,16 +213,18 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
127 * the correct hub descriptor... 213 * the correct hub descriptor...
128 */ 214 */
129 rh_a = ohci_readl(ohci, &ohci->regs->roothub.a); 215 rh_a = ohci_readl(ohci, &ohci->regs->roothub.a);
130 if (hub->set_power) { 216 if (ohci_da8xx_has_set_power(hcd)) {
131 rh_a &= ~RH_A_NPS; 217 rh_a &= ~RH_A_NPS;
132 rh_a |= RH_A_PSM; 218 rh_a |= RH_A_PSM;
133 } 219 }
134 if (hub->get_oci) { 220 if (ohci_da8xx_has_oci(hcd)) {
135 rh_a &= ~RH_A_NOCP; 221 rh_a &= ~RH_A_NOCP;
136 rh_a |= RH_A_OCPM; 222 rh_a |= RH_A_OCPM;
137 } 223 }
138 rh_a &= ~RH_A_POTPGT; 224 if (ohci_da8xx_has_potpgt(hcd)) {
139 rh_a |= hub->potpgt << 24; 225 rh_a &= ~RH_A_POTPGT;
226 rh_a |= hub->potpgt << 24;
227 }
140 ohci_writel(ohci, rh_a, &ohci->regs->roothub.a); 228 ohci_writel(ohci, rh_a, &ohci->regs->roothub.a);
141 229
142 return result; 230 return result;
@@ -169,7 +257,6 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
169 u16 wIndex, char *buf, u16 wLength) 257 u16 wIndex, char *buf, u16 wLength)
170{ 258{
171 struct device *dev = hcd->self.controller; 259 struct device *dev = hcd->self.controller;
172 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
173 int temp; 260 int temp;
174 261
175 switch (typeReq) { 262 switch (typeReq) {
@@ -183,11 +270,11 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
183 temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1); 270 temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1);
184 271
185 /* The port power status (PPS) bit defaults to 1 */ 272 /* The port power status (PPS) bit defaults to 1 */
186 if (hub->get_power && hub->get_power(wIndex) == 0) 273 if (!ohci_da8xx_get_power(hcd))
187 temp &= ~RH_PS_PPS; 274 temp &= ~RH_PS_PPS;
188 275
189 /* The port over-current indicator (POCI) bit is always 0 */ 276 /* The port over-current indicator (POCI) bit is always 0 */
190 if (hub->get_oci && hub->get_oci(wIndex) > 0) 277 if (ohci_da8xx_get_oci(hcd) > 0)
191 temp |= RH_PS_POCI; 278 temp |= RH_PS_POCI;
192 279
193 /* The over-current indicator change (OCIC) bit is 0 too */ 280 /* The over-current indicator change (OCIC) bit is 0 too */
@@ -212,10 +299,7 @@ check_port:
212 dev_dbg(dev, "%sPortFeature(%u): %s\n", 299 dev_dbg(dev, "%sPortFeature(%u): %s\n",
213 temp ? "Set" : "Clear", wIndex, "POWER"); 300 temp ? "Set" : "Clear", wIndex, "POWER");
214 301
215 if (!hub->set_power) 302 return ohci_da8xx_set_power(hcd, temp) ? -EPIPE : 0;
216 return -EPIPE;
217
218 return hub->set_power(wIndex, temp) ? -EPIPE : 0;
219 case USB_PORT_FEAT_C_OVER_CURRENT: 303 case USB_PORT_FEAT_C_OVER_CURRENT:
220 dev_dbg(dev, "%sPortFeature(%u): %s\n", 304 dev_dbg(dev, "%sPortFeature(%u): %s\n",
221 temp ? "Set" : "Clear", wIndex, 305 temp ? "Set" : "Clear", wIndex,
@@ -237,15 +321,10 @@ check_port:
237 321
238static int ohci_da8xx_probe(struct platform_device *pdev) 322static int ohci_da8xx_probe(struct platform_device *pdev)
239{ 323{
240 struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev);
241 struct da8xx_ohci_hcd *da8xx_ohci; 324 struct da8xx_ohci_hcd *da8xx_ohci;
242 struct usb_hcd *hcd; 325 struct usb_hcd *hcd;
243 struct resource *mem; 326 struct resource *mem;
244 int error, irq; 327 int error, irq;
245
246 if (hub == NULL)
247 return -ENODEV;
248
249 hcd = usb_create_hcd(&ohci_da8xx_hc_driver, &pdev->dev, 328 hcd = usb_create_hcd(&ohci_da8xx_hc_driver, &pdev->dev,
250 dev_name(&pdev->dev)); 329 dev_name(&pdev->dev));
251 if (!hcd) 330 if (!hcd)
@@ -290,12 +369,13 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
290 369
291 device_wakeup_enable(hcd->self.controller); 370 device_wakeup_enable(hcd->self.controller);
292 371
293 if (hub->ocic_notify) { 372 error = ohci_da8xx_register_notify(hcd);
294 error = hub->ocic_notify(ohci_da8xx_ocic_handler); 373 if (error)
295 if (!error) 374 goto err_remove_hcd;
296 return 0; 375
297 } 376 return 0;
298 377
378err_remove_hcd:
299 usb_remove_hcd(hcd); 379 usb_remove_hcd(hcd);
300err: 380err:
301 usb_put_hcd(hcd); 381 usb_put_hcd(hcd);
@@ -305,9 +385,8 @@ err:
305static int ohci_da8xx_remove(struct platform_device *pdev) 385static int ohci_da8xx_remove(struct platform_device *pdev)
306{ 386{
307 struct usb_hcd *hcd = platform_get_drvdata(pdev); 387 struct usb_hcd *hcd = platform_get_drvdata(pdev);
308 struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev);
309 388
310 hub->ocic_notify(NULL); 389 ohci_da8xx_unregister_notify(hcd);
311 usb_remove_hcd(hcd); 390 usb_remove_hcd(hcd);
312 usb_put_hcd(hcd); 391 usb_put_hcd(hcd);
313 392