Priyanka Mathur | 86cfc76 | 2013-01-10 17:03:04 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 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 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/of.h> |
| 20 | #include <linux/cpu.h> |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 21 | #include <linux/notifier.h> |
| 22 | #include <linux/hrtimer.h> |
| 23 | #include <linux/tick.h> |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 24 | #include <mach/mpm.h> |
| 25 | #include <mach/rpm-smd.h> |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 26 | #include "spm.h" |
| 27 | #include "lpm_resources.h" |
| 28 | #include "rpm-notifier.h" |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 29 | #include "idle.h" |
Priyanka Mathur | b44bf57 | 2012-11-07 12:07:45 -0800 | [diff] [blame] | 30 | #include "trace_msm_low_power.h" |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 31 | |
| 32 | /*Debug Definitions*/ |
| 33 | enum { |
| 34 | MSM_LPMRS_DEBUG_RPM = BIT(0), |
| 35 | MSM_LPMRS_DEBUG_PXO = BIT(1), |
| 36 | MSM_LPMRS_DEBUG_VDD_DIG = BIT(2), |
| 37 | MSM_LPMRS_DEBUG_VDD_MEM = BIT(3), |
| 38 | MSM_LPMRS_DEBUG_L2 = BIT(4), |
| 39 | MSM_LPMRS_DEBUG_LVLS = BIT(5), |
| 40 | }; |
| 41 | |
| 42 | static int msm_lpm_debug_mask; |
| 43 | module_param_named( |
| 44 | debug_mask, msm_lpm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP |
| 45 | ); |
| 46 | |
| 47 | static bool msm_lpm_get_rpm_notif = true; |
| 48 | |
| 49 | /*Macros*/ |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 50 | #define MAX_RS_NAME (16) |
| 51 | #define MAX_RS_SIZE (4) |
| 52 | #define IS_RPM_CTL(rs) \ |
| 53 | (!strncmp(rs->name, "rpm_ctl", MAX_RS_NAME)) |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 54 | #define MAX_STR_LEN 30 |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 55 | |
| 56 | static bool msm_lpm_beyond_limits_vdd_dig(struct msm_rpmrs_limits *limits); |
| 57 | static void msm_lpm_aggregate_vdd_dig(struct msm_rpmrs_limits *limits); |
| 58 | static void msm_lpm_flush_vdd_dig(int notify_rpm); |
| 59 | static void msm_lpm_notify_vdd_dig(struct msm_rpm_notifier_data |
| 60 | *rpm_notifier_cb); |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 61 | static int msm_lpm_init_value_vdd_dig(struct device_node *node, |
| 62 | char *key, uint32_t *default_value); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 63 | |
| 64 | static bool msm_lpm_beyond_limits_vdd_mem(struct msm_rpmrs_limits *limits); |
| 65 | static void msm_lpm_aggregate_vdd_mem(struct msm_rpmrs_limits *limits); |
| 66 | static void msm_lpm_flush_vdd_mem(int notify_rpm); |
| 67 | static void msm_lpm_notify_vdd_mem(struct msm_rpm_notifier_data |
| 68 | *rpm_notifier_cb); |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 69 | static int msm_lpm_init_value_vdd_mem(struct device_node *node, |
| 70 | char *key, uint32_t *default_value); |
| 71 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 72 | |
| 73 | static bool msm_lpm_beyond_limits_pxo(struct msm_rpmrs_limits *limits); |
| 74 | static void msm_lpm_aggregate_pxo(struct msm_rpmrs_limits *limits); |
| 75 | static void msm_lpm_flush_pxo(int notify_rpm); |
| 76 | static void msm_lpm_notify_pxo(struct msm_rpm_notifier_data |
| 77 | *rpm_notifier_cb); |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 78 | static int msm_lpm_init_value_pxo(struct device_node *node, |
| 79 | char *key, uint32_t *default_value); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 80 | |
| 81 | |
| 82 | static bool msm_lpm_beyond_limits_l2(struct msm_rpmrs_limits *limits); |
| 83 | static void msm_lpm_flush_l2(int notify_rpm); |
| 84 | static void msm_lpm_aggregate_l2(struct msm_rpmrs_limits *limits); |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 85 | static int msm_lpm_init_value_l2(struct device_node *node, |
| 86 | char *key, uint32_t *default_value); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 87 | |
| 88 | static void msm_lpm_flush_rpm_ctl(int notify_rpm); |
| 89 | |
| 90 | static int msm_lpm_rpm_callback(struct notifier_block *rpm_nb, |
| 91 | unsigned long action, void *rpm_notif); |
| 92 | |
| 93 | static int msm_lpm_cpu_callback(struct notifier_block *cpu_nb, |
| 94 | unsigned long action, void *hcpu); |
| 95 | |
| 96 | static ssize_t msm_lpm_resource_attr_show( |
| 97 | struct kobject *kobj, struct kobj_attribute *attr, char *buf); |
| 98 | static ssize_t msm_lpm_resource_attr_store(struct kobject *kobj, |
| 99 | struct kobj_attribute *attr, const char *buf, size_t count); |
| 100 | |
| 101 | |
| 102 | #define RPMRS_ATTR(_name) \ |
| 103 | __ATTR(_name, S_IRUGO|S_IWUSR, \ |
| 104 | msm_lpm_resource_attr_show, msm_lpm_resource_attr_store) |
| 105 | |
| 106 | /*Data structures*/ |
| 107 | struct msm_lpm_rs_data { |
| 108 | uint32_t type; |
| 109 | uint32_t id; |
| 110 | uint32_t key; |
| 111 | uint32_t value; |
| 112 | uint32_t default_value; |
| 113 | struct msm_rpm_request *handle; |
| 114 | }; |
| 115 | |
Girish Mahadevan | 909dbce | 2012-09-25 09:38:03 -0600 | [diff] [blame] | 116 | enum { |
| 117 | MSM_LPM_RPM_RS_TYPE = 0, |
| 118 | MSM_LPM_LOCAL_RS_TYPE = 1, |
| 119 | }; |
| 120 | |
Mahesh Sivasubramanian | 1523acc | 2013-02-21 18:22:30 -0700 | [diff] [blame] | 121 | enum { |
| 122 | MSM_SCM_L2_ON = 0, |
| 123 | MSM_SCM_L2_OFF = 1, |
| 124 | MSM_SCM_L2_GDHS = 3, |
| 125 | }; |
| 126 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 127 | struct msm_lpm_resource { |
| 128 | struct msm_lpm_rs_data rs_data; |
| 129 | uint32_t sleep_value; |
| 130 | char name[MAX_RS_NAME]; |
| 131 | |
| 132 | uint32_t enable_low_power; |
| 133 | bool valid; |
| 134 | |
| 135 | bool (*beyond_limits)(struct msm_rpmrs_limits *limits); |
| 136 | void (*aggregate)(struct msm_rpmrs_limits *limits); |
| 137 | void (*flush)(int notify_rpm); |
| 138 | void (*notify)(struct msm_rpm_notifier_data *rpm_notifier_cb); |
| 139 | struct kobj_attribute ko_attr; |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 140 | int (*init_value)(struct device_node *node, |
| 141 | char *key, uint32_t *default_value); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 142 | }; |
| 143 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 144 | struct lpm_lookup_table { |
| 145 | uint32_t modes; |
| 146 | const char *mode_name; |
| 147 | }; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 148 | |
| 149 | static struct msm_lpm_resource msm_lpm_l2 = { |
| 150 | .name = "l2", |
| 151 | .beyond_limits = msm_lpm_beyond_limits_l2, |
| 152 | .aggregate = msm_lpm_aggregate_l2, |
| 153 | .flush = msm_lpm_flush_l2, |
| 154 | .notify = NULL, |
Girish Mahadevan | 909dbce | 2012-09-25 09:38:03 -0600 | [diff] [blame] | 155 | .valid = false, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 156 | .ko_attr = RPMRS_ATTR(l2), |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 157 | .init_value = msm_lpm_init_value_l2, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | static struct msm_lpm_resource msm_lpm_vdd_dig = { |
| 161 | .name = "vdd-dig", |
| 162 | .beyond_limits = msm_lpm_beyond_limits_vdd_dig, |
| 163 | .aggregate = msm_lpm_aggregate_vdd_dig, |
| 164 | .flush = msm_lpm_flush_vdd_dig, |
| 165 | .notify = msm_lpm_notify_vdd_dig, |
| 166 | .valid = false, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 167 | .ko_attr = RPMRS_ATTR(vdd_dig), |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 168 | .init_value = msm_lpm_init_value_vdd_dig, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | static struct msm_lpm_resource msm_lpm_vdd_mem = { |
| 172 | .name = "vdd-mem", |
| 173 | .beyond_limits = msm_lpm_beyond_limits_vdd_mem, |
| 174 | .aggregate = msm_lpm_aggregate_vdd_mem, |
| 175 | .flush = msm_lpm_flush_vdd_mem, |
| 176 | .notify = msm_lpm_notify_vdd_mem, |
| 177 | .valid = false, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 178 | .ko_attr = RPMRS_ATTR(vdd_mem), |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 179 | .init_value = msm_lpm_init_value_vdd_mem, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | static struct msm_lpm_resource msm_lpm_pxo = { |
| 183 | .name = "pxo", |
| 184 | .beyond_limits = msm_lpm_beyond_limits_pxo, |
| 185 | .aggregate = msm_lpm_aggregate_pxo, |
| 186 | .flush = msm_lpm_flush_pxo, |
| 187 | .notify = msm_lpm_notify_pxo, |
| 188 | .valid = false, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 189 | .ko_attr = RPMRS_ATTR(pxo), |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 190 | .init_value = msm_lpm_init_value_pxo, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | static struct msm_lpm_resource *msm_lpm_resources[] = { |
| 194 | &msm_lpm_vdd_dig, |
| 195 | &msm_lpm_vdd_mem, |
| 196 | &msm_lpm_pxo, |
| 197 | &msm_lpm_l2, |
| 198 | }; |
| 199 | |
| 200 | static struct msm_lpm_resource msm_lpm_rpm_ctl = { |
| 201 | .name = "rpm_ctl", |
| 202 | .beyond_limits = NULL, |
| 203 | .aggregate = NULL, |
| 204 | .flush = msm_lpm_flush_rpm_ctl, |
| 205 | .valid = true, |
| 206 | .ko_attr = RPMRS_ATTR(rpm_ctl), |
| 207 | }; |
| 208 | |
| 209 | static struct notifier_block msm_lpm_rpm_nblk = { |
| 210 | .notifier_call = msm_lpm_rpm_callback, |
| 211 | }; |
| 212 | |
| 213 | static struct notifier_block __refdata msm_lpm_cpu_nblk = { |
| 214 | .notifier_call = msm_lpm_cpu_callback, |
| 215 | }; |
| 216 | |
| 217 | static DEFINE_SPINLOCK(msm_lpm_sysfs_lock); |
| 218 | |
| 219 | /* Attribute Definitions */ |
| 220 | static struct attribute *msm_lpm_attributes[] = { |
| 221 | &msm_lpm_vdd_dig.ko_attr.attr, |
| 222 | &msm_lpm_vdd_mem.ko_attr.attr, |
| 223 | &msm_lpm_pxo.ko_attr.attr, |
| 224 | &msm_lpm_l2.ko_attr.attr, |
| 225 | NULL, |
| 226 | }; |
| 227 | |
| 228 | static struct attribute_group msm_lpm_attribute_group = { |
| 229 | .attrs = msm_lpm_attributes, |
| 230 | }; |
| 231 | |
| 232 | static struct attribute *msm_lpm_rpm_ctl_attribute[] = { |
| 233 | &msm_lpm_rpm_ctl.ko_attr.attr, |
| 234 | NULL, |
| 235 | }; |
| 236 | |
| 237 | static struct attribute_group msm_lpm_rpm_ctl_attr_group = { |
| 238 | .attrs = msm_lpm_rpm_ctl_attribute, |
| 239 | }; |
| 240 | |
| 241 | #define GET_RS_FROM_ATTR(attr) \ |
| 242 | (container_of(attr, struct msm_lpm_resource, ko_attr)) |
| 243 | |
| 244 | /* RPM */ |
| 245 | static struct msm_rpm_request *msm_lpm_create_rpm_request |
| 246 | (uint32_t rsc_type, uint32_t rsc_id) |
| 247 | { |
| 248 | struct msm_rpm_request *handle = NULL; |
| 249 | |
| 250 | handle = msm_rpm_create_request(MSM_RPM_CTX_SLEEP_SET, |
| 251 | rsc_type, |
| 252 | rsc_id, 1); |
| 253 | return handle; |
| 254 | } |
| 255 | |
| 256 | static int msm_lpm_send_sleep_data(struct msm_rpm_request *handle, |
| 257 | uint32_t key, uint8_t *value) |
| 258 | { |
| 259 | int ret = 0; |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 260 | int msg_id; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 261 | |
| 262 | if (!handle) |
| 263 | return ret; |
| 264 | |
| 265 | ret = msm_rpm_add_kvp_data_noirq(handle, key, value, MAX_RS_SIZE); |
| 266 | |
| 267 | if (ret < 0) { |
| 268 | pr_err("%s: Error adding kvp data key %u, size %d\n", |
| 269 | __func__, key, MAX_RS_SIZE); |
| 270 | return ret; |
| 271 | } |
| 272 | |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 273 | msg_id = msm_rpm_send_request_noirq(handle); |
| 274 | if (!msg_id) { |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 275 | pr_err("%s: Error sending RPM request key %u, handle 0x%x\n", |
| 276 | __func__, key, (unsigned int)handle); |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 277 | ret = -EIO; |
| 278 | return ret; |
| 279 | } |
| 280 | |
Mahesh Sivasubramanian | b949858 | 2012-07-25 11:22:56 -0600 | [diff] [blame] | 281 | ret = msm_rpm_wait_for_ack_noirq(msg_id); |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 282 | if (ret < 0) { |
| 283 | pr_err("%s: Couldn't get ACK from RPM for Msg %d Error %d", |
| 284 | __func__, msg_id, ret); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 285 | return ret; |
| 286 | } |
| 287 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_RPM) |
| 288 | pr_info("Rs key %u, value %u, size %d\n", key, |
| 289 | *(unsigned int *)value, MAX_RS_SIZE); |
| 290 | return ret; |
| 291 | } |
| 292 | |
| 293 | /* RPM Notifier */ |
| 294 | static int msm_lpm_rpm_callback(struct notifier_block *rpm_nb, |
| 295 | unsigned long action, |
| 296 | void *rpm_notif) |
| 297 | { |
| 298 | int i; |
| 299 | struct msm_lpm_resource *rs = NULL; |
| 300 | struct msm_rpm_notifier_data *rpm_notifier_cb = |
| 301 | (struct msm_rpm_notifier_data *)rpm_notif; |
| 302 | |
| 303 | if (!msm_lpm_get_rpm_notif) |
| 304 | return NOTIFY_DONE; |
| 305 | |
| 306 | if (!(rpm_nb && rpm_notif)) |
| 307 | return NOTIFY_BAD; |
| 308 | |
| 309 | for (i = 0; i < ARRAY_SIZE(msm_lpm_resources); i++) { |
| 310 | rs = msm_lpm_resources[i]; |
| 311 | if (rs && rs->valid && rs->notify) |
| 312 | rs->notify(rpm_notifier_cb); |
| 313 | } |
| 314 | |
| 315 | return NOTIFY_OK; |
| 316 | } |
| 317 | |
| 318 | /* SYSFS */ |
| 319 | static ssize_t msm_lpm_resource_attr_show( |
| 320 | struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 321 | { |
| 322 | struct kernel_param kp; |
| 323 | unsigned long flags; |
| 324 | unsigned int temp; |
| 325 | int rc; |
| 326 | |
| 327 | spin_lock_irqsave(&msm_lpm_sysfs_lock, flags); |
| 328 | temp = GET_RS_FROM_ATTR(attr)->enable_low_power; |
| 329 | spin_unlock_irqrestore(&msm_lpm_sysfs_lock, flags); |
| 330 | |
| 331 | kp.arg = &temp; |
| 332 | rc = param_get_uint(buf, &kp); |
| 333 | |
| 334 | if (rc > 0) { |
| 335 | strlcat(buf, "\n", PAGE_SIZE); |
| 336 | rc++; |
| 337 | } |
| 338 | |
| 339 | return rc; |
| 340 | } |
| 341 | |
| 342 | static ssize_t msm_lpm_resource_attr_store(struct kobject *kobj, |
| 343 | struct kobj_attribute *attr, const char *buf, size_t count) |
| 344 | { |
| 345 | struct kernel_param kp; |
| 346 | unsigned long flags; |
| 347 | unsigned int temp; |
| 348 | int rc; |
| 349 | |
| 350 | kp.arg = &temp; |
| 351 | rc = param_set_uint(buf, &kp); |
| 352 | if (rc) |
| 353 | return rc; |
| 354 | |
| 355 | spin_lock_irqsave(&msm_lpm_sysfs_lock, flags); |
| 356 | GET_RS_FROM_ATTR(attr)->enable_low_power = temp; |
| 357 | |
| 358 | if (IS_RPM_CTL(GET_RS_FROM_ATTR(attr))) { |
| 359 | struct msm_lpm_resource *rs = GET_RS_FROM_ATTR(attr); |
| 360 | rs->flush(false); |
| 361 | } |
| 362 | |
| 363 | spin_unlock_irqrestore(&msm_lpm_sysfs_lock, flags); |
| 364 | |
| 365 | return count; |
| 366 | } |
| 367 | |
| 368 | /* lpm resource handling functions */ |
| 369 | /* Common */ |
Mahesh Sivasubramanian | f999d2e | 2012-08-06 13:26:49 -0600 | [diff] [blame] | 370 | static void msm_lpm_notify_common(struct msm_rpm_notifier_data *cb, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 371 | struct msm_lpm_resource *rs) |
| 372 | { |
Mahesh Sivasubramanian | f999d2e | 2012-08-06 13:26:49 -0600 | [diff] [blame] | 373 | if ((cb->rsc_type == rs->rs_data.type) && |
| 374 | (cb->rsc_id == rs->rs_data.id) && |
| 375 | (cb->key == rs->rs_data.key)) { |
| 376 | |
| 377 | BUG_ON(cb->size > MAX_RS_SIZE); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 378 | |
| 379 | if (rs->valid) { |
Mahesh Sivasubramanian | f999d2e | 2012-08-06 13:26:49 -0600 | [diff] [blame] | 380 | if (cb->value) { |
| 381 | memcpy(&rs->rs_data.value, cb->value, cb->size); |
| 382 | msm_rpm_add_kvp_data_noirq(rs->rs_data.handle, |
| 383 | cb->key, cb->value, cb->size); |
| 384 | } |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 385 | else |
| 386 | rs->rs_data.value = rs->rs_data.default_value; |
| 387 | |
| 388 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_RPM) |
| 389 | pr_info("Notification received Rs %s value %u\n", |
| 390 | rs->name, rs->rs_data.value); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /* L2 */ |
| 396 | static bool msm_lpm_beyond_limits_l2(struct msm_rpmrs_limits *limits) |
| 397 | { |
| 398 | uint32_t l2; |
Girish Mahadevan | ce5a173 | 2012-10-10 18:53:47 -0600 | [diff] [blame] | 399 | bool ret = false; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 400 | struct msm_lpm_resource *rs = &msm_lpm_l2; |
| 401 | |
| 402 | if (rs->valid) { |
| 403 | uint32_t l2_buf = rs->rs_data.value; |
| 404 | |
| 405 | if (rs->enable_low_power == 1) |
| 406 | l2 = MSM_LPM_L2_CACHE_GDHS; |
| 407 | else if (rs->enable_low_power == 2) |
| 408 | l2 = MSM_LPM_L2_CACHE_HSFS_OPEN; |
| 409 | else |
| 410 | l2 = MSM_LPM_L2_CACHE_ACTIVE ; |
| 411 | |
| 412 | if (l2_buf > l2) |
| 413 | l2 = l2_buf; |
| 414 | ret = (l2 > limits->l2_cache); |
| 415 | |
| 416 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_L2) |
| 417 | pr_info("%s: l2 buf %u, l2 %u, limits %u\n", |
| 418 | __func__, l2_buf, l2, limits->l2_cache); |
| 419 | } |
| 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | static void msm_lpm_aggregate_l2(struct msm_rpmrs_limits *limits) |
| 424 | { |
| 425 | struct msm_lpm_resource *rs = &msm_lpm_l2; |
| 426 | |
| 427 | if (rs->valid) |
| 428 | rs->sleep_value = limits->l2_cache; |
Priyanka Mathur | b44bf57 | 2012-11-07 12:07:45 -0800 | [diff] [blame] | 429 | trace_lpm_resources(rs->sleep_value, rs->name); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 430 | } |
| 431 | |
Girish Mahadevan | ee035b9 | 2013-04-11 10:49:50 -0600 | [diff] [blame] | 432 | static void msm_lpm_set_l2_mode(int sleep_mode) |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 433 | { |
Mahesh Sivasubramanian | e5d039a | 2012-11-30 14:22:00 -0700 | [diff] [blame] | 434 | int lpm, rc; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 435 | |
Mahesh Sivasubramanian | 1523acc | 2013-02-21 18:22:30 -0700 | [diff] [blame] | 436 | msm_pm_set_l2_flush_flag(MSM_SCM_L2_ON); |
Mahesh Sivasubramanian | e5d039a | 2012-11-30 14:22:00 -0700 | [diff] [blame] | 437 | |
| 438 | switch (sleep_mode) { |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 439 | case MSM_LPM_L2_CACHE_HSFS_OPEN: |
| 440 | lpm = MSM_SPM_L2_MODE_POWER_COLLAPSE; |
Mahesh Sivasubramanian | 1523acc | 2013-02-21 18:22:30 -0700 | [diff] [blame] | 441 | msm_pm_set_l2_flush_flag(MSM_SCM_L2_OFF); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 442 | break; |
| 443 | case MSM_LPM_L2_CACHE_GDHS: |
| 444 | lpm = MSM_SPM_L2_MODE_GDHS; |
Mahesh Sivasubramanian | 1523acc | 2013-02-21 18:22:30 -0700 | [diff] [blame] | 445 | msm_pm_set_l2_flush_flag(MSM_SCM_L2_GDHS); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 446 | break; |
| 447 | case MSM_LPM_L2_CACHE_RETENTION: |
| 448 | lpm = MSM_SPM_L2_MODE_RETENTION; |
| 449 | break; |
| 450 | default: |
| 451 | case MSM_LPM_L2_CACHE_ACTIVE: |
| 452 | lpm = MSM_SPM_L2_MODE_DISABLED; |
| 453 | break; |
| 454 | } |
| 455 | |
Girish Mahadevan | ee035b9 | 2013-04-11 10:49:50 -0600 | [diff] [blame] | 456 | rc = msm_spm_l2_set_low_power_mode(lpm, true); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 457 | |
| 458 | if (rc < 0) |
| 459 | pr_err("%s: Failed to set L2 low power mode %d", |
| 460 | __func__, lpm); |
| 461 | |
| 462 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_L2) |
| 463 | pr_info("%s: Requesting low power mode %d\n", |
| 464 | __func__, lpm); |
| 465 | } |
| 466 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 467 | static int msm_lpm_init_value_l2(struct device_node *node, |
| 468 | char *key, uint32_t *default_value) |
| 469 | { |
| 470 | return msm_lpm_get_l2_cache_value(node, key, default_value); |
| 471 | } |
| 472 | |
Mahesh Sivasubramanian | e5d039a | 2012-11-30 14:22:00 -0700 | [diff] [blame] | 473 | static void msm_lpm_flush_l2(int notify_rpm) |
| 474 | { |
| 475 | struct msm_lpm_resource *rs = &msm_lpm_l2; |
| 476 | |
Girish Mahadevan | ee035b9 | 2013-04-11 10:49:50 -0600 | [diff] [blame] | 477 | msm_lpm_set_l2_mode(rs->sleep_value); |
Mahesh Sivasubramanian | e5d039a | 2012-11-30 14:22:00 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 480 | int msm_lpm_get_l2_cache_value(struct device_node *node, |
| 481 | char *key, uint32_t *l2_val) |
| 482 | { |
| 483 | int i; |
| 484 | struct lpm_lookup_table l2_mode_lookup[] = { |
| 485 | {MSM_LPM_L2_CACHE_HSFS_OPEN, "l2_cache_pc"}, |
| 486 | {MSM_LPM_L2_CACHE_GDHS, "l2_cache_gdhs"}, |
| 487 | {MSM_LPM_L2_CACHE_RETENTION, "l2_cache_retention"}, |
| 488 | {MSM_LPM_L2_CACHE_ACTIVE, "l2_cache_active"} |
| 489 | }; |
| 490 | const char *l2_str; |
| 491 | int ret; |
| 492 | |
| 493 | ret = of_property_read_string(node, key, &l2_str); |
| 494 | if (!ret) { |
| 495 | ret = -EINVAL; |
| 496 | for (i = 0; i < ARRAY_SIZE(l2_mode_lookup); i++) { |
| 497 | if (!strncmp(l2_str, l2_mode_lookup[i].mode_name, |
| 498 | MAX_STR_LEN)) { |
| 499 | *l2_val = l2_mode_lookup[i].modes; |
| 500 | ret = 0; |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | return ret; |
| 506 | } |
| 507 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 508 | /* RPM CTL */ |
| 509 | static void msm_lpm_flush_rpm_ctl(int notify_rpm) |
| 510 | { |
| 511 | struct msm_lpm_resource *rs = &msm_lpm_rpm_ctl; |
| 512 | msm_lpm_send_sleep_data(rs->rs_data.handle, |
| 513 | rs->rs_data.key, |
| 514 | (uint8_t *)&rs->sleep_value); |
| 515 | } |
| 516 | |
| 517 | /*VDD Dig*/ |
| 518 | static bool msm_lpm_beyond_limits_vdd_dig(struct msm_rpmrs_limits *limits) |
| 519 | { |
| 520 | bool ret = true; |
| 521 | struct msm_lpm_resource *rs = &msm_lpm_vdd_dig; |
| 522 | |
| 523 | if (rs->valid) { |
| 524 | uint32_t vdd_buf = rs->rs_data.value; |
| 525 | uint32_t vdd_dig = rs->enable_low_power ? rs->enable_low_power : |
| 526 | rs->rs_data.default_value; |
| 527 | |
| 528 | if (vdd_buf > vdd_dig) |
| 529 | vdd_dig = vdd_buf; |
| 530 | |
| 531 | ret = (vdd_dig > limits->vdd_dig_upper_bound); |
| 532 | |
| 533 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_VDD_DIG) |
| 534 | pr_info("%s:buf %d vdd dig %d limits%d\n", |
| 535 | __func__, vdd_buf, vdd_dig, |
| 536 | limits->vdd_dig_upper_bound); |
| 537 | } |
| 538 | return ret; |
| 539 | } |
| 540 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 541 | static int msm_lpm_init_value_vdd_dig(struct device_node *node, |
| 542 | char *key, uint32_t *default_value) |
| 543 | { |
| 544 | return of_property_read_u32(node, key, default_value); |
| 545 | } |
| 546 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 547 | static void msm_lpm_aggregate_vdd_dig(struct msm_rpmrs_limits *limits) |
| 548 | { |
| 549 | struct msm_lpm_resource *rs = &msm_lpm_vdd_dig; |
| 550 | |
| 551 | if (rs->valid) { |
| 552 | uint32_t vdd_buf = rs->rs_data.value; |
| 553 | if (limits->vdd_dig_lower_bound > vdd_buf) |
| 554 | rs->sleep_value = limits->vdd_dig_lower_bound; |
| 555 | else |
| 556 | rs->sleep_value = vdd_buf; |
| 557 | } |
Priyanka Mathur | b44bf57 | 2012-11-07 12:07:45 -0800 | [diff] [blame] | 558 | trace_lpm_resources(rs->sleep_value, rs->name); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static void msm_lpm_flush_vdd_dig(int notify_rpm) |
| 562 | { |
| 563 | if (notify_rpm) { |
| 564 | struct msm_lpm_resource *rs = &msm_lpm_vdd_dig; |
| 565 | msm_lpm_send_sleep_data(rs->rs_data.handle, |
| 566 | rs->rs_data.key, |
| 567 | (uint8_t *)&rs->sleep_value); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | static void msm_lpm_notify_vdd_dig(struct msm_rpm_notifier_data |
| 572 | *rpm_notifier_cb) |
| 573 | { |
| 574 | struct msm_lpm_resource *rs = &msm_lpm_vdd_dig; |
| 575 | msm_lpm_notify_common(rpm_notifier_cb, rs); |
| 576 | } |
| 577 | |
| 578 | /*VDD Mem*/ |
| 579 | static bool msm_lpm_beyond_limits_vdd_mem(struct msm_rpmrs_limits *limits) |
| 580 | { |
| 581 | bool ret = true; |
| 582 | struct msm_lpm_resource *rs = &msm_lpm_vdd_mem; |
| 583 | |
| 584 | if (rs->valid) { |
| 585 | uint32_t vdd_buf = rs->rs_data.value; |
| 586 | uint32_t vdd_mem = rs->enable_low_power ? rs->enable_low_power : |
| 587 | rs->rs_data.default_value; |
| 588 | |
| 589 | if (vdd_buf > vdd_mem) |
| 590 | vdd_mem = vdd_buf; |
| 591 | |
| 592 | ret = (vdd_mem > limits->vdd_mem_upper_bound); |
| 593 | |
| 594 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_VDD_MEM) |
| 595 | pr_info("%s:buf %d vdd mem %d limits%d\n", |
| 596 | __func__, vdd_buf, vdd_mem, |
| 597 | limits->vdd_mem_upper_bound); |
| 598 | } |
| 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | static void msm_lpm_aggregate_vdd_mem(struct msm_rpmrs_limits *limits) |
| 603 | { |
| 604 | struct msm_lpm_resource *rs = &msm_lpm_vdd_mem; |
| 605 | |
| 606 | if (rs->valid) { |
| 607 | uint32_t vdd_buf = rs->rs_data.value; |
| 608 | if (limits->vdd_mem_lower_bound > vdd_buf) |
| 609 | rs->sleep_value = limits->vdd_mem_lower_bound; |
| 610 | else |
| 611 | rs->sleep_value = vdd_buf; |
| 612 | } |
Priyanka Mathur | b44bf57 | 2012-11-07 12:07:45 -0800 | [diff] [blame] | 613 | trace_lpm_resources(rs->sleep_value, rs->name); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void msm_lpm_flush_vdd_mem(int notify_rpm) |
| 617 | { |
| 618 | if (notify_rpm) { |
| 619 | struct msm_lpm_resource *rs = &msm_lpm_vdd_mem; |
| 620 | msm_lpm_send_sleep_data(rs->rs_data.handle, |
| 621 | rs->rs_data.key, |
| 622 | (uint8_t *)&rs->sleep_value); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | static void msm_lpm_notify_vdd_mem(struct msm_rpm_notifier_data |
| 627 | *rpm_notifier_cb) |
| 628 | { |
| 629 | struct msm_lpm_resource *rs = &msm_lpm_vdd_mem; |
| 630 | msm_lpm_notify_common(rpm_notifier_cb, rs); |
| 631 | } |
| 632 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 633 | static int msm_lpm_init_value_vdd_mem(struct device_node *node, |
| 634 | char *key, uint32_t *default_value) |
| 635 | { |
| 636 | return of_property_read_u32(node, key, default_value); |
| 637 | } |
| 638 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 639 | /*PXO*/ |
| 640 | static bool msm_lpm_beyond_limits_pxo(struct msm_rpmrs_limits *limits) |
| 641 | { |
| 642 | bool ret = true; |
| 643 | struct msm_lpm_resource *rs = &msm_lpm_pxo; |
| 644 | |
| 645 | if (rs->valid) { |
| 646 | uint32_t pxo_buf = rs->rs_data.value; |
| 647 | uint32_t pxo = rs->enable_low_power ? MSM_LPM_PXO_OFF : |
| 648 | rs->rs_data.default_value; |
| 649 | |
| 650 | if (pxo_buf > pxo) |
| 651 | pxo = pxo_buf; |
| 652 | |
| 653 | ret = (pxo > limits->pxo); |
| 654 | |
| 655 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_PXO) |
| 656 | pr_info("%s:pxo buf %d pxo %d limits pxo %d\n", |
| 657 | __func__, pxo_buf, pxo, limits->pxo); |
| 658 | } |
| 659 | return ret; |
| 660 | } |
| 661 | |
| 662 | static void msm_lpm_aggregate_pxo(struct msm_rpmrs_limits *limits) |
| 663 | { |
| 664 | struct msm_lpm_resource *rs = &msm_lpm_pxo; |
| 665 | |
| 666 | if (rs->valid) { |
| 667 | uint32_t pxo_buf = rs->rs_data.value; |
| 668 | if (limits->pxo > pxo_buf) |
| 669 | rs->sleep_value = limits->pxo; |
| 670 | else |
| 671 | rs->sleep_value = pxo_buf; |
| 672 | |
| 673 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_PXO) |
| 674 | pr_info("%s: pxo buf %d sleep value %d\n", |
| 675 | __func__, pxo_buf, rs->sleep_value); |
| 676 | } |
Priyanka Mathur | b44bf57 | 2012-11-07 12:07:45 -0800 | [diff] [blame] | 677 | trace_lpm_resources(rs->sleep_value, rs->name); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void msm_lpm_flush_pxo(int notify_rpm) |
| 681 | { |
| 682 | if (notify_rpm) { |
| 683 | struct msm_lpm_resource *rs = &msm_lpm_pxo; |
| 684 | msm_lpm_send_sleep_data(rs->rs_data.handle, |
| 685 | rs->rs_data.key, |
| 686 | (uint8_t *)&rs->sleep_value); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | static void msm_lpm_notify_pxo(struct msm_rpm_notifier_data |
| 691 | *rpm_notifier_cb) |
| 692 | { |
| 693 | struct msm_lpm_resource *rs = &msm_lpm_pxo; |
| 694 | msm_lpm_notify_common(rpm_notifier_cb, rs); |
| 695 | } |
| 696 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 697 | static int msm_lpm_init_value_pxo(struct device_node *node, |
| 698 | char *key, uint32_t *default_value) |
| 699 | { |
| 700 | return msm_lpm_get_xo_value(node, key, default_value); |
| 701 | } |
| 702 | |
Mahesh Sivasubramanian | 2efbc35 | 2012-07-18 14:15:44 -0600 | [diff] [blame] | 703 | static inline bool msm_lpm_use_mpm(struct msm_rpmrs_limits *limits) |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 704 | { |
Mahesh Sivasubramanian | 2efbc35 | 2012-07-18 14:15:44 -0600 | [diff] [blame] | 705 | return (limits->pxo == MSM_LPM_PXO_OFF); |
| 706 | } |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 707 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 708 | int msm_lpm_get_xo_value(struct device_node *node, |
| 709 | char *key, uint32_t *xo_val) |
| 710 | { |
| 711 | int i; |
| 712 | struct lpm_lookup_table pxo_mode_lookup[] = { |
| 713 | {MSM_LPM_PXO_OFF, "xo_off"}, |
| 714 | {MSM_LPM_PXO_ON, "xo_on"} |
| 715 | }; |
| 716 | const char *xo_str; |
| 717 | int ret; |
| 718 | |
| 719 | ret = of_property_read_string(node, key, &xo_str); |
| 720 | if (!ret) { |
| 721 | ret = -EINVAL; |
| 722 | for (i = 0; i < ARRAY_SIZE(pxo_mode_lookup); i++) { |
| 723 | if (!strncmp(xo_str, pxo_mode_lookup[i].mode_name, |
| 724 | MAX_STR_LEN)) { |
| 725 | *xo_val = pxo_mode_lookup[i].modes; |
| 726 | ret = 0; |
| 727 | break; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | return ret; |
| 732 | } |
| 733 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 734 | /* LPM levels interface */ |
| 735 | bool msm_lpm_level_beyond_limit(struct msm_rpmrs_limits *limits) |
| 736 | { |
| 737 | int i; |
| 738 | struct msm_lpm_resource *rs; |
| 739 | bool beyond_limit = false; |
| 740 | |
| 741 | for (i = 0; i < ARRAY_SIZE(msm_lpm_resources); i++) { |
| 742 | rs = msm_lpm_resources[i]; |
| 743 | if (rs->beyond_limits && rs->beyond_limits(limits)) { |
| 744 | beyond_limit = true; |
| 745 | if (msm_lpm_debug_mask & MSM_LPMRS_DEBUG_LVLS) |
| 746 | pr_info("%s: %s beyond limit", __func__, |
| 747 | rs->name); |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return beyond_limit; |
| 753 | } |
| 754 | |
Mahesh Sivasubramanian | 2efbc35 | 2012-07-18 14:15:44 -0600 | [diff] [blame] | 755 | int msm_lpmrs_enter_sleep(uint32_t sclk_count, struct msm_rpmrs_limits *limits, |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 756 | bool from_idle, bool notify_rpm) |
| 757 | { |
| 758 | int ret = 0; |
| 759 | int i; |
| 760 | struct msm_lpm_resource *rs = NULL; |
| 761 | |
| 762 | for (i = 0; i < ARRAY_SIZE(msm_lpm_resources); i++) { |
| 763 | rs = msm_lpm_resources[i]; |
| 764 | if (rs->aggregate) |
| 765 | rs->aggregate(limits); |
| 766 | } |
| 767 | |
| 768 | msm_lpm_get_rpm_notif = false; |
| 769 | for (i = 0; i < ARRAY_SIZE(msm_lpm_resources); i++) { |
| 770 | rs = msm_lpm_resources[i]; |
Girish Mahadevan | ce5a173 | 2012-10-10 18:53:47 -0600 | [diff] [blame] | 771 | if (rs->valid && rs->flush) |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 772 | rs->flush(notify_rpm); |
| 773 | } |
| 774 | msm_lpm_get_rpm_notif = true; |
| 775 | |
Priyanka Mathur | 86cfc76 | 2013-01-10 17:03:04 -0800 | [diff] [blame] | 776 | if (notify_rpm) |
| 777 | msm_mpm_enter_sleep(sclk_count, from_idle); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 778 | |
| 779 | return ret; |
| 780 | } |
| 781 | |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 782 | void msm_lpmrs_exit_sleep(struct msm_rpmrs_limits *limits, |
| 783 | bool from_idle, bool notify_rpm, bool collapsed) |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 784 | { |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 785 | if (msm_lpm_use_mpm(limits)) |
Mahesh Sivasubramanian | c7fe622 | 2012-11-21 16:31:21 -0700 | [diff] [blame] | 786 | msm_mpm_exit_sleep(from_idle); |
Girish Mahadevan | a9964a5 | 2012-06-29 10:14:09 -0600 | [diff] [blame] | 787 | |
Mahesh Sivasubramanian | e5d039a | 2012-11-30 14:22:00 -0700 | [diff] [blame] | 788 | if (msm_lpm_l2.valid) |
Girish Mahadevan | ee035b9 | 2013-04-11 10:49:50 -0600 | [diff] [blame] | 789 | msm_lpm_set_l2_mode(msm_lpm_l2.rs_data.default_value); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static int msm_lpm_cpu_callback(struct notifier_block *cpu_nb, |
| 793 | unsigned long action, void *hcpu) |
| 794 | { |
| 795 | struct msm_lpm_resource *rs = &msm_lpm_l2; |
| 796 | switch (action) { |
Mahesh Sivasubramanian | bfc7394 | 2012-10-17 18:04:33 -0600 | [diff] [blame] | 797 | case CPU_UP_PREPARE: |
| 798 | case CPU_UP_PREPARE_FROZEN: |
Mahesh Sivasubramanian | b76fb5e | 2012-11-05 14:40:09 -0700 | [diff] [blame] | 799 | rs->rs_data.value = rs->rs_data.default_value; |
Mahesh Sivasubramanian | bfc7394 | 2012-10-17 18:04:33 -0600 | [diff] [blame] | 800 | break; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 801 | case CPU_ONLINE_FROZEN: |
| 802 | case CPU_ONLINE: |
| 803 | if (num_online_cpus() > 1) |
Mahesh Sivasubramanian | b76fb5e | 2012-11-05 14:40:09 -0700 | [diff] [blame] | 804 | rs->rs_data.value = rs->rs_data.default_value; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 805 | break; |
| 806 | case CPU_DEAD_FROZEN: |
| 807 | case CPU_DEAD: |
| 808 | if (num_online_cpus() == 1) |
Mahesh Sivasubramanian | c373eb1 | 2012-08-22 11:28:57 -0600 | [diff] [blame] | 809 | rs->rs_data.value = MSM_LPM_L2_CACHE_HSFS_OPEN; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | return NOTIFY_OK; |
| 813 | } |
| 814 | |
| 815 | /* RPM CTL */ |
| 816 | static int __devinit msm_lpm_init_rpm_ctl(void) |
| 817 | { |
| 818 | struct msm_lpm_resource *rs = &msm_lpm_rpm_ctl; |
| 819 | |
| 820 | rs->rs_data.handle = msm_rpm_create_request( |
| 821 | MSM_RPM_CTX_ACTIVE_SET, |
| 822 | rs->rs_data.type, |
| 823 | rs->rs_data.id, 1); |
| 824 | if (!rs->rs_data.handle) |
| 825 | return -EIO; |
| 826 | |
| 827 | rs->valid = true; |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int __devinit msm_lpm_resource_sysfs_add(void) |
| 832 | { |
| 833 | struct kobject *module_kobj = NULL; |
| 834 | struct kobject *low_power_kobj = NULL; |
| 835 | struct kobject *mode_kobj = NULL; |
| 836 | int rc = 0; |
| 837 | |
| 838 | module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 839 | if (!module_kobj) { |
| 840 | pr_err("%s: cannot find kobject for module %s\n", |
| 841 | __func__, KBUILD_MODNAME); |
| 842 | rc = -ENOENT; |
| 843 | goto resource_sysfs_add_exit; |
| 844 | } |
| 845 | |
| 846 | low_power_kobj = kobject_create_and_add( |
| 847 | "enable_low_power", module_kobj); |
| 848 | if (!low_power_kobj) { |
| 849 | pr_err("%s: cannot create kobject\n", __func__); |
| 850 | rc = -ENOMEM; |
| 851 | goto resource_sysfs_add_exit; |
| 852 | } |
| 853 | |
| 854 | mode_kobj = kobject_create_and_add( |
| 855 | "mode", module_kobj); |
| 856 | if (!mode_kobj) { |
| 857 | pr_err("%s: cannot create kobject\n", __func__); |
| 858 | rc = -ENOMEM; |
| 859 | goto resource_sysfs_add_exit; |
| 860 | } |
| 861 | |
| 862 | rc = sysfs_create_group(low_power_kobj, &msm_lpm_attribute_group); |
| 863 | if (rc) { |
| 864 | pr_err("%s: cannot create kobject attribute group\n", __func__); |
| 865 | goto resource_sysfs_add_exit; |
| 866 | } |
| 867 | |
| 868 | rc = sysfs_create_group(mode_kobj, &msm_lpm_rpm_ctl_attr_group); |
| 869 | if (rc) { |
| 870 | pr_err("%s: cannot create kobject attribute group\n", __func__); |
| 871 | goto resource_sysfs_add_exit; |
| 872 | } |
| 873 | |
| 874 | resource_sysfs_add_exit: |
| 875 | if (rc) { |
| 876 | if (low_power_kobj) |
| 877 | sysfs_remove_group(low_power_kobj, |
| 878 | &msm_lpm_attribute_group); |
| 879 | kobject_del(low_power_kobj); |
| 880 | kobject_del(mode_kobj); |
| 881 | } |
| 882 | |
| 883 | return rc; |
| 884 | } |
| 885 | |
| 886 | late_initcall(msm_lpm_resource_sysfs_add); |
| 887 | |
| 888 | static int __devinit msm_lpmrs_probe(struct platform_device *pdev) |
| 889 | { |
| 890 | struct device_node *node = NULL; |
| 891 | char *key = NULL; |
| 892 | int ret = 0; |
| 893 | |
| 894 | for_each_child_of_node(pdev->dev.of_node, node) { |
| 895 | struct msm_lpm_resource *rs = NULL; |
| 896 | const char *val; |
| 897 | int i; |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 898 | bool local_resource; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 899 | |
| 900 | key = "qcom,name"; |
| 901 | ret = of_property_read_string(node, key, &val); |
| 902 | if (ret) { |
| 903 | pr_err("Cannot read string\n"); |
| 904 | goto fail; |
| 905 | } |
| 906 | |
| 907 | for (i = 0; i < ARRAY_SIZE(msm_lpm_resources); i++) { |
| 908 | char *lpmrs_name = msm_lpm_resources[i]->name; |
| 909 | if (!msm_lpm_resources[i]->valid && |
| 910 | !strncmp(val, lpmrs_name, strnlen(lpmrs_name, |
| 911 | MAX_RS_NAME))) { |
| 912 | rs = msm_lpm_resources[i]; |
| 913 | break; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | if (!rs) { |
| 918 | pr_err("LPM resource not found\n"); |
| 919 | continue; |
| 920 | } |
| 921 | |
Mahesh Sivasubramanian | b76fb5e | 2012-11-05 14:40:09 -0700 | [diff] [blame] | 922 | key = "qcom,init-value"; |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 923 | ret = rs->init_value(node, key, &rs->rs_data.default_value); |
Mahesh Sivasubramanian | b76fb5e | 2012-11-05 14:40:09 -0700 | [diff] [blame] | 924 | if (ret) { |
| 925 | pr_err("%s():Failed to read %s\n", __func__, key); |
| 926 | goto fail; |
| 927 | } |
| 928 | |
| 929 | rs->rs_data.value = rs->rs_data.default_value; |
| 930 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 931 | key = "qcom,local-resource-type"; |
| 932 | local_resource = of_property_read_bool(node, key); |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 933 | |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 934 | if (!local_resource) { |
Girish Mahadevan | 909dbce | 2012-09-25 09:38:03 -0600 | [diff] [blame] | 935 | key = "qcom,type"; |
| 936 | ret = of_property_read_u32(node, key, |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 937 | &rs->rs_data.type); |
Girish Mahadevan | 909dbce | 2012-09-25 09:38:03 -0600 | [diff] [blame] | 938 | if (ret) { |
| 939 | pr_err("Failed to read type\n"); |
| 940 | goto fail; |
| 941 | } |
| 942 | |
| 943 | key = "qcom,id"; |
| 944 | ret = of_property_read_u32(node, key, &rs->rs_data.id); |
| 945 | if (ret) { |
| 946 | pr_err("Failed to read id\n"); |
| 947 | goto fail; |
| 948 | } |
| 949 | |
| 950 | key = "qcom,key"; |
| 951 | ret = of_property_read_u32(node, key, &rs->rs_data.key); |
| 952 | if (ret) { |
| 953 | pr_err("Failed to read key\n"); |
| 954 | goto fail; |
| 955 | } |
| 956 | |
| 957 | rs->rs_data.handle = msm_lpm_create_rpm_request( |
| 958 | rs->rs_data.type, |
| 959 | rs->rs_data.id); |
| 960 | |
| 961 | if (!rs->rs_data.handle) { |
| 962 | pr_err("%s: Failed to allocate handle for %s\n", |
| 963 | __func__, rs->name); |
| 964 | ret = -1; |
| 965 | goto fail; |
| 966 | } |
| 967 | /* fall through */ |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 968 | } |
Archana Sathyakumar | e6a3510 | 2013-01-31 16:18:49 -0700 | [diff] [blame] | 969 | |
| 970 | rs->valid = true; |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 971 | } |
| 972 | msm_rpm_register_notifier(&msm_lpm_rpm_nblk); |
| 973 | msm_lpm_init_rpm_ctl(); |
Girish Mahadevan | 909dbce | 2012-09-25 09:38:03 -0600 | [diff] [blame] | 974 | |
| 975 | if (msm_lpm_l2.valid) { |
| 976 | register_hotcpu_notifier(&msm_lpm_cpu_nblk); |
| 977 | /* For UP mode, set the default to HSFS OPEN*/ |
| 978 | if (num_possible_cpus() == 1) { |
| 979 | msm_lpm_l2.rs_data.default_value = |
| 980 | MSM_LPM_L2_CACHE_HSFS_OPEN; |
| 981 | msm_lpm_l2.rs_data.value = MSM_LPM_L2_CACHE_HSFS_OPEN; |
| 982 | } |
| 983 | msm_pm_set_l2_flush_flag(0); |
| 984 | } else |
| 985 | msm_pm_set_l2_flush_flag(1); |
| 986 | |
Girish Mahadevan | 40abbe1 | 2012-04-25 14:58:13 -0600 | [diff] [blame] | 987 | fail: |
| 988 | return ret; |
| 989 | } |
| 990 | |
| 991 | static struct of_device_id msm_lpmrs_match_table[] = { |
| 992 | {.compatible = "qcom,lpm-resources"}, |
| 993 | {}, |
| 994 | }; |
| 995 | |
| 996 | static struct platform_driver msm_lpmrs_driver = { |
| 997 | .probe = msm_lpmrs_probe, |
| 998 | .driver = { |
| 999 | .name = "lpm-resources", |
| 1000 | .owner = THIS_MODULE, |
| 1001 | .of_match_table = msm_lpmrs_match_table, |
| 1002 | }, |
| 1003 | }; |
| 1004 | |
| 1005 | int __init msm_lpmrs_module_init(void) |
| 1006 | { |
| 1007 | return platform_driver_register(&msm_lpmrs_driver); |
| 1008 | } |