2020-03-12 21:13:17

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 0/3] ov5645: Switch to assigned-clock-rates

Hi All,

This patch series adds support for using assigned-clock-rates for
specifying clock rates for ov5645 driver

Thanks,
Prabhakar

Changes for V2:
* Instead of completely dropping clock-frequency property marked it as
deprecated.
* Split up imx6qdl-wandboard.dtsi changes as separate patch.


Lad Prabhakar (3):
media: dt-bindings: media: i2c: Switch to assigned-clock-rates
media: i2c: ov5645: Switch to assigned-clock-rates
ARM: dts: imx6qdl-wandboard: Switch to assigned-clock-rates for ov5645
node

.../devicetree/bindings/media/i2c/ov5645.txt | 5 +++--
arch/arm/boot/dts/imx6qdl-wandboard.dtsi | 3 ++-
drivers/media/i2c/ov5645.c | 24 +++++++++++++++-------
3 files changed, 22 insertions(+), 10 deletions(-)

--
2.7.4


2020-03-12 21:13:47

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 1/3] media: dt-bindings: media: i2c: Switch to assigned-clock-rates

Use assigned-clock-rates to specify the clock rate. Also mark
clock-frequency property as deprecated.

Signed-off-by: Lad Prabhakar <[email protected]>
---
Documentation/devicetree/bindings/media/i2c/ov5645.txt | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/i2c/ov5645.txt b/Documentation/devicetree/bindings/media/i2c/ov5645.txt
index 72ad992..e62fe82 100644
--- a/Documentation/devicetree/bindings/media/i2c/ov5645.txt
+++ b/Documentation/devicetree/bindings/media/i2c/ov5645.txt
@@ -8,7 +8,7 @@ Required Properties:
- compatible: Value should be "ovti,ov5645".
- clocks: Reference to the xclk clock.
- clock-names: Should be "xclk".
-- clock-frequency: Frequency of the xclk clock.
+- clock-frequency (deprecated): Frequency of the xclk clock.
- enable-gpios: Chip enable GPIO. Polarity is GPIO_ACTIVE_HIGH. This corresponds
to the hardware pin PWDNB which is physically active low.
- reset-gpios: Chip reset GPIO. Polarity is GPIO_ACTIVE_LOW. This corresponds to
@@ -37,7 +37,8 @@ Example:

clocks = <&clks 200>;
clock-names = "xclk";
- clock-frequency = <24000000>;
+ assigned-clocks = <&clks 200>;
+ assigned-clock-rates = <24000000>;

vdddo-supply = <&camera_dovdd_1v8>;
vdda-supply = <&camera_avdd_2v8>;
--
2.7.4

2020-03-12 21:14:03

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-rates

This patch switches to assigned-clock-rates for specifying the clock rate.
The clk-conf.c internally handles setting the clock rate when
assigned-clock-rates is passed.

The driver now sets the clock frequency only if the deprecated property
clock-frequency is defined instead assigned-clock-rates, this is to avoid
breakage with existing DT binaries.

Signed-off-by: Lad Prabhakar <[email protected]>
---
drivers/media/i2c/ov5645.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index a6c17d1..6cd16c5 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -1055,6 +1055,7 @@ static int ov5645_probe(struct i2c_client *client)
struct device_node *endpoint;
struct ov5645 *ov5645;
u8 chip_id_high, chip_id_low;
+ bool set_clk = false;
unsigned int i;
u32 xclk_freq;
int ret;
@@ -1094,10 +1095,17 @@ static int ov5645_probe(struct i2c_client *client)
return PTR_ERR(ov5645->xclk);
}

- ret = of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
+ ret = of_property_read_u32(dev->of_node, "assigned-clock-rates",
+ &xclk_freq);
if (ret) {
- dev_err(dev, "could not get xclk frequency\n");
- return ret;
+ /* check if deprecated property clock-frequency is defined */
+ ret = of_property_read_u32(dev->of_node, "clock-frequency",
+ &xclk_freq);
+ if (ret) {
+ dev_err(dev, "could not get xclk frequency\n");
+ return ret;
+ }
+ set_clk = true;
}

/* external clock must be 24MHz, allow 1% tolerance */
@@ -1107,10 +1115,12 @@ static int ov5645_probe(struct i2c_client *client)
return -EINVAL;
}

