mirror of
https://gitlab.com/manzerbredes/ina260-sysfs-driver.git
synced 2025-04-19 04:09:45 +00:00
Minor changes
This commit is contained in:
parent
87edbc6e4f
commit
b2a6cd3c65
3 changed files with 51 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,5 +5,4 @@
|
||||||
!Makefile
|
!Makefile
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!ina260.c
|
!ina260.c
|
||||||
!inahwmon.c
|
|
||||||
!README.md
|
!README.md
|
10
Makefile
10
Makefile
|
@ -20,10 +20,20 @@ run: ina260.c
|
||||||
insmod ina260.ko
|
insmod ina260.ko
|
||||||
echo ina260 0x41 > /sys/bus/i2c/devices/i2c-2/new_device
|
echo ina260 0x41 > /sys/bus/i2c/devices/i2c-2/new_device
|
||||||
|
|
||||||
|
run2: inahwmon.c
|
||||||
|
-echo 0x41 > /sys/bus/i2c/devices/i2c-2/delete_device
|
||||||
|
-rmmod inahwmon
|
||||||
|
make clean
|
||||||
|
make
|
||||||
|
insmod inahwmon.ko
|
||||||
|
echo ina260 0x41 > /sys/bus/i2c/devices/i2c-2/new_device
|
||||||
|
|
||||||
|
|
||||||
read: read.c
|
read: read.c
|
||||||
gcc $^ -o read
|
gcc $^ -o read
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ina260*.o ina260.ko ina260.mod* Module.symvers modules.order .ina260* .Module* .modules*
|
rm -f ina260*.o ina260.ko ina260.mod* Module.symvers modules.order .ina260* .Module* .modules*
|
||||||
|
rm -f inahwmon*.o inahwmon.ko inahwmon.mod* Module.symvers modules.order .inahwmon* .Module* .modules*
|
||||||
|
|
||||||
.PHONY: clean run
|
.PHONY: clean run
|
||||||
|
|
52
inahwmon.c
52
inahwmon.c
|
@ -4,21 +4,41 @@
|
||||||
#include "linux/i2c.h"
|
#include "linux/i2c.h"
|
||||||
|
|
||||||
|
|
||||||
static const struct hwmon_channel_info power = {
|
static int ina260_read(struct device *dev, enum hwmon_sensor_types type,
|
||||||
.type = hwmon_power,
|
u32 attr, int channel, long *val)
|
||||||
.config = HWMON_P_INPUT
|
{
|
||||||
};
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ina260_write(struct device *dev, enum hwmon_sensor_types type,
|
||||||
|
u32 attr, int channel, long val)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct hwmon_channel_info * const ina260_info[] = {
|
static umode_t ina260_is_visible(const void *drvdata,
|
||||||
&power,
|
enum hwmon_sensor_types type,
|
||||||
|
u32 attr, int channel){
|
||||||
|
return 0444;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HWMON_CHANNEL_INFO(stype, ...) \
|
||||||
|
(&(struct hwmon_channel_info) { \
|
||||||
|
.type = hwmon_##stype, \
|
||||||
|
.config = (u32 []) { \
|
||||||
|
__VA_ARGS__, 0 \
|
||||||
|
} \
|
||||||
|
})
|
||||||
|
|
||||||
|
static const struct hwmon_channel_info * ina260_info[] = {
|
||||||
|
HWMON_CHANNEL_INFO(power,HWMON_P_INPUT),
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct hwmon_ops ina260_hwmon_ops = {
|
static const struct hwmon_ops ina260_hwmon_ops = {
|
||||||
//.is_visible = ina238_is_visible,
|
.is_visible = ina260_is_visible,
|
||||||
.read = NULL,
|
.read = ina260_read,
|
||||||
.write = NULL,
|
.write = ina260_write,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct hwmon_chip_info ina260_chip_info = {
|
static const struct hwmon_chip_info ina260_chip_info = {
|
||||||
|
@ -26,10 +46,19 @@ static const struct hwmon_chip_info ina260_chip_info = {
|
||||||
.info = ina260_info,
|
.info = ina260_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int ina260_probe_new(struct i2c_client *client){
|
|
||||||
|
|
||||||
hwmon_device_register_with_info(&client->dev,client->name,NULL,
|
/*const struct attribute_group *extra_groups[] = {
|
||||||
|
NULL
|
||||||
|
};*/
|
||||||
|
|
||||||
|
static int ina260_probe_new(struct i2c_client *client){
|
||||||
|
struct device *hwmon_dev;
|
||||||
|
|
||||||
|
hwmon_dev=hwmon_device_register_with_info(&client->dev,client->name,NULL,
|
||||||
&ina260_chip_info,NULL);
|
&ina260_chip_info,NULL);
|
||||||
|
if (IS_ERR(hwmon_dev))
|
||||||
|
return PTR_ERR(hwmon_dev);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ina260_remove(struct i2c_client *client){
|
static int ina260_remove(struct i2c_client *client){
|
||||||
|
@ -46,6 +75,7 @@ static const struct i2c_device_id ina260_ids[] = {
|
||||||
MODULE_DEVICE_TABLE(i2c,ina260_ids);
|
MODULE_DEVICE_TABLE(i2c,ina260_ids);
|
||||||
|
|
||||||
static struct i2c_driver ina260_driver = {
|
static struct i2c_driver ina260_driver = {
|
||||||
|
.class = I2C_CLASS_HWMON,
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "ina260HWMON"
|
.name = "ina260HWMON"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue