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

2015-10-03 Thread kbuild test robot
Hi Jon,

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

config: mn10300-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
# save the attached .config to linux build tree
make.cross ARCH=mn10300 

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:272:3: warning: format 
>> '%zu' expects argument of type 'size_t', but argument 4 has type 'unsigned 
>> int' [-Wformat=]
  pr_err("%s: reg=%02x reg_size=%zu\n", __func__, reg, reg_size);
  ^
   drivers/net/ethernet/microchip/encx24j600-regmap.c:280:3: warning: format 
'%zu' expects argument of type 'size_t', but argument 4 has type 'unsigned int' 
[-Wformat=]
  pr_err("%s: reg=%02x val_size=%zu\n", __func__, reg, val_size);
  ^

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

   256  if (reg > 0xa0)
   257  return regmap_encx24j600_spi_write(context, reg, dout, 
len);
   258  
   259  if (len > 2)
   260  return -EINVAL;
   261  
   262  return regmap_encx24j600_sfr_write(context, reg, dout, len);
   263  }
   264  
   265  static int regmap_encx24j600_read(void *context,
   266const void *reg_buf, size_t reg_size,
   267void *val, size_t val_size)
   268  {
   269  u8 reg = *(const u8 *)reg_buf;
   270  
   271  if (reg_size != 1) {
 > 272  pr_err("%s: reg=%02x reg_size=%zu\n", __func__, reg, 
 > reg_size);
   273  return -EINVAL;
   274  }
   275  
   276  if (reg > 0xa0)
   277  return regmap_encx24j600_spi_read(context, reg, val, 
val_size);
   278  
   279  if (val_size > 2) {
   280  pr_err("%s: reg=%02x val_size=%zu\n", __func__, reg, 
val_size);

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


.config.gz
Description: Binary data


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

2015-10-01 Thread jon
From: Jon Ringle 

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

Signed-off-by: Jon Ringle 
---

Fixed several issues reported by kbuild bots and simplified the implementation
of regmap_encx24j600_reg_update_bits() based on changes to _regmap_update_bits

Jon

 drivers/net/ethernet/microchip/Kconfig |9 +
 drivers/net/ethernet/microchip/Makefile|1 +
 drivers/net/ethernet/microchip/encx24j600-regmap.c |  513 +
 drivers/net/ethernet/microchip/encx24j600.c| 1124 
 drivers/net/ethernet/microchip/encx24j600_hw.h |  437 
 5 files changed, 2084 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

diff --git a/drivers/net/ethernet/microchip/Kconfig 
b/drivers/net/ethernet/microchip/Kconfig
index afaf0c0..b45b28a 100644
--- a/drivers/net/ethernet/microchip/Kconfig
+++ b/drivers/net/ethernet/microchip/Kconfig
@@ -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
diff --git a/drivers/net/ethernet/microchip/Makefile 
b/drivers/net/ethernet/microchip/Makefile
index 573d429..ff78f62 100644
--- a/drivers/net/ethernet/microchip/Makefile
+++ b/drivers/net/ethernet/microchip/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_ENC28J60) += enc28j60.o
+obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o
diff --git a/drivers/net/ethernet/microchip/encx24j600-regmap.c 
b/drivers/net/ethernet/microchip/encx24j600-regmap.c
new file mode 100644
index 000..f3bb905
--- /dev/null
+++ b/drivers/net/ethernet/microchip/encx24j600-regmap.c
@@ -0,0 +1,513 @@
+/**
+ * Register map access API - ENCX24J600 support
+ *
+ * Copyright 2015 Gridpoint
+ *
+ * Author: Jon Ringle 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "encx24j600_hw.h"
+
+static inline bool is_bits_set(int value, int mask)
+{
+   return (value & mask) == mask;
+}
+
+static int encx24j600_switch_bank(struct encx24j600_context *ctx,
+int bank)
+{
+   int ret = 0;
+
+   int bank_opcode = BANK_SELECT(bank);
+   ret = spi_write(ctx->spi, &bank_opcode, 1);
+   if (ret == 0)
+   ctx->bank = bank;
+
+   return ret;
+}
+
+static int encx24j600_cmdn(struct encx24j600_context *ctx, u8 opcode,
+   const void *buf, size_t len)
+{
+   struct spi_message m;
+   struct spi_transfer t[2] = { { .tx_buf = &opcode, .len = 1, },
+{ .tx_buf = buf, .len = len }, };
+   spi_message_init(&m);
+   spi_message_add_tail(&t[0], &m);
+   spi_message_add_tail(&t[1], &m);
+
+   return spi_sync(ctx->spi, &m);
+}
+
+static void regmap_lock_mutex(void *context)
+{
+   struct encx24j600_context *ctx = context;
+   mutex_lock(&ctx->mutex);
+}
+
+static void regmap_unlock_mutex(void *context)
+{
+   struct encx24j600_context *ctx = context;
+   mutex_unlock(&ctx->mutex);
+}
+
+static int regmap_encx24j600_sfr_read(void *context, u8 reg, u8 *val,
+ size_t len)
+{
+   struct encx24j600_context *ctx = context;
+   u8 banked_reg = reg & ADDR_MASK;
+   u8 bank = ((reg & BANK_MASK) >> BANK_SHIFT);
+   u8 cmd = RCRU;
+   int ret = 0;
+   int i = 0;
+   u8 tx_buf[2];
+
+   if (reg < 0x80) {
+   cmd = RCRCODE | banked_reg;
+   if ((banked_reg < 0x16) && (ctx->bank != bank))
+   ret = encx24j600_switch_bank(ctx, bank);
+   if (unlikely(ret))
+   return ret;
+   } else {
+   /* Translate registers that are more effecient using
+* 3-byte SPI commands
+*/
+   switch (reg) {
+   case EGPRDPT:
+   cmd = RGPRDPT; break;
+   case EGPWRPT:
+   cmd = RGPWRPT; break;
+   case ERXRDPT:
+   cmd = RRXRDPT; break;
+   case ERXWRPT:
+