Lines Matching +full:trickle +full:- +full:resistor +full:- +full:ohms

1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/clk-provider.h>
105 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent); in timestamp0_store()
107 regmap_update_bits(rv3028->regmap, RV3028_EVT_CTRL, RV3028_EVT_CTRL_TSR, in timestamp0_store()
116 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent); in timestamp0_show()
121 ret = regmap_read(rv3028->regmap, RV3028_TS_COUNT, &count); in timestamp0_show()
128 ret = regmap_bulk_read(rv3028->regmap, RV3028_TS_SEC, date, in timestamp0_show()
137 tm.tm_mon = bcd2bin(date[4]) - 1; in timestamp0_show()
153 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent); in timestamp0_count_show()
156 ret = regmap_read(rv3028->regmap, RV3028_TS_COUNT, &count); in timestamp0_count_show()
180 return regmap_update_bits(rv3028->regmap, RV3028_CTRL1, RV3028_CTRL1_EERD, 0); in rv3028_exit_eerd()
188 ret = regmap_read(rv3028->regmap, RV3028_CTRL1, &ctrl1); in rv3028_enter_eerd()
196 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL1, in rv3028_enter_eerd()
201 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_enter_eerd()
218 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, 0x0); in rv3028_update_eeprom()
222 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, RV3028_EEPROM_CMD_UPDATE); in rv3028_update_eeprom()
228 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_update_eeprom()
248 ret = regmap_update_bits(rv3028->regmap, reg, mask, val); in rv3028_update_cfg()
263 if (regmap_read(rv3028->regmap, RV3028_STATUS, &status) < 0 || in rv3028_handle_irq()
269 dev_warn(&rv3028->rtc->dev, "Voltage low, data loss detected.\n"); in rv3028_handle_irq()
290 rtc_update_irq(rv3028->rtc, 1, events); in rv3028_handle_irq()
291 regmap_update_bits(rv3028->regmap, RV3028_STATUS, status, 0); in rv3028_handle_irq()
292 regmap_update_bits(rv3028->regmap, RV3028_CTRL2, ctrl, 0); in rv3028_handle_irq()
296 sysfs_notify(&rv3028->rtc->dev.kobj, NULL, in rv3028_handle_irq()
298 dev_warn(&rv3028->rtc->dev, "event detected"); in rv3028_handle_irq()
310 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_get_time()
316 return -EINVAL; in rv3028_get_time()
319 ret = regmap_bulk_read(rv3028->regmap, RV3028_SEC, date, sizeof(date)); in rv3028_get_time()
323 tm->tm_sec = bcd2bin(date[RV3028_SEC] & 0x7f); in rv3028_get_time()
324 tm->tm_min = bcd2bin(date[RV3028_MIN] & 0x7f); in rv3028_get_time()
325 tm->tm_hour = bcd2bin(date[RV3028_HOUR] & 0x3f); in rv3028_get_time()
326 tm->tm_wday = ilog2(date[RV3028_WDAY] & 0x7f); in rv3028_get_time()
327 tm->tm_mday = bcd2bin(date[RV3028_DAY] & 0x3f); in rv3028_get_time()
328 tm->tm_mon = bcd2bin(date[RV3028_MONTH] & 0x1f) - 1; in rv3028_get_time()
329 tm->tm_year = bcd2bin(date[RV3028_YEAR]) + 100; in rv3028_get_time()
340 date[RV3028_SEC] = bin2bcd(tm->tm_sec); in rv3028_set_time()
341 date[RV3028_MIN] = bin2bcd(tm->tm_min); in rv3028_set_time()
342 date[RV3028_HOUR] = bin2bcd(tm->tm_hour); in rv3028_set_time()
343 date[RV3028_WDAY] = 1 << (tm->tm_wday); in rv3028_set_time()
344 date[RV3028_DAY] = bin2bcd(tm->tm_mday); in rv3028_set_time()
345 date[RV3028_MONTH] = bin2bcd(tm->tm_mon + 1); in rv3028_set_time()
346 date[RV3028_YEAR] = bin2bcd(tm->tm_year - 100); in rv3028_set_time()
352 ret = regmap_bulk_write(rv3028->regmap, RV3028_SEC, date, in rv3028_set_time()
357 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_set_time()
369 ret = regmap_bulk_read(rv3028->regmap, RV3028_ALARM_MIN, alarmvals, in rv3028_get_alarm()
374 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_get_alarm()
378 ret = regmap_read(rv3028->regmap, RV3028_CTRL2, &ctrl); in rv3028_get_alarm()
382 alrm->time.tm_sec = 0; in rv3028_get_alarm()
383 alrm->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); in rv3028_get_alarm()
384 alrm->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f); in rv3028_get_alarm()
385 alrm->time.tm_mday = bcd2bin(alarmvals[2] & 0x3f); in rv3028_get_alarm()
387 alrm->enabled = !!(ctrl & RV3028_CTRL2_AIE); in rv3028_get_alarm()
388 alrm->pending = (status & RV3028_STATUS_AF) && alrm->enabled; in rv3028_get_alarm()
401 if (alrm->time.tm_sec) { in rv3028_set_alarm()
402 time64_t alarm_time = rtc_tm_to_time64(&alrm->time); in rv3028_set_alarm()
404 alarm_time += 60 - alrm->time.tm_sec; in rv3028_set_alarm()
405 rtc_time64_to_tm(alarm_time, &alrm->time); in rv3028_set_alarm()
408 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_set_alarm()
413 alarmvals[0] = bin2bcd(alrm->time.tm_min); in rv3028_set_alarm()
414 alarmvals[1] = bin2bcd(alrm->time.tm_hour); in rv3028_set_alarm()
415 alarmvals[2] = bin2bcd(alrm->time.tm_mday); in rv3028_set_alarm()
417 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_set_alarm()
422 ret = regmap_bulk_write(rv3028->regmap, RV3028_ALARM_MIN, alarmvals, in rv3028_set_alarm()
427 if (alrm->enabled) { in rv3028_set_alarm()
428 if (rv3028->rtc->uie_rtctimer.enabled) in rv3028_set_alarm()
430 if (rv3028->rtc->aie_timer.enabled) in rv3028_set_alarm()
434 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_set_alarm()
446 if (rv3028->rtc->uie_rtctimer.enabled) in rv3028_alarm_irq_enable()
448 if (rv3028->rtc->aie_timer.enabled) in rv3028_alarm_irq_enable()
452 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_alarm_irq_enable()
457 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_alarm_irq_enable()
470 ret = regmap_read(rv3028->regmap, RV3028_OFFSET, &value); in rv3028_read_offset()
476 ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &value); in rv3028_read_offset()
493 offset = clamp(offset, -244141L, 243187L) * 1000; in rv3028_set_offset()
500 ret = regmap_write(rv3028->regmap, RV3028_OFFSET, offset >> 1); in rv3028_set_offset()
504 ret = regmap_update_bits(rv3028->regmap, RV3028_BACKUP, BIT(7), in rv3028_set_offset()
525 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_ioctl()
533 return -ENOIOCTLCMD; in rv3028_ioctl()
562 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_ADDR, offset + i); in rv3028_eeprom_write()
566 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_DATA, buf[i]); in rv3028_eeprom_write()
570 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, 0x0); in rv3028_eeprom_write()
574 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, in rv3028_eeprom_write()
581 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_eeprom_write()
608 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_ADDR, offset + i); in rv3028_eeprom_read()
612 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, 0x0); in rv3028_eeprom_read()
616 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, in rv3028_eeprom_read()
621 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_eeprom_read()
628 ret = regmap_read(rv3028->regmap, RV3028_EEPROM_DATA, &data); in rv3028_eeprom_read()
658 ret = regmap_read(rv3028->regmap, RV3028_CLKOUT, &clkout); in rv3028_clkout_recalc_rate()
685 ret = regmap_read(rv3028->regmap, RV3028_CLKOUT, &enabled); in rv3028_clkout_set_rate()
689 ret = regmap_write(rv3028->regmap, RV3028_CLKOUT, 0x0); in rv3028_clkout_set_rate()
700 return -EINVAL; in rv3028_clkout_set_rate()
707 return regmap_write(rv3028->regmap, RV3028_CLKOUT, in rv3028_clkout_prepare()
715 regmap_write(rv3028->regmap, RV3028_CLKOUT, 0x0); in rv3028_clkout_unprepare()
716 regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_clkout_unprepare()
725 ret = regmap_read(rv3028->regmap, RV3028_CLKOUT, &clkout); in rv3028_clkout_is_prepared()
747 struct device_node *node = client->dev.of_node; in rv3028_clkout_register_clk()
749 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_clkout_register_clk()
754 init.name = "rv3028-clkout"; in rv3028_clkout_register_clk()
759 rv3028->clkout_hw.init = &init; in rv3028_clkout_register_clk()
762 of_property_read_string(node, "clock-output-names", &init.name); in rv3028_clkout_register_clk()
765 clk = devm_clk_register(&client->dev, &rv3028->clkout_hw); in rv3028_clkout_register_clk()
791 u32 ohms; in rv3028_probe() local
811 rv3028 = devm_kzalloc(&client->dev, sizeof(struct rv3028_data), in rv3028_probe()
814 return -ENOMEM; in rv3028_probe()
816 rv3028->regmap = devm_regmap_init_i2c(client, &regmap_config); in rv3028_probe()
817 if (IS_ERR(rv3028->regmap)) in rv3028_probe()
818 return PTR_ERR(rv3028->regmap); in rv3028_probe()
822 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_probe()
827 dev_warn(&client->dev, "Voltage low, data loss detected.\n"); in rv3028_probe()
830 dev_warn(&client->dev, "An alarm may have been missed.\n"); in rv3028_probe()
832 rv3028->rtc = devm_rtc_allocate_device(&client->dev); in rv3028_probe()
833 if (IS_ERR(rv3028->rtc)) in rv3028_probe()
834 return PTR_ERR(rv3028->rtc); in rv3028_probe()
836 if (client->irq > 0) { in rv3028_probe()
837 ret = devm_request_threaded_irq(&client->dev, client->irq, in rv3028_probe()
842 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); in rv3028_probe()
843 client->irq = 0; in rv3028_probe()
851 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL1, in rv3028_probe()
857 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_probe()
863 /* setup trickle charger */ in rv3028_probe()
864 if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms", in rv3028_probe()
865 &ohms)) { in rv3028_probe()
869 if (ohms == rv3028_trickle_resistors[i]) in rv3028_probe()
878 dev_warn(&client->dev, "invalid trickle resistor value\n"); in rv3028_probe()
882 ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group); in rv3028_probe()
886 rv3028->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in rv3028_probe()
887 rv3028->rtc->range_max = RTC_TIMESTAMP_END_2099; in rv3028_probe()
888 rv3028->rtc->ops = &rv3028_rtc_ops; in rv3028_probe()
889 ret = rtc_register_device(rv3028->rtc); in rv3028_probe()
893 nvmem_cfg.priv = rv3028->regmap; in rv3028_probe()
894 rtc_nvmem_register(rv3028->rtc, &nvmem_cfg); in rv3028_probe()
896 rtc_nvmem_register(rv3028->rtc, &eeprom_cfg); in rv3028_probe()
898 rv3028->rtc->max_user_freq = 1; in rv3028_probe()
914 .name = "rtc-rv3028",