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 | bttv - Bt848 frame grabber driver |
| 4 | |
| 5 | Copyright (C) 1996,97,98 Ralph Metzler <rjkm@thp.uni-koeln.de> |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 6 | & Marcus Metzler <mocm@thp.uni-koeln.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | (c) 1999-2002 Gerd Knorr <kraxel@bytesex.org> |
| 8 | |
| 9 | some v4l2 code lines are taken from Justin's bttv2 driver which is |
| 10 | (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za> |
| 11 | |
Nickolay V. Shmyrev | e84619b | 2007-10-26 11:01:08 -0300 | [diff] [blame] | 12 | V4L1 removal from: |
| 13 | (c) 2005-2006 Nickolay V. Shmyrev <nshmyrev@yandex.ru> |
| 14 | |
Mauro Carvalho Chehab | c96dd07 | 2007-10-26 16:51:47 -0300 | [diff] [blame] | 15 | Fixes to be fully V4L2 compliant by |
| 16 | (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org> |
| 17 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 18 | Cropping and overscan support |
| 19 | Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at> |
| 20 | Sponsored by OPQ Systems AB |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | This program is free software; you can redistribute it and/or modify |
| 23 | it under the terms of the GNU General Public License as published by |
| 24 | the Free Software Foundation; either version 2 of the License, or |
| 25 | (at your option) any later version. |
| 26 | |
| 27 | This program is distributed in the hope that it will be useful, |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | GNU General Public License for more details. |
| 31 | |
| 32 | You should have received a copy of the GNU General Public License |
| 33 | along with this program; if not, write to the Free Software |
| 34 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | */ |
| 36 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 37 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/init.h> |
| 40 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/errno.h> |
| 44 | #include <linux/fs.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/sched.h> |
| 47 | #include <linux/interrupt.h> |
| 48 | #include <linux/kdev_t.h> |
Mauro Carvalho Chehab | b5b8ab8 | 2006-01-09 15:25:20 -0200 | [diff] [blame] | 49 | #include "bttvp.h" |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 50 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 51 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 1b9e94d | 2012-09-09 09:23:31 -0300 | [diff] [blame] | 52 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 53 | #include <media/tvaudio.h> |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 54 | #include <media/msp3400.h> |
Mauro Carvalho Chehab | b5b8ab8 | 2006-01-09 15:25:20 -0200 | [diff] [blame] | 55 | |
Mauro Carvalho Chehab | fa9846a | 2005-07-12 13:58:42 -0700 | [diff] [blame] | 56 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #include <asm/io.h> |
| 59 | #include <asm/byteorder.h> |
| 60 | |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 61 | #include <media/saa6588.h> |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 62 | |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 63 | #define BTTV_VERSION "0.9.19" |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | unsigned int bttv_num; /* number of Bt848s in use */ |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 66 | struct bttv *bttvs[BTTV_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 68 | unsigned int bttv_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | unsigned int bttv_verbose = 1; |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 70 | unsigned int bttv_gpio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* config variables */ |
| 73 | #ifdef __BIG_ENDIAN |
| 74 | static unsigned int bigendian=1; |
| 75 | #else |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 76 | static unsigned int bigendian; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #endif |
| 78 | static unsigned int radio[BTTV_MAX]; |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 79 | static unsigned int irq_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static unsigned int gbuffers = 8; |
| 81 | static unsigned int gbufsize = 0x208000; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 82 | static unsigned int reset_crop = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Jean Delvare | 176c2f3 | 2008-09-07 12:49:59 -0300 | [diff] [blame] | 84 | static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 }; |
| 85 | static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 }; |
| 86 | static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 }; |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 87 | static int debug_latency; |
Jean Delvare | d90a4ae | 2010-02-16 14:22:37 -0300 | [diff] [blame] | 88 | static int disable_ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 90 | static unsigned int fdsr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* options */ |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 93 | static unsigned int combfilter; |
| 94 | static unsigned int lumafilter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static unsigned int automute = 1; |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 96 | static unsigned int chroma_agc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static unsigned int adc_crush = 1; |
| 98 | static unsigned int whitecrush_upper = 0xCF; |
| 99 | static unsigned int whitecrush_lower = 0x7F; |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 100 | static unsigned int vcr_hack; |
| 101 | static unsigned int irq_iswitch; |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 102 | static unsigned int uv_ratio = 50; |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 103 | static unsigned int full_luma_range; |
| 104 | static unsigned int coring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* API features (turn on/off stuff for testing) */ |
| 107 | static unsigned int v4l2 = 1; |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | /* insmod args */ |
| 110 | module_param(bttv_verbose, int, 0644); |
| 111 | module_param(bttv_gpio, int, 0644); |
| 112 | module_param(bttv_debug, int, 0644); |
| 113 | module_param(irq_debug, int, 0644); |
| 114 | module_param(debug_latency, int, 0644); |
Jean Delvare | d90a4ae | 2010-02-16 14:22:37 -0300 | [diff] [blame] | 115 | module_param(disable_ir, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | module_param(fdsr, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | module_param(gbuffers, int, 0444); |
| 119 | module_param(gbufsize, int, 0444); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 120 | module_param(reset_crop, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | module_param(v4l2, int, 0644); |
| 123 | module_param(bigendian, int, 0644); |
| 124 | module_param(irq_iswitch, int, 0644); |
| 125 | module_param(combfilter, int, 0444); |
| 126 | module_param(lumafilter, int, 0444); |
| 127 | module_param(automute, int, 0444); |
| 128 | module_param(chroma_agc, int, 0444); |
| 129 | module_param(adc_crush, int, 0444); |
| 130 | module_param(whitecrush_upper, int, 0444); |
| 131 | module_param(whitecrush_lower, int, 0444); |
| 132 | module_param(vcr_hack, int, 0444); |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 133 | module_param(uv_ratio, int, 0444); |
| 134 | module_param(full_luma_range, int, 0444); |
| 135 | module_param(coring, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Jean Delvare | 176c2f3 | 2008-09-07 12:49:59 -0300 | [diff] [blame] | 137 | module_param_array(radio, int, NULL, 0444); |
| 138 | module_param_array(video_nr, int, NULL, 0444); |
| 139 | module_param_array(radio_nr, int, NULL, 0444); |
| 140 | module_param_array(vbi_nr, int, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)"); |
| 143 | MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian"); |
| 144 | MODULE_PARM_DESC(bttv_verbose,"verbose startup messages, default is 1 (yes)"); |
| 145 | MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)"); |
| 146 | MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)"); |
| 147 | MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)"); |
Jean Delvare | d90a4ae | 2010-02-16 14:22:37 -0300 | [diff] [blame] | 148 | MODULE_PARM_DESC(disable_ir, "disable infrared remote support"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8"); |
| 150 | MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000"); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 151 | MODULE_PARM_DESC(reset_crop,"reset cropping parameters at open(), default " |
| 152 | "is 1 (yes) for compatibility with older applications"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)"); |
| 154 | MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)"); |
| 155 | MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)"); |
| 156 | MODULE_PARM_DESC(whitecrush_upper,"sets the white crush upper value, default is 207"); |
| 157 | MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127"); |
| 158 | MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)"); |
| 159 | MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler"); |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 160 | MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50"); |
| 161 | MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)"); |
| 162 | MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)"); |
Jean Delvare | 176c2f3 | 2008-09-07 12:49:59 -0300 | [diff] [blame] | 163 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
| 164 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
| 165 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards"); |
| 168 | MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr"); |
| 169 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 170 | MODULE_VERSION(BTTV_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* ----------------------------------------------------------------------- */ |
| 173 | /* sysfs */ |
| 174 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 175 | static ssize_t show_card(struct device *cd, |
| 176 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 178 | struct video_device *vfd = container_of(cd, struct video_device, dev); |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 179 | struct bttv *btv = video_get_drvdata(vfd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); |
| 181 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 182 | static DEVICE_ATTR(card, S_IRUGO, show_card, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | /* ----------------------------------------------------------------------- */ |
Jarod Wilson | f992a49 | 2007-03-24 15:23:50 -0300 | [diff] [blame] | 185 | /* dvb auto-load setup */ |
| 186 | #if defined(CONFIG_MODULES) && defined(MODULE) |
| 187 | static void request_module_async(struct work_struct *work) |
| 188 | { |
| 189 | request_module("dvb-bt8xx"); |
| 190 | } |
| 191 | |
| 192 | static void request_modules(struct bttv *dev) |
| 193 | { |
| 194 | INIT_WORK(&dev->request_module_wk, request_module_async); |
| 195 | schedule_work(&dev->request_module_wk); |
| 196 | } |
Tejun Heo | 707bcf3 | 2010-12-24 16:14:20 +0100 | [diff] [blame] | 197 | |
| 198 | static void flush_request_modules(struct bttv *dev) |
| 199 | { |
Linus Torvalds | 0b8e74c | 2012-10-07 17:49:05 +0900 | [diff] [blame] | 200 | flush_work(&dev->request_module_wk); |
Tejun Heo | 707bcf3 | 2010-12-24 16:14:20 +0100 | [diff] [blame] | 201 | } |
Jarod Wilson | f992a49 | 2007-03-24 15:23:50 -0300 | [diff] [blame] | 202 | #else |
| 203 | #define request_modules(dev) |
Mauro Carvalho Chehab | a1fd287 | 2012-10-27 16:33:41 -0300 | [diff] [blame] | 204 | #define flush_request_modules(dev) do {} while(0) |
Jarod Wilson | f992a49 | 2007-03-24 15:23:50 -0300 | [diff] [blame] | 205 | #endif /* CONFIG_MODULES */ |
| 206 | |
| 207 | |
| 208 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* static data */ |
| 210 | |
| 211 | /* special timing tables from conexant... */ |
| 212 | static u8 SRAM_Table[][60] = |
| 213 | { |
| 214 | /* PAL digital input over GPIO[7:0] */ |
| 215 | { |
| 216 | 45, // 45 bytes following |
| 217 | 0x36,0x11,0x01,0x00,0x90,0x02,0x05,0x10,0x04,0x16, |
| 218 | 0x12,0x05,0x11,0x00,0x04,0x12,0xC0,0x00,0x31,0x00, |
| 219 | 0x06,0x51,0x08,0x03,0x89,0x08,0x07,0xC0,0x44,0x00, |
| 220 | 0x81,0x01,0x01,0xA9,0x0D,0x02,0x02,0x50,0x03,0x37, |
| 221 | 0x37,0x00,0xAF,0x21,0x00 |
| 222 | }, |
| 223 | /* NTSC digital input over GPIO[7:0] */ |
| 224 | { |
| 225 | 51, // 51 bytes following |
| 226 | 0x0C,0xC0,0x00,0x00,0x90,0x02,0x03,0x10,0x03,0x06, |
| 227 | 0x10,0x04,0x12,0x12,0x05,0x02,0x13,0x04,0x19,0x00, |
| 228 | 0x04,0x39,0x00,0x06,0x59,0x08,0x03,0x83,0x08,0x07, |
| 229 | 0x03,0x50,0x00,0xC0,0x40,0x00,0x86,0x01,0x01,0xA6, |
| 230 | 0x0D,0x02,0x03,0x11,0x01,0x05,0x37,0x00,0xAC,0x21, |
| 231 | 0x00, |
| 232 | }, |
| 233 | // TGB_NTSC392 // quartzsight |
| 234 | // This table has been modified to be used for Fusion Rev D |
| 235 | { |
| 236 | 0x2A, // size of table = 42 |
| 237 | 0x06, 0x08, 0x04, 0x0a, 0xc0, 0x00, 0x18, 0x08, 0x03, 0x24, |
| 238 | 0x08, 0x07, 0x02, 0x90, 0x02, 0x08, 0x10, 0x04, 0x0c, 0x10, |
| 239 | 0x05, 0x2c, 0x11, 0x04, 0x55, 0x48, 0x00, 0x05, 0x50, 0x00, |
| 240 | 0xbf, 0x0c, 0x02, 0x2f, 0x3d, 0x00, 0x2f, 0x3f, 0x00, 0xc3, |
| 241 | 0x20, 0x00 |
| 242 | } |
| 243 | }; |
| 244 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 245 | /* minhdelayx1 first video pixel we can capture on a line and |
| 246 | hdelayx1 start of active video, both relative to rising edge of |
| 247 | /HRESET pulse (0H) in 1 / fCLKx1. |
| 248 | swidth width of active video and |
| 249 | totalwidth total line width, both in 1 / fCLKx1. |
| 250 | sqwidth total line width in square pixels. |
| 251 | vdelay start of active video in 2 * field lines relative to |
| 252 | trailing edge of /VRESET pulse (VDELAY register). |
| 253 | sheight height of active video in 2 * field lines. |
| 254 | videostart0 ITU-R frame line number of the line corresponding |
| 255 | to vdelay in the first field. */ |
| 256 | #define CROPCAP(minhdelayx1, hdelayx1, swidth, totalwidth, sqwidth, \ |
| 257 | vdelay, sheight, videostart0) \ |
| 258 | .cropcap.bounds.left = minhdelayx1, \ |
| 259 | /* * 2 because vertically we count field lines times two, */ \ |
| 260 | /* e.g. 23 * 2 to 23 * 2 + 576 in PAL-BGHI defrect. */ \ |
| 261 | .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \ |
| 262 | /* 4 is a safety margin at the end of the line. */ \ |
| 263 | .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \ |
| 264 | .cropcap.bounds.height = (sheight) + (vdelay) - MIN_VDELAY, \ |
| 265 | .cropcap.defrect.left = hdelayx1, \ |
| 266 | .cropcap.defrect.top = (videostart0) * 2, \ |
| 267 | .cropcap.defrect.width = swidth, \ |
| 268 | .cropcap.defrect.height = sheight, \ |
| 269 | .cropcap.pixelaspect.numerator = totalwidth, \ |
| 270 | .cropcap.pixelaspect.denominator = sqwidth, |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | const struct bttv_tvnorm bttv_tvnorms[] = { |
| 273 | /* PAL-BDGHI */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 274 | /* max. active video is actually 922, but 924 is divisible by 4 and 3! */ |
| 275 | /* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | .v4l2_id = V4L2_STD_PAL, |
| 278 | .name = "PAL", |
| 279 | .Fsc = 35468950, |
| 280 | .swidth = 924, |
| 281 | .sheight = 576, |
| 282 | .totalwidth = 1135, |
| 283 | .adelay = 0x7f, |
| 284 | .bdelay = 0x72, |
| 285 | .iform = (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1), |
| 286 | .scaledtwidth = 1135, |
| 287 | .hdelayx1 = 186, |
| 288 | .hactivex1 = 924, |
| 289 | .vdelay = 0x20, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 290 | .vbipack = 255, /* min (2048 / 4, 0x1ff) & 0xff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | .sram = 0, |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 292 | /* ITU-R frame line number of the first VBI line |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 293 | we can capture, of the first and second field. |
| 294 | The last line is determined by cropcap.bounds. */ |
| 295 | .vbistart = { 7, 320 }, |
| 296 | CROPCAP(/* minhdelayx1 */ 68, |
| 297 | /* hdelayx1 */ 186, |
| 298 | /* Should be (768 * 1135 + 944 / 2) / 944. |
| 299 | cropcap.defrect is used for image width |
| 300 | checks, so we keep the old value 924. */ |
| 301 | /* swidth */ 924, |
| 302 | /* totalwidth */ 1135, |
| 303 | /* sqwidth */ 944, |
| 304 | /* vdelay */ 0x20, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 305 | /* bt878 (and bt848?) can capture another |
| 306 | line below active video. */ |
Mauro Carvalho Chehab | a1fd287 | 2012-10-27 16:33:41 -0300 | [diff] [blame] | 307 | /* sheight */ (576 + 2) + 0x20 - 2, |
| 308 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | },{ |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 310 | .v4l2_id = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | .name = "NTSC", |
| 312 | .Fsc = 28636363, |
| 313 | .swidth = 768, |
| 314 | .sheight = 480, |
| 315 | .totalwidth = 910, |
| 316 | .adelay = 0x68, |
| 317 | .bdelay = 0x5d, |
| 318 | .iform = (BT848_IFORM_NTSC|BT848_IFORM_XT0), |
| 319 | .scaledtwidth = 910, |
| 320 | .hdelayx1 = 128, |
| 321 | .hactivex1 = 910, |
| 322 | .vdelay = 0x1a, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 323 | .vbipack = 144, /* min (1600 / 4, 0x1ff) & 0xff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | .sram = 1, |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 325 | .vbistart = { 10, 273 }, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 326 | CROPCAP(/* minhdelayx1 */ 68, |
| 327 | /* hdelayx1 */ 128, |
| 328 | /* Should be (640 * 910 + 780 / 2) / 780? */ |
| 329 | /* swidth */ 768, |
| 330 | /* totalwidth */ 910, |
| 331 | /* sqwidth */ 780, |
| 332 | /* vdelay */ 0x1a, |
| 333 | /* sheight */ 480, |
| 334 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | },{ |
| 336 | .v4l2_id = V4L2_STD_SECAM, |
| 337 | .name = "SECAM", |
| 338 | .Fsc = 35468950, |
| 339 | .swidth = 924, |
| 340 | .sheight = 576, |
| 341 | .totalwidth = 1135, |
| 342 | .adelay = 0x7f, |
| 343 | .bdelay = 0xb0, |
| 344 | .iform = (BT848_IFORM_SECAM|BT848_IFORM_XT1), |
| 345 | .scaledtwidth = 1135, |
| 346 | .hdelayx1 = 186, |
| 347 | .hactivex1 = 922, |
| 348 | .vdelay = 0x20, |
| 349 | .vbipack = 255, |
| 350 | .sram = 0, /* like PAL, correct? */ |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 351 | .vbistart = { 7, 320 }, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 352 | CROPCAP(/* minhdelayx1 */ 68, |
| 353 | /* hdelayx1 */ 186, |
| 354 | /* swidth */ 924, |
| 355 | /* totalwidth */ 1135, |
| 356 | /* sqwidth */ 944, |
| 357 | /* vdelay */ 0x20, |
| 358 | /* sheight */ 576, |
| 359 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | },{ |
| 361 | .v4l2_id = V4L2_STD_PAL_Nc, |
| 362 | .name = "PAL-Nc", |
| 363 | .Fsc = 28636363, |
| 364 | .swidth = 640, |
| 365 | .sheight = 576, |
| 366 | .totalwidth = 910, |
| 367 | .adelay = 0x68, |
| 368 | .bdelay = 0x5d, |
| 369 | .iform = (BT848_IFORM_PAL_NC|BT848_IFORM_XT0), |
| 370 | .scaledtwidth = 780, |
| 371 | .hdelayx1 = 130, |
| 372 | .hactivex1 = 734, |
| 373 | .vdelay = 0x1a, |
| 374 | .vbipack = 144, |
| 375 | .sram = -1, |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 376 | .vbistart = { 7, 320 }, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 377 | CROPCAP(/* minhdelayx1 */ 68, |
| 378 | /* hdelayx1 */ 130, |
| 379 | /* swidth */ (640 * 910 + 780 / 2) / 780, |
| 380 | /* totalwidth */ 910, |
| 381 | /* sqwidth */ 780, |
| 382 | /* vdelay */ 0x1a, |
| 383 | /* sheight */ 576, |
| 384 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | },{ |
| 386 | .v4l2_id = V4L2_STD_PAL_M, |
| 387 | .name = "PAL-M", |
| 388 | .Fsc = 28636363, |
| 389 | .swidth = 640, |
| 390 | .sheight = 480, |
| 391 | .totalwidth = 910, |
| 392 | .adelay = 0x68, |
| 393 | .bdelay = 0x5d, |
| 394 | .iform = (BT848_IFORM_PAL_M|BT848_IFORM_XT0), |
| 395 | .scaledtwidth = 780, |
| 396 | .hdelayx1 = 135, |
| 397 | .hactivex1 = 754, |
| 398 | .vdelay = 0x1a, |
| 399 | .vbipack = 144, |
| 400 | .sram = -1, |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 401 | .vbistart = { 10, 273 }, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 402 | CROPCAP(/* minhdelayx1 */ 68, |
| 403 | /* hdelayx1 */ 135, |
| 404 | /* swidth */ (640 * 910 + 780 / 2) / 780, |
| 405 | /* totalwidth */ 910, |
| 406 | /* sqwidth */ 780, |
| 407 | /* vdelay */ 0x1a, |
| 408 | /* sheight */ 480, |
| 409 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | },{ |
| 411 | .v4l2_id = V4L2_STD_PAL_N, |
| 412 | .name = "PAL-N", |
| 413 | .Fsc = 35468950, |
| 414 | .swidth = 768, |
| 415 | .sheight = 576, |
| 416 | .totalwidth = 1135, |
| 417 | .adelay = 0x7f, |
| 418 | .bdelay = 0x72, |
| 419 | .iform = (BT848_IFORM_PAL_N|BT848_IFORM_XT1), |
| 420 | .scaledtwidth = 944, |
| 421 | .hdelayx1 = 186, |
| 422 | .hactivex1 = 922, |
| 423 | .vdelay = 0x20, |
| 424 | .vbipack = 144, |
| 425 | .sram = -1, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 426 | .vbistart = { 7, 320 }, |
| 427 | CROPCAP(/* minhdelayx1 */ 68, |
| 428 | /* hdelayx1 */ 186, |
| 429 | /* swidth */ (768 * 1135 + 944 / 2) / 944, |
| 430 | /* totalwidth */ 1135, |
| 431 | /* sqwidth */ 944, |
| 432 | /* vdelay */ 0x20, |
| 433 | /* sheight */ 576, |
| 434 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | },{ |
| 436 | .v4l2_id = V4L2_STD_NTSC_M_JP, |
| 437 | .name = "NTSC-JP", |
| 438 | .Fsc = 28636363, |
| 439 | .swidth = 640, |
| 440 | .sheight = 480, |
| 441 | .totalwidth = 910, |
| 442 | .adelay = 0x68, |
| 443 | .bdelay = 0x5d, |
| 444 | .iform = (BT848_IFORM_NTSC_J|BT848_IFORM_XT0), |
| 445 | .scaledtwidth = 780, |
| 446 | .hdelayx1 = 135, |
| 447 | .hactivex1 = 754, |
| 448 | .vdelay = 0x16, |
| 449 | .vbipack = 144, |
| 450 | .sram = -1, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 451 | .vbistart = { 10, 273 }, |
| 452 | CROPCAP(/* minhdelayx1 */ 68, |
| 453 | /* hdelayx1 */ 135, |
| 454 | /* swidth */ (640 * 910 + 780 / 2) / 780, |
| 455 | /* totalwidth */ 910, |
| 456 | /* sqwidth */ 780, |
| 457 | /* vdelay */ 0x16, |
| 458 | /* sheight */ 480, |
| 459 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | },{ |
| 461 | /* that one hopefully works with the strange timing |
| 462 | * which video recorders produce when playing a NTSC |
| 463 | * tape on a PAL TV ... */ |
| 464 | .v4l2_id = V4L2_STD_PAL_60, |
| 465 | .name = "PAL-60", |
| 466 | .Fsc = 35468950, |
| 467 | .swidth = 924, |
| 468 | .sheight = 480, |
| 469 | .totalwidth = 1135, |
| 470 | .adelay = 0x7f, |
| 471 | .bdelay = 0x72, |
| 472 | .iform = (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1), |
| 473 | .scaledtwidth = 1135, |
| 474 | .hdelayx1 = 186, |
| 475 | .hactivex1 = 924, |
| 476 | .vdelay = 0x1a, |
| 477 | .vbipack = 255, |
| 478 | .vtotal = 524, |
| 479 | .sram = -1, |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 480 | .vbistart = { 10, 273 }, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 481 | CROPCAP(/* minhdelayx1 */ 68, |
| 482 | /* hdelayx1 */ 186, |
| 483 | /* swidth */ 924, |
| 484 | /* totalwidth */ 1135, |
| 485 | /* sqwidth */ 944, |
| 486 | /* vdelay */ 0x1a, |
| 487 | /* sheight */ 480, |
| 488 | /* videostart0 */ 23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | }; |
| 491 | static const unsigned int BTTV_TVNORMS = ARRAY_SIZE(bttv_tvnorms); |
| 492 | |
| 493 | /* ----------------------------------------------------------------------- */ |
| 494 | /* bttv format list |
| 495 | packed pixel formats must come first */ |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 496 | static const struct bttv_format formats[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
| 498 | .name = "8 bpp, gray", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | .fourcc = V4L2_PIX_FMT_GREY, |
| 500 | .btformat = BT848_COLOR_FMT_Y8, |
| 501 | .depth = 8, |
| 502 | .flags = FORMAT_FLAGS_PACKED, |
| 503 | },{ |
| 504 | .name = "8 bpp, dithered color", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | .fourcc = V4L2_PIX_FMT_HI240, |
| 506 | .btformat = BT848_COLOR_FMT_RGB8, |
| 507 | .depth = 8, |
| 508 | .flags = FORMAT_FLAGS_PACKED | FORMAT_FLAGS_DITHER, |
| 509 | },{ |
| 510 | .name = "15 bpp RGB, le", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | .fourcc = V4L2_PIX_FMT_RGB555, |
| 512 | .btformat = BT848_COLOR_FMT_RGB15, |
| 513 | .depth = 16, |
| 514 | .flags = FORMAT_FLAGS_PACKED, |
| 515 | },{ |
| 516 | .name = "15 bpp RGB, be", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | .fourcc = V4L2_PIX_FMT_RGB555X, |
| 518 | .btformat = BT848_COLOR_FMT_RGB15, |
| 519 | .btswap = 0x03, /* byteswap */ |
| 520 | .depth = 16, |
| 521 | .flags = FORMAT_FLAGS_PACKED, |
| 522 | },{ |
| 523 | .name = "16 bpp RGB, le", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 525 | .btformat = BT848_COLOR_FMT_RGB16, |
| 526 | .depth = 16, |
| 527 | .flags = FORMAT_FLAGS_PACKED, |
| 528 | },{ |
| 529 | .name = "16 bpp RGB, be", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | .fourcc = V4L2_PIX_FMT_RGB565X, |
| 531 | .btformat = BT848_COLOR_FMT_RGB16, |
| 532 | .btswap = 0x03, /* byteswap */ |
| 533 | .depth = 16, |
| 534 | .flags = FORMAT_FLAGS_PACKED, |
| 535 | },{ |
| 536 | .name = "24 bpp RGB, le", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | .fourcc = V4L2_PIX_FMT_BGR24, |
| 538 | .btformat = BT848_COLOR_FMT_RGB24, |
| 539 | .depth = 24, |
| 540 | .flags = FORMAT_FLAGS_PACKED, |
| 541 | },{ |
| 542 | .name = "32 bpp RGB, le", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | .fourcc = V4L2_PIX_FMT_BGR32, |
| 544 | .btformat = BT848_COLOR_FMT_RGB32, |
| 545 | .depth = 32, |
| 546 | .flags = FORMAT_FLAGS_PACKED, |
| 547 | },{ |
| 548 | .name = "32 bpp RGB, be", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 550 | .btformat = BT848_COLOR_FMT_RGB32, |
| 551 | .btswap = 0x0f, /* byte+word swap */ |
| 552 | .depth = 32, |
| 553 | .flags = FORMAT_FLAGS_PACKED, |
| 554 | },{ |
| 555 | .name = "4:2:2, packed, YUYV", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 557 | .btformat = BT848_COLOR_FMT_YUY2, |
| 558 | .depth = 16, |
| 559 | .flags = FORMAT_FLAGS_PACKED, |
| 560 | },{ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | .name = "4:2:2, packed, UYVY", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 563 | .btformat = BT848_COLOR_FMT_YUY2, |
| 564 | .btswap = 0x03, /* byteswap */ |
| 565 | .depth = 16, |
| 566 | .flags = FORMAT_FLAGS_PACKED, |
| 567 | },{ |
| 568 | .name = "4:2:2, planar, Y-Cb-Cr", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | .fourcc = V4L2_PIX_FMT_YUV422P, |
| 570 | .btformat = BT848_COLOR_FMT_YCrCb422, |
| 571 | .depth = 16, |
| 572 | .flags = FORMAT_FLAGS_PLANAR, |
| 573 | .hshift = 1, |
| 574 | .vshift = 0, |
| 575 | },{ |
| 576 | .name = "4:2:0, planar, Y-Cb-Cr", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | .fourcc = V4L2_PIX_FMT_YUV420, |
| 578 | .btformat = BT848_COLOR_FMT_YCrCb422, |
| 579 | .depth = 12, |
| 580 | .flags = FORMAT_FLAGS_PLANAR, |
| 581 | .hshift = 1, |
| 582 | .vshift = 1, |
| 583 | },{ |
| 584 | .name = "4:2:0, planar, Y-Cr-Cb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | .fourcc = V4L2_PIX_FMT_YVU420, |
| 586 | .btformat = BT848_COLOR_FMT_YCrCb422, |
| 587 | .depth = 12, |
| 588 | .flags = FORMAT_FLAGS_PLANAR | FORMAT_FLAGS_CrCb, |
| 589 | .hshift = 1, |
| 590 | .vshift = 1, |
| 591 | },{ |
| 592 | .name = "4:1:1, planar, Y-Cb-Cr", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | .fourcc = V4L2_PIX_FMT_YUV411P, |
| 594 | .btformat = BT848_COLOR_FMT_YCrCb411, |
| 595 | .depth = 12, |
| 596 | .flags = FORMAT_FLAGS_PLANAR, |
| 597 | .hshift = 2, |
| 598 | .vshift = 0, |
| 599 | },{ |
| 600 | .name = "4:1:0, planar, Y-Cb-Cr", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | .fourcc = V4L2_PIX_FMT_YUV410, |
| 602 | .btformat = BT848_COLOR_FMT_YCrCb411, |
| 603 | .depth = 9, |
| 604 | .flags = FORMAT_FLAGS_PLANAR, |
| 605 | .hshift = 2, |
| 606 | .vshift = 2, |
| 607 | },{ |
| 608 | .name = "4:1:0, planar, Y-Cr-Cb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | .fourcc = V4L2_PIX_FMT_YVU410, |
| 610 | .btformat = BT848_COLOR_FMT_YCrCb411, |
| 611 | .depth = 9, |
| 612 | .flags = FORMAT_FLAGS_PLANAR | FORMAT_FLAGS_CrCb, |
| 613 | .hshift = 2, |
| 614 | .vshift = 2, |
| 615 | },{ |
| 616 | .name = "raw scanlines", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | .fourcc = -1, |
| 618 | .btformat = BT848_COLOR_FMT_RAW, |
| 619 | .depth = 8, |
| 620 | .flags = FORMAT_FLAGS_RAW, |
| 621 | } |
| 622 | }; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 623 | static const unsigned int FORMATS = ARRAY_SIZE(formats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | /* ----------------------------------------------------------------------- */ |
| 626 | |
| 627 | #define V4L2_CID_PRIVATE_CHROMA_AGC (V4L2_CID_PRIVATE_BASE + 0) |
| 628 | #define V4L2_CID_PRIVATE_COMBFILTER (V4L2_CID_PRIVATE_BASE + 1) |
| 629 | #define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 2) |
| 630 | #define V4L2_CID_PRIVATE_LUMAFILTER (V4L2_CID_PRIVATE_BASE + 3) |
| 631 | #define V4L2_CID_PRIVATE_AGC_CRUSH (V4L2_CID_PRIVATE_BASE + 4) |
| 632 | #define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5) |
| 633 | #define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6) |
| 634 | #define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7) |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 635 | #define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_PRIVATE_BASE + 8) |
| 636 | #define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_PRIVATE_BASE + 9) |
| 637 | #define V4L2_CID_PRIVATE_CORING (V4L2_CID_PRIVATE_BASE + 10) |
| 638 | #define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 11) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | static const struct v4l2_queryctrl no_ctl = { |
| 641 | .name = "42", |
| 642 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 643 | }; |
| 644 | static const struct v4l2_queryctrl bttv_ctls[] = { |
| 645 | /* --- video --- */ |
| 646 | { |
| 647 | .id = V4L2_CID_BRIGHTNESS, |
| 648 | .name = "Brightness", |
| 649 | .minimum = 0, |
| 650 | .maximum = 65535, |
| 651 | .step = 256, |
| 652 | .default_value = 32768, |
| 653 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 654 | },{ |
| 655 | .id = V4L2_CID_CONTRAST, |
| 656 | .name = "Contrast", |
| 657 | .minimum = 0, |
| 658 | .maximum = 65535, |
| 659 | .step = 128, |
Alan McIvor | 961e668 | 2012-04-01 21:11:08 -0300 | [diff] [blame] | 660 | .default_value = 27648, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 662 | },{ |
| 663 | .id = V4L2_CID_SATURATION, |
| 664 | .name = "Saturation", |
| 665 | .minimum = 0, |
| 666 | .maximum = 65535, |
| 667 | .step = 128, |
| 668 | .default_value = 32768, |
| 669 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 670 | },{ |
Guilherme Herrmann Destefani | 34e59a7 | 2012-09-25 18:10:52 -0300 | [diff] [blame] | 671 | .id = V4L2_CID_COLOR_KILLER, |
| 672 | .name = "Color killer", |
| 673 | .minimum = 0, |
| 674 | .maximum = 1, |
| 675 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 676 | }, { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | .id = V4L2_CID_HUE, |
| 678 | .name = "Hue", |
| 679 | .minimum = 0, |
| 680 | .maximum = 65535, |
| 681 | .step = 256, |
| 682 | .default_value = 32768, |
| 683 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 684 | }, |
| 685 | /* --- audio --- */ |
| 686 | { |
| 687 | .id = V4L2_CID_AUDIO_MUTE, |
| 688 | .name = "Mute", |
| 689 | .minimum = 0, |
| 690 | .maximum = 1, |
| 691 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 692 | },{ |
| 693 | .id = V4L2_CID_AUDIO_VOLUME, |
| 694 | .name = "Volume", |
| 695 | .minimum = 0, |
| 696 | .maximum = 65535, |
| 697 | .step = 65535/100, |
| 698 | .default_value = 65535, |
| 699 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 700 | },{ |
| 701 | .id = V4L2_CID_AUDIO_BALANCE, |
| 702 | .name = "Balance", |
| 703 | .minimum = 0, |
| 704 | .maximum = 65535, |
| 705 | .step = 65535/100, |
| 706 | .default_value = 32768, |
| 707 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 708 | },{ |
| 709 | .id = V4L2_CID_AUDIO_BASS, |
| 710 | .name = "Bass", |
| 711 | .minimum = 0, |
| 712 | .maximum = 65535, |
| 713 | .step = 65535/100, |
| 714 | .default_value = 32768, |
| 715 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 716 | },{ |
| 717 | .id = V4L2_CID_AUDIO_TREBLE, |
| 718 | .name = "Treble", |
| 719 | .minimum = 0, |
| 720 | .maximum = 65535, |
| 721 | .step = 65535/100, |
| 722 | .default_value = 32768, |
| 723 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 724 | }, |
| 725 | /* --- private --- */ |
| 726 | { |
| 727 | .id = V4L2_CID_PRIVATE_CHROMA_AGC, |
| 728 | .name = "chroma agc", |
| 729 | .minimum = 0, |
| 730 | .maximum = 1, |
| 731 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 732 | },{ |
| 733 | .id = V4L2_CID_PRIVATE_COMBFILTER, |
| 734 | .name = "combfilter", |
| 735 | .minimum = 0, |
| 736 | .maximum = 1, |
| 737 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 738 | },{ |
| 739 | .id = V4L2_CID_PRIVATE_AUTOMUTE, |
| 740 | .name = "automute", |
| 741 | .minimum = 0, |
| 742 | .maximum = 1, |
| 743 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 744 | },{ |
| 745 | .id = V4L2_CID_PRIVATE_LUMAFILTER, |
| 746 | .name = "luma decimation filter", |
| 747 | .minimum = 0, |
| 748 | .maximum = 1, |
| 749 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 750 | },{ |
| 751 | .id = V4L2_CID_PRIVATE_AGC_CRUSH, |
| 752 | .name = "agc crush", |
| 753 | .minimum = 0, |
| 754 | .maximum = 1, |
| 755 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 756 | },{ |
| 757 | .id = V4L2_CID_PRIVATE_VCR_HACK, |
| 758 | .name = "vcr hack", |
| 759 | .minimum = 0, |
| 760 | .maximum = 1, |
| 761 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 762 | },{ |
| 763 | .id = V4L2_CID_PRIVATE_WHITECRUSH_UPPER, |
| 764 | .name = "whitecrush upper", |
| 765 | .minimum = 0, |
| 766 | .maximum = 255, |
| 767 | .step = 1, |
| 768 | .default_value = 0xCF, |
| 769 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 770 | },{ |
| 771 | .id = V4L2_CID_PRIVATE_WHITECRUSH_LOWER, |
| 772 | .name = "whitecrush lower", |
| 773 | .minimum = 0, |
| 774 | .maximum = 255, |
| 775 | .step = 1, |
| 776 | .default_value = 0x7F, |
| 777 | .type = V4L2_CTRL_TYPE_INTEGER, |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 778 | },{ |
| 779 | .id = V4L2_CID_PRIVATE_UV_RATIO, |
| 780 | .name = "uv ratio", |
| 781 | .minimum = 0, |
| 782 | .maximum = 100, |
| 783 | .step = 1, |
| 784 | .default_value = 50, |
| 785 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 786 | },{ |
| 787 | .id = V4L2_CID_PRIVATE_FULL_LUMA_RANGE, |
| 788 | .name = "full luma range", |
| 789 | .minimum = 0, |
| 790 | .maximum = 1, |
| 791 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 792 | },{ |
| 793 | .id = V4L2_CID_PRIVATE_CORING, |
| 794 | .name = "coring", |
| 795 | .minimum = 0, |
| 796 | .maximum = 3, |
| 797 | .step = 1, |
| 798 | .default_value = 0, |
| 799 | .type = V4L2_CTRL_TYPE_INTEGER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 802 | |
| 803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 806 | static const struct v4l2_queryctrl *ctrl_by_id(int id) |
| 807 | { |
| 808 | int i; |
| 809 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 810 | for (i = 0; i < ARRAY_SIZE(bttv_ctls); i++) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 811 | if (bttv_ctls[i].id == id) |
| 812 | return bttv_ctls+i; |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 813 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 814 | return NULL; |
| 815 | } |
| 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | /* ----------------------------------------------------------------------- */ |
| 818 | /* resource management */ |
| 819 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 820 | /* |
| 821 | RESOURCE_ allocated by freed by |
| 822 | |
| 823 | VIDEO_READ bttv_read 1) bttv_read 2) |
| 824 | |
| 825 | VIDEO_STREAM VIDIOC_STREAMON VIDIOC_STREAMOFF |
| 826 | VIDIOC_QBUF 1) bttv_release |
| 827 | VIDIOCMCAPTURE 1) |
| 828 | |
| 829 | OVERLAY VIDIOCCAPTURE on VIDIOCCAPTURE off |
| 830 | VIDIOC_OVERLAY on VIDIOC_OVERLAY off |
| 831 | 3) bttv_release |
| 832 | |
| 833 | VBI VIDIOC_STREAMON VIDIOC_STREAMOFF |
| 834 | VIDIOC_QBUF 1) bttv_release |
| 835 | bttv_read, bttv_poll 1) 4) |
| 836 | |
| 837 | 1) The resource must be allocated when we enter buffer prepare functions |
| 838 | and remain allocated while buffers are in the DMA queue. |
| 839 | 2) This is a single frame read. |
| 840 | 3) VIDIOC_S_FBUF and VIDIOC_S_FMT (OVERLAY) still work when |
| 841 | RESOURCE_OVERLAY is allocated. |
| 842 | 4) This is a continuous read, implies VIDIOC_STREAMON. |
| 843 | |
| 844 | Note this driver permits video input and standard changes regardless if |
| 845 | resources are allocated. |
| 846 | */ |
| 847 | |
| 848 | #define VBI_RESOURCES (RESOURCE_VBI) |
| 849 | #define VIDEO_RESOURCES (RESOURCE_VIDEO_READ | \ |
| 850 | RESOURCE_VIDEO_STREAM | \ |
| 851 | RESOURCE_OVERLAY) |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | static |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 854 | int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 856 | int xbits; /* mutual exclusive resources */ |
| 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | if (fh->resources & bit) |
| 859 | /* have it already allocated */ |
| 860 | return 1; |
| 861 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 862 | xbits = bit; |
| 863 | if (bit & (RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM)) |
| 864 | xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM; |
| 865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | /* is it free? */ |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 867 | if (btv->resources & xbits) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* no, someone else uses it */ |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 869 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 871 | |
| 872 | if ((bit & VIDEO_RESOURCES) |
| 873 | && 0 == (btv->resources & VIDEO_RESOURCES)) { |
| 874 | /* Do crop - use current, don't - use default parameters. */ |
| 875 | __s32 top = btv->crop[!!fh->do_crop].rect.top; |
| 876 | |
| 877 | if (btv->vbi_end > top) |
| 878 | goto fail; |
| 879 | |
| 880 | /* We cannot capture the same line as video and VBI data. |
| 881 | Claim scan lines crop[].rect.top to bottom. */ |
| 882 | btv->crop_start = top; |
| 883 | } else if (bit & VBI_RESOURCES) { |
| 884 | __s32 end = fh->vbi_fmt.end; |
| 885 | |
| 886 | if (end > btv->crop_start) |
| 887 | goto fail; |
| 888 | |
| 889 | /* Claim scan lines above fh->vbi_fmt.end. */ |
| 890 | btv->vbi_end = end; |
| 891 | } |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | /* it's free, grab it */ |
| 894 | fh->resources |= bit; |
| 895 | btv->resources |= bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | return 1; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 897 | |
| 898 | fail: |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 899 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | static |
| 903 | int check_btres(struct bttv_fh *fh, int bit) |
| 904 | { |
| 905 | return (fh->resources & bit); |
| 906 | } |
| 907 | |
| 908 | static |
| 909 | int locked_btres(struct bttv *btv, int bit) |
| 910 | { |
| 911 | return (btv->resources & bit); |
| 912 | } |
| 913 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 914 | /* Call with btv->lock down. */ |
| 915 | static void |
| 916 | disclaim_vbi_lines(struct bttv *btv) |
| 917 | { |
| 918 | btv->vbi_end = 0; |
| 919 | } |
| 920 | |
| 921 | /* Call with btv->lock down. */ |
| 922 | static void |
| 923 | disclaim_video_lines(struct bttv *btv) |
| 924 | { |
| 925 | const struct bttv_tvnorm *tvnorm; |
| 926 | u8 crop; |
| 927 | |
| 928 | tvnorm = &bttv_tvnorms[btv->tvnorm]; |
| 929 | btv->crop_start = tvnorm->cropcap.bounds.top |
| 930 | + tvnorm->cropcap.bounds.height; |
| 931 | |
| 932 | /* VBI capturing ends at VDELAY, start of video capturing, no |
| 933 | matter how many lines the VBI RISC program expects. When video |
| 934 | capturing is off, it shall no longer "preempt" VBI capturing, |
| 935 | so we set VDELAY to maximum. */ |
| 936 | crop = btread(BT848_E_CROP) | 0xc0; |
| 937 | btwrite(crop, BT848_E_CROP); |
| 938 | btwrite(0xfe, BT848_E_VDELAY_LO); |
| 939 | btwrite(crop, BT848_O_CROP); |
| 940 | btwrite(0xfe, BT848_O_VDELAY_LO); |
| 941 | } |
| 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | static |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 944 | void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | if ((fh->resources & bits) != bits) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 947 | /* trying to free resources not allocated by us ... */ |
| 948 | pr_err("BUG! (btres)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | fh->resources &= ~bits; |
| 951 | btv->resources &= ~bits; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 952 | |
| 953 | bits = btv->resources; |
| 954 | |
| 955 | if (0 == (bits & VIDEO_RESOURCES)) |
| 956 | disclaim_video_lines(btv); |
| 957 | |
| 958 | if (0 == (bits & VBI_RESOURCES)) |
| 959 | disclaim_vbi_lines(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* ----------------------------------------------------------------------- */ |
| 963 | /* If Bt848a or Bt849, use PLL for PAL/SECAM and crystal for NTSC */ |
| 964 | |
| 965 | /* Frequency = (F_input / PLL_X) * PLL_I.PLL_F/PLL_C |
| 966 | PLL_X = Reference pre-divider (0=1, 1=2) |
| 967 | PLL_C = Post divider (0=6, 1=4) |
| 968 | PLL_I = Integer input |
| 969 | PLL_F = Fractional input |
| 970 | |
| 971 | F_input = 28.636363 MHz: |
| 972 | PAL (CLKx2 = 35.46895 MHz): PLL_X = 1, PLL_I = 0x0E, PLL_F = 0xDCF9, PLL_C = 0 |
| 973 | */ |
| 974 | |
| 975 | static void set_pll_freq(struct bttv *btv, unsigned int fin, unsigned int fout) |
| 976 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 977 | unsigned char fl, fh, fi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 979 | /* prevent overflows */ |
| 980 | fin/=4; |
| 981 | fout/=4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 983 | fout*=12; |
| 984 | fi=fout/fin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 986 | fout=(fout%fin)*256; |
| 987 | fh=fout/fin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 989 | fout=(fout%fin)*256; |
| 990 | fl=fout/fin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 992 | btwrite(fl, BT848_PLL_F_LO); |
| 993 | btwrite(fh, BT848_PLL_F_HI); |
| 994 | btwrite(fi|BT848_PLL_X, BT848_PLL_XCI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | static void set_pll(struct bttv *btv) |
| 998 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 999 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1001 | if (!btv->pll.pll_crystal) |
| 1002 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | if (btv->pll.pll_ofreq == btv->pll.pll_current) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1005 | dprintk("%d: PLL: no change required\n", btv->c.nr); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1006 | return; |
| 1007 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1009 | if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) { |
| 1010 | /* no PLL needed */ |
| 1011 | if (btv->pll.pll_current == 0) |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 1012 | return; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1013 | if (bttv_verbose) |
| 1014 | pr_info("%d: PLL can sleep, using XTAL (%d)\n", |
| 1015 | btv->c.nr, btv->pll.pll_ifreq); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1016 | btwrite(0x00,BT848_TGCTRL); |
| 1017 | btwrite(0x00,BT848_PLL_XCI); |
| 1018 | btv->pll.pll_current = 0; |
| 1019 | return; |
| 1020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1022 | if (bttv_verbose) |
| 1023 | pr_info("%d: Setting PLL: %d => %d (needs up to 100ms)\n", |
| 1024 | btv->c.nr, |
| 1025 | btv->pll.pll_ifreq, btv->pll.pll_ofreq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq); |
| 1027 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1028 | for (i=0; i<10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | /* Let other people run while the PLL stabilizes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | msleep(10); |
| 1031 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1032 | if (btread(BT848_DSTATUS) & BT848_DSTATUS_PLOCK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | btwrite(0,BT848_DSTATUS); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1034 | } else { |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 1035 | btwrite(0x08,BT848_TGCTRL); |
| 1036 | btv->pll.pll_current = btv->pll.pll_ofreq; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1037 | if (bttv_verbose) |
| 1038 | pr_info("PLL set ok\n"); |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 1039 | return; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | btv->pll.pll_current = -1; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1043 | if (bttv_verbose) |
| 1044 | pr_info("Setting PLL failed\n"); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1045 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /* used to switch between the bt848's analog/digital video capture modes */ |
| 1049 | static void bt848A_set_timing(struct bttv *btv) |
| 1050 | { |
| 1051 | int i, len; |
| 1052 | int table_idx = bttv_tvnorms[btv->tvnorm].sram; |
| 1053 | int fsc = bttv_tvnorms[btv->tvnorm].Fsc; |
| 1054 | |
Trent Piepho | 5221e21 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 1055 | if (btv->input == btv->dig) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1056 | dprintk("%d: load digital timing table (table_idx=%d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | btv->c.nr,table_idx); |
| 1058 | |
| 1059 | /* timing change...reset timing generator address */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1060 | btwrite(0x00, BT848_TGCTRL); |
| 1061 | btwrite(0x02, BT848_TGCTRL); |
| 1062 | btwrite(0x00, BT848_TGCTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
| 1064 | len=SRAM_Table[table_idx][0]; |
| 1065 | for(i = 1; i <= len; i++) |
| 1066 | btwrite(SRAM_Table[table_idx][i],BT848_TGLB); |
| 1067 | btv->pll.pll_ofreq = 27000000; |
| 1068 | |
| 1069 | set_pll(btv); |
| 1070 | btwrite(0x11, BT848_TGCTRL); |
| 1071 | btwrite(0x41, BT848_DVSIF); |
| 1072 | } else { |
| 1073 | btv->pll.pll_ofreq = fsc; |
| 1074 | set_pll(btv); |
| 1075 | btwrite(0x0, BT848_DVSIF); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | /* ----------------------------------------------------------------------- */ |
| 1080 | |
| 1081 | static void bt848_bright(struct bttv *btv, int bright) |
| 1082 | { |
| 1083 | int value; |
| 1084 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1085 | // printk("set bright: %d\n", bright); // DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | btv->bright = bright; |
| 1087 | |
| 1088 | /* We want -128 to 127 we get 0-65535 */ |
| 1089 | value = (bright >> 8) - 128; |
| 1090 | btwrite(value & 0xff, BT848_BRIGHT); |
| 1091 | } |
| 1092 | |
| 1093 | static void bt848_hue(struct bttv *btv, int hue) |
| 1094 | { |
| 1095 | int value; |
| 1096 | |
| 1097 | btv->hue = hue; |
| 1098 | |
| 1099 | /* -128 to 127 */ |
| 1100 | value = (hue >> 8) - 128; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1101 | btwrite(value & 0xff, BT848_HUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | static void bt848_contrast(struct bttv *btv, int cont) |
| 1105 | { |
| 1106 | int value,hibit; |
| 1107 | |
| 1108 | btv->contrast = cont; |
| 1109 | |
| 1110 | /* 0-511 */ |
| 1111 | value = (cont >> 7); |
| 1112 | hibit = (value >> 6) & 4; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1113 | btwrite(value & 0xff, BT848_CONTRAST_LO); |
| 1114 | btaor(hibit, ~4, BT848_E_CONTROL); |
| 1115 | btaor(hibit, ~4, BT848_O_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static void bt848_sat(struct bttv *btv, int color) |
| 1119 | { |
| 1120 | int val_u,val_v,hibits; |
| 1121 | |
| 1122 | btv->saturation = color; |
| 1123 | |
| 1124 | /* 0-511 for the color */ |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 1125 | val_u = ((color * btv->opt_uv_ratio) / 50) >> 7; |
| 1126 | val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1127 | hibits = (val_u >> 7) & 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | hibits |= (val_v >> 8) & 1; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1129 | btwrite(val_u & 0xff, BT848_SAT_U_LO); |
| 1130 | btwrite(val_v & 0xff, BT848_SAT_V_LO); |
| 1131 | btaor(hibits, ~3, BT848_E_CONTROL); |
| 1132 | btaor(hibits, ~3, BT848_O_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | /* ----------------------------------------------------------------------- */ |
| 1136 | |
| 1137 | static int |
| 1138 | video_mux(struct bttv *btv, unsigned int input) |
| 1139 | { |
| 1140 | int mux,mask2; |
| 1141 | |
| 1142 | if (input >= bttv_tvcards[btv->c.type].video_inputs) |
| 1143 | return -EINVAL; |
| 1144 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1145 | /* needed by RemoteVideo MX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | mask2 = bttv_tvcards[btv->c.type].gpiomask2; |
| 1147 | if (mask2) |
| 1148 | gpio_inout(mask2,mask2); |
| 1149 | |
| 1150 | if (input == btv->svhs) { |
| 1151 | btor(BT848_CONTROL_COMP, BT848_E_CONTROL); |
| 1152 | btor(BT848_CONTROL_COMP, BT848_O_CONTROL); |
| 1153 | } else { |
| 1154 | btand(~BT848_CONTROL_COMP, BT848_E_CONTROL); |
| 1155 | btand(~BT848_CONTROL_COMP, BT848_O_CONTROL); |
| 1156 | } |
Trent Piepho | 6f98700 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 1157 | mux = bttv_muxsel(btv, input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | btaor(mux<<5, ~(3<<5), BT848_IFORM); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1159 | dprintk("%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | |
| 1161 | /* card specific hook */ |
| 1162 | if(bttv_tvcards[btv->c.type].muxsel_hook) |
| 1163 | bttv_tvcards[btv->c.type].muxsel_hook (btv, input); |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static char *audio_modes[] = { |
| 1168 | "audio: tuner", "audio: radio", "audio: extern", |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1169 | "audio: intern", "audio: mute" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | }; |
| 1171 | |
| 1172 | static int |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1173 | audio_mux(struct bttv *btv, int input, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | { |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1175 | int gpio_val, signal; |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1176 | struct v4l2_control ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
| 1178 | gpio_inout(bttv_tvcards[btv->c.type].gpiomask, |
| 1179 | bttv_tvcards[btv->c.type].gpiomask); |
| 1180 | signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC; |
| 1181 | |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1182 | btv->mute = mute; |
| 1183 | btv->audio = input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1185 | /* automute */ |
| 1186 | mute = mute || (btv->opt_automute && !signal && !btv->radio_user); |
| 1187 | |
| 1188 | if (mute) |
| 1189 | gpio_val = bttv_tvcards[btv->c.type].gpiomute; |
| 1190 | else |
| 1191 | gpio_val = bttv_tvcards[btv->c.type].gpiomux[input]; |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1192 | |
Trent Piepho | 72134a6 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 1193 | switch (btv->c.type) { |
| 1194 | case BTTV_BOARD_VOODOOTV_FM: |
| 1195 | case BTTV_BOARD_VOODOOTV_200: |
| 1196 | gpio_val = bttv_tda9880_setnorm(btv, gpio_val); |
| 1197 | break; |
| 1198 | |
| 1199 | default: |
| 1200 | gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val); |
| 1201 | } |
| 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | if (bttv_gpio) |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1204 | bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]); |
| 1205 | if (in_interrupt()) |
| 1206 | return 0; |
| 1207 | |
| 1208 | ctrl.id = V4L2_CID_AUDIO_MUTE; |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1209 | ctrl.value = btv->mute; |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 1210 | bttv_call_all(btv, core, s_ctrl, &ctrl); |
| 1211 | if (btv->sd_msp34xx) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1212 | u32 in; |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1213 | |
| 1214 | /* Note: the inputs tuner/radio/extern/intern are translated |
| 1215 | to msp routings. This assumes common behavior for all msp3400 |
| 1216 | based TV cards. When this assumption fails, then the |
| 1217 | specific MSP routing must be added to the card table. |
| 1218 | For now this is sufficient. */ |
| 1219 | switch (input) { |
| 1220 | case TVAUDIO_INPUT_RADIO: |
Hans de Goede | 7025e52 | 2012-05-21 07:46:22 -0300 | [diff] [blame] | 1221 | /* Some boards need the msp do to the radio demod */ |
| 1222 | if (btv->radio_uses_msp_demodulator) { |
| 1223 | in = MSP_INPUT_DEFAULT; |
| 1224 | break; |
| 1225 | } |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1226 | in = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1, |
Hans Verkuil | 0715172 | 2006-04-01 18:03:23 -0300 | [diff] [blame] | 1227 | MSP_DSP_IN_SCART, MSP_DSP_IN_SCART); |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1228 | break; |
| 1229 | case TVAUDIO_INPUT_EXTERN: |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1230 | in = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1, |
Hans Verkuil | 0715172 | 2006-04-01 18:03:23 -0300 | [diff] [blame] | 1231 | MSP_DSP_IN_SCART, MSP_DSP_IN_SCART); |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1232 | break; |
| 1233 | case TVAUDIO_INPUT_INTERN: |
| 1234 | /* Yes, this is the same input as for RADIO. I doubt |
| 1235 | if this is ever used. The only board with an INTERN |
| 1236 | input is the BTTV_BOARD_AVERMEDIA98. I wonder how |
| 1237 | that was tested. My guess is that the whole INTERN |
| 1238 | input does not work. */ |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1239 | in = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1, |
Hans Verkuil | 0715172 | 2006-04-01 18:03:23 -0300 | [diff] [blame] | 1240 | MSP_DSP_IN_SCART, MSP_DSP_IN_SCART); |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1241 | break; |
| 1242 | case TVAUDIO_INPUT_TUNER: |
| 1243 | default: |
Wade Berrier | 434b252 | 2007-06-25 13:02:16 -0300 | [diff] [blame] | 1244 | /* This is the only card that uses TUNER2, and afaik, |
| 1245 | is the only difference between the VOODOOTV_FM |
| 1246 | and VOODOOTV_200 */ |
| 1247 | if (btv->c.type == BTTV_BOARD_VOODOOTV_200) |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1248 | in = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER2, \ |
Wade Berrier | 434b252 | 2007-06-25 13:02:16 -0300 | [diff] [blame] | 1249 | MSP_DSP_IN_TUNER, MSP_DSP_IN_TUNER); |
| 1250 | else |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1251 | in = MSP_INPUT_DEFAULT; |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1252 | break; |
| 1253 | } |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1254 | v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing, |
| 1255 | in, MSP_OUTPUT_DEFAULT, 0); |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1256 | } |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 1257 | if (btv->sd_tvaudio) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1258 | v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing, |
| 1259 | input, 0, 0); |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 1260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | return 0; |
| 1262 | } |
| 1263 | |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 1264 | static inline int |
| 1265 | audio_mute(struct bttv *btv, int mute) |
| 1266 | { |
| 1267 | return audio_mux(btv, btv->audio, mute); |
| 1268 | } |
| 1269 | |
| 1270 | static inline int |
| 1271 | audio_input(struct bttv *btv, int input) |
| 1272 | { |
| 1273 | return audio_mux(btv, input, btv->mute); |
| 1274 | } |
| 1275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | static void |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1277 | bttv_crop_calc_limits(struct bttv_crop *c) |
| 1278 | { |
| 1279 | /* Scale factor min. 1:1, max. 16:1. Min. image size |
| 1280 | 48 x 32. Scaled width must be a multiple of 4. */ |
| 1281 | |
| 1282 | if (1) { |
| 1283 | /* For bug compatibility with VIDIOCGCAP and image |
| 1284 | size checks in earlier driver versions. */ |
| 1285 | c->min_scaled_width = 48; |
| 1286 | c->min_scaled_height = 32; |
| 1287 | } else { |
| 1288 | c->min_scaled_width = |
| 1289 | (max(48, c->rect.width >> 4) + 3) & ~3; |
| 1290 | c->min_scaled_height = |
| 1291 | max(32, c->rect.height >> 4); |
| 1292 | } |
| 1293 | |
| 1294 | c->max_scaled_width = c->rect.width & ~3; |
| 1295 | c->max_scaled_height = c->rect.height; |
| 1296 | } |
| 1297 | |
| 1298 | static void |
Trent Piepho | 4ef2ccc | 2009-01-28 21:32:58 -0300 | [diff] [blame] | 1299 | bttv_crop_reset(struct bttv_crop *c, unsigned int norm) |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1300 | { |
| 1301 | c->rect = bttv_tvnorms[norm].cropcap.defrect; |
| 1302 | bttv_crop_calc_limits(c); |
| 1303 | } |
| 1304 | |
| 1305 | /* Call with btv->lock down. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | static int |
| 1307 | set_tvnorm(struct bttv *btv, unsigned int norm) |
| 1308 | { |
| 1309 | const struct bttv_tvnorm *tvnorm; |
Nickolay V. Shmyrev | 302f61a | 2007-10-26 10:53:21 -0300 | [diff] [blame] | 1310 | v4l2_std_id id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Trent Piepho | 4ef2ccc | 2009-01-28 21:32:58 -0300 | [diff] [blame] | 1312 | BUG_ON(norm >= BTTV_TVNORMS); |
| 1313 | BUG_ON(btv->tvnorm >= BTTV_TVNORMS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | tvnorm = &bttv_tvnorms[norm]; |
| 1316 | |
Mike Isely | 2de26c0 | 2009-09-21 12:42:22 -0300 | [diff] [blame] | 1317 | if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap, |
Trent Piepho | 4ef2ccc | 2009-01-28 21:32:58 -0300 | [diff] [blame] | 1318 | sizeof (tvnorm->cropcap))) { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1319 | bttv_crop_reset(&btv->crop[0], norm); |
| 1320 | btv->crop[1] = btv->crop[0]; /* current = default */ |
| 1321 | |
| 1322 | if (0 == (btv->resources & VIDEO_RESOURCES)) { |
| 1323 | btv->crop_start = tvnorm->cropcap.bounds.top |
| 1324 | + tvnorm->cropcap.bounds.height; |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | btv->tvnorm = norm; |
| 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | btwrite(tvnorm->adelay, BT848_ADELAY); |
| 1331 | btwrite(tvnorm->bdelay, BT848_BDELAY); |
| 1332 | btaor(tvnorm->iform,~(BT848_IFORM_NORM|BT848_IFORM_XTBOTH), |
| 1333 | BT848_IFORM); |
| 1334 | btwrite(tvnorm->vbipack, BT848_VBI_PACK_SIZE); |
| 1335 | btwrite(1, BT848_VBI_PACK_DEL); |
| 1336 | bt848A_set_timing(btv); |
| 1337 | |
| 1338 | switch (btv->c.type) { |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 1339 | case BTTV_BOARD_VOODOOTV_FM: |
Wade Berrier | 434b252 | 2007-06-25 13:02:16 -0300 | [diff] [blame] | 1340 | case BTTV_BOARD_VOODOOTV_200: |
Trent Piepho | 72134a6 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 1341 | bttv_tda9880_setnorm(btv, gpio_read()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
Nickolay V. Shmyrev | 302f61a | 2007-10-26 10:53:21 -0300 | [diff] [blame] | 1344 | id = tvnorm->v4l2_id; |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 1345 | bttv_call_all(btv, core, s_std, id); |
Nickolay V. Shmyrev | 302f61a | 2007-10-26 10:53:21 -0300 | [diff] [blame] | 1346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | return 0; |
| 1348 | } |
| 1349 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1350 | /* Call with btv->lock down. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | static void |
Trent Piepho | 333408f | 2007-07-03 15:08:10 -0300 | [diff] [blame] | 1352 | set_input(struct bttv *btv, unsigned int input, unsigned int norm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | { |
| 1354 | unsigned long flags; |
| 1355 | |
| 1356 | btv->input = input; |
| 1357 | if (irq_iswitch) { |
| 1358 | spin_lock_irqsave(&btv->s_lock,flags); |
| 1359 | if (btv->curr.frame_irq) { |
| 1360 | /* active capture -> delayed input switch */ |
| 1361 | btv->new_input = input; |
| 1362 | } else { |
| 1363 | video_mux(btv,input); |
| 1364 | } |
| 1365 | spin_unlock_irqrestore(&btv->s_lock,flags); |
| 1366 | } else { |
| 1367 | video_mux(btv,input); |
| 1368 | } |
Trent Piepho | abb0362 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 1369 | audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ? |
| 1370 | TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN); |
Trent Piepho | 333408f | 2007-07-03 15:08:10 -0300 | [diff] [blame] | 1371 | set_tvnorm(btv, norm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | static void init_irqreg(struct bttv *btv) |
| 1375 | { |
| 1376 | /* clear status */ |
| 1377 | btwrite(0xfffffUL, BT848_INT_STAT); |
| 1378 | |
| 1379 | if (bttv_tvcards[btv->c.type].no_video) { |
| 1380 | /* i2c only */ |
| 1381 | btwrite(BT848_INT_I2CDONE, |
| 1382 | BT848_INT_MASK); |
| 1383 | } else { |
| 1384 | /* full video */ |
| 1385 | btwrite((btv->triton1) | |
| 1386 | (btv->gpioirq ? BT848_INT_GPINT : 0) | |
| 1387 | BT848_INT_SCERR | |
| 1388 | (fdsr ? BT848_INT_FDSR : 0) | |
Jean Delvare | eb1b27b | 2008-08-30 10:18:21 -0300 | [diff] [blame] | 1389 | BT848_INT_RISCI | BT848_INT_OCERR | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | BT848_INT_FMTCHG|BT848_INT_HLOCK| |
| 1391 | BT848_INT_I2CDONE, |
| 1392 | BT848_INT_MASK); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | static void init_bt848(struct bttv *btv) |
| 1397 | { |
| 1398 | int val; |
| 1399 | |
| 1400 | if (bttv_tvcards[btv->c.type].no_video) { |
| 1401 | /* very basic init only */ |
| 1402 | init_irqreg(btv); |
| 1403 | return; |
| 1404 | } |
| 1405 | |
| 1406 | btwrite(0x00, BT848_CAP_CTL); |
| 1407 | btwrite(BT848_COLOR_CTL_GAMMA, BT848_COLOR_CTL); |
| 1408 | btwrite(BT848_IFORM_XTAUTO | BT848_IFORM_AUTO, BT848_IFORM); |
| 1409 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1410 | /* set planar and packed mode trigger points and */ |
| 1411 | /* set rising edge of inverted GPINTR pin as irq trigger */ |
| 1412 | btwrite(BT848_GPIO_DMA_CTL_PKTP_32| |
| 1413 | BT848_GPIO_DMA_CTL_PLTP1_16| |
| 1414 | BT848_GPIO_DMA_CTL_PLTP23_16| |
| 1415 | BT848_GPIO_DMA_CTL_GPINTC| |
| 1416 | BT848_GPIO_DMA_CTL_GPINTI, |
| 1417 | BT848_GPIO_DMA_CTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | |
| 1419 | val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1420 | btwrite(val, BT848_E_SCLOOP); |
| 1421 | btwrite(val, BT848_O_SCLOOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1423 | btwrite(0x20, BT848_E_VSCALE_HI); |
| 1424 | btwrite(0x20, BT848_O_VSCALE_HI); |
| 1425 | btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | BT848_ADC); |
| 1427 | |
| 1428 | btwrite(whitecrush_upper, BT848_WC_UP); |
| 1429 | btwrite(whitecrush_lower, BT848_WC_DOWN); |
| 1430 | |
| 1431 | if (btv->opt_lumafilter) { |
| 1432 | btwrite(0, BT848_E_CONTROL); |
| 1433 | btwrite(0, BT848_O_CONTROL); |
| 1434 | } else { |
| 1435 | btwrite(BT848_CONTROL_LDEC, BT848_E_CONTROL); |
| 1436 | btwrite(BT848_CONTROL_LDEC, BT848_O_CONTROL); |
| 1437 | } |
| 1438 | |
| 1439 | bt848_bright(btv, btv->bright); |
| 1440 | bt848_hue(btv, btv->hue); |
| 1441 | bt848_contrast(btv, btv->contrast); |
| 1442 | bt848_sat(btv, btv->saturation); |
| 1443 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1444 | /* interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | init_irqreg(btv); |
| 1446 | } |
| 1447 | |
| 1448 | static void bttv_reinit_bt848(struct bttv *btv) |
| 1449 | { |
| 1450 | unsigned long flags; |
| 1451 | |
| 1452 | if (bttv_verbose) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1453 | pr_info("%d: reset, reinitialize\n", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | spin_lock_irqsave(&btv->s_lock,flags); |
| 1455 | btv->errors=0; |
| 1456 | bttv_set_dma(btv,0); |
| 1457 | spin_unlock_irqrestore(&btv->s_lock,flags); |
| 1458 | |
| 1459 | init_bt848(btv); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1460 | btv->pll.pll_current = -1; |
Trent Piepho | 333408f | 2007-07-03 15:08:10 -0300 | [diff] [blame] | 1461 | set_input(btv, btv->input, btv->tvnorm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1464 | static int bttv_g_ctrl(struct file *file, void *priv, |
| 1465 | struct v4l2_control *c) |
| 1466 | { |
| 1467 | struct bttv_fh *fh = priv; |
| 1468 | struct bttv *btv = fh->btv; |
| 1469 | |
| 1470 | switch (c->id) { |
| 1471 | case V4L2_CID_BRIGHTNESS: |
| 1472 | c->value = btv->bright; |
| 1473 | break; |
| 1474 | case V4L2_CID_HUE: |
| 1475 | c->value = btv->hue; |
| 1476 | break; |
| 1477 | case V4L2_CID_CONTRAST: |
| 1478 | c->value = btv->contrast; |
| 1479 | break; |
| 1480 | case V4L2_CID_SATURATION: |
| 1481 | c->value = btv->saturation; |
| 1482 | break; |
Guilherme Herrmann Destefani | 34e59a7 | 2012-09-25 18:10:52 -0300 | [diff] [blame] | 1483 | case V4L2_CID_COLOR_KILLER: |
| 1484 | c->value = btv->opt_color_killer; |
| 1485 | break; |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1486 | |
| 1487 | case V4L2_CID_AUDIO_MUTE: |
| 1488 | case V4L2_CID_AUDIO_VOLUME: |
| 1489 | case V4L2_CID_AUDIO_BALANCE: |
| 1490 | case V4L2_CID_AUDIO_BASS: |
| 1491 | case V4L2_CID_AUDIO_TREBLE: |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 1492 | bttv_call_all(btv, core, g_ctrl, c); |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1493 | break; |
| 1494 | |
| 1495 | case V4L2_CID_PRIVATE_CHROMA_AGC: |
| 1496 | c->value = btv->opt_chroma_agc; |
| 1497 | break; |
| 1498 | case V4L2_CID_PRIVATE_COMBFILTER: |
| 1499 | c->value = btv->opt_combfilter; |
| 1500 | break; |
| 1501 | case V4L2_CID_PRIVATE_LUMAFILTER: |
| 1502 | c->value = btv->opt_lumafilter; |
| 1503 | break; |
| 1504 | case V4L2_CID_PRIVATE_AUTOMUTE: |
| 1505 | c->value = btv->opt_automute; |
| 1506 | break; |
| 1507 | case V4L2_CID_PRIVATE_AGC_CRUSH: |
| 1508 | c->value = btv->opt_adc_crush; |
| 1509 | break; |
| 1510 | case V4L2_CID_PRIVATE_VCR_HACK: |
| 1511 | c->value = btv->opt_vcr_hack; |
| 1512 | break; |
| 1513 | case V4L2_CID_PRIVATE_WHITECRUSH_UPPER: |
| 1514 | c->value = btv->opt_whitecrush_upper; |
| 1515 | break; |
| 1516 | case V4L2_CID_PRIVATE_WHITECRUSH_LOWER: |
| 1517 | c->value = btv->opt_whitecrush_lower; |
| 1518 | break; |
| 1519 | case V4L2_CID_PRIVATE_UV_RATIO: |
| 1520 | c->value = btv->opt_uv_ratio; |
| 1521 | break; |
| 1522 | case V4L2_CID_PRIVATE_FULL_LUMA_RANGE: |
| 1523 | c->value = btv->opt_full_luma_range; |
| 1524 | break; |
| 1525 | case V4L2_CID_PRIVATE_CORING: |
| 1526 | c->value = btv->opt_coring; |
| 1527 | break; |
| 1528 | default: |
| 1529 | return -EINVAL; |
| 1530 | } |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | static int bttv_s_ctrl(struct file *file, void *f, |
| 1535 | struct v4l2_control *c) |
| 1536 | { |
| 1537 | int err; |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1538 | struct bttv_fh *fh = f; |
| 1539 | struct bttv *btv = fh->btv; |
| 1540 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 1541 | err = v4l2_prio_check(&btv->prio, fh->prio); |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1542 | if (0 != err) |
| 1543 | return err; |
| 1544 | |
| 1545 | switch (c->id) { |
| 1546 | case V4L2_CID_BRIGHTNESS: |
| 1547 | bt848_bright(btv, c->value); |
| 1548 | break; |
| 1549 | case V4L2_CID_HUE: |
| 1550 | bt848_hue(btv, c->value); |
| 1551 | break; |
| 1552 | case V4L2_CID_CONTRAST: |
| 1553 | bt848_contrast(btv, c->value); |
| 1554 | break; |
| 1555 | case V4L2_CID_SATURATION: |
| 1556 | bt848_sat(btv, c->value); |
| 1557 | break; |
Guilherme Herrmann Destefani | 34e59a7 | 2012-09-25 18:10:52 -0300 | [diff] [blame] | 1558 | case V4L2_CID_COLOR_KILLER: |
| 1559 | btv->opt_color_killer = c->value; |
| 1560 | if (btv->opt_color_killer) { |
| 1561 | btor(BT848_SCLOOP_CKILL, BT848_E_SCLOOP); |
| 1562 | btor(BT848_SCLOOP_CKILL, BT848_O_SCLOOP); |
| 1563 | } else { |
| 1564 | btand(~BT848_SCLOOP_CKILL, BT848_E_SCLOOP); |
| 1565 | btand(~BT848_SCLOOP_CKILL, BT848_O_SCLOOP); |
| 1566 | } |
| 1567 | break; |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1568 | case V4L2_CID_AUDIO_MUTE: |
| 1569 | audio_mute(btv, c->value); |
| 1570 | /* fall through */ |
| 1571 | case V4L2_CID_AUDIO_VOLUME: |
| 1572 | if (btv->volume_gpio) |
| 1573 | btv->volume_gpio(btv, c->value); |
| 1574 | |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 1575 | bttv_call_all(btv, core, s_ctrl, c); |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1576 | break; |
| 1577 | case V4L2_CID_AUDIO_BALANCE: |
| 1578 | case V4L2_CID_AUDIO_BASS: |
| 1579 | case V4L2_CID_AUDIO_TREBLE: |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 1580 | bttv_call_all(btv, core, s_ctrl, c); |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1581 | break; |
| 1582 | |
| 1583 | case V4L2_CID_PRIVATE_CHROMA_AGC: |
| 1584 | btv->opt_chroma_agc = c->value; |
Guilherme Herrmann Destefani | 34e59a7 | 2012-09-25 18:10:52 -0300 | [diff] [blame] | 1585 | if (btv->opt_chroma_agc) { |
| 1586 | btor(BT848_SCLOOP_CAGC, BT848_E_SCLOOP); |
| 1587 | btor(BT848_SCLOOP_CAGC, BT848_O_SCLOOP); |
| 1588 | } else { |
| 1589 | btand(~BT848_SCLOOP_CAGC, BT848_E_SCLOOP); |
| 1590 | btand(~BT848_SCLOOP_CAGC, BT848_O_SCLOOP); |
| 1591 | } |
Mauro Carvalho Chehab | 04a94d3 | 2007-12-27 22:23:34 -0300 | [diff] [blame] | 1592 | break; |
| 1593 | case V4L2_CID_PRIVATE_COMBFILTER: |
| 1594 | btv->opt_combfilter = c->value; |
| 1595 | break; |
| 1596 | case V4L2_CID_PRIVATE_LUMAFILTER: |
| 1597 | btv->opt_lumafilter = c->value; |
| 1598 | if (btv->opt_lumafilter) { |
| 1599 | btand(~BT848_CONTROL_LDEC, BT848_E_CONTROL); |
| 1600 | btand(~BT848_CONTROL_LDEC, BT848_O_CONTROL); |
| 1601 | } else { |
| 1602 | btor(BT848_CONTROL_LDEC, BT848_E_CONTROL); |
| 1603 | btor(BT848_CONTROL_LDEC, BT848_O_CONTROL); |
| 1604 | } |
| 1605 | break; |
| 1606 | case V4L2_CID_PRIVATE_AUTOMUTE: |
| 1607 | btv->opt_automute = c->value; |
| 1608 | break; |
| 1609 | case V4L2_CID_PRIVATE_AGC_CRUSH: |
| 1610 | btv->opt_adc_crush = c->value; |
| 1611 | btwrite(BT848_ADC_RESERVED | |
| 1612 | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0), |
| 1613 | BT848_ADC); |
| 1614 | break; |
| 1615 | case V4L2_CID_PRIVATE_VCR_HACK: |
| 1616 | btv->opt_vcr_hack = c->value; |
| 1617 | break; |
| 1618 | case V4L2_CID_PRIVATE_WHITECRUSH_UPPER: |
| 1619 | btv->opt_whitecrush_upper = c->value; |
| 1620 | btwrite(c->value, BT848_WC_UP); |
| 1621 | break; |
| 1622 | case V4L2_CID_PRIVATE_WHITECRUSH_LOWER: |
| 1623 | btv->opt_whitecrush_lower = c->value; |
| 1624 | btwrite(c->value, BT848_WC_DOWN); |
| 1625 | break; |
| 1626 | case V4L2_CID_PRIVATE_UV_RATIO: |
| 1627 | btv->opt_uv_ratio = c->value; |
| 1628 | bt848_sat(btv, btv->saturation); |
| 1629 | break; |
| 1630 | case V4L2_CID_PRIVATE_FULL_LUMA_RANGE: |
| 1631 | btv->opt_full_luma_range = c->value; |
| 1632 | btaor((c->value<<7), ~BT848_OFORM_RANGE, BT848_OFORM); |
| 1633 | break; |
| 1634 | case V4L2_CID_PRIVATE_CORING: |
| 1635 | btv->opt_coring = c->value; |
| 1636 | btaor((c->value<<5), ~BT848_OFORM_CORE32, BT848_OFORM); |
| 1637 | break; |
| 1638 | default: |
| 1639 | return -EINVAL; |
| 1640 | } |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | /* ----------------------------------------------------------------------- */ |
| 1645 | |
| 1646 | void bttv_gpio_tracking(struct bttv *btv, char *comment) |
| 1647 | { |
| 1648 | unsigned int outbits, data; |
| 1649 | outbits = btread(BT848_GPIO_OUT_EN); |
| 1650 | data = btread(BT848_GPIO_DATA); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1651 | pr_debug("%d: gpio: en=%08x, out=%08x in=%08x [%s]\n", |
| 1652 | btv->c.nr, outbits, data & outbits, data & ~outbits, comment); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | static void bttv_field_count(struct bttv *btv) |
| 1656 | { |
| 1657 | int need_count = 0; |
| 1658 | |
| 1659 | if (btv->users) |
| 1660 | need_count++; |
| 1661 | |
| 1662 | if (need_count) { |
| 1663 | /* start field counter */ |
| 1664 | btor(BT848_INT_VSYNC,BT848_INT_MASK); |
| 1665 | } else { |
| 1666 | /* stop field counter */ |
| 1667 | btand(~BT848_INT_VSYNC,BT848_INT_MASK); |
| 1668 | btv->field_count = 0; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | static const struct bttv_format* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | format_by_fourcc(int fourcc) |
| 1674 | { |
| 1675 | unsigned int i; |
| 1676 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1677 | for (i = 0; i < FORMATS; i++) { |
| 1678 | if (-1 == formats[i].fourcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | continue; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1680 | if (formats[i].fourcc == fourcc) |
| 1681 | return formats+i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | } |
| 1683 | return NULL; |
| 1684 | } |
| 1685 | |
| 1686 | /* ----------------------------------------------------------------------- */ |
| 1687 | /* misc helpers */ |
| 1688 | |
| 1689 | static int |
| 1690 | bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh, |
| 1691 | struct bttv_buffer *new) |
| 1692 | { |
| 1693 | struct bttv_buffer *old; |
| 1694 | unsigned long flags; |
| 1695 | int retval = 0; |
| 1696 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1697 | dprintk("switch_overlay: enter [new=%p]\n", new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | if (new) |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1699 | new->vb.state = VIDEOBUF_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | spin_lock_irqsave(&btv->s_lock,flags); |
| 1701 | old = btv->screen; |
| 1702 | btv->screen = new; |
| 1703 | btv->loop_irq |= 1; |
| 1704 | bttv_set_dma(btv, 0x03); |
| 1705 | spin_unlock_irqrestore(&btv->s_lock,flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | if (NULL != old) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 1707 | dprintk("switch_overlay: old=%p state is %d\n", |
| 1708 | old, old->vb.state); |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1709 | bttv_dma_free(&fh->cap,btv, old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | kfree(old); |
| 1711 | } |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1712 | if (NULL == new) |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 1713 | free_btres_lock(btv,fh,RESOURCE_OVERLAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | dprintk("switch_overlay: done\n"); |
| 1715 | return retval; |
| 1716 | } |
| 1717 | |
| 1718 | /* ----------------------------------------------------------------------- */ |
| 1719 | /* video4linux (1) interface */ |
| 1720 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1721 | static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv, |
| 1722 | struct bttv_buffer *buf, |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1723 | const struct bttv_format *fmt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | unsigned int width, unsigned int height, |
| 1725 | enum v4l2_field field) |
| 1726 | { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1727 | struct bttv_fh *fh = q->priv_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | int redo_dma_risc = 0; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1729 | struct bttv_crop c; |
| 1730 | int norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | int rc; |
| 1732 | |
| 1733 | /* check settings */ |
| 1734 | if (NULL == fmt) |
| 1735 | return -EINVAL; |
| 1736 | if (fmt->btformat == BT848_COLOR_FMT_RAW) { |
| 1737 | width = RAW_BPL; |
| 1738 | height = RAW_LINES*2; |
| 1739 | if (width*height > buf->vb.bsize) |
| 1740 | return -EINVAL; |
| 1741 | buf->vb.size = buf->vb.bsize; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1742 | |
| 1743 | /* Make sure tvnorm and vbi_end remain consistent |
| 1744 | until we're done. */ |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1745 | |
| 1746 | norm = btv->tvnorm; |
| 1747 | |
| 1748 | /* In this mode capturing always starts at defrect.top |
| 1749 | (default VDELAY), ignoring cropping parameters. */ |
| 1750 | if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | return -EINVAL; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1752 | } |
| 1753 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1754 | c.rect = bttv_tvnorms[norm].cropcap.defrect; |
| 1755 | } else { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1756 | norm = btv->tvnorm; |
| 1757 | c = btv->crop[!!fh->do_crop]; |
| 1758 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1759 | if (width < c.min_scaled_width || |
| 1760 | width > c.max_scaled_width || |
| 1761 | height < c.min_scaled_height) |
| 1762 | return -EINVAL; |
| 1763 | |
| 1764 | switch (field) { |
| 1765 | case V4L2_FIELD_TOP: |
| 1766 | case V4L2_FIELD_BOTTOM: |
| 1767 | case V4L2_FIELD_ALTERNATE: |
| 1768 | /* btv->crop counts frame lines. Max. scale |
| 1769 | factor is 16:1 for frames, 8:1 for fields. */ |
| 1770 | if (height * 2 > c.max_scaled_height) |
| 1771 | return -EINVAL; |
| 1772 | break; |
| 1773 | |
| 1774 | default: |
| 1775 | if (height > c.max_scaled_height) |
| 1776 | return -EINVAL; |
| 1777 | break; |
| 1778 | } |
| 1779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | buf->vb.size = (width * height * fmt->depth) >> 3; |
| 1781 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 1782 | return -EINVAL; |
| 1783 | } |
| 1784 | |
| 1785 | /* alloc + fill struct bttv_buffer (if changed) */ |
| 1786 | if (buf->vb.width != width || buf->vb.height != height || |
| 1787 | buf->vb.field != field || |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1788 | buf->tvnorm != norm || buf->fmt != fmt || |
| 1789 | buf->crop.top != c.rect.top || |
| 1790 | buf->crop.left != c.rect.left || |
| 1791 | buf->crop.width != c.rect.width || |
| 1792 | buf->crop.height != c.rect.height) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | buf->vb.width = width; |
| 1794 | buf->vb.height = height; |
| 1795 | buf->vb.field = field; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1796 | buf->tvnorm = norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | buf->fmt = fmt; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 1798 | buf->crop = c.rect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | redo_dma_risc = 1; |
| 1800 | } |
| 1801 | |
| 1802 | /* alloc risc memory */ |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1803 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | redo_dma_risc = 1; |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1805 | if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | goto fail; |
| 1807 | } |
| 1808 | |
| 1809 | if (redo_dma_risc) |
| 1810 | if (0 != (rc = bttv_buffer_risc(btv,buf))) |
| 1811 | goto fail; |
| 1812 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1813 | buf->vb.state = VIDEOBUF_PREPARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | return 0; |
| 1815 | |
| 1816 | fail: |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1817 | bttv_dma_free(q,btv,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | return rc; |
| 1819 | } |
| 1820 | |
| 1821 | static int |
| 1822 | buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) |
| 1823 | { |
| 1824 | struct bttv_fh *fh = q->priv_data; |
| 1825 | |
| 1826 | *size = fh->fmt->depth*fh->width*fh->height >> 3; |
| 1827 | if (0 == *count) |
| 1828 | *count = gbuffers; |
Andreas Bombe | dab7e31 | 2010-03-21 16:02:45 -0300 | [diff] [blame] | 1829 | if (*size * *count > gbuffers * gbufsize) |
| 1830 | *count = (gbuffers * gbufsize) / *size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | return 0; |
| 1832 | } |
| 1833 | |
| 1834 | static int |
| 1835 | buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
| 1836 | enum v4l2_field field) |
| 1837 | { |
| 1838 | struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); |
| 1839 | struct bttv_fh *fh = q->priv_data; |
| 1840 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1841 | return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | fh->width, fh->height, field); |
| 1843 | } |
| 1844 | |
| 1845 | static void |
| 1846 | buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 1847 | { |
| 1848 | struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); |
| 1849 | struct bttv_fh *fh = q->priv_data; |
| 1850 | struct bttv *btv = fh->btv; |
| 1851 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1852 | buf->vb.state = VIDEOBUF_QUEUED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | list_add_tail(&buf->vb.queue,&btv->capture); |
| 1854 | if (!btv->curr.frame_irq) { |
| 1855 | btv->loop_irq |= 1; |
| 1856 | bttv_set_dma(btv, 0x03); |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 1861 | { |
| 1862 | struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); |
| 1863 | struct bttv_fh *fh = q->priv_data; |
| 1864 | |
Michael Schimek | feaba7a | 2007-01-26 08:30:05 -0300 | [diff] [blame] | 1865 | bttv_dma_free(q,fh->btv,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | static struct videobuf_queue_ops bttv_video_qops = { |
| 1869 | .buf_setup = buffer_setup, |
| 1870 | .buf_prepare = buffer_prepare, |
| 1871 | .buf_queue = buffer_queue, |
| 1872 | .buf_release = buffer_release, |
| 1873 | }; |
| 1874 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 1875 | static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1877 | struct bttv_fh *fh = priv; |
| 1878 | struct bttv *btv = fh->btv; |
| 1879 | unsigned int i; |
| 1880 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 1882 | err = v4l2_prio_check(&btv->prio, fh->prio); |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1883 | if (err) |
| 1884 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1886 | for (i = 0; i < BTTV_TVNORMS; i++) |
| 1887 | if (*id & bttv_tvnorms[i].v4l2_id) |
| 1888 | break; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1889 | if (i == BTTV_TVNORMS) { |
| 1890 | err = -EINVAL; |
| 1891 | goto err; |
| 1892 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1894 | set_tvnorm(btv, i); |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1895 | |
| 1896 | err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1898 | return err; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1899 | } |
| 1900 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 1901 | static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1902 | { |
| 1903 | struct bttv_fh *fh = f; |
| 1904 | struct bttv *btv = fh->btv; |
| 1905 | |
| 1906 | if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML) |
| 1907 | *id = V4L2_STD_625_50; |
| 1908 | else |
| 1909 | *id = V4L2_STD_525_60; |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 1913 | static int bttv_enum_input(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1914 | struct v4l2_input *i) |
| 1915 | { |
| 1916 | struct bttv_fh *fh = priv; |
| 1917 | struct bttv *btv = fh->btv; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1918 | int rc = 0; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1919 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1920 | if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { |
| 1921 | rc = -EINVAL; |
| 1922 | goto err; |
| 1923 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1924 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1925 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Hans Verkuil | f74f89cb | 2013-01-31 08:45:13 -0300 | [diff] [blame] | 1926 | i->audioset = 0; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1927 | |
Trent Piepho | abb0362 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 1928 | if (btv->tuner_type != TUNER_ABSENT && i->index == 0) { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1929 | sprintf(i->name, "Television"); |
| 1930 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1931 | i->tuner = 0; |
| 1932 | } else if (i->index == btv->svhs) { |
| 1933 | sprintf(i->name, "S-Video"); |
| 1934 | } else { |
| 1935 | sprintf(i->name, "Composite%d", i->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1938 | if (i->index == btv->input) { |
| 1939 | __u32 dstatus = btread(BT848_DSTATUS); |
| 1940 | if (0 == (dstatus & BT848_DSTATUS_PRES)) |
| 1941 | i->status |= V4L2_IN_ST_NO_SIGNAL; |
| 1942 | if (0 == (dstatus & BT848_DSTATUS_HLOC)) |
| 1943 | i->status |= V4L2_IN_ST_NO_H_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1946 | i->std = BTTV_NORMS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1948 | err: |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1949 | |
| 1950 | return rc; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1951 | } |
Nickolay V. Shmyrev | 4b9b936 | 2006-08-25 16:53:04 -0300 | [diff] [blame] | 1952 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 1953 | static int bttv_g_input(struct file *file, void *priv, unsigned int *i) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1954 | { |
| 1955 | struct bttv_fh *fh = priv; |
| 1956 | struct bttv *btv = fh->btv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1958 | *i = btv->input; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1959 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1960 | return 0; |
| 1961 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 1963 | static int bttv_s_input(struct file *file, void *priv, unsigned int i) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1964 | { |
| 1965 | struct bttv_fh *fh = priv; |
| 1966 | struct bttv *btv = fh->btv; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1967 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1969 | err = v4l2_prio_check(&btv->prio, fh->prio); |
Hans Verkuil | f74f89cb | 2013-01-31 08:45:13 -0300 | [diff] [blame] | 1970 | if (err) |
| 1971 | return err; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1972 | |
Hans Verkuil | f74f89cb | 2013-01-31 08:45:13 -0300 | [diff] [blame] | 1973 | if (i >= bttv_tvcards[btv->c.type].video_inputs) |
| 1974 | return -EINVAL; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1975 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1976 | set_input(btv, i, btv->tvnorm); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1977 | return 0; |
| 1978 | } |
| 1979 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 1980 | static int bttv_s_tuner(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1981 | struct v4l2_tuner *t) |
| 1982 | { |
| 1983 | struct bttv_fh *fh = priv; |
| 1984 | struct bttv *btv = fh->btv; |
| 1985 | int err; |
| 1986 | |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 1987 | if (t->index) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1988 | return -EINVAL; |
| 1989 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1990 | err = v4l2_prio_check(&btv->prio, fh->prio); |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 1991 | if (err) |
| 1992 | return err; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 1993 | |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 1994 | bttv_call_all(btv, tuner, s_tuner, t); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1995 | |
| 1996 | if (btv->audio_mode_gpio) |
| 1997 | btv->audio_mode_gpio(btv, t, 1); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 1998 | return 0; |
| 1999 | } |
| 2000 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2001 | static int bttv_g_frequency(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2002 | struct v4l2_frequency *f) |
| 2003 | { |
| 2004 | struct bttv_fh *fh = priv; |
| 2005 | struct bttv *btv = fh->btv; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2006 | |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 2007 | if (f->tuner) |
| 2008 | return -EINVAL; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2009 | |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 2010 | f->frequency = btv->freq; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2011 | return 0; |
| 2012 | } |
| 2013 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2014 | static int bttv_s_frequency(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2015 | struct v4l2_frequency *f) |
| 2016 | { |
| 2017 | struct bttv_fh *fh = priv; |
| 2018 | struct bttv *btv = fh->btv; |
| 2019 | int err; |
| 2020 | |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 2021 | if (f->tuner) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2022 | return -EINVAL; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2023 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2024 | err = v4l2_prio_check(&btv->prio, fh->prio); |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 2025 | if (err) |
| 2026 | return err; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2027 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2028 | btv->freq = f->frequency; |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 2029 | bttv_call_all(btv, tuner, s_frequency, f); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2030 | if (btv->has_matchbox && btv->radio_user) |
| 2031 | tea5757_set_freq(btv, btv->freq); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2032 | return 0; |
| 2033 | } |
| 2034 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2035 | static int bttv_log_status(struct file *file, void *f) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2036 | { |
| 2037 | struct bttv_fh *fh = f; |
| 2038 | struct bttv *btv = fh->btv; |
| 2039 | |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 2040 | bttv_call_all(btv, core, log_status); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2041 | return 0; |
| 2042 | } |
| 2043 | |
Hans Verkuil | 1b9e94d | 2012-09-09 09:23:31 -0300 | [diff] [blame] | 2044 | static int bttv_g_chip_ident(struct file *file, void *f, struct v4l2_dbg_chip_ident *chip) |
| 2045 | { |
| 2046 | struct bttv_fh *fh = f; |
| 2047 | struct bttv *btv = fh->btv; |
| 2048 | |
| 2049 | chip->ident = V4L2_IDENT_NONE; |
| 2050 | chip->revision = 0; |
| 2051 | if (chip->match.type == V4L2_CHIP_MATCH_HOST) { |
| 2052 | if (v4l2_chip_match_host(&chip->match)) { |
| 2053 | chip->ident = btv->id; |
| 2054 | if (chip->ident == PCI_DEVICE_ID_FUSION879) |
| 2055 | chip->ident = V4L2_IDENT_BT879; |
| 2056 | } |
| 2057 | return 0; |
| 2058 | } |
| 2059 | if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER && |
| 2060 | chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR) |
| 2061 | return -EINVAL; |
| 2062 | /* TODO: is this correct? */ |
| 2063 | return bttv_call_all_err(btv, core, g_chip_ident, chip); |
| 2064 | } |
| 2065 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2066 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2067 | static int bttv_g_register(struct file *file, void *f, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 2068 | struct v4l2_dbg_register *reg) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2069 | { |
| 2070 | struct bttv_fh *fh = f; |
| 2071 | struct bttv *btv = fh->btv; |
| 2072 | |
| 2073 | if (!capable(CAP_SYS_ADMIN)) |
| 2074 | return -EPERM; |
| 2075 | |
Hans Verkuil | 1b9e94d | 2012-09-09 09:23:31 -0300 | [diff] [blame] | 2076 | if (!v4l2_chip_match_host(®->match)) { |
| 2077 | /* TODO: subdev errors should not be ignored, this should become a |
| 2078 | subdev helper function. */ |
| 2079 | bttv_call_all(btv, core, g_register, reg); |
| 2080 | return 0; |
| 2081 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2082 | |
| 2083 | /* bt848 has a 12-bit register space */ |
| 2084 | reg->reg &= 0xfff; |
| 2085 | reg->val = btread(reg->reg); |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 2086 | reg->size = 1; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2087 | |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2091 | static int bttv_s_register(struct file *file, void *f, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 2092 | struct v4l2_dbg_register *reg) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2093 | { |
| 2094 | struct bttv_fh *fh = f; |
| 2095 | struct bttv *btv = fh->btv; |
| 2096 | |
| 2097 | if (!capable(CAP_SYS_ADMIN)) |
| 2098 | return -EPERM; |
| 2099 | |
Hans Verkuil | 1b9e94d | 2012-09-09 09:23:31 -0300 | [diff] [blame] | 2100 | if (!v4l2_chip_match_host(®->match)) { |
| 2101 | /* TODO: subdev errors should not be ignored, this should become a |
| 2102 | subdev helper function. */ |
| 2103 | bttv_call_all(btv, core, s_register, reg); |
| 2104 | return 0; |
| 2105 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2106 | |
| 2107 | /* bt848 has a 12-bit register space */ |
| 2108 | reg->reg &= 0xfff; |
| 2109 | btwrite(reg->val, reg->reg); |
| 2110 | |
| 2111 | return 0; |
| 2112 | } |
| 2113 | #endif |
| 2114 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2115 | /* Given cropping boundaries b and the scaled width and height of a |
| 2116 | single field or frame, which must not exceed hardware limits, this |
| 2117 | function adjusts the cropping parameters c. */ |
| 2118 | static void |
| 2119 | bttv_crop_adjust (struct bttv_crop * c, |
| 2120 | const struct v4l2_rect * b, |
| 2121 | __s32 width, |
| 2122 | __s32 height, |
| 2123 | enum v4l2_field field) |
| 2124 | { |
| 2125 | __s32 frame_height = height << !V4L2_FIELD_HAS_BOTH(field); |
| 2126 | __s32 max_left; |
| 2127 | __s32 max_top; |
| 2128 | |
| 2129 | if (width < c->min_scaled_width) { |
| 2130 | /* Max. hor. scale factor 16:1. */ |
| 2131 | c->rect.width = width * 16; |
| 2132 | } else if (width > c->max_scaled_width) { |
| 2133 | /* Min. hor. scale factor 1:1. */ |
| 2134 | c->rect.width = width; |
| 2135 | |
| 2136 | max_left = b->left + b->width - width; |
| 2137 | max_left = min(max_left, (__s32) MAX_HDELAY); |
| 2138 | if (c->rect.left > max_left) |
| 2139 | c->rect.left = max_left; |
| 2140 | } |
| 2141 | |
| 2142 | if (height < c->min_scaled_height) { |
| 2143 | /* Max. vert. scale factor 16:1, single fields 8:1. */ |
| 2144 | c->rect.height = height * 16; |
| 2145 | } else if (frame_height > c->max_scaled_height) { |
| 2146 | /* Min. vert. scale factor 1:1. |
| 2147 | Top and height count field lines times two. */ |
| 2148 | c->rect.height = (frame_height + 1) & ~1; |
| 2149 | |
| 2150 | max_top = b->top + b->height - c->rect.height; |
| 2151 | if (c->rect.top > max_top) |
| 2152 | c->rect.top = max_top; |
| 2153 | } |
| 2154 | |
| 2155 | bttv_crop_calc_limits(c); |
| 2156 | } |
| 2157 | |
| 2158 | /* Returns an error if scaling to a frame or single field with the given |
| 2159 | width and height is not possible with the current cropping parameters |
| 2160 | and width aligned according to width_mask. If adjust_size is TRUE the |
| 2161 | function may adjust the width and/or height instead, rounding width |
| 2162 | to (width + width_bias) & width_mask. If adjust_crop is TRUE it may |
| 2163 | also adjust the current cropping parameters to get closer to the |
| 2164 | desired image size. */ |
| 2165 | static int |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2166 | limit_scaled_size_lock (struct bttv_fh * fh, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2167 | __s32 * width, |
| 2168 | __s32 * height, |
| 2169 | enum v4l2_field field, |
| 2170 | unsigned int width_mask, |
| 2171 | unsigned int width_bias, |
| 2172 | int adjust_size, |
| 2173 | int adjust_crop) |
| 2174 | { |
| 2175 | struct bttv *btv = fh->btv; |
| 2176 | const struct v4l2_rect *b; |
| 2177 | struct bttv_crop *c; |
| 2178 | __s32 min_width; |
| 2179 | __s32 min_height; |
| 2180 | __s32 max_width; |
| 2181 | __s32 max_height; |
| 2182 | int rc; |
| 2183 | |
| 2184 | BUG_ON((int) width_mask >= 0 || |
| 2185 | width_bias >= (unsigned int) -width_mask); |
| 2186 | |
| 2187 | /* Make sure tvnorm, vbi_end and the current cropping parameters |
| 2188 | remain consistent until we're done. */ |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2189 | |
| 2190 | b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; |
| 2191 | |
| 2192 | /* Do crop - use current, don't - use default parameters. */ |
| 2193 | c = &btv->crop[!!fh->do_crop]; |
| 2194 | |
| 2195 | if (fh->do_crop |
| 2196 | && adjust_size |
| 2197 | && adjust_crop |
| 2198 | && !locked_btres(btv, VIDEO_RESOURCES)) { |
| 2199 | min_width = 48; |
| 2200 | min_height = 32; |
| 2201 | |
| 2202 | /* We cannot scale up. When the scaled image is larger |
| 2203 | than crop.rect we adjust the crop.rect as required |
| 2204 | by the V4L2 spec, hence cropcap.bounds are our limit. */ |
| 2205 | max_width = min(b->width, (__s32) MAX_HACTIVE); |
| 2206 | max_height = b->height; |
| 2207 | |
| 2208 | /* We cannot capture the same line as video and VBI data. |
| 2209 | Note btv->vbi_end is really a minimum, see |
| 2210 | bttv_vbi_try_fmt(). */ |
| 2211 | if (btv->vbi_end > b->top) { |
| 2212 | max_height -= btv->vbi_end - b->top; |
| 2213 | rc = -EBUSY; |
| 2214 | if (min_height > max_height) |
| 2215 | goto fail; |
| 2216 | } |
| 2217 | } else { |
| 2218 | rc = -EBUSY; |
| 2219 | if (btv->vbi_end > c->rect.top) |
| 2220 | goto fail; |
| 2221 | |
| 2222 | min_width = c->min_scaled_width; |
| 2223 | min_height = c->min_scaled_height; |
| 2224 | max_width = c->max_scaled_width; |
| 2225 | max_height = c->max_scaled_height; |
| 2226 | |
| 2227 | adjust_crop = 0; |
| 2228 | } |
| 2229 | |
| 2230 | min_width = (min_width - width_mask - 1) & width_mask; |
| 2231 | max_width = max_width & width_mask; |
| 2232 | |
| 2233 | /* Max. scale factor is 16:1 for frames, 8:1 for fields. */ |
| 2234 | min_height = min_height; |
| 2235 | /* Min. scale factor is 1:1. */ |
| 2236 | max_height >>= !V4L2_FIELD_HAS_BOTH(field); |
| 2237 | |
| 2238 | if (adjust_size) { |
| 2239 | *width = clamp(*width, min_width, max_width); |
| 2240 | *height = clamp(*height, min_height, max_height); |
| 2241 | |
| 2242 | /* Round after clamping to avoid overflow. */ |
| 2243 | *width = (*width + width_bias) & width_mask; |
| 2244 | |
| 2245 | if (adjust_crop) { |
| 2246 | bttv_crop_adjust(c, b, *width, *height, field); |
| 2247 | |
| 2248 | if (btv->vbi_end > c->rect.top) { |
| 2249 | /* Move the crop window out of the way. */ |
| 2250 | c->rect.top = btv->vbi_end; |
| 2251 | } |
| 2252 | } |
| 2253 | } else { |
| 2254 | rc = -EINVAL; |
| 2255 | if (*width < min_width || |
| 2256 | *height < min_height || |
| 2257 | *width > max_width || |
| 2258 | *height > max_height || |
| 2259 | 0 != (*width & ~width_mask)) |
| 2260 | goto fail; |
| 2261 | } |
| 2262 | |
| 2263 | rc = 0; /* success */ |
| 2264 | |
| 2265 | fail: |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2266 | |
| 2267 | return rc; |
| 2268 | } |
| 2269 | |
| 2270 | /* Returns an error if the given overlay window dimensions are not |
| 2271 | possible with the current cropping parameters. If adjust_size is |
| 2272 | TRUE the function may adjust the window width and/or height |
| 2273 | instead, however it always rounds the horizontal position and |
| 2274 | width as btcx_align() does. If adjust_crop is TRUE the function |
| 2275 | may also adjust the current cropping parameters to get closer |
| 2276 | to the desired window size. */ |
| 2277 | static int |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2278 | verify_window_lock (struct bttv_fh * fh, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2279 | struct v4l2_window * win, |
| 2280 | int adjust_size, |
| 2281 | int adjust_crop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | { |
| 2283 | enum v4l2_field field; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2284 | unsigned int width_mask; |
| 2285 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
| 2287 | if (win->w.width < 48 || win->w.height < 32) |
| 2288 | return -EINVAL; |
| 2289 | if (win->clipcount > 2048) |
| 2290 | return -EINVAL; |
| 2291 | |
| 2292 | field = win->field; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
| 2294 | if (V4L2_FIELD_ANY == field) { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2295 | __s32 height2; |
| 2296 | |
| 2297 | height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; |
| 2298 | field = (win->w.height > height2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | ? V4L2_FIELD_INTERLACED |
| 2300 | : V4L2_FIELD_TOP; |
| 2301 | } |
| 2302 | switch (field) { |
| 2303 | case V4L2_FIELD_TOP: |
| 2304 | case V4L2_FIELD_BOTTOM: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | case V4L2_FIELD_INTERLACED: |
| 2306 | break; |
| 2307 | default: |
| 2308 | return -EINVAL; |
| 2309 | } |
| 2310 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2311 | /* 4-byte alignment. */ |
| 2312 | if (NULL == fh->ovfmt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | return -EINVAL; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2314 | width_mask = ~0; |
| 2315 | switch (fh->ovfmt->depth) { |
| 2316 | case 8: |
| 2317 | case 24: |
| 2318 | width_mask = ~3; |
| 2319 | break; |
| 2320 | case 16: |
| 2321 | width_mask = ~1; |
| 2322 | break; |
| 2323 | case 32: |
| 2324 | break; |
| 2325 | default: |
| 2326 | BUG(); |
| 2327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2329 | win->w.width -= win->w.left & ~width_mask; |
| 2330 | win->w.left = (win->w.left - width_mask - 1) & width_mask; |
| 2331 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2332 | rc = limit_scaled_size_lock(fh, &win->w.width, &win->w.height, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2333 | field, width_mask, |
| 2334 | /* width_bias: round down */ 0, |
| 2335 | adjust_size, adjust_crop); |
| 2336 | if (0 != rc) |
| 2337 | return rc; |
| 2338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | win->field = field; |
| 2340 | return 0; |
| 2341 | } |
| 2342 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2343 | static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | struct v4l2_window *win, int fixup) |
| 2345 | { |
| 2346 | struct v4l2_clip *clips = NULL; |
| 2347 | int n,size,retval = 0; |
| 2348 | |
| 2349 | if (NULL == fh->ovfmt) |
| 2350 | return -EINVAL; |
| 2351 | if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED)) |
| 2352 | return -EINVAL; |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2353 | retval = verify_window_lock(fh, win, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2354 | /* adjust_size */ fixup, |
| 2355 | /* adjust_crop */ fixup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | if (0 != retval) |
| 2357 | return retval; |
| 2358 | |
| 2359 | /* copy clips -- luckily v4l1 + v4l2 are binary |
| 2360 | compatible here ...*/ |
| 2361 | n = win->clipcount; |
| 2362 | size = sizeof(*clips)*(n+4); |
| 2363 | clips = kmalloc(size,GFP_KERNEL); |
| 2364 | if (NULL == clips) |
| 2365 | return -ENOMEM; |
| 2366 | if (n > 0) { |
| 2367 | if (copy_from_user(clips,win->clips,sizeof(struct v4l2_clip)*n)) { |
| 2368 | kfree(clips); |
| 2369 | return -EFAULT; |
| 2370 | } |
| 2371 | } |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | /* clip against screen */ |
| 2374 | if (NULL != btv->fbuf.base) |
| 2375 | n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, |
| 2376 | &win->w, clips, n); |
| 2377 | btcx_sort_clips(clips,n); |
| 2378 | |
| 2379 | /* 4-byte alignments */ |
| 2380 | switch (fh->ovfmt->depth) { |
| 2381 | case 8: |
| 2382 | case 24: |
| 2383 | btcx_align(&win->w, clips, n, 3); |
| 2384 | break; |
| 2385 | case 16: |
| 2386 | btcx_align(&win->w, clips, n, 1); |
| 2387 | break; |
| 2388 | case 32: |
| 2389 | /* no alignment fixups needed */ |
| 2390 | break; |
| 2391 | default: |
| 2392 | BUG(); |
| 2393 | } |
| 2394 | |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 2395 | kfree(fh->ov.clips); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | fh->ov.clips = clips; |
| 2397 | fh->ov.nclips = n; |
| 2398 | |
| 2399 | fh->ov.w = win->w; |
| 2400 | fh->ov.field = win->field; |
| 2401 | fh->ov.setup_ok = 1; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | btv->init.ov.w.width = win->w.width; |
| 2404 | btv->init.ov.w.height = win->w.height; |
| 2405 | btv->init.ov.field = win->field; |
| 2406 | |
| 2407 | /* update overlay if needed */ |
| 2408 | retval = 0; |
| 2409 | if (check_btres(fh, RESOURCE_OVERLAY)) { |
| 2410 | struct bttv_buffer *new; |
| 2411 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 2412 | new = videobuf_sg_alloc(sizeof(*new)); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2413 | new->crop = btv->crop[!!fh->do_crop].rect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); |
| 2415 | retval = bttv_switch_overlay(btv,fh,new); |
| 2416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | return retval; |
| 2418 | } |
| 2419 | |
| 2420 | /* ----------------------------------------------------------------------- */ |
| 2421 | |
| 2422 | static struct videobuf_queue* bttv_queue(struct bttv_fh *fh) |
| 2423 | { |
| 2424 | struct videobuf_queue* q = NULL; |
| 2425 | |
| 2426 | switch (fh->type) { |
| 2427 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 2428 | q = &fh->cap; |
| 2429 | break; |
| 2430 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 2431 | q = &fh->vbi; |
| 2432 | break; |
| 2433 | default: |
| 2434 | BUG(); |
| 2435 | } |
| 2436 | return q; |
| 2437 | } |
| 2438 | |
| 2439 | static int bttv_resource(struct bttv_fh *fh) |
| 2440 | { |
| 2441 | int res = 0; |
| 2442 | |
| 2443 | switch (fh->type) { |
| 2444 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 2445 | res = RESOURCE_VIDEO_STREAM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | break; |
| 2447 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 2448 | res = RESOURCE_VBI; |
| 2449 | break; |
| 2450 | default: |
| 2451 | BUG(); |
| 2452 | } |
| 2453 | return res; |
| 2454 | } |
| 2455 | |
| 2456 | static int bttv_switch_type(struct bttv_fh *fh, enum v4l2_buf_type type) |
| 2457 | { |
| 2458 | struct videobuf_queue *q = bttv_queue(fh); |
| 2459 | int res = bttv_resource(fh); |
| 2460 | |
| 2461 | if (check_btres(fh,res)) |
| 2462 | return -EBUSY; |
| 2463 | if (videobuf_queue_is_busy(q)) |
| 2464 | return -EBUSY; |
| 2465 | fh->type = type; |
| 2466 | return 0; |
| 2467 | } |
| 2468 | |
Michael H. Schimek | c87c948 | 2005-12-01 00:51:33 -0800 | [diff] [blame] | 2469 | static void |
| 2470 | pix_format_set_size (struct v4l2_pix_format * f, |
| 2471 | const struct bttv_format * fmt, |
| 2472 | unsigned int width, |
| 2473 | unsigned int height) |
| 2474 | { |
| 2475 | f->width = width; |
| 2476 | f->height = height; |
| 2477 | |
| 2478 | if (fmt->flags & FORMAT_FLAGS_PLANAR) { |
| 2479 | f->bytesperline = width; /* Y plane */ |
| 2480 | f->sizeimage = (width * height * fmt->depth) >> 3; |
| 2481 | } else { |
| 2482 | f->bytesperline = (width * fmt->depth) >> 3; |
| 2483 | f->sizeimage = height * f->bytesperline; |
| 2484 | } |
| 2485 | } |
| 2486 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2487 | static int bttv_g_fmt_vid_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2488 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2490 | struct bttv_fh *fh = priv; |
| 2491 | |
| 2492 | pix_format_set_size(&f->fmt.pix, fh->fmt, |
| 2493 | fh->width, fh->height); |
| 2494 | f->fmt.pix.field = fh->cap.field; |
| 2495 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 2496 | |
| 2497 | return 0; |
| 2498 | } |
| 2499 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2500 | static int bttv_g_fmt_vid_overlay(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2501 | struct v4l2_format *f) |
| 2502 | { |
| 2503 | struct bttv_fh *fh = priv; |
| 2504 | |
| 2505 | f->fmt.win.w = fh->ov.w; |
| 2506 | f->fmt.win.field = fh->ov.field; |
| 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2511 | static int bttv_try_fmt_vid_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2512 | struct v4l2_format *f) |
| 2513 | { |
| 2514 | const struct bttv_format *fmt; |
| 2515 | struct bttv_fh *fh = priv; |
| 2516 | struct bttv *btv = fh->btv; |
| 2517 | enum v4l2_field field; |
| 2518 | __s32 width, height; |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2519 | int rc; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2520 | |
| 2521 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 2522 | if (NULL == fmt) |
| 2523 | return -EINVAL; |
| 2524 | |
| 2525 | field = f->fmt.pix.field; |
| 2526 | |
| 2527 | if (V4L2_FIELD_ANY == field) { |
| 2528 | __s32 height2; |
| 2529 | |
| 2530 | height2 = btv->crop[!!fh->do_crop].rect.height >> 1; |
| 2531 | field = (f->fmt.pix.height > height2) |
| 2532 | ? V4L2_FIELD_INTERLACED |
| 2533 | : V4L2_FIELD_BOTTOM; |
| 2534 | } |
| 2535 | |
| 2536 | if (V4L2_FIELD_SEQ_BT == field) |
| 2537 | field = V4L2_FIELD_SEQ_TB; |
| 2538 | |
| 2539 | switch (field) { |
| 2540 | case V4L2_FIELD_TOP: |
| 2541 | case V4L2_FIELD_BOTTOM: |
| 2542 | case V4L2_FIELD_ALTERNATE: |
| 2543 | case V4L2_FIELD_INTERLACED: |
| 2544 | break; |
| 2545 | case V4L2_FIELD_SEQ_TB: |
| 2546 | if (fmt->flags & FORMAT_FLAGS_PLANAR) |
| 2547 | return -EINVAL; |
| 2548 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | default: |
| 2550 | return -EINVAL; |
| 2551 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2552 | |
| 2553 | width = f->fmt.pix.width; |
| 2554 | height = f->fmt.pix.height; |
| 2555 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2556 | rc = limit_scaled_size_lock(fh, &width, &height, field, |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2557 | /* width_mask: 4 pixels */ ~3, |
| 2558 | /* width_bias: nearest */ 2, |
| 2559 | /* adjust_size */ 1, |
| 2560 | /* adjust_crop */ 0); |
| 2561 | if (0 != rc) |
| 2562 | return rc; |
| 2563 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2564 | /* update data for the application */ |
| 2565 | f->fmt.pix.field = field; |
| 2566 | pix_format_set_size(&f->fmt.pix, fmt, width, height); |
| 2567 | |
| 2568 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2571 | static int bttv_try_fmt_vid_overlay(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2572 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2574 | struct bttv_fh *fh = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2576 | return verify_window_lock(fh, &f->fmt.win, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2577 | /* adjust_size */ 1, |
| 2578 | /* adjust_crop */ 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2581 | static int bttv_s_fmt_vid_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2582 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | { |
| 2584 | int retval; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2585 | const struct bttv_format *fmt; |
| 2586 | struct bttv_fh *fh = priv; |
| 2587 | struct bttv *btv = fh->btv; |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2588 | __s32 width, height; |
| 2589 | enum v4l2_field field; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2591 | retval = bttv_switch_type(fh, f->type); |
| 2592 | if (0 != retval) |
| 2593 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2595 | retval = bttv_try_fmt_vid_cap(file, priv, f); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2596 | if (0 != retval) |
| 2597 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2599 | width = f->fmt.pix.width; |
| 2600 | height = f->fmt.pix.height; |
| 2601 | field = f->fmt.pix.field; |
| 2602 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2603 | retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field, |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2604 | /* width_mask: 4 pixels */ ~3, |
| 2605 | /* width_bias: nearest */ 2, |
| 2606 | /* adjust_size */ 1, |
| 2607 | /* adjust_crop */ 1); |
| 2608 | if (0 != retval) |
| 2609 | return retval; |
| 2610 | |
| 2611 | f->fmt.pix.field = field; |
| 2612 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2613 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2615 | /* update our state informations */ |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2616 | fh->fmt = fmt; |
| 2617 | fh->cap.field = f->fmt.pix.field; |
| 2618 | fh->cap.last = V4L2_FIELD_NONE; |
| 2619 | fh->width = f->fmt.pix.width; |
| 2620 | fh->height = f->fmt.pix.height; |
| 2621 | btv->init.fmt = fmt; |
| 2622 | btv->init.width = f->fmt.pix.width; |
| 2623 | btv->init.height = f->fmt.pix.height; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2624 | |
| 2625 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2628 | static int bttv_s_fmt_vid_overlay(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2629 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2631 | struct bttv_fh *fh = priv; |
| 2632 | struct bttv *btv = fh->btv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2634 | if (no_overlay > 0) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 2635 | pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2636 | return -EINVAL; |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2637 | } |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 2638 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2639 | return setup_window_lock(fh, btv, &f->fmt.win, 1); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2642 | static int bttv_querycap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2643 | struct v4l2_capability *cap) |
| 2644 | { |
Hans Verkuil | 78dea1a | 2012-09-09 09:03:29 -0300 | [diff] [blame] | 2645 | struct video_device *vdev = video_devdata(file); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2646 | struct bttv_fh *fh = priv; |
| 2647 | struct bttv *btv = fh->btv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2649 | if (0 == v4l2) |
| 2650 | return -EINVAL; |
Mauro Carvalho Chehab | 4dcef52 | 2005-08-04 12:53:30 -0700 | [diff] [blame] | 2651 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2652 | strlcpy(cap->driver, "bttv", sizeof(cap->driver)); |
| 2653 | strlcpy(cap->card, btv->video_dev->name, sizeof(cap->card)); |
| 2654 | snprintf(cap->bus_info, sizeof(cap->bus_info), |
| 2655 | "PCI:%s", pci_name(btv->c.pci)); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2656 | cap->capabilities = |
| 2657 | V4L2_CAP_VIDEO_CAPTURE | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2658 | V4L2_CAP_READWRITE | |
Hans Verkuil | 78dea1a | 2012-09-09 09:03:29 -0300 | [diff] [blame] | 2659 | V4L2_CAP_STREAMING | |
| 2660 | V4L2_CAP_DEVICE_CAPS; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2661 | if (no_overlay <= 0) |
| 2662 | cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; |
Hans Verkuil | 78dea1a | 2012-09-09 09:03:29 -0300 | [diff] [blame] | 2663 | if (btv->vbi_dev) |
| 2664 | cap->capabilities |= V4L2_CAP_VBI_CAPTURE; |
| 2665 | if (btv->radio_dev) |
| 2666 | cap->capabilities |= V4L2_CAP_RADIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2668 | /* |
| 2669 | * No need to lock here: those vars are initialized during board |
| 2670 | * probe and remains untouched during the rest of the driver lifecycle |
| 2671 | */ |
| 2672 | if (btv->has_saa6588) |
| 2673 | cap->capabilities |= V4L2_CAP_RDS_CAPTURE; |
Trent Piepho | abb0362 | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 2674 | if (btv->tuner_type != TUNER_ABSENT) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2675 | cap->capabilities |= V4L2_CAP_TUNER; |
Hans Verkuil | 78dea1a | 2012-09-09 09:03:29 -0300 | [diff] [blame] | 2676 | if (vdev->vfl_type == VFL_TYPE_GRABBER) |
| 2677 | cap->device_caps = cap->capabilities & |
| 2678 | (V4L2_CAP_VIDEO_CAPTURE | |
| 2679 | V4L2_CAP_READWRITE | |
| 2680 | V4L2_CAP_STREAMING | |
| 2681 | V4L2_CAP_VIDEO_OVERLAY | |
| 2682 | V4L2_CAP_TUNER); |
| 2683 | else if (vdev->vfl_type == VFL_TYPE_VBI) |
| 2684 | cap->device_caps = cap->capabilities & |
| 2685 | (V4L2_CAP_VBI_CAPTURE | |
| 2686 | V4L2_CAP_READWRITE | |
| 2687 | V4L2_CAP_STREAMING | |
| 2688 | V4L2_CAP_TUNER); |
| 2689 | else { |
| 2690 | cap->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; |
| 2691 | if (btv->has_saa6588) |
| 2692 | cap->device_caps |= V4L2_CAP_READWRITE | |
| 2693 | V4L2_CAP_RDS_CAPTURE; |
| 2694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | return 0; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2696 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2698 | static int bttv_enum_fmt_cap_ovr(struct v4l2_fmtdesc *f) |
| 2699 | { |
| 2700 | int index = -1, i; |
| 2701 | |
| 2702 | for (i = 0; i < FORMATS; i++) { |
| 2703 | if (formats[i].fourcc != -1) |
| 2704 | index++; |
| 2705 | if ((unsigned int)index == f->index) |
| 2706 | break; |
| 2707 | } |
| 2708 | if (FORMATS == i) |
| 2709 | return -EINVAL; |
| 2710 | |
| 2711 | f->pixelformat = formats[i].fourcc; |
| 2712 | strlcpy(f->description, formats[i].name, sizeof(f->description)); |
| 2713 | |
| 2714 | return i; |
| 2715 | } |
| 2716 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2717 | static int bttv_enum_fmt_vid_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2718 | struct v4l2_fmtdesc *f) |
| 2719 | { |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2720 | int rc = bttv_enum_fmt_cap_ovr(f); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2721 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2722 | if (rc < 0) |
| 2723 | return rc; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2724 | |
| 2725 | return 0; |
| 2726 | } |
| 2727 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 2728 | static int bttv_enum_fmt_vid_overlay(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2729 | struct v4l2_fmtdesc *f) |
| 2730 | { |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2731 | int rc; |
| 2732 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2733 | if (no_overlay > 0) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 2734 | pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2735 | return -EINVAL; |
| 2736 | } |
| 2737 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2738 | rc = bttv_enum_fmt_cap_ovr(f); |
| 2739 | |
| 2740 | if (rc < 0) |
| 2741 | return rc; |
| 2742 | |
| 2743 | if (!(formats[rc].flags & FORMAT_FLAGS_PACKED)) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2744 | return -EINVAL; |
| 2745 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2746 | return 0; |
| 2747 | } |
| 2748 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2749 | static int bttv_g_fbuf(struct file *file, void *f, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2750 | struct v4l2_framebuffer *fb) |
| 2751 | { |
| 2752 | struct bttv_fh *fh = f; |
| 2753 | struct bttv *btv = fh->btv; |
| 2754 | |
| 2755 | *fb = btv->fbuf; |
| 2756 | fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; |
| 2757 | if (fh->ovfmt) |
| 2758 | fb->fmt.pixelformat = fh->ovfmt->fourcc; |
| 2759 | return 0; |
| 2760 | } |
| 2761 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2762 | static int bttv_overlay(struct file *file, void *f, unsigned int on) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2763 | { |
| 2764 | struct bttv_fh *fh = f; |
| 2765 | struct bttv *btv = fh->btv; |
| 2766 | struct bttv_buffer *new; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2767 | int retval = 0; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2768 | |
| 2769 | if (on) { |
| 2770 | /* verify args */ |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2771 | if (unlikely(!btv->fbuf.base)) { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2772 | return -EINVAL; |
| 2773 | } |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2774 | if (unlikely(!fh->ov.setup_ok)) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 2775 | dprintk("%d: overlay: !setup_ok\n", btv->c.nr); |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2776 | retval = -EINVAL; |
| 2777 | } |
| 2778 | if (retval) |
| 2779 | return retval; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2780 | } |
| 2781 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2782 | if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY)) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2783 | return -EBUSY; |
| 2784 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2785 | if (on) { |
| 2786 | fh->ov.tvnorm = btv->tvnorm; |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 2787 | new = videobuf_sg_alloc(sizeof(*new)); |
Robert Fitzsimons | 7c01880 | 2008-02-13 16:38:11 -0300 | [diff] [blame] | 2788 | new->crop = btv->crop[!!fh->do_crop].rect; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2789 | bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); |
| 2790 | } else { |
| 2791 | new = NULL; |
| 2792 | } |
| 2793 | |
| 2794 | /* switch over */ |
| 2795 | retval = bttv_switch_overlay(btv, fh, new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | return retval; |
| 2797 | } |
| 2798 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2799 | static int bttv_s_fbuf(struct file *file, void *f, |
Hans Verkuil | e6eb28c | 2012-09-04 10:26:45 -0300 | [diff] [blame] | 2800 | const struct v4l2_framebuffer *fb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2802 | struct bttv_fh *fh = f; |
| 2803 | struct bttv *btv = fh->btv; |
| 2804 | const struct bttv_format *fmt; |
| 2805 | int retval; |
| 2806 | |
| 2807 | if (!capable(CAP_SYS_ADMIN) && |
| 2808 | !capable(CAP_SYS_RAWIO)) |
| 2809 | return -EPERM; |
| 2810 | |
| 2811 | /* check args */ |
| 2812 | fmt = format_by_fourcc(fb->fmt.pixelformat); |
| 2813 | if (NULL == fmt) |
| 2814 | return -EINVAL; |
| 2815 | if (0 == (fmt->flags & FORMAT_FLAGS_PACKED)) |
| 2816 | return -EINVAL; |
| 2817 | |
| 2818 | retval = -EINVAL; |
| 2819 | if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { |
| 2820 | __s32 width = fb->fmt.width; |
| 2821 | __s32 height = fb->fmt.height; |
| 2822 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2823 | retval = limit_scaled_size_lock(fh, &width, &height, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2824 | V4L2_FIELD_INTERLACED, |
| 2825 | /* width_mask */ ~3, |
| 2826 | /* width_bias */ 2, |
| 2827 | /* adjust_size */ 0, |
| 2828 | /* adjust_crop */ 0); |
| 2829 | if (0 != retval) |
| 2830 | return retval; |
| 2831 | } |
| 2832 | |
| 2833 | /* ok, accept it */ |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2834 | btv->fbuf.base = fb->base; |
| 2835 | btv->fbuf.fmt.width = fb->fmt.width; |
| 2836 | btv->fbuf.fmt.height = fb->fmt.height; |
| 2837 | if (0 != fb->fmt.bytesperline) |
| 2838 | btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline; |
| 2839 | else |
| 2840 | btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8; |
| 2841 | |
| 2842 | retval = 0; |
| 2843 | fh->ovfmt = fmt; |
| 2844 | btv->init.ovfmt = fmt; |
| 2845 | if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { |
| 2846 | fh->ov.w.left = 0; |
| 2847 | fh->ov.w.top = 0; |
| 2848 | fh->ov.w.width = fb->fmt.width; |
| 2849 | fh->ov.w.height = fb->fmt.height; |
| 2850 | btv->init.ov.w.width = fb->fmt.width; |
| 2851 | btv->init.ov.w.height = fb->fmt.height; |
| 2852 | kfree(fh->ov.clips); |
| 2853 | fh->ov.clips = NULL; |
| 2854 | fh->ov.nclips = 0; |
| 2855 | |
| 2856 | if (check_btres(fh, RESOURCE_OVERLAY)) { |
| 2857 | struct bttv_buffer *new; |
| 2858 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 2859 | new = videobuf_sg_alloc(sizeof(*new)); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2860 | new->crop = btv->crop[!!fh->do_crop].rect; |
| 2861 | bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); |
| 2862 | retval = bttv_switch_overlay(btv, fh, new); |
| 2863 | } |
| 2864 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2865 | return retval; |
| 2866 | } |
| 2867 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2868 | static int bttv_reqbufs(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2869 | struct v4l2_requestbuffers *p) |
| 2870 | { |
| 2871 | struct bttv_fh *fh = priv; |
| 2872 | return videobuf_reqbufs(bttv_queue(fh), p); |
| 2873 | } |
| 2874 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2875 | static int bttv_querybuf(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2876 | struct v4l2_buffer *b) |
| 2877 | { |
| 2878 | struct bttv_fh *fh = priv; |
| 2879 | return videobuf_querybuf(bttv_queue(fh), b); |
| 2880 | } |
| 2881 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2882 | static int bttv_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2883 | { |
| 2884 | struct bttv_fh *fh = priv; |
| 2885 | struct bttv *btv = fh->btv; |
| 2886 | int res = bttv_resource(fh); |
| 2887 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2888 | if (!check_alloc_btres_lock(btv, fh, res)) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2889 | return -EBUSY; |
| 2890 | |
| 2891 | return videobuf_qbuf(bttv_queue(fh), b); |
| 2892 | } |
| 2893 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2894 | static int bttv_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2895 | { |
| 2896 | struct bttv_fh *fh = priv; |
| 2897 | return videobuf_dqbuf(bttv_queue(fh), b, |
| 2898 | file->f_flags & O_NONBLOCK); |
| 2899 | } |
| 2900 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2901 | static int bttv_streamon(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2902 | enum v4l2_buf_type type) |
| 2903 | { |
| 2904 | struct bttv_fh *fh = priv; |
| 2905 | struct bttv *btv = fh->btv; |
| 2906 | int res = bttv_resource(fh); |
| 2907 | |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2908 | if (!check_alloc_btres_lock(btv, fh, res)) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2909 | return -EBUSY; |
| 2910 | return videobuf_streamon(bttv_queue(fh)); |
| 2911 | } |
| 2912 | |
| 2913 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2914 | static int bttv_streamoff(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2915 | enum v4l2_buf_type type) |
| 2916 | { |
| 2917 | struct bttv_fh *fh = priv; |
| 2918 | struct bttv *btv = fh->btv; |
| 2919 | int retval; |
| 2920 | int res = bttv_resource(fh); |
| 2921 | |
| 2922 | |
| 2923 | retval = videobuf_streamoff(bttv_queue(fh)); |
| 2924 | if (retval < 0) |
| 2925 | return retval; |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 2926 | free_btres_lock(btv, fh, res); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2927 | return 0; |
| 2928 | } |
| 2929 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2930 | static int bttv_queryctrl(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2931 | struct v4l2_queryctrl *c) |
| 2932 | { |
| 2933 | struct bttv_fh *fh = priv; |
| 2934 | struct bttv *btv = fh->btv; |
| 2935 | const struct v4l2_queryctrl *ctrl; |
| 2936 | |
| 2937 | if ((c->id < V4L2_CID_BASE || |
| 2938 | c->id >= V4L2_CID_LASTP1) && |
| 2939 | (c->id < V4L2_CID_PRIVATE_BASE || |
| 2940 | c->id >= V4L2_CID_PRIVATE_LASTP1)) |
| 2941 | return -EINVAL; |
| 2942 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2943 | if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME)) |
| 2944 | *c = no_ctl; |
| 2945 | else { |
| 2946 | ctrl = ctrl_by_id(c->id); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2947 | |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 2948 | *c = (NULL != ctrl) ? *ctrl : no_ctl; |
| 2949 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2950 | |
| 2951 | return 0; |
| 2952 | } |
| 2953 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2954 | static int bttv_g_parm(struct file *file, void *f, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2955 | struct v4l2_streamparm *parm) |
| 2956 | { |
| 2957 | struct bttv_fh *fh = f; |
| 2958 | struct bttv *btv = fh->btv; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2959 | |
Trent Piepho | 51f0b8d5 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2960 | v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, |
| 2961 | &parm->parm.capture.timeperframe); |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 2962 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2963 | return 0; |
| 2964 | } |
| 2965 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2966 | static int bttv_g_tuner(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2967 | struct v4l2_tuner *t) |
| 2968 | { |
| 2969 | struct bttv_fh *fh = priv; |
| 2970 | struct bttv *btv = fh->btv; |
| 2971 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2972 | if (0 != t->index) |
| 2973 | return -EINVAL; |
| 2974 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2975 | t->rxsubchans = V4L2_TUNER_SUB_MONO; |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 2976 | bttv_call_all(btv, tuner, g_tuner, t); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2977 | strcpy(t->name, "Television"); |
| 2978 | t->capability = V4L2_TUNER_CAP_NORM; |
| 2979 | t->type = V4L2_TUNER_ANALOG_TV; |
| 2980 | if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC) |
| 2981 | t->signal = 0xffff; |
| 2982 | |
| 2983 | if (btv->audio_mode_gpio) |
| 2984 | btv->audio_mode_gpio(btv, t, 0); |
| 2985 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2986 | return 0; |
| 2987 | } |
| 2988 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2989 | static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 2990 | { |
| 2991 | struct bttv_fh *fh = f; |
| 2992 | struct bttv *btv = fh->btv; |
| 2993 | |
| 2994 | *p = v4l2_prio_max(&btv->prio); |
| 2995 | |
| 2996 | return 0; |
| 2997 | } |
| 2998 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 2999 | static int bttv_s_priority(struct file *file, void *f, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3000 | enum v4l2_priority prio) |
| 3001 | { |
| 3002 | struct bttv_fh *fh = f; |
| 3003 | struct bttv *btv = fh->btv; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3004 | int rc; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3005 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3006 | rc = v4l2_prio_change(&btv->prio, &fh->prio, prio); |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3007 | |
| 3008 | return rc; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3009 | } |
| 3010 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3011 | static int bttv_cropcap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3012 | struct v4l2_cropcap *cap) |
| 3013 | { |
| 3014 | struct bttv_fh *fh = priv; |
| 3015 | struct bttv *btv = fh->btv; |
| 3016 | |
| 3017 | if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 3018 | cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
| 3019 | return -EINVAL; |
| 3020 | |
| 3021 | *cap = bttv_tvnorms[btv->tvnorm].cropcap; |
| 3022 | |
| 3023 | return 0; |
| 3024 | } |
| 3025 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3026 | static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3027 | { |
| 3028 | struct bttv_fh *fh = f; |
| 3029 | struct bttv *btv = fh->btv; |
| 3030 | |
| 3031 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 3032 | crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
| 3033 | return -EINVAL; |
| 3034 | |
| 3035 | /* No fh->do_crop = 1; because btv->crop[1] may be |
| 3036 | inconsistent with fh->width or fh->height and apps |
| 3037 | do not expect a change here. */ |
| 3038 | |
| 3039 | crop->c = btv->crop[!!fh->do_crop].rect; |
| 3040 | |
| 3041 | return 0; |
| 3042 | } |
| 3043 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 3044 | static int bttv_s_crop(struct file *file, void *f, const struct v4l2_crop *crop) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3045 | { |
| 3046 | struct bttv_fh *fh = f; |
| 3047 | struct bttv *btv = fh->btv; |
| 3048 | const struct v4l2_rect *b; |
| 3049 | int retval; |
| 3050 | struct bttv_crop c; |
| 3051 | __s32 b_left; |
| 3052 | __s32 b_top; |
| 3053 | __s32 b_right; |
| 3054 | __s32 b_bottom; |
| 3055 | |
| 3056 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 3057 | crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
| 3058 | return -EINVAL; |
| 3059 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3060 | /* Make sure tvnorm, vbi_end and the current cropping |
| 3061 | parameters remain consistent until we're done. Note |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3062 | read() may change vbi_end in check_alloc_btres_lock(). */ |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3063 | retval = v4l2_prio_check(&btv->prio, fh->prio); |
| 3064 | if (0 != retval) { |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3065 | return retval; |
| 3066 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3067 | |
| 3068 | retval = -EBUSY; |
| 3069 | |
| 3070 | if (locked_btres(fh->btv, VIDEO_RESOURCES)) { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3071 | return retval; |
| 3072 | } |
| 3073 | |
| 3074 | b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; |
| 3075 | |
| 3076 | b_left = b->left; |
| 3077 | b_right = b_left + b->width; |
| 3078 | b_bottom = b->top + b->height; |
| 3079 | |
| 3080 | b_top = max(b->top, btv->vbi_end); |
| 3081 | if (b_top + 32 >= b_bottom) { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3082 | return retval; |
| 3083 | } |
| 3084 | |
| 3085 | /* Min. scaled size 48 x 32. */ |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 3086 | c.rect.left = clamp_t(s32, crop->c.left, b_left, b_right - 48); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3087 | c.rect.left = min(c.rect.left, (__s32) MAX_HDELAY); |
| 3088 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 3089 | c.rect.width = clamp_t(s32, crop->c.width, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3090 | 48, b_right - c.rect.left); |
| 3091 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 3092 | c.rect.top = clamp_t(s32, crop->c.top, b_top, b_bottom - 32); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3093 | /* Top and height must be a multiple of two. */ |
| 3094 | c.rect.top = (c.rect.top + 1) & ~1; |
| 3095 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 3096 | c.rect.height = clamp_t(s32, crop->c.height, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3097 | 32, b_bottom - c.rect.top); |
| 3098 | c.rect.height = (c.rect.height + 1) & ~1; |
| 3099 | |
| 3100 | bttv_crop_calc_limits(&c); |
| 3101 | |
| 3102 | btv->crop[1] = c; |
| 3103 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3104 | fh->do_crop = 1; |
| 3105 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3106 | if (fh->width < c.min_scaled_width) { |
| 3107 | fh->width = c.min_scaled_width; |
| 3108 | btv->init.width = c.min_scaled_width; |
| 3109 | } else if (fh->width > c.max_scaled_width) { |
| 3110 | fh->width = c.max_scaled_width; |
| 3111 | btv->init.width = c.max_scaled_width; |
| 3112 | } |
| 3113 | |
| 3114 | if (fh->height < c.min_scaled_height) { |
| 3115 | fh->height = c.min_scaled_height; |
| 3116 | btv->init.height = c.min_scaled_height; |
| 3117 | } else if (fh->height > c.max_scaled_height) { |
| 3118 | fh->height = c.max_scaled_height; |
| 3119 | btv->init.height = c.max_scaled_height; |
| 3120 | } |
| 3121 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3122 | return 0; |
| 3123 | } |
| 3124 | |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3125 | static int bttv_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3126 | { |
Mauro Carvalho Chehab | d69b2e4 | 2008-04-01 20:30:24 -0300 | [diff] [blame] | 3127 | if (unlikely(a->index)) |
| 3128 | return -EINVAL; |
| 3129 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3130 | strcpy(a->name, "audio"); |
| 3131 | return 0; |
| 3132 | } |
| 3133 | |
Hans Verkuil | 0e8025b9 | 2012-09-04 11:59:31 -0300 | [diff] [blame] | 3134 | static int bttv_s_audio(struct file *file, void *priv, const struct v4l2_audio *a) |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3135 | { |
Mauro Carvalho Chehab | d69b2e4 | 2008-04-01 20:30:24 -0300 | [diff] [blame] | 3136 | if (unlikely(a->index)) |
| 3137 | return -EINVAL; |
| 3138 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3139 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | static ssize_t bttv_read(struct file *file, char __user *data, |
| 3143 | size_t count, loff_t *ppos) |
| 3144 | { |
| 3145 | struct bttv_fh *fh = file->private_data; |
| 3146 | int retval = 0; |
| 3147 | |
| 3148 | if (fh->btv->errors) |
| 3149 | bttv_reinit_bt848(fh->btv); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3150 | dprintk("%d: read count=%d type=%s\n", |
| 3151 | fh->btv->c.nr, (int)count, v4l2_type_names[fh->type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | |
| 3153 | switch (fh->type) { |
| 3154 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3155 | if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3156 | /* VIDEO_READ in use by another fh, |
| 3157 | or VIDEO_STREAM by any fh. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | return -EBUSY; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | retval = videobuf_read_one(&fh->cap, data, count, ppos, |
| 3161 | file->f_flags & O_NONBLOCK); |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3162 | free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | break; |
| 3164 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3165 | if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | return -EBUSY; |
| 3167 | retval = videobuf_read_stream(&fh->vbi, data, count, ppos, 1, |
| 3168 | file->f_flags & O_NONBLOCK); |
| 3169 | break; |
| 3170 | default: |
| 3171 | BUG(); |
| 3172 | } |
| 3173 | return retval; |
| 3174 | } |
| 3175 | |
| 3176 | static unsigned int bttv_poll(struct file *file, poll_table *wait) |
| 3177 | { |
| 3178 | struct bttv_fh *fh = file->private_data; |
| 3179 | struct bttv_buffer *buf; |
| 3180 | enum v4l2_field field; |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 3181 | unsigned int rc = POLLERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | |
| 3183 | if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3184 | if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | return POLLERR; |
| 3186 | return videobuf_poll_stream(file, &fh->vbi, wait); |
| 3187 | } |
| 3188 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3189 | if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | /* streaming capture */ |
| 3191 | if (list_empty(&fh->cap.stream)) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 3192 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); |
| 3194 | } else { |
| 3195 | /* read() capture */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | if (NULL == fh->cap.read_buf) { |
| 3197 | /* need to capture a new frame */ |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 3198 | if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) |
| 3199 | goto err; |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 3200 | fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize); |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 3201 | if (NULL == fh->cap.read_buf) |
| 3202 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; |
| 3204 | field = videobuf_next_field(&fh->cap); |
| 3205 | if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) { |
Nickolay V. Shmyrev | 50ab5ed | 2005-12-01 00:51:32 -0800 | [diff] [blame] | 3206 | kfree (fh->cap.read_buf); |
| 3207 | fh->cap.read_buf = NULL; |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 3208 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | } |
| 3210 | fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); |
| 3211 | fh->cap.read_off = 0; |
| 3212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | buf = (struct bttv_buffer*)fh->cap.read_buf; |
| 3214 | } |
| 3215 | |
| 3216 | poll_wait(file, &buf->vb.done, wait); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3217 | if (buf->vb.state == VIDEOBUF_DONE || |
| 3218 | buf->vb.state == VIDEOBUF_ERROR) |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 3219 | rc = POLLIN|POLLRDNORM; |
| 3220 | else |
| 3221 | rc = 0; |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 3222 | err: |
Figo.zhang | 9fd6418 | 2009-06-16 13:31:29 -0300 | [diff] [blame] | 3223 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 3226 | static int bttv_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | { |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 3228 | struct video_device *vdev = video_devdata(file); |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 3229 | struct bttv *btv = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | struct bttv_fh *fh; |
| 3231 | enum v4l2_buf_type type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3233 | dprintk("open dev=%s\n", video_device_node_name(vdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | |
Laurent Pinchart | 327ae59 | 2009-11-27 13:57:55 -0300 | [diff] [blame] | 3235 | if (vdev->vfl_type == VFL_TYPE_GRABBER) { |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 3236 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Laurent Pinchart | 327ae59 | 2009-11-27 13:57:55 -0300 | [diff] [blame] | 3237 | } else if (vdev->vfl_type == VFL_TYPE_VBI) { |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 3238 | type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 3239 | } else { |
| 3240 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | return -ENODEV; |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 3242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3244 | dprintk("%d: open called (type=%s)\n", |
| 3245 | btv->c.nr, v4l2_type_names[type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
| 3247 | /* allocate per filehandle data */ |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3248 | fh = kmalloc(sizeof(*fh), GFP_KERNEL); |
| 3249 | if (unlikely(!fh)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | return -ENOMEM; |
| 3251 | file->private_data = fh; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | *fh = btv->init; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | fh->type = type; |
| 3256 | fh->ov.setup_ok = 0; |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3257 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 3258 | v4l2_prio_open(&btv->prio, &fh->prio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 3260 | videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, |
| 3261 | &btv->c.pci->dev, &btv->s_lock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 3263 | V4L2_FIELD_INTERLACED, |
| 3264 | sizeof(struct bttv_buffer), |
Mauro Carvalho Chehab | 587f0d5 | 2010-12-15 18:45:42 -0300 | [diff] [blame] | 3265 | fh, &btv->lock); |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 3266 | videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, |
| 3267 | &btv->c.pci->dev, &btv->s_lock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | V4L2_BUF_TYPE_VBI_CAPTURE, |
| 3269 | V4L2_FIELD_SEQ_TB, |
| 3270 | sizeof(struct bttv_buffer), |
Mauro Carvalho Chehab | 587f0d5 | 2010-12-15 18:45:42 -0300 | [diff] [blame] | 3271 | fh, &btv->lock); |
Nickolay V. Shmyrev | 302f61a | 2007-10-26 10:53:21 -0300 | [diff] [blame] | 3272 | set_tvnorm(btv,btv->tvnorm); |
Mauro Carvalho Chehab | b46a9c8 | 2008-08-05 10:12:35 -0300 | [diff] [blame] | 3273 | set_input(btv, btv->input, btv->tvnorm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | |
| 3275 | btv->users++; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3276 | |
| 3277 | /* The V4L2 spec requires one global set of cropping parameters |
| 3278 | which only change on request. These are stored in btv->crop[1]. |
| 3279 | However for compatibility with V4L apps and cropping unaware |
| 3280 | V4L2 apps we now reset the cropping parameters as seen through |
| 3281 | this fh, which is to say VIDIOC_G_CROP and scaling limit checks |
| 3282 | will use btv->crop[0], the default cropping parameters for the |
| 3283 | current video standard, and VIDIOC_S_FMT will not implicitely |
| 3284 | change the cropping parameters until VIDIOC_S_CROP has been |
| 3285 | called. */ |
| 3286 | fh->do_crop = !reset_crop; /* module parameter */ |
| 3287 | |
| 3288 | /* Likewise there should be one global set of VBI capture |
| 3289 | parameters, but for compatibility with V4L apps and earlier |
| 3290 | driver versions each fh has its own parameters. */ |
| 3291 | bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); |
| 3292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | bttv_field_count(btv); |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 3297 | static int bttv_release(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | { |
| 3299 | struct bttv_fh *fh = file->private_data; |
| 3300 | struct bttv *btv = fh->btv; |
| 3301 | |
| 3302 | /* turn off overlay */ |
| 3303 | if (check_btres(fh, RESOURCE_OVERLAY)) |
| 3304 | bttv_switch_overlay(btv,fh,NULL); |
| 3305 | |
| 3306 | /* stop video capture */ |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3307 | if (check_btres(fh, RESOURCE_VIDEO_STREAM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | videobuf_streamoff(&fh->cap); |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3309 | free_btres_lock(btv,fh,RESOURCE_VIDEO_STREAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | } |
| 3311 | if (fh->cap.read_buf) { |
| 3312 | buffer_release(&fh->cap,fh->cap.read_buf); |
| 3313 | kfree(fh->cap.read_buf); |
| 3314 | } |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3315 | if (check_btres(fh, RESOURCE_VIDEO_READ)) { |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3316 | free_btres_lock(btv, fh, RESOURCE_VIDEO_READ); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 3317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | |
| 3319 | /* stop vbi capture */ |
| 3320 | if (check_btres(fh, RESOURCE_VBI)) { |
Brandon Philips | 053fcb6 | 2007-11-13 20:11:26 -0300 | [diff] [blame] | 3321 | videobuf_stop(&fh->vbi); |
Mauro Carvalho Chehab | 8822f0d | 2010-09-14 12:19:51 -0300 | [diff] [blame] | 3322 | free_btres_lock(btv,fh,RESOURCE_VBI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | /* free stuff */ |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | videobuf_mmap_free(&fh->cap); |
| 3328 | videobuf_mmap_free(&fh->vbi); |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 3329 | v4l2_prio_close(&btv->prio, fh->prio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | file->private_data = NULL; |
| 3331 | kfree(fh); |
| 3332 | |
| 3333 | btv->users--; |
| 3334 | bttv_field_count(btv); |
Mauro Carvalho Chehab | b46a9c8 | 2008-08-05 10:12:35 -0300 | [diff] [blame] | 3335 | |
| 3336 | if (!btv->users) |
| 3337 | audio_mute(btv, 1); |
| 3338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | return 0; |
| 3340 | } |
| 3341 | |
| 3342 | static int |
| 3343 | bttv_mmap(struct file *file, struct vm_area_struct *vma) |
| 3344 | { |
| 3345 | struct bttv_fh *fh = file->private_data; |
| 3346 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3347 | dprintk("%d: mmap type=%s 0x%lx+%ld\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | fh->btv->c.nr, v4l2_type_names[fh->type], |
| 3349 | vma->vm_start, vma->vm_end - vma->vm_start); |
| 3350 | return videobuf_mmap_mapper(bttv_queue(fh),vma); |
| 3351 | } |
| 3352 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 3353 | static const struct v4l2_file_operations bttv_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | { |
Mauro Carvalho Chehab | 8979e9d | 2010-09-15 08:22:09 -0300 | [diff] [blame] | 3355 | .owner = THIS_MODULE, |
| 3356 | .open = bttv_open, |
| 3357 | .release = bttv_release, |
| 3358 | .unlocked_ioctl = video_ioctl2, |
| 3359 | .read = bttv_read, |
| 3360 | .mmap = bttv_mmap, |
| 3361 | .poll = bttv_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | }; |
| 3363 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 3364 | static const struct v4l2_ioctl_ops bttv_ioctl_ops = { |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3365 | .vidioc_querycap = bttv_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 3366 | .vidioc_enum_fmt_vid_cap = bttv_enum_fmt_vid_cap, |
| 3367 | .vidioc_g_fmt_vid_cap = bttv_g_fmt_vid_cap, |
| 3368 | .vidioc_try_fmt_vid_cap = bttv_try_fmt_vid_cap, |
| 3369 | .vidioc_s_fmt_vid_cap = bttv_s_fmt_vid_cap, |
| 3370 | .vidioc_enum_fmt_vid_overlay = bttv_enum_fmt_vid_overlay, |
| 3371 | .vidioc_g_fmt_vid_overlay = bttv_g_fmt_vid_overlay, |
| 3372 | .vidioc_try_fmt_vid_overlay = bttv_try_fmt_vid_overlay, |
| 3373 | .vidioc_s_fmt_vid_overlay = bttv_s_fmt_vid_overlay, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 3374 | .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap, |
| 3375 | .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap, |
| 3376 | .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap, |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3377 | .vidioc_g_audio = bttv_g_audio, |
| 3378 | .vidioc_s_audio = bttv_s_audio, |
| 3379 | .vidioc_cropcap = bttv_cropcap, |
| 3380 | .vidioc_reqbufs = bttv_reqbufs, |
| 3381 | .vidioc_querybuf = bttv_querybuf, |
| 3382 | .vidioc_qbuf = bttv_qbuf, |
| 3383 | .vidioc_dqbuf = bttv_dqbuf, |
| 3384 | .vidioc_s_std = bttv_s_std, |
| 3385 | .vidioc_enum_input = bttv_enum_input, |
| 3386 | .vidioc_g_input = bttv_g_input, |
| 3387 | .vidioc_s_input = bttv_s_input, |
| 3388 | .vidioc_queryctrl = bttv_queryctrl, |
| 3389 | .vidioc_g_ctrl = bttv_g_ctrl, |
| 3390 | .vidioc_s_ctrl = bttv_s_ctrl, |
| 3391 | .vidioc_streamon = bttv_streamon, |
| 3392 | .vidioc_streamoff = bttv_streamoff, |
| 3393 | .vidioc_g_tuner = bttv_g_tuner, |
| 3394 | .vidioc_s_tuner = bttv_s_tuner, |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3395 | .vidioc_g_crop = bttv_g_crop, |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3396 | .vidioc_s_crop = bttv_s_crop, |
| 3397 | .vidioc_g_fbuf = bttv_g_fbuf, |
| 3398 | .vidioc_s_fbuf = bttv_s_fbuf, |
| 3399 | .vidioc_overlay = bttv_overlay, |
| 3400 | .vidioc_g_priority = bttv_g_priority, |
| 3401 | .vidioc_s_priority = bttv_s_priority, |
| 3402 | .vidioc_g_parm = bttv_g_parm, |
| 3403 | .vidioc_g_frequency = bttv_g_frequency, |
| 3404 | .vidioc_s_frequency = bttv_s_frequency, |
| 3405 | .vidioc_log_status = bttv_log_status, |
| 3406 | .vidioc_querystd = bttv_querystd, |
Hans Verkuil | 1b9e94d | 2012-09-09 09:23:31 -0300 | [diff] [blame] | 3407 | .vidioc_g_chip_ident = bttv_g_chip_ident, |
Zoltan Devai | 4384683 | 2008-01-14 13:24:38 -0300 | [diff] [blame] | 3408 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3409 | .vidioc_g_register = bttv_g_register, |
| 3410 | .vidioc_s_register = bttv_s_register, |
Zoltan Devai | 4384683 | 2008-01-14 13:24:38 -0300 | [diff] [blame] | 3411 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 3412 | }; |
| 3413 | |
| 3414 | static struct video_device bttv_video_template = { |
| 3415 | .fops = &bttv_fops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 3416 | .ioctl_ops = &bttv_ioctl_ops, |
| 3417 | .tvnorms = BTTV_NORMS, |
| 3418 | .current_norm = V4L2_STD_PAL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | }; |
| 3420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | /* ----------------------------------------------------------------------- */ |
| 3422 | /* radio interface */ |
| 3423 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 3424 | static int radio_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | { |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 3426 | struct video_device *vdev = video_devdata(file); |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 3427 | struct bttv *btv = video_drvdata(file); |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3428 | struct bttv_fh *fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3430 | dprintk("open dev=%s\n", video_device_node_name(vdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3432 | dprintk("%d: open called (radio)\n", btv->c.nr); |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3433 | |
| 3434 | /* allocate per filehandle data */ |
| 3435 | fh = kmalloc(sizeof(*fh), GFP_KERNEL); |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3436 | if (unlikely(!fh)) |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3437 | return -ENOMEM; |
| 3438 | file->private_data = fh; |
| 3439 | *fh = btv->init; |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3440 | |
Mauro Carvalho Chehab | c37db91 | 2010-09-15 08:18:31 -0300 | [diff] [blame] | 3441 | v4l2_prio_open(&btv->prio, &fh->prio); |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | btv->radio_user++; |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3444 | |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 3445 | bttv_call_all(btv, tuner, s_radio); |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 3446 | audio_input(btv,TVAUDIO_INPUT_RADIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 3448 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | } |
| 3450 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 3451 | static int radio_release(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | { |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3453 | struct bttv_fh *fh = file->private_data; |
| 3454 | struct bttv *btv = fh->btv; |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 3455 | struct saa6588_command cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 3457 | v4l2_prio_close(&btv->prio, fh->prio); |
Robert Fitzsimons | b9bc07a | 2008-04-10 09:40:31 -0300 | [diff] [blame] | 3458 | file->private_data = NULL; |
| 3459 | kfree(fh); |
| 3460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | btv->radio_user--; |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3462 | |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 3463 | bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd); |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | return 0; |
| 3466 | } |
| 3467 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3468 | static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3470 | struct bttv_fh *fh = priv; |
| 3471 | struct bttv *btv = fh->btv; |
| 3472 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3473 | if (0 != t->index) |
| 3474 | return -EINVAL; |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3475 | strcpy(t->name, "Radio"); |
| 3476 | t->type = V4L2_TUNER_RADIO; |
| 3477 | |
Hans Verkuil | 859f027 | 2009-03-28 08:29:00 -0300 | [diff] [blame] | 3478 | bttv_call_all(btv, tuner, g_tuner, t); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3479 | |
| 3480 | if (btv->audio_mode_gpio) |
| 3481 | btv->audio_mode_gpio(btv, t, 0); |
| 3482 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3483 | return 0; |
| 3484 | } |
| 3485 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3486 | static int radio_s_tuner(struct file *file, void *priv, |
| 3487 | struct v4l2_tuner *t) |
| 3488 | { |
| 3489 | struct bttv_fh *fh = priv; |
| 3490 | struct bttv *btv = fh->btv; |
| 3491 | |
| 3492 | if (0 != t->index) |
| 3493 | return -EINVAL; |
| 3494 | |
Hans Verkuil | a024c1a | 2011-06-12 07:02:43 -0300 | [diff] [blame] | 3495 | bttv_call_all(btv, tuner, s_tuner, t); |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3496 | return 0; |
| 3497 | } |
| 3498 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3499 | static int radio_queryctrl(struct file *file, void *priv, |
| 3500 | struct v4l2_queryctrl *c) |
| 3501 | { |
| 3502 | const struct v4l2_queryctrl *ctrl; |
| 3503 | |
| 3504 | if (c->id < V4L2_CID_BASE || |
| 3505 | c->id >= V4L2_CID_LASTP1) |
| 3506 | return -EINVAL; |
| 3507 | |
| 3508 | if (c->id == V4L2_CID_AUDIO_MUTE) { |
| 3509 | ctrl = ctrl_by_id(c->id); |
| 3510 | *c = *ctrl; |
| 3511 | } else |
| 3512 | *c = no_ctl; |
| 3513 | |
| 3514 | return 0; |
| 3515 | } |
| 3516 | |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3517 | static ssize_t radio_read(struct file *file, char __user *data, |
| 3518 | size_t count, loff_t *ppos) |
| 3519 | { |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3520 | struct bttv_fh *fh = file->private_data; |
| 3521 | struct bttv *btv = fh->btv; |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 3522 | struct saa6588_command cmd; |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3523 | cmd.block_count = count/3; |
| 3524 | cmd.buffer = data; |
| 3525 | cmd.instance = file; |
| 3526 | cmd.result = -ENODEV; |
| 3527 | |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 3528 | bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd); |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3529 | |
| 3530 | return cmd.result; |
| 3531 | } |
| 3532 | |
| 3533 | static unsigned int radio_poll(struct file *file, poll_table *wait) |
| 3534 | { |
Robert Fitzsimons | 5cd3955 | 2008-04-01 11:41:54 -0300 | [diff] [blame] | 3535 | struct bttv_fh *fh = file->private_data; |
| 3536 | struct bttv *btv = fh->btv; |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 3537 | struct saa6588_command cmd; |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3538 | cmd.instance = file; |
| 3539 | cmd.event_list = wait; |
| 3540 | cmd.result = -ENODEV; |
Hans Verkuil | b9218f2 | 2010-12-27 12:22:46 -0300 | [diff] [blame] | 3541 | bttv_call_all(btv, core, ioctl, SAA6588_CMD_POLL, &cmd); |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3542 | |
| 3543 | return cmd.result; |
| 3544 | } |
| 3545 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 3546 | static const struct v4l2_file_operations radio_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | { |
| 3548 | .owner = THIS_MODULE, |
| 3549 | .open = radio_open, |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3550 | .read = radio_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | .release = radio_release, |
Mauro Carvalho Chehab | 587f0d5 | 2010-12-15 18:45:42 -0300 | [diff] [blame] | 3552 | .unlocked_ioctl = video_ioctl2, |
Mauro Carvalho Chehab | 24a70fd | 2005-09-09 13:03:39 -0700 | [diff] [blame] | 3553 | .poll = radio_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | }; |
| 3555 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 3556 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Hans Verkuil | 78dea1a | 2012-09-09 09:03:29 -0300 | [diff] [blame] | 3557 | .vidioc_querycap = bttv_querycap, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3558 | .vidioc_g_tuner = radio_g_tuner, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3559 | .vidioc_s_tuner = radio_s_tuner, |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 3560 | .vidioc_queryctrl = radio_queryctrl, |
Mauro Carvalho Chehab | e5ae3db | 2007-12-27 22:22:59 -0300 | [diff] [blame] | 3561 | .vidioc_g_ctrl = bttv_g_ctrl, |
| 3562 | .vidioc_s_ctrl = bttv_s_ctrl, |
| 3563 | .vidioc_g_frequency = bttv_g_frequency, |
| 3564 | .vidioc_s_frequency = bttv_s_frequency, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | }; |
| 3566 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 3567 | static struct video_device radio_template = { |
| 3568 | .fops = &radio_fops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 3569 | .ioctl_ops = &radio_ioctl_ops, |
| 3570 | }; |
| 3571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | /* ----------------------------------------------------------------------- */ |
| 3573 | /* some debug code */ |
| 3574 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 3575 | static int bttv_risc_decode(u32 risc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | { |
| 3577 | static char *instr[16] = { |
| 3578 | [ BT848_RISC_WRITE >> 28 ] = "write", |
| 3579 | [ BT848_RISC_SKIP >> 28 ] = "skip", |
| 3580 | [ BT848_RISC_WRITEC >> 28 ] = "writec", |
| 3581 | [ BT848_RISC_JUMP >> 28 ] = "jump", |
| 3582 | [ BT848_RISC_SYNC >> 28 ] = "sync", |
| 3583 | [ BT848_RISC_WRITE123 >> 28 ] = "write123", |
| 3584 | [ BT848_RISC_SKIP123 >> 28 ] = "skip123", |
| 3585 | [ BT848_RISC_WRITE1S23 >> 28 ] = "write1s23", |
| 3586 | }; |
| 3587 | static int incr[16] = { |
| 3588 | [ BT848_RISC_WRITE >> 28 ] = 2, |
| 3589 | [ BT848_RISC_JUMP >> 28 ] = 2, |
| 3590 | [ BT848_RISC_SYNC >> 28 ] = 2, |
| 3591 | [ BT848_RISC_WRITE123 >> 28 ] = 5, |
| 3592 | [ BT848_RISC_SKIP123 >> 28 ] = 2, |
| 3593 | [ BT848_RISC_WRITE1S23 >> 28 ] = 3, |
| 3594 | }; |
| 3595 | static char *bits[] = { |
| 3596 | "be0", "be1", "be2", "be3/resync", |
| 3597 | "set0", "set1", "set2", "set3", |
| 3598 | "clr0", "clr1", "clr2", "clr3", |
| 3599 | "irq", "res", "eol", "sol", |
| 3600 | }; |
| 3601 | int i; |
| 3602 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3603 | pr_cont("0x%08x [ %s", risc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | instr[risc >> 28] ? instr[risc >> 28] : "INVALID"); |
| 3605 | for (i = ARRAY_SIZE(bits)-1; i >= 0; i--) |
| 3606 | if (risc & (1 << (i + 12))) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3607 | pr_cont(" %s", bits[i]); |
| 3608 | pr_cont(" count=%d ]\n", risc & 0xfff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | return incr[risc >> 28] ? incr[risc >> 28] : 1; |
| 3610 | } |
| 3611 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 3612 | static void bttv_risc_disasm(struct bttv *btv, |
| 3613 | struct btcx_riscmem *risc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | { |
| 3615 | unsigned int i,j,n; |
| 3616 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3617 | pr_info("%s: risc disasm: %p [dma=0x%08lx]\n", |
| 3618 | btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | for (i = 0; i < (risc->size >> 2); i += n) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3620 | pr_info("%s: 0x%lx: ", |
| 3621 | btv->c.v4l2_dev.name, |
| 3622 | (unsigned long)(risc->dma + (i<<2))); |
Al Viro | 3aa7110 | 2008-06-22 14:20:09 -0300 | [diff] [blame] | 3623 | n = bttv_risc_decode(le32_to_cpu(risc->cpu[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | for (j = 1; j < n; j++) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3625 | pr_info("%s: 0x%lx: 0x%08x [ arg #%d ]\n", |
| 3626 | btv->c.v4l2_dev.name, |
| 3627 | (unsigned long)(risc->dma + ((i+j)<<2)), |
| 3628 | risc->cpu[i+j], j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | if (0 == risc->cpu[i]) |
| 3630 | break; |
| 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | static void bttv_print_riscaddr(struct bttv *btv) |
| 3635 | { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3636 | pr_info(" main: %08llx\n", (unsigned long long)btv->main.dma); |
| 3637 | pr_info(" vbi : o=%08llx e=%08llx\n", |
| 3638 | btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0, |
| 3639 | btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0); |
| 3640 | pr_info(" cap : o=%08llx e=%08llx\n", |
| 3641 | btv->curr.top |
| 3642 | ? (unsigned long long)btv->curr.top->top.dma : 0, |
| 3643 | btv->curr.bottom |
| 3644 | ? (unsigned long long)btv->curr.bottom->bottom.dma : 0); |
| 3645 | pr_info(" scr : o=%08llx e=%08llx\n", |
| 3646 | btv->screen ? (unsigned long long)btv->screen->top.dma : 0, |
| 3647 | btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | bttv_risc_disasm(btv, &btv->main); |
| 3649 | } |
| 3650 | |
| 3651 | /* ----------------------------------------------------------------------- */ |
| 3652 | /* irq handler */ |
| 3653 | |
| 3654 | static char *irq_name[] = { |
| 3655 | "FMTCHG", // format change detected (525 vs. 625) |
| 3656 | "VSYNC", // vertical sync (new field) |
| 3657 | "HSYNC", // horizontal sync |
| 3658 | "OFLOW", // chroma/luma AGC overflow |
| 3659 | "HLOCK", // horizontal lock changed |
| 3660 | "VPRES", // video presence changed |
| 3661 | "6", "7", |
| 3662 | "I2CDONE", // hw irc operation finished |
| 3663 | "GPINT", // gpio port triggered irq |
| 3664 | "10", |
| 3665 | "RISCI", // risc instruction triggered irq |
| 3666 | "FBUS", // pixel data fifo dropped data (high pci bus latencies) |
| 3667 | "FTRGT", // pixel data fifo overrun |
| 3668 | "FDSR", // fifo data stream resyncronisation |
| 3669 | "PPERR", // parity error (data transfer) |
| 3670 | "RIPERR", // parity error (read risc instructions) |
| 3671 | "PABORT", // pci abort |
| 3672 | "OCERR", // risc instruction error |
| 3673 | "SCERR", // syncronisation error |
| 3674 | }; |
| 3675 | |
| 3676 | static void bttv_print_irqbits(u32 print, u32 mark) |
| 3677 | { |
| 3678 | unsigned int i; |
| 3679 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3680 | pr_cont("bits:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | for (i = 0; i < ARRAY_SIZE(irq_name); i++) { |
| 3682 | if (print & (1 << i)) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3683 | pr_cont(" %s", irq_name[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | if (mark & (1 << i)) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3685 | pr_cont("*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc) |
| 3690 | { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3691 | pr_warn("%d: irq: skipped frame [main=%lx,o_vbi=%lx,o_field=%lx,rc=%lx]\n", |
| 3692 | btv->c.nr, |
| 3693 | (unsigned long)btv->main.dma, |
| 3694 | (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]), |
| 3695 | (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]), |
| 3696 | (unsigned long)rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | |
| 3698 | if (0 == (btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC)) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3699 | pr_notice("%d: Oh, there (temporarily?) is no input signal. " |
| 3700 | "Ok, then this is harmless, don't worry ;)\n", |
| 3701 | btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | return; |
| 3703 | } |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3704 | pr_notice("%d: Uhm. Looks like we have unusual high IRQ latencies\n", |
| 3705 | btv->c.nr); |
| 3706 | pr_notice("%d: Lets try to catch the culpit red-handed ...\n", |
| 3707 | btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | dump_stack(); |
| 3709 | } |
| 3710 | |
| 3711 | static int |
| 3712 | bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set) |
| 3713 | { |
| 3714 | struct bttv_buffer *item; |
| 3715 | |
| 3716 | memset(set,0,sizeof(*set)); |
| 3717 | |
| 3718 | /* capture request ? */ |
| 3719 | if (!list_empty(&btv->capture)) { |
| 3720 | set->frame_irq = 1; |
| 3721 | item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); |
| 3722 | if (V4L2_FIELD_HAS_TOP(item->vb.field)) |
| 3723 | set->top = item; |
| 3724 | if (V4L2_FIELD_HAS_BOTTOM(item->vb.field)) |
| 3725 | set->bottom = item; |
| 3726 | |
| 3727 | /* capture request for other field ? */ |
| 3728 | if (!V4L2_FIELD_HAS_BOTH(item->vb.field) && |
| 3729 | (item->vb.queue.next != &btv->capture)) { |
| 3730 | item = list_entry(item->vb.queue.next, struct bttv_buffer, vb.queue); |
Mike Isely | 66349b4 | 2009-09-21 12:09:08 -0300 | [diff] [blame] | 3731 | /* Mike Isely <isely@pobox.com> - Only check |
| 3732 | * and set up the bottom field in the logic |
| 3733 | * below. Don't ever do the top field. This |
| 3734 | * of course means that if we set up the |
| 3735 | * bottom field in the above code that we'll |
| 3736 | * actually skip a field. But that's OK. |
| 3737 | * Having processed only a single buffer this |
| 3738 | * time, then the next time around the first |
| 3739 | * available buffer should be for a top field. |
| 3740 | * That will then cause us here to set up a |
| 3741 | * top then a bottom field in the normal way. |
| 3742 | * The alternative to this understanding is |
| 3743 | * that we set up the second available buffer |
| 3744 | * as a top field, but that's out of order |
| 3745 | * since this driver always processes the top |
| 3746 | * field first - the effect will be the two |
| 3747 | * buffers being returned in the wrong order, |
| 3748 | * with the second buffer also being delayed |
| 3749 | * by one field time (owing to the fifo nature |
| 3750 | * of videobuf). Worse still, we'll be stuck |
| 3751 | * doing fields out of order now every time |
| 3752 | * until something else causes a field to be |
| 3753 | * dropped. By effectively forcing a field to |
| 3754 | * drop this way then we always get back into |
| 3755 | * sync within a single frame time. (Out of |
| 3756 | * order fields can screw up deinterlacing |
| 3757 | * algorithms.) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | if (!V4L2_FIELD_HAS_BOTH(item->vb.field)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | if (NULL == set->bottom && |
| 3760 | V4L2_FIELD_BOTTOM == item->vb.field) { |
| 3761 | set->bottom = item; |
| 3762 | } |
| 3763 | if (NULL != set->top && NULL != set->bottom) |
| 3764 | set->top_irq = 2; |
| 3765 | } |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | /* screen overlay ? */ |
| 3770 | if (NULL != btv->screen) { |
| 3771 | if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) { |
| 3772 | if (NULL == set->top && NULL == set->bottom) { |
| 3773 | set->top = btv->screen; |
| 3774 | set->bottom = btv->screen; |
| 3775 | } |
| 3776 | } else { |
| 3777 | if (V4L2_FIELD_TOP == btv->screen->vb.field && |
| 3778 | NULL == set->top) { |
| 3779 | set->top = btv->screen; |
| 3780 | } |
| 3781 | if (V4L2_FIELD_BOTTOM == btv->screen->vb.field && |
| 3782 | NULL == set->bottom) { |
| 3783 | set->bottom = btv->screen; |
| 3784 | } |
| 3785 | } |
| 3786 | } |
| 3787 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3788 | dprintk("%d: next set: top=%p bottom=%p [screen=%p,irq=%d,%d]\n", |
| 3789 | btv->c.nr, set->top, set->bottom, |
| 3790 | btv->screen, set->frame_irq, set->top_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | return 0; |
| 3792 | } |
| 3793 | |
| 3794 | static void |
| 3795 | bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup, |
| 3796 | struct bttv_buffer_set *curr, unsigned int state) |
| 3797 | { |
| 3798 | struct timeval ts; |
| 3799 | |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 3800 | v4l2_get_timestamp(&ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | |
| 3802 | if (wakeup->top == wakeup->bottom) { |
| 3803 | if (NULL != wakeup->top && curr->top != wakeup->top) { |
| 3804 | if (irq_debug > 1) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3805 | pr_debug("%d: wakeup: both=%p\n", |
| 3806 | btv->c.nr, wakeup->top); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | wakeup->top->vb.ts = ts; |
| 3808 | wakeup->top->vb.field_count = btv->field_count; |
| 3809 | wakeup->top->vb.state = state; |
| 3810 | wake_up(&wakeup->top->vb.done); |
| 3811 | } |
| 3812 | } else { |
| 3813 | if (NULL != wakeup->top && curr->top != wakeup->top) { |
| 3814 | if (irq_debug > 1) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3815 | pr_debug("%d: wakeup: top=%p\n", |
| 3816 | btv->c.nr, wakeup->top); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | wakeup->top->vb.ts = ts; |
| 3818 | wakeup->top->vb.field_count = btv->field_count; |
| 3819 | wakeup->top->vb.state = state; |
| 3820 | wake_up(&wakeup->top->vb.done); |
| 3821 | } |
| 3822 | if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) { |
| 3823 | if (irq_debug > 1) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3824 | pr_debug("%d: wakeup: bottom=%p\n", |
| 3825 | btv->c.nr, wakeup->bottom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | wakeup->bottom->vb.ts = ts; |
| 3827 | wakeup->bottom->vb.field_count = btv->field_count; |
| 3828 | wakeup->bottom->vb.state = state; |
| 3829 | wake_up(&wakeup->bottom->vb.done); |
| 3830 | } |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | static void |
| 3835 | bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup, |
| 3836 | unsigned int state) |
| 3837 | { |
| 3838 | struct timeval ts; |
| 3839 | |
| 3840 | if (NULL == wakeup) |
| 3841 | return; |
| 3842 | |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 3843 | v4l2_get_timestamp(&ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | wakeup->vb.ts = ts; |
| 3845 | wakeup->vb.field_count = btv->field_count; |
| 3846 | wakeup->vb.state = state; |
| 3847 | wake_up(&wakeup->vb.done); |
| 3848 | } |
| 3849 | |
| 3850 | static void bttv_irq_timeout(unsigned long data) |
| 3851 | { |
| 3852 | struct bttv *btv = (struct bttv *)data; |
| 3853 | struct bttv_buffer_set old,new; |
| 3854 | struct bttv_buffer *ovbi; |
| 3855 | struct bttv_buffer *item; |
| 3856 | unsigned long flags; |
| 3857 | |
| 3858 | if (bttv_verbose) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3859 | pr_info("%d: timeout: drop=%d irq=%d/%d, risc=%08x, ", |
| 3860 | btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total, |
| 3861 | btread(BT848_RISC_COUNT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | bttv_print_irqbits(btread(BT848_INT_STAT),0); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 3863 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | spin_lock_irqsave(&btv->s_lock,flags); |
| 3867 | |
| 3868 | /* deactivate stuff */ |
| 3869 | memset(&new,0,sizeof(new)); |
| 3870 | old = btv->curr; |
| 3871 | ovbi = btv->cvbi; |
| 3872 | btv->curr = new; |
| 3873 | btv->cvbi = NULL; |
| 3874 | btv->loop_irq = 0; |
| 3875 | bttv_buffer_activate_video(btv, &new); |
| 3876 | bttv_buffer_activate_vbi(btv, NULL); |
| 3877 | bttv_set_dma(btv, 0); |
| 3878 | |
| 3879 | /* wake up */ |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3880 | bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_ERROR); |
| 3881 | bttv_irq_wakeup_vbi(btv, ovbi, VIDEOBUF_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | |
| 3883 | /* cancel all outstanding capture / vbi requests */ |
| 3884 | while (!list_empty(&btv->capture)) { |
| 3885 | item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); |
| 3886 | list_del(&item->vb.queue); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3887 | item->vb.state = VIDEOBUF_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | wake_up(&item->vb.done); |
| 3889 | } |
| 3890 | while (!list_empty(&btv->vcapture)) { |
| 3891 | item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); |
| 3892 | list_del(&item->vb.queue); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3893 | item->vb.state = VIDEOBUF_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | wake_up(&item->vb.done); |
| 3895 | } |
| 3896 | |
| 3897 | btv->errors++; |
| 3898 | spin_unlock_irqrestore(&btv->s_lock,flags); |
| 3899 | } |
| 3900 | |
| 3901 | static void |
| 3902 | bttv_irq_wakeup_top(struct bttv *btv) |
| 3903 | { |
| 3904 | struct bttv_buffer *wakeup = btv->curr.top; |
| 3905 | |
| 3906 | if (NULL == wakeup) |
| 3907 | return; |
| 3908 | |
| 3909 | spin_lock(&btv->s_lock); |
| 3910 | btv->curr.top_irq = 0; |
| 3911 | btv->curr.top = NULL; |
| 3912 | bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0); |
| 3913 | |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 3914 | v4l2_get_timestamp(&wakeup->vb.ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | wakeup->vb.field_count = btv->field_count; |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3916 | wakeup->vb.state = VIDEOBUF_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | wake_up(&wakeup->vb.done); |
| 3918 | spin_unlock(&btv->s_lock); |
| 3919 | } |
| 3920 | |
| 3921 | static inline int is_active(struct btcx_riscmem *risc, u32 rc) |
| 3922 | { |
| 3923 | if (rc < risc->dma) |
| 3924 | return 0; |
| 3925 | if (rc > risc->dma + risc->size) |
| 3926 | return 0; |
| 3927 | return 1; |
| 3928 | } |
| 3929 | |
| 3930 | static void |
| 3931 | bttv_irq_switch_video(struct bttv *btv) |
| 3932 | { |
| 3933 | struct bttv_buffer_set new; |
| 3934 | struct bttv_buffer_set old; |
| 3935 | dma_addr_t rc; |
| 3936 | |
| 3937 | spin_lock(&btv->s_lock); |
| 3938 | |
| 3939 | /* new buffer set */ |
| 3940 | bttv_irq_next_video(btv, &new); |
| 3941 | rc = btread(BT848_RISC_COUNT); |
| 3942 | if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) || |
| 3943 | (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) { |
| 3944 | btv->framedrop++; |
| 3945 | if (debug_latency) |
| 3946 | bttv_irq_debug_low_latency(btv, rc); |
| 3947 | spin_unlock(&btv->s_lock); |
| 3948 | return; |
| 3949 | } |
| 3950 | |
| 3951 | /* switch over */ |
| 3952 | old = btv->curr; |
| 3953 | btv->curr = new; |
| 3954 | btv->loop_irq &= ~1; |
| 3955 | bttv_buffer_activate_video(btv, &new); |
| 3956 | bttv_set_dma(btv, 0); |
| 3957 | |
| 3958 | /* switch input */ |
| 3959 | if (UNSET != btv->new_input) { |
| 3960 | video_mux(btv,btv->new_input); |
| 3961 | btv->new_input = UNSET; |
| 3962 | } |
| 3963 | |
| 3964 | /* wake up finished buffers */ |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3965 | bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_DONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | spin_unlock(&btv->s_lock); |
| 3967 | } |
| 3968 | |
| 3969 | static void |
| 3970 | bttv_irq_switch_vbi(struct bttv *btv) |
| 3971 | { |
| 3972 | struct bttv_buffer *new = NULL; |
| 3973 | struct bttv_buffer *old; |
| 3974 | u32 rc; |
| 3975 | |
| 3976 | spin_lock(&btv->s_lock); |
| 3977 | |
| 3978 | if (!list_empty(&btv->vcapture)) |
| 3979 | new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); |
| 3980 | old = btv->cvbi; |
| 3981 | |
| 3982 | rc = btread(BT848_RISC_COUNT); |
| 3983 | if (NULL != old && (is_active(&old->top, rc) || |
| 3984 | is_active(&old->bottom, rc))) { |
| 3985 | btv->framedrop++; |
| 3986 | if (debug_latency) |
| 3987 | bttv_irq_debug_low_latency(btv, rc); |
| 3988 | spin_unlock(&btv->s_lock); |
| 3989 | return; |
| 3990 | } |
| 3991 | |
| 3992 | /* switch */ |
| 3993 | btv->cvbi = new; |
| 3994 | btv->loop_irq &= ~4; |
| 3995 | bttv_buffer_activate_vbi(btv, new); |
| 3996 | bttv_set_dma(btv, 0); |
| 3997 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 3998 | bttv_irq_wakeup_vbi(btv, old, VIDEOBUF_DONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | spin_unlock(&btv->s_lock); |
| 4000 | } |
| 4001 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 4002 | static irqreturn_t bttv_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | { |
| 4004 | u32 stat,astat; |
| 4005 | u32 dstat; |
| 4006 | int count; |
| 4007 | struct bttv *btv; |
| 4008 | int handled = 0; |
| 4009 | |
| 4010 | btv=(struct bttv *)dev_id; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 4011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | count=0; |
| 4013 | while (1) { |
| 4014 | /* get/clear interrupt status bits */ |
| 4015 | stat=btread(BT848_INT_STAT); |
| 4016 | astat=stat&btread(BT848_INT_MASK); |
| 4017 | if (!astat) |
| 4018 | break; |
| 4019 | handled = 1; |
| 4020 | btwrite(stat,BT848_INT_STAT); |
| 4021 | |
| 4022 | /* get device status bits */ |
| 4023 | dstat=btread(BT848_DSTATUS); |
| 4024 | |
| 4025 | if (irq_debug) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4026 | pr_debug("%d: irq loop=%d fc=%d riscs=%x, riscc=%08x, ", |
| 4027 | btv->c.nr, count, btv->field_count, |
| 4028 | stat>>28, btread(BT848_RISC_COUNT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | bttv_print_irqbits(stat,astat); |
| 4030 | if (stat & BT848_INT_HLOCK) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4031 | pr_cont(" HLOC => %s", |
| 4032 | dstat & BT848_DSTATUS_HLOC |
| 4033 | ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | if (stat & BT848_INT_VPRES) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4035 | pr_cont(" PRES => %s", |
| 4036 | dstat & BT848_DSTATUS_PRES |
| 4037 | ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | if (stat & BT848_INT_FMTCHG) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4039 | pr_cont(" NUML => %s", |
| 4040 | dstat & BT848_DSTATUS_NUML |
| 4041 | ? "625" : "525"); |
| 4042 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | if (astat&BT848_INT_VSYNC) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4046 | btv->field_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 4048 | if ((astat & BT848_INT_GPINT) && btv->remote) { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 4049 | bttv_input_irq(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | if (astat & BT848_INT_I2CDONE) { |
| 4053 | btv->i2c_done = stat; |
| 4054 | wake_up(&btv->i2c_queue); |
| 4055 | } |
| 4056 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4057 | if ((astat & BT848_INT_RISCI) && (stat & (4<<28))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | bttv_irq_switch_vbi(btv); |
| 4059 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4060 | if ((astat & BT848_INT_RISCI) && (stat & (2<<28))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | bttv_irq_wakeup_top(btv); |
| 4062 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4063 | if ((astat & BT848_INT_RISCI) && (stat & (1<<28))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | bttv_irq_switch_video(btv); |
| 4065 | |
| 4066 | if ((astat & BT848_INT_HLOCK) && btv->opt_automute) |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 4067 | audio_mute(btv, btv->mute); /* trigger automute */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | |
| 4069 | if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4070 | pr_info("%d: %s%s @ %08x,", |
| 4071 | btv->c.nr, |
| 4072 | (astat & BT848_INT_SCERR) ? "SCERR" : "", |
| 4073 | (astat & BT848_INT_OCERR) ? "OCERR" : "", |
| 4074 | btread(BT848_RISC_COUNT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | bttv_print_irqbits(stat,astat); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4076 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | if (bttv_debug) |
| 4078 | bttv_print_riscaddr(btv); |
| 4079 | } |
| 4080 | if (fdsr && astat & BT848_INT_FDSR) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4081 | pr_info("%d: FDSR @ %08x\n", |
| 4082 | btv->c.nr, btread(BT848_RISC_COUNT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | if (bttv_debug) |
| 4084 | bttv_print_riscaddr(btv); |
| 4085 | } |
| 4086 | |
| 4087 | count++; |
| 4088 | if (count > 4) { |
nshmyrev@yandex.ru | c58c21c | 2005-11-08 21:37:41 -0800 | [diff] [blame] | 4089 | |
| 4090 | if (count > 8 || !(astat & BT848_INT_GPINT)) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4091 | btwrite(0, BT848_INT_MASK); |
nshmyrev@yandex.ru | c58c21c | 2005-11-08 21:37:41 -0800 | [diff] [blame] | 4092 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4093 | pr_err("%d: IRQ lockup, cleared int mask [", |
| 4094 | btv->c.nr); |
nshmyrev@yandex.ru | c58c21c | 2005-11-08 21:37:41 -0800 | [diff] [blame] | 4095 | } else { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4096 | pr_err("%d: IRQ lockup, clearing GPINT from int mask [", |
| 4097 | btv->c.nr); |
nshmyrev@yandex.ru | c58c21c | 2005-11-08 21:37:41 -0800 | [diff] [blame] | 4098 | |
| 4099 | btwrite(btread(BT848_INT_MASK) & (-1 ^ BT848_INT_GPINT), |
| 4100 | BT848_INT_MASK); |
| 4101 | }; |
| 4102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | bttv_print_irqbits(stat,astat); |
nshmyrev@yandex.ru | c58c21c | 2005-11-08 21:37:41 -0800 | [diff] [blame] | 4104 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4105 | pr_cont("]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | } |
| 4107 | } |
| 4108 | btv->irq_total++; |
| 4109 | if (handled) |
| 4110 | btv->irq_me++; |
| 4111 | return IRQ_RETVAL(handled); |
| 4112 | } |
| 4113 | |
| 4114 | |
| 4115 | /* ----------------------------------------------------------------------- */ |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 4116 | /* initialization */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | |
| 4118 | static struct video_device *vdev_init(struct bttv *btv, |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 4119 | const struct video_device *template, |
Hans Verkuil | 0ea6bc8 | 2008-07-26 08:26:43 -0300 | [diff] [blame] | 4120 | const char *type_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | { |
| 4122 | struct video_device *vfd; |
| 4123 | |
| 4124 | vfd = video_device_alloc(); |
| 4125 | if (NULL == vfd) |
| 4126 | return NULL; |
| 4127 | *vfd = *template; |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4128 | vfd->v4l2_dev = &btv->c.v4l2_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | vfd->release = video_device_release; |
Mauro Carvalho Chehab | 1d0a436 | 2008-06-23 12:31:29 -0300 | [diff] [blame] | 4130 | vfd->debug = bttv_debug; |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 4131 | video_set_drvdata(vfd, btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", |
| 4133 | btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 4134 | type_name, bttv_tvcards[btv->c.type].name); |
Hans Verkuil | d9b6707 | 2013-02-06 11:43:07 -0300 | [diff] [blame^] | 4135 | if (btv->tuner_type == TUNER_ABSENT) { |
| 4136 | v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY); |
| 4137 | v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY); |
| 4138 | v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER); |
| 4139 | v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER); |
| 4140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | return vfd; |
| 4142 | } |
| 4143 | |
| 4144 | static void bttv_unregister_video(struct bttv *btv) |
| 4145 | { |
| 4146 | if (btv->video_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 4147 | if (video_is_registered(btv->video_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | video_unregister_device(btv->video_dev); |
| 4149 | else |
| 4150 | video_device_release(btv->video_dev); |
| 4151 | btv->video_dev = NULL; |
| 4152 | } |
| 4153 | if (btv->vbi_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 4154 | if (video_is_registered(btv->vbi_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | video_unregister_device(btv->vbi_dev); |
| 4156 | else |
| 4157 | video_device_release(btv->vbi_dev); |
| 4158 | btv->vbi_dev = NULL; |
| 4159 | } |
| 4160 | if (btv->radio_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 4161 | if (video_is_registered(btv->radio_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | video_unregister_device(btv->radio_dev); |
| 4163 | else |
| 4164 | video_device_release(btv->radio_dev); |
| 4165 | btv->radio_dev = NULL; |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | /* register video4linux devices */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 4170 | static int bttv_register_video(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | { |
Hans Verkuil | 0ea6bc8 | 2008-07-26 08:26:43 -0300 | [diff] [blame] | 4172 | if (no_overlay > 0) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4173 | pr_notice("Overlay support disabled\n"); |
Mauro Carvalho Chehab | 4dcef52 | 2005-08-04 12:53:30 -0700 | [diff] [blame] | 4174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | /* video */ |
Hans Verkuil | 0ea6bc8 | 2008-07-26 08:26:43 -0300 | [diff] [blame] | 4176 | btv->video_dev = vdev_init(btv, &bttv_video_template, "video"); |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 4177 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4178 | if (NULL == btv->video_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | goto err; |
Jean Delvare | 176c2f3 | 2008-09-07 12:49:59 -0300 | [diff] [blame] | 4180 | if (video_register_device(btv->video_dev, VFL_TYPE_GRABBER, |
| 4181 | video_nr[btv->c.nr]) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | goto err; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4183 | pr_info("%d: registered device %s\n", |
| 4184 | btv->c.nr, video_device_node_name(btv->video_dev)); |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 4185 | if (device_create_file(&btv->video_dev->dev, |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 4186 | &dev_attr_card)<0) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4187 | pr_err("%d: device_create_file 'card' failed\n", btv->c.nr); |
Trent Piepho | d94fc9a | 2006-07-29 17:18:06 -0300 | [diff] [blame] | 4188 | goto err; |
| 4189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | |
| 4191 | /* vbi */ |
Hans Verkuil | 0ea6bc8 | 2008-07-26 08:26:43 -0300 | [diff] [blame] | 4192 | btv->vbi_dev = vdev_init(btv, &bttv_video_template, "vbi"); |
Mauro Carvalho Chehab | 9134be0 | 2007-12-27 22:28:31 -0300 | [diff] [blame] | 4193 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4194 | if (NULL == btv->vbi_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | goto err; |
Jean Delvare | 176c2f3 | 2008-09-07 12:49:59 -0300 | [diff] [blame] | 4196 | if (video_register_device(btv->vbi_dev, VFL_TYPE_VBI, |
| 4197 | vbi_nr[btv->c.nr]) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | goto err; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4199 | pr_info("%d: registered device %s\n", |
| 4200 | btv->c.nr, video_device_node_name(btv->vbi_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4202 | if (!btv->has_radio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | return 0; |
| 4204 | /* radio */ |
Hans Verkuil | 0ea6bc8 | 2008-07-26 08:26:43 -0300 | [diff] [blame] | 4205 | btv->radio_dev = vdev_init(btv, &radio_template, "radio"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4206 | if (NULL == btv->radio_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | goto err; |
Jean Delvare | 176c2f3 | 2008-09-07 12:49:59 -0300 | [diff] [blame] | 4208 | if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO, |
| 4209 | radio_nr[btv->c.nr]) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | goto err; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4211 | pr_info("%d: registered device %s\n", |
| 4212 | btv->c.nr, video_device_node_name(btv->radio_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | |
| 4214 | /* all done */ |
| 4215 | return 0; |
| 4216 | |
| 4217 | err: |
| 4218 | bttv_unregister_video(btv); |
| 4219 | return -1; |
| 4220 | } |
| 4221 | |
| 4222 | |
| 4223 | /* on OpenFirmware machines (PowerMac at least), PCI memory cycle */ |
| 4224 | /* response on cards with no firmware is not enabled by OF */ |
| 4225 | static void pci_set_command(struct pci_dev *dev) |
| 4226 | { |
| 4227 | #if defined(__powerpc__) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4228 | unsigned int cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4230 | pci_read_config_dword(dev, PCI_COMMAND, &cmd); |
| 4231 | cmd = (cmd | PCI_COMMAND_MEMORY ); |
| 4232 | pci_write_config_dword(dev, PCI_COMMAND, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | #endif |
| 4234 | } |
| 4235 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 4236 | static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | { |
| 4238 | int result; |
| 4239 | unsigned char lat; |
| 4240 | struct bttv *btv; |
| 4241 | |
| 4242 | if (bttv_num == BTTV_MAX) |
| 4243 | return -ENOMEM; |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4244 | pr_info("Bt8xx card found (%d)\n", bttv_num); |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 4245 | bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL); |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4246 | if (btv == NULL) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4247 | pr_err("out of memory\n"); |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4248 | return -ENOMEM; |
| 4249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | btv->c.nr = bttv_num; |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4251 | snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name), |
| 4252 | "bttv%d", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | |
| 4254 | /* initialize structs / fill in defaults */ |
Ingo Molnar | bd5f0ac | 2006-01-13 14:10:24 -0200 | [diff] [blame] | 4255 | mutex_init(&btv->lock); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4256 | spin_lock_init(&btv->s_lock); |
| 4257 | spin_lock_init(&btv->gpio_lock); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4258 | init_waitqueue_head(&btv->i2c_queue); |
| 4259 | INIT_LIST_HEAD(&btv->c.subs); |
| 4260 | INIT_LIST_HEAD(&btv->capture); |
| 4261 | INIT_LIST_HEAD(&btv->vcapture); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | v4l2_prio_init(&btv->prio); |
| 4263 | |
| 4264 | init_timer(&btv->timeout); |
| 4265 | btv->timeout.function = bttv_irq_timeout; |
| 4266 | btv->timeout.data = (unsigned long)btv; |
| 4267 | |
Michael Krufky | 7c08fb0 | 2005-11-08 21:36:21 -0800 | [diff] [blame] | 4268 | btv->i2c_rc = -1; |
| 4269 | btv->tuner_type = UNSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | btv->new_input = UNSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | btv->has_radio=radio[btv->c.nr]; |
| 4272 | |
| 4273 | /* pci stuff (init, get irq/mmio, ... */ |
| 4274 | btv->c.pci = dev; |
Michael Krufky | 7c08fb0 | 2005-11-08 21:36:21 -0800 | [diff] [blame] | 4275 | btv->id = dev->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | if (pci_enable_device(dev)) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4277 | pr_warn("%d: Can't enable device\n", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | return -EIO; |
| 4279 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4280 | if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4281 | pr_warn("%d: No suitable DMA available\n", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | return -EIO; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | if (!request_mem_region(pci_resource_start(dev,0), |
| 4285 | pci_resource_len(dev,0), |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4286 | btv->c.v4l2_dev.name)) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4287 | pr_warn("%d: can't request iomem (0x%llx)\n", |
| 4288 | btv->c.nr, |
| 4289 | (unsigned long long)pci_resource_start(dev, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | return -EBUSY; |
| 4291 | } |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4292 | pci_set_master(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | pci_set_command(dev); |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4294 | |
| 4295 | result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev); |
| 4296 | if (result < 0) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4297 | pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr); |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4298 | goto fail0; |
| 4299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | |
Bjørn Mork | abd34d8 | 2011-03-21 11:35:56 -0300 | [diff] [blame] | 4301 | btv->revision = dev->revision; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4302 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4303 | pr_info("%d: Bt%d (rev %d) at %s, irq: %d, latency: %d, mmio: 0x%llx\n", |
| 4304 | bttv_num, btv->id, btv->revision, pci_name(dev), |
| 4305 | btv->c.pci->irq, lat, |
| 4306 | (unsigned long long)pci_resource_start(dev, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | schedule(); |
| 4308 | |
Akinobu Mita | 5f1693f | 2006-12-20 10:08:56 -0300 | [diff] [blame] | 4309 | btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000); |
| 4310 | if (NULL == btv->bt848_mmio) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4311 | pr_err("%d: ioremap() failed\n", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | result = -EIO; |
| 4313 | goto fail1; |
| 4314 | } |
| 4315 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4316 | /* identify card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | bttv_idcard(btv); |
| 4318 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4319 | /* disable irqs, register irq handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | btwrite(0, BT848_INT_MASK); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4321 | result = request_irq(btv->c.pci->irq, bttv_irq, |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4322 | IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4323 | if (result < 0) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4324 | pr_err("%d: can't get IRQ %d\n", |
| 4325 | bttv_num, btv->c.pci->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | goto fail1; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | |
| 4329 | if (0 != bttv_handle_chipset(btv)) { |
| 4330 | result = -EIO; |
| 4331 | goto fail2; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | |
| 4334 | /* init options from insmod args */ |
| 4335 | btv->opt_combfilter = combfilter; |
| 4336 | btv->opt_lumafilter = lumafilter; |
| 4337 | btv->opt_automute = automute; |
| 4338 | btv->opt_chroma_agc = chroma_agc; |
| 4339 | btv->opt_adc_crush = adc_crush; |
| 4340 | btv->opt_vcr_hack = vcr_hack; |
| 4341 | btv->opt_whitecrush_upper = whitecrush_upper; |
| 4342 | btv->opt_whitecrush_lower = whitecrush_lower; |
Mauro Carvalho Chehab | 060d302 | 2005-06-28 20:45:25 -0700 | [diff] [blame] | 4343 | btv->opt_uv_ratio = uv_ratio; |
| 4344 | btv->opt_full_luma_range = full_luma_range; |
| 4345 | btv->opt_coring = coring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | |
| 4347 | /* fill struct bttv with some useful defaults */ |
| 4348 | btv->init.btv = btv; |
| 4349 | btv->init.ov.w.width = 320; |
| 4350 | btv->init.ov.w.height = 240; |
Mauro Carvalho Chehab | c96dd07 | 2007-10-26 16:51:47 -0300 | [diff] [blame] | 4351 | btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | btv->init.width = 320; |
| 4353 | btv->init.height = 240; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | btv->input = 0; |
| 4355 | |
| 4356 | /* initialize hardware */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4357 | if (bttv_gpio) |
| 4358 | bttv_gpio_tracking(btv,"pre-init"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | |
| 4360 | bttv_risc_init_main(btv); |
| 4361 | init_bt848(btv); |
| 4362 | |
| 4363 | /* gpio */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4364 | btwrite(0x00, BT848_GPIO_REG_INP); |
| 4365 | btwrite(0x00, BT848_GPIO_OUT_EN); |
| 4366 | if (bttv_verbose) |
| 4367 | bttv_gpio_tracking(btv,"init"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4369 | /* needs to be done before i2c is registered */ |
| 4370 | bttv_init_card1(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4372 | /* register i2c + gpio */ |
| 4373 | init_bttv_i2c(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4375 | /* some card-specific stuff (needs working i2c) */ |
| 4376 | bttv_init_card2(btv); |
Hans Verkuil | 2c90577 | 2009-07-20 08:14:17 -0300 | [diff] [blame] | 4377 | bttv_init_tuner(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | init_irqreg(btv); |
| 4379 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4380 | /* register video4linux + input */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | if (!bttv_tvcards[btv->c.type].no_video) { |
| 4382 | bttv_register_video(btv); |
| 4383 | bt848_bright(btv,32768); |
Alan McIvor | 961e668 | 2012-04-01 21:11:08 -0300 | [diff] [blame] | 4384 | bt848_contrast(btv, 27648); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | bt848_hue(btv,32768); |
| 4386 | bt848_sat(btv,32768); |
Hans Verkuil | 8bf2f8e | 2006-03-18 21:31:00 -0300 | [diff] [blame] | 4387 | audio_mute(btv, 1); |
Trent Piepho | 333408f | 2007-07-03 15:08:10 -0300 | [diff] [blame] | 4388 | set_input(btv, 0, btv->tvnorm); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 4389 | bttv_crop_reset(&btv->crop[0], btv->tvnorm); |
| 4390 | btv->crop[1] = btv->crop[0]; /* current = default */ |
| 4391 | disclaim_vbi_lines(btv); |
| 4392 | disclaim_video_lines(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
Jarod Wilson | f992a49 | 2007-03-24 15:23:50 -0300 | [diff] [blame] | 4395 | /* add subdevices and autoload dvb-bt8xx if needed */ |
| 4396 | if (bttv_tvcards[btv->c.type].has_dvb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | bttv_sub_add_device(&btv->c, "dvb"); |
Jarod Wilson | f992a49 | 2007-03-24 15:23:50 -0300 | [diff] [blame] | 4398 | request_modules(btv); |
| 4399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | |
Jean Delvare | d90a4ae | 2010-02-16 14:22:37 -0300 | [diff] [blame] | 4401 | if (!disable_ir) { |
| 4402 | init_bttv_i2c_ir(btv); |
| 4403 | bttv_input_init(btv); |
| 4404 | } |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 4405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | /* everything is fine */ |
| 4407 | bttv_num++; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4408 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4410 | fail2: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4411 | free_irq(btv->c.pci->irq,btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4413 | fail1: |
| 4414 | v4l2_device_unregister(&btv->c.v4l2_dev); |
| 4415 | |
| 4416 | fail0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | if (btv->bt848_mmio) |
| 4418 | iounmap(btv->bt848_mmio); |
| 4419 | release_mem_region(pci_resource_start(btv->c.pci,0), |
| 4420 | pci_resource_len(btv->c.pci,0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | return result; |
| 4422 | } |
| 4423 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 4424 | static void bttv_remove(struct pci_dev *pci_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | { |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4426 | struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); |
| 4427 | struct bttv *btv = to_bttv(v4l2_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
| 4429 | if (bttv_verbose) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4430 | pr_info("%d: unloading\n", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | |
Tejun Heo | 707bcf3 | 2010-12-24 16:14:20 +0100 | [diff] [blame] | 4432 | if (bttv_tvcards[btv->c.type].has_dvb) |
| 4433 | flush_request_modules(btv); |
| 4434 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4435 | /* shutdown everything (DMA+IRQs) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | btand(~15, BT848_GPIO_DMA_CTL); |
| 4437 | btwrite(0, BT848_INT_MASK); |
| 4438 | btwrite(~0x0, BT848_INT_STAT); |
| 4439 | btwrite(0x0, BT848_GPIO_OUT_EN); |
| 4440 | if (bttv_gpio) |
| 4441 | bttv_gpio_tracking(btv,"cleanup"); |
| 4442 | |
| 4443 | /* tell gpio modules we are leaving ... */ |
| 4444 | btv->shutdown=1; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 4445 | bttv_input_fini(btv); |
Christopher Pascoe | 889aee8 | 2006-01-09 15:25:28 -0200 | [diff] [blame] | 4446 | bttv_sub_del_devices(&btv->c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4448 | /* unregister i2c_bus + input */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | fini_bttv_i2c(btv); |
| 4450 | |
| 4451 | /* unregister video4linux */ |
| 4452 | bttv_unregister_video(btv); |
| 4453 | |
| 4454 | /* free allocated memory */ |
| 4455 | btcx_riscmem_free(btv->c.pci,&btv->main); |
| 4456 | |
| 4457 | /* free ressources */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4458 | free_irq(btv->c.pci->irq,btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | iounmap(btv->bt848_mmio); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4460 | release_mem_region(pci_resource_start(btv->c.pci,0), |
| 4461 | pci_resource_len(btv->c.pci,0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4463 | v4l2_device_unregister(&btv->c.v4l2_dev); |
Trent Piepho | 4b10d3b | 2009-01-28 21:32:59 -0300 | [diff] [blame] | 4464 | bttvs[btv->c.nr] = NULL; |
| 4465 | kfree(btv); |
| 4466 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4467 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 4470 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) |
| 4472 | { |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4473 | struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); |
| 4474 | struct bttv *btv = to_bttv(v4l2_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | struct bttv_buffer_set idle; |
| 4476 | unsigned long flags; |
| 4477 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4478 | dprintk("%d: suspend %d\n", btv->c.nr, state.event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | |
| 4480 | /* stop dma + irqs */ |
| 4481 | spin_lock_irqsave(&btv->s_lock,flags); |
| 4482 | memset(&idle, 0, sizeof(idle)); |
| 4483 | btv->state.video = btv->curr; |
| 4484 | btv->state.vbi = btv->cvbi; |
| 4485 | btv->state.loop_irq = btv->loop_irq; |
| 4486 | btv->curr = idle; |
| 4487 | btv->loop_irq = 0; |
| 4488 | bttv_buffer_activate_video(btv, &idle); |
| 4489 | bttv_buffer_activate_vbi(btv, NULL); |
| 4490 | bttv_set_dma(btv, 0); |
| 4491 | btwrite(0, BT848_INT_MASK); |
| 4492 | spin_unlock_irqrestore(&btv->s_lock,flags); |
| 4493 | |
| 4494 | /* save bt878 state */ |
| 4495 | btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN); |
| 4496 | btv->state.gpio_data = gpio_read(); |
| 4497 | |
| 4498 | /* save pci state */ |
| 4499 | pci_save_state(pci_dev); |
| 4500 | if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { |
| 4501 | pci_disable_device(pci_dev); |
| 4502 | btv->state.disabled = 1; |
| 4503 | } |
| 4504 | return 0; |
| 4505 | } |
| 4506 | |
| 4507 | static int bttv_resume(struct pci_dev *pci_dev) |
| 4508 | { |
Hans Verkuil | 74fc7bd | 2009-03-14 12:36:54 -0300 | [diff] [blame] | 4509 | struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); |
| 4510 | struct bttv *btv = to_bttv(v4l2_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | unsigned long flags; |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 4512 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4514 | dprintk("%d: resume\n", btv->c.nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | |
| 4516 | /* restore pci state */ |
| 4517 | if (btv->state.disabled) { |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 4518 | err=pci_enable_device(pci_dev); |
| 4519 | if (err) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4520 | pr_warn("%d: Can't enable device\n", btv->c.nr); |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 4521 | return err; |
| 4522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | btv->state.disabled = 0; |
| 4524 | } |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 4525 | err=pci_set_power_state(pci_dev, PCI_D0); |
| 4526 | if (err) { |
| 4527 | pci_disable_device(pci_dev); |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4528 | pr_warn("%d: Can't enable device\n", btv->c.nr); |
Mauro Carvalho Chehab | 08adb9e | 2005-09-09 13:03:55 -0700 | [diff] [blame] | 4529 | btv->state.disabled = 1; |
| 4530 | return err; |
| 4531 | } |
| 4532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | pci_restore_state(pci_dev); |
| 4534 | |
| 4535 | /* restore bt878 state */ |
| 4536 | bttv_reinit_bt848(btv); |
| 4537 | gpio_inout(0xffffff, btv->state.gpio_enable); |
| 4538 | gpio_write(btv->state.gpio_data); |
| 4539 | |
| 4540 | /* restart dma */ |
| 4541 | spin_lock_irqsave(&btv->s_lock,flags); |
| 4542 | btv->curr = btv->state.video; |
| 4543 | btv->cvbi = btv->state.vbi; |
| 4544 | btv->loop_irq = btv->state.loop_irq; |
| 4545 | bttv_buffer_activate_video(btv, &btv->curr); |
| 4546 | bttv_buffer_activate_vbi(btv, btv->cvbi); |
| 4547 | bttv_set_dma(btv, 0); |
| 4548 | spin_unlock_irqrestore(&btv->s_lock,flags); |
| 4549 | return 0; |
| 4550 | } |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 4551 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | |
| 4553 | static struct pci_device_id bttv_pci_tbl[] = { |
Joe Perches | 76e9741 | 2009-07-05 15:59:21 -0300 | [diff] [blame] | 4554 | {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT848), 0}, |
| 4555 | {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT849), 0}, |
| 4556 | {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT878), 0}, |
| 4557 | {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT879), 0}, |
Peter De Schrijver | c540d9f | 2011-11-06 10:47:58 -0300 | [diff] [blame] | 4558 | {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_FUSION879), 0}, |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4559 | {0,} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | }; |
| 4561 | |
| 4562 | MODULE_DEVICE_TABLE(pci, bttv_pci_tbl); |
| 4563 | |
| 4564 | static struct pci_driver bttv_pci_driver = { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 4565 | .name = "bttv", |
| 4566 | .id_table = bttv_pci_tbl, |
| 4567 | .probe = bttv_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 4568 | .remove = bttv_remove, |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 4569 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | .suspend = bttv_suspend, |
| 4571 | .resume = bttv_resume, |
Alexey Dobriyan | 17bc98a | 2006-08-12 22:01:27 -0300 | [diff] [blame] | 4572 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | }; |
| 4574 | |
Adrian Bunk | 7d44e89 | 2007-12-11 19:23:43 -0300 | [diff] [blame] | 4575 | static int __init bttv_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | { |
Randy Dunlap | c526e22 | 2006-07-15 09:08:26 -0300 | [diff] [blame] | 4577 | int ret; |
| 4578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | bttv_num = 0; |
| 4580 | |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4581 | pr_info("driver version %s loaded\n", BTTV_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME) |
| 4583 | gbuffers = 2; |
Filipe Rosset | f41b696 | 2009-05-28 11:11:53 -0300 | [diff] [blame] | 4584 | if (gbufsize > BTTV_MAX_FBUF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | gbufsize = BTTV_MAX_FBUF; |
| 4586 | gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK; |
| 4587 | if (bttv_verbose) |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4588 | pr_info("using %d buffers with %dk (%d pages) each for capture\n", |
| 4589 | gbuffers, gbufsize >> 10, gbufsize >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | |
| 4591 | bttv_check_chipset(); |
| 4592 | |
Randy Dunlap | c526e22 | 2006-07-15 09:08:26 -0300 | [diff] [blame] | 4593 | ret = bus_register(&bttv_sub_bus_type); |
| 4594 | if (ret < 0) { |
Joe Perches | 8af443e | 2011-08-21 19:56:48 -0300 | [diff] [blame] | 4595 | pr_warn("bus_register error: %d\n", ret); |
Randy Dunlap | c526e22 | 2006-07-15 09:08:26 -0300 | [diff] [blame] | 4596 | return ret; |
| 4597 | } |
Akinobu Mita | 9e7e85e | 2007-12-17 14:26:29 -0300 | [diff] [blame] | 4598 | ret = pci_register_driver(&bttv_pci_driver); |
| 4599 | if (ret < 0) |
| 4600 | bus_unregister(&bttv_sub_bus_type); |
| 4601 | |
| 4602 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | } |
| 4604 | |
Adrian Bunk | 7d44e89 | 2007-12-11 19:23:43 -0300 | [diff] [blame] | 4605 | static void __exit bttv_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | { |
| 4607 | pci_unregister_driver(&bttv_pci_driver); |
| 4608 | bus_unregister(&bttv_sub_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | module_init(bttv_init_module); |
| 4612 | module_exit(bttv_cleanup_module); |
| 4613 | |
| 4614 | /* |
| 4615 | * Local variables: |
| 4616 | * c-basic-offset: 8 |
| 4617 | * End: |
| 4618 | */ |