All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Sperl <kernel@martin.sperl.org>
To: "Eric Anholt" <eric@anholt.net>,
	"Noralf Trønnes" <noralf@tronnes.org>,
	wsa@the-dreams.de, swarren@wwwdotorg.org
Cc: linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH v3 7/7] i2c: bcm2835: Add support for dynamic clock
Date: Thu, 29 Sep 2016 10:02:44 +0200	[thread overview]
Message-ID: <109bda50-455e-f91b-a3a1-bf00cb5745db@martin.sperl.org> (raw)
In-Reply-To: <87r383g1kb.fsf@eliezer.anholt.net>

On 28.09.2016 23:24, Eric Anholt wrote:
> Noralf Trønnes <noralf@tronnes.org> writes:
>
>> Support a dynamic clock by reading the frequency and setting the
>> divisor in the transfer function instead of during probe.
> Is this fixing some particular case you could note in the commit
> message?  As is, it makes me think that we should be using a notifier
> for when the parent clock (that's the one I assume you're talking about
> being dynamic) changes.  But maybe you're working around a variable VPU
> clock being set by the firmware, because we don't have a notifier for
> it?
>
> I'm a bit worried because I think this is going to be pretty expensive
> to be doing per transfer.

Well, the clocks are all configured without CLK_GET_RATE_NOCACHE et. al.,
so the value is read from cache, which is not (very) expensive
(see clk_core_get_rate).

This also means that any clock change of the VPU done by the firmware
does not propagate to the linux kernel anyway and the unchanged
cached value is returned.

To make this work it would require a notification mechanism from the
firmware to trigger a re-validation of all the caches. (or some sort of 
watchdog
process).

Adding a notifier to each driver (I2C, SPI) instead is - imo - a lot of 
unnecessary
code complexity, as any currently running transfer would still be impacted,
because changing the clock-divider in flight is a asking for trouble.
But then changing the vpu-clock speed while a I2s/SPI/... transfer is 
running is
also asking for trouble....

The only place where - IMO - a notifier would make sense is with the 
auxiliar
UART driver(8250_bcm2835aux.c), as there we only read the clock rates
when setting/changing the baud rate. But - again -  this would require some
notification by the firmware in the first place and any reception in the
window of change would go wrong because of unexpected effective baud
rate changes.

So as far as I can tell the change to read the current clock rate in the
transfer function is a reasonable approach and the clock framework should
handle the communication with the firmware about such changes.
(And I remember having had some discussions around this subject
with Phil Elwell or popcornmix some time ago on github where it boiled
down to: what is the "right" interface? - I can not find the reference
right now)

Reviewed-by: Martin Sperl <kernel@martin.sperl.org>

Thanks, Martin

WARNING: multiple messages have this Message-ID (diff)
From: kernel@martin.sperl.org (Martin Sperl)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 7/7] i2c: bcm2835: Add support for dynamic clock
Date: Thu, 29 Sep 2016 10:02:44 +0200	[thread overview]
Message-ID: <109bda50-455e-f91b-a3a1-bf00cb5745db@martin.sperl.org> (raw)
In-Reply-To: <87r383g1kb.fsf@eliezer.anholt.net>

On 28.09.2016 23:24, Eric Anholt wrote:
> Noralf Tr?nnes <noralf@tronnes.org> writes:
>
>> Support a dynamic clock by reading the frequency and setting the
>> divisor in the transfer function instead of during probe.
> Is this fixing some particular case you could note in the commit
> message?  As is, it makes me think that we should be using a notifier
> for when the parent clock (that's the one I assume you're talking about
> being dynamic) changes.  But maybe you're working around a variable VPU
> clock being set by the firmware, because we don't have a notifier for
> it?
>
> I'm a bit worried because I think this is going to be pretty expensive
> to be doing per transfer.

Well, the clocks are all configured without CLK_GET_RATE_NOCACHE et. al.,
so the value is read from cache, which is not (very) expensive
(see clk_core_get_rate).

This also means that any clock change of the VPU done by the firmware
does not propagate to the linux kernel anyway and the unchanged
cached value is returned.

