linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] media: ov13858: Calculate pixel-rate at runtime, use mode
@ 2017-09-05 23:44 Rajmohan Mani
  2017-09-06  6:23 ` Sakari Ailus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Rajmohan Mani @ 2017-09-05 23:44 UTC (permalink / raw)
  To: rajmohan.mani, linux-media, sakari.ailus; +Cc: Chiranjeevi Rapolu, tfiga

From: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>

Instead of calculating pixle-rate at two different places, calculate at run
time at a single place.

Instead of using hardcoded pixels-per-line, extract it from current sensor
mode.

Signed-off-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
---
 drivers/media/i2c/ov13858.c | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
index af7af0d..2821824 100644
--- a/drivers/media/i2c/ov13858.c
+++ b/drivers/media/i2c/ov13858.c
@@ -955,11 +955,9 @@ struct ov13858_mode {
 };
 
 /* Link frequency configs */
-static const struct ov13858_link_freq_config
+static struct ov13858_link_freq_config
 			link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
 	{
-		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
-		.pixel_rate = (OV13858_LINK_FREQ_540MHZ * 2 * 4) / 10,
 		.pixels_per_line = OV13858_PPL_540MHZ,
 		.reg_list = {
 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
@@ -967,8 +965,6 @@ struct ov13858_mode {
 		}
 	},
 	{
-		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
-		.pixel_rate = (OV13858_LINK_FREQ_270MHZ * 2 * 4) / 10,
 		.pixels_per_line = OV13858_PPL_270MHZ,
 		.reg_list = {
 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
@@ -1617,6 +1613,10 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
 	s64 exposure_max;
 	s64 vblank_def;
 	s64 vblank_min;
+	s64 hblank;
+	s64 pixel_rate_min;
+	s64 pixel_rate_max;
+	const struct ov13858_mode *mode;
 	int ret;
 
 	ctrl_hdlr = &ov13858->ctrl_handler;
@@ -1634,29 +1634,30 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
 				link_freq_menu_items);
 	ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
+	pixel_rate_max = link_freq_configs[0].pixel_rate;
+	pixel_rate_min = link_freq_configs[1].pixel_rate;
 	/* By default, PIXEL_RATE is read only */
 	ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
-					V4L2_CID_PIXEL_RATE, 0,
-					link_freq_configs[0].pixel_rate, 1,
-					link_freq_configs[0].pixel_rate);
+						V4L2_CID_PIXEL_RATE,
+						pixel_rate_min, pixel_rate_max,
+						1, pixel_rate_max);
 
-	vblank_def = ov13858->cur_mode->vts_def - ov13858->cur_mode->height;
-	vblank_min = ov13858->cur_mode->vts_min - ov13858->cur_mode->height;
+	mode = ov13858->cur_mode;
+	vblank_def = mode->vts_def - mode->height;
+	vblank_min = mode->vts_min - mode->height;
 	ov13858->vblank = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
-				vblank_min,
-				OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
+				vblank_min, OV13858_VTS_MAX - mode->height, 1,
 				vblank_def);
 
+	hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
+		 mode->width;
 	ov13858->hblank = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
-				1,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width);
+				hblank, hblank, 1, hblank);
 	ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
-	exposure_max = ov13858->cur_mode->vts_def - 8;
+	exposure_max = mode->vts_def - 8;
 	ov13858->exposure = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops,
 				V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,
@@ -1704,6 +1705,7 @@ static int ov13858_probe(struct i2c_client *client,
 			 const struct i2c_device_id *devid)
 {
 	struct ov13858 *ov13858;
+	int i;
 	int ret;
 	u32 val = 0;
 
@@ -1725,6 +1727,12 @@ static int ov13858_probe(struct i2c_client *client,
 		return ret;
 	}
 
+	for (i = 0; i < OV13858_NUM_OF_LINK_FREQS; i++) {
+		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
+		link_freq_configs[i].pixel_rate  =
+					(link_freq_menu_items[i] * 2 * 4) / 10;
+	}
+
 	/* Set default mode to max resolution */
 	ov13858->cur_mode = &supported_modes[0];
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] media: ov13858: Calculate pixel-rate at runtime, use mode
  2017-09-05 23:44 [PATCH v1] media: ov13858: Calculate pixel-rate at runtime, use mode Rajmohan Mani
@ 2017-09-06  6:23 ` Sakari Ailus
  2017-09-06 18:26 ` [PATCH v2] " Chiranjeevi Rapolu
  2017-09-18 20:43 ` [PATCH v3] " Chiranjeevi Rapolu
  2 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2017-09-06  6:23 UTC (permalink / raw)
  To: Rajmohan Mani; +Cc: linux-media, sakari.ailus, Chiranjeevi Rapolu, tfiga

