All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: John Crispin <john@phrozen.org>
Cc: Ray Liu <ray.liu@airoha.com>, Mark Brown <broonie@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Christian Marangi <ansuelsmth@gmail.com>,
	devicetree@vger.kernel.org, lei.dong@airoha.com,
	Linqi.zhang@airoha.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
	Rajeev.kumar@airoha.com, upstream@airoha.com,
	Weifeng.xu@airoha.com, zhengping.zhang@airoha.com
Subject: Re: [PATCH v2 2/2] spi: airoha: add support for AN7589
Date: Sat, 5 Dec 2026 14:45:01 +0100	[thread overview]
Message-ID: <axQVXfr1cDKrTYtx@lore-desk> (raw)
In-Reply-To: <20261204185823.3797250-3-john@phrozen.org>

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

> The AN7589 NFI takes a 36 bit DMA address: the upper 4 bits go into a
> second register at 0x88. Add match data with the width of the DMA
> address, use it for the DMA mask and write the upper register only on
> the AN7589, so the EN7581 and EN7523 never touch an offset they do not
> document.
> 
> Signed-off-by: John Crispin <john@phrozen.org>

Hi John,

just a couple of nits inline. Fixing them:

Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>

Regards,
Lorenzo

> ---
> Changes in v2:
> - Fail the probe when there is no match data (Mark).
> 
>  drivers/spi/spi-airoha-snfi.c | 53+++++++++++++++++++++++++++++------
>  1 file changed, 45 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
> index 95bfde7c8e7f..aa4b56d1d5cb 100644
> --- a/drivers/spi/spi-airoha-snfi.c
> +++ b/drivers/spi/spi-airoha-snfi.c
> @@ -132,6 +132,8 @@
>  #define REG_SPI_NFI_STA				0x0060
>  #define REG_SPI_NFI_FIFOSTA			0x0064
>  #define REG_SPI_NFI_STRADDR			0x0080
> +#define REG_SPI_NFI_STRADDR_2			0x0088
> +#define SPI_NFI_STRADDR_2_ADDR_HI		GENMASK(3, 0)

nit: REG_SPI_NFI_STRADDR_HIGH		0x0088
     SPI_NFI_STRADDR_HIGH		GENMASK(3, 0)

>  #define REG_SPI_NFI_FDM0L			0x00a0
>  #define REG_SPI_NFI_FDM0M			0x00a4
>  #define REG_SPI_NFI_FDM7L			0x00d8
> @@ -218,13 +220,33 @@ enum airoha_snand_cs {
>  	SPI_CHIP_SEL_LOW,
>  };
>  
> +struct airoha_snand_data {
> +	u8 dma_addr_bits;
> +};
> +
>  struct airoha_snand_ctrl {
>  	struct device *dev;
>  	struct regmap *regmap_ctrl;
>  	struct regmap *regmap_nfi;
>  	struct clk *spi_clk;
> +	const struct airoha_snand_data *data;
>  };
>  
> +static int airoha_snand_set_dma_addr(struct airoha_snand_ctrl *as_ctrl,
> +				     dma_addr_t dma_addr)
> +{
> +	int err;
> +
> +	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR,
> +			   lower_32_bits(dma_addr));
> +	if (err || as_ctrl->data->dma_addr_bits <= 32)
> +		return err;

nit: I guess it is more clear doing:

	if (err)
		return err;

	if (as_ctrl->data->dma_addr_bits <= 32)
		return 0;

> +
> +	return regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR_2,
> +			    FIELD_PREP(SPI_NFI_STRADDR_2_ADDR_HI,
> +				       upper_32_bits(dma_addr)));
> +}
> +
>  static int airoha_snand_set_fifo_op(struct airoha_snand_ctrl *as_ctrl,
>  				    u8 op_cmd, int op_len)
>  {
> @@ -647,9 +669,7 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
>  	if (err)
>  		goto error_dma_mode_off;
>  
> -	/* set dma addr */
> -	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR,
> -			   dma_addr);
> +	err = airoha_snand_set_dma_addr(as_ctrl, dma_addr);
>  	if (err)
>  		goto error_dma_unmap;
>  
> @@ -836,9 +856,7 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
>  	if (err)
>  		goto error_dma_mode_off;
>  
> -	/* set dma addr */
> -	err = regmap_write(as_ctrl->regmap_nfi, REG_SPI_NFI_STRADDR,
> -			   dma_addr);
> +	err = airoha_snand_set_dma_addr(as_ctrl, dma_addr);
>  	if (err)
>  		goto error_dma_unmap;
>  
> @@ -1051,8 +1069,23 @@ static const struct regmap_config spi_nfi_regmap_config = {
>  	.max_register	= REG_SPI_NFI_SNF_NFI_CNFG,
>  };
>  
> +static const struct airoha_snand_data airoha_en7581_snand_data = {
> +	.dma_addr_bits = 32,
> +};
> +
> +static const struct airoha_snand_data airoha_an7589_snand_data = {
> +	.dma_addr_bits = 36,
> +};
> +
>  static const struct of_device_id airoha_snand_ids[] = {
> -	{ .compatible	= "airoha,en7581-snand" },
> +	{
> +		.compatible	= "airoha,an7589-snand",
> +		.data		= &airoha_an7589_snand_data,
> +	},
> +	{
> +		.compatible	= "airoha,en7581-snand",
> +		.data		= &airoha_en7581_snand_data,
> +	},
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, airoha_snand_ids);
> @@ -1073,6 +1106,9 @@ static int airoha_snand_probe(struct platform_device *pdev)
>  
>  	as_ctrl = spi_controller_get_devdata(ctrl);
>  	as_ctrl->dev = dev;
> +	as_ctrl->data = device_get_match_data(dev);
> +	if (!as_ctrl->data)
> +		return -ENODEV;
>  
>  	base = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(base))
> @@ -1114,7 +1150,8 @@ static int airoha_snand_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> -	err = dma_set_mask(as_ctrl->dev, DMA_BIT_MASK(32));
> +	err = dma_set_mask(as_ctrl->dev,
> +			   DMA_BIT_MASK(as_ctrl->data->dma_addr_bits));
>  	if (err)
>  		return err;
>  
> -- 
> 2.34.1
> 

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

      reply	other threads:[~2026-12-05 13:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:58 [PATCH v2 0/2] spi: airoha: add AN7589 support John Crispin
2026-12-04 18:58 ` [PATCH v2 1/2] spi: dt-bindings: airoha: add AN7589 John Crispin
2026-12-05 13:36   ` Lorenzo Bianconi
2026-12-04 18:58 ` [PATCH v2 2/2] spi: airoha: add support for AN7589 John Crispin
2026-12-05 13:45   ` Lorenzo Bianconi [this message]

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=axQVXfr1cDKrTYtx@lore-desk \
    --to=lorenzo@kernel.org \
    --cc=Linqi.zhang@airoha.com \
    --cc=Rajeev.kumar@airoha.com \
    --cc=Weifeng.xu@airoha.com \
    --cc=ansuelsmth@gmail.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=john@phrozen.org \
    --cc=krzk+dt@kernel.org \
    --cc=lei.dong@airoha.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=ray.liu@airoha.com \
    --cc=robh@kernel.org \
    --cc=upstream@airoha.com \
    --cc=zhengping.zhang@airoha.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 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.