From 8dbe1830ce99abacff6ef092e2e526c90a93b096 Mon Sep 17 00:00:00 2001 From: Dragos Bogdan Date: Tue, 2 Jul 2024 17:27:39 +0300 Subject: [PATCH 1/3] platform: max32670: Add VDDIO selection support for SPI Signed-off-by: Dragos Bogdan --- drivers/platform/maxim/max32670/maxim_spi.c | 36 +++++++++++++++++++++ drivers/platform/maxim/max32670/maxim_spi.h | 1 + 2 files changed, 37 insertions(+) diff --git a/drivers/platform/maxim/max32670/maxim_spi.c b/drivers/platform/maxim/max32670/maxim_spi.c index a49ca3d5056..654ce7bb5ff 100644 --- a/drivers/platform/maxim/max32670/maxim_spi.c +++ b/drivers/platform/maxim/max32670/maxim_spi.c @@ -57,6 +57,38 @@ /************************ Functions Definitions *******************************/ /******************************************************************************/ +/** + * @brief Configure the VDDIO level for a SPI interface + * @param desc - the SPI descriptor + * @return 0 in case of success, -EINVAL otherwise + */ +static int32_t _max_spi_config_pins(struct no_os_spi_desc *desc) +{ + struct max_spi_init_param *eparam; + mxc_gpio_cfg_t spi_pins; + + eparam = desc->extra; + + switch(desc->device_id) { + case 0: + spi_pins = gpio_cfg_spi0; + break; + case 1: + spi_pins = gpio_cfg_spi1; + break; + case 2: + spi_pins = gpio_cfg_spi2; + break; + default: + return -EINVAL; + } + + spi_pins.vssel = eparam->vssel; + MXC_GPIO_Config(&spi_pins); + + return 0; +} + static int _max_spi_config(struct no_os_spi_desc *desc) { int32_t ret; @@ -72,6 +104,10 @@ static int _max_spi_config(struct no_os_spi_desc *desc) goto err_init; } + ret = _max_spi_config_pins(desc); + if (ret) + return ret; + ret = MXC_SPI_SetMode(MXC_SPI_GET_SPI(desc->device_id), (mxc_spi_mode_t)desc->mode); if (ret) { diff --git a/drivers/platform/maxim/max32670/maxim_spi.h b/drivers/platform/maxim/max32670/maxim_spi.h index 456512355c2..9558e5fcea8 100644 --- a/drivers/platform/maxim/max32670/maxim_spi.h +++ b/drivers/platform/maxim/max32670/maxim_spi.h @@ -62,6 +62,7 @@ enum spi_ss_polarity { struct max_spi_init_param { uint32_t num_slaves; enum spi_ss_polarity polarity; + mxc_gpio_vssel_t vssel; }; #endif From 4d8dea2a486397f047d795f0c3a59429faad62d7 Mon Sep 17 00:00:00 2001 From: Dragos Bogdan Date: Tue, 2 Jul 2024 17:31:14 +0300 Subject: [PATCH 2/3] platform: max32670: Add VDDIO selection support for UART Signed-off-by: Dragos Bogdan --- drivers/platform/maxim/max32670/maxim_uart.c | 37 ++++++++++++++++++++ drivers/platform/maxim/max32670/maxim_uart.h | 1 + 2 files changed, 38 insertions(+) diff --git a/drivers/platform/maxim/max32670/maxim_uart.c b/drivers/platform/maxim/max32670/maxim_uart.c index b673dd9d33d..6c647d0d39e 100644 --- a/drivers/platform/maxim/max32670/maxim_uart.c +++ b/drivers/platform/maxim/max32670/maxim_uart.c @@ -221,6 +221,39 @@ void uart_rx_callback(void *context) max_uart_read_nonblocking(d, &c, 1); } +/** + * @brief Configure the VDDIO for the UART pins. + * @param device_id - the interface number. + * @param vssel - the voltage level of the interface. + * @return 0 in case of success, -EINVAL otherwise. + */ +static int32_t _max_uart_pins_config(uint32_t device_id, mxc_gpio_vssel_t vssel) +{ + mxc_gpio_cfg_t uart_pins; + + switch (device_id) { + case 0: + uart_pins = gpio_cfg_uart0; + break; + case 1: + uart_pins = gpio_cfg_uart1; + break; + case 2: + uart_pins = gpio_cfg_uart2; + break; + case 3: + uart_pins = gpio_cfg_uart3; + break; + default: + return -EINVAL; + } + + uart_pins.vssel = vssel; + MXC_GPIO_Config(&uart_pins); + + return 0; +} + /** * @brief Initialize the UART communication peripheral. * @param desc - The UART descriptor. @@ -319,6 +352,10 @@ static int32_t max_uart_init(struct no_os_uart_desc **desc, goto error; } + ret = _max_uart_pins_config(descriptor->device_id, eparam->vssel); + if (ret) + goto error; + ret = MXC_UART_SetDataSize(uart_regs, size); if (ret != E_NO_ERROR) { ret = -EINVAL; diff --git a/drivers/platform/maxim/max32670/maxim_uart.h b/drivers/platform/maxim/max32670/maxim_uart.h index 935f0820a77..dc190c40a04 100644 --- a/drivers/platform/maxim/max32670/maxim_uart.h +++ b/drivers/platform/maxim/max32670/maxim_uart.h @@ -58,6 +58,7 @@ enum max_uart_flow_ctrl { */ struct max_uart_init_param { enum max_uart_flow_ctrl flow; + mxc_gpio_vssel_t vssel; }; /** From cf7caa93b8e1155d46d9d29effa80df3b26f075b Mon Sep 17 00:00:00 2001 From: Dragos Bogdan Date: Tue, 2 Jul 2024 17:33:02 +0300 Subject: [PATCH 3/3] platform: max32670: Update UART max_uart_flow_ctrl enum For consistency reasons, to match the other Maxim targets. Signed-off-by: Dragos Bogdan --- drivers/platform/maxim/max32670/maxim_uart.c | 4 ++-- drivers/platform/maxim/max32670/maxim_uart.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/platform/maxim/max32670/maxim_uart.c b/drivers/platform/maxim/max32670/maxim_uart.c index 6c647d0d39e..3b64355a81f 100644 --- a/drivers/platform/maxim/max32670/maxim_uart.c +++ b/drivers/platform/maxim/max32670/maxim_uart.c @@ -335,10 +335,10 @@ static int32_t max_uart_init(struct no_os_uart_desc **desc, } switch (eparam->flow) { - case MAX_UART_FLOW_DIS: + case UART_FLOW_DIS: flow = MXC_UART_FLOW_DIS; break; - case MAX_UART_FLOW_EN: + case UART_FLOW_EN: flow = MXC_UART_FLOW_EN; break; default: diff --git a/drivers/platform/maxim/max32670/maxim_uart.h b/drivers/platform/maxim/max32670/maxim_uart.h index dc190c40a04..56c971d1778 100644 --- a/drivers/platform/maxim/max32670/maxim_uart.h +++ b/drivers/platform/maxim/max32670/maxim_uart.h @@ -49,8 +49,8 @@ * @brief UART flow control */ enum max_uart_flow_ctrl { - MAX_UART_FLOW_DIS, - MAX_UART_FLOW_EN + UART_FLOW_DIS, + UART_FLOW_EN }; /**