sd-as3525.c: disable wide bus, it corrupts writes
[kugel-rb.git] / firmware / target / arm / adc-pp5020.c
blob2d75a7e25f73dbd5fc52e7f2bbddd027e2562a77
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 #if defined(PBELL_VIBE500)
35 #define ADC_UNK (*(volatile unsigned long*)(0x7000002c))
36 #endif
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)
47 return 0;
49 /* Start conversion */
50 ADC_ADDR |= 0x80000000;
52 /* Wait for conversion to complete */
53 while((ADC_STATUS & (0x40<<8*channel))==0);
55 /* Stop conversion */
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;
73 #endif
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)
90 adc_counter = 0;
91 adc_scan(0);
92 adc_scan(1);
93 adc_scan(2);
94 adc_scan(3);
98 /* Figured out from how the OF does things */
99 void adc_init(void)
101 #if defined(PBELL_VIBE500)
102 ADC_UNK |= 0x1000;
103 #endif
105 #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
106 ADC_INIT = 0;
107 #else
108 ADC_INIT |= 1;
109 ADC_INIT |= 0x40000000;
110 #endif
111 udelay(100);
113 /* Reset ADC */
114 DEV_RS2 |= 0x20;
115 udelay(100);
117 DEV_RS2 &=~ 0x20;
118 udelay(100);
120 /* Enable ADC */
121 DEV_EN2 |= 0x20;
122 udelay(100);
124 ADC_CLOCK_SRC |= 0x3;
125 udelay(100);
127 ADC_ADDR = 0;
128 ADC_ADDR |= 0x40;
130 #if !(defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330))
131 ADC_ADDR |= 0x20000000;
132 udelay(100);
134 ADC_INIT;
135 ADC_INIT = 0;
136 udelay(100);
137 #endif
139 ADC_STATUS = 0;
141 /* Enable channel 0 (battery) */
142 DEV_INIT1 &=~0x3;
143 ADC_ADDR |= 0x1000000;
144 ADC_STATUS |= 0x20;
146 /* Enable channel 1 (unknown) */
147 DEV_INIT1 &=~30;
148 ADC_ADDR |= 0x2000000;
149 ADC_STATUS |= 0x2000;
151 #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || \
152 defined(MROBE_100)
153 /* Enable channel 2 (H10:remote) */
154 DEV_INIT1 &=~0x300;
155 DEV_INIT1 |= 0x100;
156 ADC_ADDR |= 0x4000000;
157 ADC_STATUS |= 0x200000;
159 /* Enable channel 3 (H10:scroll pad) */
160 DEV_INIT1 &=~0x3000;
161 DEV_INIT1 |= 0x1000;
162 ADC_ADDR |= 0x8000000;
163 ADC_STATUS |= 0x20000000;
164 #endif
166 #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
167 ADC_INIT |= 0x80000000;
168 udelay(100);
169 ADC_INIT = 0;
170 #endif
172 /* Force a scan of all channels to get initial values */
173 adc_scan(0);
174 adc_scan(1);
175 adc_scan(2);
176 adc_scan(3);
178 tick_add_task(adc_tick);