Lines Matching +full:quartz +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>
27 * PCF85063A -- Rev. 6 — 18 November 2015
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
86 rc = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_SC, regs, in pcf85063_rtc_read_time()
93 dev_warn(&pcf85063->rtc->dev, "Power loss detected, invalid time\n"); in pcf85063_rtc_read_time()
94 return -EINVAL; in pcf85063_rtc_read_time()
97 tm->tm_sec = bcd2bin(regs[0] & 0x7F); in pcf85063_rtc_read_time()
98 tm->tm_min = bcd2bin(regs[1] & 0x7F); in pcf85063_rtc_read_time()
99 tm->tm_hour = bcd2bin(regs[2] & 0x3F); /* rtc hr 0-23 */ in pcf85063_rtc_read_time()
100 tm->tm_mday = bcd2bin(regs[3] & 0x3F); in pcf85063_rtc_read_time()
101 tm->tm_wday = regs[4] & 0x07; in pcf85063_rtc_read_time()
102 tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */ in pcf85063_rtc_read_time()
103 tm->tm_year = bcd2bin(regs[6]); in pcf85063_rtc_read_time()
104 tm->tm_year += 100; in pcf85063_rtc_read_time()
119 rc = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1, in pcf85063_rtc_set_time()
126 regs[0] = bin2bcd(tm->tm_sec) & 0x7F; /* clear OS flag */ in pcf85063_rtc_set_time()
128 regs[1] = bin2bcd(tm->tm_min); in pcf85063_rtc_set_time()
129 regs[2] = bin2bcd(tm->tm_hour); in pcf85063_rtc_set_time()
131 /* Day of month, 1 - 31 */ in pcf85063_rtc_set_time()
132 regs[3] = bin2bcd(tm->tm_mday); in pcf85063_rtc_set_time()
134 /* Day, 0 - 6 */ in pcf85063_rtc_set_time()
135 regs[4] = tm->tm_wday & 0x07; in pcf85063_rtc_set_time()
137 /* month, 1 - 12 */ in pcf85063_rtc_set_time()
138 regs[5] = bin2bcd(tm->tm_mon + 1); in pcf85063_rtc_set_time()
141 regs[6] = bin2bcd(tm->tm_year - 100); in pcf85063_rtc_set_time()
144 rc = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_SC, in pcf85063_rtc_set_time()
154 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1, in pcf85063_rtc_set_time()
165 ret = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_ALM_S, in pcf85063_rtc_read_alarm()
170 alrm->time.tm_sec = bcd2bin(buf[0]); in pcf85063_rtc_read_alarm()
171 alrm->time.tm_min = bcd2bin(buf[1]); in pcf85063_rtc_read_alarm()
172 alrm->time.tm_hour = bcd2bin(buf[2]); in pcf85063_rtc_read_alarm()
173 alrm->time.tm_mday = bcd2bin(buf[3]); in pcf85063_rtc_read_alarm()
175 ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val); in pcf85063_rtc_read_alarm()
179 alrm->enabled = !!(val & PCF85063_CTRL2_AIE); in pcf85063_rtc_read_alarm()
190 buf[0] = bin2bcd(alrm->time.tm_sec); in pcf85063_rtc_set_alarm()
191 buf[1] = bin2bcd(alrm->time.tm_min); in pcf85063_rtc_set_alarm()
192 buf[2] = bin2bcd(alrm->time.tm_hour); in pcf85063_rtc_set_alarm()
193 buf[3] = bin2bcd(alrm->time.tm_mday); in pcf85063_rtc_set_alarm()
196 ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_set_alarm()
201 ret = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_ALM_S, in pcf85063_rtc_set_alarm()
206 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_set_alarm()
208 alrm->enabled ? PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF : PCF85063_CTRL2_AF); in pcf85063_rtc_set_alarm()
216 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_alarm_irq_enable()
227 err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val); in pcf85063_rtc_handle_irq()
232 rtc_update_irq(pcf85063->rtc, 1, RTC_IRQF | RTC_AF); in pcf85063_rtc_handle_irq()
233 regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_rtc_handle_irq()
249 ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, &reg); in pcf85063_read_offset()
271 return -ERANGE; in pcf85063_set_offset()
272 if (offset < PCF85063_OFFSET_STEP0 * -64) in pcf85063_set_offset()
273 return -ERANGE; in pcf85063_set_offset()
278 error0 = abs(offset - (mode0 * PCF85063_OFFSET_STEP0)); in pcf85063_set_offset()
279 error1 = abs(offset - (mode1 * PCF85063_OFFSET_STEP1)); in pcf85063_set_offset()
280 if (mode1 > 63 || mode1 < -64 || error0 < error1) in pcf85063_set_offset()
285 return regmap_write(pcf85063->regmap, PCF85063_REG_OFFSET, reg); in pcf85063_set_offset()
296 ret = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &status); in pcf85063_ioctl()
305 return -ENOIOCTLCMD; in pcf85063_ioctl()
344 u32 load = 7000; in pcf85063_load_capacitance() local
348 load = force_cap; in pcf85063_load_capacitance()
350 of_property_read_u32(np, "quartz-load-femtofarads", &load); in pcf85063_load_capacitance()
352 switch (load) { in pcf85063_load_capacitance()
354 dev_warn(&pcf85063->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000", in pcf85063_load_capacitance()
355 load); in pcf85063_load_capacitance()
364 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1, in pcf85063_load_capacitance()
391 int ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); in pcf85063_clkout_recalc_rate()
420 return regmap_update_bits(pcf85063->regmap, in pcf85063_clkout_set_rate()
424 return -EINVAL; in pcf85063_clkout_set_rate()
433 ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, &buf); in pcf85063_clkout_control()
450 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, in pcf85063_clkout_control()
468 int ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); in pcf85063_clkout_is_prepared()
490 init.name = "pcf85063-clkout"; in pcf85063_clkout_register_clk()
495 pcf85063->clkout_hw.init = &init; in pcf85063_clkout_register_clk()
498 of_property_read_string(pcf85063->rtc->dev.of_node, in pcf85063_clkout_register_clk()
499 "clock-output-names", &init.name); in pcf85063_clkout_register_clk()
502 clk = devm_clk_register(&pcf85063->rtc->dev, &pcf85063->clkout_hw); in pcf85063_clkout_register_clk()
505 of_clk_add_provider(pcf85063->rtc->dev.of_node, in pcf85063_clkout_register_clk()
545 const void *data = of_device_get_match_data(&client->dev); in pcf85063_probe()
554 dev_dbg(&client->dev, "%s\n", __func__); in pcf85063_probe()
556 pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063), in pcf85063_probe()
559 return -ENOMEM; in pcf85063_probe()
564 pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap); in pcf85063_probe()
565 if (IS_ERR(pcf85063->regmap)) in pcf85063_probe()
566 return PTR_ERR(pcf85063->regmap); in pcf85063_probe()
570 err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp); in pcf85063_probe()
572 dev_err(&client->dev, "RTC chip is not present\n"); in pcf85063_probe()
576 pcf85063->rtc = devm_rtc_allocate_device(&client->dev); in pcf85063_probe()
577 if (IS_ERR(pcf85063->rtc)) in pcf85063_probe()
578 return PTR_ERR(pcf85063->rtc); in pcf85063_probe()
580 err = pcf85063_load_capacitance(pcf85063, client->dev.of_node, in pcf85063_probe()
581 config->force_cap_7000 ? 7000 : 0); in pcf85063_probe()
583 dev_warn(&client->dev, "failed to set xtal load capacitance: %d", in pcf85063_probe()
586 pcf85063->rtc->ops = &pcf85063_rtc_ops; in pcf85063_probe()
587 pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in pcf85063_probe()
588 pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099; in pcf85063_probe()
589 pcf85063->rtc->uie_unsupported = 1; in pcf85063_probe()
591 if (config->has_alarms && client->irq > 0) { in pcf85063_probe()
592 err = devm_request_threaded_irq(&client->dev, client->irq, in pcf85063_probe()
597 dev_warn(&pcf85063->rtc->dev, in pcf85063_probe()
600 pcf85063->rtc->ops = &pcf85063_rtc_ops_alarm; in pcf85063_probe()
601 device_init_wakeup(&client->dev, true); in pcf85063_probe()
602 err = dev_pm_set_wake_irq(&client->dev, client->irq); in pcf85063_probe()
604 dev_err(&pcf85063->rtc->dev, in pcf85063_probe()
609 nvmem_cfg.priv = pcf85063->regmap; in pcf85063_probe()
610 rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg); in pcf85063_probe()
617 return rtc_register_device(pcf85063->rtc); in pcf85063_probe()
633 .name = "rtc-pcf85063",