Skip to contentSkip to conversation

fsi: aspeed: Support fsi pin muxing

PATCH Superseded Joel Stanley 2 participants 5 messages Mar 24, 2020 – Mar 27, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joel Stanley

author maintainer
#0 lore raw

cover fsi: aspeed: Support fsi pin muxing

This adds support for configuring the PCB pinout (not the ASPEED pads) used for FSI depending on the state of a GPIO.

Joel Stanley (2):
ARM: dts: aspeed: tacoma: Add GPIOs for FSI
fsi: aspeed: Support cabled FSI

 arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts |  9 ++---
 drivers/fsi/fsi-master-aspeed.c             | 45 +++++++++++++++++++++
 2 files changed, 48 insertions(+), 6 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/2 ARM: dts: aspeed: tacoma: Add GPIOs for FSI

GPIO Q7 is no longer used for air/water. It is repurposed on Tacoma to indicate cabled (low) vs internal FSI (high).

GPIO B0 controls the muxing of FSI to the cable (low) or internal pins (high).

---
 arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts +3 -6
index 88ef4af7b234..be699fd4ad22 100644
@@ -34,12 +34,6 @@
 	gpio-keys {
 		compatible = "gpio-keys";
 
-		air-water {
-			label = "air-water";
-			gpios = <&gpio0 ASPEED_GPIO(Q, 7) GPIO_ACTIVE_LOW>;
-			linux,code = <ASPEED_GPIO(Q, 7)>;
-		};
-
 		checkstop {
 			label = "checkstop";
 			gpios = <&gpio0 ASPEED_GPIO(E, 3) GPIO_ACTIVE_LOW>;
@@ -178,6 +172,9 @@
 	#address-cells = <2>;
 	#size-cells = <0>;
 
+	fsi-routing-gpios = <&gpio0 ASPEED_GPIO(Q, 7) GPIO_ACTIVE_HIGH>;
+	fsi-mux-gpios = <&gpio0 ASPEED_GPIO(B, 0) GPIO_ACTIVE_HIGH>;
+
 	cfam@0,0 {
 		reg = <0 0>;
 		#address-cells = <1>;
Signature · 1 line
2.25.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH linux dev-5.4 1/2] ARM: dts: aspeed: tacoma: Add GPIOs for FSI

Quoted 7 lines · Joel Stanley

GPIO Q7 is no longer used for air/water. It is repurposed on Tacoma to indicate cabled (low) vs internal FSI (high).

GPIO B0 controls the muxing of FSI to the cable (low) or internal pins (high).

Good times.

author maintainer
#3 lore raw

PATCH 2/2 fsi: aspeed: Support cabled FSI

In reply to Joel Stanley

Some FSI development systems have internally routed FSI signals, and some have external cabled FSI. Software can detect which machine this is by reading a jumper GPIO, and also control which pins the signals are routed to through a mux GPIO.

This attempts to find the GPIOs at probe time. If they are not present in the device tree the driver will not error and continue as before.

The mux GPIO is owned by the FSI driver to ensure it is not modified at runtime. The jumper is freed to allow other software to inspect it's state.

---
 drivers/fsi/fsi-master-aspeed.c | 45 +++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/fsi/fsi-master-aspeed.c +45 -0
index f49742b310c2..3436805d590a 100644
@@ -13,6 +13,7 @@
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/iopoll.h>
+#include <linux/gpio/consumer.h>
 
 #include "fsi-master.h"
 
@@ -419,6 +420,44 @@ static int aspeed_master_init(struct fsi_master_aspeed *aspeed)
 	return 0;
 }
 
+static int tacoma_cabled_fsi_fixup(struct device *dev)
+{
+	struct gpio_desc *routing_gpio, *mux_gpio;
+	int gpio;
+
+	/*
+	 * The routing GPIO is a jumper indicating we should mux for the
+	 * externally routed FSI cable.
+	 */
+	routing_gpio = devm_gpiod_get_optional(dev, "fsi-routing", GPIOD_IN);
+	if (IS_ERR(routing_gpio))
+		return PTR_ERR(routing_gpio);
+	if (!routing_gpio)
+		return 0;
+
+	mux_gpio = devm_gpiod_get_optional(dev, "fsi-mux", GPIOD_IN);
+	if (IS_ERR(mux_gpio))
+		return PTR_ERR(mux_gpio);
+	if (!mux_gpio)
+		return 0;
+
+	gpio = gpiod_get_value(routing_gpio);
+	if (gpio < 0)
+		return 0;
+
+	/* If the routing GPIO is low we should set the mux to low. */
+	if (gpio == 0) {
+		gpiod_set_value(mux_gpio, 0);
+		dev_info(dev, "FSI configured for external cable\n");
+	}
+
+	/* Free the cabled mux GPIO for other users to sample */
+	devm_gpiod_put(dev, routing_gpio);
+
+	return 0;
+}
+
+
 static int fsi_master_aspeed_probe(struct platform_device *pdev)
 {
 	struct fsi_master_aspeed *aspeed;
@@ -426,6 +465,12 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	int rc, links, reg;
 	__be32 raw;
 
+	rc = tacoma_cabled_fsi_fixup(&pdev->dev);
+	if (rc) {
+		dev_err(&pdev->dev, "Tacoma FSI cable fixup failed\n");
+		return rc;
+	}
+
 	aspeed = devm_kzalloc(&pdev->dev, sizeof(*aspeed), GFP_KERNEL);
 	if (!aspeed)
 		return -ENOMEM;
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH linux dev-5.4 2/2] fsi: aspeed: Support cabled FSI

Quoted 44 lines · Joel Stanley

Some FSI development systems have internally routed FSI signals, and some have external cabled FSI. Software can detect which machine this is by reading a jumper GPIO, and also control which pins the signals are routed to through a mux GPIO.

This attempts to find the GPIOs at probe time. If they are not present in the device tree the driver will not error and continue as before.

The mux GPIO is owned by the FSI driver to ensure it is not modified at runtime. The jumper is freed to allow other software to inspect it's state.

---
 drivers/fsi/fsi-master-aspeed.c | 45 +++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/fsi/fsi-master-aspeed.c +11 -0
index f49742b310c2..3436805d590a 100644
@@ -13,6 +13,7 @@
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/iopoll.h>
+#include <linux/gpio/consumer.h>
 
 #include "fsi-master.h"
 
@@ -419,6 +420,44 @@ static int aspeed_master_init(struct 
 fsi_master_aspeed *aspeed)
 	return 0;
 }
 
