/*
 * Copyright (C) 2013 Pavel Machek <pavel@ucw.cz>
 * Copyright (C) 2013-2014 Aaro Koskinen <aaro.koskinen@iki.fi>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 (or later) as
 * published by the Free Software Foundation.
 */

/dts-v1/;

#include "omap34xx-hs.dtsi"

/ {
	model = "Nokia N900";
	compatible = "nokia,omap3-n900", "ti,omap3430", "ti,omap3";

	cpus {
		cpu@0 {
			cpu0-supply = <&vcc>;
		};
	};

	memory {
		device_type = "memory";
		reg = <0x80000000 0x10000000>; /* 256 MB */
	};

	gpio_keys {
		compatible = "gpio-keys";

		camera_lens_cover {
			label = "Camera Lens Cover";
			gpios = <&gpio4 14 GPIO_ACTIVE_LOW>; /* 110 */
			linux,input-type = <5>; /* EV_SW */
			linux,code = <0x09>; /* SW_CAMERA_LENS_COVER */
			gpio-key,wakeup;
		};

		camera_focus {
			label = "Camera Focus";
			gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; /* 68 */
			linux,code = <0x210>; /* KEY_CAMERA_FOCUS */
			gpio-key,wakeup;
		};

		camera_capture {
			label = "Camera Capture";
			gpios = <&gpio3 5 GPIO_ACTIVE_LOW>; /* 69 */
			linux,code = <0xd4>; /* KEY_CAMERA */
			gpio-key,wakeup;
		};

		lock_button {
			label = "Lock Button";
			gpios = <&gpio4 17 GPIO_ACTIVE_LOW>; /* 113 */
			linux,code = <0x98>; /* KEY_SCREENLOCK */
			gpio-key,wakeup;
		};

		keypad_slide {
			label = "Keypad Slide";
			gpios = <&gpio3 7 GPIO_ACTIVE_LOW>; /* 71 */
			linux,input-type = <5>; /* EV_SW */
			linux,code = <0x0a>; /* SW_KEYPAD_SLIDE */
			gpio-key,wakeup;
		};

		proximity_sensor {
			label = "Proximity Sensor";
			gpios = <&gpio3 25 GPIO_ACTIVE_HIGH>; /* 89 */
			linux,input-type = <5>; /* EV_SW */
			linux,code = <0x0b>; /* SW_FRONT_PROXIMITY */
		};
	};

	isp1704: isp1704 {
		compatible = "nxp,isp1704";
		nxp,enable-gpio = <&gpio3 3 GPIO_ACTIVE_HIGH>;
		usb-phy = <&usb2_phy>;
	};

	tv: connector {
		compatible = "composite-connector";
		label = "tv";

		port {
			tv_connector_in: endpoint {
				remote-endpoint = <&venc_out>;
			};
		};
	};
};

