Commit Graph

864 Commits

Author SHA1 Message Date
Tom Burdick 006d9ffceb i2c: mcux transfer with callbacks
Implements i2c_transfer_cb for the mcux driver

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-08-11 14:12:13 -04:00
Tom Burdick a45ece6984 i2c: Adds i2c_transfer_async API for I2C
i2c_transfer_async is the asynchronous version of i2c_transfer where
the completion of the transfer is notified to the caller using a callback.

This can be used in conjuction with the common callbacks and datatypes
in async.h for directly doing an async transfer with an IPC object
to notify a thread.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-08-11 14:12:13 -04:00
Henrik Brix Andersen e84636d010 drivers: i2c: check if clock device is ready before accessing
Add check for device_is_ready() before accessing clock control devices.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-09 17:16:16 +02:00
Attie Grande 51b22060c9 drivers: i2c: sam0: Lock bus before referencing messages
The I2C bus lock did not previously enclose the referencing of the
transfers to conduct. If two attempts are made to use the bus at a
similar time, then one set of messages may have been transferred twice.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2022-08-09 12:29:13 +02:00
Kumar Gala 5a4d1f7ac3 i2c: shell: Remove prefix filtering of device list
The I2C shell would filter the list of devices it knows about to
ones that have a device name that starts with "I2C_".  It was the
case that the majority of I2C bus controller devices happened
to be named with the "I2C_" prefix, however there is no guarantee
that is the case.  With the remove of label properties from the
devicetree this is even more true.

For now remove the prefix filter and just return the full list
of devices.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-08 10:51:51 +02:00
Lucas Tamborrino b44572aaec drivers: i2c: esp32: fix node identification
This PR fixes the instances indexing in the driver's
initialization macros.

The use of DT_INST macros along with other node identifiers
was preventing the driver from initialize correctly in some
cases.

The driver requires the signal mux number value. Hence the need
to use the SoC's peripheral number information and DT_NODELABEL
macro for node id.

Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
2022-08-04 13:45:23 +02:00
Gerard Marull-Paretas 149fe06341 drivers: arc/designware: remove unused <soc.h>
The <soc.h> header is not required by a few ARC/Designware drivers, so
remove it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-03 07:46:14 -04:00
Tom Burdick 13aae8c61a i2c: NPCX Port use correct device define macro
I2C has its own set of device define macro wrappers to provide
automatic stats tracking when enabled for the device class. This
particular driver happened ot be missed in the transition.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-08-03 05:05:23 +01:00
Kumar Gala 84575930f5 i2c: Remove unncessary HAS_I2C_DW Kconfig symbol
The HAS_I2C_DW was to limit Kconfig visibility to only platforms
that utilize the I2C DW IP.  The Kconfig for I2C_DW depends on
DT_HAS_SNPS_DESIGNWARE_I2C_ENABLED which will cause the same
visbility limitation to only platforms that have I2C DW devicetree
nodes.  Thus we can remove HAS_I2C_DW and its references.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-01 18:01:44 +02:00
Kumar Gala dc3e86e7dc drivers: i2c: Update drivers to use devicetree Kconfig symbol
Update i2c drivers to use DT_HAS_<compat>_ENABLED Kconfig symbol
to expose the driver and enable it by default based on devicetree.

We remove 'depend on' Kconfig for symbols that would be implied by
the devicetree node existing.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-28 16:12:43 -05:00
Simon Hein d0921018fc drivers: Fix coding guidelines MISRAC:2012 Rule 14.4 do-whiles/Zero checks
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)

Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.

The commit is a subset of the original auditable-branch commit:
5d02614e34

Signed-off-by: Simon Hein <SHein@baumer.com>
2022-07-26 15:30:24 -04:00
Kumar Gala 35d93ef7bc drivers: i2c: esp32: Rework SDA/SDL pins as gpios in devicetree
For the !SOC_I2C_SUPPORT_HW_CLR_BUS in which we implement bus
reset via GPIOs, change the devicetree properties to be actual
gpio properties and update the code to reflect this.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-26 12:10:58 -05:00
HaiLong Yang efa0973473 drivers: i2c: improve gd32 i2c driver stability
This split the repeated START condition to STOP + START conditions.

The old implement may cause undefined behavior for gd32 i2c, like
enter STOP condition accidentally.

Signed-off-by: HaiLong Yang <hailong.yang@brainco.cn>
2022-07-25 15:14:21 +02:00
Alex Sergeev 269f664a98 drivers: i2c: gd32: Use correct FAST speed
Fixed bug where configured FAST speed causes FAST_PLUS speed to be applied.

Signed-off-by: Alex Sergeev <asergeev@carbonrobotics.com>
2022-07-25 09:38:41 +02:00
Tim Lin d7ccea6357 ITE: drivers/i2c: Add command queue mode not allowed condition
If the transaction of write or read is divided into two transfers
(not two messages), the command queue mode does not support.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2022-07-20 11:08:56 +02:00
Kumar Gala 8fb2210cfb emul: remove name param from bus register APIs
Rework the <BUS>_emul_register calls to not pass the name param.  The
name param is only used for logging and we can get it from the
struct <BUS>_emul instead.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-19 15:52:36 -05:00
Aaron Massey fc98549952 emul: Use DEVICE_DT_GET instead of DT_LABEL
DT nodes aren't guaranteed to define a label property. But emulated bus
controllers currently make use of this property to dispatch to the
associated emulator.

Have emulated bus controllers use DEVICE_DT_GET(node_id) to dispatch to
right target peripheral emulator. This also change makes emul_get_binding
and device_get_binding synonymous in behavior with respect to their
parameters.

This also strictly enforces a 1:1 correspondence between invocations of
DEVICE_DT_DEFINE and EMUL_DEFINE.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-19 11:43:30 -05:00
Aaron Massey 9d7b9dc807 emul: Simplify emulator bus initialization and API
Allow emulator creators to write an init function that can be used
across multiple busses so as to reduce the boilerplate and cognitive
load in creating an emulator.

Part of this change includes allowing access to the emul struct from a
field in a {bus}_struct api (e.g. i2c_struct), which removes the need for
sporadic usages of CONTAINER_OF to access the emul struct.

Overall, this change simplifies and reduces the amount of boilerplate
code to get a device emulator up and running, thus reducing excise work
to writing tests.

TEST=twister on accel,espi, and eeprom drivers tests

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-19 11:43:30 -05:00
Aaron Massey 1028459afd emul: Run clang-format
Run clang-format on all files touched by improved emulator API pull-request
that allowed access to the target device emulator from its bus api without
CONTAINER_OF usage.

drivers/i2c/i2c_emul.c
drivers/spi/spi_emul.c
include/zephyr/drivers/emul.h
include/zephyr/drivers/espi_emul.h
include/zephyr/drivers/i2c_emul.h
include/zephyr/drivers/spi_emul.h
subsys/emul/emul.c
subsys/emul/emul_bmi160.c
subsys/emul/espi/emul_espi_host.c
subsys/emul/i2c/emul_atmel_at24.c

TEST=twister on accel,espi, and eeprom drivers tests

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-19 11:43:30 -05:00
Gerard Marull-Paretas cad6865aaa drivers: i2c: nrfx_twim: constify twim_config
The twim_config structure is no longer modified at runtime, so it can be
placed in driver's config (const).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas 9974bb043f drivers: i2c: nrfx_twim: disable and restore state for bus recovery
TWIM peripheral needs to be disabled for bus recovery, otherwise SCL/SDA
lines will not be released. This patch makes sure to disable peripheral
if active, and, restore its state afterwards (including pin
configuration).

It is worth to note that a better solution would be to:

1. Define scl/sda pins as `-gpios` in DT
2. Use GPIO API in the driver to perform recovery (as some other drivers
   do)
3. Potentially use a "gpio" pinctrl state for this case

Unfortunately HAL is doing everything under the hood, so we have little
options to improve this unless we don't use it for such case. GPIO based
recovery should likely be generalized as many drivers seem to replicate
such _algorithm_.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas 6f26fa2912 drivers: i2c: nrfx_twim: enable device runtime PM
Enable device runtime PM on the I2C driver. Note that this mechanism
replaces the old nrfx_twim_enable/disable calls with
pm_device_runtime_get/put, which means that driver will not save power
unless CONFIG_PM_DEVICE_RUNTIME=y.

