Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: i3c: add support for setaasa initialization #78117

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions drivers/i3c/i3c_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,12 @@
*/
static int i3c_bus_setdasa(const struct device *dev,
const struct i3c_dev_list *dev_list,
bool *need_daa)
bool *need_daa, bool *need_aasa)

Check notice on line 594 in drivers/i3c/i3c_common.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/i3c/i3c_common.c:594 -static int i3c_bus_setdasa(const struct device *dev, - const struct i3c_dev_list *dev_list, +static int i3c_bus_setdasa(const struct device *dev, const struct i3c_dev_list *dev_list,
{
int i, ret;

*need_daa = false;
*need_aasa = false;

/* Loop through the registered I3C devices */
for (i = 0; i < dev_list->num_i3c; i++) {
Expand All @@ -610,6 +611,17 @@
continue;
}

/*
* A device that supports SETAASA and will use the same dynamic
* address as its static address if a different dynamic address
* is not requested
*/
if ((desc->supports_setaasa) && ((desc->init_dynamic_addr == 0) ||
desc->init_dynamic_addr == desc->static_addr)) {
*need_aasa = true;

Check notice on line 621 in drivers/i3c/i3c_common.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/i3c/i3c_common.c:621 - desc->init_dynamic_addr == desc->static_addr)) { + desc->init_dynamic_addr == desc->static_addr)) {
continue;
}

LOG_DBG("SETDASA for 0x%x", desc->static_addr);

ret = i3c_ccc_do_setdasa(desc);
Expand Down Expand Up @@ -639,6 +651,7 @@
{
int i, ret = 0;
bool need_daa = true;
bool need_aasa = true;
struct i3c_ccc_events i3c_events;

#ifdef CONFIG_I3C_INIT_RSTACT
Expand Down Expand Up @@ -684,11 +697,32 @@
/*
* Set static addresses as dynamic addresses.
*/
ret = i3c_bus_setdasa(dev, dev_list, &need_daa);
ret = i3c_bus_setdasa(dev, dev_list, &need_daa, &need_aasa);
if (ret != 0) {
goto err_out;
}

/*
* Perform Set All Addresses to Static Address if possible.
*/
if (need_aasa) {
ret = i3c_ccc_do_setaasa_all(dev);
if (ret != 0) {
for (i = 0; i < dev_list->num_i3c; i++) {
struct i3c_device_desc *desc = &dev_list->i3c[i];
/*
* Only set for devices that support SETAASA and do not
* request a different dynamic address than its SA
*/
if ((desc->supports_setaasa) && (desc->static_addr != 0) &&
((desc->init_dynamic_addr == 0) ||
desc->init_dynamic_addr == desc->static_addr)) {
desc->dynamic_addr = desc->static_addr;
}
}
}
}

/*
* Perform Dynamic Address Assignment if needed.
*/
Expand Down
3 changes: 2 additions & 1 deletion drivers/i3c/i3c_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ static int cmd_i3c_ccc_setaasa(const struct shell *shell_ctx, size_t argc, char
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
struct i3c_device_desc *desc =
CONTAINER_OF(node, struct i3c_device_desc, node);
if ((desc->dynamic_addr == 0) && (desc->static_addr != 0)) {
if ((desc->supports_setaasa) && (desc->dynamic_addr == 0) &&
(desc->static_addr != 0)) {
desc->dynamic_addr = desc->static_addr;
}
}
Expand Down
6 changes: 6 additions & 0 deletions dts/bindings/i3c/i3c-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ properties:
type: int
description: |
Dynamic address to be assigned to the device.

supports-setaasa:
type: boolean
description: |
Indicates if the device supports the CCC SETAASA. If true, it will
be used as an optimization for bus initialization.
Comment on lines +65 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if more supports-* are required in the future, a bit field could be more future-proof, but not sure if it can be the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... it definitely could and that was something was thinking about, but that could come when more "supports" are implemented rather than using an inefficient bool for each of them.

8 changes: 8 additions & 0 deletions include/zephyr/drivers/i3c.h
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,14 @@ struct i3c_device_desc {
*/
const uint8_t init_dynamic_addr;

/**
* Device support for SETAASA
*
* This will be used as an optimization for bus initializtion if the
* device supports SETAASA.
*/
const bool supports_setaasa;

/**
* Dynamic Address for this target device used for communication.
*
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/drivers/i3c/devicetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
| DT_PROP_BY_IDX(node_id, reg, 2), \
.init_dynamic_addr = \
DT_PROP_OR(node_id, assigned_address, 0), \
.supports_setaasa = DT_PROP(node_id, supports_setaasa), \
},

Check notice on line 75 in include/zephyr/drivers/i3c/devicetree.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/i3c/devicetree.h:75 -#define I3C_DEVICE_DESC_DT(node_id) \ - { \ - .bus = DEVICE_DT_GET(DT_BUS(node_id)), \ - .dev = DEVICE_DT_GET(node_id), \ - .static_addr = DT_PROP_BY_IDX(node_id, reg, 0), \ - .pid = ((uint64_t)DT_PROP_BY_IDX(node_id, reg, 1) << 32)\ - | DT_PROP_BY_IDX(node_id, reg, 2), \ - .init_dynamic_addr = \ - DT_PROP_OR(node_id, assigned_address, 0), \ - .supports_setaasa = DT_PROP(node_id, supports_setaasa), \ +#define I3C_DEVICE_DESC_DT(node_id) \ + { \ + .bus = DEVICE_DT_GET(DT_BUS(node_id)), \ + .dev = DEVICE_DT_GET(node_id), \ + .static_addr = DT_PROP_BY_IDX(node_id, reg, 0), \ + .pid = ((uint64_t)DT_PROP_BY_IDX(node_id, reg, 1) << 32) | \ + DT_PROP_BY_IDX(node_id, reg, 2), \ + .init_dynamic_addr = DT_PROP_OR(node_id, assigned_address, 0), \ + .supports_setaasa = DT_PROP(node_id, supports_setaasa), \

/**
* @brief Structure initializer for i3c_device_desc from devicetree instance
Expand Down
Loading