Skip to content

Commit 1f757bc

Browse files
XenuIsWatchingcfriedt
authored andcommitted
drivers: i3c: add SETNEWDA ccc helper function
This is a ccc helper function for setting a new dynamic addr for a Target. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
1 parent 71c5ccb commit 1f757bc

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

drivers/i3c/i3c_ccc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,38 @@ int i3c_ccc_do_setdasa(const struct i3c_device_desc *target)
146146
return i3c_do_ccc(target->bus, &ccc_payload);
147147
}
148148

149+
int i3c_ccc_do_setnewda(const struct i3c_device_desc *target, struct i3c_ccc_address new_da)
150+
{
151+
struct i3c_ccc_payload ccc_payload;
152+
struct i3c_ccc_target_payload ccc_tgt_payload;
153+
uint8_t new_dyn_addr;
154+
155+
__ASSERT_NO_MSG(target != NULL);
156+
__ASSERT_NO_MSG(target->bus != NULL);
157+
158+
if (target->dynamic_addr == 0U) {
159+
return -EINVAL;
160+
}
161+
162+
/*
163+
* Note that the 7-bit address needs to start at bit 1
164+
* (aka left-justified). So shift left by 1;
165+
*/
166+
new_dyn_addr = new_da.addr << 1;
167+
168+
ccc_tgt_payload.addr = target->dynamic_addr;
169+
ccc_tgt_payload.rnw = 0;
170+
ccc_tgt_payload.data = &new_dyn_addr;
171+
ccc_tgt_payload.data_len = 1;
172+
173+
memset(&ccc_payload, 0, sizeof(ccc_payload));
174+
ccc_payload.ccc.id = I3C_CCC_SETNEWDA;
175+
ccc_payload.targets.payloads = &ccc_tgt_payload;
176+
ccc_payload.targets.num_targets = 1;
177+
178+
return i3c_do_ccc(target->bus, &ccc_payload);
179+
}
180+
149181
int i3c_ccc_do_events_all_set(const struct device *controller,
150182
bool enable, struct i3c_ccc_events *events)
151183
{

include/zephyr/drivers/i3c/ccc.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,22 @@ int i3c_ccc_do_rstdaa_all(const struct device *controller);
869869
*/
870870
int i3c_ccc_do_setdasa(const struct i3c_device_desc *target);
871871

872+
/**
873+
* @brief Set New Dynamic Address for a target
874+
*
875+
* Helper function to do SETNEWDA(Set New Dynamic Address) for a particular target.
876+
*
877+
* Note this does not update @p target with the new dynamic address.
878+
*
879+
* @param[in] target Pointer to the target device descriptor where
880+
* the device is configured with a static address.
881+
* @param[in] new_da Pointer to the new_da struct.
882+
*
883+
* @return @see i3c_do_ccc
884+
*/
885+
int i3c_ccc_do_setnewda(const struct i3c_device_desc *target,
886+
struct i3c_ccc_address new_da);
887+
872888
/**
873889
* @brief Broadcast ENEC/DISEC to enable/disable target events.
874890
*

0 commit comments

Comments
 (0)