Lines Matching full:rv3028

3  * RTC driver for the Micro Crystal RV3028
110 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent); in timestamp0_store() local
112 regmap_update_bits(rv3028->regmap, RV3028_EVT_CTRL, RV3028_EVT_CTRL_TSR, in timestamp0_store()
121 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent); in timestamp0_show() local
126 ret = regmap_read(rv3028->regmap, RV3028_TS_COUNT, &count); in timestamp0_show()
133 ret = regmap_bulk_read(rv3028->regmap, RV3028_TS_SEC, date, in timestamp0_show()
158 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent); in timestamp0_count_show() local
161 ret = regmap_read(rv3028->regmap, RV3028_TS_COUNT, &count); in timestamp0_count_show()
180 static int rv3028_exit_eerd(struct rv3028_data *rv3028, u32 eerd) in rv3028_exit_eerd() argument
185 return regmap_update_bits(rv3028->regmap, RV3028_CTRL1, RV3028_CTRL1_EERD, 0); in rv3028_exit_eerd()
188 static int rv3028_enter_eerd(struct rv3028_data *rv3028, u32 *eerd) in rv3028_enter_eerd() argument
193 ret = regmap_read(rv3028->regmap, RV3028_CTRL1, &ctrl1); in rv3028_enter_eerd()
201 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL1, in rv3028_enter_eerd()
206 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_enter_eerd()
210 rv3028_exit_eerd(rv3028, *eerd); in rv3028_enter_eerd()
218 static int rv3028_update_eeprom(struct rv3028_data *rv3028, u32 eerd) in rv3028_update_eeprom() argument
223 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, 0x0); in rv3028_update_eeprom()
227 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, RV3028_EEPROM_CMD_UPDATE); in rv3028_update_eeprom()
233 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_update_eeprom()
238 rv3028_exit_eerd(rv3028, eerd); in rv3028_update_eeprom()
243 static int rv3028_update_cfg(struct rv3028_data *rv3028, unsigned int reg, in rv3028_update_cfg() argument
249 ret = rv3028_enter_eerd(rv3028, &eerd); in rv3028_update_cfg()
253 ret = regmap_update_bits(rv3028->regmap, reg, mask, val); in rv3028_update_cfg()
255 rv3028_exit_eerd(rv3028, eerd); in rv3028_update_cfg()
259 return rv3028_update_eeprom(rv3028, eerd); in rv3028_update_cfg()
264 struct rv3028_data *rv3028 = dev_id; in rv3028_handle_irq() local
268 if (regmap_read(rv3028->regmap, RV3028_STATUS, &status) < 0 || in rv3028_handle_irq()
294 rtc_update_irq(rv3028->rtc, 1, events); in rv3028_handle_irq()
295 regmap_update_bits(rv3028->regmap, RV3028_STATUS, status, 0); in rv3028_handle_irq()
296 regmap_update_bits(rv3028->regmap, RV3028_CTRL2, ctrl, 0); in rv3028_handle_irq()
300 sysfs_notify(&rv3028->rtc->dev.kobj, NULL, in rv3028_handle_irq()
302 dev_warn(&rv3028->rtc->dev, "event detected"); in rv3028_handle_irq()
310 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_get_time() local
314 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_get_time()
321 ret = regmap_bulk_read(rv3028->regmap, RV3028_SEC, date, sizeof(date)); in rv3028_get_time()
338 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_set_time() local
354 ret = regmap_bulk_write(rv3028->regmap, RV3028_SEC, date, in rv3028_set_time()
359 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_set_time()
367 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_get_alarm() local
371 ret = regmap_bulk_read(rv3028->regmap, RV3028_ALARM_MIN, alarmvals, in rv3028_get_alarm()
376 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_get_alarm()
380 ret = regmap_read(rv3028->regmap, RV3028_CTRL2, &ctrl); in rv3028_get_alarm()
397 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_set_alarm() local
410 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_set_alarm()
419 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_set_alarm()
424 ret = regmap_bulk_write(rv3028->regmap, RV3028_ALARM_MIN, alarmvals, in rv3028_set_alarm()
430 if (rv3028->rtc->uie_rtctimer.enabled) in rv3028_set_alarm()
432 if (rv3028->rtc->aie_timer.enabled) in rv3028_set_alarm()
436 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_set_alarm()
444 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_alarm_irq_enable() local
448 if (rv3028->rtc->uie_rtctimer.enabled) in rv3028_alarm_irq_enable()
450 if (rv3028->rtc->aie_timer.enabled) in rv3028_alarm_irq_enable()
454 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_alarm_irq_enable()
459 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_alarm_irq_enable()
469 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_read_offset() local
472 ret = regmap_read(rv3028->regmap, RV3028_OFFSET, &value); in rv3028_read_offset()
478 ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &value); in rv3028_read_offset()
491 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_set_offset() local
498 ret = rv3028_enter_eerd(rv3028, &eerd); in rv3028_set_offset()
502 ret = regmap_write(rv3028->regmap, RV3028_OFFSET, offset >> 1); in rv3028_set_offset()
506 ret = regmap_update_bits(rv3028->regmap, RV3028_BACKUP, BIT(7), in rv3028_set_offset()
511 return rv3028_update_eeprom(rv3028, eerd); in rv3028_set_offset()
514 rv3028_exit_eerd(rv3028, eerd); in rv3028_set_offset()
522 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_param_get() local
528 ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &value); in rv3028_param_get()
555 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_param_set() local
574 return rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_BSM, in rv3028_param_set()
586 struct rv3028_data *rv3028 = dev_get_drvdata(dev); in rv3028_ioctl() local
591 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_ioctl()
618 struct rv3028_data *rv3028 = priv; in rv3028_eeprom_write() local
623 ret = rv3028_enter_eerd(rv3028, &eerd); in rv3028_eeprom_write()
628 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_ADDR, offset + i); in rv3028_eeprom_write()
632 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_DATA, buf[i]); in rv3028_eeprom_write()
636 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, 0x0); in rv3028_eeprom_write()
640 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, in rv3028_eeprom_write()
647 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_eeprom_write()
656 rv3028_exit_eerd(rv3028, eerd); in rv3028_eeprom_write()
664 struct rv3028_data *rv3028 = priv; in rv3028_eeprom_read() local
669 ret = rv3028_enter_eerd(rv3028, &eerd); in rv3028_eeprom_read()
674 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_ADDR, offset + i); in rv3028_eeprom_read()
678 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, 0x0); in rv3028_eeprom_read()
682 ret = regmap_write(rv3028->regmap, RV3028_EEPROM_CMD, in rv3028_eeprom_read()
687 ret = regmap_read_poll_timeout(rv3028->regmap, RV3028_STATUS, status, in rv3028_eeprom_read()
694 ret = regmap_read(rv3028->regmap, RV3028_EEPROM_DATA, &data); in rv3028_eeprom_read()
701 rv3028_exit_eerd(rv3028, eerd); in rv3028_eeprom_read()
722 struct rv3028_data *rv3028 = clkout_hw_to_rv3028(hw); in rv3028_clkout_recalc_rate() local
724 ret = regmap_read(rv3028->regmap, RV3028_CLKOUT, &clkout); in rv3028_clkout_recalc_rate()
749 struct rv3028_data *rv3028 = clkout_hw_to_rv3028(hw); in rv3028_clkout_set_rate() local
751 ret = regmap_read(rv3028->regmap, RV3028_CLKOUT, &enabled); in rv3028_clkout_set_rate()
755 ret = regmap_write(rv3028->regmap, RV3028_CLKOUT, 0x0); in rv3028_clkout_set_rate()
763 return rv3028_update_cfg(rv3028, RV3028_CLKOUT, 0xff, in rv3028_clkout_set_rate()
771 struct rv3028_data *rv3028 = clkout_hw_to_rv3028(hw); in rv3028_clkout_prepare() local
773 return regmap_write(rv3028->regmap, RV3028_CLKOUT, in rv3028_clkout_prepare()
779 struct rv3028_data *rv3028 = clkout_hw_to_rv3028(hw); in rv3028_clkout_unprepare() local
781 regmap_write(rv3028->regmap, RV3028_CLKOUT, 0x0); in rv3028_clkout_unprepare()
782 regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_clkout_unprepare()
789 struct rv3028_data *rv3028 = clkout_hw_to_rv3028(hw); in rv3028_clkout_is_prepared() local
791 ret = regmap_read(rv3028->regmap, RV3028_CLKOUT, &clkout); in rv3028_clkout_is_prepared()
807 static int rv3028_clkout_register_clk(struct rv3028_data *rv3028, in rv3028_clkout_register_clk() argument
815 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS, in rv3028_clkout_register_clk()
820 init.name = "rv3028-clkout"; in rv3028_clkout_register_clk()
825 rv3028->clkout_hw.init = &init; in rv3028_clkout_register_clk()
831 clk = devm_clk_register(&client->dev, &rv3028->clkout_hw); in rv3028_clkout_register_clk()
858 static u8 rv3028_set_trickle_charger(struct rv3028_data *rv3028, in rv3028_set_trickle_charger() argument
864 ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &val_old); in rv3028_set_trickle_charger()
907 ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE | in rv3028_set_trickle_charger()
918 struct rv3028_data *rv3028; in rv3028_probe() local
939 rv3028 = devm_kzalloc(&client->dev, sizeof(struct rv3028_data), in rv3028_probe()
941 if (!rv3028) in rv3028_probe()
944 rv3028->regmap = devm_regmap_init_i2c(client, &regmap_config); in rv3028_probe()
945 if (IS_ERR(rv3028->regmap)) in rv3028_probe()
946 return PTR_ERR(rv3028->regmap); in rv3028_probe()
948 i2c_set_clientdata(client, rv3028); in rv3028_probe()
950 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status); in rv3028_probe()
957 rv3028->rtc = devm_rtc_allocate_device(&client->dev); in rv3028_probe()
958 if (IS_ERR(rv3028->rtc)) in rv3028_probe()
959 return PTR_ERR(rv3028->rtc); in rv3028_probe()
976 "rv3028", rv3028); in rv3028_probe()
983 clear_bit(RTC_FEATURE_ALARM, rv3028->rtc->features); in rv3028_probe()
985 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL1, in rv3028_probe()
991 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2, in rv3028_probe()
997 ret = rv3028_set_trickle_charger(rv3028, client); in rv3028_probe()
1001 ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group); in rv3028_probe()
1005 set_bit(RTC_FEATURE_BACKUP_SWITCH_MODE, rv3028->rtc->features); in rv3028_probe()
1007 rv3028->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in rv3028_probe()
1008 rv3028->rtc->range_max = RTC_TIMESTAMP_END_2099; in rv3028_probe()
1009 rv3028->rtc->ops = &rv3028_rtc_ops; in rv3028_probe()
1010 ret = devm_rtc_register_device(rv3028->rtc); in rv3028_probe()
1014 nvmem_cfg.priv = rv3028->regmap; in rv3028_probe()
1015 devm_rtc_nvmem_register(rv3028->rtc, &nvmem_cfg); in rv3028_probe()
1016 eeprom_cfg.priv = rv3028; in rv3028_probe()
1017 devm_rtc_nvmem_register(rv3028->rtc, &eeprom_cfg); in rv3028_probe()
1019 rv3028->rtc->max_user_freq = 1; in rv3028_probe()
1022 rv3028_clkout_register_clk(rv3028, client); in rv3028_probe()
1034 { .compatible = "microcrystal,rv3028", },
1040 { .name = "rv3028", },
1047 .name = "rtc-rv3028",
1057 MODULE_DESCRIPTION("Micro Crystal RV3028 RTC driver");