35 .max_dll_clock_period_in_ns = 32,
36 .max_dll_delay_in_ns = 16,
39 #define MXS_SET_ADDR 0x4
40 #define MXS_CLR_ADDR 0x8
60 while ((
readl(addr) & mask) && --timeout)
66 #define MODULE_CLKGATE (1 << 30)
67 #define MODULE_SFTRST (1 << 31)
85 static int gpmi_reset_block(
void __iomem *reset_addr,
bool just_enable)
123 pr_err(
"%s(%p): module reset timeout\n", __func__, reset_addr);
139 ret = clk_prepare_enable(clk);
143 clk_disable_unprepare(clk);
154 #define gpmi_enable_clk(x) __gpmi_enable_clk(x, true)
155 #define gpmi_disable_clk(x) __gpmi_enable_clk(x, false)
165 ret = gpmi_reset_block(r->
gpmi_regs,
false);
196 pr_err(
"Show GPMI registers :\n");
199 pr_err(
"offset 0x%.3x : 0x%.8x\n", i * 0x10, reg);
203 pr_err(
"BCH Geometry :\n");
280 static unsigned int ns_to_cycles(
unsigned int time,
285 k = (time + period - 1) / period;
289 #define DEF_MIN_PROP_DELAY 5
290 #define DEF_MAX_PROP_DELAY 9
292 static int gpmi_nfc_compute_hardware_timing(
struct gpmi_nand_data *
this,
299 bool improved_timing_is_available;
300 unsigned long clock_frequency_in_hz;
301 unsigned int clock_period_in_ns;
302 bool dll_use_half_periods;
303 unsigned int dll_delay_shift;
304 unsigned int max_sample_delay_in_ns;
305 unsigned int address_setup_in_cycles;
307 unsigned int data_setup_in_cycles;
308 unsigned int data_hold_in_cycles;
309 int ideal_sample_delay_in_ns;
310 unsigned int sample_delay_factor;
330 improved_timing_is_available =
338 clock_period_in_ns =
NSEC_PER_SEC / clock_frequency_in_hz;
351 clock_period_in_ns, 1);
353 clock_period_in_ns, 1);
355 clock_period_in_ns, 0);
416 dll_use_half_periods =
true;
417 dll_delay_shift = 3 + 1;
419 dll_use_half_periods =
false;
429 max_sample_delay_in_ns = 0;
435 max_sample_delay_in_ns =
451 if (!improved_timing_is_available) {
469 while ((ideal_sample_delay_in_ns > max_sample_delay_in_ns) &&
472 data_setup_in_cycles++;
473 ideal_sample_delay_in_ns -= clock_period_in_ns;
475 if (ideal_sample_delay_in_ns < 0)
476 ideal_sample_delay_in_ns = 0;
489 sample_delay_factor =
491 ideal_sample_delay_in_ns << dll_delay_shift,
492 clock_period_in_ns, 0);
516 data_setup_in_ns = clock_period_in_ns * data_setup_in_cycles;
528 (
int)data_setup_in_ns;
540 while ((tEYE <= 0) &&
543 data_setup_in_cycles++;
545 data_setup_in_ns += clock_period_in_ns;
547 tEYE += clock_period_in_ns;
560 ideal_sample_delay_in_ns =
561 ((
int)max_prop_delay_in_ns +
563 (
int)min_prop_delay_in_ns +
565 (
int)data_setup_in_ns) >> 1;
604 if (ideal_sample_delay_in_ns < 0)
605 ideal_sample_delay_in_ns = 0;
611 while ((ideal_sample_delay_in_ns > max_sample_delay_in_ns) &&
615 data_setup_in_cycles++;
617 data_setup_in_ns += clock_period_in_ns;
619 tEYE += clock_period_in_ns;
625 ideal_sample_delay_in_ns -= (clock_period_in_ns >> 1);
628 if (ideal_sample_delay_in_ns < 0)
629 ideal_sample_delay_in_ns = 0;
641 sample_delay_factor =
642 ns_to_cycles(ideal_sample_delay_in_ns << dll_delay_shift,
643 clock_period_in_ns, 0);
653 #define IDEAL_DELAY ((int) ideal_sample_delay_in_ns)
655 #define QUANTIZED_DELAY \
656 ((int) ((sample_delay_factor * clock_period_in_ns) >> \
659 #define DELAY_ERROR (abs(QUANTIZED_DELAY - IDEAL_DELAY))
661 #define SAMPLE_IS_NOT_WITHIN_THE_EYE (DELAY_ERROR > (tEYE >> 1))
670 (data_setup_in_cycles < nfc->max_data_setup_cycles)) {
682 if (sample_delay_factor != 0)
683 sample_delay_factor--;
694 data_setup_in_cycles++;
696 data_setup_in_ns += clock_period_in_ns;
698 tEYE += clock_period_in_ns;
704 ideal_sample_delay_in_ns -= (clock_period_in_ns >> 1);
707 ideal_sample_delay_in_ns -= clock_period_in_ns;
710 if (ideal_sample_delay_in_ns < 0)
711 ideal_sample_delay_in_ns = 0;
717 sample_delay_factor =
719 ideal_sample_delay_in_ns << dll_delay_shift,
720 clock_period_in_ns, 0);
828 int mode = this->timing_mode;
829 int dll_threshold = 16;
831 unsigned long clk_period;
863 t_rea = ((mode == 5) ? 16 : 20) * 10;
866 t_rp = clk_period * 1;
868 if (clk_period > dll_threshold) {
880 delay = (((t_rea + c - t_rp) * 8) * 10) / rp;
881 delay = (delay + 5) / 10;
908 if (ret || feature[0] != mode)
914 rate = (mode == 5) ? 100000000 : 80000000;
921 this->timing_mode =
mode;
922 dev_info(this->
dev,
"enable the asynchronous EDO mode %d\n", mode);
927 dev_err(this->
dev,
"mode:%d ,failed in set feature.\n", mode);
937 int mode = onfi_get_async_timing_mode(chip);
947 return enable_edo_mode(
this, mode);
957 unsigned int clock_period_in_ns;
959 unsigned int dll_wait_time_in_us;
966 pr_err(
"We failed in enable the clk\n");
976 gpmi_compute_edo_timing(
this, &hw);
978 gpmi_nfc_compute_hardware_timing(
this, &hw);
1024 dll_wait_time_in_us = (clock_period_in_ns * 64) / 1000;
1026 if (!dll_wait_time_in_us)
1027 dll_wait_time_in_us = 1;
1030 udelay(dll_wait_time_in_us);
1063 pr_err(
"unknow arch.\n");
1070 this->last_dma_type = this->
dma_type;
1079 int chip = this->current_chip;
1090 pio[1] = pio[2] = 0;
1091 desc = dmaengine_prep_slave_sg(channel,
1095 pr_err(
"step 1 error\n");
1100 sgl = &this->cmd_sgl;
1102 sg_init_one(sgl, this->cmd_buffer, this->command_length);
1104 desc = dmaengine_prep_slave_sg(channel,
1109 pr_err(
"step 2 error\n");
1122 int chip = this->current_chip;
1138 desc = dmaengine_prep_slave_sg(channel, (
struct scatterlist *)pio,
1141 pr_err(
"step 1 error\n");
1147 desc = dmaengine_prep_slave_sg(channel, &this->data_sgl,
1151 pr_err(
"step 2 error\n");
1163 int chip = this->current_chip;
1174 desc = dmaengine_prep_slave_sg(channel,
1178 pr_err(
"step 1 error\n");
1184 desc = dmaengine_prep_slave_sg(channel, &this->data_sgl,
1188 pr_err(
"step 2 error\n");
1207 int chip = this->current_chip;
1231 desc = dmaengine_prep_slave_sg(channel,
1236 pr_err(
"step 2 error\n");
1253 int chip = this->current_chip;
1267 desc = dmaengine_prep_slave_sg(channel,
1271 pr_err(
"step 1 error\n");
1296 desc = dmaengine_prep_slave_sg(channel,
1301 pr_err(
"step 2 error\n");
1317 desc = dmaengine_prep_slave_sg(channel,
1322 pr_err(
"step 3 error\n");