tegra: hwpm: add wrapper linux os structure

Currently, HWPM parent structure contains linux specific device
variables. In an effort to make HWPM driver OS agnostic, create Linux
specific wrapper HWPM structure tegra_hwpm_os_linux. Move linux specific
variables from tegra_soc_hwpm structure to tegra_hwpm_os_linux
structure.

Jira THWPM-60

Change-Id: I189cde92c5b83b327ccb467c72dee5756f16481d
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2729700
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Vedashree Vidwans
2022-06-15 23:41:07 -07:00
committed by mobile promotions
parent 2dd64aec0b
commit 738361e0e2
14 changed files with 292 additions and 212 deletions

View File

@@ -23,11 +23,13 @@
#include <soc/tegra/fuse.h>
#include <tegra_hwpm.h>
#include <tegra_hwpm_ip.h>
#include <tegra_hwpm_log.h>
#include <tegra_hwpm_soc.h>
#include <tegra_hwpm_kmem.h>
#include <tegra_hwpm_common.h>
#include <os/linux/debugfs.h>
#include <os/linux/ip_utils.h>
#include <os/linux/driver.h>
static const struct of_device_id tegra_soc_hwpm_of_match[] = {
{
@@ -64,16 +66,12 @@ static bool tegra_hwpm_read_support_soc_tools_prop(struct platform_device *pdev)
return allow_node;
}
static int tegra_hwpm_init_chip_info(struct tegra_soc_hwpm *hwpm)
int tegra_hwpm_init_chip_info(struct tegra_hwpm_os_linux *hwpm_linux)
{
tegra_hwpm_fn(hwpm, " ");
hwpm->dbg_mask = TEGRA_HWPM_DEFAULT_DBG_MASK;
hwpm->device_info.chip = tegra_get_chip_id();
hwpm->device_info.chip_revision = tegra_get_major_rev();
hwpm->device_info.revision = tegra_chip_get_revision();
hwpm->device_info.platform = tegra_get_platform();
hwpm_linux->device_info.chip = tegra_get_chip_id();
hwpm_linux->device_info.chip_revision = tegra_get_major_rev();
hwpm_linux->device_info.revision = tegra_chip_get_revision();
hwpm_linux->device_info.platform = tegra_get_platform();
return 0;
}
@@ -82,6 +80,7 @@ static int tegra_hwpm_probe(struct platform_device *pdev)
{
int ret = 0;
struct device *dev = NULL;
struct tegra_hwpm_os_linux *hwpm_linux = NULL;
struct tegra_soc_hwpm *hwpm = NULL;
if (!pdev) {
@@ -96,94 +95,100 @@ static int tegra_hwpm_probe(struct platform_device *pdev)
goto fail;
}
hwpm = kzalloc(sizeof(struct tegra_soc_hwpm), GFP_KERNEL);
if (!hwpm) {
tegra_hwpm_err(hwpm, "Couldn't allocate memory for hwpm struct");
hwpm_linux = kzalloc(sizeof(struct tegra_hwpm_os_linux), GFP_KERNEL);
if (!hwpm_linux) {
tegra_hwpm_err(NULL,
"Couldn't allocate memory for linux hwpm struct");
ret = -ENOMEM;
goto fail;
}
hwpm->pdev = pdev;
hwpm->dev = &pdev->dev;
hwpm->np = pdev->dev.of_node;
hwpm->class.owner = THIS_MODULE;
hwpm->class.name = TEGRA_SOC_HWPM_MODULE_NAME;
hwpm_linux->pdev = pdev;
hwpm_linux->dev = &pdev->dev;
hwpm_linux->np = pdev->dev.of_node;
hwpm_linux->class.owner = THIS_MODULE;
hwpm_linux->class.name = TEGRA_SOC_HWPM_MODULE_NAME;
hwpm = &hwpm_linux->hwpm;
/* Create device node */
ret = class_register(&hwpm->class);
ret = class_register(&hwpm_linux->class);
if (ret) {
tegra_hwpm_err(hwpm, "Failed to register class");
goto class_register;
}
/* Set devnode to retrieve device permissions */
hwpm->class.devnode = tegra_hwpm_get_devnode;
hwpm_linux->class.devnode = tegra_hwpm_get_devnode;
ret = alloc_chrdev_region(&hwpm->dev_t, 0, 1, dev_name(hwpm->dev));
ret = alloc_chrdev_region(&hwpm_linux->dev_t, 0, 1,
dev_name(hwpm_linux->dev));
if (ret) {
tegra_hwpm_err(hwpm, "Failed to allocate device region");
goto alloc_chrdev_region;
}
cdev_init(&hwpm->cdev, &tegra_soc_hwpm_ops);
hwpm->cdev.owner = THIS_MODULE;
cdev_init(&hwpm_linux->cdev, &tegra_hwpm_ops);
hwpm_linux->cdev.owner = THIS_MODULE;
ret = cdev_add(&hwpm->cdev, hwpm->dev_t, 1);
ret = cdev_add(&hwpm_linux->cdev, hwpm_linux->dev_t, 1);
if (ret) {
tegra_hwpm_err(hwpm, "Failed to add cdev");
goto cdev_add;
}
dev = device_create(&hwpm->class,
NULL,
hwpm->dev_t,
NULL,
TEGRA_SOC_HWPM_MODULE_NAME);
dev = device_create(&hwpm_linux->class, NULL,
hwpm_linux->dev_t, NULL, TEGRA_SOC_HWPM_MODULE_NAME);
if (IS_ERR(dev)) {
tegra_hwpm_err(hwpm, "Failed to create device");
ret = PTR_ERR(dev);
goto device_create;
}
(void) dma_set_mask_and_coherent(hwpm->dev, DMA_BIT_MASK(39));
(void) dma_set_mask_and_coherent(hwpm_linux->dev, DMA_BIT_MASK(39));
if (tegra_hwpm_is_platform_silicon()) {
hwpm->la_clk = devm_clk_get(hwpm->dev, "la");
if (IS_ERR(hwpm->la_clk)) {
hwpm_linux->la_clk = devm_clk_get(hwpm_linux->dev, "la");
if (IS_ERR(hwpm_linux->la_clk)) {
tegra_hwpm_err(hwpm, "Missing la clock");
ret = PTR_ERR(hwpm->la_clk);
ret = PTR_ERR(hwpm_linux->la_clk);
goto clock_reset_fail;
}
hwpm->la_parent_clk = devm_clk_get(hwpm->dev, "parent");
if (IS_ERR(hwpm->la_parent_clk)) {
hwpm_linux->la_parent_clk =
devm_clk_get(hwpm_linux->dev, "parent");
if (IS_ERR(hwpm_linux->la_parent_clk)) {
tegra_hwpm_err(hwpm, "Missing la parent clk");
ret = PTR_ERR(hwpm->la_parent_clk);
ret = PTR_ERR(hwpm_linux->la_parent_clk);
goto clock_reset_fail;
}
hwpm->la_rst = devm_reset_control_get(hwpm->dev, "la");
if (IS_ERR(hwpm->la_rst)) {
hwpm_linux->la_rst =
devm_reset_control_get(hwpm_linux->dev, "la");
if (IS_ERR(hwpm_linux->la_rst)) {
tegra_hwpm_err(hwpm, "Missing la reset");
ret = PTR_ERR(hwpm->la_rst);
ret = PTR_ERR(hwpm_linux->la_rst);
goto clock_reset_fail;
}
hwpm->hwpm_rst = devm_reset_control_get(hwpm->dev, "hwpm");
if (IS_ERR(hwpm->hwpm_rst)) {
hwpm_linux->hwpm_rst =
devm_reset_control_get(hwpm_linux->dev, "hwpm");
if (IS_ERR(hwpm_linux->hwpm_rst)) {
tegra_hwpm_err(hwpm, "Missing hwpm reset");
ret = PTR_ERR(hwpm->hwpm_rst);
ret = PTR_ERR(hwpm_linux->hwpm_rst);
goto clock_reset_fail;
}
}
tegra_hwpm_debugfs_init(hwpm);
ret = tegra_hwpm_init_chip_info(hwpm);
tegra_hwpm_debugfs_init(hwpm_linux);
ret = tegra_hwpm_init_chip_info(hwpm_linux);
if (ret != 0) {
tegra_hwpm_err(hwpm, "Failed to initialize current chip info.");
tegra_hwpm_err(hwpm, "Failed to initialize current chip info");
goto init_chip_info_fail;
}
ret = tegra_hwpm_init_sw_components(hwpm);
ret = tegra_hwpm_init_sw_components(hwpm, hwpm_linux->device_info.chip,
hwpm_linux->device_info.chip_revision);
if (ret != 0) {
tegra_hwpm_err(hwpm, "Failed to init sw components");
goto init_sw_components_fail;
@@ -207,25 +212,26 @@ static int tegra_hwpm_probe(struct platform_device *pdev)
init_chip_info_fail:
init_sw_components_fail:
if (tegra_hwpm_is_platform_silicon()) {
if (hwpm->la_clk)
devm_clk_put(hwpm->dev, hwpm->la_clk);
if (hwpm->la_parent_clk)
devm_clk_put(hwpm->dev, hwpm->la_parent_clk);
if (hwpm->la_rst)
reset_control_assert(hwpm->la_rst);
if (hwpm->hwpm_rst)
reset_control_assert(hwpm->hwpm_rst);
if (hwpm_linux->la_clk)
devm_clk_put(hwpm_linux->dev, hwpm_linux->la_clk);
if (hwpm_linux->la_parent_clk)
devm_clk_put(hwpm_linux->dev,
hwpm_linux->la_parent_clk);
if (hwpm_linux->la_rst)
reset_control_assert(hwpm_linux->la_rst);
if (hwpm_linux->hwpm_rst)
reset_control_assert(hwpm_linux->hwpm_rst);
}
clock_reset_fail:
device_destroy(&hwpm->class, hwpm->dev_t);
device_destroy(&hwpm_linux->class, hwpm_linux->dev_t);
device_create:
cdev_del(&hwpm->cdev);
cdev_del(&hwpm_linux->cdev);
cdev_add:
unregister_chrdev_region(hwpm->dev_t, 1);
unregister_chrdev_region(hwpm_linux->dev_t, 1);
alloc_chrdev_region:
class_unregister(&hwpm->class);
class_unregister(&hwpm_linux->class);
class_register:
kfree(hwpm);
tegra_hwpm_kfree(NULL, hwpm_linux);
fail:
tegra_hwpm_err(NULL, "Probe failed!");
success:
@@ -234,6 +240,7 @@ success:
static int tegra_hwpm_remove(struct platform_device *pdev)
{
struct tegra_hwpm_os_linux *hwpm_linux = NULL;
struct tegra_soc_hwpm *hwpm = NULL;
if (!pdev) {
@@ -247,25 +254,34 @@ static int tegra_hwpm_remove(struct platform_device *pdev)
return -ENODEV;
}
if (tegra_hwpm_is_platform_silicon()) {
if (hwpm->la_clk)
devm_clk_put(hwpm->dev, hwpm->la_clk);
if (hwpm->la_parent_clk)
devm_clk_put(hwpm->dev, hwpm->la_parent_clk);
if (hwpm->la_rst)
reset_control_assert(hwpm->la_rst);
if (hwpm->hwpm_rst)
reset_control_assert(hwpm->hwpm_rst);
hwpm_linux = tegra_hwpm_os_linux_from_hwpm(hwpm);
if (!hwpm_linux) {
tegra_hwpm_err(NULL, "Invalid hwpm_linux struct");
return -ENODEV;
}
device_destroy(&hwpm->class, hwpm->dev_t);
cdev_del(&hwpm->cdev);
unregister_chrdev_region(hwpm->dev_t, 1);
class_unregister(&hwpm->class);
if (tegra_hwpm_is_platform_silicon()) {
if (hwpm_linux->la_clk)
devm_clk_put(hwpm_linux->dev, hwpm_linux->la_clk);
if (hwpm_linux->la_parent_clk)
devm_clk_put(hwpm_linux->dev, hwpm_linux->la_parent_clk);
if (hwpm_linux->la_rst)
reset_control_assert(hwpm_linux->la_rst);
if (hwpm_linux->hwpm_rst)
reset_control_assert(hwpm_linux->hwpm_rst);
}
tegra_hwpm_debugfs_deinit(hwpm);
tegra_hwpm_release_ip_register_node(hwpm);
tegra_hwpm_release_sw_components(hwpm);
tegra_hwpm_release_sw_setup(hwpm);
tegra_hwpm_debugfs_deinit(hwpm_linux);
device_destroy(&hwpm_linux->class, hwpm_linux->dev_t);
cdev_del(&hwpm_linux->cdev);
unregister_chrdev_region(hwpm_linux->dev_t, 1);
class_unregister(&hwpm_linux->class);
tegra_hwpm_kfree(NULL, hwpm_linux);
tegra_soc_hwpm_pdev = NULL;
return 0;
}