pms.c 25.6 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *	Media Vision Pro Movie Studio
 *			or
 *	"all you need is an I2C bus some RAM and a prayer"
 *
 *	This draws heavily on code
 *
 *	(c) Wolfgang Koehler,  wolf@first.gmd.de, Dec. 1994
 *	Kiefernring 15
 *	14478 Potsdam, Germany
 *
 *	Most of this code is directly derived from his userspace driver.
13 14
 *	His driver works so send any reports to alan@lxorguk.ukuu.org.uk
 *	unless the userspace driver also doesn't work for you...
15
 *
Linus Torvalds's avatar
Linus Torvalds committed
16
 *      Changes:
17 18 19 20
 *	25-11-2009 	Hans Verkuil <hverkuil@xs4all.nl>
 * 			- converted to version 2 of the V4L API.
 *      08/07/2003      Daniele Bellucci <bellucda@tiscali.it>
 *                      - pms_capture: report back -EFAULT
Linus Torvalds's avatar
Linus Torvalds committed
21 22 23 24 25 26 27 28 29 30
 */

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/ioport.h>
#include <linux/init.h>
31
#include <linux/mutex.h>
32
#include <linux/uaccess.h>
33
#include <linux/isa.h>
Linus Torvalds's avatar
Linus Torvalds committed
34
#include <asm/io.h>
35 36

#include <linux/videodev2.h>
37
#include <media/v4l2-common.h>
38
#include <media/v4l2-ioctl.h>
39 40 41
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-event.h>
42
#include <media/v4l2-device.h>
Linus Torvalds's avatar
Linus Torvalds committed
43

44
MODULE_LICENSE("GPL");
45
MODULE_VERSION("0.0.5");
Linus Torvalds's avatar
Linus Torvalds committed
46 47

#define MOTOROLA	1
48
#define PHILIPS2	2               /* SAA7191 */
Linus Torvalds's avatar
Linus Torvalds committed
49 50 51
#define PHILIPS1	3
#define MVVMEMORYWIDTH	0x40		/* 512 bytes */

52
struct i2c_info {
Linus Torvalds's avatar
Linus Torvalds committed
53 54 55 56 57 58
	u8 slave;
	u8 sub;
	u8 data;
	u8 hits;
};

59 60 61
struct pms {
	struct v4l2_device v4l2_dev;
	struct video_device vdev;
62
	struct v4l2_ctrl_handler hdl;
63 64
	int height;
	int width;
65 66
	int depth;
	int input;
67 68 69 70 71 72
	struct mutex lock;
	int i2c_count;
	struct i2c_info i2cinfo[64];

	int decoder;
	int standard;	/* 0 - auto 1 - ntsc 2 - pal 3 - secam */
73
	v4l2_std_id std;
74 75 76 77
	int io;
	int data;
	void __iomem *mem;
};
Linus Torvalds's avatar
Linus Torvalds committed
78 79 80 81

/*
 *	I/O ports and Shared Memory
 */
82

83 84 85 86 87
static int io_port = 0x250;
module_param(io_port, int, 0);

static int mem_base = 0xc8000;
module_param(mem_base, int, 0);
Linus Torvalds's avatar
Linus Torvalds committed
88

89 90
static int video_nr = -1;
module_param(video_nr, int, 0);
91

Linus Torvalds's avatar
Linus Torvalds committed
92

93
static inline void mvv_write(struct pms *dev, u8 index, u8 value)
Linus Torvalds's avatar
Linus Torvalds committed
94
{
95
	outw(index | (value << 8), dev->io);
Linus Torvalds's avatar
Linus Torvalds committed
96 97
}

98
static inline u8 mvv_read(struct pms *dev, u8 index)
Linus Torvalds's avatar
Linus Torvalds committed
99
{
100 101
	outb(index, dev->io);
	return inb(dev->data);
Linus Torvalds's avatar
Linus Torvalds committed
102 103
}

104
static int pms_i2c_stat(struct pms *dev, u8 slave)
Linus Torvalds's avatar
Linus Torvalds committed
105
{
106
	int counter = 0;
Linus Torvalds's avatar
Linus Torvalds committed
107
	int i;
108

109
	outb(0x28, dev->io);
110

111 112
	while ((inb(dev->data) & 0x01) == 0)
		if (counter++ == 256)
Linus Torvalds's avatar
Linus Torvalds committed
113 114
			break;

115 116
	while ((inb(dev->data) & 0x01) != 0)
		if (counter++ == 256)
Linus Torvalds's avatar
Linus Torvalds committed
117
			break;
118

119
	outb(slave, dev->io);
120

121 122 123
	counter = 0;
	while ((inb(dev->data) & 0x01) == 0)
		if (counter++ == 256)
Linus Torvalds's avatar
Linus Torvalds committed
124 125
			break;

126 127
	while ((inb(dev->data) & 0x01) != 0)
		if (counter++ == 256)
Linus Torvalds's avatar
Linus Torvalds committed
128
			break;
129

130 131 132 133
	for (i = 0; i < 12; i++) {
		char st = inb(dev->data);

		if ((st & 2) != 0)
Linus Torvalds's avatar
Linus Torvalds committed
134
			return -1;
135
		if ((st & 1) == 0)
Linus Torvalds's avatar
Linus Torvalds committed
136 137
			break;
	}
138 139
	outb(0x29, dev->io);
	return inb(dev->data);
Linus Torvalds's avatar
Linus Torvalds committed
140 141
}

142
static int pms_i2c_write(struct pms *dev, u16 slave, u16 sub, u16 data)
Linus Torvalds's avatar
Linus Torvalds committed
143
{
144
	int skip = 0;
Linus Torvalds's avatar
Linus Torvalds committed
145 146
	int count;
	int i;
147

148 149 150 151 152 153 154
	for (i = 0; i < dev->i2c_count; i++) {
		if ((dev->i2cinfo[i].slave == slave) &&
		    (dev->i2cinfo[i].sub == sub)) {
			if (dev->i2cinfo[i].data == data)
				skip = 1;
			dev->i2cinfo[i].data = data;
			i = dev->i2c_count + 1;
Linus Torvalds's avatar
Linus Torvalds committed
155 156
		}
	}
157

158 159 160 161 162
	if (i == dev->i2c_count && dev->i2c_count < 64) {
		dev->i2cinfo[dev->i2c_count].slave = slave;
		dev->i2cinfo[dev->i2c_count].sub = sub;
		dev->i2cinfo[dev->i2c_count].data = data;
		dev->i2c_count++;
Linus Torvalds's avatar
Linus Torvalds committed
163
	}
164

165
	if (skip)
Linus Torvalds's avatar
Linus Torvalds committed
166
		return 0;
167

168 169 170
	mvv_write(dev, 0x29, sub);
	mvv_write(dev, 0x2A, data);
	mvv_write(dev, 0x28, slave);
171

172
	outb(0x28, dev->io);
173

174 175 176
	count = 0;
	while ((inb(dev->data) & 1) == 0)
		if (count > 255)
Linus Torvalds's avatar
Linus Torvalds committed
177
			break;
178 179
	while ((inb(dev->data) & 1) != 0)
		if (count > 255)
Linus Torvalds's avatar
Linus Torvalds committed
180
			break;
181

182
	count = inb(dev->data);
183

184
	if (count & 2)
Linus Torvalds's avatar
Linus Torvalds committed
185 186 187 188
		return -1;
	return count;
}

189
static int pms_i2c_read(struct pms *dev, int slave, int sub)
Linus Torvalds's avatar
Linus Torvalds committed
190
{
191 192 193 194 195
	int i;

	for (i = 0; i < dev->i2c_count; i++) {
		if (dev->i2cinfo[i].slave == slave && dev->i2cinfo[i].sub == sub)
			return dev->i2cinfo[i].data;
Linus Torvalds's avatar
Linus Torvalds committed
196 197 198 199 200
	}
	return 0;
}


201
static void pms_i2c_andor(struct pms *dev, int slave, int sub, int and, int or)
Linus Torvalds's avatar
Linus Torvalds committed
202
{
203 204
	u8 tmp;

205 206 207
	tmp = pms_i2c_read(dev, slave, sub);
	tmp = (tmp & and) | or;
	pms_i2c_write(dev, slave, sub, tmp);
Linus Torvalds's avatar
Linus Torvalds committed
208 209 210 211 212
}

/*
 *	Control functions
 */
213

Linus Torvalds's avatar
Linus Torvalds committed
214

215
static void pms_videosource(struct pms *dev, short source)
Linus Torvalds's avatar
Linus Torvalds committed
216
{
217 218 219 220 221 222 223 224 225 226 227 228 229
	switch (dev->decoder) {
	case MOTOROLA:
		break;
	case PHILIPS2:
		pms_i2c_andor(dev, 0x8a, 0x06, 0x7f, source ? 0x80 : 0);
		break;
	case PHILIPS1:
		break;
	}
	mvv_write(dev, 0x2E, 0x31);
	/* Was: mvv_write(dev, 0x2E, source ? 0x31 : 0x30);
	   But could not make this work correctly. Only Composite input
	   worked for me. */
Linus Torvalds's avatar
Linus Torvalds committed
230 231
}

232
static void pms_hue(struct pms *dev, short hue)
Linus Torvalds's avatar
Linus Torvalds committed
233
{
234 235 236 237 238 239 240 241 242 243
	switch (dev->decoder) {
	case MOTOROLA:
		pms_i2c_write(dev, 0x8a, 0x00, hue);
		break;
	case PHILIPS2:
		pms_i2c_write(dev, 0x8a, 0x07, hue);
		break;
	case PHILIPS1:
		pms_i2c_write(dev, 0x42, 0x07, hue);
		break;
Linus Torvalds's avatar
Linus Torvalds committed
244 245 246
	}
}

247
static void pms_saturation(struct pms *dev, short sat)
Linus Torvalds's avatar
Linus Torvalds committed
248
{
249 250
	switch (dev->decoder) {
	case MOTOROLA:
251
		pms_i2c_write(dev, 0x8a, 0x00, sat);
252 253
		break;
	case PHILIPS1:
254
		pms_i2c_write(dev, 0x42, 0x12, sat);
255
		break;
Linus Torvalds's avatar
Linus Torvalds committed
256 257
	}
}
258 259


260
static void pms_contrast(struct pms *dev, short contrast)
Linus Torvalds's avatar
Linus Torvalds committed
261
{
262 263 264 265 266 267 268
	switch (dev->decoder) {
	case MOTOROLA:
		pms_i2c_write(dev, 0x8a, 0x00, contrast);
		break;
	case PHILIPS1:
		pms_i2c_write(dev, 0x42, 0x13, contrast);
		break;
Linus Torvalds's avatar
Linus Torvalds committed
269 270 271
	}
}

272
static void pms_brightness(struct pms *dev, short brightness)
Linus Torvalds's avatar
Linus Torvalds committed
273
{
274 275 276 277 278 279 280 281 282
	switch (dev->decoder) {
	case MOTOROLA:
		pms_i2c_write(dev, 0x8a, 0x00, brightness);
		pms_i2c_write(dev, 0x8a, 0x00, brightness);
		pms_i2c_write(dev, 0x8a, 0x00, brightness);
		break;
	case PHILIPS1:
		pms_i2c_write(dev, 0x42, 0x19, brightness);
		break;
Linus Torvalds's avatar
Linus Torvalds committed
283 284 285 286
	}
}


287
static void pms_format(struct pms *dev, short format)
Linus Torvalds's avatar
Linus Torvalds committed
288 289
{
	int target;
290

291 292 293 294 295 296
	dev->standard = format;

	if (dev->decoder == PHILIPS1)
		target = 0x42;
	else if (dev->decoder == PHILIPS2)
		target = 0x8a;
Linus Torvalds's avatar
Linus Torvalds committed
297 298
	else
		return;
299

300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
	switch (format) {
	case 0:	/* Auto */
		pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00);
		pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x80);
		break;
	case 1: /* NTSC */
		pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00);
		pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x40);
		break;
	case 2: /* PAL */
		pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00);
		pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x00);
		break;
	case 3:	/* SECAM */
		pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x01);
		pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x00);
		break;
