[PATCH] mt9p031: Do not use PLL if external frequency is the same as target frequency.

2011-09-06 Thread Javier Martin
This patch adds a check to see whether ext_freq and target_freq are equal and,
if true, PLL won't be used.

Signed-off-by: Javier Martin javier.mar...@vista-silicon.com
---
 drivers/media/video/mt9p031.c |   18 +++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c
index 5cfa39f..42b5d18 100644
--- a/drivers/media/video/mt9p031.c
+++ b/drivers/media/video/mt9p031.c
@@ -117,6 +117,7 @@ struct mt9p031 {
u16 xskip;
u16 yskip;
 
+   bool use_pll;
const struct mt9p031_pll_divs *pll;
 
/* Registers cache */
@@ -201,10 +202,16 @@ static int mt9p031_pll_get_divs(struct mt9p031 *mt9p031)
struct i2c_client *client = v4l2_get_subdevdata(mt9p031-subdev);
int i;
 
+   if (mt9p031-pdata-ext_freq == mt9p031-pdata-target_freq) {
+   mt9p031-use_pll = false;
+   return 0;
+   }
+
for (i = 0; i  ARRAY_SIZE(mt9p031_divs); i++) {
if (mt9p031_divs[i].ext_freq == mt9p031-pdata-ext_freq 
  mt9p031_divs[i].target_freq == mt9p031-pdata-target_freq) {
mt9p031-pll = mt9p031_divs[i];
+   mt9p031-use_pll = true;
return 0;
}
}
@@ -385,8 +392,10 @@ static int mt9p031_s_stream(struct v4l2_subdev *subdev, 
int enable)
 MT9P031_OUTPUT_CONTROL_CEN, 0);
if (ret  0)
return ret;
-
-   return mt9p031_pll_disable(mt9p031);
+   if (mt9p031-use_pll)
+   return mt9p031_pll_disable(mt9p031);
+   else
+   return 0;
}
 
ret = mt9p031_set_params(mt9p031);
@@ -399,7 +408,10 @@ static int mt9p031_s_stream(struct v4l2_subdev *subdev, 
int enable)
if (ret  0)
return ret;
 
-   return mt9p031_pll_enable(mt9p031);
+   if (mt9p031-use_pll)
+   return mt9p031_pll_enable(mt9p031);
+   else
+   return 0;
 }
 
 static int mt9p031_enum_mbus_code(struct v4l2_subdev *subdev,
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mt9p031: Do not use PLL if external frequency is the same as target frequency.

2011-09-06 Thread Laurent Pinchart
Hi Javier,

On Tuesday 06 September 2011 12:03:00 Javier Martin wrote:
 This patch adds a check to see whether ext_freq and target_freq are equal
 and, if true, PLL won't be used.

Thanks for the patch.

As you're touching PLL code, what about fixing PLL setup by computing 
parameters dynamically instead of using a table of hardcoded values ? :-)

 Signed-off-by: Javier Martin javier.mar...@vista-silicon.com
 ---
  drivers/media/video/mt9p031.c |   18 +++---
  1 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c
 index 5cfa39f..42b5d18 100644
 --- a/drivers/media/video/mt9p031.c
 +++ b/drivers/media/video/mt9p031.c
 @@ -117,6 +117,7 @@ struct mt9p031 {
   u16 xskip;
   u16 yskip;
 
 + bool use_pll;
   const struct mt9p031_pll_divs *pll;
 
   /* Registers cache */
 @@ -201,10 +202,16 @@ static int mt9p031_pll_get_divs(struct mt9p031
 *mt9p031) struct i2c_client *client =
 v4l2_get_subdevdata(mt9p031-subdev); int i;
 
 + if (mt9p031-pdata-ext_freq == mt9p031-pdata-target_freq) {
 + mt9p031-use_pll = false;
 + return 0;
 + }
 +
   for (i = 0; i  ARRAY_SIZE(mt9p031_divs); i++) {
   if (mt9p031_divs[i].ext_freq == mt9p031-pdata-ext_freq 
 mt9p031_divs[i].target_freq == mt9p031-pdata-target_freq) {
   mt9p031-pll = mt9p031_divs[i];
 + mt9p031-use_pll = true;
   return 0;
   }
   }
 @@ -385,8 +392,10 @@ static int mt9p031_s_stream(struct v4l2_subdev
 *subdev, int enable) MT9P031_OUTPUT_CONTROL_CEN, 0);
   if (ret  0)
   return ret;
 -
 - return mt9p031_pll_disable(mt9p031);
 + if (mt9p031-use_pll)
 + return mt9p031_pll_disable(mt9p031);
 + else
 + return 0;
   }
 
   ret = mt9p031_set_params(mt9p031);
 @@ -399,7 +408,10 @@ static int mt9p031_s_stream(struct v4l2_subdev
 *subdev, int enable) if (ret  0)
   return ret;
 
 - return mt9p031_pll_enable(mt9p031);
 + if (mt9p031-use_pll)
 + return mt9p031_pll_enable(mt9p031);
 + else
 + return 0;
  }
 
  static int mt9p031_enum_mbus_code(struct v4l2_subdev *subdev,

-- 
Regards,

Laurent Pinchart
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mt9p031: Do not use PLL if external frequency is the same as target frequency.

2011-09-06 Thread javier Martin
On 6 September 2011 12:27, Laurent Pinchart
laurent.pinch...@ideasonboard.com wrote:
 Hi Javier,

 On Tuesday 06 September 2011 12:03:00 Javier Martin wrote:
 This patch adds a check to see whether ext_freq and target_freq are equal
 and, if true, PLL won't be used.

 Thanks for the patch.

 As you're touching PLL code, what about fixing PLL setup by computing
 parameters dynamically instead of using a table of hardcoded values ? :-)

Hi Laurent,
I'm not exactly struggling with PLL code right now. I've just get a
new prototype which provides an external 48MHz oscillator for the
clock. So, no need to use PLL there and thus the purpose of this
patch.

However, as you said, dynamic configuration of PLL is one of the
pending issues on the driver and I might address it myself in the
future, but it depends on requirements of the project.


Regards.
-- 
Javier Martin
Vista Silicon S.L.
CDTUC - FASE C - Oficina S-345
Avda de los Castros s/n
39005- Santander. Cantabria. Spain
+34 942 25 32 60
www.vista-silicon.com
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html