Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * lm75.c - Part of lm_sensors, Linux kernel modules for hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	 monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/util_macros.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "lm75.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * This driver handles the LM75 and compatible digital temperature sensors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) enum lm75_type {		/* keep sorted in alphabetical order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	adt75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	ds1775,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	ds75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	ds7505,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	g751,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	lm75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	lm75a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	lm75b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	max6625,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	max6626,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	max31725,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	mcp980x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	pct2075,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	stds75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	stlm75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	tcn75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	tmp100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	tmp101,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	tmp105,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	tmp112,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	tmp175,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	tmp275,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	tmp75,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	tmp75b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	tmp75c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * struct lm75_params - lm75 configuration parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @set_mask:		Bits to set in configuration register when configuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *			the chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @clr_mask:		Bits to clear in configuration register when configuring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *			the chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @default_resolution:	Default number of bits to represent the temperature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *			value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * @resolution_limits:	Limit register resolution. Optional. Should be set if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *			the resolution of limit registers does not match the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *			resolution of the temperature register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * @resolutions:	List of resolutions associated with sample times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *			Optional. Should be set if num_sample_times is larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *			than 1, and if the resolution changes with sample times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *			If set, number of entries must match num_sample_times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * @default_sample_time:Sample time to be set by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * @num_sample_times:	Number of possible sample times to be set. Optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *			Should be set if the number of sample times is larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *			than one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * @sample_times:	All the possible sample times to be set. Mandatory if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *			num_sample_times is larger than 1. If set, number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *			entries must match num_sample_times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) struct lm75_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u8			set_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u8			clr_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	u8			default_resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	u8			resolution_limits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	const u8		*resolutions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned int		default_sample_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	u8			num_sample_times;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	const unsigned int	*sample_times;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /* Addresses scanned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /* The LM75 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define LM75_REG_TEMP		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define LM75_REG_CONF		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define LM75_REG_HYST		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define LM75_REG_MAX		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define PCT2075_REG_IDLE	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Each client has this additional data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct lm75_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct i2c_client		*client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct regmap			*regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct regulator		*vs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	u8				orig_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	u8				current_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u8				resolution;	/* In bits, 9 to 16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	unsigned int			sample_time;	/* In ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	enum lm75_type			kind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	const struct lm75_params	*params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*-----------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define LM75_SAMPLE_CLEAR_MASK	(3 << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* The structure below stores the configuration values of the supported devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * In case of being supported multiple configurations, the default one must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * always be the first element of the array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static const struct lm75_params device_params[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	[adt75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		.clr_mask = 1 << 5,	/* not one-shot mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		.default_sample_time = MSEC_PER_SEC / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	[ds1775] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		.clr_mask = 3 << 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		.set_mask = 2 << 5,	/* 11-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		.default_resolution = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		.default_sample_time = 500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		.sample_times = (unsigned int []){ 125, 250, 500, 1000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	[ds75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		.clr_mask = 3 << 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		.set_mask = 2 << 5,	/* 11-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		.default_resolution = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		.default_sample_time = 600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		.sample_times = (unsigned int []){ 150, 300, 600, 1200 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	[stds75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		.clr_mask = 3 << 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		.set_mask = 2 << 5,	/* 11-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		.default_resolution = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		.default_sample_time = 600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		.sample_times = (unsigned int []){ 150, 300, 600, 1200 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	[stlm75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		.default_resolution = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		.default_sample_time = MSEC_PER_SEC / 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	[ds7505] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		.set_mask = 3 << 5,	/* 12-bit mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		.default_sample_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		.sample_times = (unsigned int []){ 25, 50, 100, 200 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	[g751] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		.default_resolution = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		.default_sample_time = MSEC_PER_SEC / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	[lm75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		.default_resolution = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		.default_sample_time = MSEC_PER_SEC / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	[lm75a] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		.default_resolution = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		.default_sample_time = MSEC_PER_SEC / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	[lm75b] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		.default_resolution = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		.default_sample_time = MSEC_PER_SEC / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	[max6625] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		.default_resolution = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		.default_sample_time = MSEC_PER_SEC / 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	[max6626] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		.default_sample_time = MSEC_PER_SEC / 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		.resolution_limits = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	[max31725] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		.default_resolution = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		.default_sample_time = MSEC_PER_SEC / 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	[tcn75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		.default_resolution = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		.default_sample_time = MSEC_PER_SEC / 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	[pct2075] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		.default_resolution = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		.default_sample_time = MSEC_PER_SEC / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		.num_sample_times = 31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		.sample_times = (unsigned int []){ 100, 200, 300, 400, 500, 600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		2800, 2900, 3000, 3100 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	[mcp980x] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		.clr_mask = 1 << 7,	/* not one-shot mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		.resolution_limits = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		.default_sample_time = 240,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		.sample_times = (unsigned int []){ 30, 60, 120, 240 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	[tmp100] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		.clr_mask = 1 << 7,	/* not one-shot mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		.default_sample_time = 320,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		.sample_times = (unsigned int []){ 40, 80, 160, 320 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	[tmp101] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		.clr_mask = 1 << 7,	/* not one-shot mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		.default_sample_time = 320,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		.sample_times = (unsigned int []){ 40, 80, 160, 320 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	[tmp105] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		.clr_mask = 1 << 7,	/* not one-shot mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		.default_sample_time = 220,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		.sample_times = (unsigned int []){ 28, 55, 110, 220 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	[tmp112] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		.set_mask = 3 << 5,	/* 8 samples / second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		.clr_mask = 1 << 7,	/* no one-shot mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		.default_sample_time = 125,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		.sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	[tmp175] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		.clr_mask = 1 << 7,	/* not one-shot mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		.default_sample_time = 220,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		.sample_times = (unsigned int []){ 28, 55, 110, 220 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	[tmp275] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		.clr_mask = 1 << 7,	/* not one-shot mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		.default_sample_time = 220,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		.sample_times = (unsigned int []){ 28, 55, 110, 220 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	[tmp75] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		.set_mask = 3 << 5,	/* 12-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		.clr_mask = 1 << 7,	/* not one-shot mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		.default_sample_time = 220,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		.sample_times = (unsigned int []){ 28, 55, 110, 220 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		.resolutions = (u8 []) {9, 10, 11, 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	[tmp75b] = { /* not one-shot mode, Conversion rate 37Hz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		.clr_mask = 1 << 7 | 3 << 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		.default_sample_time = MSEC_PER_SEC / 37,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		.sample_times = (unsigned int []){ MSEC_PER_SEC / 37,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			MSEC_PER_SEC / 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			MSEC_PER_SEC / 9, MSEC_PER_SEC / 4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		.num_sample_times = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	[tmp75c] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		.clr_mask = 1 << 5,	/*not one-shot mode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		.default_resolution = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		.default_sample_time = MSEC_PER_SEC / 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int lm75_write_config(struct lm75_data *data, u8 set_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			     u8 clr_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	u8 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	clr_mask |= LM75_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	value = data->current_conf & ~clr_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	value |= set_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (data->current_conf != value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		s32 err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		err = i2c_smbus_write_byte_data(data->client, LM75_REG_CONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 						value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		data->current_conf = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static int lm75_read(struct device *dev, enum hwmon_sensor_types type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		     u32 attr, int channel, long *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct lm75_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	unsigned int regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	int err, reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	case hwmon_chip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		case hwmon_chip_update_interval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			*val = data->sample_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	case hwmon_temp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		case hwmon_temp_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			reg = LM75_REG_TEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		case hwmon_temp_max:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			reg = LM75_REG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		case hwmon_temp_max_hyst:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			reg = LM75_REG_HYST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		err = regmap_read(data->regmap, reg, &regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		*val = lm75_reg_to_mc(regval, data->resolution);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static int lm75_write_temp(struct device *dev, u32 attr, long temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct lm75_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	u8 resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	case hwmon_temp_max:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		reg = LM75_REG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	case hwmon_temp_max_hyst:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		reg = LM75_REG_HYST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 * Resolution of limit registers is assumed to be the same as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 * temperature input register resolution unless given explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	if (data->params->resolution_limits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		resolution = data->params->resolution_limits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		resolution = data->resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	temp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	temp = DIV_ROUND_CLOSEST(temp  << (resolution - 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				 1000) << (16 - resolution);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	return regmap_write(data->regmap, reg, (u16)temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static int lm75_update_interval(struct device *dev, long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct lm75_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	unsigned int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	u8 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	s32 err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	index = find_closest(val, data->params->sample_times,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			     (int)data->params->num_sample_times);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	switch (data->kind) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		err = lm75_write_config(data, lm75_sample_set_masks[index],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 					LM75_SAMPLE_CLEAR_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		data->sample_time = data->params->sample_times[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		if (data->params->resolutions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			data->resolution = data->params->resolutions[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	case tmp112:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		err = regmap_read(data->regmap, LM75_REG_CONF, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		reg &= ~0x00c0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		reg |= (3 - index) << 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		err = regmap_write(data->regmap, LM75_REG_CONF, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		data->sample_time = data->params->sample_times[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	case pct2075:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		err = i2c_smbus_write_byte_data(data->client, PCT2075_REG_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 						index + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		data->sample_time = data->params->sample_times[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static int lm75_write_chip(struct device *dev, u32 attr, long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	case hwmon_chip_update_interval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		return lm75_update_interval(dev, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		      u32 attr, int channel, long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	case hwmon_chip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		return lm75_write_chip(dev, attr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	case hwmon_temp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		return lm75_write_temp(dev, attr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			       u32 attr, int channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	const struct lm75_data *config_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	case hwmon_chip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		case hwmon_chip_update_interval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			if (config_data->params->num_sample_times > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 				return 0644;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			return 0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	case hwmon_temp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		case hwmon_temp_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			return 0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		case hwmon_temp_max:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		case hwmon_temp_max_hyst:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			return 0644;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static const struct hwmon_channel_info *lm75_info[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	HWMON_CHANNEL_INFO(chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			   HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	HWMON_CHANNEL_INFO(temp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static const struct hwmon_ops lm75_hwmon_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	.is_visible = lm75_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	.read = lm75_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	.write = lm75_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static const struct hwmon_chip_info lm75_chip_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	.ops = &lm75_hwmon_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	.info = lm75_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static bool lm75_is_writeable_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	return reg != LM75_REG_TEMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	return reg == LM75_REG_TEMP || reg == LM75_REG_CONF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static const struct regmap_config lm75_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	.reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	.val_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	.max_register = PCT2075_REG_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	.writeable_reg = lm75_is_writeable_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	.volatile_reg = lm75_is_volatile_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	.val_format_endian = REGMAP_ENDIAN_BIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	.cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	.use_single_read = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	.use_single_write = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static void lm75_disable_regulator(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	struct lm75_data *lm75 = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	regulator_disable(lm75->vs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static void lm75_remove(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	struct lm75_data *lm75 = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	struct i2c_client *client = lm75->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static const struct i2c_device_id lm75_ids[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static int lm75_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	struct lm75_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	int status, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	enum lm75_type kind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (client->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		kind = (enum lm75_type)of_device_get_match_data(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		kind = i2c_match_id(lm75_ids, client)->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	if (!i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 			I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	data = devm_kzalloc(dev, sizeof(struct lm75_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	data->kind = kind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	data->vs = devm_regulator_get(dev, "vs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	if (IS_ERR(data->vs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		return PTR_ERR(data->vs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	data->regmap = devm_regmap_init_i2c(client, &lm75_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	if (IS_ERR(data->regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		return PTR_ERR(data->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	/* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	 * Then tweak to be more precise when appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	data->params = &device_params[data->kind];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	/* Save default sample time and resolution*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	data->sample_time = data->params->default_sample_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	data->resolution = data->params->default_resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	/* Enable the power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	err = regulator_enable(data->vs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		dev_err(dev, "failed to enable regulator: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	err = devm_add_action_or_reset(dev, lm75_disable_regulator, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	/* Cache original configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	status = i2c_smbus_read_byte_data(client, LM75_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		dev_dbg(dev, "Can't read config? %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	data->orig_conf = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	data->current_conf = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	err = lm75_write_config(data, data->params->set_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 				data->params->clr_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	err = devm_add_action_or_reset(dev, lm75_remove, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 							 data, &lm75_chip_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 							 NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	if (IS_ERR(hwmon_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		return PTR_ERR(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), client->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static const struct i2c_device_id lm75_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	{ "adt75", adt75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	{ "ds1775", ds1775, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	{ "ds75", ds75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	{ "ds7505", ds7505, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	{ "g751", g751, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	{ "lm75", lm75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	{ "lm75a", lm75a, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	{ "lm75b", lm75b, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	{ "max6625", max6625, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	{ "max6626", max6626, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	{ "max31725", max31725, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	{ "max31726", max31725, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	{ "mcp980x", mcp980x, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	{ "pct2075", pct2075, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	{ "stds75", stds75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	{ "stlm75", stlm75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	{ "tcn75", tcn75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	{ "tmp100", tmp100, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	{ "tmp101", tmp101, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	{ "tmp105", tmp105, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	{ "tmp112", tmp112, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	{ "tmp175", tmp175, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	{ "tmp275", tmp275, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	{ "tmp75", tmp75, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	{ "tmp75b", tmp75b, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	{ "tmp75c", tmp75c, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	{ /* LIST END */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) MODULE_DEVICE_TABLE(i2c, lm75_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static const struct of_device_id __maybe_unused lm75_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		.compatible = "adi,adt75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		.data = (void *)adt75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		.compatible = "dallas,ds1775",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		.data = (void *)ds1775
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		.compatible = "dallas,ds75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		.data = (void *)ds75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		.compatible = "dallas,ds7505",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		.data = (void *)ds7505
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		.compatible = "gmt,g751",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		.data = (void *)g751
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		.compatible = "national,lm75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		.data = (void *)lm75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		.compatible = "national,lm75a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		.data = (void *)lm75a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		.compatible = "national,lm75b",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 		.data = (void *)lm75b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		.compatible = "maxim,max6625",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 		.data = (void *)max6625
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		.compatible = "maxim,max6626",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 		.data = (void *)max6626
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		.compatible = "maxim,max31725",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		.data = (void *)max31725
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		.compatible = "maxim,max31726",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		.data = (void *)max31725
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 		.compatible = "maxim,mcp980x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		.data = (void *)mcp980x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 		.compatible = "nxp,pct2075",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		.data = (void *)pct2075
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		.compatible = "st,stds75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 		.data = (void *)stds75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		.compatible = "st,stlm75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 		.data = (void *)stlm75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		.compatible = "microchip,tcn75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		.data = (void *)tcn75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		.compatible = "ti,tmp100",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		.data = (void *)tmp100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		.compatible = "ti,tmp101",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 		.data = (void *)tmp101
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		.compatible = "ti,tmp105",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 		.data = (void *)tmp105
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		.compatible = "ti,tmp112",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 		.data = (void *)tmp112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		.compatible = "ti,tmp175",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		.data = (void *)tmp175
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		.compatible = "ti,tmp275",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		.data = (void *)tmp275
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 		.compatible = "ti,tmp75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		.data = (void *)tmp75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		.compatible = "ti,tmp75b",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		.data = (void *)tmp75b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		.compatible = "ti,tmp75c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		.data = (void *)tmp75c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) MODULE_DEVICE_TABLE(of, lm75_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) #define LM75A_ID 0xA1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) static int lm75_detect(struct i2c_client *new_client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 		       struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	struct i2c_adapter *adapter = new_client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	int conf, hyst, os;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	bool is_lm75a = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 				     I2C_FUNC_SMBUS_WORD_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	 * Now, we do the remaining detection. There is no identification-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	 * dedicated register so we have to rely on several tricks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	 * unused bits, registers cycling over 8-address boundaries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	 * addresses 0x04-0x07 returning the last read value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	 * The cycling+unused addresses combination is not tested,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	 * since it would significantly slow the detection down and would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	 * hardly add any value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	 * The National Semiconductor LM75A is different than earlier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	 * LM75s.  It has an ID byte of 0xaX (where X is the chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	 * revision, with 1 being the only revision in existence) in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	 * register 7, and unused registers return 0xff rather than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	 * last read value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	 * Note that this function only detects the original National
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	 * Semiconductor LM75 and the LM75A. Clones from other vendors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	 * aren't detected, on purpose, because they are typically never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	 * found on PC hardware. They are found on embedded designs where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	 * they can be instantiated explicitly so detection is not needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	 * The absence of identification registers on all these clones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	 * would make their exhaustive detection very difficult and weak,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	 * and odds are that the driver would bind to unsupported devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	/* Unused bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	conf = i2c_smbus_read_byte_data(new_client, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	if (conf & 0xe0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	/* First check for LM75A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	if (i2c_smbus_read_byte_data(new_client, 7) == LM75A_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		 * LM75A returns 0xff on unused registers so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		 * just to be sure we check for that too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 		if (i2c_smbus_read_byte_data(new_client, 4) != 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 		 || i2c_smbus_read_byte_data(new_client, 5) != 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		 || i2c_smbus_read_byte_data(new_client, 6) != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 		is_lm75a = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		hyst = i2c_smbus_read_byte_data(new_client, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		os = i2c_smbus_read_byte_data(new_client, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	} else { /* Traditional style LM75 detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 		/* Unused addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 		hyst = i2c_smbus_read_byte_data(new_client, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		if (i2c_smbus_read_byte_data(new_client, 4) != hyst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		 || i2c_smbus_read_byte_data(new_client, 5) != hyst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 		 || i2c_smbus_read_byte_data(new_client, 6) != hyst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		 || i2c_smbus_read_byte_data(new_client, 7) != hyst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		os = i2c_smbus_read_byte_data(new_client, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 		if (i2c_smbus_read_byte_data(new_client, 4) != os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		 || i2c_smbus_read_byte_data(new_client, 5) != os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		 || i2c_smbus_read_byte_data(new_client, 6) != os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		 || i2c_smbus_read_byte_data(new_client, 7) != os)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	 * It is very unlikely that this is a LM75 if both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	 * hysteresis and temperature limit registers are 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	if (hyst == 0 && os == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	/* Addresses cycling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	for (i = 8; i <= 248; i += 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 		 || i2c_smbus_read_byte_data(new_client, i + 2) != hyst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		 || i2c_smbus_read_byte_data(new_client, i + 3) != os)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		if (is_lm75a && i2c_smbus_read_byte_data(new_client, i + 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 				!= LM75A_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	strlcpy(info->type, is_lm75a ? "lm75a" : "lm75", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) static int lm75_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	status = i2c_smbus_read_byte_data(client, LM75_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 		dev_dbg(&client->dev, "Can't read config? %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	status = status | LM75_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	i2c_smbus_write_byte_data(client, LM75_REG_CONF, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) static int lm75_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 	status = i2c_smbus_read_byte_data(client, LM75_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 	if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 		dev_dbg(&client->dev, "Can't read config? %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	status = status & ~LM75_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	i2c_smbus_write_byte_data(client, LM75_REG_CONF, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) static const struct dev_pm_ops lm75_dev_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	.suspend	= lm75_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 	.resume		= lm75_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) #define LM75_DEV_PM_OPS (&lm75_dev_pm_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) #define LM75_DEV_PM_OPS NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) static struct i2c_driver lm75_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	.class		= I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 		.name	= "lm75",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 		.of_match_table = of_match_ptr(lm75_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 		.pm	= LM75_DEV_PM_OPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 	.probe_new	= lm75_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 	.id_table	= lm75_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 	.detect		= lm75_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 	.address_list	= normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) module_i2c_driver(lm75_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) MODULE_DESCRIPTION("LM75 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) MODULE_LICENSE("GPL");