Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 1 | /* |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 2 | * Hardware monitoring driver for LTC2978 and compatible chips. |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2011 Ericsson AB. |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 5 | * Copyright (c) 2013, 2014, 2015 Guenter Roeck |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/i2c.h> |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 24 | #include <linux/regulator/driver.h> |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 25 | #include "pmbus.h" |
| 26 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 27 | enum chips { ltc2974, ltc2975, ltc2977, ltc2978, ltc3880, ltc3882, ltc3883, |
| 28 | ltc3887, ltm4676 }; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 29 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 30 | /* Common for all chips */ |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 31 | #define LTC2978_MFR_VOUT_PEAK 0xdd |
| 32 | #define LTC2978_MFR_VIN_PEAK 0xde |
| 33 | #define LTC2978_MFR_TEMPERATURE_PEAK 0xdf |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 34 | #define LTC2978_MFR_SPECIAL_ID 0xe7 /* Not on LTC3882 */ |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 35 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 36 | /* LTC2974, LTC2975, LCT2977, and LTC2978 */ |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 37 | #define LTC2978_MFR_VOUT_MIN 0xfb |
| 38 | #define LTC2978_MFR_VIN_MIN 0xfc |
| 39 | #define LTC2978_MFR_TEMPERATURE_MIN 0xfd |
| 40 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 41 | /* LTC2974, LTC2975 */ |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 42 | #define LTC2974_MFR_IOUT_PEAK 0xd7 |
| 43 | #define LTC2974_MFR_IOUT_MIN 0xd8 |
| 44 | |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 45 | /* LTC3880, LTC3882, LTC3883, LTC3887, and LTM4676 */ |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 46 | #define LTC3880_MFR_IOUT_PEAK 0xd7 |
| 47 | #define LTC3880_MFR_CLEAR_PEAKS 0xe3 |
| 48 | #define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4 |
| 49 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 50 | /* LTC3883 only */ |
| 51 | #define LTC3883_MFR_IIN_PEAK 0xe1 |
| 52 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 53 | /* LTC2975 only */ |
| 54 | #define LTC2975_MFR_IIN_PEAK 0xc4 |
| 55 | #define LTC2975_MFR_IIN_MIN 0xc5 |
| 56 | #define LTC2975_MFR_PIN_PEAK 0xc6 |
| 57 | #define LTC2975_MFR_PIN_MIN 0xc7 |
| 58 | |
Guenter Roeck | a2e15107 | 2014-03-05 09:33:01 -0800 | [diff] [blame] | 59 | #define LTC2974_ID_REV1 0x0212 |
| 60 | #define LTC2974_ID_REV2 0x0213 |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 61 | #define LTC2975_ID 0x0223 |
Guenter Roeck | c24c407e | 2013-09-23 10:56:48 -0700 | [diff] [blame] | 62 | #define LTC2977_ID 0x0130 |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 63 | #define LTC2978_ID_REV1 0x0121 |
| 64 | #define LTC2978_ID_REV2 0x0122 |
Guenter Roeck | 3f08d7f | 2013-09-23 11:23:37 -0700 | [diff] [blame] | 65 | #define LTC2978A_ID 0x0124 |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 66 | #define LTC3880_ID 0x4000 |
| 67 | #define LTC3880_ID_MASK 0xff00 |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 68 | #define LTC3883_ID 0x4300 |
| 69 | #define LTC3883_ID_MASK 0xff00 |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 70 | #define LTC3887_ID 0x4700 |
| 71 | #define LTC3887_ID_MASK 0xff00 |
Guenter Roeck | e8047a2 | 2015-08-07 01:04:56 -0700 | [diff] [blame] | 72 | #define LTM4676_ID 0x4400 |
| 73 | #define LTM4676_ID_2 0x4480 |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 74 | #define LTM4676A_ID 0x47e0 |
Guenter Roeck | f76992b | 2014-03-05 21:23:01 -0800 | [diff] [blame] | 75 | #define LTM4676_ID_MASK 0xfff0 |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 76 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 77 | #define LTC2974_NUM_PAGES 4 |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 78 | #define LTC2978_NUM_PAGES 8 |
| 79 | #define LTC3880_NUM_PAGES 2 |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 80 | #define LTC3883_NUM_PAGES 1 |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 81 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 82 | /* |
| 83 | * LTC2978 clears peak data whenever the CLEAR_FAULTS command is executed, which |
| 84 | * happens pretty much each time chip data is updated. Raw peak data therefore |
| 85 | * does not provide much value. To be able to provide useful peak data, keep an |
| 86 | * internal cache of measured peak data, which is only cleared if an explicit |
| 87 | * "clear peak" command is executed for the sensor in question. |
| 88 | */ |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 89 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 90 | struct ltc2978_data { |
| 91 | enum chips id; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 92 | u16 vin_min, vin_max; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 93 | u16 temp_min[LTC2974_NUM_PAGES], temp_max[LTC2974_NUM_PAGES]; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 94 | u16 vout_min[LTC2978_NUM_PAGES], vout_max[LTC2978_NUM_PAGES]; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 95 | u16 iout_min[LTC2974_NUM_PAGES], iout_max[LTC2974_NUM_PAGES]; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 96 | u16 iin_min, iin_max; |
| 97 | u16 pin_min, pin_max; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 98 | u16 temp2_max; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 99 | struct pmbus_driver_info info; |
| 100 | }; |
| 101 | |
| 102 | #define to_ltc2978_data(x) container_of(x, struct ltc2978_data, info) |
| 103 | |
| 104 | static inline int lin11_to_val(int data) |
| 105 | { |
| 106 | s16 e = ((s16)data) >> 11; |
| 107 | s32 m = (((s16)(data << 5)) >> 5); |
| 108 | |
| 109 | /* |
| 110 | * mantissa is 10 bit + sign, exponent adds up to 15 bit. |
| 111 | * Add 6 bit to exponent for maximum accuracy (10 + 15 + 6 = 31). |
| 112 | */ |
| 113 | e += 6; |
| 114 | return (e < 0 ? m >> -e : m << e); |
| 115 | } |
| 116 | |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 117 | static int ltc2978_read_word_data_common(struct i2c_client *client, int page, |
| 118 | int reg) |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 119 | { |
| 120 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 121 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 122 | int ret; |
| 123 | |
| 124 | switch (reg) { |
| 125 | case PMBUS_VIRT_READ_VIN_MAX: |
| 126 | ret = pmbus_read_word_data(client, page, LTC2978_MFR_VIN_PEAK); |
| 127 | if (ret >= 0) { |
| 128 | if (lin11_to_val(ret) > lin11_to_val(data->vin_max)) |
| 129 | data->vin_max = ret; |
| 130 | ret = data->vin_max; |
| 131 | } |
| 132 | break; |
| 133 | case PMBUS_VIRT_READ_VOUT_MAX: |
| 134 | ret = pmbus_read_word_data(client, page, LTC2978_MFR_VOUT_PEAK); |
| 135 | if (ret >= 0) { |
| 136 | /* |
| 137 | * VOUT is 16 bit unsigned with fixed exponent, |
| 138 | * so we can compare it directly |
| 139 | */ |
| 140 | if (ret > data->vout_max[page]) |
| 141 | data->vout_max[page] = ret; |
| 142 | ret = data->vout_max[page]; |
| 143 | } |
| 144 | break; |
| 145 | case PMBUS_VIRT_READ_TEMP_MAX: |
| 146 | ret = pmbus_read_word_data(client, page, |
| 147 | LTC2978_MFR_TEMPERATURE_PEAK); |
| 148 | if (ret >= 0) { |
Guenter Roeck | 8c958c7 | 2013-02-21 10:27:54 -0800 | [diff] [blame] | 149 | if (lin11_to_val(ret) |
| 150 | > lin11_to_val(data->temp_max[page])) |
| 151 | data->temp_max[page] = ret; |
| 152 | ret = data->temp_max[page]; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 153 | } |
| 154 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 155 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 156 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
| 157 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
| 158 | ret = 0; |
| 159 | break; |
| 160 | default: |
| 161 | ret = -ENODATA; |
| 162 | break; |
| 163 | } |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | static int ltc2978_read_word_data(struct i2c_client *client, int page, int reg) |
| 168 | { |
| 169 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 170 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 171 | int ret; |
| 172 | |
| 173 | switch (reg) { |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 174 | case PMBUS_VIRT_READ_VIN_MIN: |
| 175 | ret = pmbus_read_word_data(client, page, LTC2978_MFR_VIN_MIN); |
| 176 | if (ret >= 0) { |
| 177 | if (lin11_to_val(ret) < lin11_to_val(data->vin_min)) |
| 178 | data->vin_min = ret; |
| 179 | ret = data->vin_min; |
| 180 | } |
| 181 | break; |
| 182 | case PMBUS_VIRT_READ_VOUT_MIN: |
| 183 | ret = pmbus_read_word_data(client, page, LTC2978_MFR_VOUT_MIN); |
| 184 | if (ret >= 0) { |
| 185 | /* |
| 186 | * VOUT_MIN is known to not be supported on some lots |
| 187 | * of LTC2978 revision 1, and will return the maximum |
| 188 | * possible voltage if read. If VOUT_MAX is valid and |
| 189 | * lower than the reading of VOUT_MIN, use it instead. |
| 190 | */ |
| 191 | if (data->vout_max[page] && ret > data->vout_max[page]) |
| 192 | ret = data->vout_max[page]; |
| 193 | if (ret < data->vout_min[page]) |
| 194 | data->vout_min[page] = ret; |
| 195 | ret = data->vout_min[page]; |
| 196 | } |
| 197 | break; |
| 198 | case PMBUS_VIRT_READ_TEMP_MIN: |
| 199 | ret = pmbus_read_word_data(client, page, |
| 200 | LTC2978_MFR_TEMPERATURE_MIN); |
| 201 | if (ret >= 0) { |
| 202 | if (lin11_to_val(ret) |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 203 | < lin11_to_val(data->temp_min[page])) |
| 204 | data->temp_min[page] = ret; |
| 205 | ret = data->temp_min[page]; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 206 | } |
| 207 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 208 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 209 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 210 | case PMBUS_VIRT_READ_TEMP2_MAX: |
| 211 | case PMBUS_VIRT_RESET_TEMP2_HISTORY: |
| 212 | ret = -ENXIO; |
| 213 | break; |
| 214 | default: |
| 215 | ret = ltc2978_read_word_data_common(client, page, reg); |
| 216 | break; |
| 217 | } |
| 218 | return ret; |
| 219 | } |
| 220 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 221 | static int ltc2974_read_word_data(struct i2c_client *client, int page, int reg) |
| 222 | { |
| 223 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 224 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 225 | int ret; |
| 226 | |
| 227 | switch (reg) { |
| 228 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 229 | ret = pmbus_read_word_data(client, page, LTC2974_MFR_IOUT_PEAK); |
| 230 | if (ret >= 0) { |
| 231 | if (lin11_to_val(ret) |
| 232 | > lin11_to_val(data->iout_max[page])) |
| 233 | data->iout_max[page] = ret; |
| 234 | ret = data->iout_max[page]; |
| 235 | } |
| 236 | break; |
| 237 | case PMBUS_VIRT_READ_IOUT_MIN: |
| 238 | ret = pmbus_read_word_data(client, page, LTC2974_MFR_IOUT_MIN); |
| 239 | if (ret >= 0) { |
| 240 | if (lin11_to_val(ret) |
| 241 | < lin11_to_val(data->iout_min[page])) |
| 242 | data->iout_min[page] = ret; |
| 243 | ret = data->iout_min[page]; |
| 244 | } |
| 245 | break; |
| 246 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 247 | ret = 0; |
| 248 | break; |
| 249 | default: |
| 250 | ret = ltc2978_read_word_data(client, page, reg); |
| 251 | break; |
| 252 | } |
| 253 | return ret; |
| 254 | } |
| 255 | |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 256 | static int ltc2975_read_word_data(struct i2c_client *client, int page, int reg) |
| 257 | { |
| 258 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 259 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 260 | int ret; |
| 261 | |
| 262 | switch (reg) { |
| 263 | case PMBUS_VIRT_READ_IIN_MAX: |
| 264 | ret = pmbus_read_word_data(client, page, LTC2975_MFR_IIN_PEAK); |
| 265 | if (ret >= 0) { |
| 266 | if (lin11_to_val(ret) |
| 267 | > lin11_to_val(data->iin_max)) |
| 268 | data->iin_max = ret; |
| 269 | ret = data->iin_max; |
| 270 | } |
| 271 | break; |
| 272 | case PMBUS_VIRT_READ_IIN_MIN: |
| 273 | ret = pmbus_read_word_data(client, page, LTC2975_MFR_IIN_MIN); |
| 274 | if (ret >= 0) { |
| 275 | if (lin11_to_val(ret) |
| 276 | < lin11_to_val(data->iin_min)) |
| 277 | data->iin_min = ret; |
| 278 | ret = data->iin_min; |
| 279 | } |
| 280 | break; |
| 281 | case PMBUS_VIRT_READ_PIN_MAX: |
| 282 | ret = pmbus_read_word_data(client, page, LTC2975_MFR_PIN_PEAK); |
| 283 | if (ret >= 0) { |
| 284 | if (lin11_to_val(ret) |
| 285 | > lin11_to_val(data->pin_max)) |
| 286 | data->pin_max = ret; |
| 287 | ret = data->pin_max; |
| 288 | } |
| 289 | break; |
| 290 | case PMBUS_VIRT_READ_PIN_MIN: |
| 291 | ret = pmbus_read_word_data(client, page, LTC2975_MFR_PIN_MIN); |
| 292 | if (ret >= 0) { |
| 293 | if (lin11_to_val(ret) |
| 294 | < lin11_to_val(data->pin_min)) |
| 295 | data->pin_min = ret; |
| 296 | ret = data->pin_min; |
| 297 | } |
| 298 | break; |
| 299 | case PMBUS_VIRT_RESET_IIN_HISTORY: |
| 300 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
| 301 | ret = 0; |
| 302 | break; |
| 303 | default: |
| 304 | ret = ltc2978_read_word_data(client, page, reg); |
| 305 | break; |
| 306 | } |
| 307 | return ret; |
| 308 | } |
| 309 | |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 310 | static int ltc3880_read_word_data(struct i2c_client *client, int page, int reg) |
| 311 | { |
| 312 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 313 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 314 | int ret; |
| 315 | |
| 316 | switch (reg) { |
| 317 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 318 | ret = pmbus_read_word_data(client, page, LTC3880_MFR_IOUT_PEAK); |
| 319 | if (ret >= 0) { |
| 320 | if (lin11_to_val(ret) |
| 321 | > lin11_to_val(data->iout_max[page])) |
| 322 | data->iout_max[page] = ret; |
| 323 | ret = data->iout_max[page]; |
| 324 | } |
| 325 | break; |
| 326 | case PMBUS_VIRT_READ_TEMP2_MAX: |
| 327 | ret = pmbus_read_word_data(client, page, |
| 328 | LTC3880_MFR_TEMPERATURE2_PEAK); |
| 329 | if (ret >= 0) { |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 330 | if (lin11_to_val(ret) > lin11_to_val(data->temp2_max)) |
| 331 | data->temp2_max = ret; |
| 332 | ret = data->temp2_max; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 333 | } |
| 334 | break; |
| 335 | case PMBUS_VIRT_READ_VIN_MIN: |
| 336 | case PMBUS_VIRT_READ_VOUT_MIN: |
| 337 | case PMBUS_VIRT_READ_TEMP_MIN: |
| 338 | ret = -ENXIO; |
| 339 | break; |
| 340 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 341 | case PMBUS_VIRT_RESET_TEMP2_HISTORY: |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 342 | ret = 0; |
| 343 | break; |
| 344 | default: |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 345 | ret = ltc2978_read_word_data_common(client, page, reg); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 346 | break; |
| 347 | } |
| 348 | return ret; |
| 349 | } |
| 350 | |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 351 | static int ltc3883_read_word_data(struct i2c_client *client, int page, int reg) |
| 352 | { |
| 353 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 354 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 355 | int ret; |
| 356 | |
| 357 | switch (reg) { |
| 358 | case PMBUS_VIRT_READ_IIN_MAX: |
| 359 | ret = pmbus_read_word_data(client, page, LTC3883_MFR_IIN_PEAK); |
| 360 | if (ret >= 0) { |
| 361 | if (lin11_to_val(ret) |
| 362 | > lin11_to_val(data->iin_max)) |
| 363 | data->iin_max = ret; |
| 364 | ret = data->iin_max; |
| 365 | } |
| 366 | break; |
| 367 | case PMBUS_VIRT_RESET_IIN_HISTORY: |
| 368 | ret = 0; |
| 369 | break; |
| 370 | default: |
| 371 | ret = ltc3880_read_word_data(client, page, reg); |
| 372 | break; |
| 373 | } |
| 374 | return ret; |
| 375 | } |
| 376 | |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 377 | static int ltc2978_clear_peaks(struct i2c_client *client, int page, |
| 378 | enum chips id) |
| 379 | { |
| 380 | int ret; |
| 381 | |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 382 | if (id == ltc3880 || id == ltc3882 || id == ltc3883 || id == ltc3887 || |
| 383 | id == ltm4676) |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 384 | ret = pmbus_write_byte(client, 0, LTC3880_MFR_CLEAR_PEAKS); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 385 | else |
| 386 | ret = pmbus_write_byte(client, page, PMBUS_CLEAR_FAULTS); |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 387 | |
| 388 | return ret; |
| 389 | } |
| 390 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 391 | static int ltc2978_write_word_data(struct i2c_client *client, int page, |
| 392 | int reg, u16 word) |
| 393 | { |
| 394 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 395 | struct ltc2978_data *data = to_ltc2978_data(info); |
| 396 | int ret; |
| 397 | |
| 398 | switch (reg) { |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 399 | case PMBUS_VIRT_RESET_IIN_HISTORY: |
| 400 | data->iin_max = 0x7c00; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 401 | data->iin_min = 0x7bff; |
| 402 | ret = ltc2978_clear_peaks(client, 0, data->id); |
| 403 | break; |
| 404 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
| 405 | data->pin_max = 0x7c00; |
| 406 | data->pin_min = 0x7bff; |
| 407 | ret = ltc2978_clear_peaks(client, 0, data->id); |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 408 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 409 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 410 | data->iout_max[page] = 0x7c00; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 411 | data->iout_min[page] = 0xfbff; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 412 | ret = ltc2978_clear_peaks(client, page, data->id); |
| 413 | break; |
| 414 | case PMBUS_VIRT_RESET_TEMP2_HISTORY: |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 415 | data->temp2_max = 0x7c00; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 416 | ret = ltc2978_clear_peaks(client, page, data->id); |
| 417 | break; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 418 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 419 | data->vout_min[page] = 0xffff; |
| 420 | data->vout_max[page] = 0; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 421 | ret = ltc2978_clear_peaks(client, page, data->id); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 422 | break; |
| 423 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
| 424 | data->vin_min = 0x7bff; |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 425 | data->vin_max = 0x7c00; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 426 | ret = ltc2978_clear_peaks(client, page, data->id); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 427 | break; |
| 428 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 429 | data->temp_min[page] = 0x7bff; |
Guenter Roeck | 8c958c7 | 2013-02-21 10:27:54 -0800 | [diff] [blame] | 430 | data->temp_max[page] = 0x7c00; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 431 | ret = ltc2978_clear_peaks(client, page, data->id); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 432 | break; |
| 433 | default: |
| 434 | ret = -ENODATA; |
| 435 | break; |
| 436 | } |
| 437 | return ret; |
| 438 | } |
| 439 | |
| 440 | static const struct i2c_device_id ltc2978_id[] = { |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 441 | {"ltc2974", ltc2974}, |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 442 | {"ltc2975", ltc2975}, |
Guenter Roeck | c24c407e | 2013-09-23 10:56:48 -0700 | [diff] [blame] | 443 | {"ltc2977", ltc2977}, |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 444 | {"ltc2978", ltc2978}, |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 445 | {"ltc3880", ltc3880}, |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 446 | {"ltc3882", ltc3882}, |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 447 | {"ltc3883", ltc3883}, |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 448 | {"ltc3887", ltc3887}, |
Guenter Roeck | f76992b | 2014-03-05 21:23:01 -0800 | [diff] [blame] | 449 | {"ltm4676", ltm4676}, |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 450 | {} |
| 451 | }; |
| 452 | MODULE_DEVICE_TABLE(i2c, ltc2978_id); |
| 453 | |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 454 | #if IS_ENABLED(CONFIG_SENSORS_LTC2978_REGULATOR) |
| 455 | static const struct regulator_desc ltc2978_reg_desc[] = { |
| 456 | PMBUS_REGULATOR("vout", 0), |
| 457 | PMBUS_REGULATOR("vout", 1), |
| 458 | PMBUS_REGULATOR("vout", 2), |
| 459 | PMBUS_REGULATOR("vout", 3), |
| 460 | PMBUS_REGULATOR("vout", 4), |
| 461 | PMBUS_REGULATOR("vout", 5), |
| 462 | PMBUS_REGULATOR("vout", 6), |
| 463 | PMBUS_REGULATOR("vout", 7), |
| 464 | }; |
| 465 | #endif /* CONFIG_SENSORS_LTC2978_REGULATOR */ |
| 466 | |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 467 | static int ltc2978_get_id(struct i2c_client *client) |
| 468 | { |
| 469 | int chip_id; |
| 470 | |
| 471 | chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID); |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 472 | if (chip_id < 0) { |
| 473 | const struct i2c_device_id *id; |
| 474 | u8 buf[I2C_SMBUS_BLOCK_MAX]; |
| 475 | int ret; |
| 476 | |
| 477 | if (!i2c_check_functionality(client->adapter, |
| 478 | I2C_FUNC_SMBUS_READ_BLOCK_DATA)) |
| 479 | return -ENODEV; |
| 480 | |
| 481 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf); |
| 482 | if (ret < 0) |
| 483 | return ret; |
| 484 | if (ret < 3 || strncmp(buf, "LTC", 3)) |
| 485 | return -ENODEV; |
| 486 | |
| 487 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); |
| 488 | if (ret < 0) |
| 489 | return ret; |
| 490 | for (id = <c2978_id[0]; strlen(id->name); id++) { |
| 491 | if (!strncasecmp(id->name, buf, strlen(id->name))) |
| 492 | return (int)id->driver_data; |
| 493 | } |
| 494 | return -ENODEV; |
| 495 | } |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 496 | |
| 497 | if (chip_id == LTC2974_ID_REV1 || chip_id == LTC2974_ID_REV2) |
| 498 | return ltc2974; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 499 | else if (chip_id == LTC2975_ID) |
| 500 | return ltc2975; |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 501 | else if (chip_id == LTC2977_ID) |
| 502 | return ltc2977; |
| 503 | else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2 || |
| 504 | chip_id == LTC2978A_ID) |
| 505 | return ltc2978; |
| 506 | else if ((chip_id & LTC3880_ID_MASK) == LTC3880_ID) |
| 507 | return ltc3880; |
| 508 | else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID) |
| 509 | return ltc3883; |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 510 | else if ((chip_id & LTC3887_ID_MASK) == LTC3887_ID) |
| 511 | return ltc3887; |
Guenter Roeck | e8047a2 | 2015-08-07 01:04:56 -0700 | [diff] [blame] | 512 | else if ((chip_id & LTM4676_ID_MASK) == LTM4676_ID || |
| 513 | (chip_id & LTM4676_ID_MASK) == LTM4676_ID_2 || |
| 514 | (chip_id & LTM4676_ID_MASK) == LTM4676A_ID) |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 515 | return ltm4676; |
| 516 | |
| 517 | dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); |
| 518 | return -ENODEV; |
| 519 | } |
| 520 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 521 | static int ltc2978_probe(struct i2c_client *client, |
| 522 | const struct i2c_device_id *id) |
| 523 | { |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 524 | int i, chip_id; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 525 | struct ltc2978_data *data; |
| 526 | struct pmbus_driver_info *info; |
| 527 | |
| 528 | if (!i2c_check_functionality(client->adapter, |
| 529 | I2C_FUNC_SMBUS_READ_WORD_DATA)) |
| 530 | return -ENODEV; |
| 531 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 532 | data = devm_kzalloc(&client->dev, sizeof(struct ltc2978_data), |
| 533 | GFP_KERNEL); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 534 | if (!data) |
| 535 | return -ENOMEM; |
| 536 | |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 537 | chip_id = ltc2978_get_id(client); |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 538 | if (chip_id < 0) |
| 539 | return chip_id; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 540 | |
Guenter Roeck | 836954d | 2015-06-08 10:14:00 -0700 | [diff] [blame] | 541 | data->id = chip_id; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 542 | if (data->id != id->driver_data) |
| 543 | dev_warn(&client->dev, |
| 544 | "Device mismatch: Configured %s, detected %s\n", |
| 545 | id->name, |
| 546 | ltc2978_id[data->id].name); |
| 547 | |
| 548 | info = &data->info; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 549 | info->write_word_data = ltc2978_write_word_data; |
| 550 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 551 | data->vin_min = 0x7bff; |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 552 | data->vin_max = 0x7c00; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 553 | for (i = 0; i < ARRAY_SIZE(data->vout_min); i++) |
| 554 | data->vout_min[i] = 0xffff; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 555 | for (i = 0; i < ARRAY_SIZE(data->iout_min); i++) |
| 556 | data->iout_min[i] = 0xfbff; |
| 557 | for (i = 0; i < ARRAY_SIZE(data->iout_max); i++) |
| 558 | data->iout_max[i] = 0x7c00; |
| 559 | for (i = 0; i < ARRAY_SIZE(data->temp_min); i++) |
| 560 | data->temp_min[i] = 0x7bff; |
Guenter Roeck | 8c958c7 | 2013-02-21 10:27:54 -0800 | [diff] [blame] | 561 | for (i = 0; i < ARRAY_SIZE(data->temp_max); i++) |
| 562 | data->temp_max[i] = 0x7c00; |
Guenter Roeck | dbd712c | 2013-02-21 09:33:25 -0800 | [diff] [blame] | 563 | data->temp2_max = 0x7c00; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 564 | |
Guenter Roeck | f366fcc | 2013-02-21 10:49:40 -0800 | [diff] [blame] | 565 | switch (data->id) { |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 566 | case ltc2974: |
| 567 | info->read_word_data = ltc2974_read_word_data; |
| 568 | info->pages = LTC2974_NUM_PAGES; |
| 569 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 570 | | PMBUS_HAVE_TEMP2; |
| 571 | for (i = 0; i < info->pages; i++) { |
| 572 | info->func[i] |= PMBUS_HAVE_VOUT |
| 573 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_POUT |
| 574 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
| 575 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
| 576 | } |
| 577 | break; |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 578 | case ltc2975: |
| 579 | info->read_word_data = ltc2975_read_word_data; |
| 580 | info->pages = LTC2974_NUM_PAGES; |
| 581 | info->func[0] = PMBUS_HAVE_IIN | PMBUS_HAVE_PIN |
| 582 | | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 583 | | PMBUS_HAVE_TEMP2; |
| 584 | for (i = 0; i < info->pages; i++) { |
| 585 | info->func[i] |= PMBUS_HAVE_VOUT |
| 586 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_POUT |
| 587 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
| 588 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
| 589 | } |
| 590 | break; |
Guenter Roeck | c24c407e | 2013-09-23 10:56:48 -0700 | [diff] [blame] | 591 | case ltc2977: |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 592 | case ltc2978: |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 593 | info->read_word_data = ltc2978_read_word_data; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 594 | info->pages = LTC2978_NUM_PAGES; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 595 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 596 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 597 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 598 | for (i = 1; i < LTC2978_NUM_PAGES; i++) { |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 599 | info->func[i] = PMBUS_HAVE_VOUT |
| 600 | | PMBUS_HAVE_STATUS_VOUT; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 601 | } |
| 602 | break; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 603 | case ltc3880: |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 604 | case ltc3887: |
Guenter Roeck | f76992b | 2014-03-05 21:23:01 -0800 | [diff] [blame] | 605 | case ltm4676: |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 606 | info->read_word_data = ltc3880_read_word_data; |
Guenter Roeck | 3d0d283 | 2013-02-28 08:14:45 -0800 | [diff] [blame] | 607 | info->pages = LTC3880_NUM_PAGES; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 608 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
| 609 | | PMBUS_HAVE_STATUS_INPUT |
| 610 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 611 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 612 | | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 613 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
| 614 | info->func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 615 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 616 | | PMBUS_HAVE_POUT |
| 617 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 618 | break; |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 619 | case ltc3882: |
| 620 | info->read_word_data = ltc3880_read_word_data; |
| 621 | info->pages = LTC3880_NUM_PAGES; |
| 622 | info->func[0] = PMBUS_HAVE_VIN |
| 623 | | PMBUS_HAVE_STATUS_INPUT |
| 624 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 625 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 626 | | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 627 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
| 628 | info->func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 629 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 630 | | PMBUS_HAVE_POUT |
| 631 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
| 632 | break; |
Guenter Roeck | fd9175d | 2013-01-27 09:24:28 -0800 | [diff] [blame] | 633 | case ltc3883: |
| 634 | info->read_word_data = ltc3883_read_word_data; |
| 635 | info->pages = LTC3883_NUM_PAGES; |
| 636 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
| 637 | | PMBUS_HAVE_STATUS_INPUT |
| 638 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 639 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 640 | | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP |
| 641 | | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; |
Guenter Roeck | ddfb41c | 2011-09-11 20:31:09 -0700 | [diff] [blame] | 642 | break; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 643 | default: |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 644 | return -ENODEV; |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 645 | } |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 646 | |
| 647 | #if IS_ENABLED(CONFIG_SENSORS_LTC2978_REGULATOR) |
| 648 | info->num_regulators = info->pages; |
| 649 | info->reg_desc = ltc2978_reg_desc; |
| 650 | if (info->num_regulators > ARRAY_SIZE(ltc2978_reg_desc)) { |
| 651 | dev_err(&client->dev, "num_regulators too large!"); |
| 652 | info->num_regulators = ARRAY_SIZE(ltc2978_reg_desc); |
| 653 | } |
| 654 | #endif |
| 655 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 656 | return pmbus_do_probe(client, id, info); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 659 | #ifdef CONFIG_OF |
| 660 | static const struct of_device_id ltc2978_of_match[] = { |
| 661 | { .compatible = "lltc,ltc2974" }, |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 662 | { .compatible = "lltc,ltc2975" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 663 | { .compatible = "lltc,ltc2977" }, |
| 664 | { .compatible = "lltc,ltc2978" }, |
| 665 | { .compatible = "lltc,ltc3880" }, |
Guenter Roeck | bf89386 | 2015-06-08 10:29:45 -0700 | [diff] [blame] | 666 | { .compatible = "lltc,ltc3882" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 667 | { .compatible = "lltc,ltc3883" }, |
Guenter Roeck | 1539856 | 2015-08-07 09:06:37 -0700 | [diff] [blame] | 668 | { .compatible = "lltc,ltc3887" }, |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 669 | { .compatible = "lltc,ltm4676" }, |
| 670 | { } |
| 671 | }; |
| 672 | MODULE_DEVICE_TABLE(of, ltc2978_of_match); |
| 673 | #endif |
| 674 | |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 675 | static struct i2c_driver ltc2978_driver = { |
| 676 | .driver = { |
| 677 | .name = "ltc2978", |
Alan Tull | 77aa358 | 2014-10-15 13:55:10 -0500 | [diff] [blame] | 678 | .of_match_table = of_match_ptr(ltc2978_of_match), |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 679 | }, |
| 680 | .probe = ltc2978_probe, |
Guenter Roeck | dd285ad | 2012-02-22 08:56:44 -0800 | [diff] [blame] | 681 | .remove = pmbus_do_remove, |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 682 | .id_table = ltc2978_id, |
| 683 | }; |
| 684 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 685 | module_i2c_driver(ltc2978_driver); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 686 | |
| 687 | MODULE_AUTHOR("Guenter Roeck"); |
Guenter Roeck | 649ca82 | 2015-06-08 09:56:20 -0700 | [diff] [blame^] | 688 | MODULE_DESCRIPTION("PMBus driver for LTC2978 and comppatible chips"); |
Guenter Roeck | c3ff9a6 | 2011-09-02 09:58:37 -0700 | [diff] [blame] | 689 | MODULE_LICENSE("GPL"); |