0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _LINUX_GNSS_H
0009 #define _LINUX_GNSS_H
0010
0011 #include <linux/cdev.h>
0012 #include <linux/device.h>
0013 #include <linux/kfifo.h>
0014 #include <linux/mutex.h>
0015 #include <linux/rwsem.h>
0016 #include <linux/types.h>
0017 #include <linux/wait.h>
0018
0019 struct gnss_device;
0020
0021 enum gnss_type {
0022 GNSS_TYPE_NMEA = 0,
0023 GNSS_TYPE_SIRF,
0024 GNSS_TYPE_UBX,
0025 GNSS_TYPE_MTK,
0026
0027 GNSS_TYPE_COUNT
0028 };
0029
0030 struct gnss_operations {
0031 int (*open)(struct gnss_device *gdev);
0032 void (*close)(struct gnss_device *gdev);
0033 int (*write_raw)(struct gnss_device *gdev, const unsigned char *buf,
0034 size_t count);
0035 };
0036
0037 struct gnss_device {
0038 struct device dev;
0039 struct cdev cdev;
0040 int id;
0041
0042 enum gnss_type type;
0043 unsigned long flags;
0044
0045 struct rw_semaphore rwsem;
0046 const struct gnss_operations *ops;
0047 unsigned int count;
0048 unsigned int disconnected:1;
0049
0050 struct mutex read_mutex;
0051 struct kfifo read_fifo;
0052 wait_queue_head_t read_queue;
0053
0054 struct mutex write_mutex;
0055 char *write_buf;
0056 };
0057
0058 struct gnss_device *gnss_allocate_device(struct device *parent);
0059 void gnss_put_device(struct gnss_device *gdev);
0060 int gnss_register_device(struct gnss_device *gdev);
0061 void gnss_deregister_device(struct gnss_device *gdev);
0062
0063 int gnss_insert_raw(struct gnss_device *gdev, const unsigned char *buf,
0064 size_t count);
0065
0066 static inline void gnss_set_drvdata(struct gnss_device *gdev, void *data)
0067 {
0068 dev_set_drvdata(&gdev->dev, data);
0069 }
0070
0071 static inline void *gnss_get_drvdata(struct gnss_device *gdev)
0072 {
0073 return dev_get_drvdata(&gdev->dev);
0074 }
0075
0076 #endif