📄 tm6000.c
字号:
if(msgs[i].flags & I2C_M_RD ) {// printk(KERN_ALERT "i should read from the i2c device %x %u bytes\n", msgs[i].addr, msgs[i].len); if(msgs[i].len == 1) { msgs[i].buf[0] = tm6000_dev->i2c_response;// printk(KERN_ALERT "read: %x\n", msgs[i].buf[0]); ++success; } else { printk(KERN_ALERT "wrong reception buffer size in %s", __FUNCTION__); } } else {// printk(KERN_ALERT "i should write to i2c device %x, the bytes ", msgs[i].addr); for(j = 0; j < msgs[i].len; ++j) { printk("%x", msgs[i].buf[j]); } printk("\n"); if(msgs[i].len > 2) { printk(KERN_ALERT "should send more than two bytes in %s.\n", __FUNCTION__); continue; } else if(msgs[i].len == 0) { printk(KERN_ALERT "should send zero bytes.\n"); continue; } if(msgs[i].len == 1) { // reading a register data = kzalloc(1*sizeof(u8), GFP_KERNEL); req = msgs[i].addr; req |= msgs[i].buf[0] << 8;// printk(KERN_ALERT "sending req %x\n", req); ret = tm6000_rcv_control_msg(tm6000_dev, 0x10, req, 0x0000, data, 1); tm6000_dev->i2c_response = data[0]; kfree(data); if(ret < 0) { printk(KERN_ALERT "i2c sending failure, code %i\n", ret); continue; } ++success; } else { // msgs[i].len == 2 data = kzalloc(1*sizeof(u8), GFP_KERNEL); req = msgs[i].addr; req |= msgs[i].buf[0] << 8; data[0] = msgs[i].buf[1];// printk(KERN_ALERT "sending req %x\n", req); ret = tm6000_snd_control_msg(tm6000_dev, 0x10, req, 0x0000, data, 1); kfree(data); if(ret < 0) { printk(KERN_ALERT "i2c sending failure, code %i\n", ret); continue; } ++success; } } } return success;}static int tm6000_zl10353_i2c_algo_control(struct i2c_adapter *adapter, unsigned int cmd, unsigned long arg){ return 0;}static u32 tm6000_zl10353_i2c_functionality(struct i2c_adapter *adap) { return I2C_FUNC_SMBUS_EMUL;}static struct i2c_algorithm tm6000_zl10353_i2c_algorithm = { .master_xfer = tm6000_zl10353_i2c_xfer, .algo_control = tm6000_zl10353_i2c_algo_control, .functionality = tm6000_zl10353_i2c_functionality,};static int tm6000_xc3028_i2c_xfer(struct i2c_adapter *i2c_adapter, struct i2c_msg msgs[], int num){ int i, j, ret; unsigned int success = 0, k; u8* data; u16 req; struct tm6000_device *tm6000_dev = i2c_adapter->algo_data; for(i = 0; i < num; ++i) { if(msgs[i].flags & I2C_M_RD ) { printk(KERN_ALERT "tm6000: WARNING! xc3028 i2c read not implemented!\n");// printk(KERN_ALERT "i should read from the i2c device %x %u bytes\n", msgs[i].addr, msgs[i].len);// if(msgs[i].len == 1) {// msgs[i].buf[0] = tm6000_dev->i2c_response;// printk(KERN_ALERT "read: %x\n", msgs[i].buf[0]);// ++success;// }// else {// printk(KERN_ALERT "wrong reception buffer size in %s", __FUNCTION__);// } } else { printk(KERN_ALERT "tm6000: xc3028 i2c: i should write to i2c device %x, the bytes ", msgs[i].addr); for(j = 0; j < msgs[i].len; ++j) { printk("%x", msgs[i].buf[j]); } printk("\n"); if(msgs[i].len > 2) { printk(KERN_ALERT "should send more than two bytes in %s.\n", __FUNCTION__); continue; } else if(msgs[i].len == 0) { printk(KERN_ALERT "should send zero bytes.\n"); continue; } if(msgs[i].len == 1) { // reading a register data = kzalloc(1*sizeof(u8), GFP_KERNEL); req = msgs[i].addr; req |= msgs[i].buf[0] << 8;// printk(KERN_ALERT "sending req %x\n", req); ret = tm6000_rcv_control_msg(tm6000_dev, 0x10, req, 0x0000, data, 1); tm6000_dev->i2c_response = data[0]; kfree(data); if(ret < 0) { printk(KERN_ALERT "i2c sending failure, code %i\n", ret); continue; } ++success; } else { // msgs[i].len == 2 data = kzalloc(1*sizeof(u8), GFP_KERNEL); req = msgs[i].addr; req |= msgs[i].buf[0] << 8; data[0] = msgs[i].buf[1];// printk(KERN_ALERT "sending req %x\n", req); ret = tm6000_snd_control_msg(tm6000_dev, 0x10, req, 0x0000, data, 1); kfree(data); if(ret < 0) { printk(KERN_ALERT "i2c sending failure, code %i\n", ret); continue; } ++success; } } } return success;}static int tm6000_xc3028_i2c_algo_control(struct i2c_adapter *adapter, unsigned int cmd, unsigned long arg){ return 0;}static u32 tm6000_xc3028_i2c_functionality(struct i2c_adapter *adap) { return I2C_FUNC_SMBUS_EMUL;}static struct i2c_algorithm tm6000_xc3028_i2c_algorithm = { .master_xfer = tm6000_xc3028_i2c_xfer, .algo_control = tm6000_xc3028_i2c_algo_control, .functionality = tm6000_xc3028_i2c_functionality,};struct zl10353_config zl10353_config ={ /* demodulator's I2C address */ .demod_address = 0x1e, /* set if no pll is connected to the secondary i2c bus */ .no_tuner = 1,};int tm6000_get_frequency(struct dvb_frontend *fe, u32 *frequency) {*frequency = 0;return 0;}int tm6000_set_frequency(struct dvb_frontend *fe, u32 frequency) {printk(KERN_ALERT "should set 2frequency to %u", frequency);return 0;}int (*set_params)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p);struct bcode { int reg; char *txt; int len; int delay;};static int tm6000_zl103530_init(struct dvb_frontend *fe){ printk(KERN_ALERT "initialisation of the ZL10353\n");/* zl10353_write(fe, "\x50\x0b", 2); zl10353_write(fe, "\x55\x80", 2); udelay(100); zl10353_write(fe, "\xea\x01", 2); zl10353_write(fe, "\xea\x00", 2); zl10353_write(fe, "\x56\x1c", 2); zl10353_write(fe, "\x5e\x40", 2); zl10353_write(fe, "\x64\x36", 2); zl10353_write(fe, "\x65\x67", 2); zl10353_write(fe, "\x66\xe5", 2); zl10353_write(fe, "\x6c\x19", 2); zl10353_write(fe, "\x6d\xe9", 2); zl10353_write(fe, "\x51\x44", 2); zl10353_write(fe, "\x52\x46", 2); zl10353_write(fe, "\x53\x15", 2); zl10353_write(fe, "\x54\x0f", 2); zl10353_write(fe, "\x5c\x75", 2); zl10353_write(fe, "\x70\x01", 2); udelay(300); zl10353_write(fe, "\x50\x0c", 2); udelay(100);*/ return 0;}#define TUNING_GRANULARITY 15625static int tm6000_zl10353_pll(struct tm6000_device *tm6000_dev, struct dvb_frontend_parameters *p){ int i, ret; u8 *data; u32 frequencyToSet;printk(KERN_ALERT "should set frequency %u\n", p->frequency);printk(KERN_ALERT "and bandwith %u\n", p->u.ofdm.bandwidth);// return 0;// data = kzalloc(2*sizeof(__u8), GFP_KERNEL);// ret = tm6000_rcv_control_msg(tm6000_dev, 0x0e, 0xc2, 0x08, data, 0x2);// printk(KERN_ALERT "received %x %x\n", data[0], data[1]);// kfree(data);// zl10353_write(tm6000_dev->dvb_frontend,"\x70\x01",2);// mdelay(10); data = kzalloc(3*sizeof(__u8), GFP_KERNEL); data[0]=0x01; data[1]=0x00; data[2]=0x00; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x80c2, 0x08, data, 0x3); kfree(data); if(ret < 0) { return ret; } ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(3*sizeof(__u8), GFP_KERNEL); switch(p->u.ofdm.bandwidth) { case BANDWIDTH_7_MHZ: data[0]=0x37; break; default: printk(KERN_ALERT "tm6000: bandwidth not supported"); case BANDWIDTH_8_MHZ: data[0]=0x77; break; } data[1]=0x01; data[2]=0x72; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x02c2, 0x00, data, 0x3); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(1*sizeof(__u8), GFP_KERNEL); data[0]=0x18; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x2bc2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0xb*sizeof(__u8), GFP_KERNEL); ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x14c2, 0x00, data, 0xb); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0xb*sizeof(__u8), GFP_KERNEL); data[0]=0x14; data[1]=0x08; data[2]=0x00; data[3]=0x00; data[4]=0x0c; data[5]=0x08; data[6]=0xc2; data[7]=0xa4; data[8]=0x49; data[9]=0x0d; data[10]=0x2d; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x13c2, 0x00, data, 0xb); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0xc*sizeof(__u8), GFP_KERNEL); data[0]=0x01; data[1]=0x4b; data[2]=0x02; data[3]=0xd5; data[4]=0x55; data[5]=0xc7; data[6]=0xd7; data[7]=0x00; data[8]=0xa1; data[9]=0xff; data[10]=0xef; data[11]=0xff; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x0dc2, 0x00, data, 0xc); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(1*sizeof(__u8), GFP_KERNEL); data[0]=0x1; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x2dc2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(1*sizeof(__u8), GFP_KERNEL); data[0]=0x3; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x18c2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0xb*sizeof(__u8), GFP_KERNEL); ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x1bc2, 0x00, data, 0xb); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(1*sizeof(__u8), GFP_KERNEL); data[0]=0x1; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x1dc2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(6*sizeof(__u8), GFP_KERNEL); data[0]=0x00; data[1]=0x29; data[2]=0x56; data[3]=0xb4; data[4]=0x00; data[5]=0xb4; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x0fc2, 0x00, data, 0x6); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(1*sizeof(__u8), GFP_KERNEL); data[0]=0x01; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x20c2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0);// 1c f2 4d e0 00 0b 61 66 06 69 13 data = kzalloc(0xb*sizeof(__u8), GFP_KERNEL);/* data[0]=0x04; data[1]=0x93; data[2]=0x24; data[3]=0x92; data[4]=0x02; data[5]=0xad; data[6]=0x01; data[7]=0x66; data[8]=0xa6; data[9]=0xa8; data[10]=0x24;*///new data[0]=0x1c; data[1]=0xf2; data[2]=0x4d; data[3]=0xe0; data[4]=0x00; data[5]=0x0b; data[6]=0x61; data[7]=0x66; data[8]=0x06; data[9]=0x69; data[10]=0x13; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x1ec2, 0x00, data, 0xb); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0x1*sizeof(__u8), GFP_KERNEL); data[0]=0x29; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x22c2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0x1*sizeof(__u8), GFP_KERNEL); data[0]=0x06; ret = tm6000_snd_control_msg(tm6000_dev, 0x10, 0x23c2, 0x00, data, 0x1); kfree(data); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x01, 0x0, 0x0); ret = tm6000_snd_control_msg(tm6000_dev, 0x03, 0x0101, 0x00, 0x0, 0x0); data = kzalloc(0x8*sizeof(__u8), GFP_KERNEL); data[0]=0x00; data[1]=0x08; data[2]=0x09; data[3]=0x68; data[4]=0x9a; data[5]=0x02; data[6]=0x5a; data[7]=0x26;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -