# I3C configuration options
#
# Copyright (c) 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

menuconfig I3C
	bool "Improved Inter-Integrated Circuit (I3C) bus drivers"
	help
	  Enable I3C Driver Configuration

if I3C

module = I3C
module-str = i3c
source "subsys/logging/Kconfig.template.log_config"

choice I3C_MODE
	prompt "I3C Mode Selection"
	default I3C_DUAL_ROLE
	help
	  Select the role in which I3C is enabled.
	  At least one of Controller or Target must be enabled.

	  Selecting only one can reduce the code footprint size.

config I3C_CONTROLLER_ROLE_ONLY
	bool "I3C Controller only"

config I3C_TARGET_ROLE_ONLY
	bool "I3C Target only"

config I3C_DUAL_ROLE
	bool "Both I3C Controller and Target"

endchoice

config I3C_CONTROLLER
	bool
	default y if I3C_DUAL_ROLE || I3C_CONTROLLER_ROLE_ONLY

config I3C_TARGET
	bool
	default y if I3C_DUAL_ROLE || I3C_TARGET_ROLE_ONLY

config I3C_SHELL
	bool "I3C Shell"
	depends on SHELL
	help
	  Enable I3C Shell.

	  The I3C shell supports info, bus recovery, CCC, I3C read and
	  write operations.

config I3C_TARGET_BUFFER_MODE
	bool "I3C target driver for buffer mode"
	depends on I3C_TARGET
	help
	  This is an option to enable buffer mode.

menuconfig I3C_USE_IBI
	bool "Use In-Band Interrupt (IBI)"
	default y
	help
	  Enable this to use In-Band Interrupt (IBI).

	  Says Y if unsure.

if I3C_USE_IBI

config I3C_IBI_MAX_PAYLOAD_SIZE
	int "Maximum IBI Payload Size"
	default 16
	help
	  Maximum IBI payload size.

menuconfig I3C_IBI_WORKQUEUE
	bool "Use IBI Workqueue"
	help
	  Use global workqueue for processing IBI.

	  This is enabled by driver if needed.

if I3C_IBI_WORKQUEUE

config I3C_IBI_WORKQUEUE_STACK_SIZE
	int "IBI workqueue stack size"
	default 1024
	help
	  Stack size for the IBI global workqueue.

config I3C_IBI_WORKQUEUE_PRIORITY
	int "IBI workqueue thread priority"
	default -1
	help
	  Thread priority for the IBI global workqueue.

config I3C_IBI_WORKQUEUE_LENGTH
	int "IBI workqueue queue length"
	default 8
	help
	  Define the maximum number of IBIs that can be
	  queued in the workqueue.

config I3C_IBI_WORKQUEUE_VERBOSE_DEBUG
	bool "Verbose debug messages for IBI workqueue"
	help
	  This turns on verbose debug for the IBI workqueue
	  when logging level is set to DEBUG, and prints
	  the IBI payload.

endif # I3C_IBI_WORKQUEUE

endif # I3C_USE_IBI

comment "Initialization Priority"

config I3C_CONTROLLER_INIT_PRIORITY
	int "I3C Controller Init Priority"
	# Default is just after CONFIG_KERNEL_INIT_PRIORITY_DEVICE
	default 50
	help
	  This is for setting up I3C controller device driver instance
	  and also to perform bus initialization (e.g. dynamic address
	  assignment).

	  Note that this needs to be done before the device driver
	  instances of the connected I2C and I3C devices start
	  initializing those devices. This is because some devices
	  may not be addressable until addresses are assigned by
	  the controller.

config I3C_INIT_RSTACT
	bool "Perform Reset Action During Bus Initialization"
	default y
	help
	  This determines whether the bus initialization routine
	  sends a reset action command to I3C targets.

if I3C_CONTROLLER && I3C_TARGET

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 encountered 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 encountered through DEFTGTS that is not
	  within known I2C devices.

endif # I3C_CONTROLLER && I3C_TARGET

if I3C_CONTROLLER

config I3C_RTIO
	bool "I3C RTIO API"
	select EXPERIMENTAL
	select RTIO
	select RTIO_WORKQ
	help
	  API and implementations of I3C for RTIO

if I3C_RTIO
config I3C_RTIO_SQ_SIZE
	int "Submission queue size for blocking calls"
	default 4
	help
	  Blocking i3c calls when I3C_RTIO is enabled are copied into a per driver
	  submission queue. The queue depth determines the number of possible i3c_msg
	  structs that may be in the array given to i3c_transfer. A sensible default
	  is going to be 4 given the device address, register address, and a value
	  to be read or written.

config I3C_RTIO_CQ_SIZE
	int "Completion queue size for blocking calls"
	default 4
	help
	  Blocking i3c calls when I3C_RTIO is enabled are copied into a per driver
	  submission queue. The queue depth determines the number of possible i3c_msg
	  structs that may be in the array given to i3c_transfer. A sensible default
	  is going to be 4 given the device address, register address, and a value
	  to be read or written.

config I3C_RTIO_FALLBACK_MSGS
	int "Number of available i3c_msg structs for the default handler to use"
	default 4
	help
		When RTIO is used with a driver that does not yet implement the submit API
		natively the submissions are converted back to struct i3c_msg values that
		are given to i3c_transfer. This requires some number of msgs be available to convert
		the submissions into on the stack. MISRA rules dictate we must know this in
		advance.

		In all likelihood 4 is going to work for everyone, but in case you do end up with
		an issue where you are using RTIO, your driver does not implement submit natively,

endif # I3C_RTIO

endif # I3C_CONTROLLER

comment "Device Drivers"

# zephyr-keep-sorted-start
rsource "Kconfig.cdns"
rsource "Kconfig.dw"
rsource "Kconfig.it51xxx"
rsource "Kconfig.max32"
rsource "Kconfig.npcx"
rsource "Kconfig.nxp"
rsource "Kconfig.renesas"
rsource "Kconfig.stm32"
rsource "Kconfig.test"
# zephyr-keep-sorted-stop

endif # I3C
