Lines Matching +full:quartz +full:- +full:load +full:- +full:femtofarads
1 // SPDX-License-Identifier: GPL-2.0-only
26 #define PCF8523_CONTROL3_BLF BIT(2) /* battery low bit, read-only */
57 u32 load, value = 0; in pcf8523_load_capacitance() local
59 load = 12500; in pcf8523_load_capacitance()
60 of_property_read_u32(node, "quartz-load-femtofarads", &load); in pcf8523_load_capacitance()
62 switch (load) { in pcf8523_load_capacitance()
64 dev_warn(&pcf8523->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 12500", in pcf8523_load_capacitance()
65 load); in pcf8523_load_capacitance()
74 return regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1, in pcf8523_load_capacitance()
84 err = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL2, &value); in pcf8523_irq()
90 regmap_write(pcf8523->regmap, PCF8523_REG_CONTROL2, value); in pcf8523_irq()
91 rtc_update_irq(pcf8523->rtc, 1, RTC_IRQF | RTC_AF); in pcf8523_irq()
105 err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_CONTROL1, regs, in pcf8523_rtc_read_time()
111 return -EINVAL; in pcf8523_rtc_read_time()
113 tm->tm_sec = bcd2bin(regs[3] & 0x7f); in pcf8523_rtc_read_time()
114 tm->tm_min = bcd2bin(regs[4] & 0x7f); in pcf8523_rtc_read_time()
115 tm->tm_hour = bcd2bin(regs[5] & 0x3f); in pcf8523_rtc_read_time()
116 tm->tm_mday = bcd2bin(regs[6] & 0x3f); in pcf8523_rtc_read_time()
117 tm->tm_wday = regs[7] & 0x7; in pcf8523_rtc_read_time()
118 tm->tm_mon = bcd2bin(regs[8] & 0x1f) - 1; in pcf8523_rtc_read_time()
119 tm->tm_year = bcd2bin(regs[9]) + 100; in pcf8523_rtc_read_time()
130 err = regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1, in pcf8523_rtc_set_time()
136 regs[0] = bin2bcd(tm->tm_sec); in pcf8523_rtc_set_time()
137 regs[1] = bin2bcd(tm->tm_min); in pcf8523_rtc_set_time()
138 regs[2] = bin2bcd(tm->tm_hour); in pcf8523_rtc_set_time()
139 regs[3] = bin2bcd(tm->tm_mday); in pcf8523_rtc_set_time()
140 regs[4] = tm->tm_wday; in pcf8523_rtc_set_time()
141 regs[5] = bin2bcd(tm->tm_mon + 1); in pcf8523_rtc_set_time()
142 regs[6] = bin2bcd(tm->tm_year - 100); in pcf8523_rtc_set_time()
144 err = regmap_bulk_write(pcf8523->regmap, PCF8523_REG_SECONDS, regs, in pcf8523_rtc_set_time()
152 regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1, in pcf8523_rtc_set_time()
157 return regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1, in pcf8523_rtc_set_time()
168 err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_MINUTE_ALARM, regs, in pcf8523_rtc_read_alarm()
173 tm->time.tm_sec = 0; in pcf8523_rtc_read_alarm()
174 tm->time.tm_min = bcd2bin(regs[0] & 0x7F); in pcf8523_rtc_read_alarm()
175 tm->time.tm_hour = bcd2bin(regs[1] & 0x3F); in pcf8523_rtc_read_alarm()
176 tm->time.tm_mday = bcd2bin(regs[2] & 0x3F); in pcf8523_rtc_read_alarm()
177 tm->time.tm_wday = bcd2bin(regs[3] & 0x7); in pcf8523_rtc_read_alarm()
179 err = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL1, &value); in pcf8523_rtc_read_alarm()
182 tm->enabled = !!(value & PCF8523_CONTROL1_AIE); in pcf8523_rtc_read_alarm()
184 err = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL2, &value); in pcf8523_rtc_read_alarm()
187 tm->pending = !!(value & PCF8523_CONTROL2_AF); in pcf8523_rtc_read_alarm()
196 return regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1, in pcf8523_irq_enable()
211 err = regmap_write(pcf8523->regmap, PCF8523_REG_CONTROL2, 0); in pcf8523_rtc_set_alarm()
215 regs[0] = bin2bcd(tm->time.tm_min); in pcf8523_rtc_set_alarm()
216 regs[1] = bin2bcd(tm->time.tm_hour); in pcf8523_rtc_set_alarm()
217 regs[2] = bin2bcd(tm->time.tm_mday); in pcf8523_rtc_set_alarm()
220 err = regmap_bulk_write(pcf8523->regmap, PCF8523_REG_MINUTE_ALARM, regs, in pcf8523_rtc_set_alarm()
225 if (tm->enabled) in pcf8523_rtc_set_alarm()
226 return pcf8523_irq_enable(dev, tm->enabled); in pcf8523_rtc_set_alarm()
237 switch (param->param) { in pcf8523_param_get()
239 ret = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL3, &value); in pcf8523_param_get()
248 param->uvalue = RTC_BSM_LEVEL; in pcf8523_param_get()
252 param->uvalue = RTC_BSM_DIRECT; in pcf8523_param_get()
255 param->uvalue = RTC_BSM_STANDBY; in pcf8523_param_get()
258 param->uvalue = RTC_BSM_DISABLED; in pcf8523_param_get()
264 return -EINVAL; in pcf8523_param_get()
275 switch (param->param) { in pcf8523_param_set()
277 switch (param->uvalue) { in pcf8523_param_set()
291 return -EINVAL; in pcf8523_param_set()
294 return regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL3, in pcf8523_param_set()
301 return -EINVAL; in pcf8523_param_set()
317 ret = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL3, &value); in pcf8523_rtc_ioctl()
324 ret = regmap_read(pcf8523->regmap, PCF8523_REG_SECONDS, &value); in pcf8523_rtc_ioctl()
334 return -ENOIOCTLCMD; in pcf8523_rtc_ioctl()
345 err = regmap_read(pcf8523->regmap, PCF8523_REG_OFFSET, &value); in pcf8523_rtc_read_offset()
349 /* sign extend the 7-bit offset value */ in pcf8523_rtc_read_offset()
362 reg_m0 = clamp(DIV_ROUND_CLOSEST(offset, 4340), -64L, 63L); in pcf8523_rtc_set_offset()
363 reg_m1 = clamp(DIV_ROUND_CLOSEST(offset, 4069), -64L, 63L); in pcf8523_rtc_set_offset()
365 if (abs(reg_m0 * 4340 - offset) < abs(reg_m1 * 4069 - offset)) in pcf8523_rtc_set_offset()
370 return regmap_write(pcf8523->regmap, PCF8523_REG_OFFSET, value); in pcf8523_rtc_set_offset()
378 if (client->irq > 0 && device_may_wakeup(dev)) in pcf8523_suspend()
379 enable_irq_wake(client->irq); in pcf8523_suspend()
388 if (client->irq > 0 && device_may_wakeup(dev)) in pcf8523_resume()
389 disable_irq_wake(client->irq); in pcf8523_resume()
424 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in pcf8523_probe()
425 return -ENODEV; in pcf8523_probe()
427 pcf8523 = devm_kzalloc(&client->dev, sizeof(struct pcf8523), GFP_KERNEL); in pcf8523_probe()
429 return -ENOMEM; in pcf8523_probe()
431 pcf8523->regmap = devm_regmap_init_i2c(client, ®map_config); in pcf8523_probe()
432 if (IS_ERR(pcf8523->regmap)) in pcf8523_probe()
433 return PTR_ERR(pcf8523->regmap); in pcf8523_probe()
437 rtc = devm_rtc_allocate_device(&client->dev); in pcf8523_probe()
440 pcf8523->rtc = rtc; in pcf8523_probe()
442 err = pcf8523_load_capacitance(pcf8523, client->dev.of_node); in pcf8523_probe()
444 dev_warn(&client->dev, "failed to set xtal load capacitance: %d", in pcf8523_probe()
447 err = regmap_read(pcf8523->regmap, PCF8523_REG_SECONDS, &value); in pcf8523_probe()
452 err = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL3, &value); in pcf8523_probe()
457 err = regmap_write(pcf8523->regmap, PCF8523_REG_CONTROL3, in pcf8523_probe()
464 rtc->ops = &pcf8523_rtc_ops; in pcf8523_probe()
465 rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in pcf8523_probe()
466 rtc->range_max = RTC_TIMESTAMP_END_2099; in pcf8523_probe()
467 set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->features); in pcf8523_probe()
468 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features); in pcf8523_probe()
470 if (client->irq > 0) { in pcf8523_probe()
473 if (dev_fwnode(&client->dev)) in pcf8523_probe()
476 err = regmap_write(pcf8523->regmap, PCF8523_TMR_CLKOUT_CTRL, 0x38); in pcf8523_probe()
480 err = devm_request_threaded_irq(&client->dev, client->irq, in pcf8523_probe()
483 dev_name(&rtc->dev), pcf8523); in pcf8523_probe()
487 dev_pm_set_wake_irq(&client->dev, client->irq); in pcf8523_probe()
490 wakeup_source = of_property_read_bool(client->dev.of_node, "wakeup-source"); in pcf8523_probe()
491 if (client->irq > 0 || wakeup_source) in pcf8523_probe()
492 device_init_wakeup(&client->dev, true); in pcf8523_probe()
512 .name = "rtc-pcf8523",
521 MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");