Skip to contentSkip to conversation

marvell-ccic: add soc camera support in marvell-ccic driver

PATCH In review Albert Wang 3 participants 40 messages Feb 7, 2013 – Mar 13, 2013 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

v4 cover marvell-ccic: add soc camera support in marvell-ccic driver

The following patches series will add soc_camera support in marvell-ccic driver

Patch set V4 - Change log:
- remove the first patch of V3 which had been queued in tree
- merge [PATCH 09/15-12/15] of V3 to [PATCH 10/12] of V4
- use soc_camera mode replace the old mode for maintain in the future
- correct some errors of implementation in mcam_ctlr_image()
- change get_mcam() function name to vq_to_mcam()
- use proper words replace some inaccurate wordings in description
- add [PATCH 08/12] to rename varablies for avoiding CamelCase warning
- adjust patch sequence and move [PATCH 14/15] of V3 to [PATCH 09/12] of V4
- change some functions implementation include spliting into 2 functions and decreasing parameters

Patch set V3 - Change log:
- correct and enhance the implementation of some functions
- replace most of preprocessor instruction with runtime detect
- use devm_clk_get and devm_gpio_request which were missed in previous version
- change code format in some funcions: replace if-else with switch
- change some confused variable names
- remove unnecessary functions: buf_init, buf_cleanup ...
- remove unnecessary keyword: inline, extern ...
- remove unnecessary include header file name
- remove duplicated and unused code
- remove unnecessary initialization of ret variable
- [PATCH 09/15] change description

Patch set V2 - Change log:
- remove register definition patch
- split big patch to some small patches
- split mcam-core.c to mcam-core.c and mcam-core-standard.c
- add mcam-core-soc.c for soc camera support
- split 3 frame buffers support patch into 2 patches

Patch set V1 - Log:
- add mmp register definition
- add soc_camera support on mcam core and mmp driver
- add 3 frames buffers support in DMA_CONTIG mode

Thanks
Albert Wang

--
Albert Wang (7):
[media] marvell-ccic: reset ccic phy when stop streaming for stability [media] marvell-ccic: switch to resource managed allocation and request [media] marvell-ccic: rename B_DMA* to avoid CamelCase warning [media] marvell-ccic: use unsigned int type replace int type [media] marvell-ccic: add soc_camera support for marvell-ccic driver [media] marvell-ccic: add dma burst support for marvell-ccic driver [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

Libin Yang (5):
[media] marvell-ccic: add MIPI support for marvell-ccic driver [media] marvell-ccic: add clock tree support for marvell-ccic driver [media] marvell-ccic: refine mcam_set_contig_buffer function [media] marvell-ccic: add new formats support for marvell-ccic driver [media] marvell-ccic: add SOF/EOF pair check for marvell-ccic driver

 drivers/media/platform/Makefile                   |    4 +-
 drivers/media/platform/marvell-ccic/Kconfig       |    6 +-
 drivers/media/platform/marvell-ccic/cafe-driver.c |    2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c   | 1362 ++++++++++-----------
 drivers/media/platform/marvell-ccic/mcam-core.h   |  102 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c  |  306 +++--
 include/media/mmp-camera.h                        |   16 +
 7 files changed, 941 insertions(+), 857 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v4 1/12 marvell-ccic: add MIPI support for marvell-ccic driver

From: Libin Yang <[email protected]>

This patch adds the MIPI support for marvell-ccic. Board driver should determine whether using MIPI or not.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   66 +++++++++++++
 drivers/media/platform/marvell-ccic/mcam-core.h  |   28 +++++-
 drivers/media/platform/marvell-ccic/mmp-driver.c |  113 +++++++++++++++++++++-
 include/media/mmp-camera.h                       |   10 ++
 4 files changed, 214 insertions(+), 3 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +66 -0
index 7012913f..7e178d8 100755
@@ -19,6 +19,7 @@
 #include <linux/delay.h>
 #include <linux/vmalloc.h>
 #include <linux/io.h>
+#include <linux/clk.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
@@ -253,6 +254,39 @@ static void mcam_ctlr_stop(struct mcam_camera *cam)
 	mcam_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
 }
 
+static int mcam_config_mipi(struct mcam_camera *mcam, int enable)
+{
+	if (mcam->bus_type == V4L2_MBUS_CSI2 && enable) {
+		/* Using MIPI mode and enable MIPI */
+		cam_dbg(mcam, "camera: DPHY3=0x%x, DPHY5=0x%x, DPHY6=0x%x\n",
+			mcam->dphy[0], mcam->dphy[1], mcam->dphy[2]);
+		mcam_reg_write(mcam, REG_CSI2_DPHY3, mcam->dphy[0]);
+		mcam_reg_write(mcam, REG_CSI2_DPHY5, mcam->dphy[1]);
+		mcam_reg_write(mcam, REG_CSI2_DPHY6, mcam->dphy[2]);
+
+		if (mcam->mipi_enabled == 0) {
+			BUG_ON(mcam->lane > 4 || mcam->lane <= 0);
+			/*
+			 * 0x41 actives 1 lane
+			 * 0x43 actives 2 lanes
+			 * 0x45 actives 3 lanes (never happen)
+			 * 0x47 actives 4 lanes
+			 */
+			mcam_reg_write(mcam, REG_CSI2_CTRL0,
+				CSI2_C0_MIPI_EN | CSI2_C0_ACT_LANE(mcam->lane));
+			mcam->mipi_enabled = 1;
+		}
+	} else {
+		/* Using Parallel mode or disable MIPI */
+		mcam_reg_write(mcam, REG_CSI2_CTRL0, 0x0);
+		mcam_reg_write(mcam, REG_CSI2_DPHY3, 0x0);
+		mcam_reg_write(mcam, REG_CSI2_DPHY5, 0x0);
+		mcam_reg_write(mcam, REG_CSI2_DPHY6, 0x0);
+		mcam->mipi_enabled = 0;
+	}
+	return 0;
+}
+
 /* ------------------------------------------------------------------- */
 
 #ifdef MCAM_MODE_VMALLOC
@@ -656,6 +690,13 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
 	 */
 	mcam_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC,
 			C0_SIFM_MASK);
+
+	/*
+	 * This field controls the generation of EOF(DVP only)
+	 */
+	if (cam->bus_type != V4L2_MBUS_CSI2)
+		mcam_reg_set_bit(cam, REG_CTRL0,
+				C0_EOF_VSYNC | C0_VEDGE_CTRL);
 }
 
 
@@ -886,6 +927,16 @@ static int mcam_read_setup(struct mcam_camera *cam)
 	spin_lock_irqsave(&cam->dev_lock, flags);
 	clear_bit(CF_DMA_ACTIVE, &cam->flags);
 	mcam_reset_buffers(cam);
+	/*
+	 * Update CSI2_DPHY value
+	 */
+	if (cam->calc_dphy)
+		cam->calc_dphy(cam);
+	cam_dbg(cam, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x\n",
+			cam->dphy[0], cam->dphy[1], cam->dphy[2]);
+	ret = mcam_config_mipi(cam, 1);
+	if (ret < 0)
+		return ret;
 	mcam_ctlr_irq_enable(cam);
 	cam->state = S_STREAMING;
 	if (!test_bit(CF_SG_RESTART, &cam->flags))
@@ -1551,6 +1602,16 @@ static int mcam_v4l_open(struct file *filp)
 		mcam_set_config_needed(cam, 1);
 	}
 	(cam->users)++;
+	if (cam->bus_type == V4L2_MBUS_CSI2) {
+		cam->pll1 = devm_clk_get(cam->dev, "pll1");
+		if (IS_ERR_OR_NULL(cam->pll1) && cam->dphy[2] == 0) {
+			cam_err(cam, "Could not get pll1 clock\n");
+			if (IS_ERR(cam->pll1))
+				ret = PTR_ERR(cam->pll1);
+			else
+				ret = -EINVAL;
+		}
+	}
 out:
 	mutex_unlock(&cam->s_mutex);
 	return ret;
@@ -1569,10 +1630,15 @@ static int mcam_v4l_release(struct file *filp)
 	if (cam->users == 0) {
 		mcam_ctlr_stop_dma(cam);
 		mcam_cleanup_vb2(cam);
+		mcam_config_mipi(cam, 0);
 		mcam_ctlr_power_down(cam);
 		if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read)
 			mcam_free_dma_bufs(cam);
 	}
+	if (cam->bus_type == V4L2_MBUS_CSI2) {
+		devm_clk_put(cam->dev, cam->pll1);
+		cam->pll1 = NULL;
+	}
 	mutex_unlock(&cam->s_mutex);
 	return 0;
 }
drivers/media/platform/marvell-ccic/mcam-core.h +26 -2
index 5e802c6..f73a801 100755
@@ -101,11 +101,21 @@ struct mcam_camera {
 	short int clock_speed;	/* Sensor clock speed, default 30 */
 	short int use_smbus;	/* SMBUS or straight I2c? */
 	enum mcam_buffer_mode buffer_mode;
+
+	enum v4l2_mbus_type bus_type;
+	/* MIPI support */
+	int *dphy;
+	int mipi_enabled;
+	int lane;			/* lane number */
+
+	struct clk *pll1;
+
 	/*
 	 * Callbacks from the core to the platform code.
 	 */
 	void (*plat_power_up) (struct mcam_camera *cam);
 	void (*plat_power_down) (struct mcam_camera *cam);
+	void (*calc_dphy) (struct mcam_camera *cam);
 
 	/*
 	 * Everything below here is private to the mcam core and
@@ -218,6 +228,17 @@ int mccic_resume(struct mcam_camera *cam);
 #define REG_Y0BAR	0x00
 #define REG_Y1BAR	0x04
 #define REG_Y2BAR	0x08
+
+/*
+ * register definitions for MIPI support
+ */
+#define REG_CSI2_CTRL0	0x100
+#define   CSI2_C0_MIPI_EN (0x1 << 0)
+#define   CSI2_C0_ACT_LANE(n) ((n-1) << 1)
+#define REG_CSI2_DPHY3	0x12c
+#define REG_CSI2_DPHY5	0x134
+#define REG_CSI2_DPHY6	0x138
+
 /* ... */
 
 #define REG_IMGPITCH	0x24	/* Image pitch register */
@@ -286,13 +307,16 @@ int mccic_resume(struct mcam_camera *cam);
 #define	  C0_YUVE_XUVY	  0x00020000	/* 420: .UVY		*/
 #define	  C0_YUVE_XVUY	  0x00030000	/* 420: .VUY		*/
 /* Bayer bits 18,19 if needed */
+#define	  C0_EOF_VSYNC	  0x00400000	/* Generate EOF by VSYNC */
+#define	  C0_VEDGE_CTRL   0x00800000	/* Detect falling edge of VSYNC */
 #define	  C0_HPOL_LOW	  0x01000000	/* HSYNC polarity active low */
 #define	  C0_VPOL_LOW	  0x02000000	/* VSYNC polarity active low */
 #define	  C0_VCLK_LOW	  0x04000000	/* VCLK on falling edge */
 #define	  C0_DOWNSCALE	  0x08000000	/* Enable downscaler */
-#define	  C0_SIFM_MASK	  0xc0000000	/* SIF mode bits */
+/* SIFMODE */
 #define	  C0_SIF_HVSYNC	  0x00000000	/* Use H/VSYNC */
-#define	  CO_SOF_NOSYNC	  0x40000000	/* Use inband active signaling */
+#define	  C0_SOF_NOSYNC	  0x40000000	/* Use inband active signaling */
+#define	  C0_SIFM_MASK	  0xc0000000	/* SIF mode bits */
 
 /* Bits below C1_444ALPHA are not present in Cafe */
 #define REG_CTRL1	0x40	/* Control 1 */
drivers/media/platform/marvell-ccic/mmp-driver.c +112 -1

145 lines not on this page · raw message

include/media/mmp-camera.h +10 -0
index 7611963..813efe2 100755
@@ -1,3 +1,4 @@
+#include <media/v4l2-mediabus.h>
 /*
  * Information for the Marvell Armada MMP camera
  */
@@ -6,4 +7,13 @@ struct mmp_camera_platform_data {
 	struct platform_device *i2c_device;
 	int sensor_power_gpio;
 	int sensor_reset_gpio;
+	enum v4l2_mbus_type bus_type;
+	/*
+	 * MIPI support
+	 */
+	int dphy[3];		/* DPHY: CSI2_DPHY3, CSI2_DPHY5, CSI2_DPHY6 */
+	int dphy3_algo;		/* Exist 2 algos for calculate CSI2_DPHY3 */
+	int mipi_enabled;	/* MIPI enabled flag */
+	int lane;		/* ccic used lane number; 0 means DVP mode */
+	int lane_clk;
 };
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Albert

A general comment first: I have no idea about this hardware, so, feel free to ignore all my hardware-handling related comments. But just from looking your handling of the pll1 clock does seem a bit fishy to me. You acquire and release the clock in the generic mcam code, but only use it in the mmp driver. Is it really needed centrally? Wouldn't it suffice to only acquire it in mmp? Same goes for your mcam_config_mipi() function - is it really needed centrally? But as I said, maybe I'm just missing something.

Quoted 27 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the MIPI support for marvell-ccic. Board driver should determine whether using MIPI or not.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   66 +++++++++++++
 drivers/media/platform/marvell-ccic/mcam-core.h  |   28 +++++-
 drivers/media/platform/marvell-ccic/mmp-driver.c |  113 +++++++++++++++++++++-
 include/media/mmp-camera.h                       |   10 ++
 4 files changed, 214 insertions(+), 3 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +1 -0
index 7012913f..7e178d8 100755
@@ -19,6 +19,7 @@
 #include <linux/delay.h>
 #include <linux/vmalloc.h>
 #include <linux/io.h>
+#include <linux/clk.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 259

Quoted 6 lines
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
@@ -253,6 +254,39 @@ static void mcam_ctlr_stop(struct mcam_camera *cam)
 	mcam_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
 }
 
+static int mcam_config_mipi(struct mcam_camera *mcam, int enable)
+{
+	if (mcam->bus_type == V4L2_MBUS_CSI2 && enable) {

This function is only called twice in the code: both times with a const "enable" - once 1 and once 0. But you also do a disable, if the parallel bus is used. Wouldn't it look prettier as

+static int mcam_config_mipi(struct mcam_camera *mcam, bool enable) +{
+ if (enable) {

And then see the change below.

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 268

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +9 -0
+		/* Using MIPI mode and enable MIPI */
+		cam_dbg(mcam, "camera: DPHY3=0x%x, DPHY5=0x%x, DPHY6=0x%x\n",
+			mcam->dphy[0], mcam->dphy[1], mcam->dphy[2]);
+		mcam_reg_write(mcam, REG_CSI2_DPHY3, mcam->dphy[0]);
+		mcam_reg_write(mcam, REG_CSI2_DPHY5, mcam->dphy[1]);
+		mcam_reg_write(mcam, REG_CSI2_DPHY6, mcam->dphy[2]);
+
+		if (mcam->mipi_enabled == 0) {
+			BUG_ON(mcam->lane > 4 || mcam->lane <= 0);

A recent discussion about the use of BUG* macros in the kernel indicated, that you only should BUG() the kernel, when there's really no way to continue and the system would die soon anyway. Otherwise produce an error / warning message and return an error code (if possible).

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +9 -0
+			/*
+			 * 0x41 actives 1 lane
+			 * 0x43 actives 2 lanes
+			 * 0x45 actives 3 lanes (never happen)
+			 * 0x47 actives 4 lanes
+			 */
+			mcam_reg_write(mcam, REG_CSI2_CTRL0,
+				CSI2_C0_MIPI_EN | CSI2_C0_ACT_LANE(mcam->lane));
+			mcam->mipi_enabled = 1;

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 287

Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +10 -0
+		}
+	} else {
+		/* Using Parallel mode or disable MIPI */
+		mcam_reg_write(mcam, REG_CSI2_CTRL0, 0x0);
+		mcam_reg_write(mcam, REG_CSI2_DPHY3, 0x0);
+		mcam_reg_write(mcam, REG_CSI2_DPHY5, 0x0);
+		mcam_reg_write(mcam, REG_CSI2_DPHY6, 0x0);
+		mcam->mipi_enabled = 0;
+	}
+	return 0;

If you convert the above BUG() to a failure, then you need this return value, in this version this function never fails.

Quoted 21 lines
drivers/media/platform/marvell-ccic/mcam-core.c +9 -0
+}
+
 /* ------------------------------------------------------------------- */
 
 #ifdef MCAM_MODE_VMALLOC
@@ -656,6 +690,13 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
 	 */
 	mcam_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC,
 			C0_SIFM_MASK);
+
+	/*
+	 * This field controls the generation of EOF(DVP only)
+	 */
+	if (cam->bus_type != V4L2_MBUS_CSI2)
+		mcam_reg_set_bit(cam, REG_CTRL0,
+				C0_EOF_VSYNC | C0_VEDGE_CTRL);
 }
 
 
@@ -886,6 +927,16 @@ static int mcam_read_setup(struct mcam_camera *cam)
 	spin_lock_irqsave(&cam->dev_lock, flags);

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_read_setup(struct mcam_camera *cam) · line 937

Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +8 -0
 	clear_bit(CF_DMA_ACTIVE, &cam->flags);
 	mcam_reset_buffers(cam);
+	/*
+	 * Update CSI2_DPHY value
+	 */
+	if (cam->calc_dphy)
+		cam->calc_dphy(cam);
+	cam_dbg(cam, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x\n",
+			cam->dphy[0], cam->dphy[1], cam->dphy[2]);
+	ret = mcam_config_mipi(cam, 1);

Then here you do

+ ret = mcam_config_mipi(cam, cam->bus_type == V4L2_MBUS_CSI2);

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_v4l_open(struct file *filp) · line 1607

Quoted 12 lines
drivers/media/platform/marvell-ccic/mcam-core.c +5 -0
+	if (ret < 0)
+		return ret;
 	mcam_ctlr_irq_enable(cam);
 	cam->state = S_STREAMING;
 	if (!test_bit(CF_SG_RESTART, &cam->flags))
@@ -1551,6 +1602,16 @@ static int mcam_v4l_open(struct file *filp)
 		mcam_set_config_needed(cam, 1);
 	}
 	(cam->users)++;
+	if (cam->bus_type == V4L2_MBUS_CSI2) {
+		cam->pll1 = devm_clk_get(cam->dev, "pll1");
+		if (IS_ERR_OR_NULL(cam->pll1) && cam->dphy[2] == 0) {

So, is CSI2 mode only supported with enabled CONFIG_HAVE_CLK? It looks a bit susppicious, but, I think, this might be valid here - you really need a clock, from which you can read a valid rate to use CSI2, right? Otherwise you cannot configure dphy.

Quoted 11 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+			cam_err(cam, "Could not get pll1 clock\n");
+			if (IS_ERR(cam->pll1))
+				ret = PTR_ERR(cam->pll1);
+			else
+				ret = -EINVAL;
+		}
+	}
 out:
 	mutex_unlock(&cam->s_mutex);
 	return ret;

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_v4l_release(struct file *filp) · line 1633

Quoted 4 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -0
@@ -1569,10 +1630,15 @@ static int mcam_v4l_release(struct file *filp)
 	if (cam->users == 0) {
 		mcam_ctlr_stop_dma(cam);
 		mcam_cleanup_vb2(cam);
+		mcam_config_mipi(cam, 0);

and use a boolean value here

+ mcam_config_mipi(cam, false);

Quoted 88 lines
drivers/media/platform/marvell-ccic/mcam-core.c +4 -0
 		mcam_ctlr_power_down(cam);
 		if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read)
 			mcam_free_dma_bufs(cam);
 	}
+	if (cam->bus_type == V4L2_MBUS_CSI2) {
+		devm_clk_put(cam->dev, cam->pll1);
+		cam->pll1 = NULL;
+	}
 	mutex_unlock(&cam->s_mutex);
 	return 0;
 }
drivers/media/platform/marvell-ccic/mcam-core.h +26 -2
index 5e802c6..f73a801 100755
@@ -101,11 +101,21 @@ struct mcam_camera {
 	short int clock_speed;	/* Sensor clock speed, default 30 */
 	short int use_smbus;	/* SMBUS or straight I2c? */
 	enum mcam_buffer_mode buffer_mode;
+
+	enum v4l2_mbus_type bus_type;
+	/* MIPI support */
+	int *dphy;
+	int mipi_enabled;
+	int lane;			/* lane number */
+
+	struct clk *pll1;
+
 	/*
 	 * Callbacks from the core to the platform code.
 	 */
 	void (*plat_power_up) (struct mcam_camera *cam);
 	void (*plat_power_down) (struct mcam_camera *cam);
+	void (*calc_dphy) (struct mcam_camera *cam);
 
 	/*
 	 * Everything below here is private to the mcam core and
@@ -218,6 +228,17 @@ int mccic_resume(struct mcam_camera *cam);
 #define REG_Y0BAR	0x00
 #define REG_Y1BAR	0x04
 #define REG_Y2BAR	0x08
+
+/*
+ * register definitions for MIPI support
+ */
+#define REG_CSI2_CTRL0	0x100
+#define   CSI2_C0_MIPI_EN (0x1 << 0)
+#define   CSI2_C0_ACT_LANE(n) ((n-1) << 1)
+#define REG_CSI2_DPHY3	0x12c
+#define REG_CSI2_DPHY5	0x134
+#define REG_CSI2_DPHY6	0x138
+
 /* ... */
 
 #define REG_IMGPITCH	0x24	/* Image pitch register */
@@ -286,13 +307,16 @@ int mccic_resume(struct mcam_camera *cam);
 #define	  C0_YUVE_XUVY	  0x00020000	/* 420: .UVY		*/
 #define	  C0_YUVE_XVUY	  0x00030000	/* 420: .VUY		*/
 /* Bayer bits 18,19 if needed */
+#define	  C0_EOF_VSYNC	  0x00400000	/* Generate EOF by VSYNC */
+#define	  C0_VEDGE_CTRL   0x00800000	/* Detect falling edge of VSYNC */
 #define	  C0_HPOL_LOW	  0x01000000	/* HSYNC polarity active low */
 #define	  C0_VPOL_LOW	  0x02000000	/* VSYNC polarity active low */
 #define	  C0_VCLK_LOW	  0x04000000	/* VCLK on falling edge */
 #define	  C0_DOWNSCALE	  0x08000000	/* Enable downscaler */
-#define	  C0_SIFM_MASK	  0xc0000000	/* SIF mode bits */
+/* SIFMODE */
 #define	  C0_SIF_HVSYNC	  0x00000000	/* Use H/VSYNC */
-#define	  CO_SOF_NOSYNC	  0x40000000	/* Use inband active signaling */
+#define	  C0_SOF_NOSYNC	  0x40000000	/* Use inband active signaling */
+#define	  C0_SIFM_MASK	  0xc0000000	/* SIF mode bits */
 
 /* Bits below C1_444ALPHA are not present in Cafe */
 #define REG_CTRL1	0x40	/* Control 1 */
drivers/media/platform/marvell-ccic/mmp-driver.c +1 -0
index c4c17fe..7ab01e9 100755
@@ -27,6 +27,7 @@
 #include <linux/delay.h>
 #include <linux/list.h>
 #include <linux/pm.h>
+#include <linux/clk.h>
 
 #include "mcam-core.h"
 
@@ -152,6 +153,103 @@ static void mmpcam_power_down(struct mcam_camera *mcam)
 	gpio_set_value(pdata->sensor_reset_gpio, 0);

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 163

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +8 -0
 }
 
