// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2001
 * Denis Peter MPL AG Switzerland. d.peter@mpl.ch
 */

/*
 * Date & Time support for the MC146818 (PIXX4) RTC
 */

#include <command.h>
#include <dm.h>
#include <rtc.h>

#if defined(CONFIG_X86) || defined(CONFIG_TARGET_MALTA)
#include <asm/io.h>
#define in8(p) inb(p)
#define out8(p, v) outb(v, p)
#endif

/* Set this to 1 to clear the CMOS RAM */
#define CLEAR_CMOS		0

#define RTC_PORT_MC146818	0x70
#define RTC_SECONDS		0x00
#define RTC_SECONDS_ALARM	0x01
#define RTC_MINUTES		0x02
#define RTC_MINUTES_ALARM	0x03
#define RTC_HOURS		0x04
#define RTC_HOURS_ALARM		0x05
#define RTC_DAY_OF_WEEK		0x06
#define RTC_DATE_OF_MONTH	0x07
#define RTC_MONTH		0x08
#define RTC_YEAR		0x09
#define RTC_CONFIG_A		0x0a
#define RTC_CONFIG_B		0x0b
#define RTC_CONFIG_C		0x0c
#define RTC_CONFIG_D		0x0d
#define RTC_REG_SIZE		0x80

#define RTC_CONFIG_A_REF_CLCK_32KHZ	(1 << 5)
#define RTC_CONFIG_A_RATE_1024HZ	6

#define RTC_CONFIG_B_24H		(1 << 1)

#define RTC_CONFIG_D_VALID_RAM_AND_TIME	0x80

static int mc146818_read8(int reg)
{
#ifdef CONFIG_SYS_RTC_REG_BASE_ADDR
	return in8(CONFIG_SYS_RTC_REG_BASE_ADDR + reg);
#else
	int ofs = 0;

	if (reg >= 128) {
		ofs = 2;
		reg -= 128;
	}
	out8(RTC_PORT_MC146818 + ofs, reg);

	return in8(RTC_PORT_MC146818 + ofs + 1);
#endif
}

static void mc146818_write8(int reg, uchar val)
{
#ifdef CONFIG_SYS_RTC_REG_BASE_ADDR
	out8(CONFIG_SYS_RTC_REG_BASE_ADDR + reg, val);
#else
	int ofs = 0;

	if (reg >= 128) {
		ofs = 2;
		reg -= 128;
	}
	out8(RTC_PORT_MC146818 + ofs, reg);
	out8(RTC_PORT_MC146818 + ofs + 1, val);
#endif
}

