Commit graph

15409 commits

Author SHA1 Message Date
Martí Bolívar
6008e7ee24 devicetree: spi: add CS GPIO controller accessors
Add two new macros for getting the chip select GPIO controller from a
SPI device:

- DT_SPI_DEV_CS_GPIOS_CTLR()
- DT_INST_SPI_DEV_CS_GPIOS_CTLR()

Now that we can get struct device pointers at build time directly from
a devicetree node identifier, it's useful to be able to get a
node_id for a CS GPIO controller from the SPI device, because that's
necessary for setting up the gpio_dev in a struct spi_cs_control.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-23 10:34:19 -05:00
Martí Bolívar
24b5053600 devicetree: adjust some implementation details
Reimplement DT_PHANDLE_BY_IDX() in a way that defers concatenating its
parameters together until after all of them have been expanded, for
reasons that will be taken advantage of in the next patch.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-23 10:34:19 -05:00
Martí Bolívar
ad49bcf492 devicetree: add DT_INST_BUS(node_id)
This returns the node identifier for a node's bus. For example, for a
device on an I2C bus, it would return a node identifier for the I2C
bus controller.

We already have a DT_BUS() and DT_INST_BUS_LABEL(), but there hasn't
been a request or need for DT_INST_BUS() up until now, so it didn't
exist yet.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-23 10:34:19 -05:00
Krzysztof Chruscinski
de84575e2e sys: util: Update implementation of loop macros
Recursive macros are more generic but they are very depending for
preprocessor. When they are used extensively they can prolong
compilation even ten times. Replaced them with brute force
implementation for:
- FOR_EACH macros
- GET_N_ARG
- GET_ARGS_LESS_N
- UTIL_LISTIFY
- UTIL_REPEAT

New implementation provides same functionality but it is limited to 64
input arguments. This is not a hard limitation and can be increased
in the future.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-02-23 12:35:48 +01:00
Alexander Wachter
8fbc2cd825 devicetree: pwms: add helper marcos to obtain the node identifier
Added helper macros to obtain the pwm-controller node identifier
from a pwms phandle.

Signed-off-by: Alexander Wachter <alexander.wachter@leica-geosystems.com>
2021-02-22 17:56:46 -05:00
Mulin Chao
7c9d3f44f0 driver: sensor: npcx: add tachometer sensor support.
In NPCX7 series, it contains two tachometer (TACH) modules that contains
two Independent timers (counter 1 and 2). They are used to capture a
counter value when an event is detected via the external pads (TA or
TB).

The CL also includes:
— Add npcx tachometer device tree declarations.
— Zephyr sensor api implementation for tachometer.
— Enable "tach1" device in npcx7m6fb.dts for testing.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-02-22 17:56:19 -05:00
Daniel Leung
2816c17a09 x86: allow linking in virtual address space
This adds the pieces to allow the kernel to be linked
in virtual address space.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-22 14:55:28 -05:00
Daniel Leung
d340afd456 x86: use CONFIG_SRAM_OFFSET instead of CONFIG_X86_KERNEL_OFFSET
This changes x86 to use CONFIG_SRAM_OFFSET instead of
arch-specific CONFIG_X86_KERNEL_OFFSET. This allows the common
MMU macro Z_BOOT_VIRT_TO_PHYS() and Z_BOOT_PHYS_TO_VIRT() to
function properly if we ever need to map the kernel into
virtual address space that does not have the same starting
physical address.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-22 14:55:28 -05:00
Kumar Gala
f9c6ee77cc devicetree: deprecate DT_CLOCKS_LABEL APIs
Mark all variants of the DT_CLOCKS_LABEL APIs:
* DT_CLOCKS_LABEL_BY_IDX
* DT_CLOCKS_LABEL_BY_NAME
* DT_CLOCKS_LABEL
* DT_INST_CLOCKS_LABEL_BY_IDX
* DT_INST_CLOCKS_LABEL_BY_NAME
* DT_INST_CLOCKS_LABEL

As deprecated in favor of utilizing:

