Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] V4L: soc-camera: add helper functions for new bus configuration type

Add helper functions to process the new media bus configuration type
similar to soc_camera_apply_sensor_flags() and
soc_camera_bus_param_compatible().

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Guennadi Liakhovetski and committed by
Mauro Carvalho Chehab
32c69fcc 7cd74ffb

+73 -2
+34
drivers/media/video/soc_camera.c
··· 108 108 EXPORT_SYMBOL(soc_camera_xlate_by_fourcc); 109 109 110 110 /** 111 + * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags 112 + * @icl: camera platform parameters 113 + * @cfg: media bus configuration 114 + * @return: resulting flags 115 + */ 116 + unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, 117 + const struct v4l2_mbus_config *cfg) 118 + { 119 + unsigned long f, flags = cfg->flags; 120 + 121 + /* If only one of the two polarities is supported, switch to the opposite */ 122 + if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) { 123 + f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW); 124 + if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW) 125 + flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW; 126 + } 127 + 128 + if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) { 129 + f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW); 130 + if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW) 131 + flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW; 132 + } 133 + 134 + if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) { 135 + f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING); 136 + if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING) 137 + flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING; 138 + } 139 + 140 + return flags; 141 + } 142 + EXPORT_SYMBOL(soc_camera_apply_board_flags); 143 + 144 + /** 111 145 * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags 112 146 * @icl: camera platform parameters 113 147 * @flags: flags to be inverted according to platform configuration
+33
drivers/media/video/soc_mediabus.c
··· 383 383 } 384 384 EXPORT_SYMBOL(soc_mbus_get_fmtdesc); 385 385 386 + unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg, 387 + unsigned int flags) 388 + { 389 + unsigned long common_flags; 390 + bool hsync = true, vsync = true, pclk, data, mode; 391 + bool mipi_lanes, mipi_clock; 392 + 393 + common_flags = cfg->flags & flags; 394 + 395 + switch (cfg->type) { 396 + case V4L2_MBUS_PARALLEL: 397 + hsync = common_flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | 398 + V4L2_MBUS_HSYNC_ACTIVE_LOW); 399 + vsync = common_flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | 400 + V4L2_MBUS_VSYNC_ACTIVE_LOW); 401 + case V4L2_MBUS_BT656: 402 + pclk = common_flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | 403 + V4L2_MBUS_PCLK_SAMPLE_FALLING); 404 + data = common_flags & (V4L2_MBUS_DATA_ACTIVE_HIGH | 405 + V4L2_MBUS_DATA_ACTIVE_LOW); 406 + mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE); 407 + return (!hsync || !vsync || !pclk || !data || !mode) ? 408 + 0 : common_flags; 409 + case V4L2_MBUS_CSI2: 410 + mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES; 411 + mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK | 412 + V4L2_MBUS_CSI2_CONTINUOUS_CLOCK); 413 + return (!mipi_lanes || !mipi_clock) ? 0 : common_flags; 414 + } 415 + return 0; 416 + } 417 + EXPORT_SYMBOL(soc_mbus_config_compatible); 418 + 386 419 static int __init soc_mbus_init(void) 387 420 { 388 421 return 0;
+4 -2
include/media/soc_camera.h
··· 300 300 *start = start_min + length_max - *length; 301 301 } 302 302 303 - extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, 304 - unsigned long flags); 303 + unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, 304 + unsigned long flags); 305 + unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, 306 + const struct v4l2_mbus_config *cfg); 305 307 306 308 /* This is only temporary here - until v4l2-subdev begins to link to video_device */ 307 309 #include <linux/i2c.h>
+2
include/media/soc_mediabus.h
··· 82 82 s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf); 83 83 int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf, 84 84 unsigned int *numerator, unsigned int *denominator); 85 + unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg, 86 + unsigned int flags); 85 87 86 88 #endif