blob: 57d4b1c099e57fa094c07361c45b94e9ee8dff40 [file] [log] [blame]
Sudeep Hollaaa4f8862017-03-28 11:36:07 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * SCMI Message Protocol driver header
4 *
5 * Copyright (C) 2018 ARM Ltd.
6 */
Sudeep Holla933c5042017-10-30 18:33:30 +00007#include <linux/device.h>
Sudeep Hollaaa4f8862017-03-28 11:36:07 +01008#include <linux/types.h>
9
Sudeep Hollab6f20ff2017-06-06 11:16:15 +010010#define SCMI_MAX_STR_SIZE 16
11
12/**
13 * struct scmi_revision_info - version information structure
14 *
15 * @major_ver: Major ABI version. Change here implies risk of backward
16 * compatibility break.
17 * @minor_ver: Minor ABI version. Change here implies new feature addition,
18 * or compatible change in ABI.
19 * @num_protocols: Number of protocols that are implemented, excluding the
20 * base protocol.
21 * @num_agents: Number of agents in the system.
22 * @impl_ver: A vendor-specific implementation version.
23 * @vendor_id: A vendor identifier(Null terminated ASCII string)
24 * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
25 */
26struct scmi_revision_info {
27 u16 major_ver;
28 u16 minor_ver;
29 u8 num_protocols;
30 u8 num_agents;
31 u32 impl_ver;
32 char vendor_id[SCMI_MAX_STR_SIZE];
33 char sub_vendor_id[SCMI_MAX_STR_SIZE];
34};
35
Sudeep Hollaa9e3fbf2017-06-06 11:22:51 +010036struct scmi_handle;
37
38/**
39 * struct scmi_perf_ops - represents the various operations provided
40 * by SCMI Performance Protocol
41 *
42 * @limits_set: sets limits on the performance level of a domain
43 * @limits_get: gets limits on the performance level of a domain
44 * @level_set: sets the performance level of a domain
45 * @level_get: gets the performance level of a domain
46 * @device_domain_id: gets the scmi domain id for a given device
47 * @get_transition_latency: gets the DVFS transition latency for a given device
48 * @add_opps_to_device: adds all the OPPs for a given device
49 * @freq_set: sets the frequency for a given device using sustained frequency
50 * to sustained performance level mapping
51 * @freq_get: gets the frequency for a given device using sustained frequency
52 * to sustained performance level mapping
53 */
54struct scmi_perf_ops {
55 int (*limits_set)(const struct scmi_handle *handle, u32 domain,
56 u32 max_perf, u32 min_perf);
57 int (*limits_get)(const struct scmi_handle *handle, u32 domain,
58 u32 *max_perf, u32 *min_perf);
59 int (*level_set)(const struct scmi_handle *handle, u32 domain,
60 u32 level);
61 int (*level_get)(const struct scmi_handle *handle, u32 domain,
62 u32 *level);
63 int (*device_domain_id)(struct device *dev);
64 int (*get_transition_latency)(const struct scmi_handle *handle,
65 struct device *dev);
66 int (*add_opps_to_device)(const struct scmi_handle *handle,
67 struct device *dev);
68 int (*freq_set)(const struct scmi_handle *handle, u32 domain,
69 unsigned long rate);
70 int (*freq_get)(const struct scmi_handle *handle, u32 domain,
71 unsigned long *rate);
72};
73
Sudeep Hollaaa4f8862017-03-28 11:36:07 +010074/**
75 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
76 *
77 * @dev: pointer to the SCMI device
Sudeep Hollab6f20ff2017-06-06 11:16:15 +010078 * @version: pointer to the structure containing SCMI version information
Sudeep Hollaa9e3fbf2017-06-06 11:22:51 +010079 * @perf_ops: pointer to set of performance protocol operations
Sudeep Hollaaa4f8862017-03-28 11:36:07 +010080 */
81struct scmi_handle {
82 struct device *dev;
Sudeep Hollab6f20ff2017-06-06 11:16:15 +010083 struct scmi_revision_info *version;
Sudeep Hollaa9e3fbf2017-06-06 11:22:51 +010084 struct scmi_perf_ops *perf_ops;
85 /* for protocol internal use */
86 void *perf_priv;
Sudeep Hollab6f20ff2017-06-06 11:16:15 +010087};
88
89enum scmi_std_protocol {
90 SCMI_PROTOCOL_BASE = 0x10,
91 SCMI_PROTOCOL_POWER = 0x11,
92 SCMI_PROTOCOL_SYSTEM = 0x12,
93 SCMI_PROTOCOL_PERF = 0x13,
94 SCMI_PROTOCOL_CLOCK = 0x14,
95 SCMI_PROTOCOL_SENSOR = 0x15,
Sudeep Hollaaa4f8862017-03-28 11:36:07 +010096};
Sudeep Holla933c5042017-10-30 18:33:30 +000097
98struct scmi_device {
99 u32 id;
100 u8 protocol_id;
101 struct device dev;
102 struct scmi_handle *handle;
103};
104
105#define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
106
107struct scmi_device *
108scmi_device_create(struct device_node *np, struct device *parent, int protocol);
109void scmi_device_destroy(struct scmi_device *scmi_dev);
110
111struct scmi_device_id {
112 u8 protocol_id;
113};
114
115struct scmi_driver {
116 const char *name;
117 int (*probe)(struct scmi_device *sdev);
118 void (*remove)(struct scmi_device *sdev);
119 const struct scmi_device_id *id_table;
120
121 struct device_driver driver;
122};
123
124#define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
125
126#ifdef CONFIG_ARM_SCMI_PROTOCOL
127int scmi_driver_register(struct scmi_driver *driver,
128 struct module *owner, const char *mod_name);
129void scmi_driver_unregister(struct scmi_driver *driver);
130#else
131static inline int
132scmi_driver_register(struct scmi_driver *driver, struct module *owner,
133 const char *mod_name)
134{
135 return -EINVAL;
136}
137
138static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
139#endif /* CONFIG_ARM_SCMI_PROTOCOL */
140
141#define scmi_register(driver) \
142 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
143#define scmi_unregister(driver) \
144 scmi_driver_unregister(driver)
145
146/**
147 * module_scmi_driver() - Helper macro for registering a scmi driver
148 * @__scmi_driver: scmi_driver structure
149 *
150 * Helper macro for scmi drivers to set up proper module init / exit
151 * functions. Replaces module_init() and module_exit() and keeps people from
152 * printing pointless things to the kernel log when their driver is loaded.
153 */
154#define module_scmi_driver(__scmi_driver) \
155 module_driver(__scmi_driver, scmi_register, scmi_unregister)
156
157typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
158int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
159void scmi_protocol_unregister(int protocol_id);