* DT_CLOCKS_CTLR_BY_IDX
* DT_CLOCKS_CTLR_BY_NAME
* DT_CLOCKS_CTLR
* DT_INST_CLOCKS_CTLR_BY_IDX
* DT_INST_CLOCKS_CTLR_BY_NAME
* DT_INST_CLOCKS_CTLR

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-22 12:20:33 -06:00
Reto Schneider
545fb92fc1 net: pkt: Fix headroom edge case
This commit fixes some edge cases when using net_bufs with reserved
bytes (headroom) as fragments of a net_pkt.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2021-02-22 19:33:16 +02:00
Reto Schneider
1919766d7b net: buf: Simplify querying maximum len
net_buf_max_len() provides the maximum number of bytes which can be put
behind the data pointer. This provides a save alternative to using the
size field of the net_buf structure directly, which does not take the
reserved bytes (headroom) into account.

This commit also replaces the usage of the size field in places where
size got used directly. Code has not been adjusted when it is easy to
recognise that the buffer does not have any reserved bytes, which is the
case after allocation or reset. Same goes for the faulty usage by
net_pkt as exposed by the last commit and begin fixed by a separate
commit.

Even though it would be cleaner, I decided to not rename the size field
to e.g. __buf_size in order to keep the amount of code changes low.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2021-02-22 19:33:16 +02:00
Peter Bigot
d554d34137 device: add post-process of elf file to manage device handles
Following the idiom used for system calls, add script support to read
the initial application binary to identify which devices are defined,
and to use their offset in the device array as their unique handle
rather than the externally-defined ordinal from devicetree.  The
device dependency arrays are updated to use these handles.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 15:46:16 -05:00
Peter Bigot
669bc6b86f device: inject device dependency information from devicetree nodes
Generate arrays of dependency information for each device.  If a
device definition is being constructed from devicetree these come from
the devicetree dependency information.  Additional dependencies may be
passed through using the DT_ macros.

Define flag values for device handles so we can partition the
dependency array into distinct sets, which include things it requires,
things it supports (may not be needed), and child nodes (not
implemented, may not be needed).

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 15:46:16 -05:00
Peter Bigot
d1a0568e11 device: store device pm busy status in the state structure
Move the busy status from a global atomic bit sequence to atomic flags
in the device PM state.  While this temporarily adds 4 bytes to each
PM structure the whole device PM infrastructure will be refactored and
it's likely the extra memory can be recovered.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 10:11:20 -05:00
Peter Bigot
65eee5cb47 device: store initialization status in the state structure
Separate the state indicator of whether the initialization function
has been invoked from the success or failure of the initialization.
This allows precise confirmation that the device is ready (i.e. it has
been initialized, and that initialization succeeded).

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 10:11:20 -05:00
Peter Bigot
8d771f1d8e device: move device power management state into common dynamic state
This avoids the need for distinct object that uses flash to store its
initializer.  Instead the state is initialized when the kernel is
starting up, before anything can reference it.  In future refactoring
the PM state could be accessed directly without storing an extra
pointer in the static device state.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 10:11:20 -05:00
Peter Bigot
a955c9e1aa device: add common structure for dynamic device state
While devices have driver-specific dynamic state accessed through the
data field, there is also dynamic state that is common to most if not
all devices.  Add a structure to hold that data.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 10:11:20 -05:00
Carlo Caione
13118acb15 arch: aarch64: Remove useless ISB
Quoting from the reference manual "Writes to PSTATE.{PAN, D, A, I, F}
occur in program order without the need for additional synchronization."
so we can remove the ISB for arch_irq_lock() and arch_irq_unlock().

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-02-19 16:26:38 +03:00
Peter Bigot
2aab687270 device: introduce device_usable_check
As we add support for devices that are powered down, or are present
but have not yet been started, we need more precise information about
why a device isn't ready, so callers can take appropriate steps to
make it ready.

Add a new function that determines readiness and indicates the reason
for not being ready in a defined unique error code per condition.
Expose this in both a syscall form to be invoked from applications,
and a unchecked form that can be used from supervisor contexts
including syscall implementation functions.

Anticipated future conditions include:
* device is powered down and needs to be brought back up;
* device was installed disabled and has not been started.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 05:17:37 -06:00
Thomas LE ROUX
37dca20444 net: lwm2m: Utility functions added to LWM2M Engine
Added 3 utility functions :
- lwm2m_engine_update_period_service() which updates the period of a
given service.
- lwm2m_engine_update_period_min_observer() which updates the
min_period_sec for a given observe node.
- lwm2m_engine_update_period_max_observer() which updates the
max_period_sec for a given observe node.

