Commit Graph

44 Commits

Author SHA1 Message Date
Mike J. Chen f55d281536 drivers: i3c: i3c_mcux: a number of improvements and bug fixes
The main improvement is that mcux_i3c_transfer() and
mcux_i3c_i2c_api_transfer() will try much harder to not return an error
that could be caused by the bus being busy. The bus could be busy because
of IBI handling, especially if there are multiple I3C devices all raising
IBI that need to be processed, which can involve a number of context
switches and delays and take considerable time such that an application
initiated I3C transfer request might have returned busy. Replaced the code
that polled for idle state with a timeout with an infinite loop on a
condvar. The condvar is broadcast to at the end of every stop, which should
be when the bus goes idle.

Details of other changes:

* Remove ibi_lock, which seemed not useful. Use the single lock (switched
  from semaphore to mutex so it can be released by condvar) for both IBI
  handling and application requests.

* Remove code that disables i3c controller interrupts during transfers.
  Since the only interrupt is SLVSTART, and that just posts a work, it
  didn't seem necessary to disable that interrupt.

* Don't clear SLVSTART interrupt in mcux_i3c_status_clear_all(), to prevent
  any application transfers from accidentally clearing the SLVSTART
  interrupt or the handling of one IBI clearing the START initiated by
  another I3C device immeidately as the other one finishes.
  The only clearing of SLVSTART is in the isr.

* Add back a wait in mcux_i3c_request_auto_ibi(), otherwise the ibitype
  could be 0 if the processor is faster than the auto ibi handling.
  An earlier change removed a wait for MCTRLDONE, which isn't
  always set when AUTO_IBI is requested, but that could mean we try to
  read the ibitype before it's ready. Waiting for IBIWON instead should be
  correct and better, since the AUTO_IBI should result in IBIWON status bit
  being set (and MCTRLDONE being set would not guarantee that IBIWON was
  set).

* Change mcux_i3c_request_emit_stop() to still wait for idle if requested,
  even if the STOP wasn't actually issued, and add the release of the new
  condvar

* Change mcux_i3c_do_one_xfer_read() to handle the IBI use case differently
  than the regular application requested transfer case. In the application
  requested transfer case, the rx_len is known and set in RDTERM, so we
  could check for the COMPLETE status bit, but for IBI transfers, we
  just do a read to the payload buffer without knowing how many bytes
  the target may send us so never get a COMPLETE. Rather than check for a
  COMPLETE bit that might never occur, just have both cases read until we
  either read all requested bytes or we get a timeout error. But for the
  timeout error, if it's IBI and non-zero bytes were received, return
  the bytes received instead of an error.

* Change mcux_i3c_do_one_xfer() to return the error returned by
  mcux_i3c_do_one_xfer_read/write().

* Remove spurious return -EIO from end of mcux_i3c_do_daa()

* Change mcux_i3c_ibi_enable() to restore SLVSTART on error, and
  add some LOG_ERR() messages for error cases. Also add check to
  make sure idx is valid since there is a limit to how many IBI
  this controller can support.

* Change mcux_i3c_ibi_disable() to always reenable SLVSTART interrupt,
  even if the CCC to tell the target to disable IBI events fails.

* Change mcux_i3c_isr() to reenable SLVSTART interrupt if the
  work_enqueue() fails.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2024-02-29 11:52:34 +00:00
Roman Studenikin 260fc89643 drivers: use DT_INST_PROP over DT_INST_PROP_OR if possible
It might happens that DT(_INST)_PROP_OR is used with boolean properties.
For instance:

	.single_wire = DT_INST_PROP_OR(index, single_wire, false),	\
	.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false),	\

This is not required as boolean properties are generated with false
value when not present, so the _OR macro extension is superflous
and the above code can be replaced by:

	.single_wire = DT_INST_PROP(index, single_wire),		\
	.tx_rx_swap = DT_INST_PROP(index, tx_rx_swap),			\

Signed-off-by: Roman Studenikin <srv@meta.com>
2024-01-30 00:26:58 +00:00
Ryan McClelland b4768d5d42 drivers: i3c: cdns: run clang-format
Run the clang-formatter. This just changes white-space on defines.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-12-15 14:39:38 +01:00
Ryan McClelland 9c22c82604 drivers: i3c: cdns: handle controller aborts
Some targets do not give EoD at the end of a register read. They will
auto increment their address pointer on to the next address, but that
may not be of interest to the application where the buffer size will
only be set to the size of only that register. If the target, does
not give an EoD, then the Controller will give an Abort... but this
should not be treated as an error in this case.

