Commit Graph

690 Commits

Author SHA1 Message Date
Martí Bolívar 7bbead6786 drivers: i2c: add dummy driver for vnd,i2c
We will need this to be able to DEVICE_DT_GET() bus devices from
tests/drivers/build_all in an upcoming commit.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-23 10:34:19 -05:00
Alexandre Bourdiol 59ce5af11b drivers: i2c: add support of STM32WL
Add I2C support to STM32WL

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-02-19 22:39:24 -05:00
Kumar Gala 9dfd87b931 device: esp32: Convert clock control to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access
to the clock controller device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-18 12:42:53 -06:00
Kumar Gala 2a69690823 drivers: i2c: NXP: Convert clock control to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access
to the clock controller device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-18 12:27:59 -06:00
Kumar Gala 3a8fffb9c3 device: rv32m1: Convert clock control to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access
to the clock controller device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-18 09:26:39 -06:00
Mulin Chao ff3fd6dc37 driver: i2c: npcx: fix a glitch on SCL before stop condition.
In the npcx i2c FIFO mechanism, the hardware will release SCL bus
immediately after the driver reads data from FIFO. That's why we need
to hold SCL bus before configuring the next transaction. Once it was
done, the driver release the bus for the next transaction.

But during the last transaction, the driver releases SCL first then
starts a STOP condition. At this moment, the SCL is pulled high by PU
resistance and driven to low for generating STOP condition later. This
additional clock might influence some i2c devices if they don't reset
their state machine after receiving STOP.

This CL fixes this issue by two steps:
1. Distinguish that it's the last read transaction with STOP condition?
2. If so, issue STOP condition before reading FIFO instead of holding
   SCL bus. Then the hardware will generate it immediately after reading
   FIFO.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-02-18 08:54:48 -06:00
Kumar Gala b275fec8c4 soc: stm32: convert to use DEVICE_DT_GET for clocks
Convert from device_get_binding to DEVICE_DT_GET.  In doing this we
no longer need the label in the devicetree node so we remove that.

Removed all __ASSERT_NO_MSG(clk) since we'll get a build error if
DEVICE_DT_GET cant be satisfied, and the clock control api's will
handle reporting if the device_is_ready.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-16 17:01:37 -06:00
Peter Bigot 4ee876b797 drivers/i2c: stm32_v1: remove unused variable
A recent patch removed use of the cfg structure, but left a pointer to
it defined which causes build failures.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-15 16:35:30 +03:00
Flavio Ceolin 3f87c5a0f4 power: Rename constraint API
Replace pm_ctrl_* with pm_constraint.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-02-15 08:08:36 -05:00
Kumar Gala 8b932fbabc drivers: i2c: Add some Kconfig depends
Add some simple depends so we limit various I2C drivers to the SoC
families that the drivers are relevant to.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-14 18:31:55 -05:00
Erwan Gouriou 6288af6f75 drivers/i2c: stm32_v1: TX IRQ enable called twice in a row
On I2C V1 parts, LL_I2C_EnableIT_TX() translates to EVT and BUF
IRQ enabling.
In stm32_i2c_msg_write function, LL_I2C_EnableIT_TX is called right
after stm32_i2c_enable_transfer_interrupts which already enables BUF
IRQ, which starts the transfer.
As a consequence it could happen that transfer is already complete
at the time LL_I2C_EnableIT_TX is called. This case is not expected
by remaining part of the code which loops forever waiting for BUF IRQ
to be raised.
Remove the superfluous LL_I2C_EnableIT_TX call.

Fixes: #32265

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-02-14 18:29:29 -05:00
Peter Bigot 90d8c8d9cd drivers: i2c: litex: remove redundant null pointers
The callback pointers for uninitiated operations are implicitly null;
making them explicit only confuses maintainers searching for drivers
that implement the API.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-09 13:59:17 -05:00
Mulin Chao 40cadb320e driver: i2c: npcx: Prevent transaction result overwritten by recovery.
This CL prevents the transaction result overwritten by the recovery
function. Even if the recovery mechanism succeeds, the upper layer still
needs to know why the transaction failed.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-02-05 12:24:52 -05:00
Mulin Chao c3beabd3c8 driver: i2c: npcx: clear status register by setting a single bit.
Since all fields' type in SMBST is R/W1C and RO, setting a single bit to
clear a specified event is a more suitable solution. Or we might clear
the other pending bits that occurred at the same moment unexpectedly.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-02-05 12:24:52 -05:00
Mulin Chao 7c8cb78b23 driver: i2c: npcx: reset i2c semaphore before start transaction.
This CL reset i2c event-completed semaphore before starting
transactions. Some interrupt events such as BUS_ERROR might change its
counter when i2c bus is idle. It causes that the driver cannot wait
for the event completed and return immediately.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-02-05 12:24:52 -05:00
Flavio Ceolin d21cfd5f36 power: Remove power management conditionals from code
Remove conditionals (PM_DEEP_SLEEP_STATES and PM_SLEEP_STATES) from
power management code. Now these features are always available when
power management is enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-22 09:31:20 -05:00
Flavio Ceolin 579f7049c7 power: Move pm subsystem to new power states
Migrate the whole pm subsystem to use new power states information
from power_state.h and get states and residency properties from
device tree.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-22 09:31:20 -05:00
Rajavardhan Gundi 945dc6ea72 drivers: i2c_mchp_xec: Set Default Configuration
The default configuration is made to be "master" at
"standard speed". This makes it possible to use the
driver without having to configure it.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2021-01-20 14:16:27 -05:00
Rajavardhan Gundi 8751816745 drivers: i2c_mchp_xec: Enable slave mode support
Enable slave support for I2C device instances. Slave mode is
interrupt based, wheras master mode is still based on polling.

Remove ENI bit in master configuration since it is not needed for
master mode.

Signed-off-by: Francisco Munoz <francisco.munoz.ruiz@intel.com>
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2021-01-20 14:16:27 -05: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
Antonio Tessarolo f4acdc2729 NXP: Enable I2C for imx6sx
This commit add support for i2c on imx6sx.
I2C support is based on imx7d and requires NXP HAL.
The Device Tree binding is also changed to better reflect that i2c
driver support both imx6sx and imx7d.

Signed-off-by: Antonio Tessarolo <anthonytexdev@gmail.com>
2021-01-18 17:01:34 -05:00
Tim Lin 981166eb8e drivers/i2c: add i2c driver on it8xxx2 platform
This commit is about the it8xxx2 i2c master driver which
includes six SMBus channels. The enhanced channel i2c3,
i2c4, i2c5 are controller which are designed to support
the I2C protocol.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2021-01-15 11:22:57 -05:00
Kumar Gala 02703e60d9 device: Remove DEVICE_DT_DECLARE / DEVICE_DT_INST_DECLARE
Now that we generate a header that extern's all possible devicetree
based device struct we can remove DEVICE_DT_DECLARE and
DEVICE_DT_INST_DECLARE as they aren't needed anymore.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-01-15 07:16:21 -06:00
Mahavir Jain 29f87c3a0f boards: esp32: add XIP support and enable bootloader build
Disable RTC WDT enabled (by default) by 2nd stage bootloader in ESP-IDF.
This WDT timer ensures correct hand-over and startup sequence from
bootloader to application.

Enabling bootloader caused system clock initialization to fail
when clock rate is greater then 80MHz. This also fixes
esp32 clock source code.

Signed-off-by: Mahavir Jain <mahavir@espressif.com>
2021-01-13 09:10:46 -05:00
Mulin Chao d7976753a8 driver: i2c: fix recovery mechanism in npcx series.
Since the PU power rail of i2c bus might be gone at the initial state
after ec powered up, we might have no chance to get STOP condition. This
is because no i2c transactions occurred before its power rail is
restored. But it's crucial to reset the whole i2c module after i2c bus
is back to the idle state.

