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+
8792struct 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
95101static 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+
471493static 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};
475498MODULE_DEVICE_TABLE (of , sg2044_spifmc_match );
0 commit comments