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
42 struct counter_device *const counter = in counter_device_release() local
45 counter_chrdev_remove(counter); in counter_device_release()
48 kfree(container_of(counter, struct counter_device_allochelper, counter)); in counter_device_release()
57 .name = "counter",
58 .dev_name = "counter",
64 * counter_priv - access counter device private data
65 * @counter: counter device
67 * Get the counter device private data
69 void *counter_priv(const struct counter_device *const counter) in counter_priv() argument
72 container_of(counter, struct counter_device_allochelper, counter); in counter_priv()
76 EXPORT_SYMBOL_NS_GPL(counter_priv, COUNTER);
82 * This is part one of counter registration. The structure is allocated
90 struct counter_device *counter; in counter_alloc() local
98 counter = &ch->counter; in counter_alloc()
99 dev = &counter->dev; in counter_alloc()
107 mutex_init(&counter->ops_exist_lock); in counter_alloc()
112 err = counter_chrdev_add(counter); in counter_alloc()
122 return counter; in counter_alloc()
126 counter_chrdev_remove(counter); in counter_alloc()
136 EXPORT_SYMBOL_NS_GPL(counter_alloc, COUNTER);
138 void counter_put(struct counter_device *counter) in counter_put() argument
140 put_device(&counter->dev); in counter_put()
142 EXPORT_SYMBOL_NS_GPL(counter_put, COUNTER);
145 * counter_add - complete registration of a counter
146 * @counter: the counter to add
148 * This is part two of counter registration.
152 int counter_add(struct counter_device *counter) in counter_add() argument
155 struct device *dev = &counter->dev; in counter_add()
157 if (counter->parent) { in counter_add()
158 dev->parent = counter->parent; in counter_add()
159 dev->of_node = counter->parent->of_node; in counter_add()
162 err = counter_sysfs_add(counter); in counter_add()
167 return cdev_device_add(&counter->chrdev, dev); in counter_add()
169 EXPORT_SYMBOL_NS_GPL(counter_add, COUNTER);
172 * counter_unregister - unregister Counter from the system
173 * @counter: pointer to Counter to unregister
175 * The Counter is unregistered from the system.
177 void counter_unregister(struct counter_device *const counter) in counter_unregister() argument
179 if (!counter) in counter_unregister()
182 cdev_device_del(&counter->chrdev, &counter->dev); in counter_unregister()
184 mutex_lock(&counter->ops_exist_lock); in counter_unregister()
186 counter->ops = NULL; in counter_unregister()
187 wake_up(&counter->events_wait); in counter_unregister()
189 mutex_unlock(&counter->ops_exist_lock); in counter_unregister()
191 EXPORT_SYMBOL_NS_GPL(counter_unregister, COUNTER);
193 static void devm_counter_release(void *counter) in devm_counter_release() argument
195 counter_unregister(counter); in devm_counter_release()
198 static void devm_counter_put(void *counter) in devm_counter_put() argument
200 counter_put(counter); in devm_counter_put()
213 struct counter_device *counter; in devm_counter_alloc() local
216 counter = counter_alloc(sizeof_priv); in devm_counter_alloc()
217 if (!counter) in devm_counter_alloc()
220 err = devm_add_action_or_reset(dev, devm_counter_put, counter); in devm_counter_alloc()
224 return counter; in devm_counter_alloc()
226 EXPORT_SYMBOL_NS_GPL(devm_counter_alloc, COUNTER);
229 * devm_counter_add - complete registration of a counter
231 * @counter: the counter to add
237 struct counter_device *const counter) in devm_counter_add() argument
241 err = counter_add(counter); in devm_counter_add()
245 return devm_add_action_or_reset(dev, devm_counter_release, counter); in devm_counter_add()
247 EXPORT_SYMBOL_NS_GPL(devm_counter_add, COUNTER);
281 MODULE_DESCRIPTION("Generic Counter interface");