Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1 | /* |
Hans Verkuil | 3ff4ad8 | 2009-04-01 03:15:52 -0300 | [diff] [blame] | 2 | * USB USBVISION Video device driver 0.9.10 |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 3 | * |
| 4 | * |
| 5 | * |
| 6 | * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> |
| 7 | * |
| 8 | * This module is part of usbvision driver project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | * Let's call the version 0.... until compression decoding is completely |
| 25 | * implemented. |
| 26 | * |
| 27 | * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach. |
| 28 | * It was based on USB CPiA driver written by Peter Pregler, |
| 29 | * Scott J. Bertin and Johannes Erdfelt |
| 30 | * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler & |
| 31 | * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink |
| 32 | * Updates to driver completed by Dwaine P. Garden |
| 33 | * |
| 34 | * |
| 35 | * TODO: |
| 36 | * - use submit_urb for all setup packets |
| 37 | * - Fix memory settings for nt1004. It is 4 times as big as the |
| 38 | * nt1003 memory. |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 39 | * - Add audio on endpoint 3 for nt1004 chip. |
| 40 | * Seems impossible, needs a codec interface. Which one? |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 41 | * - Clean up the driver. |
| 42 | * - optimization for performance. |
| 43 | * - Add Videotext capability (VBI). Working on it..... |
| 44 | * - Check audio for other devices |
| 45 | * |
| 46 | */ |
| 47 | |
Mauro Carvalho Chehab | f30ebd4 | 2006-12-09 12:32:18 -0300 | [diff] [blame] | 48 | #include <linux/version.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 49 | #include <linux/kernel.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 50 | #include <linux/list.h> |
| 51 | #include <linux/timer.h> |
| 52 | #include <linux/slab.h> |
Alexey Dobriyan | 405f557 | 2009-07-11 22:08:37 +0400 | [diff] [blame] | 53 | #include <linux/smp_lock.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 54 | #include <linux/mm.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 55 | #include <linux/highmem.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 56 | #include <linux/vmalloc.h> |
| 57 | #include <linux/module.h> |
| 58 | #include <linux/init.h> |
| 59 | #include <linux/spinlock.h> |
| 60 | #include <asm/io.h> |
| 61 | #include <linux/videodev2.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 62 | #include <linux/i2c.h> |
| 63 | |
| 64 | #include <media/saa7115.h> |
| 65 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 66 | #include <media/v4l2-ioctl.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 67 | #include <media/tuner.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 68 | |
Mauro Carvalho Chehab | a1ed551 | 2006-12-09 11:41:59 -0300 | [diff] [blame] | 69 | #include <linux/workqueue.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 70 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 71 | #include "usbvision.h" |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 72 | #include "usbvision-cards.h" |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 73 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 74 | #define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>,\ |
| 75 | Dwaine Garden <DwaineGarden@rogers.com>" |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 76 | #define DRIVER_NAME "usbvision" |
| 77 | #define DRIVER_ALIAS "USBVision" |
| 78 | #define DRIVER_DESC "USBVision USB Video Device Driver for Linux" |
| 79 | #define DRIVER_LICENSE "GPL" |
| 80 | #define USBVISION_DRIVER_VERSION_MAJOR 0 |
| 81 | #define USBVISION_DRIVER_VERSION_MINOR 9 |
Hans Verkuil | 3ff4ad8 | 2009-04-01 03:15:52 -0300 | [diff] [blame] | 82 | #define USBVISION_DRIVER_VERSION_PATCHLEVEL 10 |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 83 | #define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,\ |
| 84 | USBVISION_DRIVER_VERSION_MINOR,\ |
| 85 | USBVISION_DRIVER_VERSION_PATCHLEVEL) |
| 86 | #define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR)\ |
| 87 | "." __stringify(USBVISION_DRIVER_VERSION_MINOR)\ |
| 88 | "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 89 | |
| 90 | #define ENABLE_HEXDUMP 0 /* Enable if you need it */ |
| 91 | |
| 92 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 93 | #ifdef USBVISION_DEBUG |
Thierry MERLE | df18c31 | 2008-04-04 21:00:57 -0300 | [diff] [blame] | 94 | #define PDEBUG(level, fmt, args...) { \ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 95 | if (video_debug & (level)) \ |
Greg Kroah-Hartman | a482f32 | 2008-10-10 05:08:23 -0300 | [diff] [blame] | 96 | printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ |
| 97 | __func__, __LINE__ , ## args); \ |
Thierry MERLE | df18c31 | 2008-04-04 21:00:57 -0300 | [diff] [blame] | 98 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 99 | #else |
| 100 | #define PDEBUG(level, fmt, args...) do {} while(0) |
| 101 | #endif |
| 102 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 103 | #define DBG_IO 1<<1 |
| 104 | #define DBG_PROBE 1<<2 |
Thierry MERLE | c876a34 | 2006-12-09 16:42:54 -0300 | [diff] [blame] | 105 | #define DBG_MMAP 1<<3 |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 106 | |
| 107 | //String operations |
| 108 | #define rmspace(str) while(*str==' ') str++; |
| 109 | #define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++; |
| 110 | |
| 111 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 112 | /* sequential number of usbvision device */ |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 113 | static int usbvision_nr; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 114 | |
| 115 | static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = { |
| 116 | { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" }, |
| 117 | { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" }, |
| 118 | { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" }, |
| 119 | { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" }, |
| 120 | { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" }, |
| 121 | { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" }, |
| 122 | { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, // 1.5 ! |
| 123 | { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" } |
| 124 | }; |
| 125 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 126 | /* Function prototypes */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 127 | static void usbvision_release(struct usb_usbvision *usbvision); |
| 128 | |
Joe Perches | c84e603 | 2008-02-03 17:18:59 +0200 | [diff] [blame] | 129 | /* Default initialization of device driver parameters */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 130 | /* Set the default format for ISOC endpoint */ |
| 131 | static int isocMode = ISOC_MODE_COMPRESS; |
| 132 | /* Set the default Debug Mode of the device driver */ |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 133 | static int video_debug; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 134 | /* Set the default device to power on at startup */ |
| 135 | static int PowerOnAtOpen = 1; |
| 136 | /* Sequential Number of Video Device */ |
| 137 | static int video_nr = -1; |
| 138 | /* Sequential Number of Radio Device */ |
| 139 | static int radio_nr = -1; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 140 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 141 | /* Grab parameters for the device driver */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 142 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 143 | /* Showing parameters under SYSFS */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 144 | module_param(isocMode, int, 0444); |
| 145 | module_param(video_debug, int, 0444); |
| 146 | module_param(PowerOnAtOpen, int, 0444); |
| 147 | module_param(video_nr, int, 0444); |
| 148 | module_param(radio_nr, int, 0444); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 149 | |
| 150 | MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); |
| 151 | MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)"); |
| 152 | MODULE_PARM_DESC(PowerOnAtOpen, " Set the default device to power on when device is opened. Default: 1 (On)"); |
| 153 | MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)"); |
| 154 | MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 155 | |
| 156 | |
| 157 | // Misc stuff |
| 158 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 159 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 160 | MODULE_LICENSE(DRIVER_LICENSE); |
Mauro Carvalho Chehab | a1ed551 | 2006-12-09 11:41:59 -0300 | [diff] [blame] | 161 | MODULE_VERSION(USBVISION_VERSION_STRING); |
| 162 | MODULE_ALIAS(DRIVER_ALIAS); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 163 | |
| 164 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 165 | /*****************************************************************************/ |
| 166 | /* SYSFS Code - Copied from the stv680.c usb module. */ |
| 167 | /* Device information is located at /sys/class/video4linux/video0 */ |
| 168 | /* Device parameters information is located at /sys/module/usbvision */ |
| 169 | /* Device USB Information is located at */ |
| 170 | /* /sys/bus/usb/drivers/USBVision Video Grabber */ |
| 171 | /*****************************************************************************/ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 172 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 173 | #define YES_NO(x) ((x) ? "Yes" : "No") |
| 174 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 175 | static inline struct usb_usbvision *cd_to_usbvision(struct device *cd) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 176 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 177 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 178 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 179 | return video_get_drvdata(vdev); |
| 180 | } |
| 181 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 182 | static ssize_t show_version(struct device *cd, |
| 183 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 184 | { |
| 185 | return sprintf(buf, "%s\n", USBVISION_VERSION_STRING); |
| 186 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 187 | static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 188 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 189 | static ssize_t show_model(struct device *cd, |
| 190 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 191 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 192 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 193 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 194 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 195 | return sprintf(buf, "%s\n", |
| 196 | usbvision_device_data[usbvision->DevModel].ModelString); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 197 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 198 | static DEVICE_ATTR(model, S_IRUGO, show_model, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 199 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 200 | static ssize_t show_hue(struct device *cd, |
| 201 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 202 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 203 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 204 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 205 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 206 | struct v4l2_control ctrl; |
| 207 | ctrl.id = V4L2_CID_HUE; |
| 208 | ctrl.value = 0; |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 209 | if(usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 210 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 211 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 212 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 213 | static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 214 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 215 | static ssize_t show_contrast(struct device *cd, |
| 216 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 217 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 218 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 219 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 220 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 221 | struct v4l2_control ctrl; |
| 222 | ctrl.id = V4L2_CID_CONTRAST; |
| 223 | ctrl.value = 0; |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 224 | if(usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 225 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 226 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 227 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 228 | static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 229 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 230 | static ssize_t show_brightness(struct device *cd, |
| 231 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 232 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 233 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 234 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 235 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 236 | struct v4l2_control ctrl; |
| 237 | ctrl.id = V4L2_CID_BRIGHTNESS; |
| 238 | ctrl.value = 0; |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 239 | if(usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 240 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 241 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 242 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 243 | static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 244 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 245 | static ssize_t show_saturation(struct device *cd, |
| 246 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 247 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 248 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 249 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 250 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 251 | struct v4l2_control ctrl; |
| 252 | ctrl.id = V4L2_CID_SATURATION; |
| 253 | ctrl.value = 0; |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 254 | if(usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 255 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 256 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 257 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 258 | static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 259 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 260 | static ssize_t show_streaming(struct device *cd, |
| 261 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 262 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 263 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 264 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 265 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 266 | return sprintf(buf, "%s\n", |
| 267 | YES_NO(usbvision->streaming==Stream_On?1:0)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 268 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 269 | static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 270 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 271 | static ssize_t show_compression(struct device *cd, |
| 272 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 273 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 274 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 275 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 276 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 277 | return sprintf(buf, "%s\n", |
| 278 | YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 279 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 280 | static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 281 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 282 | static ssize_t show_device_bridge(struct device *cd, |
| 283 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 284 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 285 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 286 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 287 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 288 | return sprintf(buf, "%d\n", usbvision->bridgeType); |
| 289 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 290 | static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 291 | |
| 292 | static void usbvision_create_sysfs(struct video_device *vdev) |
| 293 | { |
| 294 | int res; |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 295 | if (!vdev) |
| 296 | return; |
| 297 | do { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 298 | res = device_create_file(&vdev->dev, &dev_attr_version); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 299 | if (res<0) |
| 300 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 301 | res = device_create_file(&vdev->dev, &dev_attr_model); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 302 | if (res<0) |
| 303 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 304 | res = device_create_file(&vdev->dev, &dev_attr_hue); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 305 | if (res<0) |
| 306 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 307 | res = device_create_file(&vdev->dev, &dev_attr_contrast); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 308 | if (res<0) |
| 309 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 310 | res = device_create_file(&vdev->dev, &dev_attr_brightness); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 311 | if (res<0) |
| 312 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 313 | res = device_create_file(&vdev->dev, &dev_attr_saturation); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 314 | if (res<0) |
| 315 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 316 | res = device_create_file(&vdev->dev, &dev_attr_streaming); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 317 | if (res<0) |
| 318 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 319 | res = device_create_file(&vdev->dev, &dev_attr_compression); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 320 | if (res<0) |
| 321 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 322 | res = device_create_file(&vdev->dev, &dev_attr_bridge); |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 323 | if (res>=0) |
| 324 | return; |
| 325 | } while (0); |
| 326 | |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 327 | dev_err(&vdev->dev, "%s error: %d\n", __func__, res); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void usbvision_remove_sysfs(struct video_device *vdev) |
| 331 | { |
| 332 | if (vdev) { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 333 | device_remove_file(&vdev->dev, &dev_attr_version); |
| 334 | device_remove_file(&vdev->dev, &dev_attr_model); |
| 335 | device_remove_file(&vdev->dev, &dev_attr_hue); |
| 336 | device_remove_file(&vdev->dev, &dev_attr_contrast); |
| 337 | device_remove_file(&vdev->dev, &dev_attr_brightness); |
| 338 | device_remove_file(&vdev->dev, &dev_attr_saturation); |
| 339 | device_remove_file(&vdev->dev, &dev_attr_streaming); |
| 340 | device_remove_file(&vdev->dev, &dev_attr_compression); |
| 341 | device_remove_file(&vdev->dev, &dev_attr_bridge); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 345 | /* |
| 346 | * usbvision_open() |
| 347 | * |
| 348 | * This is part of Video 4 Linux API. The driver can be opened by one |
| 349 | * client only (checks internal counter 'usbvision->user'). The procedure |
| 350 | * then allocates buffers needed for video processing. |
| 351 | * |
| 352 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 353 | static int usbvision_v4l2_open(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 354 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 355 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 356 | int errCode = 0; |
| 357 | |
| 358 | PDEBUG(DBG_IO, "open"); |
| 359 | |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 360 | lock_kernel(); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 361 | usbvision_reset_powerOffTimer(usbvision); |
| 362 | |
| 363 | if (usbvision->user) |
| 364 | errCode = -EBUSY; |
| 365 | else { |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 366 | /* Allocate memory for the scratch ring buffer */ |
| 367 | errCode = usbvision_scratch_alloc(usbvision); |
| 368 | if (isocMode==ISOC_MODE_COMPRESS) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 369 | /* Allocate intermediate decompression buffers |
| 370 | only if needed */ |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 371 | errCode = usbvision_decompress_alloc(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 372 | } |
| 373 | if (errCode) { |
| 374 | /* Deallocate all buffers if trouble */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 375 | usbvision_scratch_free(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 376 | usbvision_decompress_free(usbvision); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /* If so far no errors then we shall start the camera */ |
| 381 | if (!errCode) { |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 382 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 383 | if (usbvision->power == 0) { |
| 384 | usbvision_power_on(usbvision); |
Thierry MERLE | 1ff16c2 | 2007-04-14 16:23:49 -0300 | [diff] [blame] | 385 | usbvision_i2c_register(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /* Send init sequence only once, it's large! */ |
| 389 | if (!usbvision->initialized) { |
| 390 | int setup_ok = 0; |
| 391 | setup_ok = usbvision_setup(usbvision,isocMode); |
| 392 | if (setup_ok) |
| 393 | usbvision->initialized = 1; |
| 394 | else |
| 395 | errCode = -EBUSY; |
| 396 | } |
| 397 | |
| 398 | if (!errCode) { |
| 399 | usbvision_begin_streaming(usbvision); |
| 400 | errCode = usbvision_init_isoc(usbvision); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 401 | /* device must be initialized before isoc transfer */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 402 | usbvision_muxsel(usbvision,0); |
| 403 | usbvision->user++; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 404 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 405 | if (PowerOnAtOpen) { |
Thierry MERLE | 1ff16c2 | 2007-04-14 16:23:49 -0300 | [diff] [blame] | 406 | usbvision_i2c_unregister(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 407 | usbvision_power_off(usbvision); |
| 408 | usbvision->initialized = 0; |
| 409 | } |
| 410 | } |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 411 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 412 | } |
| 413 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 414 | /* prepare queues */ |
| 415 | usbvision_empty_framequeues(usbvision); |
| 416 | |
| 417 | PDEBUG(DBG_IO, "success"); |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 418 | unlock_kernel(); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 419 | return errCode; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * usbvision_v4l2_close() |
| 424 | * |
| 425 | * This is part of Video 4 Linux API. The procedure |
| 426 | * stops streaming and deallocates all buffers that were earlier |
| 427 | * allocated in usbvision_v4l2_open(). |
| 428 | * |
| 429 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 430 | static int usbvision_v4l2_close(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 431 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 432 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 433 | |
| 434 | PDEBUG(DBG_IO, "close"); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 435 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 436 | |
| 437 | usbvision_audio_off(usbvision); |
| 438 | usbvision_restart_isoc(usbvision); |
| 439 | usbvision_stop_isoc(usbvision); |
| 440 | |
| 441 | usbvision_decompress_free(usbvision); |
Thierry MERLE | 38284ba | 2006-12-15 16:46:53 -0300 | [diff] [blame] | 442 | usbvision_frames_free(usbvision); |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 443 | usbvision_empty_framequeues(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 444 | usbvision_scratch_free(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 445 | |
| 446 | usbvision->user--; |
| 447 | |
| 448 | if (PowerOnAtOpen) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 449 | /* power off in a little while |
| 450 | to avoid off/on every close/open short sequences */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 451 | usbvision_set_powerOffTimer(usbvision); |
| 452 | usbvision->initialized = 0; |
| 453 | } |
| 454 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 455 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 456 | |
| 457 | if (usbvision->remove_pending) { |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 458 | printk(KERN_INFO "%s: Final disconnect\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 459 | usbvision_release(usbvision); |
| 460 | } |
| 461 | |
| 462 | PDEBUG(DBG_IO, "success"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | |
| 467 | /* |
| 468 | * usbvision_ioctl() |
| 469 | * |
| 470 | * This is part of Video 4 Linux API. The procedure handles ioctl() calls. |
| 471 | * |
| 472 | */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 473 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 474 | static int vidioc_g_register (struct file *file, void *priv, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 475 | struct v4l2_dbg_register *reg) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 476 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 477 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 478 | int errCode; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 479 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 480 | if (!v4l2_chip_match_host(®->match)) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 481 | return -EINVAL; |
| 482 | /* NT100x has a 8-bit register space */ |
| 483 | errCode = usbvision_read_reg(usbvision, reg->reg&0xff); |
| 484 | if (errCode < 0) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 485 | dev_err(&usbvision->vdev->dev, |
| 486 | "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", |
| 487 | __func__, errCode); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 488 | return errCode; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 489 | } |
Trent Piepho | bc14713 | 2007-07-23 06:58:31 -0300 | [diff] [blame] | 490 | reg->val = errCode; |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 491 | reg->size = 1; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 495 | static int vidioc_s_register (struct file *file, void *priv, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 496 | struct v4l2_dbg_register *reg) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 497 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 498 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 499 | int errCode; |
| 500 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 501 | if (!v4l2_chip_match_host(®->match)) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 502 | return -EINVAL; |
| 503 | /* NT100x has a 8-bit register space */ |
Trent Piepho | bc14713 | 2007-07-23 06:58:31 -0300 | [diff] [blame] | 504 | errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val); |
| 505 | if (errCode < 0) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 506 | dev_err(&usbvision->vdev->dev, |
| 507 | "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", |
| 508 | __func__, errCode); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 509 | return errCode; |
| 510 | } |
| 511 | return 0; |
| 512 | } |
| 513 | #endif |
| 514 | |
| 515 | static int vidioc_querycap (struct file *file, void *priv, |
| 516 | struct v4l2_capability *vc) |
| 517 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 518 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 519 | |
| 520 | strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); |
| 521 | strlcpy(vc->card, |
| 522 | usbvision_device_data[usbvision->DevModel].ModelString, |
| 523 | sizeof(vc->card)); |
Thierry MERLE | 6f2a278 | 2009-01-20 17:40:44 -0300 | [diff] [blame] | 524 | usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info)); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 525 | vc->version = USBVISION_DRIVER_VERSION; |
| 526 | vc->capabilities = V4L2_CAP_VIDEO_CAPTURE | |
| 527 | V4L2_CAP_AUDIO | |
| 528 | V4L2_CAP_READWRITE | |
| 529 | V4L2_CAP_STREAMING | |
| 530 | (usbvision->have_tuner ? V4L2_CAP_TUNER : 0); |
| 531 | return 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 532 | } |
| 533 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 534 | static int vidioc_enum_input (struct file *file, void *priv, |
| 535 | struct v4l2_input *vi) |
| 536 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 537 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 538 | int chan; |
| 539 | |
Roel Kluin | 223ffe5 | 2009-05-02 16:38:47 -0300 | [diff] [blame] | 540 | if (vi->index >= usbvision->video_inputs) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 541 | return -EINVAL; |
| 542 | if (usbvision->have_tuner) { |
| 543 | chan = vi->index; |
| 544 | } else { |
| 545 | chan = vi->index + 1; /*skip Television string*/ |
| 546 | } |
| 547 | /* Determine the requested input characteristics |
| 548 | specific for each usbvision card model */ |
| 549 | switch(chan) { |
| 550 | case 0: |
| 551 | if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { |
| 552 | strcpy(vi->name, "White Video Input"); |
| 553 | } else { |
| 554 | strcpy(vi->name, "Television"); |
| 555 | vi->type = V4L2_INPUT_TYPE_TUNER; |
| 556 | vi->audioset = 1; |
| 557 | vi->tuner = chan; |
| 558 | vi->std = USBVISION_NORMS; |
| 559 | } |
| 560 | break; |
| 561 | case 1: |
| 562 | vi->type = V4L2_INPUT_TYPE_CAMERA; |
| 563 | if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { |
| 564 | strcpy(vi->name, "Green Video Input"); |
| 565 | } else { |
| 566 | strcpy(vi->name, "Composite Video Input"); |
| 567 | } |
| 568 | vi->std = V4L2_STD_PAL; |
| 569 | break; |
| 570 | case 2: |
| 571 | vi->type = V4L2_INPUT_TYPE_CAMERA; |
| 572 | if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { |
| 573 | strcpy(vi->name, "Yellow Video Input"); |
| 574 | } else { |
| 575 | strcpy(vi->name, "S-Video Input"); |
| 576 | } |
| 577 | vi->std = V4L2_STD_PAL; |
| 578 | break; |
| 579 | case 3: |
| 580 | vi->type = V4L2_INPUT_TYPE_CAMERA; |
| 581 | strcpy(vi->name, "Red Video Input"); |
| 582 | vi->std = V4L2_STD_PAL; |
| 583 | break; |
| 584 | } |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int vidioc_g_input (struct file *file, void *priv, unsigned int *input) |
| 589 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 590 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 591 | |
| 592 | *input = usbvision->ctl_input; |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static int vidioc_s_input (struct file *file, void *priv, unsigned int input) |
| 597 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 598 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 599 | |
Roel Kluin | f14a297 | 2009-10-23 07:59:42 -0300 | [diff] [blame] | 600 | if (input >= usbvision->video_inputs) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 601 | return -EINVAL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 602 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 603 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 66a1787 | 2007-06-26 16:35:30 -0300 | [diff] [blame] | 604 | usbvision_muxsel(usbvision, input); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 605 | usbvision_set_input(usbvision); |
| 606 | usbvision_set_output(usbvision, |
| 607 | usbvision->curwidth, |
| 608 | usbvision->curheight); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 609 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id) |
| 614 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 615 | struct usb_usbvision *usbvision = video_drvdata(file); |
| 616 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 617 | usbvision->tvnormId=*id; |
| 618 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 619 | mutex_lock(&usbvision->lock); |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 620 | call_all(usbvision, core, s_std, usbvision->tvnormId); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 621 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 66a1787 | 2007-06-26 16:35:30 -0300 | [diff] [blame] | 622 | /* propagate the change to the decoder */ |
| 623 | usbvision_muxsel(usbvision, usbvision->ctl_input); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static int vidioc_g_tuner (struct file *file, void *priv, |
| 629 | struct v4l2_tuner *vt) |
| 630 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 631 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 632 | |
| 633 | if (!usbvision->have_tuner || vt->index) // Only tuner 0 |
| 634 | return -EINVAL; |
| 635 | if(usbvision->radio) { |
| 636 | strcpy(vt->name, "Radio"); |
| 637 | vt->type = V4L2_TUNER_RADIO; |
| 638 | } else { |
| 639 | strcpy(vt->name, "Television"); |
| 640 | } |
| 641 | /* Let clients fill in the remainder of this struct */ |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 642 | call_all(usbvision, tuner, g_tuner, vt); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | static int vidioc_s_tuner (struct file *file, void *priv, |
| 648 | struct v4l2_tuner *vt) |
| 649 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 650 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 651 | |
| 652 | // Only no or one tuner for now |
| 653 | if (!usbvision->have_tuner || vt->index) |
| 654 | return -EINVAL; |
| 655 | /* let clients handle this */ |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 656 | call_all(usbvision, tuner, s_tuner, vt); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | static int vidioc_g_frequency (struct file *file, void *priv, |
| 662 | struct v4l2_frequency *freq) |
| 663 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 664 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 665 | |
| 666 | freq->tuner = 0; // Only one tuner |
| 667 | if(usbvision->radio) { |
| 668 | freq->type = V4L2_TUNER_RADIO; |
| 669 | } else { |
| 670 | freq->type = V4L2_TUNER_ANALOG_TV; |
| 671 | } |
| 672 | freq->frequency = usbvision->freq; |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | static int vidioc_s_frequency (struct file *file, void *priv, |
| 678 | struct v4l2_frequency *freq) |
| 679 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 680 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 681 | |
| 682 | // Only no or one tuner for now |
| 683 | if (!usbvision->have_tuner || freq->tuner) |
| 684 | return -EINVAL; |
| 685 | |
| 686 | usbvision->freq = freq->frequency; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 687 | call_all(usbvision, tuner, s_frequency, freq); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a) |
| 693 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 694 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 695 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 696 | if(usbvision->radio) { |
| 697 | strcpy(a->name,"Radio"); |
| 698 | } else { |
| 699 | strcpy(a->name, "TV"); |
| 700 | } |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int vidioc_s_audio (struct file *file, void *fh, |
| 706 | struct v4l2_audio *a) |
| 707 | { |
| 708 | if(a->index) { |
| 709 | return -EINVAL; |
| 710 | } |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int vidioc_queryctrl (struct file *file, void *priv, |
| 716 | struct v4l2_queryctrl *ctrl) |
| 717 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 718 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 719 | |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 720 | call_all(usbvision, core, queryctrl, ctrl); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 721 | |
| 722 | if (!ctrl->type) |
| 723 | return -EINVAL; |
| 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static int vidioc_g_ctrl (struct file *file, void *priv, |
| 729 | struct v4l2_control *ctrl) |
| 730 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 731 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 732 | call_all(usbvision, core, g_ctrl, ctrl); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | static int vidioc_s_ctrl (struct file *file, void *priv, |
| 738 | struct v4l2_control *ctrl) |
| 739 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 740 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 741 | call_all(usbvision, core, s_ctrl, ctrl); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | static int vidioc_reqbufs (struct file *file, |
| 747 | void *priv, struct v4l2_requestbuffers *vr) |
| 748 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 749 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 750 | int ret; |
| 751 | |
| 752 | RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES); |
| 753 | |
| 754 | /* Check input validity: |
| 755 | the user must do a VIDEO CAPTURE and MMAP method. */ |
Trent Piepho | 975f576 | 2009-03-28 22:25:36 -0300 | [diff] [blame] | 756 | if (vr->memory != V4L2_MEMORY_MMAP) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 757 | return -EINVAL; |
| 758 | |
| 759 | if(usbvision->streaming == Stream_On) { |
| 760 | if ((ret = usbvision_stream_interrupt(usbvision))) |
| 761 | return ret; |
| 762 | } |
| 763 | |
| 764 | usbvision_frames_free(usbvision); |
| 765 | usbvision_empty_framequeues(usbvision); |
| 766 | vr->count = usbvision_frames_alloc(usbvision,vr->count); |
| 767 | |
| 768 | usbvision->curFrame = NULL; |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static int vidioc_querybuf (struct file *file, |
| 774 | void *priv, struct v4l2_buffer *vb) |
| 775 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 776 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 777 | struct usbvision_frame *frame; |
| 778 | |
| 779 | /* FIXME : must control |
| 780 | that buffers are mapped (VIDIOC_REQBUFS has been called) */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 781 | if(vb->index>=usbvision->num_frames) { |
| 782 | return -EINVAL; |
| 783 | } |
| 784 | /* Updating the corresponding frame state */ |
| 785 | vb->flags = 0; |
| 786 | frame = &usbvision->frame[vb->index]; |
| 787 | if(frame->grabstate >= FrameState_Ready) |
| 788 | vb->flags |= V4L2_BUF_FLAG_QUEUED; |
| 789 | if(frame->grabstate >= FrameState_Done) |
| 790 | vb->flags |= V4L2_BUF_FLAG_DONE; |
| 791 | if(frame->grabstate == FrameState_Unused) |
| 792 | vb->flags |= V4L2_BUF_FLAG_MAPPED; |
| 793 | vb->memory = V4L2_MEMORY_MMAP; |
| 794 | |
| 795 | vb->m.offset = vb->index*PAGE_ALIGN(usbvision->max_frame_size); |
| 796 | |
| 797 | vb->memory = V4L2_MEMORY_MMAP; |
| 798 | vb->field = V4L2_FIELD_NONE; |
| 799 | vb->length = usbvision->curwidth* |
| 800 | usbvision->curheight* |
| 801 | usbvision->palette.bytes_per_pixel; |
| 802 | vb->timestamp = usbvision->frame[vb->index].timestamp; |
| 803 | vb->sequence = usbvision->frame[vb->index].sequence; |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb) |
| 808 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 809 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 810 | struct usbvision_frame *frame; |
| 811 | unsigned long lock_flags; |
| 812 | |
| 813 | /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 814 | if(vb->index>=usbvision->num_frames) { |
| 815 | return -EINVAL; |
| 816 | } |
| 817 | |
| 818 | frame = &usbvision->frame[vb->index]; |
| 819 | |
| 820 | if (frame->grabstate != FrameState_Unused) { |
| 821 | return -EAGAIN; |
| 822 | } |
| 823 | |
| 824 | /* Mark it as ready and enqueue frame */ |
| 825 | frame->grabstate = FrameState_Ready; |
| 826 | frame->scanstate = ScanState_Scanning; |
| 827 | frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ |
| 828 | |
| 829 | vb->flags &= ~V4L2_BUF_FLAG_DONE; |
| 830 | |
| 831 | /* set v4l2_format index */ |
| 832 | frame->v4l2_format = usbvision->palette; |
| 833 | |
| 834 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 835 | list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue); |
| 836 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb) |
| 842 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 843 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 844 | int ret; |
| 845 | struct usbvision_frame *f; |
| 846 | unsigned long lock_flags; |
| 847 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 848 | if (list_empty(&(usbvision->outqueue))) { |
| 849 | if (usbvision->streaming == Stream_Idle) |
| 850 | return -EINVAL; |
| 851 | ret = wait_event_interruptible |
| 852 | (usbvision->wait_frame, |
| 853 | !list_empty(&(usbvision->outqueue))); |
| 854 | if (ret) |
| 855 | return ret; |
| 856 | } |
| 857 | |
| 858 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 859 | f = list_entry(usbvision->outqueue.next, |
| 860 | struct usbvision_frame, frame); |
| 861 | list_del(usbvision->outqueue.next); |
| 862 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); |
| 863 | |
| 864 | f->grabstate = FrameState_Unused; |
| 865 | |
| 866 | vb->memory = V4L2_MEMORY_MMAP; |
| 867 | vb->flags = V4L2_BUF_FLAG_MAPPED | |
| 868 | V4L2_BUF_FLAG_QUEUED | |
| 869 | V4L2_BUF_FLAG_DONE; |
| 870 | vb->index = f->index; |
| 871 | vb->sequence = f->sequence; |
| 872 | vb->timestamp = f->timestamp; |
| 873 | vb->field = V4L2_FIELD_NONE; |
| 874 | vb->bytesused = f->scanlength; |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 880 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 881 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 882 | |
| 883 | usbvision->streaming = Stream_On; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 884 | call_all(usbvision, video, s_stream, 1); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | static int vidioc_streamoff(struct file *file, |
| 890 | void *priv, enum v4l2_buf_type type) |
| 891 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 892 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 893 | |
| 894 | if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 895 | return -EINVAL; |
| 896 | |
| 897 | if(usbvision->streaming == Stream_On) { |
| 898 | usbvision_stream_interrupt(usbvision); |
| 899 | /* Stop all video streamings */ |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 900 | call_all(usbvision, video, s_stream, 0); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 901 | } |
| 902 | usbvision_empty_framequeues(usbvision); |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 907 | static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 908 | struct v4l2_fmtdesc *vfd) |
| 909 | { |
| 910 | if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) { |
| 911 | return -EINVAL; |
| 912 | } |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 913 | strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc); |
| 914 | vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 915 | return 0; |
| 916 | } |
| 917 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 918 | static int vidioc_g_fmt_vid_cap (struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 919 | struct v4l2_format *vf) |
| 920 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 921 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 922 | vf->fmt.pix.width = usbvision->curwidth; |
| 923 | vf->fmt.pix.height = usbvision->curheight; |
| 924 | vf->fmt.pix.pixelformat = usbvision->palette.format; |
| 925 | vf->fmt.pix.bytesperline = |
| 926 | usbvision->curwidth*usbvision->palette.bytes_per_pixel; |
| 927 | vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*usbvision->curheight; |
| 928 | vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 929 | vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 934 | static int vidioc_try_fmt_vid_cap (struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 935 | struct v4l2_format *vf) |
| 936 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 937 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 938 | int formatIdx; |
| 939 | |
| 940 | /* Find requested format in available ones */ |
| 941 | for(formatIdx=0;formatIdx<USBVISION_SUPPORTED_PALETTES;formatIdx++) { |
| 942 | if(vf->fmt.pix.pixelformat == |
| 943 | usbvision_v4l2_format[formatIdx].format) { |
| 944 | usbvision->palette = usbvision_v4l2_format[formatIdx]; |
| 945 | break; |
| 946 | } |
| 947 | } |
| 948 | /* robustness */ |
| 949 | if(formatIdx == USBVISION_SUPPORTED_PALETTES) { |
| 950 | return -EINVAL; |
| 951 | } |
| 952 | RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH); |
| 953 | RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); |
| 954 | |
| 955 | vf->fmt.pix.bytesperline = vf->fmt.pix.width* |
| 956 | usbvision->palette.bytes_per_pixel; |
| 957 | vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height; |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 962 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 963 | struct v4l2_format *vf) |
| 964 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 965 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 966 | int ret; |
| 967 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 968 | if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 969 | return ret; |
| 970 | } |
| 971 | |
| 972 | /* stop io in case it is already in progress */ |
| 973 | if(usbvision->streaming == Stream_On) { |
| 974 | if ((ret = usbvision_stream_interrupt(usbvision))) |
| 975 | return ret; |
| 976 | } |
| 977 | usbvision_frames_free(usbvision); |
| 978 | usbvision_empty_framequeues(usbvision); |
| 979 | |
| 980 | usbvision->curFrame = NULL; |
| 981 | |
| 982 | /* by now we are committed to the new data... */ |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 983 | mutex_lock(&usbvision->lock); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 984 | usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 985 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 986 | |
| 987 | return 0; |
| 988 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 989 | |
Al Viro | 8a5ab41 | 2007-02-09 16:38:20 +0000 | [diff] [blame] | 990 | static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 991 | size_t count, loff_t *ppos) |
| 992 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 993 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 994 | int noblock = file->f_flags & O_NONBLOCK; |
| 995 | unsigned long lock_flags; |
| 996 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 997 | int ret,i; |
| 998 | struct usbvision_frame *frame; |
| 999 | |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1000 | PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1001 | (unsigned long)count, noblock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1002 | |
| 1003 | if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL)) |
| 1004 | return -EFAULT; |
| 1005 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1006 | /* This entry point is compatible with the mmap routines |
| 1007 | so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF |
| 1008 | to get frames or call read on the device. */ |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1009 | if(!usbvision->num_frames) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1010 | /* First, allocate some frames to work with |
| 1011 | if this has not been done with VIDIOC_REQBUF */ |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1012 | usbvision_frames_free(usbvision); |
| 1013 | usbvision_empty_framequeues(usbvision); |
| 1014 | usbvision_frames_alloc(usbvision,USBVISION_NUMFRAMES); |
| 1015 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1016 | |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1017 | if(usbvision->streaming != Stream_On) { |
| 1018 | /* no stream is running, make it running ! */ |
| 1019 | usbvision->streaming = Stream_On; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1020 | call_all(usbvision, video, s_stream, 1); |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1021 | } |
| 1022 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1023 | /* Then, enqueue as many frames as possible |
| 1024 | (like a user of VIDIOC_QBUF would do) */ |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1025 | for(i=0;i<usbvision->num_frames;i++) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1026 | frame = &usbvision->frame[i]; |
| 1027 | if(frame->grabstate == FrameState_Unused) { |
| 1028 | /* Mark it as ready and enqueue frame */ |
| 1029 | frame->grabstate = FrameState_Ready; |
| 1030 | frame->scanstate = ScanState_Scanning; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1031 | /* Accumulated in usbvision_parse_data() */ |
| 1032 | frame->scanlength = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1033 | |
| 1034 | /* set v4l2_format index */ |
| 1035 | frame->v4l2_format = usbvision->palette; |
| 1036 | |
| 1037 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 1038 | list_add_tail(&frame->frame, &usbvision->inqueue); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1039 | spin_unlock_irqrestore(&usbvision->queue_lock, |
| 1040 | lock_flags); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */ |
| 1045 | if (list_empty(&(usbvision->outqueue))) { |
| 1046 | if(noblock) |
| 1047 | return -EAGAIN; |
| 1048 | |
| 1049 | ret = wait_event_interruptible |
| 1050 | (usbvision->wait_frame, |
| 1051 | !list_empty(&(usbvision->outqueue))); |
| 1052 | if (ret) |
| 1053 | return ret; |
| 1054 | } |
| 1055 | |
| 1056 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 1057 | frame = list_entry(usbvision->outqueue.next, |
| 1058 | struct usbvision_frame, frame); |
| 1059 | list_del(usbvision->outqueue.next); |
| 1060 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); |
| 1061 | |
| 1062 | /* An error returns an empty frame */ |
| 1063 | if (frame->grabstate == FrameState_Error) { |
| 1064 | frame->bytes_read = 0; |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1068 | PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1069 | __func__, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1070 | frame->index, frame->bytes_read, frame->scanlength); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1071 | |
| 1072 | /* copy bytes to user space; we allow for partials reads */ |
| 1073 | if ((count + frame->bytes_read) > (unsigned long)frame->scanlength) |
| 1074 | count = frame->scanlength - frame->bytes_read; |
| 1075 | |
| 1076 | if (copy_to_user(buf, frame->data + frame->bytes_read, count)) { |
| 1077 | return -EFAULT; |
| 1078 | } |
| 1079 | |
| 1080 | frame->bytes_read += count; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1081 | PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1082 | __func__, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1083 | (unsigned long)count, frame->bytes_read); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1084 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1085 | /* For now, forget the frame if it has not been read in one shot. */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1086 | /* if (frame->bytes_read >= frame->scanlength) {// All data has been read */ |
| 1087 | frame->bytes_read = 0; |
| 1088 | |
| 1089 | /* Mark it as available to be used again. */ |
Thierry MERLE | c430ca1 | 2006-12-29 20:32:08 -0300 | [diff] [blame] | 1090 | frame->grabstate = FrameState_Unused; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1091 | /* } */ |
| 1092 | |
| 1093 | return count; |
| 1094 | } |
| 1095 | |
| 1096 | static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma) |
| 1097 | { |
| 1098 | unsigned long size = vma->vm_end - vma->vm_start, |
| 1099 | start = vma->vm_start; |
| 1100 | void *pos; |
| 1101 | u32 i; |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 1102 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1103 | |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1104 | PDEBUG(DBG_MMAP, "mmap"); |
| 1105 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1106 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1107 | |
| 1108 | if (!USBVISION_IS_OPERATIONAL(usbvision)) { |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1109 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1110 | return -EFAULT; |
| 1111 | } |
| 1112 | |
| 1113 | if (!(vma->vm_flags & VM_WRITE) || |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1114 | size != PAGE_ALIGN(usbvision->max_frame_size)) { |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1115 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1116 | return -EINVAL; |
| 1117 | } |
| 1118 | |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1119 | for (i = 0; i < usbvision->num_frames; i++) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1120 | if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) == |
| 1121 | vma->vm_pgoff) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1122 | break; |
| 1123 | } |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1124 | if (i == usbvision->num_frames) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1125 | PDEBUG(DBG_MMAP, |
| 1126 | "mmap: user supplied mapping address is out of range"); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1127 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1128 | return -EINVAL; |
| 1129 | } |
| 1130 | |
| 1131 | /* VM_IO is eventually going to replace PageReserved altogether */ |
| 1132 | vma->vm_flags |= VM_IO; |
| 1133 | vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ |
| 1134 | |
| 1135 | pos = usbvision->frame[i].data; |
| 1136 | while (size > 0) { |
| 1137 | |
| 1138 | if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { |
Thierry MERLE | c876a34 | 2006-12-09 16:42:54 -0300 | [diff] [blame] | 1139 | PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed"); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1140 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1141 | return -EAGAIN; |
| 1142 | } |
| 1143 | start += PAGE_SIZE; |
| 1144 | pos += PAGE_SIZE; |
| 1145 | size -= PAGE_SIZE; |
| 1146 | } |
| 1147 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1148 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1149 | return 0; |
| 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | /* |
| 1154 | * Here comes the stuff for radio on usbvision based devices |
| 1155 | * |
| 1156 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1157 | static int usbvision_radio_open(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1158 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 1159 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1160 | int errCode = 0; |
| 1161 | |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1162 | PDEBUG(DBG_IO, "%s:", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1163 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1164 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1165 | |
| 1166 | if (usbvision->user) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1167 | dev_err(&usbvision->rdev->dev, |
| 1168 | "%s: Someone tried to open an already opened USBVision Radio!\n", |
| 1169 | __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1170 | errCode = -EBUSY; |
| 1171 | } |
| 1172 | else { |
| 1173 | if(PowerOnAtOpen) { |
| 1174 | usbvision_reset_powerOffTimer(usbvision); |
| 1175 | if (usbvision->power == 0) { |
| 1176 | usbvision_power_on(usbvision); |
Thierry MERLE | 1ff16c2 | 2007-04-14 16:23:49 -0300 | [diff] [blame] | 1177 | usbvision_i2c_register(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1181 | /* Alternate interface 1 is is the biggest frame size */ |
| 1182 | errCode = usbvision_set_alternate(usbvision); |
| 1183 | if (errCode < 0) { |
| 1184 | usbvision->last_error = errCode; |
Andrew Morton | 544e617 | 2007-12-12 18:25:23 -0300 | [diff] [blame] | 1185 | errCode = -EBUSY; |
| 1186 | goto out; |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1187 | } |
| 1188 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1189 | // If so far no errors then we shall start the radio |
| 1190 | usbvision->radio = 1; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1191 | call_all(usbvision, tuner, s_radio); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1192 | usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); |
| 1193 | usbvision->user++; |
| 1194 | } |
| 1195 | |
| 1196 | if (errCode) { |
| 1197 | if (PowerOnAtOpen) { |
Thierry MERLE | 1ff16c2 | 2007-04-14 16:23:49 -0300 | [diff] [blame] | 1198 | usbvision_i2c_unregister(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1199 | usbvision_power_off(usbvision); |
| 1200 | usbvision->initialized = 0; |
| 1201 | } |
| 1202 | } |
Andrew Morton | 544e617 | 2007-12-12 18:25:23 -0300 | [diff] [blame] | 1203 | out: |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1204 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1205 | return errCode; |
| 1206 | } |
| 1207 | |
| 1208 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1209 | static int usbvision_radio_close(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1210 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 1211 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1212 | int errCode = 0; |
| 1213 | |
| 1214 | PDEBUG(DBG_IO, ""); |
| 1215 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1216 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1217 | |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1218 | /* Set packet size to 0 */ |
| 1219 | usbvision->ifaceAlt=0; |
| 1220 | errCode = usb_set_interface(usbvision->dev, usbvision->iface, |
| 1221 | usbvision->ifaceAlt); |
| 1222 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1223 | usbvision_audio_off(usbvision); |
| 1224 | usbvision->radio=0; |
| 1225 | usbvision->user--; |
| 1226 | |
| 1227 | if (PowerOnAtOpen) { |
| 1228 | usbvision_set_powerOffTimer(usbvision); |
| 1229 | usbvision->initialized = 0; |
| 1230 | } |
| 1231 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1232 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1233 | |
| 1234 | if (usbvision->remove_pending) { |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1235 | printk(KERN_INFO "%s: Final disconnect\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1236 | usbvision_release(usbvision); |
| 1237 | } |
| 1238 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1239 | PDEBUG(DBG_IO, "success"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1240 | return errCode; |
| 1241 | } |
| 1242 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1243 | // |
| 1244 | // Video registration stuff |
| 1245 | // |
| 1246 | |
| 1247 | // Video template |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1248 | static const struct v4l2_file_operations usbvision_fops = { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1249 | .owner = THIS_MODULE, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1250 | .open = usbvision_v4l2_open, |
| 1251 | .release = usbvision_v4l2_close, |
| 1252 | .read = usbvision_v4l2_read, |
| 1253 | .mmap = usbvision_v4l2_mmap, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1254 | .ioctl = video_ioctl2, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1255 | /* .poll = video_poll, */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1256 | }; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1257 | |
| 1258 | static const struct v4l2_ioctl_ops usbvision_ioctl_ops = { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1259 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1260 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1261 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1262 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1263 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1264 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1265 | .vidioc_querybuf = vidioc_querybuf, |
| 1266 | .vidioc_qbuf = vidioc_qbuf, |
| 1267 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1268 | .vidioc_s_std = vidioc_s_std, |
| 1269 | .vidioc_enum_input = vidioc_enum_input, |
| 1270 | .vidioc_g_input = vidioc_g_input, |
| 1271 | .vidioc_s_input = vidioc_s_input, |
| 1272 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1273 | .vidioc_g_audio = vidioc_g_audio, |
Al Viro | ed4d637 | 2007-09-26 01:53:42 +0100 | [diff] [blame] | 1274 | .vidioc_s_audio = vidioc_s_audio, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1275 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1276 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1277 | .vidioc_streamon = vidioc_streamon, |
| 1278 | .vidioc_streamoff = vidioc_streamoff, |
| 1279 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1280 | /* .vidiocgmbuf = vidiocgmbuf, */ |
| 1281 | #endif |
| 1282 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1283 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1284 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1285 | .vidioc_s_frequency = vidioc_s_frequency, |
| 1286 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1287 | .vidioc_g_register = vidioc_g_register, |
| 1288 | .vidioc_s_register = vidioc_s_register, |
| 1289 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1290 | }; |
| 1291 | |
| 1292 | static struct video_device usbvision_video_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1293 | .fops = &usbvision_fops, |
| 1294 | .ioctl_ops = &usbvision_ioctl_ops, |
| 1295 | .name = "usbvision-video", |
| 1296 | .release = video_device_release, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1297 | .tvnorms = USBVISION_NORMS, |
| 1298 | .current_norm = V4L2_STD_PAL |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1299 | }; |
| 1300 | |
| 1301 | |
| 1302 | // Radio template |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1303 | static const struct v4l2_file_operations usbvision_radio_fops = { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1304 | .owner = THIS_MODULE, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1305 | .open = usbvision_radio_open, |
| 1306 | .release = usbvision_radio_close, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1307 | .ioctl = video_ioctl2, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1308 | }; |
| 1309 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1310 | static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1311 | .vidioc_querycap = vidioc_querycap, |
| 1312 | .vidioc_enum_input = vidioc_enum_input, |
| 1313 | .vidioc_g_input = vidioc_g_input, |
| 1314 | .vidioc_s_input = vidioc_s_input, |
| 1315 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1316 | .vidioc_g_audio = vidioc_g_audio, |
Al Viro | ed4d637 | 2007-09-26 01:53:42 +0100 | [diff] [blame] | 1317 | .vidioc_s_audio = vidioc_s_audio, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1318 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1319 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1320 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1321 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1322 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1323 | .vidioc_s_frequency = vidioc_s_frequency, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1324 | }; |
| 1325 | |
| 1326 | static struct video_device usbvision_radio_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1327 | .fops = &usbvision_radio_fops, |
| 1328 | .name = "usbvision-radio", |
| 1329 | .release = video_device_release, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1330 | .ioctl_ops = &usbvision_radio_ioctl_ops, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1331 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1332 | .tvnorms = USBVISION_NORMS, |
| 1333 | .current_norm = V4L2_STD_PAL |
| 1334 | }; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1335 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1336 | |
| 1337 | static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision, |
| 1338 | struct video_device *vdev_template, |
| 1339 | char *name) |
| 1340 | { |
| 1341 | struct usb_device *usb_dev = usbvision->dev; |
| 1342 | struct video_device *vdev; |
| 1343 | |
| 1344 | if (usb_dev == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1345 | dev_err(&usbvision->dev->dev, |
| 1346 | "%s: usbvision->dev is not set\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1347 | return NULL; |
| 1348 | } |
| 1349 | |
| 1350 | vdev = video_device_alloc(); |
| 1351 | if (NULL == vdev) { |
| 1352 | return NULL; |
| 1353 | } |
| 1354 | *vdev = *vdev_template; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1355 | vdev->v4l2_dev = &usbvision->v4l2_dev; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1356 | snprintf(vdev->name, sizeof(vdev->name), "%s", name); |
| 1357 | video_set_drvdata(vdev, usbvision); |
| 1358 | return vdev; |
| 1359 | } |
| 1360 | |
| 1361 | // unregister video4linux devices |
| 1362 | static void usbvision_unregister_video(struct usb_usbvision *usbvision) |
| 1363 | { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1364 | // Radio Device: |
| 1365 | if (usbvision->rdev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1366 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", |
| 1367 | video_device_node_name(usbvision->rdev)); |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 1368 | if (video_is_registered(usbvision->rdev)) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1369 | video_unregister_device(usbvision->rdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1370 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1371 | video_device_release(usbvision->rdev); |
| 1372 | } |
| 1373 | usbvision->rdev = NULL; |
| 1374 | } |
| 1375 | |
| 1376 | // Video Device: |
| 1377 | if (usbvision->vdev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1378 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", |
| 1379 | video_device_node_name(usbvision->vdev)); |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 1380 | if (video_is_registered(usbvision->vdev)) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1381 | video_unregister_device(usbvision->vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1382 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1383 | video_device_release(usbvision->vdev); |
| 1384 | } |
| 1385 | usbvision->vdev = NULL; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | // register video4linux devices |
| 1390 | static int __devinit usbvision_register_video(struct usb_usbvision *usbvision) |
| 1391 | { |
| 1392 | // Video Device: |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1393 | usbvision->vdev = usbvision_vdev_init(usbvision, |
| 1394 | &usbvision_video_template, |
| 1395 | "USBVision Video"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1396 | if (usbvision->vdev == NULL) { |
| 1397 | goto err_exit; |
| 1398 | } |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1399 | if (video_register_device(usbvision->vdev, |
| 1400 | VFL_TYPE_GRABBER, |
| 1401 | video_nr)<0) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1402 | goto err_exit; |
| 1403 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1404 | printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", |
| 1405 | usbvision->nr, video_device_node_name(usbvision->vdev)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1406 | |
| 1407 | // Radio Device: |
| 1408 | if (usbvision_device_data[usbvision->DevModel].Radio) { |
| 1409 | // usbvision has radio |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1410 | usbvision->rdev = usbvision_vdev_init(usbvision, |
| 1411 | &usbvision_radio_template, |
| 1412 | "USBVision Radio"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1413 | if (usbvision->rdev == NULL) { |
| 1414 | goto err_exit; |
| 1415 | } |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1416 | if (video_register_device(usbvision->rdev, |
| 1417 | VFL_TYPE_RADIO, |
| 1418 | radio_nr)<0) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1419 | goto err_exit; |
| 1420 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1421 | printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", |
| 1422 | usbvision->nr, video_device_node_name(usbvision->rdev)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1423 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1424 | // all done |
| 1425 | return 0; |
| 1426 | |
| 1427 | err_exit: |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1428 | dev_err(&usbvision->dev->dev, |
| 1429 | "USBVision[%d]: video_register_device() failed\n", |
| 1430 | usbvision->nr); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1431 | usbvision_unregister_video(usbvision); |
| 1432 | return -1; |
| 1433 | } |
| 1434 | |
| 1435 | /* |
| 1436 | * usbvision_alloc() |
| 1437 | * |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1438 | * This code allocates the struct usb_usbvision. |
| 1439 | * It is filled with default values. |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1440 | * |
| 1441 | * Returns NULL on error, a pointer to usb_usbvision else. |
| 1442 | * |
| 1443 | */ |
Janne Grunau | a878440 | 2009-04-01 08:46:00 -0300 | [diff] [blame] | 1444 | static struct usb_usbvision *usbvision_alloc(struct usb_device *dev, |
| 1445 | struct usb_interface *intf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1446 | { |
| 1447 | struct usb_usbvision *usbvision; |
| 1448 | |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1449 | usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL); |
| 1450 | if (usbvision == NULL) |
| 1451 | return NULL; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1452 | |
| 1453 | usbvision->dev = dev; |
Janne Grunau | a878440 | 2009-04-01 08:46:00 -0300 | [diff] [blame] | 1454 | if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev)) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1455 | goto err_free; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1456 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1457 | mutex_init(&usbvision->lock); /* available */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1458 | |
| 1459 | // prepare control urb for control messages during interrupts |
| 1460 | usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1461 | if (usbvision->ctrlUrb == NULL) |
| 1462 | goto err_unreg; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1463 | init_waitqueue_head(&usbvision->ctrlUrb_wq); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1464 | |
| 1465 | usbvision_init_powerOffTimer(usbvision); |
| 1466 | |
| 1467 | return usbvision; |
| 1468 | |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1469 | err_unreg: |
| 1470 | v4l2_device_unregister(&usbvision->v4l2_dev); |
| 1471 | err_free: |
| 1472 | kfree(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1473 | return NULL; |
| 1474 | } |
| 1475 | |
| 1476 | /* |
| 1477 | * usbvision_release() |
| 1478 | * |
| 1479 | * This code does final release of struct usb_usbvision. This happens |
| 1480 | * after the device is disconnected -and- all clients closed their files. |
| 1481 | * |
| 1482 | */ |
| 1483 | static void usbvision_release(struct usb_usbvision *usbvision) |
| 1484 | { |
| 1485 | PDEBUG(DBG_PROBE, ""); |
| 1486 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1487 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1488 | |
| 1489 | usbvision_reset_powerOffTimer(usbvision); |
| 1490 | |
| 1491 | usbvision->initialized = 0; |
| 1492 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1493 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1494 | |
| 1495 | usbvision_remove_sysfs(usbvision->vdev); |
| 1496 | usbvision_unregister_video(usbvision); |
| 1497 | |
| 1498 | if (usbvision->ctrlUrb) { |
| 1499 | usb_free_urb(usbvision->ctrlUrb); |
| 1500 | } |
| 1501 | |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1502 | v4l2_device_unregister(&usbvision->v4l2_dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1503 | kfree(usbvision); |
| 1504 | |
| 1505 | PDEBUG(DBG_PROBE, "success"); |
| 1506 | } |
| 1507 | |
| 1508 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1509 | /*********************** usb interface **********************************/ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1510 | |
| 1511 | static void usbvision_configure_video(struct usb_usbvision *usbvision) |
| 1512 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1513 | int model; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1514 | |
| 1515 | if (usbvision == NULL) |
| 1516 | return; |
| 1517 | |
| 1518 | model = usbvision->DevModel; |
| 1519 | usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24; |
| 1520 | |
Trent Piepho | c682b3a | 2007-04-14 15:16:26 -0300 | [diff] [blame] | 1521 | if (usbvision_device_data[usbvision->DevModel].Vin_Reg2_override) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1522 | usbvision->Vin_Reg2_Preset = |
| 1523 | usbvision_device_data[usbvision->DevModel].Vin_Reg2; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1524 | } else { |
| 1525 | usbvision->Vin_Reg2_Preset = 0; |
| 1526 | } |
| 1527 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1528 | usbvision->tvnormId = usbvision_device_data[model].VideoNorm; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1529 | |
| 1530 | usbvision->video_inputs = usbvision_device_data[model].VideoChannels; |
| 1531 | usbvision->ctl_input = 0; |
| 1532 | |
| 1533 | /* This should be here to make i2c clients to be able to register */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1534 | /* first switch off audio */ |
| 1535 | usbvision_audio_off(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1536 | if (!PowerOnAtOpen) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1537 | /* and then power up the noisy tuner */ |
| 1538 | usbvision_power_on(usbvision); |
Thierry MERLE | 1ff16c2 | 2007-04-14 16:23:49 -0300 | [diff] [blame] | 1539 | usbvision_i2c_register(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | /* |
| 1544 | * usbvision_probe() |
| 1545 | * |
| 1546 | * This procedure queries device descriptor and accepts the interface |
| 1547 | * if it looks like USBVISION video device |
| 1548 | * |
| 1549 | */ |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1550 | static int __devinit usbvision_probe(struct usb_interface *intf, |
| 1551 | const struct usb_device_id *devid) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1552 | { |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1553 | struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf)); |
| 1554 | struct usb_interface *uif; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1555 | __u8 ifnum = intf->altsetting->desc.bInterfaceNumber; |
| 1556 | const struct usb_host_interface *interface; |
| 1557 | struct usb_usbvision *usbvision = NULL; |
| 1558 | const struct usb_endpoint_descriptor *endpoint; |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1559 | int model,i; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1560 | |
| 1561 | PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u", |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1562 | dev->descriptor.idVendor, |
| 1563 | dev->descriptor.idProduct, ifnum); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1564 | |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1565 | model = devid->driver_info; |
Mauro Carvalho Chehab | f8a389d | 2007-04-14 15:17:35 -0300 | [diff] [blame] | 1566 | if ( (model<0) || (model>=usbvision_device_data_size) ) { |
Thierry MERLE | 672d013 | 2007-04-14 17:53:55 -0300 | [diff] [blame] | 1567 | PDEBUG(DBG_PROBE, "model out of bounds %d",model); |
Mauro Carvalho Chehab | f8a389d | 2007-04-14 15:17:35 -0300 | [diff] [blame] | 1568 | return -ENODEV; |
| 1569 | } |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1570 | printk(KERN_INFO "%s: %s found\n", __func__, |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1571 | usbvision_device_data[model].ModelString); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1572 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1573 | if (usbvision_device_data[model].Interface >= 0) { |
| 1574 | interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0]; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1575 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1576 | interface = &dev->actconfig->interface[ifnum]->altsetting[0]; |
| 1577 | } |
| 1578 | endpoint = &interface->endpoint[1].desc; |
Julia Lawall | 2230c3c | 2009-01-03 16:53:10 -0300 | [diff] [blame] | 1579 | if (!usb_endpoint_xfer_isoc(endpoint)) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1580 | dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1581 | __func__, ifnum); |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1582 | dev_err(&intf->dev, "%s: Endpoint attributes %d", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1583 | __func__, endpoint->bmAttributes); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1584 | return -ENODEV; |
| 1585 | } |
Julia Lawall | 1341798 | 2008-12-29 21:49:22 -0300 | [diff] [blame] | 1586 | if (usb_endpoint_dir_out(endpoint)) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1587 | dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1588 | __func__, ifnum); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1589 | return -ENODEV; |
| 1590 | } |
| 1591 | |
Janne Grunau | a878440 | 2009-04-01 08:46:00 -0300 | [diff] [blame] | 1592 | usbvision = usbvision_alloc(dev, intf); |
| 1593 | if (usbvision == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1594 | dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1595 | return -ENOMEM; |
| 1596 | } |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1597 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1598 | if (dev->descriptor.bNumConfigurations > 1) { |
| 1599 | usbvision->bridgeType = BRIDGE_NT1004; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1600 | } else if (model == DAZZLE_DVC_90_REV_1_SECAM) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1601 | usbvision->bridgeType = BRIDGE_NT1005; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1602 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1603 | usbvision->bridgeType = BRIDGE_NT1003; |
| 1604 | } |
| 1605 | PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType); |
| 1606 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1607 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1608 | |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1609 | /* compute alternate max packet sizes */ |
| 1610 | uif = dev->actconfig->interface[0]; |
| 1611 | |
| 1612 | usbvision->num_alt=uif->num_altsetting; |
| 1613 | PDEBUG(DBG_PROBE, "Alternate settings: %i",usbvision->num_alt); |
| 1614 | usbvision->alt_max_pkt_size = kmalloc(32* |
| 1615 | usbvision->num_alt,GFP_KERNEL); |
| 1616 | if (usbvision->alt_max_pkt_size == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1617 | dev_err(&intf->dev, "usbvision: out of memory!\n"); |
Daniel Walker | 0991112 | 2007-12-12 18:22:48 -0300 | [diff] [blame] | 1618 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1619 | return -ENOMEM; |
| 1620 | } |
| 1621 | |
| 1622 | for (i = 0; i < usbvision->num_alt ; i++) { |
| 1623 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc. |
| 1624 | wMaxPacketSize); |
| 1625 | usbvision->alt_max_pkt_size[i] = |
| 1626 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1627 | PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i",i, |
| 1628 | usbvision->alt_max_pkt_size[i]); |
| 1629 | } |
| 1630 | |
| 1631 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1632 | usbvision->nr = usbvision_nr++; |
| 1633 | |
| 1634 | usbvision->have_tuner = usbvision_device_data[model].Tuner; |
| 1635 | if (usbvision->have_tuner) { |
| 1636 | usbvision->tuner_type = usbvision_device_data[model].TunerType; |
| 1637 | } |
| 1638 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1639 | usbvision->DevModel = model; |
| 1640 | usbvision->remove_pending = 0; |
| 1641 | usbvision->iface = ifnum; |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1642 | usbvision->ifaceAlt = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1643 | usbvision->video_endp = endpoint->bEndpointAddress; |
| 1644 | usbvision->isocPacketSize = 0; |
| 1645 | usbvision->usb_bandwidth = 0; |
| 1646 | usbvision->user = 0; |
| 1647 | usbvision->streaming = Stream_Off; |
| 1648 | usbvision_register_video(usbvision); |
| 1649 | usbvision_configure_video(usbvision); |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1650 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1651 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1652 | usbvision_create_sysfs(usbvision->vdev); |
| 1653 | |
| 1654 | PDEBUG(DBG_PROBE, "success"); |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | /* |
| 1660 | * usbvision_disconnect() |
| 1661 | * |
| 1662 | * This procedure stops all driver activity, deallocates interface-private |
| 1663 | * structure (pointed by 'ptr') and after that driver should be removable |
| 1664 | * with no ill consequences. |
| 1665 | * |
| 1666 | */ |
| 1667 | static void __devexit usbvision_disconnect(struct usb_interface *intf) |
| 1668 | { |
Hans Verkuil | aeb506a | 2010-05-02 09:00:13 -0300 | [diff] [blame^] | 1669 | struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1670 | |
| 1671 | PDEBUG(DBG_PROBE, ""); |
| 1672 | |
| 1673 | if (usbvision == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1674 | dev_err(&usbvision->dev->dev, |
| 1675 | "%s: usb_get_intfdata() failed\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1676 | return; |
| 1677 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1678 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1679 | mutex_lock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1680 | |
| 1681 | // At this time we ask to cancel outstanding URBs |
| 1682 | usbvision_stop_isoc(usbvision); |
| 1683 | |
Hans Verkuil | f1ba28c | 2009-03-14 12:27:01 -0300 | [diff] [blame] | 1684 | v4l2_device_disconnect(&usbvision->v4l2_dev); |
| 1685 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1686 | if (usbvision->power) { |
Thierry MERLE | 1ff16c2 | 2007-04-14 16:23:49 -0300 | [diff] [blame] | 1687 | usbvision_i2c_unregister(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1688 | usbvision_power_off(usbvision); |
| 1689 | } |
| 1690 | usbvision->remove_pending = 1; // Now all ISO data will be ignored |
| 1691 | |
| 1692 | usb_put_dev(usbvision->dev); |
| 1693 | usbvision->dev = NULL; // USB device is no more |
| 1694 | |
Matthias Kaehlcke | 289d4d2 | 2007-10-24 17:31:15 -0300 | [diff] [blame] | 1695 | mutex_unlock(&usbvision->lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1696 | |
| 1697 | if (usbvision->user) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1698 | printk(KERN_INFO "%s: In use, disconnect pending\n", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1699 | __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1700 | wake_up_interruptible(&usbvision->wait_frame); |
| 1701 | wake_up_interruptible(&usbvision->wait_stream); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1702 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1703 | usbvision_release(usbvision); |
| 1704 | } |
| 1705 | |
| 1706 | PDEBUG(DBG_PROBE, "success"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | static struct usb_driver usbvision_driver = { |
| 1710 | .name = "usbvision", |
| 1711 | .id_table = usbvision_table, |
| 1712 | .probe = usbvision_probe, |
Jean Delvare | e36bc31 | 2009-06-04 11:07:16 -0300 | [diff] [blame] | 1713 | .disconnect = __devexit_p(usbvision_disconnect), |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1714 | }; |
| 1715 | |
| 1716 | /* |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1717 | * usbvision_init() |
| 1718 | * |
| 1719 | * This code is run to initialize the driver. |
| 1720 | * |
| 1721 | */ |
| 1722 | static int __init usbvision_init(void) |
| 1723 | { |
| 1724 | int errCode; |
| 1725 | |
| 1726 | PDEBUG(DBG_PROBE, ""); |
| 1727 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1728 | PDEBUG(DBG_IO, "IO debugging is enabled [video]"); |
| 1729 | PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]"); |
Thierry MERLE | c876a34 | 2006-12-09 16:42:54 -0300 | [diff] [blame] | 1730 | PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1731 | |
| 1732 | /* disable planar mode support unless compression enabled */ |
| 1733 | if (isocMode != ISOC_MODE_COMPRESS ) { |
| 1734 | // FIXME : not the right way to set supported flag |
| 1735 | usbvision_v4l2_format[6].supported = 0; // V4L2_PIX_FMT_YVU420 |
| 1736 | usbvision_v4l2_format[7].supported = 0; // V4L2_PIX_FMT_YUV422P |
| 1737 | } |
| 1738 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1739 | errCode = usb_register(&usbvision_driver); |
| 1740 | |
| 1741 | if (errCode == 0) { |
Dwaine Garden | de6a1b8 | 2007-01-07 21:13:55 -0300 | [diff] [blame] | 1742 | printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1743 | PDEBUG(DBG_PROBE, "success"); |
| 1744 | } |
| 1745 | return errCode; |
| 1746 | } |
| 1747 | |
| 1748 | static void __exit usbvision_exit(void) |
| 1749 | { |
| 1750 | PDEBUG(DBG_PROBE, ""); |
| 1751 | |
| 1752 | usb_deregister(&usbvision_driver); |
| 1753 | PDEBUG(DBG_PROBE, "success"); |
| 1754 | } |
| 1755 | |
| 1756 | module_init(usbvision_init); |
| 1757 | module_exit(usbvision_exit); |
| 1758 | |
| 1759 | /* |
| 1760 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 1761 | * --------------------------------------------------------------------------- |
| 1762 | * Local variables: |
| 1763 | * c-basic-offset: 8 |
| 1764 | * End: |
| 1765 | */ |