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