dm: rtc: Add driver model support for real-time clocks
Subsystems (5)
cover dm: rtc: Add driver model support for real-time clocks
When driver model is used for I2C, the real-time clock functionality does not work (e.g. the 'date' command gives build errors when CONFIG_DM_I2C is defined). It is possible to work around this by using driver model I2C functions. But what is really needed is an RTC uclass.
This series:
- renames some RTC functions to have an rtc_ prefix
- adds sandbox support for RTC and an emulated I2C RTC device
- adds a driver model RTC uclass and associated tests
- corrects various minor driver model I2C issues that were discovered
With this it should be fairly easy to convert an existing RTC driver to driver model, but this series does not include that as I'm not sure if any of the boards I have include an RTC.
Simon Glass (20):
dm: spi: Correct the comment on spi_get_ops()
dm: i2c: sandbox: Add debugging to the speed limit
dm: i2c: Add functions to read and write a register
dm: i2c: Add an explicit test mode to the sandbox I2C driver
fdt: Correct warning in fdt_setup_simplefb_node()
dm: rtc: Rename gregorian day function
dm: rtc: Rename to_tm() to rtc_to_tm() and add error code
dm: rtc: Rename mktime() and reduce the number of parameters
dm: Remove unnecessary types in bcd.h
dm: rtc: Split structure definition into its own file
dm: sandbox: Add os_localtime() to obtain the system time
dm: rtc: Add a uclass for real-time clocks
dm: rtc: sandbox: Add an emulated I2C RTC device
dm: rtc: sandbox: Add a driver for the sandbox I2C RTC
dm: rtc: Convert 'date' command to support driver model
dm: net: rtc: Support using driver model for rtc in sntp
dm: sandbox: dts: Add a real-time clock attached to I2C
dm: rtc: sandbox: Enable real-time clock support
dm: test: dts: Sort the aliases in the test device tree file
dm: rtc: Add tests for real-time clocks
arch/sandbox/cpu/os.c | 18 +++ arch/sandbox/dts/sandbox.dts | 12 +- arch/sandbox/include/asm/rtc.h | 28 +++++ arch/sandbox/include/asm/test.h | 31 ++++++ common/cmd_date.c | 55 +++++++--- common/fdt_support.c | 2 +- common/image.c | 2 +- configs/sandbox_defconfig | 1 + drivers/i2c/i2c-uclass.c | 19 ++++ drivers/i2c/sandbox_i2c.c | 34 ++++-- drivers/rtc/Kconfig | 8 ++ drivers/rtc/Makefile | 4 + drivers/rtc/at91sam9_rtt.c | 5 +- drivers/rtc/bfin_rtc.c | 5 +- drivers/rtc/date.c | 38 ++++--- drivers/rtc/ds1306.c | 5 +- drivers/rtc/ds1374.c | 6 +- drivers/rtc/ftrtc010.c | 5 +- drivers/rtc/i2c_rtc_emul.c | 236 ++++++++++++++++++++++++++++++++++++++++ drivers/rtc/imxdi.c | 5 +- drivers/rtc/mc13xxx-rtc.c | 5 +- drivers/rtc/mcfrtc.c | 2 +- drivers/rtc/mpc8xx.c | 5 +- drivers/rtc/mx27rtc.c | 5 +- drivers/rtc/mxsrtc.c | 5 +- drivers/rtc/pl031.c | 5 +- drivers/rtc/rtc-uclass.c | 96 ++++++++++++++++ drivers/rtc/sandbox_rtc.c | 106 ++++++++++++++++++ include/bcd.h | 8 +- include/configs/sandbox.h | 1 + include/dm/uclass-id.h | 1 + include/i2c.h | 22 ++++ include/os.h | 11 ++ include/rtc.h | 197 ++++++++++++++++++++++++++++----- include/rtc_def.h | 36 ++++++ include/spi.h | 2 +- net/sntp.c | 14 ++- post/drivers/rtc.c | 28 +++-- test/dm/Makefile | 1 + test/dm/i2c.c | 8 ++ test/dm/rtc.c | 175 +++++++++++++++++++++++++++++ test/dm/test.dts | 26 ++++- 42 files changed, 1155 insertions(+), 123 deletions(-) create mode 100644 arch/sandbox/include/asm/rtc.h create mode 100644 drivers/rtc/i2c_rtc_emul.c create mode 100644 drivers/rtc/rtc-uclass.c create mode 100644 drivers/rtc/sandbox_rtc.c create mode 100644 include/rtc_def.h create mode 100644 test/dm/rtc.c
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 1/20 dm: spi: Correct the comment on spi_get_ops()
This comment should refer to SPI, not serial.
---
include/spi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/spi.h +1 -1
@@ -612,7 +612,7 @@ int sandbox_spi_get_emul(struct sandbox_state *state, struct udevice *bus, struct udevice *slave, struct udevice **emulp); -/* Access the serial operations for a device */ +/* Access the operations for a SPI device */ #define spi_get_ops (dev) ((struct dm_spi_ops *)(dev)->driver->ops)#define spi_emul_get_ops (dev) ((struct dm_spi_emul_ops *)(dev)->driver->ops)#endif /* CONFIG_DM_SPI */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 1/20 dm: spi: Correct the comment on spi_get_ops()
Quoted 22 lines · Simon Glass
This comment should refer to SPI, not serial.
Signed-off-by Simon Glass <[email protected]>---
include/spi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/spi.h +1
-2@@ -612,7 +612,7 @@ int sandbox_spi_get_emul(struct sandbox_state *state, struct udevice *bus, struct udevice *slave, struct udevice **emulp); -/* Access the serial operations for a device */ +/* Access the operations for a SPI device */ #define spi_get_ops (dev) ((struct dm_spi_ops *)(dev)->driver->ops)#define spi_emul_get_ops (dev) ((struct dm_spi_emul_ops *)(dev)->driver->ops)#endif /* CONFIG_DM_SPI */ --
Quoted 2 lines
2.2.0.rc0.207.ga3a616c
thanks!
Signature · 1 line
Jagan.
PATCH 1/20 dm: spi: Correct the comment on spi_get_ops()
Quoted 17 lines · Jagan Teki
Quoted 16 lines · Simon Glass
This comment should refer to SPI, not serial.
Signed-off-by Simon Glass <[email protected]>---
include/spi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/spi.h +0
-0@@ -612,7 +612,7 @@ int sandbox_spi_get_emul(struct sandbox_state *state, struct udevice *bus, struct udevice *slave, struct udevice **emulp);
Quoted 10 lines
Quoted 8 lines
include/spi.h +1
-2-/* Access the serial operations for a device */ +/* Access the operations for a SPI device */ #define spi_get_ops (dev) ((struct dm_spi_ops *)(dev)->driver->ops)#define spi_emul_get_ops (dev) ((struct dm_spi_emul_ops *)(dev)->driver->ops)#endif /* CONFIG_DM_SPI */ --2.2.0.rc0.207.ga3a616c
Reviewed-by Jagannadha Sutradharudu Teki <[email protected]>
Applied to u-boot-dm.
PATCH 2/20 dm: i2c: sandbox: Add debugging to the speed limit
In reply to Simon GlassPrint a debug() message with the I2C speed is exceeded.
---
drivers/i2c/sandbox_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/sandbox_i2c.c +3 -1
@@ -73,8 +73,10 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,* 400KHz for reads */ is_read = nmsgs >1 ; -if (i2c->speed_hz > (is_read ?400000 :100000 )) +if (i2c->speed_hz > (is_read ?400000 :100000 )) { +debug ("%s: Max speed exceeded\n" , __func__);return -EINVAL ; + }return ops->xfer (emul, msg, nmsgs); }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 2/20 dm: i2c: sandbox: Add debugging to the speed limit
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 13 lines
Print a
debug()message with the I2C speed is exceeded.Signed-off-by Simon Glass <[email protected]>---
drivers/i2c/sandbox_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i2c/sandbox_i2c.c +0
-0
drivers/i2c/sandbox_i2c.c static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, · line 79
Quoted 8 lines
drivers/i2c/sandbox_i2c.c +3
-1@@ -73,8 +73,10 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,* 400KHz for reads */ is_read = nmsgs >1 ; -if (i2c->speed_hz > (is_read ?400000 :100000 )) +if (i2c->speed_hz > (is_read ?400000 :100000 )) { +debug ("%s: Max speed exceeded\n" , __func__);return -EINVAL ; + }
Why different speeds for reading/writing?
bye,
Heiko
Quoted 4 lines
drivers/i2c/sandbox_i2c.c +0
-0return ops->xfer (emul, msg, nmsgs); }
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 2/20 dm: i2c: sandbox: Add debugging to the speed limit
Hi Heiko,
Quoted 22 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 18 lines
Print a
debug()message with the I2C speed is exceeded.Signed-off-by Simon Glass <[email protected]>---
drivers/i2c/sandbox_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i2c/sandbox_i2c.c +0
-0@@ -73,8 +73,10 @@ static int sandbox_i2c_xfer(struct udevice *bus, structi2c_msg *msg, * 400KHz for reads */ is_read = nmsgs >1 ;
Quoted 8 lines
drivers/i2c/sandbox_i2c.c static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, · line 79
Quoted 5 lines
drivers/i2c/sandbox_i2c.c +3
-1-if (i2c->speed_hz > (is_read ?400000 :100000 )) +if (i2c->speed_hz > (is_read ?400000 :100000 )) { +debug ("%s: Max speed exceeded\n" , __func__);return -EINVAL ; + }Why different speeds for reading/writing?
This is just test code - in fact a later patch adds a flag to enable it only when running tests. See test/dm/i2c.c.
Regards,
Simon
PATCH 2/20 dm: i2c: sandbox: Add debugging to the speed limit
Hello Simon,
Am 23.04.2015 17:12, schrieb Simon Glass:
Quoted 34 lines
Hi Heiko,
Quoted 22 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 18 lines
Print a
debug()message with the I2C speed is exceeded.Signed-off-by Simon Glass <[email protected]>---
drivers/i2c/sandbox_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i2c/sandbox_i2c.c +0
-0@@ -73,8 +73,10 @@ static int sandbox_i2c_xfer(struct udevice *bus, structi2c_msg *msg, * 400KHz for reads */ is_read = nmsgs >1 ;Quoted 8 lines
drivers/i2c/sandbox_i2c.c static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, · line 79
Quoted 5 lines
drivers/i2c/sandbox_i2c.c +3
-1-if (i2c->speed_hz > (is_read ?400000 :100000 )) +if (i2c->speed_hz > (is_read ?400000 :100000 )) { +debug ("%s: Max speed exceeded\n" , __func__);return -EINVAL ; + }Why different speeds for reading/writing?
Quoted 2 lines
This is just test code - in fact a later patch adds a flag to enable it only when running tests. See
test/dm/i2c.c.
Ah, thanks for the clarification, so:
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 2/20 dm: i2c: sandbox: Add debugging to the speed limit
Quoted 44 lines · Heiko Schocher
Hello Simon,
Am 23.04.2015 17:12, schrieb Simon Glass:
Quoted 40 lines
Hi Heiko,
Quoted 34 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 20 lines
Print a
debug()message with the I2C speed is exceeded.Signed-off-by Simon Glass <[email protected]>---
drivers/i2c/sandbox_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i2c/sandbox_i2c.c +0
-0@@ -73,8 +73,10 @@ static int sandbox_i2c_xfer(struct udevice *bus,struct
i2c_msg*msg,* 400KHz for reads */ is_read = nmsgs > 1;drivers/i2c/sandbox_i2c.c static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, · line 79
Quoted 5 lines
drivers/i2c/sandbox_i2c.c +3
-1-if (i2c->speed_hz > (is_read ?400000 :100000 )) +if (i2c->speed_hz > (is_read ?400000 :100000 )) { +debug ("%s: Max speed exceeded\n" , __func__);return -EINVAL ; + }Why different speeds for reading/writing?
Quoted 7 lines
Quoted 2 lines
This is just test code - in fact a later patch adds a flag to enable it only when running tests. See
test/dm/i2c.c.Ah, thanks for the clarification, so:
Acked-by Heiko Schocher <[email protected]>
Applied to u-boot-dm.
PATCH 3/20 dm: i2c: Add functions to read and write a register
In reply to Simon GlassAdd driver model versions of the legacy functions to read and write a single byte register. These are a useful shortcut in many cases.
---
drivers/i2c/i2c-uclass.c | 19 +++++++++++++++++++ include/i2c.h | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+)
drivers/i2c/i2c-uclass.c +19 -0
@@ -186,6 +186,25 @@ int dm_i2c_write(struct udevice *dev, uint offset, const uint8_t *buffer, } } +int dm_i2c_reg_read (struct udevice *dev,uint offset) +{ +uint8_t val; +int ret; + + ret =dm_i2c_read (dev, offset, &val,1 ); +if (ret <0 ) +return ret; + +return val; +} + +int dm_i2c_reg_write (struct udevice *dev,uint offset,uint value) +{ +uint8_t val = value; + +return dm_i2c_write (dev, offset, &val,1 ); +} +/** * i2c_probe_chip() - probe for a chip on a bus *
include/i2c.h +21 -0
@@ -124,6 +124,27 @@ int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags, struct udevice **devp);/** +* dm_i2c_reg_read() - Read a value from an I2C register +* +* This reads a single value from the given address in an I2C chip +* +* @addr: Address to read from +* @return value read, or -ve on error +*/ +int dm_i2c_reg_read (struct udevice *dev,uint offset); + +/** +* dm_i2c_reg_write() - Write a value to an I2C register +* +* This writes a single value to the given address in an I2C chip +* +* @addr: Address to write to +* @val: Value to write (normally a byte) +* @return 0 on success, -ve on error +*/ +int dm_i2c_reg_write (struct udevice *dev,uint offset,unsigned int val); + +/** * dm_i2c_set_bus_speed() - set the speed of a bus * * @bus: Bus to adjust
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 3/20 dm: i2c: Add functions to read and write a register
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 9 lines
Add driver model versions of the legacy functions to read and write a single byte register. These are a useful shortcut in many cases.
Signed-off-by Simon Glass <[email protected]>---
drivers/i2c/i2c-uclass.c | 19 +++++++++++++++++++ include/i2c.h | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+)
bye,
Heiko
Quoted 64 lines
drivers/i2c/i2c-uclass.c +19
-0@@ -186,6 +186,25 @@ int dm_i2c_write(struct udevice *dev, uint offset, const uint8_t *buffer, } } +int dm_i2c_reg_read (struct udevice *dev,uint offset) +{ +uint8_t val; +int ret; + + ret =dm_i2c_read (dev, offset, &val,1 ); +if (ret <0 ) +return ret; + +return val; +} + +int dm_i2c_reg_write (struct udevice *dev,uint offset,uint value) +{ +uint8_t val = value; + +return dm_i2c_write (dev, offset, &val,1 ); +} +/** * i2c_probe_chip() - probe for a chip on a bus * include/i2c.h +21
-0@@ -124,6 +124,27 @@ int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags, struct udevice **devp);/** +* dm_i2c_reg_read() - Read a value from an I2C register +* +* This reads a single value from the given address in an I2C chip +* +* @addr: Address to read from +* @return value read, or -ve on error +*/ +int dm_i2c_reg_read (struct udevice *dev,uint offset); + +/** +* dm_i2c_reg_write() - Write a value to an I2C register +* +* This writes a single value to the given address in an I2C chip +* +* @addr: Address to write to +* @val: Value to write (normally a byte) +* @return 0 on success, -ve on error +*/ +int dm_i2c_reg_write (struct udevice *dev,uint offset,unsigned int val); + +/** * dm_i2c_set_bus_speed() - set the speed of a bus * * @bus: Bus to adjust
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 3/20 dm: i2c: Add functions to read and write a register
Quoted 10 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 7 lines
Add driver model versions of the legacy functions to read and write a single byte register. These are a useful shortcut in many cases.
Signed-off-by Simon Glass <[email protected]>---
Quoted 6 lines
Quoted 3 lines
drivers/i2c/i2c-uclass.c | 19 +++++++++++++++++++ include/i2c.h | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+)Acked-by Heiko Schocher <[email protected]>
Applied to u-boot-dm.
[snip]
PATCH 4/20 dm: i2c: Add an explicit test mode to the sandbox I2C driver
In reply to Simon GlassAt present this driver has a few test features. They are needed for running the driver model unit tests but are confusing and unnecessary if using sandbox at the command line. Add a flag to enable the test mode, and don't enable it by default.
---
arch/sandbox/include/asm/test.h | 10 ++++++++++ drivers/i2c/sandbox_i2c.c | 34 +++++++++++++++++++++++----------- include/i2c.h | 1 + test/dm/i2c.c | 8 ++++++++ 4 files changed, 42 insertions(+), 11 deletions(-)
arch/sandbox/include/asm/test.h +10 -0
@@ -17,6 +17,16 @@#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL +/** +* sandbox_i2c_set_test_mode() - set test mode for running unit tests +* +* See sandbox_i2c_xfer() for the behaviour changes. +* +* @bus: sandbox I2C bus to adjust +* @test_mode: true to select test mode, false to run normally +*/ +void sandbox_i2c_set_test_mode (struct udevice *bus,bool test_mode); +enum sandbox_i2c_eeprom_test_mode {SIE_TEST_MODE_NONE ,/* Permits read/write of only one byte per I2C transaction */
drivers/i2c/sandbox_i2c.c +23 -11
@@ -18,8 +18,8 @@DECLARE_GLOBAL_DATA_PTR ; -struct dm_sandbox_i2c_emul_priv { -struct udevice *emul; +struct sandbox_i2c_priv { +bool test_mode; }; static int get_emul(struct udevice *dev, struct udevice **devp,
@@ -47,17 +47,25 @@ static int get_emul(struct udevice *dev, struct udevice **devp,return 0 ; } +void sandbox_i2c_set_test_mode (struct udevice *bus,bool test_mode) +{ +struct sandbox_i2c_priv *priv =dev_get_priv (bus); + + priv->test_mode = test_mode; +} +static int sandbox_i2c_xfer (struct udevice *bus,struct i2c_msg *msg,int nmsgs) {struct dm_i2c_bus *i2c =dev_get_uclass_priv (bus); +struct sandbox_i2c_priv *priv =dev_get_priv (bus);struct dm_i2c_ops *ops;struct udevice *emul, *dev;bool is_read;int ret;/* Special test code to return success but with no emulation */ -if (msg->addr ==SANDBOX_I2C_TEST_ADDR ) +if (priv->test_mode && msg->addr ==SANDBOX_I2C_TEST_ADDR )return 0 ; ret =i2c_get_chip (bus, msg->addr,1 , &dev);
@@ -68,15 +76,18 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,if (ret)return ret; -/* -* For testing, don't allow writing above 100KHz for writes and -* 400KHz for reads -*/ - is_read = nmsgs >1 ; -if (i2c->speed_hz > (is_read ?400000 :100000 )) { -debug ("%s: Max speed exceeded\n" , __func__); -return -EINVAL ; +if (priv->test_mode) { +/* +* For testing, don't allow writing above 100KHz for writes and +* 400KHz for reads. +*/ + is_read = nmsgs >1 ; +if (i2c->speed_hz > (is_read ?400000 :100000 )) { +debug ("%s: Max speed exceeded\n" , __func__); +return -EINVAL ; + } } +return ops->xfer (emul, msg, nmsgs); }
@@ -94,4 +105,5 @@ U_BOOT_DRIVER(i2c_sandbox) = { .id = UCLASS_I2C, .of_match = sandbox_i2c_ids, .ops = &sandbox_i2c_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_i2c_priv), };
include/i2c.h +1 -0
@@ -54,6 +54,7 @@ struct dm_i2c_chip {uint flags;#ifdef CONFIG_SANDBOX struct udevice *emul; +bool test_mode;#endif };
test/dm/i2c.c +8 -0
@@ -66,6 +66,9 @@ static int dm_test_i2c_speed(struct dm_test_state *dms)uint8_t buf[5 ];ut_assertok (uclass_get_device_by_seq (UCLASS_I2C , busnum, &bus)); + +/* Use test mode so we create the required errors for invalid speeds */ +sandbox_i2c_set_test_mode (bus, true);ut_assertok (i2c_get_chip (bus, chip,1 , &dev));ut_assertok (dm_i2c_set_bus_speed (bus,100000 ));ut_assertok (dm_i2c_read (dev,0 , buf,5 ));
@@ -73,6 +76,7 @@ static int dm_test_i2c_speed(struct dm_test_state *dms)ut_asserteq (400000 ,dm_i2c_get_bus_speed (bus));ut_assertok (dm_i2c_read (dev,0 , buf,5 ));ut_asserteq (-EINVAL ,dm_i2c_write (dev,0 , buf,5 )); +sandbox_i2c_set_test_mode (bus, false);return 0 ; }
@@ -100,7 +104,11 @@ static int dm_test_i2c_probe_empty(struct dm_test_state *dms)struct udevice *bus, *dev;ut_assertok (uclass_get_device_by_seq (UCLASS_I2C , busnum, &bus)); + +/* Use test mode so that this chip address will always probe */ +sandbox_i2c_set_test_mode (bus, true);ut_assertok (dm_i2c_probe (bus,SANDBOX_I2C_TEST_ADDR ,0 , &dev)); +sandbox_i2c_set_test_mode (bus, false);return 0 ; }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 4/20 dm: i2c: Add an explicit test mode to the sandbox I2C driver
Quoted 5 lines · Simon Glass
At present this driver has a few test features. They are needed for running the driver model unit tests but are confusing and unnecessary if using sandbox at the command line. Add a flag to enable the test mode, and don't enable it by default.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/include/asm/test.h | 10 ++++++++++ drivers/i2c/sandbox_i2c.c | 34 +++++++++++++++++++++++----------- include/i2c.h | 1 + test/dm/i2c.c | 8 ++++++++ 4 files changed, 42 insertions(+), 11 deletions(-)
Applied to u-boot-dm.
PATCH 5/20 fdt: Correct warning in fdt_setup_simplefb_node()
In reply to Simon GlassAdjust the printf() string to avoid a warning on sandbox.
---
common/fdt_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/fdt_support.c +1 -1
@@ -1533,7 +1533,7 @@ int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width,if (ret <0 )return ret; -snprintf (name,sizeof (name),"framebuffer@%llx" , base_address); +snprintf (name,sizeof (name),"framebuffer@%" PRIx64, base_address); ret =fdt_set_name (fdt, node, name);if (ret <0 )return ret;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 5/20 fdt: Correct warning in fdt_setup_simplefb_node()
Quoted 8 lines · Simon Glass
Adjust the
printf()string to avoid a warning on sandbox.Signed-off-by Simon Glass <[email protected]>---
common/fdt_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm.
PATCH 6/20 dm: rtc: Rename gregorian day function
In reply to Simon GlassChange this function name to something more descriptive. Also return a failure code if it cannot calculate a correct value.
---
common/cmd_date.c | 2 +- drivers/rtc/date.c | 9 +++++++-- drivers/rtc/ds1306.c | 2 +- include/rtc.h | 12 +++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-)
common/cmd_date.c +1 -1
@@ -196,7 +196,7 @@ int mk_date (const char *datestr, struct rtc_time *tmp) tmp->tm_min = val;/* calculate day of week */ -GregorianDay (tmp); +rtc_calc_weekday (tmp);return (0 );default :
drivers/rtc/date.c +7 -2
@@ -11,6 +11,7 @@#include <common.h> #include <command.h> +#include <errno.h> #include <rtc.h> #if defined(CONFIG_CMD_DATE ) || defined(CONFIG_TIMESTAMP )
@@ -30,13 +31,15 @@ static int month_days[12] = {/* * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) */ -void GregorianDay (struct rtc_time * tm) +int rtc_calc_weekday (struct rtc_time *tm) {int leapsToDate;int lastYear;int day;int MonthOffset[] = {0 ,31 ,59 ,90 ,120 ,151 ,181 ,212 ,243 ,273 ,304 ,334 }; +if (tm->tm_year <1753 ) +return -EINVAL ; lastYear=tm->tm_year-1 ;/*
@@ -64,6 +67,8 @@ void GregorianDay(struct rtc_time * tm) day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1 ] + tm->tm_mday; tm->tm_wday=day%7 ; + +return 0 ; }void to_tm (int tim,struct rtc_time * tm)
@@ -101,7 +106,7 @@ void to_tm(int tim, struct rtc_time * tm)/* * Determine the day of week */ -GregorianDay (tm); +rtc_calc_weekday (tm); }/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
drivers/rtc/ds1306.c +1 -1
@@ -110,7 +110,7 @@ int rtc_get (struct rtc_time *tmp) immap->im_cpm.cp_pbdat &= ~PB_SPI_CE ;/* Disable DS1306 Chip */ udelay (10 ); -GregorianDay (tmp);/* Determine the day of week */ +rtc_calc_weekday (tmp);/* Determine the day of week */ debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
include/rtc.h +11 -1
@@ -45,7 +45,6 @@ int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);void rtc_reset (void ); -void GregorianDay (struct rtc_time *);void to_tm (int ,struct rtc_time *);unsigned long mktime (unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int );
@@ -87,4 +86,15 @@ void rtc_write32(int reg, u32 value);*/ void rtc_init (void ); +/** +* rtc_calc_weekday() - Work out the weekday from a time +* +* This only works for the Gregorian calendar - i.e. after 1752 (in the UK). +* It sets time->tm_wdaay to the correct day of the week. +* +* @time: Time to inspect. tm_wday is updated +* @return 0 if OK, -EINVAL if the weekday could not be determined +*/ +int rtc_calc_weekday (struct rtc_time *time); +#endif /* _RTC_H_ */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 6/20 dm: rtc: Rename gregorian day function
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 11 lines
Change this function name to something more descriptive. Also return a failure code if it cannot calculate a correct value.
Signed-off-by Simon Glass <[email protected]>---
common/cmd_date.c | 2 +- drivers/rtc/date.c | 9 +++++++-- drivers/rtc/ds1306.c | 2 +- include/rtc.h | 12 +++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-)
bye,
Heiko
Quoted 103 lines
common/cmd_date.c +1
-1@@ -196,7 +196,7 @@ int mk_date (const char *datestr, struct rtc_time *tmp) tmp->tm_min = val;/* calculate day of week */ -GregorianDay (tmp); +rtc_calc_weekday (tmp);return (0 );default :drivers/rtc/date.c +7
-2@@ -11,6 +11,7 @@#include <common.h> #include <command.h> +#include <errno.h> #include <rtc.h> #if defined(CONFIG_CMD_DATE ) || defined(CONFIG_TIMESTAMP )@@ -30,13 +31,15 @@ static int month_days[12] = {/* * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) */ -void GregorianDay (struct rtc_time * tm) +int rtc_calc_weekday (struct rtc_time *tm) {int leapsToDate;int lastYear;int day;int MonthOffset[] = {0 ,31 ,59 ,90 ,120 ,151 ,181 ,212 ,243 ,273 ,304 ,334 }; +if (tm->tm_year <1753 ) +return -EINVAL ; lastYear=tm->tm_year-1 ;/* @@ -64,6 +67,8 @@ void GregorianDay(struct rtc_time * tm) day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1 ] + tm->tm_mday; tm->tm_wday=day%7 ; + +return 0 ; }void to_tm (int tim,struct rtc_time * tm)@@ -101,7 +106,7 @@ void to_tm(int tim, struct rtc_time * tm)/* * Determine the day of week */ -GregorianDay (tm); +rtc_calc_weekday (tm); }/* Converts Gregorian date to seconds since 1970-01-01 00:00:00. drivers/rtc/ds1306.c +1
-1@@ -110,7 +110,7 @@ int rtc_get (struct rtc_time *tmp) immap->im_cpm.cp_pbdat &= ~PB_SPI_CE ;/* Disable DS1306 Chip */ udelay (10 ); -GregorianDay (tmp);/* Determine the day of week */ +rtc_calc_weekday (tmp);/* Determine the day of week */ debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,include/rtc.h +11
-1@@ -45,7 +45,6 @@ int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);void rtc_reset (void ); -void GregorianDay (struct rtc_time *);void to_tm (int ,struct rtc_time *);unsigned long mktime (unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int );@@ -87,4 +86,15 @@ void rtc_write32(int reg, u32 value);*/ void rtc_init (void ); +/** +* rtc_calc_weekday() - Work out the weekday from a time +* +* This only works for the Gregorian calendar - i.e. after 1752 (in the UK). +* It sets time->tm_wdaay to the correct day of the week. +* +* @time: Time to inspect. tm_wday is updated +* @return 0 if OK, -EINVAL if the weekday could not be determined +*/ +int rtc_calc_weekday (struct rtc_time *time); +#endif /* _RTC_H_ */
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 6/20 dm: rtc: Rename gregorian day function
Quoted 10 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 7 lines
Change this function name to something more descriptive. Also return a failure code if it cannot calculate a correct value.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Quoted 5 lines
common/cmd_date.c | 2 +- drivers/rtc/date.c | 9 +++++++-- drivers/rtc/ds1306.c | 2 +- include/rtc.h | 12 +++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-)Acked-by Heiko Schocher <[email protected]>
Applied to u-boot-dm.
PATCH 7/20 dm: rtc: Rename to_tm() to rtc_to_tm() and add error code
In reply to Simon GlassRename this function so that it is clear that it is provided by the RTC. Also return an error when it cannot function as expected. This is unlikely to occur since it works for dates since 1752 and many RTCs do not support such old dates. Still it is better to be accurate.
---
common/image.c | 2 +- drivers/rtc/at91sam9_rtt.c | 2 +- drivers/rtc/bfin_rtc.c | 2 +- drivers/rtc/date.c | 8 ++++++-- drivers/rtc/ds1374.c | 2 +- drivers/rtc/ftrtc010.c | 2 +- drivers/rtc/imxdi.c | 2 +- drivers/rtc/mc13xxx-rtc.c | 2 +- drivers/rtc/mcfrtc.c | 2 +- drivers/rtc/mpc8xx.c | 2 +- drivers/rtc/mx27rtc.c | 2 +- drivers/rtc/mxsrtc.c | 2 +- drivers/rtc/pl031.c | 2 +- include/rtc.h | 15 ++++++++++++++- net/sntp.c | 2 +- post/drivers/rtc.c | 6 +++--- 16 files changed, 36 insertions(+), 19 deletions(-)
common/image.c +1 -1
@@ -533,7 +533,7 @@ void genimg_print_time(time_t timestamp)#ifndef USE_HOSTCC struct rtc_time tm; -to_tm (timestamp, &tm); +rtc_to_tm (timestamp, &tm);printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n" , tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
drivers/rtc/at91sam9_rtt.c +1 -1
@@ -44,7 +44,7 @@ int rtc_get (struct rtc_time *tmp) }while (tim!=tim2); off =readl (&gpbr->reg[AT91_GPBR_INDEX_TIMEOFF ]);/* off==0 means time is invalid, but we ignore that */ -to_tm (tim+off, tmp); +rtc_to_tm (tim+off, tmp);return 0 ; }
drivers/rtc/bfin_rtc.c +1 -1
@@ -114,7 +114,7 @@ int rtc_get(struct rtc_time *tmp)/* Calculate the total number of seconds since epoch */ time_in_sec = (tm_sec) +MIN_TO_SECS (tm_min) +HRS_TO_SECS (tm_hr) +DAYS_TO_SECS (tm_day); -to_tm (time_in_sec, tmp); +rtc_to_tm (time_in_sec, tmp);return 0 ; }
drivers/rtc/date.c +6 -2
@@ -71,7 +71,7 @@ int rtc_calc_weekday(struct rtc_time *tm)return 0 ; } -void to_tm (int tim,struct rtc_time * tm) +int rtc_to_tm (int tim,struct rtc_time *tm) { registerint i; registerlong hms, day;
@@ -103,10 +103,14 @@ void to_tm(int tim, struct rtc_time * tm)/* Days are what is left over (+1) from all that. */ tm->tm_mday = day +1 ; +/* Zero unused fields */ + tm->tm_yday =0 ; + tm->tm_isdst =0 ; +/* * Determine the day of week */ -rtc_calc_weekday (tm); +return rtc_calc_weekday (tm); }/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
drivers/rtc/ds1374.c +1 -1
@@ -118,7 +118,7 @@ int rtc_get (struct rtc_time *tm){DEBUGR ("Get RTC s since 1.1.1970: %ld\n" , time1); -to_tm (time1, tm);/* To Gregorian Date */ +rtc_to_tm (time1, tm);/* To Gregorian Date */ if (rtc_read (RTC_SR_ADDR ) &RTC_SR_BIT_OSF ) {printf ("### Warning: RTC oscillator has stopped\n" );
drivers/rtc/ftrtc010.c +1 -1
@@ -86,7 +86,7 @@ int rtc_get(struct rtc_time *tmp) now =ftrtc010_time () +readl (&rtc->record);#endif -to_tm (now, tmp); +rtc_to_tm (now, tmp);return 0 ; }
drivers/rtc/imxdi.c +1 -1
@@ -192,7 +192,7 @@ int rtc_get(struct rtc_time *tmp) } now =__raw_readl (&data.regs->dtcmr); -to_tm (now, tmp); +rtc_to_tm (now, tmp); err:return rc;
drivers/rtc/mc13xxx-rtc.c +1 -1
@@ -36,7 +36,7 @@ int rtc_get(struct rtc_time *rtc) tim = day1 *86400 + time; -to_tm (tim, rtc); +rtc_to_tm (tim, rtc); rtc->tm_yday =0 ; rtc->tm_isdst =0 ;
drivers/rtc/mcfrtc.c +1 -1
@@ -38,7 +38,7 @@ int rtc_get(struct rtc_time *tmp) tim = (tim *60 ) + rtc_mins; tim = (tim *60 ) + rtc->seconds; -to_tm (tim, tmp); +rtc_to_tm (tim, tmp); tmp->tm_yday =0 ; tmp->tm_isdst =0 ;
drivers/rtc/mpc8xx.c +1 -1
@@ -26,7 +26,7 @@ int rtc_get (struct rtc_time *tmp) tim = immr->im_sit.sit_rtc; -to_tm (tim, tmp); +rtc_to_tm (tim, tmp); debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
drivers/rtc/mx27rtc.c +1 -1
@@ -30,7 +30,7 @@ int rtc_get(struct rtc_time *time) sec += min *60 + hour *3600 + day *24 *3600 ; -to_tm (sec, time); +rtc_to_tm (sec, time);return 0 ; }
drivers/rtc/mxsrtc.c +1 -1
@@ -43,7 +43,7 @@ int rtc_get(struct rtc_time *time)uint32_t secs; secs =readl (&rtc_regs->hw_rtc_seconds); -to_tm (secs, time); +rtc_to_tm (secs, time);return 0 ; }
drivers/rtc/pl031.c +1 -1
@@ -97,7 +97,7 @@ int rtc_get(struct rtc_time *tmp) tim =RTC_READ_REG (RTC_DR ); -to_tm (tim, tmp); +rtc_to_tm (tim, tmp); debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
include/rtc.h +14 -1
@@ -45,7 +45,6 @@ int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);void rtc_reset (void ); -void to_tm (int ,struct rtc_time *);unsigned long mktime (unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int );
@@ -97,4 +96,18 @@ void rtc_init(void);*/ int rtc_calc_weekday (struct rtc_time *time); +/** +* rtc_to_tm() - Convert a time_t value into a broken-out time +* +* The following fields are set up by this function: +* tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday +* +* Note that tm_yday and tm_isdst are set to 0. +* +* @time_t: Number of seconds since 1970-01-01 00:00:00 +* @time: Place to put the broken-out time +* @return 0 if OK, -EINVAL if the weekday could not be determined +*/ +int rtc_to_tm (int time_t,struct rtc_time *time); +#endif /* _RTC_H_ */
net/sntp.c +1 -1
@@ -68,7 +68,7 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,*/ memcpy (&seconds, &rpktp->transmit_timestamp,sizeof (ulong)); -to_tm (ntohl (seconds) -2208988800UL + net_ntp_time_offset, &tm); +rtc_to_tm (ntohl (seconds) -2208988800UL + net_ntp_time_offset, &tm);#if defined(CONFIG_CMD_DATE )rtc_set (&tm);#endif
post/drivers/rtc.c +3 -3
@@ -63,7 +63,7 @@ static void rtc_post_restore (struct rtc_time *tm, unsigned int sec) tm->tm_min, tm->tm_sec) + sec;struct rtc_time ntm; -to_tm (t, &ntm); +rtc_to_tm (t, &ntm);rtc_set (&ntm); }
@@ -119,7 +119,7 @@ int rtc_post_test (int flags)time_t t =mktime (ynl, i +1 , daysnl[i],23 ,59 ,59 );struct rtc_time tm; -to_tm (t, &tm); +rtc_to_tm (t, &tm);rtc_set (&tm); skipped++;
@@ -143,7 +143,7 @@ int rtc_post_test (int flags)time_t t =mktime (yl, i +1 , daysl[i],23 ,59 ,59 );struct rtc_time tm; -to_tm (t, &tm); +rtc_to_tm (t, &tm);rtc_set (&tm); skipped++;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 7/20 dm: rtc: Rename to_tm() to rtc_to_tm() and add error code
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 17 lines
Rename this function so that it is clear that it is provided by the RTC. Also return an error when it cannot function as expected. This is unlikely to occur since it works for dates since 1752 and many RTCs do not support such old dates. Still it is better to be accurate.
Signed-off-by Simon Glass <[email protected]>---
common/image.c | 2 +- drivers/rtc/at91sam9_rtt.c | 2 +- drivers/rtc/bfin_rtc.c | 2 +- drivers/rtc/date.c | 8 ++++++-- drivers/rtc/ds1374.c | 2 +- drivers/rtc/ftrtc010.c | 2 +- drivers/rtc/imxdi.c | 2 +- drivers/rtc/mc13xxx-rtc.c | 2 +- drivers/rtc/mcfrtc.c | 2 +-
Quoted 8 lines
drivers/rtc/mpc8xx.c | 2 +- drivers/rtc/mx27rtc.c | 2 +- drivers/rtc/mxsrtc.c | 2 +- drivers/rtc/pl031.c | 2 +- include/rtc.h | 15 ++++++++++++++- net/sntp.c | 2 +- post/drivers/rtc.c | 6 +++--- 16 files changed, 36 insertions(+), 19 deletions(-)
Thanks!
bye,
Heiko
Quoted 261 lines
common/image.c +1
-1@@ -533,7 +533,7 @@ void genimg_print_time(time_t timestamp)#ifndef USE_HOSTCC struct rtc_time tm; -to_tm (timestamp, &tm); +rtc_to_tm (timestamp, &tm);printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n" , tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);drivers/rtc/at91sam9_rtt.c +1
-1@@ -44,7 +44,7 @@ int rtc_get (struct rtc_time *tmp) }while (tim!=tim2); off =readl (&gpbr->reg[AT91_GPBR_INDEX_TIMEOFF ]);/* off==0 means time is invalid, but we ignore that */ -to_tm (tim+off, tmp); +rtc_to_tm (tim+off, tmp);return 0 ; }drivers/rtc/bfin_rtc.c +1
-1@@ -114,7 +114,7 @@ int rtc_get(struct rtc_time *tmp)/* Calculate the total number of seconds since epoch */ time_in_sec = (tm_sec) +MIN_TO_SECS (tm_min) +HRS_TO_SECS (tm_hr) +DAYS_TO_SECS (tm_day); -to_tm (time_in_sec, tmp); +rtc_to_tm (time_in_sec, tmp);return 0 ; }drivers/rtc/date.c +6
-2@@ -71,7 +71,7 @@ int rtc_calc_weekday(struct rtc_time *tm)return 0 ; } -void to_tm (int tim,struct rtc_time * tm) +int rtc_to_tm (int tim,struct rtc_time *tm) { registerint i; registerlong hms, day;@@ -103,10 +103,14 @@ void to_tm(int tim, struct rtc_time * tm)/* Days are what is left over (+1) from all that. */ tm->tm_mday = day +1 ; +/* Zero unused fields */ + tm->tm_yday =0 ; + tm->tm_isdst =0 ; +/* * Determine the day of week */ -rtc_calc_weekday (tm); +return rtc_calc_weekday (tm); }/* Converts Gregorian date to seconds since 1970-01-01 00:00:00. drivers/rtc/ds1374.c +1
-1@@ -118,7 +118,7 @@ int rtc_get (struct rtc_time *tm){DEBUGR ("Get RTC s since 1.1.1970: %ld\n" , time1); -to_tm (time1, tm);/* To Gregorian Date */ +rtc_to_tm (time1, tm);/* To Gregorian Date */ if (rtc_read (RTC_SR_ADDR ) &RTC_SR_BIT_OSF ) {printf ("### Warning: RTC oscillator has stopped\n" );drivers/rtc/ftrtc010.c +1
-1@@ -86,7 +86,7 @@ int rtc_get(struct rtc_time *tmp) now =ftrtc010_time () +readl (&rtc->record);#endif -to_tm (now, tmp); +rtc_to_tm (now, tmp);return 0 ; }drivers/rtc/imxdi.c +1
-1@@ -192,7 +192,7 @@ int rtc_get(struct rtc_time *tmp) } now =__raw_readl (&data.regs->dtcmr); -to_tm (now, tmp); +rtc_to_tm (now, tmp); err:return rc;drivers/rtc/mc13xxx-rtc.c +1
-1@@ -36,7 +36,7 @@ int rtc_get(struct rtc_time *rtc) tim = day1 *86400 + time; -to_tm (tim, rtc); +rtc_to_tm (tim, rtc); rtc->tm_yday =0 ; rtc->tm_isdst =0 ;drivers/rtc/mcfrtc.c +1
-1@@ -38,7 +38,7 @@ int rtc_get(struct rtc_time *tmp) tim = (tim *60 ) + rtc_mins; tim = (tim *60 ) + rtc->seconds; -to_tm (tim, tmp); +rtc_to_tm (tim, tmp); tmp->tm_yday =0 ; tmp->tm_isdst =0 ;drivers/rtc/mpc8xx.c +1
-1@@ -26,7 +26,7 @@ int rtc_get (struct rtc_time *tmp) tim = immr->im_sit.sit_rtc; -to_tm (tim, tmp); +rtc_to_tm (tim, tmp); debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,drivers/rtc/mx27rtc.c +1
-1@@ -30,7 +30,7 @@ int rtc_get(struct rtc_time *time) sec += min *60 + hour *3600 + day *24 *3600 ; -to_tm (sec, time); +rtc_to_tm (sec, time);return 0 ; }drivers/rtc/mxsrtc.c +1
-1@@ -43,7 +43,7 @@ int rtc_get(struct rtc_time *time)uint32_t secs; secs =readl (&rtc_regs->hw_rtc_seconds); -to_tm (secs, time); +rtc_to_tm (secs, time);return 0 ; }drivers/rtc/pl031.c +1
-1@@ -97,7 +97,7 @@ int rtc_get(struct rtc_time *tmp) tim =RTC_READ_REG (RTC_DR ); -to_tm (tim, tmp); +rtc_to_tm (tim, tmp); debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,include/rtc.h +14
-1@@ -45,7 +45,6 @@ int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);void rtc_reset (void ); -void to_tm (int ,struct rtc_time *);unsigned long mktime (unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int ,unsigned int );@@ -97,4 +96,18 @@ void rtc_init(void);*/ int rtc_calc_weekday (struct rtc_time *time); +/** +* rtc_to_tm() - Convert a time_t value into a broken-out time +* +* The following fields are set up by this function: +* tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday +* +* Note that tm_yday and tm_isdst are set to 0. +* +* @time_t: Number of seconds since 1970-01-01 00:00:00 +* @time: Place to put the broken-out time +* @return 0 if OK, -EINVAL if the weekday could not be determined +*/ +int rtc_to_tm (int time_t,struct rtc_time *time); +#endif /* _RTC_H_ */ net/sntp.c +1
-1@@ -68,7 +68,7 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,*/ memcpy (&seconds, &rpktp->transmit_timestamp,sizeof (ulong)); -to_tm (ntohl (seconds) -2208988800UL + net_ntp_time_offset, &tm); +rtc_to_tm (ntohl (seconds) -2208988800UL + net_ntp_time_offset, &tm);#if defined(CONFIG_CMD_DATE )rtc_set (&tm);#endif post/drivers/rtc.c +3
-3@@ -63,7 +63,7 @@ static void rtc_post_restore (struct rtc_time *tm, unsigned int sec) tm->tm_min, tm->tm_sec) + sec;struct rtc_time ntm; -to_tm (t, &ntm); +rtc_to_tm (t, &ntm);rtc_set (&ntm); }@@ -119,7 +119,7 @@ int rtc_post_test (int flags)time_t t =mktime (ynl, i +1 , daysnl[i],23 ,59 ,59 );struct rtc_time tm; -to_tm (t, &tm); +rtc_to_tm (t, &tm);rtc_set (&tm); skipped++;@@ -143,7 +143,7 @@ int rtc_post_test (int flags)time_t t =mktime (yl, i +1 , daysl[i],23 ,59 ,59 );struct rtc_time tm; -to_tm (t, &tm); +rtc_to_tm (t, &tm);rtc_set (&tm); skipped++;
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 7/20 dm: rtc: Rename to_tm() to rtc_to_tm() and add error code
Quoted 31 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 18 lines
Rename this function so that it is clear that it is provided by the RTC. Also return an error when it cannot function as expected. This is unlikely to occur since it works for dates since 1752 and many RTCs do not support such old dates. Still it is better to be accurate.
Signed-off-by Simon Glass <[email protected]>---
common/image.c | 2 +- drivers/rtc/at91sam9_rtt.c | 2 +- drivers/rtc/bfin_rtc.c | 2 +- drivers/rtc/date.c | 8 ++++++-- drivers/rtc/ds1374.c | 2 +- drivers/rtc/ftrtc010.c | 2 +- drivers/rtc/imxdi.c | 2 +- drivers/rtc/mc13xxx-rtc.c | 2 +- drivers/rtc/mcfrtc.c | 2 +-Quoted 8 lines
drivers/rtc/mpc8xx.c | 2 +- drivers/rtc/mx27rtc.c | 2 +- drivers/rtc/mxsrtc.c | 2 +- drivers/rtc/pl031.c | 2 +- include/rtc.h | 15 ++++++++++++++- net/sntp.c | 2 +- post/drivers/rtc.c | 6 +++--- 16 files changed, 36 insertions(+), 19 deletions(-)
Quoted 3 lines
Thanks!
Acked-by Heiko Schocher <[email protected]>
Applied to u-boot-dm.
PATCH 8/20 dm: rtc: Rename mktime() and reduce the number of parameters
In reply to Simon GlassMost callers unpack the structure and pass each member. It seems better to pass the whole structure instead, as with the C library. Also add an rtc_ prefix.
---
drivers/rtc/at91sam9_rtt.c | 3 +-- drivers/rtc/bfin_rtc.c | 3 +-- drivers/rtc/date.c | 23 ++++++++++++----------- drivers/rtc/ds1306.c | 3 +-- drivers/rtc/ds1374.c | 4 +--- drivers/rtc/ftrtc010.c | 3 +-- drivers/rtc/imxdi.c | 3 +-- drivers/rtc/mc13xxx-rtc.c | 3 +-- drivers/rtc/mpc8xx.c | 3 +-- drivers/rtc/mx27rtc.c | 3 +-- drivers/rtc/mxsrtc.c | 3 +-- drivers/rtc/pl031.c | 3 +-- include/rtc.h | 16 +++++++++++++--- post/drivers/rtc.c | 22 ++++++++++++++++++---- 14 files changed, 54 insertions(+), 41 deletions(-)
drivers/rtc/at91sam9_rtt.c +1 -2
@@ -54,8 +54,7 @@ int rtc_set (struct rtc_time *tmp)at91_gpbr_t *gpbr = (at91_gpbr_t *)ATMEL_BASE_GPBR ;ulong tim; - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp);/* clear alarm, set prescaler to 32768, clear counter */ writel (32768 +AT91_RTT_RTTRST , &rtt->mr);
drivers/rtc/bfin_rtc.c +1 -2
@@ -67,8 +67,7 @@ int rtc_set(struct rtc_time *tmp)wait_for_complete ();/* Calculate number of seconds this incoming time represents */ - remain =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + remain =rtc_mktime (tmp);/* Figure out how many days since epoch */ days = remain /NUM_SECS_IN_DAY ;
drivers/rtc/date.c +12 -11
@@ -128,22 +128,23 @@ int rtc_to_tm(int tim, struct rtc_time *tm)* machines were long is 32-bit! (However, as time_t is signed, we * will already get problems at other places on 2038-01-19 03:14:08) */ -unsigned long -mktime (unsigned int year,unsigned int mon, -unsigned int day,unsigned int hour, -unsigned int min,unsigned int sec) +unsigned long rtc_mktime (const struct rtc_time *tm) { -if (0 >= (int ) (mon -=2 )) {/* 1..12 -> 11,12,1..10 */ +int mon = tm->tm_mon; +int year = tm->tm_year; +int days, hours; + + mon -=2 ; +if (0 >= (int )mon) {/* 1..12 -> 11,12,1..10 */ mon +=12 ;/* Puts Feb last since it has leap day */ year -=1 ; } -return ((( - (unsigned long ) (year/4 - year/100 + year/400 +367 *mon/12 + day) + - year*365 -719499 - )*24 + hour/* now have hours */ - )*60 + min/* now have minutes */ - )*60 + sec;/* finally seconds */ + days = (unsigned long )(year /4 - year /100 + year /400 + +367 * mon /12 + tm->tm_mday) + + year *365 -719499 ; + hours = days *24 + tm->tm_hour; +return (hours *60 + tm->tm_min) *60 + tm->tm_sec; }#endif
drivers/rtc/ds1306.c +1 -2
@@ -180,8 +180,7 @@ int rtc_set (struct rtc_time *tmp) {ulong tim; - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp); immap->im_sitk.sitk_rtck =KAPWR_KEY ; immap->im_sit.sit_rtc = tim;
drivers/rtc/ds1374.c +1 -3
@@ -147,9 +147,7 @@ int rtc_set (struct rtc_time *tmp){if (tmp->tm_year <1970 || tmp->tm_year >2069 )printf ("WARNING: year should be between 1970 and 2069!\n" ); - time =mktime (tmp->tm_year, tmp->tm_mon, - tmp->tm_mday, tmp->tm_hour, - tmp->tm_min, tmp->tm_sec); + time =rtc_mktime (tmp);DEBUGR ("Set RTC s since 1.1.1970: %ld (0x%02lx)\n" , time, time);
drivers/rtc/ftrtc010.c +1 -2
@@ -104,8 +104,7 @@ int rtc_set(struct rtc_time *tmp) tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - new =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour, - tmp->tm_min, tmp->tm_sec); + new =rtc_mktime (tmp); now =ftrtc010_time ();
drivers/rtc/imxdi.c +1 -2
@@ -209,8 +209,7 @@ int rtc_set(struct rtc_time *tmp) goto err; } - now =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + now =rtc_mktime (tmp);/* zero the fractional part first */ rc =DI_WRITE_WAIT (0 , dtclr);if (rc ==0 )
drivers/rtc/mc13xxx-rtc.c +1 -2
@@ -51,8 +51,7 @@ int rtc_set(struct rtc_time *rtc)if (!p)return -1 ; - time =mktime (rtc->tm_year, rtc->tm_mon, rtc->tm_mday, - rtc->tm_hour, rtc->tm_min, rtc->tm_sec); + time =rtc_mktime (rtc); day = time /86400 ; time %=86400 ;
drivers/rtc/mpc8xx.c +1 -2
@@ -44,8 +44,7 @@ int rtc_set (struct rtc_time *tmp) tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp); immr->im_sitk.sitk_rtck =KAPWR_KEY ; immr->im_sit.sit_rtc = tim;
drivers/rtc/mx27rtc.c +1 -2
@@ -40,8 +40,7 @@ int rtc_set(struct rtc_time *time)struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE ;uint32_t day, hour, min, sec; - sec =mktime (time->tm_year, time->tm_mon, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); + sec =rtc_mktime (time); day = sec / (24 *3600 ); sec = sec % (24 *3600 );
drivers/rtc/mxsrtc.c +1 -2
@@ -52,8 +52,7 @@ int rtc_set(struct rtc_time *time) {uint32_t secs; - secs =mktime (time->tm_year, time->tm_mon, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); + secs =rtc_mktime (time);return mxs_rtc_set_time (secs); }
drivers/rtc/pl031.c +1 -2
@@ -72,8 +72,7 @@ int rtc_set(struct rtc_time *tmp) }/* Calculate number of seconds this incoming time represents */ - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp);RTC_WRITE_REG (RTC_LR , tim);
include/rtc.h +13 -3
@@ -45,9 +45,6 @@ int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);void rtc_reset (void ); -unsigned long mktime (unsigned int ,unsigned int ,unsigned int , -unsigned int ,unsigned int ,unsigned int ); -/** * rtc_read8() - Read an 8-bit register *
@@ -110,4 +107,17 @@ int rtc_calc_weekday(struct rtc_time *time);*/ int rtc_to_tm (int time_t,struct rtc_time *time); +/** +* rtc_mktime() - Convert a broken-out time into a time_t value +* +* The following fields need to be valid for this function to work: +* tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year +* +* Note that tm_wday and tm_yday are ignored. +* +* @time: Broken-out time to convert +* @return corresponding time_t value, seconds since 1970-01-01 00:00:00 +*/ +unsigned long rtc_mktime (const struct rtc_time *time); +#endif /* _RTC_H_ */
post/drivers/rtc.c +18 -4
@@ -59,8 +59,7 @@ static int rtc_post_skip (ulong * diff)static void rtc_post_restore (struct rtc_time *tm,unsigned int sec) { -time_t t =mktime (tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, - tm->tm_min, tm->tm_sec) + sec; +time_t t =rtc_mktime (tm) + sec;struct rtc_time ntm;rtc_to_tm (t, &ntm);
@@ -116,9 +115,16 @@ int rtc_post_test (int flags)rtc_get (&svtm);for (i =0 ; i <12 ; i++) { -time_t t =mktime (ynl, i +1 , daysnl[i],23 ,59 ,59 ); +time_t t;struct rtc_time tm; + tm.tm_year = ynl; + tm.tm_mon = i +1 ; + tm.tm_mday = daysnl[i]; + tm.tm_hour =23 ; + tm.tm_min =59 ; + tm.tm_sec =59 ; + t =rtc_mktime (&tm);rtc_to_tm (t, &tm);rtc_set (&tm);
@@ -140,9 +146,17 @@ int rtc_post_test (int flags) }for (i =0 ; i <12 ; i++) { -time_t t =mktime (yl, i +1 , daysl[i],23 ,59 ,59 ); +time_t t;struct rtc_time tm; + tm.tm_year = yl; + tm.tm_mon = i +1 ; + tm.tm_mday = daysl[i]; + tm.tm_hour =23 ; + tm.tm_min =59 ; + tm.tm_sec =59 ; + t =rtc_mktime (&tm); +rtc_to_tm (t, &tm);rtc_set (&tm);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 8/20 dm: rtc: Rename mktime() and reduce the number of parameters
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 7 lines
Most callers unpack the structure and pass each member. It seems better to pass the whole structure instead, as with the C library. Also add an
rtc_prefix.Signed-off-by Simon Glass <[email protected]>---
Quoted 15 lines
drivers/rtc/at91sam9_rtt.c | 3 +-- drivers/rtc/bfin_rtc.c | 3 +-- drivers/rtc/date.c | 23 ++++++++++++----------- drivers/rtc/ds1306.c | 3 +-- drivers/rtc/ds1374.c | 4 +--- drivers/rtc/ftrtc010.c | 3 +-- drivers/rtc/imxdi.c | 3 +-- drivers/rtc/mc13xxx-rtc.c | 3 +-- drivers/rtc/mpc8xx.c | 3 +-- drivers/rtc/mx27rtc.c | 3 +-- drivers/rtc/mxsrtc.c | 3 +-- drivers/rtc/pl031.c | 3 +-- include/rtc.h | 16 +++++++++++++--- post/drivers/rtc.c | 22 ++++++++++++++++++---- 14 files changed, 54 insertions(+), 41 deletions(-)
bye,
Heiko
Quoted 279 lines
drivers/rtc/at91sam9_rtt.c +1
-2@@ -54,8 +54,7 @@ int rtc_set (struct rtc_time *tmp)at91_gpbr_t *gpbr = (at91_gpbr_t *)ATMEL_BASE_GPBR ;ulong tim; - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp);/* clear alarm, set prescaler to 32768, clear counter */ writel (32768 +AT91_RTT_RTTRST , &rtt->mr);drivers/rtc/bfin_rtc.c +1
-2@@ -67,8 +67,7 @@ int rtc_set(struct rtc_time *tmp)wait_for_complete ();/* Calculate number of seconds this incoming time represents */ - remain =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + remain =rtc_mktime (tmp);/* Figure out how many days since epoch */ days = remain /NUM_SECS_IN_DAY ;drivers/rtc/date.c +12
-11@@ -128,22 +128,23 @@ int rtc_to_tm(int tim, struct rtc_time *tm)* machines were long is 32-bit! (However, as time_t is signed, we * will already get problems at other places on 2038-01-19 03:14:08) */ -unsigned long -mktime (unsigned int year,unsigned int mon, -unsigned int day,unsigned int hour, -unsigned int min,unsigned int sec) +unsigned long rtc_mktime (const struct rtc_time *tm) { -if (0 >= (int ) (mon -=2 )) {/* 1..12 -> 11,12,1..10 */ +int mon = tm->tm_mon; +int year = tm->tm_year; +int days, hours; + + mon -=2 ; +if (0 >= (int )mon) {/* 1..12 -> 11,12,1..10 */ mon +=12 ;/* Puts Feb last since it has leap day */ year -=1 ; } -return ((( - (unsigned long ) (year/4 - year/100 + year/400 +367 *mon/12 + day) + - year*365 -719499 - )*24 + hour/* now have hours */ - )*60 + min/* now have minutes */ - )*60 + sec;/* finally seconds */ + days = (unsigned long )(year /4 - year /100 + year /400 + +367 * mon /12 + tm->tm_mday) + + year *365 -719499 ; + hours = days *24 + tm->tm_hour; +return (hours *60 + tm->tm_min) *60 + tm->tm_sec; }#endif drivers/rtc/ds1306.c +1
-2@@ -180,8 +180,7 @@ int rtc_set (struct rtc_time *tmp) {ulong tim; - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp); immap->im_sitk.sitk_rtck =KAPWR_KEY ; immap->im_sit.sit_rtc = tim;drivers/rtc/ds1374.c +1
-3@@ -147,9 +147,7 @@ int rtc_set (struct rtc_time *tmp){if (tmp->tm_year <1970 || tmp->tm_year >2069 )printf ("WARNING: year should be between 1970 and 2069!\n" ); - time =mktime (tmp->tm_year, tmp->tm_mon, - tmp->tm_mday, tmp->tm_hour, - tmp->tm_min, tmp->tm_sec); + time =rtc_mktime (tmp);DEBUGR ("Set RTC s since 1.1.1970: %ld (0x%02lx)\n" , time, time);drivers/rtc/ftrtc010.c +1
-2@@ -104,8 +104,7 @@ int rtc_set(struct rtc_time *tmp) tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - new =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour, - tmp->tm_min, tmp->tm_sec); + new =rtc_mktime (tmp); now =ftrtc010_time ();drivers/rtc/imxdi.c +1
-2@@ -209,8 +209,7 @@ int rtc_set(struct rtc_time *tmp) goto err; } - now =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + now =rtc_mktime (tmp);/* zero the fractional part first */ rc =DI_WRITE_WAIT (0 , dtclr);if (rc ==0 )drivers/rtc/mc13xxx-rtc.c +1
-2@@ -51,8 +51,7 @@ int rtc_set(struct rtc_time *rtc)if (!p)return -1 ; - time =mktime (rtc->tm_year, rtc->tm_mon, rtc->tm_mday, - rtc->tm_hour, rtc->tm_min, rtc->tm_sec); + time =rtc_mktime (rtc); day = time /86400 ; time %=86400 ;drivers/rtc/mpc8xx.c +1
-2@@ -44,8 +44,7 @@ int rtc_set (struct rtc_time *tmp) tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp); immr->im_sitk.sitk_rtck =KAPWR_KEY ; immr->im_sit.sit_rtc = tim;drivers/rtc/mx27rtc.c +1
-2@@ -40,8 +40,7 @@ int rtc_set(struct rtc_time *time)struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE ;uint32_t day, hour, min, sec; - sec =mktime (time->tm_year, time->tm_mon, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); + sec =rtc_mktime (time); day = sec / (24 *3600 ); sec = sec % (24 *3600 );drivers/rtc/mxsrtc.c +1
-2@@ -52,8 +52,7 @@ int rtc_set(struct rtc_time *time) {uint32_t secs; - secs =mktime (time->tm_year, time->tm_mon, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); + secs =rtc_mktime (time);return mxs_rtc_set_time (secs); }drivers/rtc/pl031.c +1
-2@@ -72,8 +72,7 @@ int rtc_set(struct rtc_time *tmp) }/* Calculate number of seconds this incoming time represents */ - tim =mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tim =rtc_mktime (tmp);RTC_WRITE_REG (RTC_LR , tim);include/rtc.h +13
-3@@ -45,9 +45,6 @@ int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);void rtc_reset (void ); -unsigned long mktime (unsigned int ,unsigned int ,unsigned int , -unsigned int ,unsigned int ,unsigned int ); -/** * rtc_read8() - Read an 8-bit register * @@ -110,4 +107,17 @@ int rtc_calc_weekday(struct rtc_time *time);*/ int rtc_to_tm (int time_t,struct rtc_time *time); +/** +* rtc_mktime() - Convert a broken-out time into a time_t value +* +* The following fields need to be valid for this function to work: +* tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year +* +* Note that tm_wday and tm_yday are ignored. +* +* @time: Broken-out time to convert +* @return corresponding time_t value, seconds since 1970-01-01 00:00:00 +*/ +unsigned long rtc_mktime (const struct rtc_time *time); +#endif /* _RTC_H_ */ post/drivers/rtc.c +18
-4@@ -59,8 +59,7 @@ static int rtc_post_skip (ulong * diff)static void rtc_post_restore (struct rtc_time *tm,unsigned int sec) { -time_t t =mktime (tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, - tm->tm_min, tm->tm_sec) + sec; +time_t t =rtc_mktime (tm) + sec;struct rtc_time ntm;rtc_to_tm (t, &ntm);@@ -116,9 +115,16 @@ int rtc_post_test (int flags)rtc_get (&svtm);for (i =0 ; i <12 ; i++) { -time_t t =mktime (ynl, i +1 , daysnl[i],23 ,59 ,59 ); +time_t t;struct rtc_time tm; + tm.tm_year = ynl; + tm.tm_mon = i +1 ; + tm.tm_mday = daysnl[i]; + tm.tm_hour =23 ; + tm.tm_min =59 ; + tm.tm_sec =59 ; + t =rtc_mktime (&tm);rtc_to_tm (t, &tm);rtc_set (&tm);@@ -140,9 +146,17 @@ int rtc_post_test (int flags) }for (i =0 ; i <12 ; i++) { -time_t t =mktime (yl, i +1 , daysl[i],23 ,59 ,59 ); +time_t t;struct rtc_time tm; + tm.tm_year = yl; + tm.tm_mon = i +1 ; + tm.tm_mday = daysl[i]; + tm.tm_hour =23 ; + tm.tm_min =59 ; + tm.tm_sec =59 ; + t =rtc_mktime (&tm); +rtc_to_tm (t, &tm);rtc_set (&tm);
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 8/20 dm: rtc: Rename mktime() and reduce the number of parameters
Quoted 28 lines · Heiko Schocher
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
Quoted 8 lines
Most callers unpack the structure and pass each member. It seems better to pass the whole structure instead, as with the C library. Also add an
rtc_prefix.Signed-off-by Simon Glass <[email protected]>---
Quoted 15 lines
drivers/rtc/at91sam9_rtt.c | 3 +-- drivers/rtc/bfin_rtc.c | 3 +-- drivers/rtc/date.c | 23 ++++++++++++----------- drivers/rtc/ds1306.c | 3 +-- drivers/rtc/ds1374.c | 4 +--- drivers/rtc/ftrtc010.c | 3 +-- drivers/rtc/imxdi.c | 3 +-- drivers/rtc/mc13xxx-rtc.c | 3 +-- drivers/rtc/mpc8xx.c | 3 +-- drivers/rtc/mx27rtc.c | 3 +-- drivers/rtc/mxsrtc.c | 3 +-- drivers/rtc/pl031.c | 3 +-- include/rtc.h | 16 +++++++++++++--- post/drivers/rtc.c | 22 ++++++++++++++++++---- 14 files changed, 54 insertions(+), 41 deletions(-)
Quoted 1 line
Acked-by Heiko Schocher <[email protected]>
Applied to u-boot-dm.
PATCH 9/20 dm: Remove unnecessary types in bcd.h
In reply to Simon GlassWe don't need to use u8, and if we avoid it, it isn't so much of a problem that rtc.h includes this header. With this change we can include rtc.h from sandbox files.
---
include/bcd.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
include/bcd.h +3 -5
@@ -10,14 +10,12 @@#ifndef _BCD_H#define _BCD_H -#include <linux/types.h> - -static inline unsigned int bcd2bin (u8 val) +static inline unsigned int bcd2bin (unsigned int val) { -return ((val) &0x0f ) + ((val) >>4 ) *10 ; +return ((val) &0x0f ) + ((val &0xff ) >>4 ) *10 ; } -static inline u8 bin2bcd (unsigned int val) +static inline unsigned int bin2bcd (unsigned int val) {return (((val /10 ) <<4 ) | (val %10 )); }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 9/20 dm: Remove unnecessary types in bcd.h
Quoted 9 lines · Simon Glass
We don't need to use u8, and if we avoid it, it isn't so much of a problem that
rtc.hincludes this header. With this change we can includertc.hfrom sandbox files.Signed-off-by Simon Glass <[email protected]>---
include/bcd.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Applied to u-boot-dm.
PATCH 10/20 dm: rtc: Split structure definition into its own file
In reply to Simon GlassMove the definition of struct rtc_time into a separate file so that sandbox can include it without requiring common.h and the like.
---
include/rtc.h | 26 +------------------------- include/rtc_def.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 include/rtc_def.h
include/rtc.h +1 -25
@@ -15,31 +15,7 @@* it there instead of in evey single driver */ #include <bcd.h> - -/* -* The struct used to pass data from the generic interface code to -* the hardware dependend low-level code ande vice versa. Identical -* to struct rtc_time used by the Linux kernel. -* -* Note that there are small but significant differences to the -* common "struct time": -* -* struct time: struct rtc_time: -* tm_mon 0 ... 11 1 ... 12 -* tm_year years since 1900 years since 0 -*/ - -struct rtc_time { -int tm_sec; -int tm_min; -int tm_hour; -int tm_mday; -int tm_mon; -int tm_year; -int tm_wday; -int tm_yday; -int tm_isdst; -}; +#include <rtc_def.h> int rtc_get (struct rtc_time *);int rtc_set (struct rtc_time *);
include/rtc_def.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* (C) Copyright 2001 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __rtc_def_h +#define __rtc_def_h + +/* +* The struct used to pass data from the generic interface code to +* the hardware dependend low-level code ande vice versa. Identical +* to struct rtc_time used by the Linux kernel. +* +* Note that there are small but significant differences to the +* common "struct time": +* +* struct time: struct rtc_time: +* tm_mon 0 ... 11 1 ... 12 +* tm_year years since 1900 years since 0 +*/ + +struct rtc_time { +int tm_sec; +int tm_min; +int tm_hour; +int tm_mday; +int tm_mon; +int tm_year; +int tm_wday; +int tm_yday; +int tm_isdst; +}; + +#endif
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 10/20 dm: rtc: Split structure definition into its own file
Quoted 10 lines · Simon Glass
Move the definition of struct
rtc_timeinto a separate file so that sandbox can include it without requiringcommon.hand the like.Signed-off-by Simon Glass <[email protected]>---
include/rtc.h | 26 +------------------------- include/rtc_def.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 include/rtc_def.h
Applied to u-boot-dm.
PATCH 11/20 dm: sandbox: Add os_localtime() to obtain the system time
In reply to Simon GlassAdd a function to read the system time into U-Boot.
---
arch/sandbox/cpu/os.c | 18 ++++++++++++++++++ include/os.h | 11 +++++++++++ 2 files changed, 29 insertions(+)
arch/sandbox/cpu/os.c +18 -0
@@ -24,6 +24,7 @@#include <asm/sections.h> #include <asm/state.h> #include <os.h> +#include <rtc_def.h> /* Operating System Interface */
@@ -537,3 +538,20 @@ int os_jump_to_image(const void *dest, int size)return unlink (fname); } + +void os_localtime (struct rtc_time *rt) +{ +time_t t =time (NULL ); +struct tm *tm; + + tm =localtime (&t); + rt->tm_sec = tm->tm_sec; + rt->tm_min = tm->tm_min; + rt->tm_hour = tm->tm_hour; + rt->tm_mday = tm->tm_mday; + rt->tm_mon = tm->tm_mon +1 ; + rt->tm_year = tm->tm_year +1900 ; + rt->tm_wday = tm->tm_wday; + rt->tm_yday = tm->tm_yday; + rt->tm_isdst = tm->tm_isdst; +}
include/os.h +11 -0
@@ -13,6 +13,7 @@#include <linux/types.h> +struct rtc_time ;struct sandbox_state ;/**
@@ -277,4 +278,14 @@ int os_read_ram_buf(const char *fname);*/ int os_jump_to_image (const void *dest,int size); +/** +* Read the current system time +* +* This reads the current Local Time and places it into the provided +* structure. +* +* @param rt Place to put system time +*/ +void os_localtime (struct rtc_time *rt); +#endif
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 11/20 dm: sandbox: Add os_localtime() to obtain the system time
Quoted 8 lines · Simon Glass
Add a function to read the system time into U-Boot.
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/cpu/os.c | 18 ++++++++++++++++++ include/os.h | 11 +++++++++++ 2 files changed, 29 insertions(+)
Applied to u-boot-dm.
PATCH 12/20 dm: rtc: Add a uclass for real-time clocks
In reply to Simon GlassAdd a uclass for real-time clocks which support getting the current time, setting it and resetting the chip to a known-working state. Some RTCs have additional registers which can be used to store settings, so also provide an interface to these.
---
drivers/rtc/Kconfig | 8 +++ drivers/rtc/Makefile | 2 + drivers/rtc/rtc-uclass.c | 96 ++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/rtc.h | 132 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 drivers/rtc/rtc-uclass.c
drivers/rtc/Kconfig +8 -0
@@ -0,0 +1,8 @@ +config DM_RTC + bool "Enable Driver Model for RTC drivers" + depends on DM + help + Enable drver model for real-time-clock drivers. The RTC uclass + then provides the rtc_get()/rtc_set() interface, delegating to + drivers to perform the actual functions. See rtc.h for a + description of the API.
drivers/rtc/Makefile +2 -0
@@ -7,6 +7,8 @@ #ccflags-y += -DDEBUG +obj-$(CONFIG_DM_RTC) += rtc-uclass.o + obj-$(CONFIG_RTC_AT91SAM9_RTT) += at91sam9_rtt.o obj-$(CONFIG_RTC_BFIN) += bfin_rtc.o obj-y += date.o
drivers/rtc/rtc-uclass.c new file +96 -0
96 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -45,6 +45,7 @@ enum uclass_id {UCLASS_USB_HUB ,/* USB hub */ UCLASS_USB_DEV_GENERIC ,/* USB generic device */ UCLASS_MASS_STORAGE ,/* Mass storage device */ +UCLASS_RTC ,/* Real time clock device */ UCLASS_COUNT , UCLASS_INVALID = -1,
include/rtc.h +132 -0
144 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 12/20 dm: rtc: Add a uclass for real-time clocks
Quoted 8 lines · Simon Glass
Add a uclass for real-time clocks which support getting the current time, setting it and resetting the chip to a known-working state. Some RTCs have additional registers which can be used to store settings, so also provide an interface to these.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
drivers/rtc/Kconfig | 8 +++ drivers/rtc/Makefile | 2 + drivers/rtc/rtc-uclass.c | 96 ++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/rtc.h | 132 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 drivers/rtc/rtc-uclass.c
Applied to u-boot-dm.
PATCH 13/20 dm: rtc: sandbox: Add an emulated I2C RTC device
In reply to Simon GlassAdd a sandbox I2C emulation device which emulates a real-time clock. The clock works off an offset from the current system time, and supports setting and getting the clock, as well as access to byte-width regisers in the RTC. It does not support changing the system time.
This device can be used for testing the 'date' command on sandbox, as well as the RTC uclass.
---
arch/sandbox/include/asm/rtc.h | 28 +++++ arch/sandbox/include/asm/test.h | 21 ++++ drivers/rtc/Makefile | 1 + drivers/rtc/i2c_rtc_emul.c | 236 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 286 insertions(+) create mode 100644 arch/sandbox/include/asm/rtc.h create mode 100644 drivers/rtc/i2c_rtc_emul.c
arch/sandbox/include/asm/rtc.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Simulate an I2C real time clock +* +* Copyright (c) 2015 Google, Inc +* Written by Simon Glass <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __asm_rtc_h +#define __asm_rtc_h + +/* Register numbers in the sandbox RTC */ +enum { +REG_SEC =5 , +REG_MIN , +REG_HOUR , +REG_MDAY , +REG_MON , +REG_YEAR , +REG_WDAY , + +REG_RESET =0x20 , + +REG_COUNT =0x80 , +}; + +#endif
arch/sandbox/include/asm/test.h +21 -0
@@ -38,4 +38,25 @@ void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,void sandbox_i2c_eeprom_set_offset_len (struct udevice *dev,int offset_len); +/** +* sandbox_i2c_rtc_set_offset() - set the time offset from system/base time +* +* @dev: RTC device to adjust +* @use_system_time: true to use system time, false to use @base_time +* @offset: RTC offset from current system/base time (-1 for no +* change) +* @return old value of RTC offset +*/ +long sandbox_i2c_rtc_set_offset (struct udevice *dev,bool use_system_time, +int offset); + +/** +* sandbox_i2c_rtc_get_set_base_time() - get and set the base time +* +* @dev: RTC device to adjust +* @base_time: New base system time (set to -1 for no change) +* @return old base time +*/ +long sandbox_i2c_rtc_get_set_base_time (struct udevice *dev,long base_time); +#endif
drivers/rtc/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_RTC_DS164x) += ds164x.o obj-$(CONFIG_RTC_DS174x) += ds174x.o obj-$(CONFIG_RTC_DS3231) += ds3231.o obj-$(CONFIG_RTC_FTRTC010) += ftrtc010.o +obj-$(CONFIG_SANDBOX) += i2c_rtc_emul.o obj-$(CONFIG_RTC_IMXDI) += imxdi.o obj-$(CONFIG_RTC_ISL1208) += isl1208.o obj-$(CONFIG_RTC_M41T11) += m41t11.o
drivers/rtc/i2c_rtc_emul.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 13/20 dm: rtc: sandbox: Add an emulated I2C RTC device
Quoted 11 lines · Simon Glass
Add a sandbox I2C emulation device which emulates a real-time clock. The clock works off an offset from the current system time, and supports setting and getting the clock, as well as access to byte-width regisers in the RTC. It does not support changing the system time.
This device can be used for testing the 'date' command on sandbox, as well as the RTC uclass.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
arch/sandbox/include/asm/rtc.h | 28 +++++ arch/sandbox/include/asm/test.h | 21 ++++ drivers/rtc/Makefile | 1 + drivers/rtc/i2c_rtc_emul.c | 236 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 286 insertions(+) create mode 100644 arch/sandbox/include/asm/rtc.h create mode 100644 drivers/rtc/i2c_rtc_emul.c
Applied to u-boot-dm.
PATCH 14/20 dm: rtc: sandbox: Add a driver for the sandbox I2C RTC
In reply to Simon GlassAdd a driver which communicates with the sandbox I2C emulation RTC device and permits it to be used in U-Boot. This driver is very simple - it just reads and writes selected I2C registers in the device.
---
drivers/rtc/Makefile | 3 ++ drivers/rtc/sandbox_rtc.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 drivers/rtc/sandbox_rtc.c
drivers/rtc/Makefile +3 -0
@@ -52,4 +52,7 @@ obj-$(CONFIG_RTC_RTC4543) += rtc4543.o obj-$(CONFIG_RTC_RV3029) += rv3029.o obj-$(CONFIG_RTC_RX8025) += rx8025.o obj-$(CONFIG_RTC_S3C24X0) += s3c24x0_rtc.o +ifdef CONFIG_DM_RTC +obj-$(CONFIG_SANDBOX) += sandbox_rtc.o +endif obj-$(CONFIG_RTC_X1205) += x1205.o
drivers/rtc/sandbox_rtc.c new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 14/20 dm: rtc: sandbox: Add a driver for the sandbox I2C RTC
Quoted 11 lines · Simon Glass
Add a driver which communicates with the sandbox I2C emulation RTC device and permits it to be used in U-Boot. This driver is very simple - it just reads and writes selected I2C registers in the device.
Signed-off-by Simon Glass <[email protected]>---
drivers/rtc/Makefile | 3 ++ drivers/rtc/sandbox_rtc.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 drivers/rtc/sandbox_rtc.c
Applied to u-boot-dm.
PATCH 15/20 dm: rtc: Convert 'date' command to support driver model
In reply to Simon GlassAdjust 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.
---
common/cmd_date.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-)
common/cmd_date.c +39 -14
@@ -10,6 +10,7 @@*/ #include <common.h> #include <command.h> +#include <dm.h> #include <rtc.h> #include <i2c.h>
@@ -31,10 +32,18 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {struct rtc_time tm;int rcode =0 ; -int old_bus; +int old_bus__maybe_unused ;/* 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 ();i2c_set_bus_num (CONFIG_SYS_RTC_BUS_NUM );#else
@@ -46,29 +55,45 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])case 2 :/* set date & time */ if (strcmp (argv[1 ],"reset" ) ==0 ) {puts ("Reset RTC...\n" ); -rtc_reset (); +#ifdef CONFIG_DM_I2C + rcode =dm_rtc_reset (dev); +#else +rtc_reset (); +#endif }else {/* initialize tm with current time */ - rcode =rtc_get (&tm); - -if (!rcode) { +#ifdef CONFIG_DM_I2C + rcode =dm_rtc_get (dev, &tm); +#else + rcode =rtc_get (&tm); +#endif +if (!rcode) {/* insert new date & time */ -if (mk_date (argv[1 ], &tm) !=0 ) { +if (mk_date (argv[1 ], &tm) !=0 ) {puts ("## Bad date format\n" );break ; }/* and write to RTC */ - rcode =rtc_set (&tm); -if (rcode) -puts ("## Set date failed\n" ); +#ifdef CONFIG_DM_I2C + rcode =dm_rtc_set (dev, &tm); +#else + rcode =rtc_set (&tm); +#endif +if (rcode) { +printf ("## Set date failed: err=%d\n" , + rcode); + } }else {puts ("## Get date failed\n" ); } }/* FALL TROUGH */ 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) {puts ("## Get date failed\n" );break ;
@@ -88,11 +113,11 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])/* switch back to original I2C bus */ #ifdef CONFIG_SYS_I2C i2c_set_bus_num (old_bus); -#else +#elif !defined(CONFIG_DM_I2C )I2C_SET_BUS (old_bus);#endif -return rcode; +return rcode ?CMD_RET_FAILURE :0 ; }/*
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 15/20 dm: rtc: Convert 'date' command to support driver model
Quoted 8 lines · Simon Glass
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 <[email protected]>---
common/cmd_date.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-)
Applied to u-boot-dm.
PATCH 16/20 dm: net: rtc: Support using driver model for rtc in sntp
In reply to Simon GlassWhen setting the date, support driver model RTC also.
---
net/sntp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/sntp.c +12 -0
@@ -7,6 +7,7 @@#include <common.h> #include <command.h> +#include <dm.h> #include <net.h> #include <rtc.h>
@@ -70,7 +71,18 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,rtc_to_tm (ntohl (seconds) -2208988800UL + net_ntp_time_offset, &tm);#if defined(CONFIG_CMD_DATE ) +# ifdef CONFIG_DM_RTC +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_RTC ,0 , &dev); +if (ret) +printf ("SNTP: cannot find RTC: err=%d\n" , ret); +else +dm_rtc_set (dev, &tm); +# else rtc_set (&tm); +# endif #endif printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n", tm.tm_year, tm.tm_mon, tm.tm_mday,
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 16/20 dm: net: rtc: Support using driver model for rtc in sntp
Hi Simon,
Quoted 3 lines · Simon Glass
When setting the date, support driver model RTC also.
Signed-off-by Simon Glass <[email protected]>
PATCH 16/20 dm: net: rtc: Support using driver model for rtc in sntp
Quoted 8 lines · Joe Hershberger
Hi Simon,
Quoted 3 lines · Simon Glass
When setting the date, support driver model RTC also.
Signed-off-by Simon Glass <[email protected]>Acked-by Joe Hershberger <[email protected]>
Applied to u-boot-dm.
PATCH 17/20 dm: sandbox: dts: Add a real-time clock attached to I2C
In reply to Simon GlassAdd an emulated RTC device for sandbox, so that the 'date' command can be used.
---
arch/sandbox/dts/sandbox.dts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/sandbox/dts/sandbox.dts +11 -1
@@ -8,7 +8,9 @@ aliases { eth5 = "/eth at 90000000"; + i2c0 = &i2c_0; pci0 = &pci; + rtc0 = &rtc_0; }; chosen {
@@ -90,7 +92,7 @@ num-gpios = <10>; }; - i2c at 0 { + i2c_0: i2c at 0 { #address-cells = <1>; #size-cells = <0>; reg = <0 0>;
@@ -105,6 +107,14 @@ sandbox,size = <128>; }; }; + + rtc_0: rtc at 43 { + reg = <0x43>; + compatible = "sandbox-rtc"; + emul { + compatible = "sandbox,i2c-rtc"; + }; + }; }; spi at 0 {
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 17/20 dm: sandbox: dts: Add a real-time clock attached to I2C
Quoted 8 lines · Simon Glass
Add an emulated RTC device for sandbox, so that the 'date' command can be used.
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/dts/sandbox.dts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Applied to u-boot-dm.
PATCH 18/20 dm: rtc: sandbox: Enable real-time clock support
In reply to Simon GlassEnable real-time-clock support in sandbox.
---
configs/sandbox_defconfig | 1 + drivers/rtc/Makefile | 2 -- include/configs/sandbox.h | 1 + 3 files changed, 2 insertions(+), 2 deletions(-)
configs/sandbox_defconfig +1 -0
@@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_DM_RTC=y
drivers/rtc/Makefile +0 -2
@@ -52,7 +52,5 @@ obj-$(CONFIG_RTC_RTC4543) += rtc4543.o obj-$(CONFIG_RTC_RV3029) += rv3029.o obj-$(CONFIG_RTC_RX8025) += rx8025.o obj-$(CONFIG_RTC_S3C24X0) += s3c24x0_rtc.o -ifdef CONFIG_DM_RTC obj-$(CONFIG_SANDBOX) += sandbox_rtc.o -endif obj-$(CONFIG_RTC_X1205) += x1205.o
include/configs/sandbox.h +1 -0
@@ -192,5 +192,6 @@#define CONFIG_CMD_LZMADEC #define CONFIG_CMD_USB +#define CONFIG_CMD_DATE #endif
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 18/20 dm: rtc: sandbox: Enable real-time clock support
Quoted 9 lines · Simon Glass
Enable real-time-clock support in sandbox.
Signed-off-by Simon Glass <[email protected]>---
configs/sandbox_defconfig | 1 + drivers/rtc/Makefile | 2 -- include/configs/sandbox.h | 1 + 3 files changed, 2 insertions(+), 2 deletions(-)
Applied to u-boot-dm.
PATCH 19/20 dm: test: dts: Sort the aliases in the test device tree file
In reply to Simon GlassSort these aliases to avoid confusion as to what is present.
---
test/dm/test.dts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
test/dm/test.dts +4 -4
@@ -8,18 +8,18 @@ aliases { console = &uart0; + eth0 = "/eth at 10002000"; + eth5 = ð_5; i2c0 = "/i2c at 0"; - spi0 = "/spi at 0"; pci0 = &pci; - testfdt6 = "/e-test"; + spi0 = "/spi at 0"; testbus3 = "/some-bus"; testfdt0 = "/some-bus/c-test at 0"; testfdt1 = "/some-bus/c-test at 1"; testfdt3 = "/b-test"; testfdt5 = "/some-bus/c-test at 5"; + testfdt6 = "/e-test"; testfdt8 = "/a-test"; - eth0 = "/eth at 10002000"; - eth5 = ð_5; usb0 = &usb_0; usb1 = &usb_1; usb2 = &usb_2;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 19/20 dm: test: dts: Sort the aliases in the test device tree file
Hi Simon,
Quoted 4 lines · Simon Glass
Sort these aliases to avoid confusion as to what is present.
Signed-off-by Simon Glass <[email protected]>---
PATCH 19/20 dm: test: dts: Sort the aliases in the test device tree file
Quoted 9 lines · Joe Hershberger
Hi Simon,
Quoted 4 lines · Simon Glass
Sort these aliases to avoid confusion as to what is present.
Signed-off-by Simon Glass <[email protected]>---
Reviewed-by Joe Hershberger <[email protected]>
Applied to u-boot-dm.
PATCH 20/20 dm: rtc: Add tests for real-time clocks
In reply to Simon GlassAdd some simple tests to verify that the RTC uclass works correctly in U-Boot.
---
test/dm/Makefile | 1 + test/dm/rtc.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test.dts | 18 ++++++ 3 files changed, 194 insertions(+) create mode 100644 test/dm/rtc.c
test/dm/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_DM_PCI) += pci.o +obj-$(CONFIG_DM_RTC) += rtc.o obj-$(CONFIG_DM_SPI_FLASH) += sf.o obj-$(CONFIG_DM_SPI) += spi.o obj-$(CONFIG_DM_USB) += usb.o
test/dm/rtc.c new file +175 -0
175 lines not on this page · raw message
test/dm/test.dts +18 -0
@@ -20,6 +20,8 @@ testfdt5 = "/some-bus/c-test at 5"; testfdt6 = "/e-test"; testfdt8 = "/a-test"; + rtc0 = &rtc_0; + rtc1 = &rtc_1; usb0 = &usb_0; usb1 = &usb_1; usb2 = &usb_2;
@@ -139,6 +141,22 @@ sandbox,size = <256>; }; }; + + rtc_0: rtc at 43 { + reg = <0x43>; + compatible = "sandbox-rtc"; + emul { + compatible = "sandbox,i2c-rtc"; + }; + }; + + rtc_1: rtc at 61 { + reg = <0x61>; + compatible = "sandbox-rtc"; + emul { + compatible = "sandbox,i2c-rtc"; + }; + }; }; pci: pci-controller {
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH 20/20 dm: rtc: Add tests for real-time clocks
Quoted 11 lines · Simon Glass
Add some simple tests to verify that the RTC uclass works correctly in U-Boot.
Signed-off-by Simon Glass <[email protected]>---
test/dm/Makefile | 1 + test/dm/rtc.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test.dts | 18 ++++++ 3 files changed, 194 insertions(+) create mode 100644 test/dm/rtc.c
Applied to u-boot-dm.
cover dm: rtc: Add driver model support for real-time clocks
In reply to Simon GlassHi,
Quoted 29 lines · Simon Glass
When driver model is used for I2C, the real-time clock functionality does not work (e.g. the 'date' command gives build errors when
CONFIG_DM_I2Cis defined). It is possible to work around this by using driver model I2C functions. But what is really needed is an RTC uclass.This series:
- renames some RTC functions to have anrtc_prefix
- adds sandbox support for RTC and an emulated I2C RTC device
- adds a driver model RTC uclass and associated tests
- corrects various minor driver model I2C issues that were discoveredWith this it should be fairly easy to convert an existing RTC driver to driver model, but this series does not include that as I'm not sure if any of the boards I have include an RTC.
Simon Glass (20):
dm: spi: Correct the comment onspi_get_ops()
dm: i2c: sandbox: Add debugging to the speed limit
dm: i2c: Add functions to read and write a register
dm: i2c: Add an explicit test mode to the sandbox I2C driver
fdt: Correct warning infdt_setup_simplefb_node()
dm: rtc: Rename gregorian day function
dm: rtc: Renameto_tm()tortc_to_tm()and add error code
dm: rtc: Renamemktime()and reduce the number of parameters
dm: Remove unnecessary types inbcd.h
dm: rtc: Split structure definition into its own file
dm: sandbox: Addos_localtime()to obtain the system time
dm: rtc: Add a uclass for real-time clocks
Quoted 8 lines
dm: rtc: sandbox: Add an emulated I2C RTC device
dm: rtc: sandbox: Add a driver for the sandbox I2C RTC
dm: rtc: Convert 'date' command to support driver model
dm: net: rtc: Support using driver model for rtc in sntp
dm: sandbox: dts: Add a real-time clock attached to I2C
dm: rtc: sandbox: Enable real-time clock support
dm: test: dts: Sort the aliases in the test device tree file
dm: rtc: Add tests for real-time clocks
Thanks for the various reviews on this series. If there is nothing else, I will pull this in soon.
Regards,
Simon
cover dm: rtc: Add driver model support for real-time clocks
Bonjour Simon,
Le Tue, 28 Apr 2015 20:43:47 -0600, Simon Glass <[email protected]> a ?crit :
Quoted 2 lines
Thanks for the various reviews on this series. If there is nothing else, I will pull this in soon.
Seems ok, apart from a few 'implicit declaration' warnings here that do not seem to have been seen by others:
common/cmd_date.c:65:4: attention : implicit declaration of function ?rtc_set? [-Wimplicit-function-declaration]
drivers/rtc/ds1374.c: In function ?rtc_read?:drivers/rtc/ds1374.c:215:2: attention : implicit declaration of function ?i2c_reg_read? [-Wimplicit-function-declaration] drivers/rtc/ds1374.c: In function ?rtc_write?:drivers/rtc/ds1374.c:222:3: attention : implicit declaration of function ?i2c_reg_write? [-Wimplicit-function-declaration]
Quoted 2 lines
Regards,
Simon
Cordialement,
Albert ARIBAUD
3ADEV
cover dm: rtc: Add driver model support for real-time clocks
Hi Albert,
Quoted 14 lines · Albert ARIBAUD
Bonjour Simon,
Le Tue, 28 Apr 2015 20:43:47 -0600, Simon Glass <[email protected]> a ?crit :
Quoted 2 lines
Thanks for the various reviews on this series. If there is nothing else, I will pull this in soon.
Seems ok, apart from a few 'implicit declaration' warnings here that do not seem to have been seen by others:
common/cmd_date.c:65:4: attention : implicit declaration of function ?rtc_set? [-Wimplicit-function-declaration]
Quoted 6 lines
drivers/rtc/ds1374.c: In function ?rtc_read?:drivers/rtc/ds1374.c:215:2: attention : implicit declaration of function ?i2c_reg_read? [-Wimplicit-function-declaration]drivers/rtc/ds1374.c: In function ?rtc_write?:drivers/rtc/ds1374.c:222:3: attention : implicit declaration of function ?i2c_reg_write? [-Wimplicit-function-declaration]
That's because those functions are not defined in he compatibility layer. Presumably the build fails also?
I'll apply what I have (assuming I still don't see any build errors) and send out a patch for this.
Regards,
Simon