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");
25 for (i
= 0; i
< TEGRA_EMC_MAX_FREQS
; i
++) {
26 if (timings
[i
].revision
== 0)
32 /* only the nominal and derated tables are expected */
34 dev_warn(dev
, "excess EMC table '%s'\n", rmem
->name
);
39 if (count
!= emc
->num_timings
) {
40 dev_warn(dev
, "%u derated vs. %u nominal entries\n",
41 count
, emc
->num_timings
);
46 emc
->derated
= timings
;
48 emc
->num_timings
= count
;
49 emc
->nominal
= timings
;
53 /* keep track of which table this is */
59 static void tegra210_emc_table_device_release(struct reserved_mem
*rmem
,
62 struct tegra210_emc_timing
*timings
= rmem
->priv
;
63 struct tegra210_emc
*emc
= dev_get_drvdata(dev
);
65 if ((emc
->nominal
&& timings
!= emc
->nominal
) &&
66 (emc
->derated
&& timings
!= emc
->derated
))
67 dev_warn(dev
, "trying to release unassigned EMC table '%s'\n",
73 static const struct reserved_mem_ops tegra210_emc_table_ops
= {
74 .device_init
= tegra210_emc_table_device_init
,
75 .device_release
= tegra210_emc_table_device_release
,
78 static int tegra210_emc_table_init(struct reserved_mem
*rmem
)
80 pr_debug("Tegra210 EMC table at %pa, size %lu bytes\n", &rmem
->base
,
81 (unsigned long)rmem
->size
);
83 rmem
->ops
= &tegra210_emc_table_ops
;
87 RESERVEDMEM_OF_DECLARE(tegra210_emc_table
, "nvidia,tegra210-emc-table",
88 tegra210_emc_table_init
);