+/*
+ * calc the dphy register values
+ * There are three dphy registers being used.
+ * dphy[0] - CSI2_DPHY3
+ * dphy[1] - CSI2_DPHY5
+ * dphy[2] - CSI2_DPHY6
+ * CSI2_DPHY3 and CSI2_DPHY6 can be set with a default value
+ * or be calculated dynamically

Do you really support static dphy[*] valus? You'd recalculate them every time this function is called?

Quoted 28 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +28 -0
+ */
+void mmpcam_calc_dphy(struct mcam_camera *mcam)
+{
+	struct mmp_camera *cam = mcam_to_cam(mcam);
+	struct mmp_camera_platform_data *pdata = cam->pdev->dev.platform_data;
+	struct device *dev = &cam->pdev->dev;
+	unsigned long tx_clk_esc;
+
+	/*
+	 * If CSI2_DPHY3 is calculated dynamically,
+	 * pdata->lane_clk should be already set
+	 * either in the board driver statically
+	 * or in the sensor driver dynamically.
+	 */
+	/*
+	 * dphy[0] - CSI2_DPHY3:
+	 *  bit 0 ~ bit 7: HS Term Enable.
+	 *   defines the time that the DPHY
+	 *   wait before enabling the data
+	 *   lane termination after detecting
+	 *   that the sensor has driven the data
+	 *   lanes to the LP00 bridge state.
+	 *   The value is calculated by:
+	 *   (Max T(D_TERM_EN)/Period(DDR)) - 1
+	 *  bit 8 ~ bit 15: HS_SETTLE
+	 *   Time interval during which the HS
+	 *   receiver shall ignore any Data Lane
+	 *   HS transistions.

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 201

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +10 -0
+	 *   The vaule has been calibrated on
+	 *   different boards. It seems to work well.
+	 *
+	 *  More detail please refer
+	 *  MIPI Alliance Spectification for D-PHY
+	 *  document for explanation of HS-SETTLE
+	 *  and D-TERM-EN.
+	 */
+	switch (pdata->dphy3_algo) {
+	case 1:

These values are purely software, thy have no direct analogs in hardware, right? I.e. you cannot read them from a register and you don't have to write them to one. Then, I think, you really want to use macros for them.

Quoted 20 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +20 -0
+		/*
+		 * dphy3_algo == 1
+		 * Calculate CSI2_DPHY3 algo for PXA910
+		 */
+		pdata->dphy[0] = ((1 + pdata->lane_clk * 80 / 1000) & 0xff) << 8
+			| (1 + pdata->lane_clk * 35 / 1000);
+		break;
+	case 2:
+		/*
+		 * dphy3_algo == 2
+		 * Calculate CSI2_DPHY3 algo for PXA2128
+		 */
+		pdata->dphy[0] =
+			((2 + pdata->lane_clk * 110 / 1000) & 0xff) << 8
+			| (1 + pdata->lane_clk * 35 / 1000);
+		break;
+	default:
+		/*
+		 * dphy3_algo == 0
+		 * Use default CSI2_DPHY3 value for PXA688/PXA988

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 231

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +10 -0
+		 */
+		dev_dbg(dev, "camera: use the default CSI2_DPHY3 value\n");
+	}
+
+	/*
+	 * pll1 will never be changed, it is a fixed value
+	 */
+
+	if (IS_ERR_OR_NULL(mcam->pll1))
+		return;

All this function does is calculate dphy[] array values, right? And these values are only used if CSI2 is activated. And CSI2 can only be activated if an open() has been successful. And you only succeed a CSI2-mode open() if a clock can be acquired. So, the above check is redundant?

Quoted 72 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +35 -1
+
+	/* get the escape clk, this is hard coded */
+	tx_clk_esc = (clk_get_rate(mcam->pll1) / 1000000) / 12;
+
+	/*
+	 * dphy[2] - CSI2_DPHY6:
+	 * bit 0 ~ bit 7: CK Term Enable
+	 *  Time for the Clock Lane receiver to enable the HS line
+	 *  termination. The value is calculated similarly with
+	 *  HS Term Enable
+	 * bit 8 ~ bit 15: CK Settle
+	 *  Time interval during which the HS receiver shall ignore
+	 *  any Clock Lane HS transitions.
+	 *  The value is calibrated on the boards.
+	 */
+	pdata->dphy[2] = ((534 * tx_clk_esc / 2000 - 1) & 0xff) << 8
+			| ((38 * tx_clk_esc / 1000 - 1) & 0xff);
+
+	dev_dbg(dev, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x\n",
+		pdata->dphy[0], pdata->dphy[1], pdata->dphy[2]);
+}
 
 static irqreturn_t mmpcam_irq(int irq, void *data)
 {
@@ -174,6 +272,10 @@ static int mmpcam_probe(struct platform_device *pdev)
 	struct mmp_camera_platform_data *pdata;
 	int ret;
 
+	pdata = pdev->dev.platform_data;
+	if (!pdata)
+		return -ENODEV;
+
 	cam = kzalloc(sizeof(*cam), GFP_KERNEL);
 	if (cam == NULL)
 		return -ENOMEM;
@@ -183,8 +285,18 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam = &cam->mcam;
 	mcam->plat_power_up = mmpcam_power_up;
 	mcam->plat_power_down = mmpcam_power_down;
+	mcam->calc_dphy = mmpcam_calc_dphy;
 	mcam->dev = &pdev->dev;
 	mcam->use_smbus = 0;
+	mcam->bus_type = pdata->bus_type;
+	mcam->dphy = pdata->dphy;
+	/* mosetly it won't happen. dphy is an array in pdata, but in case .. */
+	if (unlikely(mcam->dphy == NULL)) {
+		ret = -EINVAL;
+		goto out_free;
+	}
+	mcam->mipi_enabled = 0;
+	mcam->lane = pdata->lane;
 	mcam->chip_id = V4L2_IDENT_ARMADA610;
 	mcam->buffer_mode = B_DMA_sg;
 	spin_lock_init(&mcam->dev_lock);
@@ -223,7 +335,6 @@ static int mmpcam_probe(struct platform_device *pdev)
 	 * Find the i2c adapter.  This assumes, of course, that the
 	 * i2c bus is already up and functioning.
 	 */
-	pdata = pdev->dev.platform_data;
 	mcam->i2c_adapter = platform_get_drvdata(pdata->i2c_device);
 	if (mcam->i2c_adapter == NULL) {
 		ret = -ENODEV;
include/media/mmp-camera.h +1 -0
index 7611963..813efe2 100755
@@ -1,3 +1,4 @@
+#include <media/v4l2-mediabus.h>
 /*
  * Information for the Marvell Armada MMP camera
  */

include/media/mmp-camera.h struct mmp_camera_platform_data { · line 15

Quoted 9 lines
include/media/mmp-camera.h +6 -0
@@ -6,4 +7,13 @@ struct mmp_camera_platform_data {
 	struct platform_device *i2c_device;
 	int sensor_power_gpio;
 	int sensor_reset_gpio;
+	enum v4l2_mbus_type bus_type;
+	/*
+	 * MIPI support
+	 */
+	int dphy[3];		/* DPHY: CSI2_DPHY3, CSI2_DPHY5, CSI2_DPHY6 */
+	int dphy3_algo;		/* Exist 2 algos for calculate CSI2_DPHY3 */

I'd make the above an enum

include/media/mmp-camera.h struct mmp_camera_platform_data { · line 16

Quoted 1 line
include/media/mmp-camera.h +1 -0
+	int mipi_enabled;	/* MIPI enabled flag */

And this one a bool

Quoted 6 lines
include/media/mmp-camera.h +2 -0
+	int lane;		/* ccic used lane number; 0 means DVP mode */
+	int lane_clk;
 };
Signature · 1 line
1.7.9.5

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#3 lore raw

RE: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi, Guennadi

Thank you very much for your review and comments!

Quoted 63 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 05:35
To: Albert Wang
Cc: [email protected]; Linux Media Mailing List; Libin Yang
Subject: Re: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Albert

A general comment first: I have no idea about this hardware, so, feel free to ignore all my hardware-handling related comments. But just from looking your handling of the pll1 clock does seem a bit fishy to me. You acquire and release the clock in the generic mcam code, but only use it in the mmp driver. Is it really needed centrally? Wouldn't it suffice to only acquire it in mmp? Same goes for your mcam_config_mipi() function - is it really needed centrally? But as I said, maybe I'm just missing something.

Quoted 7 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the MIPI support for marvell-ccic. Board driver should determine whether using MIPI or not.

Review

Quoted 8 lines
---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   66 +++++++++++++
 drivers/media/platform/marvell-ccic/mcam-core.h  |   28 +++++-
 drivers/media/platform/marvell-ccic/mmp-driver.c |  113 +++++++++++++++++++++-
 include/media/mmp-camera.h                       |   10 ++
 4 files changed, 214 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.c

Quoted 12 lines

index 7012913f..7e178d8 100755

drivers/media/platform/marvell-ccic/mcam-core.c +1 -0
@@ -19,6 +19,7 @@
 #include <linux/delay.h>
 #include <linux/vmalloc.h>
 #include <linux/io.h>
+#include <linux/clk.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 259

Quoted 6 lines
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
@@ -253,6 +254,39 @@ static void mcam_ctlr_stop(struct mcam_camera *cam)
     mcam_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
 }
 
+static int mcam_config_mipi(struct mcam_camera *mcam, int enable)
+{
+    if (mcam->bus_type == V4L2_MBUS_CSI2 && enable) {

This function is only called twice in the code: both times with a const "enable" - once 1 and once 0. But you also do a disable, if the parallel bus is used. Wouldn't it look prettier as

(quoted diff) +3 -0
+static int mcam_config_mipi(struct mcam_camera *mcam, bool enable)
+{
+      if (enable) {
Quoted 2 lines

And then see the change below.

OK, we can think about it.

Quoted 11 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 261

Quoted 2 lines
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
+            /* Using MIPI mode and enable MIPI */
+            cam_dbg(mcam, "camera: DPHY3=0x%x, DPHY5=0x%x,

DPHY6=0x%x\n",

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 268

Quoted 7 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+                    mcam->dphy[0], mcam->dphy[1], mcam->dphy[2]);
+            mcam_reg_write(mcam, REG_CSI2_DPHY3, mcam->dphy[0]);
+            mcam_reg_write(mcam, REG_CSI2_DPHY5, mcam->dphy[1]);
+            mcam_reg_write(mcam, REG_CSI2_DPHY6, mcam->dphy[2]);
+
+            if (mcam->mipi_enabled == 0) {
+                    BUG_ON(mcam->lane > 4 || mcam->lane <= 0);
Quoted 5 lines

A recent discussion about the use of BUG* macros in the kernel indicated, that you only should BUG() the kernel, when there's really no way to continue and the system would die soon anyway. Otherwise produce an error / warning message and return an error code (if possible).

Yes, you are right, we will change it.

Quoted 69 lines
Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +9 -0
+                    /*
+                     * 0x41 actives 1 lane
+                     * 0x43 actives 2 lanes
+                     * 0x45 actives 3 lanes (never happen)
+                     * 0x47 actives 4 lanes
+                     */
+                    mcam_reg_write(mcam, REG_CSI2_CTRL0,
+                            CSI2_C0_MIPI_EN | CSI2_C0_ACT_LANE(mcam->lane));
+                    mcam->mipi_enabled = 1;

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_stop(struct mcam_camera *cam) · line 287

Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +10 -0
+            }
+    } else {
+            /* Using Parallel mode or disable MIPI */
+            mcam_reg_write(mcam, REG_CSI2_CTRL0, 0x0);
+            mcam_reg_write(mcam, REG_CSI2_DPHY3, 0x0);
+            mcam_reg_write(mcam, REG_CSI2_DPHY5, 0x0);
+            mcam_reg_write(mcam, REG_CSI2_DPHY6, 0x0);
+            mcam->mipi_enabled = 0;
+    }
+    return 0;

If you convert the above BUG() to a failure, then you need this return value, in this version this function never fails.

Quoted 20 lines
drivers/media/platform/marvell-ccic/mcam-core.c +9 -0
+}
+
 /* ------------------------------------------------------------------- */
 
 #ifdef MCAM_MODE_VMALLOC
@@ -656,6 +690,13 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
      */
     mcam_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC,
                     C0_SIFM_MASK);
+
+    /*
+     * This field controls the generation of EOF(DVP only)
+     */
+    if (cam->bus_type != V4L2_MBUS_CSI2)
+            mcam_reg_set_bit(cam, REG_CTRL0,
+                            C0_EOF_VSYNC | C0_VEDGE_CTRL);
 }
 
 

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_read_setup(struct mcam_camera *cam) · line 935

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +6 -0
@@ -886,6 +927,16 @@ static int mcam_read_setup(struct mcam_camera *cam)
     spin_lock_irqsave(&cam->dev_lock, flags);
     clear_bit(CF_DMA_ACTIVE, &cam->flags);
     mcam_reset_buffers(cam);
+    /*
+     * Update CSI2_DPHY value
+     */
+    if (cam->calc_dphy)
+            cam->calc_dphy(cam);
+    cam_dbg(cam, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x,

dphy6=0x%x\n",

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_read_setup(struct mcam_camera *cam) · line 937

Quoted 2 lines
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
+                    cam->dphy[0], cam->dphy[1], cam->dphy[2]);
+    ret = mcam_config_mipi(cam, 1);

Then here you do

+ ret = mcam_config_mipi(cam, cam->bus_type == V4L2_MBUS_CSI2);

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
+    if (ret < 0)
+            return ret;
     mcam_ctlr_irq_enable(cam);
     cam->state = S_STREAMING;
     if (!test_bit(CF_SG_RESTART, &cam->flags))
@@ -1551,6 +1602,16 @@ static int mcam_v4l_open(struct file *filp)
             mcam_set_config_needed(cam, 1);
     }
     (cam->users)++;
Quoted 9 lines

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_v4l_open(struct file *filp) · line 1607

Quoted 3 lines
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
+    if (cam->bus_type == V4L2_MBUS_CSI2) {
+            cam->pll1 = devm_clk_get(cam->dev, "pll1");
+            if (IS_ERR_OR_NULL(cam->pll1) && cam->dphy[2] == 0) {

So, is CSI2 mode only supported with enabled CONFIG_HAVE_CLK? It looks a bit susppicious, but, I think, this might be valid here - you really need a clock, from which you can read a valid rate to use CSI2, right? Otherwise you cannot configure dphy.

Yes.

Quoted 123 lines
Quoted 11 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+                    cam_err(cam, "Could not get pll1 clock\n");
+                    if (IS_ERR(cam->pll1))
+                            ret = PTR_ERR(cam->pll1);
+                    else
+                            ret = -EINVAL;
+            }
+    }
 out:
     mutex_unlock(&cam->s_mutex);
     return ret;

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_v4l_release(struct file *filp) · line 1633

Quoted 4 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -0
@@ -1569,10 +1630,15 @@ static int mcam_v4l_release(struct file *filp)
     if (cam->users == 0) {
             mcam_ctlr_stop_dma(cam);
             mcam_cleanup_vb2(cam);
+            mcam_config_mipi(cam, 0);

and use a boolean value here

+ mcam_config_mipi(cam, false);

Review

Quoted 12 lines
drivers/media/platform/marvell-ccic/mcam-core.c +4 -0
             mcam_ctlr_power_down(cam);
             if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read)
                     mcam_free_dma_bufs(cam);
     }
+    if (cam->bus_type == V4L2_MBUS_CSI2) {
+            devm_clk_put(cam->dev, cam->pll1);
+            cam->pll1 = NULL;
+    }
     mutex_unlock(&cam->s_mutex);
     return 0;
 }
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.h

Quoted 44 lines

index 5e802c6..f73a801 100755

drivers/media/platform/marvell-ccic/mcam-core.h +21 -0
@@ -101,11 +101,21 @@ struct mcam_camera {
     short int clock_speed;  /* Sensor clock speed, default 30 */
     short int use_smbus;    /* SMBUS or straight I2c? */
     enum mcam_buffer_mode buffer_mode;
+
+    enum v4l2_mbus_type bus_type;
+    /* MIPI support */
+    int *dphy;
+    int mipi_enabled;
+    int lane;                       /* lane number */
+
+    struct clk *pll1;
+
     /*
      * Callbacks from the core to the platform code.
      */
     void (*plat_power_up) (struct mcam_camera *cam);
     void (*plat_power_down) (struct mcam_camera *cam);
+    void (*calc_dphy) (struct mcam_camera *cam);
 
     /*
      * Everything below here is private to the mcam core and
@@ -218,6 +228,17 @@ int mccic_resume(struct mcam_camera *cam);
 #define REG_Y0BAR   0x00
 #define REG_Y1BAR   0x04
 #define REG_Y2BAR   0x08
+
+/*
+ * register definitions for MIPI support
+ */
+#define REG_CSI2_CTRL0      0x100
+#define   CSI2_C0_MIPI_EN (0x1 << 0)
+#define   CSI2_C0_ACT_LANE(n) ((n-1) << 1)
+#define REG_CSI2_DPHY3      0x12c
+#define REG_CSI2_DPHY5      0x134
+#define REG_CSI2_DPHY6      0x138
+
 /* ... */
 
 #define REG_IMGPITCH        0x24    /* Image pitch register */

drivers/media/platform/marvell-ccic/mcam-core.h int mccic_resume(struct mcam_camera *cam); · line 311

Quoted 5 lines
drivers/media/platform/marvell-ccic/mcam-core.h +2 -0
@@ -286,13 +307,16 @@ int mccic_resume(struct mcam_camera *cam);
 #define       C0_YUVE_XUVY    0x00020000    /* 420: .UVY            */
 #define       C0_YUVE_XVUY    0x00030000    /* 420: .VUY            */
 /* Bayer bits 18,19 if needed */
+#define       C0_EOF_VSYNC    0x00400000    /* Generate EOF by VSYNC */
+#define       C0_VEDGE_CTRL   0x00800000    /* Detect falling edge of

VSYNC */

Review

Quoted 14 lines
drivers/media/platform/marvell-ccic/mcam-core.h +3 -2
 #define       C0_HPOL_LOW     0x01000000    /* HSYNC polarity active low */
 #define       C0_VPOL_LOW     0x02000000    /* VSYNC polarity active low */
 #define       C0_VCLK_LOW     0x04000000    /* VCLK on falling edge */
 #define       C0_DOWNSCALE    0x08000000    /* Enable downscaler */
-#define       C0_SIFM_MASK    0xc0000000    /* SIF mode bits */
+/* SIFMODE */
 #define       C0_SIF_HVSYNC   0x00000000    /* Use H/VSYNC */
-#define       CO_SOF_NOSYNC   0x40000000    /* Use inband active signaling */
+#define       C0_SOF_NOSYNC   0x40000000    /* Use inband active signaling */
+#define       C0_SIFM_MASK    0xc0000000    /* SIF mode bits */
 
 /* Bits below C1_444ALPHA are not present in Cafe */
 #define REG_CTRL1   0x40    /* Control 1 */
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mmp-driver.c

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera

Quoted 12 lines

index c4c17fe..7ab01e9 100755

drivers/media/platform/marvell-ccic/mmp-driver.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/delay.h>
 #include <linux/list.h>
 #include <linux/pm.h>
+#include <linux/clk.h>
 
 #include "mcam-core.h"
 
@@ -152,6 +153,103 @@ static void mmpcam_power_down(struct mcam_camera

*mcam)

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 163

Quoted 11 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +8 -0
     gpio_set_value(pdata->sensor_reset_gpio, 0);
 }
 
