linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Md Sadre Alam <quic_mdalam@quicinc.com>
Cc: agross@kernel.org, andersson@kernel.org,
	konrad.dybcio@linaro.org, robh+dt@kernel.org,
	conor+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	richard@nod.at, vigneshr@ti.com, broonie@kernel.org,
	linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
	linux-spi@vger.kernel.org, quic_srichara@quicinc.com,
	qpic_varada@quicinc.com
Subject: Re: [RFC PATCH 1/5] mtd: nand: ecc-qcom: Add support for ECC Engine Driver
Date: Tue, 31 Oct 2023 16:28:56 +0100	[thread overview]
Message-ID: <20231031162856.1d9e3246@xps-13> (raw)
In-Reply-To: <20231031120307.1600689-2-quic_mdalam@quicinc.com>

Hi,

quic_mdalam@quicinc.com wrote on Tue, 31 Oct 2023 17:33:03 +0530:

Commit log is missing.

> Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
> Signed-off-by: Sricharan R <quic_srichara@quicinc.com>

If Sricharan is a co developer you need to use the right tags. Please
have a look at the documentation. Using the two SoB here does not mean
anything.

> ---
>  drivers/mtd/nand/Kconfig    |   7 ++
>  drivers/mtd/nand/Makefile   |   1 +
>  drivers/mtd/nand/ecc-qcom.c | 198 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 206 insertions(+)
>  create mode 100644 drivers/mtd/nand/ecc-qcom.c
> 
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index 5b0c2c95f10c..333cec8187c8 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -61,6 +61,13 @@ config MTD_NAND_ECC_MEDIATEK
>  	help
>  	  This enables support for the hardware ECC engine from Mediatek.
>  
> +config MTD_NAND_ECC_QCOM
> +	tristate "Qualcomm hardware ECC engine"
> +	depends on ARCH_QCOM

Same comment as Mark regarding COMPILE_TEST

