Skip to contentSkip to conversation

regmap: Allow installing custom reg_update_bits function

PATCH Superseded [email protected] 3 participants 9 messages Oct 1, 2015 – Oct 2, 2015

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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   | 5 +++++
 include/linux/regmap.h         | 4 ++++
 3 files changed, 12 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 +5 -0
index afaf562..ba00d62 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,10 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
 	int ret;
 	unsigned int tmp, orig;
 
+	if (map->reg_update_bits)
+		return map->reg_update_bits(map->bus_context, reg, mask, val,
+					    change, force_write);
+
 	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 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.

---
 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

Re: [PATCH 2/2] net: Microchip encx24j600 driver

config: i386-allmodconfig (attached as .config) reproduce:

Hi Jon,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: i386-allmodconfig (attached as .config)
reproduce:

        git checkout abb68976e3057f70babddaf71802ed126d0297bc
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

drivers/net/ethernet/microchip/encx24j600.c: In function 'encx24j600_spi_probe':

>> drivers/net/ethernet/microchip/encx24j600.c:1063:2: error: implicit declaration of function 'SET_ETHTOOL_OPS' [-Werror=implicit-function-declaration]
     SET_ETHTOOL_OPS(ndev, &encx24j600_ethtool_ops);
     ^

cc1: some warnings being treated as errors

vim +/SET_ETHTOOL_OPS +1063 drivers/net/ethernet/microchip/encx24j600.c

1057 goto out_free;
1058 }
1059
1060 /* Get the MAC address from the chip */
1061 encx24j600_hw_get_macaddr(priv, ndev->dev_addr);
1062

> 1063		SET_ETHTOOL_OPS(ndev, &encx24j600_ethtool_ops);

