Lines Matching +full:trickle +full:- +full:resistor +full:- +full:ohms

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rtc-ds1307.c - RTC driver for some mostly-compatible I2C chips.
22 #include <linux/hwmon-sysfs.h>
23 #include <linux/clk-provider.h>
28 * We can't determine type by probing, but if we expect pre-Linux code
30 * setting the date and time), Linux can ignore the non-clock features.
54 #define DS1307_REG_SECS 0x00 /* 00-59 */
58 #define DS1307_REG_MIN 0x01 /* 00-59 */
60 #define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */
65 #define DS1307_REG_WDAY 0x03 /* 01-07 */
67 #define DS1307_REG_MDAY 0x04 /* 01-31 */
68 #define DS1307_REG_MONTH 0x05 /* 01-12 */
70 #define DS1307_REG_YEAR 0x06 /* 00-99 */
73 * Other registers (control, status, alarms, trickle charge, NVRAM, etc)
161 /* negative offset step is -2.034ppm */
166 #define M41TXX_MIN_OFFSET ((-31) * M41TXX_NEG_OFFSET_STEP_PPB)
197 /* Does the RTC require trickle-resistor-ohms to select the value of
198 * the resistor between Vcc and Vbackup?
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()
249 switch (ds1307->type) { in ds1307_get_time()
255 return -EINVAL; in ds1307_get_time()
260 return -EINVAL; in ds1307_get_time()
262 ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &tmp); in ds1307_get_time()
266 return -EINVAL; in ds1307_get_time()
270 return -EINVAL; in ds1307_get_time()
272 ret = regmap_read(ds1307->regmap, DS1340_REG_FLAG, &tmp); in ds1307_get_time()
276 return -EINVAL; in ds1307_get_time()
279 ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp); in ds1307_get_time()
283 return -EINVAL; in ds1307_get_time()
287 return -EINVAL; in ds1307_get_time()
294 t->tm_sec = bcd2bin(regs[DS1307_REG_SECS] & 0x7f); in ds1307_get_time()
295 t->tm_min = bcd2bin(regs[DS1307_REG_MIN] & 0x7f); in ds1307_get_time()
297 t->tm_hour = bcd2bin(tmp); in ds1307_get_time()
298 t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1; in ds1307_get_time()
299 t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f); in ds1307_get_time()
301 t->tm_mon = bcd2bin(tmp) - 1; in ds1307_get_time()
302 t->tm_year = bcd2bin(regs[DS1307_REG_YEAR]) + 100; in ds1307_get_time()
304 if (regs[chip->century_reg] & chip->century_bit && in ds1307_get_time()
306 t->tm_year += 100; in ds1307_get_time()
310 "read", t->tm_sec, t->tm_min, in ds1307_get_time()
311 t->tm_hour, t->tm_mday, in ds1307_get_time()
312 t->tm_mon, t->tm_year, t->tm_wday); in ds1307_get_time()
320 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_set_time()
327 "write", t->tm_sec, t->tm_min, in ds1307_set_time()
328 t->tm_hour, t->tm_mday, in ds1307_set_time()
329 t->tm_mon, t->tm_year, t->tm_wday); in ds1307_set_time()
331 if (t->tm_year < 100) in ds1307_set_time()
332 return -EINVAL; in ds1307_set_time()
335 if (t->tm_year > (chip->century_bit ? 299 : 199)) in ds1307_set_time()
336 return -EINVAL; in ds1307_set_time()
338 if (t->tm_year > 199) in ds1307_set_time()
339 return -EINVAL; in ds1307_set_time()
342 regs[DS1307_REG_SECS] = bin2bcd(t->tm_sec); in ds1307_set_time()
343 regs[DS1307_REG_MIN] = bin2bcd(t->tm_min); in ds1307_set_time()
344 regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour); in ds1307_set_time()
345 regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1); in ds1307_set_time()
346 regs[DS1307_REG_MDAY] = bin2bcd(t->tm_mday); in ds1307_set_time()
347 regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1); in ds1307_set_time()
350 tmp = t->tm_year - 100; in ds1307_set_time()
353 if (chip->century_enable_bit) in ds1307_set_time()
354 regs[chip->century_reg] |= chip->century_enable_bit; in ds1307_set_time()
355 if (t->tm_year > 199 && chip->century_bit) in ds1307_set_time()
356 regs[chip->century_reg] |= chip->century_bit; in ds1307_set_time()
358 switch (ds1307->type) { in ds1307_set_time()
361 regmap_update_bits(ds1307->regmap, DS1307_REG_CONTROL, in ds1307_set_time()
365 regmap_update_bits(ds1307->regmap, DS1340_REG_FLAG, in ds1307_set_time()
369 regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, in ds1307_set_time()
387 result = regmap_bulk_write(ds1307->regmap, chip->offset, regs, in ds1307_set_time()
394 if (ds1307->type == rx_8130) { in ds1307_set_time()
396 result = regmap_write(ds1307->regmap, RX8130_REG_FLAG, in ds1307_set_time()
413 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1337_read_alarm()
414 return -EINVAL; in ds1337_read_alarm()
417 ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, in ds1337_read_alarm()
428 * report alarm time (ALARM1); assume 24 hour and day-of-month modes, in ds1337_read_alarm()
431 t->time.tm_sec = bcd2bin(regs[0] & 0x7f); in ds1337_read_alarm()
432 t->time.tm_min = bcd2bin(regs[1] & 0x7f); in ds1337_read_alarm()
433 t->time.tm_hour = bcd2bin(regs[2] & 0x3f); in ds1337_read_alarm()
434 t->time.tm_mday = bcd2bin(regs[3] & 0x3f); in ds1337_read_alarm()
437 t->enabled = !!(regs[7] & DS1337_BIT_A1IE); in ds1337_read_alarm()
438 t->pending = !!(regs[8] & DS1337_BIT_A1I); in ds1337_read_alarm()
442 "alarm read", t->time.tm_sec, t->time.tm_min, in ds1337_read_alarm()
443 t->time.tm_hour, t->time.tm_mday, in ds1337_read_alarm()
444 t->enabled, t->pending); in ds1337_read_alarm()
456 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1337_set_alarm()
457 return -EINVAL; in ds1337_set_alarm()
461 "alarm set", t->time.tm_sec, t->time.tm_min, in ds1337_set_alarm()
462 t->time.tm_hour, t->time.tm_mday, in ds1337_set_alarm()
463 t->enabled, t->pending); in ds1337_set_alarm()
466 ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, in ds1337_set_alarm()
478 /* set ALARM1, using 24 hour and day-of-month modes */ in ds1337_set_alarm()
479 regs[0] = bin2bcd(t->time.tm_sec); in ds1337_set_alarm()
480 regs[1] = bin2bcd(t->time.tm_min); in ds1337_set_alarm()
481 regs[2] = bin2bcd(t->time.tm_hour); in ds1337_set_alarm()
482 regs[3] = bin2bcd(t->time.tm_mday); in ds1337_set_alarm()
484 /* set ALARM2 to non-garbage */ in ds1337_set_alarm()
493 ret = regmap_bulk_write(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, in ds1337_set_alarm()
501 if (t->enabled) { in ds1337_set_alarm()
504 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, regs[7]); in ds1337_set_alarm()
514 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1307_alarm_irq_enable()
515 return -ENOTTY; in ds1307_alarm_irq_enable()
517 return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_alarm_irq_enable()
522 static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, u32 ohms, bool diode) in do_trickle_setup_ds1339() argument
529 switch (ohms) { in do_trickle_setup_ds1339()
540 dev_warn(ds1307->dev, in do_trickle_setup_ds1339()
541 "Unsupported ohm value %u in dt\n", ohms); in do_trickle_setup_ds1339()
547 static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode) in do_trickle_setup_rx8130() argument
560 struct mutex *lock = &ds1307->rtc->ops_lock; in rx8130_irq()
567 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_irq()
576 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_irq()
581 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in rx8130_irq()
595 if (!test_bit(HAS_ALARM, &ds1307->flags)) in rx8130_read_alarm()
596 return -EINVAL; in rx8130_read_alarm()
599 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, in rx8130_read_alarm()
605 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_read_alarm()
610 t->enabled = !!(ctl[2] & RX8130_REG_CONTROL0_AIE); in rx8130_read_alarm()
611 t->pending = !!(ctl[1] & RX8130_REG_FLAG_AF); in rx8130_read_alarm()
613 /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ in rx8130_read_alarm()
614 t->time.tm_sec = -1; in rx8130_read_alarm()
615 t->time.tm_min = bcd2bin(ald[0] & 0x7f); in rx8130_read_alarm()
616 t->time.tm_hour = bcd2bin(ald[1] & 0x7f); in rx8130_read_alarm()
617 t->time.tm_wday = -1; in rx8130_read_alarm()
618 t->time.tm_mday = bcd2bin(ald[2] & 0x7f); in rx8130_read_alarm()
619 t->time.tm_mon = -1; in rx8130_read_alarm()
620 t->time.tm_year = -1; in rx8130_read_alarm()
621 t->time.tm_yday = -1; in rx8130_read_alarm()
622 t->time.tm_isdst = -1; in rx8130_read_alarm()
625 __func__, t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in rx8130_read_alarm()
626 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled); in rx8130_read_alarm()
637 if (!test_bit(HAS_ALARM, &ds1307->flags)) in rx8130_set_alarm()
638 return -EINVAL; in rx8130_set_alarm()
642 t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in rx8130_set_alarm()
643 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, in rx8130_set_alarm()
644 t->enabled, t->pending); in rx8130_set_alarm()
647 ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_set_alarm()
656 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, in rx8130_set_alarm()
662 ald[0] = bin2bcd(t->time.tm_min); in rx8130_set_alarm()
663 ald[1] = bin2bcd(t->time.tm_hour); in rx8130_set_alarm()
664 ald[2] = bin2bcd(t->time.tm_mday); in rx8130_set_alarm()
666 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, in rx8130_set_alarm()
671 if (!t->enabled) in rx8130_set_alarm()
676 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, ctl[2]); in rx8130_set_alarm()
684 if (!test_bit(HAS_ALARM, &ds1307->flags)) in rx8130_alarm_irq_enable()
685 return -EINVAL; in rx8130_alarm_irq_enable()
687 ret = regmap_read(ds1307->regmap, RX8130_REG_CONTROL0, &reg); in rx8130_alarm_irq_enable()
696 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg); in rx8130_alarm_irq_enable()
702 struct mutex *lock = &ds1307->rtc->ops_lock; in mcp794xx_irq()
708 ret = regmap_read(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, &reg); in mcp794xx_irq()
714 ret = regmap_write(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, reg); in mcp794xx_irq()
719 ret = regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, in mcp794xx_irq()
724 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in mcp794xx_irq()
738 if (!test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_read_alarm()
739 return -EINVAL; in mcp794xx_read_alarm()
742 ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_read_alarm()
747 t->enabled = !!(regs[0] & MCP794XX_BIT_ALM0_EN); in mcp794xx_read_alarm()
749 /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ in mcp794xx_read_alarm()
750 t->time.tm_sec = bcd2bin(regs[3] & 0x7f); in mcp794xx_read_alarm()
751 t->time.tm_min = bcd2bin(regs[4] & 0x7f); in mcp794xx_read_alarm()
752 t->time.tm_hour = bcd2bin(regs[5] & 0x3f); in mcp794xx_read_alarm()
753 t->time.tm_wday = bcd2bin(regs[6] & 0x7) - 1; in mcp794xx_read_alarm()
754 t->time.tm_mday = bcd2bin(regs[7] & 0x3f); in mcp794xx_read_alarm()
755 t->time.tm_mon = bcd2bin(regs[8] & 0x1f) - 1; in mcp794xx_read_alarm()
756 t->time.tm_year = -1; in mcp794xx_read_alarm()
757 t->time.tm_yday = -1; in mcp794xx_read_alarm()
758 t->time.tm_isdst = -1; in mcp794xx_read_alarm()
762 t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in mcp794xx_read_alarm()
763 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled, in mcp794xx_read_alarm()
787 return (tm_now.tm_wday + days_alarm - days_now) % 7 + 1; in mcp794xx_alm_weekday()
796 if (!test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_set_alarm()
797 return -EINVAL; in mcp794xx_set_alarm()
799 wday = mcp794xx_alm_weekday(dev, &t->time); in mcp794xx_set_alarm()
805 t->time.tm_sec, t->time.tm_min, t->time.tm_hour, in mcp794xx_set_alarm()
806 t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, in mcp794xx_set_alarm()
807 t->enabled, t->pending); in mcp794xx_set_alarm()
810 ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_set_alarm()
815 /* Set alarm 0, using 24-hour and day-of-month modes. */ in mcp794xx_set_alarm()
816 regs[3] = bin2bcd(t->time.tm_sec); in mcp794xx_set_alarm()
817 regs[4] = bin2bcd(t->time.tm_min); in mcp794xx_set_alarm()
818 regs[5] = bin2bcd(t->time.tm_hour); in mcp794xx_set_alarm()
820 regs[7] = bin2bcd(t->time.tm_mday); in mcp794xx_set_alarm()
821 regs[8] = bin2bcd(t->time.tm_mon + 1); in mcp794xx_set_alarm()
830 ret = regmap_bulk_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_set_alarm()
835 if (!t->enabled) in mcp794xx_set_alarm()
838 return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs[0]); in mcp794xx_set_alarm()
845 if (!test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_alarm_irq_enable()
846 return -EINVAL; in mcp794xx_alarm_irq_enable()
848 return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, in mcp794xx_alarm_irq_enable()
859 regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); in m41txx_rtc_read_offset()
867 *offset = -(val * M41TXX_NEG_OFFSET_STEP_PPB); in m41txx_rtc_read_offset()
878 return -ERANGE; in m41txx_rtc_set_offset()
889 return regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, in m41txx_rtc_set_offset()
901 ret = regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, in ds1388_wdt_start()
906 ret = regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_start()
916 regs[1] = bin2bcd(wdt_dev->timeout); in ds1388_wdt_start()
918 ret = regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_start()
923 return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_start()
932 return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_stop()
941 return regmap_bulk_read(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_ping()
951 wdt_dev->timeout = val; in ds1388_wdt_set_timeout()
953 regs[1] = bin2bcd(wdt_dev->timeout); in ds1388_wdt_set_timeout()
955 return regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_set_timeout()
1205 struct mutex *lock = &ds1307->rtc->ops_lock; in ds1307_irq()
1209 ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat); in ds1307_irq()
1215 regmap_write(ds1307->regmap, DS1337_REG_STATUS, stat); in ds1307_irq()
1217 ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_irq()
1222 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in ds1307_irq()
1231 /*----------------------------------------------------------------------*/
1245 struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); in frequency_test_store()
1255 regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT, in frequency_test_store()
1265 struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); in frequency_test_show()
1268 regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); in frequency_test_show()
1289 switch (ds1307->type) { in ds1307_add_frequency_test()
1293 err = rtc_add_group(ds1307->rtc, &rtc_freq_test_attr_group); in ds1307_add_frequency_test()
1304 /*----------------------------------------------------------------------*/
1310 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_nvram_read()
1312 return regmap_bulk_read(ds1307->regmap, chip->nvram_offset + offset, in ds1307_nvram_read()
1320 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_nvram_write()
1322 return regmap_bulk_write(ds1307->regmap, chip->nvram_offset + offset, in ds1307_nvram_write()
1326 /*----------------------------------------------------------------------*/
1331 u32 ohms, chargeable; in ds1307_trickle_init() local
1332 bool diode = chip->charge_default; in ds1307_trickle_init()
1334 if (!chip->do_trickle_setup) in ds1307_trickle_init()
1337 if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", in ds1307_trickle_init()
1338 &ohms) && chip->requires_trickle_resistor) in ds1307_trickle_init()
1341 /* aux-voltage-chargeable takes precedence over the deprecated in ds1307_trickle_init()
1342 * trickle-diode-disable in ds1307_trickle_init()
1344 if (!device_property_read_u32(ds1307->dev, "aux-voltage-chargeable", in ds1307_trickle_init()
1354 dev_warn(ds1307->dev, in ds1307_trickle_init()
1355 "unsupported aux-voltage-chargeable value\n"); in ds1307_trickle_init()
1358 } else if (device_property_read_bool(ds1307->dev, in ds1307_trickle_init()
1359 "trickle-diode-disable")) { in ds1307_trickle_init()
1363 return chip->do_trickle_setup(ds1307, ohms, diode); in ds1307_trickle_init()
1366 /*----------------------------------------------------------------------*/
1377 * A user-initiated temperature conversion is not started by this function,
1387 ret = regmap_bulk_read(ds1307->regmap, DS3231_REG_TEMPERATURE, in ds3231_hwmon_read_temp()
1392 * Temperature is represented as a 10-bit code with a resolution of in ds3231_hwmon_read_temp()
1427 if (ds1307->type != ds_3231) in ds1307_hwmon_register()
1430 dev = devm_hwmon_device_register_with_groups(ds1307->dev, ds1307->name, in ds1307_hwmon_register()
1434 dev_warn(ds1307->dev, "unable to register hwmon device %ld\n", in ds1307_hwmon_register()
1447 /*----------------------------------------------------------------------*/
1450 * Square-wave output support for DS3231
1474 struct mutex *lock = &ds1307->rtc->ops_lock; in ds1337_write_control()
1478 ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1337_write_control()
1492 ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); in ds3231_clk_sqw_recalc_rate()
1508 for (i = ARRAY_SIZE(ds3231_clk_sqw_rates) - 1; i >= 0; i--) { in ds3231_clk_sqw_round_rate()
1530 return -EINVAL; in ds3231_clk_sqw_set_rate()
1560 ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); in ds3231_clk_sqw_is_prepared()
1584 struct mutex *lock = &ds1307->rtc->ops_lock; in ds3231_clk_32khz_control()
1588 ret = regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS, in ds3231_clk_32khz_control()
1615 ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status); in ds3231_clk_32khz_is_prepared()
1642 struct device_node *node = ds1307->dev->of_node; in ds3231_clks_register()
1646 onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL); in ds3231_clks_register()
1648 return -ENOMEM; in ds3231_clks_register()
1650 onecell->clk_num = ARRAY_SIZE(ds3231_clks_init); in ds3231_clks_register()
1651 onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num, in ds3231_clks_register()
1652 sizeof(onecell->clks[0]), GFP_KERNEL); in ds3231_clks_register()
1653 if (!onecell->clks) in ds3231_clks_register()
1654 return -ENOMEM; in ds3231_clks_register()
1660 * Interrupt signal due to alarm conditions and square-wave in ds3231_clks_register()
1663 if (i == DS3231_CLK_SQW && test_bit(HAS_ALARM, &ds1307->flags)) in ds3231_clks_register()
1667 of_property_read_string_index(node, "clock-output-names", i, in ds3231_clks_register()
1669 ds1307->clks[i].init = &init; in ds3231_clks_register()
1671 onecell->clks[i] = devm_clk_register(ds1307->dev, in ds3231_clks_register()
1672 &ds1307->clks[i]); in ds3231_clks_register()
1673 if (IS_ERR(onecell->clks[i])) in ds3231_clks_register()
1674 return PTR_ERR(onecell->clks[i]); in ds3231_clks_register()
1689 if (ds1307->type != ds_3231) in ds1307_clks_register()
1694 dev_warn(ds1307->dev, "unable to register clock device %d\n", in ds1307_clks_register()
1728 if (ds1307->type != ds_1388) in ds1307_wdt_register()
1731 wdt = devm_kzalloc(ds1307->dev, sizeof(*wdt), GFP_KERNEL); in ds1307_wdt_register()
1735 err = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &val); in ds1307_wdt_register()
1737 wdt->bootstatus = WDIOF_CARDRESET; in ds1307_wdt_register()
1739 wdt->info = &ds1388_wdt_info; in ds1307_wdt_register()
1740 wdt->ops = &ds1388_wdt_ops; in ds1307_wdt_register()
1741 wdt->timeout = 99; in ds1307_wdt_register()
1742 wdt->max_timeout = 99; in ds1307_wdt_register()
1743 wdt->min_timeout = 1; in ds1307_wdt_register()
1745 watchdog_init_timeout(wdt, 0, ds1307->dev); in ds1307_wdt_register()
1747 devm_watchdog_register_device(ds1307->dev, wdt); in ds1307_wdt_register()
1764 int err = -ENODEV; in ds1307_probe()
1770 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); in ds1307_probe()
1773 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); in ds1307_probe()
1775 return -ENOMEM; in ds1307_probe()
1777 dev_set_drvdata(&client->dev, ds1307); in ds1307_probe()
1778 ds1307->dev = &client->dev; in ds1307_probe()
1779 ds1307->name = client->name; in ds1307_probe()
1781 ds1307->regmap = devm_regmap_init_i2c(client, &regmap_config); in ds1307_probe()
1782 if (IS_ERR(ds1307->regmap)) { in ds1307_probe()
1783 dev_err(ds1307->dev, "regmap allocation failed\n"); in ds1307_probe()
1784 return PTR_ERR(ds1307->regmap); in ds1307_probe()
1789 if (client->dev.of_node) { in ds1307_probe()
1790 ds1307->type = (enum ds_type) in ds1307_probe()
1791 of_device_get_match_data(&client->dev); in ds1307_probe()
1792 chip = &chips[ds1307->type]; in ds1307_probe()
1794 chip = &chips[id->driver_data]; in ds1307_probe()
1795 ds1307->type = id->driver_data; in ds1307_probe()
1800 ds1307->dev); in ds1307_probe()
1802 return -ENODEV; in ds1307_probe()
1803 chip = &chips[acpi_id->driver_data]; in ds1307_probe()
1804 ds1307->type = acpi_id->driver_data; in ds1307_probe()
1807 want_irq = client->irq > 0 && chip->alarm; in ds1307_probe()
1811 else if (pdata->trickle_charger_setup) in ds1307_probe()
1812 trickle_charger_setup = pdata->trickle_charger_setup; in ds1307_probe()
1814 if (trickle_charger_setup && chip->trickle_charger_reg) { in ds1307_probe()
1815 dev_dbg(ds1307->dev, in ds1307_probe()
1816 "writing trickle charger info 0x%x to 0x%x\n", in ds1307_probe()
1817 trickle_charger_setup, chip->trickle_charger_reg); in ds1307_probe()
1818 regmap_write(ds1307->regmap, chip->trickle_charger_reg, in ds1307_probe()
1826 * the device's .dts file using the "wakeup-source" boolean property. in ds1307_probe()
1827 * If the "wakeup-source" property is set, don't request an IRQ. in ds1307_probe()
1831 if (chip->alarm && of_property_read_bool(client->dev.of_node, in ds1307_probe()
1832 "wakeup-source")) in ds1307_probe()
1836 switch (ds1307->type) { in ds1307_probe()
1842 err = regmap_bulk_read(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_probe()
1845 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1854 * Using IRQ or defined as wakeup-source? in ds1307_probe()
1860 regs[0] |= DS1337_BIT_INTCN | chip->bbsqi_bit; in ds1307_probe()
1864 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_probe()
1869 regmap_write(ds1307->regmap, DS1337_REG_STATUS, in ds1307_probe()
1871 dev_warn(ds1307->dev, "SET TIME!\n"); in ds1307_probe()
1876 err = regmap_bulk_read(ds1307->regmap, in ds1307_probe()
1879 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1886 regmap_write(ds1307->regmap, in ds1307_probe()
1889 dev_warn(ds1307->dev, in ds1307_probe()
1890 "oscillator stop detected - SET TIME!\n"); in ds1307_probe()
1895 regmap_write(ds1307->regmap, in ds1307_probe()
1898 dev_warn(ds1307->dev, "power-on detected\n"); in ds1307_probe()
1903 regmap_write(ds1307->regmap, in ds1307_probe()
1906 dev_warn(ds1307->dev, "voltage drop detected\n"); in ds1307_probe()
1914 regmap_write(ds1307->regmap, in ds1307_probe()
1918 err = regmap_bulk_read(ds1307->regmap, in ds1307_probe()
1922 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1933 regmap_write(ds1307->regmap, in ds1307_probe()
1938 err = regmap_read(ds1307->regmap, DS1388_REG_CONTROL, &tmp); in ds1307_probe()
1940 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1947 regmap_write(ds1307->regmap, DS1388_REG_CONTROL, tmp); in ds1307_probe()
1955 err = regmap_bulk_read(ds1307->regmap, chip->offset, regs, in ds1307_probe()
1958 dev_dbg(ds1307->dev, "read error %d\n", err); in ds1307_probe()
1962 if (ds1307->type == mcp794xx && in ds1307_probe()
1964 regmap_write(ds1307->regmap, DS1307_REG_WDAY, in ds1307_probe()
1970 switch (ds1307->type) { in ds1307_probe()
1987 * Be sure we're in 24 hour mode. Multi-master systems in ds1307_probe()
1995 regmap_write(ds1307->regmap, chip->offset + DS1307_REG_HOUR, in ds1307_probe()
2000 device_set_wakeup_capable(ds1307->dev, true); in ds1307_probe()
2001 set_bit(HAS_ALARM, &ds1307->flags); in ds1307_probe()
2004 ds1307->rtc = devm_rtc_allocate_device(ds1307->dev); in ds1307_probe()
2005 if (IS_ERR(ds1307->rtc)) in ds1307_probe()
2006 return PTR_ERR(ds1307->rtc); in ds1307_probe()
2009 dev_info(ds1307->dev, in ds1307_probe()
2010 "'wakeup-source' is set, request for an IRQ is disabled!\n"); in ds1307_probe()
2012 ds1307->rtc->uie_unsupported = 1; in ds1307_probe()
2016 err = devm_request_threaded_irq(ds1307->dev, client->irq, NULL, in ds1307_probe()
2017 chip->irq_handler ?: ds1307_irq, in ds1307_probe()
2019 ds1307->name, ds1307); in ds1307_probe()
2021 client->irq = 0; in ds1307_probe()
2022 device_set_wakeup_capable(ds1307->dev, false); in ds1307_probe()
2023 clear_bit(HAS_ALARM, &ds1307->flags); in ds1307_probe()
2024 dev_err(ds1307->dev, "unable to request IRQ!\n"); in ds1307_probe()
2026 dev_dbg(ds1307->dev, "got IRQ %d\n", client->irq); in ds1307_probe()
2030 ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; in ds1307_probe()
2035 err = rtc_register_device(ds1307->rtc); in ds1307_probe()
2039 if (chip->nvram_size) { in ds1307_probe()
2044 .size = chip->nvram_size, in ds1307_probe()
2050 ds1307->rtc->nvram_old_abi = true; in ds1307_probe()
2051 rtc_nvmem_register(ds1307->rtc, &nvmem_cfg); in ds1307_probe()
2066 .name = "rtc-ds1307",