Skip to contentSkip to conversation

Question: regmap_field_write() - why using update?

DISCUSSION Krzysztof Kozlowski 2 participants 6 messages Jul 14, 2022 – Jul 19, 2022

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 10 lines · Krzysztof Kozlowski

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.

#2 lore raw
Quoted 10 lines · Mark Brown
Quoted 7 lines · Krzysztof Kozlowski

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.

Quoted 6 lines
Quoted 2 lines

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

#3 lore raw
Quoted 14 lines · Krzysztof Kozlowski
Quoted 13 lines · Mark Brown
Quoted 10 lines · Krzysztof Kozlowski

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?

Quoted 8 lines
Quoted 3 lines

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

#4 lore raw
Quoted 9 lines · Krzysztof Kozlowski
Quoted 4 lines · Krzysztof Kozlowski

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.

#5 lore raw
Quoted 3 lines · Mark Brown

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.

Quoted 3 lines

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