]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * budget.c: driver for the SAA7146 based Budget DVB cards | |
3 | * | |
4 | * Compiled from various sources by Michael Hunold <michael@mihu.de> | |
5 | * | |
6 | * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de> | |
7 | * | |
8 | * Copyright (C) 1999-2002 Ralph Metzler | |
9 | * & Marcus Metzler for convergence integrated media GmbH | |
10 | * | |
11 | * 26feb2004 Support for FS Activy Card (Grundig tuner) by | |
12 | * Michael Dreher <michael@5dot1.de>, | |
13 | * Oliver Endriss <o.endriss@gmx.de> and | |
14 | * Andreas 'randy' Weinberger | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or | |
17 | * modify it under the terms of the GNU General Public License | |
18 | * as published by the Free Software Foundation; either version 2 | |
19 | * of the License, or (at your option) any later version. | |
20 | * | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, | |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26 | * | |
27 | * | |
28 | * You should have received a copy of the GNU General Public License | |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
31 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html | |
32 | * | |
33 | * | |
34 | * the project's page is at http://www.linuxtv.org/dvb/ | |
35 | */ | |
36 | ||
37 | #include "budget.h" | |
38 | #include "stv0299.h" | |
39 | #include "ves1x93.h" | |
40 | #include "ves1820.h" | |
41 | #include "l64781.h" | |
42 | #include "tda8083.h" | |
96bf2f2b | 43 | #include "s5h1420.h" |
1da177e4 LT |
44 | |
45 | static void Set22K (struct budget *budget, int state) | |
46 | { | |
47 | struct saa7146_dev *dev=budget->dev; | |
48 | dprintk(2, "budget: %p\n", budget); | |
49 | saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO)); | |
50 | } | |
51 | ||
52 | /* Diseqc functions only for TT Budget card */ | |
53 | /* taken from the Skyvision DVB driver by | |
54 | Ralph Metzler <rjkm@metzlerbros.de> */ | |
55 | ||
56 | static void DiseqcSendBit (struct budget *budget, int data) | |
57 | { | |
58 | struct saa7146_dev *dev=budget->dev; | |
59 | dprintk(2, "budget: %p\n", budget); | |
60 | ||
61 | saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); | |
62 | udelay(data ? 500 : 1000); | |
63 | saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); | |
64 | udelay(data ? 1000 : 500); | |
65 | } | |
66 | ||
67 | static void DiseqcSendByte (struct budget *budget, int data) | |
68 | { | |
69 | int i, par=1, d; | |
70 | ||
71 | dprintk(2, "budget: %p\n", budget); | |
72 | ||
73 | for (i=7; i>=0; i--) { | |
74 | d = (data>>i)&1; | |
75 | par ^= d; | |
76 | DiseqcSendBit(budget, d); | |
77 | } | |
78 | ||
79 | DiseqcSendBit(budget, par); | |
80 | } | |
81 | ||
82 | static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst) | |
83 | { | |
84 | struct saa7146_dev *dev=budget->dev; | |
85 | int i; | |
86 | ||
87 | dprintk(2, "budget: %p\n", budget); | |
88 | ||
89 | saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); | |
90 | mdelay(16); | |
91 | ||
92 | for (i=0; i<len; i++) | |
93 | DiseqcSendByte(budget, msg[i]); | |
94 | ||
95 | mdelay(16); | |
96 | ||
97 | if (burst!=-1) { | |
98 | if (burst) | |
99 | DiseqcSendByte(budget, 0xff); | |
100 | else { | |
101 | saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); | |
102 | udelay(12500); | |
103 | saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); | |
104 | } | |
105 | msleep(20); | |
106 | } | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | /* | |
112 | * Routines for the Fujitsu Siemens Activy budget card | |
113 | * 22 kHz tone and DiSEqC are handled by the frontend. | |
114 | * Voltage must be set here. | |
f49cc15b | 115 | * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL |
1da177e4 LT |
116 | */ |
117 | static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage) | |
118 | { | |
119 | struct saa7146_dev *dev=budget->dev; | |
120 | ||
121 | dprintk(2, "budget: %p\n", budget); | |
122 | ||
123 | switch (voltage) { | |
124 | case SEC_VOLTAGE_13: | |
f49cc15b | 125 | saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); |
1da177e4 LT |
126 | saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO); |
127 | break; | |
128 | case SEC_VOLTAGE_18: | |
f49cc15b | 129 | saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); |
1da177e4 LT |
130 | saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI); |
131 | break; | |
f49cc15b OE |
132 | case SEC_VOLTAGE_OFF: |
133 | saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); | |
134 | break; | |
1da177e4 LT |
135 | default: |
136 | return -EINVAL; | |
137 | } | |
138 | ||
139 | return 0; | |
140 | } | |
141 | ||
142 | static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) | |
143 | { | |
144 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
145 | ||
146 | return SetVoltage_Activy (budget, voltage); | |
147 | } | |
148 | ||
149 | static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) | |
150 | { | |
151 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
152 | ||
153 | switch (tone) { | |
154 | case SEC_TONE_ON: | |
155 | Set22K (budget, 1); | |
156 | break; | |
157 | ||
158 | case SEC_TONE_OFF: | |
159 | Set22K (budget, 0); | |
160 | break; | |
161 | ||
162 | default: | |
163 | return -EINVAL; | |
164 | } | |
165 | ||
166 | return 0; | |
167 | } | |
168 | ||
169 | static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) | |
170 | { | |
171 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
172 | ||
173 | SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0); | |
174 | ||
175 | return 0; | |
176 | } | |
177 | ||
178 | static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) | |
179 | { | |
180 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
181 | ||
182 | SendDiSEqCMsg (budget, 0, NULL, minicmd); | |
183 | ||
184 | return 0; | |
185 | } | |
186 | ||
96bf2f2b AQ |
187 | static int lnbp21_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) |
188 | { | |
189 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
190 | u8 buf; | |
191 | struct i2c_msg msg = { .addr = 0x08, .flags = I2C_M_RD, .buf = &buf, .len = sizeof(buf) }; | |
192 | ||
193 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
194 | ||
195 | switch(voltage) { | |
196 | case SEC_VOLTAGE_13: | |
197 | buf = (buf & 0xf7) | 0x04; | |
198 | break; | |
199 | ||
200 | case SEC_VOLTAGE_18: | |
201 | buf = (buf & 0xf7) | 0x0c; | |
202 | break; | |
203 | ||
204 | case SEC_VOLTAGE_OFF: | |
205 | buf = buf & 0xf0; | |
206 | break; | |
207 | } | |
208 | ||
209 | msg.flags = 0; | |
210 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
211 | ||
212 | return 0; | |
213 | } | |
214 | ||
400b7083 | 215 | static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend* fe, long arg) |
96bf2f2b AQ |
216 | { |
217 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
218 | u8 buf; | |
219 | struct i2c_msg msg = { .addr = 0x08, .flags = I2C_M_RD, .buf = &buf, .len = sizeof(buf) }; | |
220 | ||
221 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
222 | ||
223 | if (arg) { | |
224 | buf = buf | 0x10; | |
225 | } else { | |
226 | buf = buf & 0xef; | |
227 | } | |
228 | ||
229 | msg.flags = 0; | |
230 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
231 | ||
232 | return 0; | |
233 | } | |
234 | ||
9691bb14 | 235 | static int lnbp21_init(struct budget* budget) |
96bf2f2b AQ |
236 | { |
237 | u8 buf = 0x00; | |
238 | struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = &buf, .len = sizeof(buf) }; | |
239 | ||
9691bb14 MZ |
240 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) |
241 | return -EIO; | |
242 | return 0; | |
96bf2f2b AQ |
243 | } |
244 | ||
1da177e4 LT |
245 | static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) |
246 | { | |
247 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
248 | u8 pwr = 0; | |
249 | u8 buf[4]; | |
250 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; | |
251 | u32 div = (params->frequency + 479500) / 125; | |
252 | ||
253 | if (params->frequency > 2000000) pwr = 3; | |
254 | else if (params->frequency > 1800000) pwr = 2; | |
255 | else if (params->frequency > 1600000) pwr = 1; | |
256 | else if (params->frequency > 1200000) pwr = 0; | |
257 | else if (params->frequency >= 1100000) pwr = 1; | |
258 | else pwr = 2; | |
259 | ||
260 | buf[0] = (div >> 8) & 0x7f; | |
261 | buf[1] = div & 0xff; | |
262 | buf[2] = ((div & 0x18000) >> 10) | 0x95; | |
263 | buf[3] = (pwr << 6) | 0x30; | |
264 | ||
9101e622 | 265 | // NOTE: since we're using a prescaler of 2, we set the |
1da177e4 LT |
266 | // divisor frequency to 62.5kHz and divide by 125 above |
267 | ||
268 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
269 | return 0; | |
270 | } | |
271 | ||
272 | static struct ves1x93_config alps_bsrv2_config = | |
273 | { | |
274 | .demod_address = 0x08, | |
275 | .xin = 90100000UL, | |
276 | .invert_pwm = 0, | |
277 | .pll_set = alps_bsrv2_pll_set, | |
278 | }; | |
279 | ||
280 | static u8 alps_bsru6_inittab[] = { | |
281 | 0x01, 0x15, | |
282 | 0x02, 0x00, | |
283 | 0x03, 0x00, | |
9691bb14 | 284 | 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ |
1da177e4 LT |
285 | 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ |
286 | 0x06, 0x40, /* DAC not used, set to high impendance mode */ | |
287 | 0x07, 0x00, /* DAC LSB */ | |
288 | 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */ | |
289 | 0x09, 0x00, /* FIFO */ | |
290 | 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ | |
291 | 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ | |
292 | 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ | |
293 | 0x10, 0x3f, // AGC2 0x3d | |
294 | 0x11, 0x84, | |
ff29d06a | 295 | 0x12, 0xb9, |
1da177e4 LT |
296 | 0x15, 0xc9, // lock detector threshold |
297 | 0x16, 0x00, | |
298 | 0x17, 0x00, | |
299 | 0x18, 0x00, | |
300 | 0x19, 0x00, | |
301 | 0x1a, 0x00, | |
302 | 0x1f, 0x50, | |
303 | 0x20, 0x00, | |
304 | 0x21, 0x00, | |
305 | 0x22, 0x00, | |
306 | 0x23, 0x00, | |
307 | 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 | |
308 | 0x29, 0x1e, // 1/2 threshold | |
309 | 0x2a, 0x14, // 2/3 threshold | |
310 | 0x2b, 0x0f, // 3/4 threshold | |
311 | 0x2c, 0x09, // 5/6 threshold | |
312 | 0x2d, 0x05, // 7/8 threshold | |
313 | 0x2e, 0x01, | |
314 | 0x31, 0x1f, // test all FECs | |
315 | 0x32, 0x19, // viterbi and synchro search | |
316 | 0x33, 0xfc, // rs control | |
317 | 0x34, 0x93, // error control | |
318 | 0x0f, 0x52, | |
319 | 0xff, 0xff | |
320 | }; | |
321 | ||
322 | static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio) | |
323 | { | |
324 | u8 aclk = 0; | |
325 | u8 bclk = 0; | |
326 | ||
327 | if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; } | |
328 | else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; } | |
329 | else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; } | |
330 | else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; } | |
331 | else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; } | |
332 | else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; } | |
333 | ||
334 | stv0299_writereg (fe, 0x13, aclk); | |
335 | stv0299_writereg (fe, 0x14, bclk); | |
336 | stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); | |
337 | stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); | |
338 | stv0299_writereg (fe, 0x21, (ratio ) & 0xf0); | |
339 | ||
340 | return 0; | |
341 | } | |
342 | ||
cfbfce15 | 343 | static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params) |
1da177e4 | 344 | { |
1da177e4 LT |
345 | u8 data[4]; |
346 | u32 div; | |
347 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; | |
348 | ||
349 | if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL; | |
350 | ||
351 | div = (params->frequency + (125 - 1)) / 125; // round correctly | |
352 | data[0] = (div >> 8) & 0x7f; | |
353 | data[1] = div & 0xff; | |
354 | data[2] = 0x80 | ((div & 0x18000) >> 10) | 4; | |
355 | data[3] = 0xC4; | |
356 | ||
357 | if (params->frequency > 1530000) data[3] = 0xc0; | |
358 | ||
cfbfce15 | 359 | if (i2c_transfer(i2c, &msg, 1) != 1) return -EIO; |
1da177e4 LT |
360 | return 0; |
361 | } | |
362 | ||
363 | static struct stv0299_config alps_bsru6_config = { | |
364 | ||
365 | .demod_address = 0x68, | |
366 | .inittab = alps_bsru6_inittab, | |
367 | .mclk = 88000000UL, | |
368 | .invert = 1, | |
1da177e4 LT |
369 | .skip_reinit = 0, |
370 | .lock_output = STV0229_LOCKOUTPUT_1, | |
371 | .volt13_op0_op1 = STV0299_VOLT13_OP1, | |
372 | .min_delay_ms = 100, | |
373 | .set_symbol_rate = alps_bsru6_set_symbol_rate, | |
374 | .pll_set = alps_bsru6_pll_set, | |
375 | }; | |
376 | ||
9691bb14 MZ |
377 | static u8 alps_bsbe1_inittab[] = { |
378 | 0x01, 0x15, | |
379 | 0x02, 0x30, | |
380 | 0x03, 0x00, | |
381 | 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ | |
382 | 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ | |
383 | 0x06, 0x40, /* DAC not used, set to high impendance mode */ | |
384 | 0x07, 0x00, /* DAC LSB */ | |
385 | 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */ | |
386 | 0x09, 0x00, /* FIFO */ | |
387 | 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ | |
388 | 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ | |
389 | 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ | |
390 | 0x10, 0x3f, // AGC2 0x3d | |
391 | 0x11, 0x84, | |
ff29d06a | 392 | 0x12, 0xb9, |
9691bb14 MZ |
393 | 0x15, 0xc9, // lock detector threshold |
394 | 0x16, 0x00, | |
395 | 0x17, 0x00, | |
396 | 0x18, 0x00, | |
397 | 0x19, 0x00, | |
398 | 0x1a, 0x00, | |
399 | 0x1f, 0x50, | |
400 | 0x20, 0x00, | |
401 | 0x21, 0x00, | |
402 | 0x22, 0x00, | |
403 | 0x23, 0x00, | |
404 | 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 | |
405 | 0x29, 0x1e, // 1/2 threshold | |
406 | 0x2a, 0x14, // 2/3 threshold | |
407 | 0x2b, 0x0f, // 3/4 threshold | |
408 | 0x2c, 0x09, // 5/6 threshold | |
409 | 0x2d, 0x05, // 7/8 threshold | |
410 | 0x2e, 0x01, | |
411 | 0x31, 0x1f, // test all FECs | |
412 | 0x32, 0x19, // viterbi and synchro search | |
413 | 0x33, 0xfc, // rs control | |
414 | 0x34, 0x93, // error control | |
415 | 0x0f, 0x92, // 0x80 = inverse AGC | |
416 | 0xff, 0xff | |
417 | }; | |
418 | ||
419 | static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params) | |
420 | { | |
421 | int ret; | |
422 | u8 data[4]; | |
423 | u32 div; | |
424 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; | |
425 | ||
426 | if ((params->frequency < 950000) || (params->frequency > 2150000)) | |
427 | return -EINVAL; | |
428 | ||
429 | div = (params->frequency + (125 - 1)) / 125; // round correctly | |
430 | data[0] = (div >> 8) & 0x7f; | |
431 | data[1] = div & 0xff; | |
432 | data[2] = 0x80 | ((div & 0x18000) >> 10) | 4; | |
433 | data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4; | |
434 | ||
435 | ret = i2c_transfer(i2c, &msg, 1); | |
436 | return (ret != 1) ? -EIO : 0; | |
437 | } | |
438 | ||
439 | static struct stv0299_config alps_bsbe1_config = { | |
440 | .demod_address = 0x68, | |
441 | .inittab = alps_bsbe1_inittab, | |
442 | .mclk = 88000000UL, | |
443 | .invert = 1, | |
9691bb14 MZ |
444 | .skip_reinit = 0, |
445 | .min_delay_ms = 100, | |
446 | .set_symbol_rate = alps_bsru6_set_symbol_rate, | |
447 | .pll_set = alps_bsbe1_pll_set, | |
448 | }; | |
449 | ||
1da177e4 LT |
450 | static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) |
451 | { | |
452 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
453 | u32 div; | |
454 | u8 data[4]; | |
455 | struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) }; | |
456 | ||
457 | div = (params->frequency + 35937500 + 31250) / 62500; | |
458 | ||
459 | data[0] = (div >> 8) & 0x7f; | |
460 | data[1] = div & 0xff; | |
461 | data[2] = 0x85 | ((div >> 10) & 0x60); | |
462 | data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81); | |
463 | ||
464 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
465 | return 0; | |
466 | } | |
467 | ||
468 | static struct ves1820_config alps_tdbe2_config = { | |
469 | .demod_address = 0x09, | |
470 | .xin = 57840000UL, | |
471 | .invert = 1, | |
472 | .selagc = VES1820_SELAGC_SIGNAMPERR, | |
473 | .pll_set = alps_tdbe2_pll_set, | |
474 | }; | |
475 | ||
476 | static int grundig_29504_401_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | |
477 | { | |
478 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
479 | u32 div; | |
480 | u8 cfg, cpump, band_select; | |
481 | u8 data[4]; | |
482 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; | |
483 | ||
484 | div = (36125000 + params->frequency) / 166666; | |
485 | ||
486 | cfg = 0x88; | |
487 | ||
488 | if (params->frequency < 175000000) cpump = 2; | |
489 | else if (params->frequency < 390000000) cpump = 1; | |
490 | else if (params->frequency < 470000000) cpump = 2; | |
491 | else if (params->frequency < 750000000) cpump = 1; | |
492 | else cpump = 3; | |
493 | ||
494 | if (params->frequency < 175000000) band_select = 0x0e; | |
495 | else if (params->frequency < 470000000) band_select = 0x05; | |
496 | else band_select = 0x03; | |
497 | ||
498 | data[0] = (div >> 8) & 0x7f; | |
499 | data[1] = div & 0xff; | |
500 | data[2] = ((div >> 10) & 0x60) | cfg; | |
501 | data[3] = (cpump << 6) | band_select; | |
502 | ||
503 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
504 | return 0; | |
505 | } | |
506 | ||
507 | static struct l64781_config grundig_29504_401_config = { | |
508 | .demod_address = 0x55, | |
509 | .pll_set = grundig_29504_401_pll_set, | |
510 | }; | |
511 | ||
512 | static int grundig_29504_451_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | |
513 | { | |
514 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
515 | u32 div; | |
516 | u8 data[4]; | |
517 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; | |
518 | ||
519 | div = params->frequency / 125; | |
520 | data[0] = (div >> 8) & 0x7f; | |
521 | data[1] = div & 0xff; | |
522 | data[2] = 0x8e; | |
523 | data[3] = 0x00; | |
524 | ||
525 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
526 | return 0; | |
527 | } | |
528 | ||
529 | static struct tda8083_config grundig_29504_451_config = { | |
530 | .demod_address = 0x68, | |
531 | .pll_set = grundig_29504_451_pll_set, | |
532 | }; | |
533 | ||
96bf2f2b AQ |
534 | static int s5h1420_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u32* freqout) |
535 | { | |
536 | struct budget* budget = (struct budget*) fe->dvb->priv; | |
537 | u32 div; | |
538 | u8 data[4]; | |
539 | struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; | |
540 | ||
541 | div = params->frequency / 1000; | |
542 | data[0] = (div >> 8) & 0x7f; | |
543 | data[1] = div & 0xff; | |
544 | data[2] = 0xc2; | |
545 | ||
546 | if (div < 1450) | |
547 | data[3] = 0x00; | |
548 | else if (div < 1850) | |
549 | data[3] = 0x40; | |
550 | else if (div < 2000) | |
551 | data[3] = 0x80; | |
552 | else | |
553 | data[3] = 0xc0; | |
554 | ||
555 | if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; | |
556 | ||
557 | *freqout = div * 1000; | |
558 | return 0; | |
559 | } | |
560 | ||
561 | static struct s5h1420_config s5h1420_config = { | |
562 | .demod_address = 0x53, | |
a9d6a80b | 563 | .invert = 1, |
96bf2f2b AQ |
564 | .pll_set = s5h1420_pll_set, |
565 | }; | |
566 | ||
1da177e4 LT |
567 | static u8 read_pwm(struct budget* budget) |
568 | { | |
569 | u8 b = 0xff; | |
570 | u8 pwm; | |
571 | struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 }, | |
572 | { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} }; | |
573 | ||
9101e622 | 574 | if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff)) |
1da177e4 LT |
575 | pwm = 0x48; |
576 | ||
577 | return pwm; | |
578 | } | |
579 | ||
580 | static void frontend_init(struct budget *budget) | |
581 | { | |
582 | switch(budget->dev->pci->subsystem_device) { | |
9691bb14 MZ |
583 | case 0x1017: |
584 | // try the ALPS BSBE1 now | |
585 | budget->dvb_frontend = stv0299_attach(&alps_bsbe1_config, &budget->i2c_adap); | |
586 | if (budget->dvb_frontend) { | |
587 | budget->dvb_frontend->ops->set_voltage = lnbp21_set_voltage; | |
588 | budget->dvb_frontend->ops->enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; | |
f49cc15b | 589 | budget->dvb_frontend->ops->dishnetwork_send_legacy_command = NULL; |
9691bb14 MZ |
590 | if (lnbp21_init(budget)) { |
591 | printk("%s: No LNBP21 found!\n", __FUNCTION__); | |
592 | goto error_out; | |
593 | } | |
594 | } | |
595 | ||
596 | break; | |
1da177e4 LT |
597 | case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659)) |
598 | case 0x1013: | |
599 | // try the ALPS BSRV2 first of all | |
600 | budget->dvb_frontend = ves1x93_attach(&alps_bsrv2_config, &budget->i2c_adap); | |
601 | if (budget->dvb_frontend) { | |
602 | budget->dvb_frontend->ops->diseqc_send_master_cmd = budget_diseqc_send_master_cmd; | |
9101e622 | 603 | budget->dvb_frontend->ops->diseqc_send_burst = budget_diseqc_send_burst; |
1da177e4 LT |
604 | budget->dvb_frontend->ops->set_tone = budget_set_tone; |
605 | break; | |
606 | } | |
607 | ||
608 | // try the ALPS BSRU6 now | |
609 | budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap); | |
610 | if (budget->dvb_frontend) { | |
611 | budget->dvb_frontend->ops->diseqc_send_master_cmd = budget_diseqc_send_master_cmd; | |
612 | budget->dvb_frontend->ops->diseqc_send_burst = budget_diseqc_send_burst; | |
613 | budget->dvb_frontend->ops->set_tone = budget_set_tone; | |
614 | break; | |
615 | } | |
616 | break; | |
617 | ||
618 | case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659)) | |
619 | ||
620 | budget->dvb_frontend = ves1820_attach(&alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget)); | |
621 | if (budget->dvb_frontend) break; | |
622 | break; | |
623 | ||
624 | case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060)) | |
625 | ||
626 | budget->dvb_frontend = l64781_attach(&grundig_29504_401_config, &budget->i2c_adap); | |
627 | if (budget->dvb_frontend) break; | |
628 | break; | |
629 | ||
630 | case 0x4f60: // Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/ALPS BSRU6(tsa5059)) | |
631 | budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap); | |
632 | if (budget->dvb_frontend) { | |
633 | budget->dvb_frontend->ops->set_voltage = siemens_budget_set_voltage; | |
f49cc15b | 634 | budget->dvb_frontend->ops->dishnetwork_send_legacy_command = NULL; |
1da177e4 LT |
635 | } |
636 | break; | |
637 | ||
638 | case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522)) | |
639 | budget->dvb_frontend = tda8083_attach(&grundig_29504_451_config, &budget->i2c_adap); | |
640 | if (budget->dvb_frontend) { | |
641 | budget->dvb_frontend->ops->set_voltage = siemens_budget_set_voltage; | |
f49cc15b | 642 | budget->dvb_frontend->ops->dishnetwork_send_legacy_command = NULL; |
1da177e4 LT |
643 | } |
644 | break; | |
96bf2f2b AQ |
645 | |
646 | case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260)) | |
647 | budget->dvb_frontend = s5h1420_attach(&s5h1420_config, &budget->i2c_adap); | |
648 | if (budget->dvb_frontend) { | |
649 | budget->dvb_frontend->ops->set_voltage = lnbp21_set_voltage; | |
650 | budget->dvb_frontend->ops->enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; | |
9691bb14 MZ |
651 | if (lnbp21_init(budget)) { |
652 | printk("%s: No LNBP21 found!\n", __FUNCTION__); | |
653 | goto error_out; | |
654 | } | |
96bf2f2b AQ |
655 | break; |
656 | } | |
1da177e4 LT |
657 | } |
658 | ||
659 | if (budget->dvb_frontend == NULL) { | |
660 | printk("budget: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", | |
661 | budget->dev->pci->vendor, | |
662 | budget->dev->pci->device, | |
663 | budget->dev->pci->subsystem_vendor, | |
664 | budget->dev->pci->subsystem_device); | |
665 | } else { | |
9691bb14 MZ |
666 | if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) |
667 | goto error_out; | |
1da177e4 | 668 | } |
9691bb14 MZ |
669 | return; |
670 | ||
671 | error_out: | |
672 | printk("budget: Frontend registration failed!\n"); | |
673 | if (budget->dvb_frontend->ops->release) | |
674 | budget->dvb_frontend->ops->release(budget->dvb_frontend); | |
675 | budget->dvb_frontend = NULL; | |
676 | return; | |
1da177e4 LT |
677 | } |
678 | ||
679 | static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info) | |
680 | { | |
681 | struct budget *budget = NULL; | |
682 | int err; | |
683 | ||
684 | budget = kmalloc(sizeof(struct budget), GFP_KERNEL); | |
685 | if( NULL == budget ) { | |
686 | return -ENOMEM; | |
687 | } | |
688 | ||
689 | dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget); | |
690 | ||
691 | dev->ext_priv = budget; | |
692 | ||
693 | if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) { | |
694 | printk("==> failed\n"); | |
695 | kfree (budget); | |
696 | return err; | |
697 | } | |
698 | ||
fdc53a6d | 699 | budget->dvb_adapter.priv = budget; |
1da177e4 LT |
700 | frontend_init(budget); |
701 | ||
702 | return 0; | |
703 | } | |
704 | ||
705 | static int budget_detach (struct saa7146_dev* dev) | |
706 | { | |
707 | struct budget *budget = (struct budget*) dev->ext_priv; | |
708 | int err; | |
709 | ||
710 | if (budget->dvb_frontend) dvb_unregister_frontend(budget->dvb_frontend); | |
711 | ||
712 | err = ttpci_budget_deinit (budget); | |
713 | ||
714 | kfree (budget); | |
715 | dev->ext_priv = NULL; | |
716 | ||
717 | return err; | |
718 | } | |
719 | ||
720 | static struct saa7146_extension budget_extension; | |
721 | ||
9691bb14 | 722 | MAKE_BUDGET_INFO(ttbs2, "TT-Budget/WinTV-NOVA-S PCI (rev AL/alps bsbe1 lnbp21 frontend)", BUDGET_TT); |
1da177e4 LT |
723 | MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT); |
724 | MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT); | |
725 | MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); | |
726 | MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC); | |
727 | MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY); | |
728 | MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY); | |
729 | ||
730 | static struct pci_device_id pci_tbl[] = { | |
731 | MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003), | |
732 | MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004), | |
733 | MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005), | |
734 | MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013), | |
9691bb14 | 735 | MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017), |
96bf2f2b | 736 | MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016), |
1da177e4 LT |
737 | MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60), |
738 | MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61), | |
739 | { | |
740 | .vendor = 0, | |
741 | } | |
742 | }; | |
743 | ||
744 | MODULE_DEVICE_TABLE(pci, pci_tbl); | |
745 | ||
746 | static struct saa7146_extension budget_extension = { | |
747 | .name = "budget dvb\0", | |
69459f3d | 748 | .flags = SAA7146_I2C_SHORT_DELAY, |
1da177e4 LT |
749 | |
750 | .module = THIS_MODULE, | |
751 | .pci_tbl = pci_tbl, | |
752 | .attach = budget_attach, | |
753 | .detach = budget_detach, | |
754 | ||
755 | .irq_mask = MASK_10, | |
756 | .irq_func = ttpci_budget_irq10_handler, | |
757 | }; | |
758 | ||
759 | static int __init budget_init(void) | |
760 | { | |
761 | return saa7146_register_extension(&budget_extension); | |
762 | } | |
763 | ||
764 | static void __exit budget_exit(void) | |
765 | { | |
766 | saa7146_unregister_extension(&budget_extension); | |
767 | } | |
768 | ||
769 | module_init(budget_init); | |
770 | module_exit(budget_exit); | |
771 | ||
772 | MODULE_LICENSE("GPL"); | |
773 | MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others"); | |
774 | MODULE_DESCRIPTION("driver for the SAA7146 based so-called " | |
775 | "budget PCI DVB cards by Siemens, Technotrend, Hauppauge"); |