linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version
@ 2018-06-11 14:26 Andrea Greco
  2018-06-11 16:15 ` kbuild test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andrea Greco @ 2018-06-11 14:26 UTC (permalink / raw)
  To: davem; +Cc: tobin, Andrea Greco, Michael Grzeschik, linux-kernel, netdev

From: Andrea Greco <a.greco@4sigma.it>

Add support for com20022I/com20020, io mapped.

Signed-off-by: Andrea Greco <a.greco@4sigma.it>
---
 drivers/net/arcnet/Kconfig       |   9 +-
 drivers/net/arcnet/Makefile      |   1 +
 drivers/net/arcnet/com20020-io.c | 315 +++++++++++++++++++++++++++++++++++++++
 drivers/net/arcnet/com20020.c    |   5 +-
 4 files changed, 327 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/arcnet/com20020-io.c

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index afc5898e7a16..f72620dc63ec 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-	depends on NETDEVICES && (ISA || PCI || PCMCIA)
+	depends on NETDEVICES
 	tristate "ARCnet support"
 	---help---
 	  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,12 @@ config ARCNET_COM20020_CS
 
 	  To compile this driver as a module, choose M here: the module will be
 	  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_IO
+	tristate "Support for COM20020 (IO mapped)"
+	depends on ARCNET_COM20020
+	help
+	  Say Y here if your custom board mount com20020 chipset or friends.
+	  Supported Chipset: com20020, com20022, com20022I-3v3
+	  If unsure, say N.
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..18da4341f404 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_IO) += com20020-io.o
diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
new file mode 100644
index 000000000000..23c24d4de5a9
--- /dev/null
+++ b/drivers/net/arcnet/com20020-io.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Linux ARCnet driver for com 20020.
+ *
+ * datasheet:
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/200223vrevc.pdf
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/20020.pdf
+ *
+ * Supported chip version:
+ * - com20020
+ * - com20022
+ * - com20022I-3v3
+ */
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/of_address.h>
+#include <linux/of_gpio.h>
+#include <linux/sizes.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include "arcdevice.h"
+#include "com20020.h"
+
+/* Reset (5 * xTalFreq), minimal com20020 xTal is 10Mhz */
+#define RESET_DELAY 500
+
+static unsigned int io_arc_inb(int addr, int offset)
+{
+	return ioread8((void *__iomem) addr + offset);
+}
+
+static void io_arc_outb(int value, int addr, int offset)
+{
+	iowrite8(value, (void *__iomem)addr + offset);
+}
+
+static void io_arc_insb(int  addr, int offset, void *buffer, int count)
+{
+	ioread8_rep((void *__iomem) (addr + offset), buffer, count);
+}
+
+static void io_arc_outsb(int addr, int offset, void *buffer, int count)
+{
+	iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
+}
+
+enum com20020_xtal_freq {
+	freq_10Mhz = 10,
+	freq_20Mhz = 20,
+};
+
+enum com20020_arcnet_speed {
+	arc_speed_10M_bps = 10000000,
+	arc_speed_5M_bps = 5000000,
+	arc_speed_2M50_bps = 2500000,
+	arc_speed_1M25_bps = 1250000,
+	arc_speed_625K_bps = 625000,
+	arc_speed_312K5_bps = 312500,
+	arc_speed_156K25_bps = 156250,
+};
+
+enum com20020_timeout {
+	arc_timeout_328us =   328000,
+	arc_timeout_164us = 164000,
+	arc_timeout_82us =  82000,
+	arc_timeout_20u5s =  20500,
+};
+
+static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
+{
+	int pll_factor, req_clock_frq = 20;
+
+	switch (arcnet_speed) {
+	case arc_speed_10M_bps:
+		req_clock_frq = 80;
+		*clockp = 0;
+		break;
+	case arc_speed_5M_bps:
+		req_clock_frq = 40;
+		*clockp = 0;
+		break;
+	case arc_speed_2M50_bps:
+		*clockp = 0;
+		break;
+	case arc_speed_1M25_bps:
+		*clockp = 1;
+		break;
+	case arc_speed_625K_bps:
+		*clockp = 2;
+		break;
+	case arc_speed_312K5_bps:
+		*clockp = 3;
+		break;
+	case arc_speed_156K25_bps:
+		*clockp = 4;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (xtal != freq_10Mhz && xtal != freq_20Mhz)
+		return -EINVAL;
+
+	pll_factor = (unsigned int)req_clock_frq / xtal;
+
+	switch (pll_factor) {
+	case 1:
+		*clockm = 0;
+		break;
+	case 2:
+		*clockm = 1;
+		break;
+	case 4:
+		*clockm = 3;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int setup_timeout(int *timeout)
+{
+	switch (*timeout) {
+	case arc_timeout_328us:
+		*timeout = 0;
+		break;
+	case arc_timeout_164us:
+		*timeout = 1;
+		break;
+	case arc_timeout_82us:
+		*timeout = 2;
+		break;
+	case arc_timeout_20u5s:
+		*timeout = 3;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int com20020_probe(struct platform_device *pdev)
+{
+	struct device_node *np;
+	struct net_device *dev;
+	struct arcnet_local *lp;
+	struct resource res, *iores;
+	int ret, phy_reset;
+	u32 timeout, xtal, arc_speed;
+	int clockp, clockm;
+	bool backplane = false;
+	int ioaddr;
+
+	np = pdev->dev.of_node;
+
+	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret)
+		return ret;
+
+	ret = of_property_read_u32(np, "timeout-ns", &timeout);
+	if (ret) {
+		dev_err(&pdev->dev, "timeout is required param");
+		return ret;
+	}
+
+	ret = of_property_read_u32(np, "smsc,xtal-mhz", &xtal);
+	if (ret) {
+		dev_err(&pdev->dev, "xtal-mhz is required param");
+		return ret;
+	}
+
+	ret = of_property_read_u32(np, "bus-speed-bps", &arc_speed);
+	if (ret) {
+		dev_err(&pdev->dev, "Bus speed is required param");
+		return ret;
+	}
+
+	if (of_property_read_bool(np, "smsc,backplane-enabled"))
+		backplane = true;
+
+	phy_reset = of_get_named_gpio(np, "reset-gpios", 0);
+	if (!gpio_is_valid(phy_reset)) {
+		dev_err(&pdev->dev, "reset gpio not valid");
+		return phy_reset;
+	}
+
+	ret = devm_gpio_request_one(&pdev->dev, phy_reset, GPIOF_OUT_INIT_LOW,
+				    "arcnet-reset");
+	if (ret) {
+		dev_err(&pdev->dev, "failed to get phy reset gpio: %d\n", ret);
+		return ret;
+	}
+
+	dev = alloc_arcdev(NULL);
+	dev->netdev_ops = &com20020_netdev_ops;
+	lp = netdev_priv(dev);
+
+	lp->card_flags = ARC_CAN_10MBIT;
+
+	/* Peak random address,
+	 * if required user could set a new-one in userspace
+	 */
+	get_random_bytes(dev->dev_addr, dev->addr_len);
+
+	if (!devm_request_mem_region(&pdev->dev, res.start, resource_size(&res),
+				     lp->card_name))
+		return -EBUSY;
+
+	ioaddr = (int)devm_ioremap(&pdev->dev, iores->start,
+				 resource_size(iores));
+	if (!ioaddr) {
+		dev_err(&pdev->dev, "ioremap fallied\n");
+		return -ENOMEM;
+	}
+
+	gpio_set_value_cansleep(phy_reset, 0);
+	ndelay(RESET_DELAY);
+	gpio_set_value_cansleep(phy_reset, 1);
+
+	lp->hw.arc_inb = io_arc_inb;
+	lp->hw.arc_outb = io_arc_outb;
+	lp->hw.arc_insb = io_arc_insb;
+	lp->hw.arc_outsb = io_arc_outsb;
+
+	/* ARCNET controller needs this access to detect bustype */
+	lp->hw.arc_outb(0x00, ioaddr, COM20020_REG_W_COMMAND);
+	lp->hw.arc_inb(ioaddr, COM20020_REG_R_DIAGSTAT);
+
+	dev->base_addr = (unsigned long)ioaddr;
+
+	dev->irq = of_get_named_gpio(np, "interrupts", 0);
+	if (dev->irq == -EPROBE_DEFER) {
+		return dev->irq;
+	} else if (!gpio_is_valid(dev->irq)) {
+		dev_err(&pdev->dev, "irq-gpios not valid !");
+		return -EIO;
+	}
+	dev->irq = gpio_to_irq(dev->irq);
+
+	ret = setup_clock(&clockp, &clockm, xtal, arc_speed);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Impossible use oscillator:%dMhz and arcnet bus speed:%dKbps",
+			xtal, arc_speed / 1000);
+		return ret;
+	}
+
+	ret = setup_timeout(&timeout);
+	if (ret) {
+		dev_err(&pdev->dev, "Timeout:%d is not valid value", timeout);
+		return ret;
+	}
+
+	lp->backplane = (int)backplane;
+	lp->timeout = timeout;
+	lp->clockm = clockm;
+	lp->clockp = clockp;
+	lp->hw.owner = THIS_MODULE;
+
+	if (lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
+		ret = -EIO;
+		goto err_release_mem;
+	}
+
+	if (com20020_check(dev)) {
+		ret = -EIO;
+		goto err_release_mem;
+	}
+
+	ret = com20020_found(dev, IRQF_TRIGGER_FALLING);
+	if (ret)
+		goto err_release_mem;
+
+	dev_dbg(&pdev->dev, "probe Done\n");
+	return 0;
+
+err_release_mem:
+	devm_iounmap(&pdev->dev, (void __iomem *)ioaddr);
+	devm_release_mem_region(&pdev->dev, res.start, resource_size(&res));
+	dev_err(&pdev->dev, "probe failed!\n");
+	return ret;
+}
+
+static const struct of_device_id of_com20020_match[] = {
+	{ .compatible = "smsc,com20020",	},
+	{ },
+};
+
+MODULE_DEVICE_TABLE(of, of_com20020_match);
+
+static struct platform_driver of_com20020_driver = {
+	.driver			= {
+		.name		= "com20020-memory-bus",
+		.of_match_table = of_com20020_match,
+	},
+	.probe			= com20020_probe,
+};
+
+static int com20020_init(void)
+{
+	return platform_driver_register(&of_com20020_driver);
+}
+late_initcall(com20020_init);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index cbcea7834378..8d979a66d8e9 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -43,7 +43,7 @@
 #include "com20020.h"
 
 static const char * const clockrates[] = {
-	"XXXXXXX", "XXXXXXXX", "XXXXXX", "2.5 Mb/s",
+	"10 Mb/s", "XXXXXXXX", "XXXXXX", "2.5 Mb/s",
 	"1.25Mb/s", "625 Kb/s", "312.5 Kb/s", "156.25 Kb/s",
 	"Reserved", "Reserved", "Reserved"
 };
@@ -429,7 +429,8 @@ static void com20020_set_mc_list(struct net_device *dev)
 
 #if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \
     defined(CONFIG_ARCNET_COM20020_ISA_MODULE) || \
-    defined(CONFIG_ARCNET_COM20020_CS_MODULE)
+    defined(CONFIG_ARCNET_COM20020_CS_MODULE)  || \
+    defined(CONFIG_ARCNET_COM20020_IO)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
-- 
2.14.4

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

* Re: [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version
  2018-06-11 14:26 [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version Andrea Greco
@ 2018-06-11 16:15 ` kbuild test robot
  2018-06-11 16:35 ` kbuild test robot
  2018-06-22  8:11 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2018-06-11 16:15 UTC (permalink / raw)
  To: Andrea Greco
  Cc: kbuild-all, davem, tobin, Andrea Greco, Michael Grzeschik,
	linux-kernel, netdev

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

Hi Andrea,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.17 next-20180608]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andrea-Greco/arcnet-leds-Removed-leds-dependecy/20180611-222941
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=sparc64 

All warnings (new ones prefixed by >>):

   drivers/net//arcnet/com20020-io.c: In function 'io_arc_inb':
>> drivers/net//arcnet/com20020-io.c:34:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     return ioread8((void *__iomem) addr + offset);
                    ^
   drivers/net//arcnet/com20020-io.c: In function 'io_arc_outb':
   drivers/net//arcnet/com20020-io.c:39:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     iowrite8(value, (void *__iomem)addr + offset);
                     ^
   drivers/net//arcnet/com20020-io.c: In function 'io_arc_insb':
   drivers/net//arcnet/com20020-io.c:44:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ioread8_rep((void *__iomem) (addr + offset), buffer, count);
                 ^
   drivers/net//arcnet/com20020-io.c: In function 'io_arc_outsb':
   drivers/net//arcnet/com20020-io.c:49:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
                  ^
   drivers/net//arcnet/com20020-io.c: In function 'com20020_probe':
>> drivers/net//arcnet/com20020-io.c:219:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     ioaddr = (int)devm_ioremap(&pdev->dev, iores->start,
              ^
   drivers/net//arcnet/com20020-io.c:288:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     devm_iounmap(&pdev->dev, (void __iomem *)ioaddr);
                              ^

vim +34 drivers/net//arcnet/com20020-io.c

    31	
    32	static unsigned int io_arc_inb(int addr, int offset)
    33	{
  > 34		return ioread8((void *__iomem) addr + offset);
    35	}
    36	
    37	static void io_arc_outb(int value, int addr, int offset)
    38	{
    39		iowrite8(value, (void *__iomem)addr + offset);
    40	}
    41	
    42	static void io_arc_insb(int  addr, int offset, void *buffer, int count)
    43	{
  > 44		ioread8_rep((void *__iomem) (addr + offset), buffer, count);
    45	}
    46	
    47	static void io_arc_outsb(int addr, int offset, void *buffer, int count)
    48	{
    49		iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
    50	}
    51	
    52	enum com20020_xtal_freq {
    53		freq_10Mhz = 10,
    54		freq_20Mhz = 20,
    55	};
    56	
    57	enum com20020_arcnet_speed {
    58		arc_speed_10M_bps = 10000000,
    59		arc_speed_5M_bps = 5000000,
    60		arc_speed_2M50_bps = 2500000,
    61		arc_speed_1M25_bps = 1250000,
    62		arc_speed_625K_bps = 625000,
    63		arc_speed_312K5_bps = 312500,
    64		arc_speed_156K25_bps = 156250,
    65	};
    66	
    67	enum com20020_timeout {
    68		arc_timeout_328us =   328000,
    69		arc_timeout_164us = 164000,
    70		arc_timeout_82us =  82000,
    71		arc_timeout_20u5s =  20500,
    72	};
    73	
    74	static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
    75	{
    76		int pll_factor, req_clock_frq = 20;
    77	
    78		switch (arcnet_speed) {
    79		case arc_speed_10M_bps:
    80			req_clock_frq = 80;
    81			*clockp = 0;
    82			break;
    83		case arc_speed_5M_bps:
    84			req_clock_frq = 40;
    85			*clockp = 0;
    86			break;
    87		case arc_speed_2M50_bps:
    88			*clockp = 0;
    89			break;
    90		case arc_speed_1M25_bps:
    91			*clockp = 1;
    92			break;
    93		case arc_speed_625K_bps:
    94			*clockp = 2;
    95			break;
    96		case arc_speed_312K5_bps:
    97			*clockp = 3;
    98			break;
    99		case arc_speed_156K25_bps:
   100			*clockp = 4;
   101			break;
   102		default:
   103			return -EINVAL;
   104		}
   105	
   106		if (xtal != freq_10Mhz && xtal != freq_20Mhz)
   107			return -EINVAL;
   108	
   109		pll_factor = (unsigned int)req_clock_frq / xtal;
   110	
   111		switch (pll_factor) {
   112		case 1:
   113			*clockm = 0;
   114			break;
   115		case 2:
   116			*clockm = 1;
   117			break;
   118		case 4:
   119			*clockm = 3;
   120			break;
   121		default:
   122			return -EINVAL;
   123		}
   124	
   125		return 0;
   126	}
   127	
   128	static int setup_timeout(int *timeout)
   129	{
   130		switch (*timeout) {
   131		case arc_timeout_328us:
   132			*timeout = 0;
   133			break;
   134		case arc_timeout_164us:
   135			*timeout = 1;
   136			break;
   137		case arc_timeout_82us:
   138			*timeout = 2;
   139			break;
   140		case arc_timeout_20u5s:
   141			*timeout = 3;
   142			break;
   143		default:
   144			return -EINVAL;
   145		}
   146	
   147		return 0;
   148	}
   149	
   150	static int com20020_probe(struct platform_device *pdev)
   151	{
   152		struct device_node *np;
   153		struct net_device *dev;
   154		struct arcnet_local *lp;
   155		struct resource res, *iores;
   156		int ret, phy_reset;
   157		u32 timeout, xtal, arc_speed;
   158		int clockp, clockm;
   159		bool backplane = false;
   160		int ioaddr;
   161	
   162		np = pdev->dev.of_node;
   163	
   164		iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   165	
   166		ret = of_address_to_resource(np, 0, &res);
   167		if (ret)
   168			return ret;
   169	
   170		ret = of_property_read_u32(np, "timeout-ns", &timeout);
   171		if (ret) {
   172			dev_err(&pdev->dev, "timeout is required param");
   173			return ret;
   174		}
   175	
   176		ret = of_property_read_u32(np, "smsc,xtal-mhz", &xtal);
   177		if (ret) {
   178			dev_err(&pdev->dev, "xtal-mhz is required param");
   179			return ret;
   180		}
   181	
   182		ret = of_property_read_u32(np, "bus-speed-bps", &arc_speed);
   183		if (ret) {
   184			dev_err(&pdev->dev, "Bus speed is required param");
   185			return ret;
   186		}
   187	
   188		if (of_property_read_bool(np, "smsc,backplane-enabled"))
   189			backplane = true;
   190	
   191		phy_reset = of_get_named_gpio(np, "reset-gpios", 0);
   192		if (!gpio_is_valid(phy_reset)) {
   193			dev_err(&pdev->dev, "reset gpio not valid");
   194			return phy_reset;
   195		}
   196	
   197		ret = devm_gpio_request_one(&pdev->dev, phy_reset, GPIOF_OUT_INIT_LOW,
   198					    "arcnet-reset");
   199		if (ret) {
   200			dev_err(&pdev->dev, "failed to get phy reset gpio: %d\n", ret);
   201			return ret;
   202		}
   203	
   204		dev = alloc_arcdev(NULL);
   205		dev->netdev_ops = &com20020_netdev_ops;
   206		lp = netdev_priv(dev);
   207	
   208		lp->card_flags = ARC_CAN_10MBIT;
   209	
   210		/* Peak random address,
   211		 * if required user could set a new-one in userspace
   212		 */
   213		get_random_bytes(dev->dev_addr, dev->addr_len);
   214	
   215		if (!devm_request_mem_region(&pdev->dev, res.start, resource_size(&res),
   216					     lp->card_name))
   217			return -EBUSY;
   218	
 > 219		ioaddr = (int)devm_ioremap(&pdev->dev, iores->start,
   220					 resource_size(iores));
   221		if (!ioaddr) {
   222			dev_err(&pdev->dev, "ioremap fallied\n");
   223			return -ENOMEM;
   224		}
   225	
   226		gpio_set_value_cansleep(phy_reset, 0);
   227		ndelay(RESET_DELAY);
   228		gpio_set_value_cansleep(phy_reset, 1);
   229	
   230		lp->hw.arc_inb = io_arc_inb;
   231		lp->hw.arc_outb = io_arc_outb;
   232		lp->hw.arc_insb = io_arc_insb;
   233		lp->hw.arc_outsb = io_arc_outsb;
   234	
   235		/* ARCNET controller needs this access to detect bustype */
   236		lp->hw.arc_outb(0x00, ioaddr, COM20020_REG_W_COMMAND);
   237		lp->hw.arc_inb(ioaddr, COM20020_REG_R_DIAGSTAT);
   238	
   239		dev->base_addr = (unsigned long)ioaddr;
   240	
   241		dev->irq = of_get_named_gpio(np, "interrupts", 0);
   242		if (dev->irq == -EPROBE_DEFER) {
   243			return dev->irq;
   244		} else if (!gpio_is_valid(dev->irq)) {
   245			dev_err(&pdev->dev, "irq-gpios not valid !");
   246			return -EIO;
   247		}
   248		dev->irq = gpio_to_irq(dev->irq);
   249	
   250		ret = setup_clock(&clockp, &clockm, xtal, arc_speed);
   251		if (ret) {
   252			dev_err(&pdev->dev,
   253				"Impossible use oscillator:%dMhz and arcnet bus speed:%dKbps",
   254				xtal, arc_speed / 1000);
   255			return ret;
   256		}
   257	
   258		ret = setup_timeout(&timeout);
   259		if (ret) {
   260			dev_err(&pdev->dev, "Timeout:%d is not valid value", timeout);
   261			return ret;
   262		}
   263	
   264		lp->backplane = (int)backplane;
   265		lp->timeout = timeout;
   266		lp->clockm = clockm;
   267		lp->clockp = clockp;
   268		lp->hw.owner = THIS_MODULE;
   269	
   270		if (lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
   271			ret = -EIO;
   272			goto err_release_mem;
   273		}
   274	
   275		if (com20020_check(dev)) {
   276			ret = -EIO;
   277			goto err_release_mem;
   278		}
   279	
   280		ret = com20020_found(dev, IRQF_TRIGGER_FALLING);
   281		if (ret)
   282			goto err_release_mem;
   283	
   284		dev_dbg(&pdev->dev, "probe Done\n");
   285		return 0;
   286	
   287	err_release_mem:
   288		devm_iounmap(&pdev->dev, (void __iomem *)ioaddr);
   289		devm_release_mem_region(&pdev->dev, res.start, resource_size(&res));
   290		dev_err(&pdev->dev, "probe failed!\n");
   291		return ret;
   292	}
   293	

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 54207 bytes --]

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

* Re: [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version
  2018-06-11 14:26 [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version Andrea Greco
  2018-06-11 16:15 ` kbuild test robot
@ 2018-06-11 16:35 ` kbuild test robot
  2018-06-18 12:51   ` Andrea Greco
  2018-06-22  8:11 ` kbuild test robot
  2 siblings, 1 reply; 5+ messages in thread
From: kbuild test robot @ 2018-06-11 16:35 UTC (permalink / raw)
  To: Andrea Greco
  Cc: kbuild-all, davem, tobin, Andrea Greco, Michael Grzeschik,
	linux-kernel, netdev

Hi Andrea,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.17 next-20180608]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andrea-Greco/arcnet-leds-Removed-leds-dependecy/20180611-222941
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/net/arcnet/com20020-io.c:34:45: sparse: incorrect type in argument 1 (different address spaces) @@    expected void [noderef] <asn:2>*<noident> @@    got sn:2>*<noident> @@
   drivers/net/arcnet/com20020-io.c:34:45:    expected void [noderef] <asn:2>*<noident>
   drivers/net/arcnet/com20020-io.c:34:45:    got void *
   drivers/net/arcnet/com20020-io.c:39:45: sparse: incorrect type in argument 2 (different address spaces) @@    expected void [noderef] <asn:2>*<noident> @@    got sn:2>*<noident> @@
   drivers/net/arcnet/com20020-io.c:39:45:    expected void [noderef] <asn:2>*<noident>
   drivers/net/arcnet/com20020-io.c:39:45:    got void *
>> drivers/net/arcnet/com20020-io.c:44:22: sparse: incorrect type in argument 1 (different address spaces) @@    expected void [noderef] <asn:2>*port @@    got void [noderef] <asn:2>*port @@
   drivers/net/arcnet/com20020-io.c:44:22:    expected void [noderef] <asn:2>*port
   drivers/net/arcnet/com20020-io.c:44:22:    got void *[noderef] <asn:2><noident>
   drivers/net/arcnet/com20020-io.c:49:23: sparse: incorrect type in argument 1 (different address spaces) @@    expected void [noderef] <asn:2>*port @@    got void [noderef] <asn:2>*port @@
   drivers/net/arcnet/com20020-io.c:49:23:    expected void [noderef] <asn:2>*port
   drivers/net/arcnet/com20020-io.c:49:23:    got void *[noderef] <asn:2><noident>
>> drivers/net/arcnet/com20020-io.c:219:19: sparse: cast removes address space of expression
   drivers/net/arcnet/com20020-io.c: In function 'io_arc_inb':
   drivers/net/arcnet/com20020-io.c:34:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     return ioread8((void *__iomem) addr + offset);
                    ^
   drivers/net/arcnet/com20020-io.c: In function 'io_arc_outb':
   drivers/net/arcnet/com20020-io.c:39:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     iowrite8(value, (void *__iomem)addr + offset);
                     ^
   drivers/net/arcnet/com20020-io.c: In function 'io_arc_insb':
   drivers/net/arcnet/com20020-io.c:44:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ioread8_rep((void *__iomem) (addr + offset), buffer, count);
                 ^
   drivers/net/arcnet/com20020-io.c: In function 'io_arc_outsb':
   drivers/net/arcnet/com20020-io.c:49:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
                  ^
   drivers/net/arcnet/com20020-io.c: In function 'com20020_probe':
   drivers/net/arcnet/com20020-io.c:219:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     ioaddr = (int)devm_ioremap(&pdev->dev, iores->start,
              ^
   drivers/net/arcnet/com20020-io.c:288:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     devm_iounmap(&pdev->dev, (void __iomem *)ioaddr);
                              ^

vim +34 drivers/net/arcnet/com20020-io.c

    31	
    32	static unsigned int io_arc_inb(int addr, int offset)
    33	{
  > 34		return ioread8((void *__iomem) addr + offset);
    35	}
    36	
    37	static void io_arc_outb(int value, int addr, int offset)
    38	{
  > 39		iowrite8(value, (void *__iomem)addr + offset);
    40	}
    41	
    42	static void io_arc_insb(int  addr, int offset, void *buffer, int count)
    43	{
  > 44		ioread8_rep((void *__iomem) (addr + offset), buffer, count);
    45	}
    46	
    47	static void io_arc_outsb(int addr, int offset, void *buffer, int count)
    48	{
    49		iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
    50	}
    51	
    52	enum com20020_xtal_freq {
    53		freq_10Mhz = 10,
    54		freq_20Mhz = 20,
    55	};
    56	
    57	enum com20020_arcnet_speed {
    58		arc_speed_10M_bps = 10000000,
    59		arc_speed_5M_bps = 5000000,
    60		arc_speed_2M50_bps = 2500000,
    61		arc_speed_1M25_bps = 1250000,
    62		arc_speed_625K_bps = 625000,
    63		arc_speed_312K5_bps = 312500,
    64		arc_speed_156K25_bps = 156250,
    65	};
    66	
    67	enum com20020_timeout {
    68		arc_timeout_328us =   328000,
    69		arc_timeout_164us = 164000,
    70		arc_timeout_82us =  82000,
    71		arc_timeout_20u5s =  20500,
    72	};
    73	
    74	static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
    75	{
    76		int pll_factor, req_clock_frq = 20;
    77	
    78		switch (arcnet_speed) {
    79		case arc_speed_10M_bps:
    80			req_clock_frq = 80;
    81			*clockp = 0;
    82			break;
    83		case arc_speed_5M_bps:
    84			req_clock_frq = 40;
    85			*clockp = 0;
    86			break;
    87		case arc_speed_2M50_bps:
    88			*clockp = 0;
    89			break;
    90		case arc_speed_1M25_bps:
    91			*clockp = 1;
    92			break;
    93		case arc_speed_625K_bps:
    94			*clockp = 2;
    95			break;
    96		case arc_speed_312K5_bps:
    97			*clockp = 3;
    98			break;
    99		case arc_speed_156K25_bps:
   100			*clockp = 4;
   101			break;
   102		default:
   103			return -EINVAL;
   104		}
   105	
   106		if (xtal != freq_10Mhz && xtal != freq_20Mhz)
   107			return -EINVAL;
   108	
   109		pll_factor = (unsigned int)req_clock_frq / xtal;
   110	
   111		switch (pll_factor) {
   112		case 1:
   113			*clockm = 0;
   114			break;
   115		case 2:
   116			*clockm = 1;
   117			break;
   118		case 4:
   119			*clockm = 3;
   120			break;
   121		default:
   122			return -EINVAL;
   123		}
   124	
   125		return 0;
   126	}
   127	
   128	static int setup_timeout(int *timeout)
   129	{
   130		switch (*timeout) {
   131		case arc_timeout_328us:
   132			*timeout = 0;
   133			break;
   134		case arc_timeout_164us:
   135			*timeout = 1;
   136			break;
   137		case arc_timeout_82us:
   138			*timeout = 2;
   139			break;
   140		case arc_timeout_20u5s:
   141			*timeout = 3;
   142			break;
   143		default:
   144			return -EINVAL;
   145		}
   146	
   147		return 0;
   148	}
   149	
   150	static int com20020_probe(struct platform_device *pdev)
   151	{
   152		struct device_node *np;
   153		struct net_device *dev;
   154		struct arcnet_local *lp;
   155		struct resource res, *iores;
   156		int ret, phy_reset;
   157		u32 timeout, xtal, arc_speed;
   158		int clockp, clockm;
   159		bool backplane = false;
   160		int ioaddr;
   161	
   162		np = pdev->dev.of_node;
   163	
   164		iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   165	
   166		ret = of_address_to_resource(np, 0, &res);
   167		if (ret)
   168			return ret;
   169	
   170		ret = of_property_read_u32(np, "timeout-ns", &timeout);
   171		if (ret) {
   172			dev_err(&pdev->dev, "timeout is required param");
   173			return ret;
   174		}
   175	
   176		ret = of_property_read_u32(np, "smsc,xtal-mhz", &xtal);
   177		if (ret) {
   178			dev_err(&pdev->dev, "xtal-mhz is required param");
   179			return ret;
   180		}
   181	
   182		ret = of_property_read_u32(np, "bus-speed-bps", &arc_speed);
   183		if (ret) {
   184			dev_err(&pdev->dev, "Bus speed is required param");
   185			return ret;
   186		}
   187	
   188		if (of_property_read_bool(np, "smsc,backplane-enabled"))
   189			backplane = true;
   190	
   191		phy_reset = of_get_named_gpio(np, "reset-gpios", 0);
   192		if (!gpio_is_valid(phy_reset)) {
   193			dev_err(&pdev->dev, "reset gpio not valid");
   194			return phy_reset;
   195		}
   196	
   197		ret = devm_gpio_request_one(&pdev->dev, phy_reset, GPIOF_OUT_INIT_LOW,
   198					    "arcnet-reset");
   199		if (ret) {
   200			dev_err(&pdev->dev, "failed to get phy reset gpio: %d\n", ret);
   201			return ret;
   202		}
   203	
   204		dev = alloc_arcdev(NULL);
   205		dev->netdev_ops = &com20020_netdev_ops;
   206		lp = netdev_priv(dev);
   207	
   208		lp->card_flags = ARC_CAN_10MBIT;
   209	
   210		/* Peak random address,
   211		 * if required user could set a new-one in userspace
   212		 */
   213		get_random_bytes(dev->dev_addr, dev->addr_len);
   214	
   215		if (!devm_request_mem_region(&pdev->dev, res.start, resource_size(&res),
   216					     lp->card_name))
   217			return -EBUSY;
   218	
 > 219		ioaddr = (int)devm_ioremap(&pdev->dev, iores->start,
   220					 resource_size(iores));
   221		if (!ioaddr) {
   222			dev_err(&pdev->dev, "ioremap fallied\n");
   223			return -ENOMEM;
   224		}
   225	
   226		gpio_set_value_cansleep(phy_reset, 0);
   227		ndelay(RESET_DELAY);
   228		gpio_set_value_cansleep(phy_reset, 1);
   229	
   230		lp->hw.arc_inb = io_arc_inb;
   231		lp->hw.arc_outb = io_arc_outb;
   232		lp->hw.arc_insb = io_arc_insb;
   233		lp->hw.arc_outsb = io_arc_outsb;
   234	
   235		/* ARCNET controller needs this access to detect bustype */
   236		lp->hw.arc_outb(0x00, ioaddr, COM20020_REG_W_COMMAND);
   237		lp->hw.arc_inb(ioaddr, COM20020_REG_R_DIAGSTAT);
   238	
   239		dev->base_addr = (unsigned long)ioaddr;
   240	
   241		dev->irq = of_get_named_gpio(np, "interrupts", 0);
   242		if (dev->irq == -EPROBE_DEFER) {
   243			return dev->irq;
   244		} else if (!gpio_is_valid(dev->irq)) {
   245			dev_err(&pdev->dev, "irq-gpios not valid !");
   246			return -EIO;
   247		}
   248		dev->irq = gpio_to_irq(dev->irq);
   249	
   250		ret = setup_clock(&clockp, &clockm, xtal, arc_speed);
   251		if (ret) {
   252			dev_err(&pdev->dev,
   253				"Impossible use oscillator:%dMhz and arcnet bus speed:%dKbps",
   254				xtal, arc_speed / 1000);
   255			return ret;
   256		}
   257	
   258		ret = setup_timeout(&timeout);
   259		if (ret) {
   260			dev_err(&pdev->dev, "Timeout:%d is not valid value", timeout);
   261			return ret;
   262		}
   263	
   264		lp->backplane = (int)backplane;
   265		lp->timeout = timeout;
   266		lp->clockm = clockm;
   267		lp->clockp = clockp;
   268		lp->hw.owner = THIS_MODULE;
   269	
   270		if (lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
   271			ret = -EIO;
   272			goto err_release_mem;
   273		}
   274	
   275		if (com20020_check(dev)) {
   276			ret = -EIO;
   277			goto err_release_mem;
   278		}
   279	
   280		ret = com20020_found(dev, IRQF_TRIGGER_FALLING);
   281		if (ret)
   282			goto err_release_mem;
   283	
   284		dev_dbg(&pdev->dev, "probe Done\n");
   285		return 0;
   286	
   287	err_release_mem:
   288		devm_iounmap(&pdev->dev, (void __iomem *)ioaddr);
   289		devm_release_mem_region(&pdev->dev, res.start, resource_size(&res));
   290		dev_err(&pdev->dev, "probe failed!\n");
   291		return ret;
   292	}
   293	

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

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

* Re: [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version
  2018-06-11 16:35 ` kbuild test robot
