@@ -1510,8 +1510,8 @@ static int cqspi_of_get_pdata(struct cqspi_st *cqspi)
15101510 cqspi -> is_decoded_cs = of_property_read_bool (np , "cdns,is-decoded-cs" );
15111511
15121512 if (of_property_read_u32 (np , "cdns,fifo-depth" , & cqspi -> fifo_depth )) {
1513- dev_err ( dev , "couldn't determine fifo- depth\n" );
1514- return - ENXIO ;
1513+ /* Zero signals FIFO depth should be runtime detected. */
1514+ cqspi -> fifo_depth = 0 ;
15151515 }
15161516
15171517 if (of_property_read_u32 (np , "cdns,fifo-width" , & cqspi -> fifo_width )) {
@@ -1541,8 +1541,6 @@ static void cqspi_controller_init(struct cqspi_st *cqspi)
15411541{
15421542 u32 reg ;
15431543
1544- cqspi_controller_enable (cqspi , 0 );
1545-
15461544 /* Configure the remap address register, no remap */
15471545 writel (0 , cqspi -> iobase + CQSPI_REG_REMAP );
15481546
@@ -1576,8 +1574,29 @@ static void cqspi_controller_init(struct cqspi_st *cqspi)
15761574 reg |= CQSPI_REG_CONFIG_DMA_MASK ;
15771575 writel (reg , cqspi -> iobase + CQSPI_REG_CONFIG );
15781576 }
1577+ }
15791578
1580- cqspi_controller_enable (cqspi , 1 );
1579+ static void cqspi_controller_detect_fifo_depth (struct cqspi_st * cqspi )
1580+ {
1581+ struct device * dev = & cqspi -> pdev -> dev ;
1582+ u32 reg , fifo_depth ;
1583+
1584+ /*
1585+ * Bits N-1:0 are writable while bits 31:N are read as zero, with 2^N
1586+ * the FIFO depth.
1587+ */
1588+ writel (U32_MAX , cqspi -> iobase + CQSPI_REG_SRAMPARTITION );
1589+ reg = readl (cqspi -> iobase + CQSPI_REG_SRAMPARTITION );
1590+ fifo_depth = reg + 1 ;
1591+
1592+ /* FIFO depth of zero means no value from devicetree was provided. */
1593+ if (cqspi -> fifo_depth == 0 ) {
1594+ cqspi -> fifo_depth = fifo_depth ;
1595+ dev_dbg (dev , "using FIFO depth of %u\n" , fifo_depth );
1596+ } else if (fifo_depth != cqspi -> fifo_depth ) {
1597+ dev_warn (dev , "detected FIFO depth (%u) different from config (%u)\n" ,
1598+ fifo_depth , cqspi -> fifo_depth );
1599+ }
15811600}
15821601
15831602static int cqspi_request_mmap_dma (struct cqspi_st * cqspi )
@@ -1730,6 +1749,7 @@ static int cqspi_probe(struct platform_device *pdev)
17301749 cqspi -> pdev = pdev ;
17311750 cqspi -> host = host ;
17321751 cqspi -> is_jh7110 = false;
1752+ cqspi -> ddata = ddata = of_device_get_match_data (dev );
17331753 platform_set_drvdata (pdev , cqspi );
17341754
17351755 /* Obtain configuration from OF. */
@@ -1821,8 +1841,6 @@ static int cqspi_probe(struct platform_device *pdev)
18211841 /* write completion is supported by default */
18221842 cqspi -> wr_completion = true;
18231843
1824- ddata = of_device_get_match_data (dev );
1825- cqspi -> ddata = ddata ;
18261844 if (ddata ) {
18271845 if (ddata -> quirks & CQSPI_NEEDS_WR_DELAY )
18281846 cqspi -> wr_delay = 50 * DIV_ROUND_UP (NSEC_PER_SEC ,
@@ -1864,7 +1882,10 @@ static int cqspi_probe(struct platform_device *pdev)
18641882 }
18651883
18661884 cqspi_wait_idle (cqspi );
1885+ cqspi_controller_enable (cqspi , 0 );
1886+ cqspi_controller_detect_fifo_depth (cqspi );
18671887 cqspi_controller_init (cqspi );
1888+ cqspi_controller_enable (cqspi , 1 );
18681889 cqspi -> current_cs = -1 ;
18691890 cqspi -> sclk = 0 ;
18701891
@@ -1947,7 +1968,9 @@ static int cqspi_runtime_resume(struct device *dev)
19471968
19481969 clk_prepare_enable (cqspi -> clk );
19491970 cqspi_wait_idle (cqspi );
1971+ cqspi_controller_enable (cqspi , 0 );
19501972 cqspi_controller_init (cqspi );
1973+ cqspi_controller_enable (cqspi , 1 );
19511974
19521975 cqspi -> current_cs = -1 ;
19531976 cqspi -> sclk = 0 ;
0 commit comments