Commit graph

134 commits

Author SHA1 Message Date
Rafael Laya a55ebe1377 drivers: Fixes Controller Mode for I2C DW Driver
4996a9be262ca81bae717bdd8c2939db2a6876b7 adds Target Support for the
Designware I2C Driver

But the change missed guarding some places with
CONFIG_I2C_TARGET

This commit fixes regressions caused by such change

Signed-off-by: Rafael Laya <rafael_laya97@hotmail.com>
2024-05-08 09:30:45 -04:00
Tom Burdick 4180d70439 dma: Fix error_callback enable/disable confusion
Previously the logic was inverted for error_callback_en where 0 was
enablement and 1 was disable. This was likely done so that the default,
sensibly so, was to enable the error callback if possible. A variety of
in tree users had confused the enable/disable value.

Change the name of the flag to error_callback_dis where the default
remains 0 (do not disable the callback!) and correct in tree uses of the
flag where it seemed incorrect.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-04-11 17:08:10 -04:00
Pisit Sawangvonganan 70c7ac704d drivers: i2c: correct spelling
Employ a code spell checking tool to scan and correct spelling errors
in all files within the drivers/i2c directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-15 09:59:17 +01:00
Adrien Ricciardi 4824e405cf drivers: i2c: i2c_dw: Fixed integer overflow in i2c_dw_data_ask().
The controller can implement a reception FIFO as deep as 256 bytes.
However, the computation made by the driver code to determine how many
bytes can be asked is stored in a signed 8-bit variable called rx_empty.

If the reception FIFO depth is greater or equal to 128 bytes and the FIFO
is currently empty, the rx_empty value will be 128 (or more), which
stands for a negative value as the variable is signed.

Thus, the later code checking if the FIFO is full will run while it should
not and exit from the i2c_dw_data_ask() function too early.

This hangs the controller in an infinite loop of interrupt storm because
the interrupt flags are never cleared.

Storing the rx_empty empty on a signed 32-bit variable instead of a 8-bit
one solves the issue and is compliant with the controller hardware
specifications of a maximum FIFO depth of 256 bytes.

It has been agreed with upstream maintainers to change the type of the
variables tx_empty, rx_empty, cnt, rx_buffer_depth and tx_buffer_depth to
plain int because it is most effectively handled by the CPUs. Using 8-bit
or 16-bit variables had no meaning here.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2024-01-08 20:57:05 -06:00
Anisetti Avinash Krishna 53b717edd6 drivers: i2c: i2c_dw: update DMA node access in I2C dw
Update DMA node access from paren-node to dmas property in dts instance.

Signed-off-by: Anisetti Avinash Krishna <anisetti.avinash.krishna@intel.com>
2023-12-22 09:52:59 +01:00
Bindu S 877208dc78 drivers: i2c: i2c_dw: Added intel lpss dma support for I2C
Enabled intel LPSS DMA interface using dw common to support
usage of internal DMA in LPSS I2C to transfer and
receive data.

Signed-off-by: Bindu S <bindu.s@intel.com>
2023-09-26 12:02:23 +02:00
TOKITA Hiroshi e2f47c0c38 drivers: i2c: i2c_dw: Add capability for handling reset device
Reset the device on initializing if reset-node is available in dts.
`snps,desingware-i2c` does not define reset-node itself.
Add more of an element that inherits `reset-device.yaml` to
the `compatible` section to allow defining the reset-node
for using this feature.

For example.

```
compatible = "reset-device-inherit-node", "snps,designware-i2c";
```

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-09-11 11:10:12 +02:00
Corey Wharton 46ba5e5518 drivers: i2c: i2c_dw: add bus mutex
This change adds a mutex to protect against simultaneous access to the bus
instead of returning an error during transfers. Since most I2C code doesn't
handle retries (especially with a -EIO code) not blocking on a mutex can
cause a number of problems.

Signed-off-by: Corey Wharton <xodus7@cwharton.com>
2023-04-07 13:17:43 +02:00
Dennis Wang 357c6dba45 driver: i2c: Fix Controller Initialization
Change Summary: The TX/RX FIFO was not flush on initialization thus
causing bad transactions. Thus, we need to flush the FIFO, and
according to Synopsys DW I2C spec, we can flush TX/RX FIFO by clearing
the enable bit. This is verified with our own I2C test on the SoC with
Synopsys DW I2C IP.

Signed-off-by: Dennis Wang <dennisjw@fb.com>
2022-12-28 10:43:34 +01:00
Johan Hedberg 3c762f845e drivers: i2c_dw: Convert to use dynamic BDF lookup
Use the new PCIe core infrastructure for looking up the BDF at runtime
based on the VID/DID values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-16 11:18:43 +01:00
Henrik Brix Andersen 3c99a1e015 drivers: pcie: reintroduce support for I/O BARs
Reintroduce support for accessing I/O BARs which was removed in
43d84147d9.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09: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 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
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Esteban Valverde 426c1f6aff drivers: i2c: Fix get_regs() to happen after DEVICE_MMIO_MAP
Fixing a bug where get_regs() was being executed before MMIO mapping
moving the declaration of reg_base after DEVICE_MMIO_MAP

