Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/spmi.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/of.h> |
| 16 | #include <linux/of_address.h> |
| 17 | #include <linux/of_irq.h> |
| 18 | #include <linux/of_spmi.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/module.h> |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 21 | #include <linux/types.h> |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 22 | |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 23 | struct of_spmi_dev_info { |
| 24 | struct spmi_controller *ctrl; |
| 25 | struct spmi_boardinfo b_info; |
| 26 | }; |
| 27 | |
| 28 | struct of_spmi_res_info { |
| 29 | struct device_node *node; |
| 30 | uint32_t num_reg; |
| 31 | uint32_t num_irq; |
| 32 | }; |
| 33 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 34 | /* |
| 35 | * Initialize r_info structure for safe usage |
| 36 | */ |
| 37 | static inline void of_spmi_init_resource(struct of_spmi_res_info *r_info, |
| 38 | struct device_node *node) |
| 39 | { |
| 40 | r_info->node = node; |
| 41 | r_info->num_reg = 0; |
| 42 | r_info->num_irq = 0; |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Allocate dev_node array for spmi_device |
| 47 | */ |
| 48 | static inline int of_spmi_alloc_device_store(struct of_spmi_dev_info *d_info, |
| 49 | uint32_t num_dev_node) |
| 50 | { |
| 51 | d_info->b_info.num_dev_node = num_dev_node; |
| 52 | d_info->b_info.dev_node = kzalloc(sizeof(struct spmi_resource) * |
| 53 | num_dev_node, GFP_KERNEL); |
| 54 | if (!d_info->b_info.dev_node) |
| 55 | return -ENOMEM; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Calculate the number of resources to allocate |
| 62 | * |
| 63 | * The caller is responsible for initializing the of_spmi_res_info structure. |
| 64 | */ |
| 65 | static void of_spmi_sum_node_resources(struct of_spmi_res_info *r_info, |
| 66 | bool has_reg) |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 67 | { |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 68 | struct of_irq oirq; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 69 | uint64_t size; |
| 70 | uint32_t flags; |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 71 | int i = 0; |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 72 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 73 | while (of_irq_map_one(r_info->node, i, &oirq) == 0) |
| 74 | i++; |
| 75 | |
| 76 | r_info->num_irq += i; |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 77 | |
| 78 | if (!has_reg) |
| 79 | return; |
| 80 | |
| 81 | /* |
| 82 | * We can't use of_address_to_resource here since it includes |
| 83 | * address translation; and address translation assumes that no |
| 84 | * parent buses have a size-cell of 0. But SPMI does have a |
| 85 | * size-cell of 0. |
| 86 | */ |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 87 | i = 0; |
| 88 | while (of_get_address(r_info->node, i, &size, &flags) != NULL) |
| 89 | i++; |
| 90 | |
| 91 | r_info->num_reg += i; |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 94 | /* |
| 95 | * free spmi_resource for the spmi_device |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 96 | */ |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 97 | static void of_spmi_free_device_resources(struct of_spmi_dev_info *d_info) |
| 98 | { |
| 99 | int i; |
| 100 | |
| 101 | for (i = 0; i < d_info->b_info.num_dev_node; i++) |
| 102 | kfree(d_info->b_info.dev_node[i].resource); |
| 103 | |
| 104 | kfree(d_info->b_info.dev_node); |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Gather node resources and populate |
| 109 | */ |
| 110 | static void of_spmi_populate_node_resources(struct of_spmi_dev_info *d_info, |
| 111 | struct of_spmi_res_info *r_info, |
| 112 | int idx) |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 113 | |
| 114 | { |
| 115 | uint32_t num_irq = r_info->num_irq, num_reg = r_info->num_reg; |
| 116 | int i; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 117 | struct resource *res; |
| 118 | const __be32 *addrp; |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 119 | uint64_t size; |
| 120 | uint32_t flags; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 121 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 122 | res = d_info->b_info.dev_node[idx].resource; |
| 123 | d_info->b_info.dev_node[idx].of_node = r_info->node; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 124 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 125 | if ((num_irq || num_reg) && (res != NULL)) { |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 126 | for (i = 0; i < num_reg; i++, res++) { |
| 127 | /* Addresses are always 16 bits */ |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 128 | addrp = of_get_address(r_info->node, i, &size, &flags); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 129 | BUG_ON(!addrp); |
| 130 | res->start = be32_to_cpup(addrp); |
| 131 | res->end = res->start + size - 1; |
| 132 | res->flags = flags; |
Michael Bohan | a6a354d | 2012-05-21 17:47:11 -0700 | [diff] [blame^] | 133 | of_property_read_string_index(r_info->node, "reg-names", |
| 134 | i, &res->name); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 135 | } |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 136 | WARN_ON(of_irq_to_resource_table(r_info->node, res, num_irq) != |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 137 | num_irq); |
| 138 | } |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Allocate enough memory to handle the resources associated with the |
| 143 | * device_node. The number of device nodes included in this allocation |
| 144 | * depends on whether the spmi-dev-container flag is specified or not. |
| 145 | */ |
| 146 | static int of_spmi_allocate_node_resources(struct of_spmi_dev_info *d_info, |
| 147 | struct of_spmi_res_info *r_info, |
| 148 | uint32_t idx) |
| 149 | { |
| 150 | uint32_t num_irq = r_info->num_irq, num_reg = r_info->num_reg; |
| 151 | struct resource *res = NULL; |
| 152 | |
| 153 | if (num_irq || num_reg) { |
| 154 | res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL); |
| 155 | if (!res) |
| 156 | return -ENOMEM; |
| 157 | } |
| 158 | d_info->b_info.dev_node[idx].num_resources = num_reg + num_irq; |
| 159 | d_info->b_info.dev_node[idx].resource = res; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 164 | /* |
| 165 | * create a single spmi_device |
| 166 | */ |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 167 | static int of_spmi_create_device(struct of_spmi_dev_info *d_info, |
| 168 | struct device_node *node) |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 169 | { |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 170 | struct spmi_controller *ctrl = d_info->ctrl; |
| 171 | struct spmi_boardinfo *b_info = &d_info->b_info; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 172 | void *result; |
| 173 | int rc; |
| 174 | |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 175 | rc = of_modalias_node(node, b_info->name, sizeof(b_info->name)); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 176 | if (rc < 0) { |
| 177 | dev_err(&ctrl->dev, "of_spmi modalias failure on %s\n", |
| 178 | node->full_name); |
| 179 | return rc; |
| 180 | } |
| 181 | |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 182 | b_info->of_node = of_node_get(node); |
| 183 | result = spmi_new_device(ctrl, b_info); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 184 | |
| 185 | if (result == NULL) { |
| 186 | dev_err(&ctrl->dev, "of_spmi: Failure registering %s\n", |
| 187 | node->full_name); |
| 188 | of_node_put(node); |
| 189 | return -ENODEV; |
| 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 195 | /* |
| 196 | * Walks all children of a node containing the spmi-dev-container |
| 197 | * binding. This special type of spmi_device can include resources |
| 198 | * from more than one device node. |
| 199 | */ |
| 200 | static void of_spmi_walk_dev_container(struct of_spmi_dev_info *d_info, |
| 201 | struct device_node *container) |
| 202 | { |
| 203 | struct of_spmi_res_info r_info = {}; |
| 204 | struct spmi_controller *ctrl = d_info->ctrl; |
| 205 | struct device_node *node; |
| 206 | int rc, i, num_dev_node = 0; |
| 207 | |
Michael Bohan | 677dbbd | 2012-04-03 14:55:11 -0700 | [diff] [blame] | 208 | if (!of_device_is_available(container)) |
| 209 | return; |
| 210 | |
Michael Bohan | 87436bd | 2012-04-03 14:45:03 -0700 | [diff] [blame] | 211 | /* |
| 212 | * Count the total number of device_nodes so we know how much |
| 213 | * device_store to allocate. |
| 214 | */ |
Michael Bohan | 677dbbd | 2012-04-03 14:55:11 -0700 | [diff] [blame] | 215 | for_each_child_of_node(container, node) { |
| 216 | if (!of_device_is_available(node)) |
| 217 | continue; |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 218 | num_dev_node++; |
Michael Bohan | 677dbbd | 2012-04-03 14:55:11 -0700 | [diff] [blame] | 219 | } |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 220 | |
| 221 | rc = of_spmi_alloc_device_store(d_info, num_dev_node); |
| 222 | if (rc) { |
| 223 | dev_err(&ctrl->dev, "%s: unable to allocate" |
| 224 | " device resources\n", __func__); |
| 225 | return; |
| 226 | } |
| 227 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 228 | i = 0; |
| 229 | for_each_child_of_node(container, node) { |
Michael Bohan | 677dbbd | 2012-04-03 14:55:11 -0700 | [diff] [blame] | 230 | if (!of_device_is_available(node)) |
| 231 | continue; |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 232 | of_spmi_init_resource(&r_info, node); |
| 233 | of_spmi_sum_node_resources(&r_info, 1); |
| 234 | rc = of_spmi_allocate_node_resources(d_info, &r_info, i); |
| 235 | if (rc) { |
| 236 | dev_err(&ctrl->dev, "%s: unable to allocate" |
| 237 | " resources\n", __func__); |
| 238 | of_spmi_free_device_resources(d_info); |
| 239 | return; |
| 240 | } |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 241 | of_spmi_populate_node_resources(d_info, &r_info, i); |
| 242 | i++; |
| 243 | } |
| 244 | |
| 245 | rc = of_spmi_create_device(d_info, container); |
| 246 | if (rc) { |
| 247 | dev_err(&ctrl->dev, "%s: unable to create device for" |
| 248 | " node %s\n", __func__, container->full_name); |
| 249 | of_spmi_free_device_resources(d_info); |
| 250 | return; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * Walks all children of a node containing the spmi-slave-container |
| 256 | * binding. This indicates that all spmi_devices created from this |
| 257 | * point all share the same slave_id. |
| 258 | */ |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 259 | static void of_spmi_walk_slave_container(struct of_spmi_dev_info *d_info, |
| 260 | struct device_node *container) |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 261 | { |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 262 | struct spmi_controller *ctrl = d_info->ctrl; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 263 | struct device_node *node; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 264 | int rc; |
| 265 | |
| 266 | for_each_child_of_node(container, node) { |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 267 | struct of_spmi_res_info r_info; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 268 | |
Michael Bohan | 677dbbd | 2012-04-03 14:55:11 -0700 | [diff] [blame] | 269 | if (!of_device_is_available(node)) |
| 270 | continue; |
| 271 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 272 | /** |
| 273 | * Check to see if this node contains children which |
| 274 | * should be all created as the same spmi_device. |
| 275 | */ |
| 276 | if (of_get_property(node, "spmi-dev-container", NULL)) { |
| 277 | of_spmi_walk_dev_container(d_info, node); |
| 278 | continue; |
| 279 | } |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 280 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 281 | rc = of_spmi_alloc_device_store(d_info, 1); |
| 282 | if (rc) { |
| 283 | dev_err(&ctrl->dev, "%s: unable to allocate" |
| 284 | " device resources\n", __func__); |
| 285 | goto slave_err; |
| 286 | } |
| 287 | |
| 288 | of_spmi_init_resource(&r_info, node); |
| 289 | of_spmi_sum_node_resources(&r_info, 1); |
| 290 | |
| 291 | rc = of_spmi_allocate_node_resources(d_info, &r_info, 0); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 292 | if (rc) { |
| 293 | dev_err(&ctrl->dev, "%s: unable to allocate" |
| 294 | " resources\n", __func__); |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 295 | goto slave_err; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 296 | } |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 297 | |
| 298 | of_spmi_populate_node_resources(d_info, &r_info, 0); |
| 299 | |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 300 | rc = of_spmi_create_device(d_info, node); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 301 | if (rc) { |
| 302 | dev_err(&ctrl->dev, "%s: unable to create device for" |
| 303 | " node %s\n", __func__, node->full_name); |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 304 | goto slave_err; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 307 | return; |
| 308 | |
| 309 | slave_err: |
| 310 | of_spmi_free_device_resources(d_info); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | int of_spmi_register_devices(struct spmi_controller *ctrl) |
| 314 | { |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 315 | struct device_node *node = ctrl->dev.of_node; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 316 | |
| 317 | /* Only register child devices if the ctrl has a node pointer set */ |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 318 | if (!node) |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 319 | return -ENODEV; |
| 320 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 321 | if (of_get_property(node, "spmi-slave-container", NULL)) { |
| 322 | dev_err(&ctrl->dev, "%s: structural error: spmi-slave-container" |
| 323 | " is prohibited at the root level\n", __func__); |
| 324 | return -EINVAL; |
| 325 | } else if (of_get_property(node, "spmi-dev-container", NULL)) { |
| 326 | dev_err(&ctrl->dev, "%s: structural error: spmi-dev-container" |
| 327 | " is prohibited at the root level\n", __func__); |
| 328 | return -EINVAL; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Make best effort to launch as many nodes as possible. If there are |
| 333 | * syntax errors, we will simply ignore that subtree and keep going. |
| 334 | */ |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 335 | for_each_child_of_node(ctrl->dev.of_node, node) { |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 336 | struct of_spmi_dev_info d_info = {}; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 337 | const __be32 *slave_id; |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 338 | int len, rc, have_dev_container = 0; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 339 | |
| 340 | slave_id = of_get_property(node, "reg", &len); |
| 341 | if (!slave_id) { |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 342 | dev_err(&ctrl->dev, "%s: invalid sid " |
| 343 | "on %s\n", __func__, node->full_name); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 344 | continue; |
| 345 | } |
| 346 | |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 347 | d_info.b_info.slave_id = be32_to_cpup(slave_id); |
| 348 | d_info.ctrl = ctrl; |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 349 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 350 | if (of_get_property(node, "spmi-dev-container", NULL)) |
| 351 | have_dev_container = 1; |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 352 | if (of_get_property(node, "spmi-slave-container", NULL)) { |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 353 | if (have_dev_container) |
| 354 | of_spmi_walk_dev_container(&d_info, node); |
| 355 | else |
| 356 | of_spmi_walk_slave_container(&d_info, node); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 357 | } else { |
Michael Bohan | 11926c9 | 2012-02-08 11:01:24 -0800 | [diff] [blame] | 358 | struct of_spmi_res_info r_info; |
| 359 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 360 | /** |
| 361 | * A dev container at the second level without a slave |
| 362 | * container is considered an error. |
| 363 | */ |
| 364 | if (have_dev_container) { |
| 365 | dev_err(&ctrl->dev, "%s: structural error," |
| 366 | " node %s has spmi-dev-container without" |
| 367 | " specifying spmi-slave-container\n", |
| 368 | __func__, node->full_name); |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 369 | continue; |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Michael Bohan | 677dbbd | 2012-04-03 14:55:11 -0700 | [diff] [blame] | 372 | if (!of_device_is_available(node)) |
| 373 | continue; |
| 374 | |
Michael Bohan | 86622b3 | 2012-02-08 16:59:00 -0800 | [diff] [blame] | 375 | rc = of_spmi_alloc_device_store(&d_info, 1); |
| 376 | if (rc) { |
| 377 | dev_err(&ctrl->dev, "%s: unable to allocate" |
| 378 | " device resources\n", __func__); |
| 379 | continue; |
| 380 | } |
| 381 | |
| 382 | of_spmi_init_resource(&r_info, node); |
| 383 | of_spmi_sum_node_resources(&r_info, 0); |
| 384 | rc = of_spmi_allocate_node_resources(&d_info, |
| 385 | &r_info, 0); |
| 386 | if (rc) { |
| 387 | dev_err(&ctrl->dev, "%s: unable to allocate" |
| 388 | " resources\n", __func__); |
| 389 | of_spmi_free_device_resources(&d_info); |
| 390 | continue; |
| 391 | } |
| 392 | |
| 393 | of_spmi_populate_node_resources(&d_info, &r_info, 0); |
| 394 | |
| 395 | rc = of_spmi_create_device(&d_info, node); |
| 396 | if (rc) { |
| 397 | dev_err(&ctrl->dev, "%s: unable to create" |
| 398 | " device\n", __func__); |
| 399 | of_spmi_free_device_resources(&d_info); |
| 400 | continue; |
| 401 | } |
Michael Bohan | 86e30dc | 2012-01-05 14:16:43 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | EXPORT_SYMBOL(of_spmi_register_devices); |
| 408 | |
| 409 | MODULE_LICENSE("GPL"); |