Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [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/delay.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/slab.h> |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_address.h> |
| 22 | #include <linux/platform_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <mach/msm_iomap.h> |
Praveen Chidambaram | 76679d4 | 2011-12-16 14:19:02 -0700 | [diff] [blame] | 24 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | #include "spm.h" |
| 26 | #include "spm_driver.h" |
| 27 | |
| 28 | struct msm_spm_power_modes { |
| 29 | uint32_t mode; |
| 30 | bool notify_rpm; |
| 31 | uint32_t start_addr; |
| 32 | |
| 33 | }; |
| 34 | |
| 35 | struct msm_spm_device { |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 36 | bool initialized; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | struct msm_spm_driver_data reg_data; |
| 38 | struct msm_spm_power_modes *modes; |
| 39 | uint32_t num_modes; |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 40 | uint32_t cpu_vdd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 43 | struct msm_spm_vdd_info { |
| 44 | uint32_t cpu; |
| 45 | uint32_t vlevel; |
| 46 | int err; |
| 47 | }; |
| 48 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 49 | static struct msm_spm_device msm_spm_l2_device; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct msm_spm_device, msm_cpu_spm_device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 52 | |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 53 | static void msm_spm_smp_set_vdd(void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 54 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | struct msm_spm_device *dev; |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 56 | struct msm_spm_vdd_info *info = (struct msm_spm_vdd_info *)data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 57 | |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 58 | dev = &per_cpu(msm_cpu_spm_device, info->cpu); |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 59 | if (!dev->initialized) |
| 60 | return; |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 61 | dev->cpu_vdd = info->vlevel; |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 62 | info->err = msm_spm_drv_set_vdd(&dev->reg_data, info->vlevel); |
| 63 | } |
| 64 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 65 | /** |
| 66 | * msm_spm_set_vdd(): Set core voltage |
| 67 | * @cpu: core id |
| 68 | * @vlevel: Encoded PMIC data. |
| 69 | */ |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 70 | int msm_spm_set_vdd(unsigned int cpu, unsigned int vlevel) |
| 71 | { |
| 72 | struct msm_spm_vdd_info info; |
| 73 | int ret; |
| 74 | |
| 75 | info.cpu = cpu; |
| 76 | info.vlevel = vlevel; |
| 77 | |
Praveen Chidambaram | 8624ce7 | 2012-10-05 17:11:33 -0600 | [diff] [blame] | 78 | if (cpu_online(cpu)) { |
| 79 | /** |
| 80 | * We do not want to set the voltage of another core from |
| 81 | * this core, as its possible that we may race the vdd change |
| 82 | * with the SPM state machine of that core, which could also |
| 83 | * be changing the voltage of that core during power collapse. |
| 84 | * Hence, set the function to be executed on that core and block |
| 85 | * until the vdd change is complete. |
| 86 | */ |
| 87 | ret = smp_call_function_single(cpu, msm_spm_smp_set_vdd, |
| 88 | &info, true); |
| 89 | if (!ret) |
| 90 | ret = info.err; |
| 91 | } else { |
| 92 | /** |
| 93 | * Since the core is not online, it is safe to set the vdd |
| 94 | * directly. |
| 95 | */ |
| 96 | msm_spm_smp_set_vdd(&info); |
Praveen Chidambaram | bcd483b | 2012-09-16 14:54:35 -0600 | [diff] [blame] | 97 | ret = info.err; |
Praveen Chidambaram | 8624ce7 | 2012-10-05 17:11:33 -0600 | [diff] [blame] | 98 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 99 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | return ret; |
| 101 | } |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 102 | EXPORT_SYMBOL(msm_spm_set_vdd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 104 | /** |
| 105 | * msm_spm_get_vdd(): Get core voltage |
| 106 | * @cpu: core id |
| 107 | * @return: Returns encoded PMIC data. |
| 108 | */ |
Praveen Chidambaram | 4133ba1 | 2012-09-29 22:27:03 -0600 | [diff] [blame] | 109 | unsigned int msm_spm_get_vdd(unsigned int cpu) |
| 110 | { |
| 111 | struct msm_spm_device *dev; |
| 112 | |
| 113 | dev = &per_cpu(msm_cpu_spm_device, cpu); |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 114 | return dev->cpu_vdd; |
Praveen Chidambaram | 4133ba1 | 2012-09-29 22:27:03 -0600 | [diff] [blame] | 115 | } |
| 116 | EXPORT_SYMBOL(msm_spm_get_vdd); |
| 117 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 118 | static int msm_spm_dev_set_low_power_mode(struct msm_spm_device *dev, |
| 119 | unsigned int mode, bool notify_rpm) |
| 120 | { |
| 121 | uint32_t i; |
| 122 | uint32_t start_addr = 0; |
| 123 | int ret = -EINVAL; |
| 124 | |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 125 | if (!dev->initialized) |
| 126 | return -ENXIO; |
| 127 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 128 | if (mode == MSM_SPM_MODE_DISABLED) { |
| 129 | ret = msm_spm_drv_set_spm_enable(&dev->reg_data, false); |
| 130 | } else if (!msm_spm_drv_set_spm_enable(&dev->reg_data, true)) { |
| 131 | for (i = 0; i < dev->num_modes; i++) { |
| 132 | if ((dev->modes[i].mode == mode) && |
| 133 | (dev->modes[i].notify_rpm == notify_rpm)) { |
| 134 | start_addr = dev->modes[i].start_addr; |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | ret = msm_spm_drv_set_low_power_mode(&dev->reg_data, |
| 139 | start_addr); |
| 140 | } |
| 141 | return ret; |
| 142 | } |
| 143 | |
Stephen Boyd | db35411 | 2012-05-09 14:24:58 -0700 | [diff] [blame] | 144 | static int __devinit msm_spm_dev_init(struct msm_spm_device *dev, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 145 | struct msm_spm_platform_data *data) |
| 146 | { |
| 147 | int i, ret = -ENOMEM; |
| 148 | uint32_t offset = 0; |
| 149 | |
| 150 | dev->num_modes = data->num_modes; |
| 151 | dev->modes = kmalloc( |
| 152 | sizeof(struct msm_spm_power_modes) * dev->num_modes, |
| 153 | GFP_KERNEL); |
| 154 | |
| 155 | if (!dev->modes) |
| 156 | goto spm_failed_malloc; |
| 157 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 158 | dev->reg_data.ver_reg = data->ver_reg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 159 | ret = msm_spm_drv_init(&dev->reg_data, data); |
| 160 | |
| 161 | if (ret) |
| 162 | goto spm_failed_init; |
| 163 | |
| 164 | for (i = 0; i < dev->num_modes; i++) { |
| 165 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 166 | /* Default offset is 0 and gets updated as we write more |
| 167 | * sequences into SPM |
| 168 | */ |
| 169 | dev->modes[i].start_addr = offset; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 170 | ret = msm_spm_drv_write_seq_data(&dev->reg_data, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 171 | data->modes[i].cmd, &offset); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | if (ret < 0) |
| 173 | goto spm_failed_init; |
| 174 | |
| 175 | dev->modes[i].mode = data->modes[i].mode; |
| 176 | dev->modes[i].notify_rpm = data->modes[i].notify_rpm; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 177 | } |
| 178 | msm_spm_drv_flush_seq_entry(&dev->reg_data); |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 179 | dev->initialized = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 180 | return 0; |
| 181 | |
| 182 | spm_failed_init: |
| 183 | kfree(dev->modes); |
| 184 | spm_failed_malloc: |
| 185 | return ret; |
| 186 | } |
| 187 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 188 | /** |
| 189 | * msm_spm_turn_on_cpu_rail(): Power on cpu rail before turning on core |
| 190 | * @cpu: core id |
| 191 | */ |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 192 | int msm_spm_turn_on_cpu_rail(unsigned int cpu) |
| 193 | { |
| 194 | uint32_t val = 0; |
| 195 | uint32_t timeout = 0; |
| 196 | void *reg = NULL; |
Stepan Moskovchenko | 2b0b06e | 2012-02-03 15:03:52 -0800 | [diff] [blame] | 197 | void *saw_bases[] = { |
| 198 | 0, |
| 199 | MSM_SAW1_BASE, |
| 200 | MSM_SAW2_BASE, |
| 201 | MSM_SAW3_BASE |
| 202 | }; |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 203 | |
Stepan Moskovchenko | 2b0b06e | 2012-02-03 15:03:52 -0800 | [diff] [blame] | 204 | if (cpu == 0 || cpu >= num_possible_cpus()) |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 205 | return -EINVAL; |
| 206 | |
Stepan Moskovchenko | 2b0b06e | 2012-02-03 15:03:52 -0800 | [diff] [blame] | 207 | reg = saw_bases[cpu]; |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 208 | |
Stepan Moskovchenko | 5b9e776 | 2012-09-21 20:32:17 -0700 | [diff] [blame] | 209 | if (soc_class_is_msm8960() || soc_class_is_msm8930() || |
| 210 | soc_class_is_apq8064()) { |
Stepan Moskovchenko | 2b0b06e | 2012-02-03 15:03:52 -0800 | [diff] [blame] | 211 | val = 0xA4; |
| 212 | reg += 0x14; |
| 213 | timeout = 512; |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 214 | } else { |
| 215 | return -ENOSYS; |
| 216 | } |
| 217 | |
| 218 | writel_relaxed(val, reg); |
| 219 | mb(); |
| 220 | udelay(timeout); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | EXPORT_SYMBOL(msm_spm_turn_on_cpu_rail); |
| 225 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 226 | void msm_spm_reinit(void) |
| 227 | { |
| 228 | unsigned int cpu; |
| 229 | for_each_possible_cpu(cpu) |
| 230 | msm_spm_drv_reinit(&per_cpu(msm_cpu_spm_device.reg_data, cpu)); |
| 231 | } |
| 232 | EXPORT_SYMBOL(msm_spm_reinit); |
| 233 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 234 | /** |
| 235 | * msm_spm_set_low_power_mode() - Configure SPM start address for low power mode |
| 236 | * @mode: SPM LPM mode to enter |
| 237 | * @notify_rpm: Notify RPM in this mode |
| 238 | */ |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 239 | int msm_spm_set_low_power_mode(unsigned int mode, bool notify_rpm) |
| 240 | { |
| 241 | struct msm_spm_device *dev = &__get_cpu_var(msm_cpu_spm_device); |
| 242 | return msm_spm_dev_set_low_power_mode(dev, mode, notify_rpm); |
| 243 | } |
| 244 | EXPORT_SYMBOL(msm_spm_set_low_power_mode); |
| 245 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 246 | /** |
| 247 | * msm_spm_init(): Board initalization function |
| 248 | * @data: platform specific SPM register configuration data |
| 249 | * @nr_devs: Number of SPM devices being initialized |
| 250 | */ |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 251 | int __init msm_spm_init(struct msm_spm_platform_data *data, int nr_devs) |
| 252 | { |
| 253 | unsigned int cpu; |
| 254 | int ret = 0; |
| 255 | |
| 256 | BUG_ON((nr_devs < num_possible_cpus()) || !data); |
| 257 | |
| 258 | for_each_possible_cpu(cpu) { |
| 259 | struct msm_spm_device *dev = &per_cpu(msm_cpu_spm_device, cpu); |
| 260 | ret = msm_spm_dev_init(dev, &data[cpu]); |
| 261 | if (ret < 0) { |
| 262 | pr_warn("%s():failed CPU:%u ret:%d\n", __func__, |
| 263 | cpu, ret); |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | #ifdef CONFIG_MSM_L2_SPM |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 272 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 273 | /** |
| 274 | * msm_spm_l2_set_low_power_mode(): Configure L2 SPM start address |
| 275 | * for low power mode |
| 276 | * @mode: SPM LPM mode to enter |
| 277 | * @notify_rpm: Notify RPM in this mode |
| 278 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 279 | int msm_spm_l2_set_low_power_mode(unsigned int mode, bool notify_rpm) |
| 280 | { |
| 281 | return msm_spm_dev_set_low_power_mode( |
| 282 | &msm_spm_l2_device, mode, notify_rpm); |
| 283 | } |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 284 | EXPORT_SYMBOL(msm_spm_l2_set_low_power_mode); |
Maheshkumar Sivasubramanian | 4ac2376 | 2011-11-02 10:03:06 -0600 | [diff] [blame] | 285 | |
| 286 | void msm_spm_l2_reinit(void) |
| 287 | { |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 288 | if (!msm_spm_l2_device.initialized) |
| 289 | return; |
Maheshkumar Sivasubramanian | 4ac2376 | 2011-11-02 10:03:06 -0600 | [diff] [blame] | 290 | msm_spm_drv_reinit(&msm_spm_l2_device.reg_data); |
| 291 | } |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 292 | EXPORT_SYMBOL(msm_spm_l2_reinit); |
| 293 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 294 | /** |
| 295 | * msm_spm_apcs_set_vdd(): Set Apps processor core sub-system voltage |
| 296 | * @vlevel: Encoded PMIC data. |
| 297 | */ |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 298 | int msm_spm_apcs_set_vdd(unsigned int vlevel) |
| 299 | { |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 300 | if (!msm_spm_l2_device.initialized) |
| 301 | return -ENXIO; |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 302 | return msm_spm_drv_set_vdd(&msm_spm_l2_device.reg_data, vlevel); |
| 303 | } |
| 304 | EXPORT_SYMBOL(msm_spm_apcs_set_vdd); |
| 305 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 306 | /** |
| 307 | * msm_spm_apcs_set_phase(): Set number of SMPS phases. |
| 308 | * phase_cnt: Number of phases to be set active |
| 309 | */ |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 310 | int msm_spm_apcs_set_phase(unsigned int phase_cnt) |
| 311 | { |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 312 | if (!msm_spm_l2_device.initialized) |
| 313 | return -ENXIO; |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 314 | return msm_spm_drv_set_pmic_data(&msm_spm_l2_device.reg_data, |
| 315 | MSM_SPM_PMIC_PHASE_PORT, phase_cnt); |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 316 | } |
| 317 | EXPORT_SYMBOL(msm_spm_apcs_set_phase); |
| 318 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 319 | /** msm_spm_enable_fts_lpm() : Enable FTS to switch to low power |
| 320 | * when the cores are in low power modes |
| 321 | * @mode: The mode configuration for FTS |
| 322 | */ |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 323 | int msm_spm_enable_fts_lpm(uint32_t mode) |
| 324 | { |
Mahesh Sivasubramanian | bc42024 | 2013-03-26 17:18:04 -0600 | [diff] [blame] | 325 | if (!msm_spm_l2_device.initialized) |
| 326 | return -ENXIO; |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 327 | return msm_spm_drv_set_pmic_data(&msm_spm_l2_device.reg_data, |
| 328 | MSM_SPM_PMIC_PFM_PORT, mode); |
| 329 | } |
| 330 | EXPORT_SYMBOL(msm_spm_enable_fts_lpm); |
| 331 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 332 | /** |
| 333 | * msm_spm_l2_init(): Board initialization function |
| 334 | * @data: SPM target specific register configuration |
| 335 | */ |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 336 | int __init msm_spm_l2_init(struct msm_spm_platform_data *data) |
| 337 | { |
| 338 | return msm_spm_dev_init(&msm_spm_l2_device, data); |
| 339 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 340 | #endif |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 341 | |
Sathish Ambley | 86487e5 | 2012-06-11 13:46:11 -0700 | [diff] [blame] | 342 | static int __devinit msm_spm_dev_probe(struct platform_device *pdev) |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 343 | { |
| 344 | int ret = 0; |
| 345 | int cpu = 0; |
| 346 | int i = 0; |
| 347 | struct device_node *node = pdev->dev.of_node; |
| 348 | struct msm_spm_platform_data spm_data; |
| 349 | char *key = NULL; |
| 350 | uint32_t val = 0; |
| 351 | struct msm_spm_seq_entry modes[MSM_SPM_MODE_NR]; |
| 352 | size_t len = 0; |
| 353 | struct msm_spm_device *dev = NULL; |
| 354 | struct resource *res = NULL; |
| 355 | uint32_t mode_count = 0; |
| 356 | |
| 357 | struct spm_of { |
| 358 | char *key; |
| 359 | uint32_t id; |
| 360 | }; |
| 361 | |
| 362 | struct spm_of spm_of_data[] = { |
| 363 | {"qcom,saw2-cfg", MSM_SPM_REG_SAW2_CFG}, |
| 364 | {"qcom,saw2-avs-ctl", MSM_SPM_REG_SAW2_AVS_CTL}, |
| 365 | {"qcom,saw2-avs-hysteresis", MSM_SPM_REG_SAW2_AVS_HYSTERESIS}, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 366 | {"qcom,saw2-avs-limit", MSM_SPM_REG_SAW2_AVS_LIMIT}, |
Praveen Chidambaram | 2772d83 | 2012-08-22 11:50:34 -0600 | [diff] [blame] | 367 | {"qcom,saw2-avs-dly", MSM_SPM_REG_SAW2_AVS_DLY}, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 368 | {"qcom,saw2-spm-dly", MSM_SPM_REG_SAW2_SPM_DLY}, |
Praveen Chidambaram | 2772d83 | 2012-08-22 11:50:34 -0600 | [diff] [blame] | 369 | {"qcom,saw2-spm-ctl", MSM_SPM_REG_SAW2_SPM_CTL}, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 370 | {"qcom,saw2-pmic-data0", MSM_SPM_REG_SAW2_PMIC_DATA_0}, |
| 371 | {"qcom,saw2-pmic-data1", MSM_SPM_REG_SAW2_PMIC_DATA_1}, |
| 372 | {"qcom,saw2-pmic-data2", MSM_SPM_REG_SAW2_PMIC_DATA_2}, |
| 373 | {"qcom,saw2-pmic-data3", MSM_SPM_REG_SAW2_PMIC_DATA_3}, |
| 374 | {"qcom,saw2-pmic-data4", MSM_SPM_REG_SAW2_PMIC_DATA_4}, |
| 375 | {"qcom,saw2-pmic-data5", MSM_SPM_REG_SAW2_PMIC_DATA_5}, |
| 376 | {"qcom,saw2-pmic-data6", MSM_SPM_REG_SAW2_PMIC_DATA_6}, |
| 377 | {"qcom,saw2-pmic-data7", MSM_SPM_REG_SAW2_PMIC_DATA_7}, |
| 378 | }; |
| 379 | |
| 380 | struct mode_of { |
| 381 | char *key; |
| 382 | uint32_t id; |
| 383 | uint32_t notify_rpm; |
| 384 | }; |
| 385 | |
Mahesh Sivasubramanian | 1137332 | 2012-06-14 11:17:20 -0600 | [diff] [blame] | 386 | struct mode_of of_cpu_modes[] = { |
| 387 | {"qcom,saw2-spm-cmd-wfi", MSM_SPM_MODE_CLOCK_GATING, 0}, |
| 388 | {"qcom,saw2-spm-cmd-ret", MSM_SPM_MODE_POWER_RETENTION, 0}, |
| 389 | {"qcom,saw2-spm-cmd-spc", MSM_SPM_MODE_POWER_COLLAPSE, 0}, |
| 390 | {"qcom,saw2-spm-cmd-pc", MSM_SPM_MODE_POWER_COLLAPSE, 1}, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 391 | }; |
| 392 | |
Mahesh Sivasubramanian | 1137332 | 2012-06-14 11:17:20 -0600 | [diff] [blame] | 393 | struct mode_of of_l2_modes[] = { |
Mahesh Sivasubramanian | 1826ae4 | 2012-11-07 14:37:13 -0700 | [diff] [blame] | 394 | {"qcom,saw2-spm-cmd-ret", MSM_SPM_L2_MODE_RETENTION, 0}, |
Mahesh Sivasubramanian | 1137332 | 2012-06-14 11:17:20 -0600 | [diff] [blame] | 395 | {"qcom,saw2-spm-cmd-gdhs", MSM_SPM_L2_MODE_GDHS, 1}, |
| 396 | {"qcom,saw2-spm-cmd-pc", MSM_SPM_L2_MODE_POWER_COLLAPSE, 1}, |
| 397 | }; |
| 398 | |
| 399 | struct mode_of *mode_of_data; |
| 400 | int num_modes; |
| 401 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 402 | memset(&spm_data, 0, sizeof(struct msm_spm_platform_data)); |
| 403 | memset(&modes, 0, |
| 404 | (MSM_SPM_MODE_NR - 2) * sizeof(struct msm_spm_seq_entry)); |
| 405 | |
| 406 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 407 | if (!res) |
| 408 | goto fail; |
| 409 | |
| 410 | spm_data.reg_base_addr = devm_ioremap(&pdev->dev, res->start, |
| 411 | resource_size(res)); |
| 412 | if (!spm_data.reg_base_addr) |
| 413 | return -ENOMEM; |
| 414 | |
| 415 | key = "qcom,core-id"; |
| 416 | ret = of_property_read_u32(node, key, &val); |
| 417 | if (ret) |
| 418 | goto fail; |
| 419 | cpu = val; |
| 420 | |
| 421 | key = "qcom,saw2-ver-reg"; |
| 422 | ret = of_property_read_u32(node, key, &val); |
| 423 | if (ret) |
| 424 | goto fail; |
| 425 | spm_data.ver_reg = val; |
| 426 | |
| 427 | key = "qcom,vctl-timeout-us"; |
| 428 | ret = of_property_read_u32(node, key, &val); |
| 429 | if (!ret) |
| 430 | spm_data.vctl_timeout_us = val; |
| 431 | |
Mahesh Sivasubramanian | 1137332 | 2012-06-14 11:17:20 -0600 | [diff] [blame] | 432 | /* |
| 433 | * Device with id 0..NR_CPUS are SPM for apps cores |
| 434 | * Device with id 0xFFFF is for L2 SPM. |
| 435 | */ |
| 436 | if (cpu >= 0 && cpu < num_possible_cpus()) { |
| 437 | mode_of_data = of_cpu_modes; |
| 438 | num_modes = ARRAY_SIZE(of_cpu_modes); |
| 439 | dev = &per_cpu(msm_cpu_spm_device, cpu); |
| 440 | |
| 441 | } else { |
| 442 | mode_of_data = of_l2_modes; |
| 443 | num_modes = ARRAY_SIZE(of_l2_modes); |
| 444 | dev = &msm_spm_l2_device; |
| 445 | } |
| 446 | |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 447 | spm_data.vctl_port = -1; |
| 448 | spm_data.phase_port = -1; |
| 449 | spm_data.pfm_port = -1; |
| 450 | |
| 451 | /* optional */ |
| 452 | if (dev == &msm_spm_l2_device) { |
| 453 | key = "qcom,vctl-port"; |
| 454 | ret = of_property_read_u32(node, key, &val); |
| 455 | if (!ret) |
| 456 | spm_data.vctl_port = val; |
| 457 | |
| 458 | key = "qcom,phase-port"; |
| 459 | ret = of_property_read_u32(node, key, &val); |
| 460 | if (!ret) |
| 461 | spm_data.phase_port = val; |
| 462 | |
| 463 | key = "qcom,pfm-port"; |
| 464 | ret = of_property_read_u32(node, key, &val); |
| 465 | if (!ret) |
| 466 | spm_data.pfm_port = val; |
| 467 | } |
| 468 | |
| 469 | for (i = 0; i < ARRAY_SIZE(spm_of_data); i++) { |
| 470 | ret = of_property_read_u32(node, spm_of_data[i].key, &val); |
| 471 | if (ret) |
| 472 | continue; |
| 473 | spm_data.reg_init_values[spm_of_data[i].id] = val; |
| 474 | } |
| 475 | |
Mahesh Sivasubramanian | 1137332 | 2012-06-14 11:17:20 -0600 | [diff] [blame] | 476 | for (i = 0; i < num_modes; i++) { |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 477 | key = mode_of_data[i].key; |
| 478 | modes[mode_count].cmd = |
| 479 | (uint8_t *)of_get_property(node, key, &len); |
| 480 | if (!modes[mode_count].cmd) |
| 481 | continue; |
| 482 | modes[mode_count].mode = mode_of_data[i].id; |
| 483 | modes[mode_count].notify_rpm = mode_of_data[i].notify_rpm; |
| 484 | mode_count++; |
| 485 | } |
| 486 | |
| 487 | spm_data.modes = modes; |
| 488 | spm_data.num_modes = mode_count; |
| 489 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 490 | ret = msm_spm_dev_init(dev, &spm_data); |
Mahesh Sivasubramanian | 1137332 | 2012-06-14 11:17:20 -0600 | [diff] [blame] | 491 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 492 | if (ret < 0) |
| 493 | pr_warn("%s():failed core-id:%u ret:%d\n", __func__, cpu, ret); |
| 494 | |
| 495 | return ret; |
| 496 | |
| 497 | fail: |
| 498 | pr_err("%s: Failed reading node=%s, key=%s\n", |
| 499 | __func__, node->full_name, key); |
| 500 | return -EFAULT; |
| 501 | } |
| 502 | |
Sathish Ambley | 86487e5 | 2012-06-11 13:46:11 -0700 | [diff] [blame] | 503 | static struct of_device_id msm_spm_match_table[] = { |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 504 | {.compatible = "qcom,spm-v2"}, |
| 505 | {}, |
| 506 | }; |
| 507 | |
Sathish Ambley | 86487e5 | 2012-06-11 13:46:11 -0700 | [diff] [blame] | 508 | static struct platform_driver msm_spm_device_driver = { |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 509 | .probe = msm_spm_dev_probe, |
| 510 | .driver = { |
| 511 | .name = "spm-v2", |
| 512 | .owner = THIS_MODULE, |
| 513 | .of_match_table = msm_spm_match_table, |
| 514 | }, |
| 515 | }; |
| 516 | |
Praveen Chidambaram | 7347bfe | 2012-11-01 15:21:10 -0600 | [diff] [blame] | 517 | /** |
| 518 | * msm_spm_device_init(): Device tree initialization function |
| 519 | */ |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 520 | int __init msm_spm_device_init(void) |
| 521 | { |
| 522 | return platform_driver_register(&msm_spm_device_driver); |
| 523 | } |