Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] mt9p031: Use generic PLL setup code

Compute the PLL parameters at runtime using the generic Aptina PLL
helper.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
08cd43cc 0b27c81b

+28 -35
+1
drivers/media/video/Kconfig
··· 493 493 config VIDEO_MT9P031 494 494 tristate "Aptina MT9P031 support" 495 495 depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API 496 + select VIDEO_APTINA_PLL 496 497 ---help--- 497 498 This is a Video4Linux2 sensor-level driver for the Aptina 498 499 (Micron) mt9p031 5 Mpixel camera.
+27 -35
drivers/media/video/mt9p031.c
··· 27 27 #include <media/v4l2-device.h> 28 28 #include <media/v4l2-subdev.h> 29 29 30 + #include "aptina-pll.h" 31 + 30 32 #define MT9P031_PIXEL_ARRAY_WIDTH 2752 31 33 #define MT9P031_PIXEL_ARRAY_HEIGHT 2004 32 34 ··· 99 97 #define MT9P031_TEST_PATTERN_RED 0xa2 100 98 #define MT9P031_TEST_PATTERN_BLUE 0xa3 101 99 102 - struct mt9p031_pll_divs { 103 - u32 ext_freq; 104 - u32 target_freq; 105 - u8 m; 106 - u8 n; 107 - u8 p1; 108 - }; 109 - 110 100 struct mt9p031 { 111 101 struct v4l2_subdev subdev; 112 102 struct media_pad pad; ··· 109 115 struct mutex power_lock; /* lock to protect power_count */ 110 116 int power_count; 111 117 112 - const struct mt9p031_pll_divs *pll; 118 + struct aptina_pll pll; 113 119 114 120 /* Registers cache */ 115 121 u16 output_control; ··· 177 183 0); 178 184 } 179 185 180 - /* 181 - * This static table uses ext_freq and vdd_io values to select suitable 182 - * PLL dividers m, n and p1 which have been calculated as specifiec in p36 183 - * of Aptina's mt9p031 datasheet. New values should be added here. 184 - */ 185 - static const struct mt9p031_pll_divs mt9p031_divs[] = { 186 - /* ext_freq target_freq m n p1 */ 187 - {21000000, 48000000, 26, 2, 6} 188 - }; 189 - 190 - static int mt9p031_pll_get_divs(struct mt9p031 *mt9p031) 186 + static int mt9p031_pll_setup(struct mt9p031 *mt9p031) 191 187 { 188 + static const struct aptina_pll_limits limits = { 189 + .ext_clock_min = 6000000, 190 + .ext_clock_max = 27000000, 191 + .int_clock_min = 2000000, 192 + .int_clock_max = 13500000, 193 + .out_clock_min = 180000000, 194 + .out_clock_max = 360000000, 195 + .pix_clock_max = 96000000, 196 + .n_min = 1, 197 + .n_max = 64, 198 + .m_min = 16, 199 + .m_max = 255, 200 + .p1_min = 1, 201 + .p1_max = 128, 202 + }; 203 + 192 204 struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); 193 - int i; 205 + struct mt9p031_platform_data *pdata = mt9p031->pdata; 194 206 195 - for (i = 0; i < ARRAY_SIZE(mt9p031_divs); i++) { 196 - if (mt9p031_divs[i].ext_freq == mt9p031->pdata->ext_freq && 197 - mt9p031_divs[i].target_freq == mt9p031->pdata->target_freq) { 198 - mt9p031->pll = &mt9p031_divs[i]; 199 - return 0; 200 - } 201 - } 207 + mt9p031->pll.ext_clock = pdata->ext_freq; 208 + mt9p031->pll.pix_clock = pdata->target_freq; 202 209 203 - dev_err(&client->dev, "Couldn't find PLL dividers for ext_freq = %d, " 204 - "target_freq = %d\n", mt9p031->pdata->ext_freq, 205 - mt9p031->pdata->target_freq); 206 - return -EINVAL; 210 + return aptina_pll_calculate(&client->dev, &limits, &mt9p031->pll); 207 211 } 208 212 209 213 static int mt9p031_pll_enable(struct mt9p031 *mt9p031) ··· 215 223 return ret; 216 224 217 225 ret = mt9p031_write(client, MT9P031_PLL_CONFIG_1, 218 - (mt9p031->pll->m << 8) | (mt9p031->pll->n - 1)); 226 + (mt9p031->pll.m << 8) | (mt9p031->pll.n - 1)); 219 227 if (ret < 0) 220 228 return ret; 221 229 222 - ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll->p1 - 1); 230 + ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll.p1 - 1); 223 231 if (ret < 0) 224 232 return ret; 225 233 ··· 892 900 mt9p031->format.field = V4L2_FIELD_NONE; 893 901 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; 894 902 895 - ret = mt9p031_pll_get_divs(mt9p031); 903 + ret = mt9p031_pll_setup(mt9p031); 896 904 897 905 done: 898 906 if (ret < 0) {