Lines Matching +full:rx +full:- +full:sync +full:- +full:mode

4  * SPDX-License-Identifier: Apache-2.0
78 struct k_sem sync; member
100 MMC_TypeDef *sdmmcx = priv->hsd.Instance; in stm32_sdmmc_fc_enable()
102 sdmmcx->CLKCR |= SDMMC_CLKCR_HWFC_EN; in stm32_sdmmc_fc_enable()
108 struct stm32_sdmmc_priv *priv = dev->data; in stm32_sdmmc_isr()
111 HAL_MMC_IRQHandler(&priv->hsd); in stm32_sdmmc_isr()
113 HAL_SD_IRQHandler(&priv->hsd); in stm32_sdmmc_isr()
122 priv->status = hsd->ErrorCode; \
124 k_sem_give(&priv->sync); \
146 (clock_control_subsys_t)&priv->pclken[1], in stm32_sdmmc_clock_enable()
149 return -EIO; in stm32_sdmmc_clock_enable()
157 (clock_control_subsys_t)&priv->pclken[1], in stm32_sdmmc_clock_enable()
160 return -EIO; in stm32_sdmmc_clock_enable()
165 return -ENOTSUP; in stm32_sdmmc_clock_enable()
170 return clock_control_on(clock, (clock_control_subsys_t)&priv->pclken[0]); in stm32_sdmmc_clock_enable()
181 (clock_control_subsys_t)&priv->pclken); in stm32_sdmmc_clock_disable()
204 if (!device_is_ready(dma->dev)) { in stm32_sdmmc_configure_dma()
206 return -ENODEV; in stm32_sdmmc_configure_dma()
209 dma->cfg.user_data = handle; in stm32_sdmmc_configure_dma()
211 ret = dma_config(dma->dev, dma->channel, &dma->cfg); in stm32_sdmmc_configure_dma()
217 handle->Instance = __LL_DMA_GET_STREAM_INSTANCE(dma->reg, dma->channel_nb); in stm32_sdmmc_configure_dma()
218 handle->Init.Channel = dma->cfg.dma_slot * DMA_CHANNEL_1; in stm32_sdmmc_configure_dma()
219 handle->Init.PeriphInc = DMA_PINC_DISABLE; in stm32_sdmmc_configure_dma()
220 handle->Init.MemInc = DMA_MINC_ENABLE; in stm32_sdmmc_configure_dma()
221 handle->Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; in stm32_sdmmc_configure_dma()
222 handle->Init.MemDataAlignment = DMA_MDATAALIGN_WORD; in stm32_sdmmc_configure_dma()
223 handle->Init.Mode = DMA_PFCTRL; in stm32_sdmmc_configure_dma()
224 handle->Init.Priority = table_priority[dma->cfg.channel_priority], in stm32_sdmmc_configure_dma()
225 handle->Init.FIFOMode = DMA_FIFOMODE_ENABLE; in stm32_sdmmc_configure_dma()
226 handle->Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; in stm32_sdmmc_configure_dma()
227 handle->Init.MemBurst = DMA_MBURST_INC4; in stm32_sdmmc_configure_dma()
228 handle->Init.PeriphBurst = DMA_PBURST_INC4; in stm32_sdmmc_configure_dma()
239 err = stm32_sdmmc_configure_dma(&priv->dma_tx_handle, &priv->dma_tx); in stm32_sdmmc_dma_init()
244 __HAL_LINKDMA(&priv->hsd, hdmatx, priv->dma_tx_handle); in stm32_sdmmc_dma_init()
245 HAL_DMA_Init(&priv->dma_tx_handle); in stm32_sdmmc_dma_init()
247 err = stm32_sdmmc_configure_dma(&priv->dma_rx_handle, &priv->dma_rx); in stm32_sdmmc_dma_init()
249 LOG_ERR("failed to init rx dma"); in stm32_sdmmc_dma_init()
252 __HAL_LINKDMA(&priv->hsd, hdmarx, priv->dma_rx_handle); in stm32_sdmmc_dma_init()
253 HAL_DMA_Init(&priv->dma_rx_handle); in stm32_sdmmc_dma_init()
261 struct sdmmc_dma_stream *dma_tx = &priv->dma_tx; in stm32_sdmmc_dma_deinit()
262 struct sdmmc_dma_stream *dma_rx = &priv->dma_rx; in stm32_sdmmc_dma_deinit()
264 ret = dma_stop(dma_tx->dev, dma_tx->channel); in stm32_sdmmc_dma_deinit()
265 HAL_DMA_DeInit(&priv->dma_tx_handle); in stm32_sdmmc_dma_deinit()
270 ret = dma_stop(dma_rx->dev, dma_rx->channel); in stm32_sdmmc_dma_deinit()
271 HAL_DMA_DeInit(&priv->dma_rx_handle); in stm32_sdmmc_dma_deinit()
273 LOG_ERR("Failed to stop rx DMA transmission"); in stm32_sdmmc_dma_deinit()
283 const struct device *dev = disk->dev; in stm32_sdmmc_access_init()
284 struct stm32_sdmmc_priv *priv = dev->data; in stm32_sdmmc_access_init()
287 if (priv->status == DISK_STATUS_NOMEDIA) { in stm32_sdmmc_access_init()
288 return -ENODEV; in stm32_sdmmc_access_init()
305 err = reset_line_toggle_dt(&priv->reset); in stm32_sdmmc_access_init()
312 err = HAL_MMC_Init(&priv->hsd); in stm32_sdmmc_access_init()
314 err = HAL_SD_Init(&priv->hsd); in stm32_sdmmc_access_init()
317 LOG_ERR("failed to init stm32_sdmmc (ErrorCode 0x%X)", priv->hsd.ErrorCode); in stm32_sdmmc_access_init()
318 return -EIO; in stm32_sdmmc_access_init()
325 priv->status = DISK_STATUS_OK; in stm32_sdmmc_access_init()
342 err = HAL_MMC_DeInit(&priv->hsd); in stm32_sdmmc_access_deinit()
344 err = HAL_SD_DeInit(&priv->hsd); in stm32_sdmmc_access_deinit()
348 LOG_ERR("failed to deinit stm32_sdmmc (ErrorCode 0x%X)", priv->hsd.ErrorCode); in stm32_sdmmc_access_deinit()
352 priv->status = DISK_STATUS_UNINIT; in stm32_sdmmc_access_deinit()
358 const struct device *dev = disk->dev; in stm32_sdmmc_access_status()
359 struct stm32_sdmmc_priv *priv = dev->data; in stm32_sdmmc_access_status()
361 return priv->status; in stm32_sdmmc_access_status()
398 const struct device *dev = disk->dev; in stm32_sdmmc_access_read()
399 struct stm32_sdmmc_priv *priv = dev->data; in stm32_sdmmc_access_read()
402 k_sem_take(&priv->thread_lock, K_FOREVER); in stm32_sdmmc_access_read()
404 err = stm32_sdmmc_read_blocks(&priv->hsd, data_buf, start_sector, num_sector); in stm32_sdmmc_access_read()
407 err = -EIO; in stm32_sdmmc_access_read()
411 k_sem_take(&priv->sync, K_FOREVER); in stm32_sdmmc_access_read()
413 if (priv->status != DISK_STATUS_OK) { in stm32_sdmmc_access_read()
414 LOG_ERR("sd read error %d", priv->status); in stm32_sdmmc_access_read()
415 err = -EIO; in stm32_sdmmc_access_read()
419 while (!stm32_sdmmc_is_card_in_transfer(&priv->hsd)) { in stm32_sdmmc_access_read()
423 k_sem_give(&priv->thread_lock); in stm32_sdmmc_access_read()
454 const struct device *dev = disk->dev; in stm32_sdmmc_access_write()
455 struct stm32_sdmmc_priv *priv = dev->data; in stm32_sdmmc_access_write()
458 k_sem_take(&priv->thread_lock, K_FOREVER); in stm32_sdmmc_access_write()
460 err = stm32_sdmmc_write_blocks(&priv->hsd, (uint8_t *)data_buf, start_sector, num_sector); in stm32_sdmmc_access_write()
463 err = -EIO; in stm32_sdmmc_access_write()
467 k_sem_take(&priv->sync, K_FOREVER); in stm32_sdmmc_access_write()
469 if (priv->status != DISK_STATUS_OK) { in stm32_sdmmc_access_write()
470 LOG_ERR("sd write error %d", priv->status); in stm32_sdmmc_access_write()
471 err = -EIO; in stm32_sdmmc_access_write()
475 while (!stm32_sdmmc_is_card_in_transfer(&priv->hsd)) { in stm32_sdmmc_access_write()
479 k_sem_give(&priv->thread_lock); in stm32_sdmmc_access_write()
495 const struct device *dev = disk->dev; in stm32_sdmmc_access_ioctl()
496 struct stm32_sdmmc_priv *priv = dev->data; in stm32_sdmmc_access_ioctl()
502 err = stm32_sdmmc_get_card_info(&priv->hsd, &info); in stm32_sdmmc_access_ioctl()
504 return -EIO; in stm32_sdmmc_access_ioctl()
509 err = stm32_sdmmc_get_card_info(&priv->hsd, &info); in stm32_sdmmc_access_ioctl()
511 return -EIO; in stm32_sdmmc_access_ioctl()
519 /* we use a blocking API, so nothing to do for sync */ in stm32_sdmmc_access_ioctl()
526 return -EINVAL; in stm32_sdmmc_access_ioctl()
560 if (!priv->cd.port) { in stm32_sdmmc_card_present()
564 err = gpio_pin_get_dt(&priv->cd); in stm32_sdmmc_card_present()
580 priv->status = DISK_STATUS_UNINIT; in stm32_sdmmc_cd_handler()
584 priv->status = DISK_STATUS_NOMEDIA; in stm32_sdmmc_cd_handler()
596 k_work_submit(&priv->work); in stm32_sdmmc_cd_callback()
603 if (!priv->cd.port) { in stm32_sdmmc_card_detect_init()
607 if (!gpio_is_ready_dt(&priv->cd)) { in stm32_sdmmc_card_detect_init()
608 return -ENODEV; in stm32_sdmmc_card_detect_init()
611 gpio_init_callback(&priv->cd_cb, stm32_sdmmc_cd_callback, in stm32_sdmmc_card_detect_init()
612 1 << priv->cd.pin); in stm32_sdmmc_card_detect_init()
614 err = gpio_add_callback(priv->cd.port, &priv->cd_cb); in stm32_sdmmc_card_detect_init()
619 err = gpio_pin_configure_dt(&priv->cd, GPIO_INPUT); in stm32_sdmmc_card_detect_init()
624 err = gpio_pin_interrupt_configure_dt(&priv->cd, GPIO_INT_EDGE_BOTH); in stm32_sdmmc_card_detect_init()
631 gpio_pin_configure_dt(&priv->cd, GPIO_DISCONNECTED); in stm32_sdmmc_card_detect_init()
633 gpio_remove_callback(priv->cd.port, &priv->cd_cb); in stm32_sdmmc_card_detect_init()
639 if (!priv->cd.port) { in stm32_sdmmc_card_detect_uninit()
643 gpio_pin_interrupt_configure_dt(&priv->cd, GPIO_INT_MODE_DISABLED); in stm32_sdmmc_card_detect_uninit()
644 gpio_pin_configure_dt(&priv->cd, GPIO_DISCONNECTED); in stm32_sdmmc_card_detect_uninit()
645 gpio_remove_callback(priv->cd.port, &priv->cd_cb); in stm32_sdmmc_card_detect_uninit()
654 if (!priv->pe.port) { in stm32_sdmmc_pwr_init()
658 if (!gpio_is_ready_dt(&priv->pe)) { in stm32_sdmmc_pwr_init()
659 return -ENODEV; in stm32_sdmmc_pwr_init()
662 err = gpio_pin_configure_dt(&priv->pe, GPIO_OUTPUT_ACTIVE); in stm32_sdmmc_pwr_init()
674 if (!priv->pe.port) { in stm32_sdmmc_pwr_uninit()
678 gpio_pin_configure_dt(&priv->pe, GPIO_DISCONNECTED); in stm32_sdmmc_pwr_uninit()
684 struct stm32_sdmmc_priv *priv = dev->data; in disk_stm32_sdmmc_init()
690 return -ENODEV; in disk_stm32_sdmmc_init()
693 if (!device_is_ready(priv->reset.dev)) { in disk_stm32_sdmmc_init()
695 return -ENODEV; in disk_stm32_sdmmc_init()
699 err = pinctrl_apply_state(priv->pcfg, PINCTRL_STATE_DEFAULT); in disk_stm32_sdmmc_init()
704 priv->irq_config(dev); in disk_stm32_sdmmc_init()
707 k_sem_init(&priv->thread_lock, 1, 1); in disk_stm32_sdmmc_init()
708 k_sem_init(&priv->sync, 0, 1); in disk_stm32_sdmmc_init()
711 k_work_init(&priv->work, stm32_sdmmc_cd_handler); in disk_stm32_sdmmc_init()
725 priv->status = DISK_STATUS_UNINIT; in disk_stm32_sdmmc_init()
727 priv->status = DISK_STATUS_NOMEDIA; in disk_stm32_sdmmc_init()
816 SDMMC_DMA_CHANNEL(rx, RX)