2004-10-15 21:41:46 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
* Tuner "middleware" for Philips TEA5767 chip
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2004 J<EFBFBD>rg Hohensohn
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2005-08-13 17:34:10 +00:00
|
|
|
|
#include "config.h"
|
2004-10-15 21:41:46 +00:00
|
|
|
|
#include <stdbool.h>
|
2004-10-17 23:24:18 +00:00
|
|
|
|
#include <string.h>
|
2004-10-19 08:20:38 +00:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include "kernel.h"
|
2004-10-15 21:41:46 +00:00
|
|
|
|
#include "tuner.h" /* tuner abstraction interface */
|
|
|
|
|
#include "fmradio_i2c.h" /* physical interface driver */
|
|
|
|
|
|
2004-10-17 23:24:18 +00:00
|
|
|
|
#define I2C_ADR 0xC0
|
|
|
|
|
static unsigned char write_bytes[5];
|
2004-10-15 21:41:46 +00:00
|
|
|
|
|
|
|
|
|
/* tuner abstraction layer: set something to the tuner */
|
|
|
|
|
void philips_set(int setting, int value)
|
|
|
|
|
{
|
|
|
|
|
switch(setting)
|
|
|
|
|
{
|
2004-10-19 08:20:38 +00:00
|
|
|
|
case RADIO_SLEEP:
|
|
|
|
|
/* init values */
|
|
|
|
|
write_bytes[0] = 0x80; /* mute */
|
|
|
|
|
write_bytes[1] = 0x00;
|
2005-08-24 09:15:13 +00:00
|
|
|
|
write_bytes[2] = 0x00;
|
2005-08-13 17:34:10 +00:00
|
|
|
|
#if CONFIG_TUNER_XTAL == 32768000
|
|
|
|
|
write_bytes[3] = 0x1A; /* 32.768MHz, soft mute,
|
|
|
|
|
stereo noise cancelling */
|
|
|
|
|
#else
|
2004-10-19 08:20:38 +00:00
|
|
|
|
write_bytes[3] = 0x0A; /* soft mute, stereo noise cancelling */
|
2005-08-13 17:34:10 +00:00
|
|
|
|
#endif
|
2004-10-19 08:20:38 +00:00
|
|
|
|
write_bytes[4] = 0x00;
|
|
|
|
|
if (value) /* sleep */
|
|
|
|
|
{
|
|
|
|
|
write_bytes[3] |= 0x40; /* standby mode */
|
|
|
|
|
}
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RADIO_FREQUENCY:
|
2004-10-17 23:24:18 +00:00
|
|
|
|
{
|
|
|
|
|
int n;
|
2005-08-13 17:34:10 +00:00
|
|
|
|
#if CONFIG_TUNER_XTAL == 32768000
|
2005-08-24 09:15:13 +00:00
|
|
|
|
n = (4 * (value - 225000)) / 32768;
|
2005-08-13 17:34:10 +00:00
|
|
|
|
#else
|
2005-08-24 09:15:13 +00:00
|
|
|
|
n = (4 * (value - 225000)) / 50000;
|
2005-08-13 17:34:10 +00:00
|
|
|
|
#endif
|
2004-10-17 23:24:18 +00:00
|
|
|
|
write_bytes[0] = (write_bytes[0] & 0xC0) | (n >> 8);
|
|
|
|
|
write_bytes[1] = n & 0xFF;
|
|
|
|
|
}
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RADIO_MUTE:
|
2004-10-17 23:24:18 +00:00
|
|
|
|
write_bytes[0] = (write_bytes[0] & 0x7F) | (value ? 0x80 : 0);
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RADIO_FORCE_MONO:
|
2004-10-17 23:24:18 +00:00
|
|
|
|
write_bytes[2] = (write_bytes[2] & 0xF7) | (value ? 0x08 : 0);
|
|
|
|
|
fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
2004-10-18 07:58:59 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2004-10-15 21:41:46 +00:00
|
|
|
|
}
|
2004-10-18 07:58:59 +00:00
|
|
|
|
fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
|
2004-10-15 21:41:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* tuner abstraction layer: read something from the tuner */
|
|
|
|
|
int philips_get(int setting)
|
|
|
|
|
{
|
2004-10-17 23:24:18 +00:00
|
|
|
|
unsigned char read_bytes[5];
|
2004-10-18 07:58:59 +00:00
|
|
|
|
int val = -1; /* default for unsupported query */
|
2004-10-17 23:24:18 +00:00
|
|
|
|
|
|
|
|
|
fmradio_i2c_read(I2C_ADR, read_bytes, sizeof(read_bytes));
|
|
|
|
|
|
2004-10-15 21:41:46 +00:00
|
|
|
|
switch(setting)
|
|
|
|
|
{
|
|
|
|
|
case RADIO_PRESENT:
|
2004-10-17 23:24:18 +00:00
|
|
|
|
val = 1; /* true */
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-10-19 08:20:38 +00:00
|
|
|
|
case RADIO_TUNED:
|
|
|
|
|
val = 0;
|
|
|
|
|
if (read_bytes[0] & 0x80) /* ready */
|
|
|
|
|
{
|
|
|
|
|
val = read_bytes[2] & 0x7F; /* IF counter */
|
|
|
|
|
val = (abs(val - 0x36) < 2); /* close match */
|
|
|
|
|
}
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RADIO_STEREO:
|
2004-10-17 23:24:18 +00:00
|
|
|
|
val = read_bytes[2] >> 7;
|
2004-10-15 21:41:46 +00:00
|
|
|
|
break;
|
2004-10-19 08:20:38 +00:00
|
|
|
|
|
|
|
|
|
case RADIO_ALL: /* debug query */
|
|
|
|
|
val = read_bytes[0] << 24
|
|
|
|
|
| read_bytes[1] << 16
|
|
|
|
|
| read_bytes[2] << 8
|
|
|
|
|
| read_bytes[3];
|
|
|
|
|
break;
|
2004-10-15 21:41:46 +00:00
|
|
|
|
}
|
|
|
|
|
return val;
|
|
|
|
|
}
|