The original test suite for i2c recovery mechanism didn't consider this
case that initial i2c bus is low before ec powered on. Hence, this CL
fixed this symptom by:

1. Force i2c modules must proceed 'reset' step no matter we received
   STOP condition or not.
2. Use Boolean for condition check to prevent misusage and meet MISRA.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-01-12 23:30:58 -05:00
Kumar Gala 4dd143f26f driver: i2c: npcx: Convert drivers to new DT device macros
Convert i2c npcx drivers from:

DEVICE_AND_API_INIT -> DEVICE_DT_DEFINE
DEVICE_GET -> DEVICE_DT_GET

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-01-05 13:19:32 -06:00
Mulin Chao f3ea7f5819 driver: i2c: add i2c support in npcx series.
The NPCX SMB modules provides full support for a two-wire SMBus/I2C
synchronous serial interface. Each SMBus/I2C interface is a two-wire
serial interface that is compatible with both Intel SMBus and Philips
I2C physical layer. There are 8 SMBus modules and 10 buses in NPCX7
series.

In NPCX7 series, the SMB5 and SMB6 modules contain a two-way switch to
support two separate SMBus/I2C buses (ports) with one SMB module
(controller) Please refer Section 4.7.2 in the datasheet. In order to
support it, this CL seperates the i2c driver into port and controller
drivers. The controller driver is in charge of i2c module operations
and internal state machine. The port driver is in charge of pin-mux
and connection between Zehpyr i2c api interface and controller driver.

All of modules have separate 32-byte transmit FIFO and 32-byte receive
FIFO buffers. These FIFO buffers reduce firmware overhead during long
SMBus transactions by allowing the Core to write or read more than one
data byte at a time to/from the SMB module.

The CL also includes:
— Add npcx i2c port/controller device tree declarations.
— Zephyr i2c api implementation.
— Add "i2c-0" aliases in npcx7m6fb.dts for i2c test suites.

Signed-off-by: Mulin Chao <MLChao@nuvoton.com>
2020-12-27 18:15:14 +01:00
Kumar Gala 463d028a53 drivers: i2c: eeprom: Convert drivers to new DT device macros
Convert i2c slave eeprom driver from:

    DEVICE_AND_API_INIT -> DEVICE_DT_INST_DEFINE

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-18 08:01:59 -06: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
Rajavardhan Gundi af2ba71e18 drivers: i2c_mchp_xec: fix incorrect timeout value
Use WAIT_COUNT instead of TIME_OUT.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2020-12-17 08:06:39 -05:00
Peter Bigot 96fa707e0c Revert "drivers: move eeprom_slave driver to tests directory"
This reverts commit cabbd916cf.

This is considered to be useful enough that it should be restored
as a stable Zephyr API.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-16 16:39:49 -05:00
Rajavardhan Gundi 3f13487753 drivers: i2c_mchp_xec: changes to address i2c failure
The i2c controller reset sequence is revamped to address
i2c failures which require a reset. Also, more time is
given for i2c slave device to read data by waiting longer.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2020-12-16 12:51:05 -05:00
Peter Bigot c70cc93833 drivers: i2c_gecko: refactor to unify device definition
Switch to iterated definition based on indexes.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-15 11:19:26 +01:00
Kumar Gala 843d3f74da drivers: i2c: i2c_sifive: Fix build issue
Add a missing ',' in DEVICE_DT_INST_DEFINE

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-11 09:13:02 -06:00
Kumar Gala 0e01bc5eed drivers: i2c: stm32: Convert drivers to new DT device macros
Convert i2c drivers from:

DEVICE_AND_API_INIT -> DEVICE_DT_DEFINE
DEVICE_GET -> DEVICE_DT_GET

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-10 16:40:11 -06:00
Kumar Gala 071e7adefb drivers: i2c: Convert drivers to new DT device macros
Convert i2c drivers from:

