blob: 6c34ac9cefdd4c48c92ee2dd47ec7a596fa0b0f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07003 Frontend/Card driver for TwinHan DST Frontend
4 Copyright (C) 2003 Jamie Honan
5 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07007 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070012 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070017 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020*/
21
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/string.h>
27#include <linux/slab.h>
28#include <linux/vmalloc.h>
29#include <linux/delay.h>
30#include <asm/div64.h>
31
32#include "dvb_frontend.h"
33#include "dst_priv.h"
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070034#include "dst_common.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070037static unsigned int verbose = 1;
38module_param(verbose, int, 0644);
39MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070041static unsigned int debug = 1;
42module_param(debug, int, 0644);
43MODULE_PARM_DESC(debug, "debug messages, default is 0 (yes)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070045static unsigned int dst_addons;
46module_param(dst_addons, int, 0644);
Johannes Stezenbach4a2cc122005-05-16 21:54:45 -070047MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070049#define dprintk if (debug) printk
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define HAS_LOCK 1
52#define ATTEMPT_TUNE 2
53#define HAS_POWER 4
54
55static void dst_packsize(struct dst_state* state, int psize)
56{
57 union dst_gpio_packet bits;
58
59 bits.psize = psize;
60 bt878_device_control(state->bt, DST_IG_TS, &bits);
61}
62
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070063int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 union dst_gpio_packet enb;
66 union dst_gpio_packet bits;
67 int err;
68
69 enb.enb.mask = mask;
70 enb.enb.enable = enbb;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070071 if (verbose > 4)
72 dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__, mask, enbb, outhigh);
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070075 dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__, err, mask, enbb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return -EREMOTEIO;
77 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -070078 udelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* because complete disabling means no output, no need to do output packet */
80 if (enbb == 0)
81 return 0;
82
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070083 if (delay)
84 msleep(10);
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 bits.outp.mask = enbb;
87 bits.outp.highvals = outhigh;
88
89 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070090 dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__, err, enbb, outhigh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return -EREMOTEIO;
92 }
93 return 0;
94}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070095EXPORT_SYMBOL(dst_gpio_outb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070097int dst_gpio_inb(struct dst_state *state, u8 * result)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 union dst_gpio_packet rd_packet;
100 int err;
101
102 *result = 0;
103
104 if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
105 dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__, err);
106 return -EREMOTEIO;
107 }
108
109 *result = (u8) rd_packet.rd.value;
110 return 0;
111}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700112EXPORT_SYMBOL(dst_gpio_inb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700114int rdc_reset_state(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700116 if (verbose > 1)
117 dprintk("%s: Resetting state machine\n", __FUNCTION__);
118
119 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
120 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
121 return -1;
122 }
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 msleep(10);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700125
126 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
127 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
128 msleep(10);
129 return -1;
130 }
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return 0;
133}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700134EXPORT_SYMBOL(rdc_reset_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700136int rdc_8820_reset(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700138 if (verbose > 1)
139 dprintk("%s: Resetting DST\n", __FUNCTION__);
140
141 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
142 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
143 return -1;
144 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700145 udelay(1000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700146 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return 0;
152}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700153EXPORT_SYMBOL(rdc_8820_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700155int dst_pio_enable(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700157 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
158 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
159 return -1;
160 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700161 udelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return 0;
163}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700164EXPORT_SYMBOL(dst_pio_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700166int 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 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700172 if (state->type_flags & DST_TYPE_HAS_FW_1)
173 udelay(1000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700174
175 return 0;
176}
177EXPORT_SYMBOL(dst_pio_disable);
178
179int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 u8 reply;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 int i;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 for (i = 0; i < 200; i++) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700185 if (dst_gpio_inb(state, &reply) < 0) {
186 dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__);
187 return -1;
188 }
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return 1;
194 }
Johannes Stezenbachb46dd442005-05-16 21:54:44 -0700195 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700197 if (verbose > 1)
198 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i);
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return 0;
201}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700202EXPORT_SYMBOL(dst_wait_dst_ready);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700204int 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
212 return 0;
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 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700240 if (state->type_flags & DST_TYPE_HAS_FW_1)
241 msleep(100);
242 else
243 msleep(5);
244
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700245 return 0;
246}
247EXPORT_SYMBOL(dst_comm_init);
248
249
250int write_dst(struct dst_state *state, u8 *data, u8 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 struct i2c_msg msg = {
253 .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len
254 };
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 int err;
257 int cnt;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700258 if (debug && (verbose > 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 u8 i;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700260 if (verbose > 4) {
Manu Abraham7d534212005-07-07 17:57:50 -0700261 dprintk("%s writing [ ", __FUNCTION__);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700262 for (i = 0; i < len; i++)
Manu Abraham7d534212005-07-07 17:57:50 -0700263 dprintk("%02x ", data[i]);
264 dprintk("]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700267 for (cnt = 0; cnt < 2; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700269 dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]);
270 dst_error_recovery(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 continue;
272 } else
273 break;
274 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700275
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return 0;
285}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700286EXPORT_SYMBOL(write_dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700288int read_dst(struct dst_state *state, u8 * ret, u8 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len };
291 int err;
292 int cnt;
293
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700294 for (cnt = 0; cnt < 2; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700298 dst_error_recovery(state);
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 continue;
301 } else
302 break;
303 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700304 if (cnt >= 2) {
305 if (verbose > 1)
306 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
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]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 for (err = 1; err < len; err++)
314 dprintk(" 0x%x", ret[err]);
315 if (err > 1)
316 dprintk("\n");
317 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return 0;
320}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700321EXPORT_SYMBOL(read_dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Manu Abraham7d534212005-07-07 17:57:50 -0700323static int dst_set_polarization(struct dst_state *state)
324{
325 switch (state->voltage) {
326 case SEC_VOLTAGE_13: // vertical
327 printk("%s: Polarization=[Vertical]\n", __FUNCTION__);
Allan Stirling3dff9192005-07-07 17:57:51 -0700328 state->tx_tuna[8] &= ~0x40; //1
Manu Abraham7d534212005-07-07 17:57:50 -0700329 break;
330
331 case SEC_VOLTAGE_18: // horizontal
332 printk("%s: Polarization=[Horizontal]\n", __FUNCTION__);
Allan Stirling3dff9192005-07-07 17:57:51 -0700333 state->tx_tuna[8] |= 0x40; // 0
Manu Abraham7d534212005-07-07 17:57:50 -0700334 break;
335
336 case SEC_VOLTAGE_OFF:
337
338 break;
339 }
340
341 return 0;
342}
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344static int dst_set_freq(struct dst_state *state, u32 freq)
345{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 state->frequency = freq;
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700347 if (debug > 4)
348 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (state->dst_type == DST_TYPE_IS_SAT) {
351 freq = freq / 1000;
352 if (freq < 950 || freq > 2150)
353 return -EINVAL;
Manu Abraham7d534212005-07-07 17:57:50 -0700354
355 state->tx_tuna[2] = (freq >> 8);
356 state->tx_tuna[3] = (u8) freq;
357 state->tx_tuna[4] = 0x01;
358 state->tx_tuna[8] &= ~0x04;
359 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
360 if (freq < 1531)
361 state->tx_tuna[8] |= 0x04;
362 }
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 } else if (state->dst_type == DST_TYPE_IS_TERR) {
365 freq = freq / 1000;
366 if (freq < 137000 || freq > 858000)
367 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Manu Abraham7d534212005-07-07 17:57:50 -0700369 state->tx_tuna[2] = (freq >> 16) & 0xff;
370 state->tx_tuna[3] = (freq >> 8) & 0xff;
371 state->tx_tuna[4] = (u8) freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
Manu Abraham7d534212005-07-07 17:57:50 -0700374 state->tx_tuna[2] = (freq >> 16) & 0xff;
375 state->tx_tuna[3] = (freq >> 8) & 0xff;
376 state->tx_tuna[4] = (u8) freq;
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 } else
379 return -EINVAL;
380 return 0;
381}
382
383static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
384{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 state->bandwidth = bandwidth;
386
387 if (state->dst_type != DST_TYPE_IS_TERR)
388 return 0;
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 switch (bandwidth) {
Manu Abraham7d534212005-07-07 17:57:50 -0700391 case BANDWIDTH_6_MHZ:
392 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
393 state->tx_tuna[7] = 0x06;
394 else {
395 state->tx_tuna[6] = 0x06;
396 state->tx_tuna[7] = 0x00;
397 }
398 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Manu Abraham7d534212005-07-07 17:57:50 -0700400 case BANDWIDTH_7_MHZ:
401 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
402 state->tx_tuna[7] = 0x07;
403 else {
404 state->tx_tuna[6] = 0x07;
405 state->tx_tuna[7] = 0x00;
406 }
407 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Manu Abraham7d534212005-07-07 17:57:50 -0700409 case BANDWIDTH_8_MHZ:
410 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
411 state->tx_tuna[7] = 0x08;
412 else {
413 state->tx_tuna[6] = 0x08;
414 state->tx_tuna[7] = 0x00;
415 }
416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Manu Abraham7d534212005-07-07 17:57:50 -0700418 default:
419 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
421 return 0;
422}
423
424static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion)
425{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 state->inversion = inversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 switch (inversion) {
Manu Abraham7d534212005-07-07 17:57:50 -0700428 case INVERSION_OFF: // Inversion = Normal
429 state->tx_tuna[8] &= ~0x80;
430 break;
431
432 case INVERSION_ON:
433 state->tx_tuna[8] |= 0x80;
434 break;
435 default:
436 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438 return 0;
439}
440
441static int dst_set_fec(struct dst_state* state, fe_code_rate_t fec)
442{
443 state->fec = fec;
444 return 0;
445}
446
447static fe_code_rate_t dst_get_fec(struct dst_state* state)
448{
449 return state->fec;
450}
451
452static int dst_set_symbolrate(struct dst_state* state, u32 srate)
453{
454 u8 *val;
455 u32 symcalc;
456 u64 sval;
457
458 state->symbol_rate = srate;
459
460 if (state->dst_type == DST_TYPE_IS_TERR) {
461 return 0;
462 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700463 if (debug > 4)
464 dprintk("%s: set symrate %u\n", __FUNCTION__, srate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 srate /= 1000;
466 val = &state->tx_tuna[0];
467
468 if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
469 sval = srate;
470 sval <<= 20;
471 do_div(sval, 88000);
472 symcalc = (u32) sval;
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700473
474 if (debug > 4)
475 dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc);
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 val[5] = (u8) (symcalc >> 12);
478 val[6] = (u8) (symcalc >> 4);
479 val[7] = (u8) (symcalc << 4);
480 } else {
481 val[5] = (u8) (srate >> 16) & 0x7f;
482 val[6] = (u8) (srate >> 8);
483 val[7] = (u8) srate;
484 }
485 val[8] &= ~0x20;
486 if (srate > 8000)
487 val[8] |= 0x20;
488 return 0;
489}
490
Manu Abraham7d534212005-07-07 17:57:50 -0700491
492static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
493{
494 if (state->dst_type != DST_TYPE_IS_CABLE)
495 return 0;
496
497 state->modulation = modulation;
498 switch (modulation) {
499 case QAM_16:
500 state->tx_tuna[8] = 0x10;
501 break;
502
503 case QAM_32:
504 state->tx_tuna[8] = 0x20;
505 break;
506
507 case QAM_64:
508 state->tx_tuna[8] = 0x40;
509 break;
510
511 case QAM_128:
512 state->tx_tuna[8] = 0x80;
513 break;
514
515 case QAM_256:
516 state->tx_tuna[8] = 0x00;
517 break;
518
519 case QPSK:
520 case QAM_AUTO:
521 case VSB_8:
522 case VSB_16:
523 default:
524 return -EINVAL;
525
526 }
527
528 return 0;
529}
530
531static fe_modulation_t dst_get_modulation(struct dst_state *state)
532{
533 return state->modulation;
534}
535
536
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700537u8 dst_check_sum(u8 * buf, u32 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 u32 i;
540 u8 val = 0;
541 if (!len)
542 return 0;
543 for (i = 0; i < len; i++) {
544 val += buf[i];
545 }
546 return ((~val) + 1);
547}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700548EXPORT_SYMBOL(dst_check_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550static void dst_type_flags_print(u32 type_flags)
551{
552 printk("DST type flags :");
553 if (type_flags & DST_TYPE_HAS_NEWTUNE)
554 printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
555 if (type_flags & DST_TYPE_HAS_TS204)
556 printk(" 0x%x ts204", DST_TYPE_HAS_TS204);
557 if (type_flags & DST_TYPE_HAS_SYMDIV)
558 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700559 if (type_flags & DST_TYPE_HAS_FW_1)
560 printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
561 if (type_flags & DST_TYPE_HAS_FW_2)
562 printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
563 if (type_flags & DST_TYPE_HAS_FW_3)
564 printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700565// if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw)
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 printk("\n");
568}
569
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700570
571static int dst_type_print (u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
573 char *otype;
574 switch (type) {
575 case DST_TYPE_IS_SAT:
576 otype = "satellite";
577 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 case DST_TYPE_IS_TERR:
580 otype = "terrestrial";
581 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 case DST_TYPE_IS_CABLE:
584 otype = "cable";
585 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 default:
588 printk("%s: invalid dst type %d\n", __FUNCTION__, type);
589 return -EINVAL;
590 }
591 printk("DST type : %s\n", otype);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 return 0;
594}
595
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700596/*
597 Known cards list
598 Satellite
599 -------------------
Johannes Stezenbache6ac6992005-05-16 21:54:42 -0700600 200103A
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700601 VP-1020 DST-MOT LG(old), TS=188
602
603 VP-1020 DST-03T LG(new), TS=204
604 VP-1022 DST-03T LG(new), TS=204
605 VP-1025 DST-03T LG(new), TS=204
606
607 VP-1030 DSTMCI, LG(new), TS=188
608 VP-1032 DSTMCI, LG(new), TS=188
609
610 Cable
611 -------------------
612 VP-2030 DCT-CI, Samsung, TS=204
613 VP-2021 DCT-CI, Unknown, TS=204
614 VP-2031 DCT-CI, Philips, TS=188
615 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
616 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
617
618 Terrestrial
619 -------------------
620 VP-3050 DTTNXT TS=188
621 VP-3040 DTT-CI, Philips, TS=188
622 VP-3040 DTT-CI, Philips, TS=204
623
624 ATSC
625 -------------------
626 VP-3220 ATSCDI, TS=188
627 VP-3250 ATSCAD, TS=188
628
629*/
630
631struct dst_types dst_tlist[] = {
632 {
Johannes Stezenbache6ac6992005-05-16 21:54:42 -0700633 .device_id = "200103A",
634 .offset = 0,
635 .dst_type = DST_TYPE_IS_SAT,
Manu Abraham7d534212005-07-07 17:57:50 -0700636 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
Johannes Stezenbache6ac6992005-05-16 21:54:42 -0700637 .dst_feature = 0
638 }, /* obsolete */
639
640 {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700641 .device_id = "DST-020",
642 .offset = 0,
643 .dst_type = DST_TYPE_IS_SAT,
644 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
645 .dst_feature = 0
646 }, /* obsolete */
647
648 {
649 .device_id = "DST-030",
650 .offset = 0,
651 .dst_type = DST_TYPE_IS_SAT,
652 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
653 .dst_feature = 0
654 }, /* obsolete */
655
656 {
657 .device_id = "DST-03T",
658 .offset = 0,
659 .dst_type = DST_TYPE_IS_SAT,
660 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
661 .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
662 | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO
663 },
664
665 {
666 .device_id = "DST-MOT",
667 .offset = 0,
668 .dst_type = DST_TYPE_IS_SAT,
669 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
670 .dst_feature = 0
671 }, /* obsolete */
672
673 {
674 .device_id = "DST-CI",
675 .offset = 1,
676 .dst_type = DST_TYPE_IS_SAT,
677 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
678 .dst_feature = DST_TYPE_HAS_CA
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700679 }, /* An OEM board */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700680
681 {
682 .device_id = "DSTMCI",
683 .offset = 1,
684 .dst_type = DST_TYPE_IS_SAT,
Manu Abraham7d534212005-07-07 17:57:50 -0700685 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700686 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
687 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
688 },
689
690 {
691 .device_id = "DSTFCI",
692 .offset = 1,
693 .dst_type = DST_TYPE_IS_SAT,
694 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
695 .dst_feature = 0
696 }, /* unknown to vendor */
697
698 {
699 .device_id = "DCT-CI",
700 .offset = 1,
701 .dst_type = DST_TYPE_IS_CABLE,
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700702 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
703 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700704 .dst_feature = DST_TYPE_HAS_CA
705 },
706
707 {
708 .device_id = "DCTNEW",
709 .offset = 1,
710 .dst_type = DST_TYPE_IS_CABLE,
711 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3,
712 .dst_feature = 0
713 },
714
715 {
716 .device_id = "DTT-CI",
717 .offset = 1,
718 .dst_type = DST_TYPE_IS_TERR,
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700719 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700720 .dst_feature = 0
721 },
722
723 {
724 .device_id = "DTTDIG",
725 .offset = 1,
726 .dst_type = DST_TYPE_IS_TERR,
727 .type_flags = DST_TYPE_HAS_FW_2,
728 .dst_feature = 0
729 },
730
731 {
732 .device_id = "DTTNXT",
733 .offset = 1,
734 .dst_type = DST_TYPE_IS_TERR,
735 .type_flags = DST_TYPE_HAS_FW_2,
736 .dst_feature = DST_TYPE_HAS_ANALOG
737 },
738
739 {
740 .device_id = "ATSCDI",
741 .offset = 1,
742 .dst_type = DST_TYPE_IS_ATSC,
743 .type_flags = DST_TYPE_HAS_FW_2,
744 .dst_feature = 0
745 },
746
747 {
748 .device_id = "ATSCAD",
749 .offset = 1,
750 .dst_type = DST_TYPE_IS_ATSC,
751 .type_flags = DST_TYPE_HAS_FW_2,
752 .dst_feature = 0
753 },
754
755 { }
756
757};
758
759
760static int dst_get_device_id(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700762 u8 reply;
763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 int i;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700765 struct dst_types *p_dst_type;
766 u8 use_dst_type = 0;
767 u32 use_type_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700769 static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700771 device_type[7] = dst_check_sum(device_type, 7);
772
773 if (write_dst(state, device_type, FIXED_COMM))
774 return -1; /* Write failed */
775
776 if ((dst_pio_disable(state)) < 0)
777 return -1;
778
779 if (read_dst(state, &reply, GET_ACK))
780 return -1; /* Read failure */
781
782 if (reply != ACK) {
783 dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__, reply);
784 return -1; /* Unack'd write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700786
787 if (!dst_wait_dst_ready(state, DEVICE_INIT))
788 return -1; /* DST not ready yet */
789
790 if (read_dst(state, state->rxbuffer, FIXED_COMM))
791 return -1;
792
793 dst_pio_disable(state);
794
795 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
796 dprintk("%s: Checksum failure! \n", __FUNCTION__);
797 return -1; /* Checksum failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700799
800 state->rxbuffer[7] = '\0';
801
802 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE (dst_tlist); i++, p_dst_type++) {
803 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
804 use_type_flags = p_dst_type->type_flags;
805 use_dst_type = p_dst_type->dst_type;
806
807 /* Card capabilities */
808 state->dst_hw_cap = p_dst_type->dst_feature;
809 printk ("%s: Recognise [%s]\n", __FUNCTION__, p_dst_type->device_id);
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 break;
812 }
813 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700814
815 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
816 printk("%s: Unable to recognize %s or %s\n", __FUNCTION__, &state->rxbuffer[0], &state->rxbuffer[1]);
817 printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 use_dst_type = DST_TYPE_IS_SAT;
819 use_type_flags = DST_TYPE_HAS_SYMDIV;
820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700822 dst_type_print(use_dst_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 state->type_flags = use_type_flags;
824 state->dst_type = use_dst_type;
825 dst_type_flags_print(state->type_flags);
826
827 if (state->type_flags & DST_TYPE_HAS_TS204) {
828 dst_packsize(state, 204);
829 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 return 0;
832}
833
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700834static int dst_probe(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700836 if ((rdc_8820_reset(state)) < 0) {
837 dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__);
838 return -1;
839 }
Johannes Stezenbach4a2cc122005-05-16 21:54:45 -0700840 if (dst_addons & DST_TYPE_HAS_CA)
841 msleep(4000);
842 else
843 msleep(100);
844
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700845 if ((dst_comm_init(state)) < 0) {
846 dprintk("%s: DST Initialization Failed.\n", __FUNCTION__);
847 return -1;
848 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700849 msleep(100);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700850 if (dst_get_device_id(state) < 0) {
851 dprintk("%s: unknown device.\n", __FUNCTION__);
852 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700854
855 return 0;
856}
857
858int dst_command(struct dst_state* state, u8 * data, u8 len)
859{
860 u8 reply;
861 if ((dst_comm_init(state)) < 0) {
862 dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__);
863 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700865
866 if (write_dst(state, data, len)) {
867 if (verbose > 1)
868 dprintk("%s: Tring to recover.. \n", __FUNCTION__);
869 if ((dst_error_recovery(state)) < 0) {
870 dprintk("%s: Recovery Failed.\n", __FUNCTION__);
871 return -1;
872 }
873 return -1;
874 }
875 if ((dst_pio_disable(state)) < 0) {
876 dprintk("%s: PIO Disable Failed.\n", __FUNCTION__);
877 return -1;
878 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700879 if (state->type_flags & DST_TYPE_HAS_FW_1)
880 udelay(3000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700881
882 if (read_dst(state, &reply, GET_ACK)) {
883 if (verbose > 1)
884 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
885 if ((dst_error_recovery(state)) < 0) {
886 dprintk("%s: Recovery Failed.\n", __FUNCTION__);
887 return -1;
888 }
889 return -1;
890 }
891
892 if (reply != ACK) {
893 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
894 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 }
896 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
897 return 0;
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700898
899// udelay(3000);
900 if (state->type_flags & DST_TYPE_HAS_FW_1)
901 udelay(3000);
902 else
903 udelay(2000);
904
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700905 if (!dst_wait_dst_ready(state, NO_DELAY))
906 return -1;
907
908 if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
909 if (verbose > 1)
910 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
911 if ((dst_error_recovery(state)) < 0) {
912 dprintk("%s: Recovery failed.\n", __FUNCTION__);
913 return -1;
914 }
915 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
919 dprintk("%s: checksum failure\n", __FUNCTION__);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700920 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 return 0;
924}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700925EXPORT_SYMBOL(dst_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927static int dst_get_signal(struct dst_state* state)
928{
929 int retval;
930 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
Johannes Stezenbach5b5b5342005-09-09 13:02:52 -0700931 //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
933 state->decode_lock = state->decode_strength = state->decode_snr = 0;
934 return 0;
935 }
936 if (0 == (state->diseq_flags & HAS_LOCK)) {
937 state->decode_lock = state->decode_strength = state->decode_snr = 0;
938 return 0;
939 }
940 if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
941 retval = dst_command(state, get_signal, 8);
942 if (retval < 0)
943 return retval;
944 if (state->dst_type == DST_TYPE_IS_SAT) {
945 state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
946 state->decode_strength = state->rxbuffer[5] << 8;
947 state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
948 } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
949 state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
950 state->decode_strength = state->rxbuffer[4] << 8;
951 state->decode_snr = state->rxbuffer[3] << 8;
952 }
953 state->cur_jiff = jiffies;
954 }
955 return 0;
956}
957
958static int dst_tone_power_cmd(struct dst_state* state)
959{
960 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
961
962 if (state->dst_type == DST_TYPE_IS_TERR)
963 return 0;
964
Manu Abraham8f6da8f2005-05-28 15:51:51 -0700965 paket[4] = state->tx_tuna[4];
Manu Abraham86360a32005-05-28 15:51:51 -0700966 paket[2] = state->tx_tuna[2];
Manu Abraham203fe8b2005-05-28 15:51:48 -0700967 paket[3] = state->tx_tuna[3];
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700968 paket[7] = dst_check_sum (paket, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 dst_command(state, paket, 8);
Manu Abraham203fe8b2005-05-28 15:51:48 -0700970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 return 0;
972}
973
974static int dst_get_tuna(struct dst_state* state)
975{
976 int retval;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
979 return 0;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 state->diseq_flags &= ~(HAS_LOCK);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700982 if (!dst_wait_dst_ready(state, NO_DELAY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 return 0;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
986 /* how to get variable length reply ???? */
987 retval = read_dst(state, state->rx_tuna, 10);
988 } else {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700989 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (retval < 0) {
993 dprintk("%s: read not successful\n", __FUNCTION__);
994 return 0;
995 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
998 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
999 dprintk("%s: checksum failure?\n", __FUNCTION__);
1000 return 0;
1001 }
1002 } else {
1003 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
1004 dprintk("%s: checksum failure?\n", __FUNCTION__);
1005 return 0;
1006 }
1007 }
1008 if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
1009 return 0;
1010 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
1011
1012 state->decode_lock = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 state->diseq_flags |= HAS_LOCK;
Manu Abraham7d534212005-07-07 17:57:50 -07001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return 1;
1016}
1017
1018static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
1019
1020static int dst_write_tuna(struct dvb_frontend* fe)
1021{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001022 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 int retval;
1024 u8 reply;
1025
Johannes Stezenbach8385e462005-05-16 21:54:43 -07001026 if (debug > 4)
1027 dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags);
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 state->decode_freq = 0;
1030 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1031 if (state->dst_type == DST_TYPE_IS_SAT) {
1032 if (!(state->diseq_flags & HAS_POWER))
1033 dst_set_voltage(fe, SEC_VOLTAGE_13);
1034 }
1035 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001036
1037 if ((dst_comm_init(state)) < 0) {
1038 dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__);
1039 return -1;
1040 }
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
1044 retval = write_dst(state, &state->tx_tuna[0], 10);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 } else {
1047 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001048 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 if (retval < 0) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001051 dst_pio_disable(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 dprintk("%s: write not successful\n", __FUNCTION__);
1053 return retval;
1054 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001055
1056 if ((dst_pio_disable(state)) < 0) {
1057 dprintk("%s: DST PIO disable failed !\n", __FUNCTION__);
1058 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001060
1061 if ((read_dst(state, &reply, GET_ACK) < 0)) {
1062 dprintk("%s: read verify not successful.\n", __FUNCTION__);
1063 return -1;
1064 }
1065 if (reply != ACK) {
1066 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return 0;
1068 }
1069 state->diseq_flags |= ATTEMPT_TUNE;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001070
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 return dst_get_tuna(state);
1072}
1073
1074/*
1075 * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
1076 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
1077 * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
1078 * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
1079 * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
1080 * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
1081 * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
1082 * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
1083 * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
1084 * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
1085 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
1086 */
1087
1088static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
1089{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001090 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1092
Manu Abraham226d97e2005-05-28 15:51:52 -07001093 if (state->dst_type != DST_TYPE_IS_SAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 return 0;
1095
1096 if (cmd->msg_len == 0 || cmd->msg_len > 4)
1097 return -EINVAL;
1098 memcpy(&paket[3], cmd->msg, cmd->msg_len);
1099 paket[7] = dst_check_sum(&paket[0], 7);
1100 dst_command(state, paket, 8);
1101 return 0;
1102}
1103
1104static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
1105{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 int need_cmd;
Manu Abraham0eac3e42005-05-28 15:51:50 -07001107 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 state->voltage = voltage;
1110
Manu Abraham226d97e2005-05-28 15:51:52 -07001111 if (state->dst_type != DST_TYPE_IS_SAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 return 0;
1113
1114 need_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 switch (voltage) {
Manu Abraham8f6da8f2005-05-28 15:51:51 -07001116 case SEC_VOLTAGE_13:
1117 case SEC_VOLTAGE_18:
1118 if ((state->diseq_flags & HAS_POWER) == 0)
1119 need_cmd = 1;
1120 state->diseq_flags |= HAS_POWER;
1121 state->tx_tuna[4] = 0x01;
1122 break;
1123
1124 case SEC_VOLTAGE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 need_cmd = 1;
Manu Abraham8f6da8f2005-05-28 15:51:51 -07001126 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
1127 state->tx_tuna[4] = 0x00;
1128 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001129
Manu Abraham8f6da8f2005-05-28 15:51:51 -07001130 default:
1131 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001133 if (need_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 dst_tone_power_cmd(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return 0;
1137}
1138
1139static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
1140{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001141 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 state->tone = tone;
1144
Manu Abraham226d97e2005-05-28 15:51:52 -07001145 if (state->dst_type != DST_TYPE_IS_SAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 return 0;
1147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 switch (tone) {
Manu Abraham86360a32005-05-28 15:51:51 -07001149 case SEC_TONE_OFF:
Steffen Motzer4b2bd302005-07-07 17:58:31 -07001150 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1151 state->tx_tuna[2] = 0x00;
1152 else
1153 state->tx_tuna[2] = 0xff;
1154
Manu Abraham86360a32005-05-28 15:51:51 -07001155 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001156
Manu Abraham86360a32005-05-28 15:51:51 -07001157 case SEC_TONE_ON:
1158 state->tx_tuna[2] = 0x02;
1159 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001160
Manu Abraham86360a32005-05-28 15:51:51 -07001161 default:
1162 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164 dst_tone_power_cmd(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 return 0;
1167}
1168
Manu Abraham203fe8b2005-05-28 15:51:48 -07001169static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1170{
1171 struct dst_state *state = fe->demodulator_priv;
1172
Manu Abraham226d97e2005-05-28 15:51:52 -07001173 if (state->dst_type != DST_TYPE_IS_SAT)
Manu Abraham203fe8b2005-05-28 15:51:48 -07001174 return 0;
1175
1176 state->minicmd = minicmd;
1177
1178 switch (minicmd) {
1179 case SEC_MINI_A:
1180 state->tx_tuna[3] = 0x02;
1181 break;
1182 case SEC_MINI_B:
1183 state->tx_tuna[3] = 0xff;
1184 break;
1185 }
1186 dst_tone_power_cmd(state);
1187
1188 return 0;
1189}
1190
1191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192static int dst_init(struct dvb_frontend* fe)
1193{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001194 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
1196 static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
1197 static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1198 static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1199 static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1200 static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
Manu Abraham7d534212005-07-07 17:57:50 -07001201// state->inversion = INVERSION_ON;
1202 state->inversion = INVERSION_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 state->voltage = SEC_VOLTAGE_13;
1204 state->tone = SEC_TONE_OFF;
1205 state->symbol_rate = 29473000;
1206 state->fec = FEC_AUTO;
1207 state->diseq_flags = 0;
1208 state->k22 = 0x02;
1209 state->bandwidth = BANDWIDTH_7_MHZ;
1210 state->cur_jiff = jiffies;
1211 if (state->dst_type == DST_TYPE_IS_SAT) {
1212 state->frequency = 950000;
1213 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_satci_tuna : ini_satfta_tuna), sizeof(ini_satfta_tuna));
1214 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1215 state->frequency = 137000000;
1216 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_tvci_tuna : ini_tvfta_tuna), sizeof(ini_tvfta_tuna));
1217 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1218 state->frequency = 51000000;
1219 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_cabci_tuna : ini_cabfta_tuna), sizeof(ini_cabfta_tuna));
1220 }
1221
1222 return 0;
1223}
1224
1225static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
1226{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001227 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 *status = 0;
1230 if (state->diseq_flags & HAS_LOCK) {
Manu Abraham7d534212005-07-07 17:57:50 -07001231// dst_get_signal(state); // don't require(?) to ask MCU
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 if (state->decode_lock)
1233 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
1234 }
1235
1236 return 0;
1237}
1238
1239static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
1240{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001241 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 dst_get_signal(state);
1244 *strength = state->decode_strength;
1245
1246 return 0;
1247}
1248
1249static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
1250{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001251 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 dst_get_signal(state);
1254 *snr = state->decode_snr;
1255
1256 return 0;
1257}
1258
1259static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
1260{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001261 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 dst_set_freq(state, p->frequency);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001264 if (verbose > 4)
Manu Abraham7d534212005-07-07 17:57:50 -07001265 dprintk("Set Frequency=[%d]\n", p->frequency);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001266
Manu Abraham7d534212005-07-07 17:57:50 -07001267// dst_set_inversion(state, p->inversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 if (state->dst_type == DST_TYPE_IS_SAT) {
Manu Abraham7d534212005-07-07 17:57:50 -07001269 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1270 dst_set_inversion(state, p->inversion);
1271
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 dst_set_fec(state, p->u.qpsk.fec_inner);
1273 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
Manu Abraham7d534212005-07-07 17:57:50 -07001274 dst_set_polarization(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001275 if (verbose > 4)
Manu Abraham7d534212005-07-07 17:57:50 -07001276 dprintk("Set Symbolrate=[%d]\n", p->u.qpsk.symbol_rate);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1279 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
1280 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1281 dst_set_fec(state, p->u.qam.fec_inner);
1282 dst_set_symbolrate(state, p->u.qam.symbol_rate);
Manu Abraham7d534212005-07-07 17:57:50 -07001283 dst_set_modulation(state, p->u.qam.modulation);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 dst_write_tuna(fe);
1286
1287 return 0;
1288}
1289
1290static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
1291{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001292 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 p->frequency = state->decode_freq;
Manu Abraham7d534212005-07-07 17:57:50 -07001295// p->inversion = state->inversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 if (state->dst_type == DST_TYPE_IS_SAT) {
Manu Abraham7d534212005-07-07 17:57:50 -07001297 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1298 p->inversion = state->inversion;
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 p->u.qpsk.symbol_rate = state->symbol_rate;
1301 p->u.qpsk.fec_inner = dst_get_fec(state);
1302 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1303 p->u.ofdm.bandwidth = state->bandwidth;
1304 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1305 p->u.qam.symbol_rate = state->symbol_rate;
1306 p->u.qam.fec_inner = dst_get_fec(state);
Manu Abraham7d534212005-07-07 17:57:50 -07001307// p->u.qam.modulation = QAM_AUTO;
1308 p->u.qam.modulation = dst_get_modulation(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 }
1310
1311 return 0;
1312}
1313
1314static void dst_release(struct dvb_frontend* fe)
1315{
Manu Abraham0eac3e42005-05-28 15:51:50 -07001316 struct dst_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 kfree(state);
1318}
1319
1320static struct dvb_frontend_ops dst_dvbt_ops;
1321static struct dvb_frontend_ops dst_dvbs_ops;
1322static struct dvb_frontend_ops dst_dvbc_ops;
1323
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001324struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001327 /* check if the ASIC is there */
1328 if (dst_probe(state) < 0) {
1329 if (state)
1330 kfree(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001332 return NULL;
1333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /* determine settings based on type */
1335 switch (state->dst_type) {
1336 case DST_TYPE_IS_TERR:
1337 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
1338 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 case DST_TYPE_IS_CABLE:
1341 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
1342 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 case DST_TYPE_IS_SAT:
1345 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
1346 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 default:
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001349 printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__);
1350 if (state)
1351 kfree(state);
1352
1353 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
1355
1356 /* create dvb_frontend */
1357 state->frontend.ops = &state->ops;
1358 state->frontend.demodulator_priv = state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001360 return state; /* Manu (DST is a card not a frontend) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361}
1362
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001363EXPORT_SYMBOL(dst_attach);
1364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365static struct dvb_frontend_ops dst_dvbt_ops = {
1366
1367 .info = {
1368 .name = "DST DVB-T",
1369 .type = FE_OFDM,
1370 .frequency_min = 137000000,
1371 .frequency_max = 858000000,
1372 .frequency_stepsize = 166667,
1373 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
1374 },
1375
1376 .release = dst_release,
1377
1378 .init = dst_init,
1379
1380 .set_frontend = dst_set_frontend,
1381 .get_frontend = dst_get_frontend,
1382
1383 .read_status = dst_read_status,
1384 .read_signal_strength = dst_read_signal_strength,
1385 .read_snr = dst_read_snr,
1386};
1387
1388static struct dvb_frontend_ops dst_dvbs_ops = {
1389
1390 .info = {
1391 .name = "DST DVB-S",
1392 .type = FE_QPSK,
1393 .frequency_min = 950000,
1394 .frequency_max = 2150000,
1395 .frequency_stepsize = 1000, /* kHz for QPSK frontends */
1396 .frequency_tolerance = 29500,
1397 .symbol_rate_min = 1000000,
1398 .symbol_rate_max = 45000000,
1399 /* . symbol_rate_tolerance = ???,*/
1400 .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
1401 },
1402
1403 .release = dst_release,
1404
1405 .init = dst_init,
1406
1407 .set_frontend = dst_set_frontend,
1408 .get_frontend = dst_get_frontend,
1409
1410 .read_status = dst_read_status,
1411 .read_signal_strength = dst_read_signal_strength,
1412 .read_snr = dst_read_snr,
1413
Manu Abraham203fe8b2005-05-28 15:51:48 -07001414 .diseqc_send_burst = dst_send_burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 .diseqc_send_master_cmd = dst_set_diseqc,
1416 .set_voltage = dst_set_voltage,
1417 .set_tone = dst_set_tone,
1418};
1419
1420static struct dvb_frontend_ops dst_dvbc_ops = {
1421
1422 .info = {
1423 .name = "DST DVB-C",
1424 .type = FE_QAM,
1425 .frequency_stepsize = 62500,
1426 .frequency_min = 51000000,
1427 .frequency_max = 858000000,
1428 .symbol_rate_min = 1000000,
1429 .symbol_rate_max = 45000000,
1430 /* . symbol_rate_tolerance = ???,*/
1431 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
1432 },
1433
1434 .release = dst_release,
1435
1436 .init = dst_init,
1437
1438 .set_frontend = dst_set_frontend,
1439 .get_frontend = dst_get_frontend,
1440
1441 .read_status = dst_read_status,
1442 .read_signal_strength = dst_read_signal_strength,
1443 .read_snr = dst_read_snr,
1444};
1445
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001447MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1448MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1449MODULE_LICENSE("GPL");