47f53ebd51e17f9ce14a116f48dbcf7e80fb9c77
[openwrt/staging/pepe2k.git] /
1 From 01c0da9c8cd3ff6cbe0ced8e28505d4195f60db4 Mon Sep 17 00:00:00 2001
2 From: Claudiu Manoil <claudiu.manoil@nxp.com>
3 Date: Thu, 14 Nov 2019 17:03:20 +0200
4 Subject: [PATCH] net: mscc: ocelot: move resource ioremap and regmap init to
5 common code
6
7 Let's make this ioremap and regmap init code common. It should not
8 be platform dependent as it should be usable by PCI devices too.
9 Use better names where necessary to avoid clashes.
10
11 Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
12 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/ethernet/mscc/ocelot.h | 4 +---
16 drivers/net/ethernet/mscc/ocelot_board.c | 17 ++++++++++-------
17 drivers/net/ethernet/mscc/ocelot_io.c | 14 +++++---------
18 3 files changed, 16 insertions(+), 19 deletions(-)
19
20 --- a/drivers/net/ethernet/mscc/ocelot.h
21 +++ b/drivers/net/ethernet/mscc/ocelot.h
22 @@ -546,9 +546,7 @@ void ocelot_port_writel(struct ocelot_po
23
24 int ocelot_regfields_init(struct ocelot *ocelot,
25 const struct reg_field *const regfields);
26 -struct regmap *ocelot_io_platform_init(struct ocelot *ocelot,
27 - struct platform_device *pdev,
28 - const char *name);
29 +struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
30
31 #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
32 #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
33 --- a/drivers/net/ethernet/mscc/ocelot_board.c
34 +++ b/drivers/net/ethernet/mscc/ocelot_board.c
35 @@ -276,7 +276,7 @@ static int mscc_ocelot_probe(struct plat
36 enum ocelot_target id;
37 char *name;
38 u8 optional:1;
39 - } res[] = {
40 + } io_target[] = {
41 { SYS, "sys" },
42 { REW, "rew" },
43 { QSYS, "qsys" },
44 @@ -296,20 +296,23 @@ static int mscc_ocelot_probe(struct plat
45 platform_set_drvdata(pdev, ocelot);
46 ocelot->dev = &pdev->dev;
47
48 - for (i = 0; i < ARRAY_SIZE(res); i++) {
49 + for (i = 0; i < ARRAY_SIZE(io_target); i++) {
50 struct regmap *target;
51 + struct resource *res;
52
53 - target = ocelot_io_platform_init(ocelot, pdev, res[i].name);
54 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
55 + io_target[i].name);
56 +
57 + target = ocelot_regmap_init(ocelot, res);
58 if (IS_ERR(target)) {
59 - if (res[i].optional) {
60 - ocelot->targets[res[i].id] = NULL;
61 + if (io_target[i].optional) {
62 + ocelot->targets[io_target[i].id] = NULL;
63 continue;
64 }
65 -
66 return PTR_ERR(target);
67 }
68
69 - ocelot->targets[res[i].id] = target;
70 + ocelot->targets[io_target[i].id] = target;
71 }
72
73 hsio = syscon_regmap_lookup_by_compatible("mscc,ocelot-hsio");
74 --- a/drivers/net/ethernet/mscc/ocelot_io.c
75 +++ b/drivers/net/ethernet/mscc/ocelot_io.c
76 @@ -97,20 +97,16 @@ static struct regmap_config ocelot_regma
77 .reg_stride = 4,
78 };
79
80 -struct regmap *ocelot_io_platform_init(struct ocelot *ocelot,
81 - struct platform_device *pdev,
82 - const char *name)
83 +struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res)
84 {
85 - struct resource *res;
86 void __iomem *regs;
87
88 - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
89 regs = devm_ioremap_resource(ocelot->dev, res);
90 if (IS_ERR(regs))
91 return ERR_CAST(regs);
92
93 - ocelot_regmap_config.name = name;
94 - return devm_regmap_init_mmio(ocelot->dev, regs,
95 - &ocelot_regmap_config);
96 + ocelot_regmap_config.name = res->name;
97 +
98 + return devm_regmap_init_mmio(ocelot->dev, regs, &ocelot_regmap_config);
99 }
100 -EXPORT_SYMBOL(ocelot_io_platform_init);
101 +EXPORT_SYMBOL(ocelot_regmap_init);