- ret = clk_set_rate(ov5645->xclk, xclk_freq);
- if (ret) {
- dev_err(dev, "could not set xclk frequency\n");
- return ret;
+ if (set_clk) {
+ ret = clk_set_rate(ov5645->xclk, xclk_freq);
+ if (ret) {
+ dev_err(dev, "could not set xclk frequency\n");
+ return ret;
+ }
}

for (i = 0; i < OV5645_NUM_SUPPLIES; i++)
--
2.7.4

2020-03-12 21:15:25

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 3/3] ARM: dts: imx6qdl-wandboard: Switch to assigned-clock-rates for ov5645 node

clock-frequency property is now marked as deprecated in ov5645 binding,
so switch to assigned-clock-rates for specifying xclk clock frequency.

Signed-off-by: Lad Prabhakar <[email protected]>
---
arch/arm/boot/dts/imx6qdl-wandboard.dtsi | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6qdl-wandboard.dtsi b/arch/arm/boot/dts/imx6qdl-wandboard.dtsi
index c070893..71f5f75 100644
--- a/arch/arm/boot/dts/imx6qdl-wandboard.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-wandboard.dtsi
@@ -126,7 +126,8 @@
reg = <0x3c>;
clocks = <&clks IMX6QDL_CLK_CKO2>;
clock-names = "xclk";
- clock-frequency = <24000000>;
+ assigned-clocks = <&clks IMX6QDL_CLK_CKO2>;
+ assigned-clock-rates = <24000000>;
vdddo-supply = <&reg_1p8v>;
vdda-supply = <&reg_2p8v>;
vddd-supply = <&reg_1p5v>;
--
2.7.4

2020-03-12 21:42:42

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-rates

Hi Prabhakar,

On Thu, Mar 12, 2020 at 10:13 PM Lad Prabhakar
<[email protected]> wrote:
> This patch switches to assigned-clock-rates for specifying the clock rate.
> The clk-conf.c internally handles setting the clock rate when
> assigned-clock-rates is passed.
>
> The driver now sets the clock frequency only if the deprecated property
> clock-frequency is defined instead assigned-clock-rates, this is to avoid
> breakage with existing DT binaries.
>
> Signed-off-by: Lad Prabhakar <[email protected]>

Thanks for your patch!

> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -1055,6 +1055,7 @@ static int ov5645_probe(struct i2c_client *client)
> struct device_node *endpoint;
> struct ov5645 *ov5645;
> u8 chip_id_high, chip_id_low;
> + bool set_clk = false;
> unsigned int i;
> u32 xclk_freq;
> int ret;
> @@ -1094,10 +1095,17 @@ static int ov5645_probe(struct i2c_client *client)
> return PTR_ERR(ov5645->xclk);
> }
>
> - ret = of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
> + ret = of_property_read_u32(dev->of_node, "assigned-clock-rates",
> + &xclk_freq);
> if (ret) {

I think you can just leave out the above check...

> - dev_err(dev, "could not get xclk frequency\n");
> - return ret;
> + /* check if deprecated property clock-frequency is defined */
> + ret = of_property_read_u32(dev->of_node, "clock-frequency",
> + &xclk_freq);
> + if (ret) {

... and ignore the absence of the deprecated property.

> + dev_err(dev, "could not get xclk frequency\n");
> + return ret;
> + }
> + set_clk = true;

I.e. just

/* check if deprecated property clock-frequency is defined */
xclk_freq = 0;
of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
if (xclk_freq) {
ret = clk_set_rate(ov5645->xclk, xclk_freq);
if (ret) {
dev_err(dev, "could not set xclk frequency\n");
return ret;
}
} else {
xclk_freq = clk_get_rate(ov5645->xclk, xclk_freq);
}

> }
>
> /* external clock must be 24MHz, allow 1% tolerance */
> @@ -1107,10 +1115,12 @@ static int ov5645_probe(struct i2c_client *client)
> return -EINVAL;
> }
>
> - ret = clk_set_rate(ov5645->xclk, xclk_freq);
> - if (ret) {
> - dev_err(dev, "could not set xclk frequency\n");
> - return ret;
> + if (set_clk) {
> + ret = clk_set_rate(ov5645->xclk, xclk_freq);
> + if (ret) {
> + dev_err(dev, "could not set xclk frequency\n");
> + return ret;
> + }

> }
>
> for (i = 0; i < OV5645_NUM_SUPPLIES; i++)
> --
> 2.7.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel



--
Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2020-03-12 21:53:28

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: RE: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-rates

Hi Geert,

Thank you for the quick review.

> -----Original Message-----
> From: Geert Uytterhoeven <[email protected]>
> Sent: 12 March 2020 21:42
> To: Prabhakar Mahadev Lad <[email protected]>
> Cc: Mauro Carvalho Chehab <[email protected]>; Shawn Guo
> <[email protected]>; Sascha Hauer <[email protected]>;
> Pengutronix Kernel Team <[email protected]>; Rob Herring
> <[email protected]>; Mark Rutland <[email protected]>; Sakari
> Ailus <[email protected]>; NXP Linux Team <[email protected]>;
> Magnus Damm <[email protected]>; Ezequiel Garcia
> <[email protected]>; open list:OPEN FIRMWARE AND FLATTENED
> DEVICE TREE BINDINGS <[email protected]>; Linux Kernel Mailing
> List <[email protected]>; Linux-Renesas <linux-renesas-
> [email protected]>; Fabio Estevam <[email protected]>; Linux ARM
> <[email protected]>; Linux Media Mailing List <linux-
> [email protected]>
> Subject: Re: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-
> rates
>
> Hi Prabhakar,
>
> On Thu, Mar 12, 2020 at 10:13 PM Lad Prabhakar <prabhakar.mahadev-
> [email protected]> wrote:
> > This patch switches to assigned-clock-rates for specifying the clock rate.
> > The clk-conf.c internally handles setting the clock rate when
> > assigned-clock-rates is passed.
> >
> > The driver now sets the clock frequency only if the deprecated
> > property clock-frequency is defined instead assigned-clock-rates, this
> > is to avoid breakage with existing DT binaries.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-
> [email protected]>
>
> Thanks for your patch!
>
> > --- a/drivers/media/i2c/ov5645.c
> > +++ b/drivers/media/i2c/ov5645.c
> > @@ -1055,6 +1055,7 @@ static int ov5645_probe(struct i2c_client *client)
> > struct device_node *endpoint;
> > struct ov5645 *ov5645;
> > u8 chip_id_high, chip_id_low;
> > + bool set_clk = false;
> > unsigned int i;
> > u32 xclk_freq;
> > int ret;
> > @@ -1094,10 +1095,17 @@ static int ov5645_probe(struct i2c_client
> *client)
> > return PTR_ERR(ov5645->xclk);
> > }
> >
> > - ret = of_property_read_u32(dev->of_node, "clock-frequency",
> &xclk_freq);
> > + ret = of_property_read_u32(dev->of_node, "assigned-clock-rates",
> > + &xclk_freq);
> > if (ret) {
>
> I think you can just leave out the above check...
>
> > - dev_err(dev, "could not get xclk frequency\n");
> > - return ret;
> > + /* check if deprecated property clock-frequency is defined */
> > + ret = of_property_read_u32(dev->of_node, "clock-frequency",
> > + &xclk_freq);
> > + if (ret) {
>
> ... and ignore the absence of the deprecated property.
>
> > + dev_err(dev, "could not get xclk frequency\n");
> > + return ret;
> > + }
> > + set_clk = true;
>
> I.e. just
>
> /* check if deprecated property clock-frequency is defined */
> xclk_freq = 0;
> of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
> if (xclk_freq) {
> ret = clk_set_rate(ov5645->xclk, xclk_freq);
> if (ret) {
> dev_err(dev, "could not set xclk frequency\n");
> return ret;
> }
> } else {
> xclk_freq = clk_get_rate(ov5645->xclk, xclk_freq);
> }
>
I did think about it initially, but realized the clk_get_rate may vary platform to platform
for example in G2E clk_get_rate() returns a frequency of 24242424 with
assigned-clock-rates set to 24000000 and probe would fail due to a check for
external clock must be 24MHz, with 1% tolerance.

Cheers,
--Prabhakar

> > }
> >
> > /* external clock must be 24MHz, allow 1% tolerance */ @@
> > -1107,10 +1115,12 @@ static int ov5645_probe(struct i2c_client *client)
> > return -EINVAL;
> > }
> >
> > - ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > - if (ret) {
> > - dev_err(dev, "could not set xclk frequency\n");
> > - return ret;
> > + if (set_clk) {
> > + ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > + if (ret) {
> > + dev_err(dev, "could not set xclk frequency\n");
> > + return ret;
> > + }
>
> > }
> >
> > for (i = 0; i < OV5645_NUM_SUPPLIES; i++)
> > --
> > 2.7.4
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > [email protected]
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
>
>
> --
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-
> m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds


Renesas Electronics Europe GmbH, Geschaeftsfuehrer/President: Carsten Jauch, Sitz der Gesellschaft/Registered office: Duesseldorf, Arcadiastrasse 10, 40472 Duesseldorf, Germany, Handelsregister/Commercial Register: Duesseldorf, HRB 3708 USt-IDNr./Tax identification no.: DE 119353406 WEEE-Reg.-Nr./WEEE reg. no.: DE 14978647

2020-03-12 23:02:33

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-rates

Hi Prabakhar,

Thank you for the patch.

On Thu, Mar 12, 2020 at 09:12:31PM +0000, Lad Prabhakar wrote:
> This patch switches to assigned-clock-rates for specifying the clock rate.
> The clk-conf.c internally handles setting the clock rate when
> assigned-clock-rates is passed.
>
> The driver now sets the clock frequency only if the deprecated property
> clock-frequency is defined instead assigned-clock-rates, this is to avoid
> breakage with existing DT binaries.
>
> Signed-off-by: Lad Prabhakar <[email protected]>
> ---
> drivers/media/i2c/ov5645.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index a6c17d1..6cd16c5 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -1055,6 +1055,7 @@ static int ov5645_probe(struct i2c_client *client)
> struct device_node *endpoint;
> struct ov5645 *ov5645;
> u8 chip_id_high, chip_id_low;
> + bool set_clk = false;
> unsigned int i;
> u32 xclk_freq;
> int ret;
> @@ -1094,10 +1095,17 @@ static int ov5645_probe(struct i2c_client *client)
> return PTR_ERR(ov5645->xclk);
> }
>
> - ret = of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
> + ret = of_property_read_u32(dev->of_node, "assigned-clock-rates",
> + &xclk_freq);

