imx233: factor adc accross targets

The old code allowed each target to specify its adc targets but this proved
useless since the target rely directly on imx233/lradc for input method and
generic adc is mostly used for battery and debug. Remove all target specific
files and provide a generic implemenation. The targets can still specify a
battery temperature channel in powermgmt-target.h

Change-Id: I68cf2e3e46379d174ac6d774ffb237bb15a19ae3
This commit is contained in:
Amaury Pouly 2013-11-19 19:04:03 +00:00
parent 287be81c16
commit c2c2274e0a
15 changed files with 62 additions and 377 deletions

View file

@ -1177,7 +1177,6 @@ target/arm/imx233/creative-zen/lcd-zenv.c
target/arm/imx233/creative-zen/button-zen.c target/arm/imx233/creative-zen/button-zen.c
target/arm/imx233/creative-zen/debug-zen.c target/arm/imx233/creative-zen/debug-zen.c
target/arm/imx233/creative-zen/power-zen.c target/arm/imx233/creative-zen/power-zen.c
target/arm/imx233/creative-zen/adc-zen.c
target/arm/imx233/creative-zen/powermgmt-zen.c target/arm/imx233/creative-zen/powermgmt-zen.c
target/arm/imx233/button-lradc-imx233.c target/arm/imx233/button-lradc-imx233.c
#endif #endif
@ -1189,7 +1188,6 @@ target/arm/imx233/creative-zenxfi2/lcd-zenxfi2.c
target/arm/imx233/creative-zenxfi2/button-zenxfi2.c target/arm/imx233/creative-zenxfi2/button-zenxfi2.c
target/arm/imx233/creative-zenxfi2/debug-zenxfi2.c target/arm/imx233/creative-zenxfi2/debug-zenxfi2.c
target/arm/imx233/creative-zenxfi2/power-zenxfi2.c target/arm/imx233/creative-zenxfi2/power-zenxfi2.c
target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c
target/arm/imx233/creative-zenxfi2/powermgmt-zenxfi2.c target/arm/imx233/creative-zenxfi2/powermgmt-zenxfi2.c
#endif #endif
@ -1201,7 +1199,6 @@ target/arm/imx233/creative-zenxfi3/lcd-zenxfi3.c
target/arm/imx233/creative-zenxfi3/button-zenxfi3.c target/arm/imx233/creative-zenxfi3/button-zenxfi3.c
target/arm/imx233/creative-zenxfi3/debug-zenxfi3.c target/arm/imx233/creative-zenxfi3/debug-zenxfi3.c
target/arm/imx233/creative-zenxfi3/power-zenxfi3.c target/arm/imx233/creative-zenxfi3/power-zenxfi3.c
target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c
target/arm/imx233/creative-zenxfi3/powermgmt-zenxfi3.c target/arm/imx233/creative-zenxfi3/powermgmt-zenxfi3.c
#endif #endif
@ -1212,7 +1209,6 @@ target/arm/imx233/sony-nwz/backlight-nwz.c
target/arm/imx233/sony-nwz/button-nwz.c target/arm/imx233/sony-nwz/button-nwz.c
target/arm/imx233/sony-nwz/debug-nwz.c target/arm/imx233/sony-nwz/debug-nwz.c
target/arm/imx233/sony-nwz/power-nwz.c target/arm/imx233/sony-nwz/power-nwz.c
target/arm/imx233/sony-nwz/adc-nwz.c
# if defined(SONY_NWZE360) # if defined(SONY_NWZE360)
target/arm/imx233/sony-nwz/lcd-nwze360.c target/arm/imx233/sony-nwz/lcd-nwze360.c
target/arm/imx233/sony-nwz/powermgmt-nwze360.c target/arm/imx233/sony-nwz/powermgmt-nwze360.c
@ -1437,7 +1433,6 @@ target/arm/imx233/sansa-fuzeplus/lcd-fuzeplus.c
target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c
target/arm/imx233/sansa-fuzeplus/debug-fuzeplus.c target/arm/imx233/sansa-fuzeplus/debug-fuzeplus.c
target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c
target/arm/imx233/sansa-fuzeplus/adc-fuzeplus.c
target/arm/imx233/sansa-fuzeplus/powermgmt-fuzeplus.c target/arm/imx233/sansa-fuzeplus/powermgmt-fuzeplus.c
#endif #endif

View file

