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