^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * rtc-efi: RTC Class Driver for EFI-based systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: dann frazier <dannf@dannf.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Based on efirtc.c by Stephane Eranian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/stringify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define EFI_ISDST (EFI_TIME_ADJUST_DAYLIGHT|EFI_TIME_IN_DAYLIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * returns day of the year [0-365]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) compute_yday(efi_time_t *eft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* efi_time_t.month is in the [1-12] so, we need -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return rtc_year_days(eft->day, eft->month - 1, eft->year);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * returns day of the week [0-6] 0=Sunday
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) compute_wday(efi_time_t *eft, int yday)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int ndays = eft->year * (365 % 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) + (eft->year - 1) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) - (eft->year - 1) / 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) + (eft->year - 1) / 400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) + yday;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * 1/1/0000 may or may not have been a Sunday (if it ever existed at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * all) but assuming it was makes this calculation work correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return ndays % 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) convert_to_efi_time(struct rtc_time *wtime, efi_time_t *eft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) eft->year = wtime->tm_year + 1900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) eft->month = wtime->tm_mon + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) eft->day = wtime->tm_mday;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) eft->hour = wtime->tm_hour;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) eft->minute = wtime->tm_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) eft->second = wtime->tm_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) eft->nanosecond = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) eft->daylight = wtime->tm_isdst ? EFI_ISDST : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) eft->timezone = EFI_UNSPECIFIED_TIMEZONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) memset(wtime, 0, sizeof(*wtime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (eft->second >= 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) wtime->tm_sec = eft->second;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (eft->minute >= 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) wtime->tm_min = eft->minute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (eft->hour >= 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) wtime->tm_hour = eft->hour;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!eft->day || eft->day > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) wtime->tm_mday = eft->day;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!eft->month || eft->month > 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) wtime->tm_mon = eft->month - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (eft->year < 1900 || eft->year > 9999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) wtime->tm_year = eft->year - 1900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* day in the year [1-365]*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) wtime->tm_yday = compute_yday(eft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* day of the week [0-6], Sunday=0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) wtime->tm_wday = compute_wday(eft, wtime->tm_yday);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) switch (eft->daylight & EFI_ISDST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) case EFI_ISDST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) wtime->tm_isdst = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) case EFI_TIME_ADJUST_DAYLIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) wtime->tm_isdst = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) wtime->tm_isdst = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) efi_time_t eft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * As of EFI v1.10, this call always returns an unsupported status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) (efi_bool_t *)&wkalrm->pending, &eft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (status != EFI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (!convert_from_efi_time(&eft, &wkalrm->time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return rtc_valid_tm(&wkalrm->time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) efi_time_t eft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) convert_to_efi_time(&wkalrm->time, &eft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * XXX Fixme:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * As of EFI 0.92 with the firmware I have on my
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * machine this call does not seem to work quite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * As of v1.10, this call always returns an unsupported status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) dev_warn(dev, "write status is %d\n", (int)status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return status == EFI_SUCCESS ? 0 : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int efi_read_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) efi_time_t eft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) efi_time_cap_t cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) status = efi.get_time(&eft, &cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (status != EFI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* should never happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dev_err(dev, "can't read time\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (!convert_from_efi_time(&eft, tm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int efi_set_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) efi_time_t eft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) convert_to_efi_time(tm, &eft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) status = efi.set_time(&eft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return status == EFI_SUCCESS ? 0 : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int efi_procfs(struct device *dev, struct seq_file *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) efi_time_t eft, alm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) efi_time_cap_t cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) efi_bool_t enabled, pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) memset(&eft, 0, sizeof(eft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) memset(&alm, 0, sizeof(alm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) memset(&cap, 0, sizeof(cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) efi.get_time(&eft, &cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) efi.get_wakeup_time(&enabled, &pending, &alm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) "Time\t\t: %u:%u:%u.%09u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) "Date\t\t: %u-%u-%u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) "Daylight\t: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) eft.hour, eft.minute, eft.second, eft.nanosecond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) eft.year, eft.month, eft.day,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) eft.daylight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (eft.timezone == EFI_UNSPECIFIED_TIMEZONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) seq_puts(seq, "Timezone\t: unspecified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* XXX fixme: convert to string? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) seq_printf(seq, "Timezone\t: %u\n", eft.timezone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) "Alarm Time\t: %u:%u:%u.%09u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) "Alarm Date\t: %u-%u-%u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) "Alarm Daylight\t: %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) "Enabled\t\t: %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) "Pending\t\t: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) alm.hour, alm.minute, alm.second, alm.nanosecond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) alm.year, alm.month, alm.day,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) alm.daylight,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) enabled == 1 ? "yes" : "no",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pending == 1 ? "yes" : "no");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (eft.timezone == EFI_UNSPECIFIED_TIMEZONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) seq_puts(seq, "Timezone\t: unspecified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* XXX fixme: convert to string? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) seq_printf(seq, "Timezone\t: %u\n", alm.timezone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * now prints the capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) "Resolution\t: %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) "Accuracy\t: %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) "SetstoZero\t: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) cap.resolution, cap.accuracy, cap.sets_to_zero);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static const struct rtc_class_ops efi_rtc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .read_time = efi_read_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .set_time = efi_set_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .read_alarm = efi_read_alarm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .set_alarm = efi_set_alarm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .proc = efi_procfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int __init efi_rtc_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct rtc_device *rtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) efi_time_t eft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) efi_time_cap_t cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* First check if the RTC is usable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (efi.get_time(&eft, &cap) != EFI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) rtc = devm_rtc_device_register(&dev->dev, "rtc-efi", &efi_rtc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (IS_ERR(rtc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return PTR_ERR(rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) rtc->uie_unsupported = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) platform_set_drvdata(dev, rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static struct platform_driver efi_rtc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .name = "rtc-efi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) module_platform_driver_probe(efi_rtc_driver, efi_rtc_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_ALIAS("platform:rtc-efi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_AUTHOR("dann frazier <dannf@dannf.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_DESCRIPTION("EFI RTC driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_ALIAS("platform:rtc-efi");