Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 1 | /* |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2 | * Copyright (C) STMicroelectronics 2009 |
| 3 | * Copyright (C) ST-Ericsson SA 2010 |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 4 | * |
| 5 | * License Terms: GNU General Public License v2 |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 6 | * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com> |
| 7 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 8 | * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> |
| 9 | * |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 10 | * U8500 PRCM Unit interface driver |
| 11 | * |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 12 | */ |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 13 | #include <linux/module.h> |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/delay.h> |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 16 | #include <linux/errno.h> |
| 17 | #include <linux/err.h> |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 18 | #include <linux/spinlock.h> |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 19 | #include <linux/io.h> |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 20 | #include <linux/slab.h> |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 21 | #include <linux/mutex.h> |
| 22 | #include <linux/completion.h> |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 23 | #include <linux/irq.h> |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 24 | #include <linux/jiffies.h> |
| 25 | #include <linux/bitops.h> |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 26 | #include <linux/fs.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/uaccess.h> |
| 29 | #include <linux/mfd/core.h> |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 30 | #include <linux/mfd/dbx500-prcmu.h> |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 31 | #include <linux/regulator/db8500-prcmu.h> |
| 32 | #include <linux/regulator/machine.h> |
Daniel Lezcano | cc9a0f6 | 2012-02-28 22:46:06 +0100 | [diff] [blame] | 33 | #include <asm/hardware/gic.h> |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 34 | #include <mach/hardware.h> |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 35 | #include <mach/irqs.h> |
| 36 | #include <mach/db8500-regs.h> |
| 37 | #include <mach/id.h> |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 38 | #include "dbx500-prcmu-regs.h" |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 39 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 40 | /* Offset for the firmware version within the TCPM */ |
| 41 | #define PRCMU_FW_VERSION_OFFSET 0xA4 |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 42 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 43 | /* Index of different voltages to be used when accessing AVSData */ |
| 44 | #define PRCM_AVS_BASE 0x2FC |
| 45 | #define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0) |
| 46 | #define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1) |
| 47 | #define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2) |
| 48 | #define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3) |
| 49 | #define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4) |
| 50 | #define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5) |
| 51 | #define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6) |
| 52 | #define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7) |
| 53 | #define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8) |
| 54 | #define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9) |
| 55 | #define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA) |
| 56 | #define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB) |
| 57 | #define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC) |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 58 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 59 | #define PRCM_AVS_VOLTAGE 0 |
| 60 | #define PRCM_AVS_VOLTAGE_MASK 0x3f |
| 61 | #define PRCM_AVS_ISSLOWSTARTUP 6 |
| 62 | #define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP) |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 63 | #define PRCM_AVS_ISMODEENABLE 7 |
| 64 | #define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE) |
| 65 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 66 | #define PRCM_BOOT_STATUS 0xFFF |
| 67 | #define PRCM_ROMCODE_A2P 0xFFE |
| 68 | #define PRCM_ROMCODE_P2A 0xFFD |
| 69 | #define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */ |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 70 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 71 | #define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */ |
| 72 | |
| 73 | #define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */ |
| 74 | #define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0) |
| 75 | #define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1) |
| 76 | #define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2) |
| 77 | #define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3) |
| 78 | #define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4) |
| 79 | #define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5) |
| 80 | #define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8) |
| 81 | |
| 82 | /* Req Mailboxes */ |
| 83 | #define PRCM_REQ_MB0 0xFDC /* 12 bytes */ |
| 84 | #define PRCM_REQ_MB1 0xFD0 /* 12 bytes */ |
| 85 | #define PRCM_REQ_MB2 0xFC0 /* 16 bytes */ |
| 86 | #define PRCM_REQ_MB3 0xE4C /* 372 bytes */ |
| 87 | #define PRCM_REQ_MB4 0xE48 /* 4 bytes */ |
| 88 | #define PRCM_REQ_MB5 0xE44 /* 4 bytes */ |
| 89 | |
| 90 | /* Ack Mailboxes */ |
| 91 | #define PRCM_ACK_MB0 0xE08 /* 52 bytes */ |
| 92 | #define PRCM_ACK_MB1 0xE04 /* 4 bytes */ |
| 93 | #define PRCM_ACK_MB2 0xE00 /* 4 bytes */ |
| 94 | #define PRCM_ACK_MB3 0xDFC /* 4 bytes */ |
| 95 | #define PRCM_ACK_MB4 0xDF8 /* 4 bytes */ |
| 96 | #define PRCM_ACK_MB5 0xDF4 /* 4 bytes */ |
| 97 | |
| 98 | /* Mailbox 0 headers */ |
| 99 | #define MB0H_POWER_STATE_TRANS 0 |
| 100 | #define MB0H_CONFIG_WAKEUPS_EXE 1 |
| 101 | #define MB0H_READ_WAKEUP_ACK 3 |
| 102 | #define MB0H_CONFIG_WAKEUPS_SLEEP 4 |
| 103 | |
| 104 | #define MB0H_WAKEUP_EXE 2 |
| 105 | #define MB0H_WAKEUP_SLEEP 5 |
| 106 | |
| 107 | /* Mailbox 0 REQs */ |
| 108 | #define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0) |
| 109 | #define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1) |
| 110 | #define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2) |
| 111 | #define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3) |
| 112 | #define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4) |
| 113 | #define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8) |
| 114 | |
| 115 | /* Mailbox 0 ACKs */ |
| 116 | #define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0) |
| 117 | #define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1) |
| 118 | #define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4) |
| 119 | #define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8) |
| 120 | #define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C) |
| 121 | #define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20) |
| 122 | #define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20 |
| 123 | |
| 124 | /* Mailbox 1 headers */ |
| 125 | #define MB1H_ARM_APE_OPP 0x0 |
| 126 | #define MB1H_RESET_MODEM 0x2 |
| 127 | #define MB1H_REQUEST_APE_OPP_100_VOLT 0x3 |
| 128 | #define MB1H_RELEASE_APE_OPP_100_VOLT 0x4 |
| 129 | #define MB1H_RELEASE_USB_WAKEUP 0x5 |
Mattias Nilsson | a592c2e | 2011-08-12 10:27:41 +0200 | [diff] [blame] | 130 | #define MB1H_PLL_ON_OFF 0x6 |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 131 | |
| 132 | /* Mailbox 1 Requests */ |
| 133 | #define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0) |
| 134 | #define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1) |
Mattias Nilsson | a592c2e | 2011-08-12 10:27:41 +0200 | [diff] [blame] | 135 | #define PRCM_REQ_MB1_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4) |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 136 | #define PLL_SOC0_OFF 0x1 |
| 137 | #define PLL_SOC0_ON 0x2 |
Mattias Nilsson | a592c2e | 2011-08-12 10:27:41 +0200 | [diff] [blame] | 138 | #define PLL_SOC1_OFF 0x4 |
| 139 | #define PLL_SOC1_ON 0x8 |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 140 | |
| 141 | /* Mailbox 1 ACKs */ |
| 142 | #define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0) |
| 143 | #define PRCM_ACK_MB1_CURRENT_APE_OPP (PRCM_ACK_MB1 + 0x1) |
| 144 | #define PRCM_ACK_MB1_APE_VOLTAGE_STATUS (PRCM_ACK_MB1 + 0x2) |
| 145 | #define PRCM_ACK_MB1_DVFS_STATUS (PRCM_ACK_MB1 + 0x3) |
| 146 | |
| 147 | /* Mailbox 2 headers */ |
| 148 | #define MB2H_DPS 0x0 |
| 149 | #define MB2H_AUTO_PWR 0x1 |
| 150 | |
| 151 | /* Mailbox 2 REQs */ |
| 152 | #define PRCM_REQ_MB2_SVA_MMDSP (PRCM_REQ_MB2 + 0x0) |
| 153 | #define PRCM_REQ_MB2_SVA_PIPE (PRCM_REQ_MB2 + 0x1) |
| 154 | #define PRCM_REQ_MB2_SIA_MMDSP (PRCM_REQ_MB2 + 0x2) |
| 155 | #define PRCM_REQ_MB2_SIA_PIPE (PRCM_REQ_MB2 + 0x3) |
| 156 | #define PRCM_REQ_MB2_SGA (PRCM_REQ_MB2 + 0x4) |
| 157 | #define PRCM_REQ_MB2_B2R2_MCDE (PRCM_REQ_MB2 + 0x5) |
| 158 | #define PRCM_REQ_MB2_ESRAM12 (PRCM_REQ_MB2 + 0x6) |
| 159 | #define PRCM_REQ_MB2_ESRAM34 (PRCM_REQ_MB2 + 0x7) |
| 160 | #define PRCM_REQ_MB2_AUTO_PM_SLEEP (PRCM_REQ_MB2 + 0x8) |
| 161 | #define PRCM_REQ_MB2_AUTO_PM_IDLE (PRCM_REQ_MB2 + 0xC) |
| 162 | |
| 163 | /* Mailbox 2 ACKs */ |
| 164 | #define PRCM_ACK_MB2_DPS_STATUS (PRCM_ACK_MB2 + 0x0) |
| 165 | #define HWACC_PWR_ST_OK 0xFE |
| 166 | |
| 167 | /* Mailbox 3 headers */ |
| 168 | #define MB3H_ANC 0x0 |
| 169 | #define MB3H_SIDETONE 0x1 |
| 170 | #define MB3H_SYSCLK 0xE |
| 171 | |
| 172 | /* Mailbox 3 Requests */ |
| 173 | #define PRCM_REQ_MB3_ANC_FIR_COEFF (PRCM_REQ_MB3 + 0x0) |
| 174 | #define PRCM_REQ_MB3_ANC_IIR_COEFF (PRCM_REQ_MB3 + 0x20) |
| 175 | #define PRCM_REQ_MB3_ANC_SHIFTER (PRCM_REQ_MB3 + 0x60) |
| 176 | #define PRCM_REQ_MB3_ANC_WARP (PRCM_REQ_MB3 + 0x64) |
| 177 | #define PRCM_REQ_MB3_SIDETONE_FIR_GAIN (PRCM_REQ_MB3 + 0x68) |
| 178 | #define PRCM_REQ_MB3_SIDETONE_FIR_COEFF (PRCM_REQ_MB3 + 0x6C) |
| 179 | #define PRCM_REQ_MB3_SYSCLK_MGT (PRCM_REQ_MB3 + 0x16C) |
| 180 | |
| 181 | /* Mailbox 4 headers */ |
| 182 | #define MB4H_DDR_INIT 0x0 |
| 183 | #define MB4H_MEM_ST 0x1 |
| 184 | #define MB4H_HOTDOG 0x12 |
| 185 | #define MB4H_HOTMON 0x13 |
| 186 | #define MB4H_HOT_PERIOD 0x14 |
Mattias Nilsson | a592c2e | 2011-08-12 10:27:41 +0200 | [diff] [blame] | 187 | #define MB4H_A9WDOG_CONF 0x16 |
| 188 | #define MB4H_A9WDOG_EN 0x17 |
| 189 | #define MB4H_A9WDOG_DIS 0x18 |
| 190 | #define MB4H_A9WDOG_LOAD 0x19 |
| 191 | #define MB4H_A9WDOG_KICK 0x20 |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 192 | |
| 193 | /* Mailbox 4 Requests */ |
| 194 | #define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0) |
| 195 | #define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1) |
| 196 | #define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3) |
| 197 | #define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0) |
| 198 | #define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0) |
| 199 | #define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1) |
| 200 | #define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2) |
| 201 | #define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0) |
| 202 | #define HOTMON_CONFIG_LOW BIT(0) |
| 203 | #define HOTMON_CONFIG_HIGH BIT(1) |
Mattias Nilsson | a592c2e | 2011-08-12 10:27:41 +0200 | [diff] [blame] | 204 | #define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0) |
| 205 | #define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1) |
| 206 | #define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2) |
| 207 | #define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3) |
| 208 | #define A9WDOG_AUTO_OFF_EN BIT(7) |
| 209 | #define A9WDOG_AUTO_OFF_DIS 0 |
| 210 | #define A9WDOG_ID_MASK 0xf |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 211 | |
| 212 | /* Mailbox 5 Requests */ |
| 213 | #define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0) |
| 214 | #define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1) |
| 215 | #define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2) |
| 216 | #define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3) |
| 217 | #define PRCMU_I2C_WRITE(slave) \ |
| 218 | (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0)) |
| 219 | #define PRCMU_I2C_READ(slave) \ |
| 220 | (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0)) |
| 221 | #define PRCMU_I2C_STOP_EN BIT(3) |
| 222 | |
| 223 | /* Mailbox 5 ACKs */ |
| 224 | #define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1) |
| 225 | #define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3) |
| 226 | #define I2C_WR_OK 0x1 |
| 227 | #define I2C_RD_OK 0x2 |
| 228 | |
| 229 | #define NUM_MB 8 |
| 230 | #define MBOX_BIT BIT |
| 231 | #define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1) |
| 232 | |
| 233 | /* |
| 234 | * Wakeups/IRQs |
| 235 | */ |
| 236 | |
| 237 | #define WAKEUP_BIT_RTC BIT(0) |
| 238 | #define WAKEUP_BIT_RTT0 BIT(1) |
| 239 | #define WAKEUP_BIT_RTT1 BIT(2) |
| 240 | #define WAKEUP_BIT_HSI0 BIT(3) |
| 241 | #define WAKEUP_BIT_HSI1 BIT(4) |
| 242 | #define WAKEUP_BIT_CA_WAKE BIT(5) |
| 243 | #define WAKEUP_BIT_USB BIT(6) |
| 244 | #define WAKEUP_BIT_ABB BIT(7) |
| 245 | #define WAKEUP_BIT_ABB_FIFO BIT(8) |
| 246 | #define WAKEUP_BIT_SYSCLK_OK BIT(9) |
| 247 | #define WAKEUP_BIT_CA_SLEEP BIT(10) |
| 248 | #define WAKEUP_BIT_AC_WAKE_ACK BIT(11) |
| 249 | #define WAKEUP_BIT_SIDE_TONE_OK BIT(12) |
| 250 | #define WAKEUP_BIT_ANC_OK BIT(13) |
| 251 | #define WAKEUP_BIT_SW_ERROR BIT(14) |
| 252 | #define WAKEUP_BIT_AC_SLEEP_ACK BIT(15) |
| 253 | #define WAKEUP_BIT_ARM BIT(17) |
| 254 | #define WAKEUP_BIT_HOTMON_LOW BIT(18) |
| 255 | #define WAKEUP_BIT_HOTMON_HIGH BIT(19) |
| 256 | #define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20) |
| 257 | #define WAKEUP_BIT_GPIO0 BIT(23) |
| 258 | #define WAKEUP_BIT_GPIO1 BIT(24) |
| 259 | #define WAKEUP_BIT_GPIO2 BIT(25) |
| 260 | #define WAKEUP_BIT_GPIO3 BIT(26) |
| 261 | #define WAKEUP_BIT_GPIO4 BIT(27) |
| 262 | #define WAKEUP_BIT_GPIO5 BIT(28) |
| 263 | #define WAKEUP_BIT_GPIO6 BIT(29) |
| 264 | #define WAKEUP_BIT_GPIO7 BIT(30) |
| 265 | #define WAKEUP_BIT_GPIO8 BIT(31) |
| 266 | |
Mattias Nilsson | b58d12f | 2012-01-13 16:20:10 +0100 | [diff] [blame] | 267 | static struct { |
| 268 | bool valid; |
| 269 | struct prcmu_fw_version version; |
| 270 | } fw_info; |
| 271 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 272 | /* |
| 273 | * This vector maps irq numbers to the bits in the bit field used in |
| 274 | * communication with the PRCMU firmware. |
| 275 | * |
| 276 | * The reason for having this is to keep the irq numbers contiguous even though |
| 277 | * the bits in the bit field are not. (The bits also have a tendency to move |
| 278 | * around, to further complicate matters.) |
| 279 | */ |
| 280 | #define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE) |
| 281 | #define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name) |
| 282 | static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = { |
| 283 | IRQ_ENTRY(RTC), |
| 284 | IRQ_ENTRY(RTT0), |
| 285 | IRQ_ENTRY(RTT1), |
| 286 | IRQ_ENTRY(HSI0), |
| 287 | IRQ_ENTRY(HSI1), |
| 288 | IRQ_ENTRY(CA_WAKE), |
| 289 | IRQ_ENTRY(USB), |
| 290 | IRQ_ENTRY(ABB), |
| 291 | IRQ_ENTRY(ABB_FIFO), |
| 292 | IRQ_ENTRY(CA_SLEEP), |
| 293 | IRQ_ENTRY(ARM), |
| 294 | IRQ_ENTRY(HOTMON_LOW), |
| 295 | IRQ_ENTRY(HOTMON_HIGH), |
| 296 | IRQ_ENTRY(MODEM_SW_RESET_REQ), |
| 297 | IRQ_ENTRY(GPIO0), |
| 298 | IRQ_ENTRY(GPIO1), |
| 299 | IRQ_ENTRY(GPIO2), |
| 300 | IRQ_ENTRY(GPIO3), |
| 301 | IRQ_ENTRY(GPIO4), |
| 302 | IRQ_ENTRY(GPIO5), |
| 303 | IRQ_ENTRY(GPIO6), |
| 304 | IRQ_ENTRY(GPIO7), |
| 305 | IRQ_ENTRY(GPIO8) |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 306 | }; |
| 307 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 308 | #define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1) |
| 309 | #define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name) |
| 310 | static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = { |
| 311 | WAKEUP_ENTRY(RTC), |
| 312 | WAKEUP_ENTRY(RTT0), |
| 313 | WAKEUP_ENTRY(RTT1), |
| 314 | WAKEUP_ENTRY(HSI0), |
| 315 | WAKEUP_ENTRY(HSI1), |
| 316 | WAKEUP_ENTRY(USB), |
| 317 | WAKEUP_ENTRY(ABB), |
| 318 | WAKEUP_ENTRY(ABB_FIFO), |
| 319 | WAKEUP_ENTRY(ARM) |
| 320 | }; |
| 321 | |
| 322 | /* |
| 323 | * mb0_transfer - state needed for mailbox 0 communication. |
| 324 | * @lock: The transaction lock. |
| 325 | * @dbb_events_lock: A lock used to handle concurrent access to (parts of) |
| 326 | * the request data. |
| 327 | * @mask_work: Work structure used for (un)masking wakeup interrupts. |
| 328 | * @req: Request data that need to persist between requests. |
| 329 | */ |
| 330 | static struct { |
| 331 | spinlock_t lock; |
| 332 | spinlock_t dbb_irqs_lock; |
| 333 | struct work_struct mask_work; |
| 334 | struct mutex ac_wake_lock; |
| 335 | struct completion ac_wake_work; |
| 336 | struct { |
| 337 | u32 dbb_irqs; |
| 338 | u32 dbb_wakeups; |
| 339 | u32 abb_events; |
| 340 | } req; |
| 341 | } mb0_transfer; |
| 342 | |
| 343 | /* |
| 344 | * mb1_transfer - state needed for mailbox 1 communication. |
| 345 | * @lock: The transaction lock. |
| 346 | * @work: The transaction completion structure. |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 347 | * @ape_opp: The current APE OPP. |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 348 | * @ack: Reply ("acknowledge") data. |
| 349 | */ |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 350 | static struct { |
| 351 | struct mutex lock; |
| 352 | struct completion work; |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 353 | u8 ape_opp; |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 354 | struct { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 355 | u8 header; |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 356 | u8 arm_opp; |
| 357 | u8 ape_opp; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 358 | u8 ape_voltage_status; |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 359 | } ack; |
| 360 | } mb1_transfer; |
| 361 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 362 | /* |
| 363 | * mb2_transfer - state needed for mailbox 2 communication. |
| 364 | * @lock: The transaction lock. |
| 365 | * @work: The transaction completion structure. |
| 366 | * @auto_pm_lock: The autonomous power management configuration lock. |
| 367 | * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled. |
| 368 | * @req: Request data that need to persist between requests. |
| 369 | * @ack: Reply ("acknowledge") data. |
| 370 | */ |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 371 | static struct { |
| 372 | struct mutex lock; |
| 373 | struct completion work; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 374 | spinlock_t auto_pm_lock; |
| 375 | bool auto_pm_enabled; |
| 376 | struct { |
| 377 | u8 status; |
| 378 | } ack; |
| 379 | } mb2_transfer; |
| 380 | |
| 381 | /* |
| 382 | * mb3_transfer - state needed for mailbox 3 communication. |
| 383 | * @lock: The request lock. |
| 384 | * @sysclk_lock: A lock used to handle concurrent sysclk requests. |
| 385 | * @sysclk_work: Work structure used for sysclk requests. |
| 386 | */ |
| 387 | static struct { |
| 388 | spinlock_t lock; |
| 389 | struct mutex sysclk_lock; |
| 390 | struct completion sysclk_work; |
| 391 | } mb3_transfer; |
| 392 | |
| 393 | /* |
| 394 | * mb4_transfer - state needed for mailbox 4 communication. |
| 395 | * @lock: The transaction lock. |
| 396 | * @work: The transaction completion structure. |
| 397 | */ |
| 398 | static struct { |
| 399 | struct mutex lock; |
| 400 | struct completion work; |
| 401 | } mb4_transfer; |
| 402 | |
| 403 | /* |
| 404 | * mb5_transfer - state needed for mailbox 5 communication. |
| 405 | * @lock: The transaction lock. |
| 406 | * @work: The transaction completion structure. |
| 407 | * @ack: Reply ("acknowledge") data. |
| 408 | */ |
| 409 | static struct { |
| 410 | struct mutex lock; |
| 411 | struct completion work; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 412 | struct { |
| 413 | u8 status; |
| 414 | u8 value; |
| 415 | } ack; |
| 416 | } mb5_transfer; |
| 417 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 418 | static atomic_t ac_wake_req_state = ATOMIC_INIT(0); |
| 419 | |
| 420 | /* Spinlocks */ |
Mattias Nilsson | b4a6dbd | 2012-01-13 16:21:00 +0100 | [diff] [blame] | 421 | static DEFINE_SPINLOCK(prcmu_lock); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 422 | static DEFINE_SPINLOCK(clkout_lock); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 423 | |
| 424 | /* Global var to runtime determine TCDM base for v2 or v1 */ |
| 425 | static __iomem void *tcdm_base; |
| 426 | |
| 427 | struct clk_mgt { |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 428 | void __iomem *reg; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 429 | u32 pllsw; |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 430 | int branch; |
| 431 | bool clk38div; |
| 432 | }; |
| 433 | |
| 434 | enum { |
| 435 | PLL_RAW, |
| 436 | PLL_FIX, |
| 437 | PLL_DIV |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | static DEFINE_SPINLOCK(clk_mgt_lock); |
| 441 | |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 442 | #define CLK_MGT_ENTRY(_name, _branch, _clk38div)[PRCMU_##_name] = \ |
| 443 | { (PRCM_##_name##_MGT), 0 , _branch, _clk38div} |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 444 | struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = { |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 445 | CLK_MGT_ENTRY(SGACLK, PLL_DIV, false), |
| 446 | CLK_MGT_ENTRY(UARTCLK, PLL_FIX, true), |
| 447 | CLK_MGT_ENTRY(MSP02CLK, PLL_FIX, true), |
| 448 | CLK_MGT_ENTRY(MSP1CLK, PLL_FIX, true), |
| 449 | CLK_MGT_ENTRY(I2CCLK, PLL_FIX, true), |
| 450 | CLK_MGT_ENTRY(SDMMCCLK, PLL_DIV, true), |
| 451 | CLK_MGT_ENTRY(SLIMCLK, PLL_FIX, true), |
| 452 | CLK_MGT_ENTRY(PER1CLK, PLL_DIV, true), |
| 453 | CLK_MGT_ENTRY(PER2CLK, PLL_DIV, true), |
| 454 | CLK_MGT_ENTRY(PER3CLK, PLL_DIV, true), |
| 455 | CLK_MGT_ENTRY(PER5CLK, PLL_DIV, true), |
| 456 | CLK_MGT_ENTRY(PER6CLK, PLL_DIV, true), |
| 457 | CLK_MGT_ENTRY(PER7CLK, PLL_DIV, true), |
| 458 | CLK_MGT_ENTRY(LCDCLK, PLL_FIX, true), |
| 459 | CLK_MGT_ENTRY(BMLCLK, PLL_DIV, true), |
| 460 | CLK_MGT_ENTRY(HSITXCLK, PLL_DIV, true), |
| 461 | CLK_MGT_ENTRY(HSIRXCLK, PLL_DIV, true), |
| 462 | CLK_MGT_ENTRY(HDMICLK, PLL_FIX, false), |
| 463 | CLK_MGT_ENTRY(APEATCLK, PLL_DIV, true), |
| 464 | CLK_MGT_ENTRY(APETRACECLK, PLL_DIV, true), |
| 465 | CLK_MGT_ENTRY(MCDECLK, PLL_DIV, true), |
| 466 | CLK_MGT_ENTRY(IPI2CCLK, PLL_FIX, true), |
| 467 | CLK_MGT_ENTRY(DSIALTCLK, PLL_FIX, false), |
| 468 | CLK_MGT_ENTRY(DMACLK, PLL_DIV, true), |
| 469 | CLK_MGT_ENTRY(B2R2CLK, PLL_DIV, true), |
| 470 | CLK_MGT_ENTRY(TVCLK, PLL_FIX, true), |
| 471 | CLK_MGT_ENTRY(SSPCLK, PLL_FIX, true), |
| 472 | CLK_MGT_ENTRY(RNGCLK, PLL_FIX, true), |
| 473 | CLK_MGT_ENTRY(UICCCLK, PLL_FIX, false), |
| 474 | }; |
| 475 | |
| 476 | struct dsiclk { |
| 477 | u32 divsel_mask; |
| 478 | u32 divsel_shift; |
| 479 | u32 divsel; |
| 480 | }; |
| 481 | |
| 482 | static struct dsiclk dsiclk[2] = { |
| 483 | { |
| 484 | .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_MASK, |
| 485 | .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_SHIFT, |
| 486 | .divsel = PRCM_DSI_PLLOUT_SEL_PHI, |
| 487 | }, |
| 488 | { |
| 489 | .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_MASK, |
| 490 | .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_SHIFT, |
| 491 | .divsel = PRCM_DSI_PLLOUT_SEL_PHI, |
| 492 | } |
| 493 | }; |
| 494 | |
| 495 | struct dsiescclk { |
| 496 | u32 en; |
| 497 | u32 div_mask; |
| 498 | u32 div_shift; |
| 499 | }; |
| 500 | |
| 501 | static struct dsiescclk dsiescclk[3] = { |
| 502 | { |
| 503 | .en = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_EN, |
| 504 | .div_mask = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_MASK, |
| 505 | .div_shift = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_SHIFT, |
| 506 | }, |
| 507 | { |
| 508 | .en = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_EN, |
| 509 | .div_mask = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_MASK, |
| 510 | .div_shift = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_SHIFT, |
| 511 | }, |
| 512 | { |
| 513 | .en = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_EN, |
| 514 | .div_mask = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_MASK, |
| 515 | .div_shift = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_SHIFT, |
| 516 | } |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 517 | }; |
| 518 | |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 519 | static struct regulator *hwacc_regulator[NUM_HW_ACC]; |
| 520 | static struct regulator *hwacc_ret_regulator[NUM_HW_ACC]; |
| 521 | |
| 522 | static bool hwacc_enabled[NUM_HW_ACC]; |
| 523 | static bool hwacc_ret_enabled[NUM_HW_ACC]; |
| 524 | |
| 525 | static const char *hwacc_regulator_name[NUM_HW_ACC] = { |
| 526 | [HW_ACC_SVAMMDSP] = "hwacc-sva-mmdsp", |
| 527 | [HW_ACC_SVAPIPE] = "hwacc-sva-pipe", |
| 528 | [HW_ACC_SIAMMDSP] = "hwacc-sia-mmdsp", |
| 529 | [HW_ACC_SIAPIPE] = "hwacc-sia-pipe", |
| 530 | [HW_ACC_SGA] = "hwacc-sga", |
| 531 | [HW_ACC_B2R2] = "hwacc-b2r2", |
| 532 | [HW_ACC_MCDE] = "hwacc-mcde", |
| 533 | [HW_ACC_ESRAM1] = "hwacc-esram1", |
| 534 | [HW_ACC_ESRAM2] = "hwacc-esram2", |
| 535 | [HW_ACC_ESRAM3] = "hwacc-esram3", |
| 536 | [HW_ACC_ESRAM4] = "hwacc-esram4", |
| 537 | }; |
| 538 | |
| 539 | static const char *hwacc_ret_regulator_name[NUM_HW_ACC] = { |
| 540 | [HW_ACC_SVAMMDSP] = "hwacc-sva-mmdsp-ret", |
| 541 | [HW_ACC_SIAMMDSP] = "hwacc-sia-mmdsp-ret", |
| 542 | [HW_ACC_ESRAM1] = "hwacc-esram1-ret", |
| 543 | [HW_ACC_ESRAM2] = "hwacc-esram2-ret", |
| 544 | [HW_ACC_ESRAM3] = "hwacc-esram3-ret", |
| 545 | [HW_ACC_ESRAM4] = "hwacc-esram4-ret", |
| 546 | }; |
| 547 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 548 | /* |
| 549 | * Used by MCDE to setup all necessary PRCMU registers |
| 550 | */ |
| 551 | #define PRCMU_RESET_DSIPLL 0x00004000 |
| 552 | #define PRCMU_UNCLAMP_DSIPLL 0x00400800 |
| 553 | |
| 554 | #define PRCMU_CLK_PLL_DIV_SHIFT 0 |
| 555 | #define PRCMU_CLK_PLL_SW_SHIFT 5 |
| 556 | #define PRCMU_CLK_38 (1 << 9) |
| 557 | #define PRCMU_CLK_38_SRC (1 << 10) |
| 558 | #define PRCMU_CLK_38_DIV (1 << 11) |
| 559 | |
| 560 | /* PLLDIV=12, PLLSW=4 (PLLDDR) */ |
| 561 | #define PRCMU_DSI_CLOCK_SETTING 0x0000008C |
| 562 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 563 | /* DPI 50000000 Hz */ |
| 564 | #define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \ |
| 565 | (16 << PRCMU_CLK_PLL_DIV_SHIFT)) |
| 566 | #define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00 |
| 567 | |
| 568 | /* D=101, N=1, R=4, SELDIV2=0 */ |
| 569 | #define PRCMU_PLLDSI_FREQ_SETTING 0x00040165 |
| 570 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 571 | #define PRCMU_ENABLE_PLLDSI 0x00000001 |
| 572 | #define PRCMU_DISABLE_PLLDSI 0x00000000 |
| 573 | #define PRCMU_RELEASE_RESET_DSS 0x0000400C |
| 574 | #define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202 |
| 575 | /* ESC clk, div0=1, div1=1, div2=3 */ |
| 576 | #define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101 |
| 577 | #define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101 |
| 578 | #define PRCMU_DSI_RESET_SW 0x00000007 |
| 579 | |
| 580 | #define PRCMU_PLLDSI_LOCKP_LOCKED 0x3 |
| 581 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 582 | int db8500_prcmu_enable_dsipll(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 583 | { |
| 584 | int i; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 585 | |
| 586 | /* Clear DSIPLL_RESETN */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 587 | writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 588 | /* Unclamp DSIPLL in/out */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 589 | writel(PRCMU_UNCLAMP_DSIPLL, PRCM_MMIP_LS_CLAMP_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 590 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 591 | /* Set DSI PLL FREQ */ |
Daniel Willerud | c72fe85 | 2012-01-13 16:20:03 +0100 | [diff] [blame] | 592 | writel(PRCMU_PLLDSI_FREQ_SETTING, PRCM_PLLDSI_FREQ); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 593 | writel(PRCMU_DSI_PLLOUT_SEL_SETTING, PRCM_DSI_PLLOUT_SEL); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 594 | /* Enable Escape clocks */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 595 | writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 596 | |
| 597 | /* Start DSI PLL */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 598 | writel(PRCMU_ENABLE_PLLDSI, PRCM_PLLDSI_ENABLE); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 599 | /* Reset DSI PLL */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 600 | writel(PRCMU_DSI_RESET_SW, PRCM_DSI_SW_RESET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 601 | for (i = 0; i < 10; i++) { |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 602 | if ((readl(PRCM_PLLDSI_LOCKP) & PRCMU_PLLDSI_LOCKP_LOCKED) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 603 | == PRCMU_PLLDSI_LOCKP_LOCKED) |
| 604 | break; |
| 605 | udelay(100); |
| 606 | } |
| 607 | /* Set DSIPLL_RESETN */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 608 | writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 612 | int db8500_prcmu_disable_dsipll(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 613 | { |
| 614 | /* Disable dsi pll */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 615 | writel(PRCMU_DISABLE_PLLDSI, PRCM_PLLDSI_ENABLE); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 616 | /* Disable escapeclock */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 617 | writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 618 | return 0; |
| 619 | } |
| 620 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 621 | int db8500_prcmu_set_display_clocks(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 622 | { |
| 623 | unsigned long flags; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 624 | |
| 625 | spin_lock_irqsave(&clk_mgt_lock, flags); |
| 626 | |
| 627 | /* Grab the HW semaphore. */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 628 | while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 629 | cpu_relax(); |
| 630 | |
Daniel Willerud | c72fe85 | 2012-01-13 16:20:03 +0100 | [diff] [blame] | 631 | writel(PRCMU_DSI_CLOCK_SETTING, PRCM_HDMICLK_MGT); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 632 | writel(PRCMU_DSI_LP_CLOCK_SETTING, PRCM_TVCLK_MGT); |
| 633 | writel(PRCMU_DPI_CLOCK_SETTING, PRCM_LCDCLK_MGT); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 634 | |
| 635 | /* Release the HW semaphore. */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 636 | writel(0, PRCM_SEM); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 637 | |
| 638 | spin_unlock_irqrestore(&clk_mgt_lock, flags); |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Mattias Nilsson | b4a6dbd | 2012-01-13 16:21:00 +0100 | [diff] [blame] | 643 | u32 db8500_prcmu_read(unsigned int reg) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 644 | { |
Mattias Nilsson | b4a6dbd | 2012-01-13 16:21:00 +0100 | [diff] [blame] | 645 | return readl(_PRCMU_BASE + reg); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 646 | } |
| 647 | |
Mattias Nilsson | b4a6dbd | 2012-01-13 16:21:00 +0100 | [diff] [blame] | 648 | void db8500_prcmu_write(unsigned int reg, u32 value) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 649 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 650 | unsigned long flags; |
| 651 | |
Mattias Nilsson | b4a6dbd | 2012-01-13 16:21:00 +0100 | [diff] [blame] | 652 | spin_lock_irqsave(&prcmu_lock, flags); |
| 653 | writel(value, (_PRCMU_BASE + reg)); |
| 654 | spin_unlock_irqrestore(&prcmu_lock, flags); |
| 655 | } |
| 656 | |
| 657 | void db8500_prcmu_write_masked(unsigned int reg, u32 mask, u32 value) |
| 658 | { |
| 659 | u32 val; |
| 660 | unsigned long flags; |
| 661 | |
| 662 | spin_lock_irqsave(&prcmu_lock, flags); |
| 663 | val = readl(_PRCMU_BASE + reg); |
| 664 | val = ((val & ~mask) | (value & mask)); |
| 665 | writel(val, (_PRCMU_BASE + reg)); |
| 666 | spin_unlock_irqrestore(&prcmu_lock, flags); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 667 | } |
| 668 | |
Mattias Nilsson | b58d12f | 2012-01-13 16:20:10 +0100 | [diff] [blame] | 669 | struct prcmu_fw_version *prcmu_get_fw_version(void) |
| 670 | { |
| 671 | return fw_info.valid ? &fw_info.version : NULL; |
| 672 | } |
| 673 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 674 | bool prcmu_has_arm_maxopp(void) |
| 675 | { |
| 676 | return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) & |
| 677 | PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK; |
| 678 | } |
| 679 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 680 | /** |
| 681 | * prcmu_get_boot_status - PRCMU boot status checking |
| 682 | * Returns: the current PRCMU boot status |
| 683 | */ |
| 684 | int prcmu_get_boot_status(void) |
| 685 | { |
| 686 | return readb(tcdm_base + PRCM_BOOT_STATUS); |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * prcmu_set_rc_a2p - This function is used to run few power state sequences |
| 691 | * @val: Value to be set, i.e. transition requested |
| 692 | * Returns: 0 on success, -EINVAL on invalid argument |
| 693 | * |
| 694 | * This function is used to run the following power state sequences - |
| 695 | * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep |
| 696 | */ |
| 697 | int prcmu_set_rc_a2p(enum romcode_write val) |
| 698 | { |
| 699 | if (val < RDY_2_DS || val > RDY_2_XP70_RST) |
| 700 | return -EINVAL; |
| 701 | writeb(val, (tcdm_base + PRCM_ROMCODE_A2P)); |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * prcmu_get_rc_p2a - This function is used to get power state sequences |
| 707 | * Returns: the power transition that has last happened |
| 708 | * |
| 709 | * This function can return the following transitions- |
| 710 | * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep |
| 711 | */ |
| 712 | enum romcode_read prcmu_get_rc_p2a(void) |
| 713 | { |
| 714 | return readb(tcdm_base + PRCM_ROMCODE_P2A); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * prcmu_get_current_mode - Return the current XP70 power mode |
| 719 | * Returns: Returns the current AP(ARM) power mode: init, |
| 720 | * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset |
| 721 | */ |
| 722 | enum ap_pwrst prcmu_get_xp70_current_state(void) |
| 723 | { |
| 724 | return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE); |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * prcmu_config_clkout - Configure one of the programmable clock outputs. |
| 729 | * @clkout: The CLKOUT number (0 or 1). |
| 730 | * @source: The clock to be used (one of the PRCMU_CLKSRC_*). |
| 731 | * @div: The divider to be applied. |
| 732 | * |
| 733 | * Configures one of the programmable clock outputs (CLKOUTs). |
| 734 | * @div should be in the range [1,63] to request a configuration, or 0 to |
| 735 | * inform that the configuration is no longer requested. |
| 736 | */ |
| 737 | int prcmu_config_clkout(u8 clkout, u8 source, u8 div) |
| 738 | { |
| 739 | static int requests[2]; |
| 740 | int r = 0; |
| 741 | unsigned long flags; |
| 742 | u32 val; |
| 743 | u32 bits; |
| 744 | u32 mask; |
| 745 | u32 div_mask; |
| 746 | |
| 747 | BUG_ON(clkout > 1); |
| 748 | BUG_ON(div > 63); |
| 749 | BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009)); |
| 750 | |
| 751 | if (!div && !requests[clkout]) |
| 752 | return -EINVAL; |
| 753 | |
| 754 | switch (clkout) { |
| 755 | case 0: |
| 756 | div_mask = PRCM_CLKOCR_CLKODIV0_MASK; |
| 757 | mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK); |
| 758 | bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) | |
| 759 | (div << PRCM_CLKOCR_CLKODIV0_SHIFT)); |
| 760 | break; |
| 761 | case 1: |
| 762 | div_mask = PRCM_CLKOCR_CLKODIV1_MASK; |
| 763 | mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK | |
| 764 | PRCM_CLKOCR_CLK1TYPE); |
| 765 | bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) | |
| 766 | (div << PRCM_CLKOCR_CLKODIV1_SHIFT)); |
| 767 | break; |
| 768 | } |
| 769 | bits &= mask; |
| 770 | |
| 771 | spin_lock_irqsave(&clkout_lock, flags); |
| 772 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 773 | val = readl(PRCM_CLKOCR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 774 | if (val & div_mask) { |
| 775 | if (div) { |
| 776 | if ((val & mask) != bits) { |
| 777 | r = -EBUSY; |
| 778 | goto unlock_and_return; |
| 779 | } |
| 780 | } else { |
| 781 | if ((val & mask & ~div_mask) != bits) { |
| 782 | r = -EINVAL; |
| 783 | goto unlock_and_return; |
| 784 | } |
| 785 | } |
| 786 | } |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 787 | writel((bits | (val & ~mask)), PRCM_CLKOCR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 788 | requests[clkout] += (div ? 1 : -1); |
| 789 | |
| 790 | unlock_and_return: |
| 791 | spin_unlock_irqrestore(&clkout_lock, flags); |
| 792 | |
| 793 | return r; |
| 794 | } |
| 795 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 796 | int db8500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 797 | { |
| 798 | unsigned long flags; |
| 799 | |
| 800 | BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state)); |
| 801 | |
| 802 | spin_lock_irqsave(&mb0_transfer.lock, flags); |
| 803 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 804 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 805 | cpu_relax(); |
| 806 | |
| 807 | writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0)); |
| 808 | writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE)); |
| 809 | writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE)); |
| 810 | writeb((keep_ulp_clk ? 1 : 0), |
| 811 | (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE)); |
| 812 | writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI)); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 813 | writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 814 | |
| 815 | spin_unlock_irqrestore(&mb0_transfer.lock, flags); |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 820 | u8 db8500_prcmu_get_power_state_result(void) |
| 821 | { |
| 822 | return readb(tcdm_base + PRCM_ACK_MB0_AP_PWRSTTR_STATUS); |
| 823 | } |
| 824 | |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 825 | /* This function decouple the gic from the prcmu */ |
| 826 | int db8500_prcmu_gic_decouple(void) |
| 827 | { |
Daniel Lezcano | 801448e | 2012-02-28 22:46:05 +0100 | [diff] [blame] | 828 | u32 val = readl(PRCM_A9_MASK_REQ); |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 829 | |
| 830 | /* Set bit 0 register value to 1 */ |
Daniel Lezcano | 801448e | 2012-02-28 22:46:05 +0100 | [diff] [blame] | 831 | writel(val | PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ, |
| 832 | PRCM_A9_MASK_REQ); |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 833 | |
| 834 | /* Make sure the register is updated */ |
Daniel Lezcano | 801448e | 2012-02-28 22:46:05 +0100 | [diff] [blame] | 835 | readl(PRCM_A9_MASK_REQ); |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 836 | |
| 837 | /* Wait a few cycles for the gic mask completion */ |
Daniel Lezcano | 801448e | 2012-02-28 22:46:05 +0100 | [diff] [blame] | 838 | udelay(1); |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | /* This function recouple the gic with the prcmu */ |
| 844 | int db8500_prcmu_gic_recouple(void) |
| 845 | { |
Daniel Lezcano | 801448e | 2012-02-28 22:46:05 +0100 | [diff] [blame] | 846 | u32 val = readl(PRCM_A9_MASK_REQ); |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 847 | |
| 848 | /* Set bit 0 register value to 0 */ |
Daniel Lezcano | 801448e | 2012-02-28 22:46:05 +0100 | [diff] [blame] | 849 | writel(val & ~PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ, PRCM_A9_MASK_REQ); |
Daniel Lezcano | 485540d | 2012-02-20 12:30:26 +0100 | [diff] [blame] | 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
Daniel Lezcano | cc9a0f6 | 2012-02-28 22:46:06 +0100 | [diff] [blame] | 854 | #define PRCMU_GIC_NUMBER_REGS 5 |
| 855 | |
| 856 | /* |
| 857 | * This function checks if there are pending irq on the gic. It only |
| 858 | * makes sense if the gic has been decoupled before with the |
| 859 | * db8500_prcmu_gic_decouple function. Disabling an interrupt only |
| 860 | * disables the forwarding of the interrupt to any CPU interface. It |
| 861 | * does not prevent the interrupt from changing state, for example |
| 862 | * becoming pending, or active and pending if it is already |
| 863 | * active. Hence, we have to check the interrupt is pending *and* is |
| 864 | * active. |
| 865 | */ |
| 866 | bool db8500_prcmu_gic_pending_irq(void) |
| 867 | { |
| 868 | u32 pr; /* Pending register */ |
| 869 | u32 er; /* Enable register */ |
| 870 | void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE); |
| 871 | int i; |
| 872 | |
| 873 | /* 5 registers. STI & PPI not skipped */ |
| 874 | for (i = 0; i < PRCMU_GIC_NUMBER_REGS; i++) { |
| 875 | |
| 876 | pr = readl_relaxed(dist_base + GIC_DIST_PENDING_SET + i * 4); |
| 877 | er = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 878 | |
| 879 | if (pr & er) |
| 880 | return true; /* There is a pending interrupt */ |
| 881 | } |
| 882 | |
| 883 | return false; |
| 884 | } |
| 885 | |
Daniel Lezcano | 9f60d33 | 2012-02-28 22:46:07 +0100 | [diff] [blame] | 886 | /* |
Daniel Lezcano | 9ab492e | 2012-02-28 22:46:08 +0100 | [diff] [blame] | 887 | * This function checks if there are pending interrupt on the |
| 888 | * prcmu which has been delegated to monitor the irqs with the |
| 889 | * db8500_prcmu_copy_gic_settings function. |
| 890 | */ |
| 891 | bool db8500_prcmu_pending_irq(void) |
| 892 | { |
| 893 | u32 it, im; |
| 894 | int i; |
| 895 | |
| 896 | for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) { |
| 897 | it = readl(PRCM_ARMITVAL31TO0 + i * 4); |
| 898 | im = readl(PRCM_ARMITMSK31TO0 + i * 4); |
| 899 | if (it & im) |
| 900 | return true; /* There is a pending interrupt */ |
| 901 | } |
| 902 | |
| 903 | return false; |
| 904 | } |
| 905 | |
| 906 | /* |
Daniel Lezcano | 34fe6f1 | 2012-02-28 22:46:09 +0100 | [diff] [blame^] | 907 | * This function checks if the specified cpu is in in WFI. It's usage |
| 908 | * makes sense only if the gic is decoupled with the db8500_prcmu_gic_decouple |
| 909 | * function. Of course passing smp_processor_id() to this function will |
| 910 | * always return false... |
| 911 | */ |
| 912 | bool db8500_prcmu_is_cpu_in_wfi(int cpu) |
| 913 | { |
| 914 | return readl(PRCM_ARM_WFI_STANDBY) & cpu ? PRCM_ARM_WFI_STANDBY_WFI1 : |
| 915 | PRCM_ARM_WFI_STANDBY_WFI0; |
| 916 | } |
| 917 | |
| 918 | /* |
Daniel Lezcano | 9f60d33 | 2012-02-28 22:46:07 +0100 | [diff] [blame] | 919 | * This function copies the gic SPI settings to the prcmu in order to |
| 920 | * monitor them and abort/finish the retention/off sequence or state. |
| 921 | */ |
| 922 | int db8500_prcmu_copy_gic_settings(void) |
| 923 | { |
| 924 | u32 er; /* Enable register */ |
| 925 | void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE); |
| 926 | int i; |
| 927 | |
| 928 | /* We skip the STI and PPI */ |
| 929 | for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) { |
| 930 | er = readl_relaxed(dist_base + |
| 931 | GIC_DIST_ENABLE_SET + (i + 1) * 4); |
| 932 | writel(er, PRCM_ARMITMSK31TO0 + i * 4); |
| 933 | } |
| 934 | |
| 935 | return 0; |
| 936 | } |
| 937 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 938 | /* This function should only be called while mb0_transfer.lock is held. */ |
| 939 | static void config_wakeups(void) |
| 940 | { |
| 941 | const u8 header[2] = { |
| 942 | MB0H_CONFIG_WAKEUPS_EXE, |
| 943 | MB0H_CONFIG_WAKEUPS_SLEEP |
| 944 | }; |
| 945 | static u32 last_dbb_events; |
| 946 | static u32 last_abb_events; |
| 947 | u32 dbb_events; |
| 948 | u32 abb_events; |
| 949 | unsigned int i; |
| 950 | |
| 951 | dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups; |
| 952 | dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK); |
| 953 | |
| 954 | abb_events = mb0_transfer.req.abb_events; |
| 955 | |
| 956 | if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events)) |
| 957 | return; |
| 958 | |
| 959 | for (i = 0; i < 2; i++) { |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 960 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 961 | cpu_relax(); |
| 962 | writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500)); |
| 963 | writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500)); |
| 964 | writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0)); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 965 | writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 966 | } |
| 967 | last_dbb_events = dbb_events; |
| 968 | last_abb_events = abb_events; |
| 969 | } |
| 970 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 971 | void db8500_prcmu_enable_wakeups(u32 wakeups) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 972 | { |
| 973 | unsigned long flags; |
| 974 | u32 bits; |
| 975 | int i; |
| 976 | |
| 977 | BUG_ON(wakeups != (wakeups & VALID_WAKEUPS)); |
| 978 | |
| 979 | for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) { |
| 980 | if (wakeups & BIT(i)) |
| 981 | bits |= prcmu_wakeup_bit[i]; |
| 982 | } |
| 983 | |
| 984 | spin_lock_irqsave(&mb0_transfer.lock, flags); |
| 985 | |
| 986 | mb0_transfer.req.dbb_wakeups = bits; |
| 987 | config_wakeups(); |
| 988 | |
| 989 | spin_unlock_irqrestore(&mb0_transfer.lock, flags); |
| 990 | } |
| 991 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 992 | void db8500_prcmu_config_abb_event_readout(u32 abb_events) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 993 | { |
| 994 | unsigned long flags; |
| 995 | |
| 996 | spin_lock_irqsave(&mb0_transfer.lock, flags); |
| 997 | |
| 998 | mb0_transfer.req.abb_events = abb_events; |
| 999 | config_wakeups(); |
| 1000 | |
| 1001 | spin_unlock_irqrestore(&mb0_transfer.lock, flags); |
| 1002 | } |
| 1003 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1004 | void db8500_prcmu_get_abb_event_buffer(void __iomem **buf) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1005 | { |
| 1006 | if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1) |
| 1007 | *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500); |
| 1008 | else |
| 1009 | *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500); |
| 1010 | } |
| 1011 | |
| 1012 | /** |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1013 | * db8500_prcmu_set_arm_opp - set the appropriate ARM OPP |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1014 | * @opp: The new ARM operating point to which transition is to be made |
| 1015 | * Returns: 0 on success, non-zero on failure |
| 1016 | * |
| 1017 | * This function sets the the operating point of the ARM. |
| 1018 | */ |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1019 | int db8500_prcmu_set_arm_opp(u8 opp) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1020 | { |
| 1021 | int r; |
| 1022 | |
| 1023 | if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK) |
| 1024 | return -EINVAL; |
| 1025 | |
| 1026 | r = 0; |
| 1027 | |
| 1028 | mutex_lock(&mb1_transfer.lock); |
| 1029 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1030 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1031 | cpu_relax(); |
| 1032 | |
| 1033 | writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); |
| 1034 | writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP)); |
| 1035 | writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP)); |
| 1036 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1037 | writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1038 | wait_for_completion(&mb1_transfer.work); |
| 1039 | |
| 1040 | if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) || |
| 1041 | (mb1_transfer.ack.arm_opp != opp)) |
| 1042 | r = -EIO; |
| 1043 | |
| 1044 | mutex_unlock(&mb1_transfer.lock); |
| 1045 | |
| 1046 | return r; |
| 1047 | } |
| 1048 | |
| 1049 | /** |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1050 | * db8500_prcmu_get_arm_opp - get the current ARM OPP |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1051 | * |
| 1052 | * Returns: the current ARM OPP |
| 1053 | */ |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1054 | int db8500_prcmu_get_arm_opp(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1055 | { |
| 1056 | return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP); |
| 1057 | } |
| 1058 | |
| 1059 | /** |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1060 | * db8500_prcmu_get_ddr_opp - get the current DDR OPP |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1061 | * |
| 1062 | * Returns: the current DDR OPP |
| 1063 | */ |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1064 | int db8500_prcmu_get_ddr_opp(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1065 | { |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1066 | return readb(PRCM_DDR_SUBSYS_APE_MINBW); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /** |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1070 | * db8500_set_ddr_opp - set the appropriate DDR OPP |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1071 | * @opp: The new DDR operating point to which transition is to be made |
| 1072 | * Returns: 0 on success, non-zero on failure |
| 1073 | * |
| 1074 | * This function sets the operating point of the DDR. |
| 1075 | */ |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1076 | int db8500_prcmu_set_ddr_opp(u8 opp) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1077 | { |
| 1078 | if (opp < DDR_100_OPP || opp > DDR_25_OPP) |
| 1079 | return -EINVAL; |
| 1080 | /* Changing the DDR OPP can hang the hardware pre-v21 */ |
| 1081 | if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20()) |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1082 | writeb(opp, PRCM_DDR_SUBSYS_APE_MINBW); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1083 | |
| 1084 | return 0; |
| 1085 | } |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1086 | |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 1087 | /* Divide the frequency of certain clocks by 2 for APE_50_PARTLY_25_OPP. */ |
| 1088 | static void request_even_slower_clocks(bool enable) |
| 1089 | { |
| 1090 | void __iomem *clock_reg[] = { |
| 1091 | PRCM_ACLK_MGT, |
| 1092 | PRCM_DMACLK_MGT |
| 1093 | }; |
| 1094 | unsigned long flags; |
| 1095 | unsigned int i; |
| 1096 | |
| 1097 | spin_lock_irqsave(&clk_mgt_lock, flags); |
| 1098 | |
| 1099 | /* Grab the HW semaphore. */ |
| 1100 | while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) |
| 1101 | cpu_relax(); |
| 1102 | |
| 1103 | for (i = 0; i < ARRAY_SIZE(clock_reg); i++) { |
| 1104 | u32 val; |
| 1105 | u32 div; |
| 1106 | |
| 1107 | val = readl(clock_reg[i]); |
| 1108 | div = (val & PRCM_CLK_MGT_CLKPLLDIV_MASK); |
| 1109 | if (enable) { |
| 1110 | if ((div <= 1) || (div > 15)) { |
| 1111 | pr_err("prcmu: Bad clock divider %d in %s\n", |
| 1112 | div, __func__); |
| 1113 | goto unlock_and_return; |
| 1114 | } |
| 1115 | div <<= 1; |
| 1116 | } else { |
| 1117 | if (div <= 2) |
| 1118 | goto unlock_and_return; |
| 1119 | div >>= 1; |
| 1120 | } |
| 1121 | val = ((val & ~PRCM_CLK_MGT_CLKPLLDIV_MASK) | |
| 1122 | (div & PRCM_CLK_MGT_CLKPLLDIV_MASK)); |
| 1123 | writel(val, clock_reg[i]); |
| 1124 | } |
| 1125 | |
| 1126 | unlock_and_return: |
| 1127 | /* Release the HW semaphore. */ |
| 1128 | writel(0, PRCM_SEM); |
| 1129 | |
| 1130 | spin_unlock_irqrestore(&clk_mgt_lock, flags); |
| 1131 | } |
| 1132 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1133 | /** |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1134 | * db8500_set_ape_opp - set the appropriate APE OPP |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1135 | * @opp: The new APE operating point to which transition is to be made |
| 1136 | * Returns: 0 on success, non-zero on failure |
| 1137 | * |
| 1138 | * This function sets the operating point of the APE. |
| 1139 | */ |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1140 | int db8500_prcmu_set_ape_opp(u8 opp) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1141 | { |
| 1142 | int r = 0; |
| 1143 | |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 1144 | if (opp == mb1_transfer.ape_opp) |
| 1145 | return 0; |
| 1146 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1147 | mutex_lock(&mb1_transfer.lock); |
| 1148 | |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 1149 | if (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP) |
| 1150 | request_even_slower_clocks(false); |
| 1151 | |
| 1152 | if ((opp != APE_100_OPP) && (mb1_transfer.ape_opp != APE_100_OPP)) |
| 1153 | goto skip_message; |
| 1154 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1155 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1156 | cpu_relax(); |
| 1157 | |
| 1158 | writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); |
| 1159 | writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP)); |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 1160 | writeb(((opp == APE_50_PARTLY_25_OPP) ? APE_50_OPP : opp), |
| 1161 | (tcdm_base + PRCM_REQ_MB1_APE_OPP)); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1162 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1163 | writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1164 | wait_for_completion(&mb1_transfer.work); |
| 1165 | |
| 1166 | if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) || |
| 1167 | (mb1_transfer.ack.ape_opp != opp)) |
| 1168 | r = -EIO; |
| 1169 | |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 1170 | skip_message: |
| 1171 | if ((!r && (opp == APE_50_PARTLY_25_OPP)) || |
| 1172 | (r && (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP))) |
| 1173 | request_even_slower_clocks(true); |
| 1174 | if (!r) |
| 1175 | mb1_transfer.ape_opp = opp; |
| 1176 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1177 | mutex_unlock(&mb1_transfer.lock); |
| 1178 | |
| 1179 | return r; |
| 1180 | } |
| 1181 | |
| 1182 | /** |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1183 | * db8500_prcmu_get_ape_opp - get the current APE OPP |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1184 | * |
| 1185 | * Returns: the current APE OPP |
| 1186 | */ |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 1187 | int db8500_prcmu_get_ape_opp(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1188 | { |
| 1189 | return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP); |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage |
| 1194 | * @enable: true to request the higher voltage, false to drop a request. |
| 1195 | * |
| 1196 | * Calls to this function to enable and disable requests must be balanced. |
| 1197 | */ |
| 1198 | int prcmu_request_ape_opp_100_voltage(bool enable) |
| 1199 | { |
| 1200 | int r = 0; |
| 1201 | u8 header; |
| 1202 | static unsigned int requests; |
| 1203 | |
| 1204 | mutex_lock(&mb1_transfer.lock); |
| 1205 | |
| 1206 | if (enable) { |
| 1207 | if (0 != requests++) |
| 1208 | goto unlock_and_return; |
| 1209 | header = MB1H_REQUEST_APE_OPP_100_VOLT; |
| 1210 | } else { |
| 1211 | if (requests == 0) { |
| 1212 | r = -EIO; |
| 1213 | goto unlock_and_return; |
| 1214 | } else if (1 != requests--) { |
| 1215 | goto unlock_and_return; |
| 1216 | } |
| 1217 | header = MB1H_RELEASE_APE_OPP_100_VOLT; |
| 1218 | } |
| 1219 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1220 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1221 | cpu_relax(); |
| 1222 | |
| 1223 | writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); |
| 1224 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1225 | writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1226 | wait_for_completion(&mb1_transfer.work); |
| 1227 | |
| 1228 | if ((mb1_transfer.ack.header != header) || |
| 1229 | ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0)) |
| 1230 | r = -EIO; |
| 1231 | |
| 1232 | unlock_and_return: |
| 1233 | mutex_unlock(&mb1_transfer.lock); |
| 1234 | |
| 1235 | return r; |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup |
| 1240 | * |
| 1241 | * This function releases the power state requirements of a USB wakeup. |
| 1242 | */ |
| 1243 | int prcmu_release_usb_wakeup_state(void) |
| 1244 | { |
| 1245 | int r = 0; |
| 1246 | |
| 1247 | mutex_lock(&mb1_transfer.lock); |
| 1248 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1249 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1250 | cpu_relax(); |
| 1251 | |
| 1252 | writeb(MB1H_RELEASE_USB_WAKEUP, |
| 1253 | (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); |
| 1254 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1255 | writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1256 | wait_for_completion(&mb1_transfer.work); |
| 1257 | |
| 1258 | if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) || |
| 1259 | ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0)) |
| 1260 | r = -EIO; |
| 1261 | |
| 1262 | mutex_unlock(&mb1_transfer.lock); |
| 1263 | |
| 1264 | return r; |
| 1265 | } |
| 1266 | |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 1267 | static int request_pll(u8 clock, bool enable) |
| 1268 | { |
| 1269 | int r = 0; |
| 1270 | |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1271 | if (clock == PRCMU_PLLSOC0) |
| 1272 | clock = (enable ? PLL_SOC0_ON : PLL_SOC0_OFF); |
| 1273 | else if (clock == PRCMU_PLLSOC1) |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 1274 | clock = (enable ? PLL_SOC1_ON : PLL_SOC1_OFF); |
| 1275 | else |
| 1276 | return -EINVAL; |
| 1277 | |
| 1278 | mutex_lock(&mb1_transfer.lock); |
| 1279 | |
| 1280 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) |
| 1281 | cpu_relax(); |
| 1282 | |
| 1283 | writeb(MB1H_PLL_ON_OFF, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); |
| 1284 | writeb(clock, (tcdm_base + PRCM_REQ_MB1_PLL_ON_OFF)); |
| 1285 | |
| 1286 | writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET); |
| 1287 | wait_for_completion(&mb1_transfer.work); |
| 1288 | |
| 1289 | if (mb1_transfer.ack.header != MB1H_PLL_ON_OFF) |
| 1290 | r = -EIO; |
| 1291 | |
| 1292 | mutex_unlock(&mb1_transfer.lock); |
| 1293 | |
| 1294 | return r; |
| 1295 | } |
| 1296 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1297 | /** |
Bengt Jonsson | 0b9199e | 2011-08-12 10:28:25 +0200 | [diff] [blame] | 1298 | * prcmu_set_hwacc - set the power state of a h/w accelerator |
| 1299 | * @hwacc_dev: The hardware accelerator (enum hw_acc_dev). |
| 1300 | * @state: The new power state (enum hw_acc_state). |
| 1301 | * |
| 1302 | * This function sets the power state of a hardware accelerator. |
| 1303 | * This function should not be called from interrupt context. |
| 1304 | * |
| 1305 | * NOTE! Deprecated, to be removed when all users switched over to use the |
| 1306 | * regulator framework API. |
| 1307 | */ |
| 1308 | int prcmu_set_hwacc(u16 hwacc_dev, u8 state) |
| 1309 | { |
| 1310 | int r = 0; |
| 1311 | bool ram_retention = false; |
| 1312 | bool enable, enable_ret; |
| 1313 | |
| 1314 | /* check argument */ |
| 1315 | BUG_ON(hwacc_dev >= NUM_HW_ACC); |
| 1316 | |
| 1317 | /* get state of switches */ |
| 1318 | enable = hwacc_enabled[hwacc_dev]; |
| 1319 | enable_ret = hwacc_ret_enabled[hwacc_dev]; |
| 1320 | |
| 1321 | /* set flag if retention is possible */ |
| 1322 | switch (hwacc_dev) { |
| 1323 | case HW_ACC_SVAMMDSP: |
| 1324 | case HW_ACC_SIAMMDSP: |
| 1325 | case HW_ACC_ESRAM1: |
| 1326 | case HW_ACC_ESRAM2: |
| 1327 | case HW_ACC_ESRAM3: |
| 1328 | case HW_ACC_ESRAM4: |
| 1329 | ram_retention = true; |
| 1330 | break; |
| 1331 | } |
| 1332 | |
| 1333 | /* check argument */ |
| 1334 | BUG_ON(state > HW_ON); |
| 1335 | BUG_ON(state == HW_OFF_RAMRET && !ram_retention); |
| 1336 | |
| 1337 | /* modify enable flags */ |
| 1338 | switch (state) { |
| 1339 | case HW_OFF: |
| 1340 | enable_ret = false; |
| 1341 | enable = false; |
| 1342 | break; |
| 1343 | case HW_ON: |
| 1344 | enable = true; |
| 1345 | break; |
| 1346 | case HW_OFF_RAMRET: |
| 1347 | enable_ret = true; |
| 1348 | enable = false; |
| 1349 | break; |
| 1350 | } |
| 1351 | |
| 1352 | /* get regulator (lazy) */ |
| 1353 | if (hwacc_regulator[hwacc_dev] == NULL) { |
| 1354 | hwacc_regulator[hwacc_dev] = regulator_get(NULL, |
| 1355 | hwacc_regulator_name[hwacc_dev]); |
| 1356 | if (IS_ERR(hwacc_regulator[hwacc_dev])) { |
| 1357 | pr_err("prcmu: failed to get supply %s\n", |
| 1358 | hwacc_regulator_name[hwacc_dev]); |
| 1359 | r = PTR_ERR(hwacc_regulator[hwacc_dev]); |
| 1360 | goto out; |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | if (ram_retention) { |
| 1365 | if (hwacc_ret_regulator[hwacc_dev] == NULL) { |
| 1366 | hwacc_ret_regulator[hwacc_dev] = regulator_get(NULL, |
| 1367 | hwacc_ret_regulator_name[hwacc_dev]); |
| 1368 | if (IS_ERR(hwacc_ret_regulator[hwacc_dev])) { |
| 1369 | pr_err("prcmu: failed to get supply %s\n", |
| 1370 | hwacc_ret_regulator_name[hwacc_dev]); |
| 1371 | r = PTR_ERR(hwacc_ret_regulator[hwacc_dev]); |
| 1372 | goto out; |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | /* set regulators */ |
| 1378 | if (ram_retention) { |
| 1379 | if (enable_ret && !hwacc_ret_enabled[hwacc_dev]) { |
| 1380 | r = regulator_enable(hwacc_ret_regulator[hwacc_dev]); |
| 1381 | if (r < 0) { |
| 1382 | pr_err("prcmu_set_hwacc: ret enable failed\n"); |
| 1383 | goto out; |
| 1384 | } |
| 1385 | hwacc_ret_enabled[hwacc_dev] = true; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | if (enable && !hwacc_enabled[hwacc_dev]) { |
| 1390 | r = regulator_enable(hwacc_regulator[hwacc_dev]); |
| 1391 | if (r < 0) { |
| 1392 | pr_err("prcmu_set_hwacc: enable failed\n"); |
| 1393 | goto out; |
| 1394 | } |
| 1395 | hwacc_enabled[hwacc_dev] = true; |
| 1396 | } |
| 1397 | |
| 1398 | if (!enable && hwacc_enabled[hwacc_dev]) { |
| 1399 | r = regulator_disable(hwacc_regulator[hwacc_dev]); |
| 1400 | if (r < 0) { |
| 1401 | pr_err("prcmu_set_hwacc: disable failed\n"); |
| 1402 | goto out; |
| 1403 | } |
| 1404 | hwacc_enabled[hwacc_dev] = false; |
| 1405 | } |
| 1406 | |
| 1407 | if (ram_retention) { |
| 1408 | if (!enable_ret && hwacc_ret_enabled[hwacc_dev]) { |
| 1409 | r = regulator_disable(hwacc_ret_regulator[hwacc_dev]); |
| 1410 | if (r < 0) { |
| 1411 | pr_err("prcmu_set_hwacc: ret disable failed\n"); |
| 1412 | goto out; |
| 1413 | } |
| 1414 | hwacc_ret_enabled[hwacc_dev] = false; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | out: |
| 1419 | return r; |
| 1420 | } |
| 1421 | EXPORT_SYMBOL(prcmu_set_hwacc); |
| 1422 | |
| 1423 | /** |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1424 | * db8500_prcmu_set_epod - set the state of a EPOD (power domain) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1425 | * @epod_id: The EPOD to set |
| 1426 | * @epod_state: The new EPOD state |
| 1427 | * |
| 1428 | * This function sets the state of a EPOD (power domain). It may not be called |
| 1429 | * from interrupt context. |
| 1430 | */ |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1431 | int db8500_prcmu_set_epod(u16 epod_id, u8 epod_state) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1432 | { |
| 1433 | int r = 0; |
| 1434 | bool ram_retention = false; |
| 1435 | int i; |
| 1436 | |
| 1437 | /* check argument */ |
| 1438 | BUG_ON(epod_id >= NUM_EPOD_ID); |
| 1439 | |
| 1440 | /* set flag if retention is possible */ |
| 1441 | switch (epod_id) { |
| 1442 | case EPOD_ID_SVAMMDSP: |
| 1443 | case EPOD_ID_SIAMMDSP: |
| 1444 | case EPOD_ID_ESRAM12: |
| 1445 | case EPOD_ID_ESRAM34: |
| 1446 | ram_retention = true; |
| 1447 | break; |
| 1448 | } |
| 1449 | |
| 1450 | /* check argument */ |
| 1451 | BUG_ON(epod_state > EPOD_STATE_ON); |
| 1452 | BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention); |
| 1453 | |
| 1454 | /* get lock */ |
| 1455 | mutex_lock(&mb2_transfer.lock); |
| 1456 | |
| 1457 | /* wait for mailbox */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1458 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(2)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1459 | cpu_relax(); |
| 1460 | |
| 1461 | /* fill in mailbox */ |
| 1462 | for (i = 0; i < NUM_EPOD_ID; i++) |
| 1463 | writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i)); |
| 1464 | writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id)); |
| 1465 | |
| 1466 | writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2)); |
| 1467 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1468 | writel(MBOX_BIT(2), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1469 | |
| 1470 | /* |
| 1471 | * The current firmware version does not handle errors correctly, |
| 1472 | * and we cannot recover if there is an error. |
| 1473 | * This is expected to change when the firmware is updated. |
| 1474 | */ |
| 1475 | if (!wait_for_completion_timeout(&mb2_transfer.work, |
| 1476 | msecs_to_jiffies(20000))) { |
| 1477 | pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n", |
| 1478 | __func__); |
| 1479 | r = -EIO; |
| 1480 | goto unlock_and_return; |
| 1481 | } |
| 1482 | |
| 1483 | if (mb2_transfer.ack.status != HWACC_PWR_ST_OK) |
| 1484 | r = -EIO; |
| 1485 | |
| 1486 | unlock_and_return: |
| 1487 | mutex_unlock(&mb2_transfer.lock); |
| 1488 | return r; |
| 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * prcmu_configure_auto_pm - Configure autonomous power management. |
| 1493 | * @sleep: Configuration for ApSleep. |
| 1494 | * @idle: Configuration for ApIdle. |
| 1495 | */ |
| 1496 | void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep, |
| 1497 | struct prcmu_auto_pm_config *idle) |
| 1498 | { |
| 1499 | u32 sleep_cfg; |
| 1500 | u32 idle_cfg; |
| 1501 | unsigned long flags; |
| 1502 | |
| 1503 | BUG_ON((sleep == NULL) || (idle == NULL)); |
| 1504 | |
| 1505 | sleep_cfg = (sleep->sva_auto_pm_enable & 0xF); |
| 1506 | sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF)); |
| 1507 | sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF)); |
| 1508 | sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF)); |
| 1509 | sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF)); |
| 1510 | sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF)); |
| 1511 | |
| 1512 | idle_cfg = (idle->sva_auto_pm_enable & 0xF); |
| 1513 | idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF)); |
| 1514 | idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF)); |
| 1515 | idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF)); |
| 1516 | idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF)); |
| 1517 | idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF)); |
| 1518 | |
| 1519 | spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags); |
| 1520 | |
| 1521 | /* |
| 1522 | * The autonomous power management configuration is done through |
| 1523 | * fields in mailbox 2, but these fields are only used as shared |
| 1524 | * variables - i.e. there is no need to send a message. |
| 1525 | */ |
| 1526 | writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP)); |
| 1527 | writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE)); |
| 1528 | |
| 1529 | mb2_transfer.auto_pm_enabled = |
| 1530 | ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) || |
| 1531 | (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) || |
| 1532 | (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) || |
| 1533 | (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON)); |
| 1534 | |
| 1535 | spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags); |
| 1536 | } |
| 1537 | EXPORT_SYMBOL(prcmu_configure_auto_pm); |
| 1538 | |
| 1539 | bool prcmu_is_auto_pm_enabled(void) |
| 1540 | { |
| 1541 | return mb2_transfer.auto_pm_enabled; |
| 1542 | } |
| 1543 | |
| 1544 | static int request_sysclk(bool enable) |
| 1545 | { |
| 1546 | int r; |
| 1547 | unsigned long flags; |
| 1548 | |
| 1549 | r = 0; |
| 1550 | |
| 1551 | mutex_lock(&mb3_transfer.sysclk_lock); |
| 1552 | |
| 1553 | spin_lock_irqsave(&mb3_transfer.lock, flags); |
| 1554 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1555 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(3)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1556 | cpu_relax(); |
| 1557 | |
| 1558 | writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT)); |
| 1559 | |
| 1560 | writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3)); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1561 | writel(MBOX_BIT(3), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1562 | |
| 1563 | spin_unlock_irqrestore(&mb3_transfer.lock, flags); |
| 1564 | |
| 1565 | /* |
| 1566 | * The firmware only sends an ACK if we want to enable the |
| 1567 | * SysClk, and it succeeds. |
| 1568 | */ |
| 1569 | if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work, |
| 1570 | msecs_to_jiffies(20000))) { |
| 1571 | pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n", |
| 1572 | __func__); |
| 1573 | r = -EIO; |
| 1574 | } |
| 1575 | |
| 1576 | mutex_unlock(&mb3_transfer.sysclk_lock); |
| 1577 | |
| 1578 | return r; |
| 1579 | } |
| 1580 | |
| 1581 | static int request_timclk(bool enable) |
| 1582 | { |
| 1583 | u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK); |
| 1584 | |
| 1585 | if (!enable) |
| 1586 | val |= PRCM_TCR_STOP_TIMERS; |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1587 | writel(val, PRCM_TCR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1588 | |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1592 | static int request_clock(u8 clock, bool enable) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1593 | { |
| 1594 | u32 val; |
| 1595 | unsigned long flags; |
| 1596 | |
| 1597 | spin_lock_irqsave(&clk_mgt_lock, flags); |
| 1598 | |
| 1599 | /* Grab the HW semaphore. */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1600 | while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1601 | cpu_relax(); |
| 1602 | |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1603 | val = readl(clk_mgt[clock].reg); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1604 | if (enable) { |
| 1605 | val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw); |
| 1606 | } else { |
| 1607 | clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK); |
| 1608 | val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK); |
| 1609 | } |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1610 | writel(val, clk_mgt[clock].reg); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1611 | |
| 1612 | /* Release the HW semaphore. */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 1613 | writel(0, PRCM_SEM); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1614 | |
| 1615 | spin_unlock_irqrestore(&clk_mgt_lock, flags); |
| 1616 | |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 1620 | static int request_sga_clock(u8 clock, bool enable) |
| 1621 | { |
| 1622 | u32 val; |
| 1623 | int ret; |
| 1624 | |
| 1625 | if (enable) { |
| 1626 | val = readl(PRCM_CGATING_BYPASS); |
| 1627 | writel(val | PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS); |
| 1628 | } |
| 1629 | |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1630 | ret = request_clock(clock, enable); |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 1631 | |
| 1632 | if (!ret && !enable) { |
| 1633 | val = readl(PRCM_CGATING_BYPASS); |
| 1634 | writel(val & ~PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS); |
| 1635 | } |
| 1636 | |
| 1637 | return ret; |
| 1638 | } |
| 1639 | |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1640 | static inline bool plldsi_locked(void) |
| 1641 | { |
| 1642 | return (readl(PRCM_PLLDSI_LOCKP) & |
| 1643 | (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 | |
| 1644 | PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3)) == |
| 1645 | (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 | |
| 1646 | PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3); |
| 1647 | } |
| 1648 | |
| 1649 | static int request_plldsi(bool enable) |
| 1650 | { |
| 1651 | int r = 0; |
| 1652 | u32 val; |
| 1653 | |
| 1654 | writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP | |
| 1655 | PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI), (enable ? |
| 1656 | PRCM_MMIP_LS_CLAMP_CLR : PRCM_MMIP_LS_CLAMP_SET)); |
| 1657 | |
| 1658 | val = readl(PRCM_PLLDSI_ENABLE); |
| 1659 | if (enable) |
| 1660 | val |= PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE; |
| 1661 | else |
| 1662 | val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE; |
| 1663 | writel(val, PRCM_PLLDSI_ENABLE); |
| 1664 | |
| 1665 | if (enable) { |
| 1666 | unsigned int i; |
| 1667 | bool locked = plldsi_locked(); |
| 1668 | |
| 1669 | for (i = 10; !locked && (i > 0); --i) { |
| 1670 | udelay(100); |
| 1671 | locked = plldsi_locked(); |
| 1672 | } |
| 1673 | if (locked) { |
| 1674 | writel(PRCM_APE_RESETN_DSIPLL_RESETN, |
| 1675 | PRCM_APE_RESETN_SET); |
| 1676 | } else { |
| 1677 | writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP | |
| 1678 | PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI), |
| 1679 | PRCM_MMIP_LS_CLAMP_SET); |
| 1680 | val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE; |
| 1681 | writel(val, PRCM_PLLDSI_ENABLE); |
| 1682 | r = -EAGAIN; |
| 1683 | } |
| 1684 | } else { |
| 1685 | writel(PRCM_APE_RESETN_DSIPLL_RESETN, PRCM_APE_RESETN_CLR); |
| 1686 | } |
| 1687 | return r; |
| 1688 | } |
| 1689 | |
| 1690 | static int request_dsiclk(u8 n, bool enable) |
| 1691 | { |
| 1692 | u32 val; |
| 1693 | |
| 1694 | val = readl(PRCM_DSI_PLLOUT_SEL); |
| 1695 | val &= ~dsiclk[n].divsel_mask; |
| 1696 | val |= ((enable ? dsiclk[n].divsel : PRCM_DSI_PLLOUT_SEL_OFF) << |
| 1697 | dsiclk[n].divsel_shift); |
| 1698 | writel(val, PRCM_DSI_PLLOUT_SEL); |
| 1699 | return 0; |
| 1700 | } |
| 1701 | |
| 1702 | static int request_dsiescclk(u8 n, bool enable) |
| 1703 | { |
| 1704 | u32 val; |
| 1705 | |
| 1706 | val = readl(PRCM_DSITVCLK_DIV); |
| 1707 | enable ? (val |= dsiescclk[n].en) : (val &= ~dsiescclk[n].en); |
| 1708 | writel(val, PRCM_DSITVCLK_DIV); |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1712 | /** |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1713 | * db8500_prcmu_request_clock() - Request for a clock to be enabled or disabled. |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1714 | * @clock: The clock for which the request is made. |
| 1715 | * @enable: Whether the clock should be enabled (true) or disabled (false). |
| 1716 | * |
| 1717 | * This function should only be used by the clock implementation. |
| 1718 | * Do not use it from any other place! |
| 1719 | */ |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 1720 | int db8500_prcmu_request_clock(u8 clock, bool enable) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1721 | { |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1722 | if (clock == PRCMU_SGACLK) |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 1723 | return request_sga_clock(clock, enable); |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1724 | else if (clock < PRCMU_NUM_REG_CLOCKS) |
| 1725 | return request_clock(clock, enable); |
| 1726 | else if (clock == PRCMU_TIMCLK) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1727 | return request_timclk(enable); |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1728 | else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK)) |
| 1729 | return request_dsiclk((clock - PRCMU_DSI0CLK), enable); |
| 1730 | else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK)) |
| 1731 | return request_dsiescclk((clock - PRCMU_DSI0ESCCLK), enable); |
| 1732 | else if (clock == PRCMU_PLLDSI) |
| 1733 | return request_plldsi(enable); |
| 1734 | else if (clock == PRCMU_SYSCLK) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 1735 | return request_sysclk(enable); |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1736 | else if ((clock == PRCMU_PLLSOC0) || (clock == PRCMU_PLLSOC1)) |
Mattias Nilsson | 0837bb7 | 2011-08-12 10:28:18 +0200 | [diff] [blame] | 1737 | return request_pll(clock, enable); |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1738 | else |
| 1739 | return -EINVAL; |
| 1740 | } |
| 1741 | |
| 1742 | static unsigned long pll_rate(void __iomem *reg, unsigned long src_rate, |
| 1743 | int branch) |
| 1744 | { |
| 1745 | u64 rate; |
| 1746 | u32 val; |
| 1747 | u32 d; |
| 1748 | u32 div = 1; |
| 1749 | |
| 1750 | val = readl(reg); |
| 1751 | |
| 1752 | rate = src_rate; |
| 1753 | rate *= ((val & PRCM_PLL_FREQ_D_MASK) >> PRCM_PLL_FREQ_D_SHIFT); |
| 1754 | |
| 1755 | d = ((val & PRCM_PLL_FREQ_N_MASK) >> PRCM_PLL_FREQ_N_SHIFT); |
| 1756 | if (d > 1) |
| 1757 | div *= d; |
| 1758 | |
| 1759 | d = ((val & PRCM_PLL_FREQ_R_MASK) >> PRCM_PLL_FREQ_R_SHIFT); |
| 1760 | if (d > 1) |
| 1761 | div *= d; |
| 1762 | |
| 1763 | if (val & PRCM_PLL_FREQ_SELDIV2) |
| 1764 | div *= 2; |
| 1765 | |
| 1766 | if ((branch == PLL_FIX) || ((branch == PLL_DIV) && |
| 1767 | (val & PRCM_PLL_FREQ_DIV2EN) && |
| 1768 | ((reg == PRCM_PLLSOC0_FREQ) || |
| 1769 | (reg == PRCM_PLLDDR_FREQ)))) |
| 1770 | div *= 2; |
| 1771 | |
| 1772 | (void)do_div(rate, div); |
| 1773 | |
| 1774 | return (unsigned long)rate; |
| 1775 | } |
| 1776 | |
| 1777 | #define ROOT_CLOCK_RATE 38400000 |
| 1778 | |
| 1779 | static unsigned long clock_rate(u8 clock) |
| 1780 | { |
| 1781 | u32 val; |
| 1782 | u32 pllsw; |
| 1783 | unsigned long rate = ROOT_CLOCK_RATE; |
| 1784 | |
| 1785 | val = readl(clk_mgt[clock].reg); |
| 1786 | |
| 1787 | if (val & PRCM_CLK_MGT_CLK38) { |
| 1788 | if (clk_mgt[clock].clk38div && (val & PRCM_CLK_MGT_CLK38DIV)) |
| 1789 | rate /= 2; |
| 1790 | return rate; |
Linus Walleij | e62ccf3 | 2011-10-10 12:14:14 +0200 | [diff] [blame] | 1791 | } |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1792 | |
| 1793 | val |= clk_mgt[clock].pllsw; |
| 1794 | pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK); |
| 1795 | |
| 1796 | if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC0) |
| 1797 | rate = pll_rate(PRCM_PLLSOC0_FREQ, rate, clk_mgt[clock].branch); |
| 1798 | else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC1) |
| 1799 | rate = pll_rate(PRCM_PLLSOC1_FREQ, rate, clk_mgt[clock].branch); |
| 1800 | else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_DDR) |
| 1801 | rate = pll_rate(PRCM_PLLDDR_FREQ, rate, clk_mgt[clock].branch); |
| 1802 | else |
| 1803 | return 0; |
| 1804 | |
| 1805 | if ((clock == PRCMU_SGACLK) && |
| 1806 | (val & PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN)) { |
| 1807 | u64 r = (rate * 10); |
| 1808 | |
| 1809 | (void)do_div(r, 25); |
| 1810 | return (unsigned long)r; |
| 1811 | } |
| 1812 | val &= PRCM_CLK_MGT_CLKPLLDIV_MASK; |
| 1813 | if (val) |
| 1814 | return rate / val; |
| 1815 | else |
| 1816 | return 0; |
| 1817 | } |
| 1818 | |
| 1819 | static unsigned long dsiclk_rate(u8 n) |
| 1820 | { |
| 1821 | u32 divsel; |
| 1822 | u32 div = 1; |
| 1823 | |
| 1824 | divsel = readl(PRCM_DSI_PLLOUT_SEL); |
| 1825 | divsel = ((divsel & dsiclk[n].divsel_mask) >> dsiclk[n].divsel_shift); |
| 1826 | |
| 1827 | if (divsel == PRCM_DSI_PLLOUT_SEL_OFF) |
| 1828 | divsel = dsiclk[n].divsel; |
| 1829 | |
| 1830 | switch (divsel) { |
| 1831 | case PRCM_DSI_PLLOUT_SEL_PHI_4: |
| 1832 | div *= 2; |
| 1833 | case PRCM_DSI_PLLOUT_SEL_PHI_2: |
| 1834 | div *= 2; |
| 1835 | case PRCM_DSI_PLLOUT_SEL_PHI: |
| 1836 | return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK), |
| 1837 | PLL_RAW) / div; |
| 1838 | default: |
| 1839 | return 0; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | static unsigned long dsiescclk_rate(u8 n) |
| 1844 | { |
| 1845 | u32 div; |
| 1846 | |
| 1847 | div = readl(PRCM_DSITVCLK_DIV); |
| 1848 | div = ((div & dsiescclk[n].div_mask) >> (dsiescclk[n].div_shift)); |
| 1849 | return clock_rate(PRCMU_TVCLK) / max((u32)1, div); |
| 1850 | } |
| 1851 | |
| 1852 | unsigned long prcmu_clock_rate(u8 clock) |
| 1853 | { |
Linus Walleij | e62ccf3 | 2011-10-10 12:14:14 +0200 | [diff] [blame] | 1854 | if (clock < PRCMU_NUM_REG_CLOCKS) |
Mattias Nilsson | 6b6fae2 | 2012-01-13 16:20:28 +0100 | [diff] [blame] | 1855 | return clock_rate(clock); |
| 1856 | else if (clock == PRCMU_TIMCLK) |
| 1857 | return ROOT_CLOCK_RATE / 16; |
| 1858 | else if (clock == PRCMU_SYSCLK) |
| 1859 | return ROOT_CLOCK_RATE; |
| 1860 | else if (clock == PRCMU_PLLSOC0) |
| 1861 | return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, PLL_RAW); |
| 1862 | else if (clock == PRCMU_PLLSOC1) |
| 1863 | return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, PLL_RAW); |
| 1864 | else if (clock == PRCMU_PLLDDR) |
| 1865 | return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, PLL_RAW); |
| 1866 | else if (clock == PRCMU_PLLDSI) |
| 1867 | return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK), |
| 1868 | PLL_RAW); |
| 1869 | else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK)) |
| 1870 | return dsiclk_rate(clock - PRCMU_DSI0CLK); |
| 1871 | else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK)) |
| 1872 | return dsiescclk_rate(clock - PRCMU_DSI0ESCCLK); |
| 1873 | else |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | static unsigned long clock_source_rate(u32 clk_mgt_val, int branch) |
| 1878 | { |
| 1879 | if (clk_mgt_val & PRCM_CLK_MGT_CLK38) |
| 1880 | return ROOT_CLOCK_RATE; |
| 1881 | clk_mgt_val &= PRCM_CLK_MGT_CLKPLLSW_MASK; |
| 1882 | if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC0) |
| 1883 | return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, branch); |
| 1884 | else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC1) |
| 1885 | return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, branch); |
| 1886 | else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_DDR) |
| 1887 | return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, branch); |
| 1888 | else |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | static u32 clock_divider(unsigned long src_rate, unsigned long rate) |
| 1893 | { |
| 1894 | u32 div; |
| 1895 | |
| 1896 | div = (src_rate / rate); |
| 1897 | if (div == 0) |
| 1898 | return 1; |
| 1899 | if (rate < (src_rate / div)) |
| 1900 | div++; |
| 1901 | return div; |
| 1902 | } |
| 1903 | |
| 1904 | static long round_clock_rate(u8 clock, unsigned long rate) |
| 1905 | { |
| 1906 | u32 val; |
| 1907 | u32 div; |
| 1908 | unsigned long src_rate; |
| 1909 | long rounded_rate; |
| 1910 | |
| 1911 | val = readl(clk_mgt[clock].reg); |
| 1912 | src_rate = clock_source_rate((val | clk_mgt[clock].pllsw), |
| 1913 | clk_mgt[clock].branch); |
| 1914 | div = clock_divider(src_rate, rate); |
| 1915 | if (val & PRCM_CLK_MGT_CLK38) { |
| 1916 | if (clk_mgt[clock].clk38div) { |
| 1917 | if (div > 2) |
| 1918 | div = 2; |
| 1919 | } else { |
| 1920 | div = 1; |
| 1921 | } |
| 1922 | } else if ((clock == PRCMU_SGACLK) && (div == 3)) { |
| 1923 | u64 r = (src_rate * 10); |
| 1924 | |
| 1925 | (void)do_div(r, 25); |
| 1926 | if (r <= rate) |
| 1927 | return (unsigned long)r; |
| 1928 | } |
| 1929 | rounded_rate = (src_rate / min(div, (u32)31)); |
| 1930 | |
| 1931 | return rounded_rate; |
| 1932 | } |
| 1933 | |
| 1934 | #define MIN_PLL_VCO_RATE 600000000ULL |
| 1935 | #define MAX_PLL_VCO_RATE 1680640000ULL |
| 1936 | |
| 1937 | static long round_plldsi_rate(unsigned long rate) |
| 1938 | { |
| 1939 | long rounded_rate = 0; |
| 1940 | unsigned long src_rate; |
| 1941 | unsigned long rem; |
| 1942 | u32 r; |
| 1943 | |
| 1944 | src_rate = clock_rate(PRCMU_HDMICLK); |
| 1945 | rem = rate; |
| 1946 | |
| 1947 | for (r = 7; (rem > 0) && (r > 0); r--) { |
| 1948 | u64 d; |
| 1949 | |
| 1950 | d = (r * rate); |
| 1951 | (void)do_div(d, src_rate); |
| 1952 | if (d < 6) |
| 1953 | d = 6; |
| 1954 | else if (d > 255) |
| 1955 | d = 255; |
| 1956 | d *= src_rate; |
| 1957 | if (((2 * d) < (r * MIN_PLL_VCO_RATE)) || |
| 1958 | ((r * MAX_PLL_VCO_RATE) < (2 * d))) |
| 1959 | continue; |
| 1960 | (void)do_div(d, r); |
| 1961 | if (rate < d) { |
| 1962 | if (rounded_rate == 0) |
| 1963 | rounded_rate = (long)d; |
| 1964 | break; |
| 1965 | } |
| 1966 | if ((rate - d) < rem) { |
| 1967 | rem = (rate - d); |
| 1968 | rounded_rate = (long)d; |
| 1969 | } |
| 1970 | } |
| 1971 | return rounded_rate; |
| 1972 | } |
| 1973 | |
| 1974 | static long round_dsiclk_rate(unsigned long rate) |
| 1975 | { |
| 1976 | u32 div; |
| 1977 | unsigned long src_rate; |
| 1978 | long rounded_rate; |
| 1979 | |
| 1980 | src_rate = pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK), |
| 1981 | PLL_RAW); |
| 1982 | div = clock_divider(src_rate, rate); |
| 1983 | rounded_rate = (src_rate / ((div > 2) ? 4 : div)); |
| 1984 | |
| 1985 | return rounded_rate; |
| 1986 | } |
| 1987 | |
| 1988 | static long round_dsiescclk_rate(unsigned long rate) |
| 1989 | { |
| 1990 | u32 div; |
| 1991 | unsigned long src_rate; |
| 1992 | long rounded_rate; |
| 1993 | |
| 1994 | src_rate = clock_rate(PRCMU_TVCLK); |
| 1995 | div = clock_divider(src_rate, rate); |
| 1996 | rounded_rate = (src_rate / min(div, (u32)255)); |
| 1997 | |
| 1998 | return rounded_rate; |
| 1999 | } |
| 2000 | |
| 2001 | long prcmu_round_clock_rate(u8 clock, unsigned long rate) |
| 2002 | { |
| 2003 | if (clock < PRCMU_NUM_REG_CLOCKS) |
| 2004 | return round_clock_rate(clock, rate); |
| 2005 | else if (clock == PRCMU_PLLDSI) |
| 2006 | return round_plldsi_rate(rate); |
| 2007 | else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK)) |
| 2008 | return round_dsiclk_rate(rate); |
| 2009 | else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK)) |
| 2010 | return round_dsiescclk_rate(rate); |
| 2011 | else |
| 2012 | return (long)prcmu_clock_rate(clock); |
| 2013 | } |
| 2014 | |
| 2015 | static void set_clock_rate(u8 clock, unsigned long rate) |
| 2016 | { |
| 2017 | u32 val; |
| 2018 | u32 div; |
| 2019 | unsigned long src_rate; |
| 2020 | unsigned long flags; |
| 2021 | |
| 2022 | spin_lock_irqsave(&clk_mgt_lock, flags); |
| 2023 | |
| 2024 | /* Grab the HW semaphore. */ |
| 2025 | while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) |
| 2026 | cpu_relax(); |
| 2027 | |
| 2028 | val = readl(clk_mgt[clock].reg); |
| 2029 | src_rate = clock_source_rate((val | clk_mgt[clock].pllsw), |
| 2030 | clk_mgt[clock].branch); |
| 2031 | div = clock_divider(src_rate, rate); |
| 2032 | if (val & PRCM_CLK_MGT_CLK38) { |
| 2033 | if (clk_mgt[clock].clk38div) { |
| 2034 | if (div > 1) |
| 2035 | val |= PRCM_CLK_MGT_CLK38DIV; |
| 2036 | else |
| 2037 | val &= ~PRCM_CLK_MGT_CLK38DIV; |
| 2038 | } |
| 2039 | } else if (clock == PRCMU_SGACLK) { |
| 2040 | val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK | |
| 2041 | PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN); |
| 2042 | if (div == 3) { |
| 2043 | u64 r = (src_rate * 10); |
| 2044 | |
| 2045 | (void)do_div(r, 25); |
| 2046 | if (r <= rate) { |
| 2047 | val |= PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN; |
| 2048 | div = 0; |
| 2049 | } |
| 2050 | } |
| 2051 | val |= min(div, (u32)31); |
| 2052 | } else { |
| 2053 | val &= ~PRCM_CLK_MGT_CLKPLLDIV_MASK; |
| 2054 | val |= min(div, (u32)31); |
| 2055 | } |
| 2056 | writel(val, clk_mgt[clock].reg); |
| 2057 | |
| 2058 | /* Release the HW semaphore. */ |
| 2059 | writel(0, PRCM_SEM); |
| 2060 | |
| 2061 | spin_unlock_irqrestore(&clk_mgt_lock, flags); |
| 2062 | } |
| 2063 | |
| 2064 | static int set_plldsi_rate(unsigned long rate) |
| 2065 | { |
| 2066 | unsigned long src_rate; |
| 2067 | unsigned long rem; |
| 2068 | u32 pll_freq = 0; |
| 2069 | u32 r; |
| 2070 | |
| 2071 | src_rate = clock_rate(PRCMU_HDMICLK); |
| 2072 | rem = rate; |
| 2073 | |
| 2074 | for (r = 7; (rem > 0) && (r > 0); r--) { |
| 2075 | u64 d; |
| 2076 | u64 hwrate; |
| 2077 | |
| 2078 | d = (r * rate); |
| 2079 | (void)do_div(d, src_rate); |
| 2080 | if (d < 6) |
| 2081 | d = 6; |
| 2082 | else if (d > 255) |
| 2083 | d = 255; |
| 2084 | hwrate = (d * src_rate); |
| 2085 | if (((2 * hwrate) < (r * MIN_PLL_VCO_RATE)) || |
| 2086 | ((r * MAX_PLL_VCO_RATE) < (2 * hwrate))) |
| 2087 | continue; |
| 2088 | (void)do_div(hwrate, r); |
| 2089 | if (rate < hwrate) { |
| 2090 | if (pll_freq == 0) |
| 2091 | pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) | |
| 2092 | (r << PRCM_PLL_FREQ_R_SHIFT)); |
| 2093 | break; |
| 2094 | } |
| 2095 | if ((rate - hwrate) < rem) { |
| 2096 | rem = (rate - hwrate); |
| 2097 | pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) | |
| 2098 | (r << PRCM_PLL_FREQ_R_SHIFT)); |
| 2099 | } |
| 2100 | } |
| 2101 | if (pll_freq == 0) |
| 2102 | return -EINVAL; |
| 2103 | |
| 2104 | pll_freq |= (1 << PRCM_PLL_FREQ_N_SHIFT); |
| 2105 | writel(pll_freq, PRCM_PLLDSI_FREQ); |
| 2106 | |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | static void set_dsiclk_rate(u8 n, unsigned long rate) |
| 2111 | { |
| 2112 | u32 val; |
| 2113 | u32 div; |
| 2114 | |
| 2115 | div = clock_divider(pll_rate(PRCM_PLLDSI_FREQ, |
| 2116 | clock_rate(PRCMU_HDMICLK), PLL_RAW), rate); |
| 2117 | |
| 2118 | dsiclk[n].divsel = (div == 1) ? PRCM_DSI_PLLOUT_SEL_PHI : |
| 2119 | (div == 2) ? PRCM_DSI_PLLOUT_SEL_PHI_2 : |
| 2120 | /* else */ PRCM_DSI_PLLOUT_SEL_PHI_4; |
| 2121 | |
| 2122 | val = readl(PRCM_DSI_PLLOUT_SEL); |
| 2123 | val &= ~dsiclk[n].divsel_mask; |
| 2124 | val |= (dsiclk[n].divsel << dsiclk[n].divsel_shift); |
| 2125 | writel(val, PRCM_DSI_PLLOUT_SEL); |
| 2126 | } |
| 2127 | |
| 2128 | static void set_dsiescclk_rate(u8 n, unsigned long rate) |
| 2129 | { |
| 2130 | u32 val; |
| 2131 | u32 div; |
| 2132 | |
| 2133 | div = clock_divider(clock_rate(PRCMU_TVCLK), rate); |
| 2134 | val = readl(PRCM_DSITVCLK_DIV); |
| 2135 | val &= ~dsiescclk[n].div_mask; |
| 2136 | val |= (min(div, (u32)255) << dsiescclk[n].div_shift); |
| 2137 | writel(val, PRCM_DSITVCLK_DIV); |
| 2138 | } |
| 2139 | |
| 2140 | int prcmu_set_clock_rate(u8 clock, unsigned long rate) |
| 2141 | { |
| 2142 | if (clock < PRCMU_NUM_REG_CLOCKS) |
| 2143 | set_clock_rate(clock, rate); |
| 2144 | else if (clock == PRCMU_PLLDSI) |
| 2145 | return set_plldsi_rate(rate); |
| 2146 | else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK)) |
| 2147 | set_dsiclk_rate((clock - PRCMU_DSI0CLK), rate); |
| 2148 | else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK)) |
| 2149 | set_dsiescclk_rate((clock - PRCMU_DSI0ESCCLK), rate); |
| 2150 | return 0; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2151 | } |
| 2152 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 2153 | int db8500_prcmu_config_esram0_deep_sleep(u8 state) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2154 | { |
| 2155 | if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) || |
| 2156 | (state < ESRAM0_DEEP_SLEEP_STATE_OFF)) |
| 2157 | return -EINVAL; |
| 2158 | |
| 2159 | mutex_lock(&mb4_transfer.lock); |
| 2160 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2161 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2162 | cpu_relax(); |
| 2163 | |
| 2164 | writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); |
| 2165 | writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON), |
| 2166 | (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE)); |
| 2167 | writeb(DDR_PWR_STATE_ON, |
| 2168 | (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE)); |
| 2169 | writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST)); |
| 2170 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2171 | writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2172 | wait_for_completion(&mb4_transfer.work); |
| 2173 | |
| 2174 | mutex_unlock(&mb4_transfer.lock); |
| 2175 | |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2179 | int db8500_prcmu_config_hotdog(u8 threshold) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2180 | { |
| 2181 | mutex_lock(&mb4_transfer.lock); |
| 2182 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2183 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2184 | cpu_relax(); |
| 2185 | |
| 2186 | writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD)); |
| 2187 | writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); |
| 2188 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2189 | writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2190 | wait_for_completion(&mb4_transfer.work); |
| 2191 | |
| 2192 | mutex_unlock(&mb4_transfer.lock); |
| 2193 | |
| 2194 | return 0; |
| 2195 | } |
| 2196 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2197 | int db8500_prcmu_config_hotmon(u8 low, u8 high) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2198 | { |
| 2199 | mutex_lock(&mb4_transfer.lock); |
| 2200 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2201 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2202 | cpu_relax(); |
| 2203 | |
| 2204 | writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW)); |
| 2205 | writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH)); |
| 2206 | writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH), |
| 2207 | (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG)); |
| 2208 | writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); |
| 2209 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2210 | writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2211 | wait_for_completion(&mb4_transfer.work); |
| 2212 | |
| 2213 | mutex_unlock(&mb4_transfer.lock); |
| 2214 | |
| 2215 | return 0; |
| 2216 | } |
| 2217 | |
| 2218 | static int config_hot_period(u16 val) |
| 2219 | { |
| 2220 | mutex_lock(&mb4_transfer.lock); |
| 2221 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2222 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2223 | cpu_relax(); |
| 2224 | |
| 2225 | writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD)); |
| 2226 | writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); |
| 2227 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2228 | writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2229 | wait_for_completion(&mb4_transfer.work); |
| 2230 | |
| 2231 | mutex_unlock(&mb4_transfer.lock); |
| 2232 | |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2236 | int db8500_prcmu_start_temp_sense(u16 cycles32k) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2237 | { |
| 2238 | if (cycles32k == 0xFFFF) |
| 2239 | return -EINVAL; |
| 2240 | |
| 2241 | return config_hot_period(cycles32k); |
| 2242 | } |
| 2243 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2244 | int db8500_prcmu_stop_temp_sense(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2245 | { |
| 2246 | return config_hot_period(0xFFFF); |
| 2247 | } |
| 2248 | |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2249 | static int prcmu_a9wdog(u8 cmd, u8 d0, u8 d1, u8 d2, u8 d3) |
| 2250 | { |
| 2251 | |
| 2252 | mutex_lock(&mb4_transfer.lock); |
| 2253 | |
| 2254 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) |
| 2255 | cpu_relax(); |
| 2256 | |
| 2257 | writeb(d0, (tcdm_base + PRCM_REQ_MB4_A9WDOG_0)); |
| 2258 | writeb(d1, (tcdm_base + PRCM_REQ_MB4_A9WDOG_1)); |
| 2259 | writeb(d2, (tcdm_base + PRCM_REQ_MB4_A9WDOG_2)); |
| 2260 | writeb(d3, (tcdm_base + PRCM_REQ_MB4_A9WDOG_3)); |
| 2261 | |
| 2262 | writeb(cmd, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); |
| 2263 | |
| 2264 | writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET); |
| 2265 | wait_for_completion(&mb4_transfer.work); |
| 2266 | |
| 2267 | mutex_unlock(&mb4_transfer.lock); |
| 2268 | |
| 2269 | return 0; |
| 2270 | |
| 2271 | } |
| 2272 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2273 | int db8500_prcmu_config_a9wdog(u8 num, bool sleep_auto_off) |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2274 | { |
| 2275 | BUG_ON(num == 0 || num > 0xf); |
| 2276 | return prcmu_a9wdog(MB4H_A9WDOG_CONF, num, 0, 0, |
| 2277 | sleep_auto_off ? A9WDOG_AUTO_OFF_EN : |
| 2278 | A9WDOG_AUTO_OFF_DIS); |
| 2279 | } |
| 2280 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2281 | int db8500_prcmu_enable_a9wdog(u8 id) |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2282 | { |
| 2283 | return prcmu_a9wdog(MB4H_A9WDOG_EN, id, 0, 0, 0); |
| 2284 | } |
| 2285 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2286 | int db8500_prcmu_disable_a9wdog(u8 id) |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2287 | { |
| 2288 | return prcmu_a9wdog(MB4H_A9WDOG_DIS, id, 0, 0, 0); |
| 2289 | } |
| 2290 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2291 | int db8500_prcmu_kick_a9wdog(u8 id) |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2292 | { |
| 2293 | return prcmu_a9wdog(MB4H_A9WDOG_KICK, id, 0, 0, 0); |
| 2294 | } |
| 2295 | |
| 2296 | /* |
| 2297 | * timeout is 28 bit, in ms. |
| 2298 | */ |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2299 | int db8500_prcmu_load_a9wdog(u8 id, u32 timeout) |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2300 | { |
Jonas Aberg | 84165b8 | 2011-08-12 10:28:33 +0200 | [diff] [blame] | 2301 | return prcmu_a9wdog(MB4H_A9WDOG_LOAD, |
| 2302 | (id & A9WDOG_ID_MASK) | |
| 2303 | /* |
| 2304 | * Put the lowest 28 bits of timeout at |
| 2305 | * offset 4. Four first bits are used for id. |
| 2306 | */ |
| 2307 | (u8)((timeout << 4) & 0xf0), |
| 2308 | (u8)((timeout >> 4) & 0xff), |
| 2309 | (u8)((timeout >> 12) & 0xff), |
| 2310 | (u8)((timeout >> 20) & 0xff)); |
| 2311 | } |
| 2312 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2313 | /** |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2314 | * prcmu_abb_read() - Read register value(s) from the ABB. |
| 2315 | * @slave: The I2C slave address. |
| 2316 | * @reg: The (start) register address. |
| 2317 | * @value: The read out value(s). |
| 2318 | * @size: The number of registers to read. |
| 2319 | * |
| 2320 | * Reads register value(s) from the ABB. |
| 2321 | * @size has to be 1 for the current firmware version. |
| 2322 | */ |
| 2323 | int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size) |
| 2324 | { |
| 2325 | int r; |
| 2326 | |
| 2327 | if (size != 1) |
| 2328 | return -EINVAL; |
| 2329 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2330 | mutex_lock(&mb5_transfer.lock); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2331 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2332 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5)) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2333 | cpu_relax(); |
| 2334 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2335 | writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP)); |
| 2336 | writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS)); |
| 2337 | writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG)); |
| 2338 | writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL)); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2339 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2340 | writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2341 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2342 | if (!wait_for_completion_timeout(&mb5_transfer.work, |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2343 | msecs_to_jiffies(20000))) { |
| 2344 | pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n", |
| 2345 | __func__); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2346 | r = -EIO; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2347 | } else { |
| 2348 | r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2349 | } |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2350 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2351 | if (!r) |
| 2352 | *value = mb5_transfer.ack.value; |
| 2353 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2354 | mutex_unlock(&mb5_transfer.lock); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2355 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2356 | return r; |
| 2357 | } |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2358 | |
| 2359 | /** |
| 2360 | * prcmu_abb_write() - Write register value(s) to the ABB. |
| 2361 | * @slave: The I2C slave address. |
| 2362 | * @reg: The (start) register address. |
| 2363 | * @value: The value(s) to write. |
| 2364 | * @size: The number of registers to write. |
| 2365 | * |
| 2366 | * Reads register value(s) from the ABB. |
| 2367 | * @size has to be 1 for the current firmware version. |
| 2368 | */ |
| 2369 | int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size) |
| 2370 | { |
| 2371 | int r; |
| 2372 | |
| 2373 | if (size != 1) |
| 2374 | return -EINVAL; |
| 2375 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2376 | mutex_lock(&mb5_transfer.lock); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2377 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2378 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5)) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2379 | cpu_relax(); |
| 2380 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2381 | writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP)); |
| 2382 | writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS)); |
| 2383 | writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG)); |
| 2384 | writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL)); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2385 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2386 | writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2387 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2388 | if (!wait_for_completion_timeout(&mb5_transfer.work, |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2389 | msecs_to_jiffies(20000))) { |
| 2390 | pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n", |
| 2391 | __func__); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2392 | r = -EIO; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2393 | } else { |
| 2394 | r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2395 | } |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2396 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2397 | mutex_unlock(&mb5_transfer.lock); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2398 | |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2399 | return r; |
| 2400 | } |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2401 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2402 | /** |
| 2403 | * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem |
| 2404 | */ |
| 2405 | void prcmu_ac_wake_req(void) |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2406 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2407 | u32 val; |
Mattias Nilsson | d6e3002 | 2011-08-12 10:28:43 +0200 | [diff] [blame] | 2408 | u32 status; |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2409 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2410 | mutex_lock(&mb0_transfer.ac_wake_lock); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2411 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2412 | val = readl(PRCM_HOSTACCESS_REQ); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2413 | if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ) |
| 2414 | goto unlock_and_return; |
| 2415 | |
| 2416 | atomic_set(&ac_wake_req_state, 1); |
| 2417 | |
Mattias Nilsson | d6e3002 | 2011-08-12 10:28:43 +0200 | [diff] [blame] | 2418 | retry: |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2419 | writel((val | PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ), PRCM_HOSTACCESS_REQ); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2420 | |
| 2421 | if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work, |
Mattias Nilsson | d6e3002 | 2011-08-12 10:28:43 +0200 | [diff] [blame] | 2422 | msecs_to_jiffies(5000))) { |
Linus Walleij | 57265bc | 2011-10-10 13:04:44 +0200 | [diff] [blame] | 2423 | pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n", |
Mattias Nilsson | d6e3002 | 2011-08-12 10:28:43 +0200 | [diff] [blame] | 2424 | __func__); |
| 2425 | goto unlock_and_return; |
| 2426 | } |
| 2427 | |
| 2428 | /* |
| 2429 | * The modem can generate an AC_WAKE_ACK, and then still go to sleep. |
| 2430 | * As a workaround, we wait, and then check that the modem is indeed |
| 2431 | * awake (in terms of the value of the PRCM_MOD_AWAKE_STATUS |
| 2432 | * register, which may not be the whole truth). |
| 2433 | */ |
| 2434 | udelay(400); |
| 2435 | status = (readl(PRCM_MOD_AWAKE_STATUS) & BITS(0, 2)); |
| 2436 | if (status != (PRCM_MOD_AWAKE_STATUS_PRCM_MOD_AAPD_AWAKE | |
| 2437 | PRCM_MOD_AWAKE_STATUS_PRCM_MOD_COREPD_AWAKE)) { |
| 2438 | pr_err("prcmu: %s received ack, but modem not awake (0x%X).\n", |
| 2439 | __func__, status); |
| 2440 | udelay(1200); |
| 2441 | writel(val, PRCM_HOSTACCESS_REQ); |
| 2442 | if (wait_for_completion_timeout(&mb0_transfer.ac_wake_work, |
| 2443 | msecs_to_jiffies(5000))) |
| 2444 | goto retry; |
Linus Walleij | 57265bc | 2011-10-10 13:04:44 +0200 | [diff] [blame] | 2445 | pr_crit("prcmu: %s timed out (5 s) waiting for AC_SLEEP_ACK.\n", |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2446 | __func__); |
| 2447 | } |
| 2448 | |
| 2449 | unlock_and_return: |
| 2450 | mutex_unlock(&mb0_transfer.ac_wake_lock); |
| 2451 | } |
| 2452 | |
| 2453 | /** |
| 2454 | * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem |
| 2455 | */ |
| 2456 | void prcmu_ac_sleep_req() |
| 2457 | { |
| 2458 | u32 val; |
| 2459 | |
| 2460 | mutex_lock(&mb0_transfer.ac_wake_lock); |
| 2461 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2462 | val = readl(PRCM_HOSTACCESS_REQ); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2463 | if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)) |
| 2464 | goto unlock_and_return; |
| 2465 | |
| 2466 | writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ), |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2467 | PRCM_HOSTACCESS_REQ); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2468 | |
| 2469 | if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work, |
Mattias Nilsson | d6e3002 | 2011-08-12 10:28:43 +0200 | [diff] [blame] | 2470 | msecs_to_jiffies(5000))) { |
Linus Walleij | 57265bc | 2011-10-10 13:04:44 +0200 | [diff] [blame] | 2471 | pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n", |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2472 | __func__); |
| 2473 | } |
| 2474 | |
| 2475 | atomic_set(&ac_wake_req_state, 0); |
| 2476 | |
| 2477 | unlock_and_return: |
| 2478 | mutex_unlock(&mb0_transfer.ac_wake_lock); |
| 2479 | } |
| 2480 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 2481 | bool db8500_prcmu_is_ac_wake_requested(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2482 | { |
| 2483 | return (atomic_read(&ac_wake_req_state) != 0); |
| 2484 | } |
| 2485 | |
| 2486 | /** |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 2487 | * db8500_prcmu_system_reset - System reset |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2488 | * |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 2489 | * Saves the reset reason code and then sets the APE_SOFTRST register which |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2490 | * fires interrupt to fw |
| 2491 | */ |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 2492 | void db8500_prcmu_system_reset(u16 reset_code) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2493 | { |
| 2494 | writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON)); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2495 | writel(1, PRCM_APE_SOFTRST); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | /** |
Sebastian Rasmussen | 597045d | 2011-08-12 10:28:53 +0200 | [diff] [blame] | 2499 | * db8500_prcmu_get_reset_code - Retrieve SW reset reason code |
| 2500 | * |
| 2501 | * Retrieves the reset reason code stored by prcmu_system_reset() before |
| 2502 | * last restart. |
| 2503 | */ |
| 2504 | u16 db8500_prcmu_get_reset_code(void) |
| 2505 | { |
| 2506 | return readw(tcdm_base + PRCM_SW_RST_REASON); |
| 2507 | } |
| 2508 | |
| 2509 | /** |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2510 | * db8500_prcmu_reset_modem - ask the PRCMU to reset modem |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2511 | */ |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2512 | void db8500_prcmu_modem_reset(void) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2513 | { |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2514 | mutex_lock(&mb1_transfer.lock); |
| 2515 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2516 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2517 | cpu_relax(); |
| 2518 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2519 | writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2520 | writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2521 | wait_for_completion(&mb1_transfer.work); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2522 | |
| 2523 | /* |
| 2524 | * No need to check return from PRCMU as modem should go in reset state |
| 2525 | * This state is already managed by upper layer |
| 2526 | */ |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2527 | |
| 2528 | mutex_unlock(&mb1_transfer.lock); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2531 | static void ack_dbb_wakeup(void) |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2532 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2533 | unsigned long flags; |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2534 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2535 | spin_lock_irqsave(&mb0_transfer.lock, flags); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2536 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2537 | while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0)) |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2538 | cpu_relax(); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2539 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2540 | writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0)); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2541 | writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2542 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2543 | spin_unlock_irqrestore(&mb0_transfer.lock, flags); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2544 | } |
| 2545 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2546 | static inline void print_unknown_header_warning(u8 n, u8 header) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2547 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2548 | pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n", |
| 2549 | header, n); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2550 | } |
| 2551 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2552 | static bool read_mailbox_0(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2553 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2554 | bool r; |
| 2555 | u32 ev; |
| 2556 | unsigned int n; |
| 2557 | u8 header; |
| 2558 | |
| 2559 | header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0); |
| 2560 | switch (header) { |
| 2561 | case MB0H_WAKEUP_EXE: |
| 2562 | case MB0H_WAKEUP_SLEEP: |
| 2563 | if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1) |
| 2564 | ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500); |
| 2565 | else |
| 2566 | ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500); |
| 2567 | |
| 2568 | if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK)) |
| 2569 | complete(&mb0_transfer.ac_wake_work); |
| 2570 | if (ev & WAKEUP_BIT_SYSCLK_OK) |
| 2571 | complete(&mb3_transfer.sysclk_work); |
| 2572 | |
| 2573 | ev &= mb0_transfer.req.dbb_irqs; |
| 2574 | |
| 2575 | for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) { |
| 2576 | if (ev & prcmu_irq_bit[n]) |
| 2577 | generic_handle_irq(IRQ_PRCMU_BASE + n); |
| 2578 | } |
| 2579 | r = true; |
| 2580 | break; |
| 2581 | default: |
| 2582 | print_unknown_header_warning(0, header); |
| 2583 | r = false; |
| 2584 | break; |
| 2585 | } |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2586 | writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2587 | return r; |
| 2588 | } |
| 2589 | |
| 2590 | static bool read_mailbox_1(void) |
| 2591 | { |
| 2592 | mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1); |
| 2593 | mb1_transfer.ack.arm_opp = readb(tcdm_base + |
| 2594 | PRCM_ACK_MB1_CURRENT_ARM_OPP); |
| 2595 | mb1_transfer.ack.ape_opp = readb(tcdm_base + |
| 2596 | PRCM_ACK_MB1_CURRENT_APE_OPP); |
| 2597 | mb1_transfer.ack.ape_voltage_status = readb(tcdm_base + |
| 2598 | PRCM_ACK_MB1_APE_VOLTAGE_STATUS); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2599 | writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2600 | complete(&mb1_transfer.work); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2601 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2602 | } |
| 2603 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2604 | static bool read_mailbox_2(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2605 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2606 | mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2607 | writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2608 | complete(&mb2_transfer.work); |
| 2609 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2610 | } |
| 2611 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2612 | static bool read_mailbox_3(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2613 | { |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2614 | writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2615 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2616 | } |
| 2617 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2618 | static bool read_mailbox_4(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2619 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2620 | u8 header; |
| 2621 | bool do_complete = true; |
| 2622 | |
| 2623 | header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4); |
| 2624 | switch (header) { |
| 2625 | case MB4H_MEM_ST: |
| 2626 | case MB4H_HOTDOG: |
| 2627 | case MB4H_HOTMON: |
| 2628 | case MB4H_HOT_PERIOD: |
Mattias Nilsson | a592c2e | 2011-08-12 10:27:41 +0200 | [diff] [blame] | 2629 | case MB4H_A9WDOG_CONF: |
| 2630 | case MB4H_A9WDOG_EN: |
| 2631 | case MB4H_A9WDOG_DIS: |
| 2632 | case MB4H_A9WDOG_LOAD: |
| 2633 | case MB4H_A9WDOG_KICK: |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2634 | break; |
| 2635 | default: |
| 2636 | print_unknown_header_warning(4, header); |
| 2637 | do_complete = false; |
| 2638 | break; |
| 2639 | } |
| 2640 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2641 | writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2642 | |
| 2643 | if (do_complete) |
| 2644 | complete(&mb4_transfer.work); |
| 2645 | |
| 2646 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2647 | } |
| 2648 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2649 | static bool read_mailbox_5(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2650 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2651 | mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS); |
| 2652 | mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL); |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2653 | writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2654 | complete(&mb5_transfer.work); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2655 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2656 | } |
| 2657 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2658 | static bool read_mailbox_6(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2659 | { |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2660 | writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2661 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2664 | static bool read_mailbox_7(void) |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2665 | { |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2666 | writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2667 | return false; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2668 | } |
| 2669 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2670 | static bool (* const read_mailbox[NUM_MB])(void) = { |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2671 | read_mailbox_0, |
| 2672 | read_mailbox_1, |
| 2673 | read_mailbox_2, |
| 2674 | read_mailbox_3, |
| 2675 | read_mailbox_4, |
| 2676 | read_mailbox_5, |
| 2677 | read_mailbox_6, |
| 2678 | read_mailbox_7 |
| 2679 | }; |
| 2680 | |
| 2681 | static irqreturn_t prcmu_irq_handler(int irq, void *data) |
| 2682 | { |
| 2683 | u32 bits; |
| 2684 | u8 n; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2685 | irqreturn_t r; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2686 | |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 2687 | bits = (readl(PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2688 | if (unlikely(!bits)) |
| 2689 | return IRQ_NONE; |
| 2690 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2691 | r = IRQ_HANDLED; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2692 | for (n = 0; bits; n++) { |
| 2693 | if (bits & MBOX_BIT(n)) { |
| 2694 | bits -= MBOX_BIT(n); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2695 | if (read_mailbox[n]()) |
| 2696 | r = IRQ_WAKE_THREAD; |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2697 | } |
| 2698 | } |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2699 | return r; |
| 2700 | } |
| 2701 | |
| 2702 | static irqreturn_t prcmu_irq_thread_fn(int irq, void *data) |
| 2703 | { |
| 2704 | ack_dbb_wakeup(); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2705 | return IRQ_HANDLED; |
| 2706 | } |
| 2707 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2708 | static void prcmu_mask_work(struct work_struct *work) |
| 2709 | { |
| 2710 | unsigned long flags; |
| 2711 | |
| 2712 | spin_lock_irqsave(&mb0_transfer.lock, flags); |
| 2713 | |
| 2714 | config_wakeups(); |
| 2715 | |
| 2716 | spin_unlock_irqrestore(&mb0_transfer.lock, flags); |
| 2717 | } |
| 2718 | |
| 2719 | static void prcmu_irq_mask(struct irq_data *d) |
| 2720 | { |
| 2721 | unsigned long flags; |
| 2722 | |
| 2723 | spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags); |
| 2724 | |
| 2725 | mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE]; |
| 2726 | |
| 2727 | spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags); |
| 2728 | |
| 2729 | if (d->irq != IRQ_PRCMU_CA_SLEEP) |
| 2730 | schedule_work(&mb0_transfer.mask_work); |
| 2731 | } |
| 2732 | |
| 2733 | static void prcmu_irq_unmask(struct irq_data *d) |
| 2734 | { |
| 2735 | unsigned long flags; |
| 2736 | |
| 2737 | spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags); |
| 2738 | |
| 2739 | mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE]; |
| 2740 | |
| 2741 | spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags); |
| 2742 | |
| 2743 | if (d->irq != IRQ_PRCMU_CA_SLEEP) |
| 2744 | schedule_work(&mb0_transfer.mask_work); |
| 2745 | } |
| 2746 | |
| 2747 | static void noop(struct irq_data *d) |
| 2748 | { |
| 2749 | } |
| 2750 | |
| 2751 | static struct irq_chip prcmu_irq_chip = { |
| 2752 | .name = "prcmu", |
| 2753 | .irq_disable = prcmu_irq_mask, |
| 2754 | .irq_ack = noop, |
| 2755 | .irq_mask = prcmu_irq_mask, |
| 2756 | .irq_unmask = prcmu_irq_unmask, |
| 2757 | }; |
| 2758 | |
Mattias Nilsson | b58d12f | 2012-01-13 16:20:10 +0100 | [diff] [blame] | 2759 | static char *fw_project_name(u8 project) |
| 2760 | { |
| 2761 | switch (project) { |
| 2762 | case PRCMU_FW_PROJECT_U8500: |
| 2763 | return "U8500"; |
| 2764 | case PRCMU_FW_PROJECT_U8500_C2: |
| 2765 | return "U8500 C2"; |
| 2766 | case PRCMU_FW_PROJECT_U9500: |
| 2767 | return "U9500"; |
| 2768 | case PRCMU_FW_PROJECT_U9500_C2: |
| 2769 | return "U9500 C2"; |
| 2770 | default: |
| 2771 | return "Unknown"; |
| 2772 | } |
| 2773 | } |
| 2774 | |
Mattias Nilsson | 73180f8 | 2011-08-12 10:28:10 +0200 | [diff] [blame] | 2775 | void __init db8500_prcmu_early_init(void) |
Mattias Wallin | fcbd458 | 2010-12-02 16:20:42 +0100 | [diff] [blame] | 2776 | { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2777 | unsigned int i; |
Linus Walleij | 3e2762c | 2012-01-02 14:17:40 +0100 | [diff] [blame] | 2778 | if (cpu_is_u8500v2()) { |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2779 | void *tcpm_base = ioremap_nocache(U8500_PRCMU_TCPM_BASE, SZ_4K); |
| 2780 | |
| 2781 | if (tcpm_base != NULL) { |
Linus Walleij | 3e2762c | 2012-01-02 14:17:40 +0100 | [diff] [blame] | 2782 | u32 version; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2783 | version = readl(tcpm_base + PRCMU_FW_VERSION_OFFSET); |
Mattias Nilsson | b58d12f | 2012-01-13 16:20:10 +0100 | [diff] [blame] | 2784 | fw_info.version.project = version & 0xFF; |
| 2785 | fw_info.version.api_version = (version >> 8) & 0xFF; |
| 2786 | fw_info.version.func_version = (version >> 16) & 0xFF; |
| 2787 | fw_info.version.errata = (version >> 24) & 0xFF; |
| 2788 | fw_info.valid = true; |
| 2789 | pr_info("PRCMU firmware: %s, version %d.%d.%d\n", |
| 2790 | fw_project_name(fw_info.version.project), |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2791 | (version >> 8) & 0xFF, (version >> 16) & 0xFF, |
| 2792 | (version >> 24) & 0xFF); |
| 2793 | iounmap(tcpm_base); |
| 2794 | } |
| 2795 | |
Mattias Wallin | fcbd458 | 2010-12-02 16:20:42 +0100 | [diff] [blame] | 2796 | tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE); |
| 2797 | } else { |
| 2798 | pr_err("prcmu: Unsupported chip version\n"); |
| 2799 | BUG(); |
| 2800 | } |
Mattias Wallin | fcbd458 | 2010-12-02 16:20:42 +0100 | [diff] [blame] | 2801 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2802 | spin_lock_init(&mb0_transfer.lock); |
| 2803 | spin_lock_init(&mb0_transfer.dbb_irqs_lock); |
| 2804 | mutex_init(&mb0_transfer.ac_wake_lock); |
| 2805 | init_completion(&mb0_transfer.ac_wake_work); |
Martin Persson | e0befb2 | 2010-12-08 15:13:28 +0100 | [diff] [blame] | 2806 | mutex_init(&mb1_transfer.lock); |
| 2807 | init_completion(&mb1_transfer.work); |
Mattias Nilsson | 4d64d2e | 2012-01-13 16:20:43 +0100 | [diff] [blame] | 2808 | mb1_transfer.ape_opp = APE_NO_CHANGE; |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2809 | mutex_init(&mb2_transfer.lock); |
| 2810 | init_completion(&mb2_transfer.work); |
| 2811 | spin_lock_init(&mb2_transfer.auto_pm_lock); |
| 2812 | spin_lock_init(&mb3_transfer.lock); |
| 2813 | mutex_init(&mb3_transfer.sysclk_lock); |
| 2814 | init_completion(&mb3_transfer.sysclk_work); |
| 2815 | mutex_init(&mb4_transfer.lock); |
| 2816 | init_completion(&mb4_transfer.work); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2817 | mutex_init(&mb5_transfer.lock); |
| 2818 | init_completion(&mb5_transfer.work); |
| 2819 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2820 | INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work); |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2821 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 2822 | /* Initalize irqs. */ |
| 2823 | for (i = 0; i < NUM_PRCMU_WAKEUPS; i++) { |
| 2824 | unsigned int irq; |
| 2825 | |
| 2826 | irq = IRQ_PRCMU_BASE + i; |
| 2827 | irq_set_chip_and_handler(irq, &prcmu_irq_chip, |
| 2828 | handle_simple_irq); |
| 2829 | set_irq_flags(irq, IRQF_VALID); |
| 2830 | } |
Linus Walleij | e3726fc | 2010-08-19 12:36:01 +0100 | [diff] [blame] | 2831 | } |
| 2832 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 2833 | static void __init init_prcm_registers(void) |
Mattias Nilsson | d65e12d | 2011-08-12 10:27:50 +0200 | [diff] [blame] | 2834 | { |
| 2835 | u32 val; |
| 2836 | |
| 2837 | val = readl(PRCM_A9PL_FORCE_CLKEN); |
| 2838 | val &= ~(PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN | |
| 2839 | PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN); |
| 2840 | writel(val, (PRCM_A9PL_FORCE_CLKEN)); |
| 2841 | } |
| 2842 | |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2843 | /* |
| 2844 | * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC |
| 2845 | */ |
| 2846 | static struct regulator_consumer_supply db8500_vape_consumers[] = { |
| 2847 | REGULATOR_SUPPLY("v-ape", NULL), |
| 2848 | REGULATOR_SUPPLY("v-i2c", "nmk-i2c.0"), |
| 2849 | REGULATOR_SUPPLY("v-i2c", "nmk-i2c.1"), |
| 2850 | REGULATOR_SUPPLY("v-i2c", "nmk-i2c.2"), |
| 2851 | REGULATOR_SUPPLY("v-i2c", "nmk-i2c.3"), |
| 2852 | /* "v-mmc" changed to "vcore" in the mainline kernel */ |
| 2853 | REGULATOR_SUPPLY("vcore", "sdi0"), |
| 2854 | REGULATOR_SUPPLY("vcore", "sdi1"), |
| 2855 | REGULATOR_SUPPLY("vcore", "sdi2"), |
| 2856 | REGULATOR_SUPPLY("vcore", "sdi3"), |
| 2857 | REGULATOR_SUPPLY("vcore", "sdi4"), |
| 2858 | REGULATOR_SUPPLY("v-dma", "dma40.0"), |
| 2859 | REGULATOR_SUPPLY("v-ape", "ab8500-usb.0"), |
| 2860 | /* "v-uart" changed to "vcore" in the mainline kernel */ |
| 2861 | REGULATOR_SUPPLY("vcore", "uart0"), |
| 2862 | REGULATOR_SUPPLY("vcore", "uart1"), |
| 2863 | REGULATOR_SUPPLY("vcore", "uart2"), |
| 2864 | REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"), |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 2865 | REGULATOR_SUPPLY("v-hsi", "ste_hsi.0"), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2866 | }; |
| 2867 | |
| 2868 | static struct regulator_consumer_supply db8500_vsmps2_consumers[] = { |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2869 | REGULATOR_SUPPLY("musb_1v8", "ab8500-usb.0"), |
| 2870 | /* AV8100 regulator */ |
| 2871 | REGULATOR_SUPPLY("hdmi_1v8", "0-0070"), |
| 2872 | }; |
| 2873 | |
| 2874 | static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 2875 | REGULATOR_SUPPLY("vsupply", "b2r2_bus"), |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 2876 | REGULATOR_SUPPLY("vsupply", "mcde"), |
| 2877 | }; |
| 2878 | |
| 2879 | /* SVA MMDSP regulator switch */ |
| 2880 | static struct regulator_consumer_supply db8500_svammdsp_consumers[] = { |
| 2881 | REGULATOR_SUPPLY("sva-mmdsp", "cm_control"), |
| 2882 | }; |
| 2883 | |
| 2884 | /* SVA pipe regulator switch */ |
| 2885 | static struct regulator_consumer_supply db8500_svapipe_consumers[] = { |
| 2886 | REGULATOR_SUPPLY("sva-pipe", "cm_control"), |
| 2887 | }; |
| 2888 | |
| 2889 | /* SIA MMDSP regulator switch */ |
| 2890 | static struct regulator_consumer_supply db8500_siammdsp_consumers[] = { |
| 2891 | REGULATOR_SUPPLY("sia-mmdsp", "cm_control"), |
| 2892 | }; |
| 2893 | |
| 2894 | /* SIA pipe regulator switch */ |
| 2895 | static struct regulator_consumer_supply db8500_siapipe_consumers[] = { |
| 2896 | REGULATOR_SUPPLY("sia-pipe", "cm_control"), |
| 2897 | }; |
| 2898 | |
| 2899 | static struct regulator_consumer_supply db8500_sga_consumers[] = { |
| 2900 | REGULATOR_SUPPLY("v-mali", NULL), |
| 2901 | }; |
| 2902 | |
| 2903 | /* ESRAM1 and 2 regulator switch */ |
| 2904 | static struct regulator_consumer_supply db8500_esram12_consumers[] = { |
| 2905 | REGULATOR_SUPPLY("esram12", "cm_control"), |
| 2906 | }; |
| 2907 | |
| 2908 | /* ESRAM3 and 4 regulator switch */ |
| 2909 | static struct regulator_consumer_supply db8500_esram34_consumers[] = { |
| 2910 | REGULATOR_SUPPLY("v-esram34", "mcde"), |
| 2911 | REGULATOR_SUPPLY("esram34", "cm_control"), |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 2912 | REGULATOR_SUPPLY("lcla_esram", "dma40.0"), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2913 | }; |
| 2914 | |
| 2915 | static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = { |
| 2916 | [DB8500_REGULATOR_VAPE] = { |
| 2917 | .constraints = { |
| 2918 | .name = "db8500-vape", |
| 2919 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2920 | }, |
| 2921 | .consumer_supplies = db8500_vape_consumers, |
| 2922 | .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers), |
| 2923 | }, |
| 2924 | [DB8500_REGULATOR_VARM] = { |
| 2925 | .constraints = { |
| 2926 | .name = "db8500-varm", |
| 2927 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2928 | }, |
| 2929 | }, |
| 2930 | [DB8500_REGULATOR_VMODEM] = { |
| 2931 | .constraints = { |
| 2932 | .name = "db8500-vmodem", |
| 2933 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2934 | }, |
| 2935 | }, |
| 2936 | [DB8500_REGULATOR_VPLL] = { |
| 2937 | .constraints = { |
| 2938 | .name = "db8500-vpll", |
| 2939 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2940 | }, |
| 2941 | }, |
| 2942 | [DB8500_REGULATOR_VSMPS1] = { |
| 2943 | .constraints = { |
| 2944 | .name = "db8500-vsmps1", |
| 2945 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2946 | }, |
| 2947 | }, |
| 2948 | [DB8500_REGULATOR_VSMPS2] = { |
| 2949 | .constraints = { |
| 2950 | .name = "db8500-vsmps2", |
| 2951 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2952 | }, |
| 2953 | .consumer_supplies = db8500_vsmps2_consumers, |
| 2954 | .num_consumer_supplies = ARRAY_SIZE(db8500_vsmps2_consumers), |
| 2955 | }, |
| 2956 | [DB8500_REGULATOR_VSMPS3] = { |
| 2957 | .constraints = { |
| 2958 | .name = "db8500-vsmps3", |
| 2959 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2960 | }, |
| 2961 | }, |
| 2962 | [DB8500_REGULATOR_VRF1] = { |
| 2963 | .constraints = { |
| 2964 | .name = "db8500-vrf1", |
| 2965 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2966 | }, |
| 2967 | }, |
| 2968 | [DB8500_REGULATOR_SWITCH_SVAMMDSP] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 2969 | /* dependency to u8500-vape is handled outside regulator framework */ |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2970 | .constraints = { |
| 2971 | .name = "db8500-sva-mmdsp", |
| 2972 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2973 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 2974 | .consumer_supplies = db8500_svammdsp_consumers, |
| 2975 | .num_consumer_supplies = ARRAY_SIZE(db8500_svammdsp_consumers), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2976 | }, |
| 2977 | [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = { |
| 2978 | .constraints = { |
| 2979 | /* "ret" means "retention" */ |
| 2980 | .name = "db8500-sva-mmdsp-ret", |
| 2981 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2982 | }, |
| 2983 | }, |
| 2984 | [DB8500_REGULATOR_SWITCH_SVAPIPE] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 2985 | /* dependency to u8500-vape is handled outside regulator framework */ |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2986 | .constraints = { |
| 2987 | .name = "db8500-sva-pipe", |
| 2988 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2989 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 2990 | .consumer_supplies = db8500_svapipe_consumers, |
| 2991 | .num_consumer_supplies = ARRAY_SIZE(db8500_svapipe_consumers), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2992 | }, |
| 2993 | [DB8500_REGULATOR_SWITCH_SIAMMDSP] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 2994 | /* dependency to u8500-vape is handled outside regulator framework */ |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 2995 | .constraints = { |
| 2996 | .name = "db8500-sia-mmdsp", |
| 2997 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 2998 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 2999 | .consumer_supplies = db8500_siammdsp_consumers, |
| 3000 | .num_consumer_supplies = ARRAY_SIZE(db8500_siammdsp_consumers), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3001 | }, |
| 3002 | [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = { |
| 3003 | .constraints = { |
| 3004 | .name = "db8500-sia-mmdsp-ret", |
| 3005 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3006 | }, |
| 3007 | }, |
| 3008 | [DB8500_REGULATOR_SWITCH_SIAPIPE] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 3009 | /* dependency to u8500-vape is handled outside regulator framework */ |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3010 | .constraints = { |
| 3011 | .name = "db8500-sia-pipe", |
| 3012 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3013 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 3014 | .consumer_supplies = db8500_siapipe_consumers, |
| 3015 | .num_consumer_supplies = ARRAY_SIZE(db8500_siapipe_consumers), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3016 | }, |
| 3017 | [DB8500_REGULATOR_SWITCH_SGA] = { |
| 3018 | .supply_regulator = "db8500-vape", |
| 3019 | .constraints = { |
| 3020 | .name = "db8500-sga", |
| 3021 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3022 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 3023 | .consumer_supplies = db8500_sga_consumers, |
| 3024 | .num_consumer_supplies = ARRAY_SIZE(db8500_sga_consumers), |
| 3025 | |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3026 | }, |
| 3027 | [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = { |
| 3028 | .supply_regulator = "db8500-vape", |
| 3029 | .constraints = { |
| 3030 | .name = "db8500-b2r2-mcde", |
| 3031 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3032 | }, |
| 3033 | .consumer_supplies = db8500_b2r2_mcde_consumers, |
| 3034 | .num_consumer_supplies = ARRAY_SIZE(db8500_b2r2_mcde_consumers), |
| 3035 | }, |
| 3036 | [DB8500_REGULATOR_SWITCH_ESRAM12] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 3037 | /* |
| 3038 | * esram12 is set in retention and supplied by Vsafe when Vape is off, |
| 3039 | * no need to hold Vape |
| 3040 | */ |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3041 | .constraints = { |
| 3042 | .name = "db8500-esram12", |
| 3043 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3044 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 3045 | .consumer_supplies = db8500_esram12_consumers, |
| 3046 | .num_consumer_supplies = ARRAY_SIZE(db8500_esram12_consumers), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3047 | }, |
| 3048 | [DB8500_REGULATOR_SWITCH_ESRAM12RET] = { |
| 3049 | .constraints = { |
| 3050 | .name = "db8500-esram12-ret", |
| 3051 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3052 | }, |
| 3053 | }, |
| 3054 | [DB8500_REGULATOR_SWITCH_ESRAM34] = { |
Bengt Jonsson | 992b133 | 2012-01-13 16:20:36 +0100 | [diff] [blame] | 3055 | /* |
| 3056 | * esram34 is set in retention and supplied by Vsafe when Vape is off, |
| 3057 | * no need to hold Vape |
| 3058 | */ |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3059 | .constraints = { |
| 3060 | .name = "db8500-esram34", |
| 3061 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3062 | }, |
Bengt Jonsson | 624e87c | 2011-08-12 10:29:02 +0200 | [diff] [blame] | 3063 | .consumer_supplies = db8500_esram34_consumers, |
| 3064 | .num_consumer_supplies = ARRAY_SIZE(db8500_esram34_consumers), |
Bengt Jonsson | 1032fbf | 2011-04-01 14:43:33 +0200 | [diff] [blame] | 3065 | }, |
| 3066 | [DB8500_REGULATOR_SWITCH_ESRAM34RET] = { |
| 3067 | .constraints = { |
| 3068 | .name = "db8500-esram34-ret", |
| 3069 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 3070 | }, |
| 3071 | }, |
| 3072 | }; |
| 3073 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 3074 | static struct mfd_cell db8500_prcmu_devs[] = { |
| 3075 | { |
| 3076 | .name = "db8500-prcmu-regulators", |
Mattias Wallin | 1ed7891 | 2011-05-27 11:49:43 +0200 | [diff] [blame] | 3077 | .platform_data = &db8500_regulators, |
| 3078 | .pdata_size = sizeof(db8500_regulators), |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 3079 | }, |
| 3080 | { |
| 3081 | .name = "cpufreq-u8500", |
| 3082 | }, |
| 3083 | }; |
| 3084 | |
| 3085 | /** |
| 3086 | * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic |
| 3087 | * |
| 3088 | */ |
| 3089 | static int __init db8500_prcmu_probe(struct platform_device *pdev) |
| 3090 | { |
| 3091 | int err = 0; |
| 3092 | |
| 3093 | if (ux500_is_svp()) |
| 3094 | return -ENODEV; |
| 3095 | |
Mattias Nilsson | 0508901 | 2012-01-13 16:20:20 +0100 | [diff] [blame] | 3096 | init_prcm_registers(); |
Mattias Nilsson | d65e12d | 2011-08-12 10:27:50 +0200 | [diff] [blame] | 3097 | |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 3098 | /* Clean up the mailbox interrupts after pre-kernel code. */ |
Mattias Nilsson | c553b3c | 2011-08-12 10:27:20 +0200 | [diff] [blame] | 3099 | writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR); |
Mattias Nilsson | 3df57bc | 2011-05-16 00:15:05 +0200 | [diff] [blame] | 3100 | |
| 3101 | err = request_threaded_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler, |
| 3102 | prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL); |
| 3103 | if (err < 0) { |
| 3104 | pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n"); |
| 3105 | err = -EBUSY; |
| 3106 | goto no_irq_return; |
| 3107 | } |
| 3108 | |
| 3109 | if (cpu_is_u8500v20_or_later()) |
| 3110 | prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET); |
| 3111 | |
| 3112 | err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs, |
| 3113 | ARRAY_SIZE(db8500_prcmu_devs), NULL, |
| 3114 | 0); |
| 3115 | |
| 3116 | if (err) |
| 3117 | pr_err("prcmu: Failed to add subdevices\n"); |
| 3118 | else |
| 3119 | pr_info("DB8500 PRCMU initialized\n"); |
| 3120 | |
| 3121 | no_irq_return: |
| 3122 | return err; |
| 3123 | } |
| 3124 | |
| 3125 | static struct platform_driver db8500_prcmu_driver = { |
| 3126 | .driver = { |
| 3127 | .name = "db8500-prcmu", |
| 3128 | .owner = THIS_MODULE, |
| 3129 | }, |
| 3130 | }; |
| 3131 | |
| 3132 | static int __init db8500_prcmu_init(void) |
| 3133 | { |
| 3134 | return platform_driver_probe(&db8500_prcmu_driver, db8500_prcmu_probe); |
| 3135 | } |
| 3136 | |
| 3137 | arch_initcall(db8500_prcmu_init); |
| 3138 | |
| 3139 | MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>"); |
| 3140 | MODULE_DESCRIPTION("DB8500 PRCM Unit driver"); |
| 3141 | MODULE_LICENSE("GPL v2"); |