Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Icenowy Zheng and committed by
Chen-Yu Tsai
5828729b ce397d21

+55 -2
+55 -2
drivers/soc/sunxi/sunxi_sram.c
··· 17 17 #include <linux/of_address.h> 18 18 #include <linux/of_device.h> 19 19 #include <linux/platform_device.h> 20 + #include <linux/regmap.h> 20 21 21 22 #include <linux/soc/sunxi/sunxi_sram.h> 22 23 ··· 282 281 } 283 282 EXPORT_SYMBOL(sunxi_sram_release); 284 283 284 + struct sunxi_sramc_variant { 285 + bool has_emac_clock; 286 + }; 287 + 288 + static const struct sunxi_sramc_variant sun4i_a10_sramc_variant = { 289 + /* Nothing special */ 290 + }; 291 + 292 + static const struct sunxi_sramc_variant sun50i_a64_sramc_variant = { 293 + .has_emac_clock = true, 294 + }; 295 + 296 + #define SUNXI_SRAM_EMAC_CLOCK_REG 0x30 297 + static bool sunxi_sram_regmap_accessible_reg(struct device *dev, 298 + unsigned int reg) 299 + { 300 + if (reg == SUNXI_SRAM_EMAC_CLOCK_REG) 301 + return true; 302 + return false; 303 + } 304 + 305 + static struct regmap_config sunxi_sram_emac_clock_regmap = { 306 + .reg_bits = 32, 307 + .val_bits = 32, 308 + .reg_stride = 4, 309 + /* last defined register */ 310 + .max_register = SUNXI_SRAM_EMAC_CLOCK_REG, 311 + /* other devices have no business accessing other registers */ 312 + .readable_reg = sunxi_sram_regmap_accessible_reg, 313 + .writeable_reg = sunxi_sram_regmap_accessible_reg, 314 + }; 315 + 285 316 static int sunxi_sram_probe(struct platform_device *pdev) 286 317 { 287 318 struct resource *res; 288 319 struct dentry *d; 320 + struct regmap *emac_clock; 321 + const struct sunxi_sramc_variant *variant; 289 322 290 323 sram_dev = &pdev->dev; 324 + 325 + variant = of_device_get_match_data(&pdev->dev); 326 + if (!variant) 327 + return -EINVAL; 291 328 292 329 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 293 330 base = devm_ioremap_resource(&pdev->dev, res); ··· 339 300 if (!d) 340 301 return -ENOMEM; 341 302 303 + if (variant->has_emac_clock) { 304 + emac_clock = devm_regmap_init_mmio(&pdev->dev, base, 305 + &sunxi_sram_emac_clock_regmap); 306 + 307 + if (IS_ERR(emac_clock)) 308 + return PTR_ERR(emac_clock); 309 + } 310 + 342 311 return 0; 343 312 } 344 313 345 314 static const struct of_device_id sunxi_sram_dt_match[] = { 346 - { .compatible = "allwinner,sun4i-a10-sram-controller" }, 347 - { .compatible = "allwinner,sun50i-a64-sram-controller" }, 315 + { 316 + .compatible = "allwinner,sun4i-a10-sram-controller", 317 + .data = &sun4i_a10_sramc_variant, 318 + }, 319 + { 320 + .compatible = "allwinner,sun50i-a64-sram-controller", 321 + .data = &sun50i_a64_sramc_variant, 322 + }, 348 323 { }, 349 324 }; 350 325 MODULE_DEVICE_TABLE(of, sunxi_sram_dt_match);