static int mc146818_get(struct rtc_time *tmp)
{
	uchar sec, min, hour, mday, wday __attribute__((unused)),mon, year;

	/* here check if rtc can be accessed */
	while ((mc146818_read8(RTC_CONFIG_A) & 0x80) == 0x80)
		;

	sec	= mc146818_read8(RTC_SECONDS);
	min	= mc146818_read8(RTC_MINUTES);
	hour	= mc146818_read8(RTC_HOURS);
	mday	= mc146818_read8(RTC_DATE_OF_MONTH);
	wday	= mc146818_read8(RTC_DAY_OF_WEEK);
	mon	= mc146818_read8(RTC_MONTH);
	year	= mc146818_read8(RTC_YEAR);
#ifdef RTC_DEBUG
	printf("Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x hr: %02x min: %02x sec: %02x\n",
	       year, mon, mday, wday, hour, min, sec);
	printf("Alarms: mday: %02x hour: %02x min: %02x sec: %02x\n",
	       mc146818_read8(RTC_CONFIG_D) & 0x3f,
	       mc146818_read8(RTC_HOURS_ALARM),
	       mc146818_read8(RTC_MINUTES_ALARM),
	       mc146818_read8(RTC_SECONDS_ALARM));
#endif
	tmp->tm_sec  = bcd2bin(sec & 0x7f);
	tmp->tm_min  = bcd2bin(min & 0x7f);
	tmp->tm_hour = bcd2bin(hour & 0x3f);
	tmp->tm_mday = bcd2bin(mday & 0x3f);
	tmp->tm_mon  = bcd2bin(mon & 0x1f);
	tmp->tm_year = bcd2bin(year);

	if (tmp->tm_year < 70)
		tmp->tm_year += 2000;
	else
		tmp->tm_year += 1900;

	tmp->tm_yday = 0;
	tmp->tm_isdst = 0;
	/*
	 * The mc146818 only updates wday if it is non-zero, sunday is 1
	 * saturday is 7. So let's use our library routine.
	 */
	rtc_calc_weekday(tmp);
#ifdef RTC_DEBUG
	printf("Get DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
	       tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
	       tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif

	return 0;
}

static int mc146818_set(struct rtc_time *tmp)
{
#ifdef RTC_DEBUG
	printf("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
	       tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
	       tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#endif
	/* Disable the RTC to update the regs */
	mc146818_write8(RTC_CONFIG_B, 0x82);

	mc146818_write8(RTC_YEAR, bin2bcd(tmp->tm_year % 100));
	mc146818_write8(RTC_MONTH, bin2bcd(tmp->tm_mon));
	/* Sunday = 1, Saturday = 7 */
	mc146818_write8(RTC_DAY_OF_WEEK, bin2bcd(tmp->tm_wday + 1));
	mc146818_write8(RTC_DATE_OF_MONTH, bin2bcd(tmp->tm_mday));
	mc146818_write8(RTC_HOURS, bin2bcd(tmp->tm_hour));
	mc146818_write8(RTC_MINUTES, bin2bcd(tmp->tm_min));
	mc146818_write8(RTC_SECONDS, bin2bcd(tmp->tm_sec));

	/* Enable the RTC to update the regs */
	mc146818_write8(RTC_CONFIG_B, 0x02);

	return 0;
}

static void mc146818_reset(void)
{
	/* Disable the RTC to update the regs */
	mc146818_write8(RTC_CONFIG_B, 0x82);

	/* Normal OP */
	mc146818_write8(RTC_CONFIG_A, 0x20);
	mc146818_write8(RTC_CONFIG_B, 0x00);
	mc146818_write8(RTC_CONFIG_B, 0x00);

	/* Enable the RTC to update the regs */
	mc146818_write8(RTC_CONFIG_B, 0x02);
}

static void mc146818_init(void)
{
#if CLEAR_CMOS
	int i;

	rtc_write8(RTC_SECONDS_ALARM, 0);
	rtc_write8(RTC_MINUTES_ALARM, 0);
	rtc_write8(RTC_HOURS_ALARM, 0);
	for (i = RTC_CONFIG_A; i < RTC_REG_SIZE; i++)
		rtc_write8(i, 0);
	printf("RTC: zeroing CMOS RAM\n");
#endif

	/* Setup the real time clock */
	mc146818_write8(RTC_CONFIG_B, RTC_CONFIG_B_24H);
	/* Setup the frequency it operates at */
	mc146818_write8(RTC_CONFIG_A, RTC_CONFIG_A_REF_CLCK_32KHZ |
			RTC_CONFIG_A_RATE_1024HZ);
	/* Ensure all reserved bits are 0 in register D */
	mc146818_write8(RTC_CONFIG_D, RTC_CONFIG_D_VALID_RAM_AND_TIME);

	/* Clear any pending interrupts */
	mc146818_read8(RTC_CONFIG_C);
}

#ifdef CONFIG_DM_RTC

static int rtc_mc146818_get(struct udevice *dev, struct rtc_time *time)
{
	return mc146818_get(time);
}

static int rtc_mc146818_set(struct udevice *dev, const struct rtc_time *time)
{
	return mc146818_set((struct rtc_time *)time);
}

static int rtc_mc146818_reset(struct udevice *dev)
{
	mc146818_reset();

	return 0;
}

static int rtc_mc146818_read8(struct udevice *dev, unsigned int reg)
{
	return mc146818_read8(reg);
}

static int rtc_mc146818_write8(struct udevice *dev, unsigned int reg, int val)
{
	mc146818_write8(reg, val);

	return 0;
}

static int rtc_mc146818_probe(struct udevice *dev)
{
	mc146818_init();

	return 0;
}

static const struct rtc_ops rtc_mc146818_ops = {
	.get = rtc_mc146818_get,
	.set = rtc_mc146818_set,
	.reset = rtc_mc146818_reset,
	.read8 = rtc_mc146818_read8,
	.write8 = rtc_mc146818_write8,
};

static const struct udevice_id rtc_mc146818_ids[] = {
	{ .compatible = "motorola,mc146818" },
	{ }
};

U_BOOT_DRIVER(motorola_mc146818) = {
	.name = "motorola_mc146818",
	.id = UCLASS_RTC,
	.of_match = rtc_mc146818_ids,
	.probe = rtc_mc146818_probe,
	.ops = &rtc_mc146818_ops,
};

#else /* !CONFIG_DM_RTC */

int rtc_get(struct rtc_time *tmp)
{
	return mc146818_get(tmp);
}

int rtc_set(struct rtc_time *tmp)
{
	return mc146818_set(tmp);
}

void rtc_reset(void)
{
	mc146818_reset();
}

int rtc_read8(int reg)
{
	return mc146818_read8(reg);
}

void rtc_write8(int reg, uchar val)
{
	mc146818_write8(reg, val);
}

u32 rtc_read32(int reg)
{
	u32 value = 0;
	int i;

	for (i = 0; i < sizeof(value); i++)
		value |= rtc_read8(reg + i) << (i << 3);

	return value;
}

void rtc_write32(int reg, u32 value)
{
	int i;

	for (i = 0; i < sizeof(value); i++)
		rtc_write8(reg + i, (value >> (i << 3)) & 0xff);
}

void rtc_init(void)
{
	mc146818_init();
}

#endif /* CONFIG_DM_RTC */
