Lines Matching +full:smbus +full:- +full:timeout +full:- +full:disable

1 // SPDX-License-Identifier: GPL-2.0-only
3 * RTC client/driver for the Maxim/Dallas DS1374 Real-Time Clock over I2C
9 * Copyright (C) 2006-2007 Freescale Semiconductor
14 * recommended in .../Documentation/i2c/writing-clients.rst section
15 * "Sending and receiving", using SMBus level communication is preferred.
93 return -EINVAL; in ds1374_read_rtc()
100 return -EIO; in ds1374_read_rtc()
102 for (i = nbytes - 1, *time = 0; i >= 0; i--) in ds1374_read_rtc()
116 return -EINVAL; in ds1374_write_rtc()
137 dev_warn(&client->dev, in ds1374_check_rtc_status()
193 if (client->irq <= 0) in ds1374_read_alarm()
194 return -EINVAL; in ds1374_read_alarm()
196 mutex_lock(&ds1374->mutex); in ds1374_read_alarm()
214 rtc_time64_to_tm(now + cur_alarm, &alarm->time); in ds1374_read_alarm()
215 alarm->enabled = !!(cr & DS1374_REG_CR_WACE); in ds1374_read_alarm()
216 alarm->pending = !!(sr & DS1374_REG_SR_AF); in ds1374_read_alarm()
219 mutex_unlock(&ds1374->mutex); in ds1374_read_alarm()
232 if (client->irq <= 0) in ds1374_set_alarm()
233 return -EINVAL; in ds1374_set_alarm()
239 new_alarm = rtc_tm_to_time64(&alarm->time); in ds1374_set_alarm()
251 new_alarm -= itime; in ds1374_set_alarm()
253 mutex_lock(&ds1374->mutex); in ds1374_set_alarm()
259 /* Disable any existing alarm before setting the new one in ds1374_set_alarm()
271 if (alarm->enabled) { in ds1374_set_alarm()
279 mutex_unlock(&ds1374->mutex); in ds1374_set_alarm()
290 schedule_work(&ds1374->work); in ds1374_irq()
297 struct i2c_client *client = ds1374->client; in ds1374_work()
300 mutex_lock(&ds1374->mutex); in ds1374_work()
317 rtc_update_irq(ds1374->rtc, 1, RTC_AF | RTC_IRQF); in ds1374_work()
321 if (!ds1374->exiting) in ds1374_work()
322 enable_irq(client->irq); in ds1374_work()
324 mutex_unlock(&ds1374->mutex); in ds1374_work()
334 mutex_lock(&ds1374->mutex); in ds1374_alarm_irq_enable()
349 mutex_unlock(&ds1374->mutex); in ds1374_alarm_irq_enable()
375 #define TIMER_MARGIN_MAX 4095 /* 24-bit value */
379 MODULE_PARM_DESC(wdt_margin, "Watchdog timeout in seconds (default 32s)");
392 static int ds1374_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout) in ds1374_wdt_settimeout() argument
395 struct i2c_client *client = ds1374->client; in ds1374_wdt_settimeout()
398 wdt->timeout = timeout; in ds1374_wdt_settimeout()
404 /* Disable any existing watchdog/alarm before setting the new one */ in ds1374_wdt_settimeout()
412 timeout = timeout * 4096; in ds1374_wdt_settimeout()
413 ret = ds1374_write_rtc(client, timeout, DS1374_REG_WDALM0, 3); in ds1374_wdt_settimeout()
437 return ds1374_read_rtc(ds1374->client, &val, DS1374_REG_WDALM0, 3); in ds1374_wdt_start()
443 struct i2c_client *client = ds1374->client; in ds1374_wdt_stop()
450 /* Disable watchdog timer */ in ds1374_wdt_stop()
475 ds1374 = devm_kzalloc(&client->dev, sizeof(struct ds1374), GFP_KERNEL); in ds1374_probe()
477 return -ENOMEM; in ds1374_probe()
479 ds1374->rtc = devm_rtc_allocate_device(&client->dev); in ds1374_probe()
480 if (IS_ERR(ds1374->rtc)) in ds1374_probe()
481 return PTR_ERR(ds1374->rtc); in ds1374_probe()
483 ds1374->client = client; in ds1374_probe()
486 INIT_WORK(&ds1374->work, ds1374_work); in ds1374_probe()
487 mutex_init(&ds1374->mutex); in ds1374_probe()
493 if (client->irq > 0) { in ds1374_probe()
494 ret = devm_request_irq(&client->dev, client->irq, ds1374_irq, 0, in ds1374_probe()
497 dev_err(&client->dev, "unable to request IRQ\n"); in ds1374_probe()
501 device_set_wakeup_capable(&client->dev, 1); in ds1374_probe()
504 ds1374->rtc->ops = &ds1374_rtc_ops; in ds1374_probe()
505 ds1374->rtc->range_max = U32_MAX; in ds1374_probe()
507 ret = devm_rtc_register_device(ds1374->rtc); in ds1374_probe()
512 ds1374->wdt.info = &ds1374_wdt_info; in ds1374_probe()
513 ds1374->wdt.ops = &ds1374_wdt_ops; in ds1374_probe()
514 ds1374->wdt.timeout = TIMER_MARGIN_DEFAULT; in ds1374_probe()
515 ds1374->wdt.min_timeout = TIMER_MARGIN_MIN; in ds1374_probe()
516 ds1374->wdt.max_timeout = TIMER_MARGIN_MAX; in ds1374_probe()
518 watchdog_init_timeout(&ds1374->wdt, wdt_margin, &client->dev); in ds1374_probe()
519 watchdog_set_nowayout(&ds1374->wdt, nowayout); in ds1374_probe()
520 watchdog_stop_on_reboot(&ds1374->wdt); in ds1374_probe()
521 watchdog_stop_on_unregister(&ds1374->wdt); in ds1374_probe()
522 watchdog_set_drvdata(&ds1374->wdt, ds1374); in ds1374_probe()
523 ds1374_wdt_settimeout(&ds1374->wdt, ds1374->wdt.timeout); in ds1374_probe()
525 ret = devm_watchdog_register_device(&client->dev, &ds1374->wdt); in ds1374_probe()
537 if (client->irq > 0) { in ds1374_remove()
538 mutex_lock(&ds1374->mutex); in ds1374_remove()
539 ds1374->exiting = 1; in ds1374_remove()
540 mutex_unlock(&ds1374->mutex); in ds1374_remove()
542 devm_free_irq(&client->dev, client->irq, client); in ds1374_remove()
543 cancel_work_sync(&ds1374->work); in ds1374_remove()
552 if (client->irq > 0 && device_may_wakeup(&client->dev)) in ds1374_suspend()
553 enable_irq_wake(client->irq); in ds1374_suspend()
561 if (client->irq > 0 && device_may_wakeup(&client->dev)) in ds1374_resume()
562 disable_irq_wake(client->irq); in ds1374_resume()
571 .name = "rtc-ds1374",