gnss.h 1.4 KB

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