diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2008-11-10 20:55:56 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2008-11-10 20:55:56 +0000 |
commit | 02dfae031a2362dbbcec70f10a2bfe089719899d (patch) | |
tree | 0b86426a84149f9b9bec0d000c1be52df4dd248f /firmware | |
parent | f7b1d806e6f48367a2039b1ac08516db355b938c (diff) | |
download | rockbox-02dfae031a2362dbbcec70f10a2bfe089719899d.tar.gz rockbox-02dfae031a2362dbbcec70f10a2bfe089719899d.zip |
Sansa AMS: use the AS3514 ADC driver
Move the ADC defines to as3514.h, and make adc-target.h only include as3514.h
Implement the missing API (ascodec_readbytes, ascodec_(un)lock)
Revert the changes to the PP-specific arm/ascodec-target.h in r19073,
use a AS3525 specific ascodec-target.h while moving the AS3514 specific
code in export/as3514.h
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19076 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 2 | ||||
-rw-r--r-- | firmware/export/as3514.h | 27 | ||||
-rw-r--r-- | firmware/target/arm/as3525/adc-target.h (renamed from firmware/target/arm/as3525/adc-as3525.c) | 18 | ||||
-rw-r--r-- | firmware/target/arm/as3525/as3525-codec.c | 35 | ||||
-rw-r--r-- | firmware/target/arm/as3525/ascodec-target.h | 40 | ||||
-rw-r--r-- | firmware/target/arm/ascodec-target.h | 18 | ||||
-rw-r--r-- | firmware/target/arm/sandisk/adc-target.h | 22 |
7 files changed, 114 insertions, 48 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index ff75a6c888..0065749088 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -339,7 +339,7 @@ target/arm/as3525/ata_sd_as3525.c | |||
339 | target/arm/as3525/power-as3525.c | 339 | target/arm/as3525/power-as3525.c |
340 | target/arm/as3525/usb-as3525.c | 340 | target/arm/as3525/usb-as3525.c |
341 | #ifndef BOOTLOADER | 341 | #ifndef BOOTLOADER |
342 | target/arm/as3525/adc-as3525.c | 342 | target/arm/adc-as3514.c |
343 | target/arm/as3525/pcm-as3525.c | 343 | target/arm/as3525/pcm-as3525.c |
344 | target/arm/as3525/audio-as3525.c | 344 | target/arm/as3525/audio-as3525.c |
345 | target/arm/as3525/debug-as3525.c | 345 | target/arm/as3525/debug-as3525.c |
diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h index 2bbdc2ed66..f3c5c616eb 100644 --- a/firmware/export/as3514.h +++ b/firmware/export/as3514.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #ifndef _AS3514_H | 22 | #ifndef _AS3514_H |
23 | #define _AS3514_H | 23 | #define _AS3514_H |
24 | 24 | ||
25 | #include "config.h" | ||
25 | #include <stdbool.h> | 26 | #include <stdbool.h> |
26 | 27 | ||
27 | extern int tenthdb2master(int db); | 28 | extern int tenthdb2master(int db); |
@@ -80,4 +81,30 @@ extern void audiohw_set_sample_rate(int sampling_control); | |||
80 | #define VOLUME_MIN -735 | 81 | #define VOLUME_MIN -735 |
81 | #define VOLUME_MAX 60 | 82 | #define VOLUME_MAX 60 |
82 | 83 | ||
84 | /* ADC channels */ | ||
85 | #define NUM_ADC_CHANNELS 13 | ||
86 | |||
87 | #define ADC_BVDD 0 /* Battery voltage of 4V LiIo accumulator */ | ||
88 | #define ADC_RTCSUP 1 /* RTC backup battery voltage */ | ||
89 | #define ADC_UVDD 2 /* USB host voltage */ | ||
90 | #define ADC_CHG_IN 3 /* Charger input voltage */ | ||
91 | #define ADC_CVDD 4 /* Charger pump output voltage */ | ||
92 | #define ADC_BATTEMP 5 /* Battery charging temperature */ | ||
93 | #define ADC_MICSUP1 6 /* Voltage on MicSup1 for remote control | ||
94 | or external voltage measurement */ | ||
95 | #define ADC_MICSUP2 7 /* Voltage on MicSup1 for remote control | ||
96 | or external voltage measurement */ | ||
97 | #define ADC_VBE1 8 /* Measuring junction temperature @ 2uA */ | ||
98 | #define ADC_VBE2 9 /* Measuring junction temperature @ 1uA */ | ||
99 | #define ADC_I_MICSUP1 10 /* Current of MicSup1 for remote control detection */ | ||
100 | #define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */ | ||
101 | #define ADC_VBAT 12 /* Single cell battery voltage */ | ||
102 | |||
103 | #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \ | ||
104 | || CONFIG_CPU == AS3525 | ||
105 | #define AS3514_I2C_ADDR 0x46 | ||
106 | #else | ||
107 | #error Unknown target! | ||
108 | #endif | ||
109 | |||
83 | #endif /* _AS3514_H */ | 110 | #endif /* _AS3514_H */ |
diff --git a/firmware/target/arm/as3525/adc-as3525.c b/firmware/target/arm/as3525/adc-target.h index 6e1aac5a65..007a11af10 100644 --- a/firmware/target/arm/as3525/adc-as3525.c +++ b/firmware/target/arm/as3525/adc-target.h | |||
@@ -7,7 +7,7 @@ | |||
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright © 2008 Rafaël Carré | 10 | * Copyright (C) 2006 by Barry Wardell |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License | 13 | * modify it under the terms of the GNU General Public License |
@@ -18,16 +18,10 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #ifndef _ADC_TARGET_H_ | ||
22 | #define _ADC_TARGET_H_ | ||
21 | 23 | ||
22 | #include "adc.h" | 24 | /* The ADC sources and channels are common to all targets with AS3514 */ |
25 | #include "as3514.h" | ||
23 | 26 | ||
24 | /* TODO */ | 27 | #endif |
25 | |||
26 | unsigned short adc_read(int channel) | ||
27 | { | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | void adc_init(void) | ||
32 | { | ||
33 | } | ||
diff --git a/firmware/target/arm/as3525/as3525-codec.c b/firmware/target/arm/as3525/as3525-codec.c index 4d8598eaf1..86bce86c39 100644 --- a/firmware/target/arm/as3525/as3525-codec.c +++ b/firmware/target/arm/as3525/as3525-codec.c | |||
@@ -38,6 +38,7 @@ | |||
38 | */ | 38 | */ |
39 | 39 | ||
40 | #include "ascodec-target.h" | 40 | #include "ascodec-target.h" |
41 | #include "kernel.h" | ||
41 | #include "as3525.h" | 42 | #include "as3525.h" |
42 | 43 | ||
43 | #define I2C2_DATA *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x00)) | 44 | #define I2C2_DATA *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x00)) |
@@ -53,6 +54,7 @@ | |||
53 | #define I2C2_INT_CLR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x40)) | 54 | #define I2C2_INT_CLR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x40)) |
54 | #define I2C2_SADDR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x44)) | 55 | #define I2C2_SADDR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x44)) |
55 | 56 | ||
57 | static struct mutex as_mtx SHAREDBSS_ATTR; | ||
56 | 58 | ||
57 | /* initialises the internal i2c bus and prepares for transfers to the codec */ | 59 | /* initialises the internal i2c bus and prepares for transfers to the codec */ |
58 | void ascodec_init(void) | 60 | void ascodec_init(void) |
@@ -84,7 +86,7 @@ static int i2c_busy(void) | |||
84 | 86 | ||
85 | 87 | ||
86 | /* returns 0 on success, <0 otherwise */ | 88 | /* returns 0 on success, <0 otherwise */ |
87 | int ascodec_write(int index, int value) | 89 | int ascodec_write(unsigned int index, unsigned int value) |
88 | { | 90 | { |
89 | if (index == 0x21) { | 91 | if (index == 0x21) { |
90 | /* prevent setting of the LREG_CP_not bit */ | 92 | /* prevent setting of the LREG_CP_not bit */ |
@@ -110,7 +112,7 @@ int ascodec_write(int index, int value) | |||
110 | 112 | ||
111 | 113 | ||
112 | /* returns value read on success, <0 otherwise */ | 114 | /* returns value read on success, <0 otherwise */ |
113 | int ascodec_read(int index) | 115 | int ascodec_read(unsigned int index) |
114 | { | 116 | { |
115 | /* check if still busy */ | 117 | /* check if still busy */ |
116 | if (i2c_busy()) { | 118 | if (i2c_busy()) { |
@@ -128,3 +130,32 @@ int ascodec_read(int index) | |||
128 | return I2C2_DATA; | 130 | return I2C2_DATA; |
129 | } | 131 | } |
130 | 132 | ||
133 | int ascodec_readbytes(int index, int len, unsigned char *data) | ||
134 | { | ||
135 | int i; | ||
136 | |||
137 | ascodec_lock(); | ||
138 | |||
139 | for(i=0; i<len; i++) | ||
140 | { | ||
141 | int temp = ascodec_read(index+i); | ||
142 | if(temp == -1) | ||
143 | break; | ||
144 | else | ||
145 | data[i] = temp; | ||
146 | } | ||
147 | |||
148 | ascodec_unlock(); | ||
149 | |||
150 | return i; | ||
151 | } | ||
152 | |||
153 | void ascodec_lock(void) | ||
154 | { | ||
155 | mutex_lock(&as_mtx); | ||
156 | } | ||
157 | |||
158 | void ascodec_unlock(void) | ||
159 | { | ||
160 | mutex_unlock(&as_mtx); | ||
161 | } | ||
diff --git a/firmware/target/arm/as3525/ascodec-target.h b/firmware/target/arm/as3525/ascodec-target.h new file mode 100644 index 0000000000..46f6e11d4b --- /dev/null +++ b/firmware/target/arm/as3525/ascodec-target.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Driver for AS3514 audio codec | ||
11 | * | ||
12 | * Copyright (c) 2007 Daniel Ankers | ||
13 | * Copyright (c) 2007 Christian Gmeiner | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * as published by the Free Software Foundation; either version 2 | ||
18 | * of the License, or (at your option) any later version. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | |||
25 | #ifndef _ASCODEC_TARGET_H | ||
26 | #define _ASCODEC_TARGET_H | ||
27 | |||
28 | #include "as3514.h" | ||
29 | |||
30 | int ascodec_write(unsigned int index, unsigned int value); | ||
31 | |||
32 | int ascodec_read(unsigned int index); | ||
33 | |||
34 | int ascodec_readbytes(int index, int len, unsigned char *data); | ||
35 | |||
36 | void ascodec_lock(void); | ||
37 | |||
38 | void ascodec_unlock(void); | ||
39 | |||
40 | #endif /* !_ASCODEC_TARGET_H */ | ||
diff --git a/firmware/target/arm/ascodec-target.h b/firmware/target/arm/ascodec-target.h index afd19fff63..3337cb78b9 100644 --- a/firmware/target/arm/ascodec-target.h +++ b/firmware/target/arm/ascodec-target.h | |||
@@ -27,14 +27,11 @@ | |||
27 | 27 | ||
28 | #include "config.h" | 28 | #include "config.h" |
29 | 29 | ||
30 | #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) || \ | ||
31 | CONFIG_CPU==AS3525 | ||
32 | #define AS3514_I2C_ADDR 0x46 | ||
33 | #else | ||
34 | #error Unknown target! | ||
35 | #endif | ||
36 | |||
37 | #ifdef CPU_PP | 30 | #ifdef CPU_PP |
31 | /* TODO: This header is actually portalplayer specific, and should be | ||
32 | * moved into an appropriate subdir */ | ||
33 | |||
34 | #include "as3514.h" | ||
38 | #include "i2c-pp.h" | 35 | #include "i2c-pp.h" |
39 | 36 | ||
40 | static inline int ascodec_write(unsigned int reg, unsigned int value) | 37 | static inline int ascodec_write(unsigned int reg, unsigned int value) |
@@ -61,12 +58,7 @@ static inline void ascodec_unlock(void) | |||
61 | { | 58 | { |
62 | i2c_unlock(); | 59 | i2c_unlock(); |
63 | } | 60 | } |
64 | #elif CONFIG_CPU==AS3525 | ||
65 | void ascodec_init(void); | ||
66 | |||
67 | int ascodec_write(int index, int value); | ||
68 | 61 | ||
69 | int ascodec_read(int index); | 62 | #endif /* CPU_PP */ |
70 | #endif | ||
71 | 63 | ||
72 | #endif /* !_ASCODEC_TARGET_H */ | 64 | #endif /* !_ASCODEC_TARGET_H */ |
diff --git a/firmware/target/arm/sandisk/adc-target.h b/firmware/target/arm/sandisk/adc-target.h index ab7d5d92ed..007a11af10 100644 --- a/firmware/target/arm/sandisk/adc-target.h +++ b/firmware/target/arm/sandisk/adc-target.h | |||
@@ -21,25 +21,7 @@ | |||
21 | #ifndef _ADC_TARGET_H_ | 21 | #ifndef _ADC_TARGET_H_ |
22 | #define _ADC_TARGET_H_ | 22 | #define _ADC_TARGET_H_ |
23 | 23 | ||
24 | /* ADC channels */ | 24 | /* The ADC sources and channels are common to all targets with AS3514 */ |
25 | #define NUM_ADC_CHANNELS 13 | 25 | #include "as3514.h" |
26 | |||
27 | #define ADC_BVDD 0 /* Battery voltage of 4V LiIo accumulator */ | ||
28 | #define ADC_RTCSUP 1 /* RTC backup battery voltage */ | ||
29 | #define ADC_UVDD 2 /* USB host voltage */ | ||
30 | #define ADC_CHG_IN 3 /* Charger input voltage */ | ||
31 | #define ADC_CVDD 4 /* Charger pump output voltage */ | ||
32 | #define ADC_BATTEMP 5 /* Battery charging temperature */ | ||
33 | #define ADC_MICSUP1 6 /* Voltage on MicSup1 for remote control | ||
34 | or external voltage measurement */ | ||
35 | #define ADC_MICSUP2 7 /* Voltage on MicSup1 for remote control | ||
36 | or external voltage measurement */ | ||
37 | #define ADC_VBE1 8 /* Measuring junction temperature @ 2uA */ | ||
38 | #define ADC_VBE2 9 /* Measuring junction temperature @ 1uA */ | ||
39 | #define ADC_I_MICSUP1 10 /* Current of MicSup1 for remote control detection */ | ||
40 | #define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */ | ||
41 | #define ADC_VBAT 12 /* Single cell battery voltage */ | ||
42 | |||
43 | #define ADC_UNREG_POWER ADC_BVDD /* For compatibility */ | ||
44 | 26 | ||
45 | #endif | 27 | #endif |