&omap3_pmx_core {
	pinctrl-names = "default";

	uart2_pins: pinmux_uart2_pins {
		pinctrl-single,pins = <
			0x14a (PIN_INPUT | MUX_MODE0)		/* uart2_rx */
			0x148 (PIN_OUTPUT | MUX_MODE0)		/* uart2_tx */
		>;
	};

	uart3_pins: pinmux_uart3_pins {
		pinctrl-single,pins = <
			0x16e (PIN_INPUT | MUX_MODE0)		/* uart3_rx */
			0x170 (PIN_OUTPUT | MUX_MODE0)		/* uart3_tx */
		>;
	};

	i2c1_pins: pinmux_i2c1_pins {
		pinctrl-single,pins = <
			0x18a (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c1_scl */
			0x18c (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c1_sda */
		>;
	};

	i2c2_pins: pinmux_i2c2_pins {
		pinctrl-single,pins = <
			0x18e (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c2_scl */
			0x190 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c2_sda */
		>;
	};

	i2c3_pins: pinmux_i2c3_pins {
		pinctrl-single,pins = <
			0x192 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c3_scl */
			0x194 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c3_sda */
		>;
	};

	mmc1_pins: pinmux_mmc1_pins {
		pinctrl-single,pins = <
			0x114 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc1_clk */
			0x116 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc1_cmd */
			0x118 (PIN_INPUT_PULLUP | MUX_MODE0) 	/* sdmmc1_dat0 */
			0x11a (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc1_dat1 */
			0x11c (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc1_dat2 */
			0x11e (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc1_dat3 */
		>;
	};

	mmc2_pins: pinmux_mmc2_pins {
		pinctrl-single,pins = <
			0x128 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_clk */
			0x12a (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_cmd */
			0x12c (PIN_INPUT_PULLUP | MUX_MODE0) 	/* sdmmc2_dat0 */
			0x12e (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat1 */
			0x130 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat2 */
			0x132 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat3 */
			0x134 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat4 */
			0x136 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat5 */
			0x138 (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat6 */
			0x13a (PIN_INPUT_PULLUP | MUX_MODE0)	/* sdmmc2_dat7 */
		>;
	};

	acx565akm_pins: pinmux_acx565akm_pins {
		pinctrl-single,pins = <
			0x0d4 (PIN_OUTPUT | MUX_MODE4)		/* RX51_LCD_RESET_GPIO */
		>;
	};

	dss_sdi_pins: pinmux_dss_sdi_pins {
		pinctrl-single,pins = <
			0x0c0 (PIN_OUTPUT | MUX_MODE1)   /* dss_data10.sdi_dat1n */
			0x0c2 (PIN_OUTPUT | MUX_MODE1)   /* dss_data11.sdi_dat1p */
			0x0c4 (PIN_OUTPUT | MUX_MODE1)   /* dss_data12.sdi_dat2n */
			0x0c6 (PIN_OUTPUT | MUX_MODE1)   /* dss_data13.sdi_dat2p */

			0x0d8 (PIN_OUTPUT | MUX_MODE1)   /* dss_data22.sdi_clkp */
			0x0da (PIN_OUTPUT | MUX_MODE1)   /* dss_data23.sdi_clkn */
		>;
	};
};

&i2c1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c1_pins>;

	clock-frequency = <2200000>;

	twl: twl@48 {
		reg = <0x48>;
		interrupts = <7>; /* SYS_NIRQ cascaded to intc */
		interrupt-parent = <&intc>;
	};
};

#include "twl4030.dtsi"
#include "twl4030_omap3.dtsi"

&vaux1 {
	regulator-name = "V28";
	regulator-min-microvolt = <2800000>;
	regulator-max-microvolt = <2800000>;
	regulator-always-on; /* due battery cover sensor */
};

&vaux2 {
	regulator-name = "VCSI";
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
};

&vaux3 {
	regulator-name = "VMMC2_30";
	regulator-min-microvolt = <2800000>;
	regulator-max-microvolt = <3000000>;
};

&vaux4 {
	regulator-name = "VCAM_ANA_28";
	regulator-min-microvolt = <2800000>;
	regulator-max-microvolt = <2800000>;
};

&vmmc1 {
	regulator-name = "VMMC1";
	regulator-min-microvolt = <1850000>;
	regulator-max-microvolt = <3150000>;
};

&vmmc2 {
	regulator-name = "V28_A";
	regulator-min-microvolt = <2800000>;
	regulator-max-microvolt = <3000000>;
	regulator-always-on; /* due VIO leak to AIC34 VDDs */
};

&vpll1 {
	regulator-name = "VPLL";
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
	regulator-always-on;
};

&vpll2 {
	regulator-name = "VSDI_CSI";
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
	regulator-always-on;
};

&vsim {
	regulator-name = "VMMC2_IO_18";
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
};

&vio {
	regulator-name = "VIO";
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;

};

&vintana1 {
	regulator-name = "VINTANA1";
	/* fixed to 1500000 */
	regulator-always-on;
};

&vintana2 {
	regulator-name = "VINTANA2";
	regulator-min-microvolt = <2750000>;
	regulator-max-microvolt = <2750000>;
	regulator-always-on;
};

&vintdig {
	regulator-name = "VINTDIG";
	/* fixed to 1500000 */
	regulator-always-on;
};

&twl {
	twl_audio: audio {
		compatible = "ti,twl4030-audio";
		ti,enable-vibra = <1>;
	};
};

&twl_keypad {
	linux,keymap = < 0x00000010 /* KEY_Q */
			 0x00010018 /* KEY_O */
			 0x00020019 /* KEY_P */
			 0x00030033 /* KEY_COMMA */
			 0x0004000e /* KEY_BACKSPACE */
			 0x0006001e /* KEY_A */
			 0x0007001f /* KEY_S */

			 0x01000011 /* KEY_W */
			 0x01010020 /* KEY_D */
			 0x01020021 /* KEY_F */
			 0x01030022 /* KEY_G */
			 0x01040023 /* KEY_H */
			 0x01050024 /* KEY_J */
			 0x01060025 /* KEY_K */
			 0x01070026 /* KEY_L */

			 0x02000012 /* KEY_E */
			 0x02010034 /* KEY_DOT */
			 0x02020067 /* KEY_UP */
			 0x0203001c /* KEY_ENTER */
			 0x0205002c /* KEY_Z */
			 0x0206002d /* KEY_X */
			 0x0207002e /* KEY_C */
			 0x02080043 /* KEY_F9 */

			 0x03000013 /* KEY_R */
			 0x0301002f /* KEY_V */
			 0x03020030 /* KEY_B */
			 0x03030031 /* KEY_N */
			 0x03040032 /* KEY_M */
			 0x03050039 /* KEY_SPACE */
			 0x03060039 /* KEY_SPACE */
			 0x03070069 /* KEY_LEFT */

			 0x04000014 /* KEY_T */
			 0x0401006c /* KEY_DOWN */
			 0x0402006a /* KEY_RIGHT */
			 0x0404001d /* KEY_LEFTCTRL */
			 0x04050064 /* KEY_RIGHTALT */
			 0x0406002a /* KEY_LEFTSHIFT */
			 0x04080044 /* KEY_F10 */

			 0x05000015 /* KEY_Y */
			 0x05080057 /* KEY_F11 */

			 0x06000016 /* KEY_U */

			 0x07000017 /* KEY_I */
			 0x07010041 /* KEY_F7 */
			 0x07020042 /* KEY_F8 */
			 >;
};

&twl_gpio {
	ti,pullups	= <0x0>;
	ti,pulldowns	= <0x03ff3f>; /* BIT(0..5) | BIT(8..17) */
};

&i2c2 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c2_pins>;

	clock-frequency = <100000>;

	tlv320aic3x: tlv320aic3x@18 {
		compatible = "ti,tlv320aic3x";
		reg = <0x18>;
		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
		ai3x-gpio-func = <
			0 /* AIC3X_GPIO1_FUNC_DISABLED */
			5 /* AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT */
		>;

		AVDD-supply = <&vmmc2>;
		DRVDD-supply = <&vmmc2>;
		IOVDD-supply = <&vio>;
		DVDD-supply = <&vio>;
	};

	tlv320aic3x_aux: tlv320aic3x@19 {
		compatible = "ti,tlv320aic3x";
		reg = <0x19>;
		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */

		AVDD-supply = <&vmmc2>;
		DRVDD-supply = <&vmmc2>;
		IOVDD-supply = <&vio>;
		DVDD-supply = <&vio>;
	};

	tsl2563: tsl2563@29 {
		compatible = "amstaos,tsl2563";
		reg = <0x29>;

		amstaos,cover-comp-gain = <16>;
	};

	lp5523: lp5523@32 {
		compatible = "national,lp5523";
		reg = <0x32>;
		clock-mode = /bits/ 8 <0>; /* LP55XX_CLOCK_AUTO */
		enable-gpio = <&gpio2 9 GPIO_ACTIVE_HIGH>; /* 41 */

		chan0 {
			chan-name = "lp5523:kb1";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan1 {
			chan-name = "lp5523:kb2";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan2 {
			chan-name = "lp5523:kb3";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan3 {
			chan-name = "lp5523:kb4";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan4 {
			chan-name = "lp5523:b";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan5 {
			chan-name = "lp5523:g";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan6 {
			chan-name = "lp5523:r";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan7 {
			chan-name = "lp5523:kb5";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};

		chan8 {
			chan-name = "lp5523:kb6";
			led-cur = /bits/ 8 <50>;
			max-cur = /bits/ 8 <100>;
		};
	};

	bq27200: bq27200@55 {
		compatible = "ti,bq27200";
		reg = <0x55>;
	};

	tpa6130a2: tpa6130a2@60 {
		compatible = "ti,tpa6130a2";
		reg = <0x60>;

		Vdd-supply = <&vmmc2>;

		power-gpio = <&gpio4 2 GPIO_ACTIVE_HIGH>; /* 98 */
	};

	bq24150a: bq24150a@6b {
		compatible = "ti,bq24150a";
		reg = <0x6b>;

		ti,current-limit = <100>;
		ti,weak-battery-voltage = <3400>;
		ti,battery-regulation-voltage = <4200>;
		ti,charge-current = <650>;
		ti,termination-current = <100>;
		ti,resistor-sense = <68>;

		ti,usb-charger-detection = <&isp1704>;
	};
};

&i2c3 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c3_pins>;

	clock-frequency = <400000>;
};

&mmc1 {
	pinctrl-names = "default";
	pinctrl-0 = <&mmc1_pins>;
	vmmc-supply = <&vmmc1>;
	bus-width = <4>;
	cd-gpios = <&gpio6 0 GPIO_ACTIVE_HIGH>; /* 160 */
};

/* most boards use vaux3, only some old versions use vmmc2 instead */
&mmc2 {
	pinctrl-names = "default";
	pinctrl-0 = <&mmc2_pins>;
	vmmc-supply = <&vaux3>;
	vmmc_aux-supply = <&vsim>;
	bus-width = <8>;
	non-removable;
};

&mmc3 {
	status = "disabled";
};

&gpmc {
	ranges = <0 0 0x04000000 0x10000000>; /* 256MB */

	/* gpio-irq for dma: 65 */

	onenand@0,0 {
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <0 0 0x10000000>;

		gpmc,sync-read;
		gpmc,sync-write;
		gpmc,burst-length = <16>;
		gpmc,burst-read;
		gpmc,burst-wrap;
		gpmc,burst-write;
		gpmc,device-width = <2>; /* GPMC_DEVWIDTH_16BIT */
		gpmc,mux-add-data = <2>; /* GPMC_MUX_AD */
		gpmc,cs-on-ns = <0>;
		gpmc,cs-rd-off-ns = <87>;
		gpmc,cs-wr-off-ns = <87>;
		gpmc,adv-on-ns = <0>;
		gpmc,adv-rd-off-ns = <10>;
		gpmc,adv-wr-off-ns = <10>;
		gpmc,oe-on-ns = <15>;
		gpmc,oe-off-ns = <87>;
		gpmc,we-on-ns = <0>;
		gpmc,we-off-ns = <87>;
		gpmc,rd-cycle-ns = <112>;
		gpmc,wr-cycle-ns = <112>;
		gpmc,access-ns = <81>;
		gpmc,page-burst-access-ns = <15>;
		gpmc,bus-turnaround-ns = <0>;
		gpmc,cycle2cycle-delay-ns = <0>;
		gpmc,wait-monitoring-ns = <0>;
		gpmc,clk-activation-ns = <5>;
		gpmc,wr-data-mux-bus-ns = <30>;
		gpmc,wr-access-ns = <81>;
		gpmc,sync-clk-ps = <15000>;

		/*
		 * MTD partition table corresponding to Nokia's
		 * Maemo 5 (Fremantle) release.
		 */
		partition@0 {
			label = "bootloader";
			reg = <0x00000000 0x00020000>;
			read-only;
		};
		partition@1 {
			label = "config";
			reg = <0x00020000 0x00060000>;
		};
		partition@2 {
			label = "log";
			reg = <0x00080000 0x00040000>;
		};
		partition@3 {
			label = "kernel";
			reg = <0x000c0000 0x00200000>;
		};
		partition@4 {
			label = "initfs";
			reg = <0x002c0000 0x00200000>;
		};
		partition@5 {
			label = "rootfs";
			reg = <0x004c0000 0x0fb40000>;
		};
	};
};

&mcspi1 {
	/*
	 * For some reason, touchscreen is necessary for screen to work at
	 * all on real hw. It works well without it on emulator.
	 *
	 * Also... order in the device tree actually matters here.
	 */
	tsc2005@0 {
		compatible = "tsc2005";
		spi-max-frequency = <6000000>;
		reg = <0>;
	};

	acx565akm@2 {
		compatible = "sony,acx565akm";
		spi-max-frequency = <6000000>;
		reg = <2>;

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

		label = "lcd";
		reset-gpios = <&gpio3 26 GPIO_ACTIVE_HIGH>; /* 90 */

		port {
			lcd_in: endpoint {
				remote-endpoint = <&sdi_out>;
			};
		};
	};
};

&usb_otg_hs {
	interface-type = <0>;
	usb-phy = <&usb2_phy>;
	phys = <&usb2_phy>;
	phy-names = "usb2-phy";
	mode = <2>;
	power = <50>;
};

&uart1 {
	status = "disabled";
};

&uart2 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart2_pins>;
};

&uart3 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart3_pins>;
};

&dss {
	status = "ok";

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

	vdds_sdi-supply = <&vaux1>;

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

		port@1 {
			reg = <1>;

			sdi_out: endpoint {
				remote-endpoint = <&lcd_in>;
				datapairs = <2>;
			};
		};
	};
};

&venc {
	status = "ok";

	vdda-supply = <&vdac>;

	port {
		venc_out: endpoint {
			remote-endpoint = <&tv_connector_in>;
			ti,channels = <1>;
		};
	};
};
