21
21
#ifndef _V4L2_SUBDEV_H
22
22
#define _V4L2_SUBDEV_H
24
#include <linux/v4l2-subdev.h>
25
#include <media/media-entity.h>
24
26
#include <media/v4l2-common.h>
27
#include <media/v4l2-dev.h>
28
#include <media/v4l2-fh.h>
25
29
#include <media/v4l2-mediabus.h>
27
31
/* generic v4l2_device notify callback notification values */
160
167
int (*s_power)(struct v4l2_subdev *sd, int on);
161
168
int (*interrupt_service_routine)(struct v4l2_subdev *sd,
162
169
u32 status, bool *handled);
170
int (*subscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
171
struct v4l2_event_subscription *sub);
172
int (*unsubscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
173
struct v4l2_event_subscription *sub);
165
/* s_mode: switch the tuner to a specific tuner mode. Replacement of s_radio.
167
s_radio: v4l device was opened in Radio mode, to be replaced by s_mode.
176
/* s_radio: v4l device was opened in radio mode.
178
g_frequency: freq->type must be filled in. Normally done by video_ioctl2
179
or the bridge driver.
182
s_tuner: vt->type must be filled in. Normally done by video_ioctl2 or the
169
185
s_type_addr: sets tuner type and its I2C addr.
171
187
s_config: sets tda9887 specific stuff, like port1, port2 and qss
173
189
struct v4l2_subdev_tuner_ops {
174
int (*s_mode)(struct v4l2_subdev *sd, enum v4l2_tuner_type);
175
190
int (*s_radio)(struct v4l2_subdev *sd);
176
191
int (*s_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
177
192
int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
257
272
int (*s_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop);
258
273
int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
259
274
int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
275
int (*g_frame_interval)(struct v4l2_subdev *sd,
276
struct v4l2_subdev_frame_interval *interval);
277
int (*s_frame_interval)(struct v4l2_subdev *sd,
278
struct v4l2_subdev_frame_interval *interval);
260
279
int (*enum_framesizes)(struct v4l2_subdev *sd, struct v4l2_frmsizeenum *fsize);
261
280
int (*enum_frameintervals)(struct v4l2_subdev *sd, struct v4l2_frmivalenum *fival);
262
281
int (*enum_dv_presets) (struct v4l2_subdev *sd,
271
290
struct v4l2_dv_timings *timings);
272
291
int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index,
273
292
enum v4l2_mbus_pixelcode *code);
293
int (*enum_mbus_fsizes)(struct v4l2_subdev *sd,
294
struct v4l2_frmsizeenum *fsize);
274
295
int (*g_mbus_fmt)(struct v4l2_subdev *sd,
275
296
struct v4l2_mbus_framefmt *fmt);
276
297
int (*try_mbus_fmt)(struct v4l2_subdev *sd,
324
345
* This is needed for some sensors, which always corrupt
325
346
* several top lines of the output image, or which send their
326
347
* metadata in them.
348
* @g_skip_frames: number of frames to skip at stream start. This is needed for
349
* buggy sensors that generate faulty frames when they are
328
352
struct v4l2_subdev_sensor_ops {
329
353
int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
354
int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
401
426
struct v4l2_subdev_ir_parameters *params);
429
struct v4l2_subdev_pad_ops {
430
int (*enum_mbus_code)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
431
struct v4l2_subdev_mbus_code_enum *code);
432
int (*enum_frame_size)(struct v4l2_subdev *sd,
433
struct v4l2_subdev_fh *fh,
434
struct v4l2_subdev_frame_size_enum *fse);
435
int (*enum_frame_interval)(struct v4l2_subdev *sd,
436
struct v4l2_subdev_fh *fh,
437
struct v4l2_subdev_frame_interval_enum *fie);
438
int (*get_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
439
struct v4l2_subdev_format *format);
440
int (*set_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
441
struct v4l2_subdev_format *format);
442
int (*set_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
443
struct v4l2_subdev_crop *crop);
444
int (*get_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
445
struct v4l2_subdev_crop *crop);
404
448
struct v4l2_subdev_ops {
405
449
const struct v4l2_subdev_core_ops *core;
406
450
const struct v4l2_subdev_tuner_ops *tuner;
421
466
* unregistered: called when this subdev is unregistered. When called the
422
467
* v4l2_dev field is still set to the correct v4l2_device.
469
* open: called when the subdev device node is opened by an application.
471
* close: called when the subdev device node is closed.
424
473
struct v4l2_subdev_internal_ops {
425
474
int (*registered)(struct v4l2_subdev *sd);
426
475
void (*unregistered)(struct v4l2_subdev *sd);
476
int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
477
int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
429
480
#define V4L2_SUBDEV_NAME_SIZE 32
431
482
/* Set this flag if this subdev is a i2c device. */
432
#define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
483
#define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
433
484
/* Set this flag if this subdev is a spi device. */
434
#define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
485
#define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
486
/* Set this flag if this subdev needs a device node. */
487
#define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
488
/* Set this flag if this subdev generates events. */
489
#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
436
491
/* Each instance of a subdev driver should create this struct, either
437
492
stand-alone or embedded in a larger struct.
439
494
struct v4l2_subdev {
495
#if defined(CONFIG_MEDIA_CONTROLLER)
496
struct media_entity entity;
440
498
struct list_head list;
441
499
struct module *owner;
453
511
/* pointer to private data */
514
/* subdev device node */
515
struct video_device devnode;
516
/* number of events to be allocated on open */
517
unsigned int nevents;
520
#define media_entity_to_v4l2_subdev(ent) \
521
container_of(ent, struct v4l2_subdev, entity)
522
#define vdev_to_v4l2_subdev(vdev) \
523
container_of(vdev, struct v4l2_subdev, devnode)
526
* Used for storing subdev information per file handle
528
struct v4l2_subdev_fh {
530
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
531
struct v4l2_mbus_framefmt *try_fmt;
532
struct v4l2_rect *try_crop;
536
#define to_v4l2_subdev_fh(fh) \
537
container_of(fh, struct v4l2_subdev_fh, vfh)
539
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
540
static inline struct v4l2_mbus_framefmt *
541
v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
543
return &fh->try_fmt[pad];
546
static inline struct v4l2_rect *
547
v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
549
return &fh->try_crop[pad];
553
extern const struct v4l2_file_operations v4l2_subdev_fops;
458
555
static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
475
572
return sd->host_priv;
478
static inline void v4l2_subdev_init(struct v4l2_subdev *sd,
479
const struct v4l2_subdev_ops *ops)
481
INIT_LIST_HEAD(&sd->list);
482
/* ops->core MUST be set */
483
BUG_ON(!ops || !ops->core);
490
sd->host_priv = NULL;
575
void v4l2_subdev_init(struct v4l2_subdev *sd,
576
const struct v4l2_subdev_ops *ops);
493
578
/* Call an ops of a v4l2_subdev, doing the right checks against