diff options
author | Tomasz Moń <desowin@gmail.com> | 2011-12-16 11:20:38 +0000 |
---|---|---|
committer | Tomasz Moń <desowin@gmail.com> | 2011-12-16 11:20:38 +0000 |
commit | a0b81bdbfc435bfd794a6b1b86c3378ed258c3df (patch) | |
tree | 2dc45367bd3d9b3b0e283e614ecbf0aa146f85bc | |
parent | a47982eb608c5a6538bd60f2bb0ffe095f11692e (diff) | |
download | rockbox-a0b81bdbfc435bfd794a6b1b86c3378ed258c3df.tar.gz rockbox-a0b81bdbfc435bfd794a6b1b86c3378ed258c3df.zip |
Sansa Connect: Disable USB clocks when disconnected.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31323 a1c6a512-1295-4272-9138-f99709370657
4 files changed, 106 insertions, 19 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c index 2ed69b6c9b..c22bd2c21d 100644 --- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c +++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | |||
@@ -230,7 +230,7 @@ static void spi_txrx(unsigned char *buf_tx, unsigned char *buf_rx, int n) | |||
230 | IO_SERIAL1_TX_DATA = buf_tx[i]; | 230 | IO_SERIAL1_TX_DATA = buf_tx[i]; |
231 | 231 | ||
232 | /* a short wait for AVR to process data */ | 232 | /* a short wait for AVR to process data */ |
233 | sleep(HZ/1000); | 233 | sleep(0); |
234 | 234 | ||
235 | do | 235 | do |
236 | { | 236 | { |
@@ -407,13 +407,9 @@ void GIO0(void) | |||
407 | queue_post(&btn_queue, BTN_INTERRUPT, 0); | 407 | queue_post(&btn_queue, BTN_INTERRUPT, 0); |
408 | } | 408 | } |
409 | 409 | ||
410 | void GIO2(void) __attribute__ ((section(".icode"))); | 410 | static int headphones_inserted_callback(struct timeout *tmo) |
411 | void GIO2(void) | ||
412 | { | 411 | { |
413 | /* Clear interrupt */ | 412 | (void)tmo; |
414 | IO_INTC_IRQ1 = (1 << 7); | ||
415 | /* Disable interrupt */ | ||
416 | IO_INTC_EINT1 &= ~INTR_EINT1_EXT2; | ||
417 | 413 | ||
418 | if (IO_GIO_BITSET0 & 0x04) | 414 | if (IO_GIO_BITSET0 & 0x04) |
419 | { | 415 | { |
@@ -424,7 +420,19 @@ void GIO2(void) | |||
424 | aic3x_switch_output(true); | 420 | aic3x_switch_output(true); |
425 | } | 421 | } |
426 | 422 | ||
427 | IO_INTC_EINT1 |= INTR_EINT1_EXT2; | 423 | return 0; |
424 | } | ||
425 | |||
426 | void GIO2(void) __attribute__ ((section(".icode"))); | ||
427 | void GIO2(void) | ||
428 | { | ||
429 | static struct timeout headphones_oneshot; | ||
430 | |||
431 | /* Clear interrupt */ | ||
432 | IO_INTC_IRQ1 = (1 << 7); | ||
433 | |||
434 | timeout_register(&headphones_oneshot, headphones_inserted_callback, | ||
435 | HZ/2, 0); | ||
428 | } | 436 | } |
429 | #endif | 437 | #endif |
430 | 438 | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c index e53a15e94f..308b4297c2 100644 --- a/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c +++ b/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c | |||
@@ -89,13 +89,11 @@ void lcd_init_device(void) | |||
89 | /* Disable Video Encoder clock */ | 89 | /* Disable Video Encoder clock */ |
90 | bitclr16(&IO_CLK_MOD1, CLK_MOD1_VENC); | 90 | bitclr16(&IO_CLK_MOD1, CLK_MOD1_VENC); |
91 | 91 | ||
92 | /* configure GIO39, GIO34 and GIO33 as outputs */ | 92 | /* configure GIO39, GIO34 as outputs */ |
93 | IO_GIO_DIR2 &= ~((1 << 7) /* GIO39 */ | (1 << 2) /* GIO34 */ | | 93 | IO_GIO_DIR2 &= ~((1 << 7) /* GIO39 */ | (1 << 2) /* GIO34 */); |
94 | (1 << 1) /* GIO33 */); | ||
95 | 94 | ||
96 | IO_GIO_FSEL3 = (IO_GIO_FSEL3 & ~(0x300F)) | | 95 | IO_GIO_FSEL3 = (IO_GIO_FSEL3 & ~(0x300F)) | |
97 | (0x1000) /* GIO39 - FIELD_VENC */ | | 96 | (0x1000) /* GIO39 - FIELD_VENC */ | |
98 | (0x3) /* GIO33 - CLKOUT1B (bootloader does this) */ | | ||
99 | (0x4); /* GIO34 - PWM1 (brightness control) */ | 97 | (0x4); /* GIO34 - PWM1 (brightness control) */ |
100 | 98 | ||
101 | /* OSD Clock = VENC Clock /2, | 99 | /* OSD Clock = VENC Clock /2, |
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c index 979b1b9eb2..abe6622f0b 100644 --- a/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c +++ b/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c | |||
@@ -28,6 +28,60 @@ | |||
28 | #include "usb_core.h" | 28 | #include "usb_core.h" |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | static bool usb_is_connected = false; | ||
32 | |||
33 | static int usb_detect_callback(struct timeout *tmo) | ||
34 | { | ||
35 | (void)tmo; | ||
36 | |||
37 | if (IO_GIO_BITSET0 & (1 << 9)) | ||
38 | { | ||
39 | /* Set GIO33 as normal output, drive it low */ | ||
40 | IO_GIO_FSEL3 &= ~(0x0003); | ||
41 | IO_GIO_BITCLR2 = (1 << 1); | ||
42 | |||
43 | /* Disable M48XI crystal resonator */ | ||
44 | IO_CLK_LPCTL1 |= 0x01; | ||
45 | |||
46 | /* Drive reset low */ | ||
47 | IO_GIO_BITCLR0 = (1 << 7); | ||
48 | |||
49 | /* Disable VLYNQ clock */ | ||
50 | IO_CLK_MOD2 &= ~(1 << 13); | ||
51 | |||
52 | usb_is_connected = false; | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | /* Enable M48XI crystal resonator */ | ||
57 | IO_CLK_LPCTL1 &= ~(0x01); | ||
58 | |||
59 | /* Set GIO33 as CLKOUT1B */ | ||
60 | IO_GIO_FSEL3 |= 0x0003; | ||
61 | |||
62 | /* Drive reset high */ | ||
63 | IO_GIO_BITSET0 = (1 << 7); | ||
64 | |||
65 | /* Enable VLYNQ clock */ | ||
66 | IO_CLK_MOD2 |= (1 << 13); | ||
67 | |||
68 | usb_is_connected = true; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void GIO9(void) __attribute__ ((section(".icode"))); | ||
75 | void GIO9(void) | ||
76 | { | ||
77 | static struct timeout usb_oneshot; | ||
78 | |||
79 | /* Clear interrupt */ | ||
80 | IO_INTC_IRQ1 = (1 << 14); | ||
81 | |||
82 | timeout_register(&usb_oneshot, usb_detect_callback, HZ, 0); | ||
83 | } | ||
84 | |||
31 | bool usb_drv_connected(void) | 85 | bool usb_drv_connected(void) |
32 | { | 86 | { |
33 | return false; | 87 | return false; |
@@ -35,20 +89,47 @@ bool usb_drv_connected(void) | |||
35 | 89 | ||
36 | int usb_detect(void) | 90 | int usb_detect(void) |
37 | { | 91 | { |
38 | return USB_EXTRACTED; | 92 | if (usb_is_connected == true) |
93 | { | ||
94 | return USB_INSERTED; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | return USB_EXTRACTED; | ||
99 | } | ||
39 | } | 100 | } |
40 | 101 | ||
41 | void usb_init_device(void) | 102 | void usb_init_device(void) |
42 | { | 103 | { |
43 | /* set TNETV USB nreset high */ | ||
44 | IO_GIO_DIR0 &= ~(1 << 7); | ||
45 | IO_GIO_BITSET0 = (1 << 7); | ||
46 | |||
47 | /* set VLYNQ port functions */ | 104 | /* set VLYNQ port functions */ |
48 | IO_GIO_FSEL1 = 0xAAAA; | 105 | IO_GIO_FSEL1 = 0xAAAA; |
49 | IO_GIO_FSEL2 = (IO_GIO_FSEL2 & 0xFFF0) | 0xA; | 106 | IO_GIO_FSEL2 = (IO_GIO_FSEL2 & 0xFFF0) | 0xA; |
50 | 107 | ||
51 | return; | 108 | /* set GIO7 as output (TNETV reset) */ |
109 | /* set GIO9 as input (USB inserted indicator) */ | ||
110 | IO_GIO_INV0 &= ~((1 << 7) | (1 << 9)); | ||
111 | IO_GIO_DIR0 = (IO_GIO_DIR0 & ~(1 << 7)) | (1 << 9); | ||
112 | |||
113 | /* Enable interrupt on GIO9 change (any edge) */ | ||
114 | IO_GIO_IRQPORT |= (1 << 9); | ||
115 | IO_GIO_IRQEDGE |= (1 << 9); | ||
116 | |||
117 | /* set GIO33 as output (TNETV clock) */ | ||
118 | IO_GIO_DIR2 &= ~(1 << 1); | ||
119 | IO_GIO_INV2 &= ~(1 << 1); | ||
120 | /* use M48XI clock on GIO33 */ | ||
121 | IO_CLK_OSEL = (IO_CLK_OSEL & 0xF0F) | 0x50; | ||
122 | |||
123 | /* Powerdown internal USB */ | ||
124 | IO_CLK_LPCTL1 = 0x11; | ||
125 | /* Disable internal USB clock */ | ||
126 | IO_CLK_MOD2 &= ~(1 << 6); | ||
127 | |||
128 | /* Enable USB insert detection interrupt */ | ||
129 | IO_INTC_EINT1 |= (1 << 14); | ||
130 | |||
131 | /* Check if USB is connected */ | ||
132 | usb_detect_callback(NULL); | ||
52 | } | 133 | } |
53 | 134 | ||
54 | void usb_enable(bool on) | 135 | void usb_enable(bool on) |
diff --git a/firmware/target/arm/tms320dm320/sdmmc-dm320.c b/firmware/target/arm/tms320dm320/sdmmc-dm320.c index 6c744755f2..6b5399d9a2 100644 --- a/firmware/target/arm/tms320dm320/sdmmc-dm320.c +++ b/firmware/target/arm/tms320dm320/sdmmc-dm320.c | |||
@@ -893,7 +893,7 @@ int sd_init(void) | |||
893 | 893 | ||
894 | /* mmc module clock: 75 Mhz (AHB) / 2 = ~37.5 Mhz | 894 | /* mmc module clock: 75 Mhz (AHB) / 2 = ~37.5 Mhz |
895 | * (Frequencies above are taken from Sansa Connect's OF source code) */ | 895 | * (Frequencies above are taken from Sansa Connect's OF source code) */ |
896 | IO_CLK_DIV3 = (IO_CLK_DIV3 & 0xFF00) | 0x01; | 896 | IO_CLK_DIV3 = (IO_CLK_DIV3 & 0xFF00) | 0x02; /* OF uses 1 */ |
897 | 897 | ||
898 | bitset16(&IO_CLK_MOD2, CLK_MOD2_MMC); | 898 | bitset16(&IO_CLK_MOD2, CLK_MOD2_MMC); |
899 | 899 | ||