DEVICE_AND_API_INIT -> DEVICE_DT_INST_DEFINE
DEVICE_GET -> DEVICE_DT_INST_GET
DEVICE_DECLARE -> DEVICE_DT_INST_DECLARE

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-10 16:40:11 -06:00
Anas Nashif e0f3833bf7 power: remove SYS_ and sys_ prefixes
Remove SYS_ and sys_ from all PM related functions and defines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Anas Nashif dd931f93a2 power: standarize PM Kconfigs and cleanup
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE

and use PM_ as the prefix for all PM related Kconfigs

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Peter Bigot 63043bc5ac drivers: i2c: convert nrf drivers to dt device defines
Use the devicetree node as the source of object name and other
information used when defining the device structure.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-01 15:19:22 -05:00
Martin Jäger 42eb8d7336 drivers: i2c: stm32: use generic LL headers
Use generic LL headers instead of depending on soc.h.

Signed-off-by: Martin Jäger <martin@libre.solar>
2020-11-30 15:50:03 +01:00
Antonio Tessarolo 38566ef482 Driver i2c_imx: changed read and write transmission size type
imx_msg transmission size type is uint32_t:
changed imx_read and imx_write signature accordingly.
Removed also two unused variables.

Signed-off-by: Antonio Tessarolo <anthonytexdev@gmail.com>
2020-11-30 15:49:38 +01:00
Antonio Tessarolo 0a2456c0eb i2c_imx: Fix system fault when there is no data to send
When there is no data to send (e.g. i2c message with NULL buffer and
len=0), i2c_imx driver locks itself in isr handling forever.
So if there is no data to send, only device's address must be written
on bus. This fixes i2c_shell's scan command on both imx7 and imx6sx.

Signed-off-by: Antonio Tessarolo <anthonytexdev@gmail.com>
2020-11-30 15:49:38 +01: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
Gerson Fernando Budke bc00f19724 drivers: i2c: Introduce SAM4L i2c TWIM driver
The SAM4L have a unique I2C driver.  It shares simultaneously pins for
both master and slave controllers.  Each controller have their own
instance.  This introduces the TWIM controller that handles only the
master part.

The TWIM controller uses no copy and the driver was prepared to work
with both 7 and 10 bits address.  The controller can handler up to 256
bytes for a single transfer allowing long data communication with
almost no CPU intervention.

The driver was wrote specifically to Zephyr.  It receives a transfer
list of from upper layers to a specific device on the bus.  It programs
the first and second transfer, if it exists, before start.  At end of
full read/write interrupt, will program the next data block.  This
process repeats until all transfers be executed.  The driver uses
interrupt from TWIM to check for erros or program next tranfer.

Future work can enable low power mode on the driver allowing long
transfers with low power consumption.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-11-19 10:52:49 -06:00
Johan Hedberg e2b243893d drivers: i2c: dw: Update to use new pcie_alloc_irq API
Take advantage of the new pcie_alloc_irq() API so that we get a valid
IRQ on platforms where the IRQ register is not pre-populated with a
valid value up front.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-11-14 11:13:00 +02:00
Andreas Dröscher 49a3ce5881 i2c-mcux: take semaphore during transfer
Neither i2c_transfer in i2c.h nor i2c_mcux_transfer in i2c_mcux.c
have any sort of locking. If e.g. an i2c eprom is updated using a
shell and simultaneously another thread access a lm75 then one
of the two transfers will fail or produce a random result.

This changes addresses this issue by that all i2c_msgs of one
i2c_transfer are completed before allowing a subsequent transfer
to start.

The code has been validated on a FRDM_K64F.

Signed-off-by: Andreas Dröscher <github@anticat.ch>
2020-11-13 09:14:09 -06:00
Kumar Gala b4a3880a75 drivers: remove unnecessary use of DEVICE_AND_API_INIT
For drivers that support CONFIG_DEVICE_POWER_MANAGEMENT there are some
cases that look like:

  #ifdef CONFIG_DEVICE_POWER_MANAGEMENT
    DEVICE_DEFINE()
  #else
    DEVICE_AND_API_INIT()
  #endif

