• Home
  • Raw
  • Download

Lines Matching +full:wake +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 #include <linux/mfd/rohm-bd70528.h>
9 #include <linux/mfd/rohm-bd71828.h>
55 struct device *dev;
66 ret = regmap_read(bd70528->regmap, BD70528_REG_WAKE_EN, &ctrl_reg); in bd70528_set_wake()
85 return regmap_write(bd70528->regmap, BD70528_REG_WAKE_EN, in bd70528_set_wake()
98 * Is the timeout registers counting down, or is the disable - re-enable in bd70528_set_elapsed_tmr()
99 * going to restart the elapsed-time counting? If counting is restarted in bd70528_set_elapsed_tmr()
107 ret = regmap_read(bd70528->regmap, BD70528_REG_ELAPSED_TIMER_EN, in bd70528_set_elapsed_tmr()
127 return regmap_write(bd70528->regmap, BD70528_REG_ELAPSED_TIMER_EN, in bd70528_set_elapsed_tmr()
136 ret = bd70528_wdt_set(r->parent, new_state & BD70528_WDT_STATE_BIT, in bd70528_set_rtc_based_timers()
139 dev_err(r->dev, in bd70528_set_rtc_based_timers()
143 ret = bd70528_set_elapsed_tmr(r->parent, in bd70528_set_rtc_based_timers()
147 dev_err(r->dev, in bd70528_set_rtc_based_timers()
151 ret = bd70528_set_wake(r->parent, new_state & BD70528_WAKE_STATE_BIT, in bd70528_set_rtc_based_timers()
154 dev_err(r->dev, in bd70528_set_rtc_based_timers()
155 "Failed to disable 'wake timer' for RTC setting\n"); in bd70528_set_rtc_based_timers()
165 if (!r->has_rtc_timers) in bd70528_re_enable_rtc_based_timers()
174 if (!r->has_rtc_timers) in bd70528_disable_rtc_based_timers()
182 d->sec &= ~BD70528_MASK_RTC_SEC; in tmday2rtc()
183 d->min &= ~BD70528_MASK_RTC_MINUTE; in tmday2rtc()
184 d->hour &= ~BD70528_MASK_RTC_HOUR; in tmday2rtc()
185 d->sec |= bin2bcd(t->tm_sec); in tmday2rtc()
186 d->min |= bin2bcd(t->tm_min); in tmday2rtc()
187 d->hour |= bin2bcd(t->tm_hour); in tmday2rtc()
192 r->day &= ~BD70528_MASK_RTC_DAY; in tm2rtc()
193 r->week &= ~BD70528_MASK_RTC_WEEK; in tm2rtc()
194 r->month &= ~BD70528_MASK_RTC_MONTH; in tm2rtc()
196 * PM and 24H bits are not used by Wake - thus we clear them in tm2rtc()
197 * here and not in tmday2rtc() which is also used by wake. in tm2rtc()
199 r->time.hour &= ~(BD70528_MASK_RTC_HOUR_PM | BD70528_MASK_RTC_HOUR_24H); in tm2rtc()
201 tmday2rtc(t, &r->time); in tm2rtc()
205 r->time.hour |= BD70528_MASK_RTC_HOUR_24H; in tm2rtc()
206 r->day |= bin2bcd(t->tm_mday); in tm2rtc()
207 r->week |= bin2bcd(t->tm_wday); in tm2rtc()
208 r->month |= bin2bcd(t->tm_mon + 1); in tm2rtc()
209 r->year = bin2bcd(t->tm_year - 100); in tm2rtc()
214 t->tm_sec = bcd2bin(r->time.sec & BD70528_MASK_RTC_SEC); in rtc2tm()
215 t->tm_min = bcd2bin(r->time.min & BD70528_MASK_RTC_MINUTE); in rtc2tm()
216 t->tm_hour = bcd2bin(r->time.hour & BD70528_MASK_RTC_HOUR); in rtc2tm()
221 if (!(r->time.hour & BD70528_MASK_RTC_HOUR_24H)) { in rtc2tm()
222 t->tm_hour %= 12; in rtc2tm()
223 if (r->time.hour & BD70528_MASK_RTC_HOUR_PM) in rtc2tm()
224 t->tm_hour += 12; in rtc2tm()
226 t->tm_mday = bcd2bin(r->day & BD70528_MASK_RTC_DAY); in rtc2tm()
227 t->tm_mon = bcd2bin(r->month & BD70528_MASK_RTC_MONTH) - 1; in rtc2tm()
228 t->tm_year = 100 + bcd2bin(r->year & BD70528_MASK_RTC_YEAR); in rtc2tm()
229 t->tm_wday = bcd2bin(r->week & BD70528_MASK_RTC_WEEK); in rtc2tm()
232 static int bd71828_set_alarm(struct device *dev, struct rtc_wkalrm *a) in bd71828_set_alarm()
237 struct rohm_regmap_dev *parent = r->parent; in bd71828_set_alarm()
239 ret = regmap_bulk_read(parent->regmap, BD71828_REG_RTC_ALM_START, in bd71828_set_alarm()
246 tm2rtc(&a->time, &alm.alm0); in bd71828_set_alarm()
248 if (!a->enabled) in bd71828_set_alarm()
253 ret = regmap_bulk_write(parent->regmap, BD71828_REG_RTC_ALM_START, in bd71828_set_alarm()
262 static int bd70528_set_alarm(struct device *dev, struct rtc_wkalrm *a) in bd70528_set_alarm()
264 struct bd70528_rtc_wake wake; in bd70528_set_alarm() local
268 struct rohm_regmap_dev *parent = r->parent; in bd70528_set_alarm()
270 ret = regmap_bulk_read(parent->regmap, BD70528_REG_RTC_WAKE_START, in bd70528_set_alarm()
271 &wake, sizeof(wake)); in bd70528_set_alarm()
273 dev_err(dev, "Failed to read wake regs\n"); in bd70528_set_alarm()
277 ret = regmap_bulk_read(parent->regmap, BD70528_REG_RTC_ALM_START, in bd70528_set_alarm()
284 tm2rtc(&a->time, &alm.data); in bd70528_set_alarm()
285 tmday2rtc(&a->time, &wake.time); in bd70528_set_alarm()
287 if (a->enabled) { in bd70528_set_alarm()
289 wake.ctrl |= BD70528_MASK_WAKE_EN; in bd70528_set_alarm()
292 wake.ctrl &= ~BD70528_MASK_WAKE_EN; in bd70528_set_alarm()
295 ret = regmap_bulk_write(parent->regmap, in bd70528_set_alarm()
296 BD70528_REG_RTC_WAKE_START, &wake, in bd70528_set_alarm()
297 sizeof(wake)); in bd70528_set_alarm()
299 dev_err(dev, "Failed to set wake time\n"); in bd70528_set_alarm()
302 ret = regmap_bulk_write(parent->regmap, BD70528_REG_RTC_ALM_START, in bd70528_set_alarm()
310 static int bd71828_read_alarm(struct device *dev, struct rtc_wkalrm *a) in bd71828_read_alarm()
315 struct rohm_regmap_dev *parent = r->parent; in bd71828_read_alarm()
317 ret = regmap_bulk_read(parent->regmap, BD71828_REG_RTC_ALM_START, in bd71828_read_alarm()
324 rtc2tm(&alm.alm0, &a->time); in bd71828_read_alarm()
325 a->time.tm_mday = -1; in bd71828_read_alarm()
326 a->time.tm_mon = -1; in bd71828_read_alarm()
327 a->time.tm_year = -1; in bd71828_read_alarm()
328 a->enabled = !!(alm.alm_mask & BD70528_MASK_ALM_EN); in bd71828_read_alarm()
329 a->pending = 0; in bd71828_read_alarm()
334 static int bd70528_read_alarm(struct device *dev, struct rtc_wkalrm *a) in bd70528_read_alarm()
339 struct rohm_regmap_dev *parent = r->parent; in bd70528_read_alarm()
341 ret = regmap_bulk_read(parent->regmap, BD70528_REG_RTC_ALM_START, in bd70528_read_alarm()
348 rtc2tm(&alm.data, &a->time); in bd70528_read_alarm()
349 a->time.tm_mday = -1; in bd70528_read_alarm()
350 a->time.tm_mon = -1; in bd70528_read_alarm()
351 a->time.tm_year = -1; in bd70528_read_alarm()
352 a->enabled = !(alm.alm_mask & BD70528_MASK_ALM_EN); in bd70528_read_alarm()
353 a->pending = 0; in bd70528_read_alarm()
358 static int bd70528_set_time_locked(struct device *dev, struct rtc_time *t) in bd70528_set_time_locked()
363 struct rohm_regmap_dev *parent = r->parent; in bd70528_set_time_locked()
369 tmpret = regmap_bulk_read(parent->regmap, in bd70528_set_time_locked()
370 r->reg_time_start, &rtc_data, in bd70528_set_time_locked()
378 tmpret = regmap_bulk_write(parent->regmap, in bd70528_set_time_locked()
379 r->reg_time_start, &rtc_data, in bd70528_set_time_locked()
394 static int bd71828_set_time(struct device *dev, struct rtc_time *t) in bd71828_set_time()
399 static int bd70528_set_time(struct device *dev, struct rtc_time *t) in bd70528_set_time()
404 bd70528_wdt_lock(r->parent); in bd70528_set_time()
406 bd70528_wdt_unlock(r->parent); in bd70528_set_time()
410 static int bd70528_get_time(struct device *dev, struct rtc_time *t) in bd70528_get_time()
413 struct rohm_regmap_dev *parent = r->parent; in bd70528_get_time()
418 ret = regmap_bulk_read(parent->regmap, in bd70528_get_time()
419 r->reg_time_start, &rtc_data, in bd70528_get_time()
431 static int bd70528_alm_enable(struct device *dev, unsigned int enabled) in bd70528_alm_enable()
440 bd70528_wdt_lock(r->parent); in bd70528_alm_enable()
441 ret = bd70528_set_wake(r->parent, enabled, NULL); in bd70528_alm_enable()
443 dev_err(dev, "Failed to change wake state\n"); in bd70528_alm_enable()
446 ret = regmap_update_bits(r->parent->regmap, BD70528_REG_RTC_ALM_MASK, in bd70528_alm_enable()
452 bd70528_wdt_unlock(r->parent); in bd70528_alm_enable()
456 static int bd71828_alm_enable(struct device *dev, unsigned int enabled) in bd71828_alm_enable()
465 ret = regmap_update_bits(r->parent->regmap, BD71828_REG_RTC_ALM0_MASK, in bd71828_alm_enable()
509 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; in bd70528_probe()
511 parent = dev_get_drvdata(pdev->dev.parent); in bd70528_probe()
513 dev_err(&pdev->dev, "No MFD driver data\n"); in bd70528_probe()
514 return -EINVAL; in bd70528_probe()
516 bd_rtc = devm_kzalloc(&pdev->dev, sizeof(*bd_rtc), GFP_KERNEL); in bd70528_probe()
518 return -ENOMEM; in bd70528_probe()
520 bd_rtc->parent = parent; in bd70528_probe()
521 bd_rtc->dev = &pdev->dev; in bd70528_probe()
525 irq_name = "bd70528-rtc-alm"; in bd70528_probe()
526 bd_rtc->has_rtc_timers = true; in bd70528_probe()
527 bd_rtc->reg_time_start = BD70528_REG_RTC_START; in bd70528_probe()
533 irq_name = "bd71828-rtc-alm-0"; in bd70528_probe()
534 bd_rtc->reg_time_start = BD71828_REG_RTC_START; in bd70528_probe()
539 dev_err(&pdev->dev, "Unknown chip\n"); in bd70528_probe()
540 return -ENOENT; in bd70528_probe()
550 ret = regmap_read(parent->regmap, hour_reg, &hr); in bd70528_probe()
553 dev_err(&pdev->dev, "Failed to reag RTC clock\n"); in bd70528_probe()
560 ret = rtc_ops->read_time(&pdev->dev, &t); in bd70528_probe()
563 ret = rtc_ops->set_time(&pdev->dev, &t); in bd70528_probe()
566 dev_err(&pdev->dev, in bd70528_probe()
572 device_set_wakeup_capable(&pdev->dev, true); in bd70528_probe()
573 device_wakeup_enable(&pdev->dev); in bd70528_probe()
575 rtc = devm_rtc_allocate_device(&pdev->dev); in bd70528_probe()
577 dev_err(&pdev->dev, "RTC device creation failed\n"); in bd70528_probe()
581 rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in bd70528_probe()
582 rtc->range_max = RTC_TIMESTAMP_END_2099; in bd70528_probe()
583 rtc->ops = rtc_ops; in bd70528_probe()
586 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, &alm_hndlr, in bd70528_probe()
587 IRQF_ONESHOT, "bd70528-rtc", rtc); in bd70528_probe()
594 * leave them enabled as irq-controller should disable irqs in bd70528_probe()
595 * from sub-registers when IRQ is disabled or freed. in bd70528_probe()
598 ret = regmap_update_bits(parent->regmap, in bd70528_probe()
602 dev_err(&pdev->dev, "Failed to enable RTC interrupts\n"); in bd70528_probe()
611 { "bd70528-rtc", ROHM_CHIP_TYPE_BD70528 },
612 { "bd71828-rtc", ROHM_CHIP_TYPE_BD71828 },
619 .name = "bd70528-rtc"
630 MODULE_ALIAS("platform:bd70528-rtc");