mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space
@ 2024-07-16 12:03 Ahmad Fatoum
  2024-07-16 12:03 ` [PATCH v2 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum
  2024-07-19 12:31 ` [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 12:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We currently define __pci_iobase to please static analyzers that would
otherwise complain about inb/outb and friends accessing the NULL page.

Let's make better use of it and add a node representing it to the device
tree. This way we can add simple memory mapped peripherals on top that
just need writable registers that can be read back in tests.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - new commit: instead of messing with readb/writeb and friends'
    definition, we just do a device tree fixup
---
 arch/sandbox/board/Makefile   |  1 +
 arch/sandbox/board/devices.c  |  2 --
 arch/sandbox/board/io-ports.c | 35 +++++++++++++++++++++++++++++++++++
 arch/sandbox/dts/sandbox.dts  |  6 ++++++
 4 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 arch/sandbox/board/io-ports.c

diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index b4bab02163fb..8e6e1d2d8843 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
+obj-y += io-ports.o
 obj-y += board.o
 obj-y += clock.o
 obj-y += hostfile.o
diff --git a/arch/sandbox/board/devices.c b/arch/sandbox/board/devices.c
index ecd24e920721..0f344017b213 100644
--- a/arch/sandbox/board/devices.c
+++ b/arch/sandbox/board/devices.c
@@ -10,8 +10,6 @@
 #include <mach/linux.h>
 #include <asm/io.h>
 
-unsigned char __pci_iobase[IO_SPACE_LIMIT];
-
 static LIST_HEAD(sandbox_device_list);
 
 int sandbox_add_device(struct device *dev)
diff --git a/arch/sandbox/board/io-ports.c b/arch/sandbox/board/io-ports.c
new file mode 100644
index 000000000000..c5a26cdd0155
--- /dev/null
+++ b/arch/sandbox/board/io-ports.c
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm/io.h>
+#include <driver.h>
+#include <of.h>
+
+unsigned char __pci_iobase[IO_SPACE_LIMIT];
+
+static int ioport_bus_probe(struct device *dev)
+{
+	struct device_node *bus = dev->of_node;
+	u64 arr[3] = {
+		0,				/* child bus address */
+		virt_to_phys(__pci_iobase),	/* parent bus address */
+		sizeof(__pci_iobase),		/* resource size */
+	};
+
+	of_property_write_u64_array(bus, "reg", &arr[1], 2);
+	of_property_write_u64_array(bus, "ranges", &arr[0], 3);
+
+	return of_platform_populate(bus, of_default_bus_match_table, dev);
+}
+
+static __maybe_unused struct of_device_id sandbox_ioport_dt_ids[] = {
+	{ .compatible = "barebox,sandbox-ioport-bus", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, sandbox_ioport_dt_ids);
+
+static struct driver sandbox_ioport_driver = {
+	.name  = "sandbox-ioport-bus",
+	.of_compatible = sandbox_ioport_dt_ids,
+	.probe = ioport_bus_probe,
+};
+postcore_platform_driver(sandbox_ioport_driver);
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 3ed2c115a67e..ea75f3a6a9b0 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -55,6 +55,12 @@ y {
 		};
 	};
 
+	io-ports {
+		compatible = "barebox,sandbox-ioport-bus";
+		#address-cells = <2>;
+		#size-cells = <2>;
+	};
+
 	stickypage: stickypage {
 		compatible = "barebox,stickypage", "syscon";
 		reg = <0 0 0 4096>;
-- 
2.39.2




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

* [PATCH v2 2/2] sandbox: add dummy pinctrl nodes
  2024-07-16 12:03 [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Ahmad Fatoum
@ 2024-07-16 12:03 ` Ahmad Fatoum
  2024-07-19 12:31 ` [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 12:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Now that I/O ports are represented in the device tree , let's use it
describe a fake pinctrl-single controller. This allows testing common
pinctrl code in sandbox.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - remove power/watchdog pinmux to reduce dupication
  - add an unknown device to test that scenario too
---
 arch/sandbox/dts/sandbox.dts | 41 ++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index ea75f3a6a9b0..cf47513c76fe 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -59,6 +59,35 @@ io-ports {
 		compatible = "barebox,sandbox-ioport-bus";
 		#address-cells = <2>;
 		#size-cells = <2>;
+
+		pinctrl@0 {
+			compatible = "pinctrl-single";
+			/* Proxy 0 addressing */
+			reg = <0x0 0x0 0x0 0x4>;
+			#pinctrl-cells = <1>;
+			pinctrl-single,register-width = <8>;
+			pinctrl-single,function-mask = <0x0000000f>;
+
+			pinctrl_sound_default: sound-default-pins {
+				pinctrl-single,pins = <0x00	0x01>;
+			};
+
+			pinctrl_sound_sleep: sound-sleep-pins {
+				pinctrl-single,pins = <0x00	0x02>;
+			};
+
+			pinctrl_led_default: led-default-pins {
+				pinctrl-single,pins = <0x01	0x01>;
+			};
+
+			pinctrl_led_sleep: led-sleep-pins {
+				pinctrl-single,pins = <0x01	0x02>;
+			};
+
+			pinctrl_unknown_default: unknown-default-pins {
+				pinctrl-single,pins = <0x02	0x01>;
+			};
+		};
 	};
 
 	stickypage: stickypage {
@@ -128,9 +157,21 @@ watchdog {
 
 	sound {
 		compatible = "barebox,sandbox-sound";
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_sound_default>;
+		pinctrl-1 = <&pinctrl_sound_sleep>;
+	};
+
+	unknown-device {
+		compatible = "barebox,unknown-device";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_unknown_default>;
 	};
 
 	led {
 		compatible = "barebox,sandbox-led";
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_led_default>;
+		pinctrl-1 = <&pinctrl_led_sleep>;
 	};
 };
-- 
2.39.2




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

* Re: [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space
  2024-07-16 12:03 [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Ahmad Fatoum
  2024-07-16 12:03 ` [PATCH v2 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum
@ 2024-07-19 12:31 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-07-19 12:31 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Tue, 16 Jul 2024 14:03:09 +0200, Ahmad Fatoum wrote:
> We currently define __pci_iobase to please static analyzers that would
> otherwise complain about inb/outb and friends accessing the NULL page.
> 
> Let's make better use of it and add a node representing it to the device
> tree. This way we can add simple memory mapped peripherals on top that
> just need writable registers that can be read back in tests.
> 
> [...]

Applied, thanks!

[1/2] sandbox: alias I/O ports region in MMIO space
      https://git.pengutronix.de/cgit/barebox/commit/?id=eaa990eef328 (link may not be stable)
[2/2] sandbox: add dummy pinctrl nodes
      https://git.pengutronix.de/cgit/barebox/commit/?id=700ff2933ae8 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-07-19 12:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 12:03 [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Ahmad Fatoum
2024-07-16 12:03 ` [PATCH v2 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum
2024-07-19 12:31 ` [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox