// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
 *
 * Based on a the Linux rtc-rv3029c2.c driver written by:
 *   Gregory Hermant <gregory.hermant@calao-systems.com>
 *   Michael Buesch <m@bues.ch>
 */

#include <command.h>
#include <dm.h>
#include <i2c.h>
#include <log.h>
#include <rtc.h>
#include <dm/device_compat.h>
#include <linux/bitops.h>
#include <linux/delay.h>

#define RTC_RV3029_PAGE_LEN             7

/* control section */
#define RV3029_ONOFF_CTRL		0x00
#define RV3029_ONOFF_CTRL_WE		BIT(0)
#define RV3029_ONOFF_CTRL_TE		BIT(1)
#define RV3029_ONOFF_CTRL_TAR		BIT(2)
#define RV3029_ONOFF_CTRL_EERE		BIT(3)
#define RV3029_ONOFF_CTRL_SRON		BIT(4)
#define RV3029_ONOFF_CTRL_TD0		BIT(5)
#define RV3029_ONOFF_CTRL_TD1		BIT(6)
#define RV3029_ONOFF_CTRL_CLKINT	BIT(7)
#define RV3029_IRQ_CTRL			0x01
#define RV3029_IRQ_CTRL_AIE		BIT(0)
#define RV3029_IRQ_CTRL_TIE		BIT(1)
#define RV3029_IRQ_CTRL_V1IE		BIT(2)
#define RV3029_IRQ_CTRL_V2IE		BIT(3)
#define RV3029_IRQ_CTRL_SRIE		BIT(4)
#define RV3029_IRQ_FLAGS		0x02
#define RV3029_IRQ_FLAGS_AF		BIT(0)
#define RV3029_IRQ_FLAGS_TF		BIT(1)
#define RV3029_IRQ_FLAGS_V1IF		BIT(2)
#define RV3029_IRQ_FLAGS_V2IF		BIT(3)
#define RV3029_IRQ_FLAGS_SRF		BIT(4)
#define RV3029_STATUS			0x03
#define RV3029_STATUS_VLOW1		BIT(2)
#define RV3029_STATUS_VLOW2		BIT(3)
#define RV3029_STATUS_SR		BIT(4)
#define RV3029_STATUS_PON		BIT(5)
#define RV3029_STATUS_EEBUSY		BIT(7)
#define RV3029_RST_CTRL			0x04
#define RV3029_RST_CTRL_SYSR		BIT(4)
#define RV3029_CONTROL_SECTION_LEN	0x05

/* watch section */
#define RV3029_W_SEC			0x08
#define RV3029_W_MINUTES		0x09
#define RV3029_W_HOURS			0x0A
#define RV3029_REG_HR_12_24		BIT(6) /* 24h/12h mode */
#define RV3029_REG_HR_PM		BIT(5) /* PM/AM bit in 12h mode */
#define RV3029_W_DATE			0x0B
#define RV3029_W_DAYS			0x0C
#define RV3029_W_MONTHS			0x0D
#define RV3029_W_YEARS			0x0E

/* eeprom control section */
#define RV3029_CONTROL_E2P_EECTRL	0x30
#define RV3029_TRICKLE_1K		BIT(4) /* 1.5K resistance */
#define RV3029_TRICKLE_5K		BIT(5) /* 5K   resistance */
#define RV3029_TRICKLE_20K		BIT(6) /* 20K  resistance */
#define RV3029_TRICKLE_80K		BIT(7) /* 80K  resistance */
#define RV3029_TRICKLE_MASK		(RV3029_TRICKLE_1K |\
					 RV3029_TRICKLE_5K |\
					 RV3029_TRICKLE_20K |\
					 RV3029_TRICKLE_80K)
#define RV3029_TRICKLE_SHIFT		4


static int rv3029_rtc_get(struct udevice *dev, struct rtc_time *tm)
{
	u8 regs[RTC_RV3029_PAGE_LEN];
	int ret;

	ret = dm_i2c_read(dev, RV3029_W_SEC, regs, sizeof(regs));
	if (ret < 0) {
		printf("%s: error reading RTC: %x\n", __func__, ret);
		return -EIO;
	}

	tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]);
	tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES - RV3029_W_SEC]);

	/* HR field has a more complex interpretation */
	{
		const u8 _hr = regs[RV3029_W_HOURS - RV3029_W_SEC];

		if (_hr & RV3029_REG_HR_12_24) {
			/* 12h format */
			tm->tm_hour = bcd2bin(_hr & 0x1f);
			if (_hr & RV3029_REG_HR_PM)	/* PM flag set */
				tm->tm_hour += 12;
		} else {
			/* 24h format */
			tm->tm_hour = bcd2bin(_hr & 0x3f);
		}
	}

	tm->tm_mday = bcd2bin(regs[RV3029_W_DATE - RV3029_W_SEC]);
	tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1;
	/* RTC supports only years > 1999 */
	tm->tm_year = bcd2bin(regs[RV3029_W_YEARS - RV3029_W_SEC]) + 2000;
	tm->tm_wday = bcd2bin(regs[RV3029_W_DAYS - RV3029_W_SEC]) - 1;

	tm->tm_yday = 0;
	tm->tm_isdst = 0;

	debug("%s: %4d-%02d-%02d (wday=%d) %2d:%02d:%02d\n",
	      __func__, tm->tm_year, tm->tm_mon, tm->tm_mday,
	      tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);

	return 0;
}

static int rv3029_rtc_set(struct udevice *dev, const struct rtc_time *tm)
{
	u8 regs[RTC_RV3029_PAGE_LEN];

	debug("%s: %4d-%02d-%02d (wday=%d( %2d:%02d:%02d\n",
	      __func__, tm->tm_year, tm->tm_mon, tm->tm_mday,
	      tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);


	if (tm->tm_year < 2000) {
		printf("%s: year %d (before 2000) not supported\n",
		       __func__, tm->tm_year);
		return -EINVAL;
	}

	regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec);
	regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min);
	regs[RV3029_W_HOURS - RV3029_W_SEC] = bin2bcd(tm->tm_hour);
	regs[RV3029_W_DATE - RV3029_W_SEC] = bin2bcd(tm->tm_mday);
	regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1);
	regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7;
	regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 2000);

	return dm_i2c_write(dev, RV3029_W_SEC, regs, sizeof(regs));
}

static int rv3029_rtc_reset(struct udevice *dev)
{
	u8 ctrl = RV3029_RST_CTRL_SYSR;
	unsigned long start;
	const unsigned long timeout_ms = 10000;
	int ret;

	/* trigger the system-reset */
	ret = dm_i2c_write(dev, RV3029_RST_CTRL, &ctrl, 1);
	if (ret < 0)
		return -EIO;

	/* wait for the system-reset to complete */
	start = get_timer(0);
	do {
		if (get_timer(start) > timeout_ms)
			return -ETIMEDOUT;

		ret = dm_i2c_read(dev, RV3029_RST_CTRL, &ctrl, 1);
		if (ret < 0)
			return -EIO;
	} while (ctrl & RV3029_RST_CTRL_SYSR);

	return 0;
}

static int rv3029_rtc_read8(struct udevice *dev, unsigned int reg)
{
	u8 data;
	int ret;

	ret = dm_i2c_read(dev, reg, &data, sizeof(data));
	return ret < 0 ? ret : data;
}

static int rv3029_rtc_write8(struct udevice *dev, unsigned int reg, int val)
{
	u8 data = val;

	return dm_i2c_write(dev, reg, &data, 1);
}

#if defined(OF_CONTROL)
static int rv3029_get_sr(struct udevice *dev, u8 *buf)
{
	int ret = dm_i2c_read(dev, RV3029_STATUS, buf, 1);

	if (ret < 0)
		return -EIO;

	dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
	return 0;
}

static int rv3029_set_sr(struct udevice *dev, u8 val)
{
	int ret;

	ret = dm_i2c_read(dev, RV3029_STATUS, &val, 1);
	if (ret < 0)
		return -EIO;

	dev_dbg(dev, "status = 0x%.2x (%d)\n", val, val);
	return 0;
}

static int rv3029_eeprom_busywait(struct udevice *dev)
{
	int i, ret;
	u8 sr;

	for (i = 100; i > 0; i--) {
		ret = rv3029_get_sr(dev, &sr);
		if (ret < 0)
			break;
		if (!(sr & RV3029_STATUS_EEBUSY))
			break;
		udelay(10000);
	}
	if (i <= 0) {
		dev_err(dev, "EEPROM busy wait timeout.\n");
		return -ETIMEDOUT;
	}

	return ret;
}

static int rv3029_update_bits(struct udevice *dev, u8 reg, u8 mask, u8 set)
{
	u8 buf;
	int ret;

	ret = dm_i2c_read(dev, reg, &buf, 1);
	if (ret < 0)
		return ret;

	if ((buf & mask) == (set && mask))
		return 0;

	buf = (buf & ~mask) | (set & mask);
	ret = dm_i2c_read(dev, reg, &buf, 1);
	if (ret < 0)
		return ret;

	return 0;
}

static int rv3029_eeprom_exit(struct udevice *dev)
{
	/* Re-enable eeprom refresh */
	return rv3029_update_bits(dev, RV3029_ONOFF_CTRL,
				  RV3029_ONOFF_CTRL_EERE,
				  RV3029_ONOFF_CTRL_EERE);
}

static int rv3029_eeprom_enter(struct udevice *dev)
{
	int ret;
	u8 sr;

	/* Check whether we are in the allowed voltage range. */
	ret = rv3029_get_sr(dev, &sr);
	if (ret < 0)
		return ret;
	if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
		/* We clear the bits and retry once just in case
		 * we had a brown out in early startup.
		 */
		sr &= ~RV3029_STATUS_VLOW1;
		sr &= ~RV3029_STATUS_VLOW2;
		ret = rv3029_set_sr(dev, sr);
		if (ret < 0)
			return ret;
		udelay(10000);
		ret = rv3029_get_sr(dev, &sr);
		if (ret < 0)
			return ret;
		if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
			dev_err(dev, "Supply voltage is too low to safely access the EEPROM.\n");
			return -ENODEV;
		}
	}

	/* Disable eeprom refresh. */
	ret = rv3029_update_bits(dev,
				 RV3029_ONOFF_CTRL, RV3029_ONOFF_CTRL_EERE, 0);
	if (ret < 0)
		return ret;

	/* Wait for any previous eeprom accesses to finish. */
	ret = rv3029_eeprom_busywait(dev);
	if (ret < 0)
		rv3029_eeprom_exit(dev);

	return ret;
}

static int rv3029_eeprom_read(struct udevice *dev, u8 reg,
			      u8 buf[], size_t len)
{
	int ret, err;

	err = rv3029_eeprom_enter(dev);
	if (err < 0)
		return err;

	ret = dm_i2c_read(dev, reg, buf, len);

	err = rv3029_eeprom_exit(dev);
	if (err < 0)
		return err;

	return ret;
}

static int rv3029_eeprom_write(struct udevice *dev, u8 reg,
			       u8 const buf[], size_t len)
{
	int ret;
	size_t i;
	u8 tmp;

	ret = rv3029_eeprom_enter(dev);
	if (ret < 0)
		return ret;

	for (i = 0; i < len; i++, reg++) {
		ret = dm_i2c_read(dev, reg, &tmp, 1);
		if (ret < 0)
			break;
		if (tmp != buf[i]) {
			ret = dm_i2c_write(dev, reg, &buf[i], 1);
			if (ret < 0)
				break;
		}
		ret = rv3029_eeprom_busywait(dev);
		if (ret < 0)
			break;
	}

	ret = rv3029_eeprom_exit(dev);
	if (ret < 0)
		return ret;

	return 0;
}

static int rv3029_eeprom_update_bits(struct udevice *dev,
				     u8 reg, u8 mask, u8 set)
{
	u8 buf;
	int ret;

	ret = rv3029_eeprom_read(dev, reg, &buf, 1);
	if (ret < 0)
		return ret;

	/*
	 * If the EEPROM already reads the correct bitpattern, we don't need
	 * to update it.
	 */
	if ((buf & mask) == (set & mask))
		return 0;

	buf = (buf & ~mask) | (set & mask);
	ret = rv3029_eeprom_write(dev, reg, &buf, 1);
	if (ret < 0)
		return ret;

	return 0;
}

