summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iriver/h300/adc-h300.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iriver/h300/adc-h300.c')
-rw-r--r--firmware/target/coldfire/iriver/h300/adc-h300.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/h300/adc-h300.c b/firmware/target/coldfire/iriver/h300/adc-h300.c
new file mode 100644
index 0000000000..31702eaef1
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/adc-h300.c
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "cpu.h"
21#include "system.h"
22#include "kernel.h"
23#include "thread.h"
24#include "adc.h"
25#include "pcf50606.h"
26
27static unsigned char adcdata[NUM_ADC_CHANNELS];
28
29static int adcc2_parms[] =
30{
31 [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */
32 [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */
33 [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */
34 [ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* ADCIN1, resistive divider */
35};
36
37unsigned short adc_scan(int channel)
38{
39 int level = set_irq_level(HIGHEST_IRQ_LEVEL);
40 unsigned char data;
41
42 pcf50606_write(0x2f, adcc2_parms[channel]);
43 data = pcf50606_read(0x30);
44
45 adcdata[channel] = data;
46
47 set_irq_level(level);
48 return data;
49}
50
51
52unsigned short adc_read(int channel)
53{
54 return adcdata[channel];
55}
56
57static int adc_counter;
58
59static void adc_tick(void)
60{
61 if(++adc_counter == HZ)
62 {
63 adc_counter = 0;
64 adc_scan(ADC_BATTERY);
65 adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote
66 detection feels stable. */
67 }
68}
69
70void adc_init(void)
71{
72 or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS
73 GPIO21: Data In (to the ADC)
74 GPIO22: CLK
75 GPIO31: Data Out (from the ADC) */
76 or_l(0x00600080, &GPIO_ENABLE);
77 or_l(0x80, &GPIO_OUT); /* CS high */
78 and_l(~0x00400000, &GPIO_OUT); /* CLK low */
79
80 adc_scan(ADC_BATTERY);
81
82 tick_add_task(adc_tick);
83}