Skip to content

Commit 08cd43c

Browse files
pinchartlMauro Carvalho Chehab
authored and
Mauro Carvalho Chehab
committed
[media] mt9p031: Use generic PLL setup code
Compute the PLL parameters at runtime using the generic Aptina PLL helper. Signed-off-by: Laurent Pinchart <[email protected]> Acked-by: Sakari Ailus <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 0b27c81 commit 08cd43c

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

drivers/media/video/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ config VIDEO_VS6624
493493
config VIDEO_MT9P031
494494
tristate "Aptina MT9P031 support"
495495
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
496+
select VIDEO_APTINA_PLL
496497
---help---
497498
This is a Video4Linux2 sensor-level driver for the Aptina
498499
(Micron) mt9p031 5 Mpixel camera.

drivers/media/video/mt9p031.c

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <media/v4l2-device.h>
2828
#include <media/v4l2-subdev.h>
2929

30+
#include "aptina-pll.h"
31+
3032
#define MT9P031_PIXEL_ARRAY_WIDTH 2752
3133
#define MT9P031_PIXEL_ARRAY_HEIGHT 2004
3234

@@ -97,14 +99,6 @@
9799
#define MT9P031_TEST_PATTERN_RED 0xa2
98100
#define MT9P031_TEST_PATTERN_BLUE 0xa3
99101

100-
struct mt9p031_pll_divs {
101-
u32 ext_freq;
102-
u32 target_freq;
103-
u8 m;
104-
u8 n;
105-
u8 p1;
106-
};
107-
108102
struct mt9p031 {
109103
struct v4l2_subdev subdev;
110104
struct media_pad pad;
@@ -115,7 +109,7 @@ struct mt9p031 {
115109
struct mutex power_lock; /* lock to protect power_count */
116110
int power_count;
117111

118-
const struct mt9p031_pll_divs *pll;
112+
struct aptina_pll pll;
119113

120114
/* Registers cache */
121115
u16 output_control;
@@ -183,33 +177,31 @@ static int mt9p031_reset(struct mt9p031 *mt9p031)
183177
0);
184178
}
185179

186-
/*
187-
* This static table uses ext_freq and vdd_io values to select suitable
188-
* PLL dividers m, n and p1 which have been calculated as specifiec in p36
189-
* of Aptina's mt9p031 datasheet. New values should be added here.
190-
*/
191-
static const struct mt9p031_pll_divs mt9p031_divs[] = {
192-
/* ext_freq target_freq m n p1 */
193-
{21000000, 48000000, 26, 2, 6}
194-
};
195-
196-
static int mt9p031_pll_get_divs(struct mt9p031 *mt9p031)
180+
static int mt9p031_pll_setup(struct mt9p031 *mt9p031)
197181
{
182+
static const struct aptina_pll_limits limits = {
183+
.ext_clock_min = 6000000,
184+
.ext_clock_max = 27000000,
185+
.int_clock_min = 2000000,
186+
.int_clock_max = 13500000,
187+
.out_clock_min = 180000000,
188+
.out_clock_max = 360000000,
189+
.pix_clock_max = 96000000,
190+
.n_min = 1,
191+
.n_max = 64,
192+
.m_min = 16,
193+
.m_max = 255,
194+
.p1_min = 1,
195+
.p1_max = 128,
196+
};
197+
198198
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
199-
int i;
199+
struct mt9p031_platform_data *pdata = mt9p031->pdata;
200200

201-
for (i = 0; i < ARRAY_SIZE(mt9p031_divs); i++) {
202-
if (mt9p031_divs[i].ext_freq == mt9p031->pdata->ext_freq &&
203-
mt9p031_divs[i].target_freq == mt9p031->pdata->target_freq) {
204-
mt9p031->pll = &mt9p031_divs[i];
205-
return 0;
206-
}
207-
}
201+
mt9p031->pll.ext_clock = pdata->ext_freq;
202+
mt9p031->pll.pix_clock = pdata->target_freq;
208203

209-
dev_err(&client->dev, "Couldn't find PLL dividers for ext_freq = %d, "
210-
"target_freq = %d\n", mt9p031->pdata->ext_freq,
211-
mt9p031->pdata->target_freq);
212-
return -EINVAL;
204+
return aptina_pll_calculate(&client->dev, &limits, &mt9p031->pll);
213205
}
214206

215207
static int mt9p031_pll_enable(struct mt9p031 *mt9p031)
@@ -223,11 +215,11 @@ static int mt9p031_pll_enable(struct mt9p031 *mt9p031)
223215
return ret;
224216

225217
ret = mt9p031_write(client, MT9P031_PLL_CONFIG_1,
226-
(mt9p031->pll->m << 8) | (mt9p031->pll->n - 1));
218+
(mt9p031->pll.m << 8) | (mt9p031->pll.n - 1));
227219
if (ret < 0)
228220
return ret;
229221

230-
ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll->p1 - 1);
222+
ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll.p1 - 1);
231223
if (ret < 0)
232224
return ret;
233225

@@ -900,7 +892,7 @@ static int mt9p031_probe(struct i2c_client *client,
900892
mt9p031->format.field = V4L2_FIELD_NONE;
901893
mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB;
902894

903-
ret = mt9p031_pll_get_divs(mt9p031);
895+
ret = mt9p031_pll_setup(mt9p031);
904896

905897
done:
906898
if (ret < 0) {

0 commit comments

Comments
 (0)