#define pr_fmt(fmt) …
#define MAX_XFER_SIZE …
#define NXT2002_DEFAULT_FIRMWARE …
#define NXT2004_DEFAULT_FIRMWARE …
#define CRC_CCIT_MASK …
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <media/dvb_frontend.h>
#include "nxt200x.h"
struct nxt200x_state { … };
static int debug;
#define dprintk(args...) …
static int i2c_writebytes (struct nxt200x_state* state, u8 addr, u8 *buf, u8 len)
{ … }
static int i2c_readbytes(struct nxt200x_state *state, u8 addr, u8 *buf, u8 len)
{ … }
static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg,
const u8 *buf, u8 len)
{ … }
static int nxt200x_readbytes(struct nxt200x_state *state, u8 reg, u8 *buf, u8 len)
{ … }
static u16 nxt200x_crc(u16 crc, u8 c)
{ … }
static int nxt200x_writereg_multibyte (struct nxt200x_state* state, u8 reg, u8* data, u8 len)
{ … }
static int nxt200x_readreg_multibyte (struct nxt200x_state* state, u8 reg, u8* data, u8 len)
{ … }
static void nxt200x_microcontroller_stop (struct nxt200x_state* state)
{ … }
static void nxt200x_microcontroller_start (struct nxt200x_state* state)
{ … }
static void nxt2004_microcontroller_init (struct nxt200x_state* state)
{ … }
static int nxt200x_writetuner (struct nxt200x_state* state, u8* data)
{ … }
static void nxt200x_agc_reset(struct nxt200x_state* state)
{ … }
static int nxt2002_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
{
struct nxt200x_state* state = fe->demodulator_priv;
u8 buf[3], written = 0, chunkpos = 0;
u16 rambase, position, crc = 0;
dprintk("%s\n", __func__);
dprintk("Firmware is %zu bytes\n", fw->size);
nxt200x_readbytes(state, 0x10, buf, 1);
if (buf[0] & 0x10)
rambase = 0x1000;
else
rambase = 0x0000;
dprintk("rambase on this nxt2002 is %04X\n", rambase);
buf[0] = 0x80;
nxt200x_writebytes(state, 0x2B, buf, 1);
for (position = 0; position < fw->size; position++) {
if (written == 0) {
crc = 0;
chunkpos = 0x28;
buf[0] = ((rambase + position) >> 8);
buf[1] = (rambase + position) & 0xFF;
buf[2] = 0x81;
nxt200x_writebytes(state, 0x29, buf, 3);
}
written++;
chunkpos++;
if ((written % 4) == 0)
nxt200x_writebytes(state, chunkpos, &fw->data[position-3], 4);
crc = nxt200x_crc(crc, fw->data[position]);
if ((written == 255) || (position+1 == fw->size)) {
nxt200x_writebytes(state, chunkpos+4-(written %4),
&fw->data[position-(written %4) + 1],
written %4);
buf[0] = crc << 8;
buf[1] = crc & 0xFF;
nxt200x_writebytes(state, 0x2C, buf, 2);
nxt200x_readbytes(state, 0x2A, buf, 1);
buf[0] = 0x80;
nxt200x_writebytes(state, 0x2B, buf, 1);
written = 0;
}
}
return 0;
};
static int nxt2004_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
{
struct nxt200x_state* state = fe->demodulator_priv;
u8 buf[3];
u16 rambase, position, crc=0;
dprintk("%s\n", __func__);
dprintk("Firmware is %zu bytes\n", fw->size);
rambase = 0x1000;
buf[0] = 0x80;
nxt200x_writebytes(state, 0x2B, buf,1);
for (position = 0; position < fw->size; position++) {
crc = nxt200x_crc(crc, fw->data[position]);
}
buf[0] = rambase >> 8;
buf[1] = rambase & 0xFF;
buf[2] = 0x81;
nxt200x_writebytes(state,0x29,buf,3);
for (position = 0; position < fw->size;) {
nxt200x_writebytes(state, 0x2C, &fw->data[position],
fw->size-position > 255 ? 255 : fw->size-position);
position += (fw->size-position > 255 ? 255 : fw->size-position);
}
buf[0] = crc >> 8;
buf[1] = crc & 0xFF;
dprintk("firmware crc is 0x%02X 0x%02X\n", buf[0], buf[1]);
nxt200x_writebytes(state, 0x2C, buf,2);
nxt200x_readbytes(state, 0x2C, buf, 1);
buf[0] = 0x80;
nxt200x_writebytes(state, 0x2B, buf,1);
return 0;
};
static int nxt200x_setup_frontend_parameters(struct dvb_frontend *fe)
{ … }
static int nxt200x_read_status(struct dvb_frontend *fe, enum fe_status *status)
{ … }
static int nxt200x_read_ber(struct dvb_frontend* fe, u32* ber)
{ … }
static int nxt200x_read_signal_strength(struct dvb_frontend* fe, u16* strength)
{ … }
static int nxt200x_read_snr(struct dvb_frontend* fe, u16* snr)
{ … }
static int nxt200x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
{ … }
static int nxt200x_sleep(struct dvb_frontend* fe)
{ … }
static int nxt2002_init(struct dvb_frontend* fe)
{ … }
static int nxt2004_init(struct dvb_frontend* fe)
{ … }
static int nxt200x_init(struct dvb_frontend* fe)
{ … }
static int nxt200x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
{ … }
static void nxt200x_release(struct dvb_frontend* fe)
{ … }
static const struct dvb_frontend_ops nxt200x_ops;
struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
struct i2c_adapter* i2c)
{ … }
static const struct dvb_frontend_ops nxt200x_ops = …;
module_param(debug, int, 0644);
MODULE_PARM_DESC(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_AUTHOR(…) …;
MODULE_LICENSE(…) …;
EXPORT_SYMBOL_GPL(…);