static void rv3029_trickle_config(struct udevice *dev)
{
	static const struct rv3029_trickle_tab_elem {
		u32 r;		/* resistance in ohms */
		u8 conf;	/* trickle config bits */
	} rv3029_trickle_tab[] = {
		{
			.r	= 1076,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_5K |
				  RV3029_TRICKLE_20K | RV3029_TRICKLE_80K,
		}, {
			.r	= 1091,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_5K |
				  RV3029_TRICKLE_20K,
		}, {
			.r	= 1137,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_5K |
				  RV3029_TRICKLE_80K,
		}, {
			.r	= 1154,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_5K,
		}, {
			.r	= 1371,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_20K |
				  RV3029_TRICKLE_80K,
		}, {
			.r	= 1395,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_20K,
		}, {
			.r	= 1472,
			.conf	= RV3029_TRICKLE_1K | RV3029_TRICKLE_80K,
		}, {
			.r	= 1500,
			.conf	= RV3029_TRICKLE_1K,
		}, {
			.r	= 3810,
			.conf	= RV3029_TRICKLE_5K | RV3029_TRICKLE_20K |
				  RV3029_TRICKLE_80K,
		}, {
			.r	= 4000,
			.conf	= RV3029_TRICKLE_5K | RV3029_TRICKLE_20K,
		}, {
			.r	= 4706,
			.conf	= RV3029_TRICKLE_5K | RV3029_TRICKLE_80K,
		}, {
			.r	= 5000,
			.conf	= RV3029_TRICKLE_5K,
		}, {
			.r	= 16000,
			.conf	= RV3029_TRICKLE_20K | RV3029_TRICKLE_80K,
		}, {
			.r	= 20000,
			.conf	= RV3029_TRICKLE_20K,
		}, {
			.r	= 80000,
			.conf	= RV3029_TRICKLE_80K,
		},
	};
	int err;
	u32 ohms;
	u8 trickle_set_bits = 0;

	/* Configure the trickle charger. */
	err = dev_read_u32(dev, "trickle-resistor-ohms", &ohms);

	if (!err) {
		/* Find trickle-charger config */
		for (int i = 0; i < ARRAY_SIZE(rv3029_trickle_tab); i++)
			if (rv3029_trickle_tab[i].r >= ohms) {
				dev_dbg(dev, "trickle charger at %d ohms\n",
					rv3029_trickle_tab[i].r);
				trickle_set_bits = rv3029_trickle_tab[i].conf;
				break;
			}
	}

	dev_dbg(dev, "trickle charger config 0x%x\n", trickle_set_bits);
	err = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,
					RV3029_TRICKLE_MASK,
					trickle_set_bits);
	if (err < 0)
		dev_dbg(dev, "failed to update trickle charger\n");
}
#else
static inline void rv3029_trickle_config(struct udevice *dev)
{
}
#endif

static int rv3029_probe(struct udevice *dev)
{
	i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS |
				DM_I2C_CHIP_WR_ADDRESS);

	rv3029_trickle_config(dev);
	return 0;
}

static const struct rtc_ops rv3029_rtc_ops = {
	.get = rv3029_rtc_get,
	.set = rv3029_rtc_set,
	.read8 = rv3029_rtc_read8,
	.write8 = rv3029_rtc_write8,
	.reset = rv3029_rtc_reset,
};

static const struct udevice_id rv3029_rtc_ids[] = {
	{ .compatible = "mc,rv3029" },
	{ .compatible = "mc,rv3029c2" },
	{ }
};

U_BOOT_DRIVER(rtc_rv3029) = {
	.name	= "rtc-rv3029",
	.id	= UCLASS_RTC,
	.probe	= rv3029_probe,
	.of_match = rv3029_rtc_ids,
	.ops	= &rv3029_rtc_ops,
};