You shouldn't read the assigned-clock-rates property, you should instead
get the rate from the clock with clk_get_rate().

> if (ret) {
> - dev_err(dev, "could not get xclk frequency\n");
> - return ret;
> + /* check if deprecated property clock-frequency is defined */
> + ret = of_property_read_u32(dev->of_node, "clock-frequency",
> + &xclk_freq);
> + if (ret) {
> + dev_err(dev, "could not get xclk frequency\n");
> + return ret;
> + }
> + set_clk = true;
> }
>
> /* external clock must be 24MHz, allow 1% tolerance */
> @@ -1107,10 +1115,12 @@ static int ov5645_probe(struct i2c_client *client)
> return -EINVAL;
> }
>
> - ret = clk_set_rate(ov5645->xclk, xclk_freq);
> - if (ret) {
> - dev_err(dev, "could not set xclk frequency\n");
> - return ret;
> + if (set_clk) {
> + ret = clk_set_rate(ov5645->xclk, xclk_freq);
> + if (ret) {
> + dev_err(dev, "could not set xclk frequency\n");
> + return ret;
> + }
> }
>
> for (i = 0; i < OV5645_NUM_SUPPLIES; i++)

--
Regards,

Laurent Pinchart

2020-03-12 23:04:38

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-rates

Hi Prabhakar,

On Thu, Mar 12, 2020 at 09:52:38PM +0000, Prabhakar Mahadev Lad wrote:
> On 12 March 2020 21:42, Geert Uytterhoeven wrote:
> > On Thu, Mar 12, 2020 at 10:13 PM Lad Prabhakar wrote:
> > > This patch switches to assigned-clock-rates for specifying the clock rate.
> > > The clk-conf.c internally handles setting the clock rate when
> > > assigned-clock-rates is passed.
> > >
> > > The driver now sets the clock frequency only if the deprecated
> > > property clock-frequency is defined instead assigned-clock-rates, this
> > > is to avoid breakage with existing DT binaries.
> > >
> > > Signed-off-by: Lad Prabhakar <[email protected]>
> >
> > Thanks for your patch!
> >
> > > --- a/drivers/media/i2c/ov5645.c
> > > +++ b/drivers/media/i2c/ov5645.c
> > > @@ -1055,6 +1055,7 @@ static int ov5645_probe(struct i2c_client *client)
> > > struct device_node *endpoint;
> > > struct ov5645 *ov5645;
> > > u8 chip_id_high, chip_id_low;
> > > + bool set_clk = false;
> > > unsigned int i;
> > > u32 xclk_freq;
> > > int ret;
> > > @@ -1094,10 +1095,17 @@ static int ov5645_probe(struct i2c_client
> > *client)
> > > return PTR_ERR(ov5645->xclk);
> > > }
> > >
> > > - ret = of_property_read_u32(dev->of_node, "clock-frequency",
> > &xclk_freq);
> > > + ret = of_property_read_u32(dev->of_node, "assigned-clock-rates",
> > > + &xclk_freq);
> > > if (ret) {
> >
> > I think you can just leave out the above check...
> >
> > > - dev_err(dev, "could not get xclk frequency\n");
> > > - return ret;
> > > + /* check if deprecated property clock-frequency is defined */
> > > + ret = of_property_read_u32(dev->of_node, "clock-frequency",
> > > + &xclk_freq);
> > > + if (ret) {
> >
> > ... and ignore the absence of the deprecated property.
> >
> > > + dev_err(dev, "could not get xclk frequency\n");
> > > + return ret;
> > > + }
> > > + set_clk = true;
> >
> > I.e. just
> >
> > /* check if deprecated property clock-frequency is defined */
> > xclk_freq = 0;
> > of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
> > if (xclk_freq) {
> > ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > if (ret) {
> > dev_err(dev, "could not set xclk frequency\n");
> > return ret;
> > }
> > } else {
> > xclk_freq = clk_get_rate(ov5645->xclk, xclk_freq);
> > }
> >
> I did think about it initially, but realized the clk_get_rate may vary platform to platform
> for example in G2E clk_get_rate() returns a frequency of 24242424 with
> assigned-clock-rates set to 24000000 and probe would fail due to a check for
> external clock must be 24MHz, with 1% tolerance.

Then you need to handle the tolerance in this driver :-)

