xref: /linux/drivers/hwmon/ina209.c (revision 53597deca0e38c30e6cd4ba2114fa42d2bcd85bb)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Driver for the Texas Instruments / Burr Brown INA209
4  * Bidirectional Current/Power Monitor
5  *
6  * Copyright (C) 2012 Guenter Roeck <linux@roeck-us.net>
7  *
8  * Derived from Ira W. Snyder's original driver submission
9  *	Copyright (C) 2008 Paul Hays <Paul.Hays@cattail.ca>
10  *	Copyright (C) 2008-2009 Ira W. Snyder <iws@ovro.caltech.edu>
11  *
12  * Aligned with ina2xx driver
13  *	Copyright (C) 2012 Lothar Felten <l-felten@ti.com>
14  *	Thanks to Jan Volkering
15  *
16  * Datasheet:
17  * https://www.ti.com/lit/gpn/ina209
18  */
19 
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/err.h>
24 #include <linux/slab.h>
25 #include <linux/bug.h>
26 #include <linux/i2c.h>
27 #include <linux/hwmon.h>
28 #include <linux/hwmon-sysfs.h>
29 
30 /* register definitions */
31 #define INA209_CONFIGURATION		0x00
32 #define INA209_STATUS			0x01
33 #define INA209_STATUS_MASK		0x02
34 #define INA209_SHUNT_VOLTAGE		0x03
35 #define INA209_BUS_VOLTAGE		0x04
36 #define INA209_POWER			0x05
37 #define INA209_CURRENT			0x06
38 #define INA209_SHUNT_VOLTAGE_POS_PEAK	0x07
39 #define INA209_SHUNT_VOLTAGE_NEG_PEAK	0x08
40 #define INA209_BUS_VOLTAGE_MAX_PEAK	0x09
41 #define INA209_BUS_VOLTAGE_MIN_PEAK	0x0a
42 #define INA209_POWER_PEAK		0x0b
43 #define INA209_SHUNT_VOLTAGE_POS_WARN	0x0c
44 #define INA209_SHUNT_VOLTAGE_NEG_WARN	0x0d
45 #define INA209_POWER_WARN		0x0e
46 #define INA209_BUS_VOLTAGE_OVER_WARN	0x0f
47 #define INA209_BUS_VOLTAGE_UNDER_WARN	0x10
48 #define INA209_POWER_OVER_LIMIT		0x11
49 #define INA209_BUS_VOLTAGE_OVER_LIMIT	0x12
50 #define INA209_BUS_VOLTAGE_UNDER_LIMIT	0x13
51 #define INA209_CRITICAL_DAC_POS		0x14
52 #define INA209_CRITICAL_DAC_NEG		0x15
53 #define INA209_CALIBRATION		0x16
54 
55 #define INA209_REGISTERS		0x17
56 
57 #define INA209_CONFIG_DEFAULT		0x3c47	/* PGA=8, full range */
58 #define INA209_SHUNT_DEFAULT		10000	/* uOhm */
59 
60 struct ina209_data {
61 	struct i2c_client *client;
62 
63 	struct mutex update_lock;
64 	bool valid;
65 	unsigned long last_updated;	/* in jiffies */
66 
67 	u16 regs[INA209_REGISTERS];	/* All chip registers */
68 
69 	u16 config_orig;		/* Original configuration */
70 	u16 calibration_orig;		/* Original calibration */
71 	u16 update_interval;
72 };
73 
74 static struct ina209_data *ina209_update_device(struct device *dev)
75 {
76 	struct ina209_data *data = dev_get_drvdata(dev);
77 	struct i2c_client *client = data->client;
78 	struct ina209_data *ret = data;
79 	s32 val;
80 	int i;
81 
82 	mutex_lock(&data->update_lock);
83 
84 	if (!data->valid ||
85 	    time_after(jiffies, data->last_updated + data->update_interval)) {
86 		for (i = 0; i < ARRAY_SIZE(data->regs); i++) {
87 			val = i2c_smbus_read_word_swapped(client, i);
88 			if (val < 0) {
89 				ret = ERR_PTR(val);
90 				goto abort;
91 			}
92 			data->regs[i] = val;
93 		}
94 		data->last_updated = jiffies;
95 		data->valid = true;
96 	}
97 abort:
98 	mutex_unlock(&data->update_lock);
99 	return ret;
100 }
101 
102 /*
103  * Read a value from a device register and convert it to the
104  * appropriate sysfs units
105  */
106 static long ina209_from_reg(const u8 reg, const u16 val)
107 {
108 	switch (reg) {
109 	case INA209_SHUNT_VOLTAGE:
110 	case INA209_SHUNT_VOLTAGE_POS_PEAK:
111 	case INA209_SHUNT_VOLTAGE_NEG_PEAK:
112 	case INA209_SHUNT_VOLTAGE_POS_WARN:
113 	case INA209_SHUNT_VOLTAGE_NEG_WARN:
114 		/* LSB=10 uV. Convert to mV. */
115 		return DIV_ROUND_CLOSEST((s16)val, 100);
116 
117 	case INA209_BUS_VOLTAGE:
118 	case INA209_BUS_VOLTAGE_MAX_PEAK:
119 	case INA209_BUS_VOLTAGE_MIN_PEAK:
120 	case INA209_BUS_VOLTAGE_OVER_WARN:
121 	case INA209_BUS_VOLTAGE_UNDER_WARN:
122 	case INA209_BUS_VOLTAGE_OVER_LIMIT:
123 	case INA209_BUS_VOLTAGE_UNDER_LIMIT:
124 		/* LSB=4 mV, last 3 bits unused */
125 		return (val >> 3) * 4;
126 
127 	case INA209_CRITICAL_DAC_POS:
128 		/* LSB=1 mV, in the upper 8 bits */
129 		return val >> 8;
130 
131 	case INA209_CRITICAL_DAC_NEG:
132 		/* LSB=1 mV, in the upper 8 bits */
133 		return -1 * (val >> 8);
134 
135 	case INA209_POWER:
136 	case INA209_POWER_PEAK:
137 	case INA209_POWER_WARN:
138 	case INA209_POWER_OVER_LIMIT:
139 		/* LSB=20 mW. Convert to uW */
140 		return val * 20 * 1000L;
141 
142 	case INA209_CURRENT:
143 		/* LSB=1 mA (selected). Is in mA */
144 		return (s16)val;
145 	}
146 
147 	/* programmer goofed */
148 	WARN_ON_ONCE(1);
149 	return 0;
150 }
151 
152 /*
153  * Take a value and convert it to register format, clamping the value
154  * to the appropriate range.
155  */
156 static int ina209_to_reg(u8 reg, u16 old, long val)
157 {
158 	switch (reg) {
159 	case INA209_SHUNT_VOLTAGE_POS_WARN:
160 	case INA209_SHUNT_VOLTAGE_NEG_WARN:
161 		/* Limit to +- 320 mV, 10 uV LSB */
162 		return clamp_val(val, -320, 320) * 100;
163 
164 	case INA209_BUS_VOLTAGE_OVER_WARN:
165 	case INA209_BUS_VOLTAGE_UNDER_WARN:
166 	case INA209_BUS_VOLTAGE_OVER_LIMIT:
167 	case INA209_BUS_VOLTAGE_UNDER_LIMIT:
168 		/*
169 		 * Limit to 0-32000 mV, 4 mV LSB
170 		 *
171 		 * The last three bits aren't part of the value, but we'll
172 		 * preserve them in their original state.
173 		 */
174 		return (DIV_ROUND_CLOSEST(clamp_val(val, 0, 32000), 4) << 3)
175 		  | (old & 0x7);
176 
177 	case INA209_CRITICAL_DAC_NEG:
178 		/*
179 		 * Limit to -255-0 mV, 1 mV LSB
180 		 * Convert the value to a positive value for the register
181 		 *
182 		 * The value lives in the top 8 bits only, be careful
183 		 * and keep original value of other bits.
184 		 */
185 		return (clamp_val(-val, 0, 255) << 8) | (old & 0xff);
186 
187 	case INA209_CRITICAL_DAC_POS:
188 		/*
189 		 * Limit to 0-255 mV, 1 mV LSB
190 		 *
191 		 * The value lives in the top 8 bits only, be careful
192 		 * and keep original value of other bits.
193 		 */
194 		return (clamp_val(val, 0, 255) << 8) | (old & 0xff);
195 
196 	case INA209_POWER_WARN:
197 	case INA209_POWER_OVER_LIMIT:
198 		/* 20 mW LSB */
199 		return DIV_ROUND_CLOSEST(val, 20 * 1000);
200 	}
201 
202 	/* Other registers are read-only, return access error */
203 	return -EACCES;
204 }
205 
206 static int ina209_interval_from_reg(u16 reg)
207 {
208 	return 68 >> (15 - ((reg >> 3) & 0x0f));
209 }
210 
211 static u16 ina209_reg_from_interval(u16 config, long interval)
212 {
213 	int i, adc;
214 
215 	if (interval <= 0) {
216 		adc = 8;
217 	} else {
218 		adc = 15;
219 		for (i = 34 + 34 / 2; i; i >>= 1) {
220 			if (i < interval)
221 				break;
222 			adc--;
223 		}
224 	}
225 	return (config & 0xf807) | (adc << 3) | (adc << 7);
226 }
227 
228 static ssize_t ina209_interval_store(struct device *dev,
229 				     struct device_attribute *da,
230 				     const char *buf, size_t count)
231 {
232 	struct ina209_data *data = ina209_update_device(dev);
233 	long val;
234 	u16 regval;
235 	int ret;
236 
237 	if (IS_ERR(data))
238 		return PTR_ERR(data);
239 
240 	ret = kstrtol(buf, 10, &val);
241 	if (ret < 0)
242 		return ret;
243 
244 	mutex_lock(&data->update_lock);
245 	regval = ina209_reg_from_interval(data->regs[INA209_CONFIGURATION],
246 					  val);
247 	i2c_smbus_write_word_swapped(data->client, INA209_CONFIGURATION,
248 				     regval);
249 	data->regs[INA209_CONFIGURATION] = regval;
250 	data->update_interval = ina209_interval_from_reg(regval);
251 	mutex_unlock(&data->update_lock);
252 	return count;
253 }
254 
255 static ssize_t ina209_interval_show(struct device *dev,
256 				    struct device_attribute *da, char *buf)
257 {
258 	struct ina209_data *data = dev_get_drvdata(dev);
259 
260 	return sysfs_emit(buf, "%d\n", data->update_interval);
261 }
262 
263 /*
264  * History is reset by writing 1 into bit 0 of the respective peak register.
265  * Since more than one peak register may be affected by the scope of a
266  * reset_history attribute write, use a bit mask in attr->index to identify
267  * which registers are affected.
268  */
269 static u16 ina209_reset_history_regs[] = {
270 	INA209_SHUNT_VOLTAGE_POS_PEAK,
271 	INA209_SHUNT_VOLTAGE_NEG_PEAK,
272 	INA209_BUS_VOLTAGE_MAX_PEAK,
273 	INA209_BUS_VOLTAGE_MIN_PEAK,
274 	INA209_POWER_PEAK
275 };
276 
277 static ssize_t ina209_history_store(struct device *dev,
278 				    struct device_attribute *da,
279 				    const char *buf, size_t count)
280 {
281 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
282 	struct ina209_data *data = dev_get_drvdata(dev);
283 	struct i2c_client *client = data->client;
284 	u32 mask = attr->index;
285 	long val;
286 	int i, ret;
287 
288 	ret = kstrtol(buf, 10, &val);
289 	if (ret < 0)
290 		return ret;
291 
292 	mutex_lock(&data->update_lock);
293 	for (i = 0; i < ARRAY_SIZE(ina209_reset_history_regs); i++) {
294 		if (mask & (1 << i))
295 			i2c_smbus_write_word_swapped(client,
296 					ina209_reset_history_regs[i], 1);
297 	}
298 	data->valid = false;
299 	mutex_unlock(&data->update_lock);
300 	return count;
301 }
302 
303 static ssize_t ina209_value_store(struct device *dev,
304 				  struct device_attribute *da,
305 				  const char *buf, size_t count)
306 {
307 	struct ina209_data *data = ina209_update_device(dev);
308 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
309 	int reg = attr->index;
310 	long val;
311 	int ret;
312 
313 	if (IS_ERR(data))
314 		return PTR_ERR(data);
315 
316 	ret = kstrtol(buf, 10, &val);
317 	if (ret < 0)
318 		return ret;
319 
320 	mutex_lock(&data->update_lock);
321 	ret = ina209_to_reg(reg, data->regs[reg], val);
322 	if (ret < 0) {
323 		count = ret;
324 		goto abort;
325 	}
326 	i2c_smbus_write_word_swapped(data->client, reg, ret);
327 	data->regs[reg] = ret;
328 abort:
329 	mutex_unlock(&data->update_lock);
330 	return count;
331 }
332 
333 static ssize_t ina209_value_show(struct device *dev,
334 				 struct device_attribute *da, char *buf)
335 {
336 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
337 	struct ina209_data *data = ina209_update_device(dev);
338 	long val;
339 
340 	if (IS_ERR(data))
341 		return PTR_ERR(data);
342 
343 	val = ina209_from_reg(attr->index, data->regs[attr->index]);
344 	return sysfs_emit(buf, "%ld\n", val);
345 }
346 
347 static ssize_t ina209_alarm_show(struct device *dev,
348 				 struct device_attribute *da, char *buf)
349 {
350 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
351 	struct ina209_data *data = ina209_update_device(dev);
352 	const unsigned int mask = attr->index;
353 	u16 status;
354 
355 	if (IS_ERR(data))
356 		return PTR_ERR(data);
357 
358 	status = data->regs[INA209_STATUS];
359 
360 	/*
361 	 * All alarms are in the INA209_STATUS register. To avoid a long
362 	 * switch statement, the mask is passed in attr->index
363 	 */
364 	return sysfs_emit(buf, "%u\n", !!(status & mask));
365 }
366 
367 /* Shunt voltage, history, limits, alarms */
368 static SENSOR_DEVICE_ATTR_RO(in0_input, ina209_value, INA209_SHUNT_VOLTAGE);
369 static SENSOR_DEVICE_ATTR_RO(in0_input_highest, ina209_value,
370 			     INA209_SHUNT_VOLTAGE_POS_PEAK);
371 static SENSOR_DEVICE_ATTR_RO(in0_input_lowest, ina209_value,
372 			     INA209_SHUNT_VOLTAGE_NEG_PEAK);
373 static SENSOR_DEVICE_ATTR_WO(in0_reset_history, ina209_history,
374 			     (1 << 0) | (1 << 1));
375 static SENSOR_DEVICE_ATTR_RW(in0_max, ina209_value,
376 			     INA209_SHUNT_VOLTAGE_POS_WARN);
377 static SENSOR_DEVICE_ATTR_RW(in0_min, ina209_value,
378 			     INA209_SHUNT_VOLTAGE_NEG_WARN);
379 static SENSOR_DEVICE_ATTR_RW(in0_crit_max, ina209_value,
380 			     INA209_CRITICAL_DAC_POS);
381 static SENSOR_DEVICE_ATTR_RW(in0_crit_min, ina209_value,
382 			     INA209_CRITICAL_DAC_NEG);
383 
384 static SENSOR_DEVICE_ATTR_RO(in0_min_alarm, ina209_alarm, 1 << 11);
385 static SENSOR_DEVICE_ATTR_RO(in0_max_alarm, ina209_alarm, 1 << 12);
386 static SENSOR_DEVICE_ATTR_RO(in0_crit_min_alarm, ina209_alarm, 1 << 6);
387 static SENSOR_DEVICE_ATTR_RO(in0_crit_max_alarm, ina209_alarm, 1 << 7);
388 
389 /* Bus voltage, history, limits, alarms */
390 static SENSOR_DEVICE_ATTR_RO(in1_input, ina209_value, INA209_BUS_VOLTAGE);
391 static SENSOR_DEVICE_ATTR_RO(in1_input_highest, ina209_value,
392 			     INA209_BUS_VOLTAGE_MAX_PEAK);
393 static SENSOR_DEVICE_ATTR_RO(in1_input_lowest, ina209_value,
394 			     INA209_BUS_VOLTAGE_MIN_PEAK);
395 static SENSOR_DEVICE_ATTR_WO(in1_reset_history, ina209_history,
396 			     (1 << 2) | (1 << 3));
397 static SENSOR_DEVICE_ATTR_RW(in1_max, ina209_value,
398 			     INA209_BUS_VOLTAGE_OVER_WARN);
399 static SENSOR_DEVICE_ATTR_RW(in1_min, ina209_value,
400 			     INA209_BUS_VOLTAGE_UNDER_WARN);
401 static SENSOR_DEVICE_ATTR_RW(in1_crit_max, ina209_value,
402 			     INA209_BUS_VOLTAGE_OVER_LIMIT);
403 static SENSOR_DEVICE_ATTR_RW(in1_crit_min, ina209_value,
404 			     INA209_BUS_VOLTAGE_UNDER_LIMIT);
405 
406 static SENSOR_DEVICE_ATTR_RO(in1_min_alarm, ina209_alarm, 1 << 14);
407 static SENSOR_DEVICE_ATTR_RO(in1_max_alarm, ina209_alarm, 1 << 15);
408 static SENSOR_DEVICE_ATTR_RO(in1_crit_min_alarm, ina209_alarm, 1 << 9);
409 static SENSOR_DEVICE_ATTR_RO(in1_crit_max_alarm, ina209_alarm, 1 << 10);
410 
411 /* Power */
412 static SENSOR_DEVICE_ATTR_RO(power1_input, ina209_value, INA209_POWER);
413 static SENSOR_DEVICE_ATTR_RO(power1_input_highest, ina209_value,
414 			     INA209_POWER_PEAK);
415 static SENSOR_DEVICE_ATTR_WO(power1_reset_history, ina209_history, 1 << 4);
416 static SENSOR_DEVICE_ATTR_RW(power1_max, ina209_value, INA209_POWER_WARN);
417 static SENSOR_DEVICE_ATTR_RW(power1_crit, ina209_value,
418 			     INA209_POWER_OVER_LIMIT);
419 
420 static SENSOR_DEVICE_ATTR_RO(power1_max_alarm, ina209_alarm, 1 << 13);
421 static SENSOR_DEVICE_ATTR_RO(power1_crit_alarm, ina209_alarm, 1 << 8);
422 
423 /* Current */
424 static SENSOR_DEVICE_ATTR_RO(curr1_input, ina209_value, INA209_CURRENT);
425 
426 static SENSOR_DEVICE_ATTR_RW(update_interval, ina209_interval, 0);
427 
428 /*
429  * Finally, construct an array of pointers to members of the above objects,
430  * as required for sysfs_create_group()
431  */
432 static struct attribute *ina209_attrs[] = {
433 	&sensor_dev_attr_in0_input.dev_attr.attr,
434 	&sensor_dev_attr_in0_input_highest.dev_attr.attr,
435 	&sensor_dev_attr_in0_input_lowest.dev_attr.attr,
436 	&sensor_dev_attr_in0_reset_history.dev_attr.attr,
437 	&sensor_dev_attr_in0_max.dev_attr.attr,
438 	&sensor_dev_attr_in0_min.dev_attr.attr,
439 	&sensor_dev_attr_in0_crit_max.dev_attr.attr,
440 	&sensor_dev_attr_in0_crit_min.dev_attr.attr,
441 	&sensor_dev_attr_in0_max_alarm.dev_attr.attr,
442 	&sensor_dev_attr_in0_min_alarm.dev_attr.attr,
443 	&sensor_dev_attr_in0_crit_max_alarm.dev_attr.attr,
444 	&sensor_dev_attr_in0_crit_min_alarm.dev_attr.attr,
445 
446 	&sensor_dev_attr_in1_input.dev_attr.attr,
447 	&sensor_dev_attr_in1_input_highest.dev_attr.attr,
448 	&sensor_dev_attr_in1_input_lowest.dev_attr.attr,
449 	&sensor_dev_attr_in1_reset_history.dev_attr.attr,
450 	&sensor_dev_attr_in1_max.dev_attr.attr,
451 	&sensor_dev_attr_in1_min.dev_attr.attr,
452 	&sensor_dev_attr_in1_crit_max.dev_attr.attr,
453 	&sensor_dev_attr_in1_crit_min.dev_attr.attr,
454 	&sensor_dev_attr_in1_max_alarm.dev_attr.attr,
455 	&sensor_dev_attr_in1_min_alarm.dev_attr.attr,
456 	&sensor_dev_attr_in1_crit_max_alarm.dev_attr.attr,
457 	&sensor_dev_attr_in1_crit_min_alarm.dev_attr.attr,
458 
459 	&sensor_dev_attr_power1_input.dev_attr.attr,
460 	&sensor_dev_attr_power1_input_highest.dev_attr.attr,
461 	&sensor_dev_attr_power1_reset_history.dev_attr.attr,
462 	&sensor_dev_attr_power1_max.dev_attr.attr,
463 	&sensor_dev_attr_power1_crit.dev_attr.attr,
464 	&sensor_dev_attr_power1_max_alarm.dev_attr.attr,
465 	&sensor_dev_attr_power1_crit_alarm.dev_attr.attr,
466 
467 	&sensor_dev_attr_curr1_input.dev_attr.attr,
468 
469 	&sensor_dev_attr_update_interval.dev_attr.attr,
470 
471 	NULL,
472 };
473 ATTRIBUTE_GROUPS(ina209);
474 
475 static void ina209_restore_conf(struct i2c_client *client,
476 				struct ina209_data *data)
477 {
478 	/* Restore initial configuration */
479 	i2c_smbus_write_word_swapped(client, INA209_CONFIGURATION,
480 				     data->config_orig);
481 	i2c_smbus_write_word_swapped(client, INA209_CALIBRATION,
482 				     data->calibration_orig);
483 }
484 
485 static int ina209_init_client(struct i2c_client *client,
486 			      struct ina209_data *data)
487 {
488 	u32 shunt;
489 	int reg;
490 
491 	reg = i2c_smbus_read_word_swapped(client, INA209_CALIBRATION);
492 	if (reg < 0)
493 		return reg;
494 	data->calibration_orig = reg;
495 
496 	reg = i2c_smbus_read_word_swapped(client, INA209_CONFIGURATION);
497 	if (reg < 0)
498 		return reg;
499 	data->config_orig = reg;
500 
501 	if (!of_property_read_u32(client->dev.of_node, "shunt-resistor",
502 				  &shunt)) {
503 		if (shunt == 0)
504 			return -EINVAL;
505 	} else {
506 		shunt = data->calibration_orig ?
507 		  40960000 / data->calibration_orig : INA209_SHUNT_DEFAULT;
508 	}
509 
510 	i2c_smbus_write_word_swapped(client, INA209_CONFIGURATION,
511 				     INA209_CONFIG_DEFAULT);
512 	data->update_interval = ina209_interval_from_reg(INA209_CONFIG_DEFAULT);
513 
514 	/*
515 	 * Calibrate current LSB to 1mA. Shunt is in uOhms.
516 	 * See equation 13 in datasheet.
517 	 */
518 	i2c_smbus_write_word_swapped(client, INA209_CALIBRATION,
519 				     clamp_val(40960000 / shunt, 1, 65535));
520 
521 	/* Clear status register */
522 	i2c_smbus_read_word_swapped(client, INA209_STATUS);
523 
524 	return 0;
525 }
526 
527 static int ina209_probe(struct i2c_client *client)
528 {
529 	struct i2c_adapter *adapter = client->adapter;
530 	struct ina209_data *data;
531 	struct device *hwmon_dev;
532 	int ret;
533 
534 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
535 		return -ENODEV;
536 
537 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
538 	if (!data)
539 		return -ENOMEM;
540 
541 	i2c_set_clientdata(client, data);
542 	data->client = client;
543 	mutex_init(&data->update_lock);
544 
545 	ret = ina209_init_client(client, data);
546 	if (ret)
547 		return ret;
548 
549 	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
550 							   client->name,
551 							   data, ina209_groups);
552 	if (IS_ERR(hwmon_dev)) {
553 		ret = PTR_ERR(hwmon_dev);
554 		goto out_restore_conf;
555 	}
556 
557 	return 0;
558 
559 out_restore_conf:
560 	ina209_restore_conf(client, data);
561 	return ret;
562 }
563 
564 static void ina209_remove(struct i2c_client *client)
565 {
566 	struct ina209_data *data = i2c_get_clientdata(client);
567 
568 	ina209_restore_conf(client, data);
569 }
570 
571 static const struct i2c_device_id ina209_id[] = {
572 	{ "ina209" },
573 	{ }
574 };
575 MODULE_DEVICE_TABLE(i2c, ina209_id);
576 
577 static const struct of_device_id __maybe_unused ina209_of_match[] = {
578 	{ .compatible = "ti,ina209" },
579 	{ },
580 };
581 MODULE_DEVICE_TABLE(of, ina209_of_match);
582 
583 /* This is the driver that will be inserted */
584 static struct i2c_driver ina209_driver = {
585 	.driver = {
586 		.name	= "ina209",
587 		.of_match_table = of_match_ptr(ina209_of_match),
588 	},
589 	.probe		= ina209_probe,
590 	.remove		= ina209_remove,
591 	.id_table	= ina209_id,
592 };
593 
594 module_i2c_driver(ina209_driver);
595 
596 MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>, Paul Hays <Paul.Hays@cattail.ca>, Guenter Roeck <linux@roeck-us.net>");
597 MODULE_DESCRIPTION("INA209 driver");
598 MODULE_LICENSE("GPL");
599