Lines Matching +full:xtal +full:- +full:load +full:- +full:femtofarads
1 // SPDX-License-Identifier: GPL-2.0
7 * Maintainers: http://www.nslu2-linux.org/
12 #include <linux/clk-provider.h>
24 * https://www.nxp.com/docs/en/data-sheet/PCF85063A.pdf
25 * https://www.nxp.com/docs/en/data-sheet/PCF85063TP.pdf
27 * PCF85063A -- Rev. 7 — 30 March 2018
28 * PCF85063TP -- Rev. 4 — 6 May 2015
30 * https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8263-C7_App-Manual.pdf
31 * RV8263 -- Rev. 1.0 — January 2019
87 rc = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_SC, regs, in pcf85063_rtc_read_time()
94 dev_warn(&pcf85063->rtc->dev, "Power loss detected, invalid time\n"); in pcf85063_rtc_read_time()
95 return -EINVAL; in pcf85063_rtc_read_time()
98 tm->tm_sec = bcd2bin(regs[0] & 0x7F); in pcf85063_rtc_read_time()
99 tm->tm_min = bcd2bin(regs[1] & 0x7F); in pcf85063_rtc_read_time()
100 tm->tm_hour = bcd2bin(regs[2] & 0x3F); /* rtc hr 0-23 */ in pcf85063_rtc_read_time()
101 tm->tm_mday = bcd2bin(regs[3] & 0x3F); in pcf85063_rtc_read_time()
102 tm->tm_wday = regs[4] & 0x07; in pcf85063_rtc_read_time()
103 tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */ in pcf85063_rtc_read_time()
104 tm->tm_year = bcd2bin(regs[6]); in pcf85063_rtc_read_time()
105 tm->tm_year += 100; in pcf85063_rtc_read_time()
120 rc = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1, in pcf85063_rtc_set_time()
128 regs[0] = bin2bcd(tm->tm_sec) & 0x7F; /* clear OS flag */ in pcf85063_rtc_set_time()
130 regs[1] = bin2bcd(tm->tm_min); in pcf85063_rtc_set_time()
131 regs[2] = bin2bcd(tm->tm_hour); in pcf85063_rtc_set_time()
133 /* Day of month, 1 - 31 */ in pcf85063_rtc_set_time()
134 regs[3] = bin2bcd(tm->tm_mday); in pcf85063_rtc_set_time()
136 /* Day, 0 - 6 */ in pcf85063_rtc_set_time()
137 regs[4] = tm->tm_wday & 0x07; in pcf85063_rtc_set_time()
139 /* month, 1 - 12 */ in pcf85063_rtc_set_time()
140 regs[5] = bin2bcd(tm->tm_mon + 1); in pcf85063_rtc_set_time()
143 regs[6] = bin2bcd(tm->tm_year - 100); in pcf85063_rtc_set_time()
146 rc = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_SC, in pcf85063_rtc_set_time()
156 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1, in pcf85063_rtc_set_time()
167 ret = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_ALM_S, in pcf85063_rtc_read_alarm()
172 alrm->time.tm_sec = bcd2bin(buf[0] & 0x7f); in pcf85063_rtc_read_alarm()
173 alrm->time.tm_min = bcd2bin(buf[1] & 0x7f); in pcf85063_rtc_read_alarm()
174 alrm->time.tm_hour = bcd2bin(buf[2] & 0x3f); in pcf85063_rtc_read_alarm()
175 alrm->time.tm_mday = bcd2bin(buf[3] & 0x3f); in pcf85063_rtc_read_alarm()
177 ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val); in pcf85063_rtc_read_alarm()
181 alrm->enabled = !!(val & PCF85063_CTRL2_AIE); in pcf85063_rtc_read_alarm()
192 buf[0] = bin2bcd(alrm->time.tm_sec); in pcf85063_rtc_set_alarm()
193 buf[1] = bin2bcd(alrm->time.tm_min); in pcf85063_rtc_set_alarm()
194 buf[2] = bin2bcd(alrm->time.tm_hour); in pcf85063_rtc_set_alarm()
195 buf[3] = bin2bcd(alrm->time.tm_mday); in pcf85063_rtc_set_alarm()
198 ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_set_alarm()
203 ret = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_ALM_S, in pcf85063_rtc_set_alarm()
208 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_set_alarm()
210 alrm->enabled ? PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF : PCF85063_CTRL2_AF); in pcf85063_rtc_set_alarm()
218 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_alarm_irq_enable()
229 err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val); in pcf85063_rtc_handle_irq()
234 rtc_update_irq(pcf85063->rtc, 1, RTC_IRQF | RTC_AF); in pcf85063_rtc_handle_irq()
235 regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_handle_irq()
251 ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, ®); in pcf85063_read_offset()
273 return -ERANGE; in pcf85063_set_offset()
274 if (offset < PCF85063_OFFSET_STEP0 * -64) in pcf85063_set_offset()
275 return -ERANGE; in pcf85063_set_offset()
280 error0 = abs(offset - (mode0 * PCF85063_OFFSET_STEP0)); in pcf85063_set_offset()
281 error1 = abs(offset - (mode1 * PCF85063_OFFSET_STEP1)); in pcf85063_set_offset()
282 if (mode1 > 63 || mode1 < -64 || error0 < error1) in pcf85063_set_offset()
287 return regmap_write(pcf85063->regmap, PCF85063_REG_OFFSET, reg); in pcf85063_set_offset()
298 ret = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &status); in pcf85063_ioctl()
307 return -ENOIOCTLCMD; in pcf85063_ioctl()
338 u32 load = 7000; in pcf85063_load_capacitance() local
342 load = force_cap; in pcf85063_load_capacitance()
344 of_property_read_u32(np, "quartz-load-femtofarads", &load); in pcf85063_load_capacitance()
346 switch (load) { in pcf85063_load_capacitance()
348 dev_warn(&pcf85063->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000", in pcf85063_load_capacitance()
349 load); in pcf85063_load_capacitance()
358 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1, in pcf85063_load_capacitance()
385 int ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); in pcf85063_clkout_recalc_rate()
414 return regmap_update_bits(pcf85063->regmap, in pcf85063_clkout_set_rate()
418 return -EINVAL; in pcf85063_clkout_set_rate()
427 ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); in pcf85063_clkout_control()
444 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_clkout_control()
462 int ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); in pcf85063_clkout_is_prepared()
483 struct device_node *node = pcf85063->rtc->dev.parent->of_node; in pcf85063_clkout_register_clk()
497 init.name = "pcf85063-clkout"; in pcf85063_clkout_register_clk()
502 pcf85063->clkout_hw.init = &init; in pcf85063_clkout_register_clk()
505 of_property_read_string(node, "clock-output-names", &init.name); in pcf85063_clkout_register_clk()
508 clk = devm_clk_register(&pcf85063->rtc->dev, &pcf85063->clkout_hw); in pcf85063_clkout_register_clk()
566 dev_dbg(&client->dev, "%s\n", __func__); in pcf85063_probe()
568 pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063), in pcf85063_probe()
571 return -ENOMEM; in pcf85063_probe()
575 return -ENODEV; in pcf85063_probe()
577 pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap); in pcf85063_probe()
578 if (IS_ERR(pcf85063->regmap)) in pcf85063_probe()
579 return PTR_ERR(pcf85063->regmap); in pcf85063_probe()
583 err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp); in pcf85063_probe()
585 dev_err(&client->dev, "RTC chip is not present\n"); in pcf85063_probe()
589 pcf85063->rtc = devm_rtc_allocate_device(&client->dev); in pcf85063_probe()
590 if (IS_ERR(pcf85063->rtc)) in pcf85063_probe()
591 return PTR_ERR(pcf85063->rtc); in pcf85063_probe()
593 err = pcf85063_load_capacitance(pcf85063, client->dev.of_node, in pcf85063_probe()
594 config->force_cap_7000 ? 7000 : 0); in pcf85063_probe()
596 dev_warn(&client->dev, "failed to set xtal load capacitance: %d", in pcf85063_probe()
599 pcf85063->rtc->ops = &pcf85063_rtc_ops; in pcf85063_probe()
600 pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in pcf85063_probe()
601 pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099; in pcf85063_probe()
602 set_bit(RTC_FEATURE_ALARM_RES_2S, pcf85063->rtc->features); in pcf85063_probe()
603 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf85063->rtc->features); in pcf85063_probe()
604 clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); in pcf85063_probe()
606 if (config->has_alarms && client->irq > 0) { in pcf85063_probe()
609 if (dev_fwnode(&client->dev)) in pcf85063_probe()
612 err = devm_request_threaded_irq(&client->dev, client->irq, in pcf85063_probe()
617 dev_warn(&pcf85063->rtc->dev, in pcf85063_probe()
620 set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); in pcf85063_probe()
621 device_init_wakeup(&client->dev, true); in pcf85063_probe()
622 err = dev_pm_set_wake_irq(&client->dev, client->irq); in pcf85063_probe()
624 dev_err(&pcf85063->rtc->dev, in pcf85063_probe()
629 nvmem_cfg.priv = pcf85063->regmap; in pcf85063_probe()
630 devm_rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg); in pcf85063_probe()
637 return devm_rtc_register_device(pcf85063->rtc); in pcf85063_probe()
664 .name = "rtc-pcf85063",