Skip to contentSkip to conversation

regmap: Allow installing custom reg_update_bits function

PATCH Applied [email protected] 4 participants 14 messages Oct 1, 2015 – Oct 6, 2015

Subsystems (4)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 regmap: Allow installing custom reg_update_bits function

From: Jon Ringle <[email protected]>

This commit allows installing a custom reg_update_bits function for cases where the hardware provides a mechanism to set or clear register bits without a read/modify/write cycle. Such is the case with the Microchip ENCX24J600.

---
 drivers/base/regmap/internal.h |  3 +++
 drivers/base/regmap/regmap.c   | 25 +++++++++++++++++++++++++
 include/linux/regmap.h         |  4 ++++
 3 files changed, 32 insertions(+)
drivers/base/regmap/internal.h +3 -0
index cc55788..4036d7a 100644
@@ -98,6 +98,9 @@ struct regmap {
 
 	int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
 	int (*reg_write)(void *context, unsigned int reg, unsigned int val);
+	int (*reg_update_bits)(void *context, unsigned int reg,
+			       unsigned int mask, unsigned int val,
+			       bool *change, bool force_write);
 
 	bool defer_caching;
 
drivers/base/regmap/regmap.c +25 -0
index afaf562..70387c9 100644
@@ -619,6 +619,7 @@ struct regmap *__regmap_init(struct device *dev,
 		goto skip_format_initialization;
 	} else {
 		map->reg_read  = _regmap_bus_read;
+		map->reg_update_bits = bus->reg_update_bits;
 	}
 
 	reg_endian = regmap_get_reg_endian(bus, config);
@@ -2509,6 +2510,30 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
 	int ret;
 	unsigned int tmp, orig;
 
+	if (map->reg_update_bits) {
+		ret = map->reg_update_bits(map->bus_context, reg, mask, val,
+					   change, force_write);
+		if (ret != 0)
+			return ret;
+
+		/* Fix up the cache by read/modify/write */
+		if (!map->cache_bypass && !map->defer_caching) {
+			ret = regcache_read(map, reg, &orig);
+			if (ret != 0)
+				return ret;
+
+			tmp = orig & ~mask;
+			tmp |= val & mask;
+
+			ret = regcache_write(map, reg, tmp);
+			if (ret != 0)
+				return ret;
+			if (map->cache_only)
+				map->cache_dirty = true;
+		}
+		return ret;
+	}
+
 	ret = _regmap_read(map, reg, &orig);
 	if (ret != 0)
 		return ret;
include/linux/regmap.h +4 -0
index 8fc0bfd..4d3a3b1 100644
@@ -296,6 +296,9 @@ typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
 				  unsigned int *val);
 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
 				   unsigned int val);
+typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
+					 unsigned int mask, unsigned int val,
+					 bool *change, bool force_write);
 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
 typedef void (*regmap_hw_free_context)(void *context);
 
@@ -335,6 +338,7 @@ struct regmap_bus {
 	regmap_hw_gather_write gather_write;
 	regmap_hw_async_write async_write;
 	regmap_hw_reg_write reg_write;
+	regmap_hw_reg_update_bits reg_update_bits;
 	regmap_hw_read read;
 	regmap_hw_reg_read reg_read;
 	regmap_hw_free_context free_context;
Signature · 1 line
2.4.1
#1 lore raw

PATCH v2 2/2 net: Microchip encx24j600 driver

From: Jon Ringle <[email protected]>

This ethernet driver supports the Micorchip enc424j600/626j600 Ethernet controller over a SPI bus interface. This driver makes use of the regmap API to optimize access to registers by caching registers where possible.

Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39935b.pdf

---
 drivers/net/ethernet/microchip/Kconfig             |    9 +
 drivers/net/ethernet/microchip/Makefile            |    1 +
 drivers/net/ethernet/microchip/encx24j600-regmap.c |  551 ++++++++++
 drivers/net/ethernet/microchip/encx24j600.c        | 1124 ++++++++++++++++++++
 drivers/net/ethernet/microchip/encx24j600_hw.h     |  437 ++++++++
 5 files changed, 2122 insertions(+)
 create mode 100644 drivers/net/ethernet/microchip/encx24j600-regmap.c
 create mode 100644 drivers/net/ethernet/microchip/encx24j600.c
 create mode 100644 drivers/net/ethernet/microchip/encx24j600_hw.h
drivers/net/ethernet/microchip/Kconfig +9 -0
index afaf0c0..b45b28a 100644
@@ -35,4 +35,13 @@ config ENC28J60_WRITEVERIFY
 	  Enable the verify after the buffer write useful for debugging purpose.
 	  If unsure, say N.
 
+config ENCX24J600
+    tristate "ENCX24J600 support"
+    depends on SPI
+    ---help---
+      Support for the Microchip ENC424J600 ethernet chip.
+
+      To compile this driver as a module, choose M here. The module will be
+      called enc424j600.
+
 endif # NET_VENDOR_MICROCHIP
drivers/net/ethernet/microchip/Makefile +1 -0
index 573d429..ff78f62 100644
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_ENC28J60) += enc28j60.o
+obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o
drivers/net/ethernet/microchip/encx24j600-regmap.c new file +551 -0

