drivers/rtc/rtc-r9701.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-r9701.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-r9701.c- Extension
.c- Size
- 3649 bytes
- Lines
- 146
- Domain
- Driver Families
- Bucket
- drivers/rtc
- 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/module.hlinux/kernel.hlinux/platform_device.hlinux/device.hlinux/init.hlinux/rtc.hlinux/spi/spi.hlinux/bcd.hlinux/delay.hlinux/bitops.h
Detected Declarations
function Copyrightfunction read_regsfunction r9701_get_datetimefunction r9701_set_datetimefunction r9701_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Driver for Epson RTC-9701JE
*
* Copyright (C) 2008 Magnus Damm
*
* Based on rtc-max6902.c
*
* Copyright (C) 2006 8D Technologies inc.
* Copyright (C) 2004 Compulab Ltd.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/rtc.h>
#include <linux/spi/spi.h>
#include <linux/bcd.h>
#include <linux/delay.h>
#include <linux/bitops.h>
#define RSECCNT 0x00 /* Second Counter */
#define RMINCNT 0x01 /* Minute Counter */
#define RHRCNT 0x02 /* Hour Counter */
#define RWKCNT 0x03 /* Week Counter */
#define RDAYCNT 0x04 /* Day Counter */
#define RMONCNT 0x05 /* Month Counter */
#define RYRCNT 0x06 /* Year Counter */
#define R100CNT 0x07 /* Y100 Counter */
#define RMINAR 0x08 /* Minute Alarm */
#define RHRAR 0x09 /* Hour Alarm */
#define RWKAR 0x0a /* Week/Day Alarm */
#define RTIMCNT 0x0c /* Interval Timer */
#define REXT 0x0d /* Extension Register */
#define RFLAG 0x0e /* RTC Flag Register */
#define RCR 0x0f /* RTC Control Register */
static int write_reg(struct device *dev, int address, unsigned char data)
{
struct spi_device *spi = to_spi_device(dev);
unsigned char buf[2];
buf[0] = address & 0x7f;
buf[1] = data;
return spi_write(spi, buf, ARRAY_SIZE(buf));
}
static int read_regs(struct device *dev, unsigned char *regs, int no_regs)
{
struct spi_device *spi = to_spi_device(dev);
u8 txbuf[1], rxbuf[1];
int k, ret;
ret = 0;
for (k = 0; ret == 0 && k < no_regs; k++) {
txbuf[0] = 0x80 | regs[k];
ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1);
regs[k] = rxbuf[0];
}
return ret;
}
static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
{
int ret;
unsigned char buf[] = { RSECCNT, RMINCNT, RHRCNT,
RDAYCNT, RMONCNT, RYRCNT };
ret = read_regs(dev, buf, ARRAY_SIZE(buf));
if (ret)
return ret;
dt->tm_sec = bcd2bin(buf[0]); /* RSECCNT */
dt->tm_min = bcd2bin(buf[1]); /* RMINCNT */
dt->tm_hour = bcd2bin(buf[2]); /* RHRCNT */
dt->tm_mday = bcd2bin(buf[3]); /* RDAYCNT */
dt->tm_mon = bcd2bin(buf[4]) - 1; /* RMONCNT */
dt->tm_year = bcd2bin(buf[5]) + 100; /* RYRCNT */
return 0;
}
static int r9701_set_datetime(struct device *dev, struct rtc_time *dt)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/platform_device.h`, `linux/device.h`, `linux/init.h`, `linux/rtc.h`, `linux/spi/spi.h`, `linux/bcd.h`.
- Detected declarations: `function Copyright`, `function read_regs`, `function r9701_get_datetime`, `function r9701_set_datetime`, `function r9701_probe`.
- Atlas domain: Driver Families / drivers/rtc.
- 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.