r5u870

Ricoh R5U870 Linux Driver
git clone https://logand.com/git/r5u870.git/
Log | Files | Refs | README | LICENSE

usbcam_priv.h (6724B)


      1 /*
      2  * USBCAM abstraction library for USB webcam drivers
      3  *
      4  * Copyright (c) 2007 Sam Revitch <samr7 cs washington edu>
      5  *
      6  * This program is free software; you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation; either version 2, or (at your option)
      9  * any later version.
     10  *
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  * GNU General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program; if not, write to the Free Software
     18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     19  */
     20 
     21 /*
     22  * This header file is private and internal to usbcam.
     23  * DO NOT INCLUDE THIS HEADER FILE IN MINIDRIVERS.  USE usbcam.h INSTEAD.
     24  */
     25 
     26 #if !defined(__USBCAM_PRIV_H__)
     27 #define __USBCAM_PRIV_H__
     28 
     29 #include "usbcam.h"
     30 
     31 #include <linux/kernel.h>
     32 #include <linux/kthread.h>
     33 #include <linux/signal.h>
     34 #include <linux/sched.h>
     35 #include <linux/list.h>
     36 #include <linux/slab.h>
     37 #include <linux/module.h>
     38 #include <linux/smp_lock.h>
     39 #include <linux/vmalloc.h>
     40 #include <linux/mm.h>
     41 #include <linux/timer.h>
     42 #include <linux/init.h>
     43 #include <linux/spinlock.h>
     44 #include <linux/videodev.h>
     45 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
     46 #include <media/video-buf.h>
     47 #else
     48 #include <media/videobuf-dma-sg.h>
     49 #endif
     50 
     51 
     52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
     53 #define usb_endpoint_xfer_bulk(EPD) \
     54 	(((EPD)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == \
     55 	 USB_ENDPOINT_XFER_BULK)
     56 #define usb_endpoint_xfer_int(EPD) \
     57 	(((EPD)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == \
     58 	 USB_ENDPOINT_XFER_INT)
     59 #define usb_endpoint_xfer_isoc(EPD) \
     60 	(((EPD)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == \
     61 	 USB_ENDPOINT_XFER_ISOC)
     62 #define usb_endpoint_dir_in(EPD) \
     63 	(((EPD)->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
     64 #define usb_autopm_get_interface(X) 0
     65 #define usb_autopm_put_interface(X)
     66 #endif  /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) */
     67 
     68 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
     69 #if !defined(videobuf_queue_pci_init)
     70 #define videobuf_queue_pci_init videobuf_queue_sg_init
     71 #endif
     72 #endif
     73 
     74 /*
     75  * When creating a minidriver that is not part of the core kernel, it
     76  * may be desired to use a specific version of usbcam.  In this case,
     77  * usbcam's symbols should be available only to the minidriver with
     78  * which it is linked, and its symbols should not be exported.
     79  */
     80 #define USBCAM_EXPORT_SYMBOL(X) EXPORT_SYMBOL(X)
     81 
     82 #define assert usbcam_assert
     83 
     84 #define usbcam_drvname(MDP) ((MDP)->um_owner->name)
     85 
     86 #if defined(CONFIG_USB_USBCAM_DEBUG)
     87 #define usbcam_dbgm(MD, SUBSYS, FMT, ARG...) do {			\
     88 	if ((MD)->um_debug &&						\
     89 	    *(MD)->um_debug & (1UL << USBCAM_DBG_ ## SUBSYS))		\
     90 		printk(KERN_DEBUG "%s: " FMT "\n",			\
     91 		       (MD)->um_modname, ## ARG);			\
     92 } while (0)
     93 #else
     94 #define usbcam_dbgm(MD, SUBSYS, FMT, ARG...)
     95 #endif  /* defined(CONFIG_USB_USBCAM_DEBUG) */
     96 
     97 #define usbcam_minidrv_op_present(UDP, CB) 				\
     98 	((UDP)->ud_minidrv->um_ops->CB ? 1 : 0)
     99 #define usbcam_minidrv_op(UDP, CB, ARGS...)				\
    100 	((UDP)->ud_minidrv->um_ops->CB((UDP), ## ARGS))
    101 
    102 
    103 /*
    104  * Private data structure definitions
    105  */
    106 
    107 /*
    108  * This structure represents a registered minidriver
    109  */
    110 struct usbcam_minidrv {
    111 	struct kref			um_kref;
    112 	struct module			*um_owner;
    113 	const char			*um_modname;
    114 	int				*um_debug;
    115 	int				um_version;
    116 	int				um_dev_count;
    117 	struct list_head		um_dev_list;
    118 	int				um_dev_privsize;
    119 	struct usb_driver		um_usbdrv;
    120 	struct mutex			um_lock;
    121 	const struct usbcam_dev_ops	*um_ops;
    122 	struct video_device		um_videodev_template;
    123 	struct file_operations		um_v4l_fops;
    124 	const int			*um_video_nr_array;
    125 	int				um_video_nr_array_len;
    126 };
    127 
    128 /*
    129  * The frame structure is generally managed by the video-buf module
    130  * and represents some chunk of memory that the video4linux client
    131  * requested as a frame buffer.  It might be vmalloc()'d, or it might
    132  * be mapped from a user address space.  In either case, usbcam
    133  * guarantees a contiguous kernel mapping accessible to the minidriver.
    134  *
    135  * The primary reason to use video-buf in usbcam is for its
    136  * implementation of buffer mapping methods and "zero-copy" kernel-user
    137  * data movement.  The V4L2 API is quite rich, and it's much easier to
    138  * use video-buf than to create a private full-featured implementation,
    139  * and much more desirable to use video-buf than to limp along with a
    140  * substandard implementation.  The video-buf module isn't specifically
    141  * used for DMA functionality, as most USB devices, with the possible
    142  * exception of those employing bulk transfers, are unsuitable for
    143  * direct frame buffer DMA.
    144  *
    145  * Minidrivers can access details of the current frame using
    146  * usbcam_curframe_get(), and can signal completion of the current
    147  * frame with usbcam_curframe_complete().  It is up to the minidriver
    148  * to fill in the frame buffer.
    149  */
    150 struct usbcam_frame {
    151 	struct videobuf_buffer	vbb;
    152 	struct list_head	cap_links;
    153 	void			*vmap_base;
    154 	void			*vmap_sof;
    155 };
    156 
    157 /*
    158  * This structure represents an open file handle and the frame
    159  * buffers associated with that client
    160  */
    161 struct usbcam_fh {
    162 	struct usbcam_dev		*ufh_dev;
    163 	int				ufh_flags;
    164 	struct videobuf_queue		ufh_vbq;
    165 };
    166 
    167 #define USBCAM_FH_USE_FIXED_FB		0x00000001
    168 
    169 extern void usbcam_work_stop(struct usbcam_dev *udp);
    170 extern void usbcam_capture_stop(struct usbcam_dev *udp);
    171 extern void usbcam_ctrl_releaseall(struct usbcam_dev *udp);
    172 
    173 /*
    174  * The below maybe_stop function allows usbcam to ensure that any kernel
    175  * threads it creates are completely stopped and not executing any
    176  * usbcam code at module unload time.
    177  *
    178  * This is ugly but it remains unclear how better to do it.
    179  */
    180 static inline void usbcam_work_maybe_stop(struct usbcam_dev *udp)
    181 {
    182 	if (!udp->ud_work_refs)
    183 		usbcam_work_stop(udp);
    184 }
    185 
    186 /*
    187  * Only stop capturing if no frames are queued.
    188  *
    189  * We allow and encourage the minidriver to continue capturing in the
    190  * last requested format, and have it stop autonomously when it receives
    191  * its first data for the next frame but finds no frame available.  This
    192  * expedites the process for situations such as S_FMT which cannot
    193  * tolerate capture being in progress.
    194  */
    195 static inline void usbcam_capture_stop_nondestructive(struct usbcam_dev *udp)
    196 {
    197 	if (udp->ud_capturing && list_empty(&udp->ud_frame_cap_queue))
    198 		usbcam_capture_stop(udp);
    199 }
    200 
    201 extern struct videobuf_queue_ops usbcam_videobuf_qops;
    202 extern struct file_operations usbcam_v4l_fops_template;
    203 extern struct video_device usbcam_videodev_template;
    204 
    205 #endif  /* !defined(__USBCAM_PRIV_H__) */