Signed-off-by: Thomas LE ROUX <thomas.leroux@smile.fr>
2021-02-19 10:52:08 +02:00
Joakim Andersson
e0787bf31b Bluetooth: host: Add definitions for generate DHKey v2 commands
Add definitions for the HCI command LE Generate DHKey v2.
This command includes the option to use the debug private key.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-18 13:50:22 +01:00
Andrzej Kaczmarek
9d8503c3b1 Bluetooth: controller: Initialize PDUs in set #0 on reset
Set #0 is used for legacy advertising when legacy HCI commands are used
and in such case it's possible to enable advertising without any prior
configuration. This means we should better always have PDUs in set #0
initialized with default empty data.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-18 13:29:37 +01:00
Erwan Gouriou
5d2150efa4 drivers/interrupt_controller: stm32: Make use of DEVICE_DT API
Convert stm32 interrupt controller driver to DEVICE_DT API.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-02-17 14:26:23 -06:00
Richard McCrae
f8705a6db7 net: sockets: Add EAI error code translations
Added EAI_SOCKTYPE and EAI_FAMILY DNS error code translations

Signed-off-by: Richard McCrae <richard.mccrae@nordicsemi.no>
2021-02-17 18:54:12 +02:00
Peter Bigot
8f8cdc18c4 gpio: clean up flags related to logical initialization
The wrapper function detects when a logic-level initial value requires
inverting the physical level initial value, and updates the flags to
effect the necessary change.  However where logical and physical
levels are not inverted the flag requesting logic-level initialization
was left in place and passed to a driver that got confused by it.

Clear the flag after its purpose has been addressed.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-17 09:11:29 -06:00
Alexander Wachter
9a5525c316 include: clock_control: Fix int return value
The return value of clock_control_get_status is a clock_control_status
enum, but in case the device is not ready, an int is returned.
This leads to compiler errors. Introduced a new enum value
CLOCK_CONTROL_STATUS_UNAVAILABLE and return it instead of -ENODEV.

Signed-off-by: Alexander Wachter <alexander.wachter@leica-geosystems.com>
2021-02-17 14:28:50 +01:00
Hubert Miś
ce3dcf2394 net: socket: getsockopt SO_PROTOCOL implementation
This patch adds implementation of socket option used to get
protocol used for given socket (e.g. IPPROTO_TCP). This option
is not defined in POSIX, but it is Linux extension.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-17 10:36:58 +02:00
Hubert Miś
f6263c8143 net: socket: getsockopt SO_TYPE implementation
This patch adds implementation of socket option used to get
type of given socket (e.g. SOCK_STREAM).

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-17 10:36:58 +02: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
28897df295 device: use empty string as drvname when devicetree label is absent
As we move to making the `label` property optional, we need to account
for widespread use of `dev->name` in contexts where the pointer is not
validated before it is dereferenced.  Use an empty string instead of a
null pointer when no label is provided.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-16 14:39:53 -06:00
Peter Bigot
5b36a01a67 device: binding lookup should return null for unsupported names
A null device name should map to a null device.  So should a name that
is empty.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-16 14:39:53 -06:00
Kumar Gala
fc9b8100c7 devicetree: clocks: provide accessors for controller phandle
Provide a helper to extract the devicetree node_id for a CLOCKS
controller from a clocks phandle array.  This can be used with
DEVICE_DT_GET() to directly reference the corresponding controller
device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Co-authored-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2021-02-16 14:15:40 -06:00
Max van Kessel
5dc1c082d7 audio: dmic: fix compile error on arm gcc 8
Fixes invalid conversion (channel) to enum PDM LR.
GCC Permissive Error

Signed-off-by: Max van Kessel <max_van_kessel@msn.com>
2021-02-16 15:29:16 +03:00
Jim Shu
4004665fa7 arch: riscv: linker: fix _image_rom_start symbol
Change _image_rom_start symbol from 0 to the beginning of
ROMABLE_REGION.

