blob: 3b314ce991e5aad4261ef39c2fb896d15bc8c2c3 [file] [log] [blame]
Chris Verges7f3923a2009-09-22 16:46:20 -07001/*
2 * An SPI driver for the Philips PCF2123 RTC
3 * Copyright 2009 Cyber Switching, Inc.
4 *
5 * Author: Chris Verges <chrisv@cyberswitching.com>
6 * Maintainers: http://www.cyberswitching.com
7 *
8 * based on the RS5C348 driver in this same directory.
9 *
10 * Thanks to Christian Pellegrin <chripell@fsfe.org> for
11 * the sysfs contributions to this driver.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 *
17 * Please note that the CS is active high, so platform data
18 * should look something like:
19 *
20 * static struct spi_board_info ek_spi_devices[] = {
Sachin Kamat369015f2013-07-03 15:06:01 -070021 * ...
22 * {
23 * .modalias = "rtc-pcf2123",
24 * .chip_select = 1,
25 * .controller_data = (void *)AT91_PIN_PA10,
Chris Verges7f3923a2009-09-22 16:46:20 -070026 * .max_speed_hz = 1000 * 1000,
27 * .mode = SPI_CS_HIGH,
28 * .bus_num = 0,
29 * },
30 * ...
31 *};
32 *
33 */
34
35#include <linux/bcd.h>
36#include <linux/delay.h>
37#include <linux/device.h>
38#include <linux/errno.h>
39#include <linux/init.h>
40#include <linux/kernel.h>
Joshua Clayton3fc70072015-02-13 14:40:29 -080041#include <linux/of.h>
Chris Verges7f3923a2009-09-22 16:46:20 -070042#include <linux/string.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
Chris Verges7f3923a2009-09-22 16:46:20 -070044#include <linux/rtc.h>
45#include <linux/spi/spi.h>
Paul Gortmaker21138522011-05-27 09:57:25 -040046#include <linux/module.h>
Dylan Howey790d0332019-05-03 19:52:10 +000047#include <linux/regmap.h>
Chris Verges7f3923a2009-09-22 16:46:20 -070048
Joshua Clayton245cb742016-01-04 10:31:19 -080049/* REGISTERS */
Chris Verges7f3923a2009-09-22 16:46:20 -070050#define PCF2123_REG_CTRL1 (0x00) /* Control Register 1 */
51#define PCF2123_REG_CTRL2 (0x01) /* Control Register 2 */
52#define PCF2123_REG_SC (0x02) /* datetime */
53#define PCF2123_REG_MN (0x03)
54#define PCF2123_REG_HR (0x04)
55#define PCF2123_REG_DM (0x05)
56#define PCF2123_REG_DW (0x06)
57#define PCF2123_REG_MO (0x07)
58#define PCF2123_REG_YR (0x08)
Joshua Clayton245cb742016-01-04 10:31:19 -080059#define PCF2123_REG_ALRM_MN (0x09) /* Alarm Registers */
60#define PCF2123_REG_ALRM_HR (0x0a)
61#define PCF2123_REG_ALRM_DM (0x0b)
62#define PCF2123_REG_ALRM_DW (0x0c)
63#define PCF2123_REG_OFFSET (0x0d) /* Clock Rate Offset Register */
64#define PCF2123_REG_TMR_CLKOUT (0x0e) /* Timer Registers */
65#define PCF2123_REG_CTDWN_TMR (0x0f)
Chris Verges7f3923a2009-09-22 16:46:20 -070066
Joshua Clayton245cb742016-01-04 10:31:19 -080067/* PCF2123_REG_CTRL1 BITS */
68#define CTRL1_CLEAR (0) /* Clear */
69#define CTRL1_CORR_INT BIT(1) /* Correction irq enable */
70#define CTRL1_12_HOUR BIT(2) /* 12 hour time */
71#define CTRL1_SW_RESET (BIT(3) | BIT(4) | BIT(6)) /* Software reset */
72#define CTRL1_STOP BIT(5) /* Stop the clock */
73#define CTRL1_EXT_TEST BIT(7) /* External clock test mode */
74
75/* PCF2123_REG_CTRL2 BITS */
76#define CTRL2_TIE BIT(0) /* Countdown timer irq enable */
77#define CTRL2_AIE BIT(1) /* Alarm irq enable */
78#define CTRL2_TF BIT(2) /* Countdown timer flag */
79#define CTRL2_AF BIT(3) /* Alarm flag */
80#define CTRL2_TI_TP BIT(4) /* Irq pin generates pulse */
81#define CTRL2_MSF BIT(5) /* Minute or second irq flag */
82#define CTRL2_SI BIT(6) /* Second irq enable */
83#define CTRL2_MI BIT(7) /* Minute irq enable */
84
85/* PCF2123_REG_SC BITS */
86#define OSC_HAS_STOPPED BIT(7) /* Clock has been stopped */
87
88/* PCF2123_REG_ALRM_XX BITS */
89#define ALRM_ENABLE BIT(7) /* MN, HR, DM, or DW alarm enable */
90
91/* PCF2123_REG_TMR_CLKOUT BITS */
92#define CD_TMR_4096KHZ (0) /* 4096 KHz countdown timer */
93#define CD_TMR_64HZ (1) /* 64 Hz countdown timer */
94#define CD_TMR_1HZ (2) /* 1 Hz countdown timer */
95#define CD_TMR_60th_HZ (3) /* 60th Hz countdown timer */
96#define CD_TMR_TE BIT(3) /* Countdown timer enable */
97
98/* PCF2123_REG_OFFSET BITS */
Martin Kepplinger82df3e02016-04-18 12:17:44 +020099#define OFFSET_SIGN_BIT 6 /* 2's complement sign bit */
Joshua Clayton245cb742016-01-04 10:31:19 -0800100#define OFFSET_COARSE BIT(7) /* Coarse mode offset */
Joshua Claytonbae2f642016-02-05 12:41:13 -0800101#define OFFSET_STEP (2170) /* Offset step in parts per billion */
Dylan Howey790d0332019-05-03 19:52:10 +0000102#define OFFSET_MASK GENMASK(6, 0) /* Offset value */
Joshua Clayton245cb742016-01-04 10:31:19 -0800103
104/* READ/WRITE ADDRESS BITS */
105#define PCF2123_WRITE BIT(4)
106#define PCF2123_READ (BIT(4) | BIT(7))
107
Chris Verges7f3923a2009-09-22 16:46:20 -0700108
109static struct spi_driver pcf2123_driver;
110
Chris Verges7f3923a2009-09-22 16:46:20 -0700111struct pcf2123_plat_data {
112 struct rtc_device *rtc;
Dylan Howey790d0332019-05-03 19:52:10 +0000113 struct regmap *map;
Chris Verges7f3923a2009-09-22 16:46:20 -0700114};
115
Dylan Howey790d0332019-05-03 19:52:10 +0000116static const struct regmap_config pcf2123_regmap_config = {
117 .reg_bits = 8,
118 .val_bits = 8,
119 .read_flag_mask = PCF2123_READ,
120 .write_flag_mask = PCF2123_WRITE,
121 .max_register = PCF2123_REG_CTDWN_TMR,
122};
Joshua Clayton809b4532016-01-04 10:31:21 -0800123
Joshua Claytonbae2f642016-02-05 12:41:13 -0800124static int pcf2123_read_offset(struct device *dev, long *offset)
125{
Dylan Howey790d0332019-05-03 19:52:10 +0000126 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
127 int ret, val;
128 unsigned int reg;
Joshua Claytonbae2f642016-02-05 12:41:13 -0800129
Dylan Howey790d0332019-05-03 19:52:10 +0000130 ret = regmap_read(pdata->map, PCF2123_REG_OFFSET, &reg);
131 if (ret)
Joshua Claytonbae2f642016-02-05 12:41:13 -0800132 return ret;
133
Dylan Howey790d0332019-05-03 19:52:10 +0000134 val = sign_extend32((reg & OFFSET_MASK), OFFSET_SIGN_BIT);
Joshua Claytonbae2f642016-02-05 12:41:13 -0800135
Dylan Howey790d0332019-05-03 19:52:10 +0000136 if (reg & OFFSET_COARSE)
137 val *= 2;
138
139 *offset = ((long)val) * OFFSET_STEP;
Joshua Claytonbae2f642016-02-05 12:41:13 -0800140
141 return 0;
142}
143
144/*
145 * The offset register is a 7 bit signed value with a coarse bit in bit 7.
146 * The main difference between the two is normal offset adjusts the first
147 * second of n minutes every other hour, with 61, 62 and 63 being shoved
148 * into the 60th minute.
149 * The coarse adjustment does the same, but every hour.
150 * the two overlap, with every even normal offset value corresponding
151 * to a coarse offset. Based on this algorithm, it seems that despite the
152 * name, coarse offset is a better fit for overlapping values.
153 */
154static int pcf2123_set_offset(struct device *dev, long offset)
155{
Dylan Howey790d0332019-05-03 19:52:10 +0000156 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
Joshua Claytonbae2f642016-02-05 12:41:13 -0800157 s8 reg;
158
159 if (offset > OFFSET_STEP * 127)
160 reg = 127;
161 else if (offset < OFFSET_STEP * -128)
162 reg = -128;
163 else
164 reg = (s8)((offset + (OFFSET_STEP >> 1)) / OFFSET_STEP);
165
166 /* choose fine offset only for odd values in the normal range */
167 if (reg & 1 && reg <= 63 && reg >= -64) {
168 /* Normal offset. Clear the coarse bit */
169 reg &= ~OFFSET_COARSE;
170 } else {
171 /* Coarse offset. Divide by 2 and set the coarse bit */
172 reg >>= 1;
173 reg |= OFFSET_COARSE;
174 }
175
Dylan Howey790d0332019-05-03 19:52:10 +0000176 return regmap_write(pdata->map, PCF2123_REG_OFFSET, (unsigned int)reg);
Joshua Claytonbae2f642016-02-05 12:41:13 -0800177}
178
Chris Verges7f3923a2009-09-22 16:46:20 -0700179static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
180{
Dylan Howey790d0332019-05-03 19:52:10 +0000181 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
Joshua Clayton66c056d2016-01-04 10:31:20 -0800182 u8 rxbuf[7];
Chris Verges7f3923a2009-09-22 16:46:20 -0700183 int ret;
184
Dylan Howey790d0332019-05-03 19:52:10 +0000185 ret = regmap_bulk_read(pdata->map, PCF2123_REG_SC, rxbuf,
186 sizeof(rxbuf));
187 if (ret)
Chris Verges7f3923a2009-09-22 16:46:20 -0700188 return ret;
Chris Verges7f3923a2009-09-22 16:46:20 -0700189
Joshua Claytonf07fa922016-01-04 10:31:23 -0800190 if (rxbuf[0] & OSC_HAS_STOPPED) {
191 dev_info(dev, "clock was stopped. Time is not valid\n");
192 return -EINVAL;
193 }
194
Chris Verges7f3923a2009-09-22 16:46:20 -0700195 tm->tm_sec = bcd2bin(rxbuf[0] & 0x7F);
196 tm->tm_min = bcd2bin(rxbuf[1] & 0x7F);
197 tm->tm_hour = bcd2bin(rxbuf[2] & 0x3F); /* rtc hr 0-23 */
198 tm->tm_mday = bcd2bin(rxbuf[3] & 0x3F);
199 tm->tm_wday = rxbuf[4] & 0x07;
200 tm->tm_mon = bcd2bin(rxbuf[5] & 0x1F) - 1; /* rtc mn 1-12 */
201 tm->tm_year = bcd2bin(rxbuf[6]);
202 if (tm->tm_year < 70)
203 tm->tm_year += 100; /* assume we are in 1970...2069 */
204
Dylan Howeyc33850b2019-05-03 19:52:12 +0000205 dev_dbg(dev, "%s: tm is %ptR\n", __func__, tm);
Chris Verges7f3923a2009-09-22 16:46:20 -0700206
Alexandre Belloni22652ba2018-02-19 16:23:56 +0100207 return 0;
Chris Verges7f3923a2009-09-22 16:46:20 -0700208}
209
210static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
211{
Dylan Howey790d0332019-05-03 19:52:10 +0000212 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
213 u8 txbuf[7];
Chris Verges7f3923a2009-09-22 16:46:20 -0700214 int ret;
215
Dylan Howeyc33850b2019-05-03 19:52:12 +0000216 dev_dbg(dev, "%s: tm is %ptR\n", __func__, tm);
Chris Verges7f3923a2009-09-22 16:46:20 -0700217
218 /* Stop the counter first */
Dylan Howey790d0332019-05-03 19:52:10 +0000219 ret = regmap_write(pdata->map, PCF2123_REG_CTRL1, CTRL1_STOP);
220 if (ret)
Chris Verges7f3923a2009-09-22 16:46:20 -0700221 return ret;
Chris Verges7f3923a2009-09-22 16:46:20 -0700222
223 /* Set the new time */
Dylan Howey790d0332019-05-03 19:52:10 +0000224 txbuf[0] = bin2bcd(tm->tm_sec & 0x7F);
225 txbuf[1] = bin2bcd(tm->tm_min & 0x7F);
226 txbuf[2] = bin2bcd(tm->tm_hour & 0x3F);
227 txbuf[3] = bin2bcd(tm->tm_mday & 0x3F);
228 txbuf[4] = tm->tm_wday & 0x07;
229 txbuf[5] = bin2bcd((tm->tm_mon + 1) & 0x1F); /* rtc mn 1-12 */
230 txbuf[6] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100);
Chris Verges7f3923a2009-09-22 16:46:20 -0700231
Dylan Howey790d0332019-05-03 19:52:10 +0000232 ret = regmap_bulk_write(pdata->map, PCF2123_REG_SC, txbuf,
233 sizeof(txbuf));
234 if (ret)
Chris Verges7f3923a2009-09-22 16:46:20 -0700235 return ret;
Chris Verges7f3923a2009-09-22 16:46:20 -0700236
237 /* Start the counter */
Dylan Howey790d0332019-05-03 19:52:10 +0000238 ret = regmap_write(pdata->map, PCF2123_REG_CTRL1, CTRL1_CLEAR);
239 if (ret)
Chris Verges7f3923a2009-09-22 16:46:20 -0700240 return ret;
Chris Verges7f3923a2009-09-22 16:46:20 -0700241
242 return 0;
243}
244
Dylan Howeye32e60a2019-05-03 19:52:12 +0000245static int pcf2123_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
246{
247 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
248 u8 rxbuf[4];
249 int ret;
250 unsigned int val = 0;
251
252 ret = regmap_bulk_read(pdata->map, PCF2123_REG_ALRM_MN, rxbuf,
253 sizeof(rxbuf));
254 if (ret)
255 return ret;
256
257 alm->time.tm_min = bcd2bin(rxbuf[0] & 0x7F);
258 alm->time.tm_hour = bcd2bin(rxbuf[1] & 0x3F);
259 alm->time.tm_mday = bcd2bin(rxbuf[2] & 0x3F);
260 alm->time.tm_wday = bcd2bin(rxbuf[3] & 0x07);
261
262 dev_dbg(dev, "%s: alm is %ptR\n", __func__, &alm->time);
263
264 ret = regmap_read(pdata->map, PCF2123_REG_CTRL2, &val);
265 if (ret)
266 return ret;
267
268 alm->enabled = !!(val & CTRL2_AIE);
269
270 return 0;
271}
272
273static int pcf2123_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
274{
275 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
276 u8 txbuf[4];
277 int ret;
278
279 dev_dbg(dev, "%s: alm is %ptR\n", __func__, &alm->time);
280
281 /* Ensure alarm flag is clear */
282 ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AF, 0);
283 if (ret)
284 return ret;
285
286 /* Disable alarm interrupt */
287 ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AIE, 0);
288 if (ret)
289 return ret;
290
291 /* Set new alarm */
292 txbuf[0] = bin2bcd(alm->time.tm_min & 0x7F);
293 txbuf[1] = bin2bcd(alm->time.tm_hour & 0x3F);
294 txbuf[2] = bin2bcd(alm->time.tm_mday & 0x3F);
295 txbuf[3] = bin2bcd(alm->time.tm_wday & 0x07);
296
297 ret = regmap_bulk_write(pdata->map, PCF2123_REG_ALRM_MN, txbuf,
298 sizeof(txbuf));
299 if (ret)
300 return ret;
301
302 /* Enable alarm interrupt */
303 if (alm->enabled) {
304 ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2,
305 CTRL2_AIE, CTRL2_AIE);
306 if (ret)
307 return ret;
308 }
309
310 return 0;
311}
312
313static irqreturn_t pcf2123_rtc_irq(int irq, void *dev)
314{
315 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
316 struct mutex *lock = &pdata->rtc->ops_lock;
317 unsigned int val = 0;
318 int ret = IRQ_NONE;
319
320 mutex_lock(lock);
321 regmap_read(pdata->map, PCF2123_REG_CTRL2, &val);
322
323 /* Alarm? */
324 if (val & CTRL2_AF) {
325 ret = IRQ_HANDLED;
326
327 /* Clear alarm flag */
328 regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AF, 0);
329
330 rtc_update_irq(pdata->rtc, 1, RTC_IRQF | RTC_AF);
331 }
332
333 mutex_unlock(lock);
334
335 return ret;
336}
337
Joshua Clayton1e094b92016-01-04 10:31:22 -0800338static int pcf2123_reset(struct device *dev)
339{
Dylan Howey790d0332019-05-03 19:52:10 +0000340 struct pcf2123_plat_data *pdata = dev_get_platdata(dev);
Joshua Clayton1e094b92016-01-04 10:31:22 -0800341 int ret;
Dylan Howey790d0332019-05-03 19:52:10 +0000342 unsigned int val = 0;
Joshua Clayton1e094b92016-01-04 10:31:22 -0800343
Dylan Howey790d0332019-05-03 19:52:10 +0000344 ret = regmap_write(pdata->map, PCF2123_REG_CTRL1, CTRL1_SW_RESET);
345 if (ret)
Joshua Clayton1e094b92016-01-04 10:31:22 -0800346 return ret;
347
348 /* Stop the counter */
349 dev_dbg(dev, "stopping RTC\n");
Dylan Howey790d0332019-05-03 19:52:10 +0000350 ret = regmap_write(pdata->map, PCF2123_REG_CTRL1, CTRL1_STOP);
351 if (ret)
Joshua Clayton1e094b92016-01-04 10:31:22 -0800352 return ret;
353
354 /* See if the counter was actually stopped */
355 dev_dbg(dev, "checking for presence of RTC\n");
Dylan Howey790d0332019-05-03 19:52:10 +0000356 ret = regmap_read(pdata->map, PCF2123_REG_CTRL1, &val);
357 if (ret)
Joshua Clayton1e094b92016-01-04 10:31:22 -0800358 return ret;
359
Dylan Howey790d0332019-05-03 19:52:10 +0000360 dev_dbg(dev, "received data from RTC (0x%08X)\n", val);
361 if (!(val & CTRL1_STOP))
Joshua Clayton1e094b92016-01-04 10:31:22 -0800362 return -ENODEV;
363
364 /* Start the counter */
Dylan Howey790d0332019-05-03 19:52:10 +0000365 ret = regmap_write(pdata->map, PCF2123_REG_CTRL1, CTRL1_CLEAR);
366 if (ret)
Joshua Clayton1e094b92016-01-04 10:31:22 -0800367 return ret;
368
369 return 0;
370}
371
Chris Verges7f3923a2009-09-22 16:46:20 -0700372static const struct rtc_class_ops pcf2123_rtc_ops = {
373 .read_time = pcf2123_rtc_read_time,
374 .set_time = pcf2123_rtc_set_time,
Joshua Claytonbae2f642016-02-05 12:41:13 -0800375 .read_offset = pcf2123_read_offset,
376 .set_offset = pcf2123_set_offset,
Dylan Howeye32e60a2019-05-03 19:52:12 +0000377 .read_alarm = pcf2123_rtc_read_alarm,
378 .set_alarm = pcf2123_rtc_set_alarm,
Chris Verges7f3923a2009-09-22 16:46:20 -0700379};
380
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800381static int pcf2123_probe(struct spi_device *spi)
Chris Verges7f3923a2009-09-22 16:46:20 -0700382{
383 struct rtc_device *rtc;
Joshua Claytonf07fa922016-01-04 10:31:23 -0800384 struct rtc_time tm;
Chris Verges7f3923a2009-09-22 16:46:20 -0700385 struct pcf2123_plat_data *pdata;
Dylan Howeye32e60a2019-05-03 19:52:12 +0000386 int ret = 0;
Chris Verges7f3923a2009-09-22 16:46:20 -0700387
Jingoo Handd48ccc2013-04-29 16:20:47 -0700388 pdata = devm_kzalloc(&spi->dev, sizeof(struct pcf2123_plat_data),
389 GFP_KERNEL);
Chris Verges7f3923a2009-09-22 16:46:20 -0700390 if (!pdata)
391 return -ENOMEM;
392 spi->dev.platform_data = pdata;
393
Dylan Howey790d0332019-05-03 19:52:10 +0000394 pdata->map = devm_regmap_init_spi(spi, &pcf2123_regmap_config);
395
396 if (IS_ERR(pdata->map)) {
397 dev_err(&spi->dev, "regmap init failed.\n");
398 goto kfree_exit;
399 }
400
Joshua Claytonf07fa922016-01-04 10:31:23 -0800401 ret = pcf2123_rtc_read_time(&spi->dev, &tm);
Joshua Clayton1e094b92016-01-04 10:31:22 -0800402 if (ret < 0) {
Joshua Claytonf07fa922016-01-04 10:31:23 -0800403 ret = pcf2123_reset(&spi->dev);
404 if (ret < 0) {
405 dev_err(&spi->dev, "chip not found\n");
406 goto kfree_exit;
407 }
Chris Verges7f3923a2009-09-22 16:46:20 -0700408 }
409
Chris Verges7f3923a2009-09-22 16:46:20 -0700410 dev_info(&spi->dev, "spiclk %u KHz.\n",
411 (spi->max_speed_hz + 500) / 1000);
412
Chris Verges7f3923a2009-09-22 16:46:20 -0700413 /* Finalize the initialization */
Jingoo Handd48ccc2013-04-29 16:20:47 -0700414 rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
Chris Verges7f3923a2009-09-22 16:46:20 -0700415 &pcf2123_rtc_ops, THIS_MODULE);
416
417 if (IS_ERR(rtc)) {
418 dev_err(&spi->dev, "failed to register.\n");
419 ret = PTR_ERR(rtc);
420 goto kfree_exit;
421 }
422
423 pdata->rtc = rtc;
424
Dylan Howeye32e60a2019-05-03 19:52:12 +0000425 /* Register alarm irq */
426 if (spi->irq > 0) {
427 ret = devm_request_threaded_irq(&spi->dev, spi->irq, NULL,
428 pcf2123_rtc_irq,
429 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
430 pcf2123_driver.driver.name, &spi->dev);
431 if (!ret)
432 device_init_wakeup(&spi->dev, true);
433 else
434 dev_err(&spi->dev, "could not request irq.\n");
435 }
436
437 /* The PCF2123's alarm only has minute accuracy. Must add timer
438 * support to this driver to generate interrupts more than once
439 * per minute.
440 */
441 pdata->rtc->uie_unsupported = 1;
442
Chris Verges7f3923a2009-09-22 16:46:20 -0700443 return 0;
Chris Vergesf3d2570a2009-09-22 16:46:22 -0700444
Chris Verges7f3923a2009-09-22 16:46:20 -0700445kfree_exit:
Chris Verges7f3923a2009-09-22 16:46:20 -0700446 spi->dev.platform_data = NULL;
447 return ret;
448}
449
Joshua Clayton3fc70072015-02-13 14:40:29 -0800450#ifdef CONFIG_OF
451static const struct of_device_id pcf2123_dt_ids[] = {
452 { .compatible = "nxp,rtc-pcf2123", },
Alexandre Belloni3c3d7102018-12-18 22:42:23 +0100453 { .compatible = "microcrystal,rv2123", },
Joshua Clayton3fc70072015-02-13 14:40:29 -0800454 { /* sentinel */ }
455};
456MODULE_DEVICE_TABLE(of, pcf2123_dt_ids);
457#endif
458
Chris Verges7f3923a2009-09-22 16:46:20 -0700459static struct spi_driver pcf2123_driver = {
460 .driver = {
461 .name = "rtc-pcf2123",
Joshua Clayton3fc70072015-02-13 14:40:29 -0800462 .of_match_table = of_match_ptr(pcf2123_dt_ids),
Chris Verges7f3923a2009-09-22 16:46:20 -0700463 },
464 .probe = pcf2123_probe,
Chris Verges7f3923a2009-09-22 16:46:20 -0700465};
466
Axel Lin109e9412012-03-23 15:02:30 -0700467module_spi_driver(pcf2123_driver);
Chris Verges7f3923a2009-09-22 16:46:20 -0700468
469MODULE_AUTHOR("Chris Verges <chrisv@cyberswitching.com>");
470MODULE_DESCRIPTION("NXP PCF2123 RTC driver");
471MODULE_LICENSE("GPL");