Skip to content

Commit ab388ea

Browse files
committed
drivers: firmware: scmi: add NXP bbnsm domain protocol
This protocol is intended provide access to the battery-backed module, it contains persistent storage (GPR), an RTC, and the ON/OFF button. The protocol can also provide access to similar functions implemented via external board components. Added button P2A notification event for the BBM protocol. Signed-off-by: Yongxu Wang <[email protected]>
1 parent a467d60 commit ab388ea

File tree

6 files changed

+201
-0
lines changed

6 files changed

+201
-0
lines changed

doc/hardware/arch/arm-scmi.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ example, ``CPU_SLEEP_MODE_SET``.
191191
This driver is NXP-specific. As such, it may only be used on NXP
192192
system that uses SCMI for cpu domain management operations.
193193

194+
NXP - BBNSM management
195+
***************************
196+
197+
This protocol is intended provide access to the battery-backed module.
198+
This contains persistent storage (GPR), an RTC, and the ON/OFF button,
199+
for example, ``scmi_bbm_button_notify``.
200+
201+
.. note::
202+
This driver is NXP-specific. As such, it may only be used on NXP
203+
system that uses SCMI for bbnsm domain management operations.
204+
194205
Enabling the SCMI support
195206
*************************
196207

drivers/firmware/scmi/nxp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ zephyr_library_property(ALLOW_EMPTY TRUE)
55

66
zephyr_library_sources_ifdef(CONFIG_ARM_SCMI_NXP_VENDOR_EXTENSIONS shmem.c)
77
zephyr_library_sources_ifdef(CONFIG_NXP_SCMI_CPU_DOMAIN_HELPERS cpu.c)
8+
zephyr_library_sources_ifdef(CONFIG_NXP_SCMI_BBM bbm.c)

drivers/firmware/scmi/nxp/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ config NXP_SCMI_CPU_DOMAIN_HELPERS
1616
help
1717
Enable support for SCMI cpu domain protocol helper functions.
1818

19+
config NXP_SCMI_BBM
20+
bool "NXP BBM SCMI interface protocol"
21+
default y
22+
depends on DT_HAS_NXP_SCMI_BBM_ENABLED
23+
help
24+
Enable support for SCMI NXP BBM functions.
25+
1926
endif # ARM_SCMI_NXP_VENDOR_EXTENSIONS