> +	select MTD_NAND_ECC
> +	help
> +	  This enables support for the hardware ECC engine from Qualcomm.
> +
>  endmenu
>  
>  endmenu
> diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
> index 19e1291ac4d5..c73b8a3456ec 100644
> --- a/drivers/mtd/nand/Makefile
> +++ b/drivers/mtd/nand/Makefile
> @@ -3,6 +3,7 @@
>  nandcore-objs := core.o bbt.o
>  obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
>  obj-$(CONFIG_MTD_NAND_ECC_MEDIATEK) += ecc-mtk.o
> +obj-$(CONFIG_MTD_NAND_ECC_QCOM) += ecc-qcom.o qpic_common.o
>  
>  obj-y	+= onenand/
>  obj-y	+= raw/
> diff --git a/drivers/mtd/nand/ecc-qcom.c b/drivers/mtd/nand/ecc-qcom.c
> new file mode 100644
> index 000000000000..a85423ed368a
> --- /dev/null
> +++ b/drivers/mtd/nand/ecc-qcom.c
> @@ -0,0 +1,198 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +/*
> + * QCOM ECC Engine  Driver.
> + * Copyright (C) 2023  Qualcomm Inc.
> + * Authors:	Md sadre Alam		<quic_mdalam@quicinc.com>
> + *		Sricharan R		<quic_srichara@quicinc.com>
> + */
> +
> +#include <linux/platform_device.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/interrupt.h>
> +#include <linux/clk.h>
> +#include <linux/module.h>
> +#include <linux/iopoll.h>
> +#include <linux/of.h>
> +#include <linux/of_platform.h>
> +#include <linux/mutex.h>
> +#include <linux/mtd/nand-qpic-common.h>
> +
> +
> +
> +/* ECC modes supported by the controller */
> +#define ECC_NONE        BIT(0)
> +#define ECC_RS_4BIT     BIT(1)
> +#define ECC_BCH_4BIT    BIT(2)
> +#define ECC_BCH_8BIT    BIT(3)
> +
> +struct qpic_ecc_caps {
> +	u32 err_mask;
> +	u32 err_shift;
> +	const u8 *ecc_strength;
> +	const u32 *ecc_regs;
> +	u8 num_ecc_strength;
> +	u8 ecc_mode_shift;
> +	u32 parity_bits;
> +	int pg_irq_sel;
> +};
> +
> +
> +struct qcom_nand_host *to_qcom_nand_host(struct nand_chip *chip)
> +{
> +	return container_of(chip, struct qcom_nand_host, chip);
> +}
> +EXPORT_SYMBOL(to_qcom_nand_host);
> +
> +struct qcom_nand_controller *
> +get_qcom_nand_controller(struct nand_chip *chip)
> +{
> +	return container_of(chip->controller, struct qcom_nand_controller,
> +			    controller);
> +}
> +EXPORT_SYMBOL(get_qcom_nand_controller);
> +
> +static struct qpic_ecc *qpic_ecc_get(struct device_node *np)
> +{
> +	struct platform_device *pdev;
> +	struct qpic_ecc *ecc;
> +
> +	pdev = of_find_device_by_node(np);
> +	if (!pdev)
> +		return ERR_PTR(-EPROBE_DEFER);
> +
> +	ecc = platform_get_drvdata(pdev);
> +	if (!ecc) {
> +		put_device(&pdev->dev);
> +		return ERR_PTR(-EPROBE_DEFER);
> +	}
> +
> +	return ecc;
> +}
> +
> +struct qpic_ecc *of_qpic_ecc_get(struct device_node *of_node)
> +{
> +	struct qpic_ecc *ecc = NULL;
> +	struct device_node *np;
> +
> +	np = of_parse_phandle(of_node, "nand-ecc-engine", 0);
> +	/* for backward compatibility */

There is no backward compatibility to handle upstream

> +	if (!np)
> +		np = of_parse_phandle(of_node, "ecc-engine", 0);
> +	if (np) {
> +		ecc = qpic_ecc_get(np);
> +		of_node_put(np);
> +	}
> +
> +	return ecc;
> +}
> +EXPORT_SYMBOL(of_qpic_ecc_get);
> +
> +int qcom_ecc_config(struct qpic_ecc  *ecc, int ecc_strength,
> +			bool wide_bus)
> +{
> +	ecc->ecc_modes = (ECC_RS_4BIT | ECC_BCH_8BIT);
> +
> +	if (ecc_strength >= 8) {

If your engine does not support more than an 8-bit strength this
condition seems a bit strange.

> +		/* 8 bit ECC defaults to BCH ECC on all platforms */
> +		ecc->bch_enabled = true;
> +		ecc->ecc_mode = 1;

ecc_modes above, ecc_mode here, not very clear what this is.
Please give meaningful names to your variables, not just the bit name
that this is capturing because here it's unclear what this is.

> +
> +		if (wide_bus) {
> +			ecc->ecc_bytes_hw = 14;
> +			ecc->spare_bytes = 0;

Spare bytes depend on the flash, you can't use constant values like
that.

I also don't understand what wide_bus is and why it has an impact of
only 1 on the number of ECC bytes. Please make all this more explicit.

> +			ecc->bbm_size = 2;
> +		} else {
> +			ecc->ecc_bytes_hw = 13;
> +			ecc->spare_bytes = 2;
> +			ecc->bbm_size = 1;
> +		}
> +	} else {
> +		/*
> +		 * if the controller supports BCH for 4 bit ECC, the controller
> +		 * uses lesser bytes for ECC. If RS is used, the ECC bytes is
> +		 * always 10 bytes
> +		 */
> +		if (ecc->ecc_modes & ECC_BCH_4BIT) {
> +			/* BCH */
> +			ecc->bch_enabled = true;
> +			ecc->ecc_mode = 0;
> +			if (wide_bus) {
> +				ecc->ecc_bytes_hw = 8;
> +				ecc->spare_bytes = 2;
> +				ecc->bbm_size = 2;
> +			} else {
> +				ecc->ecc_bytes_hw = 7;
> +				ecc->spare_bytes = 4;
> +				ecc->bbm_size = 1;
> +			}
> +		} else {
> +			/* RS */
> +			ecc->ecc_bytes_hw = 10;
> +			if (wide_bus) {
> +				ecc->spare_bytes = 0;
> +				ecc->bbm_size = 2;
> +			} else {
> +				ecc->spare_bytes = 1;
> +				ecc->bbm_size = 1;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(qcom_ecc_config);

Thanks,
Miquèl

  reply	other threads:[~2023-10-31 15:29 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 12:03 [RFC PATCH 0/5] Add QPIC SPI NAND driver support Md Sadre Alam
2023-10-31 12:03 ` [RFC PATCH 1/5] mtd: nand: ecc-qcom: Add support for ECC Engine Driver Md Sadre Alam
2023-10-31 15:28   ` Miquel Raynal [this message]
2023-11-03 12:06     ` Md Sadre Alam
2023-11-03 12:08       ` Krzysztof Kozlowski
2023-11-03 12:11         ` Krzysztof Kozlowski
2023-10-31 17:11   ` Krzysztof Kozlowski
2023-11-03 12:24     ` Md Sadre Alam
2023-11-03 12:33       ` Dmitry Baryshkov
2023-11-03 13:23         ` Md Sadre Alam
2023-11-03 13:46           ` Miquel Raynal
2023-11-20  6:30             ` Md Sadre Alam
2023-11-03 13:54           ` Dmitry Baryshkov
2023-10-31 12:03 ` [RFC PATCH 2/5] arm64: dts: qcom: ipq9574: Add ecc engine support Md Sadre Alam
2023-10-31 15:23   ` Konrad Dybcio
2023-11-03 11:26     ` Md Sadre Alam
2023-10-31 17:12   ` Krzysztof Kozlowski
2023-11-03 12:09     ` Md Sadre Alam
2023-10-31 12:03 ` [RFC PATCH 3/5] mtd: nand: qpic_common: Add support for qpic common API Md Sadre Alam
2023-10-31 15:54   ` Miquel Raynal
2023-10-31 12:03 ` [RFC PATCH 4/5] spi: qpic: Add support for qpic spi nand driver Md Sadre Alam
2023-10-31 14:23   ` Mark Brown
2023-11-03 11:20     ` Md Sadre Alam
2023-11-03 12:47       ` Mark Brown
2023-11-20  6:34         ` Md Sadre Alam
2023-10-31 17:13   ` Krzysztof Kozlowski
2023-11-03 12:13     ` Md Sadre Alam
2023-11-03 12:18       ` Krzysztof Kozlowski
2023-11-03 12:15     ` Md Sadre Alam
2023-10-31 12:03 ` [RFC PATCH 5/5] arm64: dts: qcom: ipq9574: Add support for SPI nand Md Sadre Alam
2023-10-31 15:27   ` Konrad Dybcio
2023-11-03 11:31     ` Md Sadre Alam
2023-10-31 17:17   ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231031162856.1d9e3246@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=qpic_varada@quicinc.com \
    --cc=quic_mdalam@quicinc.com \
    --cc=quic_srichara@quicinc.com \
    --cc=richard@nod.at \
    --cc=robh+dt@kernel.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).