-
Notifications
You must be signed in to change notification settings - Fork 0
/
industrialio-configfs.c
158 lines (132 loc) · 3.95 KB
/
industrialio-configfs.c
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Industrial I/O configfs bits
*
* Copyright (c) 2015 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#include <linux/configfs.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kmod.h>
#include <linux/slab.h>
#include <linux/iio/iio.h>
#include <linux/iio/sw_trigger.h>
#include <linux/iio/iio_simple_dummy.h>
static struct config_group *trigger_make_group(struct config_group *group,
const char *name)
{
struct iio_sw_trigger *t;
t = iio_sw_trigger_create(group->cg_item.ci_name, name);
if (IS_ERR(t))
return ERR_CAST(t);
config_item_set_name(&t->group.cg_item, name);
return &t->group;
}
static void trigger_drop_group(struct config_group *group,
struct config_item *item)
{
struct iio_sw_trigger *t = to_iio_sw_trigger(item);
iio_sw_trigger_destroy(t);
config_item_put(item);
}
static struct configfs_group_operations trigger_ops = {
.make_group = &trigger_make_group,
.drop_item = &trigger_drop_group,
};
static struct config_item_type iio_trigger_type_group_type = {
.ct_group_ops = &trigger_ops,
.ct_owner = THIS_MODULE,
};
static struct config_item_type iio_triggers_group_type = {
.ct_owner = THIS_MODULE,
};
static struct config_group iio_triggers_group = {
.cg_item = {
.ci_namebuf = "triggers",
.ci_type = &iio_triggers_group_type,
},
};
//---------------------------------------------------------------------------
static struct config_group *device_make_group(struct config_group *group,
const char *name)
{
iio_dummy_probe(name);
return group;
}
static void device_drop_group(struct config_group *group,
struct config_item *item)
{
printk(KERN_ALERT "%s\n", config_item_name(item));
iio_dummy_remove(config_item_name(item));
}
//---------------------------------------------------------------------------
// device ops
static struct configfs_group_operations device_ops = {
.make_group = &device_make_group,
.drop_item = &device_drop_group,
};
// Device type group type
static struct config_item_type iio_device_type_group_type = {
.ct_group_ops = &device_ops,
.ct_owner = THIS_MODULE,
};
// Group type
static struct config_item_type iio_devices_group_type = {
.ct_owner = THIS_MODULE,
};
// created with mkdir on a config_group
static struct config_group iio_devices_group = {
.cg_item = {
.ci_namebuf = "devices",
.ci_type = &iio_devices_group_type,
},
};
static struct config_group *iio_root_default_groups[] = {
&iio_triggers_group,
&iio_devices_group,
NULL
};
static struct config_item_type iio_root_group_type = {
.ct_owner = THIS_MODULE,
};
static struct configfs_subsystem iio_configfs_subsys = {
.su_group = {
.cg_item = {
.ci_namebuf = "iio",
.ci_type = &iio_root_group_type,
},
.default_groups = iio_root_default_groups,
},
.su_mutex = __MUTEX_INITIALIZER(iio_configfs_subsys.su_mutex),
};
int iio_sw_trigger_type_configfs_register(struct iio_sw_trigger_type *tt)
{
config_group_init_type_name(&tt->group, tt->name,
&iio_trigger_type_group_type);
return configfs_register_group(&iio_triggers_group, &tt->group);
}
EXPORT_SYMBOL_GPL(iio_sw_trigger_type_configfs_register);
void iio_sw_trigger_type_configfs_unregister(struct iio_sw_trigger_type *tt)
{
configfs_unregister_group(&tt->group);
}
EXPORT_SYMBOL_GPL(iio_sw_trigger_type_configfs_unregister);
static int __init iio_configfs_init(void)
{
config_group_init(&iio_triggers_group);
config_group_init(&iio_devices_group);
config_group_init(&iio_configfs_subsys.su_group);
return configfs_register_subsystem(&iio_configfs_subsys);
}
module_init(iio_configfs_init);
static void __exit iio_configfs_exit(void)
{
configfs_unregister_subsystem(&iio_configfs_subsys);
}
module_exit(iio_configfs_exit);
MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
MODULE_DESCRIPTION("Industrial I/O configfs support");
MODULE_LICENSE("GPL v2");