blob: 464086b9d8c5a483a91c50e4861c2afc6e54e107 [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 Hollaaa4f8862017-03-28 11:36:07 +010036/**
37 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
38 *
39 * @dev: pointer to the SCMI device
Sudeep Hollab6f20ff2017-06-06 11:16:15 +010040 * @version: pointer to the structure containing SCMI version information
Sudeep Hollaaa4f8862017-03-28 11:36:07 +010041 */
42struct scmi_handle {
43 struct device *dev;
Sudeep Hollab6f20ff2017-06-06 11:16:15 +010044 struct scmi_revision_info *version;
45};
46
47enum scmi_std_protocol {
48 SCMI_PROTOCOL_BASE = 0x10,
49 SCMI_PROTOCOL_POWER = 0x11,
50 SCMI_PROTOCOL_SYSTEM = 0x12,
51 SCMI_PROTOCOL_PERF = 0x13,
52 SCMI_PROTOCOL_CLOCK = 0x14,
53 SCMI_PROTOCOL_SENSOR = 0x15,
Sudeep Hollaaa4f8862017-03-28 11:36:07 +010054};
Sudeep Holla933c5042017-10-30 18:33:30 +000055
56struct scmi_device {
57 u32 id;
58 u8 protocol_id;
59 struct device dev;
60 struct scmi_handle *handle;
61};
62
63#define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
64
65struct scmi_device *
66scmi_device_create(struct device_node *np, struct device *parent, int protocol);
67void scmi_device_destroy(struct scmi_device *scmi_dev);
68
69struct scmi_device_id {
70 u8 protocol_id;
71};
72
73struct scmi_driver {
74 const char *name;
75 int (*probe)(struct scmi_device *sdev);
76 void (*remove)(struct scmi_device *sdev);
77 const struct scmi_device_id *id_table;
78
79 struct device_driver driver;
80};
81
82#define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
83
84#ifdef CONFIG_ARM_SCMI_PROTOCOL
85int scmi_driver_register(struct scmi_driver *driver,
86 struct module *owner, const char *mod_name);
87void scmi_driver_unregister(struct scmi_driver *driver);
88#else
89static inline int
90scmi_driver_register(struct scmi_driver *driver, struct module *owner,
91 const char *mod_name)
92{
93 return -EINVAL;
94}
95
96static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
97#endif /* CONFIG_ARM_SCMI_PROTOCOL */
98
99#define scmi_register(driver) \
100 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
101#define scmi_unregister(driver) \
102 scmi_driver_unregister(driver)
103
104/**
105 * module_scmi_driver() - Helper macro for registering a scmi driver
106 * @__scmi_driver: scmi_driver structure
107 *
108 * Helper macro for scmi drivers to set up proper module init / exit
109 * functions. Replaces module_init() and module_exit() and keeps people from
110 * printing pointless things to the kernel log when their driver is loaded.
111 */
112#define module_scmi_driver(__scmi_driver) \
113 module_driver(__scmi_driver, scmi_register, scmi_unregister)
114
115typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
116int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
117void scmi_protocol_unregister(int protocol_id);