blob: d9149cd25b31767fa5d73f23eee7006b1aa32848 [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_OWNER 1 /* to be removed soon */
13#define OBSOLETE_DEVDATA 1 /* to be removed soon */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030014
15#include <linux/poll.h>
16#include <linux/fs.h>
17#include <linux/device.h>
18#include <linux/mutex.h>
19#include <linux/compiler.h> /* need __user */
Mauro Carvalho Chehab487206f2006-08-08 09:10:01 -030020#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030021#include <linux/videodev.h>
22#else
23#include <linux/videodev2.h>
24#endif
25
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030026#define VIDEO_MAJOR 81
27/* Minor device allocation */
28#define MINOR_VFL_TYPE_GRABBER_MIN 0
29#define MINOR_VFL_TYPE_GRABBER_MAX 63
30#define MINOR_VFL_TYPE_RADIO_MIN 64
31#define MINOR_VFL_TYPE_RADIO_MAX 127
32#define MINOR_VFL_TYPE_VTX_MIN 192
33#define MINOR_VFL_TYPE_VTX_MAX 223
34#define MINOR_VFL_TYPE_VBI_MIN 224
35#define MINOR_VFL_TYPE_VBI_MAX 255
36
37#define VFL_TYPE_GRABBER 0
38#define VFL_TYPE_VBI 1
39#define VFL_TYPE_RADIO 2
40#define VFL_TYPE_VTX 3
41
Hans Verkuila3998102008-07-21 02:57:38 -030042struct v4l2_ioctl_callbacks;
43
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030044/*
45 * Newer version of video_device, handled by videodev2.c
46 * This version moves redundant code from video device code to
47 * the common handler
48 */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030049
50struct video_device
51{
52 /* device ops */
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -030053 const struct file_operations *fops;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030054
Kay Sievers54bd5b62007-10-08 16:26:13 -030055 /* sysfs */
Hans Verkuil22a04f12008-07-20 06:35:02 -030056 struct device dev; /* v4l device */
Hans Verkuil5e85e732008-07-20 06:31:39 -030057 struct device *parent; /* device parent */
Kay Sievers54bd5b62007-10-08 16:26:13 -030058
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030059 /* device info */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030060 char name[32];
Hans Verkuil22a04f12008-07-20 06:35:02 -030061 int type; /* v4l1 */
62 int type2; /* v4l2 */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030063 int minor;
brandon@ifup.org539a7552008-06-20 22:58:53 -030064 /* attribute to diferentiate multiple indexs on one physical device */
65 int index;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030066
Hans Verkuil22a04f12008-07-20 06:35:02 -030067 int debug; /* Activates debug level*/
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030068
69 /* Video standard vars */
Mauro Carvalho Chehabe75f9ce2006-11-20 13:19:20 -030070 v4l2_std_id tvnorms; /* Supported tv norms */
71 v4l2_std_id current_norm; /* Current tvnorm */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030072
73 /* callbacks */
74 void (*release)(struct video_device *vfd);
75
76 /* ioctl callbacks */
Hans Verkuila3998102008-07-21 02:57:38 -030077 const struct v4l2_ioctl_ops *ioctl_ops;
Trent Piephodbbff482007-01-22 23:31:53 -030078
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -030079#ifdef OBSOLETE_OWNER /* to be removed soon */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030080/* obsolete -- fops->owner is used instead */
81struct module *owner;
82/* dev->driver_data will be used instead some day.
83 * Use the video_{get|set}_drvdata() helper functions,
84 * so the switch over will be transparent for you.
85 * Or use {pci|usb}_{get|set}_drvdata() directly. */
86void *priv;
87#endif
88
89 /* for videodev.c intenal usage -- please don't touch */
90 int users; /* video_exclusive_{open|close} ... */
91 struct mutex lock; /* ... helper function uses these */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030092};
93
Linus Torvaldse90ff922007-09-13 21:09:01 -030094/* Class-dev to video-device */
Hans Verkuil22a04f12008-07-20 06:35:02 -030095#define to_video_device(cd) container_of(cd, struct video_device, dev)
Linus Torvaldse90ff922007-09-13 21:09:01 -030096
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030097/* Version 2 functions */
98extern int video_register_device(struct video_device *vfd, int type, int nr);
brandon@ifup.org539a7552008-06-20 22:58:53 -030099int video_register_device_index(struct video_device *vfd, int type, int nr,
100 int index);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300101void video_unregister_device(struct video_device *);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300102
103/* helper functions to alloc / release struct video_device, the
104 later can be used for video_device->release() */
105struct video_device *video_device_alloc(void);
106void video_device_release(struct video_device *vfd);
107
Mauro Carvalho Chehab8a905162006-09-10 12:01:19 -0300108#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300109#include <linux/mm.h>
110
Andrew Morton8a6914a2006-08-14 22:43:19 -0700111static inline int __must_check
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300112video_device_create_file(struct video_device *vfd,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300113 struct device_attribute *attr)
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300114{
Hans Verkuil22a04f12008-07-20 06:35:02 -0300115 int ret = device_create_file(&vfd->dev, attr);
Michael Krufky3117bee2006-07-19 13:23:38 -0300116 if (ret < 0)
Hans Verkuil2bc93aa2008-07-17 16:45:00 -0300117 printk(KERN_WARNING "%s error: %d\n", __func__, ret);
Michael Krufky3117bee2006-07-19 13:23:38 -0300118 return ret;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300119}
120static inline void
121video_device_remove_file(struct video_device *vfd,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300122 struct device_attribute *attr)
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300123{
Hans Verkuil22a04f12008-07-20 06:35:02 -0300124 device_remove_file(&vfd->dev, attr);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300125}
126
Mauro Carvalho Chehab8a905162006-09-10 12:01:19 -0300127#endif /* CONFIG_VIDEO_V4L1_COMPAT */
128
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -0300129#ifdef OBSOLETE_OWNER /* to be removed soon */
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300130/* helper functions to access driver private data. */
131static inline void *video_get_drvdata(struct video_device *dev)
132{
133 return dev->priv;
134}
135
136static inline void video_set_drvdata(struct video_device *dev, void *data)
137{
138 dev->priv = data;
139}
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300140
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300141#endif
142
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300143#ifdef OBSOLETE_DEVDATA /* to be removed soon */
144/* Obsolete stuff - Still needed for radio devices and obsolete drivers */
145extern struct video_device* video_devdata(struct file*);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300146extern int video_exclusive_open(struct inode *inode, struct file *file);
147extern int video_exclusive_release(struct inode *inode, struct file *file);
Mauro Carvalho Chehab38ee04f2006-08-08 09:10:01 -0300148#endif
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300149
150#endif /* _V4L2_DEV_H */