Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * OMAP3/OMAP4 Voltage Management Routines |
| 3 | * |
| 4 | * Author: Thara Gopinath <thara@ti.com> |
| 5 | * |
| 6 | * Copyright (C) 2007 Texas Instruments, Inc. |
| 7 | * Rajendra Nayak <rnayak@ti.com> |
| 8 | * Lesly A M <x0080970@ti.com> |
| 9 | * |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 10 | * Copyright (C) 2008, 2011 Nokia Corporation |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 11 | * Kalle Jokiniemi |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 12 | * Paul Walmsley |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 13 | * |
| 14 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 15 | * Thara Gopinath <thara@ti.com> |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License version 2 as |
| 19 | * published by the Free Software Foundation. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/io.h> |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 24 | #include <linux/err.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 25 | #include <linux/export.h> |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 26 | #include <linux/debugfs.h> |
| 27 | #include <linux/slab.h> |
Kevin Hilman | 0e2f3d9 | 2011-04-04 17:22:28 -0700 | [diff] [blame] | 28 | #include <linux/clk.h> |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 29 | |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 30 | #include "common.h" |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 31 | |
| 32 | #include "prm-regbits-34xx.h" |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 33 | #include "prm-regbits-44xx.h" |
| 34 | #include "prm44xx.h" |
| 35 | #include "prcm44xx.h" |
| 36 | #include "prminst44xx.h" |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 37 | #include "control.h" |
| 38 | |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 39 | #include "voltage.h" |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 40 | #include "powerdomain.h" |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 41 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 42 | #include "vc.h" |
| 43 | #include "vp.h" |
| 44 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 45 | static LIST_HEAD(voltdm_list); |
| 46 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 47 | /* Public functions */ |
| 48 | /** |
Kevin Hilman | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 49 | * voltdm_get_voltage() - Gets the current non-auto-compensated voltage |
| 50 | * @voltdm: pointer to the voltdm for which current voltage info is needed |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 51 | * |
Kevin Hilman | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 52 | * API to get the current non-auto-compensated voltage for a voltage domain. |
| 53 | * Returns 0 in case of error else returns the current voltage. |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 54 | */ |
Kevin Hilman | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 55 | unsigned long voltdm_get_voltage(struct voltagedomain *voltdm) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 56 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 57 | if (!voltdm || IS_ERR(voltdm)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 58 | pr_warn("%s: VDD specified does not exist!\n", __func__); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
Kevin Hilman | 7590f60 | 2011-04-05 16:55:22 -0700 | [diff] [blame] | 62 | return voltdm->nominal_volt; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 66 | * voltdm_scale() - API to scale voltage of a particular voltage domain. |
| 67 | * @voltdm: pointer to the voltage domain which is to be scaled. |
| 68 | * @target_volt: The target voltage of the voltage domain |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 69 | * |
| 70 | * This API should be called by the kernel to do the voltage scaling |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 71 | * for a particular voltage domain during DVFS. |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 72 | */ |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 73 | int voltdm_scale(struct voltagedomain *voltdm, |
| 74 | unsigned long target_volt) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 75 | { |
Kevin Hilman | c15f1d8 | 2012-03-02 14:08:57 -0800 | [diff] [blame] | 76 | int ret, i; |
| 77 | unsigned long volt = 0; |
Kevin Hilman | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 78 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 79 | if (!voltdm || IS_ERR(voltdm)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 80 | pr_warn("%s: VDD specified does not exist!\n", __func__); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 81 | return -EINVAL; |
| 82 | } |
| 83 | |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 84 | if (!voltdm->scale) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 85 | pr_err("%s: No voltage scale API registered for vdd_%s\n", |
| 86 | __func__, voltdm->name); |
| 87 | return -ENODATA; |
| 88 | } |
| 89 | |
Kevin Hilman | c15f1d8 | 2012-03-02 14:08:57 -0800 | [diff] [blame] | 90 | /* Adjust voltage to the exact voltage from the OPP table */ |
| 91 | for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) { |
| 92 | if (voltdm->volt_data[i].volt_nominal >= target_volt) { |
| 93 | volt = voltdm->volt_data[i].volt_nominal; |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if (!volt) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 99 | pr_warn("%s: not scaling. OPP voltage for %lu, not found.\n", |
| 100 | __func__, target_volt); |
Kevin Hilman | c15f1d8 | 2012-03-02 14:08:57 -0800 | [diff] [blame] | 101 | return -EINVAL; |
| 102 | } |
| 103 | |
| 104 | ret = voltdm->scale(voltdm, volt); |
Kevin Hilman | 6a62b78 | 2011-07-18 16:24:17 -0700 | [diff] [blame] | 105 | if (!ret) |
Kevin Hilman | c15f1d8 | 2012-03-02 14:08:57 -0800 | [diff] [blame] | 106 | voltdm->nominal_volt = volt; |
Kevin Hilman | 6a62b78 | 2011-07-18 16:24:17 -0700 | [diff] [blame] | 107 | |
| 108 | return ret; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 112 | * voltdm_reset() - Resets the voltage of a particular voltage domain |
| 113 | * to that of the current OPP. |
| 114 | * @voltdm: pointer to the voltage domain whose voltage is to be reset. |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 115 | * |
| 116 | * This API finds out the correct voltage the voltage domain is supposed |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 117 | * to be at and resets the voltage to that level. Should be used especially |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 118 | * while disabling any voltage compensation modules. |
| 119 | */ |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 120 | void voltdm_reset(struct voltagedomain *voltdm) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 121 | { |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 122 | unsigned long target_volt; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 123 | |
| 124 | if (!voltdm || IS_ERR(voltdm)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 125 | pr_warn("%s: VDD specified does not exist!\n", __func__); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
Kevin Hilman | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 129 | target_volt = voltdm_get_voltage(voltdm); |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 130 | if (!target_volt) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 131 | pr_err("%s: unable to find current voltage for vdd_%s\n", |
| 132 | __func__, voltdm->name); |
| 133 | return; |
| 134 | } |
| 135 | |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 136 | voltdm_scale(voltdm, target_volt); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * omap_voltage_get_volttable() - API to get the voltage table associated with a |
| 141 | * particular voltage domain. |
| 142 | * @voltdm: pointer to the VDD for which the voltage table is required |
| 143 | * @volt_data: the voltage table for the particular vdd which is to be |
| 144 | * populated by this API |
| 145 | * |
| 146 | * This API populates the voltage table associated with a VDD into the |
| 147 | * passed parameter pointer. Returns the count of distinct voltages |
| 148 | * supported by this vdd. |
| 149 | * |
| 150 | */ |
| 151 | void omap_voltage_get_volttable(struct voltagedomain *voltdm, |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 152 | struct omap_volt_data **volt_data) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 153 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 154 | if (!voltdm || IS_ERR(voltdm)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 155 | pr_warn("%s: VDD specified does not exist!\n", __func__); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 156 | return; |
| 157 | } |
| 158 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 159 | *volt_data = voltdm->volt_data; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * omap_voltage_get_voltdata() - API to get the voltage table entry for a |
| 164 | * particular voltage |
| 165 | * @voltdm: pointer to the VDD whose voltage table has to be searched |
| 166 | * @volt: the voltage to be searched in the voltage table |
| 167 | * |
| 168 | * This API searches through the voltage table for the required voltage |
| 169 | * domain and tries to find a matching entry for the passed voltage volt. |
| 170 | * If a matching entry is found volt_data is populated with that entry. |
| 171 | * This API searches only through the non-compensated voltages int the |
| 172 | * voltage table. |
| 173 | * Returns pointer to the voltage table entry corresponding to volt on |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 174 | * success. Returns -ENODATA if no voltage table exisits for the passed voltage |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 175 | * domain or if there is no matching entry. |
| 176 | */ |
| 177 | struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm, |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 178 | unsigned long volt) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 179 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 180 | int i; |
| 181 | |
| 182 | if (!voltdm || IS_ERR(voltdm)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 183 | pr_warn("%s: VDD specified does not exist!\n", __func__); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 184 | return ERR_PTR(-EINVAL); |
| 185 | } |
| 186 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 187 | if (!voltdm->volt_data) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 188 | pr_warn("%s: voltage table does not exist for vdd_%s\n", |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 189 | __func__, voltdm->name); |
| 190 | return ERR_PTR(-ENODATA); |
| 191 | } |
| 192 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 193 | for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) { |
| 194 | if (voltdm->volt_data[i].volt_nominal == volt) |
| 195 | return &voltdm->volt_data[i]; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 196 | } |
| 197 | |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 198 | pr_notice("%s: Unable to match the current voltage with the voltage table for vdd_%s\n", |
| 199 | __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 200 | |
| 201 | return ERR_PTR(-ENODATA); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * omap_voltage_register_pmic() - API to register PMIC specific data |
| 206 | * @voltdm: pointer to the VDD for which the PMIC specific data is |
| 207 | * to be registered |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 208 | * @pmic: the structure containing pmic info |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 209 | * |
| 210 | * This API is to be called by the SOC/PMIC file to specify the |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 211 | * pmic specific info as present in omap_voltdm_pmic structure. |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 212 | */ |
| 213 | int omap_voltage_register_pmic(struct voltagedomain *voltdm, |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 214 | struct omap_voltdm_pmic *pmic) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 215 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 216 | if (!voltdm || IS_ERR(voltdm)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 217 | pr_warn("%s: VDD specified does not exist!\n", __func__); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 218 | return -EINVAL; |
| 219 | } |
| 220 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 221 | voltdm->pmic = pmic; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | /** |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 227 | * omap_voltage_late_init() - Init the various voltage parameters |
| 228 | * |
| 229 | * This API is to be called in the later stages of the |
| 230 | * system boot to init the voltage controller and |
| 231 | * voltage processors. |
| 232 | */ |
| 233 | int __init omap_voltage_late_init(void) |
| 234 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 235 | struct voltagedomain *voltdm; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 236 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 237 | if (list_empty(&voltdm_list)) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 238 | pr_err("%s: Voltage driver support not added\n", |
| 239 | __func__); |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 243 | list_for_each_entry(voltdm, &voltdm_list, node) { |
Kevin Hilman | 0e2f3d9 | 2011-04-04 17:22:28 -0700 | [diff] [blame] | 244 | struct clk *sys_ck; |
| 245 | |
Kevin Hilman | 37efca7 | 2011-03-23 17:00:21 -0700 | [diff] [blame] | 246 | if (!voltdm->scalable) |
| 247 | continue; |
| 248 | |
Kevin Hilman | 0e2f3d9 | 2011-04-04 17:22:28 -0700 | [diff] [blame] | 249 | sys_ck = clk_get(NULL, voltdm->sys_clk.name); |
| 250 | if (IS_ERR(sys_ck)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 251 | pr_warn("%s: Could not get sys clk.\n", __func__); |
Kevin Hilman | 0e2f3d9 | 2011-04-04 17:22:28 -0700 | [diff] [blame] | 252 | return -EINVAL; |
| 253 | } |
| 254 | voltdm->sys_clk.rate = clk_get_rate(sys_ck); |
| 255 | WARN_ON(!voltdm->sys_clk.rate); |
| 256 | clk_put(sys_ck); |
| 257 | |
Kevin Hilman | 4d47506 | 2011-07-18 15:48:22 -0700 | [diff] [blame] | 258 | if (voltdm->vc) { |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 259 | voltdm->scale = omap_vc_bypass_scale; |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 260 | omap_vc_init_channel(voltdm); |
Kevin Hilman | 4d47506 | 2011-07-18 15:48:22 -0700 | [diff] [blame] | 261 | } |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 262 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 263 | if (voltdm->vp) { |
| 264 | voltdm->scale = omap_vp_forceupdate_scale; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 265 | omap_vp_init(voltdm); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 266 | } |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 272 | static struct voltagedomain *_voltdm_lookup(const char *name) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 273 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 274 | struct voltagedomain *voltdm, *temp_voltdm; |
| 275 | |
| 276 | voltdm = NULL; |
| 277 | |
| 278 | list_for_each_entry(temp_voltdm, &voltdm_list, node) { |
| 279 | if (!strcmp(name, temp_voltdm->name)) { |
| 280 | voltdm = temp_voltdm; |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | return voltdm; |
| 286 | } |
| 287 | |
| 288 | static int _voltdm_register(struct voltagedomain *voltdm) |
| 289 | { |
| 290 | if (!voltdm || !voltdm->name) |
| 291 | return -EINVAL; |
| 292 | |
| 293 | list_add(&voltdm->node, &voltdm_list); |
| 294 | |
| 295 | pr_debug("voltagedomain: registered %s\n", voltdm->name); |
| 296 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 297 | return 0; |
| 298 | } |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * voltdm_lookup - look up a voltagedomain by name, return a pointer |
| 302 | * @name: name of voltagedomain |
| 303 | * |
| 304 | * Find a registered voltagedomain by its name @name. Returns a pointer |
| 305 | * to the struct voltagedomain if found, or NULL otherwise. |
| 306 | */ |
| 307 | struct voltagedomain *voltdm_lookup(const char *name) |
| 308 | { |
| 309 | struct voltagedomain *voltdm ; |
| 310 | |
| 311 | if (!name) |
| 312 | return NULL; |
| 313 | |
| 314 | voltdm = _voltdm_lookup(name); |
| 315 | |
| 316 | return voltdm; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * voltdm_init - set up the voltagedomain layer |
| 321 | * @voltdm_list: array of struct voltagedomain pointers to register |
| 322 | * |
| 323 | * Loop through the array of voltagedomains @voltdm_list, registering all |
| 324 | * that are available on the current CPU. If voltdm_list is supplied |
| 325 | * and not null, all of the referenced voltagedomains will be |
| 326 | * registered. No return value. |
| 327 | */ |
| 328 | void voltdm_init(struct voltagedomain **voltdms) |
| 329 | { |
| 330 | struct voltagedomain **v; |
| 331 | |
| 332 | if (voltdms) { |
| 333 | for (v = voltdms; *v; v++) |
| 334 | _voltdm_register(*v); |
| 335 | } |
| 336 | } |