Commit graph

338 commits

Author SHA1 Message Date
Peter Bigot bfb56c5e20 drivers: flash: nrf_qspi_nor: support read of sub-word lengths
mcuboot and possibly other tools read single byte values to determine
the state of objects.  Rather than fail to do the read of values too
short for this peripheral detect the situation and read into a stack
buffer that meets the length criteria, and on success copy the data
into the provided buffer.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-21 17:04:05 +02:00
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

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

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

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

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
Kumar Gala db725c0ec9 drivers: Replace GPIO_CS Kconfig with devicetree detection
Use DT_INST_SPI_DEV_HAS_CS_GPIOS() in drivers to determine if we should
utilize CS_GPIO base SPI chipselect handling.  This allows us to remove
Kconfig option for this feature.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-09 13:07:05 +02:00
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

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

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Tomasz Bursztyka 8d7bb8ffd8 device: Refactor device structures
When the device driver model got introduced, there were no concept of
SYS_INIT() which can be seen as software service. These were introduced
afterwards and reusing the device infrastructure for simplicity.
However, it meant to allocate a bit too much for something that only
required an initialization function to be called at right time.

Thus refactoring the devices structures relevantly:
- introducing struct init_entry which is a generic init end-point
- struct deviceconfig is removed and struct device owns everything now.
- SYS_INIT() generates only a struct init_entry via calling
  INIT_ENTRY_DEFINE()
- DEVICE_AND_API_INIT() generates a struct device and calls
  INIT_ENTRY_DEFINE()
- init objects sections are in ROM
- device objects sections are in RAM (but will end up in ROM once they
  will be 'constified')

It also generate a tiny memory gain on both ROM and RAM, which is nice.

Perhaps kernel/device.c could be renamed to something more relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Andrzej Głąbek 8ee12207ff drivers: flash: Add driver for AT45 compatible SPI flash chips
Add a driver that can handle several instances of AT45 family chips,
which are enabled by specifying DT nodes for them with the "compatible"
property set to "atmel,at45" and other required properties like JEDEC
ID, chip capacity, block and page size etc. configured accordingly.

The driver is only capable of using "power of 2" binary page sizes in
those chips and at initialization configures them to work in that mode
(unless it is already done).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-05-07 14:51:10 +02:00
Adam Serbinski 26be827af8 flash: sam0: set write_block_size=1 when EMULATE_BYTE_PAGES is set
The sam0 has a page size of 64 bytes, making it incompatible with
the nvs driver that specifies a maximum write block size of
32 bytes. When CONFIG_SOC_FLASH_SAM0_EMULATE_BYTE_PAGES is set,
it should report a write block size of 1 byte, which is compatible
with nvs.

Signed-off-by: Adam Serbinski <aserbinski@gmail.com>
2020-05-07 10:06:17 +02:00
Peter Bigot 7e35983977 drivers: flash: spi-nor: correct index into array property value
The dpd-wake-sequence has a value that is an array of three integers,
which was formerly indexed by a suffix on the property name.  This was
updated to new accessors but failed to separate the index from the
property name.  Update the access idiom.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-07 00:59:29 -05:00
Kumar Gala fdd85d5ad7 dts: Rename DT_HAS_NODE macro to DT_HAS_NODE_STATUS_OKAY
Rename DT_HAS_NODE to DT_HAS_NODE_STATUS_OKAY so the semantics are
clear.  As going forward DT_HAS_NODE will report if a NODE exists
regardless of its status.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-06 05:25:41 -05:00
Kumar Gala 50345848b4 drivers: flash: flash_simulator: Convert to new DT macros
Convert flash_simulator to use new DT macros and remove associated
defines in dts_fixup.h.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-30 04:47:44 -05:00
Kumar Gala 7a15afc1d4 drivers: flash: replace DT_FLASH_DEV_NAME with DT macro
Replace DT_FLASH_DEV_NAME with DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL.
We now set zephyr,flash-controller in the chosen node of the device
tree to the flash controller device.

NOTE: For a SoCs with on die flash, this points to the controller and
      not the 'soc-nv-flash' node.  Typically the controller is the
      parent of the 'soc-nv-flash' node).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-27 18:43:20 -05:00
Martí Bolívar 100187cb64 drivers: flash: nordic qspi: finish DT API conversion
Also convert bus node access to the new API.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-21 18:31:08 +02:00
Peter A. Bigot 3d8125a47c drivers: flash: nrfx_qspi_nor: fix semaphore errors
The code generally invoked qspi_wait_for_completion() within a locked
region without verifying that an operation was successfully initiated.
This caused a deadlock whenever the operation failed, e.g. because the
data buffer was not 4-byte aligned.  Update that function to take the
result of the operation and either wait for completion or release the
lock, depending on its value.

Also uniformly use the correct type for Nordic HAL error values, and
refactor the erase module so that the correct values are displayed in
the diagnostic when something goes wrong.

