Skip to content

Commit 32c69fc

Browse files
lyakhMauro Carvalho Chehab
authored andcommitted
[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>
1 parent 7cd74ff commit 32c69fc

4 files changed

Lines changed: 73 additions & 2 deletions

File tree

‎drivers/media/video/soc_camera.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,40 @@ const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
107107
}
108108
EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);
109109

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+
110144
/**
111145
* soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
112146
* @icl: camera platform parameters

‎drivers/media/video/soc_mediabus.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,39 @@ const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
383383
}
384384
EXPORT_SYMBOL(soc_mbus_get_fmtdesc);
385385

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+
386419
static int __init soc_mbus_init(void)
387420
{
388421
return 0;

‎include/media/soc_camera.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ static inline void soc_camera_limit_side(int *start, int *length,
300300
*start = start_min + length_max - *length;
301301
}
302302

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);
305307

306308
/* This is only temporary here - until v4l2-subdev begins to link to video_device */
307309
#include <linux/i2c.h>

‎include/media/soc_mediabus.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,7 @@ const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
8282
s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf);
8383
int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf,
8484
unsigned int *numerator, unsigned int *denominator);
85+
unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
86+
unsigned int flags);
8587

8688
#endif

0 commit comments

Comments
 (0)