linux/drivers/rtc/rtc-cmos.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * RTC class driver for "CMOS RTC":  PCs, ACPI, etc
 *
 * Copyright (C) 1996 Paul Gortmaker (drivers/char/rtc.c)
 * Copyright (C) 2006 David Brownell (convert to new framework)
 */

/*
 * The original "cmos clock" chip was an MC146818 chip, now obsolete.
 * That defined the register interface now provided by all PCs, some
 * non-PC systems, and incorporated into ACPI.  Modern PC chipsets
 * integrate an MC146818 clone in their southbridge, and boards use
 * that instead of discrete clones like the DS12887 or M48T86.  There
 * are also clones that connect using the LPC bus.
 *
 * That register API is also used directly by various other drivers
 * (notably for integrated NVRAM), infrastructure (x86 has code to
 * bypass the RTC framework, directly reading the RTC during boot
 * and updating minutes/seconds for systems using NTP synch) and
 * utilities (like userspace 'hwclock', if no /dev node exists).
 *
 * So **ALL** calls to CMOS_READ and CMOS_WRITE must be done with
 * interrupts disabled, holding the global rtc_lock, to exclude those
 * other drivers and utilities on correctly configured systems.
 */

#define pr_fmt(fmt)

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/platform_device.h>
#include <linux/log2.h>
#include <linux/pm.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#ifdef CONFIG_X86
#include <asm/i8259.h>
#include <asm/processor.h>
#include <linux/dmi.h>
#endif

/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
#include <linux/mc146818rtc.h>

#ifdef CONFIG_ACPI
/*
 * Use ACPI SCI to replace HPET interrupt for RTC Alarm event
 *
 * If cleared, ACPI SCI is only used to wake up the system from suspend
 *
 * If set, ACPI SCI is used to handle UIE/AIE and system wakeup
 */

static bool use_acpi_alarm;
module_param(use_acpi_alarm, bool, 0444);

static inline int cmos_use_acpi_alarm(void)
{}
#else /* !CONFIG_ACPI */

static inline int cmos_use_acpi_alarm(void)
{
	return 0;
}
#endif

struct cmos_rtc {};

/* both platform and pnp busses use negative numbers for invalid irqs */
#define is_valid_irq(n)

static const char driver_name[] =;

/* The RTC_INTR register may have e.g. RTC_PF set even if RTC_PIE is clear;
 * always mask it against the irq enable bits in RTC_CONTROL.  Bit values
 * are the same: PF==PIE, AF=AIE, UF=UIE; so RTC_IRQMASK works with both.
 */
#define RTC_IRQMASK

static inline int is_intr(u8 rtc_intr)
{}

/*----------------------------------------------------------------*/

/* Much modern x86 hardware has HPETs (10+ MHz timers) which, because
 * many BIOS programmers don't set up "sane mode" IRQ routing, are mostly
 * used in a broken "legacy replacement" mode.  The breakage includes
 * HPET #1 hijacking the IRQ for this RTC, and being unavailable for
 * other (better) use.
 *
 * When that broken mode is in use, platform glue provides a partial
 * emulation of hardware RTC IRQ facilities using HPET #1.  We don't
 * want to use HPET for anything except those IRQs though...
 */
#ifdef CONFIG_HPET_EMULATE_RTC
#include <asm/hpet.h>
#else

static inline int is_hpet_enabled(void)
{
	return 0;
}

static inline int hpet_mask_rtc_irq_bit(unsigned long mask)
{
	return 0;
}

static inline int hpet_set_rtc_irq_bit(unsigned long mask)
{
	return 0;
}

static inline int
hpet_set_alarm_time(unsigned char hrs, unsigned char min, unsigned char sec)
{
	return 0;
}

static inline int hpet_set_periodic_freq(unsigned long freq)
{
	return 0;
}

static inline int hpet_rtc_dropped_irq(void)
{
	return 0;
}

static inline int hpet_rtc_timer_init(void)
{
	return 0;
}

extern irq_handler_t hpet_rtc_interrupt;

static inline int hpet_register_irq_handler(irq_handler_t handler)
{
	return 0;
}

static inline int hpet_unregister_irq_handler(irq_handler_t handler)
{
	return 0;
}

#endif

/* Don't use HPET for RTC Alarm event if ACPI Fixed event is used */
static inline int use_hpet_alarm(void)
{}

/*----------------------------------------------------------------*/

#ifdef RTC_PORT

/* Most newer x86 systems have two register banks, the first used
 * for RTC and NVRAM and the second only for NVRAM.  Caller must
 * own rtc_lock ... and we won't worry about access during NMI.
 */
#define can_bank2

static inline unsigned char cmos_read_bank2(unsigned char addr)
{}

static inline void cmos_write_bank2(unsigned char val, unsigned char addr)
{}

#else

#define can_bank2

static inline unsigned char cmos_read_bank2(unsigned char addr)
{
	return 0;
}

static inline void cmos_write_bank2(unsigned char val, unsigned char addr)
{
}

#endif

/*----------------------------------------------------------------*/

static int cmos_read_time(struct device *dev, struct rtc_time *t)
{}

static int cmos_set_time(struct device *dev, struct rtc_time *t)
{}

struct cmos_read_alarm_callback_param {};

static void cmos_read_alarm_callback(unsigned char __always_unused seconds,
				     void *param_in)
{}

static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
{}

static void cmos_checkintr(struct cmos_rtc *cmos, unsigned char rtc_control)
{}

static void cmos_irq_enable(struct cmos_rtc *cmos, unsigned char mask)
{}

