Lines Matching +full:clkout +full:- +full:disable

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright 2005-06 Tower Technologies
7 * Maintainers: http://www.nslu2-linux.org/
11 * https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf
15 #include <linux/clk-provider.h>
92 err = regmap_read(pcf8563->regmap, PCF8563_REG_ST2, &buf); in pcf8563_set_alarm_mode()
103 return regmap_write(pcf8563->regmap, PCF8563_REG_ST2, buf); in pcf8563_set_alarm_mode()
112 err = regmap_read(pcf8563->regmap, PCF8563_REG_ST2, &buf); in pcf8563_get_alarm_mode()
135 rtc_update_irq(pcf8563->rtc, 1, RTC_IRQF | RTC_AF); in pcf8563_irq()
145 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
153 err = regmap_bulk_read(pcf8563->regmap, PCF8563_REG_ST1, buf, in pcf8563_rtc_read_time()
161 return -EINVAL; in pcf8563_rtc_read_time()
172 tm->tm_sec = bcd2bin(buf[PCF8563_REG_SC] & 0x7F); in pcf8563_rtc_read_time()
173 tm->tm_min = bcd2bin(buf[PCF8563_REG_MN] & 0x7F); in pcf8563_rtc_read_time()
174 tm->tm_hour = bcd2bin(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */ in pcf8563_rtc_read_time()
175 tm->tm_mday = bcd2bin(buf[PCF8563_REG_DM] & 0x3F); in pcf8563_rtc_read_time()
176 tm->tm_wday = buf[PCF8563_REG_DW] & 0x07; in pcf8563_rtc_read_time()
177 tm->tm_mon = bcd2bin(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ in pcf8563_rtc_read_time()
178 tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]) + 100; in pcf8563_rtc_read_time()
180 pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ? in pcf8563_rtc_read_time()
181 (tm->tm_year >= 100) : (tm->tm_year < 100); in pcf8563_rtc_read_time()
186 tm->tm_sec, tm->tm_min, tm->tm_hour, in pcf8563_rtc_read_time()
187 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); in pcf8563_rtc_read_time()
200 tm->tm_sec, tm->tm_min, tm->tm_hour, in pcf8563_rtc_set_time()
201 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); in pcf8563_rtc_set_time()
204 buf[PCF8563_REG_SC] = bin2bcd(tm->tm_sec); in pcf8563_rtc_set_time()
205 buf[PCF8563_REG_MN] = bin2bcd(tm->tm_min); in pcf8563_rtc_set_time()
206 buf[PCF8563_REG_HR] = bin2bcd(tm->tm_hour); in pcf8563_rtc_set_time()
208 buf[PCF8563_REG_DM] = bin2bcd(tm->tm_mday); in pcf8563_rtc_set_time()
210 /* month, 1 - 12 */ in pcf8563_rtc_set_time()
211 buf[PCF8563_REG_MO] = bin2bcd(tm->tm_mon + 1); in pcf8563_rtc_set_time()
214 buf[PCF8563_REG_YR] = bin2bcd(tm->tm_year - 100); in pcf8563_rtc_set_time()
215 if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100)) in pcf8563_rtc_set_time()
218 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; in pcf8563_rtc_set_time()
220 return regmap_bulk_write(pcf8563->regmap, PCF8563_REG_SC, in pcf8563_rtc_set_time()
222 sizeof(buf) - PCF8563_REG_SC); in pcf8563_rtc_set_time()
232 ret = regmap_test_bits(pcf8563->regmap, PCF8563_REG_SC, in pcf8563_rtc_ioctl()
240 return -ENOIOCTLCMD; in pcf8563_rtc_ioctl()
250 err = regmap_bulk_read(pcf8563->regmap, PCF8563_REG_AMN, buf, in pcf8563_rtc_read_alarm()
259 tm->time.tm_sec = 0; in pcf8563_rtc_read_alarm()
260 tm->time.tm_min = bcd2bin(buf[0] & 0x7F); in pcf8563_rtc_read_alarm()
261 tm->time.tm_hour = bcd2bin(buf[1] & 0x3F); in pcf8563_rtc_read_alarm()
262 tm->time.tm_mday = bcd2bin(buf[2] & 0x3F); in pcf8563_rtc_read_alarm()
263 tm->time.tm_wday = bcd2bin(buf[3] & 0x7); in pcf8563_rtc_read_alarm()
265 err = pcf8563_get_alarm_mode(pcf8563, &tm->enabled, &tm->pending); in pcf8563_rtc_read_alarm()
270 " enabled=%d, pending=%d\n", __func__, tm->time.tm_min, in pcf8563_rtc_read_alarm()
271 tm->time.tm_hour, tm->time.tm_mday, tm->time.tm_wday, in pcf8563_rtc_read_alarm()
272 tm->enabled, tm->pending); in pcf8563_rtc_read_alarm()
283 buf[0] = bin2bcd(tm->time.tm_min); in pcf8563_rtc_set_alarm()
284 buf[1] = bin2bcd(tm->time.tm_hour); in pcf8563_rtc_set_alarm()
285 buf[2] = bin2bcd(tm->time.tm_mday); in pcf8563_rtc_set_alarm()
286 buf[3] = tm->time.tm_wday & 0x07; in pcf8563_rtc_set_alarm()
288 err = regmap_bulk_write(pcf8563->regmap, PCF8563_REG_SC, buf, in pcf8563_rtc_set_alarm()
293 return pcf8563_set_alarm_mode(pcf8563, !!tm->enabled); in pcf8563_rtc_set_alarm()
306 * Handling of the clkout
325 ret = regmap_read(pcf8563->regmap, PCF8563_REG_CLKO, &buf); in pcf8563_clkout_recalc_rate()
352 ret = regmap_read(pcf8563->regmap, PCF8563_REG_CLKO, &buf); in pcf8563_clkout_set_rate()
360 return regmap_update_bits(pcf8563->regmap, in pcf8563_clkout_set_rate()
366 return -EINVAL; in pcf8563_clkout_set_rate()
375 ret = regmap_read(pcf8563->regmap, PCF8563_REG_CLKO, &buf); in pcf8563_clkout_control()
384 return regmap_update_bits(pcf8563->regmap, PCF8563_REG_CLKO, in pcf8563_clkout_control()
404 ret = regmap_read(pcf8563->regmap, PCF8563_REG_CLKO, &buf); in pcf8563_clkout_is_prepared()
422 struct device_node *node = pcf8563->rtc->dev.of_node; in pcf8563_clkout_register_clk()
427 /* disable the clkout output */ in pcf8563_clkout_register_clk()
428 ret = regmap_clear_bits(pcf8563->regmap, PCF8563_REG_CLKO, in pcf8563_clkout_register_clk()
433 init.name = "pcf8563-clkout"; in pcf8563_clkout_register_clk()
438 pcf8563->clkout_hw.init = &init; in pcf8563_clkout_register_clk()
441 of_property_read_string(node, "clock-output-names", &init.name); in pcf8563_clkout_register_clk()
444 clk = devm_clk_register(&pcf8563->rtc->dev, &pcf8563->clkout_hw); in pcf8563_clkout_register_clk()
473 dev_dbg(&client->dev, "%s\n", __func__); in pcf8563_probe()
475 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in pcf8563_probe()
476 return -ENODEV; in pcf8563_probe()
478 pcf8563 = devm_kzalloc(&client->dev, sizeof(struct pcf8563), in pcf8563_probe()
481 return -ENOMEM; in pcf8563_probe()
483 pcf8563->regmap = devm_regmap_init_i2c(client, &regmap_config); in pcf8563_probe()
484 if (IS_ERR(pcf8563->regmap)) in pcf8563_probe()
485 return PTR_ERR(pcf8563->regmap); in pcf8563_probe()
488 device_set_wakeup_capable(&client->dev, 1); in pcf8563_probe()
491 err = regmap_set_bits(pcf8563->regmap, PCF8563_REG_TMRC, in pcf8563_probe()
494 dev_err(&client->dev, "%s: write error\n", __func__); in pcf8563_probe()
498 /* Clear flags and disable interrupts */ in pcf8563_probe()
499 err = regmap_write(pcf8563->regmap, PCF8563_REG_ST2, 0); in pcf8563_probe()
501 dev_err(&client->dev, "%s: write error\n", __func__); in pcf8563_probe()
505 pcf8563->rtc = devm_rtc_allocate_device(&client->dev); in pcf8563_probe()
506 if (IS_ERR(pcf8563->rtc)) in pcf8563_probe()
507 return PTR_ERR(pcf8563->rtc); in pcf8563_probe()
509 pcf8563->rtc->ops = &pcf8563_rtc_ops; in pcf8563_probe()
511 set_bit(RTC_FEATURE_ALARM_RES_MINUTE, pcf8563->rtc->features); in pcf8563_probe()
512 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf8563->rtc->features); in pcf8563_probe()
513 clear_bit(RTC_FEATURE_ALARM, pcf8563->rtc->features); in pcf8563_probe()
514 pcf8563->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in pcf8563_probe()
515 pcf8563->rtc->range_max = RTC_TIMESTAMP_END_2099; in pcf8563_probe()
516 pcf8563->rtc->set_start_time = true; in pcf8563_probe()
518 if (client->irq > 0) { in pcf8563_probe()
521 if (dev_fwnode(&client->dev)) in pcf8563_probe()
524 err = devm_request_threaded_irq(&client->dev, client->irq, in pcf8563_probe()
529 dev_err(&client->dev, "unable to request IRQ %d\n", in pcf8563_probe()
530 client->irq); in pcf8563_probe()
534 client->irq = 0; in pcf8563_probe()
537 if (client->irq > 0 || device_property_read_bool(&client->dev, "wakeup-source")) { in pcf8563_probe()
538 device_init_wakeup(&client->dev, true); in pcf8563_probe()
539 set_bit(RTC_FEATURE_ALARM, pcf8563->rtc->features); in pcf8563_probe()
542 err = devm_rtc_register_device(pcf8563->rtc); in pcf8563_probe()
575 .name = "rtc-pcf8563",