Commit graph

42 commits

Author SHA1 Message Date
Carles Cufi 8c748fd005 kernel: Modify the signature of k_mem_slab_free()
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.

The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);

has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);

The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.

All in-tree uses of the function have been adapted.

Fixes #61888.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-09-03 18:20:59 -04:00
Pieter De Gendt 6b532ff43e treewide: Update clock control API usage
Replace all (clock_control_subsys_t *) casts with (clock_control_subsys_t)

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-05 10:55:46 +02:00
Gerson Fernando Budke f1b68beca1 drivers: ssc: sam: Update to use clock control
This update Atmel SAM ssc driver to use clock control driver.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2023-03-21 14:12:25 -07: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
Gerson Fernando Budke e1d88706bb drivers: i2s: Update sam ssc driver to use pinctrl
This update Atmel sam ssc driver to use pinctrl driver and API. It
updates all boards with new pinctrl groups format. In addition this
remove DEV_NAME macro at sam xdma driver.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-03-24 15:45:37 -07:00
Gerard Marull-Paretas 9953c194b9 drivers: remove redundant DEV_NAME helpers
Just use dev->name. This change follow same principles applied when
DEV_CFG and DEV_DATA macros were removed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-15 17:31:51 -04:00
Piotr Mienkowski 1ed5ba7720 drivers: i2s_sam_ssc: fix cache coherency in dma_rx_callback
Invalidate the cache before the RX data block is passed to the DMA
engine and not after it is received. If the RX data block contains
dirty cache lines they can be flushed anytime, overwriting legitimate
data that have been prefilled by the DMA module.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2022-01-28 10:07:25 +01:00
Gerard Marull-Paretas 72a0d68284 drivers: i2s: 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
Piotr Mienkowski 4566d0ec58 drivers: i2s_sam_ssc: use dma_reload() to continue transfer
Use `dma_reload()` instead of `dma_config()` within DMA callbacks. This
significantly shortens time required to reconfigure DMA engine to
transmit / receive the next data block and allows to configure higher
I2S bus data rates.

The maximum I2S data rate supported by the driver is still lower than
that of underlying hardware. To fully support hardware capabilities the
I2S driver would have to use scatter-gather / linked-list DMA transfer.
This is currently not supported by the DMA driver.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2021-07-27 09:52:07 -04:00
Piotr Mienkowski aaf64e0bdf soc: atmel_sam: Add _INST to ATMEL_SAM_DT_PIN* macros
The macros are used to get the pin(s) of a given driver instance. Add
_INST prefix to match convention used by the devicetree.h. The original
macros can now be used to obtain pin(s) of an arbitrary device instance
identified by the nodelabel.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2021-06-14 09:50:41 -05:00
Kumar Gala 6f8f08a6a3 drivers: i2s: i2s_sam_ssc: Fix build issue
Change to make i2s_config const missed a case in the SAM driver.
Without this we get build errors when building in CI.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-05-05 13:01:01 -05:00
Andrzej Głąbek 7fcf78073b drivers: i2s: Add missing const qualifiers
The i2s_config structure passed to the i2s_configure() function is
not supposed to be modified by the driver. Similarly, the structure
returned by the i2s_config_get() function is not supposed to be
modified outside the driver.
Decorate the pointers to those structures with the const qualifier
and correct one driver that actually modified the structure passed
to i2s_configure().

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2021-05-03 19:57:49 -04:00
Andrzej Głąbek e4c7f4d62a drivers: i2s: Introduce the I2S_DIR_BOTH enumeration value
Introduce a new enumeration value that allows setting configuration
and triggering commands for both I2S streams simultaneously.
Such possibility is especially important on hardware where the streams
can be only enabled/disabled (but not started/stopped) independently,
like it is in nRF SoCs.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2021-05-03 19:57:49 -04:00
Gerard Marull-Paretas c650523870 drivers: i2s: 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
Piotr Mienkowski b22df38d30 drivers: i2s_sam_ssc.c: store *dev_dma in flash
The DMA module the i2s_sam_ssc relies on cannot change during the
runtime. Store pointer to dev_dma in flash, not in RAM. The new
implementation saves 40 bytes of flash and 32 bytes of RAM.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2021-03-03 16:16:33 +03:00
Kumar Gala 6c9c7ec759 i2s: atmel sam ssc: Convert dma to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access
to the dma controller device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-28 16:37:22 -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
Kumar Gala 8e55cfab96 drivers: i2s: Convert drivers to new DT device macros
Convert i2s drivers from:

    DEVICE_AND_API_INIT -> DEVICE_DT{_INST}_DEFINE
    DEVICE_GET -> DEVICE_DT_INST_GET
    DEVICE_DECLARE -> DEVICE_DT_INST_DECLARE

