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 #if defined(PBELL_VIBE500)
35 #define ADC_UNK (*(volatile unsigned long*)(0x7000002c))
38 static unsigned short adcdata
[NUM_ADC_CHANNELS
];
40 /* Scan ADC so that adcdata[channel] gets updated. */
41 unsigned short adc_scan(int channel
)
43 unsigned int adc_data_1
;
44 unsigned int adc_data_2
;
46 if (channel
>= NUM_ADC_CHANNELS
)
49 /* Start conversion */
50 ADC_ADDR
|= 0x80000000;
52 /* Wait for conversion to complete */
53 while((ADC_STATUS
& (0x40<<8*channel
))==0);
56 ADC_ADDR
&=~ 0x80000000;
58 /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
59 For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
60 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
61 adc_data_1
= ((ADC_DATA_1
>> (8*channel
)) & 0xff);
62 adc_data_2
= ((ADC_DATA_2
>> (8*channel
+6)) & 0x3);
64 adcdata
[channel
] = (adc_data_1
<<2 | adc_data_2
);
66 #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330))
67 /* ADC values read low if PLL is enabled */
68 if(PLL_CONTROL
& 0x80000000){
69 adcdata
[channel
] += 0x14;
70 if(adcdata
[channel
] > 0x400)
71 adcdata
[channel
] = 0x400;
75 return adcdata
[channel
];
78 /* Read 10-bit channel data */
79 unsigned short adc_read(int channel
)
81 return adcdata
[channel
];
84 static int adc_counter
;
86 static void adc_tick(void)
88 if(++adc_counter
== HZ
)
98 /* Figured out from how the OF does things */
101 #if defined(PBELL_VIBE500)
105 #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
109 ADC_INIT
|= 0x40000000;
124 ADC_CLOCK_SRC
|= 0x3;
130 #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330))
131 ADC_ADDR
|= 0x20000000;
141 /* Enable channel 0 (battery) */
143 ADC_ADDR
|= 0x1000000;
146 /* Enable channel 1 (unknown) */
148 ADC_ADDR
|= 0x2000000;
149 ADC_STATUS
|= 0x2000;
151 #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || \
153 /* Enable channel 2 (H10:remote) */
156 ADC_ADDR
|= 0x4000000;
157 ADC_STATUS
|= 0x200000;
159 /* Enable channel 3 (H10:scroll pad) */
162 ADC_ADDR
|= 0x8000000;
163 ADC_STATUS
|= 0x20000000;
166 #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
167 ADC_INIT
|= 0x80000000;
172 /* Force a scan of all channels to get initial values */
178 tick_add_task(adc_tick
);