> > > }
> > >
> > > /* external clock must be 24MHz, allow 1% tolerance */ @@
> > > -1107,10 +1115,12 @@ static int ov5645_probe(struct i2c_client *client)
> > > return -EINVAL;
> > > }
> > >
> > > - ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > > - if (ret) {
> > > - dev_err(dev, "could not set xclk frequency\n");
> > > - return ret;
> > > + if (set_clk) {
> > > + ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > > + if (ret) {
> > > + dev_err(dev, "could not set xclk frequency\n");
> > > + return ret;
> > > + }
> > >
> > > }
> > >
> > > for (i = 0; i < OV5645_NUM_SUPPLIES; i++)

--
Regards,

Laurent Pinchart

2020-03-13 08:02:49

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: RE: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-rates

Hi Laurent,

Thank you for the review.

> -----Original Message-----
> From: Laurent Pinchart <[email protected]>
> Sent: 12 March 2020 23:03
> To: Prabhakar Mahadev Lad <[email protected]>
> Cc: Geert Uytterhoeven <[email protected]>; Mauro Carvalho Chehab
> <[email protected]>; Shawn Guo <[email protected]>; Sascha
> Hauer <[email protected]>; Pengutronix Kernel Team
> <[email protected]>; Rob Herring <[email protected]>; Mark
> Rutland <[email protected]>; Sakari Ailus
> <[email protected]>; NXP Linux Team <[email protected]>;
> Magnus Damm <[email protected]>; Ezequiel Garcia
> <[email protected]>; open list:OPEN FIRMWARE AND FLATTENED
> DEVICE TREE BINDINGS <[email protected]>; Linux Kernel Mailing
> List <[email protected]>; Linux-Renesas <linux-renesas-
> [email protected]>; Fabio Estevam <[email protected]>; Linux ARM
> <[email protected]>; Linux Media Mailing List <linux-
> [email protected]>
> Subject: Re: [PATCH v2 2/3] media: i2c: ov5645: Switch to assigned-clock-
> rates
>
> Hi Prabhakar,
>
> On Thu, Mar 12, 2020 at 09:52:38PM +0000, Prabhakar Mahadev Lad wrote:
> > On 12 March 2020 21:42, Geert Uytterhoeven wrote:
> > > On Thu, Mar 12, 2020 at 10:13 PM Lad Prabhakar wrote:
> > > > This patch switches to assigned-clock-rates for specifying the clock rate.
> > > > The clk-conf.c internally handles setting the clock rate when
> > > > assigned-clock-rates is passed.
> > > >
> > > > The driver now sets the clock frequency only if the deprecated
> > > > property clock-frequency is defined instead assigned-clock-rates,
> > > > this is to avoid breakage with existing DT binaries.
> > > >
> > > > Signed-off-by: Lad Prabhakar
> > > > <[email protected]>
> > >
> > > Thanks for your patch!
> > >
> > > > --- a/drivers/media/i2c/ov5645.c
> > > > +++ b/drivers/media/i2c/ov5645.c
> > > > @@ -1055,6 +1055,7 @@ static int ov5645_probe(struct i2c_client
> *client)
> > > > struct device_node *endpoint;
> > > > struct ov5645 *ov5645;
> > > > u8 chip_id_high, chip_id_low;
> > > > + bool set_clk = false;
> > > > unsigned int i;
> > > > u32 xclk_freq;
> > > > int ret;
> > > > @@ -1094,10 +1095,17 @@ static int ov5645_probe(struct i2c_client
> > > *client)
> > > > return PTR_ERR(ov5645->xclk);
> > > > }
> > > >
> > > > - ret = of_property_read_u32(dev->of_node, "clock-frequency",
> > > &xclk_freq);
> > > > + ret = of_property_read_u32(dev->of_node, "assigned-clock-
> rates",
> > > > + &xclk_freq);
> > > > if (ret) {
> > >
> > > I think you can just leave out the above check...
> > >
> > > > - dev_err(dev, "could not get xclk frequency\n");
> > > > - return ret;
> > > > + /* check if deprecated property clock-frequency is defined */
> > > > + ret = of_property_read_u32(dev->of_node, "clock-
> frequency",
> > > > + &xclk_freq);
> > > > + if (ret) {
> > >
> > > ... and ignore the absence of the deprecated property.
> > >
> > > > + dev_err(dev, "could not get xclk frequency\n");
> > > > + return ret;
> > > > + }
> > > > + set_clk = true;
> > >
> > > I.e. just
> > >
> > > /* check if deprecated property clock-frequency is defined */
> > > xclk_freq = 0;
> > > of_property_read_u32(dev->of_node, "clock-frequency",
> &xclk_freq);
> > > if (xclk_freq) {
> > > ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > > if (ret) {
> > > dev_err(dev, "could not set xclk frequency\n");
> > > return ret;
> > > }
> > > } else {
> > > xclk_freq = clk_get_rate(ov5645->xclk, xclk_freq);
> > > }
> > >
> > I did think about it initially, but realized the clk_get_rate may vary
> > platform to platform for example in G2E clk_get_rate() returns a
> > frequency of 24242424 with assigned-clock-rates set to 24000000 and
> > probe would fail due to a check for external clock must be 24MHz, with 1%
> tolerance.
>
> Then you need to handle the tolerance in this driver :-)
>
Sure I will increase the tolerance here.

