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
19struct gnss_device;
20
21enum gnss_type {
22 GNSS_TYPE_NMEA = 0,
23 GNSS_TYPE_SIRF,
24 GNSS_TYPE_UBX,
25 GNSS_TYPE_MTK,
26
27 GNSS_TYPE_COUNT
28};
29
30struct gnss_operations {
31 int (*open)(struct gnss_device *gdev);
32 void (*close)(struct gnss_device *gdev);
33 int (*write_raw)(struct gnss_device *gdev, const unsigned char *buf,
34 size_t count);
35};
36
37struct gnss_device {
38 struct device dev;
39 struct cdev cdev;
40 int id;
41
42 enum gnss_type type;
43 unsigned long flags;
44
45 struct rw_semaphore rwsem;
46 const struct gnss_operations *ops;
47 unsigned int count;
48 unsigned int disconnected:1;
49
50 struct mutex read_mutex;
51 struct kfifo read_fifo;
52 wait_queue_head_t read_queue;
53
54 struct mutex write_mutex;
55 char *write_buf;
56};
57
58struct gnss_device *gnss_allocate_device(struct device *parent);
59void gnss_put_device(struct gnss_device *gdev);
60int gnss_register_device(struct gnss_device *gdev);
61void gnss_deregister_device(struct gnss_device *gdev);
62
63int gnss_insert_raw(struct gnss_device *gdev, const unsigned char *buf,
64 size_t count);
65
66static inline void gnss_set_drvdata(struct gnss_device *gdev, void *data)
67{
68 dev_set_drvdata(dev: &gdev->dev, data);
69}
70
71static inline void *gnss_get_drvdata(struct gnss_device *gdev)
72{
73 return dev_get_drvdata(dev: &gdev->dev);
74}
75
76#endif /* _LINUX_GNSS_H */
77

source code of linux/include/linux/gnss.h