Lines Matching +full:calibration +full:- +full:data
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2010
69 /* Request a data read */ in ab8500_rtc_read_time()
135 /* Request a data write */ in ab8500_rtc_set_time()
154 alarm->enabled = 1; in ab8500_rtc_read_alarm()
156 alarm->enabled = 0; in ab8500_rtc_read_alarm()
158 alarm->pending = 0; in ab8500_rtc_read_alarm()
171 rtc_time64_to_tm(secs, &alarm->time); in ab8500_rtc_read_alarm()
189 mins = (unsigned long)rtc_tm_to_time64(&alarm->time) / 60; in ab8500_rtc_set_alarm()
203 return ab8500_rtc_irq_enable(dev, alarm->enabled); in ab8500_rtc_set_alarm()
206 static int ab8500_rtc_set_calibration(struct device *dev, int calibration) in ab8500_rtc_set_calibration() argument
212 * Check that the calibration value (which is in units of 0.5 in ab8500_rtc_set_calibration()
213 * parts-per-million) is in the AB8500's range for RtcCalibration in ab8500_rtc_set_calibration()
214 * register. -128 (0x80) is not permitted because the AB8500 uses in ab8500_rtc_set_calibration()
215 * a sign-bit rather than two's complement, so 0x80 is just another in ab8500_rtc_set_calibration()
218 if ((calibration < -127) || (calibration > 127)) { in ab8500_rtc_set_calibration()
220 return -EINVAL; in ab8500_rtc_set_calibration()
224 * The AB8500 uses sign (in bit7) and magnitude (in bits0-7) in ab8500_rtc_set_calibration()
228 if (calibration >= 0) in ab8500_rtc_set_calibration()
229 rtccal = 0x7F & calibration; in ab8500_rtc_set_calibration()
231 rtccal = ~(calibration - 1) | 0x80; in ab8500_rtc_set_calibration()
239 static int ab8500_rtc_get_calibration(struct device *dev, int *calibration) in ab8500_rtc_get_calibration() argument
248 * The AB8500 uses sign (in bit7) and magnitude (in bits0-7) in ab8500_rtc_get_calibration()
253 *calibration = 0 - (rtccal & 0x7F); in ab8500_rtc_get_calibration()
255 *calibration = 0x7F & rtccal; in ab8500_rtc_get_calibration()
266 int calibration = 0; in ab8500_sysfs_store_rtc_calibration() local
268 if (sscanf(buf, " %i ", &calibration) != 1) { in ab8500_sysfs_store_rtc_calibration()
269 dev_err(dev, "Failed to store RTC calibration attribute\n"); in ab8500_sysfs_store_rtc_calibration()
270 return -EINVAL; in ab8500_sysfs_store_rtc_calibration()
273 retval = ab8500_rtc_set_calibration(dev, calibration); in ab8500_sysfs_store_rtc_calibration()
282 int calibration = 0; in ab8500_sysfs_show_rtc_calibration() local
284 retval = ab8500_rtc_get_calibration(dev, &calibration); in ab8500_sysfs_show_rtc_calibration()
286 dev_err(dev, "Failed to read RTC calibration attribute\n"); in ab8500_sysfs_show_rtc_calibration()
291 return sprintf(buf, "%d\n", calibration); in ab8500_sysfs_show_rtc_calibration()
307 static irqreturn_t rtc_alarm_handler(int irq, void *data) in rtc_alarm_handler() argument
309 struct rtc_device *rtc = data; in rtc_alarm_handler()
312 dev_dbg(&rtc->dev, "%s\n", __func__); in rtc_alarm_handler()
327 { "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, },
345 err = abx500_mask_and_set_register_interruptible(&pdev->dev, AB8500_RTC, in ab8500_rtc_probe()
353 err = abx500_get_register_interruptible(&pdev->dev, AB8500_RTC, in ab8500_rtc_probe()
360 dev_err(&pdev->dev, "RTC supply failure\n"); in ab8500_rtc_probe()
361 return -ENODEV; in ab8500_rtc_probe()
364 device_init_wakeup(&pdev->dev, true); in ab8500_rtc_probe()
366 rtc = devm_rtc_allocate_device(&pdev->dev); in ab8500_rtc_probe()
370 rtc->ops = (struct rtc_class_ops *)platid->driver_data; in ab8500_rtc_probe()
372 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, in ab8500_rtc_probe()
374 "ab8500-rtc", rtc); in ab8500_rtc_probe()
378 dev_pm_set_wake_irq(&pdev->dev, irq); in ab8500_rtc_probe()
381 set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->features); in ab8500_rtc_probe()
382 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features); in ab8500_rtc_probe()
384 rtc->range_max = (1ULL << 24) * 60 - 1; // 24-bit minutes + 59 secs in ab8500_rtc_probe()
385 rtc->start_secs = RTC_TIMESTAMP_BEGIN_2000; in ab8500_rtc_probe()
386 rtc->set_start_time = true; in ab8500_rtc_probe()
397 dev_pm_clear_wake_irq(&pdev->dev); in ab8500_rtc_remove()
398 device_init_wakeup(&pdev->dev, false); in ab8500_rtc_remove()
403 .name = "ab8500-rtc",