diff --git a/os/linux/tegra_hwpm_linux.c b/os/linux/tegra_hwpm_linux.c index 859d535..4e3be65 100644 --- a/os/linux/tegra_hwpm_linux.c +++ b/os/linux/tegra_hwpm_linux.c @@ -36,6 +36,30 @@ static const struct of_device_id tegra_soc_hwpm_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_soc_hwpm_of_match); +static char *tegra_hwpm_get_devnode(struct device *dev, umode_t *mode) +{ + if (!mode) { + return NULL; + } + + /* Allow root:debug ownership */ + *mode = 0660; + + return NULL; +} + +static bool tegra_hwpm_read_support_soc_tools_prop(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + bool allow_node = of_property_read_bool(np, "support-soc-tools"); + + if (!allow_node) { + tegra_hwpm_err(NULL, "support-soc-tools is absent"); + } + + return allow_node; +} + static int tegra_hwpm_probe(struct platform_device *pdev) { int ret = 0; @@ -48,6 +72,12 @@ static int tegra_hwpm_probe(struct platform_device *pdev) goto fail; } + if (!tegra_hwpm_read_support_soc_tools_prop(pdev)) { + tegra_hwpm_err(NULL, "SOC HWPM not supported in this config"); + ret = -ENODEV; + goto fail; + } + hwpm = kzalloc(sizeof(struct tegra_soc_hwpm), GFP_KERNEL); if (!hwpm) { tegra_hwpm_err(hwpm, "Couldn't allocate memory for hwpm struct"); @@ -67,6 +97,9 @@ static int tegra_hwpm_probe(struct platform_device *pdev) goto class_register; } + /* Set devnode to retrieve device permissions */ + hwpm->class.devnode = tegra_hwpm_get_devnode; + ret = alloc_chrdev_region(&hwpm->dev_t, 0, 1, dev_name(hwpm->dev)); if (ret) { tegra_hwpm_err(hwpm, "Failed to allocate device region");