Skip to content

Commit

Permalink
mgmt: ec_host_cmd: add SPI SMT32 backend
Browse files Browse the repository at this point in the history
Add support for SPI host command backend for STM32 chips family.

Unfortunately, the current SPI API can't be used to handle the host
commands communication. The main issues are unknown command size sent
by the host(the SPI transaction sends/receives specific number of bytes)
and need to constant sending status byte(the SPI module is enabled and
disabled per transaction). Thus the SPI backend includes basic SPI STM32
driver adjusted to host command specification.

Signed-off-by: Dawid Niedzwiecki <[email protected]>
  • Loading branch information
niedzwiecki-dawid committed May 23, 2023
1 parent b0688ea commit 6294bd6
Show file tree
Hide file tree
Showing 8 changed files with 814 additions and 2 deletions.
32 changes: 32 additions & 0 deletions doc/services/device_mgmt/ec_host_cmd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,44 @@ one backend layer.
.. image:: ec_host_cmd_shi.png
:align: center

Another case is SPI. Unfortunately, the current SPI API can't be used to handle the host commands
communication. The main issues are unknown command size sent by the host (the SPI transaction
sends/receives specific number of bytes) and need to constant sending status byte (the SPI module
is enabled and disabled per transaction). It forces implementing the SPI driver within a backend,
as it is done for SHI. That means a SPI backend has to implemented per chip family. However, it
can be changed in the future once the SPI API is extended to host command needs.

That approach requires configuring the SPI dts node in a special way. The main compatible string of
a SPI node has changed to use the Host Command version of a SPI driver. The rest of the properties
should be configured as usual. Example of the SPI node for STM32:

.. code-block:: devicetree
&spi1 {
/* Change the compatible string to use the Host Command version of the
* STM32 SPI driver
*/
compatible = "st,stm32-spi-host-cmd";
status = "okay";
dmas = <&dma2 3 3 0x38440 0x03>,
<&dma2 0 3 0x38480 0x03>;
dma-names = "tx", "rx";
/* This field is used to point at our CS pin */
cs-gpios = <&gpioa 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
The chip that runs Zephyr is a SPI slave and the `cs-gpios` property is used to point our CS pin.
For the SPI, it is required to set the backend chosen node ``zephyr,host-cmd-spi-backend``.

The supported backend and peripheral drivers:

* Simulator
* SHI - ITE and NPCX
* eSPI - any eSPI slave driver that support :kconfig:option:`CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD` and
:kconfig:option:`CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE`
* UART - any UART driver that supports the asynchronous API
* SPI - STM32

Initialization
**************
Expand All @@ -54,6 +85,7 @@ initializes the host command subsystem by calling :c:func:`ec_host_cmd_init`:
* ``zephyr,host-cmd-espi-backend``
* ``zephyr,host-cmd-shi-backend``
* ``zephyr,host-cmd-uart-backend``
* ``zephyr,host-cmd-spi-backend``

If no backend chosen node is configured, the application must call the :c:func:`ec_host_cmd_init`
function directly. This way of initialization is useful if a backend is chosen in runtime
Expand Down
10 changes: 10 additions & 0 deletions dts/bindings/spi/st,stm32-spi-host-cmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2023 Google LLC
# SPDX-License-Identifier: Apache-2.0

description: |
Host Command version of STM32 SPI controller.
All properties are the same, but a different driver is used.
compatible: "st,stm32-spi-host-cmd"

include: st,stm32-spi.yaml
10 changes: 10 additions & 0 deletions dts/bindings/spi/st,stm32h7-spi-host-cmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2023 Google LLC
# SPDX-License-Identifier: Apache-2.0

description: |
Host Command version of STM32H7 SPI controller.
All properties are the same, but a different driver is used.
compatible: "st,stm32h7-spi-host-cmd"

include: st,stm32h7-spi.yaml
4 changes: 3 additions & 1 deletion subsys/mgmt/ec_host_cmd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ config EC_HOST_CMD_HANDLER_TX_BUFFER_SIZE
default 0 if EC_HOST_CMD_BACKEND_ESPI
default 0 if EC_HOST_CMD_BACKEND_SHI
default 256 if EC_HOST_CMD_BACKEND_UART
default 552 if EC_HOST_CMD_BACKEND_SPI
default 256
help
Buffer size in bytes for TX buffer defined by the host command handler.
Expand All @@ -38,6 +39,7 @@ config EC_HOST_CMD_HANDLER_RX_BUFFER_SIZE
default 256 if EC_HOST_CMD_BACKEND_ESPI
default 0 if EC_HOST_CMD_BACKEND_SHI
default 544 if EC_HOST_CMD_BACKEND_UART
default 544 if EC_HOST_CMD_BACKEND_SPI
default 256
help
Buffer size in bytes for TX buffer defined by the host command handler.
Expand All @@ -56,7 +58,7 @@ config EC_HOST_CMD_HANDLER_PRIO

config EC_HOST_CMD_INIT_PRIORITY
int "Initialization priority"
default 60
default 80
range 0 99
help
Initialization priority for Host Command. It must be higher than the initialization
Expand Down
4 changes: 4 additions & 0 deletions subsys/mgmt/ec_host_cmd/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ zephyr_library_sources_ifdef(
zephyr_library_sources_ifdef(
CONFIG_EC_HOST_CMD_BACKEND_UART
ec_host_cmd_backend_uart.c)

zephyr_library_sources_ifdef(
CONFIG_EC_HOST_CMD_BACKEND_SPI_STM32
ec_host_cmd_backend_spi_stm32.c)
23 changes: 23 additions & 0 deletions subsys/mgmt/ec_host_cmd/backends/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
DT_CHOSEN_ESPI_BACKEND := zephyr,host-cmd-espi-backend
DT_CHOSEN_SHI_BACKEND := zephyr,host-cmd-shi-backend
DT_CHOSEN_UART_BACKEND := zephyr,host-cmd-uart-backend
DT_CHOSEN_SPI_BACKEND := zephyr,host-cmd-spi-backend

config EC_HOST_CMD_BACKEND_SIMULATOR
bool "Embedded Controller Host Command Backend Simulator"
Expand Down Expand Up @@ -37,6 +38,12 @@ config EC_HOST_CMD_BACKEND_UART
Enable support for Embedded Controller host commands using
the UART.

config EC_HOST_CMD_BACKEND_SPI
bool "Host commands support using SPI"
help
Enable support for Embedded Controller host commands using
the SPI.

if EC_HOST_CMD_BACKEND_SHI

choice EC_HOST_CMD_BACKEND_SHI_DRIVER
Expand Down Expand Up @@ -79,3 +86,19 @@ config EC_HOST_CMD_BACKEND_SHI_MAX_RESPONSE
response.

endif # EC_HOST_CMD_BACKEND_SHI

if EC_HOST_CMD_BACKEND_SPI

choice EC_HOST_CMD_BACKEND_SPI_DRIVER
prompt "SHI driver"
default EC_HOST_CMD_BACKEND_SPI_STM32 if SOC_FAMILY_STM32

config EC_HOST_CMD_BACKEND_SPI_STM32
bool "SPI by STM32"
help
This option enables the driver for SPI backend in the
STM32 chip family.

endchoice

endif # EC_HOST_CMD_BACKEND_SPI
Loading

0 comments on commit 6294bd6

Please sign in to comment.