developer | e451caf | 2021-05-11 21:57:51 +0800 | [diff] [blame^] | 1 | --- a/drivers/spi/spi-mt65xx.c |
| 2 | +++ b/drivers/spi/spi-mt65xx.c |
| 3 | @@ -184,7 +184,7 @@ static const struct mtk_spi_compatible m |
| 4 | */ |
| 5 | static const struct mtk_chip_config mtk_default_chip_info = { |
| 6 | .sample_sel = 0, |
| 7 | - .get_tick_dly = 0, |
| 8 | + .get_tick_dly = 1, |
| 9 | }; |
| 10 | |
| 11 | static const struct of_device_id mtk_spi_of_match[] = { |
| 12 | @@ -730,8 +730,11 @@ static int mtk_spi_mem_adjust_op_size(st |
| 13 | |
| 14 | if (op->data.dir != SPI_MEM_NO_DATA) { |
| 15 | opcode_len = 1 + op->addr.nbytes + op->dummy.nbytes; |
| 16 | - if (opcode_len + op->data.nbytes > MTK_SPI_IPM_PACKET_SIZE) |
| 17 | + if (opcode_len + op->data.nbytes > MTK_SPI_IPM_PACKET_SIZE) { |
| 18 | op->data.nbytes = MTK_SPI_IPM_PACKET_SIZE -opcode_len; |
| 19 | + /* force data buffer dma-aligned. */ |
| 20 | + op->data.nbytes -= op->data.nbytes % 4; |
| 21 | + } |
| 22 | } |
| 23 | |
| 24 | return 0; |
| 25 | @@ -758,10 +761,6 @@ static bool mtk_spi_mem_supports_op(stru |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | - if (op->data.dir == SPI_MEM_DATA_IN && |
| 30 | - !IS_ALIGNED((size_t)op->data.buf.in, 4)) |
| 31 | - return false; |
| 32 | - |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | @@ -820,6 +819,7 @@ static int mtk_spi_mem_exec_op(struct sp |
| 37 | struct mtk_spi *mdata = spi_master_get_devdata(mem->spi->master); |
| 38 | u32 reg_val, nio = 1, tx_size; |
| 39 | char *tx_tmp_buf; |
| 40 | + char *rx_tmp_buf; |
| 41 | int ret = 0; |
| 42 | |
| 43 | mdata->use_spimem = true; |
| 44 | @@ -914,10 +914,18 @@ static int mtk_spi_mem_exec_op(struct sp |
| 45 | } |
| 46 | |
| 47 | if (op->data.dir == SPI_MEM_DATA_IN) { |
| 48 | + if(!IS_ALIGNED((size_t)op->data.buf.in, 4)) { |
| 49 | + rx_tmp_buf = kzalloc(op->data.nbytes, GFP_KERNEL | GFP_DMA); |
| 50 | + if (!rx_tmp_buf) |
| 51 | + return -ENOMEM; |
| 52 | + } |
| 53 | + else |
| 54 | + rx_tmp_buf = op->data.buf.in; |
| 55 | + |
| 56 | mdata->rx_dma = dma_map_single(mdata->dev, |
| 57 | - op->data.buf.in, |
| 58 | - op->data.nbytes, |
| 59 | - DMA_FROM_DEVICE); |
| 60 | + rx_tmp_buf, |
| 61 | + op->data.nbytes, |
| 62 | + DMA_FROM_DEVICE); |
| 63 | if (dma_mapping_error(mdata->dev, mdata->rx_dma)) { |
| 64 | ret = -ENOMEM; |
| 65 | goto unmap_tx_dma; |
| 66 | @@ -947,9 +955,14 @@ static int mtk_spi_mem_exec_op(struct sp |
| 67 | writel(reg_val, mdata->base + SPI_CMD_REG); |
| 68 | |
| 69 | unmap_rx_dma: |
| 70 | - if (op->data.dir == SPI_MEM_DATA_IN) |
| 71 | + if (op->data.dir == SPI_MEM_DATA_IN) { |
| 72 | + if(!IS_ALIGNED((size_t)op->data.buf.in, 4)) { |
| 73 | + memcpy(op->data.buf.in, rx_tmp_buf, op->data.nbytes); |
| 74 | + kfree(rx_tmp_buf); |
| 75 | + } |
| 76 | dma_unmap_single(mdata->dev, mdata->rx_dma, |
| 77 | op->data.nbytes, DMA_FROM_DEVICE); |
| 78 | + } |
| 79 | unmap_tx_dma: |
| 80 | dma_unmap_single(mdata->dev, mdata->tx_dma, |
| 81 | tx_size, DMA_TO_DEVICE); |