[PATCH 2/5] drivers: mtd: nand: Add qpic_common API file

Md Sadre Alam quic_mdalam at quicinc.com
Tue Feb 20 07:59:02 PST 2024



On 2/15/2024 8:30 PM, Dmitry Baryshkov wrote:
> On Thu, 15 Feb 2024 at 15:53, Md Sadre Alam <quic_mdalam at quicinc.com> wrote:
>>
>> Add qpic_common.c file which hold all the common
>> qpic APIs which will be used by both qpic raw nand
>> driver and qpic spi nand driver.
>>
>> Co-developed-by: Sricharan Ramabadhran <quic_srichara at quicinc.com>
>> Signed-off-by: Sricharan Ramabadhran <quic_srichara at quicinc.com>
>> Co-developed-by: Varadarajan Narayanan <quic_varada at quicinc.com>
>> Signed-off-by: Varadarajan Narayanan <quic_varada at quicinc.com>
>> Signed-off-by: Md Sadre Alam <quic_mdalam at quicinc.com>
>> ---
>>   drivers/mtd/nand/Makefile            |    1 +
>>   drivers/mtd/nand/qpic_common.c       |  786 +++++++++++++++++
>>   drivers/mtd/nand/raw/qcom_nandc.c    | 1226 +-------------------------
>>   include/linux/mtd/nand-qpic-common.h |  488 ++++++++++
>>   4 files changed, 1291 insertions(+), 1210 deletions(-)
>>   create mode 100644 drivers/mtd/nand/qpic_common.c
>>   create mode 100644 include/linux/mtd/nand-qpic-common.h
>>
>> diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
>> index 19e1291ac4d5..131707a41293 100644
>> --- a/drivers/mtd/nand/Makefile
>> +++ b/drivers/mtd/nand/Makefile
>> @@ -12,3 +12,4 @@ nandcore-$(CONFIG_MTD_NAND_ECC) += ecc.o
>>   nandcore-$(CONFIG_MTD_NAND_ECC_SW_HAMMING) += ecc-sw-hamming.o
>>   nandcore-$(CONFIG_MTD_NAND_ECC_SW_BCH) += ecc-sw-bch.o
>>   nandcore-$(CONFIG_MTD_NAND_ECC_MXIC) += ecc-mxic.o
>> +obj-y += qpic_common.o
>> diff --git a/drivers/mtd/nand/qpic_common.c b/drivers/mtd/nand/qpic_common.c
>> new file mode 100644
>> index 000000000000..4d74ba888028
>> --- /dev/null
>> +++ b/drivers/mtd/nand/qpic_common.c
>> @@ -0,0 +1,786 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * QPIC Controller common API file.
>> + * Copyright (C) 2023  Qualcomm Inc.
>> + * Authors:    Md sadre Alam           <quic_mdalam at quicinc.com>
>> + *             Sricharan R             <quic_srichara at quicinc.com>
>> + *             Varadarajan Narayanan   <quic_varada at quicinc.com>
> 
> This is a bit of an exaggeration. You are moving code, not writing new
> code. Please retain the existing copyrights for the moved code.
Ok
> 
>> + *
>> + */
>> +
>> +#include <linux/mtd/nand-qpic-common.h>
>> +
>> +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);
> 
> NAK for adding functions to the global export namespace without a
> proper driver-specific prefix.
Ok, will fix in next patch
> 
> Also, a bunch of the code here seems not so well thought. It was fine
> for an internal interface, but it doesn't look so good as a common
> wrapper. Please consider defining a sensible common code module
> interface instead.

  QPIC controller will support both raw NAND as well Serial nand interface.
  This common API file was the part of raw NAND driver , since for serial
  nand most of the APIs from raw nand driver will be re-used that's why i
  have created this common API file, so that QPIC serial nand driver
  drivers/spi/spi-qpic-snand.c and QPIC raw NAND driver
  drivers/mtd/nand/raw/qcom_nandc.c can used these common APIs.

  Could you please suggest how I should handle this in batter way.
> 
> At least each function that is being exported should get a kerneldoc.
Ok
> 
> Last, but not least, please use EXPORT_SYMBOL_GPL.
Ok
> 
>> +
>> +/*
>> + * Helper to prepare DMA descriptors for configuring registers
>> + * before reading a NAND page.
>> + */
>> +void config_nand_page_read(struct nand_chip *chip)
>> +{
>> +       struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
>> +
>> +       write_reg_dma(nandc, NAND_ADDR0, 2, 0);
>> +       write_reg_dma(nandc, NAND_DEV0_CFG0, 3, 0);
>> +       if (!nandc->props->qpic_v2)
>> +               write_reg_dma(nandc, NAND_EBI2_ECC_BUF_CFG, 1, 0);
>> +       write_reg_dma(nandc, NAND_ERASED_CW_DETECT_CFG, 1, 0);
>> +       write_reg_dma(nandc, NAND_ERASED_CW_DETECT_CFG, 1,
>> +                     NAND_ERASED_CW_SET | NAND_BAM_NEXT_SGL);
>> +}
>> +EXPORT_SYMBOL(config_nand_page_read);
>> +
>> +/* Frees the BAM transaction memory */
>> +void free_bam_transaction(struct qcom_nand_controller *nandc)
>> +{
>> +       struct bam_transaction *bam_txn = nandc->bam_txn;
>> +
>> +       devm_kfree(nandc->dev, bam_txn);
> 
> devm_kfree is usually a bad sign. Either the devm_kfree should be
> dropped (because the memory area is allocated only during probe / init
> and doesn't need to be freed manually) or use kalloc/kfree directly
> without devres wrapping.
Ok
> 
>> +}
>> +EXPORT_SYMBOL(free_bam_transaction);
>> +
> 
> [skipped the rest]
> 
>> --
>> 2.34.1
>>
>>
> 
> 
> --
> With best wishes
> Dmitry

Thanks for reviewing, Will fix all the comments in next patch.

Regards,
Alam.



More information about the linux-mtd mailing list