+static int tacoma_cabled_fsi_fixup(struct device *dev)
+{
+	struct gpio_desc *routing_gpio, *mux_gpio;
+	int gpio;
+
+	/*
+	 * The routing GPIO is a jumper indicating we should mux for the
+	 * externally routed FSI cable.
+	 */
+	routing_gpio = devm_gpiod_get_optional(dev, "fsi-routing", GPIOD_IN);

drivers/fsi/fsi-master-aspeed.c static int aspeed_master_init(struct · line 443

Quoted 10 lines
drivers/fsi/fsi-master-aspeed.c +10 -0
+	if (IS_ERR(routing_gpio))
+		return PTR_ERR(routing_gpio);
+	if (!routing_gpio)
+		return 0;
+
+	mux_gpio = devm_gpiod_get_optional(dev, "fsi-mux", GPIOD_IN);
+	if (IS_ERR(mux_gpio))
+		return PTR_ERR(mux_gpio);
+	if (!mux_gpio)
+		return 0;

This leaks routing_gpio.

drivers/fsi/fsi-master-aspeed.c static int aspeed_master_init(struct fsi_master_aspeed *aspeed) · line 452

Quoted 10 lines
drivers/fsi/fsi-master-aspeed.c +10 -0
+
+	gpio = gpiod_get_value(routing_gpio);
+	if (gpio < 0)
+		return 0;
+
+	/* If the routing GPIO is low we should set the mux to low. */
+	if (gpio == 0) {
+		gpiod_set_value(mux_gpio, 0);
+		dev_info(dev, "FSI configured for external cable\n");
+	}

Is mux_gpio pulled up? Also you're acquiring mux_gpio using the GPIOD_IN flag - the dt patch only specifies GPIO_ACTIVE_HIGH which means its implicitly push-pull, but we're not changing the direction before setting the value.

I feel like we should explicitly set the value either way, or at least document the pull-up state in a comment if the gpio is indeed pulled up.

drivers/fsi/fsi-master-aspeed.c static int aspeed_master_init(struct fsi_master_aspeed *aspeed) · line 455

Quoted 3 lines
drivers/fsi/fsi-master-aspeed.c +3 -0
+
+	/* Free the cabled mux GPIO for other users to sample */
+	devm_gpiod_put(dev, routing_gpio);

The comment mentions "mux GPIO" but then does the put for routing_gpio. I think you can improve the clarity of the comment to make it more obvious that it's meant to apply to routing_gpio and it isn't a mistake in the code.

Can you also add to the comment why you're not putting mux_gpio?

Quoted 26 lines
drivers/fsi/fsi-master-aspeed.c +5 -0
+
+	return 0;
+}
+
+
 static int fsi_master_aspeed_probe(struct platform_device *pdev)
 {
drivers/fsi/fsi-master-aspeed.c +6 -0
 	struct fsi_master_aspeed *aspeed;
@@ -426,6 +465,12 @@ static int fsi_master_aspeed_probe(struct 
 platform_device *pdev)
 	int rc, links, reg;
 	__be32 raw;
 
+	rc = tacoma_cabled_fsi_fixup(&pdev->dev);
+	if (rc) {
+		dev_err(&pdev->dev, "Tacoma FSI cable fixup failed\n");
+		return rc;
+	}
+
 	aspeed = devm_kzalloc(&pdev->dev, sizeof(*aspeed), GFP_KERNEL);
 	if (!aspeed)

return -ENOMEM;

Signature · 1 line
2.25.1