1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2017 NVIDIA CORPORATION. All rights reserved.
7 #include <linux/module.h>
8 #include <linux/mod_devicetable.h>
9 #include <linux/of_device.h>
10 #include <linux/platform_device.h>
12 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
13 #include <dt-bindings/memory/tegra186-mc.h>
16 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
17 #include <dt-bindings/memory/tegra194-mc.h>
20 struct tegra186_mc_client
{
24 unsigned int override
;
25 unsigned int security
;
29 struct tegra186_mc_soc
{
30 const struct tegra186_mc_client
*clients
;
31 unsigned int num_clients
;
38 const struct tegra186_mc_soc
*soc
;
41 static void tegra186_mc_program_sid(struct tegra186_mc
*mc
)
45 for (i
= 0; i
< mc
->soc
->num_clients
; i
++) {
46 const struct tegra186_mc_client
*client
= &mc
->soc
->clients
[i
];
47 u32 override
, security
;
49 override
= readl(mc
->regs
+ client
->regs
.override
);
50 security
= readl(mc
->regs
+ client
->regs
.security
);
52 dev_dbg(mc
->dev
, "client %s: override: %x security: %x\n",
53 client
->name
, override
, security
);
55 dev_dbg(mc
->dev
, "setting SID %u for %s\n", client
->sid
,
57 writel(client
->sid
, mc
->regs
+ client
->regs
.override
);
59 override
= readl(mc
->regs
+ client
->regs
.override
);
60 security
= readl(mc
->regs
+ client
->regs
.security
);
62 dev_dbg(mc
->dev
, "client %s: override: %x security: %x\n",
63 client
->name
, override
, security
);
67 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
68 static const struct tegra186_mc_client tegra186_mc_clients
[] = {
71 .sid
= TEGRA186_SID_PASSTHROUGH
,
78 .sid
= TEGRA186_SID_AFI
,
85 .sid
= TEGRA186_SID_HDA
,
92 .sid
= TEGRA186_SID_HOST1X
,
99 .sid
= TEGRA186_SID_NVENC
,
106 .sid
= TEGRA186_SID_SATA
,
113 .sid
= TEGRA186_SID_PASSTHROUGH
,
120 .sid
= TEGRA186_SID_NVENC
,
127 .sid
= TEGRA186_SID_AFI
,
134 .sid
= TEGRA186_SID_HDA
,
141 .sid
= TEGRA186_SID_PASSTHROUGH
,
148 .sid
= TEGRA186_SID_SATA
,
155 .sid
= TEGRA186_SID_ISP
,
162 .sid
= TEGRA186_SID_ISP
,
169 .sid
= TEGRA186_SID_ISP
,
175 .name
= "xusb_hostr",
176 .sid
= TEGRA186_SID_XUSB_HOST
,
182 .name
= "xusb_hostw",
183 .sid
= TEGRA186_SID_XUSB_HOST
,
190 .sid
= TEGRA186_SID_XUSB_DEV
,
197 .sid
= TEGRA186_SID_XUSB_DEV
,
204 .sid
= TEGRA186_SID_TSEC
,
211 .sid
= TEGRA186_SID_TSEC
,
218 .sid
= TEGRA186_SID_GPU
,
225 .sid
= TEGRA186_SID_GPU
,
232 .sid
= TEGRA186_SID_SDMMC1
,
239 .sid
= TEGRA186_SID_SDMMC2
,
246 .sid
= TEGRA186_SID_SDMMC3
,
253 .sid
= TEGRA186_SID_SDMMC4
,
260 .sid
= TEGRA186_SID_SDMMC1
,
267 .sid
= TEGRA186_SID_SDMMC2
,
274 .sid
= TEGRA186_SID_SDMMC3
,
281 .sid
= TEGRA186_SID_SDMMC4
,
288 .sid
= TEGRA186_SID_VIC
,
295 .sid
= TEGRA186_SID_VIC
,
302 .sid
= TEGRA186_SID_VI
,
309 .sid
= TEGRA186_SID_NVDEC
,
316 .sid
= TEGRA186_SID_NVDEC
,
323 .sid
= TEGRA186_SID_APE
,
330 .sid
= TEGRA186_SID_APE
,
337 .sid
= TEGRA186_SID_NVJPG
,
344 .sid
= TEGRA186_SID_NVJPG
,
351 .sid
= TEGRA186_SID_SE
,
358 .sid
= TEGRA186_SID_SE
,
365 .sid
= TEGRA186_SID_ETR
,
372 .sid
= TEGRA186_SID_ETR
,
379 .sid
= TEGRA186_SID_TSECB
,
386 .sid
= TEGRA186_SID_TSECB
,
393 .sid
= TEGRA186_SID_GPU
,
400 .sid
= TEGRA186_SID_GPU
,
407 .sid
= TEGRA186_SID_GPCDMA_0
,
414 .sid
= TEGRA186_SID_GPCDMA_0
,
421 .sid
= TEGRA186_SID_EQOS
,
428 .sid
= TEGRA186_SID_EQOS
,
435 .sid
= TEGRA186_SID_UFSHC
,
442 .sid
= TEGRA186_SID_UFSHC
,
448 .name
= "nvdisplayr",
449 .sid
= TEGRA186_SID_NVDISPLAY
,
456 .sid
= TEGRA186_SID_BPMP
,
463 .sid
= TEGRA186_SID_BPMP
,
470 .sid
= TEGRA186_SID_BPMP
,
477 .sid
= TEGRA186_SID_BPMP
,
484 .sid
= TEGRA186_SID_AON
,
491 .sid
= TEGRA186_SID_AON
,
498 .sid
= TEGRA186_SID_AON
,
505 .sid
= TEGRA186_SID_AON
,
512 .sid
= TEGRA186_SID_SCE
,
519 .sid
= TEGRA186_SID_SCE
,
526 .sid
= TEGRA186_SID_SCE
,
533 .sid
= TEGRA186_SID_SCE
,
540 .sid
= TEGRA186_SID_APE
,
547 .sid
= TEGRA186_SID_APE
,
553 .name
= "nvdisplayr1",
554 .sid
= TEGRA186_SID_NVDISPLAY
,
561 .sid
= TEGRA186_SID_VIC
,
568 .sid
= TEGRA186_SID_NVDEC
,
576 static const struct tegra186_mc_soc tegra186_mc_soc
= {
577 .num_clients
= ARRAY_SIZE(tegra186_mc_clients
),
578 .clients
= tegra186_mc_clients
,
582 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
583 static const struct tegra186_mc_client tegra194_mc_clients
[] = {
586 .sid
= TEGRA194_SID_PASSTHROUGH
,
593 .sid
= TEGRA194_SID_MIU
,
600 .sid
= TEGRA194_SID_MIU
,
607 .sid
= TEGRA194_SID_HDA
,
613 .name
= "host1xdmar",
614 .sid
= TEGRA194_SID_HOST1X
,
621 .sid
= TEGRA194_SID_NVENC
,
628 .sid
= TEGRA194_SID_SATA
,
635 .sid
= TEGRA194_SID_PASSTHROUGH
,
642 .sid
= TEGRA194_SID_NVENC
,
649 .sid
= TEGRA194_SID_HDA
,
656 .sid
= TEGRA194_SID_PASSTHROUGH
,
663 .sid
= TEGRA194_SID_SATA
,
670 .sid
= TEGRA194_SID_ISP
,
677 .sid
= TEGRA194_SID_ISP_FALCON
,
684 .sid
= TEGRA194_SID_ISP
,
691 .sid
= TEGRA194_SID_ISP
,
697 .name
= "xusb_hostr",
698 .sid
= TEGRA194_SID_XUSB_HOST
,
704 .name
= "xusb_hostw",
705 .sid
= TEGRA194_SID_XUSB_HOST
,
712 .sid
= TEGRA194_SID_XUSB_DEV
,
719 .sid
= TEGRA194_SID_XUSB_DEV
,
726 .sid
= TEGRA194_SID_SDMMC1
,
733 .sid
= TEGRA194_SID_SDMMC3
,
740 .sid
= TEGRA194_SID_SDMMC4
,
747 .sid
= TEGRA194_SID_SDMMC1
,
754 .sid
= TEGRA194_SID_SDMMC3
,
761 .sid
= TEGRA194_SID_SDMMC4
,
768 .sid
= TEGRA194_SID_VIC
,
775 .sid
= TEGRA194_SID_VIC
,
782 .sid
= TEGRA194_SID_VI
,
789 .sid
= TEGRA194_SID_NVDEC
,
796 .sid
= TEGRA194_SID_NVDEC
,
803 .sid
= TEGRA194_SID_APE
,
810 .sid
= TEGRA194_SID_APE
,
817 .sid
= TEGRA194_SID_NVJPG
,
824 .sid
= TEGRA194_SID_NVJPG
,
831 .sid
= TEGRA194_SID_PASSTHROUGH
,
838 .sid
= TEGRA194_SID_PASSTHROUGH
,
845 .sid
= TEGRA194_SID_ETR
,
852 .sid
= TEGRA194_SID_ETR
,
859 .sid
= TEGRA194_SID_PASSTHROUGH
,
866 .sid
= TEGRA194_SID_PASSTHROUGH
,
873 .sid
= TEGRA194_SID_EQOS
,
880 .sid
= TEGRA194_SID_EQOS
,
887 .sid
= TEGRA194_SID_UFSHC
,
894 .sid
= TEGRA194_SID_UFSHC
,
900 .name
= "nvdisplayr",
901 .sid
= TEGRA194_SID_NVDISPLAY
,
908 .sid
= TEGRA194_SID_BPMP
,
915 .sid
= TEGRA194_SID_BPMP
,
922 .sid
= TEGRA194_SID_BPMP
,
929 .sid
= TEGRA194_SID_BPMP
,
936 .sid
= TEGRA194_SID_AON
,
943 .sid
= TEGRA194_SID_AON
,
950 .sid
= TEGRA194_SID_AON
,
957 .sid
= TEGRA194_SID_AON
,
964 .sid
= TEGRA194_SID_SCE
,
971 .sid
= TEGRA194_SID_SCE
,
978 .sid
= TEGRA194_SID_SCE
,
985 .sid
= TEGRA194_SID_SCE
,
992 .sid
= TEGRA194_SID_APE
,
999 .sid
= TEGRA194_SID_APE
,
1005 .name
= "nvdisplayr1",
1006 .sid
= TEGRA194_SID_NVDISPLAY
,
1013 .sid
= TEGRA194_SID_VIC
,
1019 .name
= "nvdecsrd1",
1020 .sid
= TEGRA194_SID_NVDEC
,
1027 .sid
= TEGRA194_SID_MIU
,
1034 .sid
= TEGRA194_SID_MIU
,
1041 .sid
= TEGRA194_SID_MIU
,
1048 .sid
= TEGRA194_SID_MIU
,
1055 .sid
= TEGRA194_SID_MIU
,
1062 .sid
= TEGRA194_SID_MIU
,
1069 .sid
= TEGRA194_SID_MIU
,
1076 .sid
= TEGRA194_SID_MIU
,
1083 .sid
= TEGRA194_SID_MIU
,
1090 .sid
= TEGRA194_SID_MIU
,
1097 .sid
= TEGRA194_SID_PASSTHROUGH
,
1104 .sid
= TEGRA194_SID_VI_FALCON
,
1111 .sid
= TEGRA194_SID_VI_FALCON
,
1118 .sid
= TEGRA194_SID_NVDLA0
,
1124 .name
= "dla0falrdb",
1125 .sid
= TEGRA194_SID_NVDLA0
,
1132 .sid
= TEGRA194_SID_NVDLA0
,
1138 .name
= "dla0falwrb",
1139 .sid
= TEGRA194_SID_NVDLA0
,
1146 .sid
= TEGRA194_SID_NVDLA1
,
1152 .name
= "dla1falrdb",
1153 .sid
= TEGRA194_SID_NVDLA1
,
1160 .sid
= TEGRA194_SID_NVDLA1
,
1166 .name
= "dla1falwrb",
1167 .sid
= TEGRA194_SID_NVDLA1
,
1174 .sid
= TEGRA194_SID_PVA0
,
1181 .sid
= TEGRA194_SID_PVA0
,
1188 .sid
= TEGRA194_SID_PVA0
,
1195 .sid
= TEGRA194_SID_PVA0
,
1202 .sid
= TEGRA194_SID_PVA0
,
1209 .sid
= TEGRA194_SID_PVA0
,
1216 .sid
= TEGRA194_SID_PVA1
,
1223 .sid
= TEGRA194_SID_PVA1
,
1230 .sid
= TEGRA194_SID_PVA1
,
1237 .sid
= TEGRA194_SID_PVA1
,
1244 .sid
= TEGRA194_SID_PVA1
,
1251 .sid
= TEGRA194_SID_PVA1
,
1258 .sid
= TEGRA194_SID_RCE
,
1265 .sid
= TEGRA194_SID_RCE
,
1272 .sid
= TEGRA194_SID_RCE
,
1279 .sid
= TEGRA194_SID_RCE
,
1285 .name
= "nvenc1srd",
1286 .sid
= TEGRA194_SID_NVENC1
,
1292 .name
= "nvenc1swr",
1293 .sid
= TEGRA194_SID_NVENC1
,
1300 .sid
= TEGRA194_SID_PCIE0
,
1307 .sid
= TEGRA194_SID_PCIE0
,
1314 .sid
= TEGRA194_SID_PCIE1
,
1321 .sid
= TEGRA194_SID_PCIE1
,
1328 .sid
= TEGRA194_SID_PCIE2
,
1335 .sid
= TEGRA194_SID_PCIE2
,
1342 .sid
= TEGRA194_SID_PCIE3
,
1349 .sid
= TEGRA194_SID_PCIE3
,
1356 .sid
= TEGRA194_SID_PCIE4
,
1363 .sid
= TEGRA194_SID_PCIE4
,
1370 .sid
= TEGRA194_SID_PCIE5
,
1377 .sid
= TEGRA194_SID_PCIE5
,
1384 .sid
= TEGRA194_SID_ISP_FALCON
,
1391 .sid
= TEGRA194_SID_NVDLA0
,
1398 .sid
= TEGRA194_SID_NVDLA1
,
1405 .sid
= TEGRA194_SID_PVA0
,
1412 .sid
= TEGRA194_SID_PVA0
,
1419 .sid
= TEGRA194_SID_PVA1
,
1426 .sid
= TEGRA194_SID_PVA1
,
1433 .sid
= TEGRA194_SID_PCIE5
,
1439 .name
= "nvencsrd1",
1440 .sid
= TEGRA194_SID_NVENC
,
1446 .name
= "nvenc1srd1",
1447 .sid
= TEGRA194_SID_NVENC1
,
1454 .sid
= TEGRA194_SID_ISP
,
1461 .sid
= TEGRA194_SID_PCIE0
,
1467 .name
= "nvdec1srd",
1468 .sid
= TEGRA194_SID_NVDEC1
,
1474 .name
= "nvdec1srd1",
1475 .sid
= TEGRA194_SID_NVDEC1
,
1481 .name
= "nvdec1swr",
1482 .sid
= TEGRA194_SID_NVDEC1
,
1489 .sid
= TEGRA194_SID_MIU
,
1496 .sid
= TEGRA194_SID_MIU
,
1503 .sid
= TEGRA194_SID_MIU
,
1510 .sid
= TEGRA194_SID_MIU
,
1518 static const struct tegra186_mc_soc tegra194_mc_soc
= {
1519 .num_clients
= ARRAY_SIZE(tegra194_mc_clients
),
1520 .clients
= tegra194_mc_clients
,
1524 static int tegra186_mc_probe(struct platform_device
*pdev
)
1526 struct tegra186_mc
*mc
;
1527 struct resource
*res
;
1530 mc
= devm_kzalloc(&pdev
->dev
, sizeof(*mc
), GFP_KERNEL
);
1534 mc
->soc
= of_device_get_match_data(&pdev
->dev
);
1536 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1537 mc
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
1538 if (IS_ERR(mc
->regs
))
1539 return PTR_ERR(mc
->regs
);
1541 mc
->dev
= &pdev
->dev
;
1543 err
= of_platform_populate(pdev
->dev
.of_node
, NULL
, NULL
, &pdev
->dev
);
1547 platform_set_drvdata(pdev
, mc
);
1548 tegra186_mc_program_sid(mc
);
1553 static int tegra186_mc_remove(struct platform_device
*pdev
)
1555 struct tegra186_mc
*mc
= platform_get_drvdata(pdev
);
1557 of_platform_depopulate(mc
->dev
);
1562 static const struct of_device_id tegra186_mc_of_match
[] = {
1563 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
1564 { .compatible
= "nvidia,tegra186-mc", .data
= &tegra186_mc_soc
},
1566 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
1567 { .compatible
= "nvidia,tegra194-mc", .data
= &tegra194_mc_soc
},
1571 MODULE_DEVICE_TABLE(of
, tegra186_mc_of_match
);
1573 static int __maybe_unused
tegra186_mc_suspend(struct device
*dev
)
1578 static int __maybe_unused
tegra186_mc_resume(struct device
*dev
)
1580 struct tegra186_mc
*mc
= dev_get_drvdata(dev
);
1582 tegra186_mc_program_sid(mc
);
1587 static const struct dev_pm_ops tegra186_mc_pm_ops
= {
1588 SET_SYSTEM_SLEEP_PM_OPS(tegra186_mc_suspend
, tegra186_mc_resume
)
1591 static struct platform_driver tegra186_mc_driver
= {
1593 .name
= "tegra186-mc",
1594 .of_match_table
= tegra186_mc_of_match
,
1595 .pm
= &tegra186_mc_pm_ops
,
1596 .suppress_bind_attrs
= true,
1598 .probe
= tegra186_mc_probe
,
1599 .remove
= tegra186_mc_remove
,
1601 module_platform_driver(tegra186_mc_driver
);
1603 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
1604 MODULE_DESCRIPTION("NVIDIA Tegra186 Memory Controller driver");
1605 MODULE_LICENSE("GPL v2");