summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-07-30 20:12:03 +0000
committerJens Arnold <amiconn@rockbox.org>2007-07-30 20:12:03 +0000
commita4a3cd9d52b1969bf44315bdf4a229636ceb3f24 (patch)
treedf1bb0f4c47c3c91998682d27b03747e8fcb79fb
parentaaf92393b3b18dce26dde7a4f94a437cefdff684 (diff)
downloadrockbox-a4a3cd9d52b1969bf44315bdf4a229636ceb3f24.tar.gz
rockbox-a4a3cd9d52b1969bf44315bdf4a229636ceb3f24.zip
First version of a 1st/2nd gen ADC driver. 1st gen is untested yet.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14082 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES16
-rw-r--r--firmware/export/config-ipod1g2g.h8
-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
5 files changed, 146 insertions, 22 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index b73a82a15c..91cead088d 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -562,7 +562,7 @@ target/arm/wmcodec-pp.c
562target/arm/i2s-pp.c 562target/arm/i2s-pp.c
563target/arm/ata-as-arm.S 563target/arm/ata-as-arm.S
564target/arm/ata-pp5020.c 564target/arm/ata-pp5020.c
565target/arm/ipod/adc-ipod.c 565target/arm/ipod/adc-ipod-pcf.c
566target/arm/ipod/backlight-4g_color.c 566target/arm/ipod/backlight-4g_color.c
567target/arm/ipod/button-clickwheel.c 567target/arm/ipod/button-clickwheel.c
568target/arm/ipod/lcd-gray.c 568target/arm/ipod/lcd-gray.c
@@ -578,7 +578,7 @@ target/arm/ata-as-arm.S
578target/arm/ata-pp5020.c 578target/arm/ata-pp5020.c
579target/arm/wmcodec-pp.c 579target/arm/wmcodec-pp.c
580target/arm/i2s-pp.c 580target/arm/i2s-pp.c
581target/arm/ipod/adc-ipod.c 581target/arm/ipod/adc-ipod-pcf.c
582target/arm/ipod/backlight-4g_color.c 582target/arm/ipod/backlight-4g_color.c
583target/arm/ipod/button-clickwheel.c 583target/arm/ipod/button-clickwheel.c
584target/arm/ipod/lcd-color_nano.c 584target/arm/ipod/lcd-color_nano.c
@@ -594,7 +594,7 @@ target/arm/ata-as-arm.S
594target/arm/ata-pp5020.c 594target/arm/ata-pp5020.c
595target/arm/wmcodec-pp.c 595target/arm/wmcodec-pp.c
596target/arm/i2s-pp.c 596target/arm/i2s-pp.c
597target/arm/ipod/adc-ipod.c 597target/arm/ipod/adc-ipod-pcf.c
598target/arm/ipod/backlight-nano_video.c 598target/arm/ipod/backlight-nano_video.c
599target/arm/ipod/button-clickwheel.c 599target/arm/ipod/button-clickwheel.c
600target/arm/ipod/lcd-color_nano.c 600target/arm/ipod/lcd-color_nano.c
@@ -610,7 +610,7 @@ target/arm/ata-as-arm.S
610target/arm/ata-pp5020.c 610target/arm/ata-pp5020.c
611target/arm/wmcodec-pp.c 611target/arm/wmcodec-pp.c
612target/arm/i2s-pp.c 612target/arm/i2s-pp.c
613target/arm/ipod/adc-ipod.c 613target/arm/ipod/adc-ipod-pcf.c
614target/arm/ipod/backlight-nano_video.c 614target/arm/ipod/backlight-nano_video.c
615target/arm/ipod/button-clickwheel.c 615target/arm/ipod/button-clickwheel.c
616target/arm/ipod/power-ipod.c 616target/arm/ipod/power-ipod.c
@@ -625,7 +625,7 @@ drivers/pcf50605.c
625target/arm/ata-pp5002.c 625target/arm/ata-pp5002.c
626target/arm/wmcodec-pp.c 626target/arm/wmcodec-pp.c
627target/arm/i2s-pp.c 627target/arm/i2s-pp.c
628target/arm/ipod/adc-ipod.c 628target/arm/ipod/adc-ipod-pcf.c
629target/arm/ipod/3g/backlight-3g.c 629target/arm/ipod/3g/backlight-3g.c
630target/arm/ipod/button-1g-3g.c 630target/arm/ipod/button-1g-3g.c
631target/arm/ipod/lcd-gray.c 631target/arm/ipod/lcd-gray.c
@@ -639,7 +639,7 @@ target/arm/usb-pp.c
639target/arm/ata-pp5002.c 639target/arm/ata-pp5002.c
640target/arm/wmcodec-pp.c 640target/arm/wmcodec-pp.c
641target/arm/i2s-pp.c 641target/arm/i2s-pp.c
642target/arm/ipod/adc-ipod.c 642target/arm/ipod/1g2g/adc-ipod-1g2g.c
643target/arm/ipod/1g2g/backlight-1g2g.c 643target/arm/ipod/1g2g/backlight-1g2g.c
644target/arm/ipod/button-1g-3g.c 644target/arm/ipod/button-1g-3g.c
645target/arm/ipod/lcd-gray.c 645target/arm/ipod/lcd-gray.c
@@ -654,7 +654,7 @@ target/arm/ata-as-arm.S
654target/arm/ata-pp5020.c 654target/arm/ata-pp5020.c
655target/arm/wmcodec-pp.c 655target/arm/wmcodec-pp.c
656target/arm/i2s-pp.c 656target/arm/i2s-pp.c
657target/arm/ipod/adc-ipod.c 657target/arm/ipod/adc-ipod-pcf.c
658target/arm/ipod/backlight-mini1g_mini2g.c 658target/arm/ipod/backlight-mini1g_mini2g.c
659target/arm/ipod/button-mini1g.c 659target/arm/ipod/button-mini1g.c
660target/arm/ipod/lcd-gray.c 660target/arm/ipod/lcd-gray.c
@@ -670,7 +670,7 @@ target/arm/ata-as-arm.S
670target/arm/ata-pp5020.c 670target/arm/ata-pp5020.c
671target/arm/wmcodec-pp.c 671target/arm/wmcodec-pp.c
672target/arm/i2s-pp.c 672target/arm/i2s-pp.c
673target/arm/ipod/adc-ipod.c 673target/arm/ipod/adc-ipod-pcf.c
674target/arm/ipod/backlight-mini1g_mini2g.c 674target/arm/ipod/backlight-mini1g_mini2g.c
675target/arm/ipod/button-clickwheel.c 675target/arm/ipod/button-clickwheel.c
676target/arm/ipod/lcd-gray.c 676target/arm/ipod/lcd-gray.c
diff --git a/firmware/export/config-ipod1g2g.h b/firmware/export/config-ipod1g2g.h
index b69d401f36..188c3930f6 100644
--- a/firmware/export/config-ipod1g2g.h
+++ b/firmware/export/config-ipod1g2g.h
@@ -81,11 +81,11 @@
81 81
82/* Type of mobile power */ 82/* Type of mobile power */
83#define CONFIG_BATTERY BATT_LIPOL1300 83#define CONFIG_BATTERY BATT_LIPOL1300
84#define BATTERY_CAPACITY_MIN 630 /* min. capacity selectable */ 84#define BATTERY_CAPACITY_MIN 1200 /* min. capacity selectable */
85#define BATTERY_CAPACITY_MAX 1000 /* max. capacity selectable */ 85#define BATTERY_CAPACITY_MAX 1900 /* max. capacity selectable */
86#define BATTERY_CAPACITY_INC 10 /* capacity increment */ 86#define BATTERY_CAPACITY_INC 50 /* capacity increment */
87#define BATTERY_TYPES_COUNT 1 /* only one type */ 87#define BATTERY_TYPES_COUNT 1 /* only one type */
88#define BATTERY_SCALE_FACTOR 5865 88#define BATTERY_SCALE_FACTOR 25882
89 89
90/* Hardware controlled charging? FIXME */ 90/* Hardware controlled charging? FIXME */
91//#define CONFIG_CHARGING CHARGING_SIMPLE 91//#define CONFIG_CHARGING CHARGING_SIMPLE
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