blob: 1d4df571060bb4f94b7f5bb4280055e9163aa1e5 [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 Chehab401998f2006-06-04 10:06:18 -030019#include <linux/videodev2.h>
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030020
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030021#define VIDEO_MAJOR 81
22/* Minor device allocation */
23#define MINOR_VFL_TYPE_GRABBER_MIN 0
24#define MINOR_VFL_TYPE_GRABBER_MAX 63
25#define MINOR_VFL_TYPE_RADIO_MIN 64
26#define MINOR_VFL_TYPE_RADIO_MAX 127
27#define MINOR_VFL_TYPE_VTX_MIN 192
28#define MINOR_VFL_TYPE_VTX_MAX 223
29#define MINOR_VFL_TYPE_VBI_MIN 224
30#define MINOR_VFL_TYPE_VBI_MAX 255
31
32#define VFL_TYPE_GRABBER 0
33#define VFL_TYPE_VBI 1
34#define VFL_TYPE_RADIO 2
35#define VFL_TYPE_VTX 3
36
Hans Verkuila3998102008-07-21 02:57:38 -030037struct v4l2_ioctl_callbacks;
38
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030039/*
40 * Newer version of video_device, handled by videodev2.c
41 * This version moves redundant code from video device code to
42 * the common handler
43 */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030044
45struct video_device
46{
47 /* device ops */
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -030048 const struct file_operations *fops;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030049
Kay Sievers54bd5b62007-10-08 16:26:13 -030050 /* sysfs */
Hans Verkuil22a04f12008-07-20 06:35:02 -030051 struct device dev; /* v4l device */
Hans Verkuil5e85e732008-07-20 06:31:39 -030052 struct device *parent; /* device parent */
Kay Sievers54bd5b62007-10-08 16:26:13 -030053
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030054 /* device info */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030055 char name[32];
Hans Verkuil0ea6bc82008-07-26 08:26:43 -030056 int vfl_type;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030057 int minor;
Hans Verkuilde1e5752008-07-26 08:37:58 -030058 /* attribute to differentiate multiple indices on one physical device */
brandon@ifup.org539a7552008-06-20 22:58:53 -030059 int index;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030060
Hans Verkuil22a04f12008-07-20 06:35:02 -030061 int debug; /* Activates debug level*/
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030062
63 /* Video standard vars */
Mauro Carvalho Chehabe75f9ce2006-11-20 13:19:20 -030064 v4l2_std_id tvnorms; /* Supported tv norms */
65 v4l2_std_id current_norm; /* Current tvnorm */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030066
67 /* callbacks */
68 void (*release)(struct video_device *vfd);
69
70 /* ioctl callbacks */
Hans Verkuila3998102008-07-21 02:57:38 -030071 const struct v4l2_ioctl_ops *ioctl_ops;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030072};
73
Linus Torvaldse90ff922007-09-13 21:09:01 -030074/* Class-dev to video-device */
Hans Verkuil22a04f12008-07-20 06:35:02 -030075#define to_video_device(cd) container_of(cd, struct video_device, dev)
Linus Torvaldse90ff922007-09-13 21:09:01 -030076
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030077/* Version 2 functions */
Hans Verkuile138c592008-08-23 06:38:11 -030078int __must_check video_register_device(struct video_device *vfd, int type, int nr);
79int __must_check video_register_device_index(struct video_device *vfd, int type, int nr,
brandon@ifup.org539a7552008-06-20 22:58:53 -030080 int index);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030081void video_unregister_device(struct video_device *);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030082
83/* helper functions to alloc / release struct video_device, the
84 later can be used for video_device->release() */
Hans Verkuile138c592008-08-23 06:38:11 -030085struct video_device * __must_check video_device_alloc(void);
Hans Verkuilf9e86b52008-08-23 05:47:41 -030086/* this release function frees the vfd pointer */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030087void video_device_release(struct video_device *vfd);
Hans Verkuilf9e86b52008-08-23 05:47:41 -030088/* this release function does nothing, use when the video_device is a
89 static global struct. Note that having a static video_device is
90 a dubious construction at best. */
91void video_device_release_empty(struct video_device *vfd);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030092
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030093/* helper functions to access driver private data. */
94static inline void *video_get_drvdata(struct video_device *dev)
95{
Hans Verkuil601e9442008-08-23 07:24:07 -030096 return dev_get_drvdata(&dev->dev);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030097}
98
99static inline void video_set_drvdata(struct video_device *dev, void *data)
100{
Hans Verkuil601e9442008-08-23 07:24:07 -0300101 dev_set_drvdata(&dev->dev, data);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300102}
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300103
Hans Verkuil601e9442008-08-23 07:24:07 -0300104#ifdef OBSOLETE_DEVDATA /* to be removed soon */
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300105/* Obsolete stuff - Still needed for radio devices and obsolete drivers */
106extern struct video_device* video_devdata(struct file*);
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300107#endif
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300108
109#endif /* _V4L2_DEV_H */