Lines Matching +full:trickle +full:- +full:diode +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0
89 while ((ret == -ENXIO || ret == -EIO) && --try); in rv8803_read_reg()
91 dev_err(&client->dev, "Unable to read register 0x%02x\n", reg); in rv8803_read_reg()
104 while ((ret == -ENXIO || ret == -EIO) && --try); in rv8803_read_regs()
106 dev_err(&client->dev, in rv8803_read_regs()
108 reg, reg + count - 1); in rv8803_read_regs()
109 return ret < 0 ? ret : -EIO; in rv8803_read_regs()
122 while ((ret == -ENXIO || ret == -EIO) && --try); in rv8803_write_reg()
124 dev_err(&client->dev, "Unable to write register 0x%02x\n", reg); in rv8803_write_reg()
138 while ((ret == -ENXIO || ret == -EIO) && --try); in rv8803_write_regs()
140 dev_err(&client->dev, in rv8803_write_regs()
142 reg, reg + count - 1); in rv8803_write_regs()
151 ret = rv8803_write_reg(rv8803->client, RV8803_OSC_OFFSET, 0x00); in rv8803_regs_init()
155 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL, in rv8803_regs_init()
160 ret = rv8803_write_regs(rv8803->client, RV8803_ALARM_MIN, 3, in rv8803_regs_init()
165 return rv8803_write_reg(rv8803->client, RV8803_RAM, 0x00); in rv8803_regs_init()
173 * The RV-8803 resets all registers to POR defaults after voltage-loss, in rv8803_regs_reset()
176 if (full || rv8803->type == rx_8803 || rv8803->type == rx_8900) { in rv8803_regs_reset()
192 mutex_lock(&rv8803->flags_lock); in rv8803_handle_irq()
196 mutex_unlock(&rv8803->flags_lock); in rv8803_handle_irq()
201 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); in rv8803_handle_irq()
204 dev_warn(&client->dev, "Voltage low, data loss detected.\n"); in rv8803_handle_irq()
208 rv8803->ctrl &= ~RV8803_CTRL_TIE; in rv8803_handle_irq()
214 rv8803->ctrl &= ~RV8803_CTRL_AIE; in rv8803_handle_irq()
220 rv8803->ctrl &= ~RV8803_CTRL_UIE; in rv8803_handle_irq()
225 rtc_update_irq(rv8803->rtc, 1, events); in rv8803_handle_irq()
227 rv8803_write_reg(rv8803->client, RV8803_CTRL, rv8803->ctrl); in rv8803_handle_irq()
230 mutex_unlock(&rv8803->flags_lock); in rv8803_handle_irq()
243 if (rv8803->alarm_invalid) { in rv8803_get_time()
245 return -EINVAL; in rv8803_get_time()
248 flags = rv8803_read_reg(rv8803->client, RV8803_FLAG); in rv8803_get_time()
254 return -EINVAL; in rv8803_get_time()
257 ret = rv8803_read_regs(rv8803->client, RV8803_SEC, 7, date); in rv8803_get_time()
262 ret = rv8803_read_regs(rv8803->client, RV8803_SEC, 7, date2); in rv8803_get_time()
270 tm->tm_sec = bcd2bin(date[RV8803_SEC] & 0x7f); in rv8803_get_time()
271 tm->tm_min = bcd2bin(date[RV8803_MIN] & 0x7f); in rv8803_get_time()
272 tm->tm_hour = bcd2bin(date[RV8803_HOUR] & 0x3f); in rv8803_get_time()
273 tm->tm_wday = ilog2(date[RV8803_WEEK] & 0x7f); in rv8803_get_time()
274 tm->tm_mday = bcd2bin(date[RV8803_DAY] & 0x3f); in rv8803_get_time()
275 tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1; in rv8803_get_time()
276 tm->tm_year = bcd2bin(date[RV8803_YEAR]) + 100; in rv8803_get_time()
287 ctrl = rv8803_read_reg(rv8803->client, RV8803_CTRL); in rv8803_set_time()
292 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL, in rv8803_set_time()
297 date[RV8803_SEC] = bin2bcd(tm->tm_sec); in rv8803_set_time()
298 date[RV8803_MIN] = bin2bcd(tm->tm_min); in rv8803_set_time()
299 date[RV8803_HOUR] = bin2bcd(tm->tm_hour); in rv8803_set_time()
300 date[RV8803_WEEK] = 1 << (tm->tm_wday); in rv8803_set_time()
301 date[RV8803_DAY] = bin2bcd(tm->tm_mday); in rv8803_set_time()
302 date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1); in rv8803_set_time()
303 date[RV8803_YEAR] = bin2bcd(tm->tm_year - 100); in rv8803_set_time()
305 ret = rv8803_write_regs(rv8803->client, RV8803_SEC, 7, date); in rv8803_set_time()
310 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL, in rv8803_set_time()
315 mutex_lock(&rv8803->flags_lock); in rv8803_set_time()
317 flags = rv8803_read_reg(rv8803->client, RV8803_FLAG); in rv8803_set_time()
319 mutex_unlock(&rv8803->flags_lock); in rv8803_set_time()
323 if ((flags & RV8803_FLAG_V2F) || rv8803->alarm_invalid) { in rv8803_set_time()
329 ret = rv8803_regs_reset(rv8803, rv8803->alarm_invalid); in rv8803_set_time()
331 mutex_unlock(&rv8803->flags_lock); in rv8803_set_time()
335 rv8803->alarm_invalid = false; in rv8803_set_time()
338 ret = rv8803_write_reg(rv8803->client, RV8803_FLAG, in rv8803_set_time()
341 mutex_unlock(&rv8803->flags_lock); in rv8803_set_time()
349 struct i2c_client *client = rv8803->client; in rv8803_get_alarm()
370 alrm->time.tm_sec = 0; in rv8803_get_alarm()
371 alrm->time.tm_min = bcd2bin(alarmvals[0]); in rv8803_get_alarm()
372 alrm->time.tm_hour = bcd2bin(alarmvals[1]); in rv8803_get_alarm()
373 alrm->time.tm_mday = bcd2bin(alarmvals[2]); in rv8803_get_alarm()
375 alrm->enabled = !!(rv8803->ctrl & RV8803_CTRL_AIE); in rv8803_get_alarm()
376 alrm->pending = (flags & RV8803_FLAG_AF) && alrm->enabled; in rv8803_get_alarm()
378 if ((unsigned int)alrm->time.tm_mday > 31 || in rv8803_get_alarm()
379 (unsigned int)alrm->time.tm_hour >= 24 || in rv8803_get_alarm()
380 (unsigned int)alrm->time.tm_min >= 60) in rv8803_get_alarm()
386 rv8803->alarm_invalid = true; in rv8803_get_alarm()
387 return -EINVAL; in rv8803_get_alarm()
399 if (alrm->time.tm_sec) { in rv8803_set_alarm()
400 time64_t alarm_time = rtc_tm_to_time64(&alrm->time); in rv8803_set_alarm()
402 alarm_time += 60 - alrm->time.tm_sec; in rv8803_set_alarm()
403 rtc_time64_to_tm(alarm_time, &alrm->time); in rv8803_set_alarm()
406 mutex_lock(&rv8803->flags_lock); in rv8803_set_alarm()
410 mutex_unlock(&rv8803->flags_lock); in rv8803_set_alarm()
414 alarmvals[0] = bin2bcd(alrm->time.tm_min); in rv8803_set_alarm()
415 alarmvals[1] = bin2bcd(alrm->time.tm_hour); in rv8803_set_alarm()
416 alarmvals[2] = bin2bcd(alrm->time.tm_mday); in rv8803_set_alarm()
418 if (rv8803->ctrl & (RV8803_CTRL_AIE | RV8803_CTRL_UIE)) { in rv8803_set_alarm()
419 rv8803->ctrl &= ~(RV8803_CTRL_AIE | RV8803_CTRL_UIE); in rv8803_set_alarm()
420 err = rv8803_write_reg(rv8803->client, RV8803_CTRL, in rv8803_set_alarm()
421 rv8803->ctrl); in rv8803_set_alarm()
423 mutex_unlock(&rv8803->flags_lock); in rv8803_set_alarm()
429 err = rv8803_write_reg(rv8803->client, RV8803_FLAG, ctrl[0]); in rv8803_set_alarm()
430 mutex_unlock(&rv8803->flags_lock); in rv8803_set_alarm()
434 err = rv8803_write_regs(rv8803->client, RV8803_ALARM_MIN, 3, alarmvals); in rv8803_set_alarm()
438 if (alrm->enabled) { in rv8803_set_alarm()
439 if (rv8803->rtc->uie_rtctimer.enabled) in rv8803_set_alarm()
440 rv8803->ctrl |= RV8803_CTRL_UIE; in rv8803_set_alarm()
441 if (rv8803->rtc->aie_timer.enabled) in rv8803_set_alarm()
442 rv8803->ctrl |= RV8803_CTRL_AIE; in rv8803_set_alarm()
444 err = rv8803_write_reg(rv8803->client, RV8803_CTRL, in rv8803_set_alarm()
445 rv8803->ctrl); in rv8803_set_alarm()
459 ctrl = rv8803->ctrl; in rv8803_alarm_irq_enable()
462 if (rv8803->rtc->uie_rtctimer.enabled) in rv8803_alarm_irq_enable()
464 if (rv8803->rtc->aie_timer.enabled) in rv8803_alarm_irq_enable()
467 if (!rv8803->rtc->uie_rtctimer.enabled) in rv8803_alarm_irq_enable()
469 if (!rv8803->rtc->aie_timer.enabled) in rv8803_alarm_irq_enable()
473 mutex_lock(&rv8803->flags_lock); in rv8803_alarm_irq_enable()
476 mutex_unlock(&rv8803->flags_lock); in rv8803_alarm_irq_enable()
481 mutex_unlock(&rv8803->flags_lock); in rv8803_alarm_irq_enable()
485 if (ctrl != rv8803->ctrl) { in rv8803_alarm_irq_enable()
486 rv8803->ctrl = ctrl; in rv8803_alarm_irq_enable()
487 err = rv8803_write_reg(client, RV8803_CTRL, rv8803->ctrl); in rv8803_alarm_irq_enable()
509 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); in rv8803_ioctl()
519 mutex_lock(&rv8803->flags_lock); in rv8803_ioctl()
522 mutex_unlock(&rv8803->flags_lock); in rv8803_ioctl()
528 mutex_unlock(&rv8803->flags_lock); in rv8803_ioctl()
535 return -ENOIOCTLCMD; in rv8803_ioctl()
570 struct i2c_client *client = rv8803->client; in rx8900_trickle_charger_init()
571 struct device_node *node = client->dev.of_node; in rx8900_trickle_charger_init()
578 if (rv8803->type != rx_8900) in rx8900_trickle_charger_init()
581 err = i2c_smbus_read_byte_data(rv8803->client, RX8900_BACKUP_CTRL); in rx8900_trickle_charger_init()
587 flags |= rv8803->backup; in rx8900_trickle_charger_init()
589 return i2c_smbus_write_byte_data(rv8803->client, RX8900_BACKUP_CTRL, in rx8900_trickle_charger_init()
593 /* configure registers with values different than the Power-On reset defaults */
598 err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA); in rv8803_regs_configure()
604 dev_err(&rv8803->client->dev, "failed to init charger\n"); in rv8803_regs_configure()
615 if (rv8803->client->irq > 0 && device_may_wakeup(dev)) in rv8803_resume()
616 disable_irq_wake(rv8803->client->irq); in rv8803_resume()
625 if (rv8803->client->irq > 0 && device_may_wakeup(dev)) in rv8803_suspend()
626 enable_irq_wake(rv8803->client->irq); in rv8803_suspend()
644 struct i2c_adapter *adapter = client->adapter; in rv8803_probe()
659 dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n"); in rv8803_probe()
660 return -EIO; in rv8803_probe()
663 rv8803 = devm_kzalloc(&client->dev, sizeof(struct rv8803_data), in rv8803_probe()
666 return -ENOMEM; in rv8803_probe()
668 mutex_init(&rv8803->flags_lock); in rv8803_probe()
669 rv8803->client = client; in rv8803_probe()
670 if (client->dev.of_node) { in rv8803_probe()
671 rv8803->type = (uintptr_t)of_device_get_match_data(&client->dev); in rv8803_probe()
675 rv8803->type = id->driver_data; in rv8803_probe()
684 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); in rv8803_probe()
687 dev_warn(&client->dev, "Voltage low, data loss detected.\n"); in rv8803_probe()
690 dev_warn(&client->dev, "An alarm maybe have been missed.\n"); in rv8803_probe()
692 rv8803->rtc = devm_rtc_allocate_device(&client->dev); in rv8803_probe()
693 if (IS_ERR(rv8803->rtc)) in rv8803_probe()
694 return PTR_ERR(rv8803->rtc); in rv8803_probe()
696 if (client->irq > 0) { in rv8803_probe()
699 if (dev_fwnode(&client->dev)) in rv8803_probe()
702 err = devm_request_threaded_irq(&client->dev, client->irq, in rv8803_probe()
707 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); in rv8803_probe()
708 client->irq = 0; in rv8803_probe()
710 device_init_wakeup(&client->dev, true); in rv8803_probe()
711 err = dev_pm_set_wake_irq(&client->dev, client->irq); in rv8803_probe()
713 dev_err(&client->dev, "failed to set wake IRQ\n"); in rv8803_probe()
716 if (device_property_read_bool(&client->dev, "wakeup-source")) in rv8803_probe()
717 device_init_wakeup(&client->dev, true); in rv8803_probe()
719 clear_bit(RTC_FEATURE_ALARM, rv8803->rtc->features); in rv8803_probe()
722 if (of_property_read_bool(client->dev.of_node, "epson,vdet-disable")) in rv8803_probe()
723 rv8803->backup |= RX8900_FLAG_VDETOFF; in rv8803_probe()
725 if (of_property_read_bool(client->dev.of_node, "trickle-diode-disable")) in rv8803_probe()
726 rv8803->backup |= RX8900_FLAG_SWOFF; in rv8803_probe()
732 rv8803->rtc->ops = &rv8803_rtc_ops; in rv8803_probe()
733 rv8803->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in rv8803_probe()
734 rv8803->rtc->range_max = RTC_TIMESTAMP_END_2099; in rv8803_probe()
735 err = devm_rtc_register_device(rv8803->rtc); in rv8803_probe()
739 devm_rtc_nvmem_register(rv8803->rtc, &nvmem_cfg); in rv8803_probe()
741 rv8803->rtc->max_user_freq = 1; in rv8803_probe()
769 .name = "rtc-rv8803",