28 #include <linux/kernel.h>
29 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/i2c.h>
41 #define INA2XX_CONFIG 0x00
42 #define INA2XX_SHUNT_VOLTAGE 0x01
43 #define INA2XX_BUS_VOLTAGE 0x02
44 #define INA2XX_POWER 0x03
45 #define INA2XX_CURRENT 0x04
46 #define INA2XX_CALIBRATION 0x05
49 #define INA226_MASK_ENABLE 0x06
50 #define INA226_ALERT_LIMIT 0x07
51 #define INA226_DIE_ID 0xFF
55 #define INA219_REGISTERS 6
56 #define INA226_REGISTERS 8
58 #define INA2XX_MAX_REGISTERS 8
61 #define INA219_CONFIG_DEFAULT 0x399F
62 #define INA226_CONFIG_DEFAULT 0x4527
65 #define INA2XX_CONVERSION_RATE 15
94 .calibration_factor = 40960000,
97 .bus_voltage_shift = 3,
98 .bus_voltage_lsb = 4000,
103 .calibration_factor = 5120000,
106 .bus_voltage_shift = 0,
107 .bus_voltage_lsb = 1250,
125 dev_dbg(&client->
dev,
"Starting ina2xx update\n");
128 for (i = 0; i < data->
config->registers; i++) {
129 int rv = i2c_smbus_read_word_swapped(client, i);
155 * data->
config->bus_voltage_lsb;
179 struct ina2xx_data *data = ina2xx_update_device(dev);
182 return PTR_ERR(data);
185 ina2xx_get_value(data, attr->
index));
205 static struct attribute *ina2xx_attributes[] = {
206 &sensor_dev_attr_in0_input.dev_attr.attr,
207 &sensor_dev_attr_in1_input.dev_attr.attr,
208 &sensor_dev_attr_curr1_input.dev_attr.attr,
209 &sensor_dev_attr_power1_input.dev_attr.attr,
214 .attrs = ina2xx_attributes,
217 static int ina2xx_probe(
struct i2c_client *client,
233 if (client->
dev.platform_data) {
243 data->
kind =
id->driver_data;
248 data->
config->config_default);
252 data->
config->calibration_factor / shunt);
254 i2c_set_clientdata(client, data);
267 dev_info(&client->
dev,
"power monitor %s (Rshunt = %li uOhm)\n",
277 static int ina2xx_remove(
struct i2c_client *client)
279 struct ina2xx_data *data = i2c_get_clientdata(client);
300 .probe = ina2xx_probe,
301 .remove = ina2xx_remove,
302 .id_table = ina2xx_id,
305 static int __init ina2xx_init(
void)
307 return i2c_add_driver(&ina2xx_driver);
310 static void __exit ina2xx_exit(
void)