Lines Matching full:this
34 * Clear the bit and poll it cleared. This is usually called with
68 * the next hard reset. This case occurs in the NAND boot mode. When the board
71 * You will see a DMA timeout in this case. The bug has been fixed
74 * To avoid this bug, just add a new parameter `just_enable` for
119 static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v) in __gpmi_enable_clk() argument
126 clk = this->resources.clock[i]; in __gpmi_enable_clk()
142 clk_disable_unprepare(this->resources.clock[i - 1]); in __gpmi_enable_clk()
146 static int gpmi_init(struct gpmi_nand_data *this) in gpmi_init() argument
148 struct resources *r = &this->resources; in gpmi_init()
151 ret = pm_runtime_get_sync(this->dev); in gpmi_init()
153 pm_runtime_put_noidle(this->dev); in gpmi_init()
165 ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this)); in gpmi_init()
191 pm_runtime_mark_last_busy(this->dev); in gpmi_init()
192 pm_runtime_put_autosuspend(this->dev); in gpmi_init()
196 /* This function is very useful. It is called only when the bug occur. */
197 static void gpmi_dump_info(struct gpmi_nand_data *this) in gpmi_dump_info() argument
199 struct resources *r = &this->resources; in gpmi_dump_info()
200 struct bch_geometry *geo = &this->bch_geometry; in gpmi_dump_info()
204 dev_err(this->dev, "Show GPMI registers :\n"); in gpmi_dump_info()
207 dev_err(this->dev, "offset 0x%.3x : 0x%.8x\n", i * 0x10, reg); in gpmi_dump_info()
211 dev_err(this->dev, "Show BCH registers :\n"); in gpmi_dump_info()
214 dev_err(this->dev, "offset 0x%.3x : 0x%.8x\n", i * 0x10, reg); in gpmi_dump_info()
216 dev_err(this->dev, "BCH Geometry :\n" in gpmi_dump_info()
241 static inline bool gpmi_check_ecc(struct gpmi_nand_data *this) in gpmi_check_ecc() argument
243 struct bch_geometry *geo = &this->bch_geometry; in gpmi_check_ecc()
246 if (GPMI_IS_MXS(this)) { in gpmi_check_ecc()
251 return geo->ecc_strength <= this->devdata->bch_max_ecc_strength; in gpmi_check_ecc()
258 * We may have available oob space in this case.
260 static int set_geometry_by_ecc_info(struct gpmi_nand_data *this, in set_geometry_by_ecc_info() argument
264 struct bch_geometry *geo = &this->bch_geometry; in set_geometry_by_ecc_info()
265 struct nand_chip *chip = &this->nand; in set_geometry_by_ecc_info()
277 dev_err(this->dev, in set_geometry_by_ecc_info()
285 if (!gpmi_check_ecc(this)) in set_geometry_by_ecc_info()
290 dev_err(this->dev, in set_geometry_by_ecc_info()
358 if (!this->swap_block_mark) in set_geometry_by_ecc_info()
389 static inline int get_ecc_strength(struct gpmi_nand_data *this) in get_ecc_strength() argument
391 struct bch_geometry *geo = &this->bch_geometry; in get_ecc_strength()
392 struct mtd_info *mtd = nand_to_mtd(&this->nand); in get_ecc_strength()
402 static int legacy_set_geometry(struct gpmi_nand_data *this) in legacy_set_geometry() argument
404 struct bch_geometry *geo = &this->bch_geometry; in legacy_set_geometry()
405 struct mtd_info *mtd = nand_to_mtd(&this->nand); in legacy_set_geometry()
430 geo->ecc_strength = get_ecc_strength(this); in legacy_set_geometry()
431 if (!gpmi_check_ecc(this)) { in legacy_set_geometry()
432 dev_err(this->dev, in legacy_set_geometry()
436 this->devdata->bch_max_ecc_strength); in legacy_set_geometry()
456 if (!this->swap_block_mark) in legacy_set_geometry()
514 static int common_nfc_set_geometry(struct gpmi_nand_data *this) in common_nfc_set_geometry() argument
516 struct nand_chip *chip = &this->nand; in common_nfc_set_geometry()
521 return set_geometry_by_ecc_info(this, chip->ecc.strength, in common_nfc_set_geometry()
524 if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc")) in common_nfc_set_geometry()
525 || legacy_set_geometry(this)) { in common_nfc_set_geometry()
529 return set_geometry_by_ecc_info(this, in common_nfc_set_geometry()
538 static int bch_set_geometry(struct gpmi_nand_data *this) in bch_set_geometry() argument
540 struct resources *r = &this->resources; in bch_set_geometry()
543 ret = common_nfc_set_geometry(this); in bch_set_geometry()
547 ret = pm_runtime_get_sync(this->dev); in bch_set_geometry()
549 pm_runtime_put_autosuspend(this->dev); in bch_set_geometry()
554 * Due to erratum #2847 of the MX23, the BCH cannot be soft reset on this in bch_set_geometry()
558 ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this)); in bch_set_geometry()
567 pm_runtime_mark_last_busy(this->dev); in bch_set_geometry()
568 pm_runtime_put_autosuspend(this->dev); in bch_set_geometry()
647 static void gpmi_nfc_compute_timings(struct gpmi_nand_data *this, in gpmi_nfc_compute_timings() argument
650 struct gpmi_nfc_hardware_timing *hw = &this->hw; in gpmi_nfc_compute_timings()
651 unsigned int dll_threshold_ps = this->devdata->max_chain_delay; in gpmi_nfc_compute_timings()
716 static void gpmi_nfc_apply_timings(struct gpmi_nand_data *this) in gpmi_nfc_apply_timings() argument
718 struct gpmi_nfc_hardware_timing *hw = &this->hw; in gpmi_nfc_apply_timings()
719 struct resources *r = &this->resources; in gpmi_nfc_apply_timings()
747 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_setup_interface() local
756 if (sdr->tRC_min <= 25000 && !GPMI_IS_MX6(this)) in gpmi_setup_interface()
759 /* Stop here if this call was just a check */ in gpmi_setup_interface()
764 gpmi_nfc_compute_timings(this, sdr); in gpmi_setup_interface()
766 this->hw.must_apply_timings = true; in gpmi_setup_interface()
772 static void gpmi_clear_bch(struct gpmi_nand_data *this) in gpmi_clear_bch() argument
774 struct resources *r = &this->resources; in gpmi_clear_bch()
778 static struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) in get_dma_chan() argument
781 return this->dma_chans[0]; in get_dma_chan()
784 /* This will be called after the DMA operation is finished. */
787 struct gpmi_nand_data *this = param; in dma_irq_callback() local
788 struct completion *dma_c = &this->dma_done; in dma_irq_callback()
795 struct gpmi_nand_data *this = cookie; in bch_irq() local
797 gpmi_clear_bch(this); in bch_irq()
798 complete(&this->bch_done); in bch_irq()
802 static int gpmi_raw_len_to_len(struct gpmi_nand_data *this, int raw_len) in gpmi_raw_len_to_len() argument
808 if (this->bch) in gpmi_raw_len_to_len()
809 return ALIGN_DOWN(raw_len, this->bch_geometry.ecc_chunk_size); in gpmi_raw_len_to_len()
815 static bool prepare_data_dma(struct gpmi_nand_data *this, const void *buf, in prepare_data_dma() argument
820 int len = gpmi_raw_len_to_len(this, raw_len); in prepare_data_dma()
825 ret = dma_map_sg(this->dev, sgl, 1, dr); in prepare_data_dma()
834 sg_init_one(sgl, this->data_buffer_dma, len); in prepare_data_dma()
836 if (dr == DMA_TO_DEVICE && buf != this->data_buffer_dma) in prepare_data_dma()
837 memcpy(this->data_buffer_dma, buf, len); in prepare_data_dma()
839 dma_map_sg(this->dev, sgl, 1, dr); in prepare_data_dma()
861 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ooblayout_ecc() local
862 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ooblayout_ecc()
877 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ooblayout_free() local
878 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ooblayout_free()
949 static int acquire_register_block(struct gpmi_nand_data *this, in acquire_register_block() argument
952 struct platform_device *pdev = this->pdev; in acquire_register_block()
953 struct resources *res = &this->resources; in acquire_register_block()
967 dev_err(this->dev, "unknown resource name : %s\n", res_name); in acquire_register_block()
972 static int acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h) in acquire_bch_irq() argument
974 struct platform_device *pdev = this->pdev; in acquire_bch_irq()
981 dev_err(this->dev, "Can't get resource for %s\n", res_name); in acquire_bch_irq()
985 err = devm_request_irq(this->dev, r->start, irq_h, 0, res_name, this); in acquire_bch_irq()
987 dev_err(this->dev, "error requesting BCH IRQ\n"); in acquire_bch_irq()
992 static void release_dma_channels(struct gpmi_nand_data *this) in release_dma_channels() argument
996 if (this->dma_chans[i]) { in release_dma_channels()
997 dma_release_channel(this->dma_chans[i]); in release_dma_channels()
998 this->dma_chans[i] = NULL; in release_dma_channels()
1002 static int acquire_dma_channels(struct gpmi_nand_data *this) in acquire_dma_channels() argument
1004 struct platform_device *pdev = this->pdev; in acquire_dma_channels()
1011 ret = dev_err_probe(this->dev, PTR_ERR(dma_chan), in acquire_dma_channels()
1013 release_dma_channels(this); in acquire_dma_channels()
1015 this->dma_chans[0] = dma_chan; in acquire_dma_channels()
1021 static int gpmi_get_clks(struct gpmi_nand_data *this) in gpmi_get_clks() argument
1023 struct resources *r = &this->resources; in gpmi_get_clks()
1027 for (i = 0; i < this->devdata->clks_count; i++) { in gpmi_get_clks()
1028 clk = devm_clk_get(this->dev, this->devdata->clks[i]); in gpmi_get_clks()
1037 if (GPMI_IS_MX6(this)) in gpmi_get_clks()
1049 dev_dbg(this->dev, "failed in finding the clocks.\n"); in gpmi_get_clks()
1053 static int acquire_resources(struct gpmi_nand_data *this) in acquire_resources() argument
1057 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME); in acquire_resources()
1061 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME); in acquire_resources()
1065 ret = acquire_bch_irq(this, bch_irq); in acquire_resources()
1069 ret = acquire_dma_channels(this); in acquire_resources()
1073 ret = gpmi_get_clks(this); in acquire_resources()
1079 release_dma_channels(this); in acquire_resources()
1084 static void release_resources(struct gpmi_nand_data *this) in release_resources() argument
1086 release_dma_channels(this); in release_resources()
1089 static void gpmi_free_dma_buffer(struct gpmi_nand_data *this) in gpmi_free_dma_buffer() argument
1091 struct device *dev = this->dev; in gpmi_free_dma_buffer()
1092 struct bch_geometry *geo = &this->bch_geometry; in gpmi_free_dma_buffer()
1094 if (this->auxiliary_virt && virt_addr_valid(this->auxiliary_virt)) in gpmi_free_dma_buffer()
1096 this->auxiliary_virt, in gpmi_free_dma_buffer()
1097 this->auxiliary_phys); in gpmi_free_dma_buffer()
1098 kfree(this->data_buffer_dma); in gpmi_free_dma_buffer()
1099 kfree(this->raw_buffer); in gpmi_free_dma_buffer()
1101 this->data_buffer_dma = NULL; in gpmi_free_dma_buffer()
1102 this->raw_buffer = NULL; in gpmi_free_dma_buffer()
1106 static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this) in gpmi_alloc_dma_buffer() argument
1108 struct bch_geometry *geo = &this->bch_geometry; in gpmi_alloc_dma_buffer()
1109 struct device *dev = this->dev; in gpmi_alloc_dma_buffer()
1110 struct mtd_info *mtd = nand_to_mtd(&this->nand); in gpmi_alloc_dma_buffer()
1120 this->data_buffer_dma = kzalloc(mtd->writesize ?: PAGE_SIZE, in gpmi_alloc_dma_buffer()
1122 if (this->data_buffer_dma == NULL) in gpmi_alloc_dma_buffer()
1125 this->auxiliary_virt = dma_alloc_coherent(dev, geo->auxiliary_size, in gpmi_alloc_dma_buffer()
1126 &this->auxiliary_phys, GFP_DMA); in gpmi_alloc_dma_buffer()
1127 if (!this->auxiliary_virt) in gpmi_alloc_dma_buffer()
1130 this->raw_buffer = kzalloc((mtd->writesize ?: PAGE_SIZE) + mtd->oobsize, GFP_KERNEL); in gpmi_alloc_dma_buffer()
1131 if (!this->raw_buffer) in gpmi_alloc_dma_buffer()
1137 gpmi_free_dma_buffer(this); in gpmi_alloc_dma_buffer()
1146 static void block_mark_swapping(struct gpmi_nand_data *this, in block_mark_swapping() argument
1149 struct bch_geometry *nfc_geo = &this->bch_geometry; in block_mark_swapping()
1157 if (!this->swap_block_mark) in block_mark_swapping()
1192 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_count_bitflips() local
1193 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_count_bitflips()
1200 status = this->auxiliary_virt + ALIGN(meta, 4); in gpmi_count_bitflips()
1208 u8 *eccbuf = this->raw_buffer; in gpmi_count_bitflips()
1241 * nothing was written into this subpage the ECC is in gpmi_count_bitflips()
1243 * at this point that we are reading an erased page and in gpmi_count_bitflips()
1245 * ecc_strength bitflips. If this is a page with random in gpmi_count_bitflips()
1246 * data, we exceed this number of bitflips and have a in gpmi_count_bitflips()
1255 this->auxiliary_virt, in gpmi_count_bitflips()
1285 static void gpmi_bch_layout_std(struct gpmi_nand_data *this) in gpmi_bch_layout_std() argument
1287 struct bch_geometry *geo = &this->bch_geometry; in gpmi_bch_layout_std()
1292 this->bch_flashlayout0 = in gpmi_bch_layout_std()
1295 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) | in gpmi_bch_layout_std()
1296 BF_BCH_FLASH0LAYOUT0_GF(gf_len, this) | in gpmi_bch_layout_std()
1297 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this); in gpmi_bch_layout_std()
1299 this->bch_flashlayout1 = in gpmi_bch_layout_std()
1301 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | in gpmi_bch_layout_std()
1302 BF_BCH_FLASH0LAYOUT1_GF(gf_len, this) | in gpmi_bch_layout_std()
1303 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this); in gpmi_bch_layout_std()
1309 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_page() local
1311 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ecc_read_page()
1315 gpmi_bch_layout_std(this); in gpmi_ecc_read_page()
1316 this->bch = true; in gpmi_ecc_read_page()
1327 block_mark_swapping(this, buf, this->auxiliary_virt); in gpmi_ecc_read_page()
1341 chip->oob_poi[0] = ((uint8_t *)this->auxiliary_virt)[0]; in gpmi_ecc_read_page()
1351 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_subpage() local
1352 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ecc_read_subpage()
1369 if (this->swap_block_mark) { in gpmi_ecc_read_subpage()
1372 * If this chunk is in the range of [first, last], in gpmi_ecc_read_subpage()
1379 dev_dbg(this->dev, in gpmi_ecc_read_subpage()
1399 this->bch_flashlayout0 = BF_BCH_FLASH0LAYOUT0_NBLOCKS(n - 1) | in gpmi_ecc_read_subpage()
1401 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) | in gpmi_ecc_read_subpage()
1402 BF_BCH_FLASH0LAYOUT0_GF(geo->gf_len, this) | in gpmi_ecc_read_subpage()
1403 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(geo->ecc_chunk_size, this); in gpmi_ecc_read_subpage()
1405 this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) | in gpmi_ecc_read_subpage()
1406 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | in gpmi_ecc_read_subpage()
1407 BF_BCH_FLASH0LAYOUT1_GF(geo->gf_len, this) | in gpmi_ecc_read_subpage()
1408 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->ecc_chunk_size, this); in gpmi_ecc_read_subpage()
1410 this->bch = true; in gpmi_ecc_read_subpage()
1416 dev_dbg(this->dev, "page:%d(%d:%d)%d, chunk:(%d:%d), BCH PG size:%d\n", in gpmi_ecc_read_subpage()
1428 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_write_page() local
1429 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_write_page()
1432 dev_dbg(this->dev, "ecc write page.\n"); in gpmi_ecc_write_page()
1434 gpmi_bch_layout_std(this); in gpmi_ecc_write_page()
1435 this->bch = true; in gpmi_ecc_write_page()
1437 memcpy(this->auxiliary_virt, chip->oob_poi, nfc_geo->auxiliary_size); in gpmi_ecc_write_page()
1439 if (this->swap_block_mark) { in gpmi_ecc_write_page()
1444 memcpy(this->data_buffer_dma, buf, mtd->writesize); in gpmi_ecc_write_page()
1445 buf = this->data_buffer_dma; in gpmi_ecc_write_page()
1446 block_mark_swapping(this, this->data_buffer_dma, in gpmi_ecc_write_page()
1447 this->auxiliary_virt); in gpmi_ecc_write_page()
1456 * There are several places in this driver where we have to handle the OOB and
1457 * block marks. This is the function where things are the most complicated, so
1458 * this is where we try to explain it all. All the other places refer back to
1475 * are OOB. This gives the caller a way to see the actual, physical bytes
1479 * What we do for this specific read operation depends on two questions:
1518 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_oob() local
1535 if (GPMI_IS_MX23(this)) { in gpmi_ecc_read_oob()
1563 * This function reads a NAND page without involving the ECC engine (no HW
1578 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_page_raw() local
1579 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_read_page_raw()
1582 u8 *tmp_buf = this->raw_buffer; in gpmi_ecc_read_page_raw()
1599 * See the layout description for a detailed explanation on why this in gpmi_ecc_read_page_raw()
1602 if (this->swap_block_mark) in gpmi_ecc_read_page_raw()
1606 * Copy the metadata section into the oob buffer (this section is in gpmi_ecc_read_page_raw()
1648 * This function writes a NAND page without involving the ECC engine (no HW
1663 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_write_page_raw() local
1664 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_write_page_raw()
1667 u8 *tmp_buf = this->raw_buffer; in gpmi_ecc_write_page_raw()
1720 * See the layout description for a detailed explanation on why this in gpmi_ecc_write_page_raw()
1723 if (this->swap_block_mark) in gpmi_ecc_write_page_raw()
1743 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_block_markbad() local
1751 column = !GPMI_IS_MX23(this) ? mtd->writesize : 0; in gpmi_block_markbad()
1754 block_mark = this->data_buffer_dma; in gpmi_block_markbad()
1767 static int nand_boot_set_geometry(struct gpmi_nand_data *this) in nand_boot_set_geometry() argument
1769 struct boot_rom_geometry *geometry = &this->rom_geometry; in nand_boot_set_geometry()
1774 * In principle, we should be reading this from the OTP bits, since in nand_boot_set_geometry()
1784 * In principle, we should be reading this from the OTP bits, since in nand_boot_set_geometry()
1794 static int mx23_check_transcription_stamp(struct gpmi_nand_data *this) in mx23_check_transcription_stamp() argument
1796 struct boot_rom_geometry *rom_geo = &this->rom_geometry; in mx23_check_transcription_stamp()
1797 struct device *dev = this->dev; in mx23_check_transcription_stamp()
1798 struct nand_chip *chip = &this->nand; in mx23_check_transcription_stamp()
1849 static int mx23_write_transcription_stamp(struct gpmi_nand_data *this) in mx23_write_transcription_stamp() argument
1851 struct device *dev = this->dev; in mx23_write_transcription_stamp()
1852 struct boot_rom_geometry *rom_geo = &this->rom_geometry; in mx23_write_transcription_stamp()
1853 struct nand_chip *chip = &this->nand; in mx23_write_transcription_stamp()
1885 /* Erase this block. */ in mx23_write_transcription_stamp()
1915 static int mx23_boot_init(struct gpmi_nand_data *this) in mx23_boot_init() argument
1917 struct device *dev = this->dev; in mx23_boot_init()
1918 struct nand_chip *chip = &this->nand; in mx23_boot_init()
1934 if (mx23_check_transcription_stamp(this)) in mx23_boot_init()
1952 * Compute the chip, page and byte addresses for this block's in mx23_boot_init()
1970 * again, but this time the result will be a mark in the in mx23_boot_init()
1984 mx23_write_transcription_stamp(this); in mx23_boot_init()
1988 static int nand_boot_init(struct gpmi_nand_data *this) in nand_boot_init() argument
1990 nand_boot_set_geometry(this); in nand_boot_init()
1992 /* This is ROM arch-specific initilization before the BBT scanning. */ in nand_boot_init()
1993 if (GPMI_IS_MX23(this)) in nand_boot_init()
1994 return mx23_boot_init(this); in nand_boot_init()
1998 static int gpmi_set_geometry(struct gpmi_nand_data *this) in gpmi_set_geometry() argument
2003 gpmi_free_dma_buffer(this); in gpmi_set_geometry()
2006 ret = bch_set_geometry(this); in gpmi_set_geometry()
2008 dev_err(this->dev, "Error setting BCH geometry : %d\n", ret); in gpmi_set_geometry()
2013 return gpmi_alloc_dma_buffer(this); in gpmi_set_geometry()
2016 static int gpmi_init_last(struct gpmi_nand_data *this) in gpmi_init_last() argument
2018 struct nand_chip *chip = &this->nand; in gpmi_init_last()
2021 struct bch_geometry *bch_geo = &this->bch_geometry; in gpmi_init_last()
2025 ret = gpmi_set_geometry(this); in gpmi_init_last()
2048 if (GPMI_IS_MX6(this) && in gpmi_init_last()
2059 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_nand_attach_chip() local
2065 if (of_property_read_bool(this->dev->of_node, in gpmi_nand_attach_chip()
2067 this->swap_block_mark = false; in gpmi_nand_attach_chip()
2069 dev_dbg(this->dev, "Blockmark swapping %sabled\n", in gpmi_nand_attach_chip()
2070 this->swap_block_mark ? "en" : "dis"); in gpmi_nand_attach_chip()
2072 ret = gpmi_init_last(this); in gpmi_nand_attach_chip()
2081 static struct gpmi_transfer *get_next_transfer(struct gpmi_nand_data *this) in get_next_transfer() argument
2083 struct gpmi_transfer *transfer = &this->transfers[this->ntransfers]; in get_next_transfer()
2085 this->ntransfers++; in get_next_transfer()
2087 if (this->ntransfers == GPMI_MAX_TRANSFERS) in get_next_transfer()
2094 struct gpmi_nand_data *this, u8 cmd, const u8 *addr, int naddr) in gpmi_chain_command() argument
2096 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_command()
2099 int chip = this->nand.cur_cs; in gpmi_chain_command()
2105 | BF_GPMI_CTRL0_CS(chip, this) in gpmi_chain_command()
2106 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_command()
2117 transfer = get_next_transfer(this); in gpmi_chain_command()
2126 dma_map_sg(this->dev, &transfer->sgl, 1, DMA_TO_DEVICE); in gpmi_chain_command()
2136 struct gpmi_nand_data *this) in gpmi_chain_wait_ready() argument
2138 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_wait_ready()
2143 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this) in gpmi_chain_wait_ready()
2144 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_wait_ready()
2154 struct gpmi_nand_data *this, void *buf, int raw_len, bool *direct) in gpmi_chain_data_read() argument
2157 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_data_read()
2161 transfer = get_next_transfer(this); in gpmi_chain_data_read()
2167 *direct = prepare_data_dma(this, buf, raw_len, &transfer->sgl, in gpmi_chain_data_read()
2172 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this) in gpmi_chain_data_read()
2173 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_data_read()
2177 if (this->bch) { in gpmi_chain_data_read()
2184 pio[5] = this->auxiliary_phys; in gpmi_chain_data_read()
2192 if (!this->bch) in gpmi_chain_data_read()
2201 struct gpmi_nand_data *this, const void *buf, int raw_len) in gpmi_chain_data_write() argument
2203 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_data_write()
2208 transfer = get_next_transfer(this); in gpmi_chain_data_write()
2214 prepare_data_dma(this, buf, raw_len, &transfer->sgl, DMA_TO_DEVICE); in gpmi_chain_data_write()
2218 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this) in gpmi_chain_data_write()
2219 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_data_write()
2223 if (this->bch) { in gpmi_chain_data_write()
2230 pio[5] = this->auxiliary_phys; in gpmi_chain_data_write()
2235 (this->bch ? MXS_DMA_CTRL_WAIT4END : 0)); in gpmi_chain_data_write()
2239 if (!this->bch) in gpmi_chain_data_write()
2252 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_nfc_exec_op() local
2265 this->ntransfers = 0; in gpmi_nfc_exec_op()
2267 this->transfers[i].direction = DMA_NONE; in gpmi_nfc_exec_op()
2269 ret = pm_runtime_get_sync(this->dev); in gpmi_nfc_exec_op()
2271 pm_runtime_put_noidle(this->dev); in gpmi_nfc_exec_op()
2276 * This driver currently supports only one NAND chip. Plus, dies share in gpmi_nfc_exec_op()
2281 if (this->hw.must_apply_timings) { in gpmi_nfc_exec_op()
2282 this->hw.must_apply_timings = false; in gpmi_nfc_exec_op()
2283 gpmi_nfc_apply_timings(this); in gpmi_nfc_exec_op()
2286 dev_dbg(this->dev, "%s: %d instructions\n", __func__, op->ninstrs); in gpmi_nfc_exec_op()
2295 desc = gpmi_chain_wait_ready(this); in gpmi_nfc_exec_op()
2301 * When this command has an address cycle chain it in gpmi_nfc_exec_op()
2308 desc = gpmi_chain_command(this, cmd, NULL, 0); in gpmi_nfc_exec_op()
2312 desc = gpmi_chain_command(this, cmd, instr->ctx.addr.addrs, in gpmi_nfc_exec_op()
2320 desc = gpmi_chain_data_write(this, buf_write, buf_len); in gpmi_nfc_exec_op()
2330 desc = gpmi_chain_data_read(this, buf_read, buf_len, in gpmi_nfc_exec_op()
2341 dev_dbg(this->dev, "%s setup done\n", __func__); in gpmi_nfc_exec_op()
2344 dev_err(this->dev, "Multiple data instructions not supported\n"); in gpmi_nfc_exec_op()
2349 if (this->bch) { in gpmi_nfc_exec_op()
2350 writel(this->bch_flashlayout0, in gpmi_nfc_exec_op()
2351 this->resources.bch_regs + HW_BCH_FLASH0LAYOUT0); in gpmi_nfc_exec_op()
2352 writel(this->bch_flashlayout1, in gpmi_nfc_exec_op()
2353 this->resources.bch_regs + HW_BCH_FLASH0LAYOUT1); in gpmi_nfc_exec_op()
2357 desc->callback_param = this; in gpmi_nfc_exec_op()
2358 dma_completion = &this->dma_done; in gpmi_nfc_exec_op()
2363 if (this->bch && buf_read) { in gpmi_nfc_exec_op()
2365 this->resources.bch_regs + HW_BCH_CTRL_SET); in gpmi_nfc_exec_op()
2366 bch_completion = &this->bch_done; in gpmi_nfc_exec_op()
2371 dma_async_issue_pending(get_dma_chan(this)); in gpmi_nfc_exec_op()
2375 dev_err(this->dev, "DMA timeout, last DMA\n"); in gpmi_nfc_exec_op()
2376 gpmi_dump_info(this); in gpmi_nfc_exec_op()
2381 if (this->bch && buf_read) { in gpmi_nfc_exec_op()
2384 dev_err(this->dev, "BCH timeout, last DMA\n"); in gpmi_nfc_exec_op()
2385 gpmi_dump_info(this); in gpmi_nfc_exec_op()
2392 this->resources.bch_regs + HW_BCH_CTRL_CLR); in gpmi_nfc_exec_op()
2393 gpmi_clear_bch(this); in gpmi_nfc_exec_op()
2398 for (i = 0; i < this->ntransfers; i++) { in gpmi_nfc_exec_op()
2399 struct gpmi_transfer *transfer = &this->transfers[i]; in gpmi_nfc_exec_op()
2402 dma_unmap_sg(this->dev, &transfer->sgl, 1, in gpmi_nfc_exec_op()
2407 memcpy(buf_read, this->data_buffer_dma, in gpmi_nfc_exec_op()
2408 gpmi_raw_len_to_len(this, buf_len)); in gpmi_nfc_exec_op()
2410 this->bch = false; in gpmi_nfc_exec_op()
2412 pm_runtime_mark_last_busy(this->dev); in gpmi_nfc_exec_op()
2413 pm_runtime_put_autosuspend(this->dev); in gpmi_nfc_exec_op()
2424 static int gpmi_nand_init(struct gpmi_nand_data *this) in gpmi_nand_init() argument
2426 struct nand_chip *chip = &this->nand; in gpmi_nand_init()
2432 mtd->dev.parent = this->dev; in gpmi_nand_init()
2435 nand_set_controller_data(chip, this); in gpmi_nand_init()
2436 nand_set_flash_node(chip, this->pdev->dev.of_node); in gpmi_nand_init()
2442 this->swap_block_mark = !GPMI_IS_MX23(this); in gpmi_nand_init()
2448 this->bch_geometry.payload_size = 1024; in gpmi_nand_init()
2449 this->bch_geometry.auxiliary_size = 128; in gpmi_nand_init()
2450 ret = gpmi_alloc_dma_buffer(this); in gpmi_nand_init()
2454 nand_controller_init(&this->base); in gpmi_nand_init()
2455 this->base.ops = &gpmi_nand_controller_ops; in gpmi_nand_init()
2456 chip->controller = &this->base; in gpmi_nand_init()
2458 ret = nand_scan(chip, GPMI_IS_MX6(this) ? 2 : 1); in gpmi_nand_init()
2462 ret = nand_boot_init(this); in gpmi_nand_init()
2477 gpmi_free_dma_buffer(this); in gpmi_nand_init()
2493 struct gpmi_nand_data *this; in gpmi_nand_probe() local
2496 this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL); in gpmi_nand_probe()
2497 if (!this) in gpmi_nand_probe()
2500 this->devdata = of_device_get_match_data(&pdev->dev); in gpmi_nand_probe()
2501 platform_set_drvdata(pdev, this); in gpmi_nand_probe()
2502 this->pdev = pdev; in gpmi_nand_probe()
2503 this->dev = &pdev->dev; in gpmi_nand_probe()
2505 ret = acquire_resources(this); in gpmi_nand_probe()
2509 ret = __gpmi_enable_clk(this, true); in gpmi_nand_probe()
2519 ret = gpmi_init(this); in gpmi_nand_probe()
2523 ret = gpmi_nand_init(this); in gpmi_nand_probe()
2530 dev_info(this->dev, "driver registered.\n"); in gpmi_nand_probe()
2537 release_resources(this); in gpmi_nand_probe()
2545 struct gpmi_nand_data *this = platform_get_drvdata(pdev); in gpmi_nand_remove() local
2546 struct nand_chip *chip = &this->nand; in gpmi_nand_remove()
2555 gpmi_free_dma_buffer(this); in gpmi_nand_remove()
2556 release_resources(this); in gpmi_nand_remove()
2563 struct gpmi_nand_data *this = dev_get_drvdata(dev); in gpmi_pm_suspend() local
2565 release_dma_channels(this); in gpmi_pm_suspend()
2571 struct gpmi_nand_data *this = dev_get_drvdata(dev); in gpmi_pm_resume() local
2574 ret = acquire_dma_channels(this); in gpmi_pm_resume()
2579 ret = gpmi_init(this); in gpmi_pm_resume()
2581 dev_err(this->dev, "Error setting GPMI : %d\n", ret); in gpmi_pm_resume()
2586 if (this->hw.clk_rate) in gpmi_pm_resume()
2587 this->hw.must_apply_timings = true; in gpmi_pm_resume()
2590 ret = bch_set_geometry(this); in gpmi_pm_resume()
2592 dev_err(this->dev, "Error setting BCH : %d\n", ret); in gpmi_pm_resume()
2602 struct gpmi_nand_data *this = dev_get_drvdata(dev); in gpmi_runtime_suspend() local
2604 return __gpmi_enable_clk(this, false); in gpmi_runtime_suspend()
2609 struct gpmi_nand_data *this = dev_get_drvdata(dev); in gpmi_runtime_resume() local
2611 return __gpmi_enable_clk(this, true); in gpmi_runtime_resume()