blob: 7a98e07448783c4dbd343a245d83c73ef3ccf403 [file] [log] [blame]
Krzysztof Kozlowski734c5cd2018-08-07 18:19:18 +02001// SPDX-License-Identifier: GPL-2.0+
2//
3// RTC driver for Maxim MAX77686 and MAX77802
4//
5// Copyright (C) 2012 Samsung Electronics Co.Ltd
6//
7// based on rtc-max8997.c
Jonghwa Leefca1dd02013-02-21 16:44:26 -08008
Laxman Dewanganf3937542016-02-09 22:56:34 +05309#include <linux/i2c.h>
Jonghwa Leefca1dd02013-02-21 16:44:26 -080010#include <linux/slab.h>
11#include <linux/rtc.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/mfd/max77686-private.h>
17#include <linux/irqdomain.h>
18#include <linux/regmap.h>
19
Laxman Dewanganf3937542016-02-09 22:56:34 +053020#define MAX77686_I2C_ADDR_RTC (0x0C >> 1)
Laxman Dewangan726fe732016-03-02 14:06:24 +053021#define MAX77620_I2C_ADDR_RTC 0x68
Laxman Dewanganf3937542016-02-09 22:56:34 +053022#define MAX77686_INVALID_I2C_ADDR (-1)
23
Laxman Dewangan726fe732016-03-02 14:06:24 +053024/* Define non existing register */
25#define MAX77686_INVALID_REG (-1)
26
Jonghwa Leefca1dd02013-02-21 16:44:26 -080027/* RTC Control Register */
28#define BCD_EN_SHIFT 0
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +053029#define BCD_EN_MASK BIT(BCD_EN_SHIFT)
Jonghwa Leefca1dd02013-02-21 16:44:26 -080030#define MODEL24_SHIFT 1
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +053031#define MODEL24_MASK BIT(MODEL24_SHIFT)
Jonghwa Leefca1dd02013-02-21 16:44:26 -080032/* RTC Update Register1 */
33#define RTC_UDR_SHIFT 0
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +053034#define RTC_UDR_MASK BIT(RTC_UDR_SHIFT)
Jonghwa Leefca1dd02013-02-21 16:44:26 -080035#define RTC_RBUDR_SHIFT 4
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +053036#define RTC_RBUDR_MASK BIT(RTC_RBUDR_SHIFT)
Jonghwa Leefca1dd02013-02-21 16:44:26 -080037/* RTC Hour register */
38#define HOUR_PM_SHIFT 6
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +053039#define HOUR_PM_MASK BIT(HOUR_PM_SHIFT)
Jonghwa Leefca1dd02013-02-21 16:44:26 -080040/* RTC Alarm Enable */
41#define ALARM_ENABLE_SHIFT 7
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +053042#define ALARM_ENABLE_MASK BIT(ALARM_ENABLE_SHIFT)
Jonghwa Leefca1dd02013-02-21 16:44:26 -080043
Javier Martinez Canillasf9031292016-01-27 00:36:42 -030044#define REG_RTC_NONE 0xdeadbeef
45
46/*
47 * MAX77802 has separate register (RTCAE1) for alarm enable instead
48 * using 1 bit from registers RTC{SEC,MIN,HOUR,DAY,MONTH,YEAR,DATE}
49 * as in done in MAX77686.
50 */
51#define MAX77802_ALARM_ENABLE_VALUE 0x77
52
Jonghwa Leefca1dd02013-02-21 16:44:26 -080053enum {
54 RTC_SEC = 0,
55 RTC_MIN,
56 RTC_HOUR,
57 RTC_WEEKDAY,
58 RTC_MONTH,
59 RTC_YEAR,
60 RTC_DATE,
61 RTC_NR_TIME
62};
63
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -030064struct max77686_rtc_driver_data {
65 /* Minimum usecs needed for a RTC update */
66 unsigned long delay;
67 /* Mask used to read RTC registers value */
68 u8 mask;
Javier Martinez Canillas90a56982016-01-27 00:36:41 -030069 /* Registers offset to I2C addresses map */
70 const unsigned int *map;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -030071 /* Has a separate alarm enable register? */
72 bool alarm_enable_reg;
Laxman Dewanganf3937542016-02-09 22:56:34 +053073 /* I2C address for RTC block */
74 int rtc_i2c_addr;
Laxman Dewangan726fe732016-03-02 14:06:24 +053075 /* RTC interrupt via platform resource */
76 bool rtc_irq_from_platform;
77 /* Pending alarm status register */
78 int alarm_pending_status_reg;
Laxman Dewanganf3937542016-02-09 22:56:34 +053079 /* RTC IRQ CHIP for regmap */
80 const struct regmap_irq_chip *rtc_irq_chip;
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -030081};
82
Jonghwa Leefca1dd02013-02-21 16:44:26 -080083struct max77686_rtc_info {
84 struct device *dev;
Jonghwa Leefca1dd02013-02-21 16:44:26 -080085 struct i2c_client *rtc;
86 struct rtc_device *rtc_dev;
87 struct mutex lock;
88
89 struct regmap *regmap;
Laxman Dewanganf604c482016-02-09 22:56:32 +053090 struct regmap *rtc_regmap;
Jonghwa Leefca1dd02013-02-21 16:44:26 -080091
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -030092 const struct max77686_rtc_driver_data *drv_data;
Laxman Dewanganf3937542016-02-09 22:56:34 +053093 struct regmap_irq_chip_data *rtc_irq_data;
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -030094
Laxman Dewanganf3937542016-02-09 22:56:34 +053095 int rtc_irq;
Jonghwa Leefca1dd02013-02-21 16:44:26 -080096 int virq;
97 int rtc_24hr_mode;
98};
99
100enum MAX77686_RTC_OP {
101 MAX77686_RTC_WRITE,
102 MAX77686_RTC_READ,
103};
104
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300105/* These are not registers but just offsets that are mapped to addresses */
106enum max77686_rtc_reg_offset {
107 REG_RTC_CONTROLM = 0,
108 REG_RTC_CONTROL,
109 REG_RTC_UPDATE0,
110 REG_WTSR_SMPL_CNTL,
111 REG_RTC_SEC,
112 REG_RTC_MIN,
113 REG_RTC_HOUR,
114 REG_RTC_WEEKDAY,
115 REG_RTC_MONTH,
116 REG_RTC_YEAR,
117 REG_RTC_DATE,
118 REG_ALARM1_SEC,
119 REG_ALARM1_MIN,
120 REG_ALARM1_HOUR,
121 REG_ALARM1_WEEKDAY,
122 REG_ALARM1_MONTH,
123 REG_ALARM1_YEAR,
124 REG_ALARM1_DATE,
125 REG_ALARM2_SEC,
126 REG_ALARM2_MIN,
127 REG_ALARM2_HOUR,
128 REG_ALARM2_WEEKDAY,
129 REG_ALARM2_MONTH,
130 REG_ALARM2_YEAR,
131 REG_ALARM2_DATE,
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300132 REG_RTC_AE1,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300133 REG_RTC_END,
134};
135
136/* Maps RTC registers offset to the MAX77686 register addresses */
137static const unsigned int max77686_map[REG_RTC_END] = {
138 [REG_RTC_CONTROLM] = MAX77686_RTC_CONTROLM,
139 [REG_RTC_CONTROL] = MAX77686_RTC_CONTROL,
140 [REG_RTC_UPDATE0] = MAX77686_RTC_UPDATE0,
141 [REG_WTSR_SMPL_CNTL] = MAX77686_WTSR_SMPL_CNTL,
142 [REG_RTC_SEC] = MAX77686_RTC_SEC,
143 [REG_RTC_MIN] = MAX77686_RTC_MIN,
144 [REG_RTC_HOUR] = MAX77686_RTC_HOUR,
145 [REG_RTC_WEEKDAY] = MAX77686_RTC_WEEKDAY,
146 [REG_RTC_MONTH] = MAX77686_RTC_MONTH,
147 [REG_RTC_YEAR] = MAX77686_RTC_YEAR,
148 [REG_RTC_DATE] = MAX77686_RTC_DATE,
149 [REG_ALARM1_SEC] = MAX77686_ALARM1_SEC,
150 [REG_ALARM1_MIN] = MAX77686_ALARM1_MIN,
151 [REG_ALARM1_HOUR] = MAX77686_ALARM1_HOUR,
152 [REG_ALARM1_WEEKDAY] = MAX77686_ALARM1_WEEKDAY,
153 [REG_ALARM1_MONTH] = MAX77686_ALARM1_MONTH,
154 [REG_ALARM1_YEAR] = MAX77686_ALARM1_YEAR,
155 [REG_ALARM1_DATE] = MAX77686_ALARM1_DATE,
156 [REG_ALARM2_SEC] = MAX77686_ALARM2_SEC,
157 [REG_ALARM2_MIN] = MAX77686_ALARM2_MIN,
158 [REG_ALARM2_HOUR] = MAX77686_ALARM2_HOUR,
159 [REG_ALARM2_WEEKDAY] = MAX77686_ALARM2_WEEKDAY,
160 [REG_ALARM2_MONTH] = MAX77686_ALARM2_MONTH,
161 [REG_ALARM2_YEAR] = MAX77686_ALARM2_YEAR,
162 [REG_ALARM2_DATE] = MAX77686_ALARM2_DATE,
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300163 [REG_RTC_AE1] = REG_RTC_NONE,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300164};
165
Laxman Dewanganf3937542016-02-09 22:56:34 +0530166static const struct regmap_irq max77686_rtc_irqs[] = {
167 /* RTC interrupts */
Laxman Dewangan7e845362016-03-02 14:06:25 +0530168 REGMAP_IRQ_REG(0, 0, MAX77686_RTCINT_RTC60S_MSK),
169 REGMAP_IRQ_REG(1, 0, MAX77686_RTCINT_RTCA1_MSK),
170 REGMAP_IRQ_REG(2, 0, MAX77686_RTCINT_RTCA2_MSK),
171 REGMAP_IRQ_REG(3, 0, MAX77686_RTCINT_SMPL_MSK),
172 REGMAP_IRQ_REG(4, 0, MAX77686_RTCINT_RTC1S_MSK),
173 REGMAP_IRQ_REG(5, 0, MAX77686_RTCINT_WTSR_MSK),
Laxman Dewanganf3937542016-02-09 22:56:34 +0530174};
175
176static const struct regmap_irq_chip max77686_rtc_irq_chip = {
177 .name = "max77686-rtc",
178 .status_base = MAX77686_RTC_INT,
179 .mask_base = MAX77686_RTC_INTM,
180 .num_regs = 1,
181 .irqs = max77686_rtc_irqs,
182 .num_irqs = ARRAY_SIZE(max77686_rtc_irqs),
183};
184
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300185static const struct max77686_rtc_driver_data max77686_drv_data = {
186 .delay = 16000,
187 .mask = 0x7f,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300188 .map = max77686_map,
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300189 .alarm_enable_reg = false,
Laxman Dewangan726fe732016-03-02 14:06:24 +0530190 .rtc_irq_from_platform = false,
191 .alarm_pending_status_reg = MAX77686_REG_STATUS2,
Laxman Dewanganf3937542016-02-09 22:56:34 +0530192 .rtc_i2c_addr = MAX77686_I2C_ADDR_RTC,
193 .rtc_irq_chip = &max77686_rtc_irq_chip,
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300194};
195
Laxman Dewangan726fe732016-03-02 14:06:24 +0530196static const struct max77686_rtc_driver_data max77620_drv_data = {
197 .delay = 16000,
198 .mask = 0x7f,
199 .map = max77686_map,
200 .alarm_enable_reg = false,
201 .rtc_irq_from_platform = true,
202 .alarm_pending_status_reg = MAX77686_INVALID_REG,
203 .rtc_i2c_addr = MAX77620_I2C_ADDR_RTC,
204 .rtc_irq_chip = &max77686_rtc_irq_chip,
205};
206
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300207static const unsigned int max77802_map[REG_RTC_END] = {
208 [REG_RTC_CONTROLM] = MAX77802_RTC_CONTROLM,
209 [REG_RTC_CONTROL] = MAX77802_RTC_CONTROL,
210 [REG_RTC_UPDATE0] = MAX77802_RTC_UPDATE0,
211 [REG_WTSR_SMPL_CNTL] = MAX77802_WTSR_SMPL_CNTL,
212 [REG_RTC_SEC] = MAX77802_RTC_SEC,
213 [REG_RTC_MIN] = MAX77802_RTC_MIN,
214 [REG_RTC_HOUR] = MAX77802_RTC_HOUR,
215 [REG_RTC_WEEKDAY] = MAX77802_RTC_WEEKDAY,
216 [REG_RTC_MONTH] = MAX77802_RTC_MONTH,
217 [REG_RTC_YEAR] = MAX77802_RTC_YEAR,
218 [REG_RTC_DATE] = MAX77802_RTC_DATE,
219 [REG_ALARM1_SEC] = MAX77802_ALARM1_SEC,
220 [REG_ALARM1_MIN] = MAX77802_ALARM1_MIN,
221 [REG_ALARM1_HOUR] = MAX77802_ALARM1_HOUR,
222 [REG_ALARM1_WEEKDAY] = MAX77802_ALARM1_WEEKDAY,
223 [REG_ALARM1_MONTH] = MAX77802_ALARM1_MONTH,
224 [REG_ALARM1_YEAR] = MAX77802_ALARM1_YEAR,
225 [REG_ALARM1_DATE] = MAX77802_ALARM1_DATE,
226 [REG_ALARM2_SEC] = MAX77802_ALARM2_SEC,
227 [REG_ALARM2_MIN] = MAX77802_ALARM2_MIN,
228 [REG_ALARM2_HOUR] = MAX77802_ALARM2_HOUR,
229 [REG_ALARM2_WEEKDAY] = MAX77802_ALARM2_WEEKDAY,
230 [REG_ALARM2_MONTH] = MAX77802_ALARM2_MONTH,
231 [REG_ALARM2_YEAR] = MAX77802_ALARM2_YEAR,
232 [REG_ALARM2_DATE] = MAX77802_ALARM2_DATE,
233 [REG_RTC_AE1] = MAX77802_RTC_AE1,
234};
235
Laxman Dewanganf3937542016-02-09 22:56:34 +0530236static const struct regmap_irq_chip max77802_rtc_irq_chip = {
237 .name = "max77802-rtc",
238 .status_base = MAX77802_RTC_INT,
239 .mask_base = MAX77802_RTC_INTM,
240 .num_regs = 1,
241 .irqs = max77686_rtc_irqs, /* same masks as 77686 */
242 .num_irqs = ARRAY_SIZE(max77686_rtc_irqs),
243};
244
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300245static const struct max77686_rtc_driver_data max77802_drv_data = {
246 .delay = 200,
247 .mask = 0xff,
248 .map = max77802_map,
249 .alarm_enable_reg = true,
Laxman Dewangan726fe732016-03-02 14:06:24 +0530250 .rtc_irq_from_platform = false,
251 .alarm_pending_status_reg = MAX77686_REG_STATUS2,
Laxman Dewanganf3937542016-02-09 22:56:34 +0530252 .rtc_i2c_addr = MAX77686_INVALID_I2C_ADDR,
253 .rtc_irq_chip = &max77802_rtc_irq_chip,
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300254};
255
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800256static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300257 struct max77686_rtc_info *info)
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800258{
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300259 u8 mask = info->drv_data->mask;
260
261 tm->tm_sec = data[RTC_SEC] & mask;
262 tm->tm_min = data[RTC_MIN] & mask;
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +0530263 if (info->rtc_24hr_mode) {
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800264 tm->tm_hour = data[RTC_HOUR] & 0x1f;
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +0530265 } else {
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800266 tm->tm_hour = data[RTC_HOUR] & 0x0f;
267 if (data[RTC_HOUR] & HOUR_PM_MASK)
268 tm->tm_hour += 12;
269 }
270
Javier Martinez Canillasa20cd882014-10-13 15:53:03 -0700271 /* Only a single bit is set in data[], so fls() would be equivalent */
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300272 tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800273 tm->tm_mday = data[RTC_DATE] & 0x1f;
274 tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300275 tm->tm_year = data[RTC_YEAR] & mask;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800276 tm->tm_yday = 0;
277 tm->tm_isdst = 0;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300278
279 /*
280 * MAX77686 uses 1 bit from sec/min/hour/etc RTC registers and the
281 * year values are just 0..99 so add 100 to support up to 2099.
282 */
283 if (!info->drv_data->alarm_enable_reg)
284 tm->tm_year += 100;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800285}
286
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300287static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data,
288 struct max77686_rtc_info *info)
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800289{
290 data[RTC_SEC] = tm->tm_sec;
291 data[RTC_MIN] = tm->tm_min;
292 data[RTC_HOUR] = tm->tm_hour;
293 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
294 data[RTC_DATE] = tm->tm_mday;
295 data[RTC_MONTH] = tm->tm_mon + 1;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300296
297 if (info->drv_data->alarm_enable_reg) {
298 data[RTC_YEAR] = tm->tm_year;
299 return 0;
300 }
301
Sachin Kamatcdf5f4a2013-07-03 15:05:55 -0700302 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800303
304 if (tm->tm_year < 100) {
Javier Martinez Canillas1e5813b2016-01-27 00:36:43 -0300305 dev_err(info->dev, "RTC cannot handle the year %d.\n",
Joe Perchesa737e832015-04-16 12:46:14 -0700306 1900 + tm->tm_year);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800307 return -EINVAL;
308 }
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300309
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800310 return 0;
311}
312
313static int max77686_rtc_update(struct max77686_rtc_info *info,
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +0530314 enum MAX77686_RTC_OP op)
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800315{
316 int ret;
317 unsigned int data;
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300318 unsigned long delay = info->drv_data->delay;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800319
320 if (op == MAX77686_RTC_WRITE)
321 data = 1 << RTC_UDR_SHIFT;
322 else
323 data = 1 << RTC_RBUDR_SHIFT;
324
Laxman Dewanganf604c482016-02-09 22:56:32 +0530325 ret = regmap_update_bits(info->rtc_regmap,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300326 info->drv_data->map[REG_RTC_UPDATE0],
327 data, data);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800328 if (ret < 0)
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900329 dev_err(info->dev, "Fail to write update reg(ret=%d, data=0x%x)\n",
330 ret, data);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800331 else {
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300332 /* Minimum delay required before RTC update. */
333 usleep_range(delay, delay * 2);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800334 }
335
336 return ret;
337}
338
339static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
340{
341 struct max77686_rtc_info *info = dev_get_drvdata(dev);
342 u8 data[RTC_NR_TIME];
343 int ret;
344
345 mutex_lock(&info->lock);
346
347 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
348 if (ret < 0)
349 goto out;
350
Laxman Dewanganf604c482016-02-09 22:56:32 +0530351 ret = regmap_bulk_read(info->rtc_regmap,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300352 info->drv_data->map[REG_RTC_SEC],
353 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800354 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900355 dev_err(info->dev, "Fail to read time reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800356 goto out;
357 }
358
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300359 max77686_rtc_data_to_tm(data, tm, info);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800360
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800361out:
362 mutex_unlock(&info->lock);
Christophe JAILLETb28cc6c2018-11-14 00:36:45 +0100363 return ret;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800364}
365
366static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
367{
368 struct max77686_rtc_info *info = dev_get_drvdata(dev);
369 u8 data[RTC_NR_TIME];
370 int ret;
371
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300372 ret = max77686_rtc_tm_to_data(tm, data, info);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800373 if (ret < 0)
374 return ret;
375
376 mutex_lock(&info->lock);
377
Laxman Dewanganf604c482016-02-09 22:56:32 +0530378 ret = regmap_bulk_write(info->rtc_regmap,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300379 info->drv_data->map[REG_RTC_SEC],
380 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800381 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900382 dev_err(info->dev, "Fail to write time reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800383 goto out;
384 }
385
386 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
387
388out:
389 mutex_unlock(&info->lock);
390 return ret;
391}
392
393static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
394{
395 struct max77686_rtc_info *info = dev_get_drvdata(dev);
396 u8 data[RTC_NR_TIME];
397 unsigned int val;
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300398 const unsigned int *map = info->drv_data->map;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800399 int i, ret;
400
401 mutex_lock(&info->lock);
402
403 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
404 if (ret < 0)
405 goto out;
406
Laxman Dewanganf604c482016-02-09 22:56:32 +0530407 ret = regmap_bulk_read(info->rtc_regmap, map[REG_ALARM1_SEC],
408 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800409 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900410 dev_err(info->dev, "Fail to read alarm reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800411 goto out;
412 }
413
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300414 max77686_rtc_data_to_tm(data, &alrm->time, info);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800415
416 alrm->enabled = 0;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300417
418 if (info->drv_data->alarm_enable_reg) {
419 if (map[REG_RTC_AE1] == REG_RTC_NONE) {
420 ret = -EINVAL;
421 dev_err(info->dev,
422 "alarm enable register not set(%d)\n", ret);
423 goto out;
424 }
425
Laxman Dewanganf604c482016-02-09 22:56:32 +0530426 ret = regmap_read(info->rtc_regmap, map[REG_RTC_AE1], &val);
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300427 if (ret < 0) {
428 dev_err(info->dev,
429 "fail to read alarm enable(%d)\n", ret);
430 goto out;
431 }
432
433 if (val)
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800434 alrm->enabled = 1;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300435 } else {
436 for (i = 0; i < ARRAY_SIZE(data); i++) {
437 if (data[i] & ALARM_ENABLE_MASK) {
438 alrm->enabled = 1;
439 break;
440 }
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800441 }
442 }
443
444 alrm->pending = 0;
Laxman Dewangan726fe732016-03-02 14:06:24 +0530445
446 if (info->drv_data->alarm_pending_status_reg == MAX77686_INVALID_REG)
447 goto out;
448
449 ret = regmap_read(info->regmap,
450 info->drv_data->alarm_pending_status_reg, &val);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800451 if (ret < 0) {
Laxman Dewangan726fe732016-03-02 14:06:24 +0530452 dev_err(info->dev,
453 "Fail to read alarm pending status reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800454 goto out;
455 }
456
457 if (val & (1 << 4)) /* RTCA1 */
458 alrm->pending = 1;
459
460out:
461 mutex_unlock(&info->lock);
Javier Martinez Canillas7cdffeb2016-01-27 00:36:37 -0300462 return ret;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800463}
464
465static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
466{
467 u8 data[RTC_NR_TIME];
468 int ret, i;
469 struct rtc_time tm;
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300470 const unsigned int *map = info->drv_data->map;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800471
472 if (!mutex_is_locked(&info->lock))
473 dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
474
475 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
476 if (ret < 0)
477 goto out;
478
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300479 if (info->drv_data->alarm_enable_reg) {
480 if (map[REG_RTC_AE1] == REG_RTC_NONE) {
481 ret = -EINVAL;
482 dev_err(info->dev,
483 "alarm enable register not set(%d)\n", ret);
484 goto out;
485 }
486
Laxman Dewanganf604c482016-02-09 22:56:32 +0530487 ret = regmap_write(info->rtc_regmap, map[REG_RTC_AE1], 0);
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300488 } else {
Laxman Dewanganf604c482016-02-09 22:56:32 +0530489 ret = regmap_bulk_read(info->rtc_regmap, map[REG_ALARM1_SEC],
490 data, ARRAY_SIZE(data));
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300491 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900492 dev_err(info->dev, "Fail to read alarm reg(%d)\n", ret);
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300493 goto out;
494 }
495
496 max77686_rtc_data_to_tm(data, &tm, info);
497
498 for (i = 0; i < ARRAY_SIZE(data); i++)
499 data[i] &= ~ALARM_ENABLE_MASK;
500
Laxman Dewanganf604c482016-02-09 22:56:32 +0530501 ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC],
502 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800503 }
504
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800505 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900506 dev_err(info->dev, "Fail to write alarm reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800507 goto out;
508 }
509
510 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
511out:
512 return ret;
513}
514
515static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
516{
517 u8 data[RTC_NR_TIME];
518 int ret;
519 struct rtc_time tm;
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300520 const unsigned int *map = info->drv_data->map;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800521
522 if (!mutex_is_locked(&info->lock))
523 dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
524
525 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
526 if (ret < 0)
527 goto out;
528
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300529 if (info->drv_data->alarm_enable_reg) {
Laxman Dewanganf604c482016-02-09 22:56:32 +0530530 ret = regmap_write(info->rtc_regmap, map[REG_RTC_AE1],
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300531 MAX77802_ALARM_ENABLE_VALUE);
532 } else {
Laxman Dewanganf604c482016-02-09 22:56:32 +0530533 ret = regmap_bulk_read(info->rtc_regmap, map[REG_ALARM1_SEC],
534 data, ARRAY_SIZE(data));
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300535 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900536 dev_err(info->dev, "Fail to read alarm reg(%d)\n", ret);
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300537 goto out;
538 }
539
540 max77686_rtc_data_to_tm(data, &tm, info);
541
542 data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
543 data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
544 data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
545 data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
546 if (data[RTC_MONTH] & 0xf)
547 data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
548 if (data[RTC_YEAR] & info->drv_data->mask)
549 data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
550 if (data[RTC_DATE] & 0x1f)
551 data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
552
Laxman Dewanganf604c482016-02-09 22:56:32 +0530553 ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC],
554 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800555 }
556
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800557 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900558 dev_err(info->dev, "Fail to write alarm reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800559 goto out;
560 }
561
562 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
563out:
564 return ret;
565}
566
567static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
568{
569 struct max77686_rtc_info *info = dev_get_drvdata(dev);
570 u8 data[RTC_NR_TIME];
571 int ret;
572
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300573 ret = max77686_rtc_tm_to_data(&alrm->time, data, info);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800574 if (ret < 0)
575 return ret;
576
577 mutex_lock(&info->lock);
578
579 ret = max77686_rtc_stop_alarm(info);
580 if (ret < 0)
581 goto out;
582
Laxman Dewanganf604c482016-02-09 22:56:32 +0530583 ret = regmap_bulk_write(info->rtc_regmap,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300584 info->drv_data->map[REG_ALARM1_SEC],
585 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800586
587 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900588 dev_err(info->dev, "Fail to write alarm reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800589 goto out;
590 }
591
592 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
593 if (ret < 0)
594 goto out;
595
596 if (alrm->enabled)
597 ret = max77686_rtc_start_alarm(info);
598out:
599 mutex_unlock(&info->lock);
600 return ret;
601}
602
603static int max77686_rtc_alarm_irq_enable(struct device *dev,
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +0530604 unsigned int enabled)
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800605{
606 struct max77686_rtc_info *info = dev_get_drvdata(dev);
607 int ret;
608
609 mutex_lock(&info->lock);
610 if (enabled)
611 ret = max77686_rtc_start_alarm(info);
612 else
613 ret = max77686_rtc_stop_alarm(info);
614 mutex_unlock(&info->lock);
615
616 return ret;
617}
618
619static irqreturn_t max77686_rtc_alarm_irq(int irq, void *data)
620{
621 struct max77686_rtc_info *info = data;
622
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900623 dev_dbg(info->dev, "RTC alarm IRQ: %d\n", irq);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800624
625 rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
626
627 return IRQ_HANDLED;
628}
629
630static const struct rtc_class_ops max77686_rtc_ops = {
631 .read_time = max77686_rtc_read_time,
632 .set_time = max77686_rtc_set_time,
633 .read_alarm = max77686_rtc_read_alarm,
634 .set_alarm = max77686_rtc_set_alarm,
635 .alarm_irq_enable = max77686_rtc_alarm_irq_enable,
636};
637
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800638static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
639{
640 u8 data[2];
641 int ret;
642
643 /* Set RTC control register : Binary mode, 24hour mdoe */
644 data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
645 data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
646
647 info->rtc_24hr_mode = 1;
648
Laxman Dewanganf604c482016-02-09 22:56:32 +0530649 ret = regmap_bulk_write(info->rtc_regmap,
Javier Martinez Canillas90a56982016-01-27 00:36:41 -0300650 info->drv_data->map[REG_RTC_CONTROLM],
651 data, ARRAY_SIZE(data));
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800652 if (ret < 0) {
Krzysztof Kozlowskibf035f42016-01-27 15:46:11 +0900653 dev_err(info->dev, "Fail to write controlm reg(%d)\n", ret);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800654 return ret;
655 }
656
657 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
658 return ret;
659}
660
Laxman Dewanganf3937542016-02-09 22:56:34 +0530661static const struct regmap_config max77686_rtc_regmap_config = {
662 .reg_bits = 8,
663 .val_bits = 8,
664};
665
666static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
667{
668 struct device *parent = info->dev->parent;
669 struct i2c_client *parent_i2c = to_i2c_client(parent);
670 int ret;
671
Laxman Dewangan726fe732016-03-02 14:06:24 +0530672 if (info->drv_data->rtc_irq_from_platform) {
673 struct platform_device *pdev = to_platform_device(info->dev);
674
675 info->rtc_irq = platform_get_irq(pdev, 0);
Stephen Boydfaac9102019-07-30 11:15:39 -0700676 if (info->rtc_irq < 0)
Laxman Dewangan726fe732016-03-02 14:06:24 +0530677 return info->rtc_irq;
Laxman Dewangan726fe732016-03-02 14:06:24 +0530678 } else {
679 info->rtc_irq = parent_i2c->irq;
680 }
Laxman Dewanganf3937542016-02-09 22:56:34 +0530681
682 info->regmap = dev_get_regmap(parent, NULL);
683 if (!info->regmap) {
684 dev_err(info->dev, "Failed to get rtc regmap\n");
685 return -ENODEV;
686 }
687
688 if (info->drv_data->rtc_i2c_addr == MAX77686_INVALID_I2C_ADDR) {
689 info->rtc_regmap = info->regmap;
690 goto add_rtc_irq;
691 }
692
Wolfram Sang71507102019-07-22 19:26:16 +0200693 info->rtc = i2c_new_dummy_device(parent_i2c->adapter,
694 info->drv_data->rtc_i2c_addr);
695 if (IS_ERR(info->rtc)) {
Laxman Dewanganf3937542016-02-09 22:56:34 +0530696 dev_err(info->dev, "Failed to allocate I2C device for RTC\n");
Wolfram Sang71507102019-07-22 19:26:16 +0200697 return PTR_ERR(info->rtc);
Laxman Dewanganf3937542016-02-09 22:56:34 +0530698 }
699
700 info->rtc_regmap = devm_regmap_init_i2c(info->rtc,
701 &max77686_rtc_regmap_config);
702 if (IS_ERR(info->rtc_regmap)) {
703 ret = PTR_ERR(info->rtc_regmap);
704 dev_err(info->dev, "Failed to allocate RTC regmap: %d\n", ret);
705 goto err_unregister_i2c;
706 }
707
708add_rtc_irq:
709 ret = regmap_add_irq_chip(info->rtc_regmap, info->rtc_irq,
710 IRQF_TRIGGER_FALLING | IRQF_ONESHOT |
711 IRQF_SHARED, 0, info->drv_data->rtc_irq_chip,
712 &info->rtc_irq_data);
713 if (ret < 0) {
714 dev_err(info->dev, "Failed to add RTC irq chip: %d\n", ret);
715 goto err_unregister_i2c;
716 }
717
718 return 0;
719
720err_unregister_i2c:
721 if (info->rtc)
722 i2c_unregister_device(info->rtc);
723 return ret;
724}
725
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800726static int max77686_rtc_probe(struct platform_device *pdev)
727{
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800728 struct max77686_rtc_info *info;
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300729 const struct platform_device_id *id = platform_get_device_id(pdev);
Javier Martinez Canillas6f1c1e72014-07-04 22:24:04 +0200730 int ret;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800731
Jingoo Han0f64f852013-04-29 16:18:30 -0700732 info = devm_kzalloc(&pdev->dev, sizeof(struct max77686_rtc_info),
Laxman Dewangan0b4f8b02016-02-09 22:56:30 +0530733 GFP_KERNEL);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800734 if (!info)
735 return -ENOMEM;
736
737 mutex_init(&info->lock);
738 info->dev = &pdev->dev;
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300739 info->drv_data = (const struct max77686_rtc_driver_data *)
740 id->driver_data;
Javier Martinez Canillas6f1c1e72014-07-04 22:24:04 +0200741
Laxman Dewanganf3937542016-02-09 22:56:34 +0530742 ret = max77686_init_rtc_regmap(info);
743 if (ret < 0)
744 return ret;
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300745
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800746 platform_set_drvdata(pdev, info);
747
748 ret = max77686_rtc_init_reg(info);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800749 if (ret < 0) {
750 dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
751 goto err_rtc;
752 }
753
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800754 device_init_wakeup(&pdev->dev, 1);
755
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300756 info->rtc_dev = devm_rtc_device_register(&pdev->dev, id->name,
Jingoo Hanf56950e2013-04-29 16:19:05 -0700757 &max77686_rtc_ops, THIS_MODULE);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800758
759 if (IS_ERR(info->rtc_dev)) {
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800760 ret = PTR_ERR(info->rtc_dev);
761 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
762 if (ret == 0)
763 ret = -EINVAL;
764 goto err_rtc;
765 }
Javier Martinez Canillas6f1c1e72014-07-04 22:24:04 +0200766
Laxman Dewanganf3937542016-02-09 22:56:34 +0530767 info->virq = regmap_irq_get_virq(info->rtc_irq_data,
Javier Martinez Canillas6f1c1e72014-07-04 22:24:04 +0200768 MAX77686_RTCIRQ_RTCA1);
Krzysztof Kozlowskifb166ba2016-02-04 09:26:35 +0900769 if (info->virq <= 0) {
Sachin Kamatad819032013-04-29 16:20:12 -0700770 ret = -ENXIO;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800771 goto err_rtc;
Sachin Kamatad819032013-04-29 16:20:12 -0700772 }
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800773
Laxman Dewanganf3937542016-02-09 22:56:34 +0530774 ret = request_threaded_irq(info->virq, NULL, max77686_rtc_alarm_irq, 0,
775 "rtc-alarm1", info);
776 if (ret < 0) {
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800777 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
778 info->virq, ret);
Laxman Dewanganf3937542016-02-09 22:56:34 +0530779 goto err_rtc;
780 }
781
782 return 0;
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800783
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800784err_rtc:
Laxman Dewanganf3937542016-02-09 22:56:34 +0530785 regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data);
786 if (info->rtc)
787 i2c_unregister_device(info->rtc);
788
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800789 return ret;
790}
791
Laxman Dewanganf3937542016-02-09 22:56:34 +0530792static int max77686_rtc_remove(struct platform_device *pdev)
793{
794 struct max77686_rtc_info *info = platform_get_drvdata(pdev);
795
796 free_irq(info->virq, info);
797 regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data);
798 if (info->rtc)
799 i2c_unregister_device(info->rtc);
800
801 return 0;
802}
803
Doug Andersone7f7fc72014-10-13 15:52:55 -0700804#ifdef CONFIG_PM_SLEEP
805static int max77686_rtc_suspend(struct device *dev)
806{
807 if (device_may_wakeup(dev)) {
808 struct max77686_rtc_info *info = dev_get_drvdata(dev);
809
810 return enable_irq_wake(info->virq);
811 }
812
813 return 0;
814}
815
816static int max77686_rtc_resume(struct device *dev)
817{
818 if (device_may_wakeup(dev)) {
819 struct max77686_rtc_info *info = dev_get_drvdata(dev);
820
821 return disable_irq_wake(info->virq);
822 }
823
824 return 0;
825}
826#endif
827
828static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
829 max77686_rtc_suspend, max77686_rtc_resume);
830
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800831static const struct platform_device_id rtc_id[] = {
Javier Martinez Canillas01ea01b2016-01-27 00:36:40 -0300832 { "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, },
Javier Martinez Canillasf9031292016-01-27 00:36:42 -0300833 { "max77802-rtc", .driver_data = (kernel_ulong_t)&max77802_drv_data, },
Laxman Dewangan726fe732016-03-02 14:06:24 +0530834 { "max77620-rtc", .driver_data = (kernel_ulong_t)&max77620_drv_data, },
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800835 {},
836};
Javier Martinez Canillas2d0cca02015-05-13 17:18:01 +0200837MODULE_DEVICE_TABLE(platform, rtc_id);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800838
839static struct platform_driver max77686_rtc_driver = {
840 .driver = {
841 .name = "max77686-rtc",
Doug Andersone7f7fc72014-10-13 15:52:55 -0700842 .pm = &max77686_rtc_pm_ops,
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800843 },
844 .probe = max77686_rtc_probe,
Laxman Dewanganf3937542016-02-09 22:56:34 +0530845 .remove = max77686_rtc_remove,
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800846 .id_table = rtc_id,
847};
848
Jingoo Han0c58ff52013-04-29 16:18:28 -0700849module_platform_driver(max77686_rtc_driver);
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800850
851MODULE_DESCRIPTION("Maxim MAX77686 RTC driver");
Jingoo Hanf5b1d3c2013-04-29 16:18:29 -0700852MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
Jonghwa Leefca1dd02013-02-21 16:44:26 -0800853MODULE_LICENSE("GPL");