Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd73b36f authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (10072): soc-camera: Add signal inversion flags to be used by camera drivers



As reported by Antonio Ospite <ospite@studenti.unina.it> two platforms with a
mt9m111 camera require opposite pixel clock polarity, which means one of them
inverts it. This patch adds support for inversion flags and switches all
available camera drivers to using them.

Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5ca11fa3
Loading
Loading
Loading
Loading
+7 −8
Original line number Original line Diff line number Diff line
@@ -272,17 +272,16 @@ static int mt9m001_set_bus_param(struct soc_camera_device *icd,
static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
{
{
	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
	unsigned int width_flag = SOCAM_DATAWIDTH_10;
	struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
	/* MT9M001 has all capture_format parameters fixed */
	unsigned long flags = SOCAM_DATAWIDTH_10 | SOCAM_PCLK_SAMPLE_RISING |
		SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
		SOCAM_MASTER;


	if (bus_switch_possible(mt9m001))
	if (bus_switch_possible(mt9m001))
		width_flag |= SOCAM_DATAWIDTH_8;
		flags |= SOCAM_DATAWIDTH_8;


	/* MT9M001 has all capture_format parameters fixed */
	return soc_camera_apply_sensor_flags(icl, flags);
	return SOCAM_PCLK_SAMPLE_RISING |
		SOCAM_HSYNC_ACTIVE_HIGH |
		SOCAM_VSYNC_ACTIVE_HIGH |
		SOCAM_MASTER |
		width_flag;
}
}


static int mt9m001_set_fmt(struct soc_camera_device *icd,
static int mt9m001_set_fmt(struct soc_camera_device *icd,
+5 −1
Original line number Original line Diff line number Diff line
@@ -415,9 +415,13 @@ static int mt9m111_stop_capture(struct soc_camera_device *icd)


static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
{
{
	return SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
	struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
	struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
	unsigned long flags = SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
		SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
		SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
		SOCAM_DATAWIDTH_8;
		SOCAM_DATAWIDTH_8;

	return soc_camera_apply_sensor_flags(icl, flags);
}
}


static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
+3 −0
Original line number Original line Diff line number Diff line
@@ -273,6 +273,7 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
				 unsigned long flags)
				 unsigned long flags)
{
{
	struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
	struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
	struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
	unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
	unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
	int ret;
	int ret;
	u16 pixclk = 0;
	u16 pixclk = 0;
@@ -296,6 +297,8 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
		mt9v022->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
		mt9v022->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
	}
	}


	flags = soc_camera_apply_sensor_flags(icl, flags);

	if (flags & SOCAM_PCLK_SAMPLE_RISING)
	if (flags & SOCAM_PCLK_SAMPLE_RISING)
		pixclk |= 0x10;
		pixclk |= 0x10;


+5 −5
Original line number Original line Diff line number Diff line
@@ -716,12 +716,12 @@ static int ov772x_set_bus_param(struct soc_camera_device *icd,
static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
{
{
	struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
	struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);

	struct soc_camera_link *icl = priv->client->dev.platform_data;
	return  SOCAM_PCLK_SAMPLE_RISING |
	unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
		SOCAM_HSYNC_ACTIVE_HIGH  |
		SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
		SOCAM_VSYNC_ACTIVE_HIGH  |
		SOCAM_MASTER             |
		priv->info->buswidth;
		priv->info->buswidth;

	return soc_camera_apply_sensor_flags(icl, flags);
}
}


static int ov772x_get_chip_id(struct soc_camera_device *icd,
static int ov772x_get_chip_id(struct soc_camera_device *icd,
+34 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,40 @@ const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
}
}
EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);
EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);


/**
 * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
 * @icl:	camera platform parameters
 * @flags:	flags to be inverted according to platform configuration
 * @return:	resulting flags
 */
unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
					    unsigned long flags)
{
	unsigned long f;

	/* If only one of the two polarities is supported, switch to the opposite */
	if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) {
		f = flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
		if (f == SOCAM_HSYNC_ACTIVE_HIGH || f == SOCAM_HSYNC_ACTIVE_LOW)
			flags ^= SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW;
	}

	if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) {
		f = flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
		if (f == SOCAM_VSYNC_ACTIVE_HIGH || f == SOCAM_VSYNC_ACTIVE_LOW)
			flags ^= SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW;
	}

	if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) {
		f = flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
		if (f == SOCAM_PCLK_SAMPLE_RISING || f == SOCAM_PCLK_SAMPLE_FALLING)
			flags ^= SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING;
	}

	return flags;
}
EXPORT_SYMBOL(soc_camera_apply_sensor_flags);

static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
				      struct v4l2_format *f)
				      struct v4l2_format *f)
{
{
Loading