Lines Matching refs:as_ctrl
223 static int airoha_snand_set_fifo_op(struct airoha_snand_ctrl *as_ctrl, in airoha_snand_set_fifo_op() argument
229 err = regmap_write(as_ctrl->regmap_ctrl, REG_SPI_CTRL_OPFIFO_WDATA, in airoha_snand_set_fifo_op()
235 err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl, in airoha_snand_set_fifo_op()
242 err = regmap_write(as_ctrl->regmap_ctrl, REG_SPI_CTRL_OPFIFO_WR, in airoha_snand_set_fifo_op()
247 return regmap_read_poll_timeout(as_ctrl->regmap_ctrl, in airoha_snand_set_fifo_op()
253 static int airoha_snand_set_cs(struct airoha_snand_ctrl *as_ctrl, u8 cs) in airoha_snand_set_cs() argument
255 return airoha_snand_set_fifo_op(as_ctrl, cs, sizeof(cs)); in airoha_snand_set_cs()
258 static int airoha_snand_write_data_to_fifo(struct airoha_snand_ctrl *as_ctrl, in airoha_snand_write_data_to_fifo() argument
268 err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl, in airoha_snand_write_data_to_fifo()
276 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_write_data_to_fifo()
283 err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl, in airoha_snand_write_data_to_fifo()
294 static int airoha_snand_read_data_from_fifo(struct airoha_snand_ctrl *as_ctrl, in airoha_snand_read_data_from_fifo() argument
304 err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl, in airoha_snand_read_data_from_fifo()
312 err = regmap_read(as_ctrl->regmap_ctrl, in airoha_snand_read_data_from_fifo()
319 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_read_data_from_fifo()
328 static int airoha_snand_set_mode(struct airoha_snand_ctrl *as_ctrl, in airoha_snand_set_mode() argument
337 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
342 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
347 err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
354 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
359 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
366 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
372 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
377 err = regmap_write(as_ctrl->regmap_ctrl, in airoha_snand_set_mode()
387 return regmap_write(as_ctrl->regmap_ctrl, REG_SPI_CTRL_DUMMY, 0); in airoha_snand_set_mode()
390 static int airoha_snand_write_data(struct airoha_snand_ctrl *as_ctrl, u8 cmd, in airoha_snand_write_data() argument
399 err = airoha_snand_set_fifo_op(as_ctrl, cmd, data_len); in airoha_snand_write_data()
403 err = airoha_snand_write_data_to_fifo(as_ctrl, &data[i], in airoha_snand_write_data()
412 static int airoha_snand_read_data(struct airoha_snand_ctrl *as_ctrl, u8 *data, in airoha_snand_read_data() argument
421 err = airoha_snand_set_fifo_op(as_ctrl, 0xc, data_len); in airoha_snand_read_data()
425 err = airoha_snand_read_data_from_fifo(as_ctrl, &data[i], in airoha_snand_read_data()
434 static int airoha_snand_nfi_init(struct airoha_snand_ctrl *as_ctrl) in airoha_snand_nfi_init() argument
439 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_NFI_CNFG, in airoha_snand_nfi_init()
445 return regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR_EN, in airoha_snand_nfi_init()
449 static int airoha_snand_nfi_config(struct airoha_snand_ctrl *as_ctrl) in airoha_snand_nfi_config() argument
454 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, in airoha_snand_nfi_config()
460 err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_nfi_config()
466 err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_nfi_config()
472 err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_nfi_config()
478 switch (as_ctrl->nfi_cfg.spare_size) { in airoha_snand_nfi_config()
493 err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_PAGEFMT, in airoha_snand_nfi_config()
498 switch (as_ctrl->nfi_cfg.page_size) { in airoha_snand_nfi_config()
510 err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_PAGEFMT, in airoha_snand_nfi_config()
516 val = FIELD_PREP(SPI_NFI_SEC_NUM, as_ctrl->nfi_cfg.sec_num); in airoha_snand_nfi_config()
517 err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, in airoha_snand_nfi_config()
523 err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SECCUS_SIZE, in airoha_snand_nfi_config()
529 val = FIELD_PREP(SPI_NFI_CUS_SEC_SIZE, as_ctrl->nfi_cfg.sec_size); in airoha_snand_nfi_config()
530 return regmap_update_bits(as_ctrl->regmap_nfi, in airoha_snand_nfi_config()
573 struct airoha_snand_ctrl *as_ctrl; in airoha_snand_adjust_op_size() local
575 as_ctrl = spi_controller_get_devdata(mem->spi->controller); in airoha_snand_adjust_op_size()
576 max_len = as_ctrl->nfi_cfg.sec_size; in airoha_snand_adjust_op_size()
577 max_len += as_ctrl->nfi_cfg.spare_size; in airoha_snand_adjust_op_size()
578 max_len *= as_ctrl->nfi_cfg.sec_num; in airoha_snand_adjust_op_size()
632 struct airoha_snand_ctrl *as_ctrl; in airoha_snand_dirmap_read() local
650 as_ctrl = spi_controller_get_devdata(spi->controller); in airoha_snand_dirmap_read()
651 err = airoha_snand_set_mode(as_ctrl, SPI_MODE_DMA); in airoha_snand_dirmap_read()
655 err = airoha_snand_nfi_config(as_ctrl); in airoha_snand_dirmap_read()
659 dma_addr = dma_map_single(as_ctrl->dev, txrx_buf, SPI_NAND_CACHE_SIZE, in airoha_snand_dirmap_read()
661 err = dma_mapping_error(as_ctrl->dev, dma_addr); in airoha_snand_dirmap_read()
666 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR, in airoha_snand_dirmap_read()
672 val = as_ctrl->nfi_cfg.sec_size * as_ctrl->nfi_cfg.sec_num; in airoha_snand_dirmap_read()
674 err = regmap_update_bits(as_ctrl->regmap_nfi, in airoha_snand_dirmap_read()
681 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_RD_CTL2, in airoha_snand_dirmap_read()
687 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_MISC_CTL, in airoha_snand_dirmap_read()
693 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_RD_CTL3, 0x0); in airoha_snand_dirmap_read()
698 err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_dirmap_read()
704 err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_dirmap_read()
709 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_CMD, 0x0); in airoha_snand_dirmap_read()
714 err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, in airoha_snand_dirmap_read()
719 err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, in airoha_snand_dirmap_read()
724 err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, in airoha_snand_dirmap_read()
735 err = regmap_write_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_STA_CTL1, in airoha_snand_dirmap_read()
741 err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR, in airoha_snand_dirmap_read()
750 dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE, in airoha_snand_dirmap_read()
752 err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL); in airoha_snand_dirmap_read()
761 dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE, in airoha_snand_dirmap_read()
772 struct airoha_snand_ctrl *as_ctrl; in airoha_snand_dirmap_write() local
777 as_ctrl = spi_controller_get_devdata(spi->controller); in airoha_snand_dirmap_write()
778 err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL); in airoha_snand_dirmap_write()
783 dma_addr = dma_map_single(as_ctrl->dev, txrx_buf, SPI_NAND_CACHE_SIZE, in airoha_snand_dirmap_write()
785 err = dma_mapping_error(as_ctrl->dev, dma_addr); in airoha_snand_dirmap_write()
789 err = airoha_snand_set_mode(as_ctrl, SPI_MODE_DMA); in airoha_snand_dirmap_write()
793 err = airoha_snand_nfi_config(as_ctrl); in airoha_snand_dirmap_write()
803 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR, in airoha_snand_dirmap_write()
809 as_ctrl->nfi_cfg.sec_size * as_ctrl->nfi_cfg.sec_num); in airoha_snand_dirmap_write()
810 err = regmap_update_bits(as_ctrl->regmap_nfi, in airoha_snand_dirmap_write()
816 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_PG_CTL1, in airoha_snand_dirmap_write()
822 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_MISC_CTL, in airoha_snand_dirmap_write()
827 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_PG_CTL2, 0x0); in airoha_snand_dirmap_write()
831 err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_dirmap_write()
836 err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_dirmap_write()
842 err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CNFG, in airoha_snand_dirmap_write()
847 err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_CMD, 0x80); in airoha_snand_dirmap_write()
851 err = regmap_clear_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, in airoha_snand_dirmap_write()
856 err = regmap_set_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, in airoha_snand_dirmap_write()
861 err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR, in airoha_snand_dirmap_write()
867 err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, in airoha_snand_dirmap_write()
878 err = regmap_write_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_STA_CTL1, in airoha_snand_dirmap_write()
884 dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE, in airoha_snand_dirmap_write()
886 err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL); in airoha_snand_dirmap_write()
893 dma_unmap_single(as_ctrl->dev, dma_addr, SPI_NAND_CACHE_SIZE, in airoha_snand_dirmap_write()
902 struct airoha_snand_ctrl *as_ctrl; in airoha_snand_exec_op() local
905 as_ctrl = spi_controller_get_devdata(mem->spi->controller); in airoha_snand_exec_op()
908 err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL); in airoha_snand_exec_op()
912 err = airoha_snand_set_cs(as_ctrl, SPI_CHIP_SEL_LOW); in airoha_snand_exec_op()
917 err = airoha_snand_write_data(as_ctrl, 0x8, &opcode, sizeof(opcode)); in airoha_snand_exec_op()
927 err = airoha_snand_write_data(as_ctrl, cmd, &data[i], in airoha_snand_exec_op()
936 err = airoha_snand_write_data(as_ctrl, 0x8, &data[0], in airoha_snand_exec_op()
944 err = airoha_snand_read_data(as_ctrl, op->data.buf.in, in airoha_snand_exec_op()
949 err = airoha_snand_write_data(as_ctrl, 0x8, op->data.buf.out, in airoha_snand_exec_op()
955 return airoha_snand_set_cs(as_ctrl, SPI_CHIP_SEL_HIGH); in airoha_snand_exec_op()
969 struct airoha_snand_ctrl *as_ctrl; in airoha_snand_setup() local
973 as_ctrl = spi_controller_get_devdata(spi->controller); in airoha_snand_setup()
974 txrx_buf = devm_kzalloc(as_ctrl->dev, SPI_NAND_CACHE_SIZE, in airoha_snand_setup()
984 static int airoha_snand_nfi_setup(struct airoha_snand_ctrl *as_ctrl) in airoha_snand_nfi_setup() argument
989 err = regmap_read(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, &val); in airoha_snand_nfi_setup()
995 err = regmap_read(as_ctrl->regmap_nfi, REG_SPI_NFI_SECCUS_SIZE, &val); in airoha_snand_nfi_setup()
1002 as_ctrl->nfi_cfg.sec_size = sec_size; in airoha_snand_nfi_setup()
1003 as_ctrl->nfi_cfg.sec_num = sec_num; in airoha_snand_nfi_setup()
1004 as_ctrl->nfi_cfg.page_size = round_down(sec_size * sec_num, 1024); in airoha_snand_nfi_setup()
1005 as_ctrl->nfi_cfg.spare_size = 16; in airoha_snand_nfi_setup()
1007 err = airoha_snand_nfi_init(as_ctrl); in airoha_snand_nfi_setup()
1011 return airoha_snand_nfi_config(as_ctrl); in airoha_snand_nfi_setup()
1038 struct airoha_snand_ctrl *as_ctrl; in airoha_snand_probe() local
1044 ctrl = devm_spi_alloc_host(dev, sizeof(*as_ctrl)); in airoha_snand_probe()
1048 as_ctrl = spi_controller_get_devdata(ctrl); in airoha_snand_probe()
1049 as_ctrl->dev = dev; in airoha_snand_probe()
1055 as_ctrl->regmap_ctrl = devm_regmap_init_mmio(dev, base, in airoha_snand_probe()
1057 if (IS_ERR(as_ctrl->regmap_ctrl)) in airoha_snand_probe()
1058 return dev_err_probe(dev, PTR_ERR(as_ctrl->regmap_ctrl), in airoha_snand_probe()
1065 as_ctrl->regmap_nfi = devm_regmap_init_mmio(dev, base, in airoha_snand_probe()
1067 if (IS_ERR(as_ctrl->regmap_nfi)) in airoha_snand_probe()
1068 return dev_err_probe(dev, PTR_ERR(as_ctrl->regmap_nfi), in airoha_snand_probe()
1071 as_ctrl->spi_clk = devm_clk_get_enabled(dev, "spi"); in airoha_snand_probe()
1072 if (IS_ERR(as_ctrl->spi_clk)) in airoha_snand_probe()
1073 return dev_err_probe(dev, PTR_ERR(as_ctrl->spi_clk), in airoha_snand_probe()
1076 err = dma_set_mask(as_ctrl->dev, DMA_BIT_MASK(32)); in airoha_snand_probe()
1087 err = airoha_snand_nfi_setup(as_ctrl); in airoha_snand_probe()