1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Tuner "middleware" for Philips TEA5767 chip
11 * Copyright (C) 2004 Jörg Hohensohn
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
27 #include "tuner.h" /* tuner abstraction interface */
29 #include "fmradio_i2c.h" /* physical interface driver */
31 #if defined(PHILIPS_HDD1630) || defined(ONDA_VX747) || defined(ONDA_VX777) || defined(PHILIPS_HDD6330)
37 /* define RSSI range */
41 static bool tuner_present
= true;
42 static unsigned char write_bytes
[5] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
44 static void tea5767_set_clear(int byte
, unsigned char bits
, int set
)
46 write_bytes
[byte
] &= ~bits
;
48 write_bytes
[byte
] |= bits
;
51 /* tuner abstraction layer: set something to the tuner */
52 int tea5767_set(int setting
, int value
)
58 write_bytes
[0] |= (1<<7); /* mute */
59 #if CONFIG_TUNER_XTAL == 32768
60 /* 32.768kHz, soft mute, stereo noise cancelling */
61 write_bytes
[3] |= (1<<4) | (1<<3) | (1<<1);
63 /* soft mute, stereo noise cancelling */
64 write_bytes
[3] |= (1<<3) | (1<<1);
66 /* sleep / standby mode */
67 tea5767_set_clear(3, (1<<6), value
);
73 #if CONFIG_TUNER_XTAL == 32768
74 n
= (4 * (value
- 225000) + 16384) / 32768;
76 n
= (4 * (value
- 225000)) / 50000;
78 write_bytes
[0] = (write_bytes
[0] & 0xC0) | (n
>> 8);
83 case RADIO_SCAN_FREQUENCY
:
84 tea5767_set(RADIO_FREQUENCY
, value
);
86 return tea5767_get(RADIO_TUNED
);
89 tea5767_set_clear(0, 0x80, value
);
94 const struct fm_region_data
*rd
= &fm_region_data
[value
];
95 int deemphasis
= (rd
->deemphasis
== 75) ? 1 : 0;
96 int band
= (rd
->freq_min
== 76000000) ? 1 : 0;
98 tea5767_set_clear(4, (1<<6), deemphasis
);
99 tea5767_set_clear(3, (1<<5), band
);
102 case RADIO_FORCE_MONO
:
103 tea5767_set_clear(2, 0x08, value
);
109 fmradio_i2c_write(I2C_ADR
, write_bytes
, sizeof(write_bytes
));
113 /* tuner abstraction layer: read something from the tuner */
114 int tea5767_get(int setting
)
116 unsigned char read_bytes
[5];
117 int val
= -1; /* default for unsupported query */
119 fmradio_i2c_read(I2C_ADR
, read_bytes
, sizeof(read_bytes
));
129 if (read_bytes
[0] & 0x80) /* ready */
131 val
= read_bytes
[2] & 0x7F; /* IF counter */
132 val
= (abs(val
- 0x36) < 2); /* close match */
137 val
= read_bytes
[2] >> 7;
141 val
= 10 + 3*(read_bytes
[3] >> 4);
156 void tea5767_init(void)
158 /* save binsize by only detecting presence for targets where it may be absent */
159 #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
160 unsigned char buf
[5];
161 unsigned char chipid
;
163 /* init chipid register with 0xFF in case fmradio_i2c_read fails silently */
165 if (fmradio_i2c_read(I2C_ADR
, buf
, sizeof(buf
)) < 0) {
166 /* no i2c device detected */
167 tuner_present
= false;
170 chipid
= buf
[3] & 0x0F;
171 tuner_present
= (chipid
== 0);
176 void tea5767_dbg_info(struct tea5767_dbg_info
*info
)
178 fmradio_i2c_read(I2C_ADR
, info
->read_regs
, 5);
179 memcpy(info
->write_regs
, write_bytes
, 5);