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

memory: tegra: Extract setup code into callback

Separate the setup code for Tegra30 and later into a ->setup() callback
and set it for all applicable chips.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20210602163302.120041-7-thierry.reding@gmail.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

authored by

Thierry Reding and committed by
Krzysztof Kozlowski
ddeceab0 c64738e9

+84 -57
+70 -57
drivers/memory/tegra/mc.c
··· 299 299 return 0; 300 300 } 301 301 302 - static int tegra_mc_setup_latency_allowance(struct tegra_mc *mc) 303 - { 304 - unsigned long long tick; 305 - unsigned int i; 306 - u32 value; 307 - 308 - /* compute the number of MC clock cycles per tick */ 309 - tick = (unsigned long long)mc->tick * clk_get_rate(mc->clk); 310 - do_div(tick, NSEC_PER_SEC); 311 - 312 - value = mc_readl(mc, MC_EMEM_ARB_CFG); 313 - value &= ~MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE_MASK; 314 - value |= MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE(tick); 315 - mc_writel(mc, value, MC_EMEM_ARB_CFG); 316 - 317 - /* write latency allowance defaults */ 318 - for (i = 0; i < mc->soc->num_clients; i++) { 319 - const struct tegra_mc_client *client = &mc->soc->clients[i]; 320 - u32 value; 321 - 322 - value = mc_readl(mc, client->regs.la.reg); 323 - value &= ~(client->regs.la.mask << client->regs.la.shift); 324 - value |= (client->regs.la.def & client->regs.la.mask) << client->regs.la.shift; 325 - mc_writel(mc, value, client->regs.la.reg); 326 - } 327 - 328 - /* latch new values */ 329 - mc_writel(mc, MC_TIMING_UPDATE, MC_TIMING_CONTROL); 330 - 331 - return 0; 332 - } 333 - 334 302 int tegra_mc_write_emem_configuration(struct tegra_mc *mc, unsigned long rate) 335 303 { 336 304 unsigned int i; ··· 335 367 return dram_count; 336 368 } 337 369 EXPORT_SYMBOL_GPL(tegra_mc_get_emem_device_count); 370 + 371 + #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \ 372 + defined(CONFIG_ARCH_TEGRA_114_SOC) || \ 373 + defined(CONFIG_ARCH_TEGRA_124_SOC) || \ 374 + defined(CONFIG_ARCH_TEGRA_132_SOC) || \ 375 + defined(CONFIG_ARCH_TEGRA_210_SOC) 376 + static int tegra_mc_setup_latency_allowance(struct tegra_mc *mc) 377 + { 378 + unsigned long long tick; 379 + unsigned int i; 380 + u32 value; 381 + 382 + /* compute the number of MC clock cycles per tick */ 383 + tick = (unsigned long long)mc->tick * clk_get_rate(mc->clk); 384 + do_div(tick, NSEC_PER_SEC); 385 + 386 + value = mc_readl(mc, MC_EMEM_ARB_CFG); 387 + value &= ~MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE_MASK; 388 + value |= MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE(tick); 389 + mc_writel(mc, value, MC_EMEM_ARB_CFG); 390 + 391 + /* write latency allowance defaults */ 392 + for (i = 0; i < mc->soc->num_clients; i++) { 393 + const struct tegra_mc_client *client = &mc->soc->clients[i]; 394 + u32 value; 395 + 396 + value = mc_readl(mc, client->regs.la.reg); 397 + value &= ~(client->regs.la.mask << client->regs.la.shift); 398 + value |= (client->regs.la.def & client->regs.la.mask) << client->regs.la.shift; 399 + mc_writel(mc, value, client->regs.la.reg); 400 + } 401 + 402 + /* latch new values */ 403 + mc_writel(mc, MC_TIMING_UPDATE, MC_TIMING_CONTROL); 404 + 405 + return 0; 406 + } 338 407 339 408 static int load_one_timing(struct tegra_mc *mc, 340 409 struct tegra_mc_timing *timing, ··· 463 458 464 459 return 0; 465 460 } 461 + 462 + int tegra30_mc_probe(struct tegra_mc *mc) 463 + { 464 + int err; 465 + 466 + mc->clk = devm_clk_get_optional(mc->dev, "mc"); 467 + if (IS_ERR(mc->clk)) { 468 + dev_err(mc->dev, "failed to get MC clock: %ld\n", PTR_ERR(mc->clk)); 469 + return PTR_ERR(mc->clk); 470 + } 471 + 472 + /* ensure that debug features are disabled */ 473 + mc_writel(mc, 0x00000000, MC_TIMING_CONTROL_DBG); 474 + 475 + err = tegra_mc_setup_latency_allowance(mc); 476 + if (err < 0) { 477 + dev_err(mc->dev, "failed to setup latency allowance: %d\n", err); 478 + return err; 479 + } 480 + 481 + err = tegra_mc_setup_timings(mc); 482 + if (err < 0) { 483 + dev_err(mc->dev, "failed to setup timings: %d\n", err); 484 + return err; 485 + } 486 + 487 + return 0; 488 + } 489 + 490 + const struct tegra_mc_ops tegra30_mc_ops = { 491 + .probe = tegra30_mc_probe, 492 + }; 493 + #endif 466 494 467 495 static const char *const status_names[32] = { 468 496 [ 1] = "External interrupt", ··· 815 777 if (IS_ERR(mc->regs)) 816 778 return PTR_ERR(mc->regs); 817 779 818 - mc->clk = devm_clk_get(&pdev->dev, "mc"); 819 - if (IS_ERR(mc->clk)) { 820 - dev_err(&pdev->dev, "failed to get MC clock: %ld\n", 821 - PTR_ERR(mc->clk)); 822 - return PTR_ERR(mc->clk); 823 - } 824 - 825 780 mc->debugfs.root = debugfs_create_dir("mc", NULL); 826 781 827 782 if (mc->soc->ops && mc->soc->ops->probe) { ··· 829 798 } else 830 799 #endif 831 800 { 832 - /* ensure that debug features are disabled */ 833 - mc_writel(mc, 0x00000000, MC_TIMING_CONTROL_DBG); 834 - 835 - err = tegra_mc_setup_latency_allowance(mc); 836 - if (err < 0) { 837 - dev_err(&pdev->dev, 838 - "failed to setup latency allowance: %d\n", 839 - err); 840 - return err; 841 - } 842 - 843 801 isr = tegra_mc_irq; 844 - 845 - err = tegra_mc_setup_timings(mc); 846 - if (err < 0) { 847 - dev_err(&pdev->dev, "failed to setup timings: %d\n", 848 - err); 849 - return err; 850 - } 851 802 } 852 803 853 804 mc->irq = platform_get_irq(pdev, 0);
+9
drivers/memory/tegra/mc.h
··· 129 129 extern const struct tegra_mc_soc tegra210_mc_soc; 130 130 #endif 131 131 132 + #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \ 133 + defined(CONFIG_ARCH_TEGRA_114_SOC) || \ 134 + defined(CONFIG_ARCH_TEGRA_124_SOC) || \ 135 + defined(CONFIG_ARCH_TEGRA_132_SOC) || \ 136 + defined(CONFIG_ARCH_TEGRA_210_SOC) 137 + int tegra30_mc_probe(struct tegra_mc *mc); 138 + extern const struct tegra_mc_ops tegra30_mc_ops; 139 + #endif 140 + 132 141 /* 133 142 * These IDs are for internal use of Tegra ICC drivers. The ID numbers are 134 143 * chosen such that they don't conflict with the device-tree ICC node IDs.
+1
drivers/memory/tegra/tegra114.c
··· 1113 1113 .reset_ops = &tegra_mc_reset_ops_common, 1114 1114 .resets = tegra114_mc_resets, 1115 1115 .num_resets = ARRAY_SIZE(tegra114_mc_resets), 1116 + .ops = &tegra30_mc_ops, 1116 1117 };
+2
drivers/memory/tegra/tegra124.c
··· 1274 1274 .resets = tegra124_mc_resets, 1275 1275 .num_resets = ARRAY_SIZE(tegra124_mc_resets), 1276 1276 .icc_ops = &tegra124_mc_icc_ops, 1277 + .ops = &tegra30_mc_ops, 1277 1278 }; 1278 1279 #endif /* CONFIG_ARCH_TEGRA_124_SOC */ 1279 1280 ··· 1306 1305 .resets = tegra124_mc_resets, 1307 1306 .num_resets = ARRAY_SIZE(tegra124_mc_resets), 1308 1307 .icc_ops = &tegra124_mc_icc_ops, 1308 + .ops = &tegra30_mc_ops, 1309 1309 }; 1310 1310 #endif /* CONFIG_ARCH_TEGRA_132_SOC */
+1
drivers/memory/tegra/tegra210.c
··· 1286 1286 .reset_ops = &tegra_mc_reset_ops_common, 1287 1287 .resets = tegra210_mc_resets, 1288 1288 .num_resets = ARRAY_SIZE(tegra210_mc_resets), 1289 + .ops = &tegra30_mc_ops, 1289 1290 };
+1
drivers/memory/tegra/tegra30.c
··· 1399 1399 .resets = tegra30_mc_resets, 1400 1400 .num_resets = ARRAY_SIZE(tegra30_mc_resets), 1401 1401 .icc_ops = &tegra30_mc_icc_ops, 1402 + .ops = &tegra30_mc_ops, 1402 1403 };