xref: /linux/include/uapi/linux/rtc.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  * Generic RTC interface.
4607ca46eSDavid Howells  * This version contains the part of the user interface to the Real Time Clock
5607ca46eSDavid Howells  * service. It is used with both the legacy mc146818 and also  EFI
6607ca46eSDavid Howells  * Struct rtc_time and first 12 ioctl by Paul Gortmaker, 1996 - separated out
7607ca46eSDavid Howells  * from <linux/mc146818rtc.h> to this file for 2.4 kernels.
8607ca46eSDavid Howells  *
9607ca46eSDavid Howells  * Copyright (C) 1999 Hewlett-Packard Co.
10607ca46eSDavid Howells  * Copyright (C) 1999 Stephane Eranian <eranian@hpl.hp.com>
11607ca46eSDavid Howells  */
12607ca46eSDavid Howells #ifndef _UAPI_LINUX_RTC_H_
13607ca46eSDavid Howells #define _UAPI_LINUX_RTC_H_
14607ca46eSDavid Howells 
15b0efe028SEugene Syromiatnikov #include <linux/const.h>
16b0efe028SEugene Syromiatnikov #include <linux/ioctl.h>
176a8af1b6SAlexandre Belloni #include <linux/types.h>
18b0efe028SEugene Syromiatnikov 
19607ca46eSDavid Howells /*
20607ca46eSDavid Howells  * The struct used to pass data via the following ioctl. Similar to the
21607ca46eSDavid Howells  * struct tm in <time.h>, but it needs to be here so that the kernel
22607ca46eSDavid Howells  * source is self contained, allowing cross-compiles, etc. etc.
23607ca46eSDavid Howells  */
24607ca46eSDavid Howells 
25607ca46eSDavid Howells struct rtc_time {
26607ca46eSDavid Howells 	int tm_sec;
27607ca46eSDavid Howells 	int tm_min;
28607ca46eSDavid Howells 	int tm_hour;
29607ca46eSDavid Howells 	int tm_mday;
30607ca46eSDavid Howells 	int tm_mon;
31607ca46eSDavid Howells 	int tm_year;
32607ca46eSDavid Howells 	int tm_wday;
33607ca46eSDavid Howells 	int tm_yday;
34607ca46eSDavid Howells 	int tm_isdst;
35607ca46eSDavid Howells };
36607ca46eSDavid Howells 
37607ca46eSDavid Howells /*
38607ca46eSDavid Howells  * This data structure is inspired by the EFI (v0.92) wakeup
39607ca46eSDavid Howells  * alarm API.
40607ca46eSDavid Howells  */
41607ca46eSDavid Howells struct rtc_wkalrm {
42607ca46eSDavid Howells 	unsigned char enabled;	/* 0 = alarm disabled, 1 = alarm enabled */
43607ca46eSDavid Howells 	unsigned char pending;  /* 0 = alarm not pending, 1 = alarm pending */
44607ca46eSDavid Howells 	struct rtc_time time;	/* time the alarm is set to */
45607ca46eSDavid Howells };
46607ca46eSDavid Howells 
47607ca46eSDavid Howells /*
48607ca46eSDavid Howells  * Data structure to control PLL correction some better RTC feature
49607ca46eSDavid Howells  * pll_value is used to get or set current value of correction,
50607ca46eSDavid Howells  * the rest of the struct is used to query HW capabilities.
51607ca46eSDavid Howells  * This is modeled after the RTC used in Q40/Q60 computers but
52607ca46eSDavid Howells  * should be sufficiently flexible for other devices
53607ca46eSDavid Howells  *
54607ca46eSDavid Howells  * +ve pll_value means clock will run faster by
55607ca46eSDavid Howells  *   pll_value*pll_posmult/pll_clock
56607ca46eSDavid Howells  * -ve pll_value means clock will run slower by
57607ca46eSDavid Howells  *   pll_value*pll_negmult/pll_clock
58607ca46eSDavid Howells  */
59607ca46eSDavid Howells 
60607ca46eSDavid Howells struct rtc_pll_info {
61607ca46eSDavid Howells 	int pll_ctrl;       /* placeholder for fancier control */
62607ca46eSDavid Howells 	int pll_value;      /* get/set correction value */
63607ca46eSDavid Howells 	int pll_max;        /* max +ve (faster) adjustment value */
64607ca46eSDavid Howells 	int pll_min;        /* max -ve (slower) adjustment value */
65607ca46eSDavid Howells 	int pll_posmult;    /* factor for +ve correction */
66607ca46eSDavid Howells 	int pll_negmult;    /* factor for -ve correction */
67607ca46eSDavid Howells 	long pll_clock;     /* base PLL frequency */
68607ca46eSDavid Howells };
69607ca46eSDavid Howells 
706a8af1b6SAlexandre Belloni struct rtc_param {
716a8af1b6SAlexandre Belloni 	__u64 param;
726a8af1b6SAlexandre Belloni 	union {
736a8af1b6SAlexandre Belloni 		__u64 uvalue;
746a8af1b6SAlexandre Belloni 		__s64 svalue;
756a8af1b6SAlexandre Belloni 		__u64 ptr;
766a8af1b6SAlexandre Belloni 	};
776a8af1b6SAlexandre Belloni 	__u32 index;
786a8af1b6SAlexandre Belloni 	__u32 __pad;
796a8af1b6SAlexandre Belloni };
806a8af1b6SAlexandre Belloni 
81607ca46eSDavid Howells /*
82607ca46eSDavid Howells  * ioctl calls that are permitted to the /dev/rtc interface, if
83607ca46eSDavid Howells  * any of the RTC drivers are enabled.
84607ca46eSDavid Howells  */
85607ca46eSDavid Howells 
86607ca46eSDavid Howells #define RTC_AIE_ON	_IO('p', 0x01)	/* Alarm int. enable on		*/
87607ca46eSDavid Howells #define RTC_AIE_OFF	_IO('p', 0x02)	/* ... off			*/
88607ca46eSDavid Howells #define RTC_UIE_ON	_IO('p', 0x03)	/* Update int. enable on	*/
89607ca46eSDavid Howells #define RTC_UIE_OFF	_IO('p', 0x04)	/* ... off			*/
90607ca46eSDavid Howells #define RTC_PIE_ON	_IO('p', 0x05)	/* Periodic int. enable on	*/
91607ca46eSDavid Howells #define RTC_PIE_OFF	_IO('p', 0x06)	/* ... off			*/
92607ca46eSDavid Howells #define RTC_WIE_ON	_IO('p', 0x0f)  /* Watchdog int. enable on	*/
93607ca46eSDavid Howells #define RTC_WIE_OFF	_IO('p', 0x10)  /* ... off			*/
94607ca46eSDavid Howells 
95607ca46eSDavid Howells #define RTC_ALM_SET	_IOW('p', 0x07, struct rtc_time) /* Set alarm time  */
96607ca46eSDavid Howells #define RTC_ALM_READ	_IOR('p', 0x08, struct rtc_time) /* Read alarm time */
97607ca46eSDavid Howells #define RTC_RD_TIME	_IOR('p', 0x09, struct rtc_time) /* Read RTC time   */
98607ca46eSDavid Howells #define RTC_SET_TIME	_IOW('p', 0x0a, struct rtc_time) /* Set RTC time    */
99607ca46eSDavid Howells #define RTC_IRQP_READ	_IOR('p', 0x0b, unsigned long)	 /* Read IRQ rate   */
100607ca46eSDavid Howells #define RTC_IRQP_SET	_IOW('p', 0x0c, unsigned long)	 /* Set IRQ rate    */
101607ca46eSDavid Howells #define RTC_EPOCH_READ	_IOR('p', 0x0d, unsigned long)	 /* Read epoch      */
102607ca46eSDavid Howells #define RTC_EPOCH_SET	_IOW('p', 0x0e, unsigned long)	 /* Set epoch       */
103607ca46eSDavid Howells 
104607ca46eSDavid Howells #define RTC_WKALM_SET	_IOW('p', 0x0f, struct rtc_wkalrm)/* Set wakeup alarm*/
105607ca46eSDavid Howells #define RTC_WKALM_RD	_IOR('p', 0x10, struct rtc_wkalrm)/* Get wakeup alarm*/
106607ca46eSDavid Howells 
107607ca46eSDavid Howells #define RTC_PLL_GET	_IOR('p', 0x11, struct rtc_pll_info)  /* Get PLL correction */
108607ca46eSDavid Howells #define RTC_PLL_SET	_IOW('p', 0x12, struct rtc_pll_info)  /* Set PLL correction */
109607ca46eSDavid Howells 
1106a8af1b6SAlexandre Belloni #define RTC_PARAM_GET	_IOW('p', 0x13, struct rtc_param)  /* Get parameter */
1116a8af1b6SAlexandre Belloni #define RTC_PARAM_SET	_IOW('p', 0x14, struct rtc_param)  /* Set parameter */
1126a8af1b6SAlexandre Belloni 
113b0efe028SEugene Syromiatnikov #define RTC_VL_DATA_INVALID	_BITUL(0) /* Voltage too low, RTC data is invalid */
114b0efe028SEugene Syromiatnikov #define RTC_VL_BACKUP_LOW	_BITUL(1) /* Backup voltage is low */
115b0efe028SEugene Syromiatnikov #define RTC_VL_BACKUP_EMPTY	_BITUL(2) /* Backup empty or not present */
116b0efe028SEugene Syromiatnikov #define RTC_VL_ACCURACY_LOW	_BITUL(3) /* Voltage is low, RTC accuracy is reduced */
117734e5e4eSAlexandre Belloni #define RTC_VL_BACKUP_SWITCH	_BITUL(4) /* Backup switchover happened */
1183431ca48SAlexandre Belloni 
1193431ca48SAlexandre Belloni #define RTC_VL_READ	_IOR('p', 0x13, unsigned int)	/* Voltage low detection */
120607ca46eSDavid Howells #define RTC_VL_CLR	_IO('p', 0x14)		/* Clear voltage low information */
121607ca46eSDavid Howells 
122607ca46eSDavid Howells /* interrupt flags */
123607ca46eSDavid Howells #define RTC_IRQF 0x80	/* Any of the following is active */
124607ca46eSDavid Howells #define RTC_PF 0x40	/* Periodic interrupt */
125607ca46eSDavid Howells #define RTC_AF 0x20	/* Alarm interrupt */
126607ca46eSDavid Howells #define RTC_UF 0x10	/* Update interrupt for 1Hz RTC */
127607ca46eSDavid Howells 
1287ae41220SAlexandre Belloni /* feature list */
1297ae41220SAlexandre Belloni #define RTC_FEATURE_ALARM		0
1307ae41220SAlexandre Belloni #define RTC_FEATURE_ALARM_RES_MINUTE	1
1317ae41220SAlexandre Belloni #define RTC_FEATURE_NEED_WEEK_DAY	2
132917425f7SAlexandre Belloni #define RTC_FEATURE_ALARM_RES_2S	3
133917425f7SAlexandre Belloni #define RTC_FEATURE_UPDATE_INTERRUPT	4
13422685519SAlexandre Belloni #define RTC_FEATURE_CORRECTION		5
1350d20e9fbSAlexandre Belloni #define RTC_FEATURE_BACKUP_SWITCH_MODE	6
136*e99653afSAlexandre Belloni #define RTC_FEATURE_ALARM_WAKEUP_ONLY	7
137*e99653afSAlexandre Belloni #define RTC_FEATURE_CNT			8
138607ca46eSDavid Howells 
1396a8af1b6SAlexandre Belloni /* parameter list */
1406a8af1b6SAlexandre Belloni #define RTC_PARAM_FEATURES		0
141a6d8c6e1SAlexandre Belloni #define RTC_PARAM_CORRECTION		1
1420d20e9fbSAlexandre Belloni #define RTC_PARAM_BACKUP_SWITCH_MODE	2
1430d20e9fbSAlexandre Belloni 
1440d20e9fbSAlexandre Belloni #define RTC_BSM_DISABLED	0
1450d20e9fbSAlexandre Belloni #define RTC_BSM_DIRECT		1
1460d20e9fbSAlexandre Belloni #define RTC_BSM_LEVEL		2
1470d20e9fbSAlexandre Belloni #define RTC_BSM_STANDBY		3
1486a8af1b6SAlexandre Belloni 
149607ca46eSDavid Howells #define RTC_MAX_FREQ	8192
150607ca46eSDavid Howells 
151607ca46eSDavid Howells 
152607ca46eSDavid Howells #endif /* _UAPI_LINUX_RTC_H_ */
153