aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2007-03-02 17:42:21 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-04-27 14:44:09 -0400
commitd9e54324d03add27990ac27fcb34a1ae7a0f97ef (patch)
treee13d27678b2c33464266f23fd1ae085eb9eb0afd /drivers/media/dvb/frontends
parent387e69adff3d441616b45002ff85c5b36001be9e (diff)
V4L/DVB (5374): Or51132: refactor i2c code, improve error resilience
The code the i2c transactions was leftover from the old V4L-based ATSC driver. It did too little with too much code. It is re-written to remove unnecessary parameters and be more efficient. A demod register can now be read with one function call, instead of repeating a dozen line block of code each time. There were msleep()'s, which appear to be unnecessary, spread around all the I2C transactions. These have been removed. Reading SNR used to take about 130 ms, now it's down to 1.8 ms. Reads from the demodulator's registers do not return correct results sometimes. Adding or removing the delays in the I2C transactions did not appear to effect the probability of failure. If anything, the transactions without delays were less likely to fail, but since far more transactions could be made per second the number of failures per hour was greater. To increase reliability, the SNR and get_params functions will now retry once if they get bad data back. This appears to have reduced the probability of failure to effectively zero. Some error messages are cleaned up or given KERN_* levels when they were missing. or51132_setmode() wasn't returning correct error codes, which is fixed as well. CC: Rusty Scott <rustys@ieee.org> Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/frontends')
-rw-r--r--drivers/media/dvb/frontends/or51132.c305
1 files changed, 127 insertions, 178 deletions
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index 5a3a6e53cda2..4e0aca7c67aa 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -1,6 +1,9 @@
1/* 1/*
2 * Support for OR51132 (pcHDTV HD-3000) - VSB/QAM 2 * Support for OR51132 (pcHDTV HD-3000) - VSB/QAM
3 * 3 *
4 *
5 * Copyright (C) 2007 Trent Piepho <xyzzy@speakeasy.org>
6 *
4 * Copyright (C) 2005 Kirk Lapray <kirk_lapray@bigfoot.com> 7 * Copyright (C) 2005 Kirk Lapray <kirk_lapray@bigfoot.com>
5 * 8 *
6 * Based on code from Jack Kelliher (kelliher@xmission.com) 9 * Based on code from Jack Kelliher (kelliher@xmission.com)
@@ -69,46 +72,70 @@ struct or51132_state
69 u32 current_frequency; 72 u32 current_frequency;
70}; 73};
71 74
72static int i2c_writebytes (struct or51132_state* state, u8 reg, u8 *buf, int len) 75
76/* Write buffer to demod */
77static int or51132_writebuf(struct or51132_state *state, const u8 *buf, int len)
73{ 78{
74 int err; 79 int err;
75 struct i2c_msg msg; 80 struct i2c_msg msg = { .addr = state->config->demod_address,
76 msg.addr = reg; 81 .flags = 0, .buf = (u8*)buf, .len = len };
77 msg.flags = 0;
78 msg.len = len;
79 msg.buf = buf;
80 82
83 /* msleep(20); */ /* doesn't appear to be necessary */
81 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 84 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
82 printk(KERN_WARNING "or51132: i2c_writebytes error (addr %02x, err == %i)\n", reg, err); 85 printk(KERN_WARNING "or51132: I2C write (addr 0x%02x len %d) error: %d\n",
86 msg.addr, msg.len, err);
83 return -EREMOTEIO; 87 return -EREMOTEIO;
84 } 88 }
85
86 return 0; 89 return 0;
87} 90}
88 91
89static u8 i2c_readbytes (struct or51132_state* state, u8 reg, u8* buf, int len) 92/* Write constant bytes, e.g. or51132_writebytes(state, 0x04, 0x42, 0x00);
93 Less code and more efficient that loading a buffer on the stack with
94 the bytes to send and then calling or51132_writebuf() on that. */
95#define or51132_writebytes(state, data...) \
96 ({ const static u8 _data[] = {data}; \
97 or51132_writebuf(state, _data, sizeof(_data)); })
98
99/* Read data from demod into buffer. Returns 0 on success. */
100static int or51132_readbuf(struct or51132_state *state, u8 *buf, int len)
90{ 101{
91 int err; 102 int err;
92 struct i2c_msg msg; 103 struct i2c_msg msg = { .addr = state->config->demod_address,
93 msg.addr = reg; 104 .flags = I2C_M_RD, .buf = buf, .len = len };
94 msg.flags = I2C_M_RD;
95 msg.len = len;
96 msg.buf = buf;
97 105
106 /* msleep(20); */ /* doesn't appear to be necessary */
98 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 107 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
99 printk(KERN_WARNING "or51132: i2c_readbytes error (addr %02x, err == %i)\n", reg, err); 108 printk(KERN_WARNING "or51132: I2C read (addr 0x%02x len %d) error: %d\n",
109 msg.addr, msg.len, err);
100 return -EREMOTEIO; 110 return -EREMOTEIO;
101 } 111 }
102
103 return 0; 112 return 0;
104} 113}
105 114
115/* Reads a 16-bit demod register. Returns <0 on error. */
116static int or51132_readreg(struct or51132_state *state, u8 reg)
117{
118 u8 buf[2] = { 0x04, reg };
119 struct i2c_msg msg[2] = {
120 {.addr = state->config->demod_address, .flags = 0,
121 .buf = buf, .len = 2 },
122 {.addr = state->config->demod_address, .flags = I2C_M_RD,
123 .buf = buf, .len = 2 }};
124 int err;
125
126 if ((err = i2c_transfer(state->i2c, msg, 2)) != 2) {
127 printk(KERN_WARNING "or51132: I2C error reading register %d: %d\n",
128 reg, err);
129 return -EREMOTEIO;
130 }
131 return le16_to_cpup((u16*)buf);
132}
133
106static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware *fw) 134static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
107{ 135{
108 struct or51132_state* state = fe->demodulator_priv; 136 struct or51132_state* state = fe->demodulator_priv;
109 static u8 run_buf[] = {0x7F,0x01}; 137 const static u8 run_buf[] = {0x7F,0x01};
110 u8 rec_buf[8]; 138 u8 rec_buf[8];
111 u8 cmd_buf[3];
112 u32 firmwareAsize, firmwareBsize; 139 u32 firmwareAsize, firmwareBsize;
113 int i,ret; 140 int i,ret;
114 141
@@ -121,30 +148,21 @@ static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware
121 dprintk("FirmwareB is %i bytes\n",firmwareBsize); 148 dprintk("FirmwareB is %i bytes\n",firmwareBsize);
122 149
123 /* Upload firmware */ 150 /* Upload firmware */
124 if ((ret = i2c_writebytes(state,state->config->demod_address, 151 if ((ret = or51132_writebuf(state, &fw->data[8], firmwareAsize))) {
125 &fw->data[8],firmwareAsize))) {
126 printk(KERN_WARNING "or51132: load_firmware error 1\n"); 152 printk(KERN_WARNING "or51132: load_firmware error 1\n");
127 return ret; 153 return ret;
128 } 154 }
129 msleep(1); /* 1ms */ 155 if ((ret = or51132_writebuf(state, &fw->data[8+firmwareAsize],
130 if ((ret = i2c_writebytes(state,state->config->demod_address, 156 firmwareBsize))) {
131 &fw->data[8+firmwareAsize],firmwareBsize))) {
132 printk(KERN_WARNING "or51132: load_firmware error 2\n"); 157 printk(KERN_WARNING "or51132: load_firmware error 2\n");
133 return ret; 158 return ret;
134 } 159 }
135 msleep(1); /* 1ms */
136 160
137 if ((ret = i2c_writebytes(state,state->config->demod_address, 161 if ((ret = or51132_writebuf(state, run_buf, 2))) {
138 run_buf,2))) {
139 printk(KERN_WARNING "or51132: load_firmware error 3\n"); 162 printk(KERN_WARNING "or51132: load_firmware error 3\n");
140 return ret; 163 return ret;
141 } 164 }
142 165 if ((ret = or51132_writebuf(state, run_buf, 2))) {
143 /* Wait at least 5 msec */
144 msleep(20); /* 10ms */
145
146 if ((ret = i2c_writebytes(state,state->config->demod_address,
147 run_buf,2))) {
148 printk(KERN_WARNING "or51132: load_firmware error 4\n"); 166 printk(KERN_WARNING "or51132: load_firmware error 4\n");
149 return ret; 167 return ret;
150 } 168 }
@@ -154,43 +172,25 @@ static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware
154 172
155 /* Read back ucode version to besure we loaded correctly and are really up and running */ 173 /* Read back ucode version to besure we loaded correctly and are really up and running */
156 /* Get uCode version */ 174 /* Get uCode version */
157 cmd_buf[0] = 0x10; 175 if ((ret = or51132_writebytes(state, 0x10, 0x10, 0x00))) {
158 cmd_buf[1] = 0x10;
159 cmd_buf[2] = 0x00;
160 msleep(20); /* 20ms */
161 if ((ret = i2c_writebytes(state,state->config->demod_address,
162 cmd_buf,3))) {
163 printk(KERN_WARNING "or51132: load_firmware error a\n"); 176 printk(KERN_WARNING "or51132: load_firmware error a\n");
164 return ret; 177 return ret;
165 } 178 }
166 179 if ((ret = or51132_writebytes(state, 0x04, 0x17))) {
167 cmd_buf[0] = 0x04;
168 cmd_buf[1] = 0x17;
169 msleep(20); /* 20ms */
170 if ((ret = i2c_writebytes(state,state->config->demod_address,
171 cmd_buf,2))) {
172 printk(KERN_WARNING "or51132: load_firmware error b\n"); 180 printk(KERN_WARNING "or51132: load_firmware error b\n");
173 return ret; 181 return ret;
174 } 182 }
175 183 if ((ret = or51132_writebytes(state, 0x00, 0x00))) {
176 cmd_buf[0] = 0x00;
177 cmd_buf[1] = 0x00;
178 msleep(20); /* 20ms */
179 if ((ret = i2c_writebytes(state,state->config->demod_address,
180 cmd_buf,2))) {
181 printk(KERN_WARNING "or51132: load_firmware error c\n"); 184 printk(KERN_WARNING "or51132: load_firmware error c\n");
182 return ret; 185 return ret;
183 } 186 }
184 187 for (i=0;i<4;i++) {
185 for(i=0;i<4;i++) {
186 msleep(20); /* 20ms */
187 /* Once upon a time, this command might have had something 188 /* Once upon a time, this command might have had something
188 to do with getting the firmware version, but it's 189 to do with getting the firmware version, but it's
189 not used anymore: 190 not used anymore:
190 {0x04,0x00,0x30,0x00,i+1} */ 191 {0x04,0x00,0x30,0x00,i+1} */
191 /* Read 8 bytes, two bytes at a time */ 192 /* Read 8 bytes, two bytes at a time */
192 if ((ret = i2c_readbytes(state,state->config->demod_address, 193 if ((ret = or51132_readbuf(state, &rec_buf[i*2], 2))) {
193 &rec_buf[i*2],2))) {
194 printk(KERN_WARNING 194 printk(KERN_WARNING
195 "or51132: load_firmware error d - %d\n",i); 195 "or51132: load_firmware error d - %d\n",i);
196 return ret; 196 return ret;
@@ -204,12 +204,7 @@ static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware
204 rec_buf[3],rec_buf[2]>>4,rec_buf[2]&0x0f, 204 rec_buf[3],rec_buf[2]>>4,rec_buf[2]&0x0f,
205 rec_buf[5],rec_buf[4]>>4,rec_buf[4]&0x0f); 205 rec_buf[5],rec_buf[4]>>4,rec_buf[4]&0x0f);
206 206
207 cmd_buf[0] = 0x10; 207 if ((ret = or51132_writebytes(state, 0x10, 0x00, 0x00))) {
208 cmd_buf[1] = 0x00;
209 cmd_buf[2] = 0x00;
210 msleep(20); /* 20ms */
211 if ((ret = i2c_writebytes(state,state->config->demod_address,
212 cmd_buf,3))) {
213 printk(KERN_WARNING "or51132: load_firmware error e\n"); 208 printk(KERN_WARNING "or51132: load_firmware error e\n");
214 return ret; 209 return ret;
215 } 210 }
@@ -241,70 +236,55 @@ static int or51132_sleep(struct dvb_frontend* fe)
241static int or51132_setmode(struct dvb_frontend* fe) 236static int or51132_setmode(struct dvb_frontend* fe)
242{ 237{
243 struct or51132_state* state = fe->demodulator_priv; 238 struct or51132_state* state = fe->demodulator_priv;
244 unsigned char cmd_buf[3]; 239 u8 cmd_buf1[3] = {0x04, 0x01, 0x5f};
240 u8 cmd_buf2[3] = {0x1c, 0x00, 0 };
245 241
246 dprintk("setmode %d\n",(int)state->current_modulation); 242 dprintk("setmode %d\n",(int)state->current_modulation);
247 /* set operation mode in Receiver 1 register; */ 243
248 cmd_buf[0] = 0x04;
249 cmd_buf[1] = 0x01;
250 switch (state->current_modulation) { 244 switch (state->current_modulation) {
251 case QAM_256:
252 case QAM_64:
253 case QAM_AUTO:
254 /* Auto-deinterleave; MPEG ser, MPEG2tr, phase noise-high*/
255 cmd_buf[2] = 0x5F;
256 break;
257 case VSB_8: 245 case VSB_8:
258 /* Auto CH, Auto NTSC rej, MPEGser, MPEG2tr, phase noise-high*/ 246 /* Auto CH, Auto NTSC rej, MPEGser, MPEG2tr, phase noise-high */
259 cmd_buf[2] = 0x50; 247 cmd_buf1[2] = 0x50;
248 /* REC MODE inv IF spectrum, Normal */
249 cmd_buf2[1] = 0x03;
250 /* Channel MODE ATSC/VSB8 */
251 cmd_buf2[2] = 0x06;
260 break; 252 break;
261 default: 253 /* All QAM modes are:
262 printk("setmode:Modulation set to unsupported value\n"); 254 Auto-deinterleave; MPEGser, MPEG2tr, phase noise-high
263 }; 255 REC MODE Normal Carrier Lock */
264 if (i2c_writebytes(state,state->config->demod_address,
265 cmd_buf,3)) {
266 printk(KERN_WARNING "or51132: set_mode error 1\n");
267 return -1;
268 }
269 dprintk("or51132: set #1 to %02x\n", cmd_buf[2]);
270
271 /* Set operation mode in Receiver 6 register */
272 cmd_buf[0] = 0x1C;
273 switch (state->current_modulation) {
274 case QAM_AUTO: 256 case QAM_AUTO:
275 /* REC MODE Normal Carrier Lock */
276 cmd_buf[1] = 0x00;
277 /* Channel MODE Auto QAM64/256 */ 257 /* Channel MODE Auto QAM64/256 */
278 cmd_buf[2] = 0x4f; 258 cmd_buf2[2] = 0x4f;
279 break; 259 break;
280 case QAM_256: 260 case QAM_256:
281 /* REC MODE Normal Carrier Lock */
282 cmd_buf[1] = 0x00;
283 /* Channel MODE QAM256 */ 261 /* Channel MODE QAM256 */
284 cmd_buf[2] = 0x45; 262 cmd_buf2[2] = 0x45;
285 break; 263 break;
286 case QAM_64: 264 case QAM_64:
287 /* REC MODE Normal Carrier Lock */
288 cmd_buf[1] = 0x00;
289 /* Channel MODE QAM64 */ 265 /* Channel MODE QAM64 */
290 cmd_buf[2] = 0x43; 266 cmd_buf2[2] = 0x43;
291 break;
292 case VSB_8:
293 /* REC MODE inv IF spectrum, Normal */
294 cmd_buf[1] = 0x03;
295 /* Channel MODE ATSC/VSB8 */
296 cmd_buf[2] = 0x06;
297 break; 267 break;
298 default: 268 default:
299 printk("setmode: Modulation set to unsupported value\n"); 269 printk(KERN_WARNING
300 }; 270 "or51132: setmode: Modulation set to unsupported value (%d)\n",
301 msleep(20); /* 20ms */ 271 state->current_modulation);
302 if (i2c_writebytes(state,state->config->demod_address, 272 return -EINVAL;
303 cmd_buf,3)) { 273 }
274
275 /* Set Receiver 1 register */
276 if (or51132_writebuf(state, cmd_buf1, 3)) {
277 printk(KERN_WARNING "or51132: set_mode error 1\n");
278 return -EREMOTEIO;
279 }
280 dprintk("set #1 to %02x\n", cmd_buf1[2]);
281
282 /* Set operation mode in Receiver 6 register */
283 if (or51132_writebuf(state, cmd_buf2, 3)) {
304 printk(KERN_WARNING "or51132: set_mode error 2\n"); 284 printk(KERN_WARNING "or51132: set_mode error 2\n");
305 return -1; 285 return -EREMOTEIO;
306 } 286 }
307 dprintk("or51132: set #6 to 0x%02x%02x\n", cmd_buf[1], cmd_buf[2]); 287 dprintk("set #6 to 0x%02x%02x\n", cmd_buf2[1], cmd_buf2[2]);
308 288
309 return 0; 289 return 0;
310} 290}
@@ -401,28 +381,23 @@ static int or51132_get_parameters(struct dvb_frontend* fe,
401 struct dvb_frontend_parameters *param) 381 struct dvb_frontend_parameters *param)
402{ 382{
403 struct or51132_state* state = fe->demodulator_priv; 383 struct or51132_state* state = fe->demodulator_priv;
404 u8 buf[2]; 384 int status;
385 int retry = 1;
405 386
387start:
406 /* Receiver Status */ 388 /* Receiver Status */
407 buf[0]=0x04; 389 if ((status = or51132_readreg(state, 0x00)) < 0) {
408 buf[1]=0x00; 390 printk(KERN_WARNING "or51132: get_parameters: error reading receiver status\n");
409 msleep(30); /* 30ms */
410 if (i2c_writebytes(state,state->config->demod_address,buf,2)) {
411 printk(KERN_WARNING "or51132: get_parameters write error\n");
412 return -EREMOTEIO;
413 }
414 msleep(30); /* 30ms */
415 if (i2c_readbytes(state,state->config->demod_address,buf,2)) {
416 printk(KERN_WARNING "or51132: get_parameters read error\n");
417 return -EREMOTEIO; 391 return -EREMOTEIO;
418 } 392 }
419 switch(buf[0]) { 393 switch(status&0xff) {
420 case 0x06: param->u.vsb.modulation = VSB_8; break; 394 case 0x06: param->u.vsb.modulation = VSB_8; break;
421 case 0x43: param->u.vsb.modulation = QAM_64; break; 395 case 0x43: param->u.vsb.modulation = QAM_64; break;
422 case 0x45: param->u.vsb.modulation = QAM_256; break; 396 case 0x45: param->u.vsb.modulation = QAM_256; break;
423 default: 397 default:
398 if (retry--) goto start;
424 printk(KERN_WARNING "or51132: unknown status 0x%02x\n", 399 printk(KERN_WARNING "or51132: unknown status 0x%02x\n",
425 buf[0]); 400 status&0xff);
426 return -EREMOTEIO; 401 return -EREMOTEIO;
427 } 402 }
428 403
@@ -438,32 +413,21 @@ static int or51132_get_parameters(struct dvb_frontend* fe,
438static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status) 413static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status)
439{ 414{
440 struct or51132_state* state = fe->demodulator_priv; 415 struct or51132_state* state = fe->demodulator_priv;
441 unsigned char rec_buf[2]; 416 int reg;
442 unsigned char snd_buf[2];
443 *status = 0;
444 417
445 /* Receiver Status */ 418 /* Receiver Status */
446 snd_buf[0]=0x04; 419 if ((reg = or51132_readreg(state, 0x00)) < 0) {
447 snd_buf[1]=0x00; 420 printk(KERN_WARNING "or51132: read_status: error reading receiver status: %d\n", reg);
448 msleep(30); /* 30ms */ 421 *status = 0;
449 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) { 422 return -EREMOTEIO;
450 printk(KERN_WARNING "or51132: read_status write error\n");
451 return -1;
452 }
453 msleep(30); /* 30ms */
454 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
455 printk(KERN_WARNING "or51132: read_status read error\n");
456 return -1;
457 }
458 dprintk("read_status %x %x\n",rec_buf[0],rec_buf[1]);
459
460 if (rec_buf[1] & 0x01) { /* Receiver Lock */
461 *status |= FE_HAS_SIGNAL;
462 *status |= FE_HAS_CARRIER;
463 *status |= FE_HAS_VITERBI;
464 *status |= FE_HAS_SYNC;
465 *status |= FE_HAS_LOCK;
466 } 423 }
424 dprintk("%s: read_status %04x\n", __FUNCTION__, reg);
425
426 if (reg & 0x0100) /* Receiver Lock */
427 *status = FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI|
428 FE_HAS_SYNC|FE_HAS_LOCK;
429 else
430 *status = 0;
467 return 0; 431 return 0;
468} 432}
469 433
@@ -506,47 +470,30 @@ static u32 calculate_snr(u32 mse, u32 c)
506static int or51132_read_snr(struct dvb_frontend* fe, u16* snr) 470static int or51132_read_snr(struct dvb_frontend* fe, u16* snr)
507{ 471{
508 struct or51132_state* state = fe->demodulator_priv; 472 struct or51132_state* state = fe->demodulator_priv;
509 u8 rec_buf[2]; 473 int noise, reg;
510 u8 snd_buf[2]; 474 u32 c, usK = 0;
511 u32 noise; 475 int retry = 1;
512 u32 c; 476
513 u32 usK; 477start:
514 478 /* SNR after Equalizer */
515 /* Register is same for VSB or QAM firmware */ 479 noise = or51132_readreg(state, 0x02);
516 snd_buf[0]=0x04; 480 if (noise < 0) {
517 snd_buf[1]=0x02; /* SNR after Equalizer */ 481 printk(KERN_WARNING "or51132: read_snr: error reading equalizer\n");
518 msleep(30); /* 30ms */
519 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
520 printk(KERN_WARNING "or51132: snr write error\n");
521 return -EREMOTEIO;
522 }
523 msleep(30); /* 30ms */
524 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
525 printk(KERN_WARNING "or51132: snr read error\n");
526 return -EREMOTEIO; 482 return -EREMOTEIO;
527 } 483 }
528 noise = rec_buf[0] | (rec_buf[1] << 8); 484 dprintk("read_snr noise (%d)\n", noise);
529 dprintk("read_snr noise %x %x (%i)\n",rec_buf[0],rec_buf[1],noise);
530 485
531 /* Read status, contains modulation type for QAM_AUTO and 486 /* Read status, contains modulation type for QAM_AUTO and
532 NTSC filter for VSB */ 487 NTSC filter for VSB */
533 snd_buf[0]=0x04; 488 reg = or51132_readreg(state, 0x00);
534 snd_buf[1]=0x00; /* Status register */ 489 if (reg < 0) {
535 msleep(30); /* 30ms */ 490 printk(KERN_WARNING "or51132: read_snr: error reading receiver status\n");
536 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
537 printk(KERN_WARNING "or51132: status write error\n");
538 return -EREMOTEIO;
539 }
540 msleep(30); /* 30ms */
541 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
542 printk(KERN_WARNING "or51132: status read error\n");
543 return -EREMOTEIO; 491 return -EREMOTEIO;
544 } 492 }
545 493
546 usK = 0; 494 switch (reg&0xff) {
547 switch (rec_buf[0]) {
548 case 0x06: 495 case 0x06:
549 usK = (rec_buf[1] & 0x10) ? 0x03000000 : 0; 496 if (reg & 0x1000) usK = 3 << 24;
550 /* Fall through to QAM64 case */ 497 /* Fall through to QAM64 case */
551 case 0x43: 498 case 0x43:
552 c = 150204167; 499 c = 150204167;
@@ -555,11 +502,12 @@ static int or51132_read_snr(struct dvb_frontend* fe, u16* snr)
555 c = 150290396; 502 c = 150290396;
556 break; 503 break;
557 default: 504 default:
558 printk(KERN_ERR "or51132: unknown status 0x%02x\n", rec_buf[0]); 505 printk(KERN_WARNING "or51132: unknown status 0x%02x\n", reg&0xff);
506 if (retry--) goto start;
559 return -EREMOTEIO; 507 return -EREMOTEIO;
560 } 508 }
561 dprintk("%s: modulation %02x, NTSC rej O%s\n", __FUNCTION__, 509 dprintk("%s: modulation %02x, NTSC rej O%s\n", __FUNCTION__,
562 rec_buf[0], rec_buf[1]&0x10?"n":"ff"); 510 reg&0xff, reg&0x1000?"n":"ff");
563 511
564 /* Calculate SNR using noise, c, and NTSC rejection correction */ 512 /* Calculate SNR using noise, c, and NTSC rejection correction */
565 state->snr = calculate_snr(noise, c) - usK; 513 state->snr = calculate_snr(noise, c) - usK;
@@ -671,6 +619,7 @@ MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
671 619
672MODULE_DESCRIPTION("OR51132 ATSC [pcHDTV HD-3000] (8VSB & ITU J83 AnnexB FEC QAM64/256) Demodulator Driver"); 620MODULE_DESCRIPTION("OR51132 ATSC [pcHDTV HD-3000] (8VSB & ITU J83 AnnexB FEC QAM64/256) Demodulator Driver");
673MODULE_AUTHOR("Kirk Lapray"); 621MODULE_AUTHOR("Kirk Lapray");
622MODULE_AUTHOR("Trent Piepho");
674MODULE_LICENSE("GPL"); 623MODULE_LICENSE("GPL");
675 624
676EXPORT_SYMBOL(or51132_attach); 625EXPORT_SYMBOL(or51132_attach);