All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fillion, Claude" <Claude.Fillion@mksinst.com>
To: Luca Ceresoli <luca@lucaceresoli.net>, Adam Ford <aford173@gmail.com>
Cc: Sean Anderson <sean.anderson@seco.com>,
	linux-clk <linux-clk@vger.kernel.org>
Subject: RE: [EXTERNAL] Re: Questions regarding regarding idt/renesas versaclock5 driver
Date: Tue, 22 Mar 2022 20:09:24 +0000	[thread overview]
Message-ID: <MN2PR03MB50085D86CF1C1CC89FD74E0993179@MN2PR03MB5008.namprd03.prod.outlook.com> (raw)
In-Reply-To: <158a5b3e-7ed0-c545-99d7-8890583facdb@lucaceresoli.net>

Hello Luca,

> -----Original Message-----
> From: Luca Ceresoli <luca@lucaceresoli.net>
> Sent: Tuesday, March 22, 2022 12:00 PM
> To: Fillion, Claude <Claude.Fillion@mksinst.com>; Adam Ford
> <aford173@gmail.com>
> Cc: Sean Anderson <sean.anderson@seco.com>; linux-clk <linux-
> clk@vger.kernel.org>
> Subject: Re: [EXTERNAL] Re: Questions regarding regarding idt/renesas
> versaclock5 driver
> 
> Hi Claude,
> 
> On 21/03/22 22:21, Fillion, Claude wrote:
> [...]
> >>>> Look at the use of devm_clk_get_optional and clk_prepare_enable
> >>>> from that patch.  (yes, there is a subsequent patch that fixes
> >>>> something I didn't quite do right, but the basics are here)
> >>>>
> >>>> The consumer drivers need to 'get' the clock so it can associate
> >>>> itself to the clock in question.  Once the relationship is
> >>>> established, the consumer needs to call clk_prepare_enable() which
> >>>> uses
> >> the clock system to turn the clock on.
> >>>> Without this step, it's likely the Versaclock won't generate a
> >>>> signal, because it doesn't know it needs to turn it on.
> >>>>
> >>>> adam
> >>>
> >>> Not sure I fully follow.  I see that clk out1 is enabled but the
> >>> other channels
> >> are not so it would seem my difficulty is with individual channels.
> >>
> >> Do the devices that need the clock from the versaclock reference the
> >> versaclock?  If so, to those drivers use the get and enable?  If not,
> >> the versaclock will stay off.  In the patch example I showed, I had
> >> to modify the Ethernet driver on a processor, because it didn't
> >> explicitly enable the reference clock.  That Ethernet driver expected
> >> the refclk was always present which was a false assumption.  Once I
> >> got the consumer device (in this case, Ethernet) to request and
> >> enable the clock, the clock subsystem enabled the corresponding output
> on the versaclock.
> >>
> >> For the Ethernet example I cited above, the corresponding device tree
> >> looks
> >> like:
> >>
> >> &avb {
> >>      clocks = <&cpg CPG_MOD 812>, <&versaclock5 4>;
> >>      clock-names = "fck", "refclk";
> >>      status = "okay";
> >> };
> >>
> >> With this device tree reference, the 'refclk' gets associated to
> >> versaclock ouput 4.  When the Ethernet needs the clock, it calls
> >> clk_prepare_enable on that clock reference, and the clock system
> >> calls on the versaclock driver to enable the output.  The reason I
> >> needed to submit that patch was that the consumer driver (the
> >> Ethernet in this
> >> case) wasn't calling the clk_prepare_enable, so the clock remained
> >> off.  It's likely that whatever devices that need the clock from the
> >> versaclock will need both a device tree reference to it as well as a
> >> call to clk_prepare_enable.
> >
> > For my application I would like the ability to set clock frequencies according
> to values that are stored in a json formatted config file. Is there a way to
> change these values from user space app code?  If not, would it be ok to add
> code to my consumer driver (say in the probe method) that would read the
> values from the json and then call set_rate() and prepare_enable()) ?
> 
> This is absolutely not a standard practice in the kernel. If drivers are well
> written then a consumer driver knows which clock it needs, it will ask the
> produced that frequency and configure the consumer device accordingly.
> 
> E.g. if the consumer device is an audio codec then user space will never say "I
> want you to ask for a 1 MHz clock" but rather "I want to playback at 48 kHz",
> then the driver will ask for a given clock frequency and configure the codec to
> use it, perhaps setting divisor/multiplier registers etc.
> 
> So I really suggest you to understand what the correct kernel-userspace
> interface would be for your consumer driver. If you want you can share what
> the consumer device is so we can be give some suggestions.
> 
> That said, if you don't want to mainline your consumer driver nobody will
> prevent you from doing anything "strange". But keep it limited to your driver,
> you don't want to have conflicts in the versaclock code when you upgrade to
> a more recent kernel.
> 
> Also, I don't think json is expected to be in the kernel. If you want to do
> something like that then maybe parse json at userspace level and then send
> just the frequency in Hz via a sysfs entry.
> 
> --
> Luca

