Loading drivers/soc/qcom/bgcom_spi.c +28 −4 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ #define HED_EVENT_ID_LEN (0x02) #define HED_EVENT_SIZE_LEN (0x02) #define HED_EVENT_DATA_STRT_LEN (0x05) #define CMA_BFFR_POOL_SIZE (128*1024) #define MAX_RETRY 500 Loading Loading @@ -116,6 +117,9 @@ static struct mutex bg_resume_mutex; static atomic_t bg_is_spi_active; static int bg_irq; static uint8_t *fxd_mem_buffer; static struct mutex cma_buffer_lock; static struct spi_device *get_spi_device(void) { struct bg_spi_priv *bg_spi = container_of(bg_com_drv, Loading Loading @@ -528,6 +532,7 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, uint8_t *tx_buf; uint32_t size; int ret; bool is_cma_used = false; uint8_t cmnd = 0; uint32_t ahb_addr = 0; struct spi_device *spi = get_spi_device(); Loading @@ -551,11 +556,22 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, return -EBUSY; } mutex_lock(&cma_buffer_lock); size = num_words*BG_SPI_WORD_SIZE; txn_len = BG_SPI_AHB_CMD_LEN + size; tx_buf = dma_zalloc_coherent(&spi->dev, txn_len, &dma_hndl, GFP_KERNEL); if (!tx_buf) if (fxd_mem_buffer != NULL && txn_len <= CMA_BFFR_POOL_SIZE) { memset(fxd_mem_buffer, 0, txn_len); tx_buf = fxd_mem_buffer; is_cma_used = true; } else tx_buf = dma_zalloc_coherent(&spi->dev, txn_len, &dma_hndl, GFP_KERNEL); if (!tx_buf) { mutex_unlock(&cma_buffer_lock); return -ENOMEM; } cmnd |= BG_SPI_AHB_WRITE_CMD; ahb_addr |= ahb_start_addr; Loading @@ -565,7 +581,9 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, memcpy(tx_buf+BG_SPI_AHB_CMD_LEN, write_buf, size); ret = bgcom_transfer(handle, tx_buf, NULL, txn_len); if (!is_cma_used) dma_free_coherent(&spi->dev, txn_len, tx_buf, dma_hndl); mutex_unlock(&cma_buffer_lock); return ret; } EXPORT_SYMBOL(bgcom_ahb_write); Loading Loading @@ -942,6 +960,10 @@ static void bg_spi_init(struct bg_spi_priv *bg_spi) bg_com_drv = &bg_spi->lhandle; mutex_init(&bg_resume_mutex); fxd_mem_buffer = kmalloc(CMA_BFFR_POOL_SIZE, GFP_KERNEL | GFP_ATOMIC); mutex_init(&cma_buffer_lock); } static int bg_spi_probe(struct spi_device *spi) Loading Loading @@ -1005,7 +1027,9 @@ static int bg_spi_remove(struct spi_device *spi) mutex_destroy(&bg_spi->xfer_mutex); devm_kfree(&spi->dev, bg_spi); spi_set_drvdata(spi, NULL); if (fxd_mem_buffer != NULL) kfree(fxd_mem_buffer); mutex_destroy(&cma_buffer_lock); return 0; } Loading Loading
drivers/soc/qcom/bgcom_spi.c +28 −4 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ #define HED_EVENT_ID_LEN (0x02) #define HED_EVENT_SIZE_LEN (0x02) #define HED_EVENT_DATA_STRT_LEN (0x05) #define CMA_BFFR_POOL_SIZE (128*1024) #define MAX_RETRY 500 Loading Loading @@ -116,6 +117,9 @@ static struct mutex bg_resume_mutex; static atomic_t bg_is_spi_active; static int bg_irq; static uint8_t *fxd_mem_buffer; static struct mutex cma_buffer_lock; static struct spi_device *get_spi_device(void) { struct bg_spi_priv *bg_spi = container_of(bg_com_drv, Loading Loading @@ -528,6 +532,7 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, uint8_t *tx_buf; uint32_t size; int ret; bool is_cma_used = false; uint8_t cmnd = 0; uint32_t ahb_addr = 0; struct spi_device *spi = get_spi_device(); Loading @@ -551,11 +556,22 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, return -EBUSY; } mutex_lock(&cma_buffer_lock); size = num_words*BG_SPI_WORD_SIZE; txn_len = BG_SPI_AHB_CMD_LEN + size; tx_buf = dma_zalloc_coherent(&spi->dev, txn_len, &dma_hndl, GFP_KERNEL); if (!tx_buf) if (fxd_mem_buffer != NULL && txn_len <= CMA_BFFR_POOL_SIZE) { memset(fxd_mem_buffer, 0, txn_len); tx_buf = fxd_mem_buffer; is_cma_used = true; } else tx_buf = dma_zalloc_coherent(&spi->dev, txn_len, &dma_hndl, GFP_KERNEL); if (!tx_buf) { mutex_unlock(&cma_buffer_lock); return -ENOMEM; } cmnd |= BG_SPI_AHB_WRITE_CMD; ahb_addr |= ahb_start_addr; Loading @@ -565,7 +581,9 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr, memcpy(tx_buf+BG_SPI_AHB_CMD_LEN, write_buf, size); ret = bgcom_transfer(handle, tx_buf, NULL, txn_len); if (!is_cma_used) dma_free_coherent(&spi->dev, txn_len, tx_buf, dma_hndl); mutex_unlock(&cma_buffer_lock); return ret; } EXPORT_SYMBOL(bgcom_ahb_write); Loading Loading @@ -942,6 +960,10 @@ static void bg_spi_init(struct bg_spi_priv *bg_spi) bg_com_drv = &bg_spi->lhandle; mutex_init(&bg_resume_mutex); fxd_mem_buffer = kmalloc(CMA_BFFR_POOL_SIZE, GFP_KERNEL | GFP_ATOMIC); mutex_init(&cma_buffer_lock); } static int bg_spi_probe(struct spi_device *spi) Loading Loading @@ -1005,7 +1027,9 @@ static int bg_spi_remove(struct spi_device *spi) mutex_destroy(&bg_spi->xfer_mutex); devm_kfree(&spi->dev, bg_spi); spi_set_drvdata(spi, NULL); if (fxd_mem_buffer != NULL) kfree(fxd_mem_buffer); mutex_destroy(&cma_buffer_lock); return 0; } Loading