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