drivers/hwmon/lm75.c

Source file repositories/reference/linux-study-clean/drivers/hwmon/lm75.c

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/lm75.c
Extension
.c
Size
30459 bytes
Lines
1178
Domain
Driver Families
Bucket
drivers/hwmon
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 lm75_params {
	bool			config_reg_16bits;
	u16			set_mask;
	u16			clr_mask;
	u8			default_resolution;
	u8			resolution_limits;
	const u8		*resolutions;
	unsigned int		default_sample_time;
	u8			num_sample_times;
	const unsigned int	*sample_times;
	bool			alarm;
};

/* Addresses scanned */
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
					0x4d, 0x4e, 0x4f, I2C_CLIENT_END };

/* The LM75 registers */
#define LM75_REG_TEMP		0x00
#define LM75_REG_CONF		0x01
#define LM75_REG_HYST		0x02
#define LM75_REG_MAX		0x03
#define PCT2075_REG_IDLE	0x04

struct lm75_data {
	const char *label;
	struct regmap			*regmap;
	u16				orig_conf;
	u8				resolution;	/* In bits, 9 to 16 */
	unsigned int			sample_time;	/* In ms */
	enum lm75_type			kind;
	const struct lm75_params	*params;
	u8				reg_buf[1];
	u8				val_buf[3];
};

/*-----------------------------------------------------------------------*/

static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 };

#define LM75_ALERT_POLARITY_HIGH_8_BIT	(BIT(2))
#define LM75_ALERT_POLARITY_HIGH_16_BIT	(BIT(2) << 8)
#define LM75_SAMPLE_CLEAR_MASK		(3 << 5)

/* The structure below stores the configuration values of the supported devices.
 * In case of being supported multiple configurations, the default one must
 * always be the first element of the array
 */
static const struct lm75_params device_params[] = {
	[adt75] = {
		.clr_mask = 1 << 5,	/* not one-shot mode */
		.default_resolution = 12,
		.default_sample_time = MSEC_PER_SEC / 10,
	},
	[as6200] = {
		.config_reg_16bits = true,
		.set_mask = 0xC010,	/* 8 sample/s, 4 CF */
		.default_resolution = 12,
		.default_sample_time = 125,
		.num_sample_times = 4,
		.sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
		.alarm = true,
	},
	[at30ts74] = {
		.set_mask = 3 << 5,	/* 12-bit mode*/
		.default_resolution = 12,
		.default_sample_time = 200,
		.num_sample_times = 4,
		.sample_times = (unsigned int []){ 25, 50, 100, 200 },
		.resolutions = (u8 []) {9, 10, 11, 12 },
	},
	[ds1775] = {
		.clr_mask = 3 << 5,
		.set_mask = 2 << 5,	/* 11-bit mode */
		.default_resolution = 11,
		.default_sample_time = 500,
		.num_sample_times = 4,
		.sample_times = (unsigned int []){ 125, 250, 500, 1000 },
		.resolutions = (u8 []) {9, 10, 11, 12 },
	},
	[ds75] = {
		.clr_mask = 3 << 5,
		.set_mask = 2 << 5,	/* 11-bit mode */
		.default_resolution = 11,
		.default_sample_time = 600,
		.num_sample_times = 4,
		.sample_times = (unsigned int []){ 150, 300, 600, 1200 },
		.resolutions = (u8 []) {9, 10, 11, 12 },
	},
	[stds75] = {

Annotation

Implementation Notes