linux/drivers/hwmon/spd5118.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Driver for Jedec 5118 compliant temperature sensors
 *
 * Derived from https://github.com/Steve-Tech/SPD5118-DKMS
 * Originally from T/2 driver at https://t2sde.org/packages/linux
 *	Copyright (c) 2023 René Rebe, ExactCODE GmbH; Germany.
 *
 * Copyright (c) 2024 Guenter Roeck
 *
 * Inspired by ee1004.c and jc42.c.
 *
 * SPD5118 compliant temperature sensors are typically used on DDR5
 * memory modules.
 */

#include <linux/bitops.h>
#include <linux/bits.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/nvmem-provider.h>
#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/units.h>

/* Addresses to scan */
static const unsigned short normal_i2c[] =;

/* SPD5118 registers. */
#define SPD5118_REG_TYPE
#define SPD5118_REG_REVISION
#define SPD5118_REG_VENDOR
#define SPD5118_REG_CAPABILITY
#define SPD5118_REG_I2C_LEGACY_MODE
#define SPD5118_REG_TEMP_CLR
#define SPD5118_REG_ERROR_CLR
#define SPD5118_REG_TEMP_CONFIG
#define SPD5118_REG_TEMP_MAX
#define SPD5118_REG_TEMP_MIN
#define SPD5118_REG_TEMP_CRIT
#define SPD5118_REG_TEMP_LCRIT
#define SPD5118_REG_TEMP
#define SPD5118_REG_TEMP_STATUS

#define SPD5118_TEMP_STATUS_HIGH
#define SPD5118_TEMP_STATUS_LOW
#define SPD5118_TEMP_STATUS_CRIT
#define SPD5118_TEMP_STATUS_LCRIT

#define SPD5118_CAP_TS_SUPPORT

#define SPD5118_TS_DISABLE

#define SPD5118_LEGACY_MODE_ADDR
#define SPD5118_LEGACY_PAGE_MASK
#define SPD5118_LEGACY_MODE_MASK

#define SPD5118_NUM_PAGES
#define SPD5118_PAGE_SIZE
#define SPD5118_PAGE_SHIFT
#define SPD5118_PAGE_MASK
#define SPD5118_EEPROM_BASE
#define SPD5118_EEPROM_SIZE

/* Temperature unit in millicelsius */
#define SPD5118_TEMP_UNIT
/* Representable temperature range in millicelsius */
#define SPD5118_TEMP_RANGE_MIN
#define SPD5118_TEMP_RANGE_MAX

struct spd5118_data {};

/* hwmon */

static int spd5118_temp_from_reg(u16 reg)
{}

static u16 spd5118_temp_to_reg(long temp)
{}

static int spd5118_read_temp(struct regmap *regmap, u32 attr, long *val)
{}

static int spd5118_read_alarm(struct regmap *regmap, u32 attr, long *val)
{}

static int spd5118_read_enable(struct regmap *regmap, long *val)
{}

static int spd5118_read(struct device *dev, enum hwmon_sensor_types type,
			u32 attr, int channel, long *val)
{}

static int spd5118_write_temp(struct regmap *regmap, u32 attr, long val)
{}

static int spd5118_write_enable(struct regmap *regmap, long val)
{}

static int spd5118_temp_write(struct regmap *regmap, u32 attr, long val)
{}

static int spd5118_write(struct device *dev, enum hwmon_sensor_types type,
			 u32 attr, int channel, long val)
{}

static umode_t spd5118_is_visible(const void *_data, enum hwmon_sensor_types type,
				  u32 attr, int channel)
{}

static inline bool spd5118_parity8(u8 w)
{}

/*
 * Bank and vendor id are 8-bit fields with seven data bits and odd parity.
 * Vendor IDs 0 and 0x7f are invalid.
 * See Jedec standard JEP106BJ for details and a list of assigned vendor IDs.
 */
static bool spd5118_vendor_valid(u8 bank, u8 id)
{}

/* Return 0 if detection is successful, -ENODEV otherwise */
static int spd5118_detect(struct i2c_client *client, struct i2c_board_info *info)
{}

static const struct hwmon_channel_info *spd5118_info[] =;

static const struct hwmon_ops spd5118_hwmon_ops =;

static const struct hwmon_chip_info spd5118_chip_info =;

/* nvmem */

static ssize_t spd5118_nvmem_read_page(struct regmap *regmap, char *buf,
				       unsigned int offset, size_t count)
{}

static int spd5118_nvmem_read(void *priv, unsigned int off, void *val, size_t count)
{}

static int spd5118_nvmem_init(struct device *dev, struct spd5118_data *data)
{}

/* regmap */

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

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

static const struct regmap_range_cfg spd5118_regmap_range_cfg[] =;

static const struct regmap_config spd5118_regmap_config =;

static int spd5118_init(struct i2c_client *client)
{}

static int spd5118_probe(struct i2c_client *client)
{}

static int spd5118_suspend(struct device *dev)
{}

static int spd5118_resume(struct device *dev)
{}

static DEFINE_SIMPLE_DEV_PM_OPS(spd5118_pm_ops, spd5118_suspend, spd5118_resume);

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

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

static struct i2c_driver spd5118_driver =;

module_i2c_driver();

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