]>
Commit | Line | Data |
---|---|---|
f7c2fe38 FL |
1 | /* |
2 | * Driver for Texas Instruments INA219, INA226 power monitor chips | |
3 | * | |
4 | * INA219: | |
5 | * Zero Drift Bi-Directional Current/Power Monitor with I2C Interface | |
6 | * Datasheet: http://www.ti.com/product/ina219 | |
7 | * | |
dc92cd0c GR |
8 | * INA220: |
9 | * Bi-Directional Current/Power Monitor with I2C Interface | |
10 | * Datasheet: http://www.ti.com/product/ina220 | |
11 | * | |
f7c2fe38 FL |
12 | * INA226: |
13 | * Bi-Directional Current/Power Monitor with I2C Interface | |
14 | * Datasheet: http://www.ti.com/product/ina226 | |
15 | * | |
dc92cd0c GR |
16 | * INA230: |
17 | * Bi-directional Current/Power Monitor with I2C Interface | |
18 | * Datasheet: http://www.ti.com/product/ina230 | |
19 | * | |
3ad86700 | 20 | * Copyright (C) 2012 Lothar Felten <[email protected]> |
f7c2fe38 FL |
21 | * Thanks to Jan Volkering |
22 | * | |
23 | * This program is free software; you can redistribute it and/or modify | |
24 | * it under the terms of the GNU General Public License as published by | |
25 | * the Free Software Foundation; version 2 of the License. | |
26 | */ | |
27 | ||
28 | #include <linux/kernel.h> | |
29 | #include <linux/module.h> | |
30 | #include <linux/init.h> | |
31 | #include <linux/err.h> | |
32 | #include <linux/slab.h> | |
33 | #include <linux/i2c.h> | |
34 | #include <linux/hwmon.h> | |
35 | #include <linux/hwmon-sysfs.h> | |
dcd8f392 | 36 | #include <linux/jiffies.h> |
bd0ddd4d | 37 | #include <linux/of_device.h> |
31e7ad74 | 38 | #include <linux/of.h> |
509416a8 | 39 | #include <linux/delay.h> |
d38df34e | 40 | #include <linux/util_macros.h> |
a0de56c8 | 41 | #include <linux/regmap.h> |
f7c2fe38 FL |
42 | |
43 | #include <linux/platform_data/ina2xx.h> | |
44 | ||
45 | /* common register definitions */ | |
46 | #define INA2XX_CONFIG 0x00 | |
47 | #define INA2XX_SHUNT_VOLTAGE 0x01 /* readonly */ | |
48 | #define INA2XX_BUS_VOLTAGE 0x02 /* readonly */ | |
49 | #define INA2XX_POWER 0x03 /* readonly */ | |
50 | #define INA2XX_CURRENT 0x04 /* readonly */ | |
51 | #define INA2XX_CALIBRATION 0x05 | |
52 | ||
53 | /* INA226 register definitions */ | |
54 | #define INA226_MASK_ENABLE 0x06 | |
55 | #define INA226_ALERT_LIMIT 0x07 | |
56 | #define INA226_DIE_ID 0xFF | |
57 | ||
f7c2fe38 FL |
58 | /* register count */ |
59 | #define INA219_REGISTERS 6 | |
60 | #define INA226_REGISTERS 8 | |
61 | ||
62 | #define INA2XX_MAX_REGISTERS 8 | |
63 | ||
64 | /* settings - depend on use case */ | |
65 | #define INA219_CONFIG_DEFAULT 0x399F /* PGA=8 */ | |
66 | #define INA226_CONFIG_DEFAULT 0x4527 /* averages=16 */ | |
67 | ||
68 | /* worst case is 68.10 ms (~14.6Hz, ina219) */ | |
69 | #define INA2XX_CONVERSION_RATE 15 | |
509416a8 BG |
70 | #define INA2XX_MAX_DELAY 69 /* worst case delay in ms */ |
71 | ||
72 | #define INA2XX_RSHUNT_DEFAULT 10000 | |
f7c2fe38 | 73 | |
72a87a47 BG |
74 | /* bit mask for reading the averaging setting in the configuration register */ |
75 | #define INA226_AVG_RD_MASK 0x0E00 | |
76 | ||
77 | #define INA226_READ_AVG(reg) (((reg) & INA226_AVG_RD_MASK) >> 9) | |
78 | #define INA226_SHIFT_AVG(val) ((val) << 9) | |
79 | ||
80 | /* common attrs, ina226 attrs and NULL */ | |
81 | #define INA2XX_MAX_ATTRIBUTE_GROUPS 3 | |
82 | ||
83 | /* | |
84 | * Both bus voltage and shunt voltage conversion times for ina226 are set | |
85 | * to 0b0100 on POR, which translates to 2200 microseconds in total. | |
86 | */ | |
87 | #define INA226_TOTAL_CONV_TIME_DEFAULT 2200 | |
88 | ||
a0de56c8 MT |
89 | static struct regmap_config ina2xx_regmap_config = { |
90 | .reg_bits = 8, | |
91 | .val_bits = 16, | |
92 | }; | |
93 | ||
f7c2fe38 FL |
94 | enum ina2xx_ids { ina219, ina226 }; |
95 | ||
6106db25 GR |
96 | struct ina2xx_config { |
97 | u16 config_default; | |
5d389b12 | 98 | int calibration_value; |
6106db25 GR |
99 | int registers; |
100 | int shunt_div; | |
101 | int bus_voltage_shift; | |
102 | int bus_voltage_lsb; /* uV */ | |
5d389b12 | 103 | int power_lsb_factor; |
6106db25 GR |
104 | }; |
105 | ||
f7c2fe38 | 106 | struct ina2xx_data { |
6106db25 | 107 | const struct ina2xx_config *config; |
f7c2fe38 | 108 | |
509416a8 | 109 | long rshunt; |
5d389b12 MP |
110 | long current_lsb_uA; |
111 | long power_lsb_uW; | |
a0de56c8 MT |
112 | struct mutex config_lock; |
113 | struct regmap *regmap; | |
f7c2fe38 | 114 | |
72a87a47 | 115 | const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; |
f7c2fe38 FL |
116 | }; |
117 | ||
6106db25 GR |
118 | static const struct ina2xx_config ina2xx_config[] = { |
119 | [ina219] = { | |
120 | .config_default = INA219_CONFIG_DEFAULT, | |
5d389b12 | 121 | .calibration_value = 4096, |
6106db25 GR |
122 | .registers = INA219_REGISTERS, |
123 | .shunt_div = 100, | |
124 | .bus_voltage_shift = 3, | |
125 | .bus_voltage_lsb = 4000, | |
5d389b12 | 126 | .power_lsb_factor = 20, |
6106db25 GR |
127 | }, |
128 | [ina226] = { | |
129 | .config_default = INA226_CONFIG_DEFAULT, | |
5d389b12 | 130 | .calibration_value = 2048, |
6106db25 GR |
131 | .registers = INA226_REGISTERS, |
132 | .shunt_div = 400, | |
133 | .bus_voltage_shift = 0, | |
134 | .bus_voltage_lsb = 1250, | |
5d389b12 | 135 | .power_lsb_factor = 25, |
6106db25 GR |
136 | }, |
137 | }; | |
138 | ||
72a87a47 BG |
139 | /* |
140 | * Available averaging rates for ina226. The indices correspond with | |
141 | * the bit values expected by the chip (according to the ina226 datasheet, | |
142 | * table 3 AVG bit settings, found at | |
143 | * http://www.ti.com/lit/ds/symlink/ina226.pdf. | |
144 | */ | |
145 | static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 }; | |
146 | ||
72a87a47 BG |
147 | static int ina226_reg_to_interval(u16 config) |
148 | { | |
149 | int avg = ina226_avg_tab[INA226_READ_AVG(config)]; | |
150 | ||
151 | /* | |
152 | * Multiply the total conversion time by the number of averages. | |
153 | * Return the result in milliseconds. | |
154 | */ | |
155 | return DIV_ROUND_CLOSEST(avg * INA226_TOTAL_CONV_TIME_DEFAULT, 1000); | |
156 | } | |
157 | ||
a0de56c8 MT |
158 | /* |
159 | * Return the new, shifted AVG field value of CONFIG register, | |
160 | * to use with regmap_update_bits | |
161 | */ | |
162 | static u16 ina226_interval_to_reg(int interval) | |
72a87a47 BG |
163 | { |
164 | int avg, avg_bits; | |
165 | ||
166 | avg = DIV_ROUND_CLOSEST(interval * 1000, | |
167 | INA226_TOTAL_CONV_TIME_DEFAULT); | |
d38df34e BG |
168 | avg_bits = find_closest(avg, ina226_avg_tab, |
169 | ARRAY_SIZE(ina226_avg_tab)); | |
72a87a47 | 170 | |
a0de56c8 | 171 | return INA226_SHIFT_AVG(avg_bits); |
72a87a47 BG |
172 | } |
173 | ||
5d389b12 MP |
174 | /* |
175 | * Calibration register is set to the best value, which eliminates | |
176 | * truncation errors on calculating current register in hardware. | |
177 | * According to datasheet (eq. 3) the best values are 2048 for | |
178 | * ina226 and 4096 for ina219. They are hardcoded as calibration_value. | |
179 | */ | |
8a5fc795 BG |
180 | static int ina2xx_calibrate(struct ina2xx_data *data) |
181 | { | |
5d389b12 MP |
182 | return regmap_write(data->regmap, INA2XX_CALIBRATION, |
183 | data->config->calibration_value); | |
8a5fc795 BG |
184 | } |
185 | ||
509416a8 BG |
186 | /* |
187 | * Initialize the configuration and calibration registers. | |
188 | */ | |
189 | static int ina2xx_init(struct ina2xx_data *data) | |
f7c2fe38 | 190 | { |
a0de56c8 MT |
191 | int ret = regmap_write(data->regmap, INA2XX_CONFIG, |
192 | data->config->config_default); | |
509416a8 BG |
193 | if (ret < 0) |
194 | return ret; | |
f7c2fe38 | 195 | |
8a5fc795 | 196 | return ina2xx_calibrate(data); |
509416a8 | 197 | } |
f7c2fe38 | 198 | |
a0de56c8 | 199 | static int ina2xx_read_reg(struct device *dev, int reg, unsigned int *regval) |
509416a8 BG |
200 | { |
201 | struct ina2xx_data *data = dev_get_drvdata(dev); | |
a0de56c8 | 202 | int ret, retry; |
f7c2fe38 | 203 | |
a0de56c8 | 204 | dev_dbg(dev, "Starting register %d read\n", reg); |
f7c2fe38 | 205 | |
509416a8 | 206 | for (retry = 5; retry; retry--) { |
a0de56c8 MT |
207 | |
208 | ret = regmap_read(data->regmap, reg, regval); | |
209 | if (ret < 0) | |
210 | return ret; | |
211 | ||
212 | dev_dbg(dev, "read %d, val = 0x%04x\n", reg, *regval); | |
509416a8 BG |
213 | |
214 | /* | |
215 | * If the current value in the calibration register is 0, the | |
216 | * power and current registers will also remain at 0. In case | |
217 | * the chip has been reset let's check the calibration | |
218 | * register and reinitialize if needed. | |
a0de56c8 MT |
219 | * We do that extra read of the calibration register if there |
220 | * is some hint of a chip reset. | |
509416a8 | 221 | */ |
a0de56c8 MT |
222 | if (*regval == 0) { |
223 | unsigned int cal; | |
224 | ||
225 | ret = regmap_read(data->regmap, INA2XX_CALIBRATION, | |
226 | &cal); | |
227 | if (ret < 0) | |
228 | return ret; | |
229 | ||
230 | if (cal == 0) { | |
231 | dev_warn(dev, "chip not calibrated, reinitializing\n"); | |
232 | ||
233 | ret = ina2xx_init(data); | |
234 | if (ret < 0) | |
235 | return ret; | |
236 | /* | |
237 | * Let's make sure the power and current | |
238 | * registers have been updated before trying | |
239 | * again. | |
240 | */ | |
241 | msleep(INA2XX_MAX_DELAY); | |
242 | continue; | |
243 | } | |
509416a8 | 244 | } |
509416a8 | 245 | return 0; |
f7c2fe38 | 246 | } |
509416a8 BG |
247 | |
248 | /* | |
249 | * If we're here then although all write operations succeeded, the | |
250 | * chip still returns 0 in the calibration register. Nothing more we | |
251 | * can do here. | |
252 | */ | |
253 | dev_err(dev, "unable to reinitialize the chip\n"); | |
254 | return -ENODEV; | |
255 | } | |
256 | ||
a0de56c8 MT |
257 | static int ina2xx_get_value(struct ina2xx_data *data, u8 reg, |
258 | unsigned int regval) | |
f7c2fe38 | 259 | { |
6106db25 | 260 | int val; |
f7c2fe38 FL |
261 | |
262 | switch (reg) { | |
263 | case INA2XX_SHUNT_VOLTAGE: | |
c0214f98 | 264 | /* signed register */ |
a0de56c8 | 265 | val = DIV_ROUND_CLOSEST((s16)regval, data->config->shunt_div); |
f7c2fe38 FL |
266 | break; |
267 | case INA2XX_BUS_VOLTAGE: | |
a0de56c8 | 268 | val = (regval >> data->config->bus_voltage_shift) |
6106db25 GR |
269 | * data->config->bus_voltage_lsb; |
270 | val = DIV_ROUND_CLOSEST(val, 1000); | |
f7c2fe38 FL |
271 | break; |
272 | case INA2XX_POWER: | |
5d389b12 | 273 | val = regval * data->power_lsb_uW; |
f7c2fe38 FL |
274 | break; |
275 | case INA2XX_CURRENT: | |
5d389b12 | 276 | /* signed register, result in mA */ |
38cd989e | 277 | val = (s16)regval * data->current_lsb_uA; |
5d389b12 | 278 | val = DIV_ROUND_CLOSEST(val, 1000); |
f7c2fe38 | 279 | break; |
8a5fc795 | 280 | case INA2XX_CALIBRATION: |
5d389b12 | 281 | val = regval; |
8a5fc795 | 282 | break; |
f7c2fe38 FL |
283 | default: |
284 | /* programmer goofed */ | |
285 | WARN_ON_ONCE(1); | |
286 | val = 0; | |
287 | break; | |
288 | } | |
289 | ||
290 | return val; | |
291 | } | |
292 | ||
293 | static ssize_t ina2xx_show_value(struct device *dev, | |
294 | struct device_attribute *da, char *buf) | |
295 | { | |
296 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | |
a0de56c8 MT |
297 | struct ina2xx_data *data = dev_get_drvdata(dev); |
298 | unsigned int regval; | |
f7c2fe38 | 299 | |
a0de56c8 MT |
300 | int err = ina2xx_read_reg(dev, attr->index, ®val); |
301 | ||
302 | if (err < 0) | |
303 | return err; | |
f7c2fe38 | 304 | |
6106db25 | 305 | return snprintf(buf, PAGE_SIZE, "%d\n", |
a0de56c8 | 306 | ina2xx_get_value(data, attr->index, regval)); |
f7c2fe38 FL |
307 | } |
308 | ||
5d389b12 MP |
309 | /* |
310 | * In order to keep calibration register value fixed, the product | |
311 | * of current_lsb and shunt_resistor should also be fixed and equal | |
312 | * to shunt_voltage_lsb = 1 / shunt_div multiplied by 10^9 in order | |
313 | * to keep the scale. | |
314 | */ | |
315 | static int ina2xx_set_shunt(struct ina2xx_data *data, long val) | |
316 | { | |
317 | unsigned int dividend = DIV_ROUND_CLOSEST(1000000000, | |
318 | data->config->shunt_div); | |
319 | if (val <= 0 || val > dividend) | |
320 | return -EINVAL; | |
321 | ||
322 | mutex_lock(&data->config_lock); | |
323 | data->rshunt = val; | |
324 | data->current_lsb_uA = DIV_ROUND_CLOSEST(dividend, val); | |
325 | data->power_lsb_uW = data->config->power_lsb_factor * | |
326 | data->current_lsb_uA; | |
327 | mutex_unlock(&data->config_lock); | |
328 | ||
329 | return 0; | |
330 | } | |
331 | ||
3ad86700 LF |
332 | static ssize_t ina2xx_show_shunt(struct device *dev, |
333 | struct device_attribute *da, | |
334 | char *buf) | |
335 | { | |
336 | struct ina2xx_data *data = dev_get_drvdata(dev); | |
337 | ||
338 | return snprintf(buf, PAGE_SIZE, "%li\n", data->rshunt); | |
339 | } | |
340 | ||
5d389b12 MP |
341 | static ssize_t ina2xx_store_shunt(struct device *dev, |
342 | struct device_attribute *da, | |
343 | const char *buf, size_t count) | |
8a5fc795 | 344 | { |
8a5fc795 BG |
345 | unsigned long val; |
346 | int status; | |
a0de56c8 | 347 | struct ina2xx_data *data = dev_get_drvdata(dev); |
8a5fc795 BG |
348 | |
349 | status = kstrtoul(buf, 10, &val); | |
350 | if (status < 0) | |
351 | return status; | |
352 | ||
5d389b12 | 353 | status = ina2xx_set_shunt(data, val); |
8a5fc795 BG |
354 | if (status < 0) |
355 | return status; | |
8a5fc795 BG |
356 | return count; |
357 | } | |
358 | ||
72a87a47 BG |
359 | static ssize_t ina226_set_interval(struct device *dev, |
360 | struct device_attribute *da, | |
361 | const char *buf, size_t count) | |
362 | { | |
363 | struct ina2xx_data *data = dev_get_drvdata(dev); | |
364 | unsigned long val; | |
365 | int status; | |
366 | ||
72a87a47 BG |
367 | status = kstrtoul(buf, 10, &val); |
368 | if (status < 0) | |
369 | return status; | |
370 | ||
371 | if (val > INT_MAX || val == 0) | |
372 | return -EINVAL; | |
373 | ||
a0de56c8 MT |
374 | status = regmap_update_bits(data->regmap, INA2XX_CONFIG, |
375 | INA226_AVG_RD_MASK, | |
376 | ina226_interval_to_reg(val)); | |
72a87a47 BG |
377 | if (status < 0) |
378 | return status; | |
379 | ||
380 | return count; | |
381 | } | |
382 | ||
383 | static ssize_t ina226_show_interval(struct device *dev, | |
384 | struct device_attribute *da, char *buf) | |
385 | { | |
a0de56c8 MT |
386 | struct ina2xx_data *data = dev_get_drvdata(dev); |
387 | int status; | |
388 | unsigned int regval; | |
72a87a47 | 389 | |
a0de56c8 MT |
390 | status = regmap_read(data->regmap, INA2XX_CONFIG, ®val); |
391 | if (status) | |
392 | return status; | |
72a87a47 | 393 | |
a0de56c8 | 394 | return snprintf(buf, PAGE_SIZE, "%d\n", ina226_reg_to_interval(regval)); |
72a87a47 BG |
395 | } |
396 | ||
f7c2fe38 | 397 | /* shunt voltage */ |
f0df0fd9 GR |
398 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, ina2xx_show_value, NULL, |
399 | INA2XX_SHUNT_VOLTAGE); | |
f7c2fe38 FL |
400 | |
401 | /* bus voltage */ | |
f0df0fd9 GR |
402 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ina2xx_show_value, NULL, |
403 | INA2XX_BUS_VOLTAGE); | |
f7c2fe38 FL |
404 | |
405 | /* calculated current */ | |
f0df0fd9 GR |
406 | static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ina2xx_show_value, NULL, |
407 | INA2XX_CURRENT); | |
f7c2fe38 FL |
408 | |
409 | /* calculated power */ | |
f0df0fd9 GR |
410 | static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL, |
411 | INA2XX_POWER); | |
f7c2fe38 | 412 | |
8a5fc795 BG |
413 | /* shunt resistance */ |
414 | static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR, | |
3ad86700 | 415 | ina2xx_show_shunt, ina2xx_store_shunt, |
8a5fc795 BG |
416 | INA2XX_CALIBRATION); |
417 | ||
72a87a47 BG |
418 | /* update interval (ina226 only) */ |
419 | static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, | |
420 | ina226_show_interval, ina226_set_interval, 0); | |
421 | ||
f7c2fe38 | 422 | /* pointers to created device attributes */ |
468bf0e3 | 423 | static struct attribute *ina2xx_attrs[] = { |
f7c2fe38 FL |
424 | &sensor_dev_attr_in0_input.dev_attr.attr, |
425 | &sensor_dev_attr_in1_input.dev_attr.attr, | |
426 | &sensor_dev_attr_curr1_input.dev_attr.attr, | |
427 | &sensor_dev_attr_power1_input.dev_attr.attr, | |
8a5fc795 | 428 | &sensor_dev_attr_shunt_resistor.dev_attr.attr, |
f7c2fe38 FL |
429 | NULL, |
430 | }; | |
72a87a47 BG |
431 | |
432 | static const struct attribute_group ina2xx_group = { | |
433 | .attrs = ina2xx_attrs, | |
434 | }; | |
435 | ||
436 | static struct attribute *ina226_attrs[] = { | |
437 | &sensor_dev_attr_update_interval.dev_attr.attr, | |
438 | NULL, | |
439 | }; | |
440 | ||
441 | static const struct attribute_group ina226_group = { | |
442 | .attrs = ina226_attrs, | |
443 | }; | |
f7c2fe38 FL |
444 | |
445 | static int ina2xx_probe(struct i2c_client *client, | |
446 | const struct i2c_device_id *id) | |
447 | { | |
468bf0e3 GR |
448 | struct device *dev = &client->dev; |
449 | struct ina2xx_data *data; | |
450 | struct device *hwmon_dev; | |
468bf0e3 | 451 | u32 val; |
72a87a47 | 452 | int ret, group = 0; |
bd0ddd4d JMC |
453 | enum ina2xx_ids chip; |
454 | ||
455 | if (client->dev.of_node) | |
456 | chip = (enum ina2xx_ids)of_device_get_match_data(&client->dev); | |
457 | else | |
458 | chip = id->driver_data; | |
f7c2fe38 | 459 | |
468bf0e3 | 460 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
f7c2fe38 FL |
461 | if (!data) |
462 | return -ENOMEM; | |
463 | ||
f7c2fe38 | 464 | /* set the device type */ |
bd0ddd4d | 465 | data->config = &ina2xx_config[chip]; |
0c4c5860 | 466 | mutex_init(&data->config_lock); |
72a87a47 | 467 | |
001e2e73 MT |
468 | if (of_property_read_u32(dev->of_node, "shunt-resistor", &val) < 0) { |
469 | struct ina2xx_platform_data *pdata = dev_get_platdata(dev); | |
470 | ||
471 | if (pdata) | |
472 | val = pdata->shunt_uohms; | |
473 | else | |
474 | val = INA2XX_RSHUNT_DEFAULT; | |
475 | } | |
476 | ||
5d389b12 | 477 | ina2xx_set_shunt(data, val); |
001e2e73 | 478 | |
a0de56c8 MT |
479 | ina2xx_regmap_config.max_register = data->config->registers; |
480 | ||
481 | data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config); | |
482 | if (IS_ERR(data->regmap)) { | |
483 | dev_err(dev, "failed to allocate register map\n"); | |
484 | return PTR_ERR(data->regmap); | |
485 | } | |
486 | ||
509416a8 | 487 | ret = ina2xx_init(data); |
f975b339 | 488 | if (ret < 0) { |
509416a8 | 489 | dev_err(dev, "error configuring the device: %d\n", ret); |
f975b339 BG |
490 | return -ENODEV; |
491 | } | |
f7c2fe38 | 492 | |
72a87a47 | 493 | data->groups[group++] = &ina2xx_group; |
70df9ebb | 494 | if (chip == ina226) |
72a87a47 BG |
495 | data->groups[group++] = &ina226_group; |
496 | ||
468bf0e3 | 497 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
72a87a47 | 498 | data, data->groups); |
468bf0e3 GR |
499 | if (IS_ERR(hwmon_dev)) |
500 | return PTR_ERR(hwmon_dev); | |
f7c2fe38 | 501 | |
468bf0e3 | 502 | dev_info(dev, "power monitor %s (Rshunt = %li uOhm)\n", |
70df9ebb | 503 | client->name, data->rshunt); |
6106db25 | 504 | |
f7c2fe38 | 505 | return 0; |
f7c2fe38 FL |
506 | } |
507 | ||
508 | static const struct i2c_device_id ina2xx_id[] = { | |
509 | { "ina219", ina219 }, | |
dc92cd0c | 510 | { "ina220", ina219 }, |
f7c2fe38 | 511 | { "ina226", ina226 }, |
dc92cd0c | 512 | { "ina230", ina226 }, |
add513be | 513 | { "ina231", ina226 }, |
f7c2fe38 FL |
514 | { } |
515 | }; | |
516 | MODULE_DEVICE_TABLE(i2c, ina2xx_id); | |
517 | ||
bd0ddd4d JMC |
518 | static const struct of_device_id ina2xx_of_match[] = { |
519 | { | |
520 | .compatible = "ti,ina219", | |
521 | .data = (void *)ina219 | |
522 | }, | |
523 | { | |
524 | .compatible = "ti,ina220", | |
525 | .data = (void *)ina219 | |
526 | }, | |
527 | { | |
528 | .compatible = "ti,ina226", | |
529 | .data = (void *)ina226 | |
530 | }, | |
531 | { | |
532 | .compatible = "ti,ina230", | |
533 | .data = (void *)ina226 | |
534 | }, | |
535 | { | |
536 | .compatible = "ti,ina231", | |
537 | .data = (void *)ina226 | |
538 | }, | |
539 | { }, | |
540 | }; | |
541 | MODULE_DEVICE_TABLE(of, ina2xx_of_match); | |
542 | ||
f7c2fe38 FL |
543 | static struct i2c_driver ina2xx_driver = { |
544 | .driver = { | |
545 | .name = "ina2xx", | |
bd0ddd4d | 546 | .of_match_table = of_match_ptr(ina2xx_of_match), |
f7c2fe38 FL |
547 | }, |
548 | .probe = ina2xx_probe, | |
f7c2fe38 FL |
549 | .id_table = ina2xx_id, |
550 | }; | |
551 | ||
d835ca0f | 552 | module_i2c_driver(ina2xx_driver); |
f7c2fe38 FL |
553 | |
554 | MODULE_AUTHOR("Lothar Felten <[email protected]>"); | |
555 | MODULE_DESCRIPTION("ina2xx driver"); | |
556 | MODULE_LICENSE("GPL"); |