+/*
+ * calc the dphy register values
+ * There are three dphy registers being used.
+ * dphy[0] - CSI2_DPHY3
+ * dphy[1] - CSI2_DPHY5
+ * dphy[2] - CSI2_DPHY6
+ * CSI2_DPHY3 and CSI2_DPHY6 can be set with a default value
+ * or be calculated dynamically
Quoted 3 lines

Do you really support static dphy[*] valus? You'd recalculate them every time this function is called?

It looks that's our fault.

Quoted 34 lines
Quoted 34 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +34 -0
+ */
+void mmpcam_calc_dphy(struct mcam_camera *mcam)
+{
+    struct mmp_camera *cam = mcam_to_cam(mcam);
+    struct mmp_camera_platform_data *pdata = cam->pdev->dev.platform_data;
+    struct device *dev = &cam->pdev->dev;
+    unsigned long tx_clk_esc;
+
+    /*
+     * If CSI2_DPHY3 is calculated dynamically,
+     * pdata->lane_clk should be already set
+     * either in the board driver statically
+     * or in the sensor driver dynamically.
+     */
+    /*
+     * dphy[0] - CSI2_DPHY3:
+     *  bit 0 ~ bit 7: HS Term Enable.
+     *   defines the time that the DPHY
+     *   wait before enabling the data
+     *   lane termination after detecting
+     *   that the sensor has driven the data
+     *   lanes to the LP00 bridge state.
+     *   The value is calculated by:
+     *   (Max T(D_TERM_EN)/Period(DDR)) - 1
+     *  bit 8 ~ bit 15: HS_SETTLE
+     *   Time interval during which the HS
+     *   receiver shall ignore any Data Lane
+     *   HS transistions.
+     *   The vaule has been calibrated on
+     *   different boards. It seems to work well.
+     *
+     *  More detail please refer
+     *  MIPI Alliance Spectification for D-PHY
+     *  document for explanation of HS-SETTLE
Quoted 9 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 201

Quoted 4 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +4 -0
+     *  and D-TERM-EN.
+     */
+    switch (pdata->dphy3_algo) {
+    case 1:

These values are purely software, thy have no direct analogs in hardware, right? I.e. you cannot read them from a register and you don't have to write them to one. Then, I think, you really want to use macros for them.

Yes, your suggestion is reasonable.

Quoted 27 lines
Quoted 27 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +27 -0
+            /*
+             * dphy3_algo == 1
+             * Calculate CSI2_DPHY3 algo for PXA910
+             */
+            pdata->dphy[0] = ((1 + pdata->lane_clk * 80 / 1000) & 0xff) << 8
+                    | (1 + pdata->lane_clk * 35 / 1000);
+            break;
+    case 2:
+            /*
+             * dphy3_algo == 2
+             * Calculate CSI2_DPHY3 algo for PXA2128
+             */
+            pdata->dphy[0] =
+                    ((2 + pdata->lane_clk * 110 / 1000) & 0xff) << 8
+                    | (1 + pdata->lane_clk * 35 / 1000);
+            break;
+    default:
+            /*
+             * dphy3_algo == 0
+             * Use default CSI2_DPHY3 value for PXA688/PXA988
+             */
+            dev_dbg(dev, "camera: use the default CSI2_DPHY3 value\n");
+    }
+
+    /*
+     * pll1 will never be changed, it is a fixed value
+     */
Quoted 9 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 231

Quoted 3 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +3 -0
+
+    if (IS_ERR_OR_NULL(mcam->pll1))
+            return;

All this function does is calculate dphy[] array values, right? And these values are only used if CSI2 is activated. And CSI2 can only be activated if an open() has been successful. And you only succeed a CSI2-mode open() if a clock can be acquired. So, the above check is redundant?

Yes.

Quoted 85 lines
Quoted 9 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +9 -0
+
+    /* get the escape clk, this is hard coded */
+    tx_clk_esc = (clk_get_rate(mcam->pll1) / 1000000) / 12;
+
+    /*
+     * dphy[2] - CSI2_DPHY6:
+     * bit 0 ~ bit 7: CK Term Enable
+     *  Time for the Clock Lane receiver to enable the HS line
+     *  termination. The value is calculated similarly with

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam)

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +10 -0
+     *  HS Term Enable
+     * bit 8 ~ bit 15: CK Settle
+     *  Time interval during which the HS receiver shall ignore
+     *  any Clock Lane HS transitions.
+     *  The value is calibrated on the boards.
+     */
+    pdata->dphy[2] = ((534 * tx_clk_esc / 2000 - 1) & 0xff) << 8
+                    | ((38 * tx_clk_esc / 1000 - 1) & 0xff);
+
+    dev_dbg(dev, "camera: DPHY sets: dphy3=0x%x, dphy5=0x%x,

dphy6=0x%x\n",

Quoted 53 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +16 -1
+            pdata->dphy[0], pdata->dphy[1], pdata->dphy[2]);
+}
 
 static irqreturn_t mmpcam_irq(int irq, void *data)
 {
@@ -174,6 +272,10 @@ static int mmpcam_probe(struct platform_device *pdev)
     struct mmp_camera_platform_data *pdata;
     int ret;
 
+    pdata = pdev->dev.platform_data;
+    if (!pdata)
+            return -ENODEV;
+
     cam = kzalloc(sizeof(*cam), GFP_KERNEL);
     if (cam == NULL)
             return -ENOMEM;
@@ -183,8 +285,18 @@ static int mmpcam_probe(struct platform_device *pdev)
     mcam = &cam->mcam;
     mcam->plat_power_up = mmpcam_power_up;
     mcam->plat_power_down = mmpcam_power_down;
+    mcam->calc_dphy = mmpcam_calc_dphy;
     mcam->dev = &pdev->dev;
     mcam->use_smbus = 0;
+    mcam->bus_type = pdata->bus_type;
+    mcam->dphy = pdata->dphy;
+    /* mosetly it won't happen. dphy is an array in pdata, but in case .. */
+    if (unlikely(mcam->dphy == NULL)) {
+            ret = -EINVAL;
+            goto out_free;
+    }
+    mcam->mipi_enabled = 0;
+    mcam->lane = pdata->lane;
     mcam->chip_id = V4L2_IDENT_ARMADA610;
     mcam->buffer_mode = B_DMA_sg;
     spin_lock_init(&mcam->dev_lock);
@@ -223,7 +335,6 @@ static int mmpcam_probe(struct platform_device *pdev)
      * Find the i2c adapter.  This assumes, of course, that the
      * i2c bus is already up and functioning.
      */
-    pdata = pdev->dev.platform_data;
     mcam->i2c_adapter = platform_get_drvdata(pdata->i2c_device);
     if (mcam->i2c_adapter == NULL) {
             ret = -ENODEV;
include/media/mmp-camera.h +1 -0
index 7611963..813efe2 100755
@@ -1,3 +1,4 @@
+#include <media/v4l2-mediabus.h>
 /*
  * Information for the Marvell Armada MMP camera
  */

include/media/mmp-camera.h struct mmp_camera_platform_data { · line 15

Quoted 9 lines
include/media/mmp-camera.h +6 -0
@@ -6,4 +7,13 @@ struct mmp_camera_platform_data {
     struct platform_device *i2c_device;
     int sensor_power_gpio;
     int sensor_reset_gpio;
+    enum v4l2_mbus_type bus_type;
+    /*
+     * MIPI support
+     */
+    int dphy[3];            /* DPHY: CSI2_DPHY3, CSI2_DPHY5, CSI2_DPHY6 */
+    int dphy3_algo;         /* Exist 2 algos for calculate CSI2_DPHY3 */

I'd make the above an enum

Quoted 4 lines

include/media/mmp-camera.h struct mmp_camera_platform_data { · line 16

Quoted 1 line
include/media/mmp-camera.h +1 -0
+    int mipi_enabled;       /* MIPI enabled flag */

And this one a bool

OK, we will update it.

Quoted 7 lines
Quoted 6 lines
include/media/mmp-camera.h +2 -1
+    int lane;               /* ccic used lane number; 0 means DVP mode */
+    int lane_clk;
 };
--

1.7.9.5

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#4 lore raw

RE: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

In reply to Guennadi Liakhovetski

Hi Guennadi,

Thanks for your careful review. Please help see my comments below.

Quoted 10 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, March 05, 2013 5:35 AM
To: Albert Wang
Cc: [email protected]; Linux Media Mailing List; Libin Yang
Subject: Re: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Albert

Quoted 7 lines

A general comment first: I have no idea about this hardware, so, feel free to ignore all my hardware-handling related comments. But just from looking your handling of the pll1 clock does seem a bit fishy to me. You acquire and release the clock in the generic mcam code, but only use it in the mmp driver. Is it really needed centrally? Wouldn't it suffice to only acquire it in mmp? Same goes for your mcam_config_mipi() function - is it really needed centrally? But as I said, maybe I'm just missing something.

[Libin] For the mcam_config_mipi() function, it is used to config mipi in the soc. All boards need to configure it if they are using MIPI based on Marvell CCIC. So I think this function should be in the mcam-core.

For the pll1, I think you are right. Actually, it is board based. MMP based boards are using pll1 to calculate the dphy. And I can not guarantee that all boards need pll1. It seems putting pll1 in the mmp-driver is more reasonable. But do you remember, in the previous patch review, you mentioned that it is better to keep the reference to the clock until clean up, because other components may change it. So what I design is: get pll1 and hold it in the open and release it automatically with devm (It may be better to release the pll1 when closing the camera). The problem is in mmp-driver, there is no such point to get the pll1. The open action is in the mcam-core. If I move getting pll1 to the probe function of mmp-driver and putting it in remove, it means camera driver will hold the pll1 all the time. Do you have some suggestions?

[snip]

Quoted 10 lines
Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
+	if (ret < 0)
+		return ret;
 	mcam_ctlr_irq_enable(cam);
 	cam->state = S_STREAMING;
 	if (!test_bit(CF_SG_RESTART, &cam->flags))
@@ -1551,6 +1602,16 @@ static int mcam_v4l_open(struct file *filp)
 		mcam_set_config_needed(cam, 1);
 	}
 	(cam->users)++;
Quoted 8 lines

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_v4l_open(struct file *filp) · line 1607

Quoted 3 lines
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
+	if (cam->bus_type == V4L2_MBUS_CSI2) {
+		cam->pll1 = devm_clk_get(cam->dev, "pll1");
+		if (IS_ERR_OR_NULL(cam->pll1) && cam->dphy[2] == 0) {

So, is CSI2 mode only supported with enabled CONFIG_HAVE_CLK? It looks a bit susppicious, but, I think, this might be valid here - you really need a clock, from which you can read a valid rate to use CSI2, right? Otherwise you cannot configure dphy.

[Libin] If dphy[2] is initialized, it is OK pll1 is not used. Please see the related comments below in the function mmpcam_calc_dphy()

Quoted 7 lines
Quoted 7 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +6 -0
+ */
+void mmpcam_calc_dphy(struct mcam_camera *mcam)
+{
+	struct mmp_camera *cam = mcam_to_cam(mcam);
+	struct mmp_camera_platform_data *pdata = cam->pdev->dev.platform_data;
+	struct device *dev = &cam->pdev->dev;

[snip]

Quoted 5 lines
Quoted 5 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +5 -0
+	}
+
+	/*
+	 * pll1 will never be changed, it is a fixed value
+	 */
Quoted 8 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 231

Quoted 3 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +3 -0
+
+	if (IS_ERR_OR_NULL(mcam->pll1))
+		return;

All this function does is calculate dphy[] array values, right? And these values are only used if CSI2 is activated. And CSI2 can only be activated if an open() has been successful. And you only succeed a CSI2-mode open() if a clock can be acquired. So, the above check is redundant?

[Libin] pll1 is used to calculate dphy[2]. If dphy[2] is initialized then pll1 being NULL is OK. Please see the open function. If pll1 is not NULL, then we will calculate the dphy[2] based on pll1.

Quoted 9 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 239

Quoted 9 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +8 -0
+
+	/* get the escape clk, this is hard coded */
+	tx_clk_esc = (clk_get_rate(mcam->pll1) / 1000000) / 12;
+
+	/*
+	 * dphy[2] - CSI2_DPHY6:
+	 * bit 0 ~ bit 7: CK Term Enable
+	 *  Time for the Clock Lane receiver to enable the HS line

Regards,
Libin

#5 lore raw

RE: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Libin

Quoted 26 lines · Libin Yang

Hi Guennadi,

Thanks for your careful review. Please help see my comments below.

Quoted 10 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, March 05, 2013 5:35 AM
To: Albert Wang
Cc: [email protected]; Linux Media Mailing List; Libin Yang
Subject: Re: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Albert

Quoted 7 lines

A general comment first: I have no idea about this hardware, so, feel free to ignore all my hardware-handling related comments. But just from looking your handling of the pll1 clock does seem a bit fishy to me. You acquire and release the clock in the generic mcam code, but only use it in the mmp driver. Is it really needed centrally? Wouldn't it suffice to only acquire it in mmp? Same goes for your mcam_config_mipi() function - is it really needed centrally? But as I said, maybe I'm just missing something.

[Libin] For the mcam_config_mipi() function, it is used to config mipi in the soc. All boards need to configure it if they are using MIPI based on Marvell CCIC. So I think this function should be in the mcam-core.

Quoted 13 lines

For the pll1, I think you are right. Actually, it is board based. MMP based boards are using pll1 to calculate the dphy. And I can not guarantee that all boards need pll1. It seems putting pll1 in the mmp-driver is more reasonable. But do you remember, in the previous patch review, you mentioned that it is better to keep the reference to the clock until clean up, because other components may change it. So what I design is: get pll1 and hold it in the open and release it automatically with devm (It may be better to release the pll1 when closing the camera). The problem is in mmp-driver, there is no such point to get the pll1. The open action is in the mcam-core. If I move getting pll1 to the probe function of mmp-driver and putting it in remove, it means camera driver will hold the pll1 all the time. Do you have some suggestions?

Wouldn't it be possible to acquire the clock in mmpcam_power_up() like

struct mmp_camera {
	...

+ struct clk *mipi;
};

static int mmpcam_probe(struct platform_device *pdev)

{
	...
+	cam->mipi = ERR_PTR(-EINVAL);
	...

-static void mmpcam_power_up(struct mcam_camera *mcam) +static int mmpcam_power_up(struct mcam_camera *mcam)

{
	...

+ if (mcam->bus_type == V4L2_MBUS_CSI2 && IS_ERR(cam->mipi)) {
+ cam->mipi = devm_clk_get(mcam->dev, "mipi");
+ if (IS_ERR(cam->mipi))
+ return PTR_ERR(cam->mipi);
+ }

Yes, it might be good to change the return type of .plat_power_up() to int in a separate patch first. And I think a clock name like "mipi" is better suitable here, since, as you say, not on all hardware it will be pll1.

Quoted 21 lines

[snip]

Quoted 10 lines
Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
+	if (ret < 0)
+		return ret;
 	mcam_ctlr_irq_enable(cam);
 	cam->state = S_STREAMING;
 	if (!test_bit(CF_SG_RESTART, &cam->flags))
@@ -1551,6 +1602,16 @@ static int mcam_v4l_open(struct file *filp)
 		mcam_set_config_needed(cam, 1);
 	}
 	(cam->users)++;
Quoted 8 lines

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_v4l_open(struct file *filp) · line 1607

Quoted 3 lines
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
+	if (cam->bus_type == V4L2_MBUS_CSI2) {
+		cam->pll1 = devm_clk_get(cam->dev, "pll1");
+		if (IS_ERR_OR_NULL(cam->pll1) && cam->dphy[2] == 0) {

So, is CSI2 mode only supported with enabled CONFIG_HAVE_CLK? It looks a bit susppicious, but, I think, this might be valid here - you really need a clock, from which you can read a valid rate to use CSI2, right? Otherwise you cannot configure dphy.

Quoted 2 lines

[Libin] If dphy[2] is initialized, it is OK pll1 is not used. Please see the related comments below in the function mmpcam_calc_dphy()

yes, ok, makes sense.

Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +6 -0
+ */
+void mmpcam_calc_dphy(struct mcam_camera *mcam)
+{
+	struct mmp_camera *cam = mcam_to_cam(mcam);
+	struct mmp_camera_platform_data *pdata = cam->pdev->dev.platform_data;
+	struct device *dev = &cam->pdev->dev;

[snip]

Quoted 5 lines
Quoted 5 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +5 -0
+	}
+
+	/*
+	 * pll1 will never be changed, it is a fixed value
+	 */
Quoted 8 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 231

Quoted 3 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +3 -0
+
+	if (IS_ERR_OR_NULL(mcam->pll1))
+		return;

All this function does is calculate dphy[] array values, right? And these values are only used if CSI2 is activated. And CSI2 can only be activated if an open() has been successful. And you only succeed a CSI2-mode open() if a clock can be acquired. So, the above check is redundant?

Quoted 3 lines

[Libin] pll1 is used to calculate dphy[2]. If dphy[2] is initialized then pll1 being NULL is OK. Please see the open function. If pll1 is not NULL, then we will calculate the dphy[2] based on pll1.

Ok, makes sense too.

Quoted 12 lines
Quoted 9 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera *mcam) · line 239

Quoted 9 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +8 -0
+
+	/* get the escape clk, this is hard coded */
+	tx_clk_esc = (clk_get_rate(mcam->pll1) / 1000000) / 12;
+
+	/*
+	 * dphy[2] - CSI2_DPHY6:
+	 * bit 0 ~ bit 7: CK Term Enable
+	 *  Time for the Clock Lane receiver to enable the HS line

Regards,
Libin

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#6 lore raw

RE: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Guennadi,

Quoted 61 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, March 12, 2013 6:08 PM
To: Libin Yang
Cc: Albert Wang; [email protected]; Linux Media Mailing List
Subject: RE: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi Libin

Quoted 13 lines
Quoted 8 lines

A general comment first: I have no idea about this hardware, so, feel free to ignore all my hardware-handling related comments. But just from looking your handling of the pll1 clock does seem a bit fishy to me. You acquire and release the clock in the generic mcam code, but only use it in the mmp driver. Is it really needed centrally? Wouldn't it suffice to only acquire it in mmp? Same goes for your mcam_config_mipi() function - is it really needed centrally? But as I said, maybe I'm just missing something.

[Libin] For the mcam_config_mipi() function, it is used to config mipi in the soc. All boards need to configure it if they are using MIPI based on Marvell CCIC. So I think this function should be in the mcam-core.

Quoted 13 lines

For the pll1, I think you are right. Actually, it is board based. MMP based boards are using pll1 to calculate the dphy. And I can not guarantee that all boards need pll1. It seems putting pll1 in the mmp-driver is more reasonable. But do you remember, in the previous patch review, you mentioned that it is better to keep the reference to the clock until clean up, because other components may change it. So what I design is: get pll1 and hold it in the open and release it automatically with devm (It may be better to release the pll1 when closing the camera). The problem is in mmp-driver, there is no such point to get the pll1. The open action is in the mcam-core. If I move getting pll1 to the probe function of mmp-driver and putting it in remove, it means camera driver will hold the pll1 all the time. Do you have some suggestions?

Wouldn't it be possible to acquire the clock in mmpcam_power_up() like

struct mmp_camera {
	...
(quoted diff) +1 -0
+	struct clk *mipi;

};

static int mmpcam_probe(struct platform_device *pdev)

{
	...
(quoted diff) +2 -1
+	cam->mipi = ERR_PTR(-EINVAL);
...
 
-static void mmpcam_power_up(struct mcam_camera *mcam)
+static int mmpcam_power_up(struct mcam_camera *mcam)
{
	...
(quoted diff) +5 -0
+	if (mcam->bus_type == V4L2_MBUS_CSI2 && IS_ERR(cam->mipi)) {
+		cam->mipi = devm_clk_get(mcam->dev, "mipi");
+		if (IS_ERR(cam->mipi))
+			return PTR_ERR(cam->mipi);
+	}
Quoted 3 lines

Yes, it might be good to change the return type of .plat_power_up() to int in a separate patch first. And I think a clock name like "mipi" is better suitable here, since, as you say, not on all hardware it will be pll1.

[Libin] It is reasonable to acquire the clock in mmpcam_power_up() and release it in mmpcam_power_down(). So we can get the clock when opening and put the clock when closing. Using "mipi" is a good suggestion. And I'd like to put "mipi" clock in the struct mmp_camera, as it is platform related.

Quoted 4 lines
Quoted 4 lines

[snip]

Quoted 1 line

Regards,
Libin

#7 lore raw

Re: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

In reply to Albert Wang

Oh, one more thing occurred to me after looking at your another patch:

Quoted 13 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the MIPI support for marvell-ccic. Board driver should determine whether using MIPI or not.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   66 +++++++++++++
 drivers/media/platform/marvell-ccic/mcam-core.h  |   28 +++++-
 drivers/media/platform/marvell-ccic/mmp-driver.c |  113 +++++++++++++++++++++-
 include/media/mmp-camera.h                       |   10 ++
 4 files changed, 214 insertions(+), 3 deletions(-)

[snip]

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 294

Quoted 11 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +5 -0
@@ -183,8 +285,18 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam = &cam->mcam;
 	mcam->plat_power_up = mmpcam_power_up;
 	mcam->plat_power_down = mmpcam_power_down;
+	mcam->calc_dphy = mmpcam_calc_dphy;
 	mcam->dev = &pdev->dev;
 	mcam->use_smbus = 0;
+	mcam->bus_type = pdata->bus_type;
+	mcam->dphy = pdata->dphy;
+	/* mosetly it won't happen. dphy is an array in pdata, but in case .. */
+	if (unlikely(mcam->dphy == NULL)) {

There's no such case - you did define it as an array, this will never be NULL.

Quoted 42 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +5 -1
+		ret = -EINVAL;
+		goto out_free;
+	}
+	mcam->mipi_enabled = 0;
+	mcam->lane = pdata->lane;
 	mcam->chip_id = V4L2_IDENT_ARMADA610;
 	mcam->buffer_mode = B_DMA_sg;
 	spin_lock_init(&mcam->dev_lock);
@@ -223,7 +335,6 @@ static int mmpcam_probe(struct platform_device *pdev)
 	 * Find the i2c adapter.  This assumes, of course, that the
 	 * i2c bus is already up and functioning.
 	 */
-	pdata = pdev->dev.platform_data;
 	mcam->i2c_adapter = platform_get_drvdata(pdata->i2c_device);
 	if (mcam->i2c_adapter == NULL) {
 		ret = -ENODEV;
include/media/mmp-camera.h +10 -0
index 7611963..813efe2 100755
@@ -1,3 +1,4 @@
+#include <media/v4l2-mediabus.h>
 /*
  * Information for the Marvell Armada MMP camera
  */
@@ -6,4 +7,13 @@ struct mmp_camera_platform_data {
 	struct platform_device *i2c_device;
 	int sensor_power_gpio;
 	int sensor_reset_gpio;
+	enum v4l2_mbus_type bus_type;
+	/*
+	 * MIPI support
+	 */
+	int dphy[3];		/* DPHY: CSI2_DPHY3, CSI2_DPHY5, CSI2_DPHY6 */
+	int dphy3_algo;		/* Exist 2 algos for calculate CSI2_DPHY3 */
+	int mipi_enabled;	/* MIPI enabled flag */
+	int lane;		/* ccic used lane number; 0 means DVP mode */
+	int lane_clk;
 };
Signature · 1 line
1.7.9.5

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#8 lore raw

RE: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Hi, Guennadi

Quoted 28 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 18:21
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 01/12] [media] marvell-ccic: add MIPI support for marvell-ccic driver

Oh, one more thing occurred to me after looking at your another patch:

Quoted 13 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the MIPI support for marvell-ccic. Board driver should determine whether using MIPI or not.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   66 +++++++++++++
 drivers/media/platform/marvell-ccic/mcam-core.h  |   28 +++++-
 drivers/media/platform/marvell-ccic/mmp-driver.c |  113 +++++++++++++++++++++-
 include/media/mmp-camera.h                       |   10 ++
 4 files changed, 214 insertions(+), 3 deletions(-)

[snip]

Quoted 15 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 294

Quoted 11 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +5 -0
@@ -183,8 +285,18 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam = &cam->mcam;
 	mcam->plat_power_up = mmpcam_power_up;
 	mcam->plat_power_down = mmpcam_power_down;
+	mcam->calc_dphy = mmpcam_calc_dphy;
 	mcam->dev = &pdev->dev;
 	mcam->use_smbus = 0;
+	mcam->bus_type = pdata->bus_type;
+	mcam->dphy = pdata->dphy;
+	/* mosetly it won't happen. dphy is an array in pdata, but in case .. */
+	if (unlikely(mcam->dphy == NULL)) {

There's no such case - you did define it as an array, this will never be NULL.

Yes, we will change it.

Quoted 41 lines
Quoted 41 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +5 -1
+		ret = -EINVAL;
+		goto out_free;
+	}
+	mcam->mipi_enabled = 0;
+	mcam->lane = pdata->lane;
 	mcam->chip_id = V4L2_IDENT_ARMADA610;
 	mcam->buffer_mode = B_DMA_sg;
 	spin_lock_init(&mcam->dev_lock);
@@ -223,7 +335,6 @@ static int mmpcam_probe(struct platform_device *pdev)
 	 * Find the i2c adapter.  This assumes, of course, that the
 	 * i2c bus is already up and functioning.
 	 */
-	pdata = pdev->dev.platform_data;
 	mcam->i2c_adapter = platform_get_drvdata(pdata->i2c_device);
 	if (mcam->i2c_adapter == NULL) {
 		ret = -ENODEV;
include/media/mmp-camera.h +10 -1
index 7611963..813efe2 100755
@@ -1,3 +1,4 @@
+#include <media/v4l2-mediabus.h>
 /*
  * Information for the Marvell Armada MMP camera
  */
@@ -6,4 +7,13 @@ struct mmp_camera_platform_data {
 	struct platform_device *i2c_device;
 	int sensor_power_gpio;
 	int sensor_reset_gpio;
+	enum v4l2_mbus_type bus_type;
+	/*
+	 * MIPI support
+	 */
+	int dphy[3];		/* DPHY: CSI2_DPHY3, CSI2_DPHY5, CSI2_DPHY6 */
+	int dphy3_algo;		/* Exist 2 algos for calculate CSI2_DPHY3 */
+	int mipi_enabled;	/* MIPI enabled flag */
+	int lane;		/* ccic used lane number; 0 means DVP mode */
+	int lane_clk;
 };
--

1.7.9.5

Quoted 8 lines
Quoted 1 line

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#9 lore raw

PATCH v4 2/12 marvell-ccic: add clock tree support for marvell-ccic driver

In reply to Albert Wang

From: Libin Yang <[email protected]>

This patch adds the clock tree support for marvell-ccic.

---
 drivers/media/platform/marvell-ccic/mcam-core.h  |    4 ++
 drivers/media/platform/marvell-ccic/mmp-driver.c |   47 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)
drivers/media/platform/marvell-ccic/mcam-core.h +4 -0
index f73a801..2b2dc06 100755
@@ -82,6 +82,8 @@ struct mcam_frame_state {
 	unsigned int delivered;
 };
 
+#define NR_MCAM_CLK 3
+
 /*
  * A description of one of our devices.
  * Locking: controlled by s_mutex.  Certain fields, however, require
@@ -109,6 +111,8 @@ struct mcam_camera {
 	int lane;			/* lane number */
 
 	struct clk *pll1;
+	/* clock tree support */
+	struct clk *clk[NR_MCAM_CLK];
 
 	/*
 	 * Callbacks from the core to the platform code.
drivers/media/platform/marvell-ccic/mmp-driver.c +47 -0

83 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#10 lore raw

Re: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

Hi Albert

Quoted 39 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the clock tree support for marvell-ccic.

---
 drivers/media/platform/marvell-ccic/mcam-core.h  |    4 ++
 drivers/media/platform/marvell-ccic/mmp-driver.c |   47 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)
drivers/media/platform/marvell-ccic/mcam-core.h +4 -0
index f73a801..2b2dc06 100755
@@ -82,6 +82,8 @@ struct mcam_frame_state {
 	unsigned int delivered;
 };
 
+#define NR_MCAM_CLK 3
+
 /*
  * A description of one of our devices.
  * Locking: controlled by s_mutex.  Certain fields, however, require
@@ -109,6 +111,8 @@ struct mcam_camera {
 	int lane;			/* lane number */
 
 	struct clk *pll1;
+	/* clock tree support */
+	struct clk *clk[NR_MCAM_CLK];
 
 	/*
 	 * Callbacks from the core to the platform code.
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0
index 7ab01e9..2fe0324 100755

drivers/media/platform/marvell-ccic/mmp-driver.c MODULE_ALIAS("platform:mmp-camera"); · line 39

Quoted 5 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +2 -0
@@ -35,6 +35,8 @@ MODULE_ALIAS("platform:mmp-camera");
 MODULE_AUTHOR("Jonathan Corbet <[email protected]>");
 MODULE_LICENSE("GPL");
 
+static char *mcam_clks[] = {"CCICAXICLK", "CCICFUNCLK", "CCICPHYCLK"};
+

It's good, you are using fixed clock names now!

Quoted 4 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0
 struct mmp_camera {
 	void *power_regs;
 	struct platform_device *pdev;

drivers/media/platform/marvell-ccic/mmp-driver.c static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev) · line 115

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +7 -0
@@ -104,6 +106,26 @@ static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev)
 #define REG_CCIC_DCGCR		0x28	/* CCIC dyn clock gate ctrl reg */
 #define REG_CCIC_CRCR		0x50	/* CCIC clk reset ctrl reg	*/
 
+static void mcam_clk_enable(struct mcam_camera *mcam)
+{
+	unsigned int i;
+
+	for (i = 0; i < NR_MCAM_CLK; i++) {
+		if (mcam->clk[i])
+			clk_enable(mcam->clk[i]);

I think it's generally considered a better option to use clk_prepare_enable() and clk_disable_unprepare() instead of just clk_enable() and clk_disable().

Quoted 59 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +34 -0
+	}
+}
+
+static void mcam_clk_disable(struct mcam_camera *mcam)
+{
+	int i;
+
+	for (i = NR_MCAM_CLK - 1; i >= 0; i--) {
+		if (mcam->clk[i])
+			clk_disable(mcam->clk[i]);
+	}
+}
+
 /*
  * Power control.
  */
@@ -134,6 +156,8 @@ static void mmpcam_power_up(struct mcam_camera *mcam)
 	mdelay(5);
 	gpio_set_value(pdata->sensor_reset_gpio, 1); /* reset is active low */
 	mdelay(5);
+
+	mcam_clk_enable(mcam);
 }
 
 static void mmpcam_power_down(struct mcam_camera *mcam)
@@ -151,6 +175,8 @@ static void mmpcam_power_down(struct mcam_camera *mcam)
 	pdata = cam->pdev->dev.platform_data;
 	gpio_set_value(pdata->sensor_power_gpio, 0);
 	gpio_set_value(pdata->sensor_reset_gpio, 0);
+
+	mcam_clk_disable(mcam);
 }
 
 /*
@@ -263,6 +289,23 @@ static irqreturn_t mmpcam_irq(int irq, void *data)
 	return IRQ_RETVAL(handled);
 }
 
+static int mcam_init_clk(struct mcam_camera *mcam,
+			struct mmp_camera_platform_data *pdata)
+{
+	unsigned int i;
+
+	for (i = 0; i < NR_MCAM_CLK; i++) {
+		if (mcam_clks[i] != NULL) {
+			mcam->clk[i] = devm_clk_get(mcam->dev, mcam_clks[i]);
+			if (IS_ERR(mcam->clk[i])) {
+				dev_err(mcam->dev, "Could not get clk: %s\n",
+						mcam_clks[i]);
+				return PTR_ERR(mcam->clk[i]);
+			}
+		}
+	}
+	return 0;
+}
 
 static int mmpcam_probe(struct platform_device *pdev)
 {

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 380

Quoted 7 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +4 -0
@@ -331,6 +374,10 @@ static int mmpcam_probe(struct platform_device *pdev)
 		ret = -ENODEV;
 		goto out_unmap1;
 	}
+
+	ret = mcam_init_clk(mcam, pdata);
+	if (ret)
+		goto out_unmap2;

Now, I'm confused again: doesn't this mean, that all existing users of this driver will fail?

Quoted 6 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0
 	/*
 	 * Find the i2c adapter.  This assumes, of course, that the
 	 * i2c bus is already up and functioning.
Signature · 1 line
1.7.9.5

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#11 lore raw

RE: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

Hi, Guennadi

Quoted 69 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 17:51
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

Hi Albert

Quoted 7 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the clock tree support for marvell-ccic.

Review

Quoted 6 lines
---
 drivers/media/platform/marvell-ccic/mcam-core.h  |    4 ++
 drivers/media/platform/marvell-ccic/mmp-driver.c |   47 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.h

Review

Quoted 22 lines

index f73a801..2b2dc06 100755

drivers/media/platform/marvell-ccic/mcam-core.h +4 -0
@@ -82,6 +82,8 @@ struct mcam_frame_state {
 	unsigned int delivered;
 };
 
+#define NR_MCAM_CLK 3
+
 /*
  * A description of one of our devices.
  * Locking: controlled by s_mutex.  Certain fields, however, require
@@ -109,6 +111,8 @@ struct mcam_camera {
 	int lane;			/* lane number */
 
 	struct clk *pll1;
+	/* clock tree support */
+	struct clk *clk[NR_MCAM_CLK];
 
 	/*
 	 * Callbacks from the core to the platform code.
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mmp-driver.c

drivers/media/platform/marvell-ccic/mmp-driver.c MODULE_ALIAS("platform:mmp-camera"); · line 39

Quoted 9 lines

index 7ab01e9..2fe0324 100755

drivers/media/platform/marvell-ccic/mmp-driver.c +2 -0
@@ -35,6 +35,8 @@ MODULE_ALIAS("platform:mmp-camera");
 MODULE_AUTHOR("Jonathan Corbet <[email protected]>");
 MODULE_LICENSE("GPL");
 
+static char *mcam_clks[] = {"CCICAXICLK", "CCICFUNCLK", "CCICPHYCLK"};
+

It's good, you are using fixed clock names now!

drivers/media/platform/marvell-ccic/mmp-driver.c static struct mmp_camera *mmpcam_find_device(struct

Quoted 4 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0
 struct mmp_camera {
 	void *power_regs;
 	struct platform_device *pdev;
@@ -104,6 +106,26 @@ static struct mmp_camera *mmpcam_find_device(struct

platform_device *pdev)

Quoted 3 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0
 #define REG_CCIC_DCGCR		0x28	/* CCIC dyn clock gate ctrl reg */
 #define REG_CCIC_CRCR		0x50	/* CCIC clk reset ctrl reg	*/
 
Quoted 12 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev) · line 115

Quoted 7 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +7 -0
+static void mcam_clk_enable(struct mcam_camera *mcam)
+{
+	unsigned int i;
+
+	for (i = 0; i < NR_MCAM_CLK; i++) {
+		if (mcam->clk[i])
+			clk_enable(mcam->clk[i]);

I think it's generally considered a better option to use clk_prepare_enable() and clk_disable_unprepare() instead of just clk_enable() and clk_disable().

Sounds great, we will think about it.

Quoted 57 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static void mmpcam_power_down(struct mcam_camera

Quoted 26 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +15 -0
+	}
+}
+
+static void mcam_clk_disable(struct mcam_camera *mcam)
+{
+	int i;
+
+	for (i = NR_MCAM_CLK - 1; i >= 0; i--) {
+		if (mcam->clk[i])
+			clk_disable(mcam->clk[i]);
+	}
+}
+
 /*
  * Power control.
  */
@@ -134,6 +156,8 @@ static void mmpcam_power_up(struct mcam_camera *mcam)
 	mdelay(5);
 	gpio_set_value(pdata->sensor_reset_gpio, 1); /* reset is active low */
 	mdelay(5);
+
+	mcam_clk_enable(mcam);
 }
 
 static void mmpcam_power_down(struct mcam_camera *mcam)
@@ -151,6 +175,8 @@ static void mmpcam_power_down(struct mcam_camera

*mcam)

Quoted 30 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +19 -0
 	pdata = cam->pdev->dev.platform_data;
 	gpio_set_value(pdata->sensor_power_gpio, 0);
 	gpio_set_value(pdata->sensor_reset_gpio, 0);
+
+	mcam_clk_disable(mcam);
 }
 
 /*
@@ -263,6 +289,23 @@ static irqreturn_t mmpcam_irq(int irq, void *data)
 	return IRQ_RETVAL(handled);
 }
 
+static int mcam_init_clk(struct mcam_camera *mcam,
+			struct mmp_camera_platform_data *pdata)
+{
+	unsigned int i;
+
+	for (i = 0; i < NR_MCAM_CLK; i++) {
+		if (mcam_clks[i] != NULL) {
+			mcam->clk[i] = devm_clk_get(mcam->dev, mcam_clks[i]);
+			if (IS_ERR(mcam->clk[i])) {
+				dev_err(mcam->dev, "Could not get clk: %s\n",
+						mcam_clks[i]);
+				return PTR_ERR(mcam->clk[i]);
+			}
+		}
+	}
+	return 0;
+}
 
Quoted 14 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 380

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +4 -0
 static int mmpcam_probe(struct platform_device *pdev)
 {
@@ -331,6 +374,10 @@ static int mmpcam_probe(struct platform_device *pdev)
 		ret = -ENODEV;
 		goto out_unmap1;
 	}
+
+	ret = mcam_init_clk(mcam, pdata);
+	if (ret)
+		goto out_unmap2;

Now, I'm confused again: doesn't this mean, that all existing users of this driver will fail?

Sorry, I don't understand what's your concern?

Quoted 7 lines
Quoted 6 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -1
 	/*
 	 * Find the i2c adapter.  This assumes, of course, that the
 	 * i2c bus is already up and functioning.
--

1.7.9.5

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#12 lore raw

RE: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

Hi Albert

Quoted 10 lines · Albert Wang

Hi, Guennadi

Quoted 7 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 17:51
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

[snip]

Quoted 12 lines
Quoted 12 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 380

Quoted 8 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +4 -0
@@ -331,6 +374,10 @@ static int mmpcam_probe(struct platform_device *pdev)
 		ret = -ENODEV;
 		goto out_unmap1;
 	}
+
+	ret = mcam_init_clk(mcam, pdata);
+	if (ret)
+		goto out_unmap2;

Now, I'm confused again: doesn't this mean, that all existing users of this driver will fail?

Quoted 1 line

Sorry, I don't understand what's your concern?

I mean - wouldn't the above function fail for all existing users, because they don't provide the clocks, that you're requesting here?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#13 lore raw

RE: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

Hi, Guennadi

Quoted 38 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Wednesday, 06 March, 2013 23:00
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: RE: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support for marvell-ccic driver

Hi Albert

Quoted 9 lines · Albert Wang

Hi, Guennadi

Quoted 6 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 17:51
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 02/12] [media] marvell-ccic: add clock tree support

for

Quoted 1 line
Quoted 1 line

marvell-ccic driver

[snip]

Quoted 12 lines
Quoted 12 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 380

Quoted 8 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +4 -0
@@ -331,6 +374,10 @@ static int mmpcam_probe(struct platform_device *pdev)
 		ret = -ENODEV;
 		goto out_unmap1;
 	}
+
+	ret = mcam_init_clk(mcam, pdata);
+	if (ret)
+		goto out_unmap2;

Now, I'm confused again: doesn't this mean, that all existing users of this driver will fail?

Quoted 5 lines
Quoted 1 line

Sorry, I don't understand what's your concern?

I mean - wouldn't the above function fail for all existing users, because they don't provide the clocks, that you're requesting here?

OK, I see. We will update it.

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#14 lore raw

PATCH v4 3/12 marvell-ccic: reset ccic phy when stop streaming for stability

In reply to Albert Wang

This patch adds the reset ccic phy operation when stop streaming.

Stop streaming without reset ccic phy, the next start streaming may be unstable.
Also need add CCIC2 definition when PXA688/PXA2128 support dual ccics.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |    6 ++++++
 drivers/media/platform/marvell-ccic/mcam-core.h  |    2 ++
 drivers/media/platform/marvell-ccic/mmp-driver.c |   25 ++++++++++++++++++++++
 3 files changed, 33 insertions(+)
drivers/media/platform/marvell-ccic/mcam-core.c +6 -0
index 7e178d8..a32df35 100755
@@ -1045,6 +1045,12 @@ static int mcam_vb_stop_streaming(struct vb2_queue *vq)
 		return -EINVAL;
 	mcam_ctlr_stop_dma(cam);
 	/*
+	 * Reset the CCIC PHY after stopping streaming,
+	 * otherwise, the CCIC may be unstable.
+	 */
+	if (cam->ctlr_reset)
+		cam->ctlr_reset(cam);
+	/*
 	 * VB2 reclaims the buffers, so we need to forget
 	 * about them.
 	 */
