2 * Media Vision Pro Movie Studio
4 * "all you need is an I2C bus some RAM and a prayer"
6 * This draws heavily on code
8 * (c) Wolfgang Koehler, wolf@first.gmd.de, Dec. 1994
10 * 14478 Potsdam, Germany
12 * Most of this code is directly derived from his userspace driver.
13 * His driver works so send any reports to alan@lxorguk.ukuu.org.uk
14 * unless the userspace driver also doesn't work for you...
17 * 25-11-2009 Hans Verkuil <hverkuil@xs4all.nl>
18 * - converted to version 2 of the V4L API.
19 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
20 * - pms_capture: report back -EFAULT
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
32 #include <linux/version.h>
33 #include <linux/mutex.h>
34 #include <linux/uaccess.h>
37 #include <linux/videodev2.h>
38 #include <media/v4l2-common.h>
39 #include <media/v4l2-ioctl.h>
40 #include <media/v4l2-device.h>
42 MODULE_LICENSE("GPL");
46 #define PHILIPS2 2 /* SAA7191 */
48 #define MVVMEMORYWIDTH 0x40 /* 512 bytes */
58 struct v4l2_device v4l2_dev
;
59 struct video_device vdev
;
64 s32 brightness
, saturation
, hue
, contrast
;
68 struct i2c_info i2cinfo
[64];
71 int standard
; /* 0 - auto 1 - ntsc 2 - pal 3 - secam */
78 static struct pms pms_card
;
81 * I/O ports and Shared Memory
84 static int io_port
= 0x250;
85 module_param(io_port
, int, 0);
87 static int mem_base
= 0xc8000;
88 module_param(mem_base
, int, 0);
90 static int video_nr
= -1;
91 module_param(video_nr
, int, 0);
94 static inline void mvv_write(struct pms
*dev
, u8 index
, u8 value
)
96 outw(index
| (value
<< 8), dev
->io
);
99 static inline u8
mvv_read(struct pms
*dev
, u8 index
)
101 outb(index
, dev
->io
);
102 return inb(dev
->data
);
105 static int pms_i2c_stat(struct pms
*dev
, u8 slave
)
112 while ((inb(dev
->data
) & 0x01) == 0)
113 if (counter
++ == 256)
116 while ((inb(dev
->data
) & 0x01) != 0)
117 if (counter
++ == 256)
120 outb(slave
, dev
->io
);
123 while ((inb(dev
->data
) & 0x01) == 0)
124 if (counter
++ == 256)
127 while ((inb(dev
->data
) & 0x01) != 0)
128 if (counter
++ == 256)
131 for (i
= 0; i
< 12; i
++) {
132 char st
= inb(dev
->data
);
140 return inb(dev
->data
);
143 static int pms_i2c_write(struct pms
*dev
, u16 slave
, u16 sub
, u16 data
)
149 for (i
= 0; i
< dev
->i2c_count
; i
++) {
150 if ((dev
->i2cinfo
[i
].slave
== slave
) &&
151 (dev
->i2cinfo
[i
].sub
== sub
)) {
152 if (dev
->i2cinfo
[i
].data
== data
)
154 dev
->i2cinfo
[i
].data
= data
;
155 i
= dev
->i2c_count
+ 1;
159 if (i
== dev
->i2c_count
&& dev
->i2c_count
< 64) {
160 dev
->i2cinfo
[dev
->i2c_count
].slave
= slave
;
161 dev
->i2cinfo
[dev
->i2c_count
].sub
= sub
;
162 dev
->i2cinfo
[dev
->i2c_count
].data
= data
;
169 mvv_write(dev
, 0x29, sub
);
170 mvv_write(dev
, 0x2A, data
);
171 mvv_write(dev
, 0x28, slave
);
176 while ((inb(dev
->data
) & 1) == 0)
179 while ((inb(dev
->data
) & 1) != 0)
183 count
= inb(dev
->data
);
190 static int pms_i2c_read(struct pms
*dev
, int slave
, int sub
)
194 for (i
= 0; i
< dev
->i2c_count
; i
++) {
195 if (dev
->i2cinfo
[i
].slave
== slave
&& dev
->i2cinfo
[i
].sub
== sub
)
196 return dev
->i2cinfo
[i
].data
;
202 static void pms_i2c_andor(struct pms
*dev
, int slave
, int sub
, int and, int or)
206 tmp
= pms_i2c_read(dev
, slave
, sub
);
207 tmp
= (tmp
& and) | or;
208 pms_i2c_write(dev
, slave
, sub
, tmp
);
216 static void pms_videosource(struct pms
*dev
, short source
)
218 switch (dev
->decoder
) {
222 pms_i2c_andor(dev
, 0x8a, 0x06, 0x7f, source
? 0x80 : 0);
227 mvv_write(dev
, 0x2E, 0x31);
228 /* Was: mvv_write(dev, 0x2E, source ? 0x31 : 0x30);
229 But could not make this work correctly. Only Composite input
233 static void pms_hue(struct pms
*dev
, short hue
)
235 switch (dev
->decoder
) {
237 pms_i2c_write(dev
, 0x8a, 0x00, hue
);
240 pms_i2c_write(dev
, 0x8a, 0x07, hue
);
243 pms_i2c_write(dev
, 0x42, 0x07, hue
);
248 static void pms_saturation(struct pms
*dev
, short sat
)
250 switch (dev
->decoder
) {
252 pms_i2c_write(dev
, 0x8a, 0x00, sat
);
255 pms_i2c_write(dev
, 0x42, 0x12, sat
);
261 static void pms_contrast(struct pms
*dev
, short contrast
)
263 switch (dev
->decoder
) {
265 pms_i2c_write(dev
, 0x8a, 0x00, contrast
);
268 pms_i2c_write(dev
, 0x42, 0x13, contrast
);
273 static void pms_brightness(struct pms
*dev
, short brightness
)
275 switch (dev
->decoder
) {
277 pms_i2c_write(dev
, 0x8a, 0x00, brightness
);
278 pms_i2c_write(dev
, 0x8a, 0x00, brightness
);
279 pms_i2c_write(dev
, 0x8a, 0x00, brightness
);
282 pms_i2c_write(dev
, 0x42, 0x19, brightness
);
288 static void pms_format(struct pms
*dev
, short format
)
292 dev
->standard
= format
;
294 if (dev
->decoder
== PHILIPS1
)
296 else if (dev
->decoder
== PHILIPS2
)
303 pms_i2c_andor(dev
, target
, 0x0d, 0xfe, 0x00);
304 pms_i2c_andor(dev
, target
, 0x0f, 0x3f, 0x80);
307 pms_i2c_andor(dev
, target
, 0x0d, 0xfe, 0x00);
308 pms_i2c_andor(dev
, target
, 0x0f, 0x3f, 0x40);
311 pms_i2c_andor(dev
, target
, 0x0d, 0xfe, 0x00);
312 pms_i2c_andor(dev
, target
, 0x0f, 0x3f, 0x00);
315 pms_i2c_andor(dev
, target
, 0x0d, 0xfe, 0x01);
316 pms_i2c_andor(dev
, target
, 0x0f, 0x3f, 0x00);
321 #ifdef FOR_FUTURE_EXPANSION
324 * These features of the PMS card are not currently exposes. They
325 * could become a private v4l ioctl for PMSCONFIG or somesuch if
326 * people need it. We also don't yet use the PMS interrupt.
329 static void pms_hstart(struct pms
*dev
, short start
)
331 switch (dev
->decoder
) {
333 pms_i2c_write(dev
, 0x8a, 0x05, start
);
334 pms_i2c_write(dev
, 0x8a, 0x18, start
);
337 pms_i2c_write(dev
, 0x42, 0x05, start
);
338 pms_i2c_write(dev
, 0x42, 0x18, start
);
347 static void pms_bandpass(struct pms
*dev
, short pass
)
349 if (dev
->decoder
== PHILIPS2
)
350 pms_i2c_andor(dev
, 0x8a, 0x06, 0xcf, (pass
& 0x03) << 4);
351 else if (dev
->decoder
== PHILIPS1
)
352 pms_i2c_andor(dev
, 0x42, 0x06, 0xcf, (pass
& 0x03) << 4);
355 static void pms_antisnow(struct pms
*dev
, short snow
)
357 if (dev
->decoder
== PHILIPS2
)
358 pms_i2c_andor(dev
, 0x8a, 0x06, 0xf3, (snow
& 0x03) << 2);
359 else if (dev
->decoder
== PHILIPS1
)
360 pms_i2c_andor(dev
, 0x42, 0x06, 0xf3, (snow
& 0x03) << 2);
363 static void pms_sharpness(struct pms
*dev
, short sharp
)
365 if (dev
->decoder
== PHILIPS2
)
366 pms_i2c_andor(dev
, 0x8a, 0x06, 0xfc, sharp
& 0x03);
367 else if (dev
->decoder
== PHILIPS1
)
368 pms_i2c_andor(dev
, 0x42, 0x06, 0xfc, sharp
& 0x03);
371 static void pms_chromaagc(struct pms
*dev
, short agc
)
373 if (dev
->decoder
== PHILIPS2
)
374 pms_i2c_andor(dev
, 0x8a, 0x0c, 0x9f, (agc
& 0x03) << 5);
375 else if (dev
->decoder
== PHILIPS1
)
376 pms_i2c_andor(dev
, 0x42, 0x0c, 0x9f, (agc
& 0x03) << 5);
379 static void pms_vertnoise(struct pms
*dev
, short noise
)
381 if (dev
->decoder
== PHILIPS2
)
382 pms_i2c_andor(dev
, 0x8a, 0x10, 0xfc, noise
& 3);
383 else if (dev
->decoder
== PHILIPS1
)
384 pms_i2c_andor(dev
, 0x42, 0x10, 0xfc, noise
& 3);
387 static void pms_forcecolour(struct pms
*dev
, short colour
)
389 if (dev
->decoder
== PHILIPS2
)
390 pms_i2c_andor(dev
, 0x8a, 0x0c, 0x7f, (colour
& 1) << 7);
391 else if (dev
->decoder
== PHILIPS1
)
392 pms_i2c_andor(dev
, 0x42, 0x0c, 0x7, (colour
& 1) << 7);
395 static void pms_antigamma(struct pms
*dev
, short gamma
)
397 if (dev
->decoder
== PHILIPS2
)
398 pms_i2c_andor(dev
, 0xb8, 0x00, 0x7f, (gamma
& 1) << 7);
399 else if (dev
->decoder
== PHILIPS1
)
400 pms_i2c_andor(dev
, 0x42, 0x20, 0x7, (gamma
& 1) << 7);
403 static void pms_prefilter(struct pms
*dev
, short filter
)
405 if (dev
->decoder
== PHILIPS2
)
406 pms_i2c_andor(dev
, 0x8a, 0x06, 0xbf, (filter
& 1) << 6);
407 else if (dev
->decoder
== PHILIPS1
)
408 pms_i2c_andor(dev
, 0x42, 0x06, 0xbf, (filter
& 1) << 6);
411 static void pms_hfilter(struct pms
*dev
, short filter
)
413 if (dev
->decoder
== PHILIPS2
)
414 pms_i2c_andor(dev
, 0xb8, 0x04, 0x1f, (filter
& 7) << 5);
415 else if (dev
->decoder
== PHILIPS1
)
416 pms_i2c_andor(dev
, 0x42, 0x24, 0x1f, (filter
& 7) << 5);
419 static void pms_vfilter(struct pms
*dev
, short filter
)
421 if (dev
->decoder
== PHILIPS2
)
422 pms_i2c_andor(dev
, 0xb8, 0x08, 0x9f, (filter
& 3) << 5);
423 else if (dev
->decoder
== PHILIPS1
)
424 pms_i2c_andor(dev
, 0x42, 0x28, 0x9f, (filter
& 3) << 5);
427 static void pms_killcolour(struct pms
*dev
, short colour
)
429 if (dev
->decoder
== PHILIPS2
) {
430 pms_i2c_andor(dev
, 0x8a, 0x08, 0x07, (colour
& 0x1f) << 3);
431 pms_i2c_andor(dev
, 0x8a, 0x09, 0x07, (colour
& 0x1f) << 3);
432 } else if (dev
->decoder
== PHILIPS1
) {
433 pms_i2c_andor(dev
, 0x42, 0x08, 0x07, (colour
& 0x1f) << 3);
434 pms_i2c_andor(dev
, 0x42, 0x09, 0x07, (colour
& 0x1f) << 3);
438 static void pms_chromagain(struct pms
*dev
, short chroma
)
440 if (dev
->decoder
== PHILIPS2
)
441 pms_i2c_write(dev
, 0x8a, 0x11, chroma
);
442 else if (dev
->decoder
== PHILIPS1
)
443 pms_i2c_write(dev
, 0x42, 0x11, chroma
);
447 static void pms_spacialcompl(struct pms
*dev
, short data
)
449 mvv_write(dev
, 0x3b, data
);
452 static void pms_spacialcomph(struct pms
*dev
, short data
)
454 mvv_write(dev
, 0x3a, data
);
457 static void pms_vstart(struct pms
*dev
, short start
)
459 mvv_write(dev
, 0x16, start
);
460 mvv_write(dev
, 0x17, (start
>> 8) & 0x01);
465 static void pms_secamcross(struct pms
*dev
, short cross
)
467 if (dev
->decoder
== PHILIPS2
)
468 pms_i2c_andor(dev
, 0x8a, 0x0f, 0xdf, (cross
& 1) << 5);
469 else if (dev
->decoder
== PHILIPS1
)
470 pms_i2c_andor(dev
, 0x42, 0x0f, 0xdf, (cross
& 1) << 5);
474 static void pms_swsense(struct pms
*dev
, short sense
)
476 if (dev
->decoder
== PHILIPS2
) {
477 pms_i2c_write(dev
, 0x8a, 0x0a, sense
);
478 pms_i2c_write(dev
, 0x8a, 0x0b, sense
);
479 } else if (dev
->decoder
== PHILIPS1
) {
480 pms_i2c_write(dev
, 0x42, 0x0a, sense
);
481 pms_i2c_write(dev
, 0x42, 0x0b, sense
);
486 static void pms_framerate(struct pms
*dev
, short frr
)
488 int fps
= (dev
->std
& V4L2_STD_525_60
) ? 30 : 25;
493 mvv_write(dev
, 0x14, 0x80 | fps
);
494 mvv_write(dev
, 0x15, 1);
497 static void pms_vert(struct pms
*dev
, u8 deciden
, u8 decinum
)
499 mvv_write(dev
, 0x1c, deciden
); /* Denominator */
500 mvv_write(dev
, 0x1d, decinum
); /* Numerator */
504 * Turn 16bit ratios into best small ratio the chipset can grok
507 static void pms_vertdeci(struct pms
*dev
, unsigned short decinum
, unsigned short deciden
)
509 /* Knock it down by / 5 once */
510 if (decinum
% 5 == 0) {
517 while (decinum
% 3 == 0 && deciden
% 3 == 0) {
524 while (decinum
% 2 == 0 && deciden
% 2 == 0) {
531 while (deciden
> 32) {
533 decinum
= (decinum
+ 1) / 2;
537 pms_vert(dev
, deciden
, decinum
);
540 static void pms_horzdeci(struct pms
*dev
, short decinum
, short deciden
)
542 if (decinum
<= 512) {
543 if (decinum
% 5 == 0) {
549 deciden
= 640; /* 768 would be ideal */
552 while (((decinum
| deciden
) & 1) == 0) {
556 while (deciden
> 32) {
558 decinum
= (decinum
+ 1) >> 1;
563 mvv_write(dev
, 0x24, 0x80 | deciden
);
564 mvv_write(dev
, 0x25, decinum
);
567 static void pms_resolution(struct pms
*dev
, short width
, short height
)
575 mvv_write(dev
, 0x18, fg_height
);
576 mvv_write(dev
, 0x19, fg_height
>> 8);
578 if (dev
->std
& V4L2_STD_525_60
) {
579 mvv_write(dev
, 0x1a, 0xfc);
580 mvv_write(dev
, 0x1b, 0x00);
581 if (height
> fg_height
)
582 pms_vertdeci(dev
, 240, 240);
584 pms_vertdeci(dev
, fg_height
, 240);
586 mvv_write(dev
, 0x1a, 0x1a);
587 mvv_write(dev
, 0x1b, 0x01);
589 pms_vertdeci(dev
, 270, 270);
591 pms_vertdeci(dev
, fg_height
, 270);
593 mvv_write(dev
, 0x12, 0);
594 mvv_write(dev
, 0x13, MVVMEMORYWIDTH
);
595 mvv_write(dev
, 0x42, 0x00);
596 mvv_write(dev
, 0x43, 0x00);
597 mvv_write(dev
, 0x44, MVVMEMORYWIDTH
);
599 mvv_write(dev
, 0x22, width
+ 8);
600 mvv_write(dev
, 0x23, (width
+ 8) >> 8);
602 if (dev
->std
& V4L2_STD_525_60
)
603 pms_horzdeci(dev
, width
, 640);
605 pms_horzdeci(dev
, width
+ 8, 768);
607 mvv_write(dev
, 0x30, mvv_read(dev
, 0x30) & 0xfe);
608 mvv_write(dev
, 0x08, mvv_read(dev
, 0x08) | 0x01);
609 mvv_write(dev
, 0x01, mvv_read(dev
, 0x01) & 0xfd);
610 mvv_write(dev
, 0x32, 0x00);
611 mvv_write(dev
, 0x33, MVVMEMORYWIDTH
);
619 static void pms_vcrinput(struct pms
*dev
, short input
)
621 if (dev
->decoder
== PHILIPS2
)
622 pms_i2c_andor(dev
, 0x8a, 0x0d, 0x7f, (input
& 1) << 7);
623 else if (dev
->decoder
== PHILIPS1
)
624 pms_i2c_andor(dev
, 0x42, 0x0d, 0x7f, (input
& 1) << 7);
628 static int pms_capture(struct pms
*dev
, char __user
*buf
, int rgb555
, int count
)
631 int dw
= 2 * dev
->width
;
632 char tmp
[dw
+ 32]; /* using a temp buffer is faster than direct */
635 unsigned char r8
= 0x5; /* value for reg8 */
638 r8
|= 0x20; /* else use untranslated rgb = 565 */
639 mvv_write(dev
, 0x08, r8
); /* capture rgb555/565, init DRAM, PC enable */
641 /* printf("%d %d %d %d %d %x %x\n",width,height,voff,nom,den,mvv_buf); */
643 for (y
= 0; y
< dev
->height
; y
++) {
644 writeb(0, dev
->mem
); /* synchronisiert neue Zeile */
647 * This is in truth a fifo, be very careful as if you
648 * forgot this odd things will occur 8)
651 memcpy_fromio(tmp
, dev
->mem
, dw
+ 32); /* discard 16 word */
658 if (dt
+ len
> count
)
661 if (copy_to_user(buf
, tmp
+ 32, dt
))
662 return len
? len
: -EFAULT
;
672 * Video4linux interfacing
675 static int pms_querycap(struct file
*file
, void *priv
,
676 struct v4l2_capability
*vcap
)
678 struct pms
*dev
= video_drvdata(file
);
680 strlcpy(vcap
->driver
, dev
->v4l2_dev
.name
, sizeof(vcap
->driver
));
681 strlcpy(vcap
->card
, "Mediavision PMS", sizeof(vcap
->card
));
682 strlcpy(vcap
->bus_info
, "ISA", sizeof(vcap
->bus_info
));
683 vcap
->version
= KERNEL_VERSION(0, 0, 3);
684 vcap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_READWRITE
;
688 static int pms_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
690 static const char *inputs
[4] = {
699 strlcpy(vin
->name
, inputs
[vin
->index
], sizeof(vin
->name
));
700 vin
->type
= V4L2_INPUT_TYPE_CAMERA
;
703 vin
->std
= V4L2_STD_ALL
;
708 static int pms_g_input(struct file
*file
, void *fh
, unsigned int *inp
)
710 struct pms
*dev
= video_drvdata(file
);
716 static int pms_s_input(struct file
*file
, void *fh
, unsigned int inp
)
718 struct pms
*dev
= video_drvdata(file
);
723 mutex_lock(&dev
->lock
);
725 pms_videosource(dev
, inp
& 1);
726 pms_vcrinput(dev
, inp
>> 1);
727 mutex_unlock(&dev
->lock
);
731 static int pms_g_std(struct file
*file
, void *fh
, v4l2_std_id
*std
)
733 struct pms
*dev
= video_drvdata(file
);
739 static int pms_s_std(struct file
*file
, void *fh
, v4l2_std_id
*std
)
741 struct pms
*dev
= video_drvdata(file
);
745 mutex_lock(&dev
->lock
);
746 if (dev
->std
& V4L2_STD_NTSC
) {
747 pms_framerate(dev
, 30);
748 pms_secamcross(dev
, 0);
750 } else if (dev
->std
& V4L2_STD_PAL
) {
751 pms_framerate(dev
, 25);
752 pms_secamcross(dev
, 0);
754 } else if (dev
->std
& V4L2_STD_SECAM
) {
755 pms_framerate(dev
, 25);
756 pms_secamcross(dev
, 1);
763 case VIDEO_MODE_AUTO:
764 pms_framerate(dev, 25);
765 pms_secamcross(dev, 0);
769 mutex_unlock(&dev
->lock
);
773 static int pms_queryctrl(struct file
*file
, void *priv
,
774 struct v4l2_queryctrl
*qc
)
777 case V4L2_CID_BRIGHTNESS
:
778 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 139);
779 case V4L2_CID_CONTRAST
:
780 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 70);
781 case V4L2_CID_SATURATION
:
782 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 64);
784 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 0);
789 static int pms_g_ctrl(struct file
*file
, void *priv
,
790 struct v4l2_control
*ctrl
)
792 struct pms
*dev
= video_drvdata(file
);
796 case V4L2_CID_BRIGHTNESS
:
797 ctrl
->value
= dev
->brightness
;
799 case V4L2_CID_CONTRAST
:
800 ctrl
->value
= dev
->contrast
;
802 case V4L2_CID_SATURATION
:
803 ctrl
->value
= dev
->saturation
;
806 ctrl
->value
= dev
->hue
;
815 static int pms_s_ctrl(struct file
*file
, void *priv
,
816 struct v4l2_control
*ctrl
)
818 struct pms
*dev
= video_drvdata(file
);
821 mutex_lock(&dev
->lock
);
823 case V4L2_CID_BRIGHTNESS
:
824 dev
->brightness
= ctrl
->value
;
825 pms_brightness(dev
, dev
->brightness
);
827 case V4L2_CID_CONTRAST
:
828 dev
->contrast
= ctrl
->value
;
829 pms_contrast(dev
, dev
->contrast
);
831 case V4L2_CID_SATURATION
:
832 dev
->saturation
= ctrl
->value
;
833 pms_saturation(dev
, dev
->saturation
);
836 dev
->hue
= ctrl
->value
;
837 pms_hue(dev
, dev
->hue
);
843 mutex_unlock(&dev
->lock
);
847 static int pms_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
849 struct pms
*dev
= video_drvdata(file
);
850 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
852 pix
->width
= dev
->width
;
853 pix
->height
= dev
->height
;
854 pix
->pixelformat
= dev
->width
== 15 ?
855 V4L2_PIX_FMT_RGB555
: V4L2_PIX_FMT_RGB565
;
856 pix
->field
= V4L2_FIELD_NONE
;
857 pix
->bytesperline
= 2 * dev
->width
;
858 pix
->sizeimage
= 2 * dev
->width
* dev
->height
;
860 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
864 static int pms_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
866 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
868 if (pix
->height
< 16 || pix
->height
> 480)
870 if (pix
->width
< 16 || pix
->width
> 640)
872 if (pix
->pixelformat
!= V4L2_PIX_FMT_RGB555
&&
873 pix
->pixelformat
!= V4L2_PIX_FMT_RGB565
)
875 pix
->field
= V4L2_FIELD_NONE
;
876 pix
->bytesperline
= 2 * pix
->width
;
877 pix
->sizeimage
= 2 * pix
->width
* pix
->height
;
879 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
883 static int pms_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
885 struct pms
*dev
= video_drvdata(file
);
886 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
887 int ret
= pms_try_fmt_vid_cap(file
, fh
, fmt
);
891 mutex_lock(&dev
->lock
);
892 dev
->width
= pix
->width
;
893 dev
->height
= pix
->height
;
894 dev
->depth
= (pix
->pixelformat
== V4L2_PIX_FMT_RGB555
) ? 15 : 16;
895 pms_resolution(dev
, dev
->width
, dev
->height
);
896 /* Ok we figured out what to use from our wide choice */
897 mutex_unlock(&dev
->lock
);
901 static int pms_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
903 static struct v4l2_fmtdesc formats
[] = {
905 "RGB 5:5:5", V4L2_PIX_FMT_RGB555
,
909 "RGB 5:6:5", V4L2_PIX_FMT_RGB565
,
913 enum v4l2_buf_type type
= fmt
->type
;
918 *fmt
= formats
[fmt
->index
];
923 static ssize_t
pms_read(struct file
*file
, char __user
*buf
,
924 size_t count
, loff_t
*ppos
)
926 struct pms
*dev
= video_drvdata(file
);
929 mutex_lock(&dev
->lock
);
930 len
= pms_capture(dev
, buf
, (dev
->depth
== 15), count
);
931 mutex_unlock(&dev
->lock
);
935 static int pms_exclusive_open(struct file
*file
)
937 struct pms
*dev
= video_drvdata(file
);
939 return test_and_set_bit(0, &dev
->in_use
) ? -EBUSY
: 0;
942 static int pms_exclusive_release(struct file
*file
)
944 struct pms
*dev
= video_drvdata(file
);
946 clear_bit(0, &dev
->in_use
);
950 static const struct v4l2_file_operations pms_fops
= {
951 .owner
= THIS_MODULE
,
952 .open
= pms_exclusive_open
,
953 .release
= pms_exclusive_release
,
954 .ioctl
= video_ioctl2
,
958 static const struct v4l2_ioctl_ops pms_ioctl_ops
= {
959 .vidioc_querycap
= pms_querycap
,
960 .vidioc_g_input
= pms_g_input
,
961 .vidioc_s_input
= pms_s_input
,
962 .vidioc_enum_input
= pms_enum_input
,
963 .vidioc_g_std
= pms_g_std
,
964 .vidioc_s_std
= pms_s_std
,
965 .vidioc_queryctrl
= pms_queryctrl
,
966 .vidioc_g_ctrl
= pms_g_ctrl
,
967 .vidioc_s_ctrl
= pms_s_ctrl
,
968 .vidioc_enum_fmt_vid_cap
= pms_enum_fmt_vid_cap
,
969 .vidioc_g_fmt_vid_cap
= pms_g_fmt_vid_cap
,
970 .vidioc_s_fmt_vid_cap
= pms_s_fmt_vid_cap
,
971 .vidioc_try_fmt_vid_cap
= pms_try_fmt_vid_cap
,
975 * Probe for and initialise the Mediavision PMS
978 static int init_mediavision(struct pms
*dev
)
983 static const unsigned char i2c_defs
[] = {
984 0x4c, 0x30, 0x00, 0xe8,
985 0xb6, 0xe2, 0x00, 0x00,
986 0xff, 0xff, 0x00, 0x00,
987 0x00, 0x00, 0x78, 0x98,
988 0x00, 0x00, 0x00, 0x00,
989 0x34, 0x0a, 0xf4, 0xce,
993 dev
->mem
= ioremap(mem_base
, 0x800);
997 if (!request_region(0x9a01, 1, "Mediavision PMS config")) {
998 printk(KERN_WARNING
"mediavision: unable to detect: 0x9a01 in use.\n");
1002 if (!request_region(dev
->io
, 3, "Mediavision PMS")) {
1003 printk(KERN_WARNING
"mediavision: I/O port %d in use.\n", dev
->io
);
1004 release_region(0x9a01, 1);
1008 outb(0xb8, 0x9a01); /* Unlock */
1009 outb(dev
->io
>> 4, 0x9a01); /* Set IO port */
1012 id
= mvv_read(dev
, 3);
1013 decst
= pms_i2c_stat(dev
, 0x43);
1017 else if (pms_i2c_stat(dev
, 0xb9) != -1)
1019 else if (pms_i2c_stat(dev
, 0x8b) != -1)
1024 printk(KERN_INFO
"PMS type is %d\n", idec
);
1026 release_region(dev
->io
, 3);
1027 release_region(0x9a01, 1);
1033 * Ok we have a PMS of some sort
1036 mvv_write(dev
, 0x04, mem_base
>> 12); /* Set the memory area */
1038 /* Ok now load the defaults */
1040 for (i
= 0; i
< 0x19; i
++) {
1041 if (i2c_defs
[i
] == 0xff)
1042 pms_i2c_andor(dev
, 0x8a, i
, 0x07, 0x00);
1044 pms_i2c_write(dev
, 0x8a, i
, i2c_defs
[i
]);
1047 pms_i2c_write(dev
, 0xb8, 0x00, 0x12);
1048 pms_i2c_write(dev
, 0xb8, 0x04, 0x00);
1049 pms_i2c_write(dev
, 0xb8, 0x07, 0x00);
1050 pms_i2c_write(dev
, 0xb8, 0x08, 0x00);
1051 pms_i2c_write(dev
, 0xb8, 0x09, 0xff);
1052 pms_i2c_write(dev
, 0xb8, 0x0a, 0x00);
1053 pms_i2c_write(dev
, 0xb8, 0x0b, 0x10);
1054 pms_i2c_write(dev
, 0xb8, 0x10, 0x03);
1056 mvv_write(dev
, 0x01, 0x00);
1057 mvv_write(dev
, 0x05, 0xa0);
1058 mvv_write(dev
, 0x08, 0x25);
1059 mvv_write(dev
, 0x09, 0x00);
1060 mvv_write(dev
, 0x0a, 0x20 | MVVMEMORYWIDTH
);
1062 mvv_write(dev
, 0x10, 0x02);
1063 mvv_write(dev
, 0x1e, 0x0c);
1064 mvv_write(dev
, 0x1f, 0x03);
1065 mvv_write(dev
, 0x26, 0x06);
1067 mvv_write(dev
, 0x2b, 0x00);
1068 mvv_write(dev
, 0x2c, 0x20);
1069 mvv_write(dev
, 0x2d, 0x00);
1070 mvv_write(dev
, 0x2f, 0x70);
1071 mvv_write(dev
, 0x32, 0x00);
1072 mvv_write(dev
, 0x33, MVVMEMORYWIDTH
);
1073 mvv_write(dev
, 0x34, 0x00);
1074 mvv_write(dev
, 0x35, 0x00);
1075 mvv_write(dev
, 0x3a, 0x80);
1076 mvv_write(dev
, 0x3b, 0x10);
1077 mvv_write(dev
, 0x20, 0x00);
1078 mvv_write(dev
, 0x21, 0x00);
1079 mvv_write(dev
, 0x30, 0x22);
1084 * Initialization and module stuff
1089 module_param(enable
, int, 0);
1092 static int __init
pms_init(void)
1094 struct pms
*dev
= &pms_card
;
1095 struct v4l2_device
*v4l2_dev
= &dev
->v4l2_dev
;
1098 strlcpy(v4l2_dev
->name
, "pms", sizeof(v4l2_dev
->name
));
1100 v4l2_info(v4l2_dev
, "Mediavision Pro Movie Studio driver 0.03\n");
1105 "PMS: not enabled, use pms.enable=1 to probe\n");
1110 dev
->decoder
= PHILIPS2
;
1112 dev
->data
= io_port
+ 1;
1114 if (init_mediavision(dev
)) {
1115 v4l2_err(v4l2_dev
, "Board not found.\n");
1119 res
= v4l2_device_register(NULL
, v4l2_dev
);
1121 v4l2_err(v4l2_dev
, "Could not register v4l2_device\n");
1125 strlcpy(dev
->vdev
.name
, v4l2_dev
->name
, sizeof(dev
->vdev
.name
));
1126 dev
->vdev
.v4l2_dev
= v4l2_dev
;
1127 dev
->vdev
.fops
= &pms_fops
;
1128 dev
->vdev
.ioctl_ops
= &pms_ioctl_ops
;
1129 dev
->vdev
.release
= video_device_release_empty
;
1130 video_set_drvdata(&dev
->vdev
, dev
);
1131 mutex_init(&dev
->lock
);
1132 dev
->std
= V4L2_STD_NTSC_M
;
1136 dev
->brightness
= 139;
1139 dev
->saturation
= 64;
1140 pms_swsense(dev
, 75);
1141 pms_resolution(dev
, 320, 240);
1142 pms_videosource(dev
, 0);
1143 pms_vcrinput(dev
, 0);
1144 if (video_register_device(&dev
->vdev
, VFL_TYPE_GRABBER
, video_nr
) < 0) {
1145 v4l2_device_unregister(&dev
->v4l2_dev
);
1146 release_region(dev
->io
, 3);
1147 release_region(0x9a01, 1);
1154 static void __exit
pms_exit(void)
1156 struct pms
*dev
= &pms_card
;
1158 video_unregister_device(&dev
->vdev
);
1159 release_region(dev
->io
, 3);
1160 release_region(0x9a01, 1);
1164 module_init(pms_init
);
1165 module_exit(pms_exit
);