Message ID | 1586191361-16598-3-git-send-email-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ov5645: Deprecate usage of the clock-frequency | expand |
Hi Prabhakar, On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > 24MHz. So instead making clock-frequency as dt-property just let the > driver enforce the required clock frequency. Even if some current systems where the driver is used are using 24 MHz clock, that doesn't mean there wouldn't be systems using another frequency that the driver does not support right now. The driver really should not set the frequency unless it gets it from DT, but I think the preferred means is to use assigned-clock-rates instead, and not to involve the driver with setting the frequency. Otherwise we'll make it impossible to support other frequencies, at least without more or less random defaults.
Hi Sakari, On Mon, Apr 6, 2020 at 5:51 PM Sakari Ailus <sakari.ailus@linux.intel.com> wrote: > > Hi Prabhakar, > > On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > 24MHz. So instead making clock-frequency as dt-property just let the > > driver enforce the required clock frequency. > > Even if some current systems where the driver is used are using 24 MHz > clock, that doesn't mean there wouldn't be systems using another frequency > that the driver does not support right now. > > The driver really should not set the frequency unless it gets it from DT, > but I think the preferred means is to use assigned-clock-rates instead, and > not to involve the driver with setting the frequency. > > Otherwise we'll make it impossible to support other frequencies, at least > without more or less random defaults. > Ouch! my previous version of patches switched the driver for using assigned-clock-rates but I was asked to not do so [1]. [1] https://patchwork.linuxtv.org/patch/62185/ Cheers, --Prabhakar > -- > Kind regards, > > Sakari Ailus
Hi Sakari, (CC'ing Maxime) On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > 24MHz. So instead making clock-frequency as dt-property just let the > > driver enforce the required clock frequency. > > Even if some current systems where the driver is used are using 24 MHz > clock, that doesn't mean there wouldn't be systems using another frequency > that the driver does not support right now. > > The driver really should not set the frequency unless it gets it from DT, > but I think the preferred means is to use assigned-clock-rates instead, and > not to involve the driver with setting the frequency. > > Otherwise we'll make it impossible to support other frequencies, at least > without more or less random defaults. We're running in circles here. As the driver only supports 24MHz at the moment, the frequency should be set by the driver, as it's a driver limitation. We can then work on supporting additional frequencies, which will require DT to provide a list of supported frequencies for the system, but that can be done on top.
Hi Prabhakar, Thank you for the patch. On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > 24MHz. So instead making clock-frequency as dt-property just let the > driver enforce the required clock frequency. > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > --- > drivers/media/i2c/ov5645.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c > index a6c17d15d754..52848fff8a08 100644 > --- a/drivers/media/i2c/ov5645.c > +++ b/drivers/media/i2c/ov5645.c > @@ -61,6 +61,8 @@ > #define OV5645_SDE_SAT_U 0x5583 > #define OV5645_SDE_SAT_V 0x5584 > > +#define OV5645_XVCLK_FREQ 24000000 > + > /* regulator supplies */ > static const char * const ov5645_supply_name[] = { > "vdddo", /* Digital I/O (1.8V) supply */ > @@ -1094,25 +1096,19 @@ 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 = clk_set_rate(ov5645->xclk, OV5645_XVCLK_FREQ); > if (ret) { > - dev_err(dev, "could not get xclk frequency\n"); > + dev_err(dev, "could not set xclk frequency\n"); > return ret; > } > - I think you can keep the blank line here. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > /* external clock must be 24MHz, allow 1% tolerance */ > + xclk_freq = clk_get_rate(ov5645->xclk); > if (xclk_freq < 23760000 || xclk_freq > 24240000) { > dev_err(dev, "external clock frequency %u is not supported\n", > xclk_freq); > return -EINVAL; > } > > - 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++) > ov5645->supplies[i].supply = ov5645_supply_name[i]; >
Hi Laurent, On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > Hi Sakari, > > (CC'ing Maxime) > > On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > > On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > > 24MHz. So instead making clock-frequency as dt-property just let the > > > driver enforce the required clock frequency. > > > > Even if some current systems where the driver is used are using 24 MHz > > clock, that doesn't mean there wouldn't be systems using another frequency > > that the driver does not support right now. > > > > The driver really should not set the frequency unless it gets it from DT, > > but I think the preferred means is to use assigned-clock-rates instead, and > > not to involve the driver with setting the frequency. > > > > Otherwise we'll make it impossible to support other frequencies, at least > > without more or less random defaults. > > We're running in circles here. > > As the driver only supports 24MHz at the moment, the frequency should be > set by the driver, as it's a driver limitation. We can then work on > supporting additional frequencies, which will require DT to provide a > list of supported frequencies for the system, but that can be done on > top. I guess it would be possible to use different external clock frequencies on a sensor in a given system but that seems to be a bit far fetched, to the extent I've never seen anyone doing that in practice. Originally, the driver set the frequency based on the clock-frequency property. If we're removing that but use a fixed frequency instead, then how is that going to work going forward when someone adds support for other frequencies in the driver and has a system requiring that, while there are some other platforms relying on the driver setting a particular frequency? Although, if you're saying that this driver only needs to work with DT that comes with the kernel and you don't care about DT binary compatibility, this would be fine.
Hi Prabhakar, On Mon, Apr 6, 2020 at 6:43 PM Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote: > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > 24MHz. So instead making clock-frequency as dt-property just let the > driver enforce the required clock frequency. > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> However, still wondering about the "xvclk" name above and in the definition below. Is this the naming from the datasheet? The DT bindings nor the driver use the "xvclk" naming. > --- a/drivers/media/i2c/ov5645.c > +++ b/drivers/media/i2c/ov5645.c > @@ -61,6 +61,8 @@ > #define OV5645_SDE_SAT_U 0x5583 > #define OV5645_SDE_SAT_V 0x5584 > > +#define OV5645_XVCLK_FREQ 24000000 > + Gr{oetje,eeting}s, Geert
Hi Laurent, Thank you for the review. On Mon, Apr 6, 2020 at 6:34 PM Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote: > > Hi Prabhakar, > > Thank you for the patch. > > On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > 24MHz. So instead making clock-frequency as dt-property just let the > > driver enforce the required clock frequency. > > > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > --- > > drivers/media/i2c/ov5645.c | 14 +++++--------- > > 1 file changed, 5 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c > > index a6c17d15d754..52848fff8a08 100644 > > --- a/drivers/media/i2c/ov5645.c > > +++ b/drivers/media/i2c/ov5645.c > > @@ -61,6 +61,8 @@ > > #define OV5645_SDE_SAT_U 0x5583 > > #define OV5645_SDE_SAT_V 0x5584 > > > > +#define OV5645_XVCLK_FREQ 24000000 > > + > > /* regulator supplies */ > > static const char * const ov5645_supply_name[] = { > > "vdddo", /* Digital I/O (1.8V) supply */ > > @@ -1094,25 +1096,19 @@ 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 = clk_set_rate(ov5645->xclk, OV5645_XVCLK_FREQ); > > if (ret) { > > - dev_err(dev, "could not get xclk frequency\n"); > > + dev_err(dev, "could not set xclk frequency\n"); > > return ret; > > } > > - > > I think you can keep the blank line here. > Oops my bad will drop that in next version. Cheers, --Prabhakar > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > /* external clock must be 24MHz, allow 1% tolerance */ > > + xclk_freq = clk_get_rate(ov5645->xclk); > > if (xclk_freq < 23760000 || xclk_freq > 24240000) { > > dev_err(dev, "external clock frequency %u is not supported\n", > > xclk_freq); > > return -EINVAL; > > } > > > > - 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++) > > ov5645->supplies[i].supply = ov5645_supply_name[i]; > > > > -- > Regards, > > Laurent Pinchart
Hi Geert, Thank you for the review. On Tue, Apr 7, 2020 at 8:17 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > Hi Prabhakar, > > On Mon, Apr 6, 2020 at 6:43 PM Lad Prabhakar > <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote: > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > 24MHz. So instead making clock-frequency as dt-property just let the > > driver enforce the required clock frequency. > > > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> > > However, still wondering about the "xvclk" name above and in the definition > below. Is this the naming from the datasheet? > The DT bindings nor the driver use the "xvclk" naming. > xvclk naming is from the datasheet, although the 0v5645 datasheet on publicly available I have referred [1]/[2]. If I am not wrong all the ov sensors have the same naming convention as xvclk. [1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf [2] https://www.ovt.com/download/sensorpdf/126/OmniVision_OV5645.pdf Cheers, --Prabhakar > > --- a/drivers/media/i2c/ov5645.c > > +++ b/drivers/media/i2c/ov5645.c > > @@ -61,6 +61,8 @@ > > #define OV5645_SDE_SAT_U 0x5583 > > #define OV5645_SDE_SAT_V 0x5584 > > > > +#define OV5645_XVCLK_FREQ 24000000 > > + > > 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
Hi Prabhakar, On Tue, Apr 07, 2020 at 08:40:06AM +0100, Lad, Prabhakar wrote: > On Tue, Apr 7, 2020 at 8:17 AM Geert Uytterhoeven wrote: > > On Mon, Apr 6, 2020 at 6:43 PM Lad Prabhakar wrote: > > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > > 24MHz. So instead making clock-frequency as dt-property just let the > > > driver enforce the required clock frequency. > > > > > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> > > > > However, still wondering about the "xvclk" name above and in the definition > > below. Is this the naming from the datasheet? > > The DT bindings nor the driver use the "xvclk" naming. > > > xvclk naming is from the datasheet, although the 0v5645 datasheet on > publicly available I have referred [1]/[2]. > If I am not wrong all the ov sensors have the same naming convention as xvclk. > > [1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf > [2] https://www.ovt.com/download/sensorpdf/126/OmniVision_OV5645.pdf The clock in DT should really have been named xvclk, but it's too late to change that. We can follow one of two approaches, either naming everything xclk, and naming everything but the DT property xvclk. Both have pros and cons, feel free to pick your preferred option, but in any case a comment to explain the issue would be useful. > > > --- a/drivers/media/i2c/ov5645.c > > > +++ b/drivers/media/i2c/ov5645.c > > > @@ -61,6 +61,8 @@ > > > #define OV5645_SDE_SAT_U 0x5583 > > > #define OV5645_SDE_SAT_V 0x5584 > > > > > > +#define OV5645_XVCLK_FREQ 24000000 > > > +
Hi Sakari, On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > > On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > > > On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > > > 24MHz. So instead making clock-frequency as dt-property just let the > > > > driver enforce the required clock frequency. > > > > > > Even if some current systems where the driver is used are using 24 MHz > > > clock, that doesn't mean there wouldn't be systems using another frequency > > > that the driver does not support right now. > > > > > > The driver really should not set the frequency unless it gets it from DT, > > > but I think the preferred means is to use assigned-clock-rates instead, and > > > not to involve the driver with setting the frequency. > > > > > > Otherwise we'll make it impossible to support other frequencies, at least > > > without more or less random defaults. > > > > We're running in circles here. > > > > As the driver only supports 24MHz at the moment, the frequency should be > > set by the driver, as it's a driver limitation. We can then work on > > supporting additional frequencies, which will require DT to provide a > > list of supported frequencies for the system, but that can be done on > > top. > > I guess it would be possible to use different external clock frequencies on > a sensor in a given system but that seems to be a bit far fetched, to the > extent I've never seen anyone doing that in practice. > > Originally, the driver set the frequency based on the clock-frequency > property. If we're removing that but use a fixed frequency instead, then > how is that going to work going forward when someone adds support for other > frequencies in the driver and has a system requiring that, while there are > some other platforms relying on the driver setting a particular frequency? The standard property for this is link-frequencies, not clock-frequency. Deprecating clock-frequency now paves the way to use the standard property later when/if someone implements support for additional frequencies. > Although, if you're saying that this driver only needs to work with DT that > comes with the kernel and you don't care about DT binary compatibility, > this would be fine. I believe this series to not break backward compatibility, as the driver only works with a 24MHz clock, so I expect all DTs to specify that.
Hi Laurent, On Tue, Apr 07, 2020 at 03:21:06PM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > > On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > > > On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > > > > On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > > > > Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > > > > as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > > > > 24MHz. So instead making clock-frequency as dt-property just let the > > > > > driver enforce the required clock frequency. > > > > > > > > Even if some current systems where the driver is used are using 24 MHz > > > > clock, that doesn't mean there wouldn't be systems using another frequency > > > > that the driver does not support right now. > > > > > > > > The driver really should not set the frequency unless it gets it from DT, > > > > but I think the preferred means is to use assigned-clock-rates instead, and > > > > not to involve the driver with setting the frequency. > > > > > > > > Otherwise we'll make it impossible to support other frequencies, at least > > > > without more or less random defaults. > > > > > > We're running in circles here. > > > > > > As the driver only supports 24MHz at the moment, the frequency should be > > > set by the driver, as it's a driver limitation. We can then work on > > > supporting additional frequencies, which will require DT to provide a > > > list of supported frequencies for the system, but that can be done on > > > top. > > > > I guess it would be possible to use different external clock frequencies on > > a sensor in a given system but that seems to be a bit far fetched, to the > > extent I've never seen anyone doing that in practice. > > > > Originally, the driver set the frequency based on the clock-frequency > > property. If we're removing that but use a fixed frequency instead, then > > how is that going to work going forward when someone adds support for other > > frequencies in the driver and has a system requiring that, while there are > > some other platforms relying on the driver setting a particular frequency? > > The standard property for this is link-frequencies, not clock-frequency. > Deprecating clock-frequency now paves the way to use the standard > property later when/if someone implements support for additional > frequencies. The external clock frequency and link frequency are different indeed, but they are related. The link frequency has been selected in a way that it is possible to generate that exact frequency using the chosen external clock frequency. If you change the external clock frequency, chances are good there is no PLL configuration to generate that link frequency. > > > Although, if you're saying that this driver only needs to work with DT that > > comes with the kernel and you don't care about DT binary compatibility, > > this would be fine. > > I believe this series to not break backward compatibility, as the driver > only works with a 24MHz clock, so I expect all DTs to specify that. What you're still doing here is defining the DT bindings based on the current driver implementation, not the device properties.
Hi Sakari, On Tue, Apr 07, 2020 at 06:14:01PM +0300, Sakari Ailus wrote: > On Tue, Apr 07, 2020 at 03:21:06PM +0300, Laurent Pinchart wrote: > > On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > >> On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > >>> On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > >>>> On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > >>>>> Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > >>>>> as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > >>>>> 24MHz. So instead making clock-frequency as dt-property just let the > >>>>> driver enforce the required clock frequency. > >>>> > >>>> Even if some current systems where the driver is used are using 24 MHz > >>>> clock, that doesn't mean there wouldn't be systems using another frequency > >>>> that the driver does not support right now. > >>>> > >>>> The driver really should not set the frequency unless it gets it from DT, > >>>> but I think the preferred means is to use assigned-clock-rates instead, and > >>>> not to involve the driver with setting the frequency. > >>>> > >>>> Otherwise we'll make it impossible to support other frequencies, at least > >>>> without more or less random defaults. > >>> > >>> We're running in circles here. > >>> > >>> As the driver only supports 24MHz at the moment, the frequency should be > >>> set by the driver, as it's a driver limitation. We can then work on > >>> supporting additional frequencies, which will require DT to provide a > >>> list of supported frequencies for the system, but that can be done on > >>> top. > >> > >> I guess it would be possible to use different external clock frequencies on > >> a sensor in a given system but that seems to be a bit far fetched, to the > >> extent I've never seen anyone doing that in practice. > >> > >> Originally, the driver set the frequency based on the clock-frequency > >> property. If we're removing that but use a fixed frequency instead, then > >> how is that going to work going forward when someone adds support for other > >> frequencies in the driver and has a system requiring that, while there are > >> some other platforms relying on the driver setting a particular frequency? > > > > The standard property for this is link-frequencies, not clock-frequency. > > Deprecating clock-frequency now paves the way to use the standard > > property later when/if someone implements support for additional > > frequencies. > > The external clock frequency and link frequency are different indeed, but > they are related. The link frequency has been selected in a way that it is > possible to generate that exact frequency using the chosen external clock > frequency. If you change the external clock frequency, chances are good > there is no PLL configuration to generate that link frequency. But aren't we supposed to pick the clock frequency based on the link frequency specified in DT ? In any case, this policy needs to be carefully documented. > >> Although, if you're saying that this driver only needs to work with DT that > >> comes with the kernel and you don't care about DT binary compatibility, > >> this would be fine. > > > > I believe this series to not break backward compatibility, as the driver > > only works with a 24MHz clock, so I expect all DTs to specify that. > > What you're still doing here is defining the DT bindings based on the > current driver implementation, not the device properties. Quite the contrary, the device doesn't require any particular input clock frequency, so we're removing that from DT :-) Specifying the clock frequency in DT is in my opinion a manual workaround for not computing it at runtime based on the desired link frequency, while the link frequency is a property of the system as it specifies the range of link frequencies that are safe to use from an EMC point of view.
Hi Sakari, On Tue, Apr 14, 2020 at 11:55:54PM +0300, Laurent Pinchart wrote: > On Tue, Apr 07, 2020 at 06:14:01PM +0300, Sakari Ailus wrote: > > On Tue, Apr 07, 2020 at 03:21:06PM +0300, Laurent Pinchart wrote: > >> On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > >>> On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > >>>> On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > >>>>> On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > >>>>>> Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > >>>>>> as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > >>>>>> 24MHz. So instead making clock-frequency as dt-property just let the > >>>>>> driver enforce the required clock frequency. > >>>>> > >>>>> Even if some current systems where the driver is used are using 24 MHz > >>>>> clock, that doesn't mean there wouldn't be systems using another frequency > >>>>> that the driver does not support right now. > >>>>> > >>>>> The driver really should not set the frequency unless it gets it from DT, > >>>>> but I think the preferred means is to use assigned-clock-rates instead, and > >>>>> not to involve the driver with setting the frequency. > >>>>> > >>>>> Otherwise we'll make it impossible to support other frequencies, at least > >>>>> without more or less random defaults. > >>>> > >>>> We're running in circles here. > >>>> > >>>> As the driver only supports 24MHz at the moment, the frequency should be > >>>> set by the driver, as it's a driver limitation. We can then work on > >>>> supporting additional frequencies, which will require DT to provide a > >>>> list of supported frequencies for the system, but that can be done on > >>>> top. > >>> > >>> I guess it would be possible to use different external clock frequencies on > >>> a sensor in a given system but that seems to be a bit far fetched, to the > >>> extent I've never seen anyone doing that in practice. > >>> > >>> Originally, the driver set the frequency based on the clock-frequency > >>> property. If we're removing that but use a fixed frequency instead, then > >>> how is that going to work going forward when someone adds support for other > >>> frequencies in the driver and has a system requiring that, while there are > >>> some other platforms relying on the driver setting a particular frequency? > >> > >> The standard property for this is link-frequencies, not clock-frequency. > >> Deprecating clock-frequency now paves the way to use the standard > >> property later when/if someone implements support for additional > >> frequencies. > > > > The external clock frequency and link frequency are different indeed, but > > they are related. The link frequency has been selected in a way that it is > > possible to generate that exact frequency using the chosen external clock > > frequency. If you change the external clock frequency, chances are good > > there is no PLL configuration to generate that link frequency. > > But aren't we supposed to pick the clock frequency based on the link > frequency specified in DT ? > > In any case, this policy needs to be carefully documented. And by this I mean in a central place, not leaving it to individual bindings. Maxime, we've previously discussed this issue privately on IRC, what's your opinion ? > >>> Although, if you're saying that this driver only needs to work with DT that > >>> comes with the kernel and you don't care about DT binary compatibility, > >>> this would be fine. > >> > >> I believe this series to not break backward compatibility, as the driver > >> only works with a 24MHz clock, so I expect all DTs to specify that. > > > > What you're still doing here is defining the DT bindings based on the > > current driver implementation, not the device properties. > > Quite the contrary, the device doesn't require any particular input > clock frequency, so we're removing that from DT :-) Specifying the clock > frequency in DT is in my opinion a manual workaround for not computing > it at runtime based on the desired link frequency, while the link > frequency is a property of the system as it specifies the range of link > frequencies that are safe to use from an EMC point of view.
On Tue, Apr 14, 2020 at 11:55:52PM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Tue, Apr 07, 2020 at 06:14:01PM +0300, Sakari Ailus wrote: > > On Tue, Apr 07, 2020 at 03:21:06PM +0300, Laurent Pinchart wrote: > > > On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > > >> On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > > >>> On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > > >>>> On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > >>>>> Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > >>>>> as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > >>>>> 24MHz. So instead making clock-frequency as dt-property just let the > > >>>>> driver enforce the required clock frequency. > > >>>> > > >>>> Even if some current systems where the driver is used are using 24 MHz > > >>>> clock, that doesn't mean there wouldn't be systems using another frequency > > >>>> that the driver does not support right now. > > >>>> > > >>>> The driver really should not set the frequency unless it gets it from DT, > > >>>> but I think the preferred means is to use assigned-clock-rates instead, and > > >>>> not to involve the driver with setting the frequency. > > >>>> > > >>>> Otherwise we'll make it impossible to support other frequencies, at least > > >>>> without more or less random defaults. > > >>> > > >>> We're running in circles here. > > >>> > > >>> As the driver only supports 24MHz at the moment, the frequency should be > > >>> set by the driver, as it's a driver limitation. We can then work on > > >>> supporting additional frequencies, which will require DT to provide a > > >>> list of supported frequencies for the system, but that can be done on > > >>> top. > > >> > > >> I guess it would be possible to use different external clock frequencies on > > >> a sensor in a given system but that seems to be a bit far fetched, to the > > >> extent I've never seen anyone doing that in practice. > > >> > > >> Originally, the driver set the frequency based on the clock-frequency > > >> property. If we're removing that but use a fixed frequency instead, then > > >> how is that going to work going forward when someone adds support for other > > >> frequencies in the driver and has a system requiring that, while there are > > >> some other platforms relying on the driver setting a particular frequency? > > > > > > The standard property for this is link-frequencies, not clock-frequency. > > > Deprecating clock-frequency now paves the way to use the standard > > > property later when/if someone implements support for additional > > > frequencies. > > > > The external clock frequency and link frequency are different indeed, but > > they are related. The link frequency has been selected in a way that it is > > possible to generate that exact frequency using the chosen external clock > > frequency. If you change the external clock frequency, chances are good > > there is no PLL configuration to generate that link frequency. > > But aren't we supposed to pick the clock frequency based on the link > frequency specified in DT ? > > In any case, this policy needs to be carefully documented. > > > >> Although, if you're saying that this driver only needs to work with DT that > > >> comes with the kernel and you don't care about DT binary compatibility, > > >> this would be fine. > > > > > > I believe this series to not break backward compatibility, as the driver > > > only works with a 24MHz clock, so I expect all DTs to specify that. > > > > What you're still doing here is defining the DT bindings based on the > > current driver implementation, not the device properties. > > Quite the contrary, the device doesn't require any particular input > clock frequency, so we're removing that from DT :-) Specifying the clock > frequency in DT is in my opinion a manual workaround for not computing > it at runtime based on the desired link frequency, while the link > frequency is a property of the system as it specifies the range of link > frequencies that are safe to use from an EMC point of view. I 100% agree with this. Maxime
Hi Laurent, On Tue, Apr 14, 2020 at 11:55:52PM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Tue, Apr 07, 2020 at 06:14:01PM +0300, Sakari Ailus wrote: > > On Tue, Apr 07, 2020 at 03:21:06PM +0300, Laurent Pinchart wrote: > > > On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > > >> On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > > >>> On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > > >>>> On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > > >>>>> Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > > >>>>> as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > > >>>>> 24MHz. So instead making clock-frequency as dt-property just let the > > >>>>> driver enforce the required clock frequency. > > >>>> > > >>>> Even if some current systems where the driver is used are using 24 MHz > > >>>> clock, that doesn't mean there wouldn't be systems using another frequency > > >>>> that the driver does not support right now. > > >>>> > > >>>> The driver really should not set the frequency unless it gets it from DT, > > >>>> but I think the preferred means is to use assigned-clock-rates instead, and > > >>>> not to involve the driver with setting the frequency. > > >>>> > > >>>> Otherwise we'll make it impossible to support other frequencies, at least > > >>>> without more or less random defaults. > > >>> > > >>> We're running in circles here. > > >>> > > >>> As the driver only supports 24MHz at the moment, the frequency should be > > >>> set by the driver, as it's a driver limitation. We can then work on > > >>> supporting additional frequencies, which will require DT to provide a > > >>> list of supported frequencies for the system, but that can be done on > > >>> top. > > >> > > >> I guess it would be possible to use different external clock frequencies on > > >> a sensor in a given system but that seems to be a bit far fetched, to the > > >> extent I've never seen anyone doing that in practice. > > >> > > >> Originally, the driver set the frequency based on the clock-frequency > > >> property. If we're removing that but use a fixed frequency instead, then > > >> how is that going to work going forward when someone adds support for other > > >> frequencies in the driver and has a system requiring that, while there are > > >> some other platforms relying on the driver setting a particular frequency? > > > > > > The standard property for this is link-frequencies, not clock-frequency. > > > Deprecating clock-frequency now paves the way to use the standard > > > property later when/if someone implements support for additional > > > frequencies. > > > > The external clock frequency and link frequency are different indeed, but > > they are related. The link frequency has been selected in a way that it is > > possible to generate that exact frequency using the chosen external clock > > frequency. If you change the external clock frequency, chances are good > > there is no PLL configuration to generate that link frequency. > > But aren't we supposed to pick the clock frequency based on the link > frequency specified in DT ? No. In a general case there is no reliable way to come up with an external clock frequency based on another, different if related, frequency. > > In any case, this policy needs to be carefully documented. I thought after ten or so years this would be already an established practice. :-) I agree it should be documented. We don't seem to have specific documentation for camera sensor drivers at the moment. I can submit a patch... > > > >> Although, if you're saying that this driver only needs to work with DT that > > >> comes with the kernel and you don't care about DT binary compatibility, > > >> this would be fine. > > > > > > I believe this series to not break backward compatibility, as the driver > > > only works with a 24MHz clock, so I expect all DTs to specify that. > > > > What you're still doing here is defining the DT bindings based on the > > current driver implementation, not the device properties. > > Quite the contrary, the device doesn't require any particular input > clock frequency, so we're removing that from DT :-) Specifying the clock > frequency in DT is in my opinion a manual workaround for not computing > it at runtime based on the desired link frequency, while the link > frequency is a property of the system as it specifies the range of link > frequencies that are safe to use from an EMC point of view. The external clock frequency is significantly lower than the link frequency (usually), but it still comes out of the SoC (or a PMIC chip). The clock signal track on PCB as well as wiring may also be rather long, depending on where the camera sensor is --- quite possibly tens of centimetres. Therefore I wouldn't categorically rule out possible EMC issues with that one either. The bottom line is: use a known-good, safe frequency.
Hi Sakari, On Wed, Apr 15, 2020 at 07:27:22PM +0300, Sakari Ailus wrote: > On Tue, Apr 14, 2020 at 11:55:52PM +0300, Laurent Pinchart wrote: > > On Tue, Apr 07, 2020 at 06:14:01PM +0300, Sakari Ailus wrote: > >> On Tue, Apr 07, 2020 at 03:21:06PM +0300, Laurent Pinchart wrote: > >>> On Tue, Apr 07, 2020 at 09:22:41AM +0300, Sakari Ailus wrote: > >>>> On Mon, Apr 06, 2020 at 08:32:34PM +0300, Laurent Pinchart wrote: > >>>>> On Mon, Apr 06, 2020 at 07:51:08PM +0300, Sakari Ailus wrote: > >>>>>> On Mon, Apr 06, 2020 at 05:42:38PM +0100, Lad Prabhakar wrote: > >>>>>>> Modes in the driver are based on xvclk frequency fixed to 24MHz, but where > >>>>>>> as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to > >>>>>>> 24MHz. So instead making clock-frequency as dt-property just let the > >>>>>>> driver enforce the required clock frequency. > >>>>>> > >>>>>> Even if some current systems where the driver is used are using 24 MHz > >>>>>> clock, that doesn't mean there wouldn't be systems using another frequency > >>>>>> that the driver does not support right now. > >>>>>> > >>>>>> The driver really should not set the frequency unless it gets it from DT, > >>>>>> but I think the preferred means is to use assigned-clock-rates instead, and > >>>>>> not to involve the driver with setting the frequency. > >>>>>> > >>>>>> Otherwise we'll make it impossible to support other frequencies, at least > >>>>>> without more or less random defaults. > >>>>> > >>>>> We're running in circles here. > >>>>> > >>>>> As the driver only supports 24MHz at the moment, the frequency should be > >>>>> set by the driver, as it's a driver limitation. We can then work on > >>>>> supporting additional frequencies, which will require DT to provide a > >>>>> list of supported frequencies for the system, but that can be done on > >>>>> top. > >>>> > >>>> I guess it would be possible to use different external clock frequencies on > >>>> a sensor in a given system but that seems to be a bit far fetched, to the > >>>> extent I've never seen anyone doing that in practice. > >>>> > >>>> Originally, the driver set the frequency based on the clock-frequency > >>>> property. If we're removing that but use a fixed frequency instead, then > >>>> how is that going to work going forward when someone adds support for other > >>>> frequencies in the driver and has a system requiring that, while there are > >>>> some other platforms relying on the driver setting a particular frequency? > >>> > >>> The standard property for this is link-frequencies, not clock-frequency. > >>> Deprecating clock-frequency now paves the way to use the standard > >>> property later when/if someone implements support for additional > >>> frequencies. > >> > >> The external clock frequency and link frequency are different indeed, but > >> they are related. The link frequency has been selected in a way that it is > >> possible to generate that exact frequency using the chosen external clock > >> frequency. If you change the external clock frequency, chances are good > >> there is no PLL configuration to generate that link frequency. > > > > But aren't we supposed to pick the clock frequency based on the link > > frequency specified in DT ? > > No. In a general case there is no reliable way to come up with an external > clock frequency based on another, different if related, frequency. > > > In any case, this policy needs to be carefully documented. > > I thought after ten or so years this would be already an established > practice. :-) > > I agree it should be documented. We don't seem to have specific > documentation for camera sensor drivers at the moment. I can submit a > patch... > > >>>> Although, if you're saying that this driver only needs to work with DT that > >>>> comes with the kernel and you don't care about DT binary compatibility, > >>>> this would be fine. > >>> > >>> I believe this series to not break backward compatibility, as the driver > >>> only works with a 24MHz clock, so I expect all DTs to specify that. > >> > >> What you're still doing here is defining the DT bindings based on the > >> current driver implementation, not the device properties. > > > > Quite the contrary, the device doesn't require any particular input > > clock frequency, so we're removing that from DT :-) Specifying the clock > > frequency in DT is in my opinion a manual workaround for not computing > > it at runtime based on the desired link frequency, while the link > > frequency is a property of the system as it specifies the range of link > > frequencies that are safe to use from an EMC point of view. > > The external clock frequency is significantly lower than the link frequency > (usually), but it still comes out of the SoC (or a PMIC chip). The clock > signal track on PCB as well as wiring may also be rather long, depending on > where the camera sensor is --- quite possibly tens of centimetres. > Therefore I wouldn't categorically rule out possible EMC issues with that > one either. That's a valid point. > The bottom line is: use a known-good, safe frequency. What if different input clock frequencies are needed to achieve different link frequencies ?
diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index a6c17d15d754..52848fff8a08 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -61,6 +61,8 @@ #define OV5645_SDE_SAT_U 0x5583 #define OV5645_SDE_SAT_V 0x5584 +#define OV5645_XVCLK_FREQ 24000000 + /* regulator supplies */ static const char * const ov5645_supply_name[] = { "vdddo", /* Digital I/O (1.8V) supply */ @@ -1094,25 +1096,19 @@ 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 = clk_set_rate(ov5645->xclk, OV5645_XVCLK_FREQ); if (ret) { - dev_err(dev, "could not get xclk frequency\n"); + dev_err(dev, "could not set xclk frequency\n"); return ret; } - /* external clock must be 24MHz, allow 1% tolerance */ + xclk_freq = clk_get_rate(ov5645->xclk); if (xclk_freq < 23760000 || xclk_freq > 24240000) { dev_err(dev, "external clock frequency %u is not supported\n", xclk_freq); return -EINVAL; } - 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++) ov5645->supplies[i].supply = ov5645_supply_name[i];
Modes in the driver are based on xvclk frequency fixed to 24MHz, but where as the OV5645 sensor can support the xvclk frequency ranging from 6MHz to 24MHz. So instead making clock-frequency as dt-property just let the driver enforce the required clock frequency. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> --- drivers/media/i2c/ov5645.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)