de2d9148521e50d1bd6570130a2aeb0f32f96fda
[openwrt/staging/aparcar.git] /
1 From d7f7e04f8b67571a4bf5a0dcd4f9da4214f5262c Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 18 Apr 2021 23:46:15 +0200
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 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
14 Link: https://lore.kernel.org/linux-mtd/20210418214616.239574-3-hauke@hauke-m.de
15 ---
16 drivers/mtd/parsers/parser_trx.c | 9 ++++++++-
17 1 file changed, 8 insertions(+), 1 deletion(-)
18
19 --- a/drivers/mtd/parsers/parser_trx.c
20 +++ b/drivers/mtd/parsers/parser_trx.c
21 @@ -51,13 +51,20 @@ static int parser_trx_parse(struct mtd_i
22 const struct mtd_partition **pparts,
23 struct mtd_part_parser_data *data)
24 {
25 + struct device_node *np = mtd_get_of_node(mtd);
26 struct mtd_partition *parts;
27 struct mtd_partition *part;
28 struct trx_header trx;
29 size_t bytes_read;
30 uint8_t curr_part = 0, i = 0;
31 + uint32_t trx_magic = TRX_MAGIC;
32 int err;
33
34 + /* Get different magic from device tree if specified */
35 + err = of_property_read_u32(np, "brcm,trx-magic", &trx_magic);
36 + if (err != 0 && err != -EINVAL)
37 + pr_err("failed to parse \"brcm,trx-magic\" DT attribute, using default: %d\n", err);
38 +
39 parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition),
40 GFP_KERNEL);
41 if (!parts)
42 @@ -70,7 +77,7 @@ static int parser_trx_parse(struct mtd_i
43 return err;
44 }
45
46 - if (trx.magic != TRX_MAGIC) {
47 + if (trx.magic != trx_magic) {
48 kfree(parts);
49 return -ENOENT;
50 }