Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 1 | /* |
| 2 | * INA3221 Triple Current/Voltage Monitor |
| 3 | * |
| 4 | * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ |
| 5 | * Andrew F. Davis <afd@ti.com> |
| 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 version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/hwmon.h> |
| 18 | #include <linux/hwmon-sysfs.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/module.h> |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 21 | #include <linux/mutex.h> |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 22 | #include <linux/of.h> |
| 23 | #include <linux/regmap.h> |
| 24 | |
| 25 | #define INA3221_DRIVER_NAME "ina3221" |
| 26 | |
| 27 | #define INA3221_CONFIG 0x00 |
| 28 | #define INA3221_SHUNT1 0x01 |
| 29 | #define INA3221_BUS1 0x02 |
| 30 | #define INA3221_SHUNT2 0x03 |
| 31 | #define INA3221_BUS2 0x04 |
| 32 | #define INA3221_SHUNT3 0x05 |
| 33 | #define INA3221_BUS3 0x06 |
| 34 | #define INA3221_CRIT1 0x07 |
| 35 | #define INA3221_WARN1 0x08 |
| 36 | #define INA3221_CRIT2 0x09 |
| 37 | #define INA3221_WARN2 0x0a |
| 38 | #define INA3221_CRIT3 0x0b |
| 39 | #define INA3221_WARN3 0x0c |
| 40 | #define INA3221_MASK_ENABLE 0x0f |
| 41 | |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 42 | #define INA3221_CONFIG_MODE_MASK GENMASK(2, 0) |
| 43 | #define INA3221_CONFIG_MODE_POWERDOWN 0 |
Nicolin Chen | 791ebc9 | 2018-09-29 14:44:06 -0700 | [diff] [blame] | 44 | #define INA3221_CONFIG_MODE_SHUNT BIT(0) |
| 45 | #define INA3221_CONFIG_MODE_BUS BIT(1) |
| 46 | #define INA3221_CONFIG_MODE_CONTINUOUS BIT(2) |
Nicolin Chen | 4c0415a | 2018-11-05 12:48:42 -0800 | [diff] [blame^] | 47 | #define INA3221_CONFIG_VSH_CT_SHIFT 3 |
| 48 | #define INA3221_CONFIG_VSH_CT_MASK GENMASK(5, 3) |
| 49 | #define INA3221_CONFIG_VSH_CT(x) (((x) & GENMASK(5, 3)) >> 3) |
| 50 | #define INA3221_CONFIG_VBUS_CT_SHIFT 6 |
| 51 | #define INA3221_CONFIG_VBUS_CT_MASK GENMASK(8, 6) |
| 52 | #define INA3221_CONFIG_VBUS_CT(x) (((x) & GENMASK(8, 6)) >> 6) |
| 53 | #define INA3221_CONFIG_CHs_EN_MASK GENMASK(14, 12) |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 54 | #define INA3221_CONFIG_CHx_EN(x) BIT(14 - (x)) |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 55 | |
| 56 | #define INA3221_RSHUNT_DEFAULT 10000 |
| 57 | |
| 58 | enum ina3221_fields { |
| 59 | /* Configuration */ |
| 60 | F_RST, |
| 61 | |
Nicolin Chen | 4c0415a | 2018-11-05 12:48:42 -0800 | [diff] [blame^] | 62 | /* Status Flags */ |
| 63 | F_CVRF, |
| 64 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 65 | /* Alert Flags */ |
| 66 | F_WF3, F_WF2, F_WF1, |
| 67 | F_CF3, F_CF2, F_CF1, |
| 68 | |
| 69 | /* sentinel */ |
| 70 | F_MAX_FIELDS |
| 71 | }; |
| 72 | |
| 73 | static const struct reg_field ina3221_reg_fields[] = { |
| 74 | [F_RST] = REG_FIELD(INA3221_CONFIG, 15, 15), |
| 75 | |
Nicolin Chen | 4c0415a | 2018-11-05 12:48:42 -0800 | [diff] [blame^] | 76 | [F_CVRF] = REG_FIELD(INA3221_MASK_ENABLE, 0, 0), |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 77 | [F_WF3] = REG_FIELD(INA3221_MASK_ENABLE, 3, 3), |
| 78 | [F_WF2] = REG_FIELD(INA3221_MASK_ENABLE, 4, 4), |
| 79 | [F_WF1] = REG_FIELD(INA3221_MASK_ENABLE, 5, 5), |
| 80 | [F_CF3] = REG_FIELD(INA3221_MASK_ENABLE, 7, 7), |
| 81 | [F_CF2] = REG_FIELD(INA3221_MASK_ENABLE, 8, 8), |
| 82 | [F_CF1] = REG_FIELD(INA3221_MASK_ENABLE, 9, 9), |
| 83 | }; |
| 84 | |
| 85 | enum ina3221_channels { |
| 86 | INA3221_CHANNEL1, |
| 87 | INA3221_CHANNEL2, |
| 88 | INA3221_CHANNEL3, |
| 89 | INA3221_NUM_CHANNELS |
| 90 | }; |
| 91 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 92 | /** |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 93 | * struct ina3221_input - channel input source specific information |
| 94 | * @label: label of channel input source |
| 95 | * @shunt_resistor: shunt resistor value of channel input source |
| 96 | * @disconnected: connection status of channel input source |
| 97 | */ |
| 98 | struct ina3221_input { |
| 99 | const char *label; |
| 100 | int shunt_resistor; |
| 101 | bool disconnected; |
| 102 | }; |
| 103 | |
| 104 | /** |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 105 | * struct ina3221_data - device specific information |
| 106 | * @regmap: Register map of the device |
| 107 | * @fields: Register fields of the device |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 108 | * @inputs: Array of channel input source specific structures |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 109 | * @lock: mutex lock to serialize sysfs attribute accesses |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 110 | * @reg_config: Register value of INA3221_CONFIG |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 111 | */ |
| 112 | struct ina3221_data { |
| 113 | struct regmap *regmap; |
| 114 | struct regmap_field *fields[F_MAX_FIELDS]; |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 115 | struct ina3221_input inputs[INA3221_NUM_CHANNELS]; |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 116 | struct mutex lock; |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 117 | u32 reg_config; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 118 | }; |
| 119 | |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 120 | static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel) |
| 121 | { |
| 122 | return ina->reg_config & INA3221_CONFIG_CHx_EN(channel); |
| 123 | } |
| 124 | |
Nicolin Chen | 4c0415a | 2018-11-05 12:48:42 -0800 | [diff] [blame^] | 125 | /* Lookup table for Bus and Shunt conversion times in usec */ |
| 126 | static const u16 ina3221_conv_time[] = { |
| 127 | 140, 204, 332, 588, 1100, 2116, 4156, 8244, |
| 128 | }; |
| 129 | |
| 130 | static inline int ina3221_wait_for_data(struct ina3221_data *ina) |
| 131 | { |
| 132 | u32 channels = hweight16(ina->reg_config & INA3221_CONFIG_CHs_EN_MASK); |
| 133 | u32 vbus_ct_idx = INA3221_CONFIG_VBUS_CT(ina->reg_config); |
| 134 | u32 vsh_ct_idx = INA3221_CONFIG_VSH_CT(ina->reg_config); |
| 135 | u32 vbus_ct = ina3221_conv_time[vbus_ct_idx]; |
| 136 | u32 vsh_ct = ina3221_conv_time[vsh_ct_idx]; |
| 137 | u32 wait, cvrf; |
| 138 | |
| 139 | /* Calculate total conversion time */ |
| 140 | wait = channels * (vbus_ct + vsh_ct); |
| 141 | |
| 142 | /* Polling the CVRF bit to make sure read data is ready */ |
| 143 | return regmap_field_read_poll_timeout(ina->fields[F_CVRF], |
| 144 | cvrf, cvrf, wait, 100000); |
| 145 | } |
| 146 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 147 | static int ina3221_read_value(struct ina3221_data *ina, unsigned int reg, |
| 148 | int *val) |
| 149 | { |
| 150 | unsigned int regval; |
| 151 | int ret; |
| 152 | |
| 153 | ret = regmap_read(ina->regmap, reg, ®val); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | |
| 157 | *val = sign_extend32(regval >> 3, 12); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 162 | static const u8 ina3221_in_reg[] = { |
| 163 | INA3221_BUS1, |
| 164 | INA3221_BUS2, |
| 165 | INA3221_BUS3, |
| 166 | INA3221_SHUNT1, |
| 167 | INA3221_SHUNT2, |
| 168 | INA3221_SHUNT3, |
| 169 | }; |
| 170 | |
| 171 | static int ina3221_read_in(struct device *dev, u32 attr, int channel, long *val) |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 172 | { |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 173 | const bool is_shunt = channel > INA3221_CHANNEL3; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 174 | struct ina3221_data *ina = dev_get_drvdata(dev); |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 175 | u8 reg = ina3221_in_reg[channel]; |
| 176 | int regval, ret; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 177 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 178 | /* Translate shunt channel index to sensor channel index */ |
| 179 | channel %= INA3221_NUM_CHANNELS; |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 180 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 181 | switch (attr) { |
| 182 | case hwmon_in_input: |
| 183 | if (!ina3221_is_enabled(ina, channel)) |
| 184 | return -ENODATA; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 185 | |
Nicolin Chen | 4c0415a | 2018-11-05 12:48:42 -0800 | [diff] [blame^] | 186 | ret = ina3221_wait_for_data(ina); |
| 187 | if (ret) |
| 188 | return ret; |
| 189 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 190 | ret = ina3221_read_value(ina, reg, ®val); |
| 191 | if (ret) |
| 192 | return ret; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 193 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 194 | /* |
| 195 | * Scale of shunt voltage (uV): LSB is 40uV |
| 196 | * Scale of bus voltage (mV): LSB is 8mV |
| 197 | */ |
| 198 | *val = regval * (is_shunt ? 40 : 8); |
| 199 | return 0; |
| 200 | case hwmon_in_enable: |
| 201 | *val = ina3221_is_enabled(ina, channel); |
| 202 | return 0; |
| 203 | default: |
| 204 | return -EOPNOTSUPP; |
| 205 | } |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 206 | } |
| 207 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 208 | static const u8 ina3221_curr_reg[][INA3221_NUM_CHANNELS] = { |
| 209 | [hwmon_curr_input] = { INA3221_SHUNT1, INA3221_SHUNT2, INA3221_SHUNT3 }, |
| 210 | [hwmon_curr_max] = { INA3221_WARN1, INA3221_WARN2, INA3221_WARN3 }, |
| 211 | [hwmon_curr_crit] = { INA3221_CRIT1, INA3221_CRIT2, INA3221_CRIT3 }, |
| 212 | [hwmon_curr_max_alarm] = { F_WF1, F_WF2, F_WF3 }, |
| 213 | [hwmon_curr_crit_alarm] = { F_CF1, F_CF2, F_CF3 }, |
| 214 | }; |
| 215 | |
| 216 | static int ina3221_read_curr(struct device *dev, u32 attr, |
| 217 | int channel, long *val) |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 218 | { |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 219 | struct ina3221_data *ina = dev_get_drvdata(dev); |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 220 | struct ina3221_input *input = &ina->inputs[channel]; |
| 221 | int resistance_uo = input->shunt_resistor; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 222 | u8 reg = ina3221_curr_reg[attr][channel]; |
| 223 | int regval, voltage_nv, ret; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 224 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 225 | switch (attr) { |
| 226 | case hwmon_curr_input: |
| 227 | if (!ina3221_is_enabled(ina, channel)) |
| 228 | return -ENODATA; |
Nicolin Chen | 4c0415a | 2018-11-05 12:48:42 -0800 | [diff] [blame^] | 229 | |
| 230 | ret = ina3221_wait_for_data(ina); |
| 231 | if (ret) |
| 232 | return ret; |
| 233 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 234 | /* fall through */ |
| 235 | case hwmon_curr_crit: |
| 236 | case hwmon_curr_max: |
| 237 | ret = ina3221_read_value(ina, reg, ®val); |
| 238 | if (ret) |
| 239 | return ret; |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 240 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 241 | /* Scale of shunt voltage: LSB is 40uV (40000nV) */ |
| 242 | voltage_nv = regval * 40000; |
| 243 | /* Return current in mA */ |
| 244 | *val = DIV_ROUND_CLOSEST(voltage_nv, resistance_uo); |
| 245 | return 0; |
| 246 | case hwmon_curr_crit_alarm: |
| 247 | case hwmon_curr_max_alarm: |
Nicolin Chen | efb0489 | 2018-11-05 12:48:40 -0800 | [diff] [blame] | 248 | /* No actual register read if channel is disabled */ |
| 249 | if (!ina3221_is_enabled(ina, channel)) { |
| 250 | /* Return 0 for alert flags */ |
| 251 | *val = 0; |
| 252 | return 0; |
| 253 | } |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 254 | ret = regmap_field_read(ina->fields[reg], ®val); |
| 255 | if (ret) |
| 256 | return ret; |
| 257 | *val = regval; |
| 258 | return 0; |
| 259 | default: |
| 260 | return -EOPNOTSUPP; |
| 261 | } |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 262 | } |
| 263 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 264 | static int ina3221_write_curr(struct device *dev, u32 attr, |
| 265 | int channel, long val) |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 266 | { |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 267 | struct ina3221_data *ina = dev_get_drvdata(dev); |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 268 | struct ina3221_input *input = &ina->inputs[channel]; |
| 269 | int resistance_uo = input->shunt_resistor; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 270 | u8 reg = ina3221_curr_reg[attr][channel]; |
| 271 | int regval, current_ma, voltage_uv; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 272 | |
| 273 | /* clamp current */ |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 274 | current_ma = clamp_val(val, |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 275 | INT_MIN / resistance_uo, |
| 276 | INT_MAX / resistance_uo); |
| 277 | |
| 278 | voltage_uv = DIV_ROUND_CLOSEST(current_ma * resistance_uo, 1000); |
| 279 | |
| 280 | /* clamp voltage */ |
| 281 | voltage_uv = clamp_val(voltage_uv, -163800, 163800); |
| 282 | |
| 283 | /* 1 / 40uV(scale) << 3(register shift) = 5 */ |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 284 | regval = DIV_ROUND_CLOSEST(voltage_uv, 5) & 0xfff8; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 285 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 286 | return regmap_write(ina->regmap, reg, regval); |
| 287 | } |
| 288 | |
| 289 | static int ina3221_write_enable(struct device *dev, int channel, bool enable) |
| 290 | { |
| 291 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 292 | u16 config, mask = INA3221_CONFIG_CHx_EN(channel); |
| 293 | int ret; |
| 294 | |
| 295 | config = enable ? mask : 0; |
| 296 | |
| 297 | /* Enable or disable the channel */ |
| 298 | ret = regmap_update_bits(ina->regmap, INA3221_CONFIG, mask, config); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 299 | if (ret) |
| 300 | return ret; |
| 301 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 302 | /* Cache the latest config register value */ |
| 303 | ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config); |
| 304 | if (ret) |
| 305 | return ret; |
| 306 | |
| 307 | return 0; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 310 | static int ina3221_read(struct device *dev, enum hwmon_sensor_types type, |
| 311 | u32 attr, int channel, long *val) |
| 312 | { |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 313 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 314 | int ret; |
| 315 | |
| 316 | mutex_lock(&ina->lock); |
| 317 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 318 | switch (type) { |
| 319 | case hwmon_in: |
| 320 | /* 0-align channel ID */ |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 321 | ret = ina3221_read_in(dev, attr, channel - 1, val); |
| 322 | break; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 323 | case hwmon_curr: |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 324 | ret = ina3221_read_curr(dev, attr, channel, val); |
| 325 | break; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 326 | default: |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 327 | ret = -EOPNOTSUPP; |
| 328 | break; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 329 | } |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 330 | |
| 331 | mutex_unlock(&ina->lock); |
| 332 | |
| 333 | return ret; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static int ina3221_write(struct device *dev, enum hwmon_sensor_types type, |
| 337 | u32 attr, int channel, long val) |
| 338 | { |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 339 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 340 | int ret; |
| 341 | |
| 342 | mutex_lock(&ina->lock); |
| 343 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 344 | switch (type) { |
| 345 | case hwmon_in: |
| 346 | /* 0-align channel ID */ |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 347 | ret = ina3221_write_enable(dev, channel - 1, val); |
| 348 | break; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 349 | case hwmon_curr: |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 350 | ret = ina3221_write_curr(dev, attr, channel, val); |
| 351 | break; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 352 | default: |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 353 | ret = -EOPNOTSUPP; |
| 354 | break; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 355 | } |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 356 | |
| 357 | mutex_unlock(&ina->lock); |
| 358 | |
| 359 | return ret; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int ina3221_read_string(struct device *dev, enum hwmon_sensor_types type, |
| 363 | u32 attr, int channel, const char **str) |
| 364 | { |
| 365 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 366 | int index = channel - 1; |
| 367 | |
| 368 | *str = ina->inputs[index].label; |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static umode_t ina3221_is_visible(const void *drvdata, |
| 374 | enum hwmon_sensor_types type, |
| 375 | u32 attr, int channel) |
| 376 | { |
| 377 | const struct ina3221_data *ina = drvdata; |
| 378 | const struct ina3221_input *input = NULL; |
| 379 | |
| 380 | switch (type) { |
| 381 | case hwmon_in: |
| 382 | /* Ignore in0_ */ |
| 383 | if (channel == 0) |
| 384 | return 0; |
| 385 | |
| 386 | switch (attr) { |
| 387 | case hwmon_in_label: |
| 388 | if (channel - 1 <= INA3221_CHANNEL3) |
| 389 | input = &ina->inputs[channel - 1]; |
| 390 | /* Hide label node if label is not provided */ |
| 391 | return (input && input->label) ? 0444 : 0; |
| 392 | case hwmon_in_input: |
| 393 | return 0444; |
| 394 | case hwmon_in_enable: |
| 395 | return 0644; |
| 396 | default: |
| 397 | return 0; |
| 398 | } |
| 399 | case hwmon_curr: |
| 400 | switch (attr) { |
| 401 | case hwmon_curr_input: |
| 402 | case hwmon_curr_crit_alarm: |
| 403 | case hwmon_curr_max_alarm: |
| 404 | return 0444; |
| 405 | case hwmon_curr_crit: |
| 406 | case hwmon_curr_max: |
| 407 | return 0644; |
| 408 | default: |
| 409 | return 0; |
| 410 | } |
| 411 | default: |
| 412 | return 0; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | static const u32 ina3221_in_config[] = { |
| 417 | /* 0: dummy, skipped in is_visible */ |
| 418 | HWMON_I_INPUT, |
| 419 | /* 1-3: input voltage Channels */ |
| 420 | HWMON_I_INPUT | HWMON_I_ENABLE | HWMON_I_LABEL, |
| 421 | HWMON_I_INPUT | HWMON_I_ENABLE | HWMON_I_LABEL, |
| 422 | HWMON_I_INPUT | HWMON_I_ENABLE | HWMON_I_LABEL, |
| 423 | /* 4-6: shunt voltage Channels */ |
| 424 | HWMON_I_INPUT, |
| 425 | HWMON_I_INPUT, |
| 426 | HWMON_I_INPUT, |
| 427 | 0 |
| 428 | }; |
| 429 | |
| 430 | static const struct hwmon_channel_info ina3221_in = { |
| 431 | .type = hwmon_in, |
| 432 | .config = ina3221_in_config, |
| 433 | }; |
| 434 | |
| 435 | #define INA3221_HWMON_CURR_CONFIG (HWMON_C_INPUT | \ |
| 436 | HWMON_C_CRIT | HWMON_C_CRIT_ALARM | \ |
| 437 | HWMON_C_MAX | HWMON_C_MAX_ALARM) |
| 438 | |
| 439 | static const u32 ina3221_curr_config[] = { |
| 440 | INA3221_HWMON_CURR_CONFIG, |
| 441 | INA3221_HWMON_CURR_CONFIG, |
| 442 | INA3221_HWMON_CURR_CONFIG, |
| 443 | 0 |
| 444 | }; |
| 445 | |
| 446 | static const struct hwmon_channel_info ina3221_curr = { |
| 447 | .type = hwmon_curr, |
| 448 | .config = ina3221_curr_config, |
| 449 | }; |
| 450 | |
| 451 | static const struct hwmon_channel_info *ina3221_info[] = { |
| 452 | &ina3221_in, |
| 453 | &ina3221_curr, |
| 454 | NULL |
| 455 | }; |
| 456 | |
| 457 | static const struct hwmon_ops ina3221_hwmon_ops = { |
| 458 | .is_visible = ina3221_is_visible, |
| 459 | .read_string = ina3221_read_string, |
| 460 | .read = ina3221_read, |
| 461 | .write = ina3221_write, |
| 462 | }; |
| 463 | |
| 464 | static const struct hwmon_chip_info ina3221_chip_info = { |
| 465 | .ops = &ina3221_hwmon_ops, |
| 466 | .info = ina3221_info, |
| 467 | }; |
| 468 | |
| 469 | /* Extra attribute groups */ |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 470 | static ssize_t ina3221_show_shunt(struct device *dev, |
| 471 | struct device_attribute *attr, char *buf) |
| 472 | { |
| 473 | struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); |
| 474 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 475 | unsigned int channel = sd_attr->index; |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 476 | struct ina3221_input *input = &ina->inputs[channel]; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 477 | |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 478 | return snprintf(buf, PAGE_SIZE, "%d\n", input->shunt_resistor); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static ssize_t ina3221_set_shunt(struct device *dev, |
| 482 | struct device_attribute *attr, |
| 483 | const char *buf, size_t count) |
| 484 | { |
| 485 | struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); |
| 486 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 487 | unsigned int channel = sd_attr->index; |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 488 | struct ina3221_input *input = &ina->inputs[channel]; |
Guenter Roeck | 9ad0df1 | 2016-06-24 19:41:57 -0700 | [diff] [blame] | 489 | int val; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 490 | int ret; |
| 491 | |
Guenter Roeck | 9ad0df1 | 2016-06-24 19:41:57 -0700 | [diff] [blame] | 492 | ret = kstrtoint(buf, 0, &val); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 493 | if (ret) |
| 494 | return ret; |
| 495 | |
Guenter Roeck | 9ad0df1 | 2016-06-24 19:41:57 -0700 | [diff] [blame] | 496 | val = clamp_val(val, 1, INT_MAX); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 497 | |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 498 | input->shunt_resistor = val; |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 499 | |
| 500 | return count; |
| 501 | } |
| 502 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 503 | /* shunt resistance */ |
| 504 | static SENSOR_DEVICE_ATTR(shunt1_resistor, S_IRUGO | S_IWUSR, |
| 505 | ina3221_show_shunt, ina3221_set_shunt, INA3221_CHANNEL1); |
| 506 | static SENSOR_DEVICE_ATTR(shunt2_resistor, S_IRUGO | S_IWUSR, |
| 507 | ina3221_show_shunt, ina3221_set_shunt, INA3221_CHANNEL2); |
| 508 | static SENSOR_DEVICE_ATTR(shunt3_resistor, S_IRUGO | S_IWUSR, |
| 509 | ina3221_show_shunt, ina3221_set_shunt, INA3221_CHANNEL3); |
| 510 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 511 | static struct attribute *ina3221_attrs[] = { |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 512 | &sensor_dev_attr_shunt1_resistor.dev_attr.attr, |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 513 | &sensor_dev_attr_shunt2_resistor.dev_attr.attr, |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 514 | &sensor_dev_attr_shunt3_resistor.dev_attr.attr, |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 515 | NULL, |
| 516 | }; |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 517 | ATTRIBUTE_GROUPS(ina3221); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 518 | |
| 519 | static const struct regmap_range ina3221_yes_ranges[] = { |
Nicolin Chen | c20217b | 2018-09-29 14:44:05 -0700 | [diff] [blame] | 520 | regmap_reg_range(INA3221_CONFIG, INA3221_BUS3), |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 521 | regmap_reg_range(INA3221_MASK_ENABLE, INA3221_MASK_ENABLE), |
| 522 | }; |
| 523 | |
| 524 | static const struct regmap_access_table ina3221_volatile_table = { |
| 525 | .yes_ranges = ina3221_yes_ranges, |
| 526 | .n_yes_ranges = ARRAY_SIZE(ina3221_yes_ranges), |
| 527 | }; |
| 528 | |
| 529 | static const struct regmap_config ina3221_regmap_config = { |
| 530 | .reg_bits = 8, |
| 531 | .val_bits = 16, |
| 532 | |
| 533 | .cache_type = REGCACHE_RBTREE, |
| 534 | .volatile_table = &ina3221_volatile_table, |
| 535 | }; |
| 536 | |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 537 | static int ina3221_probe_child_from_dt(struct device *dev, |
| 538 | struct device_node *child, |
| 539 | struct ina3221_data *ina) |
| 540 | { |
| 541 | struct ina3221_input *input; |
| 542 | u32 val; |
| 543 | int ret; |
| 544 | |
| 545 | ret = of_property_read_u32(child, "reg", &val); |
| 546 | if (ret) { |
| 547 | dev_err(dev, "missing reg property of %s\n", child->name); |
| 548 | return ret; |
| 549 | } else if (val > INA3221_CHANNEL3) { |
| 550 | dev_err(dev, "invalid reg %d of %s\n", val, child->name); |
| 551 | return ret; |
| 552 | } |
| 553 | |
| 554 | input = &ina->inputs[val]; |
| 555 | |
| 556 | /* Log the disconnected channel input */ |
| 557 | if (!of_device_is_available(child)) { |
| 558 | input->disconnected = true; |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /* Save the connected input label if available */ |
| 563 | of_property_read_string(child, "label", &input->label); |
| 564 | |
| 565 | /* Overwrite default shunt resistor value optionally */ |
Nicolin Chen | a6e4326 | 2018-10-08 14:24:51 -0700 | [diff] [blame] | 566 | if (!of_property_read_u32(child, "shunt-resistor-micro-ohms", &val)) { |
| 567 | if (val < 1 || val > INT_MAX) { |
| 568 | dev_err(dev, "invalid shunt resistor value %u of %s\n", |
| 569 | val, child->name); |
| 570 | return -EINVAL; |
| 571 | } |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 572 | input->shunt_resistor = val; |
Nicolin Chen | a6e4326 | 2018-10-08 14:24:51 -0700 | [diff] [blame] | 573 | } |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina) |
| 579 | { |
| 580 | const struct device_node *np = dev->of_node; |
| 581 | struct device_node *child; |
| 582 | int ret; |
| 583 | |
| 584 | /* Compatible with non-DT platforms */ |
| 585 | if (!np) |
| 586 | return 0; |
| 587 | |
| 588 | for_each_child_of_node(np, child) { |
| 589 | ret = ina3221_probe_child_from_dt(dev, child, ina); |
| 590 | if (ret) |
| 591 | return ret; |
| 592 | } |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 597 | static int ina3221_probe(struct i2c_client *client, |
| 598 | const struct i2c_device_id *id) |
| 599 | { |
| 600 | struct device *dev = &client->dev; |
| 601 | struct ina3221_data *ina; |
| 602 | struct device *hwmon_dev; |
| 603 | int i, ret; |
| 604 | |
| 605 | ina = devm_kzalloc(dev, sizeof(*ina), GFP_KERNEL); |
| 606 | if (!ina) |
| 607 | return -ENOMEM; |
| 608 | |
| 609 | ina->regmap = devm_regmap_init_i2c(client, &ina3221_regmap_config); |
| 610 | if (IS_ERR(ina->regmap)) { |
| 611 | dev_err(dev, "Unable to allocate register map\n"); |
| 612 | return PTR_ERR(ina->regmap); |
| 613 | } |
| 614 | |
| 615 | for (i = 0; i < F_MAX_FIELDS; i++) { |
| 616 | ina->fields[i] = devm_regmap_field_alloc(dev, |
| 617 | ina->regmap, |
| 618 | ina3221_reg_fields[i]); |
| 619 | if (IS_ERR(ina->fields[i])) { |
| 620 | dev_err(dev, "Unable to allocate regmap fields\n"); |
| 621 | return PTR_ERR(ina->fields[i]); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | for (i = 0; i < INA3221_NUM_CHANNELS; i++) |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 626 | ina->inputs[i].shunt_resistor = INA3221_RSHUNT_DEFAULT; |
| 627 | |
| 628 | ret = ina3221_probe_from_dt(dev, ina); |
| 629 | if (ret) { |
| 630 | dev_err(dev, "Unable to probe from device tree\n"); |
| 631 | return ret; |
| 632 | } |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 633 | |
| 634 | ret = regmap_field_write(ina->fields[F_RST], true); |
| 635 | if (ret) { |
| 636 | dev_err(dev, "Unable to reset device\n"); |
| 637 | return ret; |
| 638 | } |
| 639 | |
Nicolin Chen | a9e9dd9 | 2018-10-01 18:05:23 -0700 | [diff] [blame] | 640 | /* Sync config register after reset */ |
| 641 | ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config); |
| 642 | if (ret) |
| 643 | return ret; |
| 644 | |
| 645 | /* Disable channels if their inputs are disconnected */ |
| 646 | for (i = 0; i < INA3221_NUM_CHANNELS; i++) { |
| 647 | if (ina->inputs[i].disconnected) |
| 648 | ina->reg_config &= ~INA3221_CONFIG_CHx_EN(i); |
| 649 | } |
| 650 | ret = regmap_write(ina->regmap, INA3221_CONFIG, ina->reg_config); |
| 651 | if (ret) |
| 652 | return ret; |
| 653 | |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 654 | mutex_init(&ina->lock); |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 655 | dev_set_drvdata(dev, ina); |
| 656 | |
Nicolin Chen | d4b0166 | 2018-10-08 13:14:24 -0700 | [diff] [blame] | 657 | hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, ina, |
| 658 | &ina3221_chip_info, |
| 659 | ina3221_groups); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 660 | if (IS_ERR(hwmon_dev)) { |
| 661 | dev_err(dev, "Unable to register hwmon device\n"); |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 662 | mutex_destroy(&ina->lock); |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 663 | return PTR_ERR(hwmon_dev); |
| 664 | } |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 669 | static int ina3221_remove(struct i2c_client *client) |
| 670 | { |
| 671 | struct ina3221_data *ina = dev_get_drvdata(&client->dev); |
| 672 | |
| 673 | mutex_destroy(&ina->lock); |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
Arnd Bergmann | ead21c7 | 2018-10-02 23:10:47 +0200 | [diff] [blame] | 678 | static int __maybe_unused ina3221_suspend(struct device *dev) |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 679 | { |
| 680 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 681 | int ret; |
| 682 | |
| 683 | /* Save config register value and enable cache-only */ |
| 684 | ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config); |
| 685 | if (ret) |
| 686 | return ret; |
| 687 | |
| 688 | /* Set to power-down mode for power saving */ |
| 689 | ret = regmap_update_bits(ina->regmap, INA3221_CONFIG, |
| 690 | INA3221_CONFIG_MODE_MASK, |
| 691 | INA3221_CONFIG_MODE_POWERDOWN); |
| 692 | if (ret) |
| 693 | return ret; |
| 694 | |
| 695 | regcache_cache_only(ina->regmap, true); |
| 696 | regcache_mark_dirty(ina->regmap); |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
Arnd Bergmann | ead21c7 | 2018-10-02 23:10:47 +0200 | [diff] [blame] | 701 | static int __maybe_unused ina3221_resume(struct device *dev) |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 702 | { |
| 703 | struct ina3221_data *ina = dev_get_drvdata(dev); |
| 704 | int ret; |
| 705 | |
| 706 | regcache_cache_only(ina->regmap, false); |
| 707 | |
| 708 | /* Software reset the chip */ |
| 709 | ret = regmap_field_write(ina->fields[F_RST], true); |
| 710 | if (ret) { |
| 711 | dev_err(dev, "Unable to reset device\n"); |
| 712 | return ret; |
| 713 | } |
| 714 | |
| 715 | /* Restore cached register values to hardware */ |
| 716 | ret = regcache_sync(ina->regmap); |
| 717 | if (ret) |
| 718 | return ret; |
| 719 | |
| 720 | /* Restore config register value to hardware */ |
| 721 | ret = regmap_write(ina->regmap, INA3221_CONFIG, ina->reg_config); |
| 722 | if (ret) |
| 723 | return ret; |
| 724 | |
| 725 | return 0; |
| 726 | } |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 727 | |
| 728 | static const struct dev_pm_ops ina3221_pm = { |
| 729 | SET_SYSTEM_SLEEP_PM_OPS(ina3221_suspend, ina3221_resume) |
| 730 | }; |
| 731 | |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 732 | static const struct of_device_id ina3221_of_match_table[] = { |
| 733 | { .compatible = "ti,ina3221", }, |
| 734 | { /* sentinel */ } |
| 735 | }; |
| 736 | MODULE_DEVICE_TABLE(of, ina3221_of_match_table); |
| 737 | |
| 738 | static const struct i2c_device_id ina3221_ids[] = { |
| 739 | { "ina3221", 0 }, |
| 740 | { /* sentinel */ } |
| 741 | }; |
| 742 | MODULE_DEVICE_TABLE(i2c, ina3221_ids); |
| 743 | |
| 744 | static struct i2c_driver ina3221_i2c_driver = { |
| 745 | .probe = ina3221_probe, |
Nicolin Chen | 87625b2 | 2018-11-05 12:48:41 -0800 | [diff] [blame] | 746 | .remove = ina3221_remove, |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 747 | .driver = { |
| 748 | .name = INA3221_DRIVER_NAME, |
| 749 | .of_match_table = ina3221_of_match_table, |
Nicolin Chen | 59d608e | 2018-09-29 14:44:07 -0700 | [diff] [blame] | 750 | .pm = &ina3221_pm, |
Andrew F. Davis | 7cb6dcf | 2016-06-10 10:32:33 -0500 | [diff] [blame] | 751 | }, |
| 752 | .id_table = ina3221_ids, |
| 753 | }; |
| 754 | module_i2c_driver(ina3221_i2c_driver); |
| 755 | |
| 756 | MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); |
| 757 | MODULE_DESCRIPTION("Texas Instruments INA3221 HWMon Driver"); |
| 758 | MODULE_LICENSE("GPL v2"); |