Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 3 | Frontend/Card driver for TwinHan DST Frontend |
| 4 | Copyright (C) 2003 Jamie Honan |
| 5 | Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 7 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 12 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #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 Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 34 | #include "dst_common.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 37 | static unsigned int verbose = 1; |
| 38 | module_param(verbose, int, 0644); |
| 39 | MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 41 | static unsigned int debug = 1; |
| 42 | module_param(debug, int, 0644); |
| 43 | MODULE_PARM_DESC(debug, "debug messages, default is 0 (yes)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 45 | static unsigned int dst_addons; |
| 46 | module_param(dst_addons, int, 0644); |
Johannes Stezenbach | 4a2cc12 | 2005-05-16 21:54:45 -0700 | [diff] [blame] | 47 | MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 49 | #define dprintk if (debug) printk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define HAS_LOCK 1 |
| 52 | #define ATTEMPT_TUNE 2 |
| 53 | #define HAS_POWER 4 |
| 54 | |
| 55 | static 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 Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 63 | int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 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 Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 71 | if (verbose > 4) |
| 72 | dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__, mask, enbb, outhigh); |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 75 | dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__, err, mask, enbb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return -EREMOTEIO; |
| 77 | } |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 78 | udelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* because complete disabling means no output, no need to do output packet */ |
| 80 | if (enbb == 0) |
| 81 | return 0; |
| 82 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 83 | if (delay) |
| 84 | msleep(10); |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | bits.outp.mask = enbb; |
| 87 | bits.outp.highvals = outhigh; |
| 88 | |
| 89 | if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 90 | dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__, err, enbb, outhigh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | return -EREMOTEIO; |
| 92 | } |
| 93 | return 0; |
| 94 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 95 | EXPORT_SYMBOL(dst_gpio_outb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 97 | int dst_gpio_inb(struct dst_state *state, u8 * result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 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 Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 112 | EXPORT_SYMBOL(dst_gpio_inb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 114 | int rdc_reset_state(struct dst_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 116 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | msleep(10); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 125 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return 0; |
| 133 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 134 | EXPORT_SYMBOL(rdc_reset_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 136 | int rdc_8820_reset(struct dst_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 138 | 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 Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 145 | udelay(1000); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 146 | if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) { |
| 147 | dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); |
| 148 | return -1; |
| 149 | } |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 153 | EXPORT_SYMBOL(rdc_8820_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 155 | int dst_pio_enable(struct dst_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 157 | 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 Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 161 | udelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return 0; |
| 163 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 164 | EXPORT_SYMBOL(dst_pio_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 166 | int 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 Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 172 | if (state->type_flags & DST_TYPE_HAS_FW_1) |
| 173 | udelay(1000); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | EXPORT_SYMBOL(dst_pio_disable); |
| 178 | |
| 179 | int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | u8 reply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | int i; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | for (i = 0; i < 200; i++) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 185 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return 1; |
| 194 | } |
Johannes Stezenbach | b46dd44 | 2005-05-16 21:54:44 -0700 | [diff] [blame] | 195 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 197 | if (verbose > 1) |
| 198 | dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i); |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return 0; |
| 201 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 202 | EXPORT_SYMBOL(dst_wait_dst_ready); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 204 | int 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 | } |
| 214 | EXPORT_SYMBOL(dst_error_recovery); |
| 215 | |
| 216 | int 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 | } |
| 225 | EXPORT_SYMBOL(dst_error_bailout); |
| 226 | |
| 227 | |
| 228 | int 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 Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 240 | if (state->type_flags & DST_TYPE_HAS_FW_1) |
| 241 | msleep(100); |
| 242 | else |
| 243 | msleep(5); |
| 244 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 245 | return 0; |
| 246 | } |
| 247 | EXPORT_SYMBOL(dst_comm_init); |
| 248 | |
| 249 | |
| 250 | int write_dst(struct dst_state *state, u8 *data, u8 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
| 252 | struct i2c_msg msg = { |
| 253 | .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len |
| 254 | }; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | int err; |
| 257 | int cnt; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 258 | if (debug && (verbose > 4)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | u8 i; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 260 | if (verbose > 4) { |
| 261 | dprintk("%s writing", __FUNCTION__); |
| 262 | for (i = 0; i < len; i++) |
| 263 | dprintk(" %02x", data[i]); |
| 264 | dprintk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 267 | for (cnt = 0; cnt < 2; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 269 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | continue; |
| 272 | } else |
| 273 | break; |
| 274 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 275 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | return 0; |
| 285 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 286 | EXPORT_SYMBOL(write_dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 288 | int read_dst(struct dst_state *state, u8 * ret, u8 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
| 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 Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 294 | for (cnt = 0; cnt < 2; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 298 | dst_error_recovery(state); |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | continue; |
| 301 | } else |
| 302 | break; |
| 303 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 304 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | for (err = 1; err < len; err++) |
| 314 | dprintk(" 0x%x", ret[err]); |
| 315 | if (err > 1) |
| 316 | dprintk("\n"); |
| 317 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | return 0; |
| 320 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 321 | EXPORT_SYMBOL(read_dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | static int dst_set_freq(struct dst_state *state, u32 freq) |
| 324 | { |
| 325 | u8 *val; |
| 326 | |
| 327 | state->frequency = freq; |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 328 | if (debug > 4) |
| 329 | dprintk("%s: set Frequency %u\n", __FUNCTION__, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (state->dst_type == DST_TYPE_IS_SAT) { |
| 332 | freq = freq / 1000; |
| 333 | if (freq < 950 || freq > 2150) |
| 334 | return -EINVAL; |
| 335 | val = &state->tx_tuna[0]; |
| 336 | val[2] = (freq >> 8) & 0x7f; |
| 337 | val[3] = (u8) freq; |
| 338 | val[4] = 1; |
| 339 | val[8] &= ~4; |
| 340 | if (freq < 1531) |
| 341 | val[8] |= 4; |
| 342 | } else if (state->dst_type == DST_TYPE_IS_TERR) { |
| 343 | freq = freq / 1000; |
| 344 | if (freq < 137000 || freq > 858000) |
| 345 | return -EINVAL; |
| 346 | val = &state->tx_tuna[0]; |
| 347 | val[2] = (freq >> 16) & 0xff; |
| 348 | val[3] = (freq >> 8) & 0xff; |
| 349 | val[4] = (u8) freq; |
| 350 | val[5] = 0; |
| 351 | switch (state->bandwidth) { |
| 352 | case BANDWIDTH_6_MHZ: |
| 353 | val[6] = 6; |
| 354 | break; |
| 355 | |
| 356 | case BANDWIDTH_7_MHZ: |
| 357 | case BANDWIDTH_AUTO: |
| 358 | val[6] = 7; |
| 359 | break; |
| 360 | |
| 361 | case BANDWIDTH_8_MHZ: |
| 362 | val[6] = 8; |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | val[7] = 0; |
| 367 | val[8] = 0; |
| 368 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { |
| 369 | /* guess till will get one */ |
| 370 | freq = freq / 1000; |
| 371 | val = &state->tx_tuna[0]; |
| 372 | val[2] = (freq >> 16) & 0xff; |
| 373 | val[3] = (freq >> 8) & 0xff; |
| 374 | val[4] = (u8) freq; |
| 375 | } else |
| 376 | return -EINVAL; |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) |
| 381 | { |
| 382 | u8 *val; |
| 383 | |
| 384 | state->bandwidth = bandwidth; |
| 385 | |
| 386 | if (state->dst_type != DST_TYPE_IS_TERR) |
| 387 | return 0; |
| 388 | |
| 389 | val = &state->tx_tuna[0]; |
| 390 | switch (bandwidth) { |
| 391 | case BANDWIDTH_6_MHZ: |
| 392 | val[6] = 6; |
| 393 | break; |
| 394 | |
| 395 | case BANDWIDTH_7_MHZ: |
| 396 | val[6] = 7; |
| 397 | break; |
| 398 | |
| 399 | case BANDWIDTH_8_MHZ: |
| 400 | val[6] = 8; |
| 401 | break; |
| 402 | |
| 403 | default: |
| 404 | return -EINVAL; |
| 405 | } |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion) |
| 410 | { |
| 411 | u8 *val; |
| 412 | |
| 413 | state->inversion = inversion; |
| 414 | |
| 415 | val = &state->tx_tuna[0]; |
| 416 | |
| 417 | val[8] &= ~0x80; |
| 418 | |
| 419 | switch (inversion) { |
| 420 | case INVERSION_OFF: |
| 421 | break; |
| 422 | case INVERSION_ON: |
| 423 | val[8] |= 0x80; |
| 424 | break; |
| 425 | default: |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static int dst_set_fec(struct dst_state* state, fe_code_rate_t fec) |
| 432 | { |
| 433 | state->fec = fec; |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static fe_code_rate_t dst_get_fec(struct dst_state* state) |
| 438 | { |
| 439 | return state->fec; |
| 440 | } |
| 441 | |
| 442 | static int dst_set_symbolrate(struct dst_state* state, u32 srate) |
| 443 | { |
| 444 | u8 *val; |
| 445 | u32 symcalc; |
| 446 | u64 sval; |
| 447 | |
| 448 | state->symbol_rate = srate; |
| 449 | |
| 450 | if (state->dst_type == DST_TYPE_IS_TERR) { |
| 451 | return 0; |
| 452 | } |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 453 | if (debug > 4) |
| 454 | dprintk("%s: set symrate %u\n", __FUNCTION__, srate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | srate /= 1000; |
| 456 | val = &state->tx_tuna[0]; |
| 457 | |
| 458 | if (state->type_flags & DST_TYPE_HAS_SYMDIV) { |
| 459 | sval = srate; |
| 460 | sval <<= 20; |
| 461 | do_div(sval, 88000); |
| 462 | symcalc = (u32) sval; |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 463 | |
| 464 | if (debug > 4) |
| 465 | dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc); |
| 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | val[5] = (u8) (symcalc >> 12); |
| 468 | val[6] = (u8) (symcalc >> 4); |
| 469 | val[7] = (u8) (symcalc << 4); |
| 470 | } else { |
| 471 | val[5] = (u8) (srate >> 16) & 0x7f; |
| 472 | val[6] = (u8) (srate >> 8); |
| 473 | val[7] = (u8) srate; |
| 474 | } |
| 475 | val[8] &= ~0x20; |
| 476 | if (srate > 8000) |
| 477 | val[8] |= 0x20; |
| 478 | return 0; |
| 479 | } |
| 480 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 481 | u8 dst_check_sum(u8 * buf, u32 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
| 483 | u32 i; |
| 484 | u8 val = 0; |
| 485 | if (!len) |
| 486 | return 0; |
| 487 | for (i = 0; i < len; i++) { |
| 488 | val += buf[i]; |
| 489 | } |
| 490 | return ((~val) + 1); |
| 491 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 492 | EXPORT_SYMBOL(dst_check_sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | static void dst_type_flags_print(u32 type_flags) |
| 495 | { |
| 496 | printk("DST type flags :"); |
| 497 | if (type_flags & DST_TYPE_HAS_NEWTUNE) |
| 498 | printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE); |
| 499 | if (type_flags & DST_TYPE_HAS_TS204) |
| 500 | printk(" 0x%x ts204", DST_TYPE_HAS_TS204); |
| 501 | if (type_flags & DST_TYPE_HAS_SYMDIV) |
| 502 | printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 503 | if (type_flags & DST_TYPE_HAS_FW_1) |
| 504 | printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1); |
| 505 | if (type_flags & DST_TYPE_HAS_FW_2) |
| 506 | printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2); |
| 507 | if (type_flags & DST_TYPE_HAS_FW_3) |
| 508 | printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3); |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 509 | // if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | printk("\n"); |
| 512 | } |
| 513 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 514 | |
| 515 | static int dst_type_print (u8 type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
| 517 | char *otype; |
| 518 | switch (type) { |
| 519 | case DST_TYPE_IS_SAT: |
| 520 | otype = "satellite"; |
| 521 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | case DST_TYPE_IS_TERR: |
| 524 | otype = "terrestrial"; |
| 525 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | case DST_TYPE_IS_CABLE: |
| 528 | otype = "cable"; |
| 529 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | default: |
| 532 | printk("%s: invalid dst type %d\n", __FUNCTION__, type); |
| 533 | return -EINVAL; |
| 534 | } |
| 535 | printk("DST type : %s\n", otype); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return 0; |
| 538 | } |
| 539 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 540 | /* |
| 541 | Known cards list |
| 542 | Satellite |
| 543 | ------------------- |
Johannes Stezenbach | e6ac699 | 2005-05-16 21:54:42 -0700 | [diff] [blame] | 544 | 200103A |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 545 | VP-1020 DST-MOT LG(old), TS=188 |
| 546 | |
| 547 | VP-1020 DST-03T LG(new), TS=204 |
| 548 | VP-1022 DST-03T LG(new), TS=204 |
| 549 | VP-1025 DST-03T LG(new), TS=204 |
| 550 | |
| 551 | VP-1030 DSTMCI, LG(new), TS=188 |
| 552 | VP-1032 DSTMCI, LG(new), TS=188 |
| 553 | |
| 554 | Cable |
| 555 | ------------------- |
| 556 | VP-2030 DCT-CI, Samsung, TS=204 |
| 557 | VP-2021 DCT-CI, Unknown, TS=204 |
| 558 | VP-2031 DCT-CI, Philips, TS=188 |
| 559 | VP-2040 DCT-CI, Philips, TS=188, with CA daughter board |
| 560 | VP-2040 DCT-CI, Philips, TS=204, without CA daughter board |
| 561 | |
| 562 | Terrestrial |
| 563 | ------------------- |
| 564 | VP-3050 DTTNXT TS=188 |
| 565 | VP-3040 DTT-CI, Philips, TS=188 |
| 566 | VP-3040 DTT-CI, Philips, TS=204 |
| 567 | |
| 568 | ATSC |
| 569 | ------------------- |
| 570 | VP-3220 ATSCDI, TS=188 |
| 571 | VP-3250 ATSCAD, TS=188 |
| 572 | |
| 573 | */ |
| 574 | |
| 575 | struct dst_types dst_tlist[] = { |
| 576 | { |
Johannes Stezenbach | e6ac699 | 2005-05-16 21:54:42 -0700 | [diff] [blame] | 577 | .device_id = "200103A", |
| 578 | .offset = 0, |
| 579 | .dst_type = DST_TYPE_IS_SAT, |
| 580 | .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1, |
| 581 | .dst_feature = 0 |
| 582 | }, /* obsolete */ |
| 583 | |
| 584 | { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 585 | .device_id = "DST-020", |
| 586 | .offset = 0, |
| 587 | .dst_type = DST_TYPE_IS_SAT, |
| 588 | .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1, |
| 589 | .dst_feature = 0 |
| 590 | }, /* obsolete */ |
| 591 | |
| 592 | { |
| 593 | .device_id = "DST-030", |
| 594 | .offset = 0, |
| 595 | .dst_type = DST_TYPE_IS_SAT, |
| 596 | .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1, |
| 597 | .dst_feature = 0 |
| 598 | }, /* obsolete */ |
| 599 | |
| 600 | { |
| 601 | .device_id = "DST-03T", |
| 602 | .offset = 0, |
| 603 | .dst_type = DST_TYPE_IS_SAT, |
| 604 | .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2, |
| 605 | .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5 |
| 606 | | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO |
| 607 | }, |
| 608 | |
| 609 | { |
| 610 | .device_id = "DST-MOT", |
| 611 | .offset = 0, |
| 612 | .dst_type = DST_TYPE_IS_SAT, |
| 613 | .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1, |
| 614 | .dst_feature = 0 |
| 615 | }, /* obsolete */ |
| 616 | |
| 617 | { |
| 618 | .device_id = "DST-CI", |
| 619 | .offset = 1, |
| 620 | .dst_type = DST_TYPE_IS_SAT, |
| 621 | .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1, |
| 622 | .dst_feature = DST_TYPE_HAS_CA |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 623 | }, /* An OEM board */ |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 624 | |
| 625 | { |
| 626 | .device_id = "DSTMCI", |
| 627 | .offset = 1, |
| 628 | .dst_type = DST_TYPE_IS_SAT, |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 629 | .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 630 | .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 |
| 631 | | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC |
| 632 | }, |
| 633 | |
| 634 | { |
| 635 | .device_id = "DSTFCI", |
| 636 | .offset = 1, |
| 637 | .dst_type = DST_TYPE_IS_SAT, |
| 638 | .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1, |
| 639 | .dst_feature = 0 |
| 640 | }, /* unknown to vendor */ |
| 641 | |
| 642 | { |
| 643 | .device_id = "DCT-CI", |
| 644 | .offset = 1, |
| 645 | .dst_type = DST_TYPE_IS_CABLE, |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 646 | .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1 |
| 647 | | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 648 | .dst_feature = DST_TYPE_HAS_CA |
| 649 | }, |
| 650 | |
| 651 | { |
| 652 | .device_id = "DCTNEW", |
| 653 | .offset = 1, |
| 654 | .dst_type = DST_TYPE_IS_CABLE, |
| 655 | .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3, |
| 656 | .dst_feature = 0 |
| 657 | }, |
| 658 | |
| 659 | { |
| 660 | .device_id = "DTT-CI", |
| 661 | .offset = 1, |
| 662 | .dst_type = DST_TYPE_IS_TERR, |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 663 | .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 664 | .dst_feature = 0 |
| 665 | }, |
| 666 | |
| 667 | { |
| 668 | .device_id = "DTTDIG", |
| 669 | .offset = 1, |
| 670 | .dst_type = DST_TYPE_IS_TERR, |
| 671 | .type_flags = DST_TYPE_HAS_FW_2, |
| 672 | .dst_feature = 0 |
| 673 | }, |
| 674 | |
| 675 | { |
| 676 | .device_id = "DTTNXT", |
| 677 | .offset = 1, |
| 678 | .dst_type = DST_TYPE_IS_TERR, |
| 679 | .type_flags = DST_TYPE_HAS_FW_2, |
| 680 | .dst_feature = DST_TYPE_HAS_ANALOG |
| 681 | }, |
| 682 | |
| 683 | { |
| 684 | .device_id = "ATSCDI", |
| 685 | .offset = 1, |
| 686 | .dst_type = DST_TYPE_IS_ATSC, |
| 687 | .type_flags = DST_TYPE_HAS_FW_2, |
| 688 | .dst_feature = 0 |
| 689 | }, |
| 690 | |
| 691 | { |
| 692 | .device_id = "ATSCAD", |
| 693 | .offset = 1, |
| 694 | .dst_type = DST_TYPE_IS_ATSC, |
| 695 | .type_flags = DST_TYPE_HAS_FW_2, |
| 696 | .dst_feature = 0 |
| 697 | }, |
| 698 | |
| 699 | { } |
| 700 | |
| 701 | }; |
| 702 | |
| 703 | |
| 704 | static int dst_get_device_id(struct dst_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 706 | u8 reply; |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | int i; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 709 | struct dst_types *p_dst_type; |
| 710 | u8 use_dst_type = 0; |
| 711 | u32 use_type_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 713 | static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 715 | device_type[7] = dst_check_sum(device_type, 7); |
| 716 | |
| 717 | if (write_dst(state, device_type, FIXED_COMM)) |
| 718 | return -1; /* Write failed */ |
| 719 | |
| 720 | if ((dst_pio_disable(state)) < 0) |
| 721 | return -1; |
| 722 | |
| 723 | if (read_dst(state, &reply, GET_ACK)) |
| 724 | return -1; /* Read failure */ |
| 725 | |
| 726 | if (reply != ACK) { |
| 727 | dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__, reply); |
| 728 | return -1; /* Unack'd write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 730 | |
| 731 | if (!dst_wait_dst_ready(state, DEVICE_INIT)) |
| 732 | return -1; /* DST not ready yet */ |
| 733 | |
| 734 | if (read_dst(state, state->rxbuffer, FIXED_COMM)) |
| 735 | return -1; |
| 736 | |
| 737 | dst_pio_disable(state); |
| 738 | |
| 739 | if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { |
| 740 | dprintk("%s: Checksum failure! \n", __FUNCTION__); |
| 741 | return -1; /* Checksum failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 743 | |
| 744 | state->rxbuffer[7] = '\0'; |
| 745 | |
| 746 | for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE (dst_tlist); i++, p_dst_type++) { |
| 747 | if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) { |
| 748 | use_type_flags = p_dst_type->type_flags; |
| 749 | use_dst_type = p_dst_type->dst_type; |
| 750 | |
| 751 | /* Card capabilities */ |
| 752 | state->dst_hw_cap = p_dst_type->dst_feature; |
| 753 | printk ("%s: Recognise [%s]\n", __FUNCTION__, p_dst_type->device_id); |
| 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | break; |
| 756 | } |
| 757 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 758 | |
| 759 | if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) { |
| 760 | printk("%s: Unable to recognize %s or %s\n", __FUNCTION__, &state->rxbuffer[0], &state->rxbuffer[1]); |
| 761 | printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | use_dst_type = DST_TYPE_IS_SAT; |
| 763 | use_type_flags = DST_TYPE_HAS_SYMDIV; |
| 764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 766 | dst_type_print(use_dst_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | state->type_flags = use_type_flags; |
| 768 | state->dst_type = use_dst_type; |
| 769 | dst_type_flags_print(state->type_flags); |
| 770 | |
| 771 | if (state->type_flags & DST_TYPE_HAS_TS204) { |
| 772 | dst_packsize(state, 204); |
| 773 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | return 0; |
| 776 | } |
| 777 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 778 | static int dst_probe(struct dst_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 780 | if ((rdc_8820_reset(state)) < 0) { |
| 781 | dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__); |
| 782 | return -1; |
| 783 | } |
Johannes Stezenbach | 4a2cc12 | 2005-05-16 21:54:45 -0700 | [diff] [blame] | 784 | if (dst_addons & DST_TYPE_HAS_CA) |
| 785 | msleep(4000); |
| 786 | else |
| 787 | msleep(100); |
| 788 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 789 | if ((dst_comm_init(state)) < 0) { |
| 790 | dprintk("%s: DST Initialization Failed.\n", __FUNCTION__); |
| 791 | return -1; |
| 792 | } |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 793 | msleep(100); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 794 | if (dst_get_device_id(state) < 0) { |
| 795 | dprintk("%s: unknown device.\n", __FUNCTION__); |
| 796 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | int dst_command(struct dst_state* state, u8 * data, u8 len) |
| 803 | { |
| 804 | u8 reply; |
| 805 | if ((dst_comm_init(state)) < 0) { |
| 806 | dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__); |
| 807 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 809 | |
| 810 | if (write_dst(state, data, len)) { |
| 811 | if (verbose > 1) |
| 812 | dprintk("%s: Tring to recover.. \n", __FUNCTION__); |
| 813 | if ((dst_error_recovery(state)) < 0) { |
| 814 | dprintk("%s: Recovery Failed.\n", __FUNCTION__); |
| 815 | return -1; |
| 816 | } |
| 817 | return -1; |
| 818 | } |
| 819 | if ((dst_pio_disable(state)) < 0) { |
| 820 | dprintk("%s: PIO Disable Failed.\n", __FUNCTION__); |
| 821 | return -1; |
| 822 | } |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 823 | if (state->type_flags & DST_TYPE_HAS_FW_1) |
| 824 | udelay(3000); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 825 | |
| 826 | if (read_dst(state, &reply, GET_ACK)) { |
| 827 | if (verbose > 1) |
| 828 | dprintk("%s: Trying to recover.. \n", __FUNCTION__); |
| 829 | if ((dst_error_recovery(state)) < 0) { |
| 830 | dprintk("%s: Recovery Failed.\n", __FUNCTION__); |
| 831 | return -1; |
| 832 | } |
| 833 | return -1; |
| 834 | } |
| 835 | |
| 836 | if (reply != ACK) { |
| 837 | dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply); |
| 838 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3)) |
| 841 | return 0; |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 842 | |
| 843 | // udelay(3000); |
| 844 | if (state->type_flags & DST_TYPE_HAS_FW_1) |
| 845 | udelay(3000); |
| 846 | else |
| 847 | udelay(2000); |
| 848 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 849 | if (!dst_wait_dst_ready(state, NO_DELAY)) |
| 850 | return -1; |
| 851 | |
| 852 | if (read_dst(state, state->rxbuffer, FIXED_COMM)) { |
| 853 | if (verbose > 1) |
| 854 | dprintk("%s: Trying to recover.. \n", __FUNCTION__); |
| 855 | if ((dst_error_recovery(state)) < 0) { |
| 856 | dprintk("%s: Recovery failed.\n", __FUNCTION__); |
| 857 | return -1; |
| 858 | } |
| 859 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { |
| 863 | dprintk("%s: checksum failure\n", __FUNCTION__); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 864 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | return 0; |
| 868 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 869 | EXPORT_SYMBOL(dst_command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | static int dst_get_signal(struct dst_state* state) |
| 872 | { |
| 873 | int retval; |
| 874 | u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; |
| 875 | |
| 876 | if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { |
| 877 | state->decode_lock = state->decode_strength = state->decode_snr = 0; |
| 878 | return 0; |
| 879 | } |
| 880 | if (0 == (state->diseq_flags & HAS_LOCK)) { |
| 881 | state->decode_lock = state->decode_strength = state->decode_snr = 0; |
| 882 | return 0; |
| 883 | } |
| 884 | if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) { |
| 885 | retval = dst_command(state, get_signal, 8); |
| 886 | if (retval < 0) |
| 887 | return retval; |
| 888 | if (state->dst_type == DST_TYPE_IS_SAT) { |
| 889 | state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0; |
| 890 | state->decode_strength = state->rxbuffer[5] << 8; |
| 891 | state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3]; |
| 892 | } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) { |
| 893 | state->decode_lock = (state->rxbuffer[1]) ? 1 : 0; |
| 894 | state->decode_strength = state->rxbuffer[4] << 8; |
| 895 | state->decode_snr = state->rxbuffer[3] << 8; |
| 896 | } |
| 897 | state->cur_jiff = jiffies; |
| 898 | } |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static int dst_tone_power_cmd(struct dst_state* state) |
| 903 | { |
| 904 | u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 }; |
| 905 | |
| 906 | if (state->dst_type == DST_TYPE_IS_TERR) |
| 907 | return 0; |
| 908 | |
| 909 | if (state->voltage == SEC_VOLTAGE_OFF) |
| 910 | paket[4] = 0; |
| 911 | else |
| 912 | paket[4] = 1; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | if (state->tone == SEC_TONE_ON) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 915 | paket[2] = 0x02; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | else |
| 917 | paket[2] = 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 918 | if (state->minicmd == SEC_MINI_A) |
| 919 | paket[3] = 0x02; |
| 920 | else |
| 921 | paket[3] = 0; |
| 922 | |
| 923 | paket[7] = dst_check_sum (paket, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | dst_command(state, paket, 8); |
| 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | static int dst_get_tuna(struct dst_state* state) |
| 929 | { |
| 930 | int retval; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | if ((state->diseq_flags & ATTEMPT_TUNE) == 0) |
| 933 | return 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | state->diseq_flags &= ~(HAS_LOCK); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 936 | if (!dst_wait_dst_ready(state, NO_DELAY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | return 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { |
| 940 | /* how to get variable length reply ???? */ |
| 941 | retval = read_dst(state, state->rx_tuna, 10); |
| 942 | } else { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 943 | retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | if (retval < 0) { |
| 947 | dprintk("%s: read not successful\n", __FUNCTION__); |
| 948 | return 0; |
| 949 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { |
| 952 | if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) { |
| 953 | dprintk("%s: checksum failure?\n", __FUNCTION__); |
| 954 | return 0; |
| 955 | } |
| 956 | } else { |
| 957 | if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) { |
| 958 | dprintk("%s: checksum failure?\n", __FUNCTION__); |
| 959 | return 0; |
| 960 | } |
| 961 | } |
| 962 | if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0) |
| 963 | return 0; |
| 964 | state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3]; |
| 965 | |
| 966 | state->decode_lock = 1; |
| 967 | /* |
| 968 | dst->decode_n1 = (dst->rx_tuna[4] << 8) + |
| 969 | (dst->rx_tuna[5]); |
| 970 | |
| 971 | dst->decode_n2 = (dst->rx_tuna[8] << 8) + |
| 972 | (dst->rx_tuna[7]); |
| 973 | */ |
| 974 | state->diseq_flags |= HAS_LOCK; |
| 975 | /* dst->cur_jiff = jiffies; */ |
| 976 | return 1; |
| 977 | } |
| 978 | |
| 979 | static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage); |
| 980 | |
| 981 | static int dst_write_tuna(struct dvb_frontend* fe) |
| 982 | { |
| 983 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 984 | int retval; |
| 985 | u8 reply; |
| 986 | |
Johannes Stezenbach | 8385e46 | 2005-05-16 21:54:43 -0700 | [diff] [blame] | 987 | if (debug > 4) |
| 988 | dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags); |
| 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | state->decode_freq = 0; |
| 991 | state->decode_lock = state->decode_strength = state->decode_snr = 0; |
| 992 | if (state->dst_type == DST_TYPE_IS_SAT) { |
| 993 | if (!(state->diseq_flags & HAS_POWER)) |
| 994 | dst_set_voltage(fe, SEC_VOLTAGE_13); |
| 995 | } |
| 996 | state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 997 | |
| 998 | if ((dst_comm_init(state)) < 0) { |
| 999 | dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__); |
| 1000 | return -1; |
| 1001 | } |
| 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9); |
| 1005 | retval = write_dst(state, &state->tx_tuna[0], 10); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | } else { |
| 1008 | state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1009 | retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | } |
| 1011 | if (retval < 0) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1012 | dst_pio_disable(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | dprintk("%s: write not successful\n", __FUNCTION__); |
| 1014 | return retval; |
| 1015 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1016 | |
| 1017 | if ((dst_pio_disable(state)) < 0) { |
| 1018 | dprintk("%s: DST PIO disable failed !\n", __FUNCTION__); |
| 1019 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1021 | |
| 1022 | if ((read_dst(state, &reply, GET_ACK) < 0)) { |
| 1023 | dprintk("%s: read verify not successful.\n", __FUNCTION__); |
| 1024 | return -1; |
| 1025 | } |
| 1026 | if (reply != ACK) { |
| 1027 | dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | return 0; |
| 1029 | } |
| 1030 | state->diseq_flags |= ATTEMPT_TUNE; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | return dst_get_tuna(state); |
| 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00 |
| 1037 | * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00 |
| 1038 | * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00 |
| 1039 | * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00 |
| 1040 | * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00 |
| 1041 | * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 |
| 1042 | * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 |
| 1043 | * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec |
| 1044 | * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8 |
| 1045 | * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4 |
| 1046 | * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0 |
| 1047 | */ |
| 1048 | |
| 1049 | static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) |
| 1050 | { |
| 1051 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1052 | u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; |
| 1053 | |
| 1054 | if (state->dst_type == DST_TYPE_IS_TERR) |
| 1055 | return 0; |
| 1056 | |
| 1057 | if (cmd->msg_len == 0 || cmd->msg_len > 4) |
| 1058 | return -EINVAL; |
| 1059 | memcpy(&paket[3], cmd->msg, cmd->msg_len); |
| 1060 | paket[7] = dst_check_sum(&paket[0], 7); |
| 1061 | dst_command(state, paket, 8); |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) |
| 1066 | { |
| 1067 | u8 *val; |
| 1068 | int need_cmd; |
| 1069 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1070 | |
| 1071 | state->voltage = voltage; |
| 1072 | |
| 1073 | if (state->dst_type == DST_TYPE_IS_TERR) |
| 1074 | return 0; |
| 1075 | |
| 1076 | need_cmd = 0; |
| 1077 | val = &state->tx_tuna[0]; |
| 1078 | val[8] &= ~0x40; |
| 1079 | switch (voltage) { |
| 1080 | case SEC_VOLTAGE_13: |
| 1081 | if ((state->diseq_flags & HAS_POWER) == 0) |
| 1082 | need_cmd = 1; |
| 1083 | state->diseq_flags |= HAS_POWER; |
| 1084 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | case SEC_VOLTAGE_18: |
| 1087 | if ((state->diseq_flags & HAS_POWER) == 0) |
| 1088 | need_cmd = 1; |
| 1089 | state->diseq_flags |= HAS_POWER; |
| 1090 | val[8] |= 0x40; |
| 1091 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | case SEC_VOLTAGE_OFF: |
| 1094 | need_cmd = 1; |
| 1095 | state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE); |
| 1096 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | default: |
| 1099 | return -EINVAL; |
| 1100 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1101 | if (need_cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | dst_tone_power_cmd(state); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) |
| 1108 | { |
| 1109 | u8 *val; |
| 1110 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1111 | |
| 1112 | state->tone = tone; |
| 1113 | |
| 1114 | if (state->dst_type == DST_TYPE_IS_TERR) |
| 1115 | return 0; |
| 1116 | |
| 1117 | val = &state->tx_tuna[0]; |
| 1118 | |
| 1119 | val[8] &= ~0x1; |
| 1120 | |
| 1121 | switch (tone) { |
| 1122 | case SEC_TONE_OFF: |
| 1123 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | case SEC_TONE_ON: |
| 1126 | val[8] |= 1; |
| 1127 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | default: |
| 1130 | return -EINVAL; |
| 1131 | } |
| 1132 | dst_tone_power_cmd(state); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | static int dst_init(struct dvb_frontend* fe) |
| 1138 | { |
| 1139 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1140 | static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; |
| 1141 | static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; |
| 1142 | static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; |
| 1143 | static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; |
| 1144 | static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; |
| 1145 | static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; |
| 1146 | state->inversion = INVERSION_ON; |
| 1147 | state->voltage = SEC_VOLTAGE_13; |
| 1148 | state->tone = SEC_TONE_OFF; |
| 1149 | state->symbol_rate = 29473000; |
| 1150 | state->fec = FEC_AUTO; |
| 1151 | state->diseq_flags = 0; |
| 1152 | state->k22 = 0x02; |
| 1153 | state->bandwidth = BANDWIDTH_7_MHZ; |
| 1154 | state->cur_jiff = jiffies; |
| 1155 | if (state->dst_type == DST_TYPE_IS_SAT) { |
| 1156 | state->frequency = 950000; |
| 1157 | memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_satci_tuna : ini_satfta_tuna), sizeof(ini_satfta_tuna)); |
| 1158 | } else if (state->dst_type == DST_TYPE_IS_TERR) { |
| 1159 | state->frequency = 137000000; |
| 1160 | memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_tvci_tuna : ini_tvfta_tuna), sizeof(ini_tvfta_tuna)); |
| 1161 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { |
| 1162 | state->frequency = 51000000; |
| 1163 | memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_cabci_tuna : ini_cabfta_tuna), sizeof(ini_cabfta_tuna)); |
| 1164 | } |
| 1165 | |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status) |
| 1170 | { |
| 1171 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1172 | |
| 1173 | *status = 0; |
| 1174 | if (state->diseq_flags & HAS_LOCK) { |
| 1175 | dst_get_signal(state); |
| 1176 | if (state->decode_lock) |
| 1177 | *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI; |
| 1178 | } |
| 1179 | |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength) |
| 1184 | { |
| 1185 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1186 | |
| 1187 | dst_get_signal(state); |
| 1188 | *strength = state->decode_strength; |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static int dst_read_snr(struct dvb_frontend* fe, u16* snr) |
| 1194 | { |
| 1195 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1196 | |
| 1197 | dst_get_signal(state); |
| 1198 | *snr = state->decode_snr; |
| 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) |
| 1204 | { |
| 1205 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1206 | |
| 1207 | dst_set_freq(state, p->frequency); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1208 | if (verbose > 4) |
| 1209 | dprintk("Set Frequency = [%d]\n", p->frequency); |
| 1210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | dst_set_inversion(state, p->inversion); |
| 1212 | if (state->dst_type == DST_TYPE_IS_SAT) { |
| 1213 | dst_set_fec(state, p->u.qpsk.fec_inner); |
| 1214 | dst_set_symbolrate(state, p->u.qpsk.symbol_rate); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1215 | if (verbose > 4) |
| 1216 | dprintk("Set Symbolrate = [%d]\n", p->u.qpsk.symbol_rate); |
| 1217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } else if (state->dst_type == DST_TYPE_IS_TERR) { |
| 1219 | dst_set_bandwidth(state, p->u.ofdm.bandwidth); |
| 1220 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { |
| 1221 | dst_set_fec(state, p->u.qam.fec_inner); |
| 1222 | dst_set_symbolrate(state, p->u.qam.symbol_rate); |
| 1223 | } |
| 1224 | dst_write_tuna(fe); |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) |
| 1230 | { |
| 1231 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1232 | |
| 1233 | p->frequency = state->decode_freq; |
| 1234 | p->inversion = state->inversion; |
| 1235 | if (state->dst_type == DST_TYPE_IS_SAT) { |
| 1236 | p->u.qpsk.symbol_rate = state->symbol_rate; |
| 1237 | p->u.qpsk.fec_inner = dst_get_fec(state); |
| 1238 | } else if (state->dst_type == DST_TYPE_IS_TERR) { |
| 1239 | p->u.ofdm.bandwidth = state->bandwidth; |
| 1240 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { |
| 1241 | p->u.qam.symbol_rate = state->symbol_rate; |
| 1242 | p->u.qam.fec_inner = dst_get_fec(state); |
| 1243 | p->u.qam.modulation = QAM_AUTO; |
| 1244 | } |
| 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static void dst_release(struct dvb_frontend* fe) |
| 1250 | { |
| 1251 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; |
| 1252 | kfree(state); |
| 1253 | } |
| 1254 | |
| 1255 | static struct dvb_frontend_ops dst_dvbt_ops; |
| 1256 | static struct dvb_frontend_ops dst_dvbs_ops; |
| 1257 | static struct dvb_frontend_ops dst_dvbc_ops; |
| 1258 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1259 | struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1262 | /* check if the ASIC is there */ |
| 1263 | if (dst_probe(state) < 0) { |
| 1264 | if (state) |
| 1265 | kfree(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1267 | return NULL; |
| 1268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | /* determine settings based on type */ |
| 1270 | switch (state->dst_type) { |
| 1271 | case DST_TYPE_IS_TERR: |
| 1272 | memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops)); |
| 1273 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | case DST_TYPE_IS_CABLE: |
| 1276 | memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops)); |
| 1277 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | case DST_TYPE_IS_SAT: |
| 1280 | memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops)); |
| 1281 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | default: |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1284 | printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__); |
| 1285 | if (state) |
| 1286 | kfree(state); |
| 1287 | |
| 1288 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /* create dvb_frontend */ |
| 1292 | state->frontend.ops = &state->ops; |
| 1293 | state->frontend.demodulator_priv = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1295 | return state; /* Manu (DST is a card not a frontend) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1298 | EXPORT_SYMBOL(dst_attach); |
| 1299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | static struct dvb_frontend_ops dst_dvbt_ops = { |
| 1301 | |
| 1302 | .info = { |
| 1303 | .name = "DST DVB-T", |
| 1304 | .type = FE_OFDM, |
| 1305 | .frequency_min = 137000000, |
| 1306 | .frequency_max = 858000000, |
| 1307 | .frequency_stepsize = 166667, |
| 1308 | .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
| 1309 | }, |
| 1310 | |
| 1311 | .release = dst_release, |
| 1312 | |
| 1313 | .init = dst_init, |
| 1314 | |
| 1315 | .set_frontend = dst_set_frontend, |
| 1316 | .get_frontend = dst_get_frontend, |
| 1317 | |
| 1318 | .read_status = dst_read_status, |
| 1319 | .read_signal_strength = dst_read_signal_strength, |
| 1320 | .read_snr = dst_read_snr, |
| 1321 | }; |
| 1322 | |
| 1323 | static struct dvb_frontend_ops dst_dvbs_ops = { |
| 1324 | |
| 1325 | .info = { |
| 1326 | .name = "DST DVB-S", |
| 1327 | .type = FE_QPSK, |
| 1328 | .frequency_min = 950000, |
| 1329 | .frequency_max = 2150000, |
| 1330 | .frequency_stepsize = 1000, /* kHz for QPSK frontends */ |
| 1331 | .frequency_tolerance = 29500, |
| 1332 | .symbol_rate_min = 1000000, |
| 1333 | .symbol_rate_max = 45000000, |
| 1334 | /* . symbol_rate_tolerance = ???,*/ |
| 1335 | .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK |
| 1336 | }, |
| 1337 | |
| 1338 | .release = dst_release, |
| 1339 | |
| 1340 | .init = dst_init, |
| 1341 | |
| 1342 | .set_frontend = dst_set_frontend, |
| 1343 | .get_frontend = dst_get_frontend, |
| 1344 | |
| 1345 | .read_status = dst_read_status, |
| 1346 | .read_signal_strength = dst_read_signal_strength, |
| 1347 | .read_snr = dst_read_snr, |
| 1348 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1349 | .diseqc_send_burst = dst_set_tone, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | .diseqc_send_master_cmd = dst_set_diseqc, |
| 1351 | .set_voltage = dst_set_voltage, |
| 1352 | .set_tone = dst_set_tone, |
| 1353 | }; |
| 1354 | |
| 1355 | static struct dvb_frontend_ops dst_dvbc_ops = { |
| 1356 | |
| 1357 | .info = { |
| 1358 | .name = "DST DVB-C", |
| 1359 | .type = FE_QAM, |
| 1360 | .frequency_stepsize = 62500, |
| 1361 | .frequency_min = 51000000, |
| 1362 | .frequency_max = 858000000, |
| 1363 | .symbol_rate_min = 1000000, |
| 1364 | .symbol_rate_max = 45000000, |
| 1365 | /* . symbol_rate_tolerance = ???,*/ |
| 1366 | .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO |
| 1367 | }, |
| 1368 | |
| 1369 | .release = dst_release, |
| 1370 | |
| 1371 | .init = dst_init, |
| 1372 | |
| 1373 | .set_frontend = dst_set_frontend, |
| 1374 | .get_frontend = dst_get_frontend, |
| 1375 | |
| 1376 | .read_status = dst_read_status, |
| 1377 | .read_signal_strength = dst_read_signal_strength, |
| 1378 | .read_snr = dst_read_snr, |
| 1379 | }; |
| 1380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1382 | MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver"); |
| 1383 | MODULE_AUTHOR("Jamie Honan, Manu Abraham"); |
| 1384 | MODULE_LICENSE("GPL"); |