551 lines not on this page · raw message

drivers/net/ethernet/microchip/encx24j600.c new file +1124 -0

1,124 lines not on this page · raw message

drivers/net/ethernet/microchip/encx24j600_hw.h new file +437 -0

437 lines not on this page · raw message

Signature · 1 line
2.4.1
#2 lore raw

[RFC PATCH] net: encx24j600_exit() can be static

Signed-off-by: Fengguang Wu <[email protected]>
---
 encx24j600.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/microchip/encx24j600.c +1 -1
index 1da37fd..afc008a 100644
@@ -1112,7 +1112,7 @@ static int __init encx24j600_init(void)
 }
 module_init(encx24j600_init);
 
-void encx24j600_exit(void)
+static void encx24j600_exit(void)
 {
 	spi_unregister_driver(&encx24j600_spi_net_driver);
 }
maintainer Applied
#3 lore raw

Re: [PATCH net-next v2 2/2] net: Microchip encx24j600 driver

In reply to [email protected]

From: [email protected]
Date: Thu, 1 Oct 2015 07:43:21 -0400

Quoted 10 lines

From: Jon Ringle <[email protected]>

This ethernet driver supports the Micorchip enc424j600/626j600 Ethernet controller over a SPI bus interface. This driver makes use of the regmap API to optimize access to registers by caching registers where possible.

Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39935b.pdf

Applied.

maintainer
#4 lore raw

Re: [PATCH net-next v2 2/2] net: Microchip encx24j600 driver

From: David Miller <[email protected]>
Date: Mon, 05 Oct 2015 03:54:55 -0700 (PDT)

Quoted 9 lines

From: [email protected]
Date: Thu, 1 Oct 2015 07:43:21 -0400

Quoted 6 lines

From: Jon Ringle <[email protected]>

This ethernet driver supports the Micorchip enc424j600/626j600 Ethernet controller over a SPI bus interface. This driver makes use of the regmap API to optimize access to registers by caching registers where possible.

Quoted 6 lines
Quoted 4 lines

Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39935b.pdf

Applied.

Actually, I had to revert both patches. Please look at the compiler warnings your code generates:

drivers/mfd/wm5110-tables.c: In function ‘wm5110_patch’:
drivers/mfd/wm5110-tables.c:281:11: warning: passing argument 2 of ‘regmap_register_patch’ from incompatible pointer type [enabled by default] In file included from include/linux/mfd/arizona/core.h:17:0,

                 from drivers/mfd/wm5110-tables.c:15:

include/linux/regmap.h:727:5: note: expected ‘const struct reg_sequence *’ but argument is of type ‘const struct reg_default *’ drivers/mfd/wm8998-tables.c: In function ‘wm8998_patch’:
drivers/mfd/wm8998-tables.c:50:10: warning: passing argument 2 of ‘regmap_register_patch’ from incompatible pointer type [enabled by default] In file included from include/linux/mfd/arizona/core.h:17:0,

                 from drivers/mfd/wm8998-tables.c:15:

