From e2fe582d6254b6ec036479456f9562ba96a6b14a Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 6 May 2022 18:02:41 -0500 Subject: [PATCH] drivers: sdhc: Add SD response type masks Add SD response type masks, to allow drivers to mask out the SPI or SD native mode response type based on the SD host controller mode they use. Signed-off-by: Daniel DeGrasse --- drivers/sdhc/imx_usdhc.c | 8 +++++--- drivers/sdhc/sdhc_spi.c | 2 +- include/zephyr/drivers/sdhc.h | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/sdhc/imx_usdhc.c b/drivers/sdhc/imx_usdhc.c index 88684e04d02..73c1342bd84 100644 --- a/drivers/sdhc/imx_usdhc.c +++ b/drivers/sdhc/imx_usdhc.c @@ -586,7 +586,7 @@ static int imx_usdhc_request(const struct device *dev, struct sdhc_command *cmd, host_cmd.index = cmd->opcode; host_cmd.argument = cmd->arg; /* Mask out part of response type field used for SPI commands */ - host_cmd.responseType = (cmd->response_type & 0xF); + host_cmd.responseType = (cmd->response_type & SDHC_NATIVE_RESPONSE_MASK); transfer.command = &host_cmd; if (cmd->timeout_ms == SDHC_TIMEOUT_FOREVER) { request.command_timeout = K_FOREVER; @@ -711,8 +711,10 @@ static int imx_usdhc_request(const struct device *dev, struct sdhc_command *cmd, k_mutex_unlock(&dev_data->access_mutex); /* Record command response */ memcpy(cmd->response, host_cmd.response, sizeof(cmd->response)); - /* Record number of bytes xfered */ - data->bytes_xfered = dev_data->transfer_handle.transferredWords; + if (data) { + /* Record number of bytes xfered */ + data->bytes_xfered = dev_data->transfer_handle.transferredWords; + } return ret; } diff --git a/drivers/sdhc/sdhc_spi.c b/drivers/sdhc/sdhc_spi.c index 2d64da2cad8..b5c8fab1e91 100644 --- a/drivers/sdhc/sdhc_spi.c +++ b/drivers/sdhc/sdhc_spi.c @@ -231,7 +231,7 @@ static int sdhc_spi_response_get(const struct device *dev, struct sdhc_command * } /* else IDLE_STATE bit is set, which is not an error, card is just resetting */ } - switch ((cmd->response_type & 0xF0)) { + switch ((cmd->response_type & SDHC_SPI_RESPONSE_TYPE_MASK)) { case SD_SPI_RSP_TYPE_R1: /* R1 response - one byte*/ break; diff --git a/include/zephyr/drivers/sdhc.h b/include/zephyr/drivers/sdhc.h index 1cb33e1c6be..f0368f3a564 100644 --- a/include/zephyr/drivers/sdhc.h +++ b/include/zephyr/drivers/sdhc.h @@ -48,6 +48,9 @@ struct sdhc_command { int timeout_ms; /*!< Command timeout in milliseconds */ }; +#define SDHC_NATIVE_RESPONSE_MASK 0xF +#define SDHC_SPI_RESPONSE_TYPE_MASK 0xF0 + /** * @brief SD host controller data structure *