1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Barry Wardell
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
28 #define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00))
29 #define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04))
30 #define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20))
31 #define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24))
32 #define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c))
34 static unsigned short adcdata
[NUM_ADC_CHANNELS
];
36 /* Scan ADC so that adcdata[channel] gets updated. */
37 unsigned short adc_scan(int channel
)
39 unsigned int adc_data_1
;
40 unsigned int adc_data_2
;
42 if (channel
>= NUM_ADC_CHANNELS
)
45 /* Start conversion */
46 ADC_ADDR
|= 0x80000000;
48 /* Wait for conversion to complete */
49 while((ADC_STATUS
& (0x40<<8*channel
))==0);
52 ADC_ADDR
&=~ 0x80000000;
54 /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
55 For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
56 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
57 adc_data_1
= ((ADC_DATA_1
>> (8*channel
)) & 0xff);
58 adc_data_2
= ((ADC_DATA_2
>> (8*channel
+6)) & 0x3);
60 adcdata
[channel
] = (adc_data_1
<<2 | adc_data_2
);
62 #if !defined(PHILIPS_HDD1630)
63 /* ADC values read low if PLL is enabled */
64 if(PLL_CONTROL
& 0x80000000){
65 adcdata
[channel
] += 0x14;
66 if(adcdata
[channel
] > 0x400)
67 adcdata
[channel
] = 0x400;
71 return adcdata
[channel
];
74 /* Read 10-bit channel data */
75 unsigned short adc_read(int channel
)
77 return adcdata
[channel
];
80 static int adc_counter
;
82 static void adc_tick(void)
84 if(++adc_counter
== HZ
)
94 /* Figured out from how the OF does things */
97 #if defined(PHILIPS_HDD1630)
101 ADC_INIT
|= 0x40000000;
116 ADC_CLOCK_SRC
|= 0x3;
122 #if !defined(PHILIPS_HDD1630)
123 ADC_ADDR
|= 0x20000000;
133 /* Enable channel 0 (battery) */
135 ADC_ADDR
|= 0x1000000;
138 /* Enable channel 1 (unknown) */
140 ADC_ADDR
|= 0x2000000;
141 ADC_STATUS
|= 0x2000;
143 #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || \
145 /* Enable channel 2 (H10:remote) */
148 ADC_ADDR
|= 0x4000000;
149 ADC_STATUS
|= 0x200000;
151 /* Enable channel 3 (H10:scroll pad) */
154 ADC_ADDR
|= 0x8000000;
155 ADC_STATUS
|= 0x20000000;
158 #if defined(PHILIPS_HDD1630)
159 ADC_INIT
|= 0x80000000;
164 /* Force a scan of all channels to get initial values */
170 tick_add_task(adc_tick
);