Signed-off-by: Esteban Valverde <esteban.valverde.vega@intel.com>
2022-04-29 08:56:49 +02:00
Tomasz Bursztyka 9a18fdea3f drivers: Check and fix device const qualifier on ISR
Re-running the script that checks for the const qualifier missing on
struct device ISR's parameter.

The script also changes the parameter 'arg' to 'dev' when relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-03-16 12:33:12 +01:00
Andrei-Edward Popa 6d5ec5a0d5 drivers: i2c: added slave support for DW
added slave mode support for I2C designware chip

Signed-off-by: Andrei-Edward Popa <andrei_edward.popa@upb.ro>
2022-02-21 19:42:07 -05:00
Andrei-Edward Popa e1f91db622 drivers: i2c: i2c_dw: added pinctrl support
added pinctrl support for designware i2c driver

Signed-off-by: Andrei-Edward Popa <andrei_edward.popa@upb.ro>
2022-02-21 19:42:07 -05:00
Tomasz Bursztyka f7a2ff4f8d drivers: Fixing the 2 drivers for PCIe IRQ connection
Now these 2 drivers should be working properly in case of IRQ remapping.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-07 10:47:27 -05:00
Tom Burdick 7b1349cfe6 stats: i2c: I2C stats
Adds the ability for I2C drivers to report synchronous transfer stats
using a I2C specific macro to define the device instance.

The macro creates a container for device_state which allows for per
instance device class common data structure to be used in the device
class api (ex: i2c.h). This is used to maintain per driver instance
stats for all i2c drivers. This is a reusable idea across other device
classes as desired.

Using Kconfig device class stats may be turned on/off individually
this way as well, in this case I2C_STATS.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2021-12-04 07:22:56 -05:00
Gerard Marull-Paretas 89a4f36fc8 device: remove inclusion of pm/device.h
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-29 11:08:38 +01:00
Tomasz Bursztyka f70ecc1099 drivers/pcie: Improve and fix MBAR retrieval depending on use cases
So far pcie_get_mbar() has been the only way to retrieve a MBAR. But
it's logic does not fit all uses cases as we will see further.
The meaning of its parameter "index" is not about BAR index but about
a valid Base Address count instead. It's an arbitrary way to index
MBARs unrelated to the actual BAR index.

While this has proven to be just the function we needed so far, this has
not been the case for MSI-X, which one (through BIR info) needs to
access the BAR by their actual index. Same as ivshmem in fact, though
that one did not generate any bug since it never has IO BARs nor 64bits
BARs (so far?).

So:

- renaming existing pcie_get_mbar() to pcie_probe_mbar(), which is a
  more relevant name as it indeed probes the BARs to find the nth valid
  one.
- Introducing a new pcie_get_mbar() which this time really asks for the
  BAR index.
- Applying the change where relevant. So all use pcie_probe_mbar() now
  but MSI-X and ivshmem.

Fixes #37444

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-08-20 06:30:20 -04:00
Gerard Marull-Paretas 70322853a8 pm: device: move device busy APIs to pm subsystem
The following device busy APIs:

- device_busy_set()
- device_busy_clear()
- device_busy_check()
- device_any_busy_check()

were used for device PM, so they have been moved to the pm subsystem.
This means they are now prefixed with `pm_` and are defined in
`pm/device.h`.

If device PM is not enabled dummy functions are now provided that do
nothing or return `-ENOSYS`, meaning that the functionality is not
available.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-30 09:28:42 -04:00
Gerard Marull-Paretas a8245f78a1 drivers: i2c: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 10:55:49 -04:00
Johan Hedberg 776fbf2d26 drivers: i2c_dw: Remove CMake-based templating
With some additional macro-magic we can remove the CMake-based header
file template feature, and instead take advantage of the usual
DT_INST_FOREACH_STATUS_OKAY() macro.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-04-21 20:40:52 -04:00
Flavio Ceolin a6183cff87 pm: docs: sys_suspend -> pm_system_suspend
Change references to an old function name.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-22 12:42:30 -04:00
Satoshi Ikawa f47f23f1a0 drivers: i2c_dw: Convert to use register for RX/TX buffer depth
RX/TX buffer depth are configurable parameters of DW_apb_i2c.

Change code from using fixed value I2C_DW_FIFO_DEPTH to using
register ic_comp_param_1 for RX/TX buffer depth.

Signed-off-by: Satoshi Ikawa <ikawa.satoshi@socionext.com>
2021-03-09 14:16:35 +01:00
Watson Zeng faba1100ea drivers: i2c: DW i2c: use 32 bit access instead of 16 and 32 bit mix
Current DW I2C driver uses 32 bit access for some registers and
16 bit access for others. So if DW I2C IP is connected via bus
which doesn't support 16 bit access we will get bus error.

