summaryrefslogtreecommitdiff
path: root/drivers/virtio/virtio_rtc_internal.h
blob: 296afee6719b32bf50bf728d5c3be59509ac2468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * virtio_rtc internal interfaces
 *
 * Copyright (C) 2022-2023 OpenSynergy GmbH
 * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#ifndef _VIRTIO_RTC_INTERNAL_H_
#define _VIRTIO_RTC_INTERNAL_H_

#include <linux/device.h>
#include <linux/err.h>
#include <linux/ptp_clock_kernel.h>
#include <linux/types.h>

/* driver core IFs */

struct viortc_dev;

int viortc_read(struct viortc_dev *viortc, u16 vio_clk_id, u64 *reading);
int viortc_read_cross(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,
		      u64 *reading, u64 *cycles);
int viortc_cross_cap(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,
		     bool *supported);
int viortc_read_alarm(struct viortc_dev *viortc, u16 vio_clk_id,
		      u64 *alarm_time, bool *enabled);
int viortc_set_alarm(struct viortc_dev *viortc, u16 vio_clk_id, u64 alarm_time,
		     bool alarm_enable);
int viortc_set_alarm_enabled(struct viortc_dev *viortc, u16 vio_clk_id,
			     bool alarm_enable);

struct viortc_class;

struct viortc_class *viortc_class_from_dev(struct device *dev);

/* PTP IFs */

struct viortc_ptp_clock;

#if IS_ENABLED(CONFIG_VIRTIO_RTC_PTP)

struct viortc_ptp_clock *viortc_ptp_register(struct viortc_dev *viortc,
					     struct device *parent_dev,
					     u16 vio_clk_id,
					     const char *ptp_clock_name);
int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp,
			  struct device *parent_dev);

#else

static inline struct viortc_ptp_clock *
viortc_ptp_register(struct viortc_dev *viortc, struct device *parent_dev,
		    u16 vio_clk_id, const char *ptp_clock_name)
{
	return NULL;
}

static inline int viortc_ptp_unregister(struct viortc_ptp_clock *vio_ptp,
					struct device *parent_dev)
{
	return -ENODEV;
}

#endif

/* HW counter IFs */

/**
 * viortc_hw_xtstamp_params() - get HW-specific xtstamp params
 * @hw_counter: virtio_rtc HW counter type
 * @cs_id: clocksource id corresponding to hw_counter
 *
 * Gets the HW-specific xtstamp params. Returns an error if the driver cannot
 * support xtstamp.
 *
 * Context: Process context.
 * Return: Zero on success, negative error code otherwise.
 */
int viortc_hw_xtstamp_params(u8 *hw_counter, enum clocksource_ids *cs_id);

/* RTC class IFs */

#if IS_ENABLED(CONFIG_VIRTIO_RTC_CLASS)

void viortc_class_alarm(struct viortc_class *viortc_class, u16 vio_clk_id);

void viortc_class_stop(struct viortc_class *viortc_class);

int viortc_class_register(struct viortc_class *viortc_class);

struct viortc_class *viortc_class_init(struct viortc_dev *viortc,
				       u16 vio_clk_id, bool have_alarm,
				       struct device *parent_dev);

#else /* CONFIG_VIRTIO_RTC_CLASS */

static inline void viortc_class_alarm(struct viortc_class *viortc_class,
				      u16 vio_clk_id)
{
}

static inline void viortc_class_stop(struct viortc_class *viortc_class)
{
}

static inline int viortc_class_register(struct viortc_class *viortc_class)
{
	return -ENODEV;
}

static inline struct viortc_class *viortc_class_init(struct viortc_dev *viortc,
						     u16 vio_clk_id,
						     bool have_alarm,
						     struct device *parent_dev)
{
	return ERR_PTR(-ENODEV);
}

#endif /* CONFIG_VIRTIO_RTC_CLASS */

#endif /* _VIRTIO_RTC_INTERNAL_H_ */