Lines Matching full:rv3032

3  * RTC driver for the Micro Crystal RV3032
118 static int rv3032_exit_eerd(struct rv3032_data *rv3032, u32 eerd) in rv3032_exit_eerd() argument
123 return regmap_update_bits(rv3032->regmap, RV3032_CTRL1, RV3032_CTRL1_EERD, 0); in rv3032_exit_eerd()
126 static int rv3032_enter_eerd(struct rv3032_data *rv3032, u32 *eerd) in rv3032_enter_eerd() argument
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()
148 rv3032_exit_eerd(rv3032, *eerd); in rv3032_enter_eerd()
156 static int rv3032_update_cfg(struct rv3032_data *rv3032, unsigned int reg, in rv3032_update_cfg() argument
162 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_update_cfg()
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()
181 rv3032_exit_eerd(rv3032, eerd); in rv3032_update_cfg()
188 struct rv3032_data *rv3032 = dev_id; in rv3032_handle_irq() local
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()
226 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_get_time() local
230 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_get_time()
237 ret = regmap_bulk_read(rv3032->regmap, RV3032_SEC, date, sizeof(date)); in rv3032_get_time()
254 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_set_time() local
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()
279 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_get_alarm() local
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()
309 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_set_alarm() local
314 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, 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()
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()
348 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_alarm_irq_enable() local
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()
373 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_read_offset() local
376 ret = regmap_read(rv3032->regmap, RV3032_OFFSET, &value); in rv3032_read_offset()
389 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_set_offset() local
394 return rv3032_update_cfg(rv3032, RV3032_OFFSET, RV3032_OFFSET_MSK, in rv3032_set_offset()
400 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_param_get() local
407 ret = regmap_read(rv3032->regmap, RV3032_PMU, &value); in rv3032_param_get()
435 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_param_set() local
440 if (rv3032->trickle_charger_set) in rv3032_param_set()
457 return rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_BSM, in rv3032_param_set()
469 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_ioctl() local
474 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_ioctl()
499 struct rv3032_data *rv3032 = priv; in rv3032_eeprom_write() local
504 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_eeprom_write()
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()
533 rv3032_exit_eerd(rv3032, eerd); in rv3032_eeprom_write()
540 struct rv3032_data *rv3032 = priv; in rv3032_eeprom_read() local
545 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_eeprom_read()
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()
573 rv3032_exit_eerd(rv3032, eerd); in rv3032_eeprom_read()
578 static int rv3032_trickle_charger_setup(struct device *dev, struct rv3032_data *rv3032) in rv3032_trickle_charger_setup() argument
606 rv3032->trickle_charger_set = true; in rv3032_trickle_charger_setup()
608 return rv3032_update_cfg(rv3032, RV3032_PMU, in rv3032_trickle_charger_setup()
629 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_recalc_rate() local
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()
668 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_set_rate() local
674 return rv3032_update_cfg(rv3032, RV3032_CLKOUT2, 0xff, in rv3032_clkout_set_rate()
682 ret = rv3032_enter_eerd(rv3032, &eerd); 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()
706 rv3032_exit_eerd(rv3032, eerd); in rv3032_clkout_set_rate()
713 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_prepare() local
715 return rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_NCLKE, 0); in rv3032_clkout_prepare()
720 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_unprepare() local
722 rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_NCLKE, RV3032_PMU_NCLKE); in rv3032_clkout_unprepare()
728 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_is_prepared() local
730 ret = regmap_read(rv3032->regmap, RV3032_PMU, &val); in rv3032_clkout_is_prepared()
746 static int rv3032_clkout_register_clk(struct rv3032_data *rv3032, in rv3032_clkout_register_clk() argument
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()
775 clk = devm_clk_register(&client->dev, &rv3032->clkout_hw); in rv3032_clkout_register_clk()
785 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_hwmon_read_temp() local
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()
863 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_hwmon_register() local
868 devm_hwmon_device_register_with_info(dev, "rv3032", rv3032, &rv3032_hwmon_chip_info, NULL); in rv3032_hwmon_register()
892 struct rv3032_data *rv3032; in rv3032_probe() local
913 rv3032 = devm_kzalloc(&client->dev, sizeof(struct rv3032_data), in rv3032_probe()
915 if (!rv3032) 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()
922 i2c_set_clientdata(client, rv3032); 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()
941 "rv3032", rv3032); 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()
969 eeprom_cfg.priv = rv3032; 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()
975 rv3032_clkout_register_clk(rv3032, client); in rv3032_probe()
990 { .compatible = "microcrystal,rv3032", },
997 .name = "rtc-rv3032",
1006 MODULE_DESCRIPTION("Micro Crystal RV3032 RTC driver");