2 * Copyright (C) 2014 Free Electrons
4 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/err.h>
13 #include <linux/export.h>
14 #include <linux/mtd/rawnand.h>
16 static const struct nand_data_interface onfi_sdr_timings[] = {
19 .type = NAND_SDR_IFACE,
50 .tRST_max = 250000000000ULL,
61 .type = NAND_SDR_IFACE,
92 .tRST_max = 500000000,
103 .type = NAND_SDR_IFACE,
122 .tFEAT_max = 1000000,
133 .tRST_max = 500000000,
145 .type = NAND_SDR_IFACE,
164 .tFEAT_max = 1000000,
176 .tRST_max = 500000000,
187 .type = NAND_SDR_IFACE,
206 .tFEAT_max = 1000000,
218 .tRST_max = 500000000,
229 .type = NAND_SDR_IFACE,
248 .tFEAT_max = 1000000,
260 .tRST_max = 500000000,
272 * onfi_async_timing_mode_to_sdr_timings - [NAND Interface] Retrieve NAND
273 * timings according to the given ONFI timing mode
274 * @mode: ONFI timing mode
276 const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode)
278 if (mode < 0 || mode >= ARRAY_SIZE(onfi_sdr_timings))
279 return ERR_PTR(-EINVAL);
281 return &onfi_sdr_timings[mode].timings.sdr;
283 EXPORT_SYMBOL(onfi_async_timing_mode_to_sdr_timings);
286 * onfi_init_data_interface - [NAND Interface] Initialize a data interface from
288 * @iface: The data interface to be initialized
289 * @mode: The ONFI timing mode
291 int onfi_init_data_interface(struct nand_chip *chip,
292 struct nand_data_interface *iface,
293 enum nand_data_interface_type type,
296 if (type != NAND_SDR_IFACE)
299 if (timing_mode < 0 || timing_mode >= ARRAY_SIZE(onfi_sdr_timings))
302 *iface = onfi_sdr_timings[timing_mode];
305 * Initialize timings that cannot be deduced from timing mode:
306 * tR, tPROG, tCCS, ...
307 * These information are part of the ONFI parameter page.
309 if (chip->onfi_version) {
310 struct nand_onfi_params *params = &chip->onfi_params;
311 struct nand_sdr_timings *timings = &iface->timings.sdr;
313 /* microseconds -> picoseconds */
314 timings->tPROG_max = 1000000UL * le16_to_cpu(params->t_prog);
315 timings->tBERS_max = 1000000UL * le16_to_cpu(params->t_bers);
316 timings->tR_max = 1000000UL * le16_to_cpu(params->t_r);
318 /* nanoseconds -> picoseconds */
319 timings->tCCS_min = 1000UL * le16_to_cpu(params->t_ccs);
324 EXPORT_SYMBOL(onfi_init_data_interface);
327 * nand_get_default_data_interface - [NAND Interface] Retrieve NAND
328 * data interface for mode 0. This is used as default timing after
331 const struct nand_data_interface *nand_get_default_data_interface(void)
333 return &onfi_sdr_timings[0];
335 EXPORT_SYMBOL(nand_get_default_data_interface);