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