// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright 2012 Free Electrons
 */

/*
 * The CFA-10049 is an expansion board for the CFA-10036 module, thus we
 * need to include the CFA-10036 DTS.
 */
#include "imx28-cfa10036.dts"

/ {
	model = "Crystalfontz CFA-10049 Board";
	compatible = "crystalfontz,cfa10049", "crystalfontz,cfa10036", "fsl,imx28";

	i2cmux {
		compatible = "i2c-mux-gpio";
		#address-cells = <1>;
		#size-cells = <0>;
		pinctrl-names = "default";
		pinctrl-0 = <&i2cmux_pins_cfa10049>;
		mux-gpios = <&gpio1 22 0 &gpio1 23 0>;
		i2c-parent = <&i2c1>;

		i2c@0 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <0>;

			adc0: nau7802@2a {
				compatible = "nuvoton,nau7802";
				reg = <0x2a>;
				nuvoton,vldo = <3000>;
			};
		};

		i2c@1 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <1>;

			adc1: nau7802@2a {
				compatible = "nuvoton,nau7802";
				reg = <0x2a>;
				nuvoton,vldo = <3000>;
			};
		};

		i2c@2 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2>;

				adc2: nau7802@2a {
				compatible = "nuvoton,nau7802";
				reg = <0x2a>;
				nuvoton,vldo = <3000>;
			};
		};

		i2c@3 {
			reg = <3>;
			#address-cells = <1>;
			#size-cells = <0>;

			pca9555: pca9555@20 {
				compatible = "nxp,pca9555";
				pinctrl-names = "default";
				pinctrl-0 = <&pca_pins_cfa10049>;
				interrupt-parent = <&gpio2>;
				interrupts = <19 0x2>;
				gpio-controller;
				#gpio-cells = <2>;
				interrupt-controller;
				#interrupt-cells = <2>;
				reg = <0x20>;
			};
		};
	};

	reg_usb1_vbus: regulator-0 {
		compatible = "regulator-fixed";
		pinctrl-names = "default";
		pinctrl-0 = <&usb_pins_cfa10049>;
		regulator-name = "usb1_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio0 7 1>;
	};

	spi-2 {
		compatible = "spi-gpio";
		pinctrl-names = "default";
		pinctrl-0 = <&spi2_pins_cfa10049>;
		status = "okay";
		sck-gpios = <&gpio2 16 0>;
		mosi-gpios = <&gpio2 17 0>;
		miso-gpios = <&gpio2 18 0>;
		cs-gpios = <&gpio3 5 0>;
		num-chipselects = <1>;
		#address-cells = <1>;
		#size-cells = <0>;

		hx8357: hx8357@0 {
			compatible = "himax,hx8357b", "himax,hx8357";
			reg = <0>;
			spi-max-frequency = <100000>;
			spi-cpol;
			spi-cpha;
			gpios-reset = <&gpio3 30 0>;
			im-gpios = <&gpio5 4 0 &gpio5 5 0 &gpio5 6 0>;
		};
	};

	spi-3 {
		compatible = "spi-gpio";
		pinctrl-names = "default";
		pinctrl-0 = <&spi3_pins_cfa10049>;
		status = "okay";
		sck-gpios = <&gpio0 24 0>;
		mosi-gpios = <&gpio0 28 0>;
		cs-gpios = <&gpio0 17 0 &gpio0 26 0 &gpio0 27 0>;
		num-chipselects = <3>;
		#address-cells = <1>;
		#size-cells = <0>;

		gpio5: gpio5@0 {
			compatible = "fairchild,74hc595";
			gpio-controller;
			#gpio-cells = <2>;
			reg = <0>;
			registers-number = <2>;
			spi-max-frequency = <100000>;
		};

		gpio6: gpio6@1 {
			compatible = "fairchild,74hc595";
			gpio-controller;
			#gpio-cells = <2>;
			reg = <1>;
			registers-number = <4>;
			spi-max-frequency = <100000>;
		};

		dac0: dh2228@2 {
			compatible = "rohm,dh2228fv";
			reg = <2>;
			spi-max-frequency = <100000>;
		};
	};

	gpio-keys {
		compatible = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&rotary_btn_pins_cfa10049>;

		rotary-button {
			label = "rotary_button";
			gpios = <&gpio3 26 1>;
			debounce-interval = <10>;
			linux,code = <28>;
		};
	};

	rotary {
		compatible = "rotary-encoder";
		pinctrl-names = "default";
		pinctrl-0 = <&rotary_pins_cfa10049>;
		gpios = <&gpio3 24 1>, <&gpio3 25 1>;
		linux,axis = <1>; /* REL_Y */
		rotary-encoder,relative-axis;
	};

	backlight {
		compatible = "pwm-backlight";
		pwms = <&pwm 3 5000000>;
		brightness-levels = <0 4 8 16 32 64 128 255>;
		default-brightness-level = <6>;

	};

	onewire {
		compatible = "w1-gpio";
		pinctrl-names = "default";
		pinctrl-0 = <&w1_gpio_pins>;
		status = "okay";
		gpios = <&gpio1 21 0>;
	};
};

&i2c1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c1_pins_a>;
	status = "okay";
};

