Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX23885 PCIe bridge |
| 3 | * |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org> |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/moduleparam.h> |
| 26 | #include <linux/kmod.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/kthread.h> |
| 32 | #include <asm/div64.h> |
| 33 | |
| 34 | #include "cx23885.h" |
| 35 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 36 | #include <media/v4l2-ioctl.h> |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 37 | #include "cx23885-ioctl.h" |
Kusanagi Kouichi | 0b32d65 | 2010-01-22 04:55:28 -0300 | [diff] [blame] | 38 | #include "tuner-xc2028.h" |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 39 | |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 40 | #include <media/cx25840.h> |
| 41 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 42 | MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards"); |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 43 | MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 44 | MODULE_LICENSE("GPL"); |
| 45 | |
| 46 | /* ------------------------------------------------------------------ */ |
| 47 | |
| 48 | static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET }; |
| 49 | static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET }; |
| 50 | static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET }; |
| 51 | |
| 52 | module_param_array(video_nr, int, NULL, 0444); |
| 53 | module_param_array(vbi_nr, int, NULL, 0444); |
| 54 | module_param_array(radio_nr, int, NULL, 0444); |
| 55 | |
| 56 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
| 57 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
| 58 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
| 59 | |
Steven Toth | 4513fc69 | 2008-01-12 11:36:36 -0300 | [diff] [blame] | 60 | static unsigned int video_debug; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 61 | module_param(video_debug, int, 0644); |
| 62 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
| 63 | |
Steven Toth | 4513fc69 | 2008-01-12 11:36:36 -0300 | [diff] [blame] | 64 | static unsigned int irq_debug; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 65 | module_param(irq_debug, int, 0644); |
| 66 | MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]"); |
| 67 | |
| 68 | static unsigned int vid_limit = 16; |
| 69 | module_param(vid_limit, int, 0644); |
| 70 | MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); |
| 71 | |
| 72 | #define dprintk(level, fmt, arg...)\ |
Steven Toth | 4513fc69 | 2008-01-12 11:36:36 -0300 | [diff] [blame] | 73 | do { if (video_debug >= level)\ |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 74 | printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\ |
Steven Toth | 4513fc69 | 2008-01-12 11:36:36 -0300 | [diff] [blame] | 75 | } while (0) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 76 | |
| 77 | /* ------------------------------------------------------------------- */ |
| 78 | /* static data */ |
| 79 | |
| 80 | #define FORMAT_FLAGS_PACKED 0x01 |
| 81 | |
| 82 | static struct cx23885_fmt formats[] = { |
| 83 | { |
| 84 | .name = "8 bpp, gray", |
| 85 | .fourcc = V4L2_PIX_FMT_GREY, |
| 86 | .depth = 8, |
| 87 | .flags = FORMAT_FLAGS_PACKED, |
| 88 | }, { |
| 89 | .name = "15 bpp RGB, le", |
| 90 | .fourcc = V4L2_PIX_FMT_RGB555, |
| 91 | .depth = 16, |
| 92 | .flags = FORMAT_FLAGS_PACKED, |
| 93 | }, { |
| 94 | .name = "15 bpp RGB, be", |
| 95 | .fourcc = V4L2_PIX_FMT_RGB555X, |
| 96 | .depth = 16, |
| 97 | .flags = FORMAT_FLAGS_PACKED, |
| 98 | }, { |
| 99 | .name = "16 bpp RGB, le", |
| 100 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 101 | .depth = 16, |
| 102 | .flags = FORMAT_FLAGS_PACKED, |
| 103 | }, { |
| 104 | .name = "16 bpp RGB, be", |
| 105 | .fourcc = V4L2_PIX_FMT_RGB565X, |
| 106 | .depth = 16, |
| 107 | .flags = FORMAT_FLAGS_PACKED, |
| 108 | }, { |
| 109 | .name = "24 bpp RGB, le", |
| 110 | .fourcc = V4L2_PIX_FMT_BGR24, |
| 111 | .depth = 24, |
| 112 | .flags = FORMAT_FLAGS_PACKED, |
| 113 | }, { |
| 114 | .name = "32 bpp RGB, le", |
| 115 | .fourcc = V4L2_PIX_FMT_BGR32, |
| 116 | .depth = 32, |
| 117 | .flags = FORMAT_FLAGS_PACKED, |
| 118 | }, { |
| 119 | .name = "32 bpp RGB, be", |
| 120 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 121 | .depth = 32, |
| 122 | .flags = FORMAT_FLAGS_PACKED, |
| 123 | }, { |
| 124 | .name = "4:2:2, packed, YUYV", |
| 125 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 126 | .depth = 16, |
| 127 | .flags = FORMAT_FLAGS_PACKED, |
| 128 | }, { |
| 129 | .name = "4:2:2, packed, UYVY", |
| 130 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 131 | .depth = 16, |
| 132 | .flags = FORMAT_FLAGS_PACKED, |
| 133 | }, |
| 134 | }; |
| 135 | |
| 136 | static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc) |
| 137 | { |
| 138 | unsigned int i; |
| 139 | |
| 140 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 141 | if (formats[i].fourcc == fourcc) |
| 142 | return formats+i; |
| 143 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 144 | printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 145 | return NULL; |
| 146 | } |
| 147 | |
| 148 | /* ------------------------------------------------------------------- */ |
| 149 | |
| 150 | static const struct v4l2_queryctrl no_ctl = { |
| 151 | .name = "42", |
| 152 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 153 | }; |
| 154 | |
| 155 | static struct cx23885_ctrl cx23885_ctls[] = { |
| 156 | /* --- video --- */ |
| 157 | { |
| 158 | .v = { |
| 159 | .id = V4L2_CID_BRIGHTNESS, |
| 160 | .name = "Brightness", |
| 161 | .minimum = 0x00, |
| 162 | .maximum = 0xff, |
| 163 | .step = 1, |
| 164 | .default_value = 0x7f, |
| 165 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 166 | }, |
| 167 | .off = 128, |
| 168 | .reg = LUMA_CTRL, |
| 169 | .mask = 0x00ff, |
| 170 | .shift = 0, |
| 171 | }, { |
| 172 | .v = { |
| 173 | .id = V4L2_CID_CONTRAST, |
| 174 | .name = "Contrast", |
| 175 | .minimum = 0, |
Mijhail Moreyra | b12ab3f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 176 | .maximum = 0x7f, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 177 | .step = 1, |
| 178 | .default_value = 0x3f, |
| 179 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 180 | }, |
| 181 | .off = 0, |
| 182 | .reg = LUMA_CTRL, |
| 183 | .mask = 0xff00, |
| 184 | .shift = 8, |
| 185 | }, { |
| 186 | .v = { |
| 187 | .id = V4L2_CID_HUE, |
| 188 | .name = "Hue", |
Mijhail Moreyra | b12ab3f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 189 | .minimum = -127, |
| 190 | .maximum = 128, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 191 | .step = 1, |
Mijhail Moreyra | b12ab3f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 192 | .default_value = 0x0, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 193 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 194 | }, |
| 195 | .off = 128, |
| 196 | .reg = CHROMA_CTRL, |
| 197 | .mask = 0xff0000, |
| 198 | .shift = 16, |
| 199 | }, { |
| 200 | /* strictly, this only describes only U saturation. |
| 201 | * V saturation is handled specially through code. |
| 202 | */ |
| 203 | .v = { |
| 204 | .id = V4L2_CID_SATURATION, |
| 205 | .name = "Saturation", |
| 206 | .minimum = 0, |
Mijhail Moreyra | b12ab3f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 207 | .maximum = 0x7f, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 208 | .step = 1, |
Mijhail Moreyra | b12ab3f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 209 | .default_value = 0x3f, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 210 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 211 | }, |
| 212 | .off = 0, |
| 213 | .reg = CHROMA_CTRL, |
| 214 | .mask = 0x00ff, |
| 215 | .shift = 0, |
| 216 | }, { |
| 217 | /* --- audio --- */ |
| 218 | .v = { |
| 219 | .id = V4L2_CID_AUDIO_MUTE, |
| 220 | .name = "Mute", |
| 221 | .minimum = 0, |
| 222 | .maximum = 1, |
| 223 | .default_value = 1, |
| 224 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 225 | }, |
| 226 | .reg = PATH1_CTL1, |
| 227 | .mask = (0x1f << 24), |
| 228 | .shift = 24, |
| 229 | }, { |
| 230 | .v = { |
| 231 | .id = V4L2_CID_AUDIO_VOLUME, |
| 232 | .name = "Volume", |
| 233 | .minimum = 0, |
| 234 | .maximum = 0x3f, |
| 235 | .step = 1, |
| 236 | .default_value = 0x3f, |
| 237 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 238 | }, |
| 239 | .reg = PATH1_VOL_CTL, |
| 240 | .mask = 0xff, |
| 241 | .shift = 0, |
| 242 | } |
| 243 | }; |
| 244 | static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls); |
| 245 | |
Hans Verkuil | 2ba5889 | 2009-02-13 10:57:48 -0300 | [diff] [blame] | 246 | /* Must be sorted from low to high control ID! */ |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 247 | static const u32 cx23885_user_ctrls[] = { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 248 | V4L2_CID_USER_CLASS, |
| 249 | V4L2_CID_BRIGHTNESS, |
| 250 | V4L2_CID_CONTRAST, |
| 251 | V4L2_CID_SATURATION, |
| 252 | V4L2_CID_HUE, |
| 253 | V4L2_CID_AUDIO_VOLUME, |
| 254 | V4L2_CID_AUDIO_MUTE, |
| 255 | 0 |
| 256 | }; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 257 | |
| 258 | static const u32 *ctrl_classes[] = { |
| 259 | cx23885_user_ctrls, |
| 260 | NULL |
| 261 | }; |
| 262 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 263 | void cx23885_video_wakeup(struct cx23885_dev *dev, |
| 264 | struct cx23885_dmaqueue *q, u32 count) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 265 | { |
| 266 | struct cx23885_buffer *buf; |
| 267 | int bc; |
| 268 | |
| 269 | for (bc = 0;; bc++) { |
| 270 | if (list_empty(&q->active)) |
| 271 | break; |
| 272 | buf = list_entry(q->active.next, |
| 273 | struct cx23885_buffer, vb.queue); |
Steven Toth | a19602f2 | 2008-01-10 11:43:18 -0300 | [diff] [blame] | 274 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 275 | /* count comes from the hw and is is 16bit wide -- |
| 276 | * this trick handles wrap-arounds correctly for |
| 277 | * up to 32767 buffers in flight... */ |
| 278 | if ((s16) (count - buf->count) < 0) |
| 279 | break; |
Steven Toth | a19602f2 | 2008-01-10 11:43:18 -0300 | [diff] [blame] | 280 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 281 | do_gettimeofday(&buf->vb.ts); |
| 282 | dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i, |
| 283 | count, buf->count); |
| 284 | buf->vb.state = VIDEOBUF_DONE; |
| 285 | list_del(&buf->vb.queue); |
| 286 | wake_up(&buf->vb.done); |
| 287 | } |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 288 | if (list_empty(&q->active)) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 289 | del_timer(&q->timeout); |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 290 | else |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 291 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 292 | if (bc != 1) |
Steven Toth | 21a7809 | 2008-01-10 04:38:59 -0300 | [diff] [blame] | 293 | printk(KERN_ERR "%s: %d buffers handled (should be 1)\n", |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 294 | __func__, bc); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 295 | } |
| 296 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 297 | static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 298 | { |
| 299 | dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 300 | __func__, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 301 | (unsigned int)norm, |
| 302 | v4l2_norm_to_name(norm)); |
| 303 | |
| 304 | dev->tvnorm = norm; |
| 305 | |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 306 | call_all(dev, core, s_std, norm); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 311 | static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 312 | struct pci_dev *pci, |
| 313 | struct video_device *template, |
| 314 | char *type) |
| 315 | { |
| 316 | struct video_device *vfd; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 317 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 318 | |
| 319 | vfd = video_device_alloc(); |
| 320 | if (NULL == vfd) |
| 321 | return NULL; |
| 322 | *vfd = *template; |
Hans Verkuil | c0714f6 | 2009-03-13 08:02:43 -0300 | [diff] [blame] | 323 | vfd->v4l2_dev = &dev->v4l2_dev; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 324 | vfd->release = video_device_release; |
| 325 | snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", |
| 326 | dev->name, type, cx23885_boards[dev->board].name); |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 327 | video_set_drvdata(vfd, dev); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 328 | return vfd; |
| 329 | } |
| 330 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 331 | static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 332 | { |
| 333 | int i; |
| 334 | |
| 335 | if (qctrl->id < V4L2_CID_BASE || |
| 336 | qctrl->id >= V4L2_CID_LASTP1) |
| 337 | return -EINVAL; |
| 338 | for (i = 0; i < CX23885_CTLS; i++) |
| 339 | if (cx23885_ctls[i].v.id == qctrl->id) |
| 340 | break; |
| 341 | if (i == CX23885_CTLS) { |
| 342 | *qctrl = no_ctl; |
| 343 | return 0; |
| 344 | } |
| 345 | *qctrl = cx23885_ctls[i].v; |
| 346 | return 0; |
| 347 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 348 | |
| 349 | /* ------------------------------------------------------------------- */ |
| 350 | /* resource management */ |
| 351 | |
| 352 | static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh, |
| 353 | unsigned int bit) |
| 354 | { |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 355 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 356 | if (fh->resources & bit) |
| 357 | /* have it already allocated */ |
| 358 | return 1; |
| 359 | |
| 360 | /* is it free? */ |
| 361 | mutex_lock(&dev->lock); |
| 362 | if (dev->resources & bit) { |
| 363 | /* no, someone else uses it */ |
| 364 | mutex_unlock(&dev->lock); |
| 365 | return 0; |
| 366 | } |
| 367 | /* it's free, grab it */ |
| 368 | fh->resources |= bit; |
| 369 | dev->resources |= bit; |
| 370 | dprintk(1, "res: get %d\n", bit); |
| 371 | mutex_unlock(&dev->lock); |
| 372 | return 1; |
| 373 | } |
| 374 | |
| 375 | static int res_check(struct cx23885_fh *fh, unsigned int bit) |
| 376 | { |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 377 | return fh->resources & bit; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static int res_locked(struct cx23885_dev *dev, unsigned int bit) |
| 381 | { |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 382 | return dev->resources & bit; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh, |
| 386 | unsigned int bits) |
| 387 | { |
| 388 | BUG_ON((fh->resources & bits) != bits); |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 389 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 390 | |
| 391 | mutex_lock(&dev->lock); |
| 392 | fh->resources &= ~bits; |
| 393 | dev->resources &= ~bits; |
| 394 | dprintk(1, "res: put %d\n", bits); |
| 395 | mutex_unlock(&dev->lock); |
| 396 | } |
| 397 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 398 | static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 399 | { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 400 | dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 401 | __func__, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 402 | input, INPUT(input)->vmux, |
| 403 | INPUT(input)->gpio0, INPUT(input)->gpio1, |
| 404 | INPUT(input)->gpio2, INPUT(input)->gpio3); |
| 405 | dev->input = input; |
| 406 | |
David T.L. Wong | 6f0d8c0 | 2009-10-21 13:15:30 -0300 | [diff] [blame] | 407 | if (dev->board == CX23885_BOARD_MYGICA_X8506 || |
| 408 | dev->board == CX23885_BOARD_MAGICPRO_PROHDTVE2) { |
| 409 | /* Select Analog TV */ |
| 410 | if (INPUT(input)->type == CX23885_VMUX_TELEVISION) |
| 411 | cx23885_gpio_clear(dev, GPIO_0); |
| 412 | } |
| 413 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 414 | /* Tell the internal A/V decoder */ |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 415 | v4l2_subdev_call(dev->sd_cx25840, video, s_routing, |
| 416 | INPUT(input)->vmux, 0, 0); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 417 | |
| 418 | return 0; |
| 419 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 420 | |
| 421 | /* ------------------------------------------------------------------ */ |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 422 | static int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 423 | unsigned int height, enum v4l2_field field) |
| 424 | { |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 425 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int cx23885_start_video_dma(struct cx23885_dev *dev, |
| 430 | struct cx23885_dmaqueue *q, |
| 431 | struct cx23885_buffer *buf) |
| 432 | { |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 433 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 434 | |
| 435 | /* setup fifo + format */ |
| 436 | cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01], |
| 437 | buf->bpl, buf->risc.dma); |
| 438 | cx23885_set_scale(dev, buf->vb.width, buf->vb.height, buf->vb.field); |
| 439 | |
| 440 | /* reset counter */ |
| 441 | cx_write(VID_A_GPCNT_CTL, 3); |
| 442 | q->count = 1; |
| 443 | |
| 444 | /* enable irq */ |
Andy Walls | dbe83a3 | 2010-07-19 01:19:43 -0300 | [diff] [blame] | 445 | cx23885_irq_add_enable(dev, 0x01); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 446 | cx_set(VID_A_INT_MSK, 0x000011); |
| 447 | |
| 448 | /* start dma */ |
| 449 | cx_set(DEV_CNTRL2, (1<<5)); |
| 450 | cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */ |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 455 | |
| 456 | static int cx23885_restart_video_queue(struct cx23885_dev *dev, |
| 457 | struct cx23885_dmaqueue *q) |
| 458 | { |
| 459 | struct cx23885_buffer *buf, *prev; |
| 460 | struct list_head *item; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 461 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 462 | |
| 463 | if (!list_empty(&q->active)) { |
| 464 | buf = list_entry(q->active.next, struct cx23885_buffer, |
| 465 | vb.queue); |
| 466 | dprintk(2, "restart_queue [%p/%d]: restart dma\n", |
| 467 | buf, buf->vb.i); |
| 468 | cx23885_start_video_dma(dev, q, buf); |
| 469 | list_for_each(item, &q->active) { |
| 470 | buf = list_entry(item, struct cx23885_buffer, |
| 471 | vb.queue); |
| 472 | buf->count = q->count++; |
| 473 | } |
| 474 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | prev = NULL; |
| 479 | for (;;) { |
| 480 | if (list_empty(&q->queued)) |
| 481 | return 0; |
| 482 | buf = list_entry(q->queued.next, struct cx23885_buffer, |
| 483 | vb.queue); |
| 484 | if (NULL == prev) { |
| 485 | list_move_tail(&buf->vb.queue, &q->active); |
| 486 | cx23885_start_video_dma(dev, q, buf); |
| 487 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 488 | buf->count = q->count++; |
| 489 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 490 | dprintk(2, "[%p/%d] restart_queue - first active\n", |
| 491 | buf, buf->vb.i); |
| 492 | |
| 493 | } else if (prev->vb.width == buf->vb.width && |
| 494 | prev->vb.height == buf->vb.height && |
| 495 | prev->fmt == buf->fmt) { |
| 496 | list_move_tail(&buf->vb.queue, &q->active); |
| 497 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 498 | buf->count = q->count++; |
| 499 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 500 | prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */ |
| 501 | dprintk(2, "[%p/%d] restart_queue - move to active\n", |
| 502 | buf, buf->vb.i); |
| 503 | } else { |
| 504 | return 0; |
| 505 | } |
| 506 | prev = buf; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | static int buffer_setup(struct videobuf_queue *q, unsigned int *count, |
| 511 | unsigned int *size) |
| 512 | { |
| 513 | struct cx23885_fh *fh = q->priv_data; |
| 514 | |
| 515 | *size = fh->fmt->depth*fh->width*fh->height >> 3; |
| 516 | if (0 == *count) |
| 517 | *count = 32; |
Andreas Bombe | dab7e31 | 2010-03-21 16:02:45 -0300 | [diff] [blame] | 518 | if (*size * *count > vid_limit * 1024 * 1024) |
| 519 | *count = (vid_limit * 1024 * 1024) / *size; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
| 524 | enum v4l2_field field) |
| 525 | { |
| 526 | struct cx23885_fh *fh = q->priv_data; |
| 527 | struct cx23885_dev *dev = fh->dev; |
| 528 | struct cx23885_buffer *buf = |
| 529 | container_of(vb, struct cx23885_buffer, vb); |
| 530 | int rc, init_buffer = 0; |
| 531 | u32 line0_offset, line1_offset; |
| 532 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
| 533 | |
| 534 | BUG_ON(NULL == fh->fmt); |
| 535 | if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) || |
| 536 | fh->height < 32 || fh->height > norm_maxh(dev->tvnorm)) |
| 537 | return -EINVAL; |
| 538 | buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; |
| 539 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 540 | return -EINVAL; |
| 541 | |
| 542 | if (buf->fmt != fh->fmt || |
| 543 | buf->vb.width != fh->width || |
| 544 | buf->vb.height != fh->height || |
| 545 | buf->vb.field != field) { |
| 546 | buf->fmt = fh->fmt; |
| 547 | buf->vb.width = fh->width; |
| 548 | buf->vb.height = fh->height; |
| 549 | buf->vb.field = field; |
| 550 | init_buffer = 1; |
| 551 | } |
| 552 | |
| 553 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 554 | init_buffer = 1; |
| 555 | rc = videobuf_iolock(q, &buf->vb, NULL); |
| 556 | if (0 != rc) |
| 557 | goto fail; |
| 558 | } |
| 559 | |
| 560 | if (init_buffer) { |
| 561 | buf->bpl = buf->vb.width * buf->fmt->depth >> 3; |
| 562 | switch (buf->vb.field) { |
| 563 | case V4L2_FIELD_TOP: |
| 564 | cx23885_risc_buffer(dev->pci, &buf->risc, |
| 565 | dma->sglist, 0, UNSET, |
| 566 | buf->bpl, 0, buf->vb.height); |
| 567 | break; |
| 568 | case V4L2_FIELD_BOTTOM: |
| 569 | cx23885_risc_buffer(dev->pci, &buf->risc, |
| 570 | dma->sglist, UNSET, 0, |
| 571 | buf->bpl, 0, buf->vb.height); |
| 572 | break; |
| 573 | case V4L2_FIELD_INTERLACED: |
| 574 | if (dev->tvnorm & V4L2_STD_NTSC) { |
| 575 | /* cx25840 transmits NTSC bottom field first */ |
| 576 | dprintk(1, "%s() Creating NTSC risc\n", |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 577 | __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 578 | line0_offset = buf->bpl; |
| 579 | line1_offset = 0; |
| 580 | } else { |
| 581 | /* All other formats are top field first */ |
| 582 | dprintk(1, "%s() Creating PAL/SECAM risc\n", |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 583 | __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 584 | line0_offset = 0; |
| 585 | line1_offset = buf->bpl; |
| 586 | } |
| 587 | cx23885_risc_buffer(dev->pci, &buf->risc, |
| 588 | dma->sglist, line0_offset, |
| 589 | line1_offset, |
| 590 | buf->bpl, buf->bpl, |
| 591 | buf->vb.height >> 1); |
| 592 | break; |
| 593 | case V4L2_FIELD_SEQ_TB: |
| 594 | cx23885_risc_buffer(dev->pci, &buf->risc, |
| 595 | dma->sglist, |
| 596 | 0, buf->bpl * (buf->vb.height >> 1), |
| 597 | buf->bpl, 0, |
| 598 | buf->vb.height >> 1); |
| 599 | break; |
| 600 | case V4L2_FIELD_SEQ_BT: |
| 601 | cx23885_risc_buffer(dev->pci, &buf->risc, |
| 602 | dma->sglist, |
| 603 | buf->bpl * (buf->vb.height >> 1), 0, |
| 604 | buf->bpl, 0, |
| 605 | buf->vb.height >> 1); |
| 606 | break; |
| 607 | default: |
| 608 | BUG(); |
| 609 | } |
| 610 | } |
| 611 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
| 612 | buf, buf->vb.i, |
| 613 | fh->width, fh->height, fh->fmt->depth, fh->fmt->name, |
| 614 | (unsigned long)buf->risc.dma); |
| 615 | |
| 616 | buf->vb.state = VIDEOBUF_PREPARED; |
| 617 | return 0; |
| 618 | |
| 619 | fail: |
| 620 | cx23885_free_buffer(q, buf); |
| 621 | return rc; |
| 622 | } |
| 623 | |
| 624 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 625 | { |
| 626 | struct cx23885_buffer *buf = container_of(vb, |
| 627 | struct cx23885_buffer, vb); |
| 628 | struct cx23885_buffer *prev; |
| 629 | struct cx23885_fh *fh = vq->priv_data; |
| 630 | struct cx23885_dev *dev = fh->dev; |
| 631 | struct cx23885_dmaqueue *q = &dev->vidq; |
| 632 | |
| 633 | /* add jump to stopper */ |
| 634 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 635 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 636 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
| 637 | |
| 638 | if (!list_empty(&q->queued)) { |
| 639 | list_add_tail(&buf->vb.queue, &q->queued); |
| 640 | buf->vb.state = VIDEOBUF_QUEUED; |
| 641 | dprintk(2, "[%p/%d] buffer_queue - append to queued\n", |
| 642 | buf, buf->vb.i); |
| 643 | |
| 644 | } else if (list_empty(&q->active)) { |
| 645 | list_add_tail(&buf->vb.queue, &q->active); |
| 646 | cx23885_start_video_dma(dev, q, buf); |
| 647 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 648 | buf->count = q->count++; |
| 649 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 650 | dprintk(2, "[%p/%d] buffer_queue - first active\n", |
| 651 | buf, buf->vb.i); |
| 652 | |
| 653 | } else { |
| 654 | prev = list_entry(q->active.prev, struct cx23885_buffer, |
| 655 | vb.queue); |
| 656 | if (prev->vb.width == buf->vb.width && |
| 657 | prev->vb.height == buf->vb.height && |
| 658 | prev->fmt == buf->fmt) { |
| 659 | list_add_tail(&buf->vb.queue, &q->active); |
| 660 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 661 | buf->count = q->count++; |
| 662 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 663 | /* 64 bit bits 63-32 */ |
| 664 | prev->risc.jmp[2] = cpu_to_le32(0); |
| 665 | dprintk(2, "[%p/%d] buffer_queue - append to active\n", |
| 666 | buf, buf->vb.i); |
| 667 | |
| 668 | } else { |
| 669 | list_add_tail(&buf->vb.queue, &q->queued); |
| 670 | buf->vb.state = VIDEOBUF_QUEUED; |
| 671 | dprintk(2, "[%p/%d] buffer_queue - first queued\n", |
| 672 | buf, buf->vb.i); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | static void buffer_release(struct videobuf_queue *q, |
| 678 | struct videobuf_buffer *vb) |
| 679 | { |
| 680 | struct cx23885_buffer *buf = container_of(vb, |
| 681 | struct cx23885_buffer, vb); |
| 682 | |
| 683 | cx23885_free_buffer(q, buf); |
| 684 | } |
| 685 | |
| 686 | static struct videobuf_queue_ops cx23885_video_qops = { |
| 687 | .buf_setup = buffer_setup, |
| 688 | .buf_prepare = buffer_prepare, |
| 689 | .buf_queue = buffer_queue, |
| 690 | .buf_release = buffer_release, |
| 691 | }; |
| 692 | |
| 693 | static struct videobuf_queue *get_queue(struct cx23885_fh *fh) |
| 694 | { |
| 695 | switch (fh->type) { |
| 696 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 697 | return &fh->vidq; |
| 698 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 699 | return &fh->vbiq; |
| 700 | default: |
| 701 | BUG(); |
| 702 | return NULL; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | static int get_resource(struct cx23885_fh *fh) |
| 707 | { |
| 708 | switch (fh->type) { |
| 709 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 710 | return RESOURCE_VIDEO; |
| 711 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 712 | return RESOURCE_VBI; |
| 713 | default: |
| 714 | BUG(); |
| 715 | return 0; |
| 716 | } |
| 717 | } |
| 718 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 719 | static int video_open(struct file *file) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 720 | { |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 721 | struct video_device *vdev = video_devdata(file); |
| 722 | struct cx23885_dev *dev = video_drvdata(file); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 723 | struct cx23885_fh *fh; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 724 | enum v4l2_buf_type type = 0; |
| 725 | int radio = 0; |
| 726 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 727 | switch (vdev->vfl_type) { |
| 728 | case VFL_TYPE_GRABBER: |
| 729 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 730 | break; |
| 731 | case VFL_TYPE_VBI: |
| 732 | type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 733 | break; |
| 734 | case VFL_TYPE_RADIO: |
| 735 | radio = 1; |
| 736 | break; |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 737 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 738 | |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 739 | dprintk(1, "open dev=%s radio=%d type=%s\n", |
| 740 | video_device_node_name(vdev), radio, v4l2_type_names[type]); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 741 | |
| 742 | /* allocate + initialize per filehandle data */ |
| 743 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 744 | if (NULL == fh) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 745 | return -ENOMEM; |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 746 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 747 | file->private_data = fh; |
| 748 | fh->dev = dev; |
| 749 | fh->radio = radio; |
| 750 | fh->type = type; |
| 751 | fh->width = 320; |
| 752 | fh->height = 240; |
| 753 | fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); |
| 754 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 755 | videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops, |
| 756 | &dev->pci->dev, &dev->slock, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 757 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 758 | V4L2_FIELD_INTERLACED, |
| 759 | sizeof(struct cx23885_buffer), |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 760 | fh, NULL); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 761 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 762 | videobuf_queue_sg_init(&fh->vbiq, &cx23885_vbi_qops, |
| 763 | &dev->pci->dev, &dev->slock, |
| 764 | V4L2_BUF_TYPE_VBI_CAPTURE, |
| 765 | V4L2_FIELD_SEQ_TB, |
| 766 | sizeof(struct cx23885_buffer), |
| 767 | fh, NULL); |
| 768 | |
| 769 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 770 | dprintk(1, "post videobuf_queue_init()\n"); |
| 771 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static ssize_t video_read(struct file *file, char __user *data, |
| 776 | size_t count, loff_t *ppos) |
| 777 | { |
| 778 | struct cx23885_fh *fh = file->private_data; |
| 779 | |
| 780 | switch (fh->type) { |
| 781 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 782 | if (res_locked(fh->dev, RESOURCE_VIDEO)) |
| 783 | return -EBUSY; |
| 784 | return videobuf_read_one(&fh->vidq, data, count, ppos, |
| 785 | file->f_flags & O_NONBLOCK); |
| 786 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 787 | if (!res_get(fh->dev, fh, RESOURCE_VBI)) |
| 788 | return -EBUSY; |
| 789 | return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1, |
| 790 | file->f_flags & O_NONBLOCK); |
| 791 | default: |
| 792 | BUG(); |
| 793 | return 0; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | static unsigned int video_poll(struct file *file, |
| 798 | struct poll_table_struct *wait) |
| 799 | { |
| 800 | struct cx23885_fh *fh = file->private_data; |
| 801 | struct cx23885_buffer *buf; |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 802 | unsigned int rc = POLLERR; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 803 | |
| 804 | if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { |
| 805 | if (!res_get(fh->dev, fh, RESOURCE_VBI)) |
| 806 | return POLLERR; |
| 807 | return videobuf_poll_stream(file, &fh->vbiq, wait); |
| 808 | } |
| 809 | |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 810 | mutex_lock(&fh->vidq.vb_lock); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 811 | if (res_check(fh, RESOURCE_VIDEO)) { |
| 812 | /* streaming capture */ |
| 813 | if (list_empty(&fh->vidq.stream)) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 814 | goto done; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 815 | buf = list_entry(fh->vidq.stream.next, |
| 816 | struct cx23885_buffer, vb.stream); |
| 817 | } else { |
| 818 | /* read() capture */ |
| 819 | buf = (struct cx23885_buffer *)fh->vidq.read_buf; |
| 820 | if (NULL == buf) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 821 | goto done; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 822 | } |
| 823 | poll_wait(file, &buf->vb.done, wait); |
| 824 | if (buf->vb.state == VIDEOBUF_DONE || |
| 825 | buf->vb.state == VIDEOBUF_ERROR) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 826 | rc = POLLIN|POLLRDNORM; |
| 827 | else |
| 828 | rc = 0; |
| 829 | done: |
| 830 | mutex_unlock(&fh->vidq.vb_lock); |
| 831 | return rc; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 832 | } |
| 833 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 834 | static int video_release(struct file *file) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 835 | { |
| 836 | struct cx23885_fh *fh = file->private_data; |
| 837 | struct cx23885_dev *dev = fh->dev; |
| 838 | |
| 839 | /* turn off overlay */ |
| 840 | if (res_check(fh, RESOURCE_OVERLAY)) { |
| 841 | /* FIXME */ |
| 842 | res_free(dev, fh, RESOURCE_OVERLAY); |
| 843 | } |
| 844 | |
| 845 | /* stop video capture */ |
| 846 | if (res_check(fh, RESOURCE_VIDEO)) { |
| 847 | videobuf_queue_cancel(&fh->vidq); |
| 848 | res_free(dev, fh, RESOURCE_VIDEO); |
| 849 | } |
| 850 | if (fh->vidq.read_buf) { |
| 851 | buffer_release(&fh->vidq, fh->vidq.read_buf); |
| 852 | kfree(fh->vidq.read_buf); |
| 853 | } |
| 854 | |
| 855 | /* stop vbi capture */ |
| 856 | if (res_check(fh, RESOURCE_VBI)) { |
| 857 | if (fh->vbiq.streaming) |
| 858 | videobuf_streamoff(&fh->vbiq); |
| 859 | if (fh->vbiq.reading) |
| 860 | videobuf_read_stop(&fh->vbiq); |
| 861 | res_free(dev, fh, RESOURCE_VBI); |
| 862 | } |
| 863 | |
| 864 | videobuf_mmap_free(&fh->vidq); |
| 865 | file->private_data = NULL; |
| 866 | kfree(fh); |
| 867 | |
Steven Toth | a19602f2 | 2008-01-10 11:43:18 -0300 | [diff] [blame] | 868 | /* We are not putting the tuner to sleep here on exit, because |
| 869 | * we want to use the mpeg encoder in another session to capture |
| 870 | * tuner video. Closing this will result in no video to the encoder. |
| 871 | */ |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | static int video_mmap(struct file *file, struct vm_area_struct *vma) |
| 877 | { |
| 878 | struct cx23885_fh *fh = file->private_data; |
| 879 | |
| 880 | return videobuf_mmap_mapper(get_queue(fh), vma); |
| 881 | } |
| 882 | |
| 883 | /* ------------------------------------------------------------------ */ |
| 884 | /* VIDEO CTRL IOCTLS */ |
| 885 | |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 886 | static int cx23885_get_control(struct cx23885_dev *dev, |
| 887 | struct v4l2_control *ctl) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 888 | { |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 889 | dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__); |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 890 | call_all(dev, core, g_ctrl, ctl); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 891 | return 0; |
| 892 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 893 | |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 894 | static int cx23885_set_control(struct cx23885_dev *dev, |
| 895 | struct v4l2_control *ctl) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 896 | { |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 897 | dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)\n", __func__); |
| 898 | call_all(dev, core, s_ctrl, ctl); |
| 899 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 900 | return 0; |
| 901 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 902 | |
| 903 | static void init_controls(struct cx23885_dev *dev) |
| 904 | { |
| 905 | struct v4l2_control ctrl; |
| 906 | int i; |
| 907 | |
| 908 | for (i = 0; i < CX23885_CTLS; i++) { |
| 909 | ctrl.id = cx23885_ctls[i].v.id; |
| 910 | ctrl.value = cx23885_ctls[i].v.default_value; |
| 911 | |
| 912 | cx23885_set_control(dev, &ctrl); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /* ------------------------------------------------------------------ */ |
| 917 | /* VIDEO IOCTLS */ |
| 918 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 919 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 920 | struct v4l2_format *f) |
| 921 | { |
| 922 | struct cx23885_fh *fh = priv; |
| 923 | |
| 924 | f->fmt.pix.width = fh->width; |
| 925 | f->fmt.pix.height = fh->height; |
| 926 | f->fmt.pix.field = fh->vidq.field; |
| 927 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 928 | f->fmt.pix.bytesperline = |
| 929 | (f->fmt.pix.width * fh->fmt->depth) >> 3; |
| 930 | f->fmt.pix.sizeimage = |
| 931 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 936 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 937 | struct v4l2_format *f) |
| 938 | { |
| 939 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 940 | struct cx23885_fmt *fmt; |
| 941 | enum v4l2_field field; |
| 942 | unsigned int maxw, maxh; |
| 943 | |
| 944 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 945 | if (NULL == fmt) |
| 946 | return -EINVAL; |
| 947 | |
| 948 | field = f->fmt.pix.field; |
| 949 | maxw = norm_maxw(dev->tvnorm); |
| 950 | maxh = norm_maxh(dev->tvnorm); |
| 951 | |
| 952 | if (V4L2_FIELD_ANY == field) { |
| 953 | field = (f->fmt.pix.height > maxh/2) |
| 954 | ? V4L2_FIELD_INTERLACED |
| 955 | : V4L2_FIELD_BOTTOM; |
| 956 | } |
| 957 | |
| 958 | switch (field) { |
| 959 | case V4L2_FIELD_TOP: |
| 960 | case V4L2_FIELD_BOTTOM: |
| 961 | maxh = maxh / 2; |
| 962 | break; |
| 963 | case V4L2_FIELD_INTERLACED: |
| 964 | break; |
| 965 | default: |
| 966 | return -EINVAL; |
| 967 | } |
| 968 | |
| 969 | f->fmt.pix.field = field; |
Trent Piepho | 2449afc | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 970 | v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2, |
| 971 | &f->fmt.pix.height, 32, maxh, 0, 0); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 972 | f->fmt.pix.bytesperline = |
| 973 | (f->fmt.pix.width * fmt->depth) >> 3; |
| 974 | f->fmt.pix.sizeimage = |
| 975 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 980 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 981 | struct v4l2_format *f) |
| 982 | { |
| 983 | struct cx23885_fh *fh = priv; |
| 984 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
Hans Verkuil | cc99113 | 2010-05-09 10:09:28 -0300 | [diff] [blame] | 985 | struct v4l2_mbus_framefmt mbus_fmt; |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 986 | int err; |
| 987 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 988 | dprintk(2, "%s()\n", __func__); |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 989 | err = vidioc_try_fmt_vid_cap(file, priv, f); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 990 | |
| 991 | if (0 != err) |
| 992 | return err; |
| 993 | fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 994 | fh->width = f->fmt.pix.width; |
| 995 | fh->height = f->fmt.pix.height; |
| 996 | fh->vidq.field = f->fmt.pix.field; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 997 | dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 998 | fh->width, fh->height, fh->vidq.field); |
Hans Verkuil | cc99113 | 2010-05-09 10:09:28 -0300 | [diff] [blame] | 999 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 1000 | call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
| 1001 | v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | static int vidioc_querycap(struct file *file, void *priv, |
| 1006 | struct v4l2_capability *cap) |
| 1007 | { |
| 1008 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1009 | |
| 1010 | strcpy(cap->driver, "cx23885"); |
| 1011 | strlcpy(cap->card, cx23885_boards[dev->board].name, |
| 1012 | sizeof(cap->card)); |
| 1013 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1014 | cap->capabilities = |
| 1015 | V4L2_CAP_VIDEO_CAPTURE | |
| 1016 | V4L2_CAP_READWRITE | |
| 1017 | V4L2_CAP_STREAMING | |
| 1018 | V4L2_CAP_VBI_CAPTURE; |
| 1019 | if (UNSET != dev->tuner_type) |
| 1020 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1024 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1025 | struct v4l2_fmtdesc *f) |
| 1026 | { |
| 1027 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 1028 | return -EINVAL; |
| 1029 | |
| 1030 | strlcpy(f->description, formats[f->index].name, |
| 1031 | sizeof(f->description)); |
| 1032 | f->pixelformat = formats[f->index].fourcc; |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1037 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1038 | struct v4l2_requestbuffers *p) |
| 1039 | { |
| 1040 | struct cx23885_fh *fh = priv; |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 1041 | return videobuf_reqbufs(get_queue(fh), p); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1045 | struct v4l2_buffer *p) |
| 1046 | { |
| 1047 | struct cx23885_fh *fh = priv; |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 1048 | return videobuf_querybuf(get_queue(fh), p); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static int vidioc_qbuf(struct file *file, void *priv, |
| 1052 | struct v4l2_buffer *p) |
| 1053 | { |
| 1054 | struct cx23885_fh *fh = priv; |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 1055 | return videobuf_qbuf(get_queue(fh), p); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static int vidioc_dqbuf(struct file *file, void *priv, |
| 1059 | struct v4l2_buffer *p) |
| 1060 | { |
| 1061 | struct cx23885_fh *fh = priv; |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 1062 | return videobuf_dqbuf(get_queue(fh), p, |
| 1063 | file->f_flags & O_NONBLOCK); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | static int vidioc_streamon(struct file *file, void *priv, |
| 1067 | enum v4l2_buf_type i) |
| 1068 | { |
| 1069 | struct cx23885_fh *fh = priv; |
| 1070 | struct cx23885_dev *dev = fh->dev; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1071 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1072 | |
Steven Toth | 5ab27e6 | 2011-10-10 11:09:54 -0300 | [diff] [blame^] | 1073 | if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && |
| 1074 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1075 | return -EINVAL; |
| 1076 | if (unlikely(i != fh->type)) |
| 1077 | return -EINVAL; |
| 1078 | |
| 1079 | if (unlikely(!res_get(dev, fh, get_resource(fh)))) |
| 1080 | return -EBUSY; |
| 1081 | return videobuf_streamon(get_queue(fh)); |
| 1082 | } |
| 1083 | |
| 1084 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 1085 | { |
| 1086 | struct cx23885_fh *fh = priv; |
| 1087 | struct cx23885_dev *dev = fh->dev; |
| 1088 | int err, res; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1089 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1090 | |
Steven Toth | 5ab27e6 | 2011-10-10 11:09:54 -0300 | [diff] [blame^] | 1091 | if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && |
| 1092 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1093 | return -EINVAL; |
| 1094 | if (i != fh->type) |
| 1095 | return -EINVAL; |
| 1096 | |
| 1097 | res = get_resource(fh); |
| 1098 | err = videobuf_streamoff(get_queue(fh)); |
| 1099 | if (err < 0) |
| 1100 | return err; |
| 1101 | res_free(dev, fh, res); |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
| 1105 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms) |
| 1106 | { |
| 1107 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1108 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1109 | |
| 1110 | mutex_lock(&dev->lock); |
| 1111 | cx23885_set_tvnorm(dev, *tvnorms); |
| 1112 | mutex_unlock(&dev->lock); |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 1117 | static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1118 | { |
| 1119 | static const char *iname[] = { |
| 1120 | [CX23885_VMUX_COMPOSITE1] = "Composite1", |
| 1121 | [CX23885_VMUX_COMPOSITE2] = "Composite2", |
| 1122 | [CX23885_VMUX_COMPOSITE3] = "Composite3", |
| 1123 | [CX23885_VMUX_COMPOSITE4] = "Composite4", |
| 1124 | [CX23885_VMUX_SVIDEO] = "S-Video", |
David T.L. Wong | dac65fa | 2009-10-21 11:07:24 -0300 | [diff] [blame] | 1125 | [CX23885_VMUX_COMPONENT] = "Component", |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1126 | [CX23885_VMUX_TELEVISION] = "Television", |
| 1127 | [CX23885_VMUX_CABLE] = "Cable TV", |
| 1128 | [CX23885_VMUX_DVB] = "DVB", |
| 1129 | [CX23885_VMUX_DEBUG] = "for debug only", |
| 1130 | }; |
| 1131 | unsigned int n; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1132 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1133 | |
| 1134 | n = i->index; |
| 1135 | if (n >= 4) |
| 1136 | return -EINVAL; |
| 1137 | |
| 1138 | if (0 == INPUT(n)->type) |
| 1139 | return -EINVAL; |
| 1140 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1141 | i->index = n; |
| 1142 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1143 | strcpy(i->name, iname[INPUT(n)->type]); |
| 1144 | if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) || |
Julia Lawall | 473d802 | 2010-08-05 17:22:44 -0300 | [diff] [blame] | 1145 | (CX23885_VMUX_CABLE == INPUT(n)->type)) { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1146 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1147 | i->std = CX23885_NORMS; |
Julia Lawall | 473d802 | 2010-08-05 17:22:44 -0300 | [diff] [blame] | 1148 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1149 | return 0; |
| 1150 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1151 | |
| 1152 | static int vidioc_enum_input(struct file *file, void *priv, |
| 1153 | struct v4l2_input *i) |
| 1154 | { |
| 1155 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1156 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1157 | return cx23885_enum_input(dev, i); |
| 1158 | } |
| 1159 | |
| 1160 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1161 | { |
| 1162 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1163 | |
| 1164 | *i = dev->input; |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1165 | dprintk(1, "%s() returns %d\n", __func__, *i); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 1170 | { |
| 1171 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1172 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1173 | dprintk(1, "%s(%d)\n", __func__, i); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1174 | |
| 1175 | if (i >= 4) { |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1176 | dprintk(1, "%s() -EINVAL\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1177 | return -EINVAL; |
| 1178 | } |
| 1179 | |
| 1180 | mutex_lock(&dev->lock); |
| 1181 | cx23885_video_mux(dev, i); |
| 1182 | mutex_unlock(&dev->lock); |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
Andy Walls | e9e5cf4 | 2010-07-18 18:18:06 -0300 | [diff] [blame] | 1186 | static int vidioc_log_status(struct file *file, void *priv) |
| 1187 | { |
| 1188 | struct cx23885_fh *fh = priv; |
| 1189 | struct cx23885_dev *dev = fh->dev; |
| 1190 | |
| 1191 | printk(KERN_INFO |
| 1192 | "%s/0: ============ START LOG STATUS ============\n", |
| 1193 | dev->name); |
| 1194 | call_all(dev, core, log_status); |
| 1195 | printk(KERN_INFO |
| 1196 | "%s/0: ============= END LOG STATUS =============\n", |
| 1197 | dev->name); |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1201 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 1202 | struct v4l2_queryctrl *qctrl) |
| 1203 | { |
| 1204 | qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id); |
| 1205 | if (unlikely(qctrl->id == 0)) |
| 1206 | return -EINVAL; |
| 1207 | return cx23885_ctrl_query(qctrl); |
| 1208 | } |
| 1209 | |
| 1210 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1211 | struct v4l2_control *ctl) |
| 1212 | { |
| 1213 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1214 | |
| 1215 | return cx23885_get_control(dev, ctl); |
| 1216 | } |
| 1217 | |
| 1218 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1219 | struct v4l2_control *ctl) |
| 1220 | { |
| 1221 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1222 | |
| 1223 | return cx23885_set_control(dev, ctl); |
| 1224 | } |
| 1225 | |
| 1226 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 1227 | struct v4l2_tuner *t) |
| 1228 | { |
| 1229 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1230 | |
| 1231 | if (unlikely(UNSET == dev->tuner_type)) |
| 1232 | return -EINVAL; |
| 1233 | if (0 != t->index) |
| 1234 | return -EINVAL; |
| 1235 | |
| 1236 | strcpy(t->name, "Television"); |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1237 | |
Steven Toth | 80f1e08 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1238 | call_all(dev, tuner, g_tuner, t); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 1243 | struct v4l2_tuner *t) |
| 1244 | { |
| 1245 | struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; |
| 1246 | |
| 1247 | if (UNSET == dev->tuner_type) |
| 1248 | return -EINVAL; |
| 1249 | if (0 != t->index) |
| 1250 | return -EINVAL; |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1251 | /* Update the A/V core */ |
Steven Toth | 80f1e08 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1252 | call_all(dev, tuner, s_tuner, t); |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1253 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 1258 | struct v4l2_frequency *f) |
| 1259 | { |
| 1260 | struct cx23885_fh *fh = priv; |
| 1261 | struct cx23885_dev *dev = fh->dev; |
| 1262 | |
| 1263 | if (unlikely(UNSET == dev->tuner_type)) |
| 1264 | return -EINVAL; |
| 1265 | |
| 1266 | /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */ |
| 1267 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1268 | f->frequency = dev->freq; |
| 1269 | |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1270 | call_all(dev, tuner, g_frequency, f); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1271 | |
| 1272 | return 0; |
| 1273 | } |
| 1274 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 1275 | static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1276 | { |
| 1277 | if (unlikely(UNSET == dev->tuner_type)) |
| 1278 | return -EINVAL; |
| 1279 | if (unlikely(f->tuner != 0)) |
| 1280 | return -EINVAL; |
| 1281 | |
| 1282 | mutex_lock(&dev->lock); |
| 1283 | dev->freq = f->frequency; |
| 1284 | |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1285 | call_all(dev, tuner, s_frequency, f); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1286 | |
| 1287 | /* When changing channels it is required to reset TVAUDIO */ |
| 1288 | msleep(10); |
| 1289 | |
| 1290 | mutex_unlock(&dev->lock); |
| 1291 | |
| 1292 | return 0; |
| 1293 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1294 | |
| 1295 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 1296 | struct v4l2_frequency *f) |
| 1297 | { |
| 1298 | struct cx23885_fh *fh = priv; |
| 1299 | struct cx23885_dev *dev = fh->dev; |
| 1300 | |
| 1301 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1302 | return -EINVAL; |
| 1303 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
| 1304 | return -EINVAL; |
| 1305 | |
| 1306 | return |
| 1307 | cx23885_set_freq(dev, f); |
| 1308 | } |
| 1309 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1310 | /* ----------------------------------------------------------- */ |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1311 | |
| 1312 | static void cx23885_vid_timeout(unsigned long data) |
| 1313 | { |
| 1314 | struct cx23885_dev *dev = (struct cx23885_dev *)data; |
| 1315 | struct cx23885_dmaqueue *q = &dev->vidq; |
| 1316 | struct cx23885_buffer *buf; |
| 1317 | unsigned long flags; |
| 1318 | |
| 1319 | cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]); |
| 1320 | |
| 1321 | cx_clear(VID_A_DMA_CTL, 0x11); |
| 1322 | |
| 1323 | spin_lock_irqsave(&dev->slock, flags); |
| 1324 | while (!list_empty(&q->active)) { |
| 1325 | buf = list_entry(q->active.next, |
| 1326 | struct cx23885_buffer, vb.queue); |
| 1327 | list_del(&buf->vb.queue); |
| 1328 | buf->vb.state = VIDEOBUF_ERROR; |
| 1329 | wake_up(&buf->vb.done); |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1330 | printk(KERN_ERR "%s: [%p/%d] timeout - dma=0x%08lx\n", |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1331 | dev->name, buf, buf->vb.i, |
| 1332 | (unsigned long)buf->risc.dma); |
| 1333 | } |
| 1334 | cx23885_restart_video_queue(dev, q); |
| 1335 | spin_unlock_irqrestore(&dev->slock, flags); |
| 1336 | } |
| 1337 | |
| 1338 | int cx23885_video_irq(struct cx23885_dev *dev, u32 status) |
| 1339 | { |
| 1340 | u32 mask, count; |
| 1341 | int handled = 0; |
| 1342 | |
| 1343 | mask = cx_read(VID_A_INT_MSK); |
| 1344 | if (0 == (status & mask)) |
| 1345 | return handled; |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1346 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1347 | cx_write(VID_A_INT_STAT, status); |
| 1348 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1349 | /* risc op code error */ |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1350 | if ((status & VID_BC_MSK_OPC_ERR) || |
| 1351 | (status & VID_BC_MSK_SYNC) || |
| 1352 | (status & VID_BC_MSK_OF)) { |
| 1353 | |
| 1354 | if (status & VID_BC_MSK_OPC_ERR) |
| 1355 | dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n", |
| 1356 | VID_BC_MSK_OPC_ERR); |
| 1357 | |
| 1358 | if (status & VID_BC_MSK_SYNC) |
| 1359 | dprintk(7, " (VID_BC_MSK_SYNC 0x%08x)\n", |
| 1360 | VID_BC_MSK_SYNC); |
| 1361 | |
| 1362 | if (status & VID_BC_MSK_OF) |
| 1363 | dprintk(7, " (VID_BC_MSK_OF 0x%08x)\n", |
| 1364 | VID_BC_MSK_OF); |
| 1365 | |
| 1366 | printk(KERN_WARNING "%s: video risc op code error\n", |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1367 | dev->name); |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1368 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1369 | cx_clear(VID_A_DMA_CTL, 0x11); |
| 1370 | cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]); |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1371 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1372 | } |
| 1373 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1374 | /* Video */ |
| 1375 | if (status & VID_BC_MSK_RISCI1) { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1376 | spin_lock(&dev->slock); |
| 1377 | count = cx_read(VID_A_GPCNT); |
| 1378 | cx23885_video_wakeup(dev, &dev->vidq, count); |
| 1379 | spin_unlock(&dev->slock); |
| 1380 | handled++; |
| 1381 | } |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1382 | if (status & VID_BC_MSK_RISCI2) { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1383 | dprintk(2, "stopper video\n"); |
| 1384 | spin_lock(&dev->slock); |
| 1385 | cx23885_restart_video_queue(dev, &dev->vidq); |
| 1386 | spin_unlock(&dev->slock); |
| 1387 | handled++; |
| 1388 | } |
| 1389 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1390 | /* Allow the VBI framework to process it's payload */ |
| 1391 | handled += cx23885_vbi_irq(dev, status); |
| 1392 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1393 | return handled; |
| 1394 | } |
| 1395 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1396 | /* ----------------------------------------------------------- */ |
| 1397 | /* exported stuff */ |
| 1398 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1399 | static const struct v4l2_file_operations video_fops = { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1400 | .owner = THIS_MODULE, |
| 1401 | .open = video_open, |
| 1402 | .release = video_release, |
| 1403 | .read = video_read, |
| 1404 | .poll = video_poll, |
| 1405 | .mmap = video_mmap, |
| 1406 | .ioctl = video_ioctl2, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1407 | }; |
| 1408 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1409 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1410 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1411 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1412 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1413 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1414 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 1415 | .vidioc_g_fmt_vbi_cap = cx23885_vbi_fmt, |
| 1416 | .vidioc_try_fmt_vbi_cap = cx23885_vbi_fmt, |
| 1417 | .vidioc_s_fmt_vbi_cap = cx23885_vbi_fmt, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1418 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1419 | .vidioc_querybuf = vidioc_querybuf, |
| 1420 | .vidioc_qbuf = vidioc_qbuf, |
| 1421 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1422 | .vidioc_s_std = vidioc_s_std, |
| 1423 | .vidioc_enum_input = vidioc_enum_input, |
| 1424 | .vidioc_g_input = vidioc_g_input, |
| 1425 | .vidioc_s_input = vidioc_s_input, |
Andy Walls | e9e5cf4 | 2010-07-18 18:18:06 -0300 | [diff] [blame] | 1426 | .vidioc_log_status = vidioc_log_status, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1427 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1428 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1429 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1430 | .vidioc_streamon = vidioc_streamon, |
| 1431 | .vidioc_streamoff = vidioc_streamoff, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1432 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1433 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1434 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1435 | .vidioc_s_frequency = vidioc_s_frequency, |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 1436 | .vidioc_g_chip_ident = cx23885_g_chip_ident, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1437 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 1438 | .vidioc_g_register = cx23885_g_register, |
| 1439 | .vidioc_s_register = cx23885_s_register, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1440 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1441 | }; |
| 1442 | |
| 1443 | static struct video_device cx23885_vbi_template; |
| 1444 | static struct video_device cx23885_video_template = { |
| 1445 | .name = "cx23885-video", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1446 | .fops = &video_fops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1447 | .ioctl_ops = &video_ioctl_ops, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1448 | .tvnorms = CX23885_NORMS, |
| 1449 | .current_norm = V4L2_STD_NTSC_M, |
| 1450 | }; |
| 1451 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1452 | static const struct v4l2_file_operations radio_fops = { |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1453 | .owner = THIS_MODULE, |
| 1454 | .open = video_open, |
| 1455 | .release = video_release, |
| 1456 | .ioctl = video_ioctl2, |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1457 | }; |
| 1458 | |
| 1459 | |
| 1460 | void cx23885_video_unregister(struct cx23885_dev *dev) |
| 1461 | { |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1462 | dprintk(1, "%s()\n", __func__); |
Andy Walls | dbe83a3 | 2010-07-19 01:19:43 -0300 | [diff] [blame] | 1463 | cx23885_irq_remove(dev, 0x01); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1464 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1465 | if (dev->vbi_dev) { |
| 1466 | if (video_is_registered(dev->vbi_dev)) |
| 1467 | video_unregister_device(dev->vbi_dev); |
| 1468 | else |
| 1469 | video_device_release(dev->vbi_dev); |
| 1470 | dev->vbi_dev = NULL; |
| 1471 | btcx_riscmem_free(dev->pci, &dev->vbiq.stopper); |
| 1472 | } |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1473 | if (dev->video_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 1474 | if (video_is_registered(dev->video_dev)) |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1475 | video_unregister_device(dev->video_dev); |
| 1476 | else |
| 1477 | video_device_release(dev->video_dev); |
| 1478 | dev->video_dev = NULL; |
| 1479 | |
| 1480 | btcx_riscmem_free(dev->pci, &dev->vidq.stopper); |
| 1481 | } |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1482 | |
| 1483 | if (dev->audio_dev) |
Steven Toth | efa762f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1484 | cx23885_audio_unregister(dev); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | int cx23885_video_register(struct cx23885_dev *dev) |
| 1488 | { |
| 1489 | int err; |
| 1490 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1491 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1492 | spin_lock_init(&dev->slock); |
| 1493 | |
| 1494 | /* Initialize VBI template */ |
| 1495 | memcpy(&cx23885_vbi_template, &cx23885_video_template, |
| 1496 | sizeof(cx23885_vbi_template)); |
| 1497 | strcpy(cx23885_vbi_template.name, "cx23885-vbi"); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1498 | |
| 1499 | dev->tvnorm = cx23885_video_template.current_norm; |
| 1500 | |
| 1501 | /* init video dma queues */ |
| 1502 | INIT_LIST_HEAD(&dev->vidq.active); |
| 1503 | INIT_LIST_HEAD(&dev->vidq.queued); |
| 1504 | dev->vidq.timeout.function = cx23885_vid_timeout; |
| 1505 | dev->vidq.timeout.data = (unsigned long)dev; |
| 1506 | init_timer(&dev->vidq.timeout); |
| 1507 | cx23885_risc_stopper(dev->pci, &dev->vidq.stopper, |
| 1508 | VID_A_DMA_CTL, 0x11, 0x00); |
| 1509 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1510 | /* init vbi dma queues */ |
| 1511 | INIT_LIST_HEAD(&dev->vbiq.active); |
| 1512 | INIT_LIST_HEAD(&dev->vbiq.queued); |
| 1513 | dev->vbiq.timeout.function = cx23885_vbi_timeout; |
| 1514 | dev->vbiq.timeout.data = (unsigned long)dev; |
| 1515 | init_timer(&dev->vbiq.timeout); |
| 1516 | cx23885_risc_stopper(dev->pci, &dev->vbiq.stopper, |
| 1517 | VID_A_DMA_CTL, 0x22, 0x00); |
Andy Walls | dbe83a3 | 2010-07-19 01:19:43 -0300 | [diff] [blame] | 1518 | |
| 1519 | cx23885_irq_add_enable(dev, 0x01); |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1520 | |
Igor M. Liplianin | 557f48d | 2011-01-25 17:05:00 -0300 | [diff] [blame] | 1521 | if ((TUNER_ABSENT != dev->tuner_type) && |
| 1522 | ((dev->tuner_bus == 0) || (dev->tuner_bus == 1))) { |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1523 | struct v4l2_subdev *sd = NULL; |
| 1524 | |
| 1525 | if (dev->tuner_addr) |
Hans Verkuil | e6574f2 | 2009-04-01 03:57:53 -0300 | [diff] [blame] | 1526 | sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, |
Igor M. Liplianin | 557f48d | 2011-01-25 17:05:00 -0300 | [diff] [blame] | 1527 | &dev->i2c_bus[dev->tuner_bus].i2c_adap, |
Laurent Pinchart | 9a1f8b3 | 2010-09-24 10:16:44 -0300 | [diff] [blame] | 1528 | "tuner", dev->tuner_addr, NULL); |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1529 | else |
Hans Verkuil | 53dacb1 | 2009-08-10 02:49:08 -0300 | [diff] [blame] | 1530 | sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, |
Igor M. Liplianin | 557f48d | 2011-01-25 17:05:00 -0300 | [diff] [blame] | 1531 | &dev->i2c_bus[dev->tuner_bus].i2c_adap, |
Laurent Pinchart | 1532a07 | 2010-09-24 07:58:29 -0300 | [diff] [blame] | 1532 | "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV)); |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1533 | if (sd) { |
| 1534 | struct tuner_setup tun_setup; |
| 1535 | |
David T.L. Wong | fd705e7 | 2009-10-21 11:08:30 -0300 | [diff] [blame] | 1536 | memset(&tun_setup, 0, sizeof(tun_setup)); |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1537 | tun_setup.mode_mask = T_ANALOG_TV; |
| 1538 | tun_setup.type = dev->tuner_type; |
| 1539 | tun_setup.addr = v4l2_i2c_subdev_addr(sd); |
David T.L. Wong | 6f0d8c0 | 2009-10-21 13:15:30 -0300 | [diff] [blame] | 1540 | tun_setup.tuner_callback = cx23885_tuner_callback; |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1541 | |
| 1542 | v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup); |
Kusanagi Kouichi | 0b32d65 | 2010-01-22 04:55:28 -0300 | [diff] [blame] | 1543 | |
| 1544 | if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) { |
| 1545 | struct xc2028_ctrl ctrl = { |
| 1546 | .fname = XC2028_DEFAULT_FIRMWARE, |
| 1547 | .max_len = 64 |
| 1548 | }; |
| 1549 | struct v4l2_priv_tun_config cfg = { |
| 1550 | .tuner = dev->tuner_type, |
| 1551 | .priv = &ctrl |
| 1552 | }; |
| 1553 | v4l2_subdev_call(sd, tuner, s_config, &cfg); |
| 1554 | } |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
Steven Toth | 79776c8 | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1558 | /* register Video device */ |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1559 | dev->video_dev = cx23885_vdev_init(dev, dev->pci, |
| 1560 | &cx23885_video_template, "video"); |
| 1561 | err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER, |
| 1562 | video_nr[dev->nr]); |
| 1563 | if (err < 0) { |
| 1564 | printk(KERN_INFO "%s: can't register video device\n", |
| 1565 | dev->name); |
| 1566 | goto fail_unreg; |
| 1567 | } |
Steven Toth | f88fb8e | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1568 | printk(KERN_INFO "%s: registered device %s [v4l2]\n", |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1569 | dev->name, video_device_node_name(dev->video_dev)); |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1570 | |
Steven Toth | f88fb8e | 2011-10-10 11:09:54 -0300 | [diff] [blame] | 1571 | /* register VBI device */ |
| 1572 | dev->vbi_dev = cx23885_vdev_init(dev, dev->pci, |
| 1573 | &cx23885_vbi_template, "vbi"); |
| 1574 | err = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, |
| 1575 | vbi_nr[dev->nr]); |
| 1576 | if (err < 0) { |
| 1577 | printk(KERN_INFO "%s: can't register vbi device\n", |
| 1578 | dev->name); |
| 1579 | goto fail_unreg; |
| 1580 | } |
| 1581 | printk(KERN_INFO "%s: registered device %s\n", |
| 1582 | dev->name, video_device_node_name(dev->vbi_dev)); |
| 1583 | |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1584 | /* Register ALSA audio device */ |
Steven Toth | efa762f | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1585 | dev->audio_dev = cx23885_audio_register(dev); |
Mijhail Moreyra | 97ce567 | 2011-10-10 11:09:53 -0300 | [diff] [blame] | 1586 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1587 | /* initial device configuration */ |
| 1588 | mutex_lock(&dev->lock); |
| 1589 | cx23885_set_tvnorm(dev, dev->tvnorm); |
| 1590 | init_controls(dev); |
| 1591 | cx23885_video_mux(dev, 0); |
| 1592 | mutex_unlock(&dev->lock); |
| 1593 | |
Steven Toth | e47f30b | 2008-01-10 04:25:59 -0300 | [diff] [blame] | 1594 | return 0; |
| 1595 | |
| 1596 | fail_unreg: |
| 1597 | cx23885_video_unregister(dev); |
| 1598 | return err; |
| 1599 | } |
| 1600 | |