Lines Matching refs:op

150 static void mtk_nor_set_addr(struct mtk_nor *sp, const struct spi_mem_op *op)  in mtk_nor_set_addr()  argument
152 u32 addr = op->addr.val; in mtk_nor_set_addr()
159 if (op->addr.nbytes == 4) { in mtk_nor_set_addr()
167 static bool need_bounce(struct mtk_nor *sp, const struct spi_mem_op *op) in need_bounce() argument
169 return ((uintptr_t)op->data.buf.in & MTK_NOR_DMA_ALIGN_MASK); in need_bounce()
172 static bool mtk_nor_match_read(const struct spi_mem_op *op) in mtk_nor_match_read() argument
176 if (op->dummy.nbytes) in mtk_nor_match_read()
177 dummy = op->dummy.nbytes * BITS_PER_BYTE / op->dummy.buswidth; in mtk_nor_match_read()
179 if ((op->data.buswidth == 2) || (op->data.buswidth == 4)) { in mtk_nor_match_read()
180 if (op->addr.buswidth == 1) in mtk_nor_match_read()
182 else if (op->addr.buswidth == 2) in mtk_nor_match_read()
184 else if (op->addr.buswidth == 4) in mtk_nor_match_read()
186 } else if ((op->addr.buswidth == 1) && (op->data.buswidth == 1)) { in mtk_nor_match_read()
187 if (op->cmd.opcode == 0x03) in mtk_nor_match_read()
189 else if (op->cmd.opcode == 0x0b) in mtk_nor_match_read()
195 static bool mtk_nor_match_prg(const struct spi_mem_op *op) in mtk_nor_match_prg() argument
200 if ((op->cmd.buswidth > 1) || (op->addr.buswidth > 1) || in mtk_nor_match_prg()
201 (op->dummy.buswidth > 1) || (op->data.buswidth > 1)) in mtk_nor_match_prg()
204 tx_len = op->cmd.nbytes + op->addr.nbytes; in mtk_nor_match_prg()
206 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_match_prg()
208 tx_len += op->dummy.nbytes; in mtk_nor_match_prg()
216 if ((!op->addr.nbytes) && in mtk_nor_match_prg()
217 (tx_len + op->data.nbytes > MTK_NOR_REG_PRGDATA_MAX + 1)) in mtk_nor_match_prg()
219 } else if (op->data.dir == SPI_MEM_DATA_IN) { in mtk_nor_match_prg()
223 rx_len = op->data.nbytes; in mtk_nor_match_prg()
224 prg_left = MTK_NOR_PRG_CNT_MAX / 8 - tx_len - op->dummy.nbytes; in mtk_nor_match_prg()
228 if (!op->addr.nbytes) in mtk_nor_match_prg()
233 prg_len = tx_len + op->dummy.nbytes + rx_len; in mtk_nor_match_prg()
237 prg_len = tx_len + op->dummy.nbytes; in mtk_nor_match_prg()
244 static void mtk_nor_adj_prg_size(struct spi_mem_op *op) in mtk_nor_adj_prg_size() argument
248 tx_len = op->cmd.nbytes + op->addr.nbytes; in mtk_nor_adj_prg_size()
249 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_adj_prg_size()
250 tx_len += op->dummy.nbytes; in mtk_nor_adj_prg_size()
252 if (op->data.nbytes > tx_left) in mtk_nor_adj_prg_size()
253 op->data.nbytes = tx_left; in mtk_nor_adj_prg_size()
254 } else if (op->data.dir == SPI_MEM_DATA_IN) { in mtk_nor_adj_prg_size()
255 prg_left = MTK_NOR_PRG_CNT_MAX / 8 - tx_len - op->dummy.nbytes; in mtk_nor_adj_prg_size()
258 if (op->data.nbytes > prg_left) in mtk_nor_adj_prg_size()
259 op->data.nbytes = prg_left; in mtk_nor_adj_prg_size()
263 static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) in mtk_nor_adjust_op_size() argument
267 if (!op->data.nbytes) in mtk_nor_adjust_op_size()
270 if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) { in mtk_nor_adjust_op_size()
271 if ((op->data.dir == SPI_MEM_DATA_IN) && in mtk_nor_adjust_op_size()
272 mtk_nor_match_read(op)) { in mtk_nor_adjust_op_size()
274 if (op->data.nbytes > 0x400000) in mtk_nor_adjust_op_size()
275 op->data.nbytes = 0x400000; in mtk_nor_adjust_op_size()
277 if ((op->addr.val & MTK_NOR_DMA_ALIGN_MASK) || in mtk_nor_adjust_op_size()
278 (op->data.nbytes < MTK_NOR_DMA_ALIGN)) in mtk_nor_adjust_op_size()
279 op->data.nbytes = 1; in mtk_nor_adjust_op_size()
280 else if (!need_bounce(sp, op)) in mtk_nor_adjust_op_size()
281 op->data.nbytes &= ~MTK_NOR_DMA_ALIGN_MASK; in mtk_nor_adjust_op_size()
282 else if (op->data.nbytes > MTK_NOR_BOUNCE_BUF_SIZE) in mtk_nor_adjust_op_size()
283 op->data.nbytes = MTK_NOR_BOUNCE_BUF_SIZE; in mtk_nor_adjust_op_size()
285 } else if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_adjust_op_size()
286 if (op->data.nbytes >= MTK_NOR_PP_SIZE) in mtk_nor_adjust_op_size()
287 op->data.nbytes = MTK_NOR_PP_SIZE; in mtk_nor_adjust_op_size()
289 op->data.nbytes = 1; in mtk_nor_adjust_op_size()
294 mtk_nor_adj_prg_size(op); in mtk_nor_adjust_op_size()
299 const struct spi_mem_op *op) in mtk_nor_supports_op() argument
301 if (!spi_mem_default_supports_op(mem, op)) in mtk_nor_supports_op()
304 if (op->cmd.buswidth != 1) in mtk_nor_supports_op()
307 if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) { in mtk_nor_supports_op()
308 switch (op->data.dir) { in mtk_nor_supports_op()
310 if (mtk_nor_match_read(op)) in mtk_nor_supports_op()
314 if ((op->addr.buswidth == 1) && in mtk_nor_supports_op()
315 (op->dummy.nbytes == 0) && in mtk_nor_supports_op()
316 (op->data.buswidth == 1)) in mtk_nor_supports_op()
324 return mtk_nor_match_prg(op); in mtk_nor_supports_op()
327 static void mtk_nor_setup_bus(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_setup_bus() argument
331 if (op->addr.nbytes == 4) in mtk_nor_setup_bus()
334 if (op->data.buswidth == 4) { in mtk_nor_setup_bus()
336 writeb(op->cmd.opcode, sp->base + MTK_NOR_REG_PRGDATA(4)); in mtk_nor_setup_bus()
337 if (op->addr.buswidth == 4) in mtk_nor_setup_bus()
339 } else if (op->data.buswidth == 2) { in mtk_nor_setup_bus()
341 writeb(op->cmd.opcode, sp->base + MTK_NOR_REG_PRGDATA(3)); in mtk_nor_setup_bus()
342 if (op->addr.buswidth == 2) in mtk_nor_setup_bus()
345 if (op->cmd.opcode == 0x0b) in mtk_nor_setup_bus()
396 static int mtk_nor_read_bounce(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_read_bounce() argument
401 if (op->data.nbytes & MTK_NOR_DMA_ALIGN_MASK) in mtk_nor_read_bounce()
402 rdlen = (op->data.nbytes + MTK_NOR_DMA_ALIGN) & ~MTK_NOR_DMA_ALIGN_MASK; in mtk_nor_read_bounce()
404 rdlen = op->data.nbytes; in mtk_nor_read_bounce()
406 ret = mtk_nor_dma_exec(sp, op->addr.val, rdlen, sp->buffer_dma); in mtk_nor_read_bounce()
409 memcpy(op->data.buf.in, sp->buffer, op->data.nbytes); in mtk_nor_read_bounce()
414 static int mtk_nor_read_dma(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_read_dma() argument
419 if (need_bounce(sp, op)) in mtk_nor_read_dma()
420 return mtk_nor_read_bounce(sp, op); in mtk_nor_read_dma()
422 dma_addr = dma_map_single(sp->dev, op->data.buf.in, in mtk_nor_read_dma()
423 op->data.nbytes, DMA_FROM_DEVICE); in mtk_nor_read_dma()
428 ret = mtk_nor_dma_exec(sp, op->addr.val, op->data.nbytes, dma_addr); in mtk_nor_read_dma()
430 dma_unmap_single(sp->dev, dma_addr, op->data.nbytes, DMA_FROM_DEVICE); in mtk_nor_read_dma()
435 static int mtk_nor_read_pio(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_read_pio() argument
437 u8 *buf = op->data.buf.in; in mtk_nor_read_pio()
479 static int mtk_nor_pp_buffered(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_pp_buffered() argument
481 const u8 *buf = op->data.buf.out; in mtk_nor_pp_buffered()
489 for (i = 0; i < op->data.nbytes; i += 4) { in mtk_nor_pp_buffered()
495 (op->data.nbytes + 5) * BITS_PER_BYTE); in mtk_nor_pp_buffered()
499 const struct spi_mem_op *op) in mtk_nor_pp_unbuffered() argument
501 const u8 *buf = op->data.buf.out; in mtk_nor_pp_unbuffered()
511 static int mtk_nor_spi_mem_prg(struct mtk_nor *sp, const struct spi_mem_op *op) in mtk_nor_spi_mem_prg() argument
520 tx_len = op->cmd.nbytes + op->addr.nbytes; in mtk_nor_spi_mem_prg()
523 if (op->data.dir == SPI_MEM_DATA_OUT) in mtk_nor_spi_mem_prg()
524 tx_len += op->dummy.nbytes + op->data.nbytes; in mtk_nor_spi_mem_prg()
525 else if (op->data.dir == SPI_MEM_DATA_IN) in mtk_nor_spi_mem_prg()
526 rx_len = op->data.nbytes; in mtk_nor_spi_mem_prg()
528 prg_len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes + in mtk_nor_spi_mem_prg()
529 op->data.nbytes; in mtk_nor_spi_mem_prg()
540 for (i = op->cmd.nbytes; i > 0; i--, reg_offset--) { in mtk_nor_spi_mem_prg()
542 bufbyte = (op->cmd.opcode >> ((i - 1) * BITS_PER_BYTE)) & 0xff; in mtk_nor_spi_mem_prg()
546 for (i = op->addr.nbytes; i > 0; i--, reg_offset--) { in mtk_nor_spi_mem_prg()
548 bufbyte = (op->addr.val >> ((i - 1) * BITS_PER_BYTE)) & 0xff; in mtk_nor_spi_mem_prg()
552 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_spi_mem_prg()
553 for (i = 0; i < op->dummy.nbytes; i++, reg_offset--) { in mtk_nor_spi_mem_prg()
558 for (i = 0; i < op->data.nbytes; i++, reg_offset--) { in mtk_nor_spi_mem_prg()
560 writeb(((const u8 *)(op->data.buf.out))[i], reg); in mtk_nor_spi_mem_prg()
583 if (op->data.dir == SPI_MEM_DATA_IN) { in mtk_nor_spi_mem_prg()
584 for (i = op->data.nbytes - 1; i >= 0; i--, reg_offset++) { in mtk_nor_spi_mem_prg()
586 ((u8 *)(op->data.buf.in))[i] = readb(reg); in mtk_nor_spi_mem_prg()
593 static int mtk_nor_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) in mtk_nor_exec_op() argument
598 if ((op->data.nbytes == 0) || in mtk_nor_exec_op()
599 ((op->addr.nbytes != 3) && (op->addr.nbytes != 4))) in mtk_nor_exec_op()
600 return mtk_nor_spi_mem_prg(sp, op); in mtk_nor_exec_op()
602 if (op->data.dir == SPI_MEM_DATA_OUT) { in mtk_nor_exec_op()
603 mtk_nor_set_addr(sp, op); in mtk_nor_exec_op()
604 writeb(op->cmd.opcode, sp->base + MTK_NOR_REG_PRGDATA0); in mtk_nor_exec_op()
605 if (op->data.nbytes == MTK_NOR_PP_SIZE) in mtk_nor_exec_op()
606 return mtk_nor_pp_buffered(sp, op); in mtk_nor_exec_op()
607 return mtk_nor_pp_unbuffered(sp, op); in mtk_nor_exec_op()
610 if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op)) { in mtk_nor_exec_op()
614 mtk_nor_setup_bus(sp, op); in mtk_nor_exec_op()
615 if (op->data.nbytes == 1) { in mtk_nor_exec_op()
616 mtk_nor_set_addr(sp, op); in mtk_nor_exec_op()
617 return mtk_nor_read_pio(sp, op); in mtk_nor_exec_op()
619 return mtk_nor_read_dma(sp, op); in mtk_nor_exec_op()
623 return mtk_nor_spi_mem_prg(sp, op); in mtk_nor_exec_op()