Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef __ARCH_ARM_MACH_MSM_CPR_H |
| 16 | #define __ARCH_ARM_MACH_MSM_CPR_H |
| 17 | |
| 18 | /* Register Offsets for RBCPR */ |
| 19 | |
| 20 | /* RBCPR Gate Count and Target Registers */ |
| 21 | #define RBCPR_GCNT_TARGET(n) (0x60 + 4 * n) |
| 22 | |
| 23 | /* RBCPR Timer Control */ |
| 24 | #define RBCPR_TIMER_INTERVAL 0x44 |
| 25 | #define RBIF_TIMER_ADJUST 0x4C |
| 26 | |
| 27 | /* RBCPR Config Register */ |
| 28 | #define RBIF_LIMIT 0x48 |
| 29 | #define RBCPR_STEP_QUOT 0X80 |
| 30 | #define RBCPR_CTL 0x90 |
| 31 | #define RBIF_SW_VLEVEL 0x94 |
| 32 | #define RBIF_CONT_ACK_CMD 0x98 |
| 33 | #define RBIF_CONT_NACK_CMD 0x9C |
| 34 | |
| 35 | /* RBCPR Result status Register */ |
| 36 | #define RBCPR_RESULT_0 0xA0 |
| 37 | #define RBCPR_RESULT_1 0xA4 |
| 38 | #define RBCPR_QUOT_AVG 0x118 |
| 39 | |
| 40 | /* RBCPR DEBUG Register */ |
| 41 | #define RBCPR_DEBUG1 0x120 |
| 42 | |
| 43 | /* RBCPR Interrupt Control Register */ |
| 44 | #define RBIF_IRQ_EN(n) (0x100 + 4 * n) |
| 45 | #define RBIF_IRQ_CLEAR 0x110 |
| 46 | #define RBIF_IRQ_STATUS 0x114 |
| 47 | |
| 48 | /* Bit Mask Values */ |
| 49 | #define GCNT_M 0x003FF000 |
| 50 | #define TARGET_M 0x00000FFF |
| 51 | #define SW_VLEVEL_M 0x0000003F |
| 52 | #define UP_FLAG_M 0x00000010 |
| 53 | #define DOWN_FLAG_M 0x00000004 |
| 54 | #define CEILING_M 0x00000FC0 |
| 55 | #define FLOOR_M 0x0000003F |
| 56 | #define LOOP_EN_M 0x00000001 |
| 57 | #define TIMER_M 0x00000008 |
| 58 | #define SW_AUTO_CONT_ACK_EN_M 0x00000020 |
| 59 | #define SW_AUTO_CONT_NACK_DN_EN_M 0x00000040 |
| 60 | #define HW_TO_PMIC_EN_M BIT(4) |
| 61 | #define BUSY_M BIT(19) |
| 62 | #define QUOT_SLOW_M 0x00FFF000 |
| 63 | #define UP_THRESHOLD_M 0x0F000000 |
| 64 | #define DN_THRESHOLD_M 0xF0000000 |
| 65 | |
| 66 | /* Bit Values */ |
| 67 | #define ENABLE_CPR BIT(0) |
| 68 | #define DISABLE_CPR 0x0 |
| 69 | #define ENABLE_TIMER BIT(3) |
| 70 | #define DISABLE_TIMER 0x0 |
| 71 | #define SW_MODE 0x0 |
| 72 | #define SW_AUTO_CONT_ACK_EN BIT(5) |
| 73 | #define SW_AUTO_CONT_NACK_DN_EN BIT(6) |
| 74 | |
Kaushal Kumar | a6bad69 | 2012-09-27 06:52:19 +0530 | [diff] [blame] | 75 | /* Shift Values */ |
| 76 | #define RBIF_CONS_DN_SHIFT (0x4) |
| 77 | |
Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 78 | /* Test values for RBCPR RUMI Testing */ |
| 79 | #define GNT_CNT 0xC0 |
| 80 | #define TARGET 0xEFF |
| 81 | |
| 82 | #define CEILING_V 0x30 |
| 83 | #define FLOOR_V 0x15 |
| 84 | |
| 85 | #define SW_LEVEL 0x20 |
| 86 | |
| 87 | /* Interrupt Mask for All interrupt flags */ |
| 88 | #define INT_MASK (MIN_INT | DOWN_INT | MID_INT | UP_INT | MAX_INT) |
| 89 | |
| 90 | /* Number of oscilator in each sensor */ |
| 91 | #define NUM_OSC 8 |
| 92 | |
| 93 | #define CPR_MODE 2 |
| 94 | |
| 95 | /** |
| 96 | * enum cpr_mode - Modes in which cpr is used |
| 97 | */ |
| 98 | enum cpr_mode { |
| 99 | NORMAL_MODE = 0, |
| 100 | TURBO_MODE, |
| 101 | SVS_MODE, |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * enum cpr_action - Cpr actions to be taken |
| 106 | */ |
| 107 | enum cpr_action { |
| 108 | DOWN = 0, |
| 109 | UP, |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * enum cpr_interrupt |
| 114 | */ |
| 115 | enum cpr_interrupt { |
| 116 | DONE_INT = BIT(0), |
| 117 | MIN_INT = BIT(1), |
| 118 | DOWN_INT = BIT(2), |
| 119 | MID_INT = BIT(3), |
| 120 | UP_INT = BIT(4), |
| 121 | MAX_INT = BIT(5), |
| 122 | }; |
| 123 | |
| 124 | /** |
Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 125 | * struct msm_cpr_osc - Data for CPR ring oscillator |
| 126 | * @gcnt: gate count value for the oscillator |
Kaushal Kumar | d0e4c81 | 2012-08-22 16:30:09 +0530 | [diff] [blame] | 127 | * @quot: target value for ring oscillator |
Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 128 | */ |
| 129 | struct msm_cpr_osc { |
| 130 | int gcnt; |
Kaushal Kumar | d0e4c81 | 2012-08-22 16:30:09 +0530 | [diff] [blame] | 131 | uint32_t quot; |
Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /** |
| 135 | * struct msm_cpr_mode - Data for CPR modes of operation |
| 136 | * @msm_cpr_osc: structure for oscillator data |
| 137 | * @ring_osc: ring oscillator of the sensor |
| 138 | * @tgt_volt_offset: inital voltage offset from default value |
| 139 | * @step_quot: step Quot for CPR calcuation |
| 140 | */ |
| 141 | struct msm_cpr_mode { |
| 142 | struct msm_cpr_osc ring_osc_data[NUM_OSC]; |
| 143 | int ring_osc; |
| 144 | int32_t tgt_volt_offset; |
| 145 | uint32_t step_quot; |
Trilok Soni | db64ae9 | 2012-09-02 02:09:04 +0530 | [diff] [blame] | 146 | uint32_t turbo_Vmax; |
| 147 | uint32_t turbo_Vmin; |
| 148 | uint32_t nom_Vmax; |
| 149 | uint32_t nom_Vmin; |
Kaushal Kumar | d0e4c81 | 2012-08-22 16:30:09 +0530 | [diff] [blame] | 150 | uint32_t calibrated_uV; |
Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | /** |
| 154 | * struct msm_cpr_config - Platform data for CPR configuration |
| 155 | * @ref_clk_khz: clock value of CPR in KHz |
| 156 | * @delay_us: timer delay in micro second |
| 157 | * @irq_line: irq line to be use (0 or 1 or 2) |
| 158 | * @msm_cpr_mode: structure for CPR mode data |
| 159 | */ |
| 160 | struct msm_cpr_config { |
| 161 | unsigned long ref_clk_khz; |
| 162 | unsigned long delay_us; |
| 163 | int irq_line; |
| 164 | struct msm_cpr_mode *cpr_mode_data; |
| 165 | int min_down_step; |
| 166 | uint32_t tgt_count_div_N; /* Target Cnt(Nom) = Target Cnt(Turbo) / N */ |
| 167 | uint32_t floor; |
| 168 | uint32_t ceiling; |
| 169 | uint32_t sw_vlevel; |
| 170 | uint32_t up_threshold; |
| 171 | uint32_t dn_threshold; |
| 172 | uint32_t up_margin; |
| 173 | uint32_t dn_margin; |
Kaushal Kumar | d0e4c81 | 2012-08-22 16:30:09 +0530 | [diff] [blame] | 174 | uint32_t max_nom_freq; |
| 175 | uint32_t max_freq; |
| 176 | uint32_t max_quot; |
Kaushal Kumar | ecfc918 | 2012-10-25 16:17:51 +0530 | [diff] [blame] | 177 | bool disable_cpr; |
Tirupathi Reddy | 7c5d7b1 | 2012-11-06 13:29:36 +0530 | [diff] [blame] | 178 | uint32_t step_size; |
Kaushal Kumar | d0e4c81 | 2012-08-22 16:30:09 +0530 | [diff] [blame] | 179 | uint32_t (*get_quot)(uint32_t max_quot, uint32_t max_freq, |
| 180 | uint32_t new_freq); |
| 181 | void (*clk_enable)(void); |
Pankaj Kumar | 32ce1ea | 2012-04-04 20:29:29 +0530 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | /** |
| 185 | * struct msm_cpr_config - CPR Registers |
| 186 | */ |
| 187 | struct msm_cpr_reg { |
| 188 | uint32_t rbif_timer_interval; |
| 189 | uint32_t rbif_int_en; |
| 190 | uint32_t rbif_limit; |
| 191 | uint32_t rbif_timer_adjust; |
| 192 | uint32_t rbcpr_gcnt_target; |
| 193 | uint32_t rbcpr_step_quot; |
| 194 | uint32_t rbif_sw_level; |
| 195 | uint32_t rbcpr_ctl; |
| 196 | }; |
| 197 | |
| 198 | #if defined(CONFIG_MSM_CPR) || defined(CONFIG_MSM_CPR_MODULE) |
| 199 | /* msm_cpr_pm_resume: Used by Power Manager for Idle Power Collapse */ |
| 200 | void msm_cpr_pm_resume(void); |
| 201 | /* msm_cpr_pm_suspend: Used by Power Manager for Idle Power Collapse */ |
| 202 | void msm_cpr_pm_suspend(void); |
| 203 | /* msm_cpr_enable: Used by Power Manager for GDFS */ |
| 204 | void msm_cpr_enable(void); |
| 205 | /* msm_cpr_disable: Used by Power Manager for GDFS */ |
| 206 | void msm_cpr_disable(void); |
| 207 | #else |
| 208 | /* msm_cpr_pm_resume: Used by Power Manager for Idle Power Collapse */ |
| 209 | void msm_cpr_pm_resume(void) { } |
| 210 | /* msm_cpr_pm_suspend: Used by Power Manager for Idle Power Collapse */ |
| 211 | void msm_cpr_pm_suspend(void) { } |
| 212 | /* msm_cpr_enable: Used by Power Manager for GDFS */ |
| 213 | void msm_cpr_enable(void) { } |
| 214 | /* msm_cpr_disable: Used by Power Manager for GDFS */ |
| 215 | void msm_cpr_disable(void) { } |
| 216 | #endif |
| 217 | |
| 218 | #ifdef CONFIG_DEBUG_FS |
| 219 | int msm_cpr_debug_init(void *); |
| 220 | #else |
| 221 | static inline int msm_cpr_debug_init(void *) { return 0; } |
| 222 | #endif |
| 223 | #endif /* __ARCH_ARM_MACH_MSM_CPR_H */ |