Skip to content

Commit 5828729

Browse files
Icenowywens
authored andcommitted
soc: sunxi: export a regmap for EMAC clock reg on A64
The A64 SRAM controller memory zone has a EMAC clock register, which is needed by the Ethernet MAC driver (dwmac-sun8i). Export a regmap for this register on A64. Signed-off-by: Icenowy Zheng <icenowy@aosc.io> [wens@csie.org: export whole address range with only EMAC register accessible and drop regmap name] Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
1 parent ce397d2 commit 5828729

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

drivers/soc/sunxi/sunxi_sram.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/of_address.h>
1818
#include <linux/of_device.h>
1919
#include <linux/platform_device.h>
20+
#include <linux/regmap.h>
2021

2122
#include <linux/soc/sunxi/sunxi_sram.h>
2223

@@ -281,13 +282,51 @@ int sunxi_sram_release(struct device *dev)
281282
}
282283
EXPORT_SYMBOL(sunxi_sram_release);
283284

285+
struct sunxi_sramc_variant {
286+
bool has_emac_clock;
287+
};
288+
289+
static const struct sunxi_sramc_variant sun4i_a10_sramc_variant = {
290+
/* Nothing special */
291+
};
292+
293+
static const struct sunxi_sramc_variant sun50i_a64_sramc_variant = {
294+
.has_emac_clock = true,
295+
};
296+
297+
#define SUNXI_SRAM_EMAC_CLOCK_REG 0x30
298+
static bool sunxi_sram_regmap_accessible_reg(struct device *dev,
299+
unsigned int reg)
300+
{
301+
if (reg == SUNXI_SRAM_EMAC_CLOCK_REG)
302+
return true;
303+
return false;
304+
}
305+
306+
static struct regmap_config sunxi_sram_emac_clock_regmap = {
307+
.reg_bits = 32,
308+
.val_bits = 32,
309+
.reg_stride = 4,
310+
/* last defined register */
311+
.max_register = SUNXI_SRAM_EMAC_CLOCK_REG,
312+
/* other devices have no business accessing other registers */
313+
.readable_reg = sunxi_sram_regmap_accessible_reg,
314+
.writeable_reg = sunxi_sram_regmap_accessible_reg,
315+
};
316+
284317
static int sunxi_sram_probe(struct platform_device *pdev)
285318
{
286319
struct resource *res;
287320
struct dentry *d;
321+
struct regmap *emac_clock;
322+
const struct sunxi_sramc_variant *variant;
288323

289324
sram_dev = &pdev->dev;
290325

326+
variant = of_device_get_match_data(&pdev->dev);
327+
if (!variant)
328+
return -EINVAL;
329+
291330
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
292331
base = devm_ioremap_resource(&pdev->dev, res);
293332
if (IS_ERR(base))
@@ -300,12 +339,26 @@ static int sunxi_sram_probe(struct platform_device *pdev)
300339
if (!d)
301340
return -ENOMEM;
302341

342+
if (variant->has_emac_clock) {
343+
emac_clock = devm_regmap_init_mmio(&pdev->dev, base,
344+
&sunxi_sram_emac_clock_regmap);
345+
346+
if (IS_ERR(emac_clock))
347+
return PTR_ERR(emac_clock);
348+
}
349+
303350
return 0;
304351
}
305352

306353
static const struct of_device_id sunxi_sram_dt_match[] = {
307-
{ .compatible = "allwinner,sun4i-a10-sram-controller" },
308-
{ .compatible = "allwinner,sun50i-a64-sram-controller" },
354+
{
355+
.compatible = "allwinner,sun4i-a10-sram-controller",
356+
.data = &sun4i_a10_sramc_variant,
357+
},
358+
{
359+
.compatible = "allwinner,sun50i-a64-sram-controller",
360+
.data = &sun50i_a64_sramc_variant,
361+
},
309362
{ },
310363
};
311364
MODULE_DEVICE_TABLE(of, sunxi_sram_dt_match);

0 commit comments

Comments
 (0)