Lines Matching full:this
7 * This program is free software; you can redistribute it and/or modify
12 * This program is distributed in the hope that it will be useful,
18 * with this program; if not, write to the Free Software Foundation, Inc.,
47 struct gpmi_nand_data *this = cookie; in bch_irq() local
49 gpmi_clear_bch(this); in bch_irq()
50 complete(&this->bch_done); in bch_irq()
72 static inline int get_ecc_strength(struct gpmi_nand_data *this) in get_ecc_strength() argument
74 struct bch_geometry *geo = &this->bch_geometry; in get_ecc_strength()
75 struct mtd_info *mtd = &this->mtd; in get_ecc_strength()
85 int common_nfc_set_geometry(struct gpmi_nand_data *this) in common_nfc_set_geometry() argument
87 struct bch_geometry *geo = &this->bch_geometry; in common_nfc_set_geometry()
88 struct mtd_info *mtd = &this->mtd; in common_nfc_set_geometry()
111 geo->ecc_strength = get_ecc_strength(this); in common_nfc_set_geometry()
132 if (!this->swap_block_mark) in common_nfc_set_geometry()
190 struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) in get_dma_chan() argument
192 int chipnr = this->current_chip; in get_dma_chan()
194 return this->dma_chans[chipnr]; in get_dma_chan()
198 void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr) in prepare_data_dma() argument
200 struct scatterlist *sgl = &this->data_sgl; in prepare_data_dma()
203 this->direct_dma_map_ok = true; in prepare_data_dma()
206 sg_init_one(sgl, this->upper_buf, this->upper_len); in prepare_data_dma()
207 ret = dma_map_sg(this->dev, sgl, 1, dr); in prepare_data_dma()
210 sg_init_one(sgl, this->data_buffer_dma, PAGE_SIZE); in prepare_data_dma()
213 memcpy(this->data_buffer_dma, this->upper_buf, in prepare_data_dma()
214 this->upper_len); in prepare_data_dma()
216 ret = dma_map_sg(this->dev, sgl, 1, dr); in prepare_data_dma()
220 this->direct_dma_map_ok = false; in prepare_data_dma()
224 /* This will be called after the DMA operation is finished. */
227 struct gpmi_nand_data *this = param; in dma_irq_callback() local
228 struct completion *dma_c = &this->dma_done; in dma_irq_callback()
232 switch (this->dma_type) { in dma_irq_callback()
234 dma_unmap_sg(this->dev, &this->cmd_sgl, 1, DMA_TO_DEVICE); in dma_irq_callback()
238 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_FROM_DEVICE); in dma_irq_callback()
239 if (this->direct_dma_map_ok == false) in dma_irq_callback()
240 memcpy(this->upper_buf, this->data_buffer_dma, in dma_irq_callback()
241 this->upper_len); in dma_irq_callback()
245 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_TO_DEVICE); in dma_irq_callback()
258 int start_dma_without_bch_irq(struct gpmi_nand_data *this, in start_dma_without_bch_irq() argument
261 struct completion *dma_c = &this->dma_done; in start_dma_without_bch_irq()
267 desc->callback_param = this; in start_dma_without_bch_irq()
273 pr_err("DMA timeout, last DMA :%d\n", this->last_dma_type); in start_dma_without_bch_irq()
274 gpmi_dump_info(this); in start_dma_without_bch_irq()
281 * This function is used in BCH reading or BCH writing pages.
287 int start_dma_with_bch_irq(struct gpmi_nand_data *this, in start_dma_with_bch_irq() argument
290 struct completion *bch_c = &this->bch_done; in start_dma_with_bch_irq()
297 start_dma_without_bch_irq(this, desc); in start_dma_with_bch_irq()
302 pr_err("BCH timeout, last DMA :%d\n", this->last_dma_type); in start_dma_with_bch_irq()
303 gpmi_dump_info(this); in start_dma_with_bch_irq()
310 acquire_register_block(struct gpmi_nand_data *this, const char *res_name) in acquire_register_block() argument
312 struct platform_device *pdev = this->pdev; in acquire_register_block()
313 struct resources *res = &this->resources; in acquire_register_block()
339 static void release_register_block(struct gpmi_nand_data *this) in release_register_block() argument
341 struct resources *res = &this->resources; in release_register_block()
351 acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h) in acquire_bch_irq() argument
353 struct platform_device *pdev = this->pdev; in acquire_bch_irq()
354 struct resources *res = &this->resources; in acquire_bch_irq()
365 err = request_irq(r->start, irq_h, 0, res_name, this); in acquire_bch_irq()
376 static void release_bch_irq(struct gpmi_nand_data *this) in release_bch_irq() argument
378 struct resources *res = &this->resources; in release_bch_irq()
382 free_irq(i, this); in release_bch_irq()
387 struct gpmi_nand_data *this = param; in gpmi_dma_filter() local
388 struct resource *r = this->private; in gpmi_dma_filter()
401 chan->private = &this->dma_data; in gpmi_dma_filter()
407 static void release_dma_channels(struct gpmi_nand_data *this) in release_dma_channels() argument
411 if (this->dma_chans[i]) { in release_dma_channels()
412 dma_release_channel(this->dma_chans[i]); in release_dma_channels()
413 this->dma_chans[i] = NULL; in release_dma_channels()
417 static int __devinit acquire_dma_channels(struct gpmi_nand_data *this) in acquire_dma_channels() argument
419 struct platform_device *pdev = this->pdev; in acquire_dma_channels()
420 struct gpmi_nand_platform_data *pdata = this->pdata; in acquire_dma_channels()
421 struct resources *res = &this->resources; in acquire_dma_channels()
435 this->private = r; in acquire_dma_channels()
451 this->dma_data.chan_irq = r_dma->start; in acquire_dma_channels()
453 this->dma_data.chan_irq = NO_IRQ; in acquire_dma_channels()
455 this->dma_data.chan_irq = r_dma->start + (i - r->start); in acquire_dma_channels()
457 dma_chan = dma_request_channel(mask, gpmi_dma_filter, this); in acquire_dma_channels()
462 this->dma_chans[i - r->start] = dma_chan; in acquire_dma_channels()
471 release_dma_channels(this); in acquire_dma_channels()
475 static int __devinit acquire_resources(struct gpmi_nand_data *this) in acquire_resources() argument
477 struct resources *res = &this->resources; in acquire_resources()
480 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME); in acquire_resources()
484 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME); in acquire_resources()
488 ret = acquire_bch_irq(this, bch_irq); in acquire_resources()
492 ret = acquire_dma_channels(this); in acquire_resources()
496 res->clock = clk_get(&this->pdev->dev, NULL); in acquire_resources()
505 release_dma_channels(this); in acquire_resources()
507 release_bch_irq(this); in acquire_resources()
509 release_register_block(this); in acquire_resources()
513 static void release_resources(struct gpmi_nand_data *this) in release_resources() argument
515 struct resources *r = &this->resources; in release_resources()
518 release_register_block(this); in release_resources()
519 release_bch_irq(this); in release_resources()
520 release_dma_channels(this); in release_resources()
523 static int __devinit init_hardware(struct gpmi_nand_data *this) in init_hardware() argument
528 * This structure contains the "safe" GPMI timing that should succeed in init_hardware()
543 ret = gpmi_init(this); in init_hardware()
547 this->timing = safe_timing; in init_hardware()
551 static int read_page_prepare(struct gpmi_nand_data *this, in read_page_prepare() argument
556 struct device *dev = this->dev; in read_page_prepare()
572 this->direct_dma_map_ok = true; in read_page_prepare()
579 this->direct_dma_map_ok = false; in read_page_prepare()
583 static inline void read_page_end(struct gpmi_nand_data *this, in read_page_end() argument
588 if (this->direct_dma_map_ok) in read_page_end()
589 dma_unmap_single(this->dev, used_phys, length, DMA_FROM_DEVICE); in read_page_end()
592 static inline void read_page_swap_end(struct gpmi_nand_data *this, in read_page_swap_end() argument
597 if (!this->direct_dma_map_ok) in read_page_swap_end()
601 static int send_page_prepare(struct gpmi_nand_data *this, in send_page_prepare() argument
606 struct device *dev = this->dev; in send_page_prepare()
636 static void send_page_end(struct gpmi_nand_data *this, in send_page_end() argument
641 struct device *dev = this->dev; in send_page_end()
646 static void gpmi_free_dma_buffer(struct gpmi_nand_data *this) in gpmi_free_dma_buffer() argument
648 struct device *dev = this->dev; in gpmi_free_dma_buffer()
650 if (this->page_buffer_virt && virt_addr_valid(this->page_buffer_virt)) in gpmi_free_dma_buffer()
651 dma_free_coherent(dev, this->page_buffer_size, in gpmi_free_dma_buffer()
652 this->page_buffer_virt, in gpmi_free_dma_buffer()
653 this->page_buffer_phys); in gpmi_free_dma_buffer()
654 kfree(this->cmd_buffer); in gpmi_free_dma_buffer()
655 kfree(this->data_buffer_dma); in gpmi_free_dma_buffer()
657 this->cmd_buffer = NULL; in gpmi_free_dma_buffer()
658 this->data_buffer_dma = NULL; in gpmi_free_dma_buffer()
659 this->page_buffer_virt = NULL; in gpmi_free_dma_buffer()
660 this->page_buffer_size = 0; in gpmi_free_dma_buffer()
664 static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this) in gpmi_alloc_dma_buffer() argument
666 struct bch_geometry *geo = &this->bch_geometry; in gpmi_alloc_dma_buffer()
667 struct device *dev = this->dev; in gpmi_alloc_dma_buffer()
670 this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA); in gpmi_alloc_dma_buffer()
671 if (this->cmd_buffer == NULL) in gpmi_alloc_dma_buffer()
675 this->data_buffer_dma = kzalloc(PAGE_SIZE, GFP_DMA); in gpmi_alloc_dma_buffer()
676 if (this->data_buffer_dma == NULL) in gpmi_alloc_dma_buffer()
687 this->page_buffer_size = geo->payload_size + geo->auxiliary_size; in gpmi_alloc_dma_buffer()
688 this->page_buffer_virt = dma_alloc_coherent(dev, this->page_buffer_size, in gpmi_alloc_dma_buffer()
689 &this->page_buffer_phys, GFP_DMA); in gpmi_alloc_dma_buffer()
690 if (!this->page_buffer_virt) in gpmi_alloc_dma_buffer()
695 this->payload_virt = this->page_buffer_virt; in gpmi_alloc_dma_buffer()
696 this->payload_phys = this->page_buffer_phys; in gpmi_alloc_dma_buffer()
697 this->auxiliary_virt = this->payload_virt + geo->payload_size; in gpmi_alloc_dma_buffer()
698 this->auxiliary_phys = this->payload_phys + geo->payload_size; in gpmi_alloc_dma_buffer()
702 gpmi_free_dma_buffer(this); in gpmi_alloc_dma_buffer()
710 struct gpmi_nand_data *this = chip->priv; in gpmi_cmd_ctrl() local
726 this->cmd_buffer[this->command_length++] = data; in gpmi_cmd_ctrl()
730 if (!this->command_length) in gpmi_cmd_ctrl()
733 ret = gpmi_send_command(this); in gpmi_cmd_ctrl()
735 pr_err("Chip: %u, Error %d\n", this->current_chip, ret); in gpmi_cmd_ctrl()
737 this->command_length = 0; in gpmi_cmd_ctrl()
743 struct gpmi_nand_data *this = chip->priv; in gpmi_dev_ready() local
745 return gpmi_is_ready(this, this->current_chip); in gpmi_dev_ready()
751 struct gpmi_nand_data *this = chip->priv; in gpmi_select_chip() local
753 if ((this->current_chip < 0) && (chipnr >= 0)) in gpmi_select_chip()
754 gpmi_begin(this); in gpmi_select_chip()
755 else if ((this->current_chip >= 0) && (chipnr < 0)) in gpmi_select_chip()
756 gpmi_end(this); in gpmi_select_chip()
758 this->current_chip = chipnr; in gpmi_select_chip()
764 struct gpmi_nand_data *this = chip->priv; in gpmi_read_buf() local
767 this->upper_buf = buf; in gpmi_read_buf()
768 this->upper_len = len; in gpmi_read_buf()
770 gpmi_read_data(this); in gpmi_read_buf()
776 struct gpmi_nand_data *this = chip->priv; in gpmi_write_buf() local
779 this->upper_buf = (uint8_t *)buf; in gpmi_write_buf()
780 this->upper_len = len; in gpmi_write_buf()
782 gpmi_send_data(this); in gpmi_write_buf()
788 struct gpmi_nand_data *this = chip->priv; in gpmi_read_byte() local
789 uint8_t *buf = this->data_buffer_dma; in gpmi_read_byte()
800 static void block_mark_swapping(struct gpmi_nand_data *this, in block_mark_swapping() argument
803 struct bch_geometry *nfc_geo = &this->bch_geometry; in block_mark_swapping()
811 if (!this->swap_block_mark) in block_mark_swapping()
846 struct gpmi_nand_data *this = chip->priv; in gpmi_ecc_read_page() local
847 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_read_page()
859 ret = read_page_prepare(this, buf, mtd->writesize, in gpmi_ecc_read_page()
860 this->payload_virt, this->payload_phys, in gpmi_ecc_read_page()
868 auxiliary_virt = this->auxiliary_virt; in gpmi_ecc_read_page()
869 auxiliary_phys = this->auxiliary_phys; in gpmi_ecc_read_page()
872 ret = gpmi_read_page(this, payload_phys, auxiliary_phys); in gpmi_ecc_read_page()
873 read_page_end(this, buf, mtd->writesize, in gpmi_ecc_read_page()
874 this->payload_virt, this->payload_phys, in gpmi_ecc_read_page()
883 block_mark_swapping(this, payload_virt, auxiliary_virt); in gpmi_ecc_read_page()
922 read_page_swap_end(this, buf, mtd->writesize, in gpmi_ecc_read_page()
923 this->payload_virt, this->payload_phys, in gpmi_ecc_read_page()
933 struct gpmi_nand_data *this = chip->priv; in gpmi_ecc_write_page() local
934 struct bch_geometry *nfc_geo = &this->bch_geometry; in gpmi_ecc_write_page()
942 if (this->swap_block_mark) { in gpmi_ecc_write_page()
948 memcpy(this->payload_virt, buf, mtd->writesize); in gpmi_ecc_write_page()
949 payload_virt = this->payload_virt; in gpmi_ecc_write_page()
950 payload_phys = this->payload_phys; in gpmi_ecc_write_page()
952 memcpy(this->auxiliary_virt, chip->oob_poi, in gpmi_ecc_write_page()
954 auxiliary_virt = this->auxiliary_virt; in gpmi_ecc_write_page()
955 auxiliary_phys = this->auxiliary_phys; in gpmi_ecc_write_page()
958 block_mark_swapping(this, in gpmi_ecc_write_page()
965 ret = send_page_prepare(this, in gpmi_ecc_write_page()
967 this->payload_virt, this->payload_phys, in gpmi_ecc_write_page()
975 ret = send_page_prepare(this, in gpmi_ecc_write_page()
977 this->auxiliary_virt, this->auxiliary_phys, in gpmi_ecc_write_page()
987 ret = gpmi_send_page(this, payload_phys, auxiliary_phys); in gpmi_ecc_write_page()
991 if (!this->swap_block_mark) { in gpmi_ecc_write_page()
992 send_page_end(this, chip->oob_poi, mtd->oobsize, in gpmi_ecc_write_page()
993 this->auxiliary_virt, this->auxiliary_phys, in gpmi_ecc_write_page()
997 send_page_end(this, buf, mtd->writesize, in gpmi_ecc_write_page()
998 this->payload_virt, this->payload_phys, in gpmi_ecc_write_page()
1005 * There are several places in this driver where we have to handle the OOB and
1006 * block marks. This is the function where things are the most complicated, so
1007 * this is where we try to explain it all. All the other places refer back to
1024 * are OOB. This gives the caller a way to see the actual, physical bytes
1028 * What we do for this specific read operation depends on two questions:
1067 * this driver.
1072 struct gpmi_nand_data *this = chip->priv; in gpmi_ecc_read_oob() local
1087 if (!this->swap_block_mark) { in gpmi_ecc_read_oob()
1094 * Return true, indicating that the next call to this function must send in gpmi_ecc_read_oob()
1107 * MTD_OPS_PLACE_OOB. So We have to implement this function to prohibit in gpmi_ecc_write_oob()
1116 struct gpmi_nand_data *this = chip->priv; in gpmi_block_markbad() local
1133 column = this->swap_block_mark ? mtd->writesize : 0; in gpmi_block_markbad()
1136 block_mark = this->data_buffer_dma; in gpmi_block_markbad()
1158 static int __devinit nand_boot_set_geometry(struct gpmi_nand_data *this) in nand_boot_set_geometry() argument
1160 struct boot_rom_geometry *geometry = &this->rom_geometry; in nand_boot_set_geometry()
1165 * In principle, we should be reading this from the OTP bits, since in nand_boot_set_geometry()
1175 * In principle, we should be reading this from the OTP bits, since in nand_boot_set_geometry()
1185 static int __devinit mx23_check_transcription_stamp(struct gpmi_nand_data *this) in mx23_check_transcription_stamp() argument
1187 struct boot_rom_geometry *rom_geo = &this->rom_geometry; in mx23_check_transcription_stamp()
1188 struct device *dev = this->dev; in mx23_check_transcription_stamp()
1189 struct mtd_info *mtd = &this->mtd; in mx23_check_transcription_stamp()
1190 struct nand_chip *chip = &this->nand; in mx23_check_transcription_stamp()
1202 saved_chip_number = this->current_chip; in mx23_check_transcription_stamp()
1242 static int __devinit mx23_write_transcription_stamp(struct gpmi_nand_data *this) in mx23_write_transcription_stamp() argument
1244 struct device *dev = this->dev; in mx23_write_transcription_stamp()
1245 struct boot_rom_geometry *rom_geo = &this->rom_geometry; in mx23_write_transcription_stamp()
1246 struct mtd_info *mtd = &this->mtd; in mx23_write_transcription_stamp()
1247 struct nand_chip *chip = &this->nand; in mx23_write_transcription_stamp()
1275 saved_chip_number = this->current_chip; in mx23_write_transcription_stamp()
1285 /* Erase this block. */ in mx23_write_transcription_stamp()
1325 static int __devinit mx23_boot_init(struct gpmi_nand_data *this) in mx23_boot_init() argument
1327 struct device *dev = this->dev; in mx23_boot_init()
1328 struct nand_chip *chip = &this->nand; in mx23_boot_init()
1329 struct mtd_info *mtd = &this->mtd; in mx23_boot_init()
1344 if (mx23_check_transcription_stamp(this)) in mx23_boot_init()
1362 * Compute the chip, page and byte addresses for this block's in mx23_boot_init()
1377 * again, but this time the result will be a mark in the in mx23_boot_init()
1390 mx23_write_transcription_stamp(this); in mx23_boot_init()
1394 static int __devinit nand_boot_init(struct gpmi_nand_data *this) in nand_boot_init() argument
1396 nand_boot_set_geometry(this); in nand_boot_init()
1398 /* This is ROM arch-specific initilization before the BBT scanning. */ in nand_boot_init()
1399 if (GPMI_IS_MX23(this)) in nand_boot_init()
1400 return mx23_boot_init(this); in nand_boot_init()
1404 static int __devinit gpmi_set_geometry(struct gpmi_nand_data *this) in gpmi_set_geometry() argument
1409 gpmi_free_dma_buffer(this); in gpmi_set_geometry()
1412 ret = bch_set_geometry(this); in gpmi_set_geometry()
1419 return gpmi_alloc_dma_buffer(this); in gpmi_set_geometry()
1422 static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) in gpmi_pre_bbt_scan() argument
1427 if (GPMI_IS_MX23(this)) in gpmi_pre_bbt_scan()
1428 this->swap_block_mark = false; in gpmi_pre_bbt_scan()
1430 this->swap_block_mark = true; in gpmi_pre_bbt_scan()
1433 ret = gpmi_set_geometry(this); in gpmi_pre_bbt_scan()
1438 return nand_boot_init(this); in gpmi_pre_bbt_scan()
1444 struct gpmi_nand_data *this = chip->priv; in gpmi_scan_bbt() local
1448 ret = gpmi_pre_bbt_scan(this); in gpmi_scan_bbt()
1456 void gpmi_nfc_exit(struct gpmi_nand_data *this) in gpmi_nfc_exit() argument
1458 nand_release(&this->mtd); in gpmi_nfc_exit()
1459 gpmi_free_dma_buffer(this); in gpmi_nfc_exit()
1462 static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this) in gpmi_nfc_init() argument
1464 struct gpmi_nand_platform_data *pdata = this->pdata; in gpmi_nfc_init()
1465 struct mtd_info *mtd = &this->mtd; in gpmi_nfc_init()
1466 struct nand_chip *chip = &this->nand; in gpmi_nfc_init()
1470 this->current_chip = -1; in gpmi_nfc_init()
1478 chip->priv = this; in gpmi_nfc_init()
1498 this->bch_geometry.payload_size = 1024; in gpmi_nfc_init()
1499 this->bch_geometry.auxiliary_size = 128; in gpmi_nfc_init()
1500 ret = gpmi_alloc_dma_buffer(this); in gpmi_nfc_init()
1517 gpmi_nfc_exit(this); in gpmi_nfc_init()
1524 struct gpmi_nand_data *this; in gpmi_nand_probe() local
1527 this = kzalloc(sizeof(*this), GFP_KERNEL); in gpmi_nand_probe()
1528 if (!this) { in gpmi_nand_probe()
1533 platform_set_drvdata(pdev, this); in gpmi_nand_probe()
1534 this->pdev = pdev; in gpmi_nand_probe()
1535 this->dev = &pdev->dev; in gpmi_nand_probe()
1536 this->pdata = pdata; in gpmi_nand_probe()
1544 ret = acquire_resources(this); in gpmi_nand_probe()
1548 ret = init_hardware(this); in gpmi_nand_probe()
1552 ret = gpmi_nfc_init(this); in gpmi_nand_probe()
1559 release_resources(this); in gpmi_nand_probe()
1563 kfree(this); in gpmi_nand_probe()
1569 struct gpmi_nand_data *this = platform_get_drvdata(pdev); in gpmi_nand_remove() local
1571 gpmi_nfc_exit(this); in gpmi_nand_remove()
1572 release_resources(this); in gpmi_nand_remove()
1574 kfree(this); in gpmi_nand_remove()