Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Add MediaTek MT7986 SPI NAND support

Merge series from Xiangsheng Hou <xiangsheng.hou@mediatek.com>:

This patch series split from bellow series which pick-up spi relevant patches
https://lore.kernel.org/all/20230130030656.12127-1-xiangsheng.hou@mediatek.com.
This series add MediaTek MT7986 SPI NAND controller support, add read latch
latency, smaple delay adjust and add optional nfi_hclk.

+84 -11
+45 -9
Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml
··· 18 18 using the accompanying ECC engine. There should be only one spi 19 19 slave device following generic spi bindings. 20 20 21 - allOf: 22 - - $ref: /schemas/spi/spi-controller.yaml# 23 - 24 21 properties: 25 22 compatible: 26 23 enum: 27 24 - mediatek,mt7622-snand 28 25 - mediatek,mt7629-snand 26 + - mediatek,mt7986-snand 29 27 30 28 reg: 31 29 items: ··· 34 36 - description: NFI interrupt 35 37 36 38 clocks: 37 - items: 38 - - description: clock used for the controller 39 - - description: clock used for the SPI bus 39 + minItems: 2 40 + maxItems: 3 40 41 41 42 clock-names: 42 - items: 43 - - const: nfi_clk 44 - - const: pad_clk 43 + minItems: 2 44 + maxItems: 3 45 45 46 46 nand-ecc-engine: 47 47 description: device-tree node of the accompanying ECC engine. 48 48 $ref: /schemas/types.yaml#/definitions/phandle 49 + 50 + mediatek,rx-latch-latency-ns: 51 + description: Data read latch latency, unit is nanoseconds. 49 52 50 53 required: 51 54 - compatible ··· 55 56 - clocks 56 57 - clock-names 57 58 - nand-ecc-engine 59 + 60 + allOf: 61 + - $ref: /schemas/spi/spi-controller.yaml# 62 + - if: 63 + properties: 64 + compatible: 65 + enum: 66 + - mediatek,mt7622-snand 67 + - mediatek,mt7629-snand 68 + then: 69 + properties: 70 + clocks: 71 + items: 72 + - description: clock used for the controller 73 + - description: clock used for the SPI bus 74 + clock-names: 75 + items: 76 + - const: nfi_clk 77 + - const: pad_clk 78 + 79 + - if: 80 + properties: 81 + compatible: 82 + enum: 83 + - mediatek,mt7986-snand 84 + then: 85 + properties: 86 + clocks: 87 + items: 88 + - description: clock used for the controller 89 + - description: clock used for the SPI bus 90 + - description: clock used for the AHB bus 91 + clock-names: 92 + items: 93 + - const: nfi_clk 94 + - const: pad_clk 95 + - const: nfi_hclk 58 96 59 97 unevaluatedProperties: false 60 98
+39 -2
drivers/spi/spi-mtk-snfi.c
··· 195 195 #define DATA_READ_MODE_X4 2 196 196 #define DATA_READ_MODE_DUAL 5 197 197 #define DATA_READ_MODE_QUAD 6 198 + #define DATA_READ_LATCH_LAT GENMASK(9, 8) 199 + #define DATA_READ_LATCH_LAT_S 8 198 200 #define PG_LOAD_CUSTOM_EN BIT(7) 199 201 #define DATARD_CUSTOM_EN BIT(6) 200 202 #define CS_DESELECT_CYC_S 0 ··· 207 205 208 206 #define SNF_DLY_CTL3 0x548 209 207 #define SFCK_SAM_DLY_S 0 208 + #define SFCK_SAM_DLY GENMASK(5, 0) 209 + #define SFCK_SAM_DLY_TOTAL 9 210 + #define SFCK_SAM_DLY_RANGE 47 210 211 211 212 #define SNF_STA_CTL1 0x550 212 213 #define CUS_PG_DONE BIT(28) ··· 302 297 struct device *dev; 303 298 struct clk *nfi_clk; 304 299 struct clk *pad_clk; 300 + struct clk *nfi_hclk; 305 301 void __iomem *nfi_base; 306 302 int irq; 307 303 struct completion op_done; ··· 1345 1339 dev_err(ms->dev, "unable to enable pad clk\n"); 1346 1340 goto err1; 1347 1341 } 1342 + ret = clk_prepare_enable(ms->nfi_hclk); 1343 + if (ret) { 1344 + dev_err(ms->dev, "unable to enable nfi hclk\n"); 1345 + goto err2; 1346 + } 1347 + 1348 1348 return 0; 1349 + 1350 + err2: 1351 + clk_disable_unprepare(ms->pad_clk); 1349 1352 err1: 1350 1353 clk_disable_unprepare(ms->nfi_clk); 1351 1354 return ret; ··· 1362 1347 1363 1348 static void mtk_snand_disable_clk(struct mtk_snand *ms) 1364 1349 { 1350 + clk_disable_unprepare(ms->nfi_hclk); 1365 1351 clk_disable_unprepare(ms->pad_clk); 1366 1352 clk_disable_unprepare(ms->nfi_clk); 1367 1353 } ··· 1373 1357 const struct of_device_id *dev_id; 1374 1358 struct spi_controller *ctlr; 1375 1359 struct mtk_snand *ms; 1360 + unsigned long spi_freq; 1361 + u32 val = 0; 1376 1362 int ret; 1377 1363 1378 1364 dev_id = of_match_node(mtk_snand_ids, np); ··· 1419 1401 goto release_ecc; 1420 1402 } 1421 1403 1404 + ms->nfi_hclk = devm_clk_get_optional(&pdev->dev, "nfi_hclk"); 1405 + if (IS_ERR(ms->nfi_hclk)) { 1406 + ret = PTR_ERR(ms->nfi_hclk); 1407 + dev_err(&pdev->dev, "unable to get nfi_hclk, err = %d\n", ret); 1408 + goto release_ecc; 1409 + } 1410 + 1422 1411 ret = mtk_snand_enable_clk(ms); 1423 1412 if (ret) 1424 1413 goto release_ecc; ··· 1453 1428 // switch to SNFI mode 1454 1429 nfi_write32(ms, SNF_CFG, SPI_MODE); 1455 1430 1431 + ret = of_property_read_u32(np, "rx-sample-delay-ns", &val); 1432 + if (!ret) 1433 + nfi_rmw32(ms, SNF_DLY_CTL3, SFCK_SAM_DLY, 1434 + val * SFCK_SAM_DLY_RANGE / SFCK_SAM_DLY_TOTAL); 1435 + 1436 + ret = of_property_read_u32(np, "mediatek,rx-latch-latency-ns", &val); 1437 + if (!ret) { 1438 + spi_freq = clk_get_rate(ms->pad_clk); 1439 + val = DIV_ROUND_CLOSEST(val, NSEC_PER_SEC / spi_freq); 1440 + nfi_rmw32(ms, SNF_MISC_CTL, DATA_READ_LATCH_LAT, 1441 + val << DATA_READ_LATCH_LAT_S); 1442 + } 1443 + 1456 1444 // setup an initial page format for ops matching page_cache_op template 1457 1445 // before ECC is called. 1458 - ret = mtk_snand_setup_pagefmt(ms, ms->caps->sector_size, 1459 - ms->caps->spare_sizes[0]); 1446 + ret = mtk_snand_setup_pagefmt(ms, SZ_2K, SZ_64); 1460 1447 if (ret) { 1461 1448 dev_err(ms->dev, "failed to set initial page format\n"); 1462 1449 goto disable_clk;