Hello Luca,
Thank you for responding.  I will attempt to provide a little more detail on our use case.  Our products do a fair amount of signal processing, both in transmitting and receiving chains. The clocks we would like to adjust control ADC and DAC sample rates.  These rates do not change frequently, but depending on particular features we enable or on conditions that are specific to a certain customer there will be times where we will need to change sample rates. Our products have an extensive set of configuration parameters contained in json files that control many details of our signal processing chains.  Ideally we would like to add the ability to get/set clock rates through this mechanism.

When changing frequency we expect to reboot the device, but would like to avoid rebuilding/distributing new code.  Essentially  1 code package, configured multiple different ways.

The idea of parsing json at userspace and just sending the frequency in Hz via a sysfs entry seems appealing. I thought I would need to call the set_rate() method of the driver in order to change frequency.  If it is not too much trouble can you explain how I could change frequency via sysfs call?

This is what I see on the device in /sys:
      root@CLAUDE:/sys/class/i2c-dev/i2c-1/device/1-006a# ls
      driver     modalias   name       of_node    power      subsystem  uevent

From this I am not clear on how to set frequency.

Regards,
Claude

======================================================================
This message and any attachments are intended only for the designated recipient(s) and may contain confidential or proprietary information and be subject to the attorney-client privilege or other confidentiality protections.  If you are not a designated recipient, you may not review, use, copy or distribute this message or any attachments.  If you received this email in error, please notify the sender by reply e-mail and permanently delete the original and any copies of this message and any attachments thereto.  Thank you.

  reply	other threads:[~2022-03-22 20:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <MN2PR03MB5008EB5F50B680C2A2E271D893019@MN2PR03MB5008.namprd03.prod.outlook.com>
2022-02-28 16:03 ` Questions regarding regarding idt/renesas versaclock5 driver Sean Anderson
2022-02-28 17:06   ` Adam Ford
2022-02-28 22:13     ` Luca Ceresoli
     [not found]       ` <MN2PR03MB5008747FDF505CA30970ADE293029@MN2PR03MB5008.namprd03.prod.outlook.com>
2022-03-01 14:29         ` [EXTERNAL] " Adam Ford
2022-03-01 18:16           ` Fillion, Claude
2022-03-01 18:28             ` Adam Ford
2022-03-02 14:43               ` Fillion, Claude
2022-03-02 15:45                 ` Adam Ford
2022-03-02 17:26                   ` Luca Ceresoli
2022-03-02 20:49                     ` Fillion, Claude
2022-03-03 14:41                       ` Luca Ceresoli
2022-03-03 18:15                         ` Fillion, Claude
2022-03-03 22:33                           ` Luca Ceresoli
2022-03-04 20:07                             ` Fillion, Claude
2022-03-04 20:30                               ` Luca Ceresoli
2022-03-07 20:39                                 ` Fillion, Claude
2022-03-07 20:41                                   ` Fillion, Claude
2022-03-09 17:20                                   ` Luca Ceresoli
2022-03-09 18:02                                     ` Fillion, Claude
2022-03-09 18:44                                       ` Adam Ford
2022-03-04 20:53                           ` Sean Anderson
2022-03-07 20:39                             ` Fillion, Claude
2022-03-21 21:21                   ` Fillion, Claude
2022-03-22 15:59                     ` Luca Ceresoli
2022-03-22 20:09                       ` Fillion, Claude [this message]
2022-04-14 22:37                         ` Luca Ceresoli
2022-04-15 14:26                           ` Fillion, Claude

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MN2PR03MB50085D86CF1C1CC89FD74E0993179@MN2PR03MB5008.namprd03.prod.outlook.com \
    --to=claude.fillion@mksinst.com \
    --cc=aford173@gmail.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=luca@lucaceresoli.net \
    --cc=sean.anderson@seco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.