blob: b65ba34fd00a9d1e5dc9d4fd7373d97d03c4236a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Support for OR51211 (pcHDTV HD-2000) - VSB
3 *
4 * Copyright (C) 2005 Kirk Lapray <kirk_lapray@bigfoot.com>
5 *
6 * Based on code from Jack Kelliher (kelliher@xmission.com)
7 * Copyright (C) 2002 & pcHDTV, inc.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019*/
20
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -030021#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24 * This driver needs external firmware. Please use the command
Mauro Carvalho Chehabfe63a1a2018-05-08 18:10:05 -030025 * "<kerneldir>/scripts/get_dvb_firmware or51211" to
Ville Skytt\รค12e66f62006-01-09 15:25:38 -020026 * download/extract it, and then copy it to /usr/lib/hotplug/firmware
27 * or /lib/firmware (depending on configuration of firmware hotplug).
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 */
29#define OR51211_DEFAULT_FIRMWARE "dvb-fe-or51211.fw"
30
31#include <linux/kernel.h>
32#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/device.h>
34#include <linux/firmware.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080035#include <linux/string.h>
36#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/byteorder.h>
38
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -050039#include <media/dvb_math.h>
40#include <media/dvb_frontend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "or51211.h"
42
43static int debug;
44#define dprintk(args...) \
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -030045 do { if (debug) pr_debug(args); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47static u8 run_buf[] = {0x7f,0x01};
48static u8 cmd_buf[] = {0x04,0x01,0x50,0x80,0x06}; // ATSC
49
50struct or51211_state {
51
52 struct i2c_adapter* i2c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 /* Configuration settings */
55 const struct or51211_config* config;
56
57 struct dvb_frontend frontend;
58 struct bt878* bt;
59
60 /* Demodulator private data */
61 u8 initialized:1;
Rusty Scott1444e5f2006-12-04 18:04:16 -030062 u32 snr; /* Result of last SNR claculation */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 /* Tuner private data */
65 u32 current_frequency;
66};
67
David Woodhousebc179152008-05-24 00:12:23 +010068static int i2c_writebytes (struct or51211_state* state, u8 reg, const u8 *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 int len)
70{
71 int err;
72 struct i2c_msg msg;
73 msg.addr = reg;
74 msg.flags = 0;
75 msg.len = len;
David Woodhousebc179152008-05-24 00:12:23 +010076 msg.buf = (u8 *)buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -030079 pr_warn("error (addr %02x, err == %i)\n", reg, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 return -EREMOTEIO;
81 }
82
83 return 0;
84}
85
Hans Verkuileda9e4e2008-08-22 17:12:08 -030086static int i2c_readbytes(struct or51211_state *state, u8 reg, u8 *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 int err;
89 struct i2c_msg msg;
90 msg.addr = reg;
91 msg.flags = I2C_M_RD;
92 msg.len = len;
93 msg.buf = buf;
94
95 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -030096 pr_warn("error (addr %02x, err == %i)\n", reg, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return -EREMOTEIO;
98 }
99
100 return 0;
101}
102
103static int or51211_load_firmware (struct dvb_frontend* fe,
104 const struct firmware *fw)
105{
106 struct or51211_state* state = fe->demodulator_priv;
107 u8 tudata[585];
108 int i;
109
Mauro Carvalho Chehab35f30f32014-09-24 20:35:12 -0300110 dprintk("Firmware is %zu bytes\n", fw->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 /* Get eprom data */
113 tudata[0] = 17;
114 if (i2c_writebytes(state,0x50,tudata,1)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300115 pr_warn("error eprom addr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return -1;
117 }
118 if (i2c_readbytes(state,0x50,&tudata[145],192)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300119 pr_warn("error eprom\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return -1;
121 }
122
123 /* Create firmware buffer */
124 for (i = 0; i < 145; i++)
125 tudata[i] = fw->data[i];
126
127 for (i = 0; i < 248; i++)
128 tudata[i+337] = fw->data[145+i];
129
130 state->config->reset(fe);
131
132 if (i2c_writebytes(state,state->config->demod_address,tudata,585)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300133 pr_warn("error 1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return -1;
135 }
136 msleep(1);
137
138 if (i2c_writebytes(state,state->config->demod_address,
139 &fw->data[393],8125)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300140 pr_warn("error 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return -1;
142 }
143 msleep(1);
144
145 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300146 pr_warn("error 3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return -1;
148 }
149
150 /* Wait at least 5 msec */
151 msleep(10);
152 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300153 pr_warn("error 4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return -1;
155 }
156 msleep(10);
157
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300158 pr_info("Done.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return 0;
160};
161
162static int or51211_setmode(struct dvb_frontend* fe, int mode)
163{
164 struct or51211_state* state = fe->demodulator_priv;
165 u8 rec_buf[14];
166
167 state->config->setmode(fe, mode);
168
169 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300170 pr_warn("error 1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return -1;
172 }
173
174 /* Wait at least 5 msec */
175 msleep(10);
176 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300177 pr_warn("error 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return -1;
179 }
180
181 msleep(10);
182
183 /* Set operation mode in Receiver 1 register;
184 * type 1:
185 * data 0x50h Automatic sets receiver channel conditions
186 * Automatic NTSC rejection filter
187 * Enable MPEG serial data output
188 * MPEG2tr
189 * High tuner phase noise
190 * normal +/-150kHz Carrier acquisition range
191 */
192 if (i2c_writebytes(state,state->config->demod_address,cmd_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300193 pr_warn("error 3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return -1;
195 }
196
197 rec_buf[0] = 0x04;
198 rec_buf[1] = 0x00;
199 rec_buf[2] = 0x03;
200 rec_buf[3] = 0x00;
201 msleep(20);
202 if (i2c_writebytes(state,state->config->demod_address,rec_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300203 pr_warn("error 5\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205 msleep(3);
206 if (i2c_readbytes(state,state->config->demod_address,&rec_buf[10],2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300207 pr_warn("error 6\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return -1;
209 }
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300210 dprintk("rec status %02x %02x\n", rec_buf[10], rec_buf[11]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 return 0;
213}
214
Mauro Carvalho Chehabd42c0862011-12-26 15:02:20 -0300215static int or51211_set_parameters(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Mauro Carvalho Chehabd42c0862011-12-26 15:02:20 -0300217 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 struct or51211_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /* Change only if we are actually changing the channel */
Mauro Carvalho Chehabd42c0862011-12-26 15:02:20 -0300221 if (state->current_frequency != p->frequency) {
Michael Krufkycd2cd0a2007-06-24 18:14:52 -0300222 if (fe->ops.tuner_ops.set_params) {
Mauro Carvalho Chehab14d24d12011-12-24 12:24:33 -0300223 fe->ops.tuner_ops.set_params(fe);
Michael Krufkycd2cd0a2007-06-24 18:14:52 -0300224 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 /* Set to ATSC mode */
228 or51211_setmode(fe,0);
229
230 /* Update current frequency */
Mauro Carvalho Chehabd42c0862011-12-26 15:02:20 -0300231 state->current_frequency = p->frequency;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233 return 0;
234}
235
Mauro Carvalho Chehab0df289a2015-06-07 14:53:52 -0300236static int or51211_read_status(struct dvb_frontend *fe, enum fe_status *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 struct or51211_state* state = fe->demodulator_priv;
239 unsigned char rec_buf[2];
240 unsigned char snd_buf[] = {0x04,0x00,0x03,0x00};
241 *status = 0;
242
243 /* Receiver Status */
244 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300245 pr_warn("write error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return -1;
247 }
248 msleep(3);
249 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300250 pr_warn("read error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return -1;
252 }
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300253 dprintk("%x %x\n", rec_buf[0], rec_buf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 if (rec_buf[0] & 0x01) { /* Receiver Lock */
256 *status |= FE_HAS_SIGNAL;
257 *status |= FE_HAS_CARRIER;
258 *status |= FE_HAS_VITERBI;
259 *status |= FE_HAS_SYNC;
260 *status |= FE_HAS_LOCK;
261 }
262 return 0;
263}
264
Rusty Scott1444e5f2006-12-04 18:04:16 -0300265/* Calculate SNR estimation (scaled by 2^24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Rusty Scott1444e5f2006-12-04 18:04:16 -0300267 8-VSB SNR equation from Oren datasheets
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Rusty Scott1444e5f2006-12-04 18:04:16 -0300269 For 8-VSB:
270 SNR[dB] = 10 * log10(219037.9454 / MSE^2 )
271
272 We re-write the snr equation as:
273 SNR * 2^24 = 10*(c - 2*intlog10(MSE))
274 Where for 8-VSB, c = log10(219037.9454) * 2^24 */
275
276static u32 calculate_snr(u32 mse, u32 c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Rusty Scott1444e5f2006-12-04 18:04:16 -0300278 if (mse == 0) /* No signal */
279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Rusty Scott1444e5f2006-12-04 18:04:16 -0300281 mse = 2*intlog10(mse);
282 if (mse > c) {
283 /* Negative SNR, which is possible, but realisticly the
284 demod will lose lock before the signal gets this bad. The
285 API only allows for unsigned values, so just return 0 */
286 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
Rusty Scott1444e5f2006-12-04 18:04:16 -0300288 return 10*(c - mse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
291static int or51211_read_snr(struct dvb_frontend* fe, u16* snr)
292{
293 struct or51211_state* state = fe->demodulator_priv;
294 u8 rec_buf[2];
Rusty Scott1444e5f2006-12-04 18:04:16 -0300295 u8 snd_buf[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /* SNR after Equalizer */
298 snd_buf[0] = 0x04;
299 snd_buf[1] = 0x00;
300 snd_buf[2] = 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300303 pr_warn("error writing snr reg\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return -1;
305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300307 pr_warn("read_status read error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 return -1;
309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Rusty Scott1444e5f2006-12-04 18:04:16 -0300311 state->snr = calculate_snr(rec_buf[0], 89599047);
312 *snr = (state->snr) >> 16;
313
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300314 dprintk("noise = 0x%02x, snr = %d.%02d dB\n", rec_buf[0],
Rusty Scott1444e5f2006-12-04 18:04:16 -0300315 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
316
317 return 0;
318}
319
320static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength)
321{
322 /* Calculate Strength from SNR up to 35dB */
323 /* Even though the SNR can go higher than 35dB, there is some comfort */
324 /* factor in having a range of strong signals that can show at 100% */
325 struct or51211_state* state = (struct or51211_state*)fe->demodulator_priv;
326 u16 snr;
327 int ret;
328
329 ret = fe->ops.read_snr(fe, &snr);
330 if (ret != 0)
331 return ret;
332 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
333 /* scale the range 0 - 35*2^24 into 0 - 65535 */
334 if (state->snr >= 8960 * 0x10000)
335 *strength = 0xffff;
336 else
337 *strength = state->snr / 8960;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 return 0;
340}
341
342static int or51211_read_ber(struct dvb_frontend* fe, u32* ber)
343{
344 *ber = -ENOSYS;
345 return 0;
346}
347
348static int or51211_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
349{
350 *ucblocks = -ENOSYS;
351 return 0;
352}
353
354static int or51211_sleep(struct dvb_frontend* fe)
355{
356 return 0;
357}
358
359static int or51211_init(struct dvb_frontend* fe)
360{
361 struct or51211_state* state = fe->demodulator_priv;
362 const struct or51211_config* config = state->config;
363 const struct firmware* fw;
364 unsigned char get_ver_buf[] = {0x04,0x00,0x30,0x00,0x00};
365 unsigned char rec_buf[14];
366 int ret,i;
367
368 if (!state->initialized) {
369 /* Request the firmware, this will block until it uploads */
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300370 pr_info("Waiting for firmware upload (%s)...\n",
371 OR51211_DEFAULT_FIRMWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 ret = config->request_firmware(fe, &fw,
373 OR51211_DEFAULT_FIRMWARE);
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300374 pr_info("Got Hotplug firmware\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (ret) {
Mauro Carvalho Chehab4bd69e72016-10-18 17:44:22 -0200376 pr_warn("No firmware uploaded (timeout or file not found?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return ret;
378 }
379
380 ret = or51211_load_firmware(fe, fw);
Magnus Damm73ca66b2006-07-10 04:44:09 -0700381 release_firmware(fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (ret) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300383 pr_warn("Writing firmware to device failed!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return ret;
385 }
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300386 pr_info("Firmware upload complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 /* Set operation mode in Receiver 1 register;
389 * type 1:
390 * data 0x50h Automatic sets receiver channel conditions
391 * Automatic NTSC rejection filter
392 * Enable MPEG serial data output
393 * MPEG2tr
394 * High tuner phase noise
395 * normal +/-150kHz Carrier acquisition range
396 */
397 if (i2c_writebytes(state,state->config->demod_address,
398 cmd_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300399 pr_warn("Load DVR Error 5\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return -1;
401 }
402
403 /* Read back ucode version to besure we loaded correctly */
404 /* and are really up and running */
405 rec_buf[0] = 0x04;
406 rec_buf[1] = 0x00;
407 rec_buf[2] = 0x03;
408 rec_buf[3] = 0x00;
409 msleep(30);
410 if (i2c_writebytes(state,state->config->demod_address,
411 rec_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300412 pr_warn("Load DVR Error A\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return -1;
414 }
415 msleep(3);
416 if (i2c_readbytes(state,state->config->demod_address,
417 &rec_buf[10],2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300418 pr_warn("Load DVR Error B\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return -1;
420 }
421
422 rec_buf[0] = 0x04;
423 rec_buf[1] = 0x00;
424 rec_buf[2] = 0x01;
425 rec_buf[3] = 0x00;
426 msleep(20);
427 if (i2c_writebytes(state,state->config->demod_address,
428 rec_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300429 pr_warn("Load DVR Error C\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return -1;
431 }
432 msleep(3);
433 if (i2c_readbytes(state,state->config->demod_address,
434 &rec_buf[12],2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300435 pr_warn("Load DVR Error D\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return -1;
437 }
438
439 for (i = 0; i < 8; i++)
440 rec_buf[i]=0xed;
441
442 for (i = 0; i < 5; i++) {
443 msleep(30);
444 get_ver_buf[4] = i+1;
445 if (i2c_writebytes(state,state->config->demod_address,
446 get_ver_buf,5)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300447 pr_warn("Load DVR Error 6 - %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return -1;
449 }
450 msleep(3);
451
452 if (i2c_readbytes(state,state->config->demod_address,
453 &rec_buf[i*2],2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300454 pr_warn("Load DVR Error 7 - %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return -1;
456 }
457 /* If we didn't receive the right index, try again */
458 if ((int)rec_buf[i*2+1]!=i+1){
459 i--;
460 }
461 }
Andy Shevchenko870f31c2012-12-17 22:10:00 -0300462 dprintk("read_fwbits %10ph\n", rec_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300464 pr_info("ver TU%02x%02x%02x VSB mode %02x Status %02x\n",
465 rec_buf[2], rec_buf[4], rec_buf[6], rec_buf[12],
466 rec_buf[10]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 rec_buf[0] = 0x04;
469 rec_buf[1] = 0x00;
470 rec_buf[2] = 0x03;
471 rec_buf[3] = 0x00;
472 msleep(20);
473 if (i2c_writebytes(state,state->config->demod_address,
474 rec_buf,3)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300475 pr_warn("Load DVR Error 8\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return -1;
477 }
478 msleep(20);
479 if (i2c_readbytes(state,state->config->demod_address,
480 &rec_buf[8],2)) {
Andy Shevchenkobb9e31f2012-12-18 10:20:28 -0300481 pr_warn("Load DVR Error 9\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 return -1;
483 }
484 state->initialized = 1;
485 }
486
487 return 0;
488}
489
490static int or51211_get_tune_settings(struct dvb_frontend* fe,
491 struct dvb_frontend_tune_settings* fesettings)
492{
493 fesettings->min_delay_ms = 500;
494 fesettings->step_size = 0;
495 fesettings->max_drift = 0;
496 return 0;
497}
498
499static void or51211_release(struct dvb_frontend* fe)
500{
501 struct or51211_state* state = fe->demodulator_priv;
502 state->config->sleep(fe);
503 kfree(state);
504}
505
Max Kellermannbd336e62016-08-09 18:32:21 -0300506static const struct dvb_frontend_ops or51211_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508struct dvb_frontend* or51211_attach(const struct or51211_config* config,
509 struct i2c_adapter* i2c)
510{
511 struct or51211_state* state = NULL;
512
513 /* Allocate memory for the internal state */
Matthias Schwarzott084e24a2009-08-10 22:51:01 -0300514 state = kzalloc(sizeof(struct or51211_state), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (state == NULL)
Mauro Carvalho Chehab3473e342008-01-07 10:45:47 -0300516 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 /* Setup the state */
519 state->config = config;
520 state->i2c = i2c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 state->initialized = 0;
522 state->current_frequency = 0;
523
524 /* Create dvb_frontend */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300525 memcpy(&state->frontend.ops, &or51211_ops, sizeof(struct dvb_frontend_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 state->frontend.demodulator_priv = state;
527 return &state->frontend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
Max Kellermannbd336e62016-08-09 18:32:21 -0300530static const struct dvb_frontend_ops or51211_ops = {
Mauro Carvalho Chehabd42c0862011-12-26 15:02:20 -0300531 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .info = {
533 .name = "Oren OR51211 VSB Frontend",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .frequency_min = 44000000,
535 .frequency_max = 958000000,
536 .frequency_stepsize = 166666,
537 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
538 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
539 FE_CAN_8VSB
540 },
541
542 .release = or51211_release,
543
544 .init = or51211_init,
545 .sleep = or51211_sleep,
546
Mauro Carvalho Chehabd42c0862011-12-26 15:02:20 -0300547 .set_frontend = or51211_set_parameters,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .get_tune_settings = or51211_get_tune_settings,
549
550 .read_status = or51211_read_status,
551 .read_ber = or51211_read_ber,
552 .read_signal_strength = or51211_read_signal_strength,
553 .read_snr = or51211_read_snr,
554 .read_ucblocks = or51211_read_ucblocks,
555};
556
557module_param(debug, int, 0644);
558MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
559
560MODULE_DESCRIPTION("Oren OR51211 VSB [pcHDTV HD-2000] Demodulator Driver");
561MODULE_AUTHOR("Kirk Lapray");
562MODULE_LICENSE("GPL");
563
564EXPORT_SYMBOL(or51211_attach);
565