Linus Torvalds's avatar
Linus Torvalds committed
317 318 319 320 321 322 323
	}
}

#ifdef FOR_FUTURE_EXPANSION

/*
 *	These features of the PMS card are not currently exposes. They
324
 *	could become a private v4l ioctl for PMSCONFIG or somesuch if
Linus Torvalds's avatar
Linus Torvalds committed
325 326 327
 *	people need it. We also don't yet use the PMS interrupt.
 */

328
static void pms_hstart(struct pms *dev, short start)
Linus Torvalds's avatar
Linus Torvalds committed
329
{
330 331 332 333 334 335 336 337 338
	switch (dev->decoder) {
	case PHILIPS1:
		pms_i2c_write(dev, 0x8a, 0x05, start);
		pms_i2c_write(dev, 0x8a, 0x18, start);
		break;
	case PHILIPS2:
		pms_i2c_write(dev, 0x42, 0x05, start);
		pms_i2c_write(dev, 0x42, 0x18, start);
		break;
Linus Torvalds's avatar
Linus Torvalds committed
339 340 341 342 343 344
	}
}

/*
 *	Bandpass filters
 */
345

346
static void pms_bandpass(struct pms *dev, short pass)
Linus Torvalds's avatar
Linus Torvalds committed
347
{
348 349 350 351
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x06, 0xcf, (pass & 0x03) << 4);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x06, 0xcf, (pass & 0x03) << 4);
Linus Torvalds's avatar
Linus Torvalds committed
352 353
}

354
static void pms_antisnow(struct pms *dev, short snow)
Linus Torvalds's avatar
Linus Torvalds committed
355
{
356 357 358 359
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x06, 0xf3, (snow & 0x03) << 2);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x06, 0xf3, (snow & 0x03) << 2);
Linus Torvalds's avatar
Linus Torvalds committed
360 361
}

362
static void pms_sharpness(struct pms *dev, short sharp)
Linus Torvalds's avatar
Linus Torvalds committed
363
{
364 365 366 367
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x06, 0xfc, sharp & 0x03);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x06, 0xfc, sharp & 0x03);
Linus Torvalds's avatar
Linus Torvalds committed
368 369
}

370
static void pms_chromaagc(struct pms *dev, short agc)
Linus Torvalds's avatar
Linus Torvalds committed
371
{
372 373 374 375
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x0c, 0x9f, (agc & 0x03) << 5);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x0c, 0x9f, (agc & 0x03) << 5);
Linus Torvalds's avatar
Linus Torvalds committed
376 377
}

378
static void pms_vertnoise(struct pms *dev, short noise)
Linus Torvalds's avatar
Linus Torvalds committed
379
{
380 381 382 383
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x10, 0xfc, noise & 3);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x10, 0xfc, noise & 3);
Linus Torvalds's avatar
Linus Torvalds committed
384 385
}

386
static void pms_forcecolour(struct pms *dev, short colour)
Linus Torvalds's avatar
Linus Torvalds committed
387
{
388 389 390 391
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x0c, 0x7f, (colour & 1) << 7);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x0c, 0x7, (colour & 1) << 7);
Linus Torvalds's avatar
Linus Torvalds committed
392 393
}

394
static void pms_antigamma(struct pms *dev, short gamma)
Linus Torvalds's avatar
Linus Torvalds committed
395
{
396 397 398 399
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0xb8, 0x00, 0x7f, (gamma & 1) << 7);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x20, 0x7, (gamma & 1) << 7);
Linus Torvalds's avatar
Linus Torvalds committed
400 401
}

402
static void pms_prefilter(struct pms *dev, short filter)
Linus Torvalds's avatar
Linus Torvalds committed
403
{
404 405 406 407
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x06, 0xbf, (filter & 1) << 6);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x06, 0xbf, (filter & 1) << 6);
Linus Torvalds's avatar
Linus Torvalds committed
408 409
}

410
static void pms_hfilter(struct pms *dev, short filter)
Linus Torvalds's avatar
Linus Torvalds committed
411
{
412 413 414 415
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0xb8, 0x04, 0x1f, (filter & 7) << 5);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x24, 0x1f, (filter & 7) << 5);
Linus Torvalds's avatar
Linus Torvalds committed
416 417
}

418
static void pms_vfilter(struct pms *dev, short filter)
Linus Torvalds's avatar
Linus Torvalds committed
419
{
420 421 422 423
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0xb8, 0x08, 0x9f, (filter & 3) << 5);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x28, 0x9f, (filter & 3) << 5);
Linus Torvalds's avatar
Linus Torvalds committed
424 425
}

426
static void pms_killcolour(struct pms *dev, short colour)
Linus Torvalds's avatar
Linus Torvalds committed
427
{
428 429 430 431 432 433
	if (dev->decoder == PHILIPS2) {
		pms_i2c_andor(dev, 0x8a, 0x08, 0x07, (colour & 0x1f) << 3);
		pms_i2c_andor(dev, 0x8a, 0x09, 0x07, (colour & 0x1f) << 3);
	} else if (dev->decoder == PHILIPS1) {
		pms_i2c_andor(dev, 0x42, 0x08, 0x07, (colour & 0x1f) << 3);
		pms_i2c_andor(dev, 0x42, 0x09, 0x07, (colour & 0x1f) << 3);
Linus Torvalds's avatar
Linus Torvalds committed
434 435 436
	}
}

437
static void pms_chromagain(struct pms *dev, short chroma)
Linus Torvalds's avatar
Linus Torvalds committed
438
{
439 440 441 442
	if (dev->decoder == PHILIPS2)
		pms_i2c_write(dev, 0x8a, 0x11, chroma);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_write(dev, 0x42, 0x11, chroma);
Linus Torvalds's avatar
Linus Torvalds committed
443 444 445
}


