2 * Freescale GPMI NFC NAND Flash Driver
4 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
5 * Copyright (C) 2008 Embedded Alley Solutions, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "gpmi-regs-mx50.h"
23 #include "bch-regs-mx50.h"
25 #define FEATURE_SIZE 4 /* p1, p2, p3, p4 */
26 #define NAND_CMD_SET_FEATURE 0xef
29 * How many clocks do we need in low power mode?
30 * We try to list them :
31 * GMPI : gpmi_apb_clk, gpmi_io_clk
32 * BCH : bch_clk, bch_apb_clk
33 * DMA(RAM) : apbh_dma_clk, ddr_clk(RAM), ahb_max_clk(RAM)
34 * (APBHDMA fetches DMA descriptors from DDR
35 * through AHB-MAX/PL301)
37 * ONFI NAND : pll1_main_clk
39 static struct clk *ddr_clk;
40 static struct clk *ahb_max_clk;
42 static void setup_ddr_timing_onfi(struct gpmi_nfc_data *this)
45 struct resources *resources = &this->resources;
47 /* set timing 2 register */
48 value = BF_GPMI_TIMING2_DATA_PAUSE(0x6)
49 | BF_GPMI_TIMING2_CMDADD_PAUSE(0x4)
50 | BF_GPMI_TIMING2_POSTAMBLE_DELAY(0x2)
51 | BF_GPMI_TIMING2_PREAMBLE_DELAY(0x4)
52 | BF_GPMI_TIMING2_CE_DELAY(0x2)
53 | BF_GPMI_TIMING2_READ_LATENCY(0x2);
55 __raw_writel(value, resources->gpmi_regs + HW_GPMI_TIMING2);
57 /* set timing 1 register */
58 __raw_writel(BF_GPMI_TIMING1_DEVICE_BUSY_TIMEOUT(0x500),
59 resources->gpmi_regs + HW_GPMI_TIMING1);
61 /* Put GPMI in NAND mode, disable device reset, and make certain
62 IRQRDY polarity is active high. */
63 value = BV_GPMI_CTRL1_GPMI_MODE__NAND
64 | BM_GPMI_CTRL1_GANGED_RDYBUSY
65 | BF_GPMI_CTRL1_WRN_DLY_SEL(0x3)
66 | (BV_GPMI_CTRL1_DEV_RESET__DISABLED << 3)
67 | (BV_GPMI_CTRL1_ATA_IRQRDY_POLARITY__ACTIVEHIGH << 2);
69 __raw_writel(value, resources->gpmi_regs + HW_GPMI_CTRL1_SET);
72 /* This must be called in the context of enabling necessary clocks */
73 static void common_ddr_init(struct resources *resources)
77 /* [6] enable both write & read DDR DLLs */
78 value = BM_GPMI_READ_DDR_DLL_CTRL_REFCLK_ON |
79 BM_GPMI_READ_DDR_DLL_CTRL_ENABLE |
80 BF_GPMI_READ_DDR_DLL_CTRL_SLV_UPDATE_INT(0x2) |
81 BF_GPMI_READ_DDR_DLL_CTRL_SLV_DLY_TARGET(0x7);
83 __raw_writel(value, resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
86 __raw_writel(value | BM_GPMI_READ_DDR_DLL_CTRL_RESET,
87 resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
88 value = value & ~BM_GPMI_READ_DDR_DLL_CTRL_RESET;
89 __raw_writel(value, resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
91 value = BM_GPMI_WRITE_DDR_DLL_CTRL_REFCLK_ON |
92 BM_GPMI_WRITE_DDR_DLL_CTRL_ENABLE |
93 BF_GPMI_WRITE_DDR_DLL_CTRL_SLV_UPDATE_INT(0x2) |
94 BF_GPMI_WRITE_DDR_DLL_CTRL_SLV_DLY_TARGET(0x7) ,
96 __raw_writel(value, resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
99 __raw_writel(value | BM_GPMI_WRITE_DDR_DLL_CTRL_RESET,
100 resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
101 __raw_writel(value, resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
103 /* [9] wait for locks for read and write */
105 uint32_t read_status, write_status;
106 uint32_t r_mask, w_mask;
108 read_status = __raw_readl(resources->gpmi_regs
109 + HW_GPMI_READ_DDR_DLL_STS);
110 write_status = __raw_readl(resources->gpmi_regs
111 + HW_GPMI_WRITE_DDR_DLL_STS);
113 r_mask = (BM_GPMI_READ_DDR_DLL_STS_REF_LOCK |
114 BM_GPMI_READ_DDR_DLL_STS_SLV_LOCK);
115 w_mask = (BM_GPMI_WRITE_DDR_DLL_STS_REF_LOCK |
116 BM_GPMI_WRITE_DDR_DLL_STS_SLV_LOCK);
118 if (((read_status & r_mask) == r_mask)
119 && ((write_status & w_mask) == w_mask))
123 /* [10] force update of read/write */
124 value = __raw_readl(resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
125 __raw_writel(value | BM_GPMI_READ_DDR_DLL_CTRL_SLV_FORCE_UPD,
126 resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
127 __raw_writel(value, resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
129 value = __raw_readl(resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
130 __raw_writel(value | BM_GPMI_WRITE_DDR_DLL_CTRL_SLV_FORCE_UPD,
131 resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
132 __raw_writel(value, resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
134 /* [11] set gate update */
135 value = __raw_readl(resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
136 value |= BM_GPMI_READ_DDR_DLL_CTRL_GATE_UPDATE;
137 __raw_writel(value, resources->gpmi_regs + HW_GPMI_READ_DDR_DLL_CTRL);
139 value = __raw_readl(resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
140 value |= BM_GPMI_WRITE_DDR_DLL_CTRL_GATE_UPDATE;
141 __raw_writel(value, resources->gpmi_regs + HW_GPMI_WRITE_DDR_DLL_CTRL);
144 static int enable_ddr_onfi(struct gpmi_nfc_data *this)
146 struct resources *resources = &this->resources;
147 struct mil *mil = &this->mil;
148 struct nand_chip *nand = &this->mil.nand;
149 struct mtd_info *mtd = &mil->mtd;
150 int saved_chip_number = 0;
151 uint8_t device_feature[FEATURE_SIZE];
152 int mode = 0;/* there is 5 mode available, default is 0 */
154 saved_chip_number = mil->current_chip;
155 nand->select_chip(mtd, 0);
157 /* [0] set proper timing */
158 __raw_writel(BF_GPMI_TIMING0_ADDRESS_SETUP(0x1)
159 | BF_GPMI_TIMING0_DATA_HOLD(0x3)
160 | BF_GPMI_TIMING0_DATA_SETUP(0x3),
161 resources->gpmi_regs + HW_GPMI_TIMING0);
163 /* [1] send SET FEATURE commond to NAND */
164 memset(device_feature, 0, sizeof(device_feature));
165 device_feature[0] = (0x1 << 4) | (mode & 0x7);
167 nand->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
168 nand->cmdfunc(mtd, NAND_CMD_SET_FEATURE, 1, -1);
169 nand->write_buf(mtd, device_feature, FEATURE_SIZE);
171 /* [2] set clk divider */
172 __raw_writel(BM_GPMI_CTRL1_GPMI_CLK_DIV2_EN,
173 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
175 /* [3] about the clock, pay attention! */
176 nand->select_chip(mtd, saved_chip_number);
179 pll1 = clk_get(NULL, "pll1_main_clk");
181 printk(KERN_INFO "No PLL1 clock\n");
184 clk_set_parent(resources->clock, pll1);
185 clk_set_rate(resources->clock, 20000000);
187 nand->select_chip(mtd, 0);
189 /* [4] setup timing */
190 setup_ddr_timing_onfi(this);
192 /* [5] set to SYNC mode */
193 __raw_writel(BM_GPMI_CTRL1_TOGGLE_MODE,
194 resources->gpmi_regs + HW_GPMI_CTRL1_CLR);
195 __raw_writel(BM_GPMI_CTRL1_SSYNCMODE | BM_GPMI_CTRL1_GANGED_RDYBUSY,
196 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
198 /* common DDR initialization */
199 common_ddr_init(resources);
201 nand->select_chip(mtd, saved_chip_number);
203 printk(KERN_INFO "Micron ONFI NAND enters synchronous mode %d\n", mode);
207 static void setup_ddr_timing_toggle(struct gpmi_nfc_data *this)
210 struct resources *resources = &this->resources;
212 /* set timing 2 register */
213 value = BF_GPMI_TIMING2_DATA_PAUSE(0x6)
214 | BF_GPMI_TIMING2_CMDADD_PAUSE(0x4)
215 | BF_GPMI_TIMING2_POSTAMBLE_DELAY(0x3)
216 | BF_GPMI_TIMING2_PREAMBLE_DELAY(0x2)
217 | BF_GPMI_TIMING2_CE_DELAY(0x2)
218 | BF_GPMI_TIMING2_READ_LATENCY(0x2);
220 __raw_writel(value, resources->gpmi_regs + HW_GPMI_TIMING2);
222 /* set timing 1 register */
223 __raw_writel(BF_GPMI_TIMING1_DEVICE_BUSY_TIMEOUT(0x500),
224 resources->gpmi_regs + HW_GPMI_TIMING1);
226 /* Put GPMI in NAND mode, disable device reset, and make certain
227 IRQRDY polarity is active high. */
228 value = BV_GPMI_CTRL1_GPMI_MODE__NAND
229 | BM_GPMI_CTRL1_GANGED_RDYBUSY
230 | (BV_GPMI_CTRL1_DEV_RESET__DISABLED << 3)
231 | (BV_GPMI_CTRL1_ATA_IRQRDY_POLARITY__ACTIVEHIGH << 2);
233 __raw_writel(value, resources->gpmi_regs + HW_GPMI_CTRL1_SET);
236 static int enable_ddr_toggle(struct gpmi_nfc_data *this)
238 struct resources *resources = &this->resources;
239 struct mil *mil = &this->mil;
240 struct nand_chip *nand = &this->mil.nand;
241 struct mtd_info *mtd = &mil->mtd;
242 int saved_chip_number = mil->current_chip;
244 nand->select_chip(mtd, 0);
246 /* [0] set proper timing */
247 __raw_writel(BF_GPMI_TIMING0_ADDRESS_SETUP(0x5)
248 | BF_GPMI_TIMING0_DATA_HOLD(0xa)
249 | BF_GPMI_TIMING0_DATA_SETUP(0xa),
250 resources->gpmi_regs + HW_GPMI_TIMING0);
252 /* [2] set clk divider */
253 __raw_writel(BM_GPMI_CTRL1_GPMI_CLK_DIV2_EN,
254 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
256 /* [3] about the clock, pay attention! */
257 nand->select_chip(mtd, saved_chip_number);
262 pll1 = clk_get(NULL, "pll1_main_clk");
264 printk(KERN_INFO "No PLL1 clock\n");
268 /* toggle nand : 133/66 MHz */
270 clk_set_parent(resources->clock, pll1);
271 clk_set_rate(resources->clock, rate);
273 nand->select_chip(mtd, 0);
275 /* [4] setup timing */
276 setup_ddr_timing_toggle(this);
278 /* [5] set to TOGGLE mode */
279 __raw_writel(BM_GPMI_CTRL1_SSYNCMODE,
280 resources->gpmi_regs + HW_GPMI_CTRL1_CLR);
281 __raw_writel(BM_GPMI_CTRL1_TOGGLE_MODE | BM_GPMI_CTRL1_GANGED_RDYBUSY,
282 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
284 /* common DDR initialization */
285 common_ddr_init(resources);
287 nand->select_chip(mtd, saved_chip_number);
289 printk(KERN_INFO "-- Sumsung TOGGLE NAND is enabled now. --\n");
293 static inline bool is_board_support_ddr(struct gpmi_nfc_data *this)
295 /* Only arm2 board supports the DDR, the rdp board does not. */
299 /* To check if we need to initialize something else*/
300 static int extra_init(struct gpmi_nfc_data *this)
302 /* mx6q do not need the extra clocks, while the mx50 needs. */
303 if (GPMI_IS_MX6Q(this))
306 ddr_clk = clk_get(NULL, "ddr_clk");
307 if (IS_ERR(ddr_clk)) {
308 printk(KERN_ERR "The ddr clock is gone!");
313 ahb_max_clk = clk_get(NULL, "ahb_max_clk");
314 if (IS_ERR(ahb_max_clk)) {
315 printk(KERN_ERR "The APBH_DMA clock is gone!");
320 if (is_board_support_ddr(this)) {
322 return enable_ddr_onfi(this);
324 return enable_ddr_toggle(this);
330 * init() - Initializes the NFC hardware.
332 * @this: Per-device data.
334 static int init(struct gpmi_nfc_data *this)
336 struct resources *resources = &this->resources;
338 /* Enable the clock. */
339 clk_enable(resources->clock);
341 /* Reset the GPMI block. */
342 mxs_reset_block(resources->gpmi_regs + HW_GPMI_CTRL0, true);
344 /* Choose NAND mode. */
345 __raw_writel(BM_GPMI_CTRL1_GPMI_MODE,
346 resources->gpmi_regs + HW_GPMI_CTRL1_CLR);
348 /* Set the IRQ polarity. */
349 __raw_writel(BM_GPMI_CTRL1_ATA_IRQRDY_POLARITY,
350 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
352 /* Disable write protection. */
353 __raw_writel(BM_GPMI_CTRL1_DEV_RESET,
354 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
356 /* Select BCH ECC. */
357 __raw_writel(BM_GPMI_CTRL1_BCH_MODE,
358 resources->gpmi_regs + HW_GPMI_CTRL1_SET);
360 /* Disable the clock. */
361 clk_disable(resources->clock);
367 * set_geometry() - Configures the NFC geometry.
369 * @this: Per-device data.
371 static int set_geometry(struct gpmi_nfc_data *this)
373 struct resources *resources = &this->resources;
374 struct nfc_geometry *nfc = &this->nfc_geometry;
375 unsigned int block_count;
376 unsigned int block_size;
377 unsigned int metadata_size;
378 unsigned int ecc_strength;
379 unsigned int page_size;
382 /* We make the abstract choices in a common function. */
383 if (common_nfc_set_geometry(this))
386 /* Translate the abstract choices into register fields. */
387 block_count = nfc->ecc_chunk_count - 1;
388 block_size = nfc->ecc_chunk_size_in_bytes >> 2;
389 metadata_size = nfc->metadata_size_in_bytes;
390 ecc_strength = nfc->ecc_strength >> 1;
391 page_size = nfc->page_size_in_bytes;
393 /* Enable the clock. */
394 clk_enable(resources->clock);
397 * Reset the BCH block. Notice that we pass in true for the just_enable
398 * flag. This is because the soft reset for the version 0 BCH block
399 * doesn't work and the version 1 BCH block is similar enough that we
400 * suspect the same (though this has not been officially tested). If you
401 * try to soft reset a version 0 BCH block, it becomes unusable until
402 * the next hard reset.
404 mxs_reset_block(resources->bch_regs, false);
406 /* Configure layout 0. */
407 value = BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count) |
408 BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size) |
409 BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength) |
410 BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size);
411 if (is_ddr_nand(this))
412 value |= BM_BCH_FLASH0LAYOUT0_GF13_0_GF14_1;
414 __raw_writel(value, resources->bch_regs + HW_BCH_FLASH0LAYOUT0);
416 value = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) |
417 BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength) |
418 BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size);
419 if (is_ddr_nand(this))
420 value |= BM_BCH_FLASH0LAYOUT1_GF13_0_GF14_1;
422 __raw_writel(value, resources->bch_regs + HW_BCH_FLASH0LAYOUT1);
424 /* Set *all* chip selects to use layout 0. */
425 __raw_writel(0, resources->bch_regs + HW_BCH_LAYOUTSELECT);
427 /* Enable interrupts. */
428 __raw_writel(BM_BCH_CTRL_COMPLETE_IRQ_EN,
429 resources->bch_regs + HW_BCH_CTRL_SET);
431 /* Disable the clock. */
432 clk_disable(resources->clock);
438 * set_timing() - Configures the NFC timing.
440 * @this: Per-device data.
441 * @timing: The timing of interest.
443 static int set_timing(struct gpmi_nfc_data *this,
444 const struct nand_timing *timing)
446 struct nfc_hal *nfc = this->nfc;
448 /* Accept the new timing. */
449 nfc->timing = *timing;
454 * get_timing() - Retrieves the NFC hardware timing.
456 * @this: Per-device data.
457 * @clock_frequency_in_hz: The clock frequency, in Hz, during the current
458 * I/O transaction. If no I/O transaction is in
459 * progress, this is the clock frequency during the
460 * most recent I/O transaction.
461 * @hardware_timing: The hardware timing configuration in effect during
462 * the current I/O transaction. If no I/O transaction
463 * is in progress, this is the hardware timing
464 * configuration during the most recent I/O
467 static void get_timing(struct gpmi_nfc_data *this,
468 unsigned long *clock_frequency_in_hz,
469 struct gpmi_nfc_hardware_timing *hardware_timing)
471 struct resources *resources = &this->resources;
472 struct nfc_hal *nfc = this->nfc;
473 unsigned char *gpmi_regs = resources->gpmi_regs;
474 uint32_t register_image;
476 /* Return the clock frequency. */
477 *clock_frequency_in_hz = nfc->clock_frequency_in_hz;
479 /* We'll be reading the hardware, so let's enable the clock. */
480 clk_enable(resources->clock);
482 /* Retrieve the hardware timing. */
483 register_image = __raw_readl(gpmi_regs + HW_GPMI_TIMING0);
485 hardware_timing->data_setup_in_cycles =
486 (register_image & BM_GPMI_TIMING0_DATA_SETUP) >>
487 BP_GPMI_TIMING0_DATA_SETUP;
489 hardware_timing->data_hold_in_cycles =
490 (register_image & BM_GPMI_TIMING0_DATA_HOLD) >>
491 BP_GPMI_TIMING0_DATA_HOLD;
493 hardware_timing->address_setup_in_cycles =
494 (register_image & BM_GPMI_TIMING0_ADDRESS_SETUP) >>
495 BP_GPMI_TIMING0_ADDRESS_SETUP;
497 register_image = __raw_readl(gpmi_regs + HW_GPMI_CTRL1);
499 hardware_timing->use_half_periods =
500 (register_image & BM_GPMI_CTRL1_HALF_PERIOD) >>
501 BP_GPMI_CTRL1_HALF_PERIOD;
503 hardware_timing->sample_delay_factor =
504 (register_image & BM_GPMI_CTRL1_RDN_DELAY) >>
505 BP_GPMI_CTRL1_RDN_DELAY;
507 /* We're done reading the hardware, so disable the clock. */
508 clk_disable(resources->clock);
511 static void exit(struct gpmi_nfc_data *this)
515 static void begin(struct gpmi_nfc_data *this)
517 struct resources *resources = &this->resources;
518 struct nfc_hal *nfc = this->nfc;
519 struct gpmi_nfc_hardware_timing hw;
521 /* Enable the clock. */
525 clk_enable(ahb_max_clk);
526 clk_enable(resources->clock);
528 /* Get the timing information we need. */
529 nfc->clock_frequency_in_hz = clk_get_rate(resources->clock);
530 gpmi_nfc_compute_hardware_timing(this, &hw);
532 /* Apply the hardware timing. */
534 /* Coming soon - the clock handling code isn't ready yet. */
539 * end() - End NFC I/O.
541 * @this: Per-device data.
543 static void end(struct gpmi_nfc_data *this)
545 struct resources *resources = &this->resources;
547 clk_disable(resources->clock);
549 clk_disable(ahb_max_clk);
551 clk_disable(ddr_clk);
555 * clear_bch() - Clears a BCH interrupt.
557 * @this: Per-device data.
559 static void clear_bch(struct gpmi_nfc_data *this)
561 struct resources *resources = &this->resources;
562 __raw_writel(BM_BCH_CTRL_COMPLETE_IRQ,
563 resources->bch_regs + HW_BCH_CTRL_CLR);
567 * is_ready() - Returns the ready/busy status of the given chip.
569 * @this: Per-device data.
570 * @chip: The chip of interest.
572 static int is_ready(struct gpmi_nfc_data *this, unsigned chip)
574 struct resources *resources = &this->resources;
576 uint32_t register_image;
578 /* Extract and return the status. */
579 mask = BF_GPMI_STAT_READY_BUSY(1 << 0);
580 register_image = __raw_readl(resources->gpmi_regs + HW_GPMI_STAT);
581 return !!(register_image & mask);
584 /* The DMA may need the NAND-LOCK bit set to work properly. */
585 static int send_command(struct gpmi_nfc_data *this)
587 struct dma_chan *channel = get_dma_chan(this);
588 struct mil *mil = &this->mil;
589 struct dma_async_tx_descriptor *desc;
590 struct scatterlist *sgl;
593 /* [1] send out the PIO words */
594 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(BV_GPMI_CTRL0_COMMAND_MODE__WRITE)
595 | BM_GPMI_CTRL0_WORD_LENGTH
596 | BF_GPMI_CTRL0_CS(mil->current_chip)
597 | BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_CLE)
598 | BM_GPMI_CTRL0_ADDRESS_INCREMENT
599 | BF_GPMI_CTRL0_XFER_COUNT(mil->command_length);
601 desc = channel->device->device_prep_slave_sg(channel,
602 (struct scatterlist *)pio,
603 ARRAY_SIZE(pio), DMA_NONE, 0);
605 pr_info("step 1 error");
609 /* [2] send out the COMMAND + ADDRESS string stored in @buffer */
612 sg_init_one(sgl, mil->cmd_buffer, mil->command_length);
613 dma_map_sg(this->dev, sgl, 1, DMA_TO_DEVICE);
614 desc = channel->device->device_prep_slave_sg(channel,
615 sgl, 1, DMA_TO_DEVICE, 1);
621 /* [3] submit the DMA */
622 this->dma_type = DMA_FOR_COMMAND;
623 start_dma_without_bch_irq(this, desc);
627 static int send_data(struct gpmi_nfc_data *this)
629 struct dma_async_tx_descriptor *desc;
630 struct dma_chan *channel = get_dma_chan(this);
631 struct mil *mil = &this->mil;
632 uint32_t command_mode;
637 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WRITE;
638 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
640 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
641 | BM_GPMI_CTRL0_WORD_LENGTH
642 | BF_GPMI_CTRL0_CS(mil->current_chip)
643 | BF_GPMI_CTRL0_ADDRESS(address)
644 | BF_GPMI_CTRL0_XFER_COUNT(mil->upper_len);
646 desc = channel->device->device_prep_slave_sg(channel,
647 (struct scatterlist *)pio,
648 ARRAY_SIZE(pio), DMA_NONE, 0);
650 pr_info("step 1 error");
654 /* [2] send DMA request */
655 prepare_data_dma(this, DMA_TO_DEVICE);
656 desc = channel->device->device_prep_slave_sg(channel, &mil->data_sgl,
657 1, DMA_TO_DEVICE, 1);
659 pr_info("step 2 error");
662 /* [3] submit the DMA */
663 this->dma_type = DMA_FOR_WRITE_DATA;
664 start_dma_without_bch_irq(this, desc);
668 static int read_data(struct gpmi_nfc_data *this)
670 struct dma_async_tx_descriptor *desc;
671 struct dma_chan *channel = get_dma_chan(this);
672 struct mil *mil = &this->mil;
676 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(BV_GPMI_CTRL0_COMMAND_MODE__READ)
677 | BM_GPMI_CTRL0_WORD_LENGTH
678 | BF_GPMI_CTRL0_CS(mil->current_chip)
679 | BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_DATA)
680 | BF_GPMI_CTRL0_XFER_COUNT(mil->upper_len);
682 desc = channel->device->device_prep_slave_sg(channel,
683 (struct scatterlist *)pio,
684 ARRAY_SIZE(pio), DMA_NONE, 0);
686 pr_info("step 1 error");
690 /* [2] : send DMA request */
691 prepare_data_dma(this, DMA_FROM_DEVICE);
692 desc = channel->device->device_prep_slave_sg(channel, &mil->data_sgl,
693 1, DMA_FROM_DEVICE, 1);
695 pr_info("step 2 error");
699 /* [3] : submit the DMA */
700 this->dma_type = DMA_FOR_READ_DATA;
701 start_dma_without_bch_irq(this, desc);
705 static int send_page(struct gpmi_nfc_data *this,
706 dma_addr_t payload, dma_addr_t auxiliary)
708 struct nfc_geometry *geo = &this->nfc_geometry;
709 uint32_t command_mode;
711 uint32_t ecc_command;
712 uint32_t buffer_mask;
715 struct dma_async_tx_descriptor *desc;
716 struct dma_chan *channel = get_dma_chan(this);
717 struct mil *mil = &this->mil;
718 int chip = mil->current_chip;
721 /* DDR use the 16-bit for DATA transmission! */
722 if (is_board_support_ddr(this) && is_ddr_nand(this)) {
723 busw = BV_GPMI_CTRL0_WORD_LENGTH__16_BIT;
724 page_size = geo->page_size_in_bytes >> 1;
726 busw = BM_GPMI_CTRL0_WORD_LENGTH;
727 page_size = geo->page_size_in_bytes;
730 /* A DMA descriptor that does an ECC page read. */
731 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WRITE;
732 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
733 ecc_command = BV_GPMI_ECCCTRL_ECC_CMD__BCH_ENCODE;
734 buffer_mask = BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_PAGE |
735 BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_AUXONLY;
737 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
739 | BF_GPMI_CTRL0_CS(chip)
740 | BF_GPMI_CTRL0_ADDRESS(address)
741 | BF_GPMI_CTRL0_XFER_COUNT(0);
743 pio[2] = BM_GPMI_ECCCTRL_ENABLE_ECC
744 | BF_GPMI_ECCCTRL_ECC_CMD(ecc_command)
745 | BF_GPMI_ECCCTRL_BUFFER_MASK(buffer_mask);
750 desc = channel->device->device_prep_slave_sg(channel,
751 (struct scatterlist *)pio,
752 ARRAY_SIZE(pio), DMA_NONE, 0);
754 pr_info("step 2 error");
757 this->dma_type = DMA_FOR_WRITE_ECC_PAGE;
758 return start_dma_with_bch_irq(this, desc);
761 static int read_page(struct gpmi_nfc_data *this,
762 dma_addr_t payload, dma_addr_t auxiliary)
764 struct nfc_geometry *geo = &this->nfc_geometry;
765 uint32_t command_mode;
767 uint32_t ecc_command;
768 uint32_t buffer_mask;
771 struct dma_async_tx_descriptor *desc;
772 struct dma_chan *channel = get_dma_chan(this);
773 struct mil *mil = &this->mil;
774 int chip = mil->current_chip;
777 /* DDR use the 16-bit for DATA transmission! */
778 if (is_board_support_ddr(this) && is_ddr_nand(this)) {
779 busw = BV_GPMI_CTRL0_WORD_LENGTH__16_BIT;
780 page_size = geo->page_size_in_bytes >> 1;
782 busw = BM_GPMI_CTRL0_WORD_LENGTH;
783 page_size = geo->page_size_in_bytes;
786 /* [1] Wait for the chip to report ready. */
787 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WAIT_FOR_READY;
788 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
790 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
792 | BF_GPMI_CTRL0_CS(chip)
793 | BF_GPMI_CTRL0_ADDRESS(address)
794 | BF_GPMI_CTRL0_XFER_COUNT(0);
796 desc = channel->device->device_prep_slave_sg(channel,
797 (struct scatterlist *)pio, 2, DMA_NONE, 0);
799 pr_info("step 1 error");
803 /* [2] Enable the BCH block and read. */
804 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__READ;
805 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
806 ecc_command = BV_GPMI_ECCCTRL_ECC_CMD__BCH_DECODE;
807 buffer_mask = BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_PAGE
808 | BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_AUXONLY;
810 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
812 | BF_GPMI_CTRL0_CS(chip)
813 | BF_GPMI_CTRL0_ADDRESS(address)
814 | BF_GPMI_CTRL0_XFER_COUNT(page_size);
817 pio[2] = BM_GPMI_ECCCTRL_ENABLE_ECC
818 | BF_GPMI_ECCCTRL_ECC_CMD(ecc_command)
819 | BF_GPMI_ECCCTRL_BUFFER_MASK(buffer_mask);
823 desc = channel->device->device_prep_slave_sg(channel,
824 (struct scatterlist *)pio,
825 ARRAY_SIZE(pio), DMA_NONE, 1);
827 pr_info("step 2 error");
831 /* [3] Disable the BCH block */
832 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WAIT_FOR_READY;
833 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
835 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
837 | BF_GPMI_CTRL0_CS(chip)
838 | BF_GPMI_CTRL0_ADDRESS(address)
839 | BF_GPMI_CTRL0_XFER_COUNT(page_size);
841 desc = channel->device->device_prep_slave_sg(channel,
842 (struct scatterlist *)pio, 2, DMA_NONE, 1);
844 pr_info("step 3 error");
848 /* [4] submit the DMA */
849 this->dma_type = DMA_FOR_READ_ECC_PAGE;
850 return start_dma_with_bch_irq(this, desc);
853 /* This structure represents the NFC HAL for this version of the hardware. */
854 struct nfc_hal gpmi_nfc_hal_mx50 = {
855 .description = "8-chip GPMI and BCH",
857 .max_data_setup_cycles = (BM_GPMI_TIMING0_DATA_SETUP >>
858 BP_GPMI_TIMING0_DATA_SETUP),
859 .internal_data_setup_in_ns = 0,
860 .max_sample_delay_factor = (BM_GPMI_CTRL1_RDN_DELAY >>
861 BP_GPMI_CTRL1_RDN_DELAY),
862 .max_dll_clock_period_in_ns = 32,
863 .max_dll_delay_in_ns = 16,
865 .extra_init = extra_init,
866 .set_geometry = set_geometry,
867 .set_timing = set_timing,
868 .get_timing = get_timing,
872 .clear_bch = clear_bch,
873 .is_ready = is_ready,
874 .send_command = send_command,
875 .send_data = send_data,
876 .read_data = read_data,
877 .send_page = send_page,
878 .read_page = read_page,