summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c100
-rw-r--r--firmware/target/arm/ipod/1g2g/adc-target.h34
-rw-r--r--firmware/target/arm/ipod/adc-ipod-pcf.c (renamed from firmware/target/arm/ipod/adc-ipod.c)10
3 files changed, 134 insertions, 10 deletions
diff --git a/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c b/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c
new file mode 100644
index 0000000000..759b6fb592
--- /dev/null
+++ b/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c
@@ -0,0 +1,100 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Jens Arnold
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
20#include "config.h"
21#include "cpu.h"
22#include "hwcompat.h"
23#include "kernel.h"
24
25static struct mutex adc_mutex NOCACHEBSS_ATTR;
26
27unsigned short adc_scan(int channel)
28{
29 int i, j;
30 unsigned short data = 0;
31 unsigned pval;
32
33 (void)channel; /* there is only one */
34 spinlock_lock(&adc_mutex);
35
36 if ((IPOD_HW_REVISION >> 16) == 1)
37 {
38 pval = GPIOB_OUTPUT_VAL;
39 GPIOB_OUTPUT_VAL = pval | 0x04; /* B2 -> high */
40 for (i = 32; i > 0; --i);
41
42 GPIOB_OUTPUT_VAL = pval; /* B2 -> low */
43 for (i = 200; i > 0; --i);
44
45 for (j = 0; j < 8; j++)
46 {
47 GPIOB_OUTPUT_VAL = pval | 0x02; /* B1 -> high */
48 for (i = 8; i > 0; --i);
49
50 data = (data << 1) | ((GPIOB_INPUT_VAL & 0x08) >> 3);
51
52 GPIOB_OUTPUT_VAL = pval; /* B1 -> low */
53 for (i = 320; i > 0; --i);
54 }
55 }
56 else if ((IPOD_HW_REVISION >> 16) == 2)
57 {
58 pval = GPIOB_OUTPUT_VAL;
59 GPIOB_OUTPUT_VAL = pval | 0x0a; /* B1, B3 -> high */
60 while (!(GPIOB_INPUT_VAL & 0x04)); /* wait for B2 == 1 */
61
62 GPIOB_OUTPUT_VAL = pval; /* B1, B3 -> low */
63 while (GPIOB_INPUT_VAL & 0x04); /* wait for B2 == 0 */
64
65 for (j = 0; j < 8; j++)
66 {
67 GPIOB_OUTPUT_VAL = pval | 0x02; /* B1 -> high */
68 while (!(GPIOB_INPUT_VAL & 0x04)); /* wait for B2 == 1 */
69
70 data = (data << 1) | ((GPIOB_INPUT_VAL & 0x10) >> 4);
71
72 GPIOB_OUTPUT_VAL = pval; /* B1 -> low */
73 while (GPIOB_INPUT_VAL & 0x04); /* wait for B2 == 0 */
74 }
75 }
76 spinlock_unlock(&adc_mutex);
77 return data;
78}
79
80void adc_init(void)
81{
82 spinlock_init(&adc_mutex);
83
84 GPIOB_ENABLE |= 0x1e; /* enable B1..B4 */
85
86 if ((IPOD_HW_REVISION >> 16) == 1)
87 {
88 GPIOB_OUTPUT_EN = (GPIOB_OUTPUT_EN & ~0x08) | 0x16;
89 /* B1, B2, B4 -> output, B3 -> input */
90 GPIOB_OUTPUT_VAL = (GPIOB_OUTPUT_VAL & ~0x06) | 0x10;
91 /* B1, B2 -> low, B4 -> high */
92 }
93 else if ((IPOD_HW_REVISION >> 16) == 2)
94 {
95 GPIOB_OUTPUT_EN = (GPIOB_OUTPUT_EN & ~0x14) | 0x0a;
96 /* B1, B3 -> output, B2, B4 -> input */
97 GPIOB_OUTPUT_VAL &= ~0x0a; /* B1, B3 -> low */
98 while (GPIOB_INPUT_VAL & 0x04); /* wait for B2 == 0 */
99 }
100}
diff --git a/firmware/target/arm/ipod/1g2g/adc-target.h b/firmware/target/arm/ipod/1g2g/adc-target.h
new file mode 100644
index 0000000000..b3f6cd6303
--- /dev/null
+++ b/firmware/target/arm/ipod/1g2g/adc-target.h
@@ -0,0 +1,34 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Jens Arnold
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
20#ifndef _ADC_TARGET_H_
21#define _ADC_TARGET_H_
22
23#define NUM_ADC_CHANNELS 1
24
25#define ADC_BATTERY 0
26#define ADC_UNREG_POWER ADC_BATTERY
27
28/* Force a scan now */
29unsigned short adc_scan(int channel);
30static inline unsigned short adc_read(int channel)
31{
32 return adc_scan(channel);
33}
34#endif
diff --git a/firmware/target/arm/ipod/adc-ipod.c b/firmware/target/arm/ipod/adc-ipod-pcf.c
index 39463af30b..bc2524de5d 100644
--- a/firmware/target/arm/ipod/adc-ipod.c
+++ b/firmware/target/arm/ipod/adc-ipod-pcf.c
@@ -36,7 +36,6 @@ static struct adc_struct adcdata[NUM_ADC_CHANNELS] IDATA_ATTR;
36 36
37static unsigned short _adc_read(struct adc_struct *adc) 37static unsigned short _adc_read(struct adc_struct *adc)
38{ 38{
39#ifndef IPOD_1G2G
40 if (adc->timeout < current_tick) { 39 if (adc->timeout < current_tick) {
41 unsigned char data[2]; 40 unsigned char data[2];
42 unsigned short value; 41 unsigned short value;
@@ -56,7 +55,6 @@ static unsigned short _adc_read(struct adc_struct *adc)
56 adc->data = value; 55 adc->data = value;
57 return value; 56 return value;
58 } else 57 } else
59#endif
60 { 58 {
61 return adc->data; 59 return adc->data;
62 } 60 }
@@ -66,19 +64,11 @@ static unsigned short _adc_read(struct adc_struct *adc)
66unsigned short adc_scan(int channel) { 64unsigned short adc_scan(int channel) {
67 struct adc_struct *adc = &adcdata[channel]; 65 struct adc_struct *adc = &adcdata[channel];
68 adc->timeout = 0; 66 adc->timeout = 0;
69#ifdef IPOD_1G2G
70 if (channel == ADC_UNREG_POWER)
71 return 681; /* FIXME fake 4.00V */
72#endif
73 return _adc_read(adc); 67 return _adc_read(adc);
74} 68}
75 69
76/* Retrieve the ADC value, only does a scan periodically */ 70/* Retrieve the ADC value, only does a scan periodically */
77unsigned short adc_read(int channel) { 71unsigned short adc_read(int channel) {
78#ifdef IPOD_1G2G
79 if (channel == ADC_UNREG_POWER)
80 return 681; /* FIXME fake 4.00V */
81#endif
82 return _adc_read(&adcdata[channel]); 72 return _adc_read(&adcdata[channel]);
83} 73}
84 74