Commit 215b95ba authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB (6430): Convert tuner-xc2028 driver to the newer hybrid approach

This changeset converts tuner-xc2028 to the newer hybrid approach. It also
prevents creating twice the xc3028 private struct by both DVB and V4L parts.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 3b20532c
...@@ -69,6 +69,7 @@ source "drivers/media/common/Kconfig" ...@@ -69,6 +69,7 @@ source "drivers/media/common/Kconfig"
config VIDEO_TUNER config VIDEO_TUNER
tristate tristate
depends on I2C depends on I2C
select TUNER_XC2028 if !VIDEO_TUNER_CUSTOMIZE
select TUNER_MT20XX if !VIDEO_TUNER_CUSTOMIZE select TUNER_MT20XX if !VIDEO_TUNER_CUSTOMIZE
select TUNER_TDA8290 if !VIDEO_TUNER_CUSTOMIZE select TUNER_TDA8290 if !VIDEO_TUNER_CUSTOMIZE
select TUNER_TEA5761 if !VIDEO_TUNER_CUSTOMIZE select TUNER_TEA5761 if !VIDEO_TUNER_CUSTOMIZE
...@@ -89,6 +90,13 @@ menuconfig VIDEO_TUNER_CUSTOMIZE ...@@ -89,6 +90,13 @@ menuconfig VIDEO_TUNER_CUSTOMIZE
if VIDEO_TUNER_CUSTOMIZE if VIDEO_TUNER_CUSTOMIZE
config TUNER_XC2028
tristate "XCeive xc2028/xc3028 tuners"
depends on I2C
default m if VIDEO_TUNER_CUSTOMIZE
help
Say Y here to include support for the xc2028/xc3028 tuners.
config TUNER_MT20XX config TUNER_MT20XX
tristate "Microtune 2032 / 2050 tuners" tristate "Microtune 2032 / 2050 tuners"
depends on I2C depends on I2C
......
...@@ -505,18 +505,6 @@ config TUNER_3036 ...@@ -505,18 +505,6 @@ config TUNER_3036
Say Y here to include support for Philips SAB3036 compatible tuners. Say Y here to include support for Philips SAB3036 compatible tuners.
If in doubt, say N. If in doubt, say N.
config TUNER_XC2028
tristate "Xceive xc2028 support for tm5600/tm6000 driver"
depends on I2C
select VIDEO_TUNER
help
Say Y here to include support for Xceive xc2028 tuner. This is
required on a few tm5600/tm6000 designs. You should notice
that this module currently works only with the special
firmware versions used on those Trident chips.
If in doubt, say N.
config VIDEO_VINO config VIDEO_VINO
tristate "SGI Vino Video For Linux (EXPERIMENTAL)" tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
......
...@@ -6,10 +6,6 @@ zr36067-objs := zoran_procfs.o zoran_device.o \ ...@@ -6,10 +6,6 @@ zr36067-objs := zoran_procfs.o zoran_device.o \
zoran_driver.o zoran_card.o zoran_driver.o zoran_card.o
tuner-objs := tuner-core.o tuner-types.o tda9887.o tuner-objs := tuner-core.o tuner-types.o tda9887.o
ifneq ($(CONFIG_TUNER_XC2028),)
tuner-objs += tuner-xc2028.o
endif
msp3400-objs := msp3400-driver.o msp3400-kthreads.o msp3400-objs := msp3400-driver.o msp3400-kthreads.o
obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o \ obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o \
...@@ -85,6 +81,7 @@ obj-$(CONFIG_TUNER_3036) += tuner-3036.o ...@@ -85,6 +81,7 @@ obj-$(CONFIG_TUNER_3036) += tuner-3036.o
obj-$(CONFIG_VIDEO_TUNER) += tuner.o obj-$(CONFIG_VIDEO_TUNER) += tuner.o
obj-$(CONFIG_TUNER_XC2028) += tuner-xc2028.o
obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o
obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o
obj-$(CONFIG_TUNER_TDA8290) += tda8290.o obj-$(CONFIG_TUNER_TDA8290) += tda8290.o
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "tda8290.h" #include "tda8290.h"
#include "tea5761.h" #include "tea5761.h"
#include "tea5767.h" #include "tea5767.h"
#include "tuner-xc2028.h"
#include "tuner-simple.h" #include "tuner-simple.h"
#define UNSET (-1U) #define UNSET (-1U)
...@@ -323,8 +324,17 @@ static void set_type(struct i2c_client *c, unsigned int type, ...@@ -323,8 +324,17 @@ static void set_type(struct i2c_client *c, unsigned int type,
attach_simple_tuner(t); attach_simple_tuner(t);
break; break;
case TUNER_XC2028: case TUNER_XC2028:
xc2028_tuner_init(c); {
int rc=xc2028_attach(&t->fe, t->i2c.adapter, t->i2c.addr,
&c->dev, c->adapter->algo_data,
t->tuner_callback);
if (rc<0) {
t->type = TUNER_ABSENT;
t->mode_mask = T_UNINITIALIZED;
return;
}
break; break;
}
case TUNER_TDA9887: case TUNER_TDA9887:
tda9887_tuner_init(t); tda9887_tuner_init(t);
break; break;
......
...@@ -70,8 +70,6 @@ struct tuner { ...@@ -70,8 +70,6 @@ struct tuner {
struct tuner_operations ops; struct tuner_operations ops;
}; };
extern int xc2028_tuner_init(struct i2c_client *c);
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
extern int tda9887_tuner_init(struct tuner *t); extern int tda9887_tuner_init(struct tuner *t);
......
...@@ -13,16 +13,15 @@ ...@@ -13,16 +13,15 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <media/tuner.h> #include <media/tuner.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include "tuner-driver.h" #include "tuner-i2c.h"
#include "tuner-xc2028.h" #include "tuner-xc2028.h"
#include <linux/dvb/frontend.h> #include <linux/dvb/frontend.h>
#include "dvb_frontend.h" #include "dvb_frontend.h"
/* digital TV standards */ #define PREFIX "xc2028 "
#define V4L2_STD_DTV_6MHZ ((v4l2_std_id)0x04000000)
#define V4L2_STD_DTV_7MHZ ((v4l2_std_id)0x08000000) static LIST_HEAD(xc2028_list);
#define V4L2_STD_DTV_8MHZ ((v4l2_std_id)0x10000000)
/* Firmwares used on tm5600/tm6000 + xc2028/xc3028 */ /* Firmwares used on tm5600/tm6000 + xc2028/xc3028 */
...@@ -40,6 +39,15 @@ static const char *firmware_DK = "tm_xc3028_DK_PAL_MTS.fw"; ...@@ -40,6 +39,15 @@ static const char *firmware_DK = "tm_xc3028_DK_PAL_MTS.fw";
static const char *firmware_MN = "tm_xc3028_MN_BTSC.fw"; static const char *firmware_MN = "tm_xc3028_MN_BTSC.fw";
struct xc2028_data { struct xc2028_data {
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;
v4l2_std_id firm_type; /* video stds supported v4l2_std_id firm_type; /* video stds supported
by current firmware */ by current firmware */
fe_bandwidth_t bandwidth; /* Firmware bandwidth: fe_bandwidth_t bandwidth; /* Firmware bandwidth:
...@@ -52,57 +60,60 @@ struct xc2028_data { ...@@ -52,57 +60,60 @@ struct xc2028_data {
struct mutex lock; struct mutex lock;
}; };
#define i2c_send(rc,c,buf,size) \ #define i2c_send(rc, priv, buf, size) \
if (size != (rc = i2c_master_send(c, buf, size))) \ if (size != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size))) \
tuner_warn("i2c output error: rc = %d (should be %d)\n", \ tuner_info("i2c output error: rc = %d (should be %d)\n", \
rc, (int)size); rc, (int)size);
#define i2c_rcv(rc,c,buf,size) \ #define i2c_rcv(rc, priv, buf, size) \
if (size != (rc = i2c_master_recv(c, buf, size))) \ if (size != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size))) \
tuner_warn("i2c input error: rc = %d (should be %d)\n", \ tuner_info("i2c input error: rc = %d (should be %d)\n", \
rc, (int)size); rc, (int)size);
#define send_seq(c, data...) \ #define send_seq(priv, data...) \
{ int rc; \ { int rc; \
const static u8 _val[] = data; \ static u8 _val[] = data; \
if (sizeof(_val) != \ if (sizeof(_val) != \
(rc = i2c_master_send \ (rc = tuner_i2c_xfer_send (&priv->i2c_props, \
(c, _val, sizeof(_val)))) { \ _val, sizeof(_val)))) { \
printk(KERN_ERR "Error on line %d: %d\n",__LINE__,rc); \ tuner_info("Error on line %d: %d\n",__LINE__,rc); \
return; \ return -EINVAL; \
} \ } \
msleep (10); \ msleep (10); \
} }
static int xc2028_get_reg(struct i2c_client *c, u16 reg) static int xc2028_get_reg(struct xc2028_data *priv, u16 reg)
{ {
int rc; int rc;
unsigned char buf[1]; unsigned char buf[1];
struct tuner *t = i2c_get_clientdata(c);
tuner_info("%s called\n", __FUNCTION__);
buf[0]= reg; buf[0]= reg;
i2c_send(rc, c, buf, sizeof(buf)); i2c_send(rc, priv, buf, sizeof(buf));
if (rc<0) if (rc<0)
return rc; return rc;
i2c_rcv(rc, c, buf, 2); i2c_rcv(rc, priv, buf, 2);
if (rc<0) if (rc<0)
return rc; return rc;
return (buf[1])|(buf[0]<<8); return (buf[1])|(buf[0]<<8);
} }
static int load_firmware (struct i2c_client *c, const char *name) static int load_firmware (struct dvb_frontend *fe, const char *name)
{ {
struct xc2028_data *priv = fe->tuner_priv;
const struct firmware *fw=NULL; const struct firmware *fw=NULL;
struct tuner *t = i2c_get_clientdata(c);
unsigned char *p, *endp; unsigned char *p, *endp;
int len=0, rc=0; int len=0, rc=0;
static const char firmware_ver[] = "tm6000/xcv v1"; static const char firmware_ver[] = "tm6000/xcv v1";
tuner_info("xc2028: Loading firmware %s\n", name); tuner_info("%s called\n", __FUNCTION__);
rc = request_firmware(&fw, name, &c->dev);
tuner_info("Loading firmware %s\n", name);
rc = request_firmware(&fw, name, priv->dev);
if (rc < 0) { if (rc < 0) {
if (rc==-ENOENT) if (rc==-ENOENT)
tuner_info("Error: firmware %s not found.\n", name); tuner_info("Error: firmware %s not found.\n", name);
...@@ -138,7 +149,7 @@ static int load_firmware (struct i2c_client *c, const char *name) ...@@ -138,7 +149,7 @@ static int load_firmware (struct i2c_client *c, const char *name)
while(p<endp) { while(p<endp) {
if ((*p) & 0x80) { if ((*p) & 0x80) {
/* Special callback command received */ /* Special callback command received */
rc = t->tuner_callback(c->adapter->algo_data, rc = priv->tuner_callback(priv->video_dev,
XC2028_TUNER_RESET, (*p)&0x7f); XC2028_TUNER_RESET, (*p)&0x7f);
if (rc<0) { if (rc<0) {
tuner_info("Error at RESET code %d\n", tuner_info("Error at RESET code %d\n",
...@@ -162,7 +173,7 @@ static int load_firmware (struct i2c_client *c, const char *name) ...@@ -162,7 +173,7 @@ static int load_firmware (struct i2c_client *c, const char *name)
goto err; goto err;
} }
i2c_send(rc, c, p, len); i2c_send(rc, priv, p, len);
if (rc<0) if (rc<0)
goto err; goto err;
p+=len; p+=len;
...@@ -179,171 +190,173 @@ err: ...@@ -179,171 +190,173 @@ err:
return rc; return rc;
} }
static int check_firmware(struct i2c_client *c, enum tuner_mode new_mode, static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
v4l2_std_id std,
fe_bandwidth_t bandwidth) fe_bandwidth_t bandwidth)
{ {
struct xc2028_data *priv = fe->tuner_priv;
int rc, version; int rc, version;
struct tuner *t = i2c_get_clientdata(c);
struct xc2028_data *xc2028 = t->priv;
const char *name; const char *name;
int change_digital_bandwidth; int change_digital_bandwidth;
if (!t->tuner_callback) { tuner_info("%s called\n", __FUNCTION__);
printk(KERN_ERR "xc2028: need tuner_callback to load firmware\n");
return -EINVAL;
}
printk(KERN_INFO "xc2028: I am in mode %u and I should switch to mode %i\n", tuner_info( "I am in mode %u and I should switch to mode %i\n",
xc2028->mode, new_mode); priv->mode, new_mode);
/* first of all, determine whether we have switched the mode */ /* first of all, determine whether we have switched the mode */
if(new_mode != xc2028->mode) { if(new_mode != priv->mode) {
xc2028->mode = new_mode; priv->mode = new_mode;
xc2028->need_load_generic = 1; priv->need_load_generic = 1;
} }
change_digital_bandwidth = (xc2028->mode == T_DIGITAL_TV change_digital_bandwidth = (priv->mode == T_DIGITAL_TV
&& bandwidth != xc2028->bandwidth) ? 1 : 0; && bandwidth != priv->bandwidth) ? 1 : 0;
tuner_info("xc2028: old bandwidth %u, new bandwidth %u\n", xc2028->bandwidth, tuner_info("old bandwidth %u, new bandwidth %u\n", priv->bandwidth,
bandwidth); bandwidth);
if (xc2028->need_load_generic) { if (priv->need_load_generic) {
if (xc2028->bandwidth==8) if (priv->bandwidth==8)
name = firmware_8MHZ_INIT0; name = firmware_8MHZ_INIT0;
else else
name = firmware_INIT0; name = firmware_INIT0;
/* Reset is needed before loading firmware */ /* Reset is needed before loading firmware */
rc = t->tuner_callback(c->adapter->algo_data, rc = priv->tuner_callback(priv->video_dev,
XC2028_TUNER_RESET, 0); XC2028_TUNER_RESET, 0);
if (rc<0) if (rc<0)
return rc; return rc;
rc = load_firmware(c,name); rc = load_firmware(fe,name);
if (rc<0) if (rc<0)
return rc; return rc;
xc2028->need_load_generic=0; priv->need_load_generic=0;
xc2028->firm_type=0; priv->firm_type=0;
if(xc2028->mode == T_DIGITAL_TV) { if(priv->mode == T_DIGITAL_TV) {
change_digital_bandwidth=1; change_digital_bandwidth=1;
} }
} }
tuner_info("xc2028: I should change bandwidth %u\n", tuner_info("I should change bandwidth %u\n",
change_digital_bandwidth); change_digital_bandwidth);
/* FIXME: t->std makes no sense here */
if (change_digital_bandwidth) { if (change_digital_bandwidth) {
switch(bandwidth) { switch(bandwidth) {
case BANDWIDTH_8_MHZ: case BANDWIDTH_8_MHZ:
t->std = V4L2_STD_DTV_8MHZ; std = V4L2_STD_DTV_8MHZ;
break; break;
case BANDWIDTH_7_MHZ: case BANDWIDTH_7_MHZ:
t->std = V4L2_STD_DTV_7MHZ; std = V4L2_STD_DTV_7MHZ;
break; break;
case BANDWIDTH_6_MHZ: case BANDWIDTH_6_MHZ:
t->std = V4L2_STD_DTV_6MHZ; std = V4L2_STD_DTV_6MHZ;
break; break;
default: default:
tuner_info("error: bandwidth not supported.\n"); tuner_info("error: bandwidth not supported.\n");
}; };
xc2028->bandwidth = bandwidth; priv->bandwidth = bandwidth;
} }
if (xc2028->firm_type & t->std) { if (priv->firm_type & std) {
tuner_info("xc3028: no need to load a std-specific firmware.\n"); tuner_info("xc3028: no need to load a std-specific firmware.\n");
return 0; return 0;
} }
rc = load_firmware(c,firmware_INIT1); rc = load_firmware(fe,firmware_INIT1);
if (t->std & V4L2_STD_MN) if (std & V4L2_STD_MN)
name=firmware_MN; name=firmware_MN;
else if (t->std & V4L2_STD_DTV_6MHZ) else if (std & V4L2_STD_DTV_6MHZ)
name=firmware_6M; name=firmware_6M;
else if (t->std & V4L2_STD_DTV_7MHZ) else if (std & V4L2_STD_DTV_7MHZ)
name=firmware_7M; name=firmware_7M;
else if (t->std & V4L2_STD_DTV_8MHZ) else if (std & V4L2_STD_DTV_8MHZ)
name=firmware_8M; name=firmware_8M;
else if (t->std & V4L2_STD_PAL_B) else if (std & V4L2_STD_PAL_B)
name=firmware_B; name=firmware_B;
else else
name=firmware_DK; name=firmware_DK;
tuner_info("xc2028: loading firmware named %s.\n", name); tuner_info("loading firmware named %s.\n", name);
rc = load_firmware(c, name); rc = load_firmware(fe, name);
if (rc<0) if (rc<0)
return rc; return rc;
version = xc2028_get_reg(c, 0x4); version = xc2028_get_reg(priv, 0x4);
tuner_info("Firmware version is %d.%d\n", tuner_info("Firmware version is %d.%d\n",
(version>>4)&0x0f,(version)&0x0f); (version>>4)&0x0f,(version)&0x0f);
xc2028->firm_type=t->std; priv->firm_type=std;
return 0; return 0;
} }
static int xc2028_signal(struct i2c_client *c) static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
{ {
struct tuner *t = i2c_get_clientdata(c); struct xc2028_data *priv = fe->tuner_priv;
struct xc2028_data *xc2028 = t->priv;
int frq_lock, signal=0; int frq_lock, signal=0;
mutex_lock(&xc2028->lock); tuner_info("%s called\n", __FUNCTION__);
mutex_lock(&priv->lock);
printk(KERN_INFO "xc2028: %s called\n", __FUNCTION__); *strength = 0;
frq_lock = xc2028_get_reg(c, 0x2); frq_lock = xc2028_get_reg(priv, 0x2);
if (frq_lock<=0) if (frq_lock<=0)
goto ret; goto ret;
/* Frequency is locked. Return signal quality */ /* Frequency is locked. Return signal quality */
signal = xc2028_get_reg(c, 0x40); signal = xc2028_get_reg(priv, 0x40);
if(signal<=0) { if(signal<=0) {
signal=frq_lock; signal=frq_lock;
} }
ret: ret:
mutex_unlock(&xc2028->lock); mutex_unlock(&priv->lock);
return signal; *strength = signal;
return 0;
} }
#define DIV 15625 #define DIV 15625
static void generic_set_tv_freq(struct i2c_client *c, u32 freq /* in Hz */, static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */,
enum tuner_mode new_mode, fe_bandwidth_t bandwidth) enum tuner_mode new_mode,
v4l2_std_id std,
fe_bandwidth_t bandwidth)
{ {
int rc; struct xc2028_data *priv = fe->tuner_priv;
int rc=-EINVAL;
unsigned char buf[5]; unsigned char buf[5];
struct tuner *t = i2c_get_clientdata(c);
u32 div, offset = 0; u32 div, offset = 0;
tuner_info("%s called\n", __FUNCTION__);
/* HACK: It seems that specific firmware need to be reloaded /* HACK: It seems that specific firmware need to be reloaded
when freq is changed */ when freq is changed */
struct xc2028_data *xc2028 = t->priv;
mutex_lock(&xc2028->lock); mutex_lock(&priv->lock);
xc2028->firm_type=0; priv->firm_type=0;
/* Reset GPIO 1 */ /* Reset GPIO 1 */
if (t->tuner_callback) { rc = priv->tuner_callback(priv->video_dev, XC2028_TUNER_RESET, 0);
rc = t->tuner_callback( c->adapter->algo_data,
XC2028_TUNER_RESET, 0);
if (rc<0) if (rc<0)
goto ret; goto ret;
}
msleep(10); msleep(10);
printk("xc3028: should set frequency %d kHz)\n", freq / 1000); tuner_info("should set frequency %d kHz)\n", freq / 1000);
if (check_firmware(c, new_mode, bandwidth)<0) if (check_firmware(fe, new_mode, std, bandwidth)<0)
goto ret; goto ret;
if(new_mode == T_DIGITAL_TV) if(new_mode == T_DIGITAL_TV)
...@@ -352,13 +365,10 @@ static void generic_set_tv_freq(struct i2c_client *c, u32 freq /* in Hz */, ...@@ -352,13 +365,10 @@ static void generic_set_tv_freq(struct i2c_client *c, u32 freq /* in Hz */,
div = (freq - offset + DIV/2)/DIV; div = (freq - offset + DIV/2)/DIV;
/* CMD= Set frequency */ /* CMD= Set frequency */
send_seq(c, {0x00, 0x02, 0x00, 0x00}); send_seq(priv, {0x00, 0x02, 0x00, 0x00});
if (t->tuner_callback) { rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
rc = t->tuner_callback( c->adapter->algo_data,
XC2028_RESET_CLK, 1);
if (rc<0) if (rc<0)
goto ret; goto ret;
}
msleep(10); msleep(10);
...@@ -368,121 +378,82 @@ static void generic_set_tv_freq(struct i2c_client *c, u32 freq /* in Hz */, ...@@ -368,121 +378,82 @@ static void generic_set_tv_freq(struct i2c_client *c, u32 freq /* in Hz */,
buf[3]= 0xff & (div); buf[3]= 0xff & (div);
buf[4]= 0; buf[4]= 0;
i2c_send(rc, c, buf, sizeof(buf)); i2c_send(rc, priv, buf, sizeof(buf));
if (rc<0) if (rc<0)
goto ret; goto ret;
msleep(100); msleep(100);
priv->frequency=freq;
printk("divider= %02x %02x %02x %02x (freq=%d.%02d)\n", printk("divider= %02x %02x %02x %02x (freq=%d.%02d)\n",
buf[1],buf[2],buf[3],buf[4], buf[1],buf[2],buf[3],buf[4],
freq / 16, freq % 16 * 100 / 16); freq / 1000000, (freq%1000000)/10000);
ret:
mutex_unlock(&xc2028->lock);
}
rc=0;
static void set_tv_freq(struct i2c_client *c, unsigned int freq) ret:
{ mutex_unlock(&priv->lock);
printk(KERN_INFO "xc2028: %s called\n", __FUNCTION__);
generic_set_tv_freq(c, freq * 62500l, T_ANALOG_TV, return rc;
BANDWIDTH_8_MHZ /* unimportant */);
} }
static void xc2028_release(struct i2c_client *c) static int xc2028_set_tv_freq(struct dvb_frontend *fe,
struct analog_parameters *p)
{ {
struct tuner *t = i2c_get_clientdata(c); struct xc2028_data *priv = fe->tuner_priv;
kfree(t->priv);
t->priv = NULL;
}
static struct tuner_operations tea5767_tuner_ops = {
.set_tv_freq = set_tv_freq,
.has_signal = xc2028_signal,
.release = xc2028_release,
// .is_stereo = xc2028_stereo,
};
tuner_info("%s called\n", __FUNCTION__);
static int init=0; return generic_set_tv_freq(fe, 62500l*p->frequency, T_ANALOG_TV,
p->std,
BANDWIDTH_8_MHZ /* NOT USED */);
}
int xc2028_tuner_init(struct i2c_client *c) static int xc2028_set_params(struct dvb_frontend *fe,
struct dvb_frontend_parameters *p)
{ {
struct tuner *t = i2c_get_clientdata(c); struct xc2028_data *priv = fe->tuner_priv;
int version = xc2028_get_reg(c, 0x4);
int prd_id = xc2028_get_reg(c, 0x8);
struct xc2028_data *xc2028;
tuner_info("Xcv2028/3028 init called!\n"); tuner_info("%s called\n", __FUNCTION__);
if (init) { /* FIXME: Only OFDM implemented */
printk (KERN_ERR "Module already initialized!\n"); if (fe->ops.info.type != FE_OFDM) {
return 0; tuner_info ("DTV type not implemented.\n");
return -EINVAL;
} }
init++;
xc2028 = kzalloc(sizeof(*xc2028), GFP_KERNEL);
if (!xc2028)
return -ENOMEM;
t->priv = xc2028;
xc2028->bandwidth=BANDWIDTH_6_MHZ;
xc2028->need_load_generic=1;
xc2028->mode = T_UNINITIALIZED;
mutex_init(&xc2028->lock);
/* FIXME: Check where t->priv will be freed */
if (version<0) return generic_set_tv_freq(fe, p->frequency, T_DIGITAL_TV,
version=0; 0, /* NOT USED */
p->u.ofdm.bandwidth);
if (prd_id<0)
prd_id=0;
strlcpy(c->name, "xc2028", sizeof(c->name));
tuner_info("type set to %d (%s, hw ver=%d.%d, fw ver=%d.%d, id=0x%04x)\n",
t->type, c->name,
(version>>12)&0x0f,(version>>8)&0x0f,
(version>>4)&0x0f,(version)&0x0f, prd_id);
memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations));
return 0;
} }
static int xc3028_set_params(struct dvb_frontend *fe, static int xc2028_dvb_release(struct dvb_frontend *fe)
struct dvb_frontend_parameters *p)
{ {
struct i2c_client *c = fe->tuner_priv; struct xc2028_data *priv = fe->tuner_priv;
printk(KERN_INFO "xc2028: %s called\n", __FUNCTION__); tuner_info("%s called\n", __FUNCTION__);
generic_set_tv_freq(c, p->frequency, T_DIGITAL_TV, priv->count--;
p->u.ofdm.bandwidth);
if (!priv->count)
kfree (priv);
return 0; return 0;
} }
static int xc3028_dvb_release(struct dvb_frontend *fe) static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
{ {
printk(KERN_INFO "xc2028: %s called\n", __FUNCTION__); struct xc2028_data *priv = fe->tuner_priv;
fe->tuner_priv = NULL;
return 0; tuner_info("%s called\n", __FUNCTION__);
}
static int xc3028_dvb_init(struct dvb_frontend *fe) *frequency = priv->frequency;
{
printk(KERN_INFO "xc2028: %s called\n", __FUNCTION__);
return 0; return 0;
} }
static const struct dvb_tuner_ops xc3028_dvb_tuner_ops = { static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
.info = { .info = {
.name = "Xceive XC3028", .name = "Xceive XC3028",
.frequency_min = 42000000, .frequency_min = 42000000,
...@@ -490,33 +461,74 @@ static const struct dvb_tuner_ops xc3028_dvb_tuner_ops = { ...@@ -490,33 +461,74 @@ static const struct dvb_tuner_ops xc3028_dvb_tuner_ops = {
.frequency_step = 50000, .frequency_step = 50000,
}, },
.release = xc3028_dvb_release, .set_analog_params = xc2028_set_tv_freq,
.init = xc3028_dvb_init, .release = xc2028_dvb_release,
.get_frequency = xc2028_get_frequency,
.get_rf_strength = xc2028_signal,
.set_params = xc2028_set_params,
// int (*sleep)(struct dvb_frontend *fe); // int (*sleep)(struct dvb_frontend *fe);
/** This is for simple PLLs - set all parameters in one go. */
.set_params = xc3028_set_params,
/** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */
// int (*calc_regs)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p, u8 *buf, int buf_len);
// int (*get_frequency)(struct dvb_frontend *fe, u32 *frequency);
// int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth); // int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
// int (*get_status)(struct dvb_frontend *fe, u32 *status); // int (*get_status)(struct dvb_frontend *fe, u32 *status);
}; };
int xc2028_attach(struct i2c_client *c, struct dvb_frontend *fe) 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))
{ {
fe->tuner_priv = c; struct xc2028_data *priv;
memcpy(&fe->ops.tuner_ops, &xc3028_dvb_tuner_ops, sizeof(fe->ops.tuner_ops)); printk( KERN_INFO PREFIX "Xcv2028/3028 init called!\n");
return 0; 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;
fe->tuner_priv = priv;
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;
}
EXPORT_SYMBOL(xc2028_attach); EXPORT_SYMBOL(xc2028_attach);
MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
MODULE_LICENSE("GPL");
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
* This code is placed under the terms of the GNU General Public License v2 * This code is placed under the terms of the GNU General Public License v2
*/ */
#ifndef __TUNER_XC2028_H__
#define __TUNER_XC2028_H__
#include "dvb_frontend.h"
/* xc2028 commands for callback */ /* xc2028 commands for callback */
#define XC2028_TUNER_RESET 0 #define XC2028_TUNER_RESET 0
#define XC2028_RESET_CLK 1 #define XC2028_RESET_CLK 1
...@@ -11,4 +16,21 @@ ...@@ -11,4 +16,21 @@
struct dvb_frontend; struct dvb_frontend;
struct i2c_client; struct i2c_client;
int xc2028_attach(struct i2c_client *c, struct dvb_frontend *fe); #if defined(CONFIG_TUNER_XC2028) || (defined(CONFIG_TUNER_XC2028_MODULE) && defined(MODULE))
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));
#else
static inline 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))
{
printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
__FUNCTION__);
return -EINVAL;
}
#endif
#endif /* __TUNER_XC2028_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment