Path: blob/master/drivers/media/video/et61x251/et61x251.h
17780 views
/***************************************************************************1* V4L2 driver for ET61X[12]51 PC Camera Controllers *2* *3* Copyright (C) 2006 by Luca Risolia <[email protected]> *4* *5* This program is free software; you can redistribute it and/or modify *6* it under the terms of the GNU General Public License as published by *7* the Free Software Foundation; either version 2 of the License, or *8* (at your option) any later version. *9* *10* This program is distributed in the hope that it will be useful, *11* but WITHOUT ANY WARRANTY; without even the implied warranty of *12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *13* GNU General Public License for more details. *14* *15* You should have received a copy of the GNU General Public License *16* along with this program; if not, write to the Free Software *17* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *18***************************************************************************/1920#ifndef _ET61X251_H_21#define _ET61X251_H_2223#include <linux/version.h>24#include <linux/usb.h>25#include <linux/videodev2.h>26#include <media/v4l2-common.h>27#include <linux/device.h>28#include <linux/list.h>29#include <linux/spinlock.h>30#include <linux/time.h>31#include <linux/wait.h>32#include <linux/types.h>33#include <linux/param.h>34#include <linux/rwsem.h>35#include <linux/mutex.h>36#include <linux/stddef.h>37#include <linux/string.h>38#include <linux/kref.h>3940#include "et61x251_sensor.h"4142/*****************************************************************************/4344#define ET61X251_DEBUG45#define ET61X251_DEBUG_LEVEL 246#define ET61X251_MAX_DEVICES 6447#define ET61X251_PRESERVE_IMGSCALE 048#define ET61X251_FORCE_MUNMAP 049#define ET61X251_MAX_FRAMES 3250#define ET61X251_COMPRESSION_QUALITY 051#define ET61X251_URBS 252#define ET61X251_ISO_PACKETS 753#define ET61X251_ALTERNATE_SETTING 1354#define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS)55#define ET61X251_CTRL_TIMEOUT 10056#define ET61X251_FRAME_TIMEOUT 25758/*****************************************************************************/5960static const struct usb_device_id et61x251_id_table[] = {61{ USB_DEVICE(0x102c, 0x6251), },62{ }63};6465ET61X251_SENSOR_TABLE6667/*****************************************************************************/6869enum et61x251_frame_state {70F_UNUSED,71F_QUEUED,72F_GRABBING,73F_DONE,74F_ERROR,75};7677struct et61x251_frame_t {78void* bufmem;79struct v4l2_buffer buf;80enum et61x251_frame_state state;81struct list_head frame;82unsigned long vma_use_count;83};8485enum et61x251_dev_state {86DEV_INITIALIZED = 0x01,87DEV_DISCONNECTED = 0x02,88DEV_MISCONFIGURED = 0x04,89};9091enum et61x251_io_method {92IO_NONE,93IO_READ,94IO_MMAP,95};9697enum et61x251_stream_state {98STREAM_OFF,99STREAM_INTERRUPT,100STREAM_ON,101};102103struct et61x251_sysfs_attr {104u8 reg, i2c_reg;105};106107struct et61x251_module_param {108u8 force_munmap;109u16 frame_timeout;110};111112static DEFINE_MUTEX(et61x251_sysfs_lock);113static DECLARE_RWSEM(et61x251_dev_lock);114115struct et61x251_device {116struct video_device* v4ldev;117118struct et61x251_sensor sensor;119120struct usb_device* usbdev;121struct urb* urb[ET61X251_URBS];122void* transfer_buffer[ET61X251_URBS];123u8* control_buffer;124125struct et61x251_frame_t *frame_current, frame[ET61X251_MAX_FRAMES];126struct list_head inqueue, outqueue;127u32 frame_count, nbuffers, nreadbuffers;128129enum et61x251_io_method io;130enum et61x251_stream_state stream;131132struct v4l2_jpegcompression compression;133134struct et61x251_sysfs_attr sysfs;135struct et61x251_module_param module_param;136137struct kref kref;138enum et61x251_dev_state state;139u8 users;140141struct completion probe;142struct mutex open_mutex, fileop_mutex;143spinlock_t queue_lock;144wait_queue_head_t wait_open, wait_frame, wait_stream;145};146147/*****************************************************************************/148149struct et61x251_device*150et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id)151{152return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;153}154155156void157et61x251_attach_sensor(struct et61x251_device* cam,158const struct et61x251_sensor* sensor)159{160memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor));161}162163/*****************************************************************************/164165#undef DBG166#undef KDBG167#ifdef ET61X251_DEBUG168# define DBG(level, fmt, args...) \169do { \170if (debug >= (level)) { \171if ((level) == 1) \172dev_err(&cam->usbdev->dev, fmt "\n", ## args); \173else if ((level) == 2) \174dev_info(&cam->usbdev->dev, fmt "\n", ## args); \175else if ((level) >= 3) \176dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \177__FILE__, __func__, __LINE__ , ## args); \178} \179} while (0)180# define KDBG(level, fmt, args...) \181do { \182if (debug >= (level)) { \183if ((level) == 1 || (level) == 2) \184pr_info("et61x251: " fmt "\n", ## args); \185else if ((level) == 3) \186pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \187__func__, __LINE__ , ## args); \188} \189} while (0)190# define V4LDBG(level, name, cmd) \191do { \192if (debug >= (level)) \193v4l_print_ioctl(name, cmd); \194} while (0)195#else196# define DBG(level, fmt, args...) do {;} while(0)197# define KDBG(level, fmt, args...) do {;} while(0)198# define V4LDBG(level, name, cmd) do {;} while(0)199#endif200201#undef PDBG202#define PDBG(fmt, args...) \203dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \204__LINE__ , ## args)205206#undef PDBGG207#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */208209#endif /* _ET61X251_H_ */210211212