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