Also check the alignment requirements for the flash address and
transfer size, which are highly constrained on this device.  This
driver also requires 4-byte aligned data buffer; this is checked in
the Nordic HAL.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-04-20 15:41:35 +02:00
Erwan Gouriou 65eacef644 drivers/flash: stm32: Use stm32 generic compat as driver compatible
Instead of various series compatibles, use single stm32 generic
compatible as reference for stm32 flash driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-20 03:51:36 -05:00
Kumar Gala f04490e300 drivers: flash: nrf_qspi_nor: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 11:17:32 -05:00
Kumar Gala 8dc6f9f5dd drivers: flash: nrf: Conver to new DT macros
Convert driver from DT_FLASH_BASE_ADDRESS and DT_FLASH_DEV_NAME to use
DT_REG_ADDR and DT_INST_LABEL.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 06:22:40 -05:00
Kumar Gala 613dba7fac drivers: flash: stm32: Convert to new DT macros
Replace DT_FLASH_SIZE with new DT_REG_SIZE macro.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 06:22:40 -05:00
Kumar Gala f311c8ad60 drivers: flash: atmel sam: Fix DT_DRV_COMPAT setting
For a flash driver DT_DRV_COMPAT should be the compatible for the flash
controller and not the soc-nv-flash.  Change to driver to use the flash
controllers compatible and get the soc-nv-flash properties as a child of
that controller.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 06:22:40 -05:00
Kumar Gala 14b6b8b07c drivers: flash: silabs: Fix DT_DRV_COMPAT setting
For a flash driver DT_DRV_COMPAT should be the compatible for the flash
controller and not the soc-nv-flash.  Change to driver to use the flash
controllers compatible and get the soc-nv-flash properties as a child of
that controller.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 06:22:40 -05:00
Kumar Gala a61d2a281c drivers: flash: mcux: Fix DT_DRV_COMPAT setting
For a flash driver DT_DRV_COMPAT should be the compatible for the flash
controller and not the soc-nv-flash.  Change to driver to use the flash
controllers compatible and get the soc-nv-flash properties as a child of
that controller.

The soc_flash_mcux supports several possible compatible so handle that
as part of how we set DT_DRV_COMPAT.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 06:22:40 -05:00
Kumar Gala 3fa974cab0 drivers: flash: rv32m1: Fix DT_DRV_COMPAT setting
For a flash driver DT_DRV_COMPAT should be the compatible for the flash
controller and not the soc-nv-flash.  Change to driver to use the flash
controllers compatible and get the soc-nv-flash properties as a child of
that controller.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-15 06:22:40 -05:00
Peter Bigot 95baa51de8 drivers: flash: spi-nor: fix unconditional use of BE32K
The 32 KiBy bulk erase command was being invoked without respecting
the flag that indicates it's supported.  Make the invocation
conditional.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-14 09:13:34 -05:00
Steven Slupsky e55f1987a0 drivers: flash: sam0: fix unaligned memory read
Use the UNALIGNED_GET() macro instead of the
flash_sam0_read_unaigned_u32() function to ensure
word alignment of the source address.

Signed-off-by: Steven Slupsky <sslupsky@gmail.com>

drivers: flash: sam0:  fix whitespace

Fix checkpass whitespace error.

Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
2020-04-11 15:34:21 -04:00
Ivo Clarysse db400713ba drivers/flash: shell: Add optional device argument
Update `flash` shell commands to take an optional device argument,
instead of using the chosen flash device.

Signed-off-by: Ivo Clarysse <ivo@bcdevices.com>
2020-04-09 16:36:39 +02:00
Kumar Gala c7f8b30f53 drivers: flash: openisa rv32m1: Replace DT_FLASH define
Replace DT_FLASH_SIZE with new DT_INST_REG_SIZE as we phase out
DT_FLASH define usage.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-09 08:41:09 -05:00
Kumar Gala 19e91ab9f2 drivers: flash: nxp mcux: Replace DT_FLASH define
Replace DT_FLASH_WRITE_BLOCK_SIZE with new DT_INST_NODE_HAS_PROP and
DT_INST_PROP macro as we phase out DT_FLASH define usage.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-09 08:41:09 -05:00
Kumar Gala 9a28ff317f drivers: flash: atmel_sam: Replace DT_FLASH define
Replace DT_FLASH_DEV_BASE_ADDRESS with new DT_REG_ADDR/DT_INST macro as
we phase out DT_FLASH define usage.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-09 08:41:09 -05:00
Kumar Gala 608dba486e drivers: flash: Use DT_INST_LABEL instead of DT_FLASH_DEV_NAME
Replace use of DT_FLASH_DEV_NAME with DT_INST_LABEL in drivers as we
want to phase out DT_FLASH_DEV_NAME.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-08 15:28:52 -05:00
Peter Bigot 08fea84a30 drivers: flash: sam: fix timeout units
The duration is used in math with the uptime clock, not as a timeout.
Correct value expression and rename to clarify units.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-07 16:39:08 -05:00
Erwan Gouriou e4589b8657 drivers: flash: stm32: Use correct driver compatible
Use valid stm32 flash driver compatibles instead of flash
area compatible.
For 'write_block_size' property, use reference to soc-nv-flash.

