1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/of_reserved_mem.h>
8 #include "tegra210-emc.h"
10 #define TEGRA_EMC_MAX_FREQS 16
12 static int tegra210_emc_table_device_init(struct reserved_mem
*rmem
,
15 struct tegra210_emc
*emc
= dev_get_drvdata(dev
);
16 struct tegra210_emc_timing
*timings
;
17 unsigned int i
, count
= 0;
19 timings
= memremap(rmem
->base
, rmem
->size
, MEMREMAP_WB
);
21 dev_err(dev
, "failed to map EMC table\n");
27 for (i
= 0; i
< TEGRA_EMC_MAX_FREQS
; i
++) {
28 if (timings
[i
].revision
== 0)
34 /* only the nominal and derated tables are expected */
36 dev_warn(dev
, "excess EMC table '%s'\n", rmem
->name
);
41 if (count
!= emc
->num_timings
) {
42 dev_warn(dev
, "%u derated vs. %u nominal entries\n",
43 count
, emc
->num_timings
);
48 emc
->derated
= timings
;
50 emc
->num_timings
= count
;
51 emc
->nominal
= timings
;
55 /* keep track of which table this is */
61 static void tegra210_emc_table_device_release(struct reserved_mem
*rmem
,
64 struct tegra210_emc_timing
*timings
= rmem
->priv
;
65 struct tegra210_emc
*emc
= dev_get_drvdata(dev
);
67 if ((emc
->nominal
&& timings
!= emc
->nominal
) &&
68 (emc
->derated
&& timings
!= emc
->derated
))
69 dev_warn(dev
, "trying to release unassigned EMC table '%s'\n",
75 static const struct reserved_mem_ops tegra210_emc_table_ops
= {
76 .device_init
= tegra210_emc_table_device_init
,
77 .device_release
= tegra210_emc_table_device_release
,
80 static int tegra210_emc_table_init(struct reserved_mem
*rmem
)
82 pr_debug("Tegra210 EMC table at %pa, size %lu bytes\n", &rmem
->base
,
83 (unsigned long)rmem
->size
);
85 rmem
->ops
= &tegra210_emc_table_ops
;
89 RESERVEDMEM_OF_DECLARE(tegra210_emc_table
, "nvidia,tegra210-emc-table",
90 tegra210_emc_table_init
);