Skip to contentSkip to conversation

arm: aspeed: Add LPC uart routing support

PATCH Superseded Chia-Wei Wang 2 participants 7 messages Sep 1, 2021

Subsystems (2)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover arm: aspeed: Add LPC uart routing support

Add LPC uart routing driver and the device tree nodes.

Chia-Wei Wang (2):
soc: aspeed: Add LPC UART routing support
ARM: dts: aspeed: Add uart routing to device tree

 arch/arm/boot/dts/aspeed-g5.dtsi             |   6 +
 arch/arm/boot/dts/aspeed-g6.dtsi             |   6 +
 drivers/soc/aspeed/Kconfig                   |  11 +
 drivers/soc/aspeed/Makefile                  |   9 +-
 drivers/soc/aspeed/aspeed-lpc-uart-routing.c | 621 +++++++++++++++++++
 5 files changed, 649 insertions(+), 4 deletions(-)
 create mode 100644 drivers/soc/aspeed/aspeed-lpc-uart-routing.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 soc: aspeed: Add LPC UART routing support

Add driver support for the LPC UART routing control. Users can perform runtime configuration of the RX muxes among the UART controllers and the UART TXD/RXD IO pins. This is achieved through the exported sysfs interface.

---
 drivers/soc/aspeed/Kconfig                   |  11 +
 drivers/soc/aspeed/Makefile                  |   9 +-
 drivers/soc/aspeed/aspeed-lpc-uart-routing.c | 621 +++++++++++++++++++
 3 files changed, 637 insertions(+), 4 deletions(-)
 create mode 100644 drivers/soc/aspeed/aspeed-lpc-uart-routing.c
drivers/soc/aspeed/Kconfig +11 -0
index 243ca196e6ad..6866757e6be2 100644
@@ -24,6 +24,17 @@ config ASPEED_LPC_SNOOP
 	  allows the BMC to listen on and save the data written by
 	  the host to an arbitrary LPC I/O port.
 
+config ASPEED_LPC_UART_ROUTING
+	tristate "ASPEED LPC uart routing control"
+	select REGMAP
+	select MFD_SYSCON
+	default ARCH_ASPEED
+	help
+	  Provides a driver to control the LPC UART routing paths.
+	  An sysfs interface is exported allowing users to perform
+	  runtime configuration of the RX muxes between the UART
+	  controllers and I/O pins.
+
 config ASPEED_P2A_CTRL
 	tristate "ASPEED P2A (VGA MMIO to BMC) bridge control"
 	select REGMAP
drivers/soc/aspeed/Makefile +5 -4
index fcab7192e1a4..87ad6578ddbb 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_ASPEED_LPC_CTRL)	+= aspeed-lpc-ctrl.o
-obj-$(CONFIG_ASPEED_LPC_SNOOP)	+= aspeed-lpc-snoop.o
-obj-$(CONFIG_ASPEED_P2A_CTRL)	+= aspeed-p2a-ctrl.o
-obj-$(CONFIG_ASPEED_SOCINFO)	+= aspeed-socinfo.o
+obj-$(CONFIG_ASPEED_LPC_CTRL)		+= aspeed-lpc-ctrl.o
+obj-$(CONFIG_ASPEED_LPC_SNOOP)		+= aspeed-lpc-snoop.o
+obj-$(CONFIG_ASPEED_LPC_UART_ROUTING)	+= aspeed-lpc-uart-routing.o
+obj-$(CONFIG_ASPEED_P2A_CTRL)		+= aspeed-p2a-ctrl.o
+obj-$(CONFIG_ASPEED_SOCINFO)		+= aspeed-socinfo.o
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +621 -0

621 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/2] soc: aspeed: Add LPC UART routing support

Quoted 2 lines · Chia-Wei Wang

Add driver support for the LPC UART routing control. Users can perform

As we discussed, remove the "LPC" part of the name.

Quoted 4 lines

runtime configuration of the RX muxes among the UART controllers and the UART TXD/RXD IO pins. This is achieved through the exported sysfs interface.

It would be good to have some example of how to use it, and the output from sysfs.

You should also add a patch to document the sysfs files in Documentation/ABI.

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 9

Quoted 11 lines

+++ b/drivers/soc/aspeed/aspeed-lpc-uart-routing.c

drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +9 -0
@@ -0,0 +1,621 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Google LLC
+ * Copyright (c) 2021 Aspeed Technology Inc.
+ */
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_address.h>

You can drop this one.

Quoted 27 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +27 -0
+#include <linux/of_platform.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+#include <linux/platform_device.h>
+
+/* register offsets */
+#define HICR9  0x98
+#define HICRA  0x9c
+
+/* attributes options */
+#define UART_ROUTING_IO1       "io1"
+#define UART_ROUTING_IO2       "io2"
+#define UART_ROUTING_IO3       "io3"
+#define UART_ROUTING_IO4       "io4"
+#define UART_ROUTING_IO5       "io5"
+#define UART_ROUTING_IO6       "io6"
+#define UART_ROUTING_IO10      "io10"
+#define UART_ROUTING_UART1     "uart1"
+#define UART_ROUTING_UART2     "uart2"
+#define UART_ROUTING_UART3     "uart3"
+#define UART_ROUTING_UART4     "uart4"
+#define UART_ROUTING_UART5     "uart5"
+#define UART_ROUTING_UART6     "uart6"
+#define UART_ROUTING_UART10    "uart10"
+#define UART_ROUTING_RES       "reserved"
+
+struct aspeed_uart_routing {

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 46

Quoted 10 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +10 -0
+       struct regmap *map;
+       spinlock_t lock;
+       struct attribute_group const *attr_grp;
+};
+
+struct aspeed_uart_routing_selector {
+       struct device_attribute dev_attr;
+       uint32_t reg;
+       uint32_t mask;
+       uint32_t shift;

These can be u8.

Quoted 9 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +9 -0
+static ssize_t aspeed_uart_routing_show(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       struct aspeed_uart_routing *uart_routing = dev_get_drvdata(dev);
+       struct aspeed_uart_routing_selector *sel = to_routing_selector(attr);
+       int val, pos, len;
+
+       regmap_read(uart_routing->map, sel->reg, &val);

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 512

Quoted 10 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +10 -0
+       val = (val >> sel->shift) & sel->mask;
+
+       len = 0;
+       for (pos = 0; sel->options[pos] != NULL; ++pos) {
+               if (pos == val) {
+                       len += snprintf(buf + len, PAGE_SIZE - 1 - len,
+                                       "[%s] ", sel->options[pos]);
+               } else {
+                       len += snprintf(buf + len, PAGE_SIZE - 1 - len,
+                                       "%s ", sel->options[pos]);

The kernel prefers sysfs_emit and sysfs_emit_at insteading of using snprintf directly.

Quoted 19 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +19 -0
+               }
+       }
+
+       if (val >= pos) {
+               len += snprintf(buf + len, PAGE_SIZE - 1 - len,
+                               "[unknown(%d)]", val);
+       }
+
+       len += snprintf(buf + len, PAGE_SIZE - 1 - len, "\n");
+
+       return len;
+}
+
+static ssize_t aspeed_uart_routing_store(struct device *dev,
+                                        struct device_attribute *attr,
+                                        const char *buf, size_t count)
+{
+       unsigned long flags;
+       struct aspeed_uart_routing *uart_routing = dev_get_drvdata(dev);

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 541

Quoted 10 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +10 -0
+       struct aspeed_uart_routing_selector *sel = to_routing_selector(attr);
+       int val;
+
+       val = match_string(sel->options, -1, buf);
+       if (val < 0) {
+               dev_err(dev, "invalid value \"%s\"\n", buf);
+               return -EINVAL;
+       }
+
+       spin_lock_irqsave(&uart_routing->lock, flags);

I can't see why you would need a spinlock here. The regmap has it's own locking so it will protect against concurrent updates to the registers.

Quoted 9 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +9 -0
+
+       regmap_update_bits(uart_routing->map, sel->reg,
+                       (sel->mask << sel->shift),
+                       (val & sel->mask) << sel->shift);
+
+       spin_unlock_irqrestore(&uart_routing->lock, flags);
+
+       return count;
+}

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 560

Quoted 10 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +10 -0
+
+static int aspeed_uart_routing_probe(struct platform_device *pdev)
+{
+       int rc;
+       struct device *dev = &pdev->dev;
+       struct aspeed_uart_routing *uart_routing;
+
+       uart_routing = devm_kzalloc(&pdev->dev,
+                                   sizeof(*uart_routing),
+                                   GFP_KERNEL);

You can reformat this file to have longer lines; the kernel is ok with up to 100 columsn these days.

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 562

Quoted 2 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +2 -0
+       if (!uart_routing) {
+               dev_err(dev, "cannot allocate memory\n");

I'd drop this error message.

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 574

Quoted 12 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +12 -0
+               return -ENOMEM;
+       }
+
+       uart_routing->map = syscon_node_to_regmap(dev->parent->of_node);
+       if (IS_ERR(uart_routing->map)) {
+               dev_err(dev, "cannot get regmap\n");
+               return PTR_ERR(uart_routing->map);
+       }
+
+       uart_routing->attr_grp = of_device_get_match_data(dev);
+
+       spin_lock_init(&uart_routing->lock);

I don't think you need the lock at all.

Cheers,

Joel

#3 lore raw

RE: [PATCH 1/2] soc: aspeed: Add LPC UART routing support

Quoted 13 lines

-----Original Message-----
From: Joel Stanley <[email protected]>
Sent: Wednesday, September 1, 2021 3:37 PM

Quoted 2 lines · Chia-Wei Wang

Add driver support for the LPC UART routing control. Users can perform

As we discussed, remove the "LPC" part of the name.

Quoted 2 lines

runtime configuration of the RX muxes among the UART controllers and the UART TXD/RXD IO pins. This is achieved through the exported sysfs

Quoted 9 lines

interface.

Quoted 2 lines

It would be good to have some example of how to use it, and the output from sysfs.

You should also add a patch to document the sysfs files in Documentation/ABI.

Will add a new commit for the sysfs description.

Quoted 5 lines
Quoted 5 lines

+++ b/drivers/soc/aspeed/aspeed-lpc-uart-routing.c

drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +3 -0
@@ -0,0 +1,621 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Google LLC
Quoted 8 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 9

Quoted 6 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +6 -0
+ * Copyright (c) 2021 Aspeed Technology Inc.
+ */
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_address.h>

You can drop this one.

Revised as suggested.

Quoted 31 lines
Quoted 31 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +30 -0
+#include <linux/of_platform.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+#include <linux/platform_device.h>
+
+/* register offsets */
+#define HICR9  0x98
+#define HICRA  0x9c
+
+/* attributes options */
+#define UART_ROUTING_IO1       "io1"
+#define UART_ROUTING_IO2       "io2"
+#define UART_ROUTING_IO3       "io3"
+#define UART_ROUTING_IO4       "io4"
+#define UART_ROUTING_IO5       "io5"
+#define UART_ROUTING_IO6       "io6"
+#define UART_ROUTING_IO10      "io10"
+#define UART_ROUTING_UART1     "uart1"
+#define UART_ROUTING_UART2     "uart2"
+#define UART_ROUTING_UART3     "uart3"
+#define UART_ROUTING_UART4     "uart4"
+#define UART_ROUTING_UART5     "uart5"
+#define UART_ROUTING_UART6     "uart6"
+#define UART_ROUTING_UART10    "uart10"
+#define UART_ROUTING_RES       "reserved"
+
+struct aspeed_uart_routing {
+       struct regmap *map;
+       spinlock_t lock;
+       struct attribute_group const *attr_grp; };
Quoted 8 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 46

Quoted 6 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +6 -0
+
+struct aspeed_uart_routing_selector {
+       struct device_attribute dev_attr;
+       uint32_t reg;
+       uint32_t mask;
+       uint32_t shift;

These can be u8.

Revised as suggested.

Quoted 8 lines

Review line 47

Quoted 3 lines
(quoted diff) +2 -0
+static ssize_t aspeed_uart_routing_show(struct device *dev,
+                                       struct device_attribute

*attr,

Review line 50

Quoted 3 lines
(quoted diff) +3 -0
+                                       char *buf) {
+       struct aspeed_uart_routing *uart_routing = dev_get_drvdata(dev);
+       struct aspeed_uart_routing_selector *sel =

to_routing_selector(attr);

Quoted 16 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 512

Quoted 13 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +13 -0
+       int val, pos, len;
+
+       regmap_read(uart_routing->map, sel->reg, &val);
+       val = (val >> sel->shift) & sel->mask;
+
+       len = 0;
+       for (pos = 0; sel->options[pos] != NULL; ++pos) {
+               if (pos == val) {
+                       len += snprintf(buf + len, PAGE_SIZE - 1 - len,
+                                       "[%s] ", sel->options[pos]);
+               } else {
+                       len += snprintf(buf + len, PAGE_SIZE - 1 - len,
+                                       "%s ", sel->options[pos]);

The kernel prefers sysfs_emit and sysfs_emit_at insteading of using snprintf directly.

Revised as suggested.

Quoted 23 lines
Quoted 6 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +5 -0
+               }
+       }
+
+       if (val >= pos) {
+               len += snprintf(buf + len, PAGE_SIZE - 1 - len,

drivers/soc/aspeed/aspeed-lpc-uart-routing.c

Quoted 10 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +10 -0
+                               "[unknown(%d)]", val);
+       }
+
+       len += snprintf(buf + len, PAGE_SIZE - 1 - len, "\n");
+
+       return len;
+}
+
+static ssize_t aspeed_uart_routing_store(struct device *dev,
+                                        struct device_attribute

*attr,

Review line 83

Quoted 5 lines
(quoted diff) +5 -0
+                                        const char *buf, size_t
+count) {
+       unsigned long flags;
+       struct aspeed_uart_routing *uart_routing = dev_get_drvdata(dev);
+       struct aspeed_uart_routing_selector *sel =

to_routing_selector(attr);

Quoted 12 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 541

Quoted 9 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +9 -0
+       int val;
+
+       val = match_string(sel->options, -1, buf);
+       if (val < 0) {
+               dev_err(dev, "invalid value \"%s\"\n", buf);
+               return -EINVAL;
+       }
+
+       spin_lock_irqsave(&uart_routing->lock, flags);

I can't see why you would need a spinlock here. The regmap has it's own locking so it will protect against concurrent updates to the registers.

You are right. Lock is not needed here. Will removed it as suggested.

Quoted 23 lines
Quoted 9 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +8 -0
+
+       regmap_update_bits(uart_routing->map, sel->reg,
+                       (sel->mask << sel->shift),
+                       (val & sel->mask) << sel->shift);
+
+       spin_unlock_irqrestore(&uart_routing->lock, flags);
+
+       return count;

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 560

Quoted 10 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +10 -0
+}
+
+static int aspeed_uart_routing_probe(struct platform_device *pdev) {
+       int rc;
+       struct device *dev = &pdev->dev;
+       struct aspeed_uart_routing *uart_routing;
+
+       uart_routing = devm_kzalloc(&pdev->dev,
+                                   sizeof(*uart_routing),
+                                   GFP_KERNEL);

You can reformat this file to have longer lines; the kernel is ok with up to 100 columsn these days.

Quoted 4 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 562

Quoted 2 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +2 -0
+       if (!uart_routing) {
+               dev_err(dev, "cannot allocate memory\n");

I'd drop this error message.

Revised as suggested

Quoted 6 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c

Quoted 5 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +4 -0
+               return -ENOMEM;
+       }
+
+       uart_routing->map =

syscon_node_to_regmap(dev->parent->of_node);

Quoted 10 lines

drivers/soc/aspeed/aspeed-lpc-uart-routing.c line 574

Quoted 8 lines
drivers/soc/aspeed/aspeed-lpc-uart-routing.c new file +8 -0
+       if (IS_ERR(uart_routing->map)) {
+               dev_err(dev, "cannot get regmap\n");
+               return PTR_ERR(uart_routing->map);
+       }
+
+       uart_routing->attr_grp = of_device_get_match_data(dev);
+
+       spin_lock_init(&uart_routing->lock);

I don't think you need the lock at all.

Same as above.

Thanks for reviewing this.
The v2 patch will include the driver refactoring and additional documentation.

Chiawei

#4 lore raw

PATCH 2/2 ARM: dts: aspeed: Add uart routing to device tree

In reply to Chia-Wei Wang

Add LPC uart routing to the device tree for Aspeed AST25xx/AST26xx SoCs.

---
 arch/arm/boot/dts/aspeed-g5.dtsi | 6 ++++++
 arch/arm/boot/dts/aspeed-g6.dtsi | 6 ++++++
 2 files changed, 12 insertions(+)
arch/arm/boot/dts/aspeed-g5.dtsi +6 -0
index 329eaeef66fb..ba7744cb0842 100644
@@ -492,6 +492,12 @@
 					#reset-cells = <1>;
 				};
 
+				lpc_uart_routing: lpc-uart-routing at 98 {
+					compatible = "aspeed,ast2500-lpc-uart-routing";
+					reg = <0x98 0x8>;
+					status = "disabled";
+				};
+
 				lhc: lhc at a0 {
 					compatible = "aspeed,ast2500-lhc";
 					reg = <0xa0 0x24 0xc8 0x8>;
arch/arm/boot/dts/aspeed-g6.dtsi +6 -0
index f96607b7b4e2..3699c50a2945 100644
@@ -523,6 +523,12 @@
 					#reset-cells = <1>;
 				};
 
+				lpc_uart_routing: lpc-uart-routing at 98 {
+					compatible = "aspeed,ast2600-lpc-uart-routing";
+					reg = <0x98 0x8>;
+					status = "disabled";
+				};
+
 				ibt: ibt at 140 {
 					compatible = "aspeed,ast2600-ibt-bmc";
 					reg = <0x140 0x18>;
Signature · 1 line
2.17.1
maintainer
#5 lore raw
In reply to Chia-Wei Wang
Quoted 2 lines · Chia-Wei Wang

Add LPC uart routing driver and the device tree nodes.

Thanks for submitting this driver. There are many parties who are interested in this, so hopefully they can step forward and review.

Is this LPC UART routing, or UART routing in general? I know the register to control the routing is hidden in the LPC space, but I thought it was just general routing. I would drop the LPC part of the name.

You also need to update the bindings document with the new compatible string. Send a patch for Documentation/devicetree/bindings/mfd/aspeed-lpc.txt.

Cheers,

Joel

Quoted 16 lines

Chia-Wei Wang (2):
soc: aspeed: Add LPC UART routing support
ARM: dts: aspeed: Add uart routing to device tree

 arch/arm/boot/dts/aspeed-g5.dtsi             |   6 +
 arch/arm/boot/dts/aspeed-g6.dtsi             |   6 +
 drivers/soc/aspeed/Kconfig                   |  11 +
 drivers/soc/aspeed/Makefile                  |   9 +-
 drivers/soc/aspeed/aspeed-lpc-uart-routing.c | 621 +++++++++++++++++++
 5 files changed, 649 insertions(+), 4 deletions(-)
 create mode 100644 drivers/soc/aspeed/aspeed-lpc-uart-routing.c

--
2.17.1

#6 lore raw

Hi Joel,

Quoted 11 lines

From: Joel Stanley <[email protected]>
Sent: Wednesday, September 1, 2021 3:04 PM

Quoted 2 lines · Chia-Wei Wang

Add LPC uart routing driver and the device tree nodes.

Thanks for submitting this driver. There are many parties who are interested in this, so hopefully they can step forward and review.

Quoted 6 lines

Is this LPC UART routing, or UART routing in general? I know the register to control the routing is hidden in the LPC space, but I thought it was just general routing. I would drop the LPC part of the name.

You also need to update the bindings document with the new compatible string. Send a patch for Documentation/devicetree/bindings/mfd/aspeed-lpc.txt.

Thanks for the feedback.

The UART routing is general.
I will send a v2 patch which drops the LPC part of name. And the compatible string will also be updated to the dt-bindings.

Chiawei