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)) { |
| 58 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 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 | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 76 | int ret; |
| 77 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 78 | if (!voltdm || IS_ERR(voltdm)) { |
| 79 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 80 | return -EINVAL; |
| 81 | } |
| 82 | |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 83 | if (!voltdm->scale) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 84 | pr_err("%s: No voltage scale API registered for vdd_%s\n", |
| 85 | __func__, voltdm->name); |
| 86 | return -ENODATA; |
| 87 | } |
| 88 | |
Kevin Hilman | 6a62b78 | 2011-07-18 16:24:17 -0700 | [diff] [blame] | 89 | ret = voltdm->scale(voltdm, target_volt); |
| 90 | if (!ret) |
| 91 | voltdm->nominal_volt = target_volt; |
| 92 | |
| 93 | return ret; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 97 | * voltdm_reset() - Resets the voltage of a particular voltage domain |
| 98 | * to that of the current OPP. |
| 99 | * @voltdm: pointer to the voltage domain whose voltage is to be reset. |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 100 | * |
| 101 | * 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] | 102 | * 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] | 103 | * while disabling any voltage compensation modules. |
| 104 | */ |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 105 | void voltdm_reset(struct voltagedomain *voltdm) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 106 | { |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 107 | unsigned long target_volt; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 108 | |
| 109 | if (!voltdm || IS_ERR(voltdm)) { |
| 110 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 111 | return; |
| 112 | } |
| 113 | |
Kevin Hilman | d5c1282 | 2011-07-15 16:05:12 -0700 | [diff] [blame] | 114 | target_volt = voltdm_get_voltage(voltdm); |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 115 | if (!target_volt) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 116 | pr_err("%s: unable to find current voltage for vdd_%s\n", |
| 117 | __func__, voltdm->name); |
| 118 | return; |
| 119 | } |
| 120 | |
Kevin Hilman | 5e5651b | 2011-04-05 16:27:21 -0700 | [diff] [blame] | 121 | voltdm_scale(voltdm, target_volt); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /** |
| 125 | * omap_voltage_get_volttable() - API to get the voltage table associated with a |
| 126 | * particular voltage domain. |
| 127 | * @voltdm: pointer to the VDD for which the voltage table is required |
| 128 | * @volt_data: the voltage table for the particular vdd which is to be |
| 129 | * populated by this API |
| 130 | * |
| 131 | * This API populates the voltage table associated with a VDD into the |
| 132 | * passed parameter pointer. Returns the count of distinct voltages |
| 133 | * supported by this vdd. |
| 134 | * |
| 135 | */ |
| 136 | void omap_voltage_get_volttable(struct voltagedomain *voltdm, |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 137 | struct omap_volt_data **volt_data) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 138 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 139 | if (!voltdm || IS_ERR(voltdm)) { |
| 140 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 141 | return; |
| 142 | } |
| 143 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 144 | *volt_data = voltdm->volt_data; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
| 148 | * omap_voltage_get_voltdata() - API to get the voltage table entry for a |
| 149 | * particular voltage |
| 150 | * @voltdm: pointer to the VDD whose voltage table has to be searched |
| 151 | * @volt: the voltage to be searched in the voltage table |
| 152 | * |
| 153 | * This API searches through the voltage table for the required voltage |
| 154 | * domain and tries to find a matching entry for the passed voltage volt. |
| 155 | * If a matching entry is found volt_data is populated with that entry. |
| 156 | * This API searches only through the non-compensated voltages int the |
| 157 | * voltage table. |
| 158 | * Returns pointer to the voltage table entry corresponding to volt on |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 159 | * success. Returns -ENODATA if no voltage table exisits for the passed voltage |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 160 | * domain or if there is no matching entry. |
| 161 | */ |
| 162 | struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm, |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 163 | unsigned long volt) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 164 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 165 | int i; |
| 166 | |
| 167 | if (!voltdm || IS_ERR(voltdm)) { |
| 168 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 169 | return ERR_PTR(-EINVAL); |
| 170 | } |
| 171 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 172 | if (!voltdm->volt_data) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 173 | pr_warning("%s: voltage table does not exist for vdd_%s\n", |
| 174 | __func__, voltdm->name); |
| 175 | return ERR_PTR(-ENODATA); |
| 176 | } |
| 177 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 178 | for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) { |
| 179 | if (voltdm->volt_data[i].volt_nominal == volt) |
| 180 | return &voltdm->volt_data[i]; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | pr_notice("%s: Unable to match the current voltage with the voltage" |
| 184 | "table for vdd_%s\n", __func__, voltdm->name); |
| 185 | |
| 186 | return ERR_PTR(-ENODATA); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * omap_voltage_register_pmic() - API to register PMIC specific data |
| 191 | * @voltdm: pointer to the VDD for which the PMIC specific data is |
| 192 | * to be registered |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 193 | * @pmic: the structure containing pmic info |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 194 | * |
| 195 | * 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] | 196 | * pmic specific info as present in omap_voltdm_pmic structure. |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 197 | */ |
| 198 | int omap_voltage_register_pmic(struct voltagedomain *voltdm, |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 199 | struct omap_voltdm_pmic *pmic) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 200 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 201 | if (!voltdm || IS_ERR(voltdm)) { |
| 202 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 206 | voltdm->pmic = pmic; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | /** |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 212 | * omap_change_voltscale_method() - API to change the voltage scaling method. |
| 213 | * @voltdm: pointer to the VDD whose voltage scaling method |
| 214 | * has to be changed. |
| 215 | * @voltscale_method: the method to be used for voltage scaling. |
| 216 | * |
| 217 | * This API can be used by the board files to change the method of voltage |
| 218 | * scaling between vpforceupdate and vcbypass. The parameter values are |
| 219 | * defined in voltage.h |
| 220 | */ |
| 221 | void omap_change_voltscale_method(struct voltagedomain *voltdm, |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 222 | int voltscale_method) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 223 | { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 224 | if (!voltdm || IS_ERR(voltdm)) { |
| 225 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 226 | return; |
| 227 | } |
| 228 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 229 | switch (voltscale_method) { |
| 230 | case VOLTSCALE_VPFORCEUPDATE: |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 231 | voltdm->scale = omap_vp_forceupdate_scale; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 232 | return; |
| 233 | case VOLTSCALE_VCBYPASS: |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 234 | voltdm->scale = omap_vc_bypass_scale; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 235 | return; |
| 236 | default: |
| 237 | pr_warning("%s: Trying to change the method of voltage scaling" |
| 238 | "to an unsupported one!\n", __func__); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 243 | * omap_voltage_late_init() - Init the various voltage parameters |
| 244 | * |
| 245 | * This API is to be called in the later stages of the |
| 246 | * system boot to init the voltage controller and |
| 247 | * voltage processors. |
| 248 | */ |
| 249 | int __init omap_voltage_late_init(void) |
| 250 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 251 | struct voltagedomain *voltdm; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 252 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 253 | if (list_empty(&voltdm_list)) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 254 | pr_err("%s: Voltage driver support not added\n", |
| 255 | __func__); |
| 256 | return -EINVAL; |
| 257 | } |
| 258 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 259 | list_for_each_entry(voltdm, &voltdm_list, node) { |
Kevin Hilman | 0e2f3d9 | 2011-04-04 17:22:28 -0700 | [diff] [blame] | 260 | struct clk *sys_ck; |
| 261 | |
Kevin Hilman | 37efca7 | 2011-03-23 17:00:21 -0700 | [diff] [blame] | 262 | if (!voltdm->scalable) |
| 263 | continue; |
| 264 | |
Kevin Hilman | 0e2f3d9 | 2011-04-04 17:22:28 -0700 | [diff] [blame] | 265 | sys_ck = clk_get(NULL, voltdm->sys_clk.name); |
| 266 | if (IS_ERR(sys_ck)) { |
| 267 | pr_warning("%s: Could not get sys clk.\n", __func__); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | voltdm->sys_clk.rate = clk_get_rate(sys_ck); |
| 271 | WARN_ON(!voltdm->sys_clk.rate); |
| 272 | clk_put(sys_ck); |
| 273 | |
Kevin Hilman | 4d47506 | 2011-07-18 15:48:22 -0700 | [diff] [blame] | 274 | if (voltdm->vc) { |
Kevin Hilman | 0f01565 | 2011-07-14 11:12:32 -0700 | [diff] [blame] | 275 | voltdm->scale = omap_vc_bypass_scale; |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 276 | omap_vc_init_channel(voltdm); |
Kevin Hilman | 4d47506 | 2011-07-18 15:48:22 -0700 | [diff] [blame] | 277 | } |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 278 | |
Kevin Hilman | e327788 | 2011-07-14 11:29:06 -0700 | [diff] [blame] | 279 | if (voltdm->vp) { |
| 280 | voltdm->scale = omap_vp_forceupdate_scale; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 281 | omap_vp_init(voltdm); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 282 | } |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 288 | static struct voltagedomain *_voltdm_lookup(const char *name) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 289 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 290 | struct voltagedomain *voltdm, *temp_voltdm; |
| 291 | |
| 292 | voltdm = NULL; |
| 293 | |
| 294 | list_for_each_entry(temp_voltdm, &voltdm_list, node) { |
| 295 | if (!strcmp(name, temp_voltdm->name)) { |
| 296 | voltdm = temp_voltdm; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | return voltdm; |
| 302 | } |
| 303 | |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 304 | /** |
| 305 | * voltdm_add_pwrdm - add a powerdomain to a voltagedomain |
| 306 | * @voltdm: struct voltagedomain * to add the powerdomain to |
| 307 | * @pwrdm: struct powerdomain * to associate with a voltagedomain |
| 308 | * |
| 309 | * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This |
| 310 | * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if |
| 311 | * presented with invalid pointers; -ENOMEM if memory could not be allocated; |
| 312 | * or 0 upon success. |
| 313 | */ |
| 314 | int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm) |
| 315 | { |
| 316 | if (!voltdm || !pwrdm) |
| 317 | return -EINVAL; |
| 318 | |
| 319 | pr_debug("voltagedomain: associating powerdomain %s with voltagedomain " |
| 320 | "%s\n", pwrdm->name, voltdm->name); |
| 321 | |
| 322 | list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm |
| 329 | * @voltdm: struct voltagedomain * to iterate over |
| 330 | * @fn: callback function * |
| 331 | * |
| 332 | * Call the supplied function @fn for each powerdomain in the |
| 333 | * voltagedomain @voltdm. Returns -EINVAL if presented with invalid |
| 334 | * pointers; or passes along the last return value of the callback |
| 335 | * function, which should be 0 for success or anything else to |
| 336 | * indicate failure. |
| 337 | */ |
| 338 | int voltdm_for_each_pwrdm(struct voltagedomain *voltdm, |
| 339 | int (*fn)(struct voltagedomain *voltdm, |
| 340 | struct powerdomain *pwrdm)) |
| 341 | { |
| 342 | struct powerdomain *pwrdm; |
| 343 | int ret = 0; |
| 344 | |
| 345 | if (!fn) |
| 346 | return -EINVAL; |
| 347 | |
| 348 | list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node) |
| 349 | ret = (*fn)(voltdm, pwrdm); |
| 350 | |
| 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * voltdm_for_each - call function on each registered voltagedomain |
| 356 | * @fn: callback function * |
| 357 | * |
| 358 | * Call the supplied function @fn for each registered voltagedomain. |
| 359 | * The callback function @fn can return anything but 0 to bail out |
| 360 | * early from the iterator. Returns the last return value of the |
| 361 | * callback function, which should be 0 for success or anything else |
| 362 | * to indicate failure; or -EINVAL if the function pointer is null. |
| 363 | */ |
| 364 | int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user), |
| 365 | void *user) |
| 366 | { |
| 367 | struct voltagedomain *temp_voltdm; |
| 368 | int ret = 0; |
| 369 | |
| 370 | if (!fn) |
| 371 | return -EINVAL; |
| 372 | |
| 373 | list_for_each_entry(temp_voltdm, &voltdm_list, node) { |
| 374 | ret = (*fn)(temp_voltdm, user); |
| 375 | if (ret) |
| 376 | break; |
| 377 | } |
| 378 | |
| 379 | return ret; |
| 380 | } |
| 381 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 382 | static int _voltdm_register(struct voltagedomain *voltdm) |
| 383 | { |
| 384 | if (!voltdm || !voltdm->name) |
| 385 | return -EINVAL; |
| 386 | |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 387 | INIT_LIST_HEAD(&voltdm->pwrdm_list); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 388 | list_add(&voltdm->node, &voltdm_list); |
| 389 | |
| 390 | pr_debug("voltagedomain: registered %s\n", voltdm->name); |
| 391 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 392 | return 0; |
| 393 | } |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 394 | |
| 395 | /** |
| 396 | * voltdm_lookup - look up a voltagedomain by name, return a pointer |
| 397 | * @name: name of voltagedomain |
| 398 | * |
| 399 | * Find a registered voltagedomain by its name @name. Returns a pointer |
| 400 | * to the struct voltagedomain if found, or NULL otherwise. |
| 401 | */ |
| 402 | struct voltagedomain *voltdm_lookup(const char *name) |
| 403 | { |
| 404 | struct voltagedomain *voltdm ; |
| 405 | |
| 406 | if (!name) |
| 407 | return NULL; |
| 408 | |
| 409 | voltdm = _voltdm_lookup(name); |
| 410 | |
| 411 | return voltdm; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * voltdm_init - set up the voltagedomain layer |
| 416 | * @voltdm_list: array of struct voltagedomain pointers to register |
| 417 | * |
| 418 | * Loop through the array of voltagedomains @voltdm_list, registering all |
| 419 | * that are available on the current CPU. If voltdm_list is supplied |
| 420 | * and not null, all of the referenced voltagedomains will be |
| 421 | * registered. No return value. |
| 422 | */ |
| 423 | void voltdm_init(struct voltagedomain **voltdms) |
| 424 | { |
| 425 | struct voltagedomain **v; |
| 426 | |
| 427 | if (voltdms) { |
| 428 | for (v = voltdms; *v; v++) |
| 429 | _voltdm_register(*v); |
| 430 | } |
| 431 | } |