Create an udacodec interface (similar to ascodec and wmcoded) and adapt/implement it for the iriver h1xx/h3xx and the meizus.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21546 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Bertrik Sikken 2009-06-28 17:43:04 +00:00
parent c3f9ab46de
commit 7df759c951
7 changed files with 183 additions and 39 deletions

View file

@ -689,6 +689,7 @@ target/coldfire/iriver/h300/powermgmt-h300.c
target/coldfire/iriver/h300/usb-h300.c
#ifndef BOOTLOADER
target/coldfire/iriver/audio-iriver.c
target/coldfire/iriver/udacodec-iriver.c
#endif
#endif /* SIMULATOR */
#endif /* IRIVER_H300_SERIES */
@ -711,6 +712,7 @@ target/coldfire/iriver/h100/power-h100.c
target/coldfire/iriver/h100/powermgmt-h100.c
#ifndef BOOTLOADER
target/coldfire/iriver/audio-iriver.c
target/coldfire/iriver/udacodec-iriver.c
target/coldfire/iriver/h100/spdif-h100.c
#endif
target/coldfire/iriver/h100/usb-h100.c
@ -1250,6 +1252,7 @@ target/arm/s5l8700/meizu-m3/lcd-m3.c
drivers/qt1106.c
#ifndef SIMULATOR
#ifndef BOOTLOADER
target/arm/s5l8700/udacodec-meizu.c
#endif /* BOOTLOADER */
#endif /* SIMULATOR */
#endif /* MEIZU_M3 */

View file

