Lines Matching refs:counter
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;
42 struct counter_device *const counter =
45 counter_chrdev_remove(counter);
48 kfree(container_of(counter, struct counter_device_allochelper, counter));
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)
72 container_of(counter, struct counter_device_allochelper, counter);
82 * This is part one of counter registration. The structure is allocated
90 struct counter_device *counter;
98 counter = &ch->counter;
99 dev = &counter->dev;
107 mutex_init(&counter->ops_exist_lock);
112 err = counter_chrdev_add(counter);
122 return counter;
126 counter_chrdev_remove(counter);
138 void counter_put(struct counter_device *counter)
140 put_device(&counter->dev);
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)
155 struct device *dev = &counter->dev;
157 if (counter->parent) {
158 dev->parent = counter->parent;
159 dev->of_node = counter->parent->of_node;
162 err = counter_sysfs_add(counter);
167 return cdev_device_add(&counter->chrdev, dev);
173 * @counter: pointer to Counter to unregister
177 void counter_unregister(struct counter_device *const counter)
179 if (!counter)
182 cdev_device_del(&counter->chrdev, &counter->dev);
184 mutex_lock(&counter->ops_exist_lock);
186 counter->ops = NULL;
187 wake_up(&counter->events_wait);
189 mutex_unlock(&counter->ops_exist_lock);
193 static void devm_counter_release(void *counter)
195 counter_unregister(counter);
198 static void devm_counter_put(void *counter)
200 counter_put(counter);
213 struct counter_device *counter;
216 counter = counter_alloc(sizeof_priv);
217 if (!counter)
220 err = devm_add_action_or_reset(dev, devm_counter_put, counter);
224 return counter;
229 * devm_counter_add - complete registration of a counter
231 * @counter: the counter to add
237 struct counter_device *const counter)
241 err = counter_add(counter);
245 return devm_add_action_or_reset(dev, devm_counter_release, counter);