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