// SPDX-License-Identifier: GPL-2.0-only
/*
 * Pisound Micro Linux kernel module.
 * Copyright (C) 2017-2025  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/pinctrl/bcm2835.h>
#include <dt-bindings/interrupt-controller/irq.h>

/ {
	compatible = "brcm,bcm2835";

	fragment@0 {
		target = <&gpio>;
		__overlay__ {
			pisound_micro_pins: pisound_micro_pins {
				brcm,pins = <16 26>;
				brcm,function = <BCM2835_FSEL_GPIO_IN BCM2835_FSEL_GPIO_IN>;
				brcm,pull = <BCM2835_PUD_UP BCM2835_PUD_UP>;
			};
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			clk_codec: clk-codec {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency = <12000000>;
				status = "okay";
			};
		};
	};

	fragment@2 {
		target = <&i2c_arm>;
		__overlay__ {
			status = "okay";

			#address-cells = <1>;
			#size-cells = <0>;

			pisound_micro_ctrl: pisound_micro_ctrl@12 {
				compatible = "blokas,upisnd-ctrl";

				pinctrl-names = "default";
				pinctrl-0 = <&pisound_micro_pins>;

				reg = <0x12>;
				status = "okay";

				interrupt-parent = <&gpio>;
				interrupt-controller;
				interrupts = <26 IRQ_TYPE_LEVEL_LOW>;
				interrupt-names = "data_available";

				gpio-controller;
				#gpio-cells = <2>;

				data_available-gpios = <&gpio 26 GPIO_ACTIVE_LOW>;
				reset-gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
			};

			pisound_micro_codec: upisnd_codec@3b {
				#sound-dai-cells = <0>;
				compatible = "blokas,upisnd-codec";
				reg = <0x3b>;

				clock-names = "mclk";
				clocks = <&clk_codec>;

				// Additional options with default values and alternative values:

				//input-mode    = "differential"; // Or "single-ended"

				//hp-out-mode   = "headphone";    // Or "capless-headphone"
								  // Or "line-out"

				//line-out-mode = "line-out";     // Or "headphone"
				//mono-out-mode = "line-out";     // Or "headphone"

				status = "okay";
			};
		};
	};

	fragment@3 {
		target = <&sound>;
		__overlay__ {
			compatible = "blokas,pisound-micro";
			codec = <&pisound_micro_codec>;
			ctrl = <&pisound_micro_ctrl>;
			i2s-controller = <&i2s_clk_consumer>;
			status = "okay";
		};
	};

	fragment@4 {
		target = <&i2s_clk_consumer>;
		__overlay__ {
			status = "okay";
		};
	};

	__overrides__ {
		input-mode=<&pisound_micro_codec>,"input-mode{single-ended,differential}";
		hp-out-mode=<&pisound_micro_codec>,
			"hp-out-mode{capless-headphone,headphone,line-out}";
		line-out-mode=<&pisound_micro_codec>,"line-out-mode{line-out,headphone}";
		mono-out-mode=<&pisound_micro_codec>,"mono-out-mode{line-out,headphone}";
	};

	__exports__ {
		pisound_micro_ctrl;
	};
};

/* vim: set ts=8 sw=8 noexpandtab: */
