Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 1 | /* drivers/rtc/rtc-s3c.c |
| 2 | * |
Atul Dahiya | e48add8 | 2010-07-20 12:19:14 +0530 | [diff] [blame] | 3 | * Copyright (c) 2010 Samsung Electronics Co., Ltd. |
| 4 | * http://www.samsung.com/ |
| 5 | * |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 6 | * Copyright (c) 2004,2006 Simtec Electronics |
| 7 | * Ben Dooks, <ben@simtec.co.uk> |
| 8 | * http://armlinux.simtec.co.uk/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * S3C2410/S3C2440/S3C24XX Internal RTC Driver |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/rtc.h> |
| 24 | #include <linux/bcd.h> |
| 25 | #include <linux/clk.h> |
Robert P. J. Day | 9974b6e | 2008-02-06 01:38:42 -0800 | [diff] [blame] | 26 | #include <linux/log2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Thomas Abraham | 39ce408 | 2011-10-24 14:49:04 +0200 | [diff] [blame] | 28 | #include <linux/of.h> |
Marek Szyprowski | 64704c9 | 2019-01-18 14:28:37 +0100 | [diff] [blame^] | 29 | #include <linux/of_device.h> |
Sachin Kamat | dbd9acb | 2012-07-30 14:41:48 -0700 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
| 31 | #include <linux/io.h> |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 32 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 33 | #include <asm/irq.h> |
Arnd Bergmann | b9d7c5d | 2013-03-05 12:04:37 +0100 | [diff] [blame] | 34 | #include "rtc-s3c.h" |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 35 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 36 | struct s3c_rtc { |
| 37 | struct device *dev; |
| 38 | struct rtc_device *rtc; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 39 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 40 | void __iomem *base; |
| 41 | struct clk *rtc_clk; |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 42 | struct clk *rtc_src_clk; |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 43 | bool alarm_enabled; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 44 | |
Krzysztof Kozlowski | 6b72086 | 2017-06-16 21:28:05 +0200 | [diff] [blame] | 45 | const struct s3c_rtc_data *data; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 46 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 47 | int irq_alarm; |
| 48 | int irq_tick; |
| 49 | |
| 50 | spinlock_t pie_lock; |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 51 | spinlock_t alarm_lock; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 52 | |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 53 | int ticnt_save; |
| 54 | int ticnt_en_save; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 55 | bool wake_en; |
| 56 | }; |
| 57 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 58 | struct s3c_rtc_data { |
| 59 | int max_user_freq; |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 60 | bool needs_src_clk; |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 61 | |
| 62 | void (*irq_handler) (struct s3c_rtc *info, int mask); |
| 63 | void (*set_freq) (struct s3c_rtc *info, int freq); |
| 64 | void (*enable_tick) (struct s3c_rtc *info, struct seq_file *seq); |
| 65 | void (*select_tick_clk) (struct s3c_rtc *info); |
| 66 | void (*save_tick_cnt) (struct s3c_rtc *info); |
| 67 | void (*restore_tick_cnt) (struct s3c_rtc *info); |
| 68 | void (*enable) (struct s3c_rtc *info); |
| 69 | void (*disable) (struct s3c_rtc *info); |
| 70 | }; |
| 71 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 72 | static int s3c_rtc_enable_clk(struct s3c_rtc *info) |
Donggeun Kim | 88cee8f | 2011-09-14 16:22:19 -0700 | [diff] [blame] | 73 | { |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 74 | int ret; |
Donggeun Kim | 88cee8f | 2011-09-14 16:22:19 -0700 | [diff] [blame] | 75 | |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 76 | ret = clk_enable(info->rtc_clk); |
| 77 | if (ret) |
| 78 | return ret; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 79 | |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 80 | if (info->data->needs_src_clk) { |
| 81 | ret = clk_enable(info->rtc_src_clk); |
| 82 | if (ret) { |
| 83 | clk_disable(info->rtc_clk); |
| 84 | return ret; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 85 | } |
Joonyoung Shim | 1fb1c35 | 2015-08-12 19:21:46 +0900 | [diff] [blame] | 86 | } |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 87 | return 0; |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void s3c_rtc_disable_clk(struct s3c_rtc *info) |
| 91 | { |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 92 | if (info->data->needs_src_clk) |
| 93 | clk_disable(info->rtc_src_clk); |
| 94 | clk_disable(info->rtc_clk); |
Donggeun Kim | 88cee8f | 2011-09-14 16:22:19 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 97 | /* IRQ Handlers */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 98 | static irqreturn_t s3c_rtc_tickirq(int irq, void *id) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 99 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 100 | struct s3c_rtc *info = (struct s3c_rtc *)id; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 101 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 102 | if (info->data->irq_handler) |
| 103 | info->data->irq_handler(info, S3C2410_INTP_TIC); |
Atul Dahiya | 2f3478f | 2010-07-20 16:02:51 +0530 | [diff] [blame] | 104 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 105 | return IRQ_HANDLED; |
| 106 | } |
Atul Dahiya | 2f3478f | 2010-07-20 16:02:51 +0530 | [diff] [blame] | 107 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 108 | static irqreturn_t s3c_rtc_alarmirq(int irq, void *id) |
| 109 | { |
| 110 | struct s3c_rtc *info = (struct s3c_rtc *)id; |
| 111 | |
| 112 | if (info->data->irq_handler) |
| 113 | info->data->irq_handler(info, S3C2410_INTP_ALM); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 114 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 115 | return IRQ_HANDLED; |
| 116 | } |
| 117 | |
| 118 | /* Update control registers */ |
Axel Lin | 2ec38a0 | 2011-03-04 17:36:19 -0800 | [diff] [blame] | 119 | static int s3c_rtc_setaie(struct device *dev, unsigned int enabled) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 120 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 121 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 122 | unsigned long flags; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 123 | unsigned int tmp; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 124 | int ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 125 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 126 | dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 127 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 128 | ret = s3c_rtc_enable_clk(info); |
| 129 | if (ret) |
| 130 | return ret; |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 131 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 132 | tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 133 | |
Axel Lin | 2ec38a0 | 2011-03-04 17:36:19 -0800 | [diff] [blame] | 134 | if (enabled) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 135 | tmp |= S3C2410_RTCALM_ALMEN; |
| 136 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 137 | writeb(tmp, info->base + S3C2410_RTCALM); |
Axel Lin | 2ec38a0 | 2011-03-04 17:36:19 -0800 | [diff] [blame] | 138 | |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 139 | spin_lock_irqsave(&info->alarm_lock, flags); |
| 140 | |
| 141 | if (info->alarm_enabled && !enabled) |
| 142 | s3c_rtc_disable_clk(info); |
| 143 | else if (!info->alarm_enabled && enabled) |
| 144 | ret = s3c_rtc_enable_clk(info); |
| 145 | |
| 146 | info->alarm_enabled = enabled; |
| 147 | spin_unlock_irqrestore(&info->alarm_lock, flags); |
| 148 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 149 | s3c_rtc_disable_clk(info); |
Donggeun Kim | 88cee8f | 2011-09-14 16:22:19 -0700 | [diff] [blame] | 150 | |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 151 | return ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 154 | /* Set RTC frequency */ |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 155 | static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 156 | { |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 157 | int ret; |
| 158 | |
Jonathan Cameron | 5d2a503 | 2009-01-06 14:42:12 -0800 | [diff] [blame] | 159 | if (!is_power_of_2(freq)) |
| 160 | return -EINVAL; |
| 161 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 162 | ret = s3c_rtc_enable_clk(info); |
| 163 | if (ret) |
| 164 | return ret; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 165 | spin_lock_irq(&info->pie_lock); |
Ben Dooks | 773be7e | 2008-07-23 21:30:45 -0700 | [diff] [blame] | 166 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 167 | if (info->data->set_freq) |
| 168 | info->data->set_freq(info, freq); |
Maurus Cuelenaere | 9f4123b | 2010-05-24 14:33:43 -0700 | [diff] [blame] | 169 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 170 | spin_unlock_irq(&info->pie_lock); |
Alim Akhtar | 70c96df | 2016-07-05 15:28:53 +0530 | [diff] [blame] | 171 | s3c_rtc_disable_clk(info); |
Ben Dooks | 773be7e | 2008-07-23 21:30:45 -0700 | [diff] [blame] | 172 | |
| 173 | return 0; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* Time read/write */ |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 177 | static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) |
| 178 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 179 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 180 | unsigned int have_retried = 0; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 181 | int ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 182 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 183 | ret = s3c_rtc_enable_clk(info); |
| 184 | if (ret) |
| 185 | return ret; |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 186 | |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 187 | retry_get_time: |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 188 | rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); |
| 189 | rtc_tm->tm_hour = readb(info->base + S3C2410_RTCHOUR); |
| 190 | rtc_tm->tm_mday = readb(info->base + S3C2410_RTCDATE); |
| 191 | rtc_tm->tm_mon = readb(info->base + S3C2410_RTCMON); |
| 192 | rtc_tm->tm_year = readb(info->base + S3C2410_RTCYEAR); |
| 193 | rtc_tm->tm_sec = readb(info->base + S3C2410_RTCSEC); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 194 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 195 | /* the only way to work out whether the system was mid-update |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 196 | * when we read it is to check the second counter, and if it |
| 197 | * is zero, then we re-try the entire read |
| 198 | */ |
| 199 | |
| 200 | if (rtc_tm->tm_sec == 0 && !have_retried) { |
| 201 | have_retried = 1; |
| 202 | goto retry_get_time; |
| 203 | } |
| 204 | |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 205 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
| 206 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
| 207 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
| 208 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
| 209 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
| 210 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 211 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 212 | s3c_rtc_disable_clk(info); |
| 213 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 214 | rtc_tm->tm_year += 100; |
| 215 | rtc_tm->tm_mon -= 1; |
| 216 | |
Andy Shevchenko | 9a1bacf | 2018-12-04 23:23:25 +0200 | [diff] [blame] | 217 | dev_dbg(dev, "read time %ptR\n", rtc_tm); |
Alexandre Belloni | 22652ba | 2018-02-19 16:23:56 +0100 | [diff] [blame] | 218 | return 0; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) |
| 222 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 223 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Ben Dooks | 641741e | 2006-08-27 01:23:27 -0700 | [diff] [blame] | 224 | int year = tm->tm_year - 100; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 225 | int ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 226 | |
Andy Shevchenko | 9a1bacf | 2018-12-04 23:23:25 +0200 | [diff] [blame] | 227 | dev_dbg(dev, "set time %ptR\n", tm); |
Ben Dooks | 9a65451 | 2006-08-27 01:23:22 -0700 | [diff] [blame] | 228 | |
Ben Dooks | 641741e | 2006-08-27 01:23:27 -0700 | [diff] [blame] | 229 | /* we get around y2k by simply not supporting it */ |
| 230 | |
| 231 | if (year < 0 || year >= 100) { |
| 232 | dev_err(dev, "rtc only supports 100 years\n"); |
| 233 | return -EINVAL; |
| 234 | } |
| 235 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 236 | ret = s3c_rtc_enable_clk(info); |
| 237 | if (ret) |
| 238 | return ret; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 239 | |
| 240 | writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); |
| 241 | writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); |
| 242 | writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_RTCHOUR); |
| 243 | writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_RTCDATE); |
| 244 | writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); |
| 245 | writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); |
| 246 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 247 | s3c_rtc_disable_clk(info); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 253 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 254 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 255 | struct rtc_time *alm_tm = &alrm->time; |
| 256 | unsigned int alm_en; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 257 | int ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 258 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 259 | ret = s3c_rtc_enable_clk(info); |
| 260 | if (ret) |
| 261 | return ret; |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 262 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 263 | alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); |
| 264 | alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); |
| 265 | alm_tm->tm_hour = readb(info->base + S3C2410_ALMHOUR); |
| 266 | alm_tm->tm_mon = readb(info->base + S3C2410_ALMMON); |
| 267 | alm_tm->tm_mday = readb(info->base + S3C2410_ALMDATE); |
| 268 | alm_tm->tm_year = readb(info->base + S3C2410_ALMYEAR); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 269 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 270 | alm_en = readb(info->base + S3C2410_RTCALM); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 271 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 272 | s3c_rtc_disable_clk(info); |
| 273 | |
David Brownell | a2db8df | 2006-12-13 00:35:08 -0800 | [diff] [blame] | 274 | alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; |
| 275 | |
Andy Shevchenko | 9a1bacf | 2018-12-04 23:23:25 +0200 | [diff] [blame] | 276 | dev_dbg(dev, "read alarm %d, %ptR\n", alm_en, alm_tm); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 277 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 278 | /* decode the alarm enable field */ |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 279 | if (alm_en & S3C2410_RTCALM_SECEN) |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 280 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 281 | |
| 282 | if (alm_en & S3C2410_RTCALM_MINEN) |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 283 | alm_tm->tm_min = bcd2bin(alm_tm->tm_min); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 284 | |
| 285 | if (alm_en & S3C2410_RTCALM_HOUREN) |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 286 | alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 287 | |
| 288 | if (alm_en & S3C2410_RTCALM_DAYEN) |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 289 | alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 290 | |
| 291 | if (alm_en & S3C2410_RTCALM_MONEN) { |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 292 | alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 293 | alm_tm->tm_mon -= 1; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | if (alm_en & S3C2410_RTCALM_YEAREN) |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 297 | alm_tm->tm_year = bcd2bin(alm_tm->tm_year); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 303 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 304 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 305 | struct rtc_time *tm = &alrm->time; |
| 306 | unsigned int alrm_en; |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 307 | int ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 308 | |
Andy Shevchenko | 9a1bacf | 2018-12-04 23:23:25 +0200 | [diff] [blame] | 309 | dev_dbg(dev, "s3c_rtc_setalarm: %d, %ptR\n", alrm->enabled, tm); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 310 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 311 | ret = s3c_rtc_enable_clk(info); |
| 312 | if (ret) |
| 313 | return ret; |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 314 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 315 | alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; |
| 316 | writeb(0x00, info->base + S3C2410_RTCALM); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 317 | |
| 318 | if (tm->tm_sec < 60 && tm->tm_sec >= 0) { |
| 319 | alrm_en |= S3C2410_RTCALM_SECEN; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 320 | writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_ALMSEC); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | if (tm->tm_min < 60 && tm->tm_min >= 0) { |
| 324 | alrm_en |= S3C2410_RTCALM_MINEN; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 325 | writeb(bin2bcd(tm->tm_min), info->base + S3C2410_ALMMIN); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | if (tm->tm_hour < 24 && tm->tm_hour >= 0) { |
| 329 | alrm_en |= S3C2410_RTCALM_HOUREN; |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 330 | writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Krzysztof Kozlowski | fb4ac3c | 2015-11-01 20:49:04 +0900 | [diff] [blame] | 333 | if (tm->tm_mon < 12 && tm->tm_mon >= 0) { |
| 334 | alrm_en |= S3C2410_RTCALM_MONEN; |
| 335 | writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON); |
| 336 | } |
| 337 | |
| 338 | if (tm->tm_mday <= 31 && tm->tm_mday >= 1) { |
| 339 | alrm_en |= S3C2410_RTCALM_DAYEN; |
| 340 | writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_ALMDATE); |
| 341 | } |
| 342 | |
Jingoo Han | d4a48c2 | 2013-02-21 16:45:06 -0800 | [diff] [blame] | 343 | dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 344 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 345 | writeb(alrm_en, info->base + S3C2410_RTCALM); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 346 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 347 | s3c_rtc_setaie(dev, alrm->enabled); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 348 | |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 349 | s3c_rtc_disable_clk(info); |
| 350 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 354 | static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) |
| 355 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 356 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 357 | int ret; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 358 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 359 | ret = s3c_rtc_enable_clk(info); |
| 360 | if (ret) |
| 361 | return ret; |
Maurus Cuelenaere | 9f4123b | 2010-05-24 14:33:43 -0700 | [diff] [blame] | 362 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 363 | if (info->data->enable_tick) |
| 364 | info->data->enable_tick(info, seq); |
| 365 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 366 | s3c_rtc_disable_clk(info); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 367 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 368 | return 0; |
| 369 | } |
| 370 | |
David Brownell | ff8371a | 2006-09-30 23:28:17 -0700 | [diff] [blame] | 371 | static const struct rtc_class_ops s3c_rtcops = { |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 372 | .read_time = s3c_rtc_gettime, |
| 373 | .set_time = s3c_rtc_settime, |
| 374 | .read_alarm = s3c_rtc_getalarm, |
| 375 | .set_alarm = s3c_rtc_setalarm, |
Changhwan Youn | e6eb524 | 2010-10-27 15:33:09 -0700 | [diff] [blame] | 376 | .proc = s3c_rtc_proc, |
| 377 | .alarm_irq_enable = s3c_rtc_setaie, |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 380 | static void s3c24xx_rtc_enable(struct s3c_rtc *info) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 381 | { |
Chanwoo Choi | d67288d | 2014-10-13 15:52:31 -0700 | [diff] [blame] | 382 | unsigned int con, tmp; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 383 | |
Chanwoo Choi | d67288d | 2014-10-13 15:52:31 -0700 | [diff] [blame] | 384 | con = readw(info->base + S3C2410_RTCCON); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 385 | /* re-enable the device, and check it is ok */ |
| 386 | if ((con & S3C2410_RTCCON_RTCEN) == 0) { |
| 387 | dev_info(info->dev, "rtc disabled, re-enabling\n"); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 388 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 389 | tmp = readw(info->base + S3C2410_RTCCON); |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 390 | writew(tmp | S3C2410_RTCCON_RTCEN, info->base + S3C2410_RTCCON); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 391 | } |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 392 | |
| 393 | if (con & S3C2410_RTCCON_CNTSEL) { |
| 394 | dev_info(info->dev, "removing RTCCON_CNTSEL\n"); |
| 395 | |
| 396 | tmp = readw(info->base + S3C2410_RTCCON); |
| 397 | writew(tmp & ~S3C2410_RTCCON_CNTSEL, |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 398 | info->base + S3C2410_RTCCON); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | if (con & S3C2410_RTCCON_CLKRST) { |
| 402 | dev_info(info->dev, "removing RTCCON_CLKRST\n"); |
| 403 | |
| 404 | tmp = readw(info->base + S3C2410_RTCCON); |
| 405 | writew(tmp & ~S3C2410_RTCCON_CLKRST, |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 406 | info->base + S3C2410_RTCCON); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 407 | } |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static void s3c24xx_rtc_disable(struct s3c_rtc *info) |
| 411 | { |
| 412 | unsigned int con; |
| 413 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 414 | con = readw(info->base + S3C2410_RTCCON); |
| 415 | con &= ~S3C2410_RTCCON_RTCEN; |
| 416 | writew(con, info->base + S3C2410_RTCCON); |
| 417 | |
| 418 | con = readb(info->base + S3C2410_TICNT); |
| 419 | con &= ~S3C2410_TICNT_ENABLE; |
| 420 | writeb(con, info->base + S3C2410_TICNT); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void s3c6410_rtc_disable(struct s3c_rtc *info) |
| 424 | { |
| 425 | unsigned int con; |
| 426 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 427 | con = readw(info->base + S3C2410_RTCCON); |
| 428 | con &= ~S3C64XX_RTCCON_TICEN; |
| 429 | con &= ~S3C2410_RTCCON_RTCEN; |
| 430 | writew(con, info->base + S3C2410_RTCCON); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 433 | static int s3c_rtc_remove(struct platform_device *pdev) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 434 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 435 | struct s3c_rtc *info = platform_get_drvdata(pdev); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 436 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 437 | s3c_rtc_setaie(info->dev, 0); |
| 438 | |
Joonyoung Shim | 7f23a93 | 2015-08-11 20:28:19 +0900 | [diff] [blame] | 439 | if (info->data->needs_src_clk) |
| 440 | clk_unprepare(info->rtc_src_clk); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 441 | clk_unprepare(info->rtc_clk); |
Atul Dahiya | e48add8 | 2010-07-20 12:19:14 +0530 | [diff] [blame] | 442 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 446 | static int s3c_rtc_probe(struct platform_device *pdev) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 447 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 448 | struct s3c_rtc *info = NULL; |
Changhwan Youn | e1df962 | 2010-10-27 15:33:10 -0700 | [diff] [blame] | 449 | struct rtc_time rtc_tm; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 450 | struct resource *res; |
| 451 | int ret; |
| 452 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 453 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
| 454 | if (!info) |
| 455 | return -ENOMEM; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 456 | |
| 457 | /* find the IRQs */ |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 458 | info->irq_tick = platform_get_irq(pdev, 1); |
| 459 | if (info->irq_tick < 0) { |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 460 | dev_err(&pdev->dev, "no irq for rtc tick\n"); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 461 | return info->irq_tick; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 464 | info->dev = &pdev->dev; |
Marek Szyprowski | 64704c9 | 2019-01-18 14:28:37 +0100 | [diff] [blame^] | 465 | info->data = of_device_get_match_data(&pdev->dev); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 466 | if (!info->data) { |
| 467 | dev_err(&pdev->dev, "failed getting s3c_rtc_data\n"); |
| 468 | return -EINVAL; |
| 469 | } |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 470 | spin_lock_init(&info->pie_lock); |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 471 | spin_lock_init(&info->alarm_lock); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 472 | |
| 473 | platform_set_drvdata(pdev, info); |
| 474 | |
| 475 | info->irq_alarm = platform_get_irq(pdev, 0); |
| 476 | if (info->irq_alarm < 0) { |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 477 | dev_err(&pdev->dev, "no irq for alarm\n"); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 478 | return info->irq_alarm; |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Jingoo Han | d4a48c2 | 2013-02-21 16:45:06 -0800 | [diff] [blame] | 481 | dev_dbg(&pdev->dev, "s3c2410_rtc: tick irq %d, alarm irq %d\n", |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 482 | info->irq_tick, info->irq_alarm); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 483 | |
| 484 | /* get the memory region */ |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 485 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 486 | info->base = devm_ioremap_resource(&pdev->dev, res); |
| 487 | if (IS_ERR(info->base)) |
| 488 | return PTR_ERR(info->base); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 489 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 490 | info->rtc_clk = devm_clk_get(&pdev->dev, "rtc"); |
| 491 | if (IS_ERR(info->rtc_clk)) { |
Javier Martinez Canillas | ae6e00b | 2016-03-14 22:38:38 -0300 | [diff] [blame] | 492 | ret = PTR_ERR(info->rtc_clk); |
| 493 | if (ret != -EPROBE_DEFER) |
| 494 | dev_err(&pdev->dev, "failed to find rtc clock\n"); |
| 495 | else |
| 496 | dev_dbg(&pdev->dev, "probe deferred due to missing rtc clk\n"); |
| 497 | return ret; |
Atul Dahiya | e48add8 | 2010-07-20 12:19:14 +0530 | [diff] [blame] | 498 | } |
Krzysztof Kozlowski | 9903f68 | 2017-06-16 21:28:06 +0200 | [diff] [blame] | 499 | ret = clk_prepare_enable(info->rtc_clk); |
| 500 | if (ret) |
| 501 | return ret; |
Atul Dahiya | e48add8 | 2010-07-20 12:19:14 +0530 | [diff] [blame] | 502 | |
Marek Szyprowski | eaf3a65 | 2014-10-29 14:50:38 -0700 | [diff] [blame] | 503 | if (info->data->needs_src_clk) { |
| 504 | info->rtc_src_clk = devm_clk_get(&pdev->dev, "rtc_src"); |
| 505 | if (IS_ERR(info->rtc_src_clk)) { |
Javier Martinez Canillas | ae6e00b | 2016-03-14 22:38:38 -0300 | [diff] [blame] | 506 | ret = PTR_ERR(info->rtc_src_clk); |
| 507 | if (ret != -EPROBE_DEFER) |
| 508 | dev_err(&pdev->dev, |
| 509 | "failed to find rtc source clock\n"); |
| 510 | else |
| 511 | dev_dbg(&pdev->dev, |
| 512 | "probe deferred due to missing rtc src clk\n"); |
Krzysztof Kozlowski | 8768e7b | 2017-06-16 21:28:02 +0200 | [diff] [blame] | 513 | goto err_src_clk; |
Marek Szyprowski | eaf3a65 | 2014-10-29 14:50:38 -0700 | [diff] [blame] | 514 | } |
Krzysztof Kozlowski | 9903f68 | 2017-06-16 21:28:06 +0200 | [diff] [blame] | 515 | ret = clk_prepare_enable(info->rtc_src_clk); |
| 516 | if (ret) |
| 517 | goto err_src_clk; |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 518 | } |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 519 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 520 | /* check to see if everything is setup correctly */ |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 521 | if (info->data->enable) |
| 522 | info->data->enable(info); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 523 | |
Jingoo Han | d4a48c2 | 2013-02-21 16:45:06 -0800 | [diff] [blame] | 524 | dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n", |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 525 | readw(info->base + S3C2410_RTCCON)); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 526 | |
Yauhen Kharuzhy | 51b7616 | 2008-10-29 14:01:16 -0700 | [diff] [blame] | 527 | device_init_wakeup(&pdev->dev, 1); |
| 528 | |
Krzysztof Kozlowski | 202fe4c | 2015-04-16 12:45:57 -0700 | [diff] [blame] | 529 | /* Check RTC Time */ |
Krzysztof Kozlowski | 492da68 | 2015-04-16 12:46:08 -0700 | [diff] [blame] | 530 | if (s3c_rtc_gettime(&pdev->dev, &rtc_tm)) { |
Krzysztof Kozlowski | 202fe4c | 2015-04-16 12:45:57 -0700 | [diff] [blame] | 531 | rtc_tm.tm_year = 100; |
| 532 | rtc_tm.tm_mon = 0; |
| 533 | rtc_tm.tm_mday = 1; |
| 534 | rtc_tm.tm_hour = 0; |
| 535 | rtc_tm.tm_min = 0; |
| 536 | rtc_tm.tm_sec = 0; |
| 537 | |
| 538 | s3c_rtc_settime(&pdev->dev, &rtc_tm); |
| 539 | |
| 540 | dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); |
| 541 | } |
| 542 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 543 | /* register RTC and exit */ |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 544 | info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 545 | THIS_MODULE); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 546 | if (IS_ERR(info->rtc)) { |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 547 | dev_err(&pdev->dev, "cannot attach rtc\n"); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 548 | ret = PTR_ERR(info->rtc); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 549 | goto err_nortc; |
| 550 | } |
| 551 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 552 | ret = devm_request_irq(&pdev->dev, info->irq_alarm, s3c_rtc_alarmirq, |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 553 | 0, "s3c2410-rtc alarm", info); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 554 | if (ret) { |
| 555 | dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_alarm, ret); |
| 556 | goto err_nortc; |
| 557 | } |
| 558 | |
| 559 | ret = devm_request_irq(&pdev->dev, info->irq_tick, s3c_rtc_tickirq, |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 560 | 0, "s3c2410-rtc tick", info); |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 561 | if (ret) { |
| 562 | dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_tick, ret); |
| 563 | goto err_nortc; |
| 564 | } |
Maurus Cuelenaere | eaa6e4d | 2010-06-04 14:14:46 -0700 | [diff] [blame] | 565 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 566 | if (info->data->select_tick_clk) |
| 567 | info->data->select_tick_clk(info); |
Heiko Stuebner | 25c1a24 | 2011-12-24 10:52:19 +0900 | [diff] [blame] | 568 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 569 | s3c_rtc_setfreq(info, 1); |
Maurus Cuelenaere | e893de5 | 2010-06-04 14:14:44 -0700 | [diff] [blame] | 570 | |
Marek Szyprowski | 5a5b614 | 2019-01-21 12:09:30 +0100 | [diff] [blame] | 571 | s3c_rtc_disable_clk(info); |
| 572 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 573 | return 0; |
| 574 | |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 575 | err_nortc: |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 576 | if (info->data->disable) |
| 577 | info->data->disable(info); |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 578 | |
| 579 | if (info->data->needs_src_clk) |
| 580 | clk_disable_unprepare(info->rtc_src_clk); |
Krzysztof Kozlowski | 8768e7b | 2017-06-16 21:28:02 +0200 | [diff] [blame] | 581 | err_src_clk: |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 582 | clk_disable_unprepare(info->rtc_clk); |
Atul Dahiya | e48add8 | 2010-07-20 12:19:14 +0530 | [diff] [blame] | 583 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 584 | return ret; |
| 585 | } |
| 586 | |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 587 | #ifdef CONFIG_PM_SLEEP |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 588 | |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 589 | static int s3c_rtc_suspend(struct device *dev) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 590 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 591 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 592 | int ret; |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 593 | |
Krzysztof Kozlowski | 498bcf3 | 2017-06-16 21:28:07 +0200 | [diff] [blame] | 594 | ret = s3c_rtc_enable_clk(info); |
| 595 | if (ret) |
| 596 | return ret; |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 597 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 598 | /* save TICNT for anyone using periodic interrupts */ |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 599 | if (info->data->save_tick_cnt) |
| 600 | info->data->save_tick_cnt(info); |
| 601 | |
| 602 | if (info->data->disable) |
| 603 | info->data->disable(info); |
Vladimir Zapolskiy | f501ed5 | 2010-09-22 13:05:13 -0700 | [diff] [blame] | 604 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 605 | if (device_may_wakeup(dev) && !info->wake_en) { |
| 606 | if (enable_irq_wake(info->irq_alarm) == 0) |
| 607 | info->wake_en = true; |
Ben Dooks | 52cd4e5 | 2011-05-11 15:13:28 -0700 | [diff] [blame] | 608 | else |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 609 | dev_err(dev, "enable_irq_wake failed\n"); |
Ben Dooks | 52cd4e5 | 2011-05-11 15:13:28 -0700 | [diff] [blame] | 610 | } |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 611 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 612 | return 0; |
| 613 | } |
| 614 | |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 615 | static int s3c_rtc_resume(struct device *dev) |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 616 | { |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 617 | struct s3c_rtc *info = dev_get_drvdata(dev); |
Maurus Cuelenaere | 9f4123b | 2010-05-24 14:33:43 -0700 | [diff] [blame] | 618 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 619 | if (info->data->enable) |
| 620 | info->data->enable(info); |
| 621 | |
| 622 | if (info->data->restore_tick_cnt) |
| 623 | info->data->restore_tick_cnt(info); |
Vladimir Zapolskiy | f501ed5 | 2010-09-22 13:05:13 -0700 | [diff] [blame] | 624 | |
Chanwoo Choi | 24e1455 | 2015-04-16 12:45:15 -0700 | [diff] [blame] | 625 | s3c_rtc_disable_clk(info); |
| 626 | |
Chanwoo Choi | 19be09f | 2014-10-13 15:52:28 -0700 | [diff] [blame] | 627 | if (device_may_wakeup(dev) && info->wake_en) { |
| 628 | disable_irq_wake(info->irq_alarm); |
| 629 | info->wake_en = false; |
Ben Dooks | 52cd4e5 | 2011-05-11 15:13:28 -0700 | [diff] [blame] | 630 | } |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 631 | |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 632 | return 0; |
| 633 | } |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 634 | #endif |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 635 | static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume); |
| 636 | |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 637 | static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) |
| 638 | { |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 639 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) |
| 643 | { |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 644 | rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); |
| 645 | writeb(mask, info->base + S3C2410_INTP); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq) |
| 649 | { |
| 650 | unsigned int tmp = 0; |
| 651 | int val; |
| 652 | |
| 653 | tmp = readb(info->base + S3C2410_TICNT); |
| 654 | tmp &= S3C2410_TICNT_ENABLE; |
| 655 | |
| 656 | val = (info->rtc->max_user_freq / freq) - 1; |
| 657 | tmp |= val; |
| 658 | |
| 659 | writel(tmp, info->base + S3C2410_TICNT); |
| 660 | } |
| 661 | |
| 662 | static void s3c2416_rtc_setfreq(struct s3c_rtc *info, int freq) |
| 663 | { |
| 664 | unsigned int tmp = 0; |
| 665 | int val; |
| 666 | |
| 667 | tmp = readb(info->base + S3C2410_TICNT); |
| 668 | tmp &= S3C2410_TICNT_ENABLE; |
| 669 | |
| 670 | val = (info->rtc->max_user_freq / freq) - 1; |
| 671 | |
| 672 | tmp |= S3C2443_TICNT_PART(val); |
| 673 | writel(S3C2443_TICNT1_PART(val), info->base + S3C2443_TICNT1); |
| 674 | |
| 675 | writel(S3C2416_TICNT2_PART(val), info->base + S3C2416_TICNT2); |
| 676 | |
| 677 | writel(tmp, info->base + S3C2410_TICNT); |
| 678 | } |
| 679 | |
| 680 | static void s3c2443_rtc_setfreq(struct s3c_rtc *info, int freq) |
| 681 | { |
| 682 | unsigned int tmp = 0; |
| 683 | int val; |
| 684 | |
| 685 | tmp = readb(info->base + S3C2410_TICNT); |
| 686 | tmp &= S3C2410_TICNT_ENABLE; |
| 687 | |
| 688 | val = (info->rtc->max_user_freq / freq) - 1; |
| 689 | |
| 690 | tmp |= S3C2443_TICNT_PART(val); |
| 691 | writel(S3C2443_TICNT1_PART(val), info->base + S3C2443_TICNT1); |
| 692 | |
| 693 | writel(tmp, info->base + S3C2410_TICNT); |
| 694 | } |
| 695 | |
| 696 | static void s3c6410_rtc_setfreq(struct s3c_rtc *info, int freq) |
| 697 | { |
| 698 | int val; |
| 699 | |
| 700 | val = (info->rtc->max_user_freq / freq) - 1; |
| 701 | writel(val, info->base + S3C2410_TICNT); |
| 702 | } |
| 703 | |
| 704 | static void s3c24xx_rtc_enable_tick(struct s3c_rtc *info, struct seq_file *seq) |
| 705 | { |
| 706 | unsigned int ticnt; |
| 707 | |
| 708 | ticnt = readb(info->base + S3C2410_TICNT); |
| 709 | ticnt &= S3C2410_TICNT_ENABLE; |
| 710 | |
| 711 | seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no"); |
| 712 | } |
| 713 | |
| 714 | static void s3c2416_rtc_select_tick_clk(struct s3c_rtc *info) |
| 715 | { |
| 716 | unsigned int con; |
| 717 | |
| 718 | con = readw(info->base + S3C2410_RTCCON); |
| 719 | con |= S3C2443_RTCCON_TICSEL; |
| 720 | writew(con, info->base + S3C2410_RTCCON); |
| 721 | } |
| 722 | |
| 723 | static void s3c6410_rtc_enable_tick(struct s3c_rtc *info, struct seq_file *seq) |
| 724 | { |
| 725 | unsigned int ticnt; |
| 726 | |
| 727 | ticnt = readw(info->base + S3C2410_RTCCON); |
| 728 | ticnt &= S3C64XX_RTCCON_TICEN; |
| 729 | |
| 730 | seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no"); |
| 731 | } |
| 732 | |
| 733 | static void s3c24xx_rtc_save_tick_cnt(struct s3c_rtc *info) |
| 734 | { |
| 735 | info->ticnt_save = readb(info->base + S3C2410_TICNT); |
| 736 | } |
| 737 | |
| 738 | static void s3c24xx_rtc_restore_tick_cnt(struct s3c_rtc *info) |
| 739 | { |
| 740 | writeb(info->ticnt_save, info->base + S3C2410_TICNT); |
| 741 | } |
| 742 | |
| 743 | static void s3c6410_rtc_save_tick_cnt(struct s3c_rtc *info) |
| 744 | { |
| 745 | info->ticnt_en_save = readw(info->base + S3C2410_RTCCON); |
| 746 | info->ticnt_en_save &= S3C64XX_RTCCON_TICEN; |
| 747 | info->ticnt_save = readl(info->base + S3C2410_TICNT); |
| 748 | } |
| 749 | |
| 750 | static void s3c6410_rtc_restore_tick_cnt(struct s3c_rtc *info) |
| 751 | { |
| 752 | unsigned int con; |
| 753 | |
| 754 | writel(info->ticnt_save, info->base + S3C2410_TICNT); |
| 755 | if (info->ticnt_en_save) { |
| 756 | con = readw(info->base + S3C2410_RTCCON); |
Krzysztof Kozlowski | fc1afe6 | 2017-06-16 21:28:03 +0200 | [diff] [blame] | 757 | writew(con | info->ticnt_en_save, info->base + S3C2410_RTCCON); |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | static struct s3c_rtc_data const s3c2410_rtc_data = { |
| 762 | .max_user_freq = 128, |
| 763 | .irq_handler = s3c24xx_rtc_irq, |
| 764 | .set_freq = s3c2410_rtc_setfreq, |
| 765 | .enable_tick = s3c24xx_rtc_enable_tick, |
| 766 | .save_tick_cnt = s3c24xx_rtc_save_tick_cnt, |
| 767 | .restore_tick_cnt = s3c24xx_rtc_restore_tick_cnt, |
| 768 | .enable = s3c24xx_rtc_enable, |
| 769 | .disable = s3c24xx_rtc_disable, |
| 770 | }; |
| 771 | |
| 772 | static struct s3c_rtc_data const s3c2416_rtc_data = { |
| 773 | .max_user_freq = 32768, |
| 774 | .irq_handler = s3c24xx_rtc_irq, |
| 775 | .set_freq = s3c2416_rtc_setfreq, |
| 776 | .enable_tick = s3c24xx_rtc_enable_tick, |
| 777 | .select_tick_clk = s3c2416_rtc_select_tick_clk, |
| 778 | .save_tick_cnt = s3c24xx_rtc_save_tick_cnt, |
| 779 | .restore_tick_cnt = s3c24xx_rtc_restore_tick_cnt, |
| 780 | .enable = s3c24xx_rtc_enable, |
| 781 | .disable = s3c24xx_rtc_disable, |
| 782 | }; |
| 783 | |
| 784 | static struct s3c_rtc_data const s3c2443_rtc_data = { |
| 785 | .max_user_freq = 32768, |
| 786 | .irq_handler = s3c24xx_rtc_irq, |
| 787 | .set_freq = s3c2443_rtc_setfreq, |
| 788 | .enable_tick = s3c24xx_rtc_enable_tick, |
| 789 | .select_tick_clk = s3c2416_rtc_select_tick_clk, |
| 790 | .save_tick_cnt = s3c24xx_rtc_save_tick_cnt, |
| 791 | .restore_tick_cnt = s3c24xx_rtc_restore_tick_cnt, |
| 792 | .enable = s3c24xx_rtc_enable, |
| 793 | .disable = s3c24xx_rtc_disable, |
| 794 | }; |
| 795 | |
| 796 | static struct s3c_rtc_data const s3c6410_rtc_data = { |
| 797 | .max_user_freq = 32768, |
Javier Martinez Canillas | 8792f777 | 2015-03-12 16:25:49 -0700 | [diff] [blame] | 798 | .needs_src_clk = true, |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 799 | .irq_handler = s3c6410_rtc_irq, |
| 800 | .set_freq = s3c6410_rtc_setfreq, |
| 801 | .enable_tick = s3c6410_rtc_enable_tick, |
| 802 | .save_tick_cnt = s3c6410_rtc_save_tick_cnt, |
| 803 | .restore_tick_cnt = s3c6410_rtc_restore_tick_cnt, |
| 804 | .enable = s3c24xx_rtc_enable, |
| 805 | .disable = s3c6410_rtc_disable, |
Tushar Behera | c3cba92 | 2012-04-12 12:49:14 -0700 | [diff] [blame] | 806 | }; |
| 807 | |
Thomas Abraham | 39ce408 | 2011-10-24 14:49:04 +0200 | [diff] [blame] | 808 | static const struct of_device_id s3c_rtc_dt_match[] = { |
Heiko Stuebner | d2524ca | 2011-12-24 10:52:14 +0900 | [diff] [blame] | 809 | { |
Tushar Behera | cd1e6f9 | 2012-04-12 12:49:14 -0700 | [diff] [blame] | 810 | .compatible = "samsung,s3c2410-rtc", |
Krzysztof Kozlowski | 21df6fe | 2017-06-16 21:28:04 +0200 | [diff] [blame] | 811 | .data = &s3c2410_rtc_data, |
Heiko Stuebner | d2524ca | 2011-12-24 10:52:14 +0900 | [diff] [blame] | 812 | }, { |
Tushar Behera | cd1e6f9 | 2012-04-12 12:49:14 -0700 | [diff] [blame] | 813 | .compatible = "samsung,s3c2416-rtc", |
Krzysztof Kozlowski | 21df6fe | 2017-06-16 21:28:04 +0200 | [diff] [blame] | 814 | .data = &s3c2416_rtc_data, |
Heiko Stuebner | 25c1a24 | 2011-12-24 10:52:19 +0900 | [diff] [blame] | 815 | }, { |
Tushar Behera | cd1e6f9 | 2012-04-12 12:49:14 -0700 | [diff] [blame] | 816 | .compatible = "samsung,s3c2443-rtc", |
Krzysztof Kozlowski | 21df6fe | 2017-06-16 21:28:04 +0200 | [diff] [blame] | 817 | .data = &s3c2443_rtc_data, |
Heiko Stuebner | 25c1a24 | 2011-12-24 10:52:19 +0900 | [diff] [blame] | 818 | }, { |
Tushar Behera | cd1e6f9 | 2012-04-12 12:49:14 -0700 | [diff] [blame] | 819 | .compatible = "samsung,s3c6410-rtc", |
Krzysztof Kozlowski | 21df6fe | 2017-06-16 21:28:04 +0200 | [diff] [blame] | 820 | .data = &s3c6410_rtc_data, |
Chanwoo Choi | df9e26d | 2014-10-13 15:52:35 -0700 | [diff] [blame] | 821 | }, { |
| 822 | .compatible = "samsung,exynos3250-rtc", |
Krzysztof Kozlowski | 21df6fe | 2017-06-16 21:28:04 +0200 | [diff] [blame] | 823 | .data = &s3c6410_rtc_data, |
Heiko Stuebner | d2524ca | 2011-12-24 10:52:14 +0900 | [diff] [blame] | 824 | }, |
Chanwoo Choi | ae05c95 | 2014-10-13 15:52:33 -0700 | [diff] [blame] | 825 | { /* sentinel */ }, |
Thomas Abraham | 39ce408 | 2011-10-24 14:49:04 +0200 | [diff] [blame] | 826 | }; |
| 827 | MODULE_DEVICE_TABLE(of, s3c_rtc_dt_match); |
Maurus Cuelenaere | 9f4123b | 2010-05-24 14:33:43 -0700 | [diff] [blame] | 828 | |
| 829 | static struct platform_driver s3c_rtc_driver = { |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 830 | .probe = s3c_rtc_probe, |
Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 831 | .remove = s3c_rtc_remove, |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 832 | .driver = { |
Maurus Cuelenaere | 9f4123b | 2010-05-24 14:33:43 -0700 | [diff] [blame] | 833 | .name = "s3c-rtc", |
Jingoo Han | 32e445a | 2013-04-29 16:19:27 -0700 | [diff] [blame] | 834 | .pm = &s3c_rtc_pm_ops, |
Sachin Kamat | 04a373f | 2012-12-17 16:02:52 -0800 | [diff] [blame] | 835 | .of_match_table = of_match_ptr(s3c_rtc_dt_match), |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 836 | }, |
| 837 | }; |
Axel Lin | 0c4eae6 | 2012-01-10 15:10:48 -0800 | [diff] [blame] | 838 | module_platform_driver(s3c_rtc_driver); |
Ben Dooks | 1add678 | 2006-07-01 04:36:26 -0700 | [diff] [blame] | 839 | |
| 840 | MODULE_DESCRIPTION("Samsung S3C RTC Driver"); |
| 841 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
| 842 | MODULE_LICENSE("GPL"); |
Kay Sievers | ad28a07 | 2008-04-10 21:29:25 -0700 | [diff] [blame] | 843 | MODULE_ALIAS("platform:s3c2410-rtc"); |