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