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
This commit is contained in:
Dave Chapman 2008-10-31 00:16:42 +00:00
parent 324816f019
commit 42f77d4eb0
15 changed files with 196 additions and 61 deletions

View file

@ -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;

View file

@ -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)
{
}

View file

@ -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 */

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -22,7 +22,7 @@
#include <stdbool.h>
#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);