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