@ -19,9 +19,46 @@
* *
****************************************************************************/ ****************************************************************************/
#include "adc-imx233.h" #include "adc-target.h"
#include "power-imx233.h" #include "power-imx233.h"
/* Virtual channels */
#define IMX233_ADC_BATTERY -1 /* Battery voltage (mV) */
#define IMX233_ADC_DIE_TEMP -2 /* Die temperature (°C) */
#define IMX233_ADC_VDDIO -3 /* VddIO voltage (mV) */
#if IMX233_SUBTARGET >= 3700
#define IMX233_ADC_VDD5V -4 /* Vdd5V voltage (mV) */
#endif
#ifdef IMX233_BATT_TEMP_SENSOR
#define IMX233_ADC_BATT_TEMP -5 /* Battery temperature (°C) */
#endif
static const char *imx233_adc_channel_name[NUM_ADC_CHANNELS] =
{
[ADC_BATTERY] = "Battery(raw)",
[ADC_DIE_TEMP] = "Die temperature(°C)",
[ADC_VDDIO] = "VddIO(mV)",
#if IMX233_SUBTARGET >= 3700
[ADC_VDD5V] = "Vdd5V(mV)",
#endif
#ifdef IMX233_BATT_TEMP_SENSOR
[ADC_BATT_TEMP] = "Battery temperature(raw)",
#endif
};
static int imx233_adc_mapping[NUM_ADC_CHANNELS] =
{
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
#if IMX233_SUBTARGET >= 3700
[ADC_VDD5V] = IMX233_ADC_VDD5V,
#endif
#ifdef IMX233_BATT_TEMP_SENSOR
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
#endif
};
void adc_init(void) void adc_init(void)
{ {
} }
@ -52,11 +89,11 @@ static short adc_read_virtual(int c)
return imx233_lradc_read_battery_voltage(); return imx233_lradc_read_battery_voltage();
case IMX233_ADC_VDDIO: case IMX233_ADC_VDDIO:
/* VddIO pin has a builtin 2:1 divide */ /* VddIO pin has a builtin 2:1 divide */
return adc_read_physical(LRADC_SRC_VDDIO, false); return adc_read_physical(LRADC_SRC_VDDIO, true) * 2;
#if IMX233_SUBTARGET >= 3700 #if IMX233_SUBTARGET >= 3700
case IMX233_ADC_VDD5V: case IMX233_ADC_VDD5V:
/* Vdd5V pin has a builtin 4:1 divide */ /* Vdd5V pin has a builtin 4:1 divide */
return adc_read_physical(LRADC_SRC_5V, false) * 2; return adc_read_physical(LRADC_SRC_5V, true) * 4;
#endif #endif
case IMX233_ADC_DIE_TEMP: case IMX233_ADC_DIE_TEMP:
{ {
@ -102,3 +139,8 @@ unsigned short adc_read(int channel)
else else
return adc_read_physical(c, true); return adc_read_physical(c, true);
} }
const char *adc_name(int channel)
{
return imx233_adc_channel_name[channel];
}

View file

@ -27,20 +27,21 @@
#include "powermgmt-target.h" #include "powermgmt-target.h"
#include "lradc-imx233.h" #include "lradc-imx233.h"
/* Virtual channels */ enum imx233_adc_channel_t
#define IMX233_ADC_BATTERY -1 /* Battery voltage (mV) */ {
#define IMX233_ADC_DIE_TEMP -2 /* Die temperature (°C) */ ADC_BATTERY, /* Battery voltage (mV) */
#define IMX233_ADC_VDDIO -3 /* VddIO voltage (mV) */ ADC_DIE_TEMP, /* Die temperature (°C) */
ADC_VDDIO, /* VDDIO (mV) */
#if IMX233_SUBTARGET >= 3700 #if IMX233_SUBTARGET >= 3700
#define IMX233_ADC_VDD5V -4 /* Vdd5V voltage (mV) */ ADC_VDD5V, /* VDD5V (mV) */
#endif #endif
#ifdef IMX233_BATT_TEMP_SENSOR #ifdef IMX233_BATT_TEMP_SENSOR
#define IMX233_ADC_BATT_TEMP -5 /* Battery temperature (°C) */ ADC_BATT_TEMP, /* Battery temperature (°C) */
#endif #endif
NUM_ADC_CHANNELS,
};
/* Channel mapping */ /* Return channel name */
extern int imx233_adc_mapping[]; const char *adc_name(int channel);
/* Channel names */
extern const char *imx233_adc_channel_name[];
#endif #endif

View file

@ -1,29 +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.
*
****************************************************************************/
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
#define NUM_ADC_CHANNELS 2
#define ADC_BATTERY 0
#define ADC_DIE_TEMP 1
#endif

View file

@ -1,34 +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 "adc-target.h"
#include "adc-imx233.h"
int imx233_adc_mapping[] =
{
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_BATTERY] = IMX233_ADC_BATTERY,
};
const char *imx233_adc_channel_name[] =
{
"Die temperature(°C)",
"Battery(raw)",
};

View file