There is no need to special case this as the pm_control_fn argument to
DEVICE_DEFINE will just be ignored in the
!CONFIG_DEVICE_POWER_MANAGEMENT case.  So we can cleanup the code a
little and remove the #else cases for the drivers that do this.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-11-06 09:42:47 -06:00
Trond Einar Snekvik 86c793af3f sys: util: Replace MIN(MAX(a, b), c) with CLAMP
Replaces all existing variants of value clamping with the MIN and MAX
macros with the CLAMP macro.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-05 12:12:17 +01:00
Cassini Zhuang 3d3119b1e7 drivers/i2c: i2c_gpio:init at POST_KERNEL
This is to make the gpio-i2c initialization occur after the GPIO pin
clock initialization.

Signed-off-by: Cassini Zhuang <cassini.zhuang@hansonggroup.com>
2020-10-26 09:01:09 -04:00
Erwan Gouriou 0b9c584ec1 drivers/pinmux: stm32: Provide unique API to stm32_dt_pinctrl
Set stm32_dt_pinctrl_configure function as the unique entry point
to STM32 DT pinctrl management.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-20 09:09:29 -05:00
Erwan Gouriou f44e931b0c drivers/pinmux: stm32: Get remap functions visible across family
Move pinctrl remap functions out of stm32f1 definition in order
to get it available to all series.
Allows use of more IS_ENABLED macros in calling drivers and make
code more readable.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-20 09:09:29 -05:00
Erwan Gouriou 0143b5e3de drivers/pinctrl: stm32f1: Provide a function which centralize remap
Centralize AFIO remapping into one single function.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-20 09:09:29 -05:00
Kumar Gala ccc16a41bd drivers: i2c: Move Kconfig I2C instances to esp32
The only user of the I2C instances is the esp32 driver.  Move the
Kconfig symbols down to the esp32 Kconfig for the instances it needs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-10-16 06:36:18 -04:00
Mahesh Mahadevan 8927985c70 drivers: Update Flexcomm I2C driver for clock control
Use the clock API to get the I2C clock frequency

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2020-10-15 11:17:24 -05:00
Erwan Gouriou b74a2162cb soc/arm: stm32: swap argument order in ST_STM32 PINCTRL macros
In order to be in line with other DT_INST macros in zephyr code base,
swap the arguments order in following macro definitions:
*ST_STM32_DT_PINCTRL
*ST_STM32_DT_INST_PINCTRL
Update the users accordingly.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-09 11:52:59 +02:00
Erwan Gouriou b38d84fef4 drivers/i2c: stm32: Add pinctrl configuration at driver init
Convert driver to pcintrl configuration using pcintrl helper
macros.
Pinctrl init sequence has to be done before bus_mutex initialization.

Driver dts bindings are updated to reflect usage of pinctrl-x
properties

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-09 11:52:59 +02:00
Yiyu Zhu 741d8eee7a i2c: power on reset for certain stm32 devices
Described in ES096 2.14.7,
F101X8/B, F102X8/B, and F103X8/B
might not be able to enter i2c master mode on power-up.
Force reset help to mitigate this issue.

Signed-off-by: Yiyu Zhu <smallzzy@outlook.com>
2020-10-02 11:44:17 +02:00
Erwan Gouriou 8b47e563e2 dts/Kconfig: Remove HAS_DTS_I2C
HAS_DTS_I2C is now selected by I2C and
always used as I2C && HAS_DTS_I2C.

It could then be purely removed.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-09-18 13:34:44 -05:00
Crist Xu 6fcd5b567e drivers: i2c: Fix mcux driver transfer status after NACK
Adds a delay after transferring zero-length messages to
correctly detect a NACK.

Signed-off-by: Crist Xu <crist.xu@nxp.com>
2020-09-03 21:50:18 +02:00
Peter Bigot d3e8d6c3f3 i2c_shell: restore documentation on scan technique
When this code was moved from a standalone sample to an optional shell
feature the documentation on how this works and caveats was lost.  Put
it back so it can be referenced in issue explanations.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-09-03 08:52:19 -04:00
Tomasz Bursztyka ef560e0a53 drivers: Manual const-ification of device driver instance
These are all the case that coccinelle cannot find as they are inside
macro declarations.

Fixed via:

git grep -rlz -E "\(struct device \*" |
	xargs -0 sed -i 's/(struct device/(const struct device/g'

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka 4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka 5c9dd0de78 drivers: Apply dynamic IRQ API change
Switching to constant parameter.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka 206f4d61fc drivers: i2c: Fix device instance const qualifier loss
In all of these drivers, passing the device's data was sufficient as
only the data is being used by the HAL callback function then.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +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
Simon Glass 49f2167974 emul: i2c: Add support for I2C emulators
Add an emulation controller which routes I2C traffic to attached
emulators depending on the I2C address selected. This allows drivers
for I2C peripherals to be tested on systems that don't have that
peripheral attached, with the emulator handling the I2C traffic.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-09-01 14:30:46 -04:00
Erwin Rol dce9580490 drivers: i2c_ll_stm32_v1: Reset i2c device on read/write error
Reset the i2c device when read or write return with an error
code. This is to bring the i2c hardware back into a known
state after a hardware error (like EMC spikes) caused
the device to lock up.

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2020-09-01 09:21:44 -05:00
Peter Bigot b9e3226f60 i2c: bitbang: fix SDA pin configuration
The driver must be able to read from this pin as well as write to it.
If the driver doesn't support bidirectional configuration then fall
back to the legacy mode.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-31 13:07:24 +02:00
Laurent Meunier 1603c329bd drivers: i2c_ll_stm32_v2: add support for optional timing property
In case optional timings property has been defined in DT, let's use it
and look for a matching peripheral clock and i2c bus clock so that
timing value is used instead of using runtime algorithm.

If matching the current configuration, the value will be set directly to
the I2C_TIMINGR register through the LL API.

This property is only valid for I2C V2 peripheral, so the timing config
structure member is only added in case of CONFIG_I2C_STM32_V2. Also the
initialization of the member is done conditionnaly, only in case
it is defined in DT, otherwise timings table will be empty.

Signed-off-by: Laurent Meunier <laurent.meunier@st.com>
2020-08-28 11:36:58 +02:00
Alexandre Bourdiol f5e8c06628 drivers: i2c: fix STM32 implicit-fallthrough warning
Fall through is intentional,
so make sure compiler doesn't raise warning.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-08-26 13:17:57 -04: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
Peter Bigot c789ea87ef dts: nordic,nrf-twim: rename non-hardware property
As a general rule devicetree properties should correspond to hardware
description or configuration.  In cases where a Zephyr driver receives
instance-specific configuration data from a devicetree property that
property should be marked as being Zephyr-specific.  Rename
concat-buf-size to zephyr,concat-buf-size to follow this guideline.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-24 16:35:29 -05:00
Peter Bigot afdb98a4a9 drivers: i2c_nrfx_twim: restore previous behavior without concat buffer
The Nordic TWIM peripheral generates a start condition for each bus
transaction.  Devices such as the SSD1306 display and some NXP sensors
can only tolerate the presence of a start condition and device address
after a stop condition.  Those devices will not operate correctly when
these signals are observed while the bus is already active.  This
motivated the addition of a RAM buffer into which message fragments
could be collected so TWIM can transmit them without injecting
unnecessary start conditions.

However many I2C devices interpret these signals as a repeated start
and ignore them and so function properly without a buffer
concatenating the message fragments.

