aboutsummaryrefslogtreecommitdiffstats
path: root/include/media/v4l2-subdev.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/media/v4l2-subdev.h')
-rw-r--r--include/media/v4l2-subdev.h136
1 files changed, 115 insertions, 21 deletions
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index b0316a7cf08d..1562c4ff3a65 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -21,7 +21,11 @@
21#ifndef _V4L2_SUBDEV_H 21#ifndef _V4L2_SUBDEV_H
22#define _V4L2_SUBDEV_H 22#define _V4L2_SUBDEV_H
23 23
24#include <linux/v4l2-subdev.h>
25#include <media/media-entity.h>
24#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/v4l2-dev.h>
28#include <media/v4l2-fh.h>
25#include <media/v4l2-mediabus.h> 29#include <media/v4l2-mediabus.h>
26 30
27/* generic v4l2_device notify callback notification values */ 31/* generic v4l2_device notify callback notification values */
@@ -36,7 +40,10 @@
36 40
37struct v4l2_device; 41struct v4l2_device;
38struct v4l2_ctrl_handler; 42struct v4l2_ctrl_handler;
43struct v4l2_event_subscription;
44struct v4l2_fh;
39struct v4l2_subdev; 45struct v4l2_subdev;
46struct v4l2_subdev_fh;
40struct tuner_setup; 47struct tuner_setup;
41 48
42/* decode_vbi_line */ 49/* decode_vbi_line */
@@ -106,10 +113,7 @@ struct v4l2_subdev_io_pin_config {
106 u8 strength; /* Pin drive strength */ 113 u8 strength; /* Pin drive strength */
107}; 114};
108 115
109/* s_config: if set, then it is always called by the v4l2_i2c_new_subdev* 116/*
110 functions after the v4l2_subdev was registered. It is used to pass
111 platform data to the subdev which can be used during initialization.
112
113 s_io_pin_config: configure one or more chip I/O pins for chips that 117 s_io_pin_config: configure one or more chip I/O pins for chips that
114 multiplex different internal signal pads out to IO pins. This function 118 multiplex different internal signal pads out to IO pins. This function
115 takes a pointer to an array of 'n' pin configuration entries, one for 119 takes a pointer to an array of 'n' pin configuration entries, one for
@@ -141,7 +145,6 @@ struct v4l2_subdev_io_pin_config {
141struct v4l2_subdev_core_ops { 145struct v4l2_subdev_core_ops {
142 int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip); 146 int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
143 int (*log_status)(struct v4l2_subdev *sd); 147 int (*log_status)(struct v4l2_subdev *sd);
144 int (*s_config)(struct v4l2_subdev *sd, int irq, void *platform_data);
145 int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n, 148 int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
146 struct v4l2_subdev_io_pin_config *pincfg); 149 struct v4l2_subdev_io_pin_config *pincfg);
147 int (*init)(struct v4l2_subdev *sd, u32 val); 150 int (*init)(struct v4l2_subdev *sd, u32 val);
@@ -164,6 +167,10 @@ struct v4l2_subdev_core_ops {
164 int (*s_power)(struct v4l2_subdev *sd, int on); 167 int (*s_power)(struct v4l2_subdev *sd, int on);
165 int (*interrupt_service_routine)(struct v4l2_subdev *sd, 168 int (*interrupt_service_routine)(struct v4l2_subdev *sd,
166 u32 status, bool *handled); 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);
167}; 174};
168 175
169/* s_mode: switch the tuner to a specific tuner mode. Replacement of s_radio. 176/* s_mode: switch the tuner to a specific tuner mode. Replacement of s_radio.
@@ -261,6 +268,10 @@ struct v4l2_subdev_video_ops {
261 int (*s_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop); 268 int (*s_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop);
262 int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param); 269 int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
263 int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param); 270 int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
271 int (*g_frame_interval)(struct v4l2_subdev *sd,
272 struct v4l2_subdev_frame_interval *interval);
273 int (*s_frame_interval)(struct v4l2_subdev *sd,
274 struct v4l2_subdev_frame_interval *interval);
264 int (*enum_framesizes)(struct v4l2_subdev *sd, struct v4l2_frmsizeenum *fsize); 275 int (*enum_framesizes)(struct v4l2_subdev *sd, struct v4l2_frmsizeenum *fsize);
265 int (*enum_frameintervals)(struct v4l2_subdev *sd, struct v4l2_frmivalenum *fival); 276 int (*enum_frameintervals)(struct v4l2_subdev *sd, struct v4l2_frmivalenum *fival);
266 int (*enum_dv_presets) (struct v4l2_subdev *sd, 277 int (*enum_dv_presets) (struct v4l2_subdev *sd,
@@ -275,6 +286,8 @@ struct v4l2_subdev_video_ops {
275 struct v4l2_dv_timings *timings); 286 struct v4l2_dv_timings *timings);
276 int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index, 287 int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index,
277 enum v4l2_mbus_pixelcode *code); 288 enum v4l2_mbus_pixelcode *code);
289 int (*enum_mbus_fsizes)(struct v4l2_subdev *sd,
290 struct v4l2_frmsizeenum *fsize);
278 int (*g_mbus_fmt)(struct v4l2_subdev *sd, 291 int (*g_mbus_fmt)(struct v4l2_subdev *sd,
279 struct v4l2_mbus_framefmt *fmt); 292 struct v4l2_mbus_framefmt *fmt);
280 int (*try_mbus_fmt)(struct v4l2_subdev *sd, 293 int (*try_mbus_fmt)(struct v4l2_subdev *sd,
@@ -328,9 +341,13 @@ struct v4l2_subdev_vbi_ops {
328 * This is needed for some sensors, which always corrupt 341 * This is needed for some sensors, which always corrupt
329 * several top lines of the output image, or which send their 342 * several top lines of the output image, or which send their
330 * metadata in them. 343 * metadata in them.
344 * @g_skip_frames: number of frames to skip at stream start. This is needed for
345 * buggy sensors that generate faulty frames when they are
346 * turned on.
331 */ 347 */
332struct v4l2_subdev_sensor_ops { 348struct v4l2_subdev_sensor_ops {
333 int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines); 349 int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
350 int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
334}; 351};
335 352
336/* 353/*
@@ -405,6 +422,25 @@ struct v4l2_subdev_ir_ops {
405 struct v4l2_subdev_ir_parameters *params); 422 struct v4l2_subdev_ir_parameters *params);
406}; 423};
407 424
425struct v4l2_subdev_pad_ops {
426 int (*enum_mbus_code)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
427 struct v4l2_subdev_mbus_code_enum *code);
428 int (*enum_frame_size)(struct v4l2_subdev *sd,
429 struct v4l2_subdev_fh *fh,
430 struct v4l2_subdev_frame_size_enum *fse);
431 int (*enum_frame_interval)(struct v4l2_subdev *sd,
432 struct v4l2_subdev_fh *fh,
433 struct v4l2_subdev_frame_interval_enum *fie);
434 int (*get_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
435 struct v4l2_subdev_format *format);
436 int (*set_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
437 struct v4l2_subdev_format *format);
438 int (*set_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
439 struct v4l2_subdev_crop *crop);
440 int (*get_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
441 struct v4l2_subdev_crop *crop);
442};
443
408struct v4l2_subdev_ops { 444struct v4l2_subdev_ops {
409 const struct v4l2_subdev_core_ops *core; 445 const struct v4l2_subdev_core_ops *core;
410 const struct v4l2_subdev_tuner_ops *tuner; 446 const struct v4l2_subdev_tuner_ops *tuner;
@@ -413,24 +449,55 @@ struct v4l2_subdev_ops {
413 const struct v4l2_subdev_vbi_ops *vbi; 449 const struct v4l2_subdev_vbi_ops *vbi;
414 const struct v4l2_subdev_ir_ops *ir; 450 const struct v4l2_subdev_ir_ops *ir;
415 const struct v4l2_subdev_sensor_ops *sensor; 451 const struct v4l2_subdev_sensor_ops *sensor;
452 const struct v4l2_subdev_pad_ops *pad;
453};
454
455/*
456 * Internal ops. Never call this from drivers, only the v4l2 framework can call
457 * these ops.
458 *
459 * registered: called when this subdev is registered. When called the v4l2_dev
460 * field is set to the correct v4l2_device.
461 *
462 * unregistered: called when this subdev is unregistered. When called the
463 * v4l2_dev field is still set to the correct v4l2_device.
464 *
465 * open: called when the subdev device node is opened by an application.
466 *
467 * close: called when the subdev device node is closed.
468 */
469struct v4l2_subdev_internal_ops {
470 int (*registered)(struct v4l2_subdev *sd);
471 void (*unregistered)(struct v4l2_subdev *sd);
472 int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
473 int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
416}; 474};
417 475
418#define V4L2_SUBDEV_NAME_SIZE 32 476#define V4L2_SUBDEV_NAME_SIZE 32
419 477
420/* Set this flag if this subdev is a i2c device. */ 478/* Set this flag if this subdev is a i2c device. */
421#define V4L2_SUBDEV_FL_IS_I2C (1U << 0) 479#define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
422/* Set this flag if this subdev is a spi device. */ 480/* Set this flag if this subdev is a spi device. */
423#define V4L2_SUBDEV_FL_IS_SPI (1U << 1) 481#define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
482/* Set this flag if this subdev needs a device node. */
483#define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
484/* Set this flag if this subdev generates events. */
485#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
424 486
425/* Each instance of a subdev driver should create this struct, either 487/* Each instance of a subdev driver should create this struct, either
426 stand-alone or embedded in a larger struct. 488 stand-alone or embedded in a larger struct.
427 */ 489 */
428struct v4l2_subdev { 490struct v4l2_subdev {
491#if defined(CONFIG_MEDIA_CONTROLLER)
492 struct media_entity entity;
493#endif
429 struct list_head list; 494 struct list_head list;
430 struct module *owner; 495 struct module *owner;
431 u32 flags; 496 u32 flags;
432 struct v4l2_device *v4l2_dev; 497 struct v4l2_device *v4l2_dev;
433 const struct v4l2_subdev_ops *ops; 498 const struct v4l2_subdev_ops *ops;
499 /* Never call these internal ops from within a driver! */
500 const struct v4l2_subdev_internal_ops *internal_ops;
434 /* The control handler of this subdev. May be NULL. */ 501 /* The control handler of this subdev. May be NULL. */
435 struct v4l2_ctrl_handler *ctrl_handler; 502 struct v4l2_ctrl_handler *ctrl_handler;
436 /* name must be unique */ 503 /* name must be unique */
@@ -440,8 +507,47 @@ struct v4l2_subdev {
440 /* pointer to private data */ 507 /* pointer to private data */
441 void *dev_priv; 508 void *dev_priv;
442 void *host_priv; 509 void *host_priv;
510 /* subdev device node */
511 struct video_device devnode;
512 /* number of events to be allocated on open */
513 unsigned int nevents;
514};
515
516#define media_entity_to_v4l2_subdev(ent) \
517 container_of(ent, struct v4l2_subdev, entity)
518#define vdev_to_v4l2_subdev(vdev) \
519 container_of(vdev, struct v4l2_subdev, devnode)
520
521/*
522 * Used for storing subdev information per file handle
523 */
524struct v4l2_subdev_fh {
525 struct v4l2_fh vfh;
526#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
527 struct v4l2_mbus_framefmt *try_fmt;
528 struct v4l2_rect *try_crop;
529#endif
443}; 530};
444 531
532#define to_v4l2_subdev_fh(fh) \
533 container_of(fh, struct v4l2_subdev_fh, vfh)
534
535#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
536static inline struct v4l2_mbus_framefmt *
537v4l2_subdev_get_try_format(struct v4l2_subdev_fh *fh, unsigned int pad)
538{
539 return &fh->try_fmt[pad];
540}
541
542static inline struct v4l2_rect *
543v4l2_subdev_get_try_crop(struct v4l2_subdev_fh *fh, unsigned int pad)
544{
545 return &fh->try_crop[pad];
546}
547#endif
548
549extern const struct v4l2_file_operations v4l2_subdev_fops;
550
445static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p) 551static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
446{ 552{
447 sd->dev_priv = p; 553 sd->dev_priv = p;
@@ -462,20 +568,8 @@ static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
462 return sd->host_priv; 568 return sd->host_priv;
463} 569}
464 570
465static inline void v4l2_subdev_init(struct v4l2_subdev *sd, 571void v4l2_subdev_init(struct v4l2_subdev *sd,
466 const struct v4l2_subdev_ops *ops) 572 const struct v4l2_subdev_ops *ops);
467{
468 INIT_LIST_HEAD(&sd->list);
469 /* ops->core MUST be set */
470 BUG_ON(!ops || !ops->core);
471 sd->ops = ops;
472 sd->v4l2_dev = NULL;
473 sd->flags = 0;
474 sd->name[0] = '\0';
475 sd->grp_id = 0;
476 sd->dev_priv = NULL;
477 sd->host_priv = NULL;
478}
479 573
480/* Call an ops of a v4l2_subdev, doing the right checks against 574/* Call an ops of a v4l2_subdev, doing the right checks against
481 NULL pointers. 575 NULL pointers.