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> |
Hans Verkuil | 1a3c60a | 2012-05-11 11:25:03 -0300 | [diff] [blame] | 43 | #include <media/v4l2-event.h> |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 44 | #include <media/i2c/wm8775.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards"); |
| 47 | MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); |
| 48 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 49 | MODULE_VERSION(CX88_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* ------------------------------------------------------------------ */ |
| 52 | |
| 53 | static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; |
| 54 | static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; |
| 55 | static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; |
| 56 | |
| 57 | module_param_array(video_nr, int, NULL, 0444); |
| 58 | module_param_array(vbi_nr, int, NULL, 0444); |
| 59 | module_param_array(radio_nr, int, NULL, 0444); |
| 60 | |
| 61 | MODULE_PARM_DESC(video_nr,"video device numbers"); |
| 62 | MODULE_PARM_DESC(vbi_nr,"vbi device numbers"); |
| 63 | MODULE_PARM_DESC(radio_nr,"radio device numbers"); |
| 64 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 65 | static unsigned int video_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | module_param(video_debug,int,0644); |
| 67 | MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); |
| 68 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 69 | static unsigned int irq_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | module_param(irq_debug,int,0644); |
| 71 | MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]"); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define dprintk(level,fmt, arg...) if (video_debug >= level) \ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 74 | printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* ------------------------------------------------------------------- */ |
| 77 | /* static data */ |
| 78 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 79 | static const struct cx8800_fmt formats[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | .name = "8 bpp, gray", |
| 82 | .fourcc = V4L2_PIX_FMT_GREY, |
| 83 | .cxformat = ColorFormatY8, |
| 84 | .depth = 8, |
| 85 | .flags = FORMAT_FLAGS_PACKED, |
| 86 | },{ |
| 87 | .name = "15 bpp RGB, le", |
| 88 | .fourcc = V4L2_PIX_FMT_RGB555, |
| 89 | .cxformat = ColorFormatRGB15, |
| 90 | .depth = 16, |
| 91 | .flags = FORMAT_FLAGS_PACKED, |
| 92 | },{ |
| 93 | .name = "15 bpp RGB, be", |
| 94 | .fourcc = V4L2_PIX_FMT_RGB555X, |
| 95 | .cxformat = ColorFormatRGB15 | ColorFormatBSWAP, |
| 96 | .depth = 16, |
| 97 | .flags = FORMAT_FLAGS_PACKED, |
| 98 | },{ |
| 99 | .name = "16 bpp RGB, le", |
| 100 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 101 | .cxformat = ColorFormatRGB16, |
| 102 | .depth = 16, |
| 103 | .flags = FORMAT_FLAGS_PACKED, |
| 104 | },{ |
| 105 | .name = "16 bpp RGB, be", |
| 106 | .fourcc = V4L2_PIX_FMT_RGB565X, |
| 107 | .cxformat = ColorFormatRGB16 | ColorFormatBSWAP, |
| 108 | .depth = 16, |
| 109 | .flags = FORMAT_FLAGS_PACKED, |
| 110 | },{ |
| 111 | .name = "24 bpp RGB, le", |
| 112 | .fourcc = V4L2_PIX_FMT_BGR24, |
| 113 | .cxformat = ColorFormatRGB24, |
| 114 | .depth = 24, |
| 115 | .flags = FORMAT_FLAGS_PACKED, |
| 116 | },{ |
| 117 | .name = "32 bpp RGB, le", |
| 118 | .fourcc = V4L2_PIX_FMT_BGR32, |
| 119 | .cxformat = ColorFormatRGB32, |
| 120 | .depth = 32, |
| 121 | .flags = FORMAT_FLAGS_PACKED, |
| 122 | },{ |
| 123 | .name = "32 bpp RGB, be", |
| 124 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 125 | .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP, |
| 126 | .depth = 32, |
| 127 | .flags = FORMAT_FLAGS_PACKED, |
| 128 | },{ |
| 129 | .name = "4:2:2, packed, YUYV", |
| 130 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 131 | .cxformat = ColorFormatYUY2, |
| 132 | .depth = 16, |
| 133 | .flags = FORMAT_FLAGS_PACKED, |
| 134 | },{ |
| 135 | .name = "4:2:2, packed, UYVY", |
| 136 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 137 | .cxformat = ColorFormatYUY2 | ColorFormatBSWAP, |
| 138 | .depth = 16, |
| 139 | .flags = FORMAT_FLAGS_PACKED, |
| 140 | }, |
| 141 | }; |
| 142 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 143 | static const struct cx8800_fmt* format_by_fourcc(unsigned int fourcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
| 145 | unsigned int i; |
| 146 | |
| 147 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 148 | if (formats[i].fourcc == fourcc) |
| 149 | return formats+i; |
| 150 | return NULL; |
| 151 | } |
| 152 | |
| 153 | /* ------------------------------------------------------------------- */ |
| 154 | |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 155 | struct cx88_ctrl { |
| 156 | /* control information */ |
| 157 | u32 id; |
| 158 | s32 minimum; |
| 159 | s32 maximum; |
| 160 | u32 step; |
| 161 | s32 default_value; |
| 162 | |
| 163 | /* control register information */ |
| 164 | u32 off; |
| 165 | u32 reg; |
| 166 | u32 sreg; |
| 167 | u32 mask; |
| 168 | u32 shift; |
| 169 | }; |
| 170 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 171 | static const struct cx88_ctrl cx8800_vid_ctls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* --- video --- */ |
| 173 | { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 174 | .id = V4L2_CID_BRIGHTNESS, |
| 175 | .minimum = 0x00, |
| 176 | .maximum = 0xff, |
| 177 | .step = 1, |
| 178 | .default_value = 0x7f, |
| 179 | .off = 128, |
| 180 | .reg = MO_CONTR_BRIGHT, |
| 181 | .mask = 0x00ff, |
| 182 | .shift = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | },{ |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 184 | .id = V4L2_CID_CONTRAST, |
| 185 | .minimum = 0, |
| 186 | .maximum = 0xff, |
| 187 | .step = 1, |
| 188 | .default_value = 0x3f, |
| 189 | .off = 0, |
| 190 | .reg = MO_CONTR_BRIGHT, |
| 191 | .mask = 0xff00, |
| 192 | .shift = 8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | },{ |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 194 | .id = V4L2_CID_HUE, |
| 195 | .minimum = 0, |
| 196 | .maximum = 0xff, |
| 197 | .step = 1, |
| 198 | .default_value = 0x7f, |
| 199 | .off = 128, |
| 200 | .reg = MO_HUE, |
| 201 | .mask = 0x00ff, |
| 202 | .shift = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | },{ |
| 204 | /* strictly, this only describes only U saturation. |
| 205 | * V saturation is handled specially through code. |
| 206 | */ |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 207 | .id = V4L2_CID_SATURATION, |
| 208 | .minimum = 0, |
| 209 | .maximum = 0xff, |
| 210 | .step = 1, |
| 211 | .default_value = 0x7f, |
| 212 | .off = 0, |
| 213 | .reg = MO_UV_SATURATION, |
| 214 | .mask = 0x00ff, |
| 215 | .shift = 0, |
istvan_v@mailbox.hu | eea16e3 | 2011-07-11 11:02:19 -0300 | [diff] [blame] | 216 | }, { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 217 | .id = V4L2_CID_SHARPNESS, |
| 218 | .minimum = 0, |
| 219 | .maximum = 4, |
| 220 | .step = 1, |
| 221 | .default_value = 0x0, |
| 222 | .off = 0, |
istvan_v@mailbox.hu | eea16e3 | 2011-07-11 11:02:19 -0300 | [diff] [blame] | 223 | /* NOTE: the value is converted and written to both even |
| 224 | and odd registers in the code */ |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 225 | .reg = MO_FILTER_ODD, |
| 226 | .mask = 7 << 7, |
| 227 | .shift = 7, |
istvan_v@mailbox.hu | eea16e3 | 2011-07-11 11:02:19 -0300 | [diff] [blame] | 228 | }, { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 229 | .id = V4L2_CID_CHROMA_AGC, |
| 230 | .minimum = 0, |
| 231 | .maximum = 1, |
| 232 | .default_value = 0x1, |
| 233 | .reg = MO_INPUT_FORMAT, |
| 234 | .mask = 1 << 10, |
| 235 | .shift = 10, |
Frej Drejhammar | 6d04203 | 2008-03-23 22:43:21 -0300 | [diff] [blame] | 236 | }, { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 237 | .id = V4L2_CID_COLOR_KILLER, |
| 238 | .minimum = 0, |
| 239 | .maximum = 1, |
| 240 | .default_value = 0x1, |
| 241 | .reg = MO_INPUT_FORMAT, |
| 242 | .mask = 1 << 9, |
| 243 | .shift = 9, |
Frej Drejhammar | 1b879c4 | 2008-03-23 22:43:24 -0300 | [diff] [blame] | 244 | }, { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 245 | .id = V4L2_CID_BAND_STOP_FILTER, |
| 246 | .minimum = 0, |
| 247 | .maximum = 1, |
| 248 | .step = 1, |
| 249 | .default_value = 0x0, |
| 250 | .off = 0, |
| 251 | .reg = MO_HTOTAL, |
| 252 | .mask = 3 << 11, |
| 253 | .shift = 11, |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 254 | } |
| 255 | }; |
| 256 | |
| 257 | static const struct cx88_ctrl cx8800_aud_ctls[] = { |
| 258 | { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 259 | /* --- audio --- */ |
| 260 | .id = V4L2_CID_AUDIO_MUTE, |
| 261 | .minimum = 0, |
| 262 | .maximum = 1, |
| 263 | .default_value = 1, |
| 264 | .reg = AUD_VOL_CTL, |
| 265 | .sreg = SHADOW_AUD_VOL_CTL, |
| 266 | .mask = (1 << 6), |
| 267 | .shift = 6, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | },{ |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 269 | .id = V4L2_CID_AUDIO_VOLUME, |
| 270 | .minimum = 0, |
| 271 | .maximum = 0x3f, |
| 272 | .step = 1, |
| 273 | .default_value = 0x3f, |
| 274 | .reg = AUD_VOL_CTL, |
| 275 | .sreg = SHADOW_AUD_VOL_CTL, |
| 276 | .mask = 0x3f, |
| 277 | .shift = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | },{ |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 279 | .id = V4L2_CID_AUDIO_BALANCE, |
| 280 | .minimum = 0, |
| 281 | .maximum = 0x7f, |
| 282 | .step = 1, |
| 283 | .default_value = 0x40, |
| 284 | .reg = AUD_BAL_CTL, |
| 285 | .sreg = SHADOW_AUD_BAL_CTL, |
| 286 | .mask = 0x7f, |
| 287 | .shift = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | }; |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 290 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 291 | enum { |
| 292 | CX8800_VID_CTLS = ARRAY_SIZE(cx8800_vid_ctls), |
| 293 | CX8800_AUD_CTLS = ARRAY_SIZE(cx8800_aud_ctls), |
| 294 | }; |
Michael Krufky | 38a2713 | 2006-06-26 23:42:39 -0300 | [diff] [blame] | 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* ------------------------------------------------------------------ */ |
| 297 | |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 298 | int cx88_video_mux(struct cx88_core *core, unsigned int input) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 300 | /* struct cx88_core *core = dev->core; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | 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] | 303 | input, INPUT(input).vmux, |
| 304 | INPUT(input).gpio0,INPUT(input).gpio1, |
| 305 | INPUT(input).gpio2,INPUT(input).gpio3); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 306 | core->input = input; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 307 | cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input).vmux << 14); |
| 308 | cx_write(MO_GP3_IO, INPUT(input).gpio3); |
| 309 | cx_write(MO_GP0_IO, INPUT(input).gpio0); |
| 310 | cx_write(MO_GP1_IO, INPUT(input).gpio1); |
| 311 | cx_write(MO_GP2_IO, INPUT(input).gpio2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 313 | switch (INPUT(input).type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | case CX88_VMUX_SVIDEO: |
| 315 | cx_set(MO_AFECFG_IO, 0x00000001); |
| 316 | cx_set(MO_INPUT_FORMAT, 0x00010010); |
| 317 | cx_set(MO_FILTER_EVEN, 0x00002020); |
| 318 | cx_set(MO_FILTER_ODD, 0x00002020); |
| 319 | break; |
| 320 | default: |
| 321 | cx_clear(MO_AFECFG_IO, 0x00000001); |
| 322 | cx_clear(MO_INPUT_FORMAT, 0x00010010); |
| 323 | cx_clear(MO_FILTER_EVEN, 0x00002020); |
| 324 | cx_clear(MO_FILTER_ODD, 0x00002020); |
| 325 | break; |
| 326 | } |
Michael Krufky | f24546a | 2006-10-16 16:51:11 -0300 | [diff] [blame] | 327 | |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 328 | /* if there are audioroutes defined, we have an external |
| 329 | ADC to deal with audio */ |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 330 | if (INPUT(input).audioroute) { |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 331 | /* The wm8775 module has the "2" route hardwired into |
| 332 | the initialization. Some boards may use different |
| 333 | routes for different inputs. HVR-1300 surely does */ |
Hans Verkuil | 609c4c1 | 2013-05-29 10:44:22 -0300 | [diff] [blame] | 334 | if (core->sd_wm8775) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 335 | call_all(core, audio, s_routing, |
istvan_v@mailbox.hu | 6e1f4df | 2010-03-27 09:31:32 -0300 | [diff] [blame] | 336 | INPUT(input).audioroute, 0, 0); |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 337 | } |
Darron Broad | 430189d | 2008-10-15 14:18:42 -0300 | [diff] [blame] | 338 | /* cx2388's C-ADC is connected to the tuner only. |
| 339 | When used with S-Video, that ADC is busy dealing with |
| 340 | chroma, so an external must be used for baseband audio */ |
istvan_v@mailbox.hu | 6e1f4df | 2010-03-27 09:31:32 -0300 | [diff] [blame] | 341 | if (INPUT(input).type != CX88_VMUX_TELEVISION && |
| 342 | INPUT(input).type != CX88_VMUX_CABLE) { |
Darron Broad | 430189d | 2008-10-15 14:18:42 -0300 | [diff] [blame] | 343 | /* "I2S ADC mode" */ |
| 344 | core->tvaudio = WW_I2SADC; |
| 345 | cx88_set_tvaudio(core); |
| 346 | } else { |
| 347 | /* Normal mode */ |
| 348 | cx_write(AUD_I2SCNTL, 0x0); |
| 349 | cx_clear(AUD_CTL, EN_I2SIN_ENABLE); |
| 350 | } |
Michael Krufky | f24546a | 2006-10-16 16:51:11 -0300 | [diff] [blame] | 351 | } |
Ricardo Cerqueira | 66e6fbd | 2007-10-16 20:52:08 -0300 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return 0; |
| 354 | } |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 355 | EXPORT_SYMBOL(cx88_video_mux); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* ------------------------------------------------------------------ */ |
| 358 | |
| 359 | static int start_video_dma(struct cx8800_dev *dev, |
| 360 | struct cx88_dmaqueue *q, |
| 361 | struct cx88_buffer *buf) |
| 362 | { |
| 363 | struct cx88_core *core = dev->core; |
| 364 | |
| 365 | /* setup fifo + format */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 366 | cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | buf->bpl, buf->risc.dma); |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 368 | cx88_set_scale(core, core->width, core->height, core->field); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 369 | cx_write(MO_COLOR_CTRL, dev->fmt->cxformat | ColorFormatGamma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | /* reset counter */ |
| 372 | cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET); |
Hans Verkuil | 9450684 | 2015-04-03 07:22:40 -0300 | [diff] [blame] | 373 | q->count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
| 375 | /* enable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 376 | cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 377 | |
| 378 | /* Enables corresponding bits at PCI_INT_STAT: |
| 379 | bits 0 to 4: video, audio, transport stream, VIP, Host |
| 380 | bit 7: timer |
| 381 | bits 8 and 9: DMA complete for: SRC, DST |
| 382 | bits 10 and 11: BERR signal asserted for RISC: RD, WR |
| 383 | bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB |
| 384 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | cx_set(MO_VID_INTMSK, 0x0f0011); |
| 386 | |
| 387 | /* enable capture */ |
| 388 | cx_set(VID_CAPTURE_CONTROL,0x06); |
| 389 | |
| 390 | /* start dma */ |
| 391 | cx_set(MO_DEV_CNTRL2, (1<<5)); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 392 | 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] | 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 397 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | static int stop_video_dma(struct cx8800_dev *dev) |
| 399 | { |
| 400 | struct cx88_core *core = dev->core; |
| 401 | |
| 402 | /* stop dma */ |
| 403 | cx_clear(MO_VID_DMACNTRL, 0x11); |
| 404 | |
| 405 | /* disable capture */ |
| 406 | cx_clear(VID_CAPTURE_CONTROL,0x06); |
| 407 | |
| 408 | /* disable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 409 | cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | cx_clear(MO_VID_INTMSK, 0x0f0011); |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static int restart_video_queue(struct cx8800_dev *dev, |
| 415 | struct cx88_dmaqueue *q) |
| 416 | { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 417 | struct cx88_core *core = dev->core; |
Hans Verkuil | 6f11adc | 2014-08-10 11:56:14 -0300 | [diff] [blame] | 418 | struct cx88_buffer *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | if (!list_empty(&q->active)) { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 421 | buf = list_entry(q->active.next, struct cx88_buffer, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | dprintk(2,"restart_queue [%p/%d]: restart dma\n", |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 423 | buf, buf->vb.vb2_buf.index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | start_video_dma(dev, q, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
Hans Verkuil | 6f11adc | 2014-08-10 11:56:14 -0300 | [diff] [blame] | 426 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
Mauro Carvalho Chehab | bc5e66b | 2015-06-10 13:55:35 -0300 | [diff] [blame] | 428 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | /* ------------------------------------------------------------------ */ |
| 431 | |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 432 | static int queue_setup(struct vb2_queue *q, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 433 | unsigned int *num_buffers, unsigned int *num_planes, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 434 | unsigned int sizes[], struct device *alloc_devs[]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 436 | struct cx8800_dev *dev = q->drv_priv; |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 437 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 439 | *num_planes = 1; |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 440 | sizes[0] = (dev->fmt->depth * core->width * core->height) >> 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 444 | static int buffer_prepare(struct vb2_buffer *vb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 446 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 447 | struct cx8800_dev *dev = vb->vb2_queue->drv_priv; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 448 | struct cx88_core *core = dev->core; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 449 | struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb); |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 450 | struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 452 | buf->bpl = core->width * dev->fmt->depth >> 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 454 | if (vb2_plane_size(vb, 0) < core->height * buf->bpl) |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 455 | return -EINVAL; |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 456 | vb2_set_plane_payload(vb, 0, core->height * buf->bpl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 458 | switch (core->field) { |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 459 | case V4L2_FIELD_TOP: |
| 460 | cx88_risc_buffer(dev->pci, &buf->risc, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 461 | sgt->sgl, 0, UNSET, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 462 | buf->bpl, 0, core->height); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 463 | break; |
| 464 | case V4L2_FIELD_BOTTOM: |
| 465 | cx88_risc_buffer(dev->pci, &buf->risc, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 466 | sgt->sgl, UNSET, 0, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 467 | buf->bpl, 0, core->height); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 468 | break; |
| 469 | case V4L2_FIELD_SEQ_TB: |
| 470 | cx88_risc_buffer(dev->pci, &buf->risc, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 471 | sgt->sgl, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 472 | 0, buf->bpl * (core->height >> 1), |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 473 | buf->bpl, 0, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 474 | core->height >> 1); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 475 | break; |
| 476 | case V4L2_FIELD_SEQ_BT: |
| 477 | cx88_risc_buffer(dev->pci, &buf->risc, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 478 | sgt->sgl, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 479 | buf->bpl * (core->height >> 1), 0, |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 480 | buf->bpl, 0, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 481 | core->height >> 1); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 482 | break; |
| 483 | case V4L2_FIELD_INTERLACED: |
| 484 | default: |
| 485 | cx88_risc_buffer(dev->pci, &buf->risc, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 486 | sgt->sgl, 0, buf->bpl, |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 487 | buf->bpl, buf->bpl, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 488 | core->height >> 1); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 489 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 492 | buf, buf->vb.vb2_buf.index, |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 493 | core->width, core->height, dev->fmt->depth, dev->fmt->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | (unsigned long)buf->risc.dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 498 | static void buffer_finish(struct vb2_buffer *vb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 500 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 501 | struct cx8800_dev *dev = vb->vb2_queue->drv_priv; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 502 | struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb); |
Hans Verkuil | 5e7045e | 2014-08-29 04:11:54 -0300 | [diff] [blame] | 503 | struct cx88_riscmem *risc = &buf->risc; |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 504 | |
Hans Verkuil | 5e7045e | 2014-08-29 04:11:54 -0300 | [diff] [blame] | 505 | if (risc->cpu) |
| 506 | pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); |
| 507 | memset(risc, 0, sizeof(*risc)); |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | static void buffer_queue(struct vb2_buffer *vb) |
| 511 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 512 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 513 | struct cx8800_dev *dev = vb->vb2_queue->drv_priv; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 514 | struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | struct cx88_buffer *prev; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 516 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | struct cx88_dmaqueue *q = &dev->vidq; |
| 518 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 519 | /* add jump to start */ |
| 520 | buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 8); |
| 521 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC); |
| 522 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Hans Verkuil | 6f11adc | 2014-08-10 11:56:14 -0300 | [diff] [blame] | 524 | if (list_empty(&q->active)) { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 525 | list_add_tail(&buf->list, &q->active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | dprintk(2,"[%p/%d] buffer_queue - first active\n", |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 527 | buf, buf->vb.vb2_buf.index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | } else { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 530 | buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); |
| 531 | prev = list_entry(q->active.prev, struct cx88_buffer, list); |
| 532 | list_add_tail(&buf->list, &q->active); |
Hans Verkuil | 637bc20 | 2014-08-29 03:46:05 -0300 | [diff] [blame] | 533 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 534 | dprintk(2, "[%p/%d] buffer_queue - append to active\n", |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 535 | buf, buf->vb.vb2_buf.index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 539 | static int start_streaming(struct vb2_queue *q, unsigned int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 541 | struct cx8800_dev *dev = q->drv_priv; |
| 542 | struct cx88_dmaqueue *dmaq = &dev->vidq; |
| 543 | struct cx88_buffer *buf = list_entry(dmaq->active.next, |
| 544 | struct cx88_buffer, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 546 | start_video_dma(dev, dmaq, buf); |
| 547 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 550 | static void stop_streaming(struct vb2_queue *q) |
| 551 | { |
| 552 | struct cx8800_dev *dev = q->drv_priv; |
| 553 | struct cx88_core *core = dev->core; |
| 554 | struct cx88_dmaqueue *dmaq = &dev->vidq; |
| 555 | unsigned long flags; |
| 556 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 557 | cx_clear(MO_VID_DMACNTRL, 0x11); |
| 558 | cx_clear(VID_CAPTURE_CONTROL, 0x06); |
| 559 | spin_lock_irqsave(&dev->slock, flags); |
| 560 | while (!list_empty(&dmaq->active)) { |
| 561 | struct cx88_buffer *buf = list_entry(dmaq->active.next, |
| 562 | struct cx88_buffer, list); |
| 563 | |
| 564 | list_del(&buf->list); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 565 | vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 566 | } |
| 567 | spin_unlock_irqrestore(&dev->slock, flags); |
| 568 | } |
| 569 | |
Julia Lawall | 10accd2 | 2016-09-08 20:59:18 -0300 | [diff] [blame] | 570 | static const struct vb2_ops cx8800_video_qops = { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 571 | .queue_setup = queue_setup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | .buf_prepare = buffer_prepare, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 573 | .buf_finish = buffer_finish, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | .buf_queue = buffer_queue, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 575 | .wait_prepare = vb2_ops_wait_prepare, |
| 576 | .wait_finish = vb2_ops_wait_finish, |
| 577 | .start_streaming = start_streaming, |
| 578 | .stop_streaming = stop_streaming, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | }; |
| 580 | |
| 581 | /* ------------------------------------------------------------------ */ |
| 582 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 583 | static int radio_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 585 | struct cx8800_dev *dev = video_drvdata(file); |
Dan Carpenter | 5401c2d | 2010-10-21 16:21:45 -0300 | [diff] [blame] | 586 | struct cx88_core *core = dev->core; |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 587 | int ret = v4l2_fh_open(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 589 | if (ret) |
| 590 | return ret; |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 591 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 592 | cx_write(MO_GP3_IO, core->board.radio.gpio3); |
| 593 | cx_write(MO_GP0_IO, core->board.radio.gpio0); |
| 594 | cx_write(MO_GP1_IO, core->board.radio.gpio1); |
| 595 | cx_write(MO_GP2_IO, core->board.radio.gpio2); |
| 596 | if (core->board.radio.audioroute) { |
| 597 | if (core->sd_wm8775) { |
| 598 | call_all(core, audio, s_routing, |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 599 | core->board.radio.audioroute, 0, 0); |
Darron Broad | 430189d | 2008-10-15 14:18:42 -0300 | [diff] [blame] | 600 | } |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 601 | /* "I2S ADC mode" */ |
| 602 | core->tvaudio = WW_I2SADC; |
| 603 | cx88_set_tvaudio(core); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } else { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 605 | /* FM Mode */ |
| 606 | core->tvaudio = WW_FM; |
| 607 | cx88_set_tvaudio(core); |
| 608 | cx88_set_stereo(core, V4L2_TUNER_MODE_STEREO, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 610 | call_all(core, tuner, s_radio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /* ------------------------------------------------------------------ */ |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 615 | /* VIDEO CTRL IOCTLS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 617 | static int cx8800_s_vid_ctrl(struct v4l2_ctrl *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 619 | struct cx88_core *core = |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 620 | container_of(ctrl->handler, struct cx88_core, video_hdl); |
| 621 | const struct cx88_ctrl *cc = ctrl->priv; |
| 622 | u32 value, mask; |
| 623 | |
| 624 | mask = cc->mask; |
| 625 | switch (ctrl->id) { |
| 626 | case V4L2_CID_SATURATION: |
| 627 | /* special v_sat handling */ |
| 628 | |
| 629 | value = ((ctrl->val - cc->off) << cc->shift) & cc->mask; |
| 630 | |
| 631 | if (core->tvnorm & V4L2_STD_SECAM) { |
| 632 | /* For SECAM, both U and V sat should be equal */ |
| 633 | value = value << 8 | value; |
| 634 | } else { |
| 635 | /* Keeps U Saturation proportional to V Sat */ |
| 636 | value = (value * 0x5a) / 0x7f << 8 | value; |
| 637 | } |
| 638 | mask = 0xffff; |
| 639 | break; |
| 640 | case V4L2_CID_SHARPNESS: |
| 641 | /* 0b000, 0b100, 0b101, 0b110, or 0b111 */ |
| 642 | value = (ctrl->val < 1 ? 0 : ((ctrl->val + 3) << 7)); |
| 643 | /* needs to be set for both fields */ |
| 644 | cx_andor(MO_FILTER_EVEN, mask, value); |
| 645 | break; |
| 646 | case V4L2_CID_CHROMA_AGC: |
| 647 | value = ((ctrl->val - cc->off) << cc->shift) & cc->mask; |
| 648 | break; |
| 649 | default: |
| 650 | value = ((ctrl->val - cc->off) << cc->shift) & cc->mask; |
| 651 | break; |
| 652 | } |
| 653 | dprintk(1, "set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", |
| 654 | ctrl->id, ctrl->name, ctrl->val, cc->reg, value, |
| 655 | mask, cc->sreg ? " [shadowed]" : ""); |
| 656 | if (cc->sreg) |
| 657 | cx_sandor(cc->sreg, cc->reg, mask, value); |
| 658 | else |
| 659 | cx_andor(cc->reg, mask, value); |
| 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | static int cx8800_s_aud_ctrl(struct v4l2_ctrl *ctrl) |
| 664 | { |
| 665 | struct cx88_core *core = |
| 666 | container_of(ctrl->handler, struct cx88_core, audio_hdl); |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 667 | const struct cx88_ctrl *cc = ctrl->priv; |
Mauro Carvalho Chehab | 70f0004 | 2006-01-09 15:25:26 -0200 | [diff] [blame] | 668 | u32 value,mask; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 669 | |
| 670 | /* Pass changes onto any WM8775 */ |
Hans Verkuil | 609c4c1 | 2013-05-29 10:44:22 -0300 | [diff] [blame] | 671 | if (core->sd_wm8775) { |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 672 | switch (ctrl->id) { |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 673 | case V4L2_CID_AUDIO_MUTE: |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 674 | wm8775_s_ctrl(core, ctrl->id, ctrl->val); |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 675 | break; |
| 676 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 677 | wm8775_s_ctrl(core, ctrl->id, (ctrl->val) ? |
| 678 | (0x90 + ctrl->val) << 8 : 0); |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 679 | break; |
| 680 | case V4L2_CID_AUDIO_BALANCE: |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 681 | wm8775_s_ctrl(core, ctrl->id, ctrl->val << 9); |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 682 | break; |
| 683 | default: |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 684 | break; |
| 685 | } |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 686 | } |
| 687 | |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 688 | mask = cc->mask; |
| 689 | switch (ctrl->id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | case V4L2_CID_AUDIO_BALANCE: |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 691 | value = (ctrl->val < 0x40) ? (0x7f - ctrl->val) : (ctrl->val - 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | break; |
| 693 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 694 | value = 0x3f - (ctrl->val & 0x3f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | default: |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 697 | value = ((ctrl->val - cc->off) << cc->shift) & cc->mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | break; |
| 699 | } |
Ian Pickworth | 6457af5 | 2006-02-27 00:09:45 -0300 | [diff] [blame] | 700 | dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 701 | ctrl->id, ctrl->name, ctrl->val, cc->reg, value, |
| 702 | mask, cc->sreg ? " [shadowed]" : ""); |
| 703 | if (cc->sreg) |
| 704 | cx_sandor(cc->sreg, cc->reg, mask, value); |
| 705 | else |
| 706 | cx_andor(cc->reg, mask, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return 0; |
| 708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
| 710 | /* ------------------------------------------------------------------ */ |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 711 | /* VIDEO IOCTLS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 713 | 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] | 714 | struct v4l2_format *f) |
| 715 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 716 | struct cx8800_dev *dev = video_drvdata(file); |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 717 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 718 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 719 | f->fmt.pix.width = core->width; |
| 720 | f->fmt.pix.height = core->height; |
| 721 | f->fmt.pix.field = core->field; |
Hans Verkuil | c5a8614 | 2012-05-11 10:45:18 -0300 | [diff] [blame] | 722 | f->fmt.pix.pixelformat = dev->fmt->fourcc; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 723 | f->fmt.pix.bytesperline = |
Hans Verkuil | c5a8614 | 2012-05-11 10:45:18 -0300 | [diff] [blame] | 724 | (f->fmt.pix.width * dev->fmt->depth) >> 3; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 725 | f->fmt.pix.sizeimage = |
| 726 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | c5a8614 | 2012-05-11 10:45:18 -0300 | [diff] [blame] | 727 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 731 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | struct v4l2_format *f) |
| 733 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 734 | struct cx8800_dev *dev = video_drvdata(file); |
| 735 | struct cx88_core *core = dev->core; |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 736 | const struct cx8800_fmt *fmt; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 737 | enum v4l2_field field; |
| 738 | unsigned int maxw, maxh; |
| 739 | |
| 740 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 741 | if (NULL == fmt) |
| 742 | return -EINVAL; |
| 743 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 744 | maxw = norm_maxw(core->tvnorm); |
| 745 | maxh = norm_maxh(core->tvnorm); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 746 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 747 | field = f->fmt.pix.field; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 748 | |
| 749 | switch (field) { |
| 750 | case V4L2_FIELD_TOP: |
| 751 | case V4L2_FIELD_BOTTOM: |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 752 | case V4L2_FIELD_INTERLACED: |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 753 | case V4L2_FIELD_SEQ_BT: |
| 754 | case V4L2_FIELD_SEQ_TB: |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 755 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | default: |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 757 | field = (f->fmt.pix.height > maxh / 2) |
| 758 | ? V4L2_FIELD_INTERLACED |
| 759 | : V4L2_FIELD_BOTTOM; |
| 760 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 762 | if (V4L2_FIELD_HAS_T_OR_B(field)) |
| 763 | maxh /= 2; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 764 | |
Trent Piepho | 4b89945 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 765 | v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2, |
| 766 | &f->fmt.pix.height, 32, maxh, 0, 0); |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 767 | f->fmt.pix.field = field; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 768 | f->fmt.pix.bytesperline = |
| 769 | (f->fmt.pix.width * fmt->depth) >> 3; |
| 770 | f->fmt.pix.sizeimage = |
| 771 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | 9450684 | 2015-04-03 07:22:40 -0300 | [diff] [blame] | 772 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 773 | |
| 774 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 777 | 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] | 778 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 780 | struct cx8800_dev *dev = video_drvdata(file); |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 781 | struct cx88_core *core = dev->core; |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 782 | int err = vidioc_try_fmt_vid_cap (file,priv,f); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 783 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 784 | if (0 != err) |
| 785 | return err; |
Hans Verkuil | 078859a | 2014-08-29 06:08:07 -0300 | [diff] [blame] | 786 | if (vb2_is_busy(&dev->vb2_vidq) || vb2_is_busy(&dev->vb2_vbiq)) |
| 787 | return -EBUSY; |
| 788 | if (core->dvbdev && vb2_is_busy(&core->dvbdev->vb2_mpegq)) |
| 789 | return -EBUSY; |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 790 | dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 791 | core->width = f->fmt.pix.width; |
| 792 | core->height = f->fmt.pix.height; |
| 793 | core->field = f->fmt.pix.field; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 794 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Hans Verkuil | 902e197 | 2012-05-09 16:23:07 -0300 | [diff] [blame] | 797 | void cx88_querycap(struct file *file, struct cx88_core *core, |
| 798 | struct v4l2_capability *cap) |
| 799 | { |
| 800 | struct video_device *vdev = video_devdata(file); |
| 801 | |
| 802 | strlcpy(cap->card, core->board.name, sizeof(cap->card)); |
| 803 | cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 804 | if (UNSET != core->board.tuner_type) |
| 805 | cap->device_caps |= V4L2_CAP_TUNER; |
| 806 | switch (vdev->vfl_type) { |
| 807 | case VFL_TYPE_RADIO: |
| 808 | cap->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; |
| 809 | break; |
| 810 | case VFL_TYPE_GRABBER: |
| 811 | cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE; |
| 812 | break; |
| 813 | case VFL_TYPE_VBI: |
| 814 | cap->device_caps |= V4L2_CAP_VBI_CAPTURE; |
| 815 | break; |
| 816 | } |
| 817 | cap->capabilities = cap->device_caps | V4L2_CAP_VIDEO_CAPTURE | |
| 818 | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_DEVICE_CAPS; |
| 819 | if (core->board.radio.type == CX88_RADIO) |
| 820 | cap->capabilities |= V4L2_CAP_RADIO; |
| 821 | } |
| 822 | EXPORT_SYMBOL(cx88_querycap); |
| 823 | |
| 824 | static int vidioc_querycap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 825 | struct v4l2_capability *cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 827 | struct cx8800_dev *dev = video_drvdata(file); |
| 828 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 830 | strcpy(cap->driver, "cx8800"); |
Hans Verkuil | 902e197 | 2012-05-09 16:23:07 -0300 | [diff] [blame] | 831 | sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); |
| 832 | cx88_querycap(file, core, cap); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 833 | return 0; |
| 834 | } |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 835 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 836 | 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] | 837 | struct v4l2_fmtdesc *f) |
| 838 | { |
| 839 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 840 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 842 | strlcpy(f->description,formats[f->index].name,sizeof(f->description)); |
| 843 | f->pixelformat = formats[f->index].fourcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 845 | return 0; |
| 846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Hans Verkuil | 48d6880 | 2012-05-25 12:15:30 -0300 | [diff] [blame] | 848 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm) |
| 849 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 850 | struct cx8800_dev *dev = video_drvdata(file); |
| 851 | struct cx88_core *core = dev->core; |
Hans Verkuil | 48d6880 | 2012-05-25 12:15:30 -0300 | [diff] [blame] | 852 | |
| 853 | *tvnorm = core->tvnorm; |
| 854 | return 0; |
| 855 | } |
| 856 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 857 | 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] | 858 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 859 | struct cx8800_dev *dev = video_drvdata(file); |
| 860 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 861 | |
Hans Verkuil | 078859a | 2014-08-29 06:08:07 -0300 | [diff] [blame] | 862 | return cx88_set_tvnorm(core, tvnorms); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /* only one input in this sample driver */ |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 866 | 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] | 867 | { |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 868 | static const char * const iname[] = { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 869 | [ CX88_VMUX_COMPOSITE1 ] = "Composite1", |
| 870 | [ CX88_VMUX_COMPOSITE2 ] = "Composite2", |
| 871 | [ CX88_VMUX_COMPOSITE3 ] = "Composite3", |
| 872 | [ CX88_VMUX_COMPOSITE4 ] = "Composite4", |
| 873 | [ CX88_VMUX_SVIDEO ] = "S-Video", |
| 874 | [ CX88_VMUX_TELEVISION ] = "Television", |
| 875 | [ CX88_VMUX_CABLE ] = "Cable TV", |
| 876 | [ CX88_VMUX_DVB ] = "DVB", |
| 877 | [ CX88_VMUX_DEBUG ] = "for debug only", |
| 878 | }; |
Trent Piepho | f3334bc | 2009-03-04 01:21:03 -0300 | [diff] [blame] | 879 | unsigned int n = i->index; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 880 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 881 | if (n >= 4) |
| 882 | return -EINVAL; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 883 | if (0 == INPUT(n).type) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 884 | return -EINVAL; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 885 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 886 | strcpy(i->name,iname[INPUT(n).type]); |
| 887 | if ((CX88_VMUX_TELEVISION == INPUT(n).type) || |
Julia Lawall | 473d802 | 2010-08-05 17:22:44 -0300 | [diff] [blame] | 888 | (CX88_VMUX_CABLE == INPUT(n).type)) { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 889 | i->type = V4L2_INPUT_TYPE_TUNER; |
Julia Lawall | 473d802 | 2010-08-05 17:22:44 -0300 | [diff] [blame] | 890 | } |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 891 | i->std = CX88_NORMS; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 892 | return 0; |
| 893 | } |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 894 | EXPORT_SYMBOL(cx88_enum_input); |
| 895 | |
| 896 | static int vidioc_enum_input (struct file *file, void *priv, |
| 897 | struct v4l2_input *i) |
| 898 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 899 | struct cx8800_dev *dev = video_drvdata(file); |
| 900 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 901 | return cx88_enum_input (core,i); |
| 902 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 903 | |
| 904 | static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) |
| 905 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 906 | struct cx8800_dev *dev = video_drvdata(file); |
| 907 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 908 | |
| 909 | *i = core->input; |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | static int vidioc_s_input (struct file *file, void *priv, unsigned int i) |
| 914 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 915 | struct cx8800_dev *dev = video_drvdata(file); |
| 916 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 917 | |
| 918 | if (i >= 4) |
| 919 | return -EINVAL; |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 920 | if (0 == INPUT(i).type) |
| 921 | return -EINVAL; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 922 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 923 | cx88_newstation(core); |
Mauro Carvalho Chehab | e90311a | 2007-01-20 13:58:29 -0300 | [diff] [blame] | 924 | cx88_video_mux(core,i); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 925 | return 0; |
| 926 | } |
| 927 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 928 | static int vidioc_g_tuner (struct file *file, void *priv, |
| 929 | struct v4l2_tuner *t) |
| 930 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 931 | struct cx8800_dev *dev = video_drvdata(file); |
| 932 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 933 | u32 reg; |
| 934 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 935 | if (unlikely(UNSET == core->board.tuner_type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 936 | return -EINVAL; |
Mauro Carvalho Chehab | 243d8c0 | 2007-01-20 13:58:36 -0300 | [diff] [blame] | 937 | if (0 != t->index) |
| 938 | return -EINVAL; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 939 | |
| 940 | strcpy(t->name, "Television"); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 941 | t->capability = V4L2_TUNER_CAP_NORM; |
| 942 | t->rangehigh = 0xffffffffUL; |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 943 | call_all(core, tuner, g_tuner, t); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 944 | |
| 945 | cx88_get_stereo(core ,t); |
| 946 | reg = cx_read(MO_DEVICE_STATUS); |
| 947 | t->signal = (reg & (1<<5)) ? 0xffff : 0x0000; |
| 948 | return 0; |
| 949 | } |
| 950 | |
| 951 | static int vidioc_s_tuner (struct file *file, void *priv, |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 952 | const struct v4l2_tuner *t) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 953 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 954 | struct cx8800_dev *dev = video_drvdata(file); |
| 955 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 956 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 957 | if (UNSET == core->board.tuner_type) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 958 | return -EINVAL; |
| 959 | if (0 != t->index) |
| 960 | return -EINVAL; |
| 961 | |
| 962 | cx88_set_stereo(core, t->audmode, 1); |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | static int vidioc_g_frequency (struct file *file, void *priv, |
| 967 | struct v4l2_frequency *f) |
| 968 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 969 | struct cx8800_dev *dev = video_drvdata(file); |
| 970 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 971 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 972 | if (unlikely(UNSET == core->board.tuner_type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 973 | return -EINVAL; |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 974 | if (f->tuner) |
| 975 | return -EINVAL; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 976 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 977 | f->frequency = core->freq; |
| 978 | |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 979 | call_all(core, tuner, g_frequency, f); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 980 | |
| 981 | return 0; |
| 982 | } |
| 983 | |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 984 | int cx88_set_freq (struct cx88_core *core, |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 985 | const struct v4l2_frequency *f) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 986 | { |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 987 | struct v4l2_frequency new_freq = *f; |
| 988 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 989 | if (unlikely(UNSET == core->board.tuner_type)) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 990 | return -EINVAL; |
| 991 | if (unlikely(f->tuner != 0)) |
| 992 | return -EINVAL; |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 993 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 994 | cx88_newstation(core); |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 995 | call_all(core, tuner, s_frequency, f); |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 996 | call_all(core, tuner, g_frequency, &new_freq); |
| 997 | core->freq = new_freq.frequency; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 998 | |
| 999 | /* When changing channels it is required to reset TVAUDIO */ |
| 1000 | msleep (10); |
| 1001 | cx88_set_tvaudio(core); |
| 1002 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1003 | return 0; |
| 1004 | } |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1005 | EXPORT_SYMBOL(cx88_set_freq); |
| 1006 | |
| 1007 | static int vidioc_s_frequency (struct file *file, void *priv, |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 1008 | const struct v4l2_frequency *f) |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1009 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1010 | struct cx8800_dev *dev = video_drvdata(file); |
| 1011 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1012 | |
Hans Verkuil | edbd138 | 2012-05-11 10:33:25 -0300 | [diff] [blame] | 1013 | return cx88_set_freq(core, f); |
Mauro Carvalho Chehab | 54da49f | 2007-01-20 13:58:26 -0300 | [diff] [blame] | 1014 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1015 | |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1016 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1017 | static int vidioc_g_register (struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1018 | struct v4l2_dbg_register *reg) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1019 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1020 | struct cx8800_dev *dev = video_drvdata(file); |
| 1021 | struct cx88_core *core = dev->core; |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1022 | |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1023 | /* cx2388x has a 24-bit register space */ |
Hans Verkuil | 7feeb14 | 2013-05-29 06:22:02 -0300 | [diff] [blame] | 1024 | reg->val = cx_read(reg->reg & 0xfffffc); |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1025 | reg->size = 4; |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static int vidioc_s_register (struct file *file, void *fh, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1030 | const struct v4l2_dbg_register *reg) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1031 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1032 | struct cx8800_dev *dev = video_drvdata(file); |
| 1033 | struct cx88_core *core = dev->core; |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1034 | |
Hans Verkuil | 7feeb14 | 2013-05-29 06:22:02 -0300 | [diff] [blame] | 1035 | cx_write(reg->reg & 0xfffffc, reg->val); |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | #endif |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | /* ----------------------------------------------------------- */ |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1041 | /* RADIO ESPECIFIC IOCTLS */ |
| 1042 | /* ----------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1044 | static int radio_g_tuner (struct file *file, void *priv, |
| 1045 | struct v4l2_tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1047 | struct cx8800_dev *dev = video_drvdata(file); |
| 1048 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1049 | |
| 1050 | if (unlikely(t->index > 0)) |
| 1051 | return -EINVAL; |
| 1052 | |
| 1053 | strcpy(t->name, "Radio"); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1054 | |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1055 | call_all(core, tuner, g_tuner, t); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1056 | return 0; |
| 1057 | } |
| 1058 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1059 | static int radio_s_tuner (struct file *file, void *priv, |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 1060 | const struct v4l2_tuner *t) |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1061 | { |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1062 | struct cx8800_dev *dev = video_drvdata(file); |
| 1063 | struct cx88_core *core = dev->core; |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1064 | |
| 1065 | if (0 != t->index) |
| 1066 | return -EINVAL; |
| 1067 | |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1068 | call_all(core, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1069 | return 0; |
| 1070 | } |
| 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | /* ----------------------------------------------------------- */ |
| 1073 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 1074 | static const char *cx88_vid_irqs[32] = { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 1075 | "y_risci1", "u_risci1", "v_risci1", "vbi_risc1", |
| 1076 | "y_risci2", "u_risci2", "v_risci2", "vbi_risc2", |
| 1077 | "y_oflow", "u_oflow", "v_oflow", "vbi_oflow", |
| 1078 | "y_sync", "u_sync", "v_sync", "vbi_sync", |
| 1079 | "opc_err", "par_err", "rip_err", "pci_abort", |
| 1080 | }; |
| 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | static void cx8800_vid_irq(struct cx8800_dev *dev) |
| 1083 | { |
| 1084 | struct cx88_core *core = dev->core; |
| 1085 | u32 status, mask, count; |
| 1086 | |
| 1087 | status = cx_read(MO_VID_INTSTAT); |
| 1088 | mask = cx_read(MO_VID_INTMSK); |
| 1089 | if (0 == (status & mask)) |
| 1090 | return; |
| 1091 | cx_write(MO_VID_INTSTAT, status); |
| 1092 | if (irq_debug || (status & mask & ~0xff)) |
| 1093 | cx88_print_irqbits(core->name, "irq vid", |
Mauro Carvalho Chehab | 66623a0 | 2007-03-29 08:47:04 -0300 | [diff] [blame] | 1094 | cx88_vid_irqs, ARRAY_SIZE(cx88_vid_irqs), |
| 1095 | status, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* risc op code error */ |
| 1098 | if (status & (1 << 16)) { |
| 1099 | printk(KERN_WARNING "%s/0: video risc op code error\n",core->name); |
| 1100 | cx_clear(MO_VID_DMACNTRL, 0x11); |
| 1101 | cx_clear(VID_CAPTURE_CONTROL, 0x06); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1102 | cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | /* risc1 y */ |
| 1106 | if (status & 0x01) { |
| 1107 | spin_lock(&dev->slock); |
| 1108 | count = cx_read(MO_VIDY_GPCNT); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1109 | cx88_wakeup(core, &dev->vidq, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | spin_unlock(&dev->slock); |
| 1111 | } |
| 1112 | |
| 1113 | /* risc1 vbi */ |
| 1114 | if (status & 0x08) { |
| 1115 | spin_lock(&dev->slock); |
| 1116 | count = cx_read(MO_VBI_GPCNT); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1117 | cx88_wakeup(core, &dev->vbiq, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | spin_unlock(&dev->slock); |
| 1119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1122 | static irqreturn_t cx8800_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
| 1124 | struct cx8800_dev *dev = dev_id; |
| 1125 | struct cx88_core *core = dev->core; |
| 1126 | u32 status; |
| 1127 | int loop, handled = 0; |
| 1128 | |
| 1129 | for (loop = 0; loop < 10; loop++) { |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 1130 | status = cx_read(MO_PCI_INTSTAT) & |
| 1131 | (core->pci_irqmask | PCI_INT_VIDINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | if (0 == status) |
| 1133 | goto out; |
| 1134 | cx_write(MO_PCI_INTSTAT, status); |
| 1135 | handled = 1; |
| 1136 | |
| 1137 | if (status & core->pci_irqmask) |
| 1138 | cx88_core_irq(core,status); |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 1139 | if (status & PCI_INT_VIDINT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | cx8800_vid_irq(dev); |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 1141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | if (10 == loop) { |
| 1143 | printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n", |
| 1144 | core->name); |
| 1145 | cx_write(MO_PCI_INTMSK,0); |
| 1146 | } |
| 1147 | |
| 1148 | out: |
| 1149 | return IRQ_RETVAL(handled); |
| 1150 | } |
| 1151 | |
| 1152 | /* ----------------------------------------------------------- */ |
| 1153 | /* exported stuff */ |
| 1154 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1155 | static const struct v4l2_file_operations video_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
| 1157 | .owner = THIS_MODULE, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1158 | .open = v4l2_fh_open, |
| 1159 | .release = vb2_fop_release, |
| 1160 | .read = vb2_fop_read, |
| 1161 | .poll = vb2_fop_poll, |
| 1162 | .mmap = vb2_fop_mmap, |
Mauro Carvalho Chehab | b6187264 | 2011-02-13 21:52:02 -0300 | [diff] [blame] | 1163 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | }; |
| 1165 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1166 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1167 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1168 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1169 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1170 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1171 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1172 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1173 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1174 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1175 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
Hans Verkuil | 48d6880 | 2012-05-25 12:15:30 -0300 | [diff] [blame] | 1176 | .vidioc_g_std = vidioc_g_std, |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 1177 | .vidioc_s_std = vidioc_s_std, |
| 1178 | .vidioc_enum_input = vidioc_enum_input, |
| 1179 | .vidioc_g_input = vidioc_g_input, |
| 1180 | .vidioc_s_input = vidioc_s_input, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1181 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1182 | .vidioc_streamoff = vb2_ioctl_streamoff, |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 1183 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1184 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1185 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1186 | .vidioc_s_frequency = vidioc_s_frequency, |
| 1187 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1188 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 1189 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1190 | .vidioc_g_register = vidioc_g_register, |
| 1191 | .vidioc_s_register = vidioc_s_register, |
| 1192 | #endif |
| 1193 | }; |
| 1194 | |
| 1195 | static const struct video_device cx8800_video_template = { |
| 1196 | .name = "cx8800-video", |
| 1197 | .fops = &video_fops, |
| 1198 | .ioctl_ops = &video_ioctl_ops, |
| 1199 | .tvnorms = CX88_NORMS, |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 1200 | }; |
| 1201 | |
| 1202 | static const struct v4l2_ioctl_ops vbi_ioctl_ops = { |
| 1203 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1204 | .vidioc_g_fmt_vbi_cap = cx8800_vbi_fmt, |
| 1205 | .vidioc_try_fmt_vbi_cap = cx8800_vbi_fmt, |
| 1206 | .vidioc_s_fmt_vbi_cap = cx8800_vbi_fmt, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1207 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1208 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1209 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1210 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
Hans Verkuil | 48d6880 | 2012-05-25 12:15:30 -0300 | [diff] [blame] | 1211 | .vidioc_g_std = vidioc_g_std, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1212 | .vidioc_s_std = vidioc_s_std, |
| 1213 | .vidioc_enum_input = vidioc_enum_input, |
| 1214 | .vidioc_g_input = vidioc_g_input, |
| 1215 | .vidioc_s_input = vidioc_s_input, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1216 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1217 | .vidioc_streamoff = vb2_ioctl_streamoff, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1218 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1219 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1220 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1221 | .vidioc_s_frequency = vidioc_s_frequency, |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1222 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1223 | .vidioc_g_register = vidioc_g_register, |
| 1224 | .vidioc_s_register = vidioc_s_register, |
| 1225 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1226 | }; |
| 1227 | |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 1228 | static const struct video_device cx8800_vbi_template = { |
| 1229 | .name = "cx8800-vbi", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1230 | .fops = &video_fops, |
Hans Verkuil | f33e986 | 2012-05-25 12:04:10 -0300 | [diff] [blame] | 1231 | .ioctl_ops = &vbi_ioctl_ops, |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 1232 | .tvnorms = CX88_NORMS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | }; |
| 1234 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1235 | static const struct v4l2_file_operations radio_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | { |
| 1237 | .owner = THIS_MODULE, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1238 | .open = radio_open, |
Hans Verkuil | 1a3c60a | 2012-05-11 11:25:03 -0300 | [diff] [blame] | 1239 | .poll = v4l2_ctrl_poll, |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1240 | .release = v4l2_fh_release, |
Mauro Carvalho Chehab | b6187264 | 2011-02-13 21:52:02 -0300 | [diff] [blame] | 1241 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | }; |
| 1243 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1244 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Hans Verkuil | 902e197 | 2012-05-09 16:23:07 -0300 | [diff] [blame] | 1245 | .vidioc_querycap = vidioc_querycap, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1246 | .vidioc_g_tuner = radio_g_tuner, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1247 | .vidioc_s_tuner = radio_s_tuner, |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 1248 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1249 | .vidioc_s_frequency = vidioc_s_frequency, |
Hans Verkuil | 1a3c60a | 2012-05-11 11:25:03 -0300 | [diff] [blame] | 1250 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1251 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Trent Piepho | a75d204 | 2007-08-01 00:13:28 -0300 | [diff] [blame] | 1252 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1253 | .vidioc_g_register = vidioc_g_register, |
| 1254 | .vidioc_s_register = vidioc_s_register, |
| 1255 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | }; |
| 1257 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 1258 | static const struct video_device cx8800_radio_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1259 | .name = "cx8800-radio", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1260 | .fops = &radio_fops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1261 | .ioctl_ops = &radio_ioctl_ops, |
| 1262 | }; |
| 1263 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1264 | static const struct v4l2_ctrl_ops cx8800_ctrl_vid_ops = { |
| 1265 | .s_ctrl = cx8800_s_vid_ctrl, |
| 1266 | }; |
| 1267 | |
| 1268 | static const struct v4l2_ctrl_ops cx8800_ctrl_aud_ops = { |
| 1269 | .s_ctrl = cx8800_s_aud_ctrl, |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1270 | }; |
| 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | /* ----------------------------------------------------------- */ |
| 1273 | |
| 1274 | static void cx8800_unregister_video(struct cx8800_dev *dev) |
| 1275 | { |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1276 | video_unregister_device(&dev->radio_dev); |
| 1277 | video_unregister_device(&dev->vbi_dev); |
| 1278 | video_unregister_device(&dev->video_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1281 | static int cx8800_initdev(struct pci_dev *pci_dev, |
| 1282 | const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | { |
| 1284 | struct cx8800_dev *dev; |
| 1285 | struct cx88_core *core; |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1286 | struct vb2_queue *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | int err; |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1288 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1290 | dev = kzalloc(sizeof(*dev),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | if (NULL == dev) |
| 1292 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* pci init */ |
| 1295 | dev->pci = pci_dev; |
| 1296 | if (pci_enable_device(pci_dev)) { |
| 1297 | err = -EIO; |
| 1298 | goto fail_free; |
| 1299 | } |
| 1300 | core = cx88_core_get(dev->pci); |
| 1301 | if (NULL == core) { |
| 1302 | err = -EINVAL; |
| 1303 | goto fail_free; |
| 1304 | } |
| 1305 | dev->core = core; |
| 1306 | |
| 1307 | /* print pci info */ |
Bjørn Mork | abd34d8 | 2011-03-21 11:35:56 -0300 | [diff] [blame] | 1308 | dev->pci_rev = pci_dev->revision; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1309 | pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat); |
| 1310 | 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] | 1311 | "latency: %d, mmio: 0x%llx\n", core->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | pci_name(pci_dev), dev->pci_rev, pci_dev->irq, |
Greg Kroah-Hartman | 228aef6 | 2006-06-12 15:16:52 -0700 | [diff] [blame] | 1313 | dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
| 1315 | pci_set_master(pci_dev); |
Christoph Hellwig | 1a47de6 | 2015-11-20 15:57:07 -0800 | [diff] [blame] | 1316 | err = pci_set_dma_mask(pci_dev,DMA_BIT_MASK(32)); |
| 1317 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | goto fail_core; |
| 1320 | } |
| 1321 | |
| 1322 | /* initialize driver struct */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | spin_lock_init(&dev->slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | |
| 1325 | /* init video dma queues */ |
| 1326 | INIT_LIST_HEAD(&dev->vidq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
| 1328 | /* init vbi dma queues */ |
| 1329 | INIT_LIST_HEAD(&dev->vbiq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | |
| 1331 | /* get irq */ |
| 1332 | err = request_irq(pci_dev->irq, cx8800_irq, |
Michael Opdenacker | 3e018fe | 2013-10-13 02:49:29 -0300 | [diff] [blame] | 1333 | IRQF_SHARED, core->name, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1335 | printk(KERN_ERR "%s/0: can't get IRQ %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | core->name,pci_dev->irq); |
| 1337 | goto fail_core; |
| 1338 | } |
| 1339 | cx_set(MO_PCI_INTMSK, core->pci_irqmask); |
| 1340 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1341 | for (i = 0; i < CX8800_AUD_CTLS; i++) { |
| 1342 | const struct cx88_ctrl *cc = &cx8800_aud_ctls[i]; |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1343 | struct v4l2_ctrl *vc; |
| 1344 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1345 | vc = v4l2_ctrl_new_std(&core->audio_hdl, &cx8800_ctrl_aud_ops, |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1346 | cc->id, cc->minimum, cc->maximum, cc->step, cc->default_value); |
| 1347 | if (vc == NULL) { |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1348 | err = core->audio_hdl.error; |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1349 | goto fail_core; |
| 1350 | } |
| 1351 | vc->priv = (void *)cc; |
| 1352 | } |
| 1353 | |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1354 | for (i = 0; i < CX8800_VID_CTLS; i++) { |
| 1355 | const struct cx88_ctrl *cc = &cx8800_vid_ctls[i]; |
| 1356 | struct v4l2_ctrl *vc; |
| 1357 | |
| 1358 | vc = v4l2_ctrl_new_std(&core->video_hdl, &cx8800_ctrl_vid_ops, |
| 1359 | cc->id, cc->minimum, cc->maximum, cc->step, cc->default_value); |
| 1360 | if (vc == NULL) { |
| 1361 | err = core->video_hdl.error; |
| 1362 | goto fail_core; |
| 1363 | } |
| 1364 | vc->priv = (void *)cc; |
| 1365 | if (vc->id == V4L2_CID_CHROMA_AGC) |
| 1366 | core->chroma_agc = vc; |
| 1367 | } |
Hans Verkuil | 34a6b7d | 2012-09-14 07:15:03 -0300 | [diff] [blame] | 1368 | v4l2_ctrl_add_handler(&core->video_hdl, &core->audio_hdl, NULL); |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | /* load and configure helper modules */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1371 | |
Hans Verkuil | facd236 | 2013-05-26 07:56:06 -0300 | [diff] [blame] | 1372 | if (core->board.audio_chip == CX88_AUDIO_WM8775) { |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 1373 | struct i2c_board_info wm8775_info = { |
| 1374 | .type = "wm8775", |
| 1375 | .addr = 0x36 >> 1, |
| 1376 | .platform_data = &core->wm8775_data, |
| 1377 | }; |
| 1378 | struct v4l2_subdev *sd; |
| 1379 | |
| 1380 | if (core->boardnr == CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1) |
| 1381 | core->wm8775_data.is_nova_s = true; |
| 1382 | else |
| 1383 | core->wm8775_data.is_nova_s = false; |
| 1384 | |
| 1385 | sd = v4l2_i2c_new_subdev_board(&core->v4l2_dev, &core->i2c_adap, |
| 1386 | &wm8775_info, NULL); |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1387 | if (sd != NULL) { |
| 1388 | core->sd_wm8775 = sd; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 1389 | sd->grp_id = WM8775_GID; |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 1390 | } |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 1391 | } |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1392 | |
Hans Verkuil | facd236 | 2013-05-26 07:56:06 -0300 | [diff] [blame] | 1393 | if (core->board.audio_chip == CX88_AUDIO_TVAUDIO) { |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1394 | /* This probes for a tda9874 as is used on some |
| 1395 | Pixelview Ultra boards. */ |
Laurent Pinchart | 9a1f8b3 | 2010-09-24 10:16:44 -0300 | [diff] [blame] | 1396 | v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, |
| 1397 | "tvaudio", 0, I2C_ADDRS(0xb0 >> 1)); |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1398 | } |
Steven Toth | 3057906 | 2006-09-25 12:43:42 -0300 | [diff] [blame] | 1399 | |
Michael Krufky | 6fcecce | 2007-08-24 01:32:31 -0300 | [diff] [blame] | 1400 | switch (core->boardnr) { |
| 1401 | case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD: |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1402 | case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: { |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 1403 | static const struct i2c_board_info rtc_info = { |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1404 | I2C_BOARD_INFO("isl1208", 0x6f) |
| 1405 | }; |
| 1406 | |
Michael Krufky | 6fcecce | 2007-08-24 01:32:31 -0300 | [diff] [blame] | 1407 | request_module("rtc-isl1208"); |
Hans Verkuil | b8341e1 | 2009-03-29 08:26:01 -0300 | [diff] [blame] | 1408 | core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info); |
| 1409 | } |
Michael Krufky | 8efd2e2 | 2008-04-22 14:45:14 -0300 | [diff] [blame] | 1410 | /* break intentionally omitted */ |
| 1411 | case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO: |
| 1412 | request_module("ir-kbd-i2c"); |
Michael Krufky | 6fcecce | 2007-08-24 01:32:31 -0300 | [diff] [blame] | 1413 | } |
| 1414 | |
Mauro Carvalho Chehab | 121ec13 | 2011-02-14 07:01:51 -0300 | [diff] [blame] | 1415 | /* Sets device info at pci_dev */ |
| 1416 | pci_set_drvdata(pci_dev, dev); |
| 1417 | |
Hans Verkuil | ccd6f1d | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 1418 | dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); |
Hans Verkuil | c5a8614 | 2012-05-11 10:45:18 -0300 | [diff] [blame] | 1419 | |
Hans Verkuil | 078859a | 2014-08-29 06:08:07 -0300 | [diff] [blame] | 1420 | /* Maintain a reference so cx88-blackbird can query the 8800 device. */ |
| 1421 | core->v4ldev = dev; |
| 1422 | |
Mauro Carvalho Chehab | 121ec13 | 2011-02-14 07:01:51 -0300 | [diff] [blame] | 1423 | /* initial device configuration */ |
| 1424 | mutex_lock(&core->lock); |
Devin Heitmueller | e82672f | 2014-09-20 09:23:44 -0300 | [diff] [blame] | 1425 | cx88_set_tvnorm(core, V4L2_STD_NTSC_M); |
Hans Verkuil | 8c7cb12 | 2012-05-11 09:07:45 -0300 | [diff] [blame] | 1426 | v4l2_ctrl_handler_setup(&core->video_hdl); |
| 1427 | v4l2_ctrl_handler_setup(&core->audio_hdl); |
Mauro Carvalho Chehab | 121ec13 | 2011-02-14 07:01:51 -0300 | [diff] [blame] | 1428 | cx88_video_mux(core, 0); |
| 1429 | |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1430 | q = &dev->vb2_vidq; |
| 1431 | q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1432 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; |
| 1433 | q->gfp_flags = GFP_DMA32; |
| 1434 | q->min_buffers_needed = 2; |
| 1435 | q->drv_priv = dev; |
| 1436 | q->buf_struct_size = sizeof(struct cx88_buffer); |
| 1437 | q->ops = &cx8800_video_qops; |
| 1438 | q->mem_ops = &vb2_dma_sg_memops; |
| 1439 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 1440 | q->lock = &core->lock; |
Hans Verkuil | 2bc46b3 | 2016-02-15 12:37:15 -0200 | [diff] [blame] | 1441 | q->dev = &dev->pci->dev; |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1442 | |
| 1443 | err = vb2_queue_init(q); |
| 1444 | if (err < 0) |
| 1445 | goto fail_unreg; |
| 1446 | |
| 1447 | q = &dev->vb2_vbiq; |
| 1448 | q->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 1449 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; |
| 1450 | q->gfp_flags = GFP_DMA32; |
| 1451 | q->min_buffers_needed = 2; |
| 1452 | q->drv_priv = dev; |
| 1453 | q->buf_struct_size = sizeof(struct cx88_buffer); |
| 1454 | q->ops = &cx8800_vbi_qops; |
| 1455 | q->mem_ops = &vb2_dma_sg_memops; |
| 1456 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 1457 | q->lock = &core->lock; |
Hans Verkuil | 2bc46b3 | 2016-02-15 12:37:15 -0200 | [diff] [blame] | 1458 | q->dev = &dev->pci->dev; |
Hans Verkuil | 0b6b630 | 2014-09-20 09:22:18 -0300 | [diff] [blame] | 1459 | |
| 1460 | err = vb2_queue_init(q); |
| 1461 | if (err < 0) |
| 1462 | goto fail_unreg; |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | /* register v4l devices */ |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1465 | cx88_vdev_init(core, dev->pci, &dev->video_dev, |
| 1466 | &cx8800_video_template, "video"); |
| 1467 | video_set_drvdata(&dev->video_dev, dev); |
| 1468 | dev->video_dev.ctrl_handler = &core->video_hdl; |
| 1469 | dev->video_dev.queue = &dev->vb2_vidq; |
| 1470 | err = video_register_device(&dev->video_dev, VFL_TYPE_GRABBER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | video_nr[core->nr]); |
| 1472 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1473 | printk(KERN_ERR "%s/0: can't register video device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | core->name); |
| 1475 | goto fail_unreg; |
| 1476 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1477 | printk(KERN_INFO "%s/0: registered device %s [v4l2]\n", |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1478 | core->name, video_device_node_name(&dev->video_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1480 | cx88_vdev_init(core, dev->pci, &dev->vbi_dev, |
| 1481 | &cx8800_vbi_template, "vbi"); |
| 1482 | video_set_drvdata(&dev->vbi_dev, dev); |
| 1483 | dev->vbi_dev.queue = &dev->vb2_vbiq; |
| 1484 | err = video_register_device(&dev->vbi_dev, VFL_TYPE_VBI, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | vbi_nr[core->nr]); |
| 1486 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1487 | printk(KERN_ERR "%s/0: can't register vbi device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | core->name); |
| 1489 | goto fail_unreg; |
| 1490 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1491 | printk(KERN_INFO "%s/0: registered device %s\n", |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1492 | core->name, video_device_node_name(&dev->vbi_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 1494 | if (core->board.radio.type == CX88_RADIO) { |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1495 | cx88_vdev_init(core, dev->pci, &dev->radio_dev, |
| 1496 | &cx8800_radio_template, "radio"); |
| 1497 | video_set_drvdata(&dev->radio_dev, dev); |
| 1498 | dev->radio_dev.ctrl_handler = &core->audio_hdl; |
| 1499 | err = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | radio_nr[core->nr]); |
| 1501 | if (err < 0) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1502 | printk(KERN_ERR "%s/0: can't register radio device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | core->name); |
| 1504 | goto fail_unreg; |
| 1505 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1506 | printk(KERN_INFO "%s/0: registered device %s\n", |
Hans Verkuil | 34080bc | 2015-03-09 13:34:00 -0300 | [diff] [blame] | 1507 | core->name, video_device_node_name(&dev->radio_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | /* start tvaudio thread */ |
Hans Verkuil | c39ba330 | 2014-08-29 07:45:00 -0300 | [diff] [blame] | 1511 | if (core->board.tuner_type != UNSET) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio"); |
Cyrill Gorcunov | 32b78de | 2007-07-19 11:44:11 -0300 | [diff] [blame] | 1513 | if (IS_ERR(core->kthread)) { |
| 1514 | err = PTR_ERR(core->kthread); |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1515 | printk(KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n", |
| 1516 | core->name, err); |
Cyrill Gorcunov | 32b78de | 2007-07-19 11:44:11 -0300 | [diff] [blame] | 1517 | } |
| 1518 | } |
Mauro Carvalho Chehab | 121ec13 | 2011-02-14 07:01:51 -0300 | [diff] [blame] | 1519 | mutex_unlock(&core->lock); |
| 1520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | return 0; |
| 1522 | |
| 1523 | fail_unreg: |
| 1524 | cx8800_unregister_video(dev); |
| 1525 | free_irq(pci_dev->irq, dev); |
Mauro Carvalho Chehab | 121ec13 | 2011-02-14 07:01:51 -0300 | [diff] [blame] | 1526 | mutex_unlock(&core->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | fail_core: |
Hans Verkuil | 078859a | 2014-08-29 06:08:07 -0300 | [diff] [blame] | 1528 | core->v4ldev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | cx88_core_put(core,dev->pci); |
| 1530 | fail_free: |
| 1531 | kfree(dev); |
| 1532 | return err; |
| 1533 | } |
| 1534 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1535 | static void cx8800_finidev(struct pci_dev *pci_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1537 | struct cx8800_dev *dev = pci_get_drvdata(pci_dev); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1538 | struct cx88_core *core = dev->core; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | |
| 1540 | /* stop thread */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1541 | if (core->kthread) { |
| 1542 | kthread_stop(core->kthread); |
| 1543 | core->kthread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Marton Balint | b12203d | 2008-03-26 02:07:35 -0300 | [diff] [blame] | 1546 | if (core->ir) |
Mauro Carvalho Chehab | 92f4fc1 | 2010-03-31 16:07:49 -0300 | [diff] [blame] | 1547 | cx88_ir_stop(core); |
Marton Balint | b12203d | 2008-03-26 02:07:35 -0300 | [diff] [blame] | 1548 | |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1549 | cx88_shutdown(core); /* FIXME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
| 1551 | /* unregister stuff */ |
| 1552 | |
| 1553 | free_irq(pci_dev->irq, dev); |
| 1554 | cx8800_unregister_video(dev); |
Hans Verkuil | 98822de | 2014-09-05 09:37:09 -0300 | [diff] [blame] | 1555 | pci_disable_device(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
Hans Verkuil | 078859a | 2014-08-29 06:08:07 -0300 | [diff] [blame] | 1557 | core->v4ldev = NULL; |
| 1558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | /* free memory */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1560 | cx88_core_put(core,dev->pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | kfree(dev); |
| 1562 | } |
| 1563 | |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 1564 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state) |
| 1566 | { |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 1567 | struct cx8800_dev *dev = pci_get_drvdata(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | struct cx88_core *core = dev->core; |
Alexey Khoroshilov | 5ddfbbb | 2013-04-13 18:52:04 -0300 | [diff] [blame] | 1569 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
| 1571 | /* stop video+vbi capture */ |
Alexey Khoroshilov | 5ddfbbb | 2013-04-13 18:52:04 -0300 | [diff] [blame] | 1572 | spin_lock_irqsave(&dev->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | if (!list_empty(&dev->vidq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1574 | printk("%s/0: suspend video\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | stop_video_dma(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | } |
| 1577 | if (!list_empty(&dev->vbiq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1578 | printk("%s/0: suspend vbi\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | cx8800_stop_vbi_dma(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
Alexey Khoroshilov | 5ddfbbb | 2013-04-13 18:52:04 -0300 | [diff] [blame] | 1581 | spin_unlock_irqrestore(&dev->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
Mauro Carvalho Chehab | 13595a5 | 2007-10-01 08:51:39 -0300 | [diff] [blame] | 1583 | if (core->ir) |
Mauro Carvalho Chehab | 92f4fc1 | 2010-03-31 16:07:49 -0300 | [diff] [blame] | 1584 | cx88_ir_stop(core); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | /* FIXME -- shutdown device */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1586 | cx88_shutdown(core); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
| 1588 | pci_save_state(pci_dev); |
| 1589 | if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { |
| 1590 | pci_disable_device(pci_dev); |
| 1591 | dev->state.disabled = 1; |
| 1592 | } |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
| 1596 | static int cx8800_resume(struct pci_dev *pci_dev) |
| 1597 | { |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 1598 | struct cx8800_dev *dev = pci_get_drvdata(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | struct cx88_core *core = dev->core; |
Alexey Khoroshilov | 5ddfbbb | 2013-04-13 18:52:04 -0300 | [diff] [blame] | 1600 | unsigned long flags; |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 1601 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | |
| 1603 | if (dev->state.disabled) { |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 1604 | err=pci_enable_device(pci_dev); |
| 1605 | if (err) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1606 | printk(KERN_ERR "%s/0: can't enable device\n", |
| 1607 | core->name); |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 1608 | return err; |
| 1609 | } |
| 1610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | dev->state.disabled = 0; |
| 1612 | } |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 1613 | err= pci_set_power_state(pci_dev, PCI_D0); |
| 1614 | if (err) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1615 | 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] | 1616 | pci_disable_device(pci_dev); |
| 1617 | dev->state.disabled = 1; |
| 1618 | |
| 1619 | return err; |
| 1620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | pci_restore_state(pci_dev); |
| 1622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | /* FIXME: re-initialize hardware */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 1624 | cx88_reset(core); |
Mauro Carvalho Chehab | 13595a5 | 2007-10-01 08:51:39 -0300 | [diff] [blame] | 1625 | if (core->ir) |
Mauro Carvalho Chehab | 92f4fc1 | 2010-03-31 16:07:49 -0300 | [diff] [blame] | 1626 | cx88_ir_start(core); |
Mauro Carvalho Chehab | 13595a5 | 2007-10-01 08:51:39 -0300 | [diff] [blame] | 1627 | |
| 1628 | cx_set(MO_PCI_INTMSK, core->pci_irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | |
| 1630 | /* restart video+vbi capture */ |
Alexey Khoroshilov | 5ddfbbb | 2013-04-13 18:52:04 -0300 | [diff] [blame] | 1631 | spin_lock_irqsave(&dev->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | if (!list_empty(&dev->vidq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1633 | printk("%s/0: resume video\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | restart_video_queue(dev,&dev->vidq); |
| 1635 | } |
| 1636 | if (!list_empty(&dev->vbiq.active)) { |
Trent Piepho | 5772f81 | 2007-08-15 14:41:59 -0300 | [diff] [blame] | 1637 | printk("%s/0: resume vbi\n", core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | cx8800_restart_vbi_queue(dev,&dev->vbiq); |
| 1639 | } |
Alexey Khoroshilov | 5ddfbbb | 2013-04-13 18:52:04 -0300 | [diff] [blame] | 1640 | spin_unlock_irqrestore(&dev->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
| 1642 | return 0; |
| 1643 | } |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 1644 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | |
| 1646 | /* ----------------------------------------------------------- */ |
| 1647 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 1648 | static const struct pci_device_id cx8800_pci_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | { |
| 1650 | .vendor = 0x14f1, |
| 1651 | .device = 0x8800, |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 1652 | .subvendor = PCI_ANY_ID, |
| 1653 | .subdevice = PCI_ANY_ID, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | },{ |
| 1655 | /* --- end of list --- */ |
| 1656 | } |
| 1657 | }; |
| 1658 | MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl); |
| 1659 | |
| 1660 | static struct pci_driver cx8800_pci_driver = { |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 1661 | .name = "cx8800", |
| 1662 | .id_table = cx8800_pci_tbl, |
| 1663 | .probe = cx8800_initdev, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1664 | .remove = cx8800_finidev, |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 1665 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | .suspend = cx8800_suspend, |
| 1667 | .resume = cx8800_resume, |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 1668 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | }; |
| 1670 | |
Sachin Kamat | 06333e0 | 2013-09-20 05:32:07 -0300 | [diff] [blame] | 1671 | module_pci_driver(cx8800_pci_driver); |