drivers/rtc/rtc-ab-b5ze-s3.c

Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ab-b5ze-s3.c

File Facts

System
Linux kernel
Corpus path
drivers/rtc/rtc-ab-b5ze-s3.c
Extension
.c
Size
28948 bytes
Lines
955
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct abb5zes3_rtc_data {
	struct rtc_device *rtc;
	struct regmap *regmap;

	int irq;

	bool battery_low;
	bool timer_alarm; /* current alarm is via timer A */
};

/*
 * Try and match register bits w/ fixed null values to see whether we
 * are dealing with an ABB5ZES3.
 */
static int abb5zes3_i2c_validate_chip(struct regmap *regmap)
{
	u8 regs[ABB5ZES3_MEM_MAP_LEN];
	static const u8 mask[ABB5ZES3_MEM_MAP_LEN] = { 0x00, 0x00, 0x10, 0x00,
						       0x80, 0xc0, 0xc0, 0xf8,
						       0xe0, 0x00, 0x00, 0x40,
						       0x40, 0x78, 0x00, 0x00,
						       0xf8, 0x00, 0x88, 0x00 };
	int ret, i;

	ret = regmap_bulk_read(regmap, 0, regs, ABB5ZES3_MEM_MAP_LEN);
	if (ret)
		return ret;

	for (i = 0; i < ABB5ZES3_MEM_MAP_LEN; ++i) {
		if (regs[i] & mask[i]) /* check if bits are cleared */
			return -ENODEV;
	}

	return 0;
}

/* Clear alarm status bit. */
static int _abb5zes3_rtc_clear_alarm(struct device *dev)
{
	struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
	int ret;

	ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_CTRL2,
				 ABB5ZES3_REG_CTRL2_AF, 0);
	if (ret)
		dev_err(dev, "%s: clearing alarm failed (%d)\n", __func__, ret);

	return ret;
}

/* Enable or disable alarm (i.e. alarm interrupt generation) */
static int _abb5zes3_rtc_update_alarm(struct device *dev, bool enable)
{
	struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
	int ret;

	ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_CTRL1,
				 ABB5ZES3_REG_CTRL1_AIE,
				 enable ? ABB5ZES3_REG_CTRL1_AIE : 0);
	if (ret)
		dev_err(dev, "%s: writing alarm INT failed (%d)\n",
			__func__, ret);

	return ret;
}

/* Enable or disable timer (watchdog timer A interrupt generation) */
static int _abb5zes3_rtc_update_timer(struct device *dev, bool enable)
{
	struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
	int ret;

	ret = regmap_update_bits(data->regmap, ABB5ZES3_REG_CTRL2,
				 ABB5ZES3_REG_CTRL2_WTAIE,
				 enable ? ABB5ZES3_REG_CTRL2_WTAIE : 0);
	if (ret)
		dev_err(dev, "%s: writing timer INT failed (%d)\n",
			__func__, ret);

	return ret;
}

/*
 * Note: we only read, so regmap inner lock protection is sufficient, i.e.
 * we do not need driver's main lock protection.
 */
static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
	struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
	u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN];

Annotation

Implementation Notes