From 02dfae031a2362dbbcec70f10a2bfe089719899d Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Mon, 10 Nov 2008 20:55:56 +0000 Subject: 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 --- firmware/SOURCES | 2 +- firmware/export/as3514.h | 27 +++++++++++++++++++ firmware/target/arm/as3525/adc-as3525.c | 33 ------------------------ firmware/target/arm/as3525/adc-target.h | 27 +++++++++++++++++++ firmware/target/arm/as3525/as3525-codec.c | 35 +++++++++++++++++++++++-- firmware/target/arm/as3525/ascodec-target.h | 40 +++++++++++++++++++++++++++++ firmware/target/arm/ascodec-target.h | 18 ++++--------- firmware/target/arm/sandisk/adc-target.h | 22 ++-------------- 8 files changed, 135 insertions(+), 69 deletions(-) delete mode 100644 firmware/target/arm/as3525/adc-as3525.c create mode 100644 firmware/target/arm/as3525/adc-target.h create mode 100644 firmware/target/arm/as3525/ascodec-target.h 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 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-as3525.c deleted file mode 100644 index 6e1aac5a65..0000000000 --- a/firmware/target/arm/as3525/adc-as3525.c +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright © 2008 Rafaël Carré - * - * 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. - * - ****************************************************************************/ - -#include "adc.h" - -/* TODO */ - -unsigned short adc_read(int channel) -{ - return 0; -} - -void adc_init(void) -{ -} diff --git a/firmware/target/arm/as3525/adc-target.h b/firmware/target/arm/as3525/adc-target.h new file mode 100644 index 0000000000..007a11af10 --- /dev/null +++ b/firmware/target/arm/as3525/adc-target.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * 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 + * 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 _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +/* The ADC sources and channels are common to all targets with AS3514 */ +#include "as3514.h" + +#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 ) \___| < | \_\ ( <_> > < < + * 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 -- cgit v1.2.3