| 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 |
|
| 9 |
#ifndef _VIRTIO_RTC_INTERNAL_H_ |
| 10 |
#define _VIRTIO_RTC_INTERNAL_H_ |
| 11 |
|
| 12 |
#include <linux/device.h> |
| 13 |
#include <linux/err.h> |
| 14 |
#include <linux/ptp_clock_kernel.h> |
| 15 |
#include <linux/types.h> |
| 16 |
|
| 17 |
/* driver core IFs */ |
| 18 |
|
| 19 |
struct viortc_dev; |
| 20 |
|
| 21 |
int viortc_read(struct viortc_dev *viortc, u16 vio_clk_id, u64 *reading); |
| 22 |
int viortc_read_cross(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter, |
| 23 |
u64 *reading, u64 *cycles); |
| 24 |
int viortc_cross_cap(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter, |
| 25 |
bool *supported); |
| 26 |
int viortc_read_alarm(struct viortc_dev *viortc, u16 vio_clk_id, |
| 27 |
u64 *alarm_time, bool *enabled); |
| 28 |
int viortc_set_alarm(struct viortc_dev *viortc, u16 vio_clk_id, u64 alarm_time, |
| 29 |
bool alarm_enable); |
| 30 |
int viortc_set_alarm_enabled(struct viortc_dev *viortc, u16 vio_clk_id, |
| 31 |
bool alarm_enable); |
| 32 |
|
| 33 |
struct viortc_class; |
| 34 |
|
| 35 |
struct viortc_class *viortc_class_from_dev(struct device *dev); |
| 36 |
|
| 37 |
/* PTP IFs */ |
| 38 |
|
| 39 |
struct viortc_ptp_clock; |
| 40 |
|
| 41 |
#if IS_ENABLED(CONFIG_VIRTIO_RTC_PTP) |
| 42 |
|
| 43 |
struct viortc_ptp_clock *viortc_ptp_register(struct viortc_dev *viortc, |
| 44 |
struct device *parent_dev, |
| 45 |
u16 vio_clk_id, |
| 46 |
const char *ptp_clock_name); |
| 47 |
int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp, |
| 48 |
struct device *parent_dev); |
| 49 |
|
| 50 |
#else |
| 51 |
|
| 52 |
static inline struct viortc_ptp_clock * |
| 53 |
viortc_ptp_register(struct viortc_dev *viortc, struct device *parent_dev, |
| 54 |
u16 vio_clk_id, const char *ptp_clock_name) |
| 55 |
{ |
| 56 |
return NULL; |
| 57 |
} |
| 58 |
|
| 59 |
static inline int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp, |
| 60 |
struct device *parent_dev) |
| 61 |
{ |
| 62 |
return -ENODEV; |
| 63 |
} |
| 64 |
|
| 65 |
#endif |
| 66 |
|
| 67 |
/* HW counter IFs */ |
| 68 |
|
| 69 |
/** |
| 70 |
* viortc_hw_xtstamp_params() - get HW-specific xtstamp params |
| 71 |
* @hw_counter: virtio_rtc HW counter type |
| 72 |
* @cs_id: clocksource id corresponding to hw_counter |
| 73 |
* |
| 74 |
* Gets the HW-specific xtstamp params. Returns an error if the driver cannot |
| 75 |
* support xtstamp. |
| 76 |
* |
| 77 |
* Context: Process context. |
| 78 |
* Return: Zero on success, negative error code otherwise. |
| 79 |
*/ |
| 80 |
int viortc_hw_xtstamp_params(u8 *hw_counter, enum clocksource_ids *cs_id); |
| 81 |
|
| 82 |
/* RTC class IFs */ |
| 83 |
|
| 84 |
#if IS_ENABLED(CONFIG_VIRTIO_RTC_CLASS) |
| 85 |
|
| 86 |
void viortc_class_alarm(struct viortc_class *viortc_class, u16 vio_clk_id); |
| 87 |
|
| 88 |
void viortc_class_stop(struct viortc_class *viortc_class); |
| 89 |
|
| 90 |
int viortc_class_register(struct viortc_class *viortc_class); |
| 91 |
|
| 92 |
struct viortc_class *viortc_class_init(struct viortc_dev *viortc, |
| 93 |
u16 vio_clk_id, bool have_alarm, |
| 94 |
struct device *parent_dev); |
| 95 |
|
| 96 |
#else /* CONFIG_VIRTIO_RTC_CLASS */ |
| 97 |
|
| 98 |
static inline void viortc_class_alarm(struct viortc_class *viortc_class, |
| 99 |
u16 vio_clk_id) |
| 100 |
{ |
| 101 |
} |
| 102 |
|
| 103 |
static inline void viortc_class_stop(struct viortc_class *viortc_class) |
| 104 |
{ |
| 105 |
} |
| 106 |
|
| 107 |
static inline int viortc_class_register(struct viortc_class *viortc_class) |
| 108 |
{ |
| 109 |
return -ENODEV; |
| 110 |
} |
| 111 |
|
| 112 |
static inline struct viortc_class *viortc_class_init(struct viortc_dev *viortc, |
| 113 |
u16 vio_clk_id, |
| 114 |
bool have_alarm, |
| 115 |
struct device *parent_dev) |
| 116 |
{ |
| 117 |
return ERR_PTR(-ENODEV); |
| 118 |
} |
| 119 |
|
| 120 |
#endif /* CONFIG_VIRTIO_RTC_CLASS */ |
| 121 |
|
| 122 |
#endif /* _VIRTIO_RTC_INTERNAL_H_ */ |