&lcdif {
	pinctrl-names = "default";
	pinctrl-0 = <&lcdif_18bit_pins_cfa10049
		     &lcdif_pins_cfa10049
		     &lcdif_pins_cfa10049_pullup>;
	display = <&display0>;
	status = "okay";

	display0: display0 {
		bits-per-pixel = <32>;
		bus-width = <18>;

		display-timings {
			native-mode = <&timing0>;
			timing0: timing0 {
				clock-frequency = <9216000>;
				hactive = <320>;
				vactive = <480>;
				hback-porch = <2>;
				hfront-porch = <2>;
				vback-porch = <2>;
				vfront-porch = <2>;
				hsync-len = <15>;
				vsync-len = <15>;
				hsync-active = <0>;
				vsync-active = <0>;
				de-active = <1>;
				pixelclk-active = <1>;
			};
		};
	};
};

&lradc {
	fsl,lradc-touchscreen-wires = <4>;
	status = "okay";
};

&mac0 {
	phy-mode = "rmii";
	pinctrl-names = "default";
	pinctrl-0 = <&mac0_pins_a
		&mac0_pins_cfa10049>;
	phy-reset-gpios = <&gpio2 21 GPIO_ACTIVE_LOW>;
	phy-reset-duration = <100>;
	status = "okay";
};

&pinctrl {
	usb_pins_cfa10049: usb-10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_GPMI_D07__GPIO_0_7
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_DISABLE>;
	};

	i2cmux_pins_cfa10049: i2cmux-10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_LCD_D22__GPIO_1_22
			MX28_PAD_LCD_D23__GPIO_1_23
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_DISABLE>;
	};

	mac0_pins_cfa10049: mac0-10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_SSP2_SS2__GPIO_2_21
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_DISABLE>;
	};

	pca_pins_cfa10049: pca-10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_SSP2_SS0__GPIO_2_19
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_ENABLE>;
	};

	rotary_pins_cfa10049: rotary-10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_I2C0_SCL__GPIO_3_24
			MX28_PAD_I2C0_SDA__GPIO_3_25
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_ENABLE>;
	};

	rotary_btn_pins_cfa10049: rotary-btn-10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_SAIF1_SDATA0__GPIO_3_26
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_ENABLE>;
	};

	spi2_pins_cfa10049: spi2-cfa10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_SSP2_SCK__GPIO_2_16
			MX28_PAD_SSP2_MOSI__GPIO_2_17
			MX28_PAD_SSP2_MISO__GPIO_2_18
			MX28_PAD_AUART1_TX__GPIO_3_5
		>;
		fsl,drive-strength = <MXS_DRIVE_8mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_ENABLE>;
	};

	spi3_pins_cfa10049: spi3-cfa10049@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_GPMI_RDN__GPIO_0_24
			MX28_PAD_GPMI_RESETN__GPIO_0_28
			MX28_PAD_GPMI_CE1N__GPIO_0_17
			MX28_PAD_GPMI_ALE__GPIO_0_26
			MX28_PAD_GPMI_CLE__GPIO_0_27
		>;
		fsl,drive-strength = <MXS_DRIVE_8mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_ENABLE>;
	};

	lcdif_18bit_pins_cfa10049: lcdif-18bit@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_LCD_D00__LCD_D0
			MX28_PAD_LCD_D01__LCD_D1
			MX28_PAD_LCD_D02__LCD_D2
			MX28_PAD_LCD_D03__LCD_D3
			MX28_PAD_LCD_D04__LCD_D4
			MX28_PAD_LCD_D05__LCD_D5
			MX28_PAD_LCD_D06__LCD_D6
			MX28_PAD_LCD_D07__LCD_D7
			MX28_PAD_LCD_D08__LCD_D8
			MX28_PAD_LCD_D09__LCD_D9
			MX28_PAD_LCD_D10__LCD_D10
			MX28_PAD_LCD_D11__LCD_D11
			MX28_PAD_LCD_D12__LCD_D12
			MX28_PAD_LCD_D13__LCD_D13
			MX28_PAD_LCD_D14__LCD_D14
			MX28_PAD_LCD_D15__LCD_D15
			MX28_PAD_LCD_D16__LCD_D16
			MX28_PAD_LCD_D17__LCD_D17
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_DISABLE>;
	};

	lcdif_pins_cfa10049: lcdif-evk@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_LCD_RD_E__LCD_VSYNC
			MX28_PAD_LCD_WR_RWN__LCD_HSYNC
			MX28_PAD_LCD_RS__LCD_DOTCLK
			MX28_PAD_LCD_CS__LCD_ENABLE
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_DISABLE>;
	};

	lcdif_pins_cfa10049_pullup: lcdif-10049-pullup@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_LCD_RESET__GPIO_3_30
		>;
		fsl,drive-strength = <MXS_DRIVE_4mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_ENABLE>;
	};

	w1_gpio_pins: w1-gpio@0 {
		reg = <0>;
		fsl,pinmux-ids = <
			MX28_PAD_LCD_D21__GPIO_1_21
		>;
		fsl,drive-strength = <MXS_DRIVE_8mA>;
		fsl,voltage = <MXS_VOLTAGE_HIGH>;
		fsl,pull-up = <MXS_PULL_DISABLE>; /* 0 will enable the keeper */
	};
};

&pwm {
	pinctrl-names = "default";
	pinctrl-0 = <&pwm3_pins_b>;
	status = "okay";
};

&usb1 {
	vbus-supply = <&reg_usb1_vbus>;
	pinctrl-0 = <&usb1_pins_a>;
	pinctrl-names = "default";
	status = "okay";
};

&usbphy1 {
	status = "okay";
};
