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