diff --git a/drivers/power/avs/rockchip-io-domain.c b/drivers/power/avs/rockchip-io-domain.c index c2134e363324..d723bcfae918 100644 --- a/drivers/power/avs/rockchip-io-domain.c +++ b/drivers/power/avs/rockchip-io-domain.c @@ -23,6 +23,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include "../../regulator/internal.h" #define MAX_SUPPLIES 16 @@ -644,6 +650,77 @@ static const struct file_operations rockchip_iodomain_vol_fops = { static const struct file_operations rockchip_iodomain_vol_fops = { }; #endif +static const char *rdev_get_name(struct regulator_dev *rdev) +{ + if (rdev->constraints && rdev->constraints->name) + return rdev->constraints->name; + else if (rdev->desc->name) + return rdev->desc->name; + else + return ""; +} + +static struct device_node *of_get_child_regulator(struct device_node *parent, + const char *prop_name) +{ + struct device_node *regnode = NULL; + struct device_node *child = NULL; + + for_each_child_of_node(parent, child) { + regnode = of_parse_phandle(child, prop_name, 0); + + if (!regnode) { + regnode = of_get_child_regulator(child, prop_name); + if (regnode) + return regnode; + } else { + return regnode; + } + } + return NULL; +} + +static struct device_node *of_get_regulator(struct device *dev, const char *supply) +{ + struct device_node *regnode = NULL; + char prop_name[256]; + + dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + + snprintf(prop_name, sizeof(prop_name), "%s-supply", supply); + regnode = of_parse_phandle(dev->of_node, prop_name, 0); + + if (!regnode) { + regnode = of_get_child_regulator(dev->of_node, prop_name); + if (regnode) + return regnode; + + dev_dbg(dev, "Looking up %s property in node %pOF failed\n", + prop_name, dev->of_node); + return NULL; + } + return regnode; +} + +static void rockchip_iodomain_dump(const struct platform_device *pdev, + struct rockchip_iodomain_supply *supply) +{ + struct rockchip_iodomain *iod = supply->iod; + const char *name = iod->soc_data->supply_names[supply->idx]; + struct device *dev = iod->dev; + struct device_node *node; + struct regulator_dev *r = NULL; + + node = of_get_regulator(dev, name); + if (node) { + r = of_find_regulator_by_node(node); + if (!IS_ERR_OR_NULL(r)) + dev_info(&pdev->dev, "%s(%d uV) supplied by %s\n", + name, regulator_get_voltage(supply->reg), + rdev_get_name(r)); + } +} + static int rockchip_iodomain_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -748,6 +825,7 @@ static int rockchip_iodomain_probe(struct platform_device *pdev) goto unreg_notify; } + rockchip_iodomain_dump(pdev, supply); debugfs_supply = debugfs_create_dir(supply_name, debugfs_root); debugfs_create_file("voltage", 0444, debugfs_supply, (void *)supply,