There is no default for the concat-buf-size property, and the previous
strict requirement for one when performing scatter/gather I/O
transactions broke working drivers for devices that tolerate the
repeated starts.  Allow those drivers to work by respecting the
property description and attempting to concatenate messages only if a
buffer in which to place them has been provided.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-24 16:35:29 -05:00
Peter Bigot faa855b9df drivers: i2c_nrfx_twim: refactor concat check logic
The condition of being either the last message or not concatenable to
the next message is the inverse of the condition of committing to
concatenate the next message.  The latter is arguably easier to
understand.  Reverse the logic, document the conditions, and simplify
the early continue.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-24 16:35:29 -05:00
Peter Bigot 1278c13d47 drivers: i2c_nrfx_twim: clean up when buffer capacity failure detected
Do the normal post-transfer shutdown and sync management when a
transaction is rejected due to insufficient buffer size rather than
returning with the peripheral left enabled and the transfer lock held.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-24 16:35:29 -05:00
Peter Bigot d719801d1e drivers: i2c_nrfx_twim: correct concat buf bounds check
The original checked only the current message length against the
buffer size, not accounting for space already used.

Also improve the diagnostic to indicate how much space is required vs
given.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-24 16:35:29 -05:00
Peter Bigot be8c59b4a4 drivers: i2c: nordic increase timeout to 500 ms
The 100 ms hard-coded timeout is too small to complete the transfer of
1025 bytes of SSD1306 data at 100 kHz.  Increase it to 500 ms to match
STM32 policy and fix this problem.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-24 16:31:21 -05:00
Andrew Boie 63c3e153d6 drivers: use node IDs for DEVICE_MMIO.*_INIT
There is nothing wrong with instance numbers and they are
recommended for use whenever possible, but this is an API
design problem because it's not always possible to get nodes
by instance number; in some cases, drivers need to get node
identifiers from node labels, for example.

Change these APIs (which are not yet in any Zephyr release)
to take node IDs instead of instance IDs.

Fixes: #26984

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-14 13:35:02 +02:00
Peter Bigot cabbd916cf drivers: move eeprom_slave driver to tests directory
This device isn't an actual hardware driver: it's a virtual EEPROM
that stores data in an instance-specific RAM buffer, with the data
exposed on an I2C bus as a I2C follower (slave) device that can be
controlled by another device acting as a leader (master) on that same
bus.

As such it's a reasonable example of how to write an I2C follower
driver, but it's not clear that it has a real use in applications.  A
Zephyr application that needs to emulate an EEPROM in a real-world
system would be unlikely to provide its data from a RAM buffer.

The sole in-tree reference is in the i2c_slave_api test, so move the
driver implementation into that test.

The Kconfig and hierarchy are being left in place until it is more
clear how this functionality should be selectable within Zephyr.  The
I2C_SLAVE symbol has been converted from menuconfig to config to
eliminate a Kconfig style diagnostic.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-13 11:49:12 +02:00
Erwin Rol f2156b9d4a drivers: i2c_ll_stm32_v1: Reset i2c device on timeout
When, due to EMC, a spike happens on the SDA line the hardware hangs
and will not function anymore until the unit is reset.

By adding a timeout to the msg_read and msg_write function we can
detect that something went wrong, and when that happens reset
the I2C bus.

The reset will also reset all configuration, so before reseting
store all important registers and after reseting restore
those settings.

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2020-08-12 14:53:37 -05:00
Erwin Rol d49b3e1b68 drivers: i2c_ll_stm32_v1: clear stop bit befor setting start bit
Sometimes the stop bit is still set when starting the next transaction.
When that happens the hardware will generate a start directly followed
by a stop. This will not be detected by the driver and it will endlessly
wait for the next interrupt that will never come.

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2020-08-12 14:53:37 -05: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
Steven Lemaire f93f41286e drivers: i2c: gecko: Add support for Gecko Series 2 SoC.
The EFR32MG21 uses a different kind of GPIO routing for peripherals.
It is based on the GPIO registers and no longer peripherals' registers.

