2 * Copyright (C) STMicroelectronics 2009
3 * Copyright (C) ST-Ericsson SA 2010
5 * License Terms: GNU General Public License v2
6 * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
7 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
8 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
10 * U8500 PRCM Unit interface driver
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/delay.h>
16 #include <linux/errno.h>
17 #include <linux/err.h>
18 #include <linux/spinlock.h>
20 #include <linux/slab.h>
21 #include <linux/mutex.h>
22 #include <linux/completion.h>
23 #include <linux/irq.h>
24 #include <linux/jiffies.h>
25 #include <linux/bitops.h>
27 #include <linux/platform_device.h>
28 #include <linux/uaccess.h>
29 #include <linux/mfd/core.h>
30 #include <linux/mfd/dbx500-prcmu.h>
31 #include <linux/mfd/abx500/ab8500.h>
32 #include <linux/regulator/db8500-prcmu.h>
33 #include <linux/regulator/machine.h>
34 #include <asm/hardware/gic.h>
35 #include <mach/hardware.h>
36 #include <mach/irqs.h>
37 #include <mach/db8500-regs.h>
39 #include "dbx500-prcmu-regs.h"
41 /* Offset for the firmware version within the TCPM */
42 #define PRCMU_FW_VERSION_OFFSET 0xA4
44 /* Index of different voltages to be used when accessing AVSData */
45 #define PRCM_AVS_BASE 0x2FC
46 #define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
47 #define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
48 #define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
49 #define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
50 #define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
51 #define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
52 #define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
53 #define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
54 #define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
55 #define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
56 #define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
57 #define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
58 #define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
60 #define PRCM_AVS_VOLTAGE 0
61 #define PRCM_AVS_VOLTAGE_MASK 0x3f
62 #define PRCM_AVS_ISSLOWSTARTUP 6
63 #define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
64 #define PRCM_AVS_ISMODEENABLE 7
65 #define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
67 #define PRCM_BOOT_STATUS 0xFFF
68 #define PRCM_ROMCODE_A2P 0xFFE
69 #define PRCM_ROMCODE_P2A 0xFFD
70 #define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */
72 #define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */
74 #define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */
75 #define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
76 #define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
77 #define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
78 #define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
79 #define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
80 #define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
81 #define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
84 #define PRCM_REQ_MB0 0xFDC /* 12 bytes */
85 #define PRCM_REQ_MB1 0xFD0 /* 12 bytes */
86 #define PRCM_REQ_MB2 0xFC0 /* 16 bytes */
87 #define PRCM_REQ_MB3 0xE4C /* 372 bytes */
88 #define PRCM_REQ_MB4 0xE48 /* 4 bytes */
89 #define PRCM_REQ_MB5 0xE44 /* 4 bytes */
92 #define PRCM_ACK_MB0 0xE08 /* 52 bytes */
93 #define PRCM_ACK_MB1 0xE04 /* 4 bytes */
94 #define PRCM_ACK_MB2 0xE00 /* 4 bytes */
95 #define PRCM_ACK_MB3 0xDFC /* 4 bytes */
96 #define PRCM_ACK_MB4 0xDF8 /* 4 bytes */
97 #define PRCM_ACK_MB5 0xDF4 /* 4 bytes */
99 /* Mailbox 0 headers */
100 #define MB0H_POWER_STATE_TRANS 0
101 #define MB0H_CONFIG_WAKEUPS_EXE 1
102 #define MB0H_READ_WAKEUP_ACK 3
103 #define MB0H_CONFIG_WAKEUPS_SLEEP 4
105 #define MB0H_WAKEUP_EXE 2
106 #define MB0H_WAKEUP_SLEEP 5
109 #define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
110 #define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
111 #define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
112 #define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
113 #define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
114 #define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
117 #define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
118 #define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
119 #define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
120 #define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
121 #define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
122 #define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
123 #define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
125 /* Mailbox 1 headers */
126 #define MB1H_ARM_APE_OPP 0x0
127 #define MB1H_RESET_MODEM 0x2
128 #define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
129 #define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
130 #define MB1H_RELEASE_USB_WAKEUP 0x5
131 #define MB1H_PLL_ON_OFF 0x6
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_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4)
137 #define PLL_SOC0_OFF 0x1
138 #define PLL_SOC0_ON 0x2
139 #define PLL_SOC1_OFF 0x4
140 #define PLL_SOC1_ON 0x8
143 #define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0)
144 #define PRCM_ACK_MB1_CURRENT_APE_OPP (PRCM_ACK_MB1 + 0x1)
145 #define PRCM_ACK_MB1_APE_VOLTAGE_STATUS (PRCM_ACK_MB1 + 0x2)
146 #define PRCM_ACK_MB1_DVFS_STATUS (PRCM_ACK_MB1 + 0x3)
148 /* Mailbox 2 headers */
150 #define MB2H_AUTO_PWR 0x1
153 #define PRCM_REQ_MB2_SVA_MMDSP (PRCM_REQ_MB2 + 0x0)
154 #define PRCM_REQ_MB2_SVA_PIPE (PRCM_REQ_MB2 + 0x1)
155 #define PRCM_REQ_MB2_SIA_MMDSP (PRCM_REQ_MB2 + 0x2)
156 #define PRCM_REQ_MB2_SIA_PIPE (PRCM_REQ_MB2 + 0x3)
157 #define PRCM_REQ_MB2_SGA (PRCM_REQ_MB2 + 0x4)
158 #define PRCM_REQ_MB2_B2R2_MCDE (PRCM_REQ_MB2 + 0x5)
159 #define PRCM_REQ_MB2_ESRAM12 (PRCM_REQ_MB2 + 0x6)
160 #define PRCM_REQ_MB2_ESRAM34 (PRCM_REQ_MB2 + 0x7)
161 #define PRCM_REQ_MB2_AUTO_PM_SLEEP (PRCM_REQ_MB2 + 0x8)
162 #define PRCM_REQ_MB2_AUTO_PM_IDLE (PRCM_REQ_MB2 + 0xC)
165 #define PRCM_ACK_MB2_DPS_STATUS (PRCM_ACK_MB2 + 0x0)
166 #define HWACC_PWR_ST_OK 0xFE
168 /* Mailbox 3 headers */
170 #define MB3H_SIDETONE 0x1
171 #define MB3H_SYSCLK 0xE
173 /* Mailbox 3 Requests */
174 #define PRCM_REQ_MB3_ANC_FIR_COEFF (PRCM_REQ_MB3 + 0x0)
175 #define PRCM_REQ_MB3_ANC_IIR_COEFF (PRCM_REQ_MB3 + 0x20)
176 #define PRCM_REQ_MB3_ANC_SHIFTER (PRCM_REQ_MB3 + 0x60)
177 #define PRCM_REQ_MB3_ANC_WARP (PRCM_REQ_MB3 + 0x64)
178 #define PRCM_REQ_MB3_SIDETONE_FIR_GAIN (PRCM_REQ_MB3 + 0x68)
179 #define PRCM_REQ_MB3_SIDETONE_FIR_COEFF (PRCM_REQ_MB3 + 0x6C)
180 #define PRCM_REQ_MB3_SYSCLK_MGT (PRCM_REQ_MB3 + 0x16C)
182 /* Mailbox 4 headers */
183 #define MB4H_DDR_INIT 0x0
184 #define MB4H_MEM_ST 0x1
185 #define MB4H_HOTDOG 0x12
186 #define MB4H_HOTMON 0x13
187 #define MB4H_HOT_PERIOD 0x14
188 #define MB4H_A9WDOG_CONF 0x16
189 #define MB4H_A9WDOG_EN 0x17
190 #define MB4H_A9WDOG_DIS 0x18
191 #define MB4H_A9WDOG_LOAD 0x19
192 #define MB4H_A9WDOG_KICK 0x20
194 /* Mailbox 4 Requests */
195 #define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
196 #define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
197 #define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
198 #define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
199 #define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
200 #define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
201 #define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
202 #define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
203 #define HOTMON_CONFIG_LOW BIT(0)
204 #define HOTMON_CONFIG_HIGH BIT(1)
205 #define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0)
206 #define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1)
207 #define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2)
208 #define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3)
209 #define A9WDOG_AUTO_OFF_EN BIT(7)
210 #define A9WDOG_AUTO_OFF_DIS 0
211 #define A9WDOG_ID_MASK 0xf
213 /* Mailbox 5 Requests */
214 #define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
215 #define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
216 #define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
217 #define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
218 #define PRCMU_I2C_WRITE(slave) \
219 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0))
220 #define PRCMU_I2C_READ(slave) \
221 (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0))
222 #define PRCMU_I2C_STOP_EN BIT(3)
225 #define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
226 #define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
227 #define I2C_WR_OK 0x1
228 #define I2C_RD_OK 0x2
232 #define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
238 #define WAKEUP_BIT_RTC BIT(0)
239 #define WAKEUP_BIT_RTT0 BIT(1)
240 #define WAKEUP_BIT_RTT1 BIT(2)
241 #define WAKEUP_BIT_HSI0 BIT(3)
242 #define WAKEUP_BIT_HSI1 BIT(4)
243 #define WAKEUP_BIT_CA_WAKE BIT(5)
244 #define WAKEUP_BIT_USB BIT(6)
245 #define WAKEUP_BIT_ABB BIT(7)
246 #define WAKEUP_BIT_ABB_FIFO BIT(8)
247 #define WAKEUP_BIT_SYSCLK_OK BIT(9)
248 #define WAKEUP_BIT_CA_SLEEP BIT(10)
249 #define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
250 #define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
251 #define WAKEUP_BIT_ANC_OK BIT(13)
252 #define WAKEUP_BIT_SW_ERROR BIT(14)
253 #define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
254 #define WAKEUP_BIT_ARM BIT(17)
255 #define WAKEUP_BIT_HOTMON_LOW BIT(18)
256 #define WAKEUP_BIT_HOTMON_HIGH BIT(19)
257 #define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
258 #define WAKEUP_BIT_GPIO0 BIT(23)
259 #define WAKEUP_BIT_GPIO1 BIT(24)
260 #define WAKEUP_BIT_GPIO2 BIT(25)
261 #define WAKEUP_BIT_GPIO3 BIT(26)
262 #define WAKEUP_BIT_GPIO4 BIT(27)
263 #define WAKEUP_BIT_GPIO5 BIT(28)
264 #define WAKEUP_BIT_GPIO6 BIT(29)
265 #define WAKEUP_BIT_GPIO7 BIT(30)
266 #define WAKEUP_BIT_GPIO8 BIT(31)
270 struct prcmu_fw_version version;
274 * This vector maps irq numbers to the bits in the bit field used in
275 * communication with the PRCMU firmware.
277 * The reason for having this is to keep the irq numbers contiguous even though
278 * the bits in the bit field are not. (The bits also have a tendency to move
279 * around, to further complicate matters.)
281 #define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE)
282 #define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
283 static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
295 IRQ_ENTRY(HOTMON_LOW),
296 IRQ_ENTRY(HOTMON_HIGH),
297 IRQ_ENTRY(MODEM_SW_RESET_REQ),
309 #define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
310 #define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
311 static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = {
319 WAKEUP_ENTRY(ABB_FIFO),
324 * mb0_transfer - state needed for mailbox 0 communication.
325 * @lock: The transaction lock.
326 * @dbb_events_lock: A lock used to handle concurrent access to (parts of)
328 * @mask_work: Work structure used for (un)masking wakeup interrupts.
329 * @req: Request data that need to persist between requests.
333 spinlock_t dbb_irqs_lock;
334 struct work_struct mask_work;
335 struct mutex ac_wake_lock;
336 struct completion ac_wake_work;
345 * mb1_transfer - state needed for mailbox 1 communication.
346 * @lock: The transaction lock.
347 * @work: The transaction completion structure.
348 * @ape_opp: The current APE OPP.
349 * @ack: Reply ("acknowledge") data.
353 struct completion work;
359 u8 ape_voltage_status;
364 * mb2_transfer - state needed for mailbox 2 communication.
365 * @lock: The transaction lock.
366 * @work: The transaction completion structure.
367 * @auto_pm_lock: The autonomous power management configuration lock.
368 * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled.
369 * @req: Request data that need to persist between requests.
370 * @ack: Reply ("acknowledge") data.
374 struct completion work;
375 spinlock_t auto_pm_lock;
376 bool auto_pm_enabled;
383 * mb3_transfer - state needed for mailbox 3 communication.
384 * @lock: The request lock.
385 * @sysclk_lock: A lock used to handle concurrent sysclk requests.
386 * @sysclk_work: Work structure used for sysclk requests.
390 struct mutex sysclk_lock;
391 struct completion sysclk_work;
395 * mb4_transfer - state needed for mailbox 4 communication.
396 * @lock: The transaction lock.
397 * @work: The transaction completion structure.
401 struct completion work;
405 * mb5_transfer - state needed for mailbox 5 communication.
406 * @lock: The transaction lock.
407 * @work: The transaction completion structure.
408 * @ack: Reply ("acknowledge") data.
412 struct completion work;
419 static atomic_t ac_wake_req_state = ATOMIC_INIT(0);
422 static DEFINE_SPINLOCK(prcmu_lock);
423 static DEFINE_SPINLOCK(clkout_lock);
425 /* Global var to runtime determine TCDM base for v2 or v1 */
426 static __iomem void *tcdm_base;
441 static DEFINE_SPINLOCK(clk_mgt_lock);
443 #define CLK_MGT_ENTRY(_name, _branch, _clk38div)[PRCMU_##_name] = \
444 { (PRCM_##_name##_MGT), 0 , _branch, _clk38div}
445 struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
446 CLK_MGT_ENTRY(SGACLK, PLL_DIV, false),
447 CLK_MGT_ENTRY(UARTCLK, PLL_FIX, true),
448 CLK_MGT_ENTRY(MSP02CLK, PLL_FIX, true),
449 CLK_MGT_ENTRY(MSP1CLK, PLL_FIX, true),
450 CLK_MGT_ENTRY(I2CCLK, PLL_FIX, true),
451 CLK_MGT_ENTRY(SDMMCCLK, PLL_DIV, true),
452 CLK_MGT_ENTRY(SLIMCLK, PLL_FIX, true),
453 CLK_MGT_ENTRY(PER1CLK, PLL_DIV, true),
454 CLK_MGT_ENTRY(PER2CLK, PLL_DIV, true),
455 CLK_MGT_ENTRY(PER3CLK, PLL_DIV, true),
456 CLK_MGT_ENTRY(PER5CLK, PLL_DIV, true),
457 CLK_MGT_ENTRY(PER6CLK, PLL_DIV, true),
458 CLK_MGT_ENTRY(PER7CLK, PLL_DIV, true),
459 CLK_MGT_ENTRY(LCDCLK, PLL_FIX, true),
460 CLK_MGT_ENTRY(BMLCLK, PLL_DIV, true),
461 CLK_MGT_ENTRY(HSITXCLK, PLL_DIV, true),
462 CLK_MGT_ENTRY(HSIRXCLK, PLL_DIV, true),
463 CLK_MGT_ENTRY(HDMICLK, PLL_FIX, false),
464 CLK_MGT_ENTRY(APEATCLK, PLL_DIV, true),
465 CLK_MGT_ENTRY(APETRACECLK, PLL_DIV, true),
466 CLK_MGT_ENTRY(MCDECLK, PLL_DIV, true),
467 CLK_MGT_ENTRY(IPI2CCLK, PLL_FIX, true),
468 CLK_MGT_ENTRY(DSIALTCLK, PLL_FIX, false),
469 CLK_MGT_ENTRY(DMACLK, PLL_DIV, true),
470 CLK_MGT_ENTRY(B2R2CLK, PLL_DIV, true),
471 CLK_MGT_ENTRY(TVCLK, PLL_FIX, true),
472 CLK_MGT_ENTRY(SSPCLK, PLL_FIX, true),
473 CLK_MGT_ENTRY(RNGCLK, PLL_FIX, true),
474 CLK_MGT_ENTRY(UICCCLK, PLL_FIX, false),
483 static struct dsiclk dsiclk[2] = {
485 .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_MASK,
486 .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_SHIFT,
487 .divsel = PRCM_DSI_PLLOUT_SEL_PHI,
490 .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_MASK,
491 .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_SHIFT,
492 .divsel = PRCM_DSI_PLLOUT_SEL_PHI,
502 static struct dsiescclk dsiescclk[3] = {
504 .en = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_EN,
505 .div_mask = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_MASK,
506 .div_shift = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_SHIFT,
509 .en = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_EN,
510 .div_mask = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_MASK,
511 .div_shift = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_SHIFT,
514 .en = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_EN,
515 .div_mask = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_MASK,
516 .div_shift = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_SHIFT,
521 * Used by MCDE to setup all necessary PRCMU registers
523 #define PRCMU_RESET_DSIPLL 0x00004000
524 #define PRCMU_UNCLAMP_DSIPLL 0x00400800
526 #define PRCMU_CLK_PLL_DIV_SHIFT 0
527 #define PRCMU_CLK_PLL_SW_SHIFT 5
528 #define PRCMU_CLK_38 (1 << 9)
529 #define PRCMU_CLK_38_SRC (1 << 10)
530 #define PRCMU_CLK_38_DIV (1 << 11)
532 /* PLLDIV=12, PLLSW=4 (PLLDDR) */
533 #define PRCMU_DSI_CLOCK_SETTING 0x0000008C
535 /* DPI 50000000 Hz */
536 #define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
537 (16 << PRCMU_CLK_PLL_DIV_SHIFT))
538 #define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
540 /* D=101, N=1, R=4, SELDIV2=0 */
541 #define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
543 #define PRCMU_ENABLE_PLLDSI 0x00000001
544 #define PRCMU_DISABLE_PLLDSI 0x00000000
545 #define PRCMU_RELEASE_RESET_DSS 0x0000400C
546 #define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
547 /* ESC clk, div0=1, div1=1, div2=3 */
548 #define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
549 #define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
550 #define PRCMU_DSI_RESET_SW 0x00000007
552 #define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
554 int db8500_prcmu_enable_dsipll(void)
558 /* Clear DSIPLL_RESETN */
559 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_CLR);
560 /* Unclamp DSIPLL in/out */
561 writel(PRCMU_UNCLAMP_DSIPLL, PRCM_MMIP_LS_CLAMP_CLR);
563 /* Set DSI PLL FREQ */
564 writel(PRCMU_PLLDSI_FREQ_SETTING, PRCM_PLLDSI_FREQ);
565 writel(PRCMU_DSI_PLLOUT_SEL_SETTING, PRCM_DSI_PLLOUT_SEL);
566 /* Enable Escape clocks */
567 writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
570 writel(PRCMU_ENABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
572 writel(PRCMU_DSI_RESET_SW, PRCM_DSI_SW_RESET);
573 for (i = 0; i < 10; i++) {
574 if ((readl(PRCM_PLLDSI_LOCKP) & PRCMU_PLLDSI_LOCKP_LOCKED)
575 == PRCMU_PLLDSI_LOCKP_LOCKED)
579 /* Set DSIPLL_RESETN */
580 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_SET);
584 int db8500_prcmu_disable_dsipll(void)
586 /* Disable dsi pll */
587 writel(PRCMU_DISABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
588 /* Disable escapeclock */
589 writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
593 int db8500_prcmu_set_display_clocks(void)
597 spin_lock_irqsave(&clk_mgt_lock, flags);
599 /* Grab the HW semaphore. */
600 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
603 writel(PRCMU_DSI_CLOCK_SETTING, PRCM_HDMICLK_MGT);
604 writel(PRCMU_DSI_LP_CLOCK_SETTING, PRCM_TVCLK_MGT);
605 writel(PRCMU_DPI_CLOCK_SETTING, PRCM_LCDCLK_MGT);
607 /* Release the HW semaphore. */
610 spin_unlock_irqrestore(&clk_mgt_lock, flags);
615 u32 db8500_prcmu_read(unsigned int reg)
617 return readl(_PRCMU_BASE + reg);
620 void db8500_prcmu_write(unsigned int reg, u32 value)
624 spin_lock_irqsave(&prcmu_lock, flags);
625 writel(value, (_PRCMU_BASE + reg));
626 spin_unlock_irqrestore(&prcmu_lock, flags);
629 void db8500_prcmu_write_masked(unsigned int reg, u32 mask, u32 value)
634 spin_lock_irqsave(&prcmu_lock, flags);
635 val = readl(_PRCMU_BASE + reg);
636 val = ((val & ~mask) | (value & mask));
637 writel(val, (_PRCMU_BASE + reg));
638 spin_unlock_irqrestore(&prcmu_lock, flags);
641 struct prcmu_fw_version *prcmu_get_fw_version(void)
643 return fw_info.valid ? &fw_info.version : NULL;
646 bool prcmu_has_arm_maxopp(void)
648 return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) &
649 PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK;
653 * prcmu_get_boot_status - PRCMU boot status checking
654 * Returns: the current PRCMU boot status
656 int prcmu_get_boot_status(void)
658 return readb(tcdm_base + PRCM_BOOT_STATUS);
662 * prcmu_set_rc_a2p - This function is used to run few power state sequences
663 * @val: Value to be set, i.e. transition requested
664 * Returns: 0 on success, -EINVAL on invalid argument
666 * This function is used to run the following power state sequences -
667 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
669 int prcmu_set_rc_a2p(enum romcode_write val)
671 if (val < RDY_2_DS || val > RDY_2_XP70_RST)
673 writeb(val, (tcdm_base + PRCM_ROMCODE_A2P));
678 * prcmu_get_rc_p2a - This function is used to get power state sequences
679 * Returns: the power transition that has last happened
681 * This function can return the following transitions-
682 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
684 enum romcode_read prcmu_get_rc_p2a(void)
686 return readb(tcdm_base + PRCM_ROMCODE_P2A);
690 * prcmu_get_current_mode - Return the current XP70 power mode
691 * Returns: Returns the current AP(ARM) power mode: init,
692 * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset
694 enum ap_pwrst prcmu_get_xp70_current_state(void)
696 return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE);
700 * prcmu_config_clkout - Configure one of the programmable clock outputs.
701 * @clkout: The CLKOUT number (0 or 1).
702 * @source: The clock to be used (one of the PRCMU_CLKSRC_*).
703 * @div: The divider to be applied.
705 * Configures one of the programmable clock outputs (CLKOUTs).
706 * @div should be in the range [1,63] to request a configuration, or 0 to
707 * inform that the configuration is no longer requested.
709 int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
711 static int requests[2];
721 BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009));
723 if (!div && !requests[clkout])
728 div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
729 mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
730 bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
731 (div << PRCM_CLKOCR_CLKODIV0_SHIFT));
734 div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
735 mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
736 PRCM_CLKOCR_CLK1TYPE);
737 bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
738 (div << PRCM_CLKOCR_CLKODIV1_SHIFT));
743 spin_lock_irqsave(&clkout_lock, flags);
745 val = readl(PRCM_CLKOCR);
746 if (val & div_mask) {
748 if ((val & mask) != bits) {
750 goto unlock_and_return;
753 if ((val & mask & ~div_mask) != bits) {
755 goto unlock_and_return;
759 writel((bits | (val & ~mask)), PRCM_CLKOCR);
760 requests[clkout] += (div ? 1 : -1);
763 spin_unlock_irqrestore(&clkout_lock, flags);
768 int db8500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
772 BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state));
774 spin_lock_irqsave(&mb0_transfer.lock, flags);
776 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
779 writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
780 writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE));
781 writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE));
782 writeb((keep_ulp_clk ? 1 : 0),
783 (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
784 writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
785 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
787 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
792 u8 db8500_prcmu_get_power_state_result(void)
794 return readb(tcdm_base + PRCM_ACK_MB0_AP_PWRSTTR_STATUS);
797 /* This function decouple the gic from the prcmu */
798 int db8500_prcmu_gic_decouple(void)
800 u32 val = readl(PRCM_A9_MASK_REQ);
802 /* Set bit 0 register value to 1 */
803 writel(val | PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ,
806 /* Make sure the register is updated */
807 readl(PRCM_A9_MASK_REQ);
809 /* Wait a few cycles for the gic mask completion */
815 /* This function recouple the gic with the prcmu */
816 int db8500_prcmu_gic_recouple(void)
818 u32 val = readl(PRCM_A9_MASK_REQ);
820 /* Set bit 0 register value to 0 */
821 writel(val & ~PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ, PRCM_A9_MASK_REQ);
826 #define PRCMU_GIC_NUMBER_REGS 5
829 * This function checks if there are pending irq on the gic. It only
830 * makes sense if the gic has been decoupled before with the
831 * db8500_prcmu_gic_decouple function. Disabling an interrupt only
832 * disables the forwarding of the interrupt to any CPU interface. It
833 * does not prevent the interrupt from changing state, for example
834 * becoming pending, or active and pending if it is already
835 * active. Hence, we have to check the interrupt is pending *and* is
838 bool db8500_prcmu_gic_pending_irq(void)
840 u32 pr; /* Pending register */
841 u32 er; /* Enable register */
842 void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE);
845 /* 5 registers. STI & PPI not skipped */
846 for (i = 0; i < PRCMU_GIC_NUMBER_REGS; i++) {
848 pr = readl_relaxed(dist_base + GIC_DIST_PENDING_SET + i * 4);
849 er = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
852 return true; /* There is a pending interrupt */
859 * This function checks if there are pending interrupt on the
860 * prcmu which has been delegated to monitor the irqs with the
861 * db8500_prcmu_copy_gic_settings function.
863 bool db8500_prcmu_pending_irq(void)
868 for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
869 it = readl(PRCM_ARMITVAL31TO0 + i * 4);
870 im = readl(PRCM_ARMITMSK31TO0 + i * 4);
872 return true; /* There is a pending interrupt */
879 * This function checks if the specified cpu is in in WFI. It's usage
880 * makes sense only if the gic is decoupled with the db8500_prcmu_gic_decouple
881 * function. Of course passing smp_processor_id() to this function will
882 * always return false...
884 bool db8500_prcmu_is_cpu_in_wfi(int cpu)
886 return readl(PRCM_ARM_WFI_STANDBY) & cpu ? PRCM_ARM_WFI_STANDBY_WFI1 :
887 PRCM_ARM_WFI_STANDBY_WFI0;
891 * This function copies the gic SPI settings to the prcmu in order to
892 * monitor them and abort/finish the retention/off sequence or state.
894 int db8500_prcmu_copy_gic_settings(void)
896 u32 er; /* Enable register */
897 void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE);
900 /* We skip the STI and PPI */
901 for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
902 er = readl_relaxed(dist_base +
903 GIC_DIST_ENABLE_SET + (i + 1) * 4);
904 writel(er, PRCM_ARMITMSK31TO0 + i * 4);
910 /* This function should only be called while mb0_transfer.lock is held. */
911 static void config_wakeups(void)
913 const u8 header[2] = {
914 MB0H_CONFIG_WAKEUPS_EXE,
915 MB0H_CONFIG_WAKEUPS_SLEEP
917 static u32 last_dbb_events;
918 static u32 last_abb_events;
923 dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
924 dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK);
926 abb_events = mb0_transfer.req.abb_events;
928 if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
931 for (i = 0; i < 2; i++) {
932 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
934 writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
935 writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
936 writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
937 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
939 last_dbb_events = dbb_events;
940 last_abb_events = abb_events;
943 void db8500_prcmu_enable_wakeups(u32 wakeups)
949 BUG_ON(wakeups != (wakeups & VALID_WAKEUPS));
951 for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) {
952 if (wakeups & BIT(i))
953 bits |= prcmu_wakeup_bit[i];
956 spin_lock_irqsave(&mb0_transfer.lock, flags);
958 mb0_transfer.req.dbb_wakeups = bits;
961 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
964 void db8500_prcmu_config_abb_event_readout(u32 abb_events)
968 spin_lock_irqsave(&mb0_transfer.lock, flags);
970 mb0_transfer.req.abb_events = abb_events;
973 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
976 void db8500_prcmu_get_abb_event_buffer(void __iomem **buf)
978 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
979 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
981 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500);
985 * db8500_prcmu_set_arm_opp - set the appropriate ARM OPP
986 * @opp: The new ARM operating point to which transition is to be made
987 * Returns: 0 on success, non-zero on failure
989 * This function sets the the operating point of the ARM.
991 int db8500_prcmu_set_arm_opp(u8 opp)
995 if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK)
1000 mutex_lock(&mb1_transfer.lock);
1002 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1005 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1006 writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
1007 writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
1009 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1010 wait_for_completion(&mb1_transfer.work);
1012 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
1013 (mb1_transfer.ack.arm_opp != opp))
1016 mutex_unlock(&mb1_transfer.lock);
1022 * db8500_prcmu_get_arm_opp - get the current ARM OPP
1024 * Returns: the current ARM OPP
1026 int db8500_prcmu_get_arm_opp(void)
1028 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
1032 * db8500_prcmu_get_ddr_opp - get the current DDR OPP
1034 * Returns: the current DDR OPP
1036 int db8500_prcmu_get_ddr_opp(void)
1038 return readb(PRCM_DDR_SUBSYS_APE_MINBW);
1042 * db8500_set_ddr_opp - set the appropriate DDR OPP
1043 * @opp: The new DDR operating point to which transition is to be made
1044 * Returns: 0 on success, non-zero on failure
1046 * This function sets the operating point of the DDR.
1048 int db8500_prcmu_set_ddr_opp(u8 opp)
1050 if (opp < DDR_100_OPP || opp > DDR_25_OPP)
1052 /* Changing the DDR OPP can hang the hardware pre-v21 */
1053 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
1054 writeb(opp, PRCM_DDR_SUBSYS_APE_MINBW);
1059 /* Divide the frequency of certain clocks by 2 for APE_50_PARTLY_25_OPP. */
1060 static void request_even_slower_clocks(bool enable)
1062 void __iomem *clock_reg[] = {
1066 unsigned long flags;
1069 spin_lock_irqsave(&clk_mgt_lock, flags);
1071 /* Grab the HW semaphore. */
1072 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1075 for (i = 0; i < ARRAY_SIZE(clock_reg); i++) {
1079 val = readl(clock_reg[i]);
1080 div = (val & PRCM_CLK_MGT_CLKPLLDIV_MASK);
1082 if ((div <= 1) || (div > 15)) {
1083 pr_err("prcmu: Bad clock divider %d in %s\n",
1085 goto unlock_and_return;
1090 goto unlock_and_return;
1093 val = ((val & ~PRCM_CLK_MGT_CLKPLLDIV_MASK) |
1094 (div & PRCM_CLK_MGT_CLKPLLDIV_MASK));
1095 writel(val, clock_reg[i]);
1099 /* Release the HW semaphore. */
1100 writel(0, PRCM_SEM);
1102 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1106 * db8500_set_ape_opp - set the appropriate APE OPP
1107 * @opp: The new APE operating point to which transition is to be made
1108 * Returns: 0 on success, non-zero on failure
1110 * This function sets the operating point of the APE.
1112 int db8500_prcmu_set_ape_opp(u8 opp)
1116 if (opp == mb1_transfer.ape_opp)
1119 mutex_lock(&mb1_transfer.lock);
1121 if (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP)
1122 request_even_slower_clocks(false);
1124 if ((opp != APE_100_OPP) && (mb1_transfer.ape_opp != APE_100_OPP))
1127 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1130 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1131 writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
1132 writeb(((opp == APE_50_PARTLY_25_OPP) ? APE_50_OPP : opp),
1133 (tcdm_base + PRCM_REQ_MB1_APE_OPP));
1135 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1136 wait_for_completion(&mb1_transfer.work);
1138 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
1139 (mb1_transfer.ack.ape_opp != opp))
1143 if ((!r && (opp == APE_50_PARTLY_25_OPP)) ||
1144 (r && (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP)))
1145 request_even_slower_clocks(true);
1147 mb1_transfer.ape_opp = opp;
1149 mutex_unlock(&mb1_transfer.lock);
1155 * db8500_prcmu_get_ape_opp - get the current APE OPP
1157 * Returns: the current APE OPP
1159 int db8500_prcmu_get_ape_opp(void)
1161 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP);
1165 * prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage
1166 * @enable: true to request the higher voltage, false to drop a request.
1168 * Calls to this function to enable and disable requests must be balanced.
1170 int prcmu_request_ape_opp_100_voltage(bool enable)
1174 static unsigned int requests;
1176 mutex_lock(&mb1_transfer.lock);
1179 if (0 != requests++)
1180 goto unlock_and_return;
1181 header = MB1H_REQUEST_APE_OPP_100_VOLT;
1183 if (requests == 0) {
1185 goto unlock_and_return;
1186 } else if (1 != requests--) {
1187 goto unlock_and_return;
1189 header = MB1H_RELEASE_APE_OPP_100_VOLT;
1192 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1195 writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1197 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1198 wait_for_completion(&mb1_transfer.work);
1200 if ((mb1_transfer.ack.header != header) ||
1201 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
1205 mutex_unlock(&mb1_transfer.lock);
1211 * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup
1213 * This function releases the power state requirements of a USB wakeup.
1215 int prcmu_release_usb_wakeup_state(void)
1219 mutex_lock(&mb1_transfer.lock);
1221 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1224 writeb(MB1H_RELEASE_USB_WAKEUP,
1225 (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1227 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1228 wait_for_completion(&mb1_transfer.work);
1230 if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
1231 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
1234 mutex_unlock(&mb1_transfer.lock);
1239 static int request_pll(u8 clock, bool enable)
1243 if (clock == PRCMU_PLLSOC0)
1244 clock = (enable ? PLL_SOC0_ON : PLL_SOC0_OFF);
1245 else if (clock == PRCMU_PLLSOC1)
1246 clock = (enable ? PLL_SOC1_ON : PLL_SOC1_OFF);
1250 mutex_lock(&mb1_transfer.lock);
1252 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1255 writeb(MB1H_PLL_ON_OFF, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1256 writeb(clock, (tcdm_base + PRCM_REQ_MB1_PLL_ON_OFF));
1258 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1259 wait_for_completion(&mb1_transfer.work);
1261 if (mb1_transfer.ack.header != MB1H_PLL_ON_OFF)
1264 mutex_unlock(&mb1_transfer.lock);
1270 * db8500_prcmu_set_epod - set the state of a EPOD (power domain)
1271 * @epod_id: The EPOD to set
1272 * @epod_state: The new EPOD state
1274 * This function sets the state of a EPOD (power domain). It may not be called
1275 * from interrupt context.
1277 int db8500_prcmu_set_epod(u16 epod_id, u8 epod_state)
1280 bool ram_retention = false;
1283 /* check argument */
1284 BUG_ON(epod_id >= NUM_EPOD_ID);
1286 /* set flag if retention is possible */
1288 case EPOD_ID_SVAMMDSP:
1289 case EPOD_ID_SIAMMDSP:
1290 case EPOD_ID_ESRAM12:
1291 case EPOD_ID_ESRAM34:
1292 ram_retention = true;
1296 /* check argument */
1297 BUG_ON(epod_state > EPOD_STATE_ON);
1298 BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention);
1301 mutex_lock(&mb2_transfer.lock);
1303 /* wait for mailbox */
1304 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
1307 /* fill in mailbox */
1308 for (i = 0; i < NUM_EPOD_ID; i++)
1309 writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i));
1310 writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id));
1312 writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
1314 writel(MBOX_BIT(2), PRCM_MBOX_CPU_SET);
1317 * The current firmware version does not handle errors correctly,
1318 * and we cannot recover if there is an error.
1319 * This is expected to change when the firmware is updated.
1321 if (!wait_for_completion_timeout(&mb2_transfer.work,
1322 msecs_to_jiffies(20000))) {
1323 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1326 goto unlock_and_return;
1329 if (mb2_transfer.ack.status != HWACC_PWR_ST_OK)
1333 mutex_unlock(&mb2_transfer.lock);
1338 * prcmu_configure_auto_pm - Configure autonomous power management.
1339 * @sleep: Configuration for ApSleep.
1340 * @idle: Configuration for ApIdle.
1342 void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
1343 struct prcmu_auto_pm_config *idle)
1347 unsigned long flags;
1349 BUG_ON((sleep == NULL) || (idle == NULL));
1351 sleep_cfg = (sleep->sva_auto_pm_enable & 0xF);
1352 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF));
1353 sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF));
1354 sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF));
1355 sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF));
1356 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF));
1358 idle_cfg = (idle->sva_auto_pm_enable & 0xF);
1359 idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF));
1360 idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF));
1361 idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF));
1362 idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF));
1363 idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF));
1365 spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags);
1368 * The autonomous power management configuration is done through
1369 * fields in mailbox 2, but these fields are only used as shared
1370 * variables - i.e. there is no need to send a message.
1372 writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP));
1373 writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE));
1375 mb2_transfer.auto_pm_enabled =
1376 ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1377 (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1378 (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1379 (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON));
1381 spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
1383 EXPORT_SYMBOL(prcmu_configure_auto_pm);
1385 bool prcmu_is_auto_pm_enabled(void)
1387 return mb2_transfer.auto_pm_enabled;
1390 static int request_sysclk(bool enable)
1393 unsigned long flags;
1397 mutex_lock(&mb3_transfer.sysclk_lock);
1399 spin_lock_irqsave(&mb3_transfer.lock, flags);
1401 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
1404 writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
1406 writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
1407 writel(MBOX_BIT(3), PRCM_MBOX_CPU_SET);
1409 spin_unlock_irqrestore(&mb3_transfer.lock, flags);
1412 * The firmware only sends an ACK if we want to enable the
1413 * SysClk, and it succeeds.
1415 if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work,
1416 msecs_to_jiffies(20000))) {
1417 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1422 mutex_unlock(&mb3_transfer.sysclk_lock);
1427 static int request_timclk(bool enable)
1429 u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK);
1432 val |= PRCM_TCR_STOP_TIMERS;
1433 writel(val, PRCM_TCR);
1438 static int request_clock(u8 clock, bool enable)
1441 unsigned long flags;
1443 spin_lock_irqsave(&clk_mgt_lock, flags);
1445 /* Grab the HW semaphore. */
1446 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1449 val = readl(clk_mgt[clock].reg);
1451 val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw);
1453 clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
1454 val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK);
1456 writel(val, clk_mgt[clock].reg);
1458 /* Release the HW semaphore. */
1459 writel(0, PRCM_SEM);
1461 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1466 static int request_sga_clock(u8 clock, bool enable)
1472 val = readl(PRCM_CGATING_BYPASS);
1473 writel(val | PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1476 ret = request_clock(clock, enable);
1478 if (!ret && !enable) {
1479 val = readl(PRCM_CGATING_BYPASS);
1480 writel(val & ~PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1486 static inline bool plldsi_locked(void)
1488 return (readl(PRCM_PLLDSI_LOCKP) &
1489 (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 |
1490 PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3)) ==
1491 (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 |
1492 PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3);
1495 static int request_plldsi(bool enable)
1500 writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP |
1501 PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI), (enable ?
1502 PRCM_MMIP_LS_CLAMP_CLR : PRCM_MMIP_LS_CLAMP_SET));
1504 val = readl(PRCM_PLLDSI_ENABLE);
1506 val |= PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
1508 val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
1509 writel(val, PRCM_PLLDSI_ENABLE);
1513 bool locked = plldsi_locked();
1515 for (i = 10; !locked && (i > 0); --i) {
1517 locked = plldsi_locked();
1520 writel(PRCM_APE_RESETN_DSIPLL_RESETN,
1521 PRCM_APE_RESETN_SET);
1523 writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP |
1524 PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI),
1525 PRCM_MMIP_LS_CLAMP_SET);
1526 val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
1527 writel(val, PRCM_PLLDSI_ENABLE);
1531 writel(PRCM_APE_RESETN_DSIPLL_RESETN, PRCM_APE_RESETN_CLR);
1536 static int request_dsiclk(u8 n, bool enable)
1540 val = readl(PRCM_DSI_PLLOUT_SEL);
1541 val &= ~dsiclk[n].divsel_mask;
1542 val |= ((enable ? dsiclk[n].divsel : PRCM_DSI_PLLOUT_SEL_OFF) <<
1543 dsiclk[n].divsel_shift);
1544 writel(val, PRCM_DSI_PLLOUT_SEL);
1548 static int request_dsiescclk(u8 n, bool enable)
1552 val = readl(PRCM_DSITVCLK_DIV);
1553 enable ? (val |= dsiescclk[n].en) : (val &= ~dsiescclk[n].en);
1554 writel(val, PRCM_DSITVCLK_DIV);
1559 * db8500_prcmu_request_clock() - Request for a clock to be enabled or disabled.
1560 * @clock: The clock for which the request is made.
1561 * @enable: Whether the clock should be enabled (true) or disabled (false).
1563 * This function should only be used by the clock implementation.
1564 * Do not use it from any other place!
1566 int db8500_prcmu_request_clock(u8 clock, bool enable)
1568 if (clock == PRCMU_SGACLK)
1569 return request_sga_clock(clock, enable);
1570 else if (clock < PRCMU_NUM_REG_CLOCKS)
1571 return request_clock(clock, enable);
1572 else if (clock == PRCMU_TIMCLK)
1573 return request_timclk(enable);
1574 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1575 return request_dsiclk((clock - PRCMU_DSI0CLK), enable);
1576 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1577 return request_dsiescclk((clock - PRCMU_DSI0ESCCLK), enable);
1578 else if (clock == PRCMU_PLLDSI)
1579 return request_plldsi(enable);
1580 else if (clock == PRCMU_SYSCLK)
1581 return request_sysclk(enable);
1582 else if ((clock == PRCMU_PLLSOC0) || (clock == PRCMU_PLLSOC1))
1583 return request_pll(clock, enable);
1588 static unsigned long pll_rate(void __iomem *reg, unsigned long src_rate,
1599 rate *= ((val & PRCM_PLL_FREQ_D_MASK) >> PRCM_PLL_FREQ_D_SHIFT);
1601 d = ((val & PRCM_PLL_FREQ_N_MASK) >> PRCM_PLL_FREQ_N_SHIFT);
1605 d = ((val & PRCM_PLL_FREQ_R_MASK) >> PRCM_PLL_FREQ_R_SHIFT);
1609 if (val & PRCM_PLL_FREQ_SELDIV2)
1612 if ((branch == PLL_FIX) || ((branch == PLL_DIV) &&
1613 (val & PRCM_PLL_FREQ_DIV2EN) &&
1614 ((reg == PRCM_PLLSOC0_FREQ) ||
1615 (reg == PRCM_PLLDDR_FREQ))))
1618 (void)do_div(rate, div);
1620 return (unsigned long)rate;
1623 #define ROOT_CLOCK_RATE 38400000
1625 static unsigned long clock_rate(u8 clock)
1629 unsigned long rate = ROOT_CLOCK_RATE;
1631 val = readl(clk_mgt[clock].reg);
1633 if (val & PRCM_CLK_MGT_CLK38) {
1634 if (clk_mgt[clock].clk38div && (val & PRCM_CLK_MGT_CLK38DIV))
1639 val |= clk_mgt[clock].pllsw;
1640 pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
1642 if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC0)
1643 rate = pll_rate(PRCM_PLLSOC0_FREQ, rate, clk_mgt[clock].branch);
1644 else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC1)
1645 rate = pll_rate(PRCM_PLLSOC1_FREQ, rate, clk_mgt[clock].branch);
1646 else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_DDR)
1647 rate = pll_rate(PRCM_PLLDDR_FREQ, rate, clk_mgt[clock].branch);
1651 if ((clock == PRCMU_SGACLK) &&
1652 (val & PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN)) {
1653 u64 r = (rate * 10);
1655 (void)do_div(r, 25);
1656 return (unsigned long)r;
1658 val &= PRCM_CLK_MGT_CLKPLLDIV_MASK;
1665 static unsigned long dsiclk_rate(u8 n)
1670 divsel = readl(PRCM_DSI_PLLOUT_SEL);
1671 divsel = ((divsel & dsiclk[n].divsel_mask) >> dsiclk[n].divsel_shift);
1673 if (divsel == PRCM_DSI_PLLOUT_SEL_OFF)
1674 divsel = dsiclk[n].divsel;
1677 case PRCM_DSI_PLLOUT_SEL_PHI_4:
1679 case PRCM_DSI_PLLOUT_SEL_PHI_2:
1681 case PRCM_DSI_PLLOUT_SEL_PHI:
1682 return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
1689 static unsigned long dsiescclk_rate(u8 n)
1693 div = readl(PRCM_DSITVCLK_DIV);
1694 div = ((div & dsiescclk[n].div_mask) >> (dsiescclk[n].div_shift));
1695 return clock_rate(PRCMU_TVCLK) / max((u32)1, div);
1698 unsigned long prcmu_clock_rate(u8 clock)
1700 if (clock < PRCMU_NUM_REG_CLOCKS)
1701 return clock_rate(clock);
1702 else if (clock == PRCMU_TIMCLK)
1703 return ROOT_CLOCK_RATE / 16;
1704 else if (clock == PRCMU_SYSCLK)
1705 return ROOT_CLOCK_RATE;
1706 else if (clock == PRCMU_PLLSOC0)
1707 return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
1708 else if (clock == PRCMU_PLLSOC1)
1709 return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
1710 else if (clock == PRCMU_PLLDDR)
1711 return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
1712 else if (clock == PRCMU_PLLDSI)
1713 return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
1715 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1716 return dsiclk_rate(clock - PRCMU_DSI0CLK);
1717 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1718 return dsiescclk_rate(clock - PRCMU_DSI0ESCCLK);
1723 static unsigned long clock_source_rate(u32 clk_mgt_val, int branch)
1725 if (clk_mgt_val & PRCM_CLK_MGT_CLK38)
1726 return ROOT_CLOCK_RATE;
1727 clk_mgt_val &= PRCM_CLK_MGT_CLKPLLSW_MASK;
1728 if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC0)
1729 return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, branch);
1730 else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC1)
1731 return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, branch);
1732 else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_DDR)
1733 return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, branch);
1738 static u32 clock_divider(unsigned long src_rate, unsigned long rate)
1742 div = (src_rate / rate);
1745 if (rate < (src_rate / div))
1750 static long round_clock_rate(u8 clock, unsigned long rate)
1754 unsigned long src_rate;
1757 val = readl(clk_mgt[clock].reg);
1758 src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
1759 clk_mgt[clock].branch);
1760 div = clock_divider(src_rate, rate);
1761 if (val & PRCM_CLK_MGT_CLK38) {
1762 if (clk_mgt[clock].clk38div) {
1768 } else if ((clock == PRCMU_SGACLK) && (div == 3)) {
1769 u64 r = (src_rate * 10);
1771 (void)do_div(r, 25);
1773 return (unsigned long)r;
1775 rounded_rate = (src_rate / min(div, (u32)31));
1777 return rounded_rate;
1780 #define MIN_PLL_VCO_RATE 600000000ULL
1781 #define MAX_PLL_VCO_RATE 1680640000ULL
1783 static long round_plldsi_rate(unsigned long rate)
1785 long rounded_rate = 0;
1786 unsigned long src_rate;
1790 src_rate = clock_rate(PRCMU_HDMICLK);
1793 for (r = 7; (rem > 0) && (r > 0); r--) {
1797 (void)do_div(d, src_rate);
1803 if (((2 * d) < (r * MIN_PLL_VCO_RATE)) ||
1804 ((r * MAX_PLL_VCO_RATE) < (2 * d)))
1808 if (rounded_rate == 0)
1809 rounded_rate = (long)d;
1812 if ((rate - d) < rem) {
1814 rounded_rate = (long)d;
1817 return rounded_rate;
1820 static long round_dsiclk_rate(unsigned long rate)
1823 unsigned long src_rate;
1826 src_rate = pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
1828 div = clock_divider(src_rate, rate);
1829 rounded_rate = (src_rate / ((div > 2) ? 4 : div));
1831 return rounded_rate;
1834 static long round_dsiescclk_rate(unsigned long rate)
1837 unsigned long src_rate;
1840 src_rate = clock_rate(PRCMU_TVCLK);
1841 div = clock_divider(src_rate, rate);
1842 rounded_rate = (src_rate / min(div, (u32)255));
1844 return rounded_rate;
1847 long prcmu_round_clock_rate(u8 clock, unsigned long rate)
1849 if (clock < PRCMU_NUM_REG_CLOCKS)
1850 return round_clock_rate(clock, rate);
1851 else if (clock == PRCMU_PLLDSI)
1852 return round_plldsi_rate(rate);
1853 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1854 return round_dsiclk_rate(rate);
1855 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1856 return round_dsiescclk_rate(rate);
1858 return (long)prcmu_clock_rate(clock);
1861 static void set_clock_rate(u8 clock, unsigned long rate)
1865 unsigned long src_rate;
1866 unsigned long flags;
1868 spin_lock_irqsave(&clk_mgt_lock, flags);
1870 /* Grab the HW semaphore. */
1871 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1874 val = readl(clk_mgt[clock].reg);
1875 src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
1876 clk_mgt[clock].branch);
1877 div = clock_divider(src_rate, rate);
1878 if (val & PRCM_CLK_MGT_CLK38) {
1879 if (clk_mgt[clock].clk38div) {
1881 val |= PRCM_CLK_MGT_CLK38DIV;
1883 val &= ~PRCM_CLK_MGT_CLK38DIV;
1885 } else if (clock == PRCMU_SGACLK) {
1886 val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK |
1887 PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN);
1889 u64 r = (src_rate * 10);
1891 (void)do_div(r, 25);
1893 val |= PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN;
1897 val |= min(div, (u32)31);
1899 val &= ~PRCM_CLK_MGT_CLKPLLDIV_MASK;
1900 val |= min(div, (u32)31);
1902 writel(val, clk_mgt[clock].reg);
1904 /* Release the HW semaphore. */
1905 writel(0, PRCM_SEM);
1907 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1910 static int set_plldsi_rate(unsigned long rate)
1912 unsigned long src_rate;
1917 src_rate = clock_rate(PRCMU_HDMICLK);
1920 for (r = 7; (rem > 0) && (r > 0); r--) {
1925 (void)do_div(d, src_rate);
1930 hwrate = (d * src_rate);
1931 if (((2 * hwrate) < (r * MIN_PLL_VCO_RATE)) ||
1932 ((r * MAX_PLL_VCO_RATE) < (2 * hwrate)))
1934 (void)do_div(hwrate, r);
1935 if (rate < hwrate) {
1937 pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) |
1938 (r << PRCM_PLL_FREQ_R_SHIFT));
1941 if ((rate - hwrate) < rem) {
1942 rem = (rate - hwrate);
1943 pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) |
1944 (r << PRCM_PLL_FREQ_R_SHIFT));
1950 pll_freq |= (1 << PRCM_PLL_FREQ_N_SHIFT);
1951 writel(pll_freq, PRCM_PLLDSI_FREQ);
1956 static void set_dsiclk_rate(u8 n, unsigned long rate)
1961 div = clock_divider(pll_rate(PRCM_PLLDSI_FREQ,
1962 clock_rate(PRCMU_HDMICLK), PLL_RAW), rate);
1964 dsiclk[n].divsel = (div == 1) ? PRCM_DSI_PLLOUT_SEL_PHI :
1965 (div == 2) ? PRCM_DSI_PLLOUT_SEL_PHI_2 :
1966 /* else */ PRCM_DSI_PLLOUT_SEL_PHI_4;
1968 val = readl(PRCM_DSI_PLLOUT_SEL);
1969 val &= ~dsiclk[n].divsel_mask;
1970 val |= (dsiclk[n].divsel << dsiclk[n].divsel_shift);
1971 writel(val, PRCM_DSI_PLLOUT_SEL);
1974 static void set_dsiescclk_rate(u8 n, unsigned long rate)
1979 div = clock_divider(clock_rate(PRCMU_TVCLK), rate);
1980 val = readl(PRCM_DSITVCLK_DIV);
1981 val &= ~dsiescclk[n].div_mask;
1982 val |= (min(div, (u32)255) << dsiescclk[n].div_shift);
1983 writel(val, PRCM_DSITVCLK_DIV);
1986 int prcmu_set_clock_rate(u8 clock, unsigned long rate)
1988 if (clock < PRCMU_NUM_REG_CLOCKS)
1989 set_clock_rate(clock, rate);
1990 else if (clock == PRCMU_PLLDSI)
1991 return set_plldsi_rate(rate);
1992 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1993 set_dsiclk_rate((clock - PRCMU_DSI0CLK), rate);
1994 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1995 set_dsiescclk_rate((clock - PRCMU_DSI0ESCCLK), rate);
1999 int db8500_prcmu_config_esram0_deep_sleep(u8 state)
2001 if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
2002 (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
2005 mutex_lock(&mb4_transfer.lock);
2007 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
2010 writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2011 writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON),
2012 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE));
2013 writeb(DDR_PWR_STATE_ON,
2014 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
2015 writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
2017 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
2018 wait_for_completion(&mb4_transfer.work);
2020 mutex_unlock(&mb4_transfer.lock);
2025 int db8500_prcmu_config_hotdog(u8 threshold)
2027 mutex_lock(&mb4_transfer.lock);
2029 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
2032 writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
2033 writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2035 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
2036 wait_for_completion(&mb4_transfer.work);
2038 mutex_unlock(&mb4_transfer.lock);
2043 int db8500_prcmu_config_hotmon(u8 low, u8 high)
2045 mutex_lock(&mb4_transfer.lock);
2047 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
2050 writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
2051 writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH));
2052 writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH),
2053 (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
2054 writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2056 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
2057 wait_for_completion(&mb4_transfer.work);
2059 mutex_unlock(&mb4_transfer.lock);
2064 static int config_hot_period(u16 val)
2066 mutex_lock(&mb4_transfer.lock);
2068 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
2071 writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
2072 writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2074 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
2075 wait_for_completion(&mb4_transfer.work);
2077 mutex_unlock(&mb4_transfer.lock);
2082 int db8500_prcmu_start_temp_sense(u16 cycles32k)
2084 if (cycles32k == 0xFFFF)
2087 return config_hot_period(cycles32k);
2090 int db8500_prcmu_stop_temp_sense(void)
2092 return config_hot_period(0xFFFF);
2095 static int prcmu_a9wdog(u8 cmd, u8 d0, u8 d1, u8 d2, u8 d3)
2098 mutex_lock(&mb4_transfer.lock);
2100 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
2103 writeb(d0, (tcdm_base + PRCM_REQ_MB4_A9WDOG_0));
2104 writeb(d1, (tcdm_base + PRCM_REQ_MB4_A9WDOG_1));
2105 writeb(d2, (tcdm_base + PRCM_REQ_MB4_A9WDOG_2));
2106 writeb(d3, (tcdm_base + PRCM_REQ_MB4_A9WDOG_3));
2108 writeb(cmd, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2110 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
2111 wait_for_completion(&mb4_transfer.work);
2113 mutex_unlock(&mb4_transfer.lock);
2119 int db8500_prcmu_config_a9wdog(u8 num, bool sleep_auto_off)
2121 BUG_ON(num == 0 || num > 0xf);
2122 return prcmu_a9wdog(MB4H_A9WDOG_CONF, num, 0, 0,
2123 sleep_auto_off ? A9WDOG_AUTO_OFF_EN :
2124 A9WDOG_AUTO_OFF_DIS);
2127 int db8500_prcmu_enable_a9wdog(u8 id)
2129 return prcmu_a9wdog(MB4H_A9WDOG_EN, id, 0, 0, 0);
2132 int db8500_prcmu_disable_a9wdog(u8 id)
2134 return prcmu_a9wdog(MB4H_A9WDOG_DIS, id, 0, 0, 0);
2137 int db8500_prcmu_kick_a9wdog(u8 id)
2139 return prcmu_a9wdog(MB4H_A9WDOG_KICK, id, 0, 0, 0);
2143 * timeout is 28 bit, in ms.
2145 int db8500_prcmu_load_a9wdog(u8 id, u32 timeout)
2147 return prcmu_a9wdog(MB4H_A9WDOG_LOAD,
2148 (id & A9WDOG_ID_MASK) |
2150 * Put the lowest 28 bits of timeout at
2151 * offset 4. Four first bits are used for id.
2153 (u8)((timeout << 4) & 0xf0),
2154 (u8)((timeout >> 4) & 0xff),
2155 (u8)((timeout >> 12) & 0xff),
2156 (u8)((timeout >> 20) & 0xff));
2160 * prcmu_abb_read() - Read register value(s) from the ABB.
2161 * @slave: The I2C slave address.
2162 * @reg: The (start) register address.
2163 * @value: The read out value(s).
2164 * @size: The number of registers to read.
2166 * Reads register value(s) from the ABB.
2167 * @size has to be 1 for the current firmware version.
2169 int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
2176 mutex_lock(&mb5_transfer.lock);
2178 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
2181 writeb(0, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB5));
2182 writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
2183 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
2184 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
2185 writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
2187 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
2189 if (!wait_for_completion_timeout(&mb5_transfer.work,
2190 msecs_to_jiffies(20000))) {
2191 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
2195 r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO);
2199 *value = mb5_transfer.ack.value;
2201 mutex_unlock(&mb5_transfer.lock);
2207 * prcmu_abb_write_masked() - Write masked register value(s) to the ABB.
2208 * @slave: The I2C slave address.
2209 * @reg: The (start) register address.
2210 * @value: The value(s) to write.
2211 * @mask: The mask(s) to use.
2212 * @size: The number of registers to write.
2214 * Writes masked register value(s) to the ABB.
2215 * For each @value, only the bits set to 1 in the corresponding @mask
2216 * will be written. The other bits are not changed.
2217 * @size has to be 1 for the current firmware version.
2219 int prcmu_abb_write_masked(u8 slave, u8 reg, u8 *value, u8 *mask, u8 size)
2226 mutex_lock(&mb5_transfer.lock);
2228 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
2231 writeb(~*mask, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB5));
2232 writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
2233 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
2234 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
2235 writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
2237 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
2239 if (!wait_for_completion_timeout(&mb5_transfer.work,
2240 msecs_to_jiffies(20000))) {
2241 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
2245 r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
2248 mutex_unlock(&mb5_transfer.lock);
2254 * prcmu_abb_write() - Write register value(s) to the ABB.
2255 * @slave: The I2C slave address.
2256 * @reg: The (start) register address.
2257 * @value: The value(s) to write.
2258 * @size: The number of registers to write.
2260 * Writes register value(s) to the ABB.
2261 * @size has to be 1 for the current firmware version.
2263 int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
2267 return prcmu_abb_write_masked(slave, reg, value, &mask, size);
2271 * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem
2273 int prcmu_ac_wake_req(void)
2278 mutex_lock(&mb0_transfer.ac_wake_lock);
2280 val = readl(PRCM_HOSTACCESS_REQ);
2281 if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
2282 goto unlock_and_return;
2284 atomic_set(&ac_wake_req_state, 1);
2287 * Force Modem Wake-up before hostaccess_req ping-pong.
2288 * It prevents Modem to enter in Sleep while acking the hostaccess
2289 * request. The 31us delay has been calculated by HWI.
2291 val |= PRCM_HOSTACCESS_REQ_WAKE_REQ;
2292 writel(val, PRCM_HOSTACCESS_REQ);
2296 val |= PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ;
2297 writel(val, PRCM_HOSTACCESS_REQ);
2299 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
2300 msecs_to_jiffies(5000))) {
2301 #if defined(CONFIG_DBX500_PRCMU_DEBUG)
2302 db8500_prcmu_debug_dump(__func__, true, true);
2304 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
2310 mutex_unlock(&mb0_transfer.ac_wake_lock);
2315 * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem
2317 void prcmu_ac_sleep_req()
2321 mutex_lock(&mb0_transfer.ac_wake_lock);
2323 val = readl(PRCM_HOSTACCESS_REQ);
2324 if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
2325 goto unlock_and_return;
2327 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
2328 PRCM_HOSTACCESS_REQ);
2330 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
2331 msecs_to_jiffies(5000))) {
2332 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
2336 atomic_set(&ac_wake_req_state, 0);
2339 mutex_unlock(&mb0_transfer.ac_wake_lock);
2342 bool db8500_prcmu_is_ac_wake_requested(void)
2344 return (atomic_read(&ac_wake_req_state) != 0);
2348 * db8500_prcmu_system_reset - System reset
2350 * Saves the reset reason code and then sets the APE_SOFTRST register which
2351 * fires interrupt to fw
2353 void db8500_prcmu_system_reset(u16 reset_code)
2355 writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
2356 writel(1, PRCM_APE_SOFTRST);
2360 * db8500_prcmu_get_reset_code - Retrieve SW reset reason code
2362 * Retrieves the reset reason code stored by prcmu_system_reset() before
2365 u16 db8500_prcmu_get_reset_code(void)
2367 return readw(tcdm_base + PRCM_SW_RST_REASON);
2371 * db8500_prcmu_reset_modem - ask the PRCMU to reset modem
2373 void db8500_prcmu_modem_reset(void)
2375 mutex_lock(&mb1_transfer.lock);
2377 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
2380 writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
2381 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
2382 wait_for_completion(&mb1_transfer.work);
2385 * No need to check return from PRCMU as modem should go in reset state
2386 * This state is already managed by upper layer
2389 mutex_unlock(&mb1_transfer.lock);
2392 static void ack_dbb_wakeup(void)
2394 unsigned long flags;
2396 spin_lock_irqsave(&mb0_transfer.lock, flags);
2398 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
2401 writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
2402 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
2404 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
2407 static inline void print_unknown_header_warning(u8 n, u8 header)
2409 pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n",
2413 static bool read_mailbox_0(void)
2420 header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0);
2422 case MB0H_WAKEUP_EXE:
2423 case MB0H_WAKEUP_SLEEP:
2424 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
2425 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500);
2427 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500);
2429 if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK))
2430 complete(&mb0_transfer.ac_wake_work);
2431 if (ev & WAKEUP_BIT_SYSCLK_OK)
2432 complete(&mb3_transfer.sysclk_work);
2434 ev &= mb0_transfer.req.dbb_irqs;
2436 for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
2437 if (ev & prcmu_irq_bit[n])
2438 generic_handle_irq(IRQ_PRCMU_BASE + n);
2443 print_unknown_header_warning(0, header);
2447 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR);
2451 static bool read_mailbox_1(void)
2453 mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1);
2454 mb1_transfer.ack.arm_opp = readb(tcdm_base +
2455 PRCM_ACK_MB1_CURRENT_ARM_OPP);
2456 mb1_transfer.ack.ape_opp = readb(tcdm_base +
2457 PRCM_ACK_MB1_CURRENT_APE_OPP);
2458 mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
2459 PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
2460 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR);
2461 complete(&mb1_transfer.work);
2465 static bool read_mailbox_2(void)
2467 mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
2468 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR);
2469 complete(&mb2_transfer.work);
2473 static bool read_mailbox_3(void)
2475 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR);
2479 static bool read_mailbox_4(void)
2482 bool do_complete = true;
2484 header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4);
2489 case MB4H_HOT_PERIOD:
2490 case MB4H_A9WDOG_CONF:
2491 case MB4H_A9WDOG_EN:
2492 case MB4H_A9WDOG_DIS:
2493 case MB4H_A9WDOG_LOAD:
2494 case MB4H_A9WDOG_KICK:
2497 print_unknown_header_warning(4, header);
2498 do_complete = false;
2502 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR);
2505 complete(&mb4_transfer.work);
2510 static bool read_mailbox_5(void)
2512 mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
2513 mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
2514 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR);
2515 complete(&mb5_transfer.work);
2519 static bool read_mailbox_6(void)
2521 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR);
2525 static bool read_mailbox_7(void)
2527 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR);
2531 static bool (* const read_mailbox[NUM_MB])(void) = {
2542 static irqreturn_t prcmu_irq_handler(int irq, void *data)
2548 bits = (readl(PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
2549 if (unlikely(!bits))
2553 for (n = 0; bits; n++) {
2554 if (bits & MBOX_BIT(n)) {
2555 bits -= MBOX_BIT(n);
2556 if (read_mailbox[n]())
2557 r = IRQ_WAKE_THREAD;
2563 static irqreturn_t prcmu_irq_thread_fn(int irq, void *data)
2569 static void prcmu_mask_work(struct work_struct *work)
2571 unsigned long flags;
2573 spin_lock_irqsave(&mb0_transfer.lock, flags);
2577 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
2580 static void prcmu_irq_mask(struct irq_data *d)
2582 unsigned long flags;
2584 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
2586 mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
2588 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2590 if (d->irq != IRQ_PRCMU_CA_SLEEP)
2591 schedule_work(&mb0_transfer.mask_work);
2594 static void prcmu_irq_unmask(struct irq_data *d)
2596 unsigned long flags;
2598 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
2600 mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
2602 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2604 if (d->irq != IRQ_PRCMU_CA_SLEEP)
2605 schedule_work(&mb0_transfer.mask_work);
2608 static void noop(struct irq_data *d)
2612 static struct irq_chip prcmu_irq_chip = {
2614 .irq_disable = prcmu_irq_mask,
2616 .irq_mask = prcmu_irq_mask,
2617 .irq_unmask = prcmu_irq_unmask,
2620 static char *fw_project_name(u8 project)
2623 case PRCMU_FW_PROJECT_U8500:
2625 case PRCMU_FW_PROJECT_U8500_C2:
2627 case PRCMU_FW_PROJECT_U9500:
2629 case PRCMU_FW_PROJECT_U9500_C2:
2631 case PRCMU_FW_PROJECT_U8520:
2633 case PRCMU_FW_PROJECT_U8420:
2640 void __init db8500_prcmu_early_init(void)
2643 if (cpu_is_u8500v2()) {
2644 void *tcpm_base = ioremap_nocache(U8500_PRCMU_TCPM_BASE, SZ_4K);
2646 if (tcpm_base != NULL) {
2648 version = readl(tcpm_base + PRCMU_FW_VERSION_OFFSET);
2649 fw_info.version.project = version & 0xFF;
2650 fw_info.version.api_version = (version >> 8) & 0xFF;
2651 fw_info.version.func_version = (version >> 16) & 0xFF;
2652 fw_info.version.errata = (version >> 24) & 0xFF;
2653 fw_info.valid = true;
2654 pr_info("PRCMU firmware: %s, version %d.%d.%d\n",
2655 fw_project_name(fw_info.version.project),
2656 (version >> 8) & 0xFF, (version >> 16) & 0xFF,
2657 (version >> 24) & 0xFF);
2661 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE);
2663 pr_err("prcmu: Unsupported chip version\n");
2667 spin_lock_init(&mb0_transfer.lock);
2668 spin_lock_init(&mb0_transfer.dbb_irqs_lock);
2669 mutex_init(&mb0_transfer.ac_wake_lock);
2670 init_completion(&mb0_transfer.ac_wake_work);
2671 mutex_init(&mb1_transfer.lock);
2672 init_completion(&mb1_transfer.work);
2673 mb1_transfer.ape_opp = APE_NO_CHANGE;
2674 mutex_init(&mb2_transfer.lock);
2675 init_completion(&mb2_transfer.work);
2676 spin_lock_init(&mb2_transfer.auto_pm_lock);
2677 spin_lock_init(&mb3_transfer.lock);
2678 mutex_init(&mb3_transfer.sysclk_lock);
2679 init_completion(&mb3_transfer.sysclk_work);
2680 mutex_init(&mb4_transfer.lock);
2681 init_completion(&mb4_transfer.work);
2682 mutex_init(&mb5_transfer.lock);
2683 init_completion(&mb5_transfer.work);
2685 INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
2687 /* Initalize irqs. */
2688 for (i = 0; i < NUM_PRCMU_WAKEUPS; i++) {
2691 irq = IRQ_PRCMU_BASE + i;
2692 irq_set_chip_and_handler(irq, &prcmu_irq_chip,
2694 set_irq_flags(irq, IRQF_VALID);
2698 static void __init init_prcm_registers(void)
2702 val = readl(PRCM_A9PL_FORCE_CLKEN);
2703 val &= ~(PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN |
2704 PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN);
2705 writel(val, (PRCM_A9PL_FORCE_CLKEN));
2709 * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC
2711 static struct regulator_consumer_supply db8500_vape_consumers[] = {
2712 REGULATOR_SUPPLY("v-ape", NULL),
2713 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.0"),
2714 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.1"),
2715 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.2"),
2716 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.3"),
2717 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.4"),
2718 /* "v-mmc" changed to "vcore" in the mainline kernel */
2719 REGULATOR_SUPPLY("vcore", "sdi0"),
2720 REGULATOR_SUPPLY("vcore", "sdi1"),
2721 REGULATOR_SUPPLY("vcore", "sdi2"),
2722 REGULATOR_SUPPLY("vcore", "sdi3"),
2723 REGULATOR_SUPPLY("vcore", "sdi4"),
2724 REGULATOR_SUPPLY("v-dma", "dma40.0"),
2725 REGULATOR_SUPPLY("v-ape", "ab8500-usb.0"),
2726 /* "v-uart" changed to "vcore" in the mainline kernel */
2727 REGULATOR_SUPPLY("vcore", "uart0"),
2728 REGULATOR_SUPPLY("vcore", "uart1"),
2729 REGULATOR_SUPPLY("vcore", "uart2"),
2730 REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"),
2731 REGULATOR_SUPPLY("v-hsi", "ste_hsi.0"),
2732 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
2735 static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
2736 REGULATOR_SUPPLY("musb_1v8", "ab8500-usb.0"),
2737 /* AV8100 regulator */
2738 REGULATOR_SUPPLY("hdmi_1v8", "0-0070"),
2741 static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = {
2742 REGULATOR_SUPPLY("vsupply", "b2r2_bus"),
2743 REGULATOR_SUPPLY("vsupply", "mcde"),
2746 /* SVA MMDSP regulator switch */
2747 static struct regulator_consumer_supply db8500_svammdsp_consumers[] = {
2748 REGULATOR_SUPPLY("sva-mmdsp", "cm_control"),
2751 /* SVA pipe regulator switch */
2752 static struct regulator_consumer_supply db8500_svapipe_consumers[] = {
2753 REGULATOR_SUPPLY("sva-pipe", "cm_control"),
2756 /* SIA MMDSP regulator switch */
2757 static struct regulator_consumer_supply db8500_siammdsp_consumers[] = {
2758 REGULATOR_SUPPLY("sia-mmdsp", "cm_control"),
2761 /* SIA pipe regulator switch */
2762 static struct regulator_consumer_supply db8500_siapipe_consumers[] = {
2763 REGULATOR_SUPPLY("sia-pipe", "cm_control"),
2766 static struct regulator_consumer_supply db8500_sga_consumers[] = {
2767 REGULATOR_SUPPLY("v-mali", NULL),
2770 /* ESRAM1 and 2 regulator switch */
2771 static struct regulator_consumer_supply db8500_esram12_consumers[] = {
2772 REGULATOR_SUPPLY("esram12", "cm_control"),
2775 /* ESRAM3 and 4 regulator switch */
2776 static struct regulator_consumer_supply db8500_esram34_consumers[] = {
2777 REGULATOR_SUPPLY("v-esram34", "mcde"),
2778 REGULATOR_SUPPLY("esram34", "cm_control"),
2779 REGULATOR_SUPPLY("lcla_esram", "dma40.0"),
2782 static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
2783 [DB8500_REGULATOR_VAPE] = {
2785 .name = "db8500-vape",
2786 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2789 .consumer_supplies = db8500_vape_consumers,
2790 .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers),
2792 [DB8500_REGULATOR_VARM] = {
2794 .name = "db8500-varm",
2795 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2798 [DB8500_REGULATOR_VMODEM] = {
2800 .name = "db8500-vmodem",
2801 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2804 [DB8500_REGULATOR_VPLL] = {
2806 .name = "db8500-vpll",
2807 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2810 [DB8500_REGULATOR_VSMPS1] = {
2812 .name = "db8500-vsmps1",
2813 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2816 [DB8500_REGULATOR_VSMPS2] = {
2818 .name = "db8500-vsmps2",
2819 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2821 .consumer_supplies = db8500_vsmps2_consumers,
2822 .num_consumer_supplies = ARRAY_SIZE(db8500_vsmps2_consumers),
2824 [DB8500_REGULATOR_VSMPS3] = {
2826 .name = "db8500-vsmps3",
2827 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2830 [DB8500_REGULATOR_VRF1] = {
2832 .name = "db8500-vrf1",
2833 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2836 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
2837 /* dependency to u8500-vape is handled outside regulator framework */
2839 .name = "db8500-sva-mmdsp",
2840 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2842 .consumer_supplies = db8500_svammdsp_consumers,
2843 .num_consumer_supplies = ARRAY_SIZE(db8500_svammdsp_consumers),
2845 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
2847 /* "ret" means "retention" */
2848 .name = "db8500-sva-mmdsp-ret",
2849 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2852 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
2853 /* dependency to u8500-vape is handled outside regulator framework */
2855 .name = "db8500-sva-pipe",
2856 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2858 .consumer_supplies = db8500_svapipe_consumers,
2859 .num_consumer_supplies = ARRAY_SIZE(db8500_svapipe_consumers),
2861 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
2862 /* dependency to u8500-vape is handled outside regulator framework */
2864 .name = "db8500-sia-mmdsp",
2865 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2867 .consumer_supplies = db8500_siammdsp_consumers,
2868 .num_consumer_supplies = ARRAY_SIZE(db8500_siammdsp_consumers),
2870 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
2872 .name = "db8500-sia-mmdsp-ret",
2873 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2876 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
2877 /* dependency to u8500-vape is handled outside regulator framework */
2879 .name = "db8500-sia-pipe",
2880 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2882 .consumer_supplies = db8500_siapipe_consumers,
2883 .num_consumer_supplies = ARRAY_SIZE(db8500_siapipe_consumers),
2885 [DB8500_REGULATOR_SWITCH_SGA] = {
2886 .supply_regulator = "db8500-vape",
2888 .name = "db8500-sga",
2889 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2891 .consumer_supplies = db8500_sga_consumers,
2892 .num_consumer_supplies = ARRAY_SIZE(db8500_sga_consumers),
2895 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
2896 .supply_regulator = "db8500-vape",
2898 .name = "db8500-b2r2-mcde",
2899 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2901 .consumer_supplies = db8500_b2r2_mcde_consumers,
2902 .num_consumer_supplies = ARRAY_SIZE(db8500_b2r2_mcde_consumers),
2904 [DB8500_REGULATOR_SWITCH_ESRAM12] = {
2906 * esram12 is set in retention and supplied by Vsafe when Vape is off,
2907 * no need to hold Vape
2910 .name = "db8500-esram12",
2911 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2913 .consumer_supplies = db8500_esram12_consumers,
2914 .num_consumer_supplies = ARRAY_SIZE(db8500_esram12_consumers),
2916 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
2918 .name = "db8500-esram12-ret",
2919 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2922 [DB8500_REGULATOR_SWITCH_ESRAM34] = {
2924 * esram34 is set in retention and supplied by Vsafe when Vape is off,
2925 * no need to hold Vape
2928 .name = "db8500-esram34",
2929 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2931 .consumer_supplies = db8500_esram34_consumers,
2932 .num_consumer_supplies = ARRAY_SIZE(db8500_esram34_consumers),
2934 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
2936 .name = "db8500-esram34-ret",
2937 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2942 static struct resource ab8500_resources[] = {
2944 .start = IRQ_DB8500_AB8500,
2945 .end = IRQ_DB8500_AB8500,
2946 .flags = IORESOURCE_IRQ
2950 static struct mfd_cell db8500_prcmu_devs[] = {
2952 .name = "db8500-prcmu-regulators",
2953 .of_compatible = "stericsson,db8500-prcmu-regulator",
2954 .platform_data = &db8500_regulators,
2955 .pdata_size = sizeof(db8500_regulators),
2958 .name = "cpufreq-u8500",
2959 .of_compatible = "stericsson,cpufreq-u8500",
2962 .name = "ab8500-core",
2963 .of_compatible = "stericsson,ab8500",
2964 .num_resources = ARRAY_SIZE(ab8500_resources),
2965 .resources = ab8500_resources,
2966 .id = AB8500_VERSION_AB8500,
2971 * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic
2974 static int __devinit db8500_prcmu_probe(struct platform_device *pdev)
2976 struct ab8500_platform_data *ab8500_platdata = pdev->dev.platform_data;
2977 struct device_node *np = pdev->dev.of_node;
2978 int irq = 0, err = 0, i;
2983 init_prcm_registers();
2985 /* Clean up the mailbox interrupts after pre-kernel code. */
2986 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
2989 irq = platform_get_irq(pdev, 0);
2991 if (!np || irq <= 0)
2992 irq = IRQ_DB8500_PRCMU1;
2994 err = request_threaded_irq(irq, prcmu_irq_handler,
2995 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
2997 pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
3002 for (i = 0; i < ARRAY_SIZE(db8500_prcmu_devs); i++) {
3003 if (!strcmp(db8500_prcmu_devs[i].name, "ab8500-core")) {
3004 db8500_prcmu_devs[i].platform_data = ab8500_platdata;
3005 db8500_prcmu_devs[i].pdata_size = sizeof(struct ab8500_platform_data);
3009 if (cpu_is_u8500v20_or_later())
3010 prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
3012 err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
3013 ARRAY_SIZE(db8500_prcmu_devs), NULL, 0);
3015 pr_err("prcmu: Failed to add subdevices\n");
3019 pr_info("DB8500 PRCMU initialized\n");
3024 static const struct of_device_id db8500_prcmu_match[] = {
3025 { .compatible = "stericsson,db8500-prcmu"},
3029 static struct platform_driver db8500_prcmu_driver = {
3031 .name = "db8500-prcmu",
3032 .owner = THIS_MODULE,
3033 .of_match_table = db8500_prcmu_match,
3035 .probe = db8500_prcmu_probe,
3038 static int __init db8500_prcmu_init(void)
3040 return platform_driver_register(&db8500_prcmu_driver);
3043 core_initcall(db8500_prcmu_init);
3045 MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>");
3046 MODULE_DESCRIPTION("DB8500 PRCM Unit driver");
3047 MODULE_LICENSE("GPL v2");