drivers/platform/cznic/turris-omnia-mcu-sys-off-wakeup.c
Source file repositories/reference/linux-study-clean/drivers/platform/cznic/turris-omnia-mcu-sys-off-wakeup.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/cznic/turris-omnia-mcu-sys-off-wakeup.c- Extension
.c- Size
- 6391 bytes
- Lines
- 261
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/crc32.hlinux/delay.hlinux/device.hlinux/err.hlinux/i2c.hlinux/kstrtox.hlinux/reboot.hlinux/rtc.hlinux/sysfs.hlinux/types.hlinux/turris-omnia-mcu-interface.hturris-omnia-mcu.h
Detected Declarations
function driverfunction omnia_read_timefunction omnia_read_alarmfunction omnia_set_alarmfunction omnia_alarm_irq_enablefunction omnia_power_offfunction omnia_restartfunction front_button_poweron_showfunction front_button_poweron_storefunction poweroff_attrs_visiblefunction omnia_mcu_register_sys_off_and_wakeup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* CZ.NIC's Turris Omnia MCU system off and RTC wakeup driver
*
* This is not a true RTC driver (in the sense that it does not provide a
* real-time clock), rather the MCU implements a wakeup from powered off state
* at a specified time relative to MCU boot, and we expose this feature via RTC
* alarm, so that it can be used via the rtcwake command, which is the standard
* Linux command for this.
*
* 2024 by Marek BehĂșn <kabel@kernel.org>
*/
#include <linux/crc32.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/kstrtox.h>
#include <linux/reboot.h>
#include <linux/rtc.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/turris-omnia-mcu-interface.h>
#include "turris-omnia-mcu.h"
static int omnia_get_uptime_wakeup(const struct i2c_client *client, u32 *uptime,
u32 *wakeup)
{
__le32 reply[2];
int err;
err = omnia_cmd_read(client, OMNIA_CMD_GET_UPTIME_AND_WAKEUP, reply,
sizeof(reply));
if (err)
return err;
if (uptime)
*uptime = le32_to_cpu(reply[0]);
if (wakeup)
*wakeup = le32_to_cpu(reply[1]);
return 0;
}
static int omnia_read_time(struct device *dev, struct rtc_time *tm)
{
u32 uptime;
int err;
err = omnia_get_uptime_wakeup(to_i2c_client(dev), &uptime, NULL);
if (err)
return err;
rtc_time64_to_tm(uptime, tm);
return 0;
}
static int omnia_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct i2c_client *client = to_i2c_client(dev);
struct omnia_mcu *mcu = i2c_get_clientdata(client);
u32 wakeup;
int err;
err = omnia_get_uptime_wakeup(client, NULL, &wakeup);
if (err)
return err;
alrm->enabled = !!wakeup;
rtc_time64_to_tm(wakeup ?: mcu->rtc_alarm, &alrm->time);
return 0;
}
static int omnia_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct i2c_client *client = to_i2c_client(dev);
struct omnia_mcu *mcu = i2c_get_clientdata(client);
mcu->rtc_alarm = rtc_tm_to_time64(&alrm->time);
if (alrm->enabled)
return omnia_cmd_write_u32(client, OMNIA_CMD_SET_WAKEUP,
mcu->rtc_alarm);
return 0;
Annotation
- Immediate include surface: `linux/crc32.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/i2c.h`, `linux/kstrtox.h`, `linux/reboot.h`, `linux/rtc.h`.
- Detected declarations: `function driver`, `function omnia_read_time`, `function omnia_read_alarm`, `function omnia_set_alarm`, `function omnia_alarm_irq_enable`, `function omnia_power_off`, `function omnia_restart`, `function front_button_poweron_show`, `function front_button_poweron_store`, `function poweroff_attrs_visible`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.