Some quick measurements on thingy_52 running the samples/sensor/hts221
show a decrease of ~2-3uA in average when enabling device runtime PM.
Note that the driver already had implicit PM before, so the change for
users will be ~none, except that they now must enable the PM subsystem
features. While this case is not the best example, the PM subsystem will
turn to be beneficial as a whole when all devices in the board implement
it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas 81f1bbacf4 drivers: i2c: nrfx_twim: drop init_twim shim
The function was just a shim to nrfx_twim_init, call it directly
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas a1f6163a58 drivers: i2c: nrfx_twim: create common init function
The device definition macro defined per-device init function, resulting
in a cluttered and hard to extend init function. Create a per-instance
IRQ connect function instead, which is called at init time by a common
function.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas 00ecc66677 drivers: i2c: nrfx_twim: enable/disable when resuming/suspending
The driver already implemented some sort of runtime PM by
unconditionally calling nrfx_twim_disable/enable. Perform the same
operations in the PM callback instead of doing a full init/deinit every
time.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas d3251c28aa drivers: i2c: nrfx_twim: remove redundant deinit_twim shim
The shim had no value, just call nrfx_twim_uninit directly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas 9d649a5a74 drivers: i2c: nrfx_twim: drop twim_initialized usage
The driver re-initialized itself on the twim_transfer call if it wasn't.
This condition was likely added because of some manual/custom PM
schemes. Drop it in preparation for runtime PM.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Gerard Marull-Paretas 7fad89f020 drivers: i2c: nrfx_twim: avoid init/deinit to update frequency
nrfx HAL does not support updating frequency at runtime, which means we
need to do a full init/deinit to update it when it is a matter of a
simple register write. Fix this by using the lower level HAL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-19 12:25:13 +00:00
Benjamin Björnsson e1c0a494b3 drivers: i2c: i2c_tca954x: Update driver to use i2c_dt_spec
Simplify driver by using i2c_dt_spec for bus access.

Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
2022-07-15 10:05:40 +02:00
Johann Fischer 5e5ea9a21d drivers: use unsigned int for irq_lock()
irq_lock() returns an unsigned integer key.
Generated by spatch using semantic patch
scripts/coccinelle/irq_lock.cocci

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-07-14 14:37:13 -05:00
Tim Lin 04c6d7569f ITE: drivers/i2c: Add command queue mode
Adding command queue mode can reduce the time between each byte to
improve the I2C bus clock stretching during I2C transaction.

I2C command queue mode of it8xxx2 can support I2C APIs including:
i2c_write(), i2c_read(), i2c_burst_read.

Test:
1. tests\drivers\i2c\i2c_api --> pass
2. Reading 16 bytes of data through i2c_burst_read() can reduce
   0.72ms(2.54ms->1.82ms) compared to the original pio mode when the
   frequency is 100KHz.
3. krabby platform can boot normally.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2022-07-13 10:15:32 +02:00
Andrzej Głąbek e530ba9152 drivers: i2c: nrfx: Fix i2c_recover_bus implementation for PINCTRL
When PINCTRL is enabled, the SCL and SDA pin numbers are not available
in configuration structures used for nrfx drivers initialization.
In this case, these pin numbers need to be obtained from peripheral
registers.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2022-07-08 20:05:49 +00:00
Kumar Gala 244519b497 i2c: xec: Update driver to use gpio_dt_spec
Simplify the implementation by using gpio_dt_spec.  Mostly
gpio_dt_spec is used as a common struct and lets us move
away from DT_INST_GPIO_LABEL.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-08 10:57:03 +02:00
Piotr Dymacz 20cb405e17 drivers: adjust cc13xx_cc26xx drivers for hal_ti update
The TI SimpleLink SDK got updated to version '4.40.04.04' in 'hal_ti'.
This introduced renames of some functions in HAL and has to be reflected
in Zephyr drivers which make use of them.

This renames 'PRCMPowerDomainStatus' to 'PRCMPowerDomainsAllOn' in all
affected 'cc13xx_cc26xx' drivers.

Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
2022-07-08 09:37:43 +02:00
Anas Nashif 49b36ead95 drivers: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Jun Lin d4abe64766 driver: i2c: npcx: clear FIFO status before a transaction starts
When an I2C transaction completes, the driver should clear all the FIFO
status. Otherwise, it has the chance to break the operation of the next
transaction. This commit sets the CLR_FIFO bit in the SMBFIF_CTS
register to clear all the FIFO status at the beginning of an I2C
transaction.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
2022-07-06 10:46:28 +02:00
Aymeric Aillet 81cc1abe75 drivers: i2c: tca954X: Enable driver if needed
TCA954X driver was not enabled since introduction of
new compatibility fields.

We now set I2C_TCA954X depending on related "okay"
compat fields in DT.

