summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2008-11-10 20:55:56 +0000
committerRafaël Carré <rafael.carre@gmail.com>2008-11-10 20:55:56 +0000
commit02dfae031a2362dbbcec70f10a2bfe089719899d (patch)
tree0b86426a84149f9b9bec0d000c1be52df4dd248f
parentf7b1d806e6f48367a2039b1ac08516db355b938c (diff)
Sansa AMS: use the AS3514 ADC driver
Move the ADC defines to as3514.h, and make adc-target.h only include as3514.h Implement the missing API (ascodec_readbytes, ascodec_(un)lock) Revert the changes to the PP-specific arm/ascodec-target.h in r19073, use a AS3525 specific ascodec-target.h while moving the AS3514 specific code in export/as3514.h git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19076 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/export/as3514.h27
-rw-r--r--firmware/target/arm/as3525/adc-target.h (renamed from firmware/target/arm/as3525/adc-as3525.c)18
-rw-r--r--firmware/target/arm/as3525/as3525-codec.c35
-rw-r--r--firmware/target/arm/as3525/ascodec-target.h40
-rw-r--r--firmware/target/arm/ascodec-target.h18
-rw-r--r--firmware/target/arm/sandisk/adc-target.h22
7 files changed, 114 insertions, 48 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index ff75a6c888..0065749088 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -339,7 +339,7 @@ target/arm/as3525/ata_sd_as3525.c
target/arm/as3525/power-as3525.c
target/arm/as3525/usb-as3525.c
#ifndef BOOTLOADER
-target/arm/as3525/adc-as3525.c
+target/arm/adc-as3514.c
target/arm/as3525/pcm-as3525.c
target/arm/as3525/audio-as3525.c
target/arm/as3525/debug-as3525.c
diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h
index 2bbdc2ed66..f3c5c616eb 100644
--- a/firmware/export/as3514.h
+++ b/firmware/export/as3514.h
@@ -22,6 +22,7 @@
#ifndef _AS3514_H
#define _AS3514_H
+#include "config.h"
#include <stdbool.h>
extern int tenthdb2master(int db);
@@ -80,4 +81,30 @@ extern void audiohw_set_sample_rate(int sampling_control);
#define VOLUME_MIN -735
#define VOLUME_MAX 60
+/* ADC channels */
+#define NUM_ADC_CHANNELS 13
+
+#define ADC_BVDD 0 /* Battery voltage of 4V LiIo accumulator */
+#define ADC_RTCSUP 1 /* RTC backup battery voltage */
+#define ADC_UVDD 2 /* USB host voltage */
+#define ADC_CHG_IN 3 /* Charger input voltage */
+#define ADC_CVDD 4 /* Charger pump output voltage */
+#define ADC_BATTEMP 5 /* Battery charging temperature */
+#define ADC_MICSUP1 6 /* Voltage on MicSup1 for remote control
+ or external voltage measurement */
+#define ADC_MICSUP2 7 /* Voltage on MicSup1 for remote control
+ or external voltage measurement */
+#define ADC_VBE1 8 /* Measuring junction temperature @ 2uA */
+#define ADC_VBE2 9 /* Measuring junction temperature @ 1uA */
+#define ADC_I_MICSUP1 10 /* Current of MicSup1 for remote control detection */
+#define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */
+#define ADC_VBAT 12 /* Single cell battery voltage */
+
+#if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
+ || CONFIG_CPU == AS3525
+#define AS3514_I2C_ADDR 0x46
+#else
+#error Unknown target!
+#endif
+
#endif /* _AS3514_H */
diff --git a/firmware/target/arm/as3525/adc-as3525.c b/firmware/target/arm/as3525/adc-target.h
index 6e1aac5a65..007a11af10 100644
--- a/firmware/target/arm/as3525/adc-as3525.c
+++ b/firmware/target/arm/as3525/adc-target.h
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright © 2008 Rafaël Carré
+ * Copyright (C) 2006 by Barry Wardell
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -18,16 +18,10 @@
* KIND, either express or implied.
*
****************************************************************************/
+#ifndef _ADC_TARGET_H_
+#define _ADC_TARGET_H_
-#include "adc.h"
+/* The ADC sources and channels are common to all targets with AS3514 */
+#include "as3514.h"
-/* TODO */
-
-unsigned short adc_read(int channel)
-{
- return 0;
-}
-
-void adc_init(void)
-{
-}
+#endif
diff --git a/firmware/target/arm/as3525/as3525-codec.c b/firmware/target/arm/as3525/as3525-codec.c
index 4d8598eaf1..86bce86c39 100644
--- a/firmware/target/arm/as3525/as3525-codec.c
+++ b/firmware/target/arm/as3525/as3525-codec.c
@@ -38,6 +38,7 @@
*/
#include "ascodec-target.h"
+#include "kernel.h"
#include "as3525.h"
#define I2C2_DATA *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x00))
@@ -53,6 +54,7 @@
#define I2C2_INT_CLR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x40))
#define I2C2_SADDR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x44))
+static struct mutex as_mtx SHAREDBSS_ATTR;
/* initialises the internal i2c bus and prepares for transfers to the codec */
void ascodec_init(void)
@@ -84,7 +86,7 @@ static int i2c_busy(void)
/* returns 0 on success, <0 otherwise */
-int ascodec_write(int index, int value)
+int ascodec_write(unsigned int index, unsigned int value)
{
if (index == 0x21) {
/* prevent setting of the LREG_CP_not bit */
@@ -110,7 +112,7 @@ int ascodec_write(int index, int value)
/* returns value read on success, <0 otherwise */
-int ascodec_read(int index)
+int ascodec_read(unsigned int index)
{
/* check if still busy */
if (i2c_busy()) {
@@ -128,3 +130,32 @@ int ascodec_read(int index)
return I2C2_DATA;
}
+int ascodec_readbytes(int index, int len, unsigned char *data)
+{
+ int i;
+
+ ascodec_lock();
+
+ for(i=0; i<len; i++)
+ {
+ int temp = ascodec_read(index+i);
+ if(temp == -1)
+ break;
+ else
+ data[i] = temp;
+ }
+
+ ascodec_unlock();
+
+ return i;
+}
+
+void ascodec_lock(void)
+{
+ mutex_lock(&as_mtx);
+}
+
+void ascodec_unlock(void)
+{
+ mutex_unlock(&as_mtx);
+}
diff --git a/firmware/target/arm/as3525/ascodec-target.h b/firmware/target/arm/as3525/ascodec-target.h
new file mode 100644
index 0000000000..46f6e11d4b
--- /dev/null
+++ b/firmware/target/arm/as3525/ascodec-target.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Driver for AS3514 audio codec
+ *
+ * Copyright (c) 2007 Daniel Ankers
+ * Copyright (c) 2007 Christian Gmeiner
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef _ASCODEC_TARGET_H
+#define _ASCODEC_TARGET_H
+
+#include "as3514.h"
+
+int ascodec_write(unsigned int index, unsigned int value);
+
+int ascodec_read(unsigned int index);
+
+int ascodec_readbytes(int index, int len, unsigned char *data);
+
+void ascodec_lock(void);
+
+void ascodec_unlock(void);
+
+#endif /* !_ASCODEC_TARGET_H */
diff --git a/firmware/target/arm/ascodec-target.h b/firmware/target/arm/ascodec-target.h
index afd19fff63..3337cb78b9 100644
--- a/firmware/target/arm/ascodec-target.h
+++ b/firmware/target/arm/ascodec-target.h
@@ -27,14 +27,11 @@
#include "config.h"
-#if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) || \
- CONFIG_CPU==AS3525
-#define AS3514_I2C_ADDR 0x46
-#else
-#error Unknown target!
-#endif
-
#ifdef CPU_PP
+/* TODO: This header is actually portalplayer specific, and should be
+ * moved into an appropriate subdir */
+
+#include "as3514.h"
#include "i2c-pp.h"
static inline int ascodec_write(unsigned int reg, unsigned int value)
@@ -61,12 +58,7 @@ static inline void ascodec_unlock(void)
{
i2c_unlock();
}
-#elif CONFIG_CPU==AS3525
-void ascodec_init(void);
-
-int ascodec_write(int index, int value);
-int ascodec_read(int index);
-#endif
+#endif /* CPU_PP */
#endif /* !_ASCODEC_TARGET_H */
diff --git a/firmware/target/arm/sandisk/adc-target.h b/firmware/target/arm/sandisk/adc-target.h
index ab7d5d92ed..007a11af10 100644
--- a/firmware/target/arm/sandisk/adc-target.h
+++ b/firmware/target/arm/sandisk/adc-target.h
@@ -21,25 +21,7 @@
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
-/* ADC channels */
-#define NUM_ADC_CHANNELS 13
-
-#define ADC_BVDD 0 /* Battery voltage of 4V LiIo accumulator */
-#define ADC_RTCSUP 1 /* RTC backup battery voltage */
-#define ADC_UVDD 2 /* USB host voltage */
-#define ADC_CHG_IN 3 /* Charger input voltage */
-#define ADC_CVDD 4 /* Charger pump output voltage */
-#define ADC_BATTEMP 5 /* Battery charging temperature */
-#define ADC_MICSUP1 6 /* Voltage on MicSup1 for remote control
- or external voltage measurement */
-#define ADC_MICSUP2 7 /* Voltage on MicSup1 for remote control
- or external voltage measurement */
-#define ADC_VBE1 8 /* Measuring junction temperature @ 2uA */
-#define ADC_VBE2 9 /* Measuring junction temperature @ 1uA */
-#define ADC_I_MICSUP1 10 /* Current of MicSup1 for remote control detection */
-#define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */
-#define ADC_VBAT 12 /* Single cell battery voltage */
-
-#define ADC_UNREG_POWER ADC_BVDD /* For compatibility */
+/* The ADC sources and channels are common to all targets with AS3514 */
+#include "as3514.h"
#endif