hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/include/media/v4l2-subdev.h
....@@ -1,17 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * V4L2 sub-device support header.
34 *
45 * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
156 */
167
178 #ifndef _V4L2_SUBDEV_H
....@@ -70,7 +61,7 @@
7061 * device. These devices are usually audio/video muxers/encoders/decoders or
7162 * sensors and webcam controllers.
7263 *
73
- * Usually these devices are controlled through an i2c bus, but other busses
64
+ * Usually these devices are controlled through an i2c bus, but other buses
7465 * may also be used.
7566 *
7667 * The v4l2_subdev struct provides a way of accessing these devices in a
....@@ -390,7 +381,7 @@
390381 * OUTPUT device. This is ignored by video capture devices.
391382 *
392383 * @g_input_status: get input status. Same as the status field in the
393
- * &struct &v4l2_input
384
+ * &struct v4l2_input
394385 *
395386 * @s_stream: used to notify the driver that a video stream will start or has
396387 * stopped.
....@@ -410,12 +401,6 @@
410401 * @g_dv_timings: Get custom dv timings in the sub device.
411402 *
412403 * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS() ioctl handler code.
413
- *
414
- * @g_mbus_config: get supported mediabus configurations
415
- *
416
- * @s_mbus_config: set a certain mediabus configuration. This operation is added
417
- * for compatibility with soc-camera drivers and should not be used by new
418
- * software.
419404 *
420405 * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
421406 * can adjust @size to a lower value and must not write more data to the
....@@ -444,10 +429,6 @@
444429 struct v4l2_dv_timings *timings);
445430 int (*query_dv_timings)(struct v4l2_subdev *sd,
446431 struct v4l2_dv_timings *timings);
447
- int (*g_mbus_config)(struct v4l2_subdev *sd,
448
- struct v4l2_mbus_config *cfg);
449
- int (*s_mbus_config)(struct v4l2_subdev *sd,
450
- const struct v4l2_mbus_config *cfg);
451432 int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
452433 unsigned int *size);
453434 };
....@@ -575,9 +556,9 @@
575556 *
576557 * @rx_read: Reads received codes or pulse width data.
577558 * The semantics are similar to a non-blocking read() call.
578
- * @rx_g_parameters: Get the current operating parameters and state of the
559
+ * @rx_g_parameters: Get the current operating parameters and state of
579560 * the IR receiver.
580
- * @rx_s_parameters: Set the current operating parameters and state of the
561
+ * @rx_s_parameters: Set the current operating parameters and state of
581562 * the IR receiver. It is recommended to call
582563 * [rt]x_g_parameters first to fill out the current state, and only change
583564 * the fields that need to be changed. Upon return, the actual device
....@@ -591,9 +572,9 @@
591572 *
592573 * @tx_write: Writes codes or pulse width data for transmission.
593574 * The semantics are similar to a non-blocking write() call.
594
- * @tx_g_parameters: Get the current operating parameters and state of the
575
+ * @tx_g_parameters: Get the current operating parameters and state of
595576 * the IR transmitter.
596
- * @tx_s_parameters: Set the current operating parameters and state of the
577
+ * @tx_s_parameters: Set the current operating parameters and state of
597578 * the IR transmitter. It is recommended to call
598579 * [rt]x_g_parameters first to fill out the current state, and only change
599580 * the fields that need to be changed. Upon return, the actual device
....@@ -679,6 +660,30 @@
679660 *
680661 * @set_frame_desc: set the low level media bus frame parameters, @fd array
681662 * may be adjusted by the subdev driver to device capabilities.
663
+ *
664
+ * @get_mbus_config: get the media bus configuration of a remote sub-device.
665
+ * The media bus configuration is usually retrieved from the
666
+ * firmware interface at sub-device probe time, immediately
667
+ * applied to the hardware and eventually adjusted by the
668
+ * driver. Remote sub-devices (usually video receivers) shall
669
+ * use this operation to query the transmitting end bus
670
+ * configuration in order to adjust their own one accordingly.
671
+ * Callers should make sure they get the most up-to-date as
672
+ * possible configuration from the remote end, likely calling
673
+ * this operation as close as possible to stream on time. The
674
+ * operation shall fail if the pad index it has been called on
675
+ * is not valid or in case of unrecoverable failures.
676
+ *
677
+ * @set_mbus_config: set the media bus configuration of a remote sub-device.
678
+ * This operations is intended to allow, in combination with
679
+ * the get_mbus_config operation, the negotiation of media bus
680
+ * configuration parameters between media sub-devices. The
681
+ * operation shall not fail if the requested configuration is
682
+ * not supported, but the driver shall update the content of
683
+ * the %config argument to reflect what has been actually
684
+ * applied to the hardware. The operation shall fail if the
685
+ * pad index it has been called on is not valid or in case of
686
+ * unrecoverable failures.
682687 */
683688 struct v4l2_subdev_pad_ops {
684689 int (*init_cfg)(struct v4l2_subdev *sd,
....@@ -719,6 +724,10 @@
719724 struct v4l2_mbus_frame_desc *fd);
720725 int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
721726 struct v4l2_mbus_frame_desc *fd);
727
+ int (*get_mbus_config)(struct v4l2_subdev *sd, unsigned int pad,
728
+ struct v4l2_mbus_config *config);
729
+ int (*set_mbus_config)(struct v4l2_subdev *sd, unsigned int pad,
730
+ struct v4l2_mbus_config *config);
722731 };
723732
724733 /**
....@@ -755,7 +764,17 @@
755764 *
756765 * @open: called when the subdev device node is opened by an application.
757766 *
758
- * @close: called when the subdev device node is closed.
767
+ * @close: called when the subdev device node is closed. Please note that
768
+ * it is possible for @close to be called after @unregistered!
769
+ *
770
+ * @release: called when the last user of the subdev device is gone. This
771
+ * happens after the @unregistered callback and when the last open
772
+ * filehandle to the v4l-subdevX device node was closed. If no device
773
+ * node was created for this sub-device, then the @release callback
774
+ * is called right after the @unregistered callback.
775
+ * The @release callback is typically used to free the memory containing
776
+ * the v4l2_subdev structure. It is almost certainly required for any
777
+ * sub-device that sets the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
759778 *
760779 * .. note::
761780 * Never call this from drivers, only the v4l2 framework can call
....@@ -766,6 +785,7 @@
766785 void (*unregistered)(struct v4l2_subdev *sd);
767786 int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
768787 int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
788
+ void (*release)(struct v4l2_subdev *sd);
769789 };
770790
771791 #define V4L2_SUBDEV_NAME_SIZE 32
....@@ -776,7 +796,11 @@
776796 #define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
777797 /* Set this flag if this subdev needs a device node. */
778798 #define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
779
-/* Set this flag if this subdev generates events. */
799
+/*
800
+ * Set this flag if this subdev generates events.
801
+ * Note controls can send events, thus drivers exposing controls
802
+ * should set this flag.
803
+ */
780804 #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
781805
782806 struct regulator_bulk_data;
....@@ -895,9 +919,11 @@
895919 *
896920 * @vfh: pointer to &struct v4l2_fh
897921 * @pad: pointer to &struct v4l2_subdev_pad_config
922
+ * @owner: module pointer to the owner of this file handle
898923 */
899924 struct v4l2_subdev_fh {
900925 struct v4l2_fh vfh;
926
+ struct module *owner;
901927 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
902928 struct v4l2_subdev_pad_config *pad;
903929 #endif
....@@ -922,10 +948,10 @@
922948 * @cfg: pointer to &struct v4l2_subdev_pad_config array.
923949 * @pad: index of the pad in the @cfg array.
924950 */
925
-static inline struct v4l2_mbus_framefmt
926
-*v4l2_subdev_get_try_format(struct v4l2_subdev *sd,
927
- struct v4l2_subdev_pad_config *cfg,
928
- unsigned int pad)
951
+static inline struct v4l2_mbus_framefmt *
952
+v4l2_subdev_get_try_format(struct v4l2_subdev *sd,
953
+ struct v4l2_subdev_pad_config *cfg,
954
+ unsigned int pad)
929955 {
930956 if (WARN_ON(pad >= sd->entity.num_pads))
931957 pad = 0;
....@@ -940,10 +966,10 @@
940966 * @cfg: pointer to &struct v4l2_subdev_pad_config array.
941967 * @pad: index of the pad in the @cfg array.
942968 */
943
-static inline struct v4l2_rect
944
-*v4l2_subdev_get_try_crop(struct v4l2_subdev *sd,
945
- struct v4l2_subdev_pad_config *cfg,
946
- unsigned int pad)
969
+static inline struct v4l2_rect *
970
+v4l2_subdev_get_try_crop(struct v4l2_subdev *sd,
971
+ struct v4l2_subdev_pad_config *cfg,
972
+ unsigned int pad)
947973 {
948974 if (WARN_ON(pad >= sd->entity.num_pads))
949975 pad = 0;
....@@ -951,22 +977,23 @@
951977 }
952978
953979 /**
954
- * v4l2_subdev_get_try_crop - ancillary routine to call
980
+ * v4l2_subdev_get_try_compose - ancillary routine to call
955981 * &struct v4l2_subdev_pad_config->try_compose
956982 *
957983 * @sd: pointer to &struct v4l2_subdev
958984 * @cfg: pointer to &struct v4l2_subdev_pad_config array.
959985 * @pad: index of the pad in the @cfg array.
960986 */
961
-static inline struct v4l2_rect
962
-*v4l2_subdev_get_try_compose(struct v4l2_subdev *sd,
963
- struct v4l2_subdev_pad_config *cfg,
964
- unsigned int pad)
987
+static inline struct v4l2_rect *
988
+v4l2_subdev_get_try_compose(struct v4l2_subdev *sd,
989
+ struct v4l2_subdev_pad_config *cfg,
990
+ unsigned int pad)
965991 {
966992 if (WARN_ON(pad >= sd->entity.num_pads))
967993 pad = 0;
968994 return &cfg[pad].try_compose;
969995 }
996
+
970997 #endif
971998
972999 extern const struct v4l2_file_operations v4l2_subdev_fops;
....@@ -1018,6 +1045,23 @@
10181045 }
10191046
10201047 #ifdef CONFIG_MEDIA_CONTROLLER
1048
+
1049
+/**
1050
+ * v4l2_subdev_get_fwnode_pad_1_to_1 - Get pad number from a subdev fwnode
1051
+ * endpoint, assuming 1:1 port:pad
1052
+ *
1053
+ * @entity: Pointer to the subdev entity
1054
+ * @endpoint: Pointer to a parsed fwnode endpoint
1055
+ *
1056
+ * This function can be used as the .get_fwnode_pad operation for
1057
+ * subdevices that map port numbers and pad indexes 1:1. If the endpoint
1058
+ * is owned by the subdevice, the function returns the endpoint port
1059
+ * number.
1060
+ *
1061
+ * Returns the endpoint port number on success or a negative error code.
1062
+ */
1063
+int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
1064
+ struct fwnode_endpoint *endpoint);
10211065
10221066 /**
10231067 * v4l2_subdev_link_validate_default - validates a media link
....@@ -1074,28 +1118,35 @@
10741118 void v4l2_subdev_init(struct v4l2_subdev *sd,
10751119 const struct v4l2_subdev_ops *ops);
10761120
1121
+extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
1122
+
10771123 /**
10781124 * v4l2_subdev_call - call an operation of a v4l2_subdev.
10791125 *
10801126 * @sd: pointer to the &struct v4l2_subdev
10811127 * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
10821128 * Each element there groups a set of callbacks functions.
1083
- * @f: callback function that will be called if @cond matches.
1129
+ * @f: callback function to be called.
10841130 * The callback functions are defined in groups, according to
10851131 * each element at &struct v4l2_subdev_ops.
1086
- * @args...: arguments for @f.
1132
+ * @args: arguments for @f.
10871133 *
10881134 * Example: err = v4l2_subdev_call(sd, video, s_std, norm);
10891135 */
10901136 #define v4l2_subdev_call(sd, o, f, args...) \
10911137 ({ \
1138
+ struct v4l2_subdev *__sd = (sd); \
10921139 int __result; \
1093
- if (!(sd)) \
1140
+ if (!__sd) \
10941141 __result = -ENODEV; \
1095
- else if (!((sd)->ops->o && (sd)->ops->o->f)) \
1142
+ else if (!(__sd->ops->o && __sd->ops->o->f)) \
10961143 __result = -ENOIOCTLCMD; \
1144
+ else if (v4l2_subdev_call_wrappers.o && \
1145
+ v4l2_subdev_call_wrappers.o->f) \
1146
+ __result = v4l2_subdev_call_wrappers.o->f( \
1147
+ __sd, ##args); \
10971148 else \
1098
- __result = (sd)->ops->o->f((sd), ##args); \
1149
+ __result = __sd->ops->o->f(__sd, ##args); \
10991150 __result; \
11001151 })
11011152