22 #include <linux/module.h>
24 #include <linux/errno.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/sched.h>
30 #include <linux/videodev2.h>
37 #include <asm/uaccess.h>
41 #include <asm/byteorder.h>
44 #define DEBUG(n, args...) printk(KERN_INFO args)
47 #define DEBUG(n, args...)
57 #define VERSION "0.0.5"
59 #define ar_inl(addr) inl((unsigned long)(addr))
60 #define ar_outl(val, addr) outl((unsigned long)(val), (unsigned long)(addr))
73 #define AR_WIDTH_VGA 640
74 #define AR_HEIGHT_VGA 480
75 #define AR_WIDTH_QVGA 320
76 #define AR_HEIGHT_QVGA 240
77 #define MIN_AR_WIDTH AR_WIDTH_QVGA
78 #define MIN_AR_HEIGHT AR_HEIGHT_QVGA
79 #define MAX_AR_WIDTH AR_WIDTH_VGA
80 #define MAX_AR_HEIGHT AR_HEIGHT_VGA
83 #define AR_BITS_PER_PIXEL 16
84 #define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL / 8)
87 #define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
88 #define AR_LINE_BYTES_QVGA (AR_WIDTH_QVGA * AR_BYTES_PER_PIXEL)
89 #define MAX_AR_LINE_BYTES AR_LINE_BYTES_VGA
92 #define AR_FRAME_BYTES_VGA \
93 (AR_WIDTH_VGA * AR_HEIGHT_VGA * AR_BYTES_PER_PIXEL)
94 #define AR_FRAME_BYTES_QVGA \
95 (AR_WIDTH_QVGA * AR_HEIGHT_QVGA * AR_BYTES_PER_PIXEL)
96 #define MAX_AR_FRAME_BYTES \
97 (MAX_AR_WIDTH * MAX_AR_HEIGHT * AR_BYTES_PER_PIXEL)
99 #define AR_MAX_FRAME 15
102 #define AR_SIZE_VGA 0
103 #define AR_SIZE_QVGA 1
106 #define AR_MODE_INTERLACE 0
107 #define AR_MODE_NORMAL 1
114 unsigned char *line_buff;
125 static struct ar ardev;
127 static int video_nr = -1;
132 #define DEFAULT_FREQ 50
135 static int vga_interlace;
140 static void wait_for_vsync(
void)
148 static void wait_acknowledge(
void)
152 for (i = 0; i < 1000; i++)
195 for (i = 0; i < 100; i++)
205 static void init_iic(
void)
207 DEBUG(1,
"init_iic:\n");
244 static inline void clear_dma_status(
void)
249 static void wait_for_vertical_sync(
struct ar *
ar,
int exp_line)
258 for (; tmout >= 0; tmout--) {
273 struct ar *ar = video_drvdata(file);
275 unsigned long arvcr1 = 0;
279 unsigned char *py, *pu, *
pv;
284 DEBUG(1,
"ar_read()\n");
336 for (h = 0; h < ar->
height; h++) {
337 wait_for_vertical_sync(ar, h);
351 for (h = 0; h < ar->
height; h++) {
352 wait_for_vertical_sync(ar, h);
379 for (h = 0; h < ar->
height; h++) {
393 DEBUG(1,
"ret = %d\n", ret);
399 static int ar_querycap(
struct file *file,
void *
priv,
402 struct ar *ar = video_drvdata(file);
412 static int ar_enum_input(
struct file *file,
void *fh,
struct v4l2_input *
vin)
425 static int ar_g_input(
struct file *file,
void *fh,
unsigned int *
inp)
431 static int ar_s_input(
struct file *file,
void *fh,
unsigned int inp)
436 static int ar_g_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *
fmt)
438 struct ar *ar = video_drvdata(file);
452 static int ar_try_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *
fmt)
454 struct ar *ar = video_drvdata(file);
474 static int ar_s_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
476 struct ar *ar = video_drvdata(file);
478 int ret = ar_try_fmt_vid_cap(file, fh, fmt);
504 static int ar_enum_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_fmtdesc *fmt)
517 *fmt = formats[fmt->
index];
526 static void ar_interrupt(
int irq,
void *
dev)
529 unsigned int line_count;
530 unsigned int line_number;
537 line_number = (line_count << 1);
542 line_number = line_count;
545 if (line_number == 0) {
571 if (line_number == (ar->
height - 1)) {
600 static int ar_initialize(
struct ar *ar)
602 unsigned long cr = 0;
605 DEBUG(1,
"ar_initialize:\n");
611 for (i = 0; i < 0x18; i++)
614 for (i = 0; i < 0x40d; i++)
632 for (i = 0; i < 0x100000; i++) {
644 iic(2, 0x78, 0x11, 0x01, 0x00);
645 iic(3, 0x78, 0x12, 0x00, 0x06);
646 iic(3, 0x78, 0x12, 0x12, 0x30);
647 iic(3, 0x78, 0x12, 0x15, 0x58);
648 iic(3, 0x78, 0x12, 0x17, 0x30);
650 iic(3, 0x78, 0x12, 0x1a, 0x97);
651 iic(3, 0x78, 0x12, 0x1b, 0xff);
652 iic(3, 0x78, 0x12, 0x1c, 0xff);
653 iic(3, 0x78, 0x12, 0x26, 0x10);
654 iic(3, 0x78, 0x12, 0x27, 0x00);
656 iic(2, 0x78, 0x34, 0x02, 0x00);
657 iic(2, 0x78, 0x7a, 0x10, 0x00);
658 iic(2, 0x78, 0x80, 0x39, 0x00);
659 iic(2, 0x78, 0x81, 0xe6, 0x00);
660 iic(2, 0x78, 0x8d, 0x00, 0x00);
662 iic(2, 0x78, 0x8e, 0x0c, 0x00);
663 iic(2, 0x78, 0x8f, 0x00, 0x00);
665 iic(2, 0x78, 0x90, 0x00, 0x00);
667 iic(2, 0x78, 0x93, 0x01, 0x00);
668 iic(2, 0x78, 0x94, 0xcd, 0x00);
669 iic(2, 0x78, 0x95, 0x00, 0x00);
671 iic(2, 0x78, 0x96, 0xa0, 0x00);
672 iic(2, 0x78, 0x97, 0x00, 0x00);
673 iic(2, 0x78, 0x98, 0x60, 0x00);
674 iic(2, 0x78, 0x99, 0x01, 0x00);
675 iic(2, 0x78, 0x9a, 0x19, 0x00);
677 iic(2, 0x78, 0x9b, 0x02, 0x00);
678 iic(2, 0x78, 0x9c, 0xe8, 0x00);
679 iic(2, 0x78, 0x9d, 0x02, 0x00);
680 iic(2, 0x78, 0x9e, 0x2e, 0x00);
681 iic(2, 0x78, 0xb8, 0x78, 0x00);
682 iic(2, 0x78, 0xba, 0x05, 0x00);
684 iic(2, 0x78, 0x83, 0x8c, 0x00);
689 iic(3, 0x78, 0x49, 0x00, 0x95);
690 iic(3, 0x78, 0x49, 0x01, 0x96);
691 iic(3, 0x78, 0x49, 0x03, 0x85);
692 iic(3, 0x78, 0x49, 0x04, 0x97);
693 iic(3, 0x78, 0x49, 0x02, 0x7e);
694 iic(3, 0x78, 0x49, 0x05, 0xa4);
695 iic(3, 0x78, 0x49, 0x06, 0x04);
696 iic(3, 0x78, 0x49, 0x07, 0x04);
697 iic(2, 0x78, 0x48, 0x01, 0x00);
700 iic(2, 0x78, 0x11, 0x00, 0x00);
721 .vidioc_querycap = ar_querycap,
722 .vidioc_g_input = ar_g_input,
723 .vidioc_s_input = ar_s_input,
724 .vidioc_enum_input = ar_enum_input,
725 .vidioc_enum_fmt_vid_cap = ar_enum_fmt_vid_cap,
726 .vidioc_g_fmt_vid_cap = ar_g_fmt_vid_cap,
727 .vidioc_s_fmt_vid_cap = ar_s_fmt_vid_cap,
728 .vidioc_try_fmt_vid_cap = ar_try_fmt_vid_cap,
731 #define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
733 static int __init ar_init(
void)
747 v4l2_err(v4l2_dev,
"Could not register v4l2_device\n");
755 if (ar->line_buff ==
NULL || !
ALIGN4(ar->line_buff)) {
756 v4l2_err(v4l2_dev,
"buffer allocation failed for DMA.\n");
765 v4l2_err(v4l2_dev,
"buffer allocation failed for frame.\n");
772 ar->
vdev.v4l2_dev = v4l2_dev;
773 ar->
vdev.fops = &ar_fops;
774 ar->
vdev.ioctl_ops = &ar_ioctl_ops;
777 video_set_drvdata(&ar->
vdev, ar);
808 if (ar_initialize(ar) != 0) {
809 v4l2_err(v4l2_dev,
"M64278 not found.\n");
822 v4l2_err(v4l2_dev,
"register video (Colour AR) failed.\n");
827 v4l2_info(v4l2_dev,
"%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
843 kfree(ar->line_buff);
852 static int __init ar_init_module(
void)
861 static void __exit ar_cleanup_module(
void)
874 kfree(ar->line_buff);