2007-10-02 14:57:03 +00:00
|
|
|
/* tuner-xc2028
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org)
|
2007-07-18 13:29:10 +00:00
|
|
|
* Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com)
|
|
|
|
* - frontend interface
|
2007-10-02 14:57:03 +00:00
|
|
|
* This code is placed under the terms of the GNU General Public License v2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <asm/div64.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/videodev.h>
|
|
|
|
#include <linux/delay.h>
|
2007-07-18 13:29:10 +00:00
|
|
|
#include <media/tuner.h>
|
2007-09-27 21:27:03 +00:00
|
|
|
#include <linux/mutex.h>
|
2007-10-23 18:24:06 +00:00
|
|
|
#include "tuner-i2c.h"
|
2007-10-02 14:57:03 +00:00
|
|
|
#include "tuner-xc2028.h"
|
|
|
|
|
2007-07-18 13:29:10 +00:00
|
|
|
#include <linux/dvb/frontend.h>
|
|
|
|
#include "dvb_frontend.h"
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
#define PREFIX "xc2028 "
|
|
|
|
|
|
|
|
static LIST_HEAD(xc2028_list);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
/* Firmwares used on tm5600/tm6000 + xc2028/xc3028 */
|
2007-07-18 16:33:23 +00:00
|
|
|
|
|
|
|
/* Generic firmwares */
|
|
|
|
static const char *firmware_INIT0 = "tm_xc3028_MTS_init0.fw";
|
|
|
|
static const char *firmware_8MHZ_INIT0 = "tm_xc3028_8M_MTS_init0.fw";
|
|
|
|
static const char *firmware_INIT1 = "tm_xc3028_68M_MTS_init1.fw";
|
|
|
|
|
|
|
|
/* Standard-specific firmwares */
|
|
|
|
static const char *firmware_6M = "tm_xc3028_DTV_6M.fw";
|
2007-07-27 11:24:39 +00:00
|
|
|
static const char *firmware_7M = "tm_xc3028_DTV_7M.fw";
|
|
|
|
static const char *firmware_8M = "tm_xc3028_DTV_8M.fw";
|
2007-07-18 16:33:23 +00:00
|
|
|
static const char *firmware_B = "tm_xc3028_B_PAL.fw";
|
|
|
|
static const char *firmware_DK = "tm_xc3028_DK_PAL_MTS.fw";
|
|
|
|
static const char *firmware_MN = "tm_xc3028_MN_BTSC.fw";
|
2007-10-02 14:57:03 +00:00
|
|
|
|
|
|
|
struct xc2028_data {
|
2007-10-23 18:24:06 +00:00
|
|
|
struct list_head xc2028_list;
|
|
|
|
struct tuner_i2c_props i2c_props;
|
|
|
|
int (*tuner_callback) (void *dev,
|
|
|
|
int command, int arg);
|
|
|
|
struct device *dev;
|
|
|
|
void *video_dev;
|
|
|
|
int count;
|
|
|
|
u32 frequency;
|
|
|
|
|
2007-07-18 13:29:10 +00:00
|
|
|
v4l2_std_id firm_type; /* video stds supported
|
|
|
|
by current firmware */
|
|
|
|
fe_bandwidth_t bandwidth; /* Firmware bandwidth:
|
|
|
|
6M, 7M or 8M */
|
|
|
|
int need_load_generic; /* The generic firmware
|
|
|
|
were loaded? */
|
|
|
|
enum tuner_mode mode;
|
|
|
|
struct i2c_client *i2c_client;
|
2007-10-23 18:24:06 +00:00
|
|
|
|
|
|
|
struct mutex lock;
|
2007-10-02 14:57:03 +00:00
|
|
|
};
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
#define i2c_send(rc, priv, buf, size) \
|
|
|
|
if (size != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size))) \
|
|
|
|
tuner_info("i2c output error: rc = %d (should be %d)\n", \
|
2007-10-02 14:57:03 +00:00
|
|
|
rc, (int)size);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
#define i2c_rcv(rc, priv, buf, size) \
|
|
|
|
if (size != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size))) \
|
|
|
|
tuner_info("i2c input error: rc = %d (should be %d)\n", \
|
2007-10-02 14:57:03 +00:00
|
|
|
rc, (int)size);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
#define send_seq(priv, data...) \
|
2007-10-02 14:57:03 +00:00
|
|
|
{ int rc; \
|
2007-10-23 18:24:06 +00:00
|
|
|
static u8 _val[] = data; \
|
2007-10-02 14:57:03 +00:00
|
|
|
if (sizeof(_val) != \
|
2007-10-23 18:24:06 +00:00
|
|
|
(rc = tuner_i2c_xfer_send (&priv->i2c_props, \
|
|
|
|
_val, sizeof(_val)))) { \
|
|
|
|
tuner_info("Error on line %d: %d\n",__LINE__,rc); \
|
|
|
|
return -EINVAL; \
|
2007-10-02 14:57:03 +00:00
|
|
|
} \
|
|
|
|
msleep (10); \
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int xc2028_get_reg(struct xc2028_data *priv, u16 reg)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned char buf[1];
|
2007-10-23 18:24:06 +00:00
|
|
|
|
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
|
|
|
buf[0]= reg;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
i2c_send(rc, priv, buf, sizeof(buf));
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
|
|
|
return rc;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
i2c_rcv(rc, priv, buf, 2);
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return (buf[1])|(buf[0]<<8);
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int load_firmware (struct dvb_frontend *fe, const char *name)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
2007-10-02 14:57:03 +00:00
|
|
|
const struct firmware *fw=NULL;
|
|
|
|
unsigned char *p, *endp;
|
|
|
|
int len=0, rc=0;
|
|
|
|
static const char firmware_ver[] = "tm6000/xcv v1";
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
tuner_info("Loading firmware %s\n", name);
|
|
|
|
rc = request_firmware(&fw, name, priv->dev);
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc < 0) {
|
2007-07-18 16:33:23 +00:00
|
|
|
if (rc==-ENOENT)
|
|
|
|
tuner_info("Error: firmware %s not found.\n", name);
|
|
|
|
else
|
|
|
|
tuner_info("Error %d while requesting firmware %s \n", rc, name);
|
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
p=fw->data;
|
|
|
|
endp=p+fw->size;
|
|
|
|
|
|
|
|
if(fw->size==0) {
|
|
|
|
tuner_info("Error: firmware size is zero!\n");
|
|
|
|
rc=-EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (fw->size<sizeof(firmware_ver)-1) {
|
|
|
|
/* Firmware is incorrect */
|
|
|
|
tuner_info("Error: firmware size is less than header (%d<%d)!\n",
|
|
|
|
(int)fw->size,(int)sizeof(firmware_ver)-1);
|
|
|
|
rc=-EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(p,firmware_ver,sizeof(firmware_ver)-1)) {
|
|
|
|
/* Firmware is incorrect */
|
|
|
|
tuner_info("Error: firmware is not for tm5600/6000 + Xcv2028/3028!\n");
|
|
|
|
rc=-EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
p+=sizeof(firmware_ver)-1;
|
|
|
|
|
|
|
|
while(p<endp) {
|
|
|
|
if ((*p) & 0x80) {
|
|
|
|
/* Special callback command received */
|
2007-10-23 18:24:06 +00:00
|
|
|
rc = priv->tuner_callback(priv->video_dev,
|
2007-10-02 14:57:03 +00:00
|
|
|
XC2028_TUNER_RESET, (*p)&0x7f);
|
|
|
|
if (rc<0) {
|
|
|
|
tuner_info("Error at RESET code %d\n",
|
|
|
|
(*p)&0x7f);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len=*p;
|
|
|
|
p++;
|
|
|
|
if (p+len+1>endp) {
|
|
|
|
/* Firmware is incorrect */
|
|
|
|
tuner_info("Error: firmware is truncated!\n");
|
|
|
|
rc=-EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (len<=0) {
|
|
|
|
tuner_info("Error: firmware file is corrupted!\n");
|
|
|
|
rc=-EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
i2c_send(rc, priv, p, len);
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
|
|
|
goto err;
|
|
|
|
p+=len;
|
|
|
|
|
|
|
|
if (*p)
|
|
|
|
msleep(*p);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
release_firmware(fw);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
|
|
|
|
v4l2_std_id std,
|
2007-07-18 13:29:10 +00:00
|
|
|
fe_bandwidth_t bandwidth)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
2007-10-02 14:57:03 +00:00
|
|
|
int rc, version;
|
|
|
|
const char *name;
|
2007-07-18 13:29:10 +00:00
|
|
|
int change_digital_bandwidth;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info( "I am in mode %u and I should switch to mode %i\n",
|
|
|
|
priv->mode, new_mode);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
|
|
|
/* first of all, determine whether we have switched the mode */
|
2007-10-23 18:24:06 +00:00
|
|
|
if(new_mode != priv->mode) {
|
|
|
|
priv->mode = new_mode;
|
|
|
|
priv->need_load_generic = 1;
|
2007-07-18 13:29:10 +00:00
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
change_digital_bandwidth = (priv->mode == T_DIGITAL_TV
|
|
|
|
&& bandwidth != priv->bandwidth) ? 1 : 0;
|
|
|
|
tuner_info("old bandwidth %u, new bandwidth %u\n", priv->bandwidth,
|
2007-07-18 13:29:10 +00:00
|
|
|
bandwidth);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
if (priv->need_load_generic) {
|
|
|
|
if (priv->bandwidth==8)
|
2007-07-18 13:29:10 +00:00
|
|
|
name = firmware_8MHZ_INIT0;
|
2007-07-18 16:33:23 +00:00
|
|
|
else
|
|
|
|
name = firmware_INIT0;
|
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
/* Reset is needed before loading firmware */
|
2007-10-23 18:24:06 +00:00
|
|
|
rc = priv->tuner_callback(priv->video_dev,
|
|
|
|
XC2028_TUNER_RESET, 0);
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
|
|
|
return rc;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
rc = load_firmware(fe,name);
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
|
|
|
return rc;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->need_load_generic=0;
|
|
|
|
priv->firm_type=0;
|
|
|
|
if(priv->mode == T_DIGITAL_TV) {
|
2007-07-18 13:29:10 +00:00
|
|
|
change_digital_bandwidth=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("I should change bandwidth %u\n",
|
2007-07-18 13:29:10 +00:00
|
|
|
change_digital_bandwidth);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
/* FIXME: t->std makes no sense here */
|
2007-07-18 13:29:10 +00:00
|
|
|
if (change_digital_bandwidth) {
|
|
|
|
switch(bandwidth) {
|
|
|
|
case BANDWIDTH_8_MHZ:
|
2007-10-23 18:24:06 +00:00
|
|
|
std = V4L2_STD_DTV_8MHZ;
|
2007-07-18 13:29:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BANDWIDTH_7_MHZ:
|
2007-10-23 18:24:06 +00:00
|
|
|
std = V4L2_STD_DTV_7MHZ;
|
2007-07-18 13:29:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BANDWIDTH_6_MHZ:
|
2007-10-23 18:24:06 +00:00
|
|
|
std = V4L2_STD_DTV_6MHZ;
|
2007-07-18 13:29:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
tuner_info("error: bandwidth not supported.\n");
|
|
|
|
};
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->bandwidth = bandwidth;
|
2007-10-02 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
if (priv->firm_type & std) {
|
2007-07-18 16:33:23 +00:00
|
|
|
tuner_info("xc3028: no need to load a std-specific firmware.\n");
|
2007-10-02 14:57:03 +00:00
|
|
|
return 0;
|
2007-07-18 16:33:23 +00:00
|
|
|
}
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
rc = load_firmware(fe,firmware_INIT1);
|
2007-07-18 13:26:38 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
if (std & V4L2_STD_MN)
|
2007-10-02 14:57:03 +00:00
|
|
|
name=firmware_MN;
|
2007-10-23 18:24:06 +00:00
|
|
|
else if (std & V4L2_STD_DTV_6MHZ)
|
2007-07-18 13:29:10 +00:00
|
|
|
name=firmware_6M;
|
2007-10-23 18:24:06 +00:00
|
|
|
else if (std & V4L2_STD_DTV_7MHZ)
|
2007-07-18 13:29:10 +00:00
|
|
|
name=firmware_7M;
|
2007-10-23 18:24:06 +00:00
|
|
|
else if (std & V4L2_STD_DTV_8MHZ)
|
2007-07-18 13:29:10 +00:00
|
|
|
name=firmware_8M;
|
2007-10-23 18:24:06 +00:00
|
|
|
else if (std & V4L2_STD_PAL_B)
|
2007-07-18 13:29:10 +00:00
|
|
|
name=firmware_B;
|
2007-10-02 14:57:03 +00:00
|
|
|
else
|
|
|
|
name=firmware_DK;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("loading firmware named %s.\n", name);
|
|
|
|
rc = load_firmware(fe, name);
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
|
|
|
return rc;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
version = xc2028_get_reg(priv, 0x4);
|
2007-10-02 14:57:03 +00:00
|
|
|
tuner_info("Firmware version is %d.%d\n",
|
|
|
|
(version>>4)&0x0f,(version)&0x0f);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->firm_type=std;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
2007-09-27 21:27:03 +00:00
|
|
|
int frq_lock, signal=0;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
mutex_lock(&priv->lock);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
*strength = 0;
|
|
|
|
|
|
|
|
frq_lock = xc2028_get_reg(priv, 0x2);
|
2007-09-27 21:27:03 +00:00
|
|
|
if (frq_lock<=0)
|
|
|
|
goto ret;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
|
|
|
/* Frequency is locked. Return signal quality */
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
signal = xc2028_get_reg(priv, 0x40);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-09-27 21:27:03 +00:00
|
|
|
if(signal<=0) {
|
|
|
|
signal=frq_lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret:
|
2007-10-23 18:24:06 +00:00
|
|
|
mutex_unlock(&priv->lock);
|
|
|
|
|
|
|
|
*strength = signal;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
return 0;
|
2007-10-02 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DIV 15625
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */,
|
|
|
|
enum tuner_mode new_mode,
|
|
|
|
v4l2_std_id std,
|
|
|
|
fe_bandwidth_t bandwidth)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
|
|
|
int rc=-EINVAL;
|
2007-10-02 14:57:03 +00:00
|
|
|
unsigned char buf[5];
|
2007-07-18 13:29:10 +00:00
|
|
|
u32 div, offset = 0;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
|
|
|
|
2007-07-19 02:14:25 +00:00
|
|
|
/* HACK: It seems that specific firmware need to be reloaded
|
|
|
|
when freq is changed */
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
mutex_lock(&priv->lock);
|
2007-09-27 21:27:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->firm_type=0;
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
/* Reset GPIO 1 */
|
2007-10-23 18:24:06 +00:00
|
|
|
rc = priv->tuner_callback(priv->video_dev, XC2028_TUNER_RESET, 0);
|
|
|
|
if (rc<0)
|
|
|
|
goto ret;
|
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
msleep(10);
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("should set frequency %d kHz)\n", freq / 1000);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
if (check_firmware(fe, new_mode, std, bandwidth)<0)
|
2007-09-27 21:27:03 +00:00
|
|
|
goto ret;
|
2007-07-18 16:33:23 +00:00
|
|
|
|
2007-07-19 02:14:25 +00:00
|
|
|
if(new_mode == T_DIGITAL_TV)
|
|
|
|
offset = 2750000;
|
2007-07-18 16:33:23 +00:00
|
|
|
|
2007-07-19 02:14:25 +00:00
|
|
|
div = (freq - offset + DIV/2)/DIV;
|
2007-07-18 16:33:23 +00:00
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
/* CMD= Set frequency */
|
2007-10-23 18:24:06 +00:00
|
|
|
send_seq(priv, {0x00, 0x02, 0x00, 0x00});
|
|
|
|
rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
|
|
|
|
if (rc<0)
|
|
|
|
goto ret;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
|
|
|
msleep(10);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
buf[0]= 0xff & (div>>24);
|
|
|
|
buf[1]= 0xff & (div>>16);
|
|
|
|
buf[2]= 0xff & (div>>8);
|
|
|
|
buf[3]= 0xff & (div);
|
|
|
|
buf[4]= 0;
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
i2c_send(rc, priv, buf, sizeof(buf));
|
2007-10-02 14:57:03 +00:00
|
|
|
if (rc<0)
|
2007-09-27 21:27:03 +00:00
|
|
|
goto ret;
|
2007-10-02 14:57:03 +00:00
|
|
|
msleep(100);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->frequency=freq;
|
|
|
|
|
2007-10-02 14:57:03 +00:00
|
|
|
printk("divider= %02x %02x %02x %02x (freq=%d.%02d)\n",
|
|
|
|
buf[1],buf[2],buf[3],buf[4],
|
2007-10-23 18:24:06 +00:00
|
|
|
freq / 1000000, (freq%1000000)/10000);
|
2007-09-27 21:27:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
rc=0;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
ret:
|
|
|
|
mutex_unlock(&priv->lock);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
return rc;
|
2007-07-18 13:29:10 +00:00
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int xc2028_set_tv_freq(struct dvb_frontend *fe,
|
|
|
|
struct analog_parameters *p)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
return generic_set_tv_freq(fe, 62500l*p->frequency, T_ANALOG_TV,
|
|
|
|
p->std,
|
|
|
|
BANDWIDTH_8_MHZ /* NOT USED */);
|
|
|
|
}
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int xc2028_set_params(struct dvb_frontend *fe,
|
|
|
|
struct dvb_frontend_parameters *p)
|
2007-10-02 14:57:03 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
2007-10-02 14:57:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
/* FIXME: Only OFDM implemented */
|
|
|
|
if (fe->ops.info.type != FE_OFDM) {
|
|
|
|
tuner_info ("DTV type not implemented.\n");
|
|
|
|
return -EINVAL;
|
2007-10-02 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
return generic_set_tv_freq(fe, p->frequency, T_DIGITAL_TV,
|
|
|
|
0, /* NOT USED */
|
|
|
|
p->u.ofdm.bandwidth);
|
2007-10-02 14:57:03 +00:00
|
|
|
|
|
|
|
}
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int xc2028_dvb_release(struct dvb_frontend *fe)
|
2007-07-18 13:29:10 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
|
|
|
|
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->count--;
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
if (!priv->count)
|
|
|
|
kfree (priv);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
|
2007-07-18 13:29:10 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv = fe->tuner_priv;
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
tuner_info("%s called\n", __FUNCTION__);
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
*frequency = priv->frequency;
|
2007-07-18 13:29:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
|
2007-07-18 13:29:10 +00:00
|
|
|
.info = {
|
|
|
|
.name = "Xceive XC3028",
|
|
|
|
.frequency_min = 42000000,
|
|
|
|
.frequency_max = 864000000,
|
|
|
|
.frequency_step = 50000,
|
|
|
|
},
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
.set_analog_params = xc2028_set_tv_freq,
|
|
|
|
.release = xc2028_dvb_release,
|
|
|
|
.get_frequency = xc2028_get_frequency,
|
|
|
|
.get_rf_strength = xc2028_signal,
|
|
|
|
.set_params = xc2028_set_params,
|
2007-07-18 13:29:10 +00:00
|
|
|
|
|
|
|
// int (*sleep)(struct dvb_frontend *fe);
|
|
|
|
// int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
|
|
|
|
// int (*get_status)(struct dvb_frontend *fe, u32 *status);
|
|
|
|
};
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter* i2c_adap,
|
|
|
|
u8 i2c_addr, struct device *dev, void *video_dev,
|
|
|
|
int (*tuner_callback) (void *dev, int command,int arg))
|
2007-07-18 13:29:10 +00:00
|
|
|
{
|
2007-10-23 18:24:06 +00:00
|
|
|
struct xc2028_data *priv;
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
printk( KERN_INFO PREFIX "Xcv2028/3028 init called!\n");
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
if (NULL == dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (NULL == video_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!tuner_callback) {
|
|
|
|
printk( KERN_ERR PREFIX "No tuner callback!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(priv, &xc2028_list, xc2028_list) {
|
|
|
|
if (priv->dev == dev) {
|
|
|
|
dev = NULL;
|
|
|
|
priv->count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (priv == NULL)
|
|
|
|
return -ENOMEM;
|
2007-07-18 13:29:10 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
fe->tuner_priv = priv;
|
2007-09-27 21:27:03 +00:00
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
priv->bandwidth=BANDWIDTH_6_MHZ;
|
|
|
|
priv->need_load_generic=1;
|
|
|
|
priv->mode = T_UNINITIALIZED;
|
|
|
|
priv->i2c_props.addr = i2c_addr;
|
|
|
|
priv->i2c_props.adap = i2c_adap;
|
|
|
|
priv->dev = dev;
|
|
|
|
priv->video_dev = video_dev;
|
|
|
|
priv->tuner_callback = tuner_callback;
|
|
|
|
|
|
|
|
mutex_init(&priv->lock);
|
|
|
|
|
|
|
|
list_add_tail(&priv->xc2028_list,&xc2028_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
|
|
|
|
sizeof(xc2028_dvb_tuner_ops));
|
|
|
|
|
|
|
|
tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-09-27 21:27:03 +00:00
|
|
|
|
2007-07-18 13:29:10 +00:00
|
|
|
EXPORT_SYMBOL(xc2028_attach);
|
|
|
|
|
2007-10-23 18:24:06 +00:00
|
|
|
MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
|
|
|
|
MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
|
|
|
|
MODULE_LICENSE("GPL");
|