etc..

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-17 09:21:02 -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
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
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
Peter Bigot bc34501892 drivers: use macro to define device structures
Replace individual device instance definitions with the macro that
expands to the equivalent change.

    F='struct device DEVICE_NAME_GET'
    git grep -l "$F" \
     | xargs sed -i -r \
       -e "s@$F"'\(([^)]*)\);@DEVICE_DECLARE(\1);@'

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-08 15:01:52 -04: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
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
Kumar Gala 6ae8664889 drivers: i2s: i2s_sam_ssc: Convert to devicetree
Convert i2s_sam_ssc driver to utilize devicetree.  We replace Kconfig
options for specifying the DMA configuration (channel, DMA device name)
with getting that from devicetree.  We also get pincfg from devicetree,
however we still have Kconfig sybmols to specify if the RF or RK pin is
enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 22:24:58 -05:00
Carles Cufi 9ba20dd48e drivers: audio: Port to the new timeout API
Port the I2S and DMIC drivers to the new timeout API so that they do
not need to enable legacy timeouts.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-07 11:01:55 +02:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.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 f2e35134b0 cleanup: include/: move i2s.h to drivers/i2s.h
move i2s.h to drivers/i2s.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 46a5d1e5cb cleanup: include/: move dma.h to drivers/dma.h
move dma.h to drivers/dma.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
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Aurelien Jarno 532550cba1 drivers/i2s_sam_ssc.c: enable cache support
Enable cache operations before starting a DMA operation if the CPU has a
cache. All the support was already in place, it just needs to be
enabled.

With the previous commits, it allows the I2S tests to pass on a SAM E70
Xplained board with the CPU cache enabled.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-22 13:16:42 -05:00
Andrew Boie d945d32a1e i2s_sam_ssc: fix compiler warning
First argument to a DMA callback is a void pointer.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-15 16:20:36 -05:00
Anas Nashif 0a04a134a8 drivers: i2s_sam_ssc: fix syntax using uncrustify
After changing the logger, run uncrustify to update syntax.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-10 10:22:01 -04:00
Anas Nashif a66967b0f2 driver: i2s: move to new logger
Move drivers to new logger and change samples enabling logging in
prj.conf.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-10 10:22:01 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Andrew Boie 06c23f157f i2s: expose i2s APIs to user mode
User mode may now access the read, write, and trigger APIs.
Unlike supervisor mode, memory slabs are not dealt with directly,
the data is always copied.

A new driver API added to fetch the current channel configuration,
used by the system call handlers.

The i2s_sam_ssc driver updated for the new API. CAVS driver not
modified as there is no user mode port to Xtensa yet.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-13 16:44:09 -07:00
Piotr Mienkowski dafdfadfbe drivers: Add Atmel SAM I2S (SSC) driver
Added Inter-IC Sound driver (based on SSC module) for Atmel
SAM MCU family.

Tested on Atmel SMART SAM E70 Xplained board

Origin: Original

Jira: ZEP-2509
Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2017-11-30 10:30:33 -05:00