aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Nilsson <mattias.i.nilsson@stericsson.com>2011-05-15 18:15:05 -0400
committerLinus Walleij <linus.walleij@linaro.org>2011-05-24 16:18:57 -0400
commit3df57bcf5a6ba74572218a811bd0e311414f2aff (patch)
tree118953170481831063ff5b94438b61b3b20243c7
parent650c2a2145981696c414be1d540a32447d0e353e (diff)
mfd: update DB8500 PRCMU driver
This updates the DB8500 PRCMU driver to the latest version available internally. Nominally we would update the dependent CPUfreq driver at the same time but since that is being moved around in this patch set we postpone that by simply deactivating it for the time being. This is a snapshot of the current PRCMU firmware API as it looks right now. The PRCMU firmware is still subject to change. This also updates the CPUfreq driver to a newer version that will utilize the new API. Acked-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Mattias Nilsson <mattias.i.nilsson@stericsson.com> Signed-off-by: Martin Persson <martin.persson@stericsson.com> Signed-off-by: Per Fransson <per.xx.fransson@stericsson.com> Signed-off-by: Jonas Aaberg <jonas.aberg@stericsson.com> Signed-off-by: Sebastien Rault <sebastien.rault@stericsson.com> Signed-off-by: Bengt Jonsson <bengt.g.jonsson@stericsson.com> Signed-off-by: Rickard Andersson <rickard.andersson@stericsson.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--arch/arm/mach-ux500/Makefile2
-rw-r--r--arch/arm/mach-ux500/cpu-db8500.c5
-rw-r--r--drivers/mfd/db8500-prcmu-regs.h194
-rw-r--r--drivers/mfd/db8500-prcmu.c1843
-rw-r--r--include/linux/mfd/db8500-prcmu.h992
5 files changed, 2764 insertions, 272 deletions
diff --git a/arch/arm/mach-ux500/Makefile b/arch/arm/mach-ux500/Makefile
index 7a1d43e04f97..1694916e6822 100644
--- a/arch/arm/mach-ux500/Makefile
+++ b/arch/arm/mach-ux500/Makefile
@@ -17,4 +17,4 @@ obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
17obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o 17obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
18obj-$(CONFIG_U5500_MODEM_IRQ) += modem-irq-db5500.o 18obj-$(CONFIG_U5500_MODEM_IRQ) += modem-irq-db5500.o
19obj-$(CONFIG_U5500_MBOX) += mbox-db5500.o 19obj-$(CONFIG_U5500_MBOX) += mbox-db5500.o
20obj-$(CONFIG_CPU_FREQ) += cpufreq.o 20
diff --git a/arch/arm/mach-ux500/cpu-db8500.c b/arch/arm/mach-ux500/cpu-db8500.c
index 3d419fef0470..c3c417656bd9 100644
--- a/arch/arm/mach-ux500/cpu-db8500.c
+++ b/arch/arm/mach-ux500/cpu-db8500.c
@@ -131,9 +131,14 @@ static struct platform_device db8500_pmu_device = {
131 .dev.platform_data = &db8500_pmu_platdata, 131 .dev.platform_data = &db8500_pmu_platdata,
132}; 132};
133 133
134static struct platform_device db8500_prcmu_device = {
135 .name = "db8500-prcmu",
136};
137
134static struct platform_device *platform_devs[] __initdata = { 138static struct platform_device *platform_devs[] __initdata = {
135 &u8500_dma40_device, 139 &u8500_dma40_device,
136 &db8500_pmu_device, 140 &db8500_pmu_device,
141 &db8500_prcmu_device,
137}; 142};
138 143
139static resource_size_t __initdata db8500_gpio_base[] = { 144static resource_size_t __initdata db8500_gpio_base[] = {
diff --git a/drivers/mfd/db8500-prcmu-regs.h b/drivers/mfd/db8500-prcmu-regs.h
index c1226da19bfb..3bbf04d58043 100644
--- a/drivers/mfd/db8500-prcmu-regs.h
+++ b/drivers/mfd/db8500-prcmu-regs.h
@@ -9,86 +9,158 @@
9 * 9 *
10 * PRCM Unit registers 10 * PRCM Unit registers
11 */ 11 */
12#ifndef __DB8500_PRCMU_REGS_H
13#define __DB8500_PRCMU_REGS_H
12 14
13#ifndef __MACH_PRCMU_REGS_H 15#include <linux/bitops.h>
14#define __MACH_PRCMU_REGS_H
15
16#include <mach/hardware.h> 16#include <mach/hardware.h>
17 17
18#define PRCM_ARM_PLLDIVPS (_PRCMU_BASE + 0x118) 18#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
19#define PRCM_ARM_CHGCLKREQ (_PRCMU_BASE + 0x114) 19
20#define PRCM_PLLARM_ENABLE (_PRCMU_BASE + 0x98) 20#define PRCM_ARM_PLLDIVPS 0x118
21#define PRCM_ARMCLKFIX_MGT (_PRCMU_BASE + 0x0) 21#define PRCM_ARM_PLLDIVPS_ARM_BRM_RATE BITS(0, 5)
22#define PRCM_A9_RESETN_CLR (_PRCMU_BASE + 0x1f4) 22#define PRCM_ARM_PLLDIVPS_MAX_MASK 0xF
23#define PRCM_A9_RESETN_SET (_PRCMU_BASE + 0x1f0) 23
24#define PRCM_ARM_LS_CLAMP (_PRCMU_BASE + 0x30c) 24#define PRCM_PLLARM_LOCKP 0x0A8
25#define PRCM_SRAM_A9 (_PRCMU_BASE + 0x308) 25#define PRCM_PLLARM_LOCKP_PRCM_PLLARM_LOCKP3 BIT(1)
26
27#define PRCM_ARM_CHGCLKREQ 0x114
28#define PRCM_ARM_CHGCLKREQ_PRCM_ARM_CHGCLKREQ BIT(0)
29
30#define PRCM_PLLARM_ENABLE 0x98
31#define PRCM_PLLARM_ENABLE_PRCM_PLLARM_ENABLE BIT(0)
32#define PRCM_PLLARM_ENABLE_PRCM_PLLARM_COUNTON BIT(8)
33
34#define PRCM_ARMCLKFIX_MGT 0x0
35#define PRCM_A9_RESETN_CLR 0x1f4
36#define PRCM_A9_RESETN_SET 0x1f0
37#define PRCM_ARM_LS_CLAMP 0x30C
38#define PRCM_SRAM_A9 0x308
26 39
27/* ARM WFI Standby signal register */ 40/* ARM WFI Standby signal register */
28#define PRCM_ARM_WFI_STANDBY (_PRCMU_BASE + 0x130) 41#define PRCM_ARM_WFI_STANDBY 0x130
29#define PRCMU_IOCR (_PRCMU_BASE + 0x310) 42#define PRCM_IOCR 0x310
43#define PRCM_IOCR_IOFORCE BIT(0)
30 44
31/* CPU mailbox registers */ 45/* CPU mailbox registers */
32#define PRCM_MBOX_CPU_VAL (_PRCMU_BASE + 0x0fc) 46#define PRCM_MBOX_CPU_VAL 0x0FC
33#define PRCM_MBOX_CPU_SET (_PRCMU_BASE + 0x100) 47#define PRCM_MBOX_CPU_SET 0x100
34#define PRCM_MBOX_CPU_CLR (_PRCMU_BASE + 0x104)
35 48
36/* Dual A9 core interrupt management unit registers */ 49/* Dual A9 core interrupt management unit registers */
37#define PRCM_A9_MASK_REQ (_PRCMU_BASE + 0x328) 50#define PRCM_A9_MASK_REQ 0x328
38#define PRCM_A9_MASK_ACK (_PRCMU_BASE + 0x32c) 51#define PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ BIT(0)
39#define PRCM_ARMITMSK31TO0 (_PRCMU_BASE + 0x11c) 52
40#define PRCM_ARMITMSK63TO32 (_PRCMU_BASE + 0x120) 53#define PRCM_A9_MASK_ACK 0x32C
41#define PRCM_ARMITMSK95TO64 (_PRCMU_BASE + 0x124) 54#define PRCM_ARMITMSK31TO0 0x11C
42#define PRCM_ARMITMSK127TO96 (_PRCMU_BASE + 0x128) 55#define PRCM_ARMITMSK63TO32 0x120
43#define PRCM_POWER_STATE_VAL (_PRCMU_BASE + 0x25C) 56#define PRCM_ARMITMSK95TO64 0x124
44#define PRCM_ARMITVAL31TO0 (_PRCMU_BASE + 0x260) 57#define PRCM_ARMITMSK127TO96 0x128
45#define PRCM_ARMITVAL63TO32 (_PRCMU_BASE + 0x264) 58#define PRCM_POWER_STATE_VAL 0x25C
46#define PRCM_ARMITVAL95TO64 (_PRCMU_BASE + 0x268) 59#define PRCM_ARMITVAL31TO0 0x260
47#define PRCM_ARMITVAL127TO96 (_PRCMU_BASE + 0x26C) 60#define PRCM_ARMITVAL63TO32 0x264
48 61#define PRCM_ARMITVAL95TO64 0x268
49#define PRCM_HOSTACCESS_REQ (_PRCMU_BASE + 0x334) 62#define PRCM_ARMITVAL127TO96 0x26C
50#define ARM_WAKEUP_MODEM 0x1 63
51 64#define PRCM_HOSTACCESS_REQ 0x334
52#define PRCM_ARM_IT1_CLEAR (_PRCMU_BASE + 0x48C) 65#define PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ BIT(0)
53#define PRCM_ARM_IT1_VAL (_PRCMU_BASE + 0x494) 66
54#define PRCM_HOLD_EVT (_PRCMU_BASE + 0x174) 67#define PRCM_ARM_IT1_CLR 0x48C
55 68#define PRCM_ARM_IT1_VAL 0x494
56#define PRCM_ITSTATUS0 (_PRCMU_BASE + 0x148) 69
57#define PRCM_ITSTATUS1 (_PRCMU_BASE + 0x150) 70#define PRCM_ITSTATUS0 0x148
58#define PRCM_ITSTATUS2 (_PRCMU_BASE + 0x158) 71#define PRCM_ITSTATUS1 0x150
59#define PRCM_ITSTATUS3 (_PRCMU_BASE + 0x160) 72#define PRCM_ITSTATUS2 0x158
60#define PRCM_ITSTATUS4 (_PRCMU_BASE + 0x168) 73#define PRCM_ITSTATUS3 0x160
61#define PRCM_ITSTATUS5 (_PRCMU_BASE + 0x484) 74#define PRCM_ITSTATUS4 0x168
62#define PRCM_ITCLEAR5 (_PRCMU_BASE + 0x488) 75#define PRCM_ITSTATUS5 0x484
63#define PRCM_ARMIT_MASKXP70_IT (_PRCMU_BASE + 0x1018) 76#define PRCM_ITCLEAR5 0x488
77#define PRCM_ARMIT_MASKXP70_IT 0x1018
64 78
65/* System reset register */ 79/* System reset register */
66#define PRCM_APE_SOFTRST (_PRCMU_BASE + 0x228) 80#define PRCM_APE_SOFTRST 0x228
67 81
68/* Level shifter and clamp control registers */ 82/* Level shifter and clamp control registers */
69#define PRCM_MMIP_LS_CLAMP_SET (_PRCMU_BASE + 0x420) 83#define PRCM_MMIP_LS_CLAMP_SET 0x420
70#define PRCM_MMIP_LS_CLAMP_CLR (_PRCMU_BASE + 0x424) 84#define PRCM_MMIP_LS_CLAMP_CLR 0x424
85
86/* PRCMU HW semaphore */
87#define PRCM_SEM 0x400
88#define PRCM_SEM_PRCM_SEM BIT(0)
71 89
72/* PRCMU clock/PLL/reset registers */ 90/* PRCMU clock/PLL/reset registers */
73#define PRCM_PLLDSI_FREQ (_PRCMU_BASE + 0x500) 91#define PRCM_PLLDSI_FREQ 0x500
74#define PRCM_PLLDSI_ENABLE (_PRCMU_BASE + 0x504) 92#define PRCM_PLLDSI_ENABLE 0x504
75#define PRCM_LCDCLK_MGT (_PRCMU_BASE + 0x044) 93#define PRCM_PLLDSI_LOCKP 0x508
76#define PRCM_MCDECLK_MGT (_PRCMU_BASE + 0x064) 94#define PRCM_DSI_PLLOUT_SEL 0x530
77#define PRCM_HDMICLK_MGT (_PRCMU_BASE + 0x058) 95#define PRCM_DSITVCLK_DIV 0x52C
78#define PRCM_TVCLK_MGT (_PRCMU_BASE + 0x07c) 96#define PRCM_APE_RESETN_SET 0x1E4
79#define PRCM_DSI_PLLOUT_SEL (_PRCMU_BASE + 0x530) 97#define PRCM_APE_RESETN_CLR 0x1E8
80#define PRCM_DSITVCLK_DIV (_PRCMU_BASE + 0x52C) 98
81#define PRCM_APE_RESETN_SET (_PRCMU_BASE + 0x1E4) 99#define PRCM_TCR 0x1C8
82#define PRCM_APE_RESETN_CLR (_PRCMU_BASE + 0x1E8) 100#define PRCM_TCR_TENSEL_MASK BITS(0, 7)
101#define PRCM_TCR_STOP_TIMERS BIT(16)
102#define PRCM_TCR_DOZE_MODE BIT(17)
103
104#define PRCM_CLKOCR 0x1CC
105#define PRCM_CLKOCR_CLKODIV0_SHIFT 0
106#define PRCM_CLKOCR_CLKODIV0_MASK BITS(0, 5)
107#define PRCM_CLKOCR_CLKOSEL0_SHIFT 6
108#define PRCM_CLKOCR_CLKOSEL0_MASK BITS(6, 8)
109#define PRCM_CLKOCR_CLKODIV1_SHIFT 16
110#define PRCM_CLKOCR_CLKODIV1_MASK BITS(16, 21)
111#define PRCM_CLKOCR_CLKOSEL1_SHIFT 22
112#define PRCM_CLKOCR_CLKOSEL1_MASK BITS(22, 24)
113#define PRCM_CLKOCR_CLK1TYPE BIT(28)
114
115#define PRCM_SGACLK_MGT 0x014
116#define PRCM_UARTCLK_MGT 0x018
117#define PRCM_MSP02CLK_MGT 0x01C
118#define PRCM_MSP1CLK_MGT 0x288
119#define PRCM_I2CCLK_MGT 0x020
120#define PRCM_SDMMCCLK_MGT 0x024
121#define PRCM_SLIMCLK_MGT 0x028
122#define PRCM_PER1CLK_MGT 0x02C
123#define PRCM_PER2CLK_MGT 0x030
124#define PRCM_PER3CLK_MGT 0x034
125#define PRCM_PER5CLK_MGT 0x038
126#define PRCM_PER6CLK_MGT 0x03C
127#define PRCM_PER7CLK_MGT 0x040
128#define PRCM_LCDCLK_MGT 0x044
129#define PRCM_BMLCLK_MGT 0x04C
130#define PRCM_HSITXCLK_MGT 0x050
131#define PRCM_HSIRXCLK_MGT 0x054
132#define PRCM_HDMICLK_MGT 0x058
133#define PRCM_APEATCLK_MGT 0x05C
134#define PRCM_APETRACECLK_MGT 0x060
135#define PRCM_MCDECLK_MGT 0x064
136#define PRCM_IPI2CCLK_MGT 0x068
137#define PRCM_DSIALTCLK_MGT 0x06C
138#define PRCM_DMACLK_MGT 0x074
139#define PRCM_B2R2CLK_MGT 0x078
140#define PRCM_TVCLK_MGT 0x07C
141#define PRCM_UNIPROCLK_MGT 0x278
142#define PRCM_SSPCLK_MGT 0x280
143#define PRCM_RNGCLK_MGT 0x284
144#define PRCM_UICCCLK_MGT 0x27C
145
146#define PRCM_CLK_MGT_CLKPLLDIV_MASK BITS(0, 4)
147#define PRCM_CLK_MGT_CLKPLLSW_MASK BITS(5, 7)
148#define PRCM_CLK_MGT_CLKEN BIT(8)
83 149
84/* ePOD and memory power signal control registers */ 150/* ePOD and memory power signal control registers */
85#define PRCM_EPOD_C_SET (_PRCMU_BASE + 0x410) 151#define PRCM_EPOD_C_SET 0x410
86#define PRCM_SRAM_LS_SLEEP (_PRCMU_BASE + 0x304) 152#define PRCM_SRAM_LS_SLEEP 0x304
87 153
88/* Debug power control unit registers */ 154/* Debug power control unit registers */
89#define PRCM_POWER_STATE_SET (_PRCMU_BASE + 0x254) 155#define PRCM_POWER_STATE_SET 0x254
90 156
91/* Miscellaneous unit registers */ 157/* Miscellaneous unit registers */
92#define PRCM_DSI_SW_RESET (_PRCMU_BASE + 0x324) 158#define PRCM_DSI_SW_RESET 0x324
159#define PRCM_GPIOCR 0x138
160
161/* GPIOCR register */
162#define PRCM_GPIOCR_SPI2_SELECT BIT(23)
163
164#define PRCM_DDR_SUBSYS_APE_MINBW 0x438
93 165
94#endif /* __MACH_PRCMU_REGS_H */ 166#endif /* __DB8500_PRCMU_REGS_H */
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 31f18c8c6bf8..c44725bd8b9a 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -10,94 +10,1355 @@
10 * U8500 PRCM Unit interface driver 10 * U8500 PRCM Unit interface driver
11 * 11 *
12 */ 12 */
13#include <linux/kernel.h>
14#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/delay.h>
15#include <linux/errno.h> 16#include <linux/errno.h>
16#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/spinlock.h>
17#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/slab.h>
18#include <linux/mutex.h> 21#include <linux/mutex.h>
19#include <linux/completion.h> 22#include <linux/completion.h>
23#include <linux/irq.h>
20#include <linux/jiffies.h> 24#include <linux/jiffies.h>
21#include <linux/bitops.h> 25#include <linux/bitops.h>
22#include <linux/interrupt.h> 26#include <linux/fs.h>
27#include <linux/platform_device.h>
28#include <linux/uaccess.h>
29#include <linux/mfd/core.h>
23#include <linux/mfd/db8500-prcmu.h> 30#include <linux/mfd/db8500-prcmu.h>
24
25#include <mach/hardware.h> 31#include <mach/hardware.h>
26 32#include <mach/irqs.h>
33#include <mach/db8500-regs.h>
34#include <mach/id.h>
27#include "db8500-prcmu-regs.h" 35#include "db8500-prcmu-regs.h"
28 36
29/* Global var to runtime determine TCDM base for v2 or v1 */ 37/* Offset for the firmware version within the TCPM */
30static __iomem void *tcdm_base; 38#define PRCMU_FW_VERSION_OFFSET 0xA4
31 39
32#define _MBOX_HEADER (tcdm_base + 0xFE8) 40/* PRCMU project numbers, defined by PRCMU FW */
33#define MBOX_HEADER_REQ_MB0 (_MBOX_HEADER + 0x0) 41#define PRCMU_PROJECT_ID_8500V1_0 1
42#define PRCMU_PROJECT_ID_8500V2_0 2
43#define PRCMU_PROJECT_ID_8400V2_0 3
34 44
35#define REQ_MB1 (tcdm_base + 0xFD0) 45/* Index of different voltages to be used when accessing AVSData */
36#define REQ_MB5 (tcdm_base + 0xE44) 46#define PRCM_AVS_BASE 0x2FC
47#define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
48#define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
49#define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
50#define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
51#define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
52#define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
53#define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
54#define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
55#define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
56#define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
57#define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
58#define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
59#define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
37 60
38#define REQ_MB1_ARMOPP (REQ_MB1 + 0x0) 61#define PRCM_AVS_VOLTAGE 0
39#define REQ_MB1_APEOPP (REQ_MB1 + 0x1) 62#define PRCM_AVS_VOLTAGE_MASK 0x3f
40#define REQ_MB1_BOOSTOPP (REQ_MB1 + 0x2) 63#define PRCM_AVS_ISSLOWSTARTUP 6
64#define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
65#define PRCM_AVS_ISMODEENABLE 7
66#define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
41 67
42#define ACK_MB1 (tcdm_base + 0xE04) 68#define PRCM_BOOT_STATUS 0xFFF
43#define ACK_MB5 (tcdm_base + 0xDF4) 69#define PRCM_ROMCODE_A2P 0xFFE
70#define PRCM_ROMCODE_P2A 0xFFD
71#define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */
44 72
45#define ACK_MB1_CURR_ARMOPP (ACK_MB1 + 0x0) 73#define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */
46#define ACK_MB1_CURR_APEOPP (ACK_MB1 + 0x1)
47 74
48#define REQ_MB5_I2C_SLAVE_OP (REQ_MB5) 75#define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */
49#define REQ_MB5_I2C_HW_BITS (REQ_MB5 + 1) 76#define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
50#define REQ_MB5_I2C_REG (REQ_MB5 + 2) 77#define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
51#define REQ_MB5_I2C_VAL (REQ_MB5 + 3) 78#define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
79#define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
80#define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
81#define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
82#define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
52 83
53#define ACK_MB5_I2C_STATUS (ACK_MB5 + 1) 84/* Req Mailboxes */
54#define ACK_MB5_I2C_VAL (ACK_MB5 + 3) 85#define PRCM_REQ_MB0 0xFDC /* 12 bytes */
86#define PRCM_REQ_MB1 0xFD0 /* 12 bytes */
87#define PRCM_REQ_MB2 0xFC0 /* 16 bytes */
88#define PRCM_REQ_MB3 0xE4C /* 372 bytes */
89#define PRCM_REQ_MB4 0xE48 /* 4 bytes */
90#define PRCM_REQ_MB5 0xE44 /* 4 bytes */
55 91
56#define PRCM_AVS_VARM_MAX_OPP (tcdm_base + 0x2E4) 92/* Ack Mailboxes */
57#define PRCM_AVS_ISMODEENABLE 7 93#define PRCM_ACK_MB0 0xE08 /* 52 bytes */
58#define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE) 94#define PRCM_ACK_MB1 0xE04 /* 4 bytes */
95#define PRCM_ACK_MB2 0xE00 /* 4 bytes */
96#define PRCM_ACK_MB3 0xDFC /* 4 bytes */
97#define PRCM_ACK_MB4 0xDF8 /* 4 bytes */
98#define PRCM_ACK_MB5 0xDF4 /* 4 bytes */
99
100/* Mailbox 0 headers */
101#define MB0H_POWER_STATE_TRANS 0
102#define MB0H_CONFIG_WAKEUPS_EXE 1
103#define MB0H_READ_WAKEUP_ACK 3
104#define MB0H_CONFIG_WAKEUPS_SLEEP 4
105
106#define MB0H_WAKEUP_EXE 2
107#define MB0H_WAKEUP_SLEEP 5
108
109/* Mailbox 0 REQs */
110#define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
111#define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
112#define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
113#define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
114#define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
115#define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
116
117/* Mailbox 0 ACKs */
118#define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
119#define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
120#define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
121#define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
122#define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
123#define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
124#define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
125
126/* Mailbox 1 headers */
127#define MB1H_ARM_APE_OPP 0x0
128#define MB1H_RESET_MODEM 0x2
129#define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
130#define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
131#define MB1H_RELEASE_USB_WAKEUP 0x5
132
133/* Mailbox 1 Requests */
134#define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
135#define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
136#define PRCM_REQ_MB1_APE_OPP_100_RESTORE (PRCM_REQ_MB1 + 0x4)
137#define PRCM_REQ_MB1_ARM_OPP_100_RESTORE (PRCM_REQ_MB1 + 0x8)
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)
59 160
60#define I2C_WRITE(slave) \ 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
185
186/* Mailbox 4 Requests */
187#define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
188#define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
189#define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
190#define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
191#define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
192#define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
193#define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
194#define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
195#define HOTMON_CONFIG_LOW BIT(0)
196#define HOTMON_CONFIG_HIGH BIT(1)
197
198/* Mailbox 5 Requests */
199#define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
200#define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
201#define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
202#define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
203#define PRCMU_I2C_WRITE(slave) \
61 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0)) 204 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0))
62#define I2C_READ(slave) \ 205#define PRCMU_I2C_READ(slave) \
63 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0) | BIT(0)) 206 (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0))
64#define I2C_STOP_EN BIT(3) 207#define PRCMU_I2C_STOP_EN BIT(3)
65 208
66enum mb1_h { 209/* Mailbox 5 ACKs */
67 MB1H_ARM_OPP = 1, 210#define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
68 MB1H_APE_OPP, 211#define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
69 MB1H_ARM_APE_OPP, 212#define I2C_WR_OK 0x1
213#define I2C_RD_OK 0x2
214
215#define NUM_MB 8
216#define MBOX_BIT BIT
217#define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
218
219/*
220 * Wakeups/IRQs
221 */
222
223#define WAKEUP_BIT_RTC BIT(0)
224#define WAKEUP_BIT_RTT0 BIT(1)
225#define WAKEUP_BIT_RTT1 BIT(2)
226#define WAKEUP_BIT_HSI0 BIT(3)
227#define WAKEUP_BIT_HSI1 BIT(4)
228#define WAKEUP_BIT_CA_WAKE BIT(5)
229#define WAKEUP_BIT_USB BIT(6)
230#define WAKEUP_BIT_ABB BIT(7)
231#define WAKEUP_BIT_ABB_FIFO BIT(8)
232#define WAKEUP_BIT_SYSCLK_OK BIT(9)
233#define WAKEUP_BIT_CA_SLEEP BIT(10)
234#define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
235#define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
236#define WAKEUP_BIT_ANC_OK BIT(13)
237#define WAKEUP_BIT_SW_ERROR BIT(14)
238#define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
239#define WAKEUP_BIT_ARM BIT(17)
240#define WAKEUP_BIT_HOTMON_LOW BIT(18)
241#define WAKEUP_BIT_HOTMON_HIGH BIT(19)
242#define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
243#define WAKEUP_BIT_GPIO0 BIT(23)
244#define WAKEUP_BIT_GPIO1 BIT(24)
245#define WAKEUP_BIT_GPIO2 BIT(25)
246#define WAKEUP_BIT_GPIO3 BIT(26)
247#define WAKEUP_BIT_GPIO4 BIT(27)
248#define WAKEUP_BIT_GPIO5 BIT(28)
249#define WAKEUP_BIT_GPIO6 BIT(29)
250#define WAKEUP_BIT_GPIO7 BIT(30)
251#define WAKEUP_BIT_GPIO8 BIT(31)
252
253/*
254 * This vector maps irq numbers to the bits in the bit field used in
255 * communication with the PRCMU firmware.
256 *
257 * The reason for having this is to keep the irq numbers contiguous even though
258 * the bits in the bit field are not. (The bits also have a tendency to move
259 * around, to further complicate matters.)
260 */
261#define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE)
262#define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
263static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
264 IRQ_ENTRY(RTC),
265 IRQ_ENTRY(RTT0),
266 IRQ_ENTRY(RTT1),
267 IRQ_ENTRY(HSI0),
268 IRQ_ENTRY(HSI1),
269 IRQ_ENTRY(CA_WAKE),
270 IRQ_ENTRY(USB),
271 IRQ_ENTRY(ABB),
272 IRQ_ENTRY(ABB_FIFO),
273 IRQ_ENTRY(CA_SLEEP),
274 IRQ_ENTRY(ARM),
275 IRQ_ENTRY(HOTMON_LOW),
276 IRQ_ENTRY(HOTMON_HIGH),
277 IRQ_ENTRY(MODEM_SW_RESET_REQ),
278 IRQ_ENTRY(GPIO0),
279 IRQ_ENTRY(GPIO1),
280 IRQ_ENTRY(GPIO2),
281 IRQ_ENTRY(GPIO3),
282 IRQ_ENTRY(GPIO4),
283 IRQ_ENTRY(GPIO5),
284 IRQ_ENTRY(GPIO6),
285 IRQ_ENTRY(GPIO7),
286 IRQ_ENTRY(GPIO8)
287};
288
289#define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
290#define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
291static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = {
292 WAKEUP_ENTRY(RTC),
293 WAKEUP_ENTRY(RTT0),
294 WAKEUP_ENTRY(RTT1),
295 WAKEUP_ENTRY(HSI0),
296 WAKEUP_ENTRY(HSI1),
297 WAKEUP_ENTRY(USB),
298 WAKEUP_ENTRY(ABB),
299 WAKEUP_ENTRY(ABB_FIFO),
300 WAKEUP_ENTRY(ARM)
70}; 301};
71 302
303/*
304 * mb0_transfer - state needed for mailbox 0 communication.
305 * @lock: The transaction lock.
306 * @dbb_events_lock: A lock used to handle concurrent access to (parts of)
307 * the request data.
308 * @mask_work: Work structure used for (un)masking wakeup interrupts.
309 * @req: Request data that need to persist between requests.
310 */
311static struct {
312 spinlock_t lock;
313 spinlock_t dbb_irqs_lock;
314 struct work_struct mask_work;
315 struct mutex ac_wake_lock;
316 struct completion ac_wake_work;
317 struct {
318 u32 dbb_irqs;
319 u32 dbb_wakeups;
320 u32 abb_events;
321 } req;
322} mb0_transfer;
323
324/*
325 * mb1_transfer - state needed for mailbox 1 communication.
326 * @lock: The transaction lock.
327 * @work: The transaction completion structure.
328 * @ack: Reply ("acknowledge") data.
329 */
72static struct { 330static struct {
73 struct mutex lock; 331 struct mutex lock;
74 struct completion work; 332 struct completion work;
75 struct { 333 struct {
334 u8 header;
76 u8 arm_opp; 335 u8 arm_opp;
77 u8 ape_opp; 336 u8 ape_opp;
78 u8 arm_status; 337 u8 ape_voltage_status;
79 u8 ape_status;
80 } ack; 338 } ack;
81} mb1_transfer; 339} mb1_transfer;
82 340
83enum ack_mb5_status { 341/*
84 I2C_WR_OK = 0x01, 342 * mb2_transfer - state needed for mailbox 2 communication.
85 I2C_RD_OK = 0x02, 343 * @lock: The transaction lock.
86}; 344 * @work: The transaction completion structure.
345 * @auto_pm_lock: The autonomous power management configuration lock.
346 * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled.
347 * @req: Request data that need to persist between requests.
348 * @ack: Reply ("acknowledge") data.
349 */
350static struct {
351 struct mutex lock;
352 struct completion work;
353 spinlock_t auto_pm_lock;
354 bool auto_pm_enabled;
355 struct {
356 u8 status;
357 } ack;
358} mb2_transfer;
87 359
88#define MBOX_BIT BIT 360/*
89#define NUM_MBOX 8 361 * mb3_transfer - state needed for mailbox 3 communication.
362 * @lock: The request lock.
363 * @sysclk_lock: A lock used to handle concurrent sysclk requests.
364 * @sysclk_work: Work structure used for sysclk requests.
365 */
366static struct {
367 spinlock_t lock;
368 struct mutex sysclk_lock;
369 struct completion sysclk_work;
370} mb3_transfer;
90 371
372/*
373 * mb4_transfer - state needed for mailbox 4 communication.
374 * @lock: The transaction lock.
375 * @work: The transaction completion structure.
376 */
377static struct {
378 struct mutex lock;
379 struct completion work;
380} mb4_transfer;
381
382/*
383 * mb5_transfer - state needed for mailbox 5 communication.
384 * @lock: The transaction lock.
385 * @work: The transaction completion structure.
386 * @ack: Reply ("acknowledge") data.
387 */
91static struct { 388static struct {
92 struct mutex lock; 389 struct mutex lock;
93 struct completion work; 390 struct completion work;
94 bool failed;
95 struct { 391 struct {
96 u8 status; 392 u8 status;
97 u8 value; 393 u8 value;
98 } ack; 394 } ack;
99} mb5_transfer; 395} mb5_transfer;
100 396
397static atomic_t ac_wake_req_state = ATOMIC_INIT(0);
398
399/* Spinlocks */
400static DEFINE_SPINLOCK(clkout_lock);
401static DEFINE_SPINLOCK(gpiocr_lock);
402
403/* Global var to runtime determine TCDM base for v2 or v1 */
404static __iomem void *tcdm_base;
405
406struct clk_mgt {
407 unsigned int offset;
408 u32 pllsw;
409};
410
411static DEFINE_SPINLOCK(clk_mgt_lock);
412
413#define CLK_MGT_ENTRY(_name)[PRCMU_##_name] = { (PRCM_##_name##_MGT), 0 }
414struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
415 CLK_MGT_ENTRY(SGACLK),
416 CLK_MGT_ENTRY(UARTCLK),
417 CLK_MGT_ENTRY(MSP02CLK),
418 CLK_MGT_ENTRY(MSP1CLK),
419 CLK_MGT_ENTRY(I2CCLK),
420 CLK_MGT_ENTRY(SDMMCCLK),
421 CLK_MGT_ENTRY(SLIMCLK),
422 CLK_MGT_ENTRY(PER1CLK),
423 CLK_MGT_ENTRY(PER2CLK),
424 CLK_MGT_ENTRY(PER3CLK),
425 CLK_MGT_ENTRY(PER5CLK),
426 CLK_MGT_ENTRY(PER6CLK),
427 CLK_MGT_ENTRY(PER7CLK),
428 CLK_MGT_ENTRY(LCDCLK),
429 CLK_MGT_ENTRY(BMLCLK),
430 CLK_MGT_ENTRY(HSITXCLK),
431 CLK_MGT_ENTRY(HSIRXCLK),
432 CLK_MGT_ENTRY(HDMICLK),
433 CLK_MGT_ENTRY(APEATCLK),
434 CLK_MGT_ENTRY(APETRACECLK),
435 CLK_MGT_ENTRY(MCDECLK),
436 CLK_MGT_ENTRY(IPI2CCLK),
437 CLK_MGT_ENTRY(DSIALTCLK),
438 CLK_MGT_ENTRY(DMACLK),
439 CLK_MGT_ENTRY(B2R2CLK),
440 CLK_MGT_ENTRY(TVCLK),
441 CLK_MGT_ENTRY(SSPCLK),
442 CLK_MGT_ENTRY(RNGCLK),
443 CLK_MGT_ENTRY(UICCCLK),
444};
445
446/*
447* Used by MCDE to setup all necessary PRCMU registers
448*/
449#define PRCMU_RESET_DSIPLL 0x00004000
450#define PRCMU_UNCLAMP_DSIPLL 0x00400800
451
452#define PRCMU_CLK_PLL_DIV_SHIFT 0
453#define PRCMU_CLK_PLL_SW_SHIFT 5
454#define PRCMU_CLK_38 (1 << 9)
455#define PRCMU_CLK_38_SRC (1 << 10)
456#define PRCMU_CLK_38_DIV (1 << 11)
457
458/* PLLDIV=12, PLLSW=4 (PLLDDR) */
459#define PRCMU_DSI_CLOCK_SETTING 0x0000008C
460
461/* PLLDIV=8, PLLSW=4 (PLLDDR) */
462#define PRCMU_DSI_CLOCK_SETTING_U8400 0x00000088
463
464/* DPI 50000000 Hz */
465#define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
466 (16 << PRCMU_CLK_PLL_DIV_SHIFT))
467#define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
468
469/* D=101, N=1, R=4, SELDIV2=0 */
470#define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
471
472/* D=70, N=1, R=3, SELDIV2=0 */
473#define PRCMU_PLLDSI_FREQ_SETTING_U8400 0x00030146
474
475#define PRCMU_ENABLE_PLLDSI 0x00000001
476#define PRCMU_DISABLE_PLLDSI 0x00000000
477#define PRCMU_RELEASE_RESET_DSS 0x0000400C
478#define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
479/* ESC clk, div0=1, div1=1, div2=3 */
480#define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
481#define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
482#define PRCMU_DSI_RESET_SW 0x00000007
483
484#define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
485
486static struct {
487 u8 project_number;
488 u8 api_version;
489 u8 func_version;
490 u8 errata;
491} prcmu_version;
492
493
494int prcmu_enable_dsipll(void)
495{
496 int i;
497 unsigned int plldsifreq;
498
499 /* Clear DSIPLL_RESETN */
500 writel(PRCMU_RESET_DSIPLL, (_PRCMU_BASE + PRCM_APE_RESETN_CLR));
501 /* Unclamp DSIPLL in/out */
502 writel(PRCMU_UNCLAMP_DSIPLL, (_PRCMU_BASE + PRCM_MMIP_LS_CLAMP_CLR));
503
504 if (prcmu_is_u8400())
505 plldsifreq = PRCMU_PLLDSI_FREQ_SETTING_U8400;
506 else
507 plldsifreq = PRCMU_PLLDSI_FREQ_SETTING;
508 /* Set DSI PLL FREQ */
509 writel(plldsifreq, (_PRCMU_BASE + PRCM_PLLDSI_FREQ));
510 writel(PRCMU_DSI_PLLOUT_SEL_SETTING,
511 (_PRCMU_BASE + PRCM_DSI_PLLOUT_SEL));
512 /* Enable Escape clocks */
513 writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV,
514 (_PRCMU_BASE + PRCM_DSITVCLK_DIV));
515
516 /* Start DSI PLL */
517 writel(PRCMU_ENABLE_PLLDSI, (_PRCMU_BASE + PRCM_PLLDSI_ENABLE));
518 /* Reset DSI PLL */
519 writel(PRCMU_DSI_RESET_SW, (_PRCMU_BASE + PRCM_DSI_SW_RESET));
520 for (i = 0; i < 10; i++) {
521 if ((readl(_PRCMU_BASE + PRCM_PLLDSI_LOCKP) &
522 PRCMU_PLLDSI_LOCKP_LOCKED)
523 == PRCMU_PLLDSI_LOCKP_LOCKED)
524 break;
525 udelay(100);
526 }
527 /* Set DSIPLL_RESETN */
528 writel(PRCMU_RESET_DSIPLL, (_PRCMU_BASE + PRCM_APE_RESETN_SET));
529 return 0;
530}
531
532int prcmu_disable_dsipll(void)
533{
534 /* Disable dsi pll */
535 writel(PRCMU_DISABLE_PLLDSI, (_PRCMU_BASE + PRCM_PLLDSI_ENABLE));
536 /* Disable escapeclock */
537 writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV,
538 (_PRCMU_BASE + PRCM_DSITVCLK_DIV));
539 return 0;
540}
541
542int prcmu_set_display_clocks(void)
543{
544 unsigned long flags;
545 unsigned int dsiclk;
546
547 if (prcmu_is_u8400())
548 dsiclk = PRCMU_DSI_CLOCK_SETTING_U8400;
549 else
550 dsiclk = PRCMU_DSI_CLOCK_SETTING;
551
552 spin_lock_irqsave(&clk_mgt_lock, flags);
553
554 /* Grab the HW semaphore. */
555 while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
556 cpu_relax();
557
558 writel(dsiclk, (_PRCMU_BASE + PRCM_HDMICLK_MGT));
559 writel(PRCMU_DSI_LP_CLOCK_SETTING, (_PRCMU_BASE + PRCM_TVCLK_MGT));
560 writel(PRCMU_DPI_CLOCK_SETTING, (_PRCMU_BASE + PRCM_LCDCLK_MGT));
561
562 /* Release the HW semaphore. */
563 writel(0, (_PRCMU_BASE + PRCM_SEM));
564
565 spin_unlock_irqrestore(&clk_mgt_lock, flags);
566
567 return 0;
568}
569
570/**
571 * prcmu_enable_spi2 - Enables pin muxing for SPI2 on OtherAlternateC1.
572 */
573void prcmu_enable_spi2(void)
574{
575 u32 reg;
576 unsigned long flags;
577
578 spin_lock_irqsave(&gpiocr_lock, flags);
579 reg = readl(_PRCMU_BASE + PRCM_GPIOCR);
580 writel(reg | PRCM_GPIOCR_SPI2_SELECT, _PRCMU_BASE + PRCM_GPIOCR);
581 spin_unlock_irqrestore(&gpiocr_lock, flags);
582}
583
584/**
585 * prcmu_disable_spi2 - Disables pin muxing for SPI2 on OtherAlternateC1.
586 */
587void prcmu_disable_spi2(void)
588{
589 u32 reg;
590 unsigned long flags;
591
592 spin_lock_irqsave(&gpiocr_lock, flags);
593 reg = readl(_PRCMU_BASE + PRCM_GPIOCR);
594 writel(reg & ~PRCM_GPIOCR_SPI2_SELECT, _PRCMU_BASE + PRCM_GPIOCR);
595 spin_unlock_irqrestore(&gpiocr_lock, flags);
596}
597
598bool prcmu_has_arm_maxopp(void)
599{
600 return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) &
601 PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK;
602}
603
604bool prcmu_is_u8400(void)
605{
606 return prcmu_version.project_number == PRCMU_PROJECT_ID_8400V2_0;
607}
608
609/**
610 * prcmu_get_boot_status - PRCMU boot status checking
611 * Returns: the current PRCMU boot status
612 */
613int prcmu_get_boot_status(void)
614{
615 return readb(tcdm_base + PRCM_BOOT_STATUS);
616}
617
618/**
619 * prcmu_set_rc_a2p - This function is used to run few power state sequences
620 * @val: Value to be set, i.e. transition requested
621 * Returns: 0 on success, -EINVAL on invalid argument
622 *
623 * This function is used to run the following power state sequences -
624 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
625 */
626int prcmu_set_rc_a2p(enum romcode_write val)
627{
628 if (val < RDY_2_DS || val > RDY_2_XP70_RST)
629 return -EINVAL;
630 writeb(val, (tcdm_base + PRCM_ROMCODE_A2P));
631 return 0;
632}
633
634/**
635 * prcmu_get_rc_p2a - This function is used to get power state sequences
636 * Returns: the power transition that has last happened
637 *
638 * This function can return the following transitions-
639 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
640 */
641enum romcode_read prcmu_get_rc_p2a(void)
642{
643 return readb(tcdm_base + PRCM_ROMCODE_P2A);
644}
645
646/**
647 * prcmu_get_current_mode - Return the current XP70 power mode
648 * Returns: Returns the current AP(ARM) power mode: init,
649 * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset
650 */
651enum ap_pwrst prcmu_get_xp70_current_state(void)
652{
653 return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE);
654}
655
656/**
657 * prcmu_config_clkout - Configure one of the programmable clock outputs.
658 * @clkout: The CLKOUT number (0 or 1).
659 * @source: The clock to be used (one of the PRCMU_CLKSRC_*).
660 * @div: The divider to be applied.
661 *
662 * Configures one of the programmable clock outputs (CLKOUTs).
663 * @div should be in the range [1,63] to request a configuration, or 0 to
664 * inform that the configuration is no longer requested.
665 */
666int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
667{
668 static int requests[2];
669 int r = 0;
670 unsigned long flags;
671 u32 val;
672 u32 bits;
673 u32 mask;
674 u32 div_mask;
675
676 BUG_ON(clkout > 1);
677 BUG_ON(div > 63);
678 BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009));
679
680 if (!div && !requests[clkout])
681 return -EINVAL;
682
683 switch (clkout) {
684 case 0:
685 div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
686 mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
687 bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
688 (div << PRCM_CLKOCR_CLKODIV0_SHIFT));
689 break;
690 case 1:
691 div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
692 mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
693 PRCM_CLKOCR_CLK1TYPE);
694 bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
695 (div << PRCM_CLKOCR_CLKODIV1_SHIFT));
696 break;
697 }
698 bits &= mask;
699
700 spin_lock_irqsave(&clkout_lock, flags);
701
702 val = readl(_PRCMU_BASE + PRCM_CLKOCR);
703 if (val & div_mask) {
704 if (div) {
705 if ((val & mask) != bits) {
706 r = -EBUSY;
707 goto unlock_and_return;
708 }
709 } else {
710 if ((val & mask & ~div_mask) != bits) {
711 r = -EINVAL;
712 goto unlock_and_return;
713 }
714 }
715 }
716 writel((bits | (val & ~mask)), (_PRCMU_BASE + PRCM_CLKOCR));
717 requests[clkout] += (div ? 1 : -1);
718
719unlock_and_return:
720 spin_unlock_irqrestore(&clkout_lock, flags);
721
722 return r;
723}
724
725int prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
726{
727 unsigned long flags;
728
729 BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state));
730
731 spin_lock_irqsave(&mb0_transfer.lock, flags);
732
733 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
734 cpu_relax();
735
736 writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
737 writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE));
738 writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE));
739 writeb((keep_ulp_clk ? 1 : 0),
740 (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
741 writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
742 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
743
744 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
745
746 return 0;
747}
748
749/* This function should only be called while mb0_transfer.lock is held. */
750static void config_wakeups(void)
751{
752 const u8 header[2] = {
753 MB0H_CONFIG_WAKEUPS_EXE,
754 MB0H_CONFIG_WAKEUPS_SLEEP
755 };
756 static u32 last_dbb_events;
757 static u32 last_abb_events;
758 u32 dbb_events;
759 u32 abb_events;
760 unsigned int i;
761
762 dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
763 dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK);
764
765 abb_events = mb0_transfer.req.abb_events;
766
767 if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
768 return;
769
770 for (i = 0; i < 2; i++) {
771 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
772 cpu_relax();
773 writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
774 writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
775 writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
776 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
777 }
778 last_dbb_events = dbb_events;
779 last_abb_events = abb_events;
780}
781
782void prcmu_enable_wakeups(u32 wakeups)
783{
784 unsigned long flags;
785 u32 bits;
786 int i;
787
788 BUG_ON(wakeups != (wakeups & VALID_WAKEUPS));
789
790 for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) {
791 if (wakeups & BIT(i))
792 bits |= prcmu_wakeup_bit[i];
793 }
794
795 spin_lock_irqsave(&mb0_transfer.lock, flags);
796
797 mb0_transfer.req.dbb_wakeups = bits;
798 config_wakeups();
799
800 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
801}
802
803void prcmu_config_abb_event_readout(u32 abb_events)
804{
805 unsigned long flags;
806
807 spin_lock_irqsave(&mb0_transfer.lock, flags);
808
809 mb0_transfer.req.abb_events = abb_events;
810 config_wakeups();
811
812 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
813}
814
815void prcmu_get_abb_event_buffer(void __iomem **buf)
816{
817 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
818 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
819 else
820 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500);
821}
822
823/**
824 * prcmu_set_arm_opp - set the appropriate ARM OPP
825 * @opp: The new ARM operating point to which transition is to be made
826 * Returns: 0 on success, non-zero on failure
827 *
828 * This function sets the the operating point of the ARM.
829 */
830int prcmu_set_arm_opp(u8 opp)
831{
832 int r;
833
834 if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK)
835 return -EINVAL;
836
837 r = 0;
838
839 mutex_lock(&mb1_transfer.lock);
840
841 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
842 cpu_relax();
843
844 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
845 writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
846 writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
847
848 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
849 wait_for_completion(&mb1_transfer.work);
850
851 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
852 (mb1_transfer.ack.arm_opp != opp))
853 r = -EIO;
854
855 mutex_unlock(&mb1_transfer.lock);
856
857 return r;
858}
859
860/**
861 * prcmu_get_arm_opp - get the current ARM OPP
862 *
863 * Returns: the current ARM OPP
864 */
865int prcmu_get_arm_opp(void)
866{
867 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
868}
869
870/**
871 * prcmu_get_ddr_opp - get the current DDR OPP
872 *
873 * Returns: the current DDR OPP
874 */
875int prcmu_get_ddr_opp(void)
876{
877 return readb(_PRCMU_BASE + PRCM_DDR_SUBSYS_APE_MINBW);
878}
879
880/**
881 * set_ddr_opp - set the appropriate DDR OPP
882 * @opp: The new DDR operating point to which transition is to be made
883 * Returns: 0 on success, non-zero on failure
884 *
885 * This function sets the operating point of the DDR.
886 */
887int prcmu_set_ddr_opp(u8 opp)
888{
889 if (opp < DDR_100_OPP || opp > DDR_25_OPP)
890 return -EINVAL;
891 /* Changing the DDR OPP can hang the hardware pre-v21 */
892 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
893 writeb(opp, (_PRCMU_BASE + PRCM_DDR_SUBSYS_APE_MINBW));
894
895 return 0;
896}
897/**
898 * set_ape_opp - set the appropriate APE OPP
899 * @opp: The new APE operating point to which transition is to be made
900 * Returns: 0 on success, non-zero on failure
901 *
902 * This function sets the operating point of the APE.
903 */
904int prcmu_set_ape_opp(u8 opp)
905{
906 int r = 0;
907
908 mutex_lock(&mb1_transfer.lock);
909
910 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
911 cpu_relax();
912
913 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
914 writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
915 writeb(opp, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
916
917 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
918 wait_for_completion(&mb1_transfer.work);
919
920 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
921 (mb1_transfer.ack.ape_opp != opp))
922 r = -EIO;
923
924 mutex_unlock(&mb1_transfer.lock);
925
926 return r;
927}
928
929/**
930 * prcmu_get_ape_opp - get the current APE OPP
931 *
932 * Returns: the current APE OPP
933 */
934int prcmu_get_ape_opp(void)
935{
936 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP);
937}
938
939/**
940 * prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage
941 * @enable: true to request the higher voltage, false to drop a request.
942 *
943 * Calls to this function to enable and disable requests must be balanced.
944 */
945int prcmu_request_ape_opp_100_voltage(bool enable)
946{
947 int r = 0;
948 u8 header;
949 static unsigned int requests;
950
951 mutex_lock(&mb1_transfer.lock);
952
953 if (enable) {
954 if (0 != requests++)
955 goto unlock_and_return;
956 header = MB1H_REQUEST_APE_OPP_100_VOLT;
957 } else {
958 if (requests == 0) {
959 r = -EIO;
960 goto unlock_and_return;
961 } else if (1 != requests--) {
962 goto unlock_and_return;
963 }
964 header = MB1H_RELEASE_APE_OPP_100_VOLT;
965 }
966
967 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
968 cpu_relax();
969
970 writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
971
972 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
973 wait_for_completion(&mb1_transfer.work);
974
975 if ((mb1_transfer.ack.header != header) ||
976 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
977 r = -EIO;
978
979unlock_and_return:
980 mutex_unlock(&mb1_transfer.lock);
981
982 return r;
983}
984
985/**
986 * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup
987 *
988 * This function releases the power state requirements of a USB wakeup.
989 */
990int prcmu_release_usb_wakeup_state(void)
991{
992 int r = 0;
993
994 mutex_lock(&mb1_transfer.lock);
995
996 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
997 cpu_relax();
998
999 writeb(MB1H_RELEASE_USB_WAKEUP,
1000 (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1001
1002 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1003 wait_for_completion(&mb1_transfer.work);
1004
1005 if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
1006 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
1007 r = -EIO;
1008
1009 mutex_unlock(&mb1_transfer.lock);
1010
1011 return r;
1012}
1013
1014/**
1015 * prcmu_set_epod - set the state of a EPOD (power domain)
1016 * @epod_id: The EPOD to set
1017 * @epod_state: The new EPOD state
1018 *
1019 * This function sets the state of a EPOD (power domain). It may not be called
1020 * from interrupt context.
1021 */
1022int prcmu_set_epod(u16 epod_id, u8 epod_state)
1023{
1024 int r = 0;
1025 bool ram_retention = false;
1026 int i;
1027
1028 /* check argument */
1029 BUG_ON(epod_id >= NUM_EPOD_ID);
1030
1031 /* set flag if retention is possible */
1032 switch (epod_id) {
1033 case EPOD_ID_SVAMMDSP:
1034 case EPOD_ID_SIAMMDSP:
1035 case EPOD_ID_ESRAM12:
1036 case EPOD_ID_ESRAM34:
1037 ram_retention = true;
1038 break;
1039 }
1040
1041 /* check argument */
1042 BUG_ON(epod_state > EPOD_STATE_ON);
1043 BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention);
1044
1045 /* get lock */
1046 mutex_lock(&mb2_transfer.lock);
1047
1048 /* wait for mailbox */
1049 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
1050 cpu_relax();
1051
1052 /* fill in mailbox */
1053 for (i = 0; i < NUM_EPOD_ID; i++)
1054 writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i));
1055 writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id));
1056
1057 writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
1058
1059 writel(MBOX_BIT(2), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1060
1061 /*
1062 * The current firmware version does not handle errors correctly,
1063 * and we cannot recover if there is an error.
1064 * This is expected to change when the firmware is updated.
1065 */
1066 if (!wait_for_completion_timeout(&mb2_transfer.work,
1067 msecs_to_jiffies(20000))) {
1068 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1069 __func__);
1070 r = -EIO;
1071 goto unlock_and_return;
1072 }
1073
1074 if (mb2_transfer.ack.status != HWACC_PWR_ST_OK)
1075 r = -EIO;
1076
1077unlock_and_return:
1078 mutex_unlock(&mb2_transfer.lock);
1079 return r;
1080}
1081
1082/**
1083 * prcmu_configure_auto_pm - Configure autonomous power management.
1084 * @sleep: Configuration for ApSleep.
1085 * @idle: Configuration for ApIdle.
1086 */
1087void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
1088 struct prcmu_auto_pm_config *idle)
1089{
1090 u32 sleep_cfg;
1091 u32 idle_cfg;
1092 unsigned long flags;
1093
1094 BUG_ON((sleep == NULL) || (idle == NULL));
1095
1096 sleep_cfg = (sleep->sva_auto_pm_enable & 0xF);
1097 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF));
1098 sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF));
1099 sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF));
1100 sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF));
1101 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF));
1102
1103 idle_cfg = (idle->sva_auto_pm_enable & 0xF);
1104 idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF));
1105 idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF));
1106 idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF));
1107 idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF));
1108 idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF));
1109
1110 spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags);
1111
1112 /*
1113 * The autonomous power management configuration is done through
1114 * fields in mailbox 2, but these fields are only used as shared
1115 * variables - i.e. there is no need to send a message.
1116 */
1117 writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP));
1118 writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE));
1119
1120 mb2_transfer.auto_pm_enabled =
1121 ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1122 (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1123 (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1124 (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON));
1125
1126 spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
1127}
1128EXPORT_SYMBOL(prcmu_configure_auto_pm);
1129
1130bool prcmu_is_auto_pm_enabled(void)
1131{
1132 return mb2_transfer.auto_pm_enabled;
1133}
1134
1135static int request_sysclk(bool enable)
1136{
1137 int r;
1138 unsigned long flags;
1139
1140 r = 0;
1141
1142 mutex_lock(&mb3_transfer.sysclk_lock);
1143
1144 spin_lock_irqsave(&mb3_transfer.lock, flags);
1145
1146 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
1147 cpu_relax();
1148
1149 writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
1150
1151 writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
1152 writel(MBOX_BIT(3), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1153
1154 spin_unlock_irqrestore(&mb3_transfer.lock, flags);
1155
1156 /*
1157 * The firmware only sends an ACK if we want to enable the
1158 * SysClk, and it succeeds.
1159 */
1160 if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work,
1161 msecs_to_jiffies(20000))) {
1162 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1163 __func__);
1164 r = -EIO;
1165 }
1166
1167 mutex_unlock(&mb3_transfer.sysclk_lock);
1168
1169 return r;
1170}
1171
1172static int request_timclk(bool enable)
1173{
1174 u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK);
1175
1176 if (!enable)
1177 val |= PRCM_TCR_STOP_TIMERS;
1178 writel(val, (_PRCMU_BASE + PRCM_TCR));
1179
1180 return 0;
1181}
1182
1183static int request_reg_clock(u8 clock, bool enable)
1184{
1185 u32 val;
1186 unsigned long flags;
1187
1188 spin_lock_irqsave(&clk_mgt_lock, flags);
1189
1190 /* Grab the HW semaphore. */
1191 while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1192 cpu_relax();
1193
1194 val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
1195 if (enable) {
1196 val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw);
1197 } else {
1198 clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
1199 val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK);
1200 }
1201 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
1202
1203 /* Release the HW semaphore. */
1204 writel(0, (_PRCMU_BASE + PRCM_SEM));
1205
1206 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1207
1208 return 0;
1209}
1210
1211/**
1212 * prcmu_request_clock() - Request for a clock to be enabled or disabled.
1213 * @clock: The clock for which the request is made.
1214 * @enable: Whether the clock should be enabled (true) or disabled (false).
1215 *
1216 * This function should only be used by the clock implementation.
1217 * Do not use it from any other place!
1218 */
1219int prcmu_request_clock(u8 clock, bool enable)
1220{
1221 if (clock < PRCMU_NUM_REG_CLOCKS)
1222 return request_reg_clock(clock, enable);
1223 else if (clock == PRCMU_TIMCLK)
1224 return request_timclk(enable);
1225 else if (clock == PRCMU_SYSCLK)
1226 return request_sysclk(enable);
1227 else
1228 return -EINVAL;
1229}
1230
1231int prcmu_config_esram0_deep_sleep(u8 state)
1232{
1233 if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
1234 (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
1235 return -EINVAL;
1236
1237 mutex_lock(&mb4_transfer.lock);
1238
1239 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1240 cpu_relax();
1241
1242 writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1243 writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON),
1244 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE));
1245 writeb(DDR_PWR_STATE_ON,
1246 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
1247 writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
1248
1249 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1250 wait_for_completion(&mb4_transfer.work);
1251
1252 mutex_unlock(&mb4_transfer.lock);
1253
1254 return 0;
1255}
1256
1257int prcmu_config_hotdog(u8 threshold)
1258{
1259 mutex_lock(&mb4_transfer.lock);
1260
1261 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1262 cpu_relax();
1263
1264 writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
1265 writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1266
1267 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1268 wait_for_completion(&mb4_transfer.work);
1269
1270 mutex_unlock(&mb4_transfer.lock);
1271
1272 return 0;
1273}
1274
1275int prcmu_config_hotmon(u8 low, u8 high)
1276{
1277 mutex_lock(&mb4_transfer.lock);
1278
1279 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1280 cpu_relax();
1281
1282 writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
1283 writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH));
1284 writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH),
1285 (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
1286 writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1287
1288 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1289 wait_for_completion(&mb4_transfer.work);
1290
1291 mutex_unlock(&mb4_transfer.lock);
1292
1293 return 0;
1294}
1295
1296static int config_hot_period(u16 val)
1297{
1298 mutex_lock(&mb4_transfer.lock);
1299
1300 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1301 cpu_relax();
1302
1303 writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
1304 writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1305
1306 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1307 wait_for_completion(&mb4_transfer.work);
1308
1309 mutex_unlock(&mb4_transfer.lock);
1310
1311 return 0;
1312}
1313
1314int prcmu_start_temp_sense(u16 cycles32k)
1315{
1316 if (cycles32k == 0xFFFF)
1317 return -EINVAL;
1318
1319 return config_hot_period(cycles32k);
1320}
1321
1322int prcmu_stop_temp_sense(void)
1323{
1324 return config_hot_period(0xFFFF);
1325}
1326
1327/**
1328 * prcmu_set_clock_divider() - Configure the clock divider.
1329 * @clock: The clock for which the request is made.
1330 * @divider: The clock divider. (< 32)
1331 *
1332 * This function should only be used by the clock implementation.
1333 * Do not use it from any other place!
1334 */
1335int prcmu_set_clock_divider(u8 clock, u8 divider)
1336{
1337 u32 val;
1338 unsigned long flags;
1339
1340 if ((clock >= PRCMU_NUM_REG_CLOCKS) || (divider < 1) || (31 < divider))
1341 return -EINVAL;
1342
1343 spin_lock_irqsave(&clk_mgt_lock, flags);
1344
1345 /* Grab the HW semaphore. */
1346 while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1347 cpu_relax();
1348
1349 val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
1350 val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK);
1351 val |= (u32)divider;
1352 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
1353
1354 /* Release the HW semaphore. */
1355 writel(0, (_PRCMU_BASE + PRCM_SEM));
1356
1357 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1358
1359 return 0;
1360}
1361
101/** 1362/**
102 * prcmu_abb_read() - Read register value(s) from the ABB. 1363 * prcmu_abb_read() - Read register value(s) from the ABB.
103 * @slave: The I2C slave address. 1364 * @slave: The I2C slave address.
@@ -115,33 +1376,34 @@ int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
115 if (size != 1) 1376 if (size != 1)
116 return -EINVAL; 1377 return -EINVAL;
117 1378
118 r = mutex_lock_interruptible(&mb5_transfer.lock); 1379 mutex_lock(&mb5_transfer.lock);
119 if (r)
120 return r;
121 1380
122 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5)) 1381 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
123 cpu_relax(); 1382 cpu_relax();
124 1383
125 writeb(I2C_READ(slave), REQ_MB5_I2C_SLAVE_OP); 1384 writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
126 writeb(I2C_STOP_EN, REQ_MB5_I2C_HW_BITS); 1385 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
127 writeb(reg, REQ_MB5_I2C_REG); 1386 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
1387 writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
1388
1389 writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
128 1390
129 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
130 if (!wait_for_completion_timeout(&mb5_transfer.work, 1391 if (!wait_for_completion_timeout(&mb5_transfer.work,
131 msecs_to_jiffies(500))) { 1392 msecs_to_jiffies(20000))) {
132 pr_err("prcmu: prcmu_abb_read timed out.\n"); 1393 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1394 __func__);
133 r = -EIO; 1395 r = -EIO;
134 goto unlock_and_return; 1396 } else {
1397 r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO);
135 } 1398 }
136 r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO); 1399
137 if (!r) 1400 if (!r)
138 *value = mb5_transfer.ack.value; 1401 *value = mb5_transfer.ack.value;
139 1402
140unlock_and_return:
141 mutex_unlock(&mb5_transfer.lock); 1403 mutex_unlock(&mb5_transfer.lock);
1404
142 return r; 1405 return r;
143} 1406}
144EXPORT_SYMBOL(prcmu_abb_read);
145 1407
146/** 1408/**
147 * prcmu_abb_write() - Write register value(s) to the ABB. 1409 * prcmu_abb_write() - Write register value(s) to the ABB.
@@ -160,179 +1422,262 @@ int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
160 if (size != 1) 1422 if (size != 1)
161 return -EINVAL; 1423 return -EINVAL;
162 1424
163 r = mutex_lock_interruptible(&mb5_transfer.lock); 1425 mutex_lock(&mb5_transfer.lock);
164 if (r)
165 return r;
166
167 1426
168 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5)) 1427 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
169 cpu_relax(); 1428 cpu_relax();
170 1429
171 writeb(I2C_WRITE(slave), REQ_MB5_I2C_SLAVE_OP); 1430 writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
172 writeb(I2C_STOP_EN, REQ_MB5_I2C_HW_BITS); 1431 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
173 writeb(reg, REQ_MB5_I2C_REG); 1432 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
174 writeb(*value, REQ_MB5_I2C_VAL); 1433 writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
1434
1435 writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
175 1436
176 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
177 if (!wait_for_completion_timeout(&mb5_transfer.work, 1437 if (!wait_for_completion_timeout(&mb5_transfer.work,
178 msecs_to_jiffies(500))) { 1438 msecs_to_jiffies(20000))) {
179 pr_err("prcmu: prcmu_abb_write timed out.\n"); 1439 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1440 __func__);
180 r = -EIO; 1441 r = -EIO;
181 goto unlock_and_return; 1442 } else {
1443 r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
182 } 1444 }
183 r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
184 1445
185unlock_and_return:
186 mutex_unlock(&mb5_transfer.lock); 1446 mutex_unlock(&mb5_transfer.lock);
1447
187 return r; 1448 return r;
188} 1449}
189EXPORT_SYMBOL(prcmu_abb_write);
190 1450
191static int set_ape_cpu_opps(u8 header, enum prcmu_ape_opp ape_opp, 1451/**
192 enum prcmu_cpu_opp cpu_opp) 1452 * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem
1453 */
1454void prcmu_ac_wake_req(void)
193{ 1455{
194 bool do_ape; 1456 u32 val;
195 bool do_arm;
196 int err = 0;
197 1457
198 do_ape = ((header == MB1H_APE_OPP) || (header == MB1H_ARM_APE_OPP)); 1458 mutex_lock(&mb0_transfer.ac_wake_lock);
199 do_arm = ((header == MB1H_ARM_OPP) || (header == MB1H_ARM_APE_OPP));
200 1459
201 mutex_lock(&mb1_transfer.lock); 1460 val = readl(_PRCMU_BASE + PRCM_HOSTACCESS_REQ);
1461 if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
1462 goto unlock_and_return;
202 1463
203 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) 1464 atomic_set(&ac_wake_req_state, 1);
204 cpu_relax();
205 1465
206 writeb(0, MBOX_HEADER_REQ_MB0); 1466 writel((val | PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
207 writeb(cpu_opp, REQ_MB1_ARMOPP); 1467 (_PRCMU_BASE + PRCM_HOSTACCESS_REQ));
208 writeb(ape_opp, REQ_MB1_APEOPP);
209 writeb(0, REQ_MB1_BOOSTOPP);
210 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
211 wait_for_completion(&mb1_transfer.work);
212 if ((do_ape) && (mb1_transfer.ack.ape_status != 0))
213 err = -EIO;
214 if ((do_arm) && (mb1_transfer.ack.arm_status != 0))
215 err = -EIO;
216 1468
217 mutex_unlock(&mb1_transfer.lock); 1469 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
1470 msecs_to_jiffies(20000))) {
1471 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1472 __func__);
1473 }
218 1474
219 return err; 1475unlock_and_return:
1476 mutex_unlock(&mb0_transfer.ac_wake_lock);
220} 1477}
221 1478
222/** 1479/**
223 * prcmu_set_ape_opp() - Set the OPP of the APE. 1480 * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem
224 * @opp: The OPP to set.
225 *
226 * This function sets the OPP of the APE.
227 */ 1481 */
228int prcmu_set_ape_opp(enum prcmu_ape_opp opp) 1482void prcmu_ac_sleep_req()
229{ 1483{
230 return set_ape_cpu_opps(MB1H_APE_OPP, opp, APE_OPP_NO_CHANGE); 1484 u32 val;
1485
1486 mutex_lock(&mb0_transfer.ac_wake_lock);
1487
1488 val = readl(_PRCMU_BASE + PRCM_HOSTACCESS_REQ);
1489 if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
1490 goto unlock_and_return;
1491
1492 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
1493 (_PRCMU_BASE + PRCM_HOSTACCESS_REQ));
1494
1495 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
1496 msecs_to_jiffies(20000))) {
1497 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1498 __func__);
1499 }
1500
1501 atomic_set(&ac_wake_req_state, 0);
1502
1503unlock_and_return:
1504 mutex_unlock(&mb0_transfer.ac_wake_lock);
231} 1505}
232EXPORT_SYMBOL(prcmu_set_ape_opp);
233 1506
234/** 1507bool prcmu_is_ac_wake_requested(void)
235 * prcmu_set_cpu_opp() - Set the OPP of the CPU.
236 * @opp: The OPP to set.
237 *
238 * This function sets the OPP of the CPU.
239 */
240int prcmu_set_cpu_opp(enum prcmu_cpu_opp opp)
241{ 1508{
242 return set_ape_cpu_opps(MB1H_ARM_OPP, CPU_OPP_NO_CHANGE, opp); 1509 return (atomic_read(&ac_wake_req_state) != 0);
243} 1510}
244EXPORT_SYMBOL(prcmu_set_cpu_opp);
245 1511
246/** 1512/**
247 * prcmu_set_ape_cpu_opps() - Set the OPPs of the APE and the CPU. 1513 * prcmu_system_reset - System reset
248 * @ape_opp: The APE OPP to set.
249 * @cpu_opp: The CPU OPP to set.
250 * 1514 *
251 * This function sets the OPPs of the APE and the CPU. 1515 * Saves the reset reason code and then sets the APE_SOFRST register which
1516 * fires interrupt to fw
252 */ 1517 */
253int prcmu_set_ape_cpu_opps(enum prcmu_ape_opp ape_opp, 1518void prcmu_system_reset(u16 reset_code)
254 enum prcmu_cpu_opp cpu_opp)
255{ 1519{
256 return set_ape_cpu_opps(MB1H_ARM_APE_OPP, ape_opp, cpu_opp); 1520 writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
1521 writel(1, (_PRCMU_BASE + PRCM_APE_SOFTRST));
257} 1522}
258EXPORT_SYMBOL(prcmu_set_ape_cpu_opps);
259 1523
260/** 1524/**
261 * prcmu_get_ape_opp() - Get the OPP of the APE. 1525 * prcmu_reset_modem - ask the PRCMU to reset modem
262 *
263 * This function gets the OPP of the APE.
264 */ 1526 */
265enum prcmu_ape_opp prcmu_get_ape_opp(void) 1527void prcmu_modem_reset(void)
266{ 1528{
267 return readb(ACK_MB1_CURR_APEOPP); 1529 mutex_lock(&mb1_transfer.lock);
1530
1531 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1532 cpu_relax();
1533
1534 writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1535 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1536 wait_for_completion(&mb1_transfer.work);
1537
1538 /*
1539 * No need to check return from PRCMU as modem should go in reset state
1540 * This state is already managed by upper layer
1541 */
1542
1543 mutex_unlock(&mb1_transfer.lock);
268} 1544}
269EXPORT_SYMBOL(prcmu_get_ape_opp);
270 1545
271/** 1546static void ack_dbb_wakeup(void)
272 * prcmu_get_cpu_opp() - Get the OPP of the CPU.
273 *
274 * This function gets the OPP of the CPU. The OPP is specified in %%.
275 * PRCMU_OPP_EXT is a special OPP value, not specified in %%.
276 */
277int prcmu_get_cpu_opp(void)
278{ 1547{
279 return readb(ACK_MB1_CURR_ARMOPP); 1548 unsigned long flags;
1549
1550 spin_lock_irqsave(&mb0_transfer.lock, flags);
1551
1552 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
1553 cpu_relax();
1554
1555 writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
1556 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
1557
1558 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
280} 1559}
281EXPORT_SYMBOL(prcmu_get_cpu_opp);
282 1560
283bool prcmu_has_arm_maxopp(void) 1561static inline void print_unknown_header_warning(u8 n, u8 header)
284{ 1562{
285 return (readb(PRCM_AVS_VARM_MAX_OPP) & PRCM_AVS_ISMODEENABLE_MASK) 1563 pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n",
286 == PRCM_AVS_ISMODEENABLE_MASK; 1564 header, n);
287} 1565}
288 1566
289static void read_mailbox_0(void) 1567static bool read_mailbox_0(void)
290{ 1568{
291 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLEAR); 1569 bool r;
1570 u32 ev;
1571 unsigned int n;
1572 u8 header;
1573
1574 header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0);
1575 switch (header) {
1576 case MB0H_WAKEUP_EXE:
1577 case MB0H_WAKEUP_SLEEP:
1578 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
1579 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500);
1580 else
1581 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500);
1582
1583 if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK))
1584 complete(&mb0_transfer.ac_wake_work);
1585 if (ev & WAKEUP_BIT_SYSCLK_OK)
1586 complete(&mb3_transfer.sysclk_work);
1587
1588 ev &= mb0_transfer.req.dbb_irqs;
1589
1590 for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
1591 if (ev & prcmu_irq_bit[n])
1592 generic_handle_irq(IRQ_PRCMU_BASE + n);
1593 }
1594 r = true;
1595 break;
1596 default:
1597 print_unknown_header_warning(0, header);
1598 r = false;
1599 break;
1600 }
1601 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1602 return r;
292} 1603}
293 1604
294static void read_mailbox_1(void) 1605static bool read_mailbox_1(void)
295{ 1606{
296 mb1_transfer.ack.arm_opp = readb(ACK_MB1_CURR_ARMOPP); 1607 mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1);
297 mb1_transfer.ack.ape_opp = readb(ACK_MB1_CURR_APEOPP); 1608 mb1_transfer.ack.arm_opp = readb(tcdm_base +
1609 PRCM_ACK_MB1_CURRENT_ARM_OPP);
1610 mb1_transfer.ack.ape_opp = readb(tcdm_base +
1611 PRCM_ACK_MB1_CURRENT_APE_OPP);
1612 mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
1613 PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
1614 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
298 complete(&mb1_transfer.work); 1615 complete(&mb1_transfer.work);
299 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLEAR); 1616 return false;
300} 1617}
301 1618
302static void read_mailbox_2(void) 1619static bool read_mailbox_2(void)
303{ 1620{
304 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLEAR); 1621 mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
1622 writel(MBOX_BIT(2), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1623 complete(&mb2_transfer.work);
1624 return false;
305} 1625}
306 1626
307static void read_mailbox_3(void) 1627static bool read_mailbox_3(void)
308{ 1628{
309 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLEAR); 1629 writel(MBOX_BIT(3), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1630 return false;
310} 1631}
311 1632
312static void read_mailbox_4(void) 1633static bool read_mailbox_4(void)
313{ 1634{
314 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLEAR); 1635 u8 header;
1636 bool do_complete = true;
1637
1638 header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4);
1639 switch (header) {
1640 case MB4H_MEM_ST:
1641 case MB4H_HOTDOG:
1642 case MB4H_HOTMON:
1643 case MB4H_HOT_PERIOD:
1644 break;
1645 default:
1646 print_unknown_header_warning(4, header);
1647 do_complete = false;
1648 break;
1649 }
1650
1651 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1652
1653 if (do_complete)
1654 complete(&mb4_transfer.work);
1655
1656 return false;
315} 1657}
316 1658
317static void read_mailbox_5(void) 1659static bool read_mailbox_5(void)
318{ 1660{
319 mb5_transfer.ack.status = readb(ACK_MB5_I2C_STATUS); 1661 mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
320 mb5_transfer.ack.value = readb(ACK_MB5_I2C_VAL); 1662 mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
1663 writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
321 complete(&mb5_transfer.work); 1664 complete(&mb5_transfer.work);
322 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLEAR); 1665 return false;
323} 1666}
324 1667
325static void read_mailbox_6(void) 1668static bool read_mailbox_6(void)
326{ 1669{
327 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLEAR); 1670 writel(MBOX_BIT(6), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1671 return false;
328} 1672}
329 1673
330static void read_mailbox_7(void) 1674static bool read_mailbox_7(void)
331{ 1675{
332 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLEAR); 1676 writel(MBOX_BIT(7), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1677 return false;
333} 1678}
334 1679
335static void (* const read_mailbox[NUM_MBOX])(void) = { 1680static bool (* const read_mailbox[NUM_MB])(void) = {
336 read_mailbox_0, 1681 read_mailbox_0,
337 read_mailbox_1, 1682 read_mailbox_1,
338 read_mailbox_2, 1683 read_mailbox_2,
@@ -347,49 +1692,199 @@ static irqreturn_t prcmu_irq_handler(int irq, void *data)
347{ 1692{
348 u32 bits; 1693 u32 bits;
349 u8 n; 1694 u8 n;
1695 irqreturn_t r;
350 1696
351 bits = (readl(PRCM_ARM_IT1_VAL) & (MBOX_BIT(NUM_MBOX) - 1)); 1697 bits = (readl(_PRCMU_BASE + PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
352 if (unlikely(!bits)) 1698 if (unlikely(!bits))
353 return IRQ_NONE; 1699 return IRQ_NONE;
354 1700
1701 r = IRQ_HANDLED;
355 for (n = 0; bits; n++) { 1702 for (n = 0; bits; n++) {
356 if (bits & MBOX_BIT(n)) { 1703 if (bits & MBOX_BIT(n)) {
357 bits -= MBOX_BIT(n); 1704 bits -= MBOX_BIT(n);
358 read_mailbox[n](); 1705 if (read_mailbox[n]())
1706 r = IRQ_WAKE_THREAD;
359 } 1707 }
360 } 1708 }
1709 return r;
1710}
1711
1712static irqreturn_t prcmu_irq_thread_fn(int irq, void *data)
1713{
1714 ack_dbb_wakeup();
361 return IRQ_HANDLED; 1715 return IRQ_HANDLED;
362} 1716}
363 1717
1718static void prcmu_mask_work(struct work_struct *work)
1719{
1720 unsigned long flags;
1721
1722 spin_lock_irqsave(&mb0_transfer.lock, flags);
1723
1724 config_wakeups();
1725
1726 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
1727}
1728
1729static void prcmu_irq_mask(struct irq_data *d)
1730{
1731 unsigned long flags;
1732
1733 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
1734
1735 mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
1736
1737 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
1738
1739 if (d->irq != IRQ_PRCMU_CA_SLEEP)
1740 schedule_work(&mb0_transfer.mask_work);
1741}
1742
1743static void prcmu_irq_unmask(struct irq_data *d)
1744{
1745 unsigned long flags;
1746
1747 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
1748
1749 mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
1750
1751 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
1752
1753 if (d->irq != IRQ_PRCMU_CA_SLEEP)
1754 schedule_work(&mb0_transfer.mask_work);
1755}
1756
1757static void noop(struct irq_data *d)
1758{
1759}
1760
1761static struct irq_chip prcmu_irq_chip = {
1762 .name = "prcmu",
1763 .irq_disable = prcmu_irq_mask,
1764 .irq_ack = noop,
1765 .irq_mask = prcmu_irq_mask,
1766 .irq_unmask = prcmu_irq_unmask,
1767};
1768
364void __init prcmu_early_init(void) 1769void __init prcmu_early_init(void)
365{ 1770{
366 if (cpu_is_u8500v11() || cpu_is_u8500ed()) { 1771 unsigned int i;
1772
1773 if (cpu_is_u8500v1()) {
367 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE_V1); 1774 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE_V1);
368 } else if (cpu_is_u8500v2()) { 1775 } else if (cpu_is_u8500v2()) {
1776 void *tcpm_base = ioremap_nocache(U8500_PRCMU_TCPM_BASE, SZ_4K);
1777
1778 if (tcpm_base != NULL) {
1779 int version;
1780 version = readl(tcpm_base + PRCMU_FW_VERSION_OFFSET);
1781 prcmu_version.project_number = version & 0xFF;
1782 prcmu_version.api_version = (version >> 8) & 0xFF;
1783 prcmu_version.func_version = (version >> 16) & 0xFF;
1784 prcmu_version.errata = (version >> 24) & 0xFF;
1785 pr_info("PRCMU firmware version %d.%d.%d\n",
1786 (version >> 8) & 0xFF, (version >> 16) & 0xFF,
1787 (version >> 24) & 0xFF);
1788 iounmap(tcpm_base);
1789 }
1790
369 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE); 1791 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE);
370 } else { 1792 } else {
371 pr_err("prcmu: Unsupported chip version\n"); 1793 pr_err("prcmu: Unsupported chip version\n");
372 BUG(); 1794 BUG();
373 } 1795 }
374}
375
376static int __init prcmu_init(void)
377{
378 if (cpu_is_u8500ed()) {
379 pr_err("prcmu: Unsupported chip version\n");
380 return 0;
381 }
382 1796
1797 spin_lock_init(&mb0_transfer.lock);
1798 spin_lock_init(&mb0_transfer.dbb_irqs_lock);
1799 mutex_init(&mb0_transfer.ac_wake_lock);
1800 init_completion(&mb0_transfer.ac_wake_work);
383 mutex_init(&mb1_transfer.lock); 1801 mutex_init(&mb1_transfer.lock);
384 init_completion(&mb1_transfer.work); 1802 init_completion(&mb1_transfer.work);
1803 mutex_init(&mb2_transfer.lock);
1804 init_completion(&mb2_transfer.work);
1805 spin_lock_init(&mb2_transfer.auto_pm_lock);
1806 spin_lock_init(&mb3_transfer.lock);
1807 mutex_init(&mb3_transfer.sysclk_lock);
1808 init_completion(&mb3_transfer.sysclk_work);
1809 mutex_init(&mb4_transfer.lock);
1810 init_completion(&mb4_transfer.work);
385 mutex_init(&mb5_transfer.lock); 1811 mutex_init(&mb5_transfer.lock);
386 init_completion(&mb5_transfer.work); 1812 init_completion(&mb5_transfer.work);
387 1813
1814 INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
1815
1816 /* Initalize irqs. */
1817 for (i = 0; i < NUM_PRCMU_WAKEUPS; i++) {
1818 unsigned int irq;
1819
1820 irq = IRQ_PRCMU_BASE + i;
1821 irq_set_chip_and_handler(irq, &prcmu_irq_chip,
1822 handle_simple_irq);
1823 set_irq_flags(irq, IRQF_VALID);
1824 }
1825}
1826
1827static struct mfd_cell db8500_prcmu_devs[] = {
1828 {
1829 .name = "db8500-prcmu-regulators",
1830 },
1831 {
1832 .name = "cpufreq-u8500",
1833 },
1834};
1835
1836/**
1837 * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic
1838 *
1839 */
1840static int __init db8500_prcmu_probe(struct platform_device *pdev)
1841{
1842 int err = 0;
1843
1844 if (ux500_is_svp())
1845 return -ENODEV;
1846
388 /* Clean up the mailbox interrupts after pre-kernel code. */ 1847 /* Clean up the mailbox interrupts after pre-kernel code. */
389 writel((MBOX_BIT(NUM_MBOX) - 1), PRCM_ARM_IT1_CLEAR); 1848 writel(ALL_MBOX_BITS, (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
1849
1850 err = request_threaded_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler,
1851 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
1852 if (err < 0) {
1853 pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
1854 err = -EBUSY;
1855 goto no_irq_return;
1856 }
1857
1858 if (cpu_is_u8500v20_or_later())
1859 prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
390 1860
391 return request_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler, 0, 1861 err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
392 "prcmu", NULL); 1862 ARRAY_SIZE(db8500_prcmu_devs), NULL,
1863 0);
1864
1865 if (err)
1866 pr_err("prcmu: Failed to add subdevices\n");
1867 else
1868 pr_info("DB8500 PRCMU initialized\n");
1869
1870no_irq_return:
1871 return err;
393} 1872}
394 1873
395arch_initcall(prcmu_init); 1874static struct platform_driver db8500_prcmu_driver = {
1875 .driver = {
1876 .name = "db8500-prcmu",
1877 .owner = THIS_MODULE,
1878 },
1879};
1880
1881static int __init db8500_prcmu_init(void)
1882{
1883 return platform_driver_probe(&db8500_prcmu_driver, db8500_prcmu_probe);
1884}
1885
1886arch_initcall(db8500_prcmu_init);
1887
1888MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>");
1889MODULE_DESCRIPTION("DB8500 PRCM Unit driver");
1890MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/db8500-prcmu.h b/include/linux/mfd/db8500-prcmu.h
index d591d79aa6f0..917dbcab701c 100644
--- a/include/linux/mfd/db8500-prcmu.h
+++ b/include/linux/mfd/db8500-prcmu.h
@@ -2,57 +2,977 @@
2 * Copyright (C) STMicroelectronics 2009 2 * Copyright (C) STMicroelectronics 2009
3 * Copyright (C) ST-Ericsson SA 2010 3 * Copyright (C) ST-Ericsson SA 2010
4 * 4 *
5 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
6 * Author: Martin Persson <martin.persson@stericsson.com>
7 *
8 * License Terms: GNU General Public License v2 5 * License Terms: GNU General Public License v2
6 * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
9 * 7 *
10 * PRCM Unit definitions 8 * PRCMU f/w APIs
11 */ 9 */
10#ifndef __MFD_DB8500_PRCMU_H
11#define __MFD_DB8500_PRCMU_H
12
13#include <linux/interrupt.h>
14#include <linux/notifier.h>
12 15
13#ifndef __MACH_PRCMU_DEFS_H 16/* This portion previously known as <mach/prcmu-fw-defs_v1.h> */
14#define __MACH_PRCMU_DEFS_H
15 17
16enum prcmu_cpu_opp { 18/**
17 CPU_OPP_INIT = 0x00, 19 * enum state - ON/OFF state definition
18 CPU_OPP_NO_CHANGE = 0x01, 20 * @OFF: State is ON
19 CPU_OPP_100 = 0x02, 21 * @ON: State is OFF
20 CPU_OPP_50 = 0x03, 22 *
21 CPU_OPP_MAX = 0x04, 23 */
22 CPU_OPP_EXT_CLK = 0x07 24enum state {
25 OFF = 0x0,
26 ON = 0x1,
23}; 27};
24enum prcmu_ape_opp { 28
25 APE_OPP_NO_CHANGE = 0x00, 29/**
26 APE_OPP_100 = 0x02, 30 * enum ret_state - general purpose On/Off/Retention states
27 APE_OPP_50 = 0x03, 31 *
32 */
33enum ret_state {
34 OFFST = 0,
35 ONST = 1,
36 RETST = 2
28}; 37};
29 38
30#endif /* __MACH_PRCMU_DEFS_H */ 39/**
40 * enum clk_arm - ARM Cortex A9 clock schemes
41 * @A9_OFF:
42 * @A9_BOOT:
43 * @A9_OPPT1:
44 * @A9_OPPT2:
45 * @A9_EXTCLK:
46 */
47enum clk_arm {
48 A9_OFF,
49 A9_BOOT,
50 A9_OPPT1,
51 A9_OPPT2,
52 A9_EXTCLK
53};
31 54
32/* 55/**
33 * Copyright (C) STMicroelectronics 2009 56 * enum clk_gen - GEN#0/GEN#1 clock schemes
34 * Copyright (C) ST-Ericsson SA 2010 57 * @GEN_OFF:
58 * @GEN_BOOT:
59 * @GEN_OPPT1:
60 */
61enum clk_gen {
62 GEN_OFF,
63 GEN_BOOT,
64 GEN_OPPT1,
65};
66
67/* some information between arm and xp70 */
68
69/**
70 * enum romcode_write - Romcode message written by A9 AND read by XP70
71 * @RDY_2_DS: Value set when ApDeepSleep state can be executed by XP70
72 * @RDY_2_XP70_RST: Value set when 0x0F has been successfully polled by the
73 * romcode. The xp70 will go into self-reset
74 */
75enum romcode_write {
76 RDY_2_DS = 0x09,
77 RDY_2_XP70_RST = 0x10
78};
79
80/**
81 * enum romcode_read - Romcode message written by XP70 and read by A9
82 * @INIT: Init value when romcode field is not used
83 * @FS_2_DS: Value set when power state is going from ApExecute to
84 * ApDeepSleep
85 * @END_DS: Value set when ApDeepSleep power state is reached coming from
86 * ApExecute state
87 * @DS_TO_FS: Value set when power state is going from ApDeepSleep to
88 * ApExecute
89 * @END_FS: Value set when ApExecute power state is reached coming from
90 * ApDeepSleep state
91 * @SWR: Value set when power state is going to ApReset
92 * @END_SWR: Value set when the xp70 finished executing ApReset actions and
93 * waits for romcode acknowledgment to go to self-reset
94 */
95enum romcode_read {
96 INIT = 0x00,
97 FS_2_DS = 0x0A,
98 END_DS = 0x0B,
99 DS_TO_FS = 0x0C,
100 END_FS = 0x0D,
101 SWR = 0x0E,
102 END_SWR = 0x0F
103};
104
105/**
106 * enum ap_pwrst - current power states defined in PRCMU firmware
107 * @NO_PWRST: Current power state init
108 * @AP_BOOT: Current power state is apBoot
109 * @AP_EXECUTE: Current power state is apExecute
110 * @AP_DEEP_SLEEP: Current power state is apDeepSleep
111 * @AP_SLEEP: Current power state is apSleep
112 * @AP_IDLE: Current power state is apIdle
113 * @AP_RESET: Current power state is apReset
114 */
115enum ap_pwrst {
116 NO_PWRST = 0x00,
117 AP_BOOT = 0x01,
118 AP_EXECUTE = 0x02,
119 AP_DEEP_SLEEP = 0x03,
120 AP_SLEEP = 0x04,
121 AP_IDLE = 0x05,
122 AP_RESET = 0x06
123};
124
125/**
126 * enum ap_pwrst_trans - Transition states defined in PRCMU firmware
127 * @NO_TRANSITION: No power state transition
128 * @APEXECUTE_TO_APSLEEP: Power state transition from ApExecute to ApSleep
129 * @APIDLE_TO_APSLEEP: Power state transition from ApIdle to ApSleep
130 * @APBOOT_TO_APEXECUTE: Power state transition from ApBoot to ApExecute
131 * @APEXECUTE_TO_APDEEPSLEEP: Power state transition from ApExecute to
132 * ApDeepSleep
133 * @APEXECUTE_TO_APIDLE: Power state transition from ApExecute to ApIdle
134 */
135enum ap_pwrst_trans {
136 NO_TRANSITION = 0x00,
137 APEXECUTE_TO_APSLEEP = 0x01,
138 APIDLE_TO_APSLEEP = 0x02, /* To be removed */
139 PRCMU_AP_SLEEP = 0x01,
140 APBOOT_TO_APEXECUTE = 0x03,
141 APEXECUTE_TO_APDEEPSLEEP = 0x04, /* To be removed */
142 PRCMU_AP_DEEP_SLEEP = 0x04,
143 APEXECUTE_TO_APIDLE = 0x05, /* To be removed */
144 PRCMU_AP_IDLE = 0x05,
145 PRCMU_AP_DEEP_IDLE = 0x07,
146};
147
148/**
149 * enum ddr_pwrst - DDR power states definition
150 * @DDR_PWR_STATE_UNCHANGED: SDRAM and DDR controller state is unchanged
151 * @DDR_PWR_STATE_ON:
152 * @DDR_PWR_STATE_OFFLOWLAT:
153 * @DDR_PWR_STATE_OFFHIGHLAT:
154 */
155enum ddr_pwrst {
156 DDR_PWR_STATE_UNCHANGED = 0x00,
157 DDR_PWR_STATE_ON = 0x01,
158 DDR_PWR_STATE_OFFLOWLAT = 0x02,
159 DDR_PWR_STATE_OFFHIGHLAT = 0x03
160};
161
162/**
163 * enum arm_opp - ARM OPP states definition
164 * @ARM_OPP_INIT:
165 * @ARM_NO_CHANGE: The ARM operating point is unchanged
166 * @ARM_100_OPP: The new ARM operating point is arm100opp
167 * @ARM_50_OPP: The new ARM operating point is arm50opp
168 * @ARM_MAX_OPP: Operating point is "max" (more than 100)
169 * @ARM_MAX_FREQ100OPP: Set max opp if available, else 100
170 * @ARM_EXTCLK: The new ARM operating point is armExtClk
171 */
172enum arm_opp {
173 ARM_OPP_INIT = 0x00,
174 ARM_NO_CHANGE = 0x01,
175 ARM_100_OPP = 0x02,
176 ARM_50_OPP = 0x03,
177 ARM_MAX_OPP = 0x04,
178 ARM_MAX_FREQ100OPP = 0x05,
179 ARM_EXTCLK = 0x07
180};
181
182/**
183 * enum ape_opp - APE OPP states definition
184 * @APE_OPP_INIT:
185 * @APE_NO_CHANGE: The APE operating point is unchanged
186 * @APE_100_OPP: The new APE operating point is ape100opp
187 * @APE_50_OPP: 50%
188 */
189enum ape_opp {
190 APE_OPP_INIT = 0x00,
191 APE_NO_CHANGE = 0x01,
192 APE_100_OPP = 0x02,
193 APE_50_OPP = 0x03
194};
195
196/**
197 * enum hw_acc_state - State definition for hardware accelerator
198 * @HW_NO_CHANGE: The hardware accelerator state must remain unchanged
199 * @HW_OFF: The hardware accelerator must be switched off
200 * @HW_OFF_RAMRET: The hardware accelerator must be switched off with its
201 * internal RAM in retention
202 * @HW_ON: The hwa hardware accelerator hwa must be switched on
35 * 203 *
36 * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com> 204 * NOTE! Deprecated, to be removed when all users switched over to use the
37 * Author: Sundar Iyer <sundar.iyer@stericsson.com> 205 * regulator API.
38 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> 206 */
207enum hw_acc_state {
208 HW_NO_CHANGE = 0x00,
209 HW_OFF = 0x01,
210 HW_OFF_RAMRET = 0x02,
211 HW_ON = 0x04
212};
213
214/**
215 * enum mbox_2_arm_stat - Status messages definition for mbox_arm
216 * @BOOT_TO_EXECUTEOK: The apBoot to apExecute state transition has been
217 * completed
218 * @DEEPSLEEPOK: The apExecute to apDeepSleep state transition has been
219 * completed
220 * @SLEEPOK: The apExecute to apSleep state transition has been completed
221 * @IDLEOK: The apExecute to apIdle state transition has been completed
222 * @SOFTRESETOK: The A9 watchdog/ SoftReset state has been completed
223 * @SOFTRESETGO : The A9 watchdog/SoftReset state is on going
224 * @BOOT_TO_EXECUTE: The apBoot to apExecute state transition is on going
225 * @EXECUTE_TO_DEEPSLEEP: The apExecute to apDeepSleep state transition is on
226 * going
227 * @DEEPSLEEP_TO_EXECUTE: The apDeepSleep to apExecute state transition is on
228 * going
229 * @DEEPSLEEP_TO_EXECUTEOK: The apDeepSleep to apExecute state transition has
230 * been completed
231 * @EXECUTE_TO_SLEEP: The apExecute to apSleep state transition is on going
232 * @SLEEP_TO_EXECUTE: The apSleep to apExecute state transition is on going
233 * @SLEEP_TO_EXECUTEOK: The apSleep to apExecute state transition has been
234 * completed
235 * @EXECUTE_TO_IDLE: The apExecute to apIdle state transition is on going
236 * @IDLE_TO_EXECUTE: The apIdle to apExecute state transition is on going
237 * @IDLE_TO_EXECUTEOK: The apIdle to apExecute state transition has been
238 * completed
239 * @INIT_STATUS: Status init
240 */
241enum ap_pwrsttr_status {
242 BOOT_TO_EXECUTEOK = 0xFF,
243 DEEPSLEEPOK = 0xFE,
244 SLEEPOK = 0xFD,
245 IDLEOK = 0xFC,
246 SOFTRESETOK = 0xFB,
247 SOFTRESETGO = 0xFA,
248 BOOT_TO_EXECUTE = 0xF9,
249 EXECUTE_TO_DEEPSLEEP = 0xF8,
250 DEEPSLEEP_TO_EXECUTE = 0xF7,
251 DEEPSLEEP_TO_EXECUTEOK = 0xF6,
252 EXECUTE_TO_SLEEP = 0xF5,
253 SLEEP_TO_EXECUTE = 0xF4,
254 SLEEP_TO_EXECUTEOK = 0xF3,
255 EXECUTE_TO_IDLE = 0xF2,
256 IDLE_TO_EXECUTE = 0xF1,
257 IDLE_TO_EXECUTEOK = 0xF0,
258 RDYTODS_RETURNTOEXE = 0xEF,
259 NORDYTODS_RETURNTOEXE = 0xEE,
260 EXETOSLEEP_RETURNTOEXE = 0xED,
261 EXETOIDLE_RETURNTOEXE = 0xEC,
262 INIT_STATUS = 0xEB,
263
264 /*error messages */
265 INITERROR = 0x00,
266 PLLARMLOCKP_ER = 0x01,
267 PLLDDRLOCKP_ER = 0x02,
268 PLLSOCLOCKP_ER = 0x03,
269 PLLSOCK1LOCKP_ER = 0x04,
270 ARMWFI_ER = 0x05,
271 SYSCLKOK_ER = 0x06,
272 I2C_NACK_DATA_ER = 0x07,
273 BOOT_ER = 0x08,
274 I2C_STATUS_ALWAYS_1 = 0x0A,
275 I2C_NACK_REG_ADDR_ER = 0x0B,
276 I2C_NACK_DATA0123_ER = 0x1B,
277 I2C_NACK_ADDR_ER = 0x1F,
278 CURAPPWRSTISNOT_BOOT = 0x20,
279 CURAPPWRSTISNOT_EXECUTE = 0x21,
280 CURAPPWRSTISNOT_SLEEPMODE = 0x22,
281 CURAPPWRSTISNOT_CORRECTFORIT10 = 0x23,
282 FIFO4500WUISNOT_WUPEVENT = 0x24,
283 PLL32KLOCKP_ER = 0x29,
284 DDRDEEPSLEEPOK_ER = 0x2A,
285 ROMCODEREADY_ER = 0x50,
286 WUPBEFOREDS = 0x51,
287 DDRCONFIG_ER = 0x52,
288 WUPBEFORESLEEP = 0x53,
289 WUPBEFOREIDLE = 0x54
290}; /* earlier called as mbox_2_arm_stat */
291
292/**
293 * enum dvfs_stat - DVFS status messages definition
294 * @DVFS_GO: A state transition DVFS is on going
295 * @DVFS_ARM100OPPOK: The state transition DVFS has been completed for 100OPP
296 * @DVFS_ARM50OPPOK: The state transition DVFS has been completed for 50OPP
297 * @DVFS_ARMEXTCLKOK: The state transition DVFS has been completed for EXTCLK
298 * @DVFS_NOCHGTCLKOK: The state transition DVFS has been completed for
299 * NOCHGCLK
300 * @DVFS_INITSTATUS: Value init
301 */
302enum dvfs_stat {
303 DVFS_GO = 0xFF,
304 DVFS_ARM100OPPOK = 0xFE,
305 DVFS_ARM50OPPOK = 0xFD,
306 DVFS_ARMEXTCLKOK = 0xFC,
307 DVFS_NOCHGTCLKOK = 0xFB,
308 DVFS_INITSTATUS = 0x00
309};
310
311/**
312 * enum sva_mmdsp_stat - SVA MMDSP status messages
313 * @SVA_MMDSP_GO: SVAMMDSP interrupt has happened
314 * @SVA_MMDSP_INIT: Status init
315 */
316enum sva_mmdsp_stat {
317 SVA_MMDSP_GO = 0xFF,
318 SVA_MMDSP_INIT = 0x00
319};
320
321/**
322 * enum sia_mmdsp_stat - SIA MMDSP status messages
323 * @SIA_MMDSP_GO: SIAMMDSP interrupt has happened
324 * @SIA_MMDSP_INIT: Status init
325 */
326enum sia_mmdsp_stat {
327 SIA_MMDSP_GO = 0xFF,
328 SIA_MMDSP_INIT = 0x00
329};
330
331/**
332 * enum mbox_to_arm_err - Error messages definition
333 * @INIT_ERR: Init value
334 * @PLLARMLOCKP_ERR: PLLARM has not been correctly locked in given time
335 * @PLLDDRLOCKP_ERR: PLLDDR has not been correctly locked in the given time
336 * @PLLSOC0LOCKP_ERR: PLLSOC0 has not been correctly locked in the given time
337 * @PLLSOC1LOCKP_ERR: PLLSOC1 has not been correctly locked in the given time
338 * @ARMWFI_ERR: The ARM WFI has not been correctly executed in the given time
339 * @SYSCLKOK_ERR: The SYSCLK is not available in the given time
340 * @BOOT_ERR: Romcode has not validated the XP70 self reset in the given time
341 * @ROMCODESAVECONTEXT: The Romcode didn.t correctly save it secure context
342 * @VARMHIGHSPEEDVALTO_ERR: The ARM high speed supply value transfered
343 * through I2C has not been correctly executed in the given time
344 * @VARMHIGHSPEEDACCESS_ERR: The command value of VarmHighSpeedVal transfered
345 * through I2C has not been correctly executed in the given time
346 * @VARMLOWSPEEDVALTO_ERR:The ARM low speed supply value transfered through
347 * I2C has not been correctly executed in the given time
348 * @VARMLOWSPEEDACCESS_ERR: The command value of VarmLowSpeedVal transfered
349 * through I2C has not been correctly executed in the given time
350 * @VARMRETENTIONVALTO_ERR: The ARM retention supply value transfered through
351 * I2C has not been correctly executed in the given time
352 * @VARMRETENTIONACCESS_ERR: The command value of VarmRetentionVal transfered
353 * through I2C has not been correctly executed in the given time
354 * @VAPEHIGHSPEEDVALTO_ERR: The APE highspeed supply value transfered through
355 * I2C has not been correctly executed in the given time
356 * @VSAFEHPVALTO_ERR: The SAFE high power supply value transfered through I2C
357 * has not been correctly executed in the given time
358 * @VMODSEL1VALTO_ERR: The MODEM sel1 supply value transfered through I2C has
359 * not been correctly executed in the given time
360 * @VMODSEL2VALTO_ERR: The MODEM sel2 supply value transfered through I2C has
361 * not been correctly executed in the given time
362 * @VARMOFFACCESS_ERR: The command value of Varm ON/OFF transfered through
363 * I2C has not been correctly executed in the given time
364 * @VAPEOFFACCESS_ERR: The command value of Vape ON/OFF transfered through
365 * I2C has not been correctly executed in the given time
366 * @VARMRETACCES_ERR: The command value of Varm retention ON/OFF transfered
367 * through I2C has not been correctly executed in the given time
368 * @CURAPPWRSTISNOTBOOT:Generated when Arm want to do power state transition
369 * ApBoot to ApExecute but the power current state is not Apboot
370 * @CURAPPWRSTISNOTEXECUTE: Generated when Arm want to do power state
371 * transition from ApExecute to others power state but the
372 * power current state is not ApExecute
373 * @CURAPPWRSTISNOTSLEEPMODE: Generated when wake up events are transmitted
374 * but the power current state is not ApDeepSleep/ApSleep/ApIdle
375 * @CURAPPWRSTISNOTCORRECTDBG: Generated when wake up events are transmitted
376 * but the power current state is not correct
377 * @ARMREGU1VALTO_ERR:The ArmRegu1 value transferred through I2C has not
378 * been correctly executed in the given time
379 * @ARMREGU2VALTO_ERR: The ArmRegu2 value transferred through I2C has not
380 * been correctly executed in the given time
381 * @VAPEREGUVALTO_ERR: The VApeRegu value transfered through I2C has not
382 * been correctly executed in the given time
383 * @VSMPS3REGUVALTO_ERR: The VSmps3Regu value transfered through I2C has not
384 * been correctly executed in the given time
385 * @VMODREGUVALTO_ERR: The VModemRegu value transfered through I2C has not
386 * been correctly executed in the given time
387 */
388enum mbox_to_arm_err {
389 INIT_ERR = 0x00,
390 PLLARMLOCKP_ERR = 0x01,
391 PLLDDRLOCKP_ERR = 0x02,
392 PLLSOC0LOCKP_ERR = 0x03,
393 PLLSOC1LOCKP_ERR = 0x04,
394 ARMWFI_ERR = 0x05,
395 SYSCLKOK_ERR = 0x06,
396 BOOT_ERR = 0x07,
397 ROMCODESAVECONTEXT = 0x08,
398 VARMHIGHSPEEDVALTO_ERR = 0x10,
399 VARMHIGHSPEEDACCESS_ERR = 0x11,
400 VARMLOWSPEEDVALTO_ERR = 0x12,
401 VARMLOWSPEEDACCESS_ERR = 0x13,
402 VARMRETENTIONVALTO_ERR = 0x14,
403 VARMRETENTIONACCESS_ERR = 0x15,
404 VAPEHIGHSPEEDVALTO_ERR = 0x16,
405 VSAFEHPVALTO_ERR = 0x17,
406 VMODSEL1VALTO_ERR = 0x18,
407 VMODSEL2VALTO_ERR = 0x19,
408 VARMOFFACCESS_ERR = 0x1A,
409 VAPEOFFACCESS_ERR = 0x1B,
410 VARMRETACCES_ERR = 0x1C,
411 CURAPPWRSTISNOTBOOT = 0x20,
412 CURAPPWRSTISNOTEXECUTE = 0x21,
413 CURAPPWRSTISNOTSLEEPMODE = 0x22,
414 CURAPPWRSTISNOTCORRECTDBG = 0x23,
415 ARMREGU1VALTO_ERR = 0x24,
416 ARMREGU2VALTO_ERR = 0x25,
417 VAPEREGUVALTO_ERR = 0x26,
418 VSMPS3REGUVALTO_ERR = 0x27,
419 VMODREGUVALTO_ERR = 0x28
420};
421
422enum hw_acc {
423 SVAMMDSP = 0,
424 SVAPIPE = 1,
425 SIAMMDSP = 2,
426 SIAPIPE = 3,
427 SGA = 4,
428 B2R2MCDE = 5,
429 ESRAM12 = 6,
430 ESRAM34 = 7,
431};
432
433enum cs_pwrmgt {
434 PWRDNCS0 = 0,
435 WKUPCS0 = 1,
436 PWRDNCS1 = 2,
437 WKUPCS1 = 3
438};
439
440/* Defs related to autonomous power management */
441
442/**
443 * enum sia_sva_pwr_policy - Power policy
444 * @NO_CHGT: No change
445 * @DSPOFF_HWPOFF:
446 * @DSPOFFRAMRET_HWPOFF:
447 * @DSPCLKOFF_HWPOFF:
448 * @DSPCLKOFF_HWPCLKOFF:
39 * 449 *
40 * License Terms: GNU General Public License v2 450 */
451enum sia_sva_pwr_policy {
452 NO_CHGT = 0x0,
453 DSPOFF_HWPOFF = 0x1,
454 DSPOFFRAMRET_HWPOFF = 0x2,
455 DSPCLKOFF_HWPOFF = 0x3,
456 DSPCLKOFF_HWPCLKOFF = 0x4,
457};
458
459/**
460 * enum auto_enable - Auto Power enable
461 * @AUTO_OFF:
462 * @AUTO_ON:
463 *
464 */
465enum auto_enable {
466 AUTO_OFF = 0x0,
467 AUTO_ON = 0x1,
468};
469
470/* End of file previously known as prcmu-fw-defs_v1.h */
471
472/* PRCMU Wakeup defines */
473enum prcmu_wakeup_index {
474 PRCMU_WAKEUP_INDEX_RTC,
475 PRCMU_WAKEUP_INDEX_RTT0,
476 PRCMU_WAKEUP_INDEX_RTT1,
477 PRCMU_WAKEUP_INDEX_HSI0,
478 PRCMU_WAKEUP_INDEX_HSI1,
479 PRCMU_WAKEUP_INDEX_USB,
480 PRCMU_WAKEUP_INDEX_ABB,
481 PRCMU_WAKEUP_INDEX_ABB_FIFO,
482 PRCMU_WAKEUP_INDEX_ARM,
483 NUM_PRCMU_WAKEUP_INDICES
484};
485#define PRCMU_WAKEUP(_name) (BIT(PRCMU_WAKEUP_INDEX_##_name))
486
487/* PRCMU QoS APE OPP class */
488#define PRCMU_QOS_APE_OPP 1
489#define PRCMU_QOS_DDR_OPP 2
490#define PRCMU_QOS_DEFAULT_VALUE -1
491
492/**
493 * enum hw_acc_dev - enum for hw accelerators
494 * @HW_ACC_SVAMMDSP: for SVAMMDSP
495 * @HW_ACC_SVAPIPE: for SVAPIPE
496 * @HW_ACC_SIAMMDSP: for SIAMMDSP
497 * @HW_ACC_SIAPIPE: for SIAPIPE
498 * @HW_ACC_SGA: for SGA
499 * @HW_ACC_B2R2: for B2R2
500 * @HW_ACC_MCDE: for MCDE
501 * @HW_ACC_ESRAM1: for ESRAM1
502 * @HW_ACC_ESRAM2: for ESRAM2
503 * @HW_ACC_ESRAM3: for ESRAM3
504 * @HW_ACC_ESRAM4: for ESRAM4
505 * @NUM_HW_ACC: number of hardware accelerators
506 *
507 * Different hw accelerators which can be turned ON/
508 * OFF or put into retention (MMDSPs and ESRAMs).
509 * Used with EPOD API.
41 * 510 *
42 * PRCM Unit f/w API 511 * NOTE! Deprecated, to be removed when all users switched over to use the
512 * regulator API.
513 */
514enum hw_acc_dev {
515 HW_ACC_SVAMMDSP,
516 HW_ACC_SVAPIPE,
517 HW_ACC_SIAMMDSP,
518 HW_ACC_SIAPIPE,
519 HW_ACC_SGA,
520 HW_ACC_B2R2,
521 HW_ACC_MCDE,
522 HW_ACC_ESRAM1,
523 HW_ACC_ESRAM2,
524 HW_ACC_ESRAM3,
525 HW_ACC_ESRAM4,
526 NUM_HW_ACC
527};
528
529/*
530 * Ids for all EPODs (power domains)
531 * - EPOD_ID_SVAMMDSP: power domain for SVA MMDSP
532 * - EPOD_ID_SVAPIPE: power domain for SVA pipe
533 * - EPOD_ID_SIAMMDSP: power domain for SIA MMDSP
534 * - EPOD_ID_SIAPIPE: power domain for SIA pipe
535 * - EPOD_ID_SGA: power domain for SGA
536 * - EPOD_ID_B2R2_MCDE: power domain for B2R2 and MCDE
537 * - EPOD_ID_ESRAM12: power domain for ESRAM 1 and 2
538 * - EPOD_ID_ESRAM34: power domain for ESRAM 3 and 4
539 * - NUM_EPOD_ID: number of power domains
540 */
541#define EPOD_ID_SVAMMDSP 0
542#define EPOD_ID_SVAPIPE 1
543#define EPOD_ID_SIAMMDSP 2
544#define EPOD_ID_SIAPIPE 3
545#define EPOD_ID_SGA 4
546#define EPOD_ID_B2R2_MCDE 5
547#define EPOD_ID_ESRAM12 6
548#define EPOD_ID_ESRAM34 7
549#define NUM_EPOD_ID 8
550
551/*
552 * state definition for EPOD (power domain)
553 * - EPOD_STATE_NO_CHANGE: The EPOD should remain unchanged
554 * - EPOD_STATE_OFF: The EPOD is switched off
555 * - EPOD_STATE_RAMRET: The EPOD is switched off with its internal RAM in
556 * retention
557 * - EPOD_STATE_ON_CLK_OFF: The EPOD is switched on, clock is still off
558 * - EPOD_STATE_ON: Same as above, but with clock enabled
43 */ 559 */
44#ifndef __MACH_PRCMU_H 560#define EPOD_STATE_NO_CHANGE 0x00
45#define __MACH_PRCMU_H 561#define EPOD_STATE_OFF 0x01
562#define EPOD_STATE_RAMRET 0x02
563#define EPOD_STATE_ON_CLK_OFF 0x03
564#define EPOD_STATE_ON 0x04
46 565
566/*
567 * CLKOUT sources
568 */
569#define PRCMU_CLKSRC_CLK38M 0x00
570#define PRCMU_CLKSRC_ACLK 0x01
571#define PRCMU_CLKSRC_SYSCLK 0x02
572#define PRCMU_CLKSRC_LCDCLK 0x03
573#define PRCMU_CLKSRC_SDMMCCLK 0x04
574#define PRCMU_CLKSRC_TVCLK 0x05
575#define PRCMU_CLKSRC_TIMCLK 0x06
576#define PRCMU_CLKSRC_CLK009 0x07
577/* These are only valid for CLKOUT1: */
578#define PRCMU_CLKSRC_SIAMMDSPCLK 0x40
579#define PRCMU_CLKSRC_I2CCLK 0x41
580#define PRCMU_CLKSRC_MSP02CLK 0x42
581#define PRCMU_CLKSRC_ARMPLL_OBSCLK 0x43
582#define PRCMU_CLKSRC_HSIRXCLK 0x44
583#define PRCMU_CLKSRC_HSITXCLK 0x45
584#define PRCMU_CLKSRC_ARMCLKFIX 0x46
585#define PRCMU_CLKSRC_HDMICLK 0x47
586
587/*
588 * Definitions for autonomous power management configuration.
589 */
590
591#define PRCMU_AUTO_PM_OFF 0
592#define PRCMU_AUTO_PM_ON 1
593
594#define PRCMU_AUTO_PM_POWER_ON_HSEM BIT(0)
595#define PRCMU_AUTO_PM_POWER_ON_ABB_FIFO_IT BIT(1)
596
597enum prcmu_auto_pm_policy {
598 PRCMU_AUTO_PM_POLICY_NO_CHANGE,
599 PRCMU_AUTO_PM_POLICY_DSP_OFF_HWP_OFF,
600 PRCMU_AUTO_PM_POLICY_DSP_OFF_RAMRET_HWP_OFF,
601 PRCMU_AUTO_PM_POLICY_DSP_CLK_OFF_HWP_OFF,
602 PRCMU_AUTO_PM_POLICY_DSP_CLK_OFF_HWP_CLK_OFF,
603};
604
605/**
606 * struct prcmu_auto_pm_config - Autonomous power management configuration.
607 * @sia_auto_pm_enable: SIA autonomous pm enable. (PRCMU_AUTO_PM_{OFF,ON})
608 * @sia_power_on: SIA power ON enable. (PRCMU_AUTO_PM_POWER_ON_* bitmask)
609 * @sia_policy: SIA power policy. (enum prcmu_auto_pm_policy)
610 * @sva_auto_pm_enable: SVA autonomous pm enable. (PRCMU_AUTO_PM_{OFF,ON})
611 * @sva_power_on: SVA power ON enable. (PRCMU_AUTO_PM_POWER_ON_* bitmask)
612 * @sva_policy: SVA power policy. (enum prcmu_auto_pm_policy)
613 */
614struct prcmu_auto_pm_config {
615 u8 sia_auto_pm_enable;
616 u8 sia_power_on;
617 u8 sia_policy;
618 u8 sva_auto_pm_enable;
619 u8 sva_power_on;
620 u8 sva_policy;
621};
622
623/**
624 * enum ddr_opp - DDR OPP states definition
625 * @DDR_100_OPP: The new DDR operating point is ddr100opp
626 * @DDR_50_OPP: The new DDR operating point is ddr50opp
627 * @DDR_25_OPP: The new DDR operating point is ddr25opp
628 */
629enum ddr_opp {
630 DDR_100_OPP = 0x00,
631 DDR_50_OPP = 0x01,
632 DDR_25_OPP = 0x02,
633};
634
635/*
636 * Clock identifiers.
637 */
638enum prcmu_clock {
639 PRCMU_SGACLK,
640 PRCMU_UARTCLK,
641 PRCMU_MSP02CLK,
642 PRCMU_MSP1CLK,
643 PRCMU_I2CCLK,
644 PRCMU_SDMMCCLK,
645 PRCMU_SLIMCLK,
646 PRCMU_PER1CLK,
647 PRCMU_PER2CLK,
648 PRCMU_PER3CLK,
649 PRCMU_PER5CLK,
650 PRCMU_PER6CLK,
651 PRCMU_PER7CLK,
652 PRCMU_LCDCLK,
653 PRCMU_BMLCLK,
654 PRCMU_HSITXCLK,
655 PRCMU_HSIRXCLK,
656 PRCMU_HDMICLK,
657 PRCMU_APEATCLK,
658 PRCMU_APETRACECLK,
659 PRCMU_MCDECLK,
660 PRCMU_IPI2CCLK,
661 PRCMU_DSIALTCLK,
662 PRCMU_DMACLK,
663 PRCMU_B2R2CLK,
664 PRCMU_TVCLK,
665 PRCMU_SSPCLK,
666 PRCMU_RNGCLK,
667 PRCMU_UICCCLK,
668 PRCMU_NUM_REG_CLOCKS,
669 PRCMU_SYSCLK = PRCMU_NUM_REG_CLOCKS,
670 PRCMU_TIMCLK,
671};
672
673/*
674 * Definitions for controlling ESRAM0 in deep sleep.
675 */
676#define ESRAM0_DEEP_SLEEP_STATE_OFF 1
677#define ESRAM0_DEEP_SLEEP_STATE_RET 2
678
679#ifdef CONFIG_MFD_DB8500_PRCMU
47void __init prcmu_early_init(void); 680void __init prcmu_early_init(void);
681int prcmu_set_display_clocks(void);
682int prcmu_disable_dsipll(void);
683int prcmu_enable_dsipll(void);
684#else
685static inline void __init prcmu_early_init(void) {}
686#endif
687
688#ifdef CONFIG_MFD_DB8500_PRCMU
689
690int prcmu_set_rc_a2p(enum romcode_write);
691enum romcode_read prcmu_get_rc_p2a(void);
692enum ap_pwrst prcmu_get_xp70_current_state(void);
693int prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll);
694
695void prcmu_enable_wakeups(u32 wakeups);
696static inline void prcmu_disable_wakeups(void)
697{
698 prcmu_enable_wakeups(0);
699}
700
701void prcmu_config_abb_event_readout(u32 abb_events);
702void prcmu_get_abb_event_buffer(void __iomem **buf);
703int prcmu_set_arm_opp(u8 opp);
704int prcmu_get_arm_opp(void);
705bool prcmu_has_arm_maxopp(void);
706bool prcmu_is_u8400(void);
707int prcmu_set_ape_opp(u8 opp);
708int prcmu_get_ape_opp(void);
709int prcmu_request_ape_opp_100_voltage(bool enable);
710int prcmu_release_usb_wakeup_state(void);
711int prcmu_set_ddr_opp(u8 opp);
712int prcmu_get_ddr_opp(void);
713unsigned long prcmu_qos_get_cpufreq_opp_delay(void);
714void prcmu_qos_set_cpufreq_opp_delay(unsigned long);
715/* NOTE! Use regulator framework instead */
716int prcmu_set_hwacc(u16 hw_acc_dev, u8 state);
717int prcmu_set_epod(u16 epod_id, u8 epod_state);
718void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
719 struct prcmu_auto_pm_config *idle);
720bool prcmu_is_auto_pm_enabled(void);
721
722int prcmu_config_clkout(u8 clkout, u8 source, u8 div);
723int prcmu_request_clock(u8 clock, bool enable);
724int prcmu_set_clock_divider(u8 clock, u8 divider);
725int prcmu_config_esram0_deep_sleep(u8 state);
726int prcmu_config_hotdog(u8 threshold);
727int prcmu_config_hotmon(u8 low, u8 high);
728int prcmu_start_temp_sense(u16 cycles32k);
729int prcmu_stop_temp_sense(void);
48int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size); 730int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
49int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size); 731int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size);
50int prcmu_set_ape_opp(enum prcmu_ape_opp opp);
51int prcmu_set_cpu_opp(enum prcmu_cpu_opp opp);
52int prcmu_set_ape_cpu_opps(enum prcmu_ape_opp ape_opp,
53 enum prcmu_cpu_opp cpu_opp);
54enum prcmu_ape_opp prcmu_get_ape_opp(void);
55int prcmu_get_cpu_opp(void);
56bool prcmu_has_arm_maxopp(void);
57 732
58#endif /* __MACH_PRCMU_H */ 733void prcmu_ac_wake_req(void);
734void prcmu_ac_sleep_req(void);
735void prcmu_system_reset(u16 reset_code);
736void prcmu_modem_reset(void);
737bool prcmu_is_ac_wake_requested(void);
738void prcmu_enable_spi2(void);
739void prcmu_disable_spi2(void);
740
741#else /* !CONFIG_MFD_DB8500_PRCMU */
742
743static inline int prcmu_set_rc_a2p(enum romcode_write code)
744{
745 return 0;
746}
747
748static inline enum romcode_read prcmu_get_rc_p2a(void)
749{
750 return INIT;
751}
752
753static inline enum ap_pwrst prcmu_get_xp70_current_state(void)
754{
755 return AP_EXECUTE;
756}
757
758static inline int prcmu_set_power_state(u8 state, bool keep_ulp_clk,
759 bool keep_ap_pll)
760{
761 return 0;
762}
763
764static inline void prcmu_enable_wakeups(u32 wakeups) {}
765
766static inline void prcmu_disable_wakeups(void) {}
767
768static inline void prcmu_config_abb_event_readout(u32 abb_events) {}
769
770static inline int prcmu_set_arm_opp(u8 opp)
771{
772 return 0;
773}
774
775static inline int prcmu_get_arm_opp(void)
776{
777 return ARM_100_OPP;
778}
779
780static bool prcmu_has_arm_maxopp(void)
781{
782 return false;
783}
784
785static bool prcmu_is_u8400(void)
786{
787 return false;
788}
789
790static inline int prcmu_set_ape_opp(u8 opp)
791{
792 return 0;
793}
794
795static inline int prcmu_get_ape_opp(void)
796{
797 return APE_100_OPP;
798}
799
800static inline int prcmu_request_ape_opp_100_voltage(bool enable)
801{
802 return 0;
803}
804
805static inline int prcmu_release_usb_wakeup_state(void)
806{
807 return 0;
808}
809
810static inline int prcmu_set_ddr_opp(u8 opp)
811{
812 return 0;
813}
814
815static inline int prcmu_get_ddr_opp(void)
816{
817 return DDR_100_OPP;
818}
819
820static inline unsigned long prcmu_qos_get_cpufreq_opp_delay(void)
821{
822 return 0;
823}
824
825static inline void prcmu_qos_set_cpufreq_opp_delay(unsigned long n) {}
826
827static inline int prcmu_set_hwacc(u16 hw_acc_dev, u8 state)
828{
829 return 0;
830}
831
832static inline void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
833 struct prcmu_auto_pm_config *idle)
834{
835}
836
837static inline bool prcmu_is_auto_pm_enabled(void)
838{
839 return false;
840}
841
842static inline int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
843{
844 return 0;
845}
846
847static inline int prcmu_request_clock(u8 clock, bool enable)
848{
849 return 0;
850}
851
852static inline int prcmu_set_clock_divider(u8 clock, u8 divider)
853{
854 return 0;
855}
856
857int prcmu_config_esram0_deep_sleep(u8 state)
858{
859 return 0;
860}
861
862static inline int prcmu_config_hotdog(u8 threshold)
863{
864 return 0;
865}
866
867static inline int prcmu_config_hotmon(u8 low, u8 high)
868{
869 return 0;
870}
871
872static inline int prcmu_start_temp_sense(u16 cycles32k)
873{
874 return 0;
875}
876
877static inline int prcmu_stop_temp_sense(void)
878{
879 return 0;
880}
881
882static inline int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
883{
884 return -ENOSYS;
885}
886
887static inline int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
888{
889 return -ENOSYS;
890}
891
892static inline void prcmu_ac_wake_req(void) {}
893
894static inline void prcmu_ac_sleep_req(void) {}
895
896static inline void prcmu_system_reset(u16 reset_code) {}
897
898static inline void prcmu_modem_reset(void) {}
899
900static inline bool prcmu_is_ac_wake_requested(void)
901{
902 return false;
903}
904
905#ifndef CONFIG_UX500_SOC_DB5500
906static inline int prcmu_set_display_clocks(void)
907{
908 return 0;
909}
910
911static inline int prcmu_disable_dsipll(void)
912{
913 return 0;
914}
915
916static inline int prcmu_enable_dsipll(void)
917{
918 return 0;
919}
920#endif
921
922static inline int prcmu_enable_spi2(void)
923{
924 return 0;
925}
926
927static inline int prcmu_disable_spi2(void)
928{
929 return 0;
930}
931
932#endif /* !CONFIG_MFD_DB8500_PRCMU */
933
934#ifdef CONFIG_UX500_PRCMU_QOS_POWER
935int prcmu_qos_requirement(int pm_qos_class);
936int prcmu_qos_add_requirement(int pm_qos_class, char *name, s32 value);
937int prcmu_qos_update_requirement(int pm_qos_class, char *name, s32 new_value);
938void prcmu_qos_remove_requirement(int pm_qos_class, char *name);
939int prcmu_qos_add_notifier(int prcmu_qos_class,
940 struct notifier_block *notifier);
941int prcmu_qos_remove_notifier(int prcmu_qos_class,
942 struct notifier_block *notifier);
943#else
944static inline int prcmu_qos_requirement(int prcmu_qos_class)
945{
946 return 0;
947}
948
949static inline int prcmu_qos_add_requirement(int prcmu_qos_class,
950 char *name, s32 value)
951{
952 return 0;
953}
954
955static inline int prcmu_qos_update_requirement(int prcmu_qos_class,
956 char *name, s32 new_value)
957{
958 return 0;
959}
960
961static inline void prcmu_qos_remove_requirement(int prcmu_qos_class, char *name)
962{
963}
964
965static inline int prcmu_qos_add_notifier(int prcmu_qos_class,
966 struct notifier_block *notifier)
967{
968 return 0;
969}
970static inline int prcmu_qos_remove_notifier(int prcmu_qos_class,
971 struct notifier_block *notifier)
972{
973 return 0;
974}
975
976#endif
977
978#endif /* __MFD_DB8500_PRCMU_H */