X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=include%2Frtc.h;h=1efc0db3de60c1fe3d20ba662832a3e1398f1bd5;hb=92832045c54586e9dffa082ff8cd8c2ef6040757;hp=69fe8d4db05316703ad6e48fa36843185e099f45;hpb=c9feb427aba860ebc79f9851a1bb49cc456a2d48;p=platform%2Fkernel%2Fu-boot.git diff --git a/include/rtc.h b/include/rtc.h index 69fe8d4..1efc0db 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -1,8 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * (C) Copyright 2001 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -19,6 +18,8 @@ #ifdef CONFIG_DM_RTC +struct udevice; + struct rtc_ops { /** * get() - get the current time @@ -55,6 +56,30 @@ struct rtc_ops { int (*reset)(struct udevice *dev); /** + * read() - Read multiple 8-bit registers + * + * @dev: Device to read from + * @reg: First register to read + * @buf: Output buffer + * @len: Number of registers to read + * @return 0 if OK, -ve on error + */ + int (*read)(struct udevice *dev, unsigned int reg, + u8 *buf, unsigned int len); + + /** + * write() - Write multiple 8-bit registers + * + * @dev: Device to write to + * @reg: First register to write + * @buf: Input buffer + * @len: Number of registers to write + * @return 0 if OK, -ve on error + */ + int (*write)(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len); + + /** * read8() - Read an 8-bit register * * @dev: Device to read from @@ -87,7 +112,7 @@ struct rtc_ops { int dm_rtc_get(struct udevice *dev, struct rtc_time *time); /** - * dm_rtc_put() - Write a time to an RTC + * dm_rtc_set() - Write a time to an RTC * * @dev: Device to read from * @time: Time to write into the RTC @@ -109,6 +134,29 @@ int dm_rtc_set(struct udevice *dev, struct rtc_time *time); int dm_rtc_reset(struct udevice *dev); /** + * dm_rtc_read() - Read multiple 8-bit registers + * + * @dev: Device to read from + * @reg: First register to read + * @buf: Output buffer + * @len: Number of registers to read + * @return 0 if OK, -ve on error + */ +int dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len); + +/** + * dm_rtc_write() - Write multiple 8-bit registers + * + * @dev: Device to write to + * @reg: First register to write + * @buf: Input buffer + * @len: Number of registers to write + * @return 0 if OK, -ve on error + */ +int dm_rtc_write(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len); + +/** * rtc_read8() - Read an 8-bit register * * @dev: Device to read from @@ -128,6 +176,26 @@ int rtc_read8(struct udevice *dev, unsigned int reg); int rtc_write8(struct udevice *dev, unsigned int reg, int val); /** + * rtc_read16() - Read a 16-bit value from the RTC + * + * @dev: Device to read from + * @reg: Offset to start reading from + * @valuep: Place to put the value that is read + * @return 0 if OK, -ve on error + */ +int rtc_read16(struct udevice *dev, unsigned int reg, u16 *valuep); + +/** + * rtc_write16() - Write a 16-bit value to the RTC + * + * @dev: Device to write to + * @reg: Register to start writing to + * @value: Value to write + * @return 0 if OK, -ve on error + */ +int rtc_write16(struct udevice *dev, unsigned int reg, u16 value); + +/** * rtc_read32() - Read a 32-bit value from the RTC * * @dev: Device to read from @@ -147,11 +215,17 @@ int rtc_read32(struct udevice *dev, unsigned int reg, u32 *valuep); */ int rtc_write32(struct udevice *dev, unsigned int reg, u32 value); +#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT +int rtc_enable_32khz_output(int busnum, int chip_addr); +#endif + #else int rtc_get (struct rtc_time *); int rtc_set (struct rtc_time *); void rtc_reset (void); +#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT void rtc_enable_32khz_output(void); +#endif /** * rtc_read8() - Read an 8-bit register @@ -189,7 +263,18 @@ void rtc_write32(int reg, u32 value); * rtc_init() - Set up the real time clock ready for use */ void rtc_init(void); -#endif +#endif /* CONFIG_DM_RTC */ + +/** + * is_leap_year - Check if year is a leap year + * + * @year Year + * @return 1 if leap year + */ +static inline bool is_leap_year(unsigned int year) +{ + return (!(year % 4) && (year % 100)) || !(year % 400); +} /** * rtc_calc_weekday() - Work out the weekday from a time @@ -212,9 +297,8 @@ int rtc_calc_weekday(struct rtc_time *time); * * @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); +void rtc_to_tm(u64 time_t, struct rtc_time *time); /** * rtc_mktime() - Convert a broken-out time into a time_t value @@ -229,4 +313,12 @@ int rtc_to_tm(int time_t, struct rtc_time *time); */ unsigned long rtc_mktime(const struct rtc_time *time); +/** + * rtc_month_days() - The number of days in the month + * + * @month: month (January = 0) + * @year: year (4 digits) + */ +int rtc_month_days(unsigned int month, unsigned int year); + #endif /* _RTC_H_ */