diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/ata-sd-pp.c | 1 | ||||
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/usb-imx31.c | 29 | ||||
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/usb-target.h | 3 | ||||
-rw-r--r-- | firmware/target/arm/powermgmt-ascodec.c | 8 | ||||
-rw-r--r-- | firmware/target/arm/system-pp502x.c | 100 | ||||
-rw-r--r-- | firmware/target/arm/usb-drv-arc.c | 11 | ||||
-rw-r--r-- | firmware/target/arm/usb-fw-pp502x.c | 215 | ||||
-rw-r--r-- | firmware/target/arm/usb-target.h | 9 |
8 files changed, 237 insertions, 139 deletions
diff --git a/firmware/target/arm/ata-sd-pp.c b/firmware/target/arm/ata-sd-pp.c index eb94072ff8..3a095e1321 100644 --- a/firmware/target/arm/ata-sd-pp.c +++ b/firmware/target/arm/ata-sd-pp.c | |||
@@ -1247,7 +1247,6 @@ void microsd_int(void) | |||
1247 | GPIO_SET_BITWISE(GPIOL_INT_EN, 0x08); | 1247 | GPIO_SET_BITWISE(GPIOL_INT_EN, 0x08); |
1248 | #endif | 1248 | #endif |
1249 | timeout_register(&sd1_oneshot, sd1_oneshot_callback, (3*HZ/10), 0); | 1249 | timeout_register(&sd1_oneshot, sd1_oneshot_callback, (3*HZ/10), 0); |
1250 | |||
1251 | } | 1250 | } |
1252 | #endif /* HAVE_HOTSWAP */ | 1251 | #endif /* HAVE_HOTSWAP */ |
1253 | 1252 | ||
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c b/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c index c0d7cb8d2a..99f3e072eb 100644 --- a/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c | |||
@@ -53,14 +53,19 @@ static void enable_transceiver(bool enable) | |||
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | /* Read the immediate state of the cable from the PMIC */ | ||
57 | bool usb_plugged(void) | ||
58 | { | ||
59 | return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S; | ||
60 | } | ||
61 | |||
56 | void usb_connect_event(void) | 62 | void usb_connect_event(void) |
57 | { | 63 | { |
58 | uint32_t status = mc13783_read(MC13783_INTERRUPT_SENSE0); | 64 | int status = usb_plugged() ? USB_INSERTED : USB_EXTRACTED; |
59 | usb_status = (status & MC13783_USB4V4S) ? | 65 | usb_status = status; |
60 | USB_INSERTED : USB_EXTRACTED; | ||
61 | /* Notify power that USB charging is potentially available */ | 66 | /* Notify power that USB charging is potentially available */ |
62 | charger_usb_detect_event(usb_status); | 67 | charger_usb_detect_event(status); |
63 | usb_status_event(usb_status); | 68 | usb_status_event((status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED); |
64 | } | 69 | } |
65 | 70 | ||
66 | int usb_detect(void) | 71 | int usb_detect(void) |
@@ -68,12 +73,6 @@ int usb_detect(void) | |||
68 | return usb_status; | 73 | return usb_status; |
69 | } | 74 | } |
70 | 75 | ||
71 | /* Read the immediate state of the cable from the PMIC */ | ||
72 | bool usb_plugged(void) | ||
73 | { | ||
74 | return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S; | ||
75 | } | ||
76 | |||
77 | void usb_init_device(void) | 76 | void usb_init_device(void) |
78 | { | 77 | { |
79 | /* Do one-time inits */ | 78 | /* Do one-time inits */ |
@@ -107,7 +106,7 @@ void usb_enable(bool on) | |||
107 | 106 | ||
108 | void usb_attach(void) | 107 | void usb_attach(void) |
109 | { | 108 | { |
110 | usb_enable(true); | 109 | usb_drv_attach(); |
111 | } | 110 | } |
112 | 111 | ||
113 | static void __attribute__((interrupt("IRQ"))) USB_OTG_HANDLER(void) | 112 | static void __attribute__((interrupt("IRQ"))) USB_OTG_HANDLER(void) |
@@ -122,3 +121,9 @@ void usb_drv_int_enable(bool enable) | |||
122 | else | 121 | else |
123 | avic_disable_int(USB_OTG); | 122 | avic_disable_int(USB_OTG); |
124 | } | 123 | } |
124 | |||
125 | /* Called during the bus reset interrupt when in detect mode */ | ||
126 | void usb_drv_usb_detect_event(void) | ||
127 | { | ||
128 | usb_status_event(USB_INSERTED); | ||
129 | } | ||
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-target.h b/firmware/target/arm/imx31/gigabeat-s/usb-target.h index 31b8080b57..1f96a9a7eb 100644 --- a/firmware/target/arm/imx31/gigabeat-s/usb-target.h +++ b/firmware/target/arm/imx31/gigabeat-s/usb-target.h | |||
@@ -25,9 +25,6 @@ | |||
25 | #define USB_DRIVER_CLOSE | 25 | #define USB_DRIVER_CLOSE |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | /* Connect by events, not by tick polling */ | ||
29 | #define USB_STATUS_BY_EVENT | ||
30 | |||
31 | void usb_connect_event(void); | 28 | void usb_connect_event(void); |
32 | void usb_init_device(void); | 29 | void usb_init_device(void); |
33 | int usb_detect(void); | 30 | int usb_detect(void); |
diff --git a/firmware/target/arm/powermgmt-ascodec.c b/firmware/target/arm/powermgmt-ascodec.c index 6ee6209823..1eaaf6ab30 100644 --- a/firmware/target/arm/powermgmt-ascodec.c +++ b/firmware/target/arm/powermgmt-ascodec.c | |||
@@ -134,10 +134,6 @@ static inline void charger_plugged(void) | |||
134 | { | 134 | { |
135 | batt_threshold = BATT_FULL_VOLTAGE; /* Start with topped value. */ | 135 | batt_threshold = BATT_FULL_VOLTAGE; /* Start with topped value. */ |
136 | battery_voltage_sync(); | 136 | battery_voltage_sync(); |
137 | #if defined(USB_STATUS_BY_EVENT) && defined(USB_DETECT_BY_DRV) | ||
138 | /* Charger pin detect is USB pin detect */ | ||
139 | usb_connect_event(true); | ||
140 | #endif | ||
141 | } | 137 | } |
142 | 138 | ||
143 | static inline void charger_control(void) | 139 | static inline void charger_control(void) |
@@ -192,10 +188,6 @@ static inline void charger_unplugged(void) | |||
192 | disable_charger(); | 188 | disable_charger(); |
193 | if (charge_state >= CHARGE_STATE_ERROR) | 189 | if (charge_state >= CHARGE_STATE_ERROR) |
194 | charge_state = DISCHARGING; /* Reset error */ | 190 | charge_state = DISCHARGING; /* Reset error */ |
195 | #if defined(USB_STATUS_BY_EVENT) && defined(USB_DETECT_BY_DRV) | ||
196 | /* Charger pin detect is USB pin detect */ | ||
197 | usb_connect_event(false); | ||
198 | #endif | ||
199 | } | 191 | } |
200 | 192 | ||
201 | /* Main charging algorithm - called from powermgmt.c */ | 193 | /* Main charging algorithm - called from powermgmt.c */ |
diff --git a/firmware/target/arm/system-pp502x.c b/firmware/target/arm/system-pp502x.c index ed4c028ff4..d4c07f10eb 100644 --- a/firmware/target/arm/system-pp502x.c +++ b/firmware/target/arm/system-pp502x.c | |||
@@ -25,9 +25,8 @@ | |||
25 | #include "as3514.h" | 25 | #include "as3514.h" |
26 | #include "ata-sd-target.h" | 26 | #include "ata-sd-target.h" |
27 | #include "button-target.h" | 27 | #include "button-target.h" |
28 | #ifdef HAVE_USBSTACK | 28 | #include "usb-target.h" |
29 | #include "usb_drv.h" | 29 | #include "usb_drv.h" |
30 | #endif | ||
31 | 30 | ||
32 | #ifndef BOOTLOADER | 31 | #ifndef BOOTLOADER |
33 | extern void TIMER1(void); | 32 | extern void TIMER1(void); |
@@ -42,51 +41,108 @@ void __attribute__((interrupt("IRQ"))) irq_handler(void) | |||
42 | { | 41 | { |
43 | if (CPU_INT_STAT & TIMER1_MASK) { | 42 | if (CPU_INT_STAT & TIMER1_MASK) { |
44 | TIMER1(); | 43 | TIMER1(); |
45 | } else if (CPU_INT_STAT & TIMER2_MASK) | 44 | } |
45 | else if (CPU_INT_STAT & TIMER2_MASK) { | ||
46 | TIMER2(); | 46 | TIMER2(); |
47 | } | ||
48 | #ifdef HAVE_USBSTACK | ||
49 | /* Rather high priority - place near front */ | ||
50 | else if (CPU_INT_STAT & USB_MASK) { | ||
51 | usb_drv_int(); | ||
52 | } | ||
53 | #endif | ||
47 | #if defined(IPOD_MINI) /* Mini 1st gen only, mini 2nd gen uses iPod 4G code */ | 54 | #if defined(IPOD_MINI) /* Mini 1st gen only, mini 2nd gen uses iPod 4G code */ |
48 | else if (CPU_HI_INT_STAT & GPIO0_MASK) | 55 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { |
49 | ipod_mini_button_int(); | 56 | if ((GPIOA_INT_STAT & 0x3f) || (GPIOB_INT_STAT & 0x30)) |
57 | ipod_mini_button_int(); | ||
58 | if (GPIOC_INT_STAT & 0x02) | ||
59 | firewire_insert_int(); | ||
60 | if (GPIOD_INT_STAT & 0x08) | ||
61 | usb_insert_int(); | ||
62 | } | ||
63 | /* end IPOD_MINI */ | ||
50 | #elif CONFIG_KEYPAD == IPOD_4G_PAD /* except Mini 1st gen, handled above */ | 64 | #elif CONFIG_KEYPAD == IPOD_4G_PAD /* except Mini 1st gen, handled above */ |
51 | else if (CPU_HI_INT_STAT & I2C_MASK) | 65 | else if (CPU_HI_INT_STAT & I2C_MASK) { |
52 | ipod_4g_button_int(); | 66 | ipod_4g_button_int(); |
67 | } | ||
68 | #if defined(IPOD_COLOR) || defined(IPOD_MINI2G) || defined(IPOD_4G) | ||
69 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { | ||
70 | if (GPIOC_INT_STAT & 0x02) | ||
71 | firewire_insert_int(); | ||
72 | if (GPIOD_INT_STAT & 0x08) | ||
73 | usb_insert_int(); | ||
74 | } | ||
75 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) | ||
76 | else if (CPU_HI_INT_STAT & GPIO2_MASK) { | ||
77 | if (GPIOL_INT_STAT & 0x10) | ||
78 | usb_insert_int(); | ||
79 | } | ||
80 | #endif | ||
81 | /* end CONFIG_KEYPAD == IPOD_4G_PAD */ | ||
82 | #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) | ||
83 | else if (CPU_HI_INT_STAT & GPIO2_MASK) { | ||
84 | if (GPIOL_INT_STAT & 0x04) | ||
85 | usb_insert_int(); | ||
86 | } | ||
87 | /* end IRIVER_H10 || IRIVER_H10_5GB */ | ||
53 | #elif defined(SANSA_E200) | 88 | #elif defined(SANSA_E200) |
54 | #ifdef HAVE_HOTSWAP | ||
55 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { | 89 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { |
90 | #ifdef HAVE_HOTSWAP | ||
56 | if (GPIOA_INT_STAT & 0x80) | 91 | if (GPIOA_INT_STAT & 0x80) |
57 | microsd_int(); | 92 | microsd_int(); |
58 | } | ||
59 | #endif | 93 | #endif |
94 | if (GPIOB_INT_STAT & 0x10) | ||
95 | usb_insert_int(); | ||
96 | } | ||
60 | else if (CPU_HI_INT_STAT & GPIO1_MASK) { | 97 | else if (CPU_HI_INT_STAT & GPIO1_MASK) { |
61 | if (GPIOF_INT_STAT & 0xff) | 98 | if (GPIOF_INT_STAT & 0xff) |
62 | button_int(); | 99 | button_int(); |
63 | if (GPIOH_INT_STAT & 0xc0) | 100 | if (GPIOH_INT_STAT & 0xc0) |
64 | clickwheel_int(); | 101 | clickwheel_int(); |
65 | } | 102 | } |
66 | #elif defined(SANSA_C200) && defined(HAVE_HOTSWAP) | 103 | /* end SANSA_E200 */ |
104 | #elif defined(SANSA_C200) | ||
105 | else if (CPU_HI_INT_STAT & GPIO1_MASK) { | ||
106 | if (GPIOH_INT_STAT & 0x02) | ||
107 | usb_insert_int(); | ||
108 | } | ||
109 | #ifdef HAVE_HOTSWAP | ||
67 | else if (CPU_HI_INT_STAT & GPIO2_MASK) { | 110 | else if (CPU_HI_INT_STAT & GPIO2_MASK) { |
68 | if (GPIOL_INT_STAT & 0x08) | 111 | if (GPIOL_INT_STAT & 0x08) |
69 | microsd_int(); | 112 | microsd_int(); |
70 | } | 113 | } |
114 | #endif | ||
115 | /* end SANSA_C200 */ | ||
71 | #elif defined(MROBE_100) | 116 | #elif defined(MROBE_100) |
72 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { | 117 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { |
73 | if (GPIOD_INT_STAT & 0x2) | 118 | if (GPIOD_INT_STAT & 0x02) |
74 | button_int(); | 119 | button_int(); |
75 | } | 120 | } |
121 | else if (CPU_HI_INT_STAT & GPIO2_MASK) { | ||
122 | if (GPIOL_INT_STAT & 0x04) | ||
123 | usb_insert_int(); | ||
124 | } | ||
125 | /* end MROBE_100 */ | ||
126 | #elif defined(PHILIPS_SA9200) | ||
127 | else if (CPU_HI_INT_STAT & GPIO1_MASK) { | ||
128 | if (GPIOF_INT_STAT & 0x80) | ||
129 | usb_insert_int(); | ||
130 | } | ||
131 | /* end PHILIPS_SA9200 */ | ||
76 | #elif defined(PHILIPS_HDD1630) | 132 | #elif defined(PHILIPS_HDD1630) |
77 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { | 133 | else if (CPU_HI_INT_STAT & GPIO0_MASK) { |
78 | if (GPIOA_INT_STAT & 0x20) | 134 | if (GPIOA_INT_STAT & 0x20) |
79 | button_int(); | 135 | button_int(); |
80 | } | 136 | } |
137 | else if (CPU_HI_INT_STAT & GPIO1_MASK) { | ||
138 | if (GPIOE_INT_STAT & 0x04) | ||
139 | usb_insert_int(); | ||
140 | } | ||
141 | /* end PHILIPS_HDD1630 */ | ||
81 | #endif | 142 | #endif |
82 | #ifdef IPOD_ACCESSORY_PROTOCOL | 143 | #ifdef IPOD_ACCESSORY_PROTOCOL |
83 | else if (CPU_HI_INT_STAT & SER0_MASK) { | 144 | else if (CPU_HI_INT_STAT & SER0_MASK) { |
84 | SERIAL0(); | 145 | SERIAL0(); |
85 | } | ||
86 | #endif | ||
87 | #ifdef HAVE_USBSTACK | ||
88 | else if (CPU_INT_STAT & USB_MASK) { | ||
89 | usb_drv_int(); | ||
90 | } | 146 | } |
91 | #endif | 147 | #endif |
92 | } else { | 148 | } else { |
@@ -437,8 +493,12 @@ void system_init(void) | |||
437 | #endif /* BOOTLOADER */ | 493 | #endif /* BOOTLOADER */ |
438 | } | 494 | } |
439 | 495 | ||
440 | void system_reboot(void) | 496 | void ICODE_ATTR system_reboot(void) |
441 | { | 497 | { |
498 | disable_interrupt(IRQ_FIQ_STATUS); | ||
499 | CPU_INT_DIS = -1; | ||
500 | COP_INT_DIS = -1; | ||
501 | |||
442 | /* Reboot */ | 502 | /* Reboot */ |
443 | #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) | 503 | #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) |
444 | CACHE_CTL &= ~CACHE_CTL_VECT_REMAP; | 504 | CACHE_CTL &= ~CACHE_CTL_VECT_REMAP; |
diff --git a/firmware/target/arm/usb-drv-arc.c b/firmware/target/arm/usb-drv-arc.c index b6d6ff154d..15f3bf2c6c 100644 --- a/firmware/target/arm/usb-drv-arc.c +++ b/firmware/target/arm/usb-drv-arc.c | |||
@@ -419,13 +419,11 @@ static void _usb_drv_init(bool attach) | |||
419 | REG_ENDPOINTLISTADDR = (unsigned int)qh_array; | 419 | REG_ENDPOINTLISTADDR = (unsigned int)qh_array; |
420 | REG_DEVICEADDR = 0; | 420 | REG_DEVICEADDR = 0; |
421 | 421 | ||
422 | #ifdef USB_DETECT_BY_DRV | ||
423 | if (!attach) { | 422 | if (!attach) { |
424 | /* enable RESET interrupt */ | 423 | /* enable RESET interrupt */ |
425 | REG_USBINTR = USBINTR_RESET_EN; | 424 | REG_USBINTR = USBINTR_RESET_EN; |
426 | } | 425 | } |
427 | else | 426 | else |
428 | #endif | ||
429 | { | 427 | { |
430 | /* enable USB interrupts */ | 428 | /* enable USB interrupts */ |
431 | REG_USBINTR = | 429 | REG_USBINTR = |
@@ -449,23 +447,17 @@ static void _usb_drv_init(bool attach) | |||
449 | (void)attach; | 447 | (void)attach; |
450 | } | 448 | } |
451 | 449 | ||
452 | /** With USB_DETECT_BY_DRV, attach is distinct from init, otherwise eqivalent. **/ | ||
453 | |||
454 | /* USB_DETECT_BY_DRV - enable bus reset detection only | ||
455 | * else fully enable driver */ | ||
456 | void usb_drv_init(void) | 450 | void usb_drv_init(void) |
457 | { | 451 | { |
458 | _usb_drv_init(false); | 452 | _usb_drv_init(false); |
459 | } | 453 | } |
460 | 454 | ||
461 | #ifdef USB_DETECT_BY_DRV | ||
462 | /* fully enable driver */ | 455 | /* fully enable driver */ |
463 | void usb_drv_attach(void) | 456 | void usb_drv_attach(void) |
464 | { | 457 | { |
465 | sleep(HZ/10); | 458 | sleep(HZ/10); |
466 | _usb_drv_init(true); | 459 | _usb_drv_init(true); |
467 | } | 460 | } |
468 | #endif /* USB_DETECT_BY_DRV */ | ||
469 | 461 | ||
470 | void usb_drv_exit(void) | 462 | void usb_drv_exit(void) |
471 | { | 463 | { |
@@ -513,7 +505,7 @@ void usb_drv_int(void) | |||
513 | /* reset interrupt */ | 505 | /* reset interrupt */ |
514 | if (status & USBSTS_RESET) { | 506 | if (status & USBSTS_RESET) { |
515 | REG_USBSTS = USBSTS_RESET; | 507 | REG_USBSTS = USBSTS_RESET; |
516 | #ifdef USB_DETECT_BY_DRV | 508 | |
517 | if (UNLIKELY(usbintr == USBINTR_RESET_EN)) { | 509 | if (UNLIKELY(usbintr == USBINTR_RESET_EN)) { |
518 | /* USB detected - detach and inform */ | 510 | /* USB detected - detach and inform */ |
519 | usb_drv_stop(); | 511 | usb_drv_stop(); |
@@ -523,7 +515,6 @@ void usb_drv_int(void) | |||
523 | usb_drv_usb_detect_event(); | 515 | usb_drv_usb_detect_event(); |
524 | } | 516 | } |
525 | else | 517 | else |
526 | #endif | ||
527 | { | 518 | { |
528 | bus_reset(); | 519 | bus_reset(); |
529 | usb_core_bus_reset(); /* tell mom */ | 520 | usb_core_bus_reset(); /* tell mom */ |
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c index 8a6d78675f..883ca1e8e2 100644 --- a/firmware/target/arm/usb-fw-pp502x.c +++ b/firmware/target/arm/usb-fw-pp502x.c | |||
@@ -33,6 +33,60 @@ | |||
33 | #include "usb_core.h" | 33 | #include "usb_core.h" |
34 | #include "usb_drv.h" | 34 | #include "usb_drv.h" |
35 | 35 | ||
36 | #if defined(IPOD_4G) || defined(IPOD_COLOR) \ | ||
37 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | ||
38 | /* GPIO D bit 3 is usb detect */ | ||
39 | #define USB_GPIO GPIOD | ||
40 | #define USB_GPIO_MASK 0x08 | ||
41 | #define USB_GPIO_VAL 0x08 | ||
42 | |||
43 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) | ||
44 | /* GPIO L bit 4 is usb detect */ | ||
45 | #define USB_GPIO GPIOL | ||
46 | #define USB_GPIO_MASK 0x10 | ||
47 | #define USB_GPIO_VAL 0x10 | ||
48 | |||
49 | #elif defined(SANSA_C200) | ||
50 | /* GPIO H bit 1 is usb/charger detect */ | ||
51 | #define USB_GPIO GPIOH | ||
52 | #define USB_GPIO_MASK 0x02 | ||
53 | #define USB_GPIO_VAL 0x02 | ||
54 | |||
55 | #elif defined(SANSA_E200) | ||
56 | /* GPIO B bit 4 is usb/charger detect */ | ||
57 | #define USB_GPIO GPIOB | ||
58 | #define USB_GPIO_MASK 0x10 | ||
59 | #define USB_GPIO_VAL 0x10 | ||
60 | |||
61 | #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(MROBE_100) | ||
62 | /* GPIO L bit 2 is usb detect */ | ||
63 | #define USB_GPIO GPIOL | ||
64 | #define USB_GPIO_MASK 0x04 | ||
65 | #define USB_GPIO_VAL 0x04 | ||
66 | |||
67 | #elif defined(PHILIPS_SA9200) | ||
68 | /* GPIO F bit 7 (low) is usb detect */ | ||
69 | #define USB_GPIO GPIOF | ||
70 | #define USB_GPIO_MASK 0x80 | ||
71 | #define USB_GPIO_VAL 0x00 | ||
72 | |||
73 | #elif defined(PHILIPS_HDD1630) | ||
74 | /* GPIO E bit 2 is usb detect */ | ||
75 | #define USB_GPIO GPIOE | ||
76 | #define USB_GPIO_MASK 0x04 | ||
77 | #define USB_GPIO_VAL 0x04 | ||
78 | #else | ||
79 | #error No USB GPIO config specified | ||
80 | #endif | ||
81 | |||
82 | #define USB_GPIO_ENABLE GPIO_ENABLE(USB_GPIO) | ||
83 | #define USB_GPIO_OUTPUT_EN GPIO_OUTPUT_EN(USB_GPIO) | ||
84 | #define USB_GPIO_INPUT_VAL GPIO_INPUT_VAL(USB_GPIO) | ||
85 | #define USB_GPIO_INT_EN GPIO_INT_EN(USB_GPIO) | ||
86 | #define USB_GPIO_INT_LEV GPIO_INT_LEV(USB_GPIO) | ||
87 | #define USB_GPIO_INT_CLR GPIO_INT_CLR(USB_GPIO) | ||
88 | #define USB_GPIO_HI_INT_MASK GPIO_HI_INT_MASK(USB_GPIO) | ||
89 | |||
36 | void usb_init_device(void) | 90 | void usb_init_device(void) |
37 | { | 91 | { |
38 | /* enable usb module */ | 92 | /* enable usb module */ |
@@ -52,7 +106,10 @@ void usb_init_device(void) | |||
52 | while ((inl(0x70000028) & 0x80) == 0); | 106 | while ((inl(0x70000028) & 0x80) == 0); |
53 | outl(inl(0x70000028) | 0x2, 0x70000028); | 107 | outl(inl(0x70000028) | 0x2, 0x70000028); |
54 | udelay(100000); | 108 | udelay(100000); |
55 | 109 | ||
110 | /* Do one-time inits */ | ||
111 | usb_drv_startup(); | ||
112 | |||
56 | /* disable USB-devices until USB is detected via GPIO */ | 113 | /* disable USB-devices until USB is detected via GPIO */ |
57 | #ifndef BOOTLOADER | 114 | #ifndef BOOTLOADER |
58 | /* Disabling USB0 in the bootloader makes the OF not load, | 115 | /* Disabling USB0 in the bootloader makes the OF not load, |
@@ -63,17 +120,38 @@ void usb_init_device(void) | |||
63 | DEV_INIT2 &= ~INIT_USB; | 120 | DEV_INIT2 &= ~INIT_USB; |
64 | #endif | 121 | #endif |
65 | 122 | ||
66 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ | 123 | /* These set INV_LEV to the inserted level so it will fire if already |
67 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | 124 | * inserted at the time they are enabled. */ |
125 | #ifdef USB_STATUS_BY_EVENT | ||
126 | GPIO_CLEAR_BITWISE(USB_GPIO_INT_EN, USB_GPIO_MASK); | ||
127 | GPIO_CLEAR_BITWISE(USB_GPIO_OUTPUT_EN, USB_GPIO_MASK); | ||
128 | GPIO_SET_BITWISE(USB_GPIO_ENABLE, USB_GPIO_MASK); | ||
129 | GPIO_WRITE_BITWISE(USB_GPIO_INT_LEV, USB_GPIO_VAL, USB_GPIO_MASK); | ||
130 | USB_GPIO_INT_CLR = USB_GPIO_MASK; | ||
131 | GPIO_SET_BITWISE(USB_GPIO_INT_EN, USB_GPIO_MASK); | ||
132 | CPU_HI_INT_EN = USB_GPIO_HI_INT_MASK; | ||
133 | |||
134 | #ifdef USB_FIREWIRE_HANDLING | ||
68 | /* GPIO C bit 1 is firewire detect */ | 135 | /* GPIO C bit 1 is firewire detect */ |
69 | GPIOC_ENABLE |= 0x02; | 136 | GPIO_CLEAR_BITWISE(GPIOC_INT_EN, 0x02); |
70 | GPIOC_OUTPUT_EN &= ~0x02; | 137 | GPIO_CLEAR_BITWISE(GPIOC_OUTPUT_EN, 0x02); |
138 | GPIO_SET_BITWISE(GPIOC_ENABLE, 0x02); | ||
139 | GPIO_WRITE_BITWISE(GPIOC_INT_LEV, 0x00, 0x02); | ||
140 | GPIOC_INT_CLR = 0x02; | ||
141 | GPIO_SET_BITWISE(GPIOC_INT_EN, 0x02); | ||
142 | CPU_HI_INT_EN = GPIO0_MASK; | ||
71 | #endif | 143 | #endif |
72 | 144 | CPU_INT_EN = HI_MASK; | |
73 | #ifdef HAVE_USBSTACK | 145 | #else |
74 | /* Do one-time inits */ | 146 | /* No interrupt - setup pin read only (BOOTLOADER) */ |
75 | usb_drv_startup(); | 147 | GPIO_CLEAR_BITWISE(USB_GPIO_OUTPUT_EN, USB_GPIO_MASK); |
148 | GPIO_SET_BITWISE(USB_GPIO_ENABLE, USB_GPIO_MASK); | ||
149 | #ifdef USB_FIREWIRE_HANDLING | ||
150 | /* GPIO C bit 1 is firewire detect */ | ||
151 | GPIO_CLEAR_BITWISE(GPIOC_OUTPUT_EN, 0x02); | ||
152 | GPIO_SET_BITWISE(GPIOC_ENABLE, 0x02); | ||
76 | #endif | 153 | #endif |
154 | #endif /* USB_STATUS_BY_EVENT */ | ||
77 | } | 155 | } |
78 | 156 | ||
79 | void usb_enable(bool on) | 157 | void usb_enable(bool on) |
@@ -96,21 +174,27 @@ void usb_enable(bool on) | |||
96 | 174 | ||
97 | void usb_attach(void) | 175 | void usb_attach(void) |
98 | { | 176 | { |
99 | #ifdef USB_DETECT_BY_DRV | ||
100 | usb_drv_attach(); | 177 | usb_drv_attach(); |
101 | #else | ||
102 | usb_enable(true); | ||
103 | #endif | ||
104 | } | 178 | } |
105 | 179 | ||
106 | #ifdef USB_DETECT_BY_DRV | 180 | #ifdef USB_STATUS_BY_EVENT |
107 | /* Cannot tell charger pin from USB pin */ | 181 | /* Cannot always tell power pin from USB pin */ |
108 | static int usb_status = USB_EXTRACTED; | 182 | static int usb_status = USB_EXTRACTED; |
109 | 183 | ||
110 | void usb_connect_event(bool inserted) | 184 | static int usb_timeout_event(struct timeout *tmo) |
185 | { | ||
186 | usb_status_event(tmo->data == USB_GPIO_VAL ? USB_POWERED : USB_UNPOWERED); | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | void usb_insert_int(void) | ||
111 | { | 191 | { |
112 | usb_status = inserted ? USB_INSERTED : USB_EXTRACTED; | 192 | static struct timeout usb_oneshot; |
113 | usb_status_event(inserted ? USB_POWERED : USB_UNPOWERED); | 193 | unsigned long val = USB_GPIO_INPUT_VAL & USB_GPIO_MASK; |
194 | usb_status = (val == USB_GPIO_VAL) ? USB_INSERTED : USB_EXTRACTED; | ||
195 | GPIO_WRITE_BITWISE(USB_GPIO_INT_LEV, val ^ USB_GPIO_MASK, USB_GPIO_MASK); | ||
196 | USB_GPIO_INT_CLR = USB_GPIO_MASK; | ||
197 | timeout_register(&usb_oneshot, usb_timeout_event, HZ/5, val); | ||
114 | } | 198 | } |
115 | 199 | ||
116 | /* Called during the bus reset interrupt when in detect mode */ | 200 | /* Called during the bus reset interrupt when in detect mode */ |
@@ -118,51 +202,7 @@ void usb_drv_usb_detect_event(void) | |||
118 | { | 202 | { |
119 | usb_status_event(USB_INSERTED); | 203 | usb_status_event(USB_INSERTED); |
120 | } | 204 | } |
121 | #else /* !USB_DETECT_BY_DRV */ | 205 | #endif /* USB_STATUS_BY_EVENT */ |
122 | static bool usb_pin_detect(void) | ||
123 | { | ||
124 | bool retval = false; | ||
125 | |||
126 | #if defined(IPOD_4G) || defined(IPOD_COLOR) \ | ||
127 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | ||
128 | /* GPIO D bit 3 is usb detect */ | ||
129 | if (GPIOD_INPUT_VAL & 0x08) | ||
130 | retval = true; | ||
131 | |||
132 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) | ||
133 | /* GPIO L bit 4 is usb detect */ | ||
134 | if (GPIOL_INPUT_VAL & 0x10) | ||
135 | retval = true; | ||
136 | |||
137 | #elif defined(SANSA_C200) | ||
138 | /* GPIO H bit 1 is usb/charger detect */ | ||
139 | if (GPIOH_INPUT_VAL & 0x02) | ||
140 | retval = true; | ||
141 | |||
142 | #elif defined(SANSA_E200) | ||
143 | /* GPIO B bit 4 is usb/charger detect */ | ||
144 | if (GPIOB_INPUT_VAL & 0x10) | ||
145 | retval = true; | ||
146 | |||
147 | #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(MROBE_100) | ||
148 | /* GPIO L bit 2 is usb detect */ | ||
149 | if (GPIOL_INPUT_VAL & 0x4) | ||
150 | retval = true; | ||
151 | |||
152 | #elif defined(PHILIPS_SA9200) | ||
153 | /* GPIO F bit 7 is usb detect */ | ||
154 | if (!(GPIOF_INPUT_VAL & 0x80)) | ||
155 | retval = true; | ||
156 | |||
157 | #elif defined(PHILIPS_HDD1630) | ||
158 | /* GPIO E bit 2 is usb detect */ | ||
159 | if (GPIOE_INPUT_VAL & 0x4) | ||
160 | retval = true; | ||
161 | #endif | ||
162 | |||
163 | return retval; | ||
164 | } | ||
165 | #endif /* USB_DETECT_BY_DRV */ | ||
166 | 206 | ||
167 | void usb_drv_int_enable(bool enable) | 207 | void usb_drv_int_enable(bool enable) |
168 | { | 208 | { |
@@ -178,27 +218,46 @@ void usb_drv_int_enable(bool enable) | |||
178 | /* detect host or charger (INSERTED or EXTRACTED) */ | 218 | /* detect host or charger (INSERTED or EXTRACTED) */ |
179 | int usb_detect(void) | 219 | int usb_detect(void) |
180 | { | 220 | { |
181 | #ifdef USB_DETECT_BY_DRV | 221 | #ifdef USB_STATUS_BY_EVENT |
182 | return usb_status; | 222 | return usb_status; |
183 | #else | 223 | #else |
184 | if(usb_pin_detect()) { | 224 | return ((USB_GPIO_INPUT_VAL & USB_GPIO_MASK) == USB_GPIO_VAL) ? |
185 | return USB_INSERTED; | 225 | USB_INSERTED : USB_EXTRACTED; |
186 | } | ||
187 | else { | ||
188 | return USB_EXTRACTED; | ||
189 | } | ||
190 | #endif | 226 | #endif |
191 | } | 227 | } |
192 | 228 | ||
193 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ | 229 | #ifdef USB_FIREWIRE_HANDLING |
194 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | 230 | #ifdef USB_STATUS_BY_EVENT |
231 | static bool firewire_status = false; | ||
232 | #endif | ||
233 | |||
195 | bool firewire_detect(void) | 234 | bool firewire_detect(void) |
196 | { | 235 | { |
236 | #ifdef USB_STATUS_BY_EVENT | ||
237 | return firewire_status; | ||
238 | #else | ||
197 | /* GPIO C bit 1 is firewire detect */ | 239 | /* GPIO C bit 1 is firewire detect */ |
198 | if (!(GPIOC_INPUT_VAL & 0x02)) | 240 | /* no charger detection needed for firewire */ |
199 | /* no charger detection needed for firewire */ | 241 | return (GPIOC_INPUT_VAL & 0x02) == 0x00; |
200 | return true; | ||
201 | else | ||
202 | return false; | ||
203 | } | ||
204 | #endif | 242 | #endif |
243 | } | ||
244 | |||
245 | #ifdef USB_STATUS_BY_EVENT | ||
246 | static int firewire_timeout_event(struct timeout *tmo) | ||
247 | { | ||
248 | if (tmo->data == 0x00) | ||
249 | usb_firewire_connect_event(); | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | void firewire_insert_int(void) | ||
254 | { | ||
255 | static struct timeout firewire_oneshot; | ||
256 | unsigned long val = GPIOC_INPUT_VAL & 0x02; | ||
257 | firewire_status = val == 0x00; | ||
258 | GPIO_WRITE_BITWISE(GPIOC_INT_LEV, val ^ 0x02, 0x02); | ||
259 | GPIOC_INT_CLR = 0x02; | ||
260 | timeout_register(&firewire_oneshot, firewire_timeout_event, HZ/5, val); | ||
261 | } | ||
262 | #endif /* USB_STATUS_BY_EVENT */ | ||
263 | #endif /* USB_FIREWIRE_HANDLING */ | ||
diff --git a/firmware/target/arm/usb-target.h b/firmware/target/arm/usb-target.h index 913ad805ce..8e159617d5 100644 --- a/firmware/target/arm/usb-target.h +++ b/firmware/target/arm/usb-target.h | |||
@@ -22,12 +22,7 @@ | |||
22 | #define USB_TARGET_H | 22 | #define USB_TARGET_H |
23 | 23 | ||
24 | void usb_init_device(void); | 24 | void usb_init_device(void); |
25 | 25 | void usb_insert_int(void); | |
26 | #ifndef BOOTLOADER | 26 | void firewire_insert_int(void); |
27 | #if defined(SANSA_C200) || defined(SANSA_E200) | ||
28 | #define USB_STATUS_BY_EVENT /* No USB tick */ | ||
29 | void usb_connect_event(bool inserted); | ||
30 | #endif | ||
31 | #endif /* BOOTLOADER */ | ||
32 | 27 | ||
33 | #endif | 28 | #endif |