Skip to content

Commit 9f34701

Browse files
committed
firmware: Provide new device instantiation macro
Again removing the prio parameter. And switching the unique macro call in drivers. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent cbf4c1c commit 9f34701

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

drivers/clock_control/clock_control_arm_scmi.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,5 @@ static int scmi_clock_init(const struct device *dev)
9797

9898
static struct scmi_clock_data data;
9999

100-
DT_INST_SCMI_PROTOCOL_DEFINE(0, &scmi_clock_init, NULL, &data, NULL,
101-
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY,
102-
&scmi_clock_api);
100+
SCMI_PROTOCOL_INSTANCE_FROM_DT_INST(0, &scmi_clock_init, NULL, &data, NULL,
101+
PRE_KERNEL_1, &scmi_clock_api);

drivers/firmware/scmi/mailbox.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,4 @@ static struct scmi_transport_api scmi_mbox_api = {
111111
.channel_is_free = scmi_mbox_channel_is_free,
112112
};
113113

114-
DT_INST_SCMI_MAILBOX_DEFINE(0, PRE_KERNEL_1,
115-
CONFIG_ARM_SCMI_TRANSPORT_INIT_PRIORITY,
116-
&scmi_mbox_api);
114+
SCMI_MAILBOX_INSTANCE_FROM_DT_INST(0, PRE_KERNEL_1, &scmi_mbox_api);

drivers/firmware/scmi/mailbox.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
* 2) Creates aforementioned structures for the base protocol
9999
* (identified by the `scmi` node)
100100
*
101-
* 3) "registers" the driver via `DT_INST_SCMI_TRANSPORT_DEFINE()`.
101+
* 3) "registers" the driver via `SCMI_TRANSPORT_INSTANCE_FROM_DT_INST()`.
102102
*/
103-
#define DT_INST_SCMI_MAILBOX_DEFINE(inst, level, prio, api) \
103+
#define SCMI_MAILBOX_INSTANCE_FROM_DT_INST(inst, level, api) \
104104
DT_INST_FOREACH_CHILD_STATUS_OKAY(inst, SCMI_MBOX_PROTO_CHAN_DEFINE) \
105105
DT_INST_SCMI_MBOX_BASE_CHAN_DEFINE(inst) \
106-
DT_INST_SCMI_TRANSPORT_DEFINE(inst, NULL, NULL, NULL, level, prio, api)
106+
SCMI_TRANSPORT_INSTANCE_FROM_DT_INST(inst, NULL, NULL, NULL, level, api)
107107

108108
struct scmi_mbox_channel {
109109
/* SHMEM area bound to the channel */

include/zephyr/drivers/firmware/scmi/util.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@
183183
DEVICE_DT_INST_DEFINE(inst, &scmi_core_transport_init, \
184184
pm, data, config, level, prio, api)
185185

186+
/**
187+
* @brief Define an SCMI transport driver
188+
*
189+
* This is merely a wrapper over DEVICE_INSTANCE_FROM_DT_INST(), but is
190+
* required since transport layer drivers are not allowed to place
191+
* their own init() function in the init section. Instead, transport
192+
* layer drivers place the scmi_core_transport_init() function in the
193+
* init section, which, in turn, will call the transport layer driver
194+
* init() function. This is required because the SCMI core needs to
195+
* perform channel binding and setup during the transport layer driver's
196+
* initialization.
197+
*/
198+
#define SCMI_TRANSPORT_INSTANCE_FROM_DT_INST(inst, pm, data, config, \
199+
level, api) \
200+
DEVICE_INSTANCE_FROM_DT_INST(inst, &scmi_core_transport_init, \
201+
pm, data, config, level, api)
202+
186203
/**
187204
* @brief Define an SCMI protocol
188205
*
@@ -216,6 +233,39 @@
216233
&SCMI_PROTOCOL_NAME(DT_REG_ADDR_RAW(node_id)), \
217234
config, level, prio, api)
218235

236+
/**
237+
* @brief Define an SCMI protocol
238+
*
239+
* This macro performs three important functions:
240+
* 1) It defines a `struct scmi_protocol`, which is
241+
* needed by all protocol drivers to work with the SCMI API.
242+
*
243+
* 2) It declares the static channels bound to the protocol.
244+
* This is only applicable if the transport layer driver
245+
* supports static channels.
246+
*
247+
* 3) It creates a `struct device` a sets the `data` field
248+
* to the newly defined `struct scmi_protocol`. This is
249+
* needed because the protocol driver needs to work with the
250+
* SCMI API **and** the subsystem API.
251+
*
252+
* @param node_id protocol node identifier
253+
* @param init_fn pointer to protocol's initialization function
254+
* @param api pointer to protocol's subsystem API
255+
* @param pm pointer to the protocol's power management resources
256+
* @param data pointer to protocol's private data
257+
* @param config pointer to protocol's private constant data
258+
* @param level protocol initialization level
259+
* @param api pointer to driver's api
260+
*/
261+
#define SCMI_PROTOCOL_INSTANCE(node_id, init_fn, pm, data, config, \
262+
level, api) \
263+
DT_SCMI_TRANSPORT_CHANNELS_DECLARE(node_id) \
264+
DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, DT_REG_ADDR(node_id), data); \
265+
DEVICE_INSTANCE(node_id, init_fn, pm, \
266+
&SCMI_PROTOCOL_NAME(DT_REG_ADDR(node_id)), \
267+
config, level, api)
268+
219269
/**
220270
* @brief Just like DT_SCMI_PROTOCOL_DEFINE(), but uses an instance
221271
* of a `DT_DRV_COMPAT` compatible instead of a node identifier
@@ -233,6 +283,15 @@
233283
level, prio, api) \
234284
DT_SCMI_PROTOCOL_DEFINE(DT_INST(inst, DT_DRV_COMPAT), init_fn, pm, \
235285
data, config, level, prio, api)
286+
/**
287+
* @brief Just like SCMI_PROTOCOL_INSTANCE(), but uses an instance
288+
* of a `DT_DRV_COMPAT` compatible instead of a node identifier
289+
*
290+
* @param inst instance number
291+
* @param ... Other parameters as expected by SCMI_PROTOCOL_INSTANCE
292+
*/
293+
#define SCMI_PROTOCOL_INSTANCE_FROM_DT_INST(inst, ...) \
294+
SCMI_PROTOCOL_INSTANCE(DT_INST(inst, DT_DRV_COMPAT), __VA_ARGS__)
236295

237296
/**
238297
* @brief Define an SCMI protocol with no device

0 commit comments

Comments
 (0)