Skip to content

Commit e092288

Browse files
sycamoremoonRevySR
authored andcommitted
UPSTREAM: spi: spi-sg2044-nor: Add configurable chip_info
SG2044 and SG2042 have similar SPI-NOR flash controller design, but have incompatibility which causes existing driver not working on SG2042: 1. SPI-NOR flash controller on SG2042 have no OPT register. 2. FIFO trigger level on SG2042 should be strictly less than 8. So introduce a new configurable chip_info structure to hold the different configuration. Link: https://github.com/sophgo/sophgo-doc/blob/main/SG2042/TRM/source/SPI-flash.rst Signed-off-by: Zixian Zeng <[email protected]> Reviewed-by: Chen Wang <[email protected]> & Tested-by: Chen Wang Link: https://patch.msgid.link/[email protected] Reviewed-by: Chen Wang <[email protected]> & Tested-by: Chen Wang Signed-off-by: Mark Brown <[email protected]> (cherry picked from commit 5653b4f) Signed-off-by: Han Gao <[email protected]>
1 parent e4a264f commit e092288

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

drivers/spi/spi-sg2044-nor.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@
8484

8585
#define SPIFMC_MAX_READ_SIZE 0x10000
8686

87+
struct sg204x_spifmc_chip_info {
88+
bool has_opt_reg;
89+
u32 rd_fifo_int_trigger_level;
90+
};
91+
8792
struct sg2044_spifmc {
8893
struct spi_controller *ctrl;
8994
void __iomem *io_base;
9095
struct device *dev;
9196
struct mutex lock;
9297
struct clk *clk;
98+
const struct sg204x_spifmc_chip_info *chip_info;
9399
};
94100

95101
static int sg2044_spifmc_wait_int(struct sg2044_spifmc *spifmc, u8 int_type)
@@ -139,7 +145,7 @@ static ssize_t sg2044_spifmc_read_64k(struct sg2044_spifmc *spifmc,
139145

140146
reg = sg2044_spifmc_init_reg(spifmc);
141147
reg |= (op->addr.nbytes + op->dummy.nbytes) << SPIFMC_TRAN_CSR_ADDR_BYTES_SHIFT;
142-
reg |= SPIFMC_TRAN_CSR_FIFO_TRG_LVL_8_BYTE;
148+
reg |= spifmc->chip_info->rd_fifo_int_trigger_level;
143149
reg |= SPIFMC_TRAN_CSR_WITH_CMD;
144150
reg |= SPIFMC_TRAN_CSR_TRAN_MODE_RX;
145151

@@ -335,7 +341,8 @@ static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc,
335341
reg |= SPIFMC_TRAN_CSR_TRAN_MODE_RX;
336342
reg |= SPIFMC_TRAN_CSR_TRAN_MODE_TX;
337343

338-
writel(SPIFMC_OPT_DISABLE_FIFO_FLUSH, spifmc->io_base + SPIFMC_OPT);
344+
if (spifmc->chip_info->has_opt_reg)
345+
writel(SPIFMC_OPT_DISABLE_FIFO_FLUSH, spifmc->io_base + SPIFMC_OPT);
339346
} else {
340347
/*
341348
* If write values to the Status Register,
@@ -457,6 +464,11 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
457464
ret = devm_mutex_init(dev, &spifmc->lock);
458465
if (ret)
459466
return ret;
467+
spifmc->chip_info = device_get_match_data(&pdev->dev);
468+
if (!spifmc->chip_info) {
469+
dev_err(&pdev->dev, "Failed to get specific chip info\n");
470+
return -EINVAL;
471+
}
460472

461473
sg2044_spifmc_init(spifmc);
462474
sg2044_spifmc_init_reg(spifmc);
@@ -468,8 +480,13 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
468480
return 0;
469481
}
470482

483+
static const struct sg204x_spifmc_chip_info sg2044_chip_info = {
484+
.has_opt_reg = true,
485+
.rd_fifo_int_trigger_level = SPIFMC_TRAN_CSR_FIFO_TRG_LVL_8_BYTE,
486+
};
487+
471488
static const struct of_device_id sg2044_spifmc_match[] = {
472-
{ .compatible = "sophgo,sg2044-spifmc-nor" },
489+
{ .compatible = "sophgo,sg2044-spifmc-nor", .data = &sg2044_chip_info },
473490
{ /* sentinel */ }
474491
};
475492
MODULE_DEVICE_TABLE(of, sg2044_spifmc_match);

0 commit comments

Comments
 (0)