aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/otg
diff options
context:
space:
mode:
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>2012-02-13 06:24:05 -0500
committerFelipe Balbi <balbi@ti.com>2012-02-13 06:35:17 -0500
commit144713f34727801d55d8858e0f549118b9f691c4 (patch)
tree2a8aec95ed37a2fe1bc69d6f0828394b66abc338 /drivers/usb/otg
parent7a8a3a9bec7432eedcb32b54a3940d0593246060 (diff)
usb: otg: ab8500: Start using struct usb_otg
Use struct usb_otg members with OTG specific functions instead of usb_phy members. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Acked-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> Reviewed-by: Marek Vasut <marek.vasut@gmail.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/otg')
-rw-r--r--drivers/usb/otg/ab8500-usb.c91
1 files changed, 51 insertions, 40 deletions
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
index b46a5fe178ef..e6371ff5f583 100644
--- a/drivers/usb/otg/ab8500-usb.c
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -68,7 +68,7 @@ enum ab8500_usb_link_status {
68}; 68};
69 69
70struct ab8500_usb { 70struct ab8500_usb {
71 struct usb_phy otg; 71 struct usb_phy phy;
72 struct device *dev; 72 struct device *dev;
73 int irq_num_id_rise; 73 int irq_num_id_rise;
74 int irq_num_id_fall; 74 int irq_num_id_fall;
@@ -82,9 +82,9 @@ struct ab8500_usb {
82 int rev; 82 int rev;
83}; 83};
84 84
85static inline struct ab8500_usb *xceiv_to_ab(struct usb_phy *x) 85static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
86{ 86{
87 return container_of(x, struct ab8500_usb, otg); 87 return container_of(x, struct ab8500_usb, phy);
88} 88}
89 89
90static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) 90static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
@@ -169,8 +169,8 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
169 /* TODO: Disable regulators. */ 169 /* TODO: Disable regulators. */
170 ab8500_usb_host_phy_dis(ab); 170 ab8500_usb_host_phy_dis(ab);
171 ab8500_usb_peri_phy_dis(ab); 171 ab8500_usb_peri_phy_dis(ab);
172 ab->otg.state = OTG_STATE_B_IDLE; 172 ab->phy.state = OTG_STATE_B_IDLE;
173 ab->otg.default_a = false; 173 ab->phy.otg->default_a = false;
174 ab->vbus_draw = 0; 174 ab->vbus_draw = 0;
175 event = USB_EVENT_NONE; 175 event = USB_EVENT_NONE;
176 break; 176 break;
@@ -181,22 +181,22 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
181 case USB_LINK_HOST_CHG_NM: 181 case USB_LINK_HOST_CHG_NM:
182 case USB_LINK_HOST_CHG_HS: 182 case USB_LINK_HOST_CHG_HS:
183 case USB_LINK_HOST_CHG_HS_CHIRP: 183 case USB_LINK_HOST_CHG_HS_CHIRP:
184 if (ab->otg.gadget) { 184 if (ab->phy.otg->gadget) {
185 /* TODO: Enable regulators. */ 185 /* TODO: Enable regulators. */
186 ab8500_usb_peri_phy_en(ab); 186 ab8500_usb_peri_phy_en(ab);
187 v = ab->otg.gadget; 187 v = ab->phy.otg->gadget;
188 } 188 }
189 event = USB_EVENT_VBUS; 189 event = USB_EVENT_VBUS;
190 break; 190 break;
191 191
192 case USB_LINK_HM_IDGND: 192 case USB_LINK_HM_IDGND:
193 if (ab->otg.host) { 193 if (ab->phy.otg->host) {
194 /* TODO: Enable regulators. */ 194 /* TODO: Enable regulators. */
195 ab8500_usb_host_phy_en(ab); 195 ab8500_usb_host_phy_en(ab);
196 v = ab->otg.host; 196 v = ab->phy.otg->host;
197 } 197 }
198 ab->otg.state = OTG_STATE_A_IDLE; 198 ab->phy.state = OTG_STATE_A_IDLE;
199 ab->otg.default_a = true; 199 ab->phy.otg->default_a = true;
200 event = USB_EVENT_ID; 200 event = USB_EVENT_ID;
201 break; 201 break;
202 202
@@ -212,7 +212,7 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
212 break; 212 break;
213 } 213 }
214 214
215 atomic_notifier_call_chain(&ab->otg.notifier, event, v); 215 atomic_notifier_call_chain(&ab->phy.notifier, event, v);
216 216
217 return 0; 217 return 0;
218} 218}
@@ -262,27 +262,27 @@ static void ab8500_usb_phy_disable_work(struct work_struct *work)
262 struct ab8500_usb *ab = container_of(work, struct ab8500_usb, 262 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
263 phy_dis_work); 263 phy_dis_work);
264 264
265 if (!ab->otg.host) 265 if (!ab->phy.otg->host)
266 ab8500_usb_host_phy_dis(ab); 266 ab8500_usb_host_phy_dis(ab);
267 267
268 if (!ab->otg.gadget) 268 if (!ab->phy.otg->gadget)
269 ab8500_usb_peri_phy_dis(ab); 269 ab8500_usb_peri_phy_dis(ab);
270} 270}
271 271
272static int ab8500_usb_set_power(struct usb_phy *otg, unsigned mA) 272static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
273{ 273{
274 struct ab8500_usb *ab; 274 struct ab8500_usb *ab;
275 275
276 if (!otg) 276 if (!phy)
277 return -ENODEV; 277 return -ENODEV;
278 278
279 ab = xceiv_to_ab(otg); 279 ab = phy_to_ab(phy);
280 280
281 ab->vbus_draw = mA; 281 ab->vbus_draw = mA;
282 282
283 if (mA) 283 if (mA)
284 atomic_notifier_call_chain(&ab->otg.notifier, 284 atomic_notifier_call_chain(&ab->phy.notifier,
285 USB_EVENT_ENUMERATED, ab->otg.gadget); 285 USB_EVENT_ENUMERATED, ab->phy.otg->gadget);
286 return 0; 286 return 0;
287} 287}
288 288
@@ -296,15 +296,15 @@ static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
296 return 0; 296 return 0;
297} 297}
298 298
299static int ab8500_usb_set_peripheral(struct usb_phy *otg, 299static int ab8500_usb_set_peripheral(struct usb_otg *otg,
300 struct usb_gadget *gadget) 300 struct usb_gadget *gadget)
301{ 301{
302 struct ab8500_usb *ab; 302 struct ab8500_usb *ab;
303 303
304 if (!otg) 304 if (!otg)
305 return -ENODEV; 305 return -ENODEV;
306 306
307 ab = xceiv_to_ab(otg); 307 ab = phy_to_ab(otg->phy);
308 308
309 /* Some drivers call this function in atomic context. 309 /* Some drivers call this function in atomic context.
310 * Do not update ab8500 registers directly till this 310 * Do not update ab8500 registers directly till this
@@ -313,11 +313,11 @@ static int ab8500_usb_set_peripheral(struct usb_phy *otg,
313 313
314 if (!gadget) { 314 if (!gadget) {
315 /* TODO: Disable regulators. */ 315 /* TODO: Disable regulators. */
316 ab->otg.gadget = NULL; 316 otg->gadget = NULL;
317 schedule_work(&ab->phy_dis_work); 317 schedule_work(&ab->phy_dis_work);
318 } else { 318 } else {
319 ab->otg.gadget = gadget; 319 otg->gadget = gadget;
320 ab->otg.state = OTG_STATE_B_IDLE; 320 otg->phy->state = OTG_STATE_B_IDLE;
321 321
322 /* Phy will not be enabled if cable is already 322 /* Phy will not be enabled if cable is already
323 * plugged-in. Schedule to enable phy. 323 * plugged-in. Schedule to enable phy.
@@ -329,15 +329,14 @@ static int ab8500_usb_set_peripheral(struct usb_phy *otg,
329 return 0; 329 return 0;
330} 330}
331 331
332static int ab8500_usb_set_host(struct usb_phy *otg, 332static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
333 struct usb_bus *host)
334{ 333{
335 struct ab8500_usb *ab; 334 struct ab8500_usb *ab;
336 335
337 if (!otg) 336 if (!otg)
338 return -ENODEV; 337 return -ENODEV;
339 338
340 ab = xceiv_to_ab(otg); 339 ab = phy_to_ab(otg->phy);
341 340
342 /* Some drivers call this function in atomic context. 341 /* Some drivers call this function in atomic context.
343 * Do not update ab8500 registers directly till this 342 * Do not update ab8500 registers directly till this
@@ -346,10 +345,10 @@ static int ab8500_usb_set_host(struct usb_phy *otg,
346 345
347 if (!host) { 346 if (!host) {
348 /* TODO: Disable regulators. */ 347 /* TODO: Disable regulators. */
349 ab->otg.host = NULL; 348 otg->host = NULL;
350 schedule_work(&ab->phy_dis_work); 349 schedule_work(&ab->phy_dis_work);
351 } else { 350 } else {
352 ab->otg.host = host; 351 otg->host = host;
353 /* Phy will not be enabled if cable is already 352 /* Phy will not be enabled if cable is already
354 * plugged-in. Schedule to enable phy. 353 * plugged-in. Schedule to enable phy.
355 * Use same delay to avoid any race condition. 354 * Use same delay to avoid any race condition.
@@ -472,6 +471,7 @@ static int ab8500_usb_v2_res_setup(struct platform_device *pdev,
472static int __devinit ab8500_usb_probe(struct platform_device *pdev) 471static int __devinit ab8500_usb_probe(struct platform_device *pdev)
473{ 472{
474 struct ab8500_usb *ab; 473 struct ab8500_usb *ab;
474 struct usb_otg *otg;
475 int err; 475 int err;
476 int rev; 476 int rev;
477 477
@@ -488,19 +488,28 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
488 if (!ab) 488 if (!ab)
489 return -ENOMEM; 489 return -ENOMEM;
490 490
491 otg = kzalloc(sizeof *otg, GFP_KERNEL);
492 if (!ab->phy.otg) {
493 kfree(ab);
494 return -ENOMEM;
495 }
496
491 ab->dev = &pdev->dev; 497 ab->dev = &pdev->dev;
492 ab->rev = rev; 498 ab->rev = rev;
493 ab->otg.dev = ab->dev; 499 ab->phy.dev = ab->dev;
494 ab->otg.label = "ab8500"; 500 ab->phy.otg = otg;
495 ab->otg.state = OTG_STATE_UNDEFINED; 501 ab->phy.label = "ab8500";
496 ab->otg.set_host = ab8500_usb_set_host; 502 ab->phy.set_suspend = ab8500_usb_set_suspend;
497 ab->otg.set_peripheral = ab8500_usb_set_peripheral; 503 ab->phy.set_power = ab8500_usb_set_power;
498 ab->otg.set_suspend = ab8500_usb_set_suspend; 504 ab->phy.state = OTG_STATE_UNDEFINED;
499 ab->otg.set_power = ab8500_usb_set_power; 505
506 otg->phy = &ab->phy;
507 otg->set_host = ab8500_usb_set_host;
508 otg->set_peripheral = ab8500_usb_set_peripheral;
500 509
501 platform_set_drvdata(pdev, ab); 510 platform_set_drvdata(pdev, ab);
502 511
503 ATOMIC_INIT_NOTIFIER_HEAD(&ab->otg.notifier); 512 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
504 513
505 /* v1: Wait for link status to become stable. 514 /* v1: Wait for link status to become stable.
506 * all: Updates form set_host and set_peripheral as they are atomic. 515 * all: Updates form set_host and set_peripheral as they are atomic.
@@ -520,7 +529,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
520 if (err < 0) 529 if (err < 0)
521 goto fail0; 530 goto fail0;
522 531
523 err = otg_set_transceiver(&ab->otg); 532 err = usb_set_transceiver(&ab->phy);
524 if (err) { 533 if (err) {
525 dev_err(&pdev->dev, "Can't register transceiver\n"); 534 dev_err(&pdev->dev, "Can't register transceiver\n");
526 goto fail1; 535 goto fail1;
@@ -532,6 +541,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
532fail1: 541fail1:
533 ab8500_usb_irq_free(ab); 542 ab8500_usb_irq_free(ab);
534fail0: 543fail0:
544 kfree(otg);
535 kfree(ab); 545 kfree(ab);
536 return err; 546 return err;
537} 547}
@@ -546,13 +556,14 @@ static int __devexit ab8500_usb_remove(struct platform_device *pdev)
546 556
547 cancel_work_sync(&ab->phy_dis_work); 557 cancel_work_sync(&ab->phy_dis_work);
548 558
549 otg_set_transceiver(NULL); 559 usb_set_transceiver(NULL);
550 560
551 ab8500_usb_host_phy_dis(ab); 561 ab8500_usb_host_phy_dis(ab);
552 ab8500_usb_peri_phy_dis(ab); 562 ab8500_usb_peri_phy_dis(ab);
553 563
554 platform_set_drvdata(pdev, NULL); 564 platform_set_drvdata(pdev, NULL);
555 565
566 kfree(ab->phy.otg);
556 kfree(ab); 567 kfree(ab);
557 568
558 return 0; 569 return 0;