Lines Matching +full:trickle +full:- +full:resistor +full:- +full:ohms
1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/clk-provider.h>
230 ret = regmap_bulk_read(max31335->regmap, MAX31335_SECONDS, date, in max31335_read_time()
235 tm->tm_sec = bcd2bin(date[0] & 0x7f); in max31335_read_time()
236 tm->tm_min = bcd2bin(date[1] & 0x7f); in max31335_read_time()
237 tm->tm_hour = bcd2bin(date[2] & 0x3f); in max31335_read_time()
238 tm->tm_wday = bcd2bin(date[3] & 0x7) - 1; in max31335_read_time()
239 tm->tm_mday = bcd2bin(date[4] & 0x3f); in max31335_read_time()
240 tm->tm_mon = bcd2bin(date[5] & 0x1f) - 1; in max31335_read_time()
241 tm->tm_year = bcd2bin(date[6]) + 100; in max31335_read_time()
244 tm->tm_year += 100; in max31335_read_time()
254 date[0] = bin2bcd(tm->tm_sec); in max31335_set_time()
255 date[1] = bin2bcd(tm->tm_min); in max31335_set_time()
256 date[2] = bin2bcd(tm->tm_hour); in max31335_set_time()
257 date[3] = bin2bcd(tm->tm_wday + 1); in max31335_set_time()
258 date[4] = bin2bcd(tm->tm_mday); in max31335_set_time()
259 date[5] = bin2bcd(tm->tm_mon + 1); in max31335_set_time()
260 date[6] = bin2bcd(tm->tm_year % 100); in max31335_set_time()
262 if (tm->tm_year >= 200) in max31335_set_time()
265 return regmap_bulk_write(max31335->regmap, MAX31335_SECONDS, date, in max31335_set_time()
276 ret = regmap_bulk_read(max31335->regmap, MAX31335_ALM1_SEC, regs, in max31335_read_alarm()
281 alrm->time.tm_sec = bcd2bin(regs[0] & 0x7f); in max31335_read_alarm()
282 alrm->time.tm_min = bcd2bin(regs[1] & 0x7f); in max31335_read_alarm()
283 alrm->time.tm_hour = bcd2bin(regs[2] & 0x3f); in max31335_read_alarm()
284 alrm->time.tm_mday = bcd2bin(regs[3] & 0x3f); in max31335_read_alarm()
285 alrm->time.tm_mon = bcd2bin(regs[4] & 0x1f) - 1; in max31335_read_alarm()
286 alrm->time.tm_year = bcd2bin(regs[5]) + 100; in max31335_read_alarm()
293 alrm->time.tm_year += 100; in max31335_read_alarm()
295 ret = regmap_read(max31335->regmap, MAX31335_INT_EN1, &ctrl); in max31335_read_alarm()
299 ret = regmap_read(max31335->regmap, MAX31335_STATUS1, &status); in max31335_read_alarm()
303 alrm->enabled = FIELD_GET(MAX31335_INT_EN1_A1IE, ctrl); in max31335_read_alarm()
304 alrm->pending = FIELD_GET(MAX31335_STATUS1_A1F, status); in max31335_read_alarm()
316 regs[0] = bin2bcd(alrm->time.tm_sec); in max31335_set_alarm()
317 regs[1] = bin2bcd(alrm->time.tm_min); in max31335_set_alarm()
318 regs[2] = bin2bcd(alrm->time.tm_hour); in max31335_set_alarm()
319 regs[3] = bin2bcd(alrm->time.tm_mday); in max31335_set_alarm()
320 regs[4] = bin2bcd(alrm->time.tm_mon + 1); in max31335_set_alarm()
321 regs[5] = bin2bcd(alrm->time.tm_year % 100); in max31335_set_alarm()
323 ret = regmap_bulk_write(max31335->regmap, MAX31335_ALM1_SEC, in max31335_set_alarm()
328 reg = FIELD_PREP(MAX31335_INT_EN1_A1IE, alrm->enabled); in max31335_set_alarm()
329 ret = regmap_update_bits(max31335->regmap, MAX31335_INT_EN1, in max31335_set_alarm()
334 ret = regmap_update_bits(max31335->regmap, MAX31335_STATUS1, in max31335_set_alarm()
344 return regmap_update_bits(max31335->regmap, MAX31335_INT_EN1, in max31335_alarm_irq_enable()
354 ret = regmap_update_bits_check(max31335->regmap, MAX31335_STATUS1, in max31335_handle_irq()
360 rtc_update_irq(max31335->rtc, 1, RTC_AF | RTC_IRQF); in max31335_handle_irq()
376 u32 ohms, chargeable; in max31335_trickle_charger_setup() local
380 if (device_property_read_u32(dev, "aux-voltage-chargeable", in max31335_trickle_charger_setup()
384 if (device_property_read_u32(dev, "trickle-resistor-ohms", &ohms)) in max31335_trickle_charger_setup()
387 if (device_property_read_string(dev, "adi,tc-diode", &diode)) in max31335_trickle_charger_setup()
395 return dev_err_probe(dev, -EINVAL, in max31335_trickle_charger_setup()
396 "Invalid tc-diode value: %s\n", diode); in max31335_trickle_charger_setup()
399 if (ohms == max31335_trickle_resistors[i]) in max31335_trickle_charger_setup()
407 return regmap_write(max31335->regmap, MAX31335_TRICKLE_REG, in max31335_trickle_charger_setup()
421 ret = regmap_read(max31335->regmap, MAX31335_RTC_CONFIG2, ®); in max31335_clkout_recalc_rate()
425 freq_mask = __roundup_pow_of_two(ARRAY_SIZE(max31335_clkout_freq)) - 1; in max31335_clkout_recalc_rate()
450 freq_mask = __roundup_pow_of_two(ARRAY_SIZE(max31335_clkout_freq)) - 1; in max31335_clkout_set_rate()
452 return regmap_update_bits(max31335->regmap, MAX31335_RTC_CONFIG2, in max31335_clkout_set_rate()
460 return regmap_set_bits(max31335->regmap, MAX31335_RTC_CONFIG2, in max31335_clkout_enable()
468 regmap_clear_bits(max31335->regmap, MAX31335_RTC_CONFIG2, in max31335_clkout_disable()
478 ret = regmap_read(max31335->regmap, MAX31335_RTC_CONFIG2, ®); in max31335_clkout_is_enabled()
495 .name = "max31335-clkout",
505 return regmap_bulk_read(max31335->regmap, reg, val, bytes); in max31335_nvmem_reg_read()
514 return regmap_bulk_write(max31335->regmap, reg, val, bytes); in max31335_nvmem_reg_write()
534 return -EOPNOTSUPP; in max31335_read_temp()
536 ret = regmap_bulk_read(max31335->regmap, MAX31335_TEMP_DATA_MSB, in max31335_read_temp()
579 if (!device_property_present(dev, "#clock-cells")) in max31335_clkout_register()
580 return regmap_clear_bits(max31335->regmap, MAX31335_RTC_CONFIG2, in max31335_clkout_register()
583 max31335->clkout.init = &max31335_clk_init; in max31335_clkout_register()
585 ret = devm_clk_hw_register(dev, &max31335->clkout); in max31335_clkout_register()
590 &max31335->clkout); in max31335_clkout_register()
594 max31335->clkout.clk = devm_clk_get_enabled(dev, NULL); in max31335_clkout_register()
595 if (IS_ERR(max31335->clkout.clk)) in max31335_clkout_register()
596 return dev_err_probe(dev, PTR_ERR(max31335->clkout.clk), in max31335_clkout_register()
610 max31335 = devm_kzalloc(&client->dev, sizeof(*max31335), GFP_KERNEL); in max31335_probe()
612 return -ENOMEM; in max31335_probe()
614 max31335->regmap = devm_regmap_init_i2c(client, ®map_config); in max31335_probe()
615 if (IS_ERR(max31335->regmap)) in max31335_probe()
616 return PTR_ERR(max31335->regmap); in max31335_probe()
620 max31335->rtc = devm_rtc_allocate_device(&client->dev); in max31335_probe()
621 if (IS_ERR(max31335->rtc)) in max31335_probe()
622 return PTR_ERR(max31335->rtc); in max31335_probe()
624 max31335->rtc->ops = &max31335_rtc_ops; in max31335_probe()
625 max31335->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in max31335_probe()
626 max31335->rtc->range_max = RTC_TIMESTAMP_END_2199; in max31335_probe()
627 max31335->rtc->alarm_offset_max = 24 * 60 * 60; in max31335_probe()
629 ret = max31335_clkout_register(&client->dev); in max31335_probe()
633 if (client->irq > 0) { in max31335_probe()
634 ret = devm_request_threaded_irq(&client->dev, client->irq, in max31335_probe()
639 dev_warn(&client->dev, in max31335_probe()
641 client->irq = 0; in max31335_probe()
645 if (!client->irq) in max31335_probe()
646 clear_bit(RTC_FEATURE_ALARM, max31335->rtc->features); in max31335_probe()
649 ret = devm_rtc_nvmem_register(max31335->rtc, &max31335_nvmem_cfg); in max31335_probe()
651 return dev_err_probe(&client->dev, ret, in max31335_probe()
655 hwmon = devm_hwmon_device_register_with_info(&client->dev, client->name, in max31335_probe()
660 return dev_err_probe(&client->dev, PTR_ERR(hwmon), in max31335_probe()
664 ret = max31335_trickle_charger_setup(&client->dev, max31335); in max31335_probe()
668 return devm_rtc_register_device(max31335->rtc); in max31335_probe()
687 .name = "rtc-max31335",