Merge tag 'driver-core-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / include / linux / gnss.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * GNSS receiver support
4  *
5  * Copyright (C) 2018 Johan Hovold <johan@kernel.org>
6  */
7
8 #ifndef _LINUX_GNSS_H
9 #define _LINUX_GNSS_H
10
11 #include <linux/cdev.h>
12 #include <linux/device.h>
13 #include <linux/kfifo.h>
14 #include <linux/mutex.h>
15 #include <linux/rwsem.h>
16 #include <linux/types.h>
17 #include <linux/wait.h>
18
19 struct gnss_device;
20
21 enum gnss_type {
22         GNSS_TYPE_NMEA = 0,
23         GNSS_TYPE_SIRF,
24         GNSS_TYPE_UBX,
25
26         GNSS_TYPE_COUNT
27 };
28
29 struct gnss_operations {
30         int (*open)(struct gnss_device *gdev);
31         void (*close)(struct gnss_device *gdev);
32         int (*write_raw)(struct gnss_device *gdev, const unsigned char *buf,
33                                 size_t count);
34 };
35
36 struct gnss_device {
37         struct device dev;
38         struct cdev cdev;
39         int id;
40
41         enum gnss_type type;
42         unsigned long flags;
43
44         struct rw_semaphore rwsem;
45         const struct gnss_operations *ops;
46         unsigned int count;
47         unsigned int disconnected:1;
48
49         struct mutex read_mutex;
50         struct kfifo read_fifo;
51         wait_queue_head_t read_queue;
52
53         struct mutex write_mutex;
54         char *write_buf;
55 };
56
57 struct gnss_device *gnss_allocate_device(struct device *parent);
58 void gnss_put_device(struct gnss_device *gdev);
59 int gnss_register_device(struct gnss_device *gdev);
60 void gnss_deregister_device(struct gnss_device *gdev);
61
62 int gnss_insert_raw(struct gnss_device *gdev, const unsigned char *buf,
63                         size_t count);
64
65 static inline void gnss_set_drvdata(struct gnss_device *gdev, void *data)
66 {
67         dev_set_drvdata(&gdev->dev, data);
68 }
69
70 static inline void *gnss_get_drvdata(struct gnss_device *gdev)
71 {
72         return dev_get_drvdata(&gdev->dev);
73 }
74
75 #endif /* _LINUX_GNSS_H */