blob: ae2b1e6bdf47bf1cf0427ad39e6ff67b363c0094 [file] [log] [blame]
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001/*
2 *
3 * V 4 L 2 D R I V E R H E L P E R A P I
4 *
5 * Moved from videodev2.h
6 *
7 * Some commonly needed functions for drivers (v4l2-common.o module)
8 */
9#ifndef _V4L2_DEV_H
10#define _V4L2_DEV_H
11
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -030012#define OBSOLETE_DEVDATA 1 /* to be removed soon */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030013
14#include <linux/poll.h>
15#include <linux/fs.h>
16#include <linux/device.h>
17#include <linux/mutex.h>
18#include <linux/compiler.h> /* need __user */
Mauro Carvalho Chehab487206f2006-08-08 09:10:01 -030019#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030020#include <linux/videodev.h>
21#else
22#include <linux/videodev2.h>
23#endif
24
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030025#define VIDEO_MAJOR 81
26/* Minor device allocation */
27#define MINOR_VFL_TYPE_GRABBER_MIN 0
28#define MINOR_VFL_TYPE_GRABBER_MAX 63
29#define MINOR_VFL_TYPE_RADIO_MIN 64
30#define MINOR_VFL_TYPE_RADIO_MAX 127
31#define MINOR_VFL_TYPE_VTX_MIN 192
32#define MINOR_VFL_TYPE_VTX_MAX 223
33#define MINOR_VFL_TYPE_VBI_MIN 224
34#define MINOR_VFL_TYPE_VBI_MAX 255
35
36#define VFL_TYPE_GRABBER 0
37#define VFL_TYPE_VBI 1
38#define VFL_TYPE_RADIO 2
39#define VFL_TYPE_VTX 3
40
Hans Verkuila3998102008-07-21 02:57:38 -030041struct v4l2_ioctl_callbacks;
42
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030043/*
44 * Newer version of video_device, handled by videodev2.c
45 * This version moves redundant code from video device code to
46 * the common handler
47 */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030048
49struct video_device
50{
51 /* device ops */
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -030052 const struct file_operations *fops;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030053
Kay Sievers54bd5b62007-10-08 16:26:13 -030054 /* sysfs */
Hans Verkuil22a04f12008-07-20 06:35:02 -030055 struct device dev; /* v4l device */
Hans Verkuil5e85e732008-07-20 06:31:39 -030056 struct device *parent; /* device parent */
Kay Sievers54bd5b62007-10-08 16:26:13 -030057
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030058 /* device info */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030059 char name[32];
Hans Verkuil22a04f12008-07-20 06:35:02 -030060 int type; /* v4l1 */
61 int type2; /* v4l2 */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030062 int minor;
brandon@ifup.org539a7552008-06-20 22:58:53 -030063 /* attribute to diferentiate multiple indexs on one physical device */
64 int index;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030065
Hans Verkuil22a04f12008-07-20 06:35:02 -030066 int debug; /* Activates debug level*/
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030067
68 /* Video standard vars */
Mauro Carvalho Chehabe75f9ce2006-11-20 13:19:20 -030069 v4l2_std_id tvnorms; /* Supported tv norms */
70 v4l2_std_id current_norm; /* Current tvnorm */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030071
72 /* callbacks */
73 void (*release)(struct video_device *vfd);
74
75 /* ioctl callbacks */
Hans Verkuila3998102008-07-21 02:57:38 -030076 const struct v4l2_ioctl_ops *ioctl_ops;
Trent Piephodbbff482007-01-22 23:31:53 -030077
Hans Verkuil9c39d7e2008-07-21 07:51:45 -030078#ifdef OBSOLETE_DEVDATA /* to be removed soon */
79 /* dev->driver_data will be used instead some day.
80 * Use the video_{get|set}_drvdata() helper functions,
81 * so the switch over will be transparent for you.
82 * Or use {pci|usb}_{get|set}_drvdata() directly. */
83 void *priv;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030084#endif
85
86 /* for videodev.c intenal usage -- please don't touch */
87 int users; /* video_exclusive_{open|close} ... */
88 struct mutex lock; /* ... helper function uses these */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030089};
90
Linus Torvaldse90ff922007-09-13 21:09:01 -030091/* Class-dev to video-device */
Hans Verkuil22a04f12008-07-20 06:35:02 -030092#define to_video_device(cd) container_of(cd, struct video_device, dev)
Linus Torvaldse90ff922007-09-13 21:09:01 -030093
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030094/* Version 2 functions */
95extern int video_register_device(struct video_device *vfd, int type, int nr);
brandon@ifup.org539a7552008-06-20 22:58:53 -030096int video_register_device_index(struct video_device *vfd, int type, int nr,
97 int index);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030098void video_unregister_device(struct video_device *);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030099
100/* helper functions to alloc / release struct video_device, the
101 later can be used for video_device->release() */
102struct video_device *video_device_alloc(void);
103void video_device_release(struct video_device *vfd);
104
Mauro Carvalho Chehab8a905162006-09-10 12:01:19 -0300105#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300106#include <linux/mm.h>
107
Andrew Morton8a6914a2006-08-14 22:43:19 -0700108static inline int __must_check
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300109video_device_create_file(struct video_device *vfd,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300110 struct device_attribute *attr)
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300111{
Hans Verkuil22a04f12008-07-20 06:35:02 -0300112 int ret = device_create_file(&vfd->dev, attr);
Michael Krufky3117bee2006-07-19 13:23:38 -0300113 if (ret < 0)
Hans Verkuil2bc93aa2008-07-17 16:45:00 -0300114 printk(KERN_WARNING "%s error: %d\n", __func__, ret);
Michael Krufky3117bee2006-07-19 13:23:38 -0300115 return ret;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300116}
117static inline void
118video_device_remove_file(struct video_device *vfd,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300119 struct device_attribute *attr)
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300120{
Hans Verkuil22a04f12008-07-20 06:35:02 -0300121 device_remove_file(&vfd->dev, attr);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300122}
123
Mauro Carvalho Chehab8a905162006-09-10 12:01:19 -0300124#endif /* CONFIG_VIDEO_V4L1_COMPAT */
125
Hans Verkuil9c39d7e2008-07-21 07:51:45 -0300126#ifdef OBSOLETE_DEVDATA /* to be removed soon */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300127/* helper functions to access driver private data. */
128static inline void *video_get_drvdata(struct video_device *dev)
129{
130 return dev->priv;
131}
132
133static inline void video_set_drvdata(struct video_device *dev, void *data)
134{
135 dev->priv = data;
136}
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300137
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300138/* Obsolete stuff - Still needed for radio devices and obsolete drivers */
139extern struct video_device* video_devdata(struct file*);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300140extern int video_exclusive_open(struct inode *inode, struct file *file);
141extern int video_exclusive_release(struct inode *inode, struct file *file);
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300142#endif
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300143
144#endif /* _V4L2_DEV_H */