18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_HPET_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_HPET_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/msi.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifdef CONFIG_HPET_TIMER 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define HPET_MMAP_SIZE 1024 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define HPET_ID 0x000 128c2ecf20Sopenharmony_ci#define HPET_PERIOD 0x004 138c2ecf20Sopenharmony_ci#define HPET_CFG 0x010 148c2ecf20Sopenharmony_ci#define HPET_STATUS 0x020 158c2ecf20Sopenharmony_ci#define HPET_COUNTER 0x0f0 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define HPET_Tn_CFG(n) (0x100 + 0x20 * n) 188c2ecf20Sopenharmony_ci#define HPET_Tn_CMP(n) (0x108 + 0x20 * n) 198c2ecf20Sopenharmony_ci#define HPET_Tn_ROUTE(n) (0x110 + 0x20 * n) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define HPET_T0_CFG 0x100 228c2ecf20Sopenharmony_ci#define HPET_T0_CMP 0x108 238c2ecf20Sopenharmony_ci#define HPET_T0_ROUTE 0x110 248c2ecf20Sopenharmony_ci#define HPET_T1_CFG 0x120 258c2ecf20Sopenharmony_ci#define HPET_T1_CMP 0x128 268c2ecf20Sopenharmony_ci#define HPET_T1_ROUTE 0x130 278c2ecf20Sopenharmony_ci#define HPET_T2_CFG 0x140 288c2ecf20Sopenharmony_ci#define HPET_T2_CMP 0x148 298c2ecf20Sopenharmony_ci#define HPET_T2_ROUTE 0x150 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define HPET_ID_REV 0x000000ff 328c2ecf20Sopenharmony_ci#define HPET_ID_NUMBER 0x00001f00 338c2ecf20Sopenharmony_ci#define HPET_ID_64BIT 0x00002000 348c2ecf20Sopenharmony_ci#define HPET_ID_LEGSUP 0x00008000 358c2ecf20Sopenharmony_ci#define HPET_ID_VENDOR 0xffff0000 368c2ecf20Sopenharmony_ci#define HPET_ID_NUMBER_SHIFT 8 378c2ecf20Sopenharmony_ci#define HPET_ID_VENDOR_SHIFT 16 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define HPET_CFG_ENABLE 0x001 408c2ecf20Sopenharmony_ci#define HPET_CFG_LEGACY 0x002 418c2ecf20Sopenharmony_ci#define HPET_LEGACY_8254 2 428c2ecf20Sopenharmony_ci#define HPET_LEGACY_RTC 8 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define HPET_TN_LEVEL 0x0002 458c2ecf20Sopenharmony_ci#define HPET_TN_ENABLE 0x0004 468c2ecf20Sopenharmony_ci#define HPET_TN_PERIODIC 0x0008 478c2ecf20Sopenharmony_ci#define HPET_TN_PERIODIC_CAP 0x0010 488c2ecf20Sopenharmony_ci#define HPET_TN_64BIT_CAP 0x0020 498c2ecf20Sopenharmony_ci#define HPET_TN_SETVAL 0x0040 508c2ecf20Sopenharmony_ci#define HPET_TN_32BIT 0x0100 518c2ecf20Sopenharmony_ci#define HPET_TN_ROUTE 0x3e00 528c2ecf20Sopenharmony_ci#define HPET_TN_FSB 0x4000 538c2ecf20Sopenharmony_ci#define HPET_TN_FSB_CAP 0x8000 548c2ecf20Sopenharmony_ci#define HPET_TN_ROUTE_SHIFT 9 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* Max HPET Period is 10^8 femto sec as in HPET spec */ 578c2ecf20Sopenharmony_ci#define HPET_MAX_PERIOD 100000000UL 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * Min HPET period is 10^5 femto sec just for safety. If it is less than this, 608c2ecf20Sopenharmony_ci * then 32 bit HPET counter wrapsaround in less than 0.5 sec. 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci#define HPET_MIN_PERIOD 100000UL 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* hpet memory map physical address */ 658c2ecf20Sopenharmony_ciextern unsigned long hpet_address; 668c2ecf20Sopenharmony_ciextern unsigned long force_hpet_address; 678c2ecf20Sopenharmony_ciextern bool boot_hpet_disable; 688c2ecf20Sopenharmony_ciextern u8 hpet_blockid; 698c2ecf20Sopenharmony_ciextern bool hpet_force_user; 708c2ecf20Sopenharmony_ciextern bool hpet_msi_disable; 718c2ecf20Sopenharmony_ciextern int is_hpet_enabled(void); 728c2ecf20Sopenharmony_ciextern int hpet_enable(void); 738c2ecf20Sopenharmony_ciextern void hpet_disable(void); 748c2ecf20Sopenharmony_ciextern unsigned int hpet_readl(unsigned int a); 758c2ecf20Sopenharmony_ciextern void force_hpet_resume(void); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct irq_data; 788c2ecf20Sopenharmony_cistruct hpet_channel; 798c2ecf20Sopenharmony_cistruct irq_domain; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ciextern void hpet_msi_unmask(struct irq_data *data); 828c2ecf20Sopenharmony_ciextern void hpet_msi_mask(struct irq_data *data); 838c2ecf20Sopenharmony_ciextern void hpet_msi_write(struct hpet_channel *hc, struct msi_msg *msg); 848c2ecf20Sopenharmony_ciextern struct irq_domain *hpet_create_irq_domain(int hpet_id); 858c2ecf20Sopenharmony_ciextern int hpet_assign_irq(struct irq_domain *domain, 868c2ecf20Sopenharmony_ci struct hpet_channel *hc, int dev_num); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#ifdef CONFIG_HPET_EMULATE_RTC 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_citypedef irqreturn_t (*rtc_irq_handler)(int interrupt, void *cookie); 938c2ecf20Sopenharmony_ciextern int hpet_mask_rtc_irq_bit(unsigned long bit_mask); 948c2ecf20Sopenharmony_ciextern int hpet_set_rtc_irq_bit(unsigned long bit_mask); 958c2ecf20Sopenharmony_ciextern int hpet_set_alarm_time(unsigned char hrs, unsigned char min, 968c2ecf20Sopenharmony_ci unsigned char sec); 978c2ecf20Sopenharmony_ciextern int hpet_set_periodic_freq(unsigned long freq); 988c2ecf20Sopenharmony_ciextern int hpet_rtc_dropped_irq(void); 998c2ecf20Sopenharmony_ciextern int hpet_rtc_timer_init(void); 1008c2ecf20Sopenharmony_ciextern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id); 1018c2ecf20Sopenharmony_ciextern int hpet_register_irq_handler(rtc_irq_handler handler); 1028c2ecf20Sopenharmony_ciextern void hpet_unregister_irq_handler(rtc_irq_handler handler); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#endif /* CONFIG_HPET_EMULATE_RTC */ 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#else /* CONFIG_HPET_TIMER */ 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline int hpet_enable(void) { return 0; } 1098c2ecf20Sopenharmony_cistatic inline int is_hpet_enabled(void) { return 0; } 1108c2ecf20Sopenharmony_ci#define hpet_readl(a) 0 1118c2ecf20Sopenharmony_ci#define default_setup_hpet_msi NULL 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#endif 1148c2ecf20Sopenharmony_ci#endif /* _ASM_X86_HPET_H */ 115