Skip to content

Commit 259630e

Browse files
claudiu-mdavem330
authored andcommitted
net: mscc: ocelot: move resource ioremap and regmap init to common code
Let's make this ioremap and regmap init code common. It should not be platform dependent as it should be usable by PCI devices too. Use better names where necessary to avoid clashes. Signed-off-by: Claudiu Manoil <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e7be235 commit 259630e

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

drivers/net/ethernet/mscc/ocelot.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,7 @@ void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
546546

547547
int ocelot_regfields_init(struct ocelot *ocelot,
548548
const struct reg_field *const regfields);
549-
struct regmap *ocelot_io_platform_init(struct ocelot *ocelot,
550-
struct platform_device *pdev,
551-
const char *name);
549+
struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
552550

553551
#define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
554552
#define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))

drivers/net/ethernet/mscc/ocelot_board.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
268268
enum ocelot_target id;
269269
char *name;
270270
u8 optional:1;
271-
} res[] = {
271+
} io_target[] = {
272272
{ SYS, "sys" },
273273
{ REW, "rew" },
274274
{ QSYS, "qsys" },
@@ -288,20 +288,23 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
288288
platform_set_drvdata(pdev, ocelot);
289289
ocelot->dev = &pdev->dev;
290290

291-
for (i = 0; i < ARRAY_SIZE(res); i++) {
291+
for (i = 0; i < ARRAY_SIZE(io_target); i++) {
292292
struct regmap *target;
293+
struct resource *res;
294+
295+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
296+
io_target[i].name);
293297

294-
target = ocelot_io_platform_init(ocelot, pdev, res[i].name);
298+
target = ocelot_regmap_init(ocelot, res);
295299
if (IS_ERR(target)) {
296-
if (res[i].optional) {
297-
ocelot->targets[res[i].id] = NULL;
300+
if (io_target[i].optional) {
301+
ocelot->targets[io_target[i].id] = NULL;
298302
continue;
299303
}
300-
301304
return PTR_ERR(target);
302305
}
303306

304-
ocelot->targets[res[i].id] = target;
307+
ocelot->targets[io_target[i].id] = target;
305308
}
306309

307310
hsio = syscon_regmap_lookup_by_compatible("mscc,ocelot-hsio");

drivers/net/ethernet/mscc/ocelot_io.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,16 @@ static struct regmap_config ocelot_regmap_config = {
9797
.reg_stride = 4,
9898
};
9999

100-
struct regmap *ocelot_io_platform_init(struct ocelot *ocelot,
101-
struct platform_device *pdev,
102-
const char *name)
100+
struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res)
103101
{
104-
struct resource *res;
105102
void __iomem *regs;
106103

107-
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
108104
regs = devm_ioremap_resource(ocelot->dev, res);
109105
if (IS_ERR(regs))
110106
return ERR_CAST(regs);
111107

112-
ocelot_regmap_config.name = name;
113-
return devm_regmap_init_mmio(ocelot->dev, regs,
114-
&ocelot_regmap_config);
108+
ocelot_regmap_config.name = res->name;
109+
110+
return devm_regmap_init_mmio(ocelot->dev, regs, &ocelot_regmap_config);
115111
}
116-
EXPORT_SYMBOL(ocelot_io_platform_init);
112+
EXPORT_SYMBOL(ocelot_regmap_init);

0 commit comments

Comments
 (0)