drivers/media/platform/marvell-ccic/mcam-core.h +2 -0
index 2b2dc06..ec43630 100755
@@ -104,6 +104,7 @@ struct mcam_camera {
 	short int use_smbus;	/* SMBUS or straight I2c? */
 	enum mcam_buffer_mode buffer_mode;
 
+	int ccic_id;
 	enum v4l2_mbus_type bus_type;
 	/* MIPI support */
 	int *dphy;
@@ -120,6 +121,7 @@ struct mcam_camera {
 	void (*plat_power_up) (struct mcam_camera *cam);
 	void (*plat_power_down) (struct mcam_camera *cam);
 	void (*calc_dphy) (struct mcam_camera *cam);
+	void (*ctlr_reset) (struct mcam_camera *cam);
 
 	/*
 	 * Everything below here is private to the mcam core and
drivers/media/platform/marvell-ccic/mmp-driver.c +25 -0
index 2fe0324..818abf3 100755
@@ -105,6 +105,7 @@ static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev)
 #define CPU_SUBSYS_PMU_BASE	0xd4282800
 #define REG_CCIC_DCGCR		0x28	/* CCIC dyn clock gate ctrl reg */
 #define REG_CCIC_CRCR		0x50	/* CCIC clk reset ctrl reg	*/
+#define REG_CCIC2_CRCR		0xf4	/* CCIC2 clk reset ctrl reg	*/
 
 static void mcam_clk_enable(struct mcam_camera *mcam)
 {
@@ -179,6 +180,28 @@ static void mmpcam_power_down(struct mcam_camera *mcam)
 	mcam_clk_disable(mcam);
 }
 
+void mcam_ctlr_reset(struct mcam_camera *mcam)
+{
+	unsigned long val;
+	struct mmp_camera *cam = mcam_to_cam(mcam);
+
+	if (mcam->ccic_id) {
+		/*
+		 * Using CCIC2
+		 */
+		val = ioread32(cam->power_regs + REG_CCIC2_CRCR);
+		iowrite32(val & ~0x2, cam->power_regs + REG_CCIC2_CRCR);
+		iowrite32(val | 0x2, cam->power_regs + REG_CCIC2_CRCR);
+	} else {
+		/*
+		 * Using CCIC1
+		 */
+		val = ioread32(cam->power_regs + REG_CCIC_CRCR);
+		iowrite32(val & ~0x2, cam->power_regs + REG_CCIC_CRCR);
+		iowrite32(val | 0x2, cam->power_regs + REG_CCIC_CRCR);
+	}
+}
+
 /*
  * calc the dphy register values
  * There are three dphy registers being used.
@@ -328,9 +351,11 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam = &cam->mcam;
 	mcam->plat_power_up = mmpcam_power_up;
 	mcam->plat_power_down = mmpcam_power_down;
+	mcam->ctlr_reset = mcam_ctlr_reset;
 	mcam->calc_dphy = mmpcam_calc_dphy;
 	mcam->dev = &pdev->dev;
 	mcam->use_smbus = 0;
+	mcam->ccic_id = pdev->id;
 	mcam->bus_type = pdata->bus_type;
 	mcam->dphy = pdata->dphy;
 	/* mosetly it won't happen. dphy is an array in pdata, but in case .. */
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH v4 4/12 marvell-ccic: refine mcam_set_contig_buffer function

In reply to Albert Wang

From: Libin Yang <[email protected]>

This patch refines mcam_set_contig_buffer() in mcam core. It can remove redundant code line and enhance readability.

---
 drivers/media/platform/marvell-ccic/mcam-core.c |   21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +10 -11
index a32df35..f89fce7 100755
@@ -475,22 +475,21 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 	 */
 	if (list_empty(&cam->buffers)) {
 		buf = cam->vb_bufs[frame ^ 0x1];
-		cam->vb_bufs[frame] = buf;
-		mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR,
-				vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0));
 		set_bit(CF_SINGLE_BUFFER, &cam->flags);
 		cam->frame_state.singles++;
-		return;
+	} else {
+		/*
+		 * OK, we have a buffer we can use.
+		 */
+		buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer,
+					queue);
+		list_del_init(&buf->queue);
+		clear_bit(CF_SINGLE_BUFFER, &cam->flags);
 	}
-	/*
-	 * OK, we have a buffer we can use.
-	 */
-	buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer, queue);
-	list_del_init(&buf->queue);
+
+	cam->vb_bufs[frame] = buf;
 	mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR,
 			vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0));
-	cam->vb_bufs[frame] = buf;
-	clear_bit(CF_SINGLE_BUFFER, &cam->flags);
 }
 
 /*
Signature · 1 line
1.7.9.5
#16 lore raw

PATCH v4 5/12 marvell-ccic: add new formats support for marvell-ccic driver

In reply to Albert Wang

From: Libin Yang <[email protected]>

This patch adds the new formats support for marvell-ccic.

---
 drivers/media/platform/marvell-ccic/mcam-core.c |  189 +++++++++++++++++++----
 drivers/media/platform/marvell-ccic/mcam-core.h |    6 +
 2 files changed, 162 insertions(+), 33 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +156 -33
index f89fce7..0f9604e 100755
@@ -102,6 +102,7 @@ static struct mcam_format_struct {
 	__u8 *desc;
 	__u32 pixelformat;
 	int bpp;   /* Bytes per pixel */
+	bool planar;
 	enum v4l2_mbus_pixelcode mbus_code;
 } mcam_formats[] = {
 	{
@@ -109,24 +110,56 @@ static struct mcam_format_struct {
 		.pixelformat	= V4L2_PIX_FMT_YUYV,
 		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,
 		.bpp		= 2,
+		.planar		= false,
+	},
+	{
+		.desc		= "UYVY 4:2:2",
+		.pixelformat	= V4L2_PIX_FMT_UYVY,
+		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,
+		.bpp		= 2,
+		.planar		= false,
+	},
+	{
+		.desc		= "YUV 4:2:2 PLANAR",
+		.pixelformat	= V4L2_PIX_FMT_YUV422P,
+		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,
+		.bpp		= 2,
+		.planar		= true,
+	},
+	{
+		.desc		= "YUV 4:2:0 PLANAR",
+		.pixelformat	= V4L2_PIX_FMT_YUV420,
+		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,
+		.bpp		= 2,
+		.planar		= true,
+	},
+	{
+		.desc		= "YVU 4:2:0 PLANAR",
+		.pixelformat	= V4L2_PIX_FMT_YVU420,
+		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,
+		.bpp		= 2,
+		.planar		= true,
 	},
 	{
 		.desc		= "RGB 444",
 		.pixelformat	= V4L2_PIX_FMT_RGB444,
 		.mbus_code	= V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE,
 		.bpp		= 2,
+		.planar		= false,
 	},
 	{
 		.desc		= "RGB 565",
 		.pixelformat	= V4L2_PIX_FMT_RGB565,
 		.mbus_code	= V4L2_MBUS_FMT_RGB565_2X8_LE,
 		.bpp		= 2,
+		.planar		= false,
 	},
 	{
 		.desc		= "Raw RGB Bayer",
 		.pixelformat	= V4L2_PIX_FMT_SBGGR8,
 		.mbus_code	= V4L2_MBUS_FMT_SBGGR8_1X8,
-		.bpp		= 1
+		.bpp		= 1,
+		.planar		= false,
 	},
 };
 #define N_MCAM_FMTS ARRAY_SIZE(mcam_formats)
@@ -169,6 +202,12 @@ struct mcam_dma_desc {
 	u32 segment_len;
 };
 
+struct yuv_pointer_t {
+	dma_addr_t y;
+	dma_addr_t u;
+	dma_addr_t v;
+};
+
 /*
  * Our buffer type for working with videobuf2.  Note that the vb2
  * developers have decreed that struct vb2_buffer must be at the
@@ -180,6 +219,7 @@ struct mcam_vb_buffer {
 	struct mcam_dma_desc *dma_desc;	/* Descriptor virtual address */
 	dma_addr_t dma_desc_pa;		/* Descriptor physical address */
 	int dma_desc_nent;		/* Number of mapped descriptors */
+	struct yuv_pointer_t yuv_p;
 };
 
 static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb)
@@ -459,6 +499,15 @@ static inline int mcam_check_dma_buffers(struct mcam_camera *cam)
 /*
  * DMA-contiguous code.
  */
+
+static bool mcam_fmt_is_planar(__u32 pfmt)
+{
+	struct mcam_format_struct *f;
+
+	f = mcam_find_format(pfmt);
+	return f->planar;
+}
+
 /*
  * Set up a contiguous buffer for the given frame.  Here also is where
  * the underrun strategy is set: if there is no buffer available, reuse
@@ -470,6 +519,8 @@ static inline int mcam_check_dma_buffers(struct mcam_camera *cam)
 static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 {
 	struct mcam_vb_buffer *buf;
+	struct v4l2_pix_format *fmt = &cam->pix_format;
+
 	/*
 	 * If there are no available buffers, go into single mode
 	 */
@@ -488,8 +539,13 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 	}
 
 	cam->vb_bufs[frame] = buf;
-	mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR,
-			vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0));
+	mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR, buf->yuv_p.y);
+	if (mcam_fmt_is_planar(fmt->pixelformat)) {
+		mcam_reg_write(cam, frame == 0 ?
+					REG_U0BAR : REG_U1BAR, buf->yuv_p.u);
+		mcam_reg_write(cam, frame == 0 ?
+					REG_V0BAR : REG_V1BAR, buf->yuv_p.v);
+	}
 }
 
 /*
@@ -647,49 +703,84 @@ static inline void mcam_sg_restart(struct mcam_camera *cam)
  */
 static void mcam_ctlr_image(struct mcam_camera *cam)
 {
-	int imgsz;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
+	u32 widthy = 0, widthuv = 0, imgsz_h, imgsz_w;
+
+	cam_dbg(cam, "camera: bytesperline = %d; height = %d\n",
+		fmt->bytesperline, fmt->sizeimage / fmt->bytesperline);
+	imgsz_h = (fmt->height << IMGSZ_V_SHIFT) & IMGSZ_V_MASK;
+	imgsz_w = (fmt->width * 2) & IMGSZ_H_MASK;
+
+	switch (fmt->pixelformat) {
+	case V4L2_PIX_FMT_YUYV:
+	case V4L2_PIX_FMT_UYVY:
+		widthy = fmt->width * 2;
+		widthuv = 0;
+		break;
+	case V4L2_PIX_FMT_JPEG:
+		imgsz_h = (fmt->sizeimage / fmt->bytesperline) << IMGSZ_V_SHIFT;
+		widthy = fmt->bytesperline;
+		widthuv = 0;
+		break;
+	case V4L2_PIX_FMT_YUV422P:
+	case V4L2_PIX_FMT_YUV420:
+	case V4L2_PIX_FMT_YVU420:
+		widthy = fmt->width;
+		widthuv = fmt->width / 2;
+		break;
+	default:
+		widthy = fmt->bytesperline;
+		widthuv = 0;
+	}
+
+	mcam_reg_write_mask(cam, REG_IMGPITCH, widthuv << 16 | widthy,
+			IMGP_YP_MASK | IMGP_UVP_MASK);
+	mcam_reg_write(cam, REG_IMGSIZE, imgsz_h | imgsz_w);
+	mcam_reg_write(cam, REG_IMGOFFSET, 0x0);
 
-	imgsz = ((fmt->height << IMGSZ_V_SHIFT) & IMGSZ_V_MASK) |
-		(fmt->bytesperline & IMGSZ_H_MASK);
-	mcam_reg_write(cam, REG_IMGSIZE, imgsz);
-	mcam_reg_write(cam, REG_IMGOFFSET, 0);
-	/* YPITCH just drops the last two bits */
-	mcam_reg_write_mask(cam, REG_IMGPITCH, fmt->bytesperline,
-			IMGP_YP_MASK);
 	/*
 	 * Tell the controller about the image format we are using.
 	 */
-	switch (cam->pix_format.pixelformat) {
+	switch (fmt->pixelformat) {
+	case V4L2_PIX_FMT_YUV422P:
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_YUV | C0_YUV_PLANAR | C0_YUVE_YVYU, C0_DF_MASK);
+		break;
+	case V4L2_PIX_FMT_YUV420:
+	case V4L2_PIX_FMT_YVU420:
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_YUV | C0_YUV_420PL | C0_YUVE_YVYU, C0_DF_MASK);
+		break;
 	case V4L2_PIX_FMT_YUYV:
-	    mcam_reg_write_mask(cam, REG_CTRL0,
-			    C0_DF_YUV|C0_YUV_PACKED|C0_YUVE_YUYV,
-			    C0_DF_MASK);
-	    break;
-
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_UYVY, C0_DF_MASK);
+		break;
+	case V4L2_PIX_FMT_UYVY:
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_YUYV, C0_DF_MASK);
+		break;
+	case V4L2_PIX_FMT_JPEG:
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_YUYV, C0_DF_MASK);
+		break;
 	case V4L2_PIX_FMT_RGB444:
-	    mcam_reg_write_mask(cam, REG_CTRL0,
-			    C0_DF_RGB|C0_RGBF_444|C0_RGB4_XRGB,
-			    C0_DF_MASK);
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_RGB | C0_RGBF_444 | C0_RGB4_XRGB, C0_DF_MASK);
 		/* Alpha value? */
-	    break;
-
+		break;
 	case V4L2_PIX_FMT_RGB565:
-	    mcam_reg_write_mask(cam, REG_CTRL0,
-			    C0_DF_RGB|C0_RGBF_565|C0_RGB5_BGGR,
-			    C0_DF_MASK);
-	    break;
-
+		mcam_reg_write_mask(cam, REG_CTRL0,
+			C0_DF_RGB | C0_RGBF_565 | C0_RGB5_BGGR, C0_DF_MASK);
+		break;
 	default:
-	    cam_err(cam, "Unknown format %x\n", cam->pix_format.pixelformat);
-	    break;
+		cam_err(cam, "camera: unknown format: %#x\n", fmt->pixelformat);
+		break;
 	}
+
 	/*
 	 * Make sure it knows we want to use hsync/vsync.
 	 */
-	mcam_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC,
-			C0_SIFM_MASK);
-
+	mcam_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC, C0_SIFM_MASK);
 	/*
 	 * This field controls the generation of EOF(DVP only)
 	 */
@@ -971,11 +1062,35 @@ static void mcam_vb_buf_queue(struct vb2_buffer *vb)
 {
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
 	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
+	struct v4l2_pix_format *fmt = &cam->pix_format;
 	unsigned long flags;
 	int start;
+	dma_addr_t dma_handle;
+	u32 pixel_count = fmt->width * fmt->height;
 
 	spin_lock_irqsave(&cam->dev_lock, flags);
+	dma_handle = vb2_dma_contig_plane_dma_addr(vb, 0);
+	BUG_ON(!dma_handle);
 	start = (cam->state == S_BUFWAIT) && !list_empty(&cam->buffers);
+	mvb->yuv_p.y = dma_handle;
+
+	switch (cam->pix_format.pixelformat) {
+	case V4L2_PIX_FMT_YUV422P:
+		mvb->yuv_p.u = mvb->yuv_p.y + pixel_count;
+		mvb->yuv_p.v = mvb->yuv_p.u + pixel_count / 2;
+		break;
+	case V4L2_PIX_FMT_YUV420:
+		mvb->yuv_p.u = mvb->yuv_p.y + pixel_count;
+		mvb->yuv_p.v = mvb->yuv_p.u + pixel_count / 4;
+		break;
+	case V4L2_PIX_FMT_YVU420:
+		mvb->yuv_p.v = mvb->yuv_p.y + pixel_count;
+		mvb->yuv_p.u = mvb->yuv_p.v + pixel_count / 4;
+		break;
+	default:
+		break;
+	}
+
 	list_add(&mvb->queue, &cam->buffers);
 	if (cam->state == S_STREAMING && test_bit(CF_SG_RESTART, &cam->flags))
 		mcam_sg_restart(cam);
@@ -1361,7 +1476,15 @@ static int mcam_vidioc_try_fmt_vid_cap(struct file *filp, void *priv,
 	ret = sensor_call(cam, video, try_mbus_fmt, &mbus_fmt);
 	mutex_unlock(&cam->s_mutex);
 	v4l2_fill_pix_format(pix, &mbus_fmt);
-	pix->bytesperline = pix->width * f->bpp;
+	switch (f->pixelformat) {
+	case V4L2_PIX_FMT_YUV420:
+	case V4L2_PIX_FMT_YVU420:
+		pix->bytesperline = pix->width * 3 / 2;
+		break;
+	default:
+		pix->bytesperline = pix->width * f->bpp;
+		break;
+	}
 	pix->sizeimage = pix->height * pix->bytesperline;
 	return ret;
 }
drivers/media/platform/marvell-ccic/mcam-core.h +6 -0
index ec43630..692727d 100755
@@ -234,6 +234,12 @@ int mccic_resume(struct mcam_camera *cam);
 #define REG_Y0BAR	0x00
 #define REG_Y1BAR	0x04
 #define REG_Y2BAR	0x08
+#define REG_U0BAR	0x0c
+#define REG_U1BAR	0x10
+#define REG_U2BAR	0x14
+#define REG_V0BAR	0x18
+#define REG_V1BAR	0x1C
+#define REG_V2BAR	0x20
 
 /*
  * register definitions for MIPI support
Signature · 1 line
1.7.9.5
#17 lore raw

Re: [REVIEW PATCH V4 05/12] [media] marvell-ccic: add new formats support for marvell-ccic driver

Looks pretty good to me now, just one nitpick:

Quoted 15 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the new formats support for marvell-ccic.

---
 drivers/media/platform/marvell-ccic/mcam-core.c |  189 +++++++++++++++++++----
 drivers/media/platform/marvell-ccic/mcam-core.h |    6 +
 2 files changed, 162 insertions(+), 33 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +0 -0
index f89fce7..0f9604e 100755

[snip]

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_vb_buf_queue(struct vb2_buffer *vb) · line 1073

Quoted 13 lines
drivers/media/platform/marvell-ccic/mcam-core.c +5 -0
@@ -971,11 +1062,35 @@ static void mcam_vb_buf_queue(struct vb2_buffer *vb)
 {
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
 	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
+	struct v4l2_pix_format *fmt = &cam->pix_format;
 	unsigned long flags;
 	int start;
+	dma_addr_t dma_handle;
+	u32 pixel_count = fmt->width * fmt->height;
 
 	spin_lock_irqsave(&cam->dev_lock, flags);
+	dma_handle = vb2_dma_contig_plane_dma_addr(vb, 0);
+	BUG_ON(!dma_handle);

Again - a bit too strong. But the truth is - .buf_queue() cannot fail... Would it be possible to move this pointer calculation to .buf_prepare(), which does return an error code?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#18 lore raw

RE: [REVIEW PATCH V4 05/12] [media] marvell-ccic: add new formats support for marvell-ccic driver

Hi, Guennadi

Quoted 41 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 18:08
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 05/12] [media] marvell-ccic: add new formats support for marvell-ccic driver

Looks pretty good to me now, just one nitpick:

Quoted 4 lines · Albert Wang

From: Libin Yang <[email protected]>

This patch adds the new formats support for marvell-ccic.

Review

Quoted 8 lines
---
 drivers/media/platform/marvell-ccic/mcam-core.c |  189 +++++++++++++++++++----
 drivers/media/platform/marvell-ccic/mcam-core.h |    6 +
 2 files changed, 162 insertions(+), 33 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.c

Quoted 3 lines

index f89fce7..0f9604e 100755

drivers/media/platform/marvell-ccic/mcam-core.c +0 -0

[snip]

Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
@@ -971,11 +1062,35 @@ static void mcam_vb_buf_queue(struct vb2_buffer *vb)
 {
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
 	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
+	struct v4l2_pix_format *fmt = &cam->pix_format;
 	unsigned long flags;
 	int start;
+	dma_addr_t dma_handle;
+	u32 pixel_count = fmt->width * fmt->height;
 
Quoted 8 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_vb_buf_queue(struct vb2_buffer *vb) · line 1073

Quoted 3 lines
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
 	spin_lock_irqsave(&cam->dev_lock, flags);
+	dma_handle = vb2_dma_contig_plane_dma_addr(vb, 0);
+	BUG_ON(!dma_handle);

Again - a bit too strong. But the truth is - .buf_queue() cannot fail... Would it be possible to move this pointer calculation to .buf_prepare(), which does return an error code?

Yes, we will remove all BUG_ON macros, replace them with error or warning msg.

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#19 lore raw

PATCH v4 6/12 marvell-ccic: add SOF/EOF pair check for marvell-ccic driver

In reply to Albert Wang

From: Libin Yang <[email protected]>

This patch adds the SOFx/EOFx pair check for marvell-ccic.

When switching format, the last EOF may not arrive when stop streamning. And the EOF will be detected in the next start streaming.

Must ensure clear the left over frame flags before every really start streaming.

---
 drivers/media/platform/marvell-ccic/mcam-core.c |   30 ++++++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +26 -4
index 0f9604e..29c68f1 100755
@@ -94,6 +94,9 @@ MODULE_PARM_DESC(buffer_mode,
 #define CF_CONFIG_NEEDED 4	/* Must configure hardware */
 #define CF_SINGLE_BUFFER 5	/* Running with a single buffer */
 #define CF_SG_RESTART	 6	/* SG restart needed */
+#define CF_FRAME_SOF0	 7	/* Frame 0 started */
+#define CF_FRAME_SOF1	 8
+#define CF_FRAME_SOF2	 9
 
 #define sensor_call(cam, o, f, args...) \
 	v4l2_subdev_call(cam->sensor, o, f, ##args)
@@ -260,8 +263,10 @@ static void mcam_reset_buffers(struct mcam_camera *cam)
 	int i;
 
 	cam->next_buf = -1;
-	for (i = 0; i < cam->nbufs; i++)
+	for (i = 0; i < cam->nbufs; i++) {
 		clear_bit(i, &cam->flags);
+		clear_bit(CF_FRAME_SOF0 + i, &cam->flags);
+	}
 }
 
 static inline int mcam_needs_config(struct mcam_camera *cam)
@@ -1125,6 +1130,7 @@ static void mcam_vb_wait_finish(struct vb2_queue *vq)
 static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
+	unsigned int frame;
 
 	if (cam->state != S_IDLE) {
 		INIT_LIST_HEAD(&cam->buffers);
@@ -1142,6 +1148,14 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 		cam->state = S_BUFWAIT;
 		return 0;
 	}
+
+	/*
+	 * Ensure clear the left over frame flags
+	 * before every really start streaming
+	 */
+	for (frame = 0; frame < cam->nbufs; frame++)
+		clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
+
 	return mcam_read_setup(cam);
 }
 