@ 2018-06-18 12:51   ` Andrea Greco
  0 siblings, 0 replies; 5+ messages in thread
From: Andrea Greco @ 2018-06-18 12:51 UTC (permalink / raw)
  To: David Miller
  Cc: kbuild-all, tobin, Andrea Greco, Michael Grzeschik, linux-kernel, netdev

On 06/11/2018 06:35 PM, kbuild test robot wrote:
>     drivers/net/arcnet/com20020-io.c:34:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       return ioread8((void *__iomem) addr + offset);
>                      ^
>     drivers/net/arcnet/com20020-io.c: In function 'io_arc_outb':
>     drivers/net/arcnet/com20020-io.c:39:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       iowrite8(value, (void *__iomem)addr + offset);
>                       ^
>     drivers/net/arcnet/com20020-io.c: In function 'io_arc_insb':
>     drivers/net/arcnet/com20020-io.c:44:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       ioread8_rep((void *__iomem) (addr + offset), buffer, count);
>                   ^
>     drivers/net/arcnet/com20020-io.c: In function 'io_arc_outsb':
>     drivers/net/arcnet/com20020-io.c:49:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
>                    ^
>     drivers/net/arcnet/com20020-io.c: In function 'com20020_probe':
>     drivers/net/arcnet/com20020-io.c:219:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
>       ioaddr = (int)devm_ioremap(&pdev->dev, iores->start,
>                ^
>     drivers/net/arcnet/com20020-io.c:288:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       devm_iounmap(&pdev->dev, (void __iomem *)ioaddr);
>                                ^

Is there some clean way for fix this.
Some architetture int size is 32 bit and ptr is 64, this rise warning, 
of spark64 compiler.
Change ioaddr type means introduce a lots of casting in all other driver.

Which is the best way for proceed ?

Andrea



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

* Re: [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version
  2018-06-11 14:26 [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version Andrea Greco
  2018-06-11 16:15 ` kbuild test robot
  2018-06-11 16:35 ` kbuild test robot
@ 2018-06-22  8:11 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2018-06-22  8:11 UTC (permalink / raw)
  To: Andrea Greco
  Cc: kbuild-all, davem, tobin, Andrea Greco, Michael Grzeschik,
	linux-kernel, netdev

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

Hi Andrea,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on v4.18-rc1 next-20180622]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andrea-Greco/arcnet-leds-Removed-leds-dependecy/20180611-222941
config: x86_64-randconfig-s4-06220549 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> ERROR: "com20020_found" [drivers/net/arcnet/com20020-io.ko] undefined!
>> ERROR: "com20020_check" [drivers/net/arcnet/com20020-io.ko] undefined!
>> ERROR: "com20020_netdev_ops" [drivers/net/arcnet/com20020-io.ko] undefined!

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32221 bytes --]

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

end of thread, other threads:[~2018-06-22  8:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11 14:26 [PATCH 3/6] arcnet: com20020: Add com20020 io mapped version Andrea Greco
2018-06-11 16:15 ` kbuild test robot
2018-06-11 16:35 ` kbuild test robot
2018-06-18 12:51   ` Andrea Greco
2018-06-22  8:11 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).