1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "tuner.h" /* tuner abstraction interface */
26 #include "fmradio_i2c.h" /* physical interface driver */
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
)
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);
43 /* soft mute, stereo noise cancelling */
44 write_bytes
[3] |= (1<<3) | (1<<1);
46 /* sleep / standby mode */
47 write_bytes
[3] &= ~(1<<6) | (value
? (1<<6) : 0);
53 #if CONFIG_TUNER_XTAL == 32768
54 n
= (4 * (value
- 225000) + 16384) / 32768;
56 n
= (4 * (value
- 225000)) / 50000;
58 write_bytes
[0] = (write_bytes
[0] & 0xC0) | (n
>> 8);
59 write_bytes
[1] = n
& 0xFF;
64 write_bytes
[0] = (write_bytes
[0] & 0x7F) | (value
? 0x80 : 0);
67 case RADIO_FORCE_MONO
:
68 write_bytes
[2] = (write_bytes
[2] & 0xF7) | (value
? 0x08 : 0);
71 case RADIO_SET_DEEMPHASIS
:
72 write_bytes
[4] = (write_bytes
[4] & ~(1<<6)) | (value
? (1<<6) : 0);
76 write_bytes
[3] = (write_bytes
[3] & ~(1<<5)) | (value
? (1<<5) : 0);
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
));
99 if (read_bytes
[0] & 0x80) /* ready */
101 val
= read_bytes
[2] & 0x7F; /* IF counter */
102 val
= (abs(val
- 0x36) < 2); /* close match */
107 val
= read_bytes
[2] >> 7;
110 case RADIO_ALL
: /* debug query */
111 val
= read_bytes
[0] << 24
112 | read_bytes
[1] << 16