Fix that by switching to 32 bit access only instead of 16
and 32 bit mix.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2021-03-06 09:33:24 -05:00
James Harris b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Johan Hedberg 05f8dd9ab9 drivers: i2c_dw: Remove hard-coded instance count assumption
Introduce a Kconfig variable that the SoC can set to indicate the
number of instances in Device Tree. This also fixes the accuracy of
the Elkhart Lake instance count where the code was previously assuming
up to 12 instances even though DT lists 15 nodes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-01-19 14:52:29 -05:00
Johan Hedberg 704ddaa9c3 drivers: i2c_dw: User proper PCIe DT hierarchy
Move all PCIe-based DT nodes under a PCIe bus and take advantage of
the DT_ANY_INST_ON_BUS_STATUS_OKAY() and DT_INST_ON_BUS() macros.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-01-19 14:52:29 -05:00
Dan Kalowsky 553a6e34a8 drivers: i2c_dw: add 4 additional ports
Add an additional 4 ports for upcoming Arm based server that will have a
total of 12 I2C ports.

Similar to the original 8 ports, these additional 4 ports will not be
enabled unless specified at configuration time.

Signed-off-by: Dan Kalowsky <dkalowsky@amperecomputing.com>
2020-12-17 21:52:41 -06:00
Maximilian Bachmann 3c8e98cb39 drivers/pcie: Change pcie_get_mbar() to return size and flags
currently pcie_get_mbar only returns the physical address.
This changes the function to return the size of the mbar and
the flags (IO Bar vs MEM BAR).

Signed-off-by: Maximilian Bachmann <m.bachmann@acontis.com>
2020-11-20 09:36:22 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Flavio Ceolin 0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Tomasz Bursztyka 98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Tomasz Bursztyka af6140cc0d device: Apply config_info rename everywhere
Via coccinelle:

@r_device_config@
struct device *D;
@@

D->
-	config_info
+	config

And 2 grep/sed rules for macros:

git grep -rlz 'dev)->config_info' |
	xargs -0 sed -i 's/dev)->config_info/dev)->config/g'

git grep -rlz 'dev->config_info' |
	xargs -0 sed -i 's/dev->config_info/dev->config/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Andrew Boie 9e627ed6d2 drivers: i2c_dw: use device_mmio
Fairly straightforward example of how to deal with PCIe.
The code considers whether a particular instance is PCIe
or not on a per-instance basis, so DEVICE_MMIO_ROM is not
conditionally defined.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-17 11:38:18 +02:00
Peter Bigot 78f14aa91d drivers: i2c_dw: remove inappropriate assignment of API pointer
This is set when the device is defined, and should not be modified.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-16 10:46:39 -05:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Martí Bolívar 87e1743ae0 devicetree: replace DT_HAS_DRV_INST with DT_INST_FOREACH
Make drivers multi-instance wherever possible using DT_INST_FOREACH.
This allows removing DT_HAS_DRV_INST in favor of making drivers just
do the right thing regardless of how many instances there are.

There are a few exceptions:

- SoC drivers which use CMake input files (like i2c_dw.c) or otherwise
  would require more time to convert than I have at the moment. For the
  sake of expediency, just inline the DT_HAS_DRV_INST expansion for
  now in these cases.

- SoC drivers which are explicitly single-instance (like the nRF SAADC
  driver). Again for the sake of expediency, drop a BUILD_ASSERT in
  those cases to make sure the assumption that all supported SoCs have
  at most one available instance is valid, failing fast otherwise.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-06 17:35:08 -05:00
Kumar Gala 26bfddf1ee drivers: i2c: i2c_dw: Move to devicetree detection
We can utilize the devicetree macros to determine which instances to
enable.  This will allow us to phase out the per instance Kconfig
symbols.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-05 14:44:25 -05:00
Charles E. Youse 6e89842d3d drivers/i2c/i2c_dw: really, really make 64-bit clean
The base_address in the device configuration is used as a handle
to access an entity in memory. In C, we call that a 'pointer'.
Also in C, (versus, say, PL/M) we name these pointer things after
what they point not ('regs') not what they are ('base address').

Thus, we change the member to a pointer type and change its name.
This makes it compile cleanly regardless of machine pointer size,
while also cutting down on a bunch of casting noise.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-10-02 10:24:56 -07:00
Charles E. Youse 89a984e644 drivers/i2c/i2c_dw.c: make 64-bit clean
Use UINT_TO_POINTER() macros to silence warnings about casts.

Fixes: #19219

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-10-01 18:12:28 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 8f692c7d38 cleanup: include/: move i2c.h to drivers/i2c.h
move i2c.h to drivers/i2c.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif ef281c4237 cleanup: include/: move sys_io.h to sys/sys_io.h
move sys_io.h to sys/sys_io.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00