18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * OMAP IP block custom reset and preprogramming stubs 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2012 Texas Instruments, Inc. 58c2ecf20Sopenharmony_ci * Paul Walmsley 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * A small number of IP blocks need custom reset and preprogramming 88c2ecf20Sopenharmony_ci * functions. The stubs in this file provide a standard way for the 98c2ecf20Sopenharmony_ci * hwmod code to call these functions, which are to be located under 108c2ecf20Sopenharmony_ci * drivers/. 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or 138c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License as 148c2ecf20Sopenharmony_ci * published by the Free Software Foundation version 2. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * This program is distributed "as is" WITHOUT ANY WARRANTY of any 178c2ecf20Sopenharmony_ci * kind, whether express or implied; without even the implied warranty 188c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 198c2ecf20Sopenharmony_ci * GNU General Public License for more details. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 228c2ecf20Sopenharmony_ci * along with this program; if not, write to the Free Software 238c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 248c2ecf20Sopenharmony_ci * 02110-1301 USA 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci#include <linux/kernel.h> 278c2ecf20Sopenharmony_ci#include <linux/errno.h> 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#include "omap_hwmod.h" 308c2ecf20Sopenharmony_ci#include "common.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define OMAP_RTC_STATUS_REG 0x44 338c2ecf20Sopenharmony_ci#define OMAP_RTC_KICK0_REG 0x6c 348c2ecf20Sopenharmony_ci#define OMAP_RTC_KICK1_REG 0x70 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define OMAP_RTC_KICK0_VALUE 0x83E70B13 378c2ecf20Sopenharmony_ci#define OMAP_RTC_KICK1_VALUE 0x95A4F1E0 388c2ecf20Sopenharmony_ci#define OMAP_RTC_STATUS_BUSY BIT(0) 398c2ecf20Sopenharmony_ci#define OMAP_RTC_MAX_READY_TIME 50 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/** 428c2ecf20Sopenharmony_ci * omap_rtc_wait_not_busy - Wait for the RTC BUSY flag 438c2ecf20Sopenharmony_ci * @oh: struct omap_hwmod * 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * For updating certain RTC registers, the MPU must wait 468c2ecf20Sopenharmony_ci * for the BUSY status in OMAP_RTC_STATUS_REG to become zero. 478c2ecf20Sopenharmony_ci * Once the BUSY status is zero, there is a 15 microseconds access 488c2ecf20Sopenharmony_ci * period in which the MPU can program. 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_cistatic void omap_rtc_wait_not_busy(struct omap_hwmod *oh) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci int i; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci /* BUSY may stay active for 1/32768 second (~30 usec) */ 558c2ecf20Sopenharmony_ci omap_test_timeout(omap_hwmod_read(oh, OMAP_RTC_STATUS_REG) 568c2ecf20Sopenharmony_ci & OMAP_RTC_STATUS_BUSY, OMAP_RTC_MAX_READY_TIME, i); 578c2ecf20Sopenharmony_ci /* now we have ~15 microseconds to read/write various registers */ 588c2ecf20Sopenharmony_ci} 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/** 618c2ecf20Sopenharmony_ci * omap_hwmod_rtc_unlock - Unlock the Kicker mechanism. 628c2ecf20Sopenharmony_ci * @oh: struct omap_hwmod * 638c2ecf20Sopenharmony_ci * 648c2ecf20Sopenharmony_ci * RTC IP have kicker feature. This prevents spurious writes to its registers. 658c2ecf20Sopenharmony_ci * In order to write into any of the RTC registers, KICK values has te be 668c2ecf20Sopenharmony_ci * written in respective KICK registers. This is needed for hwmod to write into 678c2ecf20Sopenharmony_ci * sysconfig register. 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_civoid omap_hwmod_rtc_unlock(struct omap_hwmod *oh) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci unsigned long flags; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci local_irq_save(flags); 748c2ecf20Sopenharmony_ci omap_rtc_wait_not_busy(oh); 758c2ecf20Sopenharmony_ci omap_hwmod_write(OMAP_RTC_KICK0_VALUE, oh, OMAP_RTC_KICK0_REG); 768c2ecf20Sopenharmony_ci omap_hwmod_write(OMAP_RTC_KICK1_VALUE, oh, OMAP_RTC_KICK1_REG); 778c2ecf20Sopenharmony_ci local_irq_restore(flags); 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/** 818c2ecf20Sopenharmony_ci * omap_hwmod_rtc_lock - Lock the Kicker mechanism. 828c2ecf20Sopenharmony_ci * @oh: struct omap_hwmod * 838c2ecf20Sopenharmony_ci * 848c2ecf20Sopenharmony_ci * RTC IP have kicker feature. This prevents spurious writes to its registers. 858c2ecf20Sopenharmony_ci * Once the RTC registers are written, KICK mechanism needs to be locked, 868c2ecf20Sopenharmony_ci * in order to prevent any spurious writes. This function locks back the RTC 878c2ecf20Sopenharmony_ci * registers once hwmod completes its write into sysconfig register. 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_civoid omap_hwmod_rtc_lock(struct omap_hwmod *oh) 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci unsigned long flags; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci local_irq_save(flags); 948c2ecf20Sopenharmony_ci omap_rtc_wait_not_busy(oh); 958c2ecf20Sopenharmony_ci omap_hwmod_write(0x0, oh, OMAP_RTC_KICK0_REG); 968c2ecf20Sopenharmony_ci omap_hwmod_write(0x0, oh, OMAP_RTC_KICK1_REG); 978c2ecf20Sopenharmony_ci local_irq_restore(flags); 988c2ecf20Sopenharmony_ci} 99