virtio_rtc_internal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * virtio_rtc internal interfaces
  4. *
  5. * Copyright (C) 2022-2023 OpenSynergy GmbH
  6. * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  7. */
  8. #ifndef _VIRTIO_RTC_INTERNAL_H_
  9. #define _VIRTIO_RTC_INTERNAL_H_
  10. #include <linux/device.h>
  11. #include <linux/err.h>
  12. #include <linux/ptp_clock_kernel.h>
  13. #include <linux/types.h>
  14. /* driver core IFs */
  15. struct viortc_dev;
  16. int viortc_read(struct viortc_dev *viortc, u16 vio_clk_id, u64 *reading);
  17. int viortc_read_cross(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,
  18. u64 *reading, u64 *cycles);
  19. int viortc_cross_cap(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,
  20. bool *supported);
  21. int viortc_read_alarm(struct viortc_dev *viortc, u16 vio_clk_id,
  22. u64 *alarm_time, bool *enabled);
  23. int viortc_set_alarm(struct viortc_dev *viortc, u16 vio_clk_id, u64 alarm_time,
  24. bool alarm_enable);
  25. int viortc_set_alarm_enabled(struct viortc_dev *viortc, u16 vio_clk_id,
  26. bool alarm_enable);
  27. struct viortc_class;
  28. struct viortc_class *viortc_class_from_dev(struct device *dev);
  29. /* PTP IFs */
  30. struct viortc_ptp_clock;
  31. #if IS_ENABLED(CONFIG_VIRTIO_RTC_PTP)
  32. struct viortc_ptp_clock *viortc_ptp_register(struct viortc_dev *viortc,
  33. struct device *parent_dev,
  34. u16 vio_clk_id,
  35. const char *ptp_clock_name);
  36. int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp,
  37. struct device *parent_dev);
  38. #else
  39. static inline struct viortc_ptp_clock *
  40. viortc_ptp_register(struct viortc_dev *viortc, struct device *parent_dev,
  41. u16 vio_clk_id, const char *ptp_clock_name)
  42. {
  43. return NULL;
  44. }
  45. static inline int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp,
  46. struct device *parent_dev)
  47. {
  48. return -ENODEV;
  49. }
  50. #endif
  51. /* HW counter IFs */
  52. /**
  53. * viortc_hw_xtstamp_params() - get HW-specific xtstamp params
  54. * @hw_counter: virtio_rtc HW counter type
  55. * @cs_id: clocksource id corresponding to hw_counter
  56. *
  57. * Gets the HW-specific xtstamp params. Returns an error if the driver cannot
  58. * support xtstamp.
  59. *
  60. * Context: Process context.
  61. * Return: Zero on success, negative error code otherwise.
  62. */
  63. int viortc_hw_xtstamp_params(u8 *hw_counter, enum clocksource_ids *cs_id);
  64. /* RTC class IFs */
  65. #if IS_ENABLED(CONFIG_VIRTIO_RTC_CLASS)
  66. void viortc_class_alarm(struct viortc_class *viortc_class, u16 vio_clk_id);
  67. void viortc_class_stop(struct viortc_class *viortc_class);
  68. int viortc_class_register(struct viortc_class *viortc_class);
  69. struct viortc_class *viortc_class_init(struct viortc_dev *viortc,
  70. u16 vio_clk_id, bool have_alarm,
  71. struct device *parent_dev);
  72. #else /* CONFIG_VIRTIO_RTC_CLASS */
  73. static inline void viortc_class_alarm(struct viortc_class *viortc_class,
  74. u16 vio_clk_id)
  75. {
  76. }
  77. static inline void viortc_class_stop(struct viortc_class *viortc_class)
  78. {
  79. }
  80. static inline int viortc_class_register(struct viortc_class *viortc_class)
  81. {
  82. return -ENODEV;
  83. }
  84. static inline struct viortc_class *viortc_class_init(struct viortc_dev *viortc,
  85. u16 vio_clk_id,
  86. bool have_alarm,
  87. struct device *parent_dev)
  88. {
  89. return ERR_PTR(-ENODEV);
  90. }
  91. #endif /* CONFIG_VIRTIO_RTC_CLASS */
  92. #endif /* _VIRTIO_RTC_INTERNAL_H_ */