446
static void pms_spacialcompl(struct pms *dev, short data)
Linus Torvalds's avatar
Linus Torvalds committed
447
{
448
	mvv_write(dev, 0x3b, data);
Linus Torvalds's avatar
Linus Torvalds committed
449 450
}

451
static void pms_spacialcomph(struct pms *dev, short data)
Linus Torvalds's avatar
Linus Torvalds committed
452
{
453
	mvv_write(dev, 0x3a, data);
Linus Torvalds's avatar
Linus Torvalds committed
454 455
}

456
static void pms_vstart(struct pms *dev, short start)
Linus Torvalds's avatar
Linus Torvalds committed
457
{
458 459
	mvv_write(dev, 0x16, start);
	mvv_write(dev, 0x17, (start >> 8) & 0x01);
Linus Torvalds's avatar
Linus Torvalds committed
460 461 462 463
}

#endif

464
static void pms_secamcross(struct pms *dev, short cross)
Linus Torvalds's avatar
Linus Torvalds committed
465
{
466 467 468 469
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x0f, 0xdf, (cross & 1) << 5);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x0f, 0xdf, (cross & 1) << 5);
Linus Torvalds's avatar
Linus Torvalds committed
470 471 472
}


473
static void pms_swsense(struct pms *dev, short sense)
Linus Torvalds's avatar
Linus Torvalds committed
474
{
475 476 477 478 479 480
	if (dev->decoder == PHILIPS2) {
		pms_i2c_write(dev, 0x8a, 0x0a, sense);
		pms_i2c_write(dev, 0x8a, 0x0b, sense);
	} else if (dev->decoder == PHILIPS1) {
		pms_i2c_write(dev, 0x42, 0x0a, sense);
		pms_i2c_write(dev, 0x42, 0x0b, sense);
Linus Torvalds's avatar
Linus Torvalds committed
481 482 483 484
	}
}


485
static void pms_framerate(struct pms *dev, short frr)
Linus Torvalds's avatar
Linus Torvalds committed
486
{
487
	int fps = (dev->std & V4L2_STD_525_60) ? 30 : 25;
488 489

	if (frr == 0)
Linus Torvalds's avatar
Linus Torvalds committed
490
		return;
491 492 493
	fps = fps/frr;
	mvv_write(dev, 0x14, 0x80 | fps);
	mvv_write(dev, 0x15, 1);
Linus Torvalds's avatar
Linus Torvalds committed
494 495
}

496
static void pms_vert(struct pms *dev, u8 deciden, u8 decinum)
Linus Torvalds's avatar
Linus Torvalds committed
497
{
498 499
	mvv_write(dev, 0x1c, deciden);	/* Denominator */
	mvv_write(dev, 0x1d, decinum);	/* Numerator */
Linus Torvalds's avatar
Linus Torvalds committed
500 501 502 503 504
}

/*
 *	Turn 16bit ratios into best small ratio the chipset can grok
 */
505

506
static void pms_vertdeci(struct pms *dev, unsigned short decinum, unsigned short deciden)
Linus Torvalds's avatar
Linus Torvalds committed
507
{
508 509 510 511
	/* Knock it down by / 5 once */
	if (decinum % 5 == 0) {
		deciden /= 5;
		decinum /= 5;
Linus Torvalds's avatar
Linus Torvalds committed
512 513 514 515
	}
	/*
	 *	3's
	 */
516 517 518
	while (decinum % 3 == 0 && deciden % 3 == 0) {
		deciden /= 3;
		decinum /= 3;
Linus Torvalds's avatar
Linus Torvalds committed
519 520 521 522
	}
	/*
	 *	2's
	 */
523 524 525
	while (decinum % 2 == 0 && deciden % 2 == 0) {
		decinum /= 2;
		deciden /= 2;
Linus Torvalds's avatar
Linus Torvalds committed
526 527 528 529
	}
	/*
	 *	Fudgyify
	 */
530 531 532
	while (deciden > 32) {
		deciden /= 2;
		decinum = (decinum + 1) / 2;
Linus Torvalds's avatar
Linus Torvalds committed
533
	}
534
	if (deciden == 32)
Linus Torvalds's avatar
Linus Torvalds committed
535
		deciden--;
536
	pms_vert(dev, deciden, decinum);
Linus Torvalds's avatar
Linus Torvalds committed
537 538
}

539
static void pms_horzdeci(struct pms *dev, short decinum, short deciden)
Linus Torvalds's avatar
Linus Torvalds committed
540
{
541 542 543 544
	if (decinum <= 512) {
		if (decinum % 5 == 0) {
			decinum /= 5;
			deciden /= 5;
Linus Torvalds's avatar
Linus Torvalds committed
545
		}
546 547 548
	} else {
		decinum = 512;
		deciden = 640;	/* 768 would be ideal */
Linus Torvalds's avatar
Linus Torvalds committed
549
	}
550

551 552 553
	while (((decinum | deciden) & 1) == 0) {
		decinum >>= 1;
		deciden >>= 1;
Linus Torvalds's avatar
Linus Torvalds committed
554
	}
555 556 557
	while (deciden > 32) {
		deciden >>= 1;
		decinum = (decinum + 1) >> 1;
Linus Torvalds's avatar
Linus Torvalds committed
558
	}
559
	if (deciden == 32)
Linus Torvalds's avatar
Linus Torvalds committed
560
		deciden--;
561

562 563
	mvv_write(dev, 0x24, 0x80 | deciden);
	mvv_write(dev, 0x25, decinum);
Linus Torvalds's avatar
Linus Torvalds committed
564 565
}

