* [PATCH v3 06/15] media: i2c: Add ov7251_pll_configure()
2022-05-04 22:30 [PATCH v3 00/15] Support OVTI7251 on Microsoft Surface line Daniel Scally
@ 2022-05-04 22:30 ` Daniel Scally
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Scally @ 2022-05-04 22:30 UTC (permalink / raw)
To: linux-media
Cc: yong.zhi, sakari.ailus, bingbu.cao, tian.shu.qiu,
andriy.shevchenko, hverkuil-cisco
Rather than having the pll settings hidden inside mode blobs, define
them in structs and use a dedicated function to set them. This makes
it simpler to extend the driver to support other frequencies for both
the external clock and desired link frequency.
Signed-off-by: Daniel Scally <djrscally@gmail.com>
---
Changes in v3:
- Added commas to last items in arrays (Andy)
Changes in v2:
- Updated to support different link-frequencies in addition to different
external clock frequencies.
drivers/media/i2c/ov7251.c | 175 ++++++++++++++++++++++++++++++-------
1 file changed, 145 insertions(+), 30 deletions(-)
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
index f21119064b2d..3440077e8ba9 100644
--- a/drivers/media/i2c/ov7251.c
+++ b/drivers/media/i2c/ov7251.c
@@ -42,6 +42,16 @@
#define OV7251_TIMING_FORMAT2_MIRROR BIT(2)
#define OV7251_PRE_ISP_00 0x5e00
#define OV7251_PRE_ISP_00_TEST_PATTERN BIT(7)
+#define OV7251_PLL1_PRE_DIV_REG 0x30b4
+#define OV7251_PLL1_MULT_REG 0x30b3
+#define OV7251_PLL1_DIVIDER_REG 0x30b1
+#define OV7251_PLL1_PIX_DIV_REG 0x30b0
+#define OV7251_PLL1_MIPI_DIV_REG 0x30b5
+#define OV7251_PLL2_PRE_DIV_REG 0x3098
+#define OV7251_PLL2_MULT_REG 0x3099
+#define OV7251_PLL2_DIVIDER_REG 0x309d
+#define OV7251_PLL2_SYS_DIV_REG 0x309a
+#define OV7251_PLL2_ADC_DIV_REG 0x309b
struct reg_value {
u16 reg;
@@ -60,6 +70,36 @@ struct ov7251_mode_info {
struct v4l2_fract timeperframe;
};
+struct ov7251_pll1_cfg {
+ unsigned int pre_div;
+ unsigned int mult;
+ unsigned int div;
+ unsigned int pix_div;
+ unsigned int mipi_div;
+};
+
+struct ov7251_pll2_cfg {
+ unsigned int pre_div;
+ unsigned int mult;
+ unsigned int div;
+ unsigned int sys_div;
+ unsigned int adc_div;
+};
+
+/*
+ * Rubbish ordering, but only PLL1 needs to have a separate configuration per
+ * link frequency and the array member needs to be last.
+ */
+struct ov7251_pll_cfgs {
+ const struct ov7251_pll2_cfg *pll2;
+ const struct ov7251_pll1_cfg *pll1[];
+};
+
+enum xclk_rate {
+ OV7251_24_MHZ,
+ OV7251_NUM_SUPPORTED_RATES
+};
+
enum supported_link_freqs {
OV7251_LINK_FREQ_240_MHZ,
OV7251_NUM_SUPPORTED_LINK_FREQS
@@ -80,6 +120,7 @@ struct ov7251 {
struct regulator *core_regulator;
struct regulator *analog_regulator;
+ const struct ov7251_pll_cfgs *pll_cfgs;
enum supported_link_freqs link_freq_idx;
const struct ov7251_mode_info *current_mode;
@@ -106,6 +147,33 @@ static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd)
return container_of(sd, struct ov7251, sd);
}
+static const struct ov7251_pll1_cfg ov7251_pll1_cfg_24_mhz_240_mhz = {
+ .pre_div = 0x03,
+ .mult = 0x64,
+ .div = 0x01,
+ .pix_div = 0x0a,
+ .mipi_div = 0x05,
+};
+
+static const struct ov7251_pll2_cfg ov7251_pll2_cfg_24_mhz = {
+ .pre_div = 0x04,
+ .mult = 0x28,
+ .div = 0x00,
+ .sys_div = 0x05,
+ .adc_div = 0x04,
+};
+
+static const struct ov7251_pll_cfgs ov7251_pll_cfgs_24_mhz = {
+ .pll2 = &ov7251_pll2_cfg_24_mhz,
+ .pll1 = {
+ [OV7251_LINK_FREQ_240_MHZ] = &ov7251_pll1_cfg_24_mhz_240_mhz,
+ },
+};
+
+static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = {
+ [OV7251_24_MHZ] = &ov7251_pll_cfgs_24_mhz,
+};
+
static const struct reg_value ov7251_global_init_setting[] = {
{ 0x0103, 0x01 },
{ 0x303b, 0x02 },
@@ -124,16 +192,6 @@ static const struct reg_value ov7251_setting_vga_30fps[] = {
{ 0x301c, 0xf0 },
{ 0x3023, 0x05 },
{ 0x3037, 0xf0 },
- { 0x3098, 0x04 }, /* pll2 pre divider */
- { 0x3099, 0x28 }, /* pll2 multiplier */
- { 0x309a, 0x05 }, /* pll2 sys divider */
- { 0x309b, 0x04 }, /* pll2 adc divider */
- { 0x309d, 0x00 }, /* pll2 divider */
- { 0x30b0, 0x0a }, /* pll1 pix divider */
- { 0x30b1, 0x01 }, /* pll1 divider */
- { 0x30b3, 0x64 }, /* pll1 multiplier */
- { 0x30b4, 0x03 }, /* pll1 pre divider */
- { 0x30b5, 0x05 }, /* pll1 mipi divider */
{ 0x3106, 0xda },
{ 0x3503, 0x07 },
{ 0x3509, 0x10 },
@@ -262,16 +320,6 @@ static const struct reg_value ov7251_setting_vga_60fps[] = {
{ 0x301c, 0x00 },
{ 0x3023, 0x05 },
{ 0x3037, 0xf0 },
- { 0x3098, 0x04 }, /* pll2 pre divider */
- { 0x3099, 0x28 }, /* pll2 multiplier */
- { 0x309a, 0x05 }, /* pll2 sys divider */
- { 0x309b, 0x04 }, /* pll2 adc divider */
- { 0x309d, 0x00 }, /* pll2 divider */
- { 0x30b0, 0x0a }, /* pll1 pix divider */
- { 0x30b1, 0x01 }, /* pll1 divider */
- { 0x30b3, 0x64 }, /* pll1 multiplier */
- { 0x30b4, 0x03 }, /* pll1 pre divider */
- { 0x30b5, 0x05 }, /* pll1 mipi divider */
{ 0x3106, 0xda },
{ 0x3503, 0x07 },
{ 0x3509, 0x10 },
@@ -400,16 +448,6 @@ static const struct reg_value ov7251_setting_vga_90fps[] = {
{ 0x301c, 0x00 },
{ 0x3023, 0x05 },
{ 0x3037, 0xf0 },
- { 0x3098, 0x04 }, /* pll2 pre divider */
- { 0x3099, 0x28 }, /* pll2 multiplier */
- { 0x309a, 0x05 }, /* pll2 sys divider */
- { 0x309b, 0x04 }, /* pll2 adc divider */
- { 0x309d, 0x00 }, /* pll2 divider */
- { 0x30b0, 0x0a }, /* pll1 pix divider */
- { 0x30b1, 0x01 }, /* pll1 divider */
- { 0x30b3, 0x64 }, /* pll1 multiplier */
- { 0x30b4, 0x03 }, /* pll1 pre divider */
- { 0x30b5, 0x05 }, /* pll1 mipi divider */
{ 0x3106, 0xda },
{ 0x3503, 0x07 },
{ 0x3509, 0x10 },
@@ -525,6 +563,10 @@ static const struct reg_value ov7251_setting_vga_90fps[] = {
{ 0x5001, 0x80 },
};
+static const unsigned long supported_xclk_rates[] = {
+ [OV7251_24_MHZ] = 24000000,
+};
+
static const s64 link_freq[] = {
[OV7251_LINK_FREQ_240_MHZ] = 240000000,
};
@@ -696,6 +738,63 @@ static int ov7251_read_reg(struct ov7251 *ov7251, u16 reg, u8 *val)
return 0;
}
+static int ov7251_pll_configure(struct ov7251 *ov7251)
+{
+ const struct ov7251_pll_cfgs *configs;
+ int ret;
+
+ configs = ov7251->pll_cfgs;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL1_PRE_DIV_REG,
+ configs->pll1[ov7251->link_freq_idx]->pre_div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL1_MULT_REG,
+ configs->pll1[ov7251->link_freq_idx]->mult);
+ if (ret < 0)
+ return ret;
+ ret = ov7251_write_reg(ov7251, OV7251_PLL1_DIVIDER_REG,
+ configs->pll1[ov7251->link_freq_idx]->div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL1_PIX_DIV_REG,
+ configs->pll1[ov7251->link_freq_idx]->pix_div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL1_MIPI_DIV_REG,
+ configs->pll1[ov7251->link_freq_idx]->mipi_div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL2_PRE_DIV_REG,
+ configs->pll2->pre_div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL2_MULT_REG,
+ configs->pll2->mult);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL2_DIVIDER_REG,
+ configs->pll2->div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL2_SYS_DIV_REG,
+ configs->pll2->sys_div);
+ if (ret < 0)
+ return ret;
+
+ ret = ov7251_write_reg(ov7251, OV7251_PLL2_ADC_DIV_REG,
+ configs->pll2->adc_div);
+
+ return ret;
+}
+
static int ov7251_set_exposure(struct ov7251 *ov7251, s32 exposure)
{
u16 reg;
@@ -1137,6 +1236,11 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable)
mutex_lock(&ov7251->lock);
if (enable) {
+ ret = ov7251_pll_configure(ov7251);
+ if (ret)
+ return dev_err_probe(ov7251->dev, ret,
+ "error configuring PLLs\n");
+
ret = ov7251_set_register_array(ov7251,
ov7251->current_mode->data,
ov7251->current_mode->data_size);
@@ -1297,6 +1401,7 @@ static int ov7251_probe(struct i2c_client *client)
u8 chip_id_high, chip_id_low, chip_rev;
s64 pixel_rate;
int ret;
+ int i;
ov7251 = devm_kzalloc(dev, sizeof(struct ov7251), GFP_KERNEL);
if (!ov7251)
@@ -1335,6 +1440,16 @@ static int ov7251_probe(struct i2c_client *client)
dev_err(dev, "could not set xclk frequency\n");
return ret;
}
+ for (i = 0; i < ARRAY_SIZE(supported_xclk_rates); i++)
+ if (ov7251->xclk_freq == supported_xclk_rates[i])
+ break;
+
+ if (i == ARRAY_SIZE(supported_xclk_rates))
+ return dev_err_probe(dev, -EINVAL,
+ "clock rate %u Hz is unsupported\n",
+ ov7251->xclk_freq);
+
+ ov7251->pll_cfgs = ov7251_pll_cfgs[i];
ov7251->io_regulator = devm_regulator_get(dev, "vdddo");
if (IS_ERR(ov7251->io_regulator)) {
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3 06/15] media: i2c: Add ov7251_pll_configure()
@ 2022-05-05 12:29 kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2022-05-05 12:29 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 4550 bytes --]
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220504223027.3480287-7-djrscally@gmail.com>
References: <20220504223027.3480287-7-djrscally@gmail.com>
TO: Daniel Scally <djrscally@gmail.com>
TO: linux-media(a)vger.kernel.org
CC: yong.zhi(a)intel.com
CC: sakari.ailus(a)linux.intel.com
CC: bingbu.cao(a)intel.com
CC: tian.shu.qiu(a)intel.com
CC: andriy.shevchenko(a)linux.intel.com
CC: hverkuil-cisco(a)xs4all.nl
Hi Daniel,
I love your patch! Perhaps something to improve:
[auto build test WARNING on media-tree/master]
[also build test WARNING on v5.18-rc5 next-20220504]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Scally/Support-OVTI7251-on-Microsoft-Surface-line/20220505-063608
base: git://linuxtv.org/media_tree.git master
:::::: branch date: 14 hours ago
:::::: commit date: 14 hours ago
config: i386-randconfig-c001 (https://download.01.org/0day-ci/archive/20220505/202205052030.TLrDYuNF-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> drivers/media/i2c/ov7251.c:1241:3-9: preceding lock on line 1236
vim +1241 drivers/media/i2c/ov7251.c
d30bb512da3d8e Todor Tomov 2018-04-25 1230
d30bb512da3d8e Todor Tomov 2018-04-25 1231 static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable)
d30bb512da3d8e Todor Tomov 2018-04-25 1232 {
d30bb512da3d8e Todor Tomov 2018-04-25 1233 struct ov7251 *ov7251 = to_ov7251(subdev);
d30bb512da3d8e Todor Tomov 2018-04-25 1234 int ret;
d30bb512da3d8e Todor Tomov 2018-04-25 1235
d30bb512da3d8e Todor Tomov 2018-04-25 @1236 mutex_lock(&ov7251->lock);
d30bb512da3d8e Todor Tomov 2018-04-25 1237
d30bb512da3d8e Todor Tomov 2018-04-25 1238 if (enable) {
575c4ea63dc4cb Daniel Scally 2022-05-04 1239 ret = ov7251_pll_configure(ov7251);
575c4ea63dc4cb Daniel Scally 2022-05-04 1240 if (ret)
575c4ea63dc4cb Daniel Scally 2022-05-04 @1241 return dev_err_probe(ov7251->dev, ret,
575c4ea63dc4cb Daniel Scally 2022-05-04 1242 "error configuring PLLs\n");
575c4ea63dc4cb Daniel Scally 2022-05-04 1243
d30bb512da3d8e Todor Tomov 2018-04-25 1244 ret = ov7251_set_register_array(ov7251,
d30bb512da3d8e Todor Tomov 2018-04-25 1245 ov7251->current_mode->data,
d30bb512da3d8e Todor Tomov 2018-04-25 1246 ov7251->current_mode->data_size);
d30bb512da3d8e Todor Tomov 2018-04-25 1247 if (ret < 0) {
d30bb512da3d8e Todor Tomov 2018-04-25 1248 dev_err(ov7251->dev, "could not set mode %dx%d\n",
d30bb512da3d8e Todor Tomov 2018-04-25 1249 ov7251->current_mode->width,
d30bb512da3d8e Todor Tomov 2018-04-25 1250 ov7251->current_mode->height);
d30bb512da3d8e Todor Tomov 2018-04-25 1251 goto exit;
d30bb512da3d8e Todor Tomov 2018-04-25 1252 }
d30bb512da3d8e Todor Tomov 2018-04-25 1253 ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls);
d30bb512da3d8e Todor Tomov 2018-04-25 1254 if (ret < 0) {
d30bb512da3d8e Todor Tomov 2018-04-25 1255 dev_err(ov7251->dev, "could not sync v4l2 controls\n");
d30bb512da3d8e Todor Tomov 2018-04-25 1256 goto exit;
d30bb512da3d8e Todor Tomov 2018-04-25 1257 }
d30bb512da3d8e Todor Tomov 2018-04-25 1258 ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT,
d30bb512da3d8e Todor Tomov 2018-04-25 1259 OV7251_SC_MODE_SELECT_STREAMING);
d30bb512da3d8e Todor Tomov 2018-04-25 1260 } else {
d30bb512da3d8e Todor Tomov 2018-04-25 1261 ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT,
d30bb512da3d8e Todor Tomov 2018-04-25 1262 OV7251_SC_MODE_SELECT_SW_STANDBY);
d30bb512da3d8e Todor Tomov 2018-04-25 1263 }
d30bb512da3d8e Todor Tomov 2018-04-25 1264
d30bb512da3d8e Todor Tomov 2018-04-25 1265 exit:
d30bb512da3d8e Todor Tomov 2018-04-25 1266 mutex_unlock(&ov7251->lock);
d30bb512da3d8e Todor Tomov 2018-04-25 1267
d30bb512da3d8e Todor Tomov 2018-04-25 1268 return ret;
d30bb512da3d8e Todor Tomov 2018-04-25 1269 }
d30bb512da3d8e Todor Tomov 2018-04-25 1270
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-05 12:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-05 12:29 [PATCH v3 06/15] media: i2c: Add ov7251_pll_configure() kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2022-05-04 22:30 [PATCH v3 00/15] Support OVTI7251 on Microsoft Surface line Daniel Scally
2022-05-04 22:30 ` [PATCH v3 06/15] media: i2c: Add ov7251_pll_configure() Daniel Scally
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.