@ -18,15 +18,16 @@
* KIND, either express or implied.
*
****************************************************************************/
#include <string.h>
#include "config.h"
#include "logf.h"
#include "system.h"
#include "string.h"
#include "audio.h"
#include "debug.h"
#include "udacodec.h"
#include "i2c-coldfire.h"
#include "audiohw.h"
#include "pcf50606.h"
const struct sound_settings_info audiohw_settings[] = {
[SOUND_VOLUME] = {"dB", 0, 1, -84, 0, -25},
@ -109,13 +110,7 @@ unsigned short uda1380_defaults[2*NUM_DEFAULT_REGS] =
/* Returns 0 if register was written or -1 if write failed */
static int uda1380_write_reg(unsigned char reg, unsigned short value)
{
unsigned char data[3];
data[0] = reg;
data[1] = value >> 8;
data[2] = value & 0xff;
if (i2c_write(I2C_IFACE_0, UDA1380_ADDR, data, 3) != 3)
if (udacodec_write(reg, value) < 0)
{
DEBUGF("uda1380 error reg=0x%x", reg);
return -1;
@ -193,23 +188,6 @@ static int audiohw_set_regs(void)
return 0;
}
static void reset(void)
{
#ifdef IRIVER_H300_SERIES
int mask = disable_irq_save();
pcf50606_write(0x3b, 0x00); /* GPOOD2 high Z */
pcf50606_write(0x3b, 0x07); /* GPOOD2 low */
restore_irq(mask);
#else
/* RESET signal */
or_l(1<<29, &GPIO_OUT);
or_l(1<<29, &GPIO_ENABLE);
or_l(1<<29, &GPIO_FUNCTION);
sleep(HZ/100);
and_l(~(1<<29), &GPIO_OUT);
#endif
}
/**
* Sets frequency settings for DAC and ADC relative to MCLK
*
@ -268,7 +246,7 @@ void audiohw_init(void)
recgain_mic = 0;
recgain_line = 0;
reset();
udacodec_reset();
if (audiohw_set_regs() == -1)
{
@ -419,20 +397,13 @@ void audiohw_set_recvol(int left, int right, int type)
{
/* for this order we can combine both registers,
making the glitch even smaller */
unsigned char data[5];
unsigned short value_dec;
unsigned short value_pga;
value_dec = DEC_VOLL(left) | DEC_VOLR(right);
value_pga = (uda1380_regs[REG_PGA] & ~PGA_GAIN_MASK)
| PGA_GAINL(left_ag) | PGA_GAINR(right_ag);
data[0] = REG_DEC_VOL;
data[1] = value_dec >> 8;
data[2] = value_dec & 0xff;
data[3] = value_pga >> 8;
data[4] = value_pga & 0xff;
if (i2c_write(I2C_IFACE_0, UDA1380_ADDR, data, 5) != 5)
if (udacodec_write2(REG_DEC_VOL, value_dec, value_pga) < 0)
{
DEBUGF("uda1380 error reg=combi rec gain");
}

View file

@ -85,8 +85,8 @@
#define CONFIG_LCD LCD_MEIZUM6
/* Define this if you have the WM8975 audio codec */
#define HAVE_WM8751 //FIXME
/* Define the type of audio codec */
#define HAVE_UDA1380
/* Define this for LCD backlight available */
#define HAVE_BACKLIGHT

View file

@ -0,0 +1,31 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 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.
*
****************************************************************************/
/* perform a hardware reset of the codec */
void udacodec_reset(void);
/* write a single register */
int udacodec_write(unsigned char reg, unsigned short value);
/* write two consecutive registers */
int udacodec_write2(unsigned char reg,
unsigned short value1, unsigned short value2);

View file

@ -615,12 +615,13 @@ int sound_val2phys(int setting, int value)
switch(setting)
{
#ifdef HAVE_RECORDING
case SOUND_LEFT_GAIN:
case SOUND_RIGHT_GAIN:
case SOUND_MIC_GAIN:
result = value * 5; /* (1/2) * 10 */
break;
#endif
default:
result = value;
break;

View file

@ -0,0 +1,62 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 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.
*
****************************************************************************/
#include "config.h"
#include "kernel.h"
#include "s5l8700.h"
#include "i2c-s5l8700.h"
#include "uda1380.h"
#include "udacodec.h"
void udacodec_reset(void)
{
/* Reset codec using GPIO P5.0 */
PCON5 = (PCON5 & ~0xF) | 1;
PDAT5 |= (1 << 0);
sleep(HZ/100);
/* Set codec reset pin inactive */
PDAT5 &= ~(1 << 0);
}
int udacodec_write(unsigned char reg, unsigned short value)
{
unsigned char data[2];
data[0] = value >> 8;
data[1] = value & 0xFF;
return i2c_write(UDA1380_ADDR, reg, 2, data);
}
int udacodec_write2(unsigned char reg,
unsigned short value1, unsigned short value2)
{
unsigned char data[4];
data[0] = value1 >> 8;
data[1] = value1 & 0xFF;
data[2] = value2 >> 8;
data[3] = value2 & 0xFF;
return i2c_write(UDA1380_ADDR, reg, 4, data);
}

View file

@ -0,0 +1,76 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 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.
*
****************************************************************************/
#include "config.h"
#include "kernel.h"
#include "i2c-coldfire.h"
#include "pcf50606.h"
#include "uda1380.h"
#include "udacodec.h"
void udacodec_reset(void)
{
#ifdef IRIVER_H300_SERIES
int mask = disable_irq_save();
pcf50606_write(0x3b, 0x00); /* GPOOD2 high Z */
pcf50606_write(0x3b, 0x07); /* GPOOD2 low */
restore_irq(mask);
#else
/* RESET signal */
or_l(1<<29, &GPIO_OUT);
or_l(1<<29, &GPIO_ENABLE);
or_l(1<<29, &GPIO_FUNCTION);
sleep(HZ/100);
and_l(~(1<<29), &GPIO_OUT);
#endif
}
int udacodec_write(unsigned char reg, unsigned short value)
{
unsigned char data[3];
data[0] = reg;
data[1] = value >> 8;
data[2] = value & 0xff;
if (i2c_write(I2C_IFACE_0, UDA1380_ADDR, data, 3) != 3) {
return -1;
}
return 0;
}
int udacodec_write2(unsigned char reg,
unsigned short value1, unsigned short value2)
{
unsigned char data[5];
data[0] = reg;
data[1] = value1 >> 8;
data[2] = value1 & 0xFF;
data[3] = value2 >> 8;
data[4] = value2 & 0xFF;
if (i2c_write(I2C_IFACE_0, UDA1380_ADDR, data, 5) != 5) {
return -1;
}
return 0;
}