Lines Matching +full:one +full:- +full:shot

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
26 #define NUM_TIME_REGS (TPS6594_REG_RTC_WEEKS - TPS6594_REG_RTC_SECONDS + 1)
29 #define NUM_TIME_ALARM_REGS (NUM_TIME_REGS - 1)
33 * After conversion, the values do not exceed the range [-32767, 33767]
36 #define MIN_OFFSET (-277774)
53 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_alarm_irq_enable()
58 return regmap_update_bits(tps->regmap, TPS6594_REG_RTC_INTERRUPTS, in tps6594_rtc_alarm_irq_enable()
69 * an up-to-date timestamp. in tps6594_rtc_shadow_timestamp()
71 ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_shadow_timestamp()
80 return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_shadow_timestamp()
87 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_read_time()
91 ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_read_time()
96 return -EINVAL; in tps6594_rtc_read_time()
103 ret = regmap_bulk_read(tps->regmap, TPS6594_REG_RTC_SECONDS, rtc_data, in tps6594_rtc_read_time()
108 tm->tm_sec = bcd2bin(rtc_data[0]); in tps6594_rtc_read_time()
109 tm->tm_min = bcd2bin(rtc_data[1]); in tps6594_rtc_read_time()
110 tm->tm_hour = bcd2bin(rtc_data[2]); in tps6594_rtc_read_time()
111 tm->tm_mday = bcd2bin(rtc_data[3]); in tps6594_rtc_read_time()
112 tm->tm_mon = bcd2bin(rtc_data[4]) - 1; in tps6594_rtc_read_time()
113 tm->tm_year = bcd2bin(rtc_data[5]) + 100; in tps6594_rtc_read_time()
114 tm->tm_wday = bcd2bin(rtc_data[6]); in tps6594_rtc_read_time()
122 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_set_time()
125 rtc_data[0] = bin2bcd(tm->tm_sec); in tps6594_rtc_set_time()
126 rtc_data[1] = bin2bcd(tm->tm_min); in tps6594_rtc_set_time()
127 rtc_data[2] = bin2bcd(tm->tm_hour); in tps6594_rtc_set_time()
128 rtc_data[3] = bin2bcd(tm->tm_mday); in tps6594_rtc_set_time()
129 rtc_data[4] = bin2bcd(tm->tm_mon + 1); in tps6594_rtc_set_time()
130 rtc_data[5] = bin2bcd(tm->tm_year - 100); in tps6594_rtc_set_time()
131 rtc_data[6] = bin2bcd(tm->tm_wday); in tps6594_rtc_set_time()
134 ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_set_time()
139 // Update all the time registers in one shot. in tps6594_rtc_set_time()
140 ret = regmap_bulk_write(tps->regmap, TPS6594_REG_RTC_SECONDS, rtc_data, in tps6594_rtc_set_time()
146 return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_set_time()
154 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_read_alarm()
157 ret = regmap_bulk_read(tps->regmap, TPS6594_REG_ALARM_SECONDS, in tps6594_rtc_read_alarm()
162 alm->time.tm_sec = bcd2bin(alarm_data[0]); in tps6594_rtc_read_alarm()
163 alm->time.tm_min = bcd2bin(alarm_data[1]); in tps6594_rtc_read_alarm()
164 alm->time.tm_hour = bcd2bin(alarm_data[2]); in tps6594_rtc_read_alarm()
165 alm->time.tm_mday = bcd2bin(alarm_data[3]); in tps6594_rtc_read_alarm()
166 alm->time.tm_mon = bcd2bin(alarm_data[4]) - 1; in tps6594_rtc_read_alarm()
167 alm->time.tm_year = bcd2bin(alarm_data[5]) + 100; in tps6594_rtc_read_alarm()
169 ret = regmap_read(tps->regmap, TPS6594_REG_RTC_INTERRUPTS, &int_val); in tps6594_rtc_read_alarm()
173 alm->enabled = int_val & TPS6594_BIT_IT_ALARM; in tps6594_rtc_read_alarm()
181 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_set_alarm()
189 alarm_data[0] = bin2bcd(alm->time.tm_sec); in tps6594_rtc_set_alarm()
190 alarm_data[1] = bin2bcd(alm->time.tm_min); in tps6594_rtc_set_alarm()
191 alarm_data[2] = bin2bcd(alm->time.tm_hour); in tps6594_rtc_set_alarm()
192 alarm_data[3] = bin2bcd(alm->time.tm_mday); in tps6594_rtc_set_alarm()
193 alarm_data[4] = bin2bcd(alm->time.tm_mon + 1); in tps6594_rtc_set_alarm()
194 alarm_data[5] = bin2bcd(alm->time.tm_year - 100); in tps6594_rtc_set_alarm()
196 // Update all the alarm registers in one shot. in tps6594_rtc_set_alarm()
197 ret = regmap_bulk_write(tps->regmap, TPS6594_REG_ALARM_SECONDS, in tps6594_rtc_set_alarm()
202 if (alm->enabled) in tps6594_rtc_set_alarm()
210 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_set_calibration()
216 * crystal inaccuracies. One time every hour when seconds counter in tps6594_rtc_set_calibration()
220 * Valid range for compensation value: [-32767 .. 32767]. in tps6594_rtc_set_calibration()
223 return -ERANGE; in tps6594_rtc_set_calibration()
227 // Update all the compensation registers in one shot. in tps6594_rtc_set_calibration()
228 ret = regmap_bulk_write(tps->regmap, TPS6594_REG_RTC_COMP_LSB, &value, in tps6594_rtc_set_calibration()
234 return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_set_calibration()
240 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_get_calibration()
245 ret = regmap_read(tps->regmap, TPS6594_REG_RTC_CTRL_1, &ctrl); in tps6594_rtc_get_calibration()
255 ret = regmap_bulk_read(tps->regmap, TPS6594_REG_RTC_COMP_LSB, &value, in tps6594_rtc_get_calibration()
279 tmp -= TICKS_PER_HOUR / 2LL; in tps6594_rtc_read_offset()
286 * Computatiion is the reverse operation of the one done in in tps6594_rtc_read_offset()
292 * See 8.3.10.5, (32768 - COMP_REG). in tps6594_rtc_read_offset()
294 *offset = (long)-tmp; in tps6594_rtc_read_offset()
306 return -ERANGE; in tps6594_rtc_set_offset()
312 tmp -= PPB_MULT / 2LL; in tps6594_rtc_set_offset()
319 * - tmp = offset * TICK_PER_HOUR : in tps6594_rtc_set_offset()
321 * which is lower than the maximum value in an `s64` (2^63-1). No overflow here. in tps6594_rtc_set_offset()
323 * - tmp += TICK_PER_HOUR / 2LL : in tps6594_rtc_set_offset()
324 * tmp will have a maximum value of 277774117964800 which is still inferior to 2^63-1. in tps6594_rtc_set_offset()
328 calibration = (int)-tmp; in tps6594_rtc_set_offset()
336 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_interrupt()
341 ret = regmap_read(tps->regmap, TPS6594_REG_RTC_STATUS, &rtc_reg); in tps6594_rtc_interrupt()
345 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); in tps6594_rtc_interrupt()
362 struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); in tps6594_rtc_probe()
363 struct device *dev = &pdev->dev; in tps6594_rtc_probe()
370 return -ENOMEM; in tps6594_rtc_probe()
372 rtc->rtc_dev = devm_rtc_allocate_device(dev); in tps6594_rtc_probe()
373 if (IS_ERR(rtc->rtc_dev)) in tps6594_rtc_probe()
374 return PTR_ERR(rtc->rtc_dev); in tps6594_rtc_probe()
377 ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_2, in tps6594_rtc_probe()
382 ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_probe()
388 ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_probe()
403 ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_probe()
408 return -ENODEV; in tps6594_rtc_probe()
411 ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_probe()
423 rtc->irq = irq; in tps6594_rtc_probe()
437 rtc->rtc_dev->ops = &tps6594_rtc_ops; in tps6594_rtc_probe()
438 rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000; in tps6594_rtc_probe()
439 rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_2099; in tps6594_rtc_probe()
441 return devm_rtc_register_device(rtc->rtc_dev); in tps6594_rtc_probe()
446 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_resume()
450 ret = regmap_test_bits(tps->regmap, TPS6594_REG_INT_STARTUP, in tps6594_rtc_resume()
463 ret = regmap_write(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_resume()
468 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); in tps6594_rtc_resume()
471 disable_irq_wake(rtc->irq); in tps6594_rtc_resume()
480 enable_irq_wake(rtc->irq); in tps6594_rtc_suspend()
488 { "tps6594-rtc", },
496 .name = "tps6594-rtc",