Cheers,
--Prabhakar

> > > > }
> > > >
> > > > /* external clock must be 24MHz, allow 1% tolerance */ @@
> > > > -1107,10 +1115,12 @@ static int ov5645_probe(struct i2c_client *client)
> > > > return -EINVAL;
> > > > }
> > > >
> > > > - ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > > > - if (ret) {
> > > > - dev_err(dev, "could not set xclk frequency\n");
> > > > - return ret;
> > > > + if (set_clk) {
> > > > + ret = clk_set_rate(ov5645->xclk, xclk_freq);
> > > > + if (ret) {
> > > > + dev_err(dev, "could not set xclk frequency\n");
> > > > + return ret;
> > > > + }
> > > >
> > > > }
> > > >
> > > > for (i = 0; i < OV5645_NUM_SUPPLIES; i++)
>
> --
> Regards,
>
> Laurent Pinchart


Renesas Electronics Europe GmbH, Geschaeftsfuehrer/President: Carsten Jauch, Sitz der Gesellschaft/Registered office: Duesseldorf, Arcadiastrasse 10, 40472 Duesseldorf, Germany, Handelsregister/Commercial Register: Duesseldorf, HRB 3708 USt-IDNr./Tax identification no.: DE 119353406 WEEE-Reg.-Nr./WEEE reg. no.: DE 14978647