Hi Rajmohan,

Thanks for the patch. A few comments below.

On Tue, Sep 05, 2017 at 04:44:58PM -0700, Rajmohan Mani wrote:
> From: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
> 
> Instead of calculating pixle-rate at two different places, calculate at run
> time at a single place.
> 
> Instead of using hardcoded pixels-per-line, extract it from current sensor
> mode.
> 
> Signed-off-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
> ---
>  drivers/media/i2c/ov13858.c | 42 +++++++++++++++++++++++++-----------------
>  1 file changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
> index af7af0d..2821824 100644
> --- a/drivers/media/i2c/ov13858.c
> +++ b/drivers/media/i2c/ov13858.c
> @@ -955,11 +955,9 @@ struct ov13858_mode {
>  };
>  
>  /* Link frequency configs */
> -static const struct ov13858_link_freq_config
> +static struct ov13858_link_freq_config
>  			link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
>  	{
> -		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> -		.pixel_rate = (OV13858_LINK_FREQ_540MHZ * 2 * 4) / 10,

Could you remove the pixel_rate field from the struct definition as well?

>  		.pixels_per_line = OV13858_PPL_540MHZ,
>  		.reg_list = {
>  			.num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
> @@ -967,8 +965,6 @@ struct ov13858_mode {
>  		}
>  	},
>  	{
> -		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> -		.pixel_rate = (OV13858_LINK_FREQ_270MHZ * 2 * 4) / 10,
>  		.pixels_per_line = OV13858_PPL_270MHZ,
>  		.reg_list = {
>  			.num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
> @@ -1617,6 +1613,10 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
>  	s64 exposure_max;
>  	s64 vblank_def;
>  	s64 vblank_min;
> +	s64 hblank;
> +	s64 pixel_rate_min;
> +	s64 pixel_rate_max;
> +	const struct ov13858_mode *mode;
>  	int ret;
>  
>  	ctrl_hdlr = &ov13858->ctrl_handler;
> @@ -1634,29 +1634,30 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
>  				link_freq_menu_items);
>  	ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>  
> +	pixel_rate_max = link_freq_configs[0].pixel_rate;
> +	pixel_rate_min = link_freq_configs[1].pixel_rate;
>  	/* By default, PIXEL_RATE is read only */
>  	ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
> -					V4L2_CID_PIXEL_RATE, 0,
> -					link_freq_configs[0].pixel_rate, 1,
> -					link_freq_configs[0].pixel_rate);
> +						V4L2_CID_PIXEL_RATE,
> +						pixel_rate_min, pixel_rate_max,
> +						1, pixel_rate_max);
>  
> -	vblank_def = ov13858->cur_mode->vts_def - ov13858->cur_mode->height;
> -	vblank_min = ov13858->cur_mode->vts_min - ov13858->cur_mode->height;
> +	mode = ov13858->cur_mode;
> +	vblank_def = mode->vts_def - mode->height;
> +	vblank_min = mode->vts_min - mode->height;
>  	ov13858->vblank = v4l2_ctrl_new_std(
>  				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
> -				vblank_min,
> -				OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
> +				vblank_min, OV13858_VTS_MAX - mode->height, 1,
>  				vblank_def);
>  
> +	hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
> +		 mode->width;
>  	ov13858->hblank = v4l2_ctrl_new_std(
>  				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
> -				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
> -				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
> -				1,
> -				OV13858_PPL_540MHZ - ov13858->cur_mode->width);
> +				hblank, hblank, 1, hblank);
>  	ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>  
> -	exposure_max = ov13858->cur_mode->vts_def - 8;
> +	exposure_max = mode->vts_def - 8;
>  	ov13858->exposure = v4l2_ctrl_new_std(
>  				ctrl_hdlr, &ov13858_ctrl_ops,
>  				V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,
> @@ -1704,6 +1705,7 @@ static int ov13858_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *devid)
>  {
>  	struct ov13858 *ov13858;
> +	int i;
>  	int ret;
>  	u32 val = 0;
>  
> @@ -1725,6 +1727,12 @@ static int ov13858_probe(struct i2c_client *client,
>  		return ret;
>  	}
>  
> +	for (i = 0; i < OV13858_NUM_OF_LINK_FREQS; i++) {
> +		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> +		link_freq_configs[i].pixel_rate  =
> +					(link_freq_menu_items[i] * 2 * 4) / 10;

Could you use the formula where you need pixel rate?

> +	}
> +
>  	/* Set default mode to max resolution */
>  	ov13858->cur_mode = &supported_modes[0];
>  

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] media: ov13858: Calculate pixel-rate at runtime, use mode
  2017-09-05 23:44 [PATCH v1] media: ov13858: Calculate pixel-rate at runtime, use mode Rajmohan Mani
  2017-09-06  6:23 ` Sakari Ailus
@ 2017-09-06 18:26 ` Chiranjeevi Rapolu
  2017-09-18 12:12   ` Sakari Ailus
  2017-09-18 20:43 ` [PATCH v3] " Chiranjeevi Rapolu
  2 siblings, 1 reply; 5+ messages in thread
