drivers/rtc/rtc-ds1347.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1347.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1347.c- Extension
.c- Size
- 4331 bytes
- Lines
- 184
- 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/init.hlinux/module.hlinux/device.hlinux/platform_device.hlinux/rtc.hlinux/spi/spi.hlinux/bcd.hlinux/regmap.h
Detected Declarations
function ds1347_read_timefunction ds1347_set_timefunction ds1347_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/* rtc-ds1347.c
*
* Driver for Dallas Semiconductor DS1347 Low Current, SPI Compatible
* Real Time Clock
*
* Author : Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/rtc.h>
#include <linux/spi/spi.h>
#include <linux/bcd.h>
#include <linux/regmap.h>
/* Registers in ds1347 rtc */
#define DS1347_SECONDS_REG 0x01
#define DS1347_MINUTES_REG 0x03
#define DS1347_HOURS_REG 0x05
#define DS1347_DATE_REG 0x07
#define DS1347_MONTH_REG 0x09
#define DS1347_DAY_REG 0x0B
#define DS1347_YEAR_REG 0x0D
#define DS1347_CONTROL_REG 0x0F
#define DS1347_CENTURY_REG 0x13
#define DS1347_STATUS_REG 0x17
#define DS1347_CLOCK_BURST 0x3F
#define DS1347_WP_BIT BIT(7)
#define DS1347_NEOSC_BIT BIT(7)
#define DS1347_OSF_BIT BIT(2)
static const struct regmap_range ds1347_ranges[] = {
{
.range_min = DS1347_SECONDS_REG,
.range_max = DS1347_STATUS_REG,
},
};
static const struct regmap_access_table ds1347_access_table = {
.yes_ranges = ds1347_ranges,
.n_yes_ranges = ARRAY_SIZE(ds1347_ranges),
};
static int ds1347_read_time(struct device *dev, struct rtc_time *dt)
{
struct regmap *map = dev_get_drvdata(dev);
unsigned int status, century, secs;
unsigned char buf[8];
int err;
err = regmap_read(map, DS1347_STATUS_REG, &status);
if (err)
return err;
if (status & DS1347_OSF_BIT)
return -EINVAL;
do {
err = regmap_bulk_read(map, DS1347_CLOCK_BURST, buf, 8);
if (err)
return err;
err = regmap_read(map, DS1347_CENTURY_REG, ¢ury);
if (err)
return err;
err = regmap_read(map, DS1347_SECONDS_REG, &secs);
if (err)
return err;
} while (buf[0] != secs);
dt->tm_sec = bcd2bin(buf[0]);
dt->tm_min = bcd2bin(buf[1] & 0x7f);
dt->tm_hour = bcd2bin(buf[2] & 0x3F);
dt->tm_mday = bcd2bin(buf[3]);
dt->tm_mon = bcd2bin(buf[4]) - 1;
dt->tm_wday = bcd2bin(buf[5]) - 1;
dt->tm_year = (bcd2bin(century) * 100) + bcd2bin(buf[6]) - 1900;
return 0;
}
static int ds1347_set_time(struct device *dev, struct rtc_time *dt)
{
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/device.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/spi/spi.h`, `linux/bcd.h`, `linux/regmap.h`.
- Detected declarations: `function ds1347_read_time`, `function ds1347_set_time`, `function ds1347_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.