// Definitions for Slice hardware
/dts-v1/;
/plugin/;

#include "dt-bindings/clock/bcm2835.h"
#include "dt-bindings/pinctrl/bcm2835.h"

/ {
  compatible = "brcm,bcm2708";

  // disable analog audio
  fragment@0 {
    target = <&audio>;
    __overlay__ {
      status = "disabled";
    };
  };

  // pinctrl definitions
  fragment@1 {
    target = <&gpio>;
    __overlay__ {
      // configure I2S to GPIO 28-31
      slice_i2s_pins: slice_i2s_pins {
        brcm,pins = <28 29 30 31>;
        brcm,function = <BCM2835_FSEL_ALT2>;
      };
      slice_ir_pins: slice_ir_pins {
        brcm,pins = <37>;
        brcm,function = <BCM2835_FSEL_GPIO_IN>;
        brcm,pull = <BCM2835_PUD_DOWN>;
      };
      cs4265_reset_pins: cs4265_reset_pins {
        brcm,pins = <33>;
        brcm,function = <BCM2835_FSEL_GPIO_OUT>;
      };
    };
  };

  // IR receiver
  fragment@2 {
    target-path = "/";
    __overlay__ {
      gpio_ir: ir-receiver {
        compatible = "gpio-ir-receiver";
        pinctrl-names = "default";
        pinctrl-0 = <&slice_ir_pins>;
        gpios = <&gpio 37 1>;
        linux,rc-map-name = "rc-rc6-mce";
        status = "okay";
      };
    };
  };

  // enable I2S
  fragment@3 {
    target = <&i2s>;
    __overlay__ {
      pinctrl-names = "default";
      pinctrl-0 = <&slice_i2s_pins>;
      status = "okay";
    };
  };

  // I2C
  fragment@4 {
    target = <&i2c1>;
    __overlay__ {
      #address-cells = <1>;
      #size-cells = <0>;
      status = "okay";

      pinctrl-names = "default";
      pinctrl-0 = <&i2c1_gpio44>; // use GPIO 44/45 for I2C1

      clock-frequency = <100000>;

      pcf8523@68 {
        compatible = "nxp,pcf8523";
        reg = <0x68>;
        nxp,xtalcap-7pf; // set crystal load to 7pf
        status = "okay";
      };

      cs4265@4e {
        #sound-dai-cells = <0>;
        compatible = "cirrus,cs4265";
        reg = <0x4e>;

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

        cs4265-reset-gpios = <&gpio 33 0>; /* AUD_RST_N on GPIO33 */
        cirrus,no-s16le; // remove S16LE support to workaround I2S controller issue
        status = "okay";
      };
    };
  };

  // Audio driver
  fragment@5 {
    target = <&sound>;
    __overlay__ {
      compatible = "fiveninjas,slice";
      clocks = <&clocks BCM2835_CLOCK_GP0>;
      clock-names = "gp0";
      i2s-controller = <&i2s>;
      status = "okay";
    };
  };

};
