Lines Matching full:counter

3  * Generic Counter interface
7 #include <linux/counter.h>
22 #include "counter-chrdev.h"
23 #include "counter-sysfs.h"
25 #define COUNTER_NAME "counter"
27 /* Provides a unique ID for each counter device */
31 struct counter_device counter; member
43 struct counter_device *const counter = in counter_device_release() local
46 counter_chrdev_remove(counter); in counter_device_release()
49 kfree(container_of(counter, struct counter_device_allochelper, counter)); in counter_device_release()
58 .name = "counter",
59 .dev_name = "counter",
65 * counter_priv - access counter device private data
66 * @counter: counter device
68 * Get the counter device private data
70 void *counter_priv(const struct counter_device *const counter) in counter_priv() argument
73 container_of(counter, struct counter_device_allochelper, counter); in counter_priv()
77 EXPORT_SYMBOL_NS_GPL(counter_priv, "COUNTER");
83 * This is part one of counter registration. The structure is allocated
91 struct counter_device *counter; in counter_alloc() local
99 counter = &ch->counter; in counter_alloc()
100 dev = &counter->dev; in counter_alloc()
108 mutex_init(&counter->ops_exist_lock); in counter_alloc()
113 err = counter_chrdev_add(counter); in counter_alloc()
123 return counter; in counter_alloc()
127 counter_chrdev_remove(counter); in counter_alloc()
137 EXPORT_SYMBOL_NS_GPL(counter_alloc, "COUNTER");
139 void counter_put(struct counter_device *counter) in counter_put() argument
141 put_device(&counter->dev); in counter_put()
143 EXPORT_SYMBOL_NS_GPL(counter_put, "COUNTER");
146 * counter_add - complete registration of a counter
147 * @counter: the counter to add
149 * This is part two of counter registration.
153 int counter_add(struct counter_device *counter) in counter_add() argument
156 struct device *dev = &counter->dev; in counter_add()
158 if (counter->parent) { in counter_add()
159 dev->parent = counter->parent; in counter_add()
160 dev->of_node = counter->parent->of_node; in counter_add()
163 err = counter_sysfs_add(counter); in counter_add()
168 return cdev_device_add(&counter->chrdev, dev); in counter_add()
170 EXPORT_SYMBOL_NS_GPL(counter_add, "COUNTER");
173 * counter_unregister - unregister Counter from the system
174 * @counter: pointer to Counter to unregister
176 * The Counter is unregistered from the system.
178 void counter_unregister(struct counter_device *const counter) in counter_unregister() argument
180 if (!counter) in counter_unregister()
183 cdev_device_del(&counter->chrdev, &counter->dev); in counter_unregister()
185 mutex_lock(&counter->ops_exist_lock); in counter_unregister()
187 counter->ops = NULL; in counter_unregister()
188 wake_up(&counter->events_wait); in counter_unregister()
190 mutex_unlock(&counter->ops_exist_lock); in counter_unregister()
192 EXPORT_SYMBOL_NS_GPL(counter_unregister, "COUNTER");
194 static void devm_counter_release(void *counter) in devm_counter_release() argument
196 counter_unregister(counter); in devm_counter_release()
199 static void devm_counter_put(void *counter) in devm_counter_put() argument
201 counter_put(counter); in devm_counter_put()
214 struct counter_device *counter; in devm_counter_alloc() local
217 counter = counter_alloc(sizeof_priv); in devm_counter_alloc()
218 if (!counter) in devm_counter_alloc()
221 err = devm_add_action_or_reset(dev, devm_counter_put, counter); in devm_counter_alloc()
225 return counter; in devm_counter_alloc()
227 EXPORT_SYMBOL_NS_GPL(devm_counter_alloc, "COUNTER");
230 * devm_counter_add - complete registration of a counter
232 * @counter: the counter to add
238 struct counter_device *const counter) in devm_counter_add() argument
242 err = counter_add(counter); in devm_counter_add()
246 return devm_add_action_or_reset(dev, devm_counter_release, counter); in devm_counter_add()
248 EXPORT_SYMBOL_NS_GPL(devm_counter_add, "COUNTER");
282 MODULE_DESCRIPTION("Generic Counter interface");