gnss.h 1.6 KB

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