au0828-cards.c 8.7 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 29 30 31 32 33 34 35 36 37

void hvr950q_cs5340_audio(void *priv, int enable)
{
	/* 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
		.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,
			},
		},
68 69 70
	},
	[AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
		.name	= "Hauppauge HVR950Q",
71 72
		.tuner_type = TUNER_XC5000,
		.tuner_addr = 0x61,
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
		.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,
			},
		},
92
	},
93 94
	[AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
		.name	= "Hauppauge HVR950Q rev xxF8",
95 96
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
97
	},
98 99
	[AU0828_BOARD_DVICO_FUSIONHDTV7] = {
		.name	= "DViCO FusionHDTV USB",
100 101
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
102
	},
103 104
	[AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
		.name = "Hauppauge Woodbury",
105 106
		.tuner_type = UNSET,
		.tuner_addr = ADDR_UNSET,
107
	},
108 109 110 111 112
};

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

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

119
	switch (dev->boardnr) {
120 121
	case AU0828_BOARD_HAUPPAUGE_HVR850:
	case AU0828_BOARD_HAUPPAUGE_HVR950Q:
122
	case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
123
	case AU0828_BOARD_DVICO_FUSIONHDTV7:
S
Steven Toth 已提交
124
		if (command == 0) {
125 126 127 128 129 130 131
			/* Tuner Reset Command from xc5000 */
			/* Drive the tuner into reset and out */
			au0828_clear(dev, REG_001, 2);
			mdelay(200);
			au0828_set(dev, REG_001, 2);
			mdelay(50);
			return 0;
132
		} else {
133
			printk(KERN_ERR
134
				"%s(): Unknown command.\n", __func__);
135 136 137 138 139 140 141 142
			return -EINVAL;
		}
		break;
	}

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

143 144 145 146 147
static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
{
	struct tveeprom tv;

	tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
148
	dev->board.tuner_type = tv.tuner_type;
149 150

	/* Make sure we support the board model */
S
Steven Toth 已提交
151
	switch (tv.model) {
152
	case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
153
	case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
154 155 156 157
	case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
	case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
	case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
	case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */
158
	case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
159
	case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
160
	case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
161 162
		break;
	default:
163 164
		printk(KERN_WARNING "%s: warning: "
		       "unknown hauppauge model #%d\n", __func__, tv.model);
165 166 167
		break;
	}

168 169
	printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
	       __func__, tv.model);
170 171 172 173 174
}

void au0828_card_setup(struct au0828_dev *dev)
{
	static u8 eeprom[256];
175 176 177
	struct tuner_setup tun_setup;
	unsigned int mode_mask = T_ANALOG_TV |
				 T_DIGITAL_TV;
178

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

181 182
	memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board));

183 184 185 186 187
	if (dev->i2c_rc == 0) {
		dev->i2c_client.addr = 0xa0 >> 1;
		tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
	}

188
	switch (dev->boardnr) {
189 190
	case AU0828_BOARD_HAUPPAUGE_HVR850:
	case AU0828_BOARD_HAUPPAUGE_HVR950Q:
191
	case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
192
	case AU0828_BOARD_HAUPPAUGE_WOODBURY:
193 194 195 196
		if (dev->i2c_rc == 0)
			hauppauge_eeprom(dev, eeprom+0xa0);
		break;
	}
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215

	if (dev->board.input != NULL) {
		/* Load the analog demodulator driver (note this would need to
		   be abstracted out if we ever need to support a different
		   demod) */
		request_module("au8522");
	}

	/* Setup tuners */
	if (dev->board.tuner_type != TUNER_ABSENT) {
		/* Load the tuner module, which does the attach */
		request_module("tuner");

		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;
		au0828_call_i2c_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
	}
216 217
}

218 219 220
/*
 * The bridge has between 8 and 12 gpios.
 * Regs 1 and 0 deal with output enables.
S
Steven Toth 已提交
221
 * Regs 3 and 2 deal with direction.
222 223 224
 */
void au0828_gpio_setup(struct au0828_dev *dev)
{
225
	dprintk(1, "%s()\n", __func__);
S
Steven Toth 已提交
226

227
	switch (dev->boardnr) {
228 229
	case AU0828_BOARD_HAUPPAUGE_HVR850:
	case AU0828_BOARD_HAUPPAUGE_HVR950Q:
230
	case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
231
	case AU0828_BOARD_HAUPPAUGE_WOODBURY:
232 233 234 235
		/* GPIO's
		 * 4 - CS5340
		 * 5 - AU8522 Demodulator
		 * 6 - eeprom W/P
236
		 * 7 - power supply
237 238 239 240 241
		 * 9 - XC5000 Tuner
		 */

		/* Into reset */
		au0828_write(dev, REG_003, 0x02);
242
		au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
243 244 245 246
		au0828_write(dev, REG_001, 0x0);
		au0828_write(dev, REG_000, 0x0);
		msleep(100);

247
		/* Out of reset (leave the cs5340 in reset until needed) */
248 249
		au0828_write(dev, REG_003, 0x02);
		au0828_write(dev, REG_001, 0x02);
250 251 252
		au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
		au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
		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 */
280
struct usb_device_id au0828_usb_id_table[] = {
281 282 283 284 285 286
	{ 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 },
287 288 289 290 291 292
	{ 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 },
293 294
	{ USB_DEVICE(0x2040, 0x721e),
		.driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
295 296 297 298 299 300
	{ 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 },
301 302 303 304 305 306
	{ 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 },
307 308
	{ USB_DEVICE(0x2040, 0x8200),
		.driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
309 310 311 312
	{ },
};

MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);