board: xiaomi: mocha: add Xiaomi Mi Pad A0101 support
The Mi Pad is a tablet computer based on Nvidia Tegra K1 SoC which
originally ran the Android operating system. The Mi Pad has a 7.9" IPS
display with 1536 x 2048 (324 ppi) resolution. 2 GB of RAM and 16/64 GB of
internal memory that can be supplemented with a microSDXC card giving up to
128 GB of additional storage.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
diff --git a/board/xiaomi/mocha/Kconfig b/board/xiaomi/mocha/Kconfig
new file mode 100644
index 0000000..25c61d4
--- /dev/null
+++ b/board/xiaomi/mocha/Kconfig
@@ -0,0 +1,12 @@
+if TARGET_MOCHA
+
+config SYS_BOARD
+ default "mocha"
+
+config SYS_VENDOR
+ default "xiaomi"
+
+config SYS_CONFIG_NAME
+ default "mocha"
+
+endif
diff --git a/board/xiaomi/mocha/MAINTAINERS b/board/xiaomi/mocha/MAINTAINERS
new file mode 100644
index 0000000..c3871a1
--- /dev/null
+++ b/board/xiaomi/mocha/MAINTAINERS
@@ -0,0 +1,8 @@
+MOCHA BOARD
+M: Svyatoslav Ryhel <clamor95@gmail.com>
+S: Maintained
+F: arch/arm/dts/tegra124-xiaomi-mocha.dts
+F: board/xiaomi/mocha/
+F: configs/mocha_defconfig
+F: doc/board/xiaomi/mocha.rst
+F: include/configs/mocha.h
diff --git a/board/xiaomi/mocha/Makefile b/board/xiaomi/mocha/Makefile
new file mode 100644
index 0000000..c42e426
--- /dev/null
+++ b/board/xiaomi/mocha/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (c) 2024, Svyatoslav Ryhel <clamor95@gmail.com>
+#
+
+obj-$(CONFIG_XPL_BUILD) += mocha-spl.o
+
+obj-y += mocha.o
+
diff --git a/board/xiaomi/mocha/mocha-spl.c b/board/xiaomi/mocha/mocha-spl.c
new file mode 100644
index 0000000..5fb11df
--- /dev/null
+++ b/board/xiaomi/mocha/mocha-spl.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Mocha SPL stage configuration
+ *
+ * (C) Copyright 2024
+ * Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <asm/arch/tegra.h>
+#include <asm/arch-tegra/tegra_i2c.h>
+#include <linux/delay.h>
+
+#define TPS65913_I2C_ADDR (0x58 << 1)
+
+#define TPS65913_SMPS12_CTRL 0x20
+#define TPS65913_SMPS12_VOLTAGE 0x23
+#define TPS65913_SMPS45_CTRL 0x28
+#define TPS65913_SMPS45_VOLTAGE 0x2B
+#define TPS65913_SMPS7_CTRL 0x30
+#define TPS65913_SMPS7_VOLTAGE 0x33
+
+#define TPS65913_SMPS12_CTRL_DATA (0x5100 | TPS65913_SMPS12_CTRL)
+#define TPS65913_SMPS12_VOLTAGE_DATA (0x3800 | TPS65913_SMPS12_VOLTAGE)
+#define TPS65913_SMPS45_CTRL_DATA (0x5100 | TPS65913_SMPS45_CTRL)
+#define TPS65913_SMPS45_VOLTAGE_DATA (0x3800 | TPS65913_SMPS45_VOLTAGE)
+#define TPS65913_SMPS7_CTRL_DATA (0x5100 | TPS65913_SMPS7_CTRL)
+#define TPS65913_SMPS7_VOLTAGE_DATA (0x4700 | TPS65913_SMPS7_VOLTAGE)
+
+void pmic_enable_cpu_vdd(void)
+{
+ /* Set CORE VDD to 1.150V. */
+ tegra_i2c_ll_write(TPS65913_I2C_ADDR, TPS65913_SMPS7_VOLTAGE_DATA);
+ udelay(1000);
+ tegra_i2c_ll_write(TPS65913_I2C_ADDR, TPS65913_SMPS7_CTRL_DATA);
+
+ udelay(1000);
+
+ /* Set CPU VDD to 1.0V. */
+ tegra_i2c_ll_write(TPS65913_I2C_ADDR, TPS65913_SMPS12_VOLTAGE_DATA);
+ udelay(1000);
+ tegra_i2c_ll_write(TPS65913_I2C_ADDR, TPS65913_SMPS12_CTRL_DATA);
+ udelay(10 * 1000);
+
+ /* Set GPU VDD to 1.0V. */
+ tegra_i2c_ll_write(TPS65913_I2C_ADDR, TPS65913_SMPS45_VOLTAGE_DATA);
+ udelay(1000);
+ tegra_i2c_ll_write(TPS65913_I2C_ADDR, TPS65913_SMPS45_CTRL_DATA);
+ udelay(10 * 1000);
+}
diff --git a/board/xiaomi/mocha/mocha.c b/board/xiaomi/mocha/mocha.c
new file mode 100644
index 0000000..5026d54
--- /dev/null
+++ b/board/xiaomi/mocha/mocha.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2024
+ * Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <dm.h>
+#include <fdt_support.h>
+#include <i2c.h>
+#include <log.h>
+
+#ifdef CONFIG_MMC_SDHCI_TEGRA
+
+#define TPS65913_I2C_ADDRESS 0x58
+#define TPS65913_PRIMARY_SECONDARY_PAD2 0xfb
+#define GPIO_4 BIT(0)
+#define TPS65913_PRIMARY_SECONDARY_PAD3 0xfe
+#define DVFS2 BIT(1)
+#define DVFS1 BIT(0)
+
+/* We are using this function only till palmas pinctrl driver is available */
+void pin_mux_mmc(void)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = i2c_get_chip_for_busnum(0, TPS65913_I2C_ADDRESS, 1, &dev);
+ if (ret) {
+ log_debug("%s: cannot find PMIC I2C chip\n", __func__);
+ return;
+ }
+
+ /* GPIO4 function has to be GPIO */
+ dm_i2c_reg_clrset(dev, TPS65913_PRIMARY_SECONDARY_PAD2,
+ GPIO_4, 0);
+
+ /* DVFS1 and DVFS2 are disabled */
+ dm_i2c_reg_clrset(dev, TPS65913_PRIMARY_SECONDARY_PAD3,
+ DVFS2 | DVFS1, 0);
+}
+#endif
diff --git a/board/xiaomi/mocha/mocha.env b/board/xiaomi/mocha/mocha.env
new file mode 100644
index 0000000..d93e243
--- /dev/null
+++ b/board/xiaomi/mocha/mocha.env
@@ -0,0 +1,23 @@
+#include <env/nvidia/prod_upd.env>
+
+button_cmd_0_name=Volume Down
+button_cmd_0=bootmenu
+button_cmd_1_name=Hall sensor (back)
+button_cmd_1=poweroff
+button_cmd_1_name=Hall sensor (front)
+button_cmd_1=poweroff
+
+partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}
+
+boot_block_size_r=0x400000
+boot_block_size=0x2000
+boot_dev=1
+
+bootmenu_0=mount internal storage=usb start && ums 0 mmc 0; bootmenu
+bootmenu_1=mount external storage=usb start && ums 0 mmc 1; bootmenu
+bootmenu_2=fastboot=echo Starting Fastboot protocol ...; fastboot usb 0; bootmenu
+bootmenu_3=update bootloader=run flash_uboot
+bootmenu_4=reboot RCM=enterrcm
+bootmenu_5=reboot=reset
+bootmenu_6=power off=poweroff
+bootmenu_delay=-1