drivers/firmware/scmi/nxp/bbm.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/firmware/scmi/nxp/bbm.h>
8+
#include <string.h>
9+
#include <zephyr/kernel.h>
10+
#include <zephyr/logging/log.h>
11+
12+
LOG_MODULE_REGISTER(scmi_nxp_bbm);
13+
14+
static uint32_t scmi_nxp_bbm_events[] = {
15+
SCMI_PROTO_BBM_PROTOCOL_BUTTON_EVENT,
16+
};
17+
18+
static struct scmi_protocol_event bbm_event = {
19+
.evts = scmi_nxp_bbm_events,
20+
.num_events = ARRAY_SIZE(scmi_nxp_bbm_events),
21+
.cb = scmi_bbm_event_protocol_cb,
22+
};
23+
24+
DT_SCMI_PROTOCOL_DEFINE_NODEV(DT_INST(0, nxp_scmi_bbm), NULL, &bbm_event);
25+
26+
int scmi_bbm_button_notify(uint32_t flags)
27+
{
28+
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_NXP_BBM);
29+
struct scmi_message msg, reply;
30+
int32_t status, ret;
31+
32+
/* sanity checks */
33+
if (proto->id != SCMI_PROTOCOL_NXP_BBM) {
34+
return -EINVAL;
35+
}
36+
37+
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_PROTO_BBM_BBM_BUTTON_NOTIFY, SCMI_COMMAND,
38+
proto->id, 0);
39+
msg.len = sizeof(flags);
40+
msg.content = &flags;
41+
42+
reply.hdr = msg.hdr;
43+
reply.len = sizeof(status);
44+
reply.content = &status;
45+
46+
ret = scmi_send_message(proto, &msg, &reply, k_is_pre_kernel());
47+
if (ret < 0) {
48+
return ret;
49+
}
50+
51+
return 0;
52+
}
53+
54+
int scmi_bbm_button_event(uint32_t *flags)
55+
{
56+
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_NXP_BBM);
57+
struct scmi_message msg;
58+
int32_t ret;
59+
60+
/* sanity checks */
61+
if (proto->id != SCMI_PROTOCOL_NXP_BBM) {
62+
return -EINVAL;
63+
}
64+
65+
/* TODO: Implement token handling for P2A flow to correctly associate notifications */
66+
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_PROTO_BBM_PROTOCOL_BUTTON_EVENT, SCMI_NOTIFICATION,
67+
proto->id, 0x0);
68+
msg.len = sizeof(flags);
69+
msg.content = flags;
70+
71+
ret = scmi_read_message(proto, &msg);
72+
if (ret < 0) {
73+
return ret;
74+
}
75+
76+
return 0;
77+
}
78+
79+
int scmi_bbm_event_protocol_cb(int32_t msg_id)
80+
{
81+
uint32_t flags;
82+
int32_t ret = 0;
83+
84+
if (msg_id == SCMI_PROTO_BBM_PROTOCOL_BUTTON_EVENT) {
85+
ret = scmi_bbm_button_event(&flags);
86+
if (ret < 0) {
87+
LOG_ERR("failed to read bbm button event to shmem: %d", ret);
88+
} else {
89+
LOG_INF("SCMI BBM BUTTON notification: flags=0x%08X", flags);
90+
}
91+
}
92+
93+
return ret;
94+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: System Control and Management Interface (SCMI) bbm protocol
5+
6+
compatible: "nxp,scmi-bbm"
7+
8+
include: [base.yaml]
9+
10+
properties:
11+
reg:
12+
required: true
13+
const: [0x81]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief SCMI NXP BBNSM domain protocol helpers
10+
*/
11+
12+
#ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_BBM_H_
13+
#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_BBM_H_
14+
15+
#include <zephyr/drivers/firmware/scmi/protocol.h>
16+
17+
#define SCMI_PROTOCOL_NXP_BBM 129
18+
19+
/*!
20+
* @name SCMI NXP BBM button notification flags
21+
*/
22+
/** @{ */
23+
/*! Enable button notifications */
24+
#define SCMI_BBM_NOTIFY_BUTTON_DETECT(x) (((x) & 0x1U) << 0U)
25+
/** @} */
26+
27+
/**
28+
* @brief Bbm protocol command message IDs
29+
*/
30+
enum scmi_bbm_message {
31+
SCMI_PROTO_BBM_PROTOCOL_RTC_EVENT = 0x0,
32+
SCMI_PROTO_BBM_PROTOCOL_BUTTON_EVENT = 0x1,
33+
SCMI_PROTO_BBM_BBM_GPR_SET = 0x3,
34+
SCMI_PROTO_BBM_BBM_GPR_GET = 0x4,
35+
SCMI_PROTO_BBM_BBM_RTC_ATTRIBUTES = 0x5,
36+
SCMI_PROTO_BBM_BBM_RTC_TIME_SET = 0x6,
37+
SCMI_PROTO_BBM_BBM_RTC_TIME_GET = 0x7,
38+
SCMI_PROTO_BBM_BBM_RTC_ALARM_SET = 0x8,
39+
SCMI_PROTO_BBM_BBM_BUTTON_GET = 0x9,
40+
SCMI_PROTO_BBM_BBM_RTC_NOTIFY = 0xA,
41+
SCMI_PROTO_BBM_BBM_BUTTON_NOTIFY = 0xB,
42+
SCMI_PROTO_BBM_BBM_RTC_STATE = 0xC,
43+
SCMI_PROTO_BBM_NEGOTIATE_PROTOCOL_VERSION = 0x10,
44+
};
45+
46+
/**
47+
* @brief Set up BBM button notify message
48+
*
49+
* @param flags to enable or disable button notify for agent
50+
*
51+
* @retval 0 if successful
52+
* @retval negative errno if failure
53+
*/
54+
int scmi_bbm_button_notify(uint32_t flags);
55+
56+
/**
57+
* @brief Read BBM button event message
58+
*
59+
* @param flags to get notification event from agent
60+
*
61+
* @retval 0 if successful
62+
* @retval negative errno if failure
63+
*/
64+
int scmi_bbm_button_event(uint32_t *flags);
65+
66+
/**
67+
* @brief BBM event notification callback
68+
*
69+
* @param msg_id to determine and handle the corresponding event.
70+
*
71+
* @retval 0 if successful
72+
* @retval negative errno if failure
73+
*/
74+
int scmi_bbm_event_protocol_cb(int32_t msg_id);
75+
#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_BBM_H_ */

0 commit comments

Comments
 (0)