Commit 653589c5 authored by Ryan McClelland's avatar Ryan McClelland Committed by Benjamin Cabé
Browse files

drivers: i3c: add controller handoff support



Add controller handoff

Signed-off-by: default avatarRyan McClelland <ryanmcclelland@meta.com>
parent e5ac786b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -11,6 +11,14 @@ zephyr_library_sources(
  i3c_common.c
)

if(CONFIG_I3C_NUM_OF_DESC_MEM_SLABS GREATER 0)
  zephyr_library_sources(i3c_mem_slab.c)
endif()

if(CONFIG_I3C_I2C_NUM_OF_DESC_MEM_SLABS GREATER 0)
  zephyr_library_sources(i3c_i2c_mem_slab.c)
endif()

zephyr_library_sources_ifdef(
  CONFIG_USERSPACE
  i3c_handlers.c
+16 −0
Original line number Diff line number Diff line
@@ -117,6 +117,22 @@ config I3C_INIT_RSTACT
	  This determines whether the bus initialization routine
	  sends a reset action command to I3C targets.

config I3C_NUM_OF_DESC_MEM_SLABS
	int "Number of I3C Device Descriptors Mem Slabs"
	default 3
	help
	  This is the number of memory slabs allocated from when
	  there is a device encounted through ENTDAA or DEFTGTS that
	  is not within known I3C devices.

config I3C_I2C_NUM_OF_DESC_MEM_SLABS
	int "Number of I2C Device Descriptors Mem Slabs"
	default 3
	help
	  This is the number of memory slabs allocated from when
	  there is a device encounted through DEFTGTS that is not
	  within known I2C devices.

config I3C_RTIO
	bool "I3C RTIO API"
	select EXPERIMENTAL
+490 −213

File changed.

Preview size limit exceeded, changes collapsed.

+171 −2

File changed.

Preview size limit exceeded, changes collapsed.

+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2024 Meta Platforms
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <string.h>
#include <stdlib.h>

#include <zephyr/drivers/i3c.h>

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(i3c, CONFIG_I3C_LOG_LEVEL);

K_MEM_SLAB_DEFINE(i3c_i2c_device_desc_pool, sizeof(struct i3c_i2c_device_desc),
	CONFIG_I3C_I2C_NUM_OF_DESC_MEM_SLABS, 4);

struct i3c_i2c_device_desc *i3c_i2c_device_desc_alloc(void)
{
	struct i3c_i2c_device_desc *desc;

	if (k_mem_slab_alloc(&i3c_i2c_device_desc_pool, (void **)&desc, K_NO_WAIT) == 0) {
		memset(desc, 0, sizeof(struct i3c_i2c_device_desc));
		LOG_INF("I2C Device Desc allocated - %d free",
			k_mem_slab_num_free_get(&i3c_i2c_device_desc_pool));
	} else {
		LOG_WRN("No memory left for I2C descriptors");
	}

	return desc;
}

void i3c_i2c_device_desc_free(struct i3c_i2c_device_desc *desc)
{
	k_mem_slab_free(&i3c_i2c_device_desc_pool, (void *)desc);
	LOG_DBG("I2C Device Desc freed");
}

bool i3c_i2c_device_desc_in_pool(struct i3c_i2c_device_desc *desc)
{
	const char *p =  (const char *)desc;
	ptrdiff_t offset = p - i3c_i2c_device_desc_pool.buffer;

	return (offset >= 0) &&
	       (offset < (i3c_i2c_device_desc_pool.info.block_size *
		   i3c_i2c_device_desc_pool.info.num_blocks)) &&
	       ((offset % i3c_i2c_device_desc_pool.info.block_size) == 0);
}
Loading