au0828-cards.c 10.6 KB
Newer Older
1 2 3
/*
 *  Driver for the Auvitek USB bridge
 *
4
 *  Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "au0828.h"
#include "au0828-cards.h"
24
#include "au8522.h"
25 26
#include "media/tuner.h"
#include "media/v4l2-common.h"
27

28
static void hvr950q_cs5340_audio(void *priv, int enable)
29 30 31 32 33 34 35 36 37
{
	/* Because the HVR-950q shares an i2s bus between the cs5340 and the
	   au8522, we need to hold cs5340 in reset when using the au8522 */
	struct au0828_dev *dev = priv;
	if (enable == 1)
		au0828_set(dev, REG_000, 0x10);
	else
		au0828_clear(dev, REG_000, 0x10);
}
38 39 40 41

struct au0828_board au0828_boards[] = {
	[AU0828_BOARD_UNKNOWN] = {
		.name	= "Unknown board",
42 43
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
44 45 46
	},
	[AU0828_BOARD_HAUPPAUGE_HVR850] = {
		.name	= "Hauppauge HVR850",
47 48
		.tuner_type = TUNER_XC5000,
		.tuner_addr = 0x61,
49
		.has_ir_i2c = 1,
50
		.i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
		.input = {
			{
				.type = AU0828_VMUX_TELEVISION,
				.vmux = AU8522_COMPOSITE_CH4_SIF,
				.amux = AU8522_AUDIO_SIF,
			},
			{
				.type = AU0828_VMUX_COMPOSITE,
				.vmux = AU8522_COMPOSITE_CH1,
				.amux = AU8522_AUDIO_NONE,
				.audio_setup = hvr950q_cs5340_audio,
			},
			{
				.type = AU0828_VMUX_SVIDEO,
				.vmux = AU8522_SVIDEO_CH13,
				.amux = AU8522_AUDIO_NONE,
				.audio_setup = hvr950q_cs5340_audio,
			},
		},
70 71 72
	},
	[AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
		.name	= "Hauppauge HVR950Q",
73 74
		.tuner_type = TUNER_XC5000,
		.tuner_addr = 0x61,
75
		.has_ir_i2c = 1,
76 77 78 79 80 81
		/* The au0828 hardware i2c implementation does not properly
		   support the xc5000's i2c clock stretching.  So we need to
		   lower the clock frequency enough where the 15us clock
		   stretch fits inside of a normal clock cycle, or else the
		   au0828 fails to set the STOP bit.  A 30 KHz clock puts the
		   clock pulse width at 18us */
82
		.i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
		.input = {
			{
				.type = AU0828_VMUX_TELEVISION,
				.vmux = AU8522_COMPOSITE_CH4_SIF,
				.amux = AU8522_AUDIO_SIF,
			},
			{
				.type = AU0828_VMUX_COMPOSITE,
				.vmux = AU8522_COMPOSITE_CH1,
				.amux = AU8522_AUDIO_NONE,
				.audio_setup = hvr950q_cs5340_audio,
			},
			{
				.type = AU0828_VMUX_SVIDEO,
				.vmux = AU8522_SVIDEO_CH13,
				.amux = AU8522_AUDIO_NONE,
				.audio_setup = hvr950q_cs5340_audio,
			},
		},
102
	},
103 104
	[AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
		.name	= "Hauppauge HVR950Q rev xxF8",
105 106
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
107
		.i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
108
	},
109 110
	[AU0828_BOARD_DVICO_FUSIONHDTV7] = {
		.name	= "DViCO FusionHDTV USB",
111 112
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
113
		.i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
114
	},
115 116
	[AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
		.name = "Hauppauge Woodbury",
117 118
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
119
		.i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
120
	},
121 122 123 124 125
};

/* Tuner callback function for au0828 boards. Currently only needed
 * for HVR1500Q, which has an xc5000 tuner.
 */