From: Chiranjeevi Rapolu @ 2017-09-06 18:26 UTC (permalink / raw)
  To: linux-media, sakari.ailus
  Cc: tfiga, jian.xu.zheng, tian.shu.qiu, rajmohan.mani, hyungwoo.yang,
	Chiranjeevi Rapolu

Calculate pixel-rate at run time instead of compile time.

Instead of using hardcoded pixels-per-line, extract it from current sensor
mode.

Signed-off-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
---
Changes in v2:
	- Removed pixel-rate from struct definition.
	- Used pixel-rate formula wherever needed.
	- Changed commit message to reflect above changes.
 drivers/media/i2c/ov13858.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
index af7af0d..77f256e 100644
--- a/drivers/media/i2c/ov13858.c
+++ b/drivers/media/i2c/ov13858.c
@@ -104,7 +104,6 @@ struct ov13858_reg_list {
 
 /* Link frequency config */
 struct ov13858_link_freq_config {
-	u32 pixel_rate;
 	u32 pixels_per_line;
 
 	/* PLL registers for this link frequency */
@@ -958,8 +957,6 @@ struct ov13858_mode {
 static const struct ov13858_link_freq_config
 			link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
 	{
-		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
-		.pixel_rate = (OV13858_LINK_FREQ_540MHZ * 2 * 4) / 10,
 		.pixels_per_line = OV13858_PPL_540MHZ,
 		.reg_list = {
 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
@@ -967,8 +964,6 @@ struct ov13858_mode {
 		}
 	},
 	{
-		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
-		.pixel_rate = (OV13858_LINK_FREQ_270MHZ * 2 * 4) / 10,
 		.pixels_per_line = OV13858_PPL_270MHZ,
 		.reg_list = {
 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
@@ -1385,6 +1380,7 @@ static int ov13858_get_pad_format(struct v4l2_subdev *sd,
 	s32 vblank_def;
 	s32 vblank_min;
 	s64 h_blank;
+	s64 pixel_rate;
 
 	mutex_lock(&ov13858->mutex);
 
@@ -1400,9 +1396,9 @@ static int ov13858_get_pad_format(struct v4l2_subdev *sd,
 	} else {
 		ov13858->cur_mode = mode;
 		__v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index);
-		__v4l2_ctrl_s_ctrl_int64(
-			ov13858->pixel_rate,
-			link_freq_configs[mode->link_freq_index].pixel_rate);
+		pixel_rate =
+		(link_freq_menu_items[mode->link_freq_index] * 2 * 4) / 10;
+		__v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate);
 		/* Update limits and set FPS to default */
 		vblank_def = ov13858->cur_mode->vts_def -
 			     ov13858->cur_mode->height;
@@ -1617,6 +1613,10 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
 	s64 exposure_max;
 	s64 vblank_def;
 	s64 vblank_min;
+	s64 hblank;
+	s64 pixel_rate_min;
+	s64 pixel_rate_max;
+	const struct ov13858_mode *mode;
 	int ret;
 
 	ctrl_hdlr = &ov13858->ctrl_handler;
@@ -1634,29 +1634,31 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
 				link_freq_menu_items);
 	ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
+	/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
+	pixel_rate_max = (link_freq_menu_items[0] * 2 * 4) / 10;
+	pixel_rate_min = (link_freq_menu_items[1] * 2 * 4) / 10;
 	/* By default, PIXEL_RATE is read only */
 	ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
-					V4L2_CID_PIXEL_RATE, 0,
-					link_freq_configs[0].pixel_rate, 1,
-					link_freq_configs[0].pixel_rate);
+						V4L2_CID_PIXEL_RATE,
+						pixel_rate_min, pixel_rate_max,
+						1, pixel_rate_max);
 
-	vblank_def = ov13858->cur_mode->vts_def - ov13858->cur_mode->height;
-	vblank_min = ov13858->cur_mode->vts_min - ov13858->cur_mode->height;
+	mode = ov13858->cur_mode;
+	vblank_def = mode->vts_def - mode->height;
+	vblank_min = mode->vts_min - mode->height;
 	ov13858->vblank = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
-				vblank_min,
-				OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
+				vblank_min, OV13858_VTS_MAX - mode->height, 1,
 				vblank_def);
 
+	hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
+		 mode->width;
 	ov13858->hblank = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
-				1,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width);
+				hblank, hblank, 1, hblank);
 	ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
