Commit | Line | Data |
---|---|---|
8f446e6f RN |
1 | /* |
2 | * OF helpers for regulator framework | |
3 | * | |
4 | * Copyright (C) 2011 Texas Instruments, Inc. | |
5 | * Rajendra Nayak <rnayak@ti.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | */ | |
12 | ||
e69af5e9 | 13 | #include <linux/module.h> |
8f446e6f RN |
14 | #include <linux/slab.h> |
15 | #include <linux/of.h> | |
16 | #include <linux/regulator/machine.h> | |
17 | ||
18 | static void of_get_regulation_constraints(struct device_node *np, | |
19 | struct regulator_init_data **init_data) | |
20 | { | |
21 | const __be32 *min_uV, *max_uV, *uV_offset; | |
22 | const __be32 *min_uA, *max_uA; | |
23 | struct regulation_constraints *constraints = &(*init_data)->constraints; | |
24 | ||
25 | constraints->name = of_get_property(np, "regulator-name", NULL); | |
26 | ||
27 | min_uV = of_get_property(np, "regulator-min-microvolt", NULL); | |
28 | if (min_uV) | |
29 | constraints->min_uV = be32_to_cpu(*min_uV); | |
30 | max_uV = of_get_property(np, "regulator-max-microvolt", NULL); | |
31 | if (max_uV) | |
32 | constraints->max_uV = be32_to_cpu(*max_uV); | |
33 | ||
34 | /* Voltage change possible? */ | |
35 | if (constraints->min_uV != constraints->max_uV) | |
36 | constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; | |
ab62aa93 MB |
37 | /* Only one voltage? Then make sure it's set. */ |
38 | if (constraints->min_uV == constraints->max_uV) | |
39 | constraints->apply_uV = true; | |
8f446e6f RN |
40 | |
41 | uV_offset = of_get_property(np, "regulator-microvolt-offset", NULL); | |
42 | if (uV_offset) | |
43 | constraints->uV_offset = be32_to_cpu(*uV_offset); | |
44 | min_uA = of_get_property(np, "regulator-min-microamp", NULL); | |
45 | if (min_uA) | |
46 | constraints->min_uA = be32_to_cpu(*min_uA); | |
47 | max_uA = of_get_property(np, "regulator-max-microamp", NULL); | |
48 | if (max_uA) | |
49 | constraints->max_uA = be32_to_cpu(*max_uA); | |
50 | ||
51 | /* Current change possible? */ | |
52 | if (constraints->min_uA != constraints->max_uA) | |
53 | constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; | |
54 | ||
55 | if (of_find_property(np, "regulator-boot-on", NULL)) | |
56 | constraints->boot_on = true; | |
57 | ||
58 | if (of_find_property(np, "regulator-always-on", NULL)) | |
59 | constraints->always_on = true; | |
60 | else /* status change should be possible if not always on. */ | |
61 | constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; | |
62 | } | |
63 | ||
64 | /** | |
65 | * of_get_regulator_init_data - extract regulator_init_data structure info | |
66 | * @dev: device requesting for regulator_init_data | |
67 | * | |
68 | * Populates regulator_init_data structure by extracting data from device | |
69 | * tree node, returns a pointer to the populated struture or NULL if memory | |
70 | * alloc fails. | |
71 | */ | |
d9a861cc SG |
72 | struct regulator_init_data *of_get_regulator_init_data(struct device *dev, |
73 | struct device_node *node) | |
8f446e6f RN |
74 | { |
75 | struct regulator_init_data *init_data; | |
76 | ||
d9a861cc | 77 | if (!node) |
8f446e6f RN |
78 | return NULL; |
79 | ||
80 | init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL); | |
81 | if (!init_data) | |
82 | return NULL; /* Out of memory? */ | |
83 | ||
d9a861cc | 84 | of_get_regulation_constraints(node, &init_data); |
8f446e6f RN |
85 | return init_data; |
86 | } | |
e69af5e9 | 87 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); |