| Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 2 | /* | 
 | 3 |  * Real-time clock driver for MPC5121 | 
 | 4 |  * | 
 | 5 |  * Copyright 2007, Domen Puncer <domen.puncer@telargo.com> | 
 | 6 |  * Copyright 2008, Freescale Semiconductor, Inc. All rights reserved. | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 7 |  * Copyright 2011, Dmitry Eremin-Solenikov | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 8 |  */ | 
 | 9 |  | 
 | 10 | #include <linux/init.h> | 
 | 11 | #include <linux/module.h> | 
 | 12 | #include <linux/rtc.h> | 
| Sachin Kamat | c8a6046 | 2013-02-21 16:44:28 -0800 | [diff] [blame] | 13 | #include <linux/of.h> | 
| Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 14 | #include <linux/of_address.h> | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 15 | #include <linux/of_device.h> | 
| Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 16 | #include <linux/of_irq.h> | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 17 | #include <linux/of_platform.h> | 
 | 18 | #include <linux/io.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 20 |  | 
 | 21 | struct mpc5121_rtc_regs { | 
 | 22 | 	u8 set_time;		/* RTC + 0x00 */ | 
 | 23 | 	u8 hour_set;		/* RTC + 0x01 */ | 
 | 24 | 	u8 minute_set;		/* RTC + 0x02 */ | 
 | 25 | 	u8 second_set;		/* RTC + 0x03 */ | 
 | 26 |  | 
 | 27 | 	u8 set_date;		/* RTC + 0x04 */ | 
 | 28 | 	u8 month_set;		/* RTC + 0x05 */ | 
 | 29 | 	u8 weekday_set;		/* RTC + 0x06 */ | 
 | 30 | 	u8 date_set;		/* RTC + 0x07 */ | 
 | 31 |  | 
 | 32 | 	u8 write_sw;		/* RTC + 0x08 */ | 
 | 33 | 	u8 sw_set;		/* RTC + 0x09 */ | 
 | 34 | 	u16 year_set;		/* RTC + 0x0a */ | 
 | 35 |  | 
 | 36 | 	u8 alm_enable;		/* RTC + 0x0c */ | 
 | 37 | 	u8 alm_hour_set;	/* RTC + 0x0d */ | 
 | 38 | 	u8 alm_min_set;		/* RTC + 0x0e */ | 
 | 39 | 	u8 int_enable;		/* RTC + 0x0f */ | 
 | 40 |  | 
 | 41 | 	u8 reserved1; | 
 | 42 | 	u8 hour;		/* RTC + 0x11 */ | 
 | 43 | 	u8 minute;		/* RTC + 0x12 */ | 
 | 44 | 	u8 second;		/* RTC + 0x13 */ | 
 | 45 |  | 
 | 46 | 	u8 month;		/* RTC + 0x14 */ | 
 | 47 | 	u8 wday_mday;		/* RTC + 0x15 */ | 
 | 48 | 	u16 year;		/* RTC + 0x16 */ | 
 | 49 |  | 
 | 50 | 	u8 int_alm;		/* RTC + 0x18 */ | 
 | 51 | 	u8 int_sw;		/* RTC + 0x19 */ | 
 | 52 | 	u8 alm_status;		/* RTC + 0x1a */ | 
 | 53 | 	u8 sw_minute;		/* RTC + 0x1b */ | 
 | 54 |  | 
 | 55 | 	u8 bus_error_1;		/* RTC + 0x1c */ | 
 | 56 | 	u8 int_day;		/* RTC + 0x1d */ | 
 | 57 | 	u8 int_min;		/* RTC + 0x1e */ | 
 | 58 | 	u8 int_sec;		/* RTC + 0x1f */ | 
 | 59 |  | 
 | 60 | 	/* | 
 | 61 | 	 * target_time: | 
 | 62 | 	 *	intended to be used for hibernation but hibernation | 
 | 63 | 	 *	does not work on silicon rev 1.5 so use it for non-volatile | 
 | 64 | 	 *	storage of offset between the actual_time register and linux | 
 | 65 | 	 *	time | 
 | 66 | 	 */ | 
 | 67 | 	u32 target_time;	/* RTC + 0x20 */ | 
 | 68 | 	/* | 
 | 69 | 	 * actual_time: | 
| Sachin Kamat | 07d27f2 | 2013-07-03 15:05:57 -0700 | [diff] [blame] | 70 | 	 *	readonly time since VBAT_RTC was last connected | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 71 | 	 */ | 
 | 72 | 	u32 actual_time;	/* RTC + 0x24 */ | 
 | 73 | 	u32 keep_alive;		/* RTC + 0x28 */ | 
 | 74 | }; | 
 | 75 |  | 
 | 76 | struct mpc5121_rtc_data { | 
 | 77 | 	unsigned irq; | 
 | 78 | 	unsigned irq_periodic; | 
 | 79 | 	struct mpc5121_rtc_regs __iomem *regs; | 
 | 80 | 	struct rtc_device *rtc; | 
 | 81 | 	struct rtc_wkalrm wkalarm; | 
 | 82 | }; | 
 | 83 |  | 
 | 84 | /* | 
 | 85 |  * Update second/minute/hour registers. | 
 | 86 |  * | 
 | 87 |  * This is just so alarm will work. | 
 | 88 |  */ | 
 | 89 | static void mpc5121_rtc_update_smh(struct mpc5121_rtc_regs __iomem *regs, | 
 | 90 | 				   struct rtc_time *tm) | 
 | 91 | { | 
 | 92 | 	out_8(®s->second_set, tm->tm_sec); | 
 | 93 | 	out_8(®s->minute_set, tm->tm_min); | 
 | 94 | 	out_8(®s->hour_set, tm->tm_hour); | 
 | 95 |  | 
 | 96 | 	/* set time sequence */ | 
 | 97 | 	out_8(®s->set_time, 0x1); | 
 | 98 | 	out_8(®s->set_time, 0x3); | 
 | 99 | 	out_8(®s->set_time, 0x1); | 
 | 100 | 	out_8(®s->set_time, 0x0); | 
 | 101 | } | 
 | 102 |  | 
 | 103 | static int mpc5121_rtc_read_time(struct device *dev, struct rtc_time *tm) | 
 | 104 | { | 
 | 105 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 106 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 107 | 	unsigned long now; | 
 | 108 |  | 
 | 109 | 	/* | 
 | 110 | 	 * linux time is actual_time plus the offset saved in target_time | 
 | 111 | 	 */ | 
 | 112 | 	now = in_be32(®s->actual_time) + in_be32(®s->target_time); | 
 | 113 |  | 
 | 114 | 	rtc_time_to_tm(now, tm); | 
 | 115 |  | 
 | 116 | 	/* | 
 | 117 | 	 * update second minute hour registers | 
 | 118 | 	 * so alarms will work | 
 | 119 | 	 */ | 
 | 120 | 	mpc5121_rtc_update_smh(regs, tm); | 
 | 121 |  | 
| Alexandre Belloni | ab62670 | 2018-02-19 16:23:55 +0100 | [diff] [blame] | 122 | 	return 0; | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 123 | } | 
 | 124 |  | 
 | 125 | static int mpc5121_rtc_set_time(struct device *dev, struct rtc_time *tm) | 
 | 126 | { | 
 | 127 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 128 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 129 | 	int ret; | 
 | 130 | 	unsigned long now; | 
 | 131 |  | 
 | 132 | 	/* | 
 | 133 | 	 * The actual_time register is read only so we write the offset | 
 | 134 | 	 * between it and linux time to the target_time register. | 
 | 135 | 	 */ | 
 | 136 | 	ret = rtc_tm_to_time(tm, &now); | 
 | 137 | 	if (ret == 0) | 
 | 138 | 		out_be32(®s->target_time, now - in_be32(®s->actual_time)); | 
 | 139 |  | 
 | 140 | 	/* | 
 | 141 | 	 * update second minute hour registers | 
 | 142 | 	 * so alarms will work | 
 | 143 | 	 */ | 
 | 144 | 	mpc5121_rtc_update_smh(regs, tm); | 
 | 145 |  | 
 | 146 | 	return 0; | 
 | 147 | } | 
 | 148 |  | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 149 | static int mpc5200_rtc_read_time(struct device *dev, struct rtc_time *tm) | 
 | 150 | { | 
 | 151 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 152 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 153 | 	int tmp; | 
 | 154 |  | 
 | 155 | 	tm->tm_sec = in_8(®s->second); | 
 | 156 | 	tm->tm_min = in_8(®s->minute); | 
 | 157 |  | 
 | 158 | 	/* 12 hour format? */ | 
 | 159 | 	if (in_8(®s->hour) & 0x20) | 
 | 160 | 		tm->tm_hour = (in_8(®s->hour) >> 1) + | 
 | 161 | 			(in_8(®s->hour) & 1 ? 12 : 0); | 
 | 162 | 	else | 
 | 163 | 		tm->tm_hour = in_8(®s->hour); | 
 | 164 |  | 
 | 165 | 	tmp = in_8(®s->wday_mday); | 
 | 166 | 	tm->tm_mday = tmp & 0x1f; | 
 | 167 | 	tm->tm_mon = in_8(®s->month) - 1; | 
 | 168 | 	tm->tm_year = in_be16(®s->year) - 1900; | 
 | 169 | 	tm->tm_wday = (tmp >> 5) % 7; | 
 | 170 | 	tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); | 
 | 171 | 	tm->tm_isdst = 0; | 
 | 172 |  | 
 | 173 | 	return 0; | 
 | 174 | } | 
 | 175 |  | 
 | 176 | static int mpc5200_rtc_set_time(struct device *dev, struct rtc_time *tm) | 
 | 177 | { | 
 | 178 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 179 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 180 |  | 
 | 181 | 	mpc5121_rtc_update_smh(regs, tm); | 
 | 182 |  | 
 | 183 | 	/* date */ | 
 | 184 | 	out_8(®s->month_set, tm->tm_mon + 1); | 
 | 185 | 	out_8(®s->weekday_set, tm->tm_wday ? tm->tm_wday : 7); | 
 | 186 | 	out_8(®s->date_set, tm->tm_mday); | 
 | 187 | 	out_be16(®s->year_set, tm->tm_year + 1900); | 
 | 188 |  | 
 | 189 | 	/* set date sequence */ | 
 | 190 | 	out_8(®s->set_date, 0x1); | 
 | 191 | 	out_8(®s->set_date, 0x3); | 
 | 192 | 	out_8(®s->set_date, 0x1); | 
 | 193 | 	out_8(®s->set_date, 0x0); | 
 | 194 |  | 
 | 195 | 	return 0; | 
 | 196 | } | 
 | 197 |  | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 198 | static int mpc5121_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 
 | 199 | { | 
 | 200 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 201 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 202 |  | 
 | 203 | 	*alarm = rtc->wkalarm; | 
 | 204 |  | 
 | 205 | 	alarm->pending = in_8(®s->alm_status); | 
 | 206 |  | 
 | 207 | 	return 0; | 
 | 208 | } | 
 | 209 |  | 
 | 210 | static int mpc5121_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 
 | 211 | { | 
 | 212 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 213 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 214 |  | 
 | 215 | 	/* | 
 | 216 | 	 * the alarm has no seconds so deal with it | 
 | 217 | 	 */ | 
 | 218 | 	if (alarm->time.tm_sec) { | 
 | 219 | 		alarm->time.tm_sec = 0; | 
 | 220 | 		alarm->time.tm_min++; | 
 | 221 | 		if (alarm->time.tm_min >= 60) { | 
 | 222 | 			alarm->time.tm_min = 0; | 
 | 223 | 			alarm->time.tm_hour++; | 
 | 224 | 			if (alarm->time.tm_hour >= 24) | 
 | 225 | 				alarm->time.tm_hour = 0; | 
 | 226 | 		} | 
 | 227 | 	} | 
 | 228 |  | 
 | 229 | 	alarm->time.tm_mday = -1; | 
 | 230 | 	alarm->time.tm_mon = -1; | 
 | 231 | 	alarm->time.tm_year = -1; | 
 | 232 |  | 
 | 233 | 	out_8(®s->alm_min_set, alarm->time.tm_min); | 
 | 234 | 	out_8(®s->alm_hour_set, alarm->time.tm_hour); | 
 | 235 |  | 
 | 236 | 	out_8(®s->alm_enable, alarm->enabled); | 
 | 237 |  | 
 | 238 | 	rtc->wkalarm = *alarm; | 
 | 239 | 	return 0; | 
 | 240 | } | 
 | 241 |  | 
 | 242 | static irqreturn_t mpc5121_rtc_handler(int irq, void *dev) | 
 | 243 | { | 
 | 244 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata((struct device *)dev); | 
 | 245 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 246 |  | 
 | 247 | 	if (in_8(®s->int_alm)) { | 
 | 248 | 		/* acknowledge and clear status */ | 
 | 249 | 		out_8(®s->int_alm, 1); | 
 | 250 | 		out_8(®s->alm_status, 1); | 
 | 251 |  | 
 | 252 | 		rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); | 
 | 253 | 		return IRQ_HANDLED; | 
 | 254 | 	} | 
 | 255 |  | 
 | 256 | 	return IRQ_NONE; | 
 | 257 | } | 
 | 258 |  | 
 | 259 | static irqreturn_t mpc5121_rtc_handler_upd(int irq, void *dev) | 
 | 260 | { | 
 | 261 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata((struct device *)dev); | 
 | 262 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 263 |  | 
 | 264 | 	if (in_8(®s->int_sec) && (in_8(®s->int_enable) & 0x1)) { | 
 | 265 | 		/* acknowledge */ | 
 | 266 | 		out_8(®s->int_sec, 1); | 
 | 267 |  | 
 | 268 | 		rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_UF); | 
 | 269 | 		return IRQ_HANDLED; | 
 | 270 | 	} | 
 | 271 |  | 
 | 272 | 	return IRQ_NONE; | 
 | 273 | } | 
 | 274 |  | 
 | 275 | static int mpc5121_rtc_alarm_irq_enable(struct device *dev, | 
 | 276 | 					unsigned int enabled) | 
 | 277 | { | 
 | 278 | 	struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); | 
 | 279 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 280 | 	int val; | 
 | 281 |  | 
 | 282 | 	if (enabled) | 
 | 283 | 		val = 1; | 
 | 284 | 	else | 
 | 285 | 		val = 0; | 
 | 286 |  | 
 | 287 | 	out_8(®s->alm_enable, val); | 
 | 288 | 	rtc->wkalarm.enabled = val; | 
 | 289 |  | 
 | 290 | 	return 0; | 
 | 291 | } | 
 | 292 |  | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 293 | static const struct rtc_class_ops mpc5121_rtc_ops = { | 
 | 294 | 	.read_time = mpc5121_rtc_read_time, | 
 | 295 | 	.set_time = mpc5121_rtc_set_time, | 
 | 296 | 	.read_alarm = mpc5121_rtc_read_alarm, | 
 | 297 | 	.set_alarm = mpc5121_rtc_set_alarm, | 
 | 298 | 	.alarm_irq_enable = mpc5121_rtc_alarm_irq_enable, | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 299 | }; | 
 | 300 |  | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 301 | static const struct rtc_class_ops mpc5200_rtc_ops = { | 
 | 302 | 	.read_time = mpc5200_rtc_read_time, | 
 | 303 | 	.set_time = mpc5200_rtc_set_time, | 
 | 304 | 	.read_alarm = mpc5121_rtc_read_alarm, | 
 | 305 | 	.set_alarm = mpc5121_rtc_set_alarm, | 
 | 306 | 	.alarm_irq_enable = mpc5121_rtc_alarm_irq_enable, | 
 | 307 | }; | 
 | 308 |  | 
| Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 309 | static int mpc5121_rtc_probe(struct platform_device *op) | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 310 | { | 
 | 311 | 	struct mpc5121_rtc_data *rtc; | 
 | 312 | 	int err = 0; | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 313 |  | 
| Jingoo Han | 073bf42 | 2013-07-03 15:07:07 -0700 | [diff] [blame] | 314 | 	rtc = devm_kzalloc(&op->dev, sizeof(*rtc), GFP_KERNEL); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 315 | 	if (!rtc) | 
 | 316 | 		return -ENOMEM; | 
 | 317 |  | 
| Grant Likely | 295bdd9 | 2010-06-02 14:06:09 -0600 | [diff] [blame] | 318 | 	rtc->regs = of_iomap(op->dev.of_node, 0); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 319 | 	if (!rtc->regs) { | 
 | 320 | 		dev_err(&op->dev, "%s: couldn't map io space\n", __func__); | 
| Jingoo Han | 073bf42 | 2013-07-03 15:07:07 -0700 | [diff] [blame] | 321 | 		return -ENOSYS; | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 322 | 	} | 
 | 323 |  | 
 | 324 | 	device_init_wakeup(&op->dev, 1); | 
 | 325 |  | 
| Jingoo Han | ad87a76 | 2013-07-03 15:07:47 -0700 | [diff] [blame] | 326 | 	platform_set_drvdata(op, rtc); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 327 |  | 
| Grant Likely | 295bdd9 | 2010-06-02 14:06:09 -0600 | [diff] [blame] | 328 | 	rtc->irq = irq_of_parse_and_map(op->dev.of_node, 1); | 
| Yong Zhang | 2f6e5f9 | 2012-03-23 15:02:34 -0700 | [diff] [blame] | 329 | 	err = request_irq(rtc->irq, mpc5121_rtc_handler, 0, | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 330 | 						"mpc5121-rtc", &op->dev); | 
 | 331 | 	if (err) { | 
 | 332 | 		dev_err(&op->dev, "%s: could not request irq: %i\n", | 
 | 333 | 							__func__, rtc->irq); | 
 | 334 | 		goto out_dispose; | 
 | 335 | 	} | 
 | 336 |  | 
| Grant Likely | 295bdd9 | 2010-06-02 14:06:09 -0600 | [diff] [blame] | 337 | 	rtc->irq_periodic = irq_of_parse_and_map(op->dev.of_node, 0); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 338 | 	err = request_irq(rtc->irq_periodic, mpc5121_rtc_handler_upd, | 
| Yong Zhang | 2f6e5f9 | 2012-03-23 15:02:34 -0700 | [diff] [blame] | 339 | 				0, "mpc5121-rtc_upd", &op->dev); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 340 | 	if (err) { | 
 | 341 | 		dev_err(&op->dev, "%s: could not request irq: %i\n", | 
 | 342 | 						__func__, rtc->irq_periodic); | 
 | 343 | 		goto out_dispose2; | 
 | 344 | 	} | 
 | 345 |  | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 346 | 	if (of_device_is_compatible(op->dev.of_node, "fsl,mpc5121-rtc")) { | 
 | 347 | 		u32 ka; | 
 | 348 | 		ka = in_be32(&rtc->regs->keep_alive); | 
 | 349 | 		if (ka & 0x02) { | 
 | 350 | 			dev_warn(&op->dev, | 
 | 351 | 				"mpc5121-rtc: Battery or oscillator failure!\n"); | 
 | 352 | 			out_be32(&rtc->regs->keep_alive, ka); | 
 | 353 | 		} | 
 | 354 |  | 
| Jingoo Han | 073bf42 | 2013-07-03 15:07:07 -0700 | [diff] [blame] | 355 | 		rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5121-rtc", | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 356 | 						&mpc5121_rtc_ops, THIS_MODULE); | 
 | 357 | 	} else { | 
| Jingoo Han | 073bf42 | 2013-07-03 15:07:07 -0700 | [diff] [blame] | 358 | 		rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5200-rtc", | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 359 | 						&mpc5200_rtc_ops, THIS_MODULE); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 360 | 	} | 
 | 361 |  | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 362 | 	if (IS_ERR(rtc->rtc)) { | 
 | 363 | 		err = PTR_ERR(rtc->rtc); | 
 | 364 | 		goto out_free_irq; | 
 | 365 | 	} | 
| John Stultz | e48b5e8 | 2012-04-24 13:43:35 -0700 | [diff] [blame] | 366 | 	rtc->rtc->uie_unsupported = 1; | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 367 |  | 
 | 368 | 	return 0; | 
 | 369 |  | 
 | 370 | out_free_irq: | 
 | 371 | 	free_irq(rtc->irq_periodic, &op->dev); | 
 | 372 | out_dispose2: | 
 | 373 | 	irq_dispose_mapping(rtc->irq_periodic); | 
 | 374 | 	free_irq(rtc->irq, &op->dev); | 
 | 375 | out_dispose: | 
 | 376 | 	irq_dispose_mapping(rtc->irq); | 
 | 377 | 	iounmap(rtc->regs); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 378 |  | 
 | 379 | 	return err; | 
 | 380 | } | 
 | 381 |  | 
| Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 382 | static int mpc5121_rtc_remove(struct platform_device *op) | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 383 | { | 
| Jingoo Han | ad87a76 | 2013-07-03 15:07:47 -0700 | [diff] [blame] | 384 | 	struct mpc5121_rtc_data *rtc = platform_get_drvdata(op); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 385 | 	struct mpc5121_rtc_regs __iomem *regs = rtc->regs; | 
 | 386 |  | 
 | 387 | 	/* disable interrupt, so there are no nasty surprises */ | 
 | 388 | 	out_8(®s->alm_enable, 0); | 
 | 389 | 	out_8(®s->int_enable, in_8(®s->int_enable) & ~0x1); | 
 | 390 |  | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 391 | 	iounmap(rtc->regs); | 
 | 392 | 	free_irq(rtc->irq, &op->dev); | 
 | 393 | 	free_irq(rtc->irq_periodic, &op->dev); | 
 | 394 | 	irq_dispose_mapping(rtc->irq); | 
 | 395 | 	irq_dispose_mapping(rtc->irq_periodic); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 396 |  | 
 | 397 | 	return 0; | 
 | 398 | } | 
 | 399 |  | 
| Sachin Kamat | c8a6046 | 2013-02-21 16:44:28 -0800 | [diff] [blame] | 400 | #ifdef CONFIG_OF | 
| Uwe Kleine-König | a28885b | 2014-10-13 15:52:39 -0700 | [diff] [blame] | 401 | static const struct of_device_id mpc5121_rtc_match[] = { | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 402 | 	{ .compatible = "fsl,mpc5121-rtc", }, | 
| Dmitry Eremin-Solenikov | 955dbea | 2011-07-25 17:13:30 -0700 | [diff] [blame] | 403 | 	{ .compatible = "fsl,mpc5200-rtc", }, | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 404 | 	{}, | 
 | 405 | }; | 
| Javier Martinez Canillas | 73798d5 | 2015-08-27 13:52:02 +0200 | [diff] [blame] | 406 | MODULE_DEVICE_TABLE(of, mpc5121_rtc_match); | 
| Sachin Kamat | c8a6046 | 2013-02-21 16:44:28 -0800 | [diff] [blame] | 407 | #endif | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 408 |  | 
| Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 409 | static struct platform_driver mpc5121_rtc_driver = { | 
| Grant Likely | 295bdd9 | 2010-06-02 14:06:09 -0600 | [diff] [blame] | 410 | 	.driver = { | 
 | 411 | 		.name = "mpc5121-rtc", | 
| Sachin Kamat | c8a6046 | 2013-02-21 16:44:28 -0800 | [diff] [blame] | 412 | 		.of_match_table = of_match_ptr(mpc5121_rtc_match), | 
| Grant Likely | 295bdd9 | 2010-06-02 14:06:09 -0600 | [diff] [blame] | 413 | 	}, | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 414 | 	.probe = mpc5121_rtc_probe, | 
| Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 415 | 	.remove = mpc5121_rtc_remove, | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 416 | }; | 
 | 417 |  | 
| Axel Lin | 0c4eae6 | 2012-01-10 15:10:48 -0800 | [diff] [blame] | 418 | module_platform_driver(mpc5121_rtc_driver); | 
| Anatolij Gustschin | 50aae72 | 2010-02-16 10:47:35 -0700 | [diff] [blame] | 419 |  | 
 | 420 | MODULE_LICENSE("GPL"); | 
 | 421 | MODULE_AUTHOR("John Rigby <jcrigby@gmail.com>"); |