fix the gigabeat remote button not working when backlight is off and filter first...
[Rockbox.git] / firmware / tuner_philips.c
blob8520fdbae9de19eff56993aa2422ecc43c6db26e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 * Tuner "middleware" for Philips TEA5767 chip
11 * Copyright (C) 2004 Jörg Hohensohn
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.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
20 #include "config.h"
21 #include <stdbool.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include "kernel.h"
25 #include "tuner.h" /* tuner abstraction interface */
26 #include "fmradio_i2c.h" /* physical interface driver */
28 #define I2C_ADR 0xC0
29 static unsigned char write_bytes[5] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
31 /* tuner abstraction layer: set something to the tuner */
32 int philips_set(int setting, int value)
34 switch(setting)
36 case RADIO_SLEEP:
37 /* init values */
38 write_bytes[0] |= (1<<7); /* mute */
39 #if CONFIG_TUNER_XTAL == 32768
40 /* 32.768kHz, soft mute, stereo noise cancelling */
41 write_bytes[3] |= (1<<4) | (1<<3) | (1<<1);
42 #else
43 /* soft mute, stereo noise cancelling */
44 write_bytes[3] |= (1<<3) | (1<<1);
45 #endif
46 /* sleep / standby mode */
47 write_bytes[3] &= ~(1<<6) | (value ? (1<<6) : 0);
48 break;
50 case RADIO_FREQUENCY:
52 int n;
53 #if CONFIG_TUNER_XTAL == 32768
54 n = (4 * (value - 225000) + 16384) / 32768;
55 #else
56 n = (4 * (value - 225000)) / 50000;
57 #endif
58 write_bytes[0] = (write_bytes[0] & 0xC0) | (n >> 8);
59 write_bytes[1] = n & 0xFF;
61 break;
63 case RADIO_SCAN_FREQUENCY:
64 philips_set(RADIO_FREQUENCY, value);
65 sleep(HZ/30);
66 return philips_get(RADIO_TUNED);
68 case RADIO_MUTE:
69 write_bytes[0] = (write_bytes[0] & 0x7F) | (value ? 0x80 : 0);
70 break;
72 case RADIO_FORCE_MONO:
73 write_bytes[2] = (write_bytes[2] & 0xF7) | (value ? 0x08 : 0);
74 break;
76 case RADIO_SET_DEEMPHASIS:
77 write_bytes[4] = (write_bytes[4] & ~(1<<6)) | (value ? (1<<6) : 0);
78 break;
80 case RADIO_SET_BAND:
81 write_bytes[3] = (write_bytes[3] & ~(1<<5)) | (value ? (1<<5) : 0);
82 default:
83 return -1;
85 fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
86 return 1;
89 /* tuner abstraction layer: read something from the tuner */
90 int philips_get(int setting)
92 unsigned char read_bytes[5];
93 int val = -1; /* default for unsupported query */
95 fmradio_i2c_read(I2C_ADR, read_bytes, sizeof(read_bytes));
97 switch(setting)
99 case RADIO_PRESENT:
100 val = 1; /* true */
101 break;
103 case RADIO_TUNED:
104 val = 0;
105 if (read_bytes[0] & 0x80) /* ready */
107 val = read_bytes[2] & 0x7F; /* IF counter */
108 val = (abs(val - 0x36) < 2); /* close match */
110 break;
112 case RADIO_STEREO:
113 val = read_bytes[2] >> 7;
114 break;
116 return val;
119 void philips_dbg_info(struct philips_dbg_info *info)
121 fmradio_i2c_read(I2C_ADR, info->read_regs, 5);
122 memcpy(info->write_regs, write_bytes, 5);