126
int au0828_tuner_callback(void *priv, int component, int command, int arg)
127 128 129
{
	struct au0828_dev *dev = priv;

130
	dprintk(1, "%s()\n", __func__);
S
Steven Toth 已提交
131

132
	switch (dev->boardnr) {
133 134
	case AU0828_BOARD_HAUPPAUGE_HVR850:
	case AU0828_BOARD_HAUPPAUGE_HVR950Q:
135
	case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
136
	case AU0828_BOARD_DVICO_FUSIONHDTV7:
S
Steven Toth 已提交
137
		if (command == 0) {
138 139 140
			/* Tuner Reset Command from xc5000 */
			/* Drive the tuner into reset and out */
			au0828_clear(dev, REG_001, 2);
141
			mdelay(10);
142
			au0828_set(dev, REG_001, 2);
143
			mdelay(10);
144
			return 0;
145
		} else {
146
			printk(KERN_ERR
147
				"%s(): Unknown command.\n", __func__);
148 149 150 151 152 153 154 155
			return -EINVAL;
		}
		break;
	}

	return 0; /* Should never be here */
}

156 157 158 159 160
static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
{
	struct tveeprom tv;

	tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
161
	dev->board.tuner_type = tv.tuner_type;
162 163

	/* Make sure we support the board model */
S
Steven Toth 已提交
164
	switch (tv.model) {
165
	case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
166
	case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
167 168
	case 72101: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
	case 72201: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
169 170 171 172 173
	case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
	case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
	case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
	case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
	case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
174 175 176
	case 72261: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
	case 72271: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
	case 72281: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
177
	case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
178
	case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
179 180
		break;
	default:
181 182
		printk(KERN_WARNING "%s: warning: "
		       "unknown hauppauge model #%d\n", __func__, tv.model);
183 184 185
		break;
	}

186 187
	printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
	       __func__, tv.model);
188 189
}

190 191
void au0828_card_analog_fe_setup(struct au0828_dev *dev);

192 193 194 195
void au0828_card_setup(struct au0828_dev *dev)
{
	static u8 eeprom[256];

196
	dprintk(1, "%s()\n", __func__);
S
Steven Toth 已提交
197

198
	dev->board = au0828_boards[dev->boardnr];
199

200 201 202 203 204
	if (dev->i2c_rc == 0) {
		dev->i2c_client.addr = 0xa0 >> 1;
		tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
	}

205
	switch (dev->boardnr) {
206 207
	case AU0828_BOARD_HAUPPAUGE_HVR850:
	case AU0828_BOARD_HAUPPAUGE_HVR950Q:
208
	case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
209
	case AU0828_BOARD_HAUPPAUGE_WOODBURY:
210 211 212 213
		if (dev->i2c_rc == 0)
			hauppauge_eeprom(dev, eeprom+0xa0);
		break;
	}
214

215 216 217 218 219
	au0828_card_analog_fe_setup(dev);
}

void au0828_card_analog_fe_setup(struct au0828_dev *dev)
{
220
#ifdef CONFIG_VIDEO_AU0828_V4L2
221 222 223 224
	struct tuner_setup tun_setup;
	struct v4l2_subdev *sd;
	unsigned int mode_mask = T_ANALOG_TV;

225
	if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
226 227 228
		/* Load the analog demodulator driver (note this would need to
		   be abstracted out if we ever need to support a different
		   demod) */
229
		sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
230
				"au8522", 0x8e >> 1, NULL);
231 232
		if (sd == NULL)
			printk(KERN_ERR "analog subdev registration failed\n");
233 234 235 236 237
	}

	/* Setup tuners */
	if (dev->board.tuner_type != TUNER_ABSENT) {
		/* Load the tuner module, which does the attach */
238
		sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
239
				"tuner", dev->board.tuner_addr, NULL);
240 241
		if (sd == NULL)
			printk(KERN_ERR "tuner subdev registration fail\n");
242 243 244 245 246

		tun_setup.mode_mask      = mode_mask;
		tun_setup.type           = dev->board.tuner_type;
		tun_setup.addr           = dev->board.tuner_addr;
		tun_setup.tuner_callback = au0828_tuner_callback;
247 248
		v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr,
				     &tun_setup);
249
	}
250
#endif
251 252
}

