Lines Matching +full:battery +full:- +full:backed

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rtc-ds1307.c - RTC driver for some mostly-compatible I2C chips.
23 #include <linux/hwmon-sysfs.h>
24 #include <linux/clk-provider.h>
29 * We can't determine type by probing, but if we expect pre-Linux code
31 * setting the date and time), Linux can ignore the non-clock features.
56 #define DS1307_REG_SECS 0x00 /* 00-59 */
60 #define DS1307_REG_MIN 0x01 /* 00-59 */
62 #define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */
67 #define DS1307_REG_WDAY 0x03 /* 01-07 */
70 #define DS1307_REG_MDAY 0x04 /* 01-31 */
71 #define DS1307_REG_MONTH 0x05 /* 01-12 */
73 #define DS1307_REG_YEAR 0x06 /* 00-99 */
164 /* negative offset step is -2.034ppm */
169 #define M41TXX_MIN_OFFSET ((-31) * M41TXX_NEG_OFFSET_STEP_PPB)
197 /* Does the RTC require trickle-resistor-ohms to select the value of
214 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_get_time()
217 if (ds1307->type == rx_8130) { in ds1307_get_time()
219 ret = regmap_read(ds1307->regmap, RX8130_REG_FLAG, &regflag); in ds1307_get_time()
227 return -EINVAL; in ds1307_get_time()
232 ret = regmap_bulk_read(ds1307->regmap, chip->offset, regs, in ds1307_get_time()
242 if (ds1307->type == m41t0 && in ds1307_get_time()
245 return -EINVAL; in ds1307_get_time()
246 } else if (ds1307->type == mcp794xx && in ds1307_get_time()
249 return -EINVAL; in ds1307_get_time()
253 switch (ds1307->type) { in ds1307_get_time()
259 return -EINVAL; in ds1307_get_time()
264 return -EINVAL; in ds1307_get_time()
266 ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &tmp); in ds1307_get_time()
270 return -EINVAL; in ds1307_get_time()
274 return -EINVAL; in ds1307_get_time()
276 ret = regmap_read(ds1307->regmap, DS1340_REG_FLAG, &tmp); in ds1307_get_time()
280 return -EINVAL; in ds1307_get_time()
283 ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp); in ds1307_get_time()
287 return -EINVAL; in ds1307_get_time()
291 return -EINVAL; in ds1307_get_time()
298 t->tm_sec = bcd2bin(regs[DS1307_REG_SECS] & 0x7f); in ds1307_get_time()
299 t->tm_min = bcd2bin(regs[DS1307_REG_MIN] & 0x7f); in ds1307_get_time()
301 t->tm_hour = bcd2bin(tmp); in ds1307_get_time()
303 if (ds1307->type == rx_8130) in ds1307_get_time()
304 t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f); in ds1307_get_time()
306 t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1; in ds1307_get_time()
307 t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f); in ds1307_get_time()
309 t->tm_mon = bcd2bin(tmp) - 1; in ds1307_get_time()
310 t->tm_year = bcd2bin(regs[DS1307_REG_YEAR]) + 100; in ds1307_get_time()
312 if (regs[chip->century_reg] & chip->century_bit && in ds1307_get_time()
314 t->tm_year += 100; in ds1307_get_time()
318 "read", t->tm_sec, t->tm_min, in ds1307_get_time()
319 t->tm_hour, t->tm_mday, in ds1307_get_time()
320 t->tm_mon, t->tm_year, t->tm_wday); in ds1307_get_time()
328 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_set_time()
335 "write", t->tm_sec, t->tm_min, in ds1307_set_time()
336 t->tm_hour, t->tm_mday, in ds1307_set_time()
337 t->tm_mon, t->tm_year, t->tm_wday); in ds1307_set_time()
339 if (t->tm_year < 100) in ds1307_set_time()
340 return -EINVAL; in ds1307_set_time()
343 if (t->tm_year > (chip->century_bit ? 299 : 199)) in ds1307_set_time()
344 return -EINVAL; in ds1307_set_time()
346 if (t->tm_year > 199) in ds1307_set_time()
347 return -EINVAL; in ds1307_set_time()
350 regs[DS1307_REG_SECS] = bin2bcd(t->tm_sec); in ds1307_set_time()
351 regs[DS1307_REG_MIN] = bin2bcd(t->tm_min); in ds1307_set_time()
352 regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour); in ds1307_set_time()
354 if (ds1307->type == rx_8130) in ds1307_set_time()
355 regs[DS1307_REG_WDAY] = 1 << t->tm_wday; in ds1307_set_time()
357 regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1); in ds1307_set_time()
358 regs[DS1307_REG_MDAY] = bin2bcd(t->tm_mday); in ds1307_set_time()
359 regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1); in ds1307_set_time()
362 tmp = t->tm_year % 100; in ds1307_set_time()
365 if (chip->century_enable_bit) in ds1307_set_time()
366 regs[chip->century_reg] |= chip->century_enable_bit; in ds1307_set_time()
367 if (t->tm_year > 199 && chip->century_bit) in ds1307_set_time()
368 regs[chip->century_reg] |= chip->century_bit; in ds1307_set_time()
370 switch (ds1307->type) { in ds1307_set_time()
373 regmap_update_bits(ds1307->regmap, DS1307_REG_CONTROL, in ds1307_set_time()
377 regmap_update_bits(ds1307->regmap, DS1340_REG_FLAG, in ds1307_set_time()
381 regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, in ds1307_set_time()
399 result = regmap_bulk_write(ds1307->regmap, chip->offset, regs, in ds1307_set_time()
406 if (ds1307->type == rx_8130) { in ds1307_set_time()
408 result = regmap_write(ds1307->regmap, RX8130_REG_FLAG, in ds1307_set_time()
426 ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, in ds1337_read_alarm()
437 * report alarm time (ALARM1); assume 24 hour and day-of-month modes, in ds1337_read_alarm()
440 t->time.tm_sec = bcd2bin(regs[0] & 0x7f); in ds1337_read_alarm()
441 t->time.tm_min = bcd2bin(regs[1] & 0x7f); in ds1337_read_alarm()
442 t->time.tm_hour = bcd2bin(regs[2] & 0x3f); in ds1337_read_alarm()
443 t->time.tm_mday = bcd2bin(regs[3] & 0x3f); in ds1337_read_alarm()
446 t->enabled = !!(regs[7] & DS1337_BIT_A1IE); in ds1337_read_alarm()
447 t->pending = !!(regs[8] & DS1337_BIT_A1I); in ds1337_read_alarm()
451 "alarm read", t->time.tm_sec, t->time.tm_min, in ds1337_read_alarm()
452 t->time.tm_hour, t->time.tm_mday, in ds1337_read_alarm()
453 t->enabled, t->pending); in ds1337_read_alarm()
467 "alarm set", t->time.tm_sec, t->time.tm_min, in ds1337_set_alarm()
468 t->time.tm_hour, t->time.tm_mday, in ds1337_set_alarm()
469 t->enabled, t->pending); in ds1337_set_alarm()
472 ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, in ds1337_set_alarm()
484 /* set ALARM1, using 24 hour and day-of-month modes */ in ds1337_set_alarm()
485 regs[0] = bin2bcd(t->time.tm_sec); in ds1337_set_alarm()
486 regs[1] = bin2bcd(t->time.tm_min); in ds1337_set_alarm()
487 regs[2] = bin2bcd(t->time.tm_hour); in ds1337_set_alarm()
488 regs[3] = bin2bcd(t->time.tm_mday); in ds1337_set_alarm()
490 /* set ALARM2 to non-garbage */ in ds1337_set_alarm()
499 ret = regmap_bulk_write(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, in ds1337_set_alarm()
507 if (t->enabled) { in ds1337_set_alarm()
510 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, regs[7]); in ds1337_set_alarm()
520 return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_alarm_irq_enable()
543 dev_warn(ds1307->dev, in do_trickle_setup_ds1339()
552 /* make sure that the backup battery is enabled */ in do_trickle_setup_rx8130()
566 rtc_lock(ds1307->rtc); in rx8130_irq()
569 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_irq()
578 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_irq()
583 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in rx8130_irq()
586 rtc_unlock(ds1307->rtc); in rx8130_irq()
598 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, in rx8130_read_alarm()
604 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_read_alarm()
609 t->enabled = !!(ctl[2] & RX8130_REG_CONTROL0_AIE); in rx8130_read_alarm()
610 t->pending = !!(ctl[1] & RX8130_REG_FLAG_AF); in rx8130_read_alarm()
612 /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ in rx8130_read_alarm()
613 t->time.tm_sec = -1; in rx8130_read_alarm()
614 t->time.tm_min = bcd2bin(ald[0] & 0x7f); in rx8130_read_alarm()
615 t->time.tm_hour = bcd2bin(ald[1] & 0x7f); in rx8130_read_alarm()
616 t->time.tm_wday = -1; in rx8130_read_alarm()
617 t->time.tm_mday = bcd2bin(ald[2] & 0x7f); in rx8130_read_alarm()
618 t->time.tm_mon = -1; in rx8130_read_alarm()
619 t->time.tm_year = -1; in rx8130_read_alarm()
620 t->time.tm_yday = -1; in rx8130_read_alarm()
621 t->time.tm_isdst = -1; in rx8130_read_alarm()
624 __func__, t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in rx8130_read_alarm()
625 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled); in rx8130_read_alarm()
638 t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in rx8130_set_alarm()
639 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, in rx8130_set_alarm()
640 t->enabled, t->pending); in rx8130_set_alarm()
643 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_set_alarm()
652 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_set_alarm()
658 ald[0] = bin2bcd(t->time.tm_min); in rx8130_set_alarm()
659 ald[1] = bin2bcd(t->time.tm_hour); in rx8130_set_alarm()
660 ald[2] = bin2bcd(t->time.tm_mday); in rx8130_set_alarm()
662 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, in rx8130_set_alarm()
667 if (!t->enabled) in rx8130_set_alarm()
672 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, ctl[2]); in rx8130_set_alarm()
680 ret = regmap_read(ds1307->regmap, RX8130_REG_CONTROL0, &reg); in rx8130_alarm_irq_enable()
689 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg); in rx8130_alarm_irq_enable()
695 struct mutex *lock = &ds1307->rtc->ops_lock; in mcp794xx_irq()
701 ret = regmap_read(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, &reg); in mcp794xx_irq()
707 ret = regmap_write(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, reg); in mcp794xx_irq()
712 ret = regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, in mcp794xx_irq()
717 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in mcp794xx_irq()
732 ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_read_alarm()
737 t->enabled = !!(regs[0] & MCP794XX_BIT_ALM0_EN); in mcp794xx_read_alarm()
739 /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ in mcp794xx_read_alarm()
740 t->time.tm_sec = bcd2bin(regs[3] & 0x7f); in mcp794xx_read_alarm()
741 t->time.tm_min = bcd2bin(regs[4] & 0x7f); in mcp794xx_read_alarm()
742 t->time.tm_hour = bcd2bin(regs[5] & 0x3f); in mcp794xx_read_alarm()
743 t->time.tm_wday = bcd2bin(regs[6] & 0x7) - 1; in mcp794xx_read_alarm()
744 t->time.tm_mday = bcd2bin(regs[7] & 0x3f); in mcp794xx_read_alarm()
745 t->time.tm_mon = bcd2bin(regs[8] & 0x1f) - 1; in mcp794xx_read_alarm()
746 t->time.tm_year = -1; in mcp794xx_read_alarm()
747 t->time.tm_yday = -1; in mcp794xx_read_alarm()
748 t->time.tm_isdst = -1; in mcp794xx_read_alarm()
752 t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in mcp794xx_read_alarm()
753 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled, in mcp794xx_read_alarm()
777 return (tm_now.tm_wday + days_alarm - days_now) % 7 + 1; in mcp794xx_alm_weekday()
786 wday = mcp794xx_alm_weekday(dev, &t->time); in mcp794xx_set_alarm()
792 t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in mcp794xx_set_alarm()
793 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, in mcp794xx_set_alarm()
794 t->enabled, t->pending); in mcp794xx_set_alarm()
797 ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_set_alarm()
802 /* Set alarm 0, using 24-hour and day-of-month modes. */ in mcp794xx_set_alarm()
803 regs[3] = bin2bcd(t->time.tm_sec); in mcp794xx_set_alarm()
804 regs[4] = bin2bcd(t->time.tm_min); in mcp794xx_set_alarm()
805 regs[5] = bin2bcd(t->time.tm_hour); in mcp794xx_set_alarm()
807 regs[7] = bin2bcd(t->time.tm_mday); in mcp794xx_set_alarm()
808 regs[8] = bin2bcd(t->time.tm_mon + 1); in mcp794xx_set_alarm()
817 ret = regmap_bulk_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_set_alarm()
822 if (!t->enabled) in mcp794xx_set_alarm()
825 return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs[0]); in mcp794xx_set_alarm()
832 return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, in mcp794xx_alarm_irq_enable()
843 regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); in m41txx_rtc_read_offset()
851 *offset = -(val * M41TXX_NEG_OFFSET_STEP_PPB); in m41txx_rtc_read_offset()
862 return -ERANGE; in m41txx_rtc_set_offset()
873 return regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, in m41txx_rtc_set_offset()
885 ret = regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, in ds1388_wdt_start()
890 ret = regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_start()
900 regs[1] = bin2bcd(wdt_dev->timeout); in ds1388_wdt_start()
902 ret = regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_start()
907 return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_start()
916 return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_stop()
925 return regmap_bulk_read(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_ping()
935 wdt_dev->timeout = val; in ds1388_wdt_set_timeout()
937 regs[1] = bin2bcd(wdt_dev->timeout); in ds1388_wdt_set_timeout()
939 return regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_set_timeout()
1023 /* this is battery backed SRAM */
1039 /* this is battery backed SRAM */
1046 /* this is battery backed SRAM */
1162 struct mutex *lock = &ds1307->rtc->ops_lock; in ds1307_irq()
1166 ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat); in ds1307_irq()
1172 regmap_write(ds1307->regmap, DS1337_REG_STATUS, stat); in ds1307_irq()
1174 ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_irq()
1179 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in ds1307_irq()
1188 /*----------------------------------------------------------------------*/
1202 struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); in frequency_test_store()
1212 regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT, in frequency_test_store()
1222 struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); in frequency_test_show()
1225 regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); in frequency_test_show()
1245 switch (ds1307->type) { in ds1307_add_frequency_test()
1249 err = rtc_add_group(ds1307->rtc, &rtc_freq_test_attr_group); in ds1307_add_frequency_test()
1260 /*----------------------------------------------------------------------*/
1266 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_nvram_read()
1268 return regmap_bulk_read(ds1307->regmap, chip->nvram_offset + offset, in ds1307_nvram_read()
1276 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_nvram_write()
1278 return regmap_bulk_write(ds1307->regmap, chip->nvram_offset + offset, in ds1307_nvram_write()
1282 /*----------------------------------------------------------------------*/
1288 bool diode = chip->charge_default; in ds1307_trickle_init()
1290 if (!chip->do_trickle_setup) in ds1307_trickle_init()
1293 if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", in ds1307_trickle_init()
1294 &ohms) && chip->requires_trickle_resistor) in ds1307_trickle_init()
1297 /* aux-voltage-chargeable takes precedence over the deprecated in ds1307_trickle_init()
1298 * trickle-diode-disable in ds1307_trickle_init()
1300 if (!device_property_read_u32(ds1307->dev, "aux-voltage-chargeable", in ds1307_trickle_init()
1310 dev_warn(ds1307->dev, in ds1307_trickle_init()
1311 "unsupported aux-voltage-chargeable value\n"); in ds1307_trickle_init()
1314 } else if (device_property_read_bool(ds1307->dev, in ds1307_trickle_init()
1315 "trickle-diode-disable")) { in ds1307_trickle_init()
1319 return chip->do_trickle_setup(ds1307, ohms, diode); in ds1307_trickle_init()
1322 /*----------------------------------------------------------------------*/
1333 * A user-initiated temperature conversion is not started by this function,
1343 ret = regmap_bulk_read(ds1307->regmap, DS3231_REG_TEMPERATURE, in ds3231_hwmon_read_temp()
1348 * Temperature is represented as a 10-bit code with a resolution of in ds3231_hwmon_read_temp()
1383 if (ds1307->type != ds_3231) in ds1307_hwmon_register()
1386 dev = devm_hwmon_device_register_with_groups(ds1307->dev, ds1307->name, in ds1307_hwmon_register()
1390 dev_warn(ds1307->dev, "unable to register hwmon device %ld\n", in ds1307_hwmon_register()
1403 /*----------------------------------------------------------------------*/
1406 * Square-wave output support for DS3231
1430 struct mutex *lock = &ds1307->rtc->ops_lock; in ds1337_write_control()
1434 ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1337_write_control()
1448 ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); in ds3231_clk_sqw_recalc_rate()
1464 for (i = ARRAY_SIZE(ds3231_clk_sqw_rates) - 1; i >= 0; i--) { in ds3231_clk_sqw_round_rate()
1486 return -EINVAL; in ds3231_clk_sqw_set_rate()
1516 ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); in ds3231_clk_sqw_is_prepared()
1540 struct mutex *lock = &ds1307->rtc->ops_lock; in ds3231_clk_32khz_control()
1544 ret = regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS, in ds3231_clk_32khz_control()
1571 ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status); in ds3231_clk_32khz_is_prepared()
1601 struct device_node *node = ds1307->dev->of_node; in ds3231_clks_register()
1605 onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL); in ds3231_clks_register()
1607 return -ENOMEM; in ds3231_clks_register()
1609 onecell->clk_num = ARRAY_SIZE(ds3231_clks_init); in ds3231_clks_register()
1610 onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num, in ds3231_clks_register()
1611 sizeof(onecell->clks[0]), GFP_KERNEL); in ds3231_clks_register()
1612 if (!onecell->clks) in ds3231_clks_register()
1613 return -ENOMEM; in ds3231_clks_register()
1616 device_property_read_string_array(ds1307->dev, "clock-output-names", in ds3231_clks_register()
1624 * Interrupt signal due to alarm conditions and square-wave in ds3231_clks_register()
1627 if (i == DS3231_CLK_SQW && test_bit(RTC_FEATURE_ALARM, ds1307->rtc->features)) in ds3231_clks_register()
1631 ds1307->clks[i].init = &init; in ds3231_clks_register()
1633 onecell->clks[i] = devm_clk_register(ds1307->dev, in ds3231_clks_register()
1634 &ds1307->clks[i]); in ds3231_clks_register()
1635 if (IS_ERR(onecell->clks[i])) in ds3231_clks_register()
1636 return PTR_ERR(onecell->clks[i]); in ds3231_clks_register()
1649 if (ds1307->type != ds_3231) in ds1307_clks_register()
1654 dev_warn(ds1307->dev, "unable to register clock device %d\n", in ds1307_clks_register()
1688 if (ds1307->type != ds_1388) in ds1307_wdt_register()
1691 wdt = devm_kzalloc(ds1307->dev, sizeof(*wdt), GFP_KERNEL); in ds1307_wdt_register()
1695 err = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &val); in ds1307_wdt_register()
1697 wdt->bootstatus = WDIOF_CARDRESET; in ds1307_wdt_register()
1699 wdt->info = &ds1388_wdt_info; in ds1307_wdt_register()
1700 wdt->ops = &ds1388_wdt_ops; in ds1307_wdt_register()
1701 wdt->timeout = 99; in ds1307_wdt_register()
1702 wdt->max_timeout = 99; in ds1307_wdt_register()
1703 wdt->min_timeout = 1; in ds1307_wdt_register()
1705 watchdog_init_timeout(wdt, 0, ds1307->dev); in ds1307_wdt_register()
1707 devm_watchdog_register_device(ds1307->dev, wdt); in ds1307_wdt_register()
1725 int err = -ENODEV; in ds1307_probe()
1731 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); in ds1307_probe()
1734 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); in ds1307_probe()
1736 return -ENOMEM; in ds1307_probe()
1738 dev_set_drvdata(&client->dev, ds1307); in ds1307_probe()
1739 ds1307->dev = &client->dev; in ds1307_probe()
1740 ds1307->name = client->name; in ds1307_probe()
1742 ds1307->regmap = devm_regmap_init_i2c(client, &regmap_config); in ds1307_probe()
1743 if (IS_ERR(ds1307->regmap)) { in ds1307_probe()
1744 dev_err(ds1307->dev, "regmap allocation failed\n"); in ds1307_probe()
1745 return PTR_ERR(ds1307->regmap); in ds1307_probe()
1750 match = device_get_match_data(&client->dev); in ds1307_probe()
1752 ds1307->type = (uintptr_t)match; in ds1307_probe()
1753 chip = &chips[ds1307->type]; in ds1307_probe()
1755 chip = &chips[id->driver_data]; in ds1307_probe()
1756 ds1307->type = id->driver_data; in ds1307_probe()
1758 return -ENODEV; in ds1307_probe()
1761 want_irq = client->irq > 0 && chip->alarm; in ds1307_probe()
1765 else if (pdata->trickle_charger_setup) in ds1307_probe()
1766 trickle_charger_setup = pdata->trickle_charger_setup; in ds1307_probe()
1768 if (trickle_charger_setup && chip->trickle_charger_reg) { in ds1307_probe()
1769 dev_dbg(ds1307->dev, in ds1307_probe()
1771 trickle_charger_setup, chip->trickle_charger_reg); in ds1307_probe()
1772 regmap_write(ds1307->regmap, chip->trickle_charger_reg, in ds1307_probe()
1779 * the device's .dts file using the "wakeup-source" boolean property. in ds1307_probe()
1780 * If the "wakeup-source" property is set, don't request an IRQ. in ds1307_probe()
1784 if (chip->alarm && device_property_read_bool(&client->dev, "wakeup-source")) in ds1307_probe()
1787 switch (ds1307->type) { in ds1307_probe()
1793 err = regmap_bulk_read(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_probe()
1796 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1805 * Using IRQ or defined as wakeup-source? in ds1307_probe()
1811 regs[0] |= DS1337_BIT_INTCN | chip->bbsqi_bit; in ds1307_probe()
1815 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_probe()
1820 regmap_write(ds1307->regmap, DS1337_REG_STATUS, in ds1307_probe()
1822 dev_warn(ds1307->dev, "SET TIME!\n"); in ds1307_probe()
1827 err = regmap_bulk_read(ds1307->regmap, in ds1307_probe()
1830 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1837 regmap_write(ds1307->regmap, in ds1307_probe()
1840 dev_warn(ds1307->dev, in ds1307_probe()
1841 "oscillator stop detected - SET TIME!\n"); in ds1307_probe()
1846 regmap_write(ds1307->regmap, in ds1307_probe()
1849 dev_warn(ds1307->dev, "power-on detected\n"); in ds1307_probe()
1854 regmap_write(ds1307->regmap, in ds1307_probe()
1857 dev_warn(ds1307->dev, "voltage drop detected\n"); in ds1307_probe()
1865 regmap_write(ds1307->regmap, in ds1307_probe()
1869 err = regmap_bulk_read(ds1307->regmap, in ds1307_probe()
1873 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1884 regmap_write(ds1307->regmap, in ds1307_probe()
1889 err = regmap_read(ds1307->regmap, DS1388_REG_CONTROL, &tmp); in ds1307_probe()
1891 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1898 regmap_write(ds1307->regmap, DS1388_REG_CONTROL, tmp); in ds1307_probe()
1906 err = regmap_bulk_read(ds1307->regmap, chip->offset, regs, in ds1307_probe()
1909 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1913 if (ds1307->type == mcp794xx && in ds1307_probe()
1915 regmap_write(ds1307->regmap, DS1307_REG_WDAY, in ds1307_probe()
1921 switch (ds1307->type) { in ds1307_probe()
1938 * Be sure we're in 24 hour mode. Multi-master systems in ds1307_probe()
1946 regmap_write(ds1307->regmap, chip->offset + DS1307_REG_HOUR, in ds1307_probe()
1950 ds1307->rtc = devm_rtc_allocate_device(ds1307->dev); in ds1307_probe()
1951 if (IS_ERR(ds1307->rtc)) in ds1307_probe()
1952 return PTR_ERR(ds1307->rtc); in ds1307_probe()
1955 device_set_wakeup_capable(ds1307->dev, true); in ds1307_probe()
1957 clear_bit(RTC_FEATURE_ALARM, ds1307->rtc->features); in ds1307_probe()
1960 dev_info(ds1307->dev, in ds1307_probe()
1961 "'wakeup-source' is set, request for an IRQ is disabled!\n"); in ds1307_probe()
1963 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, ds1307->rtc->features); in ds1307_probe()
1967 err = devm_request_threaded_irq(ds1307->dev, client->irq, NULL, in ds1307_probe()
1968 chip->irq_handler ?: ds1307_irq, in ds1307_probe()
1970 ds1307->name, ds1307); in ds1307_probe()
1972 client->irq = 0; in ds1307_probe()
1973 device_set_wakeup_capable(ds1307->dev, false); in ds1307_probe()
1974 clear_bit(RTC_FEATURE_ALARM, ds1307->rtc->features); in ds1307_probe()
1975 dev_err(ds1307->dev, "unable to request IRQ!\n"); in ds1307_probe()
1977 dev_dbg(ds1307->dev, "got IRQ %d\n", client->irq); in ds1307_probe()
1981 ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; in ds1307_probe()
1986 err = devm_rtc_register_device(ds1307->rtc); in ds1307_probe()
1990 if (chip->nvram_size) { in ds1307_probe()
1995 .size = chip->nvram_size, in ds1307_probe()
2001 devm_rtc_nvmem_register(ds1307->rtc, &nvmem_cfg); in ds1307_probe()
2016 .name = "rtc-ds1307",