18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2014-2019 MediaTek Inc. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Author: Tianping.Fang <tianping.fang@mediatek.com> 68c2ecf20Sopenharmony_ci * Sean Wang <sean.wang@mediatek.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _LINUX_MFD_MT6397_RTC_H_ 108c2ecf20Sopenharmony_ci#define _LINUX_MFD_MT6397_RTC_H_ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/jiffies.h> 138c2ecf20Sopenharmony_ci#include <linux/mutex.h> 148c2ecf20Sopenharmony_ci#include <linux/regmap.h> 158c2ecf20Sopenharmony_ci#include <linux/rtc.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define RTC_BBPU 0x0000 188c2ecf20Sopenharmony_ci#define RTC_BBPU_CBUSY BIT(6) 198c2ecf20Sopenharmony_ci#define RTC_BBPU_KEY (0x43 << 8) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define RTC_WRTGR_MT6358 0x003a 228c2ecf20Sopenharmony_ci#define RTC_WRTGR_MT6397 0x003c 238c2ecf20Sopenharmony_ci#define RTC_WRTGR_MT6323 RTC_WRTGR_MT6397 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define RTC_IRQ_STA 0x0002 268c2ecf20Sopenharmony_ci#define RTC_IRQ_STA_AL BIT(0) 278c2ecf20Sopenharmony_ci#define RTC_IRQ_STA_LP BIT(3) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define RTC_IRQ_EN 0x0004 308c2ecf20Sopenharmony_ci#define RTC_IRQ_EN_AL BIT(0) 318c2ecf20Sopenharmony_ci#define RTC_IRQ_EN_ONESHOT BIT(2) 328c2ecf20Sopenharmony_ci#define RTC_IRQ_EN_LP BIT(3) 338c2ecf20Sopenharmony_ci#define RTC_IRQ_EN_ONESHOT_AL (RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define RTC_AL_MASK 0x0008 368c2ecf20Sopenharmony_ci#define RTC_AL_MASK_DOW BIT(4) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define RTC_TC_SEC 0x000a 398c2ecf20Sopenharmony_ci/* Min, Hour, Dom... register offset to RTC_TC_SEC */ 408c2ecf20Sopenharmony_ci#define RTC_OFFSET_SEC 0 418c2ecf20Sopenharmony_ci#define RTC_OFFSET_MIN 1 428c2ecf20Sopenharmony_ci#define RTC_OFFSET_HOUR 2 438c2ecf20Sopenharmony_ci#define RTC_OFFSET_DOM 3 448c2ecf20Sopenharmony_ci#define RTC_OFFSET_DOW 4 458c2ecf20Sopenharmony_ci#define RTC_OFFSET_MTH 5 468c2ecf20Sopenharmony_ci#define RTC_OFFSET_YEAR 6 478c2ecf20Sopenharmony_ci#define RTC_OFFSET_COUNT 7 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define RTC_AL_SEC 0x0018 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define RTC_AL_SEC_MASK 0x003f 528c2ecf20Sopenharmony_ci#define RTC_AL_MIN_MASK 0x003f 538c2ecf20Sopenharmony_ci#define RTC_AL_HOU_MASK 0x001f 548c2ecf20Sopenharmony_ci#define RTC_AL_DOM_MASK 0x001f 558c2ecf20Sopenharmony_ci#define RTC_AL_DOW_MASK 0x0007 568c2ecf20Sopenharmony_ci#define RTC_AL_MTH_MASK 0x000f 578c2ecf20Sopenharmony_ci#define RTC_AL_YEA_MASK 0x007f 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define RTC_PDN2 0x002e 608c2ecf20Sopenharmony_ci#define RTC_PDN2_PWRON_ALARM BIT(4) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define RTC_MIN_YEAR 1968 638c2ecf20Sopenharmony_ci#define RTC_BASE_YEAR 1900 648c2ecf20Sopenharmony_ci#define RTC_NUM_YEARS 128 658c2ecf20Sopenharmony_ci#define RTC_MIN_YEAR_OFFSET (RTC_MIN_YEAR - RTC_BASE_YEAR) 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define MTK_RTC_POLL_DELAY_US 10 688c2ecf20Sopenharmony_ci#define MTK_RTC_POLL_TIMEOUT (jiffies_to_usecs(HZ)) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct mtk_rtc_data { 718c2ecf20Sopenharmony_ci u32 wrtgr; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistruct mt6397_rtc { 758c2ecf20Sopenharmony_ci struct rtc_device *rtc_dev; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci /* Protect register access from multiple tasks */ 788c2ecf20Sopenharmony_ci struct mutex lock; 798c2ecf20Sopenharmony_ci struct regmap *regmap; 808c2ecf20Sopenharmony_ci int irq; 818c2ecf20Sopenharmony_ci u32 addr_base; 828c2ecf20Sopenharmony_ci const struct mtk_rtc_data *data; 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#endif /* _LINUX_MFD_MT6397_RTC_H_ */ 86