aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb
diff options
context:
space:
mode:
authorPatrick Boettcher <pboettcher@kernellabs.com>2010-10-31 15:24:19 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-21 19:31:33 -0400
commit739ff04f63ba6498b287021649cb999e639c3c83 (patch)
tree3832762eb09f36c56fcf1f27057cb888a52225a5 /drivers/media/dvb
parent4f7200a8a0253e7a4b74cbf1a0a3868cccdee647 (diff)
[media] technisat-usb2: added driver for Technisat's USB2.0 DVB-S/S2 receiver
This patch is adding support for Technisat's new USB2.0 DVB-S/S2 receiver device. The development was sponsored by Technisat. The Green led is toggle depending on the frontend-state. The Red LED is turned on all the time. The MAC address reading from the EEPROM along with the LRC-method to check whether its valid. Support for the IR-receiver of the Technisat USB2 box. The keys of small, black remote-control are built-in, repeated key behaviour are simulated. The i2c-mutex of the dvb-usb-structure is used as a general mutex for USB requests, as there are 3 threads racing for atomic requests consisting of multiple usb-requests. A module option is there which disables the toggling of LEDs by the driver on certain triggers. Useful when being used in a "dark" environment. [mchehab@redhat.com: Fix merge conflicts with RC renaming patches] Signed-off-by: Martin Wilks <m.wilks@technisat.com> Signed-off-by: Patrick Boettcher <pboettcher@kernellabs.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig8
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h1
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h2
-rw-r--r--drivers/media/dvb/dvb-usb/technisat-usb2.c808
6 files changed, 823 insertions, 1 deletions
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 3d48ba019342..fe4f894183ff 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -358,3 +358,11 @@ config DVB_USB_LME2510
358 select DVB_IX2505V if !DVB_FE_CUSTOMISE 358 select DVB_IX2505V if !DVB_FE_CUSTOMISE
359 help 359 help
360 Say Y here to support the LME DM04/QQBOX DVB-S USB2.0 . 360 Say Y here to support the LME DM04/QQBOX DVB-S USB2.0 .
361
362config DVB_USB_TECHNISAT_USB2
363 tristate "Technisat DVB-S/S2 USB2.0 support"
364 depends on DVB_USB
365 select DVB_STB0899 if !DVB_FE_CUSTOMISE
366 select DVB_STB6100 if !DVB_FE_CUSTOMISE
367 help
368 Say Y here to support the Technisat USB2 DVB-S/S2 device
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 5b1d12f2d591..4bac13da0c39 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -91,6 +91,9 @@ obj-$(CONFIG_DVB_USB_AZ6027) += dvb-usb-az6027.o
91dvb-usb-lmedm04-objs = lmedm04.o 91dvb-usb-lmedm04-objs = lmedm04.o
92obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o 92obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o
93 93
94dvb-usb-technisat-usb2-objs = technisat-usb2.o
95obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o
96
94EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 97EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
95# due to tuner-xc3028 98# due to tuner-xc3028
96EXTRA_CFLAGS += -Idrivers/media/common/tuners 99EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 1a6310b61923..d0bce0445cc7 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -312,4 +312,5 @@
312#define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac 312#define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac
313#define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001 313#define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001
314#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002 314#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002
315#define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500
315#endif 316#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 23005b3cf30b..f511418b144a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -246,7 +246,7 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d)
246 dev->map_name = d->props.rc.core.rc_codes; 246 dev->map_name = d->props.rc.core.rc_codes;
247 dev->change_protocol = d->props.rc.core.change_protocol; 247 dev->change_protocol = d->props.rc.core.change_protocol;
248 dev->allowed_protos = d->props.rc.core.allowed_protos; 248 dev->allowed_protos = d->props.rc.core.allowed_protos;
249 dev->driver_type = RC_DRIVER_SCANCODE; 249 dev->driver_type = d->props.rc.core.driver_type;
250 usb_to_input_id(d->udev, &dev->input_id); 250 usb_to_input_id(d->udev, &dev->input_id);
251 dev->input_name = "IR-receiver inside an USB DVB receiver"; 251 dev->input_name = "IR-receiver inside an USB DVB receiver";
252 dev->input_phys = d->rc_phys; 252 dev->input_phys = d->rc_phys;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 65fa9268e7f7..76a80968482a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -181,6 +181,7 @@ struct dvb_rc_legacy {
181 * @rc_codes: name of rc codes table 181 * @rc_codes: name of rc codes table
182 * @protocol: type of protocol(s) currently used by the driver 182 * @protocol: type of protocol(s) currently used by the driver
183 * @allowed_protos: protocol(s) supported by the driver 183 * @allowed_protos: protocol(s) supported by the driver
184 * @driver_type: Used to point if a device supports raw mode
184 * @change_protocol: callback to change protocol 185 * @change_protocol: callback to change protocol
185 * @rc_query: called to query an event event. 186 * @rc_query: called to query an event event.
186 * @rc_interval: time in ms between two queries. 187 * @rc_interval: time in ms between two queries.
@@ -190,6 +191,7 @@ struct dvb_rc {
190 char *rc_codes; 191 char *rc_codes;
191 u64 protocol; 192 u64 protocol;
192 u64 allowed_protos; 193 u64 allowed_protos;
194 enum rc_driver_type driver_type;
193 int (*change_protocol)(struct rc_dev *dev, u64 rc_type); 195 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
194 char *module_name; 196 char *module_name;
195 int (*rc_query) (struct dvb_usb_device *d); 197 int (*rc_query) (struct dvb_usb_device *d);
diff --git a/drivers/media/dvb/dvb-usb/technisat-usb2.c b/drivers/media/dvb/dvb-usb/technisat-usb2.c
new file mode 100644
index 000000000000..406602a1499d
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/technisat-usb2.c
@@ -0,0 +1,808 @@
1/*
2 * Linux driver for Technisat DVB-S/S2 USB 2.0 device
3 *
4 * Copyright (C) 2010 Patrick Boettcher,
5 * Kernel Labs Inc. PO Box 745, St James, NY 11780
6 *
7 * Development was sponsored by Technisat Digital UK Limited, whose
8 * registered office is Witan Gate House 500 - 600 Witan Gate West,
9 * Milton Keynes, MK9 1SH
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
15 *
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 *
21 * THIS PROGRAM IS PROVIDED "AS IS" AND BOTH THE COPYRIGHT HOLDER AND
22 * TECHNISAT DIGITAL UK LTD DISCLAIM ALL WARRANTIES WITH REGARD TO
23 * THIS PROGRAM INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY OR
24 * FITNESS FOR A PARTICULAR PURPOSE. NEITHER THE COPYRIGHT HOLDER
25 * NOR TECHNISAT DIGITAL UK LIMITED SHALL BE LIABLE FOR ANY SPECIAL,
26 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
27 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
28 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
29 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS PROGRAM. See the
30 * GNU General Public License for more details.
31 */
32
33#define DVB_USB_LOG_PREFIX "technisat-usb2"
34#include "dvb-usb.h"
35
36#include "stv6110x.h"
37#include "stv090x.h"
38
39/* module parameters */
40DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
41
42static int debug;
43module_param(debug, int, 0644);
44MODULE_PARM_DESC(debug,
45 "set debugging level (bit-mask: 1=info,2=eeprom,4=i2c,8=rc)." \
46 DVB_USB_DEBUG_STATUS);
47
48/* disables all LED control command and
49 * also does not start the signal polling thread */
50static int disable_led_control;
51module_param(disable_led_control, int, 0444);
52MODULE_PARM_DESC(disable_led_control,
53 "disable LED control of the device "
54 "(default: 0 - LED control is active).");
55
56/* device private data */
57struct technisat_usb2_state {
58 struct dvb_usb_device *dev;
59 struct delayed_work green_led_work;
60 u8 power_state;
61
62 u16 last_scan_code;
63};
64
65/* debug print helpers */
66#define deb_info(args...) dprintk(debug, 0x01, args)
67#define deb_eeprom(args...) dprintk(debug, 0x02, args)
68#define deb_i2c(args...) dprintk(debug, 0x04, args)
69#define deb_rc(args...) dprintk(debug, 0x08, args)
70
71/* vendor requests */
72#define SET_IFCLK_TO_EXTERNAL_TSCLK_VENDOR_REQUEST 0xB3
73#define SET_FRONT_END_RESET_VENDOR_REQUEST 0xB4
74#define GET_VERSION_INFO_VENDOR_REQUEST 0xB5
75#define SET_GREEN_LED_VENDOR_REQUEST 0xB6
76#define SET_RED_LED_VENDOR_REQUEST 0xB7
77#define GET_IR_DATA_VENDOR_REQUEST 0xB8
78#define SET_LED_TIMER_DIVIDER_VENDOR_REQUEST 0xB9
79#define SET_USB_REENUMERATION 0xBA
80
81/* i2c-access methods */
82#define I2C_SPEED_100KHZ_BIT 0x40
83
84#define I2C_STATUS_NAK 7
85#define I2C_STATUS_OK 8
86
87static int technisat_usb2_i2c_access(struct usb_device *udev,
88 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
89{
90 u8 b[64];
91 int ret, actual_length;
92
93 deb_i2c("i2c-access: %02x, tx: ", device_addr);
94 debug_dump(tx, txlen, deb_i2c);
95 deb_i2c(" ");
96
97 if (txlen > 62) {
98 err("i2c TX buffer can't exceed 62 bytes (dev 0x%02x)",
99 device_addr);
100 txlen = 62;
101 }
102 if (rxlen > 62) {
103 err("i2c RX buffer can't exceed 62 bytes (dev 0x%02x)",
104 device_addr);
105 txlen = 62;
106 }
107
108 b[0] = I2C_SPEED_100KHZ_BIT;
109 b[1] = device_addr << 1;
110
111 if (rx != NULL) {
112 b[0] |= rxlen;
113 b[1] |= 1;
114 }
115
116 memcpy(&b[2], tx, txlen);
117 ret = usb_bulk_msg(udev,
118 usb_sndbulkpipe(udev, 0x01),
119 b, 2 + txlen,
120 NULL, 1000);
121
122 if (ret < 0) {
123 err("i2c-error: out failed %02x = %d", device_addr, ret);
124 return -ENODEV;
125 }
126
127 ret = usb_bulk_msg(udev,
128 usb_rcvbulkpipe(udev, 0x01),
129 b, 64, &actual_length, 1000);
130 if (ret < 0) {
131 err("i2c-error: in failed %02x = %d", device_addr, ret);
132 return -ENODEV;
133 }
134
135 if (b[0] != I2C_STATUS_OK) {
136 err("i2c-error: %02x = %d", device_addr, b[0]);
137 /* handle tuner-i2c-nak */
138 if (!(b[0] == I2C_STATUS_NAK &&
139 device_addr == 0x60
140 /* && device_is_technisat_usb2 */))
141 return -ENODEV;
142 }
143
144 deb_i2c("status: %d, ", b[0]);
145
146 if (rx != NULL) {
147 memcpy(rx, &b[2], rxlen);
148
149 deb_i2c("rx (%d): ", rxlen);
150 debug_dump(rx, rxlen, deb_i2c);
151 }
152
153 deb_i2c("\n");
154
155 return 0;
156}
157
158static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
159 int num)
160{
161 int ret = 0, i;
162 struct dvb_usb_device *d = i2c_get_adapdata(adap);
163
164 /* Ensure nobody else hits the i2c bus while we're sending our
165 sequence of messages, (such as the remote control thread) */
166 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
167 return -EAGAIN;
168
169 for (i = 0; i < num; i++) {
170 if (i+1 < num && msg[i+1].flags & I2C_M_RD) {
171 ret = technisat_usb2_i2c_access(d->udev, msg[i+1].addr,
172 msg[i].buf, msg[i].len,
173 msg[i+1].buf, msg[i+1].len);
174 if (ret != 0)
175 break;
176 i++;
177 } else {
178 ret = technisat_usb2_i2c_access(d->udev, msg[i].addr,
179 msg[i].buf, msg[i].len,
180 NULL, 0);
181 if (ret != 0)
182 break;
183 }
184 }
185
186 if (ret == 0)
187 ret = i;
188
189 mutex_unlock(&d->i2c_mutex);
190
191 return ret;
192}
193
194static u32 technisat_usb2_i2c_func(struct i2c_adapter *adapter)
195{
196 return I2C_FUNC_I2C;
197}
198
199static struct i2c_algorithm technisat_usb2_i2c_algo = {
200 .master_xfer = technisat_usb2_i2c_xfer,
201 .functionality = technisat_usb2_i2c_func,
202};
203
204#if 0
205static void technisat_usb2_frontend_reset(struct usb_device *udev)
206{
207 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
208 SET_FRONT_END_RESET_VENDOR_REQUEST,
209 USB_TYPE_VENDOR | USB_DIR_OUT,
210 10, 0,
211 NULL, 0, 500);
212}
213#endif
214
215/* LED control */
216enum technisat_usb2_led_state {
217 LED_OFF,
218 LED_BLINK,
219 LED_ON,
220 LED_UNDEFINED
221};
222
223static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum technisat_usb2_led_state state)
224{
225 int ret;
226
227 u8 led[8] = {
228 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
229 0
230 };
231
232 if (disable_led_control && state != LED_OFF)
233 return 0;
234
235 switch (state) {
236 case LED_ON:
237 led[1] = 0x82;
238 break;
239 case LED_BLINK:
240 led[1] = 0x82;
241 if (red) {
242 led[2] = 0x02;
243 led[3] = 10;
244 led[4] = 10;
245 } else {
246 led[2] = 0xff;
247 led[3] = 50;
248 led[4] = 50;
249 }
250 led[5] = 1;
251 break;
252
253 default:
254 case LED_OFF:
255 led[1] = 0x80;
256 break;
257 }
258
259 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
260 return -EAGAIN;
261
262 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
263 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
264 USB_TYPE_VENDOR | USB_DIR_OUT,
265 0, 0,
266 led, sizeof(led), 500);
267
268 mutex_unlock(&d->i2c_mutex);
269 return ret;
270}
271
272static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
273{
274 int ret;
275 u8 b = 0;
276
277 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
278 return -EAGAIN;
279
280 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
281 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
282 USB_TYPE_VENDOR | USB_DIR_OUT,
283 (red << 8) | green, 0,
284 &b, 1, 500);
285
286 mutex_unlock(&d->i2c_mutex);
287
288 return ret;
289}
290
291static void technisat_usb2_green_led_control(struct work_struct *work)
292{
293 struct technisat_usb2_state *state =
294 container_of(work, struct technisat_usb2_state, green_led_work.work);
295 struct dvb_frontend *fe = state->dev->adapter[0].fe;
296
297 if (state->power_state == 0)
298 goto schedule;
299
300 if (fe != NULL) {
301 enum fe_status status;
302
303 if (fe->ops.read_status(fe, &status) != 0)
304 goto schedule;
305
306 if (status & FE_HAS_LOCK) {
307 u32 ber;
308
309 if (fe->ops.read_ber(fe, &ber) != 0)
310 goto schedule;
311
312 if (ber > 1000)
313 technisat_usb2_set_led(state->dev, 0, LED_BLINK);
314 else
315 technisat_usb2_set_led(state->dev, 0, LED_ON);
316 } else
317 technisat_usb2_set_led(state->dev, 0, LED_OFF);
318 }
319
320schedule:
321 schedule_delayed_work(&state->green_led_work,
322 msecs_to_jiffies(500));
323}
324
325/* method to find out whether the firmware has to be downloaded or not */
326static int technisat_usb2_identify_state(struct usb_device *udev,
327 struct dvb_usb_device_properties *props,
328 struct dvb_usb_device_description **desc, int *cold)
329{
330 int ret;
331 u8 version[3];
332
333 /* first select the interface */
334 if (usb_set_interface(udev, 0, 1) != 0) {
335 err("could not set alternate setting to 0");
336 } else {
337 info("set alternate setting");
338 }
339
340 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
341
342 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
343 GET_VERSION_INFO_VENDOR_REQUEST,
344 USB_TYPE_VENDOR | USB_DIR_IN,
345 0, 0,
346 version, sizeof(version), 500);
347
348 if (ret < 0)
349 *cold = 1;
350 else {
351 info("firmware version: %d.%d", version[1], version[2]);
352 *cold = 0;
353 }
354
355 return 0;
356}
357
358/* power control */
359static int technisat_usb2_power_ctrl(struct dvb_usb_device *d, int level)
360{
361 struct technisat_usb2_state *state = d->priv;
362
363 state->power_state = level;
364
365 if (disable_led_control)
366 return 0;
367
368 /* green led is turned off in any case - will be turned on when tuning */
369 technisat_usb2_set_led(d, 0, LED_OFF);
370 /* red led is turned on all the time */
371 technisat_usb2_set_led(d, 1, LED_ON);
372 return 0;
373}
374
375/* mac address reading - from the eeprom */
376#if 0
377static void technisat_usb2_eeprom_dump(struct dvb_usb_device *d)
378{
379 u8 reg;
380 u8 b[16];
381 int i,j;
382
383 /* full EEPROM dump */
384 for (j = 0; j < 256 * 4; j += 16) {
385 reg = j;
386 if (technisat_usb2_i2c_access(d->udev, 0x50 + j / 256, &reg, 1, b, 16) != 0)
387 break;
388
389 deb_eeprom("EEPROM: %01x%02x: ", j / 256, reg);
390 for (i = 0; i < 16; i++)
391 deb_eeprom("%02x ", b[i]);
392 deb_eeprom("\n");
393 }
394}
395#endif
396
397static u8 technisat_usb2_calc_lrc(const u8 *b, u16 length)
398{
399 u8 lrc = 0;
400 while (--length)
401 lrc ^= *b++;
402 return lrc;
403}
404
405static int technisat_usb2_eeprom_lrc_read(struct dvb_usb_device *d,
406 u16 offset, u8 *b, u16 length, u8 tries)
407{
408 u8 bo = offset & 0xff;
409 struct i2c_msg msg[] = {
410 {
411 .addr = 0x50 | ((offset >> 8) & 0x3),
412 .buf = &bo,
413 .len = 1
414 }, {
415 .addr = 0x50 | ((offset >> 8) & 0x3),
416 .flags = I2C_M_RD,
417 .buf = b,
418 .len = length
419 }
420 };
421
422 while (tries--) {
423 int status;
424
425 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
426 break;
427
428 status =
429 technisat_usb2_calc_lrc(b, length - 1) == b[length - 1];
430
431 if (status)
432 return 0;
433 }
434
435 return -EREMOTEIO;
436}
437
438#define EEPROM_MAC_START 0x3f8
439#define EEPROM_MAC_TOTAL 8
440static int technisat_usb2_read_mac_address(struct dvb_usb_device *d,
441 u8 mac[])
442{
443 u8 buf[EEPROM_MAC_TOTAL];
444
445 if (technisat_usb2_eeprom_lrc_read(d, EEPROM_MAC_START,
446 buf, EEPROM_MAC_TOTAL, 4) != 0)
447 return -ENODEV;
448
449 memcpy(mac, buf, 6);
450 return 0;
451}
452
453/* frontend attach */
454static int technisat_usb2_set_voltage(struct dvb_frontend *fe,
455 fe_sec_voltage_t voltage)
456{
457 int i;
458 u8 gpio[3] = { 0 }; /* 0 = 2, 1 = 3, 2 = 4 */
459
460 gpio[2] = 1; /* high - voltage ? */
461
462 switch (voltage) {
463 case SEC_VOLTAGE_13:
464 gpio[0] = 1;
465 break;
466 case SEC_VOLTAGE_18:
467 gpio[0] = 1;
468 gpio[1] = 1;
469 break;
470 default:
471 case SEC_VOLTAGE_OFF:
472 break;
473 }
474
475 for (i = 0; i < 3; i++)
476 if (stv090x_set_gpio(fe, i+2, 0, gpio[i], 0) != 0)
477 return -EREMOTEIO;
478 return 0;
479}
480
481static struct stv090x_config technisat_usb2_stv090x_config = {
482 .device = STV0903,
483 .demod_mode = STV090x_SINGLE,
484 .clk_mode = STV090x_CLK_EXT,
485
486 .xtal = 8000000,
487 .address = 0x68,
488
489 .ts1_mode = STV090x_TSMODE_DVBCI,
490 .ts1_clk = 13400000,
491 .ts1_tei = 1,
492
493 .repeater_level = STV090x_RPTLEVEL_64,
494
495 .tuner_bbgain = 6,
496};
497
498static struct stv6110x_config technisat_usb2_stv6110x_config = {
499 .addr = 0x60,
500 .refclk = 16000000,
501 .clk_div = 2,
502};
503
504static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
505{
506 struct usb_device *udev = a->dev->udev;
507 int ret;
508
509 a->fe = dvb_attach(stv090x_attach, &technisat_usb2_stv090x_config,
510 &a->dev->i2c_adap, STV090x_DEMODULATOR_0);
511
512 if (a->fe) {
513 struct stv6110x_devctl *ctl;
514
515 ctl = dvb_attach(stv6110x_attach,
516 a->fe,
517 &technisat_usb2_stv6110x_config,
518 &a->dev->i2c_adap);
519
520 if (ctl) {
521 technisat_usb2_stv090x_config.tuner_init = ctl->tuner_init;
522 technisat_usb2_stv090x_config.tuner_sleep = ctl->tuner_sleep;
523 technisat_usb2_stv090x_config.tuner_set_mode = ctl->tuner_set_mode;
524 technisat_usb2_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
525 technisat_usb2_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
526 technisat_usb2_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
527 technisat_usb2_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
528 technisat_usb2_stv090x_config.tuner_set_bbgain = ctl->tuner_set_bbgain;
529 technisat_usb2_stv090x_config.tuner_get_bbgain = ctl->tuner_get_bbgain;
530 technisat_usb2_stv090x_config.tuner_set_refclk = ctl->tuner_set_refclk;
531 technisat_usb2_stv090x_config.tuner_get_status = ctl->tuner_get_status;
532
533 /* call the init function once to initialize
534 tuner's clock output divider and demod's
535 master clock */
536 if (a->fe->ops.init)
537 a->fe->ops.init(a->fe);
538
539 if (mutex_lock_interruptible(&a->dev->i2c_mutex) < 0)
540 return -EAGAIN;
541
542 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
543 SET_IFCLK_TO_EXTERNAL_TSCLK_VENDOR_REQUEST,
544 USB_TYPE_VENDOR | USB_DIR_OUT,
545 0, 0,
546 NULL, 0, 500);
547 mutex_unlock(&a->dev->i2c_mutex);
548
549 if (ret != 0)
550 err("could not set IF_CLK to external");
551
552 a->fe->ops.set_voltage = technisat_usb2_set_voltage;
553
554 /* if everything was successful assign a nice name to the frontend */
555 strlcpy(a->fe->ops.info.name, a->dev->desc->name,
556 sizeof(a->fe->ops.info.name));
557 } else {
558 dvb_frontend_detach(a->fe);
559 a->fe = NULL;
560 }
561 }
562
563 technisat_usb2_set_led_timer(a->dev, 1, 1);
564
565 return a->fe == NULL ? -ENODEV : 0;
566}
567
568/* Remote control */
569
570/* the device is giving providing raw IR-signals to the host mapping
571 * it only to one remote control is just the default implementation
572 */
573#define NOMINAL_IR_BIT_TRANSITION_TIME_US 889
574#define NOMINAL_IR_BIT_TIME_US (2 * NOMINAL_IR_BIT_TRANSITION_TIME_US)
575
576#define FIRMWARE_CLOCK_TICK 83333
577#define FIRMWARE_CLOCK_DIVISOR 256
578
579#define IR_PERCENT_TOLERANCE 15
580
581#define NOMINAL_IR_BIT_TRANSITION_TICKS ((NOMINAL_IR_BIT_TRANSITION_TIME_US * 1000 * 1000) / FIRMWARE_CLOCK_TICK)
582#define NOMINAL_IR_BIT_TRANSITION_TICK_COUNT (NOMINAL_IR_BIT_TRANSITION_TICKS / FIRMWARE_CLOCK_DIVISOR)
583
584#define NOMINAL_IR_BIT_TIME_TICKS ((NOMINAL_IR_BIT_TIME_US * 1000 * 1000) / FIRMWARE_CLOCK_TICK)
585#define NOMINAL_IR_BIT_TIME_TICK_COUNT (NOMINAL_IR_BIT_TIME_TICKS / FIRMWARE_CLOCK_DIVISOR)
586
587#define MINIMUM_IR_BIT_TRANSITION_TICK_COUNT (NOMINAL_IR_BIT_TRANSITION_TICK_COUNT - ((NOMINAL_IR_BIT_TRANSITION_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
588#define MAXIMUM_IR_BIT_TRANSITION_TICK_COUNT (NOMINAL_IR_BIT_TRANSITION_TICK_COUNT + ((NOMINAL_IR_BIT_TRANSITION_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
589
590#define MINIMUM_IR_BIT_TIME_TICK_COUNT (NOMINAL_IR_BIT_TIME_TICK_COUNT - ((NOMINAL_IR_BIT_TIME_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
591#define MAXIMUM_IR_BIT_TIME_TICK_COUNT (NOMINAL_IR_BIT_TIME_TICK_COUNT + ((NOMINAL_IR_BIT_TIME_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
592
593static int technisat_usb2_get_ir(struct dvb_usb_device *d)
594{
595 u8 buf[62], *b;
596 int ret;
597 struct ir_raw_event ev;
598
599 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
600 buf[1] = 0x08;
601 buf[2] = 0x8f;
602 buf[3] = MINIMUM_IR_BIT_TRANSITION_TICK_COUNT;
603 buf[4] = MAXIMUM_IR_BIT_TIME_TICK_COUNT;
604
605 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
606 return -EAGAIN;
607 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
608 GET_IR_DATA_VENDOR_REQUEST,
609 USB_TYPE_VENDOR | USB_DIR_OUT,
610 0, 0,
611 buf, 5, 500);
612 if (ret < 0)
613 goto unlock;
614
615 buf[1] = 0;
616 buf[2] = 0;
617 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
618 GET_IR_DATA_VENDOR_REQUEST,
619 USB_TYPE_VENDOR | USB_DIR_IN,
620 0x8080, 0,
621 buf, sizeof(buf), 500);
622
623unlock:
624 mutex_unlock(&d->i2c_mutex);
625
626 if (ret < 0)
627 return ret;
628
629 if (ret == 1)
630 return 0; /* no key pressed */
631
632 /* decoding */
633 b = buf+1;
634
635#if 0
636 deb_rc("RC: %d ", ret);
637 debug_dump(b, ret, deb_rc);
638#endif
639
640 ev.pulse = 0;
641 while (1) {
642 ev.pulse = !ev.pulse;
643 ev.duration = (*b * FIRMWARE_CLOCK_DIVISOR * FIRMWARE_CLOCK_TICK) / 1000;
644 ir_raw_event_store(d->rc_dev, &ev);
645
646 b++;
647 if (*b == 0xff) {
648 ev.pulse = 0;
649 ev.duration = 888888*2;
650 ir_raw_event_store(d->rc_dev, &ev);
651 break;
652 }
653 }
654
655 ir_raw_event_handle(d->rc_dev);
656
657 return 1;
658}
659
660static int technisat_usb2_rc_query(struct dvb_usb_device *d)
661{
662 int ret = technisat_usb2_get_ir(d);
663
664 if (ret < 0)
665 return ret;
666
667 if (ret == 0)
668 return 0;
669
670 if (!disable_led_control)
671 technisat_usb2_set_led(d, 1, LED_BLINK);
672
673 return 0;
674}
675
676/* DVB-USB and USB stuff follows */
677static struct usb_device_id technisat_usb2_id_table[] = {
678 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_DVB_S2) },
679 { 0 } /* Terminating entry */
680};
681
682/* device description */
683static struct dvb_usb_device_properties technisat_usb2_devices = {
684 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
685
686 .usb_ctrl = CYPRESS_FX2,
687
688 .identify_state = technisat_usb2_identify_state,
689 .firmware = "dvb-usb-SkyStar_USB_HD_FW_v17_63.HEX.fw",
690
691 .size_of_priv = sizeof(struct technisat_usb2_state),
692
693 .i2c_algo = &technisat_usb2_i2c_algo,
694
695 .power_ctrl = technisat_usb2_power_ctrl,
696 .read_mac_address = technisat_usb2_read_mac_address,
697
698 .num_adapters = 1,
699 .adapter = {
700 {
701 .frontend_attach = technisat_usb2_frontend_attach,
702
703 .stream = {
704 .type = USB_ISOC,
705 .count = 8,
706 .endpoint = 0x2,
707 .u = {
708 .isoc = {
709 .framesperurb = 32,
710 .framesize = 2048,
711 .interval = 3,
712 }
713 }
714 },
715
716 .size_of_priv = 0,
717 },
718 },
719
720 .num_device_descs = 1,
721 .devices = {
722 { "Technisat SkyStar USB HD (DVB-S/S2)",
723 { &technisat_usb2_id_table[0], NULL },
724 { NULL },
725 },
726 },
727
728 .rc.core = {
729 .rc_interval = 100,
730 .rc_codes = RC_MAP_TECHNISAT_USB2,
731 .module_name = "technisat-usb2",
732 .rc_query = technisat_usb2_rc_query,
733 .allowed_protos = RC_TYPE_ALL,
734 .driver_type = RC_DRIVER_IR_RAW,
735 }
736};
737
738static int technisat_usb2_probe(struct usb_interface *intf,
739 const struct usb_device_id *id)
740{
741 struct dvb_usb_device *dev;
742
743 if (dvb_usb_device_init(intf, &technisat_usb2_devices, THIS_MODULE,
744 &dev, adapter_nr) != 0)
745 return -ENODEV;
746
747 if (dev) {
748 struct technisat_usb2_state *state = dev->priv;
749 state->dev = dev;
750
751 if (!disable_led_control) {
752 INIT_DELAYED_WORK(&state->green_led_work,
753 technisat_usb2_green_led_control);
754 schedule_delayed_work(&state->green_led_work,
755 msecs_to_jiffies(500));
756 }
757 }
758
759 return 0;
760}
761
762static void technisat_usb2_disconnect(struct usb_interface *intf)
763{
764 struct dvb_usb_device *dev = usb_get_intfdata(intf);
765
766 /* work and stuff was only created when the device is is hot-state */
767 if (dev != NULL) {
768 struct technisat_usb2_state *state = dev->priv;
769 if (state != NULL) {
770 cancel_rearming_delayed_work(&state->green_led_work);
771 flush_scheduled_work();
772 }
773 }
774
775 dvb_usb_device_exit(intf);
776}
777
778static struct usb_driver technisat_usb2_driver = {
779 .name = "dvb_usb_technisat_usb2",
780 .probe = technisat_usb2_probe,
781 .disconnect = technisat_usb2_disconnect,
782 .id_table = technisat_usb2_id_table,
783};
784
785/* module stuff */
786static int __init technisat_usb2_module_init(void)
787{
788 int result = usb_register(&technisat_usb2_driver);
789 if (result) {
790 err("usb_register failed. Code %d", result);
791 return result;
792 }
793
794 return 0;
795}
796
797static void __exit technisat_usb2_module_exit(void)
798{
799 usb_deregister(&technisat_usb2_driver);
800}
801
802module_init(technisat_usb2_module_init);
803module_exit(technisat_usb2_module_exit);
804
805MODULE_AUTHOR("Patrick Boettcher <pboettcher@kernellabs.com>");
806MODULE_DESCRIPTION("Driver for Technisat DVB-S/S2 USB 2.0 device");
807MODULE_VERSION("1.0");
808MODULE_LICENSE("GPL");