2004-10-15 21:41:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
* Tuner "middleware" for Philips TEA5767 chip
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2004 Jörg Hohensohn
|
2004-10-15 21:41:46 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-10-15 21:41:46 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2012-02-25 15:07:17 +00:00
|
|
|
#include "power.h"
|
2004-10-15 21:41:46 +00:00
|
|
|
#include "tuner.h" /* tuner abstraction interface */
|
2007-07-14 11:20:31 +00:00
|
|
|
#include "fmradio.h"
|
2004-10-15 21:41:46 +00:00
|
|
|
#include "fmradio_i2c.h" /* physical interface driver */
|
|
|
|
|
2010-06-19 03:51:57 +00:00
|
|
|
#if defined(PHILIPS_HDD1630) || defined(ONDA_VX747) || defined(ONDA_VX777) || defined(PHILIPS_HDD6330)
|
2009-02-13 03:49:17 +00:00
|
|
|
#define I2C_ADR 0x60
|
|
|
|
#else
|
2004-10-17 23:24:18 +00:00
|
|
|
#define I2C_ADR 0xC0
|
2009-02-13 03:49:17 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-11 21:13:29 +00:00
|
|
|
/* define RSSI range */
|
|
|
|
#define RSSI_MIN 10
|
|
|
|
#define RSSI_MAX 55
|
|
|
|
|
2010-11-05 17:04:18 +00:00
|
|
|
static bool tuner_present = true;
|
2006-10-23 19:48:42 +00:00
|
|
|
static unsigned char write_bytes[5] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
|
2004-10-15 21:41:46 +00:00
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
static void tea5767_set_clear(int byte, unsigned char bits, int set)
|
|
|
|
{
|
|
|
|
write_bytes[byte] &= ~bits;
|
|
|
|
if (set)
|
|
|
|
write_bytes[byte] |= bits;
|
|
|
|
}
|
|
|
|
|
2004-10-15 21:41:46 +00:00
|
|
|
/* tuner abstraction layer: set something to the tuner */
|
2007-07-14 11:20:31 +00:00
|
|
|
int tea5767_set(int setting, int value)
|
2004-10-15 21:41:46 +00:00
|
|
|
{
|
|
|
|
switch(setting)
|
|
|
|
{
|
2004-10-19 08:20:38 +00:00
|
|
|
case RADIO_SLEEP:
|
|
|
|
/* init values */
|
2006-10-23 19:48:42 +00:00
|
|
|
write_bytes[0] |= (1<<7); /* mute */
|
2005-09-24 09:06:31 +00:00
|
|
|
#if CONFIG_TUNER_XTAL == 32768
|
2006-10-23 19:48:42 +00:00
|
|
|
/* 32.768kHz, soft mute, stereo noise cancelling */
|
|
|
|
write_bytes[3] |= (1<<4) | (1<<3) | (1<<1);
|
2005-08-13 17:34:10 +00:00
|
|
|
#else
|
2006-10-23 19:48:42 +00:00
|
|
|
/* soft mute, stereo noise cancelling */
|
|
|
|
write_bytes[3] |= (1<<3) | (1<<1);
|
2005-08-13 17:34:10 +00:00
|
|
|
#endif
|
2006-10-23 19:48:42 +00:00
|
|
|
/* sleep / standby mode */
|
2007-07-14 11:20:31 +00:00
|
|
|
tea5767_set_clear(3, (1<<6), value);
|
2004-10-15 21:41:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_FREQUENCY:
|
2004-10-17 23:24:18 +00:00
|
|
|
{
|
|
|
|
int n;
|
2005-09-24 09:06:31 +00:00
|
|
|
#if CONFIG_TUNER_XTAL == 32768
|
|
|
|
n = (4 * (value - 225000) + 16384) / 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);
|
2007-07-14 11:20:31 +00:00
|
|
|
write_bytes[1] = n;
|
2004-10-17 23:24:18 +00:00
|
|
|
}
|
2004-10-15 21:41:46 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
case RADIO_SCAN_FREQUENCY:
|
2007-07-14 11:20:31 +00:00
|
|
|
tea5767_set(RADIO_FREQUENCY, value);
|
2007-03-16 14:40:40 +00:00
|
|
|
sleep(HZ/30);
|
2007-07-14 11:20:31 +00:00
|
|
|
return tea5767_get(RADIO_TUNED);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2004-10-15 21:41:46 +00:00
|
|
|
case RADIO_MUTE:
|
2007-07-14 11:20:31 +00:00
|
|
|
tea5767_set_clear(0, 0x80, value);
|
2004-10-15 21:41:46 +00:00
|
|
|
break;
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
case RADIO_REGION:
|
|
|
|
{
|
2010-07-26 20:15:16 +00:00
|
|
|
const struct fm_region_data *rd = &fm_region_data[value];
|
|
|
|
int deemphasis = (rd->deemphasis == 75) ? 1 : 0;
|
|
|
|
int band = (rd->freq_min == 76000000) ? 1 : 0;
|
2004-10-18 07:58:59 +00:00
|
|
|
|
2010-07-26 20:15:16 +00:00
|
|
|
tea5767_set_clear(4, (1<<6), deemphasis);
|
|
|
|
tea5767_set_clear(3, (1<<5), band);
|
2007-07-14 11:20:31 +00:00
|
|
|
break;
|
2009-02-13 03:49:17 +00:00
|
|
|
}
|
2007-07-14 11:20:31 +00:00
|
|
|
case RADIO_FORCE_MONO:
|
|
|
|
tea5767_set_clear(2, 0x08, value);
|
2006-10-05 12:40:13 +00:00
|
|
|
break;
|
2004-10-18 07:58:59 +00:00
|
|
|
default:
|
2007-03-16 14:40:40 +00:00
|
|
|
return -1;
|
2004-10-15 21:41:46 +00:00
|
|
|
}
|
2007-07-14 11:20:31 +00:00
|
|
|
|
2012-02-05 14:58:10 +00:00
|
|
|
if(setting == RADIO_SLEEP && !value)
|
|
|
|
tuner_power(true); /* wakeup */
|
2004-10-18 07:58:59 +00:00
|
|
|
fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
|
2012-02-05 14:58:10 +00:00
|
|
|
if(setting == RADIO_SLEEP && value)
|
|
|
|
tuner_power(false); /* sleep */
|
2007-03-16 14:40:40 +00:00
|
|
|
return 1;
|
2004-10-15 21:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tuner abstraction layer: read something from the tuner */
|
2007-07-14 11:20:31 +00:00
|
|
|
int tea5767_get(int setting)
|
2004-10-15 21:41:46 +00:00
|
|
|
{
|
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:
|
2010-11-05 17:04:18 +00:00
|
|
|
val = tuner_present;
|
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;
|
2010-11-11 21:13:29 +00:00
|
|
|
|
|
|
|
case RADIO_RSSI:
|
|
|
|
val = 10 + 3*(read_bytes[3] >> 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_RSSI_MIN:
|
|
|
|
val = RSSI_MIN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_RSSI_MAX:
|
|
|
|
val = RSSI_MAX;
|
|
|
|
break;
|
2004-10-15 21:41:46 +00:00
|
|
|
}
|
2007-07-14 11:20:31 +00:00
|
|
|
|
2004-10-15 21:41:46 +00:00
|
|
|
return val;
|
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2010-11-05 17:04:18 +00:00
|
|
|
void tea5767_init(void)
|
|
|
|
{
|
|
|
|
/* save binsize by only detecting presence for targets where it may be absent */
|
2010-11-05 18:21:20 +00:00
|
|
|
#if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
|
2010-11-05 17:04:18 +00:00
|
|
|
unsigned char buf[5];
|
|
|
|
unsigned char chipid;
|
|
|
|
|
|
|
|
/* init chipid register with 0xFF in case fmradio_i2c_read fails silently */
|
|
|
|
buf[3] = 0xFF;
|
|
|
|
if (fmradio_i2c_read(I2C_ADR, buf, sizeof(buf)) < 0) {
|
|
|
|
/* no i2c device detected */
|
|
|
|
tuner_present = false;
|
|
|
|
} else {
|
|
|
|
/* check chip id */
|
|
|
|
chipid = buf[3] & 0x0F;
|
|
|
|
tuner_present = (chipid == 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
void tea5767_dbg_info(struct tea5767_dbg_info *info)
|
2007-03-16 14:40:40 +00:00
|
|
|
{
|
|
|
|
fmradio_i2c_read(I2C_ADR, info->read_regs, 5);
|
|
|
|
memcpy(info->write_regs, write_bytes, 5);
|
|
|
|
}
|