linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus
@ 2019-03-01  3:58 Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 1/5] bus: Add support for " Marek Behún
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Marek Behún @ 2019-03-01  3:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, linux-gpio, linux-kernel, Marek Behún

Hello,

this is the third version of my patches to support the Moxtet bus and
GPIOs over it. Moxtet is a Turris Mox specific tiny bus over SPI.

Patches are rebased to current linux-gpio (branch devel and/or for-next).

Changes since last version:
  - addressed the issues in device tree documentation pointed by Rob Herring
  - cosmetic changes suggested by Linus Walleij
  - added sysfs ABI documentation for /sys/bus/moxtet/devices attribute files as suggested by Linus Walleij

Marek

Marek Behún (5):
  bus: Add support for Moxtet bus
  dt-bindings: bus: Document moxtet bus binding
  bus: moxtet: Add sysfs documentation
  drivers: gpio: Add support for GPIOs over Moxtet bus
  dt-bindings: gpio: Document GPIOs via Moxtet bus

 .../ABI/testing/sysfs-bus-moxtet-devices      |  25 +
 .../devicetree/bindings/bus/moxtet.txt        |  36 ++
 .../devicetree/bindings/gpio/gpio-moxtet.txt  |  18 +
 MAINTAINERS                                   |   8 +
 drivers/bus/Kconfig                           |  10 +
 drivers/bus/Makefile                          |   1 +
 drivers/bus/moxtet.c                          | 533 ++++++++++++++++++
 drivers/gpio/Kconfig                          |   9 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-moxtet.c                    | 179 ++++++
 include/linux/moxtet.h                        | 109 ++++
 11 files changed, 929 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-moxtet-devices
 create mode 100644 Documentation/devicetree/bindings/bus/moxtet.txt
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-moxtet.txt
 create mode 100644 drivers/bus/moxtet.c
 create mode 100644 drivers/gpio/gpio-moxtet.c
 create mode 100644 include/linux/moxtet.h

-- 
2.19.2


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

* [PATCH v3 bus+gpio 1/5] bus: Add support for Moxtet bus
  2019-03-01  3:58 [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus Marek Behún
@ 2019-03-01  3:58 ` Marek Behún
  2019-03-05 11:24   ` Arnd Bergmann
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 2/5] dt-bindings: bus: Document moxtet bus binding Marek Behún
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Marek Behún @ 2019-03-01  3:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, linux-gpio, linux-kernel, Marek Behún

On the Turris Mox router different modules can be connected to the main
CPU board: currently a module with a SFP cage, a module with MiniPCIe
connector, a 4-port switch module, an 8-port switch module, and a 4-port
USB3 module.

For example:
  [CPU]-[PCIe]-[8-port switch]-[8-port switch]-[SFP]

Each of this modules has an input and output shift register, and these
are connected via SPI to the CPU board.

Via SPI we are able to discover which modules are connected, in which
order, and we can also read some information about the modules or
configure them.
From each module 8 bits can be read (of which low 4 bits identify the
module) and 8 bits can be written.

For example from the module with a SFP cage we can read the LOS,
TX-FAULT and MOD-DEF0 signals, while we can write TX-DISABLE and
RATE-SELECT signals.

This driver creates a new bus type, called "moxtet". For each Mox module
it finds via SPI, it creates a new device on the moxtet bus so that
drivers can be written for them.

The topology of how Mox modules are connected can then be read by
listing /sys/bus/moxtet/devices.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
---
 MAINTAINERS            |   7 +
 drivers/bus/Kconfig    |  10 +
 drivers/bus/Makefile   |   1 +
 drivers/bus/moxtet.c   | 533 +++++++++++++++++++++++++++++++++++++++++
 include/linux/moxtet.h | 109 +++++++++
 5 files changed, 660 insertions(+)
 create mode 100644 drivers/bus/moxtet.c
 create mode 100644 include/linux/moxtet.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 1e1351bc366d..f6aa13dbb0b8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1498,6 +1498,13 @@ F:	drivers/clocksource/timer-atlas7.c
 N:	[^a-z]sirf
 X:	drivers/gnss
 
+ARM/CZ.NIC TURRIS MOX SUPPORT
+M:	Marek Behun <marek.behun@nic.cz>
+W:	http://mox.turris.cz
+S:	Maintained
+F:	include/linux/moxtet.h
+F:	drivers/bus/moxtet.c
+
 ARM/EBSA110 MACHINE SUPPORT
 M:	Russell King <linux@armlinux.org.uk>
 L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index 1851112ccc29..6b331061d34b 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -29,6 +29,16 @@ config BRCMSTB_GISB_ARB
 	  arbiter. This driver provides timeout and target abort error handling
 	  and internal bus master decoding.
 
+config MOXTET
+	tristate "CZ.NIC Turris Mox module configuration bus"
+	depends on SPI_MASTER && OF
+	help
+	  Say yes here to add support for the module configuration bus found
+	  on CZ.NIC's Turris Mox. This is needed for the ability to discover
+	  the order in which the modules are connected and to get/set some of
+	  their settings. For example the GPIOs on Mox SFP module are
+	  configured through this bus.
+
 config HISILICON_LPC
 	bool "Support for ISA I/O space on HiSilicon Hip06/7"
 	depends on ARM64 && (ARCH_HISI || COMPILE_TEST)
diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile
index ca300b1914ce..16b43d3468c6 100644
--- a/drivers/bus/Makefile
+++ b/drivers/bus/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_ARM_CCI)		+= arm-cci.o
 
 obj-$(CONFIG_HISILICON_LPC)	+= hisi_lpc.o
 obj-$(CONFIG_BRCMSTB_GISB_ARB)	+= brcmstb_gisb.o
+obj-$(CONFIG_MOXTET)		+= moxtet.o
 
 # DPAA2 fsl-mc bus
 obj-$(CONFIG_FSL_MC_BUS)	+= fsl-mc/
