Fix remote screen check in graphic equalizer, so that it can be used on logf-enabled...
[Rockbox.git] / firmware / tuner_philips.c
blob0a6f5c4c7f434063fbcd5a461ff46eec844b0cc8
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 void 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_MUTE:
64 write_bytes[0] = (write_bytes[0] & 0x7F) | (value ? 0x80 : 0);
65 break;
67 case RADIO_FORCE_MONO:
68 write_bytes[2] = (write_bytes[2] & 0xF7) | (value ? 0x08 : 0);
69 break;
71 case RADIO_SET_DEEMPHASIS:
72 write_bytes[4] = (write_bytes[4] & ~(1<<6)) | (value ? (1<<6) : 0);
73 break;
75 case RADIO_SET_BAND:
76 write_bytes[3] = (write_bytes[3] & ~(1<<5)) | (value ? (1<<5) : 0);
77 default:
78 return;
80 fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
83 /* tuner abstraction layer: read something from the tuner */
84 int philips_get(int setting)
86 unsigned char read_bytes[5];
87 int val = -1; /* default for unsupported query */
89 fmradio_i2c_read(I2C_ADR, read_bytes, sizeof(read_bytes));
91 switch(setting)
93 case RADIO_PRESENT:
94 val = 1; /* true */
95 break;
97 case RADIO_TUNED:
98 val = 0;
99 if (read_bytes[0] & 0x80) /* ready */
101 val = read_bytes[2] & 0x7F; /* IF counter */
102 val = (abs(val - 0x36) < 2); /* close match */
104 break;
106 case RADIO_STEREO:
107 val = read_bytes[2] >> 7;
108 break;
110 case RADIO_ALL: /* debug query */
111 val = read_bytes[0] << 24
112 | read_bytes[1] << 16
113 | read_bytes[2] << 8
114 | read_bytes[3];
115 break;
117 return val;