]>
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 | ||
13 | #include <linux/slab.h> | |
14 | #include <linux/of.h> | |
15 | #include <linux/regulator/machine.h> | |
16 | ||
17 | static void of_get_regulation_constraints(struct device_node *np, | |
18 | struct regulator_init_data **init_data) | |
19 | { | |
20 | const __be32 *min_uV, *max_uV, *uV_offset; | |
21 | const __be32 *min_uA, *max_uA; | |
22 | struct regulation_constraints *constraints = &(*init_data)->constraints; | |
23 | ||
24 | constraints->name = of_get_property(np, "regulator-name", NULL); | |
25 | ||
26 | min_uV = of_get_property(np, "regulator-min-microvolt", NULL); | |
27 | if (min_uV) | |
28 | constraints->min_uV = be32_to_cpu(*min_uV); | |
29 | max_uV = of_get_property(np, "regulator-max-microvolt", NULL); | |
30 | if (max_uV) | |
31 | constraints->max_uV = be32_to_cpu(*max_uV); | |
32 | ||
33 | /* Voltage change possible? */ | |
34 | if (constraints->min_uV != constraints->max_uV) | |
35 | constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; | |
36 | ||
37 | uV_offset = of_get_property(np, "regulator-microvolt-offset", NULL); | |
38 | if (uV_offset) | |
39 | constraints->uV_offset = be32_to_cpu(*uV_offset); | |
40 | min_uA = of_get_property(np, "regulator-min-microamp", NULL); | |
41 | if (min_uA) | |
42 | constraints->min_uA = be32_to_cpu(*min_uA); | |
43 | max_uA = of_get_property(np, "regulator-max-microamp", NULL); | |
44 | if (max_uA) | |
45 | constraints->max_uA = be32_to_cpu(*max_uA); | |
46 | ||
47 | /* Current change possible? */ | |
48 | if (constraints->min_uA != constraints->max_uA) | |
49 | constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; | |
50 | ||
51 | if (of_find_property(np, "regulator-boot-on", NULL)) | |
52 | constraints->boot_on = true; | |
53 | ||
54 | if (of_find_property(np, "regulator-always-on", NULL)) | |
55 | constraints->always_on = true; | |
56 | else /* status change should be possible if not always on. */ | |
57 | constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; | |
58 | } | |
59 | ||
60 | /** | |
61 | * of_get_regulator_init_data - extract regulator_init_data structure info | |
62 | * @dev: device requesting for regulator_init_data | |
63 | * | |
64 | * Populates regulator_init_data structure by extracting data from device | |
65 | * tree node, returns a pointer to the populated struture or NULL if memory | |
66 | * alloc fails. | |
67 | */ | |
68 | struct regulator_init_data *of_get_regulator_init_data(struct device *dev) | |
69 | { | |
70 | struct regulator_init_data *init_data; | |
71 | ||
72 | if (!dev->of_node) | |
73 | return NULL; | |
74 | ||
75 | init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL); | |
76 | if (!init_data) | |
77 | return NULL; /* Out of memory? */ | |
78 | ||
79 | of_get_regulation_constraints(dev->of_node, &init_data); | |
80 | return init_data; | |
81 | } |