Signed-off-by: Aymeric Aillet <aymeric.aillet@iot.bzh>
2022-07-04 16:53:41 +02:00
Maureen Helm c969547527 drivers: i2c: Fix deprecated use of I2C_MODE_MASTER in mcux lpi2c driver
The I2C API recently updated terminology to replace "master" with
"controller", but this instance in the mcux lpi2c driver was missed.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-07-01 15:37:12 -05:00
Kumar Gala 287acdbb9d i2c: sam0: Set driver Kconfig default based on devicetree
Change Kconfig default to be based on if the devicetree has the
atmel,i2c-sam0 driver enabled.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-01 15:05:55 -05:00
Aurelien Jarno d576b7f3d3 drivers: i2c_ll_stm32_v2: add support for second target address
The Zephyr API supports multiple I2C targets addresses, and the STM32
I2C v2 implementation allows to define up to 2 targets addresses.

This patch adds support for a second I2C target address. It adds a new
config entry in the i2c_stm32_data structure, and uses the fact that
both addresses can be enabled and disabled independently. In the
interrupt, the target being addressed is determined using the address
match code from the interrupt status register.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-07-01 11:35:28 +02:00
Kumar Gala 78b1d950be drivers: i2c: lpc11u6x: Remove DT_LABEL usage
Remove DT_LABEL usage that is needed for device_get_binding, replace
this with DEVICE_DT_GET.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-06-30 10:32:33 +02:00
Tom Burdick 88ca215eed i2c: Update API terminology
Updates the API and types to match updated I2C terminology. Replaces master
with controller and slave with target.

Updates all drivers to match the changed macros, types, and API signatures.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-06-29 17:51:31 +02:00
Aymeric Aillet 9a7040303a drivers: clock: rcar: Rename global includes file
Rename r-car clock driver global include file
in order to match other files names.

Signed-off-by: Aymeric Aillet <aymeric.aillet@iot.bzh>
2022-06-28 18:11:44 +02:00
Erwan Gouriou 343fdddfdd drivers: i2c: stm32: Use device tree as single source of compatibility
Some text in help section was documenting the compatibility of driver
variants with stm32 series.
This is duplicate of information versus device tree which should be
used as single source of information for hardware description.
Remove these lines, so we don't have to touch this driver each time
a series is added.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-06-27 15:43:14 -05:00
Henrik Brix Andersen b7624bc5cf drivers: i2c: mcux: lpi2c: add bus recovery support
Add I2C bus recovery support to the NXP MCUX LPI2C driver. Since the LPI2C
peripheral block does not natively support I2C bus recovery, recovery is
performed using GPIO bitbanging.

Fixes: #42574

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-06-22 12:24:08 +02:00
Gerard Marull-Paretas 4946a15f15 soc: arm: gigadevice: use common API headers
Stop relying on <soc.h> to access HAL APIs. Use generic, per-API headers
instead. Note that <soc.h> has been left as is for now, since ARM MPU
relies on a fragile chain of includes/type definitions.

This change should improve compilation efficiency, as we no longer pull
APIs that are not needed. A similar approach is followed by STM32
drivers.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2022-06-22 18:41:19 +09:00
Tim Lin 19724ba002 ITE: drivers/i2c: Enable I2C interrupt after completing configuration
Fix the flow of I2C enable interrupt. We should enable the interrupt
after I2C configuration is completed to avoid pending interrupts and
cause errors irq.

Test port:
i2c_ite_it8xxx2: i2c0
i2c_ite_enhance: i2c4
Test:
tests\drivers\i2c\i2c_api --> pass

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2022-06-20 10:24:27 +02:00
Stephanos Ioannidis 745b7d202e drivers: i2c: Fix infinite recursion in driver unregister function
This commit fixes an infinite recusion in the
`z_vrfy_i2c_slave_driver_unregister` function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-06-17 02:19:51 +09:00
Wojciech Slenska 363989a40d drivers: i2c: sam_twi: Implement bus locking
Added bus locking mechanism, this patch resolves deadlocks
for more than one device on i2c bus, it is based on i2c_sam0 code.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2022-06-13 12:11:41 +02:00
Peter Marheine 95fb984f0b driver: i2c: npcx: prevent sleep during I2C transactions
Deep Sleep mode stops SMB module clocks which could interrupt ongoing
I2C transactions, so have the I2C driver acquire a PM lock at the
beginning of a transaction and release it at the end in order to ensure
the module remains active.

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
2022-06-05 14:47:58 +02:00