@ -278,15 +278,15 @@ void lcd_init_device(void)
imx233_pinctrl_acquire(1, 8, "lcd_power"); imx233_pinctrl_acquire(1, 8, "lcd_power");
imx233_pinctrl_set_function(1, 8, PINCTRL_FUNCTION_GPIO); imx233_pinctrl_set_function(1, 8, PINCTRL_FUNCTION_GPIO);
imx233_pinctrl_enable_gpio(1, 8, true); imx233_pinctrl_enable_gpio(1, 8, true);
// power up
lcd_power(true);
// reset lcd // reset lcd
imx233_lcdif_reset_lcd(true); imx233_lcdif_reset_lcd(true);
mdelay(1); mdelay(10);
imx233_lcdif_reset_lcd(false); imx233_lcdif_reset_lcd(false);
mdelay(1); mdelay(10);
imx233_lcdif_reset_lcd(true); imx233_lcdif_reset_lcd(true);
mdelay(1); mdelay(10);
// power up
lcd_power(true);
// setup registers // setup registers
imx233_lcdif_enable_sync_signals(true); // we need frame signals during init imx233_lcdif_enable_sync_signals(true); // we need frame signals during init
lcd_power_seq(); lcd_power_seq();

View file

@ -1,32 +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.
*
****************************************************************************/
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
#define NUM_ADC_CHANNELS 5
#define ADC_BATTERY 0
#define ADC_DIE_TEMP 1
#define ADC_VDDIO 2
#define ADC_5V 3
#define ADC_BATT_TEMP 4
#endif

View file

@ -1,40 +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 "adc-target.h"
#include "adc-imx233.h"
int imx233_adc_mapping[] =
{
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
[ADC_5V] = IMX233_ADC_VDD5V,
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
};
const char *imx233_adc_channel_name[] =
{
"Battery(raw)",
"Die temperature(°C)",
"VddIO",
"Vdd5V",
"Battery temperature(raw)",
};

View file

@ -1,32 +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.
*
****************************************************************************/
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
#define NUM_ADC_CHANNELS 5
#define ADC_BATTERY 0
#define ADC_DIE_TEMP 1
#define ADC_VDDIO 2
#define ADC_5V 3
#define ADC_BATT_TEMP 4
#endif

View file

@ -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 "adc-target.h"
#include "adc-imx233.h"
int imx233_adc_mapping[] =
{
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
[ADC_5V] = IMX233_ADC_VDD5V,
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
};
const char *imx233_adc_channel_name[] =
{
"Battery(raw)",
"Die temperature(°C)",
"VddIO",
"Vdd5V",
"Battery temperature(raw)",
};

View file

@ -24,7 +24,6 @@
#include "lcd.h" #include "lcd.h"
#include "font.h" #include "font.h"
#include "adc.h" #include "adc.h"
#include "adc-imx233.h"
#include "power-imx233.h" #include "power-imx233.h"
#include "clkctrl-imx233.h" #include "clkctrl-imx233.h"
#include "powermgmt-imx233.h" #include "powermgmt-imx233.h"
@ -269,8 +268,7 @@ bool dbg_hw_info_lradc(void)
lcd_putsf(0, 0, "Battery(mV) %d", _battery_voltage()); lcd_putsf(0, 0, "Battery(mV) %d", _battery_voltage());
for(unsigned i = 0; i < NUM_ADC_CHANNELS; i++) for(unsigned i = 0; i < NUM_ADC_CHANNELS; i++)
{ {
lcd_putsf(0, i + 1, "%s %d", imx233_adc_channel_name[i], lcd_putsf(0, i + 1, "%s %d", adc_name(i), adc_read(i));
adc_read(i));
} }
lcd_update(); lcd_update();

View file

@ -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 "adc-target.h"
#include "adc-imx233.h"
int imx233_adc_mapping[] =
{
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
[ADC_5V] = IMX233_ADC_VDD5V,
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
[ADC_CH2] = LRADC_SRC(2),
};
const char *imx233_adc_channel_name[] =
{
"Battery(raw)",
"Die temperature(°C)",
"VddIO(mV)",
"Vdd5V(mV)",
"Battery temperature(raw)",
"Channel 2",
};

View file

@ -1,33 +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.
*
****************************************************************************/
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
#define NUM_ADC_CHANNELS 6
#define ADC_BATTERY 0
#define ADC_DIE_TEMP 1
#define ADC_VDDIO 2
#define ADC_5V 3
#define ADC_BATT_TEMP 4
#define ADC_CH2 5
#endif

View file

@ -1,38 +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 "adc-target.h"
#include "adc-imx233.h"
int imx233_adc_mapping[] =
{
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
[ADC_5V] = IMX233_ADC_VDD5V,
};
const char *imx233_adc_channel_name[] =
{
"Battery(raw)",
"Die temperature(°C)",
"VddIO",
"Vdd5V",
};

View file

@ -1,31 +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.
*
****************************************************************************/
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
#define NUM_ADC_CHANNELS 4
#define ADC_BATTERY 0
#define ADC_DIE_TEMP 1
#define ADC_VDDIO 2
#define ADC_5V 3
#endif