Lines Matching +full:one +full:- +full:shot
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * rtc-tps65910.c -- TPS65910 Real Time Clock interface
8 * Based on original TI driver rtc-twl.c
32 #define NUM_TIME_REGS (TPS65910_YEARS - TPS65910_SECONDS + 1)
35 #define NUM_COMP_REGS (TPS65910_RTC_COMP_MSB - TPS65910_RTC_COMP_LSB + 1)
38 #define MIN_OFFSET (-277761)
50 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_alarm_irq_enable()
56 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, val); in tps65910_rtc_alarm_irq_enable()
65 * - Months are 1..12 vs Linux 0-11
66 * - Years are 0..99 vs Linux 1900..N (we assume 21st century)
71 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_read_time()
75 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL, in tps65910_rtc_read_time()
82 ret = regmap_bulk_read(tps->regmap, TPS65910_SECONDS, rtc_data, in tps65910_rtc_read_time()
89 tm->tm_sec = bcd2bin(rtc_data[0]); in tps65910_rtc_read_time()
90 tm->tm_min = bcd2bin(rtc_data[1]); in tps65910_rtc_read_time()
91 tm->tm_hour = bcd2bin(rtc_data[2]); in tps65910_rtc_read_time()
92 tm->tm_mday = bcd2bin(rtc_data[3]); in tps65910_rtc_read_time()
93 tm->tm_mon = bcd2bin(rtc_data[4]) - 1; in tps65910_rtc_read_time()
94 tm->tm_year = bcd2bin(rtc_data[5]) + 100; in tps65910_rtc_read_time()
102 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_set_time()
105 rtc_data[0] = bin2bcd(tm->tm_sec); in tps65910_rtc_set_time()
106 rtc_data[1] = bin2bcd(tm->tm_min); in tps65910_rtc_set_time()
107 rtc_data[2] = bin2bcd(tm->tm_hour); in tps65910_rtc_set_time()
108 rtc_data[3] = bin2bcd(tm->tm_mday); in tps65910_rtc_set_time()
109 rtc_data[4] = bin2bcd(tm->tm_mon + 1); in tps65910_rtc_set_time()
110 rtc_data[5] = bin2bcd(tm->tm_year - 100); in tps65910_rtc_set_time()
113 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL, in tps65910_rtc_set_time()
120 /* update all the time registers in one shot */ in tps65910_rtc_set_time()
121 ret = regmap_bulk_write(tps->regmap, TPS65910_SECONDS, rtc_data, in tps65910_rtc_set_time()
129 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL, in tps65910_rtc_set_time()
144 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_read_alarm()
147 ret = regmap_bulk_read(tps->regmap, TPS65910_ALARM_SECONDS, alarm_data, in tps65910_rtc_read_alarm()
154 alm->time.tm_sec = bcd2bin(alarm_data[0]); in tps65910_rtc_read_alarm()
155 alm->time.tm_min = bcd2bin(alarm_data[1]); in tps65910_rtc_read_alarm()
156 alm->time.tm_hour = bcd2bin(alarm_data[2]); in tps65910_rtc_read_alarm()
157 alm->time.tm_mday = bcd2bin(alarm_data[3]); in tps65910_rtc_read_alarm()
158 alm->time.tm_mon = bcd2bin(alarm_data[4]) - 1; in tps65910_rtc_read_alarm()
159 alm->time.tm_year = bcd2bin(alarm_data[5]) + 100; in tps65910_rtc_read_alarm()
161 ret = regmap_read(tps->regmap, TPS65910_RTC_INTERRUPTS, &int_val); in tps65910_rtc_read_alarm()
166 alm->enabled = 1; in tps65910_rtc_read_alarm()
174 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_set_alarm()
181 alarm_data[0] = bin2bcd(alm->time.tm_sec); in tps65910_rtc_set_alarm()
182 alarm_data[1] = bin2bcd(alm->time.tm_min); in tps65910_rtc_set_alarm()
183 alarm_data[2] = bin2bcd(alm->time.tm_hour); in tps65910_rtc_set_alarm()
184 alarm_data[3] = bin2bcd(alm->time.tm_mday); in tps65910_rtc_set_alarm()
185 alarm_data[4] = bin2bcd(alm->time.tm_mon + 1); in tps65910_rtc_set_alarm()
186 alarm_data[5] = bin2bcd(alm->time.tm_year - 100); in tps65910_rtc_set_alarm()
188 /* update all the alarm registers in one shot */ in tps65910_rtc_set_alarm()
189 ret = regmap_bulk_write(tps->regmap, TPS65910_ALARM_SECONDS, in tps65910_rtc_set_alarm()
196 if (alm->enabled) in tps65910_rtc_set_alarm()
205 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_set_calibration()
211 * crystal inaccuracies. One time every hour when seconds counter in tps65910_rtc_set_calibration()
217 * Valid range for compensation value: [-32768 .. 32766] in tps65910_rtc_set_calibration()
219 if ((calibration < -32768) || (calibration > 32766)) { in tps65910_rtc_set_calibration()
222 return -EINVAL; in tps65910_rtc_set_calibration()
230 /* Update all the compensation registers in one shot */ in tps65910_rtc_set_calibration()
231 ret = regmap_bulk_write(tps->regmap, TPS65910_RTC_COMP_LSB, in tps65910_rtc_set_calibration()
239 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL, in tps65910_rtc_set_calibration()
250 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_get_calibration()
255 ret = regmap_read(tps->regmap, TPS65910_RTC_CTRL, &ctrl); in tps65910_rtc_get_calibration()
265 ret = regmap_bulk_read(tps->regmap, TPS65910_RTC_COMP_LSB, comp_data, in tps65910_rtc_get_calibration()
292 tmp -= TICKS_PER_HOUR / 2LL; in tps65910_read_offset()
298 *offset = (long)-tmp; in tps65910_read_offset()
311 return -ERANGE; in tps65910_set_offset()
316 tmp -= PPB_MULT / 2LL; in tps65910_set_offset()
322 calibration = (int)-tmp; in tps65910_set_offset()
333 struct tps65910 *tps = dev_get_drvdata(dev->parent); in tps65910_rtc_interrupt()
338 ret = regmap_read(tps->regmap, TPS65910_RTC_STATUS, &rtc_reg); in tps65910_rtc_interrupt()
345 ret = regmap_write(tps->regmap, TPS65910_RTC_STATUS, rtc_reg); in tps65910_rtc_interrupt()
350 rtc_update_irq(tps_rtc->rtc, 1, events); in tps65910_rtc_interrupt()
373 tps65910 = dev_get_drvdata(pdev->dev.parent); in tps65910_rtc_probe()
375 tps_rtc = devm_kzalloc(&pdev->dev, sizeof(struct tps65910_rtc), in tps65910_rtc_probe()
378 return -ENOMEM; in tps65910_rtc_probe()
380 tps_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); in tps65910_rtc_probe()
381 if (IS_ERR(tps_rtc->rtc)) in tps65910_rtc_probe()
382 return PTR_ERR(tps_rtc->rtc); in tps65910_rtc_probe()
385 ret = regmap_read(tps65910->regmap, TPS65910_RTC_STATUS, &rtc_reg); in tps65910_rtc_probe()
389 ret = regmap_write(tps65910->regmap, TPS65910_RTC_STATUS, rtc_reg); in tps65910_rtc_probe()
393 dev_dbg(&pdev->dev, "Enabling rtc-tps65910.\n"); in tps65910_rtc_probe()
396 ret = regmap_update_bits(tps65910->regmap, TPS65910_DEVCTRL, in tps65910_rtc_probe()
402 ret = regmap_write(tps65910->regmap, TPS65910_RTC_CTRL, rtc_reg); in tps65910_rtc_probe()
412 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in tps65910_rtc_probe()
414 dev_name(&pdev->dev), &pdev->dev); in tps65910_rtc_probe()
416 irq = -1; in tps65910_rtc_probe()
418 tps_rtc->irq = irq; in tps65910_rtc_probe()
419 if (irq != -1) { in tps65910_rtc_probe()
420 if (device_property_present(tps65910->dev, "wakeup-source")) in tps65910_rtc_probe()
421 device_init_wakeup(&pdev->dev, 1); in tps65910_rtc_probe()
423 device_set_wakeup_capable(&pdev->dev, 1); in tps65910_rtc_probe()
425 clear_bit(RTC_FEATURE_ALARM, tps_rtc->rtc->features); in tps65910_rtc_probe()
428 tps_rtc->rtc->ops = &tps65910_rtc_ops; in tps65910_rtc_probe()
429 tps_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in tps65910_rtc_probe()
430 tps_rtc->rtc->range_max = RTC_TIMESTAMP_END_2099; in tps65910_rtc_probe()
432 return devm_rtc_register_device(tps_rtc->rtc); in tps65910_rtc_probe()
441 enable_irq_wake(tps_rtc->irq); in tps65910_rtc_suspend()
450 disable_irq_wake(tps_rtc->irq); in tps65910_rtc_resume()
461 .name = "tps65910-rtc",
467 MODULE_ALIAS("platform:tps65910-rtc");