27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
48 static unsigned int irq_debug;
61 #define FORMAT_FLAGS_PACKED 0x01
65 .name =
"8 bpp, gray",
70 .name =
"4:1:1, packed, Y41P",
75 .name =
"4:2:2, packed, YUYV",
80 .name =
"4:2:2, packed, UYVY",
105 if (formats[i].fourcc == fourcc)
108 pr_err(
"%s(0x%08x) NOT FOUND\n", __func__, fourcc);
118 for (bc = 0;; bc++) {
119 if (list_empty(&q->
active)) {
120 dprintk(1,
"bc=%d (=0: active empty)\n", bc);
139 if (list_empty(&q->
active))
144 pr_err(
"%s: %d buffers handled (should be 1)\n", __func__, bc);
150 dprintk(1,
"%s(norm = 0x%08x) name: [%s]\n",
168 dprintk(1,
"%s()\n", __func__);
178 video_set_drvdata(vfd, dev);
205 dprintk(1,
"%s()\n", __func__);
220 dprintk(1,
"res: get %d\n", bit);
239 dprintk(1,
"%s()\n", __func__);
244 dprintk(1,
"res: put %d\n", bits);
251 memset(&route, 0,
sizeof(route));
253 dprintk(1,
"%s(): video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
254 __func__, input,
INPUT(input)->vmux,
INPUT(input)->gpio0,
301 if (!list_empty(&q->
active)) {
318 if (list_empty(&q->
queued))
325 list_move_tail(&buf->
vb.queue, &q->
active);
330 }
else if (prev->
vb.width == buf->
vb.width &&
331 prev->
vb.height == buf->
vb.height &&
333 list_move_tail(&buf->
vb.queue, &q->
active);
358 while (!list_empty(&q->
active)) {
368 spin_unlock_irqrestore(&dev->
slock, flags);
379 if (0 == (status & mask))
385 if (status & (1 << 16)) {
386 pr_warn(
"%s, %s: video risc op code error\n",
394 spin_lock(&dev->
slock);
398 spin_unlock(&dev->
slock);
405 spin_lock(&dev->
slock);
407 &dev->
channels[channel->
i].vidq, channel);
408 spin_unlock(&dev->
slock);
430 if (dev->
channels[chan_num].video_dev) {
431 if (video_is_registered(dev->
channels[chan_num].video_dev))
441 &dev->
channels[chan_num].vidq.stopper);
443 pr_warn(
"device %d released!\n", chan_num);
454 .
name =
"cx25821-video",
457 .ioctl_ops = &video_ioctl_ops,
465 cx25821_init_controls(dev, i);
468 dev->
channels[i].sram_channels->dma_ctl, 0x11, 0);
476 INIT_LIST_HEAD(&dev->
channels[i].vidq.active);
477 INIT_LIST_HEAD(&dev->
channels[i].vidq.queued);
489 &cx25821_video_device,
"video");
491 err = video_register_device(dev->
channels[i].video_dev,
527 if (*size * *count > vid_limit * 1024 * 1024)
528 *count = (vid_limit * 1024 * 1024) / *size;
553 if (0 != buf->
vb.baddr && buf->
vb.bsize < buf->
vb.size)
556 if (buf->
fmt != fh->
fmt ||
558 buf->
vb.height != fh->
height || buf->
vb.field != field) {
575 dprintk(1,
"init_buffer=%d\n", init_buffer);
580 if (channel_opened < 0 || channel_opened > 7)
583 if (dev->
channels[channel_opened].pixel_formats ==
585 buf->
bpl = (buf->
fmt->depth * buf->
vb.width) >> 3;
587 buf->
bpl = (buf->
fmt->depth >> 3) * (buf->
vb.width);
589 if (dev->
channels[channel_opened].pixel_formats ==
591 bpl_local = buf->
bpl;
593 bpl_local = buf->
bpl;
595 if (channel_opened >= 0 && channel_opened <= 7) {
597 .use_cif_resolution) {
600 bpl_local = 352 << 1;
609 switch (buf->
vb.field) {
613 buf->
bpl, 0, buf->
vb.height);
618 buf->
bpl, 0, buf->
vb.height);
623 dprintk(1,
"top field first\n");
626 dma->
sglist, line0_offset,
627 bpl_local, bpl_local, bpl_local,
628 buf->
vb.height >> 1);
633 0, buf->
bpl * (buf->
vb.height >> 1),
634 buf->
bpl, 0, buf->
vb.height >> 1);
639 buf->
bpl * (buf->
vb.height >> 1), 0,
640 buf->
bpl, 0, buf->
vb.height >> 1);
647 dprintk(2,
"[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
649 fh->
fmt->name, (
unsigned long)buf->
risc.dma);
713 dprintk(2,
"jmp to stopper (0x%x)\n", buf->
risc.jmp[1]);
715 if (!list_empty(&q->
queued)) {
718 dprintk(2,
"[%p/%d] buffer_queue - append to queued\n", buf,
721 }
else if (list_empty(&q->
active)) {
728 dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
733 if (prev->
vb.width == buf->
vb.width
734 && prev->
vb.height == buf->
vb.height
735 && prev->
fmt == buf->
fmt) {
743 dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
749 dprintk(2,
"[%p/%d] buffer_queue - first queued\n", buf,
754 if (list_empty(&q->
active))
755 dprintk(2,
"active queue empty!\n");
761 .buf_queue = buffer_queue,
765 static int video_open(
struct file *
file)
777 dprintk(1,
"open dev=%s type=%s\n", video_device_node_name(vdev),
793 h->
channels[i].video_dev->minor == minor) {
832 dprintk(1,
"post videobuf_queue_init()\n");
838 static ssize_t video_read(
struct file *file,
char __user *
data,
size_t count,
857 static unsigned int video_poll(
struct file *file,
865 if (list_empty(&fh->
vidq.stream))
876 poll_wait(file, &buf->
vb.done, wait);
882 .use_cif_resolution) {
883 u8 cam_id = *((
char *)buf->
vb.baddr + 3);
885 (
char *)buf->
vb.baddr + (fh->
width * 2),
887 *((
char *)buf->
vb.baddr + 3) = cam_id;
897 static int video_release(
struct file *file)
911 if (fh->
vidq.read_buf) {
943 static int vidioc_streamoff(
struct file *file,
void *priv,
enum v4l2_buf_type i)
962 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
967 struct v4l2_mbus_framefmt mbus_fmt;
978 dprintk(2,
"%s()\n", __func__);
1012 dprintk(2,
"%s(): width=%d height=%d field=%d\n", __func__, fh->
width,
1020 static int vidioc_dqbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
1033 static int vidioc_log_status(
struct file *file,
void *priv)
1044 pr_info(
"%s/2: ============ START LOG STATUS ============\n",
1048 pr_info(
"Video input 0 is %s\n",
1049 (tmp & 0x11) ?
"streaming" :
"stopped");
1050 pr_info(
"%s/2: ============= END LOG STATUS =============\n",
1055 static int vidioc_s_ctrl(
struct file *file,
void *priv,
1081 f->
fmt.
pix.pixelformat = fh->
fmt->fourcc;
1093 unsigned int maxw, maxh;
1099 field = f->
fmt.
pix.field;
1104 if (f->
fmt.
pix.height > maxh / 2)
1122 if (f->
fmt.
pix.height < 32)
1124 if (f->
fmt.
pix.height > maxh)
1125 f->
fmt.
pix.height = maxh;
1126 if (f->
fmt.
pix.width < 48)
1128 if (f->
fmt.
pix.width > maxw)
1130 f->
fmt.
pix.width &= ~0x03;
1212 dprintk(1,
"%s()\n", __func__);
1221 if (dev->
tvnorm == *tvnorms)
1236 static const char *
const iname[] = {
1242 dprintk(1,
"%s()\n", __func__);
1248 if (0 ==
INPUT(n)->type)
1262 dprintk(1,
"%s()\n", __func__);
1271 dprintk(1,
"%s(): returns %d\n", __func__, *i);
1281 dprintk(1,
"%s(%d)\n", __func__, i);
1291 dprintk(1,
"%s(): -EINVAL\n", __func__);
1344 pr_err(
"Invalid fh pointer!\n");
1352 #ifdef CONFIG_VIDEO_ADV_DEBUG
1413 dprintk(1,
"%s()\n", __func__);
1433 .name =
"Brightness",
1437 .default_value = 6200,
1445 .default_value = 5000,
1449 .name =
"Saturation",
1453 .default_value = 5000,
1461 .default_value = 5000,
1465 static const int CX25821_CTLS =
ARRAY_SIZE(cx25821_ctls);
1473 for (i = 0; i < CX25821_CTLS; i++)
1474 if (cx25821_ctls[i].
id == qctrl->
id)
1476 if (i == CX25821_CTLS) {
1480 *qctrl = cx25821_ctls[
i];
1487 return cx25821_ctrl_query(qctrl);
1497 for (i = 0; i < CX25821_CTLS; i++)
1498 if (cx25821_ctls[i].
id ==
id)
1499 return cx25821_ctls +
i;
1511 ctrl = ctrl_by_id(ctl->
id);
1540 ctrl = ctrl_by_id(ctl->
id);
1545 switch (ctrl->
type) {
1586 for (i = 0; i < CX25821_CTLS; i++) {
1602 cropcap->
bounds.left = 0;
1603 cropcap->
bounds.width = 720;
1646 if (width == 352 || width == 720)
1653 if (width == 320 || width == 352 || width == 720)
1664 if (height == 576 || height == 288)
1671 if (height == 480 || height == 240)
1680 static long video_ioctl_upstream9(
struct file *file,
unsigned int cmd,
1690 if (!data_from_user) {
1691 pr_err(
"%s(): Upstream data is INVALID. Returning\n", __func__);
1695 command = data_from_user->
command;
1720 static long video_ioctl_upstream10(
struct file *file,
unsigned int cmd,
1730 if (!data_from_user) {
1731 pr_err(
"%s(): Upstream data is INVALID. Returning\n", __func__);
1735 command = data_from_user->
command;
1760 static long video_ioctl_upstream11(
struct file *file,
unsigned int cmd,
1770 if (!data_from_user) {
1771 pr_err(
"%s(): Upstream data is INVALID. Returning\n", __func__);
1775 command = data_from_user->
command;
1800 static long video_ioctl_set(
struct file *file,
unsigned int cmd,
1808 int selected_channel = 0;
1816 if (!data_from_user) {
1817 pr_err(
"%s(): User data is INVALID. Returning\n", __func__);
1821 command = data_from_user->
command;
1843 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1844 selected_channel -= 4;
1845 selected_channel = selected_channel % 8;
1848 if (selected_channel >= 0)
1865 if (cif_width != 320 && cif_width != 352)
1870 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1871 selected_channel -= 4;
1872 selected_channel = selected_channel % 8;
1875 if (selected_channel <= 7 && selected_channel >= 0) {
1876 dev->
channels[selected_channel].use_cif_resolution =
1910 static long cx25821_video_ioctl(
struct file *file,
1911 unsigned int cmd,
unsigned long arg)
1919 ret = video_ioctl_upstream9(file, cmd, arg);
1922 ret = video_ioctl_upstream10(file, cmd, arg);
1925 ret = video_ioctl_upstream11(file, cmd, arg);
1926 ret = video_ioctl_set(file, cmd, arg);
1937 .release = video_release,
1941 .ioctl = cx25821_video_ioctl,
1978 #ifdef CONFIG_VIDEO_ADV_DEBUG
1985 .name =
"cx25821-videoioctl",
1986 .fops = &video_fops,
1987 .ioctl_ops = &video_ioctl_ops,