This series of patches add ACPI support for Tegra194 and Tegra234 in
Tegra fuse and apbmisc drivers. It also adds support for Tegra241
which uses ACPI boot.
Kartik (8):
mm/util: Introduce kmemdup_array() to duplicate an array
soc/tegra: fuse: Use dev_err_probe for probe failures
soc/tegra: fuse: Refactor resource mapping
soc/tegra: fuse: Add tegra_acpi_init_apbmisc()
soc/tegra: fuse: Add function to add lookups
soc/tegra: fuse: Add function to print SKU info
soc/tegra: fuse: Add ACPI support for Tegra194 and Tegra234
soc/tegra: fuse: Add support for Tegra241
drivers/soc/tegra/Kconfig | 5 ++
drivers/soc/tegra/fuse/fuse-tegra.c | 117 +++++++++++++++++++------
drivers/soc/tegra/fuse/fuse-tegra30.c | 20 +++++
drivers/soc/tegra/fuse/fuse.h | 5 ++
drivers/soc/tegra/fuse/tegra-apbmisc.c | 110 +++++++++++++++++++----
include/linux/string.h | 2 +
include/soc/tegra/fuse.h | 1 +
mm/util.c | 34 +++++++
8 files changed, 249 insertions(+), 45 deletions(-)
---
v3 -> v4:
* Added following patch to introduce kmemdup_array:
"mm/util: Introduce kmemdup_array() to duplicate an array"
* Add "soc/tegra: fuse: Use dev_err_probe for probe failures".
v2 -> v3:
* Minor changes in following patches:
soc/tegra: fuse: Add tegra_acpi_init_apbmisc()
soc/tegra: fuse: Add ACPI support for Tegra194 and Tegra234
v1 -> v2:
* Used '--patience' while formatting patches.
* Added "soc/tegra: fuse: Refactor resource mapping" to share
the common code between tegra_init_apbmisc() and
tegra_acpi_init_apbmisc() functions.
* Dropped "soc/tegra: fuse: Add function to register nvmem"
as ACPI and device-tree boot are sharing the same probe.
So, no need to refactor the code here.
---
--
2.34.1
Add helper function tegra_fuse_add_lookups() to register Tegra fuse
nvmem lookups. So, this can be shared between tegra_fuse_init() and
ACPI probe, which is to be introduced later.
Use kmemdup_array to duplicate fuse->soc->lookups.
Signed-off-by: Kartik <[email protected]>
---
v3 -> v4:
* Use kmemdup_array to duplicate fuse->soc->lookups.
* Return err at the end of tegra_fuse_probe to remove
redundant code.
v1 -> v2:
* Use size_mul to calculate lookups array size.
---
drivers/soc/tegra/fuse/fuse-tegra.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index 98805885158e..ddf25a1bb19d 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -113,6 +113,21 @@ static void tegra_fuse_restore(void *base)
fuse->clk = NULL;
}
+static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
+{
+ size_t size;
+ int ret;
+
+ ret = kmemdup_array((void *)&fuse->lookups, &size, fuse->soc->lookups,
+ sizeof(*fuse->lookups), fuse->soc->num_lookups, GFP_KERNEL);
+ if (ret)
+ return ret;
+
+ nvmem_add_cell_lookups(fuse->lookups, size);
+
+ return 0;
+}
+
static int tegra_fuse_probe(struct platform_device *pdev)
{
void __iomem *base = fuse->base;
@@ -398,6 +413,7 @@ static int __init tegra_init_fuse(void)
const struct of_device_id *match;
struct device_node *np;
struct resource regs;
+ int err;
tegra_init_apbmisc();
@@ -495,15 +511,11 @@ static int __init tegra_init_fuse(void)
pr_debug("Tegra CPU Speedo ID %d, SoC Speedo ID %d\n",
tegra_sku_info.cpu_speedo_id, tegra_sku_info.soc_speedo_id);
- if (fuse->soc->lookups) {
- size_t size = sizeof(*fuse->lookups) * fuse->soc->num_lookups;
+ err = tegra_fuse_add_lookups(fuse);
+ if (err)
+ pr_err("failed to add FUSE lookups\n");
- fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL);
- if (fuse->lookups)
- nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups);
- }
-
- return 0;
+ return err;
}
early_initcall(tegra_init_fuse);
--
2.34.1
Add helper function tegra_fuse_print_sku_info() to print Tegra SKU
information. So, it can be shared between tegra_fuse_init() and
ACPI probe which is to be introduced later.
Signed-off-by: Kartik <[email protected]>
---
v1 -> v2:
* Renamed tegra_fuse_pr_sku_info() as
tegra_fuse_print_sku_info().
---
drivers/soc/tegra/fuse/fuse-tegra.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index ddf25a1bb19d..2ac9e7a03d05 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -113,6 +113,16 @@ static void tegra_fuse_restore(void *base)
fuse->clk = NULL;
}
+static void tegra_fuse_print_sku_info(struct tegra_sku_info *tegra_sku_info)
+{
+ pr_info("Tegra Revision: %s SKU: %d CPU Process: %d SoC Process: %d\n",
+ tegra_revision_name[tegra_sku_info->revision],
+ tegra_sku_info->sku_id, tegra_sku_info->cpu_process_id,
+ tegra_sku_info->soc_process_id);
+ pr_debug("Tegra CPU Speedo ID %d, SoC Speedo ID %d\n",
+ tegra_sku_info->cpu_speedo_id, tegra_sku_info->soc_speedo_id);
+}
+
static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
{
size_t size;
@@ -504,12 +514,7 @@ static int __init tegra_init_fuse(void)
fuse->soc->init(fuse);
- pr_info("Tegra Revision: %s SKU: %d CPU Process: %d SoC Process: %d\n",
- tegra_revision_name[tegra_sku_info.revision],
- tegra_sku_info.sku_id, tegra_sku_info.cpu_process_id,
- tegra_sku_info.soc_process_id);
- pr_debug("Tegra CPU Speedo ID %d, SoC Speedo ID %d\n",
- tegra_sku_info.cpu_speedo_id, tegra_sku_info.soc_speedo_id);
+ tegra_fuse_print_sku_info(&tegra_sku_info);
err = tegra_fuse_add_lookups(fuse);
if (err)
--
2.34.1
Add ACPI support for Tegra194 & Tegra243 SoC's. This requires
following modifications to the probe when ACPI boot is used:
- Initialize soc data.
- Add nvmem lookups.
- Register soc device.
- use devm_clk_get_optional() instead of devm_clk_get() to get
fuse->clk, as fuse clocks are not required when using ACPI boot.
Also, drop '__init' keyword for tegra_soc_device_register() as this is also
used by tegra_fuse_probe() and use dev_err_probe() wherever applicable.
Signed-off-by: Kartik <[email protected]>
---
v3 -> v4:
* Use dev_fwnode() to dereference the fwnode.
* Add MODULE_DEVICE_TABLE for tegra_fuse_acpi_match.
* Moved tegra_fuse_acpi_match above tegra_fuse_driver i.e.,
close to the user of tegra_fuse_acpi_match.
* Moved the improvements made to fuse clk/rst get error handling
to separate patch.
* Moved ACPI related initialization after fuse->base is
initialized in tegra_fuse_probe(), as this triggers a warning
in tegra_fuse_read_early() which is called from
fuse->soc->init().
v2 -> v3:
* Updated commit message to specify changes related to inclusion
of dev_err_probe().
v1 -> v2:
* Updated ACPI ID table 'tegra_fuse_acpi_match'.
* Removed ',' after "{ /* sentinel */ }" in
'tegra_fuse_acpi_match'.
* Using same probe for ACPI and device-tree boot.
* Added code for required initialization when ACPI boot is used.
* Make clocks optional for ACPI.
* Use dev_err_probe() wherever applicable.
* Check if clock has been initialized only when device-tree
boot is used.
---
drivers/soc/tegra/fuse/fuse-tegra.c | 50 +++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index 2ac9e7a03d05..167a6fe6c43d 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -3,11 +3,13 @@
* Copyright (c) 2013-2023, NVIDIA CORPORATION. All rights reserved.
*/
+#include <linux/acpi.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/kobject.h>
#include <linux/init.h>
#include <linux/io.h>
+#include <linux/mod_devicetable.h>
#include <linux/nvmem-consumer.h>
#include <linux/nvmem-provider.h>
#include <linux/of.h>
@@ -155,6 +157,37 @@ static int tegra_fuse_probe(struct platform_device *pdev)
return PTR_ERR(fuse->base);
fuse->phys = res->start;
+ /* Initialize the soc data and lookups if using ACPI boot. */
+ if (is_acpi_node(dev_fwnode(&pdev->dev)) && !fuse->soc) {
+ u8 chip;
+
+ tegra_acpi_init_apbmisc();
+
+ chip = tegra_get_chip_id();
+ switch (chip) {
+#if defined(CONFIG_ARCH_TEGRA_194_SOC)
+ case TEGRA194:
+ fuse->soc = &tegra194_fuse_soc;
+ break;
+#endif
+#if defined(CONFIG_ARCH_TEGRA_234_SOC)
+ case TEGRA234:
+ fuse->soc = &tegra234_fuse_soc;
+ break;
+#endif
+ default:
+ return dev_err_probe(&pdev->dev, -EINVAL, "Unsupported SoC: %02x\n", chip);
+ }
+
+ fuse->soc->init(fuse);
+ tegra_fuse_print_sku_info(&tegra_sku_info);
+ tegra_soc_device_register();
+
+ err = tegra_fuse_add_lookups(fuse);
+ if (err)
+ return dev_err_probe(&pdev->dev, err, "failed to add FUSE lookups\n");
+ }
+
fuse->clk = devm_clk_get(&pdev->dev, "fuse");
if (IS_ERR(fuse->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(fuse->clk), "failed to get FUSE clock\n");
@@ -278,10 +311,17 @@ static const struct dev_pm_ops tegra_fuse_pm = {
SET_SYSTEM_SLEEP_PM_OPS(tegra_fuse_suspend, tegra_fuse_resume)
};
+static const struct acpi_device_id tegra_fuse_acpi_match[] = {
+ { "NVDA200F" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(acpi, tegra_fuse_acpi_match);
+
static struct platform_driver tegra_fuse_driver = {
.driver = {
.name = "tegra-fuse",
.of_match_table = tegra_fuse_match,
+ .acpi_match_table = ACPI_PTR(tegra_fuse_acpi_match),
.pm = &tegra_fuse_pm,
.suppress_bind_attrs = true,
},
@@ -303,7 +343,13 @@ u32 __init tegra_fuse_read_early(unsigned int offset)
int tegra_fuse_readl(unsigned long offset, u32 *value)
{
- if (!fuse->read || !fuse->clk)
+ /*
+ * Wait for fuse->clk to be initialized if device-tree boot is used.
+ */
+ if (is_of_node(dev_fwnode(fuse->dev)) && !fuse->clk)
+ return -EPROBE_DEFER;
+
+ if (!fuse->read)
return -EPROBE_DEFER;
if (IS_ERR(fuse->clk))
@@ -386,7 +432,7 @@ const struct attribute_group tegra194_soc_attr_group = {
};
#endif
-struct device * __init tegra_soc_device_register(void)
+struct device *tegra_soc_device_register(void)
{
struct soc_device_attribute *attr;
struct soc_device *dev;
--
2.34.1
Add support for Tegra241 which use ACPI boot.
Signed-off-by: Kartik <[email protected]>
---
v1 -> v2:
* Removed few entries from tegra241_fuse_soc which were
initilized as NULL or 0.
---
drivers/soc/tegra/Kconfig | 5 +++++
drivers/soc/tegra/fuse/fuse-tegra.c | 5 +++++
drivers/soc/tegra/fuse/fuse-tegra30.c | 20 ++++++++++++++++++++
drivers/soc/tegra/fuse/fuse.h | 4 ++++
drivers/soc/tegra/fuse/tegra-apbmisc.c | 1 +
include/soc/tegra/fuse.h | 1 +
6 files changed, 36 insertions(+)
diff --git a/drivers/soc/tegra/Kconfig b/drivers/soc/tegra/Kconfig
index f16beeabaa92..33512558af9f 100644
--- a/drivers/soc/tegra/Kconfig
+++ b/drivers/soc/tegra/Kconfig
@@ -133,6 +133,11 @@ config ARCH_TEGRA_234_SOC
help
Enable support for the NVIDIA Tegra234 SoC.
+config ARCH_TEGRA_241_SOC
+ bool "NVIDIA Tegra241 SoC"
+ help
+ Enable support for the NVIDIA Tegra241 SoC.
+
endif
endif
diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index 167a6fe6c43d..94bfccd719de 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -174,6 +174,11 @@ static int tegra_fuse_probe(struct platform_device *pdev)
case TEGRA234:
fuse->soc = &tegra234_fuse_soc;
break;
+#endif
+#if defined(CONFIG_ARCH_TEGRA_241_SOC)
+ case TEGRA241:
+ fuse->soc = &tegra241_fuse_soc;
+ break;
#endif
default:
return dev_err_probe(&pdev->dev, -EINVAL, "Unsupported SoC: %02x\n", chip);
diff --git a/drivers/soc/tegra/fuse/fuse-tegra30.c b/drivers/soc/tegra/fuse/fuse-tegra30.c
index e94d46372a63..2070d36c510d 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra30.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra30.c
@@ -678,3 +678,23 @@ const struct tegra_fuse_soc tegra234_fuse_soc = {
.clk_suspend_on = false,
};
#endif
+
+#if defined(CONFIG_ARCH_TEGRA_241_SOC)
+static const struct tegra_fuse_info tegra241_fuse_info = {
+ .read = tegra30_fuse_read,
+ .size = 0x16008,
+ .spare = 0xcf0,
+};
+
+static const struct nvmem_keepout tegra241_fuse_keepouts[] = {
+ { .start = 0xc, .end = 0x1600c }
+};
+
+const struct tegra_fuse_soc tegra241_fuse_soc = {
+ .init = tegra30_fuse_init,
+ .info = &tegra241_fuse_info,
+ .keepouts = tegra241_fuse_keepouts,
+ .num_keepouts = ARRAY_SIZE(tegra241_fuse_keepouts),
+ .soc_attr_group = &tegra194_soc_attr_group,
+};
+#endif
diff --git a/drivers/soc/tegra/fuse/fuse.h b/drivers/soc/tegra/fuse/fuse.h
index a41e9f85281a..f3b705327c20 100644
--- a/drivers/soc/tegra/fuse/fuse.h
+++ b/drivers/soc/tegra/fuse/fuse.h
@@ -136,4 +136,8 @@ extern const struct tegra_fuse_soc tegra194_fuse_soc;
extern const struct tegra_fuse_soc tegra234_fuse_soc;
#endif
+#ifdef CONFIG_ARCH_TEGRA_241_SOC
+extern const struct tegra_fuse_soc tegra241_fuse_soc;
+#endif
+
#endif
diff --git a/drivers/soc/tegra/fuse/tegra-apbmisc.c b/drivers/soc/tegra/fuse/tegra-apbmisc.c
index e2ca93de6c1f..c72bdb3e4e2c 100644
--- a/drivers/soc/tegra/fuse/tegra-apbmisc.c
+++ b/drivers/soc/tegra/fuse/tegra-apbmisc.c
@@ -64,6 +64,7 @@ bool tegra_is_silicon(void)
switch (tegra_get_chip_id()) {
case TEGRA194:
case TEGRA234:
+ case TEGRA241:
case TEGRA264:
if (tegra_get_platform() == 0)
return true;
diff --git a/include/soc/tegra/fuse.h b/include/soc/tegra/fuse.h
index 3a513be50243..8f421b9f7585 100644
--- a/include/soc/tegra/fuse.h
+++ b/include/soc/tegra/fuse.h
@@ -17,6 +17,7 @@
#define TEGRA186 0x18
#define TEGRA194 0x19
#define TEGRA234 0x23
+#define TEGRA241 0x24
#define TEGRA264 0x26
#define TEGRA_FUSE_SKU_CALIB_0 0xf0
--
2.34.1
Hi Kartik,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tegra/for-next]
[also build test WARNING on kees/for-next/hardening akpm-mm/mm-everything linus/master v6.6-rc5 next-20231012]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kartik/mm-util-Introduce-kmemdup_array-to-duplicate-an-array/20231011-192039
base: https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git for-next
patch link: https://lore.kernel.org/r/20231011093412.7994-8-kkartik%40nvidia.com
patch subject: [PATCH v4 7/8] soc/tegra: fuse: Add ACPI support for Tegra194 and Tegra234
config: arm64-randconfig-002-20231012 (https://download.01.org/0day-ci/archive/20231013/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231013/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/soc/tegra/fuse/fuse-tegra.c:314:36: warning: 'tegra_fuse_acpi_match' defined but not used [-Wunused-const-variable=]
314 | static const struct acpi_device_id tegra_fuse_acpi_match[] = {
| ^~~~~~~~~~~~~~~~~~~~~
vim +/tegra_fuse_acpi_match +314 drivers/soc/tegra/fuse/fuse-tegra.c
313
> 314 static const struct acpi_device_id tegra_fuse_acpi_match[] = {
315 { "NVDA200F" },
316 { /* sentinel */ }
317 };
318 MODULE_DEVICE_TABLE(acpi, tegra_fuse_acpi_match);
319
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki