blob: d2a7e413e9e1752eabf82b746f8bf0b9b45810cd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07002 Frontend/Card driver for TwinHan DST Frontend
3 Copyright (C) 2003 Jamie Honan
4 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07006 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 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070011 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070016 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019*/
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/string.h>
25#include <linux/slab.h>
26#include <linux/vmalloc.h>
27#include <linux/delay.h>
28#include <asm/div64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "dvb_frontend.h"
30#include "dst_priv.h"
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070031#include "dst_common.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070033static unsigned int verbose = 1;
34module_param(verbose, int, 0644);
35MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070037static unsigned int dst_addons;
38module_param(dst_addons, int, 0644);
Johannes Stezenbach4a2cc122005-05-16 21:54:45 -070039MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Manu Abraham8cfba632006-06-21 10:27:26 -030041static unsigned int dst_algo;
42module_param(dst_algo, int, 0644);
43MODULE_PARM_DESC(dst_algo, "tuning algo: default is 0=(SW), 1=(HW)");
44
Manu Abrahama427de62005-09-09 13:03:00 -070045#define HAS_LOCK 1
46#define ATTEMPT_TUNE 2
47#define HAS_POWER 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Manu Abrahama427de62005-09-09 13:03:00 -070049#define DST_ERROR 0
50#define DST_NOTICE 1
51#define DST_INFO 2
52#define DST_DEBUG 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Manu Abrahama427de62005-09-09 13:03:00 -070054#define dprintk(x, y, z, format, arg...) do { \
55 if (z) { \
56 if ((x > DST_ERROR) && (x > y)) \
57 printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \
58 else if ((x > DST_NOTICE) && (x > y)) \
59 printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \
60 else if ((x > DST_INFO) && (x > y)) \
61 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \
62 else if ((x > DST_DEBUG) && (x > y)) \
63 printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \
64 } else { \
65 if (x > y) \
66 printk(format, ##arg); \
67 } \
68} while(0)
69
70
71static void dst_packsize(struct dst_state *state, int psize)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 union dst_gpio_packet bits;
74
75 bits.psize = psize;
76 bt878_device_control(state->bt, DST_IG_TS, &bits);
77}
78
Manu Abrahama427de62005-09-09 13:03:00 -070079int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 union dst_gpio_packet enb;
82 union dst_gpio_packet bits;
83 int err;
84
85 enb.enb.mask = mask;
86 enb.enb.enable = enbb;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070087
Manu Abrahama427de62005-09-09 13:03:00 -070088 dprintk(verbose, DST_INFO, 1, "mask=[%04x], enbb=[%04x], outhigh=[%04x]", mask, enbb, outhigh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -070090 dprintk(verbose, DST_INFO, 1, "dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)", err, mask, enbb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return -EREMOTEIO;
92 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -070093 udelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 /* because complete disabling means no output, no need to do output packet */
95 if (enbb == 0)
96 return 0;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070097 if (delay)
98 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 bits.outp.mask = enbb;
100 bits.outp.highvals = outhigh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700102 dprintk(verbose, DST_INFO, 1, "dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)", err, enbb, outhigh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return -EREMOTEIO;
104 }
Manu Abrahama427de62005-09-09 13:03:00 -0700105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return 0;
107}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700108EXPORT_SYMBOL(dst_gpio_outb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Manu Abrahama427de62005-09-09 13:03:00 -0700110int dst_gpio_inb(struct dst_state *state, u8 *result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 union dst_gpio_packet rd_packet;
113 int err;
114
115 *result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700117 dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb error (err == %i)\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -EREMOTEIO;
119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 *result = (u8) rd_packet.rd.value;
Manu Abrahama427de62005-09-09 13:03:00 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return 0;
123}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700124EXPORT_SYMBOL(dst_gpio_inb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700126int rdc_reset_state(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Manu Abrahama427de62005-09-09 13:03:00 -0700128 dprintk(verbose, DST_INFO, 1, "Resetting state machine");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700129 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700130 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700131 return -1;
132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 msleep(10);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700134 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700135 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700136 msleep(10);
137 return -1;
138 }
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return 0;
141}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700142EXPORT_SYMBOL(rdc_reset_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700144int rdc_8820_reset(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Manu Abrahama427de62005-09-09 13:03:00 -0700146 dprintk(verbose, DST_DEBUG, 1, "Resetting DST");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700147 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700148 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700149 return -1;
150 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700151 udelay(1000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700152 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700153 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700154 return -1;
155 }
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return 0;
158}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700159EXPORT_SYMBOL(rdc_8820_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700161int dst_pio_enable(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700163 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700164 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700165 return -1;
166 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700167 udelay(1000);
Manu Abrahama427de62005-09-09 13:03:00 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return 0;
170}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700171EXPORT_SYMBOL(dst_pio_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700173int dst_pio_disable(struct dst_state *state)
174{
175 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700176 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700177 return -1;
178 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700179 if (state->type_flags & DST_TYPE_HAS_FW_1)
180 udelay(1000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700181
182 return 0;
183}
184EXPORT_SYMBOL(dst_pio_disable);
185
186int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 u8 reply;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 int i;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 for (i = 0; i < 200; i++) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700192 if (dst_gpio_inb(state, &reply) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700193 dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb ERROR !");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700194 return -1;
195 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700196 if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700197 dprintk(verbose, DST_INFO, 1, "dst wait ready after %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return 1;
199 }
Johannes Stezenbachb46dd442005-05-16 21:54:44 -0700200 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
Manu Abrahama427de62005-09-09 13:03:00 -0700202 dprintk(verbose, DST_NOTICE, 1, "dst wait NOT ready after %d", i);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return 0;
205}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700206EXPORT_SYMBOL(dst_wait_dst_ready);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700208int dst_error_recovery(struct dst_state *state)
209{
Manu Abrahama427de62005-09-09 13:03:00 -0700210 dprintk(verbose, DST_NOTICE, 1, "Trying to return from previous errors.");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700211 dst_pio_disable(state);
212 msleep(10);
213 dst_pio_enable(state);
214 msleep(10);
215
216 return 0;
217}
218EXPORT_SYMBOL(dst_error_recovery);
219
220int dst_error_bailout(struct dst_state *state)
221{
Manu Abrahama427de62005-09-09 13:03:00 -0700222 dprintk(verbose, DST_INFO, 1, "Trying to bailout from previous error.");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700223 rdc_8820_reset(state);
224 dst_pio_disable(state);
225 msleep(10);
226
227 return 0;
228}
229EXPORT_SYMBOL(dst_error_bailout);
230
Manu Abrahama427de62005-09-09 13:03:00 -0700231int dst_comm_init(struct dst_state *state)
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700232{
Manu Abrahama427de62005-09-09 13:03:00 -0700233 dprintk(verbose, DST_INFO, 1, "Initializing DST.");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700234 if ((dst_pio_enable(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700235 dprintk(verbose, DST_ERROR, 1, "PIO Enable Failed");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700236 return -1;
237 }
238 if ((rdc_reset_state(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700239 dprintk(verbose, DST_ERROR, 1, "RDC 8820 State RESET Failed.");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700240 return -1;
241 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700242 if (state->type_flags & DST_TYPE_HAS_FW_1)
243 msleep(100);
244 else
245 msleep(5);
246
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700247 return 0;
248}
249EXPORT_SYMBOL(dst_comm_init);
250
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700251int write_dst(struct dst_state *state, u8 *data, u8 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 struct i2c_msg msg = {
Manu Abrahama427de62005-09-09 13:03:00 -0700254 .addr = state->config->demod_address,
255 .flags = 0,
256 .buf = data,
257 .len = len
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 };
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 int err;
Manu Abrahama427de62005-09-09 13:03:00 -0700261 u8 cnt, i;
262
263 dprintk(verbose, DST_NOTICE, 0, "writing [ ");
264 for (i = 0; i < len; i++)
265 dprintk(verbose, DST_NOTICE, 0, "%02x ", data[i]);
266 dprintk(verbose, DST_NOTICE, 0, "]\n");
267
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700268 for (cnt = 0; cnt < 2; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700270 dprintk(verbose, DST_INFO, 1, "_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, data[0]);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700271 dst_error_recovery(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 continue;
273 } else
274 break;
275 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700276 if (cnt >= 2) {
Manu Abrahama427de62005-09-09 13:03:00 -0700277 dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700278 dst_error_bailout(state);
279
280 return -1;
281 }
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return 0;
284}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700285EXPORT_SYMBOL(write_dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Manu Abrahama427de62005-09-09 13:03:00 -0700287int read_dst(struct dst_state *state, u8 *ret, u8 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Manu Abrahama427de62005-09-09 13:03:00 -0700289 struct i2c_msg msg = {
290 .addr = state->config->demod_address,
291 .flags = I2C_M_RD,
292 .buf = ret,
293 .len = len
294 };
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 int err;
297 int cnt;
298
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700299 for (cnt = 0; cnt < 2; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700301 dprintk(verbose, DST_INFO, 1, "read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, ret[0]);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700302 dst_error_recovery(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 continue;
304 } else
305 break;
306 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700307 if (cnt >= 2) {
Manu Abrahama427de62005-09-09 13:03:00 -0700308 dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700309 dst_error_bailout(state);
310
311 return -1;
312 }
Manu Abrahama427de62005-09-09 13:03:00 -0700313 dprintk(verbose, DST_DEBUG, 1, "reply is 0x%x", ret[0]);
314 for (err = 1; err < len; err++)
315 dprintk(verbose, DST_DEBUG, 0, " 0x%x", ret[err]);
316 if (err > 1)
317 dprintk(verbose, DST_DEBUG, 0, "\n");
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) {
Manu Abrahama427de62005-09-09 13:03:00 -0700326 case SEC_VOLTAGE_13: /* Vertical */
327 dprintk(verbose, DST_INFO, 1, "Polarization=[Vertical]");
328 state->tx_tuna[8] &= ~0x40;
329 break;
330 case SEC_VOLTAGE_18: /* Horizontal */
331 dprintk(verbose, DST_INFO, 1, "Polarization=[Horizontal]");
332 state->tx_tuna[8] |= 0x40;
333 break;
334 case SEC_VOLTAGE_OFF:
335 break;
Manu Abraham7d534212005-07-07 17:57:50 -0700336 }
337
338 return 0;
339}
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341static int dst_set_freq(struct dst_state *state, u32 freq)
342{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 state->frequency = freq;
Manu Abrahama427de62005-09-09 13:03:00 -0700344 dprintk(verbose, DST_INFO, 1, "set Frequency %u", freq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 if (state->dst_type == DST_TYPE_IS_SAT) {
347 freq = freq / 1000;
348 if (freq < 950 || freq > 2150)
349 return -EINVAL;
Manu Abraham7d534212005-07-07 17:57:50 -0700350 state->tx_tuna[2] = (freq >> 8);
351 state->tx_tuna[3] = (u8) freq;
352 state->tx_tuna[4] = 0x01;
353 state->tx_tuna[8] &= ~0x04;
354 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
355 if (freq < 1531)
356 state->tx_tuna[8] |= 0x04;
357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 } else if (state->dst_type == DST_TYPE_IS_TERR) {
359 freq = freq / 1000;
360 if (freq < 137000 || freq > 858000)
361 return -EINVAL;
Manu Abraham7d534212005-07-07 17:57:50 -0700362 state->tx_tuna[2] = (freq >> 16) & 0xff;
363 state->tx_tuna[3] = (freq >> 8) & 0xff;
364 state->tx_tuna[4] = (u8) freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
Manu Abraham62867422005-09-09 13:03:02 -0700366 freq = freq / 1000;
Manu Abraham7d534212005-07-07 17:57:50 -0700367 state->tx_tuna[2] = (freq >> 16) & 0xff;
368 state->tx_tuna[3] = (freq >> 8) & 0xff;
369 state->tx_tuna[4] = (u8) freq;
Manu Abrahamed3d1062006-06-21 10:27:15 -0300370 } else if (state->dst_type == DST_TYPE_IS_ATSC) {
371 freq = freq / 1000;
372 if (freq < 51000 || freq > 858000)
373 return -EINVAL;
374 state->tx_tuna[2] = (freq >> 16) & 0xff;
375 state->tx_tuna[3] = (freq >> 8) & 0xff;
376 state->tx_tuna[4] = (u8) freq;
377 state->tx_tuna[5] = 0x00; /* ATSC */
378 state->tx_tuna[6] = 0x00;
379 if (state->dst_hw_cap & DST_TYPE_HAS_ANALOG)
380 state->tx_tuna[7] = 0x00; /* Digital */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 } else
382 return -EINVAL;
Manu Abrahama427de62005-09-09 13:03:00 -0700383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return 0;
385}
386
Manu Abrahama427de62005-09-09 13:03:00 -0700387static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 state->bandwidth = bandwidth;
390
391 if (state->dst_type != DST_TYPE_IS_TERR)
392 return 0;
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 switch (bandwidth) {
Manu Abrahama427de62005-09-09 13:03:00 -0700395 case BANDWIDTH_6_MHZ:
396 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
397 state->tx_tuna[7] = 0x06;
398 else {
399 state->tx_tuna[6] = 0x06;
400 state->tx_tuna[7] = 0x00;
401 }
402 break;
403 case BANDWIDTH_7_MHZ:
404 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
405 state->tx_tuna[7] = 0x07;
406 else {
407 state->tx_tuna[6] = 0x07;
408 state->tx_tuna[7] = 0x00;
409 }
410 break;
411 case BANDWIDTH_8_MHZ:
412 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
413 state->tx_tuna[7] = 0x08;
414 else {
415 state->tx_tuna[6] = 0x08;
416 state->tx_tuna[7] = 0x00;
417 }
418 break;
419 default:
420 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
Manu Abrahama427de62005-09-09 13:03:00 -0700422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return 0;
424}
425
Manu Abrahama427de62005-09-09 13:03:00 -0700426static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t inversion)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 state->inversion = inversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 switch (inversion) {
Manu Abrahama427de62005-09-09 13:03:00 -0700430 case INVERSION_OFF: /* Inversion = Normal */
431 state->tx_tuna[8] &= ~0x80;
432 break;
433 case INVERSION_ON:
434 state->tx_tuna[8] |= 0x80;
435 break;
436 default:
437 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
Manu Abrahama427de62005-09-09 13:03:00 -0700439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return 0;
441}
442
Manu Abrahama427de62005-09-09 13:03:00 -0700443static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 state->fec = fec;
446 return 0;
447}
448
Manu Abrahama427de62005-09-09 13:03:00 -0700449static fe_code_rate_t dst_get_fec(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
451 return state->fec;
452}
453
Manu Abrahama427de62005-09-09 13:03:00 -0700454static int dst_set_symbolrate(struct dst_state *state, u32 srate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 u32 symcalc;
457 u64 sval;
458
459 state->symbol_rate = srate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (state->dst_type == DST_TYPE_IS_TERR) {
461 return 0;
462 }
Manu Abrahama427de62005-09-09 13:03:00 -0700463 dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 srate /= 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
466 sval = srate;
467 sval <<= 20;
468 do_div(sval, 88000);
469 symcalc = (u32) sval;
Manu Abrahama427de62005-09-09 13:03:00 -0700470 dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
Manu Abrahamf612c572005-09-09 13:02:58 -0700471 state->tx_tuna[5] = (u8) (symcalc >> 12);
472 state->tx_tuna[6] = (u8) (symcalc >> 4);
473 state->tx_tuna[7] = (u8) (symcalc << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 } else {
Manu Abrahamf612c572005-09-09 13:02:58 -0700475 state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
476 state->tx_tuna[6] = (u8) (srate >> 8);
477 state->tx_tuna[7] = (u8) srate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
Manu Abrahamf612c572005-09-09 13:02:58 -0700479 state->tx_tuna[8] &= ~0x20;
480 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
481 if (srate > 8000)
482 state->tx_tuna[8] |= 0x20;
483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 return 0;
485}
486
Manu Abraham7d534212005-07-07 17:57:50 -0700487
488static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
489{
490 if (state->dst_type != DST_TYPE_IS_CABLE)
491 return 0;
492
493 state->modulation = modulation;
494 switch (modulation) {
Manu Abrahama427de62005-09-09 13:03:00 -0700495 case QAM_16:
496 state->tx_tuna[8] = 0x10;
497 break;
498 case QAM_32:
499 state->tx_tuna[8] = 0x20;
500 break;
501 case QAM_64:
502 state->tx_tuna[8] = 0x40;
503 break;
504 case QAM_128:
505 state->tx_tuna[8] = 0x80;
506 break;
507 case QAM_256:
508 state->tx_tuna[8] = 0x00;
509 break;
510 case QPSK:
511 case QAM_AUTO:
512 case VSB_8:
513 case VSB_16:
514 default:
515 return -EINVAL;
Manu Abraham7d534212005-07-07 17:57:50 -0700516
517 }
518
519 return 0;
520}
521
522static fe_modulation_t dst_get_modulation(struct dst_state *state)
523{
524 return state->modulation;
525}
526
527
Manu Abrahama427de62005-09-09 13:03:00 -0700528u8 dst_check_sum(u8 *buf, u32 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
530 u32 i;
531 u8 val = 0;
532 if (!len)
533 return 0;
534 for (i = 0; i < len; i++) {
535 val += buf[i];
536 }
537 return ((~val) + 1);
538}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700539EXPORT_SYMBOL(dst_check_sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541static void dst_type_flags_print(u32 type_flags)
542{
Manu Abrahama427de62005-09-09 13:03:00 -0700543 dprintk(verbose, DST_ERROR, 0, "DST type flags :");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (type_flags & DST_TYPE_HAS_NEWTUNE)
Manu Abrahama427de62005-09-09 13:03:00 -0700545 dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 if (type_flags & DST_TYPE_HAS_TS204)
Manu Abrahama427de62005-09-09 13:03:00 -0700547 dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (type_flags & DST_TYPE_HAS_SYMDIV)
Manu Abrahama427de62005-09-09 13:03:00 -0700549 dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700550 if (type_flags & DST_TYPE_HAS_FW_1)
Manu Abrahama427de62005-09-09 13:03:00 -0700551 dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700552 if (type_flags & DST_TYPE_HAS_FW_2)
Manu Abrahama427de62005-09-09 13:03:00 -0700553 dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700554 if (type_flags & DST_TYPE_HAS_FW_3)
Manu Abrahama427de62005-09-09 13:03:00 -0700555 dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
556 dprintk(verbose, DST_ERROR, 0, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700559
Manu Abrahama427de62005-09-09 13:03:00 -0700560static int dst_type_print(u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 char *otype;
563 switch (type) {
564 case DST_TYPE_IS_SAT:
565 otype = "satellite";
566 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 case DST_TYPE_IS_TERR:
569 otype = "terrestrial";
570 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 case DST_TYPE_IS_CABLE:
573 otype = "cable";
574 break;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700575
Manu Abrahambc7386b2006-06-21 10:27:05 -0300576 case DST_TYPE_IS_ATSC:
577 otype = "atsc";
578 break;
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 default:
Manu Abrahama427de62005-09-09 13:03:00 -0700581 dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 return -EINVAL;
583 }
Manu Abrahama427de62005-09-09 13:03:00 -0700584 dprintk(verbose, DST_INFO, 1, "DST type: %s", otype);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return 0;
587}
588
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700589/*
590 Known cards list
591 Satellite
592 -------------------
Johannes Stezenbache6ac6992005-05-16 21:54:42 -0700593 200103A
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700594 VP-1020 DST-MOT LG(old), TS=188
595
596 VP-1020 DST-03T LG(new), TS=204
597 VP-1022 DST-03T LG(new), TS=204
598 VP-1025 DST-03T LG(new), TS=204
599
600 VP-1030 DSTMCI, LG(new), TS=188
601 VP-1032 DSTMCI, LG(new), TS=188
602
603 Cable
604 -------------------
605 VP-2030 DCT-CI, Samsung, TS=204
606 VP-2021 DCT-CI, Unknown, TS=204
607 VP-2031 DCT-CI, Philips, TS=188
608 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
609 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
610
611 Terrestrial
612 -------------------
613 VP-3050 DTTNXT TS=188
614 VP-3040 DTT-CI, Philips, TS=188
615 VP-3040 DTT-CI, Philips, TS=204
616
617 ATSC
618 -------------------
619 VP-3220 ATSCDI, TS=188
620 VP-3250 ATSCAD, TS=188
621
622*/
623
Adrian Bunk47a9e502006-02-27 00:07:55 -0300624static struct dst_types dst_tlist[] = {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700625 {
Johannes Stezenbache6ac6992005-05-16 21:54:42 -0700626 .device_id = "200103A",
627 .offset = 0,
628 .dst_type = DST_TYPE_IS_SAT,
Manu Abraham7d534212005-07-07 17:57:50 -0700629 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
Manu Abraham396cffd2006-06-21 10:27:49 -0300630 .dst_feature = 0,
631 .tuner_type = 0
Johannes Stezenbache6ac6992005-05-16 21:54:42 -0700632 }, /* obsolete */
633
634 {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700635 .device_id = "DST-020",
636 .offset = 0,
637 .dst_type = DST_TYPE_IS_SAT,
638 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
Manu Abraham396cffd2006-06-21 10:27:49 -0300639 .dst_feature = 0,
640 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700641 }, /* obsolete */
642
643 {
644 .device_id = "DST-030",
645 .offset = 0,
646 .dst_type = DST_TYPE_IS_SAT,
647 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
Manu Abraham396cffd2006-06-21 10:27:49 -0300648 .dst_feature = 0,
649 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700650 }, /* obsolete */
651
652 {
653 .device_id = "DST-03T",
654 .offset = 0,
655 .dst_type = DST_TYPE_IS_SAT,
656 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
657 .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
Manu Abraham396cffd2006-06-21 10:27:49 -0300658 | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO,
659 .tuner_type = TUNER_TYPE_STV0299
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700660 },
661
662 {
663 .device_id = "DST-MOT",
664 .offset = 0,
665 .dst_type = DST_TYPE_IS_SAT,
666 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
Manu Abraham396cffd2006-06-21 10:27:49 -0300667 .dst_feature = 0,
668 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700669 }, /* obsolete */
670
671 {
672 .device_id = "DST-CI",
673 .offset = 1,
674 .dst_type = DST_TYPE_IS_SAT,
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300675 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_1,
Manu Abraham396cffd2006-06-21 10:27:49 -0300676 .dst_feature = DST_TYPE_HAS_CA,
677 .tuner_type = 0
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700678 }, /* An OEM board */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700679
680 {
681 .device_id = "DSTMCI",
682 .offset = 1,
683 .dst_type = DST_TYPE_IS_SAT,
Manu Abraham7d534212005-07-07 17:57:50 -0700684 .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 -0700685 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
Manu Abraham396cffd2006-06-21 10:27:49 -0300686 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC,
687 .tuner_type = TUNER_TYPE_MULTI
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700688 },
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,
Manu Abraham396cffd2006-06-21 10:27:49 -0300695 .dst_feature = 0,
696 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700697 }, /* unknown to vendor */
698
699 {
700 .device_id = "DCT-CI",
701 .offset = 1,
702 .dst_type = DST_TYPE_IS_CABLE,
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300703 .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_FW_2,
Manu Abraham396cffd2006-06-21 10:27:49 -0300704 .dst_feature = DST_TYPE_HAS_CA,
705 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700706 },
707
708 {
709 .device_id = "DCTNEW",
710 .offset = 1,
711 .dst_type = DST_TYPE_IS_CABLE,
Manu Abraham62121b12005-09-09 13:03:01 -0700712 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD,
Manu Abraham396cffd2006-06-21 10:27:49 -0300713 .dst_feature = 0,
714 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700715 },
716
717 {
718 .device_id = "DTT-CI",
719 .offset = 1,
720 .dst_type = DST_TYPE_IS_TERR,
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300721 .type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE,
Manu Abraham396cffd2006-06-21 10:27:49 -0300722 .dst_feature = DST_TYPE_HAS_CA,
723 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700724 },
725
726 {
727 .device_id = "DTTDIG",
728 .offset = 1,
729 .dst_type = DST_TYPE_IS_TERR,
730 .type_flags = DST_TYPE_HAS_FW_2,
Manu Abraham396cffd2006-06-21 10:27:49 -0300731 .dst_feature = 0,
732 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700733 },
734
735 {
736 .device_id = "DTTNXT",
737 .offset = 1,
738 .dst_type = DST_TYPE_IS_TERR,
739 .type_flags = DST_TYPE_HAS_FW_2,
Manu Abraham396cffd2006-06-21 10:27:49 -0300740 .dst_feature = DST_TYPE_HAS_ANALOG,
741 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700742 },
743
744 {
745 .device_id = "ATSCDI",
746 .offset = 1,
747 .dst_type = DST_TYPE_IS_ATSC,
748 .type_flags = DST_TYPE_HAS_FW_2,
Manu Abraham396cffd2006-06-21 10:27:49 -0300749 .dst_feature = 0,
750 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700751 },
752
753 {
754 .device_id = "ATSCAD",
755 .offset = 1,
756 .dst_type = DST_TYPE_IS_ATSC,
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300757 .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
Manu Abraham396cffd2006-06-21 10:27:49 -0300758 .dst_feature = DST_TYPE_HAS_MAC | DST_TYPE_HAS_ANALOG,
759 .tuner_type = 0
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700760 },
761
762 { }
763
764};
765
Manu Abraham62121b12005-09-09 13:03:01 -0700766static int dst_get_mac(struct dst_state *state)
767{
768 u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
769 get_mac[7] = dst_check_sum(get_mac, 7);
770 if (dst_command(state, get_mac, 8) < 0) {
771 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
772 return -1;
773 }
774 memset(&state->mac_address, '\0', 8);
775 memcpy(&state->mac_address, &state->rxbuffer, 6);
776 dprintk(verbose, DST_ERROR, 1, "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
777 state->mac_address[0], state->mac_address[1], state->mac_address[2],
778 state->mac_address[4], state->mac_address[5], state->mac_address[6]);
779
780 return 0;
781}
782
783static int dst_fw_ver(struct dst_state *state)
784{
785 u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
786 get_ver[7] = dst_check_sum(get_ver, 7);
787 if (dst_command(state, get_ver, 8) < 0) {
788 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
789 return -1;
790 }
791 memset(&state->fw_version, '\0', 8);
792 memcpy(&state->fw_version, &state->rxbuffer, 8);
793 dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
794 state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
795 state->fw_version[1],
796 state->fw_version[5], state->fw_version[6],
797 state->fw_version[4], state->fw_version[3], state->fw_version[2]);
798
799 return 0;
800}
801
802static int dst_card_type(struct dst_state *state)
803{
804 u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
805 get_type[7] = dst_check_sum(get_type, 7);
806 if (dst_command(state, get_type, 8) < 0) {
807 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
808 return -1;
809 }
810 memset(&state->card_info, '\0', 8);
811 memcpy(&state->card_info, &state->rxbuffer, 8);
812 dprintk(verbose, DST_ERROR, 1, "Device Model=[%s]", &state->card_info[0]);
813
814 return 0;
815}
816
817static int dst_get_vendor(struct dst_state *state)
818{
819 u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
820 get_vendor[7] = dst_check_sum(get_vendor, 7);
821 if (dst_command(state, get_vendor, 8) < 0) {
822 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
823 return -1;
824 }
825 memset(&state->vendor, '\0', 8);
826 memcpy(&state->vendor, &state->rxbuffer, 8);
827 dprintk(verbose, DST_ERROR, 1, "Vendor=[%s]", &state->vendor[0]);
828
829 return 0;
830}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700831
Manu Abraham29b2f782005-11-08 21:35:09 -0800832static int dst_get_tuner_info(struct dst_state *state)
833{
834 u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
835 u8 get_tuner_2[] = { 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
836
837 get_tuner_1[7] = dst_check_sum(get_tuner_1, 7);
838 get_tuner_2[7] = dst_check_sum(get_tuner_2, 7);
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300839 dprintk(verbose, DST_ERROR, 1, "DST TYpe = MULTI FE");
Manu Abraham29b2f782005-11-08 21:35:09 -0800840 if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300841// if (dst_command(state, get_tuner_2, 8) < 0) {
842 if (dst_command(state, get_tuner_1, 8) < 0) {
843 dprintk(verbose, DST_INFO, 1, "Cmd=[0x13], Unsupported");
Manu Abraham29b2f782005-11-08 21:35:09 -0800844 return -1;
845 }
846 } else {
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300847// if (dst_command(state, get_tuner_1, 8) < 0) {
848 if (dst_command(state, get_tuner_2, 8) < 0) {
849 dprintk(verbose, DST_INFO, 1, "Cmd=[0xb], Unsupported");
Manu Abraham29b2f782005-11-08 21:35:09 -0800850 return -1;
851 }
852 }
853 memset(&state->board_info, '\0', 8);
854 memcpy(&state->board_info, &state->rxbuffer, 8);
855 if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300856 dprintk(verbose, DST_ERROR, 1, "DST type has TS=188");
857/*
Manu Abraham29b2f782005-11-08 21:35:09 -0800858 if (state->board_info[1] == 0x0b) {
859 if (state->type_flags & DST_TYPE_HAS_TS204)
860 state->type_flags &= ~DST_TYPE_HAS_TS204;
861 state->type_flags |= DST_TYPE_HAS_NEWTUNE;
862 dprintk(verbose, DST_INFO, 1, "DST type has TS=188");
863 } else {
864 if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
865 state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
866 state->type_flags |= DST_TYPE_HAS_TS204;
867 dprintk(verbose, DST_INFO, 1, "DST type has TS=204");
868 }
869 } else {
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300870*/
Manu Abraham29b2f782005-11-08 21:35:09 -0800871 }
Manu Abrahamc65f1c52006-06-21 10:27:40 -0300872 if (state->board_info[0] == 0xbc) {
873// if (state->type_flags & DST_TYPE_HAS_TS204)
874// state->type_flags &= ~DST_TYPE_HAS_TS204;
875 state->type_flags |= DST_TYPE_HAS_NEWTUNE;
876 dprintk(verbose, DST_INFO, 1, "DST type has TS=188, Daughterboard=[%d]", state->board_info[1]);
877
878 } else if (state->board_info[0] == 0xcc) {
879// if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
880// state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
881 state->type_flags |= DST_TYPE_HAS_TS204;
882 dprintk(verbose, DST_INFO, 1, "DST type has TS=204 Daughterboard=[%d]", state->board_info[1]);
883 }
884// }
Manu Abraham29b2f782005-11-08 21:35:09 -0800885
886 return 0;
887}
888
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700889static int dst_get_device_id(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700891 u8 reply;
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 int i;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700894 struct dst_types *p_dst_type;
895 u8 use_dst_type = 0;
896 u32 use_type_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700898 static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700900 device_type[7] = dst_check_sum(device_type, 7);
901
902 if (write_dst(state, device_type, FIXED_COMM))
903 return -1; /* Write failed */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700904 if ((dst_pio_disable(state)) < 0)
905 return -1;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700906 if (read_dst(state, &reply, GET_ACK))
907 return -1; /* Read failure */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700908 if (reply != ACK) {
Manu Abrahama427de62005-09-09 13:03:00 -0700909 dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700910 return -1; /* Unack'd write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700912 if (!dst_wait_dst_ready(state, DEVICE_INIT))
913 return -1; /* DST not ready yet */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700914 if (read_dst(state, state->rxbuffer, FIXED_COMM))
915 return -1;
916
917 dst_pio_disable(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700918 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
Manu Abrahama427de62005-09-09 13:03:00 -0700919 dprintk(verbose, DST_INFO, 1, "Checksum failure!");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700920 return -1; /* Checksum failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700922 state->rxbuffer[7] = '\0';
923
Manu Abrahama427de62005-09-09 13:03:00 -0700924 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700925 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
926 use_type_flags = p_dst_type->type_flags;
927 use_dst_type = p_dst_type->dst_type;
928
929 /* Card capabilities */
930 state->dst_hw_cap = p_dst_type->dst_feature;
Manu Abrahama427de62005-09-09 13:03:00 -0700931 dprintk(verbose, DST_ERROR, 1, "Recognise [%s]\n", p_dst_type->device_id);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 break;
934 }
935 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700936
937 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
Manu Abrahama427de62005-09-09 13:03:00 -0700938 dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
939 dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 use_dst_type = DST_TYPE_IS_SAT;
941 use_type_flags = DST_TYPE_HAS_SYMDIV;
942 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700943 dst_type_print(use_dst_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 state->type_flags = use_type_flags;
945 state->dst_type = use_dst_type;
946 dst_type_flags_print(state->type_flags);
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 return 0;
949}
950
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700951static int dst_probe(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Ingo Molnar3593cab2006-02-07 06:49:14 -0200953 mutex_init(&state->dst_mutex);
Manu Abraham2e506a02006-06-21 10:27:20 -0300954 if (dst_addons & DST_TYPE_HAS_CA) {
955 if ((rdc_8820_reset(state)) < 0) {
956 dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
957 return -1;
958 }
Johannes Stezenbach4a2cc122005-05-16 21:54:45 -0700959 msleep(4000);
Manu Abraham2e506a02006-06-21 10:27:20 -0300960 } else {
Johannes Stezenbach4a2cc122005-05-16 21:54:45 -0700961 msleep(100);
Manu Abraham2e506a02006-06-21 10:27:20 -0300962 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700963 if ((dst_comm_init(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700964 dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700965 return -1;
966 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -0700967 msleep(100);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700968 if (dst_get_device_id(state) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -0700969 dprintk(verbose, DST_ERROR, 1, "unknown device.");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700970 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 }
Manu Abraham62121b12005-09-09 13:03:01 -0700972 if (dst_get_mac(state) < 0) {
973 dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
974 return 0;
975 }
Manu Abraham29b2f782005-11-08 21:35:09 -0800976 if ((state->type_flags & DST_TYPE_HAS_MULTI_FE) || (state->type_flags & DST_TYPE_HAS_FW_BUILD)) {
977 if (dst_get_tuner_info(state) < 0)
978 dprintk(verbose, DST_INFO, 1, "Tuner: Unsupported command");
979 }
Manu Abraham4c09aa72005-11-08 21:35:20 -0800980 if (state->type_flags & DST_TYPE_HAS_TS204) {
981 dst_packsize(state, 204);
982 }
Manu Abraham62121b12005-09-09 13:03:01 -0700983 if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
984 if (dst_fw_ver(state) < 0) {
985 dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
986 return 0;
987 }
988 if (dst_card_type(state) < 0) {
989 dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
990 return 0;
991 }
992 if (dst_get_vendor(state) < 0) {
993 dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
994 return 0;
995 }
996 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700997
998 return 0;
999}
1000
Manu Abrahama427de62005-09-09 13:03:00 -07001001int dst_command(struct dst_state *state, u8 *data, u8 len)
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001002{
1003 u8 reply;
Manu Abrahamd28d5762005-11-08 21:35:36 -08001004
Ingo Molnar3593cab2006-02-07 06:49:14 -02001005 mutex_lock(&state->dst_mutex);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001006 if ((dst_comm_init(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001007 dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
Manu Abrahamd28d5762005-11-08 21:35:36 -08001008 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001010 if (write_dst(state, data, len)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001011 dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001012 if ((dst_error_recovery(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001013 dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
Manu Abrahamd28d5762005-11-08 21:35:36 -08001014 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001015 }
Manu Abrahamd28d5762005-11-08 21:35:36 -08001016 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001017 }
1018 if ((dst_pio_disable(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001019 dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
Manu Abrahamd28d5762005-11-08 21:35:36 -08001020 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001021 }
Johannes Stezenbach8385e462005-05-16 21:54:43 -07001022 if (state->type_flags & DST_TYPE_HAS_FW_1)
1023 udelay(3000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001024 if (read_dst(state, &reply, GET_ACK)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001025 dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001026 if ((dst_error_recovery(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001027 dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
Manu Abrahamd28d5762005-11-08 21:35:36 -08001028 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001029 }
Manu Abrahamd28d5762005-11-08 21:35:36 -08001030 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001031 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001032 if (reply != ACK) {
Manu Abrahama427de62005-09-09 13:03:00 -07001033 dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
Manu Abrahamd28d5762005-11-08 21:35:36 -08001034 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
Manu Abrahamd28d5762005-11-08 21:35:36 -08001037 goto error;
Johannes Stezenbach8385e462005-05-16 21:54:43 -07001038 if (state->type_flags & DST_TYPE_HAS_FW_1)
1039 udelay(3000);
1040 else
1041 udelay(2000);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001042 if (!dst_wait_dst_ready(state, NO_DELAY))
Manu Abrahamd28d5762005-11-08 21:35:36 -08001043 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001044 if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001045 dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001046 if ((dst_error_recovery(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001047 dprintk(verbose, DST_INFO, 1, "Recovery failed.");
Manu Abrahamd28d5762005-11-08 21:35:36 -08001048 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001049 }
Manu Abrahamd28d5762005-11-08 21:35:36 -08001050 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001053 dprintk(verbose, DST_INFO, 1, "checksum failure");
Manu Abrahamd28d5762005-11-08 21:35:36 -08001054 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
Ingo Molnar3593cab2006-02-07 06:49:14 -02001056 mutex_unlock(&state->dst_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 return 0;
Manu Abrahamd28d5762005-11-08 21:35:36 -08001058
1059error:
Ingo Molnar3593cab2006-02-07 06:49:14 -02001060 mutex_unlock(&state->dst_mutex);
Manu Abrahamd28d5762005-11-08 21:35:36 -08001061 return -EIO;
1062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001064EXPORT_SYMBOL(dst_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Manu Abrahama427de62005-09-09 13:03:00 -07001066static int dst_get_signal(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
1068 int retval;
1069 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
Johannes Stezenbach5b5b5342005-09-09 13:02:52 -07001070 //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
1072 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1073 return 0;
1074 }
1075 if (0 == (state->diseq_flags & HAS_LOCK)) {
1076 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1077 return 0;
1078 }
1079 if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
1080 retval = dst_command(state, get_signal, 8);
1081 if (retval < 0)
1082 return retval;
1083 if (state->dst_type == DST_TYPE_IS_SAT) {
1084 state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
1085 state->decode_strength = state->rxbuffer[5] << 8;
1086 state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
1087 } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
1088 state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
1089 state->decode_strength = state->rxbuffer[4] << 8;
1090 state->decode_snr = state->rxbuffer[3] << 8;
Manu Abrahamed3d1062006-06-21 10:27:15 -03001091 } else if (state->dst_type == DST_TYPE_IS_ATSC) {
1092 state->decode_lock = (state->rxbuffer[6] == 0x00) ? 1 : 0;
1093 state->decode_strength = state->rxbuffer[4] << 8;
1094 state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 }
1096 state->cur_jiff = jiffies;
1097 }
1098 return 0;
1099}
1100
Manu Abrahama427de62005-09-09 13:03:00 -07001101static int dst_tone_power_cmd(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
1103 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
1104
1105 if (state->dst_type == DST_TYPE_IS_TERR)
1106 return 0;
Manu Abraham8f6da8f2005-05-28 15:51:51 -07001107 paket[4] = state->tx_tuna[4];
Manu Abraham86360a32005-05-28 15:51:51 -07001108 paket[2] = state->tx_tuna[2];
Manu Abraham203fe8b2005-05-28 15:51:48 -07001109 paket[3] = state->tx_tuna[3];
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001110 paket[7] = dst_check_sum (paket, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 dst_command(state, paket, 8);
Manu Abraham203fe8b2005-05-28 15:51:48 -07001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 return 0;
1114}
1115
Manu Abrahama427de62005-09-09 13:03:00 -07001116static int dst_get_tuna(struct dst_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
1118 int retval;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
1121 return 0;
1122 state->diseq_flags &= ~(HAS_LOCK);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001123 if (!dst_wait_dst_ready(state, NO_DELAY))
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001124 return -EIO;
Manu Abrahama427de62005-09-09 13:03:00 -07001125 if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 /* how to get variable length reply ???? */
1127 retval = read_dst(state, state->rx_tuna, 10);
Manu Abrahama427de62005-09-09 13:03:00 -07001128 else
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001129 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 if (retval < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001131 dprintk(verbose, DST_DEBUG, 1, "read not successful");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001132 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
1134 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
1135 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001136 dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001137 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 }
1139 } else {
1140 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001141 dprintk(verbose, DST_INFO, 1, "checksum failure? ");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001142 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
1144 }
1145 if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
1146 return 0;
Tom Hughesf5648e82005-11-08 21:35:22 -08001147 if (state->dst_type == DST_TYPE_IS_SAT) {
1148 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
1149 } else {
1150 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 16) + (state->rx_tuna[3] << 8) + state->rx_tuna[4];
1151 }
1152 state->decode_freq = state->decode_freq * 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 state->decode_lock = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 state->diseq_flags |= HAS_LOCK;
Manu Abraham7d534212005-07-07 17:57:50 -07001155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 return 1;
1157}
1158
Manu Abrahama427de62005-09-09 13:03:00 -07001159static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Manu Abrahama427de62005-09-09 13:03:00 -07001161static int dst_write_tuna(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Manu Abrahama427de62005-09-09 13:03:00 -07001163 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 int retval;
1165 u8 reply;
1166
Manu Abrahama427de62005-09-09 13:03:00 -07001167 dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 state->decode_freq = 0;
1169 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1170 if (state->dst_type == DST_TYPE_IS_SAT) {
1171 if (!(state->diseq_flags & HAS_POWER))
1172 dst_set_voltage(fe, SEC_VOLTAGE_13);
1173 }
1174 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001175 mutex_lock(&state->dst_mutex);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001176 if ((dst_comm_init(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001177 dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001178 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
1182 retval = write_dst(state, &state->tx_tuna[0], 10);
1183 } else {
1184 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001185 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
1187 if (retval < 0) {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001188 dst_pio_disable(state);
Manu Abrahama427de62005-09-09 13:03:00 -07001189 dprintk(verbose, DST_DEBUG, 1, "write not successful");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001190 goto werr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001192 if ((dst_pio_disable(state)) < 0) {
Manu Abrahama427de62005-09-09 13:03:00 -07001193 dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001194 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 }
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001196 if ((read_dst(state, &reply, GET_ACK) < 0)) {
Manu Abrahama427de62005-09-09 13:03:00 -07001197 dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001198 goto error;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001199 }
1200 if (reply != ACK) {
Manu Abrahama427de62005-09-09 13:03:00 -07001201 dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001202 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
1204 state->diseq_flags |= ATTEMPT_TUNE;
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001205 retval = dst_get_tuna(state);
1206werr:
Ingo Molnar3593cab2006-02-07 06:49:14 -02001207 mutex_unlock(&state->dst_mutex);
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001208 return retval;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001209
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001210error:
Ingo Molnar3593cab2006-02-07 06:49:14 -02001211 mutex_unlock(&state->dst_mutex);
Henrik Sjobergf1016de2005-11-08 21:35:38 -08001212 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
1215/*
1216 * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
1217 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
1218 * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
1219 * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
1220 * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
1221 * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
1222 * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
1223 * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
1224 * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
1225 * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
1226 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
1227 */
1228
Manu Abrahama427de62005-09-09 13:03:00 -07001229static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Manu Abrahama427de62005-09-09 13:03:00 -07001231 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1233
Manu Abraham226d97e2005-05-28 15:51:52 -07001234 if (state->dst_type != DST_TYPE_IS_SAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (cmd->msg_len == 0 || cmd->msg_len > 4)
1237 return -EINVAL;
1238 memcpy(&paket[3], cmd->msg, cmd->msg_len);
1239 paket[7] = dst_check_sum(&paket[0], 7);
1240 dst_command(state, paket, 8);
1241 return 0;
1242}
1243
Manu Abrahama427de62005-09-09 13:03:00 -07001244static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 int need_cmd;
Manu Abrahama427de62005-09-09 13:03:00 -07001247 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 state->voltage = voltage;
Manu Abraham226d97e2005-05-28 15:51:52 -07001250 if (state->dst_type != DST_TYPE_IS_SAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 return 0;
1252
1253 need_cmd = 0;
Manu Abrahama427de62005-09-09 13:03:00 -07001254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 switch (voltage) {
Manu Abrahama427de62005-09-09 13:03:00 -07001256 case SEC_VOLTAGE_13:
1257 case SEC_VOLTAGE_18:
1258 if ((state->diseq_flags & HAS_POWER) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 need_cmd = 1;
Manu Abrahama427de62005-09-09 13:03:00 -07001260 state->diseq_flags |= HAS_POWER;
1261 state->tx_tuna[4] = 0x01;
1262 break;
1263 case SEC_VOLTAGE_OFF:
1264 need_cmd = 1;
1265 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
1266 state->tx_tuna[4] = 0x00;
1267 break;
1268 default:
1269 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
Manu Abrahama427de62005-09-09 13:03:00 -07001271
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001272 if (need_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 dst_tone_power_cmd(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 return 0;
1276}
1277
Manu Abrahama427de62005-09-09 13:03:00 -07001278static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Manu Abrahama427de62005-09-09 13:03:00 -07001280 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 state->tone = tone;
Manu Abraham226d97e2005-05-28 15:51:52 -07001283 if (state->dst_type != DST_TYPE_IS_SAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 return 0;
1285
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 switch (tone) {
Manu Abrahama427de62005-09-09 13:03:00 -07001287 case SEC_TONE_OFF:
1288 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1289 state->tx_tuna[2] = 0x00;
1290 else
1291 state->tx_tuna[2] = 0xff;
1292 break;
Steffen Motzer4b2bd302005-07-07 17:58:31 -07001293
Manu Abrahama427de62005-09-09 13:03:00 -07001294 case SEC_TONE_ON:
1295 state->tx_tuna[2] = 0x02;
1296 break;
1297 default:
1298 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 }
1300 dst_tone_power_cmd(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 return 0;
1303}
1304
Manu Abraham203fe8b2005-05-28 15:51:48 -07001305static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1306{
1307 struct dst_state *state = fe->demodulator_priv;
1308
Manu Abraham226d97e2005-05-28 15:51:52 -07001309 if (state->dst_type != DST_TYPE_IS_SAT)
Manu Abraham203fe8b2005-05-28 15:51:48 -07001310 return 0;
Manu Abraham203fe8b2005-05-28 15:51:48 -07001311 state->minicmd = minicmd;
Manu Abraham203fe8b2005-05-28 15:51:48 -07001312 switch (minicmd) {
Manu Abrahama427de62005-09-09 13:03:00 -07001313 case SEC_MINI_A:
1314 state->tx_tuna[3] = 0x02;
1315 break;
1316 case SEC_MINI_B:
1317 state->tx_tuna[3] = 0xff;
1318 break;
Manu Abraham203fe8b2005-05-28 15:51:48 -07001319 }
1320 dst_tone_power_cmd(state);
1321
1322 return 0;
1323}
1324
1325
Manu Abrahama427de62005-09-09 13:03:00 -07001326static int dst_init(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Manu Abrahama427de62005-09-09 13:03:00 -07001328 struct dst_state *state = fe->demodulator_priv;
1329
1330 static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
1331 static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
1332 static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1333 static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1334 static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1335 static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
Manu Abraham1c4e7332006-06-21 10:27:46 -03001336 static u8 atsc_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1337 static u8 atsc_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
Manu Abrahama427de62005-09-09 13:03:00 -07001338
Manu Abraham7d534212005-07-07 17:57:50 -07001339 state->inversion = INVERSION_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 state->voltage = SEC_VOLTAGE_13;
1341 state->tone = SEC_TONE_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 state->diseq_flags = 0;
1343 state->k22 = 0x02;
1344 state->bandwidth = BANDWIDTH_7_MHZ;
1345 state->cur_jiff = jiffies;
Manu Abrahama427de62005-09-09 13:03:00 -07001346 if (state->dst_type == DST_TYPE_IS_SAT)
1347 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
1348 else if (state->dst_type == DST_TYPE_IS_TERR)
1349 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
1350 else if (state->dst_type == DST_TYPE_IS_CABLE)
1351 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
Manu Abraham1c4e7332006-06-21 10:27:46 -03001352 else if (state->dst_type == DST_TYPE_IS_ATSC)
1353 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? atsc_tuna_188 : atsc_tuna_204), sizeof (atsc_tuna_204));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 return 0;
1356}
1357
Manu Abrahama427de62005-09-09 13:03:00 -07001358static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Manu Abrahama427de62005-09-09 13:03:00 -07001360 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 *status = 0;
1363 if (state->diseq_flags & HAS_LOCK) {
Manu Abraham7d534212005-07-07 17:57:50 -07001364// dst_get_signal(state); // don't require(?) to ask MCU
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 if (state->decode_lock)
1366 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
1367 }
1368
1369 return 0;
1370}
1371
Manu Abrahama427de62005-09-09 13:03:00 -07001372static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
Manu Abrahama427de62005-09-09 13:03:00 -07001374 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 dst_get_signal(state);
1377 *strength = state->decode_strength;
1378
1379 return 0;
1380}
1381
Manu Abrahama427de62005-09-09 13:03:00 -07001382static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
Manu Abrahama427de62005-09-09 13:03:00 -07001384 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 dst_get_signal(state);
1387 *snr = state->decode_snr;
1388
1389 return 0;
1390}
1391
Manu Abraham8cfba632006-06-21 10:27:26 -03001392static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
1393{
1394 struct dst_state *state = fe->demodulator_priv;
1395
1396 if (p != NULL) {
1397 dst_set_freq(state, p->frequency);
1398 dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
1399
1400 if (state->dst_type == DST_TYPE_IS_SAT) {
1401 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1402 dst_set_inversion(state, p->inversion);
1403 dst_set_fec(state, p->u.qpsk.fec_inner);
1404 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1405 dst_set_polarization(state);
1406 dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
1407
1408 } else if (state->dst_type == DST_TYPE_IS_TERR)
1409 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
1410 else if (state->dst_type == DST_TYPE_IS_CABLE) {
1411 dst_set_fec(state, p->u.qam.fec_inner);
1412 dst_set_symbolrate(state, p->u.qam.symbol_rate);
1413 dst_set_modulation(state, p->u.qam.modulation);
1414 }
1415 dst_write_tuna(fe);
1416 }
1417
1418 return 0;
1419}
1420
1421static int dst_tune_frontend(struct dvb_frontend* fe,
Andrew de Quincey36cb5572006-01-09 15:25:07 -02001422 struct dvb_frontend_parameters* p,
1423 unsigned int mode_flags,
1424 int *delay,
1425 fe_status_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Manu Abrahama427de62005-09-09 13:03:00 -07001427 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Andrew de Quincey36cb5572006-01-09 15:25:07 -02001429 if (p != NULL) {
1430 dst_set_freq(state, p->frequency);
1431 dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001432
Andrew de Quincey36cb5572006-01-09 15:25:07 -02001433 if (state->dst_type == DST_TYPE_IS_SAT) {
1434 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1435 dst_set_inversion(state, p->inversion);
1436 dst_set_fec(state, p->u.qpsk.fec_inner);
1437 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1438 dst_set_polarization(state);
1439 dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001440
Andrew de Quincey36cb5572006-01-09 15:25:07 -02001441 } else if (state->dst_type == DST_TYPE_IS_TERR)
1442 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
1443 else if (state->dst_type == DST_TYPE_IS_CABLE) {
1444 dst_set_fec(state, p->u.qam.fec_inner);
1445 dst_set_symbolrate(state, p->u.qam.symbol_rate);
1446 dst_set_modulation(state, p->u.qam.modulation);
1447 }
1448 dst_write_tuna(fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Andrew de Quincey36cb5572006-01-09 15:25:07 -02001451 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
1452 dst_read_status(fe, status);
1453
1454 *delay = HZ/10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 return 0;
1456}
1457
Manu Abraham8cfba632006-06-21 10:27:26 -03001458static int dst_get_tuning_algo(struct dvb_frontend *fe)
1459{
1460 return dst_algo;
1461}
1462
Manu Abrahama427de62005-09-09 13:03:00 -07001463static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Manu Abrahama427de62005-09-09 13:03:00 -07001465 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 p->frequency = state->decode_freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 if (state->dst_type == DST_TYPE_IS_SAT) {
Manu Abraham7d534212005-07-07 17:57:50 -07001469 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1470 p->inversion = state->inversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 p->u.qpsk.symbol_rate = state->symbol_rate;
1472 p->u.qpsk.fec_inner = dst_get_fec(state);
1473 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1474 p->u.ofdm.bandwidth = state->bandwidth;
1475 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1476 p->u.qam.symbol_rate = state->symbol_rate;
1477 p->u.qam.fec_inner = dst_get_fec(state);
Manu Abraham7d534212005-07-07 17:57:50 -07001478 p->u.qam.modulation = dst_get_modulation(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
1480
1481 return 0;
1482}
1483
Manu Abrahama427de62005-09-09 13:03:00 -07001484static void dst_release(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Manu Abrahama427de62005-09-09 13:03:00 -07001486 struct dst_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 kfree(state);
1488}
1489
1490static struct dvb_frontend_ops dst_dvbt_ops;
1491static struct dvb_frontend_ops dst_dvbs_ops;
1492static struct dvb_frontend_ops dst_dvbc_ops;
Manu Abrahambc7386b2006-06-21 10:27:05 -03001493static struct dvb_frontend_ops dst_atsc_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Manu Abrahama427de62005-09-09 13:03:00 -07001495struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001497 /* check if the ASIC is there */
1498 if (dst_probe(state) < 0) {
Jesper Juhl2ea75332005-11-07 01:01:31 -08001499 kfree(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001500 return NULL;
1501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 /* determine settings based on type */
Patrick Boettcherdea74862006-05-14 05:01:31 -03001503 /* create dvb_frontend */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 switch (state->dst_type) {
1505 case DST_TYPE_IS_TERR:
Patrick Boettcherdea74862006-05-14 05:01:31 -03001506 memcpy(&state->frontend.ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 break;
1508 case DST_TYPE_IS_CABLE:
Patrick Boettcherdea74862006-05-14 05:01:31 -03001509 memcpy(&state->frontend.ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 break;
1511 case DST_TYPE_IS_SAT:
Patrick Boettcherdea74862006-05-14 05:01:31 -03001512 memcpy(&state->frontend.ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 break;
Manu Abrahambc7386b2006-06-21 10:27:05 -03001514 case DST_TYPE_IS_ATSC:
1515 memcpy(&state->frontend.ops, &dst_atsc_ops, sizeof(struct dvb_frontend_ops));
1516 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 default:
Manu Abrahama427de62005-09-09 13:03:00 -07001518 dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
Jesper Juhl2ea75332005-11-07 01:01:31 -08001519 kfree(state);
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001520 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 state->frontend.demodulator_priv = state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001524 return state; /* Manu (DST is a card not a frontend) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001527EXPORT_SYMBOL(dst_attach);
1528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529static struct dvb_frontend_ops dst_dvbt_ops = {
1530
1531 .info = {
1532 .name = "DST DVB-T",
1533 .type = FE_OFDM,
1534 .frequency_min = 137000000,
1535 .frequency_max = 858000000,
1536 .frequency_stepsize = 166667,
1537 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
1538 },
1539
1540 .release = dst_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 .init = dst_init,
Manu Abraham8cfba632006-06-21 10:27:26 -03001542 .tune = dst_tune_frontend,
1543 .set_frontend = dst_set_frontend,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 .get_frontend = dst_get_frontend,
Manu Abrahamcdd393c2006-06-21 10:27:36 -03001545 .get_frontend_algo = dst_get_tuning_algo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 .read_status = dst_read_status,
1547 .read_signal_strength = dst_read_signal_strength,
1548 .read_snr = dst_read_snr,
1549};
1550
1551static struct dvb_frontend_ops dst_dvbs_ops = {
1552
1553 .info = {
1554 .name = "DST DVB-S",
1555 .type = FE_QPSK,
1556 .frequency_min = 950000,
1557 .frequency_max = 2150000,
1558 .frequency_stepsize = 1000, /* kHz for QPSK frontends */
1559 .frequency_tolerance = 29500,
1560 .symbol_rate_min = 1000000,
1561 .symbol_rate_max = 45000000,
1562 /* . symbol_rate_tolerance = ???,*/
1563 .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
1564 },
1565
1566 .release = dst_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 .init = dst_init,
Manu Abraham8cfba632006-06-21 10:27:26 -03001568 .tune = dst_tune_frontend,
1569 .set_frontend = dst_set_frontend,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 .get_frontend = dst_get_frontend,
Manu Abrahamcdd393c2006-06-21 10:27:36 -03001571 .get_frontend_algo = dst_get_tuning_algo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 .read_status = dst_read_status,
1573 .read_signal_strength = dst_read_signal_strength,
1574 .read_snr = dst_read_snr,
Manu Abraham203fe8b2005-05-28 15:51:48 -07001575 .diseqc_send_burst = dst_send_burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 .diseqc_send_master_cmd = dst_set_diseqc,
1577 .set_voltage = dst_set_voltage,
1578 .set_tone = dst_set_tone,
1579};
1580
1581static struct dvb_frontend_ops dst_dvbc_ops = {
1582
1583 .info = {
1584 .name = "DST DVB-C",
1585 .type = FE_QAM,
1586 .frequency_stepsize = 62500,
1587 .frequency_min = 51000000,
1588 .frequency_max = 858000000,
1589 .symbol_rate_min = 1000000,
1590 .symbol_rate_max = 45000000,
1591 /* . symbol_rate_tolerance = ???,*/
1592 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
1593 },
1594
1595 .release = dst_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 .init = dst_init,
Manu Abraham8cfba632006-06-21 10:27:26 -03001597 .tune = dst_tune_frontend,
1598 .set_frontend = dst_set_frontend,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 .get_frontend = dst_get_frontend,
Manu Abrahamcdd393c2006-06-21 10:27:36 -03001600 .get_frontend_algo = dst_get_tuning_algo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 .read_status = dst_read_status,
1602 .read_signal_strength = dst_read_signal_strength,
1603 .read_snr = dst_read_snr,
1604};
1605
Manu Abrahambc7386b2006-06-21 10:27:05 -03001606static struct dvb_frontend_ops dst_atsc_ops = {
1607 .info = {
1608 .name = "DST ATSC",
1609 .type = FE_ATSC,
1610 .frequency_stepsize = 62500,
1611 .frequency_min = 510000000,
1612 .frequency_max = 858000000,
1613 .symbol_rate_min = 1000000,
1614 .symbol_rate_max = 45000000,
1615 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
1616 },
1617
1618 .release = dst_release,
1619 .init = dst_init,
Manu Abraham8cfba632006-06-21 10:27:26 -03001620 .tune = dst_tune_frontend,
1621 .set_frontend = dst_set_frontend,
Manu Abrahambc7386b2006-06-21 10:27:05 -03001622 .get_frontend = dst_get_frontend,
Manu Abrahamcdd393c2006-06-21 10:27:36 -03001623 .get_frontend_algo = dst_get_tuning_algo,
Manu Abrahambc7386b2006-06-21 10:27:05 -03001624 .read_status = dst_read_status,
1625 .read_signal_strength = dst_read_signal_strength,
1626 .read_snr = dst_read_snr,
1627};
1628
1629MODULE_DESCRIPTION("DST DVB-S/T/C/ATSC Combo Frontend driver");
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07001630MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1631MODULE_LICENSE("GPL");