23 #include <linux/module.h>
25 #include <linux/errno.h>
27 #include <linux/kernel.h>
29 #include <linux/slab.h>
37 #include <linux/videodev2.h>
51 #define MVVMEMORYWIDTH 0x40
90 static int video_nr = -1;
96 outw(index | (value << 8), dev->
io);
99 static inline u8 mvv_read(
struct pms *dev,
u8 index)
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)
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++) {
150 if ((dev->
i2cinfo[i].slave == slave) &&
151 (dev->
i2cinfo[i].sub == sub)) {
152 if (dev->
i2cinfo[i].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)
190 static int pms_i2c_read(
struct pms *dev,
int slave,
int sub)
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)
222 pms_i2c_andor(dev, 0x8a, 0x06, 0x7f, source ? 0x80 : 0);
227 mvv_write(dev, 0x2E, 0x31);
233 static void pms_hue(
struct pms *dev,
short hue)
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)
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)
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)
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)
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
329 static void pms_hstart(
struct pms *dev,
short start)
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)
350 pms_i2c_andor(dev, 0x8a, 0x06, 0xcf, (pass & 0x03) << 4);
352 pms_i2c_andor(dev, 0x42, 0x06, 0xcf, (pass & 0x03) << 4);
355 static void pms_antisnow(
struct pms *dev,
short snow)
358 pms_i2c_andor(dev, 0x8a, 0x06, 0xf3, (snow & 0x03) << 2);
360 pms_i2c_andor(dev, 0x42, 0x06, 0xf3, (snow & 0x03) << 2);
363 static void pms_sharpness(
struct pms *dev,
short sharp)
366 pms_i2c_andor(dev, 0x8a, 0x06, 0xfc, sharp & 0x03);
368 pms_i2c_andor(dev, 0x42, 0x06, 0xfc, sharp & 0x03);
371 static void pms_chromaagc(
struct pms *dev,
short agc)
374 pms_i2c_andor(dev, 0x8a, 0x0c, 0x9f, (agc & 0x03) << 5);
376 pms_i2c_andor(dev, 0x42, 0x0c, 0x9f, (agc & 0x03) << 5);
379 static void pms_vertnoise(
struct pms *dev,
short noise)
382 pms_i2c_andor(dev, 0x8a, 0x10, 0xfc, noise & 3);
384 pms_i2c_andor(dev, 0x42, 0x10, 0xfc, noise & 3);
387 static void pms_forcecolour(
struct pms *dev,
short colour)
390 pms_i2c_andor(dev, 0x8a, 0x0c, 0x7f, (colour & 1) << 7);
392 pms_i2c_andor(dev, 0x42, 0x0c, 0x7, (colour & 1) << 7);
395 static void pms_antigamma(
struct pms *dev,
short gamma)
398 pms_i2c_andor(dev, 0xb8, 0x00, 0x7f, (gamma & 1) << 7);
400 pms_i2c_andor(dev, 0x42, 0x20, 0x7, (gamma & 1) << 7);
403 static void pms_prefilter(
struct pms *dev,
short filter)
406 pms_i2c_andor(dev, 0x8a, 0x06, 0xbf, (filter & 1) << 6);
408 pms_i2c_andor(dev, 0x42, 0x06, 0xbf, (filter & 1) << 6);
411 static void pms_hfilter(
struct pms *dev,
short filter)
414 pms_i2c_andor(dev, 0xb8, 0x04, 0x1f, (filter & 7) << 5);
416 pms_i2c_andor(dev, 0x42, 0x24, 0x1f, (filter & 7) << 5);
419 static void pms_vfilter(
struct pms *dev,
short filter)
422 pms_i2c_andor(dev, 0xb8, 0x08, 0x9f, (filter & 3) << 5);
424 pms_i2c_andor(dev, 0x42, 0x28, 0x9f, (filter & 3) << 5);
427 static void pms_killcolour(
struct pms *dev,
short colour)
430 pms_i2c_andor(dev, 0x8a, 0x08, 0x07, (colour & 0x1f) << 3);
431 pms_i2c_andor(dev, 0x8a, 0x09, 0x07, (colour & 0x1f) << 3);
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)
441 pms_i2c_write(dev, 0x8a, 0x11, chroma);
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)
468 pms_i2c_andor(dev, 0x8a, 0x0f, 0xdf, (cross & 1) << 5);
470 pms_i2c_andor(dev, 0x42, 0x0f, 0xdf, (cross & 1) << 5);
474 static void pms_swsense(
struct pms *dev,
short sense)
477 pms_i2c_write(dev, 0x8a, 0x0a, sense);
478 pms_i2c_write(dev, 0x8a, 0x0b, sense);
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)
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);
500 mvv_write(dev, 0x1d, decinum);
507 static void pms_vertdeci(
struct pms *dev,
unsigned short decinum,
unsigned short deciden)
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) {
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);
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);
595 mvv_write(dev, 0x42, 0x00);
596 mvv_write(dev, 0x43, 0x00);
599 mvv_write(dev, 0x22, width + 8);
600 mvv_write(dev, 0x23, (width + 8) >> 8);
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);
619 static void pms_vcrinput(
struct pms *dev,
short input)
622 pms_i2c_andor(dev, 0x8a, 0x0d, 0x7f, (input & 1) << 7);
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;
635 unsigned char r8 = 0x5;
639 mvv_write(dev, 0x08, r8);
643 for (y = 0; y < dev->
height; y++) {
658 if (dt + len > count)
662 return len ? len : -
EFAULT;
678 struct pms *dev = video_drvdata(file);
691 static const char *inputs[4] = {
709 static int pms_g_input(
struct file *file,
void *fh,
unsigned int *
inp)
711 struct pms *dev = video_drvdata(file);
717 static int pms_s_input(
struct file *file,
void *fh,
unsigned int inp)
719 struct pms *dev = video_drvdata(file);
725 pms_videosource(dev, inp & 1);
726 pms_vcrinput(dev, inp >> 1);
730 static int pms_g_std(
struct file *file,
void *fh,
v4l2_std_id *
std)
732 struct pms *dev = video_drvdata(file);
738 static int pms_s_std(
struct file *file,
void *fh,
v4l2_std_id *
std)
740 struct pms *dev = video_drvdata(file);
745 pms_framerate(dev, 30);
746 pms_secamcross(dev, 0);
749 pms_framerate(dev, 25);
750 pms_secamcross(dev, 0);
753 pms_framerate(dev, 25);
754 pms_secamcross(dev, 1);
777 pms_brightness(dev, ctrl->
val);
780 pms_contrast(dev, ctrl->
val);
783 pms_saturation(dev, ctrl->
val);
786 pms_hue(dev, ctrl->
val);
795 static int pms_g_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *
fmt)
797 struct pms *dev = video_drvdata(file);
812 static int pms_try_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *
fmt)
831 static int pms_s_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
833 struct pms *dev = video_drvdata(file);
835 int ret = pms_try_fmt_vid_cap(file, fh, fmt);
847 static int pms_enum_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_fmtdesc *fmt)
864 *fmt = formats[fmt->
index];
869 static ssize_t pms_read(
struct file *file,
char __user *buf,
870 size_t count, loff_t *ppos)
872 struct pms *dev = video_drvdata(file);
875 len = pms_capture(dev, buf, (dev->
depth == 15), count);
886 poll_wait(file, &fh->
wait, wait);
900 .vidioc_querycap = pms_querycap,
901 .vidioc_g_input = pms_g_input,
902 .vidioc_s_input = pms_s_input,
903 .vidioc_enum_input = pms_enum_input,
904 .vidioc_g_std = pms_g_std,
905 .vidioc_s_std = pms_s_std,
906 .vidioc_enum_fmt_vid_cap = pms_enum_fmt_vid_cap,
907 .vidioc_g_fmt_vid_cap = pms_g_fmt_vid_cap,
908 .vidioc_s_fmt_vid_cap = pms_s_fmt_vid_cap,
909 .vidioc_try_fmt_vid_cap = pms_try_fmt_vid_cap,
918 static int init_mediavision(
struct pms *dev)
922 static const unsigned char i2c_defs[] = {
923 0x4c, 0x30, 0x00, 0xe8,
924 0xb6, 0xe2, 0x00, 0x00,
925 0xff, 0xff, 0x00, 0x00,
926 0x00, 0x00, 0x78, 0x98,
927 0x00, 0x00, 0x00, 0x00,
928 0x34, 0x0a, 0xf4, 0xce,
948 outb(dev->
io >> 4, 0x9a01);
951 decst = pms_i2c_stat(dev, 0x43);
955 else if (pms_i2c_stat(dev, 0xb9) != -1)
957 else if (pms_i2c_stat(dev, 0x8b) != -1)
974 mvv_write(dev, 0x04,
mem_base >> 12);
978 for (i = 0; i < 0x19; i++) {
979 if (i2c_defs[i] == 0xff)
980 pms_i2c_andor(dev, 0x8a, i, 0x07, 0x00);
982 pms_i2c_write(dev, 0x8a, i, i2c_defs[i]);
985 pms_i2c_write(dev, 0xb8, 0x00, 0x12);
986 pms_i2c_write(dev, 0xb8, 0x04, 0x00);
987 pms_i2c_write(dev, 0xb8, 0x07, 0x00);
988 pms_i2c_write(dev, 0xb8, 0x08, 0x00);
989 pms_i2c_write(dev, 0xb8, 0x09, 0xff);
990 pms_i2c_write(dev, 0xb8, 0x0a, 0x00);
991 pms_i2c_write(dev, 0xb8, 0x0b, 0x10);
992 pms_i2c_write(dev, 0xb8, 0x10, 0x03);
994 mvv_write(dev, 0x01, 0x00);
995 mvv_write(dev, 0x05, 0xa0);
996 mvv_write(dev, 0x08, 0x25);
997 mvv_write(dev, 0x09, 0x00);
1000 mvv_write(dev, 0x10, 0x02);
1001 mvv_write(dev, 0x1e, 0x0c);
1002 mvv_write(dev, 0x1f, 0x03);
1003 mvv_write(dev, 0x26, 0x06);
1005 mvv_write(dev, 0x2b, 0x00);
1006 mvv_write(dev, 0x2c, 0x20);
1007 mvv_write(dev, 0x2d, 0x00);
1008 mvv_write(dev, 0x2f, 0x70);
1009 mvv_write(dev, 0x32, 0x00);
1011 mvv_write(dev, 0x34, 0x00);
1012 mvv_write(dev, 0x35, 0x00);
1013 mvv_write(dev, 0x3a, 0x80);
1014 mvv_write(dev, 0x3b, 0x10);
1015 mvv_write(dev, 0x20, 0x00);
1016 mvv_write(dev, 0x21, 0x00);
1017 mvv_write(dev, 0x30, 0x22);
1031 .s_ctrl = pms_s_ctrl,
1034 static int pms_probe(
struct device *pdev,
unsigned int card)
1043 pr_err(
"PMS: not enabled, use pms.enable=1 to probe\n");
1060 v4l2_err(v4l2_dev,
"Could not register v4l2_device\n");
1063 v4l2_info(v4l2_dev,
"Mediavision Pro Movie Studio driver 0.05\n");
1065 res = init_mediavision(dev);
1067 v4l2_err(v4l2_dev,
"Board not found.\n");
1087 dev->
vdev.v4l2_dev = v4l2_dev;
1088 dev->
vdev.ctrl_handler = hdl;
1089 dev->
vdev.fops = &pms_fops;
1090 dev->
vdev.ioctl_ops = &pms_ioctl_ops;
1095 video_set_drvdata(&dev->
vdev, dev);
1100 pms_swsense(dev, 75);
1101 pms_resolution(dev, 320, 240);
1102 pms_videosource(dev, 0);
1103 pms_vcrinput(dev, 0);
1121 static int pms_remove(
struct device *pdev,
unsigned int card)
1135 .remove = pms_remove,
1141 static int __init pms_init(
void)
1146 static void __exit pms_exit(
void)