Skip to content

Commit e20b556

Browse files
XenuIsWatchingnashif
authored andcommitted
drivers: i3c: add rstact format 2 and 3 helpers
Add rstact direct write and direct read formats helper functions. Signed-off-by: Ryan McClelland <[email protected]>
1 parent 18d1ca7 commit e20b556

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

drivers/i3c/i3c_ccc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,41 @@ int i3c_ccc_do_rstact_all(const struct device *controller,
102102
return i3c_do_ccc(controller, &ccc_payload);
103103
}
104104

105+
int i3c_ccc_do_rstact(const struct i3c_device_desc *target,
106+
enum i3c_ccc_rstact_defining_byte action,
107+
bool get,
108+
uint8_t *data)
109+
{
110+
struct i3c_ccc_payload ccc_payload;
111+
struct i3c_ccc_target_payload ccc_tgt_payload;
112+
uint8_t def_byte;
113+
114+
__ASSERT_NO_MSG(target != NULL);
115+
__ASSERT_NO_MSG(target->bus != NULL);
116+
117+
memset(&ccc_payload, 0, sizeof(ccc_payload));
118+
119+
ccc_tgt_payload.addr = target->dynamic_addr;
120+
if (get) {
121+
__ASSERT_NO_MSG(data != NULL);
122+
123+
ccc_tgt_payload.rnw = 1;
124+
ccc_tgt_payload.data = data;
125+
ccc_tgt_payload.data_len = sizeof(*data);
126+
} else {
127+
ccc_tgt_payload.rnw = 0;
128+
}
129+
130+
ccc_payload.ccc.id = I3C_CCC_RSTACT(false);
131+
def_byte = (uint8_t)action;
132+
ccc_payload.ccc.data = &def_byte;
133+
ccc_payload.ccc.data_len = 1U;
134+
ccc_payload.targets.payloads = &ccc_tgt_payload;
135+
ccc_payload.targets.num_targets = 1;
136+
137+
return i3c_do_ccc(target->bus, &ccc_payload);
138+
}
139+
105140
int i3c_ccc_do_rstdaa_all(const struct device *controller)
106141
{
107142
struct i3c_ccc_payload ccc_payload;

include/zephyr/drivers/i3c/ccc.h

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,18 @@ enum i3c_ccc_rstact_defining_byte {
12571257

12581258
/** Virtual Target Detect. */
12591259
I3C_CCC_RSTACT_VIRTUAL_TARGET_DETECT = 0x04U,
1260+
1261+
/** Return Time to Reset Peripheral */
1262+
I3C_CCC_RSTACT_RETURN_TIME_TO_RESET_PERIPHERAL = 0x81U,
1263+
1264+
/** Return Time to Reset Whole Target */
1265+
I3C_CCC_RSTACT_RETURN_TIME_TO_WHOLE_TARGET = 0x82U,
1266+
1267+
/** Return Time for Debug Network Adapter Reset */
1268+
I3C_CCC_RSTACT_RETURN_TIME_FOR_DEBUG_NETWORK_ADAPTER_RESET = 0x83U,
1269+
1270+
/** Return Virtual Target Indication */
1271+
I3C_CCC_RSTACT_RETURN_VIRTUAL_TARGET_INDICATION = 0x84U,
12601272
};
12611273

12621274
/**
@@ -1317,10 +1329,10 @@ int i3c_ccc_do_getpid(struct i3c_device_desc *target,
13171329
struct i3c_ccc_getpid *pid);
13181330

13191331
/**
1320-
* @brief Broadcast RSTACT to reset I3C Peripheral.
1332+
* @brief Broadcast RSTACT to reset I3C Peripheral (Format 1).
13211333
*
13221334
* Helper function to broadcast Target Reset Action (RSTACT) to
1323-
* all connected targets to Reset the I3C Peripheral Only (0x01).
1335+
* all connected targets.
13241336
*
13251337
* @param[in] controller Pointer to the controller device driver instance.
13261338
* @param[in] action What reset action to perform.
@@ -1330,6 +1342,60 @@ int i3c_ccc_do_getpid(struct i3c_device_desc *target,
13301342
int i3c_ccc_do_rstact_all(const struct device *controller,
13311343
enum i3c_ccc_rstact_defining_byte action);
13321344

1345+
/**
1346+
* @brief Single target RSTACT to reset I3C Peripheral.
1347+
*
1348+
* Helper function to do Target Reset Action (RSTACT) to
1349+
* one target.
1350+
*
1351+
* @param[in] target Pointer to the target device descriptor.
1352+
* @param[in] action What reset action to perform.
1353+
* @param[in] get True if a get, False if set
1354+
* @param[out] data Pointer to RSTACT payload received.
1355+
*
1356+
* @return @see i3c_do_ccc
1357+
*/
1358+
int i3c_ccc_do_rstact(const struct i3c_device_desc *target,
1359+
enum i3c_ccc_rstact_defining_byte action,
1360+
bool get,
1361+
uint8_t *data);
1362+
1363+
/**
1364+
* @brief Single target RSTACT to reset I3C Peripheral (Format 2).
1365+
*
1366+
* Helper function to do Target Reset Action (RSTACT, format 2) to
1367+
* one target. This is a Direct Write.
1368+
*
1369+
* @param[in] target Pointer to the target device descriptor.
1370+
* @param[in] action What reset action to perform.
1371+
*
1372+
* @return @see i3c_do_ccc
1373+
*/
1374+
static inline int i3c_ccc_do_rstact_fmt2(const struct i3c_device_desc *target,
1375+
enum i3c_ccc_rstact_defining_byte action)
1376+
{
1377+
return i3c_ccc_do_rstact(target, action, false, NULL);
1378+
}
1379+
1380+
/**
1381+
* @brief Single target RSTACT to reset I3C Peripheral (Format 3).
1382+
*
1383+
* Helper function to do Target Reset Action (RSTACT, format 3) to
1384+
* one target. This is a Direct Read.
1385+
*
1386+
* @param[in] target Pointer to the target device descriptor.
1387+
* @param[in] action What reset action to perform.
1388+
* @param[out] data Pointer to RSTACT payload received.
1389+
*
1390+
* @return @see i3c_do_ccc
1391+
*/
1392+
static inline int i3c_ccc_do_rstact_fmt3(const struct i3c_device_desc *target,
1393+
enum i3c_ccc_rstact_defining_byte action,
1394+
uint8_t *data)
1395+
{
1396+
return i3c_ccc_do_rstact(target, action, true, data);
1397+
}
1398+
13331399
/**
13341400
* @brief Broadcast RSTDAA to reset dynamic addresses for all targets.
13351401
*

0 commit comments

Comments
 (0)