There is still however a case where an abort Error shall still be
considered as an error. Athough the driver does not support it yet,
threshold interrupts are to be used if the length of the buffer
exceeds the size of the fifo. There could be the case where the
cpu can not get around fast enough to pop out data out of the rx
fifo and it will fill up. The controller will just give an abort
as it can not take any more data.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-12-15 14:39:38 +01:00
Ryan McClelland 07557e3c62 drivers: i3c: mcux: write back total number of bytes transferred
Write back the total number of bytes actually transferred.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-12-04 16:48:20 +01:00
Ryan McClelland 1e663dbedc drivers: i3c: cdns: write back total number of bytes transferred
The command response buffer will return the total number of bytes
transfered. This will write back to the pointer which is to contain
the number of bytes sent or received.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-12-04 16:48:20 +01:00
Ryan McClelland 48e514f662 drivers: i3c: rename dcr i2c mode macro to lvr
This renames the I2C 'DCR' mode to 'LVR' as that is the variable it
should be looking at and not the dcr value. This also fixes the get
'lvr' mode argument.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-12-01 10:48:31 +00:00
Ryan McClelland 1e91453005 drivers: i3c: cdns: use deterministic timeout for idle
Previously, the idle bit would be read for X amount of times. This
could vary alot depend on the CPU speed. Timeout is now to happen
from the cycle time.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-11-29 10:29:30 +01:00
Armando Visconti 0d9654670f drivers: i3c: add dummy driver for vnd,i3c
It is just used to be able to DEVICE_DT_GET() bus devices from
tests/drivers/build_all in an upcoming commit.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2023-11-13 16:08:46 +00:00
Ryan McClelland 9ddc94e0d4 drivers: i3c: specify start addr when searching for a free addr
For example, if a driver needed to reserve address before it does a
ENTDAA, it would need to get free address in a loop, but the get
free address func would return the same address everytime. It needs
the start address, which would be the last free address it go, to
be passed in to get the next free address.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-11-13 09:43:26 +01:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif ee9f278323 syscall: rename Z_SYSCALL_VERIFY -> K_SYSCALL_VERIFY
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 1a9de05767 syscall: rename Z_SYSCALL_DRIVER_ -> K_SYSCALL_DRIVER_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif df9428991a syscall: Z_SYSCALL_MEMORY_ARRAY -> K_SYSCALL_MEMORY_ARRAY
Rename macros and do not use Z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Mike J. Chen b0a5492026 drivers: i3c: mcux: Add dt property disable-open-drain-high-pp
The default is that the high time for open-drain clk is one
PPBAUD, which is typically very short. Some device require
a longer high time during the open-drain address phase so
add a property to allow device tree to override the default.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-10-27 10:50:16 +02:00
Mike J. Chen f344019f2d drivers: i3c: mcux: Remove infinite wait for MCTRLDONE in auto-IBI
Remove the MCTRLDONE wait in mcux_i3c_request_auto_ibi().
I've seen this code getting stuck where the MCTRLDONE
bit is never set in the MSTATUS register by the controller
and this function spins forever. Documentaiton of the
MCTRLDONE bit only mentions it being set for EmitStartAddr
and ProcessDAA, but not for AutoIBI requests.

All the calls to this function do completion checks
afterwards, and with a timeout, so I believe the MCTRLDONE
check is not needed (and may not even be correct).

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-10-27 10:50:16 +02:00
Mike J. Chen 1193049c0a drivers: i3c: mcux: tighten the FIFO read
At high i3c rates, the mcux_i3c_do_one_xfer_read()
could get into an infinite loop where the rx_count
kept returning 0 but the complete status bit
was never set. I believe the problem was that
the function was not emptying the FIFO fast enough,
so tighten the loop that processes the FIFO.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-10-27 10:50:16 +02:00
Mike J. Chen 7c1884ae9b drivers: i3c: mcux: send 7h7e on first transfer or after stop
Makes the i3c_mcux driver consistent with the i3c_cdns driver.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-10-27 10:50:16 +02:00
Mike J. Chen 16f4861741 drivers: i3c: mcux: fix config_get to return last config set
mcux_i3c_configure() was saving values to a ctrl_config_hal
struct, but config_get() was not returning the values in
that struct. Remove that struct from the static data of
the driver and instead just have it on the stack. We init
that struct as needed just before calling the SDK API
I3C_MasterInit(). There's no reason to keep it around.
Change mcux_i3c_configure() to save a copy of the configuration
in the static data common.ctrl_config, which is what is
returned by config_get().

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-10-27 10:50:16 +02:00
Ryan McClelland 10b85602e6 drivers: i3c: fix cdns-i3c builds with I3C_USE_IBI=n
The Cadence I3C was not building with CONFIG_I3C_USE_IBI, this fixes
the build and will give a small code size reduction when enabled.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-09-13 16:32:55 +02:00
Ryan McClelland 1b63e49b3f drivers: i3c: cdns: fix transfers while not idle
If a transfer happen in rapid sucession. It was possible for
the core to not be ready to accept another command. Poll on
the idle status bit until the core is ready to accept new data.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-09-13 16:28:55 +02:00
Ryan McClelland 696acc78e0 drivers: i3c: cdns: fix reading error after transfer
Due to a bug, after a completed transfer happen. Only the first
command response error was read. This fixes the issue so all
commands are read for if an error occurred.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-09-13 16:28:55 +02:00
Daniel Leung 26ecaba4af drivers: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Mike J. Chen 42b121ee95 drivers: i3c: mcux: fix issues when only i2c devices are on the bus
Fixes for bug:
https://github.com/zephyrproject-rtos/zephyr/issues/57560