diff --git a/drivers/bus/moxtet.c b/drivers/bus/moxtet.c
new file mode 100644
index 000000000000..19b9d12154d4
--- /dev/null
+++ b/drivers/bus/moxtet.c
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Turris Mox module configuration bus driver
+ *
+ * Copyright (C) 2018 Marek Behun <marek.behun@nic.cz>
+ */
+
+#include <linux/module.h>
+#include <linux/moxtet.h>
+#include <linux/mutex.h>
+#include <linux/of_device.h>
+#include <linux/spi/spi.h>
+
+static ssize_t
+module_id_show(struct device *dev, struct device_attribute *a, char *buf)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+
+	return sprintf(buf, "0x%x\n", mdev->id);
+}
+static DEVICE_ATTR_RO(module_id);
+
+static ssize_t
+module_name_show(struct device *dev, struct device_attribute *a, char *buf)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+
+	return sprintf(buf, "%s\n", turris_mox_module_name(mdev->id));
+}
+static DEVICE_ATTR_RO(module_name);
+
+static ssize_t
+input_value_show(struct device *dev, struct device_attribute *a, char *buf)
+{
+	int ret;
+
+	ret = moxtet_device_read(dev);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "0x%x\n", ret);
+}
+static DEVICE_ATTR_RO(input_value);
+
+static ssize_t
+output_value_show(struct device *dev, struct device_attribute *a, char *buf)
+{
+	int ret;
+
+	ret = moxtet_device_written(dev);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "0x%x\n", ret);
+}
+
+static ssize_t
+output_value_store(struct device *dev, struct device_attribute *a,
+		   const char *buf, size_t count)
+{
+	unsigned long val;
+	int ret;
+
+	ret = kstrtoul(buf, 0, &val);
+	if (ret < 0)
+		return ret;
+
+	if (val > 0xff)
+		return -ERANGE;
+
+	ret = moxtet_device_write(dev, val);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+static DEVICE_ATTR_RW(output_value);
+
+static struct attribute *moxtet_dev_attrs[] = {
+	&dev_attr_module_id.attr,
+	&dev_attr_module_name.attr,
+	&dev_attr_input_value.attr,
+	&dev_attr_output_value.attr,
+	NULL,
+};
+
+static const struct attribute_group moxtet_dev_group = {
+	.attrs = moxtet_dev_attrs,
+};
+
+static const struct attribute_group *moxtet_dev_groups[] = {
+	&moxtet_dev_group,
+	NULL,
+};
+
+static int moxtet_match(struct device *dev, struct device_driver *drv)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+	struct moxtet_driver *tdrv = to_moxtet_driver(drv);
+	const enum turris_mox_module_id *t;
+
+	if (of_driver_match_device(dev, drv))
+		return 1;
+
+	if (!tdrv->id_table)
+		return 0;
+
+	for (t = tdrv->id_table; *t; ++t)
+		if (*t == mdev->id)
+			return 1;
+
+	return 0;
+}
+
+struct bus_type moxtet_bus_type = {
+	.name		= "moxtet",
+	.dev_groups	= moxtet_dev_groups,
+	.match		= moxtet_match,
+};
+EXPORT_SYMBOL_GPL(moxtet_bus_type);
+
+int __moxtet_register_driver(struct module *owner,
+			     struct moxtet_driver *mdrv)
+{
+	mdrv->driver.owner = owner;
+	mdrv->driver.bus = &moxtet_bus_type;
+	return driver_register(&mdrv->driver);
+}
+EXPORT_SYMBOL_GPL(__moxtet_register_driver);
+
+static int moxtet_dev_check(struct device *dev, void *data)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+	struct moxtet_device *new_dev = data;
+
+	if (mdev->moxtet == new_dev->moxtet && mdev->id == new_dev->id &&
+	    mdev->idx == new_dev->idx)
+		return -EBUSY;
+	return 0;
+}
+
+static void moxtet_dev_release(struct device *dev)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+
+	put_device(mdev->moxtet->dev);
+	kfree(mdev);
+}
+
+static struct moxtet_device *
+moxtet_alloc_device(struct moxtet *moxtet)
+{
+	struct moxtet_device *dev;
+
+	if (!get_device(moxtet->dev))
+		return NULL;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev) {
+		put_device(moxtet->dev);
+		return NULL;
+	}
+
+	dev->moxtet = moxtet;
+	dev->dev.parent = moxtet->dev;
+	dev->dev.bus = &moxtet_bus_type;
+	dev->dev.release = moxtet_dev_release;
+
+	device_initialize(&dev->dev);
+
+	return dev;
+}
+
+static int moxtet_add_device(struct moxtet_device *dev)
+{
+	static DEFINE_MUTEX(add_mutex);
+	int ret;
+
+	if (dev->idx >= TURRIS_MOX_MAX_MODULES || dev->id > 0xf)
+		return -EINVAL;
+
+	dev_set_name(&dev->dev, "moxtet-%s.%u",
+		     turris_mox_module_name(dev->id), dev->idx);
+
+	mutex_lock(&add_mutex);
+
+	ret = bus_for_each_dev(&moxtet_bus_type, NULL, dev,
+			       moxtet_dev_check);
+	if (ret)
+		goto done;
+
+	ret = device_add(&dev->dev);
+	if (ret < 0)
+		dev_err(dev->moxtet->dev, "can't add %s, status %d\n",
+			dev_name(dev->moxtet->dev), ret);
+
+done:
+	mutex_unlock(&add_mutex);
+	return ret;
+}
+
+static int __unregister(struct device *dev, void *null)
+{
+	if (dev->of_node) {
+		of_node_clear_flag(dev->of_node, OF_POPULATED);
+		of_node_put(dev->of_node);
+	}
+
+	device_unregister(dev);
+
+	return 0;
+}
+
+static struct moxtet_device *
+of_register_moxtet_device(struct moxtet *moxtet, struct device_node *nc)
+{
+	struct moxtet_device *dev;
+	u32 val;
+	int ret;
+
+	dev = moxtet_alloc_device(moxtet);
+	if (!dev) {
+		dev_err(moxtet->dev,
+			"Moxtet device alloc error for %pOF\n", nc);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	ret = of_property_read_u32(nc, "reg", &val);
+	if (ret) {
+		dev_err(moxtet->dev, "%pOF has no valid 'reg' property (%d)\n",
+			nc, ret);
+		goto err_put;
+	}
+
+	dev->idx = val;
+
+	if (dev->idx >= TURRIS_MOX_MAX_MODULES) {
+		dev_err(moxtet->dev, "%pOF Moxtet address 0x%x out of range\n",
+			nc, dev->idx);
+		ret = -EINVAL;
+		goto err_put;
+	}
+
+	dev->id = moxtet->modules[dev->idx];
+
+	if (!dev->id) {
+		dev_err(moxtet->dev, "%pOF Moxtet address 0x%x is empty\n", nc,
+			dev->idx);
+		ret = -ENODEV;
+		goto err_put;
+	}
+
+	of_node_get(nc);
+	dev->dev.of_node = nc;
+
+	ret = moxtet_add_device(dev);
+	if (ret) {
+		dev_err(moxtet->dev,
+			"Moxtet device register error for %pOF\n", nc);
+		of_node_put(nc);
+		goto err_put;
+	}
+
+	return dev;
+
+err_put:
+	put_device(&dev->dev);
+	return ERR_PTR(ret);
+}
+
+static void of_register_moxtet_devices(struct moxtet *moxtet)
+{
+	struct moxtet_device *dev;
+	struct device_node *nc;
+
+	if (!moxtet->dev->of_node)
+		return;
+
+	for_each_available_child_of_node(moxtet->dev->of_node, nc) {
+		if (of_node_test_and_set_flag(nc, OF_POPULATED))
+			continue;
+		dev = of_register_moxtet_device(moxtet, nc);
+		if (IS_ERR(dev)) {
+			dev_warn(moxtet->dev,
+				 "Failed to create Moxtet device for %pOF\n",
+				 nc);
+			of_node_clear_flag(nc, OF_POPULATED);
+		}
+	}
+}
+
+static void
+moxtet_register_devices_from_topology(struct moxtet *moxtet)
+{
+	struct moxtet_device *dev;
+	int i, ret;
+
+	for (i = 0; i < moxtet->count; ++i) {
+		dev = moxtet_alloc_device(moxtet);
+		if (!dev) {
+			dev_err(moxtet->dev, "Moxtet device %u alloc error\n",
+				i);
+			continue;
+		}
+
+		dev->idx = i;
+		dev->id = moxtet->modules[i];
+
+		ret = moxtet_add_device(dev);
+		if (ret && ret != -EBUSY) {
+			put_device(&dev->dev);
+			dev_err(moxtet->dev,
+				"Moxtet device %u register error: %i\n", i,
+				ret);
+		}
+	}
+}
+
+static int moxtet_find_topology(struct moxtet *moxtet)
+{
+	u8 buf[TURRIS_MOX_MAX_MODULES];
+	int i, ret;
+
+	ret = spi_read(to_spi_device(moxtet->dev), buf, TURRIS_MOX_MAX_MODULES);
+	if (ret < 0)
+		return ret;
+
+	if (buf[0] == TURRIS_MOX_CPU_ID_EMMC) {
+		dev_info(moxtet->dev, "Found eMMC Turris Mox CPU module\n");
+	} else if (buf[0] == TURRIS_MOX_CPU_ID_SD) {
+		dev_info(moxtet->dev, "Found SD Turris Mox CPU module\n");
+	} else {
+		dev_err(moxtet->dev, "Invalid Turris Mox CPU module 0x%02x\n",
+			buf[0]);
+		return -ENODEV;
+	}
+
+	moxtet->count = 0;
+
+	for (i = 1; i < TURRIS_MOX_MAX_MODULES; ++i) {
+		int module_id;
+
+		if (buf[i] == 0xff)
+			break;
+
+		module_id = buf[i] & 0xf;
+
+		moxtet->modules[i-1] = module_id;
+		++moxtet->count;
+
+		switch (module_id) {
+		case TURRIS_MOX_MODULE_SFP:
+			dev_info(moxtet->dev, "SFP module found\n");
+			break;
+		case TURRIS_MOX_MODULE_PCI:
+			dev_info(moxtet->dev, "Mini-PCIe module found\n");
+			break;
+		case TURRIS_MOX_MODULE_TOPAZ:
+			dev_info(moxtet->dev, "Topaz Switch module found\n");
+			break;
+		case TURRIS_MOX_MODULE_PERIDOT:
+			dev_info(moxtet->dev, "Peridot Switch module found\n");
+			break;
+		case TURRIS_MOX_MODULE_USB3:
+			dev_info(moxtet->dev, "USB 3.0 module found\n");
+			break;
+		case TURRIS_MOX_MODULE_PASSPCI:
+			dev_info(moxtet->dev,
+				 "Passthrough Mini-PCIe module found\n");
+			break;
+		default:
+			dev_info(moxtet->dev,
+				 "Unknown Moxtet module found (ID 0x%02x)\n",
+				 module_id);
+		}
+	}
+
+	return 0;
+}
+
+int moxtet_device_read(struct device *dev)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+	struct moxtet *moxtet = mdev->moxtet;
+	u8 buf[TURRIS_MOX_MAX_MODULES];
+	struct spi_transfer xfer = {
+		.rx_buf = buf,
+		.tx_buf = moxtet->tx,
+		.len = moxtet->count + 1
+	};
+	int ret;
+
+	if (mdev->idx >= moxtet->count)
+		return -EINVAL;
+
+	mutex_lock(&moxtet->lock);
+
+	ret = spi_sync_transfer(to_spi_device(moxtet->dev), &xfer, 1);
+
+	mutex_unlock(&moxtet->lock);
+
+	if (ret < 0)
+		return ret;
+
+	return buf[mdev->idx + 1] >> 4;
+}
+EXPORT_SYMBOL_GPL(moxtet_device_read);
+
+int moxtet_device_write(struct device *dev, u8 val)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+	struct moxtet *moxtet = mdev->moxtet;
+	int ret;
+
+	if (mdev->idx >= moxtet->count)
+		return -EINVAL;
+
+	mutex_lock(&moxtet->lock);
+
+	moxtet->tx[moxtet->count - mdev->idx] = val;
+
+	ret = spi_write(to_spi_device(moxtet->dev), moxtet->tx,
+			moxtet->count + 1);
+
+	mutex_unlock(&moxtet->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(moxtet_device_write);
+
+int moxtet_device_written(struct device *dev)
+{
+	struct moxtet_device *mdev = to_moxtet_device(dev);
+	struct moxtet *moxtet = mdev->moxtet;
+
+	if (mdev->idx >= moxtet->count)
+		return -EINVAL;
+
+	return moxtet->tx[moxtet->count - mdev->idx];
+}
+EXPORT_SYMBOL_GPL(moxtet_device_written);
+
+static int moxtet_probe(struct spi_device *spi)
+{
+	struct moxtet *moxtet;
+	int ret;
+
+	ret = spi_setup(spi);
+	if (ret < 0)
+		return ret;
+
+	moxtet = devm_kzalloc(&spi->dev, sizeof(struct moxtet),
+			      GFP_KERNEL);
+	if (!moxtet)
+		return -ENOMEM;
+
+	moxtet->dev = &spi->dev;
+	spi_set_drvdata(spi, moxtet);
+
+	mutex_init(&moxtet->lock);
+
+	ret = moxtet_find_topology(moxtet);
+	if (ret < 0)
+		return ret;
+
+	of_register_moxtet_devices(moxtet);
+	moxtet_register_devices_from_topology(moxtet);
+
+	return 0;
+}
+
+static int moxtet_remove(struct spi_device *spi)
+{
+	struct moxtet *moxtet = spi_get_drvdata(spi);
+	int dummy;
+
+	dummy = device_for_each_child(moxtet->dev, NULL, __unregister);
+
+	mutex_destroy(&moxtet->lock);
+
+	return 0;
+}
+
+static const struct of_device_id moxtet_dt_ids[] = {
+	{ .compatible = "cznic,moxtet" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, moxtet_dt_ids);
+
+static struct spi_driver moxtet_spi_driver = {
+	.driver = {
+		.name		= "moxtet",
+		.of_match_table = moxtet_dt_ids,
+	},
+	.probe		= moxtet_probe,
+	.remove		= moxtet_remove,
+};
+
+static int __init moxtet_init(void)
+{
+	int ret;
+
+	ret = bus_register(&moxtet_bus_type);
+	if (ret < 0) {
+		pr_err("moxtet bus registration failed: %d\n", ret);
+		goto error;
+	}
+
+	ret = spi_register_driver(&moxtet_spi_driver);
+	if (ret < 0) {
+		pr_err("moxtet spi driver registration failed: %d\n", ret);
+		goto error_bus;
+	}
+
+	return 0;
+
+error_bus:
+	bus_unregister(&moxtet_bus_type);
+error:
+	return ret;
+}
+postcore_initcall_sync(moxtet_init);
+
+static void __exit moxtet_exit(void)
+{
+	spi_unregister_driver(&moxtet_spi_driver);
+	bus_unregister(&moxtet_bus_type);
+}
+module_exit(moxtet_exit);
+
+MODULE_AUTHOR("Marek Behun <marek.behun@nic.cz>");
+MODULE_DESCRIPTION("CZ.NIC's Turris Mox module configuration bus");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/moxtet.h b/include/linux/moxtet.h
new file mode 100644
index 000000000000..ddc1619815f0
--- /dev/null
+++ b/include/linux/moxtet.h
@@ -0,0 +1,109 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Turris Mox module configuration bus driver
+ *
+ * Copyright (C) 2018 Marek Behun <marek.behun@nic.cz>
+ */
+
+#ifndef __LINUX_MOXTET_H
+#define __LINUX_MOXTET_H
+
+#include <linux/device.h>
+#include <linux/mutex.h>
+
+#define TURRIS_MOX_MAX_MODULES	10
+
+enum turris_mox_cpu_module_id {
+	TURRIS_MOX_CPU_ID_EMMC	= 0x00,
+	TURRIS_MOX_CPU_ID_SD	= 0x10,
+};
+
+enum turris_mox_module_id {
+	TURRIS_MOX_MODULE_SFP		= 0x01,
+	TURRIS_MOX_MODULE_PCI		= 0x02,
+	TURRIS_MOX_MODULE_TOPAZ		= 0x03,
+	TURRIS_MOX_MODULE_PERIDOT	= 0x04,
+	TURRIS_MOX_MODULE_USB3		= 0x05,
+	TURRIS_MOX_MODULE_PASSPCI	= 0x06,
+};
+
+static inline const char *turris_mox_module_name(unsigned int id)
+{
+	switch (id) {
+	case TURRIS_MOX_MODULE_SFP:
+		return "sfp";
+	case TURRIS_MOX_MODULE_PCI:
+		return "pci";
+	case TURRIS_MOX_MODULE_TOPAZ:
+		return "topaz";
+	case TURRIS_MOX_MODULE_PERIDOT:
+		return "peridot";
+	case TURRIS_MOX_MODULE_USB3:
+		return "usb3";
+	case TURRIS_MOX_MODULE_PASSPCI:
+		return "passthrough-pci";
+	default:
+		return "unknown";
+	}
+}
+
+extern struct bus_type moxtet_type;
+
+struct moxtet {
+	struct device	*dev;
+	struct mutex	lock;
+	u8		modules[TURRIS_MOX_MAX_MODULES];
+	int		count;
+	u8		tx[TURRIS_MOX_MAX_MODULES];
+	char		module_topology[128];
+};
+
+struct moxtet_driver {
+	const enum turris_mox_module_id	*id_table;
+	struct device_driver		driver;
+};
+
+static inline struct moxtet_driver *
+to_moxtet_driver(struct device_driver *drv)
+{
+	if (!drv)
+		return NULL;
+	return container_of(drv, struct moxtet_driver, driver);
+}
+
+extern int __moxtet_register_driver(struct module *owner,
+				    struct moxtet_driver *mdrv);
+
+static inline void moxtet_unregister_driver(struct moxtet_driver *mdrv)
+{
+	if (mdrv)
+		driver_unregister(&mdrv->driver);
+}
+
+#define moxtet_register_driver(driver) \
+	__moxtet_register_driver(THIS_MODULE, driver)
+
+#define module_moxtet_driver(__moxtet_driver) \
+	module_driver(__moxtet_driver, moxtet_register_driver, \
+			moxtet_unregister_driver)
+
+struct moxtet_device {
+	struct device			dev;
+	struct moxtet			*moxtet;
+	enum turris_mox_module_id	id;
+	unsigned int			idx;
+};
+
+extern int moxtet_device_read(struct device *dev);
+extern int moxtet_device_write(struct device *dev, u8 val);
+extern int moxtet_device_written(struct device *dev);
+
+static inline struct moxtet_device *
+to_moxtet_device(struct device *dev)
+{
+	if (!dev)
+		return NULL;
+	return container_of(dev, struct moxtet_device, dev);
+}
+
+#endif /* __LINUX_MOXTET_H */
-- 
2.19.2


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

* [PATCH v3 bus+gpio 2/5] dt-bindings: bus: Document moxtet bus binding
  2019-03-01  3:58 [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 1/5] bus: Add support for " Marek Behún
@ 2019-03-01  3:58 ` Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation Marek Behún
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Marek Behún @ 2019-03-01  3:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, linux-gpio, linux-kernel,
	Marek Behún, Rob Herring, devicetree

This adds device tree binding documentation for the Moxtet bus, a bus
via which the different modules connected to the Turris Mox router can
be configured.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org
---
 .../devicetree/bindings/bus/moxtet.txt        | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/bus/moxtet.txt

diff --git a/Documentation/devicetree/bindings/bus/moxtet.txt b/Documentation/devicetree/bindings/bus/moxtet.txt
new file mode 100644
index 000000000000..2bb998cbd3ad
--- /dev/null
+++ b/Documentation/devicetree/bindings/bus/moxtet.txt
@@ -0,0 +1,36 @@
+Turris Mox module configuration bus (over SPI)
+
+Required properties:
+ - compatible		: Should be "cznic,moxtet".
+ - #address-cells	: Has to be 1
+ - #size-cells		: Has to be 0
+ - spi-cpol		: Required inverted clock polarity
+ - spi-cpha		: Required shifted clock phase
+For other required and optional properties of SPI slave nodes please refer to
+../spi/spi-bus.txt.
+
+Required properties of subnodes:
+ - reg			: Should be position on the Moxtet bus
+
+The driver finds the devices connected to the bus by itself, but it may be
+needed to reference some of them from other parts of the device tree. In that
+case the devices can be defined as subnodes of the moxtet node.
+
+Example:
+
+	moxtet@1 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "cznic,moxtet";
+		reg = <1>;
+		spi-max-frequency = <10000000>;
+		spi-cpol;
+		spi-cpha;
+
+		moxtet_sfp: gpio@0 {
+			compatible = "cznic,moxtet-sfp";
+			gpio-controller;
+			#gpio-cells = <2>;
+			reg = <0>;
+		}
+	};
-- 
2.19.2


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

* [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation
  2019-03-01  3:58 [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 1/5] bus: Add support for " Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 2/5] dt-bindings: bus: Document moxtet bus binding Marek Behún
@ 2019-03-01  3:58 ` Marek Behún
  2019-03-01 14:34   ` Linus Walleij
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 4/5] drivers: gpio: Add support for GPIOs over Moxtet bus Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via " Marek Behún
  4 siblings, 1 reply; 15+ messages in thread
From: Marek Behún @ 2019-03-01  3:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, linux-gpio, linux-kernel, Marek Behún

Add sysfs ABI documentation for the attribute files module_id,
module_name, input_value and output_value of Moxtet devices.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 .../ABI/testing/sysfs-bus-moxtet-devices      | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-moxtet-devices

diff --git a/Documentation/ABI/testing/sysfs-bus-moxtet-devices b/Documentation/ABI/testing/sysfs-bus-moxtet-devices
new file mode 100644
index 000000000000..80bae358a90c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-moxtet-devices
@@ -0,0 +1,25 @@
+What:		/sys/bus/moxtet/devices/moxtet-<name>.<addr>/module_id
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(R) Moxtet module ID. Format: %x
+
+What:		/sys/bus/moxtet/devices/moxtet-<name>.<addr>/module_name
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(R) Moxtet module name. Format: string
+
+What:		/sys/bus/moxtet/devices/moxtet-<name>.<addr>/input_value
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(R) Read input value from module at this Moxtet address.
+		Format: %x
+
+What:		/sys/bus/moxtet/devices/moxtet-<name>.<addr>/output_value
+Date:		March 2019
+KernelVersion:	5.2
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(RW) Read last written value or write value to the module on
+		this Moxtet address. Format: %x
-- 
2.19.2


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

* [PATCH v3 bus+gpio 4/5] drivers: gpio: Add support for GPIOs over Moxtet bus
  2019-03-01  3:58 [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus Marek Behún
                   ` (2 preceding siblings ...)
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation Marek Behún
@ 2019-03-01  3:58 ` Marek Behún
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via " Marek Behún
  4 siblings, 0 replies; 15+ messages in thread
From: Marek Behún @ 2019-03-01  3:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, linux-gpio, linux-kernel, Marek Behún

This adds support for interpreting the input and output bits of one
device on Moxtet bus as GPIOs.
This is needed for example by the SFP cage module of Turris Mox.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 MAINTAINERS                |   1 +
 drivers/gpio/Kconfig       |   9 ++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-moxtet.c | 179 +++++++++++++++++++++++++++++++++++++
 4 files changed, 190 insertions(+)
 create mode 100644 drivers/gpio/gpio-moxtet.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f6aa13dbb0b8..5a445153377a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1504,6 +1504,7 @@ W:	http://mox.turris.cz
 S:	Maintained
 F:	include/linux/moxtet.h
 F:	drivers/bus/moxtet.c
+F:	drivers/gpio/gpio-moxtet.c
 
 ARM/EBSA110 MACHINE SUPPORT
 M:	Russell King <linux@armlinux.org.uk>
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 3f50526a771f..4f567a2502f1 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1424,6 +1424,15 @@ config GPIO_XRA1403
 	help
 	  GPIO driver for EXAR XRA1403 16-bit SPI-based GPIO expander.
 
+config GPIO_MOXTET
+	tristate "Turris Mox Moxtet bus GPIO expander"
+	depends on MOXTET
+	help
+	  Say yes here if you are building for the Turris Mox router.
+	  This is the driver needed for configuring the GPIOs via the Moxtet
+	  bus. For example the Mox module with SFP cage needs this driver
+	  so that phylink can use corresponding GPIOs.
+
 endmenu
 
 menu "USB GPIO expanders"
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 54d55274b93a..8f20025daf50 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -88,6 +88,7 @@ obj-$(CONFIG_GPIO_MC9S08DZ60)	+= gpio-mc9s08dz60.o
 obj-$(CONFIG_GPIO_ML_IOH)	+= gpio-ml-ioh.o
 obj-$(CONFIG_GPIO_MM_LANTIQ)	+= gpio-mm-lantiq.o
 obj-$(CONFIG_GPIO_MOCKUP)      += gpio-mockup.o
+obj-$(CONFIG_GPIO_MOXTET)	+= gpio-moxtet.o
 obj-$(CONFIG_GPIO_MPC5200)	+= gpio-mpc5200.o
 obj-$(CONFIG_GPIO_MPC8XXX)	+= gpio-mpc8xxx.o
 obj-$(CONFIG_GPIO_MSIC)		+= gpio-msic.o
diff --git a/drivers/gpio/gpio-moxtet.c b/drivers/gpio/gpio-moxtet.c
new file mode 100644
index 000000000000..2fdd6cdf0db4
--- /dev/null
+++ b/drivers/gpio/gpio-moxtet.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Turris Mox Moxtet GPIO expander
+ *
+ *  Copyright (C) 2018 Marek Behun <marek.behun@nic.cz>
+ */
+
+#include <linux/bitops.h>
+#include <linux/gpio/driver.h>
+#include <linux/moxtet.h>
+#include <linux/module.h>
+
+#define MOXTET_GPIO_NGPIOS	12
+#define MOXTET_GPIO_INPUTS	4
+
+struct moxtet_gpio_desc {
+	u16 in_mask;
+	u16 out_mask;
+};
+
+static const struct moxtet_gpio_desc descs[] = {
+	[TURRIS_MOX_MODULE_SFP] = {
+		.in_mask = GENMASK(2, 0),
+		.out_mask = GENMASK(5, 4),
+	},
+};
+
+struct moxtet_gpio_chip {
+	struct device			*dev;
+	struct gpio_chip		gpio_chip;
+	const struct moxtet_gpio_desc	*desc;
+};
+
+static int moxtet_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
+{
+	struct moxtet_gpio_chip *chip = gpiochip_get_data(gc);
+	int ret;
+
+	if (chip->desc->in_mask & BIT(offset)) {
+		ret = moxtet_device_read(chip->dev);
+	} else if (chip->desc->out_mask & BIT(offset)) {
+		ret = moxtet_device_written(chip->dev);
+		if (ret >= 0)
+			ret <<= MOXTET_GPIO_INPUTS;
+	} else {
+		return -EINVAL;
+	}
+
+	if (ret < 0)
+		return ret;
+
+	return !!(ret & BIT(offset));
+}
+
+static void moxtet_gpio_set_value(struct gpio_chip *gc, unsigned int offset,
+				  int val)
+{
+	struct moxtet_gpio_chip *chip = gpiochip_get_data(gc);
+	int state;
+
+	state = moxtet_device_written(chip->dev);
+	if (state < 0)
+		return;
+
+	offset -= MOXTET_GPIO_INPUTS;
+
+	if (val)
+		state |= BIT(offset);
+	else
+		state &= ~BIT(offset);
+
+	moxtet_device_write(chip->dev, state);
+}
+
+static int moxtet_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+	struct moxtet_gpio_chip *chip = gpiochip_get_data(gc);
+
+	/* All lines are hard wired to be either input or output, not both. */
+	if (chip->desc->in_mask & BIT(offset))
+		return 1;
+	else if (chip->desc->out_mask & BIT(offset))
+		return 0;
+	else
+		return -EINVAL;
+}
+
+static int moxtet_gpio_direction_input(struct gpio_chip *gc,
+				       unsigned int offset)
+{
+	struct moxtet_gpio_chip *chip = gpiochip_get_data(gc);
+
+	if (chip->desc->in_mask & BIT(offset))
+		return 0;
+	else if (chip->desc->out_mask & BIT(offset))
+		return -ENOTSUPP;
+	else
+		return -EINVAL;
+}
+
+static int moxtet_gpio_direction_output(struct gpio_chip *gc,
+					unsigned int offset, int val)
+{
+	struct moxtet_gpio_chip *chip = gpiochip_get_data(gc);
+
+	if (chip->desc->out_mask & BIT(offset))
+		moxtet_gpio_set_value(gc, offset, val);
+	else if (chip->desc->in_mask & BIT(offset))
+		return -ENOTSUPP;
+	else
+		return -EINVAL;
+
+	return 0;
+}
+
+static int moxtet_gpio_probe(struct device *dev)
+{
+	struct moxtet_gpio_chip *chip;
+	struct device_node *nc = dev->of_node;
+	int id;
+
+	id = to_moxtet_device(dev)->id;
+
+	if (id >= ARRAY_SIZE(descs)) {
+		dev_err(dev, "%pOF Moxtet device id 0x%x is not supported by "
+			     "gpio-moxtet driver\n", nc, id);
+		return -ENOTSUPP;
+	}
+
+	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+
+	chip->dev = dev;
+	chip->gpio_chip.parent = dev;
+	chip->desc = &descs[id];
+
+	dev_set_drvdata(dev, chip);
+
+	chip->gpio_chip.label = dev_name(dev);
+	chip->gpio_chip.get_direction = moxtet_gpio_get_direction;
+	chip->gpio_chip.direction_input = moxtet_gpio_direction_input;
+	chip->gpio_chip.direction_output = moxtet_gpio_direction_output;
+	chip->gpio_chip.get = moxtet_gpio_get_value;
+	chip->gpio_chip.set = moxtet_gpio_set_value;
+	chip->gpio_chip.base = -1;
+
+	chip->gpio_chip.ngpio = MOXTET_GPIO_NGPIOS;
+
+	chip->gpio_chip.can_sleep = true;
+	chip->gpio_chip.owner = THIS_MODULE;
+
+	return devm_gpiochip_add_data(dev, &chip->gpio_chip, chip);
+}
+
+static const struct of_device_id moxtet_gpio_dt_ids[] = {
+	{ .compatible = "cznic,moxtet-gpio", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, moxtet_gpio_dt_ids);
+
+static const enum turris_mox_module_id moxtet_gpio_module_table[] = {
+	TURRIS_MOX_MODULE_SFP,
+	0,
+};
+
+static struct moxtet_driver moxtet_gpio_driver = {
+	.driver = {
+		.name		= "moxtet-gpio",
+		.of_match_table	= moxtet_gpio_dt_ids,
+		.probe		= moxtet_gpio_probe,
+	},
+	.id_table = moxtet_gpio_module_table,
+};
+module_moxtet_driver(moxtet_gpio_driver);
+
+MODULE_AUTHOR("Marek Behun <marek.behun@nic.cz>");
+MODULE_DESCRIPTION("Turris Mox Moxtet GPIO expander");
+MODULE_LICENSE("GPL v2");
-- 
2.19.2


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

* [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via Moxtet bus
  2019-03-01  3:58 [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus Marek Behún
                   ` (3 preceding siblings ...)
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 4/5] drivers: gpio: Add support for GPIOs over Moxtet bus Marek Behún
@ 2019-03-01  3:58 ` Marek Behún
  2019-03-01 14:36   ` Linus Walleij
  4 siblings, 1 reply; 15+ messages in thread
From: Marek Behún @ 2019-03-01  3:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, linux-gpio, linux-kernel,
	Marek Behún, Rob Herring, devicetree

This patch adds documentation of the device tree bindings for GPIOs
on the devices connected via Moxtet bus.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org
---
 .../devicetree/bindings/gpio/gpio-moxtet.txt   | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-moxtet.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-moxtet.txt b/Documentation/devicetree/bindings/gpio/gpio-moxtet.txt
new file mode 100644
index 000000000000..410759de9f09
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-moxtet.txt
@@ -0,0 +1,18 @@
+Turris Mox Moxtet GPIO expander via Moxtet bus
+
+Required properties:
+ - compatible		: Should be "cznic,moxtet-gpio".
+ - gpio-controller	: Marks the device node as a GPIO controller.
+ - #gpio-cells		: Should be two. For consumer use see gpio.txt.
+
+Other properties are required for a Moxtet bus device, please refer to
+Documentation/devicetree/bindings/bus/moxtet.txt.
+
+Example:
+
+	moxtet_sfp: gpio@0 {
+		compatible = "cznic,moxtet-gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+		reg = <0>;
+	}
-- 
2.19.2


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

* Re: [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation Marek Behún
@ 2019-03-01 14:34   ` Linus Walleij
  2019-03-01 15:15     ` Marek Behun
  0 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2019-03-01 14:34 UTC (permalink / raw)
  To: Marek Behún
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel

On Fri, Mar 1, 2019 at 4:59 AM Marek Behún <marek.behun@nic.cz> wrote:

> Add sysfs ABI documentation for the attribute files module_id,
> module_name, input_value and output_value of Moxtet devices.
>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

(...)
> +++ b/Documentation/ABI/testing/sysfs-bus-moxtet-devices
> @@ -0,0 +1,25 @@
> +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/module_id
> +Date:          March 2019
> +KernelVersion: 5.2
> +Contact:       Marek Behún <marek.behun@nic.cz>
> +Description:   (R) Moxtet module ID. Format: %x
> +
> +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/module_name
> +Date:          March 2019
> +KernelVersion: 5.2
> +Contact:       Marek Behún <marek.behun@nic.cz>
> +Description:   (R) Moxtet module name. Format: string

These look good.

> +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/input_value
> +Date:          March 2019
> +KernelVersion: 5.2
> +Contact:       Marek Behún <marek.behun@nic.cz>
> +Description:   (R) Read input value from module at this Moxtet address.
> +               Format: %x
> +
> +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/output_value
> +Date:          March 2019
> +KernelVersion: 5.2
> +Contact:       Marek Behún <marek.behun@nic.cz>
> +Description:   (RW) Read last written value or write value to the module on
> +               this Moxtet address. Format: %x

What is the usecase for these?

If this is for debugging it should be in debugfs rather than in sysfs.

If it is here for random userspace drivers, we need some good explanation
as to why they can't just be kernel drivers.

Yours,
Linus Walleij

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

* Re: [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via Moxtet bus
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via " Marek Behún
@ 2019-03-01 14:36   ` Linus Walleij
  2019-03-01 15:16     ` Marek Behun
  2019-03-03 23:17     ` Marek Behun
  0 siblings, 2 replies; 15+ messages in thread
From: Linus Walleij @ 2019-03-01 14:36 UTC (permalink / raw)
  To: Marek Behún
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel,
	Rob Herring,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Fri, Mar 1, 2019 at 4:59 AM Marek Behún <marek.behun@nic.cz> wrote:

> This patch adds documentation of the device tree bindings for GPIOs
> on the devices connected via Moxtet bus.
>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: devicetree@vger.kernel.org

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

> +               compatible = "cznic,moxtet-gpio";

Is cznic registered in
Documentation/devicetree/bindings/vendor-prefixes.txt?

Yours,
Linus Walleij

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

* Re: [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation
  2019-03-01 14:34   ` Linus Walleij
@ 2019-03-01 15:15     ` Marek Behun
  2019-03-04 12:07       ` Linus Walleij
  0 siblings, 1 reply; 15+ messages in thread
From: Marek Behun @ 2019-03-01 15:15 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel

On Fri, 1 Mar 2019 15:34:26 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> > +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/output_value
> > +Date:          March 2019
> > +KernelVersion: 5.2
> > +Contact:       Marek Behún <marek.behun@nic.cz>
> > +Description:   (RW) Read last written value or write value to the
> > module on
> > +               this Moxtet address. Format: %x  
> 
> What is the usecase for these?
> 
> If this is for debugging it should be in debugfs rather than in sysfs.
> 
> If it is here for random userspace drivers, we need some good
> explanation as to why they can't just be kernel drivers.

Hmm, it was for debugging purposes but the ability to write there is
not needed anymore... Shall I make it read/only? Or completely remove
it?

Marek

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

* Re: [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via Moxtet bus
  2019-03-01 14:36   ` Linus Walleij
@ 2019-03-01 15:16     ` Marek Behun
  2019-03-03 23:17     ` Marek Behun
  1 sibling, 0 replies; 15+ messages in thread
From: Marek Behun @ 2019-03-01 15:16 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel,
	Rob Herring,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Fri, 1 Mar 2019 15:36:09 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> > +               compatible = "cznic,moxtet-gpio";  
> 
> Is cznic registered in
> Documentation/devicetree/bindings/vendor-prefixes.txt?

Yes, it is registered.
Thank you for the review.
Marek

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

* Re: [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via Moxtet bus
  2019-03-01 14:36   ` Linus Walleij
  2019-03-01 15:16     ` Marek Behun
@ 2019-03-03 23:17     ` Marek Behun
  2019-03-04  9:53       ` Linus Walleij
  1 sibling, 1 reply; 15+ messages in thread
From: Marek Behun @ 2019-03-03 23:17 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel,
	Rob Herring,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

Hi Linus,

do you know who is responsible for merging into drivers/bus?

I have received reviews for this and for previous versions only from
you and Rob.

Also, please do not merge yet. I have prepared a fourth version with
debugging over debugfs, fixed some checkpatch issues, and most
importantnly added interrupt reading support from moxtet.

I will send after proper testing is done for this new version.

Marek

On Fri, 1 Mar 2019 15:36:09 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Fri, Mar 1, 2019 at 4:59 AM Marek Behún <marek.behun@nic.cz> wrote:
> 
> > This patch adds documentation of the device tree bindings for GPIOs
> > on the devices connected via Moxtet bus.
> >
> > Signed-off-by: Marek Behún <marek.behun@nic.cz>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: devicetree@vger.kernel.org  
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> > +               compatible = "cznic,moxtet-gpio";  
> 
> Is cznic registered in
> Documentation/devicetree/bindings/vendor-prefixes.txt?
> 
> Yours,
> Linus Walleij


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

* Re: [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via Moxtet bus
  2019-03-03 23:17     ` Marek Behun
@ 2019-03-04  9:53       ` Linus Walleij
  0 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2019-03-04  9:53 UTC (permalink / raw)
  To: Marek Behun
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel,
	Rob Herring,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Mon, Mar 4, 2019 at 12:17 AM Marek Behun <marek.behun@nic.cz> wrote:

> do you know who is responsible for merging into drivers/bus?

Usually the ARM SoC maintainers arm@kernel.org merge drivers
there. You should just send them a pull request and explain the
situation I think. Else they know who should deal with it.

Yours,
Linus Walleij

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

* Re: [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation
  2019-03-01 15:15     ` Marek Behun
@ 2019-03-04 12:07       ` Linus Walleij
  2019-03-05 11:11         ` Arnd Bergmann
  0 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2019-03-04 12:07 UTC (permalink / raw)
  To: Marek Behun
  Cc: Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM, linux-kernel

On Fri, Mar 1, 2019 at 4:15 PM Marek Behun <marek.behun@nic.cz> wrote:

> On Fri, 1 Mar 2019 15:34:26 +0100
> Linus Walleij <linus.walleij@linaro.org> wrote:
>
> > > +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/output_value
> > > +Date:          March 2019
> > > +KernelVersion: 5.2
> > > +Contact:       Marek Behún <marek.behun@nic.cz>
> > > +Description:   (RW) Read last written value or write value to the
> > > module on
> > > +               this Moxtet address. Format: %x
> >
> > What is the usecase for these?
> >
> > If this is for debugging it should be in debugfs rather than in sysfs.
> >
> > If it is here for random userspace drivers, we need some good
> > explanation as to why they can't just be kernel drivers.
>
> Hmm, it was for debugging purposes but the ability to write there is
> not needed anymore... Shall I make it read/only? Or completely remove
> it?

I would either remove it or move it to debugfs.

Yours,
Linus Walleij

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

* Re: [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation
  2019-03-04 12:07       ` Linus Walleij
@ 2019-03-05 11:11         ` Arnd Bergmann
  0 siblings, 0 replies; 15+ messages in thread
From: Arnd Bergmann @ 2019-03-05 11:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Marek Behun, Tony Lindgren, Shawn Guo, open list:GPIO SUBSYSTEM,
	linux-kernel

On Mon, Mar 4, 2019 at 1:08 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Fri, Mar 1, 2019 at 4:15 PM Marek Behun <marek.behun@nic.cz> wrote:
>
> > On Fri, 1 Mar 2019 15:34:26 +0100
> > Linus Walleij <linus.walleij@linaro.org> wrote:
> >
> > > > +What:          /sys/bus/moxtet/devices/moxtet-<name>.<addr>/output_value
> > > > +Date:          March 2019
> > > > +KernelVersion: 5.2
> > > > +Contact:       Marek Behún <marek.behun@nic.cz>
> > > > +Description:   (RW) Read last written value or write value to the
> > > > module on
> > > > +               this Moxtet address. Format: %x
> > >
> > > What is the usecase for these?
> > >
> > > If this is for debugging it should be in debugfs rather than in sysfs.
> > >
> > > If it is here for random userspace drivers, we need some good
> > > explanation as to why they can't just be kernel drivers.

I had the same thought, and then saw you already commented.

> > Hmm, it was for debugging purposes but the ability to write there is
> > not needed anymore... Shall I make it read/only? Or completely remove
> > it?
>
> I would either remove it or move it to debugfs.

How about removing it for the initial submission? Then we
can see if it's still needed later and discuss how it should be
done when we need it.

     Arnd

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

* Re: [PATCH v3 bus+gpio 1/5] bus: Add support for Moxtet bus
  2019-03-01  3:58 ` [PATCH v3 bus+gpio 1/5] bus: Add support for " Marek Behún
@ 2019-03-05 11:24   ` Arnd Bergmann
  0 siblings, 0 replies; 15+ messages in thread
From: Arnd Bergmann @ 2019-03-05 11:24 UTC (permalink / raw)
  To: Marek Behún
  Cc: Linus Walleij, Tony Lindgren, Shawn Guo,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List

On Fri, Mar 1, 2019 at 5:02 AM Marek Behún <marek.behun@nic.cz> wrote:
>
> On the Turris Mox router different modules can be connected to the main
> CPU board: currently a module with a SFP cage, a module with MiniPCIe
> connector, a 4-port switch module, an 8-port switch module, and a 4-port
> USB3 module.
>
> For example:
>   [CPU]-[PCIe]-[8-port switch]-[8-port switch]-[SFP]
>
> Each of this modules has an input and output shift register, and these
> are connected via SPI to the CPU board.
>
> Via SPI we are able to discover which modules are connected, in which
> order, and we can also read some information about the modules or
> configure them.
> From each module 8 bits can be read (of which low 4 bits identify the
> module) and 8 bits can be written.
>
> For example from the module with a SFP cage we can read the LOS,
> TX-FAULT and MOD-DEF0 signals, while we can write TX-DISABLE and
> RATE-SELECT signals.
>
> This driver creates a new bus type, called "moxtet". For each Mox module
> it finds via SPI, it creates a new device on the moxtet bus so that
> drivers can be written for them.
>
> The topology of how Mox modules are connected can then be read by
> listing /sys/bus/moxtet/devices.
>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> Acked-by: Linus Walleij <linus.walleij@linaro.org>

This looks very nice! I looked through the driver now and found nothing
to comment on other than the debugging properties that Linus already
mentioned, so please add my

Acked-by: Arnd Bergmann <arnd@arndb.de>

and submit the next version to soc@kernel.org so we can pick it up
for linux-5.2.

     Arnd

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

end of thread, other threads:[~2019-03-05 11:24 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01  3:58 [PATCH v3 bus+gpio 0/5] Add Moxtet bus and GPIO over Moxtet bus Marek Behún
2019-03-01  3:58 ` [PATCH v3 bus+gpio 1/5] bus: Add support for " Marek Behún
2019-03-05 11:24   ` Arnd Bergmann
2019-03-01  3:58 ` [PATCH v3 bus+gpio 2/5] dt-bindings: bus: Document moxtet bus binding Marek Behún
2019-03-01  3:58 ` [PATCH v3 bus+gpio 3/5] bus: moxtet: Add sysfs documentation Marek Behún
2019-03-01 14:34   ` Linus Walleij
2019-03-01 15:15     ` Marek Behun
2019-03-04 12:07       ` Linus Walleij
2019-03-05 11:11         ` Arnd Bergmann
2019-03-01  3:58 ` [PATCH v3 bus+gpio 4/5] drivers: gpio: Add support for GPIOs over Moxtet bus Marek Behún
2019-03-01  3:58 ` [PATCH v3 bus+gpio 5/5] dt-bindings: gpio: Document GPIOs via " Marek Behún
2019-03-01 14:36   ` Linus Walleij
2019-03-01 15:16     ` Marek Behun
2019-03-03 23:17     ` Marek Behun
2019-03-04  9:53       ` Linus Walleij

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