Commit 4f4f9689 authored by Johannes Stezenbach's avatar Johannes Stezenbach Committed by Linus Torvalds

[PATCH] dvb: dib3000 refactoring

- [DVB] dib3000: driver refactoring, makes it easier to support device clones
Signed-off-by: default avatarMichael Hunold <hunold@linuxtv.org>
Signed-off-by: default avatarJohannes Stezenbach <js@linuxtv.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d12f9fba
......@@ -2,7 +2,7 @@
#ifdef CONFIG_DVB_DIBCOM_DEBUG
static int debug;
module_param(debug, int, 0x644);
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "set debugging level (1=info,2=i2c,4=srch (|-able)).");
#endif
#define deb_info(args...) dprintk(0x01,args)
......@@ -42,65 +42,6 @@ int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val)
return i2c_transfer(state->i2c,msg, 1) != 1 ? -EREMOTEIO : 0;
}
int dib3000_init_pid_list(struct dib3000_state *state, int num)
{
int i;
if (state != NULL) {
state->pid_list = kmalloc(sizeof(struct dib3000_pid) * num,GFP_KERNEL);
if (state->pid_list == NULL)
return -ENOMEM;
deb_info("initializing %d pids for the pid_list.\n",num);
spin_lock_init(&state->pid_list_lock);
memset(state->pid_list,0,num*(sizeof(struct dib3000_pid)));
for (i=0; i < num; i++) {
state->pid_list[i].pid = 0;
state->pid_list[i].active = 0;
}
state->feedcount = 0;
} else
return -EINVAL;
return 0;
}
void dib3000_dealloc_pid_list(struct dib3000_state *state)
{
if (state != NULL && state->pid_list != NULL)
kfree(state->pid_list);
}
/* fetch a pid from pid_list */
int dib3000_get_pid_index(struct dib3000_pid pid_list[], int num_pids, int pid,
spinlock_t *pid_list_lock,int onoff)
{
int i,ret = -1;
unsigned long flags;
spin_lock_irqsave(pid_list_lock,flags);
for (i=0; i < num_pids; i++)
if (onoff) {
if (!pid_list[i].active) {
pid_list[i].pid = pid;
pid_list[i].active = 1;
ret = i;
break;
}
} else {
if (pid_list[i].active && pid_list[i].pid == pid) {
pid_list[i].pid = 0;
pid_list[i].active = 0;
ret = i;
break;
}
}
deb_info("setting pid: %5d %04x at index %d '%s'\n",pid,pid,ret,onoff ? "on" : "off");
spin_unlock_irqrestore(pid_list_lock,flags);
return ret;
}
int dib3000_search_status(u16 irq,u16 lock)
{
if (irq & 0x02) {
......@@ -139,7 +80,4 @@ EXPORT_SYMBOL(dib3000_seq);
EXPORT_SYMBOL(dib3000_read_reg);
EXPORT_SYMBOL(dib3000_write_reg);
EXPORT_SYMBOL(dib3000_init_pid_list);
EXPORT_SYMBOL(dib3000_dealloc_pid_list);
EXPORT_SYMBOL(dib3000_get_pid_index);
EXPORT_SYMBOL(dib3000_search_status);
......@@ -4,7 +4,7 @@
*
* DiBcom (http://www.dibcom.fr/)
*
* Copyright (C) 2004 Patrick Boettcher (patrick.boettcher@desy.de)
* Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
*
* based on GPL code from DibCom, which has
*
......@@ -29,19 +29,10 @@
#include "dvb_frontend.h"
#include "dib3000.h"
/* info and err, taken from usb.h, if there is anything available like by default,
* please change !
*/
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , __FILE__ , ## arg)
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , __FILE__ , ## arg)
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , __FILE__ , ## arg)
/* a PID for the pid_filter list, when in use */
struct dib3000_pid
{
u16 pid;
int active;
};
/* info and err, taken from usb.h, if there is anything available like by default. */
#define err(format, arg...) printk(KERN_ERR "dib3000mX: " format "\n" , ## arg)
#define info(format, arg...) printk(KERN_INFO "dib3000mX: " format "\n" , ## arg)
#define warn(format, arg...) printk(KERN_WARNING "dib3000mX: " format "\n" , ## arg)
/* frontend state */
struct dib3000_state {
......@@ -52,25 +43,18 @@ struct dib3000_state {
/* configuration settings */
struct dib3000_config config;
spinlock_t pid_list_lock;
struct dib3000_pid *pid_list;
int feedcount;
struct dvb_frontend frontend;
int timing_offset;
int timing_offset_comp_done;
fe_bandwidth_t last_tuned_bw;
u32 last_tuned_freq;
};
/* commonly used methods by the dib3000mb/mc/p frontend */
extern int dib3000_read_reg(struct dib3000_state *state, u16 reg);
extern int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val);
extern int dib3000_init_pid_list(struct dib3000_state *state, int num);
extern void dib3000_dealloc_pid_list(struct dib3000_state *state);
extern int dib3000_get_pid_index(struct dib3000_pid pid_list[], int num_pids,
int pid, spinlock_t *pid_list_lock,int onoff);
extern int dib3000_search_status(u16 irq,u16 lock);
/* handy shortcuts */
......@@ -81,7 +65,7 @@ extern int dib3000_search_status(u16 irq,u16 lock);
#define wr_foreach(a,v) { int i; \
if (sizeof(a) != sizeof(v)) \
err("sizeof: %zd %zd is different",sizeof(a),sizeof(v));\
err("sizeof: %d %d is different",sizeof(a),sizeof(v));\
for (i=0; i < sizeof(a)/sizeof(u16); i++) \
wr(a[i],v[i]); \
}
......@@ -136,8 +120,8 @@ extern int dib3000_search_status(u16 irq,u16 lock);
#define DIB3000_DDS_INVERSION_OFF ( 0)
#define DIB3000_DDS_INVERSION_ON ( 1)
#define DIB3000_TUNER_WRITE_ENABLE(a) (0xffff & (a << 7))
#define DIB3000_TUNER_WRITE_DISABLE(a) (0xffff & ((a << 7) | (1 << 7)))
#define DIB3000_TUNER_WRITE_ENABLE(a) (0xffff & (a << 8))
#define DIB3000_TUNER_WRITE_DISABLE(a) (0xffff & ((a << 8) | (1 << 7)))
/* for auto search */
extern u16 dib3000_seq[2][2][2];
......
......@@ -2,7 +2,7 @@
* public header file of the frontend drivers for mobile DVB-T demodulators
* DiBcom 3000-MB and DiBcom 3000-MC/P (http://www.dibcom.fr/)
*
* Copyright (C) 2004 Patrick Boettcher (patrick.boettcher@desy.de)
* Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
*
* based on GPL code from DibCom, which has
*
......@@ -31,25 +31,24 @@ struct dib3000_config
/* the demodulator's i2c address */
u8 demod_address;
/* The i2c address of the PLL */
u8 pll_addr;
/* PLL maintenance */
int (*pll_init)(struct dvb_frontend *fe);
int (*pll_set)(struct dvb_frontend *fe, struct dvb_frontend_parameters* params);
/* PLL maintenance and the i2c address of the PLL */
u8 (*pll_addr)(struct dvb_frontend *fe);
int (*pll_init)(struct dvb_frontend *fe, u8 pll_buf[5]);
int (*pll_set)(struct dvb_frontend *fe, struct dvb_frontend_parameters* params, u8 pll_buf[5]);
};
struct dib3000_xfer_ops
struct dib_fe_xfer_ops
{
/* pid and transfer handling is done in the demodulator */
int (*pid_parse)(struct dvb_frontend *fe, int onoff);
int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
int (*pid_ctrl)(struct dvb_frontend *fe, int pid, int onoff);
int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
};
extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
struct i2c_adapter* i2c, struct dib3000_xfer_ops *xfer_ops);
struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops);
extern struct dvb_frontend* dib3000mc_attach(const struct dib3000_config* config,
struct i2c_adapter* i2c, struct dib3000_xfer_ops *xfer_ops);
struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops);
#endif // DIB3000_H
......@@ -2,7 +2,7 @@
* Frontend driver for mobile DVB-T demodulator DiBcom 3000-MB
* DiBcom (http://www.dibcom.fr/)
*
* Copyright (C) 2004 Patrick Boettcher (patrick.boettcher@desy.de)
* Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
*
* based on GPL code from DibCom, which has
*
......@@ -29,7 +29,6 @@
#include <linux/init.h>
#include <linux/delay.h>
#include "dvb_frontend.h"
#include "dib3000-common.h"
#include "dib3000mb_priv.h"
#include "dib3000.h"
......@@ -41,7 +40,7 @@
#ifdef CONFIG_DVB_DIBCOM_DEBUG
static int debug;
module_param(debug, int, 0x644);
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
#endif
#define deb_info(args...) dprintk(0x01,args)
......@@ -49,6 +48,8 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-a
#define deb_setf(args...) dprintk(0x04,args)
#define deb_getf(args...) dprintk(0x08,args)
static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr);
static int dib3000mb_get_frontend(struct dvb_frontend* fe,
struct dvb_frontend_parameters *fep);
......@@ -61,11 +62,9 @@ static int dib3000mb_set_frontend(struct dvb_frontend* fe,
int search_state,seq;
if (tuner) {
wr(DIB3000MB_REG_TUNER,
DIB3000_TUNER_WRITE_ENABLE(state->config.pll_addr));
state->config.pll_set(fe, fep);
wr(DIB3000MB_REG_TUNER,
DIB3000_TUNER_WRITE_DISABLE(state->config.pll_addr));
dib3000mb_tuner_pass_ctrl(fe,1,state->config.pll_addr(fe));
state->config.pll_set(fe, fep, NULL);
dib3000mb_tuner_pass_ctrl(fe,0,state->config.pll_addr(fe));
deb_setf("bandwidth: ");
switch (ofdm->bandwidth) {
......@@ -390,11 +389,9 @@ static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode)
wr(DIB3000MB_REG_DATA_IN_DIVERSITY,DIB3000MB_DATA_DIVERSITY_IN_OFF);
if (state->config.pll_init) {
wr(DIB3000MB_REG_TUNER,
DIB3000_TUNER_WRITE_ENABLE(state->config.pll_addr));
state->config.pll_init(fe);
wr(DIB3000MB_REG_TUNER,
DIB3000_TUNER_WRITE_DISABLE(state->config.pll_addr));
dib3000mb_tuner_pass_ctrl(fe,1,state->config.pll_addr(fe));
state->config.pll_init(fe,NULL);
dib3000mb_tuner_pass_ctrl(fe,0,state->config.pll_addr(fe));
}
return 0;
......@@ -414,6 +411,7 @@ static int dib3000mb_get_frontend(struct dvb_frontend* fe,
return 0;
dds_val = ((rd(DIB3000MB_REG_DDS_VALUE_MSB) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB);
deb_getf("DDS_VAL: %x %x %x",dds_val, rd(DIB3000MB_REG_DDS_VALUE_MSB), rd(DIB3000MB_REG_DDS_VALUE_LSB));
if (dds_val < threshold)
inv_test1 = 0;
else if (dds_val == threshold)
......@@ -422,6 +420,7 @@ static int dib3000mb_get_frontend(struct dvb_frontend* fe,
inv_test1 = 2;
dds_val = ((rd(DIB3000MB_REG_DDS_FREQ_MSB) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB);
deb_getf("DDS_FREQ: %x %x %x",dds_val, rd(DIB3000MB_REG_DDS_FREQ_MSB), rd(DIB3000MB_REG_DDS_FREQ_LSB));
if (dds_val < threshold)
inv_test2 = 0;
else if (dds_val == threshold)
......@@ -714,18 +713,11 @@ static void dib3000mb_release(struct dvb_frontend* fe)
}
/* pid filter and transfer stuff */
static int dib3000mb_pid_control(struct dvb_frontend *fe,int pid,int onoff)
static int dib3000mb_pid_control(struct dvb_frontend *fe,int index, int pid,int onoff)
{
struct dib3000_state *state = fe->demodulator_priv;
int index = dib3000_get_pid_index(state->pid_list, DIB3000MB_NUM_PIDS, pid, &state->pid_list_lock,onoff);
pid = (onoff ? pid | DIB3000_ACTIVATE_PID_FILTERING : 0);
if (index >= 0) {
wr(index+DIB3000MB_REG_FIRST_PID,pid);
} else {
err("no more pids for filtering.");
return -ENOMEM;
}
return 0;
}
......@@ -749,10 +741,21 @@ static int dib3000mb_pid_parse(struct dvb_frontend *fe, int onoff)
return 0;
}
static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr)
{
struct dib3000_state *state = (struct dib3000_state*) fe->demodulator_priv;
if (onoff) {
wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr));
} else {
wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_DISABLE(pll_addr));
}
return 0;
}
static struct dvb_frontend_ops dib3000mb_ops;
struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
struct i2c_adapter* i2c, struct dib3000_xfer_ops *xfer_ops)
struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
{
struct dib3000_state* state = NULL;
......@@ -773,9 +776,6 @@ struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
if (rd(DIB3000_REG_DEVICE_ID) != DIB3000MB_DEVICE_ID)
goto error;
if (dib3000_init_pid_list(state,DIB3000MB_NUM_PIDS))
goto error;
/* create dvb_frontend */
state->frontend.ops = &state->ops;
state->frontend.demodulator_priv = state;
......@@ -784,6 +784,7 @@ struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
xfer_ops->pid_parse = dib3000mb_pid_parse;
xfer_ops->fifo_ctrl = dib3000mb_fifo_control;
xfer_ops->pid_ctrl = dib3000mb_pid_control;
xfer_ops->tuner_pass_ctrl = dib3000mb_tuner_pass_ctrl;
return &state->frontend;
......@@ -807,6 +808,7 @@ static struct dvb_frontend_ops dib3000mb_ops = {
FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
FE_CAN_TRANSMISSION_MODE_AUTO |
FE_CAN_GUARD_INTERVAL_AUTO |
FE_CAN_RECOVER |
FE_CAN_HIERARCHY_AUTO,
},
......
This diff is collapsed.
......@@ -13,31 +13,6 @@
#ifndef __DIB3000MC_PRIV_H__
#define __DIB3000MC_PRIV_H__
/* info and err, taken from usb.h, if there is anything available like by default,
* please change !
*/
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , __FILE__ , ## arg)
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , __FILE__ , ## arg)
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , __FILE__ , ## arg)
// defines the phase noise algorithm to be used (O:Inhib, 1:CPE on)
#define DEF_PHASE_NOISE_MODE 0
// define Mobille algorithms
#define DEF_MOBILE_MODE Auto_Reception
// defines the tuner type
#define DEF_TUNER_TYPE TUNER_PANASONIC_ENV57H13D5
// defines the impule noise algorithm to be used
#define DEF_IMPULSE_NOISE_MODE 0
// defines the MPEG2 data output format
#define DEF_MPEG2_OUTPUT_188 0
// defines the MPEG2 data output format
#define DEF_OUTPUT_MODE MPEG2_PARALLEL_CONTINUOUS_CLOCK
/*
* Demodulator parameters
* reg: 0 1 1 1 11 11 111
......@@ -115,7 +90,7 @@ static u16 dib3000mc_bandwidth_7mhz[] =
{ 0x1c, 0xfba5, 0x60, 0x9c25, 0x1e3, 0x0cb7, 0x1, 0xb0d0 };
static u16 dib3000mc_bandwidth_8mhz[] =
{ 0x19, 0x5c30, 0x54, 0x88a0, 0x1a6, 0xab20, 0x1, 0xb0b0 };
{ 0x19, 0x5c30, 0x54, 0x88a0, 0x1a6, 0xab20, 0x1, 0xb0d0 };
static u16 dib3000mc_reg_bandwidth_general[] = { 12,13,14,15 };
static u16 dib3000mc_bandwidth_general[] = { 0x0000, 0x03e8, 0x0000, 0x03f2 };
......@@ -173,11 +148,11 @@ static u16 dib3000mc_offset[][2] = {
static u16 dib3000mc_reg_imp_noise_ctl[] = { 34,35 };
static u16 dib3000mc_imp_noise_ctl[][2] = {
{ 0x1294, 0xfff8 }, /* mode 0 */
{ 0x1294, 0xfff8 }, /* mode 1 */
{ 0x1294, 0xfff8 }, /* mode 2 */
{ 0x1294, 0xfff8 }, /* mode 3 */
{ 0x1294, 0xfff8 }, /* mode 4 */
{ 0x1294, 0x1ff8 }, /* mode 0 */
{ 0x1294, 0x1ff8 }, /* mode 1 */
{ 0x1294, 0x1ff8 }, /* mode 2 */
{ 0x1294, 0x1ff8 }, /* mode 3 */
{ 0x1294, 0x1ff8 }, /* mode 4 */
};
/* AGC registers */
......@@ -314,12 +289,26 @@ static u16 dib3000mc_mobile_mode[][5] = {
#define DIB3000MC_REG_FEC_CFG ( 195)
#define DIB3000MC_FEC_CFG ( 0x10)
/*
* reg 206, output mode
* 1111 1111
* |||| ||||
* |||| |||+- unk
* |||| ||+-- unk
* |||| |+--- unk (on by default)
* |||| +---- fifo_ctrl (1 = inhibit (flushed), 0 = active (unflushed))
* |||+------ pid_parse (1 = enabled, 0 = disabled)
* ||+------- outp_188 (1 = TS packet size 188, 0 = packet size 204)
* |+-------- unk
* +--------- unk
*/
#define DIB3000MC_REG_SMO_MODE ( 206)
#define DIB3000MC_SMO_MODE_DEFAULT (1 << 2)
#define DIB3000MC_SMO_MODE_FIFO_FLUSH (1 << 3)
#define DIB3000MC_SMO_MODE_FIFO_UNFLUSH ~DIB3000MC_SMO_MODE_FIFO_FLUSH
#define DIB3000MC_SMO_MODE_FIFO_UNFLUSH (0xfff7)
#define DIB3000MC_SMO_MODE_PID_PARSE (1 << 4)
#define DIB3000MC_SMO_MODE_NO_PID_PARSE ~DIB3000MC_SMO_MODE_PID_PARSE
#define DIB3000MC_SMO_MODE_NO_PID_PARSE (0xffef)
#define DIB3000MC_SMO_MODE_188 (1 << 5)
#define DIB3000MC_SMO_MODE_SLAVE (DIB3000MC_SMO_MODE_DEFAULT | \
DIB3000MC_SMO_MODE_188 | DIB3000MC_SMO_MODE_PID_PARSE | (1<<1))
......@@ -392,7 +381,7 @@ static u16 dib3000mc_mobile_mode[][5] = {
#define DIB3000MC_REG_RST_I2C_ADDR ( 1024)
#define DIB3000MC_DEMOD_ADDR_ON ( 1)
#define DIB3000MC_DEMOD_ADDR(a) ((a << 3) & 0x03F0)
#define DIB3000MC_DEMOD_ADDR(a) ((a << 4) & 0x03F0)
#define DIB3000MC_REG_RESTART ( 1027)
#define DIB3000MC_RESTART_OFF (0x0000)
......
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