summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2011-12-16 11:20:38 +0000
committerTomasz Moń <desowin@gmail.com>2011-12-16 11:20:38 +0000
commita0b81bdbfc435bfd794a6b1b86c3378ed258c3df (patch)
tree2dc45367bd3d9b3b0e283e614ecbf0aa146f85bc
parenta47982eb608c5a6538bd60f2bb0ffe095f11692e (diff)
Sansa Connect: Disable USB clocks when disconnected.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31323 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c24
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c6
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c93
-rw-r--r--firmware/target/arm/tms320dm320/sdmmc-dm320.c2
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)
IO_SERIAL1_TX_DATA = buf_tx[i];
/* a short wait for AVR to process data */
- sleep(HZ/1000);
+ sleep(0);
do
{
@@ -407,13 +407,9 @@ void GIO0(void)
queue_post(&btn_queue, BTN_INTERRUPT, 0);
}
-void GIO2(void) __attribute__ ((section(".icode")));
-void GIO2(void)
+static int headphones_inserted_callback(struct timeout *tmo)
{
- /* Clear interrupt */
- IO_INTC_IRQ1 = (1 << 7);
- /* Disable interrupt */
- IO_INTC_EINT1 &= ~INTR_EINT1_EXT2;
+ (void)tmo;
if (IO_GIO_BITSET0 & 0x04)
{
@@ -424,7 +420,19 @@ void GIO2(void)
aic3x_switch_output(true);
}
- IO_INTC_EINT1 |= INTR_EINT1_EXT2;
+ return 0;
+}
+
+void GIO2(void) __attribute__ ((section(".icode")));
+void GIO2(void)
+{
+ static struct timeout headphones_oneshot;
+
+ /* Clear interrupt */
+ IO_INTC_IRQ1 = (1 << 7);
+
+ timeout_register(&headphones_oneshot, headphones_inserted_callback,
+ HZ/2, 0);
}
#endif
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)
/* Disable Video Encoder clock */
bitclr16(&IO_CLK_MOD1, CLK_MOD1_VENC);
- /* configure GIO39, GIO34 and GIO33 as outputs */
- IO_GIO_DIR2 &= ~((1 << 7) /* GIO39 */ | (1 << 2) /* GIO34 */ |
- (1 << 1) /* GIO33 */);
+ /* configure GIO39, GIO34 as outputs */
+ IO_GIO_DIR2 &= ~((1 << 7) /* GIO39 */ | (1 << 2) /* GIO34 */);
IO_GIO_FSEL3 = (IO_GIO_FSEL3 & ~(0x300F)) |
(0x1000) /* GIO39 - FIELD_VENC */ |
- (0x3) /* GIO33 - CLKOUT1B (bootloader does this) */ |
(0x4); /* GIO34 - PWM1 (brightness control) */
/* 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 @@
#include "usb_core.h"
#endif
+static bool usb_is_connected = false;
+
+static int usb_detect_callback(struct timeout *tmo)
+{
+ (void)tmo;
+
+ if (IO_GIO_BITSET0 & (1 << 9))
+ {
+ /* Set GIO33 as normal output, drive it low */
+ IO_GIO_FSEL3 &= ~(0x0003);
+ IO_GIO_BITCLR2 = (1 << 1);
+
+ /* Disable M48XI crystal resonator */
+ IO_CLK_LPCTL1 |= 0x01;
+
+ /* Drive reset low */
+ IO_GIO_BITCLR0 = (1 << 7);
+
+ /* Disable VLYNQ clock */
+ IO_CLK_MOD2 &= ~(1 << 13);
+
+ usb_is_connected = false;
+ }
+ else
+ {
+ /* Enable M48XI crystal resonator */
+ IO_CLK_LPCTL1 &= ~(0x01);
+
+ /* Set GIO33 as CLKOUT1B */
+ IO_GIO_FSEL3 |= 0x0003;
+
+ /* Drive reset high */
+ IO_GIO_BITSET0 = (1 << 7);
+
+ /* Enable VLYNQ clock */
+ IO_CLK_MOD2 |= (1 << 13);
+
+ usb_is_connected = true;
+ }
+
+ return 0;
+}
+
+void GIO9(void) __attribute__ ((section(".icode")));
+void GIO9(void)
+{
+ static struct timeout usb_oneshot;
+
+ /* Clear interrupt */
+ IO_INTC_IRQ1 = (1 << 14);
+
+ timeout_register(&usb_oneshot, usb_detect_callback, HZ, 0);
+}
+
bool usb_drv_connected(void)
{
return false;
@@ -35,20 +89,47 @@ bool usb_drv_connected(void)
int usb_detect(void)
{
- return USB_EXTRACTED;
+ if (usb_is_connected == true)
+ {
+ return USB_INSERTED;
+ }
+ else
+ {
+ return USB_EXTRACTED;
+ }
}
void usb_init_device(void)
{
- /* set TNETV USB nreset high */
- IO_GIO_DIR0 &= ~(1 << 7);
- IO_GIO_BITSET0 = (1 << 7);
-
/* set VLYNQ port functions */
IO_GIO_FSEL1 = 0xAAAA;
IO_GIO_FSEL2 = (IO_GIO_FSEL2 & 0xFFF0) | 0xA;
- return;
+ /* set GIO7 as output (TNETV reset) */
+ /* set GIO9 as input (USB inserted indicator) */
+ IO_GIO_INV0 &= ~((1 << 7) | (1 << 9));
+ IO_GIO_DIR0 = (IO_GIO_DIR0 & ~(1 << 7)) | (1 << 9);
+
+ /* Enable interrupt on GIO9 change (any edge) */
+ IO_GIO_IRQPORT |= (1 << 9);
+ IO_GIO_IRQEDGE |= (1 << 9);
+
+ /* set GIO33 as output (TNETV clock) */
+ IO_GIO_DIR2 &= ~(1 << 1);
+ IO_GIO_INV2 &= ~(1 << 1);
+ /* use M48XI clock on GIO33 */
+ IO_CLK_OSEL = (IO_CLK_OSEL & 0xF0F) | 0x50;
+
+ /* Powerdown internal USB */
+ IO_CLK_LPCTL1 = 0x11;
+ /* Disable internal USB clock */
+ IO_CLK_MOD2 &= ~(1 << 6);
+
+ /* Enable USB insert detection interrupt */
+ IO_INTC_EINT1 |= (1 << 14);
+
+ /* Check if USB is connected */
+ usb_detect_callback(NULL);
}
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)
/* mmc module clock: 75 Mhz (AHB) / 2 = ~37.5 Mhz
* (Frequencies above are taken from Sansa Connect's OF source code) */
- IO_CLK_DIV3 = (IO_CLK_DIV3 & 0xFF00) | 0x01;
+ IO_CLK_DIV3 = (IO_CLK_DIV3 & 0xFF00) | 0x02; /* OF uses 1 */
bitset16(&IO_CLK_MOD2, CLK_MOD2_MMC);