Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 2 | /* |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 3 | * Hardware monitoring driver for LTC2978 and compatible chips. |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2011 Ericsson AB. |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 6 | * Copyright (c) 2013, 2014, 2015 Guenter Roeck |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 7 | * Copyright (c) 2015 Linear Technology |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 8 | * Copyright (c) 2018 Analog Devices Inc. |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 11 | #include <linux/delay.h> |
| 12 | #include <linux/jiffies.h> |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/i2c.h> |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 19 | #include <linux/regulator/driver.h> |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 20 | #include "pmbus.h" |
| 21 | |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 22 | enum chips { ltc2974, ltc2975, ltc2977, ltc2978, ltc2980, ltc3880, ltc3882, |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 23 | ltc3883, ltc3886, ltc3887, ltm2987, ltm4675, ltm4676, ltm4686 }; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 24 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 25 | /* Common for all chips */ |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 26 | #define LTC2978_MFR_VOUT_PEAK 0xdd |
| 27 | #define LTC2978_MFR_VIN_PEAK 0xde |
| 28 | #define LTC2978_MFR_TEMPERATURE_PEAK 0xdf |
Guenter Roeck | acb092c | 2015-08-17 06:27:56 -0700 | [diff] [blame] | 29 | #define LTC2978_MFR_SPECIAL_ID 0xe7 /* Undocumented on LTC3882 */ |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 30 | #define LTC2978_MFR_COMMON 0xef |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 31 | |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 32 | /* LTC2974, LTC2975, LCT2977, LTC2980, LTC2978, and LTM2987 */ |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 33 | #define LTC2978_MFR_VOUT_MIN 0xfb |
| 34 | #define LTC2978_MFR_VIN_MIN 0xfc |
| 35 | #define LTC2978_MFR_TEMPERATURE_MIN 0xfd |
| 36 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 37 | /* LTC2974, LTC2975 */ |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 38 | #define LTC2974_MFR_IOUT_PEAK 0xd7 |
| 39 | #define LTC2974_MFR_IOUT_MIN 0xd8 |
| 40 | |
Guenter Roeck | ccf2dc5 | 2015-08-17 20:08:09 -0700 | [diff] [blame] | 41 | /* LTC3880, LTC3882, LTC3883, LTC3887, LTM4675, and LTM4676 */ |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 42 | #define LTC3880_MFR_IOUT_PEAK 0xd7 |
| 43 | #define LTC3880_MFR_CLEAR_PEAKS 0xe3 |
| 44 | #define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4 |
| 45 | |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 46 | /* LTC3883 and LTC3886 only */ |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 47 | #define LTC3883_MFR_IIN_PEAK 0xe1 |
| 48 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 49 | /* LTC2975 only */ |
| 50 | #define LTC2975_MFR_IIN_PEAK 0xc4 |
| 51 | #define LTC2975_MFR_IIN_MIN 0xc5 |
| 52 | #define LTC2975_MFR_PIN_PEAK 0xc6 |
| 53 | #define LTC2975_MFR_PIN_MIN 0xc7 |
| 54 | |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 55 | #define LTC2978_ID_MASK 0xfff0 |
| 56 | |
| 57 | #define LTC2974_ID 0x0210 |
| 58 | #define LTC2975_ID 0x0220 |
Guenter Roeck | c24c407e | 2013-09-23 10:56:48 -0700 | [diff] [blame] | 59 | #define LTC2977_ID 0x0130 |
Guenter Roeck | acb092c | 2015-08-17 06:27:56 -0700 | [diff] [blame] | 60 | #define LTC2978_ID_REV1 0x0110 /* Early revision */ |
| 61 | #define LTC2978_ID_REV2 0x0120 |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 62 | #define LTC2980_ID_A 0x8030 /* A/B for two die IDs */ |
| 63 | #define LTC2980_ID_B 0x8040 |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 64 | #define LTC3880_ID 0x4020 |
Guenter Roeck | acb092c | 2015-08-17 06:27:56 -0700 | [diff] [blame] | 65 | #define LTC3882_ID 0x4200 |
| 66 | #define LTC3882_ID_D1 0x4240 /* Dash 1 */ |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 67 | #define LTC3883_ID 0x4300 |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 68 | #define LTC3886_ID 0x4600 |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 69 | #define LTC3887_ID 0x4700 |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 70 | #define LTM2987_ID_A 0x8010 /* A/B for two die IDs */ |
| 71 | #define LTM2987_ID_B 0x8020 |
Guenter Roeck | ccf2dc5 | 2015-08-17 20:08:09 -0700 | [diff] [blame] | 72 | #define LTM4675_ID 0x47a0 |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 73 | #define LTM4676_ID_REV1 0x4400 |
| 74 | #define LTM4676_ID_REV2 0x4480 |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 75 | #define LTM4676A_ID 0x47e0 |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 76 | #define LTM4686_ID 0x4770 |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 77 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 78 | #define LTC2974_NUM_PAGES 4 |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 79 | #define LTC2978_NUM_PAGES 8 |
| 80 | #define LTC3880_NUM_PAGES 2 |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 81 | #define LTC3883_NUM_PAGES 1 |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 82 | |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 83 | #define LTC_POLL_TIMEOUT 100 /* in milli-seconds */ |
| 84 | |
| 85 | #define LTC_NOT_BUSY BIT(5) |
| 86 | #define LTC_NOT_PENDING BIT(4) |
| 87 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 88 | /* |
| 89 | * LTC2978 clears peak data whenever the CLEAR_FAULTS command is executed, which |
| 90 | * happens pretty much each time chip data is updated. Raw peak data therefore |
| 91 | * does not provide much value. To be able to provide useful peak data, keep an |
| 92 | * internal cache of measured peak data, which is only cleared if an explicit |
| 93 | * "clear peak" command is executed for the sensor in question. |
| 94 | */ |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 95 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 96 | struct ltc2978_data { |
| 97 | enum chips id; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 98 | u16 vin_min, vin_max; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 99 | u16 temp_min[LTC2974_NUM_PAGES], temp_max[LTC2974_NUM_PAGES]; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 100 | u16 vout_min[LTC2978_NUM_PAGES], vout_max[LTC2978_NUM_PAGES]; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 101 | u16 iout_min[LTC2974_NUM_PAGES], iout_max[LTC2974_NUM_PAGES]; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 102 | u16 iin_min, iin_max; |
| 103 | u16 pin_min, pin_max; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 104 | u16 temp2_max; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 105 | struct pmbus_driver_info info; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 106 | u32 features; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 107 | }; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 108 | #define to_ltc2978_data(x) container_of(x, struct ltc2978_data, info) |
| 109 | |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 110 | #define FEAT_CLEAR_PEAKS BIT(0) |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 111 | #define FEAT_NEEDS_POLLING BIT(1) |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 112 | |
| 113 | #define has_clear_peaks(d) ((d)->features & FEAT_CLEAR_PEAKS) |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 114 | #define needs_polling(d) ((d)->features & FEAT_NEEDS_POLLING) |
| 115 | |
| 116 | static int ltc_wait_ready(struct i2c_client *client) |
| 117 | { |
| 118 | unsigned long timeout = jiffies + msecs_to_jiffies(LTC_POLL_TIMEOUT); |
| 119 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 120 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 121 | int status; |
| 122 | u8 mask; |
| 123 | |
| 124 | if (!needs_polling(data)) |
| 125 | return 0; |
| 126 | |
| 127 | /* |
| 128 | * LTC3883 does not support LTC_NOT_PENDING, even though |
| 129 | * the datasheet claims that it does. |
| 130 | */ |
| 131 | mask = LTC_NOT_BUSY; |
| 132 | if (data->id != ltc3883) |
| 133 | mask |= LTC_NOT_PENDING; |
| 134 | |
| 135 | do { |
| 136 | status = pmbus_read_byte_data(client, 0, LTC2978_MFR_COMMON); |
| 137 | if (status == -EBADMSG || status == -ENXIO) { |
| 138 | /* PEC error or NACK: chip may be busy, try again */ |
| 139 | usleep_range(50, 100); |
| 140 | continue; |
| 141 | } |
| 142 | if (status < 0) |
| 143 | return status; |
| 144 | |
| 145 | if ((status & mask) == mask) |
| 146 | return 0; |
| 147 | |
| 148 | usleep_range(50, 100); |
| 149 | } while (time_before(jiffies, timeout)); |
| 150 | |
| 151 | return -ETIMEDOUT; |
| 152 | } |
| 153 | |
| 154 | static int ltc_read_word_data(struct i2c_client *client, int page, int reg) |
| 155 | { |
| 156 | int ret; |
| 157 | |
| 158 | ret = ltc_wait_ready(client); |
| 159 | if (ret < 0) |
| 160 | return ret; |
| 161 | |
| 162 | return pmbus_read_word_data(client, page, reg); |
| 163 | } |
| 164 | |
| 165 | static int ltc_read_byte_data(struct i2c_client *client, int page, int reg) |
| 166 | { |
| 167 | int ret; |
| 168 | |
| 169 | ret = ltc_wait_ready(client); |
| 170 | if (ret < 0) |
| 171 | return ret; |
| 172 | |
| 173 | return pmbus_read_byte_data(client, page, reg); |
| 174 | } |
| 175 | |
| 176 | static int ltc_write_byte(struct i2c_client *client, int page, u8 byte) |
| 177 | { |
| 178 | int ret; |
| 179 | |
| 180 | ret = ltc_wait_ready(client); |
| 181 | if (ret < 0) |
| 182 | return ret; |
| 183 | |
| 184 | return pmbus_write_byte(client, page, byte); |
| 185 | } |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 186 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 187 | static inline int lin11_to_val(int data) |
| 188 | { |
| 189 | s16 e = ((s16)data) >> 11; |
| 190 | s32 m = (((s16)(data << 5)) >> 5); |
| 191 | |
| 192 | /* |
| 193 | * mantissa is 10 bit + sign, exponent adds up to 15 bit. |
| 194 | * Add 6 bit to exponent for maximum accuracy (10 + 15 + 6 = 31). |
| 195 | */ |
| 196 | e += 6; |
| 197 | return (e < 0 ? m >> -e : m << e); |
| 198 | } |
| 199 | |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 200 | static int ltc_get_max(struct ltc2978_data *data, struct i2c_client *client, |
| 201 | int page, int reg, u16 *pmax) |
| 202 | { |
| 203 | int ret; |
| 204 | |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 205 | ret = ltc_read_word_data(client, page, reg); |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 206 | if (ret >= 0) { |
| 207 | if (lin11_to_val(ret) > lin11_to_val(*pmax)) |
| 208 | *pmax = ret; |
| 209 | ret = *pmax; |
| 210 | } |
| 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | static int ltc_get_min(struct ltc2978_data *data, struct i2c_client *client, |
| 215 | int page, int reg, u16 *pmin) |
| 216 | { |
| 217 | int ret; |
| 218 | |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 219 | ret = ltc_read_word_data(client, page, reg); |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 220 | if (ret >= 0) { |
| 221 | if (lin11_to_val(ret) < lin11_to_val(*pmin)) |
| 222 | *pmin = ret; |
| 223 | ret = *pmin; |
| 224 | } |
| 225 | return ret; |
| 226 | } |
| 227 | |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 228 | static int ltc2978_read_word_data_common(struct i2c_client *client, int page, |
| 229 | int reg) |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 230 | { |
| 231 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 232 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 233 | int ret; |
| 234 | |
| 235 | switch (reg) { |
| 236 | case PMBUS_VIRT_READ_VIN_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 237 | ret = ltc_get_max(data, client, page, LTC2978_MFR_VIN_PEAK, |
| 238 | &data->vin_max); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 239 | break; |
| 240 | case PMBUS_VIRT_READ_VOUT_MAX: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 241 | ret = ltc_read_word_data(client, page, LTC2978_MFR_VOUT_PEAK); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 242 | if (ret >= 0) { |
| 243 | /* |
| 244 | * VOUT is 16 bit unsigned with fixed exponent, |
| 245 | * so we can compare it directly |
| 246 | */ |
| 247 | if (ret > data->vout_max[page]) |
| 248 | data->vout_max[page] = ret; |
| 249 | ret = data->vout_max[page]; |
| 250 | } |
| 251 | break; |
| 252 | case PMBUS_VIRT_READ_TEMP_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 253 | ret = ltc_get_max(data, client, page, |
| 254 | LTC2978_MFR_TEMPERATURE_PEAK, |
| 255 | &data->temp_max[page]); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 256 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 257 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 258 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
| 259 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
| 260 | ret = 0; |
| 261 | break; |
| 262 | default: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 263 | ret = ltc_wait_ready(client); |
| 264 | if (ret < 0) |
| 265 | return ret; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 266 | ret = -ENODATA; |
| 267 | break; |
| 268 | } |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | static int ltc2978_read_word_data(struct i2c_client *client, int page, int reg) |
| 273 | { |
| 274 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 275 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 276 | int ret; |
| 277 | |
| 278 | switch (reg) { |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 279 | case PMBUS_VIRT_READ_VIN_MIN: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 280 | ret = ltc_get_min(data, client, page, LTC2978_MFR_VIN_MIN, |
| 281 | &data->vin_min); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 282 | break; |
| 283 | case PMBUS_VIRT_READ_VOUT_MIN: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 284 | ret = ltc_read_word_data(client, page, LTC2978_MFR_VOUT_MIN); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 285 | if (ret >= 0) { |
| 286 | /* |
| 287 | * VOUT_MIN is known to not be supported on some lots |
| 288 | * of LTC2978 revision 1, and will return the maximum |
| 289 | * possible voltage if read. If VOUT_MAX is valid and |
| 290 | * lower than the reading of VOUT_MIN, use it instead. |
| 291 | */ |
| 292 | if (data->vout_max[page] && ret > data->vout_max[page]) |
| 293 | ret = data->vout_max[page]; |
| 294 | if (ret < data->vout_min[page]) |
| 295 | data->vout_min[page] = ret; |
| 296 | ret = data->vout_min[page]; |
| 297 | } |
| 298 | break; |
| 299 | case PMBUS_VIRT_READ_TEMP_MIN: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 300 | ret = ltc_get_min(data, client, page, |
| 301 | LTC2978_MFR_TEMPERATURE_MIN, |
| 302 | &data->temp_min[page]); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 303 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 304 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 305 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 306 | case PMBUS_VIRT_READ_TEMP2_MAX: |
| 307 | case PMBUS_VIRT_RESET_TEMP2_HISTORY: |
| 308 | ret = -ENXIO; |
| 309 | break; |
| 310 | default: |
| 311 | ret = ltc2978_read_word_data_common(client, page, reg); |
| 312 | break; |
| 313 | } |
| 314 | return ret; |
| 315 | } |
| 316 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 317 | static int ltc2974_read_word_data(struct i2c_client *client, int page, int reg) |
| 318 | { |
| 319 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 320 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 321 | int ret; |
| 322 | |
| 323 | switch (reg) { |
| 324 | case PMBUS_VIRT_READ_IOUT_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 325 | ret = ltc_get_max(data, client, page, LTC2974_MFR_IOUT_PEAK, |
| 326 | &data->iout_max[page]); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 327 | break; |
| 328 | case PMBUS_VIRT_READ_IOUT_MIN: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 329 | ret = ltc_get_min(data, client, page, LTC2974_MFR_IOUT_MIN, |
| 330 | &data->iout_min[page]); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 331 | break; |
| 332 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 333 | ret = 0; |
| 334 | break; |
| 335 | default: |
| 336 | ret = ltc2978_read_word_data(client, page, reg); |
| 337 | break; |
| 338 | } |
| 339 | return ret; |
| 340 | } |
| 341 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 342 | static int ltc2975_read_word_data(struct i2c_client *client, int page, int reg) |
| 343 | { |
| 344 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 345 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 346 | int ret; |
| 347 | |
| 348 | switch (reg) { |
| 349 | case PMBUS_VIRT_READ_IIN_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 350 | ret = ltc_get_max(data, client, page, LTC2975_MFR_IIN_PEAK, |
| 351 | &data->iin_max); |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 352 | break; |
| 353 | case PMBUS_VIRT_READ_IIN_MIN: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 354 | ret = ltc_get_min(data, client, page, LTC2975_MFR_IIN_MIN, |
| 355 | &data->iin_min); |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 356 | break; |
| 357 | case PMBUS_VIRT_READ_PIN_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 358 | ret = ltc_get_max(data, client, page, LTC2975_MFR_PIN_PEAK, |
| 359 | &data->pin_max); |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 360 | break; |
| 361 | case PMBUS_VIRT_READ_PIN_MIN: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 362 | ret = ltc_get_min(data, client, page, LTC2975_MFR_PIN_MIN, |
| 363 | &data->pin_min); |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 364 | break; |
| 365 | case PMBUS_VIRT_RESET_IIN_HISTORY: |
| 366 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
| 367 | ret = 0; |
| 368 | break; |
| 369 | default: |
| 370 | ret = ltc2978_read_word_data(client, page, reg); |
| 371 | break; |
| 372 | } |
| 373 | return ret; |
| 374 | } |
| 375 | |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 376 | static int ltc3880_read_word_data(struct i2c_client *client, int page, int reg) |
| 377 | { |
| 378 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 379 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 380 | int ret; |
| 381 | |
| 382 | switch (reg) { |
| 383 | case PMBUS_VIRT_READ_IOUT_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 384 | ret = ltc_get_max(data, client, page, LTC3880_MFR_IOUT_PEAK, |
| 385 | &data->iout_max[page]); |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 386 | break; |
| 387 | case PMBUS_VIRT_READ_TEMP2_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 388 | ret = ltc_get_max(data, client, page, |
| 389 | LTC3880_MFR_TEMPERATURE2_PEAK, |
| 390 | &data->temp2_max); |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 391 | break; |
| 392 | case PMBUS_VIRT_READ_VIN_MIN: |
| 393 | case PMBUS_VIRT_READ_VOUT_MIN: |
| 394 | case PMBUS_VIRT_READ_TEMP_MIN: |
| 395 | ret = -ENXIO; |
| 396 | break; |
| 397 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 398 | case PMBUS_VIRT_RESET_TEMP2_HISTORY: |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 399 | ret = 0; |
| 400 | break; |
| 401 | default: |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 402 | ret = ltc2978_read_word_data_common(client, page, reg); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | return ret; |
| 406 | } |
| 407 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 408 | static int ltc3883_read_word_data(struct i2c_client *client, int page, int reg) |
| 409 | { |
| 410 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 411 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 412 | int ret; |
| 413 | |
| 414 | switch (reg) { |
| 415 | case PMBUS_VIRT_READ_IIN_MAX: |
Guenter Roeck | ee847a2 | 2015-08-15 17:17:53 -0700 | [diff] [blame] | 416 | ret = ltc_get_max(data, client, page, LTC3883_MFR_IIN_PEAK, |
| 417 | &data->iin_max); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 418 | break; |
| 419 | case PMBUS_VIRT_RESET_IIN_HISTORY: |
| 420 | ret = 0; |
| 421 | break; |
| 422 | default: |
| 423 | ret = ltc3880_read_word_data(client, page, reg); |
| 424 | break; |
| 425 | } |
| 426 | return ret; |
| 427 | } |
| 428 | |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 429 | static int ltc2978_clear_peaks(struct ltc2978_data *data, |
| 430 | struct i2c_client *client, int page) |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 431 | { |
| 432 | int ret; |
| 433 | |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 434 | if (has_clear_peaks(data)) |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 435 | ret = ltc_write_byte(client, 0, LTC3880_MFR_CLEAR_PEAKS); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 436 | else |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 437 | ret = ltc_write_byte(client, page, PMBUS_CLEAR_FAULTS); |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 438 | |
| 439 | return ret; |
| 440 | } |
| 441 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 442 | static int ltc2978_write_word_data(struct i2c_client *client, int page, |
| 443 | int reg, u16 word) |
| 444 | { |
| 445 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 446 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 447 | int ret; |
| 448 | |
| 449 | switch (reg) { |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 450 | case PMBUS_VIRT_RESET_IIN_HISTORY: |
| 451 | data->iin_max = 0x7c00; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 452 | data->iin_min = 0x7bff; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 453 | ret = ltc2978_clear_peaks(data, client, 0); |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 454 | break; |
| 455 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
| 456 | data->pin_max = 0x7c00; |
| 457 | data->pin_min = 0x7bff; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 458 | ret = ltc2978_clear_peaks(data, client, 0); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 459 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 460 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 461 | data->iout_max[page] = 0x7c00; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 462 | data->iout_min[page] = 0xfbff; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 463 | ret = ltc2978_clear_peaks(data, client, page); |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 464 | break; |
| 465 | case PMBUS_VIRT_RESET_TEMP2_HISTORY: |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 466 | data->temp2_max = 0x7c00; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 467 | ret = ltc2978_clear_peaks(data, client, page); |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 468 | break; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 469 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 470 | data->vout_min[page] = 0xffff; |
| 471 | data->vout_max[page] = 0; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 472 | ret = ltc2978_clear_peaks(data, client, page); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 473 | break; |
| 474 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
| 475 | data->vin_min = 0x7bff; |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 476 | data->vin_max = 0x7c00; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 477 | ret = ltc2978_clear_peaks(data, client, page); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 478 | break; |
| 479 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 480 | data->temp_min[page] = 0x7bff; |
Guenter Roeck | 8c958c7 | 2013-02-21 10:27:54 -0800 | [diff] [blame] | 481 | data->temp_max[page] = 0x7c00; |
Guenter Roeck | 8582bcc | 2015-08-15 17:02:09 -0700 | [diff] [blame] | 482 | ret = ltc2978_clear_peaks(data, client, page); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 483 | break; |
| 484 | default: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 485 | ret = ltc_wait_ready(client); |
| 486 | if (ret < 0) |
| 487 | return ret; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 488 | ret = -ENODATA; |
| 489 | break; |
| 490 | } |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | static const struct i2c_device_id ltc2978_id[] = { |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 495 | {"ltc2974", ltc2974}, |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 496 | {"ltc2975", ltc2975}, |
Guenter Roeck | c24c407e | 2013-09-23 10:56:48 -0700 | [diff] [blame] | 497 | {"ltc2977", ltc2977}, |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 498 | {"ltc2978", ltc2978}, |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 499 | {"ltc2980", ltc2980}, |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 500 | {"ltc3880", ltc3880}, |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 501 | {"ltc3882", ltc3882}, |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 502 | {"ltc3883", ltc3883}, |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 503 | {"ltc3886", ltc3886}, |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 504 | {"ltc3887", ltc3887}, |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 505 | {"ltm2987", ltm2987}, |
Guenter Roeck | ccf2dc5 | 2015-08-17 20:08:09 -0700 | [diff] [blame] | 506 | {"ltm4675", ltm4675}, |
Guenter Roeck | f76992b | 2014-03-05 21:23:01 -0800 | [diff] [blame] | 507 | {"ltm4676", ltm4676}, |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 508 | {"ltm4686", ltm4686}, |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 509 | {} |
| 510 | }; |
| 511 | MODULE_DEVICE_TABLE(i2c, ltc2978_id); |
| 512 | |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 513 | #if IS_ENABLED(CONFIG_SENSORS_LTC2978_REGULATOR) |
| 514 | static const struct regulator_desc ltc2978_reg_desc[] = { |
| 515 | PMBUS_REGULATOR("vout", 0), |
| 516 | PMBUS_REGULATOR("vout", 1), |
| 517 | PMBUS_REGULATOR("vout", 2), |
| 518 | PMBUS_REGULATOR("vout", 3), |
| 519 | PMBUS_REGULATOR("vout", 4), |
| 520 | PMBUS_REGULATOR("vout", 5), |
| 521 | PMBUS_REGULATOR("vout", 6), |
| 522 | PMBUS_REGULATOR("vout", 7), |
| 523 | }; |
| 524 | #endif /* CONFIG_SENSORS_LTC2978_REGULATOR */ |
| 525 | |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 526 | static int ltc2978_get_id(struct i2c_client *client) |
| 527 | { |
| 528 | int chip_id; |
| 529 | |
| 530 | chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID); |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 531 | if (chip_id < 0) { |
| 532 | const struct i2c_device_id *id; |
| 533 | u8 buf[I2C_SMBUS_BLOCK_MAX]; |
| 534 | int ret; |
| 535 | |
| 536 | if (!i2c_check_functionality(client->adapter, |
| 537 | I2C_FUNC_SMBUS_READ_BLOCK_DATA)) |
| 538 | return -ENODEV; |
| 539 | |
| 540 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf); |
| 541 | if (ret < 0) |
| 542 | return ret; |
| 543 | if (ret < 3 || strncmp(buf, "LTC", 3)) |
| 544 | return -ENODEV; |
| 545 | |
| 546 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); |
| 547 | if (ret < 0) |
| 548 | return ret; |
| 549 | for (id = <c2978_id[0]; strlen(id->name); id++) { |
| 550 | if (!strncasecmp(id->name, buf, strlen(id->name))) |
| 551 | return (int)id->driver_data; |
| 552 | } |
| 553 | return -ENODEV; |
| 554 | } |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 555 | |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 556 | chip_id &= LTC2978_ID_MASK; |
| 557 | |
| 558 | if (chip_id == LTC2974_ID) |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 559 | return ltc2974; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 560 | else if (chip_id == LTC2975_ID) |
| 561 | return ltc2975; |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 562 | else if (chip_id == LTC2977_ID) |
| 563 | return ltc2977; |
Guenter Roeck | acb092c | 2015-08-17 06:27:56 -0700 | [diff] [blame] | 564 | else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2) |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 565 | return ltc2978; |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 566 | else if (chip_id == LTC2980_ID_A || chip_id == LTC2980_ID_B) |
| 567 | return ltc2980; |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 568 | else if (chip_id == LTC3880_ID) |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 569 | return ltc3880; |
Guenter Roeck | acb092c | 2015-08-17 06:27:56 -0700 | [diff] [blame] | 570 | else if (chip_id == LTC3882_ID || chip_id == LTC3882_ID_D1) |
| 571 | return ltc3882; |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 572 | else if (chip_id == LTC3883_ID) |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 573 | return ltc3883; |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 574 | else if (chip_id == LTC3886_ID) |
| 575 | return ltc3886; |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 576 | else if (chip_id == LTC3887_ID) |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 577 | return ltc3887; |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 578 | else if (chip_id == LTM2987_ID_A || chip_id == LTM2987_ID_B) |
| 579 | return ltm2987; |
Guenter Roeck | ccf2dc5 | 2015-08-17 20:08:09 -0700 | [diff] [blame] | 580 | else if (chip_id == LTM4675_ID) |
| 581 | return ltm4675; |
Guenter Roeck | 00c8337 | 2015-08-17 06:21:01 -0700 | [diff] [blame] | 582 | else if (chip_id == LTM4676_ID_REV1 || chip_id == LTM4676_ID_REV2 || |
| 583 | chip_id == LTM4676A_ID) |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 584 | return ltm4676; |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 585 | else if (chip_id == LTM4686_ID) |
| 586 | return ltm4686; |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 587 | |
| 588 | dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); |
| 589 | return -ENODEV; |
| 590 | } |
| 591 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 592 | static int ltc2978_probe(struct i2c_client *client, |
| 593 | const struct i2c_device_id *id) |
| 594 | { |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 595 | int i, chip_id; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 596 | struct ltc2978_data *data; |
| 597 | struct pmbus_driver_info *info; |
| 598 | |
| 599 | if (!i2c_check_functionality(client->adapter, |
| 600 | I2C_FUNC_SMBUS_READ_WORD_DATA)) |
| 601 | return -ENODEV; |
| 602 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 603 | data = devm_kzalloc(&client->dev, sizeof(struct ltc2978_data), |
| 604 | GFP_KERNEL); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 605 | if (!data) |
| 606 | return -ENOMEM; |
| 607 | |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 608 | chip_id = ltc2978_get_id(client); |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 609 | if (chip_id < 0) |
| 610 | return chip_id; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 611 | |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 612 | data->id = chip_id; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 613 | if (data->id != id->driver_data) |
| 614 | dev_warn(&client->dev, |
| 615 | "Device mismatch: Configured %s, detected %s\n", |
| 616 | id->name, |
| 617 | ltc2978_id[data->id].name); |
| 618 | |
| 619 | info = &data->info; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 620 | info->write_word_data = ltc2978_write_word_data; |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 621 | info->write_byte = ltc_write_byte; |
| 622 | info->read_word_data = ltc_read_word_data; |
| 623 | info->read_byte_data = ltc_read_byte_data; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 624 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 625 | data->vin_min = 0x7bff; |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 626 | data->vin_max = 0x7c00; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 627 | for (i = 0; i < ARRAY_SIZE(data->vout_min); i++) |
| 628 | data->vout_min[i] = 0xffff; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 629 | for (i = 0; i < ARRAY_SIZE(data->iout_min); i++) |
| 630 | data->iout_min[i] = 0xfbff; |
| 631 | for (i = 0; i < ARRAY_SIZE(data->iout_max); i++) |
| 632 | data->iout_max[i] = 0x7c00; |
| 633 | for (i = 0; i < ARRAY_SIZE(data->temp_min); i++) |
| 634 | data->temp_min[i] = 0x7bff; |
Guenter Roeck | 8c958c7 | 2013-02-21 10:27:54 -0800 | [diff] [blame] | 635 | for (i = 0; i < ARRAY_SIZE(data->temp_max); i++) |
| 636 | data->temp_max[i] = 0x7c00; |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 637 | data->temp2_max = 0x7c00; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 638 | |
Guenter Roeck | f366fcc | 2013-02-21 10:49:40 -0800 | [diff] [blame] | 639 | switch (data->id) { |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 640 | case ltc2974: |
| 641 | info->read_word_data = ltc2974_read_word_data; |
| 642 | info->pages = LTC2974_NUM_PAGES; |
| 643 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 644 | | PMBUS_HAVE_TEMP2; |
| 645 | for (i = 0; i < info->pages; i++) { |
| 646 | info->func[i] |= PMBUS_HAVE_VOUT |
| 647 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_POUT |
| 648 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
| 649 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
| 650 | } |
| 651 | break; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 652 | case ltc2975: |
| 653 | info->read_word_data = ltc2975_read_word_data; |
| 654 | info->pages = LTC2974_NUM_PAGES; |
| 655 | info->func[0] = PMBUS_HAVE_IIN | PMBUS_HAVE_PIN |
| 656 | | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 657 | | PMBUS_HAVE_TEMP2; |
| 658 | for (i = 0; i < info->pages; i++) { |
| 659 | info->func[i] |= PMBUS_HAVE_VOUT |
| 660 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_POUT |
| 661 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
| 662 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
| 663 | } |
| 664 | break; |
Guenter Roeck | c24c407e | 2013-09-23 10:56:48 -0700 | [diff] [blame] | 665 | case ltc2977: |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 666 | case ltc2978: |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 667 | case ltc2980: |
| 668 | case ltm2987: |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 669 | info->read_word_data = ltc2978_read_word_data; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 670 | info->pages = LTC2978_NUM_PAGES; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 671 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 672 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 673 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 674 | for (i = 1; i < LTC2978_NUM_PAGES; i++) { |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 675 | info->func[i] = PMBUS_HAVE_VOUT |
| 676 | | PMBUS_HAVE_STATUS_VOUT; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 677 | } |
| 678 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 679 | case ltc3880: |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 680 | case ltc3887: |
Guenter Roeck | ccf2dc5 | 2015-08-17 20:08:09 -0700 | [diff] [blame] | 681 | case ltm4675: |
Guenter Roeck | f76992b | 2014-03-05 21:23:01 -0800 | [diff] [blame] | 682 | case ltm4676: |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 683 | case ltm4686: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 684 | data->features |= FEAT_CLEAR_PEAKS | FEAT_NEEDS_POLLING; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 685 | info->read_word_data = ltc3880_read_word_data; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 686 | info->pages = LTC3880_NUM_PAGES; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 687 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
| 688 | | PMBUS_HAVE_STATUS_INPUT |
| 689 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 690 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 691 | | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 692 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
| 693 | info->func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 694 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 695 | | PMBUS_HAVE_POUT |
| 696 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 697 | break; |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 698 | case ltc3882: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 699 | data->features |= FEAT_CLEAR_PEAKS | FEAT_NEEDS_POLLING; |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 700 | info->read_word_data = ltc3880_read_word_data; |
| 701 | info->pages = LTC3880_NUM_PAGES; |
| 702 | info->func[0] = PMBUS_HAVE_VIN |
| 703 | | PMBUS_HAVE_STATUS_INPUT |
| 704 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 705 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 706 | | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 707 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
| 708 | info->func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 709 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 710 | | PMBUS_HAVE_POUT |
| 711 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
| 712 | break; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 713 | case ltc3883: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 714 | data->features |= FEAT_CLEAR_PEAKS | FEAT_NEEDS_POLLING; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 715 | info->read_word_data = ltc3883_read_word_data; |
| 716 | info->pages = LTC3883_NUM_PAGES; |
| 717 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
| 718 | | PMBUS_HAVE_STATUS_INPUT |
| 719 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 720 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 721 | | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 722 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 723 | break; |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 724 | case ltc3886: |
Michael Jones | e04d1ce | 2015-08-17 17:45:32 -0700 | [diff] [blame] | 725 | data->features |= FEAT_CLEAR_PEAKS | FEAT_NEEDS_POLLING; |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 726 | info->read_word_data = ltc3883_read_word_data; |
| 727 | info->pages = LTC3880_NUM_PAGES; |
| 728 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
| 729 | | PMBUS_HAVE_STATUS_INPUT |
| 730 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 731 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 732 | | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 733 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
| 734 | info->func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 735 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 736 | | PMBUS_HAVE_POUT |
| 737 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
| 738 | break; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 739 | default: |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 740 | return -ENODEV; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 741 | } |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 742 | |
| 743 | #if IS_ENABLED(CONFIG_SENSORS_LTC2978_REGULATOR) |
| 744 | info->num_regulators = info->pages; |
| 745 | info->reg_desc = ltc2978_reg_desc; |
| 746 | if (info->num_regulators > ARRAY_SIZE(ltc2978_reg_desc)) { |
| 747 | dev_err(&client->dev, "num_regulators too large!"); |
| 748 | info->num_regulators = ARRAY_SIZE(ltc2978_reg_desc); |
| 749 | } |
| 750 | #endif |
| 751 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 752 | return pmbus_do_probe(client, id, info); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 755 | #ifdef CONFIG_OF |
| 756 | static const struct of_device_id ltc2978_of_match[] = { |
| 757 | { .compatible = "lltc,ltc2974" }, |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame] | 758 | { .compatible = "lltc,ltc2975" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 759 | { .compatible = "lltc,ltc2977" }, |
| 760 | { .compatible = "lltc,ltc2978" }, |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 761 | { .compatible = "lltc,ltc2980" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 762 | { .compatible = "lltc,ltc3880" }, |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 763 | { .compatible = "lltc,ltc3882" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 764 | { .compatible = "lltc,ltc3883" }, |
Guenter Roeck | 228b687 | 2015-08-17 07:21:43 -0700 | [diff] [blame] | 765 | { .compatible = "lltc,ltc3886" }, |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 766 | { .compatible = "lltc,ltc3887" }, |
Guenter Roeck | 52aae6a | 2015-08-17 06:38:01 -0700 | [diff] [blame] | 767 | { .compatible = "lltc,ltm2987" }, |
Guenter Roeck | ccf2dc5 | 2015-08-17 20:08:09 -0700 | [diff] [blame] | 768 | { .compatible = "lltc,ltm4675" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 769 | { .compatible = "lltc,ltm4676" }, |
Michael Hennerich | 4e15d05 | 2018-08-14 14:18:28 +0200 | [diff] [blame] | 770 | { .compatible = "lltc,ltm4686" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 771 | { } |
| 772 | }; |
| 773 | MODULE_DEVICE_TABLE(of, ltc2978_of_match); |
| 774 | #endif |
| 775 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 776 | static struct i2c_driver ltc2978_driver = { |
| 777 | .driver = { |
| 778 | .name = "ltc2978", |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 779 | .of_match_table = of_match_ptr(ltc2978_of_match), |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 780 | }, |
| 781 | .probe = ltc2978_probe, |
Guenter Roeck | dd285ad | 2012-02-22 08:56:44 -0800 | [diff] [blame] | 782 | .remove = pmbus_do_remove, |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 783 | .id_table = ltc2978_id, |
| 784 | }; |
| 785 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 786 | module_i2c_driver(ltc2978_driver); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 787 | |
| 788 | MODULE_AUTHOR("Guenter Roeck"); |
Colin Ian King | 89688e8 | 2018-11-26 16:28:32 +0000 | [diff] [blame] | 789 | MODULE_DESCRIPTION("PMBus driver for LTC2978 and compatible chips"); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 790 | MODULE_LICENSE("GPL"); |