summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2008-10-26 13:28:52 +0000
committerBertrik Sikken <bertrik@sikken.nl>2008-10-26 13:28:52 +0000
commit95726a5c239d37a453efa7fe4e2f7cfdb96f536b (patch)
tree35f2a66a2ea58ddb1fff97a51018c26cbeefbb51
parent92683778f615a5ff079fec12ea256643c669194a (diff)
downloadrockbox-95726a5c239d37a453efa7fe4e2f7cfdb96f536b.tar.gz
rockbox-95726a5c239d37a453efa7fe4e2f7cfdb96f536b.tar.bz2
rockbox-95726a5c239d37a453efa7fe4e2f7cfdb96f536b.zip
FS#9503 - Sansa v2 audio/PMU communication driver (for the AS3525 SoC)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18886 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/sansa_as3525.c11
-rw-r--r--firmware/SOURCES3
-rw-r--r--firmware/target/arm/as3525/as3525-codec.c132
-rw-r--r--firmware/target/arm/as3525/as3525-codec.h27
4 files changed, 173 insertions, 0 deletions
diff --git a/bootloader/sansa_as3525.c b/bootloader/sansa_as3525.c
index b9975a9722..6f230c2628 100644
--- a/bootloader/sansa_as3525.c
+++ b/bootloader/sansa_as3525.c
@@ -28,10 +28,14 @@
#include "lcd.h"
#include "common.h"
#include "config.h"
+#include "as3525-codec.h"
int show_logo(void);
void main(void)
{
+ int i;
+ unsigned char buf[8];
+
lcd_init_device();
lcd_clear_display();
@@ -43,6 +47,13 @@ void main(void)
show_logo();
+ /* show player id to demonstrate communication with codec part */
+ as3525_codec_init();
+ for (i = 0; i < 8; i++) {
+ buf[i] = as3525_codec_read(0x38 + i);
+ }
+ printf("ID: %02X%02X%02X%02X%02X%02X%02X%02X", buf[7], buf[6], buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]);
+
#ifdef SANSA_CLIP
/* Use hardware scrolling */
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 4407b0e8b9..7a93d058b4 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1038,6 +1038,7 @@ target/arm/pcm-telechips.c
#ifndef SIMULATOR
target/arm/as3525/sansa-clip/lcd-ssd1303.c
target/arm/as3525/sansa-clip/button-clip.c
+target/arm/as3525/as3525-codec.c
#endif /* !SIMULATOR */
#endif /* SANSA_CLIP */
@@ -1045,6 +1046,7 @@ target/arm/as3525/sansa-clip/button-clip.c
#ifndef SIMULATOR
target/arm/as3525/sansa-e200v2/lcd-e200v2.c
target/arm/as3525/sansa-e200v2/button-e200v2.c
+target/arm/as3525/as3525-codec.c
#endif /* !SIMULATOR */
#endif /* SANSA_E200V2 */
@@ -1052,6 +1054,7 @@ target/arm/as3525/sansa-e200v2/button-e200v2.c
#ifndef SIMULATOR
target/arm/lcd-ssd1815.c
target/arm/as3525/sansa-m200v2/button-m200v2.c
+target/arm/as3525/as3525-codec.c
#endif /* !SIMULATOR */
#endif /* SANSA_M200V2 */
diff --git a/firmware/target/arm/as3525/as3525-codec.c b/firmware/target/arm/as3525/as3525-codec.c
new file mode 100644
index 0000000000..1de2f49e1a
--- /dev/null
+++ b/firmware/target/arm/as3525/as3525-codec.c
@@ -0,0 +1,132 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: $
+ *
+ * Copyright (C) 2008 by Bertrik Sikken
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/*
+ Provides access to the codec/charger/rtc/adc part of the as3525.
+ This part is on address 0x46 of the internal i2c bus in the as3525.
+ Registers in the codec part seem to be nearly identical to the registers
+ in the AS3514 (used in the "v1" versions of the sansa c200 and e200).
+
+ I2C register description:
+ * I2C2_CNTRL needs to be set to 0x51 for transfers to work at all.
+ bit 1 indicates direction of transfer (0 = write, 1 = read)
+ * I2C2_SR (status register) indicates in bit 0 if a transfer is busy.
+ * I2C2_SLAD0 contains the i2c slave address to read from / write to.
+ * I2C2_CPSR0/1 is the divider from the peripheral clock to the i2c clock.
+ * I2C2_DACNT sets the number of bytes to transfer and actually starts it.
+
+ When a transfer is attempted to a non-existing i2c slave address,
+ interrupt bit 7 is raised and DACNT is not decremented after the transfer.
+ */
+
+#include "as3525-codec.h"
+#include "as3525.h"
+
+#define AUDIO_I2C_ADDR 0x46
+
+#define I2C2_DATA *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x00))
+#define I2C2_SLAD0 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x04))
+#define I2C2_CNTRL *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x0C))
+#define I2C2_DACNT *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x10))
+#define I2C2_CPSR0 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x1C))
+#define I2C2_CPSR1 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x20))
+#define I2C2_IMR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x24))
+#define I2C2_RIS *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x28))
+#define I2C2_MIS *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x2C))
+#define I2C2_SR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x30))
+#define I2C2_INT_CLR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x40))
+#define I2C2_SADDR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x44))
+
+
+/* initialises the internal i2c bus and prepares for transfers to the codec */
+void as3525_codec_init(void)
+{
+ /* reset device */
+ CCU_SRC = CCU_SRC_I2C_AUDIO_EN;
+ CCU_SRL = CCU_SRL_MAGIC_NUMBER;
+ CCU_SRL = 0;
+
+ /* enable clock */
+ CGU_PERI |= CGU_I2C_AUDIO_MASTER_CLOCK_ENABLE;
+
+ /* prescaler for i2c clock */
+ I2C2_CPSR0 = 60; /* 24 MHz / 400 kHz */
+ I2C2_CPSR1 = 0; /* MSB */
+
+ /* set i2c slave address of codec part */
+ I2C2_SLAD0 = AUDIO_I2C_ADDR << 1;
+
+ I2C2_CNTRL = 0x51;
+}
+
+
+/* returns != 0 when busy */
+static int i2c_busy(void)
+{
+ return (I2C2_SR & 1);
+}
+
+
+/* returns 0 on success, <0 otherwise */
+int as3525_codec_write(int index, int value)
+{
+ if (index == 0x21) {
+ /* prevent setting of the LREG_CP_not bit */
+ value &= ~(1 << 5);
+ }
+
+ /* check if still busy */
+ if (i2c_busy()) {
+ return -1;
+ }
+
+ /* start transfer */
+ I2C2_SADDR = index;
+ I2C2_CNTRL &= ~(1 << 1);
+ I2C2_DATA = value;
+ I2C2_DACNT = 1;
+
+ /* wait for transfer*/
+ while (i2c_busy());
+
+ return 0;
+}
+
+
+/* returns value read on success, <0 otherwise */
+int as3525_codec_read(int index)
+{
+ /* check if still busy */
+ if (i2c_busy()) {
+ return -1;
+ }
+
+ /* start transfer */
+ I2C2_SADDR = index;
+ I2C2_CNTRL |= (1 << 1);
+ I2C2_DACNT = 1;
+
+ /* wait for transfer*/
+ while (i2c_busy());
+
+ return I2C2_DATA;
+}
+
diff --git a/firmware/target/arm/as3525/as3525-codec.h b/firmware/target/arm/as3525/as3525-codec.h
new file mode 100644
index 0000000000..9d694554c6
--- /dev/null
+++ b/firmware/target/arm/as3525/as3525-codec.h
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: $
+ *
+ * Copyright (C) 2008 by Bertrik Sikken
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+void as3525_codec_init(void);
+
+int as3525_codec_write(int index, int value);
+int as3525_codec_read(int index);
+
+