@@ -1883,9 +1897,11 @@ int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
 	 * each time.
 	 */
 	for (frame = 0; frame < cam->nbufs; frame++)
-		if (irqs & (IRQ_EOF0 << frame)) {
+		if (irqs & (IRQ_EOF0 << frame) &&
+			test_bit(CF_FRAME_SOF0 + frame, &cam->flags)) {
 			mcam_frame_complete(cam, frame);
 			handled = 1;
+			clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
 			if (cam->buffer_mode == B_DMA_sg)
 				break;
 		}
@@ -1894,9 +1910,15 @@ int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
 	 * code assumes that we won't get multiple frame interrupts
 	 * at once; may want to rethink that.
 	 */
-	if (irqs & (IRQ_SOF0 | IRQ_SOF1 | IRQ_SOF2)) {
+	for (frame = 0; frame < cam->nbufs; frame++) {
+		if (irqs & (IRQ_SOF0 << frame)) {
+			set_bit(CF_FRAME_SOF0 + frame, &cam->flags);
+			handled = IRQ_HANDLED;
+		}
+	}
+
+	if (handled == IRQ_HANDLED) {
 		set_bit(CF_DMA_ACTIVE, &cam->flags);
-		handled = 1;
 		if (cam->buffer_mode == B_DMA_sg)
 			mcam_ctlr_stop(cam);
 	}
Signature · 1 line
1.7.9.5
#20 lore raw

PATCH v4 7/12 marvell-ccic: switch to resource managed allocation and request

In reply to Albert Wang

This patch switchs to resource managed allocation and request in mmp-driver. It can remove free resource operations.

---
 drivers/media/platform/marvell-ccic/mmp-driver.c |   65 ++++++++--------------
 1 file changed, 22 insertions(+), 43 deletions(-)
drivers/media/platform/marvell-ccic/mmp-driver.c +22 -43
index 818abf3..d355840 100755
@@ -342,7 +342,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	if (!pdata)
 		return -ENODEV;
 
-	cam = kzalloc(sizeof(*cam), GFP_KERNEL);
+	cam = devm_kzalloc(&pdev->dev, sizeof(*cam), GFP_KERNEL);
 	if (cam == NULL)
 		return -ENOMEM;
 	cam->pdev = pdev;
@@ -359,10 +359,9 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->bus_type = pdata->bus_type;
 	mcam->dphy = pdata->dphy;
 	/* mosetly it won't happen. dphy is an array in pdata, but in case .. */
-	if (unlikely(mcam->dphy == NULL)) {
-		ret = -EINVAL;
-		goto out_free;
-	}
+	if (unlikely(mcam->dphy == NULL))
+		return -EINVAL;
+
 	mcam->mipi_enabled = 0;
 	mcam->lane = pdata->lane;
 	mcam->chip_id = V4L2_IDENT_ARMADA610;
@@ -374,14 +373,12 @@ static int mmpcam_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "no iomem resource!\n");
-		ret = -ENODEV;
-		goto out_free;
+		return -ENODEV;
 	}
-	mcam->regs = ioremap(res->start, resource_size(res));
+	mcam->regs = devm_request_and_ioremap(&pdev->dev, res);
 	if (mcam->regs == NULL) {
 		dev_err(&pdev->dev, "MMIO ioremap fail\n");
-		ret = -ENODEV;
-		goto out_free;
+		return -ENODEV;
 	}
 	/*
 	 * Power/clock memory is elsewhere; get it too.  Perhaps this
@@ -390,44 +387,43 @@ static int mmpcam_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "no power resource!\n");
-		ret = -ENODEV;
-		goto out_unmap1;
+		return -ENODEV;
 	}
-	cam->power_regs = ioremap(res->start, resource_size(res));
+	cam->power_regs = devm_request_and_ioremap(&pdev->dev, res);
 	if (cam->power_regs == NULL) {
 		dev_err(&pdev->dev, "power MMIO ioremap fail\n");
-		ret = -ENODEV;
-		goto out_unmap1;
+		return -ENODEV;
 	}
 
 	ret = mcam_init_clk(mcam, pdata);
 	if (ret)
-		goto out_unmap2;
+		return ret;
 	/*
 	 * Find the i2c adapter.  This assumes, of course, that the
 	 * i2c bus is already up and functioning.
 	 */
 	mcam->i2c_adapter = platform_get_drvdata(pdata->i2c_device);
 	if (mcam->i2c_adapter == NULL) {
-		ret = -ENODEV;
 		dev_err(&pdev->dev, "No i2c adapter\n");
-		goto out_unmap2;
+		return -ENODEV;
 	}
 	/*
 	 * Sensor GPIO pins.
 	 */
-	ret = gpio_request(pdata->sensor_power_gpio, "cam-power");
+	ret = devm_gpio_request(&pdev->dev, pdata->sensor_power_gpio,
+					"cam-power");
 	if (ret) {
 		dev_err(&pdev->dev, "Can't get sensor power gpio %d",
 				pdata->sensor_power_gpio);
-		goto out_unmap2;
+		return ret;
 	}
 	gpio_direction_output(pdata->sensor_power_gpio, 0);
-	ret = gpio_request(pdata->sensor_reset_gpio, "cam-reset");
+	ret = devm_gpio_request(&pdev->dev, pdata->sensor_reset_gpio,
+					"cam-reset");
 	if (ret) {
 		dev_err(&pdev->dev, "Can't get sensor reset gpio %d",
 				pdata->sensor_reset_gpio);
-		goto out_gpio;
+		return ret;
 	}
 	gpio_direction_output(pdata->sensor_reset_gpio, 0);
 	/*
@@ -436,7 +432,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mmpcam_power_up(mcam);
 	ret = mccic_register(mcam);
 	if (ret)
-		goto out_gpio2;
+		goto out_power_down;
 	/*
 	 * Finally, set up our IRQ now that the core is ready to
 	 * deal with it.
@@ -447,8 +443,8 @@ static int mmpcam_probe(struct platform_device *pdev)
 		goto out_unregister;
 	}
 	cam->irq = res->start;
-	ret = request_irq(cam->irq, mmpcam_irq, IRQF_SHARED,
-			"mmp-camera", mcam);
+	ret = devm_request_irq(&pdev->dev, cam->irq, mmpcam_irq, IRQF_SHARED,
+					"mmp-camera", mcam);
 	if (ret == 0) {
 		mmpcam_add_device(cam);
 		return 0;
@@ -456,17 +452,8 @@ static int mmpcam_probe(struct platform_device *pdev)
 
 out_unregister:
 	mccic_shutdown(mcam);
-out_gpio2:
+out_power_down:
 	mmpcam_power_down(mcam);
-	gpio_free(pdata->sensor_reset_gpio);
-out_gpio:
-	gpio_free(pdata->sensor_power_gpio);
-out_unmap2:
-	iounmap(cam->power_regs);
-out_unmap1:
-	iounmap(mcam->regs);
-out_free:
-	kfree(cam);
 	return ret;
 }
 
@@ -474,18 +461,10 @@ out_free:
 static int mmpcam_remove(struct mmp_camera *cam)
 {
 	struct mcam_camera *mcam = &cam->mcam;
-	struct mmp_camera_platform_data *pdata;
 
 	mmpcam_remove_device(cam);
-	free_irq(cam->irq, mcam);
 	mccic_shutdown(mcam);
 	mmpcam_power_down(mcam);
-	pdata = cam->pdev->dev.platform_data;
-	gpio_free(pdata->sensor_reset_gpio);
-	gpio_free(pdata->sensor_power_gpio);
-	iounmap(cam->power_regs);
-	iounmap(mcam->regs);
-	kfree(cam);
 	return 0;
 }
 
Signature · 1 line
1.7.9.5
#21 lore raw

Re: [REVIEW PATCH V4 07/12] [media] marvell-ccic: switch to resource managed allocation and request

Yet one more nitpick

Quoted 14 lines · Albert Wang

This patch switchs to resource managed allocation and request in mmp-driver. It can remove free resource operations.

---
 drivers/media/platform/marvell-ccic/mmp-driver.c |   65 ++++++++--------------
 1 file changed, 22 insertions(+), 43 deletions(-)
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0
index 818abf3..d355840 100755

[snip]

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 378

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +2 -3
@@ -374,14 +373,12 @@ static int mmpcam_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "no iomem resource!\n");
-		ret = -ENODEV;
-		goto out_free;
+		return -ENODEV;
 	}
-	mcam->regs = ioremap(res->start, resource_size(res));
+	mcam->regs = devm_request_and_ioremap(&pdev->dev, res);

Don't kill me, but they've recently invented devm_ioremap_resource(), which is essentially the same as devm_request_and_ioremap(), but also returns an error code and prints an error message, so, you wouldn't have to invent -ENODEV yourself and you don't need the dev_err() below.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#22 lore raw

RE: [REVIEW PATCH V4 07/12] [media] marvell-ccic: switch to resource managed allocation and request

Hi, Guennadi

Quoted 30 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 18:18
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 07/12] [media] marvell-ccic: switch to resource managed allocation and request

Yet one more nitpick

Review

Quoted 11 lines · Albert Wang

This patch switchs to resource managed allocation and request in mmp-driver. It can remove free resource operations.

---
 drivers/media/platform/marvell-ccic/mmp-driver.c |   65 ++++++++--------------
 1 file changed, 22 insertions(+), 43 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mmp-driver.c

Quoted 3 lines

index 818abf3..d355840 100755

drivers/media/platform/marvell-ccic/mmp-driver.c +0 -0

[snip]

Quoted 16 lines

drivers/media/platform/marvell-ccic/mmp-driver.c static int mmpcam_probe(struct platform_device *pdev) · line 378

Quoted 10 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +2 -3
@@ -374,14 +373,12 @@ static int mmpcam_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "no iomem resource!\n");
-		ret = -ENODEV;
-		goto out_free;
+		return -ENODEV;
 	}
-	mcam->regs = ioremap(res->start, resource_size(res));
+	mcam->regs = devm_request_and_ioremap(&pdev->dev, res);

Don't kill me, but they've recently invented devm_ioremap_resource(), which is essentially the same as devm_request_and_ioremap(), but also returns an error code and prints an error message, so, you wouldn't have to invent -ENODEV yourself and you don't need the dev_err() below.

OK, we will investigate devm_ioremap_resource() and use it if need.

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#23 lore raw

PATCH v4 8/12 marvell-ccic: rename B_DMA* to avoid CamelCase warning

In reply to Albert Wang

This patch renames the B_vmalloc/B_DMA_contig/B_DMA_sg to B_VMALLOC/B_DMA_CONTIG/B_DMA_SG variables to avoid CamelCase warning reported by the checkpatch.pl script.

---
 drivers/media/platform/marvell-ccic/cafe-driver.c |    2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c   |   38 ++++++++++-----------
 drivers/media/platform/marvell-ccic/mcam-core.h   |   12 +++----
 drivers/media/platform/marvell-ccic/mmp-driver.c  |    2 +-
 4 files changed, 27 insertions(+), 27 deletions(-)
drivers/media/platform/marvell-ccic/cafe-driver.c +1 -1
index d030f9b..f85f119 100755
@@ -486,7 +486,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
 	 * We *might* be able to run DMA_contig, especially on a system
 	 * with CMA in it.
 	 */
-	mcam->buffer_mode = B_vmalloc;
+	mcam->buffer_mode = B_VMALLOC;
 	/*
 	 * Get set up on the PCI bus.
 	 */
