Commit graph

41 commits

Author SHA1 Message Date
Vit Stanicek 903bbefef3 drivers: dma_mcux_lpc: Fix omitted interrupt config
Add the invocation of an interrupt config function
(config->irq_config_func). Absence of this call results in the DMA
driver not being able to service interrupts raised by the DMA
peripheral.

This case was observed on the i.MX RT685's HiFi 4 DSP domain, where DMA
was not functional because of this.

Signed-off-by: Vit Stanicek <vit.stanicek@nxp.com>
2024-03-28 16:04:34 -05:00
Daniel DeGrasse f378fd0282 drivers: dma: dma_mcux_lpc: add workaround for RW61x flexspi
RW61x DMA has the *unique* restriction that DMA access is not routed
through the FlexSPI cache engine, only via the non-cached address space.
To enable DMA to read from the FlexSPI AHB space directly, fixup any
address passed to the DMA engine that is in the FlexSPI AHB cached
region to be in the non cached region

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-03-18 18:57:03 +01:00
Mahesh Mahadevan d77c706f94 drivers: dma_lpc: Suppport dest_scatter and source_gather
Process dest_scatter_interval and source_gather_interval
configurations and accordingly set the source and destination
increment values.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-12-15 14:04:52 +01:00
Mahesh Mahadevan 3535732580 drivers: dma: Return DMA_STATUS_BLOCK or DMA_STATUS_COMPLETE
Use intA and intB fields of the DMA descriptor to decide when
the interrupt is per block versus when the transfer is complete.
This allows us to return the correct flag to the user.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-12-14 09:28:38 +01:00
Mahesh Mahadevan 4e14f73216 drivers: dma_lpc: Process complete_callback flag
Add code to recognize the complete_callback flag
and issue the callback accordingly.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-12-14 09:28:38 +01:00
Mahesh Mahadevan 41c2c3d4b8 drivers: dma_mcux_lpc: Clear out the dma channel structure
The DMA channel data structure can retain config information.
We need to clear this everytime dma_configure is called on a
channel.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-12-11 09:52:12 +01:00
Mahesh Mahadevan e0fd9f6cde drivers: dma_mcux_lpc: Call callback only when provided
Add a check to ensure the dma_callback is provided before
calling the callback function.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-12-04 14:19:27 +01:00
Mike J. Chen a36d4beafa drivers: dma: mcux_lpc: support channel priority
Set DMA channel priority in dma_mcux_lpc_configure().

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-11-15 10:04:08 +01:00
Daniel DeGrasse aa0b8af577 drivers: dma: mcux_mcux_lpc: support hardware triggering
The LPC DMA IP offers hardware triggering via a series of SOC-specific
signals, often including sources like GPIO pins or hardware timers.
Support hardware triggers via the "dma_slot" field of the DMA
configuration structure. Currently support is offered for setting the
following:
- Trigger polarity
- Trigger level/edge mode
- burst mode
- burst length
- peripheral request

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-11-13 16:53:53 -06:00
Emilio Benavente a50c26d80f drivers: dma: dma_mcux_lpx: Added parameter in macro for 55S36
Added a parameter inside the Channel Number macro since
the LPC55S36 expects an address rather than a static number.

Signed-off-by: Emilio Benavente <emilio.benavente@nxp.com>
2023-07-21 08:58:27 -05:00
Mike J. Chen 7839eb524c drivers: dma: dma_lpc: fix bug with transfer size/width
Fix for bug:
https://github.com/zephyrproject-rtos/zephyr/issues/59802

The DMA controller only supports one transfer size, but
the Zephyr DMA driver api allows specifying a source_data_size
and dest_data_size which might be different. An old
version was always using dest_data_size for the transfer
size (variable is called "width"), but a recent change
made the driver use the MIN for the source and dest data
sizes. The MIN choice breaks the I2S driver because it
always set source_data_size to 1, but dest_data_size was
typically 4 for like two-channel 16-bit PCM data. So the
old driver worked using dest_data_size, but the new driver
broke I2S using MIN since source_data_size was 1.

To prevent confusion, change the DMA driver to assert that
source_data_size and dest_data_size are the same.

Also assert that the source_address and dest_address for
each block_config are properly aligned for the transfer size,
since that is a documentated requirement for the DMA controller.

Also rename max_xfer to max_xfer-bytes to be more clear what
the units are, and use this value in many places that
are comparing block_size in bytes rather than converting
block_size to words by dividing by width and
then comparing to NXP_LPC_DMA_MAX_XFER.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-07-19 10:36:23 -05:00
Declan Snyder 191ad08154 drivers: dma_mcux_lpc: Add Kconfig to reduce data
Add a Kconfig to have the ability to fine tune the amount of RAM that
the driver uses based on the number of channels expected to be used.

Most of the code is already there but just need this Kconfig to get the
benefit of it by reducing the size of the statically created arrays.

Also change the number of channels field in the configuration to a byte
instead of a 32 bit integer because that should be sufficient to
describe the number of DMA channels.

Rename LPC DMA Driver Kconfigs with namespace to MCUX_LPC

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-07-17 13:06:01 -05:00
Declan Snyder bb74b311fe drivers: dma_mcux_lpc: remove SDK based macro
remove the sdk based TOTAL_DMA_CHANNELS macro and instead just use the
zephyr driver's num_of_channels field

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-07-12 09:26:58 +02:00
Jacob Siverskog 9a26ab44fb drivers: dma_mcux_lpc: Fix potential NULL pointer dereferences
Dereference variables after NULL checking.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2023-06-07 13:38:19 -04:00
Declan Snyder 0daad872fd drivers: dma_mcux_lpc: Replace sem with spinlock
Replace the otrig configuration semaphore with a spinlock.

This will allow the dma_config function to be called from an ISR
and it will no longer shift the burden of waiting to be able to configure
the dma otrigs to the caller of the function, since the driver
will just spin on the lock until it can configure them, instead of
returning an error.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-06-01 13:43:56 -04:00
Declan Snyder 86fcc5de97 drivers: dma_mcux_lpc: Fix OTRIG build error
Fix the OTRIG related build error in the DMA LPC
by defaulting num_of_otrigs to 0 if a plarform using
the LPC DMA does not specify this property in devicetree.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-05-30 11:07:02 -04:00
Emilio Benavente 73b1705eb7 drivers: dma: dma_mcux_lpc: Adjusted dma driver for channel chaining.
Added to the configuration function to enable
channel chaining for the DMA_LPC that utilizes
the total of the SOC OTrig channels.

Signed-off-by: Emilio Benavente <emilio.benavente@nxp.com>
2023-05-26 17:22:43 -05:00
Declan Snyder 2af408b8fa drivers: dma_mcux_lpc: Fix busy status
Driver should just say the channel is not busy if
it is not setup rather than returning an error.

Also, change the channel index to int8_t rather
than uint32_t since it is being assigned negative
values and that width is more appropriate.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-05-26 13:15:24 -05:00
Mahesh Mahadevan b8c21a6d88 drivers: dma_mcux: Add support for big data transfers
1. Transfers are not limited by XFERCOUNT transfer length of
   LPC DMA descriptor. Added code to handle block sizes
   greater than XFERCOUNT.
2. Use the reload_en flag to decide if we should setup
   a circular descriptor chain.
3. Improve handling of source and destination width.
4. Number of DMA descriptors are defined by a Kconfig value.
5. Changed the dma_reload function to handle transfers
   greater than XFERCOUNT.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-05-26 10:05:24 -04:00
Mahesh Mahadevan 723224f086 drivers: dma_mcux: Rename variables in NXP MCUX driver
Rename the variables to help understand the code flow.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-05-26 10:05:24 -04:00
Carlo Caione cb11b2e84b barriers: Move __DSB() to the new API
Remove the arch-specific ARM-centric __DSB() macro and use the new
barrier API instead.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Gerard Marull-Paretas 2725155832 drivers: dma: mcux_lpc: remove unused device config
Device config is no longer used after
32da420126.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-18 11:09:29 -05:00
Declan Snyder 32da420126 drivers: dma_mcux_lpc: Change init level
Change init level of the mcux lpc dma driver to be
PRE_KERNEL_1 because some other hardware drivers
used on the same platforms as the lpc dma will be
dependent on the LPC DMA and are also initialized
in PRE_KERNEL_1, such as the Flexcomm UART driver
when using UART_ASYNC_API.

