Minor changes

This commit is contained in:
Loic Guegan 2023-08-12 15:27:40 +02:00
parent 63656e1bd8
commit 87edbc6e4f
3 changed files with 83 additions and 2 deletions

1
.gitignore vendored
View file

@ -5,4 +5,5 @@
!Makefile
!.gitignore
!ina260.c
!inahwmon.c
!README.md

View file

@ -2,9 +2,14 @@
#LML="/usr/src/linux-headers-$(shell uname -r)/"
LML="/lib/modules/$(shell uname -r)/build/" # Change if required on your system
obj-m += ina260.o
obj-m += inahwmon.o
all: ina260.c
all: hwmon
ina260: ina260.c
make -C $(LML) M=$(PWD) modules
hwmon: inahwmon.c
make -C $(LML) M=$(PWD) modules
run: ina260.c

75
inahwmon.c Normal file
View file

@ -0,0 +1,75 @@
#include "linux/module.h"
#include "linux/kernel.h"
#include <linux/hwmon.h>
#include "linux/i2c.h"
static const struct hwmon_channel_info power = {
.type = hwmon_power,
.config = HWMON_P_INPUT
};
static const struct hwmon_channel_info * const ina260_info[] = {
&power,
NULL
};
static const struct hwmon_ops ina260_hwmon_ops = {
//.is_visible = ina238_is_visible,
.read = NULL,
.write = NULL,
};
static const struct hwmon_chip_info ina260_chip_info = {
.ops = &ina260_hwmon_ops,
.info = ina260_info,
};
static int ina260_probe_new(struct i2c_client *client){
hwmon_device_register_with_info(&client->dev,client->name,NULL,
&ina260_chip_info,NULL);
}
static int ina260_remove(struct i2c_client *client){
hwmon_device_unregister(&client->dev);
return 0;
}
static const struct i2c_device_id ina260_ids[] = {
{ "ina260", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c,ina260_ids);
static struct i2c_driver ina260_driver = {
.driver = {
.name = "ina260HWMON"
},
.probe_new = ina260_probe_new,
.remove = ina260_remove,
.id_table = ina260_ids
};
static int __init ina260_init(void){
printk("Init\n");
i2c_add_driver(&ina260_driver);
return 0;
}
static void __exit ina260_exit(void){
printk("Quit\n");
i2c_del_driver(&ina260_driver);
}
module_init(ina260_init);
module_exit(ina260_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Loïc Guegan");
MODULE_DESCRIPTION("INA260 Texas Instruments");
MODULE_VERSION("1.0");