#include <linux/hwmon-sysfs.h>
#include <linux/i2c.h>
#include <linux/module.h>
-#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
* @regmap: Register map of the device
* @fields: Register fields of the device
* @inputs: Array of channel input source specific structures
- * @lock: mutex lock to serialize sysfs attribute accesses
* @reg_config: Register value of INA3221_CONFIG
* @summation_shunt_resistor: equivalent shunt resistor value for summation
* @summation_channel_control: Value written to SCC field in INA3221_MASK_ENABLE
struct regmap *regmap;
struct regmap_field *fields[F_MAX_FIELDS];
struct ina3221_input inputs[INA3221_NUM_CHANNELS];
- struct mutex lock;
u32 reg_config;
int summation_shunt_resistor;
u32 summation_channel_control;
static int ina3221_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
- struct ina3221_data *ina = dev_get_drvdata(dev);
int ret;
- mutex_lock(&ina->lock);
-
switch (type) {
case hwmon_chip:
ret = ina3221_read_chip(dev, attr, val);
ret = -EOPNOTSUPP;
break;
}
-
- mutex_unlock(&ina->lock);
-
return ret;
}
static int ina3221_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long val)
{
- struct ina3221_data *ina = dev_get_drvdata(dev);
int ret;
- mutex_lock(&ina->lock);
-
switch (type) {
case hwmon_chip:
ret = ina3221_write_chip(dev, attr, val);
ret = -EOPNOTSUPP;
break;
}
-
- mutex_unlock(&ina->lock);
-
return ret;
}
}
ina->pm_dev = dev;
- mutex_init(&ina->lock);
dev_set_drvdata(dev, ina);
/* Enable PM runtime -- status is suspended by default */
/* pm_runtime_put_noidle() will decrease the PM refcount until 0 */
for (i = 0; i < INA3221_NUM_CHANNELS; i++)
pm_runtime_put_noidle(ina->pm_dev);
- mutex_destroy(&ina->lock);
return ret;
}
/* pm_runtime_put_noidle() will decrease the PM refcount until 0 */
for (i = 0; i < INA3221_NUM_CHANNELS; i++)
pm_runtime_put_noidle(ina->pm_dev);
-
- mutex_destroy(&ina->lock);
}
static int ina3221_suspend(struct device *dev)