Lines Matching refs:ds1307
172 struct ds1307 { struct
195 u8 (*do_trickle_setup)(struct ds1307 *, u32, argument
212 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_get_time() local
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, ®flag); 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()
246 } else if (ds1307->type == mcp794xx && in ds1307_get_time()
253 switch (ds1307->type) { in ds1307_get_time()
266 ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &tmp); in ds1307_get_time()
276 ret = regmap_read(ds1307->regmap, DS1340_REG_FLAG, &tmp); in ds1307_get_time()
283 ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp); in ds1307_get_time()
303 if (ds1307->type == rx_8130) in ds1307_get_time()
327 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_set_time() local
328 const struct chip_desc *chip = &chips[ds1307->type]; in ds1307_set_time()
354 if (ds1307->type == rx_8130) 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()
421 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1337_read_alarm() local
426 ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, in ds1337_read_alarm()
460 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1337_set_alarm() local
472 ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, in ds1337_set_alarm()
499 ret = regmap_bulk_write(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, in ds1337_set_alarm()
510 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, regs[7]); in ds1337_set_alarm()
518 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_alarm_irq_enable() local
520 return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, in ds1307_alarm_irq_enable()
525 static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, u32 ohms, bool diode) in do_trickle_setup_ds1339() argument
543 dev_warn(ds1307->dev, in do_trickle_setup_ds1339()
550 static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode) in do_trickle_setup_rx8130() argument
562 struct ds1307 *ds1307 = dev_id; in rx8130_irq() local
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()
593 struct ds1307 *ds1307 = dev_get_drvdata(dev); in rx8130_read_alarm() local
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()
632 struct ds1307 *ds1307 = dev_get_drvdata(dev); in rx8130_set_alarm() local
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()
662 ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, in rx8130_set_alarm()
672 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, ctl[2]); in rx8130_set_alarm()
677 struct ds1307 *ds1307 = dev_get_drvdata(dev); in rx8130_alarm_irq_enable() local
680 ret = regmap_read(ds1307->regmap, RX8130_REG_CONTROL0, ®); in rx8130_alarm_irq_enable()
689 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg); in rx8130_alarm_irq_enable()
694 struct ds1307 *ds1307 = dev_id; in mcp794xx_irq() local
695 struct mutex *lock = &ds1307->rtc->ops_lock; in mcp794xx_irq()
701 ret = regmap_read(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, ®); 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()
727 struct ds1307 *ds1307 = dev_get_drvdata(dev); in mcp794xx_read_alarm() local
732 ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_read_alarm()
782 struct ds1307 *ds1307 = dev_get_drvdata(dev); in mcp794xx_set_alarm() local
797 ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_set_alarm()
817 ret = regmap_bulk_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs, in mcp794xx_set_alarm()
825 return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs[0]); in mcp794xx_set_alarm()
830 struct ds1307 *ds1307 = dev_get_drvdata(dev); in mcp794xx_alarm_irq_enable() local
832 return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, in mcp794xx_alarm_irq_enable()
839 struct ds1307 *ds1307 = dev_get_drvdata(dev); in m41txx_rtc_read_offset() local
843 regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); in m41txx_rtc_read_offset()
858 struct ds1307 *ds1307 = dev_get_drvdata(dev); in m41txx_rtc_set_offset() local
873 return regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, in m41txx_rtc_set_offset()
881 struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); in ds1388_wdt_start() local
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()
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()
914 struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); in ds1388_wdt_stop() local
916 return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, in ds1388_wdt_stop()
922 struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); in ds1388_wdt_ping() local
925 return regmap_bulk_read(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_ping()
932 struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); in ds1388_wdt_set_timeout() local
939 return regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, in ds1388_wdt_set_timeout()
1161 struct ds1307 *ds1307 = dev_id; in ds1307_irq() local
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()
1202 struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); in frequency_test_store() local
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() local
1225 regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); in frequency_test_show()
1241 static int ds1307_add_frequency_test(struct ds1307 *ds1307) in ds1307_add_frequency_test() argument
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()
1265 struct ds1307 *ds1307 = priv; in ds1307_nvram_read() local
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()
1275 struct ds1307 *ds1307 = priv; in ds1307_nvram_write() local
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()
1284 static u8 ds1307_trickle_init(struct ds1307 *ds1307, in ds1307_trickle_init() argument
1293 if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", 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()
1314 } else if (device_property_read_bool(ds1307->dev, in ds1307_trickle_init()
1319 return chip->do_trickle_setup(ds1307, ohms, diode); in ds1307_trickle_init()
1338 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds3231_hwmon_read_temp() local
1343 ret = regmap_bulk_read(ds1307->regmap, DS3231_REG_TEMPERATURE, in ds3231_hwmon_read_temp()
1379 static void ds1307_hwmon_register(struct ds1307 *ds1307) in ds1307_hwmon_register() argument
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()
1387 ds1307, in ds1307_hwmon_register()
1390 dev_warn(ds1307->dev, "unable to register hwmon device %ld\n", in ds1307_hwmon_register()
1397 static void ds1307_hwmon_register(struct ds1307 *ds1307) in ds1307_hwmon_register() argument
1417 container_of(clk, struct ds1307, clks[DS3231_CLK_SQW])
1419 container_of(clk, struct ds1307, clks[DS3231_CLK_32KHZ])
1428 static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value) in ds1337_write_control() argument
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()
1444 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); in ds3231_clk_sqw_recalc_rate() local
1448 ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); in ds3231_clk_sqw_recalc_rate()
1475 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); in ds3231_clk_sqw_set_rate() local
1493 return ds1337_write_control(ds1307, DS1337_BIT_RS1 | DS1337_BIT_RS2, in ds3231_clk_sqw_set_rate()
1499 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); in ds3231_clk_sqw_prepare() local
1501 return ds1337_write_control(ds1307, DS1337_BIT_INTCN, 0); in ds3231_clk_sqw_prepare()
1506 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); in ds3231_clk_sqw_unprepare() local
1508 ds1337_write_control(ds1307, DS1337_BIT_INTCN, DS1337_BIT_INTCN); in ds3231_clk_sqw_unprepare()
1513 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); in ds3231_clk_sqw_is_prepared() local
1516 ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); in ds3231_clk_sqw_is_prepared()
1538 static int ds3231_clk_32khz_control(struct ds1307 *ds1307, bool enable) in ds3231_clk_32khz_control() argument
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()
1554 struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); in ds3231_clk_32khz_prepare() local
1556 return ds3231_clk_32khz_control(ds1307, true); in ds3231_clk_32khz_prepare()
1561 struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); in ds3231_clk_32khz_unprepare() local
1563 ds3231_clk_32khz_control(ds1307, false); in ds3231_clk_32khz_unprepare()
1568 struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); in ds3231_clk_32khz_is_prepared() local
1571 ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status); in ds3231_clk_32khz_is_prepared()
1599 static int ds3231_clks_register(struct ds1307 *ds1307) in ds3231_clks_register() argument
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()
1610 onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num, in ds3231_clks_register()
1616 device_property_read_string_array(ds1307->dev, "clock-output-names", 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()
1645 static void ds1307_clks_register(struct ds1307 *ds1307) in ds1307_clks_register() argument
1649 if (ds1307->type != ds_3231) in ds1307_clks_register()
1652 ret = ds3231_clks_register(ds1307); in ds1307_clks_register()
1654 dev_warn(ds1307->dev, "unable to register clock device %d\n", in ds1307_clks_register()
1661 static void ds1307_clks_register(struct ds1307 *ds1307) in ds1307_clks_register() argument
1682 static void ds1307_wdt_register(struct ds1307 *ds1307) in ds1307_wdt_register() argument
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()
1705 watchdog_init_timeout(wdt, 0, ds1307->dev); in ds1307_wdt_register()
1706 watchdog_set_drvdata(wdt, ds1307); in ds1307_wdt_register()
1707 devm_watchdog_register_device(ds1307->dev, wdt); in ds1307_wdt_register()
1710 static void ds1307_wdt_register(struct ds1307 *ds1307) in ds1307_wdt_register() argument
1723 struct ds1307 *ds1307; in ds1307_probe() local
1734 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); in ds1307_probe()
1735 if (!ds1307) 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, ®map_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()
1748 i2c_set_clientdata(client, ds1307); in ds1307_probe()
1752 ds1307->type = (uintptr_t)match; in ds1307_probe()
1753 chip = &chips[ds1307->type]; in ds1307_probe()
1756 ds1307->type = id->driver_data; in ds1307_probe()
1764 trickle_charger_setup = ds1307_trickle_init(ds1307, chip); in ds1307_probe()
1769 dev_dbg(ds1307->dev, in ds1307_probe()
1772 regmap_write(ds1307->regmap, chip->trickle_charger_reg, 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()
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()
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()
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()
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()
1970 ds1307->name, ds1307); 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()
1982 err = ds1307_add_frequency_test(ds1307); in ds1307_probe()
1986 err = devm_rtc_register_device(ds1307->rtc); in ds1307_probe()
1998 .priv = ds1307, in ds1307_probe()
2001 devm_rtc_nvmem_register(ds1307->rtc, &nvmem_cfg); in ds1307_probe()
2004 ds1307_hwmon_register(ds1307); in ds1307_probe()
2005 ds1307_clks_register(ds1307); in ds1307_probe()
2006 ds1307_wdt_register(ds1307); in ds1307_probe()