To make this work it would require a notification mechanism from the
firmware to trigger a re-validation of all the caches. (or some sort of 
watchdog
process).

Adding a notifier to each driver (I2C, SPI) instead is - imo - a lot of 
unnecessary
code complexity, as any currently running transfer would still be impacted,
because changing the clock-divider in flight is a asking for trouble.
But then changing the vpu-clock speed while a I2s/SPI/... transfer is 
running is
also asking for trouble....

The only place where - IMO - a notifier would make sense is with the 
auxiliar
UART driver(8250_bcm2835aux.c), as there we only read the clock rates
when setting/changing the baud rate. But - again -  this would require some
notification by the firmware in the first place and any reception in the
window of change would go wrong because of unexpected effective baud
rate changes.

So as far as I can tell the change to read the current clock rate in the
transfer function is a reasonable approach and the clock framework should
handle the communication with the firmware about such changes.
(And I remember having had some discussions around this subject
with Phil Elwell or popcornmix some time ago on github where it boiled
down to: what is the "right" interface? - I can not find the reference
right now)

Reviewed-by: Martin Sperl <kernel@martin.sperl.org>

Thanks, Martin

  parent reply	other threads:[~2016-09-29  8:02 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-28 17:50 [PATCH v3 0/7] i2c: bcm2835: Bring in changes from downstream Noralf Trønnes
2016-09-28 17:50 ` Noralf Trønnes
2016-09-28 17:50 ` [PATCH v3 1/7] i2c: bcm2835: Fix hang for writing messages larger than 16 bytes Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-28 17:50 ` [PATCH v3 2/7] i2c: bcm2835: Protect against unexpected TXW/RXR interrupts Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-28 22:00   ` Eric Anholt
2016-09-28 22:00     ` Eric Anholt
2016-09-28 22:00     ` Eric Anholt
2016-09-28 22:22     ` Noralf Trønnes
2016-09-28 22:22       ` Noralf Trønnes
2016-09-29  5:37       ` Stefan Wahren
2016-09-29  5:37         ` Stefan Wahren
2016-10-02 14:19         ` Noralf Trønnes
2016-10-02 14:19           ` Noralf Trønnes
2016-10-03 18:58           ` Eric Anholt
2016-10-03 18:58             ` Eric Anholt
2016-10-03 19:42       ` Eric Anholt
2016-10-03 19:42         ` Eric Anholt
2016-10-04 19:24         ` Noralf Trønnes
2016-10-04 19:24           ` Noralf Trønnes
2016-09-28 17:50 ` [PATCH v3 3/7] i2c: bcm2835: Use dev_dbg logging on transfer errors Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-29 11:05   ` Martin Sperl
2016-09-29 11:05     ` Martin Sperl
2016-09-28 17:50 ` [PATCH v3 4/7] i2c: bcm2835: Can't support I2C_M_IGNORE_NAK Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-28 17:50 ` [PATCH v3 5/7] i2c: bcm2835: Add support for Repeated Start Condition Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-28 17:50 ` [PATCH v3 6/7] i2c: bcm2835: Support i2c-dev ioctl I2C_TIMEOUT Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-28 17:50 ` [PATCH v3 7/7] i2c: bcm2835: Add support for dynamic clock Noralf Trønnes
2016-09-28 17:50   ` Noralf Trønnes
2016-09-28 21:24   ` Eric Anholt
2016-09-28 21:24     ` Eric Anholt
2016-09-28 21:24     ` Eric Anholt
2016-09-28 22:10     ` Noralf Trønnes
2016-09-28 22:10       ` Noralf Trønnes
2016-09-29  8:02     ` Martin Sperl [this message]
2016-09-29  8:02       ` Martin Sperl

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=109bda50-455e-f91b-a3a1-bf00cb5745db@martin.sperl.org \
    --to=kernel@martin.sperl.org \
    --cc=eric@anholt.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=noralf@tronnes.org \
    --cc=swarren@wwwdotorg.org \
    --cc=wsa@the-dreams.de \
    /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.