-	exposure_max = ov13858->cur_mode->vts_def - 8;
+	exposure_max = mode->vts_def - 8;
 	ov13858->exposure = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops,
 				V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] media: ov13858: Calculate pixel-rate at runtime, use mode
  2017-09-06 18:26 ` [PATCH v2] " Chiranjeevi Rapolu
@ 2017-09-18 12:12   ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2017-09-18 12:12 UTC (permalink / raw)
  To: Chiranjeevi Rapolu
  Cc: linux-media, sakari.ailus, tfiga, jian.xu.zheng, tian.shu.qiu,
	rajmohan.mani, hyungwoo.yang

Hi Chiranjeevi,

On Wed, Sep 06, 2017 at 11:26:33AM -0700, Chiranjeevi Rapolu wrote:
> Calculate pixel-rate at run time instead of compile time.
> 
> Instead of using hardcoded pixels-per-line, extract it from current sensor
> mode.
> 
> Signed-off-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
> ---
> Changes in v2:
> 	- Removed pixel-rate from struct definition.
> 	- Used pixel-rate formula wherever needed.
> 	- Changed commit message to reflect above changes.
>  drivers/media/i2c/ov13858.c | 42 ++++++++++++++++++++++--------------------
>  1 file changed, 22 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
> index af7af0d..77f256e 100644
> --- a/drivers/media/i2c/ov13858.c
> +++ b/drivers/media/i2c/ov13858.c
> @@ -104,7 +104,6 @@ struct ov13858_reg_list {
>  
>  /* Link frequency config */
>  struct ov13858_link_freq_config {
> -	u32 pixel_rate;
>  	u32 pixels_per_line;
>  
>  	/* PLL registers for this link frequency */
> @@ -958,8 +957,6 @@ struct ov13858_mode {
>  static const struct ov13858_link_freq_config
>  			link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
>  	{
> -		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> -		.pixel_rate = (OV13858_LINK_FREQ_540MHZ * 2 * 4) / 10,
>  		.pixels_per_line = OV13858_PPL_540MHZ,
>  		.reg_list = {
>  			.num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
> @@ -967,8 +964,6 @@ struct ov13858_mode {
>  		}
>  	},
>  	{
> -		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> -		.pixel_rate = (OV13858_LINK_FREQ_270MHZ * 2 * 4) / 10,
>  		.pixels_per_line = OV13858_PPL_270MHZ,
>  		.reg_list = {
>  			.num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
> @@ -1385,6 +1380,7 @@ static int ov13858_get_pad_format(struct v4l2_subdev *sd,
>  	s32 vblank_def;
>  	s32 vblank_min;
>  	s64 h_blank;
> +	s64 pixel_rate;
>  
>  	mutex_lock(&ov13858->mutex);
>  
> @@ -1400,9 +1396,9 @@ static int ov13858_get_pad_format(struct v4l2_subdev *sd,
>  	} else {
>  		ov13858->cur_mode = mode;
>  		__v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index);
> -		__v4l2_ctrl_s_ctrl_int64(
> -			ov13858->pixel_rate,
> -			link_freq_configs[mode->link_freq_index].pixel_rate);
> +		pixel_rate =
> +		(link_freq_menu_items[mode->link_freq_index] * 2 * 4) / 10;

You should indent what falls on the next line, and add subsequent line
wraps if needed.

> +		__v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate);
>  		/* Update limits and set FPS to default */
>  		vblank_def = ov13858->cur_mode->vts_def -
>  			     ov13858->cur_mode->height;
> @@ -1617,6 +1613,10 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
>  	s64 exposure_max;
>  	s64 vblank_def;
>  	s64 vblank_min;
> +	s64 hblank;
> +	s64 pixel_rate_min;
> +	s64 pixel_rate_max;
> +	const struct ov13858_mode *mode;
>  	int ret;
>  
>  	ctrl_hdlr = &ov13858->ctrl_handler;
> @@ -1634,29 +1634,31 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
>  				link_freq_menu_items);
>  	ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>  
> +	/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> +	pixel_rate_max = (link_freq_menu_items[0] * 2 * 4) / 10;
> +	pixel_rate_min = (link_freq_menu_items[1] * 2 * 4) / 10;

You're using the same, some could say non-trivial, formula in three places.

Could you add a macro for it? E.g.

/* double data rate => 2; four lanes => four; 10 bits per pixel => 10 */
#define link_freq_to_pixel_rate(f) ((f) * 2 * 4 / 10)

>  	/* By default, PIXEL_RATE is read only */
>  	ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
> -					V4L2_CID_PIXEL_RATE, 0,
> -					link_freq_configs[0].pixel_rate, 1,
> -					link_freq_configs[0].pixel_rate);
> +						V4L2_CID_PIXEL_RATE,
> +						pixel_rate_min, pixel_rate_max,
> +						1, pixel_rate_max);
>  
> -	vblank_def = ov13858->cur_mode->vts_def - ov13858->cur_mode->height;
> -	vblank_min = ov13858->cur_mode->vts_min - ov13858->cur_mode->height;
> +	mode = ov13858->cur_mode;
> +	vblank_def = mode->vts_def - mode->height;
> +	vblank_min = mode->vts_min - mode->height;
>  	ov13858->vblank = v4l2_ctrl_new_std(
>  				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
> -				vblank_min,
> -				OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
> +				vblank_min, OV13858_VTS_MAX - mode->height, 1,
>  				vblank_def);
>  
> +	hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
> +		 mode->width;
>  	ov13858->hblank = v4l2_ctrl_new_std(
>  				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
> -				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
> -				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
> -				1,
> -				OV13858_PPL_540MHZ - ov13858->cur_mode->width);
> +				hblank, hblank, 1, hblank);
>  	ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>  
> -	exposure_max = ov13858->cur_mode->vts_def - 8;
> +	exposure_max = mode->vts_def - 8;
>  	ov13858->exposure = v4l2_ctrl_new_std(
>  				ctrl_hdlr, &ov13858_ctrl_ops,
>  				V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3] media: ov13858: Calculate pixel-rate at runtime, use mode
  2017-09-05 23:44 [PATCH v1] media: ov13858: Calculate pixel-rate at runtime, use mode Rajmohan Mani
  2017-09-06  6:23 ` Sakari Ailus
  2017-09-06 18:26 ` [PATCH v2] " Chiranjeevi Rapolu
@ 2017-09-18 20:43 ` Chiranjeevi Rapolu
  2 siblings, 0 replies; 5+ messages in thread
