Commit graph

58 commits

Author SHA1 Message Date
Ryan McClelland c75783219f drivers: i3c: cdns: handle variable length ccc with m0 err
The CDNS will report a M0 error if the data length is not what
it expects, but certain CCCs can have a variable length such as
GETMXDS and GETCAPS. This sets it up to ignore the M0 error if
it sees that ccc was GETMXDS or GETCAPS.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-05-16 16:23:31 +02:00
Ryan McClelland bb66b7b870 drivers: i3c: shell: fix argc length check for optional param
GETSTATUS and GETMRL where not checking the right argc length. This
corrects it to check for the right count.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-05-16 16:23:31 +02:00
Ryan McClelland 328b03f56e drivers: i3c: shell: add ccc getcaps command
Add a shell command for the CCC GETCAPS

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-05-16 16:23:31 +02:00
Ryan McClelland e59d65536d drivers: i3c: add reading GETCAPS in basic_info_get
Add reading of GETCAPS CCC in `i3c_device_basic_info_get`.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-05-16 16:23:31 +02:00
Ryan McClelland 9640905a71 drivers: i3c: add ccc getcaps helper
This adds the defines for getcaps format 1 and format 2.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-05-16 16:23:31 +02:00
Ryan McClelland 014e879e6f drivers: i3c: use byte ordering macros with ccc
Use the sys_get_be* macros with ccc where it can be used.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-05-16 16:23:31 +02:00
Mike J. Chen 6b2fae0d01 drivers: i3c: i3c_mcux: reduce timeout busy waiting
For many of the state checks with timeout, the check
should be very fast (sub 1 microseconds) and the
previous implemention involving busy waits between
checks could add unneeded latency. Change the
timeout checking method to use WAIT_FOR(), with
no extra delays between checks.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2024-04-26 10:18:54 +03:00
Alvis Sun 629bfd9f9f drivers: i3c: i3c_shell: add alphabetical order constraint
Add /* zephyr-keep-sorted-start */ around DT_FOREACH_STATUS_OKAY.

Signed-off-by: Alvis Sun <yfsun@nuvoton.com>
2024-04-24 19:40:28 +00:00
Alvis Sun 5d33a4cffe drivers: i3c: i3c_shell: add nuvoton_npcx_i3c compat macro to i3c_shell.
As titile.

Signed-off-by: Alvis Sun <yfsun@nuvoton.com>
2024-04-24 19:40:28 +00:00
Alvis Sun c6763bd2ca drivers: i3c: npcx: introduce NPCX I3C driver
This implements basic driver to utilize the I3C IP block
on NPCX.

1. I3C mode: Main controller mode only.
2. Transfer: Support SDR only.
3. IBI: Support Hot-Join, IBI(MDB).
   Controller request is not supported.
4. Support 3 I3C modules:
   I3C1(3.3V), I3C2(1.8V, espi mode), (I3C3 1.8V or 3.3V)

Signed-off-by: Alvis Sun <yfsun@nuvoton.com>
2024-04-24 19:40:28 +00:00
Alvis Sun a3cd76b6f2 drivers: i3c: update i3c_dev_list_daa_addr_helper()
During DAA, the responding device might not be in the device list.
This CL adds target device descriptor's pointer checking to prevent
getting unexpected results.

Signed-off-by: Alvis Sun <yfsun@nuvoton.com>
2024-04-24 19:40:28 +00:00
Ryan McClelland 732c2e1989 i3c: add i3c shell
Add an I3C shell. This includes support of all I3C CCC commands that
currently have helper functions implemented. This also includes all
the read/write shell commands that the i2c shell supported. An Info
command is also provided which will print out all i3c and i2c info
of an i3c bus. Only SDR read/writes are currently implemented.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-04-20 13:46:26 -04:00
Mike J. Chen 5518b0c698 drivers: i3c: i3c_mcux: retry when timeout occurs in emit stop
Have seen timeout error occur when doing an emit stop at
end of a multiple register write to a mmc5633 mag sensor IC.
The i3c_mcux driver would return on such an error without
doing the k_condvar_broadcast(), since the stop wasn't
technically done (or unclear if it was), and then future
transfers requests waiting on the condvar could be blocked
forever. Add a limited retry when a timeout occurs to
avoid such a stall condition from happening.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2024-04-13 07:05:36 -04:00
Mike J. Chen fe4b03baf3 drivers: i3c: i3c_mcux: Fix bug in do_one_xfer
Error check was incorrect, causing wait for complete
not to be done. This can result in emit stop not
working on writes because controller won't do the
stop if it is still busy processing transmit.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2024-03-25 18:38:31 -04:00
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