1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright 2021-2022 Bootlin 4 * Author: Paul Kocialkowski <paul.kocialkowski@bootlin.com> 5 */ 6 7 #ifndef _SUN6I_CSI_BRIDGE_H_ 8 #define _SUN6I_CSI_BRIDGE_H_ 9 10 #include <media/v4l2-device.h> 11 #include <media/v4l2-fwnode.h> 12 13 #define SUN6I_CSI_BRIDGE_NAME "sun6i-csi-bridge" 14 15 enum sun6i_csi_bridge_pad { 16 SUN6I_CSI_BRIDGE_PAD_SINK = 0, 17 SUN6I_CSI_BRIDGE_PAD_SOURCE = 1, 18 SUN6I_CSI_BRIDGE_PAD_COUNT = 2, 19 }; 20 21 struct sun6i_csi_device; 22 23 struct sun6i_csi_bridge_format { 24 u32 mbus_code; 25 u8 input_format; 26 u8 input_yuv_seq; 27 u8 input_yuv_seq_invert; 28 }; 29 30 struct sun6i_csi_bridge_source { 31 struct v4l2_subdev *subdev; 32 struct v4l2_fwnode_endpoint endpoint; 33 bool expected; 34 }; 35 36 struct sun6i_csi_bridge_async_subdev { 37 struct v4l2_async_subdev async_subdev; 38 struct sun6i_csi_bridge_source *source; 39 }; 40 41 struct sun6i_csi_bridge { 42 struct v4l2_subdev subdev; 43 struct v4l2_async_notifier notifier; 44 struct media_pad pads[2]; 45 struct v4l2_mbus_framefmt mbus_format; 46 struct mutex lock; /* Mbus format lock. */ 47 48 struct sun6i_csi_bridge_source source_parallel; 49 struct sun6i_csi_bridge_source source_mipi_csi2; 50 }; 51 52 /* Helpers */ 53 54 void sun6i_csi_bridge_dimensions(struct sun6i_csi_device *csi_dev, 55 unsigned int *width, unsigned int *height); 56 void sun6i_csi_bridge_format(struct sun6i_csi_device *csi_dev, 57 u32 *mbus_code, u32 *field); 58 59 /* Format */ 60 61 const struct sun6i_csi_bridge_format * 62 sun6i_csi_bridge_format_find(u32 mbus_code); 63 64 /* Bridge */ 65 66 int sun6i_csi_bridge_setup(struct sun6i_csi_device *csi_dev); 67 void sun6i_csi_bridge_cleanup(struct sun6i_csi_device *csi_dev); 68 69 #endif 70