From 1d1a17c0dbd0fdf2857c5d1636713247d28f1762 Mon Sep 17 00:00:00 2001 From: Barry Wardell Date: Tue, 16 Oct 2007 10:48:16 +0000 Subject: Improved H10 ADC driver. We now do things exactly as the OF does. This includes shifting the readings by 0x14 when PLL is enabled. Battery voltages and remote/scrollpad values adjusted accordingly. We also now wait for the ADC to indicate the conversion is complete before reading the data, so hopefully we will get more reliably steady readings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15141 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/iriver/h10/adc-h10.c | 90 +++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 26 deletions(-) (limited to 'firmware/target/arm/iriver/h10/adc-h10.c') diff --git a/firmware/target/arm/iriver/h10/adc-h10.c b/firmware/target/arm/iriver/h10/adc-h10.c index df9b16359b..f63e8b8013 100644 --- a/firmware/target/arm/iriver/h10/adc-h10.c +++ b/firmware/target/arm/iriver/h10/adc-h10.c @@ -25,29 +25,21 @@ static unsigned short adcdata[NUM_ADC_CHANNELS]; -/* Scan ADC so that adcdata[channel] gets updated */ +/* Scan ADC so that adcdata[channel] gets updated. */ unsigned short adc_scan(int channel) { unsigned int adc_data_1; unsigned int adc_data_2; - /* Initialise */ - ADC_ADDR=0x130; - ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is - off, 0x40 if the channel is on */ + /* Start conversion */ + ADC_ADDR |= 0x80000000; - /* Enable Channel */ - ADC_ADDR |= (0x1000000< 0x400) + adcdata[channel] = 0x400; + } + return adcdata[channel]; } @@ -79,25 +78,64 @@ static void adc_tick(void) } } +/* Figured out from how the OF does things */ void adc_init(void) { - /* Enable ADC */ - ADC_ENABLE_ADDR |= ADC_ENABLE; + ADC_INIT |= 1; + ADC_INIT |= 0x40000000; + udelay(100); + + /* Reset ADC */ + DEV_RS2 |= 0x20; + udelay(100); + + DEV_RS2 &=~ 0x20; + udelay(100); - /* Initialise */ - ADC_INIT=0; + /* Enable ADC */ + DEV_EN2 |= 0x20; + udelay(100); + + ADC_CLOCK_SRC |= 0x3; + udelay(100); + + ADC_ADDR |= 0x40; + ADC_ADDR |= 0x20000000; + udelay(100); + + ADC_INIT; + ADC_INIT = 0; + udelay(100); + + ADC_STATUS = 0; + + /* Enable channel 0 (battery) */ + DEV_INIT1 &=~0x3; + ADC_ADDR |= 0x1000000; + ADC_STATUS |= 0x20; + + /* Enable channel 1 (unknown, temperature?) */ + DEV_INIT1 &=~30; + ADC_ADDR |= 0x2000000; + ADC_STATUS |= 0x2000; + + /* Enable channel 2 (remote) */ + DEV_INIT1 &=~0x300; + DEV_INIT1 |= 0x100; + ADC_ADDR |= 0x4000000; + ADC_STATUS |= 0x200000; + + /* Enable channel 3 (scroll pad) */ + DEV_INIT1 &=~0x3000; + DEV_INIT1 |= 0x1000; + ADC_ADDR |= 0x8000000; + ADC_STATUS |= 0x20000000; /* Force a scan of all channels to get initial values */ adc_scan(ADC_BATTERY); adc_scan(ADC_UNKNOWN_1); adc_scan(ADC_REMOTE); adc_scan(ADC_SCROLLPAD); - - /* FIXME: The ADC sometimes reads 0 for the battery - voltage for the first few seconds. It would be better to fix this by - figuring out how to use the ADC properly. Until then, work around the - problem by waiting until it reads a proper value*/ - while(adc_scan(ADC_UNREG_POWER)==0); tick_add_task(adc_tick); } -- cgit v1.2.3