mirror of
https://gitlab.com/manzerbredes/ina260-sysfs-driver.git
synced 2025-06-06 14:47:40 +00:00
Minor changes
This commit is contained in:
parent
c66f086e89
commit
2223403c81
1 changed files with 57 additions and 53 deletions
20
ina260.c
20
ina260.c
|
@ -71,6 +71,7 @@ static int ina260_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
|
||||||
{
|
{
|
||||||
int rvalue, reg, err;
|
int rvalue, reg, err;
|
||||||
struct client_data *cdata = dev_get_drvdata(dev);
|
struct client_data *cdata = dev_get_drvdata(dev);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case hwmon_power:
|
case hwmon_power:
|
||||||
reg = INA260_REG_POWER;
|
reg = INA260_REG_POWER;
|
||||||
|
@ -85,13 +86,12 @@ static int ina260_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
err = regmap_read(cdata->regmap, reg, &rvalue);
|
err = regmap_read(cdata->regmap, reg, &rvalue);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
} else if (type == hwmon_power) {
|
else if (type == hwmon_power)
|
||||||
*val = rvalue * 10000;
|
*val = rvalue * 10000;
|
||||||
} else {
|
else
|
||||||
*val = div_u64(rvalue * 25, 100) + rvalue;
|
*val = div_u64(rvalue * 25, 100) + rvalue;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,17 +118,18 @@ INA260_REG_STORE(mask_enable, INA260_REG_MASKENABLE)
|
||||||
INA260_REG_STORE(alert_limit, INA260_REG_ALERTLIMIT)
|
INA260_REG_STORE(alert_limit, INA260_REG_ALERTLIMIT)
|
||||||
|
|
||||||
static umode_t ina260_hwmon_is_visible(const void *drvdata,
|
static umode_t ina260_hwmon_is_visible(const void *drvdata,
|
||||||
enum hwmon_sensor_types type,
|
enum hwmon_sensor_types type, u32 attr, int channel)
|
||||||
u32 attr, int channel)
|
|
||||||
{
|
{
|
||||||
return 0444;
|
return 0444;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct hwmon_channel_info *ina260_hwmon_info[] = {
|
static const struct hwmon_channel_info *ina260_hwmon_info[] = {
|
||||||
HWMON_CHANNEL_INFO(in, HWMON_I_INPUT),
|
HWMON_CHANNEL_INFO(in, HWMON_I_INPUT),
|
||||||
HWMON_CHANNEL_INFO(power, HWMON_P_INPUT),
|
HWMON_CHANNEL_INFO(power, HWMON_P_INPUT),
|
||||||
HWMON_CHANNEL_INFO(curr, HWMON_C_INPUT),
|
HWMON_CHANNEL_INFO(curr, HWMON_C_INPUT),
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct hwmon_ops ina260_hwmon_ops = {
|
static const struct hwmon_ops ina260_hwmon_ops = {
|
||||||
.is_visible = ina260_hwmon_is_visible,
|
.is_visible = ina260_hwmon_is_visible,
|
||||||
.read = ina260_hwmon_read,
|
.read = ina260_hwmon_read,
|
||||||
|
@ -139,6 +140,7 @@ static const struct hwmon_chip_info ina260_chip_info = {
|
||||||
.ops = &ina260_hwmon_ops,
|
.ops = &ina260_hwmon_ops,
|
||||||
.info = ina260_hwmon_info,
|
.info = ina260_hwmon_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----- Registers -----
|
// ----- Registers -----
|
||||||
static DEVICE_ATTR_RW(configuration);
|
static DEVICE_ATTR_RW(configuration);
|
||||||
static DEVICE_ATTR_RW(curr);
|
static DEVICE_ATTR_RW(curr);
|
||||||
|
@ -175,7 +177,8 @@ static int ina260_probe_new(struct i2c_client *client)
|
||||||
struct device *hwmon_dev;
|
struct device *hwmon_dev;
|
||||||
|
|
||||||
// Initialize client data:
|
// 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 = kzalloc(sizeof(struct client_data), GFP_KERNEL);
|
||||||
p->client = client;
|
p->client = client;
|
||||||
p->regmap = devm_regmap_init_i2c(client, &ina260_regmap_config);
|
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)
|
static void ina260_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
struct client_data *p = i2c_get_clientdata(client);
|
struct client_data *p = i2c_get_clientdata(client);
|
||||||
|
|
||||||
kfree(p);
|
kfree(p);
|
||||||
hwmon_device_unregister(&client->dev);
|
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[] = {
|
static const struct i2c_device_id ina260_ids[] = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue