Skip to contentSkip to conversation

spi: airoha: add AN7589 support

PATCH Superseded John Crispin 3 participants 6 messages Dec 2 – Dec 4

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover spi: airoha: add AN7589 support

The Airoha AN7589 carries the SPI-NAND controller of the EN7581. The one difference is the DMA address: the AN7589 takes 36 bits, with the upper 4 bits in a second register.

Patch 1 adds the compatible, with airoha,en7581-snand as the fallback. Patch 2 adds match data with the width of the DMA address, sets a 36 bit DMA mask on the AN7589 and writes the upper address bits there.

The series applies to next-20261201 and has no dependencies.

John Crispin (2):
dt-bindings: spi: airoha: add AN7589
spi: airoha: add support for AN7589

 .../bindings/spi/airoha,en7581-snand.yaml     |  1 +
 drivers/spi/spi-airoha-snfi.c                 | 51 ++++++++++++++++---
 2 files changed, 44 insertions(+), 8 deletions(-)

base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c

Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 dt-bindings: spi: airoha: add AN7589

The AN7589 SPI-NAND controller is the EN7581 one with DMA addresses wider than 32 bits. Document its compatible as a fallback pair, like the EN7523 one.

---
 Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml +1 -0
index 855aa08995b9..e8f73115e7a4 100644
@@ -18,6 +18,7 @@ properties:
       - const: airoha,en7581-snand
       - items:
           - enum:
+              - airoha,an7589-snand
               - airoha,en7523-snand
           - const: airoha,en7581-snand
 

base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c

Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 1/2] dt-bindings: spi: airoha: add AN7589

Quoted 3 lines · John Crispin

The AN7589 SPI-NAND controller is the EN7581 one with DMA addresses wider than 32 bits. Document its compatible as a fallback pair, like the EN7523 one.

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] dt-bindings: spi: airoha: add AN7589

In reply to John Crispin
Quoted 8 lines · John Crispin

The AN7589 SPI-NAND controller is the EN7581 one with DMA addresses wider than 32 bits. Document its compatible as a fallback pair, like the EN7523 one.

---
 Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml | 1 +
 1 file changed, 1 insertion(+)

Best regards,
Krzysztof

Signature · 1 line
Krzysztof Kozlowski <[email protected]>
#4 lore raw

PATCH 2/2 spi: airoha: add support for AN7589

In reply to John Crispin

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.

---
 drivers/spi/spi-airoha-snfi.c | 51 +++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 8 deletions(-)
drivers/spi/spi-airoha-snfi.c +43 -8
index 95bfde7c8e7f..ba2bf11e7f03 100644
@@ -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)
 #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;
+
+	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,7 @@ 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);
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
@@ -1114,7 +1148,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;
 
Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH 2/2] spi: airoha: add support for AN7589

drivers/spi/spi-airoha-snfi.c static int airoha_snand_probe(struct platform_device *pdev) · line 1109

Quoted 11 lines

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.

drivers/spi/spi-airoha-snfi.c +1 -0
@@ -1073,6 +1106,7 @@ 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);

We should really check this...

drivers/spi/spi-airoha-snfi.c static int airoha_snand_probe(struct platform_device *pdev) · line 1155

Quoted 10 lines
drivers/spi/spi-airoha-snfi.c +2 -1
@@ -1114,7 +1148,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;
 

...because we deference it unconditionally here.

Signature · 1 line
Mark Brown <[email protected]>