Skip to content

Commit e2fe582

Browse files
danieldegrassedleach02
authored andcommitted
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 <[email protected]>
1 parent 7840b07 commit e2fe582

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

drivers/sdhc/imx_usdhc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int imx_usdhc_request(const struct device *dev, struct sdhc_command *cmd,
586586
host_cmd.index = cmd->opcode;
587587
host_cmd.argument = cmd->arg;
588588
/* Mask out part of response type field used for SPI commands */
589-
host_cmd.responseType = (cmd->response_type & 0xF);
589+
host_cmd.responseType = (cmd->response_type & SDHC_NATIVE_RESPONSE_MASK);
590590
transfer.command = &host_cmd;
591591
if (cmd->timeout_ms == SDHC_TIMEOUT_FOREVER) {
592592
request.command_timeout = K_FOREVER;
@@ -711,8 +711,10 @@ static int imx_usdhc_request(const struct device *dev, struct sdhc_command *cmd,
711711
k_mutex_unlock(&dev_data->access_mutex);
712712
/* Record command response */
713713
memcpy(cmd->response, host_cmd.response, sizeof(cmd->response));
714-
/* Record number of bytes xfered */
715-
data->bytes_xfered = dev_data->transfer_handle.transferredWords;
714+
if (data) {
715+
/* Record number of bytes xfered */
716+
data->bytes_xfered = dev_data->transfer_handle.transferredWords;
717+
}
716718
return ret;
717719
}
718720

drivers/sdhc/sdhc_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static int sdhc_spi_response_get(const struct device *dev, struct sdhc_command *
231231
}
232232
/* else IDLE_STATE bit is set, which is not an error, card is just resetting */
233233
}
234-
switch ((cmd->response_type & 0xF0)) {
234+
switch ((cmd->response_type & SDHC_SPI_RESPONSE_TYPE_MASK)) {
235235
case SD_SPI_RSP_TYPE_R1:
236236
/* R1 response - one byte*/
237237
break;

include/zephyr/drivers/sdhc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct sdhc_command {
4848
int timeout_ms; /*!< Command timeout in milliseconds */
4949
};
5050

51+
#define SDHC_NATIVE_RESPONSE_MASK 0xF
52+
#define SDHC_SPI_RESPONSE_TYPE_MASK 0xF0
53+
5154
/**
5255
* @brief SD host controller data structure
5356
*

0 commit comments

Comments
 (0)