Lines Matching +full:transmit +full:- +full:retries
4 * SPDX-License-Identifier: Apache-2.0
63 struct mcux_sdif_data *data = dev->data; in mcux_sdif_transfer_complete()
66 data->transfer_status |= TRANSFER_DATA_FAILED; in mcux_sdif_transfer_complete()
68 data->transfer_status |= TRANSFER_DATA_COMPLETE; in mcux_sdif_transfer_complete()
70 data->transfer_status |= TRANSFER_CMD_FAILED; in mcux_sdif_transfer_complete()
72 data->transfer_status |= TRANSFER_CMD_COMPLETE; in mcux_sdif_transfer_complete()
76 k_sem_give(&data->transfer_sem); in mcux_sdif_transfer_complete()
94 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_reset()
95 struct mcux_sdif_data *data = dev->data; in mcux_sdif_reset()
97 k_mutex_lock(&data->access_mutex, K_FOREVER); in mcux_sdif_reset()
99 SDIF_DisableInterrupt(config->base, kSDIF_AllInterruptStatus); in mcux_sdif_reset()
102 (void)SDIF_Reset(config->base, kSDIF_ResetAll, MCUX_SDIF_RESET_TIMEOUT_VALUE); in mcux_sdif_reset()
105 SDIF_ClearInterruptStatus(config->base, kSDIF_AllInterruptStatus); in mcux_sdif_reset()
106 SDIF_ClearInternalDMAStatus(config->base, kSDIF_DMAAllStatus); in mcux_sdif_reset()
107 k_mutex_unlock(&data->access_mutex); in mcux_sdif_reset()
115 props->f_max = MCUX_SDIF_F_MAX; in mcux_sdif_get_host_props()
116 props->f_min = MCUX_SDIF_F_MIN; in mcux_sdif_get_host_props()
117 props->power_delay = 500; in mcux_sdif_get_host_props()
118 props->host_caps.high_spd_support = true; in mcux_sdif_get_host_props()
119 props->host_caps.suspend_res_support = true; in mcux_sdif_get_host_props()
120 props->host_caps.vol_330_support = true; in mcux_sdif_get_host_props()
121 props->host_caps.bus_8_bit_support = true; in mcux_sdif_get_host_props()
122 props->max_current_330 = 1024; in mcux_sdif_get_host_props()
128 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_set_io()
131 if (clock_control_get_rate(config->clock_dev, in mcux_sdif_set_io()
132 config->clock_subsys, in mcux_sdif_set_io()
134 return -EINVAL; in mcux_sdif_set_io()
138 if (ios->clock != 0 && in mcux_sdif_set_io()
139 (ios->clock <= MCUX_SDIF_F_MAX) && in mcux_sdif_set_io()
140 (ios->clock >= MCUX_SDIF_F_MIN)) { in mcux_sdif_set_io()
141 bus_clk_hz = SDIF_SetCardClock(config->base, src_clk_hz, ios->clock); in mcux_sdif_set_io()
143 return -ENOTSUP; in mcux_sdif_set_io()
146 } else if (ios->clock != 0) { in mcux_sdif_set_io()
148 return -ENOTSUP; in mcux_sdif_set_io()
151 if (ios->bus_mode != SDHC_BUSMODE_PUSHPULL) { in mcux_sdif_set_io()
152 return -ENOTSUP; in mcux_sdif_set_io()
155 SDIF_EnableCardPower(config->base, ios->power_mode == SDHC_POWER_ON); in mcux_sdif_set_io()
157 switch (ios->bus_width) { in mcux_sdif_set_io()
159 SDIF_SetCardBusWidth(config->base, kSDIF_Bus1BitWidth); in mcux_sdif_set_io()
162 SDIF_SetCardBusWidth(config->base, kSDIF_Bus4BitWidth); in mcux_sdif_set_io()
165 SDIF_SetCardBusWidth(config->base, kSDIF_Bus8BitWidth); in mcux_sdif_set_io()
168 return -ENOTSUP; in mcux_sdif_set_io()
171 if (ios->signal_voltage != SD_VOL_3_3_V) { in mcux_sdif_set_io()
172 return -ENOTSUP; in mcux_sdif_set_io()
182 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_init()
183 struct mcux_sdif_data *data = dev->data; in mcux_sdif_init()
190 ret = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_sdif_init()
195 host_config.responseTimeout = config->response_timeout; in mcux_sdif_init()
196 host_config.cardDetDebounce_Clock = config->cd_debounce_clocks; in mcux_sdif_init()
197 host_config.dataTimeout = config->data_timeout; in mcux_sdif_init()
198 SDIF_Init(config->base, &host_config); in mcux_sdif_init()
200 SDIF_TransferCreateHandle(config->base, &data->transfer_handle, in mcux_sdif_init()
202 config->irq_config_func(dev); in mcux_sdif_init()
204 k_mutex_init(&data->access_mutex); in mcux_sdif_init()
205 k_sem_init(&data->transfer_sem, 0, 1); in mcux_sdif_init()
211 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_get_card_present()
213 return SDIF_DetectCardInsert(config->base, false); in mcux_sdif_get_card_present()
221 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_transfer()
222 struct mcux_sdif_data *dev_data = dev->data; in mcux_sdif_transfer()
232 .dmaDesBufferStartAddr = dev_data->sdif_dma_descriptor, in mcux_sdif_transfer()
238 if (cmd->opcode == SD_GO_IDLE_STATE) { in mcux_sdif_transfer()
240 * Special handling for CMD0- we want to initialize the card in mcux_sdif_transfer()
245 if (!SDIF_SendCardActive(config->base, MCUX_SDIF_DEFAULT_TIMEOUT)) { in mcux_sdif_transfer()
247 return -EIO; in mcux_sdif_transfer()
253 sdif_cmd.index = cmd->opcode; in mcux_sdif_transfer()
254 sdif_cmd.argument = cmd->arg; in mcux_sdif_transfer()
256 sdif_cmd.responseType = (cmd->response_type & SDHC_NATIVE_RESPONSE_MASK); in mcux_sdif_transfer()
262 sdif_data.blockSize = data->block_size; in mcux_sdif_transfer()
263 sdif_data.blockCount = data->blocks; in mcux_sdif_transfer()
268 switch (cmd->opcode) { in mcux_sdif_transfer()
272 sdif_data.txData = data->data; in mcux_sdif_transfer()
277 sdif_data.rxData = data->data; in mcux_sdif_transfer()
282 sdif_data.rxData = data->data; in mcux_sdif_transfer()
285 return -ENOTSUP; in mcux_sdif_transfer()
288 dev_data->transfer_status = 0U; in mcux_sdif_transfer()
289 k_sem_reset(&dev_data->transfer_sem); in mcux_sdif_transfer()
292 error = SDIF_TransferNonBlocking(config->base, in mcux_sdif_transfer()
293 &dev_data->transfer_handle, &dma_config, &transfer); in mcux_sdif_transfer()
295 error = SDIF_TransferNonBlocking(config->base, in mcux_sdif_transfer()
296 &dev_data->transfer_handle, NULL, &transfer); in mcux_sdif_transfer()
298 } while (error == kStatus_SDIF_SyncCmdTimeout && cmd->timeout_ms--); in mcux_sdif_transfer()
301 return -EIO; in mcux_sdif_transfer()
304 while ((dev_data->transfer_status & TRANSFER_CMD_FLAGS) == 0U) { in mcux_sdif_transfer()
305 if (k_sem_take(&dev_data->transfer_sem, K_MSEC(cmd->timeout_ms))) { in mcux_sdif_transfer()
306 return -ETIMEDOUT; in mcux_sdif_transfer()
309 if (dev_data->transfer_status & TRANSFER_CMD_FAILED) { in mcux_sdif_transfer()
310 return -EIO; in mcux_sdif_transfer()
314 while ((dev_data->transfer_status & TRANSFER_DATA_FLAGS) == 0) { in mcux_sdif_transfer()
315 if (k_sem_take(&dev_data->transfer_sem, K_MSEC(data->timeout_ms))) { in mcux_sdif_transfer()
316 return -ETIMEDOUT; in mcux_sdif_transfer()
319 if (dev_data->transfer_status & TRANSFER_DATA_FAILED) { in mcux_sdif_transfer()
320 return -EIO; in mcux_sdif_transfer()
324 memcpy(cmd->response, sdif_cmd.response, sizeof(cmd->response)); in mcux_sdif_transfer()
327 data->bytes_xfered = dev_data->transfer_handle.transferredWords; in mcux_sdif_transfer()
335 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_card_busy()
337 return (SDIF_GetControllerStatus(config->base) & SDIF_STATUS_DATA_BUSY_MASK) ? in mcux_sdif_card_busy()
344 const struct mcux_sdif_config *config = dev->config; in mcux_sdif_stop_transmission()
345 struct mcux_sdif_data *data = dev->data; in mcux_sdif_stop_transmission()
358 /* Disable transmit interrupt, since we are using blocking transfer */ in mcux_sdif_stop_transmission()
359 SDIF_DisableInterrupt(config->base, kSDIF_AllInterruptStatus); in mcux_sdif_stop_transmission()
360 SDIF_ClearInterruptStatus(config->base, kSDIF_AllInterruptStatus); in mcux_sdif_stop_transmission()
363 SDIF_TransferNonBlocking(config->base, &data->transfer_handle, NULL, in mcux_sdif_stop_transmission()
373 struct mcux_sdif_data *dev_data = dev->data; in mcux_sdif_request()
375 ret = k_mutex_lock(&dev_data->access_mutex, K_MSEC(cmd->timeout_ms)); in mcux_sdif_request()
378 return -EBUSY; in mcux_sdif_request()
391 busy_timeout -= 125; in mcux_sdif_request()
395 k_mutex_unlock(&dev_data->access_mutex); in mcux_sdif_request()
396 return -ETIMEDOUT; in mcux_sdif_request()
399 } while (ret != 0 && (cmd->retries-- > 0)); in mcux_sdif_request()
400 k_mutex_unlock(&dev_data->access_mutex); in mcux_sdif_request()