From: Chiranjeevi Rapolu @ 2017-09-18 20:43 UTC (permalink / raw)
  To: linux-media, sakari.ailus
  Cc: tfiga, jian.xu.zheng, tian.shu.qiu, andy.yeh, rajmohan.mani,
	hyungwoo.yang, Chiranjeevi Rapolu

Calculate pixel-rate at run time instead of compile time.

Instead of using hardcoded pixels-per-line, extract it from current sensor
mode.

Signed-off-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
---
Changes in v3:
	- Use LINK_FREQ_TO_PIXEL_RATE macro.
	- Fix incorrect indentation.
 drivers/media/i2c/ov13858.c | 49 +++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
index af7af0d..4e331b4 100644
--- a/drivers/media/i2c/ov13858.c
+++ b/drivers/media/i2c/ov13858.c
@@ -104,7 +104,6 @@ struct ov13858_reg_list {
 
 /* Link frequency config */
 struct ov13858_link_freq_config {
-	u32 pixel_rate;
 	u32 pixels_per_line;
 
 	/* PLL registers for this link frequency */
@@ -948,6 +947,12 @@ struct ov13858_mode {
 #define OV13858_LINK_FREQ_INDEX_0	0
 #define OV13858_LINK_FREQ_INDEX_1	1
 
+/*
+ * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample
+ * data rate => double data rate; number of lanes => 4; bits per pixel => 10
+ */
+#define LINK_FREQ_TO_PIXEL_RATE(f)	(((f) * 2 * 4) / 10)
+
 /* Menu items for LINK_FREQ V4L2 control */
 static const s64 link_freq_menu_items[OV13858_NUM_OF_LINK_FREQS] = {
 	OV13858_LINK_FREQ_540MHZ,
@@ -958,8 +963,6 @@ struct ov13858_mode {
 static const struct ov13858_link_freq_config
 			link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
 	{
-		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
-		.pixel_rate = (OV13858_LINK_FREQ_540MHZ * 2 * 4) / 10,
 		.pixels_per_line = OV13858_PPL_540MHZ,
 		.reg_list = {
 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
@@ -967,8 +970,6 @@ struct ov13858_mode {
 		}
 	},
 	{
-		/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
-		.pixel_rate = (OV13858_LINK_FREQ_270MHZ * 2 * 4) / 10,
 		.pixels_per_line = OV13858_PPL_270MHZ,
 		.reg_list = {
 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
@@ -1385,6 +1386,8 @@ static int ov13858_get_pad_format(struct v4l2_subdev *sd,
 	s32 vblank_def;
 	s32 vblank_min;
 	s64 h_blank;
+	s64 pixel_rate;
+	s64 link_freq;
 
 	mutex_lock(&ov13858->mutex);
 
@@ -1400,9 +1403,10 @@ static int ov13858_get_pad_format(struct v4l2_subdev *sd,
 	} else {
 		ov13858->cur_mode = mode;
 		__v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index);
-		__v4l2_ctrl_s_ctrl_int64(
-			ov13858->pixel_rate,
-			link_freq_configs[mode->link_freq_index].pixel_rate);
+		link_freq = link_freq_menu_items[mode->link_freq_index];
+		pixel_rate = LINK_FREQ_TO_PIXEL_RATE(link_freq);
+		__v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate);
+
 		/* Update limits and set FPS to default */
 		vblank_def = ov13858->cur_mode->vts_def -
 			     ov13858->cur_mode->height;
@@ -1617,6 +1621,10 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
 	s64 exposure_max;
 	s64 vblank_def;
 	s64 vblank_min;
+	s64 hblank;
+	s64 pixel_rate_min;
+	s64 pixel_rate_max;
+	const struct ov13858_mode *mode;
 	int ret;
 
 	ctrl_hdlr = &ov13858->ctrl_handler;
@@ -1634,29 +1642,30 @@ static int ov13858_init_controls(struct ov13858 *ov13858)
 				link_freq_menu_items);
 	ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
+	pixel_rate_max = LINK_FREQ_TO_PIXEL_RATE(link_freq_menu_items[0]);
+	pixel_rate_min = LINK_FREQ_TO_PIXEL_RATE(link_freq_menu_items[1]);
 	/* By default, PIXEL_RATE is read only */
 	ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
-					V4L2_CID_PIXEL_RATE, 0,
-					link_freq_configs[0].pixel_rate, 1,
-					link_freq_configs[0].pixel_rate);
+						V4L2_CID_PIXEL_RATE,
+						pixel_rate_min, pixel_rate_max,
+						1, pixel_rate_max);
 
-	vblank_def = ov13858->cur_mode->vts_def - ov13858->cur_mode->height;
-	vblank_min = ov13858->cur_mode->vts_min - ov13858->cur_mode->height;
+	mode = ov13858->cur_mode;
+	vblank_def = mode->vts_def - mode->height;
+	vblank_min = mode->vts_min - mode->height;
 	ov13858->vblank = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
-				vblank_min,
-				OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
+				vblank_min, OV13858_VTS_MAX - mode->height, 1,
 				vblank_def);
 
+	hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
+		 mode->width;
 	ov13858->hblank = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width,
-				1,
-				OV13858_PPL_540MHZ - ov13858->cur_mode->width);
+				hblank, hblank, 1, hblank);
 	ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
-	exposure_max = ov13858->cur_mode->vts_def - 8;
+	exposure_max = mode->vts_def - 8;
 	ov13858->exposure = v4l2_ctrl_new_std(
 				ctrl_hdlr, &ov13858_ctrl_ops,
 				V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-09-18 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 23:44 [PATCH v1] media: ov13858: Calculate pixel-rate at runtime, use mode Rajmohan Mani
2017-09-06  6:23 ` Sakari Ailus
2017-09-06 18:26 ` [PATCH v2] " Chiranjeevi Rapolu
2017-09-18 12:12   ` Sakari Ailus
2017-09-18 20:43 ` [PATCH v3] " Chiranjeevi Rapolu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).