1064
1065 ret = register_netdev(ndev);
1066 if (unlikely(ret)) {

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

Re: [PATCH 2/2] net: Microchip encx24j600 driver

In reply to [email protected]
config: x86_64-allmodconfig (attached as .config) reproduce:

Hi Jon,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: x86_64-allmodconfig (attached as .config)
reproduce:

        git checkout abb68976e3057f70babddaf71802ed126d0297bc
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

In file included from include/linux/printk.h:6:0,

                    from include/linux/kernel.h:13,
                    from include/linux/delay.h:10,
                    from drivers/net/ethernet/microchip/encx24j600-regmap.c:13:
   drivers/net/ethernet/microchip/encx24j600-regmap.c: In function 'regmap_encx24j600_read':
   include/linux/kern_levels.h:4:18: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t {aka long unsigned int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/kern_levels.h:10:18: note: in expansion of macro 'KERN_SOH'
    #define KERN_ERR KERN_SOH "3" /* error conditions */
                     ^
   include/linux/printk.h:252:9: note: in expansion of macro 'KERN_ERR'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
            ^
>> drivers/net/ethernet/microchip/encx24j600-regmap.c:310:3: note: in expansion of macro 'pr_err'
      pr_err("%s: reg=%02x reg_size=%d\n", __func__, reg, reg_size);
      ^
   include/linux/kern_levels.h:4:18: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t {aka long unsigned int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/kern_levels.h:10:18: note: in expansion of macro 'KERN_SOH'
    #define KERN_ERR KERN_SOH "3" /* error conditions */
                     ^
   include/linux/printk.h:252:9: note: in expansion of macro 'KERN_ERR'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
            ^
   drivers/net/ethernet/microchip/encx24j600-regmap.c:318:3: note: in expansion of macro 'pr_err'
      pr_err("%s: reg=%02x val_size=%d\n", __func__, reg, val_size);
      ^

sparse warnings: (new ones prefixed by >>)

>> drivers/net/ethernet/microchip/encx24j600.c:775:5: sparse: symbol 'encx24j600_open' was not declared. Should it be static?
>> drivers/net/ethernet/microchip/encx24j600.c:796:5: sparse: symbol 'encx24j600_stop' was not declared. Should it be static?
>> drivers/net/ethernet/microchip/encx24j600.c:897:6: sparse: symbol 'encx24j600_tx_timeout' was not declared. Should it be static?
   drivers/net/ethernet/microchip/encx24j600.c:1063:9: sparse: undefined identifier 'SET_ETHTOOL_OPS'
   drivers/net/ethernet/microchip/encx24j600.c: In function 'encx24j600_spi_probe':
   drivers/net/ethernet/microchip/encx24j600.c:1063:2: error: implicit declaration of function 'SET_ETHTOOL_OPS' [-Werror=implicit-function-declaration]
     SET_ETHTOOL_OPS(ndev, &encx24j600_ethtool_ops);
     ^

cc1: some warnings being treated as errors

Please review and possibly fold the followup patch.

vim +/pr_err +310 drivers/net/ethernet/microchip/encx24j600-regmap.c

294 if (reg > 0xa0)
295 return regmap_encx24j600_spi_write(context, reg, dout, len);
296
297 if (len > 2)
298 return -EINVAL;
299
300 return regmap_encx24j600_sfr_write(context, reg, dout, len);
301 }
302
303 static int regmap_encx24j600_read(void *context,
304 const void *reg_buf, size_t reg_size,
305 void *val, size_t val_size)
306 {
307 u8 reg = *(const u8 *)reg_buf;
308
309 if (reg_size != 1) {

 > 310			pr_err("%s: reg=%02x reg_size=%d\n", __func__, reg, reg_size);

311 return -EINVAL;
312 }
313
314 if (reg > 0xa0)
315 return regmap_encx24j600_spi_read(context, reg, val, val_size);
316
317 if (val_size > 2) {
318 pr_err("%s: reg=%02x val_size=%d\n", __func__, reg, val_size);

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

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

In reply to [email protected]
Signed-off-by: Fengguang Wu <[email protected]>
---
 encx24j600.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/encx24j600.c +3 -3
index 27065ec..b7cb168 100644
@@ -772,7 +772,7 @@ static int encx24j600_set_mac_address(struct net_device *dev, void *addr)
 	return encx24j600_set_hw_macaddr(dev);
 }
 
-int encx24j600_open(struct net_device *dev)
+static int encx24j600_open(struct net_device *dev)
 {
 	struct encx24j600_priv *priv = netdev_priv(dev);
 
@@ -793,7 +793,7 @@ int encx24j600_open(struct net_device *dev)
 	return 0;
 }
 
-int encx24j600_stop(struct net_device *dev)
+static int encx24j600_stop(struct net_device *dev)
 {
 	struct encx24j600_priv *priv = netdev_priv(dev);
 
@@ -894,7 +894,7 @@ static netdev_tx_t encx24j600_tx(struct sk_buff *skb, struct net_device *dev)
 }
 
 /* Deal with a transmit timeout */
-void encx24j600_tx_timeout(struct net_device *dev)
+static void encx24j600_tx_timeout(struct net_device *dev)
 {
 	struct encx24j600_priv *priv = netdev_priv(dev);
 
#5 lore raw

Re: [PATCH 2/2] net: Microchip encx24j600 driver

In reply to [email protected]
config: sparc-allmodconfig (attached as .config) reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross…

Hi Jon,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

config: sparc-allmodconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
git checkout abb68976e3057f70babddaf71802ed126d0297bc
# save the attached .config to linux build tree
make.cross ARCH=sparc

All warnings (new ones prefixed by >>):

drivers/net/ethernet/microchip/encx24j600-regmap.c: In function 'regmap_encx24j600_read':

>> drivers/net/ethernet/microchip/encx24j600-regmap.c:310:3: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t' [-Wformat=]
      pr_err("%s: reg=%02x reg_size=%d\n", __func__, reg, reg_size);
      ^
   drivers/net/ethernet/microchip/encx24j600-regmap.c:318:3: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t' [-Wformat=]
      pr_err("%s: reg=%02x val_size=%d\n", __func__, reg, val_size);
      ^

vim +310 drivers/net/ethernet/microchip/encx24j600-regmap.c

294 if (reg > 0xa0)
295 return regmap_encx24j600_spi_write(context, reg, dout, len);
296
297 if (len > 2)
298 return -EINVAL;
299
300 return regmap_encx24j600_sfr_write(context, reg, dout, len);
301 }
302
303 static int regmap_encx24j600_read(void *context,
304 const void *reg_buf, size_t reg_size,
305 void *val, size_t val_size)
306 {
307 u8 reg = *(const u8 *)reg_buf;
308
309 if (reg_size != 1) {

 > 310			pr_err("%s: reg=%02x reg_size=%d\n", __func__, reg, reg_size);

311 return -EINVAL;
312 }
313
314 if (reg > 0xa0)
315 return regmap_encx24j600_spi_read(context, reg, val, val_size);
316
317 if (val_size > 2) {
318 pr_err("%s: reg=%02x val_size=%d\n", __func__, reg, val_size);

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

maintainer
#6 lore raw
In reply to [email protected]

drivers/base/regmap/regmap.c static int _regmap_update_bits(struct regmap *map, unsigned int reg, · line 2519

Quoted 11 lines · On Thu, Oct 01, 2015 at 02:33:06AM -0400, [email protected] wrote:
drivers/base/regmap/regmap.c +4 -0
@@ -2509,6 +2510,10 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
 	int ret;
 	unsigned int tmp, orig;
 
+	if (map->reg_update_bits)
+		return map->reg_update_bits(map->bus_context, reg, mask, val,
+					    change, force_write);
+
 	ret = _regmap_read(map, reg, &orig);
 	if (ret != 0)
 		return ret;

This completely bypasses and therefore breaks the cache infrastructure.

author
#7 lore raw
Quoted 6 lines · Mark Brown
Quoted 4 lines · On Thu, Oct 01, 2015 at 02:33:06AM -0400, [email protected] wrote:
drivers/base/regmap/regmap.c +0 -0
@@ -2509,6 +2510,10 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
 	int ret;
 	unsigned int tmp, orig;
 
Quoted 10 lines

drivers/base/regmap/regmap.c static int _regmap_update_bits(struct regmap *map, unsigned int reg, · line 2519

Quoted 7 lines
drivers/base/regmap/regmap.c +4 -0
+	if (map->reg_update_bits)
+		return map->reg_update_bits(map->bus_context, reg, mask, val,
+					    change, force_write);
+
 	ret = _regmap_read(map, reg, &orig);
 	if (ret != 0)
 		return ret;

This completely bypasses and therefore breaks the cache infrastructure.

Hi Mark,

Right after sending the v2 patch, I realized that calling the custom reg_update_bits would only be applicable for registers that are marked as volatile. Would the following solution be acceptable (it would also simplify the regmap_update_bits in the encx24j600 driver):

	if (regmap_volatile(map, reg) && map->reg_update_bits) {
		return map->reg_update_bits(map->bus_context, reg, mask, 
		                            val, change, force_write);

The cache state should not matter for volatile registers, right?

-Jon

maintainer
#8 lore raw
Quoted 7 lines · Jon Ringle
Quoted 1 line · Mark Brown

This completely bypasses and therefore breaks the cache infrastructure.

Right after sending the v2 patch, I realized that calling the custom reg_update_bits would only be applicable for registers that are marked as volatile. Would the following solution be acceptable (it would

Well, it should still *work* with a cache, though it's certainly true that it's unlikely to have any performance benefit with cached register since the read part of the read/modify/write cycle is essentially free with the cache.

Quoted 7 lines

also simplify the regmap_update_bits in the encx24j600 driver):

	if (regmap_volatile(map, reg) && map->reg_update_bits) {
		return map->reg_update_bits(map->bus_context, reg, mask, 
		                            val, change, force_write);

The cache state should not matter for volatile registers, right?

Right. I see you've sent a new patch already, I'll reply to that after I've thought about it a little.