summaryrefslogtreecommitdiff
path: root/inahwmon.c
blob: cce108d43da495e189cb20972925ac9f88674a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "linux/module.h"
#include "linux/kernel.h"
#include <linux/hwmon.h>
#include "linux/i2c.h"


static int ina260_read(struct device *dev, enum hwmon_sensor_types type,
		       u32 attr, int channel, long *val)
{
    *val=5;
	return 0;
}

static int ina260_write(struct device *dev, enum hwmon_sensor_types type,
		       u32 attr, int channel, long val)
{
    return 0;
}

static umode_t ina260_is_visible(const void *drvdata,
				 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
};

static const struct hwmon_ops ina260_hwmon_ops = {
    .is_visible = ina260_is_visible,
	.read = ina260_read,
	.write = ina260_write,
};

static const struct hwmon_chip_info ina260_chip_info = {
	.ops = &ina260_hwmon_ops,
	.info = ina260_info,
};


/*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);
	if (IS_ERR(hwmon_dev))
		return PTR_ERR(hwmon_dev);
    return 0;
}

static int ina260_remove(struct i2c_client *client){
	printk("Unregister client...\n");
    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 = {
    .class		= I2C_CLASS_HWMON,
	.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");