Lines Matching full:rv3032
3 * RTC driver for the Micro Crystal RV3032
117 static int rv3032_exit_eerd(struct rv3032_data *rv3032, u32 eerd) in rv3032_exit_eerd() argument
122 return regmap_update_bits(rv3032->regmap, RV3032_CTRL1, RV3032_CTRL1_EERD, 0); in rv3032_exit_eerd()
125 static int rv3032_enter_eerd(struct rv3032_data *rv3032, u32 *eerd) in rv3032_enter_eerd() argument
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()
147 rv3032_exit_eerd(rv3032, *eerd); in rv3032_enter_eerd()
155 static int rv3032_update_cfg(struct rv3032_data *rv3032, unsigned int reg, in rv3032_update_cfg() argument
161 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_update_cfg()
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()
180 rv3032_exit_eerd(rv3032, eerd); in rv3032_update_cfg()
187 struct rv3032_data *rv3032 = dev_id; in rv3032_handle_irq() local
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()
225 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_get_time() local
229 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_get_time()
236 ret = regmap_bulk_read(rv3032->regmap, RV3032_SEC, date, sizeof(date)); in rv3032_get_time()
253 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_set_time() local
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()
278 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_get_alarm() local
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()
308 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_set_alarm() local
321 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_set_alarm()
330 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_set_alarm()
335 ret = regmap_bulk_write(rv3032->regmap, RV3032_ALARM_MIN, alarmvals, in rv3032_set_alarm()
341 if (rv3032->rtc->uie_rtctimer.enabled) in rv3032_set_alarm()
343 if (rv3032->rtc->aie_timer.enabled) in rv3032_set_alarm()
347 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_set_alarm()
355 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_alarm_irq_enable() local
359 if (rv3032->rtc->uie_rtctimer.enabled) in rv3032_alarm_irq_enable()
361 if (rv3032->rtc->aie_timer.enabled) in rv3032_alarm_irq_enable()
365 ret = regmap_update_bits(rv3032->regmap, RV3032_STATUS, in rv3032_alarm_irq_enable()
370 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, in rv3032_alarm_irq_enable()
380 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_read_offset() local
383 ret = regmap_read(rv3032->regmap, RV3032_OFFSET, &value); in rv3032_read_offset()
396 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_set_offset() local
401 return rv3032_update_cfg(rv3032, RV3032_OFFSET, RV3032_OFFSET_MSK, in rv3032_set_offset()
407 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_ioctl() local
412 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_ioctl()
437 struct rv3032_data *rv3032 = priv; in rv3032_eeprom_write() local
442 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_eeprom_write()
447 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_ADDR, in rv3032_eeprom_write()
452 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_DATA, buf[i]); in rv3032_eeprom_write()
456 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, in rv3032_eeprom_write()
463 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_eeprom_write()
471 rv3032_exit_eerd(rv3032, eerd); in rv3032_eeprom_write()
478 struct rv3032_data *rv3032 = priv; in rv3032_eeprom_read() local
483 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_eeprom_read()
488 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_ADDR, in rv3032_eeprom_read()
493 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, in rv3032_eeprom_read()
498 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_eeprom_read()
504 ret = regmap_read(rv3032->regmap, RV3032_EEPROM_DATA, &data); in rv3032_eeprom_read()
511 rv3032_exit_eerd(rv3032, eerd); in rv3032_eeprom_read()
516 static int rv3032_trickle_charger_setup(struct device *dev, struct rv3032_data *rv3032) in rv3032_trickle_charger_setup() argument
544 return rv3032_update_cfg(rv3032, RV3032_PMU, in rv3032_trickle_charger_setup()
565 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_recalc_rate() local
567 ret = regmap_read(rv3032->regmap, RV3032_CLKOUT2, &clkout); in rv3032_clkout_recalc_rate()
574 ret = regmap_read(rv3032->regmap, RV3032_CLKOUT1, &clkout); in rv3032_clkout_recalc_rate()
604 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_set_rate() local
610 return rv3032_update_cfg(rv3032, RV3032_CLKOUT2, 0xff, in rv3032_clkout_set_rate()
618 ret = rv3032_enter_eerd(rv3032, &eerd); in rv3032_clkout_set_rate()
622 ret = regmap_write(rv3032->regmap, RV3032_CLKOUT1, hfd & 0xff); in rv3032_clkout_set_rate()
626 ret = regmap_write(rv3032->regmap, RV3032_CLKOUT2, RV3032_CLKOUT2_OS | in rv3032_clkout_set_rate()
631 ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, RV3032_EEPROM_CMD_UPDATE); in rv3032_clkout_set_rate()
637 ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status, in rv3032_clkout_set_rate()
642 rv3032_exit_eerd(rv3032, eerd); in rv3032_clkout_set_rate()
649 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_prepare() local
651 return rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_NCLKE, 0); in rv3032_clkout_prepare()
656 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_unprepare() local
658 rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_NCLKE, RV3032_PMU_NCLKE); in rv3032_clkout_unprepare()
664 struct rv3032_data *rv3032 = clkout_hw_to_rv3032(hw); in rv3032_clkout_is_prepared() local
666 ret = regmap_read(rv3032->regmap, RV3032_PMU, &val); in rv3032_clkout_is_prepared()
682 static int rv3032_clkout_register_clk(struct rv3032_data *rv3032, in rv3032_clkout_register_clk() argument
690 ret = regmap_update_bits(rv3032->regmap, RV3032_TLSB, RV3032_TLSB_CLKF, 0); in rv3032_clkout_register_clk()
694 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL2, RV3032_CTRL2_CLKIE, 0); in rv3032_clkout_register_clk()
698 ret = regmap_write(rv3032->regmap, RV3032_CLK_IRQ, 0); in rv3032_clkout_register_clk()
702 init.name = "rv3032-clkout"; in rv3032_clkout_register_clk()
707 rv3032->clkout_hw.init = &init; in rv3032_clkout_register_clk()
711 clk = devm_clk_register(&client->dev, &rv3032->clkout_hw); in rv3032_clkout_register_clk()
721 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_hwmon_read_temp() local
726 ret = regmap_bulk_read(rv3032->regmap, RV3032_TLSB, buf, sizeof(buf)); in rv3032_hwmon_read_temp()
737 ret = regmap_bulk_read(rv3032->regmap, RV3032_TLSB, buf, sizeof(buf)); in rv3032_hwmon_read_temp()
799 struct rv3032_data *rv3032 = dev_get_drvdata(dev); in rv3032_hwmon_register() local
804 devm_hwmon_device_register_with_info(dev, "rv3032", rv3032, &rv3032_hwmon_chip_info, NULL); in rv3032_hwmon_register()
823 struct rv3032_data *rv3032; in rv3032_probe() local
844 rv3032 = devm_kzalloc(&client->dev, sizeof(struct rv3032_data), in rv3032_probe()
846 if (!rv3032) in rv3032_probe()
849 rv3032->regmap = devm_regmap_init_i2c(client, ®map_config); in rv3032_probe()
850 if (IS_ERR(rv3032->regmap)) in rv3032_probe()
851 return PTR_ERR(rv3032->regmap); in rv3032_probe()
853 i2c_set_clientdata(client, rv3032); in rv3032_probe()
855 ret = regmap_read(rv3032->regmap, RV3032_STATUS, &status); in rv3032_probe()
859 rv3032->rtc = devm_rtc_allocate_device(&client->dev); in rv3032_probe()
860 if (IS_ERR(rv3032->rtc)) in rv3032_probe()
861 return PTR_ERR(rv3032->rtc); in rv3032_probe()
867 "rv3032", rv3032); in rv3032_probe()
878 ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL1, in rv3032_probe()
883 rv3032_trickle_charger_setup(&client->dev, rv3032); in rv3032_probe()
885 rv3032->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in rv3032_probe()
886 rv3032->rtc->range_max = RTC_TIMESTAMP_END_2099; in rv3032_probe()
887 rv3032->rtc->ops = &rv3032_rtc_ops; in rv3032_probe()
888 ret = rtc_register_device(rv3032->rtc); in rv3032_probe()
892 nvmem_cfg.priv = rv3032; in rv3032_probe()
893 rtc_nvmem_register(rv3032->rtc, &nvmem_cfg); in rv3032_probe()
894 eeprom_cfg.priv = rv3032; in rv3032_probe()
895 rtc_nvmem_register(rv3032->rtc, &eeprom_cfg); in rv3032_probe()
897 rv3032->rtc->max_user_freq = 1; in rv3032_probe()
900 rv3032_clkout_register_clk(rv3032, client); in rv3032_probe()
909 { .compatible = "microcrystal,rv3032", },
916 .name = "rtc-rv3032",
924 MODULE_DESCRIPTION("Micro Crystal RV3032 RTC driver");