mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-05 19:10:13 +00:00
83d290c56f
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
105 lines
2.4 KiB
C
105 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* (C) Copyright 2015 Google, Inc
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <i2c.h>
|
|
#include <rtc.h>
|
|
#include <asm/rtc.h>
|
|
|
|
#define REG_COUNT 0x80
|
|
|
|
static int sandbox_rtc_get(struct udevice *dev, struct rtc_time *time)
|
|
{
|
|
time->tm_sec = dm_i2c_reg_read(dev, REG_SEC);
|
|
if (time->tm_sec < 0)
|
|
return time->tm_sec;
|
|
time->tm_min = dm_i2c_reg_read(dev, REG_MIN);
|
|
if (time->tm_min < 0)
|
|
return time->tm_min;
|
|
time->tm_hour = dm_i2c_reg_read(dev, REG_HOUR);
|
|
if (time->tm_hour < 0)
|
|
return time->tm_hour;
|
|
time->tm_mday = dm_i2c_reg_read(dev, REG_MDAY);
|
|
if (time->tm_mday < 0)
|
|
return time->tm_mday;
|
|
time->tm_mon = dm_i2c_reg_read(dev, REG_MON);
|
|
if (time->tm_mon < 0)
|
|
return time->tm_mon;
|
|
time->tm_year = dm_i2c_reg_read(dev, REG_YEAR);
|
|
if (time->tm_year < 0)
|
|
return time->tm_year;
|
|
time->tm_year += 1900;
|
|
time->tm_wday = dm_i2c_reg_read(dev, REG_WDAY);
|
|
if (time->tm_wday < 0)
|
|
return time->tm_wday;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sandbox_rtc_set(struct udevice *dev, const struct rtc_time *time)
|
|
{
|
|
int ret;
|
|
|
|
ret = dm_i2c_reg_write(dev, REG_SEC, time->tm_sec);
|
|
if (ret < 0)
|
|
return ret;
|
|
ret = dm_i2c_reg_write(dev, REG_MIN, time->tm_min);
|
|
if (ret < 0)
|
|
return ret;
|
|
ret = dm_i2c_reg_write(dev, REG_HOUR, time->tm_hour);
|
|
if (ret < 0)
|
|
return ret;
|
|
ret = dm_i2c_reg_write(dev, REG_MDAY, time->tm_mday);
|
|
if (ret < 0)
|
|
return ret;
|
|
ret = dm_i2c_reg_write(dev, REG_MON, time->tm_mon);
|
|
if (ret < 0)
|
|
return ret;
|
|
ret = dm_i2c_reg_write(dev, REG_YEAR, time->tm_year - 1900);
|
|
if (ret < 0)
|
|
return ret;
|
|
ret = dm_i2c_reg_write(dev, REG_WDAY, time->tm_wday);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sandbox_rtc_reset(struct udevice *dev)
|
|
{
|
|
return dm_i2c_reg_write(dev, REG_RESET, 0);
|
|
}
|
|
|
|
static int sandbox_rtc_read8(struct udevice *dev, unsigned int reg)
|
|
{
|
|
return dm_i2c_reg_read(dev, reg);
|
|
}
|
|
|
|
static int sandbox_rtc_write8(struct udevice *dev, unsigned int reg, int val)
|
|
{
|
|
return dm_i2c_reg_write(dev, reg, val);
|
|
}
|
|
|
|
static const struct rtc_ops sandbox_rtc_ops = {
|
|
.get = sandbox_rtc_get,
|
|
.set = sandbox_rtc_set,
|
|
.reset = sandbox_rtc_reset,
|
|
.read8 = sandbox_rtc_read8,
|
|
.write8 = sandbox_rtc_write8,
|
|
};
|
|
|
|
static const struct udevice_id sandbox_rtc_ids[] = {
|
|
{ .compatible = "sandbox-rtc" },
|
|
{ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(rtc_sandbox) = {
|
|
.name = "rtc-sandbox",
|
|
.id = UCLASS_RTC,
|
|
.of_match = sandbox_rtc_ids,
|
|
.ops = &sandbox_rtc_ops,
|
|
};
|