mediatek: update mtd parser patches
[openwrt/staging/ynezz.git] / target / linux / mediatek / patches-5.4 / 0350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch
1 From 0600e3d81628002a5cd80cf83ee454851b0063c0 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 7 Mar 2021 18:19:26 +0100
4 Subject: mtd: parsers: trx: Allow to specify brcm,trx-magic in DT
5
6 Buffalo uses a different TRX magic for every device, to be able to use
7 this trx parser, make it possible to specify the TRX magic in device
8 tree. If no TRX magic is specified in device tree, the standard value
9 will be used. This value should only be specified if a vendor chooses to
10 use a non standard TRX magic.
11
12 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
13 ---
14 .../bindings/mtd/partitions/brcm,trx.txt | 5 +++++
15 drivers/mtd/parsers/parser_trx.c | 21 ++++++++++++++++++-
16 2 files changed, 25 insertions(+), 1 deletion(-)
17
18 --- a/Documentation/devicetree/bindings/mtd/partitions/brcm,trx.txt
19 +++ b/Documentation/devicetree/bindings/mtd/partitions/brcm,trx.txt
20 @@ -28,6 +28,11 @@ detected by a software parsing TRX heade
21 Required properties:
22 - compatible : (required) must be "brcm,trx"
23
24 +Optional properties:
25 +
26 +- brcm,trx-magic: TRX magic, if it is different from the default magic
27 + 0x30524448 as a u32.
28 +
29 Example:
30
31 flash@0 {
32 --- a/drivers/mtd/parsers/parser_trx.c
33 +++ b/drivers/mtd/parsers/parser_trx.c
34 @@ -74,6 +74,24 @@ out_default:
35 return "rootfs";
36 }
37
38 +static uint32_t parser_trx_get_magic(struct mtd_info *mtd)
39 +{
40 + uint32_t trx_magic = TRX_MAGIC;
41 + struct device_node *np;
42 + int err;
43 +
44 + np = mtd_get_of_node(mtd);
45 + if (!np)
46 + return trx_magic;
47 +
48 + /* Get different magic from device tree if specified */
49 + err = of_property_read_u32(np, "brcm,trx-magic", &trx_magic);
50 + if (err != 0 && err != -EINVAL)
51 + pr_err("failed to parse \"brcm,trx-magic\" DT attribute, use default: %d\n", err);
52 +
53 + return trx_magic;
54 +}
55 +
56 static int parser_trx_parse(struct mtd_info *mtd,
57 const struct mtd_partition **pparts,
58 struct mtd_part_parser_data *data)
59 @@ -83,6 +101,7 @@ static int parser_trx_parse(struct mtd_i
60 struct trx_header trx;
61 size_t bytes_read;
62 uint8_t curr_part = 0, i = 0;
63 + uint32_t trx_magic = parser_trx_get_magic(mtd);
64 int err;
65
66 parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition),
67 @@ -97,7 +116,7 @@ static int parser_trx_parse(struct mtd_i
68 return err;
69 }
70
71 - if (trx.magic != TRX_MAGIC) {
72 + if (trx.magic != trx_magic) {
73 kfree(parts);
74 return -ENOENT;
75 }