Lines Matching full:op

163 static void mtk_nor_set_addr(struct mtk_nor *sp, const struct spi_mem_op *op)  in mtk_nor_set_addr()  argument
165 u32 addr = op->addr.val; in mtk_nor_set_addr()
172 if (op->addr.nbytes == 4) { in mtk_nor_set_addr()
180 static bool need_bounce(struct mtk_nor *sp, const struct spi_mem_op *op) in need_bounce() argument
182 return ((uintptr_t)op->data.buf.in & MTK_NOR_DMA_ALIGN_MASK); in need_bounce()
185 static bool mtk_nor_match_read(const struct spi_mem_op *op) in mtk_nor_match_read() argument
189 if (op->dummy.nbytes) in mtk_nor_match_read()
190 dummy = op->dummy.nbytes * BITS_PER_BYTE / op->dummy.buswidth; in mtk_nor_match_read()
192 if ((op->data.buswidth == 2) || (op->data.buswidth == 4)) { in mtk_nor_match_read()
193 if (op->addr.buswidth == 1) in mtk_nor_match_read()
195 else if (op->addr.buswidth == 2) in mtk_nor_match_read()
197 else if (op->addr.buswidth == 4) in mtk_nor_match_read()
199 } else if ((op->addr.buswidth == 1) && (op->data.buswidth == 1)) { in mtk_nor_match_read()
200 if (op->cmd.opcode == 0x03) in mtk_nor_match_read()
202 else if (op->cmd.opcode == 0x0b) in mtk_nor_match_read()
208 static bool mtk_nor_match_prg(const struct spi_mem_op *op) in mtk_nor_match_prg() argument
213 if ((op->cmd.buswidth > 1) || (op->addr.buswidth > 1) || in mtk_nor_match_prg()
214 (op->dummy.buswidth > 1) || (op->data.buswidth > 1)) in mtk_nor_match_prg()
217 tx_len = op->cmd.nbytes + op->addr.nbytes; in mtk_nor_match_prg()
219 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_match_prg()
221 tx_len += op->dummy.nbytes; in mtk_nor_match_prg()
229 if ((!op->addr.nbytes) && in mtk_nor_match_prg()
230 (tx_len + op->data.nbytes > MTK_NOR_REG_PRGDATA_MAX + 1)) in mtk_nor_match_prg()
232 } else if (op->data.dir == SPI_MEM_DATA_IN) { in mtk_nor_match_prg()
236 rx_len = op->data.nbytes; in mtk_nor_match_prg()
237 prg_left = MTK_NOR_PRG_CNT_MAX / 8 - tx_len - op->dummy.nbytes; in mtk_nor_match_prg()
241 if (!op->addr.nbytes) in mtk_nor_match_prg()
246 prg_len = tx_len + op->dummy.nbytes + rx_len; in mtk_nor_match_prg()
250 prg_len = tx_len + op->dummy.nbytes; in mtk_nor_match_prg()
257 static void mtk_nor_adj_prg_size(struct spi_mem_op *op) in mtk_nor_adj_prg_size() argument
261 tx_len = op->cmd.nbytes + op->addr.nbytes; in mtk_nor_adj_prg_size()
262 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_adj_prg_size()
263 tx_len += op->dummy.nbytes; in mtk_nor_adj_prg_size()
265 if (op->data.nbytes > tx_left) in mtk_nor_adj_prg_size()
266 op->data.nbytes = tx_left; in mtk_nor_adj_prg_size()
267 } else if (op->data.dir == SPI_MEM_DATA_IN) { in mtk_nor_adj_prg_size()
268 prg_left = MTK_NOR_PRG_CNT_MAX / 8 - tx_len - op->dummy.nbytes; in mtk_nor_adj_prg_size()
271 if (op->data.nbytes > prg_left) in mtk_nor_adj_prg_size()
272 op->data.nbytes = prg_left; in mtk_nor_adj_prg_size()
276 static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) in mtk_nor_adjust_op_size() argument
280 if (!op->data.nbytes) in mtk_nor_adjust_op_size()
283 if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) { in mtk_nor_adjust_op_size()
284 if ((op->data.dir == SPI_MEM_DATA_IN) && in mtk_nor_adjust_op_size()
285 mtk_nor_match_read(op)) { in mtk_nor_adjust_op_size()
287 if (op->data.nbytes > 0x400000) in mtk_nor_adjust_op_size()
288 op->data.nbytes = 0x400000; in mtk_nor_adjust_op_size()
290 if ((op->addr.val & MTK_NOR_DMA_ALIGN_MASK) || in mtk_nor_adjust_op_size()
291 (op->data.nbytes < MTK_NOR_DMA_ALIGN)) in mtk_nor_adjust_op_size()
292 op->data.nbytes = 1; in mtk_nor_adjust_op_size()
293 else if (!need_bounce(sp, op)) in mtk_nor_adjust_op_size()
294 op->data.nbytes &= ~MTK_NOR_DMA_ALIGN_MASK; in mtk_nor_adjust_op_size()
295 else if (op->data.nbytes > MTK_NOR_BOUNCE_BUF_SIZE) in mtk_nor_adjust_op_size()
296 op->data.nbytes = MTK_NOR_BOUNCE_BUF_SIZE; in mtk_nor_adjust_op_size()
298 } else if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_adjust_op_size()
299 if (op->data.nbytes >= MTK_NOR_PP_SIZE) in mtk_nor_adjust_op_size()
300 op->data.nbytes = MTK_NOR_PP_SIZE; in mtk_nor_adjust_op_size()
302 op->data.nbytes = 1; in mtk_nor_adjust_op_size()
307 mtk_nor_adj_prg_size(op); in mtk_nor_adjust_op_size()
312 const struct spi_mem_op *op) in mtk_nor_supports_op() argument
314 if (!spi_mem_default_supports_op(mem, op)) in mtk_nor_supports_op()
317 if (op->cmd.buswidth != 1) in mtk_nor_supports_op()
320 if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) { in mtk_nor_supports_op()
321 switch (op->data.dir) { in mtk_nor_supports_op()
323 if (mtk_nor_match_read(op)) in mtk_nor_supports_op()
327 if ((op->addr.buswidth == 1) && in mtk_nor_supports_op()
328 (op->dummy.nbytes == 0) && in mtk_nor_supports_op()
329 (op->data.buswidth == 1)) in mtk_nor_supports_op()
337 return mtk_nor_match_prg(op); in mtk_nor_supports_op()
340 static void mtk_nor_setup_bus(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_setup_bus() argument
344 if (op->addr.nbytes == 4) in mtk_nor_setup_bus()
347 if (op->data.buswidth == 4) { in mtk_nor_setup_bus()
349 writeb(op->cmd.opcode, sp->base + MTK_NOR_REG_PRGDATA(4)); in mtk_nor_setup_bus()
350 if (op->addr.buswidth == 4) in mtk_nor_setup_bus()
352 } else if (op->data.buswidth == 2) { in mtk_nor_setup_bus()
354 writeb(op->cmd.opcode, sp->base + MTK_NOR_REG_PRGDATA(3)); in mtk_nor_setup_bus()
355 if (op->addr.buswidth == 2) in mtk_nor_setup_bus()
358 if (op->cmd.opcode == 0x0b) in mtk_nor_setup_bus()
410 static int mtk_nor_read_bounce(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_read_bounce() argument
415 if (op->data.nbytes & MTK_NOR_DMA_ALIGN_MASK) in mtk_nor_read_bounce()
416 rdlen = (op->data.nbytes + MTK_NOR_DMA_ALIGN) & ~MTK_NOR_DMA_ALIGN_MASK; in mtk_nor_read_bounce()
418 rdlen = op->data.nbytes; in mtk_nor_read_bounce()
420 ret = mtk_nor_dma_exec(sp, op->addr.val, rdlen, sp->buffer_dma); in mtk_nor_read_bounce()
423 memcpy(op->data.buf.in, sp->buffer, op->data.nbytes); in mtk_nor_read_bounce()
428 static int mtk_nor_read_dma(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_read_dma() argument
433 if (need_bounce(sp, op)) in mtk_nor_read_dma()
434 return mtk_nor_read_bounce(sp, op); in mtk_nor_read_dma()
436 dma_addr = dma_map_single(sp->dev, op->data.buf.in, in mtk_nor_read_dma()
437 op->data.nbytes, DMA_FROM_DEVICE); in mtk_nor_read_dma()
442 ret = mtk_nor_dma_exec(sp, op->addr.val, op->data.nbytes, dma_addr); in mtk_nor_read_dma()
444 dma_unmap_single(sp->dev, dma_addr, op->data.nbytes, DMA_FROM_DEVICE); in mtk_nor_read_dma()
449 static int mtk_nor_read_pio(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_read_pio() argument
451 u8 *buf = op->data.buf.in; in mtk_nor_read_pio()
485 static int mtk_nor_pp_buffered(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_pp_buffered() argument
487 const u8 *buf = op->data.buf.out; in mtk_nor_pp_buffered()
495 for (i = 0; i < op->data.nbytes; i += 4) { in mtk_nor_pp_buffered()
501 (op->data.nbytes + 5) * BITS_PER_BYTE); in mtk_nor_pp_buffered()
505 const struct spi_mem_op *op) in mtk_nor_pp_unbuffered() argument
507 const u8 *buf = op->data.buf.out; in mtk_nor_pp_unbuffered()
517 static int mtk_nor_spi_mem_prg(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_spi_mem_prg() argument
526 tx_len = op->cmd.nbytes + op->addr.nbytes; in mtk_nor_spi_mem_prg()
529 if (op->data.dir == SPI_MEM_DATA_OUT) in mtk_nor_spi_mem_prg()
530 tx_len += op->dummy.nbytes + op->data.nbytes; in mtk_nor_spi_mem_prg()
531 else if (op->data.dir == SPI_MEM_DATA_IN) in mtk_nor_spi_mem_prg()
532 rx_len = op->data.nbytes; in mtk_nor_spi_mem_prg()
534 prg_len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes + in mtk_nor_spi_mem_prg()
535 op->data.nbytes; in mtk_nor_spi_mem_prg()
537 // an invalid op may reach here if the caller calls exec_op without in mtk_nor_spi_mem_prg()
539 // spi-mem won't try this op again with generic spi transfers. in mtk_nor_spi_mem_prg()
546 for (i = op->cmd.nbytes; i > 0; i--, reg_offset--) { in mtk_nor_spi_mem_prg()
548 bufbyte = (op->cmd.opcode >> ((i - 1) * BITS_PER_BYTE)) & 0xff; in mtk_nor_spi_mem_prg()
552 for (i = op->addr.nbytes; i > 0; i--, reg_offset--) { in mtk_nor_spi_mem_prg()
554 bufbyte = (op->addr.val >> ((i - 1) * BITS_PER_BYTE)) & 0xff; in mtk_nor_spi_mem_prg()
558 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_spi_mem_prg()
559 for (i = 0; i < op->dummy.nbytes; i++, reg_offset--) { in mtk_nor_spi_mem_prg()
564 for (i = 0; i < op->data.nbytes; i++, reg_offset--) { in mtk_nor_spi_mem_prg()
566 writeb(((const u8 *)(op->data.buf.out))[i], reg); in mtk_nor_spi_mem_prg()
575 // trigger op in mtk_nor_spi_mem_prg()
589 if (op->data.dir == SPI_MEM_DATA_IN) { in mtk_nor_spi_mem_prg()
590 for (i = op->data.nbytes - 1; i >= 0; i--, reg_offset++) { in mtk_nor_spi_mem_prg()
592 ((u8 *)(op->data.buf.in))[i] = readb(reg); in mtk_nor_spi_mem_prg()
599 static int mtk_nor_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) in mtk_nor_exec_op() argument
604 if ((op->data.nbytes == 0) || in mtk_nor_exec_op()
605 ((op->addr.nbytes != 3) && (op->addr.nbytes != 4))) in mtk_nor_exec_op()
606 return mtk_nor_spi_mem_prg(sp, op); in mtk_nor_exec_op()
608 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_exec_op()
609 mtk_nor_set_addr(sp, op); in mtk_nor_exec_op()
610 writeb(op->cmd.opcode, sp->base + MTK_NOR_REG_PRGDATA0); in mtk_nor_exec_op()
611 if (op->data.nbytes == MTK_NOR_PP_SIZE) in mtk_nor_exec_op()
612 return mtk_nor_pp_buffered(sp, op); in mtk_nor_exec_op()
613 return mtk_nor_pp_unbuffered(sp, op); in mtk_nor_exec_op()
616 if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op)) { in mtk_nor_exec_op()
620 mtk_nor_setup_bus(sp, op); in mtk_nor_exec_op()
621 if (op->data.nbytes == 1) { in mtk_nor_exec_op()
622 mtk_nor_set_addr(sp, op); in mtk_nor_exec_op()
623 return mtk_nor_read_pio(sp, op); in mtk_nor_exec_op()
625 ret = mtk_nor_read_dma(sp, op); in mtk_nor_exec_op()
629 mtk_nor_setup_bus(sp, op); in mtk_nor_exec_op()
630 return mtk_nor_read_dma(sp, op); in mtk_nor_exec_op()
637 return mtk_nor_spi_mem_prg(sp, op); in mtk_nor_exec_op()