public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments
@ 2013-08-10 17:49 Sakari Ailus
  2013-08-10 17:49 ` [PATCH 1/4] smiapp: re-use clamp_t instead of min(..., max(...)) Sakari Ailus
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Sakari Ailus @ 2013-08-10 17:49 UTC (permalink / raw)
  To: linux-media; +Cc: andriy.shevchenko, laurent.pinchart

Hi,

This patchset contains Andy's cleanup patch (with clamp_t replaced with
clamp) and a few clock tree interface related fixes and a few comments to
PLL calculation.

-- 
Cheers,
Sakari


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

* [PATCH 1/4] smiapp: re-use clamp_t instead of min(..., max(...))
  2013-08-10 17:49 [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Sakari Ailus
@ 2013-08-10 17:49 ` Sakari Ailus
  2013-08-10 17:49 ` [PATCH 2/4] smiapp-pll: Add a few comments to PLL calculation Sakari Ailus
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2013-08-10 17:49 UTC (permalink / raw)
  To: linux-media; +Cc: andriy.shevchenko, laurent.pinchart

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

clamp_t does the job to put a variable into the given range.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

clamp_t -> clamp as agreed with Andy.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/i2c/smiapp/smiapp-core.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 7ac7580..4d7ba54 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -1835,12 +1835,12 @@ static void smiapp_set_compose_scaler(struct v4l2_subdev *subdev,
 		* sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
 		/ sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
 
-	a = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
-		max(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
-	b = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
-		max(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
-	max_m = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
-		    max(max_m, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
+	a = clamp(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN],
+		  sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX]);
+	b = clamp(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN],
+		  sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX]);
+	max_m = clamp(max_m, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN],
+		      sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX]);
 
 	dev_dbg(&client->dev, "scaling: a %d b %d max_m %d\n", a, b, max_m);
 
-- 
1.7.10.4


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

* [PATCH 2/4] smiapp-pll: Add a few comments to PLL calculation
  2013-08-10 17:49 [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Sakari Ailus
  2013-08-10 17:49 ` [PATCH 1/4] smiapp: re-use clamp_t instead of min(..., max(...)) Sakari Ailus
@ 2013-08-10 17:49 ` Sakari Ailus
  2013-08-10 17:49 ` [PATCH 3/4] smiapp: Prepare and unprepare clocks correctly Sakari Ailus
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2013-08-10 17:49 UTC (permalink / raw)
  To: linux-media; +Cc: andriy.shevchenko, laurent.pinchart

The PLL calculation heuristics is rather complicated and and is often
difficult to understand to its original author.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/i2c/smiapp-pll.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/media/i2c/smiapp-pll.c b/drivers/media/i2c/smiapp-pll.c
index d8d5da7..c83d301 100644
--- a/drivers/media/i2c/smiapp-pll.c
+++ b/drivers/media/i2c/smiapp-pll.c
@@ -87,6 +87,17 @@ static void print_pll(struct device *dev, struct smiapp_pll *pll)
 	dev_dbg(dev, "vt_pix_clk_freq_hz \t%d\n", pll->vt_pix_clk_freq_hz);
 }
 
