All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-spi@vger.kernel.org, conor@kernel.org, broonie@kernel.org,
	lorenzo.bianconi83@gmail.com,
	linux-arm-kernel@lists.infradead.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, nbd@nbd.name, john@phrozen.org,
	dd@embedd.com, catalin.marinas@arm.com, will@kernel.org,
	upstream@airoha.com, angelogioacchino.delregno@collabora.com
Subject: Re: [PATCH v4 3/3] spi: airoha: add SPI-NAND Flash controller driver
Date: Fri, 26 Apr 2024 18:19:13 +0200	[thread overview]
Message-ID: <ZivUAZ2SKRJsESKF@lore-desk> (raw)
In-Reply-To: <CAHp75Vd5VSMNy-bYQmcmRA47uTn567QiKmvDJGEkRUgVCk5PAQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5306 bytes --]

> On Fri, Apr 26, 2024 at 11:31 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >
> > Introduce support for SPI-NAND driver of the Airoha NAND Flash Interface
> > found on Airoha ARM SoCs.
> 
> ...
> 
> > +#include <asm-generic/unaligned.h>
> 
> No driver should include asm-generic, basically 99.9% of the kernel
> code must not do that. I.o.w. asm-generic is very special.
> 

ack we can use <asm/unaligned.h> instead

> > +#include <linux/bitfield.h>
> > +#include <linux/clk.h>
> 
> + delay.h
> 
> > +#include <linux/device.h>
> > +#include <linux/dma-mapping.h>
> 
> + errno.h
> 
> > +#include <linux/types.h>
> 
> Can you make it ordered (I noticed this after a while)?
> 
> + limits.h
> 
> > +#include <linux/math.h>
> 
> + minmax.h
> 
> > +#include <linux/module.h>
> > +#include <linux/mutex.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/sizes.h>
> > +#include <linux/spi/spi.h>
> > +#include <linux/spi/spi-mem.h>
> 
> + types.h
> 
> Also note, we usually place headers from more generic to less, hence
> linux/* followed by asm/* and not vice versa.

ack, I will fix it.

> 
> ...
> 
> > +struct airoha_snand_dev {
> > +       size_t buf_len;
> > +
> > +       u8 *txrx_buf;
> > +       dma_addr_t dma_addr;
> > +
> > +       u64 cur_page_num;
> > +       bool data_need_update;
> > +};
> 
> ...
> 
> > +               /* quad io / quad out */
> 
> io --> in ?

ack, I will fix it.

> 
> ...
> 
> > +               /* dual io / dual out */
> 
> Ditto.
> 
> ...
> 
> > +       case SPI_MEM_DATA_OUT:
> > +               /* check dummy cycle first */
> > +               if (op->dummy.nbytes)
> > +                       return false;
> > +
> > +               /* program load quad out */
> > +               if (op->addr.buswidth == 1 && op->data.buswidth == 4)
> > +                       return true;
> > +
> > +               /* standard spi */
> > +               if (op->addr.buswidth == 1 && op->data.buswidth == 1)
> > +                       return true;
> 
> > +       default:
> > +               break;
> > +       }
> > +
> > +       return false;
> 
> Why not return false directly from the default case?

it is because we still need the 'return false' at the end of routine for the
other cases due to SPI_MEM_DATA_IN and SPI_MEM_DATA_OUT.

> 
> ...
> 
> > +               op->data.nbytes = min_t(size_t, op->data.nbytes, 160 - len);
> 
> You probably wanted clamp(). It's discouraged to use min_t() for unsigned types.

do you mean doing something like:

op->data.nbytes = clamp(op->data.nbytes, op->data.nbytes, 160 - len);

maybe an 'if' condition is more readable, what do you think?

> 
> ...
> 
> > +       err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR,
> > +                                      val, (val & SPI_NFI_AHB_DONE), 0,
> > +                                      USEC_PER_SEC);
> 
> Perhaps
>   1 * USEC_PER_SEC
> ?
> 
> Easy to read plain numbers like this to get the idea "this is 1 SEC
> timeout". Also editors highlight plain integers with a different
> colour.
> 
> ...
> 
> > +       /* addr part */
> > +       cmd = opcode == SPI_NAND_OP_GET_FEATURE ? 0x11 : 0x8;
> > +       put_unaligned_be64(op->addr.val, data);
> 
> > +       for (i = 0; i < op->addr.nbytes; i++) {
> > +               err = airoha_snand_write_data(as_ctrl, cmd,
> > +                                             &data[8 - op->addr.nbytes + i],
> 
> Now you can update a for loop to make this prettier, right?
> 
> > +                                             sizeof(data[0]));
> > +               if (err)
> > +                       return err;
> > +       }
> 
>        for (i = 8 - op->addr.nbytes; i < 8; i++) {
>                err = airoha_snand_write_data(as_ctrl, cmd, &data[i],
>                                              sizeof(data[0]));
>                ...
>        }
> 
> Note, 8 can be replaced by sizeof() / ARRAY_SIZE() but I'm not insisting.

ack, I agree. I will fix it.

> 
> ...
> 
> > +       devm_kfree(as_ctrl->dev, as_dev->txrx_buf);
> > +       devm_kfree(as_ctrl->dev, as_dev);
> 
> Why?! Using devm_*free() explicitly hints about either
> misunderstanding of devm concept, or object's lifetime.

ack, I agree, we can get rid of them.

> 
> ...
> 
> > +       spi_set_ctldata(spi, NULL);
> 
> Seems there is no consensus on NULLifying this (when, if even needed),
> but it's fine.
> 
> ...
> 
> > +       base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> 
> How is 'res' being used exactly?

right, we can pass NULL here to devm_platform_get_and_ioremap_resource()

> 
> > +       if (IS_ERR(base))
> > +               return PTR_ERR(base);
> 
> ...
> 
> > +       base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
> 
> Ditto.
> 
> > +       if (IS_ERR(base))
> > +               return PTR_ERR(base);
> 
> 
> ...
> 
> > +       ctrl->dev.of_node = dev->of_node;
> 
> Use device_set_node() instead.
> You might need dev_fwnode() from property.h.

ack, I will fix it.

Regards,
Lorenzo

> 
> -- 
> With Best Regards,
> Andy Shevchenko

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-spi@vger.kernel.org, conor@kernel.org, broonie@kernel.org,
	lorenzo.bianconi83@gmail.com,
	linux-arm-kernel@lists.infradead.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, nbd@nbd.name, john@phrozen.org,
	dd@embedd.com, catalin.marinas@arm.com, will@kernel.org,
	upstream@airoha.com, angelogioacchino.delregno@collabora.com
Subject: Re: [PATCH v4 3/3] spi: airoha: add SPI-NAND Flash controller driver
Date: Fri, 26 Apr 2024 18:19:13 +0200	[thread overview]
Message-ID: <ZivUAZ2SKRJsESKF@lore-desk> (raw)
In-Reply-To: <CAHp75Vd5VSMNy-bYQmcmRA47uTn567QiKmvDJGEkRUgVCk5PAQ@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 5306 bytes --]

> On Fri, Apr 26, 2024 at 11:31 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >
> > Introduce support for SPI-NAND driver of the Airoha NAND Flash Interface
> > found on Airoha ARM SoCs.
> 
> ...
> 
> > +#include <asm-generic/unaligned.h>
> 
> No driver should include asm-generic, basically 99.9% of the kernel
> code must not do that. I.o.w. asm-generic is very special.
> 

ack we can use <asm/unaligned.h> instead

> > +#include <linux/bitfield.h>
> > +#include <linux/clk.h>
> 
> + delay.h
> 
> > +#include <linux/device.h>
> > +#include <linux/dma-mapping.h>
> 
> + errno.h
> 
> > +#include <linux/types.h>
> 
> Can you make it ordered (I noticed this after a while)?
> 
> + limits.h
> 
> > +#include <linux/math.h>
> 
> + minmax.h
> 
> > +#include <linux/module.h>
> > +#include <linux/mutex.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/sizes.h>
> > +#include <linux/spi/spi.h>
> > +#include <linux/spi/spi-mem.h>
> 
> + types.h
> 
> Also note, we usually place headers from more generic to less, hence
> linux/* followed by asm/* and not vice versa.

ack, I will fix it.

> 
> ...
> 
> > +struct airoha_snand_dev {
> > +       size_t buf_len;
> > +
> > +       u8 *txrx_buf;
> > +       dma_addr_t dma_addr;
> > +
> > +       u64 cur_page_num;
> > +       bool data_need_update;
> > +};
> 
> ...
> 
> > +               /* quad io / quad out */
> 
> io --> in ?

ack, I will fix it.

> 
> ...
> 
> > +               /* dual io / dual out */
> 
> Ditto.
> 
> ...
> 
> > +       case SPI_MEM_DATA_OUT:
> > +               /* check dummy cycle first */
> > +               if (op->dummy.nbytes)
> > +                       return false;
> > +
> > +               /* program load quad out */
> > +               if (op->addr.buswidth == 1 && op->data.buswidth == 4)
> > +                       return true;
> > +
> > +               /* standard spi */
> > +               if (op->addr.buswidth == 1 && op->data.buswidth == 1)
> > +                       return true;
> 
> > +       default:
> > +               break;
> > +       }
> > +
> > +       return false;
> 
> Why not return false directly from the default case?

it is because we still need the 'return false' at the end of routine for the
other cases due to SPI_MEM_DATA_IN and SPI_MEM_DATA_OUT.

> 
> ...
> 
> > +               op->data.nbytes = min_t(size_t, op->data.nbytes, 160 - len);
> 
> You probably wanted clamp(). It's discouraged to use min_t() for unsigned types.

do you mean doing something like:

op->data.nbytes = clamp(op->data.nbytes, op->data.nbytes, 160 - len);

maybe an 'if' condition is more readable, what do you think?

> 
> ...
> 
> > +       err = regmap_read_poll_timeout(as_ctrl->regmap_nfi, REG_SPI_NFI_INTR,
> > +                                      val, (val & SPI_NFI_AHB_DONE), 0,
> > +                                      USEC_PER_SEC);
> 
> Perhaps
>   1 * USEC_PER_SEC
> ?
> 
> Easy to read plain numbers like this to get the idea "this is 1 SEC
> timeout". Also editors highlight plain integers with a different
> colour.
> 
> ...
> 
> > +       /* addr part */
> > +       cmd = opcode == SPI_NAND_OP_GET_FEATURE ? 0x11 : 0x8;
> > +       put_unaligned_be64(op->addr.val, data);
> 
> > +       for (i = 0; i < op->addr.nbytes; i++) {
> > +               err = airoha_snand_write_data(as_ctrl, cmd,
> > +                                             &data[8 - op->addr.nbytes + i],
> 
> Now you can update a for loop to make this prettier, right?
> 
> > +                                             sizeof(data[0]));
> > +               if (err)
> > +                       return err;
> > +       }
> 
>        for (i = 8 - op->addr.nbytes; i < 8; i++) {
>                err = airoha_snand_write_data(as_ctrl, cmd, &data[i],
>                                              sizeof(data[0]));
>                ...
>        }
> 
> Note, 8 can be replaced by sizeof() / ARRAY_SIZE() but I'm not insisting.

ack, I agree. I will fix it.

> 
> ...
> 
> > +       devm_kfree(as_ctrl->dev, as_dev->txrx_buf);
> > +       devm_kfree(as_ctrl->dev, as_dev);
> 
> Why?! Using devm_*free() explicitly hints about either
> misunderstanding of devm concept, or object's lifetime.

ack, I agree, we can get rid of them.

> 
> ...
> 
> > +       spi_set_ctldata(spi, NULL);
> 
> Seems there is no consensus on NULLifying this (when, if even needed),
> but it's fine.
> 
> ...
> 
> > +       base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> 
> How is 'res' being used exactly?

right, we can pass NULL here to devm_platform_get_and_ioremap_resource()

> 
> > +       if (IS_ERR(base))
> > +               return PTR_ERR(base);
> 
> ...
> 
> > +       base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
> 
> Ditto.
> 
> > +       if (IS_ERR(base))
> > +               return PTR_ERR(base);
> 
> 
> ...
> 
> > +       ctrl->dev.of_node = dev->of_node;
> 
> Use device_set_node() instead.
> You might need dev_fwnode() from property.h.

ack, I will fix it.

Regards,
Lorenzo

> 
> -- 
> With Best Regards,
> Andy Shevchenko

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-04-26 16:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26  8:30 [PATCH v4 0/3] Add add SPI-NAND Flash controller driver for EN7581 Lorenzo Bianconi
2024-04-26  8:30 ` Lorenzo Bianconi
2024-04-26  8:30 ` [PATCH v4 1/3] dt-bindings: spi: airoha: Add YAML schema for SNFI controller Lorenzo Bianconi
2024-04-26  8:30   ` Lorenzo Bianconi
2024-04-26  8:30 ` [PATCH v4 2/3] arm64: dts: airoha: add EN7581 spi-nand node Lorenzo Bianconi
2024-04-26  8:30   ` Lorenzo Bianconi
2024-04-26  8:30 ` [PATCH v4 3/3] spi: airoha: add SPI-NAND Flash controller driver Lorenzo Bianconi
2024-04-26  8:30   ` Lorenzo Bianconi
2024-04-26 13:48   ` Andy Shevchenko
2024-04-26 13:48     ` Andy Shevchenko
2024-04-26 16:19     ` Lorenzo Bianconi [this message]
2024-04-26 16:19       ` Lorenzo Bianconi
2024-04-26 18:40       ` Andy Shevchenko
2024-04-26 18:40         ` Andy Shevchenko
2024-04-27 21:20   ` kernel test robot
2024-04-27 21:20     ` kernel test robot

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=ZivUAZ2SKRJsESKF@lore-desk \
    --to=lorenzo@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=conor@kernel.org \
    --cc=dd@embedd.com \
    --cc=devicetree@vger.kernel.org \
    --cc=john@phrozen.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lorenzo.bianconi83@gmail.com \
    --cc=nbd@nbd.name \
    --cc=robh+dt@kernel.org \
    --cc=upstream@airoha.com \
    --cc=will@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.