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