Lines Matching +full:quartz +full:- +full:load +full:- +full:femtofarads

1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/rtc/rtc-pcf85363.c
5 * Driver for NXP PCF85363 real-time clock.
125 u32 load = 7000; in pcf85363_load_capacitance() local
128 of_property_read_u32(node, "quartz-load-femtofarads", &load); in pcf85363_load_capacitance()
130 switch (load) { in pcf85363_load_capacitance()
132 dev_warn(&pcf85363->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000", in pcf85363_load_capacitance()
133 load); in pcf85363_load_capacitance()
145 return regmap_update_bits(pcf85363->regmap, CTRL_OSCILLATOR, in pcf85363_load_capacitance()
156 ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len); in pcf85363_rtc_read_time()
162 tm->tm_year = bcd2bin(buf[DT_YEARS]); in pcf85363_rtc_read_time()
164 tm->tm_year += 100; in pcf85363_rtc_read_time()
166 tm->tm_wday = buf[DT_WEEKDAYS] & 7; in pcf85363_rtc_read_time()
168 tm->tm_sec = bcd2bin(buf[DT_SECS]); in pcf85363_rtc_read_time()
170 tm->tm_min = bcd2bin(buf[DT_MINUTES]); in pcf85363_rtc_read_time()
171 tm->tm_hour = bcd2bin(buf[DT_HOURS]); in pcf85363_rtc_read_time()
172 tm->tm_mday = bcd2bin(buf[DT_DAYS]); in pcf85363_rtc_read_time()
173 tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1; in pcf85363_rtc_read_time()
189 buf[DT_SECS] = bin2bcd(tm->tm_sec); in pcf85363_rtc_set_time()
190 buf[DT_MINUTES] = bin2bcd(tm->tm_min); in pcf85363_rtc_set_time()
191 buf[DT_HOURS] = bin2bcd(tm->tm_hour); in pcf85363_rtc_set_time()
192 buf[DT_DAYS] = bin2bcd(tm->tm_mday); in pcf85363_rtc_set_time()
193 buf[DT_WEEKDAYS] = tm->tm_wday; in pcf85363_rtc_set_time()
194 buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1); in pcf85363_rtc_set_time()
195 buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); in pcf85363_rtc_set_time()
197 ret = regmap_bulk_write(pcf85363->regmap, CTRL_STOP_EN, in pcf85363_rtc_set_time()
202 ret = regmap_bulk_write(pcf85363->regmap, DT_100THS, in pcf85363_rtc_set_time()
203 buf, sizeof(tmp) - 2); in pcf85363_rtc_set_time()
207 return regmap_write(pcf85363->regmap, CTRL_STOP_EN, 0); in pcf85363_rtc_set_time()
213 unsigned char buf[DT_MONTH_ALM1 - DT_SECOND_ALM1 + 1]; in pcf85363_rtc_read_alarm()
217 ret = regmap_bulk_read(pcf85363->regmap, DT_SECOND_ALM1, buf, in pcf85363_rtc_read_alarm()
222 alrm->time.tm_sec = bcd2bin(buf[0]); in pcf85363_rtc_read_alarm()
223 alrm->time.tm_min = bcd2bin(buf[1]); in pcf85363_rtc_read_alarm()
224 alrm->time.tm_hour = bcd2bin(buf[2]); in pcf85363_rtc_read_alarm()
225 alrm->time.tm_mday = bcd2bin(buf[3]); in pcf85363_rtc_read_alarm()
226 alrm->time.tm_mon = bcd2bin(buf[4]) - 1; in pcf85363_rtc_read_alarm()
228 ret = regmap_read(pcf85363->regmap, CTRL_INTA_EN, &val); in pcf85363_rtc_read_alarm()
232 alrm->enabled = !!(val & INT_A1IE); in pcf85363_rtc_read_alarm()
244 ret = regmap_update_bits(pcf85363->regmap, DT_ALARM_EN, alarm_flags, in _pcf85363_rtc_alarm_irq_enable()
249 ret = regmap_update_bits(pcf85363->regmap, CTRL_INTA_EN, in _pcf85363_rtc_alarm_irq_enable()
256 return regmap_update_bits(pcf85363->regmap, CTRL_FLAGS, FLAGS_A1F, 0); in _pcf85363_rtc_alarm_irq_enable()
270 unsigned char buf[DT_MONTH_ALM1 - DT_SECOND_ALM1 + 1]; in pcf85363_rtc_set_alarm()
273 buf[0] = bin2bcd(alrm->time.tm_sec); in pcf85363_rtc_set_alarm()
274 buf[1] = bin2bcd(alrm->time.tm_min); in pcf85363_rtc_set_alarm()
275 buf[2] = bin2bcd(alrm->time.tm_hour); in pcf85363_rtc_set_alarm()
276 buf[3] = bin2bcd(alrm->time.tm_mday); in pcf85363_rtc_set_alarm()
277 buf[4] = bin2bcd(alrm->time.tm_mon + 1); in pcf85363_rtc_set_alarm()
287 ret = regmap_bulk_write(pcf85363->regmap, DT_SECOND_ALM1, buf, in pcf85363_rtc_set_alarm()
292 return _pcf85363_rtc_alarm_irq_enable(pcf85363, alrm->enabled); in pcf85363_rtc_set_alarm()
301 err = regmap_read(pcf85363->regmap, CTRL_FLAGS, &flags); in pcf85363_rtc_handle_irq()
306 rtc_update_irq(pcf85363->rtc, 1, RTC_IRQF | RTC_AF); in pcf85363_rtc_handle_irq()
307 regmap_update_bits(pcf85363->regmap, CTRL_FLAGS, FLAGS_A1F, 0); in pcf85363_rtc_handle_irq()
327 return regmap_bulk_read(pcf85363->regmap, CTRL_RAM + offset, in pcf85363_nvram_read()
336 return regmap_bulk_write(pcf85363->regmap, CTRL_RAM + offset, in pcf85363_nvram_write()
347 ret = regmap_read(pcf85363->regmap, CTRL_RAMBYTE, &tmp_val); in pcf85x63_nvram_read()
360 return regmap_write(pcf85363->regmap, CTRL_RAMBYTE, in pcf85x63_nvram_write()
386 const void *data = of_device_get_match_data(&client->dev); in pcf85363_probe()
389 .name = "pcf85x63-", in pcf85363_probe()
396 .name = "pcf85363-", in pcf85363_probe()
410 pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), in pcf85363_probe()
413 return -ENOMEM; in pcf85363_probe()
415 pcf85363->regmap = devm_regmap_init_i2c(client, &config->regmap); in pcf85363_probe()
416 if (IS_ERR(pcf85363->regmap)) { in pcf85363_probe()
417 dev_err(&client->dev, "regmap allocation failed\n"); in pcf85363_probe()
418 return PTR_ERR(pcf85363->regmap); in pcf85363_probe()
423 pcf85363->rtc = devm_rtc_allocate_device(&client->dev); in pcf85363_probe()
424 if (IS_ERR(pcf85363->rtc)) in pcf85363_probe()
425 return PTR_ERR(pcf85363->rtc); in pcf85363_probe()
427 err = pcf85363_load_capacitance(pcf85363, client->dev.of_node); in pcf85363_probe()
429 dev_warn(&client->dev, "failed to set xtal load capacitance: %d", in pcf85363_probe()
432 pcf85363->rtc->ops = &rtc_ops; in pcf85363_probe()
433 pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in pcf85363_probe()
434 pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099; in pcf85363_probe()
436 wakeup_source = device_property_read_bool(&client->dev, in pcf85363_probe()
437 "wakeup-source"); in pcf85363_probe()
438 if (client->irq > 0 || wakeup_source) { in pcf85363_probe()
439 regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); in pcf85363_probe()
440 regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, in pcf85363_probe()
444 if (client->irq > 0) { in pcf85363_probe()
447 if (dev_fwnode(&client->dev)) in pcf85363_probe()
449 ret = devm_request_threaded_irq(&client->dev, client->irq, in pcf85363_probe()
454 dev_warn(&client->dev, in pcf85363_probe()
456 client->irq = 0; in pcf85363_probe()
460 if (client->irq > 0 || wakeup_source) { in pcf85363_probe()
461 device_init_wakeup(&client->dev, true); in pcf85363_probe()
462 set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features); in pcf85363_probe()
464 clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features); in pcf85363_probe()
467 ret = devm_rtc_register_device(pcf85363->rtc); in pcf85363_probe()
469 for (i = 0; i < config->num_nvram; i++) { in pcf85363_probe()
471 devm_rtc_nvmem_register(pcf85363->rtc, &nvmem_cfg[i]); in pcf85363_probe()