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