blob: 4243fe6d384228b3530caabec2eeeaf585dbb02d [file] [log] [blame]
Krzysztof Kozlowski26dcc122018-08-07 18:19:19 +02001// SPDX-License-Identifier: GPL-2.0+
2//
3// Copyright (c) 2013-2014 Samsung Electronics Co., Ltd
4// http://www.samsung.com
5//
6// Copyright (C) 2013 Google, Inc
Sangbeom Kim5bccae62013-11-12 15:11:04 -08007
Joe Perchesa737e832015-04-16 12:46:14 -07008#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
Sangbeom Kim5bccae62013-11-12 15:11:04 -080010#include <linux/module.h>
11#include <linux/i2c.h>
Sangbeom Kim5bccae62013-11-12 15:11:04 -080012#include <linux/bcd.h>
Sangbeom Kim5bccae62013-11-12 15:11:04 -080013#include <linux/regmap.h>
14#include <linux/rtc.h>
Sangbeom Kim5bccae62013-11-12 15:11:04 -080015#include <linux/platform_device.h>
16#include <linux/mfd/samsung/core.h>
17#include <linux/mfd/samsung/irq.h>
18#include <linux/mfd/samsung/rtc.h>
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -070019#include <linux/mfd/samsung/s2mps14.h>
Sangbeom Kim5bccae62013-11-12 15:11:04 -080020
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -080021/*
22 * Maximum number of retries for checking changes in UDR field
Krzysztof Kozlowski602cb5b2014-06-10 15:18:40 -070023 * of S5M_RTC_UDR_CON register (to limit possible endless loop).
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -080024 *
25 * After writing to RTC registers (setting time or alarm) read the UDR field
Krzysztof Kozlowski602cb5b2014-06-10 15:18:40 -070026 * in S5M_RTC_UDR_CON register. UDR is auto-cleared when data have
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -080027 * been transferred.
28 */
29#define UDR_READ_RETRY_CNT 5
30
Gustavo A. R. Silva4a681242018-03-10 00:27:15 -060031enum {
32 RTC_SEC = 0,
33 RTC_MIN,
34 RTC_HOUR,
35 RTC_WEEKDAY,
36 RTC_DATE,
37 RTC_MONTH,
38 RTC_YEAR1,
39 RTC_YEAR2,
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -060040 /* Make sure this is always the last enum name. */
41 RTC_MAX_NUM_TIME_REGS
Gustavo A. R. Silva4a681242018-03-10 00:27:15 -060042};
43
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +090044/*
45 * Registers used by the driver which are different between chipsets.
46 *
47 * Operations like read time and write alarm/time require updating
48 * specific fields in UDR register. These fields usually are auto-cleared
49 * (with some exceptions).
50 *
51 * Table of operations per device:
52 *
53 * Device | Write time | Read time | Write alarm
54 * =================================================
55 * S5M8767 | UDR + TIME | | UDR
56 * S2MPS11/14 | WUDR | RUDR | WUDR + RUDR
57 * S2MPS13 | WUDR | RUDR | WUDR + AUDR
58 * S2MPS15 | WUDR | RUDR | AUDR
59 */
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -070060struct s5m_rtc_reg_config {
61 /* Number of registers used for setting time/alarm0/alarm1 */
62 unsigned int regs_count;
63 /* First register for time, seconds */
64 unsigned int time;
65 /* RTC control register */
66 unsigned int ctrl;
67 /* First register for alarm 0, seconds */
68 unsigned int alarm0;
69 /* First register for alarm 1, seconds */
70 unsigned int alarm1;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -070071 /*
72 * Register for update flag (UDR). Typically setting UDR field to 1
73 * will enable update of time or alarm register. Then it will be
74 * auto-cleared after successful update.
75 */
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +090076 unsigned int udr_update;
Krzysztof Kozlowski67a60252015-12-30 13:47:26 +090077 /* Auto-cleared mask in UDR field for writing time and alarm */
78 unsigned int autoclear_udr_mask;
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +090079 /*
80 * Masks in UDR field for time and alarm operations.
81 * The read time mask can be 0. Rest should not.
82 */
83 unsigned int read_time_udr_mask;
84 unsigned int write_time_udr_mask;
85 unsigned int write_alarm_udr_mask;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -070086};
87
88/* Register map for S5M8763 and S5M8767 */
89static const struct s5m_rtc_reg_config s5m_rtc_regs = {
90 .regs_count = 8,
91 .time = S5M_RTC_SEC,
92 .ctrl = S5M_ALARM1_CONF,
93 .alarm0 = S5M_ALARM0_SEC,
94 .alarm1 = S5M_ALARM1_SEC,
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +090095 .udr_update = S5M_RTC_UDR_CON,
Krzysztof Kozlowski67a60252015-12-30 13:47:26 +090096 .autoclear_udr_mask = S5M_RTC_UDR_MASK,
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +090097 .read_time_udr_mask = 0, /* Not needed */
98 .write_time_udr_mask = S5M_RTC_UDR_MASK | S5M_RTC_TIME_EN_MASK,
99 .write_alarm_udr_mask = S5M_RTC_UDR_MASK,
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700100};
101
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900102/* Register map for S2MPS13 */
103static const struct s5m_rtc_reg_config s2mps13_rtc_regs = {
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700104 .regs_count = 7,
105 .time = S2MPS_RTC_SEC,
106 .ctrl = S2MPS_RTC_CTRL,
107 .alarm0 = S2MPS_ALARM0_SEC,
108 .alarm1 = S2MPS_ALARM1_SEC,
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900109 .udr_update = S2MPS_RTC_UDR_CON,
Krzysztof Kozlowski67a60252015-12-30 13:47:26 +0900110 .autoclear_udr_mask = S2MPS_RTC_WUDR_MASK,
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900111 .read_time_udr_mask = S2MPS_RTC_RUDR_MASK,
112 .write_time_udr_mask = S2MPS_RTC_WUDR_MASK,
113 .write_alarm_udr_mask = S2MPS_RTC_WUDR_MASK | S2MPS13_RTC_AUDR_MASK,
114};
115
116/* Register map for S2MPS11/14 */
117static const struct s5m_rtc_reg_config s2mps14_rtc_regs = {
118 .regs_count = 7,
119 .time = S2MPS_RTC_SEC,
120 .ctrl = S2MPS_RTC_CTRL,
121 .alarm0 = S2MPS_ALARM0_SEC,
122 .alarm1 = S2MPS_ALARM1_SEC,
123 .udr_update = S2MPS_RTC_UDR_CON,
124 .autoclear_udr_mask = S2MPS_RTC_WUDR_MASK,
125 .read_time_udr_mask = S2MPS_RTC_RUDR_MASK,
126 .write_time_udr_mask = S2MPS_RTC_WUDR_MASK,
127 .write_alarm_udr_mask = S2MPS_RTC_WUDR_MASK | S2MPS_RTC_RUDR_MASK,
128};
129
130/*
131 * Register map for S2MPS15 - in comparison to S2MPS14 the WUDR and AUDR bits
132 * are swapped.
133 */
134static const struct s5m_rtc_reg_config s2mps15_rtc_regs = {
135 .regs_count = 7,
136 .time = S2MPS_RTC_SEC,
137 .ctrl = S2MPS_RTC_CTRL,
138 .alarm0 = S2MPS_ALARM0_SEC,
139 .alarm1 = S2MPS_ALARM1_SEC,
140 .udr_update = S2MPS_RTC_UDR_CON,
141 .autoclear_udr_mask = S2MPS_RTC_WUDR_MASK,
142 .read_time_udr_mask = S2MPS_RTC_RUDR_MASK,
143 .write_time_udr_mask = S2MPS15_RTC_WUDR_MASK,
144 .write_alarm_udr_mask = S2MPS15_RTC_AUDR_MASK,
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700145};
146
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800147struct s5m_rtc_info {
148 struct device *dev;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200149 struct i2c_client *i2c;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800150 struct sec_pmic_dev *s5m87xx;
Geert Uytterhoeven5ccb7d72013-12-12 17:12:25 -0800151 struct regmap *regmap;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800152 struct rtc_device *rtc_dev;
153 int irq;
Krzysztof Kozlowski94f91922015-04-16 12:49:27 -0700154 enum sec_device_type device_type;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800155 int rtc_24hr_mode;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700156 const struct s5m_rtc_reg_config *regs;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800157};
158
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200159static const struct regmap_config s5m_rtc_regmap_config = {
160 .reg_bits = 8,
161 .val_bits = 8,
162
Krzysztof Kozlowski602cb5b2014-06-10 15:18:40 -0700163 .max_register = S5M_RTC_REG_MAX,
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200164};
165
166static const struct regmap_config s2mps14_rtc_regmap_config = {
167 .reg_bits = 8,
168 .val_bits = 8,
169
170 .max_register = S2MPS_RTC_REG_MAX,
171};
172
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800173static void s5m8767_data_to_tm(u8 *data, struct rtc_time *tm,
174 int rtc_24hr_mode)
175{
176 tm->tm_sec = data[RTC_SEC] & 0x7f;
177 tm->tm_min = data[RTC_MIN] & 0x7f;
178 if (rtc_24hr_mode) {
179 tm->tm_hour = data[RTC_HOUR] & 0x1f;
180 } else {
181 tm->tm_hour = data[RTC_HOUR] & 0x0f;
182 if (data[RTC_HOUR] & HOUR_PM_MASK)
183 tm->tm_hour += 12;
184 }
185
186 tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f);
187 tm->tm_mday = data[RTC_DATE] & 0x1f;
188 tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
189 tm->tm_year = (data[RTC_YEAR1] & 0x7f) + 100;
190 tm->tm_yday = 0;
191 tm->tm_isdst = 0;
192}
193
194static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data)
195{
196 data[RTC_SEC] = tm->tm_sec;
197 data[RTC_MIN] = tm->tm_min;
198
199 if (tm->tm_hour >= 12)
200 data[RTC_HOUR] = tm->tm_hour | HOUR_PM_MASK;
201 else
202 data[RTC_HOUR] = tm->tm_hour & ~HOUR_PM_MASK;
203
204 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
205 data[RTC_DATE] = tm->tm_mday;
206 data[RTC_MONTH] = tm->tm_mon + 1;
Alexandre Bellonifffd6032021-08-04 12:41:32 +0200207 data[RTC_YEAR1] = tm->tm_year - 100;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800208
Alexandre Bellonifffd6032021-08-04 12:41:32 +0200209 return 0;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800210}
211
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -0800212/*
213 * Read RTC_UDR_CON register and wait till UDR field is cleared.
214 * This indicates that time/alarm update ended.
215 */
Krzysztof Kozlowski8124c712016-02-16 11:04:42 +0900216static int s5m8767_wait_for_udr_update(struct s5m_rtc_info *info)
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -0800217{
218 int ret, retry = UDR_READ_RETRY_CNT;
219 unsigned int data;
220
221 do {
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900222 ret = regmap_read(info->regmap, info->regs->udr_update, &data);
Krzysztof Kozlowski67a60252015-12-30 13:47:26 +0900223 } while (--retry && (data & info->regs->autoclear_udr_mask) && !ret);
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -0800224
225 if (!retry)
226 dev_err(info->dev, "waiting for UDR update, reached max number of retries\n");
227
228 return ret;
229}
230
Krzysztof Kozlowski8124c712016-02-16 11:04:42 +0900231static int s5m_check_peding_alarm_interrupt(struct s5m_rtc_info *info,
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700232 struct rtc_wkalrm *alarm)
233{
234 int ret;
235 unsigned int val;
236
237 switch (info->device_type) {
238 case S5M8767X:
239 case S5M8763X:
240 ret = regmap_read(info->regmap, S5M_RTC_STATUS, &val);
241 val &= S5M_ALARM0_STATUS;
242 break;
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530243 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700244 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700245 case S2MPS13X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700246 ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2,
247 &val);
248 val &= S2MPS_ALARM0_STATUS;
249 break;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700250 default:
251 return -EINVAL;
252 }
253 if (ret < 0)
254 return ret;
255
256 if (val)
257 alarm->pending = 1;
258 else
259 alarm->pending = 0;
260
261 return 0;
262}
263
Krzysztof Kozlowski8124c712016-02-16 11:04:42 +0900264static int s5m8767_rtc_set_time_reg(struct s5m_rtc_info *info)
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800265{
266 int ret;
267 unsigned int data;
268
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900269 ret = regmap_read(info->regmap, info->regs->udr_update, &data);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800270 if (ret < 0) {
271 dev_err(info->dev, "failed to read update reg(%d)\n", ret);
272 return ret;
273 }
274
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900275 data |= info->regs->write_time_udr_mask;
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530276
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900277 ret = regmap_write(info->regmap, info->regs->udr_update, data);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800278 if (ret < 0) {
279 dev_err(info->dev, "failed to write update reg(%d)\n", ret);
280 return ret;
281 }
282
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -0800283 ret = s5m8767_wait_for_udr_update(info);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800284
285 return ret;
286}
287
Krzysztof Kozlowski8124c712016-02-16 11:04:42 +0900288static int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info)
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800289{
290 int ret;
291 unsigned int data;
292
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900293 ret = regmap_read(info->regmap, info->regs->udr_update, &data);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800294 if (ret < 0) {
295 dev_err(info->dev, "%s: fail to read update reg(%d)\n",
296 __func__, ret);
297 return ret;
298 }
299
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900300 data |= info->regs->write_alarm_udr_mask;
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700301 switch (info->device_type) {
302 case S5M8763X:
303 case S5M8767X:
304 data &= ~S5M_RTC_TIME_EN_MASK;
305 break;
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530306 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700307 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700308 case S2MPS13X:
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900309 /* No exceptions needed */
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700310 break;
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700311 default:
312 return -EINVAL;
313 }
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800314
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900315 ret = regmap_write(info->regmap, info->regs->udr_update, data);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800316 if (ret < 0) {
317 dev_err(info->dev, "%s: fail to write update reg(%d)\n",
318 __func__, ret);
319 return ret;
320 }
321
Krzysztof Kozlowskid73238d2013-12-12 17:12:28 -0800322 ret = s5m8767_wait_for_udr_update(info);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800323
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700324 /* On S2MPS13 the AUDR is not auto-cleared */
325 if (info->device_type == S2MPS13X)
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900326 regmap_update_bits(info->regmap, info->regs->udr_update,
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700327 S2MPS13_RTC_AUDR_MASK, 0);
328
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800329 return ret;
330}
331
332static void s5m8763_data_to_tm(u8 *data, struct rtc_time *tm)
333{
334 tm->tm_sec = bcd2bin(data[RTC_SEC]);
335 tm->tm_min = bcd2bin(data[RTC_MIN]);
336
337 if (data[RTC_HOUR] & HOUR_12) {
338 tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x1f);
339 if (data[RTC_HOUR] & HOUR_PM)
340 tm->tm_hour += 12;
341 } else {
342 tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f);
343 }
344
345 tm->tm_wday = data[RTC_WEEKDAY] & 0x07;
346 tm->tm_mday = bcd2bin(data[RTC_DATE]);
347 tm->tm_mon = bcd2bin(data[RTC_MONTH]);
348 tm->tm_year = bcd2bin(data[RTC_YEAR1]) + bcd2bin(data[RTC_YEAR2]) * 100;
349 tm->tm_year -= 1900;
350}
351
352static void s5m8763_tm_to_data(struct rtc_time *tm, u8 *data)
353{
354 data[RTC_SEC] = bin2bcd(tm->tm_sec);
355 data[RTC_MIN] = bin2bcd(tm->tm_min);
356 data[RTC_HOUR] = bin2bcd(tm->tm_hour);
357 data[RTC_WEEKDAY] = tm->tm_wday;
358 data[RTC_DATE] = bin2bcd(tm->tm_mday);
359 data[RTC_MONTH] = bin2bcd(tm->tm_mon);
360 data[RTC_YEAR1] = bin2bcd(tm->tm_year % 100);
361 data[RTC_YEAR2] = bin2bcd((tm->tm_year + 1900) / 100);
362}
363
364static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)
365{
366 struct s5m_rtc_info *info = dev_get_drvdata(dev);
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -0600367 u8 data[RTC_MAX_NUM_TIME_REGS];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800368 int ret;
369
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900370 if (info->regs->read_time_udr_mask) {
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700371 ret = regmap_update_bits(info->regmap,
Krzysztof Kozlowskia83a7932015-12-30 13:47:25 +0900372 info->regs->udr_update,
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900373 info->regs->read_time_udr_mask,
374 info->regs->read_time_udr_mask);
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700375 if (ret) {
376 dev_err(dev,
377 "Failed to prepare registers for time reading: %d\n",
378 ret);
379 return ret;
380 }
381 }
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700382 ret = regmap_bulk_read(info->regmap, info->regs->time, data,
383 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800384 if (ret < 0)
385 return ret;
386
387 switch (info->device_type) {
388 case S5M8763X:
389 s5m8763_data_to_tm(data, tm);
390 break;
391
392 case S5M8767X:
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530393 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700394 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700395 case S2MPS13X:
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800396 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode);
397 break;
398
399 default:
400 return -EINVAL;
401 }
402
Andy Shevchenko55278422018-12-04 23:23:26 +0200403 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, tm, tm->tm_wday);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800404
Alexandre Belloni22652ba2018-02-19 16:23:56 +0100405 return 0;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800406}
407
408static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm)
409{
410 struct s5m_rtc_info *info = dev_get_drvdata(dev);
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -0600411 u8 data[RTC_MAX_NUM_TIME_REGS];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800412 int ret = 0;
413
414 switch (info->device_type) {
415 case S5M8763X:
416 s5m8763_tm_to_data(tm, data);
417 break;
418 case S5M8767X:
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530419 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700420 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700421 case S2MPS13X:
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800422 ret = s5m8767_tm_to_data(tm, data);
423 break;
424 default:
425 return -EINVAL;
426 }
427
428 if (ret < 0)
429 return ret;
430
Andy Shevchenko55278422018-12-04 23:23:26 +0200431 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, tm, tm->tm_wday);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800432
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700433 ret = regmap_raw_write(info->regmap, info->regs->time, data,
434 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800435 if (ret < 0)
436 return ret;
437
438 ret = s5m8767_rtc_set_time_reg(info);
439
440 return ret;
441}
442
443static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
444{
445 struct s5m_rtc_info *info = dev_get_drvdata(dev);
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -0600446 u8 data[RTC_MAX_NUM_TIME_REGS];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800447 unsigned int val;
448 int ret, i;
449
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700450 ret = regmap_bulk_read(info->regmap, info->regs->alarm0, data,
451 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800452 if (ret < 0)
453 return ret;
454
455 switch (info->device_type) {
456 case S5M8763X:
457 s5m8763_data_to_tm(data, &alrm->time);
Krzysztof Kozlowski602cb5b2014-06-10 15:18:40 -0700458 ret = regmap_read(info->regmap, S5M_ALARM0_CONF, &val);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800459 if (ret < 0)
460 return ret;
461
462 alrm->enabled = !!val;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800463 break;
464
465 case S5M8767X:
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530466 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700467 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700468 case S2MPS13X:
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800469 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800470 alrm->enabled = 0;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700471 for (i = 0; i < info->regs->regs_count; i++) {
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800472 if (data[i] & ALARM_ENABLE_MASK) {
473 alrm->enabled = 1;
474 break;
475 }
476 }
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800477 break;
478
479 default:
480 return -EINVAL;
481 }
482
Andy Shevchenko55278422018-12-04 23:23:26 +0200483 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, &alrm->time, alrm->time.tm_wday);
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700484
Nobuhiro Iwamatsuf2581b1d2021-07-08 14:13:04 +0900485 return s5m_check_peding_alarm_interrupt(info, alrm);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800486}
487
488static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info)
489{
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -0600490 u8 data[RTC_MAX_NUM_TIME_REGS];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800491 int ret, i;
492 struct rtc_time tm;
493
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700494 ret = regmap_bulk_read(info->regmap, info->regs->alarm0, data,
495 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800496 if (ret < 0)
497 return ret;
498
499 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
Andy Shevchenko55278422018-12-04 23:23:26 +0200500 dev_dbg(info->dev, "%s: %ptR(%d)\n", __func__, &tm, tm.tm_wday);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800501
502 switch (info->device_type) {
503 case S5M8763X:
Krzysztof Kozlowski602cb5b2014-06-10 15:18:40 -0700504 ret = regmap_write(info->regmap, S5M_ALARM0_CONF, 0);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800505 break;
506
507 case S5M8767X:
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530508 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700509 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700510 case S2MPS13X:
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700511 for (i = 0; i < info->regs->regs_count; i++)
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800512 data[i] &= ~ALARM_ENABLE_MASK;
513
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700514 ret = regmap_raw_write(info->regmap, info->regs->alarm0, data,
515 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800516 if (ret < 0)
517 return ret;
518
519 ret = s5m8767_rtc_set_alarm_reg(info);
520
521 break;
522
523 default:
524 return -EINVAL;
525 }
526
527 return ret;
528}
529
530static int s5m_rtc_start_alarm(struct s5m_rtc_info *info)
531{
532 int ret;
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -0600533 u8 data[RTC_MAX_NUM_TIME_REGS];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800534 u8 alarm0_conf;
535 struct rtc_time tm;
536
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700537 ret = regmap_bulk_read(info->regmap, info->regs->alarm0, data,
538 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800539 if (ret < 0)
540 return ret;
541
542 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
Andy Shevchenko55278422018-12-04 23:23:26 +0200543 dev_dbg(info->dev, "%s: %ptR(%d)\n", __func__, &tm, tm.tm_wday);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800544
545 switch (info->device_type) {
546 case S5M8763X:
547 alarm0_conf = 0x77;
Krzysztof Kozlowski602cb5b2014-06-10 15:18:40 -0700548 ret = regmap_write(info->regmap, S5M_ALARM0_CONF, alarm0_conf);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800549 break;
550
551 case S5M8767X:
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530552 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700553 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700554 case S2MPS13X:
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800555 data[RTC_SEC] |= ALARM_ENABLE_MASK;
556 data[RTC_MIN] |= ALARM_ENABLE_MASK;
557 data[RTC_HOUR] |= ALARM_ENABLE_MASK;
558 data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
559 if (data[RTC_DATE] & 0x1f)
560 data[RTC_DATE] |= ALARM_ENABLE_MASK;
561 if (data[RTC_MONTH] & 0xf)
562 data[RTC_MONTH] |= ALARM_ENABLE_MASK;
563 if (data[RTC_YEAR1] & 0x7f)
564 data[RTC_YEAR1] |= ALARM_ENABLE_MASK;
565
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700566 ret = regmap_raw_write(info->regmap, info->regs->alarm0, data,
567 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800568 if (ret < 0)
569 return ret;
570 ret = s5m8767_rtc_set_alarm_reg(info);
571
572 break;
573
574 default:
575 return -EINVAL;
576 }
577
578 return ret;
579}
580
581static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
582{
583 struct s5m_rtc_info *info = dev_get_drvdata(dev);
Gustavo A. R. Silva756d5282018-03-10 00:27:35 -0600584 u8 data[RTC_MAX_NUM_TIME_REGS];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800585 int ret;
586
587 switch (info->device_type) {
588 case S5M8763X:
589 s5m8763_tm_to_data(&alrm->time, data);
590 break;
591
592 case S5M8767X:
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530593 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700594 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700595 case S2MPS13X:
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800596 s5m8767_tm_to_data(&alrm->time, data);
597 break;
598
599 default:
600 return -EINVAL;
601 }
602
Andy Shevchenko55278422018-12-04 23:23:26 +0200603 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, &alrm->time, alrm->time.tm_wday);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800604
605 ret = s5m_rtc_stop_alarm(info);
606 if (ret < 0)
607 return ret;
608
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700609 ret = regmap_raw_write(info->regmap, info->regs->alarm0, data,
610 info->regs->regs_count);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800611 if (ret < 0)
612 return ret;
613
614 ret = s5m8767_rtc_set_alarm_reg(info);
615 if (ret < 0)
616 return ret;
617
618 if (alrm->enabled)
619 ret = s5m_rtc_start_alarm(info);
620
621 return ret;
622}
623
624static int s5m_rtc_alarm_irq_enable(struct device *dev,
625 unsigned int enabled)
626{
627 struct s5m_rtc_info *info = dev_get_drvdata(dev);
628
629 if (enabled)
630 return s5m_rtc_start_alarm(info);
631 else
632 return s5m_rtc_stop_alarm(info);
633}
634
635static irqreturn_t s5m_rtc_alarm_irq(int irq, void *data)
636{
637 struct s5m_rtc_info *info = data;
638
639 rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
640
641 return IRQ_HANDLED;
642}
643
644static const struct rtc_class_ops s5m_rtc_ops = {
645 .read_time = s5m_rtc_read_time,
646 .set_time = s5m_rtc_set_time,
647 .read_alarm = s5m_rtc_read_alarm,
648 .set_alarm = s5m_rtc_set_alarm,
649 .alarm_irq_enable = s5m_rtc_alarm_irq_enable,
650};
651
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800652static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info)
653{
654 u8 data[2];
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800655 int ret;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800656
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700657 switch (info->device_type) {
658 case S5M8763X:
659 case S5M8767X:
660 /* UDR update time. Default of 7.32 ms is too long. */
661 ret = regmap_update_bits(info->regmap, S5M_RTC_UDR_CON,
662 S5M_RTC_UDR_T_MASK, S5M_RTC_UDR_T_450_US);
663 if (ret < 0)
664 dev_err(info->dev, "%s: fail to change UDR time: %d\n",
665 __func__, ret);
Krzysztof Kozlowski0c5f5d92014-06-10 15:18:43 -0700666
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700667 /* Set RTC control register : Binary mode, 24hour mode */
668 data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
669 data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
670
671 ret = regmap_raw_write(info->regmap, S5M_ALARM0_CONF, data, 2);
672 break;
673
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530674 case S2MPS15X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700675 case S2MPS14X:
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700676 case S2MPS13X:
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700677 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
678 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]);
Joonyoung Shimff02c042015-08-21 18:43:41 +0900679 if (ret < 0)
680 break;
681
682 /*
683 * Should set WUDR & (RUDR or AUDR) bits to high after writing
684 * RTC_CTRL register like writing Alarm registers. We can't find
685 * the description from datasheet but vendor code does that
686 * really.
687 */
688 ret = s5m8767_rtc_set_alarm_reg(info);
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700689 break;
690
691 default:
692 return -EINVAL;
693 }
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800694
695 info->rtc_24hr_mode = 1;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800696 if (ret < 0) {
697 dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
698 __func__, ret);
699 return ret;
700 }
701
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800702 return ret;
703}
704
705static int s5m_rtc_probe(struct platform_device *pdev)
706{
707 struct sec_pmic_dev *s5m87xx = dev_get_drvdata(pdev->dev.parent);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800708 struct s5m_rtc_info *info;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200709 const struct regmap_config *regmap_cfg;
Krzysztof Kozlowskia0347f22014-06-10 15:18:47 -0700710 int ret, alarm_irq;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800711
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800712 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
713 if (!info)
714 return -ENOMEM;
715
Krzysztof Kozlowski94f91922015-04-16 12:49:27 -0700716 switch (platform_get_device_id(pdev)->driver_data) {
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530717 case S2MPS15X:
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900718 regmap_cfg = &s2mps14_rtc_regmap_config;
719 info->regs = &s2mps15_rtc_regs;
720 alarm_irq = S2MPS14_IRQ_RTCA0;
721 break;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200722 case S2MPS14X:
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900723 regmap_cfg = &s2mps14_rtc_regmap_config;
724 info->regs = &s2mps14_rtc_regs;
725 alarm_irq = S2MPS14_IRQ_RTCA0;
726 break;
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700727 case S2MPS13X:
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200728 regmap_cfg = &s2mps14_rtc_regmap_config;
Krzysztof Kozlowski8ae83b62015-12-30 13:47:27 +0900729 info->regs = &s2mps13_rtc_regs;
Krzysztof Kozlowskia0347f22014-06-10 15:18:47 -0700730 alarm_irq = S2MPS14_IRQ_RTCA0;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200731 break;
732 case S5M8763X:
733 regmap_cfg = &s5m_rtc_regmap_config;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700734 info->regs = &s5m_rtc_regs;
Krzysztof Kozlowskia0347f22014-06-10 15:18:47 -0700735 alarm_irq = S5M8763_IRQ_ALARM0;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200736 break;
737 case S5M8767X:
738 regmap_cfg = &s5m_rtc_regmap_config;
Krzysztof Kozlowskif8b23bb2014-06-10 15:18:44 -0700739 info->regs = &s5m_rtc_regs;
Krzysztof Kozlowskia0347f22014-06-10 15:18:47 -0700740 alarm_irq = S5M8767_IRQ_RTCA1;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200741 break;
742 default:
Krzysztof Kozlowski94f91922015-04-16 12:49:27 -0700743 dev_err(&pdev->dev,
744 "Device type %lu is not supported by RTC driver\n",
745 platform_get_device_id(pdev)->driver_data);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200746 return -ENODEV;
747 }
748
Bartosz Golaszewski7db7ad02021-01-14 11:22:18 +0100749 info->i2c = devm_i2c_new_dummy_device(&pdev->dev, s5m87xx->i2c->adapter,
750 RTC_I2C_ADDR);
Wolfram Sangaae364d2019-07-22 19:26:18 +0200751 if (IS_ERR(info->i2c)) {
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200752 dev_err(&pdev->dev, "Failed to allocate I2C for RTC\n");
Wolfram Sangaae364d2019-07-22 19:26:18 +0200753 return PTR_ERR(info->i2c);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200754 }
755
756 info->regmap = devm_regmap_init_i2c(info->i2c, regmap_cfg);
757 if (IS_ERR(info->regmap)) {
758 ret = PTR_ERR(info->regmap);
759 dev_err(&pdev->dev, "Failed to allocate RTC register map: %d\n",
760 ret);
Bartosz Golaszewski7db7ad02021-01-14 11:22:18 +0100761 return ret;
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200762 }
763
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800764 info->dev = &pdev->dev;
765 info->s5m87xx = s5m87xx;
Krzysztof Kozlowski94f91922015-04-16 12:49:27 -0700766 info->device_type = platform_get_device_id(pdev)->driver_data;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800767
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700768 if (s5m87xx->irq_data) {
769 info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq);
770 if (info->irq <= 0) {
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700771 dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n",
Krzysztof Kozlowskia0347f22014-06-10 15:18:47 -0700772 alarm_irq);
Bartosz Golaszewski7db7ad02021-01-14 11:22:18 +0100773 return -EINVAL;
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700774 }
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800775 }
776
777 platform_set_drvdata(pdev, info);
778
779 ret = s5m8767_rtc_init_reg(info);
Bartosz Golaszewski3be95d22021-01-14 11:22:19 +0100780 if (ret)
781 return ret;
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800782
Alexandre Bellonidae68c62021-08-04 12:41:29 +0200783 info->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
Bartosz Golaszewski7db7ad02021-01-14 11:22:18 +0100784 if (IS_ERR(info->rtc_dev))
785 return PTR_ERR(info->rtc_dev);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800786
Alexandre Bellonidae68c62021-08-04 12:41:29 +0200787 info->rtc_dev->ops = &s5m_rtc_ops;
788
Alexandre Bellonifffd6032021-08-04 12:41:32 +0200789 if (info->device_type == S5M8763X) {
790 info->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_0000;
791 info->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
792 } else {
793 info->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000;
794 info->rtc_dev->range_max = RTC_TIMESTAMP_END_2099;
795 }
796
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700797 if (!info->irq) {
Alexandre Belloni1ed4dba2021-08-04 12:41:30 +0200798 clear_bit(RTC_FEATURE_ALARM, info->rtc_dev->features);
799 } else {
800 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
801 s5m_rtc_alarm_irq, 0, "rtc-alarm0",
802 info);
803 if (ret < 0) {
804 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
805 info->irq, ret);
806 return ret;
807 }
Alexandre Belloni308247d2021-08-04 12:41:31 +0200808 device_init_wakeup(&pdev->dev, 1);
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700809 }
810
Alexandre Belloni1ed4dba2021-08-04 12:41:30 +0200811 return devm_rtc_register_device(info->rtc_dev);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200812}
813
Geert Uytterhoeven11ba5a12014-01-23 15:55:19 -0800814#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowski222ead72013-12-12 17:12:30 -0800815static int s5m_rtc_resume(struct device *dev)
816{
817 struct s5m_rtc_info *info = dev_get_drvdata(dev);
818 int ret = 0;
819
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700820 if (info->irq && device_may_wakeup(dev))
Krzysztof Kozlowski222ead72013-12-12 17:12:30 -0800821 ret = disable_irq_wake(info->irq);
822
823 return ret;
824}
825
826static int s5m_rtc_suspend(struct device *dev)
827{
828 struct s5m_rtc_info *info = dev_get_drvdata(dev);
829 int ret = 0;
830
Bartlomiej Zolnierkiewiczb7d5b9a2014-08-29 15:18:53 -0700831 if (info->irq && device_may_wakeup(dev))
Krzysztof Kozlowski222ead72013-12-12 17:12:30 -0800832 ret = enable_irq_wake(info->irq);
833
834 return ret;
835}
Geert Uytterhoeven11ba5a12014-01-23 15:55:19 -0800836#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowski222ead72013-12-12 17:12:30 -0800837
838static SIMPLE_DEV_PM_OPS(s5m_rtc_pm_ops, s5m_rtc_suspend, s5m_rtc_resume);
839
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800840static const struct platform_device_id s5m_rtc_id[] = {
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700841 { "s5m-rtc", S5M8767X },
Krzysztof Kozlowski5281f942015-04-16 12:45:45 -0700842 { "s2mps13-rtc", S2MPS13X },
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700843 { "s2mps14-rtc", S2MPS14X },
Alim Akhtara65e5ef2015-11-20 16:07:53 +0530844 { "s2mps15-rtc", S2MPS15X },
Andrey Ryabinin45cd15e2015-01-26 12:58:46 -0800845 { },
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800846};
Javier Martinez Canillas63074cc2015-08-27 12:34:32 +0200847MODULE_DEVICE_TABLE(platform, s5m_rtc_id);
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800848
849static struct platform_driver s5m_rtc_driver = {
850 .driver = {
851 .name = "s5m-rtc",
Krzysztof Kozlowski222ead72013-12-12 17:12:30 -0800852 .pm = &s5m_rtc_pm_ops,
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800853 },
854 .probe = s5m_rtc_probe,
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800855 .id_table = s5m_rtc_id,
856};
857
858module_platform_driver(s5m_rtc_driver);
859
860/* Module information */
861MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Krzysztof Kozlowski0c5deb12014-06-10 15:18:46 -0700862MODULE_DESCRIPTION("Samsung S5M/S2MPS14 RTC driver");
Sangbeom Kim5bccae62013-11-12 15:11:04 -0800863MODULE_LICENSE("GPL");