Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX25821 PCIe bridge |
| 3 | * |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 4 | * Copyright (C) 2009 Conexant Systems Inc. |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 5 | * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> |
| 6 | * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 7 | * Parts adapted/taken from Eduardo Moscoso Rubino |
| 8 | * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com> |
| 9 | * |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 28 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 29 | #include "cx25821-video.h" |
| 30 | |
| 31 | MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 32 | MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 33 | MODULE_LICENSE("GPL"); |
| 34 | |
Mauro Carvalho Chehab | 53e712d | 2009-09-13 11:39:12 -0300 | [diff] [blame] | 35 | static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 36 | |
| 37 | module_param_array(video_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 38 | |
| 39 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 41 | static unsigned int video_debug = VIDEO_DEBUG; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 42 | module_param(video_debug, int, 0644); |
| 43 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
| 44 | |
| 45 | static unsigned int irq_debug; |
| 46 | module_param(irq_debug, int, 0644); |
| 47 | MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]"); |
| 48 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 49 | static unsigned int vid_limit = 16; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 50 | module_param(vid_limit, int, 0644); |
| 51 | MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); |
| 52 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 53 | #define FORMAT_FLAGS_PACKED 0x01 |
| 54 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 55 | static const struct cx25821_fmt formats[] = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 56 | { |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 57 | .name = "8 bpp, gray", |
| 58 | .fourcc = V4L2_PIX_FMT_GREY, |
| 59 | .depth = 8, |
| 60 | .flags = FORMAT_FLAGS_PACKED, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 61 | }, { |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 62 | .name = "4:1:1, packed, Y41P", |
| 63 | .fourcc = V4L2_PIX_FMT_Y41P, |
| 64 | .depth = 12, |
| 65 | .flags = FORMAT_FLAGS_PACKED, |
| 66 | }, { |
| 67 | .name = "4:2:2, packed, YUYV", |
| 68 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 69 | .depth = 16, |
| 70 | .flags = FORMAT_FLAGS_PACKED, |
| 71 | }, { |
| 72 | .name = "4:2:2, packed, UYVY", |
| 73 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 74 | .depth = 16, |
| 75 | .flags = FORMAT_FLAGS_PACKED, |
| 76 | }, { |
| 77 | .name = "4:2:0, YUV", |
| 78 | .fourcc = V4L2_PIX_FMT_YUV420, |
| 79 | .depth = 12, |
| 80 | .flags = FORMAT_FLAGS_PACKED, |
| 81 | }, |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 82 | }; |
| 83 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 84 | static const struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 85 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 86 | unsigned int i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 87 | |
Leonid V. Fedorenchik | e313e1f | 2011-09-16 14:15:13 +0800 | [diff] [blame] | 88 | if (fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 89 | return formats + 1; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 90 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 91 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 92 | if (formats[i].fourcc == fourcc) |
| 93 | return formats + i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 94 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 95 | pr_err("%s(0x%08x) NOT FOUND\n", __func__, fourcc); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 96 | return NULL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 97 | } |
| 98 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 99 | void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, |
| 100 | u32 count) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 101 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 102 | struct cx25821_buffer *buf; |
| 103 | int bc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 104 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 105 | for (bc = 0;; bc++) { |
| 106 | if (list_empty(&q->active)) { |
| 107 | dprintk(1, "bc=%d (=0: active empty)\n", bc); |
| 108 | break; |
| 109 | } |
| 110 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 111 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 112 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 113 | |
| 114 | /* count comes from the hw and it is 16bit wide -- |
| 115 | * this trick handles wrap-arounds correctly for |
| 116 | * up to 32767 buffers in flight... */ |
Leonid V. Fedorenchik | e313e1f | 2011-09-16 14:15:13 +0800 | [diff] [blame] | 117 | if ((s16) (count - buf->count) < 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 118 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 119 | |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 120 | v4l2_get_timestamp(&buf->vb.ts); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 121 | buf->vb.state = VIDEOBUF_DONE; |
| 122 | list_del(&buf->vb.queue); |
| 123 | wake_up(&buf->vb.done); |
| 124 | } |
| 125 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 126 | if (list_empty(&q->active)) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 127 | del_timer(&q->timeout); |
| 128 | else |
| 129 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 130 | if (bc != 1) |
Leonid V. Fedorenchik | 692cfb9 | 2011-09-16 14:14:36 +0800 | [diff] [blame] | 131 | pr_err("%s: %d buffers handled (should be 1)\n", __func__, bc); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 132 | } |
| 133 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 134 | static int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 135 | { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 136 | dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", |
| 137 | __func__, (unsigned int)norm, v4l2_norm_to_name(norm)); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 138 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 139 | dev->tvnorm = norm; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 140 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 141 | /* Tell the internal A/V decoder */ |
| 142 | cx25821_call_all(dev, core, s_std, norm); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 144 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 145 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 146 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 147 | static struct video_device *cx25821_vdev_init(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 148 | struct pci_dev *pci, |
Hans Verkuil | 170bd53 | 2013-04-13 05:19:41 -0300 | [diff] [blame] | 149 | const struct video_device *template, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 150 | char *type) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 151 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 152 | struct video_device *vfd; |
| 153 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 154 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 155 | vfd = video_device_alloc(); |
| 156 | if (NULL == vfd) |
| 157 | return NULL; |
| 158 | *vfd = *template; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 159 | vfd->v4l2_dev = &dev->v4l2_dev; |
| 160 | vfd->release = video_device_release; |
| 161 | snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, type, |
| 162 | cx25821_boards[dev->board].name); |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 163 | video_set_drvdata(vfd, dev); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 164 | return vfd; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* |
| 168 | static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl) |
| 169 | { |
Leonid V. Fedorenchik | c2c311f | 2011-09-16 14:14:37 +0800 | [diff] [blame] | 170 | int i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 171 | |
Leonid V. Fedorenchik | c2c311f | 2011-09-16 14:14:37 +0800 | [diff] [blame] | 172 | if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1) |
| 173 | return -EINVAL; |
| 174 | for (i = 0; i < CX25821_CTLS; i++) |
| 175 | if (cx25821_ctls[i].v.id == qctrl->id) |
| 176 | break; |
| 177 | if (i == CX25821_CTLS) { |
| 178 | *qctrl = no_ctl; |
| 179 | return 0; |
| 180 | } |
| 181 | *qctrl = cx25821_ctls[i].v; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 182 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 183 | } |
| 184 | */ |
| 185 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 186 | /* resource management */ |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 187 | int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, |
| 188 | unsigned int bit) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 189 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 190 | dprintk(1, "%s()\n", __func__); |
| 191 | if (fh->resources & bit) |
| 192 | /* have it already allocated */ |
| 193 | return 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 194 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 195 | /* is it free? */ |
| 196 | mutex_lock(&dev->lock); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 197 | if (dev->channels[fh->channel_id].resources & bit) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 198 | /* no, someone else uses it */ |
| 199 | mutex_unlock(&dev->lock); |
| 200 | return 0; |
| 201 | } |
| 202 | /* it's free, grab it */ |
| 203 | fh->resources |= bit; |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 204 | dev->channels[fh->channel_id].resources |= bit; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 205 | dprintk(1, "res: get %d\n", bit); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 206 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 207 | return 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 208 | } |
| 209 | |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 210 | int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 211 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 212 | return fh->resources & bit; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 213 | } |
| 214 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 215 | int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 216 | { |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 217 | return fh->dev->channels[fh->channel_id].resources & bit; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 218 | } |
| 219 | |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 220 | void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, |
| 221 | unsigned int bits) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 222 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 223 | BUG_ON((fh->resources & bits) != bits); |
| 224 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 225 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 226 | mutex_lock(&dev->lock); |
| 227 | fh->resources &= ~bits; |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 228 | dev->channels[fh->channel_id].resources &= ~bits; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 229 | dprintk(1, "res: put %d\n", bits); |
| 230 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 231 | } |
| 232 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 233 | static int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 234 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 235 | struct v4l2_routing route; |
| 236 | memset(&route, 0, sizeof(route)); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 237 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 238 | dprintk(1, "%s(): video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 239 | __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0, |
| 240 | INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3); |
| 241 | dev->input = input; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 242 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 243 | route.input = INPUT(input)->vmux; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 244 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 245 | /* Tell the internal A/V decoder */ |
| 246 | cx25821_call_all(dev, video, s_routing, INPUT(input)->vmux, 0, 0); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 247 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 248 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | int cx25821_start_video_dma(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 252 | struct cx25821_dmaqueue *q, |
| 253 | struct cx25821_buffer *buf, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 254 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 255 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 256 | int tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 257 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 258 | /* setup fifo + format */ |
| 259 | cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 260 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 261 | /* reset counter */ |
| 262 | cx_write(channel->gpcnt_ctl, 3); |
| 263 | q->count = 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 264 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 265 | /* enable irq */ |
| 266 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); |
| 267 | cx_set(channel->int_msk, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 268 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 269 | /* start dma */ |
| 270 | cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 271 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 272 | /* make sure upstream setting if any is reversed */ |
| 273 | tmp = cx_read(VID_CH_MODE_SEL); |
| 274 | cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 275 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 276 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 277 | } |
| 278 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 279 | static int cx25821_restart_video_queue(struct cx25821_dev *dev, |
| 280 | struct cx25821_dmaqueue *q, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 281 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 282 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 283 | struct cx25821_buffer *buf, *prev; |
| 284 | struct list_head *item; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 285 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 286 | if (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 287 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 288 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 289 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 290 | cx25821_start_video_dma(dev, q, buf, channel); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 291 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 292 | list_for_each(item, &q->active) { |
| 293 | buf = list_entry(item, struct cx25821_buffer, vb.queue); |
| 294 | buf->count = q->count++; |
| 295 | } |
| 296 | |
| 297 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 298 | return 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 299 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 300 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 301 | prev = NULL; |
| 302 | for (;;) { |
| 303 | if (list_empty(&q->queued)) |
| 304 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 305 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 306 | buf = list_entry(q->queued.next, struct cx25821_buffer, |
| 307 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 308 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 309 | if (NULL == prev) { |
| 310 | list_move_tail(&buf->vb.queue, &q->active); |
| 311 | cx25821_start_video_dma(dev, q, buf, channel); |
| 312 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 313 | buf->count = q->count++; |
| 314 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 315 | } else if (prev->vb.width == buf->vb.width && |
| 316 | prev->vb.height == buf->vb.height && |
| 317 | prev->fmt == buf->fmt) { |
| 318 | list_move_tail(&buf->vb.queue, &q->active); |
| 319 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 320 | buf->count = q->count++; |
| 321 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 322 | prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 323 | } else { |
| 324 | return 0; |
| 325 | } |
| 326 | prev = buf; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 327 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 328 | } |
| 329 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 330 | static void cx25821_vid_timeout(unsigned long data) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 331 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 332 | struct cx25821_data *timeout_data = (struct cx25821_data *)data; |
| 333 | struct cx25821_dev *dev = timeout_data->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 334 | const struct sram_channel *channel = timeout_data->channel; |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 335 | struct cx25821_dmaqueue *q = &dev->channels[channel->i].vidq; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 336 | struct cx25821_buffer *buf; |
| 337 | unsigned long flags; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 338 | |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 339 | /* cx25821_sram_channel_dump(dev, channel); */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 340 | cx_clear(channel->dma_ctl, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 341 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 342 | spin_lock_irqsave(&dev->slock, flags); |
| 343 | while (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 344 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 345 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 346 | list_del(&buf->vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 347 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 348 | buf->vb.state = VIDEOBUF_ERROR; |
| 349 | wake_up(&buf->vb.done); |
| 350 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 351 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 352 | cx25821_restart_video_queue(dev, q, channel); |
| 353 | spin_unlock_irqrestore(&dev->slock, flags); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) |
| 357 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 358 | u32 count = 0; |
| 359 | int handled = 0; |
| 360 | u32 mask; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 361 | const struct sram_channel *channel = dev->channels[chan_num].sram_channels; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 362 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 363 | mask = cx_read(channel->int_msk); |
| 364 | if (0 == (status & mask)) |
| 365 | return handled; |
| 366 | |
| 367 | cx_write(channel->int_stat, status); |
| 368 | |
| 369 | /* risc op code error */ |
| 370 | if (status & (1 << 16)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 371 | pr_warn("%s, %s: video risc op code error\n", |
| 372 | dev->name, channel->name); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 373 | cx_clear(channel->dma_ctl, 0x11); |
| 374 | cx25821_sram_channel_dump(dev, channel); |
| 375 | } |
| 376 | |
| 377 | /* risc1 y */ |
| 378 | if (status & FLD_VID_DST_RISC1) { |
| 379 | spin_lock(&dev->slock); |
| 380 | count = cx_read(channel->gpcnt); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 381 | cx25821_video_wakeup(dev, &dev->channels[channel->i].vidq, |
| 382 | count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 383 | spin_unlock(&dev->slock); |
| 384 | handled++; |
| 385 | } |
| 386 | |
| 387 | /* risc2 y */ |
| 388 | if (status & 0x10) { |
| 389 | dprintk(2, "stopper video\n"); |
| 390 | spin_lock(&dev->slock); |
Leonid V. Fedorenchik | 788d0f3 | 2011-09-16 14:14:39 +0800 | [diff] [blame] | 391 | cx25821_restart_video_queue(dev, |
| 392 | &dev->channels[channel->i].vidq, channel); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 393 | spin_unlock(&dev->slock); |
| 394 | handled++; |
| 395 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 396 | return handled; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 397 | } |
| 398 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 399 | static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 400 | unsigned int *size) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 401 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 402 | struct cx25821_fh *fh = q->priv_data; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 403 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 404 | *size = fh->fmt->depth * fh->width * fh->height >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 405 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 406 | if (0 == *count) |
| 407 | *count = 32; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 408 | |
Andreas Bombe | dab7e31 | 2010-03-21 16:02:45 -0300 | [diff] [blame] | 409 | if (*size * *count > vid_limit * 1024 * 1024) |
| 410 | *count = (vid_limit * 1024 * 1024) / *size; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 411 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 412 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 413 | } |
| 414 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 415 | static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 416 | enum v4l2_field field) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 417 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 418 | struct cx25821_fh *fh = q->priv_data; |
| 419 | struct cx25821_dev *dev = fh->dev; |
| 420 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 421 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 422 | int rc, init_buffer = 0; |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 423 | u32 line0_offset; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 424 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
| 425 | int bpl_local = LINE_SIZE_D1; |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 426 | int channel_opened = fh->channel_id; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 427 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 428 | BUG_ON(NULL == fh->fmt); |
| 429 | if (fh->width < 48 || fh->width > 720 || |
| 430 | fh->height < 32 || fh->height > 576) |
| 431 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 432 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 433 | buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 434 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 435 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 436 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 437 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 438 | if (buf->fmt != fh->fmt || |
| 439 | buf->vb.width != fh->width || |
| 440 | buf->vb.height != fh->height || buf->vb.field != field) { |
| 441 | buf->fmt = fh->fmt; |
| 442 | buf->vb.width = fh->width; |
| 443 | buf->vb.height = fh->height; |
| 444 | buf->vb.field = field; |
| 445 | init_buffer = 1; |
| 446 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 447 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 448 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 449 | init_buffer = 1; |
| 450 | rc = videobuf_iolock(q, &buf->vb, NULL); |
| 451 | if (0 != rc) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 452 | printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 453 | goto fail; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 454 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 455 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 456 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 457 | dprintk(1, "init_buffer=%d\n", init_buffer); |
| 458 | |
| 459 | if (init_buffer) { |
| 460 | |
| 461 | channel_opened = dev->channel_opened; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 462 | if (channel_opened < 0 || channel_opened > 7) |
| 463 | channel_opened = 7; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 464 | |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 465 | if (dev->channels[channel_opened].pixel_formats == |
| 466 | PIXEL_FRMT_411) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 467 | buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; |
| 468 | else |
| 469 | buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); |
| 470 | |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 471 | if (dev->channels[channel_opened].pixel_formats == |
| 472 | PIXEL_FRMT_411) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 473 | bpl_local = buf->bpl; |
| 474 | } else { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 475 | bpl_local = buf->bpl; /* Default */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 476 | |
| 477 | if (channel_opened >= 0 && channel_opened <= 7) { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 478 | if (dev->channels[channel_opened] |
| 479 | .use_cif_resolution) { |
Leonid V. Fedorenchik | cd52b2c | 2011-10-22 01:43:53 -0300 | [diff] [blame] | 480 | if (dev->tvnorm & V4L2_STD_PAL_BG || |
| 481 | dev->tvnorm & V4L2_STD_PAL_DK) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 482 | bpl_local = 352 << 1; |
| 483 | else |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 484 | bpl_local = dev->channels[ |
| 485 | channel_opened]. |
| 486 | cif_width << 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 487 | } |
| 488 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 489 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 490 | |
| 491 | switch (buf->vb.field) { |
| 492 | case V4L2_FIELD_TOP: |
| 493 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 494 | dma->sglist, 0, UNSET, |
| 495 | buf->bpl, 0, buf->vb.height); |
| 496 | break; |
| 497 | case V4L2_FIELD_BOTTOM: |
| 498 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 499 | dma->sglist, UNSET, 0, |
| 500 | buf->bpl, 0, buf->vb.height); |
| 501 | break; |
| 502 | case V4L2_FIELD_INTERLACED: |
| 503 | /* All other formats are top field first */ |
| 504 | line0_offset = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 505 | dprintk(1, "top field first\n"); |
| 506 | |
| 507 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 508 | dma->sglist, line0_offset, |
| 509 | bpl_local, bpl_local, bpl_local, |
| 510 | buf->vb.height >> 1); |
| 511 | break; |
| 512 | case V4L2_FIELD_SEQ_TB: |
| 513 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 514 | dma->sglist, |
| 515 | 0, buf->bpl * (buf->vb.height >> 1), |
| 516 | buf->bpl, 0, buf->vb.height >> 1); |
| 517 | break; |
| 518 | case V4L2_FIELD_SEQ_BT: |
| 519 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 520 | dma->sglist, |
| 521 | buf->bpl * (buf->vb.height >> 1), 0, |
| 522 | buf->bpl, 0, buf->vb.height >> 1); |
| 523 | break; |
| 524 | default: |
| 525 | BUG(); |
| 526 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 527 | } |
| 528 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 529 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
| 530 | buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, |
| 531 | fh->fmt->name, (unsigned long)buf->risc.dma); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 532 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 533 | buf->vb.state = VIDEOBUF_PREPARED; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 534 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 535 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 536 | |
Leonid V. Fedorenchik | 2748f26 | 2011-09-16 14:14:34 +0800 | [diff] [blame] | 537 | fail: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 538 | cx25821_free_buffer(q, buf); |
| 539 | return rc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 540 | } |
| 541 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 542 | static void cx25821_buffer_release(struct videobuf_queue *q, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 543 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 544 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 545 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 546 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 547 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 548 | cx25821_free_buffer(q, buf); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 549 | } |
| 550 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 551 | static struct videobuf_queue *get_queue(struct cx25821_fh *fh) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 552 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 553 | switch (fh->type) { |
| 554 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 555 | return &fh->vidq; |
| 556 | default: |
| 557 | BUG(); |
| 558 | return NULL; |
| 559 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 560 | } |
| 561 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 562 | static int cx25821_get_resource(struct cx25821_fh *fh, int resource) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 563 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 564 | switch (fh->type) { |
| 565 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 566 | return resource; |
| 567 | default: |
| 568 | BUG(); |
| 569 | return 0; |
| 570 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 571 | } |
| 572 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 573 | static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 574 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 575 | struct cx25821_fh *fh = file->private_data; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 576 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 577 | return videobuf_mmap_mapper(get_queue(fh), vma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 578 | } |
| 579 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 580 | |
| 581 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 582 | { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 583 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 584 | container_of(vb, struct cx25821_buffer, vb); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 585 | struct cx25821_buffer *prev; |
| 586 | struct cx25821_fh *fh = vq->priv_data; |
| 587 | struct cx25821_dev *dev = fh->dev; |
| 588 | struct cx25821_dmaqueue *q = &dev->channels[fh->channel_id].vidq; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 589 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 590 | /* add jump to stopper */ |
| 591 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 592 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 593 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 594 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 595 | dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 596 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 597 | if (!list_empty(&q->queued)) { |
| 598 | list_add_tail(&buf->vb.queue, &q->queued); |
| 599 | buf->vb.state = VIDEOBUF_QUEUED; |
| 600 | dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, |
| 601 | buf->vb.i); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 602 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 603 | } else if (list_empty(&q->active)) { |
| 604 | list_add_tail(&buf->vb.queue, &q->active); |
| 605 | cx25821_start_video_dma(dev, q, buf, |
| 606 | dev->channels[fh->channel_id].sram_channels); |
| 607 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 608 | buf->count = q->count++; |
| 609 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 610 | dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", |
| 611 | buf, buf->vb.i, buf->count, q->count); |
| 612 | } else { |
| 613 | prev = list_entry(q->active.prev, struct cx25821_buffer, |
| 614 | vb.queue); |
| 615 | if (prev->vb.width == buf->vb.width |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 616 | && prev->vb.height == buf->vb.height |
| 617 | && prev->fmt == buf->fmt) { |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 618 | list_add_tail(&buf->vb.queue, &q->active); |
| 619 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 620 | buf->count = q->count++; |
| 621 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 622 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 623 | /* 64 bit bits 63-32 */ |
| 624 | prev->risc.jmp[2] = cpu_to_le32(0); |
| 625 | dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", |
| 626 | buf, buf->vb.i, buf->count); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 627 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 628 | } else { |
| 629 | list_add_tail(&buf->vb.queue, &q->queued); |
| 630 | buf->vb.state = VIDEOBUF_QUEUED; |
| 631 | dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, |
| 632 | buf->vb.i); |
| 633 | } |
| 634 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 635 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 636 | if (list_empty(&q->active)) |
| 637 | dprintk(2, "active queue empty!\n"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static struct videobuf_queue_ops cx25821_video_qops = { |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 641 | .buf_setup = cx25821_buffer_setup, |
| 642 | .buf_prepare = cx25821_buffer_prepare, |
| 643 | .buf_queue = buffer_queue, |
| 644 | .buf_release = cx25821_buffer_release, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 645 | }; |
| 646 | |
| 647 | static int video_open(struct file *file) |
| 648 | { |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 649 | struct video_device *vdev = video_devdata(file); |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 650 | struct cx25821_dev *dev = video_drvdata(file); |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 651 | struct cx25821_fh *fh; |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 652 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 653 | u32 pix_format; |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 654 | int ch_id; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 655 | |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 656 | dprintk(1, "open dev=%s type=%s\n", video_device_node_name(vdev), |
| 657 | v4l2_type_names[type]); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 658 | |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 659 | for (ch_id = 0; ch_id < MAX_VID_CHANNEL_NUM - 1; ch_id++) |
| 660 | if (dev->channels[ch_id].video_dev == vdev) |
| 661 | break; |
| 662 | |
| 663 | /* Can't happen */ |
| 664 | if (ch_id >= MAX_VID_CHANNEL_NUM - 1) |
| 665 | return -ENODEV; |
| 666 | |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 667 | /* allocate + initialize per filehandle data */ |
| 668 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); |
| 669 | if (NULL == fh) |
| 670 | return -ENOMEM; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 671 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 672 | file->private_data = fh; |
| 673 | fh->dev = dev; |
| 674 | fh->type = type; |
| 675 | fh->width = 720; |
| 676 | fh->channel_id = ch_id; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 677 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 678 | if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) |
| 679 | fh->height = 576; |
| 680 | else |
| 681 | fh->height = 480; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 682 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 683 | dev->channel_opened = fh->channel_id; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 684 | if (dev->channels[ch_id].pixel_formats == PIXEL_FRMT_411) |
| 685 | pix_format = V4L2_PIX_FMT_Y41P; |
| 686 | else |
| 687 | pix_format = V4L2_PIX_FMT_YUYV; |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 688 | fh->fmt = cx25821_format_by_fourcc(pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 689 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 690 | v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 691 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 692 | videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, &dev->pci->dev, |
| 693 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 694 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), |
| 695 | fh, NULL); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 696 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 697 | dprintk(1, "post videobuf_queue_init()\n"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 698 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 699 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static ssize_t video_read(struct file *file, char __user * data, size_t count, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 703 | loff_t *ppos) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 704 | { |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 705 | struct cx25821_fh *fh = file->private_data; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 706 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 707 | switch (fh->type) { |
| 708 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 709 | if (cx25821_res_locked(fh, RESOURCE_VIDEO0)) |
| 710 | return -EBUSY; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 711 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 712 | return videobuf_read_one(&fh->vidq, data, count, ppos, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 713 | file->f_flags & O_NONBLOCK); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 714 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 715 | default: |
| 716 | BUG(); |
| 717 | return 0; |
| 718 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static unsigned int video_poll(struct file *file, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 722 | struct poll_table_struct *wait) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 723 | { |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 724 | struct cx25821_fh *fh = file->private_data; |
| 725 | struct cx25821_buffer *buf; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 726 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 727 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { |
| 728 | /* streaming capture */ |
| 729 | if (list_empty(&fh->vidq.stream)) |
| 730 | return POLLERR; |
| 731 | buf = list_entry(fh->vidq.stream.next, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 732 | struct cx25821_buffer, vb.stream); |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 733 | } else { |
| 734 | /* read() capture */ |
| 735 | buf = (struct cx25821_buffer *)fh->vidq.read_buf; |
| 736 | if (NULL == buf) |
| 737 | return POLLERR; |
| 738 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 739 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 740 | poll_wait(file, &buf->vb.done, wait); |
| 741 | if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) { |
| 742 | if (buf->vb.state == VIDEOBUF_DONE) { |
| 743 | struct cx25821_dev *dev = fh->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 744 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 745 | if (dev && dev->channels[fh->channel_id] |
| 746 | .use_cif_resolution) { |
| 747 | u8 cam_id = *((char *)buf->vb.baddr + 3); |
| 748 | memcpy((char *)buf->vb.baddr, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 749 | (char *)buf->vb.baddr + (fh->width * 2), |
| 750 | (fh->width * 2)); |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 751 | *((char *)buf->vb.baddr + 3) = cam_id; |
| 752 | } |
| 753 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 754 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 755 | return POLLIN | POLLRDNORM; |
| 756 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 757 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 758 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | static int video_release(struct file *file) |
| 762 | { |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 763 | struct cx25821_fh *fh = file->private_data; |
| 764 | struct cx25821_dev *dev = fh->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 765 | const struct sram_channel *sram_ch = |
| 766 | dev->channels[0].sram_channels; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 767 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 768 | /* stop the risc engine and fifo */ |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 769 | cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 770 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 771 | /* stop video capture */ |
| 772 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { |
| 773 | videobuf_queue_cancel(&fh->vidq); |
| 774 | cx25821_res_free(dev, fh, RESOURCE_VIDEO0); |
| 775 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 776 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 777 | if (fh->vidq.read_buf) { |
| 778 | cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf); |
| 779 | kfree(fh->vidq.read_buf); |
| 780 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 781 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 782 | videobuf_mmap_free(&fh->vidq); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 783 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 784 | v4l2_prio_close(&dev->channels[fh->channel_id].prio, fh->prio); |
| 785 | file->private_data = NULL; |
| 786 | kfree(fh); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 787 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 788 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 789 | } |
| 790 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 791 | /* VIDEO IOCTLS */ |
| 792 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 793 | struct v4l2_format *f) |
| 794 | { |
| 795 | struct cx25821_fh *fh = priv; |
| 796 | |
| 797 | f->fmt.pix.width = fh->width; |
| 798 | f->fmt.pix.height = fh->height; |
| 799 | f->fmt.pix.field = fh->vidq.field; |
| 800 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 801 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fh->fmt->depth) >> 3; |
| 802 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 808 | struct v4l2_format *f) |
| 809 | { |
| 810 | const struct cx25821_fmt *fmt; |
| 811 | enum v4l2_field field; |
| 812 | unsigned int maxw, maxh; |
| 813 | |
| 814 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 815 | if (NULL == fmt) |
| 816 | return -EINVAL; |
| 817 | |
| 818 | field = f->fmt.pix.field; |
| 819 | maxw = 720; |
| 820 | maxh = 576; |
| 821 | |
| 822 | if (V4L2_FIELD_ANY == field) { |
| 823 | if (f->fmt.pix.height > maxh / 2) |
| 824 | field = V4L2_FIELD_INTERLACED; |
| 825 | else |
| 826 | field = V4L2_FIELD_TOP; |
| 827 | } |
| 828 | |
| 829 | switch (field) { |
| 830 | case V4L2_FIELD_TOP: |
| 831 | case V4L2_FIELD_BOTTOM: |
| 832 | maxh = maxh / 2; |
| 833 | break; |
| 834 | case V4L2_FIELD_INTERLACED: |
| 835 | break; |
| 836 | default: |
| 837 | return -EINVAL; |
| 838 | } |
| 839 | |
| 840 | f->fmt.pix.field = field; |
| 841 | if (f->fmt.pix.height < 32) |
| 842 | f->fmt.pix.height = 32; |
| 843 | if (f->fmt.pix.height > maxh) |
| 844 | f->fmt.pix.height = maxh; |
| 845 | if (f->fmt.pix.width < 48) |
| 846 | f->fmt.pix.width = 48; |
| 847 | if (f->fmt.pix.width > maxw) |
| 848 | f->fmt.pix.width = maxw; |
| 849 | f->fmt.pix.width &= ~0x03; |
| 850 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 851 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 852 | |
| 853 | return 0; |
| 854 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 855 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 856 | { |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 857 | struct cx25821_fh *fh = priv; |
| 858 | struct cx25821_dev *dev = fh->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 859 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 860 | if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) |
| 861 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 862 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 863 | if (unlikely(i != fh->type)) |
| 864 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 865 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 866 | if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, |
| 867 | RESOURCE_VIDEO0)))) |
| 868 | return -EBUSY; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 869 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 870 | return videobuf_streamon(get_queue(fh)); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 874 | { |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 875 | struct cx25821_fh *fh = priv; |
| 876 | struct cx25821_dev *dev = fh->dev; |
| 877 | int err, res; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 878 | |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 879 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 880 | return -EINVAL; |
| 881 | if (i != fh->type) |
| 882 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 883 | |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 884 | res = cx25821_get_resource(fh, RESOURCE_VIDEO0); |
| 885 | err = videobuf_streamoff(get_queue(fh)); |
| 886 | if (err < 0) |
| 887 | return err; |
| 888 | cx25821_res_free(dev, fh, res); |
| 889 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 890 | } |
| 891 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 892 | static int cx25821_is_valid_width(u32 width, v4l2_std_id tvnorm) |
| 893 | { |
| 894 | if (tvnorm == V4L2_STD_PAL_BG) { |
| 895 | if (width == 352 || width == 720) |
| 896 | return 1; |
| 897 | else |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | if (tvnorm == V4L2_STD_NTSC_M) { |
| 902 | if (width == 320 || width == 352 || width == 720) |
| 903 | return 1; |
| 904 | else |
| 905 | return 0; |
| 906 | } |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | static int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm) |
| 911 | { |
| 912 | if (tvnorm == V4L2_STD_PAL_BG) { |
| 913 | if (height == 576 || height == 288) |
| 914 | return 1; |
| 915 | else |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | if (tvnorm == V4L2_STD_NTSC_M) { |
| 920 | if (height == 480 || height == 240) |
| 921 | return 1; |
| 922 | else |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 929 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 930 | struct v4l2_format *f) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 931 | { |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 932 | struct cx25821_fh *fh = priv; |
| 933 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Hans Verkuil | c5e76a6 | 2010-08-06 16:18:23 -0300 | [diff] [blame] | 934 | struct v4l2_mbus_framefmt mbus_fmt; |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 935 | int err; |
| 936 | int pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 937 | |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 938 | if (fh) { |
| 939 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 940 | fh->prio); |
| 941 | if (0 != err) |
| 942 | return err; |
| 943 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 944 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 945 | dprintk(2, "%s()\n", __func__); |
| 946 | err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 947 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 948 | if (0 != err) |
| 949 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 950 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 951 | fh->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 952 | fh->vidq.field = f->fmt.pix.field; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 953 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 954 | /* check if width and height is valid based on set standard */ |
| 955 | if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) |
| 956 | fh->width = f->fmt.pix.width; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 957 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 958 | if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) |
| 959 | fh->height = f->fmt.pix.height; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 960 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 961 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 962 | pix_format = PIXEL_FRMT_411; |
| 963 | else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) |
| 964 | pix_format = PIXEL_FRMT_422; |
| 965 | else |
| 966 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 967 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 968 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 969 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 970 | /* check if cif resolution */ |
| 971 | if (fh->width == 320 || fh->width == 352) |
| 972 | dev->channels[fh->channel_id].use_cif_resolution = 1; |
| 973 | else |
| 974 | dev->channels[fh->channel_id].use_cif_resolution = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 975 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 976 | dev->channels[fh->channel_id].cif_width = fh->width; |
| 977 | medusa_set_resolution(dev, fh->width, SRAM_CH00); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 978 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 979 | dprintk(2, "%s(): width=%d height=%d field=%d\n", __func__, fh->width, |
| 980 | fh->height, fh->vidq.field); |
Hans Verkuil | c5e76a6 | 2010-08-06 16:18:23 -0300 | [diff] [blame] | 981 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 982 | cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 983 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 984 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
| 988 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 989 | int ret_val = 0; |
| 990 | struct cx25821_fh *fh = priv; |
| 991 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 992 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 993 | ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 994 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 995 | p->sequence = dev->channels[fh->channel_id].vidq.count; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 996 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 997 | return ret_val; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | static int vidioc_log_status(struct file *file, void *priv) |
| 1001 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 1002 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1003 | struct cx25821_fh *fh = priv; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 1004 | const struct sram_channel *sram_ch = |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 1005 | dev->channels[fh->channel_id].sram_channels; |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 1006 | u32 tmp = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1007 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 1008 | cx25821_call_all(dev, core, log_status); |
| 1009 | tmp = cx_read(sram_ch->dma_ctl); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1010 | pr_info("Video input 0 is %s\n", |
| 1011 | (tmp & 0x11) ? "streaming" : "stopped"); |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 1012 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1013 | } |
| 1014 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1015 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1016 | static int cx25821_vidioc_querycap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1017 | struct v4l2_capability *cap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1018 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1019 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 1020 | struct cx25821_fh *fh = priv; |
| 1021 | const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE | |
| 1022 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 1023 | const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1024 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1025 | strcpy(cap->driver, "cx25821"); |
| 1026 | strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); |
| 1027 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 1028 | if (fh->channel_id >= VID_CHANNEL_NUM) |
| 1029 | cap->device_caps = cap_output; |
| 1030 | else |
| 1031 | cap->device_caps = cap_input; |
| 1032 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1033 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1034 | } |
| 1035 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1036 | static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1037 | struct v4l2_fmtdesc *f) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1038 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1039 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 1040 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1041 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1042 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 1043 | f->pixelformat = formats[f->index].fourcc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1044 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1045 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1046 | } |
| 1047 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1048 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1049 | struct v4l2_requestbuffers *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1050 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1051 | struct cx25821_fh *fh = priv; |
| 1052 | return videobuf_reqbufs(get_queue(fh), p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1053 | } |
| 1054 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1055 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1056 | struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1057 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1058 | struct cx25821_fh *fh = priv; |
| 1059 | return videobuf_querybuf(get_queue(fh), p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1060 | } |
| 1061 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1062 | static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1063 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1064 | struct cx25821_fh *fh = priv; |
| 1065 | return videobuf_qbuf(get_queue(fh), p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1066 | } |
| 1067 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1068 | static int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1069 | { |
| 1070 | struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1071 | struct cx25821_fh *fh = f; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1072 | |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1073 | *p = v4l2_prio_max(&dev->channels[fh->channel_id].prio); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1078 | static int cx25821_vidioc_s_priority(struct file *file, void *f, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1079 | enum v4l2_priority prio) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1080 | { |
| 1081 | struct cx25821_fh *fh = f; |
| 1082 | struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; |
| 1083 | |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1084 | return v4l2_prio_change(&dev->channels[fh->channel_id].prio, &fh->prio, |
| 1085 | prio); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1086 | } |
| 1087 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1088 | static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms) |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 1089 | { |
| 1090 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1091 | |
| 1092 | *tvnorms = dev->tvnorm; |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1096 | int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id tvnorms) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1097 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1098 | struct cx25821_fh *fh = priv; |
| 1099 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1100 | int err; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1101 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1102 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1103 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1104 | if (fh) { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1105 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 1106 | fh->prio); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1107 | if (0 != err) |
| 1108 | return err; |
| 1109 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1110 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1111 | if (dev->tvnorm == tvnorms) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1112 | return 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1113 | |
| 1114 | mutex_lock(&dev->lock); |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1115 | cx25821_set_tvnorm(dev, tvnorms); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1116 | mutex_unlock(&dev->lock); |
| 1117 | |
| 1118 | medusa_set_videostandard(dev); |
| 1119 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1120 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1121 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1122 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1123 | static int cx25821_vidioc_enum_input(struct file *file, void *priv, |
| 1124 | struct v4l2_input *i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1125 | { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1126 | static const char * const iname[] = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1127 | [CX25821_VMUX_COMPOSITE] = "Composite", |
| 1128 | [CX25821_VMUX_SVIDEO] = "S-Video", |
| 1129 | [CX25821_VMUX_DEBUG] = "for debug only", |
| 1130 | }; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1131 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1132 | unsigned int n; |
| 1133 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1134 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1135 | n = i->index; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1136 | if (n >= CX25821_NR_INPUT) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1137 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1138 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1139 | if (0 == INPUT(n)->type) |
| 1140 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1141 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1142 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1143 | strcpy(i->name, iname[INPUT(n)->type]); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1144 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1145 | i->std = CX25821_NORMS; |
| 1146 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1147 | } |
| 1148 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1149 | static int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1150 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1151 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1152 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1153 | *i = dev->input; |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1154 | dprintk(1, "%s(): returns %d\n", __func__, *i); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1155 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1156 | } |
| 1157 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1158 | static int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1159 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1160 | struct cx25821_fh *fh = priv; |
| 1161 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1162 | int err; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1163 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1164 | dprintk(1, "%s(%d)\n", __func__, i); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1165 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1166 | if (fh) { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1167 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 1168 | fh->prio); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1169 | if (0 != err) |
| 1170 | return err; |
| 1171 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1172 | |
Hans Verkuil | 6b1dce2 | 2013-04-13 07:39:19 -0300 | [diff] [blame] | 1173 | if (i >= CX25821_NR_INPUT || INPUT(i)->type == 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1174 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1175 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1176 | mutex_lock(&dev->lock); |
| 1177 | cx25821_video_mux(dev, i); |
| 1178 | mutex_unlock(&dev->lock); |
| 1179 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1180 | } |
| 1181 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1182 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 1183 | int cx25821_vidioc_g_register(struct file *file, void *fh, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1184 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1185 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1186 | struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1187 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1188 | if (!v4l2_chip_match_host(®->match)) |
| 1189 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1190 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1191 | cx25821_call_all(dev, core, g_register, reg); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1192 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1193 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1194 | } |
| 1195 | |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 1196 | int cx25821_vidioc_s_register(struct file *file, void *fh, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1197 | const struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1198 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1199 | struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1200 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1201 | if (!v4l2_chip_match_host(®->match)) |
| 1202 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1203 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1204 | cx25821_call_all(dev, core, s_register, reg); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1205 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1206 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | #endif |
| 1210 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1211 | /*****************************************************************************/ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1212 | static const struct v4l2_queryctrl no_ctl = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1213 | .name = "42", |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1214 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 1215 | }; |
| 1216 | |
| 1217 | static struct v4l2_queryctrl cx25821_ctls[] = { |
| 1218 | /* --- video --- */ |
| 1219 | { |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 1220 | .id = V4L2_CID_BRIGHTNESS, |
| 1221 | .name = "Brightness", |
| 1222 | .minimum = 0, |
| 1223 | .maximum = 10000, |
| 1224 | .step = 1, |
| 1225 | .default_value = 6200, |
| 1226 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1227 | }, { |
| 1228 | .id = V4L2_CID_CONTRAST, |
| 1229 | .name = "Contrast", |
| 1230 | .minimum = 0, |
| 1231 | .maximum = 10000, |
| 1232 | .step = 1, |
| 1233 | .default_value = 5000, |
| 1234 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1235 | }, { |
| 1236 | .id = V4L2_CID_SATURATION, |
| 1237 | .name = "Saturation", |
| 1238 | .minimum = 0, |
| 1239 | .maximum = 10000, |
| 1240 | .step = 1, |
| 1241 | .default_value = 5000, |
| 1242 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1243 | }, { |
| 1244 | .id = V4L2_CID_HUE, |
| 1245 | .name = "Hue", |
| 1246 | .minimum = 0, |
| 1247 | .maximum = 10000, |
| 1248 | .step = 1, |
| 1249 | .default_value = 5000, |
| 1250 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1251 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1252 | }; |
| 1253 | static const int CX25821_CTLS = ARRAY_SIZE(cx25821_ctls); |
| 1254 | |
| 1255 | static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl) |
| 1256 | { |
| 1257 | int i; |
| 1258 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1259 | if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1260 | return -EINVAL; |
| 1261 | for (i = 0; i < CX25821_CTLS; i++) |
| 1262 | if (cx25821_ctls[i].id == qctrl->id) |
| 1263 | break; |
| 1264 | if (i == CX25821_CTLS) { |
| 1265 | *qctrl = no_ctl; |
| 1266 | return 0; |
| 1267 | } |
| 1268 | *qctrl = cx25821_ctls[i]; |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1272 | static int cx25821_vidioc_queryctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1273 | struct v4l2_queryctrl *qctrl) |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1274 | { |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1275 | return cx25821_ctrl_query(qctrl); |
| 1276 | } |
| 1277 | |
| 1278 | /* ------------------------------------------------------------------ */ |
| 1279 | /* VIDEO CTRL IOCTLS */ |
| 1280 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1281 | static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1282 | { |
| 1283 | unsigned int i; |
| 1284 | |
| 1285 | for (i = 0; i < CX25821_CTLS; i++) |
| 1286 | if (cx25821_ctls[i].id == id) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1287 | return cx25821_ctls + i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1288 | return NULL; |
| 1289 | } |
| 1290 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1291 | static int cx25821_vidioc_g_ctrl(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1292 | struct v4l2_control *ctl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1293 | { |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1294 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Leonid V. Fedorenchik | e0b871b | 2011-09-16 14:15:00 +0800 | [diff] [blame] | 1295 | struct cx25821_fh *fh = priv; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1296 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1297 | const struct v4l2_queryctrl *ctrl; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1298 | |
| 1299 | ctrl = ctrl_by_id(ctl->id); |
| 1300 | |
| 1301 | if (NULL == ctrl) |
| 1302 | return -EINVAL; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1303 | switch (ctl->id) { |
| 1304 | case V4L2_CID_BRIGHTNESS: |
Leonid V. Fedorenchik | e0b871b | 2011-09-16 14:15:00 +0800 | [diff] [blame] | 1305 | ctl->value = dev->channels[fh->channel_id].ctl_bright; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1306 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1307 | case V4L2_CID_HUE: |
Leonid V. Fedorenchik | e0b871b | 2011-09-16 14:15:00 +0800 | [diff] [blame] | 1308 | ctl->value = dev->channels[fh->channel_id].ctl_hue; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1309 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1310 | case V4L2_CID_CONTRAST: |
Leonid V. Fedorenchik | e0b871b | 2011-09-16 14:15:00 +0800 | [diff] [blame] | 1311 | ctl->value = dev->channels[fh->channel_id].ctl_contrast; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1312 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1313 | case V4L2_CID_SATURATION: |
Leonid V. Fedorenchik | e0b871b | 2011-09-16 14:15:00 +0800 | [diff] [blame] | 1314 | ctl->value = dev->channels[fh->channel_id].ctl_saturation; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1315 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1316 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1317 | return 0; |
| 1318 | } |
| 1319 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1320 | static int cx25821_set_control(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1321 | struct v4l2_control *ctl, int chan_num) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1322 | { |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1323 | int err; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1324 | const struct v4l2_queryctrl *ctrl; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1325 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1326 | err = -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1327 | |
| 1328 | ctrl = ctrl_by_id(ctl->id); |
| 1329 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1330 | if (NULL == ctrl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1331 | return err; |
| 1332 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1333 | switch (ctrl->type) { |
| 1334 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 1335 | case V4L2_CTRL_TYPE_MENU: |
| 1336 | case V4L2_CTRL_TYPE_INTEGER: |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1337 | if (ctl->value < ctrl->minimum) |
| 1338 | ctl->value = ctrl->minimum; |
| 1339 | if (ctl->value > ctrl->maximum) |
| 1340 | ctl->value = ctrl->maximum; |
| 1341 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1342 | default: |
| 1343 | /* nothing */ ; |
Joe Perches | 95cd17c | 2011-04-10 14:31:35 -0700 | [diff] [blame] | 1344 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1345 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1346 | switch (ctl->id) { |
| 1347 | case V4L2_CID_BRIGHTNESS: |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1348 | dev->channels[chan_num].ctl_bright = ctl->value; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1349 | medusa_set_brightness(dev, ctl->value, chan_num); |
| 1350 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1351 | case V4L2_CID_HUE: |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1352 | dev->channels[chan_num].ctl_hue = ctl->value; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1353 | medusa_set_hue(dev, ctl->value, chan_num); |
| 1354 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1355 | case V4L2_CID_CONTRAST: |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1356 | dev->channels[chan_num].ctl_contrast = ctl->value; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1357 | medusa_set_contrast(dev, ctl->value, chan_num); |
| 1358 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1359 | case V4L2_CID_SATURATION: |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1360 | dev->channels[chan_num].ctl_saturation = ctl->value; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1361 | medusa_set_saturation(dev, ctl->value, chan_num); |
| 1362 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1363 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1364 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1365 | err = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1366 | |
| 1367 | return err; |
| 1368 | } |
| 1369 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1370 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1371 | struct v4l2_control *ctl) |
| 1372 | { |
| 1373 | struct cx25821_fh *fh = priv; |
| 1374 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1375 | int err; |
| 1376 | |
| 1377 | if (fh) { |
| 1378 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 1379 | fh->prio); |
| 1380 | if (0 != err) |
| 1381 | return err; |
| 1382 | } |
| 1383 | |
| 1384 | return cx25821_set_control(dev, ctl, fh->channel_id); |
| 1385 | } |
| 1386 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1387 | static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1388 | { |
| 1389 | struct v4l2_control ctrl; |
| 1390 | int i; |
| 1391 | for (i = 0; i < CX25821_CTLS; i++) { |
| 1392 | ctrl.id = cx25821_ctls[i].id; |
| 1393 | ctrl.value = cx25821_ctls[i].default_value; |
| 1394 | |
| 1395 | cx25821_set_control(dev, &ctrl, chan_num); |
| 1396 | } |
| 1397 | } |
| 1398 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1399 | static int cx25821_vidioc_cropcap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1400 | struct v4l2_cropcap *cropcap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1401 | { |
| 1402 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1403 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1404 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1405 | return -EINVAL; |
Leonid V. Fedorenchik | a1937e1 | 2011-10-22 01:43:51 -0300 | [diff] [blame] | 1406 | cropcap->bounds.top = 0; |
| 1407 | cropcap->bounds.left = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1408 | cropcap->bounds.width = 720; |
| 1409 | cropcap->bounds.height = dev->tvnorm == V4L2_STD_PAL_BG ? 576 : 480; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1410 | cropcap->pixelaspect.numerator = |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1411 | dev->tvnorm == V4L2_STD_PAL_BG ? 59 : 10; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1412 | cropcap->pixelaspect.denominator = |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1413 | dev->tvnorm == V4L2_STD_PAL_BG ? 54 : 11; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1414 | cropcap->defrect = cropcap->bounds; |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1418 | static int cx25821_vidioc_s_crop(struct file *file, void *priv, const struct v4l2_crop *crop) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1419 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1420 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1421 | struct cx25821_fh *fh = priv; |
| 1422 | int err; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1423 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1424 | if (fh) { |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1425 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 1426 | fh->prio); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1427 | if (0 != err) |
| 1428 | return err; |
| 1429 | } |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1430 | /* cx25821_vidioc_s_crop not supported */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1431 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1432 | } |
| 1433 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame^] | 1434 | static int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1435 | { |
Leonid V. Fedorenchik | 8a911ed | 2011-09-16 14:15:01 +0800 | [diff] [blame] | 1436 | /* cx25821_vidioc_g_crop not supported */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1437 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1438 | } |
| 1439 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1440 | static long video_ioctl_upstream9(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1441 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1442 | { |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1443 | struct cx25821_fh *fh = file->private_data; |
| 1444 | struct cx25821_dev *dev = fh->dev; |
| 1445 | int command = 0; |
| 1446 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1447 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1448 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1449 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1450 | if (!data_from_user) { |
| 1451 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1452 | return 0; |
| 1453 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1454 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1455 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1456 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1457 | if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) |
| 1458 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1459 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1460 | dev->input_filename = data_from_user->input_filename; |
| 1461 | dev->input_audiofilename = data_from_user->input_filename; |
| 1462 | dev->vid_stdname = data_from_user->vid_stdname; |
| 1463 | dev->pixel_format = data_from_user->pixel_format; |
| 1464 | dev->channel_select = data_from_user->channel_select; |
| 1465 | dev->command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1466 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 1467 | switch (command) { |
| 1468 | case UPSTREAM_START_VIDEO: |
| 1469 | cx25821_start_upstream_video_ch1(dev, data_from_user); |
| 1470 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1471 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 1472 | case UPSTREAM_STOP_VIDEO: |
| 1473 | cx25821_stop_upstream_video_ch1(dev); |
| 1474 | break; |
| 1475 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1476 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 1477 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | static long video_ioctl_upstream10(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1481 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1482 | { |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1483 | struct cx25821_fh *fh = file->private_data; |
| 1484 | struct cx25821_dev *dev = fh->dev; |
| 1485 | int command = 0; |
| 1486 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1487 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1488 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1489 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1490 | if (!data_from_user) { |
| 1491 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1492 | return 0; |
| 1493 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1494 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1495 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1496 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1497 | if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) |
| 1498 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1499 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1500 | dev->input_filename_ch2 = data_from_user->input_filename; |
| 1501 | dev->input_audiofilename = data_from_user->input_filename; |
| 1502 | dev->vid_stdname_ch2 = data_from_user->vid_stdname; |
| 1503 | dev->pixel_format_ch2 = data_from_user->pixel_format; |
| 1504 | dev->channel_select_ch2 = data_from_user->channel_select; |
| 1505 | dev->command_ch2 = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1506 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 1507 | switch (command) { |
| 1508 | case UPSTREAM_START_VIDEO: |
| 1509 | cx25821_start_upstream_video_ch2(dev, data_from_user); |
| 1510 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1511 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 1512 | case UPSTREAM_STOP_VIDEO: |
| 1513 | cx25821_stop_upstream_video_ch2(dev); |
| 1514 | break; |
| 1515 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1516 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 1517 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static long video_ioctl_upstream11(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1521 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1522 | { |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1523 | struct cx25821_fh *fh = file->private_data; |
| 1524 | struct cx25821_dev *dev = fh->dev; |
| 1525 | int command = 0; |
| 1526 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1527 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1528 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1529 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1530 | if (!data_from_user) { |
| 1531 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1532 | return 0; |
| 1533 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1534 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1535 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1536 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1537 | if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) |
| 1538 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1539 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1540 | dev->input_filename = data_from_user->input_filename; |
| 1541 | dev->input_audiofilename = data_from_user->input_filename; |
| 1542 | dev->vid_stdname = data_from_user->vid_stdname; |
| 1543 | dev->pixel_format = data_from_user->pixel_format; |
| 1544 | dev->channel_select = data_from_user->channel_select; |
| 1545 | dev->command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1546 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1547 | switch (command) { |
| 1548 | case UPSTREAM_START_AUDIO: |
| 1549 | cx25821_start_upstream_audio(dev, data_from_user); |
| 1550 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1551 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1552 | case UPSTREAM_STOP_AUDIO: |
| 1553 | cx25821_stop_upstream_audio(dev); |
| 1554 | break; |
| 1555 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1556 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1557 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static long video_ioctl_set(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1561 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1562 | { |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1563 | struct cx25821_fh *fh = file->private_data; |
| 1564 | struct cx25821_dev *dev = fh->dev; |
| 1565 | struct downstream_user_struct *data_from_user; |
| 1566 | int command; |
| 1567 | int width = 720; |
Leonid V. Fedorenchik | 4a33b6f | 2011-10-22 01:43:52 -0300 | [diff] [blame] | 1568 | int selected_channel = 0; |
| 1569 | int pix_format = 0; |
| 1570 | int i = 0; |
| 1571 | int cif_enable = 0; |
| 1572 | int cif_width = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1573 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1574 | data_from_user = (struct downstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1575 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1576 | if (!data_from_user) { |
| 1577 | pr_err("%s(): User data is INVALID. Returning\n", __func__); |
| 1578 | return 0; |
| 1579 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1580 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1581 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1582 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1583 | if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1584 | && command != ENABLE_CIF_RESOLUTION && command != REG_READ |
| 1585 | && command != REG_WRITE && command != MEDUSA_READ |
| 1586 | && command != MEDUSA_WRITE) { |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1587 | return 0; |
| 1588 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1589 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1590 | switch (command) { |
| 1591 | case SET_VIDEO_STD: |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1592 | if (!strcmp(data_from_user->vid_stdname, "PAL")) |
| 1593 | dev->tvnorm = V4L2_STD_PAL_BG; |
| 1594 | else |
| 1595 | dev->tvnorm = V4L2_STD_NTSC_M; |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1596 | medusa_set_videostandard(dev); |
| 1597 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1598 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1599 | case SET_PIXEL_FORMAT: |
| 1600 | selected_channel = data_from_user->decoder_select; |
| 1601 | pix_format = data_from_user->pixel_format; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1602 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1603 | if (!(selected_channel <= 7 && selected_channel >= 0)) { |
| 1604 | selected_channel -= 4; |
| 1605 | selected_channel = selected_channel % 8; |
| 1606 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1607 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1608 | if (selected_channel >= 0) |
| 1609 | cx25821_set_pixel_format(dev, selected_channel, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1610 | pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1611 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1612 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1613 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1614 | case ENABLE_CIF_RESOLUTION: |
| 1615 | selected_channel = data_from_user->decoder_select; |
| 1616 | cif_enable = data_from_user->cif_resolution_enable; |
| 1617 | cif_width = data_from_user->cif_width; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1618 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1619 | if (cif_enable) { |
| 1620 | if (dev->tvnorm & V4L2_STD_PAL_BG |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1621 | || dev->tvnorm & V4L2_STD_PAL_DK) { |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1622 | width = 352; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1623 | } else { |
| 1624 | width = cif_width; |
| 1625 | if (cif_width != 320 && cif_width != 352) |
| 1626 | width = 320; |
| 1627 | } |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1628 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1629 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1630 | if (!(selected_channel <= 7 && selected_channel >= 0)) { |
| 1631 | selected_channel -= 4; |
| 1632 | selected_channel = selected_channel % 8; |
| 1633 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1634 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1635 | if (selected_channel <= 7 && selected_channel >= 0) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 1636 | dev->channels[selected_channel].use_cif_resolution = |
| 1637 | cif_enable; |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1638 | dev->channels[selected_channel].cif_width = width; |
| 1639 | } else { |
| 1640 | for (i = 0; i < VID_CHANNEL_NUM; i++) { |
| 1641 | dev->channels[i].use_cif_resolution = |
| 1642 | cif_enable; |
| 1643 | dev->channels[i].cif_width = width; |
| 1644 | } |
| 1645 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1646 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1647 | medusa_set_resolution(dev, width, selected_channel); |
| 1648 | break; |
| 1649 | case REG_READ: |
| 1650 | data_from_user->reg_data = cx_read(data_from_user->reg_address); |
| 1651 | break; |
| 1652 | case REG_WRITE: |
| 1653 | cx_write(data_from_user->reg_address, data_from_user->reg_data); |
| 1654 | break; |
| 1655 | case MEDUSA_READ: |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 1656 | cx25821_i2c_read(&dev->i2c_bus[0], |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1657 | (u16) data_from_user->reg_address, |
| 1658 | &data_from_user->reg_data); |
| 1659 | break; |
| 1660 | case MEDUSA_WRITE: |
| 1661 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 1662 | (u16) data_from_user->reg_address, |
| 1663 | data_from_user->reg_data); |
| 1664 | break; |
| 1665 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1666 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1667 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | static long cx25821_video_ioctl(struct file *file, |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1671 | unsigned int cmd, unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1672 | { |
Leonid V. Fedorenchik | 1316b63 | 2011-10-22 01:43:50 -0300 | [diff] [blame] | 1673 | int ret = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1674 | |
Leonid V. Fedorenchik | 1316b63 | 2011-10-22 01:43:50 -0300 | [diff] [blame] | 1675 | struct cx25821_fh *fh = file->private_data; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1676 | |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1677 | /* check to see if it's the video upstream */ |
| 1678 | if (fh->channel_id == SRAM_CH09) { |
| 1679 | ret = video_ioctl_upstream9(file, cmd, arg); |
| 1680 | return ret; |
| 1681 | } else if (fh->channel_id == SRAM_CH10) { |
| 1682 | ret = video_ioctl_upstream10(file, cmd, arg); |
| 1683 | return ret; |
| 1684 | } else if (fh->channel_id == SRAM_CH11) { |
| 1685 | ret = video_ioctl_upstream11(file, cmd, arg); |
| 1686 | ret = video_ioctl_set(file, cmd, arg); |
| 1687 | return ret; |
| 1688 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1689 | |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1690 | return video_ioctl2(file, cmd, arg); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | /* exported stuff */ |
| 1694 | static const struct v4l2_file_operations video_fops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1695 | .owner = THIS_MODULE, |
| 1696 | .open = video_open, |
| 1697 | .release = video_release, |
| 1698 | .read = video_read, |
| 1699 | .poll = video_poll, |
| 1700 | .mmap = cx25821_video_mmap, |
| 1701 | .ioctl = cx25821_video_ioctl, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1702 | }; |
| 1703 | |
| 1704 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1705 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 1706 | .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap, |
| 1707 | .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, |
| 1708 | .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, |
| 1709 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 1710 | .vidioc_reqbufs = cx25821_vidioc_reqbufs, |
| 1711 | .vidioc_querybuf = cx25821_vidioc_querybuf, |
| 1712 | .vidioc_qbuf = cx25821_vidioc_qbuf, |
| 1713 | .vidioc_dqbuf = vidioc_dqbuf, |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 1714 | .vidioc_g_std = cx25821_vidioc_g_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1715 | .vidioc_s_std = cx25821_vidioc_s_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1716 | .vidioc_cropcap = cx25821_vidioc_cropcap, |
| 1717 | .vidioc_s_crop = cx25821_vidioc_s_crop, |
| 1718 | .vidioc_g_crop = cx25821_vidioc_g_crop, |
| 1719 | .vidioc_enum_input = cx25821_vidioc_enum_input, |
| 1720 | .vidioc_g_input = cx25821_vidioc_g_input, |
| 1721 | .vidioc_s_input = cx25821_vidioc_s_input, |
| 1722 | .vidioc_g_ctrl = cx25821_vidioc_g_ctrl, |
| 1723 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1724 | .vidioc_queryctrl = cx25821_vidioc_queryctrl, |
| 1725 | .vidioc_streamon = vidioc_streamon, |
| 1726 | .vidioc_streamoff = vidioc_streamoff, |
| 1727 | .vidioc_log_status = vidioc_log_status, |
| 1728 | .vidioc_g_priority = cx25821_vidioc_g_priority, |
| 1729 | .vidioc_s_priority = cx25821_vidioc_s_priority, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1730 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1731 | .vidioc_g_register = cx25821_vidioc_g_register, |
| 1732 | .vidioc_s_register = cx25821_vidioc_s_register, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1733 | #endif |
| 1734 | }; |
| 1735 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1736 | static const struct video_device cx25821_video_device = { |
| 1737 | .name = "cx25821-video", |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 1738 | .fops = &video_fops, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1739 | .minor = -1, |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 1740 | .ioctl_ops = &video_ioctl_ops, |
| 1741 | .tvnorms = CX25821_NORMS, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1742 | }; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1743 | |
| 1744 | void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) |
| 1745 | { |
| 1746 | cx_clear(PCI_INT_MSK, 1); |
| 1747 | |
| 1748 | if (dev->channels[chan_num].video_dev) { |
| 1749 | if (video_is_registered(dev->channels[chan_num].video_dev)) |
| 1750 | video_unregister_device( |
| 1751 | dev->channels[chan_num].video_dev); |
| 1752 | else |
| 1753 | video_device_release( |
| 1754 | dev->channels[chan_num].video_dev); |
| 1755 | |
| 1756 | dev->channels[chan_num].video_dev = NULL; |
| 1757 | |
| 1758 | btcx_riscmem_free(dev->pci, |
| 1759 | &dev->channels[chan_num].vidq.stopper); |
| 1760 | |
| 1761 | pr_warn("device %d released!\n", chan_num); |
| 1762 | } |
| 1763 | |
| 1764 | } |
| 1765 | |
| 1766 | int cx25821_video_register(struct cx25821_dev *dev) |
| 1767 | { |
| 1768 | int err; |
| 1769 | int i; |
| 1770 | |
| 1771 | spin_lock_init(&dev->slock); |
| 1772 | |
| 1773 | for (i = 0; i < VID_CHANNEL_NUM; ++i) { |
| 1774 | if (i == SRAM_CH08) /* audio channel */ |
| 1775 | continue; |
| 1776 | |
| 1777 | cx25821_init_controls(dev, i); |
| 1778 | |
| 1779 | cx25821_risc_stopper(dev->pci, &dev->channels[i].vidq.stopper, |
| 1780 | dev->channels[i].sram_channels->dma_ctl, 0x11, 0); |
| 1781 | |
| 1782 | dev->channels[i].sram_channels = &cx25821_sram_channels[i]; |
| 1783 | dev->channels[i].video_dev = NULL; |
| 1784 | dev->channels[i].resources = 0; |
| 1785 | |
| 1786 | cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff); |
| 1787 | |
| 1788 | INIT_LIST_HEAD(&dev->channels[i].vidq.active); |
| 1789 | INIT_LIST_HEAD(&dev->channels[i].vidq.queued); |
| 1790 | |
| 1791 | dev->channels[i].timeout_data.dev = dev; |
| 1792 | dev->channels[i].timeout_data.channel = |
| 1793 | &cx25821_sram_channels[i]; |
| 1794 | dev->channels[i].vidq.timeout.function = cx25821_vid_timeout; |
| 1795 | dev->channels[i].vidq.timeout.data = |
| 1796 | (unsigned long)&dev->channels[i].timeout_data; |
| 1797 | init_timer(&dev->channels[i].vidq.timeout); |
| 1798 | |
| 1799 | /* register v4l devices */ |
| 1800 | dev->channels[i].video_dev = cx25821_vdev_init(dev, dev->pci, |
| 1801 | &cx25821_video_device, "video"); |
| 1802 | |
| 1803 | err = video_register_device(dev->channels[i].video_dev, |
| 1804 | VFL_TYPE_GRABBER, video_nr[dev->nr]); |
| 1805 | |
| 1806 | if (err < 0) |
| 1807 | goto fail_unreg; |
| 1808 | |
| 1809 | } |
| 1810 | |
| 1811 | /* set PCI interrupt */ |
| 1812 | cx_set(PCI_INT_MSK, 0xff); |
| 1813 | |
| 1814 | /* initial device configuration */ |
| 1815 | mutex_lock(&dev->lock); |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 1816 | dev->tvnorm = V4L2_STD_NTSC_M, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1817 | cx25821_set_tvnorm(dev, dev->tvnorm); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1818 | mutex_unlock(&dev->lock); |
| 1819 | |
| 1820 | return 0; |
| 1821 | |
| 1822 | fail_unreg: |
| 1823 | cx25821_video_unregister(dev, i); |
| 1824 | return err; |
| 1825 | } |