fixes #23997

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-07 10:52:23 -04:00
Dominik Ermel 143f9bfd4e drivers/flash/nrfx: Enable partial erase of flash
When enabled, instead of erasing entire flash page at once, page will
be erased in defined time slices. Erasing single page stalls CPU
for significant time share (~80ms) and partial erase divides the
operation in to the shorter time periods, resuming CPU operation in
meantime and enabling better scheduling of time sensitive operations.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-04-06 22:12:33 -04:00
Vinayak Kariappa Chettimada 0d8eb1c5ad drivers: flash: nrf: Fix radio sync with BLE LL split controller
Delay radio abort called in the flash driver to emulate the
behavior of pre-empt timeout in Bluetooth LL split
controller. Without this, the driver aborted radio events
in its reserved time space.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-03 22:09:50 +02:00
Andy Ross 32bb2395c2 timeout: Fix up API usage
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them.  Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:

+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
  values for equality (e.g. with K_FOREVER or K_NO_WAIT).

+ Adding a k_msleep() synonym for k_sleep() which can continue to take
  integral arguments as k_sleep() moves away to timeout arguments.

+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
  generate timeout arguments.

+ Removing the usage of K_NO_WAIT as the final argument to
  K_THREAD_DEFINE().  This is just a count of milliseconds and we need
  to use a zero.

This patch include no logic changes and should not affect generated
code at all.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Kumar Gala 28870e7a32 drivers: atmel sam0: Convert atmel sam0 drivers to new DT_INST macros
Convert older DT_INST_ macro use in atmel sam0 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-27 11:02:57 -05:00
Kumar Gala 4d977e43ca drivers: flash: spi_nor: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-27 10:05:46 -05:00
Kumar Gala 11c8de15a8 drivers: flash: spi_flash_w25qxxdv: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-27 10:00:29 -05:00
Kumar Gala 63ccb98eee drivers: openisa: Convert openisa drivers to new DT_INST macros
Convert older DT_INST_ macro use in openisa drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-27 05:28:37 -05:00
Thomas Schmid 7f5bdfb2a4 drivers: flash: stm32: fix warnings about format specifiers
Newlibc defines off_t as long int. Change %d format specifier
to %ld for logging of offsets.

Signed-off-by: Thomas Schmid <tom@lfence.de>
2020-03-27 10:15:03 +01:00
Kumar Gala 3af49c5b55 drivers: atmel sam: Convert atmel sam drivers to new DT_INST macros
Convert older DT_INST_ macro use in atmel sam drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 16:31:31 -05:00
Kumar Gala 989484b4bf drivers: stm32: Convert STM32 drivers to new DT_INST macros
Convert older DT_INST_ macro use in STM32 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 12:22:12 -05:00
Kumar Gala 4cb0a5d992 drivers: silabs: Convert silabs drivers to new DT_INST macros
Convert older DT_INST_ macro use in silab drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 05:26:23 -05:00
Kumar Gala 4b9fe8a24e drivers: mcux: Convert MCUX drivers to new DT_INST macros
Convert older DT_INST_ macro use in MCUX drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 03:40:09 -05:00
Alexander Wachter 802552414c drivers: flash: stm32g4: Fix erase on wrong bank
In the default configuration of the stm32g4 is the dual bank mode.
In dual bank mode, the flash is split into two banks with 256k each.
The erase pages have a range form 0 to 127, where each page has 2k.
If one wants to erase an area above 256k, the driver has to switch
to bank 2 befor erasing. Otherwise it will erase the page moulo 127.

Signed-off-by: Alexander Wachter <alexander.wacher@leica-geosystems.com>
2020-03-24 14:25:47 -05:00
Alexander Wachter 7b9320beed drivers: flash: stm32: Introduce logs in the flash code
This commit introduces some logs in the stm32 flash implementation.
Thith the logs it is easier to locate problems when they arrise.

Signed-off-by: Alexander Wachter <alexander.wacher@leica-geosystems.com>
2020-03-24 14:25:47 -05:00
Erwan Gouriou 5cd10c70bd drivers/flash: stm32: DT_INST_0_SOC_NV_FLASH_LABEL is not dev name
Don't use DT_INST_0_SOC_NV_FLASH_LABEL as device name.
Use DT_FLASH_DEV_NAME instead

Fixes #23678

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-03-23 08:51:22 -05:00
Peter Bigot 414bdde2f0 drivers: flash: spi_nor: avoid coverity warning in untested code
Coverity doesn't invoke the build for this module with a configuration
that provides a non-zero delay for entering or releasing deep power
down, so it sees a check that a value known to be non-negative
magically became negative without being touched, and so screams about
dead code.

Refactor to make the adjustments unconditional which has the same
effect in any reasonable level of optimization while making it
slightly less obvious that the value may not change.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-03-19 17:13:52 -04:00
Carles Cufi 4b37a8f3a4 Revert "global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()"
This reverts commit 8739517107.

Pull Request #23437 was merged by mistake with an invalid manifest.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy 8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-19 15:47:53 +01:00
Erwan Gouriou 22af564f19 drivers: flash: flash_stm32: convert to DT_INST defines
Convert driver to use DT_INST_ defines.
Removed DT_FLASH_DEV fixup macros, except DT_FLASH_DEV_NAME
used in applications.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-03-17 11:03:10 -06:00