include/linux/regmap.h:727:5: note: expected ‘const struct reg_sequence *’ but argument is of type ‘const struct reg_default *’ �τθΊ{.nΗ+‰·Ÿ�‰­†+%ŠΛ�±ιέΆ�Šw�Ί{.nΗ+‰·�Š{±ώG«ι�Š{ayΊΚ‡Ϊ™λ,j­’f£’·hšοκ�‘κηz_θ�(­ιšŽŠέ’j"ϊΆm§��Ύ«ώG«ι�’Έ?™¨θ­Ϊ&£ψ§~αΆiO•ζ¬z·švΨ^Άm§��Γ �Άμ�’Έ?–I�

maintainer
#5 lore raw

Re: [PATCH net-next v2 2/2] net: Microchip encx24j600 driver

From: David Miller <[email protected]>
Date: Mon, 05 Oct 2015 04:00:42 -0700 (PDT)

Quoted 15 lines

From: David Miller <[email protected]>
Date: Mon, 05 Oct 2015 03:54:55 -0700 (PDT)

Quoted 12 lines

From: [email protected]
Date: Thu, 1 Oct 2015 07:43:21 -0400

Quoted 9 lines

From: Jon Ringle <[email protected]>

This ethernet driver supports the Micorchip enc424j600/626j600 Ethernet controller over a SPI bus interface. This driver makes use of the regmap API to optimize access to registers by caching registers where possible.

Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39935b.pdf

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Applied.

Actually, I had to revert both patches. Please look at the compiler warnings your code generates:

Ignore me, that stuff isn't generated by your code, sorry.

author
#7 lore raw
Quoted 5 lines · David Miller

From: [email protected]
Date: Thu, 1 Oct 2015 07:43:20 -0400

Quoted 2 lines

From: Jon Ringle <[email protected]>

Quoted 7 lines
Quoted 5 lines

This commit allows installing a custom reg_update_bits function for cases where the hardware provides a mechanism to set or clear register bits without a read/modify/write cycle. Such is the case with the Microchip ENCX24J600.

Applied.

Thanks David. However, I've sent a v3 patch, and also expecting feedback from Mark Brown on the regmap portion of it.

-Jon

maintainer
#8 lore raw

From: Jon Ringle <[email protected]>
Date: Mon, 5 Oct 2015 07:57:00 -0400 (EDT)

Quoted 13 lines · David Miller
Quoted 10 lines

From: [email protected]
Date: Thu, 1 Oct 2015 07:43:20 -0400

Quoted 6 lines

From: Jon Ringle <[email protected]>

This commit allows installing a custom reg_update_bits function for cases where the hardware provides a mechanism to set or clear register bits without a read/modify/write cycle. Such is the case with the Microchip ENCX24J600.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Applied.

Thanks David. However, I've sent a v3 patch, and also expecting feedback from Mark Brown on the regmap portion of it.

Please send me relative changes from v2 to v3, thanks.

Sorry about that.

maintainer
#9 lore raw
Quoted 8 lines · David Miller
Quoted 4 lines
Quoted 1 line

Applied.

Thanks David. However, I've sent a v3 patch, and also expecting feedback from Mark Brown on the regmap portion of it.

Please send me relative changes from v2 to v3, thanks.

Sorry about that.

Ugh, this is a mess :( Can you please drop this patch instead?

maintainer
#10 lore raw

From: Mark Brown <[email protected]>
Date: Mon, 5 Oct 2015 15:25:31 +0100

Quoted 12 lines · David Miller
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Applied.

Thanks David. However, I've sent a v3 patch, and also expecting feedback from Mark Brown on the regmap portion of it.

Please send me relative changes from v2 to v3, thanks.

Sorry about that.

Ugh, this is a mess :( Can you please drop this patch instead?

I can't just "drop" changes. Once a commit hits my tree it is part of the permanent record.

The easiest thing to do is to send a relative fix, and that's why I have asked for exactly that.

maintainer
#11 lore raw
Quoted 4 lines · David Miller
Quoted 1 line

Ugh, this is a mess :( Can you please drop this patch instead?

I can't just "drop" changes. Once a commit hits my tree it is part of the permanent record.

I was expecting a revert if you want to keep the branch fast forward only.

Quoted 2 lines

The easiest thing to do is to send a relative fix, and that's why I have asked for exactly that.

This isn't very good for reviewing the API change, and of course I'd also expect this change to be in the regmap tree so we can work on regmap without collisions, I obviously can't just merge in net-next. I was thinking about making some further changes on top of this and it *is* fiddling about in the core.

Jon, please send me a patch against the regmap tree for review while we work out how to sort out this mess.

maintainer
#12 lore raw

From: Mark Brown <[email protected]>
Date: Tue, 6 Oct 2015 10:57:15 +0100

Quoted 1 line

I obviously can't just merge in net-next.

People do this all the time, when needed. My history never changes, and the networking tree is one of the first trees pulled into linux-next, so this is always safe.

maintainer
#13 lore raw
Quoted 7 lines · David Miller

Date: Tue, 6 Oct 2015 10:57:15 +0100

Quoted 1 line

I obviously can't just merge in net-next.

People do this all the time, when needed. My history never changes, and the networking tree is one of the first trees pulled into linux-next, so this is always safe.

Which would then make working with my tree annoying (I get net stuff showing up in my diffs and logs) and gets in the way for sending pull requests before Linus starts merging stuff which I tend to do.