Lines Matching +full:start +full:- +full:year

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the Epson RTC module RX-6110 SA
20 /* RX-6110 Register definitions */
104 * rx6110_rtc_tm_to_data - convert rtc_time to native time encoding
114 * The year in the RTC is a value between 0 and 99. in rx6110_rtc_tm_to_data()
118 if (tm->tm_year < 100 || tm->tm_year >= 200) in rx6110_rtc_tm_to_data()
119 return -EINVAL; in rx6110_rtc_tm_to_data()
121 data[RTC_SEC] = bin2bcd(tm->tm_sec); in rx6110_rtc_tm_to_data()
122 data[RTC_MIN] = bin2bcd(tm->tm_min); in rx6110_rtc_tm_to_data()
123 data[RTC_HOUR] = bin2bcd(tm->tm_hour); in rx6110_rtc_tm_to_data()
124 data[RTC_WDAY] = BIT(bin2bcd(tm->tm_wday)); in rx6110_rtc_tm_to_data()
125 data[RTC_MDAY] = bin2bcd(tm->tm_mday); in rx6110_rtc_tm_to_data()
126 data[RTC_MONTH] = bin2bcd(tm->tm_mon + 1); in rx6110_rtc_tm_to_data()
127 data[RTC_YEAR] = bin2bcd(tm->tm_year % 100); in rx6110_rtc_tm_to_data()
133 * rx6110_data_to_rtc_tm - convert native time encoding to rtc_time
140 tm->tm_sec = bcd2bin(data[RTC_SEC] & 0x7f); in rx6110_data_to_rtc_tm()
141 tm->tm_min = bcd2bin(data[RTC_MIN] & 0x7f); in rx6110_data_to_rtc_tm()
142 /* only 24-hour clock */ in rx6110_data_to_rtc_tm()
143 tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f); in rx6110_data_to_rtc_tm()
144 tm->tm_wday = ffs(data[RTC_WDAY] & 0x7f); in rx6110_data_to_rtc_tm()
145 tm->tm_mday = bcd2bin(data[RTC_MDAY] & 0x3f); in rx6110_data_to_rtc_tm()
146 tm->tm_mon = bcd2bin(data[RTC_MONTH] & 0x1f) - 1; in rx6110_data_to_rtc_tm()
147 tm->tm_year = bcd2bin(data[RTC_YEAR]) + 100; in rx6110_data_to_rtc_tm()
152 * The year in the RTC is a value between 0 and 99. in rx6110_data_to_rtc_tm()
156 if (tm->tm_year < 100 || tm->tm_year >= 200) in rx6110_data_to_rtc_tm()
157 return -EINVAL; in rx6110_data_to_rtc_tm()
163 * rx6110_set_time - set the current time in the rx6110 registers
168 * BUG: The HW assumes every year that is a multiple of 4 to be a leap
169 * year. Next time this is wrong is 2100, which will not be a leap year
171 * Note: If STOP is not set/cleared, the clock will start when the seconds
186 ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL, in rx6110_set_time()
191 ret = regmap_bulk_write(rx6110->regmap, RX6110_REG_SEC, data, in rx6110_set_time()
197 ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG, in rx6110_set_time()
203 ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL, in rx6110_set_time()
210 * rx6110_get_time - get the current time from the rx6110 registers
221 ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags); in rx6110_get_time()
223 return -EINVAL; in rx6110_get_time()
225 /* check for VLF Flag (set at power-on) */ in rx6110_get_time()
228 return -EINVAL; in rx6110_get_time()
232 ret = regmap_bulk_read(rx6110->regmap, RX6110_REG_SEC, data, in rx6110_get_time()
257 * rx6110_init - initialize the rx6110 registers
264 struct rtc_device *rtc = rx6110->rtc; in rx6110_init()
268 ret = regmap_update_bits(rx6110->regmap, RX6110_REG_EXT, in rx6110_init()
273 ret = regmap_register_patch(rx6110->regmap, rx6110_default_regs, in rx6110_init()
278 ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags); in rx6110_init()
282 /* check for VLF Flag (set at power-on) */ in rx6110_init()
284 dev_warn(&rtc->dev, "Voltage low, data loss detected.\n"); in rx6110_init()
288 dev_warn(&rtc->dev, "An alarm may have been missed.\n"); in rx6110_init()
292 dev_warn(&rtc->dev, "Periodic timer was detected\n"); in rx6110_init()
296 dev_warn(&rtc->dev, "Update timer was detected\n"); in rx6110_init()
299 ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG, in rx6110_init()
321 * rx6110_probe - initialize rtc driver
329 if ((spi->bits_per_word && spi->bits_per_word != 8) || in rx6110_probe()
330 (spi->max_speed_hz > 2000000) || in rx6110_probe()
331 (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) { in rx6110_probe()
332 dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n", in rx6110_probe()
333 spi->bits_per_word, spi->max_speed_hz, spi->mode); in rx6110_probe()
334 dev_warn(&spi->dev, "driving device in an unsupported mode"); in rx6110_probe()
337 rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL); in rx6110_probe()
339 return -ENOMEM; in rx6110_probe()
341 rx6110->regmap = devm_regmap_init_spi(spi, &regmap_spi_config); in rx6110_probe()
342 if (IS_ERR(rx6110->regmap)) { in rx6110_probe()
343 dev_err(&spi->dev, "regmap init failed for rtc rx6110\n"); in rx6110_probe()
344 return PTR_ERR(rx6110->regmap); in rx6110_probe()
349 rx6110->rtc = devm_rtc_device_register(&spi->dev, in rx6110_probe()
353 if (IS_ERR(rx6110->rtc)) in rx6110_probe()
354 return PTR_ERR(rx6110->rtc); in rx6110_probe()
360 rx6110->rtc->max_user_freq = 1; in rx6110_probe()
389 MODULE_DESCRIPTION("RX-6110 SA RTC driver");