static void cmos_irq_disable(struct cmos_rtc *cmos, unsigned char mask)
{}

static int cmos_validate_alarm(struct device *dev, struct rtc_wkalrm *t)
{}

struct cmos_set_alarm_callback_param {};

/* Note: this function may be executed by mc146818_avoid_UIP() more then
 *	 once
 */
static void cmos_set_alarm_callback(unsigned char __always_unused seconds,
				    void *param_in)
{}

static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
{}

static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled)
{}

#if IS_ENABLED(CONFIG_RTC_INTF_PROC)

static int cmos_procfs(struct device *dev, struct seq_file *seq)
{}

#else
#define cmos_procfs
#endif

static const struct rtc_class_ops cmos_rtc_ops =;

/*----------------------------------------------------------------*/

/*
 * All these chips have at least 64 bytes of address space, shared by
 * RTC registers and NVRAM.  Most of those bytes of NVRAM are used
 * by boot firmware.  Modern chips have 128 or 256 bytes.
 */

#define NVRAM_OFFSET

static int cmos_nvram_read(void *priv, unsigned int off, void *val,
			   size_t count)
{}

static int cmos_nvram_write(void *priv, unsigned int off, void *val,
			    size_t count)
{}

/*----------------------------------------------------------------*/

static struct cmos_rtc	cmos_rtc;

static irqreturn_t cmos_interrupt(int irq, void *p)
{}

#ifdef	CONFIG_ACPI

#include <linux/acpi.h>

static u32 rtc_handler(void *context)
{}

static void acpi_rtc_event_setup(struct device *dev)
{}

static void acpi_rtc_event_cleanup(void)
{}

static void rtc_wake_on(struct device *dev)
{}

static void rtc_wake_off(struct device *dev)
{}

#ifdef CONFIG_X86
static void use_acpi_alarm_quirks(void)
{}
#else
static inline void use_acpi_alarm_quirks(void) { }
#endif

static void acpi_cmos_wake_setup(struct device *dev)
{}

static void cmos_check_acpi_rtc_status(struct device *dev,
					      unsigned char *rtc_control)
{}

#else /* !CONFIG_ACPI */

static inline void acpi_rtc_event_setup(struct device *dev)
{
}

static inline void acpi_rtc_event_cleanup(void)
{
}

static inline void acpi_cmos_wake_setup(struct device *dev)
{
}

static inline void cmos_check_acpi_rtc_status(struct device *dev,
					      unsigned char *rtc_control)
{
}
#endif /* CONFIG_ACPI */

#ifdef	CONFIG_PNP
#define INITSECTION

#else
#define INITSECTION
#endif

#define SECS_PER_DAY
#define SECS_PER_MONTH
#define SECS_PER_YEAR

static int INITSECTION
cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
{}

static void cmos_do_shutdown(int rtc_irq)
{}

static void cmos_do_remove(struct device *dev)
{}

static int cmos_aie_poweroff(struct device *dev)
{}

static int cmos_suspend(struct device *dev)
{}

/* We want RTC alarms to wake us from e.g. ACPI G2/S5 "soft off", even
 * after a detour through G3 "mechanical off", although the ACPI spec
 * says wakeup should only work from G1/S4 "hibernate".  To most users,
 * distinctions between S4 and S5 are pointless.  So when the hardware
 * allows, don't draw that distinction.
 */
static inline int cmos_poweroff(struct device *dev)
{}

static void cmos_check_wkalrm(struct device *dev)
{}

static int __maybe_unused cmos_resume(struct device *dev)
{}

static SIMPLE_DEV_PM_OPS(cmos_pm_ops, cmos_suspend, cmos_resume);

/*----------------------------------------------------------------*/

/* On non-x86 systems, a "CMOS" RTC lives most naturally on platform_bus.
 * ACPI systems always list these as PNPACPI devices, and pre-ACPI PCs
 * probably list them in similar PNPBIOS tables; so PNP is more common.
 *
 * We don't use legacy "poke at the hardware" probing.  Ancient PCs that
 * predate even PNPBIOS should set up platform_bus devices.
 */

#ifdef	CONFIG_PNP

#include <linux/pnp.h>

static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
{}

static void cmos_pnp_remove(struct pnp_dev *pnp)
{}

static void cmos_pnp_shutdown(struct pnp_dev *pnp)
{}

static const struct pnp_device_id rtc_ids[] =;
MODULE_DEVICE_TABLE(pnp, rtc_ids);

static struct pnp_driver cmos_pnp_driver =;

#endif	/* CONFIG_PNP */

#ifdef CONFIG_OF
static const struct of_device_id of_cmos_match[] =;
MODULE_DEVICE_TABLE(of, of_cmos_match);

static __init void cmos_of_init(struct platform_device *pdev)
{}
#else
static inline void cmos_of_init(struct platform_device *pdev) {}
#endif
/*----------------------------------------------------------------*/

/* Platform setup should have set up an RTC device, when PNP is
 * unavailable ... this could happen even on (older) PCs.
 */

static int __init cmos_platform_probe(struct platform_device *pdev)
{}

static void cmos_platform_remove(struct platform_device *pdev)
{}

static void cmos_platform_shutdown(struct platform_device *pdev)
{}

/* work with hotplug and coldplug */
MODULE_ALIAS();

static struct platform_driver cmos_platform_driver =;

#ifdef CONFIG_PNP
static bool pnp_driver_registered;
#endif
static bool platform_driver_registered;

static int __init cmos_init(void)
{}
module_init();

static void __exit cmos_exit(void)
{}
module_exit(cmos_exit);


MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();