.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * V4L2 sub-device support header. |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
15 | 6 | */ |
---|
16 | 7 | |
---|
17 | 8 | #ifndef _V4L2_SUBDEV_H |
---|
.. | .. |
---|
70 | 61 | * device. These devices are usually audio/video muxers/encoders/decoders or |
---|
71 | 62 | * sensors and webcam controllers. |
---|
72 | 63 | * |
---|
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 |
---|
74 | 65 | * may also be used. |
---|
75 | 66 | * |
---|
76 | 67 | * The v4l2_subdev struct provides a way of accessing these devices in a |
---|
.. | .. |
---|
390 | 381 | * OUTPUT device. This is ignored by video capture devices. |
---|
391 | 382 | * |
---|
392 | 383 | * @g_input_status: get input status. Same as the status field in the |
---|
393 | | - * &struct &v4l2_input |
---|
| 384 | + * &struct v4l2_input |
---|
394 | 385 | * |
---|
395 | 386 | * @s_stream: used to notify the driver that a video stream will start or has |
---|
396 | 387 | * stopped. |
---|
.. | .. |
---|
410 | 401 | * @g_dv_timings: Get custom dv timings in the sub device. |
---|
411 | 402 | * |
---|
412 | 403 | * @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. |
---|
419 | 404 | * |
---|
420 | 405 | * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev |
---|
421 | 406 | * can adjust @size to a lower value and must not write more data to the |
---|
.. | .. |
---|
444 | 429 | struct v4l2_dv_timings *timings); |
---|
445 | 430 | int (*query_dv_timings)(struct v4l2_subdev *sd, |
---|
446 | 431 | 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); |
---|
451 | 432 | int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf, |
---|
452 | 433 | unsigned int *size); |
---|
453 | 434 | }; |
---|
.. | .. |
---|
575 | 556 | * |
---|
576 | 557 | * @rx_read: Reads received codes or pulse width data. |
---|
577 | 558 | * 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 |
---|
579 | 560 | * 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 |
---|
581 | 562 | * the IR receiver. It is recommended to call |
---|
582 | 563 | * [rt]x_g_parameters first to fill out the current state, and only change |
---|
583 | 564 | * the fields that need to be changed. Upon return, the actual device |
---|
.. | .. |
---|
591 | 572 | * |
---|
592 | 573 | * @tx_write: Writes codes or pulse width data for transmission. |
---|
593 | 574 | * 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 |
---|
595 | 576 | * 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 |
---|
597 | 578 | * the IR transmitter. It is recommended to call |
---|
598 | 579 | * [rt]x_g_parameters first to fill out the current state, and only change |
---|
599 | 580 | * the fields that need to be changed. Upon return, the actual device |
---|
.. | .. |
---|
679 | 660 | * |
---|
680 | 661 | * @set_frame_desc: set the low level media bus frame parameters, @fd array |
---|
681 | 662 | * 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. |
---|
682 | 687 | */ |
---|
683 | 688 | struct v4l2_subdev_pad_ops { |
---|
684 | 689 | int (*init_cfg)(struct v4l2_subdev *sd, |
---|
.. | .. |
---|
719 | 724 | struct v4l2_mbus_frame_desc *fd); |
---|
720 | 725 | int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad, |
---|
721 | 726 | 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); |
---|
722 | 731 | }; |
---|
723 | 732 | |
---|
724 | 733 | /** |
---|
.. | .. |
---|
755 | 764 | * |
---|
756 | 765 | * @open: called when the subdev device node is opened by an application. |
---|
757 | 766 | * |
---|
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. |
---|
759 | 778 | * |
---|
760 | 779 | * .. note:: |
---|
761 | 780 | * Never call this from drivers, only the v4l2 framework can call |
---|
.. | .. |
---|
766 | 785 | void (*unregistered)(struct v4l2_subdev *sd); |
---|
767 | 786 | int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh); |
---|
768 | 787 | int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh); |
---|
| 788 | + void (*release)(struct v4l2_subdev *sd); |
---|
769 | 789 | }; |
---|
770 | 790 | |
---|
771 | 791 | #define V4L2_SUBDEV_NAME_SIZE 32 |
---|
.. | .. |
---|
776 | 796 | #define V4L2_SUBDEV_FL_IS_SPI (1U << 1) |
---|
777 | 797 | /* Set this flag if this subdev needs a device node. */ |
---|
778 | 798 | #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 | + */ |
---|
780 | 804 | #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3) |
---|
781 | 805 | |
---|
782 | 806 | struct regulator_bulk_data; |
---|
.. | .. |
---|
895 | 919 | * |
---|
896 | 920 | * @vfh: pointer to &struct v4l2_fh |
---|
897 | 921 | * @pad: pointer to &struct v4l2_subdev_pad_config |
---|
| 922 | + * @owner: module pointer to the owner of this file handle |
---|
898 | 923 | */ |
---|
899 | 924 | struct v4l2_subdev_fh { |
---|
900 | 925 | struct v4l2_fh vfh; |
---|
| 926 | + struct module *owner; |
---|
901 | 927 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
---|
902 | 928 | struct v4l2_subdev_pad_config *pad; |
---|
903 | 929 | #endif |
---|
.. | .. |
---|
922 | 948 | * @cfg: pointer to &struct v4l2_subdev_pad_config array. |
---|
923 | 949 | * @pad: index of the pad in the @cfg array. |
---|
924 | 950 | */ |
---|
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) |
---|
929 | 955 | { |
---|
930 | 956 | if (WARN_ON(pad >= sd->entity.num_pads)) |
---|
931 | 957 | pad = 0; |
---|
.. | .. |
---|
940 | 966 | * @cfg: pointer to &struct v4l2_subdev_pad_config array. |
---|
941 | 967 | * @pad: index of the pad in the @cfg array. |
---|
942 | 968 | */ |
---|
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) |
---|
947 | 973 | { |
---|
948 | 974 | if (WARN_ON(pad >= sd->entity.num_pads)) |
---|
949 | 975 | pad = 0; |
---|
.. | .. |
---|
951 | 977 | } |
---|
952 | 978 | |
---|
953 | 979 | /** |
---|
954 | | - * v4l2_subdev_get_try_crop - ancillary routine to call |
---|
| 980 | + * v4l2_subdev_get_try_compose - ancillary routine to call |
---|
955 | 981 | * &struct v4l2_subdev_pad_config->try_compose |
---|
956 | 982 | * |
---|
957 | 983 | * @sd: pointer to &struct v4l2_subdev |
---|
958 | 984 | * @cfg: pointer to &struct v4l2_subdev_pad_config array. |
---|
959 | 985 | * @pad: index of the pad in the @cfg array. |
---|
960 | 986 | */ |
---|
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) |
---|
965 | 991 | { |
---|
966 | 992 | if (WARN_ON(pad >= sd->entity.num_pads)) |
---|
967 | 993 | pad = 0; |
---|
968 | 994 | return &cfg[pad].try_compose; |
---|
969 | 995 | } |
---|
| 996 | + |
---|
970 | 997 | #endif |
---|
971 | 998 | |
---|
972 | 999 | extern const struct v4l2_file_operations v4l2_subdev_fops; |
---|
.. | .. |
---|
1018 | 1045 | } |
---|
1019 | 1046 | |
---|
1020 | 1047 | #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); |
---|
1021 | 1065 | |
---|
1022 | 1066 | /** |
---|
1023 | 1067 | * v4l2_subdev_link_validate_default - validates a media link |
---|
.. | .. |
---|
1074 | 1118 | void v4l2_subdev_init(struct v4l2_subdev *sd, |
---|
1075 | 1119 | const struct v4l2_subdev_ops *ops); |
---|
1076 | 1120 | |
---|
| 1121 | +extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers; |
---|
| 1122 | + |
---|
1077 | 1123 | /** |
---|
1078 | 1124 | * v4l2_subdev_call - call an operation of a v4l2_subdev. |
---|
1079 | 1125 | * |
---|
1080 | 1126 | * @sd: pointer to the &struct v4l2_subdev |
---|
1081 | 1127 | * @o: name of the element at &struct v4l2_subdev_ops that contains @f. |
---|
1082 | 1128 | * 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. |
---|
1084 | 1130 | * The callback functions are defined in groups, according to |
---|
1085 | 1131 | * each element at &struct v4l2_subdev_ops. |
---|
1086 | | - * @args...: arguments for @f. |
---|
| 1132 | + * @args: arguments for @f. |
---|
1087 | 1133 | * |
---|
1088 | 1134 | * Example: err = v4l2_subdev_call(sd, video, s_std, norm); |
---|
1089 | 1135 | */ |
---|
1090 | 1136 | #define v4l2_subdev_call(sd, o, f, args...) \ |
---|
1091 | 1137 | ({ \ |
---|
| 1138 | + struct v4l2_subdev *__sd = (sd); \ |
---|
1092 | 1139 | int __result; \ |
---|
1093 | | - if (!(sd)) \ |
---|
| 1140 | + if (!__sd) \ |
---|
1094 | 1141 | __result = -ENODEV; \ |
---|
1095 | | - else if (!((sd)->ops->o && (sd)->ops->o->f)) \ |
---|
| 1142 | + else if (!(__sd->ops->o && __sd->ops->o->f)) \ |
---|
1096 | 1143 | __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); \ |
---|
1097 | 1148 | else \ |
---|
1098 | | - __result = (sd)->ops->o->f((sd), ##args); \ |
---|
| 1149 | + __result = __sd->ops->o->f(__sd, ##args); \ |
---|
1099 | 1150 | __result; \ |
---|
1100 | 1151 | }) |
---|
1101 | 1152 | |
---|