mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] sandbox: io: alias first page of I/O memory to I/O port space
@ 2024-07-01  7:27 Ahmad Fatoum
  2024-07-01  7:27 ` [PATCH 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-01  7:27 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We already emulate 64KiB of port space by directing (in|out)[bwl] accesses
to the __pci_iobase static array.

By have (read|write)[bwlq] access the first 4K of that port space when
trying to access the NULL page.

That way generic drivers like e.g. pinctrl-single can be trivially
described in the device tree without having to worry about runtime fixup
of the base address in the DT.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/sandbox/include/asm/io.h | 70 +++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index eec279b88834..81e9a78151c1 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -3,12 +3,82 @@
 #ifndef __ASM_SANDBOX_IO_H
 #define __ASM_SANDBOX_IO_H
 
+#include <linux/types.h>
+#include <linux/compiler.h>
+
 #define	IO_SPACE_LIMIT 0xffff
 /* pacify static analyzers */
 #define PCI_IOBASE     ((void __iomem *)__pci_iobase)
 
 extern unsigned char __pci_iobase[IO_SPACE_LIMIT];
 
+/*
+ * Alias first page of I/O memory to I/O port space
+ */
+static inline volatile void __iomem *
+__xlate_addr(const volatile void __iomem *addr)
+{
+	if ((uintptr_t)addr  < 0x1000)
+		addr += (uintptr_t)__pci_iobase;
+	return (volatile void __iomem *)addr;
+}
+
+#define __raw_readb __raw_readb
+static inline u8 __raw_readb(const volatile void __iomem *addr)
+{
+	return *(const volatile u8 __force *)__xlate_addr(addr);
+}
+
+#define __raw_readw __raw_readw
+static inline u16 __raw_readw(const volatile void __iomem *addr)
+{
+	return *(const volatile u16 __force *)__xlate_addr(addr);
+}
+
+#define __raw_readl __raw_readl
+static inline u32 __raw_readl(const volatile void __iomem *addr)
+{
+	return *(const volatile u32 __force *)__xlate_addr(addr);
+}
+
+#ifdef CONFIG_64BIT
+#define __raw_readq __raw_readq
+static inline u64 __raw_readq(const volatile void __iomem *addr)
+{
+	return *(const volatile u64 __force *)__xlate_addr(addr);
+}
+#endif /* CONFIG_64BIT */
+
+#define __raw_writeb __raw_writeb
+static inline void __raw_writeb(u8 value, volatile void __iomem *addr)
+{
+	*(volatile u8 __force *)__xlate_addr(addr) = value;
+}
+
+#define __raw_writew __raw_writew
+static inline void __raw_writew(u16 value, volatile void __iomem *addr)
+{
+	*(volatile u16 __force *)__xlate_addr(addr) = value;
+}
+
+#ifndef __raw_writel
+#define __raw_writel __raw_writel
+static inline void __raw_writel(u32 value, volatile void __iomem *addr)
+{
+	*(volatile u32 __force *)__xlate_addr(addr) = value;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#define __raw_writeq __raw_writeq
+static inline void __raw_writeq(u64 value, volatile void __iomem *addr)
+{
+	*(volatile u64 __force *)__xlate_addr(addr) = value;
+}
+#endif /* CONFIG_64BIT */
+
+#undef __xlate_addr
+
 #include <asm-generic/io.h>
 
 #endif /* __ASM_SANDBOX_IO_H */
-- 
2.39.2




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

* [PATCH 2/2] sandbox: add dummy pinctrl nodes
  2024-07-01  7:27 [PATCH 1/2] sandbox: io: alias first page of I/O memory to I/O port space Ahmad Fatoum
@ 2024-07-01  7:27 ` Ahmad Fatoum
  0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-01  7:27 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Now that MMIO addresses 0-1023 point at valid memory, let's use it
describe a fake pinctrl-single controller. This allows testing common
pinctrl code in sandbox.

Device parameter support to select the state will follow later.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/sandbox/dts/sandbox.dts | 53 ++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index f3fe6ce65c08..bb37cfeaf9a2 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -108,19 +108,72 @@ power {
 		compatible = "barebox,sandbox-power";
 		nvmem-cell-names = "reset-source";
 		nvmem-cells = <&reset_source>;
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_power_default>;
+		pinctrl-1 = <&pinctrl_power_sleep>;
 	};
 
 	watchdog {
 		compatible = "barebox,sandbox-watchdog";
 		nvmem-cell-names = "reset-source";
 		nvmem-cells = <&reset_source>;
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_watchdog_default>;
+		pinctrl-1 = <&pinctrl_watchdog_sleep>;
 	};
 
 	sound {
 		compatible = "barebox,sandbox-sound";
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_sound_default>;
+		pinctrl-1 = <&pinctrl_sound_sleep>;
 	};
 
 	led {
 		compatible = "barebox,sandbox-led";
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_led_default>;
+		pinctrl-1 = <&pinctrl_led_sleep>;
+	};
+
+	pinctrl {
+		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_power_default: power-default-pins {
+			pinctrl-single,pins = <0x00	0x01>;
+		};
+
+		pinctrl_power_sleep: power-sleep-pins {
+			pinctrl-single,pins = <0x00	0x02>;
+		};
+
+		pinctrl_watchdog_default: watchdog-default-pins {
+			pinctrl-single,pins = <0x01	0x01>;
+		};
+
+		pinctrl_watchdog_sleep: watchdog-sleep-pins {
+			pinctrl-single,pins = <0x01	0x02>;
+		};
+
+		pinctrl_sound_default: sound-default-pins {
+			pinctrl-single,pins = <0x02	0x01>;
+		};
+
+		pinctrl_sound_sleep: sound-sleep-pins {
+			pinctrl-single,pins = <0x02	0x02>;
+		};
+
+		pinctrl_led_default: led-default-pins {
+			pinctrl-single,pins = <0x03	0x01>;
+		};
+
+		pinctrl_led_sleep: led-sleep-pins {
+			pinctrl-single,pins = <0x03	0x02>;
+		};
 	};
 };
-- 
2.39.2




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

end of thread, other threads:[~2024-07-01  7:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01  7:27 [PATCH 1/2] sandbox: io: alias first page of I/O memory to I/O port space Ahmad Fatoum
2024-07-01  7:27 ` [PATCH 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum

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