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