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