linux/drivers/rtc/rtc-max31335.c

// SPDX-License-Identifier: GPL-2.0
/*
 * RTC driver for the MAX31335
 *
 * Copyright (C) 2023 Analog Devices
 *
 * Antoniu Miclaus <[email protected]>
 *
 */

#include <linux/unaligned.h>
#include <linux/bcd.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/hwmon.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/regmap.h>
#include <linux/rtc.h>
#include <linux/util_macros.h>

/* MAX31335 Register Map */
#define MAX31335_STATUS1
#define MAX31335_INT_EN1
#define MAX31335_STATUS2
#define MAX31335_INT_EN2
#define MAX31335_RTC_RESET
#define MAX31335_RTC_CONFIG
#define MAX31335_RTC_CONFIG2
#define MAX31335_TIMESTAMP_CONFIG
#define MAX31335_TIMER_CONFIG
#define MAX31335_SECONDS_1_128
#define MAX31335_SECONDS
#define MAX31335_MINUTES
#define MAX31335_HOURS
#define MAX31335_DAY
#define MAX31335_DATE
#define MAX31335_MONTH
#define MAX31335_YEAR
#define MAX31335_ALM1_SEC
#define MAX31335_ALM1_MIN
#define MAX31335_ALM1_HRS
#define MAX31335_ALM1_DAY_DATE
#define MAX31335_ALM1_MON
#define MAX31335_ALM1_YEAR
#define MAX31335_ALM2_MIN
#define MAX31335_ALM2_HRS
#define MAX31335_ALM2_DAY_DATE
#define MAX31335_TIMER_COUNT
#define MAX31335_TIMER_INIT
#define MAX31335_PWR_MGMT
#define MAX31335_TRICKLE_REG
#define MAX31335_AGING_OFFSET
#define MAX31335_TS_CONFIG
#define MAX31335_TEMP_ALARM_HIGH_MSB
#define MAX31335_TEMP_ALARM_HIGH_LSB
#define MAX31335_TEMP_ALARM_LOW_MSB
#define MAX31335_TEMP_ALARM_LOW_LSB
#define MAX31335_TEMP_DATA_MSB
#define MAX31335_TEMP_DATA_LSB
#define MAX31335_TS0_SEC_1_128
#define MAX31335_TS0_SEC
#define MAX31335_TS0_MIN
#define MAX31335_TS0_HOUR
#define MAX31335_TS0_DATE
#define MAX31335_TS0_MONTH
#define MAX31335_TS0_YEAR
#define MAX31335_TS0_FLAGS
#define MAX31335_TS1_SEC_1_128
#define MAX31335_TS1_SEC
#define MAX31335_TS1_MIN
#define MAX31335_TS1_HOUR
#define MAX31335_TS1_DATE
#define MAX31335_TS1_MONTH
#define MAX31335_TS1_YEAR
#define MAX31335_TS1_FLAGS
#define MAX31335_TS2_SEC_1_128
#define MAX31335_TS2_SEC
#define MAX31335_TS2_MIN
#define MAX31335_TS2_HOUR
#define MAX31335_TS2_DATE
#define MAX31335_TS2_MONTH
#define MAX31335_TS2_YEAR
#define MAX31335_TS2_FLAGS
#define MAX31335_TS3_SEC_1_128
#define MAX31335_TS3_SEC
#define MAX31335_TS3_MIN
#define MAX31335_TS3_HOUR
#define MAX31335_TS3_DATE
#define MAX31335_TS3_MONTH
#define MAX31335_TS3_YEAR
#define MAX31335_TS3_FLAGS

/* MAX31335_STATUS1 Bit Definitions */
#define MAX31335_STATUS1_PSDECT
#define MAX31335_STATUS1_OSF
#define MAX31335_STATUS1_PFAIL
#define MAX31335_STATUS1_VBATLOW
#define MAX31335_STATUS1_DIF
#define MAX31335_STATUS1_TIF
#define MAX31335_STATUS1_A2F
#define MAX31335_STATUS1_A1F

/* MAX31335_INT_EN1 Bit Definitions */
#define MAX31335_INT_EN1_DOSF
#define MAX31335_INT_EN1_PFAILE
#define MAX31335_INT_EN1_VBATLOWE
#define MAX31335_INT_EN1_DIE
#define MAX31335_INT_EN1_TIE
#define MAX31335_INT_EN1_A2IE
#define MAX31335_INT_EN1_A1IE

/* MAX31335_STATUS2 Bit Definitions */
#define MAX31335_STATUS2_TEMP_RDY
#define MAX31335_STATUS2_OTF
#define MAX31335_STATUS2_UTF

/* MAX31335_INT_EN2 Bit Definitions */
#define MAX31335_INT_EN2_TEMP_RDY_EN
#define MAX31335_INT_EN2_OTIE
#define MAX31335_INT_EN2_UTIE

/* MAX31335_RTC_RESET Bit Definitions */
#define MAX31335_RTC_RESET_SWRST

/* MAX31335_RTC_CONFIG1 Bit Definitions */
#define MAX31335_RTC_CONFIG1_EN_IO
#define MAX31335_RTC_CONFIG1_A1AC
#define MAX31335_RTC_CONFIG1_DIP
#define MAX31335_RTC_CONFIG1_I2C_TIMEOUT
#define MAX31335_RTC_CONFIG1_EN_OSC

/* MAX31335_RTC_CONFIG2 Bit Definitions */
#define MAX31335_RTC_CONFIG2_ENCLKO
#define MAX31335_RTC_CONFIG2_CLKO_HZ

