summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-11-11 16:00:33 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-11-11 16:00:33 +0000
commitc495cdae5926c9245d7c943c72a97206d4a0e22a (patch)
tree86afcd473d1c151ffd26fcb8e941be44a0bbbf53 /firmware/target
parent496027d8bb89ba6d503b544f5652f4d1683d43af (diff)
downloadrockbox-c495cdae5926c9245d7c943c72a97206d4a0e22a.tar.gz
rockbox-c495cdae5926c9245d7c943c72a97206d4a0e22a.zip
FS#8046: H10 FM tuner support. Thanks to Przemyslaw Holubowski for doing the hard work in figuring out how to communicate with the tuner.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15578 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/audio-pp.c16
-rw-r--r--firmware/target/arm/iriver/h10/fmradio_i2c-h10.c206
-rw-r--r--firmware/target/arm/iriver/h10/power-h10.c2
3 files changed, 218 insertions, 6 deletions
diff --git a/firmware/target/arm/audio-pp.c b/firmware/target/arm/audio-pp.c
index 9fff197520..783342ef37 100644
--- a/firmware/target/arm/audio-pp.c
+++ b/firmware/target/arm/audio-pp.c
@@ -35,6 +35,7 @@ void audio_input_mux(int source, unsigned flags)
35 /* Prevent pops from unneeded switching */ 35 /* Prevent pops from unneeded switching */
36 static int last_source = AUDIO_SRC_PLAYBACK; 36 static int last_source = AUDIO_SRC_PLAYBACK;
37#ifdef HAVE_FMRADIO_REC 37#ifdef HAVE_FMRADIO_REC
38 bool recording = flags & SRCF_RECORDING;
38 static bool last_recording = false; 39 static bool last_recording = false;
39#endif 40#endif
40 41
@@ -62,6 +63,10 @@ void audio_input_mux(int source, unsigned flags)
62#endif 63#endif
63#ifdef HAVE_LINEIN_REC 64#ifdef HAVE_LINEIN_REC
64 case AUDIO_SRC_LINEIN: /* recording only */ 65 case AUDIO_SRC_LINEIN: /* recording only */
66#if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
67 /* Switch line in source to line-in */
68 GPIO_SET_BITWISE(GPIOB_OUTPUT_VAL, 0x04);
69#endif
65 if (source != last_source) 70 if (source != last_source)
66 { 71 {
67 audiohw_enable_recording(false); /* source line */ 72 audiohw_enable_recording(false); /* source line */
@@ -71,17 +76,20 @@ void audio_input_mux(int source, unsigned flags)
71#endif 76#endif
72#ifdef HAVE_FMRADIO_REC 77#ifdef HAVE_FMRADIO_REC
73 case AUDIO_SRC_FMRADIO: /* recording and playback */ 78 case AUDIO_SRC_FMRADIO: /* recording and playback */
79#if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
80 /* Switch line in source to tuner */
81 GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL, 0x04);
82#endif /* Set line-in vol to 0dB*/
74 if (!recording) 83 if (!recording)
75 audiohw_set_recvol(0, 0, AUDIO_GAIN_LINEIN); 84 audiohw_set_recvol(0x17, 0x17, AUDIO_GAIN_LINEIN);
76 85
77 if (source == last_source && recording == last_recording) 86 if (source == last_source && recording == last_recording)
78 break; 87 break;
79 88
80 last_recording = recording; 89 last_recording = recording;
81 90
82 /* I2S recording and playback */ 91 audiohw_enable_recording(false); /* select line-in source */
83 audiohw_enable_recording(false); /* source line */ 92 audiohw_set_monitor(!recording); /* enable bypass mode */
84 audiohw_set_monitor(!recording);
85 break; 93 break;
86#endif 94#endif
87 } /* end switch */ 95 } /* end switch */
diff --git a/firmware/target/arm/iriver/h10/fmradio_i2c-h10.c b/firmware/target/arm/iriver/h10/fmradio_i2c-h10.c
new file mode 100644
index 0000000000..f3d3075df9
--- /dev/null
+++ b/firmware/target/arm/iriver/h10/fmradio_i2c-h10.c
@@ -0,0 +1,206 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 * Physical interface of the Philips TEA5767 in iriver H10 series
10 *
11 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include "config.h"
21#include "cpu.h"
22#include "logf.h"
23#include "system.h"
24
25/* cute little functions, atomic read-modify-write */
26
27#define SDA_OUTINIT GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x08)
28#define SDA_HI_IN GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_EN, 0x08)
29#define SDA_LO_OUT GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x08)
30#define SDA (GPIOD_INPUT_VAL & 0x08)
31
32#define SCL_INPUT GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_EN, 0x10)
33#define SCL_OUTPUT GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x10)
34#define SCL_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x10)
35#define SCL_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL,0x10)
36#define SCL (GPIOD_INPUT_VAL & 0x10)
37
38#define DELAY udelay(2)
39
40static void fmradio_i2c_start(void)
41{
42 SCL_HI;
43 SCL_OUTPUT;
44 SDA_HI_IN;
45 SDA_OUTINIT;
46 DELAY;
47 SDA_LO_OUT;
48 DELAY;
49 SCL_LO;
50}
51
52static void fmradio_i2c_stop(void)
53{
54 SDA_LO_OUT;
55 DELAY;
56 SCL_HI;
57 DELAY;
58 SDA_HI_IN;
59}
60
61/* Generate ACK or NACK */
62static void fmradio_i2c_ack(bool nack)
63{
64 /* Here's the deal. The slave is slow, and sometimes needs to wait
65 before it can receive the acknowledge. Therefore it forces the clock
66 low until it is ready. We need to poll the clock line until it goes
67 high before we release the ack.
68
69 In their infinite wisdom, iriver didn't pull up the SCL line, so
70 we have to drive the SCL high repeatedly to simulate a pullup. */
71
72 if (nack)
73 SDA_HI_IN;
74 else
75 SDA_LO_OUT;
76 DELAY;
77
78 SCL_HI;
79 do
80 {
81 SCL_OUTPUT; /* Set the clock to output */
82 SCL_INPUT; /* Set the clock to input */
83 DELAY;
84 }
85 while(!SCL); /* and wait for the slave to release it */
86
87 SCL_OUTPUT;
88 SCL_LO;
89}
90
91static int fmradio_i2c_getack(void)
92{
93 int ret = 1;
94
95 /* Here's the deal. The slave is slow, and sometimes needs to wait
96 before it can send the acknowledge. Therefore it forces the clock
97 low until it is ready. We need to poll the clock line until it goes
98 high before we read the ack.
99
100 In their infinite wisdom, iriver didn't pull up the SCL line, so
101 we have to drive the SCL high repeatedly to simulate a pullup. */
102
103 SDA_HI_IN;
104 DELAY;
105
106 SCL_HI; /* set clock to high */
107 do
108 {
109 SCL_OUTPUT; /* Set the clock to output */
110 SCL_INPUT; /* Set the clock to input */
111 DELAY;
112 }
113 while(!SCL); /* and wait for the slave to release it */
114
115 if (SDA)
116 ret = 0; /* ack failed */
117
118 SCL_OUTPUT;
119 SCL_LO;
120
121 return ret;
122}
123
124static void fmradio_i2c_outb(unsigned char byte)
125{
126 int i;
127
128 /* clock out each bit, MSB first */
129 for ( i=0x80; i; i>>=1 ) {
130 if ( i & byte )
131 SDA_HI_IN;
132 else
133 SDA_LO_OUT;
134 DELAY;
135 SCL_HI;
136 DELAY;
137 SCL_LO;
138 }
139}
140
141static unsigned char fmradio_i2c_inb(void)
142{
143 int i;
144 unsigned char byte = 0;
145
146 SDA_HI_IN;
147 /* clock in each bit, MSB first */
148 for ( i=0x80; i; i>>=1 ) {
149 DELAY;
150 SCL_HI;
151 DELAY;
152 if ( SDA )
153 byte |= i;
154 SCL_LO;
155 }
156
157 return byte;
158}
159
160int fmradio_i2c_write(int address, const unsigned char* buf, int count)
161{
162 int i,x=0;
163
164 fmradio_i2c_start();
165 fmradio_i2c_outb(address & 0xfe);
166 if (fmradio_i2c_getack())
167 {
168 for (i=0; i<count; i++)
169 {
170 fmradio_i2c_outb(buf[i]);
171 if (!fmradio_i2c_getack())
172 {
173 x=-2;
174 break;
175 }
176 }
177 }
178 else
179 {
180 logf("fmradio_i2c_write() - no ack\n");
181 x=-1;
182 }
183 fmradio_i2c_stop();
184 return x;
185}
186
187int fmradio_i2c_read(int address, unsigned char* buf, int count)
188{
189 int i,x=0;
190
191 fmradio_i2c_start();
192 fmradio_i2c_outb(address | 1);
193
194 if (fmradio_i2c_getack())
195 {
196 for (i=count; i>0; i--)
197 {
198 *buf++ = fmradio_i2c_inb();
199 fmradio_i2c_ack(i == 1);
200 }
201 }
202 else
203 x=-1;
204 fmradio_i2c_stop();
205 return x;
206}
diff --git a/firmware/target/arm/iriver/h10/power-h10.c b/firmware/target/arm/iriver/h10/power-h10.c
index 7f3fb40b36..f4d5be49a6 100644
--- a/firmware/target/arm/iriver/h10/power-h10.c
+++ b/firmware/target/arm/iriver/h10/power-h10.c
@@ -35,7 +35,6 @@
35bool charger_enabled; 35bool charger_enabled;
36#endif 36#endif
37 37
38#if 0
39#if CONFIG_TUNER 38#if CONFIG_TUNER
40 39
41bool tuner_power(bool status) 40bool tuner_power(bool status)
@@ -46,7 +45,6 @@ bool tuner_power(bool status)
46} 45}
47 46
48#endif /* #if CONFIG_TUNER */ 47#endif /* #if CONFIG_TUNER */
49#endif
50 48
51void power_init(void) 49void power_init(void)
52{ 50{