From 446f352abda2dbc9de90c35a02100ed5e9aad77c Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 19 Nov 2013 20:39:10 +0000 Subject: imx233: factor fmradio i2c and tuner power code Choices are limited for those: i2c is either generic software or imx233 hardware and power is either none or with a gpio. So factor ever possible combination in a single common file and use fmradio-target.h to supply the required parameters. This will remove a bunch of duplicate code. Change-Id: If12faeb2e371631cd39cc18a4c1d859812007934 --- .../arm/imx233/creative-zen/fmradio-i2c-zen.c | 40 ----- .../arm/imx233/creative-zen/fmradio-target.h | 36 +++++ .../target/arm/imx233/creative-zen/power-zen.c | 38 ----- .../imx233/creative-zenxfi2/fmradio-i2c-zenxfi2.c | 40 ----- .../arm/imx233/creative-zenxfi2/fmradio-target.h | 28 ++++ .../arm/imx233/creative-zenxfi2/power-zenxfi2.c | 42 ------ .../imx233/creative-zenxfi3/fmradio-i2c-zenxfi3.c | 40 ----- .../arm/imx233/creative-zenxfi3/fmradio-target.h | 28 ++++ .../arm/imx233/creative-zenxfi3/power-zenxfi3.c | 42 ------ firmware/target/arm/imx233/fmradio-imx233.c | 162 +++++++++++++++++++++ firmware/target/arm/imx233/fmradio-imx233.h | 64 ++++++++ .../imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c | 76 +--------- .../arm/imx233/sansa-fuzeplus/fmradio-target.h | 35 +++++ .../arm/imx233/sansa-fuzeplus/power-fuzeplus.c | 53 ------- .../target/arm/imx233/sony-nwz/fmradio-i2c-nwz.c | 40 ----- .../target/arm/imx233/sony-nwz/fmradio-target.h | 28 ++++ firmware/target/arm/imx233/sony-nwz/power-nwz.c | 42 ------ 17 files changed, 382 insertions(+), 452 deletions(-) delete mode 100644 firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c create mode 100644 firmware/target/arm/imx233/creative-zen/fmradio-target.h delete mode 100644 firmware/target/arm/imx233/creative-zenxfi2/fmradio-i2c-zenxfi2.c create mode 100644 firmware/target/arm/imx233/creative-zenxfi2/fmradio-target.h delete mode 100644 firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c delete mode 100644 firmware/target/arm/imx233/creative-zenxfi3/fmradio-i2c-zenxfi3.c create mode 100644 firmware/target/arm/imx233/creative-zenxfi3/fmradio-target.h delete mode 100644 firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c create mode 100644 firmware/target/arm/imx233/fmradio-imx233.c create mode 100644 firmware/target/arm/imx233/fmradio-imx233.h create mode 100644 firmware/target/arm/imx233/sansa-fuzeplus/fmradio-target.h delete mode 100644 firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c delete mode 100644 firmware/target/arm/imx233/sony-nwz/fmradio-i2c-nwz.c create mode 100644 firmware/target/arm/imx233/sony-nwz/fmradio-target.h delete mode 100644 firmware/target/arm/imx233/sony-nwz/power-nwz.c (limited to 'firmware/target') diff --git a/firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c b/firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c deleted file mode 100644 index a1377ce1f2..0000000000 --- a/firmware/target/arm/imx233/creative-zen/fmradio-i2c-zen.c +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * 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 "pinctrl-imx233.h" -#include "i2c.h" - -void fmradio_i2c_init(void) -{ -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - return i2c_write(address, buf, count); -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - return i2c_read(address, buf, count); -} diff --git a/firmware/target/arm/imx233/creative-zen/fmradio-target.h b/firmware/target/arm/imx233/creative-zen/fmradio-target.h new file mode 100644 index 0000000000..c2b75b3ed4 --- /dev/null +++ b/firmware/target/arm/imx233/creative-zen/fmradio-target.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#ifndef _FMRADIO_TARGET_H_ +#define _FMRADIO_TARGET_H_ + +#define IMX233_FMRADIO_I2C FMI_HW + +#ifdef CREATIVE_ZENMOZAIC +#define IMX233_FMRADIO_POWER FMP_GPIO +#define FMP_GPIO_BANK 2 +#define FMP_GPIO_PIN 15 +#define FMP_GPIO_DELAY (HZ / 5) +#else +#define IMX233_FMRADIO_POWER FMP_NONE +#endif + +#endif /* _FMRADIO_TARGET_H_ */ + \ No newline at end of file diff --git a/firmware/target/arm/imx233/creative-zen/power-zen.c b/firmware/target/arm/imx233/creative-zen/power-zen.c index c1ad5989c0..15da6ab201 100644 --- a/firmware/target/arm/imx233/creative-zen/power-zen.c +++ b/firmware/target/arm/imx233/creative-zen/power-zen.c @@ -21,44 +21,6 @@ #include "system.h" #include "power.h" -#include "tuner.h" -#include "fmradio_i2c.h" -#include "pinctrl-imx233.h" -#include "power-imx233.h" - -static bool tuner_enable = false; -static bool initialised = false; - -static void init(void) -{ -#ifdef CREATIVE_ZENMOZAIC - /* CE is B2P15 (active high) */ - imx233_pinctrl_acquire(2, 15, "tuner power"); - imx233_pinctrl_set_function(2, 15, PINCTRL_FUNCTION_GPIO); - imx233_pinctrl_enable_gpio(2, 15, true); -#endif - initialised = true; -} - -bool tuner_power(bool enable) -{ - if(!initialised) - init(); - if(tuner_enable != enable) - { -#ifdef CREATIVE_ZENMOZAIC - imx233_pinctrl_set_gpio(2, 15, enable); - sleep(HZ / 5); -#endif - tuner_enable = enable; - } - return tuner_enable; -} - -bool tuner_powered(void) -{ - return tuner_enable; -} void ide_power_enable(bool on) { diff --git a/firmware/target/arm/imx233/creative-zenxfi2/fmradio-i2c-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/fmradio-i2c-zenxfi2.c deleted file mode 100644 index 58ac8e6a08..0000000000 --- a/firmware/target/arm/imx233/creative-zenxfi2/fmradio-i2c-zenxfi2.c +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2012 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 "pinctrl-imx233.h" -#include "i2c.h" - -void fmradio_i2c_init(void) -{ -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - return i2c_write(address, buf, count); -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - return i2c_read(address, buf, count); -} diff --git a/firmware/target/arm/imx233/creative-zenxfi2/fmradio-target.h b/firmware/target/arm/imx233/creative-zenxfi2/fmradio-target.h new file mode 100644 index 0000000000..e6869dc2a5 --- /dev/null +++ b/firmware/target/arm/imx233/creative-zenxfi2/fmradio-target.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#ifndef _FMRADIO_TARGET_H_ +#define _FMRADIO_TARGET_H_ + +#define IMX233_FMRADIO_I2C FMI_HW + +#define IMX233_FMRADIO_POWER FMP_NONE + +#endif /* _FMRADIO_TARGET_H_ */ diff --git a/firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c deleted file mode 100644 index 180b7f9d4c..0000000000 --- a/firmware/target/arm/imx233/creative-zenxfi2/power-zenxfi2.c +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2011 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 "system.h" -#include "power.h" -#include "tuner.h" -#include "fmradio_i2c.h" -#include "pinctrl-imx233.h" - -static bool tuner_enable = false; - -bool tuner_power(bool enable) -{ - if(enable != tuner_enable) - { - tuner_enable = enable; - } - return tuner_enable; -} - -bool tuner_powered(void) -{ - return tuner_enable; -} diff --git a/firmware/target/arm/imx233/creative-zenxfi3/fmradio-i2c-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/fmradio-i2c-zenxfi3.c deleted file mode 100644 index 58ac8e6a08..0000000000 --- a/firmware/target/arm/imx233/creative-zenxfi3/fmradio-i2c-zenxfi3.c +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2012 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 "pinctrl-imx233.h" -#include "i2c.h" - -void fmradio_i2c_init(void) -{ -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - return i2c_write(address, buf, count); -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - return i2c_read(address, buf, count); -} diff --git a/firmware/target/arm/imx233/creative-zenxfi3/fmradio-target.h b/firmware/target/arm/imx233/creative-zenxfi3/fmradio-target.h new file mode 100644 index 0000000000..e6869dc2a5 --- /dev/null +++ b/firmware/target/arm/imx233/creative-zenxfi3/fmradio-target.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#ifndef _FMRADIO_TARGET_H_ +#define _FMRADIO_TARGET_H_ + +#define IMX233_FMRADIO_I2C FMI_HW + +#define IMX233_FMRADIO_POWER FMP_NONE + +#endif /* _FMRADIO_TARGET_H_ */ diff --git a/firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c deleted file mode 100644 index 26f2159cec..0000000000 --- a/firmware/target/arm/imx233/creative-zenxfi3/power-zenxfi3.c +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2012 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 "system.h" -#include "power.h" -#include "tuner.h" -#include "fmradio_i2c.h" -#include "pinctrl-imx233.h" - -static bool tuner_enable = false; - -bool tuner_power(bool enable) -{ - if(enable != tuner_enable) - { - tuner_enable = enable; - } - return tuner_enable; -} - -bool tuner_powered(void) -{ - return tuner_enable; -} diff --git a/firmware/target/arm/imx233/fmradio-imx233.c b/firmware/target/arm/imx233/fmradio-imx233.c new file mode 100644 index 0000000000..28ac4a4893 --- /dev/null +++ b/firmware/target/arm/imx233/fmradio-imx233.c @@ -0,0 +1,162 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "fmradio-imx233.h" +#include "fmradio-target.h" +#include "pinctrl-imx233.h" +#include "i2c.h" +#include "generic_i2c.h" + +#ifndef IMX233_FMRADIO_I2C +#error You must define IMX233_FMRADIO_I2C in fmradio-target.h +#endif + +#ifndef IMX233_FMRADIO_POWER +#error You must define IMX233_FMRADIO_POWER in fmradio-target.h +#endif + +/** Hardware I2C */ +#if IMX233_FMRADIO_I2C == FMI_HW +void fmradio_i2c_init(void) +{ +} + +int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) +{ + return i2c_write(address, buf, count); +} + +int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) +{ + return i2c_read(address, buf, count); +} +/** Software I2C */ +#elif IMX233_FMRADIO_I2C == FMI_SW +#if !defined(FMI_SW_SDA_BANK) || !defined(FMI_SW_SDA_PIN) || \ + !defined(FMI_SW_SCL_BANK) || !defined(FMI_SW_SCL_PIN) +#error You must define FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, FMI_SW_SCL_BANK and FMI_SW_SCL_PIN +#endif +static int fmradio_i2c_bus = -1; + +static void i2c_scl_dir(bool out) +{ + imx233_pinctrl_enable_gpio(FMI_SW_SCL_BANK, FMI_SW_SCL_PIN, out); +} + +static void i2c_sda_dir(bool out) +{ + imx233_pinctrl_enable_gpio(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, out); +} + +static void i2c_scl_out(bool high) +{ + imx233_pinctrl_set_gpio(FMI_SW_SCL_BANK, FMI_SW_SCL_PIN, high); +} + +static void i2c_sda_out(bool high) +{ + imx233_pinctrl_set_gpio(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, high); +} + +static bool i2c_scl_in(void) +{ + return imx233_pinctrl_get_gpio(FMI_SW_SCL_BANK, FMI_SW_SCL_PIN); +} + +static bool i2c_sda_in(void) +{ + return imx233_pinctrl_get_gpio(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN); +} + +static void i2c_delay(int d) +{ + udelay(d); +} + +struct i2c_interface fmradio_i2c = +{ + .scl_dir = i2c_scl_dir, + .sda_dir = i2c_sda_dir, + .scl_out = i2c_scl_out, + .sda_out = i2c_sda_out, + .scl_in = i2c_scl_in, + .sda_in = i2c_sda_in, + .delay = i2c_delay, + .delay_hd_sta = 4, + .delay_hd_dat = 5, + .delay_su_dat = 1, + .delay_su_sto = 4, + .delay_su_sta = 5, + .delay_thigh = 4 +}; + +void fmradio_i2c_init(void) +{ + imx233_pinctrl_acquire(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, "fmradio_i2c_sda"); + imx233_pinctrl_acquire(FMI_SW_SCL_BANK, FMI_SW_SCL_BANK, "fmradio_i2c_scl"); + imx233_pinctrl_set_function(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, PINCTRL_FUNCTION_GPIO); + imx233_pinctrl_set_function(FMI_SW_SCL_BANK, FMI_SW_SCL_BANK, PINCTRL_FUNCTION_GPIO); + fmradio_i2c_bus = i2c_add_node(&fmradio_i2c); +} + +int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) +{ + return i2c_write_data(fmradio_i2c_bus, address, -1, buf, count); +} + +int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) +{ + return i2c_read_data(fmradio_i2c_bus, address, -1, buf, count); +} +#else +#error Invalid value for IMX233_FMRADIO_I2C +#endif + +static bool tuner_enable = false; + +bool tuner_power(bool enable) +{ + if(enable != tuner_enable) + { + tuner_enable = enable; +#if IMX233_FMRADIO_POWER == FMP_GPIO + static bool init = false; + if(!init) + { + /* CE is B0P29 (active high) */ + imx233_pinctrl_acquire(FMP_GPIO_BANK, FMP_GPIO_PIN, "tuner_power"); + imx233_pinctrl_set_function(FMP_GPIO_BANK, FMP_GPIO_PIN, PINCTRL_FUNCTION_GPIO); + imx233_pinctrl_enable_gpio(FMP_GPIO_BANK, FMP_GPIO_PIN, true); + } + imx233_pinctrl_set_gpio(FMP_GPIO_BANK, FMP_GPIO_PIN, enable); + /* power up delay */ + sleep(FMP_GPIO_DELAY); +#elif IMX233_FMRADIO_POWER == FMP_NONE +#else +#error Invalid value for IMX233_FMRADIO_POWER +#endif + } + return tuner_enable; +} + +bool tuner_powered(void) +{ + return tuner_enable; +} diff --git a/firmware/target/arm/imx233/fmradio-imx233.h b/firmware/target/arm/imx233/fmradio-imx233.h new file mode 100644 index 0000000000..d53336dd40 --- /dev/null +++ b/firmware/target/arm/imx233/fmradio-imx233.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#ifndef __fmradio_imx233__ +#define __fmradio_imx233__ + +#include "config.h" +#include "tuner.h" +#include "fmradio_i2c.h" +#include "tuner.h" + +/** This driver implements fmradio i2c and tuner power in a generic way. It + * currently provides two possible implementation of i2c: + * - hardware using i2c-imx233 driver + * - software using generic-i2c driver + * And it provides tuner power by toggling an optional GPIO. + * It can be tweaked using the following defines + * and variables: + * - IMX233_FMRADIO_I2C + * - IMX233_FMRADIO_POWER + * + * The available values of IMX233_FMRADIO_I2C are: + * - FMI_HW: use hardware i2c driver + * - FMI_SW: use software i2c driver, needs additional defines: + * + FMI_SW_SDA_BANK: the SDA pin bank + * + FMI_SW_SDA_PIN: the SDA pin within bank + * + FMI_SW_SCL_BANK: the SCL pin bank + * + FMI_SW_SCL_PIN: the SCL pin bank + * The available values of IMX233_FMRADIO_POWER are: + * - FMP_NONE: tuner has no power control + * - FMP_GPIO: tuner power is controlled by a GPIO, needs additional defines: + * + FMP_GPIO_BANK: pin bank + * + FMP_GPIO_PIN: pin within bank + * + FMP_GPIO_INVERTED: define if inverted, default is active high + * + FMP_GPIO_DELAY: delay to power up/down (in ticks) + */ + +/* i2c method */ +#define FMI_HW 0 +#define FMI_SW 1 + +/* power method */ +#define FMP_NONE 0 +#define FMP_GPIO 1 + +#endif /* __fmradio_imx233__ */ + diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c index 15e061103f..2167bb6897 100644 --- a/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c +++ b/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c @@ -21,91 +21,17 @@ #include "config.h" #include "system.h" -#include "fmradio_i2c.h" #include "pinctrl-imx233.h" -#include "generic_i2c.h" #include "rds.h" #include "si4700.h" /** * Sansa Fuze+ fmradio uses the following pins: - * - B0P29 as CE apparently (active high) + * - B0P29 as CE (active high) * - B1P24 as SDA * - B1P22 as SCL * - B2P27 as STC/RDS */ -static int fmradio_i2c_bus = -1; - -static void i2c_scl_dir(bool out) -{ - imx233_pinctrl_enable_gpio(1, 22, out); -} - -static void i2c_sda_dir(bool out) -{ - imx233_pinctrl_enable_gpio(1, 24, out); -} - -static void i2c_scl_out(bool high) -{ - imx233_pinctrl_set_gpio(1, 22, high); -} - -static void i2c_sda_out(bool high) -{ - imx233_pinctrl_set_gpio(1, 24, high); -} - -static bool i2c_scl_in(void) -{ - return imx233_pinctrl_get_gpio(1, 22); -} - -static bool i2c_sda_in(void) -{ - return imx233_pinctrl_get_gpio(1, 24); -} - -static void i2c_delay(int d) -{ - udelay(d); -} - -struct i2c_interface fmradio_i2c = -{ - .scl_dir = i2c_scl_dir, - .sda_dir = i2c_sda_dir, - .scl_out = i2c_scl_out, - .sda_out = i2c_sda_out, - .scl_in = i2c_scl_in, - .sda_in = i2c_sda_in, - .delay = i2c_delay, - .delay_hd_sta = 4, - .delay_hd_dat = 5, - .delay_su_dat = 1, - .delay_su_sto = 4, - .delay_su_sta = 5, - .delay_thigh = 4 -}; - -void fmradio_i2c_init(void) -{ - imx233_pinctrl_acquire(1, 24, "fmradio i2c"); - imx233_pinctrl_acquire(1, 22, "fmradio i2c"); - imx233_pinctrl_set_function(1, 24, PINCTRL_FUNCTION_GPIO); - imx233_pinctrl_set_function(1, 22, PINCTRL_FUNCTION_GPIO); - fmradio_i2c_bus = i2c_add_node(&fmradio_i2c); -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - return i2c_write_data(fmradio_i2c_bus, address, -1, buf, count); -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - return i2c_read_data(fmradio_i2c_bus, address, -1, buf, count); -} #ifdef HAVE_RDS_CAP /* Low-level RDS Support */ diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-target.h b/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-target.h new file mode 100644 index 0000000000..4c3aa0b4e5 --- /dev/null +++ b/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-target.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#ifndef _FMRADIO_TARGET_H_ +#define _FMRADIO_TARGET_H_ + +#define IMX233_FMRADIO_I2C FMI_SW +#define FMI_SW_SDA_BANK 1 +#define FMI_SW_SDA_PIN 24 +#define FMI_SW_SCL_BANK 1 +#define FMI_SW_SCL_PIN 22 + +#define IMX233_FMRADIO_POWER FMP_GPIO +#define FMP_GPIO_BANK 0 +#define FMP_GPIO_PIN 29 +#define FMP_GPIO_DELAY (HZ / 10) + +#endif /* _FMRADIO_TARGET_H_ */ diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c deleted file mode 100644 index be087eb140..0000000000 --- a/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2011 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 "system.h" -#include "power.h" -#include "tuner.h" -#include "fmradio_i2c.h" -#include "pinctrl-imx233.h" -#include "power-imx233.h" - -static bool tuner_enable = false; - -bool tuner_power(bool enable) -{ - if(enable != tuner_enable) - { - /* CE is B0P29 (active high) */ - imx233_pinctrl_acquire(0, 29, "tuner power"); - imx233_pinctrl_set_function(0, 29, PINCTRL_FUNCTION_GPIO); - imx233_pinctrl_set_drive(0, 29, PINCTRL_DRIVE_4mA); - imx233_pinctrl_enable_gpio(0, 29, enable); - imx233_pinctrl_set_gpio(0, 29, enable); - tuner_enable = enable; - /* give time to power up, datasheet states than minimum timing time is - * around 100µs so 1 tick should do */ - sleep(1); - //imx233_power_set_dcdc_freq(enable, HW_POWER_MISC__FREQSEL__24MHz); - } - return tuner_enable; -} - -bool tuner_powered(void) -{ - return tuner_enable; -} diff --git a/firmware/target/arm/imx233/sony-nwz/fmradio-i2c-nwz.c b/firmware/target/arm/imx233/sony-nwz/fmradio-i2c-nwz.c deleted file mode 100644 index a1377ce1f2..0000000000 --- a/firmware/target/arm/imx233/sony-nwz/fmradio-i2c-nwz.c +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * 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 "pinctrl-imx233.h" -#include "i2c.h" - -void fmradio_i2c_init(void) -{ -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - return i2c_write(address, buf, count); -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - return i2c_read(address, buf, count); -} diff --git a/firmware/target/arm/imx233/sony-nwz/fmradio-target.h b/firmware/target/arm/imx233/sony-nwz/fmradio-target.h new file mode 100644 index 0000000000..e6869dc2a5 --- /dev/null +++ b/firmware/target/arm/imx233/sony-nwz/fmradio-target.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#ifndef _FMRADIO_TARGET_H_ +#define _FMRADIO_TARGET_H_ + +#define IMX233_FMRADIO_I2C FMI_HW + +#define IMX233_FMRADIO_POWER FMP_NONE + +#endif /* _FMRADIO_TARGET_H_ */ diff --git a/firmware/target/arm/imx233/sony-nwz/power-nwz.c b/firmware/target/arm/imx233/sony-nwz/power-nwz.c deleted file mode 100644 index 88644919ad..0000000000 --- a/firmware/target/arm/imx233/sony-nwz/power-nwz.c +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * 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 "system.h" -#include "power.h" -#include "tuner.h" -#include "fmradio_i2c.h" -#include "pinctrl-imx233.h" - -static bool tuner_enable = false; - -bool tuner_power(bool enable) -{ - if(enable != tuner_enable) - { - tuner_enable = enable; - } - return tuner_enable; -} - -bool tuner_powered(void) -{ - return tuner_enable; -} -- cgit v1.2.3