Lines Matching +full:spi +full:- +full:based

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/rtc/rtc-rx4581.c
6 * Based on:
7 * drivers/rtc/rtc-max6902.c
12 * Driver for MAX6902 spi RTC
14 * and based on:
15 * drivers/rtc/rtc-rx8581.c
22 * Based on: rtc-pcf8563.c (An I2C driver for the Philips PCF8563 RTC)
23 * Copyright 2005-06 Tower Technologies
31 #include <linux/spi/spi.h>
69 struct spi_device *spi = to_spi_device(dev); in rx4581_set_reg() local
76 return spi_write_then_read(spi, buf, 2, NULL, 0); in rx4581_set_reg()
82 struct spi_device *spi = to_spi_device(dev); in rx4581_get_reg() local
87 return spi_write_then_read(spi, data, 1, data, 1); in rx4581_get_reg()
92 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
96 struct spi_device *spi = to_spi_device(dev); in rx4581_get_datetime() local
102 * time and date then re-read the "update flag". If the update flag in rx4581_get_datetime()
109 return -EIO; in rx4581_get_datetime()
120 return -EIO; in rx4581_get_datetime()
126 err = spi_write_then_read(spi, date, 1, date, 7); in rx4581_get_datetime()
129 return -EIO; in rx4581_get_datetime()
136 return -EIO; in rx4581_get_datetime()
150 tm->tm_sec = bcd2bin(date[RX4581_REG_SC] & 0x7F); in rx4581_get_datetime()
151 tm->tm_min = bcd2bin(date[RX4581_REG_MN] & 0x7F); in rx4581_get_datetime()
152 tm->tm_hour = bcd2bin(date[RX4581_REG_HR] & 0x3F); /* rtc hr 0-23 */ in rx4581_get_datetime()
153 tm->tm_wday = ilog2(date[RX4581_REG_DW] & 0x7F); in rx4581_get_datetime()
154 tm->tm_mday = bcd2bin(date[RX4581_REG_DM] & 0x3F); in rx4581_get_datetime()
155 tm->tm_mon = bcd2bin(date[RX4581_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ in rx4581_get_datetime()
156 tm->tm_year = bcd2bin(date[RX4581_REG_YR]); in rx4581_get_datetime()
157 if (tm->tm_year < 70) in rx4581_get_datetime()
158 tm->tm_year += 100; /* assume we are in 1970...2069 */ in rx4581_get_datetime()
164 tm->tm_sec, tm->tm_min, tm->tm_hour, in rx4581_get_datetime()
165 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); in rx4581_get_datetime()
172 struct spi_device *spi = to_spi_device(dev); in rx4581_set_datetime() local
179 tm->tm_sec, tm->tm_min, tm->tm_hour, in rx4581_set_datetime()
180 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); in rx4581_set_datetime()
184 buf[RX4581_REG_SC+1] = bin2bcd(tm->tm_sec); in rx4581_set_datetime()
185 buf[RX4581_REG_MN+1] = bin2bcd(tm->tm_min); in rx4581_set_datetime()
186 buf[RX4581_REG_HR+1] = bin2bcd(tm->tm_hour); in rx4581_set_datetime()
188 buf[RX4581_REG_DM+1] = bin2bcd(tm->tm_mday); in rx4581_set_datetime()
190 /* month, 1 - 12 */ in rx4581_set_datetime()
191 buf[RX4581_REG_MO+1] = bin2bcd(tm->tm_mon + 1); in rx4581_set_datetime()
194 buf[RX4581_REG_YR+1] = bin2bcd(tm->tm_year % 100); in rx4581_set_datetime()
195 buf[RX4581_REG_DW+1] = (0x1 << tm->tm_wday); in rx4581_set_datetime()
201 return -EIO; in rx4581_set_datetime()
208 return -EIO; in rx4581_set_datetime()
212 err = spi_write_then_read(spi, buf, 8, NULL, 0); in rx4581_set_datetime()
215 return -EIO; in rx4581_set_datetime()
222 return -EIO; in rx4581_set_datetime()
229 return -EIO; in rx4581_set_datetime()
236 return -EIO; in rx4581_set_datetime()
243 return -EIO; in rx4581_set_datetime()
254 static int rx4581_probe(struct spi_device *spi) in rx4581_probe() argument
260 res = rx4581_get_reg(&spi->dev, RX4581_REG_SC, &tmp); in rx4581_probe()
264 rtc = devm_rtc_device_register(&spi->dev, "rx4581", in rx4581_probe()
269 spi_set_drvdata(spi, rtc); in rx4581_probe()
277 MODULE_DEVICE_TABLE(spi, rx4581_id);
281 .name = "rtc-rx4581",
289 MODULE_DESCRIPTION("rx4581 spi RTC driver");
292 MODULE_ALIAS("spi:rtc-rx4581");