Minor changes

This commit is contained in:
Loic Guegan 2023-08-14 19:17:48 +02:00
parent c66f086e89
commit 2223403c81

View file

@ -71,6 +71,7 @@ static int ina260_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
{
int rvalue, reg, err;
struct client_data *cdata = dev_get_drvdata(dev);
switch (type) {
case hwmon_power:
reg = INA260_REG_POWER;
@ -85,13 +86,12 @@ static int ina260_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
return -EOPNOTSUPP;
}
err = regmap_read(cdata->regmap, reg, &rvalue);
if (err < 0) {
if (err < 0)
return err;
} else if (type == hwmon_power) {
else if (type == hwmon_power)
*val = rvalue * 10000;
} else {
else
*val = div_u64(rvalue * 25, 100) + rvalue;
}
return 0;
}
@ -118,17 +118,18 @@ INA260_REG_STORE(mask_enable, INA260_REG_MASKENABLE)
INA260_REG_STORE(alert_limit, INA260_REG_ALERTLIMIT)
static umode_t ina260_hwmon_is_visible(const void *drvdata,
enum hwmon_sensor_types type,
u32 attr, int channel)
enum hwmon_sensor_types type, u32 attr, int channel)
{
return 0444;
}
static const struct hwmon_channel_info *ina260_hwmon_info[] = {
HWMON_CHANNEL_INFO(in, HWMON_I_INPUT),
HWMON_CHANNEL_INFO(power, HWMON_P_INPUT),
HWMON_CHANNEL_INFO(curr, HWMON_C_INPUT),
NULL
};
static const struct hwmon_ops ina260_hwmon_ops = {
.is_visible = ina260_hwmon_is_visible,
.read = ina260_hwmon_read,
@ -139,6 +140,7 @@ static const struct hwmon_chip_info ina260_chip_info = {
.ops = &ina260_hwmon_ops,
.info = ina260_hwmon_info,
};
// ----- Registers -----
static DEVICE_ATTR_RW(configuration);
static DEVICE_ATTR_RW(curr);
@ -175,7 +177,8 @@ static int ina260_probe_new(struct i2c_client *client)
struct device *hwmon_dev;
// Initialize client data:
printk("Adding ina260 [bus=%d address=0x%02x]\n", client->adapter->nr, client->addr);
printk(KERN_INFO "Adding ina260 [bus=%d address=0x%02x]\n",
client->adapter->nr, client->addr);
p = kzalloc(sizeof(struct client_data), GFP_KERNEL);
p->client = client;
p->regmap = devm_regmap_init_i2c(client, &ina260_regmap_config);
@ -190,9 +193,10 @@ static int ina260_probe_new(struct i2c_client *client)
static void ina260_remove(struct i2c_client *client)
{
struct client_data *p = i2c_get_clientdata(client);
kfree(p);
hwmon_device_unregister(&client->dev);
printk("Removing ina260 [bus=%d address=0x%02x]\n", client->adapter->nr, client->addr);
printk(KERN_INFO "Removing ina260 [bus=%d address=0x%02x]\n", client->adapter->nr, client->addr);
}
static const struct i2c_device_id ina260_ids[] = {