blob: 2e8c3afe4ec4f2864d0dd34c3db36ff3fb2cd331 [file] [log] [blame]
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001/*
Ruslan Pisarevd00586452010-10-20 06:35:54 -03002 * tm6000-cards.c - driver for TM5600/TM6000/TM6010 USB video capture devices
3 *
4 * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
5 *
6 * 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 * the Free Software Foundation version 2
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030018 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/delay.h>
24#include <linux/i2c.h>
25#include <linux/usb.h>
Tejun Heo4ef09882010-03-30 02:52:33 +090026#include <linux/slab.h>
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030027#include <media/v4l2-common.h>
28#include <media/tuner.h>
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -030029#include <media/tvaudio.h>
30#include <media/i2c-addr.h>
Stefan Ringeld064f962010-06-20 17:16:52 -030031#include <media/rc-map.h>
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030032
33#include "tm6000.h"
Mauro Carvalho Chehabc85cba32007-07-19 11:09:58 -030034#include "tm6000-regs.h"
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -030035#include "tuner-xc2028.h"
Stefan Ringel7dcc51b2010-02-03 18:48:24 -030036#include "xc5000.h"
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030037
Michel Ludwig0ec4acc2007-06-27 17:01:50 -030038#define TM6000_BOARD_UNKNOWN 0
39#define TM5600_BOARD_GENERIC 1
40#define TM6000_BOARD_GENERIC 2
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -030041#define TM6010_BOARD_GENERIC 3
42#define TM5600_BOARD_10MOONS_UT821 4
43#define TM5600_BOARD_10MOONS_UT330 5
44#define TM6000_BOARD_ADSTECH_DUAL_TV 6
45#define TM6000_BOARD_FREECOM_AND_SIMILAR 7
46#define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 8
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -030047#define TM6010_BOARD_HAUPPAUGE_900H 9
Mauro Carvalho Chehab9d3aeb52010-02-08 08:48:22 -020048#define TM6010_BOARD_BEHOLD_WANDER 10
49#define TM6010_BOARD_BEHOLD_VOYAGER 11
Mauro Carvalho Chehab04574a62010-02-08 08:50:02 -020050#define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE 12
Stefan Ringel8b0d2a02010-03-10 14:57:57 -030051#define TM6010_BOARD_TWINHAN_TU501 13
Dmitri Belimov1f65dd32011-02-02 12:15:52 -030052#define TM6010_BOARD_BEHOLD_WANDER_LITE 14
53#define TM6010_BOARD_BEHOLD_VOYAGER_LITE 15
Holger Nelson6ca00042011-02-03 01:59:29 -030054#define TM5600_BOARD_TERRATEC_GRABSTER 16
Michel Ludwig0ec4acc2007-06-27 17:01:50 -030055
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -030056#define is_generic(model) ((model == TM6000_BOARD_UNKNOWN) || \
57 (model == TM5600_BOARD_GENERIC) || \
58 (model == TM6000_BOARD_GENERIC) || \
59 (model == TM6010_BOARD_GENERIC))
60
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030061#define TM6000_MAXBOARDS 16
62static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
63
64module_param_array(card, int, NULL, 0444);
65
Mauro Carvalho Chehab7f9b1412007-10-01 06:45:22 -030066static unsigned long tm6000_devused;
67
Mauro Carvalho Chehabc85cba32007-07-19 11:09:58 -030068
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030069struct tm6000_board {
70 char *name;
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -030071 char eename[16]; /* EEPROM name */
72 unsigned eename_size; /* size of EEPROM name */
73 unsigned eename_pos; /* Position where it appears at ROM */
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030074
75 struct tm6000_capabilities caps;
76
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -030077 enum tm6000_devtype type; /* variant of the chipset */
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030078 int tuner_type; /* type of the tuner */
79 int tuner_addr; /* tuner address */
Michel Ludwig95a83822007-07-24 08:06:45 -030080 int demod_addr; /* demodulator address */
Stefan Ringel32a22322010-03-29 13:51:10 -030081
82 struct tm6000_gpio gpio;
Stefan Ringeld064f962010-06-20 17:16:52 -030083
Stefan Ringelfb7ef982011-05-09 16:53:51 -030084 struct tm6000_input vinput[3];
85 struct tm6000_input rinput;
Stefan Ringel2fbc9472011-05-09 16:53:54 -030086
Stefan Ringeld064f962010-06-20 17:16:52 -030087 char *ir_codes;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030088};
89
Thierry Reding3d1a51d2011-08-04 04:14:01 -030090static struct tm6000_board tm6000_boards[] = {
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030091 [TM6000_BOARD_UNKNOWN] = {
92 .name = "Unknown tm6000 video grabber",
93 .caps = {
Stefan Ringel2fbc9472011-05-09 16:53:54 -030094 .has_tuner = 1,
95 .has_eeprom = 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -030096 },
Stefan Ringel32a22322010-03-29 13:51:10 -030097 .gpio = {
98 .tuner_reset = TM6000_GPIO_1,
99 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300100 .vinput = { {
101 .type = TM6000_INPUT_TV,
102 .vmux = TM6000_VMUX_VIDEO_B,
103 .amux = TM6000_AMUX_ADC1,
104 }, {
105 .type = TM6000_INPUT_COMPOSITE1,
106 .vmux = TM6000_VMUX_VIDEO_A,
107 .amux = TM6000_AMUX_ADC2,
108 }, {
109 .type = TM6000_INPUT_SVIDEO,
110 .vmux = TM6000_VMUX_VIDEO_AB,
111 .amux = TM6000_AMUX_ADC2,
112 },
113 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300114 },
115 [TM5600_BOARD_GENERIC] = {
116 .name = "Generic tm5600 board",
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300117 .type = TM5600,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300118 .tuner_type = TUNER_XC2028,
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300119 .tuner_addr = 0xc2 >> 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300120 .caps = {
121 .has_tuner = 1,
Stefan Ringel2fbc9472011-05-09 16:53:54 -0300122 .has_eeprom = 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300123 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300124 .gpio = {
125 .tuner_reset = TM6000_GPIO_1,
126 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300127 .vinput = { {
128 .type = TM6000_INPUT_TV,
129 .vmux = TM6000_VMUX_VIDEO_B,
130 .amux = TM6000_AMUX_ADC1,
131 }, {
132 .type = TM6000_INPUT_COMPOSITE1,
133 .vmux = TM6000_VMUX_VIDEO_A,
134 .amux = TM6000_AMUX_ADC2,
135 }, {
136 .type = TM6000_INPUT_SVIDEO,
137 .vmux = TM6000_VMUX_VIDEO_AB,
138 .amux = TM6000_AMUX_ADC2,
139 },
140 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300141 },
142 [TM6000_BOARD_GENERIC] = {
143 .name = "Generic tm6000 board",
144 .tuner_type = TUNER_XC2028,
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300145 .tuner_addr = 0xc2 >> 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300146 .caps = {
147 .has_tuner = 1,
Stefan Ringel2fbc9472011-05-09 16:53:54 -0300148 .has_eeprom = 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300149 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300150 .gpio = {
151 .tuner_reset = TM6000_GPIO_1,
152 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300153 .vinput = { {
154 .type = TM6000_INPUT_TV,
155 .vmux = TM6000_VMUX_VIDEO_B,
156 .amux = TM6000_AMUX_ADC1,
157 }, {
158 .type = TM6000_INPUT_COMPOSITE1,
159 .vmux = TM6000_VMUX_VIDEO_A,
160 .amux = TM6000_AMUX_ADC2,
161 }, {
162 .type = TM6000_INPUT_SVIDEO,
163 .vmux = TM6000_VMUX_VIDEO_AB,
164 .amux = TM6000_AMUX_ADC2,
165 },
166 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300167 },
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300168 [TM6010_BOARD_GENERIC] = {
169 .name = "Generic tm6010 board",
170 .type = TM6010,
171 .tuner_type = TUNER_XC2028,
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300172 .tuner_addr = 0xc2 >> 1,
Stefan Ringelb57f4322010-03-29 13:51:12 -0300173 .demod_addr = 0x1e >> 1,
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300174 .caps = {
175 .has_tuner = 1,
176 .has_dvb = 1,
Stefan Ringelb57f4322010-03-29 13:51:12 -0300177 .has_zl10353 = 1,
178 .has_eeprom = 1,
179 .has_remote = 1,
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300180 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300181 .gpio = {
Stefan Ringelb57f4322010-03-29 13:51:12 -0300182 .tuner_reset = TM6010_GPIO_2,
183 .tuner_on = TM6010_GPIO_3,
184 .demod_reset = TM6010_GPIO_1,
185 .demod_on = TM6010_GPIO_4,
186 .power_led = TM6010_GPIO_7,
187 .dvb_led = TM6010_GPIO_5,
188 .ir = TM6010_GPIO_0,
Stefan Ringel32a22322010-03-29 13:51:10 -0300189 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300190 .vinput = { {
191 .type = TM6000_INPUT_TV,
192 .vmux = TM6000_VMUX_VIDEO_B,
193 .amux = TM6000_AMUX_SIF1,
194 }, {
195 .type = TM6000_INPUT_COMPOSITE1,
196 .vmux = TM6000_VMUX_VIDEO_A,
197 .amux = TM6000_AMUX_ADC2,
198 }, {
199 .type = TM6000_INPUT_SVIDEO,
200 .vmux = TM6000_VMUX_VIDEO_AB,
201 .amux = TM6000_AMUX_ADC2,
202 },
203 },
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300204 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300205 [TM5600_BOARD_10MOONS_UT821] = {
206 .name = "10Moons UT 821",
207 .tuner_type = TUNER_XC2028,
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -0300208 .eename = { '1', '0', 'M', 'O', 'O', 'N', 'S', '5', '6', '0', '0', 0xff, 0x45, 0x5b},
209 .eename_size = 14,
210 .eename_pos = 0x14,
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300211 .type = TM5600,
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300212 .tuner_addr = 0xc2 >> 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300213 .caps = {
214 .has_tuner = 1,
215 .has_eeprom = 1,
216 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300217 .gpio = {
218 .tuner_reset = TM6000_GPIO_1,
219 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300220 .vinput = { {
221 .type = TM6000_INPUT_TV,
222 .vmux = TM6000_VMUX_VIDEO_B,
223 .amux = TM6000_AMUX_ADC1,
224 }, {
225 .type = TM6000_INPUT_COMPOSITE1,
226 .vmux = TM6000_VMUX_VIDEO_A,
227 .amux = TM6000_AMUX_ADC2,
228 }, {
229 .type = TM6000_INPUT_SVIDEO,
230 .vmux = TM6000_VMUX_VIDEO_AB,
231 .amux = TM6000_AMUX_ADC2,
232 },
233 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300234 },
Michel Ludwig95a83822007-07-24 08:06:45 -0300235 [TM5600_BOARD_10MOONS_UT330] = {
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300236 .name = "10Moons UT 330",
Michel Ludwig95a83822007-07-24 08:06:45 -0300237 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300238 .tuner_addr = 0xc8 >> 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300239 .caps = {
240 .has_tuner = 1,
Michel Ludwig95a83822007-07-24 08:06:45 -0300241 .has_dvb = 0,
242 .has_zl10353 = 0,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300243 .has_eeprom = 1,
244 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300245 .vinput = { {
246 .type = TM6000_INPUT_TV,
247 .vmux = TM6000_VMUX_VIDEO_B,
248 .amux = TM6000_AMUX_ADC1,
249 }, {
250 .type = TM6000_INPUT_COMPOSITE1,
251 .vmux = TM6000_VMUX_VIDEO_A,
252 .amux = TM6000_AMUX_ADC2,
253 }, {
254 .type = TM6000_INPUT_SVIDEO,
255 .vmux = TM6000_VMUX_VIDEO_AB,
256 .amux = TM6000_AMUX_ADC2,
257 },
258 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300259 },
260 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
261 .name = "ADSTECH Dual TV USB",
262 .tuner_type = TUNER_XC2028,
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300263 .tuner_addr = 0xc8 >> 1,
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300264 .caps = {
265 .has_tuner = 1,
266 .has_tda9874 = 1,
267 .has_dvb = 1,
268 .has_zl10353 = 1,
269 .has_eeprom = 1,
270 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300271 .vinput = { {
272 .type = TM6000_INPUT_TV,
273 .vmux = TM6000_VMUX_VIDEO_B,
274 .amux = TM6000_AMUX_ADC1,
275 }, {
276 .type = TM6000_INPUT_COMPOSITE1,
277 .vmux = TM6000_VMUX_VIDEO_A,
278 .amux = TM6000_AMUX_ADC2,
279 }, {
280 .type = TM6000_INPUT_SVIDEO,
281 .vmux = TM6000_VMUX_VIDEO_AB,
282 .amux = TM6000_AMUX_ADC2,
283 },
284 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300285 },
Michel Ludwig0ec4acc2007-06-27 17:01:50 -0300286 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
287 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
Michel Ludwig43861362007-09-24 17:01:49 -0300288 .tuner_type = TUNER_XC2028, /* has a XC3028 */
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300289 .tuner_addr = 0xc2 >> 1,
290 .demod_addr = 0x1e >> 1,
Michel Ludwig0ec4acc2007-06-27 17:01:50 -0300291 .caps = {
292 .has_tuner = 1,
293 .has_dvb = 1,
294 .has_zl10353 = 1,
295 .has_eeprom = 0,
Michel Ludwig43861362007-09-24 17:01:49 -0300296 .has_remote = 1,
297 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300298 .gpio = {
299 .tuner_reset = TM6000_GPIO_4,
300 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300301 .vinput = { {
302 .type = TM6000_INPUT_TV,
303 .vmux = TM6000_VMUX_VIDEO_B,
304 .amux = TM6000_AMUX_ADC1,
305 }, {
306 .type = TM6000_INPUT_COMPOSITE1,
307 .vmux = TM6000_VMUX_VIDEO_A,
308 .amux = TM6000_AMUX_ADC2,
309 }, {
310 .type = TM6000_INPUT_SVIDEO,
311 .vmux = TM6000_VMUX_VIDEO_AB,
312 .amux = TM6000_AMUX_ADC2,
313 },
314 },
Michel Ludwig43861362007-09-24 17:01:49 -0300315 },
316 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
317 .name = "ADSTECH Mini Dual TV USB",
318 .tuner_type = TUNER_XC2028, /* has a XC3028 */
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300319 .tuner_addr = 0xc8 >> 1,
320 .demod_addr = 0x1e >> 1,
Michel Ludwig43861362007-09-24 17:01:49 -0300321 .caps = {
322 .has_tuner = 1,
323 .has_dvb = 1,
324 .has_zl10353 = 1,
325 .has_eeprom = 0,
Michel Ludwig0ec4acc2007-06-27 17:01:50 -0300326 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300327 .gpio = {
328 .tuner_reset = TM6000_GPIO_4,
329 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300330 .vinput = { {
331 .type = TM6000_INPUT_TV,
332 .vmux = TM6000_VMUX_VIDEO_B,
333 .amux = TM6000_AMUX_ADC1,
334 }, {
335 .type = TM6000_INPUT_COMPOSITE1,
336 .vmux = TM6000_VMUX_VIDEO_A,
337 .amux = TM6000_AMUX_ADC2,
338 }, {
339 .type = TM6000_INPUT_SVIDEO,
340 .vmux = TM6000_VMUX_VIDEO_AB,
341 .amux = TM6000_AMUX_ADC2,
342 },
343 },
Michel Ludwig0ec4acc2007-06-27 17:01:50 -0300344 },
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300345 [TM6010_BOARD_HAUPPAUGE_900H] = {
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300346 .name = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -0300347 .eename = { 'H', 0, 'V', 0, 'R', 0, '9', 0, '0', 0, '0', 0, 'H', 0 },
348 .eename_size = 14,
349 .eename_pos = 0x42,
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300350 .tuner_type = TUNER_XC2028, /* has a XC3028 */
Mauro Carvalho Chehab1fade8d2009-09-14 23:13:53 -0300351 .tuner_addr = 0xc2 >> 1,
352 .demod_addr = 0x1e >> 1,
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300353 .type = TM6010,
Mauro Carvalho Chehabf9fa9052011-11-30 12:58:51 -0300354 .ir_codes = RC_MAP_HAUPPAUGE,
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300355 .caps = {
356 .has_tuner = 1,
357 .has_dvb = 1,
358 .has_zl10353 = 1,
359 .has_eeprom = 1,
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300360 .has_remote = 1,
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300361 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300362 .gpio = {
363 .tuner_reset = TM6010_GPIO_2,
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300364 .tuner_on = TM6010_GPIO_3,
365 .demod_reset = TM6010_GPIO_1,
366 .demod_on = TM6010_GPIO_4,
367 .power_led = TM6010_GPIO_7,
368 .dvb_led = TM6010_GPIO_5,
369 .ir = TM6010_GPIO_0,
Stefan Ringel32a22322010-03-29 13:51:10 -0300370 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300371 .vinput = { {
372 .type = TM6000_INPUT_TV,
373 .vmux = TM6000_VMUX_VIDEO_B,
374 .amux = TM6000_AMUX_SIF1,
375 }, {
376 .type = TM6000_INPUT_COMPOSITE1,
377 .vmux = TM6000_VMUX_VIDEO_A,
378 .amux = TM6000_AMUX_ADC2,
379 }, {
380 .type = TM6000_INPUT_SVIDEO,
381 .vmux = TM6000_VMUX_VIDEO_AB,
382 .amux = TM6000_AMUX_ADC2,
383 },
384 },
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300385 },
Dmitri Belimov1eefd762009-11-10 01:37:43 -0300386 [TM6010_BOARD_BEHOLD_WANDER] = {
387 .name = "Beholder Wander DVB-T/TV/FM USB2.0",
388 .tuner_type = TUNER_XC5000,
389 .tuner_addr = 0xc2 >> 1,
390 .demod_addr = 0x1e >> 1,
391 .type = TM6010,
392 .caps = {
Dmitri Belimov2aefbc12011-03-17 21:08:55 -0300393 .has_tuner = 1,
394 .has_dvb = 1,
395 .has_zl10353 = 1,
396 .has_eeprom = 1,
397 .has_remote = 1,
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300398 .has_radio = 1,
Dmitri Belimov1eefd762009-11-10 01:37:43 -0300399 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300400 .gpio = {
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300401 .tuner_reset = TM6010_GPIO_0,
402 .demod_reset = TM6010_GPIO_1,
403 .power_led = TM6010_GPIO_6,
Stefan Ringel32a22322010-03-29 13:51:10 -0300404 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300405 .vinput = { {
406 .type = TM6000_INPUT_TV,
407 .vmux = TM6000_VMUX_VIDEO_B,
408 .amux = TM6000_AMUX_SIF1,
409 }, {
410 .type = TM6000_INPUT_COMPOSITE1,
411 .vmux = TM6000_VMUX_VIDEO_A,
412 .amux = TM6000_AMUX_ADC2,
413 }, {
414 .type = TM6000_INPUT_SVIDEO,
415 .vmux = TM6000_VMUX_VIDEO_AB,
416 .amux = TM6000_AMUX_ADC2,
417 },
418 },
419 .rinput = {
420 .type = TM6000_INPUT_RADIO,
421 .amux = TM6000_AMUX_ADC1,
422 },
Dmitri Belimov1eefd762009-11-10 01:37:43 -0300423 },
424 [TM6010_BOARD_BEHOLD_VOYAGER] = {
425 .name = "Beholder Voyager TV/FM USB2.0",
426 .tuner_type = TUNER_XC5000,
427 .tuner_addr = 0xc2 >> 1,
428 .type = TM6010,
429 .caps = {
Dmitri Belimov2aefbc12011-03-17 21:08:55 -0300430 .has_tuner = 1,
431 .has_dvb = 0,
432 .has_zl10353 = 0,
433 .has_eeprom = 1,
434 .has_remote = 1,
Stefan Ringel14169102011-05-09 16:53:49 -0300435 .has_radio = 1,
Dmitri Belimov1eefd762009-11-10 01:37:43 -0300436 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300437 .gpio = {
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300438 .tuner_reset = TM6010_GPIO_0,
439 .power_led = TM6010_GPIO_6,
Stefan Ringel32a22322010-03-29 13:51:10 -0300440 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300441 .vinput = { {
442 .type = TM6000_INPUT_TV,
443 .vmux = TM6000_VMUX_VIDEO_B,
444 .amux = TM6000_AMUX_SIF1,
445 }, {
446 .type = TM6000_INPUT_COMPOSITE1,
447 .vmux = TM6000_VMUX_VIDEO_A,
448 .amux = TM6000_AMUX_ADC2,
449 }, {
450 .type = TM6000_INPUT_SVIDEO,
451 .vmux = TM6000_VMUX_VIDEO_AB,
452 .amux = TM6000_AMUX_ADC2,
453 },
454 },
455 .rinput = {
456 .type = TM6000_INPUT_RADIO,
457 .amux = TM6000_AMUX_ADC1,
458 },
Dmitri Belimov1eefd762009-11-10 01:37:43 -0300459 },
Mauro Carvalho Chehab04574a62010-02-08 08:50:02 -0200460 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300461 .name = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
462 .tuner_type = TUNER_XC2028, /* has a XC3028 */
463 .tuner_addr = 0xc2 >> 1,
464 .demod_addr = 0x1e >> 1,
465 .type = TM6010,
466 .caps = {
467 .has_tuner = 1,
468 .has_dvb = 1,
469 .has_zl10353 = 1,
470 .has_eeprom = 1,
471 .has_remote = 1,
Thierry Redingd6572292011-08-04 04:14:18 -0300472 .has_radio = 1,
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300473 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300474 .gpio = {
475 .tuner_reset = TM6010_GPIO_2,
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300476 .tuner_on = TM6010_GPIO_3,
477 .demod_reset = TM6010_GPIO_1,
478 .demod_on = TM6010_GPIO_4,
479 .power_led = TM6010_GPIO_7,
480 .dvb_led = TM6010_GPIO_5,
481 .ir = TM6010_GPIO_0,
Stefan Ringel32a22322010-03-29 13:51:10 -0300482 },
Stefan Ringeld064f962010-06-20 17:16:52 -0300483 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300484 .vinput = { {
485 .type = TM6000_INPUT_TV,
486 .vmux = TM6000_VMUX_VIDEO_B,
487 .amux = TM6000_AMUX_SIF1,
488 }, {
489 .type = TM6000_INPUT_COMPOSITE1,
490 .vmux = TM6000_VMUX_VIDEO_A,
491 .amux = TM6000_AMUX_ADC2,
492 }, {
493 .type = TM6000_INPUT_SVIDEO,
494 .vmux = TM6000_VMUX_VIDEO_AB,
495 .amux = TM6000_AMUX_ADC2,
496 },
497 },
Thierry Redingd6572292011-08-04 04:14:18 -0300498 .rinput = {
499 .type = TM6000_INPUT_RADIO,
500 .amux = TM6000_AMUX_SIF1,
501 },
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300502 },
Holger Nelson6ca00042011-02-03 01:59:29 -0300503 [TM5600_BOARD_TERRATEC_GRABSTER] = {
504 .name = "Terratec Grabster AV 150/250 MX",
505 .type = TM5600,
506 .tuner_type = TUNER_ABSENT,
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300507 .vinput = { {
508 .type = TM6000_INPUT_TV,
509 .vmux = TM6000_VMUX_VIDEO_B,
510 .amux = TM6000_AMUX_ADC1,
511 }, {
512 .type = TM6000_INPUT_COMPOSITE1,
513 .vmux = TM6000_VMUX_VIDEO_A,
514 .amux = TM6000_AMUX_ADC2,
515 }, {
516 .type = TM6000_INPUT_SVIDEO,
517 .vmux = TM6000_VMUX_VIDEO_AB,
518 .amux = TM6000_AMUX_ADC2,
519 },
520 },
Holger Nelson6ca00042011-02-03 01:59:29 -0300521 },
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300522 [TM6010_BOARD_TWINHAN_TU501] = {
523 .name = "Twinhan TU501(704D1)",
Mauro Carvalho Chehab04574a62010-02-08 08:50:02 -0200524 .tuner_type = TUNER_XC2028, /* has a XC3028 */
525 .tuner_addr = 0xc2 >> 1,
526 .demod_addr = 0x1e >> 1,
527 .type = TM6010,
528 .caps = {
529 .has_tuner = 1,
530 .has_dvb = 1,
531 .has_zl10353 = 1,
532 .has_eeprom = 1,
533 .has_remote = 1,
534 },
Stefan Ringel32a22322010-03-29 13:51:10 -0300535 .gpio = {
536 .tuner_reset = TM6010_GPIO_2,
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300537 .tuner_on = TM6010_GPIO_3,
538 .demod_reset = TM6010_GPIO_1,
539 .demod_on = TM6010_GPIO_4,
540 .power_led = TM6010_GPIO_7,
541 .dvb_led = TM6010_GPIO_5,
542 .ir = TM6010_GPIO_0,
Stefan Ringel32a22322010-03-29 13:51:10 -0300543 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300544 .vinput = { {
545 .type = TM6000_INPUT_TV,
546 .vmux = TM6000_VMUX_VIDEO_B,
547 .amux = TM6000_AMUX_SIF1,
548 }, {
549 .type = TM6000_INPUT_COMPOSITE1,
550 .vmux = TM6000_VMUX_VIDEO_A,
551 .amux = TM6000_AMUX_ADC2,
552 }, {
553 .type = TM6000_INPUT_SVIDEO,
554 .vmux = TM6000_VMUX_VIDEO_AB,
555 .amux = TM6000_AMUX_ADC2,
556 },
557 },
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300558 },
559 [TM6010_BOARD_BEHOLD_WANDER_LITE] = {
560 .name = "Beholder Wander Lite DVB-T/TV/FM USB2.0",
561 .tuner_type = TUNER_XC5000,
562 .tuner_addr = 0xc2 >> 1,
563 .demod_addr = 0x1e >> 1,
564 .type = TM6010,
565 .caps = {
Dmitri Belimov2aefbc12011-03-17 21:08:55 -0300566 .has_tuner = 1,
567 .has_dvb = 1,
568 .has_zl10353 = 1,
569 .has_eeprom = 1,
570 .has_remote = 0,
Stefan Ringel14169102011-05-09 16:53:49 -0300571 .has_radio = 1,
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300572 },
573 .gpio = {
574 .tuner_reset = TM6010_GPIO_0,
575 .demod_reset = TM6010_GPIO_1,
576 .power_led = TM6010_GPIO_6,
577 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300578 .vinput = { {
579 .type = TM6000_INPUT_TV,
580 .vmux = TM6000_VMUX_VIDEO_B,
581 .amux = TM6000_AMUX_SIF1,
582 },
583 },
584 .rinput = {
585 .type = TM6000_INPUT_RADIO,
586 .amux = TM6000_AMUX_ADC1,
587 },
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300588 },
589 [TM6010_BOARD_BEHOLD_VOYAGER_LITE] = {
590 .name = "Beholder Voyager Lite TV/FM USB2.0",
591 .tuner_type = TUNER_XC5000,
592 .tuner_addr = 0xc2 >> 1,
593 .type = TM6010,
594 .caps = {
Dmitri Belimov2aefbc12011-03-17 21:08:55 -0300595 .has_tuner = 1,
596 .has_dvb = 0,
597 .has_zl10353 = 0,
598 .has_eeprom = 1,
599 .has_remote = 0,
Stefan Ringel14169102011-05-09 16:53:49 -0300600 .has_radio = 1,
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300601 },
602 .gpio = {
603 .tuner_reset = TM6010_GPIO_0,
604 .power_led = TM6010_GPIO_6,
605 },
Stefan Ringelfb7ef982011-05-09 16:53:51 -0300606 .vinput = { {
607 .type = TM6000_INPUT_TV,
608 .vmux = TM6000_VMUX_VIDEO_B,
609 .amux = TM6000_AMUX_SIF1,
610 },
611 },
612 .rinput = {
613 .type = TM6000_INPUT_RADIO,
614 .amux = TM6000_AMUX_ADC1,
615 },
Holger Nelson6ca00042011-02-03 01:59:29 -0300616 },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300617};
618
619/* table of devices that work with this driver */
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300620static struct usb_device_id tm6000_id_table[] = {
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -0300621 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_GENERIC },
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300622 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300623 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
Mauro Carvalho Chehabc85cba32007-07-19 11:09:58 -0300624 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
Michel Ludwig43861362007-09-24 17:01:49 -0300625 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300626 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300627 { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
628 { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
629 { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
Dmitri Belimov1eefd762009-11-10 01:37:43 -0300630 { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
631 { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
Mauro Carvalho Chehab04574a62010-02-08 08:50:02 -0200632 { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300633 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
Holger Nelson6ca00042011-02-03 01:59:29 -0300634 { USB_DEVICE(0x0ccd, 0x0079), .driver_info = TM5600_BOARD_TERRATEC_GRABSTER },
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300635 { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
636 { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
637 { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
638 { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300639 { USB_DEVICE(0x6000, 0xdec2), .driver_info = TM6010_BOARD_BEHOLD_WANDER_LITE },
640 { USB_DEVICE(0x6000, 0xdec3), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER_LITE },
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300641 { }
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300642};
Mauro Carvalho Chehab8afc5392011-11-30 13:26:10 -0300643MODULE_DEVICE_TABLE(usb, tm6000_id_table);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300644
Dmitri Belimov641d2112010-12-22 05:57:46 -0300645/* Control power led for show some activity */
646void tm6000_flash_led(struct tm6000_core *dev, u8 state)
647{
648 /* Power LED unconfigured */
649 if (!dev->gpio.power_led)
650 return;
651
652 /* ON Power LED */
653 if (state) {
654 switch (dev->model) {
655 case TM6010_BOARD_HAUPPAUGE_900H:
656 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
657 case TM6010_BOARD_TWINHAN_TU501:
658 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
659 dev->gpio.power_led, 0x00);
660 break;
661 case TM6010_BOARD_BEHOLD_WANDER:
662 case TM6010_BOARD_BEHOLD_VOYAGER:
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300663 case TM6010_BOARD_BEHOLD_WANDER_LITE:
664 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
Dmitri Belimov641d2112010-12-22 05:57:46 -0300665 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
666 dev->gpio.power_led, 0x01);
667 break;
668 }
669 }
670 /* OFF Power LED */
671 else {
672 switch (dev->model) {
673 case TM6010_BOARD_HAUPPAUGE_900H:
674 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
675 case TM6010_BOARD_TWINHAN_TU501:
676 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
677 dev->gpio.power_led, 0x01);
678 break;
679 case TM6010_BOARD_BEHOLD_WANDER:
680 case TM6010_BOARD_BEHOLD_VOYAGER:
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300681 case TM6010_BOARD_BEHOLD_WANDER_LITE:
682 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
Dmitri Belimov641d2112010-12-22 05:57:46 -0300683 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
684 dev->gpio.power_led, 0x00);
685 break;
686 }
687 }
688}
689
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300690/* Tuner callback to provide the proper gpio changes needed for xc5000 */
691int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
692{
693 int rc = 0;
694 struct tm6000_core *dev = ptr;
695
696 if (dev->tuner_type != TUNER_XC5000)
697 return 0;
698
699 switch (command) {
700 case XC5000_TUNER_RESET:
701 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
702 dev->gpio.tuner_reset, 0x01);
703 msleep(15);
704 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
705 dev->gpio.tuner_reset, 0x00);
706 msleep(15);
707 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
708 dev->gpio.tuner_reset, 0x01);
709 break;
710 }
Ruslan Pisarev51a5d392010-10-20 06:36:18 -0300711 return rc;
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300712}
Stefan Ringelcee39262010-05-30 09:19:04 -0300713EXPORT_SYMBOL_GPL(tm6000_xc5000_callback);
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300714
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300715/* Tuner callback to provide the proper gpio changes needed for xc2028 */
716
Stefan Ringele78c8f22010-02-05 19:57:06 -0300717int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300718{
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300719 int rc = 0;
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300720 struct tm6000_core *dev = ptr;
721
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300722 if (dev->tuner_type != TUNER_XC2028)
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300723 return 0;
724
725 switch (command) {
726 case XC2028_RESET_CLK:
Stefan Ringeld064f962010-06-20 17:16:52 -0300727 tm6000_ir_wait(dev, 0);
728
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300729 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300730 0x02, arg);
731 msleep(10);
Dmitri Belimov2a15ac72010-05-18 04:23:29 -0300732 rc = tm6000_i2c_reset(dev, 10);
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300733 break;
734 case XC2028_TUNER_RESET:
735 /* Reset codes during load firmware */
736 switch (arg) {
737 case 0:
Stefan Ringel583c8712010-02-15 14:37:17 -0300738 /* newer tuner can faster reset */
739 switch (dev->model) {
Bee Hock Goh1ebf2c72010-04-25 03:50:57 -0300740 case TM5600_BOARD_10MOONS_UT821:
741 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
742 dev->gpio.tuner_reset, 0x01);
743 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
744 0x300, 0x01);
745 msleep(10);
746 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
747 dev->gpio.tuner_reset, 0x00);
748 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
749 0x300, 0x00);
750 msleep(10);
751 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
752 dev->gpio.tuner_reset, 0x01);
753 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
754 0x300, 0x01);
755 break;
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300756 case TM6010_BOARD_HAUPPAUGE_900H:
Stefan Ringel583c8712010-02-15 14:37:17 -0300757 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300758 case TM6010_BOARD_TWINHAN_TU501:
Stefan Ringel583c8712010-02-15 14:37:17 -0300759 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
Stefan Ringel32a22322010-03-29 13:51:10 -0300760 dev->gpio.tuner_reset, 0x01);
Stefan Ringel583c8712010-02-15 14:37:17 -0300761 msleep(60);
762 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
Stefan Ringel32a22322010-03-29 13:51:10 -0300763 dev->gpio.tuner_reset, 0x00);
Stefan Ringel583c8712010-02-15 14:37:17 -0300764 msleep(75);
765 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
Stefan Ringel32a22322010-03-29 13:51:10 -0300766 dev->gpio.tuner_reset, 0x01);
Stefan Ringel583c8712010-02-15 14:37:17 -0300767 msleep(60);
768 break;
769 default:
770 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
Stefan Ringel32a22322010-03-29 13:51:10 -0300771 dev->gpio.tuner_reset, 0x00);
Stefan Ringel583c8712010-02-15 14:37:17 -0300772 msleep(130);
773 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
Stefan Ringel32a22322010-03-29 13:51:10 -0300774 dev->gpio.tuner_reset, 0x01);
Stefan Ringel583c8712010-02-15 14:37:17 -0300775 msleep(130);
776 break;
777 }
Stefan Ringeld064f962010-06-20 17:16:52 -0300778
779 tm6000_ir_wait(dev, 1);
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300780 break;
781 case 1:
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300782 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300783 0x02, 0x01);
784 msleep(10);
785 break;
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300786 case 2:
Dmitri Belimov2a15ac72010-05-18 04:23:29 -0300787 rc = tm6000_i2c_reset(dev, 100);
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300788 break;
789 }
Thierry Reding9dac9202011-08-04 04:14:03 -0300790 break;
791 case XC2028_I2C_FLUSH:
792 tm6000_set_reg(dev, REQ_50_SET_START, 0, 0);
793 tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0);
794 break;
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300795 }
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300796 return rc;
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300797}
Stefan Ringelcee39262010-05-30 09:19:04 -0300798EXPORT_SYMBOL_GPL(tm6000_tuner_callback);
Mauro Carvalho Chehab64d339d2009-09-14 17:16:32 -0300799
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200800int tm6000_cards_setup(struct tm6000_core *dev)
801{
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200802 /*
803 * Board-specific initialization sequence. Handles all GPIO
804 * initialization sequences that are board-specific.
805 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
806 * Probably, they're all based on some reference device. Due to that,
807 * there's a common routine at the end to handle those GPIO's. Devices
808 * that use different pinups or init sequences can just return at
809 * the board-specific session.
810 */
811 switch (dev->model) {
812 case TM6010_BOARD_HAUPPAUGE_900H:
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300813 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
814 case TM6010_BOARD_TWINHAN_TU501:
Stefan Ringelb57f4322010-03-29 13:51:12 -0300815 case TM6010_BOARD_GENERIC:
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200816 /* Turn xceive 3028 on */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300817 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300818 msleep(15);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300819 /* Turn zarlink zl10353 on */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300820 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300821 msleep(15);
822 /* Reset zarlink zl10353 */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300823 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300824 msleep(50);
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300825 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300826 msleep(15);
827 /* Turn zarlink zl10353 off */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300828 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300829 msleep(15);
830 /* ir ? */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300831 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300832 msleep(15);
833 /* Power led on (blue) */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300834 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300835 msleep(15);
836 /* DVB led off (orange) */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300837 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300838 msleep(15);
839 /* Turn zarlink zl10353 on */
Stefan Ringel2edab1e2010-03-29 13:51:11 -0300840 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
Stefan Ringel439e7c12010-02-15 14:37:18 -0300841 msleep(15);
842 break;
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300843 case TM6010_BOARD_BEHOLD_WANDER:
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300844 case TM6010_BOARD_BEHOLD_WANDER_LITE:
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300845 /* Power led on (blue) */
846 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
847 msleep(15);
848 /* Reset zarlink zl10353 */
849 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
850 msleep(50);
851 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
852 msleep(15);
853 break;
854 case TM6010_BOARD_BEHOLD_VOYAGER:
Dmitri Belimov1f65dd32011-02-02 12:15:52 -0300855 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300856 /* Power led on (blue) */
857 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
858 msleep(15);
859 break;
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200860 default:
861 break;
862 }
863
864 /*
865 * Default initialization. Most of the devices seem to use GPIO1
866 * and GPIO4.on the same way, so, this handles the common sequence
867 * used by most devices.
868 * If a device uses a different sequence or different GPIO pins for
869 * reset, just add the code at the board-specific part
870 */
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200871
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300872 if (dev->gpio.tuner_reset) {
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300873 int rc;
874 int i;
875
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300876 for (i = 0; i < 2; i++) {
877 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
878 dev->gpio.tuner_reset, 0x00);
879 if (rc < 0) {
880 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
881 return rc;
882 }
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200883
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300884 msleep(10); /* Just to be conservative */
885 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
886 dev->gpio.tuner_reset, 0x01);
887 if (rc < 0) {
888 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
889 return rc;
890 }
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200891 }
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300892 } else {
893 printk(KERN_ERR "Tuner reset is not configured\n");
894 return -1;
Mauro Carvalho Chehabe3ee9e52010-02-08 08:43:41 -0200895 }
896
897 msleep(50);
898
899 return 0;
900};
901
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300902static void tm6000_config_tuner(struct tm6000_core *dev)
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -0300903{
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300904 struct tuner_setup tun_setup;
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300905
906 /* Load tuner module */
907 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300908 "tuner", dev->tuner_addr, NULL);
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300909
910 memset(&tun_setup, 0, sizeof(tun_setup));
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300911 tun_setup.type = dev->tuner_type;
912 tun_setup.addr = dev->tuner_addr;
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300913
914 tun_setup.mode_mask = 0;
915 if (dev->caps.has_tuner)
916 tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300917
918 switch (dev->tuner_type) {
919 case TUNER_XC2028:
Stefan Ringelb9eb39d2010-05-10 13:22:50 -0300920 tun_setup.tuner_callback = tm6000_tuner_callback;
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300921 break;
922 case TUNER_XC5000:
923 tun_setup.tuner_callback = tm6000_xc5000_callback;
924 break;
925 }
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300926
927 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -0300928
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300929 switch (dev->tuner_type) {
930 case TUNER_XC2028: {
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300931 struct v4l2_priv_tun_config xc2028_cfg;
932 struct xc2028_ctrl ctl;
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300933
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300934 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300935 memset(&ctl, 0, sizeof(ctl));
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300936
Stefan Ringel58b2f4b2010-02-05 19:57:07 -0300937 ctl.demod = XC3028_FE_ZARLINK456;
Stefan Ringel3d6baf52011-05-09 16:53:56 -0300938
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -0300939 xc2028_cfg.tuner = TUNER_XC2028;
940 xc2028_cfg.priv = &ctl;
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -0300941
Roel Van Nyen9d5164d2010-04-27 18:57:00 -0300942 switch (dev->model) {
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300943 case TM6010_BOARD_HAUPPAUGE_900H:
Mauro Carvalho Chehab04574a62010-02-08 08:50:02 -0200944 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
Stefan Ringel8b0d2a02010-03-10 14:57:57 -0300945 case TM6010_BOARD_TWINHAN_TU501:
matthieu castet3874cd72011-12-16 14:15:07 -0300946 ctl.max_len = 80;
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300947 ctl.fname = "xc3028L-v36.fw";
948 break;
949 default:
950 if (dev->dev_type == TM6010)
951 ctl.fname = "xc3028-v27.fw";
952 else
Stefan Ringele18f58c2010-04-23 12:43:42 -0300953 ctl.fname = "xc3028-v24.fw";
Mauro Carvalho Chehabdf7c1d92008-10-25 08:56:22 -0300954 }
955
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -0300956 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300957 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
958 &xc2028_cfg);
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300959
960 }
961 break;
962 case TUNER_XC5000:
963 {
964 struct v4l2_priv_tun_config xc5000_cfg;
965 struct xc5000_config ctl = {
966 .i2c_address = dev->tuner_addr,
967 .if_khz = 4570,
Dmitri Belimov8aff8ba2011-02-17 22:11:05 -0300968 .radio_input = XC5000_RADIO_FM1_MONO,
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300969 };
970
971 xc5000_cfg.tuner = TUNER_XC5000;
972 xc5000_cfg.priv = &ctl;
973
Dmitri Belimov1b0e48a2010-05-04 19:53:50 -0300974 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
975 &xc5000_cfg);
976 }
977 break;
978 default:
979 printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
980 break;
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -0300981 }
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -0300982}
983
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -0300984static int fill_board_specific_data(struct tm6000_core *dev)
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300985{
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -0300986 int rc;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300987
Mauro Carvalho Chehab29c389b2008-01-08 11:19:22 -0300988 dev->dev_type = tm6000_boards[dev->model].type;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300989 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
990 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
Stefan Ringel32a22322010-03-29 13:51:10 -0300991
992 dev->gpio = tm6000_boards[dev->model].gpio;
Michel Ludwig95a83822007-07-24 08:06:45 -0300993
Stefan Ringeld064f962010-06-20 17:16:52 -0300994 dev->ir_codes = tm6000_boards[dev->model].ir_codes;
995
Michel Ludwig95a83822007-07-24 08:06:45 -0300996 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -0300997
998 dev->caps = tm6000_boards[dev->model].caps;
999
Stefan Ringelfb7ef982011-05-09 16:53:51 -03001000 dev->vinput[0] = tm6000_boards[dev->model].vinput[0];
1001 dev->vinput[1] = tm6000_boards[dev->model].vinput[1];
1002 dev->vinput[2] = tm6000_boards[dev->model].vinput[2];
1003 dev->rinput = tm6000_boards[dev->model].rinput;
1004
Thierry Reding6e896482011-09-01 02:43:04 -03001005 /* setup per-model quirks */
1006 switch (dev->model) {
1007 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
matthieu castet3874cd72011-12-16 14:15:07 -03001008 case TM6010_BOARD_HAUPPAUGE_900H:
Thierry Reding6e896482011-09-01 02:43:04 -03001009 dev->quirks |= TM6000_QUIRK_NO_USB_DELAY;
1010 break;
1011
1012 default:
1013 break;
1014 }
1015
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001016 /* initialize hardware */
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001017 rc = tm6000_init(dev);
1018 if (rc < 0)
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -03001019 return rc;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001020
Greg Dietschec5274ab2011-06-13 13:11:47 -05001021 return v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -03001022}
1023
1024
1025static void use_alternative_detection_method(struct tm6000_core *dev)
1026{
1027 int i, model = -1;
1028
1029 if (!dev->eedata_size)
1030 return;
1031
1032 for (i = 0; i < ARRAY_SIZE(tm6000_boards); i++) {
1033 if (!tm6000_boards[i].eename_size)
1034 continue;
1035 if (dev->eedata_size < tm6000_boards[i].eename_pos +
1036 tm6000_boards[i].eename_size)
1037 continue;
1038
1039 if (!memcmp(&dev->eedata[tm6000_boards[i].eename_pos],
1040 tm6000_boards[i].eename,
1041 tm6000_boards[i].eename_size)) {
1042 model = i;
1043 break;
1044 }
1045 }
1046 if (model < 0) {
1047 printk(KERN_INFO "Device has eeprom but is currently unknown\n");
1048 return;
1049 }
1050
1051 dev->model = model;
1052
1053 printk(KERN_INFO "Device identified via eeprom as %s (type = %d)\n",
1054 tm6000_boards[model].name, model);
1055}
1056
Mauro Carvalho Chehab6740a932011-11-30 14:54:05 -03001057#if defined(CONFIG_MODULES) && defined(MODULE)
1058static void request_module_async(struct work_struct *work)
1059{
1060 struct tm6000_core *dev = container_of(work, struct tm6000_core,
1061 request_module_wk);
1062
1063 request_module("tm6000-alsa");
1064
1065 if (dev->caps.has_dvb)
1066 request_module("tm6000-dvb");
1067}
1068
1069static void request_modules(struct tm6000_core *dev)
1070{
1071 INIT_WORK(&dev->request_module_wk, request_module_async);
1072 schedule_work(&dev->request_module_wk);
1073}
1074
1075static void flush_request_modules(struct tm6000_core *dev)
1076{
Tejun Heo43829732012-08-20 14:51:24 -07001077 flush_work(&dev->request_module_wk);
Mauro Carvalho Chehab6740a932011-11-30 14:54:05 -03001078}
1079#else
1080#define request_modules(dev)
1081#define flush_request_modules(dev)
1082#endif /* CONFIG_MODULES */
1083
Mauro Carvalho Chehab792bc092011-04-20 18:43:24 -03001084static int tm6000_init_dev(struct tm6000_core *dev)
1085{
1086 struct v4l2_frequency f;
1087 int rc = 0;
1088
1089 mutex_init(&dev->lock);
1090 mutex_lock(&dev->lock);
1091
1092 if (!is_generic(dev->model)) {
1093 rc = fill_board_specific_data(dev);
1094 if (rc < 0)
1095 goto err;
1096
1097 /* register i2c bus */
1098 rc = tm6000_i2c_register(dev);
1099 if (rc < 0)
1100 goto err;
1101 } else {
1102 /* register i2c bus */
1103 rc = tm6000_i2c_register(dev);
1104 if (rc < 0)
1105 goto err;
1106
1107 use_alternative_detection_method(dev);
1108
1109 rc = fill_board_specific_data(dev);
1110 if (rc < 0)
1111 goto err;
1112 }
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001113
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -03001114 /* Default values for STD and resolutions */
1115 dev->width = 720;
1116 dev->height = 480;
Hans Verkuil804be2d2013-06-03 05:36:44 -03001117 dev->norm = V4L2_STD_NTSC_M;
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -03001118
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -03001119 /* Configure tuner */
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001120 tm6000_config_tuner(dev);
Mauro Carvalho Chehabd544f2c2007-10-24 09:22:08 -03001121
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -03001122 /* Set video standard */
Laurent Pinchart8774bed2014-04-28 16:53:01 -03001123 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, dev->norm);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001124
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -03001125 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001126 f.tuner = 0;
1127 f.type = V4L2_TUNER_ANALOG_TV;
1128 f.frequency = 3092; /* 193.25 MHz */
1129 dev->freq = f.frequency;
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -03001130 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
1131
1132 if (dev->caps.has_tda9874)
1133 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -03001134 "tvaudio", I2C_ADDR_TDA9874, NULL);
Mauro Carvalho Chehabcc27a8c2007-11-02 11:23:14 -03001135
Mauro Carvalho Chehab762e17e2010-02-12 03:51:43 -03001136 /* register and initialize V4L2 */
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001137 rc = tm6000_v4l2_register(dev);
1138 if (rc < 0)
Mauro Carvalho Chehab762e17e2010-02-12 03:51:43 -03001139 goto err;
1140
Stefan Ringel0439db752010-05-10 13:22:51 -03001141 tm6000_add_into_devlist(dev);
Stefan Ringel0439db752010-05-10 13:22:51 -03001142 tm6000_init_extension(dev);
1143
Stefan Ringeld064f962010-06-20 17:16:52 -03001144 tm6000_ir_init(dev);
1145
Mauro Carvalho Chehab6740a932011-11-30 14:54:05 -03001146 request_modules(dev);
1147
Mauro Carvalho Chehabdfd36d82010-02-12 03:52:46 -03001148 mutex_unlock(&dev->lock);
Stefan Ringel80af6bb2010-02-05 19:57:02 -03001149 return 0;
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -03001150
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001151err:
1152 mutex_unlock(&dev->lock);
1153 return rc;
1154}
1155
1156/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
1157#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
1158
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001159static void get_max_endpoint(struct usb_device *udev,
1160 struct usb_host_interface *alt,
1161 char *msgtype,
1162 struct usb_host_endpoint *curr_e,
1163 struct tm6000_endpoint *tm_ep)
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001164{
1165 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
1166 unsigned int size = tmp & 0x7ff;
1167
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001168 if (udev->speed == USB_SPEED_HIGH)
Timofey Trofimov52e0a72a2010-05-29 13:52:46 -03001169 size = size * hb_mult(tmp);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001170
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001171 if (size > tm_ep->maxsize) {
1172 tm_ep->endp = curr_e;
1173 tm_ep->maxsize = size;
1174 tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
1175 tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
1176
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001177 printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001178 msgtype, curr_e->desc.bEndpointAddress,
1179 size);
1180 }
1181}
1182
1183/*
1184 * tm6000_usb_probe()
1185 * checks for supported devices
1186 */
1187static int tm6000_usb_probe(struct usb_interface *interface,
1188 const struct usb_device_id *id)
1189{
1190 struct usb_device *usbdev;
1191 struct tm6000_core *dev = NULL;
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001192 int i, rc = 0;
1193 int nr = 0;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001194 char *speed;
1195
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001196 usbdev = usb_get_dev(interface_to_usbdev(interface));
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001197
1198 /* Selects the proper interface */
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001199 rc = usb_set_interface(usbdev, 0, 1);
1200 if (rc < 0)
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001201 goto err;
1202
1203 /* Check to see next free device and mark as used */
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001204 nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001205 if (nr >= TM6000_MAXBOARDS) {
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001206 printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001207 usb_put_dev(usbdev);
1208 return -ENOMEM;
1209 }
1210
1211 /* Create and initialize dev struct */
1212 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1213 if (dev == NULL) {
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001214 printk(KERN_ERR "tm6000" ": out of memory!\n");
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001215 usb_put_dev(usbdev);
1216 return -ENOMEM;
1217 }
1218 spin_lock_init(&dev->slock);
Thierry Redingfc4eab22011-08-04 04:14:10 -03001219 mutex_init(&dev->usb_lock);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001220
1221 /* Increment usage count */
Thierry Reding6f2e77b2011-08-04 04:14:11 -03001222 set_bit(nr, &tm6000_devused);
Michel Ludwig2cd4fd12007-06-17 17:12:32 -03001223 snprintf(dev->name, 29, "tm6000 #%d", nr);
1224
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001225 dev->model = id->driver_info;
Thierry Reding3d1a51d2011-08-04 04:14:01 -03001226 if (card[nr] < ARRAY_SIZE(tm6000_boards))
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001227 dev->model = card[nr];
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001228
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001229 dev->udev = usbdev;
1230 dev->devno = nr;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001231
1232 switch (usbdev->speed) {
1233 case USB_SPEED_LOW:
1234 speed = "1.5";
1235 break;
1236 case USB_SPEED_UNKNOWN:
1237 case USB_SPEED_FULL:
1238 speed = "12";
1239 break;
1240 case USB_SPEED_HIGH:
1241 speed = "480";
1242 break;
1243 default:
1244 speed = "unknown";
1245 }
1246
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001247 /* Get endpoints */
1248 for (i = 0; i < interface->num_altsetting; i++) {
1249 int ep;
1250
1251 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
1252 struct usb_host_endpoint *e;
1253 int dir_out;
1254
1255 e = &interface->altsetting[i].endpoint[ep];
1256
1257 dir_out = ((e->desc.bEndpointAddress &
1258 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
1259
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001260 printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001261 i,
1262 interface->altsetting[i].desc.bInterfaceNumber,
1263 interface->altsetting[i].desc.bInterfaceClass);
1264
1265 switch (e->desc.bmAttributes) {
1266 case USB_ENDPOINT_XFER_BULK:
1267 if (!dir_out) {
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001268 get_max_endpoint(usbdev,
1269 &interface->altsetting[i],
1270 "Bulk IN", e,
1271 &dev->bulk_in);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001272 } else {
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001273 get_max_endpoint(usbdev,
1274 &interface->altsetting[i],
1275 "Bulk OUT", e,
1276 &dev->bulk_out);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001277 }
1278 break;
1279 case USB_ENDPOINT_XFER_ISOC:
1280 if (!dir_out) {
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001281 get_max_endpoint(usbdev,
1282 &interface->altsetting[i],
1283 "ISOC IN", e,
1284 &dev->isoc_in);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001285 } else {
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001286 get_max_endpoint(usbdev,
1287 &interface->altsetting[i],
1288 "ISOC OUT", e,
1289 &dev->isoc_out);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001290 }
1291 break;
Stefan Ringeld064f962010-06-20 17:16:52 -03001292 case USB_ENDPOINT_XFER_INT:
1293 if (!dir_out) {
1294 get_max_endpoint(usbdev,
1295 &interface->altsetting[i],
1296 "INT IN", e,
1297 &dev->int_in);
1298 } else {
1299 get_max_endpoint(usbdev,
1300 &interface->altsetting[i],
1301 "INT OUT", e,
1302 &dev->int_out);
1303 }
1304 break;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001305 }
1306 }
1307 }
1308
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001309
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001310 printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001311 speed,
1312 le16_to_cpu(dev->udev->descriptor.idVendor),
1313 le16_to_cpu(dev->udev->descriptor.idProduct),
1314 interface->altsetting->desc.bInterfaceNumber);
1315
1316/* check if the the device has the iso in endpoint at the correct place */
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -03001317 if (!dev->isoc_in.endp) {
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001318 printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
1319 rc = -ENODEV;
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001320
1321 goto err;
1322 }
1323
1324 /* save our data pointer in this interface device */
1325 usb_set_intfdata(interface, dev);
1326
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001327 printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001328
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001329 rc = tm6000_init_dev(dev);
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001330 if (rc < 0)
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001331 goto err;
1332
1333 return 0;
1334
1335err:
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001336 printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -03001337
Thierry Reding6f2e77b2011-08-04 04:14:11 -03001338 clear_bit(nr, &tm6000_devused);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001339 usb_put_dev(usbdev);
1340
1341 kfree(dev);
1342 return rc;
1343}
1344
1345/*
1346 * tm6000_usb_disconnect()
1347 * called when the device gets diconencted
1348 * video device will be unregistered on v4l2_close in case it is still open
1349 */
1350static void tm6000_usb_disconnect(struct usb_interface *interface)
1351{
1352 struct tm6000_core *dev = usb_get_intfdata(interface);
1353 usb_set_intfdata(interface, NULL);
1354
1355 if (!dev)
1356 return;
1357
Roel Van Nyen9d5164d2010-04-27 18:57:00 -03001358 printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001359
Mauro Carvalho Chehab6740a932011-11-30 14:54:05 -03001360 flush_request_modules(dev);
1361
Stefan Ringeld064f962010-06-20 17:16:52 -03001362 tm6000_ir_fini(dev);
1363
Stefan Ringelf36cc032010-05-23 15:29:25 -03001364 if (dev->gpio.power_led) {
1365 switch (dev->model) {
1366 case TM6010_BOARD_HAUPPAUGE_900H:
1367 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
1368 case TM6010_BOARD_TWINHAN_TU501:
1369 /* Power led off */
1370 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
1371 dev->gpio.power_led, 0x01);
1372 msleep(15);
1373 break;
1374 case TM6010_BOARD_BEHOLD_WANDER:
1375 case TM6010_BOARD_BEHOLD_VOYAGER:
Dmitri Belimov1f65dd32011-02-02 12:15:52 -03001376 case TM6010_BOARD_BEHOLD_WANDER_LITE:
1377 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
Stefan Ringelf36cc032010-05-23 15:29:25 -03001378 /* Power led off */
1379 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
1380 dev->gpio.power_led, 0x00);
1381 msleep(15);
1382 break;
1383 }
1384 }
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001385 tm6000_v4l2_unregister(dev);
1386
Michel Ludwig7c3f53e2007-06-16 23:21:48 -03001387 tm6000_i2c_unregister(dev);
1388
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -03001389 v4l2_device_unregister(&dev->v4l2_dev);
1390
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001391 dev->state |= DEV_DISCONNECTED;
1392
Michel Ludwig7c3f53e2007-06-16 23:21:48 -03001393 usb_put_dev(dev->udev);
1394
Stefan Ringel0439db752010-05-10 13:22:51 -03001395 tm6000_close_extension(dev);
Stefan Ringelcee39262010-05-30 09:19:04 -03001396 tm6000_remove_from_devlist(dev);
Stefan Ringel0439db752010-05-10 13:22:51 -03001397
Thierry Reding6f2e77b2011-08-04 04:14:11 -03001398 clear_bit(dev->devno, &tm6000_devused);
Michel Ludwig22927e82007-06-14 17:19:59 -03001399 kfree(dev);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001400}
1401
1402static struct usb_driver tm6000_usb_driver = {
1403 .name = "tm6000",
1404 .probe = tm6000_usb_probe,
1405 .disconnect = tm6000_usb_disconnect,
1406 .id_table = tm6000_id_table,
1407};
1408
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001409module_usb_driver(tm6000_usb_driver);
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001410
Dmitri Belimove28f49b2010-02-22 06:32:15 -03001411MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
Mauro Carvalho Chehab9701dc92009-09-14 09:42:41 -03001412MODULE_AUTHOR("Mauro Carvalho Chehab");
1413MODULE_LICENSE("GPL");