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. |
| 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. |
| 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> |
| 24 | #include "pmbus.h" |
| 25 | |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 26 | enum chips { adm1075, adm1275, adm1276 }; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 27 | |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 28 | #define ADM1275_PEAK_IOUT 0xd0 |
| 29 | #define ADM1275_PEAK_VIN 0xd1 |
| 30 | #define ADM1275_PEAK_VOUT 0xd2 |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 31 | #define ADM1275_PMON_CONFIG 0xd4 |
| 32 | |
| 33 | #define ADM1275_VIN_VOUT_SELECT (1 << 6) |
| 34 | #define ADM1275_VRANGE (1 << 5) |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 35 | #define ADM1075_IRANGE_50 (1 << 4) |
| 36 | #define ADM1075_IRANGE_25 (1 << 3) |
| 37 | #define ADM1075_IRANGE_MASK ((1 << 3) | (1 << 4)) |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 38 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 39 | #define ADM1275_IOUT_WARN2_LIMIT 0xd7 |
| 40 | #define ADM1275_DEVICE_CONFIG 0xd8 |
| 41 | |
| 42 | #define ADM1275_IOUT_WARN2_SELECT (1 << 4) |
| 43 | |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 44 | #define ADM1276_PEAK_PIN 0xda |
| 45 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 46 | #define ADM1275_MFR_STATUS_IOUT_WARN2 (1 << 0) |
| 47 | |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 48 | #define ADM1075_READ_VAUX 0xdd |
| 49 | #define ADM1075_VAUX_OV_WARN_LIMIT 0xde |
| 50 | #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf |
| 51 | #define ADM1075_VAUX_STATUS 0xf6 |
| 52 | |
| 53 | #define ADM1075_VAUX_OV_WARN (1<<7) |
| 54 | #define ADM1075_VAUX_UV_WARN (1<<6) |
| 55 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 56 | struct adm1275_data { |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 57 | int id; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 58 | bool have_oc_fault; |
| 59 | struct pmbus_driver_info info; |
| 60 | }; |
| 61 | |
| 62 | #define to_adm1275_data(x) container_of(x, struct adm1275_data, info) |
| 63 | |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 64 | static int adm1275_read_word_data(struct i2c_client *client, int page, int reg) |
| 65 | { |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 66 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 67 | const struct adm1275_data *data = to_adm1275_data(info); |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 68 | int ret = 0; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 69 | |
| 70 | if (page) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 71 | return -ENXIO; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 72 | |
| 73 | switch (reg) { |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 74 | case PMBUS_IOUT_UC_FAULT_LIMIT: |
| 75 | if (data->have_oc_fault) { |
| 76 | ret = -ENXIO; |
| 77 | break; |
| 78 | } |
| 79 | ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); |
| 80 | break; |
| 81 | case PMBUS_IOUT_OC_FAULT_LIMIT: |
| 82 | if (!data->have_oc_fault) { |
| 83 | ret = -ENXIO; |
| 84 | break; |
| 85 | } |
| 86 | ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); |
| 87 | break; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 88 | case PMBUS_VOUT_OV_WARN_LIMIT: |
| 89 | if (data->id != adm1075) { |
| 90 | ret = -ENODATA; |
| 91 | break; |
| 92 | } |
| 93 | ret = pmbus_read_word_data(client, 0, |
| 94 | ADM1075_VAUX_OV_WARN_LIMIT); |
| 95 | break; |
| 96 | case PMBUS_VOUT_UV_WARN_LIMIT: |
| 97 | if (data->id != adm1075) { |
| 98 | ret = -ENODATA; |
| 99 | break; |
| 100 | } |
| 101 | ret = pmbus_read_word_data(client, 0, |
| 102 | ADM1075_VAUX_UV_WARN_LIMIT); |
| 103 | break; |
| 104 | case PMBUS_READ_VOUT: |
| 105 | if (data->id != adm1075) { |
| 106 | ret = -ENODATA; |
| 107 | break; |
| 108 | } |
| 109 | ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX); |
| 110 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 111 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 112 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT); |
| 113 | break; |
| 114 | case PMBUS_VIRT_READ_VOUT_MAX: |
| 115 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VOUT); |
| 116 | break; |
| 117 | case PMBUS_VIRT_READ_VIN_MAX: |
| 118 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN); |
| 119 | break; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 120 | case PMBUS_VIRT_READ_PIN_MAX: |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 121 | if (data->id == adm1275) { |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 122 | ret = -ENXIO; |
| 123 | break; |
| 124 | } |
| 125 | ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN); |
| 126 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 127 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 128 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 129 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 130 | break; |
| 131 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 132 | if (data->id == adm1275) |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 133 | ret = -ENXIO; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 134 | break; |
| 135 | default: |
| 136 | ret = -ENODATA; |
| 137 | break; |
| 138 | } |
| 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | static int adm1275_write_word_data(struct i2c_client *client, int page, int reg, |
| 143 | u16 word) |
| 144 | { |
| 145 | int ret; |
| 146 | |
| 147 | if (page) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 148 | return -ENXIO; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 149 | |
| 150 | switch (reg) { |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 151 | case PMBUS_IOUT_UC_FAULT_LIMIT: |
| 152 | case PMBUS_IOUT_OC_FAULT_LIMIT: |
| 153 | ret = pmbus_write_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT, |
| 154 | word); |
| 155 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 156 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 157 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_IOUT, 0); |
| 158 | break; |
| 159 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 160 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VOUT, 0); |
| 161 | break; |
| 162 | case PMBUS_VIRT_RESET_VIN_HISTORY: |
| 163 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VIN, 0); |
| 164 | break; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 165 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
| 166 | ret = pmbus_write_word_data(client, 0, ADM1276_PEAK_PIN, 0); |
| 167 | break; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 168 | default: |
| 169 | ret = -ENODATA; |
| 170 | break; |
| 171 | } |
| 172 | return ret; |
| 173 | } |
| 174 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 175 | static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg) |
| 176 | { |
| 177 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 178 | const struct adm1275_data *data = to_adm1275_data(info); |
| 179 | int mfr_status, ret; |
| 180 | |
Guenter Roeck | da8e48a | 2011-07-29 22:19:39 -0700 | [diff] [blame] | 181 | if (page > 0) |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 182 | return -ENXIO; |
| 183 | |
| 184 | switch (reg) { |
| 185 | case PMBUS_STATUS_IOUT: |
| 186 | ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT); |
| 187 | if (ret < 0) |
| 188 | break; |
| 189 | mfr_status = pmbus_read_byte_data(client, page, |
| 190 | PMBUS_STATUS_MFR_SPECIFIC); |
| 191 | if (mfr_status < 0) { |
| 192 | ret = mfr_status; |
| 193 | break; |
| 194 | } |
| 195 | if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) { |
| 196 | ret |= data->have_oc_fault ? |
| 197 | PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT; |
| 198 | } |
| 199 | break; |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 200 | case PMBUS_STATUS_VOUT: |
| 201 | if (data->id != adm1075) { |
| 202 | ret = -ENODATA; |
| 203 | break; |
| 204 | } |
| 205 | ret = 0; |
| 206 | mfr_status = pmbus_read_byte_data(client, 0, |
| 207 | ADM1075_VAUX_STATUS); |
| 208 | if (mfr_status & ADM1075_VAUX_OV_WARN) |
| 209 | ret |= PB_VOLTAGE_OV_WARNING; |
| 210 | if (mfr_status & ADM1075_VAUX_UV_WARN) |
| 211 | ret |= PB_VOLTAGE_UV_WARNING; |
| 212 | break; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 213 | default: |
| 214 | ret = -ENODATA; |
| 215 | break; |
| 216 | } |
| 217 | return ret; |
| 218 | } |
| 219 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 220 | static const struct i2c_device_id adm1275_id[] = { |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 221 | { "adm1075", adm1075 }, |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 222 | { "adm1275", adm1275 }, |
| 223 | { "adm1276", adm1276 }, |
| 224 | { } |
| 225 | }; |
| 226 | MODULE_DEVICE_TABLE(i2c, adm1275_id); |
| 227 | |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 228 | static int adm1275_probe(struct i2c_client *client, |
| 229 | const struct i2c_device_id *id) |
| 230 | { |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 231 | u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 232 | int config, device_config; |
Guenter Roeck | 3b33ca4 | 2011-06-30 02:30:03 -0700 | [diff] [blame] | 233 | int ret; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 234 | struct pmbus_driver_info *info; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 235 | struct adm1275_data *data; |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 236 | const struct i2c_device_id *mid; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 237 | |
| 238 | if (!i2c_check_functionality(client->adapter, |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 239 | I2C_FUNC_SMBUS_READ_BYTE_DATA |
| 240 | | I2C_FUNC_SMBUS_BLOCK_DATA)) |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 241 | return -ENODEV; |
| 242 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 243 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, block_buffer); |
| 244 | if (ret < 0) { |
| 245 | dev_err(&client->dev, "Failed to read Manufacturer ID\n"); |
| 246 | return ret; |
| 247 | } |
| 248 | if (ret != 3 || strncmp(block_buffer, "ADI", 3)) { |
| 249 | dev_err(&client->dev, "Unsupported Manufacturer ID\n"); |
| 250 | return -ENODEV; |
| 251 | } |
| 252 | |
| 253 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer); |
| 254 | if (ret < 0) { |
| 255 | dev_err(&client->dev, "Failed to read Manufacturer Model\n"); |
| 256 | return ret; |
| 257 | } |
| 258 | for (mid = adm1275_id; mid->name[0]; mid++) { |
| 259 | if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) |
| 260 | break; |
| 261 | } |
| 262 | if (!mid->name[0]) { |
| 263 | dev_err(&client->dev, "Unsupported device\n"); |
| 264 | return -ENODEV; |
| 265 | } |
| 266 | |
| 267 | if (id->driver_data != mid->driver_data) |
| 268 | dev_notice(&client->dev, |
| 269 | "Device mismatch: Configured %s, detected %s\n", |
| 270 | id->name, mid->name); |
| 271 | |
| 272 | config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); |
| 273 | if (config < 0) |
| 274 | return config; |
| 275 | |
| 276 | device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG); |
| 277 | if (device_config < 0) |
| 278 | return device_config; |
| 279 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 280 | data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data), |
| 281 | GFP_KERNEL); |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 282 | if (!data) |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 283 | return -ENOMEM; |
| 284 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 285 | data->id = mid->driver_data; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 286 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 287 | info = &data->info; |
| 288 | |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 289 | info->pages = 1; |
Guenter Roeck | 1061d85 | 2011-06-25 11:21:49 -0700 | [diff] [blame] | 290 | info->format[PSC_VOLTAGE_IN] = direct; |
| 291 | info->format[PSC_VOLTAGE_OUT] = direct; |
| 292 | info->format[PSC_CURRENT_OUT] = direct; |
Guenter Roeck | 7e97bbb | 2011-07-14 14:18:03 -0700 | [diff] [blame] | 293 | info->m[PSC_CURRENT_OUT] = 807; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 294 | info->b[PSC_CURRENT_OUT] = 20475; |
| 295 | info->R[PSC_CURRENT_OUT] = -1; |
| 296 | info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
| 297 | |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 298 | info->read_word_data = adm1275_read_word_data; |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 299 | info->read_byte_data = adm1275_read_byte_data; |
Guenter Roeck | c576e30 | 2011-07-09 11:17:33 -0700 | [diff] [blame] | 300 | info->write_word_data = adm1275_write_word_data; |
| 301 | |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 302 | if (data->id == adm1075) { |
| 303 | info->m[PSC_VOLTAGE_IN] = 27169; |
| 304 | info->b[PSC_VOLTAGE_IN] = 0; |
| 305 | info->R[PSC_VOLTAGE_IN] = -1; |
| 306 | info->m[PSC_VOLTAGE_OUT] = 27169; |
| 307 | info->b[PSC_VOLTAGE_OUT] = 0; |
| 308 | info->R[PSC_VOLTAGE_OUT] = -1; |
| 309 | } else if (config & ADM1275_VRANGE) { |
Guenter Roeck | 7e97bbb | 2011-07-14 14:18:03 -0700 | [diff] [blame] | 310 | info->m[PSC_VOLTAGE_IN] = 19199; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 311 | info->b[PSC_VOLTAGE_IN] = 0; |
| 312 | info->R[PSC_VOLTAGE_IN] = -2; |
Guenter Roeck | 7e97bbb | 2011-07-14 14:18:03 -0700 | [diff] [blame] | 313 | info->m[PSC_VOLTAGE_OUT] = 19199; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 314 | info->b[PSC_VOLTAGE_OUT] = 0; |
| 315 | info->R[PSC_VOLTAGE_OUT] = -2; |
| 316 | } else { |
Guenter Roeck | 7e97bbb | 2011-07-14 14:18:03 -0700 | [diff] [blame] | 317 | info->m[PSC_VOLTAGE_IN] = 6720; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 318 | info->b[PSC_VOLTAGE_IN] = 0; |
| 319 | info->R[PSC_VOLTAGE_IN] = -1; |
Guenter Roeck | 7e97bbb | 2011-07-14 14:18:03 -0700 | [diff] [blame] | 320 | info->m[PSC_VOLTAGE_OUT] = 6720; |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 321 | info->b[PSC_VOLTAGE_OUT] = 0; |
| 322 | info->R[PSC_VOLTAGE_OUT] = -1; |
| 323 | } |
| 324 | |
Guenter Roeck | c5e6763 | 2011-08-02 11:08:57 -0700 | [diff] [blame] | 325 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
| 326 | data->have_oc_fault = true; |
| 327 | |
Guenter Roeck | 8710280 | 2011-09-30 11:53:25 -0700 | [diff] [blame] | 328 | switch (data->id) { |
Guenter Roeck | 9271126 | 2012-02-24 03:40:53 -0800 | [diff] [blame] | 329 | case adm1075: |
| 330 | info->format[PSC_POWER] = direct; |
| 331 | info->b[PSC_POWER] = 0; |
| 332 | info->R[PSC_POWER] = -1; |
| 333 | switch (config & ADM1075_IRANGE_MASK) { |
| 334 | case ADM1075_IRANGE_25: |
| 335 | info->m[PSC_POWER] = 8549; |
| 336 | info->m[PSC_CURRENT_OUT] = 806; |
| 337 | break; |
| 338 | case ADM1075_IRANGE_50: |
| 339 | info->m[PSC_POWER] = 4279; |
| 340 | info->m[PSC_CURRENT_OUT] = 404; |
| 341 | break; |
| 342 | default: |
| 343 | dev_err(&client->dev, "Invalid input current range"); |
| 344 | info->m[PSC_POWER] = 0; |
| 345 | info->m[PSC_CURRENT_OUT] = 0; |
| 346 | break; |
| 347 | } |
| 348 | info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN |
| 349 | | PMBUS_HAVE_STATUS_INPUT; |
| 350 | if (config & ADM1275_VIN_VOUT_SELECT) |
| 351 | info->func[0] |= |
| 352 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 353 | break; |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 354 | case adm1275: |
| 355 | if (config & ADM1275_VIN_VOUT_SELECT) |
| 356 | info->func[0] |= |
| 357 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 358 | else |
| 359 | info->func[0] |= |
| 360 | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; |
| 361 | break; |
| 362 | case adm1276: |
| 363 | info->format[PSC_POWER] = direct; |
| 364 | info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN |
| 365 | | PMBUS_HAVE_STATUS_INPUT; |
| 366 | if (config & ADM1275_VIN_VOUT_SELECT) |
| 367 | info->func[0] |= |
| 368 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
| 369 | if (config & ADM1275_VRANGE) { |
| 370 | info->m[PSC_POWER] = 6043; |
| 371 | info->b[PSC_POWER] = 0; |
| 372 | info->R[PSC_POWER] = -2; |
| 373 | } else { |
| 374 | info->m[PSC_POWER] = 2115; |
| 375 | info->b[PSC_POWER] = 0; |
| 376 | info->R[PSC_POWER] = -1; |
| 377 | } |
| 378 | break; |
| 379 | } |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 380 | |
Guenter Roeck | 8b313ca | 2012-02-22 08:56:43 -0800 | [diff] [blame] | 381 | return pmbus_do_probe(client, id, info); |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 384 | static struct i2c_driver adm1275_driver = { |
| 385 | .driver = { |
| 386 | .name = "adm1275", |
| 387 | }, |
| 388 | .probe = adm1275_probe, |
Guenter Roeck | dd285ad | 2012-02-22 08:56:44 -0800 | [diff] [blame] | 389 | .remove = pmbus_do_remove, |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 390 | .id_table = adm1275_id, |
| 391 | }; |
| 392 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 393 | module_i2c_driver(adm1275_driver); |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 394 | |
| 395 | MODULE_AUTHOR("Guenter Roeck"); |
Guenter Roeck | 5cf231a | 2011-07-14 11:55:35 -0700 | [diff] [blame] | 396 | MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles"); |
Guenter Roeck | 83f7649 | 2011-03-17 13:16:01 -0700 | [diff] [blame] | 397 | MODULE_LICENSE("GPL"); |