FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / arm / adc-pp5020.c
blob851e90724605f7c33949c9dc676166cb396deb5f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
22 #include "cpu.h"
23 #include "system.h"
24 #include "kernel.h"
25 #include "thread.h"
26 #include "adc.h"
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)
43 return 0;
45 /* Start conversion */
46 ADC_ADDR |= 0x80000000;
48 /* Wait for conversion to complete */
49 while((ADC_STATUS & (0x40<<8*channel))==0);
51 /* Stop conversion */
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;
69 #endif
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)
86 adc_counter = 0;
87 adc_scan(0);
88 adc_scan(1);
89 adc_scan(2);
90 adc_scan(3);
94 /* Figured out from how the OF does things */
95 void adc_init(void)
97 #if defined(PHILIPS_HDD1630)
98 ADC_INIT = 0;
99 #else
100 ADC_INIT |= 1;
101 ADC_INIT |= 0x40000000;
102 #endif
103 udelay(100);
105 /* Reset ADC */
106 DEV_RS2 |= 0x20;
107 udelay(100);
109 DEV_RS2 &=~ 0x20;
110 udelay(100);
112 /* Enable ADC */
113 DEV_EN2 |= 0x20;
114 udelay(100);
116 ADC_CLOCK_SRC |= 0x3;
117 udelay(100);
119 ADC_ADDR = 0;
120 ADC_ADDR |= 0x40;
122 #if !defined(PHILIPS_HDD1630)
123 ADC_ADDR |= 0x20000000;
124 udelay(100);
126 ADC_INIT;
127 ADC_INIT = 0;
128 udelay(100);
129 #endif
131 ADC_STATUS = 0;
133 /* Enable channel 0 (battery) */
134 DEV_INIT1 &=~0x3;
135 ADC_ADDR |= 0x1000000;
136 ADC_STATUS |= 0x20;
138 /* Enable channel 1 (unknown) */
139 DEV_INIT1 &=~30;
140 ADC_ADDR |= 0x2000000;
141 ADC_STATUS |= 0x2000;
143 #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || \
144 defined(MROBE_100)
145 /* Enable channel 2 (H10:remote) */
146 DEV_INIT1 &=~0x300;
147 DEV_INIT1 |= 0x100;
148 ADC_ADDR |= 0x4000000;
149 ADC_STATUS |= 0x200000;
151 /* Enable channel 3 (H10:scroll pad) */
152 DEV_INIT1 &=~0x3000;
153 DEV_INIT1 |= 0x1000;
154 ADC_ADDR |= 0x8000000;
155 ADC_STATUS |= 0x20000000;
156 #endif
158 #if defined(PHILIPS_HDD1630)
159 ADC_INIT |= 0x80000000;
160 udelay(100);
161 ADC_INIT = 0;
162 #endif
164 /* Force a scan of all channels to get initial values */
165 adc_scan(0);
166 adc_scan(1);
167 adc_scan(2);
168 adc_scan(3);
170 tick_add_task(adc_tick);