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