Skip to content

Commit f54b69a

Browse files
committed
spi: sophgo: Add SPI NOR controller for SG2042
Merge series from Zixian Zeng <[email protected]>: Add support SPI NOR flash memory controller for SG2042, using upstreamed SG2044 SPI NOR driver. Tested on SG2042 Pioneer Box, read, write operations. Thanks Chen Wang who provided machine and guidance.
2 parents b71cb34 + f6b1594 commit f54b69a

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

Documentation/devicetree/bindings/spi/spi-sg2044-nor.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ allOf:
1414

1515
properties:
1616
compatible:
17-
oneOf:
18-
- const: sophgo,sg2044-spifmc-nor
19-
- items:
20-
- enum:
21-
- sophgo,sg2042-spifmc-nor
22-
- const: sophgo,sg2044-spifmc-nor
17+
enum:
18+
- sophgo,sg2042-spifmc-nor
19+
- sophgo,sg2044-spifmc-nor
2320

2421
reg:
2522
maxItems: 1

drivers/spi/spi-sg2044-nor.c

Lines changed: 26 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,19 @@ 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+
488+
static const struct sg204x_spifmc_chip_info sg2042_chip_info = {
489+
.has_opt_reg = false,
490+
.rd_fifo_int_trigger_level = SPIFMC_TRAN_CSR_FIFO_TRG_LVL_1_BYTE,
491+
};
492+
471493
static const struct of_device_id sg2044_spifmc_match[] = {
472-
{ .compatible = "sophgo,sg2044-spifmc-nor" },
494+
{ .compatible = "sophgo,sg2044-spifmc-nor", .data = &sg2044_chip_info },
495+
{ .compatible = "sophgo,sg2042-spifmc-nor", .data = &sg2042_chip_info },
473496
{ /* sentinel */ }
474497
};
475498
MODULE_DEVICE_TABLE(of, sg2044_spifmc_match);

0 commit comments

Comments
 (0)