253 254 255
/*
 * The bridge has between 8 and 12 gpios.
 * Regs 1 and 0 deal with output enables.
S
Steven Toth 已提交
256
 * Regs 3 and 2 deal with direction.
257 258 259
 */
void au0828_gpio_setup(struct au0828_dev *dev)
{
260
	dprintk(1, "%s()\n", __func__);
S
Steven Toth 已提交
261

262
	switch (dev->boardnr) {
263 264
	case AU0828_BOARD_HAUPPAUGE_HVR850:
	case AU0828_BOARD_HAUPPAUGE_HVR950Q:
265
	case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
266
	case AU0828_BOARD_HAUPPAUGE_WOODBURY:
267 268 269 270
		/* GPIO's
		 * 4 - CS5340
		 * 5 - AU8522 Demodulator
		 * 6 - eeprom W/P
271
		 * 7 - power supply
272 273 274
		 * 9 - XC5000 Tuner
		 */

275 276 277
		/* Set relevant GPIOs as outputs (leave the EEPROM W/P
		   as an input since we will never touch it and it has
		   a pullup) */
278
		au0828_write(dev, REG_003, 0x02);
279
		au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
280 281

		/* Into reset */
282 283
		au0828_write(dev, REG_001, 0x0);
		au0828_write(dev, REG_000, 0x0);
284
		msleep(50);
285

286 287 288 289 290 291 292 293
		/* Bring power supply out of reset */
		au0828_write(dev, REG_000, 0x80);
		msleep(50);

		/* Bring xc5000 and au8522 out of reset (leave the
		   cs5340 in reset until needed) */
		au0828_write(dev, REG_001, 0x02); /* xc5000 */
		au0828_write(dev, REG_000, 0x80 | 0x20); /* PS + au8522 */
294

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
		msleep(250);
		break;
	case AU0828_BOARD_DVICO_FUSIONHDTV7:
		/* GPIO's
		 * 6 - ?
		 * 8 - AU8522 Demodulator
		 * 9 - XC5000 Tuner
		 */

		/* Into reset */
		au0828_write(dev, REG_003, 0x02);
		au0828_write(dev, REG_002, 0xa0);
		au0828_write(dev, REG_001, 0x0);
		au0828_write(dev, REG_000, 0x0);
		msleep(100);

		/* Out of reset */
		au0828_write(dev, REG_003, 0x02);
		au0828_write(dev, REG_002, 0xa0);
		au0828_write(dev, REG_001, 0x02);
		au0828_write(dev, REG_000, 0xa0);
		msleep(250);
		break;
	}
}

/* table of devices that work with this driver */
322
struct usb_device_id au0828_usb_id_table[] = {
323 324 325 326 327 328
	{ USB_DEVICE(0x2040, 0x7200),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
	{ USB_DEVICE(0x2040, 0x7240),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
	{ USB_DEVICE(0x0fe9, 0xd620),
		.driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
329 330 331 332 333 334
	{ USB_DEVICE(0x2040, 0x7210),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
	{ USB_DEVICE(0x2040, 0x7217),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
	{ USB_DEVICE(0x2040, 0x721b),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
335 336
	{ USB_DEVICE(0x2040, 0x721e),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
337 338 339 340 341 342
	{ USB_DEVICE(0x2040, 0x721f),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
	{ USB_DEVICE(0x2040, 0x7280),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
	{ USB_DEVICE(0x0fd9, 0x0008),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
343 344 345 346 347 348
	{ USB_DEVICE(0x2040, 0x7201),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
	{ USB_DEVICE(0x2040, 0x7211),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
	{ USB_DEVICE(0x2040, 0x7281),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
349 350
	{ USB_DEVICE(0x05e1, 0x0480),
		.driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
351 352
	{ USB_DEVICE(0x2040, 0x8200),
		.driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
353 354
	{ USB_DEVICE(0x2040, 0x7260),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
355 356
	{ USB_DEVICE(0x2040, 0x7213),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
357 358
	{ USB_DEVICE(0x2040, 0x7270),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
359 360 361 362
	{ },
};

MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);