drivers/media/platform/marvell-ccic/mcam-core.c +19 -19
index 29c68f1..939c430 100755
@@ -554,7 +554,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 }
 
 /*
- * Initial B_DMA_contig setup.
+ * Initial B_DMA_CONTIG setup.
  */
 static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 {
@@ -611,7 +611,7 @@ static void mcam_sg_next_buffer(struct mcam_camera *cam)
 }
 
 /*
- * Initial B_DMA_sg setup
+ * Initial B_DMA_SG setup
  */
 static void mcam_ctlr_dma_sg(struct mcam_camera *cam)
 {
@@ -1005,7 +1005,7 @@ static int mcam_read_setup(struct mcam_camera *cam)
 	 * Configuration.  If we still don't have DMA buffers,
 	 * make one last, desperate attempt.
 	 */
-	if (cam->buffer_mode == B_vmalloc && cam->nbufs == 0 &&
+	if (cam->buffer_mode == B_VMALLOC && cam->nbufs == 0 &&
 			mcam_alloc_dma_bufs(cam, 0))
 		return -ENOMEM;
 
@@ -1051,13 +1051,13 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 		void *alloc_ctxs[])
 {
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
-	int minbufs = (cam->buffer_mode == B_DMA_contig) ? 3 : 2;
+	int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
 
 	sizes[0] = cam->pix_format.sizeimage;
 	*num_planes = 1; /* Someday we have to support planar formats... */
 	if (*nbufs < minbufs)
 		*nbufs = minbufs;
-	if (cam->buffer_mode == B_DMA_contig)
+	if (cam->buffer_mode == B_DMA_CONTIG)
 		alloc_ctxs[0] = cam->vb_alloc_ctx;
 	return 0;
 }
@@ -1144,7 +1144,7 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 	 * destination.  So go into a wait state and hope they
 	 * give us buffers soon.
 	 */
-	if (cam->buffer_mode != B_vmalloc && list_empty(&cam->buffers)) {
+	if (cam->buffer_mode != B_VMALLOC && list_empty(&cam->buffers)) {
 		cam->state = S_BUFWAIT;
 		return 0;
 	}
@@ -1285,7 +1285,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 	vq->drv_priv = cam;
 	INIT_LIST_HEAD(&cam->buffers);
 	switch (cam->buffer_mode) {
-	case B_DMA_contig:
+	case B_DMA_CONTIG:
 #ifdef MCAM_MODE_DMA_CONTIG
 		vq->ops = &mcam_vb2_ops;
 		vq->mem_ops = &vb2_dma_contig_memops;
@@ -1295,7 +1295,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 		cam->frame_complete = mcam_dma_contig_done;
 #endif
 		break;
-	case B_DMA_sg:
+	case B_DMA_SG:
 #ifdef MCAM_MODE_DMA_SG
 		vq->ops = &mcam_vb2_sg_ops;
 		vq->mem_ops = &vb2_dma_sg_memops;
@@ -1304,7 +1304,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 		cam->frame_complete = mcam_dma_sg_done;
 #endif
 		break;
-	case B_vmalloc:
+	case B_VMALLOC:
 #ifdef MCAM_MODE_VMALLOC
 		tasklet_init(&cam->s_tasklet, mcam_frame_tasklet,
 				(unsigned long) cam);
@@ -1324,7 +1324,7 @@ static void mcam_cleanup_vb2(struct mcam_camera *cam)
 {
 	vb2_queue_release(&cam->vb_queue);
 #ifdef MCAM_MODE_DMA_CONTIG
-	if (cam->buffer_mode == B_DMA_contig)
+	if (cam->buffer_mode == B_DMA_CONTIG)
 		vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx);
 #endif
 }
@@ -1536,7 +1536,7 @@ static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
 	/*
 	 * Make sure we have appropriate DMA buffers.
 	 */
-	if (cam->buffer_mode == B_vmalloc) {
+	if (cam->buffer_mode == B_VMALLOC) {
 		ret = mcam_check_dma_buffers(cam);
 		if (ret)
 			goto out;
@@ -1774,7 +1774,7 @@ static int mcam_v4l_release(struct file *filp)
 		mcam_cleanup_vb2(cam);
 		mcam_config_mipi(cam, 0);
 		mcam_ctlr_power_down(cam);
-		if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read)
+		if (cam->buffer_mode == B_VMALLOC && alloc_bufs_at_read)
 			mcam_free_dma_bufs(cam);
 	}
 	if (cam->bus_type == V4L2_MBUS_CSI2) {
@@ -1902,7 +1902,7 @@ int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
 			mcam_frame_complete(cam, frame);
 			handled = 1;
 			clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
-			if (cam->buffer_mode == B_DMA_sg)
+			if (cam->buffer_mode == B_DMA_SG)
 				break;
 		}
 	/*
@@ -1919,7 +1919,7 @@ int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
 
 	if (handled == IRQ_HANDLED) {
 		set_bit(CF_DMA_ACTIVE, &cam->flags);
-		if (cam->buffer_mode == B_DMA_sg)
+		if (cam->buffer_mode == B_DMA_SG)
 			mcam_ctlr_stop(cam);
 	}
 	return handled;
@@ -1953,11 +1953,11 @@ int mccic_register(struct mcam_camera *cam)
 	 */
 	if (buffer_mode >= 0)
 		cam->buffer_mode = buffer_mode;
-	if (cam->buffer_mode == B_DMA_sg &&
+	if (cam->buffer_mode == B_DMA_SG &&
 			cam->chip_id == V4L2_IDENT_CAFE) {
 		printk(KERN_ERR "marvell-cam: Cafe can't do S/G I/O, "
 			"attempting vmalloc mode instead\n");
-		cam->buffer_mode = B_vmalloc;
+		cam->buffer_mode = B_VMALLOC;
 	}
 	if (!mcam_buffer_mode_supported(cam->buffer_mode)) {
 		printk(KERN_ERR "marvell-cam: buffer mode %d unsupported\n",
@@ -2010,7 +2010,7 @@ int mccic_register(struct mcam_camera *cam)
 	/*
 	 * If so requested, try to get our DMA buffers now.
 	 */
-	if (cam->buffer_mode == B_vmalloc && !alloc_bufs_at_read) {
+	if (cam->buffer_mode == B_VMALLOC && !alloc_bufs_at_read) {
 		if (mcam_alloc_dma_bufs(cam, 1))
 			cam_warn(cam, "Unable to alloc DMA buffers at load"
 					" will try again later.");
@@ -2038,7 +2038,7 @@ void mccic_shutdown(struct mcam_camera *cam)
 		mcam_ctlr_power_down(cam);
 	}
 	vb2_queue_release(&cam->vb_queue);
-	if (cam->buffer_mode == B_vmalloc)
+	if (cam->buffer_mode == B_VMALLOC)
 		mcam_free_dma_bufs(cam);
 	video_unregister_device(&cam->vdev);
 	v4l2_device_unregister(&cam->v4l2_dev);
@@ -2081,7 +2081,7 @@ int mccic_resume(struct mcam_camera *cam)
 		 * If there was a buffer in the DMA engine at suspend
 		 * time, put it back on the queue or we'll forget about it.
 		 */
-		if (cam->buffer_mode == B_DMA_sg && cam->vb_bufs[0])
+		if (cam->buffer_mode == B_DMA_SG && cam->vb_bufs[0])
 			list_add(&cam->vb_bufs[0]->queue, &cam->buffers);
 		ret = mcam_read_setup(cam);
 	}
drivers/media/platform/marvell-ccic/mcam-core.h +6 -6
index 692727d..263767e 100755
@@ -47,9 +47,9 @@ enum mcam_state {
  * let the platform pick.
  */
 enum mcam_buffer_mode {
-	B_vmalloc = 0,
-	B_DMA_contig = 1,
-	B_DMA_sg = 2
+	B_VMALLOC = 0,
+	B_DMA_CONTIG = 1,
+	B_DMA_SG = 2
 };
 
 /*
@@ -59,13 +59,13 @@ static inline int mcam_buffer_mode_supported(enum mcam_buffer_mode mode)
 {
 	switch (mode) {
 #ifdef MCAM_MODE_VMALLOC
-	case B_vmalloc:
+	case B_VMALLOC:
 #endif
 #ifdef MCAM_MODE_DMA_CONTIG
-	case B_DMA_contig:
+	case B_DMA_CONTIG:
 #endif
 #ifdef MCAM_MODE_DMA_SG
-	case B_DMA_sg:
+	case B_DMA_SG:
 #endif
 		return 1;
 	default:
drivers/media/platform/marvell-ccic/mmp-driver.c +1 -1
index d355840..89dd078 100755
@@ -365,7 +365,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->mipi_enabled = 0;
 	mcam->lane = pdata->lane;
 	mcam->chip_id = V4L2_IDENT_ARMADA610;
-	mcam->buffer_mode = B_DMA_sg;
+	mcam->buffer_mode = B_DMA_SG;
 	spin_lock_init(&mcam->dev_lock);
 	/*
 	 * Get our I/O memory.
Signature · 1 line
1.7.9.5
Acked-by on v4 8/12
#24 lore raw

Re: [REVIEW PATCH V4 08/12] [media] marvell-ccic: rename B_DMA* to avoid CamelCase warning

Quoted 6 lines · Albert Wang

This patch renames the B_vmalloc/B_DMA_contig/B_DMA_sg to B_VMALLOC/B_DMA_CONTIG/B_DMA_SG variables to avoid CamelCase warning reported by the checkpatch.pl script.

Thanks
Guennadi

Quoted 239 lines
---
 drivers/media/platform/marvell-ccic/cafe-driver.c |    2 +-
 drivers/media/platform/marvell-ccic/mcam-core.c   |   38 ++++++++++-----------
 drivers/media/platform/marvell-ccic/mcam-core.h   |   12 +++----
 drivers/media/platform/marvell-ccic/mmp-driver.c  |    2 +-
 4 files changed, 27 insertions(+), 27 deletions(-)
drivers/media/platform/marvell-ccic/cafe-driver.c +1 -1
index d030f9b..f85f119 100755
@@ -486,7 +486,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
 	 * We *might* be able to run DMA_contig, especially on a system
 	 * with CMA in it.
 	 */
-	mcam->buffer_mode = B_vmalloc;
+	mcam->buffer_mode = B_VMALLOC;
 	/*
 	 * Get set up on the PCI bus.
 	 */
drivers/media/platform/marvell-ccic/mcam-core.c +19 -19
index 29c68f1..939c430 100755
@@ -554,7 +554,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 }
 
 /*
- * Initial B_DMA_contig setup.
+ * Initial B_DMA_CONTIG setup.
  */
 static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 {
@@ -611,7 +611,7 @@ static void mcam_sg_next_buffer(struct mcam_camera *cam)
 }
 
 /*
- * Initial B_DMA_sg setup
+ * Initial B_DMA_SG setup
  */
 static void mcam_ctlr_dma_sg(struct mcam_camera *cam)
 {
@@ -1005,7 +1005,7 @@ static int mcam_read_setup(struct mcam_camera *cam)
 	 * Configuration.  If we still don't have DMA buffers,
 	 * make one last, desperate attempt.
 	 */
-	if (cam->buffer_mode == B_vmalloc && cam->nbufs == 0 &&
+	if (cam->buffer_mode == B_VMALLOC && cam->nbufs == 0 &&
 			mcam_alloc_dma_bufs(cam, 0))
 		return -ENOMEM;
 
@@ -1051,13 +1051,13 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 		void *alloc_ctxs[])
 {
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
-	int minbufs = (cam->buffer_mode == B_DMA_contig) ? 3 : 2;
+	int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
 
 	sizes[0] = cam->pix_format.sizeimage;
 	*num_planes = 1; /* Someday we have to support planar formats... */
 	if (*nbufs < minbufs)
 		*nbufs = minbufs;
-	if (cam->buffer_mode == B_DMA_contig)
+	if (cam->buffer_mode == B_DMA_CONTIG)
 		alloc_ctxs[0] = cam->vb_alloc_ctx;
 	return 0;
 }
@@ -1144,7 +1144,7 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 	 * destination.  So go into a wait state and hope they
 	 * give us buffers soon.
 	 */
-	if (cam->buffer_mode != B_vmalloc && list_empty(&cam->buffers)) {
+	if (cam->buffer_mode != B_VMALLOC && list_empty(&cam->buffers)) {
 		cam->state = S_BUFWAIT;
 		return 0;
 	}
@@ -1285,7 +1285,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 	vq->drv_priv = cam;
 	INIT_LIST_HEAD(&cam->buffers);
 	switch (cam->buffer_mode) {
-	case B_DMA_contig:
+	case B_DMA_CONTIG:
 #ifdef MCAM_MODE_DMA_CONTIG
 		vq->ops = &mcam_vb2_ops;
 		vq->mem_ops = &vb2_dma_contig_memops;
@@ -1295,7 +1295,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 		cam->frame_complete = mcam_dma_contig_done;
 #endif
 		break;
-	case B_DMA_sg:
+	case B_DMA_SG:
 #ifdef MCAM_MODE_DMA_SG
 		vq->ops = &mcam_vb2_sg_ops;
 		vq->mem_ops = &vb2_dma_sg_memops;
@@ -1304,7 +1304,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 		cam->frame_complete = mcam_dma_sg_done;
 #endif
 		break;
-	case B_vmalloc:
+	case B_VMALLOC:
 #ifdef MCAM_MODE_VMALLOC
 		tasklet_init(&cam->s_tasklet, mcam_frame_tasklet,
 				(unsigned long) cam);
@@ -1324,7 +1324,7 @@ static void mcam_cleanup_vb2(struct mcam_camera *cam)
 {
 	vb2_queue_release(&cam->vb_queue);
 #ifdef MCAM_MODE_DMA_CONTIG
-	if (cam->buffer_mode == B_DMA_contig)
+	if (cam->buffer_mode == B_DMA_CONTIG)
 		vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx);
 #endif
 }
@@ -1536,7 +1536,7 @@ static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
 	/*
 	 * Make sure we have appropriate DMA buffers.
 	 */
-	if (cam->buffer_mode == B_vmalloc) {
+	if (cam->buffer_mode == B_VMALLOC) {
 		ret = mcam_check_dma_buffers(cam);
 		if (ret)
 			goto out;
@@ -1774,7 +1774,7 @@ static int mcam_v4l_release(struct file *filp)
 		mcam_cleanup_vb2(cam);
 		mcam_config_mipi(cam, 0);
 		mcam_ctlr_power_down(cam);
-		if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read)
+		if (cam->buffer_mode == B_VMALLOC && alloc_bufs_at_read)
 			mcam_free_dma_bufs(cam);
 	}
 	if (cam->bus_type == V4L2_MBUS_CSI2) {
@@ -1902,7 +1902,7 @@ int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
 			mcam_frame_complete(cam, frame);
 			handled = 1;
 			clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
-			if (cam->buffer_mode == B_DMA_sg)
+			if (cam->buffer_mode == B_DMA_SG)
 				break;
 		}
 	/*
@@ -1919,7 +1919,7 @@ int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
 
 	if (handled == IRQ_HANDLED) {
 		set_bit(CF_DMA_ACTIVE, &cam->flags);
-		if (cam->buffer_mode == B_DMA_sg)
+		if (cam->buffer_mode == B_DMA_SG)
 			mcam_ctlr_stop(cam);
 	}
 	return handled;
@@ -1953,11 +1953,11 @@ int mccic_register(struct mcam_camera *cam)
 	 */
 	if (buffer_mode >= 0)
 		cam->buffer_mode = buffer_mode;
-	if (cam->buffer_mode == B_DMA_sg &&
+	if (cam->buffer_mode == B_DMA_SG &&
 			cam->chip_id == V4L2_IDENT_CAFE) {
 		printk(KERN_ERR "marvell-cam: Cafe can't do S/G I/O, "
 			"attempting vmalloc mode instead\n");
-		cam->buffer_mode = B_vmalloc;
+		cam->buffer_mode = B_VMALLOC;
 	}
 	if (!mcam_buffer_mode_supported(cam->buffer_mode)) {
 		printk(KERN_ERR "marvell-cam: buffer mode %d unsupported\n",
@@ -2010,7 +2010,7 @@ int mccic_register(struct mcam_camera *cam)
 	/*
 	 * If so requested, try to get our DMA buffers now.
 	 */
-	if (cam->buffer_mode == B_vmalloc && !alloc_bufs_at_read) {
+	if (cam->buffer_mode == B_VMALLOC && !alloc_bufs_at_read) {
 		if (mcam_alloc_dma_bufs(cam, 1))
 			cam_warn(cam, "Unable to alloc DMA buffers at load"
 					" will try again later.");
@@ -2038,7 +2038,7 @@ void mccic_shutdown(struct mcam_camera *cam)
 		mcam_ctlr_power_down(cam);
 	}
 	vb2_queue_release(&cam->vb_queue);
-	if (cam->buffer_mode == B_vmalloc)
+	if (cam->buffer_mode == B_VMALLOC)
 		mcam_free_dma_bufs(cam);
 	video_unregister_device(&cam->vdev);
 	v4l2_device_unregister(&cam->v4l2_dev);
@@ -2081,7 +2081,7 @@ int mccic_resume(struct mcam_camera *cam)
 		 * If there was a buffer in the DMA engine at suspend
 		 * time, put it back on the queue or we'll forget about it.
 		 */
-		if (cam->buffer_mode == B_DMA_sg && cam->vb_bufs[0])
+		if (cam->buffer_mode == B_DMA_SG && cam->vb_bufs[0])
 			list_add(&cam->vb_bufs[0]->queue, &cam->buffers);
 		ret = mcam_read_setup(cam);
 	}
drivers/media/platform/marvell-ccic/mcam-core.h +6 -6
index 692727d..263767e 100755
@@ -47,9 +47,9 @@ enum mcam_state {
  * let the platform pick.
  */
 enum mcam_buffer_mode {
-	B_vmalloc = 0,
-	B_DMA_contig = 1,
-	B_DMA_sg = 2
+	B_VMALLOC = 0,
+	B_DMA_CONTIG = 1,
+	B_DMA_SG = 2
 };
 
 /*
@@ -59,13 +59,13 @@ static inline int mcam_buffer_mode_supported(enum mcam_buffer_mode mode)
 {
 	switch (mode) {
 #ifdef MCAM_MODE_VMALLOC
-	case B_vmalloc:
+	case B_VMALLOC:
 #endif
 #ifdef MCAM_MODE_DMA_CONTIG
-	case B_DMA_contig:
+	case B_DMA_CONTIG:
 #endif
 #ifdef MCAM_MODE_DMA_SG
-	case B_DMA_sg:
+	case B_DMA_SG:
 #endif
 		return 1;
 	default:
drivers/media/platform/marvell-ccic/mmp-driver.c +1 -1
index d355840..89dd078 100755
@@ -365,7 +365,7 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->mipi_enabled = 0;
 	mcam->lane = pdata->lane;
 	mcam->chip_id = V4L2_IDENT_ARMADA610;
-	mcam->buffer_mode = B_DMA_sg;
+	mcam->buffer_mode = B_DMA_SG;
 	spin_lock_init(&mcam->dev_lock);
 	/*
 	 * Get our I/O memory.
Signature · 1 line
1.7.9.5

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#25 lore raw

PATCH v4 9/12 marvell-ccic: use unsigned int type replace int type

In reply to Albert Wang

This patch uses unsigned int type replace int type in marvell-ccic. These variables: frame number, buf number, irq... should be unsigned.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   22 +++++++++++-----------
 drivers/media/platform/marvell-ccic/mcam-core.h  |    2 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c |    2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +11 -11
index 939c430..b668f2b 100755
@@ -233,7 +233,7 @@ static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb)
 /*
  * Hand a completed buffer back to user space.
  */
-static void mcam_buffer_done(struct mcam_camera *cam, int frame,
+static void mcam_buffer_done(struct mcam_camera *cam, unsigned int frame,
 		struct vb2_buffer *vbuf)
 {
 	vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage;
@@ -260,7 +260,7 @@ static void mcam_buffer_done(struct mcam_camera *cam, int frame,
  */
 static void mcam_reset_buffers(struct mcam_camera *cam)
 {
-	int i;
+	unsigned int i;
 
 	cam->next_buf = -1;
 	for (i = 0; i < cam->nbufs; i++) {
@@ -344,7 +344,7 @@ static int mcam_config_mipi(struct mcam_camera *mcam, int enable)
  */
 static int mcam_alloc_dma_bufs(struct mcam_camera *cam, int loadtime)
 {
-	int i;
+	unsigned int i;
 
 	mcam_set_config_needed(cam, 1);
 	if (loadtime)
@@ -385,7 +385,7 @@ static int mcam_alloc_dma_bufs(struct mcam_camera *cam, int loadtime)
 
 static void mcam_free_dma_bufs(struct mcam_camera *cam)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < cam->nbufs; i++) {
 		dma_free_coherent(cam->dev, cam->dma_buf_size,
@@ -424,7 +424,7 @@ static void mcam_ctlr_dma_vmalloc(struct mcam_camera *cam)
 static void mcam_frame_tasklet(unsigned long data)
 {
 	struct mcam_camera *cam = (struct mcam_camera *) data;
-	int i;
+	unsigned int i;
 	unsigned long flags;
 	struct mcam_vb_buffer *buf;
 
@@ -472,7 +472,7 @@ static int mcam_check_dma_buffers(struct mcam_camera *cam)
 	return 0;
 }
 
-static void mcam_vmalloc_done(struct mcam_camera *cam, int frame)
+static void mcam_vmalloc_done(struct mcam_camera *cam, unsigned int frame)
 {
 	tasklet_schedule(&cam->s_tasklet);
 }
@@ -521,7 +521,7 @@ static bool mcam_fmt_is_planar(__u32 pfmt)
  * space.  In this way, we always have a buffer to DMA to and don't
  * have to try to play games stopping and restarting the controller.
  */
-static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
+static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
@@ -567,7 +567,7 @@ static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 /*
  * Frame completion handling.
  */
-static void mcam_dma_contig_done(struct mcam_camera *cam, int frame)
+static void mcam_dma_contig_done(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf = cam->vb_bufs[frame];
 
@@ -643,7 +643,7 @@ static void mcam_ctlr_dma_sg(struct mcam_camera *cam)
  * safely change the DMA descriptor array here and restart things
  * (assuming there's another buffer waiting to go).
  */
-static void mcam_dma_sg_done(struct mcam_camera *cam, int frame)
+static void mcam_dma_sg_done(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf = cam->vb_bufs[0];
 
@@ -1051,7 +1051,7 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 		void *alloc_ctxs[])
 {
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
-	int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
+	unsigned int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
 
 	sizes[0] = cam->pix_format.sizeimage;
 	*num_planes = 1; /* Someday we have to support planar formats... */
@@ -1855,7 +1855,7 @@ static struct video_device mcam_v4l_template = {
 /*
  * Interrupt handler stuff
  */
-static void mcam_frame_complete(struct mcam_camera *cam, int frame)
+static void mcam_frame_complete(struct mcam_camera *cam, unsigned int frame)
 {
 	/*
 	 * Basic frame housekeeping.
drivers/media/platform/marvell-ccic/mcam-core.h +1 -1
index 263767e..4cb68e0 100755
@@ -163,7 +163,7 @@ struct mcam_camera {
 
 	/* Mode-specific ops, set at open time */
 	void (*dma_setup)(struct mcam_camera *cam);
-	void (*frame_complete)(struct mcam_camera *cam, int frame);
+	void (*frame_complete)(struct mcam_camera *cam, unsigned int frame);
 
 	/* Current operating parameters */
 	u32 sensor_type;		/* Currently ov7670 only */
drivers/media/platform/marvell-ccic/mmp-driver.c +1 -1
index 89dd078..732af16 100755
@@ -42,7 +42,7 @@ struct mmp_camera {
 	struct platform_device *pdev;
 	struct mcam_camera mcam;
 	struct list_head devlist;
-	int irq;
+	unsigned int irq;
 };
 
 static inline struct mmp_camera *mcam_to_cam(struct mcam_camera *mcam)
Signature · 1 line
1.7.9.5
#26 lore raw

Re: [REVIEW PATCH V4 09/12] [media] marvell-ccic: use unsigned int type replace int type

I'm not against this patch, but I don't see a lot of meaning in it either, apart from the .irq part - that makes the type match *request_*irq() prototypes. Apart from that... Using "int i" for a simple iterator, that doesn't go beyond INT_MAX is kinda traditional, I think. You change int frame to unsigned, but if you look at mcam_buffer_done(), as it is called from mcam_frame_tasklet(), the

		int bufno = cam->next_buf;

variable is used for its second parameter (int frame). And ->next_buf is declared as (signed) int, and can indeed be negative in mcam_reset_buffers():

	cam->next_buf = -1;

So... You might need to be more careful with those changes, if you _really_ need them. Otherwise, unless there are real reasons, like matching an existing API, avoiding warnings, I'd really just drop all this, perhaps, apart from ->irq.

Thanks
Guennadi

Quoted 144 lines · Albert Wang

This patch uses unsigned int type replace int type in marvell-ccic. These variables: frame number, buf number, irq... should be unsigned.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   22 +++++++++++-----------
 drivers/media/platform/marvell-ccic/mcam-core.h  |    2 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c |    2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +11 -11
index 939c430..b668f2b 100755
@@ -233,7 +233,7 @@ static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb)
 /*
  * Hand a completed buffer back to user space.
  */
-static void mcam_buffer_done(struct mcam_camera *cam, int frame,
+static void mcam_buffer_done(struct mcam_camera *cam, unsigned int frame,
 		struct vb2_buffer *vbuf)
 {
 	vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage;
@@ -260,7 +260,7 @@ static void mcam_buffer_done(struct mcam_camera *cam, int frame,
  */
 static void mcam_reset_buffers(struct mcam_camera *cam)
 {
-	int i;
+	unsigned int i;
 
 	cam->next_buf = -1;
 	for (i = 0; i < cam->nbufs; i++) {
@@ -344,7 +344,7 @@ static int mcam_config_mipi(struct mcam_camera *mcam, int enable)
  */
 static int mcam_alloc_dma_bufs(struct mcam_camera *cam, int loadtime)
 {
-	int i;
+	unsigned int i;
 
 	mcam_set_config_needed(cam, 1);
 	if (loadtime)
@@ -385,7 +385,7 @@ static int mcam_alloc_dma_bufs(struct mcam_camera *cam, int loadtime)
 
 static void mcam_free_dma_bufs(struct mcam_camera *cam)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < cam->nbufs; i++) {
 		dma_free_coherent(cam->dev, cam->dma_buf_size,
@@ -424,7 +424,7 @@ static void mcam_ctlr_dma_vmalloc(struct mcam_camera *cam)
 static void mcam_frame_tasklet(unsigned long data)
 {
 	struct mcam_camera *cam = (struct mcam_camera *) data;
-	int i;
+	unsigned int i;
 	unsigned long flags;
 	struct mcam_vb_buffer *buf;
 
@@ -472,7 +472,7 @@ static int mcam_check_dma_buffers(struct mcam_camera *cam)
 	return 0;
 }
 
-static void mcam_vmalloc_done(struct mcam_camera *cam, int frame)
+static void mcam_vmalloc_done(struct mcam_camera *cam, unsigned int frame)
 {
 	tasklet_schedule(&cam->s_tasklet);
 }
@@ -521,7 +521,7 @@ static bool mcam_fmt_is_planar(__u32 pfmt)
  * space.  In this way, we always have a buffer to DMA to and don't
  * have to try to play games stopping and restarting the controller.
  */
-static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
+static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
@@ -567,7 +567,7 @@ static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 /*
  * Frame completion handling.
  */
-static void mcam_dma_contig_done(struct mcam_camera *cam, int frame)
+static void mcam_dma_contig_done(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf = cam->vb_bufs[frame];
 
@@ -643,7 +643,7 @@ static void mcam_ctlr_dma_sg(struct mcam_camera *cam)
  * safely change the DMA descriptor array here and restart things
  * (assuming there's another buffer waiting to go).
  */
-static void mcam_dma_sg_done(struct mcam_camera *cam, int frame)
+static void mcam_dma_sg_done(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf = cam->vb_bufs[0];
 
@@ -1051,7 +1051,7 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 		void *alloc_ctxs[])
 {
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
-	int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
+	unsigned int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
 
 	sizes[0] = cam->pix_format.sizeimage;
 	*num_planes = 1; /* Someday we have to support planar formats... */
@@ -1855,7 +1855,7 @@ static struct video_device mcam_v4l_template = {
 /*
  * Interrupt handler stuff
  */
-static void mcam_frame_complete(struct mcam_camera *cam, int frame)
+static void mcam_frame_complete(struct mcam_camera *cam, unsigned int frame)
 {
 	/*
 	 * Basic frame housekeeping.
drivers/media/platform/marvell-ccic/mcam-core.h +1 -1
index 263767e..4cb68e0 100755
@@ -163,7 +163,7 @@ struct mcam_camera {
 
 	/* Mode-specific ops, set at open time */
 	void (*dma_setup)(struct mcam_camera *cam);
-	void (*frame_complete)(struct mcam_camera *cam, int frame);
+	void (*frame_complete)(struct mcam_camera *cam, unsigned int frame);
 
 	/* Current operating parameters */
 	u32 sensor_type;		/* Currently ov7670 only */
drivers/media/platform/marvell-ccic/mmp-driver.c +1 -1
index 89dd078..732af16 100755
@@ -42,7 +42,7 @@ struct mmp_camera {
 	struct platform_device *pdev;
 	struct mcam_camera mcam;
 	struct list_head devlist;
-	int irq;
+	unsigned int irq;
 };
 
 static inline struct mmp_camera *mcam_to_cam(struct mcam_camera *mcam)
Signature · 1 line
1.7.9.5

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#27 lore raw

RE: [REVIEW PATCH V4 09/12] [media] marvell-ccic: use unsigned int type replace int type

Hi, Guennadi

Quoted 21 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 18:43
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 09/12] [media] marvell-ccic: use unsigned int type replace int type

I'm not against this patch, but I don't see a lot of meaning in it either, apart from the .irq part - that makes the type match *request_*irq() prototypes. Apart from that... Using "int i" for a simple iterator, that doesn't go beyond INT_MAX is kinda traditional, I think. You change int frame to unsigned, but if you look at mcam_buffer_done(), as it is called from mcam_frame_tasklet(), the

		int bufno = cam->next_buf;

variable is used for its second parameter (int frame). And ->next_buf is declared as (signed) int, and can indeed be negative in mcam_reset_buffers():

Quoted 7 lines
	cam->next_buf = -1;

So... You might need to be more careful with those changes, if you _really_ need them. Otherwise, unless there are real reasons, like matching an existing API, avoiding warnings, I'd really just drop all this, perhaps, apart from ->irq.

Actually, this patch is prepared for [PATCH 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode In that patch we need do that calculate with frame:
buf = cam->vb_bufs[(frame + (MAX_FRAME_BUFS - 1)) % MAX_FRAME_BUFS];

So we think frame should be unsigned from the original meaning.

But sometimes buffer number may be negative for some special design, I leave them alone.

So how about we change to keep buffer number with original definition if you think there is no meaning to change it and just change frame number and irq?

Quoted 154 lines

Thanks
Guennadi

Quoted 6 lines · Albert Wang

This patch uses unsigned int type replace int type in marvell-ccic. These variables: frame number, buf number, irq... should be unsigned.

Review

Quoted 7 lines
---
 drivers/media/platform/marvell-ccic/mcam-core.c  |   22 +++++++++++-----------
 drivers/media/platform/marvell-ccic/mcam-core.h  |    2 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c |    2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.c

drivers/media/platform/marvell-ccic/mcam-core.c static inline struct mcam_vb_buffer *vb_to_mvb(struct

Quoted 4 lines

index 939c430..b668f2b 100755

drivers/media/platform/marvell-ccic/mcam-core.c +0 -0
@@ -233,7 +233,7 @@ static inline struct mcam_vb_buffer *vb_to_mvb(struct

vb2_buffer *vb)

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_buffer_done(struct mcam_camera *cam, int

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -1
 /*
  * Hand a completed buffer back to user space.
  */
-static void mcam_buffer_done(struct mcam_camera *cam, int frame,
+static void mcam_buffer_done(struct mcam_camera *cam, unsigned int frame,
 		struct vb2_buffer *vbuf)
 {
 	vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage;
@@ -260,7 +260,7 @@ static void mcam_buffer_done(struct mcam_camera *cam, int

frame,

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_config_mipi(struct mcam_camera *mcam, int

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -1
  */
 static void mcam_reset_buffers(struct mcam_camera *cam)
 {
-	int i;
+	unsigned int i;
 
 	cam->next_buf = -1;
 	for (i = 0; i < cam->nbufs; i++) {
@@ -344,7 +344,7 @@ static int mcam_config_mipi(struct mcam_camera *mcam, int

enable)

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_alloc_dma_bufs(struct mcam_camera *cam,

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -1
  */
 static int mcam_alloc_dma_bufs(struct mcam_camera *cam, int loadtime)
 {
-	int i;
+	unsigned int i;
 
 	mcam_set_config_needed(cam, 1);
 	if (loadtime)
@@ -385,7 +385,7 @@ static int mcam_alloc_dma_bufs(struct mcam_camera *cam,

int loadtime)

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_ctlr_dma_vmalloc(struct mcam_camera

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -1
 static void mcam_free_dma_bufs(struct mcam_camera *cam)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < cam->nbufs; i++) {
 		dma_free_coherent(cam->dev, cam->dma_buf_size,
@@ -424,7 +424,7 @@ static void mcam_ctlr_dma_vmalloc(struct mcam_camera

*cam)

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_check_dma_buffers(struct mcam_camera

Quoted 9 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -1
 static void mcam_frame_tasklet(unsigned long data)
 {
 	struct mcam_camera *cam = (struct mcam_camera *) data;
-	int i;
+	unsigned int i;
 	unsigned long flags;
 	struct mcam_vb_buffer *buf;
 
@@ -472,7 +472,7 @@ static int mcam_check_dma_buffers(struct mcam_camera

*cam)

Review

Quoted 54 lines
drivers/media/platform/marvell-ccic/mcam-core.c +6 -6
 	return 0;
 }
 
-static void mcam_vmalloc_done(struct mcam_camera *cam, int frame)
+static void mcam_vmalloc_done(struct mcam_camera *cam, unsigned int frame)
 {
 	tasklet_schedule(&cam->s_tasklet);
 }
@@ -521,7 +521,7 @@ static bool mcam_fmt_is_planar(__u32 pfmt)
  * space.  In this way, we always have a buffer to DMA to and don't
  * have to try to play games stopping and restarting the controller.
  */
-static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
+static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
@@ -567,7 +567,7 @@ static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 /*
  * Frame completion handling.
  */
-static void mcam_dma_contig_done(struct mcam_camera *cam, int frame)
+static void mcam_dma_contig_done(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf = cam->vb_bufs[frame];
 
@@ -643,7 +643,7 @@ static void mcam_ctlr_dma_sg(struct mcam_camera *cam)
  * safely change the DMA descriptor array here and restart things
  * (assuming there's another buffer waiting to go).
  */
-static void mcam_dma_sg_done(struct mcam_camera *cam, int frame)
+static void mcam_dma_sg_done(struct mcam_camera *cam, unsigned int frame)
 {
 	struct mcam_vb_buffer *buf = cam->vb_bufs[0];
 
@@ -1051,7 +1051,7 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 		void *alloc_ctxs[])
 {
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
-	int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
+	unsigned int minbufs = (cam->buffer_mode == B_DMA_CONTIG) ? 3 : 2;
 
 	sizes[0] = cam->pix_format.sizeimage;
 	*num_planes = 1; /* Someday we have to support planar formats... */
@@ -1855,7 +1855,7 @@ static struct video_device mcam_v4l_template = {
 /*
  * Interrupt handler stuff
  */
-static void mcam_frame_complete(struct mcam_camera *cam, int frame)
+static void mcam_frame_complete(struct mcam_camera *cam, unsigned int frame)
 {
 	/*
 	 * Basic frame housekeeping.
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.h

Review

Quoted 13 lines

index 263767e..4cb68e0 100755

drivers/media/platform/marvell-ccic/mcam-core.h +1 -1
@@ -163,7 +163,7 @@ struct mcam_camera {
 
 	/* Mode-specific ops, set at open time */
 	void (*dma_setup)(struct mcam_camera *cam);
-	void (*frame_complete)(struct mcam_camera *cam, int frame);
+	void (*frame_complete)(struct mcam_camera *cam, unsigned int frame);
 
 	/* Current operating parameters */
 	u32 sensor_type;		/* Currently ov7670 only */
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mmp-driver.c

Quoted 11 lines

index 89dd078..732af16 100755

drivers/media/platform/marvell-ccic/mmp-driver.c +1 -1
@@ -42,7 +42,7 @@ struct mmp_camera {
 	struct platform_device *pdev;
 	struct mcam_camera mcam;
 	struct list_head devlist;
-	int irq;
+	unsigned int irq;
 };
 
Quoted 9 lines
Quoted 4 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +0 -1
 static inline struct mmp_camera *mcam_to_cam(struct mcam_camera *mcam)
--

1.7.9.5

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#28 lore raw

RE: [REVIEW PATCH V4 09/12] [media] marvell-ccic: use unsigned int type replace int type

Quoted 36 lines · Albert Wang

Hi, Guennadi

Quoted 21 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 18:43
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 09/12] [media] marvell-ccic: use unsigned int type replace int type

I'm not against this patch, but I don't see a lot of meaning in it either, apart from the .irq part - that makes the type match *request_*irq() prototypes. Apart from that... Using "int i" for a simple iterator, that doesn't go beyond INT_MAX is kinda traditional, I think. You change int frame to unsigned, but if you look at mcam_buffer_done(), as it is called from mcam_frame_tasklet(), the

		int bufno = cam->next_buf;

variable is used for its second parameter (int frame). And ->next_buf is declared as (signed) int, and can indeed be negative in mcam_reset_buffers():

Quoted 7 lines
	cam->next_buf = -1;

So... You might need to be more careful with those changes, if you _really_ need them. Otherwise, unless there are real reasons, like matching an existing API, avoiding warnings, I'd really just drop all this, perhaps, apart from ->irq.

Actually, this patch is prepared for [PATCH 12/12] [media] marvell-ccic:
add 3 frame buffers support in DMA_CONTIG mode
In that patch we need do that calculate with frame:
buf = cam->vb_bufs[(frame + (MAX_FRAME_BUFS - 1)) % MAX_FRAME_BUFS];

Quoted 7 lines

So we think frame should be unsigned from the original meaning.

But sometimes buffer number may be negative for some special design, I leave them alone.

So how about we change to keep buffer number with original definition if you think there is no meaning to change it and just change frame number and irq?

Sounds good to me!

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#29 lore raw

PATCH v4 10/12 marvell-ccic: add soc_camera support for marvell-ccic driver

In reply to Albert Wang

This patch adds the soc_camera mode support in marvell-ccic driver. It also removes the old mode for maintaining single mode in the future.

---
 drivers/media/platform/Makefile                  |    4 +-
 drivers/media/platform/marvell-ccic/Kconfig      |    6 +-
 drivers/media/platform/marvell-ccic/mcam-core.c  | 1084 +++++++---------------
 drivers/media/platform/marvell-ccic/mcam-core.h  |   27 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c |   73 +-
 include/media/mmp-camera.h                       |    5 +
 6 files changed, 402 insertions(+), 797 deletions(-)
drivers/media/platform/Makefile +2 -2
index 4817d28..1a345c8 100644
@@ -11,8 +11,6 @@ obj-$(CONFIG_VIDEO_TIMBERDALE)	+= timblogiw.o
 obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
 
 obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
-obj-$(CONFIG_VIDEO_CAFE_CCIC) += marvell-ccic/
-obj-$(CONFIG_VIDEO_MMP_CAMERA) += marvell-ccic/
 
 obj-$(CONFIG_VIDEO_OMAP2)		+= omap2cam.o
 obj-$(CONFIG_VIDEO_OMAP3)	+= omap3isp/
@@ -43,6 +41,8 @@ obj-$(CONFIG_ARCH_DAVINCI)		+= davinci/
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
 
 obj-$(CONFIG_SOC_CAMERA)		+= soc_camera/
+obj-$(CONFIG_VIDEO_CAFE_CCIC)		+= marvell-ccic/
+obj-$(CONFIG_VIDEO_MMP_CAMERA)		+= marvell-ccic/
 
 obj-y	+= davinci/
 
drivers/media/platform/marvell-ccic/Kconfig +3 -3
index bf739e3..7fa3c62 100755
@@ -10,14 +10,14 @@ config VIDEO_CAFE_CCIC
 	  generation OLPC systems.
 
 config VIDEO_MMP_CAMERA
-	tristate "Marvell Armada 610 integrated camera controller support"
+	tristate "Marvell Armada integrated camera controller support"
 	depends on ARCH_MMP && I2C && VIDEO_V4L2
-	select VIDEO_OV7670
 	select I2C_GPIO
+	select VIDEOBUF2_DMA_CONTIG
 	select VIDEOBUF2_DMA_SG
 	---help---
 	  This is a Video4Linux2 driver for the integrated camera
-	  controller found on Marvell Armada 610 application
+	  controller found on Marvell Armada application
 	  processors (and likely beyond).  This is the controller found
 	  in OLPC XO 1.75 systems.
 
drivers/media/platform/marvell-ccic/mcam-core.c +356 -728

1,318 lines not on this page · raw message

drivers/media/platform/marvell-ccic/mcam-core.h +19 -8
index 4cb68e0..12af7d2 100755
@@ -10,6 +10,8 @@
 #include <media/v4l2-common.h>
 #include <media/v4l2-dev.h>
 #include <media/videobuf2-core.h>
+#include <media/soc_camera.h>
+#include <media/soc_mediabus.h>
 
 /*
  * Create our own symbols for the supported buffer modes, but, for now,
@@ -91,6 +93,8 @@ struct mcam_frame_state {
  *          dev_lock is also required for access to device registers.
  */
 struct mcam_camera {
+	struct soc_camera_host soc_host;
+	struct soc_camera_device *icd;
 	/*
 	 * These fields should be set by the platform code prior to
 	 * calling mcam_register().
@@ -104,6 +108,10 @@ struct mcam_camera {
 	short int use_smbus;	/* SMBUS or straight I2c? */
 	enum mcam_buffer_mode buffer_mode;
 
+	int mclk_min;
+	int mclk_src;
+	int mclk_div;
+	char *card_name;
 	int ccic_id;
 	enum v4l2_mbus_type bus_type;
 	/* MIPI support */
@@ -133,15 +141,8 @@ struct mcam_camera {
 	int users;			/* How many open FDs */
 
 	struct mcam_frame_state frame_state;	/* Frame state counter */
-	/*
-	 * Subsystem structures.
-	 */
-	struct video_device vdev;
-	struct v4l2_subdev *sensor;
-	unsigned short sensor_addr;
 
 	/* Videobuf2 stuff */
-	struct vb2_queue vb_queue;
 	struct list_head buffers;	/* Available frames */
 
 	unsigned int nbufs;		/* How many are alloc'd */
@@ -166,7 +167,6 @@ struct mcam_camera {
 	void (*frame_complete)(struct mcam_camera *cam, unsigned int frame);
 
 	/* Current operating parameters */
-	u32 sensor_type;		/* Currently ov7670 only */
 	struct v4l2_pix_format pix_format;
 	enum v4l2_mbus_pixelcode mbus_code;
 
@@ -216,6 +216,14 @@ static inline void mcam_reg_set_bit(struct mcam_camera *cam,
 	mcam_reg_write_mask(cam, reg, val, val);
 }
 
+static inline struct mcam_camera *vq_to_mcam(struct vb2_queue *vq)
+{
+	struct soc_camera_device *icd = container_of(vq,
+					struct soc_camera_device, vb2_vidq);
+	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
+	return ici->priv;
+}
+
 /*
  * Functions for use by platform code.
  */
@@ -258,6 +266,7 @@ int mccic_resume(struct mcam_camera *cam);
 #define   IMGP_YP_MASK	  0x00003ffc	/* Y pitch field */
 #define	  IMGP_UVP_SHFT	  18		/* UV pitch (planar) */
 #define   IMGP_UVP_MASK   0x3ffc0000
+/* Bits below IRQ_TWSI* are not present in mmp */
 #define REG_IRQSTATRAW	0x28	/* RAW IRQ Status */
 #define   IRQ_EOF0	  0x00000001	/* End of frame 0 */
 #define   IRQ_EOF1	  0x00000002	/* End of frame 1 */
@@ -333,6 +342,7 @@ int mccic_resume(struct mcam_camera *cam);
 /* Bits below C1_444ALPHA are not present in Cafe */
 #define REG_CTRL1	0x40	/* Control 1 */
 #define	  C1_CLKGATE	  0x00000001	/* Sensor clock gate */
+#define   C1_RESERVED	  0x0000003c	/* Reserved and shouldn't be changed */
 #define   C1_DESC_ENA	  0x00000100	/* DMA descriptor enable */
 #define   C1_DESC_3WORD   0x00000200	/* Three-word descriptors used */
 #define	  C1_444ALPHA	  0x00f00000	/* Alpha field in RGB444 */
@@ -343,6 +353,7 @@ int mccic_resume(struct mcam_camera *cam);
 #define	  C1_DMAB_MASK	  0x06000000
 #define	  C1_TWOBUFS	  0x08000000	/* Use only two DMA buffers */
 #define	  C1_PWRDWN	  0x10000000	/* Power down */
+#define   C1_DMAPOSTED	  0x40000000    /* DMA Posted Select */
 
 #define REG_CLKCTRL	0x88	/* Clock control */
 #define	  CLK_DIV_MASK	  0x0000ffff	/* Upper bits RW "reserved" */
drivers/media/platform/marvell-ccic/mmp-driver.c +17 -56

134 lines not on this page · raw message

include/media/mmp-camera.h +5 -0
index 813efe2..513d846 100755
@@ -7,7 +7,12 @@ struct mmp_camera_platform_data {
 	struct platform_device *i2c_device;
 	int sensor_power_gpio;
 	int sensor_reset_gpio;
+	char name[16];
 	enum v4l2_mbus_type bus_type;
+	int mclk_min;
+	int mclk_src;
+	int mclk_div;
+	int chip_id;
 	/*
 	 * MIPI support
 	 */
Signature · 1 line
1.7.9.5
Acked-by on v4 10/12
#30 lore raw

Re: [REVIEW PATCH V4 10/12] [media] marvell-ccic: add soc_camera support for marvell-ccic driver

Ok, can we test existing systems, have they been tested? It is hard to review this, as you might imagine. At least I don't think I can in any reasonably way verify by just looking at this whether it's breaking anything... I think, people, really using / developing this driver for other platforms would have to just extensively test this and verify the final result (I think I know one such person ;-)). A couple of minor comments below. In general - it does look quite good to me! So, provided relevant testing is done and, possibly, my comments addressed:

Thanks
Guennadi

Quoted 5 lines · Albert Wang

This patch adds the soc_camera mode support in marvell-ccic driver. It also removes the old mode for maintaining single mode in the future.

Quoted 8 lines
---
 drivers/media/platform/Makefile                  |    4 +-
 drivers/media/platform/marvell-ccic/Kconfig      |    6 +-
 drivers/media/platform/marvell-ccic/mcam-core.c  | 1084 +++++++---------------
 drivers/media/platform/marvell-ccic/mcam-core.h  |   27 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c |   73 +-
 include/media/mmp-camera.h                       |    5 +
 6 files changed, 402 insertions(+), 797 deletions(-)

At least the stats look good ;-)

Quoted 28 lines
drivers/media/platform/Makefile +2 -2
index 4817d28..1a345c8 100644
@@ -11,8 +11,6 @@ obj-$(CONFIG_VIDEO_TIMBERDALE)	+= timblogiw.o
 obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
 
 obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
-obj-$(CONFIG_VIDEO_CAFE_CCIC) += marvell-ccic/
-obj-$(CONFIG_VIDEO_MMP_CAMERA) += marvell-ccic/
 
 obj-$(CONFIG_VIDEO_OMAP2)		+= omap2cam.o
 obj-$(CONFIG_VIDEO_OMAP3)	+= omap3isp/
@@ -43,6 +41,8 @@ obj-$(CONFIG_ARCH_DAVINCI)		+= davinci/
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
 
 obj-$(CONFIG_SOC_CAMERA)		+= soc_camera/
+obj-$(CONFIG_VIDEO_CAFE_CCIC)		+= marvell-ccic/
+obj-$(CONFIG_VIDEO_MMP_CAMERA)		+= marvell-ccic/
 
 obj-y	+= davinci/
 
drivers/media/platform/marvell-ccic/Kconfig +0 -0
index bf739e3..7fa3c62 100755

drivers/media/platform/marvell-ccic/Kconfig config VIDEO_CAFE_CCIC · line 14

Quoted 6 lines
drivers/media/platform/marvell-ccic/Kconfig +1 -1
@@ -10,14 +10,14 @@ config VIDEO_CAFE_CCIC
 	  generation OLPC systems.
 
 config VIDEO_MMP_CAMERA
-	tristate "Marvell Armada 610 integrated camera controller support"
+	tristate "Marvell Armada integrated camera controller support"
 	depends on ARCH_MMP && I2C && VIDEO_V4L2

Perhaps, you want to add "&& SOC_CAMERA" above

Quoted 11 lines
drivers/media/platform/marvell-ccic/Kconfig +2 -2
-	select VIDEO_OV7670
 	select I2C_GPIO
+	select VIDEOBUF2_DMA_CONTIG
 	select VIDEOBUF2_DMA_SG
 	---help---
 	  This is a Video4Linux2 driver for the integrated camera
-	  controller found on Marvell Armada 610 application
+	  controller found on Marvell Armada application
 	  processors (and likely beyond).  This is the controller found
 	  in OLPC XO 1.75 systems.
 

[snip]

drivers/media/platform/marvell-ccic/mmp-driver.c line 31

Quoted 9 lines
drivers/media/platform/marvell-ccic/mmp-driver.c +1 -0
index 732af16..3d5db24 100755
@@ -28,6 +28,10 @@
 #include <linux/list.h>
 #include <linux/pm.h>
 #include <linux/clk.h>
+#include <linux/regulator/consumer.h>

Looks like you don't need this header.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#31 lore raw

RE: [REVIEW PATCH V4 10/12] [media] marvell-ccic: add soc_camera support for marvell-ccic driver

Hi, Guennadi

Quoted 8 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 21:33
To: Albert Wang
Cc: [email protected]; Linux Media Mailing List; Libin Yang
Subject: Re: [REVIEW PATCH V4 10/12] [media] marvell-ccic: add soc_camera support for marvell-ccic driver

Quoted 9 lines

Ok, can we test existing systems, have they been tested? It is hard to review this, as you might imagine. At least I don't think I can in any reasonably way verify by just looking at this whether it's breaking anything... I think, people, really using / developing this driver for other platforms would have to just extensively test this and verify the final result (I think I know one such person ;-)). A couple of minor comments below. In general - it does look quite good to me! So, provided relevant testing is done and, possibly, my comments addressed:

Actually, we have tested it on all Marvell platforms which we have. But we have no OLPC board on hand.

You are right and we still need test it on OLPC.

Quoted 54 lines

Thanks
Guennadi

Quoted 5 lines · Albert Wang

This patch adds the soc_camera mode support in marvell-ccic driver. It also removes the old mode for maintaining single mode in the future.

Quoted 8 lines
---
 drivers/media/platform/Makefile                  |    4 +-
 drivers/media/platform/marvell-ccic/Kconfig      |    6 +-
 drivers/media/platform/marvell-ccic/mcam-core.c  | 1084 +++++++---------------
 drivers/media/platform/marvell-ccic/mcam-core.h  |   27 +-
 drivers/media/platform/marvell-ccic/mmp-driver.c |   73 +-
 include/media/mmp-camera.h                       |    5 +
 6 files changed, 402 insertions(+), 797 deletions(-)

At least the stats look good ;-)

Review

Quoted 24 lines
drivers/media/platform/Makefile +2 -2
index 4817d28..1a345c8 100644
@@ -11,8 +11,6 @@ obj-$(CONFIG_VIDEO_TIMBERDALE)	+= timblogiw.o
 obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
 
 obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
-obj-$(CONFIG_VIDEO_CAFE_CCIC) += marvell-ccic/
-obj-$(CONFIG_VIDEO_MMP_CAMERA) += marvell-ccic/
 
 obj-$(CONFIG_VIDEO_OMAP2)		+= omap2cam.o
 obj-$(CONFIG_VIDEO_OMAP3)	+= omap3isp/
@@ -43,6 +41,8 @@ obj-$(CONFIG_ARCH_DAVINCI)		+= davinci/
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
 
 obj-$(CONFIG_SOC_CAMERA)		+= soc_camera/
+obj-$(CONFIG_VIDEO_CAFE_CCIC)		+= marvell-ccic/
+obj-$(CONFIG_VIDEO_MMP_CAMERA)		+= marvell-ccic/
 
 obj-y	+= davinci/
 
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/Kconfig

Quoted 6 lines

index bf739e3..7fa3c62 100755

drivers/media/platform/marvell-ccic/Kconfig +0 -0
@@ -10,14 +10,14 @@ config VIDEO_CAFE_CCIC
 	  generation OLPC systems.
 
Quoted 7 lines

drivers/media/platform/marvell-ccic/Kconfig config VIDEO_CAFE_CCIC · line 14

Quoted 4 lines
drivers/media/platform/marvell-ccic/Kconfig +1 -1
 config VIDEO_MMP_CAMERA
-	tristate "Marvell Armada 610 integrated camera controller support"
+	tristate "Marvell Armada integrated camera controller support"
 	depends on ARCH_MMP && I2C && VIDEO_V4L2

Perhaps, you want to add "&& SOC_CAMERA" above

Yes, we missed it. Thanks!

Quoted 16 lines
Quoted 11 lines
drivers/media/platform/marvell-ccic/Kconfig +2 -2
-	select VIDEO_OV7670
 	select I2C_GPIO
+	select VIDEOBUF2_DMA_CONTIG
 	select VIDEOBUF2_DMA_SG
 	---help---
 	  This is a Video4Linux2 driver for the integrated camera
-	  controller found on Marvell Armada 610 application
+	  controller found on Marvell Armada application
 	  processors (and likely beyond).  This is the controller found
 	  in OLPC XO 1.75 systems.
 

[snip]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mmp-driver.c

Quoted 11 lines

drivers/media/platform/marvell-ccic/mmp-driver.c line 31

Quoted 8 lines

index 732af16..3d5db24 100755

drivers/media/platform/marvell-ccic/mmp-driver.c +1 -0
@@ -28,6 +28,10 @@
 #include <linux/list.h>
 #include <linux/pm.h>
 #include <linux/clk.h>
+#include <linux/regulator/consumer.h>

Looks like you don't need this header.

Ok, will remove it.

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#32 lore raw

PATCH v4 11/12 marvell-ccic: add dma burst support for marvell-ccic driver

In reply to Albert Wang

This patch adds the dma burst size config support for marvell-ccic. Developer can set the dma burst size in specified board driver.

---
 drivers/media/platform/marvell-ccic/mcam-core.c  |    3 ++-
 drivers/media/platform/marvell-ccic/mcam-core.h  |    8 ++++----
 drivers/media/platform/marvell-ccic/mmp-driver.c |   11 +++++++++++
 include/media/mmp-camera.h                       |    1 +
 4 files changed, 18 insertions(+), 5 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +2 -1
index 16ba045..f206e3c 100755
@@ -1218,7 +1218,8 @@ static int mcam_camera_add_device(struct soc_camera_device *icd)
 	mcam_ctlr_power_up(mcam);
 	mcam_ctlr_stop(mcam);
 	mcam_set_config_needed(mcam, 1);
-	mcam_reg_write(mcam, REG_CTRL1, C1_RESERVED | C1_DMAPOSTED);
+	mcam_reg_write(mcam, REG_CTRL1,
+				mcam->burst | C1_RESERVED | C1_DMAPOSTED);
 	mcam_reg_write(mcam, REG_CLKCTRL,
 				(mcam->mclk_src << 29) | mcam->mclk_div);
 	cam_dbg(mcam, "camera: set sensor mclk = %dMHz\n", mcam->mclk_min);
drivers/media/platform/marvell-ccic/mcam-core.h +4 -4
index 12af7d2..0accdbb 100755
@@ -108,6 +108,7 @@ struct mcam_camera {
 	short int use_smbus;	/* SMBUS or straight I2c? */
 	enum mcam_buffer_mode buffer_mode;
 
+	u32 burst;
 	int mclk_min;
 	int mclk_src;
 	int mclk_div;
@@ -347,10 +348,9 @@ int mccic_resume(struct mcam_camera *cam);
 #define   C1_DESC_3WORD   0x00000200	/* Three-word descriptors used */
 #define	  C1_444ALPHA	  0x00f00000	/* Alpha field in RGB444 */
 #define	  C1_ALPHA_SHFT	  20
-#define	  C1_DMAB32	  0x00000000	/* 32-byte DMA burst */
-#define	  C1_DMAB16	  0x02000000	/* 16-byte DMA burst */
-#define	  C1_DMAB64	  0x04000000	/* 64-byte DMA burst */
-#define	  C1_DMAB_MASK	  0x06000000
+#define	  C1_DMAB64	  0x00000000	/* 64-byte DMA burst */
+#define	  C1_DMAB128	  0x02000000	/* 128-byte DMA burst */
+#define	  C1_DMAB256	  0x04000000	/* 256-byte DMA burst */
 #define	  C1_TWOBUFS	  0x08000000	/* Use only two DMA buffers */
 #define	  C1_PWRDWN	  0x10000000	/* Power down */
 #define   C1_DMAPOSTED	  0x40000000    /* DMA Posted Select */
drivers/media/platform/marvell-ccic/mmp-driver.c +11 -0
index 3d5db24..3fd6a46 100755
@@ -360,6 +360,17 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->lane = pdata->lane;
 	/* set B_DMA_CONTIG as default */
 	mcam->buffer_mode = B_DMA_CONTIG;
+	switch (pdata->dma_burst) {
+	case 128:
+		mcam->burst = C1_DMAB128;
+		break;
+	case 256:
+		mcam->burst = C1_DMAB256;
+		break;
+	default:
+		mcam->burst = C1_DMAB64;
+		break;
+	}
 	INIT_LIST_HEAD(&mcam->buffers);
 	/*
 	 * Get our I/O memory.
include/media/mmp-camera.h +1 -0
index 513d846..44234dd 100755
@@ -13,6 +13,7 @@ struct mmp_camera_platform_data {
 	int mclk_src;
 	int mclk_div;
 	int chip_id;
+	u32 dma_burst;
 	/*
 	 * MIPI support
 	 */
Signature · 1 line
1.7.9.5
Acked-by on v4 11/12
#33 lore raw

Re: [REVIEW PATCH V4 11/12] [media] marvell-ccic: add dma burst support for marvell-ccic driver

Not much _I_ could help here with, FWIW:

Quoted 6 lines · Albert Wang

This patch adds the dma burst size config support for marvell-ccic. Developer can set the dma burst size in specified board driver.

Thanks
Guennadi

Quoted 84 lines
---
 drivers/media/platform/marvell-ccic/mcam-core.c  |    3 ++-
 drivers/media/platform/marvell-ccic/mcam-core.h  |    8 ++++----
 drivers/media/platform/marvell-ccic/mmp-driver.c |   11 +++++++++++
 include/media/mmp-camera.h                       |    1 +
 4 files changed, 18 insertions(+), 5 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +2 -1
index 16ba045..f206e3c 100755
@@ -1218,7 +1218,8 @@ static int mcam_camera_add_device(struct soc_camera_device *icd)
 	mcam_ctlr_power_up(mcam);
 	mcam_ctlr_stop(mcam);
 	mcam_set_config_needed(mcam, 1);
-	mcam_reg_write(mcam, REG_CTRL1, C1_RESERVED | C1_DMAPOSTED);
+	mcam_reg_write(mcam, REG_CTRL1,
+				mcam->burst | C1_RESERVED | C1_DMAPOSTED);
 	mcam_reg_write(mcam, REG_CLKCTRL,
 				(mcam->mclk_src << 29) | mcam->mclk_div);
 	cam_dbg(mcam, "camera: set sensor mclk = %dMHz\n", mcam->mclk_min);
drivers/media/platform/marvell-ccic/mcam-core.h +4 -4
index 12af7d2..0accdbb 100755
@@ -108,6 +108,7 @@ struct mcam_camera {
 	short int use_smbus;	/* SMBUS or straight I2c? */
 	enum mcam_buffer_mode buffer_mode;
 
+	u32 burst;
 	int mclk_min;
 	int mclk_src;
 	int mclk_div;
@@ -347,10 +348,9 @@ int mccic_resume(struct mcam_camera *cam);
 #define   C1_DESC_3WORD   0x00000200	/* Three-word descriptors used */
 #define	  C1_444ALPHA	  0x00f00000	/* Alpha field in RGB444 */
 #define	  C1_ALPHA_SHFT	  20
-#define	  C1_DMAB32	  0x00000000	/* 32-byte DMA burst */
-#define	  C1_DMAB16	  0x02000000	/* 16-byte DMA burst */
-#define	  C1_DMAB64	  0x04000000	/* 64-byte DMA burst */
-#define	  C1_DMAB_MASK	  0x06000000
+#define	  C1_DMAB64	  0x00000000	/* 64-byte DMA burst */
+#define	  C1_DMAB128	  0x02000000	/* 128-byte DMA burst */
+#define	  C1_DMAB256	  0x04000000	/* 256-byte DMA burst */
 #define	  C1_TWOBUFS	  0x08000000	/* Use only two DMA buffers */
 #define	  C1_PWRDWN	  0x10000000	/* Power down */
 #define   C1_DMAPOSTED	  0x40000000    /* DMA Posted Select */
drivers/media/platform/marvell-ccic/mmp-driver.c +11 -0
index 3d5db24..3fd6a46 100755
@@ -360,6 +360,17 @@ static int mmpcam_probe(struct platform_device *pdev)
 	mcam->lane = pdata->lane;
 	/* set B_DMA_CONTIG as default */
 	mcam->buffer_mode = B_DMA_CONTIG;
+	switch (pdata->dma_burst) {
+	case 128:
+		mcam->burst = C1_DMAB128;
+		break;
+	case 256:
+		mcam->burst = C1_DMAB256;
+		break;
+	default:
+		mcam->burst = C1_DMAB64;
+		break;
+	}
 	INIT_LIST_HEAD(&mcam->buffers);
 	/*
 	 * Get our I/O memory.
include/media/mmp-camera.h +1 -0
index 513d846..44234dd 100755
@@ -13,6 +13,7 @@ struct mmp_camera_platform_data {
 	int mclk_src;
 	int mclk_div;
 	int chip_id;
+	u32 dma_burst;
 	/*
 	 * MIPI support
 	 */
Signature · 1 line
1.7.9.5

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#34 lore raw

PATCH v4 12/12 marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

In reply to Albert Wang

This patch adds support of 3 frame buffers in DMA-contiguous mode.

In current DMA_CONTIG mode, only 2 frame buffers can be supported. Actually, Marvell CCIC can support 2 or 3 frame buffers.

Currently 3 frame buffers mode will be used by default. To use 2 frame buffers mode, can do:
#define MAX_FRAME_BUFS 2
in mcam-core.h.

---
 drivers/media/platform/marvell-ccic/mcam-core.c |   59 +++++++++++++++++------
 drivers/media/platform/marvell-ccic/mcam-core.h |   13 +++++
 2 files changed, 57 insertions(+), 15 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +44 -15
index f206e3c..33fce6c 100755
@@ -494,13 +494,32 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 	struct mcam_vb_buffer *buf;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
 
-	/*
-	 * If there are no available buffers, go into single mode
-	 */
 	if (list_empty(&cam->buffers)) {
-		buf = cam->vb_bufs[frame ^ 0x1];
-		set_bit(CF_SINGLE_BUFFER, &cam->flags);
-		cam->frame_state.singles++;
+		/*
+		 * If there are no available buffers
+		 * go into single buffer mode
+		 *
+		 * If CCIC use Two Buffers mode
+		 * will use another remaining frame buffer
+		 * frame 0 -> buf 1
+		 * frame 1 -> buf 0
+		 *
+		 * If CCIC use Three Buffers mode
+		 * will use the 2rd remaining frame buffer
+		 * frame 0 -> buf 2
+		 * frame 1 -> buf 0
+		 * frame 2 -> buf 1
+		 */
+		buf = cam->vb_bufs[(frame + (MAX_FRAME_BUFS - 1))
+						% MAX_FRAME_BUFS];
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;
+		}
 	} else {
 		/*
 		 * OK, we have a buffer we can use.
@@ -509,15 +528,15 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 					queue);
 		list_del_init(&buf->queue);
 		clear_bit(CF_SINGLE_BUFFER, &cam->flags);
+		if (cam->frame_state.usebufs != (3 - MAX_FRAME_BUFS))
+			cam->frame_state.usebufs--;
 	}
 
 	cam->vb_bufs[frame] = buf;
-	mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR, buf->yuv_p.y);
+	mcam_reg_write(cam, REG_Y0BAR + (frame << 2), buf->yuv_p.y);
 	if (mcam_fmt_is_planar(fmt->pixelformat)) {
-		mcam_reg_write(cam, frame == 0 ?
-					REG_U0BAR : REG_U1BAR, buf->yuv_p.u);
-		mcam_reg_write(cam, frame == 0 ?
-					REG_V0BAR : REG_V1BAR, buf->yuv_p.v);
+		mcam_reg_write(cam, REG_U0BAR + (frame << 2), buf->yuv_p.u);
+		mcam_reg_write(cam, REG_V0BAR + (frame << 2), buf->yuv_p.v);
 	}
 }
 
@@ -526,10 +545,14 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
  */
 static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 {
-	mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
-	cam->nbufs = 2;
-	mcam_set_contig_buffer(cam, 0);
-	mcam_set_contig_buffer(cam, 1);
+	unsigned int frame;
+
+	cam->nbufs = MAX_FRAME_BUFS;
+	for (frame = 0; frame < cam->nbufs; frame++)
+		mcam_set_contig_buffer(cam, frame);
+
+	if (cam->nbufs == 2)
+		mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
 }
 
 /*
@@ -1068,6 +1091,12 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 	for (frame = 0; frame < cam->nbufs; frame++)
 		clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
 
+	/*
+	 *  If CCIC use Two Buffers mode, init usebufs == 1
+	 *  If CCIC use Three Buffers mode, init usebufs == 0
+	 */
+	cam->frame_state.usebufs = 3 - MAX_FRAME_BUFS;
+
 	return mcam_read_setup(cam);
 }
 
drivers/media/platform/marvell-ccic/mcam-core.h +13 -0
index 0accdbb..6fffa14 100755
@@ -44,6 +44,15 @@ enum mcam_state {
 };
 #define MAX_DMA_BUFS 3
 
+#ifdef MCAM_MODE_DMA_CONTIG
+/*
+ * CCIC can support at most 3 frame buffers in DMA_CONTIG buffer mode
+ * 2 - Use Two Buffers mode
+ * 3 - Use Three Buffers mode
+ */
+#define MAX_FRAME_BUFS 3 /* marvell-ccic used Three Buffers mode as default */
+#endif
+
 /*
  * Different platforms work best with different buffer modes, so we
  * let the platform pick.
@@ -82,6 +91,10 @@ struct mcam_frame_state {
 	unsigned int frames;
 	unsigned int singles;
 	unsigned int delivered;
+	/*
+	 * Only usebufs == 2 can enter single buffer mode
+	 */
+	unsigned int usebufs;
 };
 
 #define NR_MCAM_CLK 3
Signature · 1 line
1.7.9.5
#35 lore raw

Re: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

Quoted 47 lines · Albert Wang

This patch adds support of 3 frame buffers in DMA-contiguous mode.

In current DMA_CONTIG mode, only 2 frame buffers can be supported. Actually, Marvell CCIC can support 2 or 3 frame buffers.

Currently 3 frame buffers mode will be used by default. To use 2 frame buffers mode, can do:
#define MAX_FRAME_BUFS 2
in mcam-core.h.

---
 drivers/media/platform/marvell-ccic/mcam-core.c |   59 +++++++++++++++++------
 drivers/media/platform/marvell-ccic/mcam-core.h |   13 +++++
 2 files changed, 57 insertions(+), 15 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +14 -6
index f206e3c..33fce6c 100755
@@ -494,13 +494,32 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 	struct mcam_vb_buffer *buf;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
 
-	/*
-	 * If there are no available buffers, go into single mode
-	 */
 	if (list_empty(&cam->buffers)) {
-		buf = cam->vb_bufs[frame ^ 0x1];
-		set_bit(CF_SINGLE_BUFFER, &cam->flags);
-		cam->frame_state.singles++;
+		/*
+		 * If there are no available buffers
+		 * go into single buffer mode
+		 *
+		 * If CCIC use Two Buffers mode
+		 * will use another remaining frame buffer
+		 * frame 0 -> buf 1
+		 * frame 1 -> buf 0
+		 *
+		 * If CCIC use Three Buffers mode
+		 * will use the 2rd remaining frame buffer
+		 * frame 0 -> buf 2
+		 * frame 1 -> buf 0
+		 * frame 2 -> buf 1

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame) · line 521

Quoted 10 lines
drivers/media/platform/marvell-ccic/mcam-core.c +10 -0
+		 */
+		buf = cam->vb_bufs[(frame + (MAX_FRAME_BUFS - 1))
+						% MAX_FRAME_BUFS];
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;

What is this .usebufs actually supposed to do? AFAICS, it is only used to decide, whether it should be changed, I don't see it having any effect on anything else?

Quoted 91 lines
drivers/media/platform/marvell-ccic/mcam-core.c +20 -9
+		}
 	} else {
 		/*
 		 * OK, we have a buffer we can use.
@@ -509,15 +528,15 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
 					queue);
 		list_del_init(&buf->queue);
 		clear_bit(CF_SINGLE_BUFFER, &cam->flags);
+		if (cam->frame_state.usebufs != (3 - MAX_FRAME_BUFS))
+			cam->frame_state.usebufs--;
 	}
 
 	cam->vb_bufs[frame] = buf;
-	mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR, buf->yuv_p.y);
+	mcam_reg_write(cam, REG_Y0BAR + (frame << 2), buf->yuv_p.y);
 	if (mcam_fmt_is_planar(fmt->pixelformat)) {
-		mcam_reg_write(cam, frame == 0 ?
-					REG_U0BAR : REG_U1BAR, buf->yuv_p.u);
-		mcam_reg_write(cam, frame == 0 ?
-					REG_V0BAR : REG_V1BAR, buf->yuv_p.v);
+		mcam_reg_write(cam, REG_U0BAR + (frame << 2), buf->yuv_p.u);
+		mcam_reg_write(cam, REG_V0BAR + (frame << 2), buf->yuv_p.v);
 	}
 }
 
@@ -526,10 +545,14 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame)
  */
 static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 {
-	mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
-	cam->nbufs = 2;
-	mcam_set_contig_buffer(cam, 0);
-	mcam_set_contig_buffer(cam, 1);
+	unsigned int frame;
+
+	cam->nbufs = MAX_FRAME_BUFS;
+	for (frame = 0; frame < cam->nbufs; frame++)
+		mcam_set_contig_buffer(cam, frame);
+
+	if (cam->nbufs == 2)
+		mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
 }
 
 /*
@@ -1068,6 +1091,12 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
 	for (frame = 0; frame < cam->nbufs; frame++)
 		clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
 
+	/*
+	 *  If CCIC use Two Buffers mode, init usebufs == 1
+	 *  If CCIC use Three Buffers mode, init usebufs == 0
+	 */
+	cam->frame_state.usebufs = 3 - MAX_FRAME_BUFS;
+
 	return mcam_read_setup(cam);
 }
 
drivers/media/platform/marvell-ccic/mcam-core.h +13 -0
index 0accdbb..6fffa14 100755
@@ -44,6 +44,15 @@ enum mcam_state {
 };
 #define MAX_DMA_BUFS 3
 
+#ifdef MCAM_MODE_DMA_CONTIG
+/*
+ * CCIC can support at most 3 frame buffers in DMA_CONTIG buffer mode
+ * 2 - Use Two Buffers mode
+ * 3 - Use Three Buffers mode
+ */
+#define MAX_FRAME_BUFS 3 /* marvell-ccic used Three Buffers mode as default */
+#endif
+
 /*
  * Different platforms work best with different buffer modes, so we
  * let the platform pick.
@@ -82,6 +91,10 @@ struct mcam_frame_state {
 	unsigned int frames;
 	unsigned int singles;
 	unsigned int delivered;
+	/*
+	 * Only usebufs == 2 can enter single buffer mode
+	 */
+	unsigned int usebufs;
 };
 
 #define NR_MCAM_CLK 3
Signature · 1 line
1.7.9.5

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#36 lore raw

RE: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

Hi, Guennadi

Quoted 65 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Tuesday, 05 March, 2013 22:17
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: Re: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

Quoted 13 lines · Albert Wang

This patch adds support of 3 frame buffers in DMA-contiguous mode.

In current DMA_CONTIG mode, only 2 frame buffers can be supported. Actually, Marvell CCIC can support 2 or 3 frame buffers.

Currently 3 frame buffers mode will be used by default. To use 2 frame buffers mode, can do:
#define MAX_FRAME_BUFS 2
in mcam-core.h.

Review

Quoted 6 lines
---
 drivers/media/platform/marvell-ccic/mcam-core.c |   59 +++++++++++++++++------
 drivers/media/platform/marvell-ccic/mcam-core.h |   13 +++++
 2 files changed, 57 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.c

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera

Quoted 4 lines

index f206e3c..33fce6c 100755

drivers/media/platform/marvell-ccic/mcam-core.c +0 -0
@@ -494,13 +494,32 @@ static void mcam_set_contig_buffer(struct mcam_camera

*cam, unsigned int frame)

Quoted 30 lines
drivers/media/platform/marvell-ccic/mcam-core.c +20 -6
 	struct mcam_vb_buffer *buf;
 	struct v4l2_pix_format *fmt = &cam->pix_format;
 
-	/*
-	 * If there are no available buffers, go into single mode
-	 */
 	if (list_empty(&cam->buffers)) {
-		buf = cam->vb_bufs[frame ^ 0x1];
-		set_bit(CF_SINGLE_BUFFER, &cam->flags);
-		cam->frame_state.singles++;
+		/*
+		 * If there are no available buffers
+		 * go into single buffer mode
+		 *
+		 * If CCIC use Two Buffers mode
+		 * will use another remaining frame buffer
+		 * frame 0 -> buf 1
+		 * frame 1 -> buf 0
+		 *
+		 * If CCIC use Three Buffers mode
+		 * will use the 2rd remaining frame buffer
+		 * frame 0 -> buf 2
+		 * frame 1 -> buf 0
+		 * frame 2 -> buf 1
+		 */
+		buf = cam->vb_bufs[(frame + (MAX_FRAME_BUFS - 1))
+						% MAX_FRAME_BUFS];
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
Quoted 9 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame) · line 521

Quoted 4 lines
drivers/media/platform/marvell-ccic/mcam-core.c +4 -0
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;

What is this .usebufs actually supposed to do? AFAICS, it is only used to decide, whether it should be changed, I don't see it having any effect on anything else?

Actually, we use .usebufs to decide if will enter single buffer mode. Only usebufs == 2 can enter single buffer mode.
But when init it:

	If CCIC use Two Buffers mode, init usebufs == 1
	If CCIC use Three Buffers mode, init usebufs == 0

That means when CCIC use Two Buffers mode, once buffer used out, CCIC will enter single buffer mode soon But when CCIC use Two Buffers mode, we can have 1 frame time to wait for new buffer and needn't enter single buffer mode. If we still can't get new buffer after 1 frame, then CCIC has to enter single buffer mode.
But if we are lucky enough and get new buffer when next frame come, then we can still run in normal mode.

Quoted 91 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera

Quoted 5 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -0
+		}
 	} else {
 		/*
 		 * OK, we have a buffer we can use.
@@ -509,15 +528,15 @@ static void mcam_set_contig_buffer(struct mcam_camera

*cam, unsigned int frame)

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera

Quoted 21 lines
drivers/media/platform/marvell-ccic/mcam-core.c +5 -5
 					queue);
 		list_del_init(&buf->queue);
 		clear_bit(CF_SINGLE_BUFFER, &cam->flags);
+		if (cam->frame_state.usebufs != (3 - MAX_FRAME_BUFS))
+			cam->frame_state.usebufs--;
 	}
 
 	cam->vb_bufs[frame] = buf;
-	mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR, buf->yuv_p.y);
+	mcam_reg_write(cam, REG_Y0BAR + (frame << 2), buf->yuv_p.y);
 	if (mcam_fmt_is_planar(fmt->pixelformat)) {
-		mcam_reg_write(cam, frame == 0 ?
-					REG_U0BAR : REG_U1BAR, buf->yuv_p.u);
-		mcam_reg_write(cam, frame == 0 ?
-					REG_V0BAR : REG_V1BAR, buf->yuv_p.v);
+		mcam_reg_write(cam, REG_U0BAR + (frame << 2), buf->yuv_p.u);
+		mcam_reg_write(cam, REG_V0BAR + (frame << 2), buf->yuv_p.v);
 	}
 }
 
@@ -526,10 +545,14 @@ static void mcam_set_contig_buffer(struct mcam_camera

*cam, unsigned int frame)

drivers/media/platform/marvell-ccic/mcam-core.c static int mcam_vb_start_streaming(struct vb2_queue *vq,

Quoted 19 lines
drivers/media/platform/marvell-ccic/mcam-core.c +8 -4
  */
 static void mcam_ctlr_dma_contig(struct mcam_camera *cam)
 {
-	mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
-	cam->nbufs = 2;
-	mcam_set_contig_buffer(cam, 0);
-	mcam_set_contig_buffer(cam, 1);
+	unsigned int frame;
+
+	cam->nbufs = MAX_FRAME_BUFS;
+	for (frame = 0; frame < cam->nbufs; frame++)
+		mcam_set_contig_buffer(cam, frame);
+
+	if (cam->nbufs == 2)
+		mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
 }
 
 /*
@@ -1068,6 +1091,12 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq,

unsigned int count)

Review

Quoted 13 lines
drivers/media/platform/marvell-ccic/mcam-core.c +6 -0
 	for (frame = 0; frame < cam->nbufs; frame++)
 		clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
 
+	/*
+	 *  If CCIC use Two Buffers mode, init usebufs == 1
+	 *  If CCIC use Three Buffers mode, init usebufs == 0
+	 */
+	cam->frame_state.usebufs = 3 - MAX_FRAME_BUFS;
+
 	return mcam_read_setup(cam);
 }
 
(quoted diff) +0 -0

b/drivers/media/platform/marvell-ccic/mcam-core.h

Quoted 29 lines

index 0accdbb..6fffa14 100755

drivers/media/platform/marvell-ccic/mcam-core.h +13 -0
@@ -44,6 +44,15 @@ enum mcam_state {
 };
 #define MAX_DMA_BUFS 3
 
+#ifdef MCAM_MODE_DMA_CONTIG
+/*
+ * CCIC can support at most 3 frame buffers in DMA_CONTIG buffer mode
+ * 2 - Use Two Buffers mode
+ * 3 - Use Three Buffers mode
+ */
+#define MAX_FRAME_BUFS 3 /* marvell-ccic used Three Buffers mode as default */
+#endif
+
 /*
  * Different platforms work best with different buffer modes, so we
  * let the platform pick.
@@ -82,6 +91,10 @@ struct mcam_frame_state {
 	unsigned int frames;
 	unsigned int singles;
 	unsigned int delivered;
+	/*
+	 * Only usebufs == 2 can enter single buffer mode
+	 */
+	unsigned int usebufs;
 };
 
Quoted 11 lines
Quoted 4 lines
drivers/media/platform/marvell-ccic/mcam-core.h +0 -1
 #define NR_MCAM_CLK 3
--

1.7.9.5

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#37 lore raw

RE: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

On Wed, 6 Mar 2013, Albert Wang wrote:

[snip]

Quoted 15 lines
Quoted 12 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame) · line 521

Quoted 7 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;

What is this .usebufs actually supposed to do? AFAICS, it is only used to decide, whether it should be changed, I don't see it having any effect on anything else?

Actually, we use .usebufs to decide if will enter single buffer mode. Only usebufs == 2 can enter single buffer mode.
But when init it:

Quoted 8 lines
	If CCIC use Two Buffers mode, init usebufs == 1
	If CCIC use Three Buffers mode, init usebufs == 0

That means when CCIC use Two Buffers mode, once buffer used out, CCIC will enter single buffer mode soon But when CCIC use Two Buffers mode, we can have 1 frame time to wait for
new buffer and needn't enter single buffer mode.
If we still can't get new buffer after 1 frame, then CCIC has to enter single buffer mode. But if we are lucky enough and get new buffer when next frame come, then
we can still run in normal mode.

Thanks for the explanation. Could you please tell me where in the code this .usebufs field is used as you describe?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#38 lore raw

RE: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

Hi, Guennadi

Quoted 31 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Wednesday, 06 March, 2013 23:02
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: RE: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

On Wed, 6 Mar 2013, Albert Wang wrote:

[snip]

Quoted 12 lines
Quoted 12 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame) · line 521

Quoted 7 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;

What is this .usebufs actually supposed to do? AFAICS, it is only used to decide, whether it should be changed, I don't see it having any effect on anything else?

Quoted 6 lines

Actually, we use .usebufs to decide if will enter single buffer mode. Only usebufs == 2 can enter single buffer mode.
But when init it:

	If CCIC use Two Buffers mode, init usebufs == 1
	If CCIC use Three Buffers mode, init usebufs == 0

That means when CCIC use Two Buffers mode, once buffer used out, CCIC will enter

single buffer mode soon

Quoted 9 lines
Quoted 5 lines

But when CCIC use Three Buffers mode, we can have 1 frame time to wait for new buffer and needn't enter single buffer mode.
If we still can't get new buffer after 1 frame, then CCIC has to enter single buffer mode. But if we are lucky enough and get new buffer when next frame come, then
we can still run in normal mode.

Thanks for the explanation. Could you please tell me where in the code this .usebufs field is used as you describe?

Firstly, we will init this field, the initial value depends on selected CCIC buffer mode:
+ /*
+ * If CCIC use Two Buffers mode, init usebufs == 1
+ * If CCIC use Three Buffers mode, init usebufs == 0
+ */
+ cam->frame_state.usebufs = 3 - MAX_FRAME_BUFS;

Then:

		/*

+ * If there are no available buffers
+ * go into single buffer mode
+ *
But it depends on usebufs state:
+ if (cam->frame_state.usebufs == 0)
+ cam->frame_state.usebufs++;
+ else {
+ set_bit(CF_SINGLE_BUFFER, &cam->flags);
+ cam->frame_state.singles++;
+ if (cam->frame_state.usebufs < 2)
+ cam->frame_state.usebufs++;
+ }
usebufs range is 0, 1, 2:
0 - Use Three buffer mode, and CCIC needn't enter single buffer mode when buffer used out in the first time
1 - Use Two buffer mode and CCIC need enter single buffer mode
Or Use Three buffer mode and CCIC also need enter single buffer mode when we still can't get new buffer after continuous 2 frames
2 - CCIC had enterer single buffer mode whatever use Two buffer or Three buffer mode

And if:

		/*

* OK, we have a buffer we can use.

We will exit the single buffer mode:

		clear_bit(CF_SINGLE_BUFFER, &cam->flags);

+ if (cam->frame_state.usebufs != (3 - MAX_FRAME_BUFS))
+ cam->frame_state.usebufs--;
}
And we will try to let usebufs back to initial value.

Quoted 6 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Thanks
Albert Wang
86-21-61092656

#39 lore raw

RE: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

Quoted 56 lines · Albert Wang

Hi, Guennadi

Quoted 31 lines

-----Original Message-----
From: Guennadi Liakhovetski [mailto:[email protected]]
Sent: Wednesday, 06 March, 2013 23:02
To: Albert Wang
Cc: [email protected]; [email protected]; Libin Yang
Subject: RE: [REVIEW PATCH V4 12/12] [media] marvell-ccic: add 3 frame buffers support in DMA_CONTIG mode

On Wed, 6 Mar 2013, Albert Wang wrote:

[snip]

Quoted 12 lines
Quoted 12 lines

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame) · line 521

Quoted 7 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;

What is this .usebufs actually supposed to do? AFAICS, it is only used to decide, whether it should be changed, I don't see it having any effect on anything else?

Quoted 6 lines

Actually, we use .usebufs to decide if will enter single buffer mode. Only usebufs == 2 can enter single buffer mode.
But when init it:

	If CCIC use Two Buffers mode, init usebufs == 1
	If CCIC use Three Buffers mode, init usebufs == 0

That means when CCIC use Two Buffers mode, once buffer used out, CCIC will enter

single buffer mode soon

Quoted 9 lines
Quoted 5 lines

But when CCIC use Three Buffers mode, we can have 1 frame time to wait for new buffer and needn't enter single buffer mode.
If we still can't get new buffer after 1 frame, then CCIC has to enter single buffer mode. But if we are lucky enough and get new buffer when next frame come, then
we can still run in normal mode.

Thanks for the explanation. Could you please tell me where in the code this .usebufs field is used as you describe?

Firstly, we will init this field, the initial value depends on selected CCIC buffer mode:

drivers/media/platform/marvell-ccic/mcam-core.c +5 -0
+	/*
+	 *  If CCIC use Two Buffers mode, init usebufs == 1
+	 *  If CCIC use Three Buffers mode, init usebufs == 0
+	 */
+	cam->frame_state.usebufs = 3 - MAX_FRAME_BUFS;

Then:

		/*
drivers/media/platform/marvell-ccic/mcam-core.c +3 -0
+		 * If there are no available buffers
+		 * go into single buffer mode
+		 *

But it depends on usebufs state:

drivers/media/platform/marvell-ccic/mcam-core.c static void mcam_set_contig_buffer(struct mcam_camera *cam, unsigned int frame) · line 521

Quoted 7 lines
drivers/media/platform/marvell-ccic/mcam-core.c +7 -0
+		if (cam->frame_state.usebufs == 0)
+			cam->frame_state.usebufs++;
+		else {
+			set_bit(CF_SINGLE_BUFFER, &cam->flags);
+			cam->frame_state.singles++;
+			if (cam->frame_state.usebufs < 2)
+				cam->frame_state.usebufs++;

Aaargh, I must've been blind, sorry :(

Quoted 17 lines
drivers/media/platform/marvell-ccic/mcam-core.c +1 -0
+		}

usebufs range is 0, 1, 2:
0 - Use Three buffer mode, and CCIC needn't enter single buffer mode when buffer used out in the first time
1 - Use Two buffer mode and CCIC need enter single buffer mode
Or Use Three buffer mode and CCIC also need enter single buffer mode when we still can't get new buffer after continuous 2 frames
2 - CCIC had enterer single buffer mode whatever use Two buffer or Three buffer mode

And if:

		/*

* OK, we have a buffer we can use.

We will exit the single buffer mode:

		clear_bit(CF_SINGLE_BUFFER, &cam->flags);
drivers/media/platform/marvell-ccic/mcam-core.c +2 -0
+		if (cam->frame_state.usebufs != (3 - MAX_FRAME_BUFS))
+			cam->frame_state.usebufs--;
 	}
Quoted 1 line

And we will try to let usebufs back to initial value.

Ok, it's clearer now. So, in fact, it is a kind of a remaining available buffer count, right? You could probably also do it the natural way - initialise this field not to 3 - MAX_FRAME_BUFS, but to cam->nbufs (or cam->nbufs - 1 if you prefer) directly and then count it down?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/