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