// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2020 BayLibre, SAS
 * Author: Neil Armstrong <narmstrong@baylibre.com>
 */

#include <common.h>
#include <dm.h>
#include <adc.h>
#include <env.h>
#include <init.h>
#include <net.h>
#include <asm/io.h>
#include <asm/arch/boot.h>
#include <asm/arch/sm.h>
#include <asm/arch/eth.h>
#include <asm/arch/boot.h>

#define EFUSE_MAC_OFFSET	20
#define EFUSE_MAC_SIZE		12
#define MAC_ADDR_LEN		6

#define ODROID_HW_VS_ADC_CHANNEL	1

#define MESON_SOC_ID_G12B	0x29
#define MESON_SOC_ID_SM1	0x2b

int mmc_get_env_dev(void)
{
	if (meson_get_boot_device() == BOOT_DEVICE_EMMC)
		return 1;
	return 0;
}

/* Variant detection is based on the ADC RAW values for the channel #1 */
static struct meson_odroid_boards {
	unsigned int soc_id;
	unsigned int adc_min;
	unsigned int adc_max;
	char *variant;
} boards[] = {
	/* OdroidN2 rev 2018,7,23 */
	{ MESON_SOC_ID_G12B, 80 * 4,  90 * 4, "n2" },
	/* OdroidN2 rev 2018,12,6 */
	{ MESON_SOC_ID_G12B, 160 * 4, 170 * 4, "n2" },
	/* OdroidN2 rev 2019,1,17 */
	{ MESON_SOC_ID_G12B, 245 * 4, 255 * 4, "n2" },
	/* OdroidN2 rev 2019,2,7 */
	{ MESON_SOC_ID_G12B, 330 * 4, 350 * 4, "n2" },
	/* OdroidN2plus rev 2019,11,20 */
	{ MESON_SOC_ID_G12B, 410 * 4, 430 * 4, "n2_plus" },
	/* OdroidC4 rev 2020,01,29 */
	{ MESON_SOC_ID_SM1,   80 * 4, 100 * 4, "c4" },
	/* OdroidHC4 rev 2019,12,10 */
	{ MESON_SOC_ID_SM1,  300 * 4, 320 * 4, "hc4" },
	/* OdroidC4 rev 2019,11,29 */
	{ MESON_SOC_ID_SM1,  335 * 4, 345 * 4, "c4" },
	/* OdroidHC4 rev 2020,8,7 */
	{ MESON_SOC_ID_SM1,  590 * 4, 610 * 4, "hc4" },
};

static void odroid_set_fdtfile(char *soc, char *variant)
{
	char s[128];

	snprintf(s, sizeof(s), "amlogic/meson-%s-odroid-%s.dtb", soc, variant);
	env_set("fdtfile", s);
}

static int odroid_detect_variant(void)
{
	char *variant = "", *soc = "";
	unsigned int adcval = 0;
	int ret, i, soc_id = 0;

	if (of_machine_is_compatible("amlogic,sm1")) {
		soc_id = MESON_SOC_ID_SM1;
		soc = "sm1";
	} else if (of_machine_is_compatible("amlogic,g12b")) {
		soc_id = MESON_SOC_ID_G12B;
		soc = "g12b";
	} else {
		return -1;
	}

	ret = adc_channel_single_shot("adc@9000", ODROID_HW_VS_ADC_CHANNEL,
				      &adcval);
	if (ret)
		return ret;

	for (i = 0 ; i < ARRAY_SIZE(boards) ; ++i) {
		if (soc_id == boards[i].soc_id &&
		    adcval >= boards[i].adc_min &&
		    adcval < boards[i].adc_max) {
			variant = boards[i].variant;
			break;
		}
	}

	printf("Board variant: %s\n", variant);
	env_set("variant", variant);

	odroid_set_fdtfile(soc, variant);

	return 0;
}

int misc_init_r(void)
{
	u8 mac_addr[MAC_ADDR_LEN];
	char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
	ssize_t len;

	if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) &&
	    meson_get_soc_rev(tmp, sizeof(tmp)) > 0)
		env_set("soc_rev", tmp);

	meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);

	if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
		len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
					  efuse_mac_addr, EFUSE_MAC_SIZE);
		if (len != EFUSE_MAC_SIZE)
			return 0;

		/* MAC is stored in ASCII format, 1bytes = 2characters */
		for (int i = 0; i < 6; i++) {
			tmp[0] = efuse_mac_addr[i * 2];
			tmp[1] = efuse_mac_addr[i * 2 + 1];
			tmp[2] = '\0';
			mac_addr[i] = simple_strtoul(tmp, NULL, 16);
		}

		if (is_valid_ethaddr(mac_addr))
			eth_env_set_enetaddr("ethaddr", mac_addr);
		else
			meson_generate_serial_ethaddr();
	}

	odroid_detect_variant();
	return 0;
}
