summaryrefslogtreecommitdiff
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
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
-rw-r--r--apps/keymaps/keymap-h10.c23
-rw-r--r--apps/recorder/radio.c4
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/drivers/audio/wm8731.c13
-rw-r--r--firmware/export/config-h10.h6
-rw-r--r--firmware/export/config-h10_5gb.h6
-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
9 files changed, 263 insertions, 15 deletions
diff --git a/apps/keymaps/keymap-h10.c b/apps/keymaps/keymap-h10.c
index 3e90f1520e..883b0d37d4 100644
--- a/apps/keymaps/keymap-h10.c
+++ b/apps/keymaps/keymap-h10.c
@@ -305,6 +305,26 @@ const struct button_mapping button_context_recscreen[] = {
305 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS) 305 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS)
306}; /* button_context_recscreen */ 306}; /* button_context_recscreen */
307 307
308static const struct button_mapping button_context_radio[] = {
309 { ACTION_FM_PRESET, BUTTON_RIGHT | BUTTON_REL, BUTTON_RIGHT },
310 { ACTION_FM_MENU, BUTTON_RIGHT | BUTTON_REPEAT, BUTTON_NONE },
311 { ACTION_FM_MODE, BUTTON_LEFT, BUTTON_NONE },
312 { ACTION_FM_STOP, BUTTON_PLAY | BUTTON_REPEAT, BUTTON_PLAY },
313 { ACTION_FM_EXIT, BUTTON_POWER, BUTTON_NONE },
314 { ACTION_FM_PLAY, BUTTON_PLAY | BUTTON_REL, BUTTON_PLAY },
315 { ACTION_SETTINGS_INC, BUTTON_SCROLL_UP, BUTTON_NONE },
316 { ACTION_SETTINGS_INCREPEAT, BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE },
317 { ACTION_SETTINGS_DEC, BUTTON_SCROLL_DOWN, BUTTON_NONE },
318 { ACTION_SETTINGS_DECREPEAT, BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE },
319 { ACTION_STD_PREV, BUTTON_REW, BUTTON_NONE },
320 { ACTION_STD_PREVREPEAT, BUTTON_REW|BUTTON_REPEAT, BUTTON_NONE },
321 { ACTION_STD_NEXT, BUTTON_FF, BUTTON_NONE },
322 { ACTION_STD_NEXTREPEAT, BUTTON_FF|BUTTON_REPEAT, BUTTON_NONE },
323
324 LAST_ITEM_IN_LIST
325
326};
327
308static const struct button_mapping* get_context_mapping_remote( int context ) 328static const struct button_mapping* get_context_mapping_remote( int context )
309{ 329{
310 context ^= CONTEXT_REMOTE; 330 context ^= CONTEXT_REMOTE;
@@ -385,7 +405,8 @@ const struct button_mapping* get_context_mapping(int context)
385 return button_context_keyboard; 405 return button_context_keyboard;
386 case CONTEXT_RECSCREEN: 406 case CONTEXT_RECSCREEN:
387 return button_context_recscreen; 407 return button_context_recscreen;
388 408 case CONTEXT_FM:
409 return button_context_radio;
389 default: 410 default:
390 return button_context_standard; 411 return button_context_standard;
391 } 412 }
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index a0cc10ce18..7a45027933 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -81,6 +81,10 @@
81#define FM_NEXT_PRESET 81#define FM_NEXT_PRESET
82#define FM_PREV_PRESET 82#define FM_PREV_PRESET
83 83
84#elif CONFIG_KEYPAD == IRIVER_H10_PAD
85#define FM_PRESET
86#define FM_MODE
87
84#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) 88#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
85#define FM_PRESET 89#define FM_PRESET
86#define FM_MODE 90#define FM_MODE
diff --git a/firmware/SOURCES b/firmware/SOURCES
index e78d74a198..465d10e662 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -557,6 +557,7 @@ target/arm/i2s-pp.c
557target/arm/iriver/h10/adc-h10.c 557target/arm/iriver/h10/adc-h10.c
558target/arm/iriver/h10/backlight-h10.c 558target/arm/iriver/h10/backlight-h10.c
559target/arm/iriver/h10/button-h10.c 559target/arm/iriver/h10/button-h10.c
560target/arm/iriver/h10/fmradio_i2c-h10.c
560target/arm/iriver/h10/lcd-h10_20gb.c 561target/arm/iriver/h10/lcd-h10_20gb.c
561target/arm/iriver/h10/power-h10.c 562target/arm/iriver/h10/power-h10.c
562target/arm/iriver/h10/powermgmt-h10.c 563target/arm/iriver/h10/powermgmt-h10.c
@@ -573,6 +574,7 @@ target/arm/i2s-pp.c
573target/arm/iriver/h10/adc-h10.c 574target/arm/iriver/h10/adc-h10.c
574target/arm/iriver/h10/backlight-h10.c 575target/arm/iriver/h10/backlight-h10.c
575target/arm/iriver/h10/button-h10.c 576target/arm/iriver/h10/button-h10.c
577target/arm/iriver/h10/fmradio_i2c-h10.c
576target/arm/iriver/h10/lcd-h10_5gb.c 578target/arm/iriver/h10/lcd-h10_5gb.c
577target/arm/iriver/h10/power-h10.c 579target/arm/iriver/h10/power-h10.c
578target/arm/iriver/h10/powermgmt-h10.c 580target/arm/iriver/h10/powermgmt-h10.c
diff --git a/firmware/drivers/audio/wm8731.c b/firmware/drivers/audio/wm8731.c
index 785cb2a91c..44aeefe791 100644
--- a/firmware/drivers/audio/wm8731.c
+++ b/firmware/drivers/audio/wm8731.c
@@ -319,6 +319,15 @@ void audiohw_set_recvol(int left, int right, int type)
319 319
320void audiohw_set_monitor(int enable) 320void audiohw_set_monitor(int enable)
321{ 321{
322 /* TODO: Implement for FM monitoring */ 322 if(enable)
323 (void)enable; 323 {
324 wm8731_regs[AAPCTRL] |= AAPCTRL_BYPASS;
325 wm8731_regs[AAPCTRL] &=~ (AAPCTRL_DACSEL | AAPCTRL_SIDETONE);
326 wm8731_write(AAPCTRL, wm8731_regs[AAPCTRL]);
327 }
328 else {
329 wm8731_regs[AAPCTRL] &=~ AAPCTRL_BYPASS;
330 wm8731_regs[AAPCTRL] |= AAPCTRL_DACSEL | AAPCTRL_SIDETONE;
331 wm8731_write(AAPCTRL, wm8731_regs[AAPCTRL]);
332 }
324} 333}
diff --git a/firmware/export/config-h10.h b/firmware/export/config-h10.h
index 039ebc588f..e1e0b54e28 100644
--- a/firmware/export/config-h10.h
+++ b/firmware/export/config-h10.h
@@ -12,7 +12,7 @@
12#define HAVE_RECORDING 12#define HAVE_RECORDING
13/* Define bitmask of input sources - recordable bitmask can be defined 13/* Define bitmask of input sources - recordable bitmask can be defined
14 explicitly if different */ 14 explicitly if different */
15#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN) 15#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_FMRADIO)
16 16
17/* define the bitmask of hardware sample rates */ 17/* define the bitmask of hardware sample rates */
18#define HW_SAMPR_CAPS (SAMPR_CAP_44) 18#define HW_SAMPR_CAPS (SAMPR_CAP_44)
@@ -88,8 +88,8 @@
88#define AB_REPEAT_ENABLE 1 88#define AB_REPEAT_ENABLE 1
89 89
90/* FM Tuner */ 90/* FM Tuner */
91/*#define CONFIG_TUNER TEA5767 91#define CONFIG_TUNER TEA5767
92#define CONFIG_TUNER_XTAL 32768 *//* TODO: what is this? */ 92#define CONFIG_TUNER_XTAL 32768
93 93
94/* Define this for LCD backlight available */ 94/* Define this for LCD backlight available */
95#define HAVE_BACKLIGHT 95#define HAVE_BACKLIGHT
diff --git a/firmware/export/config-h10_5gb.h b/firmware/export/config-h10_5gb.h
index 3d10af26cf..b7195221ca 100644
--- a/firmware/export/config-h10_5gb.h
+++ b/firmware/export/config-h10_5gb.h
@@ -12,7 +12,7 @@
12#define HAVE_RECORDING 12#define HAVE_RECORDING
13/* Define bitmask of input sources - recordable bitmask can be defined 13/* Define bitmask of input sources - recordable bitmask can be defined
14 explicitly if different */ 14 explicitly if different */
15#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN) 15#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_FMRADIO)
16 16
17/* define the bitmask of hardware sample rates */ 17/* define the bitmask of hardware sample rates */
18#define HW_SAMPR_CAPS (SAMPR_CAP_44) 18#define HW_SAMPR_CAPS (SAMPR_CAP_44)
@@ -74,8 +74,8 @@
74#define AB_REPEAT_ENABLE 1 74#define AB_REPEAT_ENABLE 1
75 75
76/* FM Tuner */ 76/* FM Tuner */
77/*#define CONFIG_TUNER TEA5767 77#define CONFIG_TUNER TEA5767
78#define CONFIG_TUNER_XTAL 32768 *//* TODO: what is this? */ 78#define CONFIG_TUNER_XTAL 32768
79 79
80/* Define this for LCD backlight available */ 80/* Define this for LCD backlight available */
81#define HAVE_BACKLIGHT 81#define HAVE_BACKLIGHT
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{