gnss.h 1.5 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_COUNT
  22. };
  23. struct gnss_operations {
  24. int (*open)(struct gnss_device *gdev);
  25. void (*close)(struct gnss_device *gdev);
  26. int (*write_raw)(struct gnss_device *gdev, const unsigned char *buf,
  27. size_t count);
  28. };
  29. struct gnss_device {
  30. struct device dev;
  31. struct cdev cdev;
  32. int id;
  33. enum gnss_type type;
  34. unsigned long flags;
  35. struct rw_semaphore rwsem;
  36. const struct gnss_operations *ops;
  37. unsigned int count;
  38. unsigned int disconnected:1;
  39. struct mutex read_mutex;
  40. struct kfifo read_fifo;
  41. wait_queue_head_t read_queue;
  42. struct mutex write_mutex;
  43. char *write_buf;
  44. };
  45. struct gnss_device *gnss_allocate_device(struct device *parent);
  46. void gnss_put_device(struct gnss_device *gdev);
  47. int gnss_register_device(struct gnss_device *gdev);
  48. void gnss_deregister_device(struct gnss_device *gdev);
  49. int gnss_insert_raw(struct gnss_device *gdev, const unsigned char *buf,
  50. size_t count);
  51. static inline void gnss_set_drvdata(struct gnss_device *gdev, void *data)
  52. {
  53. dev_set_drvdata(&gdev->dev, data);
  54. }
  55. static inline void *gnss_get_drvdata(struct gnss_device *gdev)
  56. {
  57. return dev_get_drvdata(&gdev->dev);
  58. }
  59. #endif /* _LINUX_GNSS_H */