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()
163 ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this)); in gpmi_init()
187 pm_runtime_mark_last_busy(this->dev); in gpmi_init()
188 pm_runtime_put_autosuspend(this->dev); in gpmi_init()
192 /* This function is very useful. It is called only when the bug occur. */
193 static void gpmi_dump_info(struct gpmi_nand_data *this) in gpmi_dump_info() argument
195 struct resources *r = &this->resources; in gpmi_dump_info()
196 struct bch_geometry *geo = &this->bch_geometry; in gpmi_dump_info()
200 dev_err(this->dev, "Show GPMI registers :\n"); in gpmi_dump_info()
203 dev_err(this->dev, "offset 0x%.3x : 0x%.8x\n", i * 0x10, reg); in gpmi_dump_info()
207 dev_err(this->dev, "Show BCH registers :\n"); in gpmi_dump_info()
210 dev_err(this->dev, "offset 0x%.3x : 0x%.8x\n", i * 0x10, reg); in gpmi_dump_info()
212 dev_err(this->dev, "BCH Geometry :\n" in gpmi_dump_info()
237 static inline bool gpmi_check_ecc(struct gpmi_nand_data *this) in gpmi_check_ecc() argument
239 struct bch_geometry *geo = &this->bch_geometry; in gpmi_check_ecc()
242 if (GPMI_IS_MXS(this)) { in gpmi_check_ecc()
247 return geo->ecc_strength <= this->devdata->bch_max_ecc_strength; in gpmi_check_ecc()
254 * We may have available oob space in this case.
256 static int set_geometry_by_ecc_info(struct gpmi_nand_data *this, in set_geometry_by_ecc_info() argument
260 struct bch_geometry *geo = &this->bch_geometry; in set_geometry_by_ecc_info()
261 struct nand_chip *chip = &this->nand; in set_geometry_by_ecc_info()
273 dev_err(this->dev, in set_geometry_by_ecc_info()
281 if (!gpmi_check_ecc(this)) in set_geometry_by_ecc_info()
286 dev_err(this->dev, in set_geometry_by_ecc_info()
354 if (!this->swap_block_mark) in set_geometry_by_ecc_info()
385 static inline int get_ecc_strength(struct gpmi_nand_data *this) in get_ecc_strength() argument
387 struct bch_geometry *geo = &this->bch_geometry; in get_ecc_strength()
388 struct mtd_info *mtd = nand_to_mtd(&this->nand); in get_ecc_strength()
398 static int legacy_set_geometry(struct gpmi_nand_data *this) in legacy_set_geometry() argument
400 struct bch_geometry *geo = &this->bch_geometry; in legacy_set_geometry()
401 struct mtd_info *mtd = nand_to_mtd(&this->nand); in legacy_set_geometry()
426 geo->ecc_strength = get_ecc_strength(this); in legacy_set_geometry()
427 if (!gpmi_check_ecc(this)) { in legacy_set_geometry()
428 dev_err(this->dev, in legacy_set_geometry()
432 this->devdata->bch_max_ecc_strength); in legacy_set_geometry()
452 if (!this->swap_block_mark) in legacy_set_geometry()
510 static int common_nfc_set_geometry(struct gpmi_nand_data *this) in common_nfc_set_geometry() argument
512 struct nand_chip *chip = &this->nand; in common_nfc_set_geometry()
517 return set_geometry_by_ecc_info(this, chip->ecc.strength, in common_nfc_set_geometry()
520 if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc")) in common_nfc_set_geometry()
521 || legacy_set_geometry(this)) { in common_nfc_set_geometry()
525 return set_geometry_by_ecc_info(this, in common_nfc_set_geometry()
534 static int bch_set_geometry(struct gpmi_nand_data *this) in bch_set_geometry() argument
536 struct resources *r = &this->resources; in bch_set_geometry()
539 ret = common_nfc_set_geometry(this); in bch_set_geometry()
543 ret = pm_runtime_get_sync(this->dev); in bch_set_geometry()
545 pm_runtime_put_autosuspend(this->dev); in bch_set_geometry()
550 * Due to erratum #2847 of the MX23, the BCH cannot be soft reset on this in bch_set_geometry()
554 ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this)); in bch_set_geometry()
563 pm_runtime_mark_last_busy(this->dev); in bch_set_geometry()
564 pm_runtime_put_autosuspend(this->dev); in bch_set_geometry()
643 static void gpmi_nfc_compute_timings(struct gpmi_nand_data *this, in gpmi_nfc_compute_timings() argument
646 struct gpmi_nfc_hardware_timing *hw = &this->hw; in gpmi_nfc_compute_timings()
647 unsigned int dll_threshold_ps = this->devdata->max_chain_delay; in gpmi_nfc_compute_timings()
712 static void gpmi_nfc_apply_timings(struct gpmi_nand_data *this) in gpmi_nfc_apply_timings() argument
714 struct gpmi_nfc_hardware_timing *hw = &this->hw; in gpmi_nfc_apply_timings()
715 struct resources *r = &this->resources; in gpmi_nfc_apply_timings()
743 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_setup_interface() local
752 if (sdr->tRC_min <= 25000 && !GPMI_IS_MX6(this)) in gpmi_setup_interface()
755 /* Stop here if this call was just a check */ in gpmi_setup_interface()
760 gpmi_nfc_compute_timings(this, sdr); in gpmi_setup_interface()
762 this->hw.must_apply_timings = true; in gpmi_setup_interface()
768 static void gpmi_clear_bch(struct gpmi_nand_data *this) in gpmi_clear_bch() argument
770 struct resources *r = &this->resources; in gpmi_clear_bch()
774 static struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) in get_dma_chan() argument
777 return this->dma_chans[0]; in get_dma_chan()
780 /* This will be called after the DMA operation is finished. */
783 struct gpmi_nand_data *this = param; in dma_irq_callback() local
784 struct completion *dma_c = &this->dma_done; in dma_irq_callback()
791 struct gpmi_nand_data *this = cookie; in bch_irq() local
793 gpmi_clear_bch(this); in bch_irq()
794 complete(&this->bch_done); in bch_irq()
798 static int gpmi_raw_len_to_len(struct gpmi_nand_data *this, int raw_len) in gpmi_raw_len_to_len() argument
804 if (this->bch) in gpmi_raw_len_to_len()
805 return ALIGN_DOWN(raw_len, this->bch_geometry.ecc_chunk_size); in gpmi_raw_len_to_len()
811 static bool prepare_data_dma(struct gpmi_nand_data *this, const void *buf, in prepare_data_dma() argument
816 int len = gpmi_raw_len_to_len(this, raw_len); in prepare_data_dma()
821 ret = dma_map_sg(this->dev, sgl, 1, dr); in prepare_data_dma()
830 sg_init_one(sgl, this->data_buffer_dma, len); in prepare_data_dma()
832 if (dr == DMA_TO_DEVICE && buf != this->data_buffer_dma) in prepare_data_dma()
833 memcpy(this->data_buffer_dma, buf, len); in prepare_data_dma()
835 dma_map_sg(this->dev, sgl, 1, dr); in prepare_data_dma()
857 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ooblayout_ecc() local
858 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ooblayout_ecc()
873 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ooblayout_free() local
874 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ooblayout_free()
945 static int acquire_register_block(struct gpmi_nand_data *this, in acquire_register_block() argument
948 struct platform_device *pdev = this->pdev; in acquire_register_block()
949 struct resources *res = &this->resources; in acquire_register_block()
963 dev_err(this->dev, "unknown resource name : %s\n", res_name); in acquire_register_block()
968 static int acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h) in acquire_bch_irq() argument
970 struct platform_device *pdev = this->pdev; in acquire_bch_irq()
977 dev_err(this->dev, "Can't get resource for %s\n", res_name); in acquire_bch_irq()
981 err = devm_request_irq(this->dev, r->start, irq_h, 0, res_name, this); in acquire_bch_irq()
983 dev_err(this->dev, "error requesting BCH IRQ\n"); in acquire_bch_irq()
988 static void release_dma_channels(struct gpmi_nand_data *this) in release_dma_channels() argument
992 if (this->dma_chans[i]) { in release_dma_channels()
993 dma_release_channel(this->dma_chans[i]); in release_dma_channels()
994 this->dma_chans[i] = NULL; in release_dma_channels()
998 static int acquire_dma_channels(struct gpmi_nand_data *this) in acquire_dma_channels() argument
1000 struct platform_device *pdev = this->pdev; in acquire_dma_channels()
1007 ret = dev_err_probe(this->dev, PTR_ERR(dma_chan), in acquire_dma_channels()
1009 release_dma_channels(this); in acquire_dma_channels()
1011 this->dma_chans[0] = dma_chan; in acquire_dma_channels()
1017 static int gpmi_get_clks(struct gpmi_nand_data *this) in gpmi_get_clks() argument
1019 struct resources *r = &this->resources; in gpmi_get_clks()
1023 for (i = 0; i < this->devdata->clks_count; i++) { in gpmi_get_clks()
1024 clk = devm_clk_get(this->dev, this->devdata->clks[i]); in gpmi_get_clks()
1033 if (GPMI_IS_MX6(this)) in gpmi_get_clks()
1045 dev_dbg(this->dev, "failed in finding the clocks.\n"); in gpmi_get_clks()
1049 static int acquire_resources(struct gpmi_nand_data *this) in acquire_resources() argument
1053 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME); in acquire_resources()
1057 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME); in acquire_resources()
1061 ret = acquire_bch_irq(this, bch_irq); in acquire_resources()
1065 ret = acquire_dma_channels(this); in acquire_resources()
1069 ret = gpmi_get_clks(this); in acquire_resources()
1075 release_dma_channels(this); in acquire_resources()
1080 static void release_resources(struct gpmi_nand_data *this) in release_resources() argument
1082 release_dma_channels(this); in release_resources()
1085 static void gpmi_free_dma_buffer(struct gpmi_nand_data *this) in gpmi_free_dma_buffer() argument
1087 struct device *dev = this->dev; in gpmi_free_dma_buffer()
1088 struct bch_geometry *geo = &this->bch_geometry; in gpmi_free_dma_buffer()
1090 if (this->auxiliary_virt && virt_addr_valid(this->auxiliary_virt)) in gpmi_free_dma_buffer()
1092 this->auxiliary_virt, in gpmi_free_dma_buffer()
1093 this->auxiliary_phys); in gpmi_free_dma_buffer()
1094 kfree(this->data_buffer_dma); in gpmi_free_dma_buffer()
1095 kfree(this->raw_buffer); in gpmi_free_dma_buffer()
1097 this->data_buffer_dma = NULL; in gpmi_free_dma_buffer()
1098 this->raw_buffer = NULL; in gpmi_free_dma_buffer()
1102 static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this) in gpmi_alloc_dma_buffer() argument
1104 struct bch_geometry *geo = &this->bch_geometry; in gpmi_alloc_dma_buffer()
1105 struct device *dev = this->dev; in gpmi_alloc_dma_buffer()
1106 struct mtd_info *mtd = nand_to_mtd(&this->nand); in gpmi_alloc_dma_buffer()
1116 this->data_buffer_dma = kzalloc(mtd->writesize ?: PAGE_SIZE, in gpmi_alloc_dma_buffer()
1118 if (this->data_buffer_dma == NULL) in gpmi_alloc_dma_buffer()
1121 this->auxiliary_virt = dma_alloc_coherent(dev, geo->auxiliary_size, in gpmi_alloc_dma_buffer()
1122 &this->auxiliary_phys, GFP_DMA); in gpmi_alloc_dma_buffer()
1123 if (!this->auxiliary_virt) in gpmi_alloc_dma_buffer()
1126 this->raw_buffer = kzalloc((mtd->writesize ?: PAGE_SIZE) + mtd->oobsize, GFP_KERNEL); in gpmi_alloc_dma_buffer()
1127 if (!this->raw_buffer) in gpmi_alloc_dma_buffer()
1133 gpmi_free_dma_buffer(this); in gpmi_alloc_dma_buffer()
1142 static void block_mark_swapping(struct gpmi_nand_data *this, in block_mark_swapping() argument
1145 struct bch_geometry *nfc_geo = &this->bch_geometry; in block_mark_swapping()
1153 if (!this->swap_block_mark) in block_mark_swapping()
1188 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_count_bitflips() local
1189 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_count_bitflips()
1196 status = this->auxiliary_virt + ALIGN(meta, 4); in gpmi_count_bitflips()
1204 u8 *eccbuf = this->raw_buffer; in gpmi_count_bitflips()
1237 * nothing was written into this subpage the ECC is in gpmi_count_bitflips()
1239 * at this point that we are reading an erased page and in gpmi_count_bitflips()
1241 * ecc_strength bitflips. If this is a page with random in gpmi_count_bitflips()
1242 * data, we exceed this number of bitflips and have a in gpmi_count_bitflips()
1251 this->auxiliary_virt, in gpmi_count_bitflips()
1281 static void gpmi_bch_layout_std(struct gpmi_nand_data *this) in gpmi_bch_layout_std() argument
1283 struct bch_geometry *geo = &this->bch_geometry; in gpmi_bch_layout_std()
1288 this->bch_flashlayout0 = in gpmi_bch_layout_std()
1291 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) | in gpmi_bch_layout_std()
1292 BF_BCH_FLASH0LAYOUT0_GF(gf_len, this) | in gpmi_bch_layout_std()
1293 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this); in gpmi_bch_layout_std()
1295 this->bch_flashlayout1 = in gpmi_bch_layout_std()
1297 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | in gpmi_bch_layout_std()
1298 BF_BCH_FLASH0LAYOUT1_GF(gf_len, this) | in gpmi_bch_layout_std()
1299 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this); in gpmi_bch_layout_std()
1305 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_page() local
1307 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ecc_read_page()
1311 gpmi_bch_layout_std(this); in gpmi_ecc_read_page()
1312 this->bch = true; in gpmi_ecc_read_page()
1323 block_mark_swapping(this, buf, this->auxiliary_virt); in gpmi_ecc_read_page()
1337 chip->oob_poi[0] = ((uint8_t *)this->auxiliary_virt)[0]; in gpmi_ecc_read_page()
1347 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_subpage() local
1348 struct bch_geometry *geo = &this->bch_geometry; in gpmi_ecc_read_subpage()
1365 if (this->swap_block_mark) { in gpmi_ecc_read_subpage()
1368 * If this chunk is in the range of [first, last], in gpmi_ecc_read_subpage()
1375 dev_dbg(this->dev, in gpmi_ecc_read_subpage()
1395 this->bch_flashlayout0 = BF_BCH_FLASH0LAYOUT0_NBLOCKS(n - 1) | in gpmi_ecc_read_subpage()
1397 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) | in gpmi_ecc_read_subpage()
1398 BF_BCH_FLASH0LAYOUT0_GF(geo->gf_len, this) | in gpmi_ecc_read_subpage()
1399 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(geo->ecc_chunk_size, this); in gpmi_ecc_read_subpage()
1401 this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) | in gpmi_ecc_read_subpage()
1402 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | in gpmi_ecc_read_subpage()
1403 BF_BCH_FLASH0LAYOUT1_GF(geo->gf_len, this) | in gpmi_ecc_read_subpage()
1404 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->ecc_chunk_size, this); in gpmi_ecc_read_subpage()
1406 this->bch = true; in gpmi_ecc_read_subpage()
1412 dev_dbg(this->dev, "page:%d(%d:%d)%d, chunk:(%d:%d), BCH PG size:%d\n", in gpmi_ecc_read_subpage()
1424 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_write_page() local
1425 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_write_page()
1428 dev_dbg(this->dev, "ecc write page.\n"); in gpmi_ecc_write_page()
1430 gpmi_bch_layout_std(this); in gpmi_ecc_write_page()
1431 this->bch = true; in gpmi_ecc_write_page()
1433 memcpy(this->auxiliary_virt, chip->oob_poi, nfc_geo->auxiliary_size); in gpmi_ecc_write_page()
1435 if (this->swap_block_mark) { in gpmi_ecc_write_page()
1440 memcpy(this->data_buffer_dma, buf, mtd->writesize); in gpmi_ecc_write_page()
1441 buf = this->data_buffer_dma; in gpmi_ecc_write_page()
1442 block_mark_swapping(this, this->data_buffer_dma, in gpmi_ecc_write_page()
1443 this->auxiliary_virt); in gpmi_ecc_write_page()
1452 * There are several places in this driver where we have to handle the OOB and
1453 * block marks. This is the function where things are the most complicated, so
1454 * this is where we try to explain it all. All the other places refer back to
1471 * are OOB. This gives the caller a way to see the actual, physical bytes
1475 * What we do for this specific read operation depends on two questions:
1514 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_oob() local
1531 if (GPMI_IS_MX23(this)) { in gpmi_ecc_read_oob()
1559 * This function reads a NAND page without involving the ECC engine (no HW
1574 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_read_page_raw() local
1575 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_read_page_raw()
1578 u8 *tmp_buf = this->raw_buffer; in gpmi_ecc_read_page_raw()
1595 * See the layout description for a detailed explanation on why this in gpmi_ecc_read_page_raw()
1598 if (this->swap_block_mark) in gpmi_ecc_read_page_raw()
1602 * Copy the metadata section into the oob buffer (this section is in gpmi_ecc_read_page_raw()
1644 * This function writes a NAND page without involving the ECC engine (no HW
1659 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_ecc_write_page_raw() local
1660 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_write_page_raw()
1663 u8 *tmp_buf = this->raw_buffer; in gpmi_ecc_write_page_raw()
1716 * See the layout description for a detailed explanation on why this in gpmi_ecc_write_page_raw()
1719 if (this->swap_block_mark) in gpmi_ecc_write_page_raw()
1739 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_block_markbad() local
1747 column = !GPMI_IS_MX23(this) ? mtd->writesize : 0; in gpmi_block_markbad()
1750 block_mark = this->data_buffer_dma; in gpmi_block_markbad()
1763 static int nand_boot_set_geometry(struct gpmi_nand_data *this) in nand_boot_set_geometry() argument
1765 struct boot_rom_geometry *geometry = &this->rom_geometry; in nand_boot_set_geometry()
1770 * In principle, we should be reading this from the OTP bits, since in nand_boot_set_geometry()
1780 * In principle, we should be reading this from the OTP bits, since in nand_boot_set_geometry()
1790 static int mx23_check_transcription_stamp(struct gpmi_nand_data *this) in mx23_check_transcription_stamp() argument
1792 struct boot_rom_geometry *rom_geo = &this->rom_geometry; in mx23_check_transcription_stamp()
1793 struct device *dev = this->dev; in mx23_check_transcription_stamp()
1794 struct nand_chip *chip = &this->nand; in mx23_check_transcription_stamp()
1845 static int mx23_write_transcription_stamp(struct gpmi_nand_data *this) in mx23_write_transcription_stamp() argument
1847 struct device *dev = this->dev; in mx23_write_transcription_stamp()
1848 struct boot_rom_geometry *rom_geo = &this->rom_geometry; in mx23_write_transcription_stamp()
1849 struct nand_chip *chip = &this->nand; in mx23_write_transcription_stamp()
1881 /* Erase this block. */ in mx23_write_transcription_stamp()
1911 static int mx23_boot_init(struct gpmi_nand_data *this) in mx23_boot_init() argument
1913 struct device *dev = this->dev; in mx23_boot_init()
1914 struct nand_chip *chip = &this->nand; in mx23_boot_init()
1930 if (mx23_check_transcription_stamp(this)) in mx23_boot_init()
1948 * Compute the chip, page and byte addresses for this block's in mx23_boot_init()
1966 * again, but this time the result will be a mark in the in mx23_boot_init()
1980 mx23_write_transcription_stamp(this); in mx23_boot_init()
1984 static int nand_boot_init(struct gpmi_nand_data *this) in nand_boot_init() argument
1986 nand_boot_set_geometry(this); in nand_boot_init()
1988 /* This is ROM arch-specific initilization before the BBT scanning. */ in nand_boot_init()
1989 if (GPMI_IS_MX23(this)) in nand_boot_init()
1990 return mx23_boot_init(this); in nand_boot_init()
1994 static int gpmi_set_geometry(struct gpmi_nand_data *this) in gpmi_set_geometry() argument
1999 gpmi_free_dma_buffer(this); in gpmi_set_geometry()
2002 ret = bch_set_geometry(this); in gpmi_set_geometry()
2004 dev_err(this->dev, "Error setting BCH geometry : %d\n", ret); in gpmi_set_geometry()
2009 return gpmi_alloc_dma_buffer(this); in gpmi_set_geometry()
2012 static int gpmi_init_last(struct gpmi_nand_data *this) in gpmi_init_last() argument
2014 struct nand_chip *chip = &this->nand; in gpmi_init_last()
2017 struct bch_geometry *bch_geo = &this->bch_geometry; in gpmi_init_last()
2021 ret = gpmi_set_geometry(this); in gpmi_init_last()
2044 if (GPMI_IS_MX6(this) && in gpmi_init_last()
2055 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_nand_attach_chip() local
2061 if (of_property_read_bool(this->dev->of_node, in gpmi_nand_attach_chip()
2063 this->swap_block_mark = false; in gpmi_nand_attach_chip()
2065 dev_dbg(this->dev, "Blockmark swapping %sabled\n", in gpmi_nand_attach_chip()
2066 this->swap_block_mark ? "en" : "dis"); in gpmi_nand_attach_chip()
2068 ret = gpmi_init_last(this); in gpmi_nand_attach_chip()
2077 static struct gpmi_transfer *get_next_transfer(struct gpmi_nand_data *this) in get_next_transfer() argument
2079 struct gpmi_transfer *transfer = &this->transfers[this->ntransfers]; in get_next_transfer()
2081 this->ntransfers++; in get_next_transfer()
2083 if (this->ntransfers == GPMI_MAX_TRANSFERS) in get_next_transfer()
2090 struct gpmi_nand_data *this, u8 cmd, const u8 *addr, int naddr) in gpmi_chain_command() argument
2092 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_command()
2095 int chip = this->nand.cur_cs; in gpmi_chain_command()
2101 | BF_GPMI_CTRL0_CS(chip, this) in gpmi_chain_command()
2102 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_command()
2113 transfer = get_next_transfer(this); in gpmi_chain_command()
2122 dma_map_sg(this->dev, &transfer->sgl, 1, DMA_TO_DEVICE); in gpmi_chain_command()
2132 struct gpmi_nand_data *this) in gpmi_chain_wait_ready() argument
2134 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_wait_ready()
2139 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this) in gpmi_chain_wait_ready()
2140 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_wait_ready()
2150 struct gpmi_nand_data *this, void *buf, int raw_len, bool *direct) in gpmi_chain_data_read() argument
2153 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_data_read()
2157 transfer = get_next_transfer(this); in gpmi_chain_data_read()
2163 *direct = prepare_data_dma(this, buf, raw_len, &transfer->sgl, in gpmi_chain_data_read()
2168 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this) in gpmi_chain_data_read()
2169 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_data_read()
2173 if (this->bch) { in gpmi_chain_data_read()
2180 pio[5] = this->auxiliary_phys; in gpmi_chain_data_read()
2188 if (!this->bch) in gpmi_chain_data_read()
2197 struct gpmi_nand_data *this, const void *buf, int raw_len) in gpmi_chain_data_write() argument
2199 struct dma_chan *channel = get_dma_chan(this); in gpmi_chain_data_write()
2204 transfer = get_next_transfer(this); in gpmi_chain_data_write()
2210 prepare_data_dma(this, buf, raw_len, &transfer->sgl, DMA_TO_DEVICE); in gpmi_chain_data_write()
2214 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this) in gpmi_chain_data_write()
2215 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this) in gpmi_chain_data_write()
2219 if (this->bch) { in gpmi_chain_data_write()
2226 pio[5] = this->auxiliary_phys; in gpmi_chain_data_write()
2231 (this->bch ? MXS_DMA_CTRL_WAIT4END : 0)); in gpmi_chain_data_write()
2235 if (!this->bch) in gpmi_chain_data_write()
2248 struct gpmi_nand_data *this = nand_get_controller_data(chip); in gpmi_nfc_exec_op() local
2261 this->ntransfers = 0; in gpmi_nfc_exec_op()
2263 this->transfers[i].direction = DMA_NONE; in gpmi_nfc_exec_op()
2265 ret = pm_runtime_get_sync(this->dev); in gpmi_nfc_exec_op()
2270 * This driver currently supports only one NAND chip. Plus, dies share in gpmi_nfc_exec_op()
2275 if (this->hw.must_apply_timings) { in gpmi_nfc_exec_op()
2276 this->hw.must_apply_timings = false; in gpmi_nfc_exec_op()
2277 gpmi_nfc_apply_timings(this); in gpmi_nfc_exec_op()
2280 dev_dbg(this->dev, "%s: %d instructions\n", __func__, op->ninstrs); in gpmi_nfc_exec_op()
2289 desc = gpmi_chain_wait_ready(this); in gpmi_nfc_exec_op()
2295 * When this command has an address cycle chain it in gpmi_nfc_exec_op()
2302 desc = gpmi_chain_command(this, cmd, NULL, 0); in gpmi_nfc_exec_op()
2306 desc = gpmi_chain_command(this, cmd, instr->ctx.addr.addrs, in gpmi_nfc_exec_op()
2314 desc = gpmi_chain_data_write(this, buf_write, buf_len); in gpmi_nfc_exec_op()
2324 desc = gpmi_chain_data_read(this, buf_read, buf_len, in gpmi_nfc_exec_op()
2335 dev_dbg(this->dev, "%s setup done\n", __func__); in gpmi_nfc_exec_op()
2338 dev_err(this->dev, "Multiple data instructions not supported\n"); in gpmi_nfc_exec_op()
2343 if (this->bch) { in gpmi_nfc_exec_op()
2344 writel(this->bch_flashlayout0, in gpmi_nfc_exec_op()
2345 this->resources.bch_regs + HW_BCH_FLASH0LAYOUT0); in gpmi_nfc_exec_op()
2346 writel(this->bch_flashlayout1, in gpmi_nfc_exec_op()
2347 this->resources.bch_regs + HW_BCH_FLASH0LAYOUT1); in gpmi_nfc_exec_op()
2350 if (this->bch && buf_read) { in gpmi_nfc_exec_op()
2352 this->resources.bch_regs + HW_BCH_CTRL_SET); in gpmi_nfc_exec_op()
2353 completion = &this->bch_done; in gpmi_nfc_exec_op()
2356 desc->callback_param = this; in gpmi_nfc_exec_op()
2357 completion = &this->dma_done; in gpmi_nfc_exec_op()
2363 dma_async_issue_pending(get_dma_chan(this)); in gpmi_nfc_exec_op()
2367 dev_err(this->dev, "DMA timeout, last DMA\n"); in gpmi_nfc_exec_op()
2368 gpmi_dump_info(this); in gpmi_nfc_exec_op()
2374 this->resources.bch_regs + HW_BCH_CTRL_CLR); in gpmi_nfc_exec_op()
2375 gpmi_clear_bch(this); in gpmi_nfc_exec_op()
2380 for (i = 0; i < this->ntransfers; i++) { in gpmi_nfc_exec_op()
2381 struct gpmi_transfer *transfer = &this->transfers[i]; in gpmi_nfc_exec_op()
2384 dma_unmap_sg(this->dev, &transfer->sgl, 1, in gpmi_nfc_exec_op()
2389 memcpy(buf_read, this->data_buffer_dma, in gpmi_nfc_exec_op()
2390 gpmi_raw_len_to_len(this, buf_len)); in gpmi_nfc_exec_op()
2392 this->bch = false; in gpmi_nfc_exec_op()
2394 pm_runtime_mark_last_busy(this->dev); in gpmi_nfc_exec_op()
2395 pm_runtime_put_autosuspend(this->dev); in gpmi_nfc_exec_op()
2406 static int gpmi_nand_init(struct gpmi_nand_data *this) in gpmi_nand_init() argument
2408 struct nand_chip *chip = &this->nand; in gpmi_nand_init()
2414 mtd->dev.parent = this->dev; in gpmi_nand_init()
2417 nand_set_controller_data(chip, this); in gpmi_nand_init()
2418 nand_set_flash_node(chip, this->pdev->dev.of_node); in gpmi_nand_init()
2424 this->swap_block_mark = !GPMI_IS_MX23(this); in gpmi_nand_init()
2430 this->bch_geometry.payload_size = 1024; in gpmi_nand_init()
2431 this->bch_geometry.auxiliary_size = 128; in gpmi_nand_init()
2432 ret = gpmi_alloc_dma_buffer(this); in gpmi_nand_init()
2436 nand_controller_init(&this->base); in gpmi_nand_init()
2437 this->base.ops = &gpmi_nand_controller_ops; in gpmi_nand_init()
2438 chip->controller = &this->base; in gpmi_nand_init()
2440 ret = nand_scan(chip, GPMI_IS_MX6(this) ? 2 : 1); in gpmi_nand_init()
2444 ret = nand_boot_init(this); in gpmi_nand_init()
2459 gpmi_free_dma_buffer(this); in gpmi_nand_init()
2485 struct gpmi_nand_data *this; in gpmi_nand_probe() local
2489 this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL); in gpmi_nand_probe()
2490 if (!this) in gpmi_nand_probe()
2495 this->devdata = of_id->data; 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()