Lines Matching +full:output +full:- +full:micro +full:- +full:ohms

1 // SPDX-License-Identifier: GPL-2.0
3 * RTC driver for the Micro Crystal RV3032
5 * Copyright (C) 2020 Micro Crystal SA
12 #include <linux/clk-provider.h>
122 return regmap_update_bits(rv3032->regmap, RV3032_CTRL1, RV3032_CTRL1_EERD, 0); in rv3032_exit_eerd()
130 ret = regmap_read(rv3032->regmap, RV3032_CTRL1, &ctrl1); in rv3032_enter_eerd()
138 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL1, in rv3032_enter_eerd()
143 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_enter_eerd()
165 ret = regmap_update_bits(rv3032->regmap, reg, mask, val); in rv3032_update_cfg()
169 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, RV3032_EEPROM_CMD_UPDATE); in rv3032_update_cfg()
175 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_update_cfg()
191 if (regmap_read(rv3032->regmap, RV3032_STATUS, &status) < 0 || in rv3032_handle_irq()
215 rtc_update_irq(rv3032->rtc, 1, events); in rv3032_handle_irq()
216 regmap_update_bits(rv3032->regmap, RV3032_STATUS, status, 0); in rv3032_handle_irq()
217 regmap_update_bits(rv3032->regmap, RV3032_CTRL2, ctrl, 0); in rv3032_handle_irq()
229 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_get_time()
234 return -EINVAL; in rv3032_get_time()
236 ret = regmap_bulk_read(rv3032->regmap, RV3032_SEC, date, sizeof(date)); in rv3032_get_time()
240 tm->tm_sec = bcd2bin(date[0] & 0x7f); in rv3032_get_time()
241 tm->tm_min = bcd2bin(date[1] & 0x7f); in rv3032_get_time()
242 tm->tm_hour = bcd2bin(date[2] & 0x3f); in rv3032_get_time()
243 tm->tm_wday = date[3] & 0x7; in rv3032_get_time()
244 tm->tm_mday = bcd2bin(date[4] & 0x3f); in rv3032_get_time()
245 tm->tm_mon = bcd2bin(date[5] & 0x1f) - 1; in rv3032_get_time()
246 tm->tm_year = bcd2bin(date[6]) + 100; in rv3032_get_time()
257 date[0] = bin2bcd(tm->tm_sec); in rv3032_set_time()
258 date[1] = bin2bcd(tm->tm_min); in rv3032_set_time()
259 date[2] = bin2bcd(tm->tm_hour); in rv3032_set_time()
260 date[3] = tm->tm_wday; in rv3032_set_time()
261 date[4] = bin2bcd(tm->tm_mday); in rv3032_set_time()
262 date[5] = bin2bcd(tm->tm_mon + 1); in rv3032_set_time()
263 date[6] = bin2bcd(tm->tm_year - 100); in rv3032_set_time()
265 ret = regmap_bulk_write(rv3032->regmap, RV3032_SEC, date, in rv3032_set_time()
270 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_set_time()
282 ret = regmap_bulk_read(rv3032->regmap, RV3032_ALARM_MIN, alarmvals, in rv3032_get_alarm()
287 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_get_alarm()
291 ret = regmap_read(rv3032->regmap, RV3032_CTRL2, &ctrl); in rv3032_get_alarm()
295 alrm->time.tm_sec = 0; in rv3032_get_alarm()
296 alrm->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); in rv3032_get_alarm()
297 alrm->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f); in rv3032_get_alarm()
298 alrm->time.tm_mday = bcd2bin(alarmvals[2] & 0x3f); in rv3032_get_alarm()
300 alrm->enabled = !!(ctrl & RV3032_CTRL2_AIE); in rv3032_get_alarm()
301 alrm->pending = (status & RV3032_STATUS_AF) && alrm->enabled; in rv3032_get_alarm()
313 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_set_alarm()
318 alarmvals[0] = bin2bcd(alrm->time.tm_min); in rv3032_set_alarm()
319 alarmvals[1] = bin2bcd(alrm->time.tm_hour); in rv3032_set_alarm()
320 alarmvals[2] = bin2bcd(alrm->time.tm_mday); in rv3032_set_alarm()
322 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_set_alarm()
327 ret = regmap_bulk_write(rv3032->regmap, RV3032_ALARM_MIN, alarmvals, in rv3032_set_alarm()
332 if (alrm->enabled) { in rv3032_set_alarm()
333 if (rv3032->rtc->uie_rtctimer.enabled) in rv3032_set_alarm()
335 if (rv3032->rtc->aie_timer.enabled) in rv3032_set_alarm()
339 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_set_alarm()
351 if (rv3032->rtc->uie_rtctimer.enabled) in rv3032_alarm_irq_enable()
353 if (rv3032->rtc->aie_timer.enabled) in rv3032_alarm_irq_enable()
357 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_alarm_irq_enable()
362 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_alarm_irq_enable()
375 ret = regmap_read(rv3032->regmap, RV3032_OFFSET, &value); in rv3032_read_offset()
390 offset = clamp(offset, -7629L, 7391L) * 1000; in rv3032_set_offset()
402 switch(param->param) { in rv3032_param_get()
406 ret = regmap_read(rv3032->regmap, RV3032_PMU, &value); in rv3032_param_get()
414 param->uvalue = RTC_BSM_DIRECT; in rv3032_param_get()
417 param->uvalue = RTC_BSM_LEVEL; in rv3032_param_get()
420 param->uvalue = RTC_BSM_DISABLED; in rv3032_param_get()
426 return -EINVAL; in rv3032_param_get()
436 switch(param->param) { in rv3032_param_set()
439 if (rv3032->trickle_charger_set) in rv3032_param_set()
440 return -EINVAL; in rv3032_param_set()
442 switch (param->uvalue) { in rv3032_param_set()
453 return -EINVAL; in rv3032_param_set()
460 return -EINVAL; in rv3032_param_set()
473 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_ioctl()
482 return -ENOIOCTLCMD; in rv3032_ioctl()
508 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_ADDR, in rv3032_eeprom_write()
513 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_DATA, buf[i]); in rv3032_eeprom_write()
517 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, in rv3032_eeprom_write()
524 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_eeprom_write()
549 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_ADDR, in rv3032_eeprom_read()
554 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, in rv3032_eeprom_read()
559 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_eeprom_read()
565 ret = regmap_read(rv3032->regmap, RV3032_EEPROM_DATA, &data); in rv3032_eeprom_read()
579 u32 val, ohms, voltage; in rv3032_trickle_charger_setup() local
583 if (!device_property_read_u32(dev, "trickle-voltage-millivolt", &voltage)) { in rv3032_trickle_charger_setup()
592 if (device_property_read_u32(dev, "trickle-resistor-ohms", &ohms)) in rv3032_trickle_charger_setup()
596 if (ohms == rv3032_trickle_resistors[i]) in rv3032_trickle_charger_setup()
605 rv3032->trickle_charger_set = true; in rv3032_trickle_charger_setup()
630 ret = regmap_read(rv3032->regmap, RV3032_CLKOUT2, &clkout); in rv3032_clkout_recalc_rate()
637 ret = regmap_read(rv3032->regmap, RV3032_CLKOUT1, &clkout); in rv3032_clkout_recalc_rate()
679 hfd = clamp(hfd, 1, 8192) - 1; in rv3032_clkout_set_rate()
685 ret = regmap_write(rv3032->regmap, RV3032_CLKOUT1, hfd & 0xff); in rv3032_clkout_set_rate()
689 ret = regmap_write(rv3032->regmap, RV3032_CLKOUT2, RV3032_CLKOUT2_OS | in rv3032_clkout_set_rate()
694 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, RV3032_EEPROM_CMD_UPDATE); in rv3032_clkout_set_rate()
700 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_clkout_set_rate()
729 ret = regmap_read(rv3032->regmap, RV3032_PMU, &val); in rv3032_clkout_is_prepared()
751 struct device_node *node = client->dev.of_node; in rv3032_clkout_register_clk()
753 ret = regmap_update_bits(rv3032->regmap, RV3032_TLSB, RV3032_TLSB_CLKF, 0); in rv3032_clkout_register_clk()
757 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, RV3032_CTRL2_CLKIE, 0); in rv3032_clkout_register_clk()
761 ret = regmap_write(rv3032->regmap, RV3032_CLK_IRQ, 0); in rv3032_clkout_register_clk()
765 init.name = "rv3032-clkout"; in rv3032_clkout_register_clk()
770 rv3032->clkout_hw.init = &init; in rv3032_clkout_register_clk()
772 of_property_read_string(node, "clock-output-names", &init.name); in rv3032_clkout_register_clk()
774 clk = devm_clk_register(&client->dev, &rv3032->clkout_hw); in rv3032_clkout_register_clk()
789 ret = regmap_bulk_read(rv3032->regmap, RV3032_TLSB, buf, sizeof(buf)); in rv3032_hwmon_read_temp()
800 ret = regmap_bulk_read(rv3032->regmap, RV3032_TLSB, buf, sizeof(buf)); in rv3032_hwmon_read_temp()
837 err = -EOPNOTSUPP; in rv3032_hwmon_read()
912 rv3032 = devm_kzalloc(&client->dev, sizeof(struct rv3032_data), in rv3032_probe()
915 return -ENOMEM; in rv3032_probe()
917 rv3032->regmap = devm_regmap_init_i2c(client, &regmap_config); in rv3032_probe()
918 if (IS_ERR(rv3032->regmap)) in rv3032_probe()
919 return PTR_ERR(rv3032->regmap); in rv3032_probe()
923 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_probe()
927 rv3032->rtc = devm_rtc_allocate_device(&client->dev); in rv3032_probe()
928 if (IS_ERR(rv3032->rtc)) in rv3032_probe()
929 return PTR_ERR(rv3032->rtc); in rv3032_probe()
931 if (client->irq > 0) { in rv3032_probe()
934 if (dev_fwnode(&client->dev)) in rv3032_probe()
937 ret = devm_request_threaded_irq(&client->dev, client->irq, in rv3032_probe()
942 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); in rv3032_probe()
943 client->irq = 0; in rv3032_probe()
946 if (!client->irq) in rv3032_probe()
947 clear_bit(RTC_FEATURE_ALARM, rv3032->rtc->features); in rv3032_probe()
949 rv3032_trickle_charger_setup(&client->dev, rv3032); in rv3032_probe()
951 set_bit(RTC_FEATURE_BACKUP_SWITCH_MODE, rv3032->rtc->features); in rv3032_probe()
952 set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rv3032->rtc->features); in rv3032_probe()
954 rv3032->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in rv3032_probe()
955 rv3032->rtc->range_max = RTC_TIMESTAMP_END_2099; in rv3032_probe()
956 rv3032->rtc->ops = &rv3032_rtc_ops; in rv3032_probe()
957 ret = devm_rtc_register_device(rv3032->rtc); in rv3032_probe()
961 nvmem_cfg.priv = rv3032->regmap; in rv3032_probe()
962 devm_rtc_nvmem_register(rv3032->rtc, &nvmem_cfg); in rv3032_probe()
964 devm_rtc_nvmem_register(rv3032->rtc, &eeprom_cfg); in rv3032_probe()
966 rv3032->rtc->max_user_freq = 1; in rv3032_probe()
972 rv3032_hwmon_register(&client->dev); in rv3032_probe()
991 .name = "rtc-rv3032",
1000 MODULE_DESCRIPTION("Micro Crystal RV3032 RTC driver");