+/*
+ * Heuristically guess the PLL tree for a given common multiplier and
+ * divisor. Begin with the operational timing and continue to video
+ * timing once operational timing has been verified.
+ *
+ * @mul is the PLL multiplier and @div is the common divisor
+ * (pre_pll_clk_div and op_sys_clk_div combined). The final PLL
+ * multiplier will be a multiple of @mul.
+ *
+ * @return Zero on success, error code on error.
+ */
 static int __smiapp_pll_calculate(struct device *dev,
 				  const struct smiapp_pll_limits *limits,
 				  struct smiapp_pll *pll, uint32_t mul,
@@ -95,6 +106,12 @@ static int __smiapp_pll_calculate(struct device *dev,
 	uint32_t sys_div;
 	uint32_t best_pix_div = INT_MAX >> 1;
 	uint32_t vt_op_binning_div;
+	/*
+	 * Higher multipliers (and divisors) are often required than
+	 * necessitated by the external clock and the output clocks. 
+	 * There are limits for all values in the clock tree. These
+	 * are the minimum and maximum multiplier for mul.
+	 */
 	uint32_t more_mul_min, more_mul_max;
 	uint32_t more_mul_factor;
 	uint32_t min_vt_div, max_vt_div, vt_div;
-- 
1.7.10.4


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

* [PATCH 3/4] smiapp: Prepare and unprepare clocks correctly
  2013-08-10 17:49 [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Sakari Ailus
  2013-08-10 17:49 ` [PATCH 1/4] smiapp: re-use clamp_t instead of min(..., max(...)) Sakari Ailus
  2013-08-10 17:49 ` [PATCH 2/4] smiapp-pll: Add a few comments to PLL calculation Sakari Ailus
@ 2013-08-10 17:49 ` Sakari Ailus
  2013-08-10 17:49 ` [PATCH 4/4] smiapp: Call the clock "ext_clk" Sakari Ailus
  2013-08-21 11:59 ` [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Laurent Pinchart
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2013-08-10 17:49 UTC (permalink / raw)
  To: linux-media; +Cc: andriy.shevchenko, laurent.pinchart

Prepare clocks before enabling and unprepare after disabling them.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/i2c/smiapp/smiapp-core.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 4d7ba54..7de9892 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -1122,9 +1122,9 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 		rval = sensor->platform_data->set_xclk(
 			&sensor->src->sd, sensor->platform_data->ext_clk);
 	else
-		rval = clk_enable(sensor->ext_clk);
+		rval = clk_prepare_enable(sensor->ext_clk);
 	if (rval < 0) {
-		dev_dbg(&client->dev, "failed to set xclk\n");
+		dev_dbg(&client->dev, "failed to enable xclk\n");
 		goto out_xclk_fail;
 	}
 	usleep_range(1000, 1000);
@@ -1244,7 +1244,7 @@ out_cci_addr_fail:
 	if (sensor->platform_data->set_xclk)
 		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
 	else
-		clk_disable(sensor->ext_clk);
+		clk_disable_unprepare(sensor->ext_clk);
 
 out_xclk_fail:
 	regulator_disable(sensor->vana);
@@ -1270,7 +1270,7 @@ static void smiapp_power_off(struct smiapp_sensor *sensor)
 	if (sensor->platform_data->set_xclk)
 		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
 	else
-		clk_disable(sensor->ext_clk);
+		clk_disable_unprepare(sensor->ext_clk);
 	usleep_range(5000, 5000);
 	regulator_disable(sensor->vana);
 	sensor->streaming = 0;
@@ -2839,7 +2839,7 @@ static int smiapp_remove(struct i2c_client *client)
 		if (sensor->platform_data->set_xclk)
 			sensor->platform_data->set_xclk(&sensor->src->sd, 0);
 		else
-			clk_disable(sensor->ext_clk);
+			clk_disable_unprepare(sensor->ext_clk);
 		sensor->power_count = 0;
 	}
 
-- 
1.7.10.4


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

* [PATCH 4/4] smiapp: Call the clock "ext_clk"
  2013-08-10 17:49 [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Sakari Ailus
                   ` (2 preceding siblings ...)
  2013-08-10 17:49 ` [PATCH 3/4] smiapp: Prepare and unprepare clocks correctly Sakari Ailus
@ 2013-08-10 17:49 ` Sakari Ailus
  2013-08-21 11:59 ` [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Laurent Pinchart
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2013-08-10 17:49 UTC (permalink / raw)
  To: linux-media; +Cc: andriy.shevchenko, laurent.pinchart

As the clock framework makes it possible to assign a device specific name to
the clocks, remove the ability to use a named clock in the driver.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/i2c/smiapp/smiapp-core.c |    9 +++------
 include/media/smiapp.h                 |    1 -
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 7de9892..ae66d91 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2363,11 +2363,9 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 	}
 
 	if (!sensor->platform_data->set_xclk) {
-		sensor->ext_clk = devm_clk_get(&client->dev,
-					sensor->platform_data->ext_clk_name);
+		sensor->ext_clk = devm_clk_get(&client->dev, "ext_clk");
 		if (IS_ERR(sensor->ext_clk)) {
-			dev_err(&client->dev, "could not get clock %s\n",
-				sensor->platform_data->ext_clk_name);
+			dev_err(&client->dev, "could not get clock\n");
 			return -ENODEV;
 		}
 
@@ -2375,8 +2373,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 				    sensor->platform_data->ext_clk);
 		if (rval < 0) {
 			dev_err(&client->dev,
-				"unable to set clock %s freq to %u\n",
-				sensor->platform_data->ext_clk_name,
+				"unable to set clock freq to %u\n",
 				sensor->platform_data->ext_clk);
 			return -ENODEV;
 		}
diff --git a/include/media/smiapp.h b/include/media/smiapp.h
index 07f96a8..0b8f124 100644
--- a/include/media/smiapp.h
+++ b/include/media/smiapp.h
@@ -77,7 +77,6 @@ struct smiapp_platform_data {
 	struct smiapp_flash_strobe_parms *strobe_setup;
 
 	int (*set_xclk)(struct v4l2_subdev *sd, int hz);
-	char *ext_clk_name;
 	int xshutdown;			/* gpio or SMIAPP_NO_XSHUTDOWN */
 };
 
-- 
1.7.10.4


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

* Re: [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments
  2013-08-10 17:49 [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Sakari Ailus
                   ` (3 preceding siblings ...)
  2013-08-10 17:49 ` [PATCH 4/4] smiapp: Call the clock "ext_clk" Sakari Ailus
@ 2013-08-21 11:59 ` Laurent Pinchart
  2013-08-21 12:04   ` Sakari Ailus
  4 siblings, 1 reply; 7+ messages in thread
From: Laurent Pinchart @ 2013-08-21 11:59 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, andriy.shevchenko

Hi Sakari,

Thank you for the patches.

On Saturday 10 August 2013 20:49:44 Sakari Ailus wrote:
> Hi,
> 
> This patchset contains Andy's cleanup patch (with clamp_t replaced with
> clamp) and a few clock tree interface related fixes and a few comments to
> PLL calculation.

There's a trailing white space in patch 2/4. Appart from that, for the whole 
set,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I've taken the patches in my tree (with the trailing white space removed) and 
will send a pull request.

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments
  2013-08-21 11:59 ` [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Laurent Pinchart
@ 2013-08-21 12:04   ` Sakari Ailus
  0 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2013-08-21 12:04 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media, andriy.shevchenko

On Wed, Aug 21, 2013 at 01:59:31PM +0200, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thank you for the patches.
> 
> On Saturday 10 August 2013 20:49:44 Sakari Ailus wrote:
> > Hi,
> > 
> > This patchset contains Andy's cleanup patch (with clamp_t replaced with
> > clamp) and a few clock tree interface related fixes and a few comments to
> > PLL calculation.
> 
> There's a trailing white space in patch 2/4. Appart from that, for the whole 
> set,
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> I've taken the patches in my tree (with the trailing white space removed) and 
> will send a pull request.

Thanks!

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

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

end of thread, other threads:[~2013-08-21 12:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-10 17:49 [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Sakari Ailus
2013-08-10 17:49 ` [PATCH 1/4] smiapp: re-use clamp_t instead of min(..., max(...)) Sakari Ailus
2013-08-10 17:49 ` [PATCH 2/4] smiapp-pll: Add a few comments to PLL calculation Sakari Ailus
2013-08-10 17:49 ` [PATCH 3/4] smiapp: Prepare and unprepare clocks correctly Sakari Ailus
2013-08-10 17:49 ` [PATCH 4/4] smiapp: Call the clock "ext_clk" Sakari Ailus
2013-08-21 11:59 ` [PATCH 0/4] smiapp: Small cleanup; clock framework fixes and clock tree comments Laurent Pinchart
2013-08-21 12:04   ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox