Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller |
| 3 | * and Digital Power Monitor |
| 4 | * |
| 5 | * Copyright (c) 2011 Ericsson AB. |
Guenter Roeck | 4ff0ce2 | 2018-03-10 18:59:04 -0800 | [diff] [blame] | 6 | * Copyright (c) 2018 Guenter Roeck |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/i2c.h> |
Guenter Roeck | 99b4160 | 2015-07-04 09:19:48 -0700 | [diff] [blame] | 25 | #include <linux/bitops.h> |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 26 | #include "pmbus.h" |
| 27 | |
Guenter Roeck | 4ff0ce2 | 2018-03-10 18:59:04 -0800 | [diff] [blame] | 28 | enum chips { adm1075, adm1272, adm1275, adm1276, adm1278, adm1293, adm1294 }; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 29 | |
| 30 | #define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0) |
| 31 | #define ADM1293_MFR_STATUS_VAUX_UV_WARN BIT(5) |
| 32 | #define ADM1293_MFR_STATUS_VAUX_OV_WARN BIT(6) |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 33 | |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 34 | #define ADM1275_PEAK_IOUT 0xd0 |
| 35 | #define ADM1275_PEAK_VIN 0xd1 |
| 36 | #define ADM1275_PEAK_VOUT 0xd2 |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 37 | #define ADM1275_PMON_CONFIG 0xd4 |
| 38 | |
Guenter Roeck | 99b4160 | 2015-07-04 09:19:48 -0700 | [diff] [blame] | 39 | #define ADM1275_VIN_VOUT_SELECT BIT(6) |
| 40 | #define ADM1275_VRANGE BIT(5) |
| 41 | #define ADM1075_IRANGE_50 BIT(4) |
| 42 | #define ADM1075_IRANGE_25 BIT(3) |
| 43 | #define ADM1075_IRANGE_MASK (BIT(3) | BIT(4)) |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 44 | |
Guenter Roeck | 4ff0ce2 | 2018-03-10 18:59:04 -0800 | [diff] [blame] | 45 | #define ADM1272_IRANGE BIT(0) |
| 46 | |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 47 | #define ADM1278_TEMP1_EN BIT(3) |
| 48 | #define ADM1278_VIN_EN BIT(2) |
| 49 | #define ADM1278_VOUT_EN BIT(1) |
| 50 | |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 51 | #define ADM1293_IRANGE_25 0 |
| 52 | #define ADM1293_IRANGE_50 BIT(6) |
| 53 | #define ADM1293_IRANGE_100 BIT(7) |
| 54 | #define ADM1293_IRANGE_200 (BIT(6) | BIT(7)) |
| 55 | #define ADM1293_IRANGE_MASK (BIT(6) | BIT(7)) |
| 56 | |
| 57 | #define ADM1293_VIN_SEL_012 BIT(2) |
| 58 | #define ADM1293_VIN_SEL_074 BIT(3) |
| 59 | #define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3)) |
| 60 | #define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3)) |
| 61 | |
| 62 | #define ADM1293_VAUX_EN BIT(1) |
| 63 | |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 64 | #define ADM1278_PEAK_TEMP 0xd7 |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 65 | #define ADM1275_IOUT_WARN2_LIMIT 0xd7 |
| 66 | #define ADM1275_DEVICE_CONFIG 0xd8 |
| 67 | |
Guenter Roeck | 99b4160 | 2015-07-04 09:19:48 -0700 | [diff] [blame] | 68 | #define ADM1275_IOUT_WARN2_SELECT BIT(4) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 69 | |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 70 | #define ADM1276_PEAK_PIN 0xda |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 71 | #define ADM1075_READ_VAUX 0xdd |
| 72 | #define ADM1075_VAUX_OV_WARN_LIMIT 0xde |
| 73 | #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 74 | #define ADM1293_IOUT_MIN 0xe3 |
| 75 | #define ADM1293_PIN_MIN 0xe4 |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 76 | #define ADM1075_VAUX_STATUS 0xf6 |
| 77 | |
Guenter Roeck | 99b4160 | 2015-07-04 09:19:48 -0700 | [diff] [blame] | 78 | #define ADM1075_VAUX_OV_WARN BIT(7) |
| 79 | #define ADM1075_VAUX_UV_WARN BIT(6) |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 80 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 81 | struct adm1275_data { |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 82 | int id; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 83 | bool have_oc_fault; |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 84 | bool have_uc_fault; |
| 85 | bool have_vout; |
| 86 | bool have_vaux_status; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 87 | bool have_mfr_vaux_status; |
| 88 | bool have_iout_min; |
| 89 | bool have_pin_min; |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 90 | bool have_pin_max; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 91 | bool have_temp_max; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 92 | struct pmbus_driver_info info; |
| 93 | }; |
| 94 | |
| 95 | #define to_adm1275_data(x) container_of(x, struct adm1275_data, info) |
| 96 | |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 97 | struct coefficients { |
| 98 | s16 m; |
| 99 | s16 b; |
| 100 | s16 R; |
| 101 | }; |
| 102 | |
| 103 | static const struct coefficients adm1075_coefficients[] = { |
| 104 | [0] = { 27169, 0, -1 }, /* voltage */ |
| 105 | [1] = { 806, 20475, -1 }, /* current, irange25 */ |
| 106 | [2] = { 404, 20475, -1 }, /* current, irange50 */ |
Shikhar Dogra | 6faecba | 2017-03-27 16:16:44 -0700 | [diff] [blame] | 107 | [3] = { 8549, 0, -1 }, /* power, irange25 */ |
| 108 | [4] = { 4279, 0, -1 }, /* power, irange50 */ |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Guenter Roeck | 4ff0ce2 | 2018-03-10 18:59:04 -0800 | [diff] [blame] | 111 | static const struct coefficients adm1272_coefficients[] = { |
| 112 | [0] = { 6770, 0, -2 }, /* voltage, vrange 60V */ |
| 113 | [1] = { 4062, 0, -2 }, /* voltage, vrange 100V */ |
| 114 | [2] = { 1326, 20480, -1 }, /* current, vsense range 15mV */ |
| 115 | [3] = { 663, 20480, -1 }, /* current, vsense range 30mV */ |
| 116 | [4] = { 3512, 0, -2 }, /* power, vrange 60V, irange 15mV */ |
| 117 | [5] = { 21071, 0, -3 }, /* power, vrange 100V, irange 15mV */ |
| 118 | [6] = { 17561, 0, -3 }, /* power, vrange 60V, irange 30mV */ |
| 119 | [7] = { 10535, 0, -3 }, /* power, vrange 100V, irange 30mV */ |
| 120 | [8] = { 42, 31871, -1 }, /* temperature */ |
| 121 | |
| 122 | }; |
| 123 | |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 124 | static const struct coefficients adm1275_coefficients[] = { |
| 125 | [0] = { 19199, 0, -2 }, /* voltage, vrange set */ |
| 126 | [1] = { 6720, 0, -1 }, /* voltage, vrange not set */ |
| 127 | [2] = { 807, 20475, -1 }, /* current */ |
| 128 | }; |
| 129 | |
| 130 | static const struct coefficients adm1276_coefficients[] = { |
| 131 | [0] = { 19199, 0, -2 }, /* voltage, vrange set */ |
| 132 | [1] = { 6720, 0, -1 }, /* voltage, vrange not set */ |
| 133 | [2] = { 807, 20475, -1 }, /* current */ |
| 134 | [3] = { 6043, 0, -2 }, /* power, vrange set */ |
| 135 | [4] = { 2115, 0, -1 }, /* power, vrange not set */ |
| 136 | }; |
| 137 | |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 138 | static const struct coefficients adm1278_coefficients[] = { |
| 139 | [0] = { 19599, 0, -2 }, /* voltage */ |
| 140 | [1] = { 800, 20475, -1 }, /* current */ |
| 141 | [2] = { 6123, 0, -2 }, /* power */ |
| 142 | [3] = { 42, 31880, -1 }, /* temperature */ |
| 143 | }; |
| 144 | |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 145 | static const struct coefficients adm1293_coefficients[] = { |
| 146 | [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */ |
| 147 | [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */ |
| 148 | [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */ |
| 149 | [3] = { 8000, -100, -2 }, /* current, irange25 */ |
| 150 | [4] = { 4000, -100, -2 }, /* current, irange50 */ |
| 151 | [5] = { 20000, -1000, -3 }, /* current, irange100 */ |
| 152 | [6] = { 10000, -1000, -3 }, /* current, irange200 */ |
| 153 | [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */ |
| 154 | [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */ |
| 155 | [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */ |
| 156 | [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */ |
| 157 | [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */ |
| 158 | [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */ |
| 159 | [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */ |
| 160 | [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */ |
| 161 | [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */ |
| 162 | [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */ |
| 163 | [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */ |
| 164 | [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */ |
| 165 | }; |
| 166 | |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 167 | static int adm1275_read_word_data(struct i2c_client *client, int page, int reg) |
| 168 | { |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 169 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 170 | const struct adm1275_data *data = to_adm1275_data(info); |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 171 | int ret = 0; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 172 | |
Guenter Roeck | ecb29ab | 2018-03-10 17:55:47 -0800 | [diff] [blame] | 173 | if (page > 0) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 174 | return -ENXIO; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 175 | |
| 176 | switch (reg) { |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 177 | case PMBUS_IOUT_UC_FAULT_LIMIT: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 178 | if (!data->have_uc_fault) |
| 179 | return -ENXIO; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 180 | ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); |
| 181 | break; |
| 182 | case PMBUS_IOUT_OC_FAULT_LIMIT: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 183 | if (!data->have_oc_fault) |
| 184 | return -ENXIO; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 185 | ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); |
| 186 | break; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 187 | case PMBUS_VOUT_OV_WARN_LIMIT: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 188 | if (data->have_vout) |
| 189 | return -ENODATA; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 190 | ret = pmbus_read_word_data(client, 0, |
| 191 | ADM1075_VAUX_OV_WARN_LIMIT); |
| 192 | break; |
| 193 | case PMBUS_VOUT_UV_WARN_LIMIT: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 194 | if (data->have_vout) |
| 195 | return -ENODATA; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 196 | ret = pmbus_read_word_data(client, 0, |
| 197 | ADM1075_VAUX_UV_WARN_LIMIT); |
| 198 | break; |
| 199 | case PMBUS_READ_VOUT: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 200 | if (data->have_vout) |
| 201 | return -ENODATA; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 202 | ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX); |
| 203 | break; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 204 | case PMBUS_VIRT_READ_IOUT_MIN: |
| 205 | if (!data->have_iout_min) |
| 206 | return -ENXIO; |
| 207 | ret = pmbus_read_word_data(client, 0, ADM1293_IOUT_MIN); |
| 208 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 209 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 210 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT); |
| 211 | break; |
| 212 | case PMBUS_VIRT_READ_VOUT_MAX: |
| 213 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VOUT); |
| 214 | break; |
| 215 | case PMBUS_VIRT_READ_VIN_MAX: |
| 216 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN); |
| 217 | break; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 218 | case PMBUS_VIRT_READ_PIN_MIN: |
| 219 | if (!data->have_pin_min) |
| 220 | return -ENXIO; |
| 221 | ret = pmbus_read_word_data(client, 0, ADM1293_PIN_MIN); |
| 222 | break; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 223 | case PMBUS_VIRT_READ_PIN_MAX: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 224 | if (!data->have_pin_max) |
| 225 | return -ENXIO; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 226 | ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN); |
| 227 | break; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 228 | case PMBUS_VIRT_READ_TEMP_MAX: |
| 229 | if (!data->have_temp_max) |
| 230 | return -ENXIO; |
| 231 | ret = pmbus_read_word_data(client, 0, ADM1278_PEAK_TEMP); |
| 232 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 233 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 234 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 235 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 236 | break; |
| 237 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 238 | if (!data->have_pin_max) |
| 239 | return -ENXIO; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 240 | break; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 241 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
| 242 | if (!data->have_temp_max) |
| 243 | return -ENXIO; |
| 244 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 245 | default: |
| 246 | ret = -ENODATA; |
| 247 | break; |
| 248 | } |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | static int adm1275_write_word_data(struct i2c_client *client, int page, int reg, |
| 253 | u16 word) |
| 254 | { |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 255 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 256 | const struct adm1275_data *data = to_adm1275_data(info); |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 257 | int ret; |
| 258 | |
Guenter Roeck | ecb29ab | 2018-03-10 17:55:47 -0800 | [diff] [blame] | 259 | if (page > 0) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 260 | return -ENXIO; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 261 | |
| 262 | switch (reg) { |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 263 | case PMBUS_IOUT_UC_FAULT_LIMIT: |
| 264 | case PMBUS_IOUT_OC_FAULT_LIMIT: |
| 265 | ret = pmbus_write_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT, |
| 266 | word); |
| 267 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 268 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 269 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_IOUT, 0); |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 270 | if (!ret && data->have_iout_min) |
| 271 | ret = pmbus_write_word_data(client, 0, |
| 272 | ADM1293_IOUT_MIN, 0); |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 273 | break; |
| 274 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 275 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VOUT, 0); |
| 276 | break; |
| 277 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
| 278 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VIN, 0); |
| 279 | break; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 280 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
| 281 | ret = pmbus_write_word_data(client, 0, ADM1276_PEAK_PIN, 0); |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 282 | if (!ret && data->have_pin_min) |
| 283 | ret = pmbus_write_word_data(client, 0, |
| 284 | ADM1293_PIN_MIN, 0); |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 285 | break; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 286 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
| 287 | ret = pmbus_write_word_data(client, 0, ADM1278_PEAK_TEMP, 0); |
| 288 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 289 | default: |
| 290 | ret = -ENODATA; |
| 291 | break; |
| 292 | } |
| 293 | return ret; |
| 294 | } |
| 295 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 296 | static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg) |
| 297 | { |
| 298 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 299 | const struct adm1275_data *data = to_adm1275_data(info); |
| 300 | int mfr_status, ret; |
| 301 | |
Guenter Roeck | da8e48a | 2011-07-29 22:19:39 -0700 | [diff] [blame] | 302 | if (page > 0) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 303 | return -ENXIO; |
| 304 | |
| 305 | switch (reg) { |
| 306 | case PMBUS_STATUS_IOUT: |
| 307 | ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT); |
| 308 | if (ret < 0) |
| 309 | break; |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 310 | if (!data->have_oc_fault && !data->have_uc_fault) |
| 311 | break; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 312 | mfr_status = pmbus_read_byte_data(client, page, |
| 313 | PMBUS_STATUS_MFR_SPECIFIC); |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 314 | if (mfr_status < 0) |
| 315 | return mfr_status; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 316 | if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) { |
| 317 | ret |= data->have_oc_fault ? |
| 318 | PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT; |
| 319 | } |
| 320 | break; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 321 | case PMBUS_STATUS_VOUT: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 322 | if (data->have_vout) |
| 323 | return -ENODATA; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 324 | ret = 0; |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 325 | if (data->have_vaux_status) { |
| 326 | mfr_status = pmbus_read_byte_data(client, 0, |
| 327 | ADM1075_VAUX_STATUS); |
| 328 | if (mfr_status < 0) |
| 329 | return mfr_status; |
| 330 | if (mfr_status & ADM1075_VAUX_OV_WARN) |
| 331 | ret |= PB_VOLTAGE_OV_WARNING; |
| 332 | if (mfr_status & ADM1075_VAUX_UV_WARN) |
| 333 | ret |= PB_VOLTAGE_UV_WARNING; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 334 | } else if (data->have_mfr_vaux_status) { |
| 335 | mfr_status = pmbus_read_byte_data(client, page, |
| 336 | PMBUS_STATUS_MFR_SPECIFIC); |
| 337 | if (mfr_status < 0) |
| 338 | return mfr_status; |
| 339 | if (mfr_status & ADM1293_MFR_STATUS_VAUX_OV_WARN) |
| 340 | ret |= PB_VOLTAGE_OV_WARNING; |
| 341 | if (mfr_status & ADM1293_MFR_STATUS_VAUX_UV_WARN) |
| 342 | ret |= PB_VOLTAGE_UV_WARNING; |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 343 | } |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 344 | break; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 345 | default: |
| 346 | ret = -ENODATA; |
| 347 | break; |
| 348 | } |
| 349 | return ret; |
| 350 | } |
| 351 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 352 | static const struct i2c_device_id adm1275_id[] = { |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 353 | { "adm1075", adm1075 }, |
Guenter Roeck | 4ff0ce2 | 2018-03-10 18:59:04 -0800 | [diff] [blame] | 354 | { "adm1272", adm1272 }, |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 355 | { "adm1275", adm1275 }, |
| 356 | { "adm1276", adm1276 }, |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 357 | { "adm1278", adm1278 }, |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 358 | { "adm1293", adm1293 }, |
| 359 | { "adm1294", adm1294 }, |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 360 | { } |
| 361 | }; |
| 362 | MODULE_DEVICE_TABLE(i2c, adm1275_id); |
| 363 | |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 364 | static int adm1275_probe(struct i2c_client *client, |
| 365 | const struct i2c_device_id *id) |
| 366 | { |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 367 | u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 368 | int config, device_config; |
Guenter Roeck | 3b33ca4 | 2011-06-30 02:30:03 -0700 | [diff] [blame] | 369 | int ret; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 370 | struct pmbus_driver_info *info; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 371 | struct adm1275_data *data; |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 372 | const struct i2c_device_id *mid; |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 373 | const struct coefficients *coefficients; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 374 | int vindex = -1, voindex = -1, cindex = -1, pindex = -1; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 375 | int tindex = -1; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 376 | |
| 377 | if (!i2c_check_functionality(client->adapter, |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 378 | I2C_FUNC_SMBUS_READ_BYTE_DATA |
| 379 | | I2C_FUNC_SMBUS_BLOCK_DATA)) |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 380 | return -ENODEV; |
| 381 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 382 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, block_buffer); |
| 383 | if (ret < 0) { |
| 384 | dev_err(&client->dev, "Failed to read Manufacturer ID\n"); |
| 385 | return ret; |
| 386 | } |
| 387 | if (ret != 3 || strncmp(block_buffer, "ADI", 3)) { |
| 388 | dev_err(&client->dev, "Unsupported Manufacturer ID\n"); |
| 389 | return -ENODEV; |
| 390 | } |
| 391 | |
| 392 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer); |
| 393 | if (ret < 0) { |
| 394 | dev_err(&client->dev, "Failed to read Manufacturer Model\n"); |
| 395 | return ret; |
| 396 | } |
| 397 | for (mid = adm1275_id; mid->name[0]; mid++) { |
| 398 | if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) |
| 399 | break; |
| 400 | } |
| 401 | if (!mid->name[0]) { |
| 402 | dev_err(&client->dev, "Unsupported device\n"); |
| 403 | return -ENODEV; |
| 404 | } |
| 405 | |
| 406 | if (id->driver_data != mid->driver_data) |
| 407 | dev_notice(&client->dev, |
| 408 | "Device mismatch: Configured %s, detected %s\n", |
| 409 | id->name, mid->name); |
| 410 | |
| 411 | config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); |
| 412 | if (config < 0) |
| 413 | return config; |
| 414 | |
| 415 | device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG); |
| 416 | if (device_config < 0) |
| 417 | return device_config; |
| 418 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 419 | data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data), |
| 420 | GFP_KERNEL); |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 421 | if (!data) |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 422 | return -ENOMEM; |
| 423 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 424 | data->id = mid->driver_data; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 425 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 426 | info = &data->info; |
| 427 | |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 428 | info->pages = 1; |
Guenter Roeck | 1061d85 | 2011-06-25 11:21:49 -0700 | [diff] [blame] | 429 | info->format[PSC_VOLTAGE_IN] = direct; |
| 430 | info->format[PSC_VOLTAGE_OUT] = direct; |
| 431 | info->format[PSC_CURRENT_OUT] = direct; |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 432 | info->format[PSC_POWER] = direct; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 433 | info->format[PSC_TEMPERATURE] = direct; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 434 | info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
| 435 | |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 436 | info->read_word_data = adm1275_read_word_data; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 437 | info->read_byte_data = adm1275_read_byte_data; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 438 | info->write_word_data = adm1275_write_word_data; |
| 439 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 440 | switch (data->id) { |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 441 | case adm1075: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 442 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
| 443 | data->have_oc_fault = true; |
| 444 | else |
| 445 | data->have_uc_fault = true; |
| 446 | data->have_pin_max = true; |
| 447 | data->have_vaux_status = true; |
| 448 | |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 449 | coefficients = adm1075_coefficients; |
| 450 | vindex = 0; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 451 | switch (config & ADM1075_IRANGE_MASK) { |
| 452 | case ADM1075_IRANGE_25: |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 453 | cindex = 1; |
| 454 | pindex = 3; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 455 | break; |
| 456 | case ADM1075_IRANGE_50: |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 457 | cindex = 2; |
| 458 | pindex = 4; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 459 | break; |
| 460 | default: |
| 461 | dev_err(&client->dev, "Invalid input current range"); |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 462 | break; |
| 463 | } |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 464 | |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 465 | info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN |
| 466 | | PMBUS_HAVE_STATUS_INPUT; |
| 467 | if (config & ADM1275_VIN_VOUT_SELECT) |
| 468 | info->func[0] |= |
| 469 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 470 | break; |
Guenter Roeck | 4ff0ce2 | 2018-03-10 18:59:04 -0800 | [diff] [blame] | 471 | case adm1272: |
| 472 | data->have_vout = true; |
| 473 | data->have_pin_max = true; |
| 474 | data->have_temp_max = true; |
| 475 | |
| 476 | coefficients = adm1272_coefficients; |
| 477 | vindex = (config & ADM1275_VRANGE) ? 1 : 0; |
| 478 | cindex = (config & ADM1272_IRANGE) ? 3 : 2; |
| 479 | /* pindex depends on the combination of the above */ |
| 480 | switch (config & (ADM1275_VRANGE | ADM1272_IRANGE)) { |
| 481 | case 0: |
| 482 | default: |
| 483 | pindex = 4; |
| 484 | break; |
| 485 | case ADM1275_VRANGE: |
| 486 | pindex = 5; |
| 487 | break; |
| 488 | case ADM1272_IRANGE: |
| 489 | pindex = 6; |
| 490 | break; |
| 491 | case ADM1275_VRANGE | ADM1272_IRANGE: |
| 492 | pindex = 7; |
| 493 | break; |
| 494 | } |
| 495 | tindex = 8; |
| 496 | |
| 497 | info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | |
| 498 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 499 | |
| 500 | /* Enable VOUT if not enabled (it is disabled by default) */ |
| 501 | if (!(config & ADM1278_VOUT_EN)) { |
| 502 | config |= ADM1278_VOUT_EN; |
| 503 | ret = i2c_smbus_write_byte_data(client, |
| 504 | ADM1275_PMON_CONFIG, |
| 505 | config); |
| 506 | if (ret < 0) { |
| 507 | dev_err(&client->dev, |
| 508 | "Failed to enable VOUT monitoring\n"); |
| 509 | return -ENODEV; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | if (config & ADM1278_TEMP1_EN) |
| 514 | info->func[0] |= |
| 515 | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
| 516 | if (config & ADM1278_VIN_EN) |
| 517 | info->func[0] |= PMBUS_HAVE_VIN; |
| 518 | break; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 519 | case adm1275: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 520 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
| 521 | data->have_oc_fault = true; |
| 522 | else |
| 523 | data->have_uc_fault = true; |
| 524 | data->have_vout = true; |
| 525 | |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 526 | coefficients = adm1275_coefficients; |
| 527 | vindex = (config & ADM1275_VRANGE) ? 0 : 1; |
| 528 | cindex = 2; |
| 529 | |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 530 | if (config & ADM1275_VIN_VOUT_SELECT) |
| 531 | info->func[0] |= |
| 532 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 533 | else |
| 534 | info->func[0] |= |
| 535 | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; |
| 536 | break; |
| 537 | case adm1276: |
Guenter Roeck | 9048539 | 2015-07-04 10:09:54 -0700 | [diff] [blame] | 538 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
| 539 | data->have_oc_fault = true; |
| 540 | else |
| 541 | data->have_uc_fault = true; |
| 542 | data->have_vout = true; |
| 543 | data->have_pin_max = true; |
| 544 | |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 545 | coefficients = adm1276_coefficients; |
| 546 | vindex = (config & ADM1275_VRANGE) ? 0 : 1; |
| 547 | cindex = 2; |
| 548 | pindex = (config & ADM1275_VRANGE) ? 3 : 4; |
| 549 | |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 550 | info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN |
| 551 | | PMBUS_HAVE_STATUS_INPUT; |
| 552 | if (config & ADM1275_VIN_VOUT_SELECT) |
| 553 | info->func[0] |= |
| 554 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 555 | break; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 556 | case adm1278: |
| 557 | data->have_vout = true; |
| 558 | data->have_pin_max = true; |
| 559 | data->have_temp_max = true; |
| 560 | |
| 561 | coefficients = adm1278_coefficients; |
| 562 | vindex = 0; |
| 563 | cindex = 1; |
| 564 | pindex = 2; |
| 565 | tindex = 3; |
| 566 | |
Yi Li | 2b3d0c1 | 2016-10-17 18:38:53 +1030 | [diff] [blame] | 567 | info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | |
| 568 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 569 | |
| 570 | /* Enable VOUT if not enabled (it is disabled by default) */ |
| 571 | if (!(config & ADM1278_VOUT_EN)) { |
| 572 | config |= ADM1278_VOUT_EN; |
| 573 | ret = i2c_smbus_write_byte_data(client, |
| 574 | ADM1275_PMON_CONFIG, |
| 575 | config); |
| 576 | if (ret < 0) { |
| 577 | dev_err(&client->dev, |
| 578 | "Failed to enable VOUT monitoring\n"); |
| 579 | return -ENODEV; |
| 580 | } |
| 581 | } |
| 582 | |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 583 | if (config & ADM1278_TEMP1_EN) |
| 584 | info->func[0] |= |
| 585 | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
| 586 | if (config & ADM1278_VIN_EN) |
| 587 | info->func[0] |= PMBUS_HAVE_VIN; |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 588 | break; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 589 | case adm1293: |
| 590 | case adm1294: |
| 591 | data->have_iout_min = true; |
| 592 | data->have_pin_min = true; |
| 593 | data->have_pin_max = true; |
| 594 | data->have_mfr_vaux_status = true; |
| 595 | |
| 596 | coefficients = adm1293_coefficients; |
| 597 | |
| 598 | voindex = 0; |
| 599 | switch (config & ADM1293_VIN_SEL_MASK) { |
| 600 | case ADM1293_VIN_SEL_012: /* 1.2V */ |
| 601 | vindex = 0; |
| 602 | break; |
| 603 | case ADM1293_VIN_SEL_074: /* 7.4V */ |
| 604 | vindex = 1; |
| 605 | break; |
| 606 | case ADM1293_VIN_SEL_210: /* 21V */ |
| 607 | vindex = 2; |
| 608 | break; |
| 609 | default: /* disabled */ |
| 610 | break; |
| 611 | } |
| 612 | |
| 613 | switch (config & ADM1293_IRANGE_MASK) { |
| 614 | case ADM1293_IRANGE_25: |
| 615 | cindex = 3; |
| 616 | break; |
| 617 | case ADM1293_IRANGE_50: |
| 618 | cindex = 4; |
| 619 | break; |
| 620 | case ADM1293_IRANGE_100: |
| 621 | cindex = 5; |
| 622 | break; |
| 623 | case ADM1293_IRANGE_200: |
| 624 | cindex = 6; |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | if (vindex >= 0) |
| 629 | pindex = 7 + vindex * 4 + (cindex - 3); |
| 630 | |
| 631 | if (config & ADM1293_VAUX_EN) |
| 632 | info->func[0] |= |
| 633 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 634 | |
| 635 | info->func[0] |= PMBUS_HAVE_PIN | |
| 636 | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; |
| 637 | |
| 638 | break; |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 639 | default: |
| 640 | dev_err(&client->dev, "Unsupported device\n"); |
| 641 | return -ENODEV; |
| 642 | } |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 643 | |
| 644 | if (voindex < 0) |
| 645 | voindex = vindex; |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 646 | if (vindex >= 0) { |
| 647 | info->m[PSC_VOLTAGE_IN] = coefficients[vindex].m; |
| 648 | info->b[PSC_VOLTAGE_IN] = coefficients[vindex].b; |
| 649 | info->R[PSC_VOLTAGE_IN] = coefficients[vindex].R; |
Guenter Roeck | 68a4038 | 2015-03-17 13:19:51 -0700 | [diff] [blame] | 650 | } |
| 651 | if (voindex >= 0) { |
| 652 | info->m[PSC_VOLTAGE_OUT] = coefficients[voindex].m; |
| 653 | info->b[PSC_VOLTAGE_OUT] = coefficients[voindex].b; |
| 654 | info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R; |
Guenter Roeck | 904b296 | 2015-07-04 08:39:18 -0700 | [diff] [blame] | 655 | } |
| 656 | if (cindex >= 0) { |
| 657 | info->m[PSC_CURRENT_OUT] = coefficients[cindex].m; |
| 658 | info->b[PSC_CURRENT_OUT] = coefficients[cindex].b; |
| 659 | info->R[PSC_CURRENT_OUT] = coefficients[cindex].R; |
| 660 | } |
| 661 | if (pindex >= 0) { |
| 662 | info->m[PSC_POWER] = coefficients[pindex].m; |
| 663 | info->b[PSC_POWER] = coefficients[pindex].b; |
| 664 | info->R[PSC_POWER] = coefficients[pindex].R; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 665 | } |
Guenter Roeck | 709066ac | 2015-07-05 11:04:56 -0700 | [diff] [blame] | 666 | if (tindex >= 0) { |
| 667 | info->m[PSC_TEMPERATURE] = coefficients[tindex].m; |
| 668 | info->b[PSC_TEMPERATURE] = coefficients[tindex].b; |
| 669 | info->R[PSC_TEMPERATURE] = coefficients[tindex].R; |
| 670 | } |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 671 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 672 | return pmbus_do_probe(client, id, info); |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 675 | static struct i2c_driver adm1275_driver = { |
| 676 | .driver = { |
| 677 | .name = "adm1275", |
| 678 | }, |
| 679 | .probe = adm1275_probe, |
Guenter Roeck | dd285ad | 2012-02-22 08:56:44 -0800 | [diff] [blame] | 680 | .remove = pmbus_do_remove, |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 681 | .id_table = adm1275_id, |
| 682 | }; |
| 683 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 684 | module_i2c_driver(adm1275_driver); |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 685 | |
| 686 | MODULE_AUTHOR("Guenter Roeck"); |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 687 | MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles"); |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 688 | MODULE_LICENSE("GPL"); |