* don't do CCC if no i3c devices in device tree
* don't wait for MCTRLDONE status when issuing stop
* don't do data part of transfer if buf_sz is 0
* don't limit transfers to only i2c devices in the device tree
  so "i2c scan" shell cmd works as expected

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-05-17 09:34:31 -05:00
Mahesh Mahadevan d3a3e54f55 drivers: i3c: Fix Build failure on MCUX I3C
Fix build failure introduced by commits
989d103d53 and
62f22f8d3b

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-05-15 15:26:32 +02:00
Gerard Marull-Paretas 989d103d53 drivers: all: mcux: remove conditional support for pinctrl
The MCUX platform always uses pinctrl, there's no need to keep extra
macrology around pinctrl. Also updated driver's Kconfig options to
`select PINCTRL` (note that some already did).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-24 13:34:22 +02:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Gerard Marull-Paretas 6ec50005db drivers: i3c: cdns: remove local DIV_ROUND_UP
The definition is already provided by zephyr/sys/util.h.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Ryan McClelland 28bb21cfe6 drivers: i3c: cdns: set tx fifo threshold interrupt to half the fifo
When a controller is running at full SDR speed at 12.5MHz, there needs
to be enough time for the processor get around to writing more data in
the fifo. Previously at -1 the size, this was enough for 1MHz with a
decent processor, but not enough at a 12.5MHz SCL.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-04-01 07:37:03 -04:00
Ryan McClelland b68492166a drivers: i3c: cdns: add attach/detach api implementation
The cadence i3c ip requires it's retaining registers to be updated
when a device is detached or attached.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-03-29 07:46:37 -04:00
Ryan McClelland 62f22f8d3b drivers: i3c: i3c attach/detach api
There are some needs to attach and reattach i3c/i2c devices at runtime
Some I2C devices can have special registers where the address can be
changed at runtime. Also some I3C devices can be powered off at runtime
freeing up the address space they take up. These new APIs allow for these
to be changed at runtime. This also moves some config/data in to a common
i3c config/data structure which would allow the api to operate on to be
common for all I3C drivers.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-03-29 07:46:37 -04:00
Ryan McClelland 2f02d6ca81 drivers: i3c: cdns: add reattach api implementation
This adds the reattach api necessary for writing the i3c retaining
registers within the cdns i3c when the dynamic address changes.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-03-29 07:46:37 -04:00
Ryan McClelland 1f757bc67f 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>
2023-03-29 07:46:37 -04:00
Ryan McClelland 71c5ccb1ef drivers: i3c: add reattach_i3c_device api
Some I3C controllers have retaining registers which are used to contain
the DA of the i3c device. This needs to be updated every time the DA is
updated with SETNEWDA or SETDASA

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-03-29 07:46:37 -04:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Ryan McClelland 672a401f20 i3c: add cdns i3c driver
This gives initial support to the cadence i3c controller

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-12-12 15:51:16 -05:00
Ryan McClelland 371470d608 i3c: GETMWL and GETMRL may be optionally supported if no settable limit
According to section 5.1.9.3.5 and 5.1.9.3.6 of the I3C Specification
v1.1.1. This CCC is may be optionally supported if the target device
has no settable limit.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-12-12 15:51:16 -05:00
Ryan McClelland b7dc01cd48 i3c: rename is_primary to is_secondary
Rename is_primary to is_secondary. The justification for this is
because it is less likely to have something configured to be
secondary, and the 0 value would be if it is primary.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-12-12 15:51:16 -05:00
Ryan McClelland ce6da0fb51 i3c: fix ccc setmrl/setmwl helper addr
i3c CCC SETMRL/SETMWL were using the static addr, the
dynamic address must be used

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-10-14 12:27:39 -04:00
Daniel Leung 3e8f97009d i3c: add I3C controller driver for MCUX
This adds a very basic driver to utilize the I3C IP block
on MCUX (e.g. RT685). Note that, for now, this only supports
being the active controller on the bus.

Origin: NXP MCUXpresso SDK
License: BSD 3-Clause
URL: https://github.com/zephyrproject-rtos/hal_nxp
Commit: 2302a1e94f5bc00ce59db4e249b688ad2e959f58
Purpose: Enabling the I3C controller on RT685.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-09-09 17:42:33 -04:00
Daniel Leung 66a9a15104 i3c: add a global workqueue for IBI
Adds support for a global workqueue so drivers can defer
IBI callbacks instead of doing it in interrupt context.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-09-09 17:42:33 -04:00
Daniel Leung ce7058d2f5 drivers: i3c: introduce I3C API for controllers
This introduces the I3C API for I3C controllers. Currently,
this supports one controller per bus under Zephyr.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-09-09 17:42:33 -04:00