xref: /linux/drivers/rtc/rtc-s5m.c (revision 3e1e4a5f3a324502c27c4e8808e06ac2ea842360)
15bccae6eSSangbeom Kim /*
25bccae6eSSangbeom Kim  * Copyright (c) 2013 Samsung Electronics Co., Ltd
35bccae6eSSangbeom Kim  *	http://www.samsung.com
45bccae6eSSangbeom Kim  *
55bccae6eSSangbeom Kim  *  Copyright (C) 2013 Google, Inc
65bccae6eSSangbeom Kim  *
75bccae6eSSangbeom Kim  *  This program is free software; you can redistribute it and/or modify
85bccae6eSSangbeom Kim  *  it under the terms of the GNU General Public License as published by
95bccae6eSSangbeom Kim  *  the Free Software Foundation; either version 2 of the License, or
105bccae6eSSangbeom Kim  *  (at your option) any later version.
115bccae6eSSangbeom Kim  *
125bccae6eSSangbeom Kim  *  This program is distributed in the hope that it will be useful,
135bccae6eSSangbeom Kim  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
145bccae6eSSangbeom Kim  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155bccae6eSSangbeom Kim  *  GNU General Public License for more details.
165bccae6eSSangbeom Kim  */
175bccae6eSSangbeom Kim 
185bccae6eSSangbeom Kim #include <linux/module.h>
195bccae6eSSangbeom Kim #include <linux/i2c.h>
205bccae6eSSangbeom Kim #include <linux/slab.h>
215bccae6eSSangbeom Kim #include <linux/bcd.h>
225bccae6eSSangbeom Kim #include <linux/bitops.h>
235bccae6eSSangbeom Kim #include <linux/regmap.h>
245bccae6eSSangbeom Kim #include <linux/rtc.h>
255bccae6eSSangbeom Kim #include <linux/delay.h>
265bccae6eSSangbeom Kim #include <linux/platform_device.h>
275bccae6eSSangbeom Kim #include <linux/mfd/samsung/core.h>
285bccae6eSSangbeom Kim #include <linux/mfd/samsung/irq.h>
295bccae6eSSangbeom Kim #include <linux/mfd/samsung/rtc.h>
305bccae6eSSangbeom Kim 
31d73238d4SKrzysztof Kozlowski /*
32d73238d4SKrzysztof Kozlowski  * Maximum number of retries for checking changes in UDR field
33d73238d4SKrzysztof Kozlowski  * of SEC_RTC_UDR_CON register (to limit possible endless loop).
34d73238d4SKrzysztof Kozlowski  *
35d73238d4SKrzysztof Kozlowski  * After writing to RTC registers (setting time or alarm) read the UDR field
36d73238d4SKrzysztof Kozlowski  * in SEC_RTC_UDR_CON register. UDR is auto-cleared when data have
37d73238d4SKrzysztof Kozlowski  * been transferred.
38d73238d4SKrzysztof Kozlowski  */
39d73238d4SKrzysztof Kozlowski #define UDR_READ_RETRY_CNT	5
40d73238d4SKrzysztof Kozlowski 
415bccae6eSSangbeom Kim struct s5m_rtc_info {
425bccae6eSSangbeom Kim 	struct device *dev;
435bccae6eSSangbeom Kim 	struct sec_pmic_dev *s5m87xx;
445ccb7d71SGeert Uytterhoeven 	struct regmap *regmap;
455bccae6eSSangbeom Kim 	struct rtc_device *rtc_dev;
465bccae6eSSangbeom Kim 	int irq;
475bccae6eSSangbeom Kim 	int device_type;
485bccae6eSSangbeom Kim 	int rtc_24hr_mode;
495bccae6eSSangbeom Kim 	bool wtsr_smpl;
505bccae6eSSangbeom Kim };
515bccae6eSSangbeom Kim 
525bccae6eSSangbeom Kim static void s5m8767_data_to_tm(u8 *data, struct rtc_time *tm,
535bccae6eSSangbeom Kim 			       int rtc_24hr_mode)
545bccae6eSSangbeom Kim {
555bccae6eSSangbeom Kim 	tm->tm_sec = data[RTC_SEC] & 0x7f;
565bccae6eSSangbeom Kim 	tm->tm_min = data[RTC_MIN] & 0x7f;
575bccae6eSSangbeom Kim 	if (rtc_24hr_mode) {
585bccae6eSSangbeom Kim 		tm->tm_hour = data[RTC_HOUR] & 0x1f;
595bccae6eSSangbeom Kim 	} else {
605bccae6eSSangbeom Kim 		tm->tm_hour = data[RTC_HOUR] & 0x0f;
615bccae6eSSangbeom Kim 		if (data[RTC_HOUR] & HOUR_PM_MASK)
625bccae6eSSangbeom Kim 			tm->tm_hour += 12;
635bccae6eSSangbeom Kim 	}
645bccae6eSSangbeom Kim 
655bccae6eSSangbeom Kim 	tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f);
665bccae6eSSangbeom Kim 	tm->tm_mday = data[RTC_DATE] & 0x1f;
675bccae6eSSangbeom Kim 	tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
685bccae6eSSangbeom Kim 	tm->tm_year = (data[RTC_YEAR1] & 0x7f) + 100;
695bccae6eSSangbeom Kim 	tm->tm_yday = 0;
705bccae6eSSangbeom Kim 	tm->tm_isdst = 0;
715bccae6eSSangbeom Kim }
725bccae6eSSangbeom Kim 
735bccae6eSSangbeom Kim static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data)
745bccae6eSSangbeom Kim {
755bccae6eSSangbeom Kim 	data[RTC_SEC] = tm->tm_sec;
765bccae6eSSangbeom Kim 	data[RTC_MIN] = tm->tm_min;
775bccae6eSSangbeom Kim 
785bccae6eSSangbeom Kim 	if (tm->tm_hour >= 12)
795bccae6eSSangbeom Kim 		data[RTC_HOUR] = tm->tm_hour | HOUR_PM_MASK;
805bccae6eSSangbeom Kim 	else
815bccae6eSSangbeom Kim 		data[RTC_HOUR] = tm->tm_hour & ~HOUR_PM_MASK;
825bccae6eSSangbeom Kim 
835bccae6eSSangbeom Kim 	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
845bccae6eSSangbeom Kim 	data[RTC_DATE] = tm->tm_mday;
855bccae6eSSangbeom Kim 	data[RTC_MONTH] = tm->tm_mon + 1;
865bccae6eSSangbeom Kim 	data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
875bccae6eSSangbeom Kim 
885bccae6eSSangbeom Kim 	if (tm->tm_year < 100) {
895bccae6eSSangbeom Kim 		pr_err("s5m8767 RTC cannot handle the year %d.\n",
905bccae6eSSangbeom Kim 		       1900 + tm->tm_year);
915bccae6eSSangbeom Kim 		return -EINVAL;
925bccae6eSSangbeom Kim 	} else {
935bccae6eSSangbeom Kim 		return 0;
945bccae6eSSangbeom Kim 	}
955bccae6eSSangbeom Kim }
965bccae6eSSangbeom Kim 
97d73238d4SKrzysztof Kozlowski /*
98d73238d4SKrzysztof Kozlowski  * Read RTC_UDR_CON register and wait till UDR field is cleared.
99d73238d4SKrzysztof Kozlowski  * This indicates that time/alarm update ended.
100d73238d4SKrzysztof Kozlowski  */
101d73238d4SKrzysztof Kozlowski static inline int s5m8767_wait_for_udr_update(struct s5m_rtc_info *info)
102d73238d4SKrzysztof Kozlowski {
103d73238d4SKrzysztof Kozlowski 	int ret, retry = UDR_READ_RETRY_CNT;
104d73238d4SKrzysztof Kozlowski 	unsigned int data;
105d73238d4SKrzysztof Kozlowski 
106d73238d4SKrzysztof Kozlowski 	do {
107d73238d4SKrzysztof Kozlowski 		ret = regmap_read(info->regmap, SEC_RTC_UDR_CON, &data);
108d73238d4SKrzysztof Kozlowski 	} while (--retry && (data & RTC_UDR_MASK) && !ret);
109d73238d4SKrzysztof Kozlowski 
110d73238d4SKrzysztof Kozlowski 	if (!retry)
111d73238d4SKrzysztof Kozlowski 		dev_err(info->dev, "waiting for UDR update, reached max number of retries\n");
112d73238d4SKrzysztof Kozlowski 
113d73238d4SKrzysztof Kozlowski 	return ret;
114d73238d4SKrzysztof Kozlowski }
115d73238d4SKrzysztof Kozlowski 
1165bccae6eSSangbeom Kim static inline int s5m8767_rtc_set_time_reg(struct s5m_rtc_info *info)
1175bccae6eSSangbeom Kim {
1185bccae6eSSangbeom Kim 	int ret;
1195bccae6eSSangbeom Kim 	unsigned int data;
1205bccae6eSSangbeom Kim 
1215ccb7d71SGeert Uytterhoeven 	ret = regmap_read(info->regmap, SEC_RTC_UDR_CON, &data);
1225bccae6eSSangbeom Kim 	if (ret < 0) {
1235bccae6eSSangbeom Kim 		dev_err(info->dev, "failed to read update reg(%d)\n", ret);
1245bccae6eSSangbeom Kim 		return ret;
1255bccae6eSSangbeom Kim 	}
1265bccae6eSSangbeom Kim 
1275bccae6eSSangbeom Kim 	data |= RTC_TIME_EN_MASK;
1285bccae6eSSangbeom Kim 	data |= RTC_UDR_MASK;
1295bccae6eSSangbeom Kim 
1305ccb7d71SGeert Uytterhoeven 	ret = regmap_write(info->regmap, SEC_RTC_UDR_CON, data);
1315bccae6eSSangbeom Kim 	if (ret < 0) {
1325bccae6eSSangbeom Kim 		dev_err(info->dev, "failed to write update reg(%d)\n", ret);
1335bccae6eSSangbeom Kim 		return ret;
1345bccae6eSSangbeom Kim 	}
1355bccae6eSSangbeom Kim 
136d73238d4SKrzysztof Kozlowski 	ret = s5m8767_wait_for_udr_update(info);
1375bccae6eSSangbeom Kim 
1385bccae6eSSangbeom Kim 	return ret;
1395bccae6eSSangbeom Kim }
1405bccae6eSSangbeom Kim 
1415bccae6eSSangbeom Kim static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info)
1425bccae6eSSangbeom Kim {
1435bccae6eSSangbeom Kim 	int ret;
1445bccae6eSSangbeom Kim 	unsigned int data;
1455bccae6eSSangbeom Kim 
1465ccb7d71SGeert Uytterhoeven 	ret = regmap_read(info->regmap, SEC_RTC_UDR_CON, &data);
1475bccae6eSSangbeom Kim 	if (ret < 0) {
1485bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to read update reg(%d)\n",
1495bccae6eSSangbeom Kim 			__func__, ret);
1505bccae6eSSangbeom Kim 		return ret;
1515bccae6eSSangbeom Kim 	}
1525bccae6eSSangbeom Kim 
1535bccae6eSSangbeom Kim 	data &= ~RTC_TIME_EN_MASK;
1545bccae6eSSangbeom Kim 	data |= RTC_UDR_MASK;
1555bccae6eSSangbeom Kim 
1565ccb7d71SGeert Uytterhoeven 	ret = regmap_write(info->regmap, SEC_RTC_UDR_CON, data);
1575bccae6eSSangbeom Kim 	if (ret < 0) {
1585bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to write update reg(%d)\n",
1595bccae6eSSangbeom Kim 			__func__, ret);
1605bccae6eSSangbeom Kim 		return ret;
1615bccae6eSSangbeom Kim 	}
1625bccae6eSSangbeom Kim 
163d73238d4SKrzysztof Kozlowski 	ret = s5m8767_wait_for_udr_update(info);
1645bccae6eSSangbeom Kim 
1655bccae6eSSangbeom Kim 	return ret;
1665bccae6eSSangbeom Kim }
1675bccae6eSSangbeom Kim 
1685bccae6eSSangbeom Kim static void s5m8763_data_to_tm(u8 *data, struct rtc_time *tm)
1695bccae6eSSangbeom Kim {
1705bccae6eSSangbeom Kim 	tm->tm_sec = bcd2bin(data[RTC_SEC]);
1715bccae6eSSangbeom Kim 	tm->tm_min = bcd2bin(data[RTC_MIN]);
1725bccae6eSSangbeom Kim 
1735bccae6eSSangbeom Kim 	if (data[RTC_HOUR] & HOUR_12) {
1745bccae6eSSangbeom Kim 		tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x1f);
1755bccae6eSSangbeom Kim 		if (data[RTC_HOUR] & HOUR_PM)
1765bccae6eSSangbeom Kim 			tm->tm_hour += 12;
1775bccae6eSSangbeom Kim 	} else {
1785bccae6eSSangbeom Kim 		tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f);
1795bccae6eSSangbeom Kim 	}
1805bccae6eSSangbeom Kim 
1815bccae6eSSangbeom Kim 	tm->tm_wday = data[RTC_WEEKDAY] & 0x07;
1825bccae6eSSangbeom Kim 	tm->tm_mday = bcd2bin(data[RTC_DATE]);
1835bccae6eSSangbeom Kim 	tm->tm_mon = bcd2bin(data[RTC_MONTH]);
1845bccae6eSSangbeom Kim 	tm->tm_year = bcd2bin(data[RTC_YEAR1]) + bcd2bin(data[RTC_YEAR2]) * 100;
1855bccae6eSSangbeom Kim 	tm->tm_year -= 1900;
1865bccae6eSSangbeom Kim }
1875bccae6eSSangbeom Kim 
1885bccae6eSSangbeom Kim static void s5m8763_tm_to_data(struct rtc_time *tm, u8 *data)
1895bccae6eSSangbeom Kim {
1905bccae6eSSangbeom Kim 	data[RTC_SEC] = bin2bcd(tm->tm_sec);
1915bccae6eSSangbeom Kim 	data[RTC_MIN] = bin2bcd(tm->tm_min);
1925bccae6eSSangbeom Kim 	data[RTC_HOUR] = bin2bcd(tm->tm_hour);
1935bccae6eSSangbeom Kim 	data[RTC_WEEKDAY] = tm->tm_wday;
1945bccae6eSSangbeom Kim 	data[RTC_DATE] = bin2bcd(tm->tm_mday);
1955bccae6eSSangbeom Kim 	data[RTC_MONTH] = bin2bcd(tm->tm_mon);
1965bccae6eSSangbeom Kim 	data[RTC_YEAR1] = bin2bcd(tm->tm_year % 100);
1975bccae6eSSangbeom Kim 	data[RTC_YEAR2] = bin2bcd((tm->tm_year + 1900) / 100);
1985bccae6eSSangbeom Kim }
1995bccae6eSSangbeom Kim 
2005bccae6eSSangbeom Kim static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)
2015bccae6eSSangbeom Kim {
2025bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
2035bccae6eSSangbeom Kim 	u8 data[8];
2045bccae6eSSangbeom Kim 	int ret;
2055bccae6eSSangbeom Kim 
2065ccb7d71SGeert Uytterhoeven 	ret = regmap_bulk_read(info->regmap, SEC_RTC_SEC, data, 8);
2075bccae6eSSangbeom Kim 	if (ret < 0)
2085bccae6eSSangbeom Kim 		return ret;
2095bccae6eSSangbeom Kim 
2105bccae6eSSangbeom Kim 	switch (info->device_type) {
2115bccae6eSSangbeom Kim 	case S5M8763X:
2125bccae6eSSangbeom Kim 		s5m8763_data_to_tm(data, tm);
2135bccae6eSSangbeom Kim 		break;
2145bccae6eSSangbeom Kim 
2155bccae6eSSangbeom Kim 	case S5M8767X:
2165bccae6eSSangbeom Kim 		s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode);
2175bccae6eSSangbeom Kim 		break;
2185bccae6eSSangbeom Kim 
2195bccae6eSSangbeom Kim 	default:
2205bccae6eSSangbeom Kim 		return -EINVAL;
2215bccae6eSSangbeom Kim 	}
2225bccae6eSSangbeom Kim 
2235bccae6eSSangbeom Kim 	dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
2245bccae6eSSangbeom Kim 		1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
2255bccae6eSSangbeom Kim 		tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
2265bccae6eSSangbeom Kim 
2275bccae6eSSangbeom Kim 	return rtc_valid_tm(tm);
2285bccae6eSSangbeom Kim }
2295bccae6eSSangbeom Kim 
2305bccae6eSSangbeom Kim static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm)
2315bccae6eSSangbeom Kim {
2325bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
2335bccae6eSSangbeom Kim 	u8 data[8];
2345bccae6eSSangbeom Kim 	int ret = 0;
2355bccae6eSSangbeom Kim 
2365bccae6eSSangbeom Kim 	switch (info->device_type) {
2375bccae6eSSangbeom Kim 	case S5M8763X:
2385bccae6eSSangbeom Kim 		s5m8763_tm_to_data(tm, data);
2395bccae6eSSangbeom Kim 		break;
2405bccae6eSSangbeom Kim 	case S5M8767X:
2415bccae6eSSangbeom Kim 		ret = s5m8767_tm_to_data(tm, data);
2425bccae6eSSangbeom Kim 		break;
2435bccae6eSSangbeom Kim 	default:
2445bccae6eSSangbeom Kim 		return -EINVAL;
2455bccae6eSSangbeom Kim 	}
2465bccae6eSSangbeom Kim 
2475bccae6eSSangbeom Kim 	if (ret < 0)
2485bccae6eSSangbeom Kim 		return ret;
2495bccae6eSSangbeom Kim 
2505bccae6eSSangbeom Kim 	dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
2515bccae6eSSangbeom Kim 		1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
2525bccae6eSSangbeom Kim 		tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
2535bccae6eSSangbeom Kim 
2545ccb7d71SGeert Uytterhoeven 	ret = regmap_raw_write(info->regmap, SEC_RTC_SEC, data, 8);
2555bccae6eSSangbeom Kim 	if (ret < 0)
2565bccae6eSSangbeom Kim 		return ret;
2575bccae6eSSangbeom Kim 
2585bccae6eSSangbeom Kim 	ret = s5m8767_rtc_set_time_reg(info);
2595bccae6eSSangbeom Kim 
2605bccae6eSSangbeom Kim 	return ret;
2615bccae6eSSangbeom Kim }
2625bccae6eSSangbeom Kim 
2635bccae6eSSangbeom Kim static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
2645bccae6eSSangbeom Kim {
2655bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
2665bccae6eSSangbeom Kim 	u8 data[8];
2675bccae6eSSangbeom Kim 	unsigned int val;
2685bccae6eSSangbeom Kim 	int ret, i;
2695bccae6eSSangbeom Kim 
2705ccb7d71SGeert Uytterhoeven 	ret = regmap_bulk_read(info->regmap, SEC_ALARM0_SEC, data, 8);
2715bccae6eSSangbeom Kim 	if (ret < 0)
2725bccae6eSSangbeom Kim 		return ret;
2735bccae6eSSangbeom Kim 
2745bccae6eSSangbeom Kim 	switch (info->device_type) {
2755bccae6eSSangbeom Kim 	case S5M8763X:
2765bccae6eSSangbeom Kim 		s5m8763_data_to_tm(data, &alrm->time);
2775ccb7d71SGeert Uytterhoeven 		ret = regmap_read(info->regmap, SEC_ALARM0_CONF, &val);
2785bccae6eSSangbeom Kim 		if (ret < 0)
2795bccae6eSSangbeom Kim 			return ret;
2805bccae6eSSangbeom Kim 
2815bccae6eSSangbeom Kim 		alrm->enabled = !!val;
2825bccae6eSSangbeom Kim 
2835ccb7d71SGeert Uytterhoeven 		ret = regmap_read(info->regmap, SEC_RTC_STATUS, &val);
2845bccae6eSSangbeom Kim 		if (ret < 0)
2855bccae6eSSangbeom Kim 			return ret;
2865bccae6eSSangbeom Kim 
2875bccae6eSSangbeom Kim 		break;
2885bccae6eSSangbeom Kim 
2895bccae6eSSangbeom Kim 	case S5M8767X:
2905bccae6eSSangbeom Kim 		s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
2915bccae6eSSangbeom Kim 		dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
2925bccae6eSSangbeom Kim 			1900 + alrm->time.tm_year, 1 + alrm->time.tm_mon,
2935bccae6eSSangbeom Kim 			alrm->time.tm_mday, alrm->time.tm_hour,
2945bccae6eSSangbeom Kim 			alrm->time.tm_min, alrm->time.tm_sec,
2955bccae6eSSangbeom Kim 			alrm->time.tm_wday);
2965bccae6eSSangbeom Kim 
2975bccae6eSSangbeom Kim 		alrm->enabled = 0;
2985bccae6eSSangbeom Kim 		for (i = 0; i < 7; i++) {
2995bccae6eSSangbeom Kim 			if (data[i] & ALARM_ENABLE_MASK) {
3005bccae6eSSangbeom Kim 				alrm->enabled = 1;
3015bccae6eSSangbeom Kim 				break;
3025bccae6eSSangbeom Kim 			}
3035bccae6eSSangbeom Kim 		}
3045bccae6eSSangbeom Kim 
3055bccae6eSSangbeom Kim 		alrm->pending = 0;
3065ccb7d71SGeert Uytterhoeven 		ret = regmap_read(info->regmap, SEC_RTC_STATUS, &val);
3075bccae6eSSangbeom Kim 		if (ret < 0)
3085bccae6eSSangbeom Kim 			return ret;
3095bccae6eSSangbeom Kim 		break;
3105bccae6eSSangbeom Kim 
3115bccae6eSSangbeom Kim 	default:
3125bccae6eSSangbeom Kim 		return -EINVAL;
3135bccae6eSSangbeom Kim 	}
3145bccae6eSSangbeom Kim 
3155bccae6eSSangbeom Kim 	if (val & ALARM0_STATUS)
3165bccae6eSSangbeom Kim 		alrm->pending = 1;
3175bccae6eSSangbeom Kim 	else
3185bccae6eSSangbeom Kim 		alrm->pending = 0;
3195bccae6eSSangbeom Kim 
3205bccae6eSSangbeom Kim 	return 0;
3215bccae6eSSangbeom Kim }
3225bccae6eSSangbeom Kim 
3235bccae6eSSangbeom Kim static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info)
3245bccae6eSSangbeom Kim {
3255bccae6eSSangbeom Kim 	u8 data[8];
3265bccae6eSSangbeom Kim 	int ret, i;
3275bccae6eSSangbeom Kim 	struct rtc_time tm;
3285bccae6eSSangbeom Kim 
3295ccb7d71SGeert Uytterhoeven 	ret = regmap_bulk_read(info->regmap, SEC_ALARM0_SEC, data, 8);
3305bccae6eSSangbeom Kim 	if (ret < 0)
3315bccae6eSSangbeom Kim 		return ret;
3325bccae6eSSangbeom Kim 
3335bccae6eSSangbeom Kim 	s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
3345bccae6eSSangbeom Kim 	dev_dbg(info->dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
3355bccae6eSSangbeom Kim 		1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday,
3365bccae6eSSangbeom Kim 		tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday);
3375bccae6eSSangbeom Kim 
3385bccae6eSSangbeom Kim 	switch (info->device_type) {
3395bccae6eSSangbeom Kim 	case S5M8763X:
3405ccb7d71SGeert Uytterhoeven 		ret = regmap_write(info->regmap, SEC_ALARM0_CONF, 0);
3415bccae6eSSangbeom Kim 		break;
3425bccae6eSSangbeom Kim 
3435bccae6eSSangbeom Kim 	case S5M8767X:
3445bccae6eSSangbeom Kim 		for (i = 0; i < 7; i++)
3455bccae6eSSangbeom Kim 			data[i] &= ~ALARM_ENABLE_MASK;
3465bccae6eSSangbeom Kim 
3475ccb7d71SGeert Uytterhoeven 		ret = regmap_raw_write(info->regmap, SEC_ALARM0_SEC, data, 8);
3485bccae6eSSangbeom Kim 		if (ret < 0)
3495bccae6eSSangbeom Kim 			return ret;
3505bccae6eSSangbeom Kim 
3515bccae6eSSangbeom Kim 		ret = s5m8767_rtc_set_alarm_reg(info);
3525bccae6eSSangbeom Kim 
3535bccae6eSSangbeom Kim 		break;
3545bccae6eSSangbeom Kim 
3555bccae6eSSangbeom Kim 	default:
3565bccae6eSSangbeom Kim 		return -EINVAL;
3575bccae6eSSangbeom Kim 	}
3585bccae6eSSangbeom Kim 
3595bccae6eSSangbeom Kim 	return ret;
3605bccae6eSSangbeom Kim }
3615bccae6eSSangbeom Kim 
3625bccae6eSSangbeom Kim static int s5m_rtc_start_alarm(struct s5m_rtc_info *info)
3635bccae6eSSangbeom Kim {
3645bccae6eSSangbeom Kim 	int ret;
3655bccae6eSSangbeom Kim 	u8 data[8];
3665bccae6eSSangbeom Kim 	u8 alarm0_conf;
3675bccae6eSSangbeom Kim 	struct rtc_time tm;
3685bccae6eSSangbeom Kim 
3695ccb7d71SGeert Uytterhoeven 	ret = regmap_bulk_read(info->regmap, SEC_ALARM0_SEC, data, 8);
3705bccae6eSSangbeom Kim 	if (ret < 0)
3715bccae6eSSangbeom Kim 		return ret;
3725bccae6eSSangbeom Kim 
3735bccae6eSSangbeom Kim 	s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
3745bccae6eSSangbeom Kim 	dev_dbg(info->dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
3755bccae6eSSangbeom Kim 		1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday,
3765bccae6eSSangbeom Kim 		tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday);
3775bccae6eSSangbeom Kim 
3785bccae6eSSangbeom Kim 	switch (info->device_type) {
3795bccae6eSSangbeom Kim 	case S5M8763X:
3805bccae6eSSangbeom Kim 		alarm0_conf = 0x77;
3815ccb7d71SGeert Uytterhoeven 		ret = regmap_write(info->regmap, SEC_ALARM0_CONF, alarm0_conf);
3825bccae6eSSangbeom Kim 		break;
3835bccae6eSSangbeom Kim 
3845bccae6eSSangbeom Kim 	case S5M8767X:
3855bccae6eSSangbeom Kim 		data[RTC_SEC] |= ALARM_ENABLE_MASK;
3865bccae6eSSangbeom Kim 		data[RTC_MIN] |= ALARM_ENABLE_MASK;
3875bccae6eSSangbeom Kim 		data[RTC_HOUR] |= ALARM_ENABLE_MASK;
3885bccae6eSSangbeom Kim 		data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
3895bccae6eSSangbeom Kim 		if (data[RTC_DATE] & 0x1f)
3905bccae6eSSangbeom Kim 			data[RTC_DATE] |= ALARM_ENABLE_MASK;
3915bccae6eSSangbeom Kim 		if (data[RTC_MONTH] & 0xf)
3925bccae6eSSangbeom Kim 			data[RTC_MONTH] |= ALARM_ENABLE_MASK;
3935bccae6eSSangbeom Kim 		if (data[RTC_YEAR1] & 0x7f)
3945bccae6eSSangbeom Kim 			data[RTC_YEAR1] |= ALARM_ENABLE_MASK;
3955bccae6eSSangbeom Kim 
3965ccb7d71SGeert Uytterhoeven 		ret = regmap_raw_write(info->regmap, SEC_ALARM0_SEC, data, 8);
3975bccae6eSSangbeom Kim 		if (ret < 0)
3985bccae6eSSangbeom Kim 			return ret;
3995bccae6eSSangbeom Kim 		ret = s5m8767_rtc_set_alarm_reg(info);
4005bccae6eSSangbeom Kim 
4015bccae6eSSangbeom Kim 		break;
4025bccae6eSSangbeom Kim 
4035bccae6eSSangbeom Kim 	default:
4045bccae6eSSangbeom Kim 		return -EINVAL;
4055bccae6eSSangbeom Kim 	}
4065bccae6eSSangbeom Kim 
4075bccae6eSSangbeom Kim 	return ret;
4085bccae6eSSangbeom Kim }
4095bccae6eSSangbeom Kim 
4105bccae6eSSangbeom Kim static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
4115bccae6eSSangbeom Kim {
4125bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
4135bccae6eSSangbeom Kim 	u8 data[8];
4145bccae6eSSangbeom Kim 	int ret;
4155bccae6eSSangbeom Kim 
4165bccae6eSSangbeom Kim 	switch (info->device_type) {
4175bccae6eSSangbeom Kim 	case S5M8763X:
4185bccae6eSSangbeom Kim 		s5m8763_tm_to_data(&alrm->time, data);
4195bccae6eSSangbeom Kim 		break;
4205bccae6eSSangbeom Kim 
4215bccae6eSSangbeom Kim 	case S5M8767X:
4225bccae6eSSangbeom Kim 		s5m8767_tm_to_data(&alrm->time, data);
4235bccae6eSSangbeom Kim 		break;
4245bccae6eSSangbeom Kim 
4255bccae6eSSangbeom Kim 	default:
4265bccae6eSSangbeom Kim 		return -EINVAL;
4275bccae6eSSangbeom Kim 	}
4285bccae6eSSangbeom Kim 
4295bccae6eSSangbeom Kim 	dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__,
4305bccae6eSSangbeom Kim 		1900 + alrm->time.tm_year, 1 + alrm->time.tm_mon,
4315bccae6eSSangbeom Kim 		alrm->time.tm_mday, alrm->time.tm_hour, alrm->time.tm_min,
4325bccae6eSSangbeom Kim 		alrm->time.tm_sec, alrm->time.tm_wday);
4335bccae6eSSangbeom Kim 
4345bccae6eSSangbeom Kim 	ret = s5m_rtc_stop_alarm(info);
4355bccae6eSSangbeom Kim 	if (ret < 0)
4365bccae6eSSangbeom Kim 		return ret;
4375bccae6eSSangbeom Kim 
4385ccb7d71SGeert Uytterhoeven 	ret = regmap_raw_write(info->regmap, SEC_ALARM0_SEC, data, 8);
4395bccae6eSSangbeom Kim 	if (ret < 0)
4405bccae6eSSangbeom Kim 		return ret;
4415bccae6eSSangbeom Kim 
4425bccae6eSSangbeom Kim 	ret = s5m8767_rtc_set_alarm_reg(info);
4435bccae6eSSangbeom Kim 	if (ret < 0)
4445bccae6eSSangbeom Kim 		return ret;
4455bccae6eSSangbeom Kim 
4465bccae6eSSangbeom Kim 	if (alrm->enabled)
4475bccae6eSSangbeom Kim 		ret = s5m_rtc_start_alarm(info);
4485bccae6eSSangbeom Kim 
4495bccae6eSSangbeom Kim 	return ret;
4505bccae6eSSangbeom Kim }
4515bccae6eSSangbeom Kim 
4525bccae6eSSangbeom Kim static int s5m_rtc_alarm_irq_enable(struct device *dev,
4535bccae6eSSangbeom Kim 				    unsigned int enabled)
4545bccae6eSSangbeom Kim {
4555bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
4565bccae6eSSangbeom Kim 
4575bccae6eSSangbeom Kim 	if (enabled)
4585bccae6eSSangbeom Kim 		return s5m_rtc_start_alarm(info);
4595bccae6eSSangbeom Kim 	else
4605bccae6eSSangbeom Kim 		return s5m_rtc_stop_alarm(info);
4615bccae6eSSangbeom Kim }
4625bccae6eSSangbeom Kim 
4635bccae6eSSangbeom Kim static irqreturn_t s5m_rtc_alarm_irq(int irq, void *data)
4645bccae6eSSangbeom Kim {
4655bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = data;
4665bccae6eSSangbeom Kim 
4675bccae6eSSangbeom Kim 	rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
4685bccae6eSSangbeom Kim 
4695bccae6eSSangbeom Kim 	return IRQ_HANDLED;
4705bccae6eSSangbeom Kim }
4715bccae6eSSangbeom Kim 
4725bccae6eSSangbeom Kim static const struct rtc_class_ops s5m_rtc_ops = {
4735bccae6eSSangbeom Kim 	.read_time = s5m_rtc_read_time,
4745bccae6eSSangbeom Kim 	.set_time = s5m_rtc_set_time,
4755bccae6eSSangbeom Kim 	.read_alarm = s5m_rtc_read_alarm,
4765bccae6eSSangbeom Kim 	.set_alarm = s5m_rtc_set_alarm,
4775bccae6eSSangbeom Kim 	.alarm_irq_enable = s5m_rtc_alarm_irq_enable,
4785bccae6eSSangbeom Kim };
4795bccae6eSSangbeom Kim 
4805bccae6eSSangbeom Kim static void s5m_rtc_enable_wtsr(struct s5m_rtc_info *info, bool enable)
4815bccae6eSSangbeom Kim {
4825bccae6eSSangbeom Kim 	int ret;
4835ccb7d71SGeert Uytterhoeven 	ret = regmap_update_bits(info->regmap, SEC_WTSR_SMPL_CNTL,
4845bccae6eSSangbeom Kim 				 WTSR_ENABLE_MASK,
4855bccae6eSSangbeom Kim 				 enable ? WTSR_ENABLE_MASK : 0);
4865bccae6eSSangbeom Kim 	if (ret < 0)
4875bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
4885bccae6eSSangbeom Kim 			__func__, ret);
4895bccae6eSSangbeom Kim }
4905bccae6eSSangbeom Kim 
4915bccae6eSSangbeom Kim static void s5m_rtc_enable_smpl(struct s5m_rtc_info *info, bool enable)
4925bccae6eSSangbeom Kim {
4935bccae6eSSangbeom Kim 	int ret;
4945ccb7d71SGeert Uytterhoeven 	ret = regmap_update_bits(info->regmap, SEC_WTSR_SMPL_CNTL,
4955bccae6eSSangbeom Kim 				 SMPL_ENABLE_MASK,
4965bccae6eSSangbeom Kim 				 enable ? SMPL_ENABLE_MASK : 0);
4975bccae6eSSangbeom Kim 	if (ret < 0)
4985bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
4995bccae6eSSangbeom Kim 			__func__, ret);
5005bccae6eSSangbeom Kim }
5015bccae6eSSangbeom Kim 
5025bccae6eSSangbeom Kim static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info)
5035bccae6eSSangbeom Kim {
5045bccae6eSSangbeom Kim 	u8 data[2];
5055bccae6eSSangbeom Kim 	unsigned int tp_read;
5065bccae6eSSangbeom Kim 	int ret;
5075bccae6eSSangbeom Kim 	struct rtc_time tm;
5085bccae6eSSangbeom Kim 
5095ccb7d71SGeert Uytterhoeven 	ret = regmap_read(info->regmap, SEC_RTC_UDR_CON, &tp_read);
5105bccae6eSSangbeom Kim 	if (ret < 0) {
5115bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to read control reg(%d)\n",
5125bccae6eSSangbeom Kim 			__func__, ret);
5135bccae6eSSangbeom Kim 		return ret;
5145bccae6eSSangbeom Kim 	}
5155bccae6eSSangbeom Kim 
5165bccae6eSSangbeom Kim 	/* Set RTC control register : Binary mode, 24hour mode */
5175bccae6eSSangbeom Kim 	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
5185bccae6eSSangbeom Kim 	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
5195bccae6eSSangbeom Kim 
5205bccae6eSSangbeom Kim 	info->rtc_24hr_mode = 1;
5215ccb7d71SGeert Uytterhoeven 	ret = regmap_raw_write(info->regmap, SEC_ALARM0_CONF, data, 2);
5225bccae6eSSangbeom Kim 	if (ret < 0) {
5235bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
5245bccae6eSSangbeom Kim 			__func__, ret);
5255bccae6eSSangbeom Kim 		return ret;
5265bccae6eSSangbeom Kim 	}
5275bccae6eSSangbeom Kim 
5285bccae6eSSangbeom Kim 	/* In first boot time, Set rtc time to 1/1/2012 00:00:00(SUN) */
5295bccae6eSSangbeom Kim 	if ((tp_read & RTC_TCON_MASK) == 0) {
5305bccae6eSSangbeom Kim 		dev_dbg(info->dev, "rtc init\n");
5315bccae6eSSangbeom Kim 		tm.tm_sec = 0;
5325bccae6eSSangbeom Kim 		tm.tm_min = 0;
5335bccae6eSSangbeom Kim 		tm.tm_hour = 0;
5345bccae6eSSangbeom Kim 		tm.tm_wday = 0;
5355bccae6eSSangbeom Kim 		tm.tm_mday = 1;
5365bccae6eSSangbeom Kim 		tm.tm_mon = 0;
5375bccae6eSSangbeom Kim 		tm.tm_year = 112;
5385bccae6eSSangbeom Kim 		tm.tm_yday = 0;
5395bccae6eSSangbeom Kim 		tm.tm_isdst = 0;
5405bccae6eSSangbeom Kim 		ret = s5m_rtc_set_time(info->dev, &tm);
5415bccae6eSSangbeom Kim 	}
5425bccae6eSSangbeom Kim 
5435ccb7d71SGeert Uytterhoeven 	ret = regmap_update_bits(info->regmap, SEC_RTC_UDR_CON,
5445bccae6eSSangbeom Kim 				 RTC_TCON_MASK, tp_read | RTC_TCON_MASK);
5455bccae6eSSangbeom Kim 	if (ret < 0)
5465bccae6eSSangbeom Kim 		dev_err(info->dev, "%s: fail to update TCON reg(%d)\n",
5475bccae6eSSangbeom Kim 			__func__, ret);
5485bccae6eSSangbeom Kim 
5495bccae6eSSangbeom Kim 	return ret;
5505bccae6eSSangbeom Kim }
5515bccae6eSSangbeom Kim 
5525bccae6eSSangbeom Kim static int s5m_rtc_probe(struct platform_device *pdev)
5535bccae6eSSangbeom Kim {
5545bccae6eSSangbeom Kim 	struct sec_pmic_dev *s5m87xx = dev_get_drvdata(pdev->dev.parent);
5555bccae6eSSangbeom Kim 	struct sec_platform_data *pdata = s5m87xx->pdata;
5565bccae6eSSangbeom Kim 	struct s5m_rtc_info *info;
5575bccae6eSSangbeom Kim 	int ret;
5585bccae6eSSangbeom Kim 
5595bccae6eSSangbeom Kim 	if (!pdata) {
5605bccae6eSSangbeom Kim 		dev_err(pdev->dev.parent, "Platform data not supplied\n");
5615bccae6eSSangbeom Kim 		return -ENODEV;
5625bccae6eSSangbeom Kim 	}
5635bccae6eSSangbeom Kim 
5645bccae6eSSangbeom Kim 	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
5655bccae6eSSangbeom Kim 	if (!info)
5665bccae6eSSangbeom Kim 		return -ENOMEM;
5675bccae6eSSangbeom Kim 
5685bccae6eSSangbeom Kim 	info->dev = &pdev->dev;
5695bccae6eSSangbeom Kim 	info->s5m87xx = s5m87xx;
570*3e1e4a5fSKrzysztof Kozlowski 	info->regmap = s5m87xx->regmap_rtc;
5715bccae6eSSangbeom Kim 	info->device_type = s5m87xx->device_type;
5725bccae6eSSangbeom Kim 	info->wtsr_smpl = s5m87xx->wtsr_smpl;
5735bccae6eSSangbeom Kim 
5745bccae6eSSangbeom Kim 	switch (pdata->device_type) {
5755bccae6eSSangbeom Kim 	case S5M8763X:
5767b003be8SKrzysztof Kozlowski 		info->irq = regmap_irq_get_virq(s5m87xx->irq_data,
5777b003be8SKrzysztof Kozlowski 				S5M8763_IRQ_ALARM0);
5785bccae6eSSangbeom Kim 		break;
5795bccae6eSSangbeom Kim 
5805bccae6eSSangbeom Kim 	case S5M8767X:
5817b003be8SKrzysztof Kozlowski 		info->irq = regmap_irq_get_virq(s5m87xx->irq_data,
5827b003be8SKrzysztof Kozlowski 				S5M8767_IRQ_RTCA1);
5835bccae6eSSangbeom Kim 		break;
5845bccae6eSSangbeom Kim 
5855bccae6eSSangbeom Kim 	default:
5865bccae6eSSangbeom Kim 		ret = -EINVAL;
5875bccae6eSSangbeom Kim 		dev_err(&pdev->dev, "Unsupported device type: %d\n", ret);
5885bccae6eSSangbeom Kim 		return ret;
5895bccae6eSSangbeom Kim 	}
5905bccae6eSSangbeom Kim 
5915bccae6eSSangbeom Kim 	platform_set_drvdata(pdev, info);
5925bccae6eSSangbeom Kim 
5935bccae6eSSangbeom Kim 	ret = s5m8767_rtc_init_reg(info);
5945bccae6eSSangbeom Kim 
5955bccae6eSSangbeom Kim 	if (info->wtsr_smpl) {
5965bccae6eSSangbeom Kim 		s5m_rtc_enable_wtsr(info, true);
5975bccae6eSSangbeom Kim 		s5m_rtc_enable_smpl(info, true);
5985bccae6eSSangbeom Kim 	}
5995bccae6eSSangbeom Kim 
6005bccae6eSSangbeom Kim 	device_init_wakeup(&pdev->dev, 1);
6015bccae6eSSangbeom Kim 
6025bccae6eSSangbeom Kim 	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "s5m-rtc",
6035bccae6eSSangbeom Kim 						 &s5m_rtc_ops, THIS_MODULE);
6045bccae6eSSangbeom Kim 
6055bccae6eSSangbeom Kim 	if (IS_ERR(info->rtc_dev))
6065bccae6eSSangbeom Kim 		return PTR_ERR(info->rtc_dev);
6075bccae6eSSangbeom Kim 
6085bccae6eSSangbeom Kim 	ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
6095bccae6eSSangbeom Kim 					s5m_rtc_alarm_irq, 0, "rtc-alarm0",
6105bccae6eSSangbeom Kim 					info);
6115bccae6eSSangbeom Kim 	if (ret < 0)
6125bccae6eSSangbeom Kim 		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
6135bccae6eSSangbeom Kim 			info->irq, ret);
6145bccae6eSSangbeom Kim 
6155bccae6eSSangbeom Kim 	return ret;
6165bccae6eSSangbeom Kim }
6175bccae6eSSangbeom Kim 
6185bccae6eSSangbeom Kim static void s5m_rtc_shutdown(struct platform_device *pdev)
6195bccae6eSSangbeom Kim {
6205bccae6eSSangbeom Kim 	struct s5m_rtc_info *info = platform_get_drvdata(pdev);
6215bccae6eSSangbeom Kim 	int i;
6225bccae6eSSangbeom Kim 	unsigned int val = 0;
6235bccae6eSSangbeom Kim 	if (info->wtsr_smpl) {
6245bccae6eSSangbeom Kim 		for (i = 0; i < 3; i++) {
6255bccae6eSSangbeom Kim 			s5m_rtc_enable_wtsr(info, false);
6265ccb7d71SGeert Uytterhoeven 			regmap_read(info->regmap, SEC_WTSR_SMPL_CNTL, &val);
6275bccae6eSSangbeom Kim 			pr_debug("%s: WTSR_SMPL reg(0x%02x)\n", __func__, val);
6285bccae6eSSangbeom Kim 			if (val & WTSR_ENABLE_MASK)
6295bccae6eSSangbeom Kim 				pr_emerg("%s: fail to disable WTSR\n",
6305bccae6eSSangbeom Kim 					 __func__);
6315bccae6eSSangbeom Kim 			else {
6325bccae6eSSangbeom Kim 				pr_info("%s: success to disable WTSR\n",
6335bccae6eSSangbeom Kim 					__func__);
6345bccae6eSSangbeom Kim 				break;
6355bccae6eSSangbeom Kim 			}
6365bccae6eSSangbeom Kim 		}
6375bccae6eSSangbeom Kim 	}
6385bccae6eSSangbeom Kim 	/* Disable SMPL when power off */
6395bccae6eSSangbeom Kim 	s5m_rtc_enable_smpl(info, false);
6405bccae6eSSangbeom Kim }
6415bccae6eSSangbeom Kim 
642222ead7fSKrzysztof Kozlowski static int s5m_rtc_resume(struct device *dev)
643222ead7fSKrzysztof Kozlowski {
644222ead7fSKrzysztof Kozlowski 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
645222ead7fSKrzysztof Kozlowski 	int ret = 0;
646222ead7fSKrzysztof Kozlowski 
647222ead7fSKrzysztof Kozlowski 	if (device_may_wakeup(dev))
648222ead7fSKrzysztof Kozlowski 		ret = disable_irq_wake(info->irq);
649222ead7fSKrzysztof Kozlowski 
650222ead7fSKrzysztof Kozlowski 	return ret;
651222ead7fSKrzysztof Kozlowski }
652222ead7fSKrzysztof Kozlowski 
653222ead7fSKrzysztof Kozlowski static int s5m_rtc_suspend(struct device *dev)
654222ead7fSKrzysztof Kozlowski {
655222ead7fSKrzysztof Kozlowski 	struct s5m_rtc_info *info = dev_get_drvdata(dev);
656222ead7fSKrzysztof Kozlowski 	int ret = 0;
657222ead7fSKrzysztof Kozlowski 
658222ead7fSKrzysztof Kozlowski 	if (device_may_wakeup(dev))
659222ead7fSKrzysztof Kozlowski 		ret = enable_irq_wake(info->irq);
660222ead7fSKrzysztof Kozlowski 
661222ead7fSKrzysztof Kozlowski 	return ret;
662222ead7fSKrzysztof Kozlowski }
663222ead7fSKrzysztof Kozlowski 
664222ead7fSKrzysztof Kozlowski static SIMPLE_DEV_PM_OPS(s5m_rtc_pm_ops, s5m_rtc_suspend, s5m_rtc_resume);
665222ead7fSKrzysztof Kozlowski 
6665bccae6eSSangbeom Kim static const struct platform_device_id s5m_rtc_id[] = {
6675bccae6eSSangbeom Kim 	{ "s5m-rtc", 0 },
6685bccae6eSSangbeom Kim };
6695bccae6eSSangbeom Kim 
6705bccae6eSSangbeom Kim static struct platform_driver s5m_rtc_driver = {
6715bccae6eSSangbeom Kim 	.driver		= {
6725bccae6eSSangbeom Kim 		.name	= "s5m-rtc",
6735bccae6eSSangbeom Kim 		.owner	= THIS_MODULE,
674222ead7fSKrzysztof Kozlowski 		.pm	= &s5m_rtc_pm_ops,
6755bccae6eSSangbeom Kim 	},
6765bccae6eSSangbeom Kim 	.probe		= s5m_rtc_probe,
6775bccae6eSSangbeom Kim 	.shutdown	= s5m_rtc_shutdown,
6785bccae6eSSangbeom Kim 	.id_table	= s5m_rtc_id,
6795bccae6eSSangbeom Kim };
6805bccae6eSSangbeom Kim 
6815bccae6eSSangbeom Kim module_platform_driver(s5m_rtc_driver);
6825bccae6eSSangbeom Kim 
6835bccae6eSSangbeom Kim /* Module information */
6845bccae6eSSangbeom Kim MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
6855bccae6eSSangbeom Kim MODULE_DESCRIPTION("Samsung S5M RTC driver");
6865bccae6eSSangbeom Kim MODULE_LICENSE("GPL");
6875bccae6eSSangbeom Kim MODULE_ALIAS("platform:s5m-rtc");
688