summary refs log tree commit diff
path: root/dts
diff options
context:
space:
mode:
Diffstat (limited to 'dts')
-rw-r--r--dts/mhs35-overlay.dts74
-rw-r--r--dts/mhs35-touch-overlay.dts91
2 files changed, 165 insertions, 0 deletions
diff --git a/dts/mhs35-overlay.dts b/dts/mhs35-overlay.dts
new file mode 100644
index 0000000..e30e596
--- /dev/null
+++ b/dts/mhs35-overlay.dts
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * device tree overlay for a goodtft mhs-3.5 raspberry pi spi display.
+ *
+ * for touch, see `./mhs35-touch-overlay.dts`!
+ *
+ * Copyright (c) 2026 Mel G. <mel@rnrd.eu>
+ */
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "brcm,bcm2711";
+
+	fragment@0 {
+		target = <&spi0>;
+
+		__overlay__ {
+			status = "okay";
+
+			spidev@0 {
+				status = "disabled";
+			};
+		};
+	};
+
+	fragment@1 {
+		target = <&gpio>;
+
+		__overlay__ {
+			mhs35_pins: mhs35_pins@0 {
+				brcm,pins = <25 24>; // reset, dc
+				brcm,function = <0 0>;
+			};
+		};
+	};
+
+	fragment@2 {
+		target = <&spi0>;
+
+		__overlay__ {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			mhs35: mhs35@0 {
+				compatible = "goodtft,mhs35";
+				reg = <0>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&mhs35_pins>;
+
+				// very conservative default that works pretty well,
+				// though is quite slow (you can see the screen update!)
+				// according to spec, should go upto 125mhz.
+				spi-max-frequency = <8000000>;
+
+				// orientation relative to a raspberry pi 4:
+				// 0 = landscape, usb/ethernet ports on left
+				// 180 = landscape, ports on right
+				// 90 = portrait, ports on top
+				// 270 portrait, ports on bottom
+				rotation = <180>;
+
+				reset-gpios = <&gpio 25 1>;
+				dc-gpios = <&gpio 24 0>;
+			};
+		};
+	};
+
+	__overrides__ {
+		speed =    <&mhs35>,"spi-max-frequency:0";
+		rotation = <&mhs35>,"rotation:0";
+	};
+};
diff --git a/dts/mhs35-touch-overlay.dts b/dts/mhs35-touch-overlay.dts
new file mode 100644
index 0000000..3b1c256
--- /dev/null
+++ b/dts/mhs35-touch-overlay.dts
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * device tree overlay for the mhs-3.5 ads7846 resistive touch controller.
+ *
+ * fits in with `./mhs35-overlay.dts`!
+ *
+ * Copyright (c) 2026 Mel G. <mel@rnrd.eu>
+ */
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "brcm,bcm2711";
+
+	fragment@0 {
+		target = <&spi0>;
+
+		__overlay__ {
+			status = "okay";
+
+			spidev@1 {
+				status = "disabled";
+			};
+		};
+	};
+
+	fragment@1 {
+		target = <&gpio>;
+
+		__overlay__ {
+			mhs35_touch_pins: mhs35_touch_pins@0 {
+				brcm,pins = <17>; // pen-irq
+				brcm,function = <0>; // in
+				brcm,pull = <2>; // up
+			};
+		};
+	};
+
+	fragment@2 {
+		target = <&spi0>;
+
+		__overlay__ {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			mhs35_touch: ads7846@1 {
+				compatible = "ti,ads7846";
+				reg = <1>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&mhs35_touch_pins>;
+
+				// adc should run at 2mhz as specced, anything
+				// slower makes reading drift and drag weirdly!
+				spi-max-frequency = <2000000>;
+				interrupts = <17 2>; // falling edge
+				interrupt-parent = <&gpio>;
+				pendown-gpio = <&gpio 17 1>; // pen-irq, check pins!
+
+				// these values try to supress garbage data on press,
+				// without these, clicks are weird and unreliable!
+				ti,keep-vref-on;
+				ti,settle-delay-usec = /bits/ 16 <150>;
+				ti,debounce-max = /bits/ 16 <10>;
+				ti,debounce-tol = /bits/ 16 <30>;
+				ti,debounce-rep = /bits/ 16 <1>;
+
+				// NOTE(mel): these values do *not* calibrate the screenspace
+				// coordination in accordance with the rotation by themselves!
+				// the exact matrices are set via libinput in userspace.
+				// see: `module.nix`
+				ti,x-min = /bits/ 16 <200>;
+				ti,y-min = /bits/ 16 <200>;
+				ti,x-max = /bits/ 16 <3900>;
+				ti,y-max = /bits/ 16 <3900>;
+				// some basic pressure values provided by goodtft,
+				// could be tuned maybe.
+				ti,pressure-min = /bits/ 16 <0>;
+				ti,pressure-max = /bits/ 16 <255>;
+				ti,x-plate-ohms = /bits/ 16 <150>;
+			};
+		};
+	};
+
+	__overrides__ {
+		touch_speed =  <&mhs35_touch>,"spi-max-frequency:0";
+		touch_penirq = <&mhs35_touch_pins>,"brcm,pins:0",
+			       <&mhs35_touch>,"interrupts:0",
+			       <&mhs35_touch>,"pendown-gpio:4";
+	};
+};