From 42f77d4eb027afed4f4ef80f10c16112c2b7fe2b Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Fri, 31 Oct 2008 00:16:42 +0000 Subject: Abstract the PortalPlayer AS3514 handling with an "ascodec" API - inspired by the wmcodec API used with the Wolfson codecs. The intention is to implement this API for the AS3525 and then share code with the Sansa V2 ports. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18940 a1c6a512-1295-4272-9138-f99709370657 --- apps/debug_menu.c | 6 +- firmware/SOURCES | 3 + firmware/drivers/audio/as3514.c | 38 ++---------- firmware/drivers/rtc/rtc_as3514.c | 5 +- firmware/export/as3514.h | 4 -- firmware/export/ascodec.h | 27 +++++++++ firmware/target/arm/adc-as3514.c | 10 ++-- firmware/target/arm/ascodec-pp.c | 66 +++++++++++++++++++++ firmware/target/arm/ascodec-target.h | 69 ++++++++++++++++++++++ firmware/target/arm/i2c-pp.c | 3 +- .../target/arm/philips/sa9200/backlight-sa9200.c | 6 +- firmware/target/arm/philips/sa9200/power-sa9200.c | 4 +- firmware/target/arm/sandisk/backlight-c200_e200.c | 6 +- firmware/target/arm/sandisk/power-c200_e200.c | 6 +- firmware/usbstack/usb_core.c | 4 +- 15 files changed, 196 insertions(+), 61 deletions(-) create mode 100644 firmware/export/ascodec.h create mode 100644 firmware/target/arm/ascodec-pp.c create mode 100644 firmware/target/arm/ascodec-target.h diff --git a/apps/debug_menu.c b/apps/debug_menu.c index ad19c3a7b2..8c4622828d 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -103,7 +103,7 @@ #endif #if defined(SANSA_E200) || defined(PHILIPS_SA9200) -#include "i2c-pp.h" +#include "ascodec.h" #include "as3514.h" #endif @@ -1228,7 +1228,9 @@ bool dbg_ports(void) lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT)); lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X", i2c_readbyte(AS3514_I2C_ADDR, AS3514_CHARGER), i2c_readbyte(AS3514_I2C_ADDR, AS3514_IRQ_ENRD0)); + snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X", + ascodec_read(AS3514_CHARGER), + ascodec_read(AS3514_IRQ_ENRD0)); lcd_puts(0, line++, buf); #endif #endif diff --git a/firmware/SOURCES b/firmware/SOURCES index 400074a0e9..e73e94b453 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -460,6 +460,7 @@ target/arm/lcd-as-memframe.S target/arm/ata-sd-pp.c target/arm/sandisk/sansa-e200/lcd-e200.c target/arm/adc-as3514.c +target/arm/ascodec-pp.c target/arm/sandisk/backlight-c200_e200.c target/arm/usb-fw-pp502x.c target/arm/sandisk/sansa-e200/button-e200.c @@ -478,6 +479,7 @@ target/arm/ata-sd-pp.c target/arm/sandisk/sansa-c200/lcd-c200.c target/arm/sandisk/sansa-c200/lcd-as-c200.S target/arm/adc-as3514.c +target/arm/ascodec-pp.c target/arm/sandisk/backlight-c200_e200.c target/arm/usb-fw-pp502x.c target/arm/sandisk/sansa-c200/button-c200.c @@ -495,6 +497,7 @@ target/arm/sandisk/audio-c200_e200.c target/arm/ata-sd-pp.c target/arm/philips/sa9200/lcd-sa9200.c target/arm/adc-as3514.c +target/arm/ascodec-pp.c target/arm/philips/sa9200/backlight-sa9200.c target/arm/usb-fw-pp502x.c target/arm/philips/sa9200/button-sa9200.c diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c index 97117e48c3..db4cb0699f 100644 --- a/firmware/drivers/audio/as3514.c +++ b/firmware/drivers/audio/as3514.c @@ -29,7 +29,7 @@ #include "audiohw.h" #include "i2s.h" -#include "i2c-pp.h" +#include "ascodec.h" const struct sound_settings_info audiohw_settings[] = { [SOUND_VOLUME] = {"dB", 0, 1, -74, 6, -25}, @@ -71,7 +71,7 @@ static unsigned int source = SOURCE_DAC; */ static void as3514_write(unsigned int reg, unsigned int value) { - if (pp_i2c_send(AS3514_I2C_ADDR, reg, value) != 2) + if (ascodec_write(reg, value) != 2) { DEBUGF("as3514 error reg=0x%02x", reg); } @@ -135,36 +135,10 @@ int sound_val2phys(int setting, int value) /* * Initialise the PP I2C and I2S. */ -void audiohw_init(void) +void audiohw_preinit(void) { unsigned int i; - /* normal outputs for CDI and I2S pin groups */ - DEV_INIT2 &= ~0x300; - - /*mini2?*/ - DEV_INIT1 &=~0x3000000; - /*mini2?*/ - - /* device reset */ - DEV_RS |= DEV_I2S; - DEV_RS &=~DEV_I2S; - - /* I2S device reset */ - DEV_RS |= DEV_I2S; - DEV_RS &=~DEV_I2S; - - /* I2S device enable */ - DEV_EN |= DEV_I2S; - - /* enable external dev clock clocks */ - DEV_EN |= DEV_EXTCLOCKS; - - /* external dev clock to 24MHz */ - outl(inl(0x70000018) & ~0xc, 0x70000018); - - i2s_reset(); - /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */ /* Turn on SUM, DAC */ @@ -199,14 +173,10 @@ void audiohw_init(void) /* read all reg values */ for (i = 0; i < ARRAYLEN(as3514.regs); i++) { - as3514.regs[i] = i2c_readbyte(AS3514_I2C_ADDR, i); + as3514.regs[i] = ascodec_read(i); } } -void audiohw_postinit(void) -{ -} - /* Silently enable / disable audio output */ void audiohw_enable_output(bool enable) { diff --git a/firmware/drivers/rtc/rtc_as3514.c b/firmware/drivers/rtc/rtc_as3514.c index 65d8359e08..878f204a4e 100644 --- a/firmware/drivers/rtc/rtc_as3514.c +++ b/firmware/drivers/rtc/rtc_as3514.c @@ -22,6 +22,7 @@ #include "rtc.h" #include "i2c-pp.h" #include "as3514.h" +#include "ascodec.h" #define MINUTE_SECONDS 60 #define HOUR_SECONDS 3600 @@ -57,7 +58,7 @@ int rtc_read_datetime(unsigned char* buf) /* RTC_AS3514's slave address is 0x46*/ for (i=0;i<4;i++){ - tmp[i] = i2c_readbyte(AS3514_I2C_ADDR, AS3514_RTC_0 + i); + tmp[i] = ascodec_read(AS3514_RTC_0 + i); } seconds = tmp[0] + (tmp[1]<<8) + (tmp[2]<<16) + (tmp[3]<<24); @@ -162,7 +163,7 @@ int rtc_write_datetime(unsigned char* buf) /* Send data to RTC */ for (i=0;i<4;i++){ - pp_i2c_send(AS3514_I2C_ADDR, AS3514_RTC_0 + i, ((seconds >> (8 * i)) & 0xff)); + ascodec_write(AS3514_RTC_0 + i, ((seconds >> (8 * i)) & 0xff)); } return 1; } diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h index aa9847c6a1..9585f5e0ef 100644 --- a/firmware/export/as3514.h +++ b/firmware/export/as3514.h @@ -79,8 +79,4 @@ extern void audiohw_set_sample_rate(int sampling_control); #define VOLUME_MIN -735 #define VOLUME_MAX 60 -#if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) -#define AS3514_I2C_ADDR 0x46 -#endif - #endif /* _AS3514_H */ diff --git a/firmware/export/ascodec.h b/firmware/export/ascodec.h new file mode 100644 index 0000000000..b8bab8a640 --- /dev/null +++ b/firmware/export/ascodec.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Dave Chapman + * + * 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_H +#define _ASCODEC_H + +#include "ascodec-target.h" + +#endif diff --git a/firmware/target/arm/adc-as3514.c b/firmware/target/arm/adc-as3514.c index 26cdc76f0d..9c2a421441 100644 --- a/firmware/target/arm/adc-as3514.c +++ b/firmware/target/arm/adc-as3514.c @@ -20,7 +20,7 @@ ****************************************************************************/ #include "adc.h" #include "kernel.h" -#include "i2c-pp.h" +#include "ascodec.h" #include "as3514.h" /* Read 10-bit channel data */ @@ -30,21 +30,21 @@ unsigned short adc_read(int channel) if ((unsigned)channel < NUM_ADC_CHANNELS) { - i2c_lock(); + ascodec_lock(); /* Select channel */ - if (pp_i2c_send( AS3514_I2C_ADDR, AS3514_ADC_0, (channel << 4)) >= 0) + if (ascodec_write(AS3514_ADC_0, (channel << 4)) >= 0) { unsigned char buf[2]; /* Read data */ - if (i2c_readbytes( AS3514_I2C_ADDR, AS3514_ADC_0, 2, buf) >= 0) + if (ascodec_readbytes(AS3514_ADC_0, 2, buf) >= 0) { data = (((buf[0] & 0x3) << 8) | buf[1]); } } - i2c_unlock(); + ascodec_unlock(); } return data; diff --git a/firmware/target/arm/ascodec-pp.c b/firmware/target/arm/ascodec-pp.c new file mode 100644 index 0000000000..30b6b1f8de --- /dev/null +++ b/firmware/target/arm/ascodec-pp.c @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#include "cpu.h" +#include "system.h" + +#include "audiohw.h" +#include "i2s.h" + +/* + * Initialise the PP I2C and I2S. + */ +void audiohw_init(void) +{ + /* normal outputs for CDI and I2S pin groups */ + DEV_INIT2 &= ~0x300; + + /*mini2?*/ + DEV_INIT1 &=~0x3000000; + /*mini2?*/ + + /* device reset */ + DEV_RS |= DEV_I2S; + DEV_RS &=~DEV_I2S; + + /* I2S device reset */ + DEV_RS |= DEV_I2S; + DEV_RS &=~DEV_I2S; + + /* I2S device enable */ + DEV_EN |= DEV_I2S; + + /* enable external dev clock clocks */ + DEV_EN |= DEV_EXTCLOCKS; + + /* external dev clock to 24MHz */ + outl(inl(0x70000018) & ~0xc, 0x70000018); + + i2s_reset(); + + audiohw_preinit(); +} + +void audiohw_postinit(void) +{ +} diff --git a/firmware/target/arm/ascodec-target.h b/firmware/target/arm/ascodec-target.h new file mode 100644 index 0000000000..19b1644541 --- /dev/null +++ b/firmware/target/arm/ascodec-target.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "config.h" + +#ifdef CPU_PP +/* TODO: This header is actually portalplayer specific, and should be + * moved into an appropriate subdir */ + +#include "i2c-pp.h" + +#if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) +#define AS3514_I2C_ADDR 0x46 +#else +#error Unknown target! +#endif + +static inline int ascodec_write(unsigned int reg, unsigned int value) +{ + return pp_i2c_send(AS3514_I2C_ADDR, reg, value); +} + +static inline int ascodec_read(unsigned int reg) +{ + return i2c_readbyte(AS3514_I2C_ADDR, reg); +} + +static inline int ascodec_readbytes(int addr, int len, unsigned char *data) +{ + return i2c_readbytes(AS3514_I2C_ADDR, addr, len, data); +} + +static inline void ascodec_lock(void) +{ + i2c_lock(); +} + +static inline void ascodec_unlock(void) +{ + i2c_unlock(); +} + +#endif /* CPU_PP */ + +#endif /* !_ASCODEC_TARGET_H */ diff --git a/firmware/target/arm/i2c-pp.c b/firmware/target/arm/i2c-pp.c index 4d83208d91..3db25c027c 100644 --- a/firmware/target/arm/i2c-pp.c +++ b/firmware/target/arm/i2c-pp.c @@ -32,6 +32,7 @@ #include "logf.h" #include "system.h" #include "i2c-pp.h" +#include "ascodec.h" #include "as3514.h" /* Local functions definitions */ @@ -230,7 +231,7 @@ void i2c_init(void) outl(0, 0x600060a4); outl(0x1e, 0x600060a4); - pp_i2c_send(AS3514_I2C_ADDR, AS3514_SUPERVISOR, 5); + ascodec_write(AS3514_SUPERVISOR, 5); #endif #endif diff --git a/firmware/target/arm/philips/sa9200/backlight-sa9200.c b/firmware/target/arm/philips/sa9200/backlight-sa9200.c index 33342d19f1..b3984ca9ad 100644 --- a/firmware/target/arm/philips/sa9200/backlight-sa9200.c +++ b/firmware/target/arm/philips/sa9200/backlight-sa9200.c @@ -23,7 +23,7 @@ #include "system.h" #include "lcd.h" #include "backlight.h" -#include "i2c-pp.h" +#include "ascodec.h" #include "as3514.h" static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; @@ -46,12 +46,12 @@ void _backlight_on(void) #ifdef HAVE_LCD_ENABLE lcd_enable(true); /* power on lcd + visible display */ #endif - pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, backlight_brightness); + ascodec_write(AS3514_DCDC15, backlight_brightness); } void _backlight_off(void) { - pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, 0x0); + ascodec_write(AS3514_DCDC15, 0x0); #ifdef HAVE_LCD_ENABLE lcd_enable(false); /* power off visible display */ #endif diff --git a/firmware/target/arm/philips/sa9200/power-sa9200.c b/firmware/target/arm/philips/sa9200/power-sa9200.c index a559f65ec4..b005a86651 100644 --- a/firmware/target/arm/philips/sa9200/power-sa9200.c +++ b/firmware/target/arm/philips/sa9200/power-sa9200.c @@ -36,9 +36,9 @@ void power_off(void) char byte; /* Send shutdown command to PMU */ - byte = i2c_readbyte(AS3514_I2C_ADDR, AS3514_SYSTEM); + byte = ascodec_read(AS3514_SYSTEM); byte &= ~0x1; - pp_i2c_send(AS3514_I2C_ADDR, AS3514_SYSTEM, byte); + ascodec_write(AS3514_SYSTEM, byte); /* Stop interrupts on both cores */ disable_interrupt(IRQ_FIQ_STATUS); diff --git a/firmware/target/arm/sandisk/backlight-c200_e200.c b/firmware/target/arm/sandisk/backlight-c200_e200.c index 33342d19f1..b3984ca9ad 100644 --- a/firmware/target/arm/sandisk/backlight-c200_e200.c +++ b/firmware/target/arm/sandisk/backlight-c200_e200.c @@ -23,7 +23,7 @@ #include "system.h" #include "lcd.h" #include "backlight.h" -#include "i2c-pp.h" +#include "ascodec.h" #include "as3514.h" static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; @@ -46,12 +46,12 @@ void _backlight_on(void) #ifdef HAVE_LCD_ENABLE lcd_enable(true); /* power on lcd + visible display */ #endif - pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, backlight_brightness); + ascodec_write(AS3514_DCDC15, backlight_brightness); } void _backlight_off(void) { - pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, 0x0); + ascodec_write(AS3514_DCDC15, 0x0); #ifdef HAVE_LCD_ENABLE lcd_enable(false); /* power off visible display */ #endif diff --git a/firmware/target/arm/sandisk/power-c200_e200.c b/firmware/target/arm/sandisk/power-c200_e200.c index a559f65ec4..d6319f44bb 100644 --- a/firmware/target/arm/sandisk/power-c200_e200.c +++ b/firmware/target/arm/sandisk/power-c200_e200.c @@ -22,7 +22,7 @@ #include #include "system.h" #include "cpu.h" -#include "i2c-pp.h" +#include "ascodec.h" #include "tuner.h" #include "as3514.h" #include "power.h" @@ -36,9 +36,9 @@ void power_off(void) char byte; /* Send shutdown command to PMU */ - byte = i2c_readbyte(AS3514_I2C_ADDR, AS3514_SYSTEM); + byte = ascodec_read(AS3514_SYSTEM); byte &= ~0x1; - pp_i2c_send(AS3514_I2C_ADDR, AS3514_SYSTEM, byte); + ascodec_write(AS3514_SYSTEM, byte); /* Stop interrupts on both cores */ disable_interrupt(IRQ_FIQ_STATUS); diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index d5e33f1b6b..fa0ff5ea04 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c @@ -46,7 +46,7 @@ /* TODO: Move target-specific stuff somewhere else (serial number reading) */ #ifdef HAVE_AS3514 -#include "i2c-pp.h" +#include "ascodec.h" #include "as3514.h" #endif @@ -274,7 +274,7 @@ static void set_serial_descriptor(void) short* p = &usb_string_iSerial.wString[1]; int i; - i2c_readbytes(AS3514_I2C_ADDR, AS3514_UID_0, 0x10, serial); + ascodec_readbytes(AS3514_UID_0, 0x10, serial); for (i = 0; i < 16; i++) { *p++ = hex[(serial[i] >> 4) & 0xF]; *p++ = hex[(serial[i] >> 0) & 0xF]; -- cgit v1.2.3