of: of_spmi: Change name of spmi-dev-container
This binding is currently used to indicate all devices existing
in the same slave. Let's change the name to be more meaningful.
The real motivation here is that we want to introduce a new
binding to specify all qpnp devices existing in the same
spmi_device. So spmi-dev-container is a more meaningful name for
that usecase, and spmi-slave-container better describes the
former.
Change-Id: I48f834b9cff9ea90d05f5e958ca21bef0ab56a86
Signed-off-by: Michael Bohan <mbohan@codeaurora.org>
diff --git a/drivers/of/of_spmi.c b/drivers/of/of_spmi.c
index 9f2a396..2032b46 100644
--- a/drivers/of/of_spmi.c
+++ b/drivers/of/of_spmi.c
@@ -19,62 +19,93 @@
#include <linux/slab.h>
#include <linux/module.h>
-/**
- * Allocate resources for a child of a spmi-container node.
- */
-static int of_spmi_allocate_resources(struct spmi_controller *ctrl,
- struct spmi_boardinfo *info,
- struct device_node *node,
- uint32_t num_reg)
+struct of_spmi_dev_info {
+ struct spmi_controller *ctrl;
+ struct spmi_boardinfo b_info;
+};
+
+struct of_spmi_res_info {
+ struct device_node *node;
+ uint32_t num_reg;
+ uint32_t num_irq;
+};
+
+static void of_spmi_sum_resources(struct of_spmi_res_info *r_info, bool has_reg)
{
- int i, num_irq = 0;
+ struct of_irq oirq;
uint64_t size;
uint32_t flags;
+
+ while (of_irq_map_one(r_info->node, r_info->num_irq, &oirq) == 0)
+ r_info->num_irq++;
+
+ if (!has_reg)
+ return;
+
+ /*
+ * We can't use of_address_to_resource here since it includes
+ * address translation; and address translation assumes that no
+ * parent buses have a size-cell of 0. But SPMI does have a
+ * size-cell of 0.
+ */
+ while (of_get_address(r_info->node, r_info->num_reg,
+ &size, &flags) != NULL)
+ r_info->num_reg++;
+}
+
+/**
+ * Allocate resources for a child of a spmi-slave node.
+ */
+static int of_spmi_allocate_resources(struct of_spmi_dev_info *d_info,
+ struct of_spmi_res_info *r_info)
+
+{
+ uint32_t num_irq = r_info->num_irq, num_reg = r_info->num_reg;
+ int i;
struct resource *res;
const __be32 *addrp;
- struct of_irq oirq;
-
- while (of_irq_map_one(node, num_irq, &oirq) == 0)
- num_irq++;
+ uint64_t size;
+ uint32_t flags;
if (num_irq || num_reg) {
res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL);
if (!res)
return -ENOMEM;
- info->num_resources = num_reg + num_irq;
- info->resource = res;
+ d_info->b_info.num_resources = num_reg + num_irq;
+ d_info->b_info.resource = res;
for (i = 0; i < num_reg; i++, res++) {
/* Addresses are always 16 bits */
- addrp = of_get_address(node, i, &size, &flags);
+ addrp = of_get_address(r_info->node, i, &size, &flags);
BUG_ON(!addrp);
res->start = be32_to_cpup(addrp);
res->end = res->start + size - 1;
res->flags = flags;
}
- WARN_ON(of_irq_to_resource_table(node, res, num_irq) !=
+ WARN_ON(of_irq_to_resource_table(r_info->node, res, num_irq) !=
num_irq);
}
return 0;
}
-static int of_spmi_create_device(struct spmi_controller *ctrl,
- struct spmi_boardinfo *info,
- struct device_node *node)
+static int of_spmi_create_device(struct of_spmi_dev_info *d_info,
+ struct device_node *node)
{
+ struct spmi_controller *ctrl = d_info->ctrl;
+ struct spmi_boardinfo *b_info = &d_info->b_info;
void *result;
int rc;
- rc = of_modalias_node(node, info->name, sizeof(info->name));
+ rc = of_modalias_node(node, b_info->name, sizeof(b_info->name));
if (rc < 0) {
dev_err(&ctrl->dev, "of_spmi modalias failure on %s\n",
node->full_name);
return rc;
}
- info->of_node = of_node_get(node);
- result = spmi_new_device(ctrl, info);
+ b_info->of_node = of_node_get(node);
+ result = spmi_new_device(ctrl, b_info);
if (result == NULL) {
dev_err(&ctrl->dev, "of_spmi: Failure registering %s\n",
@@ -86,32 +117,26 @@
return 0;
}
-static void of_spmi_walk_container_children(struct spmi_controller *ctrl,
- struct spmi_boardinfo *info,
- struct device_node *container)
+static void of_spmi_walk_slave_container(struct of_spmi_dev_info *d_info,
+ struct device_node *container)
{
+ struct spmi_controller *ctrl = d_info->ctrl;
struct device_node *node;
- uint64_t size;
- uint32_t flags, num_reg = 0;
int rc;
for_each_child_of_node(container, node) {
- /*
- * We can't use of_address_to_resource here since it includes
- * address translation; and address translation assumes that no
- * parent buses have a size-cell of 0. But SPMI does have a
- * size-cell of 0.
- */
- while (of_get_address(node, num_reg, &size, &flags) != NULL)
- num_reg++;
+ struct of_spmi_res_info r_info;
- rc = of_spmi_allocate_resources(ctrl, info, node, num_reg);
+ r_info.node = node;
+ of_spmi_sum_resources(&r_info, 1);
+
+ rc = of_spmi_allocate_resources(d_info, &r_info);
if (rc) {
dev_err(&ctrl->dev, "%s: unable to allocate"
" resources\n", __func__);
return;
}
- rc = of_spmi_create_device(ctrl, info, node);
+ rc = of_spmi_create_device(d_info, node);
if (rc) {
dev_err(&ctrl->dev, "%s: unable to create device for"
" node %s\n", __func__, node->full_name);
@@ -129,7 +154,7 @@
return -ENODEV;
for_each_child_of_node(ctrl->dev.of_node, node) {
- struct spmi_boardinfo info = {};
+ struct of_spmi_dev_info d_info = {};
const __be32 *slave_id;
int len, rc;
@@ -140,16 +165,21 @@
continue;
}
- info.slave_id = be32_to_cpup(slave_id);
+ d_info.b_info.slave_id = be32_to_cpup(slave_id);
+ d_info.ctrl = ctrl;
- if (of_get_property(node, "spmi-dev-container", NULL)) {
- of_spmi_walk_container_children(ctrl, &info, node);
+ if (of_get_property(node, "spmi-slave-container", NULL)) {
+ of_spmi_walk_slave_container(&d_info, node);
continue;
} else {
- rc = of_spmi_allocate_resources(ctrl, &info, node, 0);
+ struct of_spmi_res_info r_info;
+
+ r_info.node = node;
+ of_spmi_sum_resources(&r_info, 0);
+ rc = of_spmi_allocate_resources(&d_info, &r_info);
if (rc)
continue;
- of_spmi_create_device(ctrl, &info, node);
+ of_spmi_create_device(&d_info, node);
}
}