Signed-off-by: Steven Lemaire <steven.lemaire@zii.aero>
2020-08-06 11:49:16 +02:00
Simon Glass 6b50f643da drivers: i2c: Add a dump routine
Add a function to dump out a set of I2C messages. It uses debug logging
so it only useful for debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-08-04 17:50:39 +02:00
Tomasz Bursztyka 1580768fd3 drivers: dma: Align all drivers using user_data for callback
s/callback_arg/user_data

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-07-30 09:48:00 +02:00
Tomasz Bursztyka 6acee3dcba drivers: dma: Apply DMA callback change to relevant drivers
Now the dma device instance is passed as parameter to the callback.

Fixes #26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-07-30 09:48:00 +02:00
Maxime Bittan 9ca6b704a7 drivers: i2c: Add support for LPC11U6X I2C controllers
This commit adds a driver for the LPC11U6X I2C controllers

Signed-off-by: Maxime Bittan <maxime.bittan@seagate.com>
2020-07-29 20:12:24 +02:00
Jakub Rzeszutko 6011aee0d8 drivers: i2c: update i2c_shell commands
By fixing the issue: #21819 in the shell, it is no longer needed
to keep a workaround, which allows prompting i2c bus name.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-07-27 08:50:52 -04:00
Peter Bigot a1babb7f1f drivers: eeprom_slave: add const qualifier to read-only data
The EEPROM device doesn't mutate the source data it's given, so update
the API signature to reflect this fact.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-07-22 21:41:12 +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
Mieszko Mierunski 5d00616bf3 drivers: nrf: Add concatenation buffer to i2c nrfx TWIM driver.
Add option to concatenate i2c transfers. If concatenation buffer size is
provided then transfers will be concatenated as long as there is space
left in buffer.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2020-07-10 15:40:26 +02:00
Henrik Brix Andersen 99c7597874 drivers: i2c: mcux: return to idle on failed transfers
Abort I2C transfers through the MCUX HAL if a transfer fails to avoid
deadlock in the driver/HAL.

Fixes #25098

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-07-09 16:03:01 -05:00
Christian Taedcke 82de647e31 drivers: i2c_gecko: Fix mutation of config_info content
Since the i2c init structure is moved from config_info to the stack,
this change requires 12 bytes more stack during driver initialization.

This fixes #25255

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2020-07-08 16:10:54 -05:00
Xavier Chapron cecea7b536 drivers: i2c_nrfx_{twi, twim}: Remove potential I2C deadlock
Remove K_FOREVER wait on completion_sync.
In some situations (a short on I2C SDA line for example), this
semaphore will never be released and therefore we should not wait
it forever.
Instead we wait for a maximum of 100msec and return an error if we
weren't able to retrieve the semaphore.
In such situation, the program is not stuck anymore, but the I2C
driver must be uninit then init again to work again.

Fixes #25076.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-07-02 08:48:24 -04:00
Tomasz Bursztyka 8260736268 drivers: Remove useless device start/end pointers
Commit id a538dcd8f8 got rid of the usage of these pointers so they are
useless now and can be removed in this drivers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-26 11:09:28 -05:00
Peter Bigot a538dcd8f8 shell: refactor device_name_get implementation
Several shell modules use cloned code to iterate over all devices and
identify the nth instance that meets some criteria.  The code was
repetitive and included various errors.  Abstract to a helper function
that performs the check consistently.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-23 13:27:14 +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
Mohamed ElShahawi f9e0fa9af3 drivers: esp32/clock_control: support UART, I2C
- Change default CPU Clock to 240MHz
(PLL is activated)
- I2C, UART will use sysclk from clock driver
- esp32_enable_peripheral replaced by
clock_control_on

Signed-off-by: Mohamed ElShahawi <ExtremeGTX@hotmail.com>
2020-06-16 09:00:51 -05:00