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)
48 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_alarm_irq_enable()
53 return regmap_update_bits(tps->regmap, TPS6594_REG_RTC_INTERRUPTS, in tps6594_rtc_alarm_irq_enable()
64 * an up-to-date timestamp. in tps6594_rtc_shadow_timestamp()
66 ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_shadow_timestamp()
75 return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_shadow_timestamp()
82 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_read_time()
86 ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_read_time()
91 return -EINVAL; in tps6594_rtc_read_time()
98 ret = regmap_bulk_read(tps->regmap, TPS6594_REG_RTC_SECONDS, rtc_data, in tps6594_rtc_read_time()
103 tm->tm_sec = bcd2bin(rtc_data[0]); in tps6594_rtc_read_time()
104 tm->tm_min = bcd2bin(rtc_data[1]); in tps6594_rtc_read_time()
105 tm->tm_hour = bcd2bin(rtc_data[2]); in tps6594_rtc_read_time()
106 tm->tm_mday = bcd2bin(rtc_data[3]); in tps6594_rtc_read_time()
107 tm->tm_mon = bcd2bin(rtc_data[4]) - 1; in tps6594_rtc_read_time()
108 tm->tm_year = bcd2bin(rtc_data[5]) + 100; in tps6594_rtc_read_time()
109 tm->tm_wday = bcd2bin(rtc_data[6]); in tps6594_rtc_read_time()
117 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_set_time()
120 rtc_data[0] = bin2bcd(tm->tm_sec); in tps6594_rtc_set_time()
121 rtc_data[1] = bin2bcd(tm->tm_min); in tps6594_rtc_set_time()
122 rtc_data[2] = bin2bcd(tm->tm_hour); in tps6594_rtc_set_time()
123 rtc_data[3] = bin2bcd(tm->tm_mday); in tps6594_rtc_set_time()
124 rtc_data[4] = bin2bcd(tm->tm_mon + 1); in tps6594_rtc_set_time()
125 rtc_data[5] = bin2bcd(tm->tm_year - 100); in tps6594_rtc_set_time()
126 rtc_data[6] = bin2bcd(tm->tm_wday); in tps6594_rtc_set_time()
129 ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_set_time()
134 // Update all the time registers in one shot. in tps6594_rtc_set_time()
135 ret = regmap_bulk_write(tps->regmap, TPS6594_REG_RTC_SECONDS, rtc_data, in tps6594_rtc_set_time()
141 return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_set_time()
149 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_read_alarm()
152 ret = regmap_bulk_read(tps->regmap, TPS6594_REG_ALARM_SECONDS, in tps6594_rtc_read_alarm()
157 alm->time.tm_sec = bcd2bin(alarm_data[0]); in tps6594_rtc_read_alarm()
158 alm->time.tm_min = bcd2bin(alarm_data[1]); in tps6594_rtc_read_alarm()
159 alm->time.tm_hour = bcd2bin(alarm_data[2]); in tps6594_rtc_read_alarm()
160 alm->time.tm_mday = bcd2bin(alarm_data[3]); in tps6594_rtc_read_alarm()
161 alm->time.tm_mon = bcd2bin(alarm_data[4]) - 1; in tps6594_rtc_read_alarm()
162 alm->time.tm_year = bcd2bin(alarm_data[5]) + 100; in tps6594_rtc_read_alarm()
164 ret = regmap_read(tps->regmap, TPS6594_REG_RTC_INTERRUPTS, &int_val); in tps6594_rtc_read_alarm()
168 alm->enabled = int_val & TPS6594_BIT_IT_ALARM; in tps6594_rtc_read_alarm()
176 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_set_alarm()
184 alarm_data[0] = bin2bcd(alm->time.tm_sec); in tps6594_rtc_set_alarm()
185 alarm_data[1] = bin2bcd(alm->time.tm_min); in tps6594_rtc_set_alarm()
186 alarm_data[2] = bin2bcd(alm->time.tm_hour); in tps6594_rtc_set_alarm()
187 alarm_data[3] = bin2bcd(alm->time.tm_mday); in tps6594_rtc_set_alarm()
188 alarm_data[4] = bin2bcd(alm->time.tm_mon + 1); in tps6594_rtc_set_alarm()
189 alarm_data[5] = bin2bcd(alm->time.tm_year - 100); in tps6594_rtc_set_alarm()
191 // Update all the alarm registers in one shot. in tps6594_rtc_set_alarm()
192 ret = regmap_bulk_write(tps->regmap, TPS6594_REG_ALARM_SECONDS, in tps6594_rtc_set_alarm()
197 if (alm->enabled) in tps6594_rtc_set_alarm()
205 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_set_calibration()
211 * crystal inaccuracies. One time every hour when seconds counter in tps6594_rtc_set_calibration()
215 * Valid range for compensation value: [-32767 .. 32767]. in tps6594_rtc_set_calibration()
218 return -ERANGE; in tps6594_rtc_set_calibration()
222 // Update all the compensation registers in one shot. in tps6594_rtc_set_calibration()
223 ret = regmap_bulk_write(tps->regmap, TPS6594_REG_RTC_COMP_LSB, &value, in tps6594_rtc_set_calibration()
229 return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_set_calibration()
235 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_get_calibration()
240 ret = regmap_read(tps->regmap, TPS6594_REG_RTC_CTRL_1, &ctrl); in tps6594_rtc_get_calibration()
250 ret = regmap_bulk_read(tps->regmap, TPS6594_REG_RTC_COMP_LSB, &value, in tps6594_rtc_get_calibration()
274 tmp -= TICKS_PER_HOUR / 2LL; in tps6594_rtc_read_offset()
281 * Computatiion is the reverse operation of the one done in in tps6594_rtc_read_offset()
287 * See 8.3.10.5, (32768 - COMP_REG). in tps6594_rtc_read_offset()
289 *offset = (long)-tmp; in tps6594_rtc_read_offset()
301 return -ERANGE; in tps6594_rtc_set_offset()
307 tmp -= PPB_MULT / 2LL; in tps6594_rtc_set_offset()
314 * - tmp = offset * TICK_PER_HOUR : in tps6594_rtc_set_offset()
316 * which is lower than the maximum value in an `s64` (2^63-1). No overflow here. in tps6594_rtc_set_offset()
318 * - tmp += TICK_PER_HOUR / 2LL : in tps6594_rtc_set_offset()
319 * tmp will have a maximum value of 277774117964800 which is still inferior to 2^63-1. in tps6594_rtc_set_offset()
323 calibration = (int)-tmp; in tps6594_rtc_set_offset()
331 struct tps6594 *tps = dev_get_drvdata(dev->parent); in tps6594_rtc_interrupt()
336 ret = regmap_read(tps->regmap, TPS6594_REG_RTC_STATUS, &rtc_reg); in tps6594_rtc_interrupt()
357 struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); in tps6594_rtc_probe()
358 struct device *dev = &pdev->dev; in tps6594_rtc_probe()
365 return -ENOMEM; in tps6594_rtc_probe()
372 ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_2, in tps6594_rtc_probe()
377 ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_probe()
383 ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_probe()
398 ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS, in tps6594_rtc_probe()
403 return -ENODEV; in tps6594_rtc_probe()
406 ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1, in tps6594_rtc_probe()
430 rtc->ops = &tps6594_rtc_ops; in tps6594_rtc_probe()
431 rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in tps6594_rtc_probe()
432 rtc->range_max = RTC_TIMESTAMP_END_2099; in tps6594_rtc_probe()
438 { "tps6594-rtc", },
446 .name = "tps6594-rtc",