Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * device driver for Conexant 2388x based TV cards |
| 4 | * video4linux video interface |
| 5 | * |
| 6 | * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
| 7 | * |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 8 | * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org> |
| 9 | * - Multituner support |
| 10 | * - video_ioctl2 conversion |
| 11 | * - PAL/M fixes |
| 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/list.h> |
| 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/kmod.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/interrupt.h> |
Andrew Morton | c24228d | 2007-05-06 14:51:55 -0700 | [diff] [blame] | 35 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/kthread.h> |
| 38 | #include <asm/div64.h> |
| 39 | |
| 40 | #include "cx88.h" |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 41 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 42 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards"); |
| 45 | MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | |
| 48 | /* ------------------------------------------------------------------ */ |
| 49 | |
| 50 | static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; |
| 51 | static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; |
| 52 | static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; |
| 53 | |
| 54 | module_param_array(video_nr, int, NULL, 0444); |
| 55 | module_param_array(vbi_nr, int, NULL, 0444); |
| 56 | module_param_array(radio_nr, int, NULL, 0444); |
| 57 | |
| 58 | MODULE_PARM_DESC(video_nr,"video device numbers"); |
| 59 | MODULE_PARM_DESC(vbi_nr,"vbi device numbers"); |
| 60 | MODULE_PARM_DESC(radio_nr,"radio device numbers"); |
| 61 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 62 | static unsigned int video_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | module_param(video_debug,int,0644); |
| 64 | MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); |
| 65 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 66 | static unsigned int irq_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | module_param(irq_debug,int,0644); |
| 68 | MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]"); |
| 69 | |
| 70 | static unsigned int vid_limit = 16; |
| 71 | module_param(vid_limit,int,0644); |
| 72 | MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes"); |
| 73 | |
| 74 | #define dprintk(level,fmt, arg...) if (video_debug >= level) \ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 75 | printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /* ------------------------------------------------------------------ */ |
| 78 | |
| 79 | static LIST_HEAD(cx8800_devlist); |
| 80 | |
| 81 | /* ------------------------------------------------------------------- */ |
| 82 | /* static data */ |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | static struct cx8800_fmt formats[] = { |
| 85 | { |
| 86 | .name = "8 bpp, gray", |
| 87 | .fourcc = V4L2_PIX_FMT_GREY, |
| 88 | .cxformat = ColorFormatY8, |
| 89 | .depth = 8, |
| 90 | .flags = FORMAT_FLAGS_PACKED, |
| 91 | },{ |
| 92 | .name = "15 bpp RGB, le", |
| 93 | .fourcc = V4L2_PIX_FMT_RGB555, |
| 94 | .cxformat = ColorFormatRGB15, |
| 95 | .depth = 16, |
| 96 | .flags = FORMAT_FLAGS_PACKED, |
| 97 | },{ |
| 98 | .name = "15 bpp RGB, be", |
| 99 | .fourcc = V4L2_PIX_FMT_RGB555X, |
| 100 | .cxformat = ColorFormatRGB15 | ColorFormatBSWAP, |
| 101 | .depth = 16, |
| 102 | .flags = FORMAT_FLAGS_PACKED, |
| 103 | },{ |
| 104 | .name = "16 bpp RGB, le", |
| 105 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 106 | .cxformat = ColorFormatRGB16, |
| 107 | .depth = 16, |
| 108 | .flags = FORMAT_FLAGS_PACKED, |
| 109 | },{ |
| 110 | .name = "16 bpp RGB, be", |
| 111 | .fourcc = V4L2_PIX_FMT_RGB565X, |
| 112 | .cxformat = ColorFormatRGB16 | ColorFormatBSWAP, |
| 113 | .depth = 16, |
| 114 | .flags = FORMAT_FLAGS_PACKED, |
| 115 | },{ |
| 116 | .name = "24 bpp RGB, le", |
| 117 | .fourcc = V4L2_PIX_FMT_BGR24, |
| 118 | .cxformat = ColorFormatRGB24, |
| 119 | .depth = 24, |
| 120 | .flags = FORMAT_FLAGS_PACKED, |
| 121 | },{ |
| 122 | .name = "32 bpp RGB, le", |
| 123 | .fourcc = V4L2_PIX_FMT_BGR32, |
| 124 | .cxformat = ColorFormatRGB32, |
| 125 | .depth = 32, |
| 126 | .flags = FORMAT_FLAGS_PACKED, |
| 127 | },{ |
| 128 | .name = "32 bpp RGB, be", |
| 129 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 130 | .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP, |
| 131 | .depth = 32, |
| 132 | .flags = FORMAT_FLAGS_PACKED, |
| 133 | },{ |
| 134 | .name = "4:2:2, packed, YUYV", |
| 135 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 136 | .cxformat = ColorFormatYUY2, |
| 137 | .depth = 16, |
| 138 | .flags = FORMAT_FLAGS_PACKED, |
| 139 | },{ |
| 140 | .name = "4:2:2, packed, UYVY", |
| 141 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 142 | .cxformat = ColorFormatYUY2 | ColorFormatBSWAP, |
| 143 | .depth = 16, |
| 144 | .flags = FORMAT_FLAGS_PACKED, |
| 145 | }, |
| 146 | }; |
| 147 | |
| 148 | static struct cx8800_fmt* format_by_fourcc(unsigned int fourcc) |
| 149 | { |
| 150 | unsigned int i; |
| 151 | |
| 152 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 153 | if (formats[i].fourcc == fourcc) |
| 154 | return formats+i; |
| 155 | return NULL; |
| 156 | } |
| 157 | |
| 158 | /* ------------------------------------------------------------------- */ |
| 159 | |
| 160 | static const struct v4l2_queryctrl no_ctl = { |
| 161 | .name = "42", |
| 162 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 163 | }; |
| 164 | |
| 165 | static struct cx88_ctrl cx8800_ctls[] = { |
| 166 | /* --- video --- */ |
| 167 | { |
| 168 | .v = { |
| 169 | .id = V4L2_CID_BRIGHTNESS, |
| 170 | .name = "Brightness", |
| 171 | .minimum = 0x00, |
| 172 | .maximum = 0xff, |
| 173 | .step = 1, |
Marcin Rudowski | 9f9c907 | 2006-03-12 00:03:47 -0300 | [diff] [blame] | 174 | .default_value = 0x7f, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 176 | }, |
| 177 | .off = 128, |
| 178 | .reg = MO_CONTR_BRIGHT, |
| 179 | .mask = 0x00ff, |
| 180 | .shift = 0, |
| 181 | },{ |
| 182 | .v = { |
| 183 | .id = V4L2_CID_CONTRAST, |
| 184 | .name = "Contrast", |
| 185 | .minimum = 0, |
| 186 | .maximum = 0xff, |
| 187 | .step = 1, |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 188 | .default_value = 0x3f, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 190 | }, |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 191 | .off = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | .reg = MO_CONTR_BRIGHT, |
| 193 | .mask = 0xff00, |
| 194 | .shift = 8, |
| 195 | },{ |
| 196 | .v = { |
| 197 | .id = V4L2_CID_HUE, |
| 198 | .name = "Hue", |
| 199 | .minimum = 0, |
| 200 | .maximum = 0xff, |
| 201 | .step = 1, |
Marcin Rudowski | 9f9c907 | 2006-03-12 00:03:47 -0300 | [diff] [blame] | 202 | .default_value = 0x7f, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 204 | }, |
Michael Krufky | 9ac4c15 | 2005-07-07 17:58:38 -0700 | [diff] [blame] | 205 | .off = 128, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | .reg = MO_HUE, |
| 207 | .mask = 0x00ff, |
| 208 | .shift = 0, |
| 209 | },{ |
| 210 | /* strictly, this only describes only U saturation. |
| 211 | * V saturation is handled specially through code. |
| 212 | */ |
| 213 | .v = { |
| 214 | .id = V4L2_CID_SATURATION, |
| 215 | .name = "Saturation", |
| 216 | .minimum = 0, |
| 217 | .maximum = 0xff, |
| 218 | .step = 1, |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 219 | .default_value = 0x7f, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 221 | }, |
| 222 | .off = 0, |
| 223 | .reg = MO_UV_SATURATION, |
| 224 | .mask = 0x00ff, |
| 225 | .shift = 0, |
| 226 | },{ |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 227 | .v = { |
| 228 | .id = V4L2_CID_CHROMA_AGC, |
| 229 | .name = "Chroma AGC", |
| 230 | .minimum = 0, |
| 231 | .maximum = 1, |
Frej Drejhammar | 87a1738 | 2008-03-23 22:43:22 -0300 | [diff] [blame] | 232 | .default_value = 0x1, |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 233 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 234 | }, |
| 235 | .reg = MO_INPUT_FORMAT, |
| 236 | .mask = 1 << 10, |
| 237 | .shift = 10, |
| 238 | }, { |
Frej Drejhammar | 1b879c4 | 2008-03-23 22:43:24 -0300 | [diff] [blame] | 239 | .v = { |
| 240 | .id = V4L2_CID_COLOR_KILLER, |
| 241 | .name = "Color killer", |
| 242 | .minimum = 0, |
| 243 | .maximum = 1, |
Frej Drejhammar | 0b5afdd | 2008-03-23 22:43:25 -0300 | [diff] [blame] | 244 | .default_value = 0x1, |
Frej Drejhammar | 1b879c4 | 2008-03-23 22:43:24 -0300 | [diff] [blame] | 245 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 246 | }, |
| 247 | .reg = MO_INPUT_FORMAT, |
| 248 | .mask = 1 << 9, |
| 249 | .shift = 9, |
| 250 | }, { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | /* --- audio --- */ |
| 252 | .v = { |
| 253 | .id = V4L2_CID_AUDIO_MUTE, |
| 254 | .name = "Mute", |
| 255 | .minimum = 0, |
| 256 | .maximum = 1, |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 257 | .default_value = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 259 | }, |
| 260 | .reg = AUD_VOL_CTL, |
| 261 | .sreg = SHADOW_AUD_VOL_CTL, |
| 262 | .mask = (1 << 6), |
| 263 | .shift = 6, |
| 264 | },{ |
| 265 | .v = { |
| 266 | .id = V4L2_CID_AUDIO_VOLUME, |
| 267 | .name = "Volume", |
| 268 | .minimum = 0, |
| 269 | .maximum = 0x3f, |
| 270 | .step = 1, |
Marcin Rudowski | 9f9c907 | 2006-03-12 00:03:47 -0300 | [diff] [blame] | 271 | .default_value = 0x3f, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 273 | }, |
| 274 | .reg = AUD_VOL_CTL, |
| 275 | .sreg = SHADOW_AUD_VOL_CTL, |
| 276 | .mask = 0x3f, |
| 277 | .shift = 0, |
| 278 | },{ |
| 279 | .v = { |
| 280 | .id = V4L2_CID_AUDIO_BALANCE, |
| 281 | .name = "Balance", |
| 282 | .minimum = 0, |
| 283 | .maximum = 0x7f, |
| 284 | .step = 1, |
| 285 | .default_value = 0x40, |
| 286 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 287 | }, |
| 288 | .reg = AUD_BAL_CTL, |
| 289 | .sreg = SHADOW_AUD_BAL_CTL, |
| 290 | .mask = 0x7f, |
| 291 | .shift = 0, |
| 292 | } |
| 293 | }; |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 294 | static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Hans Verkuil | 2ba5889 | 2009-02-13 10:57:48 -0300 | [diff] [blame] | 296 | /* Must be sorted from low to high control ID! */ |
Michael Krufky | 38a2713 | 2006-06-26 23:42:39 -0300 | [diff] [blame] | 297 | const u32 cx88_user_ctrls[] = { |
| 298 | V4L2_CID_USER_CLASS, |
| 299 | V4L2_CID_BRIGHTNESS, |
| 300 | V4L2_CID_CONTRAST, |
| 301 | V4L2_CID_SATURATION, |
| 302 | V4L2_CID_HUE, |
| 303 | V4L2_CID_AUDIO_VOLUME, |
| 304 | V4L2_CID_AUDIO_BALANCE, |
| 305 | V4L2_CID_AUDIO_MUTE, |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 306 | V4L2_CID_CHROMA_AGC, |
Frej Drejhammar | 1b879c4 | 2008-03-23 22:43:24 -0300 | [diff] [blame] | 307 | V4L2_CID_COLOR_KILLER, |
Michael Krufky | 38a2713 | 2006-06-26 23:42:39 -0300 | [diff] [blame] | 308 | 0 |
| 309 | }; |
| 310 | EXPORT_SYMBOL(cx88_user_ctrls); |
| 311 | |
| 312 | static const u32 *ctrl_classes[] = { |
| 313 | cx88_user_ctrls, |
| 314 | NULL |
| 315 | }; |
| 316 | |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 317 | int cx8800_ctrl_query(struct cx88_core *core, struct v4l2_queryctrl *qctrl) |
Michael Krufky | 38a2713 | 2006-06-26 23:42:39 -0300 | [diff] [blame] | 318 | { |
| 319 | int i; |
| 320 | |
| 321 | if (qctrl->id < V4L2_CID_BASE || |
| 322 | qctrl->id >= V4L2_CID_LASTP1) |
| 323 | return -EINVAL; |
| 324 | for (i = 0; i < CX8800_CTLS; i++) |
| 325 | if (cx8800_ctls[i].v.id == qctrl->id) |
| 326 | break; |
| 327 | if (i == CX8800_CTLS) { |
| 328 | *qctrl = no_ctl; |
| 329 | return 0; |
| 330 | } |
| 331 | *qctrl = cx8800_ctls[i].v; |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 332 | /* Report chroma AGC as inactive when SECAM is selected */ |
| 333 | if (cx8800_ctls[i].v.id == V4L2_CID_CHROMA_AGC && |
| 334 | core->tvnorm & V4L2_STD_SECAM) |
| 335 | qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; |
| 336 | |
Michael Krufky | 38a2713 | 2006-06-26 23:42:39 -0300 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | EXPORT_SYMBOL(cx8800_ctrl_query); |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* ------------------------------------------------------------------- */ |
| 342 | /* resource management */ |
| 343 | |
| 344 | static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit) |
| 345 | { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 346 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | if (fh->resources & bit) |
| 348 | /* have it already allocated */ |
| 349 | return 1; |
| 350 | |
| 351 | /* is it free? */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 352 | mutex_lock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (dev->resources & bit) { |
| 354 | /* no, someone else uses it */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 355 | mutex_unlock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | /* it's free, grab it */ |
| 359 | fh->resources |= bit; |
| 360 | dev->resources |= bit; |
| 361 | dprintk(1,"res: get %d\n",bit); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 362 | mutex_unlock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return 1; |
| 364 | } |
| 365 | |
| 366 | static |
| 367 | int res_check(struct cx8800_fh *fh, unsigned int bit) |
| 368 | { |
| 369 | return (fh->resources & bit); |
| 370 | } |
| 371 | |
| 372 | static |
| 373 | int res_locked(struct cx8800_dev *dev, unsigned int bit) |
| 374 | { |
| 375 | return (dev->resources & bit); |
| 376 | } |
| 377 | |
| 378 | static |
| 379 | void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits) |
| 380 | { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 381 | struct cx88_core *core = dev->core; |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 382 | BUG_ON((fh->resources & bits) != bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 384 | mutex_lock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | fh->resources &= ~bits; |
| 386 | dev->resources &= ~bits; |
| 387 | dprintk(1,"res: put %d\n",bits); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 388 | mutex_unlock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* ------------------------------------------------------------------ */ |
| 392 | |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 393 | int cx88_video_mux(struct cx88_core *core, unsigned int input) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 395 | /* struct cx88_core *core = dev->core; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n", |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 398 | input, INPUT(input).vmux, |
| 399 | INPUT(input).gpio0,INPUT(input).gpio1, |
| 400 | INPUT(input).gpio2,INPUT(input).gpio3); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 401 | core->input = input; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 402 | cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input).vmux << 14); |
| 403 | cx_write(MO_GP3_IO, INPUT(input).gpio3); |
| 404 | cx_write(MO_GP0_IO, INPUT(input).gpio0); |
| 405 | cx_write(MO_GP1_IO, INPUT(input).gpio1); |
| 406 | cx_write(MO_GP2_IO, INPUT(input).gpio2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 408 | switch (INPUT(input).type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | case CX88_VMUX_SVIDEO: |
| 410 | cx_set(MO_AFECFG_IO, 0x00000001); |
| 411 | cx_set(MO_INPUT_FORMAT, 0x00010010); |
| 412 | cx_set(MO_FILTER_EVEN, 0x00002020); |
| 413 | cx_set(MO_FILTER_ODD, 0x00002020); |
| 414 | break; |
| 415 | default: |
| 416 | cx_clear(MO_AFECFG_IO, 0x00000001); |
| 417 | cx_clear(MO_INPUT_FORMAT, 0x00010010); |
| 418 | cx_clear(MO_FILTER_EVEN, 0x00002020); |
| 419 | cx_clear(MO_FILTER_ODD, 0x00002020); |
| 420 | break; |
| 421 | } |
Michael Krufky | f24546a | 2006-10-16 16:51:11 -0300 | [diff] [blame] | 422 | |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 423 | /* if there are audioroutes defined, we have an external |
| 424 | ADC to deal with audio */ |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 425 | if (INPUT(input).audioroute) { |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 426 | /* The wm8775 module has the "2" route hardwired into |
| 427 | the initialization. Some boards may use different |
| 428 | routes for different inputs. HVR-1300 surely does */ |
| 429 | if (core->board.audio_chip && |
Hans Verkuil | 38f9d30 | 2008-07-23 05:09:15 -0300 | [diff] [blame] | 430 | core->board.audio_chip == V4L2_IDENT_WM8775) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 431 | call_all(core, audio, s_routing, |
| 432 | INPUT(input).audioroute, 0, 0); |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 433 | } |
Darron Broad | 430189d | 2008-10-15 14:18:42 -0300 | [diff] [blame] | 434 | /* cx2388's C-ADC is connected to the tuner only. |
| 435 | When used with S-Video, that ADC is busy dealing with |
| 436 | chroma, so an external must be used for baseband audio */ |
| 437 | if (INPUT(input).type != CX88_VMUX_TELEVISION ) { |
| 438 | /* "I2S ADC mode" */ |
| 439 | core->tvaudio = WW_I2SADC; |
| 440 | cx88_set_tvaudio(core); |
| 441 | } else { |
| 442 | /* Normal mode */ |
| 443 | cx_write(AUD_I2SCNTL, 0x0); |
| 444 | cx_clear(AUD_CTL, EN_I2SIN_ENABLE); |
| 445 | } |
Michael Krufky | f24546a | 2006-10-16 16:51:11 -0300 | [diff] [blame] | 446 | } |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | return 0; |
| 449 | } |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 450 | EXPORT_SYMBOL(cx88_video_mux); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | /* ------------------------------------------------------------------ */ |
| 453 | |
| 454 | static int start_video_dma(struct cx8800_dev *dev, |
| 455 | struct cx88_dmaqueue *q, |
| 456 | struct cx88_buffer *buf) |
| 457 | { |
| 458 | struct cx88_core *core = dev->core; |
| 459 | |
| 460 | /* setup fifo + format */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 461 | cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | buf->bpl, buf->risc.dma); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 463 | cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma); |
| 465 | |
| 466 | /* reset counter */ |
| 467 | cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET); |
| 468 | q->count = 1; |
| 469 | |
| 470 | /* enable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 471 | cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 472 | |
| 473 | /* Enables corresponding bits at PCI_INT_STAT: |
| 474 | bits 0 to 4: video, audio, transport stream, VIP, Host |
| 475 | bit 7: timer |
| 476 | bits 8 and 9: DMA complete for: SRC, DST |
| 477 | bits 10 and 11: BERR signal asserted for RISC: RD, WR |
| 478 | bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB |
| 479 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | cx_set(MO_VID_INTMSK, 0x0f0011); |
| 481 | |
| 482 | /* enable capture */ |
| 483 | cx_set(VID_CAPTURE_CONTROL,0x06); |
| 484 | |
| 485 | /* start dma */ |
| 486 | cx_set(MO_DEV_CNTRL2, (1<<5)); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 487 | cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 492 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | static int stop_video_dma(struct cx8800_dev *dev) |
| 494 | { |
| 495 | struct cx88_core *core = dev->core; |
| 496 | |
| 497 | /* stop dma */ |
| 498 | cx_clear(MO_VID_DMACNTRL, 0x11); |
| 499 | |
| 500 | /* disable capture */ |
| 501 | cx_clear(VID_CAPTURE_CONTROL,0x06); |
| 502 | |
| 503 | /* disable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 504 | cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | cx_clear(MO_VID_INTMSK, 0x0f0011); |
| 506 | return 0; |
| 507 | } |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 508 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | static int restart_video_queue(struct cx8800_dev *dev, |
| 511 | struct cx88_dmaqueue *q) |
| 512 | { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 513 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | struct cx88_buffer *buf, *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
| 516 | if (!list_empty(&q->active)) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 517 | buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | dprintk(2,"restart_queue [%p/%d]: restart dma\n", |
| 519 | buf, buf->vb.i); |
| 520 | start_video_dma(dev, q, buf); |
Trent Piepho | 8bb629e2 | 2007-10-10 05:37:40 -0300 | [diff] [blame] | 521 | list_for_each_entry(buf, &q->active, vb.queue) |
| 522 | buf->count = q->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | prev = NULL; |
| 528 | for (;;) { |
| 529 | if (list_empty(&q->queued)) |
| 530 | return 0; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 531 | buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (NULL == prev) { |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 533 | list_move_tail(&buf->vb.queue, &q->active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | start_video_dma(dev, q, buf); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 535 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | buf->count = q->count++; |
| 537 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 538 | dprintk(2,"[%p/%d] restart_queue - first active\n", |
| 539 | buf,buf->vb.i); |
| 540 | |
| 541 | } else if (prev->vb.width == buf->vb.width && |
| 542 | prev->vb.height == buf->vb.height && |
| 543 | prev->fmt == buf->fmt) { |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 544 | list_move_tail(&buf->vb.queue, &q->active); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 545 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | buf->count = q->count++; |
| 547 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 548 | dprintk(2,"[%p/%d] restart_queue - move to active\n", |
| 549 | buf,buf->vb.i); |
| 550 | } else { |
| 551 | return 0; |
| 552 | } |
| 553 | prev = buf; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /* ------------------------------------------------------------------ */ |
| 558 | |
| 559 | static int |
| 560 | buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) |
| 561 | { |
| 562 | struct cx8800_fh *fh = q->priv_data; |
| 563 | |
| 564 | *size = fh->fmt->depth*fh->width*fh->height >> 3; |
| 565 | if (0 == *count) |
| 566 | *count = 32; |
| 567 | while (*size * *count > vid_limit * 1024 * 1024) |
| 568 | (*count)--; |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | static int |
| 573 | buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
| 574 | enum v4l2_field field) |
| 575 | { |
| 576 | struct cx8800_fh *fh = q->priv_data; |
| 577 | struct cx8800_dev *dev = fh->dev; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 578 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 580 | struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | int rc, init_buffer = 0; |
| 582 | |
| 583 | BUG_ON(NULL == fh->fmt); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 584 | if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) || |
| 585 | fh->height < 32 || fh->height > norm_maxh(core->tvnorm)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return -EINVAL; |
| 587 | buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; |
| 588 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 589 | return -EINVAL; |
| 590 | |
| 591 | if (buf->fmt != fh->fmt || |
| 592 | buf->vb.width != fh->width || |
| 593 | buf->vb.height != fh->height || |
| 594 | buf->vb.field != field) { |
| 595 | buf->fmt = fh->fmt; |
| 596 | buf->vb.width = fh->width; |
| 597 | buf->vb.height = fh->height; |
| 598 | buf->vb.field = field; |
| 599 | init_buffer = 1; |
| 600 | } |
| 601 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 602 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | init_buffer = 1; |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 604 | if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | goto fail; |
| 606 | } |
| 607 | |
| 608 | if (init_buffer) { |
| 609 | buf->bpl = buf->vb.width * buf->fmt->depth >> 3; |
| 610 | switch (buf->vb.field) { |
| 611 | case V4L2_FIELD_TOP: |
| 612 | cx88_risc_buffer(dev->pci, &buf->risc, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 613 | dma->sglist, 0, UNSET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | buf->bpl, 0, buf->vb.height); |
| 615 | break; |
| 616 | case V4L2_FIELD_BOTTOM: |
| 617 | cx88_risc_buffer(dev->pci, &buf->risc, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 618 | dma->sglist, UNSET, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | buf->bpl, 0, buf->vb.height); |
| 620 | break; |
| 621 | case V4L2_FIELD_INTERLACED: |
| 622 | cx88_risc_buffer(dev->pci, &buf->risc, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 623 | dma->sglist, 0, buf->bpl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | buf->bpl, buf->bpl, |
| 625 | buf->vb.height >> 1); |
| 626 | break; |
| 627 | case V4L2_FIELD_SEQ_TB: |
| 628 | cx88_risc_buffer(dev->pci, &buf->risc, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 629 | dma->sglist, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | 0, buf->bpl * (buf->vb.height >> 1), |
| 631 | buf->bpl, 0, |
| 632 | buf->vb.height >> 1); |
| 633 | break; |
| 634 | case V4L2_FIELD_SEQ_BT: |
| 635 | cx88_risc_buffer(dev->pci, &buf->risc, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 636 | dma->sglist, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | buf->bpl * (buf->vb.height >> 1), 0, |
| 638 | buf->bpl, 0, |
| 639 | buf->vb.height >> 1); |
| 640 | break; |
| 641 | default: |
| 642 | BUG(); |
| 643 | } |
| 644 | } |
| 645 | dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
| 646 | buf, buf->vb.i, |
| 647 | fh->width, fh->height, fh->fmt->depth, fh->fmt->name, |
| 648 | (unsigned long)buf->risc.dma); |
| 649 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 650 | buf->vb.state = VIDEOBUF_PREPARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return 0; |
| 652 | |
| 653 | fail: |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 654 | cx88_free_buffer(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | return rc; |
| 656 | } |
| 657 | |
| 658 | static void |
| 659 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 660 | { |
| 661 | struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); |
| 662 | struct cx88_buffer *prev; |
| 663 | struct cx8800_fh *fh = vq->priv_data; |
| 664 | struct cx8800_dev *dev = fh->dev; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 665 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | struct cx88_dmaqueue *q = &dev->vidq; |
| 667 | |
| 668 | /* add jump to stopper */ |
| 669 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 670 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 671 | |
| 672 | if (!list_empty(&q->queued)) { |
| 673 | list_add_tail(&buf->vb.queue,&q->queued); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 674 | buf->vb.state = VIDEOBUF_QUEUED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | dprintk(2,"[%p/%d] buffer_queue - append to queued\n", |
| 676 | buf, buf->vb.i); |
| 677 | |
| 678 | } else if (list_empty(&q->active)) { |
| 679 | list_add_tail(&buf->vb.queue,&q->active); |
| 680 | start_video_dma(dev, q, buf); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 681 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | buf->count = q->count++; |
| 683 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 684 | dprintk(2,"[%p/%d] buffer_queue - first active\n", |
| 685 | buf, buf->vb.i); |
| 686 | |
| 687 | } else { |
| 688 | prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); |
| 689 | if (prev->vb.width == buf->vb.width && |
| 690 | prev->vb.height == buf->vb.height && |
| 691 | prev->fmt == buf->fmt) { |
| 692 | list_add_tail(&buf->vb.queue,&q->active); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 693 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | buf->count = q->count++; |
| 695 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 696 | dprintk(2,"[%p/%d] buffer_queue - append to active\n", |
| 697 | buf, buf->vb.i); |
| 698 | |
| 699 | } else { |
| 700 | list_add_tail(&buf->vb.queue,&q->queued); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 701 | buf->vb.state = VIDEOBUF_QUEUED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | dprintk(2,"[%p/%d] buffer_queue - first queued\n", |
| 703 | buf, buf->vb.i); |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 709 | { |
| 710 | struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 712 | cx88_free_buffer(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 715 | static struct videobuf_queue_ops cx8800_video_qops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | .buf_setup = buffer_setup, |
| 717 | .buf_prepare = buffer_prepare, |
| 718 | .buf_queue = buffer_queue, |
| 719 | .buf_release = buffer_release, |
| 720 | }; |
| 721 | |
| 722 | /* ------------------------------------------------------------------ */ |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
| 725 | /* ------------------------------------------------------------------ */ |
| 726 | |
| 727 | static struct videobuf_queue* get_queue(struct cx8800_fh *fh) |
| 728 | { |
| 729 | switch (fh->type) { |
| 730 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 731 | return &fh->vidq; |
| 732 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 733 | return &fh->vbiq; |
| 734 | default: |
| 735 | BUG(); |
| 736 | return NULL; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | static int get_ressource(struct cx8800_fh *fh) |
| 741 | { |
| 742 | switch (fh->type) { |
| 743 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 744 | return RESOURCE_VIDEO; |
| 745 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 746 | return RESOURCE_VBI; |
| 747 | default: |
| 748 | BUG(); |
| 749 | return 0; |
| 750 | } |
| 751 | } |
| 752 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 753 | static int video_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 755 | int minor = video_devdata(file)->minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | struct cx8800_dev *h,*dev = NULL; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 757 | struct cx88_core *core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | struct cx8800_fh *fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | enum v4l2_buf_type type = 0; |
| 760 | int radio = 0; |
| 761 | |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 762 | lock_kernel(); |
Trent Piepho | 8bb629e2 | 2007-10-10 05:37:40 -0300 | [diff] [blame] | 763 | list_for_each_entry(h, &cx8800_devlist, devlist) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | if (h->video_dev->minor == minor) { |
| 765 | dev = h; |
| 766 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 767 | } |
| 768 | if (h->vbi_dev->minor == minor) { |
| 769 | dev = h; |
| 770 | type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 771 | } |
| 772 | if (h->radio_dev && |
| 773 | h->radio_dev->minor == minor) { |
| 774 | radio = 1; |
| 775 | dev = h; |
| 776 | } |
| 777 | } |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 778 | if (NULL == dev) { |
| 779 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | return -ENODEV; |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 783 | core = dev->core; |
| 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | dprintk(1,"open minor=%d radio=%d type=%s\n", |
| 786 | minor,radio,v4l2_type_names[type]); |
| 787 | |
| 788 | /* allocate + initialize per filehandle data */ |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 789 | fh = kzalloc(sizeof(*fh),GFP_KERNEL); |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 790 | if (NULL == fh) { |
| 791 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | return -ENOMEM; |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 793 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | file->private_data = fh; |
| 795 | fh->dev = dev; |
| 796 | fh->radio = radio; |
| 797 | fh->type = type; |
| 798 | fh->width = 320; |
| 799 | fh->height = 240; |
| 800 | fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); |
| 801 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 802 | videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops, |
| 803 | &dev->pci->dev, &dev->slock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 805 | V4L2_FIELD_INTERLACED, |
| 806 | sizeof(struct cx88_buffer), |
| 807 | fh); |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 808 | videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops, |
| 809 | &dev->pci->dev, &dev->slock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | V4L2_BUF_TYPE_VBI_CAPTURE, |
| 811 | V4L2_FIELD_SEQ_TB, |
| 812 | sizeof(struct cx88_buffer), |
| 813 | fh); |
| 814 | |
| 815 | if (fh->radio) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | dprintk(1,"video_open: setting radio device\n"); |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 817 | cx_write(MO_GP3_IO, core->board.radio.gpio3); |
| 818 | cx_write(MO_GP0_IO, core->board.radio.gpio0); |
| 819 | cx_write(MO_GP1_IO, core->board.radio.gpio1); |
| 820 | cx_write(MO_GP2_IO, core->board.radio.gpio2); |
Darron Broad | 430189d | 2008-10-15 14:18:42 -0300 | [diff] [blame] | 821 | if (core->board.radio.audioroute) { |
| 822 | if(core->board.audio_chip && |
| 823 | core->board.audio_chip == V4L2_IDENT_WM8775) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 824 | call_all(core, audio, s_routing, |
| 825 | core->board.radio.audioroute, 0, 0); |
Darron Broad | 430189d | 2008-10-15 14:18:42 -0300 | [diff] [blame] | 826 | } |
| 827 | /* "I2S ADC mode" */ |
| 828 | core->tvaudio = WW_I2SADC; |
| 829 | cx88_set_tvaudio(core); |
| 830 | } else { |
| 831 | /* FM Mode */ |
| 832 | core->tvaudio = WW_FM; |
| 833 | cx88_set_tvaudio(core); |
| 834 | cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); |
| 835 | } |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 836 | call_all(core, tuner, s_radio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 838 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Darron Broad | 3e01084 | 2008-09-25 16:51:11 -0300 | [diff] [blame] | 840 | atomic_inc(&core->users); |
| 841 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 842 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | static ssize_t |
Peter Hagervall | f9e7a02 | 2005-11-08 21:36:29 -0800 | [diff] [blame] | 846 | video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
| 848 | struct cx8800_fh *fh = file->private_data; |
| 849 | |
| 850 | switch (fh->type) { |
| 851 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 852 | if (res_locked(fh->dev,RESOURCE_VIDEO)) |
| 853 | return -EBUSY; |
| 854 | return videobuf_read_one(&fh->vidq, data, count, ppos, |
| 855 | file->f_flags & O_NONBLOCK); |
| 856 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 857 | if (!res_get(fh->dev,fh,RESOURCE_VBI)) |
| 858 | return -EBUSY; |
| 859 | return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1, |
| 860 | file->f_flags & O_NONBLOCK); |
| 861 | default: |
| 862 | BUG(); |
| 863 | return 0; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | static unsigned int |
| 868 | video_poll(struct file *file, struct poll_table_struct *wait) |
| 869 | { |
| 870 | struct cx8800_fh *fh = file->private_data; |
| 871 | struct cx88_buffer *buf; |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 872 | unsigned int rc = POLLERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { |
| 875 | if (!res_get(fh->dev,fh,RESOURCE_VBI)) |
| 876 | return POLLERR; |
| 877 | return videobuf_poll_stream(file, &fh->vbiq, wait); |
| 878 | } |
| 879 | |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 880 | mutex_lock(&fh->vidq.vb_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | if (res_check(fh,RESOURCE_VIDEO)) { |
| 882 | /* streaming capture */ |
| 883 | if (list_empty(&fh->vidq.stream)) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 884 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream); |
| 886 | } else { |
| 887 | /* read() capture */ |
| 888 | buf = (struct cx88_buffer*)fh->vidq.read_buf; |
| 889 | if (NULL == buf) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 890 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | poll_wait(file, &buf->vb.done, wait); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 893 | if (buf->vb.state == VIDEOBUF_DONE || |
| 894 | buf->vb.state == VIDEOBUF_ERROR) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 895 | rc = POLLIN|POLLRDNORM; |
| 896 | else |
| 897 | rc = 0; |
| 898 | done: |
| 899 | mutex_unlock(&fh->vidq.vb_lock); |
| 900 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 903 | static int video_release(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
| 905 | struct cx8800_fh *fh = file->private_data; |
| 906 | struct cx8800_dev *dev = fh->dev; |
| 907 | |
| 908 | /* turn off overlay */ |
| 909 | if (res_check(fh, RESOURCE_OVERLAY)) { |
| 910 | /* FIXME */ |
| 911 | res_free(dev,fh,RESOURCE_OVERLAY); |
| 912 | } |
| 913 | |
| 914 | /* stop video capture */ |
| 915 | if (res_check(fh, RESOURCE_VIDEO)) { |
| 916 | videobuf_queue_cancel(&fh->vidq); |
| 917 | res_free(dev,fh,RESOURCE_VIDEO); |
| 918 | } |
| 919 | if (fh->vidq.read_buf) { |
| 920 | buffer_release(&fh->vidq,fh->vidq.read_buf); |
| 921 | kfree(fh->vidq.read_buf); |
| 922 | } |
| 923 | |
| 924 | /* stop vbi capture */ |
| 925 | if (res_check(fh, RESOURCE_VBI)) { |
Brandon Philips | 053fcb6 | 2007-11-13 20:11:26 -0300 | [diff] [blame] | 926 | videobuf_stop(&fh->vbiq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | res_free(dev,fh,RESOURCE_VBI); |
| 928 | } |
| 929 | |
| 930 | videobuf_mmap_free(&fh->vidq); |
| 931 | videobuf_mmap_free(&fh->vbiq); |
| 932 | file->private_data = NULL; |
| 933 | kfree(fh); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 934 | |
Devin Heitmueller | 06f837c | 2009-04-28 14:35:27 -0300 | [diff] [blame] | 935 | mutex_lock(&dev->core->lock); |
Darron Broad | 3e01084 | 2008-09-25 16:51:11 -0300 | [diff] [blame] | 936 | if(atomic_dec_and_test(&dev->core->users)) |
Hans Verkuil | 7c9fc9d | 2009-04-01 03:49:59 -0300 | [diff] [blame] | 937 | call_all(dev->core, tuner, s_standby); |
Devin Heitmueller | 06f837c | 2009-04-28 14:35:27 -0300 | [diff] [blame] | 938 | mutex_unlock(&dev->core->lock); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | static int |
| 944 | video_mmap(struct file *file, struct vm_area_struct * vma) |
| 945 | { |
| 946 | struct cx8800_fh *fh = file->private_data; |
| 947 | |
| 948 | return videobuf_mmap_mapper(get_queue(fh), vma); |
| 949 | } |
| 950 | |
| 951 | /* ------------------------------------------------------------------ */ |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 952 | /* VIDEO CTRL IOCTLS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 954 | int cx88_get_control (struct cx88_core *core, struct v4l2_control *ctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 956 | struct cx88_ctrl *c = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | u32 value; |
| 958 | int i; |
| 959 | |
| 960 | for (i = 0; i < CX8800_CTLS; i++) |
| 961 | if (cx8800_ctls[i].v.id == ctl->id) |
| 962 | c = &cx8800_ctls[i]; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 963 | if (unlikely(NULL == c)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | return -EINVAL; |
| 965 | |
| 966 | value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg); |
| 967 | switch (ctl->id) { |
| 968 | case V4L2_CID_AUDIO_BALANCE: |
Marcin Rudowski | 9f9c907 | 2006-03-12 00:03:47 -0300 | [diff] [blame] | 969 | ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40) |
| 970 | : (0x7f - (value & 0x7f)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | break; |
| 972 | case V4L2_CID_AUDIO_VOLUME: |
| 973 | ctl->value = 0x3f - (value & 0x3f); |
| 974 | break; |
| 975 | default: |
| 976 | ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift; |
| 977 | break; |
| 978 | } |
Ian Pickworth | 6457af5 | 2006-02-27 00:09:45 -0300 | [diff] [blame] | 979 | dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", |
| 980 | ctl->id, c->v.name, ctl->value, c->reg, |
| 981 | value,c->mask, c->sreg ? " [shadowed]" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return 0; |
| 983 | } |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 984 | EXPORT_SYMBOL(cx88_get_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 986 | int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | struct cx88_ctrl *c = NULL; |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 989 | u32 value,mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | int i; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 991 | |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 992 | for (i = 0; i < CX8800_CTLS; i++) { |
| 993 | if (cx8800_ctls[i].v.id == ctl->id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | c = &cx8800_ctls[i]; |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 995 | } |
| 996 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 997 | if (unlikely(NULL == c)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | return -EINVAL; |
| 999 | |
| 1000 | if (ctl->value < c->v.minimum) |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1001 | ctl->value = c->v.minimum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | if (ctl->value > c->v.maximum) |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1003 | ctl->value = c->v.maximum; |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1004 | mask=c->mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | switch (ctl->id) { |
| 1006 | case V4L2_CID_AUDIO_BALANCE: |
Marcin Rudowski | 9f9c907 | 2006-03-12 00:03:47 -0300 | [diff] [blame] | 1007 | value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | break; |
| 1009 | case V4L2_CID_AUDIO_VOLUME: |
| 1010 | value = 0x3f - (ctl->value & 0x3f); |
| 1011 | break; |
| 1012 | case V4L2_CID_SATURATION: |
| 1013 | /* special v_sat handling */ |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1014 | |
| 1015 | value = ((ctl->value - c->off) << c->shift) & c->mask; |
| 1016 | |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1017 | if (core->tvnorm & V4L2_STD_SECAM) { |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1018 | /* For SECAM, both U and V sat should be equal */ |
| 1019 | value=value<<8|value; |
| 1020 | } else { |
| 1021 | /* Keeps U Saturation proportional to V Sat */ |
| 1022 | value=(value*0x5a)/0x7f<<8|value; |
| 1023 | } |
| 1024 | mask=0xffff; |
| 1025 | break; |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 1026 | case V4L2_CID_CHROMA_AGC: |
| 1027 | /* Do not allow chroma AGC to be enabled for SECAM */ |
| 1028 | value = ((ctl->value - c->off) << c->shift) & c->mask; |
| 1029 | if (core->tvnorm & V4L2_STD_SECAM && value) |
| 1030 | return -EINVAL; |
| 1031 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | default: |
| 1033 | value = ((ctl->value - c->off) << c->shift) & c->mask; |
| 1034 | break; |
| 1035 | } |
Ian Pickworth | 6457af5 | 2006-02-27 00:09:45 -0300 | [diff] [blame] | 1036 | dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", |
| 1037 | ctl->id, c->v.name, ctl->value, c->reg, value, |
| 1038 | mask, c->sreg ? " [shadowed]" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | if (c->sreg) { |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1040 | cx_sandor(c->sreg, c->reg, mask, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } else { |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1042 | cx_andor(c->reg, mask, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | } |
| 1044 | return 0; |
| 1045 | } |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1046 | EXPORT_SYMBOL(cx88_set_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1048 | static void init_controls(struct cx88_core *core) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | { |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1050 | struct v4l2_control ctrl; |
| 1051 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1053 | for (i = 0; i < CX8800_CTLS; i++) { |
| 1054 | ctrl.id=cx8800_ctls[i].v.id; |
Marcin Rudowski | 9f9c907 | 2006-03-12 00:03:47 -0300 | [diff] [blame] | 1055 | ctrl.value=cx8800_ctls[i].v.default_value; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1056 | |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1057 | cx88_set_control(core, &ctrl); |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /* ------------------------------------------------------------------ */ |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1062 | /* VIDEO IOCTLS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1064 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1065 | struct v4l2_format *f) |
| 1066 | { |
| 1067 | struct cx8800_fh *fh = priv; |
| 1068 | |
| 1069 | f->fmt.pix.width = fh->width; |
| 1070 | f->fmt.pix.height = fh->height; |
| 1071 | f->fmt.pix.field = fh->vidq.field; |
| 1072 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 1073 | f->fmt.pix.bytesperline = |
| 1074 | (f->fmt.pix.width * fh->fmt->depth) >> 3; |
| 1075 | f->fmt.pix.sizeimage = |
| 1076 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1080 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | struct v4l2_format *f) |
| 1082 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1083 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1084 | struct cx8800_fmt *fmt; |
| 1085 | enum v4l2_field field; |
| 1086 | unsigned int maxw, maxh; |
| 1087 | |
| 1088 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1089 | if (NULL == fmt) |
| 1090 | return -EINVAL; |
| 1091 | |
| 1092 | field = f->fmt.pix.field; |
| 1093 | maxw = norm_maxw(core->tvnorm); |
| 1094 | maxh = norm_maxh(core->tvnorm); |
| 1095 | |
| 1096 | if (V4L2_FIELD_ANY == field) { |
| 1097 | field = (f->fmt.pix.height > maxh/2) |
| 1098 | ? V4L2_FIELD_INTERLACED |
| 1099 | : V4L2_FIELD_BOTTOM; |
| 1100 | } |
| 1101 | |
| 1102 | switch (field) { |
| 1103 | case V4L2_FIELD_TOP: |
| 1104 | case V4L2_FIELD_BOTTOM: |
| 1105 | maxh = maxh / 2; |
| 1106 | break; |
| 1107 | case V4L2_FIELD_INTERLACED: |
| 1108 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | default: |
| 1110 | return -EINVAL; |
| 1111 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1112 | |
| 1113 | f->fmt.pix.field = field; |
Trent Piepho | 4b89945 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1114 | v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2, |
| 1115 | &f->fmt.pix.height, 32, maxh, 0, 0); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1116 | f->fmt.pix.bytesperline = |
| 1117 | (f->fmt.pix.width * fmt->depth) >> 3; |
| 1118 | f->fmt.pix.sizeimage = |
| 1119 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 1120 | |
| 1121 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1124 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1125 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1127 | struct cx8800_fh *fh = priv; |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1128 | int err = vidioc_try_fmt_vid_cap (file,priv,f); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1129 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1130 | if (0 != err) |
| 1131 | return err; |
| 1132 | fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1133 | fh->width = f->fmt.pix.width; |
| 1134 | fh->height = f->fmt.pix.height; |
| 1135 | fh->vidq.field = f->fmt.pix.field; |
| 1136 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1139 | static int vidioc_querycap (struct file *file, void *priv, |
| 1140 | struct v4l2_capability *cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1142 | struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1145 | strcpy(cap->driver, "cx8800"); |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1146 | strlcpy(cap->card, core->board.name, sizeof(cap->card)); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1147 | sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci)); |
| 1148 | cap->version = CX88_VERSION_CODE; |
| 1149 | cap->capabilities = |
| 1150 | V4L2_CAP_VIDEO_CAPTURE | |
| 1151 | V4L2_CAP_READWRITE | |
| 1152 | V4L2_CAP_STREAMING | |
| 1153 | V4L2_CAP_VBI_CAPTURE; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1154 | if (UNSET != core->board.tuner_type) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1155 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1156 | return 0; |
| 1157 | } |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1158 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1159 | static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1160 | struct v4l2_fmtdesc *f) |
| 1161 | { |
| 1162 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 1163 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1165 | strlcpy(f->description,formats[f->index].name,sizeof(f->description)); |
| 1166 | f->pixelformat = formats[f->index].fourcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1168 | return 0; |
| 1169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
Mauro Carvalho Chehab | 0dfa9ab | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 1171 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1172 | static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1173 | { |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 1174 | struct cx8800_fh *fh = priv; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1175 | |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 1176 | return videobuf_cgmbuf (get_queue(fh), mbuf, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1178 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1180 | static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1182 | struct cx8800_fh *fh = priv; |
| 1183 | return (videobuf_reqbufs(get_queue(fh), p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1186 | static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p) |
| 1187 | { |
| 1188 | struct cx8800_fh *fh = priv; |
| 1189 | return (videobuf_querybuf(get_queue(fh), p)); |
| 1190 | } |
| 1191 | |
| 1192 | static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p) |
| 1193 | { |
| 1194 | struct cx8800_fh *fh = priv; |
| 1195 | return (videobuf_qbuf(get_queue(fh), p)); |
| 1196 | } |
| 1197 | |
| 1198 | static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p) |
| 1199 | { |
| 1200 | struct cx8800_fh *fh = priv; |
| 1201 | return (videobuf_dqbuf(get_queue(fh), p, |
| 1202 | file->f_flags & O_NONBLOCK)); |
| 1203 | } |
| 1204 | |
| 1205 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 1206 | { |
| 1207 | struct cx8800_fh *fh = priv; |
| 1208 | struct cx8800_dev *dev = fh->dev; |
| 1209 | |
Rafael Diniz | b058e3f | 2008-10-24 23:07:57 -0300 | [diff] [blame] | 1210 | /* We should remember that this driver also supports teletext, */ |
| 1211 | /* so we have to test if the v4l2_buf_type is VBI capture data. */ |
| 1212 | if (unlikely((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && |
| 1213 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1214 | return -EINVAL; |
Rafael Diniz | b058e3f | 2008-10-24 23:07:57 -0300 | [diff] [blame] | 1215 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1216 | if (unlikely(i != fh->type)) |
| 1217 | return -EINVAL; |
| 1218 | |
| 1219 | if (unlikely(!res_get(dev,fh,get_ressource(fh)))) |
| 1220 | return -EBUSY; |
| 1221 | return videobuf_streamon(get_queue(fh)); |
| 1222 | } |
| 1223 | |
| 1224 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 1225 | { |
| 1226 | struct cx8800_fh *fh = priv; |
| 1227 | struct cx8800_dev *dev = fh->dev; |
| 1228 | int err, res; |
| 1229 | |
Rafael Diniz | b058e3f | 2008-10-24 23:07:57 -0300 | [diff] [blame] | 1230 | if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && |
| 1231 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1232 | return -EINVAL; |
Rafael Diniz | b058e3f | 2008-10-24 23:07:57 -0300 | [diff] [blame] | 1233 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1234 | if (i != fh->type) |
| 1235 | return -EINVAL; |
| 1236 | |
| 1237 | res = get_ressource(fh); |
| 1238 | err = videobuf_streamoff(get_queue(fh)); |
| 1239 | if (err < 0) |
| 1240 | return err; |
| 1241 | res_free(dev,fh,res); |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1245 | static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *tvnorms) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1246 | { |
| 1247 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1248 | |
| 1249 | mutex_lock(&core->lock); |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1250 | cx88_set_tvnorm(core,*tvnorms); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1251 | mutex_unlock(&core->lock); |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1252 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1253 | return 0; |
| 1254 | } |
| 1255 | |
| 1256 | /* only one input in this sample driver */ |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1257 | int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1258 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1259 | static const char *iname[] = { |
| 1260 | [ CX88_VMUX_COMPOSITE1 ] = "Composite1", |
| 1261 | [ CX88_VMUX_COMPOSITE2 ] = "Composite2", |
| 1262 | [ CX88_VMUX_COMPOSITE3 ] = "Composite3", |
| 1263 | [ CX88_VMUX_COMPOSITE4 ] = "Composite4", |
| 1264 | [ CX88_VMUX_SVIDEO ] = "S-Video", |
| 1265 | [ CX88_VMUX_TELEVISION ] = "Television", |
| 1266 | [ CX88_VMUX_CABLE ] = "Cable TV", |
| 1267 | [ CX88_VMUX_DVB ] = "DVB", |
| 1268 | [ CX88_VMUX_DEBUG ] = "for debug only", |
| 1269 | }; |
Trent Piepho | f3334bc | 2009-03-04 01:21:03 -0300 | [diff] [blame] | 1270 | unsigned int n = i->index; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1271 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1272 | if (n >= 4) |
| 1273 | return -EINVAL; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1274 | if (0 == INPUT(n).type) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1275 | return -EINVAL; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1276 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1277 | strcpy(i->name,iname[INPUT(n).type]); |
| 1278 | if ((CX88_VMUX_TELEVISION == INPUT(n).type) || |
| 1279 | (CX88_VMUX_CABLE == INPUT(n).type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1280 | i->type = V4L2_INPUT_TYPE_TUNER; |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1281 | i->std = CX88_NORMS; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1284 | EXPORT_SYMBOL(cx88_enum_input); |
| 1285 | |
| 1286 | static int vidioc_enum_input (struct file *file, void *priv, |
| 1287 | struct v4l2_input *i) |
| 1288 | { |
| 1289 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1290 | return cx88_enum_input (core,i); |
| 1291 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1292 | |
| 1293 | static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) |
| 1294 | { |
| 1295 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1296 | |
| 1297 | *i = core->input; |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static int vidioc_s_input (struct file *file, void *priv, unsigned int i) |
| 1302 | { |
| 1303 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1304 | |
| 1305 | if (i >= 4) |
| 1306 | return -EINVAL; |
| 1307 | |
| 1308 | mutex_lock(&core->lock); |
| 1309 | cx88_newstation(core); |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 1310 | cx88_video_mux(core,i); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1311 | mutex_unlock(&core->lock); |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | static int vidioc_queryctrl (struct file *file, void *priv, |
| 1318 | struct v4l2_queryctrl *qctrl) |
| 1319 | { |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 1320 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1321 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1322 | qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id); |
| 1323 | if (unlikely(qctrl->id == 0)) |
| 1324 | return -EINVAL; |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 1325 | return cx8800_ctrl_query(core, qctrl); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1326 | } |
| 1327 | |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1328 | static int vidioc_g_ctrl (struct file *file, void *priv, |
| 1329 | struct v4l2_control *ctl) |
| 1330 | { |
| 1331 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1332 | return |
| 1333 | cx88_get_control(core,ctl); |
| 1334 | } |
| 1335 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1336 | static int vidioc_s_ctrl (struct file *file, void *priv, |
| 1337 | struct v4l2_control *ctl) |
| 1338 | { |
| 1339 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1340 | return |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1341 | cx88_set_control(core,ctl); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static int vidioc_g_tuner (struct file *file, void *priv, |
| 1345 | struct v4l2_tuner *t) |
| 1346 | { |
| 1347 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1348 | u32 reg; |
| 1349 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1350 | if (unlikely(UNSET == core->board.tuner_type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1351 | return -EINVAL; |
Mauro Carvalho Chehab | 243d8c0 | 2007-01-20 13:58:36 -0300 | [diff] [blame] | 1352 | if (0 != t->index) |
| 1353 | return -EINVAL; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1354 | |
| 1355 | strcpy(t->name, "Television"); |
| 1356 | t->type = V4L2_TUNER_ANALOG_TV; |
| 1357 | t->capability = V4L2_TUNER_CAP_NORM; |
| 1358 | t->rangehigh = 0xffffffffUL; |
| 1359 | |
| 1360 | cx88_get_stereo(core ,t); |
| 1361 | reg = cx_read(MO_DEVICE_STATUS); |
| 1362 | t->signal = (reg & (1<<5)) ? 0xffff : 0x0000; |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | static int vidioc_s_tuner (struct file *file, void *priv, |
| 1367 | struct v4l2_tuner *t) |
| 1368 | { |
| 1369 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1370 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1371 | if (UNSET == core->board.tuner_type) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1372 | return -EINVAL; |
| 1373 | if (0 != t->index) |
| 1374 | return -EINVAL; |
| 1375 | |
| 1376 | cx88_set_stereo(core, t->audmode, 1); |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static int vidioc_g_frequency (struct file *file, void *priv, |
| 1381 | struct v4l2_frequency *f) |
| 1382 | { |
| 1383 | struct cx8800_fh *fh = priv; |
| 1384 | struct cx88_core *core = fh->dev->core; |
| 1385 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1386 | if (unlikely(UNSET == core->board.tuner_type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1387 | return -EINVAL; |
| 1388 | |
| 1389 | /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */ |
| 1390 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1391 | f->frequency = core->freq; |
| 1392 | |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1393 | call_all(core, tuner, g_frequency, f); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1398 | int cx88_set_freq (struct cx88_core *core, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1399 | struct v4l2_frequency *f) |
| 1400 | { |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1401 | if (unlikely(UNSET == core->board.tuner_type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1402 | return -EINVAL; |
| 1403 | if (unlikely(f->tuner != 0)) |
| 1404 | return -EINVAL; |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1405 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1406 | mutex_lock(&core->lock); |
| 1407 | core->freq = f->frequency; |
| 1408 | cx88_newstation(core); |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1409 | call_all(core, tuner, s_frequency, f); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1410 | |
| 1411 | /* When changing channels it is required to reset TVAUDIO */ |
| 1412 | msleep (10); |
| 1413 | cx88_set_tvaudio(core); |
| 1414 | |
| 1415 | mutex_unlock(&core->lock); |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1416 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1417 | return 0; |
| 1418 | } |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1419 | EXPORT_SYMBOL(cx88_set_freq); |
| 1420 | |
| 1421 | static int vidioc_s_frequency (struct file *file, void *priv, |
| 1422 | struct v4l2_frequency *f) |
| 1423 | { |
| 1424 | struct cx8800_fh *fh = priv; |
| 1425 | struct cx88_core *core = fh->dev->core; |
| 1426 | |
| 1427 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1428 | return -EINVAL; |
| 1429 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
| 1430 | return -EINVAL; |
| 1431 | |
| 1432 | return |
| 1433 | cx88_set_freq (core,f); |
| 1434 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1435 | |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1436 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1437 | static int vidioc_g_register (struct file *file, void *fh, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1438 | struct v4l2_dbg_register *reg) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1439 | { |
| 1440 | struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; |
| 1441 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1442 | if (!v4l2_chip_match_host(®->match)) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1443 | return -EINVAL; |
| 1444 | /* cx2388x has a 24-bit register space */ |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1445 | reg->val = cx_read(reg->reg & 0xffffff); |
| 1446 | reg->size = 4; |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | static int vidioc_s_register (struct file *file, void *fh, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1451 | struct v4l2_dbg_register *reg) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1452 | { |
| 1453 | struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; |
| 1454 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1455 | if (!v4l2_chip_match_host(®->match)) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1456 | return -EINVAL; |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1457 | cx_write(reg->reg & 0xffffff, reg->val); |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1458 | return 0; |
| 1459 | } |
| 1460 | #endif |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | /* ----------------------------------------------------------- */ |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1463 | /* RADIO ESPECIFIC IOCTLS */ |
| 1464 | /* ----------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1466 | static int radio_querycap (struct file *file, void *priv, |
| 1467 | struct v4l2_capability *cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1469 | struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | struct cx88_core *core = dev->core; |
| 1471 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1472 | strcpy(cap->driver, "cx8800"); |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1473 | strlcpy(cap->card, core->board.name, sizeof(cap->card)); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1474 | sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci)); |
| 1475 | cap->version = CX88_VERSION_CODE; |
| 1476 | cap->capabilities = V4L2_CAP_TUNER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | return 0; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1480 | static int radio_g_tuner (struct file *file, void *priv, |
| 1481 | struct v4l2_tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1483 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1484 | |
| 1485 | if (unlikely(t->index > 0)) |
| 1486 | return -EINVAL; |
| 1487 | |
| 1488 | strcpy(t->name, "Radio"); |
| 1489 | t->type = V4L2_TUNER_RADIO; |
| 1490 | |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1491 | call_all(core, tuner, g_tuner, t); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1492 | return 0; |
| 1493 | } |
| 1494 | |
| 1495 | static int radio_enum_input (struct file *file, void *priv, |
| 1496 | struct v4l2_input *i) |
| 1497 | { |
| 1498 | if (i->index != 0) |
| 1499 | return -EINVAL; |
| 1500 | strcpy(i->name,"Radio"); |
| 1501 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1502 | |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a) |
| 1507 | { |
| 1508 | if (unlikely(a->index)) |
| 1509 | return -EINVAL; |
| 1510 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1511 | strcpy(a->name,"Radio"); |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
| 1515 | /* FIXME: Should add a standard for radio */ |
| 1516 | |
| 1517 | static int radio_s_tuner (struct file *file, void *priv, |
| 1518 | struct v4l2_tuner *t) |
| 1519 | { |
| 1520 | struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; |
| 1521 | |
| 1522 | if (0 != t->index) |
| 1523 | return -EINVAL; |
| 1524 | |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1525 | call_all(core, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static int radio_s_audio (struct file *file, void *fh, |
| 1531 | struct v4l2_audio *a) |
| 1532 | { |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | static int radio_s_input (struct file *file, void *fh, unsigned int i) |
| 1537 | { |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | static int radio_queryctrl (struct file *file, void *priv, |
| 1542 | struct v4l2_queryctrl *c) |
| 1543 | { |
| 1544 | int i; |
| 1545 | |
| 1546 | if (c->id < V4L2_CID_BASE || |
| 1547 | c->id >= V4L2_CID_LASTP1) |
| 1548 | return -EINVAL; |
| 1549 | if (c->id == V4L2_CID_AUDIO_MUTE) { |
| 1550 | for (i = 0; i < CX8800_CTLS; i++) |
| 1551 | if (cx8800_ctls[i].v.id == c->id) |
| 1552 | break; |
| 1553 | *c = cx8800_ctls[i].v; |
| 1554 | } else |
| 1555 | *c = no_ctl; |
| 1556 | return 0; |
| 1557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
| 1559 | /* ----------------------------------------------------------- */ |
| 1560 | |
| 1561 | static void cx8800_vid_timeout(unsigned long data) |
| 1562 | { |
| 1563 | struct cx8800_dev *dev = (struct cx8800_dev*)data; |
| 1564 | struct cx88_core *core = dev->core; |
| 1565 | struct cx88_dmaqueue *q = &dev->vidq; |
| 1566 | struct cx88_buffer *buf; |
| 1567 | unsigned long flags; |
| 1568 | |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1569 | cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
| 1571 | cx_clear(MO_VID_DMACNTRL, 0x11); |
| 1572 | cx_clear(VID_CAPTURE_CONTROL, 0x06); |
| 1573 | |
| 1574 | spin_lock_irqsave(&dev->slock,flags); |
| 1575 | while (!list_empty(&q->active)) { |
| 1576 | buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); |
| 1577 | list_del(&buf->vb.queue); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1578 | buf->vb.state = VIDEOBUF_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | wake_up(&buf->vb.done); |
| 1580 | printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name, |
| 1581 | buf, buf->vb.i, (unsigned long)buf->risc.dma); |
| 1582 | } |
| 1583 | restart_video_queue(dev,q); |
| 1584 | spin_unlock_irqrestore(&dev->slock,flags); |
| 1585 | } |
| 1586 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 1587 | static char *cx88_vid_irqs[32] = { |
| 1588 | "y_risci1", "u_risci1", "v_risci1", "vbi_risc1", |
| 1589 | "y_risci2", "u_risci2", "v_risci2", "vbi_risc2", |
| 1590 | "y_oflow", "u_oflow", "v_oflow", "vbi_oflow", |
| 1591 | "y_sync", "u_sync", "v_sync", "vbi_sync", |
| 1592 | "opc_err", "par_err", "rip_err", "pci_abort", |
| 1593 | }; |
| 1594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | static void cx8800_vid_irq(struct cx8800_dev *dev) |
| 1596 | { |
| 1597 | struct cx88_core *core = dev->core; |
| 1598 | u32 status, mask, count; |
| 1599 | |
| 1600 | status = cx_read(MO_VID_INTSTAT); |
| 1601 | mask = cx_read(MO_VID_INTMSK); |
| 1602 | if (0 == (status & mask)) |
| 1603 | return; |
| 1604 | cx_write(MO_VID_INTSTAT, status); |
| 1605 | if (irq_debug || (status & mask & ~0xff)) |
| 1606 | cx88_print_irqbits(core->name, "irq vid", |
Mauro Carvalho Chehab | 66623a0 | 2007-03-29 08:47:04 -0300 | [diff] [blame] | 1607 | cx88_vid_irqs, ARRAY_SIZE(cx88_vid_irqs), |
| 1608 | status, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
| 1610 | /* risc op code error */ |
| 1611 | if (status & (1 << 16)) { |
| 1612 | printk(KERN_WARNING "%s/0: video risc op code error\n",core->name); |
| 1613 | cx_clear(MO_VID_DMACNTRL, 0x11); |
| 1614 | cx_clear(VID_CAPTURE_CONTROL, 0x06); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1615 | cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /* risc1 y */ |
| 1619 | if (status & 0x01) { |
| 1620 | spin_lock(&dev->slock); |
| 1621 | count = cx_read(MO_VIDY_GPCNT); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1622 | cx88_wakeup(core, &dev->vidq, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | spin_unlock(&dev->slock); |
| 1624 | } |
| 1625 | |
| 1626 | /* risc1 vbi */ |
| 1627 | if (status & 0x08) { |
| 1628 | spin_lock(&dev->slock); |
| 1629 | count = cx_read(MO_VBI_GPCNT); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1630 | cx88_wakeup(core, &dev->vbiq, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | spin_unlock(&dev->slock); |
| 1632 | } |
| 1633 | |
| 1634 | /* risc2 y */ |
| 1635 | if (status & 0x10) { |
| 1636 | dprintk(2,"stopper video\n"); |
| 1637 | spin_lock(&dev->slock); |
| 1638 | restart_video_queue(dev,&dev->vidq); |
| 1639 | spin_unlock(&dev->slock); |
| 1640 | } |
| 1641 | |
| 1642 | /* risc2 vbi */ |
| 1643 | if (status & 0x80) { |
| 1644 | dprintk(2,"stopper vbi\n"); |
| 1645 | spin_lock(&dev->slock); |
| 1646 | cx8800_restart_vbi_queue(dev,&dev->vbiq); |
| 1647 | spin_unlock(&dev->slock); |
| 1648 | } |
| 1649 | } |
| 1650 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1651 | static irqreturn_t cx8800_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | { |
| 1653 | struct cx8800_dev *dev = dev_id; |
| 1654 | struct cx88_core *core = dev->core; |
| 1655 | u32 status; |
| 1656 | int loop, handled = 0; |
| 1657 | |
| 1658 | for (loop = 0; loop < 10; loop++) { |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 1659 | status = cx_read(MO_PCI_INTSTAT) & |
| 1660 | (core->pci_irqmask | PCI_INT_VIDINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | if (0 == status) |
| 1662 | goto out; |
| 1663 | cx_write(MO_PCI_INTSTAT, status); |
| 1664 | handled = 1; |
| 1665 | |
| 1666 | if (status & core->pci_irqmask) |
| 1667 | cx88_core_irq(core,status); |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 1668 | if (status & PCI_INT_VIDINT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | cx8800_vid_irq(dev); |
| 1670 | }; |
| 1671 | if (10 == loop) { |
| 1672 | printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n", |
| 1673 | core->name); |
| 1674 | cx_write(MO_PCI_INTMSK,0); |
| 1675 | } |
| 1676 | |
| 1677 | out: |
| 1678 | return IRQ_RETVAL(handled); |
| 1679 | } |
| 1680 | |
| 1681 | /* ----------------------------------------------------------- */ |
| 1682 | /* exported stuff */ |
| 1683 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1684 | static const struct v4l2_file_operations video_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | { |
| 1686 | .owner = THIS_MODULE, |
| 1687 | .open = video_open, |
| 1688 | .release = video_release, |
| 1689 | .read = video_read, |
| 1690 | .poll = video_poll, |
| 1691 | .mmap = video_mmap, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1692 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | }; |
| 1694 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1695 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1696 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1697 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1698 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1699 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1700 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 1701 | .vidioc_g_fmt_vbi_cap = cx8800_vbi_fmt, |
| 1702 | .vidioc_try_fmt_vbi_cap = cx8800_vbi_fmt, |
| 1703 | .vidioc_s_fmt_vbi_cap = cx8800_vbi_fmt, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1704 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1705 | .vidioc_querybuf = vidioc_querybuf, |
| 1706 | .vidioc_qbuf = vidioc_qbuf, |
| 1707 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1708 | .vidioc_s_std = vidioc_s_std, |
| 1709 | .vidioc_enum_input = vidioc_enum_input, |
| 1710 | .vidioc_g_input = vidioc_g_input, |
| 1711 | .vidioc_s_input = vidioc_s_input, |
| 1712 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1713 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1714 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1715 | .vidioc_streamon = vidioc_streamon, |
| 1716 | .vidioc_streamoff = vidioc_streamoff, |
| 1717 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1718 | .vidiocgmbuf = vidiocgmbuf, |
| 1719 | #endif |
| 1720 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1721 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1722 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1723 | .vidioc_s_frequency = vidioc_s_frequency, |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1724 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1725 | .vidioc_g_register = vidioc_g_register, |
| 1726 | .vidioc_s_register = vidioc_s_register, |
| 1727 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1728 | }; |
| 1729 | |
| 1730 | static struct video_device cx8800_vbi_template; |
| 1731 | |
| 1732 | static struct video_device cx8800_video_template = { |
| 1733 | .name = "cx8800-video", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1734 | .fops = &video_fops, |
| 1735 | .minor = -1, |
| 1736 | .ioctl_ops = &video_ioctl_ops, |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1737 | .tvnorms = CX88_NORMS, |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1738 | .current_norm = V4L2_STD_NTSC_M, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | }; |
| 1740 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1741 | static const struct v4l2_file_operations radio_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | { |
| 1743 | .owner = THIS_MODULE, |
| 1744 | .open = video_open, |
| 1745 | .release = video_release, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1746 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | }; |
| 1748 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1749 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1750 | .vidioc_querycap = radio_querycap, |
| 1751 | .vidioc_g_tuner = radio_g_tuner, |
| 1752 | .vidioc_enum_input = radio_enum_input, |
| 1753 | .vidioc_g_audio = radio_g_audio, |
| 1754 | .vidioc_s_tuner = radio_s_tuner, |
| 1755 | .vidioc_s_audio = radio_s_audio, |
| 1756 | .vidioc_s_input = radio_s_input, |
| 1757 | .vidioc_queryctrl = radio_queryctrl, |
| 1758 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1759 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1760 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1761 | .vidioc_s_frequency = vidioc_s_frequency, |
Trent Piepho | a75d204 | 2007-08-01 00:13:28 -0300 | [diff] [blame] | 1762 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1763 | .vidioc_g_register = vidioc_g_register, |
| 1764 | .vidioc_s_register = vidioc_s_register, |
| 1765 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | }; |
| 1767 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1768 | static struct video_device cx8800_radio_template = { |
| 1769 | .name = "cx8800-radio", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1770 | .fops = &radio_fops, |
| 1771 | .minor = -1, |
| 1772 | .ioctl_ops = &radio_ioctl_ops, |
| 1773 | }; |
| 1774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | /* ----------------------------------------------------------- */ |
| 1776 | |
| 1777 | static void cx8800_unregister_video(struct cx8800_dev *dev) |
| 1778 | { |
| 1779 | if (dev->radio_dev) { |
| 1780 | if (-1 != dev->radio_dev->minor) |
| 1781 | video_unregister_device(dev->radio_dev); |
| 1782 | else |
| 1783 | video_device_release(dev->radio_dev); |
| 1784 | dev->radio_dev = NULL; |
| 1785 | } |
| 1786 | if (dev->vbi_dev) { |
| 1787 | if (-1 != dev->vbi_dev->minor) |
| 1788 | video_unregister_device(dev->vbi_dev); |
| 1789 | else |
| 1790 | video_device_release(dev->vbi_dev); |
| 1791 | dev->vbi_dev = NULL; |
| 1792 | } |
| 1793 | if (dev->video_dev) { |
| 1794 | if (-1 != dev->video_dev->minor) |
| 1795 | video_unregister_device(dev->video_dev); |
| 1796 | else |
| 1797 | video_device_release(dev->video_dev); |
| 1798 | dev->video_dev = NULL; |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | static int __devinit cx8800_initdev(struct pci_dev *pci_dev, |
| 1803 | const struct pci_device_id *pci_id) |
| 1804 | { |
| 1805 | struct cx8800_dev *dev; |
| 1806 | struct cx88_core *core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | int err; |
| 1809 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1810 | dev = kzalloc(sizeof(*dev),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | if (NULL == dev) |
| 1812 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
| 1814 | /* pci init */ |
| 1815 | dev->pci = pci_dev; |
| 1816 | if (pci_enable_device(pci_dev)) { |
| 1817 | err = -EIO; |
| 1818 | goto fail_free; |
| 1819 | } |
| 1820 | core = cx88_core_get(dev->pci); |
| 1821 | if (NULL == core) { |
| 1822 | err = -EINVAL; |
| 1823 | goto fail_free; |
| 1824 | } |
| 1825 | dev->core = core; |
| 1826 | |
| 1827 | /* print pci info */ |
| 1828 | pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1829 | pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat); |
| 1830 | printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, " |
Greg Kroah-Hartman | 228aef6 | 2006-06-12 15:16:52 -0700 | [diff] [blame] | 1831 | "latency: %d, mmio: 0x%llx\n", core->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | pci_name(pci_dev), dev->pci_rev, pci_dev->irq, |
Greg Kroah-Hartman | 228aef6 | 2006-06-12 15:16:52 -0700 | [diff] [blame] | 1833 | dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | |
| 1835 | pci_set_master(pci_dev); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1836 | if (!pci_dma_supported(pci_dev,DMA_BIT_MASK(32))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name); |
| 1838 | err = -EIO; |
| 1839 | goto fail_core; |
| 1840 | } |
| 1841 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1842 | /* Initialize VBI template */ |
| 1843 | memcpy( &cx8800_vbi_template, &cx8800_video_template, |
| 1844 | sizeof(cx8800_vbi_template) ); |
| 1845 | strcpy(cx8800_vbi_template.name,"cx8800-vbi"); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | /* initialize driver struct */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | spin_lock_init(&dev->slock); |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1849 | core->tvnorm = cx8800_video_template.current_norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | |
| 1851 | /* init video dma queues */ |
| 1852 | INIT_LIST_HEAD(&dev->vidq.active); |
| 1853 | INIT_LIST_HEAD(&dev->vidq.queued); |
| 1854 | dev->vidq.timeout.function = cx8800_vid_timeout; |
| 1855 | dev->vidq.timeout.data = (unsigned long)dev; |
| 1856 | init_timer(&dev->vidq.timeout); |
| 1857 | cx88_risc_stopper(dev->pci,&dev->vidq.stopper, |
| 1858 | MO_VID_DMACNTRL,0x11,0x00); |
| 1859 | |
| 1860 | /* init vbi dma queues */ |
| 1861 | INIT_LIST_HEAD(&dev->vbiq.active); |
| 1862 | INIT_LIST_HEAD(&dev->vbiq.queued); |
| 1863 | dev->vbiq.timeout.function = cx8800_vbi_timeout; |
| 1864 | dev->vbiq.timeout.data = (unsigned long)dev; |
| 1865 | init_timer(&dev->vbiq.timeout); |
| 1866 | cx88_risc_stopper(dev->pci,&dev->vbiq.stopper, |
| 1867 | MO_VID_DMACNTRL,0x88,0x00); |
| 1868 | |
| 1869 | /* get irq */ |
| 1870 | err = request_irq(pci_dev->irq, cx8800_irq, |
Thomas Gleixner | 8076fe3 | 2006-07-01 19:29:37 -0700 | [diff] [blame] | 1871 | IRQF_SHARED | IRQF_DISABLED, core->name, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1873 | printk(KERN_ERR "%s/0: can't get IRQ %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | core->name,pci_dev->irq); |
| 1875 | goto fail_core; |
| 1876 | } |
| 1877 | cx_set(MO_PCI_INTMSK, core->pci_irqmask); |
| 1878 | |
| 1879 | /* load and configure helper modules */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1880 | |
Hans Verkuil | 38f9d30 | 2008-07-23 05:09:15 -0300 | [diff] [blame] | 1881 | if (core->board.audio_chip == V4L2_IDENT_WM8775) |
Hans Verkuil | e6574f2 | 2009-04-01 03:57:53 -0300 | [diff] [blame] | 1882 | v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1883 | "wm8775", "wm8775", 0x36 >> 1); |
| 1884 | |
| 1885 | if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) { |
| 1886 | /* This probes for a tda9874 as is used on some |
| 1887 | Pixelview Ultra boards. */ |
Hans Verkuil | 1792f68 | 2009-03-30 11:47:55 -0300 | [diff] [blame] | 1888 | v4l2_i2c_new_probed_subdev_addr(&core->v4l2_dev, |
| 1889 | &core->i2c_adap, |
| 1890 | "tvaudio", "tvaudio", 0xb0 >> 1); |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1891 | } |
Steven Toth | 3057906 | 2006-09-25 12:43:42 -0300 | [diff] [blame] | 1892 | |
Michael Krufky | 6fcecce | 2007-08-24 01:32:31 -0300 | [diff] [blame] | 1893 | switch (core->boardnr) { |
| 1894 | case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD: |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1895 | case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: { |
| 1896 | static struct i2c_board_info rtc_info = { |
| 1897 | I2C_BOARD_INFO("isl1208", 0x6f) |
| 1898 | }; |
| 1899 | |
Michael Krufky | 6fcecce | 2007-08-24 01:32:31 -0300 | [diff] [blame] | 1900 | request_module("rtc-isl1208"); |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1901 | core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info); |
| 1902 | } |
Michael Krufky | 8efd2e2 | 2008-04-22 14:45:14 -0300 | [diff] [blame] | 1903 | /* break intentionally omitted */ |
| 1904 | case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO: |
| 1905 | request_module("ir-kbd-i2c"); |
Michael Krufky | 6fcecce | 2007-08-24 01:32:31 -0300 | [diff] [blame] | 1906 | } |
| 1907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | /* register v4l devices */ |
| 1909 | dev->video_dev = cx88_vdev_init(core,dev->pci, |
| 1910 | &cx8800_video_template,"video"); |
| 1911 | err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, |
| 1912 | video_nr[core->nr]); |
| 1913 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1914 | printk(KERN_ERR "%s/0: can't register video device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | core->name); |
| 1916 | goto fail_unreg; |
| 1917 | } |
| 1918 | printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n", |
Hans Verkuil | c6330fb | 2008-10-19 18:54:26 -0300 | [diff] [blame] | 1919 | core->name, dev->video_dev->num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
| 1921 | dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi"); |
| 1922 | err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, |
| 1923 | vbi_nr[core->nr]); |
| 1924 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1925 | printk(KERN_ERR "%s/0: can't register vbi device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | core->name); |
| 1927 | goto fail_unreg; |
| 1928 | } |
| 1929 | printk(KERN_INFO "%s/0: registered device vbi%d\n", |
Hans Verkuil | c6330fb | 2008-10-19 18:54:26 -0300 | [diff] [blame] | 1930 | core->name, dev->vbi_dev->num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1932 | if (core->board.radio.type == CX88_RADIO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | dev->radio_dev = cx88_vdev_init(core,dev->pci, |
| 1934 | &cx8800_radio_template,"radio"); |
| 1935 | err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, |
| 1936 | radio_nr[core->nr]); |
| 1937 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1938 | printk(KERN_ERR "%s/0: can't register radio device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | core->name); |
| 1940 | goto fail_unreg; |
| 1941 | } |
| 1942 | printk(KERN_INFO "%s/0: registered device radio%d\n", |
Hans Verkuil | c6330fb | 2008-10-19 18:54:26 -0300 | [diff] [blame] | 1943 | core->name, dev->radio_dev->num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | /* everything worked */ |
| 1947 | list_add_tail(&dev->devlist,&cx8800_devlist); |
| 1948 | pci_set_drvdata(pci_dev,dev); |
| 1949 | |
| 1950 | /* initial device configuration */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1951 | mutex_lock(&core->lock); |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1952 | cx88_set_tvnorm(core,core->tvnorm); |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 1953 | init_controls(core); |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 1954 | cx88_video_mux(core,0); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1955 | mutex_unlock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
| 1957 | /* start tvaudio thread */ |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1958 | if (core->board.tuner_type != TUNER_ABSENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio"); |
Cyrill Gorcunov | 32b78de | 2007-07-19 11:44:11 -0300 | [diff] [blame] | 1960 | if (IS_ERR(core->kthread)) { |
| 1961 | err = PTR_ERR(core->kthread); |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1962 | printk(KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n", |
| 1963 | core->name, err); |
Cyrill Gorcunov | 32b78de | 2007-07-19 11:44:11 -0300 | [diff] [blame] | 1964 | } |
| 1965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | return 0; |
| 1967 | |
| 1968 | fail_unreg: |
| 1969 | cx8800_unregister_video(dev); |
| 1970 | free_irq(pci_dev->irq, dev); |
| 1971 | fail_core: |
| 1972 | cx88_core_put(core,dev->pci); |
| 1973 | fail_free: |
| 1974 | kfree(dev); |
| 1975 | return err; |
| 1976 | } |
| 1977 | |
| 1978 | static void __devexit cx8800_finidev(struct pci_dev *pci_dev) |
| 1979 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1980 | struct cx8800_dev *dev = pci_get_drvdata(pci_dev); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1981 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | |
| 1983 | /* stop thread */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1984 | if (core->kthread) { |
| 1985 | kthread_stop(core->kthread); |
| 1986 | core->kthread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Marton Balint | b12203d | 2008-03-26 02:07:35 -0300 | [diff] [blame] | 1989 | if (core->ir) |
| 1990 | cx88_ir_stop(core, core->ir); |
| 1991 | |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1992 | cx88_shutdown(core); /* FIXME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | pci_disable_device(pci_dev); |
| 1994 | |
| 1995 | /* unregister stuff */ |
| 1996 | |
| 1997 | free_irq(pci_dev->irq, dev); |
| 1998 | cx8800_unregister_video(dev); |
| 1999 | pci_set_drvdata(pci_dev, NULL); |
| 2000 | |
| 2001 | /* free memory */ |
| 2002 | btcx_riscmem_free(dev->pci,&dev->vidq.stopper); |
| 2003 | list_del(&dev->devlist); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 2004 | cx88_core_put(core,dev->pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | kfree(dev); |
| 2006 | } |
| 2007 | |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 2008 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state) |
| 2010 | { |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 2011 | struct cx8800_dev *dev = pci_get_drvdata(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | struct cx88_core *core = dev->core; |
| 2013 | |
| 2014 | /* stop video+vbi capture */ |
| 2015 | spin_lock(&dev->slock); |
| 2016 | if (!list_empty(&dev->vidq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2017 | printk("%s/0: suspend video\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | stop_video_dma(dev); |
| 2019 | del_timer(&dev->vidq.timeout); |
| 2020 | } |
| 2021 | if (!list_empty(&dev->vbiq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2022 | printk("%s/0: suspend vbi\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | cx8800_stop_vbi_dma(dev); |
| 2024 | del_timer(&dev->vbiq.timeout); |
| 2025 | } |
| 2026 | spin_unlock(&dev->slock); |
| 2027 | |
Mauro Carvalho Chehab | 13595a5 | 2007-10-01 08:51:39 -0300 | [diff] [blame] | 2028 | if (core->ir) |
| 2029 | cx88_ir_stop(core, core->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | /* FIXME -- shutdown device */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 2031 | cx88_shutdown(core); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | |
| 2033 | pci_save_state(pci_dev); |
| 2034 | if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { |
| 2035 | pci_disable_device(pci_dev); |
| 2036 | dev->state.disabled = 1; |
| 2037 | } |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
| 2041 | static int cx8800_resume(struct pci_dev *pci_dev) |
| 2042 | { |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 2043 | struct cx8800_dev *dev = pci_get_drvdata(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 2045 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
| 2047 | if (dev->state.disabled) { |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 2048 | err=pci_enable_device(pci_dev); |
| 2049 | if (err) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2050 | printk(KERN_ERR "%s/0: can't enable device\n", |
| 2051 | core->name); |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 2052 | return err; |
| 2053 | } |
| 2054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | dev->state.disabled = 0; |
| 2056 | } |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 2057 | err= pci_set_power_state(pci_dev, PCI_D0); |
| 2058 | if (err) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2059 | printk(KERN_ERR "%s/0: can't set power state\n", core->name); |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 2060 | pci_disable_device(pci_dev); |
| 2061 | dev->state.disabled = 1; |
| 2062 | |
| 2063 | return err; |
| 2064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | pci_restore_state(pci_dev); |
| 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | /* FIXME: re-initialize hardware */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 2068 | cx88_reset(core); |
Mauro Carvalho Chehab | 13595a5 | 2007-10-01 08:51:39 -0300 | [diff] [blame] | 2069 | if (core->ir) |
| 2070 | cx88_ir_start(core, core->ir); |
| 2071 | |
| 2072 | cx_set(MO_PCI_INTMSK, core->pci_irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | |
| 2074 | /* restart video+vbi capture */ |
| 2075 | spin_lock(&dev->slock); |
| 2076 | if (!list_empty(&dev->vidq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2077 | printk("%s/0: resume video\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | restart_video_queue(dev,&dev->vidq); |
| 2079 | } |
| 2080 | if (!list_empty(&dev->vbiq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2081 | printk("%s/0: resume vbi\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | cx8800_restart_vbi_queue(dev,&dev->vbiq); |
| 2083 | } |
| 2084 | spin_unlock(&dev->slock); |
| 2085 | |
| 2086 | return 0; |
| 2087 | } |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 2088 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | |
| 2090 | /* ----------------------------------------------------------- */ |
| 2091 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 2092 | static struct pci_device_id cx8800_pci_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | { |
| 2094 | .vendor = 0x14f1, |
| 2095 | .device = 0x8800, |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 2096 | .subvendor = PCI_ANY_ID, |
| 2097 | .subdevice = PCI_ANY_ID, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | },{ |
| 2099 | /* --- end of list --- */ |
| 2100 | } |
| 2101 | }; |
| 2102 | MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl); |
| 2103 | |
| 2104 | static struct pci_driver cx8800_pci_driver = { |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 2105 | .name = "cx8800", |
| 2106 | .id_table = cx8800_pci_tbl, |
| 2107 | .probe = cx8800_initdev, |
| 2108 | .remove = __devexit_p(cx8800_finidev), |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 2109 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | .suspend = cx8800_suspend, |
| 2111 | .resume = cx8800_resume, |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 2112 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | }; |
| 2114 | |
| 2115 | static int cx8800_init(void) |
| 2116 | { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 2117 | printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %d.%d.%d loaded\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | (CX88_VERSION_CODE >> 16) & 0xff, |
| 2119 | (CX88_VERSION_CODE >> 8) & 0xff, |
| 2120 | CX88_VERSION_CODE & 0xff); |
| 2121 | #ifdef SNAPSHOT |
| 2122 | printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n", |
| 2123 | SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100); |
| 2124 | #endif |
| 2125 | return pci_register_driver(&cx8800_pci_driver); |
| 2126 | } |
| 2127 | |
| 2128 | static void cx8800_fini(void) |
| 2129 | { |
| 2130 | pci_unregister_driver(&cx8800_pci_driver); |
| 2131 | } |
| 2132 | |
| 2133 | module_init(cx8800_init); |
| 2134 | module_exit(cx8800_fini); |
| 2135 | |
| 2136 | /* ----------------------------------------------------------- */ |
| 2137 | /* |
| 2138 | * Local variables: |
| 2139 | * c-basic-offset: 8 |
| 2140 | * End: |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 2141 | * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | */ |