ce353a92262a76a1e5dc5b7245fa9d8adb9a59f8
[openwrt/staging/linusw.git] /
1 From 784866bc4f9f25e0494b77750f95af2a2619e498 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Thu, 16 Dec 2021 12:16:41 +0100
4 Subject: [PATCH 03/15] mtd: nand: ecc: Provide a helper to retrieve a
5 pilelined engine device
6
7 In a pipelined engine situation, we might either have the host which
8 internally has support for error correction, or have it using an
9 external hardware block for this purpose. In the former case, the host
10 is also the ECC engine. In the latter case, it is not. In order to get
11 the right pointers on the right devices (for example: in order to devm_*
12 allocate variables), let's introduce this helper which can safely be
13 called by pipelined ECC engines in order to retrieve the right device
14 structure.
15
16 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
17 Link: https://lore.kernel.org/linux-mtd/20211216111654.238086-16-miquel.raynal@bootlin.com
18 (cherry picked from commit 5145abeb0649acf810a32e63bd762e617a9b3309)
19 ---
20 drivers/mtd/nand/ecc.c | 31 +++++++++++++++++++++++++++++++
21 include/linux/mtd/nand.h | 1 +
22 2 files changed, 32 insertions(+)
23
24 diff --git a/drivers/mtd/nand/ecc.c b/drivers/mtd/nand/ecc.c
25 index 078f5ec38de3..5250764cedee 100644
26 --- a/drivers/mtd/nand/ecc.c
27 +++ b/drivers/mtd/nand/ecc.c
28 @@ -699,6 +699,37 @@ void nand_ecc_put_on_host_hw_engine(struct nand_device *nand)
29 }
30 EXPORT_SYMBOL(nand_ecc_put_on_host_hw_engine);
31
32 +/*
33 + * In the case of a pipelined engine, the device registering the ECC
34 + * engine is not necessarily the ECC engine itself but may be a host controller.
35 + * It is then useful to provide a helper to retrieve the right device object
36 + * which actually represents the ECC engine.
37 + */
38 +struct device *nand_ecc_get_engine_dev(struct device *host)
39 +{
40 + struct platform_device *ecc_pdev;
41 + struct device_node *np;
42 +
43 + /*
44 + * If the device node contains this property, it means we need to follow
45 + * it in order to get the right ECC engine device we are looking for.
46 + */
47 + np = of_parse_phandle(host->of_node, "nand-ecc-engine", 0);
48 + if (!np)
49 + return host;
50 +
51 + ecc_pdev = of_find_device_by_node(np);
52 + if (!ecc_pdev) {
53 + of_node_put(np);
54 + return NULL;
55 + }
56 +
57 + platform_device_put(ecc_pdev);
58 + of_node_put(np);
59 +
60 + return &ecc_pdev->dev;
61 +}
62 +
63 MODULE_LICENSE("GPL");
64 MODULE_AUTHOR("Miquel Raynal <miquel.raynal@bootlin.com>");
65 MODULE_DESCRIPTION("Generic ECC engine");
66 diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
67 index b617efa0a881..615b3e3a3920 100644
68 --- a/include/linux/mtd/nand.h
69 +++ b/include/linux/mtd/nand.h
70 @@ -309,6 +309,7 @@ struct nand_ecc_engine *nand_ecc_get_sw_engine(struct nand_device *nand);
71 struct nand_ecc_engine *nand_ecc_get_on_die_hw_engine(struct nand_device *nand);
72 struct nand_ecc_engine *nand_ecc_get_on_host_hw_engine(struct nand_device *nand);
73 void nand_ecc_put_on_host_hw_engine(struct nand_device *nand);
74 +struct device *nand_ecc_get_engine_dev(struct device *host);
75
76 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING)
77 struct nand_ecc_engine *nand_ecc_sw_hamming_get_engine(void);
78 --
79 2.35.1
80