1 /* DVB USB compliant linux driver for GL861 USB2.0 devices.
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation, version 2.
7 * see Documentation/dvb/README.dvb-usb for more information
14 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
16 static int gl861_i2c_msg(struct dvb_usb_device
*d
, u8 addr
,
17 u8
*wbuf
, u16 wlen
, u8
*rbuf
, u16 rlen
)
20 u16 value
= addr
<< (8 + 1);
21 int wo
= (rbuf
== NULL
|| rlen
== 0); /* write-only */
25 req
= GL861_REQ_I2C_WRITE
;
28 req
= GL861_REQ_I2C_READ
;
38 value
= value
+ wbuf
[1];
41 pr_err("%s: wlen=%d, aborting\n", KBUILD_MODNAME
, wlen
);
45 msleep(1); /* avoid I2C errors */
47 return usb_control_msg(d
->udev
, usb_rcvctrlpipe(d
->udev
, 0), req
, type
,
48 value
, index
, rbuf
, rlen
, 2000);
52 static int gl861_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
55 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
61 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
64 for (i
= 0; i
< num
; i
++) {
65 /* write/read request */
66 if (i
+1 < num
&& (msg
[i
+1].flags
& I2C_M_RD
)) {
67 if (gl861_i2c_msg(d
, msg
[i
].addr
, msg
[i
].buf
,
68 msg
[i
].len
, msg
[i
+1].buf
, msg
[i
+1].len
) < 0)
72 if (gl861_i2c_msg(d
, msg
[i
].addr
, msg
[i
].buf
,
73 msg
[i
].len
, NULL
, 0) < 0)
77 mutex_unlock(&d
->i2c_mutex
);
81 static u32
gl861_i2c_func(struct i2c_adapter
*adapter
)
86 static struct i2c_algorithm gl861_i2c_algo
= {
87 .master_xfer
= gl861_i2c_xfer
,
88 .functionality
= gl861_i2c_func
,
91 /* Callbacks for DVB USB */
92 static struct zl10353_config gl861_zl10353_config
= {
93 .demod_address
= 0x0f,
98 static int gl861_frontend_attach(struct dvb_usb_adapter
*adap
)
101 adap
->fe
[0] = dvb_attach(zl10353_attach
, &gl861_zl10353_config
,
102 &adap_to_d(adap
)->i2c_adap
);
103 if (adap
->fe
[0] == NULL
)
109 static struct qt1010_config gl861_qt1010_config
= {
113 static int gl861_tuner_attach(struct dvb_usb_adapter
*adap
)
115 return dvb_attach(qt1010_attach
,
116 adap
->fe
[0], &adap_to_d(adap
)->i2c_adap
,
117 &gl861_qt1010_config
) == NULL
? -ENODEV
: 0;
120 static int gl861_init(struct dvb_usb_device
*d
)
123 * There is 2 interfaces. Interface 0 is for TV and interface 1 is
124 * for HID remote controller. Interface 0 has 2 alternate settings.
125 * For some reason we need to set interface explicitly, defaulted
126 * as alternate setting 1?
128 return usb_set_interface(d
->udev
, 0, 0);
131 /* DVB USB Driver stuff */
132 static struct dvb_usb_device_properties gl861_props
= {
133 .driver_name
= KBUILD_MODNAME
,
134 .owner
= THIS_MODULE
,
135 .adapter_nr
= adapter_nr
,
137 .i2c_algo
= &gl861_i2c_algo
,
138 .frontend_attach
= gl861_frontend_attach
,
139 .tuner_attach
= gl861_tuner_attach
,
145 .stream
= DVB_USB_STREAM_BULK(0x81, 7, 512),
150 static const struct usb_device_id gl861_id_table
[] = {
151 { DVB_USB_DEVICE(USB_VID_MSI
, USB_PID_MSI_MEGASKY580_55801
,
152 &gl861_props
, "MSI Mega Sky 55801 DVB-T USB2.0", NULL
) },
153 { DVB_USB_DEVICE(USB_VID_ALINK
, USB_VID_ALINK_DTU
,
154 &gl861_props
, "A-LINK DTU DVB-T USB2.0", NULL
) },
157 MODULE_DEVICE_TABLE(usb
, gl861_id_table
);
159 static struct usb_driver gl861_usb_driver
= {
160 .name
= KBUILD_MODNAME
,
161 .id_table
= gl861_id_table
,
162 .probe
= dvb_usbv2_probe
,
163 .disconnect
= dvb_usbv2_disconnect
,
164 .suspend
= dvb_usbv2_suspend
,
165 .resume
= dvb_usbv2_resume
,
170 module_usb_driver(gl861_usb_driver
);
172 MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
173 MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
174 MODULE_VERSION("0.1");
175 MODULE_LICENSE("GPL");