2008-06-27 23:24:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
* Tuner "middleware" for Philips TEA5760UK chip
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jörg Hohensohn
|
|
|
|
*
|
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.
|
2008-06-27 23:24:34 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "tuner.h" /* tuner abstraction interface */
|
|
|
|
#include "fmradio.h"
|
|
|
|
#include "fmradio_i2c.h" /* physical interface driver */
|
|
|
|
|
2009-07-07 21:57:16 +00:00
|
|
|
#define I2C_ADR 0x22
|
|
|
|
|
2010-11-11 21:13:29 +00:00
|
|
|
/* define RSSI range */
|
|
|
|
#define RSSI_MIN 4
|
|
|
|
#define RSSI_MAX 46
|
|
|
|
|
2009-07-07 21:57:16 +00:00
|
|
|
static bool tuner_present = false;
|
|
|
|
static unsigned char write_bytes[7] = {
|
|
|
|
0x00, /* INTREG LSB */
|
|
|
|
0x80, /* FRQSET MSB */
|
|
|
|
0x00, /* FRQSET LSB */
|
|
|
|
0x08, /* TNCTRL MSB */
|
|
|
|
0xD2, /* TNCTRL LSB */
|
|
|
|
0x00, /* TESTREG MSB */
|
|
|
|
0x40 /* TESTREG LSB */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void tea5760_set_clear(int byte, unsigned char bits, int set)
|
2008-06-27 23:24:34 +00:00
|
|
|
{
|
|
|
|
write_bytes[byte] &= ~bits;
|
|
|
|
if (set)
|
|
|
|
write_bytes[byte] |= bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tuner abstraction layer: set something to the tuner */
|
2009-07-07 21:57:16 +00:00
|
|
|
int tea5760_set(int setting, int value)
|
2008-06-27 23:24:34 +00:00
|
|
|
{
|
|
|
|
switch(setting)
|
|
|
|
{
|
|
|
|
case RADIO_SLEEP:
|
2009-07-07 21:57:16 +00:00
|
|
|
if (value) {
|
|
|
|
/* sleep / standby mode */
|
|
|
|
tea5760_set_clear(3, (1<<6), 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* active mode */
|
|
|
|
tea5760_set_clear(3, (1<<6), 1);
|
|
|
|
/* disable hard mute */
|
|
|
|
tea5760_set_clear(4, (1<<7), 0);
|
|
|
|
}
|
2008-06-27 23:24:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_FREQUENCY:
|
|
|
|
{
|
|
|
|
int n;
|
2009-07-07 21:57:16 +00:00
|
|
|
|
|
|
|
/* low side injection */
|
|
|
|
tea5760_set_clear(4, (1<<4), 0);
|
2008-06-27 23:24:34 +00:00
|
|
|
n = (4 * (value - 225000) + 16384) / 32768;
|
2009-07-07 21:57:16 +00:00
|
|
|
|
|
|
|
/* set frequency in preset mode */
|
|
|
|
write_bytes[1] = (n >> 8) & 0x3F;
|
|
|
|
write_bytes[2] = n;
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_SCAN_FREQUENCY:
|
2009-07-07 21:57:16 +00:00
|
|
|
tea5760_set(RADIO_FREQUENCY, value);
|
|
|
|
sleep(40*HZ/1000);
|
|
|
|
return tea5760_get(RADIO_TUNED);
|
2008-06-27 23:24:34 +00:00
|
|
|
|
|
|
|
case RADIO_MUTE:
|
2009-07-07 21:57:16 +00:00
|
|
|
tea5760_set_clear(3, (1<<2), value);
|
2008-06-27 23:24:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_REGION:
|
2009-07-07 21:57:16 +00:00
|
|
|
{
|
2010-07-26 20:15:16 +00:00
|
|
|
const struct fm_region_data *rd = &fm_region_data[value];
|
|
|
|
int band = (rd->freq_min == 76000000) ? 1 : 0;
|
|
|
|
int deemphasis = (rd->deemphasis == 50) ? 1 : 0;
|
2008-06-27 23:24:34 +00:00
|
|
|
|
2010-07-26 20:15:16 +00:00
|
|
|
tea5760_set_clear(3, (1<<5), band);
|
|
|
|
tea5760_set_clear(4, (1<<1), deemphasis);
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
2009-07-07 21:57:16 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
case RADIO_FORCE_MONO:
|
2009-07-07 21:57:16 +00:00
|
|
|
tea5760_set_clear(4, (1<<3), value);
|
2008-06-27 23:24:34 +00:00
|
|
|
break;
|
2009-07-07 21:57:16 +00:00
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tuner abstraction layer: read something from the tuner */
|
2009-07-07 21:57:16 +00:00
|
|
|
int tea5760_get(int setting)
|
2008-06-27 23:24:34 +00:00
|
|
|
{
|
|
|
|
unsigned char read_bytes[16];
|
|
|
|
int val = -1; /* default for unsupported query */
|
|
|
|
|
|
|
|
fmradio_i2c_read(I2C_ADR, read_bytes, sizeof(read_bytes));
|
|
|
|
|
|
|
|
switch(setting)
|
|
|
|
{
|
|
|
|
case RADIO_PRESENT:
|
2009-07-07 21:57:16 +00:00
|
|
|
val = tuner_present ? 1 : 0;
|
2008-06-27 23:24:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_TUNED:
|
|
|
|
val = 0;
|
|
|
|
if (read_bytes[0] & (1<<4)) /* IF count correct */
|
|
|
|
{
|
|
|
|
val = read_bytes[8] >> 1; /* IF counter */
|
|
|
|
val = (abs(val - 0x36) < 2); /* close match */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_STEREO:
|
|
|
|
val = read_bytes[9] >> 2;
|
|
|
|
break;
|
2010-11-11 21:13:29 +00:00
|
|
|
|
|
|
|
case RADIO_RSSI:
|
|
|
|
val = (read_bytes[9] >> 4) & 0x0F;
|
|
|
|
val = 4 + (28 * val + 5) / 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_RSSI_MIN:
|
|
|
|
val = RSSI_MIN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_RSSI_MAX:
|
|
|
|
val = RSSI_MAX;
|
|
|
|
break;
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-07-07 21:57:16 +00:00
|
|
|
void tea5760_init(void)
|
2008-06-27 23:24:34 +00:00
|
|
|
{
|
2009-07-07 21:57:16 +00:00
|
|
|
unsigned char buf[16];
|
|
|
|
unsigned short manid, chipid;
|
|
|
|
|
|
|
|
/* read all registers */
|
|
|
|
fmradio_i2c_read(I2C_ADR, buf, sizeof(buf));
|
|
|
|
|
|
|
|
/* check device id */
|
|
|
|
manid = (buf[12] << 8) | buf[13];
|
|
|
|
chipid = (buf[14] << 8) | buf[15];
|
|
|
|
if ((manid == 0x202B) && (chipid == 0x5760))
|
|
|
|
{
|
|
|
|
tuner_present = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write initial values */
|
|
|
|
tea5760_set_clear(3, (1<<1), 1); /* soft mute on */
|
|
|
|
tea5760_set_clear(3, (1<<0), 1); /* stereo noise cancellation on */
|
|
|
|
fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
2009-07-07 21:57:16 +00:00
|
|
|
|
|
|
|
void tea5760_dbg_info(struct tea5760_dbg_info *info)
|
|
|
|
{
|
|
|
|
fmradio_i2c_read(I2C_ADR, info->read_regs, sizeof(info->read_regs));
|
|
|
|
memcpy(info->write_regs, write_bytes, sizeof(info->write_regs));
|
|
|
|
}
|
|
|
|
|