From 6a7c3920d0c1c731650debe7e730b798a6defd0f Mon Sep 17 00:00:00 2001
From: Giedrius <giedrius@blokas.io>
Date: Thu, 21 Nov 2024 08:05:49 +0000
Subject: [PATCH] Adding pimidi-overlay.dts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
---
 arch/arm/boot/dts/overlays/Makefile           |  1 +
 arch/arm/boot/dts/overlays/README             |  8 +++
 arch/arm/boot/dts/overlays/pimidi-overlay.dts | 54 +++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 arch/arm/boot/dts/overlays/pimidi-overlay.dts

--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -204,6 +204,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
 	pifi-dac-zero.dtbo \
 	pifi-mini-210.dtbo \
 	piglow.dtbo \
+	pimidi.dtbo \
 	pineboards-hat-ai.dtbo \
 	pineboards-hatdrive-poe-plus.dtbo \
 	piscreen.dtbo \
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -3735,6 +3735,14 @@ Load:   dtoverlay=piglow
 Params: <None>
 
 
+Name:   pimidi
+Info:   Configures the Blokas Labs Pimidi card
+Load:   dtoverlay=pimidi,<param>=<val>
+Params: sel                     The position used for the sel rotary switch.
+                                Each unit in the stack must be set on a unique
+                                position. If param is omitted, sel=0 is assumed.
+
+
 Name:   pineboards-hat-ai
 Info:   Pineboards Hat Ai! overlay for the Google Coral Edge TPU
 Load:   dtoverlay=pineboards-hat-ai
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/pimidi-overlay.dts
@@ -0,0 +1,54 @@
+/*
+ * Pimidi Linux kernel module.
+ * Copyright (C) 2017-2024  Vilniaus Blokas UAB, https://blokas.io/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/dts-v1/;
+/plugin/;
+
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/interrupt-controller/irq.h>
+
+/ {
+	compatible = "brcm,bcm2835";
+
+	fragment@0 {
+		target = <&i2c_arm>;
+		__overlay__ {
+			status = "okay";
+			clock-frequency=<1000000>;
+
+			pimidi_ctrl: pimidi_ctrl@20 {
+				compatible = "blokaslabs,pimidi";
+
+				reg = <0x20>;
+				status = "okay";
+
+				interrupt-parent = <&gpio>;
+				interrupts = <23 IRQ_TYPE_LEVEL_LOW>;
+				interrupt-names = "data_ready";
+				interrupt-controller;
+				#interrupt-cells = <2>;
+
+				data-ready-gpios = <&gpio 23 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
+				reset-gpios = <&gpio 22 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
+			};
+		};
+	};
+
+	__overrides__ {
+		sel = <&pimidi_ctrl>,"reg:0{0=0x20,1=0x21,2=0x22,3=0x23}",
+			<&pimidi_ctrl>,"data-ready-gpios:4{0=23,1=5,2=6,3=27}",
+			<&pimidi_ctrl>,"interrupts:0{0=23,1=5,2=6,3=27}";
+	};
+};
