/*
 * Copyright (c) 2018-2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/ {
	model = "Nordic solari_slb NRF9160";
	compatible = "nordic,solari_slb-nrf9160";

	chosen {
		zephyr,console = &uart0;
		zephyr,shell-uart = &uart0;
		zephyr,uart-mcumgr = &uart0;
	};

	vdd_pwr: vdd-pwr-ctrl {
		compatible = "regulator-fixed";
		label = "vdd-pwr-ctrl";
		regulator-name = "vdd-pwr-ctrl";
		enable-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
		regulator-boot-on;
		startup-delay-us = < 1000 >;
	};

	uart_oe_pwr: uart-oe-ctrl {
		compatible = "regulator-fixed";
		label = "uart_oe";
		regulator-name = "uart_oe";
		enable-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
		regulator-boot-on;
		startup-delay-us = < 1000 >;
	};

	mux_sps30_pwr: mux-sps30-ctrl {
		compatible = "regulator-fixed";
		label = "mux_sps30";
		regulator-name = "mux_sps30";
		enable-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
		regulator-boot-on;
		startup-delay-us = < 1000 >;
	};

	hw_driver {
		compatible = "gpio-leds";
		uart_oe: uart_oe {
			gpios = <&gpio0 0 0>;
			label = "PMx_OE";
		};
		flash_en: flash_en {
			gpios = <&gpio0 1 0 >;
			label = "NOR_FLASH_EN";
		};
		vdd_sens: vdd_sens {
			gpios = <&gpio0 2 0>;
			label = "SENS_EN";
		};
		tof_shut: tof_shut {
			gpios = <&gpio0 8 0>;
			label = "ToF_SHUT";
		};
		nox: nox {
			gpios = <&gpio0 11 0>;
			label = "MiCS_EN";
		};
		ble_wakeup: ble_wakeup {
			gpios = <&gpio0 12 0>;
			label = "BLE_WAKEUP";
		};
		led: ntc_adc:led {
			gpios = <&gpio0 14 0>;
			label = "LED_OR_NTC_OR_NOXPREHEAT";
		};
		reed_en: reed_en {
			gpios = <&gpio0 10 GPIO_OPEN_DRAIN>;
			label = "REED_IN.EN";
		};
		ble_rst: ble_rst {
			gpios = <&gpio0 27 0 >;
			label = "BLE_RST";
		};
		gauge: gauge {
			gpios = <&gpio0 3 0>;
			label = "GAUGE_EN";
		};
		dsy_oe: dsy_oe {
			gpios = <&gpio0 18 0>;
			label = "DSY_OE";
		};
		dsy_cs: dsy_cs {
			gpios = <&gpio0 19 0>;
			label = "DSY_CS";
		};
	};

	output {
		compatible = "gpio-leds";
		mcu_if_dsr: mcu_if_dsr {
			gpios = <&gpio0 30 ( GPIO_ACTIVE_LOW)>;
			label = "BLE.DSR";
		};
	};

	input {
		compatible = "gpio-keys";
		alert: alert {
			gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
			label = "BATT_ALERT";
		};
	};

	awakeners {
		compatible = "gpio-keys";
		reed: reed {
			gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
			label = "REED_IN.INPUT";
		};
		ble_int: ble_int {
			gpios = <&gpio0 26 GPIO_ACTIVE_LOW>;
			label = "MCU_IF_INT";
		};
	};

	ToFInterrupt {
		compatible = "gpio-keys";
		tof_int: tof_int {
			gpios = <&gpio0 7 (GPIO_ACTIVE_HIGH)>;
			label = "I2C.INT";
		};
	};

	/* These aliases are provided for compatibility with samples */
	aliases {
		pwr3v3-5 = &uart_oe;
		vdd-sens = &vdd_sens;
		flash-en = &flash_en;
		tof-1v8 = &tof_shut;
		nox = &nox;
		ble-wakeup = &ble_wakeup;
		ble-int = &ble_int;
		alert = &alert;
		reed = &reed;
		reed-en = &reed_en;
		gauge = &gauge;
		tof-int = &tof_int;
		ble-dsr = &mcu_if_dsr;
		ble-rst = &ble_rst;
		dsy-oe = &dsy_oe;
		dsy-cs = &dsy_cs;
		led = &led;
		ntc-adc-preheat = &ntc_adc;
	};
};

&adc {
	status = "okay";
};

&gpiote {
	status = "okay";
};

&gpio0 {
	status = "okay";
};

&uart0 {
	status = "okay";
	current-speed = <115200>;
	tx-pin = <29>;
	rx-pin = <28>;
	rts-pin = <30>;
	cts-pin = <31>;
};

&i2c2 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = <5>;
	scl-pin = <6>;
};


&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <17>;
	mosi-pin = <16>;
	miso-pin = <15>;
	cs-gpios = < &gpio0 19 0x1 >;
};

&timer0 {
	status = "okay";
};

&timer1 {
	status = "okay";
};

&timer2 {
	status = "okay";
};

&flash0 {

	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
		};
		slot0_ns_partition: partition@50000 {
			label = "image-0-nonsecure";
		};
		slot1_partition: partition@80000 {
			label = "image-1";
		};
		slot1_ns_partition: partition@c0000 {
			label = "image-1-nonsecure";
		};
		scratch_partition: partition@f0000 {
			label = "image-scratch";
			reg = <0x000f0000 0xa000>;
		};
		eeprom_partition: partition@fa000 {
			label = "storage";
			reg = <0x000fa000 0x00006000>;
		};
	};
};

/ {

	reserved-memory {
		#address-cells = <1>;
		#size-cells = <1>;
		ranges;

		sram0_s: image_s@20000000 {
			/* Secure image memory */
		};

		sram0_modem: image_modem@20016000 {
			/* Modem (shared) memory */
		};

		sram0_ns: image_ns@20020000 {
			/* Non-Secure image memory */
		};
	};
};

/* Include partition configuration file */
#include "solari_slb_nrf9160_partition_conf.dts"
