Lines Matching refs:gdev
38 struct gnss_device *gdev; in gnss_open() local
41 gdev = container_of(inode->i_cdev, struct gnss_device, cdev); in gnss_open()
43 get_device(&gdev->dev); in gnss_open()
46 file->private_data = gdev; in gnss_open()
48 down_write(&gdev->rwsem); in gnss_open()
49 if (gdev->disconnected) { in gnss_open()
54 if (gdev->count++ == 0) { in gnss_open()
55 ret = gdev->ops->open(gdev); in gnss_open()
57 gdev->count--; in gnss_open()
60 up_write(&gdev->rwsem); in gnss_open()
63 put_device(&gdev->dev); in gnss_open()
70 struct gnss_device *gdev = file->private_data; in gnss_release() local
72 down_write(&gdev->rwsem); in gnss_release()
73 if (gdev->disconnected) in gnss_release()
76 if (--gdev->count == 0) { in gnss_release()
77 gdev->ops->close(gdev); in gnss_release()
78 kfifo_reset(&gdev->read_fifo); in gnss_release()
81 up_write(&gdev->rwsem); in gnss_release()
83 put_device(&gdev->dev); in gnss_release()
91 struct gnss_device *gdev = file->private_data; in gnss_read() local
95 mutex_lock(&gdev->read_mutex); in gnss_read()
96 while (kfifo_is_empty(&gdev->read_fifo)) { in gnss_read()
97 mutex_unlock(&gdev->read_mutex); in gnss_read()
99 if (gdev->disconnected) in gnss_read()
105 ret = wait_event_interruptible(gdev->read_queue, in gnss_read()
106 gdev->disconnected || in gnss_read()
107 !kfifo_is_empty(&gdev->read_fifo)); in gnss_read()
111 mutex_lock(&gdev->read_mutex); in gnss_read()
114 ret = kfifo_to_user(&gdev->read_fifo, buf, count, &copied); in gnss_read()
118 mutex_unlock(&gdev->read_mutex); in gnss_read()
126 struct gnss_device *gdev = file->private_data; in gnss_write() local
130 if (gdev->disconnected) in gnss_write()
136 if (!(gdev->flags & GNSS_FLAG_HAS_WRITE_RAW)) in gnss_write()
141 ret = mutex_lock_interruptible(&gdev->write_mutex); in gnss_write()
151 if (copy_from_user(gdev->write_buf, buf, n)) { in gnss_write()
162 down_read(&gdev->rwsem); in gnss_write()
163 if (!gdev->disconnected) in gnss_write()
164 ret = gdev->ops->write_raw(gdev, gdev->write_buf, n); in gnss_write()
167 up_read(&gdev->rwsem); in gnss_write()
182 mutex_unlock(&gdev->write_mutex); in gnss_write()
189 struct gnss_device *gdev = file->private_data; in gnss_poll() local
192 poll_wait(file, &gdev->read_queue, wait); in gnss_poll()
194 if (!kfifo_is_empty(&gdev->read_fifo)) in gnss_poll()
196 if (gdev->disconnected) in gnss_poll()
216 struct gnss_device *gdev = to_gnss_device(dev); in gnss_device_release() local
218 kfree(gdev->write_buf); in gnss_device_release()
219 kfifo_free(&gdev->read_fifo); in gnss_device_release()
220 ida_simple_remove(&gnss_minors, gdev->id); in gnss_device_release()
221 kfree(gdev); in gnss_device_release()
226 struct gnss_device *gdev; in gnss_allocate_device() local
231 gdev = kzalloc(sizeof(*gdev), GFP_KERNEL); in gnss_allocate_device()
232 if (!gdev) in gnss_allocate_device()
237 kfree(gdev); in gnss_allocate_device()
241 gdev->id = id; in gnss_allocate_device()
243 dev = &gdev->dev; in gnss_allocate_device()
249 dev_set_drvdata(dev, gdev); in gnss_allocate_device()
252 init_rwsem(&gdev->rwsem); in gnss_allocate_device()
253 mutex_init(&gdev->read_mutex); in gnss_allocate_device()
254 mutex_init(&gdev->write_mutex); in gnss_allocate_device()
255 init_waitqueue_head(&gdev->read_queue); in gnss_allocate_device()
257 ret = kfifo_alloc(&gdev->read_fifo, GNSS_READ_FIFO_SIZE, GFP_KERNEL); in gnss_allocate_device()
261 gdev->write_buf = kzalloc(GNSS_WRITE_BUF_SIZE, GFP_KERNEL); in gnss_allocate_device()
262 if (!gdev->write_buf) in gnss_allocate_device()
265 cdev_init(&gdev->cdev, &gnss_fops); in gnss_allocate_device()
266 gdev->cdev.owner = THIS_MODULE; in gnss_allocate_device()
268 return gdev; in gnss_allocate_device()
277 void gnss_put_device(struct gnss_device *gdev) in gnss_put_device() argument
279 put_device(&gdev->dev); in gnss_put_device()
283 int gnss_register_device(struct gnss_device *gdev) in gnss_register_device() argument
288 if (gdev->ops->write_raw != NULL) in gnss_register_device()
289 gdev->flags |= GNSS_FLAG_HAS_WRITE_RAW; in gnss_register_device()
291 ret = cdev_device_add(&gdev->cdev, &gdev->dev); in gnss_register_device()
293 dev_err(&gdev->dev, "failed to add device: %d\n", ret); in gnss_register_device()
301 void gnss_deregister_device(struct gnss_device *gdev) in gnss_deregister_device() argument
303 down_write(&gdev->rwsem); in gnss_deregister_device()
304 gdev->disconnected = true; in gnss_deregister_device()
305 if (gdev->count) { in gnss_deregister_device()
306 wake_up_interruptible(&gdev->read_queue); in gnss_deregister_device()
307 gdev->ops->close(gdev); in gnss_deregister_device()
309 up_write(&gdev->rwsem); in gnss_deregister_device()
311 cdev_device_del(&gdev->cdev, &gdev->dev); in gnss_deregister_device()
320 int gnss_insert_raw(struct gnss_device *gdev, const unsigned char *buf, in gnss_insert_raw() argument
325 ret = kfifo_in(&gdev->read_fifo, buf, count); in gnss_insert_raw()
327 wake_up_interruptible(&gdev->read_queue); in gnss_insert_raw()
340 static const char *gnss_type_name(struct gnss_device *gdev) in gnss_type_name() argument
344 if (gdev->type < GNSS_TYPE_COUNT) in gnss_type_name()
345 name = gnss_type_names[gdev->type]; in gnss_type_name()
348 dev_WARN(&gdev->dev, "type name not defined\n"); in gnss_type_name()
356 struct gnss_device *gdev = to_gnss_device(dev); in type_show() local
358 return sprintf(buf, "%s\n", gnss_type_name(gdev)); in type_show()
370 struct gnss_device *gdev = to_gnss_device(dev); in gnss_uevent() local
373 ret = add_uevent_var(env, "GNSS_TYPE=%s", gnss_type_name(gdev)); in gnss_uevent()