rtc: davinci: use unlock/lock mechanism
The RTC module contains a kicker mechanism to prevent any spurious writes from changing the register values. To set the time, you must first unlock the TC registers, update them and then lock. Signed-off-by: Dario Binacchi <dariobin@libero.it> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> Link: https://lore.kernel.org/r/20210602203805.11494-6-dariobin@libero.it
This commit is contained in:
		
							parent
							
								
									79250ef3e2
								
							
						
					
					
						commit
						c7c7c8db00
					
				|  | @ -16,6 +16,18 @@ | ||||||
| #define RTC_BASE DAVINCI_RTC_BASE | #define RTC_BASE DAVINCI_RTC_BASE | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | static void davinci_rtc_lock(struct davinci_rtc *rtc) | ||||||
|  | { | ||||||
|  | 	writel(0, &rtc->kick0r); | ||||||
|  | 	writel(0, &rtc->kick1r); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void davinci_rtc_unlock(struct davinci_rtc *rtc) | ||||||
|  | { | ||||||
|  | 	writel(RTC_KICK0R_WE, &rtc->kick0r); | ||||||
|  | 	writel(RTC_KICK1R_WE, &rtc->kick1r); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int davinci_rtc_wait_not_busy(struct davinci_rtc *rtc) | static int davinci_rtc_wait_not_busy(struct davinci_rtc *rtc) | ||||||
| { | { | ||||||
| 	int count; | 	int count; | ||||||
|  | @ -89,6 +101,7 @@ int rtc_set(struct rtc_time *tmp) | ||||||
| 	if (ret) | 	if (ret) | ||||||
| 		return ret; | 		return ret; | ||||||
| 
 | 
 | ||||||
|  | 	davinci_rtc_unlock(rtc); | ||||||
| 	writeb(bin2bcd(tmp->tm_year % 100), &rtc->year); | 	writeb(bin2bcd(tmp->tm_year % 100), &rtc->year); | ||||||
| 	writeb(bin2bcd(tmp->tm_mon), &rtc->month); | 	writeb(bin2bcd(tmp->tm_mon), &rtc->month); | ||||||
| 
 | 
 | ||||||
|  | @ -97,6 +110,7 @@ int rtc_set(struct rtc_time *tmp) | ||||||
| 	writeb(bin2bcd(tmp->tm_hour), &rtc->hours); | 	writeb(bin2bcd(tmp->tm_hour), &rtc->hours); | ||||||
| 	writeb(bin2bcd(tmp->tm_min), &rtc->minutes); | 	writeb(bin2bcd(tmp->tm_min), &rtc->minutes); | ||||||
| 	writeb(bin2bcd(tmp->tm_sec), &rtc->second); | 	writeb(bin2bcd(tmp->tm_sec), &rtc->second); | ||||||
|  | 	davinci_rtc_lock(rtc); | ||||||
| 
 | 
 | ||||||
| 	debug("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n", | 	debug("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n", | ||||||
| 	      tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, | 	      tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue