mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-24 22:36:05 +00:00
dm: rtc: Convert 'date' command to support driver model
Adjust this command so that it supports using driver model for I2C, i.e. CONFIG_DM_I2C. This will permit it to be used in sandbox also. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
5871416640
commit
f9951eadb6
1 changed files with 41 additions and 14 deletions
|
@ -10,6 +10,7 @@
|
||||||
*/
|
*/
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
|
#include <dm.h>
|
||||||
#include <rtc.h>
|
#include <rtc.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
|
|
||||||
|
@ -33,10 +34,18 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
struct rtc_time tm;
|
struct rtc_time tm;
|
||||||
int rcode = 0;
|
int rcode = 0;
|
||||||
int old_bus;
|
int old_bus __maybe_unused;
|
||||||
|
|
||||||
/* switch to correct I2C bus */
|
/* switch to correct I2C bus */
|
||||||
#ifdef CONFIG_SYS_I2C
|
#ifdef CONFIG_DM_I2C
|
||||||
|
struct udevice *dev;
|
||||||
|
|
||||||
|
rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
|
||||||
|
if (rcode) {
|
||||||
|
printf("Cannot find RTC: err=%d\n", rcode);
|
||||||
|
return CMD_RET_FAILURE;
|
||||||
|
}
|
||||||
|
#elif defined(CONFIG_SYS_I2C)
|
||||||
old_bus = i2c_get_bus_num();
|
old_bus = i2c_get_bus_num();
|
||||||
i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
|
i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
|
||||||
#else
|
#else
|
||||||
|
@ -48,32 +57,50 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
case 2: /* set date & time */
|
case 2: /* set date & time */
|
||||||
if (strcmp(argv[1],"reset") == 0) {
|
if (strcmp(argv[1],"reset") == 0) {
|
||||||
puts ("Reset RTC...\n");
|
puts ("Reset RTC...\n");
|
||||||
rtc_reset ();
|
#ifdef CONFIG_DM_I2C
|
||||||
|
rcode = dm_rtc_reset(dev);
|
||||||
|
if (!rcode)
|
||||||
|
rcode = dm_rtc_set(dev, &default_tm);
|
||||||
|
#else
|
||||||
|
rtc_reset();
|
||||||
rcode = rtc_set(&default_tm);
|
rcode = rtc_set(&default_tm);
|
||||||
|
#endif
|
||||||
if (rcode)
|
if (rcode)
|
||||||
puts("## Failed to set date after RTC reset\n");
|
puts("## Failed to set date after RTC reset\n");
|
||||||
} else {
|
} else {
|
||||||
/* initialize tm with current time */
|
/* initialize tm with current time */
|
||||||
rcode = rtc_get (&tm);
|
#ifdef CONFIG_DM_I2C
|
||||||
|
rcode = dm_rtc_get(dev, &tm);
|
||||||
if(!rcode) {
|
#else
|
||||||
|
rcode = rtc_get(&tm);
|
||||||
|
#endif
|
||||||
|
if (!rcode) {
|
||||||
/* insert new date & time */
|
/* insert new date & time */
|
||||||
if (mk_date (argv[1], &tm) != 0) {
|
if (mk_date(argv[1], &tm) != 0) {
|
||||||
puts ("## Bad date format\n");
|
puts ("## Bad date format\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* and write to RTC */
|
/* and write to RTC */
|
||||||
rcode = rtc_set (&tm);
|
#ifdef CONFIG_DM_I2C
|
||||||
if(rcode)
|
rcode = dm_rtc_set(dev, &tm);
|
||||||
puts("## Set date failed\n");
|
#else
|
||||||
|
rcode = rtc_set(&tm);
|
||||||
|
#endif
|
||||||
|
if (rcode) {
|
||||||
|
printf("## Set date failed: err=%d\n",
|
||||||
|
rcode);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
puts("## Get date failed\n");
|
puts("## Get date failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* FALL TROUGH */
|
/* FALL TROUGH */
|
||||||
case 1: /* get date & time */
|
case 1: /* get date & time */
|
||||||
rcode = rtc_get (&tm);
|
#ifdef CONFIG_DM_I2C
|
||||||
|
rcode = dm_rtc_get(dev, &tm);
|
||||||
|
#else
|
||||||
|
rcode = rtc_get(&tm);
|
||||||
|
#endif
|
||||||
if (rcode) {
|
if (rcode) {
|
||||||
puts("## Get date failed\n");
|
puts("## Get date failed\n");
|
||||||
break;
|
break;
|
||||||
|
@ -93,11 +120,11 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
/* switch back to original I2C bus */
|
/* switch back to original I2C bus */
|
||||||
#ifdef CONFIG_SYS_I2C
|
#ifdef CONFIG_SYS_I2C
|
||||||
i2c_set_bus_num(old_bus);
|
i2c_set_bus_num(old_bus);
|
||||||
#else
|
#elif !defined(CONFIG_DM_I2C)
|
||||||
I2C_SET_BUS(old_bus);
|
I2C_SET_BUS(old_bus);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return rcode;
|
return rcode ? CMD_RET_FAILURE : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue