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 Free
5 * Software Foundation, version 2.
7 * see Documentation/dvb/README.dvb-usb for more information
15 int dvb_usb_gl861_debug
;
16 module_param_named(debug
,dvb_usb_gl861_debug
, int, 0644);
17 MODULE_PARM_DESC(debug
, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS
);
19 static int gl861_i2c_msg(struct dvb_usb_device
*d
, u8 addr
,
20 u8
*wbuf
, u16 wlen
, u8
*rbuf
, u16 rlen
)
23 u16 value
= addr
<< 8;
24 int wo
= (rbuf
== NULL
|| rlen
== 0); /* write-only */
28 req
= GL861_REQ_I2C_WRITE
;
31 req
= GL861_REQ_I2C_READ
;
41 value
= value
+ wbuf
[1];
44 warn("wlen = %x, aborting.", wlen
);
48 return usb_control_msg(d
->udev
, usb_rcvctrlpipe(d
->udev
, 0), req
, type
,
49 value
, index
, rbuf
, rlen
, 2000);
53 static int gl861_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
56 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
59 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
65 for (i
= 0; i
< num
; i
++) {
66 /* write/read request */
67 if (i
+1 < num
&& (msg
[i
+1].flags
& I2C_M_RD
)) {
68 if (gl861_i2c_msg(d
, msg
[i
].addr
, msg
[i
].buf
,
69 msg
[i
].len
, msg
[i
+1].buf
, msg
[i
+1].len
) < 0)
73 if (gl861_i2c_msg(d
, msg
[i
].addr
, msg
[i
].buf
,
74 msg
[i
].len
, NULL
, 0) < 0)
78 mutex_unlock(&d
->i2c_mutex
);
82 static u32
gl861_i2c_func(struct i2c_adapter
*adapter
)
87 static struct i2c_algorithm gl861_i2c_algo
= {
88 .master_xfer
= gl861_i2c_xfer
,
89 .functionality
= gl861_i2c_func
,
92 /* Callbacks for DVB USB */
93 static int gl861_identify_state(struct usb_device
*udev
,
94 struct dvb_usb_device_properties
*props
,
95 struct dvb_usb_device_description
**desc
,
103 static struct zl10353_config gl861_zl10353_config
= {
104 .demod_address
= 0x1e,
109 static int gl861_frontend_attach(struct dvb_usb_adapter
*adap
)
111 if ((adap
->fe
= dvb_attach(zl10353_attach
, &gl861_zl10353_config
,
112 &adap
->dev
->i2c_adap
)) != NULL
) {
119 static struct qt1010_config gl861_qt1010_config
= {
123 static int gl861_tuner_attach(struct dvb_usb_adapter
*adap
)
125 /* TODO FIXME; probably I2C gate.
126 QT1010 tuner does not respond before we write 0x1a to ZL10353 demodulator
127 register 0x62. This ought to be done somewhere in demodulator initialization.
128 This solution is temporary hack. */
129 u8 buf
[2] = { 0x62, 0x1a };
130 struct i2c_msg msg
= {
131 .addr
= gl861_zl10353_config
.demod_address
, .flags
= 0, .buf
= buf
, .len
= 2
133 if (i2c_transfer(&adap
->dev
->i2c_adap
, &msg
, 1) != 1) {
134 printk(KERN_WARNING
"gl861 tuner attach failed\n");
137 return dvb_attach(qt1010_attach
,
138 adap
->fe
, &adap
->dev
->i2c_adap
,
139 &gl861_qt1010_config
) == NULL
? -ENODEV
: 0;
142 /* DVB USB Driver stuff */
143 static struct dvb_usb_device_properties gl861_properties
;
145 static int gl861_probe(struct usb_interface
*intf
,
146 const struct usb_device_id
*id
)
148 struct dvb_usb_device
*d
;
149 struct usb_host_interface
*alt
;
152 if (intf
->num_altsetting
< 2)
155 if ((ret
= dvb_usb_device_init(intf
, &gl861_properties
, THIS_MODULE
, &d
)) == 0) {
156 alt
= usb_altnum_to_altsetting(intf
, 0);
159 deb_rc("not alt found!\n");
163 ret
= usb_set_interface(d
->udev
, alt
->desc
.bInterfaceNumber
,
164 alt
->desc
.bAlternateSetting
);
170 static struct usb_device_id gl861_table
[] = {
171 { USB_DEVICE(USB_VID_MSI
, USB_PID_MSI_MEGASKY580_55801
) },
172 { } /* Terminating entry */
174 MODULE_DEVICE_TABLE (usb
, gl861_table
);
176 static struct dvb_usb_device_properties gl861_properties
= {
177 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
178 .usb_ctrl
= DEVICE_SPECIFIC
,
182 .identify_state
= gl861_identify_state
,
186 .frontend_attach
= gl861_frontend_attach
,
187 .tuner_attach
= gl861_tuner_attach
,
200 .i2c_algo
= &gl861_i2c_algo
,
202 .num_device_descs
= 1,
204 { "MSI Mega Sky 55801 DVB-T USB2.0",
205 { &gl861_table
[0], NULL
},
211 static struct usb_driver gl861_driver
= {
212 .name
= "dvb_usb_gl861",
213 .probe
= gl861_probe
,
214 .disconnect
= dvb_usb_device_exit
,
215 .id_table
= gl861_table
,
219 static int __init
gl861_module_init(void)
223 if ((ret
= usb_register(&gl861_driver
))) {
224 err("usb_register failed. Error number %d", ret
);
231 static void __exit
gl861_module_exit(void)
233 /* deregister this driver from the USB subsystem */
234 usb_deregister(&gl861_driver
);
237 module_init (gl861_module_init
);
238 module_exit (gl861_module_exit
);
240 MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
241 MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
242 MODULE_VERSION("0.1");
243 MODULE_LICENSE("GPL");