Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (adm1275) Add support for ADM1293 and ADM1294

ADM1293 and ADM1294 are mostly compatible with other chips of the same
series, but have more configuration options. There are also some
differences in register details.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+158 -27
+23 -17
Documentation/hwmon/adm1275
··· 14 14 Prefix: 'adm1276' 15 15 Addresses scanned: - 16 16 Datasheet: www.analog.com/static/imported-files/data_sheets/ADM1276.pdf 17 + * Analog Devices ADM1293/ADM1294 18 + Prefix: 'adm1293', 'adm1294' 19 + Addresses scanned: - 20 + Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADM1293_1294.pdf 17 21 18 22 Author: Guenter Roeck <linux@roeck-us.net> 19 23 ··· 26 22 ----------- 27 23 28 24 This driver supports hardware montoring for Analog Devices ADM1075, ADM1275, 29 - and ADM1276 Hot-Swap Controller and Digital Power Monitor. 25 + ADM1276, ADM1293, and ADM1294 Hot-Swap Controller and Digital Power Monitors. 30 26 31 - ADM1075, ADM1275, and ADM1276 are hot-swap controllers that allow a circuit 32 - board to be removed from or inserted into a live backplane. They also feature 33 - current and voltage readback via an integrated 12-bit analog-to-digital 34 - converter (ADC), accessed using a PMBus interface. 27 + ADM1075, ADM1275, ADM1276, ADM1293, and ADM1294 are hot-swap controllers that 28 + allow a circuit board to be removed from or inserted into a live backplane. 29 + They also feature current and voltage readback via an integrated 12 30 + bit analog-to-digital converter (ADC), accessed using a PMBus interface. 35 31 36 32 The driver is a client driver to the core PMBus driver. Please see 37 33 Documentation/hwmon/pmbus for details on PMBus client drivers. ··· 62 58 The following attributes are supported. Limits are read-write, history reset 63 59 attributes are write-only, all other attributes are read-only. 64 60 65 - in1_label "vin1" or "vout1" depending on chip variant and 66 - configuration. On ADM1075, vout1 reports the voltage on 67 - the VAUX pin. 68 - in1_input Measured voltage. 69 - in1_min Minimum Voltage. 70 - in1_max Maximum voltage. 71 - in1_min_alarm Voltage low alarm. 72 - in1_max_alarm Voltage high alarm. 73 - in1_highest Historical maximum voltage. 74 - in1_reset_history Write any value to reset history. 61 + inX_label "vin1" or "vout1" depending on chip variant and 62 + configuration. On ADM1075, ADM1293, and ADM1294, 63 + vout1 reports the voltage on the VAUX pin. 64 + inX_input Measured voltage. 65 + inX_min Minimum Voltage. 66 + inX_max Maximum voltage. 67 + inX_min_alarm Voltage low alarm. 68 + inX_max_alarm Voltage high alarm. 69 + inX_highest Historical maximum voltage. 70 + inX_reset_history Write any value to reset history. 75 71 76 72 curr1_label "iout1" 77 73 curr1_input Measured current. ··· 90 86 91 87 power1_label "pin1" 92 88 power1_input Input power. 89 + power1_input_lowest Lowest observed input power. ADM1293 and ADM1294 only. 90 + power1_input_highest Highest observed input power. 93 91 power1_reset_history Write any value to reset history. 94 92 95 - Power attributes are supported on ADM1075 and ADM1276 96 - only. 93 + Power attributes are supported on ADM1075, ADM1276, 94 + ADM1293, and ADM1294.
+2 -2
drivers/hwmon/pmbus/Kconfig
··· 30 30 default n 31 31 help 32 32 If you say yes here you get hardware monitoring support for Analog 33 - Devices ADM1075, ADM1275, and ADM1276 Hot-Swap Controller and Digital 34 - Power Monitors. 33 + Devices ADM1075, ADM1275, ADM1276, ADM1293, and ADM1294 Hot-Swap 34 + Controller and Digital Power Monitors. 35 35 36 36 This driver can also be built as a module. If so, the module will 37 37 be called adm1275.
+133 -8
drivers/hwmon/pmbus/adm1275.c
··· 24 24 #include <linux/bitops.h> 25 25 #include "pmbus.h" 26 26 27 - enum chips { adm1075, adm1275, adm1276 }; 27 + enum chips { adm1075, adm1275, adm1276, adm1293, adm1294 }; 28 + 29 + #define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0) 30 + #define ADM1293_MFR_STATUS_VAUX_UV_WARN BIT(5) 31 + #define ADM1293_MFR_STATUS_VAUX_OV_WARN BIT(6) 28 32 29 33 #define ADM1275_PEAK_IOUT 0xd0 30 34 #define ADM1275_PEAK_VIN 0xd1 ··· 41 37 #define ADM1075_IRANGE_25 BIT(3) 42 38 #define ADM1075_IRANGE_MASK (BIT(3) | BIT(4)) 43 39 40 + #define ADM1293_IRANGE_25 0 41 + #define ADM1293_IRANGE_50 BIT(6) 42 + #define ADM1293_IRANGE_100 BIT(7) 43 + #define ADM1293_IRANGE_200 (BIT(6) | BIT(7)) 44 + #define ADM1293_IRANGE_MASK (BIT(6) | BIT(7)) 45 + 46 + #define ADM1293_VIN_SEL_012 BIT(2) 47 + #define ADM1293_VIN_SEL_074 BIT(3) 48 + #define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3)) 49 + #define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3)) 50 + 51 + #define ADM1293_VAUX_EN BIT(1) 52 + 44 53 #define ADM1275_IOUT_WARN2_LIMIT 0xd7 45 54 #define ADM1275_DEVICE_CONFIG 0xd8 46 55 47 56 #define ADM1275_IOUT_WARN2_SELECT BIT(4) 48 57 49 58 #define ADM1276_PEAK_PIN 0xda 50 - 51 - #define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0) 52 - 53 59 #define ADM1075_READ_VAUX 0xdd 54 60 #define ADM1075_VAUX_OV_WARN_LIMIT 0xde 55 61 #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf 62 + #define ADM1293_IOUT_MIN 0xe3 63 + #define ADM1293_PIN_MIN 0xe4 56 64 #define ADM1075_VAUX_STATUS 0xf6 57 65 58 66 #define ADM1075_VAUX_OV_WARN BIT(7) ··· 76 60 bool have_uc_fault; 77 61 bool have_vout; 78 62 bool have_vaux_status; 63 + bool have_mfr_vaux_status; 64 + bool have_iout_min; 65 + bool have_pin_min; 79 66 bool have_pin_max; 80 67 struct pmbus_driver_info info; 81 68 }; ··· 111 92 [2] = { 807, 20475, -1 }, /* current */ 112 93 [3] = { 6043, 0, -2 }, /* power, vrange set */ 113 94 [4] = { 2115, 0, -1 }, /* power, vrange not set */ 95 + }; 96 + 97 + static const struct coefficients adm1293_coefficients[] = { 98 + [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */ 99 + [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */ 100 + [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */ 101 + [3] = { 8000, -100, -2 }, /* current, irange25 */ 102 + [4] = { 4000, -100, -2 }, /* current, irange50 */ 103 + [5] = { 20000, -1000, -3 }, /* current, irange100 */ 104 + [6] = { 10000, -1000, -3 }, /* current, irange200 */ 105 + [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */ 106 + [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */ 107 + [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */ 108 + [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */ 109 + [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */ 110 + [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */ 111 + [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */ 112 + [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */ 113 + [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */ 114 + [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */ 115 + [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */ 116 + [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */ 114 117 }; 115 118 116 119 static int adm1275_read_word_data(struct i2c_client *client, int page, int reg) ··· 172 131 return -ENODATA; 173 132 ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX); 174 133 break; 134 + case PMBUS_VIRT_READ_IOUT_MIN: 135 + if (!data->have_iout_min) 136 + return -ENXIO; 137 + ret = pmbus_read_word_data(client, 0, ADM1293_IOUT_MIN); 138 + break; 175 139 case PMBUS_VIRT_READ_IOUT_MAX: 176 140 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT); 177 141 break; ··· 185 139 break; 186 140 case PMBUS_VIRT_READ_VIN_MAX: 187 141 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN); 142 + break; 143 + case PMBUS_VIRT_READ_PIN_MIN: 144 + if (!data->have_pin_min) 145 + return -ENXIO; 146 + ret = pmbus_read_word_data(client, 0, ADM1293_PIN_MIN); 188 147 break; 189 148 case PMBUS_VIRT_READ_PIN_MAX: 190 149 if (!data->have_pin_max) ··· 214 163 static int adm1275_write_word_data(struct i2c_client *client, int page, int reg, 215 164 u16 word) 216 165 { 166 + const struct pmbus_driver_info *info = pmbus_get_driver_info(client); 167 + const struct adm1275_data *data = to_adm1275_data(info); 217 168 int ret; 218 169 219 170 if (page) ··· 229 176 break; 230 177 case PMBUS_VIRT_RESET_IOUT_HISTORY: 231 178 ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_IOUT, 0); 179 + if (!ret && data->have_iout_min) 180 + ret = pmbus_write_word_data(client, 0, 181 + ADM1293_IOUT_MIN, 0); 232 182 break; 233 183 case PMBUS_VIRT_RESET_VOUT_HISTORY: 234 184 ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VOUT, 0); ··· 241 185 break; 242 186 case PMBUS_VIRT_RESET_PIN_HISTORY: 243 187 ret = pmbus_write_word_data(client, 0, ADM1276_PEAK_PIN, 0); 188 + if (!ret && data->have_pin_min) 189 + ret = pmbus_write_word_data(client, 0, 190 + ADM1293_PIN_MIN, 0); 244 191 break; 245 192 default: 246 193 ret = -ENODATA; ··· 290 231 ret |= PB_VOLTAGE_OV_WARNING; 291 232 if (mfr_status & ADM1075_VAUX_UV_WARN) 292 233 ret |= PB_VOLTAGE_UV_WARNING; 234 + } else if (data->have_mfr_vaux_status) { 235 + mfr_status = pmbus_read_byte_data(client, page, 236 + PMBUS_STATUS_MFR_SPECIFIC); 237 + if (mfr_status < 0) 238 + return mfr_status; 239 + if (mfr_status & ADM1293_MFR_STATUS_VAUX_OV_WARN) 240 + ret |= PB_VOLTAGE_OV_WARNING; 241 + if (mfr_status & ADM1293_MFR_STATUS_VAUX_UV_WARN) 242 + ret |= PB_VOLTAGE_UV_WARNING; 293 243 } 294 244 break; 295 245 default: ··· 312 244 { "adm1075", adm1075 }, 313 245 { "adm1275", adm1275 }, 314 246 { "adm1276", adm1276 }, 247 + { "adm1293", adm1293 }, 248 + { "adm1294", adm1294 }, 315 249 { } 316 250 }; 317 251 MODULE_DEVICE_TABLE(i2c, adm1275_id); ··· 328 258 struct adm1275_data *data; 329 259 const struct i2c_device_id *mid; 330 260 const struct coefficients *coefficients; 331 - int vindex = -1, cindex = -1, pindex = -1; 261 + int vindex = -1, voindex = -1, cindex = -1, pindex = -1; 332 262 333 263 if (!i2c_check_functionality(client->adapter, 334 264 I2C_FUNC_SMBUS_READ_BYTE_DATA ··· 460 390 info->func[0] |= 461 391 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; 462 392 break; 393 + case adm1293: 394 + case adm1294: 395 + data->have_iout_min = true; 396 + data->have_pin_min = true; 397 + data->have_pin_max = true; 398 + data->have_mfr_vaux_status = true; 399 + 400 + coefficients = adm1293_coefficients; 401 + 402 + voindex = 0; 403 + switch (config & ADM1293_VIN_SEL_MASK) { 404 + case ADM1293_VIN_SEL_012: /* 1.2V */ 405 + vindex = 0; 406 + break; 407 + case ADM1293_VIN_SEL_074: /* 7.4V */ 408 + vindex = 1; 409 + break; 410 + case ADM1293_VIN_SEL_210: /* 21V */ 411 + vindex = 2; 412 + break; 413 + default: /* disabled */ 414 + break; 415 + } 416 + 417 + switch (config & ADM1293_IRANGE_MASK) { 418 + case ADM1293_IRANGE_25: 419 + cindex = 3; 420 + break; 421 + case ADM1293_IRANGE_50: 422 + cindex = 4; 423 + break; 424 + case ADM1293_IRANGE_100: 425 + cindex = 5; 426 + break; 427 + case ADM1293_IRANGE_200: 428 + cindex = 6; 429 + break; 430 + } 431 + 432 + if (vindex >= 0) 433 + pindex = 7 + vindex * 4 + (cindex - 3); 434 + 435 + if (config & ADM1293_VAUX_EN) 436 + info->func[0] |= 437 + PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; 438 + 439 + info->func[0] |= PMBUS_HAVE_PIN | 440 + PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; 441 + 442 + break; 463 443 default: 464 444 dev_err(&client->dev, "Unsupported device\n"); 465 445 return -ENODEV; 466 446 } 447 + 448 + if (voindex < 0) 449 + voindex = vindex; 467 450 if (vindex >= 0) { 468 451 info->m[PSC_VOLTAGE_IN] = coefficients[vindex].m; 469 452 info->b[PSC_VOLTAGE_IN] = coefficients[vindex].b; 470 453 info->R[PSC_VOLTAGE_IN] = coefficients[vindex].R; 471 - info->m[PSC_VOLTAGE_OUT] = coefficients[vindex].m; 472 - info->b[PSC_VOLTAGE_OUT] = coefficients[vindex].b; 473 - info->R[PSC_VOLTAGE_OUT] = coefficients[vindex].R; 454 + } 455 + if (voindex >= 0) { 456 + info->m[PSC_VOLTAGE_OUT] = coefficients[voindex].m; 457 + info->b[PSC_VOLTAGE_OUT] = coefficients[voindex].b; 458 + info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R; 474 459 } 475 460 if (cindex >= 0) { 476 461 info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;