/* MAX31335_TIMESTAMP_CONFIG Bit Definitions */
#define MAX31335_TIMESTAMP_CONFIG_TSVLOW
#define MAX31335_TIMESTAMP_CONFIG_TSPWM
#define MAX31335_TIMESTAMP_CONFIG_TSDIN
#define MAX31335_TIMESTAMP_CONFIG_TSOW
#define MAX31335_TIMESTAMP_CONFIG_TSR
#define MAX31335_TIMESTAMP_CONFIG_TSE

/* MAX31335_TIMER_CONFIG Bit Definitions */
#define MAX31335_TIMER_CONFIG_TE
#define MAX31335_TIMER_CONFIG_TPAUSE
#define MAX31335_TIMER_CONFIG_TRPT
#define MAX31335_TIMER_CONFIG_TFS

/* MAX31335_HOURS Bit Definitions */
#define MAX31335_HOURS_F_24_12
#define MAX31335_HOURS_HR_20_AM_PM

/* MAX31335_MONTH Bit Definitions */
#define MAX31335_MONTH_CENTURY

/* MAX31335_PWR_MGMT Bit Definitions */
#define MAX31335_PWR_MGMT_PFVT

/* MAX31335_TRICKLE_REG Bit Definitions */
#define MAX31335_TRICKLE_REG_TRICKLE
#define MAX31335_TRICKLE_REG_EN_TRICKLE

/* MAX31335_TS_CONFIG Bit Definitions */
#define MAX31335_TS_CONFIG_AUTO
#define MAX31335_TS_CONFIG_CONVERT_T
#define MAX31335_TS_CONFIG_TSINT

/* MAX31335_TS_FLAGS Bit Definitions */
#define MAX31335_TS_FLAGS_VLOWF
#define MAX31335_TS_FLAGS_VBATF
#define MAX31335_TS_FLAGS_VCCF
#define MAX31335_TS_FLAGS_DINF

/* MAX31335 Miscellaneous Definitions */
#define MAX31335_TRICKLE_SCHOTTKY_DIODE
#define MAX31335_TRICKLE_STANDARD_DIODE
#define MAX31335_RAM_SIZE
#define MAX31335_TIME_SIZE

#define clk_hw_to_max31335(_hw)

struct max31335_data {};

static const int max31335_clkout_freq[] =;

static const u16 max31335_trickle_resistors[] =;

static bool max31335_volatile_reg(struct device *dev, unsigned int reg)
{}

static const struct regmap_config regmap_config =;

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

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

static int max31335_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{}

static int max31335_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{}

static int max31335_alarm_irq_enable(struct device *dev, unsigned int enabled)
{}

static irqreturn_t max31335_handle_irq(int irq, void *dev_id)
{}

static const struct rtc_class_ops max31335_rtc_ops =;

static int max31335_trickle_charger_setup(struct device *dev,
					  struct max31335_data *max31335)
{}

static unsigned long max31335_clkout_recalc_rate(struct clk_hw *hw,
						 unsigned long parent_rate)
{}

static long max31335_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
				       unsigned long *prate)
{}

static int max31335_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
				    unsigned long parent_rate)
{}

static int max31335_clkout_enable(struct clk_hw *hw)
{}

static void max31335_clkout_disable(struct clk_hw *hw)
{}

static int max31335_clkout_is_enabled(struct clk_hw *hw)
{}

static const struct clk_ops max31335_clkout_ops =;

static struct clk_init_data max31335_clk_init =;

static int max31335_nvmem_reg_read(void *priv, unsigned int offset,
				   void *val, size_t bytes)
{}

static int max31335_nvmem_reg_write(void *priv, unsigned int offset,
				    void *val, size_t bytes)
{}

static struct nvmem_config max31335_nvmem_cfg =;

#if IS_REACHABLE(HWMON)
static int max31335_read_temp(struct device *dev, enum hwmon_sensor_types type,
			      u32 attr, int channel, long *val)
{
	struct max31335_data *max31335 = dev_get_drvdata(dev);
	u8 reg[2];
	s16 temp;
	int ret;

	if (type != hwmon_temp || attr != hwmon_temp_input)
		return -EOPNOTSUPP;

	ret = regmap_bulk_read(max31335->regmap, MAX31335_TEMP_DATA_MSB,
			       reg, 2);
	if (ret)
		return ret;

	temp = get_unaligned_be16(reg);

	*val = (temp / 64) * 250;

	return 0;
}

static umode_t max31335_is_visible(const void *data,
				   enum hwmon_sensor_types type,
				   u32 attr, int channel)
{
	if (type == hwmon_temp && attr == hwmon_temp_input)
		return 0444;

	return 0;
}

static const struct hwmon_channel_info *max31335_info[] = {
	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
	NULL
};

static const struct hwmon_ops max31335_hwmon_ops = {
	.is_visible = max31335_is_visible,
	.read = max31335_read_temp,
};

static const struct hwmon_chip_info max31335_chip_info = {
	.ops = &max31335_hwmon_ops,
	.info = max31335_info,
};
#endif

static int max31335_clkout_register(struct device *dev)
{}

static int max31335_probe(struct i2c_client *client)
{}

static const struct i2c_device_id max31335_id[] =;

MODULE_DEVICE_TABLE(i2c, max31335_id);

static const struct of_device_id max31335_of_match[] =;

MODULE_DEVICE_TABLE(of, max31335_of_match);

static struct i2c_driver max31335_driver =;
module_i2c_driver();

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