18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
48c2ecf20Sopenharmony_ci *		  2002-2006 Thomas Gleixner (tglx@linutronix.de)
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci *  Credits:
78c2ecf20Sopenharmony_ci *	David Woodhouse for adding multichip support
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *	Aleph One Ltd. and Toby Churchill Ltd. for supporting the
108c2ecf20Sopenharmony_ci *	rework for 2K page size chips
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * This file contains all ONFI helpers.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/slab.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "internals.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define ONFI_PARAM_PAGES 3
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciu16 onfi_crc16(u16 crc, u8 const *p, size_t len)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	int i;
248c2ecf20Sopenharmony_ci	while (len--) {
258c2ecf20Sopenharmony_ci		crc ^= *p++ << 8;
268c2ecf20Sopenharmony_ci		for (i = 0; i < 8; i++)
278c2ecf20Sopenharmony_ci			crc = (crc << 1) ^ ((crc & 0x8000) ? 0x8005 : 0);
288c2ecf20Sopenharmony_ci	}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	return crc;
318c2ecf20Sopenharmony_ci}
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* Parse the Extended Parameter Page. */
348c2ecf20Sopenharmony_cistatic int nand_flash_detect_ext_param_page(struct nand_chip *chip,
358c2ecf20Sopenharmony_ci					    struct nand_onfi_params *p)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	struct nand_device *base = &chip->base;
388c2ecf20Sopenharmony_ci	struct nand_ecc_props requirements;
398c2ecf20Sopenharmony_ci	struct onfi_ext_param_page *ep;
408c2ecf20Sopenharmony_ci	struct onfi_ext_section *s;
418c2ecf20Sopenharmony_ci	struct onfi_ext_ecc_info *ecc;
428c2ecf20Sopenharmony_ci	uint8_t *cursor;
438c2ecf20Sopenharmony_ci	int ret;
448c2ecf20Sopenharmony_ci	int len;
458c2ecf20Sopenharmony_ci	int i;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	len = le16_to_cpu(p->ext_param_page_length) * 16;
488c2ecf20Sopenharmony_ci	ep = kmalloc(len, GFP_KERNEL);
498c2ecf20Sopenharmony_ci	if (!ep)
508c2ecf20Sopenharmony_ci		return -ENOMEM;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	/*
538c2ecf20Sopenharmony_ci	 * Use the Change Read Column command to skip the ONFI param pages and
548c2ecf20Sopenharmony_ci	 * ensure we read at the right location.
558c2ecf20Sopenharmony_ci	 */
568c2ecf20Sopenharmony_ci	ret = nand_change_read_column_op(chip,
578c2ecf20Sopenharmony_ci					 sizeof(*p) * p->num_of_param_pages,
588c2ecf20Sopenharmony_ci					 ep, len, true);
598c2ecf20Sopenharmony_ci	if (ret)
608c2ecf20Sopenharmony_ci		goto ext_out;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	ret = -EINVAL;
638c2ecf20Sopenharmony_ci	if ((onfi_crc16(ONFI_CRC_BASE, ((uint8_t *)ep) + 2, len - 2)
648c2ecf20Sopenharmony_ci		!= le16_to_cpu(ep->crc))) {
658c2ecf20Sopenharmony_ci		pr_debug("fail in the CRC.\n");
668c2ecf20Sopenharmony_ci		goto ext_out;
678c2ecf20Sopenharmony_ci	}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	/*
708c2ecf20Sopenharmony_ci	 * Check the signature.
718c2ecf20Sopenharmony_ci	 * Do not strictly follow the ONFI spec, maybe changed in future.
728c2ecf20Sopenharmony_ci	 */
738c2ecf20Sopenharmony_ci	if (strncmp(ep->sig, "EPPS", 4)) {
748c2ecf20Sopenharmony_ci		pr_debug("The signature is invalid.\n");
758c2ecf20Sopenharmony_ci		goto ext_out;
768c2ecf20Sopenharmony_ci	}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	/* find the ECC section. */
798c2ecf20Sopenharmony_ci	cursor = (uint8_t *)(ep + 1);
808c2ecf20Sopenharmony_ci	for (i = 0; i < ONFI_EXT_SECTION_MAX; i++) {
818c2ecf20Sopenharmony_ci		s = ep->sections + i;
828c2ecf20Sopenharmony_ci		if (s->type == ONFI_SECTION_TYPE_2)
838c2ecf20Sopenharmony_ci			break;
848c2ecf20Sopenharmony_ci		cursor += s->length * 16;
858c2ecf20Sopenharmony_ci	}
868c2ecf20Sopenharmony_ci	if (i == ONFI_EXT_SECTION_MAX) {
878c2ecf20Sopenharmony_ci		pr_debug("We can not find the ECC section.\n");
888c2ecf20Sopenharmony_ci		goto ext_out;
898c2ecf20Sopenharmony_ci	}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	/* get the info we want. */
928c2ecf20Sopenharmony_ci	ecc = (struct onfi_ext_ecc_info *)cursor;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	if (!ecc->codeword_size) {
958c2ecf20Sopenharmony_ci		pr_debug("Invalid codeword size\n");
968c2ecf20Sopenharmony_ci		goto ext_out;
978c2ecf20Sopenharmony_ci	}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	requirements.strength = ecc->ecc_bits;
1008c2ecf20Sopenharmony_ci	requirements.step_size = 1 << ecc->codeword_size;
1018c2ecf20Sopenharmony_ci	nanddev_set_ecc_requirements(base, &requirements);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	ret = 0;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ciext_out:
1068c2ecf20Sopenharmony_ci	kfree(ep);
1078c2ecf20Sopenharmony_ci	return ret;
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/*
1118c2ecf20Sopenharmony_ci * Recover data with bit-wise majority
1128c2ecf20Sopenharmony_ci */
1138c2ecf20Sopenharmony_cistatic void nand_bit_wise_majority(const void **srcbufs,
1148c2ecf20Sopenharmony_ci				   unsigned int nsrcbufs,
1158c2ecf20Sopenharmony_ci				   void *dstbuf,
1168c2ecf20Sopenharmony_ci				   unsigned int bufsize)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	int i, j, k;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	for (i = 0; i < bufsize; i++) {
1218c2ecf20Sopenharmony_ci		u8 val = 0;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci		for (j = 0; j < 8; j++) {
1248c2ecf20Sopenharmony_ci			unsigned int cnt = 0;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci			for (k = 0; k < nsrcbufs; k++) {
1278c2ecf20Sopenharmony_ci				const u8 *srcbuf = srcbufs[k];
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci				if (srcbuf[i] & BIT(j))
1308c2ecf20Sopenharmony_ci					cnt++;
1318c2ecf20Sopenharmony_ci			}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci			if (cnt > nsrcbufs / 2)
1348c2ecf20Sopenharmony_ci				val |= BIT(j);
1358c2ecf20Sopenharmony_ci		}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci		((u8 *)dstbuf)[i] = val;
1388c2ecf20Sopenharmony_ci	}
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/*
1428c2ecf20Sopenharmony_ci * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_ciint nand_onfi_detect(struct nand_chip *chip)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	struct nand_device *base = &chip->base;
1478c2ecf20Sopenharmony_ci	struct mtd_info *mtd = nand_to_mtd(chip);
1488c2ecf20Sopenharmony_ci	struct nand_memory_organization *memorg;
1498c2ecf20Sopenharmony_ci	struct nand_onfi_params *p = NULL, *pbuf;
1508c2ecf20Sopenharmony_ci	struct onfi_params *onfi;
1518c2ecf20Sopenharmony_ci	bool use_datain = false;
1528c2ecf20Sopenharmony_ci	int onfi_version = 0;
1538c2ecf20Sopenharmony_ci	char id[4];
1548c2ecf20Sopenharmony_ci	int i, ret, val;
1558c2ecf20Sopenharmony_ci	u16 crc;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	memorg = nanddev_get_memorg(&chip->base);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	/* Try ONFI for unknown chip or LP */
1608c2ecf20Sopenharmony_ci	ret = nand_readid_op(chip, 0x20, id, sizeof(id));
1618c2ecf20Sopenharmony_ci	if (ret || strncmp(id, "ONFI", 4))
1628c2ecf20Sopenharmony_ci		return 0;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	/* ONFI chip: allocate a buffer to hold its parameter page */
1658c2ecf20Sopenharmony_ci	pbuf = kzalloc((sizeof(*pbuf) * ONFI_PARAM_PAGES), GFP_KERNEL);
1668c2ecf20Sopenharmony_ci	if (!pbuf)
1678c2ecf20Sopenharmony_ci		return -ENOMEM;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	if (!nand_has_exec_op(chip) ||
1708c2ecf20Sopenharmony_ci	    !nand_read_data_op(chip, &pbuf[0], sizeof(*pbuf), true, true))
1718c2ecf20Sopenharmony_ci		use_datain = true;
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	for (i = 0; i < ONFI_PARAM_PAGES; i++) {
1748c2ecf20Sopenharmony_ci		if (!i)
1758c2ecf20Sopenharmony_ci			ret = nand_read_param_page_op(chip, 0, &pbuf[i],
1768c2ecf20Sopenharmony_ci						      sizeof(*pbuf));
1778c2ecf20Sopenharmony_ci		else if (use_datain)
1788c2ecf20Sopenharmony_ci			ret = nand_read_data_op(chip, &pbuf[i], sizeof(*pbuf),
1798c2ecf20Sopenharmony_ci						true, false);
1808c2ecf20Sopenharmony_ci		else
1818c2ecf20Sopenharmony_ci			ret = nand_change_read_column_op(chip, sizeof(*pbuf) * i,
1828c2ecf20Sopenharmony_ci							 &pbuf[i], sizeof(*pbuf),
1838c2ecf20Sopenharmony_ci							 true);
1848c2ecf20Sopenharmony_ci		if (ret) {
1858c2ecf20Sopenharmony_ci			ret = 0;
1868c2ecf20Sopenharmony_ci			goto free_onfi_param_page;
1878c2ecf20Sopenharmony_ci		}
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci		crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)&pbuf[i], 254);
1908c2ecf20Sopenharmony_ci		if (crc == le16_to_cpu(pbuf[i].crc)) {
1918c2ecf20Sopenharmony_ci			p = &pbuf[i];
1928c2ecf20Sopenharmony_ci			break;
1938c2ecf20Sopenharmony_ci		}
1948c2ecf20Sopenharmony_ci	}
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	if (i == ONFI_PARAM_PAGES) {
1978c2ecf20Sopenharmony_ci		const void *srcbufs[ONFI_PARAM_PAGES];
1988c2ecf20Sopenharmony_ci		unsigned int j;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci		for (j = 0; j < ONFI_PARAM_PAGES; j++)
2018c2ecf20Sopenharmony_ci			srcbufs[j] = pbuf + j;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci		pr_warn("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n");
2048c2ecf20Sopenharmony_ci		nand_bit_wise_majority(srcbufs, ONFI_PARAM_PAGES, pbuf,
2058c2ecf20Sopenharmony_ci				       sizeof(*pbuf));
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci		crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)pbuf, 254);
2088c2ecf20Sopenharmony_ci		if (crc != le16_to_cpu(pbuf->crc)) {
2098c2ecf20Sopenharmony_ci			pr_err("ONFI parameter recovery failed, aborting\n");
2108c2ecf20Sopenharmony_ci			goto free_onfi_param_page;
2118c2ecf20Sopenharmony_ci		}
2128c2ecf20Sopenharmony_ci		p = pbuf;
2138c2ecf20Sopenharmony_ci	}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
2168c2ecf20Sopenharmony_ci	    chip->manufacturer.desc->ops->fixup_onfi_param_page)
2178c2ecf20Sopenharmony_ci		chip->manufacturer.desc->ops->fixup_onfi_param_page(chip, p);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	/* Check version */
2208c2ecf20Sopenharmony_ci	val = le16_to_cpu(p->revision);
2218c2ecf20Sopenharmony_ci	if (val & ONFI_VERSION_2_3)
2228c2ecf20Sopenharmony_ci		onfi_version = 23;
2238c2ecf20Sopenharmony_ci	else if (val & ONFI_VERSION_2_2)
2248c2ecf20Sopenharmony_ci		onfi_version = 22;
2258c2ecf20Sopenharmony_ci	else if (val & ONFI_VERSION_2_1)
2268c2ecf20Sopenharmony_ci		onfi_version = 21;
2278c2ecf20Sopenharmony_ci	else if (val & ONFI_VERSION_2_0)
2288c2ecf20Sopenharmony_ci		onfi_version = 20;
2298c2ecf20Sopenharmony_ci	else if (val & ONFI_VERSION_1_0)
2308c2ecf20Sopenharmony_ci		onfi_version = 10;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	if (!onfi_version) {
2338c2ecf20Sopenharmony_ci		pr_info("unsupported ONFI version: %d\n", val);
2348c2ecf20Sopenharmony_ci		goto free_onfi_param_page;
2358c2ecf20Sopenharmony_ci	}
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	sanitize_string(p->manufacturer, sizeof(p->manufacturer));
2388c2ecf20Sopenharmony_ci	sanitize_string(p->model, sizeof(p->model));
2398c2ecf20Sopenharmony_ci	chip->parameters.model = kstrdup(p->model, GFP_KERNEL);
2408c2ecf20Sopenharmony_ci	if (!chip->parameters.model) {
2418c2ecf20Sopenharmony_ci		ret = -ENOMEM;
2428c2ecf20Sopenharmony_ci		goto free_onfi_param_page;
2438c2ecf20Sopenharmony_ci	}
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	memorg->pagesize = le32_to_cpu(p->byte_per_page);
2468c2ecf20Sopenharmony_ci	mtd->writesize = memorg->pagesize;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/*
2498c2ecf20Sopenharmony_ci	 * pages_per_block and blocks_per_lun may not be a power-of-2 size
2508c2ecf20Sopenharmony_ci	 * (don't ask me who thought of this...). MTD assumes that these
2518c2ecf20Sopenharmony_ci	 * dimensions will be power-of-2, so just truncate the remaining area.
2528c2ecf20Sopenharmony_ci	 */
2538c2ecf20Sopenharmony_ci	memorg->pages_per_eraseblock =
2548c2ecf20Sopenharmony_ci			1 << (fls(le32_to_cpu(p->pages_per_block)) - 1);
2558c2ecf20Sopenharmony_ci	mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	memorg->oobsize = le16_to_cpu(p->spare_bytes_per_page);
2588c2ecf20Sopenharmony_ci	mtd->oobsize = memorg->oobsize;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	memorg->luns_per_target = p->lun_count;
2618c2ecf20Sopenharmony_ci	memorg->planes_per_lun = 1 << p->interleaved_bits;
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	/* See erasesize comment */
2648c2ecf20Sopenharmony_ci	memorg->eraseblocks_per_lun =
2658c2ecf20Sopenharmony_ci		1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1);
2668c2ecf20Sopenharmony_ci	memorg->max_bad_eraseblocks_per_lun = le32_to_cpu(p->blocks_per_lun);
2678c2ecf20Sopenharmony_ci	memorg->bits_per_cell = p->bits_per_cell;
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	if (le16_to_cpu(p->features) & ONFI_FEATURE_16_BIT_BUS)
2708c2ecf20Sopenharmony_ci		chip->options |= NAND_BUSWIDTH_16;
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	if (p->ecc_bits != 0xff) {
2738c2ecf20Sopenharmony_ci		struct nand_ecc_props requirements = {
2748c2ecf20Sopenharmony_ci			.strength = p->ecc_bits,
2758c2ecf20Sopenharmony_ci			.step_size = 512,
2768c2ecf20Sopenharmony_ci		};
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci		nanddev_set_ecc_requirements(base, &requirements);
2798c2ecf20Sopenharmony_ci	} else if (onfi_version >= 21 &&
2808c2ecf20Sopenharmony_ci		(le16_to_cpu(p->features) & ONFI_FEATURE_EXT_PARAM_PAGE)) {
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci		/*
2838c2ecf20Sopenharmony_ci		 * The nand_flash_detect_ext_param_page() uses the
2848c2ecf20Sopenharmony_ci		 * Change Read Column command which maybe not supported
2858c2ecf20Sopenharmony_ci		 * by the chip->legacy.cmdfunc. So try to update the
2868c2ecf20Sopenharmony_ci		 * chip->legacy.cmdfunc now. We do not replace user supplied
2878c2ecf20Sopenharmony_ci		 * command function.
2888c2ecf20Sopenharmony_ci		 */
2898c2ecf20Sopenharmony_ci		nand_legacy_adjust_cmdfunc(chip);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci		/* The Extended Parameter Page is supported since ONFI 2.1. */
2928c2ecf20Sopenharmony_ci		if (nand_flash_detect_ext_param_page(chip, p))
2938c2ecf20Sopenharmony_ci			pr_warn("Failed to detect ONFI extended param page\n");
2948c2ecf20Sopenharmony_ci	} else {
2958c2ecf20Sopenharmony_ci		pr_warn("Could not retrieve ONFI ECC requirements\n");
2968c2ecf20Sopenharmony_ci	}
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	/* Save some parameters from the parameter page for future use */
2998c2ecf20Sopenharmony_ci	if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_SET_GET_FEATURES) {
3008c2ecf20Sopenharmony_ci		chip->parameters.supports_set_get_features = true;
3018c2ecf20Sopenharmony_ci		bitmap_set(chip->parameters.get_feature_list,
3028c2ecf20Sopenharmony_ci			   ONFI_FEATURE_ADDR_TIMING_MODE, 1);
3038c2ecf20Sopenharmony_ci		bitmap_set(chip->parameters.set_feature_list,
3048c2ecf20Sopenharmony_ci			   ONFI_FEATURE_ADDR_TIMING_MODE, 1);
3058c2ecf20Sopenharmony_ci	}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	onfi = kzalloc(sizeof(*onfi), GFP_KERNEL);
3088c2ecf20Sopenharmony_ci	if (!onfi) {
3098c2ecf20Sopenharmony_ci		ret = -ENOMEM;
3108c2ecf20Sopenharmony_ci		goto free_model;
3118c2ecf20Sopenharmony_ci	}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	onfi->version = onfi_version;
3148c2ecf20Sopenharmony_ci	onfi->tPROG = le16_to_cpu(p->t_prog);
3158c2ecf20Sopenharmony_ci	onfi->tBERS = le16_to_cpu(p->t_bers);
3168c2ecf20Sopenharmony_ci	onfi->tR = le16_to_cpu(p->t_r);
3178c2ecf20Sopenharmony_ci	onfi->tCCS = le16_to_cpu(p->t_ccs);
3188c2ecf20Sopenharmony_ci	onfi->async_timing_mode = le16_to_cpu(p->async_timing_mode);
3198c2ecf20Sopenharmony_ci	onfi->vendor_revision = le16_to_cpu(p->vendor_revision);
3208c2ecf20Sopenharmony_ci	memcpy(onfi->vendor, p->vendor, sizeof(p->vendor));
3218c2ecf20Sopenharmony_ci	chip->parameters.onfi = onfi;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	/* Identification done, free the full ONFI parameter page and exit */
3248c2ecf20Sopenharmony_ci	kfree(pbuf);
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	return 1;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cifree_model:
3298c2ecf20Sopenharmony_ci	kfree(chip->parameters.model);
3308c2ecf20Sopenharmony_cifree_onfi_param_page:
3318c2ecf20Sopenharmony_ci	kfree(pbuf);
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	return ret;
3348c2ecf20Sopenharmony_ci}
335