tusb6010.c (4d68c05ce11f4cdf6a6392f3a18dc6a985b4d0c4) | tusb6010.c (b96d3b08365f5a9603f50f3aadca6012f7eaffa1) |
---|---|
1/* 2 * TUSB6010 USB 2.0 OTG Dual Role controller 3 * 4 * Copyright (C) 2006 Nokia Corporation 5 * Tony Lindgren <tony@atomide.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 263 unchanged lines hidden (view full) --- 272static struct musb *the_musb; 273 274/* This is used by gadget drivers, and OTG transceiver logic, allowing 275 * at most mA current to be drawn from VBUS during a Default-B session 276 * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host 277 * mode), or low power Default-B sessions, something else supplies power. 278 * Caller must take care of locking. 279 */ | 1/* 2 * TUSB6010 USB 2.0 OTG Dual Role controller 3 * 4 * Copyright (C) 2006 Nokia Corporation 5 * Tony Lindgren <tony@atomide.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 263 unchanged lines hidden (view full) --- 272static struct musb *the_musb; 273 274/* This is used by gadget drivers, and OTG transceiver logic, allowing 275 * at most mA current to be drawn from VBUS during a Default-B session 276 * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host 277 * mode), or low power Default-B sessions, something else supplies power. 278 * Caller must take care of locking. 279 */ |
280static int tusb_draw_power(struct otg_transceiver *x, unsigned mA) | 280static int tusb_draw_power(struct usb_phy *x, unsigned mA) |
281{ 282 struct musb *musb = the_musb; 283 void __iomem *tbase = musb->ctrl_base; 284 u32 reg; 285 286 /* tps65030 seems to consume max 100mA, with maybe 60mA available 287 * (measured on one board) for things other than tps and tusb. 288 * 289 * Boards sharing the CPU clock with CLKIN will need to prevent 290 * certain idle sleep states while the USB link is active. 291 * 292 * REVISIT we could use VBUS to supply only _one_ of { 1.5V, 3.3V }. 293 * The actual current usage would be very board-specific. For now, 294 * it's simpler to just use an aggregate (also board-specific). 295 */ | 281{ 282 struct musb *musb = the_musb; 283 void __iomem *tbase = musb->ctrl_base; 284 u32 reg; 285 286 /* tps65030 seems to consume max 100mA, with maybe 60mA available 287 * (measured on one board) for things other than tps and tusb. 288 * 289 * Boards sharing the CPU clock with CLKIN will need to prevent 290 * certain idle sleep states while the USB link is active. 291 * 292 * REVISIT we could use VBUS to supply only _one_ of { 1.5V, 3.3V }. 293 * The actual current usage would be very board-specific. For now, 294 * it's simpler to just use an aggregate (also board-specific). 295 */ |
296 if (x->default_a || mA < (musb->min_power << 1)) | 296 if (x->otg->default_a || mA < (musb->min_power << 1)) |
297 mA = 0; 298 299 reg = musb_readl(tbase, TUSB_PRCM_MNGMT); 300 if (mA) { 301 musb->is_bus_powered = 1; 302 reg |= TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN; 303 } else { 304 musb->is_bus_powered = 0; --- 200 unchanged lines hidden (view full) --- 505 | TUSB_DEV_OTG_TIMER_ENABLE) \ 506 : 0) 507 508static void tusb_musb_set_vbus(struct musb *musb, int is_on) 509{ 510 void __iomem *tbase = musb->ctrl_base; 511 u32 conf, prcm, timer; 512 u8 devctl; | 297 mA = 0; 298 299 reg = musb_readl(tbase, TUSB_PRCM_MNGMT); 300 if (mA) { 301 musb->is_bus_powered = 1; 302 reg |= TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN; 303 } else { 304 musb->is_bus_powered = 0; --- 200 unchanged lines hidden (view full) --- 505 | TUSB_DEV_OTG_TIMER_ENABLE) \ 506 : 0) 507 508static void tusb_musb_set_vbus(struct musb *musb, int is_on) 509{ 510 void __iomem *tbase = musb->ctrl_base; 511 u32 conf, prcm, timer; 512 u8 devctl; |
513 struct usb_otg *otg = musb->xceiv->otg; |
|
513 514 /* HDRC controls CPEN, but beware current surges during device 515 * connect. They can trigger transient overcurrent conditions 516 * that must be ignored. 517 */ 518 519 prcm = musb_readl(tbase, TUSB_PRCM_MNGMT); 520 conf = musb_readl(tbase, TUSB_DEV_CONF); 521 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 522 523 if (is_on) { 524 timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE); | 514 515 /* HDRC controls CPEN, but beware current surges during device 516 * connect. They can trigger transient overcurrent conditions 517 * that must be ignored. 518 */ 519 520 prcm = musb_readl(tbase, TUSB_PRCM_MNGMT); 521 conf = musb_readl(tbase, TUSB_DEV_CONF); 522 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 523 524 if (is_on) { 525 timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE); |
525 musb->xceiv->default_a = 1; | 526 otg->default_a = 1; |
526 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 527 devctl |= MUSB_DEVCTL_SESSION; 528 529 conf |= TUSB_DEV_CONF_USB_HOST_MODE; 530 MUSB_HST_MODE(musb); 531 } else { 532 u32 otg_stat; 533 --- 9 unchanged lines hidden (view full) --- 543 break; 544 case OTG_STATE_A_WAIT_VFALL: 545 musb->xceiv->state = OTG_STATE_A_IDLE; 546 break; 547 default: 548 musb->xceiv->state = OTG_STATE_A_IDLE; 549 } 550 musb->is_active = 0; | 527 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 528 devctl |= MUSB_DEVCTL_SESSION; 529 530 conf |= TUSB_DEV_CONF_USB_HOST_MODE; 531 MUSB_HST_MODE(musb); 532 } else { 533 u32 otg_stat; 534 --- 9 unchanged lines hidden (view full) --- 544 break; 545 case OTG_STATE_A_WAIT_VFALL: 546 musb->xceiv->state = OTG_STATE_A_IDLE; 547 break; 548 default: 549 musb->xceiv->state = OTG_STATE_A_IDLE; 550 } 551 musb->is_active = 0; |
551 musb->xceiv->default_a = 1; | 552 otg->default_a = 1; |
552 MUSB_HST_MODE(musb); 553 } else { 554 musb->is_active = 0; | 553 MUSB_HST_MODE(musb); 554 } else { 555 musb->is_active = 0; |
555 musb->xceiv->default_a = 0; | 556 otg->default_a = 0; |
556 musb->xceiv->state = OTG_STATE_B_IDLE; 557 MUSB_DEV_MODE(musb); 558 } 559 560 devctl &= ~MUSB_DEVCTL_SESSION; 561 conf &= ~TUSB_DEV_CONF_USB_HOST_MODE; 562 } 563 prcm &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN); --- 75 unchanged lines hidden (view full) --- 639 return 0; 640} 641 642static inline unsigned long 643tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) 644{ 645 u32 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT); 646 unsigned long idle_timeout = 0; | 557 musb->xceiv->state = OTG_STATE_B_IDLE; 558 MUSB_DEV_MODE(musb); 559 } 560 561 devctl &= ~MUSB_DEVCTL_SESSION; 562 conf &= ~TUSB_DEV_CONF_USB_HOST_MODE; 563 } 564 prcm &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN); --- 75 unchanged lines hidden (view full) --- 640 return 0; 641} 642 643static inline unsigned long 644tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) 645{ 646 u32 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT); 647 unsigned long idle_timeout = 0; |
648 struct usb_otg *otg = musb->xceiv->otg; |
|
647 648 /* ID pin */ 649 if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) { 650 int default_a; 651 652 if (is_otg_enabled(musb)) 653 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS); 654 else 655 default_a = is_host_enabled(musb); 656 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B'); | 649 650 /* ID pin */ 651 if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) { 652 int default_a; 653 654 if (is_otg_enabled(musb)) 655 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS); 656 else 657 default_a = is_host_enabled(musb); 658 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B'); |
657 musb->xceiv->default_a = default_a; | 659 otg->default_a = default_a; |
658 tusb_musb_set_vbus(musb, default_a); 659 660 /* Don't allow idling immediately */ 661 if (default_a) 662 idle_timeout = jiffies + (HZ * 3); 663 } 664 665 /* VBUS state change */ 666 if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) { 667 668 /* B-dev state machine: no vbus ~= disconnect */ | 660 tusb_musb_set_vbus(musb, default_a); 661 662 /* Don't allow idling immediately */ 663 if (default_a) 664 idle_timeout = jiffies + (HZ * 3); 665 } 666 667 /* VBUS state change */ 668 if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) { 669 670 /* B-dev state machine: no vbus ~= disconnect */ |
669 if ((is_otg_enabled(musb) && !musb->xceiv->default_a) | 671 if ((is_otg_enabled(musb) && !otg->default_a) |
670 || !is_host_enabled(musb)) { 671 /* ? musb_root_disconnect(musb); */ 672 musb->port1_status &= 673 ~(USB_PORT_STAT_CONNECTION 674 | USB_PORT_STAT_ENABLE 675 | USB_PORT_STAT_LOW_SPEED 676 | USB_PORT_STAT_HIGH_SPEED 677 | USB_PORT_STAT_TEST --- 393 unchanged lines hidden (view full) --- 1071static int tusb_musb_init(struct musb *musb) 1072{ 1073 struct platform_device *pdev; 1074 struct resource *mem; 1075 void __iomem *sync = NULL; 1076 int ret; 1077 1078 usb_nop_xceiv_register(); | 672 || !is_host_enabled(musb)) { 673 /* ? musb_root_disconnect(musb); */ 674 musb->port1_status &= 675 ~(USB_PORT_STAT_CONNECTION 676 | USB_PORT_STAT_ENABLE 677 | USB_PORT_STAT_LOW_SPEED 678 | USB_PORT_STAT_HIGH_SPEED 679 | USB_PORT_STAT_TEST --- 393 unchanged lines hidden (view full) --- 1073static int tusb_musb_init(struct musb *musb) 1074{ 1075 struct platform_device *pdev; 1076 struct resource *mem; 1077 void __iomem *sync = NULL; 1078 int ret; 1079 1080 usb_nop_xceiv_register(); |
1079 musb->xceiv = otg_get_transceiver(); | 1081 musb->xceiv = usb_get_transceiver(); |
1080 if (!musb->xceiv) 1081 return -ENODEV; 1082 1083 pdev = to_platform_device(musb->controller); 1084 1085 /* dma address for async dma */ 1086 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1087 musb->async = mem->start; --- 35 unchanged lines hidden (view full) --- 1123 1124 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 1125 1126done: 1127 if (ret < 0) { 1128 if (sync) 1129 iounmap(sync); 1130 | 1082 if (!musb->xceiv) 1083 return -ENODEV; 1084 1085 pdev = to_platform_device(musb->controller); 1086 1087 /* dma address for async dma */ 1088 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1089 musb->async = mem->start; --- 35 unchanged lines hidden (view full) --- 1125 1126 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 1127 1128done: 1129 if (ret < 0) { 1130 if (sync) 1131 iounmap(sync); 1132 |
1131 otg_put_transceiver(musb->xceiv); | 1133 usb_put_transceiver(musb->xceiv); |
1132 usb_nop_xceiv_unregister(); 1133 } 1134 return ret; 1135} 1136 1137static int tusb_musb_exit(struct musb *musb) 1138{ 1139 del_timer_sync(&musb_idle_timer); 1140 the_musb = NULL; 1141 1142 if (musb->board_set_power) 1143 musb->board_set_power(0); 1144 1145 iounmap(musb->sync_va); 1146 | 1134 usb_nop_xceiv_unregister(); 1135 } 1136 return ret; 1137} 1138 1139static int tusb_musb_exit(struct musb *musb) 1140{ 1141 del_timer_sync(&musb_idle_timer); 1142 the_musb = NULL; 1143 1144 if (musb->board_set_power) 1145 musb->board_set_power(0); 1146 1147 iounmap(musb->sync_va); 1148 |
1147 otg_put_transceiver(musb->xceiv); | 1149 usb_put_transceiver(musb->xceiv); |
1148 usb_nop_xceiv_unregister(); 1149 return 0; 1150} 1151 1152static const struct musb_platform_ops tusb_ops = { 1153 .init = tusb_musb_init, 1154 .exit = tusb_musb_exit, 1155 --- 107 unchanged lines hidden --- | 1150 usb_nop_xceiv_unregister(); 1151 return 0; 1152} 1153 1154static const struct musb_platform_ops tusb_ops = { 1155 .init = tusb_musb_init, 1156 .exit = tusb_musb_exit, 1157 --- 107 unchanged lines hidden --- |