Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Hardware monitoring driver for Maxim MAX34440/MAX34441 |
| 3 | * |
| 4 | * Copyright (c) 2011 Ericsson AB. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/err.h> |
| 25 | #include <linux/i2c.h> |
| 26 | #include "pmbus.h" |
| 27 | |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 28 | enum chips { max34440, max34441, max34446 }; |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 29 | |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 30 | #define MAX34440_MFR_VOUT_PEAK 0xd4 |
| 31 | #define MAX34440_MFR_IOUT_PEAK 0xd5 |
| 32 | #define MAX34440_MFR_TEMPERATURE_PEAK 0xd6 |
Guenter Roeck | 56aad5d | 2012-02-24 08:13:31 -0800 | [diff] [blame] | 33 | #define MAX34440_MFR_VOUT_MIN 0xd7 |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 34 | |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 35 | #define MAX34446_MFR_POUT_PEAK 0xe0 |
| 36 | #define MAX34446_MFR_POUT_AVG 0xe1 |
| 37 | #define MAX34446_MFR_IOUT_AVG 0xe2 |
| 38 | #define MAX34446_MFR_TEMPERATURE_AVG 0xe3 |
| 39 | |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 40 | #define MAX34440_STATUS_OC_WARN (1 << 0) |
| 41 | #define MAX34440_STATUS_OC_FAULT (1 << 1) |
| 42 | #define MAX34440_STATUS_OT_FAULT (1 << 5) |
| 43 | #define MAX34440_STATUS_OT_WARN (1 << 6) |
| 44 | |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 45 | struct max34440_data { |
| 46 | int id; |
| 47 | struct pmbus_driver_info info; |
| 48 | }; |
| 49 | |
| 50 | #define to_max34440_data(x) container_of(x, struct max34440_data, info) |
| 51 | |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 52 | static int max34440_read_word_data(struct i2c_client *client, int page, int reg) |
| 53 | { |
| 54 | int ret; |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 55 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 56 | const struct max34440_data *data = to_max34440_data(info); |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 57 | |
| 58 | switch (reg) { |
Guenter Roeck | 56aad5d | 2012-02-24 08:13:31 -0800 | [diff] [blame] | 59 | case PMBUS_VIRT_READ_VOUT_MIN: |
| 60 | ret = pmbus_read_word_data(client, page, |
| 61 | MAX34440_MFR_VOUT_MIN); |
| 62 | break; |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 63 | case PMBUS_VIRT_READ_VOUT_MAX: |
| 64 | ret = pmbus_read_word_data(client, page, |
| 65 | MAX34440_MFR_VOUT_PEAK); |
| 66 | break; |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 67 | case PMBUS_VIRT_READ_IOUT_AVG: |
| 68 | if (data->id != max34446) |
| 69 | return -ENXIO; |
| 70 | ret = pmbus_read_word_data(client, page, |
| 71 | MAX34446_MFR_IOUT_AVG); |
| 72 | break; |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 73 | case PMBUS_VIRT_READ_IOUT_MAX: |
| 74 | ret = pmbus_read_word_data(client, page, |
| 75 | MAX34440_MFR_IOUT_PEAK); |
| 76 | break; |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 77 | case PMBUS_VIRT_READ_POUT_AVG: |
| 78 | if (data->id != max34446) |
| 79 | return -ENXIO; |
| 80 | ret = pmbus_read_word_data(client, page, |
| 81 | MAX34446_MFR_POUT_AVG); |
| 82 | break; |
| 83 | case PMBUS_VIRT_READ_POUT_MAX: |
| 84 | if (data->id != max34446) |
| 85 | return -ENXIO; |
| 86 | ret = pmbus_read_word_data(client, page, |
| 87 | MAX34446_MFR_POUT_PEAK); |
| 88 | break; |
| 89 | case PMBUS_VIRT_READ_TEMP_AVG: |
| 90 | if (data->id != max34446) |
| 91 | return -ENXIO; |
| 92 | ret = pmbus_read_word_data(client, page, |
| 93 | MAX34446_MFR_TEMPERATURE_AVG); |
| 94 | break; |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 95 | case PMBUS_VIRT_READ_TEMP_MAX: |
| 96 | ret = pmbus_read_word_data(client, page, |
| 97 | MAX34440_MFR_TEMPERATURE_PEAK); |
| 98 | break; |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 99 | case PMBUS_VIRT_RESET_POUT_HISTORY: |
| 100 | if (data->id != max34446) |
| 101 | return -ENXIO; |
| 102 | ret = 0; |
| 103 | break; |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 104 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 105 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 106 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
| 107 | ret = 0; |
| 108 | break; |
| 109 | default: |
| 110 | ret = -ENODATA; |
| 111 | break; |
| 112 | } |
| 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | static int max34440_write_word_data(struct i2c_client *client, int page, |
| 117 | int reg, u16 word) |
| 118 | { |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 119 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
| 120 | const struct max34440_data *data = to_max34440_data(info); |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 121 | int ret; |
| 122 | |
| 123 | switch (reg) { |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 124 | case PMBUS_VIRT_RESET_POUT_HISTORY: |
| 125 | ret = pmbus_write_word_data(client, page, |
| 126 | MAX34446_MFR_POUT_PEAK, 0); |
| 127 | if (ret) |
| 128 | break; |
| 129 | ret = pmbus_write_word_data(client, page, |
| 130 | MAX34446_MFR_POUT_AVG, 0); |
| 131 | break; |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 132 | case PMBUS_VIRT_RESET_VOUT_HISTORY: |
| 133 | ret = pmbus_write_word_data(client, page, |
Guenter Roeck | 56aad5d | 2012-02-24 08:13:31 -0800 | [diff] [blame] | 134 | MAX34440_MFR_VOUT_MIN, 0x7fff); |
| 135 | if (ret) |
| 136 | break; |
| 137 | ret = pmbus_write_word_data(client, page, |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 138 | MAX34440_MFR_VOUT_PEAK, 0); |
| 139 | break; |
| 140 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
| 141 | ret = pmbus_write_word_data(client, page, |
| 142 | MAX34440_MFR_IOUT_PEAK, 0); |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 143 | if (!ret && data->id == max34446) |
| 144 | ret = pmbus_write_word_data(client, page, |
| 145 | MAX34446_MFR_IOUT_AVG, 0); |
| 146 | |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 147 | break; |
| 148 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
| 149 | ret = pmbus_write_word_data(client, page, |
| 150 | MAX34440_MFR_TEMPERATURE_PEAK, |
Guenter Roeck | dc91ad8 | 2012-02-24 03:44:34 -0800 | [diff] [blame] | 151 | 0x8000); |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 152 | if (!ret && data->id == max34446) |
| 153 | ret = pmbus_write_word_data(client, page, |
| 154 | MAX34446_MFR_TEMPERATURE_AVG, 0); |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 155 | break; |
| 156 | default: |
| 157 | ret = -ENODATA; |
| 158 | break; |
| 159 | } |
| 160 | return ret; |
| 161 | } |
| 162 | |
Guenter Roeck | 2cfa6ae | 2011-03-08 23:00:10 -0800 | [diff] [blame] | 163 | static int max34440_read_byte_data(struct i2c_client *client, int page, int reg) |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 164 | { |
Guenter Roeck | da8e48a | 2011-07-29 22:19:39 -0700 | [diff] [blame] | 165 | int ret = 0; |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 166 | int mfg_status; |
| 167 | |
Guenter Roeck | da8e48a | 2011-07-29 22:19:39 -0700 | [diff] [blame] | 168 | if (page >= 0) { |
| 169 | ret = pmbus_set_page(client, page); |
| 170 | if (ret < 0) |
| 171 | return ret; |
| 172 | } |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 173 | |
| 174 | switch (reg) { |
| 175 | case PMBUS_STATUS_IOUT: |
| 176 | mfg_status = pmbus_read_word_data(client, 0, |
| 177 | PMBUS_STATUS_MFR_SPECIFIC); |
| 178 | if (mfg_status < 0) |
| 179 | return mfg_status; |
| 180 | if (mfg_status & MAX34440_STATUS_OC_WARN) |
| 181 | ret |= PB_IOUT_OC_WARNING; |
| 182 | if (mfg_status & MAX34440_STATUS_OC_FAULT) |
| 183 | ret |= PB_IOUT_OC_FAULT; |
| 184 | break; |
| 185 | case PMBUS_STATUS_TEMPERATURE: |
| 186 | mfg_status = pmbus_read_word_data(client, 0, |
| 187 | PMBUS_STATUS_MFR_SPECIFIC); |
| 188 | if (mfg_status < 0) |
| 189 | return mfg_status; |
| 190 | if (mfg_status & MAX34440_STATUS_OT_WARN) |
| 191 | ret |= PB_TEMP_OT_WARNING; |
| 192 | if (mfg_status & MAX34440_STATUS_OT_FAULT) |
| 193 | ret |= PB_TEMP_OT_FAULT; |
| 194 | break; |
| 195 | default: |
| 196 | ret = -ENODATA; |
| 197 | break; |
| 198 | } |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | static struct pmbus_driver_info max34440_info[] = { |
| 203 | [max34440] = { |
| 204 | .pages = 14, |
Guenter Roeck | 1061d85 | 2011-06-25 11:21:49 -0700 | [diff] [blame] | 205 | .format[PSC_VOLTAGE_IN] = direct, |
| 206 | .format[PSC_VOLTAGE_OUT] = direct, |
| 207 | .format[PSC_TEMPERATURE] = direct, |
| 208 | .format[PSC_CURRENT_OUT] = direct, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 209 | .m[PSC_VOLTAGE_IN] = 1, |
| 210 | .b[PSC_VOLTAGE_IN] = 0, |
| 211 | .R[PSC_VOLTAGE_IN] = 3, /* R = 0 in datasheet reflects mV */ |
| 212 | .m[PSC_VOLTAGE_OUT] = 1, |
| 213 | .b[PSC_VOLTAGE_OUT] = 0, |
| 214 | .R[PSC_VOLTAGE_OUT] = 3, /* R = 0 in datasheet reflects mV */ |
| 215 | .m[PSC_CURRENT_OUT] = 1, |
| 216 | .b[PSC_CURRENT_OUT] = 0, |
| 217 | .R[PSC_CURRENT_OUT] = 3, /* R = 0 in datasheet reflects mA */ |
| 218 | .m[PSC_TEMPERATURE] = 1, |
| 219 | .b[PSC_TEMPERATURE] = 0, |
| 220 | .R[PSC_TEMPERATURE] = 2, |
| 221 | .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 222 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 223 | .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 224 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 225 | .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 226 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 227 | .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 228 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 229 | .func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 230 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 231 | .func[5] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 232 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 233 | .func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 234 | .func[7] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 235 | .func[8] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 236 | .func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 237 | .func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 238 | .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 239 | .func[12] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 240 | .func[13] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
Guenter Roeck | 2cfa6ae | 2011-03-08 23:00:10 -0800 | [diff] [blame] | 241 | .read_byte_data = max34440_read_byte_data, |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 242 | .read_word_data = max34440_read_word_data, |
| 243 | .write_word_data = max34440_write_word_data, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 244 | }, |
| 245 | [max34441] = { |
| 246 | .pages = 12, |
Guenter Roeck | 1061d85 | 2011-06-25 11:21:49 -0700 | [diff] [blame] | 247 | .format[PSC_VOLTAGE_IN] = direct, |
| 248 | .format[PSC_VOLTAGE_OUT] = direct, |
| 249 | .format[PSC_TEMPERATURE] = direct, |
| 250 | .format[PSC_CURRENT_OUT] = direct, |
| 251 | .format[PSC_FAN] = direct, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 252 | .m[PSC_VOLTAGE_IN] = 1, |
| 253 | .b[PSC_VOLTAGE_IN] = 0, |
| 254 | .R[PSC_VOLTAGE_IN] = 3, |
| 255 | .m[PSC_VOLTAGE_OUT] = 1, |
| 256 | .b[PSC_VOLTAGE_OUT] = 0, |
| 257 | .R[PSC_VOLTAGE_OUT] = 3, |
| 258 | .m[PSC_CURRENT_OUT] = 1, |
| 259 | .b[PSC_CURRENT_OUT] = 0, |
| 260 | .R[PSC_CURRENT_OUT] = 3, |
| 261 | .m[PSC_TEMPERATURE] = 1, |
| 262 | .b[PSC_TEMPERATURE] = 0, |
| 263 | .R[PSC_TEMPERATURE] = 2, |
| 264 | .m[PSC_FAN] = 1, |
| 265 | .b[PSC_FAN] = 0, |
| 266 | .R[PSC_FAN] = 0, |
| 267 | .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 268 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 269 | .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 270 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 271 | .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 272 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 273 | .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 274 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 275 | .func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 276 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 277 | .func[5] = PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12, |
| 278 | .func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 279 | .func[7] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 280 | .func[8] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 281 | .func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 282 | .func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 283 | .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
Guenter Roeck | 2cfa6ae | 2011-03-08 23:00:10 -0800 | [diff] [blame] | 284 | .read_byte_data = max34440_read_byte_data, |
Guenter Roeck | 98591db | 2011-07-09 13:17:43 -0700 | [diff] [blame] | 285 | .read_word_data = max34440_read_word_data, |
| 286 | .write_word_data = max34440_write_word_data, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 287 | }, |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 288 | [max34446] = { |
| 289 | .pages = 7, |
| 290 | .format[PSC_VOLTAGE_IN] = direct, |
| 291 | .format[PSC_VOLTAGE_OUT] = direct, |
| 292 | .format[PSC_TEMPERATURE] = direct, |
| 293 | .format[PSC_CURRENT_OUT] = direct, |
| 294 | .format[PSC_POWER] = direct, |
| 295 | .m[PSC_VOLTAGE_IN] = 1, |
| 296 | .b[PSC_VOLTAGE_IN] = 0, |
| 297 | .R[PSC_VOLTAGE_IN] = 3, |
| 298 | .m[PSC_VOLTAGE_OUT] = 1, |
| 299 | .b[PSC_VOLTAGE_OUT] = 0, |
| 300 | .R[PSC_VOLTAGE_OUT] = 3, |
| 301 | .m[PSC_CURRENT_OUT] = 1, |
| 302 | .b[PSC_CURRENT_OUT] = 0, |
| 303 | .R[PSC_CURRENT_OUT] = 3, |
| 304 | .m[PSC_POWER] = 1, |
| 305 | .b[PSC_POWER] = 0, |
| 306 | .R[PSC_POWER] = 3, |
| 307 | .m[PSC_TEMPERATURE] = 1, |
| 308 | .b[PSC_TEMPERATURE] = 0, |
| 309 | .R[PSC_TEMPERATURE] = 2, |
| 310 | .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 311 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT, |
| 312 | .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 313 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 314 | .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 315 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT, |
| 316 | .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 317 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 318 | .func[4] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 319 | .func[5] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 320 | .func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, |
| 321 | .read_byte_data = max34440_read_byte_data, |
| 322 | .read_word_data = max34440_read_word_data, |
| 323 | .write_word_data = max34440_write_word_data, |
| 324 | }, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | static int max34440_probe(struct i2c_client *client, |
| 328 | const struct i2c_device_id *id) |
| 329 | { |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 330 | struct max34440_data *data; |
| 331 | |
| 332 | data = devm_kzalloc(&client->dev, sizeof(struct max34440_data), |
| 333 | GFP_KERNEL); |
| 334 | if (!data) |
| 335 | return -ENOMEM; |
| 336 | data->id = id->driver_data; |
| 337 | data->info = max34440_info[id->driver_data]; |
| 338 | |
| 339 | return pmbus_do_probe(client, id, &data->info); |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 342 | static const struct i2c_device_id max34440_id[] = { |
| 343 | {"max34440", max34440}, |
| 344 | {"max34441", max34441}, |
Guenter Roeck | 590defe | 2012-02-24 03:40:22 -0800 | [diff] [blame^] | 345 | {"max34446", max34446}, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 346 | {} |
| 347 | }; |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 348 | MODULE_DEVICE_TABLE(i2c, max34440_id); |
| 349 | |
| 350 | /* This is the driver that will be inserted */ |
| 351 | static struct i2c_driver max34440_driver = { |
| 352 | .driver = { |
| 353 | .name = "max34440", |
| 354 | }, |
| 355 | .probe = max34440_probe, |
Guenter Roeck | dd285ad | 2012-02-22 08:56:44 -0800 | [diff] [blame] | 356 | .remove = pmbus_do_remove, |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 357 | .id_table = max34440_id, |
| 358 | }; |
| 359 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 360 | module_i2c_driver(max34440_driver); |
Guenter Roeck | a3eeb45 | 2011-01-26 20:15:27 -0800 | [diff] [blame] | 361 | |
| 362 | MODULE_AUTHOR("Guenter Roeck"); |
| 363 | MODULE_DESCRIPTION("PMBus driver for Maxim MAX34440/MAX34441"); |
| 364 | MODULE_LICENSE("GPL"); |