imx233: split lradc channel setup into source and sampling parameters

Change-Id: I1be43fec9622cb78fc5737e5ed8d7fda17baf576
This commit is contained in:
Amaury Pouly 2014-02-19 12:56:22 +01:00
parent 961498d58a
commit fd0a86a572
4 changed files with 23 additions and 10 deletions

View file

@ -80,7 +80,8 @@ static short adc_read_physical(int src, bool div2)
{
int virt = imx233_lradc_acquire_channel(src, TIMEOUT_BLOCK);
// divide by two for wider ranger
imx233_lradc_setup_channel(virt, div2, false, 0, src);
imx233_lradc_setup_source(virt, div2, src);
imx233_lradc_setup_sampling(virt, false, 0);
int val = adc_read_physical_ex(virt);
imx233_lradc_release_channel(virt);
return val;

View file

@ -66,10 +66,8 @@ void imx233_lradc_set_channel_irq_callback(int channel, lradc_irq_fn_t cb)
imx233_icoll_enable_interrupt(INT_SRC_LRADC_CHx(channel), cb != NULL);
}
void imx233_lradc_setup_channel(int channel, bool div2, bool acc, int nr_samples, int src)
void imx233_lradc_setup_source(int channel, bool div2, int src)
{
HW_LRADC_CHn_CLR(channel) = BM_OR2(LRADC_CHn, NUM_SAMPLES, ACCUMULATE);
HW_LRADC_CHn_SET(channel) = BF_OR2(LRADC_CHn, NUM_SAMPLES(nr_samples), ACCUMULATE(acc));
if(div2)
BF_SETV(LRADC_CTRL2, DIVIDE_BY_TWO, 1 << channel);
else
@ -93,6 +91,12 @@ void imx233_lradc_setup_channel(int channel, bool div2, bool acc, int nr_samples
#endif
}
void imx233_lradc_setup_sampling(int channel, bool acc, int nr_samples)
{
HW_LRADC_CHn_CLR(channel) = BM_OR2(LRADC_CHn, NUM_SAMPLES, ACCUMULATE);
HW_LRADC_CHn_SET(channel) = BF_OR2(LRADC_CHn, NUM_SAMPLES(nr_samples), ACCUMULATE(acc));
}
void imx233_lradc_setup_delay(int dchan, int trigger_lradc, int trigger_delays,
int loop_count, int delay)
{
@ -202,8 +206,10 @@ void imx233_lradc_reserve_delay(int channel)
#if IMX233_SUBTARGET >= 3700
int imx233_lradc_sense_die_temperature(int nmos_chan, int pmos_chan)
{
imx233_lradc_setup_channel(nmos_chan, false, false, 0, LRADC_SRC_NMOS_THIN);
imx233_lradc_setup_channel(pmos_chan, false, false, 0, LRADC_SRC_PMOS_THIN);
imx233_lradc_setup_source(nmos_chan, false, LRADC_SRC_NMOS_THIN);
imx233_lradc_setup_sampling(nmos_chan, false, 0);
imx233_lradc_setup_source(pmos_chan, false, LRADC_SRC_PMOS_THIN);
imx233_lradc_setup_sampling(pmos_chan, false, 0);
// mux sensors
BF_CLR(LRADC_CTRL2, TEMPSENSE_PWD);
imx233_lradc_clear_channel(nmos_chan);
@ -247,7 +253,8 @@ int imx233_lradc_sense_ext_temperature(int chan, int sensor)
{
#define EXT_TEMP_ACC_COUNT 5
/* setup channel */
imx233_lradc_setup_channel(chan, false, false, 0, sensor);
imx233_lradc_setup_source(chan, false, sensor);
imx233_lradc_setup_sampling(chan, false, 0);
/* set current source to 300µA */
imx233_lradc_set_temp_isrc(sensor, BV_LRADC_CTRL2_TEMP_ISRC0__300);
/* read value and accumulate */
@ -350,7 +357,8 @@ void imx233_lradc_init(void)
battery_chan = 7;
imx233_lradc_reserve_channel(battery_chan);
/* setup them for the simplest use: no accumulation, no division*/
imx233_lradc_setup_channel(battery_chan, false, false, 0, LRADC_SRC_BATTERY);
imx233_lradc_setup_source(battery_chan, false, LRADC_SRC_BATTERY);
imx233_lradc_setup_sampling(battery_chan, false, 0);
/* setup delay channel for battery for automatic reading and scaling */
battery_delay_chan = 0;
imx233_lradc_reserve_delay(battery_delay_chan);

View file

@ -42,6 +42,7 @@
#define LRADC_NUM_CHANNELS 8
#define LRADC_NUM_DELAYS 4
#define LRADC_NUM_SOURCES 16
#define LRADC_SRC(x) (x)
#define LRADC_SRC_XPLUS LRADC_SRC(2)
@ -71,7 +72,9 @@
typedef void (*lradc_irq_fn_t)(int chan);
void imx233_lradc_init(void);
void imx233_lradc_setup_channel(int channel, bool div2, bool acc, int nr_samples, int src);
void imx233_lradc_setup_source(int channel, bool div2, int src);
/* variant of the above only for accumulation changes */
void imx233_lradc_setup_sampling(int channel, bool acc, int nr_samples);
void imx233_lradc_setup_delay(int dchan, int trigger_lradc, int trigger_delays,
int loop_count, int delay);
void imx233_lradc_clear_channel_irq(int channel);

View file

@ -115,7 +115,8 @@ static void kick_measure(bool pull_x, bool pull_y, bool detect, int src)
imx233_lradc_enable_touch_detect_irq(false);
imx233_lradc_enable_channel_irq(touch_chan, true);
/* measure channel, no accumulation */
imx233_lradc_setup_channel(touch_chan, false, true, NR_SAMPLES - 1, src);
imx233_lradc_setup_source(touch_chan, false, src);
imx233_lradc_setup_sampling(touch_chan, true, NR_SAMPLES - 1);
imx233_lradc_clear_channel(touch_chan);
/* use a delay */
imx233_lradc_setup_delay(touch_delay, 1 << touch_chan, 1 << touch_delay,