linux/drivers/rtc/rtc-sd3078.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Real Time Clock (RTC) Driver for sd3078
 * Copyright (C) 2018 Zoro Li
 */

#include <linux/bcd.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/rtc.h>
#include <linux/slab.h>

#define SD3078_REG_SC
#define SD3078_REG_MN
#define SD3078_REG_HR
#define SD3078_REG_DW
#define SD3078_REG_DM
#define SD3078_REG_MO
#define SD3078_REG_YR

#define SD3078_REG_CTRL1
#define SD3078_REG_CTRL2
#define SD3078_REG_CTRL3

#define KEY_WRITE1
#define KEY_WRITE2
#define KEY_WRITE3

#define NUM_TIME_REGS

/*
 * The sd3078 has write protection
 * and we can choose whether or not to use it.
 * Write protection is turned off by default.
 */
#define WRITE_PROTECT_EN

struct sd3078 {};

/*
 * In order to prevent arbitrary modification of the time register,
 * when modification of the register,
 * the "write" bit needs to be written in a certain order.
 * 1. set WRITE1 bit
 * 2. set WRITE2 bit
 * 3. set WRITE3 bit
 */
static void sd3078_enable_reg_write(struct sd3078 *sd3078)
{}

#if WRITE_PROTECT_EN
/*
 * In order to prevent arbitrary modification of the time register,
 * we should disable the write function.
 * when disable write,
 * the "write" bit needs to be clear in a certain order.
 * 1. clear WRITE2 bit
 * 2. clear WRITE3 bit
 * 3. clear WRITE1 bit
 */
static void sd3078_disable_reg_write(struct sd3078 *sd3078)
{
	regmap_update_bits(sd3078->regmap, SD3078_REG_CTRL1,
			   KEY_WRITE2, 0);
	regmap_update_bits(sd3078->regmap, SD3078_REG_CTRL1,
			   KEY_WRITE3, 0);
	regmap_update_bits(sd3078->regmap, SD3078_REG_CTRL2,
			   KEY_WRITE1, 0);
}
#endif

static int sd3078_rtc_read_time(struct device *dev, struct rtc_time *tm)
{}

static int sd3078_rtc_set_time(struct device *dev, struct rtc_time *tm)
{}

static const struct rtc_class_ops sd3078_rtc_ops =;

static const struct regmap_config regmap_config =;

static int sd3078_probe(struct i2c_client *client)
{}

static const struct i2c_device_id sd3078_id[] =;
MODULE_DEVICE_TABLE(i2c, sd3078_id);

static const __maybe_unused struct of_device_id rtc_dt_match[] =;
MODULE_DEVICE_TABLE(of, rtc_dt_match);

static struct i2c_driver sd3078_driver =;

module_i2c_driver();

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