All of lore.kernel.org
 help / color / mirror / Atom feed
* Question: regmap_field_write() - why using update?
@ 2022-07-14 15:01 Krzysztof Kozlowski
  2022-07-14 15:07 ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kozlowski @ 2022-07-14 15:01 UTC (permalink / raw)
  To: Mark Brown, Srinivas Kandagatla, Linux Kernel Mailing List

Hi guys,

I am converting my driver using MMIO to regmap from readl/writel and to
my surprise I found that regmap_field_write() does not behave the same
as regmap_write(). I would expect that they are the same, except one
operates on fields.

However regmap_field_write() uses an update method [1] which means it
reads and performs update. regmap_write() simply writes without a read.

I find it inconsistent and a bit confusing. Any reasons for such
behavior so I won't send a patch which breaks 100 of devices?

[1]
https://elixir.bootlin.com/linux/latest/source/include/linux/regmap.h#L1307

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: regmap_field_write() - why using update?
  2022-07-14 15:01 Question: regmap_field_write() - why using update? Krzysztof Kozlowski
@ 2022-07-14 15:07 ` Mark Brown
  2022-07-14 15:13   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2022-07-14 15:07 UTC (permalink / raw)
  To: Krzysztof Kozlowski; +Cc: Srinivas Kandagatla, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 782 bytes --]

On Thu, Jul 14, 2022 at 05:01:29PM +0200, Krzysztof Kozlowski wrote:

> I am converting my driver using MMIO to regmap from readl/writel and to
> my surprise I found that regmap_field_write() does not behave the same
> as regmap_write(). I would expect that they are the same, except one
> operates on fields.

> However regmap_field_write() uses an update method [1] which means it
> reads and performs update. regmap_write() simply writes without a read.

> I find it inconsistent and a bit confusing. Any reasons for such
> behavior so I won't send a patch which breaks 100 of devices?

How would you propose to write to a field without reading the rest of
the bits in the register?  Otherwise you'd be doing a full register
write rather than just a write to the specific field.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: regmap_field_write() - why using update?
  2022-07-14 15:07 ` Mark Brown
@ 2022-07-14 15:13   ` Krzysztof Kozlowski
  2022-07-14 15:15     ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kozlowski @ 2022-07-14 15:13 UTC (permalink / raw)
  To: Mark Brown; +Cc: Srinivas Kandagatla, Linux Kernel Mailing List

On 14/07/2022 17:07, Mark Brown wrote:
> On Thu, Jul 14, 2022 at 05:01:29PM +0200, Krzysztof Kozlowski wrote:
> 
>> I am converting my driver using MMIO to regmap from readl/writel and to
>> my surprise I found that regmap_field_write() does not behave the same
>> as regmap_write(). I would expect that they are the same, except one
>> operates on fields.
> 
>> However regmap_field_write() uses an update method [1] which means it
>> reads and performs update. regmap_write() simply writes without a read.
> 
>> I find it inconsistent and a bit confusing. Any reasons for such
>> behavior so I won't send a patch which breaks 100 of devices?
> 
> How would you propose to write to a field without reading the rest of
> the bits in the register?  Otherwise you'd be doing a full register
> write rather than just a write to the specific field.

Indeed, I forgot about bits in a field... So it has to be like this or I
need to use regmap_write(). I find the regmap field API very useful for
devices with different register layouts, but the actual "fields" part is
not really needed in my case.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: regmap_field_write() - why using update?
  2022-07-14 15:13   ` Krzysztof Kozlowski
@ 2022-07-14 15:15     ` Krzysztof Kozlowski
  2022-07-14 18:27       ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kozlowski @ 2022-07-14 15:15 UTC (permalink / raw)
  To: Mark Brown; +Cc: Srinivas Kandagatla, Linux Kernel Mailing List

On 14/07/2022 17:13, Krzysztof Kozlowski wrote:
> On 14/07/2022 17:07, Mark Brown wrote:
>> On Thu, Jul 14, 2022 at 05:01:29PM +0200, Krzysztof Kozlowski wrote:
>>
>>> I am converting my driver using MMIO to regmap from readl/writel and to
>>> my surprise I found that regmap_field_write() does not behave the same
>>> as regmap_write(). I would expect that they are the same, except one
>>> operates on fields.
>>
>>> However regmap_field_write() uses an update method [1] which means it
>>> reads and performs update. regmap_write() simply writes without a read.
>>
>>> I find it inconsistent and a bit confusing. Any reasons for such
>>> behavior so I won't send a patch which breaks 100 of devices?
>>
>> How would you propose to write to a field without reading the rest of
>> the bits in the register?  Otherwise you'd be doing a full register
>> write rather than just a write to the specific field.
> 
> Indeed, I forgot about bits in a field... So it has to be like this or I
> need to use regmap_write(). I find the regmap field API very useful for
> devices with different register layouts, but the actual "fields" part is
> not really needed in my case.

... and few registers (like "clear" registers) actually do not allow to
read.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: regmap_field_write() - why using update?
  2022-07-14 15:15     ` Krzysztof Kozlowski
@ 2022-07-14 18:27       ` Mark Brown
  2022-07-19 12:01         ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2022-07-14 18:27 UTC (permalink / raw)
  To: Krzysztof Kozlowski; +Cc: Srinivas Kandagatla, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

On Thu, Jul 14, 2022 at 05:15:34PM +0200, Krzysztof Kozlowski wrote:
> On 14/07/2022 17:13, Krzysztof Kozlowski wrote:

> > Indeed, I forgot about bits in a field... So it has to be like this or I
> > need to use regmap_write(). I find the regmap field API very useful for
> > devices with different register layouts, but the actual "fields" part is
> > not really needed in my case.

> ... and few registers (like "clear" registers) actually do not allow to
> read.

The write only registers are a good point - we could handle them through
special casing, that'd avoid any overhead from reading or issues if a
physical read happens to return something unfortunate for some reason.
Now I think about it there's also the fun case of registers which don't
have symmetric read and write, though at some point regmap_field does
stop being useful and those might well be pushing it.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: regmap_field_write() - why using update?
  2022-07-14 18:27       ` Mark Brown
@ 2022-07-19 12:01         ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2022-07-19 12:01 UTC (permalink / raw)
  To: Mark Brown; +Cc: Srinivas Kandagatla, Linux Kernel Mailing List

On 14/07/2022 20:27, Mark Brown wrote:
> The write only registers are a good point - we could handle them through
> special casing, that'd avoid any overhead from reading or issues if a
> physical read happens to return something unfortunate for some reason.

I have something ready and I will send it soon.

> Now I think about it there's also the fun case of registers which don't
> have symmetric read and write, though at some point regmap_field does
> stop being useful and those might well be pushing it.

Right.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-19 12:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 15:01 Question: regmap_field_write() - why using update? Krzysztof Kozlowski
2022-07-14 15:07 ` Mark Brown
2022-07-14 15:13   ` Krzysztof Kozlowski
2022-07-14 15:15     ` Krzysztof Kozlowski
2022-07-14 18:27       ` Mark Brown
2022-07-19 12:01         ` Krzysztof Kozlowski

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.