aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/bt8xx/dst.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/bt8xx/dst.c')
-rw-r--r--drivers/media/dvb/bt8xx/dst.c969
1 files changed, 633 insertions, 336 deletions
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index eac83768dfd0..1339912c308b 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1,25 +1,25 @@
1/* 1/*
2 Frontend-driver for TwinHan DST Frontend
3 2
4 Copyright (C) 2003 Jamie Honan 3 Frontend/Card driver for TwinHan DST Frontend
4 Copyright (C) 2003 Jamie Honan
5 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
5 6
6 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 10 (at your option) any later version.
10 11
11 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 15 GNU General Public License for more details.
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 20*/
22 21
22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -31,59 +31,22 @@
31 31
32#include "dvb_frontend.h" 32#include "dvb_frontend.h"
33#include "dst_priv.h" 33#include "dst_priv.h"
34#include "dst.h" 34#include "dst_common.h"
35 35
36struct dst_state {
37
38 struct i2c_adapter* i2c;
39
40 struct bt878* bt;
41
42 struct dvb_frontend_ops ops;
43
44 /* configuration settings */
45 const struct dst_config* config;
46
47 struct dvb_frontend frontend;
48
49 /* private demodulator data */
50 u8 tx_tuna[10];
51 u8 rx_tuna[10];
52 u8 rxbuffer[10];
53 u8 diseq_flags;
54 u8 dst_type;
55 u32 type_flags;
56 u32 frequency; /* intermediate frequency in kHz for QPSK */
57 fe_spectral_inversion_t inversion;
58 u32 symbol_rate; /* symbol rate in Symbols per second */
59 fe_code_rate_t fec;
60 fe_sec_voltage_t voltage;
61 fe_sec_tone_mode_t tone;
62 u32 decode_freq;
63 u8 decode_lock;
64 u16 decode_strength;
65 u16 decode_snr;
66 unsigned long cur_jiff;
67 u8 k22;
68 fe_bandwidth_t bandwidth;
69};
70 36
71static unsigned int dst_verbose = 0; 37static unsigned int verbose = 1;
72module_param(dst_verbose, int, 0644); 38module_param(verbose, int, 0644);
73MODULE_PARM_DESC(dst_verbose, "verbose startup messages, default is 1 (yes)"); 39MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
74static unsigned int dst_debug = 0;
75module_param(dst_debug, int, 0644);
76MODULE_PARM_DESC(dst_debug, "debug messages, default is 0 (no)");
77 40
78#define dprintk if (dst_debug) printk 41static unsigned int debug = 1;
42module_param(debug, int, 0644);
43MODULE_PARM_DESC(debug, "debug messages, default is 0 (yes)");
79 44
80#define DST_TYPE_IS_SAT 0 45static unsigned int dst_addons;
81#define DST_TYPE_IS_TERR 1 46module_param(dst_addons, int, 0644);
82#define DST_TYPE_IS_CABLE 2 47MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
83 48
84#define DST_TYPE_HAS_NEWTUNE 1 49#define dprintk if (debug) printk
85#define DST_TYPE_HAS_TS204 2
86#define DST_TYPE_HAS_SYMDIV 4
87 50
88#define HAS_LOCK 1 51#define HAS_LOCK 1
89#define ATTEMPT_TUNE 2 52#define ATTEMPT_TUNE 2
@@ -97,7 +60,7 @@ static void dst_packsize(struct dst_state* state, int psize)
97 bt878_device_control(state->bt, DST_IG_TS, &bits); 60 bt878_device_control(state->bt, DST_IG_TS, &bits);
98} 61}
99 62
100static int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh) 63int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay)
101{ 64{
102 union dst_gpio_packet enb; 65 union dst_gpio_packet enb;
103 union dst_gpio_packet bits; 66 union dst_gpio_packet bits;
@@ -105,26 +68,33 @@ static int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhig
105 68
106 enb.enb.mask = mask; 69 enb.enb.mask = mask;
107 enb.enb.enable = enbb; 70 enb.enb.enable = enbb;
71 if (verbose > 4)
72 dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__, mask, enbb, outhigh);
73
108 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) { 74 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
109 dprintk("%s: dst_gpio_enb error (err == %i, mask == 0x%02x, enb == 0x%02x)\n", __FUNCTION__, err, mask, enbb); 75 dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__, err, mask, enbb);
110 return -EREMOTEIO; 76 return -EREMOTEIO;
111 } 77 }
112 78 udelay(1000);
113 /* because complete disabling means no output, no need to do output packet */ 79 /* because complete disabling means no output, no need to do output packet */
114 if (enbb == 0) 80 if (enbb == 0)
115 return 0; 81 return 0;
116 82
83 if (delay)
84 msleep(10);
85
117 bits.outp.mask = enbb; 86 bits.outp.mask = enbb;
118 bits.outp.highvals = outhigh; 87 bits.outp.highvals = outhigh;
119 88
120 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) { 89 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
121 dprintk("%s: dst_gpio_outb error (err == %i, enbb == 0x%02x, outhigh == 0x%02x)\n", __FUNCTION__, err, enbb, outhigh); 90 dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__, err, enbb, outhigh);
122 return -EREMOTEIO; 91 return -EREMOTEIO;
123 } 92 }
124 return 0; 93 return 0;
125} 94}
95EXPORT_SYMBOL(dst_gpio_outb);
126 96
127static int dst_gpio_inb(struct dst_state *state, u8 * result) 97int dst_gpio_inb(struct dst_state *state, u8 * result)
128{ 98{
129 union dst_gpio_packet rd_packet; 99 union dst_gpio_packet rd_packet;
130 int err; 100 int err;
@@ -139,143 +109,225 @@ static int dst_gpio_inb(struct dst_state *state, u8 * result)
139 *result = (u8) rd_packet.rd.value; 109 *result = (u8) rd_packet.rd.value;
140 return 0; 110 return 0;
141} 111}
112EXPORT_SYMBOL(dst_gpio_inb);
142 113
143#define DST_I2C_ENABLE 1 114int rdc_reset_state(struct dst_state *state)
144#define DST_8820 2
145
146static int dst_reset8820(struct dst_state *state)
147{ 115{
148 int retval; 116 if (verbose > 1)
149 /* pull 8820 gpio pin low, wait, high, wait, then low */ 117 dprintk("%s: Resetting state machine\n", __FUNCTION__);
150 // dprintk ("%s: reset 8820\n", __FUNCTION__); 118
151 retval = dst_gpio_outb(state, DST_8820, DST_8820, 0); 119 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
152 if (retval < 0) 120 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
153 return retval; 121 return -1;
122 }
123
154 msleep(10); 124 msleep(10);
155 retval = dst_gpio_outb(state, DST_8820, DST_8820, DST_8820); 125
156 if (retval < 0) 126 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
157 return retval; 127 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
158 /* wait for more feedback on what works here * 128 msleep(10);
159 msleep(10); 129 return -1;
160 retval = dst_gpio_outb(dst, DST_8820, DST_8820, 0); 130 }
161 if (retval < 0) 131
162 return retval;
163 */
164 return 0; 132 return 0;
165} 133}
134EXPORT_SYMBOL(rdc_reset_state);
166 135
167static int dst_i2c_enable(struct dst_state *state) 136int rdc_8820_reset(struct dst_state *state)
168{ 137{
169 int retval; 138 if (verbose > 1)
170 /* pull I2C enable gpio pin low, wait */ 139 dprintk("%s: Resetting DST\n", __FUNCTION__);
171 // dprintk ("%s: i2c enable\n", __FUNCTION__); 140
172 retval = dst_gpio_outb(state, ~0, DST_I2C_ENABLE, 0); 141 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
173 if (retval < 0) 142 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
174 return retval; 143 return -1;
175 // dprintk ("%s: i2c enable delay\n", __FUNCTION__); 144 }
176 msleep(33); 145 udelay(1000);
146 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
147 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
148 return -1;
149 }
150
177 return 0; 151 return 0;
178} 152}
153EXPORT_SYMBOL(rdc_8820_reset);
179 154
180static int dst_i2c_disable(struct dst_state *state) 155int dst_pio_enable(struct dst_state *state)
181{ 156{
182 int retval; 157 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
183 /* release I2C enable gpio pin, wait */ 158 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
184 // dprintk ("%s: i2c disable\n", __FUNCTION__); 159 return -1;
185 retval = dst_gpio_outb(state, ~0, 0, 0); 160 }
186 if (retval < 0) 161 udelay(1000);
187 return retval; 162 return 0;
188 // dprintk ("%s: i2c disable delay\n", __FUNCTION__); 163}
189 msleep(33); 164EXPORT_SYMBOL(dst_pio_enable);
165
166int dst_pio_disable(struct dst_state *state)
167{
168 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
169 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
170 return -1;
171 }
172 if (state->type_flags & DST_TYPE_HAS_FW_1)
173 udelay(1000);
174
190 return 0; 175 return 0;
191} 176}
177EXPORT_SYMBOL(dst_pio_disable);
192 178
193static int dst_wait_dst_ready(struct dst_state *state) 179int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
194{ 180{
195 u8 reply; 181 u8 reply;
196 int retval;
197 int i; 182 int i;
183
198 for (i = 0; i < 200; i++) { 184 for (i = 0; i < 200; i++) {
199 retval = dst_gpio_inb(state, &reply); 185 if (dst_gpio_inb(state, &reply) < 0) {
200 if (retval < 0) 186 dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__);
201 return retval; 187 return -1;
202 if ((reply & DST_I2C_ENABLE) == 0) { 188 }
203 dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i); 189
190 if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
191 if (verbose > 4)
192 dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i);
204 return 1; 193 return 1;
205 } 194 }
206 msleep(10); 195 msleep(10);
207 } 196 }
208 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i); 197 if (verbose > 1)
198 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i);
199
200 return 0;
201}
202EXPORT_SYMBOL(dst_wait_dst_ready);
203
204int dst_error_recovery(struct dst_state *state)
205{
206 dprintk("%s: Trying to return from previous errors...\n", __FUNCTION__);
207 dst_pio_disable(state);
208 msleep(10);
209 dst_pio_enable(state);
210 msleep(10);
211
209 return 0; 212 return 0;
210} 213}
214EXPORT_SYMBOL(dst_error_recovery);
215
216int dst_error_bailout(struct dst_state *state)
217{
218 dprintk("%s: Trying to bailout from previous error...\n", __FUNCTION__);
219 rdc_8820_reset(state);
220 dst_pio_disable(state);
221 msleep(10);
222
223 return 0;
224}
225EXPORT_SYMBOL(dst_error_bailout);
226
227
228int dst_comm_init(struct dst_state* state)
229{
230 if (verbose > 1)
231 dprintk ("%s: Initializing DST..\n", __FUNCTION__);
232 if ((dst_pio_enable(state)) < 0) {
233 dprintk("%s: PIO Enable Failed.\n", __FUNCTION__);
234 return -1;
235 }
236 if ((rdc_reset_state(state)) < 0) {
237 dprintk("%s: RDC 8820 State RESET Failed.\n", __FUNCTION__);
238 return -1;
239 }
240 if (state->type_flags & DST_TYPE_HAS_FW_1)
241 msleep(100);
242 else
243 msleep(5);
244
245 return 0;
246}
247EXPORT_SYMBOL(dst_comm_init);
248
211 249
212static int write_dst(struct dst_state *state, u8 * data, u8 len) 250int write_dst(struct dst_state *state, u8 *data, u8 len)
213{ 251{
214 struct i2c_msg msg = { 252 struct i2c_msg msg = {
215 .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len 253 .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len
216 }; 254 };
255
217 int err; 256 int err;
218 int cnt; 257 int cnt;
219 258 if (debug && (verbose > 4)) {
220 if (dst_debug && dst_verbose) {
221 u8 i; 259 u8 i;
222 dprintk("%s writing", __FUNCTION__); 260 if (verbose > 4) {
223 for (i = 0; i < len; i++) { 261 dprintk("%s writing", __FUNCTION__);
224 dprintk(" 0x%02x", data[i]); 262 for (i = 0; i < len; i++)
263 dprintk(" %02x", data[i]);
264 dprintk("\n");
225 } 265 }
226 dprintk("\n");
227 } 266 }
228 msleep(30); 267 for (cnt = 0; cnt < 2; cnt++) {
229 for (cnt = 0; cnt < 4; cnt++) {
230 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { 268 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
231 dprintk("%s: write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]); 269 dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]);
232 dst_i2c_disable(state); 270 dst_error_recovery(state);
233 msleep(500);
234 dst_i2c_enable(state);
235 msleep(500);
236 continue; 271 continue;
237 } else 272 } else
238 break; 273 break;
239 } 274 }
240 if (cnt >= 4) 275
241 return -EREMOTEIO; 276 if (cnt >= 2) {
277 if (verbose > 1)
278 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
279 dst_error_bailout(state);
280
281 return -1;
282 }
283
242 return 0; 284 return 0;
243} 285}
286EXPORT_SYMBOL(write_dst);
244 287
245static int read_dst(struct dst_state *state, u8 * ret, u8 len) 288int read_dst(struct dst_state *state, u8 * ret, u8 len)
246{ 289{
247 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len }; 290 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len };
248 int err; 291 int err;
249 int cnt; 292 int cnt;
250 293
251 for (cnt = 0; cnt < 4; cnt++) { 294 for (cnt = 0; cnt < 2; cnt++) {
252 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { 295 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
296
253 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]); 297 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]);
254 dst_i2c_disable(state); 298 dst_error_recovery(state);
255 dst_i2c_enable(state); 299
256 continue; 300 continue;
257 } else 301 } else
258 break; 302 break;
259 } 303 }
260 if (cnt >= 4) 304 if (cnt >= 2) {
261 return -EREMOTEIO; 305 if (verbose > 1)
262 dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]); 306 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
263 if (dst_debug && dst_verbose) { 307 dst_error_bailout(state);
308
309 return -1;
310 }
311 if (debug && (verbose > 4)) {
312 dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]);
264 for (err = 1; err < len; err++) 313 for (err = 1; err < len; err++)
265 dprintk(" 0x%x", ret[err]); 314 dprintk(" 0x%x", ret[err]);
266 if (err > 1) 315 if (err > 1)
267 dprintk("\n"); 316 dprintk("\n");
268 } 317 }
318
269 return 0; 319 return 0;
270} 320}
321EXPORT_SYMBOL(read_dst);
271 322
272static int dst_set_freq(struct dst_state *state, u32 freq) 323static int dst_set_freq(struct dst_state *state, u32 freq)
273{ 324{
274 u8 *val; 325 u8 *val;
275 326
276 state->frequency = freq; 327 state->frequency = freq;
328 if (debug > 4)
329 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
277 330
278 // dprintk("%s: set frequency %u\n", __FUNCTION__, freq);
279 if (state->dst_type == DST_TYPE_IS_SAT) { 331 if (state->dst_type == DST_TYPE_IS_SAT) {
280 freq = freq / 1000; 332 freq = freq / 1000;
281 if (freq < 950 || freq > 2150) 333 if (freq < 950 || freq > 2150)
@@ -398,7 +450,8 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
398 if (state->dst_type == DST_TYPE_IS_TERR) { 450 if (state->dst_type == DST_TYPE_IS_TERR) {
399 return 0; 451 return 0;
400 } 452 }
401 // dprintk("%s: set srate %u\n", __FUNCTION__, srate); 453 if (debug > 4)
454 dprintk("%s: set symrate %u\n", __FUNCTION__, srate);
402 srate /= 1000; 455 srate /= 1000;
403 val = &state->tx_tuna[0]; 456 val = &state->tx_tuna[0];
404 457
@@ -407,7 +460,10 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
407 sval <<= 20; 460 sval <<= 20;
408 do_div(sval, 88000); 461 do_div(sval, 88000);
409 symcalc = (u32) sval; 462 symcalc = (u32) sval;
410 // dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc); 463
464 if (debug > 4)
465 dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc);
466
411 val[5] = (u8) (symcalc >> 12); 467 val[5] = (u8) (symcalc >> 12);
412 val[6] = (u8) (symcalc >> 4); 468 val[6] = (u8) (symcalc >> 4);
413 val[7] = (u8) (symcalc << 4); 469 val[7] = (u8) (symcalc << 4);
@@ -422,7 +478,7 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
422 return 0; 478 return 0;
423} 479}
424 480
425static u8 dst_check_sum(u8 * buf, u32 len) 481u8 dst_check_sum(u8 * buf, u32 len)
426{ 482{
427 u32 i; 483 u32 i;
428 u8 val = 0; 484 u8 val = 0;
@@ -433,28 +489,7 @@ static u8 dst_check_sum(u8 * buf, u32 len)
433 } 489 }
434 return ((~val) + 1); 490 return ((~val) + 1);
435} 491}
436 492EXPORT_SYMBOL(dst_check_sum);
437struct dst_types {
438 char *mstr;
439 int offs;
440 u8 dst_type;
441 u32 type_flags;
442};
443
444static struct dst_types dst_tlist[] = {
445 {"DST-020", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV},
446 {"DST-030", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE},
447 {"DST-03T", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204},
448 {"DST-MOT", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV},
449 {"DST-CI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE},
450 {"DSTMCI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_NEWTUNE},
451 {"DSTFCI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_NEWTUNE},
452 {"DCTNEW", 1, DST_TYPE_IS_CABLE, DST_TYPE_HAS_NEWTUNE},
453 {"DCT-CI", 1, DST_TYPE_IS_CABLE, DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_TS204},
454 {"DTTDIG", 1, DST_TYPE_IS_TERR, 0}
455};
456
457/* DCTNEW and DCT-CI are guesses */
458 493
459static void dst_type_flags_print(u32 type_flags) 494static void dst_type_flags_print(u32 type_flags)
460{ 495{
@@ -465,93 +500,270 @@ static void dst_type_flags_print(u32 type_flags)
465 printk(" 0x%x ts204", DST_TYPE_HAS_TS204); 500 printk(" 0x%x ts204", DST_TYPE_HAS_TS204);
466 if (type_flags & DST_TYPE_HAS_SYMDIV) 501 if (type_flags & DST_TYPE_HAS_SYMDIV)
467 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV); 502 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
503 if (type_flags & DST_TYPE_HAS_FW_1)
504 printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
505 if (type_flags & DST_TYPE_HAS_FW_2)
506 printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
507 if (type_flags & DST_TYPE_HAS_FW_3)
508 printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
509// if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw)
510
468 printk("\n"); 511 printk("\n");
469} 512}
470 513
471static int dst_type_print(u8 type) 514
515static int dst_type_print (u8 type)
472{ 516{
473 char *otype; 517 char *otype;
474 switch (type) { 518 switch (type) {
475 case DST_TYPE_IS_SAT: 519 case DST_TYPE_IS_SAT:
476 otype = "satellite"; 520 otype = "satellite";
477 break; 521 break;
522
478 case DST_TYPE_IS_TERR: 523 case DST_TYPE_IS_TERR:
479 otype = "terrestrial"; 524 otype = "terrestrial";
480 break; 525 break;
526
481 case DST_TYPE_IS_CABLE: 527 case DST_TYPE_IS_CABLE:
482 otype = "cable"; 528 otype = "cable";
483 break; 529 break;
530
484 default: 531 default:
485 printk("%s: invalid dst type %d\n", __FUNCTION__, type); 532 printk("%s: invalid dst type %d\n", __FUNCTION__, type);
486 return -EINVAL; 533 return -EINVAL;
487 } 534 }
488 printk("DST type : %s\n", otype); 535 printk("DST type : %s\n", otype);
536
489 return 0; 537 return 0;
490} 538}
491 539
492static int dst_check_ci(struct dst_state *state) 540/*
541 Known cards list
542 Satellite
543 -------------------
544 200103A
545 VP-1020 DST-MOT LG(old), TS=188
546
547 VP-1020 DST-03T LG(new), TS=204
548 VP-1022 DST-03T LG(new), TS=204
549 VP-1025 DST-03T LG(new), TS=204
550
551 VP-1030 DSTMCI, LG(new), TS=188
552 VP-1032 DSTMCI, LG(new), TS=188
553
554 Cable
555 -------------------
556 VP-2030 DCT-CI, Samsung, TS=204
557 VP-2021 DCT-CI, Unknown, TS=204
558 VP-2031 DCT-CI, Philips, TS=188
559 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
560 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
561
562 Terrestrial
563 -------------------
564 VP-3050 DTTNXT TS=188
565 VP-3040 DTT-CI, Philips, TS=188
566 VP-3040 DTT-CI, Philips, TS=204
567
568 ATSC
569 -------------------
570 VP-3220 ATSCDI, TS=188
571 VP-3250 ATSCAD, TS=188
572
573*/
574
575struct dst_types dst_tlist[] = {
576 {
577 .device_id = "200103A",
578 .offset = 0,
579 .dst_type = DST_TYPE_IS_SAT,
580 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
581 .dst_feature = 0
582 }, /* obsolete */
583
584 {
585 .device_id = "DST-020",
586 .offset = 0,
587 .dst_type = DST_TYPE_IS_SAT,
588 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
589 .dst_feature = 0
590 }, /* obsolete */
591
592 {
593 .device_id = "DST-030",
594 .offset = 0,
595 .dst_type = DST_TYPE_IS_SAT,
596 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
597 .dst_feature = 0
598 }, /* obsolete */
599
600 {
601 .device_id = "DST-03T",
602 .offset = 0,
603 .dst_type = DST_TYPE_IS_SAT,
604 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
605 .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
606 | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO
607 },
608
609 {
610 .device_id = "DST-MOT",
611 .offset = 0,
612 .dst_type = DST_TYPE_IS_SAT,
613 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
614 .dst_feature = 0
615 }, /* obsolete */
616
617 {
618 .device_id = "DST-CI",
619 .offset = 1,
620 .dst_type = DST_TYPE_IS_SAT,
621 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
622 .dst_feature = DST_TYPE_HAS_CA
623 }, /* An OEM board */
624
625 {
626 .device_id = "DSTMCI",
627 .offset = 1,
628 .dst_type = DST_TYPE_IS_SAT,
629 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
630 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
631 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
632 },
633
634 {
635 .device_id = "DSTFCI",
636 .offset = 1,
637 .dst_type = DST_TYPE_IS_SAT,
638 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
639 .dst_feature = 0
640 }, /* unknown to vendor */
641
642 {
643 .device_id = "DCT-CI",
644 .offset = 1,
645 .dst_type = DST_TYPE_IS_CABLE,
646 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
647 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
648 .dst_feature = DST_TYPE_HAS_CA
649 },
650
651 {
652 .device_id = "DCTNEW",
653 .offset = 1,
654 .dst_type = DST_TYPE_IS_CABLE,
655 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3,
656 .dst_feature = 0
657 },
658
659 {
660 .device_id = "DTT-CI",
661 .offset = 1,
662 .dst_type = DST_TYPE_IS_TERR,
663 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
664 .dst_feature = 0
665 },
666
667 {
668 .device_id = "DTTDIG",
669 .offset = 1,
670 .dst_type = DST_TYPE_IS_TERR,
671 .type_flags = DST_TYPE_HAS_FW_2,
672 .dst_feature = 0
673 },
674
675 {
676 .device_id = "DTTNXT",
677 .offset = 1,
678 .dst_type = DST_TYPE_IS_TERR,
679 .type_flags = DST_TYPE_HAS_FW_2,
680 .dst_feature = DST_TYPE_HAS_ANALOG
681 },
682
683 {
684 .device_id = "ATSCDI",
685 .offset = 1,
686 .dst_type = DST_TYPE_IS_ATSC,
687 .type_flags = DST_TYPE_HAS_FW_2,
688 .dst_feature = 0
689 },
690
691 {
692 .device_id = "ATSCAD",
693 .offset = 1,
694 .dst_type = DST_TYPE_IS_ATSC,
695 .type_flags = DST_TYPE_HAS_FW_2,
696 .dst_feature = 0
697 },
698
699 { }
700
701};
702
703
704static int dst_get_device_id(struct dst_state *state)
493{ 705{
494 u8 txbuf[8]; 706 u8 reply;
495 u8 rxbuf[8]; 707
496 int retval;
497 int i; 708 int i;
498 struct dst_types *dsp; 709 struct dst_types *p_dst_type;
499 u8 use_dst_type; 710 u8 use_dst_type = 0;
500 u32 use_type_flags; 711 u32 use_type_flags = 0;
501 712
502 memset(txbuf, 0, sizeof(txbuf)); 713 static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
503 txbuf[1] = 6;
504 txbuf[7] = dst_check_sum(txbuf, 7);
505 714
506 dst_i2c_enable(state); 715 device_type[7] = dst_check_sum(device_type, 7);
507 dst_reset8820(state); 716
508 retval = write_dst(state, txbuf, 8); 717 if (write_dst(state, device_type, FIXED_COMM))
509 if (retval < 0) { 718 return -1; /* Write failed */
510 dst_i2c_disable(state); 719
511 dprintk("%s: write not successful, maybe no card?\n", __FUNCTION__); 720 if ((dst_pio_disable(state)) < 0)
512 return retval; 721 return -1;
513 } 722
514 msleep(3); 723 if (read_dst(state, &reply, GET_ACK))
515 retval = read_dst(state, rxbuf, 1); 724 return -1; /* Read failure */
516 dst_i2c_disable(state); 725
517 if (retval < 0) { 726 if (reply != ACK) {
518 dprintk("%s: read not successful, maybe no card?\n", __FUNCTION__); 727 dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__, reply);
519 return retval; 728 return -1; /* Unack'd write */
520 }
521 if (rxbuf[0] != 0xff) {
522 dprintk("%s: write reply not 0xff, not ci (%02x)\n", __FUNCTION__, rxbuf[0]);
523 return retval;
524 }
525 if (!dst_wait_dst_ready(state))
526 return 0;
527 // dst_i2c_enable(i2c); Dimitri
528 retval = read_dst(state, rxbuf, 8);
529 dst_i2c_disable(state);
530 if (retval < 0) {
531 dprintk("%s: read not successful\n", __FUNCTION__);
532 return retval;
533 } 729 }
534 if (rxbuf[7] != dst_check_sum(rxbuf, 7)) { 730
535 dprintk("%s: checksum failure\n", __FUNCTION__); 731 if (!dst_wait_dst_ready(state, DEVICE_INIT))
536 return retval; 732 return -1; /* DST not ready yet */
733
734 if (read_dst(state, state->rxbuffer, FIXED_COMM))
735 return -1;
736
737 dst_pio_disable(state);
738
739 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
740 dprintk("%s: Checksum failure! \n", __FUNCTION__);
741 return -1; /* Checksum failure */
537 } 742 }
538 rxbuf[7] = '\0'; 743
539 for (i = 0, dsp = &dst_tlist[0]; i < sizeof(dst_tlist) / sizeof(dst_tlist[0]); i++, dsp++) { 744 state->rxbuffer[7] = '\0';
540 if (!strncmp(&rxbuf[dsp->offs], dsp->mstr, strlen(dsp->mstr))) { 745
541 use_type_flags = dsp->type_flags; 746 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE (dst_tlist); i++, p_dst_type++) {
542 use_dst_type = dsp->dst_type; 747 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
543 printk("%s: recognize %s\n", __FUNCTION__, dsp->mstr); 748 use_type_flags = p_dst_type->type_flags;
749 use_dst_type = p_dst_type->dst_type;
750
751 /* Card capabilities */
752 state->dst_hw_cap = p_dst_type->dst_feature;
753 printk ("%s: Recognise [%s]\n", __FUNCTION__, p_dst_type->device_id);
754
544 break; 755 break;
545 } 756 }
546 } 757 }
547 if (i >= sizeof(dst_tlist) / sizeof(dst_tlist[0])) { 758
548 printk("%s: unable to recognize %s or %s\n", __FUNCTION__, &rxbuf[0], &rxbuf[1]); 759 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
549 printk("%s please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__); 760 printk("%s: Unable to recognize %s or %s\n", __FUNCTION__, &state->rxbuffer[0], &state->rxbuffer[1]);
761 printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__);
550 use_dst_type = DST_TYPE_IS_SAT; 762 use_dst_type = DST_TYPE_IS_SAT;
551 use_type_flags = DST_TYPE_HAS_SYMDIV; 763 use_type_flags = DST_TYPE_HAS_SYMDIV;
552 } 764 }
553 dst_type_print(use_dst_type);
554 765
766 dst_type_print(use_dst_type);
555 state->type_flags = use_type_flags; 767 state->type_flags = use_type_flags;
556 state->dst_type = use_dst_type; 768 state->dst_type = use_dst_type;
557 dst_type_flags_print(state->type_flags); 769 dst_type_flags_print(state->type_flags);
@@ -559,50 +771,102 @@ static int dst_check_ci(struct dst_state *state)
559 if (state->type_flags & DST_TYPE_HAS_TS204) { 771 if (state->type_flags & DST_TYPE_HAS_TS204) {
560 dst_packsize(state, 204); 772 dst_packsize(state, 204);
561 } 773 }
774
562 return 0; 775 return 0;
563} 776}
564 777
565static int dst_command(struct dst_state* state, u8 * data, u8 len) 778static int dst_probe(struct dst_state *state)
779{
780 if ((rdc_8820_reset(state)) < 0) {
781 dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__);
782 return -1;
783 }
784 if (dst_addons & DST_TYPE_HAS_CA)
785 msleep(4000);
786 else
787 msleep(100);
788
789 if ((dst_comm_init(state)) < 0) {
790 dprintk("%s: DST Initialization Failed.\n", __FUNCTION__);
791 return -1;
792 }
793 msleep(100);
794 if (dst_get_device_id(state) < 0) {
795 dprintk("%s: unknown device.\n", __FUNCTION__);
796 return -1;
797 }
798
799 return 0;
800}
801
802int dst_command(struct dst_state* state, u8 * data, u8 len)
566{ 803{
567 int retval;
568 u8 reply; 804 u8 reply;
805 if ((dst_comm_init(state)) < 0) {
806 dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__);
807 return -1;
808 }
569 809
570 dst_i2c_enable(state); 810 if (write_dst(state, data, len)) {
571 dst_reset8820(state); 811 if (verbose > 1)
572 retval = write_dst(state, data, len); 812 dprintk("%s: Tring to recover.. \n", __FUNCTION__);
573 if (retval < 0) { 813 if ((dst_error_recovery(state)) < 0) {
574 dst_i2c_disable(state); 814 dprintk("%s: Recovery Failed.\n", __FUNCTION__);
575 dprintk("%s: write not successful\n", __FUNCTION__); 815 return -1;
576 return retval; 816 }
817 return -1;
577 } 818 }
578 msleep(33); 819 if ((dst_pio_disable(state)) < 0) {
579 retval = read_dst(state, &reply, 1); 820 dprintk("%s: PIO Disable Failed.\n", __FUNCTION__);
580 dst_i2c_disable(state); 821 return -1;
581 if (retval < 0) {
582 dprintk("%s: read verify not successful\n", __FUNCTION__);
583 return retval;
584 } 822 }
585 if (reply != 0xff) { 823 if (state->type_flags & DST_TYPE_HAS_FW_1)
586 dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); 824 udelay(3000);
587 return 0; 825
826 if (read_dst(state, &reply, GET_ACK)) {
827 if (verbose > 1)
828 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
829 if ((dst_error_recovery(state)) < 0) {
830 dprintk("%s: Recovery Failed.\n", __FUNCTION__);
831 return -1;
832 }
833 return -1;
834 }
835
836 if (reply != ACK) {
837 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
838 return -1;
588 } 839 }
589 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3)) 840 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
590 return 0; 841 return 0;
591 if (!dst_wait_dst_ready(state)) 842
592 return 0; 843// udelay(3000);
593 // dst_i2c_enable(i2c); Per dimitri 844 if (state->type_flags & DST_TYPE_HAS_FW_1)
594 retval = read_dst(state, state->rxbuffer, 8); 845 udelay(3000);
595 dst_i2c_disable(state); 846 else
596 if (retval < 0) { 847 udelay(2000);
597 dprintk("%s: read not successful\n", __FUNCTION__); 848
598 return 0; 849 if (!dst_wait_dst_ready(state, NO_DELAY))
850 return -1;
851
852 if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
853 if (verbose > 1)
854 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
855 if ((dst_error_recovery(state)) < 0) {
856 dprintk("%s: Recovery failed.\n", __FUNCTION__);
857 return -1;
858 }
859 return -1;
599 } 860 }
861
600 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { 862 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
601 dprintk("%s: checksum failure\n", __FUNCTION__); 863 dprintk("%s: checksum failure\n", __FUNCTION__);
602 return 0; 864 return -1;
603 } 865 }
866
604 return 0; 867 return 0;
605} 868}
869EXPORT_SYMBOL(dst_command);
606 870
607static int dst_get_signal(struct dst_state* state) 871static int dst_get_signal(struct dst_state* state)
608{ 872{
@@ -642,37 +906,38 @@ static int dst_tone_power_cmd(struct dst_state* state)
642 if (state->dst_type == DST_TYPE_IS_TERR) 906 if (state->dst_type == DST_TYPE_IS_TERR)
643 return 0; 907 return 0;
644 908
645 if (state->voltage == SEC_VOLTAGE_OFF) 909 paket[4] = state->tx_tuna[4];
646 paket[4] = 0; 910 paket[2] = state->tx_tuna[2];
647 else 911 paket[3] = state->tx_tuna[3];
648 paket[4] = 1; 912 paket[7] = dst_check_sum (paket, 7);
649 if (state->tone == SEC_TONE_ON)
650 paket[2] = state->k22;
651 else
652 paket[2] = 0;
653 paket[7] = dst_check_sum(&paket[0], 7);
654 dst_command(state, paket, 8); 913 dst_command(state, paket, 8);
914
655 return 0; 915 return 0;
656} 916}
657 917
658static int dst_get_tuna(struct dst_state* state) 918static int dst_get_tuna(struct dst_state* state)
659{ 919{
660 int retval; 920 int retval;
921
661 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) 922 if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
662 return 0; 923 return 0;
924
663 state->diseq_flags &= ~(HAS_LOCK); 925 state->diseq_flags &= ~(HAS_LOCK);
664 if (!dst_wait_dst_ready(state)) 926 if (!dst_wait_dst_ready(state, NO_DELAY))
665 return 0; 927 return 0;
928
666 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 929 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
667 /* how to get variable length reply ???? */ 930 /* how to get variable length reply ???? */
668 retval = read_dst(state, state->rx_tuna, 10); 931 retval = read_dst(state, state->rx_tuna, 10);
669 } else { 932 } else {
670 retval = read_dst(state, &state->rx_tuna[2], 8); 933 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
671 } 934 }
935
672 if (retval < 0) { 936 if (retval < 0) {
673 dprintk("%s: read not successful\n", __FUNCTION__); 937 dprintk("%s: read not successful\n", __FUNCTION__);
674 return 0; 938 return 0;
675 } 939 }
940
676 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 941 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
677 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) { 942 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
678 dprintk("%s: checksum failure?\n", __FUNCTION__); 943 dprintk("%s: checksum failure?\n", __FUNCTION__);
@@ -705,11 +970,13 @@ static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
705 970
706static int dst_write_tuna(struct dvb_frontend* fe) 971static int dst_write_tuna(struct dvb_frontend* fe)
707{ 972{
708 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 973 struct dst_state* state = fe->demodulator_priv;
709 int retval; 974 int retval;
710 u8 reply; 975 u8 reply;
711 976
712 dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags); 977 if (debug > 4)
978 dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags);
979
713 state->decode_freq = 0; 980 state->decode_freq = 0;
714 state->decode_lock = state->decode_strength = state->decode_snr = 0; 981 state->decode_lock = state->decode_strength = state->decode_snr = 0;
715 if (state->dst_type == DST_TYPE_IS_SAT) { 982 if (state->dst_type == DST_TYPE_IS_SAT) {
@@ -717,32 +984,41 @@ static int dst_write_tuna(struct dvb_frontend* fe)
717 dst_set_voltage(fe, SEC_VOLTAGE_13); 984 dst_set_voltage(fe, SEC_VOLTAGE_13);
718 } 985 }
719 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE); 986 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
720 dst_i2c_enable(state); 987
988 if ((dst_comm_init(state)) < 0) {
989 dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__);
990 return -1;
991 }
992
721 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 993 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
722 dst_reset8820(state);
723 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9); 994 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
724 retval = write_dst(state, &state->tx_tuna[0], 10); 995 retval = write_dst(state, &state->tx_tuna[0], 10);
996
725 } else { 997 } else {
726 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7); 998 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
727 retval = write_dst(state, &state->tx_tuna[2], 8); 999 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
728 } 1000 }
729 if (retval < 0) { 1001 if (retval < 0) {
730 dst_i2c_disable(state); 1002 dst_pio_disable(state);
731 dprintk("%s: write not successful\n", __FUNCTION__); 1003 dprintk("%s: write not successful\n", __FUNCTION__);
732 return retval; 1004 return retval;
733 } 1005 }
734 msleep(3); 1006
735 retval = read_dst(state, &reply, 1); 1007 if ((dst_pio_disable(state)) < 0) {
736 dst_i2c_disable(state); 1008 dprintk("%s: DST PIO disable failed !\n", __FUNCTION__);
737 if (retval < 0) { 1009 return -1;
738 dprintk("%s: read verify not successful\n", __FUNCTION__);
739 return retval;
740 } 1010 }
741 if (reply != 0xff) { 1011
742 dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); 1012 if ((read_dst(state, &reply, GET_ACK) < 0)) {
1013 dprintk("%s: read verify not successful.\n", __FUNCTION__);
1014 return -1;
1015 }
1016 if (reply != ACK) {
1017 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
743 return 0; 1018 return 0;
744 } 1019 }
745 state->diseq_flags |= ATTEMPT_TUNE; 1020 state->diseq_flags |= ATTEMPT_TUNE;
1021
746 return dst_get_tuna(state); 1022 return dst_get_tuna(state);
747} 1023}
748 1024
@@ -762,10 +1038,10 @@ static int dst_write_tuna(struct dvb_frontend* fe)
762 1038
763static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) 1039static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
764{ 1040{
765 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1041 struct dst_state* state = fe->demodulator_priv;
766 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; 1042 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
767 1043
768 if (state->dst_type == DST_TYPE_IS_TERR) 1044 if (state->dst_type != DST_TYPE_IS_SAT)
769 return 0; 1045 return 0;
770 1046
771 if (cmd->msg_len == 0 || cmd->msg_len > 4) 1047 if (cmd->msg_len == 0 || cmd->msg_len > 4)
@@ -778,73 +1054,91 @@ static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd*
778 1054
779static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 1055static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
780{ 1056{
781 u8 *val;
782 int need_cmd; 1057 int need_cmd;
783 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1058 struct dst_state* state = fe->demodulator_priv;
784 1059
785 state->voltage = voltage; 1060 state->voltage = voltage;
786 1061
787 if (state->dst_type == DST_TYPE_IS_TERR) 1062 if (state->dst_type != DST_TYPE_IS_SAT)
788 return 0; 1063 return 0;
789 1064
790 need_cmd = 0; 1065 need_cmd = 0;
791 val = &state->tx_tuna[0];
792 val[8] &= ~0x40;
793 switch (voltage) { 1066 switch (voltage) {
794 case SEC_VOLTAGE_13: 1067 case SEC_VOLTAGE_13:
795 if ((state->diseq_flags & HAS_POWER) == 0) 1068 case SEC_VOLTAGE_18:
796 need_cmd = 1; 1069 if ((state->diseq_flags & HAS_POWER) == 0)
797 state->diseq_flags |= HAS_POWER; 1070 need_cmd = 1;
798 break; 1071 state->diseq_flags |= HAS_POWER;
799 case SEC_VOLTAGE_18: 1072 state->tx_tuna[4] = 0x01;
800 if ((state->diseq_flags & HAS_POWER) == 0) 1073 break;
1074
1075 case SEC_VOLTAGE_OFF:
801 need_cmd = 1; 1076 need_cmd = 1;
802 state->diseq_flags |= HAS_POWER; 1077 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
803 val[8] |= 0x40; 1078 state->tx_tuna[4] = 0x00;
804 break; 1079 break;
805 case SEC_VOLTAGE_OFF: 1080
806 need_cmd = 1; 1081 default:
807 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE); 1082 return -EINVAL;
808 break;
809 default:
810 return -EINVAL;
811 } 1083 }
812 if (need_cmd) { 1084 if (need_cmd)
813 dst_tone_power_cmd(state); 1085 dst_tone_power_cmd(state);
814 } 1086
815 return 0; 1087 return 0;
816} 1088}
817 1089
818static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 1090static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
819{ 1091{
820 u8 *val; 1092 struct dst_state* state = fe->demodulator_priv;
821 struct dst_state* state = (struct dst_state*) fe->demodulator_priv;
822 1093
823 state->tone = tone; 1094 state->tone = tone;
824 1095
825 if (state->dst_type == DST_TYPE_IS_TERR) 1096 if (state->dst_type != DST_TYPE_IS_SAT)
826 return 0; 1097 return 0;
827 1098
828 val = &state->tx_tuna[0]; 1099 switch (tone) {
1100 case SEC_TONE_OFF:
1101 state->tx_tuna[2] = 0xff;
1102 break;
829 1103
830 val[8] &= ~0x1; 1104 case SEC_TONE_ON:
1105 state->tx_tuna[2] = 0x02;
1106 break;
831 1107
832 switch (tone) { 1108 default:
833 case SEC_TONE_OFF: 1109 return -EINVAL;
834 break;
835 case SEC_TONE_ON:
836 val[8] |= 1;
837 break;
838 default:
839 return -EINVAL;
840 } 1110 }
841 dst_tone_power_cmd(state); 1111 dst_tone_power_cmd(state);
1112
1113 return 0;
1114}
1115
1116static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1117{
1118 struct dst_state *state = fe->demodulator_priv;
1119
1120 if (state->dst_type != DST_TYPE_IS_SAT)
1121 return 0;
1122
1123 state->minicmd = minicmd;
1124
1125 switch (minicmd) {
1126 case SEC_MINI_A:
1127 state->tx_tuna[3] = 0x02;
1128 break;
1129 case SEC_MINI_B:
1130 state->tx_tuna[3] = 0xff;
1131 break;
1132 }
1133 dst_tone_power_cmd(state);
1134
842 return 0; 1135 return 0;
843} 1136}
844 1137
1138
845static int dst_init(struct dvb_frontend* fe) 1139static int dst_init(struct dvb_frontend* fe)
846{ 1140{
847 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1141 struct dst_state* state = fe->demodulator_priv;
848 static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; 1142 static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
849 static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; 1143 static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
850 static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1144 static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
@@ -876,7 +1170,7 @@ static int dst_init(struct dvb_frontend* fe)
876 1170
877static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status) 1171static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
878{ 1172{
879 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1173 struct dst_state* state = fe->demodulator_priv;
880 1174
881 *status = 0; 1175 *status = 0;
882 if (state->diseq_flags & HAS_LOCK) { 1176 if (state->diseq_flags & HAS_LOCK) {
@@ -890,7 +1184,7 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
890 1184
891static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength) 1185static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
892{ 1186{
893 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1187 struct dst_state* state = fe->demodulator_priv;
894 1188
895 dst_get_signal(state); 1189 dst_get_signal(state);
896 *strength = state->decode_strength; 1190 *strength = state->decode_strength;
@@ -900,7 +1194,7 @@ static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
900 1194
901static int dst_read_snr(struct dvb_frontend* fe, u16* snr) 1195static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
902{ 1196{
903 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1197 struct dst_state* state = fe->demodulator_priv;
904 1198
905 dst_get_signal(state); 1199 dst_get_signal(state);
906 *snr = state->decode_snr; 1200 *snr = state->decode_snr;
@@ -910,13 +1204,19 @@ static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
910 1204
911static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 1205static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
912{ 1206{
913 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1207 struct dst_state* state = fe->demodulator_priv;
914 1208
915 dst_set_freq(state, p->frequency); 1209 dst_set_freq(state, p->frequency);
1210 if (verbose > 4)
1211 dprintk("Set Frequency = [%d]\n", p->frequency);
1212
916 dst_set_inversion(state, p->inversion); 1213 dst_set_inversion(state, p->inversion);
917 if (state->dst_type == DST_TYPE_IS_SAT) { 1214 if (state->dst_type == DST_TYPE_IS_SAT) {
918 dst_set_fec(state, p->u.qpsk.fec_inner); 1215 dst_set_fec(state, p->u.qpsk.fec_inner);
919 dst_set_symbolrate(state, p->u.qpsk.symbol_rate); 1216 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1217 if (verbose > 4)
1218 dprintk("Set Symbolrate = [%d]\n", p->u.qpsk.symbol_rate);
1219
920 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1220 } else if (state->dst_type == DST_TYPE_IS_TERR) {
921 dst_set_bandwidth(state, p->u.ofdm.bandwidth); 1221 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
922 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1222 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
@@ -930,7 +1230,7 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
930 1230
931static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 1231static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
932{ 1232{
933 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1233 struct dst_state* state = fe->demodulator_priv;
934 1234
935 p->frequency = state->decode_freq; 1235 p->frequency = state->decode_freq;
936 p->inversion = state->inversion; 1236 p->inversion = state->inversion;
@@ -950,7 +1250,7 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
950 1250
951static void dst_release(struct dvb_frontend* fe) 1251static void dst_release(struct dvb_frontend* fe)
952{ 1252{
953 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1253 struct dst_state* state = fe->demodulator_priv;
954 kfree(state); 1254 kfree(state);
955} 1255}
956 1256
@@ -958,50 +1258,47 @@ static struct dvb_frontend_ops dst_dvbt_ops;
958static struct dvb_frontend_ops dst_dvbs_ops; 1258static struct dvb_frontend_ops dst_dvbs_ops;
959static struct dvb_frontend_ops dst_dvbc_ops; 1259static struct dvb_frontend_ops dst_dvbc_ops;
960 1260
961struct dvb_frontend* dst_attach(const struct dst_config* config, 1261struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
962 struct i2c_adapter* i2c,
963 struct bt878 *bt)
964{ 1262{
965 struct dst_state* state = NULL;
966
967 /* allocate memory for the internal state */
968 state = (struct dst_state*) kmalloc(sizeof(struct dst_state), GFP_KERNEL);
969 if (state == NULL) goto error;
970 1263
971 /* setup the state */ 1264 /* check if the ASIC is there */
972 state->config = config; 1265 if (dst_probe(state) < 0) {
973 state->i2c = i2c; 1266 if (state)
974 state->bt = bt; 1267 kfree(state);
975
976 /* check if the demod is there */
977 if (dst_check_ci(state) < 0) goto error;
978 1268
1269 return NULL;
1270 }
979 /* determine settings based on type */ 1271 /* determine settings based on type */
980 switch (state->dst_type) { 1272 switch (state->dst_type) {
981 case DST_TYPE_IS_TERR: 1273 case DST_TYPE_IS_TERR:
982 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops)); 1274 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
983 break; 1275 break;
1276
984 case DST_TYPE_IS_CABLE: 1277 case DST_TYPE_IS_CABLE:
985 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops)); 1278 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
986 break; 1279 break;
1280
987 case DST_TYPE_IS_SAT: 1281 case DST_TYPE_IS_SAT:
988 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops)); 1282 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
989 break; 1283 break;
1284
990 default: 1285 default:
991 printk("dst: unknown frontend type. please report to the LinuxTV.org DVB mailinglist.\n"); 1286 printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__);
992 goto error; 1287 if (state)
1288 kfree(state);
1289
1290 return NULL;
993 } 1291 }
994 1292
995 /* create dvb_frontend */ 1293 /* create dvb_frontend */
996 state->frontend.ops = &state->ops; 1294 state->frontend.ops = &state->ops;
997 state->frontend.demodulator_priv = state; 1295 state->frontend.demodulator_priv = state;
998 return &state->frontend;
999 1296
1000error: 1297 return state; /* Manu (DST is a card not a frontend) */
1001 kfree(state);
1002 return NULL;
1003} 1298}
1004 1299
1300EXPORT_SYMBOL(dst_attach);
1301
1005static struct dvb_frontend_ops dst_dvbt_ops = { 1302static struct dvb_frontend_ops dst_dvbt_ops = {
1006 1303
1007 .info = { 1304 .info = {
@@ -1051,6 +1348,7 @@ static struct dvb_frontend_ops dst_dvbs_ops = {
1051 .read_signal_strength = dst_read_signal_strength, 1348 .read_signal_strength = dst_read_signal_strength,
1052 .read_snr = dst_read_snr, 1349 .read_snr = dst_read_snr,
1053 1350
1351 .diseqc_send_burst = dst_send_burst,
1054 .diseqc_send_master_cmd = dst_set_diseqc, 1352 .diseqc_send_master_cmd = dst_set_diseqc,
1055 .set_voltage = dst_set_voltage, 1353 .set_voltage = dst_set_voltage,
1056 .set_tone = dst_set_tone, 1354 .set_tone = dst_set_tone,
@@ -1082,8 +1380,7 @@ static struct dvb_frontend_ops dst_dvbc_ops = {
1082 .read_snr = dst_read_snr, 1380 .read_snr = dst_read_snr,
1083}; 1381};
1084 1382
1383
1085MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver"); 1384MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1086MODULE_AUTHOR("Jamie Honan"); 1385MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1087MODULE_LICENSE("GPL"); 1386MODULE_LICENSE("GPL");
1088
1089EXPORT_SYMBOL(dst_attach);