summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-12-12 11:01:07 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-12-12 11:01:07 +0000
commite69d567d9ebf7d236ff9663b11ac396cc71dcd75 (patch)
tree093b9d1bc979d79be1fcd0daac1d8daf8ac55503 /firmware/drivers
parent0ad97d13fc52b28de566dc0ddaf7245583eec2cc (diff)
Bring consistency to pcm implementation and samplerate handling. Less low-level duplication. A small test_sampr fix so it works on coldfire again.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19400 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/audio/as3514.c4
-rw-r--r--firmware/drivers/audio/tlv320.c16
-rw-r--r--firmware/drivers/audio/tsc2100.c6
-rw-r--r--firmware/drivers/audio/uda1380.c35
-rw-r--r--firmware/drivers/audio/wm8731.c39
-rw-r--r--firmware/drivers/audio/wm8751.c14
-rw-r--r--firmware/drivers/audio/wm8758.c6
-rw-r--r--firmware/drivers/audio/wm8975.c6
-rw-r--r--firmware/drivers/audio/wm8978.c24
-rw-r--r--firmware/drivers/audio/wm8985.c6
10 files changed, 84 insertions, 72 deletions
diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c
index 825cf51655..551a9df9b7 100644
--- a/firmware/drivers/audio/as3514.c
+++ b/firmware/drivers/audio/as3514.c
@@ -290,9 +290,9 @@ void audiohw_close(void)
sleep(HZ/4);
}
-void audiohw_set_sample_rate(int sampling_control)
+void audiohw_set_frequency(int fsel)
{
- (void)sampling_control;
+ (void)fsel;
}
#if defined(HAVE_RECORDING)
diff --git a/firmware/drivers/audio/tlv320.c b/firmware/drivers/audio/tlv320.c
index b2c5be8e61..c85627e683 100644
--- a/firmware/drivers/audio/tlv320.c
+++ b/firmware/drivers/audio/tlv320.c
@@ -152,21 +152,21 @@ void audiohw_postinit(void)
* 44100: 1 = MCLK MCLK SCLK, LRCK: Audio Clk / 4 (default)
* 88200: 2 = MCLK*2 MCLK SCLK, LRCK: Audio Clk / 2
*/
-void audiohw_set_frequency(unsigned fsel)
+void audiohw_set_frequency(int fsel)
{
/* All rates available for 11.2896MHz besides 8.021 */
- unsigned char values_src[3] =
+ static const unsigned char values_src[HW_NUM_FREQ] =
{
- /* Fs: */
- (0x8 << 2) | SRC_CLKIN, /* 11025, 22050 */
- (0x8 << 2), /* 44100 */
- (0xf << 2), /* 88200 */
+ [HW_FREQ_11] = (0x8 << 2) | SRC_CLKIN,
+ [HW_FREQ_22] = (0x8 << 2) | SRC_CLKIN,
+ [HW_FREQ_44] = (0x8 << 2),
+ [HW_FREQ_88] = (0xf << 2),
};
unsigned value_dap, value_pc;
- if (fsel >= ARRAYLEN(values_src))
- fsel = 1;
+ if ((unsigned)fsel >= HW_NUM_FREQ)
+ fsel = HW_FREQ_DEFAULT;
/* Temporarily turn off the DAC and ADC before switching sample
rates or they don't choose their filters correctly */
diff --git a/firmware/drivers/audio/tsc2100.c b/firmware/drivers/audio/tsc2100.c
index e0e2c53e69..11f30a8560 100644
--- a/firmware/drivers/audio/tsc2100.c
+++ b/firmware/drivers/audio/tsc2100.c
@@ -130,7 +130,7 @@ void audiohw_close(void)
}
-void audiohw_set_sample_rate(int sampling_control)
-{
- (void)sampling_control;
+void audiohw_set_frequency(int fsel)
+
+ (void)fsel;
}
diff --git a/firmware/drivers/audio/uda1380.c b/firmware/drivers/audio/uda1380.c
index a0e7ef56d8..efe02caca8 100644
--- a/firmware/drivers/audio/uda1380.c
+++ b/firmware/drivers/audio/uda1380.c
@@ -218,23 +218,38 @@ static void reset(void)
* 11025: 0 = 6.25 to 12.5 MCLK/2 SCLK, LRCK: Audio Clk / 16
* 22050: 1 = 12.5 to 25 MCLK/2 SCLK, LRCK: Audio Clk / 8
* 44100: 2 = 25 to 50 MCLK SCLK, LRCK: Audio Clk / 4 (default)
- * 88200: 3 = 50 to 100 MCLK SCLK, LRCK: Audio Clk / 2 <= TODO: Needs WSPLL
+ * 88200: 3 = 50 to 100 MCLK SCLK, LRCK: Audio Clk / 2
*/
-void audiohw_set_frequency(unsigned fsel)
+void audiohw_set_frequency(int fsel)
{
- static const unsigned short values_reg[4][2] =
+ static const unsigned short values_reg[HW_NUM_FREQ][2] =
{
- /* Fs: */
- { 0, WSPLL_625_125 | SYSCLK_512FS }, /* 11025 */
- { 0, WSPLL_125_25 | SYSCLK_256FS }, /* 22050 */
- { MIX_CTL_SEL_NS, WSPLL_25_50 | SYSCLK_256FS }, /* 44100 */
- { MIX_CTL_SEL_NS, WSPLL_50_100 | SYSCLK_256FS }, /* 88200 */
+ [HW_FREQ_11] = /* Fs: */
+ {
+ 0,
+ WSPLL_625_125 | SYSCLK_512FS
+ },
+ [HW_FREQ_22] =
+ {
+ 0,
+ WSPLL_125_25 | SYSCLK_256FS
+ },
+ [HW_FREQ_44] =
+ {
+ MIX_CTL_SEL_NS,
+ WSPLL_25_50 | SYSCLK_256FS
+ },
+ [HW_FREQ_88] =
+ {
+ MIX_CTL_SEL_NS,
+ WSPLL_50_100 | SYSCLK_256FS
+ },
};
const unsigned short *ent;
- if (fsel >= ARRAYLEN(values_reg))
- fsel = 2;
+ if ((unsigned)fsel >= HW_NUM_FREQ)
+ fsel = HW_FREQ_DEFAULT;
ent = values_reg[fsel];
diff --git a/firmware/drivers/audio/wm8731.c b/firmware/drivers/audio/wm8731.c
index c065de620a..2b74d718b0 100644
--- a/firmware/drivers/audio/wm8731.c
+++ b/firmware/drivers/audio/wm8731.c
@@ -224,35 +224,24 @@ void audiohw_close(void)
/* 2) Remove the WM codec supplies. */
}
-void audiohw_set_sample_rate(int sampling_control)
+void audiohw_set_frequency(int fsel)
{
- int rate;
-
- switch(sampling_control)
+ /* For 24MHz MCLK */
+ static const unsigned char srctrl_table[HW_NUM_FREQ] =
{
- case SAMPR_96:
- rate = WMC_USB24_96000HZ;
- break;
- case SAMPR_88:
- rate = WMC_USB24_88200HZ;
- break;
- case SAMPR_48:
- rate = WMC_USB24_48000HZ;
- break;
- default:
- case SAMPR_44:
- rate = WMC_USB24_44100HZ;
- break;
- case SAMPR_32:
- rate = WMC_USB24_32000HZ;
- break;
- case SAMPR_8:
- rate = WMC_USB24_8000HZ;
- break;
- }
+ [HW_FREQ_8] = WMC_USB24_8000HZ,
+ [HW_FREQ_32] = WMC_USB24_32000HZ,
+ [HW_FREQ_44] = WMC_USB24_44100HZ,
+ [HW_FREQ_48] = WMC_USB24_48000HZ,
+ [HW_FREQ_88] = WMC_USB24_88200HZ,
+ [HW_FREQ_96] = WMC_USB24_96000HZ,
+ };
+
+ if ((unsigned)fsel >= HW_NUM_FREQ)
+ fsel = HW_FREQ_DEFAULT;
codec_set_active(false);
- wmc_write(SAMPCTRL, rate);
+ wmc_write(SAMPCTRL, srctrl_table[fsel]);
codec_set_active(true);
}
diff --git a/firmware/drivers/audio/wm8751.c b/firmware/drivers/audio/wm8751.c
index 2e0eb06dbf..79c7396629 100644
--- a/firmware/drivers/audio/wm8751.c
+++ b/firmware/drivers/audio/wm8751.c
@@ -229,8 +229,18 @@ void audiohw_close(void)
wmcodec_write(PWRMGMT1, 0x0);
}
-/* Note: Disable output before calling this function */
void audiohw_set_frequency(int fsel)
{
- wmcodec_write(CLOCKING, fsel);
+ static const unsigned char srctrl_table[HW_NUM_FREQ] =
+ {
+ HW_HAVE_11_([HW_FREQ_11] = CODEC_SRCTRL_11025HZ,)
+ HW_HAVE_22_([HW_FREQ_22] = CODEC_SRCTRL_22050HZ,)
+ HW_HAVE_44_([HW_FREQ_44] = CODEC_SRCTRL_44100HZ,)
+ HW_HAVE_88_([HW_FREQ_88] = CODEC_SRCTRL_88200HZ,)
+ };
+
+ if ((unsigned)fsel >= HW_NUM_FREQ)
+ fsel = HW_FREQ_DEFAULT;
+
+ wmcodec_write(CLOCKING, srctrl_table[fsel]);
}
diff --git a/firmware/drivers/audio/wm8758.c b/firmware/drivers/audio/wm8758.c
index 8ebfbe8e26..defc415f98 100644
--- a/firmware/drivers/audio/wm8758.c
+++ b/firmware/drivers/audio/wm8758.c
@@ -107,7 +107,7 @@ void audiohw_preinit(void)
wmcodec_write(OUTCTRL, OUTCTRL_VROI);
wmcodec_write(CLKCTRL, CLKCTRL_MS); /* WM8758 is clock master */
- audiohw_set_sample_rate(WM8758_44100HZ);
+ audiohw_set_sample_rate(HW_FREQ_44);
wmcodec_write(LOUTMIX, LOUTMIX_DACL2LMIX);
wmcodec_write(ROUTMIX, ROUTMIX_DACR2RMIX);
@@ -170,10 +170,10 @@ void audiohw_close(void)
}
/* Note: Disable output before calling this function */
-void audiohw_set_sample_rate(int sampling_control)
+void audiohw_set_frequency(int fsel)
{
/**** We force 44.1KHz for now. ****/
- (void)sampling_control;
+ (void)fsel;
/* setup PLL for MHZ=11.2896 */
wmcodec_write(PLLN, PLLN_PLLPRESCALE | 0x7);
diff --git a/firmware/drivers/audio/wm8975.c b/firmware/drivers/audio/wm8975.c
index aa519e8819..f14890db74 100644
--- a/firmware/drivers/audio/wm8975.c
+++ b/firmware/drivers/audio/wm8975.c
@@ -145,7 +145,7 @@ void audiohw_preinit(void)
wm8975_write(DAPCTRL, wm8975_regs[DAPCTRL] );
- audiohw_set_sample_rate(WM8975_44100HZ);
+ wmcodec_write(SAMPCTRL, WM8975_44100HZ);
/* set the volume to -6dB */
wmcodec_write(LOUT1VOL, LOUT1VOL_LO1ZC | IPOD_PCM_LEVEL);
@@ -224,9 +224,9 @@ void audiohw_close(void)
}
/* Note: Disable output before calling this function */
-void audiohw_set_sample_rate(int sampling_control)
+void audiohw_set_frequency(int fsel)
{
- wmcodec_write(SAMPCTRL, sampling_control);
+ (void)fsel;
}
#ifdef HAVE_RECORDING
diff --git a/firmware/drivers/audio/wm8978.c b/firmware/drivers/audio/wm8978.c
index 6a7c974f43..d8bf05063f 100644
--- a/firmware/drivers/audio/wm8978.c
+++ b/firmware/drivers/audio/wm8978.c
@@ -363,9 +363,9 @@ void audiohw_mute(bool mute)
}
}
-void audiohw_set_frequency(int sampling_control)
+void audiohw_set_frequency(int fsel)
{
- /* For 16.9344MHz MCLK */
+ /* For 16.9344MHz MCLK, codec as master. */
static const struct
{
uint32_t plln : 8;
@@ -374,7 +374,7 @@ void audiohw_set_frequency(int sampling_control)
uint32_t pllk3 : 9;
unsigned char mclkdiv;
unsigned char filter;
- } sctrl_table[HW_NUM_FREQ] =
+ } srctrl_table[HW_NUM_FREQ] =
{
[HW_FREQ_8] = /* PLL = 65.536MHz */
{
@@ -450,16 +450,14 @@ void audiohw_set_frequency(int sampling_control)
unsigned int plln;
unsigned int mclkdiv;
- if ((unsigned)sampling_control >= ARRAYLEN(sctrl_table))
- sampling_control = HW_FREQ_DEFAULT;
-
+ if ((unsigned)fsel >= HW_NUM_FREQ)
+ fsel = HW_FREQ_DEFAULT;
/* Setup filters. */
- wmc_write(WMC_ADDITIONAL_CTRL,
- sctrl_table[sampling_control].filter);
+ wmc_write(WMC_ADDITIONAL_CTRL, srctrl_table[fsel].filter);
- plln = sctrl_table[sampling_control].plln;
- mclkdiv = sctrl_table[sampling_control].mclkdiv;
+ plln = srctrl_table[fsel].plln;
+ mclkdiv = srctrl_table[fsel].mclkdiv;
if (plln != 0)
{
@@ -467,9 +465,9 @@ void audiohw_set_frequency(int sampling_control)
/* Program PLL. */
wmc_write(WMC_PLL_N, plln);
- wmc_write(WMC_PLL_K1, sctrl_table[sampling_control].pllk1);
- wmc_write(WMC_PLL_K2, sctrl_table[sampling_control].pllk2);
- wmc_write(WMC_PLL_K3, sctrl_table[sampling_control].pllk3);
+ wmc_write(WMC_PLL_K1, srctrl_table[fsel].pllk1);
+ wmc_write(WMC_PLL_K2, srctrl_table[fsel].pllk2);
+ wmc_write(WMC_PLL_K3, srctrl_table[fsel].pllk3);
/* Turn on PLL. */
wmc_set(WMC_POWER_MANAGEMENT1, WMC_PLLEN);
diff --git a/firmware/drivers/audio/wm8985.c b/firmware/drivers/audio/wm8985.c
index 0467e3718a..f7b2e510ae 100644
--- a/firmware/drivers/audio/wm8985.c
+++ b/firmware/drivers/audio/wm8985.c
@@ -235,12 +235,12 @@ void audiohw_close(void)
}
/* Note: Disable output before calling this function */
-void audiohw_set_sample_rate(int sampling_control)
+void audiohw_set_sample_rate(int fsel)
{
/* Currently the WM8985 acts as slave to the SoC I2S controller, so no
setup is needed here. This seems to be in contrast to every other WM
driver in Rockbox, so this may need to change in the future. */
- (void)sampling_control;
+ (void)fsel;
}
#ifdef HAVE_RECORDING
@@ -261,7 +261,7 @@ void audiohw_enable_recording(bool source_mic)
/* The iPod can handle multiple frequencies, but fix at 44.1KHz
for now */
- audiohw_set_sample_rate(WM8985_44100HZ);
+ audiohw_set_frequency(HW_FREQ_DEFAULT);
wmcodec_write(INCTRL,0x44); /* Connect L2 and R2 inputs */