From a924df8d6ddfa4372ce6b49c312e1da1ffceb2ad Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sun, 31 Mar 2013 21:57:53 +0200 Subject: rk27xx: implement radio support Change-Id: I59d3905e9b2a3df8aa235e424c7a6e0eff6d73e9 Reviewed-on: http://gerrit.rockbox.org/427 Reviewed-by: Marcin Bukat Tested-by: Marcin Bukat --- firmware/SOURCES | 2 + firmware/drivers/audio/rk27xx_codec.c | 18 ++++++-- firmware/export/config/rk27generic.h | 4 ++ firmware/target/arm/rk27xx/audio-rk27xx.c | 52 ++++++++++++++++++++++ .../rk27xx/rk27generic/fmradio-i2c-rk27generic.c | 39 ++++++++++++++++ .../arm/rk27xx/rk27generic/power-rk27generic.c | 6 +++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 firmware/target/arm/rk27xx/audio-rk27xx.c create mode 100644 firmware/target/arm/rk27xx/rk27generic/fmradio-i2c-rk27generic.c (limited to 'firmware') diff --git a/firmware/SOURCES b/firmware/SOURCES index 8ba45af533..92b2f5f87b 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -1509,6 +1509,7 @@ target/arm/s5l8702/ipod6g/piezo-ipod6g.c #endif #if CONFIG_CPU == RK27XX +target/arm/rk27xx/audio-rk27xx.c target/arm/rk27xx/kernel-rk27xx.c target/arm/rk27xx/system-rk27xx.c target/arm/rk27xx/backlight-rk27xx.c @@ -1532,6 +1533,7 @@ target/arm/rk27xx/rk27generic/button-rk27generic.c target/arm/rk27xx/rk27generic/powermgmt-rk27generic.c target/arm/rk27xx/rk27generic/power-rk27generic.c target/arm/rk27xx/rk27generic/lcd-rk27generic.c +target/arm/rk27xx/rk27generic/fmradio-i2c-rk27generic.c #endif #if CONFIG_CPU == JZ4732 diff --git a/firmware/drivers/audio/rk27xx_codec.c b/firmware/drivers/audio/rk27xx_codec.c index cfb98a9227..462565e8aa 100644 --- a/firmware/drivers/audio/rk27xx_codec.c +++ b/firmware/drivers/audio/rk27xx_codec.c @@ -55,12 +55,14 @@ static int codec_read(uint8_t reg, uint8_t *val) } #endif +static uint8_t cr1_sel = DACSEL; + static void audiohw_mute(bool mute) { if (mute) - codec_write(CR1, SB_MICBIAS|DAC_MUTE|DACSEL); + codec_write(CR1, SB_MICBIAS|DAC_MUTE|cr1_sel); else - codec_write(CR1, SB_MICBIAS|DACSEL); + codec_write(CR1, SB_MICBIAS|cr1_sel); } /* public functions */ @@ -109,7 +111,7 @@ void audiohw_postinit(void) udelay(1000); /* power up output stage */ - codec_write(PMR1, SB_ADC|SB_IN1|SB_IN2|SB_MIC|SB_IND); + codec_write(PMR1, SB_ADC|SB_MIC|SB_IND); sleep(HZ/10); GPIO_PDDR |= (1<<7); /* PD7 high */ @@ -159,5 +161,15 @@ void audiohw_set_master_vol(int vol_l, int vol_r) codec_write(CGR9, vol_r); codec_write(CGR8, vol_l); + codec_write(CGR5, vol_r); + codec_write(CGR4, vol_l); + codec_write(CGR3, vol_r); + codec_write(CGR2, vol_l); } } + +void audiohw_set_monitor(bool enable) +{ + cr1_sel = enable ? BYPASS1|BYPASS2 : DACSEL; + codec_write(CR1, cr1_sel|SB_MICBIAS); +} diff --git a/firmware/export/config/rk27generic.h b/firmware/export/config/rk27generic.h index 10fbd451e4..9a4326358f 100644 --- a/firmware/export/config/rk27generic.h +++ b/firmware/export/config/rk27generic.h @@ -13,6 +13,7 @@ /* Define bitmask of input sources - recordable bitmask can be defined explicitly if different */ /* #define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_FM) */ +#define INPUT_SRC_CAPS SRC_CAP_FMRADIO /* define the bitmask of hardware sample rates */ #define HW_SAMPR_CAPS (SAMPR_CAP_44 | SAMPR_CAP_22 | SAMPR_CAP_11 \ @@ -106,6 +107,9 @@ /* Define the type of audio codec */ #define HAVE_RK27XX_CODEC +#define CONFIG_TUNER TEA5767 +#define CONFIG_TUNER_XTAL 32768 + /* #define HAVE_PCM_DMA_ADDRESS */ /* Define this for LCD backlight available */ diff --git a/firmware/target/arm/rk27xx/audio-rk27xx.c b/firmware/target/arm/rk27xx/audio-rk27xx.c new file mode 100644 index 0000000000..76be4a907a --- /dev/null +++ b/firmware/target/arm/rk27xx/audio-rk27xx.c @@ -0,0 +1,52 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2013 by Amaury Pouly + * + * 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 "system.h" +#include "audiohw.h" +#include "audio.h" + +static int input_source = AUDIO_SRC_PLAYBACK; +static unsigned input_flags = 0; +static int output_source = AUDIO_SRC_PLAYBACK; + +static void select_audio_path(void) +{ + if(input_source == AUDIO_SRC_PLAYBACK) + audiohw_set_monitor(false); + else + audiohw_set_monitor(true); +} + +void audio_input_mux(int source, unsigned flags) +{ + (void) source; + (void) flags; + input_source = source; + input_flags = flags; + select_audio_path(); +} + +void audio_set_output_source(int source) +{ + (void) source; + output_source = source; + select_audio_path(); +} diff --git a/firmware/target/arm/rk27xx/rk27generic/fmradio-i2c-rk27generic.c b/firmware/target/arm/rk27xx/rk27generic/fmradio-i2c-rk27generic.c new file mode 100644 index 0000000000..4ab171cd5a --- /dev/null +++ b/firmware/target/arm/rk27xx/rk27generic/fmradio-i2c-rk27generic.c @@ -0,0 +1,39 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2013 by Amaury Pouly + * + * 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 "system.h" +#include "fmradio_i2c.h" +#include "i2c-rk27xx.h" + +void fmradio_i2c_init(void) +{ +} + +int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) +{ + return i2c_write(address, -1, count, buf); +} + +int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) +{ + return i2c_read(address, -1, count, buf); +} diff --git a/firmware/target/arm/rk27xx/rk27generic/power-rk27generic.c b/firmware/target/arm/rk27xx/rk27generic/power-rk27generic.c index 68594d0f0e..d3feb41597 100644 --- a/firmware/target/arm/rk27xx/rk27generic/power-rk27generic.c +++ b/firmware/target/arm/rk27xx/rk27generic/power-rk27generic.c @@ -38,6 +38,12 @@ void power_init(void) GPIO_PCCON |= (1<<0); } +bool tuner_power(bool status) +{ + (void) status; + return true; +} + unsigned int power_input_status(void) { return (usb_detect() == USB_INSERTED) ? POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; -- cgit v1.2.3