566
static void pms_resolution(struct pms *dev, short width, short height)
Linus Torvalds's avatar
Linus Torvalds committed
567 568
{
	int fg_height;
569

570 571 572
	fg_height = height;
	if (fg_height > 280)
		fg_height = 280;
573

574 575
	mvv_write(dev, 0x18, fg_height);
	mvv_write(dev, 0x19, fg_height >> 8);
576

577
	if (dev->std & V4L2_STD_525_60) {
578 579 580 581
		mvv_write(dev, 0x1a, 0xfc);
		mvv_write(dev, 0x1b, 0x00);
		if (height > fg_height)
			pms_vertdeci(dev, 240, 240);
Linus Torvalds's avatar
Linus Torvalds committed
582
		else
583 584 585 586 587 588
			pms_vertdeci(dev, fg_height, 240);
	} else {
		mvv_write(dev, 0x1a, 0x1a);
		mvv_write(dev, 0x1b, 0x01);
		if (fg_height > 256)
			pms_vertdeci(dev, 270, 270);
Linus Torvalds's avatar
Linus Torvalds committed
589
		else
590
			pms_vertdeci(dev, fg_height, 270);
Linus Torvalds's avatar
Linus Torvalds committed
591
	}
592 593 594 595 596
	mvv_write(dev, 0x12, 0);
	mvv_write(dev, 0x13, MVVMEMORYWIDTH);
	mvv_write(dev, 0x42, 0x00);
	mvv_write(dev, 0x43, 0x00);
	mvv_write(dev, 0x44, MVVMEMORYWIDTH);
597

598 599
	mvv_write(dev, 0x22, width + 8);
	mvv_write(dev, 0x23, (width + 8) >> 8);
Linus Torvalds's avatar
Linus Torvalds committed
600

601
	if (dev->std & V4L2_STD_525_60)
602
		pms_horzdeci(dev, width, 640);
Linus Torvalds's avatar
Linus Torvalds committed
603
	else
604
		pms_horzdeci(dev, width + 8, 768);
Linus Torvalds's avatar
Linus Torvalds committed
605

606 607 608 609 610
	mvv_write(dev, 0x30, mvv_read(dev, 0x30) & 0xfe);
	mvv_write(dev, 0x08, mvv_read(dev, 0x08) | 0x01);
	mvv_write(dev, 0x01, mvv_read(dev, 0x01) & 0xfd);
	mvv_write(dev, 0x32, 0x00);
	mvv_write(dev, 0x33, MVVMEMORYWIDTH);
Linus Torvalds's avatar
Linus Torvalds committed
611 612 613 614 615 616
}


/*
 *	Set Input
 */
617

618
static void pms_vcrinput(struct pms *dev, short input)
Linus Torvalds's avatar
Linus Torvalds committed
619
{
620 621 622 623
	if (dev->decoder == PHILIPS2)
		pms_i2c_andor(dev, 0x8a, 0x0d, 0x7f, (input & 1) << 7);
	else if (dev->decoder == PHILIPS1)
		pms_i2c_andor(dev, 0x42, 0x0d, 0x7f, (input & 1) << 7);
Linus Torvalds's avatar
Linus Torvalds committed
624 625 626
}


627
static int pms_capture(struct pms *dev, char __user *buf, int rgb555, int count)
Linus Torvalds's avatar
Linus Torvalds committed
628 629
{
	int y;
630 631
	int dw = 2 * dev->width;
	char tmp[dw + 32]; /* using a temp buffer is faster than direct  */
Linus Torvalds's avatar
Linus Torvalds committed
632
	int cnt = 0;
633
	int len = 0;
Linus Torvalds's avatar
Linus Torvalds committed
634 635 636 637
	unsigned char r8 = 0x5;  /* value for reg8  */

	if (rgb555)
		r8 |= 0x20; /* else use untranslated rgb = 565 */
638
	mvv_write(dev, 0x08, r8); /* capture rgb555/565, init DRAM, PC enable */
Linus Torvalds's avatar
Linus Torvalds committed
639 640

/*	printf("%d %d %d %d %d %x %x\n",width,height,voff,nom,den,mvv_buf); */
641

642 643
	for (y = 0; y < dev->height; y++) {
		writeb(0, dev->mem);  /* synchronisiert neue Zeile */
644

Linus Torvalds's avatar
Linus Torvalds committed
645 646 647 648
		/*
		 *	This is in truth a fifo, be very careful as if you
		 *	forgot this odd things will occur 8)
		 */
649

650
		memcpy_fromio(tmp, dev->mem, dw + 32); /* discard 16 word   */
Linus Torvalds's avatar
Linus Torvalds committed
651
		cnt -= dev->height;
652
		while (cnt <= 0) {
Linus Torvalds's avatar
Linus Torvalds committed
653 654 655
			/*
			 *	Don't copy too far
			 */
656 657 658
			int dt = dw;
			if (dt + len > count)
				dt = count - len;
Linus Torvalds's avatar
Linus Torvalds committed
659
			cnt += dev->height;
660
			if (copy_to_user(buf, tmp + 32, dt))
Linus Torvalds's avatar
Linus Torvalds committed
661
				return len ? len : -EFAULT;
662
			buf += dt;
Linus Torvalds's avatar
Linus Torvalds committed
663 664 665 666 667 668 669 670 671 672 673
			len += dt;
		}
	}
	return len;
}


/*
 *	Video4linux interfacing
 */

674 675
static int pms_querycap(struct file *file, void  *priv,
					struct v4l2_capability *vcap)
Linus Torvalds's avatar
Linus Torvalds committed
676
{
677 678
	struct pms *dev = video_drvdata(file);

679 680
	strlcpy(vcap->driver, dev->v4l2_dev.name, sizeof(vcap->driver));
	strlcpy(vcap->card, "Mediavision PMS", sizeof(vcap->card));
681 682 683 684
	snprintf(vcap->bus_info, sizeof(vcap->bus_info),
			"ISA:%s", dev->v4l2_dev.name);
	vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
	vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
685 686
	return 0;
}
687

688 689 690 691 692 693 694 695
static int pms_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
{
	static const char *inputs[4] = {
		"Composite",
		"S-Video",
		"Composite (VCR)",
		"S-Video (VCR)"
	};
696

697 698 699 700 701 702 703 704 705 706
	if (vin->index > 3)
		return -EINVAL;
	strlcpy(vin->name, inputs[vin->index], sizeof(vin->name));
	vin->type = V4L2_INPUT_TYPE_CAMERA;
	vin->audioset = 0;
	vin->tuner = 0;
	vin->std = V4L2_STD_ALL;
	vin->status = 0;
	return 0;
}
707