Therefore, remove k_malloc from init function and
make those variables statically defined instead of
heap allocated.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-05-17 14:25:13 -05:00
Declan Snyder d8ca4e9e8f drivers: dma_mcux_lpc: Status fixes
Some miscellaneous fixes to LPC DMA driver regarding status tracking:

- If a DMA channel has not been configured for any transfer,
  there will be a bug caused by the virtual channel being -1
  and then trying to index -1 into the driver data structs.
  Add -EACCES return code to indicate this situation.

- Return -EINVAL from get_status if channel number is invalid

- Update the busy flag in the LPC DMA callback function.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-05-17 14:25:13 -05:00
Cyril Fougeray 1be72d9888 dma: callback with 2 status codes for successful transfers
Make use of positive status values in the DMA callback to pass
info to the DMA client after a successful DMA operation.
A completed DMA transfer uses the status 0 while a reached
water mark uses the status 1.

Signed-off-by: Cyril Fougeray <cyril.fougeray@worldcoin.org>
2023-05-08 09:57:32 +02:00
Mahesh Mahadevan 629f8d83b5 drivers: dma: mcux_lpc: Update address increment logic
The address increment logic was looking at both source
and destination parameters together. Separate them so
we can set one.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-04-20 09:07:37 -05: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 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
Daniel DeGrasse 3603b6d501 drivers: dma: mcux_lpc_dma: Fix data variable name
Device 'data' variable name was incorrect due to recent treewide naming
cleanups. Fix variable name to fix build error.

Fixes #42118

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-01-25 14:09:30 -06:00
Tomasz Bursztyka 7bbf818cc5 drivers/dma: Fix conficting types for a variable name
Let's have dev_data for dev->data so it will not conflict with struct
call_back data variable.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-01-24 10:23:05 -05:00
Gerard Marull-Paretas 20d0260753 drivers: dma: mcux_lpc: fix variable name clash
data was already used by the struct call_back, rename device data to
`dev_data`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-20 07:41:26 -06:00
Gerard Marull-Paretas d2118eb1bc drivers: dma: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Maureen Helm b539699a98 drivers: dma: Refactor drivers to use shared init priority
Refactors all of the DMA drivers to use a shared driver class
initialization priority configuration, CONFIG_DMA_INIT_PRIORITY, to
allow configuring DMA drivers separately from other devices. This is
similar to other driver classes like I2C and SPI.

Most drivers previously used CONFIG_KERNEL_INIT_PRIORITY_DEFAULT or
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, therefore the default for this new
option is the lower of the two, which means earlier initialization.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2021-10-29 22:55:03 -04:00
Mahesh Mahadevan 91f172e4ad drivers: dma: Zero-initialize memory allocated using kmalloc
The code was wrongly calling DMA_Abort on a channel
that not initialized. This fixes Issue#38078

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2021-09-01 12:34:50 -04:00
Mahesh Mahadevan b88d8070d7 drivers: dma: Update the LPC DMA driver
1. Update the SDK API's called in the configure implementation.
The DMA_PrepareTransfer and DMA_SubmitTransfer SDK functions
are not recommneded for use. Replaced the call to these SDK
functions with other SDK API's.
2. Fix the implementation the configure function when multiple
blocks are used.
3. Update the dma_reload implementation. The old reload function
would simply abort the transfer. The new implementation reloads
the DMA buffers for transfer.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2021-04-30 12:02:55 -05:00
Gerard Marull-Paretas 861eac31b8 drivers: dma: 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 16:41:29 -04:00
Kumar Gala c5582358f6 drivers: dma: Convert drivers to new DT device macros
Convert dma 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-19 20:03:23 -05:00
Mahesh Mahadevan cb715fc813 drivers: dma: Update NXP LPC driver for SPI peripheral
1, Change the allocation of DMA descriptors for the case
when multiple buffers are used for DMA transfer. This was
tested during SPI DMA transfers
2. Add support for the case when source and destination
addresses should not be incremented.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2020-10-21 06:26:40 -05: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 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
Mahesh Mahadevan f75f8bec20 MXRT600: Add DMA support
Add DMA support for MCUX LPC SoC's

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2020-08-28 14:24:21 -05:00