Lines Matching +full:current +full:- +full:sense +full:- +full:shunt

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Linear Technology LTC4151 High Voltage I2C Current
25 #include <linux/hwmon-sysfs.h>
42 unsigned int shunt; /* in micro ohms */ member
51 struct i2c_client *client = data->client; in ltc4151_update_device()
54 mutex_lock(&data->update_lock); in ltc4151_update_device()
58 * (Conversion Rate 6 - 9 Hz) in ltc4151_update_device()
60 if (time_after(jiffies, data->last_updated + HZ / 6) || !data->valid) { in ltc4151_update_device()
63 dev_dbg(&client->dev, "Starting ltc4151 update\n"); in ltc4151_update_device()
66 for (i = 0; i < ARRAY_SIZE(data->regs); i++) { in ltc4151_update_device()
77 data->regs[i] = val; in ltc4151_update_device()
79 data->last_updated = jiffies; in ltc4151_update_device()
80 data->valid = true; in ltc4151_update_device()
83 mutex_unlock(&data->update_lock); in ltc4151_update_device()
92 val = (data->regs[reg] << 4) + (data->regs[reg + 1] >> 4); in ltc4151_get_value()
101 * 20uV resolution. Convert to current as measured with in ltc4151_get_value()
102 * a given sense resistor, in mA. in ltc4151_get_value()
104 val = val * 20 * 1000 / data->shunt; in ltc4151_get_value()
130 value = ltc4151_get_value(data, attr->index); in ltc4151_value_show()
140 /* Currents (via sense resistor) */
159 struct i2c_adapter *adapter = client->adapter; in ltc4151_probe()
160 struct device *dev = &client->dev; in ltc4151_probe()
163 u32 shunt; in ltc4151_probe() local
166 return -ENODEV; in ltc4151_probe()
170 return -ENOMEM; in ltc4151_probe()
172 if (of_property_read_u32(client->dev.of_node, in ltc4151_probe()
173 "shunt-resistor-micro-ohms", &shunt)) in ltc4151_probe()
174 shunt = 1000; /* 1 mOhm if not set via DT */ in ltc4151_probe()
176 if (shunt == 0) in ltc4151_probe()
177 return -EINVAL; in ltc4151_probe()
179 data->shunt = shunt; in ltc4151_probe()
181 data->client = client; in ltc4151_probe()
182 mutex_init(&data->update_lock); in ltc4151_probe()
184 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in ltc4151_probe()