708 709 710
static int pms_g_input(struct file *file, void *fh, unsigned int *inp)
{
	struct pms *dev = video_drvdata(file);
711

712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
	*inp = dev->input;
	return 0;
}

static int pms_s_input(struct file *file, void *fh, unsigned int inp)
{
	struct pms *dev = video_drvdata(file);

	if (inp > 3)
		return -EINVAL;

	dev->input = inp;
	pms_videosource(dev, inp & 1);
	pms_vcrinput(dev, inp >> 1);
	return 0;
}

static int pms_g_std(struct file *file, void *fh, v4l2_std_id *std)
{
	struct pms *dev = video_drvdata(file);

	*std = dev->std;
	return 0;
}

static int pms_s_std(struct file *file, void *fh, v4l2_std_id *std)
{
	struct pms *dev = video_drvdata(file);
	int ret = 0;

	dev->std = *std;
	if (dev->std & V4L2_STD_NTSC) {
		pms_framerate(dev, 30);
		pms_secamcross(dev, 0);
		pms_format(dev, 1);
	} else if (dev->std & V4L2_STD_PAL) {
		pms_framerate(dev, 25);
		pms_secamcross(dev, 0);
		pms_format(dev, 2);
	} else if (dev->std & V4L2_STD_SECAM) {
		pms_framerate(dev, 25);
		pms_secamcross(dev, 1);
		pms_format(dev, 2);
	} else {
		ret = -EINVAL;
757
	}
758 759 760 761 762 763 764 765 766 767 768
	/*
	switch (v->mode) {
	case VIDEO_MODE_AUTO:
		pms_framerate(dev, 25);
		pms_secamcross(dev, 0);
		pms_format(dev, 0);
		break;
	}*/
	return ret;
}

769
static int pms_s_ctrl(struct v4l2_ctrl *ctrl)
770
{
771
	struct pms *dev = container_of(ctrl->handler, struct pms, hdl);
772 773 774 775
	int ret = 0;

	switch (ctrl->id) {
	case V4L2_CID_BRIGHTNESS:
776
		pms_brightness(dev, ctrl->val);
777 778
		break;
	case V4L2_CID_CONTRAST:
779
		pms_contrast(dev, ctrl->val);
780 781
		break;
	case V4L2_CID_SATURATION:
782
		pms_saturation(dev, ctrl->val);
783 784
		break;
	case V4L2_CID_HUE:
785
		pms_hue(dev, ctrl->val);
786
		break;
787
	default:
788 789
		ret = -EINVAL;
		break;
Linus Torvalds's avatar
Linus Torvalds committed
790
	}
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
	return ret;
}

static int pms_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
{
	struct pms *dev = video_drvdata(file);
	struct v4l2_pix_format *pix = &fmt->fmt.pix;

	pix->width = dev->width;
	pix->height = dev->height;
	pix->pixelformat = dev->width == 15 ?
			    V4L2_PIX_FMT_RGB555 : V4L2_PIX_FMT_RGB565;
	pix->field = V4L2_FIELD_NONE;
	pix->bytesperline = 2 * dev->width;
	pix->sizeimage = 2 * dev->width * dev->height;
	/* Just a guess */
	pix->colorspace = V4L2_COLORSPACE_SRGB;
	return 0;
}

static int pms_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
{
	struct v4l2_pix_format *pix = &fmt->fmt.pix;

	if (pix->height < 16 || pix->height > 480)
		return -EINVAL;
	if (pix->width < 16 || pix->width > 640)
		return -EINVAL;
	if (pix->pixelformat != V4L2_PIX_FMT_RGB555 &&
	    pix->pixelformat != V4L2_PIX_FMT_RGB565)
		return -EINVAL;
	pix->field = V4L2_FIELD_NONE;
	pix->bytesperline = 2 * pix->width;
	pix->sizeimage = 2 * pix->width * pix->height;
	/* Just a guess */
	pix->colorspace = V4L2_COLORSPACE_SRGB;
Linus Torvalds's avatar
Linus Torvalds committed
827 828 829
	return 0;
}

830
static int pms_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
Linus Torvalds's avatar
Linus Torvalds committed
831
{
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
	struct pms *dev = video_drvdata(file);
	struct v4l2_pix_format *pix = &fmt->fmt.pix;
	int ret = pms_try_fmt_vid_cap(file, fh, fmt);

	if (ret)
		return ret;
	dev->width = pix->width;
	dev->height = pix->height;
	dev->depth = (pix->pixelformat == V4L2_PIX_FMT_RGB555) ? 15 : 16;
	pms_resolution(dev, dev->width, dev->height);
	/* Ok we figured out what to use from our wide choice */
	return 0;
}

static int pms_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
{
	static struct v4l2_fmtdesc formats[] = {
		{ 0, 0, 0,
		  "RGB 5:5:5", V4L2_PIX_FMT_RGB555,
		  { 0, 0, 0, 0 }
		},
853
		{ 1, 0, 0,
854 855 856 857 858 859 860 861 862 863 864 865
		  "RGB 5:6:5", V4L2_PIX_FMT_RGB565,
		  { 0, 0, 0, 0 }
		},
	};
	enum v4l2_buf_type type = fmt->type;

	if (fmt->index > 1)
		return -EINVAL;

	*fmt = formats[fmt->index];
	fmt->type = type;
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
866 867 868 869 870
}

static ssize_t pms_read(struct file *file, char __user *buf,
		    size_t count, loff_t *ppos)
{
871
	struct pms *dev = video_drvdata(file);
Linus Torvalds's avatar
Linus Torvalds committed
872
	int len;
873

874
	len = pms_capture(dev, buf, (dev->depth == 15), count);
Linus Torvalds's avatar
Linus Torvalds committed
875 876 877
	return len;
}

