Lines Matching refs:this

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)
126 clk = this->resources.clock[i];
142 clk_disable_unprepare(this->resources.clock[i - 1]);
146 static int gpmi_init(struct gpmi_nand_data *this)
148 struct resources *r = &this->resources;
151 ret = pm_runtime_get_sync(this->dev);
153 pm_runtime_put_noidle(this->dev);
165 ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this));
189 pm_runtime_mark_last_busy(this->dev);
190 pm_runtime_put_autosuspend(this->dev);
195 static void gpmi_dump_info(struct gpmi_nand_data *this)
197 struct resources *r = &this->resources;
198 struct bch_geometry *geo = &this->bch_geometry;
202 dev_err(this->dev, "Show GPMI registers :\n");
205 dev_err(this->dev, "offset 0x%.3x : 0x%.8x\n", i * 0x10, reg);
209 dev_err(this->dev, "Show BCH registers :\n");
212 dev_err(this->dev, "offset 0x%.3x : 0x%.8x\n", i * 0x10, reg);
214 dev_err(this->dev, "BCH Geometry :\n"
239 static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
241 struct bch_geometry *geo = &this->bch_geometry;
244 if (GPMI_IS_MXS(this)) {
249 return geo->ecc_strength <= this->devdata->bch_max_ecc_strength;
256 * We may have available oob space in this case.
258 static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
262 struct bch_geometry *geo = &this->bch_geometry;
263 struct nand_chip *chip = &this->nand;
275 dev_err(this->dev,
283 if (!gpmi_check_ecc(this))
288 dev_err(this->dev,
356 if (!this->swap_block_mark)
387 static inline int get_ecc_strength(struct gpmi_nand_data *this)
389 struct bch_geometry *geo = &this->bch_geometry;
390 struct mtd_info *mtd = nand_to_mtd(&this->nand);
400 static int legacy_set_geometry(struct gpmi_nand_data *this)
402 struct bch_geometry *geo = &this->bch_geometry;
403 struct mtd_info *mtd = nand_to_mtd(&this->nand);
428 geo->ecc_strength = get_ecc_strength(this);
429 if (!gpmi_check_ecc(this)) {
430 dev_err(this->dev,
434 this->devdata->bch_max_ecc_strength);
454 if (!this->swap_block_mark)
512 static int common_nfc_set_geometry(struct gpmi_nand_data *this)
514 struct nand_chip *chip = &this->nand;
519 return set_geometry_by_ecc_info(this, chip->ecc.strength,
522 if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc"))
523 || legacy_set_geometry(this)) {
527 return set_geometry_by_ecc_info(this,
536 static int bch_set_geometry(struct gpmi_nand_data *this)
538 struct resources *r = &this->resources;
541 ret = common_nfc_set_geometry(this);
545 ret = pm_runtime_get_sync(this->dev);
547 pm_runtime_put_autosuspend(this->dev);
552 * Due to erratum #2847 of the MX23, the BCH cannot be soft reset on this
556 ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this));
565 pm_runtime_mark_last_busy(this->dev);
566 pm_runtime_put_autosuspend(this->dev);
645 static void gpmi_nfc_compute_timings(struct gpmi_nand_data *this,
648 struct gpmi_nfc_hardware_timing *hw = &this->hw;
649 struct resources *r = &this->resources;
650 unsigned int dll_threshold_ps = this->devdata->max_chain_delay;
719 static int gpmi_nfc_apply_timings(struct gpmi_nand_data *this)
721 struct gpmi_nfc_hardware_timing *hw = &this->hw;
722 struct resources *r = &this->resources;
731 if (GPMI_IS_MX6Q(this) || GPMI_IS_MX6SX(this))
736 dev_err(this->dev, "cannot set clock rate to %lu Hz: %d\n", hw->clk_rate, ret);
740 if (GPMI_IS_MX6Q(this) || GPMI_IS_MX6SX(this)) {
770 struct gpmi_nand_data *this = nand_get_controller_data(chip);
779 if (sdr->tRC_min <= 25000 && !GPMI_IS_MX6(this))
782 /* Stop here if this call was just a check */
787 gpmi_nfc_compute_timings(this, sdr);
789 this->hw.must_apply_timings = true;
795 static void gpmi_clear_bch(struct gpmi_nand_data *this)
797 struct resources *r = &this->resources;
801 static struct dma_chan *get_dma_chan(struct gpmi_nand_data *this)
804 return this->dma_chans[0];
810 struct gpmi_nand_data *this = param;
811 struct completion *dma_c = &this->dma_done;
818 struct gpmi_nand_data *this = cookie;
820 gpmi_clear_bch(this);
821 complete(&this->bch_done);
825 static int gpmi_raw_len_to_len(struct gpmi_nand_data *this, int raw_len)
831 if (this->bch)
832 return ALIGN_DOWN(raw_len, this->bch_geometry.ecc_chunk_size);
838 static bool prepare_data_dma(struct gpmi_nand_data *this, const void *buf,
843 int len = gpmi_raw_len_to_len(this, raw_len);
848 ret = dma_map_sg(this->dev, sgl, 1, dr);
857 sg_init_one(sgl, this->data_buffer_dma, len);
859 if (dr == DMA_TO_DEVICE && buf != this->data_buffer_dma)
860 memcpy(this->data_buffer_dma, buf, len);
862 dma_map_sg(this->dev, sgl, 1, dr);
884 struct gpmi_nand_data *this = nand_get_controller_data(chip);
885 struct bch_geometry *geo = &this->bch_geometry;
900 struct gpmi_nand_data *this = nand_get_controller_data(chip);
901 struct bch_geometry *geo = &this->bch_geometry;
972 static int acquire_register_block(struct gpmi_nand_data *this,
975 struct platform_device *pdev = this->pdev;
976 struct resources *res = &this->resources;
990 dev_err(this->dev, "unknown resource name : %s\n", res_name);
995 static int acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h)
997 struct platform_device *pdev = this->pdev;
1004 dev_err(this->dev, "Can't get resource for %s\n", res_name);
1008 err = devm_request_irq(this->dev, r->start, irq_h, 0, res_name, this);
1010 dev_err(this->dev, "error requesting BCH IRQ\n");
1015 static void release_dma_channels(struct gpmi_nand_data *this)
1019 if (this->dma_chans[i]) {
1020 dma_release_channel(this->dma_chans[i]);
1021 this->dma_chans[i] = NULL;
1025 static int acquire_dma_channels(struct gpmi_nand_data *this)
1027 struct platform_device *pdev = this->pdev;
1034 ret = dev_err_probe(this->dev, PTR_ERR(dma_chan),
1036 release_dma_channels(this);
1038 this->dma_chans[0] = dma_chan;
1044 static int gpmi_get_clks(struct gpmi_nand_data *this)
1046 struct resources *r = &this->resources;
1050 for (i = 0; i < this->devdata->clks_count; i++) {
1051 clk = devm_clk_get(this->dev, this->devdata->clks[i]);
1063 dev_dbg(this->dev, "failed in finding the clocks.\n");
1067 static int acquire_resources(struct gpmi_nand_data *this)
1071 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME);
1075 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME);
1079 ret = acquire_bch_irq(this, bch_irq);
1083 ret = acquire_dma_channels(this);
1087 ret = gpmi_get_clks(this);
1093 release_dma_channels(this);
1098 static void release_resources(struct gpmi_nand_data *this)
1100 release_dma_channels(this);
1103 static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
1105 struct device *dev = this->dev;
1106 struct bch_geometry *geo = &this->bch_geometry;
1108 if (this->auxiliary_virt && virt_addr_valid(this->auxiliary_virt))
1110 this->auxiliary_virt,
1111 this->auxiliary_phys);
1112 kfree(this->data_buffer_dma);
1113 kfree(this->raw_buffer);
1115 this->data_buffer_dma = NULL;
1116 this->raw_buffer = NULL;
1120 static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this)
1122 struct bch_geometry *geo = &this->bch_geometry;
1123 struct device *dev = this->dev;
1124 struct mtd_info *mtd = nand_to_mtd(&this->nand);
1134 this->data_buffer_dma = kzalloc(mtd->writesize ?: PAGE_SIZE,
1136 if (this->data_buffer_dma == NULL)
1139 this->auxiliary_virt = dma_alloc_coherent(dev, geo->auxiliary_size,
1140 &this->auxiliary_phys, GFP_DMA);
1141 if (!this->auxiliary_virt)
1144 this->raw_buffer = kzalloc((mtd->writesize ?: PAGE_SIZE) + mtd->oobsize, GFP_KERNEL);
1145 if (!this->raw_buffer)
1151 gpmi_free_dma_buffer(this);
1160 static void block_mark_swapping(struct gpmi_nand_data *this,
1163 struct bch_geometry *nfc_geo = &this->bch_geometry;
1171 if (!this->swap_block_mark)
1206 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1207 struct bch_geometry *nfc_geo = &this->bch_geometry;
1214 status = this->auxiliary_virt + ALIGN(meta, 4);
1222 u8 *eccbuf = this->raw_buffer;
1255 * nothing was written into this subpage the ECC is
1257 * at this point that we are reading an erased page and
1259 * ecc_strength bitflips. If this is a page with random
1260 * data, we exceed this number of bitflips and have a
1269 this->auxiliary_virt,
1299 static void gpmi_bch_layout_std(struct gpmi_nand_data *this)
1301 struct bch_geometry *geo = &this->bch_geometry;
1306 this->bch_flashlayout0 =
1309 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) |
1310 BF_BCH_FLASH0LAYOUT0_GF(gf_len, this) |
1311 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this);
1313 this->bch_flashlayout1 =
1315 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) |
1316 BF_BCH_FLASH0LAYOUT1_GF(gf_len, this) |
1317 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this);
1323 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1325 struct bch_geometry *geo = &this->bch_geometry;
1329 gpmi_bch_layout_std(this);
1330 this->bch = true;
1341 block_mark_swapping(this, buf, this->auxiliary_virt);
1355 chip->oob_poi[0] = ((uint8_t *)this->auxiliary_virt)[0];
1365 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1366 struct bch_geometry *geo = &this->bch_geometry;
1383 if (this->swap_block_mark) {
1386 * If this chunk is in the range of [first, last],
1393 dev_dbg(this->dev,
1413 this->bch_flashlayout0 = BF_BCH_FLASH0LAYOUT0_NBLOCKS(n - 1) |
1415 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) |
1416 BF_BCH_FLASH0LAYOUT0_GF(geo->gf_len, this) |
1417 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(geo->ecc_chunk_size, this);
1419 this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) |
1420 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) |
1421 BF_BCH_FLASH0LAYOUT1_GF(geo->gf_len, this) |
1422 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->ecc_chunk_size, this);
1424 this->bch = true;
1430 dev_dbg(this->dev, "page:%d(%d:%d)%d, chunk:(%d:%d), BCH PG size:%d\n",
1442 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1443 struct bch_geometry *nfc_geo = &this->bch_geometry;
1446 dev_dbg(this->dev, "ecc write page.\n");
1448 gpmi_bch_layout_std(this);
1449 this->bch = true;
1451 memcpy(this->auxiliary_virt, chip->oob_poi, nfc_geo->auxiliary_size);
1453 if (this->swap_block_mark) {
1458 memcpy(this->data_buffer_dma, buf, mtd->writesize);
1459 buf = this->data_buffer_dma;
1460 block_mark_swapping(this, this->data_buffer_dma,
1461 this->auxiliary_virt);
1470 * There are several places in this driver where we have to handle the OOB and
1472 * this is where we try to explain it all. All the other places refer back to
1493 * What we do for this specific read operation depends on two questions:
1532 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1549 if (GPMI_IS_MX23(this)) {
1592 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1593 struct bch_geometry *nfc_geo = &this->bch_geometry;
1596 u8 *tmp_buf = this->raw_buffer;
1613 * See the layout description for a detailed explanation on why this
1616 if (this->swap_block_mark)
1620 * Copy the metadata section into the oob buffer (this section is
1677 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1678 struct bch_geometry *nfc_geo = &this->bch_geometry;
1681 u8 *tmp_buf = this->raw_buffer;
1734 * See the layout description for a detailed explanation on why this
1737 if (this->swap_block_mark)
1757 struct gpmi_nand_data *this = nand_get_controller_data(chip);
1765 column = !GPMI_IS_MX23(this) ? mtd->writesize : 0;
1768 block_mark = this->data_buffer_dma;
1781 static int nand_boot_set_geometry(struct gpmi_nand_data *this)
1783 struct boot_rom_geometry *geometry = &this->rom_geometry;
1788 * In principle, we should be reading this from the OTP bits, since
1798 * In principle, we should be reading this from the OTP bits, since
1808 static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
1810 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1811 struct device *dev = this->dev;
1812 struct nand_chip *chip = &this->nand;
1863 static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
1865 struct device *dev = this->dev;
1866 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1867 struct nand_chip *chip = &this->nand;
1899 /* Erase this block. */
1929 static int mx23_boot_init(struct gpmi_nand_data *this)
1931 struct device *dev = this->dev;
1932 struct nand_chip *chip = &this->nand;
1948 if (mx23_check_transcription_stamp(this))
1966 * Compute the chip, page and byte addresses for this block's
1984 * again, but this time the result will be a mark in the
1998 mx23_write_transcription_stamp(this);
2002 static int nand_boot_init(struct gpmi_nand_data *this)
2004 nand_boot_set_geometry(this);
2007 if (GPMI_IS_MX23(this))
2008 return mx23_boot_init(this);
2012 static int gpmi_set_geometry(struct gpmi_nand_data *this)
2017 gpmi_free_dma_buffer(this);
2020 ret = bch_set_geometry(this);
2022 dev_err(this->dev, "Error setting BCH geometry : %d\n", ret);
2027 return gpmi_alloc_dma_buffer(this);
2030 static int gpmi_init_last(struct gpmi_nand_data *this)
2032 struct nand_chip *chip = &this->nand;
2035 struct bch_geometry *bch_geo = &this->bch_geometry;
2039 ret = gpmi_set_geometry(this);
2062 if (GPMI_IS_MX6(this) &&
2073 struct gpmi_nand_data *this = nand_get_controller_data(chip);
2079 if (of_property_read_bool(this->dev->of_node,
2081 this->swap_block_mark = false;
2083 dev_dbg(this->dev, "Blockmark swapping %sabled\n",
2084 this->swap_block_mark ? "en" : "dis");
2086 ret = gpmi_init_last(this);
2095 static struct gpmi_transfer *get_next_transfer(struct gpmi_nand_data *this)
2097 struct gpmi_transfer *transfer = &this->transfers[this->ntransfers];
2099 this->ntransfers++;
2101 if (this->ntransfers == GPMI_MAX_TRANSFERS)
2108 struct gpmi_nand_data *this, u8 cmd, const u8 *addr, int naddr)
2110 struct dma_chan *channel = get_dma_chan(this);
2113 int chip = this->nand.cur_cs;
2119 | BF_GPMI_CTRL0_CS(chip, this)
2120 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
2131 transfer = get_next_transfer(this);
2140 dma_map_sg(this->dev, &transfer->sgl, 1, DMA_TO_DEVICE);
2150 struct gpmi_nand_data *this)
2152 struct dma_chan *channel = get_dma_chan(this);
2157 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this)
2158 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
2168 struct gpmi_nand_data *this, void *buf, int raw_len, bool *direct)
2171 struct dma_chan *channel = get_dma_chan(this);
2175 transfer = get_next_transfer(this);
2181 *direct = prepare_data_dma(this, buf, raw_len, &transfer->sgl,
2186 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this)
2187 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
2191 if (this->bch) {
2198 pio[5] = this->auxiliary_phys;
2206 if (!this->bch)
2215 struct gpmi_nand_data *this, const void *buf, int raw_len)
2217 struct dma_chan *channel = get_dma_chan(this);
2222 transfer = get_next_transfer(this);
2228 prepare_data_dma(this, buf, raw_len, &transfer->sgl, DMA_TO_DEVICE);
2232 | BF_GPMI_CTRL0_CS(this->nand.cur_cs, this)
2233 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
2237 if (this->bch) {
2244 pio[5] = this->auxiliary_phys;
2249 (this->bch ? MXS_DMA_CTRL_WAIT4END : 0));
2253 if (!this->bch)
2266 struct gpmi_nand_data *this = nand_get_controller_data(chip);
2279 this->ntransfers = 0;
2281 this->transfers[i].direction = DMA_NONE;
2283 ret = pm_runtime_get_sync(this->dev);
2285 pm_runtime_put_noidle(this->dev);
2295 if (this->hw.must_apply_timings) {
2296 this->hw.must_apply_timings = false;
2297 ret = gpmi_nfc_apply_timings(this);
2302 dev_dbg(this->dev, "%s: %d instructions\n", __func__, op->ninstrs);
2311 desc = gpmi_chain_wait_ready(this);
2317 * When this command has an address cycle chain it
2324 desc = gpmi_chain_command(this, cmd, NULL, 0);
2328 desc = gpmi_chain_command(this, cmd, instr->ctx.addr.addrs,
2336 desc = gpmi_chain_data_write(this, buf_write, buf_len);
2346 desc = gpmi_chain_data_read(this, buf_read, buf_len,
2357 dev_dbg(this->dev, "%s setup done\n", __func__);
2360 dev_err(this->dev, "Multiple data instructions not supported\n");
2365 if (this->bch) {
2366 writel(this->bch_flashlayout0,
2367 this->resources.bch_regs + HW_BCH_FLASH0LAYOUT0);
2368 writel(this->bch_flashlayout1,
2369 this->resources.bch_regs + HW_BCH_FLASH0LAYOUT1);
2373 desc->callback_param = this;
2374 dma_completion = &this->dma_done;
2379 if (this->bch && buf_read) {
2381 this->resources.bch_regs + HW_BCH_CTRL_SET);
2382 bch_completion = &this->bch_done;
2387 dma_async_issue_pending(get_dma_chan(this));
2391 dev_err(this->dev, "DMA timeout, last DMA\n");
2392 gpmi_dump_info(this);
2397 if (this->bch && buf_read) {
2400 dev_err(this->dev, "BCH timeout, last DMA\n");
2401 gpmi_dump_info(this);
2408 this->resources.bch_regs + HW_BCH_CTRL_CLR);
2409 gpmi_clear_bch(this);
2414 for (i = 0; i < this->ntransfers; i++) {
2415 struct gpmi_transfer *transfer = &this->transfers[i];
2418 dma_unmap_sg(this->dev, &transfer->sgl, 1,
2423 memcpy(buf_read, this->data_buffer_dma,
2424 gpmi_raw_len_to_len(this, buf_len));
2426 this->bch = false;
2429 pm_runtime_mark_last_busy(this->dev);
2430 pm_runtime_put_autosuspend(this->dev);
2441 static int gpmi_nand_init(struct gpmi_nand_data *this)
2443 struct nand_chip *chip = &this->nand;
2449 mtd->dev.parent = this->dev;
2452 nand_set_controller_data(chip, this);
2453 nand_set_flash_node(chip, this->pdev->dev.of_node);
2459 this->swap_block_mark = !GPMI_IS_MX23(this);
2465 this->bch_geometry.payload_size = 1024;
2466 this->bch_geometry.auxiliary_size = 128;
2467 ret = gpmi_alloc_dma_buffer(this);
2471 nand_controller_init(&this->base);
2472 this->base.ops = &gpmi_nand_controller_ops;
2473 chip->controller = &this->base;
2475 ret = nand_scan(chip, GPMI_IS_MX6(this) ? 2 : 1);
2479 ret = nand_boot_init(this);
2494 gpmi_free_dma_buffer(this);
2520 struct gpmi_nand_data *this;
2524 this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL);
2525 if (!this)
2530 this->devdata = of_id->data;
2536 platform_set_drvdata(pdev, this);
2537 this->pdev = pdev;
2538 this->dev = &pdev->dev;
2540 ret = acquire_resources(this);
2544 ret = __gpmi_enable_clk(this, true);
2554 ret = gpmi_init(this);
2558 ret = gpmi_nand_init(this);
2565 dev_info(this->dev, "driver registered.\n");
2572 release_resources(this);
2580 struct gpmi_nand_data *this = platform_get_drvdata(pdev);
2581 struct nand_chip *chip = &this->nand;
2590 gpmi_free_dma_buffer(this);
2591 release_resources(this);
2598 struct gpmi_nand_data *this = dev_get_drvdata(dev);
2600 release_dma_channels(this);
2606 struct gpmi_nand_data *this = dev_get_drvdata(dev);
2609 ret = acquire_dma_channels(this);
2614 ret = gpmi_init(this);
2616 dev_err(this->dev, "Error setting GPMI : %d\n", ret);
2621 if (this->hw.clk_rate)
2622 this->hw.must_apply_timings = true;
2625 ret = bch_set_geometry(this);
2627 dev_err(this->dev, "Error setting BCH : %d\n", ret);
2637 struct gpmi_nand_data *this = dev_get_drvdata(dev);
2639 return __gpmi_enable_clk(this, false);
2644 struct gpmi_nand_data *this = dev_get_drvdata(dev);
2646 return __gpmi_enable_clk(this, true);