2 * Support for NXT2002 and NXT2004 - VSB/QAM
4 * Copyright (C) 2005 Kirk Lapray (kirk.lapray@gmail.com)
5 * based on nxt2002 by Taylor Jacob <rtjacob@earthlink.net>
6 * and nxt2004 by Jean-Francois Thibert (jeanfrancois@sagetv.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * NOTES ABOUT THIS DRIVER
27 * This Linux driver supports:
28 * B2C2/BBTI Technisat Air2PC - ATSC (NXT2002)
29 * AverTVHD MCE A180 (NXT2004)
30 * ATI HDTV Wonder (NXT2004)
32 * This driver needs external firmware. Please use the command
33 * "<kerneldir>/Documentation/dvb/get_dvb_firmware nxt2002" or
34 * "<kerneldir>/Documentation/dvb/get_dvb_firmware nxt2004" to
35 * download/extract the appropriate firmware, and then copy it to
36 * /usr/lib/hotplug/firmware/ or /lib/firmware/
37 * (depending on configuration of firmware hotplug).
39 #define NXT2002_DEFAULT_FIRMWARE "dvb-fe-nxt2002.fw"
40 #define NXT2004_DEFAULT_FIRMWARE "dvb-fe-nxt2004.fw"
41 #define CRC_CCIT_MASK 0x1021
43 #include <linux/kernel.h>
44 #include <linux/init.h>
45 #include <linux/module.h>
46 #include <linux/moduleparam.h>
48 #include "dvb_frontend.h"
52 struct nxt200x_state {
54 struct i2c_adapter* i2c;
55 struct dvb_frontend_ops ops;
56 const struct nxt200x_config* config;
57 struct dvb_frontend frontend;
59 /* demodulator private data */
60 nxt_chip_type demod_chip;
65 #define dprintk(args...) \
67 if (debug) printk(KERN_DEBUG "nxt200x: " args); \
70 static int i2c_writebytes (struct nxt200x_state* state, u8 addr, u8 *buf, u8 len)
73 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = len };
75 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
76 printk (KERN_WARNING "nxt200x: %s: i2c write error (addr 0x%02x, err == %i)\n",
77 __FUNCTION__, addr, err);
83 static u8 i2c_readbytes (struct nxt200x_state* state, u8 addr, u8* buf, u8 len)
86 struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len };
88 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
89 printk (KERN_WARNING "nxt200x: %s: i2c read error (addr 0x%02x, err == %i)\n",
90 __FUNCTION__, addr, err);
96 static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg, u8 *buf, u8 len)
100 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf2, .len = len + 1 };
103 memcpy(&buf2[1], buf, len);
105 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
106 printk (KERN_WARNING "nxt200x: %s: i2c write error (addr 0x%02x, err == %i)\n",
107 __FUNCTION__, state->config->demod_address, err);
113 static u8 nxt200x_readbytes (struct nxt200x_state* state, u8 reg, u8* buf, u8 len)
115 u8 reg2 [] = { reg };
117 struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = reg2, .len = 1 },
118 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = buf, .len = len } };
122 if ((err = i2c_transfer (state->i2c, msg, 2)) != 2) {
123 printk (KERN_WARNING "nxt200x: %s: i2c read error (addr 0x%02x, err == %i)\n",
124 __FUNCTION__, state->config->demod_address, err);
130 static u16 nxt200x_crc(u16 crc, u8 c)
133 u16 input = (u16) c & 0xFF;
137 if((crc^input) & 0x8000)
138 crc=(crc<<1)^CRC_CCIT_MASK;
146 static int nxt200x_writereg_multibyte (struct nxt200x_state* state, u8 reg, u8* data, u8 len)
149 dprintk("%s\n", __FUNCTION__);
151 /* set mutli register register */
152 nxt200x_writebytes(state, 0x35, ®, 1);
154 /* send the actual data */
155 nxt200x_writebytes(state, 0x36, data, len);
157 switch (state->demod_chip) {
163 /* probably not right, but gives correct values */
171 len2 = ((attr << 4) | 0x10) | len;
179 /* set multi register length */
180 nxt200x_writebytes(state, 0x34, &len2, 1);
182 /* toggle the multireg write bit */
183 nxt200x_writebytes(state, 0x21, &buf, 1);
185 nxt200x_readbytes(state, 0x21, &buf, 1);
187 switch (state->demod_chip) {
189 if ((buf & 0x02) == 0)
201 printk(KERN_WARNING "nxt200x: Error writing multireg register 0x%02X\n",reg);
206 static int nxt200x_readreg_multibyte (struct nxt200x_state* state, u8 reg, u8* data, u8 len)
210 dprintk("%s\n", __FUNCTION__);
212 /* set mutli register register */
213 nxt200x_writebytes(state, 0x35, ®, 1);
215 switch (state->demod_chip) {
217 /* set multi register length */
219 nxt200x_writebytes(state, 0x34, &len2, 1);
221 /* read the actual data */
222 nxt200x_readbytes(state, reg, data, len);
226 /* probably not right, but gives correct values */
234 /* set multi register length */
235 len2 = (attr << 4) | len;
236 nxt200x_writebytes(state, 0x34, &len2, 1);
238 /* toggle the multireg bit*/
240 nxt200x_writebytes(state, 0x21, &buf, 1);
243 nxt200x_readbytes(state, 0x21, &buf, 1);
247 /* read the actual data */
248 for(i = 0; i < len; i++) {
249 nxt200x_readbytes(state, 0x36 + i, &data[i], 1);
259 printk(KERN_WARNING "nxt200x: Error reading multireg register 0x%02X\n",reg);
264 static void nxt200x_microcontroller_stop (struct nxt200x_state* state)
266 u8 buf, stopval, counter = 0;
267 dprintk("%s\n", __FUNCTION__);
269 /* set correct stop value */
270 switch (state->demod_chip) {
283 nxt200x_writebytes(state, 0x22, &buf, 1);
285 while (counter < 20) {
286 nxt200x_readbytes(state, 0x31, &buf, 1);
293 printk(KERN_WARNING "nxt200x: Timeout waiting for nxt200x to stop. This is ok after firmware upload.\n");
297 static void nxt200x_microcontroller_start (struct nxt200x_state* state)
300 dprintk("%s\n", __FUNCTION__);
303 nxt200x_writebytes(state, 0x22, &buf, 1);
306 static void nxt2004_microcontroller_init (struct nxt200x_state* state)
310 dprintk("%s\n", __FUNCTION__);
313 nxt200x_writebytes(state, 0x2b, buf, 1);
315 nxt200x_writebytes(state, 0x34, buf, 1);
317 nxt200x_writebytes(state, 0x35, buf, 1);
318 buf[0] = 0x01; buf[1] = 0x23; buf[2] = 0x45; buf[3] = 0x67; buf[4] = 0x89;
319 buf[5] = 0xAB; buf[6] = 0xCD; buf[7] = 0xEF; buf[8] = 0xC0;
320 nxt200x_writebytes(state, 0x36, buf, 9);
322 nxt200x_writebytes(state, 0x21, buf, 1);
324 while (counter < 20) {
325 nxt200x_readbytes(state, 0x21, buf, 1);
332 printk(KERN_WARNING "nxt200x: Timeout waiting for nxt2004 to init.\n");
337 static int nxt200x_writetuner (struct nxt200x_state* state, u8* data)
341 dprintk("%s\n", __FUNCTION__);
343 dprintk("Tuner Bytes: %02X %02X %02X %02X\n", data[0], data[1], data[2], data[3]);
345 /* if pll is a Philips TUV1236D then write directly to tuner */
346 if (strcmp(state->config->pll_desc->name, "Philips TUV1236D") == 0) {
347 if (i2c_writebytes(state, state->config->pll_address, data, 4))
348 printk(KERN_WARNING "nxt200x: error writing to tuner\n");
349 /* wait until we have a lock */
351 i2c_readbytes(state, state->config->pll_address, &buf, 1);
357 printk("nxt200x: timeout waiting for tuner lock\n");
360 /* set the i2c transfer speed to the tuner */
362 nxt200x_writebytes(state, 0x20, &buf, 1);
364 /* setup to transfer 4 bytes via i2c */
366 nxt200x_writebytes(state, 0x34, &buf, 1);
368 /* write actual tuner bytes */
369 nxt200x_writebytes(state, 0x36, data, 4);
371 /* set tuner i2c address */
372 buf = state->config->pll_address;
373 nxt200x_writebytes(state, 0x35, &buf, 1);
375 /* write UC Opmode to begin transfer */
377 nxt200x_writebytes(state, 0x21, &buf, 1);
380 nxt200x_readbytes(state, 0x21, &buf, 1);
381 if ((buf & 0x80)== 0x00)
386 printk("nxt200x: timeout error writing tuner\n");
391 static void nxt200x_agc_reset(struct nxt200x_state* state)
394 dprintk("%s\n", __FUNCTION__);
396 switch (state->demod_chip) {
399 nxt200x_writebytes(state, 0x08, &buf, 1);
401 nxt200x_writebytes(state, 0x08, &buf, 1);
404 nxt200x_readreg_multibyte(state, 0x08, &buf, 1);
406 nxt200x_writereg_multibyte(state, 0x08, &buf, 1);
408 nxt200x_writereg_multibyte(state, 0x08, &buf, 1);
416 static int nxt2002_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
419 struct nxt200x_state* state = fe->demodulator_priv;
420 u8 buf[3], written = 0, chunkpos = 0;
421 u16 rambase, position, crc = 0;
423 dprintk("%s\n", __FUNCTION__);
424 dprintk("Firmware is %zu bytes\n", fw->size);
426 /* Get the RAM base for this nxt2002 */
427 nxt200x_readbytes(state, 0x10, buf, 1);
434 dprintk("rambase on this nxt2002 is %04X\n", rambase);
436 /* Hold the micro in reset while loading firmware */
438 nxt200x_writebytes(state, 0x2B, buf, 1);
440 for (position = 0; position < fw->size; position++) {
444 buf[0] = ((rambase + position) >> 8);
445 buf[1] = (rambase + position) & 0xFF;
447 /* write starting address */
448 nxt200x_writebytes(state, 0x29, buf, 3);
453 if ((written % 4) == 0)
454 nxt200x_writebytes(state, chunkpos, &fw->data[position-3], 4);
456 crc = nxt200x_crc(crc, fw->data[position]);
458 if ((written == 255) || (position+1 == fw->size)) {
459 /* write remaining bytes of firmware */
460 nxt200x_writebytes(state, chunkpos+4-(written %4),
461 &fw->data[position-(written %4) + 1],
467 nxt200x_writebytes(state, 0x2C, buf, 2);
469 /* do a read to stop things */
470 nxt200x_readbytes(state, 0x2A, buf, 1);
472 /* set transfer mode to complete */
474 nxt200x_writebytes(state, 0x2B, buf, 1);
483 static int nxt2004_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
486 struct nxt200x_state* state = fe->demodulator_priv;
488 u16 rambase, position, crc=0;
490 dprintk("%s\n", __FUNCTION__);
491 dprintk("Firmware is %zu bytes\n", fw->size);
496 /* hold the micro in reset while loading firmware */
498 nxt200x_writebytes(state, 0x2B, buf,1);
500 /* calculate firmware CRC */
501 for (position = 0; position < fw->size; position++) {
502 crc = nxt200x_crc(crc, fw->data[position]);
505 buf[0] = rambase >> 8;
506 buf[1] = rambase & 0xFF;
508 /* write starting address */
509 nxt200x_writebytes(state,0x29,buf,3);
511 for (position = 0; position < fw->size;) {
512 nxt200x_writebytes(state, 0x2C, &fw->data[position],
513 fw->size-position > 255 ? 255 : fw->size-position);
514 position += (fw->size-position > 255 ? 255 : fw->size-position);
519 dprintk("firmware crc is 0x%02X 0x%02X\n", buf[0], buf[1]);
522 nxt200x_writebytes(state, 0x2C, buf,2);
524 /* do a read to stop things */
525 nxt200x_readbytes(state, 0x2C, buf, 1);
527 /* set transfer mode to complete */
529 nxt200x_writebytes(state, 0x2B, buf,1);
534 static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
535 struct dvb_frontend_parameters *p)
537 struct nxt200x_state* state = fe->demodulator_priv;
540 /* stop the micro first */
541 nxt200x_microcontroller_stop(state);
543 if (state->demod_chip == NXT2004) {
544 /* make sure demod is set to digital */
546 nxt200x_writebytes(state, 0x14, buf, 1);
548 nxt200x_writebytes(state, 0x17, buf, 1);
551 /* get tuning information */
552 dvb_pll_configure(state->config->pll_desc, buf, p->frequency, 0);
554 /* set additional params */
555 switch (p->u.vsb.modulation) {
558 /* Set punctured clock for QAM */
559 /* This is just a guess since I am unable to test it */
560 if (state->config->set_ts_params)
561 state->config->set_ts_params(fe, 1);
563 /* set to use cable input */
567 /* Set non-punctured clock for VSB */
568 if (state->config->set_ts_params)
569 state->config->set_ts_params(fe, 0);
576 /* write frequency information */
577 nxt200x_writetuner(state, buf);
579 /* reset the agc now that tuning has been completed */
580 nxt200x_agc_reset(state);
582 /* set target power level */
583 switch (p->u.vsb.modulation) {
595 nxt200x_writebytes(state, 0x42, buf, 1);
598 switch (state->demod_chip) {
609 nxt200x_writebytes(state, 0x57, buf, 1);
611 /* write sdm1 input */
614 nxt200x_writebytes(state, 0x58, buf, 2);
616 /* write sdmx input */
617 switch (p->u.vsb.modulation) {
632 nxt200x_writebytes(state, 0x5C, buf, 2);
634 /* write adc power lpf fc */
636 nxt200x_writebytes(state, 0x43, buf, 1);
638 if (state->demod_chip == NXT2004) {
642 nxt200x_writebytes(state, 0x46, buf, 2);
645 /* write accumulator2 input */
648 nxt200x_writebytes(state, 0x4B, buf, 2);
652 nxt200x_writebytes(state, 0x4D, buf, 1);
654 /* write sdm12 lpf fc */
656 nxt200x_writebytes(state, 0x55, buf, 1);
658 /* write agc control reg */
660 nxt200x_writebytes(state, 0x41, buf, 1);
662 if (state->demod_chip == NXT2004) {
663 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
665 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
668 nxt200x_readreg_multibyte(state, 0x08, buf, 1);
670 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
671 nxt200x_readreg_multibyte(state, 0x08, buf, 1);
673 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
675 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
677 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
679 nxt200x_writereg_multibyte(state, 0x81, buf, 1);
680 buf[0] = 0x80; buf[1] = 0x00; buf[2] = 0x00;
681 nxt200x_writereg_multibyte(state, 0x82, buf, 3);
682 nxt200x_readreg_multibyte(state, 0x88, buf, 1);
684 nxt200x_writereg_multibyte(state, 0x88, buf, 1);
685 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
687 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
690 /* write agc ucgp0 */
691 switch (p->u.vsb.modulation) {
705 nxt200x_writebytes(state, 0x30, buf, 1);
707 /* write agc control reg */
709 nxt200x_writebytes(state, 0x41, buf, 1);
711 /* write accumulator2 input */
714 nxt200x_writebytes(state, 0x49, buf,2);
715 nxt200x_writebytes(state, 0x4B, buf,2);
717 /* write agc control reg */
719 nxt200x_writebytes(state, 0x41, buf, 1);
721 nxt200x_microcontroller_start(state);
723 if (state->demod_chip == NXT2004) {
724 nxt2004_microcontroller_init(state);
729 nxt200x_writebytes(state, 0x5C, buf, 2);
732 /* adjacent channel detection should be done here, but I don't
733 have any stations with this need so I cannot test it */
738 static int nxt200x_read_status(struct dvb_frontend* fe, fe_status_t* status)
740 struct nxt200x_state* state = fe->demodulator_priv;
742 nxt200x_readbytes(state, 0x31, &lock, 1);
746 *status |= FE_HAS_SIGNAL;
747 *status |= FE_HAS_CARRIER;
748 *status |= FE_HAS_VITERBI;
749 *status |= FE_HAS_SYNC;
750 *status |= FE_HAS_LOCK;
755 static int nxt200x_read_ber(struct dvb_frontend* fe, u32* ber)
757 struct nxt200x_state* state = fe->demodulator_priv;
760 nxt200x_readreg_multibyte(state, 0xE6, b, 3);
762 *ber = ((b[0] << 8) + b[1]) * 8;
767 static int nxt200x_read_signal_strength(struct dvb_frontend* fe, u16* strength)
769 struct nxt200x_state* state = fe->demodulator_priv;
773 /* setup to read cluster variance */
775 nxt200x_writebytes(state, 0xA1, b, 1);
777 /* get multreg val */
778 nxt200x_readreg_multibyte(state, 0xA6, b, 2);
780 temp = (b[0] << 8) | b[1];
781 *strength = ((0x7FFF - temp) & 0x0FFF) * 16;
786 static int nxt200x_read_snr(struct dvb_frontend* fe, u16* snr)
789 struct nxt200x_state* state = fe->demodulator_priv;
794 /* setup to read cluster variance */
796 nxt200x_writebytes(state, 0xA1, b, 1);
798 /* get multreg val from 0xA6 */
799 nxt200x_readreg_multibyte(state, 0xA6, b, 2);
801 temp = (b[0] << 8) | b[1];
802 temp2 = 0x7FFF - temp;
804 /* snr will be in db */
806 snrdb = 1000*24 + ( 1000*(30-24) * ( temp2 - 0x7F00 ) / ( 0x7FFF - 0x7F00 ) );
807 else if (temp2 > 0x7EC0)
808 snrdb = 1000*18 + ( 1000*(24-18) * ( temp2 - 0x7EC0 ) / ( 0x7F00 - 0x7EC0 ) );
809 else if (temp2 > 0x7C00)
810 snrdb = 1000*12 + ( 1000*(18-12) * ( temp2 - 0x7C00 ) / ( 0x7EC0 - 0x7C00 ) );
812 snrdb = 1000*0 + ( 1000*(12-0) * ( temp2 - 0 ) / ( 0x7C00 - 0 ) );
814 /* the value reported back from the frontend will be FFFF=32db 0000=0db */
815 *snr = snrdb * (0xFFFF/32000);
820 static int nxt200x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
822 struct nxt200x_state* state = fe->demodulator_priv;
825 nxt200x_readreg_multibyte(state, 0xE6, b, 3);
831 static int nxt200x_sleep(struct dvb_frontend* fe)
836 static int nxt2002_init(struct dvb_frontend* fe)
838 struct nxt200x_state* state = fe->demodulator_priv;
839 const struct firmware *fw;
843 /* request the firmware, this will block until someone uploads it */
844 printk("nxt2002: Waiting for firmware upload (%s)...\n", NXT2002_DEFAULT_FIRMWARE);
845 ret = request_firmware(&fw, NXT2002_DEFAULT_FIRMWARE, &state->i2c->dev);
846 printk("nxt2002: Waiting for firmware upload(2)...\n");
848 printk("nxt2002: No firmware uploaded (timeout or file not found?)\n");
852 ret = nxt2002_load_firmware(fe, fw);
854 printk("nxt2002: Writing firmware to device failed\n");
855 release_firmware(fw);
858 printk("nxt2002: Firmware upload complete\n");
860 /* Put the micro into reset */
861 nxt200x_microcontroller_stop(state);
863 /* ensure transfer is complete */
865 nxt200x_writebytes(state, 0x2B, buf, 1);
867 /* Put the micro into reset for real this time */
868 nxt200x_microcontroller_stop(state);
870 /* soft reset everything (agc,frontend,eq,fec)*/
872 nxt200x_writebytes(state, 0x08, buf, 1);
874 nxt200x_writebytes(state, 0x08, buf, 1);
876 /* write agc sdm configure */
878 nxt200x_writebytes(state, 0x57, buf, 1);
880 /* write mod output format */
882 nxt200x_writebytes(state, 0x09, buf, 1);
884 /* write fec mpeg mode */
887 nxt200x_writebytes(state, 0xE9, buf, 2);
889 /* write mux selection */
891 nxt200x_writebytes(state, 0xCC, buf, 1);
896 static int nxt2004_init(struct dvb_frontend* fe)
898 struct nxt200x_state* state = fe->demodulator_priv;
899 const struct firmware *fw;
905 nxt200x_writebytes(state, 0x1E, buf, 1);
907 /* request the firmware, this will block until someone uploads it */
908 printk("nxt2004: Waiting for firmware upload (%s)...\n", NXT2004_DEFAULT_FIRMWARE);
909 ret = request_firmware(&fw, NXT2004_DEFAULT_FIRMWARE, &state->i2c->dev);
910 printk("nxt2004: Waiting for firmware upload(2)...\n");
912 printk("nxt2004: No firmware uploaded (timeout or file not found?)\n");
916 ret = nxt2004_load_firmware(fe, fw);
918 printk("nxt2004: Writing firmware to device failed\n");
919 release_firmware(fw);
922 printk("nxt2004: Firmware upload complete\n");
924 /* ensure transfer is complete */
926 nxt200x_writebytes(state, 0x19, buf, 1);
928 nxt2004_microcontroller_init(state);
929 nxt200x_microcontroller_stop(state);
930 nxt200x_microcontroller_stop(state);
931 nxt2004_microcontroller_init(state);
932 nxt200x_microcontroller_stop(state);
934 /* soft reset everything (agc,frontend,eq,fec)*/
936 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
938 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
940 /* write agc sdm configure */
942 nxt200x_writebytes(state, 0x57, buf, 1);
947 nxt200x_writebytes(state, 0x35, buf, 2);
949 nxt200x_writebytes(state, 0x34, buf, 1);
951 nxt200x_writebytes(state, 0x21, buf, 1);
955 nxt200x_writebytes(state, 0x0A, buf, 1);
959 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
961 /* write fec mpeg mode */
964 nxt200x_writebytes(state, 0xE9, buf, 2);
966 /* write mux selection */
968 nxt200x_writebytes(state, 0xCC, buf, 1);
971 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
973 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
976 nxt200x_readreg_multibyte(state, 0x08, buf, 1);
978 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
979 nxt200x_readreg_multibyte(state, 0x08, buf, 1);
981 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
984 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
986 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
988 nxt200x_writereg_multibyte(state, 0x81, buf, 1);
989 buf[0] = 0x31; buf[1] = 0x5E; buf[2] = 0x66;
990 nxt200x_writereg_multibyte(state, 0x82, buf, 3);
992 nxt200x_readreg_multibyte(state, 0x88, buf, 1);
994 nxt200x_writereg_multibyte(state, 0x88, buf, 1);
995 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
997 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
999 nxt200x_readbytes(state, 0x10, buf, 1);
1001 nxt200x_writebytes(state, 0x10, buf, 1);
1002 nxt200x_readbytes(state, 0x0A, buf, 1);
1004 nxt200x_writebytes(state, 0x0A, buf, 1);
1006 nxt2004_microcontroller_init(state);
1009 nxt200x_writebytes(state, 0x0A, buf, 1);
1011 nxt200x_writebytes(state, 0xE9, buf, 1);
1013 nxt200x_writebytes(state, 0xEA, buf, 1);
1015 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
1017 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
1018 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
1020 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
1023 nxt200x_readreg_multibyte(state, 0x08, buf, 1);
1025 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
1026 nxt200x_readreg_multibyte(state, 0x08, buf, 1);
1028 nxt200x_writereg_multibyte(state, 0x08, buf, 1);
1030 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
1032 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
1034 nxt200x_writereg_multibyte(state, 0x81, buf, 1);
1035 buf[0] = 0x80; buf[1] = 0x00; buf[2] = 0x00;
1036 nxt200x_writereg_multibyte(state, 0x82, buf, 3);
1038 nxt200x_readreg_multibyte(state, 0x88, buf, 1);
1040 nxt200x_writereg_multibyte(state, 0x88, buf, 1);
1042 nxt200x_readreg_multibyte(state, 0x80, buf, 1);
1044 nxt200x_writereg_multibyte(state, 0x80, buf, 1);
1046 /* initialize tuner */
1047 nxt200x_readbytes(state, 0x10, buf, 1);
1049 nxt200x_writebytes(state, 0x10, buf, 1);
1051 nxt200x_writebytes(state, 0x13, buf, 1);
1053 nxt200x_writebytes(state, 0x16, buf, 1);
1055 nxt200x_writebytes(state, 0x14, buf, 1);
1057 nxt200x_writebytes(state, 0x14, buf, 1);
1058 nxt200x_writebytes(state, 0x17, buf, 1);
1059 nxt200x_writebytes(state, 0x14, buf, 1);
1060 nxt200x_writebytes(state, 0x17, buf, 1);
1065 static int nxt200x_init(struct dvb_frontend* fe)
1067 struct nxt200x_state* state = fe->demodulator_priv;
1070 if (!state->initialised) {
1071 switch (state->demod_chip) {
1073 ret = nxt2002_init(fe);
1076 ret = nxt2004_init(fe);
1082 state->initialised = 1;
1087 static int nxt200x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
1089 fesettings->min_delay_ms = 500;
1090 fesettings->step_size = 0;
1091 fesettings->max_drift = 0;
1095 static void nxt200x_release(struct dvb_frontend* fe)
1097 struct nxt200x_state* state = fe->demodulator_priv;
1101 static struct dvb_frontend_ops nxt200x_ops;
1103 struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
1104 struct i2c_adapter* i2c)
1106 struct nxt200x_state* state = NULL;
1107 u8 buf [] = {0,0,0,0,0};
1109 /* allocate memory for the internal state */
1110 state = (struct nxt200x_state*) kmalloc(sizeof(struct nxt200x_state), GFP_KERNEL);
1113 memset(state,0,sizeof(*state));
1115 /* setup the state */
1116 state->config = config;
1118 memcpy(&state->ops, &nxt200x_ops, sizeof(struct dvb_frontend_ops));
1119 state->initialised = 0;
1122 nxt200x_readbytes(state, 0x00, buf, 5);
1123 dprintk("NXT info: %02X %02X %02X %02X %02X\n",
1124 buf[0], buf[1], buf[2], buf[3], buf[4]);
1126 /* set demod chip */
1129 state->demod_chip = NXT2002;
1130 printk("nxt200x: NXT2002 Detected\n");
1133 state->demod_chip = NXT2004;
1134 printk("nxt200x: NXT2004 Detected\n");
1140 /* make sure demod chip is supported */
1141 switch (state->demod_chip) {
1143 if (buf[0] != 0x04) goto error; /* device id */
1144 if (buf[1] != 0x02) goto error; /* fab id */
1145 if (buf[2] != 0x11) goto error; /* month */
1146 if (buf[3] != 0x20) goto error; /* year msb */
1147 if (buf[4] != 0x00) goto error; /* year lsb */
1150 if (buf[0] != 0x05) goto error; /* device id */
1156 /* create dvb_frontend */
1157 state->frontend.ops = &state->ops;
1158 state->frontend.demodulator_priv = state;
1159 return &state->frontend;
1164 printk("Unknown/Unsupported NXT chip: %02X %02X %02X %02X %02X\n",
1165 buf[0], buf[1], buf[2], buf[3], buf[4]);
1169 static struct dvb_frontend_ops nxt200x_ops = {
1172 .name = "Nextwave NXT200X VSB/QAM frontend",
1174 .frequency_min = 54000000,
1175 .frequency_max = 860000000,
1176 .frequency_stepsize = 166666, /* stepsize is just a guess */
1177 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1178 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1179 FE_CAN_8VSB | FE_CAN_QAM_64 | FE_CAN_QAM_256
1182 .release = nxt200x_release,
1184 .init = nxt200x_init,
1185 .sleep = nxt200x_sleep,
1187 .set_frontend = nxt200x_setup_frontend_parameters,
1188 .get_tune_settings = nxt200x_get_tune_settings,
1190 .read_status = nxt200x_read_status,
1191 .read_ber = nxt200x_read_ber,
1192 .read_signal_strength = nxt200x_read_signal_strength,
1193 .read_snr = nxt200x_read_snr,
1194 .read_ucblocks = nxt200x_read_ucblocks,
1197 module_param(debug, int, 0644);
1198 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
1200 MODULE_DESCRIPTION("NXT200X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
1201 MODULE_AUTHOR("Kirk Lapray, Jean-Francois Thibert, and Taylor Jacob");
1202 MODULE_LICENSE("GPL");
1204 EXPORT_SYMBOL(nxt200x_attach);