878 879 880 881 882 883 884 885 886 887 888
static unsigned int pms_poll(struct file *file, struct poll_table_struct *wait)
{
	struct v4l2_fh *fh = file->private_data;
	unsigned int res = POLLIN | POLLRDNORM;

	if (v4l2_event_pending(fh))
		res |= POLLPRI;
	poll_wait(file, &fh->wait, wait);
	return res;
}

889
static const struct v4l2_file_operations pms_fops = {
Linus Torvalds's avatar
Linus Torvalds committed
890
	.owner		= THIS_MODULE,
891 892 893
	.open           = v4l2_fh_open,
	.release        = v4l2_fh_release,
	.poll           = pms_poll,
894
	.unlocked_ioctl	= video_ioctl2,
Linus Torvalds's avatar
Linus Torvalds committed
895 896 897
	.read           = pms_read,
};

898
static const struct v4l2_ioctl_ops pms_ioctl_ops = {
899 900 901 902 903 904 905 906 907 908 909 910
	.vidioc_querycap	    = pms_querycap,
	.vidioc_g_input		    = pms_g_input,
	.vidioc_s_input		    = pms_s_input,
	.vidioc_enum_input	    = pms_enum_input,
	.vidioc_g_std		    = pms_g_std,
	.vidioc_s_std		    = pms_s_std,
	.vidioc_enum_fmt_vid_cap    = pms_enum_fmt_vid_cap,
	.vidioc_g_fmt_vid_cap	    = pms_g_fmt_vid_cap,
	.vidioc_s_fmt_vid_cap	    = pms_s_fmt_vid_cap,
	.vidioc_try_fmt_vid_cap     = pms_try_fmt_vid_cap,
	.vidioc_subscribe_event     = v4l2_ctrl_subscribe_event,
	.vidioc_unsubscribe_event   = v4l2_event_unsubscribe,
911
};
Linus Torvalds's avatar
Linus Torvalds committed
912 913 914 915

/*
 *	Probe for and initialise the Mediavision PMS
 */
916

917
static int init_mediavision(struct pms *dev)
Linus Torvalds's avatar
Linus Torvalds committed
918 919 920 921
{
	int id;
	int idec, decst;
	int i;
922 923 924 925 926 927 928 929
	static const unsigned char i2c_defs[] = {
		0x4c, 0x30, 0x00, 0xe8,
		0xb6, 0xe2, 0x00, 0x00,
		0xff, 0xff, 0x00, 0x00,
		0x00, 0x00, 0x78, 0x98,
		0x00, 0x00, 0x00, 0x00,
		0x34, 0x0a, 0xf4, 0xce,
		0xe4
Linus Torvalds's avatar
Linus Torvalds committed
930 931
	};

932 933
	dev->mem = ioremap(mem_base, 0x800);
	if (!dev->mem)
Linus Torvalds's avatar
Linus Torvalds committed
934
		return -ENOMEM;
935

936 937 938
	if (!request_region(0x9a01, 1, "Mediavision PMS config")) {
		printk(KERN_WARNING "mediavision: unable to detect: 0x9a01 in use.\n");
		iounmap(dev->mem);
Linus Torvalds's avatar
Linus Torvalds committed
939 940
		return -EBUSY;
	}
941 942 943 944
	if (!request_region(dev->io, 3, "Mediavision PMS")) {
		printk(KERN_WARNING "mediavision: I/O port %d in use.\n", dev->io);
		release_region(0x9a01, 1);
		iounmap(dev->mem);
Linus Torvalds's avatar
Linus Torvalds committed
945 946
		return -EBUSY;
	}
947 948
	outb(0xb8, 0x9a01);		/* Unlock */
	outb(dev->io >> 4, 0x9a01);	/* Set IO port */
949 950


951 952
	id = mvv_read(dev, 3);
	decst = pms_i2c_stat(dev, 0x43);
953

954 955 956 957 958 959
	if (decst != -1)
		idec = 2;
	else if (pms_i2c_stat(dev, 0xb9) != -1)
		idec = 3;
	else if (pms_i2c_stat(dev, 0x8b) != -1)
		idec = 1;
960
	else
961
		idec = 0;
Linus Torvalds's avatar
Linus Torvalds committed
962 963

	printk(KERN_INFO "PMS type is %d\n", idec);
964 965 966 967
	if (idec == 0) {
		release_region(dev->io, 3);
		release_region(0x9a01, 1);
		iounmap(dev->mem);
Linus Torvalds's avatar
Linus Torvalds committed
968 969 970 971 972 973
		return -ENODEV;
	}

	/*
	 *	Ok we have a PMS of some sort
	 */
974

975
	mvv_write(dev, 0x04, mem_base >> 12);	/* Set the memory area */
976

Linus Torvalds's avatar
Linus Torvalds committed
977
	/* Ok now load the defaults */
978

979 980 981
	for (i = 0; i < 0x19; i++) {
		if (i2c_defs[i] == 0xff)
			pms_i2c_andor(dev, 0x8a, i, 0x07, 0x00);
Linus Torvalds's avatar
Linus Torvalds committed
982
		else
983
			pms_i2c_write(dev, 0x8a, i, i2c_defs[i]);
Linus Torvalds's avatar
Linus Torvalds committed
984
	}
985

986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
	pms_i2c_write(dev, 0xb8, 0x00, 0x12);
	pms_i2c_write(dev, 0xb8, 0x04, 0x00);
	pms_i2c_write(dev, 0xb8, 0x07, 0x00);
	pms_i2c_write(dev, 0xb8, 0x08, 0x00);
	pms_i2c_write(dev, 0xb8, 0x09, 0xff);
	pms_i2c_write(dev, 0xb8, 0x0a, 0x00);
	pms_i2c_write(dev, 0xb8, 0x0b, 0x10);
	pms_i2c_write(dev, 0xb8, 0x10, 0x03);

	mvv_write(dev, 0x01, 0x00);
	mvv_write(dev, 0x05, 0xa0);
	mvv_write(dev, 0x08, 0x25);
	mvv_write(dev, 0x09, 0x00);
	mvv_write(dev, 0x0a, 0x20 | MVVMEMORYWIDTH);

	mvv_write(dev, 0x10, 0x02);
	mvv_write(dev, 0x1e, 0x0c);
	mvv_write(dev, 0x1f, 0x03);
	mvv_write(dev, 0x26, 0x06);

	mvv_write(dev, 0x2b, 0x00);
	mvv_write(dev, 0x2c, 0x20);
	mvv_write(dev, 0x2d, 0x00);
	mvv_write(dev, 0x2f, 0x70);
	mvv_write(dev, 0x32, 0x00);
	mvv_write(dev, 0x33, MVVMEMORYWIDTH);
	mvv_write(dev, 0x34, 0x00);
	mvv_write(dev, 0x35, 0x00);
	mvv_write(dev, 0x3a, 0x80);
	mvv_write(dev, 0x3b, 0x10);
	mvv_write(dev, 0x20, 0x00);
	mvv_write(dev, 0x21, 0x00);
	mvv_write(dev, 0x30, 0x22);
Linus Torvalds's avatar
Linus Torvalds committed
1019 1020 1021 1022 1023 1024
	return 0;
}

