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

1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/clk-provider.h>
123 return regmap_update_bits(rv3032->regmap, RV3032_CTRL1, RV3032_CTRL1_EERD, 0); in rv3032_exit_eerd()
131 ret = regmap_read(rv3032->regmap, RV3032_CTRL1, &ctrl1); in rv3032_enter_eerd()
139 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL1, in rv3032_enter_eerd()
144 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_enter_eerd()
166 ret = regmap_update_bits(rv3032->regmap, reg, mask, val); in rv3032_update_cfg()
170 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, RV3032_EEPROM_CMD_UPDATE); in rv3032_update_cfg()
176 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_update_cfg()
192 if (regmap_read(rv3032->regmap, RV3032_STATUS, &status) < 0 || in rv3032_handle_irq()
216 rtc_update_irq(rv3032->rtc, 1, events); in rv3032_handle_irq()
217 regmap_update_bits(rv3032->regmap, RV3032_STATUS, status, 0); in rv3032_handle_irq()
218 regmap_update_bits(rv3032->regmap, RV3032_CTRL2, ctrl, 0); in rv3032_handle_irq()
230 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_get_time()
235 return -EINVAL; in rv3032_get_time()
237 ret = regmap_bulk_read(rv3032->regmap, RV3032_SEC, date, sizeof(date)); in rv3032_get_time()
241 tm->tm_sec = bcd2bin(date[0] & 0x7f); in rv3032_get_time()
242 tm->tm_min = bcd2bin(date[1] & 0x7f); in rv3032_get_time()
243 tm->tm_hour = bcd2bin(date[2] & 0x3f); in rv3032_get_time()
244 tm->tm_wday = date[3] & 0x7; in rv3032_get_time()
245 tm->tm_mday = bcd2bin(date[4] & 0x3f); in rv3032_get_time()
246 tm->tm_mon = bcd2bin(date[5] & 0x1f) - 1; in rv3032_get_time()
247 tm->tm_year = bcd2bin(date[6]) + 100; in rv3032_get_time()
258 date[0] = bin2bcd(tm->tm_sec); in rv3032_set_time()
259 date[1] = bin2bcd(tm->tm_min); in rv3032_set_time()
260 date[2] = bin2bcd(tm->tm_hour); in rv3032_set_time()
261 date[3] = tm->tm_wday; in rv3032_set_time()
262 date[4] = bin2bcd(tm->tm_mday); in rv3032_set_time()
263 date[5] = bin2bcd(tm->tm_mon + 1); in rv3032_set_time()
264 date[6] = bin2bcd(tm->tm_year - 100); in rv3032_set_time()
266 ret = regmap_bulk_write(rv3032->regmap, RV3032_SEC, date, in rv3032_set_time()
271 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_set_time()
283 ret = regmap_bulk_read(rv3032->regmap, RV3032_ALARM_MIN, alarmvals, in rv3032_get_alarm()
288 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_get_alarm()
292 ret = regmap_read(rv3032->regmap, RV3032_CTRL2, &ctrl); in rv3032_get_alarm()
296 alrm->time.tm_sec = 0; in rv3032_get_alarm()
297 alrm->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); in rv3032_get_alarm()
298 alrm->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f); in rv3032_get_alarm()
299 alrm->time.tm_mday = bcd2bin(alarmvals[2] & 0x3f); in rv3032_get_alarm()
301 alrm->enabled = !!(ctrl & RV3032_CTRL2_AIE); in rv3032_get_alarm()
302 alrm->pending = (status & RV3032_STATUS_AF) && alrm->enabled; in rv3032_get_alarm()
314 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_set_alarm()
319 alarmvals[0] = bin2bcd(alrm->time.tm_min); in rv3032_set_alarm()
320 alarmvals[1] = bin2bcd(alrm->time.tm_hour); in rv3032_set_alarm()
321 alarmvals[2] = bin2bcd(alrm->time.tm_mday); in rv3032_set_alarm()
323 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_set_alarm()
328 ret = regmap_bulk_write(rv3032->regmap, RV3032_ALARM_MIN, alarmvals, in rv3032_set_alarm()
333 if (alrm->enabled) { in rv3032_set_alarm()
334 if (rv3032->rtc->uie_rtctimer.enabled) in rv3032_set_alarm()
336 if (rv3032->rtc->aie_timer.enabled) in rv3032_set_alarm()
340 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_set_alarm()
352 if (rv3032->rtc->uie_rtctimer.enabled) in rv3032_alarm_irq_enable()
354 if (rv3032->rtc->aie_timer.enabled) in rv3032_alarm_irq_enable()
358 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_alarm_irq_enable()
363 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_alarm_irq_enable()
376 ret = regmap_read(rv3032->regmap, RV3032_OFFSET, &value); in rv3032_read_offset()
391 offset = clamp(offset, -7629L, 7391L) * 1000; in rv3032_set_offset()
403 switch(param->param) { in rv3032_param_get()
407 ret = regmap_read(rv3032->regmap, RV3032_PMU, &value); in rv3032_param_get()
415 param->uvalue = RTC_BSM_DIRECT; in rv3032_param_get()
418 param->uvalue = RTC_BSM_LEVEL; in rv3032_param_get()
421 param->uvalue = RTC_BSM_DISABLED; in rv3032_param_get()
427 return -EINVAL; in rv3032_param_get()
437 switch(param->param) { in rv3032_param_set()
440 if (rv3032->trickle_charger_set) in rv3032_param_set()
441 return -EINVAL; in rv3032_param_set()
443 switch (param->uvalue) { in rv3032_param_set()
454 return -EINVAL; in rv3032_param_set()
461 return -EINVAL; in rv3032_param_set()
474 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_ioctl()
483 return -ENOIOCTLCMD; in rv3032_ioctl()
509 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_ADDR, in rv3032_eeprom_write()
514 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_DATA, buf[i]); in rv3032_eeprom_write()
518 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, in rv3032_eeprom_write()
525 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_eeprom_write()
550 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_ADDR, in rv3032_eeprom_read()
555 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, in rv3032_eeprom_read()
560 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_eeprom_read()
566 ret = regmap_read(rv3032->regmap, RV3032_EEPROM_DATA, &data); in rv3032_eeprom_read()
580 u32 val, ohms, voltage; in rv3032_trickle_charger_setup() local
584 if (!device_property_read_u32(dev, "trickle-voltage-millivolt", &voltage)) { in rv3032_trickle_charger_setup()
593 if (device_property_read_u32(dev, "trickle-resistor-ohms", &ohms)) in rv3032_trickle_charger_setup()
597 if (ohms == rv3032_trickle_resistors[i]) in rv3032_trickle_charger_setup()
601 dev_warn(dev, "invalid trickle resistor value\n"); in rv3032_trickle_charger_setup()
606 rv3032->trickle_charger_set = true; in rv3032_trickle_charger_setup()
631 ret = regmap_read(rv3032->regmap, RV3032_CLKOUT2, &clkout); in rv3032_clkout_recalc_rate()
638 ret = regmap_read(rv3032->regmap, RV3032_CLKOUT1, &clkout); in rv3032_clkout_recalc_rate()
680 hfd = clamp(hfd, 1, 8192) - 1; in rv3032_clkout_set_rate()
686 ret = regmap_write(rv3032->regmap, RV3032_CLKOUT1, hfd & 0xff); in rv3032_clkout_set_rate()
690 ret = regmap_write(rv3032->regmap, RV3032_CLKOUT2, RV3032_CLKOUT2_OS | in rv3032_clkout_set_rate()
695 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, RV3032_EEPROM_CMD_UPDATE); in rv3032_clkout_set_rate()
701 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_clkout_set_rate()
730 ret = regmap_read(rv3032->regmap, RV3032_PMU, &val); in rv3032_clkout_is_prepared()
752 struct device_node *node = client->dev.of_node; in rv3032_clkout_register_clk()
754 ret = regmap_update_bits(rv3032->regmap, RV3032_TLSB, RV3032_TLSB_CLKF, 0); in rv3032_clkout_register_clk()
758 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, RV3032_CTRL2_CLKIE, 0); in rv3032_clkout_register_clk()
762 ret = regmap_write(rv3032->regmap, RV3032_CLK_IRQ, 0); in rv3032_clkout_register_clk()
766 init.name = "rv3032-clkout"; in rv3032_clkout_register_clk()
771 rv3032->clkout_hw.init = &init; in rv3032_clkout_register_clk()
773 of_property_read_string(node, "clock-output-names", &init.name); in rv3032_clkout_register_clk()
775 clk = devm_clk_register(&client->dev, &rv3032->clkout_hw); in rv3032_clkout_register_clk()
790 ret = regmap_bulk_read(rv3032->regmap, RV3032_TLSB, buf, sizeof(buf)); in rv3032_hwmon_read_temp()
801 ret = regmap_bulk_read(rv3032->regmap, RV3032_TLSB, buf, sizeof(buf)); in rv3032_hwmon_read_temp()
838 err = -EOPNOTSUPP; in rv3032_hwmon_read()
913 rv3032 = devm_kzalloc(&client->dev, sizeof(struct rv3032_data), in rv3032_probe()
916 return -ENOMEM; in rv3032_probe()
918 rv3032->regmap = devm_regmap_init_i2c(client, &regmap_config); in rv3032_probe()
919 if (IS_ERR(rv3032->regmap)) in rv3032_probe()
920 return PTR_ERR(rv3032->regmap); in rv3032_probe()
924 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_probe()
928 rv3032->rtc = devm_rtc_allocate_device(&client->dev); in rv3032_probe()
929 if (IS_ERR(rv3032->rtc)) in rv3032_probe()
930 return PTR_ERR(rv3032->rtc); in rv3032_probe()
932 if (client->irq > 0) { in rv3032_probe()
935 if (dev_fwnode(&client->dev)) in rv3032_probe()
938 ret = devm_request_threaded_irq(&client->dev, client->irq, in rv3032_probe()
943 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); in rv3032_probe()
944 client->irq = 0; in rv3032_probe()
947 if (!client->irq) in rv3032_probe()
948 clear_bit(RTC_FEATURE_ALARM, rv3032->rtc->features); in rv3032_probe()
950 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL1, in rv3032_probe()
955 rv3032_trickle_charger_setup(&client->dev, rv3032); in rv3032_probe()
957 set_bit(RTC_FEATURE_BACKUP_SWITCH_MODE, rv3032->rtc->features); in rv3032_probe()
958 set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rv3032->rtc->features); in rv3032_probe()
960 rv3032->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in rv3032_probe()
961 rv3032->rtc->range_max = RTC_TIMESTAMP_END_2099; in rv3032_probe()
962 rv3032->rtc->ops = &rv3032_rtc_ops; in rv3032_probe()
963 ret = devm_rtc_register_device(rv3032->rtc); in rv3032_probe()
967 nvmem_cfg.priv = rv3032->regmap; in rv3032_probe()
968 devm_rtc_nvmem_register(rv3032->rtc, &nvmem_cfg); in rv3032_probe()
970 devm_rtc_nvmem_register(rv3032->rtc, &eeprom_cfg); in rv3032_probe()
972 rv3032->rtc->max_user_freq = 1; in rv3032_probe()
978 rv3032_hwmon_register(&client->dev); in rv3032_probe()
997 .name = "rtc-rv3032",