Signed-off-by: Jim Shu <cwshu@andestech.com>
2021-02-16 15:16:56 +03:00
Julien Massot
f7e3f4f2d3 arch: arm: cortex_a_r: add support for arm arch timer
This include make possible to use the arm_arch_timer on
platform such as Cortex-A9 or Cortex-R7 which has support for
ARM Global Timer.

The global timer is a 64 bit incrementing counter, memory-mapped
in the private memory region.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
2021-02-15 08:28:51 -05:00
Johan Hedberg
d01fa56f6a drivers: pcie: Introduce API to look up devices by ID
In some cases we cannot know the BDF up-front, so provide a way to
look it up based on the vendor and device ID.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-02-15 08:23:05 -05:00
Johan Hedberg
14da6014a3 drivers: pcie: Move MAX_BUS/DEV/FUNC defines to pcie.h header file
These have been redefined in various places - better to have them in a
single place that different users can use.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-02-15 08:23:05 -05:00
Scott Worley
2b926db4e1 drivers: espi: Microchip eSPI add SAF support
Add ESPI SAF features to the Microchip eSPI driver as
a separate file. ESPI SAF depends upon the core eSPI
driver adding the ability to attach the system SPI
flash to the EC eSPI endpoint instead of the host
eSPI controller.

Signed-off-by: Scott Worley <scott.worley@microchip.com>
2021-02-15 08:22:01 -05:00
Daniel Leung
ce44048d46 x86: rename CONFIG_SSE* to CONFIG_X86_SSE*
This adds X86 keyword to the kconfigs to indicate these are
for x86. The old options are still there marked as
deprecated.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-15 08:21:15 -05:00
Kuba Sanak
a17f19907b lorawan: Add userspace-defined battery level callback API
Provide the LoRaWAN stack with an optional callback to be
called whenever the battery level needs to be read.

In the case of callback not being provided, the LoRaWAN
stack will report 255 (battery level unavailable) as per
the LoRaWAN spec.

Signed-off-by: Kuba Sanak <contact@kuba.fyi>
2021-02-15 08:19:03 -05:00
Flavio Ceolin
7f56bd415f power: constraints: Update constraint documentation
Align documentation with constraint API changes.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-02-15 08:08:36 -05:00
Flavio Ceolin
86a624e2a2 power: Remove PM_STATE_LOCK option
Simplify pm subsystem removing PM_STATE_LOCK option. Constraints API is
small and is a key component of power subsystem.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-02-15 08:08:36 -05: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
Flavio Ceolin
ea4bc728f4 power: Fix documentation
Small fixes in state control documentation.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-02-15 08:08:36 -05:00
Carlo Caione
85479d1523 aarch64: linker: Align end symbols
The end symbols and especially z_mapped_end must be aligned to the MMU
page size.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-02-15 08:07:35 -05:00
Gerard Marull-Paretas
10532a5310 soc: arm: st_stm32: add support for STM32 backup SRAM
Add support for backup SRAM initialization found in multiple STM32
microcontrollers. Linker script facilities are also provided to make it
easy to define variables in the backup SRAM.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2021-02-15 08:04:24 -05:00
Piotr Pryga
0f6fcf9d75 Bluetooth: hci: Fix wrong values of cte type constants
Wrong values were used for CTE type constants. They were
update to comply with BT 5.1 spec.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Hubert Miś
5e43418cf9 net: coap: acknowledgement initialization helper
When handling CoAP Confirmable requests, there is a common
Acknowledgement initialization procedure that repeats for each
response packet initialization. This patch adds a function that
simplifies Acknowledgement initialization procedure encapsulating
repeating code.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-15 10:17:11 +02:00
Hubert Miś
9831ddd14b net: ipv6: add function checking if given address is ULA
This patch adds a helper function to verify if given IPv6 address is
a unique local address.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-15 10:15:18 +02:00
Marcin Niestroj
1bad79ceeb net: offload: fix device and driver names generated by DT device macros
Generated device and driver names have changed with commits [1] and [2],
but net offload drivers missed the conversion. Update net offload DT
device macros now.

[1] commit 8c1bef535b ("device: support generating defines from
  devicetree nodes with no label")
[2] commit f91e9fba51 ("device: fix potential truncation of DT-derived
  device names")

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-14 18:45:04 -05:00