/*
 *	Initialization and module stuff
 */
1025

1026 1027 1028 1029 1030
#ifndef MODULE
static int enable;
module_param(enable, int, 0);
#endif

1031 1032 1033 1034 1035
static const struct v4l2_ctrl_ops pms_ctrl_ops = {
	.s_ctrl = pms_s_ctrl,
};

static int pms_probe(struct device *pdev, unsigned int card)
Linus Torvalds's avatar
Linus Torvalds committed
1036
{
1037 1038 1039
	struct pms *dev;
	struct v4l2_device *v4l2_dev;
	struct v4l2_ctrl_handler *hdl;
1040 1041
	int res;

1042 1043
#ifndef MODULE
	if (!enable) {
1044
		pr_err("PMS: not enabled, use pms.enable=1 to probe\n");
1045 1046 1047 1048
		return -ENODEV;
	}
#endif

1049 1050 1051 1052
	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (dev == NULL)
		return -ENOMEM;

1053 1054 1055
	dev->decoder = PHILIPS2;
	dev->io = io_port;
	dev->data = io_port + 1;
1056 1057
	v4l2_dev = &dev->v4l2_dev;
	hdl = &dev->hdl;
1058

1059 1060 1061 1062 1063 1064 1065 1066 1067
	res = v4l2_device_register(pdev, v4l2_dev);
	if (res < 0) {
		v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
		goto free_dev;
	}
	v4l2_info(v4l2_dev, "Mediavision Pro Movie Studio driver 0.05\n");

	res = init_mediavision(dev);
	if (res) {
1068
		v4l2_err(v4l2_dev, "Board not found.\n");
1069
		goto free_io;
Linus Torvalds's avatar
Linus Torvalds committed
1070 1071
	}

1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
	v4l2_ctrl_handler_init(hdl, 4);
	v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
			V4L2_CID_BRIGHTNESS, 0, 255, 1, 139);
	v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
			V4L2_CID_CONTRAST, 0, 255, 1, 70);
	v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
			V4L2_CID_SATURATION, 0, 255, 1, 64);
	v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
			V4L2_CID_HUE, 0, 255, 1, 0);
	if (hdl->error) {
		res = hdl->error;
		goto free_hdl;
1084
	}
Linus Torvalds's avatar
Linus Torvalds committed
1085

1086
	mutex_init(&dev->lock);
1087 1088
	strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
	dev->vdev.v4l2_dev = v4l2_dev;
1089
	dev->vdev.ctrl_handler = hdl;
1090
	dev->vdev.fops = &pms_fops;
1091
	dev->vdev.ioctl_ops = &pms_ioctl_ops;
1092
	dev->vdev.release = video_device_release_empty;
1093 1094 1095
	dev->vdev.lock = &dev->lock;
	dev->vdev.tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
	set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
1096
	video_set_drvdata(&dev->vdev, dev);
1097
	dev->std = V4L2_STD_NTSC_M;
1098 1099
	dev->height = 240;
	dev->width = 320;
1100
	dev->depth = 16;
1101 1102 1103 1104
	pms_swsense(dev, 75);
	pms_resolution(dev, 320, 240);
	pms_videosource(dev, 0);
	pms_vcrinput(dev, 0);
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
	v4l2_ctrl_handler_setup(hdl);
	res = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, video_nr);
	if (res >= 0)
		return 0;

free_hdl:
	v4l2_ctrl_handler_free(hdl);
	v4l2_device_unregister(&dev->v4l2_dev);
free_io:
	release_region(dev->io, 3);
	release_region(0x9a01, 1);
	iounmap(dev->mem);
free_dev:
	kfree(dev);
	return res;
Linus Torvalds's avatar
Linus Torvalds committed
1120 1121
}

1122
static int pms_remove(struct device *pdev, unsigned int card)
Linus Torvalds's avatar
Linus Torvalds committed
1123
{
1124
	struct pms *dev = dev_get_drvdata(pdev);
Linus Torvalds's avatar
Linus Torvalds committed
1125

1126
	video_unregister_device(&dev->vdev);
1127
	v4l2_ctrl_handler_free(&dev->hdl);
1128 1129 1130
	release_region(dev->io, 3);
	release_region(0x9a01, 1);
	iounmap(dev->mem);
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
	return 0;
}

static struct isa_driver pms_driver = {
	.probe		= pms_probe,
	.remove		= pms_remove,
	.driver		= {
		.name	= "pms",
	},
};

static int __init pms_init(void)
{
	return isa_register_driver(&pms_driver, 1);
}

static void __exit pms_exit(void)
{
	isa_unregister_driver(&pms_driver);
1150
}
Linus Torvalds's avatar
Linus Torvalds committed
1151

1152 1153
module_init(pms_init);
module_exit(pms_exit);