Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * drivers/rtc/rtc-spear.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2010 ST Microelectronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Rajeev Kumar<rajeev-dlh.kumar@st.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This file is licensed under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * License version 2. This program is licensed "as is" without any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * warranty of any kind, whether express or implied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/bcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* RTC registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define TIME_REG		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define DATE_REG		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define ALARM_TIME_REG		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define ALARM_DATE_REG		0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define CTRL_REG		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define STATUS_REG		0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* TIME_REG & ALARM_TIME_REG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define SECONDS_UNITS		(0xf<<0)	/* seconds units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define SECONDS_TENS		(0x7<<4)	/* seconds tens position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define MINUTES_UNITS		(0xf<<8)	/* minutes units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define MINUTES_TENS		(0x7<<12)	/* minutes tens position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define HOURS_UNITS		(0xf<<16)	/* hours units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define HOURS_TENS		(0x3<<20)	/* hours tens position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* DATE_REG & ALARM_DATE_REG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define DAYS_UNITS		(0xf<<0)	/* days units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define DAYS_TENS		(0x3<<4)	/* days tens position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define MONTHS_UNITS		(0xf<<8)	/* months units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define MONTHS_TENS		(0x1<<12)	/* months tens position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define YEARS_UNITS		(0xf<<16)	/* years units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define YEARS_TENS		(0xf<<20)	/* years tens position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define YEARS_HUNDREDS		(0xf<<24)	/* years hundereds position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define YEARS_MILLENIUMS	(0xf<<28)	/* years millenium position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /* MASK SHIFT TIME_REG & ALARM_TIME_REG*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define SECOND_SHIFT		0x00		/* seconds units */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define MINUTE_SHIFT		0x08		/* minutes units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define HOUR_SHIFT		0x10		/* hours units position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define MDAY_SHIFT		0x00		/* Month day shift */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define MONTH_SHIFT		0x08		/* Month shift */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define YEAR_SHIFT		0x10		/* Year shift */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define SECOND_MASK		0x7F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define MIN_MASK		0x7F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define HOUR_MASK		0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define DAY_MASK		0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define MONTH_MASK		0x7F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define YEAR_MASK		0xFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) /* date reg equal to time reg, for debug only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define TIME_BYP		(1<<9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define INT_ENABLE		(1<<31)		/* interrupt enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /* STATUS_REG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define CLK_UNCONNECTED		(1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define PEND_WR_TIME		(1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define PEND_WR_DATE		(1<<3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define LOST_WR_TIME		(1<<4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define LOST_WR_DATE		(1<<5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define RTC_INT_MASK		(1<<31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define STATUS_BUSY		(PEND_WR_TIME | PEND_WR_DATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define STATUS_FAIL		(LOST_WR_TIME | LOST_WR_DATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) struct spear_rtc_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct rtc_device *rtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	void __iomem *ioaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned int irq_wake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static inline void spear_rtc_clear_interrupt(struct spear_rtc_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	spin_lock_irqsave(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	val = readl(config->ioaddr + STATUS_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	val |= RTC_INT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	writel(val, config->ioaddr + STATUS_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	spin_unlock_irqrestore(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline void spear_rtc_enable_interrupt(struct spear_rtc_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	val = readl(config->ioaddr + CTRL_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!(val & INT_ENABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		spear_rtc_clear_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		val |= INT_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		writel(val, config->ioaddr + CTRL_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static inline void spear_rtc_disable_interrupt(struct spear_rtc_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	val = readl(config->ioaddr + CTRL_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (val & INT_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		val &= ~INT_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		writel(val, config->ioaddr + CTRL_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline int is_write_complete(struct spear_rtc_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	spin_lock_irqsave(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if ((readl(config->ioaddr + STATUS_REG)) & STATUS_FAIL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	spin_unlock_irqrestore(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void rtc_wait_not_busy(struct spear_rtc_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int status, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* Assuming BUSY may stay active for 80 msec) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	for (count = 0; count < 80; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		spin_lock_irqsave(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		status = readl(config->ioaddr + STATUS_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		spin_unlock_irqrestore(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if ((status & STATUS_BUSY) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		/* check status busy, after each msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static irqreturn_t spear_rtc_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct spear_rtc_config *config = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsigned long flags, events = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	unsigned int irq_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	spin_lock_irqsave(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	irq_data = readl(config->ioaddr + STATUS_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	spin_unlock_irqrestore(&config->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if ((irq_data & RTC_INT_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		spear_rtc_clear_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		events = RTC_IRQF | RTC_AF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		rtc_update_irq(config->rtc, 1, events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static void tm2bcd(struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	tm->tm_sec = bin2bcd(tm->tm_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	tm->tm_min = bin2bcd(tm->tm_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	tm->tm_hour = bin2bcd(tm->tm_hour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	tm->tm_mday = bin2bcd(tm->tm_mday);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	tm->tm_mon = bin2bcd(tm->tm_mon + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	tm->tm_year = bin2bcd(tm->tm_year);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void bcd2tm(struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	tm->tm_sec = bcd2bin(tm->tm_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	tm->tm_min = bcd2bin(tm->tm_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	tm->tm_hour = bcd2bin(tm->tm_hour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	tm->tm_mday = bcd2bin(tm->tm_mday);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	/* epoch == 1900 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	tm->tm_year = bcd2bin(tm->tm_year);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * spear_rtc_read_time - set the time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @dev: rtc device in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * @tm: holds date and time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * This function read time and date. On success it will return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * otherwise -ve error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int spear_rtc_read_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct spear_rtc_config *config = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	unsigned int time, date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* we don't report wday/yday/isdst ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	rtc_wait_not_busy(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	time = readl(config->ioaddr + TIME_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	date = readl(config->ioaddr + DATE_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	tm->tm_sec = (time >> SECOND_SHIFT) & SECOND_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	tm->tm_min = (time >> MINUTE_SHIFT) & MIN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	tm->tm_hour = (time >> HOUR_SHIFT) & HOUR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	tm->tm_mday = (date >> MDAY_SHIFT) & DAY_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	tm->tm_mon = (date >> MONTH_SHIFT) & MONTH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	tm->tm_year = (date >> YEAR_SHIFT) & YEAR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	bcd2tm(tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * spear_rtc_set_time - set the time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * @dev: rtc device in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * @tm: holds date and time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * This function set time and date. On success it will return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * otherwise -ve error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int spear_rtc_set_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct spear_rtc_config *config = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	unsigned int time, date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	tm2bcd(tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	rtc_wait_not_busy(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	time = (tm->tm_sec << SECOND_SHIFT) | (tm->tm_min << MINUTE_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		(tm->tm_hour << HOUR_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	date = (tm->tm_mday << MDAY_SHIFT) | (tm->tm_mon << MONTH_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		(tm->tm_year << YEAR_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	writel(time, config->ioaddr + TIME_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	writel(date, config->ioaddr + DATE_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return is_write_complete(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * spear_rtc_read_alarm - read the alarm time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * @dev: rtc device in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * @alm: holds alarm date and time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * This function read alarm time and date. On success it will return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * otherwise -ve error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static int spear_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct spear_rtc_config *config = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	unsigned int time, date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	rtc_wait_not_busy(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	time = readl(config->ioaddr + ALARM_TIME_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	date = readl(config->ioaddr + ALARM_DATE_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	alm->time.tm_sec = (time >> SECOND_SHIFT) & SECOND_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	alm->time.tm_min = (time >> MINUTE_SHIFT) & MIN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	alm->time.tm_hour = (time >> HOUR_SHIFT) & HOUR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	alm->time.tm_mday = (date >> MDAY_SHIFT) & DAY_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	alm->time.tm_mon = (date >> MONTH_SHIFT) & MONTH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	alm->time.tm_year = (date >> YEAR_SHIFT) & YEAR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	bcd2tm(&alm->time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	alm->enabled = readl(config->ioaddr + CTRL_REG) & INT_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * spear_rtc_set_alarm - set the alarm time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * @dev: rtc device in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * @alm: holds alarm date and time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * This function set alarm time and date. On success it will return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * otherwise -ve error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int spear_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct spear_rtc_config *config = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	unsigned int time, date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	tm2bcd(&alm->time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	rtc_wait_not_busy(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	time = (alm->time.tm_sec << SECOND_SHIFT) | (alm->time.tm_min <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			MINUTE_SHIFT) |	(alm->time.tm_hour << HOUR_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	date = (alm->time.tm_mday << MDAY_SHIFT) | (alm->time.tm_mon <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			MONTH_SHIFT) | (alm->time.tm_year << YEAR_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	writel(time, config->ioaddr + ALARM_TIME_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	writel(date, config->ioaddr + ALARM_DATE_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	err = is_write_complete(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (alm->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		spear_rtc_enable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		spear_rtc_disable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int spear_alarm_irq_enable(struct device *dev, unsigned int enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	struct spear_rtc_config *config = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	spear_rtc_clear_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	switch (enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		/* alarm off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		spear_rtc_disable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		/* alarm on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		spear_rtc_enable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static const struct rtc_class_ops spear_rtc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	.read_time = spear_rtc_read_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	.set_time = spear_rtc_set_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	.read_alarm = spear_rtc_read_alarm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	.set_alarm = spear_rtc_set_alarm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	.alarm_irq_enable = spear_alarm_irq_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static int spear_rtc_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct spear_rtc_config *config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (!config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	/* alarm irqs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	status = devm_request_irq(&pdev->dev, irq, spear_rtc_irq, 0, pdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		dev_err(&pdev->dev, "Alarm interrupt IRQ%d already claimed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 				irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	config->ioaddr = devm_platform_ioremap_resource(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	if (IS_ERR(config->ioaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		return PTR_ERR(config->ioaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	config->clk = devm_clk_get(&pdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (IS_ERR(config->clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return PTR_ERR(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	status = clk_prepare_enable(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	spin_lock_init(&config->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	platform_set_drvdata(pdev, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	config->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 					&spear_rtc_ops, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (IS_ERR(config->rtc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				PTR_ERR(config->rtc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		status = PTR_ERR(config->rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		goto err_disable_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	config->rtc->uie_unsupported = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (!device_can_wakeup(&pdev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		device_init_wakeup(&pdev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) err_disable_clock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	clk_disable_unprepare(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static int spear_rtc_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct spear_rtc_config *config = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	spear_rtc_disable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	clk_disable_unprepare(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	device_init_wakeup(&pdev->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static int spear_rtc_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	struct spear_rtc_config *config = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (device_may_wakeup(&pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		if (!enable_irq_wake(irq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			config->irq_wake = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		spear_rtc_disable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		clk_disable(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static int spear_rtc_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct spear_rtc_config *config = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	if (device_may_wakeup(&pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		if (config->irq_wake) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			disable_irq_wake(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			config->irq_wake = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		clk_enable(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		spear_rtc_enable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static SIMPLE_DEV_PM_OPS(spear_rtc_pm_ops, spear_rtc_suspend, spear_rtc_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static void spear_rtc_shutdown(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	struct spear_rtc_config *config = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	spear_rtc_disable_interrupt(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	clk_disable(config->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static const struct of_device_id spear_rtc_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	{ .compatible = "st,spear600-rtc" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) MODULE_DEVICE_TABLE(of, spear_rtc_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static struct platform_driver spear_rtc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	.probe = spear_rtc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	.remove = spear_rtc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	.shutdown = spear_rtc_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		.name = "rtc-spear",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		.pm = &spear_rtc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		.of_match_table = of_match_ptr(spear_rtc_id_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) module_platform_driver(spear_rtc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) MODULE_ALIAS("platform:rtc-spear");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) MODULE_AUTHOR("Rajeev Kumar <rajeev-dlh.kumar@st.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) MODULE_DESCRIPTION("ST SPEAr Realtime Clock Driver (RTC)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) MODULE_LICENSE("GPL");