blob: e42a417adc5ff60b9ded23bae32c5ee6965cac19 [file] [log] [blame]
Linus Walleije3726fc2010-08-19 12:36:01 +01001/*
Martin Perssone0befb22010-12-08 15:13:28 +01002 * Copyright (C) STMicroelectronics 2009
3 * Copyright (C) ST-Ericsson SA 2010
Linus Walleije3726fc2010-08-19 12:36:01 +01004 *
5 * License Terms: GNU General Public License v2
Martin Perssone0befb22010-12-08 15:13:28 +01006 * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
7 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
Linus Walleije3726fc2010-08-19 12:36:01 +01008 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
9 *
Martin Perssone0befb22010-12-08 15:13:28 +010010 * U8500 PRCM Unit interface driver
11 *
Linus Walleije3726fc2010-08-19 12:36:01 +010012 */
Linus Walleije3726fc2010-08-19 12:36:01 +010013#include <linux/module.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020014#include <linux/kernel.h>
15#include <linux/delay.h>
Linus Walleije3726fc2010-08-19 12:36:01 +010016#include <linux/errno.h>
17#include <linux/err.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020018#include <linux/spinlock.h>
Linus Walleije3726fc2010-08-19 12:36:01 +010019#include <linux/io.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020020#include <linux/slab.h>
Linus Walleije3726fc2010-08-19 12:36:01 +010021#include <linux/mutex.h>
22#include <linux/completion.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020023#include <linux/irq.h>
Linus Walleije3726fc2010-08-19 12:36:01 +010024#include <linux/jiffies.h>
25#include <linux/bitops.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020026#include <linux/fs.h>
27#include <linux/platform_device.h>
28#include <linux/uaccess.h>
29#include <linux/mfd/core.h>
Mattias Nilsson73180f82011-08-12 10:28:10 +020030#include <linux/mfd/dbx500-prcmu.h>
Lee Jones3a8e39c2012-07-06 12:46:23 +020031#include <linux/mfd/abx500/ab8500.h>
Bengt Jonsson1032fbf2011-04-01 14:43:33 +020032#include <linux/regulator/db8500-prcmu.h>
33#include <linux/regulator/machine.h>
Ulf Hanssonc280f452012-10-10 13:42:23 +020034#include <linux/cpufreq.h>
Fabio Baltierib3aac622013-01-18 12:40:14 +010035#include <linux/platform_data/ux500_wdt.h>
Daniel Lezcanocc9a0f62012-02-28 22:46:06 +010036#include <asm/hardware/gic.h>
Linus Walleije3726fc2010-08-19 12:36:01 +010037#include <mach/hardware.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020038#include <mach/irqs.h>
39#include <mach/db8500-regs.h>
40#include <mach/id.h>
Mattias Nilsson73180f82011-08-12 10:28:10 +020041#include "dbx500-prcmu-regs.h"
Linus Walleije3726fc2010-08-19 12:36:01 +010042
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020043/* Offset for the firmware version within the TCPM */
44#define PRCMU_FW_VERSION_OFFSET 0xA4
Linus Walleije3726fc2010-08-19 12:36:01 +010045
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020046/* Index of different voltages to be used when accessing AVSData */
47#define PRCM_AVS_BASE 0x2FC
48#define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
49#define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
50#define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
51#define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
52#define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
53#define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
54#define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
55#define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
56#define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
57#define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
58#define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
59#define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
60#define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
Martin Perssone0befb22010-12-08 15:13:28 +010061
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020062#define PRCM_AVS_VOLTAGE 0
63#define PRCM_AVS_VOLTAGE_MASK 0x3f
64#define PRCM_AVS_ISSLOWSTARTUP 6
65#define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
Martin Perssone0befb22010-12-08 15:13:28 +010066#define PRCM_AVS_ISMODEENABLE 7
67#define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
68
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020069#define PRCM_BOOT_STATUS 0xFFF
70#define PRCM_ROMCODE_A2P 0xFFE
71#define PRCM_ROMCODE_P2A 0xFFD
72#define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */
Linus Walleije3726fc2010-08-19 12:36:01 +010073
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020074#define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */
75
76#define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */
77#define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
78#define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
79#define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
80#define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
81#define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
82#define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
83#define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
84
85/* Req Mailboxes */
86#define PRCM_REQ_MB0 0xFDC /* 12 bytes */
87#define PRCM_REQ_MB1 0xFD0 /* 12 bytes */
88#define PRCM_REQ_MB2 0xFC0 /* 16 bytes */
89#define PRCM_REQ_MB3 0xE4C /* 372 bytes */
90#define PRCM_REQ_MB4 0xE48 /* 4 bytes */
91#define PRCM_REQ_MB5 0xE44 /* 4 bytes */
92
93/* Ack Mailboxes */
94#define PRCM_ACK_MB0 0xE08 /* 52 bytes */
95#define PRCM_ACK_MB1 0xE04 /* 4 bytes */
96#define PRCM_ACK_MB2 0xE00 /* 4 bytes */
97#define PRCM_ACK_MB3 0xDFC /* 4 bytes */
98#define PRCM_ACK_MB4 0xDF8 /* 4 bytes */
99#define PRCM_ACK_MB5 0xDF4 /* 4 bytes */
100
101/* Mailbox 0 headers */
102#define MB0H_POWER_STATE_TRANS 0
103#define MB0H_CONFIG_WAKEUPS_EXE 1
104#define MB0H_READ_WAKEUP_ACK 3
105#define MB0H_CONFIG_WAKEUPS_SLEEP 4
106
107#define MB0H_WAKEUP_EXE 2
108#define MB0H_WAKEUP_SLEEP 5
109
110/* Mailbox 0 REQs */
111#define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
112#define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
113#define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
114#define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
115#define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
116#define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
117
118/* Mailbox 0 ACKs */
119#define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
120#define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
121#define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
122#define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
123#define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
124#define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
125#define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
126
127/* Mailbox 1 headers */
128#define MB1H_ARM_APE_OPP 0x0
129#define MB1H_RESET_MODEM 0x2
130#define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
131#define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
132#define MB1H_RELEASE_USB_WAKEUP 0x5
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200133#define MB1H_PLL_ON_OFF 0x6
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200134
135/* Mailbox 1 Requests */
136#define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
137#define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200138#define PRCM_REQ_MB1_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4)
Mattias Nilsson6b6fae22012-01-13 16:20:28 +0100139#define PLL_SOC0_OFF 0x1
140#define PLL_SOC0_ON 0x2
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200141#define PLL_SOC1_OFF 0x4
142#define PLL_SOC1_ON 0x8
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200143
144/* Mailbox 1 ACKs */
145#define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0)
146#define PRCM_ACK_MB1_CURRENT_APE_OPP (PRCM_ACK_MB1 + 0x1)
147#define PRCM_ACK_MB1_APE_VOLTAGE_STATUS (PRCM_ACK_MB1 + 0x2)
148#define PRCM_ACK_MB1_DVFS_STATUS (PRCM_ACK_MB1 + 0x3)
149
150/* Mailbox 2 headers */
151#define MB2H_DPS 0x0
152#define MB2H_AUTO_PWR 0x1
153
154/* Mailbox 2 REQs */
155#define PRCM_REQ_MB2_SVA_MMDSP (PRCM_REQ_MB2 + 0x0)
156#define PRCM_REQ_MB2_SVA_PIPE (PRCM_REQ_MB2 + 0x1)
157#define PRCM_REQ_MB2_SIA_MMDSP (PRCM_REQ_MB2 + 0x2)
158#define PRCM_REQ_MB2_SIA_PIPE (PRCM_REQ_MB2 + 0x3)
159#define PRCM_REQ_MB2_SGA (PRCM_REQ_MB2 + 0x4)
160#define PRCM_REQ_MB2_B2R2_MCDE (PRCM_REQ_MB2 + 0x5)
161#define PRCM_REQ_MB2_ESRAM12 (PRCM_REQ_MB2 + 0x6)
162#define PRCM_REQ_MB2_ESRAM34 (PRCM_REQ_MB2 + 0x7)
163#define PRCM_REQ_MB2_AUTO_PM_SLEEP (PRCM_REQ_MB2 + 0x8)
164#define PRCM_REQ_MB2_AUTO_PM_IDLE (PRCM_REQ_MB2 + 0xC)
165
166/* Mailbox 2 ACKs */
167#define PRCM_ACK_MB2_DPS_STATUS (PRCM_ACK_MB2 + 0x0)
168#define HWACC_PWR_ST_OK 0xFE
169
170/* Mailbox 3 headers */
171#define MB3H_ANC 0x0
172#define MB3H_SIDETONE 0x1
173#define MB3H_SYSCLK 0xE
174
175/* Mailbox 3 Requests */
176#define PRCM_REQ_MB3_ANC_FIR_COEFF (PRCM_REQ_MB3 + 0x0)
177#define PRCM_REQ_MB3_ANC_IIR_COEFF (PRCM_REQ_MB3 + 0x20)
178#define PRCM_REQ_MB3_ANC_SHIFTER (PRCM_REQ_MB3 + 0x60)
179#define PRCM_REQ_MB3_ANC_WARP (PRCM_REQ_MB3 + 0x64)
180#define PRCM_REQ_MB3_SIDETONE_FIR_GAIN (PRCM_REQ_MB3 + 0x68)
181#define PRCM_REQ_MB3_SIDETONE_FIR_COEFF (PRCM_REQ_MB3 + 0x6C)
182#define PRCM_REQ_MB3_SYSCLK_MGT (PRCM_REQ_MB3 + 0x16C)
183
184/* Mailbox 4 headers */
185#define MB4H_DDR_INIT 0x0
186#define MB4H_MEM_ST 0x1
187#define MB4H_HOTDOG 0x12
188#define MB4H_HOTMON 0x13
189#define MB4H_HOT_PERIOD 0x14
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200190#define MB4H_A9WDOG_CONF 0x16
191#define MB4H_A9WDOG_EN 0x17
192#define MB4H_A9WDOG_DIS 0x18
193#define MB4H_A9WDOG_LOAD 0x19
194#define MB4H_A9WDOG_KICK 0x20
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200195
196/* Mailbox 4 Requests */
197#define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
198#define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
199#define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
200#define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
201#define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
202#define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
203#define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
204#define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
205#define HOTMON_CONFIG_LOW BIT(0)
206#define HOTMON_CONFIG_HIGH BIT(1)
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200207#define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0)
208#define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1)
209#define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2)
210#define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3)
211#define A9WDOG_AUTO_OFF_EN BIT(7)
212#define A9WDOG_AUTO_OFF_DIS 0
213#define A9WDOG_ID_MASK 0xf
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200214
215/* Mailbox 5 Requests */
216#define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
217#define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
218#define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
219#define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
220#define PRCMU_I2C_WRITE(slave) \
221 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0))
222#define PRCMU_I2C_READ(slave) \
223 (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0))
224#define PRCMU_I2C_STOP_EN BIT(3)
225
226/* Mailbox 5 ACKs */
227#define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
228#define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
229#define I2C_WR_OK 0x1
230#define I2C_RD_OK 0x2
231
232#define NUM_MB 8
233#define MBOX_BIT BIT
234#define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
235
236/*
237 * Wakeups/IRQs
238 */
239
240#define WAKEUP_BIT_RTC BIT(0)
241#define WAKEUP_BIT_RTT0 BIT(1)
242#define WAKEUP_BIT_RTT1 BIT(2)
243#define WAKEUP_BIT_HSI0 BIT(3)
244#define WAKEUP_BIT_HSI1 BIT(4)
245#define WAKEUP_BIT_CA_WAKE BIT(5)
246#define WAKEUP_BIT_USB BIT(6)
247#define WAKEUP_BIT_ABB BIT(7)
248#define WAKEUP_BIT_ABB_FIFO BIT(8)
249#define WAKEUP_BIT_SYSCLK_OK BIT(9)
250#define WAKEUP_BIT_CA_SLEEP BIT(10)
251#define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
252#define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
253#define WAKEUP_BIT_ANC_OK BIT(13)
254#define WAKEUP_BIT_SW_ERROR BIT(14)
255#define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
256#define WAKEUP_BIT_ARM BIT(17)
257#define WAKEUP_BIT_HOTMON_LOW BIT(18)
258#define WAKEUP_BIT_HOTMON_HIGH BIT(19)
259#define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
260#define WAKEUP_BIT_GPIO0 BIT(23)
261#define WAKEUP_BIT_GPIO1 BIT(24)
262#define WAKEUP_BIT_GPIO2 BIT(25)
263#define WAKEUP_BIT_GPIO3 BIT(26)
264#define WAKEUP_BIT_GPIO4 BIT(27)
265#define WAKEUP_BIT_GPIO5 BIT(28)
266#define WAKEUP_BIT_GPIO6 BIT(29)
267#define WAKEUP_BIT_GPIO7 BIT(30)
268#define WAKEUP_BIT_GPIO8 BIT(31)
269
Mattias Nilssonb58d12f2012-01-13 16:20:10 +0100270static struct {
271 bool valid;
272 struct prcmu_fw_version version;
273} fw_info;
274
Lee Jonesf3f1f0a2012-09-24 09:11:46 +0100275static struct irq_domain *db8500_irq_domain;
276
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200277/*
278 * This vector maps irq numbers to the bits in the bit field used in
279 * communication with the PRCMU firmware.
280 *
281 * The reason for having this is to keep the irq numbers contiguous even though
282 * the bits in the bit field are not. (The bits also have a tendency to move
283 * around, to further complicate matters.)
284 */
285#define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE)
286#define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
287static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
288 IRQ_ENTRY(RTC),
289 IRQ_ENTRY(RTT0),
290 IRQ_ENTRY(RTT1),
291 IRQ_ENTRY(HSI0),
292 IRQ_ENTRY(HSI1),
293 IRQ_ENTRY(CA_WAKE),
294 IRQ_ENTRY(USB),
295 IRQ_ENTRY(ABB),
296 IRQ_ENTRY(ABB_FIFO),
297 IRQ_ENTRY(CA_SLEEP),
298 IRQ_ENTRY(ARM),
299 IRQ_ENTRY(HOTMON_LOW),
300 IRQ_ENTRY(HOTMON_HIGH),
301 IRQ_ENTRY(MODEM_SW_RESET_REQ),
302 IRQ_ENTRY(GPIO0),
303 IRQ_ENTRY(GPIO1),
304 IRQ_ENTRY(GPIO2),
305 IRQ_ENTRY(GPIO3),
306 IRQ_ENTRY(GPIO4),
307 IRQ_ENTRY(GPIO5),
308 IRQ_ENTRY(GPIO6),
309 IRQ_ENTRY(GPIO7),
310 IRQ_ENTRY(GPIO8)
Martin Perssone0befb22010-12-08 15:13:28 +0100311};
312
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200313#define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
314#define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
315static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = {
316 WAKEUP_ENTRY(RTC),
317 WAKEUP_ENTRY(RTT0),
318 WAKEUP_ENTRY(RTT1),
319 WAKEUP_ENTRY(HSI0),
320 WAKEUP_ENTRY(HSI1),
321 WAKEUP_ENTRY(USB),
322 WAKEUP_ENTRY(ABB),
323 WAKEUP_ENTRY(ABB_FIFO),
324 WAKEUP_ENTRY(ARM)
325};
326
327/*
328 * mb0_transfer - state needed for mailbox 0 communication.
329 * @lock: The transaction lock.
330 * @dbb_events_lock: A lock used to handle concurrent access to (parts of)
331 * the request data.
332 * @mask_work: Work structure used for (un)masking wakeup interrupts.
333 * @req: Request data that need to persist between requests.
334 */
335static struct {
336 spinlock_t lock;
337 spinlock_t dbb_irqs_lock;
338 struct work_struct mask_work;
339 struct mutex ac_wake_lock;
340 struct completion ac_wake_work;
341 struct {
342 u32 dbb_irqs;
343 u32 dbb_wakeups;
344 u32 abb_events;
345 } req;
346} mb0_transfer;
347
348/*
349 * mb1_transfer - state needed for mailbox 1 communication.
350 * @lock: The transaction lock.
351 * @work: The transaction completion structure.
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +0100352 * @ape_opp: The current APE OPP.
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200353 * @ack: Reply ("acknowledge") data.
354 */
Martin Perssone0befb22010-12-08 15:13:28 +0100355static struct {
356 struct mutex lock;
357 struct completion work;
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +0100358 u8 ape_opp;
Martin Perssone0befb22010-12-08 15:13:28 +0100359 struct {
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200360 u8 header;
Martin Perssone0befb22010-12-08 15:13:28 +0100361 u8 arm_opp;
362 u8 ape_opp;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200363 u8 ape_voltage_status;
Martin Perssone0befb22010-12-08 15:13:28 +0100364 } ack;
365} mb1_transfer;
366
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200367/*
368 * mb2_transfer - state needed for mailbox 2 communication.
369 * @lock: The transaction lock.
370 * @work: The transaction completion structure.
371 * @auto_pm_lock: The autonomous power management configuration lock.
372 * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled.
373 * @req: Request data that need to persist between requests.
374 * @ack: Reply ("acknowledge") data.
375 */
Linus Walleije3726fc2010-08-19 12:36:01 +0100376static struct {
377 struct mutex lock;
378 struct completion work;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200379 spinlock_t auto_pm_lock;
380 bool auto_pm_enabled;
381 struct {
382 u8 status;
383 } ack;
384} mb2_transfer;
385
386/*
387 * mb3_transfer - state needed for mailbox 3 communication.
388 * @lock: The request lock.
389 * @sysclk_lock: A lock used to handle concurrent sysclk requests.
390 * @sysclk_work: Work structure used for sysclk requests.
391 */
392static struct {
393 spinlock_t lock;
394 struct mutex sysclk_lock;
395 struct completion sysclk_work;
396} mb3_transfer;
397
398/*
399 * mb4_transfer - state needed for mailbox 4 communication.
400 * @lock: The transaction lock.
401 * @work: The transaction completion structure.
402 */
403static struct {
404 struct mutex lock;
405 struct completion work;
406} mb4_transfer;
407
408/*
409 * mb5_transfer - state needed for mailbox 5 communication.
410 * @lock: The transaction lock.
411 * @work: The transaction completion structure.
412 * @ack: Reply ("acknowledge") data.
413 */
414static struct {
415 struct mutex lock;
416 struct completion work;
Linus Walleije3726fc2010-08-19 12:36:01 +0100417 struct {
418 u8 status;
419 u8 value;
420 } ack;
421} mb5_transfer;
422
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200423static atomic_t ac_wake_req_state = ATOMIC_INIT(0);
424
425/* Spinlocks */
Mattias Nilssonb4a6dbd2012-01-13 16:21:00 +0100426static DEFINE_SPINLOCK(prcmu_lock);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200427static DEFINE_SPINLOCK(clkout_lock);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200428
429/* Global var to runtime determine TCDM base for v2 or v1 */
430static __iomem void *tcdm_base;
431
432struct clk_mgt {
Mattias Nilsson6b6fae22012-01-13 16:20:28 +0100433 void __iomem *reg;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200434 u32 pllsw;
Mattias Nilsson6b6fae22012-01-13 16:20:28 +0100435 int branch;
436 bool clk38div;
437};
438
439enum {
440 PLL_RAW,
441 PLL_FIX,
442 PLL_DIV
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200443};
444
445static DEFINE_SPINLOCK(clk_mgt_lock);
446
Mattias Nilsson6b6fae22012-01-13 16:20:28 +0100447#define CLK_MGT_ENTRY(_name, _branch, _clk38div)[PRCMU_##_name] = \
448 { (PRCM_##_name##_MGT), 0 , _branch, _clk38div}
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200449struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
Mattias Nilsson6b6fae22012-01-13 16:20:28 +0100450 CLK_MGT_ENTRY(SGACLK, PLL_DIV, false),
451 CLK_MGT_ENTRY(UARTCLK, PLL_FIX, true),
452 CLK_MGT_ENTRY(MSP02CLK, PLL_FIX, true),
453 CLK_MGT_ENTRY(MSP1CLK, PLL_FIX, true),
454 CLK_MGT_ENTRY(I2CCLK, PLL_FIX, true),
455 CLK_MGT_ENTRY(SDMMCCLK, PLL_DIV, true),
456 CLK_MGT_ENTRY(SLIMCLK, PLL_FIX, true),
457 CLK_MGT_ENTRY(PER1CLK, PLL_DIV, true),
458 CLK_MGT_ENTRY(PER2CLK, PLL_DIV, true),
459 CLK_MGT_ENTRY(PER3CLK, PLL_DIV, true),
460 CLK_MGT_ENTRY(PER5CLK, PLL_DIV, true),
461 CLK_MGT_ENTRY(PER6CLK, PLL_DIV, true),
462 CLK_MGT_ENTRY(PER7CLK, PLL_DIV, true),
463 CLK_MGT_ENTRY(LCDCLK, PLL_FIX, true),
464 CLK_MGT_ENTRY(BMLCLK, PLL_DIV, true),
465 CLK_MGT_ENTRY(HSITXCLK, PLL_DIV, true),
466 CLK_MGT_ENTRY(HSIRXCLK, PLL_DIV, true),
467 CLK_MGT_ENTRY(HDMICLK, PLL_FIX, false),
468 CLK_MGT_ENTRY(APEATCLK, PLL_DIV, true),
469 CLK_MGT_ENTRY(APETRACECLK, PLL_DIV, true),
470 CLK_MGT_ENTRY(MCDECLK, PLL_DIV, true),
471 CLK_MGT_ENTRY(IPI2CCLK, PLL_FIX, true),
472 CLK_MGT_ENTRY(DSIALTCLK, PLL_FIX, false),
473 CLK_MGT_ENTRY(DMACLK, PLL_DIV, true),
474 CLK_MGT_ENTRY(B2R2CLK, PLL_DIV, true),
475 CLK_MGT_ENTRY(TVCLK, PLL_FIX, true),
476 CLK_MGT_ENTRY(SSPCLK, PLL_FIX, true),
477 CLK_MGT_ENTRY(RNGCLK, PLL_FIX, true),
478 CLK_MGT_ENTRY(UICCCLK, PLL_FIX, false),
479};
480
481struct dsiclk {
482 u32 divsel_mask;
483 u32 divsel_shift;
484 u32 divsel;
485};
486
487static struct dsiclk dsiclk[2] = {
488 {
489 .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_MASK,
490 .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_SHIFT,
491 .divsel = PRCM_DSI_PLLOUT_SEL_PHI,
492 },
493 {
494 .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_MASK,
495 .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_SHIFT,
496 .divsel = PRCM_DSI_PLLOUT_SEL_PHI,
497 }
498};
499
500struct dsiescclk {
501 u32 en;
502 u32 div_mask;
503 u32 div_shift;
504};
505
506static struct dsiescclk dsiescclk[3] = {
507 {
508 .en = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_EN,
509 .div_mask = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_MASK,
510 .div_shift = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_SHIFT,
511 },
512 {
513 .en = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_EN,
514 .div_mask = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_MASK,
515 .div_shift = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_SHIFT,
516 },
517 {
518 .en = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_EN,
519 .div_mask = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_MASK,
520 .div_shift = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_SHIFT,
521 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200522};
523
Michel Jaouen20aee5b2012-08-31 14:21:30 +0200524
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200525/*
526* Used by MCDE to setup all necessary PRCMU registers
527*/
528#define PRCMU_RESET_DSIPLL 0x00004000
529#define PRCMU_UNCLAMP_DSIPLL 0x00400800
530
531#define PRCMU_CLK_PLL_DIV_SHIFT 0
532#define PRCMU_CLK_PLL_SW_SHIFT 5
533#define PRCMU_CLK_38 (1 << 9)
534#define PRCMU_CLK_38_SRC (1 << 10)
535#define PRCMU_CLK_38_DIV (1 << 11)
536
537/* PLLDIV=12, PLLSW=4 (PLLDDR) */
538#define PRCMU_DSI_CLOCK_SETTING 0x0000008C
539
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200540/* DPI 50000000 Hz */
541#define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
542 (16 << PRCMU_CLK_PLL_DIV_SHIFT))
543#define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
544
545/* D=101, N=1, R=4, SELDIV2=0 */
546#define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
547
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200548#define PRCMU_ENABLE_PLLDSI 0x00000001
549#define PRCMU_DISABLE_PLLDSI 0x00000000
550#define PRCMU_RELEASE_RESET_DSS 0x0000400C
551#define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
552/* ESC clk, div0=1, div1=1, div2=3 */
553#define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
554#define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
555#define PRCMU_DSI_RESET_SW 0x00000007
556
557#define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
558
Mattias Nilsson73180f82011-08-12 10:28:10 +0200559int db8500_prcmu_enable_dsipll(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200560{
561 int i;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200562
563 /* Clear DSIPLL_RESETN */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200564 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200565 /* Unclamp DSIPLL in/out */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200566 writel(PRCMU_UNCLAMP_DSIPLL, PRCM_MMIP_LS_CLAMP_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200567
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200568 /* Set DSI PLL FREQ */
Daniel Willerudc72fe852012-01-13 16:20:03 +0100569 writel(PRCMU_PLLDSI_FREQ_SETTING, PRCM_PLLDSI_FREQ);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200570 writel(PRCMU_DSI_PLLOUT_SEL_SETTING, PRCM_DSI_PLLOUT_SEL);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200571 /* Enable Escape clocks */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200572 writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200573
574 /* Start DSI PLL */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200575 writel(PRCMU_ENABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200576 /* Reset DSI PLL */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200577 writel(PRCMU_DSI_RESET_SW, PRCM_DSI_SW_RESET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200578 for (i = 0; i < 10; i++) {
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200579 if ((readl(PRCM_PLLDSI_LOCKP) & PRCMU_PLLDSI_LOCKP_LOCKED)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200580 == PRCMU_PLLDSI_LOCKP_LOCKED)
581 break;
582 udelay(100);
583 }
584 /* Set DSIPLL_RESETN */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200585 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200586 return 0;
587}
588
Mattias Nilsson73180f82011-08-12 10:28:10 +0200589int db8500_prcmu_disable_dsipll(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200590{
591 /* Disable dsi pll */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200592 writel(PRCMU_DISABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200593 /* Disable escapeclock */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200594 writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200595 return 0;
596}
597
Mattias Nilsson73180f82011-08-12 10:28:10 +0200598int db8500_prcmu_set_display_clocks(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200599{
600 unsigned long flags;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200601
602 spin_lock_irqsave(&clk_mgt_lock, flags);
603
604 /* Grab the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200605 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200606 cpu_relax();
607
Daniel Willerudc72fe852012-01-13 16:20:03 +0100608 writel(PRCMU_DSI_CLOCK_SETTING, PRCM_HDMICLK_MGT);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200609 writel(PRCMU_DSI_LP_CLOCK_SETTING, PRCM_TVCLK_MGT);
610 writel(PRCMU_DPI_CLOCK_SETTING, PRCM_LCDCLK_MGT);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200611
612 /* Release the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200613 writel(0, PRCM_SEM);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200614
615 spin_unlock_irqrestore(&clk_mgt_lock, flags);
616
617 return 0;
618}
619
Mattias Nilssonb4a6dbd2012-01-13 16:21:00 +0100620u32 db8500_prcmu_read(unsigned int reg)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200621{
Mattias Nilssonb4a6dbd2012-01-13 16:21:00 +0100622 return readl(_PRCMU_BASE + reg);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200623}
624
Mattias Nilssonb4a6dbd2012-01-13 16:21:00 +0100625void db8500_prcmu_write(unsigned int reg, u32 value)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200626{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200627 unsigned long flags;
628
Mattias Nilssonb4a6dbd2012-01-13 16:21:00 +0100629 spin_lock_irqsave(&prcmu_lock, flags);
630 writel(value, (_PRCMU_BASE + reg));
631 spin_unlock_irqrestore(&prcmu_lock, flags);
632}
633
634void db8500_prcmu_write_masked(unsigned int reg, u32 mask, u32 value)
635{
636 u32 val;
637 unsigned long flags;
638
639 spin_lock_irqsave(&prcmu_lock, flags);
640 val = readl(_PRCMU_BASE + reg);
641 val = ((val & ~mask) | (value & mask));
642 writel(val, (_PRCMU_BASE + reg));
643 spin_unlock_irqrestore(&prcmu_lock, flags);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200644}
645
Mattias Nilssonb58d12f2012-01-13 16:20:10 +0100646struct prcmu_fw_version *prcmu_get_fw_version(void)
647{
648 return fw_info.valid ? &fw_info.version : NULL;
649}
650
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200651bool prcmu_has_arm_maxopp(void)
652{
653 return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) &
654 PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK;
655}
656
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200657/**
658 * prcmu_get_boot_status - PRCMU boot status checking
659 * Returns: the current PRCMU boot status
660 */
661int prcmu_get_boot_status(void)
662{
663 return readb(tcdm_base + PRCM_BOOT_STATUS);
664}
665
666/**
667 * prcmu_set_rc_a2p - This function is used to run few power state sequences
668 * @val: Value to be set, i.e. transition requested
669 * Returns: 0 on success, -EINVAL on invalid argument
670 *
671 * This function is used to run the following power state sequences -
672 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
673 */
674int prcmu_set_rc_a2p(enum romcode_write val)
675{
676 if (val < RDY_2_DS || val > RDY_2_XP70_RST)
677 return -EINVAL;
678 writeb(val, (tcdm_base + PRCM_ROMCODE_A2P));
679 return 0;
680}
681
682/**
683 * prcmu_get_rc_p2a - This function is used to get power state sequences
684 * Returns: the power transition that has last happened
685 *
686 * This function can return the following transitions-
687 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
688 */
689enum romcode_read prcmu_get_rc_p2a(void)
690{
691 return readb(tcdm_base + PRCM_ROMCODE_P2A);
692}
693
694/**
695 * prcmu_get_current_mode - Return the current XP70 power mode
696 * Returns: Returns the current AP(ARM) power mode: init,
697 * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset
698 */
699enum ap_pwrst prcmu_get_xp70_current_state(void)
700{
701 return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE);
702}
703
704/**
705 * prcmu_config_clkout - Configure one of the programmable clock outputs.
706 * @clkout: The CLKOUT number (0 or 1).
707 * @source: The clock to be used (one of the PRCMU_CLKSRC_*).
708 * @div: The divider to be applied.
709 *
710 * Configures one of the programmable clock outputs (CLKOUTs).
711 * @div should be in the range [1,63] to request a configuration, or 0 to
712 * inform that the configuration is no longer requested.
713 */
714int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
715{
716 static int requests[2];
717 int r = 0;
718 unsigned long flags;
719 u32 val;
720 u32 bits;
721 u32 mask;
722 u32 div_mask;
723
724 BUG_ON(clkout > 1);
725 BUG_ON(div > 63);
726 BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009));
727
728 if (!div && !requests[clkout])
729 return -EINVAL;
730
731 switch (clkout) {
732 case 0:
733 div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
734 mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
735 bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
736 (div << PRCM_CLKOCR_CLKODIV0_SHIFT));
737 break;
738 case 1:
739 div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
740 mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
741 PRCM_CLKOCR_CLK1TYPE);
742 bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
743 (div << PRCM_CLKOCR_CLKODIV1_SHIFT));
744 break;
745 }
746 bits &= mask;
747
748 spin_lock_irqsave(&clkout_lock, flags);
749
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200750 val = readl(PRCM_CLKOCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200751 if (val & div_mask) {
752 if (div) {
753 if ((val & mask) != bits) {
754 r = -EBUSY;
755 goto unlock_and_return;
756 }
757 } else {
758 if ((val & mask & ~div_mask) != bits) {
759 r = -EINVAL;
760 goto unlock_and_return;
761 }
762 }
763 }
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200764 writel((bits | (val & ~mask)), PRCM_CLKOCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200765 requests[clkout] += (div ? 1 : -1);
766
767unlock_and_return:
768 spin_unlock_irqrestore(&clkout_lock, flags);
769
770 return r;
771}
772
Mattias Nilsson73180f82011-08-12 10:28:10 +0200773int db8500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200774{
775 unsigned long flags;
776
777 BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state));
778
779 spin_lock_irqsave(&mb0_transfer.lock, flags);
780
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200781 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200782 cpu_relax();
783
784 writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
785 writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE));
786 writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE));
787 writeb((keep_ulp_clk ? 1 : 0),
788 (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
789 writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200790 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200791
792 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
793
794 return 0;
795}
796
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +0100797u8 db8500_prcmu_get_power_state_result(void)
798{
799 return readb(tcdm_base + PRCM_ACK_MB0_AP_PWRSTTR_STATUS);
800}
801
Daniel Lezcano485540d2012-02-20 12:30:26 +0100802/* This function decouple the gic from the prcmu */
803int db8500_prcmu_gic_decouple(void)
804{
Daniel Lezcano801448e2012-02-28 22:46:05 +0100805 u32 val = readl(PRCM_A9_MASK_REQ);
Daniel Lezcano485540d2012-02-20 12:30:26 +0100806
807 /* Set bit 0 register value to 1 */
Daniel Lezcano801448e2012-02-28 22:46:05 +0100808 writel(val | PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ,
809 PRCM_A9_MASK_REQ);
Daniel Lezcano485540d2012-02-20 12:30:26 +0100810
811 /* Make sure the register is updated */
Daniel Lezcano801448e2012-02-28 22:46:05 +0100812 readl(PRCM_A9_MASK_REQ);
Daniel Lezcano485540d2012-02-20 12:30:26 +0100813
814 /* Wait a few cycles for the gic mask completion */
Daniel Lezcano801448e2012-02-28 22:46:05 +0100815 udelay(1);
Daniel Lezcano485540d2012-02-20 12:30:26 +0100816
817 return 0;
818}
819
820/* This function recouple the gic with the prcmu */
821int db8500_prcmu_gic_recouple(void)
822{
Daniel Lezcano801448e2012-02-28 22:46:05 +0100823 u32 val = readl(PRCM_A9_MASK_REQ);
Daniel Lezcano485540d2012-02-20 12:30:26 +0100824
825 /* Set bit 0 register value to 0 */
Daniel Lezcano801448e2012-02-28 22:46:05 +0100826 writel(val & ~PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ, PRCM_A9_MASK_REQ);
Daniel Lezcano485540d2012-02-20 12:30:26 +0100827
828 return 0;
829}
830
Daniel Lezcanocc9a0f62012-02-28 22:46:06 +0100831#define PRCMU_GIC_NUMBER_REGS 5
832
833/*
834 * This function checks if there are pending irq on the gic. It only
835 * makes sense if the gic has been decoupled before with the
836 * db8500_prcmu_gic_decouple function. Disabling an interrupt only
837 * disables the forwarding of the interrupt to any CPU interface. It
838 * does not prevent the interrupt from changing state, for example
839 * becoming pending, or active and pending if it is already
840 * active. Hence, we have to check the interrupt is pending *and* is
841 * active.
842 */
843bool db8500_prcmu_gic_pending_irq(void)
844{
845 u32 pr; /* Pending register */
846 u32 er; /* Enable register */
847 void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE);
848 int i;
849
850 /* 5 registers. STI & PPI not skipped */
851 for (i = 0; i < PRCMU_GIC_NUMBER_REGS; i++) {
852
853 pr = readl_relaxed(dist_base + GIC_DIST_PENDING_SET + i * 4);
854 er = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
855
856 if (pr & er)
857 return true; /* There is a pending interrupt */
858 }
859
860 return false;
861}
862
Daniel Lezcano9f60d332012-02-28 22:46:07 +0100863/*
Daniel Lezcano9ab492e2012-02-28 22:46:08 +0100864 * This function checks if there are pending interrupt on the
865 * prcmu which has been delegated to monitor the irqs with the
866 * db8500_prcmu_copy_gic_settings function.
867 */
868bool db8500_prcmu_pending_irq(void)
869{
870 u32 it, im;
871 int i;
872
873 for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
874 it = readl(PRCM_ARMITVAL31TO0 + i * 4);
875 im = readl(PRCM_ARMITMSK31TO0 + i * 4);
876 if (it & im)
877 return true; /* There is a pending interrupt */
878 }
879
880 return false;
881}
882
883/*
Daniel Lezcano34fe6f12012-02-28 22:46:09 +0100884 * This function checks if the specified cpu is in in WFI. It's usage
885 * makes sense only if the gic is decoupled with the db8500_prcmu_gic_decouple
886 * function. Of course passing smp_processor_id() to this function will
887 * always return false...
888 */
889bool db8500_prcmu_is_cpu_in_wfi(int cpu)
890{
891 return readl(PRCM_ARM_WFI_STANDBY) & cpu ? PRCM_ARM_WFI_STANDBY_WFI1 :
892 PRCM_ARM_WFI_STANDBY_WFI0;
893}
894
895/*
Daniel Lezcano9f60d332012-02-28 22:46:07 +0100896 * This function copies the gic SPI settings to the prcmu in order to
897 * monitor them and abort/finish the retention/off sequence or state.
898 */
899int db8500_prcmu_copy_gic_settings(void)
900{
901 u32 er; /* Enable register */
902 void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE);
903 int i;
904
905 /* We skip the STI and PPI */
906 for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
907 er = readl_relaxed(dist_base +
908 GIC_DIST_ENABLE_SET + (i + 1) * 4);
909 writel(er, PRCM_ARMITMSK31TO0 + i * 4);
910 }
911
912 return 0;
913}
914
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200915/* This function should only be called while mb0_transfer.lock is held. */
916static void config_wakeups(void)
917{
918 const u8 header[2] = {
919 MB0H_CONFIG_WAKEUPS_EXE,
920 MB0H_CONFIG_WAKEUPS_SLEEP
921 };
922 static u32 last_dbb_events;
923 static u32 last_abb_events;
924 u32 dbb_events;
925 u32 abb_events;
926 unsigned int i;
927
928 dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
929 dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK);
930
931 abb_events = mb0_transfer.req.abb_events;
932
933 if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
934 return;
935
936 for (i = 0; i < 2; i++) {
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200937 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200938 cpu_relax();
939 writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
940 writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
941 writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200942 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200943 }
944 last_dbb_events = dbb_events;
945 last_abb_events = abb_events;
946}
947
Mattias Nilsson73180f82011-08-12 10:28:10 +0200948void db8500_prcmu_enable_wakeups(u32 wakeups)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200949{
950 unsigned long flags;
951 u32 bits;
952 int i;
953
954 BUG_ON(wakeups != (wakeups & VALID_WAKEUPS));
955
956 for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) {
957 if (wakeups & BIT(i))
958 bits |= prcmu_wakeup_bit[i];
959 }
960
961 spin_lock_irqsave(&mb0_transfer.lock, flags);
962
963 mb0_transfer.req.dbb_wakeups = bits;
964 config_wakeups();
965
966 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
967}
968
Mattias Nilsson73180f82011-08-12 10:28:10 +0200969void db8500_prcmu_config_abb_event_readout(u32 abb_events)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200970{
971 unsigned long flags;
972
973 spin_lock_irqsave(&mb0_transfer.lock, flags);
974
975 mb0_transfer.req.abb_events = abb_events;
976 config_wakeups();
977
978 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
979}
980
Mattias Nilsson73180f82011-08-12 10:28:10 +0200981void db8500_prcmu_get_abb_event_buffer(void __iomem **buf)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200982{
983 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
984 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
985 else
986 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500);
987}
988
989/**
Mattias Nilsson73180f82011-08-12 10:28:10 +0200990 * db8500_prcmu_set_arm_opp - set the appropriate ARM OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200991 * @opp: The new ARM operating point to which transition is to be made
992 * Returns: 0 on success, non-zero on failure
993 *
994 * This function sets the the operating point of the ARM.
995 */
Mattias Nilsson73180f82011-08-12 10:28:10 +0200996int db8500_prcmu_set_arm_opp(u8 opp)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200997{
998 int r;
999
1000 if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK)
1001 return -EINVAL;
1002
1003 r = 0;
1004
1005 mutex_lock(&mb1_transfer.lock);
1006
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001007 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001008 cpu_relax();
1009
1010 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1011 writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
1012 writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
1013
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001014 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001015 wait_for_completion(&mb1_transfer.work);
1016
1017 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
1018 (mb1_transfer.ack.arm_opp != opp))
1019 r = -EIO;
1020
1021 mutex_unlock(&mb1_transfer.lock);
1022
1023 return r;
1024}
1025
1026/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02001027 * db8500_prcmu_get_arm_opp - get the current ARM OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001028 *
1029 * Returns: the current ARM OPP
1030 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02001031int db8500_prcmu_get_arm_opp(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001032{
1033 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
1034}
1035
1036/**
Mattias Nilsson05089012012-01-13 16:20:20 +01001037 * db8500_prcmu_get_ddr_opp - get the current DDR OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001038 *
1039 * Returns: the current DDR OPP
1040 */
Mattias Nilsson05089012012-01-13 16:20:20 +01001041int db8500_prcmu_get_ddr_opp(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001042{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001043 return readb(PRCM_DDR_SUBSYS_APE_MINBW);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001044}
1045
1046/**
Mattias Nilsson05089012012-01-13 16:20:20 +01001047 * db8500_set_ddr_opp - set the appropriate DDR OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001048 * @opp: The new DDR operating point to which transition is to be made
1049 * Returns: 0 on success, non-zero on failure
1050 *
1051 * This function sets the operating point of the DDR.
1052 */
Mattias Nilsson05089012012-01-13 16:20:20 +01001053int db8500_prcmu_set_ddr_opp(u8 opp)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001054{
1055 if (opp < DDR_100_OPP || opp > DDR_25_OPP)
1056 return -EINVAL;
1057 /* Changing the DDR OPP can hang the hardware pre-v21 */
1058 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001059 writeb(opp, PRCM_DDR_SUBSYS_APE_MINBW);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001060
1061 return 0;
1062}
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001063
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +01001064/* Divide the frequency of certain clocks by 2 for APE_50_PARTLY_25_OPP. */
1065static void request_even_slower_clocks(bool enable)
1066{
1067 void __iomem *clock_reg[] = {
1068 PRCM_ACLK_MGT,
1069 PRCM_DMACLK_MGT
1070 };
1071 unsigned long flags;
1072 unsigned int i;
1073
1074 spin_lock_irqsave(&clk_mgt_lock, flags);
1075
1076 /* Grab the HW semaphore. */
1077 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1078 cpu_relax();
1079
1080 for (i = 0; i < ARRAY_SIZE(clock_reg); i++) {
1081 u32 val;
1082 u32 div;
1083
1084 val = readl(clock_reg[i]);
1085 div = (val & PRCM_CLK_MGT_CLKPLLDIV_MASK);
1086 if (enable) {
1087 if ((div <= 1) || (div > 15)) {
1088 pr_err("prcmu: Bad clock divider %d in %s\n",
1089 div, __func__);
1090 goto unlock_and_return;
1091 }
1092 div <<= 1;
1093 } else {
1094 if (div <= 2)
1095 goto unlock_and_return;
1096 div >>= 1;
1097 }
1098 val = ((val & ~PRCM_CLK_MGT_CLKPLLDIV_MASK) |
1099 (div & PRCM_CLK_MGT_CLKPLLDIV_MASK));
1100 writel(val, clock_reg[i]);
1101 }
1102
1103unlock_and_return:
1104 /* Release the HW semaphore. */
1105 writel(0, PRCM_SEM);
1106
1107 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1108}
1109
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001110/**
Mattias Nilsson05089012012-01-13 16:20:20 +01001111 * db8500_set_ape_opp - set the appropriate APE OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001112 * @opp: The new APE operating point to which transition is to be made
1113 * Returns: 0 on success, non-zero on failure
1114 *
1115 * This function sets the operating point of the APE.
1116 */
Mattias Nilsson05089012012-01-13 16:20:20 +01001117int db8500_prcmu_set_ape_opp(u8 opp)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001118{
1119 int r = 0;
1120
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +01001121 if (opp == mb1_transfer.ape_opp)
1122 return 0;
1123
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001124 mutex_lock(&mb1_transfer.lock);
1125
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +01001126 if (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP)
1127 request_even_slower_clocks(false);
1128
1129 if ((opp != APE_100_OPP) && (mb1_transfer.ape_opp != APE_100_OPP))
1130 goto skip_message;
1131
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001132 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001133 cpu_relax();
1134
1135 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1136 writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +01001137 writeb(((opp == APE_50_PARTLY_25_OPP) ? APE_50_OPP : opp),
1138 (tcdm_base + PRCM_REQ_MB1_APE_OPP));
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001139
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001140 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001141 wait_for_completion(&mb1_transfer.work);
1142
1143 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
1144 (mb1_transfer.ack.ape_opp != opp))
1145 r = -EIO;
1146
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +01001147skip_message:
1148 if ((!r && (opp == APE_50_PARTLY_25_OPP)) ||
1149 (r && (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP)))
1150 request_even_slower_clocks(true);
1151 if (!r)
1152 mb1_transfer.ape_opp = opp;
1153
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001154 mutex_unlock(&mb1_transfer.lock);
1155
1156 return r;
1157}
1158
1159/**
Mattias Nilsson05089012012-01-13 16:20:20 +01001160 * db8500_prcmu_get_ape_opp - get the current APE OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001161 *
1162 * Returns: the current APE OPP
1163 */
Mattias Nilsson05089012012-01-13 16:20:20 +01001164int db8500_prcmu_get_ape_opp(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001165{
1166 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP);
1167}
1168
1169/**
Ulf Hansson686f8712012-09-24 16:43:17 +02001170 * db8500_prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001171 * @enable: true to request the higher voltage, false to drop a request.
1172 *
1173 * Calls to this function to enable and disable requests must be balanced.
1174 */
Ulf Hansson686f8712012-09-24 16:43:17 +02001175int db8500_prcmu_request_ape_opp_100_voltage(bool enable)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001176{
1177 int r = 0;
1178 u8 header;
1179 static unsigned int requests;
1180
1181 mutex_lock(&mb1_transfer.lock);
1182
1183 if (enable) {
1184 if (0 != requests++)
1185 goto unlock_and_return;
1186 header = MB1H_REQUEST_APE_OPP_100_VOLT;
1187 } else {
1188 if (requests == 0) {
1189 r = -EIO;
1190 goto unlock_and_return;
1191 } else if (1 != requests--) {
1192 goto unlock_and_return;
1193 }
1194 header = MB1H_RELEASE_APE_OPP_100_VOLT;
1195 }
1196
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001197 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001198 cpu_relax();
1199
1200 writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1201
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001202 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001203 wait_for_completion(&mb1_transfer.work);
1204
1205 if ((mb1_transfer.ack.header != header) ||
1206 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
1207 r = -EIO;
1208
1209unlock_and_return:
1210 mutex_unlock(&mb1_transfer.lock);
1211
1212 return r;
1213}
1214
1215/**
1216 * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup
1217 *
1218 * This function releases the power state requirements of a USB wakeup.
1219 */
1220int prcmu_release_usb_wakeup_state(void)
1221{
1222 int r = 0;
1223
1224 mutex_lock(&mb1_transfer.lock);
1225
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001226 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001227 cpu_relax();
1228
1229 writeb(MB1H_RELEASE_USB_WAKEUP,
1230 (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1231
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001232 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001233 wait_for_completion(&mb1_transfer.work);
1234
1235 if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
1236 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
1237 r = -EIO;
1238
1239 mutex_unlock(&mb1_transfer.lock);
1240
1241 return r;
1242}
1243
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001244static int request_pll(u8 clock, bool enable)
1245{
1246 int r = 0;
1247
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001248 if (clock == PRCMU_PLLSOC0)
1249 clock = (enable ? PLL_SOC0_ON : PLL_SOC0_OFF);
1250 else if (clock == PRCMU_PLLSOC1)
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001251 clock = (enable ? PLL_SOC1_ON : PLL_SOC1_OFF);
1252 else
1253 return -EINVAL;
1254
1255 mutex_lock(&mb1_transfer.lock);
1256
1257 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1258 cpu_relax();
1259
1260 writeb(MB1H_PLL_ON_OFF, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1261 writeb(clock, (tcdm_base + PRCM_REQ_MB1_PLL_ON_OFF));
1262
1263 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1264 wait_for_completion(&mb1_transfer.work);
1265
1266 if (mb1_transfer.ack.header != MB1H_PLL_ON_OFF)
1267 r = -EIO;
1268
1269 mutex_unlock(&mb1_transfer.lock);
1270
1271 return r;
1272}
1273
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001274/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02001275 * db8500_prcmu_set_epod - set the state of a EPOD (power domain)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001276 * @epod_id: The EPOD to set
1277 * @epod_state: The new EPOD state
1278 *
1279 * This function sets the state of a EPOD (power domain). It may not be called
1280 * from interrupt context.
1281 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02001282int db8500_prcmu_set_epod(u16 epod_id, u8 epod_state)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001283{
1284 int r = 0;
1285 bool ram_retention = false;
1286 int i;
1287
1288 /* check argument */
1289 BUG_ON(epod_id >= NUM_EPOD_ID);
1290
1291 /* set flag if retention is possible */
1292 switch (epod_id) {
1293 case EPOD_ID_SVAMMDSP:
1294 case EPOD_ID_SIAMMDSP:
1295 case EPOD_ID_ESRAM12:
1296 case EPOD_ID_ESRAM34:
1297 ram_retention = true;
1298 break;
1299 }
1300
1301 /* check argument */
1302 BUG_ON(epod_state > EPOD_STATE_ON);
1303 BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention);
1304
1305 /* get lock */
1306 mutex_lock(&mb2_transfer.lock);
1307
1308 /* wait for mailbox */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001309 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001310 cpu_relax();
1311
1312 /* fill in mailbox */
1313 for (i = 0; i < NUM_EPOD_ID; i++)
1314 writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i));
1315 writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id));
1316
1317 writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
1318
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001319 writel(MBOX_BIT(2), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001320
1321 /*
1322 * The current firmware version does not handle errors correctly,
1323 * and we cannot recover if there is an error.
1324 * This is expected to change when the firmware is updated.
1325 */
1326 if (!wait_for_completion_timeout(&mb2_transfer.work,
1327 msecs_to_jiffies(20000))) {
1328 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1329 __func__);
1330 r = -EIO;
1331 goto unlock_and_return;
1332 }
1333
1334 if (mb2_transfer.ack.status != HWACC_PWR_ST_OK)
1335 r = -EIO;
1336
1337unlock_and_return:
1338 mutex_unlock(&mb2_transfer.lock);
1339 return r;
1340}
1341
1342/**
1343 * prcmu_configure_auto_pm - Configure autonomous power management.
1344 * @sleep: Configuration for ApSleep.
1345 * @idle: Configuration for ApIdle.
1346 */
1347void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
1348 struct prcmu_auto_pm_config *idle)
1349{
1350 u32 sleep_cfg;
1351 u32 idle_cfg;
1352 unsigned long flags;
1353
1354 BUG_ON((sleep == NULL) || (idle == NULL));
1355
1356 sleep_cfg = (sleep->sva_auto_pm_enable & 0xF);
1357 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF));
1358 sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF));
1359 sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF));
1360 sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF));
1361 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF));
1362
1363 idle_cfg = (idle->sva_auto_pm_enable & 0xF);
1364 idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF));
1365 idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF));
1366 idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF));
1367 idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF));
1368 idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF));
1369
1370 spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags);
1371
1372 /*
1373 * The autonomous power management configuration is done through
1374 * fields in mailbox 2, but these fields are only used as shared
1375 * variables - i.e. there is no need to send a message.
1376 */
1377 writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP));
1378 writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE));
1379
1380 mb2_transfer.auto_pm_enabled =
1381 ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1382 (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1383 (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1384 (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON));
1385
1386 spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
1387}
1388EXPORT_SYMBOL(prcmu_configure_auto_pm);
1389
1390bool prcmu_is_auto_pm_enabled(void)
1391{
1392 return mb2_transfer.auto_pm_enabled;
1393}
1394
1395static int request_sysclk(bool enable)
1396{
1397 int r;
1398 unsigned long flags;
1399
1400 r = 0;
1401
1402 mutex_lock(&mb3_transfer.sysclk_lock);
1403
1404 spin_lock_irqsave(&mb3_transfer.lock, flags);
1405
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001406 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001407 cpu_relax();
1408
1409 writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
1410
1411 writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001412 writel(MBOX_BIT(3), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001413
1414 spin_unlock_irqrestore(&mb3_transfer.lock, flags);
1415
1416 /*
1417 * The firmware only sends an ACK if we want to enable the
1418 * SysClk, and it succeeds.
1419 */
1420 if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work,
1421 msecs_to_jiffies(20000))) {
1422 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1423 __func__);
1424 r = -EIO;
1425 }
1426
1427 mutex_unlock(&mb3_transfer.sysclk_lock);
1428
1429 return r;
1430}
1431
1432static int request_timclk(bool enable)
1433{
1434 u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK);
1435
1436 if (!enable)
1437 val |= PRCM_TCR_STOP_TIMERS;
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001438 writel(val, PRCM_TCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001439
1440 return 0;
1441}
1442
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001443static int request_clock(u8 clock, bool enable)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001444{
1445 u32 val;
1446 unsigned long flags;
1447
1448 spin_lock_irqsave(&clk_mgt_lock, flags);
1449
1450 /* Grab the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001451 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001452 cpu_relax();
1453
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001454 val = readl(clk_mgt[clock].reg);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001455 if (enable) {
1456 val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw);
1457 } else {
1458 clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
1459 val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK);
1460 }
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001461 writel(val, clk_mgt[clock].reg);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001462
1463 /* Release the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001464 writel(0, PRCM_SEM);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001465
1466 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1467
1468 return 0;
1469}
1470
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001471static int request_sga_clock(u8 clock, bool enable)
1472{
1473 u32 val;
1474 int ret;
1475
1476 if (enable) {
1477 val = readl(PRCM_CGATING_BYPASS);
1478 writel(val | PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1479 }
1480
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001481 ret = request_clock(clock, enable);
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001482
1483 if (!ret && !enable) {
1484 val = readl(PRCM_CGATING_BYPASS);
1485 writel(val & ~PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1486 }
1487
1488 return ret;
1489}
1490
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001491static inline bool plldsi_locked(void)
1492{
1493 return (readl(PRCM_PLLDSI_LOCKP) &
1494 (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 |
1495 PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3)) ==
1496 (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 |
1497 PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3);
1498}
1499
1500static int request_plldsi(bool enable)
1501{
1502 int r = 0;
1503 u32 val;
1504
1505 writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP |
1506 PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI), (enable ?
1507 PRCM_MMIP_LS_CLAMP_CLR : PRCM_MMIP_LS_CLAMP_SET));
1508
1509 val = readl(PRCM_PLLDSI_ENABLE);
1510 if (enable)
1511 val |= PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
1512 else
1513 val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
1514 writel(val, PRCM_PLLDSI_ENABLE);
1515
1516 if (enable) {
1517 unsigned int i;
1518 bool locked = plldsi_locked();
1519
1520 for (i = 10; !locked && (i > 0); --i) {
1521 udelay(100);
1522 locked = plldsi_locked();
1523 }
1524 if (locked) {
1525 writel(PRCM_APE_RESETN_DSIPLL_RESETN,
1526 PRCM_APE_RESETN_SET);
1527 } else {
1528 writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP |
1529 PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI),
1530 PRCM_MMIP_LS_CLAMP_SET);
1531 val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
1532 writel(val, PRCM_PLLDSI_ENABLE);
1533 r = -EAGAIN;
1534 }
1535 } else {
1536 writel(PRCM_APE_RESETN_DSIPLL_RESETN, PRCM_APE_RESETN_CLR);
1537 }
1538 return r;
1539}
1540
1541static int request_dsiclk(u8 n, bool enable)
1542{
1543 u32 val;
1544
1545 val = readl(PRCM_DSI_PLLOUT_SEL);
1546 val &= ~dsiclk[n].divsel_mask;
1547 val |= ((enable ? dsiclk[n].divsel : PRCM_DSI_PLLOUT_SEL_OFF) <<
1548 dsiclk[n].divsel_shift);
1549 writel(val, PRCM_DSI_PLLOUT_SEL);
1550 return 0;
1551}
1552
1553static int request_dsiescclk(u8 n, bool enable)
1554{
1555 u32 val;
1556
1557 val = readl(PRCM_DSITVCLK_DIV);
1558 enable ? (val |= dsiescclk[n].en) : (val &= ~dsiescclk[n].en);
1559 writel(val, PRCM_DSITVCLK_DIV);
1560 return 0;
1561}
1562
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001563/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02001564 * db8500_prcmu_request_clock() - Request for a clock to be enabled or disabled.
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001565 * @clock: The clock for which the request is made.
1566 * @enable: Whether the clock should be enabled (true) or disabled (false).
1567 *
1568 * This function should only be used by the clock implementation.
1569 * Do not use it from any other place!
1570 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02001571int db8500_prcmu_request_clock(u8 clock, bool enable)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001572{
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001573 if (clock == PRCMU_SGACLK)
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001574 return request_sga_clock(clock, enable);
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001575 else if (clock < PRCMU_NUM_REG_CLOCKS)
1576 return request_clock(clock, enable);
1577 else if (clock == PRCMU_TIMCLK)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001578 return request_timclk(enable);
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001579 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1580 return request_dsiclk((clock - PRCMU_DSI0CLK), enable);
1581 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1582 return request_dsiescclk((clock - PRCMU_DSI0ESCCLK), enable);
1583 else if (clock == PRCMU_PLLDSI)
1584 return request_plldsi(enable);
1585 else if (clock == PRCMU_SYSCLK)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001586 return request_sysclk(enable);
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001587 else if ((clock == PRCMU_PLLSOC0) || (clock == PRCMU_PLLSOC1))
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001588 return request_pll(clock, enable);
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001589 else
1590 return -EINVAL;
1591}
1592
1593static unsigned long pll_rate(void __iomem *reg, unsigned long src_rate,
1594 int branch)
1595{
1596 u64 rate;
1597 u32 val;
1598 u32 d;
1599 u32 div = 1;
1600
1601 val = readl(reg);
1602
1603 rate = src_rate;
1604 rate *= ((val & PRCM_PLL_FREQ_D_MASK) >> PRCM_PLL_FREQ_D_SHIFT);
1605
1606 d = ((val & PRCM_PLL_FREQ_N_MASK) >> PRCM_PLL_FREQ_N_SHIFT);
1607 if (d > 1)
1608 div *= d;
1609
1610 d = ((val & PRCM_PLL_FREQ_R_MASK) >> PRCM_PLL_FREQ_R_SHIFT);
1611 if (d > 1)
1612 div *= d;
1613
1614 if (val & PRCM_PLL_FREQ_SELDIV2)
1615 div *= 2;
1616
1617 if ((branch == PLL_FIX) || ((branch == PLL_DIV) &&
1618 (val & PRCM_PLL_FREQ_DIV2EN) &&
1619 ((reg == PRCM_PLLSOC0_FREQ) ||
Michel Jaouen20aee5b2012-08-31 14:21:30 +02001620 (reg == PRCM_PLLARM_FREQ) ||
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001621 (reg == PRCM_PLLDDR_FREQ))))
1622 div *= 2;
1623
1624 (void)do_div(rate, div);
1625
1626 return (unsigned long)rate;
1627}
1628
1629#define ROOT_CLOCK_RATE 38400000
1630
1631static unsigned long clock_rate(u8 clock)
1632{
1633 u32 val;
1634 u32 pllsw;
1635 unsigned long rate = ROOT_CLOCK_RATE;
1636
1637 val = readl(clk_mgt[clock].reg);
1638
1639 if (val & PRCM_CLK_MGT_CLK38) {
1640 if (clk_mgt[clock].clk38div && (val & PRCM_CLK_MGT_CLK38DIV))
1641 rate /= 2;
1642 return rate;
Linus Walleije62ccf32011-10-10 12:14:14 +02001643 }
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001644
1645 val |= clk_mgt[clock].pllsw;
1646 pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
1647
1648 if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC0)
1649 rate = pll_rate(PRCM_PLLSOC0_FREQ, rate, clk_mgt[clock].branch);
1650 else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC1)
1651 rate = pll_rate(PRCM_PLLSOC1_FREQ, rate, clk_mgt[clock].branch);
1652 else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_DDR)
1653 rate = pll_rate(PRCM_PLLDDR_FREQ, rate, clk_mgt[clock].branch);
1654 else
1655 return 0;
1656
1657 if ((clock == PRCMU_SGACLK) &&
1658 (val & PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN)) {
1659 u64 r = (rate * 10);
1660
1661 (void)do_div(r, 25);
1662 return (unsigned long)r;
1663 }
1664 val &= PRCM_CLK_MGT_CLKPLLDIV_MASK;
1665 if (val)
1666 return rate / val;
1667 else
1668 return 0;
1669}
Michel Jaouen20aee5b2012-08-31 14:21:30 +02001670
Ulf Hanssonb2302c82012-10-10 13:42:26 +02001671static unsigned long armss_rate(void)
Michel Jaouen20aee5b2012-08-31 14:21:30 +02001672{
1673 u32 r;
1674 unsigned long rate;
1675
1676 r = readl(PRCM_ARM_CHGCLKREQ);
1677
1678 if (r & PRCM_ARM_CHGCLKREQ_PRCM_ARM_CHGCLKREQ) {
1679 /* External ARMCLKFIX clock */
1680
1681 rate = pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, PLL_FIX);
1682
1683 /* Check PRCM_ARM_CHGCLKREQ divider */
1684 if (!(r & PRCM_ARM_CHGCLKREQ_PRCM_ARM_DIVSEL))
1685 rate /= 2;
1686
1687 /* Check PRCM_ARMCLKFIX_MGT divider */
1688 r = readl(PRCM_ARMCLKFIX_MGT);
1689 r &= PRCM_CLK_MGT_CLKPLLDIV_MASK;
1690 rate /= r;
1691
1692 } else {/* ARM PLL */
1693 rate = pll_rate(PRCM_PLLARM_FREQ, ROOT_CLOCK_RATE, PLL_DIV);
1694 }
1695
Ulf Hanssonb2302c82012-10-10 13:42:26 +02001696 return rate;
Michel Jaouen20aee5b2012-08-31 14:21:30 +02001697}
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001698
1699static unsigned long dsiclk_rate(u8 n)
1700{
1701 u32 divsel;
1702 u32 div = 1;
1703
1704 divsel = readl(PRCM_DSI_PLLOUT_SEL);
1705 divsel = ((divsel & dsiclk[n].divsel_mask) >> dsiclk[n].divsel_shift);
1706
1707 if (divsel == PRCM_DSI_PLLOUT_SEL_OFF)
1708 divsel = dsiclk[n].divsel;
1709
1710 switch (divsel) {
1711 case PRCM_DSI_PLLOUT_SEL_PHI_4:
1712 div *= 2;
1713 case PRCM_DSI_PLLOUT_SEL_PHI_2:
1714 div *= 2;
1715 case PRCM_DSI_PLLOUT_SEL_PHI:
1716 return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
1717 PLL_RAW) / div;
1718 default:
1719 return 0;
1720 }
1721}
1722
1723static unsigned long dsiescclk_rate(u8 n)
1724{
1725 u32 div;
1726
1727 div = readl(PRCM_DSITVCLK_DIV);
1728 div = ((div & dsiescclk[n].div_mask) >> (dsiescclk[n].div_shift));
1729 return clock_rate(PRCMU_TVCLK) / max((u32)1, div);
1730}
1731
1732unsigned long prcmu_clock_rate(u8 clock)
1733{
Linus Walleije62ccf32011-10-10 12:14:14 +02001734 if (clock < PRCMU_NUM_REG_CLOCKS)
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001735 return clock_rate(clock);
1736 else if (clock == PRCMU_TIMCLK)
1737 return ROOT_CLOCK_RATE / 16;
1738 else if (clock == PRCMU_SYSCLK)
1739 return ROOT_CLOCK_RATE;
1740 else if (clock == PRCMU_PLLSOC0)
1741 return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
1742 else if (clock == PRCMU_PLLSOC1)
1743 return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
Michel Jaouen20aee5b2012-08-31 14:21:30 +02001744 else if (clock == PRCMU_ARMSS)
1745 return armss_rate();
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001746 else if (clock == PRCMU_PLLDDR)
1747 return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
1748 else if (clock == PRCMU_PLLDSI)
1749 return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
1750 PLL_RAW);
1751 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1752 return dsiclk_rate(clock - PRCMU_DSI0CLK);
1753 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1754 return dsiescclk_rate(clock - PRCMU_DSI0ESCCLK);
1755 else
1756 return 0;
1757}
1758
1759static unsigned long clock_source_rate(u32 clk_mgt_val, int branch)
1760{
1761 if (clk_mgt_val & PRCM_CLK_MGT_CLK38)
1762 return ROOT_CLOCK_RATE;
1763 clk_mgt_val &= PRCM_CLK_MGT_CLKPLLSW_MASK;
1764 if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC0)
1765 return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, branch);
1766 else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC1)
1767 return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, branch);
1768 else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_DDR)
1769 return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, branch);
1770 else
1771 return 0;
1772}
1773
1774static u32 clock_divider(unsigned long src_rate, unsigned long rate)
1775{
1776 u32 div;
1777
1778 div = (src_rate / rate);
1779 if (div == 0)
1780 return 1;
1781 if (rate < (src_rate / div))
1782 div++;
1783 return div;
1784}
1785
1786static long round_clock_rate(u8 clock, unsigned long rate)
1787{
1788 u32 val;
1789 u32 div;
1790 unsigned long src_rate;
1791 long rounded_rate;
1792
1793 val = readl(clk_mgt[clock].reg);
1794 src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
1795 clk_mgt[clock].branch);
1796 div = clock_divider(src_rate, rate);
1797 if (val & PRCM_CLK_MGT_CLK38) {
1798 if (clk_mgt[clock].clk38div) {
1799 if (div > 2)
1800 div = 2;
1801 } else {
1802 div = 1;
1803 }
1804 } else if ((clock == PRCMU_SGACLK) && (div == 3)) {
1805 u64 r = (src_rate * 10);
1806
1807 (void)do_div(r, 25);
1808 if (r <= rate)
1809 return (unsigned long)r;
1810 }
1811 rounded_rate = (src_rate / min(div, (u32)31));
1812
1813 return rounded_rate;
1814}
1815
Ulf Hanssonb2302c82012-10-10 13:42:26 +02001816/* CPU FREQ table, may be changed due to if MAX_OPP is supported. */
1817static struct cpufreq_frequency_table db8500_cpufreq_table[] = {
1818 { .frequency = 200000, .index = ARM_EXTCLK,},
1819 { .frequency = 400000, .index = ARM_50_OPP,},
1820 { .frequency = 800000, .index = ARM_100_OPP,},
1821 { .frequency = CPUFREQ_TABLE_END,}, /* To be used for MAX_OPP. */
1822 { .frequency = CPUFREQ_TABLE_END,},
1823};
1824
1825static long round_armss_rate(unsigned long rate)
1826{
1827 long freq = 0;
1828 int i = 0;
1829
1830 /* cpufreq table frequencies is in KHz. */
1831 rate = rate / 1000;
1832
1833 /* Find the corresponding arm opp from the cpufreq table. */
1834 while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) {
1835 freq = db8500_cpufreq_table[i].frequency;
1836 if (freq == rate)
1837 break;
1838 i++;
1839 }
1840
1841 /* Return the last valid value, even if a match was not found. */
1842 return freq * 1000;
1843}
1844
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001845#define MIN_PLL_VCO_RATE 600000000ULL
1846#define MAX_PLL_VCO_RATE 1680640000ULL
1847
1848static long round_plldsi_rate(unsigned long rate)
1849{
1850 long rounded_rate = 0;
1851 unsigned long src_rate;
1852 unsigned long rem;
1853 u32 r;
1854
1855 src_rate = clock_rate(PRCMU_HDMICLK);
1856 rem = rate;
1857
1858 for (r = 7; (rem > 0) && (r > 0); r--) {
1859 u64 d;
1860
1861 d = (r * rate);
1862 (void)do_div(d, src_rate);
1863 if (d < 6)
1864 d = 6;
1865 else if (d > 255)
1866 d = 255;
1867 d *= src_rate;
1868 if (((2 * d) < (r * MIN_PLL_VCO_RATE)) ||
1869 ((r * MAX_PLL_VCO_RATE) < (2 * d)))
1870 continue;
1871 (void)do_div(d, r);
1872 if (rate < d) {
1873 if (rounded_rate == 0)
1874 rounded_rate = (long)d;
1875 break;
1876 }
1877 if ((rate - d) < rem) {
1878 rem = (rate - d);
1879 rounded_rate = (long)d;
1880 }
1881 }
1882 return rounded_rate;
1883}
1884
1885static long round_dsiclk_rate(unsigned long rate)
1886{
1887 u32 div;
1888 unsigned long src_rate;
1889 long rounded_rate;
1890
1891 src_rate = pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
1892 PLL_RAW);
1893 div = clock_divider(src_rate, rate);
1894 rounded_rate = (src_rate / ((div > 2) ? 4 : div));
1895
1896 return rounded_rate;
1897}
1898
1899static long round_dsiescclk_rate(unsigned long rate)
1900{
1901 u32 div;
1902 unsigned long src_rate;
1903 long rounded_rate;
1904
1905 src_rate = clock_rate(PRCMU_TVCLK);
1906 div = clock_divider(src_rate, rate);
1907 rounded_rate = (src_rate / min(div, (u32)255));
1908
1909 return rounded_rate;
1910}
1911
1912long prcmu_round_clock_rate(u8 clock, unsigned long rate)
1913{
1914 if (clock < PRCMU_NUM_REG_CLOCKS)
1915 return round_clock_rate(clock, rate);
Ulf Hanssonb2302c82012-10-10 13:42:26 +02001916 else if (clock == PRCMU_ARMSS)
1917 return round_armss_rate(rate);
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001918 else if (clock == PRCMU_PLLDSI)
1919 return round_plldsi_rate(rate);
1920 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
1921 return round_dsiclk_rate(rate);
1922 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
1923 return round_dsiescclk_rate(rate);
1924 else
1925 return (long)prcmu_clock_rate(clock);
1926}
1927
1928static void set_clock_rate(u8 clock, unsigned long rate)
1929{
1930 u32 val;
1931 u32 div;
1932 unsigned long src_rate;
1933 unsigned long flags;
1934
1935 spin_lock_irqsave(&clk_mgt_lock, flags);
1936
1937 /* Grab the HW semaphore. */
1938 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1939 cpu_relax();
1940
1941 val = readl(clk_mgt[clock].reg);
1942 src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
1943 clk_mgt[clock].branch);
1944 div = clock_divider(src_rate, rate);
1945 if (val & PRCM_CLK_MGT_CLK38) {
1946 if (clk_mgt[clock].clk38div) {
1947 if (div > 1)
1948 val |= PRCM_CLK_MGT_CLK38DIV;
1949 else
1950 val &= ~PRCM_CLK_MGT_CLK38DIV;
1951 }
1952 } else if (clock == PRCMU_SGACLK) {
1953 val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK |
1954 PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN);
1955 if (div == 3) {
1956 u64 r = (src_rate * 10);
1957
1958 (void)do_div(r, 25);
1959 if (r <= rate) {
1960 val |= PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN;
1961 div = 0;
1962 }
1963 }
1964 val |= min(div, (u32)31);
1965 } else {
1966 val &= ~PRCM_CLK_MGT_CLKPLLDIV_MASK;
1967 val |= min(div, (u32)31);
1968 }
1969 writel(val, clk_mgt[clock].reg);
1970
1971 /* Release the HW semaphore. */
1972 writel(0, PRCM_SEM);
1973
1974 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1975}
1976
Ulf Hanssonb2302c82012-10-10 13:42:26 +02001977static int set_armss_rate(unsigned long rate)
1978{
1979 int i = 0;
1980
1981 /* cpufreq table frequencies is in KHz. */
1982 rate = rate / 1000;
1983
1984 /* Find the corresponding arm opp from the cpufreq table. */
1985 while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) {
1986 if (db8500_cpufreq_table[i].frequency == rate)
1987 break;
1988 i++;
1989 }
1990
1991 if (db8500_cpufreq_table[i].frequency != rate)
1992 return -EINVAL;
1993
1994 /* Set the new arm opp. */
1995 return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].index);
1996}
1997
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01001998static int set_plldsi_rate(unsigned long rate)
1999{
2000 unsigned long src_rate;
2001 unsigned long rem;
2002 u32 pll_freq = 0;
2003 u32 r;
2004
2005 src_rate = clock_rate(PRCMU_HDMICLK);
2006 rem = rate;
2007
2008 for (r = 7; (rem > 0) && (r > 0); r--) {
2009 u64 d;
2010 u64 hwrate;
2011
2012 d = (r * rate);
2013 (void)do_div(d, src_rate);
2014 if (d < 6)
2015 d = 6;
2016 else if (d > 255)
2017 d = 255;
2018 hwrate = (d * src_rate);
2019 if (((2 * hwrate) < (r * MIN_PLL_VCO_RATE)) ||
2020 ((r * MAX_PLL_VCO_RATE) < (2 * hwrate)))
2021 continue;
2022 (void)do_div(hwrate, r);
2023 if (rate < hwrate) {
2024 if (pll_freq == 0)
2025 pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) |
2026 (r << PRCM_PLL_FREQ_R_SHIFT));
2027 break;
2028 }
2029 if ((rate - hwrate) < rem) {
2030 rem = (rate - hwrate);
2031 pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) |
2032 (r << PRCM_PLL_FREQ_R_SHIFT));
2033 }
2034 }
2035 if (pll_freq == 0)
2036 return -EINVAL;
2037
2038 pll_freq |= (1 << PRCM_PLL_FREQ_N_SHIFT);
2039 writel(pll_freq, PRCM_PLLDSI_FREQ);
2040
2041 return 0;
2042}
2043
2044static void set_dsiclk_rate(u8 n, unsigned long rate)
2045{
2046 u32 val;
2047 u32 div;
2048
2049 div = clock_divider(pll_rate(PRCM_PLLDSI_FREQ,
2050 clock_rate(PRCMU_HDMICLK), PLL_RAW), rate);
2051
2052 dsiclk[n].divsel = (div == 1) ? PRCM_DSI_PLLOUT_SEL_PHI :
2053 (div == 2) ? PRCM_DSI_PLLOUT_SEL_PHI_2 :
2054 /* else */ PRCM_DSI_PLLOUT_SEL_PHI_4;
2055
2056 val = readl(PRCM_DSI_PLLOUT_SEL);
2057 val &= ~dsiclk[n].divsel_mask;
2058 val |= (dsiclk[n].divsel << dsiclk[n].divsel_shift);
2059 writel(val, PRCM_DSI_PLLOUT_SEL);
2060}
2061
2062static void set_dsiescclk_rate(u8 n, unsigned long rate)
2063{
2064 u32 val;
2065 u32 div;
2066
2067 div = clock_divider(clock_rate(PRCMU_TVCLK), rate);
2068 val = readl(PRCM_DSITVCLK_DIV);
2069 val &= ~dsiescclk[n].div_mask;
2070 val |= (min(div, (u32)255) << dsiescclk[n].div_shift);
2071 writel(val, PRCM_DSITVCLK_DIV);
2072}
2073
2074int prcmu_set_clock_rate(u8 clock, unsigned long rate)
2075{
2076 if (clock < PRCMU_NUM_REG_CLOCKS)
2077 set_clock_rate(clock, rate);
Ulf Hanssonb2302c82012-10-10 13:42:26 +02002078 else if (clock == PRCMU_ARMSS)
2079 return set_armss_rate(rate);
Mattias Nilsson6b6fae22012-01-13 16:20:28 +01002080 else if (clock == PRCMU_PLLDSI)
2081 return set_plldsi_rate(rate);
2082 else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
2083 set_dsiclk_rate((clock - PRCMU_DSI0CLK), rate);
2084 else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
2085 set_dsiescclk_rate((clock - PRCMU_DSI0ESCCLK), rate);
2086 return 0;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002087}
2088
Mattias Nilsson73180f82011-08-12 10:28:10 +02002089int db8500_prcmu_config_esram0_deep_sleep(u8 state)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002090{
2091 if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
2092 (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
2093 return -EINVAL;
2094
2095 mutex_lock(&mb4_transfer.lock);
2096
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002097 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002098 cpu_relax();
2099
2100 writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2101 writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON),
2102 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE));
2103 writeb(DDR_PWR_STATE_ON,
2104 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
2105 writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
2106
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002107 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002108 wait_for_completion(&mb4_transfer.work);
2109
2110 mutex_unlock(&mb4_transfer.lock);
2111
2112 return 0;
2113}
2114
Mattias Nilsson05089012012-01-13 16:20:20 +01002115int db8500_prcmu_config_hotdog(u8 threshold)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002116{
2117 mutex_lock(&mb4_transfer.lock);
2118
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002119 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002120 cpu_relax();
2121
2122 writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
2123 writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2124
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002125 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002126 wait_for_completion(&mb4_transfer.work);
2127
2128 mutex_unlock(&mb4_transfer.lock);
2129
2130 return 0;
2131}
2132
Mattias Nilsson05089012012-01-13 16:20:20 +01002133int db8500_prcmu_config_hotmon(u8 low, u8 high)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002134{
2135 mutex_lock(&mb4_transfer.lock);
2136
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002137 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002138 cpu_relax();
2139
2140 writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
2141 writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH));
2142 writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH),
2143 (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
2144 writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2145
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002146 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002147 wait_for_completion(&mb4_transfer.work);
2148
2149 mutex_unlock(&mb4_transfer.lock);
2150
2151 return 0;
2152}
2153
2154static int config_hot_period(u16 val)
2155{
2156 mutex_lock(&mb4_transfer.lock);
2157
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002158 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002159 cpu_relax();
2160
2161 writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
2162 writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2163
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002164 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002165 wait_for_completion(&mb4_transfer.work);
2166
2167 mutex_unlock(&mb4_transfer.lock);
2168
2169 return 0;
2170}
2171
Mattias Nilsson05089012012-01-13 16:20:20 +01002172int db8500_prcmu_start_temp_sense(u16 cycles32k)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002173{
2174 if (cycles32k == 0xFFFF)
2175 return -EINVAL;
2176
2177 return config_hot_period(cycles32k);
2178}
2179
Mattias Nilsson05089012012-01-13 16:20:20 +01002180int db8500_prcmu_stop_temp_sense(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002181{
2182 return config_hot_period(0xFFFF);
2183}
2184
Jonas Aberg84165b82011-08-12 10:28:33 +02002185static int prcmu_a9wdog(u8 cmd, u8 d0, u8 d1, u8 d2, u8 d3)
2186{
2187
2188 mutex_lock(&mb4_transfer.lock);
2189
2190 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
2191 cpu_relax();
2192
2193 writeb(d0, (tcdm_base + PRCM_REQ_MB4_A9WDOG_0));
2194 writeb(d1, (tcdm_base + PRCM_REQ_MB4_A9WDOG_1));
2195 writeb(d2, (tcdm_base + PRCM_REQ_MB4_A9WDOG_2));
2196 writeb(d3, (tcdm_base + PRCM_REQ_MB4_A9WDOG_3));
2197
2198 writeb(cmd, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
2199
2200 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
2201 wait_for_completion(&mb4_transfer.work);
2202
2203 mutex_unlock(&mb4_transfer.lock);
2204
2205 return 0;
2206
2207}
2208
Mattias Nilsson05089012012-01-13 16:20:20 +01002209int db8500_prcmu_config_a9wdog(u8 num, bool sleep_auto_off)
Jonas Aberg84165b82011-08-12 10:28:33 +02002210{
2211 BUG_ON(num == 0 || num > 0xf);
2212 return prcmu_a9wdog(MB4H_A9WDOG_CONF, num, 0, 0,
2213 sleep_auto_off ? A9WDOG_AUTO_OFF_EN :
2214 A9WDOG_AUTO_OFF_DIS);
2215}
Fabio Baltieri6f8cfa92013-01-18 12:40:12 +01002216EXPORT_SYMBOL(db8500_prcmu_config_a9wdog);
Jonas Aberg84165b82011-08-12 10:28:33 +02002217
Mattias Nilsson05089012012-01-13 16:20:20 +01002218int db8500_prcmu_enable_a9wdog(u8 id)
Jonas Aberg84165b82011-08-12 10:28:33 +02002219{
2220 return prcmu_a9wdog(MB4H_A9WDOG_EN, id, 0, 0, 0);
2221}
Fabio Baltieri6f8cfa92013-01-18 12:40:12 +01002222EXPORT_SYMBOL(db8500_prcmu_enable_a9wdog);
Jonas Aberg84165b82011-08-12 10:28:33 +02002223
Mattias Nilsson05089012012-01-13 16:20:20 +01002224int db8500_prcmu_disable_a9wdog(u8 id)
Jonas Aberg84165b82011-08-12 10:28:33 +02002225{
2226 return prcmu_a9wdog(MB4H_A9WDOG_DIS, id, 0, 0, 0);
2227}
Fabio Baltieri6f8cfa92013-01-18 12:40:12 +01002228EXPORT_SYMBOL(db8500_prcmu_disable_a9wdog);
Jonas Aberg84165b82011-08-12 10:28:33 +02002229
Mattias Nilsson05089012012-01-13 16:20:20 +01002230int db8500_prcmu_kick_a9wdog(u8 id)
Jonas Aberg84165b82011-08-12 10:28:33 +02002231{
2232 return prcmu_a9wdog(MB4H_A9WDOG_KICK, id, 0, 0, 0);
2233}
Fabio Baltieri6f8cfa92013-01-18 12:40:12 +01002234EXPORT_SYMBOL(db8500_prcmu_kick_a9wdog);
Jonas Aberg84165b82011-08-12 10:28:33 +02002235
2236/*
2237 * timeout is 28 bit, in ms.
2238 */
Mattias Nilsson05089012012-01-13 16:20:20 +01002239int db8500_prcmu_load_a9wdog(u8 id, u32 timeout)
Jonas Aberg84165b82011-08-12 10:28:33 +02002240{
Jonas Aberg84165b82011-08-12 10:28:33 +02002241 return prcmu_a9wdog(MB4H_A9WDOG_LOAD,
2242 (id & A9WDOG_ID_MASK) |
2243 /*
2244 * Put the lowest 28 bits of timeout at
2245 * offset 4. Four first bits are used for id.
2246 */
2247 (u8)((timeout << 4) & 0xf0),
2248 (u8)((timeout >> 4) & 0xff),
2249 (u8)((timeout >> 12) & 0xff),
2250 (u8)((timeout >> 20) & 0xff));
2251}
Fabio Baltieri6f8cfa92013-01-18 12:40:12 +01002252EXPORT_SYMBOL(db8500_prcmu_load_a9wdog);
Jonas Aberg84165b82011-08-12 10:28:33 +02002253
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002254/**
Linus Walleije3726fc2010-08-19 12:36:01 +01002255 * prcmu_abb_read() - Read register value(s) from the ABB.
2256 * @slave: The I2C slave address.
2257 * @reg: The (start) register address.
2258 * @value: The read out value(s).
2259 * @size: The number of registers to read.
2260 *
2261 * Reads register value(s) from the ABB.
2262 * @size has to be 1 for the current firmware version.
2263 */
2264int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
2265{
2266 int r;
2267
2268 if (size != 1)
2269 return -EINVAL;
2270
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002271 mutex_lock(&mb5_transfer.lock);
Linus Walleije3726fc2010-08-19 12:36:01 +01002272
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002273 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
Linus Walleije3726fc2010-08-19 12:36:01 +01002274 cpu_relax();
2275
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002276 writeb(0, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB5));
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002277 writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
2278 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
2279 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
2280 writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
Linus Walleije3726fc2010-08-19 12:36:01 +01002281
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002282 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002283
Linus Walleije3726fc2010-08-19 12:36:01 +01002284 if (!wait_for_completion_timeout(&mb5_transfer.work,
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002285 msecs_to_jiffies(20000))) {
2286 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
2287 __func__);
Linus Walleije3726fc2010-08-19 12:36:01 +01002288 r = -EIO;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002289 } else {
2290 r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO);
Linus Walleije3726fc2010-08-19 12:36:01 +01002291 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002292
Linus Walleije3726fc2010-08-19 12:36:01 +01002293 if (!r)
2294 *value = mb5_transfer.ack.value;
2295
Linus Walleije3726fc2010-08-19 12:36:01 +01002296 mutex_unlock(&mb5_transfer.lock);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002297
Linus Walleije3726fc2010-08-19 12:36:01 +01002298 return r;
2299}
Linus Walleije3726fc2010-08-19 12:36:01 +01002300
2301/**
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002302 * prcmu_abb_write_masked() - Write masked register value(s) to the ABB.
Linus Walleije3726fc2010-08-19 12:36:01 +01002303 * @slave: The I2C slave address.
2304 * @reg: The (start) register address.
2305 * @value: The value(s) to write.
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002306 * @mask: The mask(s) to use.
Linus Walleije3726fc2010-08-19 12:36:01 +01002307 * @size: The number of registers to write.
2308 *
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002309 * Writes masked register value(s) to the ABB.
2310 * For each @value, only the bits set to 1 in the corresponding @mask
2311 * will be written. The other bits are not changed.
Linus Walleije3726fc2010-08-19 12:36:01 +01002312 * @size has to be 1 for the current firmware version.
2313 */
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002314int prcmu_abb_write_masked(u8 slave, u8 reg, u8 *value, u8 *mask, u8 size)
Linus Walleije3726fc2010-08-19 12:36:01 +01002315{
2316 int r;
2317
2318 if (size != 1)
2319 return -EINVAL;
2320
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002321 mutex_lock(&mb5_transfer.lock);
Linus Walleije3726fc2010-08-19 12:36:01 +01002322
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002323 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
Linus Walleije3726fc2010-08-19 12:36:01 +01002324 cpu_relax();
2325
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002326 writeb(~*mask, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB5));
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002327 writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
2328 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
2329 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
2330 writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
Linus Walleije3726fc2010-08-19 12:36:01 +01002331
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002332 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002333
Linus Walleije3726fc2010-08-19 12:36:01 +01002334 if (!wait_for_completion_timeout(&mb5_transfer.work,
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002335 msecs_to_jiffies(20000))) {
2336 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
2337 __func__);
Linus Walleije3726fc2010-08-19 12:36:01 +01002338 r = -EIO;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002339 } else {
2340 r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
Linus Walleije3726fc2010-08-19 12:36:01 +01002341 }
Linus Walleije3726fc2010-08-19 12:36:01 +01002342
Linus Walleije3726fc2010-08-19 12:36:01 +01002343 mutex_unlock(&mb5_transfer.lock);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002344
Linus Walleije3726fc2010-08-19 12:36:01 +01002345 return r;
2346}
Linus Walleije3726fc2010-08-19 12:36:01 +01002347
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002348/**
Mattias Nilsson3c3e4892012-03-08 14:02:05 +01002349 * prcmu_abb_write() - Write register value(s) to the ABB.
2350 * @slave: The I2C slave address.
2351 * @reg: The (start) register address.
2352 * @value: The value(s) to write.
2353 * @size: The number of registers to write.
2354 *
2355 * Writes register value(s) to the ABB.
2356 * @size has to be 1 for the current firmware version.
2357 */
2358int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
2359{
2360 u8 mask = ~0;
2361
2362 return prcmu_abb_write_masked(slave, reg, value, &mask, size);
2363}
2364
2365/**
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002366 * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem
2367 */
Arun Murthy5261e102012-05-21 14:28:21 +05302368int prcmu_ac_wake_req(void)
Martin Perssone0befb22010-12-08 15:13:28 +01002369{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002370 u32 val;
Arun Murthy5261e102012-05-21 14:28:21 +05302371 int ret = 0;
Martin Perssone0befb22010-12-08 15:13:28 +01002372
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002373 mutex_lock(&mb0_transfer.ac_wake_lock);
Martin Perssone0befb22010-12-08 15:13:28 +01002374
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002375 val = readl(PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002376 if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
2377 goto unlock_and_return;
2378
2379 atomic_set(&ac_wake_req_state, 1);
2380
Arun Murthy5261e102012-05-21 14:28:21 +05302381 /*
2382 * Force Modem Wake-up before hostaccess_req ping-pong.
2383 * It prevents Modem to enter in Sleep while acking the hostaccess
2384 * request. The 31us delay has been calculated by HWI.
2385 */
2386 val |= PRCM_HOSTACCESS_REQ_WAKE_REQ;
2387 writel(val, PRCM_HOSTACCESS_REQ);
2388
2389 udelay(31);
2390
2391 val |= PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ;
2392 writel(val, PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002393
2394 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
Mattias Nilssond6e30022011-08-12 10:28:43 +02002395 msecs_to_jiffies(5000))) {
Arun Murthy5261e102012-05-21 14:28:21 +05302396#if defined(CONFIG_DBX500_PRCMU_DEBUG)
2397 db8500_prcmu_debug_dump(__func__, true, true);
2398#endif
Linus Walleij57265bc2011-10-10 13:04:44 +02002399 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
Mattias Nilssond6e30022011-08-12 10:28:43 +02002400 __func__);
Arun Murthy5261e102012-05-21 14:28:21 +05302401 ret = -EFAULT;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002402 }
2403
2404unlock_and_return:
2405 mutex_unlock(&mb0_transfer.ac_wake_lock);
Arun Murthy5261e102012-05-21 14:28:21 +05302406 return ret;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002407}
2408
2409/**
2410 * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem
2411 */
2412void prcmu_ac_sleep_req()
2413{
2414 u32 val;
2415
2416 mutex_lock(&mb0_transfer.ac_wake_lock);
2417
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002418 val = readl(PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002419 if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
2420 goto unlock_and_return;
2421
2422 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002423 PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002424
2425 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
Mattias Nilssond6e30022011-08-12 10:28:43 +02002426 msecs_to_jiffies(5000))) {
Linus Walleij57265bc2011-10-10 13:04:44 +02002427 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002428 __func__);
2429 }
2430
2431 atomic_set(&ac_wake_req_state, 0);
2432
2433unlock_and_return:
2434 mutex_unlock(&mb0_transfer.ac_wake_lock);
2435}
2436
Mattias Nilsson73180f82011-08-12 10:28:10 +02002437bool db8500_prcmu_is_ac_wake_requested(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002438{
2439 return (atomic_read(&ac_wake_req_state) != 0);
2440}
2441
2442/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02002443 * db8500_prcmu_system_reset - System reset
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002444 *
Mattias Nilsson73180f82011-08-12 10:28:10 +02002445 * Saves the reset reason code and then sets the APE_SOFTRST register which
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002446 * fires interrupt to fw
2447 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02002448void db8500_prcmu_system_reset(u16 reset_code)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002449{
2450 writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002451 writel(1, PRCM_APE_SOFTRST);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002452}
2453
2454/**
Sebastian Rasmussen597045d2011-08-12 10:28:53 +02002455 * db8500_prcmu_get_reset_code - Retrieve SW reset reason code
2456 *
2457 * Retrieves the reset reason code stored by prcmu_system_reset() before
2458 * last restart.
2459 */
2460u16 db8500_prcmu_get_reset_code(void)
2461{
2462 return readw(tcdm_base + PRCM_SW_RST_REASON);
2463}
2464
2465/**
Mattias Nilsson05089012012-01-13 16:20:20 +01002466 * db8500_prcmu_reset_modem - ask the PRCMU to reset modem
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002467 */
Mattias Nilsson05089012012-01-13 16:20:20 +01002468void db8500_prcmu_modem_reset(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002469{
Martin Perssone0befb22010-12-08 15:13:28 +01002470 mutex_lock(&mb1_transfer.lock);
2471
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002472 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Martin Perssone0befb22010-12-08 15:13:28 +01002473 cpu_relax();
2474
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002475 writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002476 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Martin Perssone0befb22010-12-08 15:13:28 +01002477 wait_for_completion(&mb1_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002478
2479 /*
2480 * No need to check return from PRCMU as modem should go in reset state
2481 * This state is already managed by upper layer
2482 */
Martin Perssone0befb22010-12-08 15:13:28 +01002483
2484 mutex_unlock(&mb1_transfer.lock);
Martin Perssone0befb22010-12-08 15:13:28 +01002485}
2486
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002487static void ack_dbb_wakeup(void)
Martin Perssone0befb22010-12-08 15:13:28 +01002488{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002489 unsigned long flags;
Martin Perssone0befb22010-12-08 15:13:28 +01002490
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002491 spin_lock_irqsave(&mb0_transfer.lock, flags);
Martin Perssone0befb22010-12-08 15:13:28 +01002492
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002493 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002494 cpu_relax();
Martin Perssone0befb22010-12-08 15:13:28 +01002495
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002496 writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002497 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
Martin Perssone0befb22010-12-08 15:13:28 +01002498
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002499 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
Martin Perssone0befb22010-12-08 15:13:28 +01002500}
2501
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002502static inline void print_unknown_header_warning(u8 n, u8 header)
Linus Walleije3726fc2010-08-19 12:36:01 +01002503{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002504 pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n",
2505 header, n);
Linus Walleije3726fc2010-08-19 12:36:01 +01002506}
2507
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002508static bool read_mailbox_0(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002509{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002510 bool r;
2511 u32 ev;
2512 unsigned int n;
2513 u8 header;
2514
2515 header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0);
2516 switch (header) {
2517 case MB0H_WAKEUP_EXE:
2518 case MB0H_WAKEUP_SLEEP:
2519 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
2520 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500);
2521 else
2522 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500);
2523
2524 if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK))
2525 complete(&mb0_transfer.ac_wake_work);
2526 if (ev & WAKEUP_BIT_SYSCLK_OK)
2527 complete(&mb3_transfer.sysclk_work);
2528
2529 ev &= mb0_transfer.req.dbb_irqs;
2530
2531 for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
2532 if (ev & prcmu_irq_bit[n])
Linus Walleij89d9b1c2012-12-20 10:20:15 +01002533 generic_handle_irq(irq_find_mapping(db8500_irq_domain, n));
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002534 }
2535 r = true;
2536 break;
2537 default:
2538 print_unknown_header_warning(0, header);
2539 r = false;
2540 break;
2541 }
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002542 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002543 return r;
2544}
2545
2546static bool read_mailbox_1(void)
2547{
2548 mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1);
2549 mb1_transfer.ack.arm_opp = readb(tcdm_base +
2550 PRCM_ACK_MB1_CURRENT_ARM_OPP);
2551 mb1_transfer.ack.ape_opp = readb(tcdm_base +
2552 PRCM_ACK_MB1_CURRENT_APE_OPP);
2553 mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
2554 PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002555 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR);
Martin Perssone0befb22010-12-08 15:13:28 +01002556 complete(&mb1_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002557 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002558}
2559
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002560static bool read_mailbox_2(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002561{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002562 mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002563 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002564 complete(&mb2_transfer.work);
2565 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002566}
2567
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002568static bool read_mailbox_3(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002569{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002570 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002571 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002572}
2573
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002574static bool read_mailbox_4(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002575{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002576 u8 header;
2577 bool do_complete = true;
2578
2579 header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4);
2580 switch (header) {
2581 case MB4H_MEM_ST:
2582 case MB4H_HOTDOG:
2583 case MB4H_HOTMON:
2584 case MB4H_HOT_PERIOD:
Mattias Nilssona592c2e2011-08-12 10:27:41 +02002585 case MB4H_A9WDOG_CONF:
2586 case MB4H_A9WDOG_EN:
2587 case MB4H_A9WDOG_DIS:
2588 case MB4H_A9WDOG_LOAD:
2589 case MB4H_A9WDOG_KICK:
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002590 break;
2591 default:
2592 print_unknown_header_warning(4, header);
2593 do_complete = false;
2594 break;
2595 }
2596
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002597 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002598
2599 if (do_complete)
2600 complete(&mb4_transfer.work);
2601
2602 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002603}
2604
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002605static bool read_mailbox_5(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002606{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002607 mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
2608 mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002609 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR);
Linus Walleije3726fc2010-08-19 12:36:01 +01002610 complete(&mb5_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002611 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002612}
2613
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002614static bool read_mailbox_6(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002615{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002616 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002617 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002618}
2619
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002620static bool read_mailbox_7(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01002621{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002622 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002623 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01002624}
2625
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002626static bool (* const read_mailbox[NUM_MB])(void) = {
Linus Walleije3726fc2010-08-19 12:36:01 +01002627 read_mailbox_0,
2628 read_mailbox_1,
2629 read_mailbox_2,
2630 read_mailbox_3,
2631 read_mailbox_4,
2632 read_mailbox_5,
2633 read_mailbox_6,
2634 read_mailbox_7
2635};
2636
2637static irqreturn_t prcmu_irq_handler(int irq, void *data)
2638{
2639 u32 bits;
2640 u8 n;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002641 irqreturn_t r;
Linus Walleije3726fc2010-08-19 12:36:01 +01002642
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002643 bits = (readl(PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
Linus Walleije3726fc2010-08-19 12:36:01 +01002644 if (unlikely(!bits))
2645 return IRQ_NONE;
2646
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002647 r = IRQ_HANDLED;
Linus Walleije3726fc2010-08-19 12:36:01 +01002648 for (n = 0; bits; n++) {
2649 if (bits & MBOX_BIT(n)) {
2650 bits -= MBOX_BIT(n);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002651 if (read_mailbox[n]())
2652 r = IRQ_WAKE_THREAD;
Linus Walleije3726fc2010-08-19 12:36:01 +01002653 }
2654 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002655 return r;
2656}
2657
2658static irqreturn_t prcmu_irq_thread_fn(int irq, void *data)
2659{
2660 ack_dbb_wakeup();
Linus Walleije3726fc2010-08-19 12:36:01 +01002661 return IRQ_HANDLED;
2662}
2663
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002664static void prcmu_mask_work(struct work_struct *work)
2665{
2666 unsigned long flags;
2667
2668 spin_lock_irqsave(&mb0_transfer.lock, flags);
2669
2670 config_wakeups();
2671
2672 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
2673}
2674
2675static void prcmu_irq_mask(struct irq_data *d)
2676{
2677 unsigned long flags;
2678
2679 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
2680
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01002681 mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->hwirq];
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002682
2683 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2684
2685 if (d->irq != IRQ_PRCMU_CA_SLEEP)
2686 schedule_work(&mb0_transfer.mask_work);
2687}
2688
2689static void prcmu_irq_unmask(struct irq_data *d)
2690{
2691 unsigned long flags;
2692
2693 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
2694
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01002695 mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->hwirq];
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002696
2697 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2698
2699 if (d->irq != IRQ_PRCMU_CA_SLEEP)
2700 schedule_work(&mb0_transfer.mask_work);
2701}
2702
2703static void noop(struct irq_data *d)
2704{
2705}
2706
2707static struct irq_chip prcmu_irq_chip = {
2708 .name = "prcmu",
2709 .irq_disable = prcmu_irq_mask,
2710 .irq_ack = noop,
2711 .irq_mask = prcmu_irq_mask,
2712 .irq_unmask = prcmu_irq_unmask,
2713};
2714
Mattias Nilssonb58d12f2012-01-13 16:20:10 +01002715static char *fw_project_name(u8 project)
2716{
2717 switch (project) {
2718 case PRCMU_FW_PROJECT_U8500:
2719 return "U8500";
2720 case PRCMU_FW_PROJECT_U8500_C2:
2721 return "U8500 C2";
2722 case PRCMU_FW_PROJECT_U9500:
2723 return "U9500";
2724 case PRCMU_FW_PROJECT_U9500_C2:
2725 return "U9500 C2";
Bengt Jonsson5f96a1a62012-03-15 19:50:40 +01002726 case PRCMU_FW_PROJECT_U8520:
2727 return "U8520";
Bengt Jonsson1927ddf2012-03-15 19:50:51 +01002728 case PRCMU_FW_PROJECT_U8420:
2729 return "U8420";
Mattias Nilssonb58d12f2012-01-13 16:20:10 +01002730 default:
2731 return "Unknown";
2732 }
2733}
2734
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01002735static int db8500_irq_map(struct irq_domain *d, unsigned int virq,
2736 irq_hw_number_t hwirq)
2737{
2738 irq_set_chip_and_handler(virq, &prcmu_irq_chip,
2739 handle_simple_irq);
2740 set_irq_flags(virq, IRQF_VALID);
2741
2742 return 0;
2743}
2744
2745static struct irq_domain_ops db8500_irq_ops = {
Linus Walleij89d9b1c2012-12-20 10:20:15 +01002746 .map = db8500_irq_map,
2747 .xlate = irq_domain_xlate_twocell,
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01002748};
2749
2750static int db8500_irq_init(struct device_node *np)
2751{
Linus Walleij89d9b1c2012-12-20 10:20:15 +01002752 int irq_base = 0;
2753 int i;
Linus Walleija7238e42012-10-18 18:22:11 +02002754
2755 /* In the device tree case, just take some IRQs */
2756 if (!np)
2757 irq_base = IRQ_PRCMU_BASE;
2758
2759 db8500_irq_domain = irq_domain_add_simple(
2760 np, NUM_PRCMU_WAKEUPS, irq_base,
2761 &db8500_irq_ops, NULL);
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01002762
2763 if (!db8500_irq_domain) {
2764 pr_err("Failed to create irqdomain\n");
2765 return -ENOSYS;
2766 }
2767
Linus Walleij89d9b1c2012-12-20 10:20:15 +01002768 /* All wakeups will be used, so create mappings for all */
2769 for (i = 0; i < NUM_PRCMU_WAKEUPS; i++)
2770 irq_create_mapping(db8500_irq_domain, i);
2771
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01002772 return 0;
2773}
2774
Mattias Nilsson73180f82011-08-12 10:28:10 +02002775void __init db8500_prcmu_early_init(void)
Mattias Wallinfcbd4582010-12-02 16:20:42 +01002776{
Lee Jonesb851c062012-11-05 16:10:36 +01002777 if (cpu_is_u8500v2() || cpu_is_u9540()) {
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002778 void *tcpm_base = ioremap_nocache(U8500_PRCMU_TCPM_BASE, SZ_4K);
2779
2780 if (tcpm_base != NULL) {
Linus Walleij3e2762c2012-01-02 14:17:40 +01002781 u32 version;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002782 version = readl(tcpm_base + PRCMU_FW_VERSION_OFFSET);
Mattias Nilssonb58d12f2012-01-13 16:20:10 +01002783 fw_info.version.project = version & 0xFF;
2784 fw_info.version.api_version = (version >> 8) & 0xFF;
2785 fw_info.version.func_version = (version >> 16) & 0xFF;
2786 fw_info.version.errata = (version >> 24) & 0xFF;
2787 fw_info.valid = true;
2788 pr_info("PRCMU firmware: %s, version %d.%d.%d\n",
2789 fw_project_name(fw_info.version.project),
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002790 (version >> 8) & 0xFF, (version >> 16) & 0xFF,
2791 (version >> 24) & 0xFF);
2792 iounmap(tcpm_base);
2793 }
2794
Lee Jonesb851c062012-11-05 16:10:36 +01002795 if (cpu_is_u9540())
2796 tcdm_base = ioremap_nocache(U8500_PRCMU_TCDM_BASE,
2797 SZ_4K + SZ_8K) + SZ_8K;
2798 else
2799 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE);
Mattias Wallinfcbd4582010-12-02 16:20:42 +01002800 } else {
2801 pr_err("prcmu: Unsupported chip version\n");
2802 BUG();
2803 }
Mattias Wallinfcbd4582010-12-02 16:20:42 +01002804
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002805 spin_lock_init(&mb0_transfer.lock);
2806 spin_lock_init(&mb0_transfer.dbb_irqs_lock);
2807 mutex_init(&mb0_transfer.ac_wake_lock);
2808 init_completion(&mb0_transfer.ac_wake_work);
Martin Perssone0befb22010-12-08 15:13:28 +01002809 mutex_init(&mb1_transfer.lock);
2810 init_completion(&mb1_transfer.work);
Mattias Nilsson4d64d2e2012-01-13 16:20:43 +01002811 mb1_transfer.ape_opp = APE_NO_CHANGE;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002812 mutex_init(&mb2_transfer.lock);
2813 init_completion(&mb2_transfer.work);
2814 spin_lock_init(&mb2_transfer.auto_pm_lock);
2815 spin_lock_init(&mb3_transfer.lock);
2816 mutex_init(&mb3_transfer.sysclk_lock);
2817 init_completion(&mb3_transfer.sysclk_work);
2818 mutex_init(&mb4_transfer.lock);
2819 init_completion(&mb4_transfer.work);
Linus Walleije3726fc2010-08-19 12:36:01 +01002820 mutex_init(&mb5_transfer.lock);
2821 init_completion(&mb5_transfer.work);
2822
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002823 INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
Linus Walleije3726fc2010-08-19 12:36:01 +01002824}
2825
Mattias Nilsson05089012012-01-13 16:20:20 +01002826static void __init init_prcm_registers(void)
Mattias Nilssond65e12d2011-08-12 10:27:50 +02002827{
2828 u32 val;
2829
2830 val = readl(PRCM_A9PL_FORCE_CLKEN);
2831 val &= ~(PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN |
2832 PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN);
2833 writel(val, (PRCM_A9PL_FORCE_CLKEN));
2834}
2835
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002836/*
2837 * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC
2838 */
2839static struct regulator_consumer_supply db8500_vape_consumers[] = {
2840 REGULATOR_SUPPLY("v-ape", NULL),
2841 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.0"),
2842 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.1"),
2843 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.2"),
2844 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.3"),
Lee Jonesae840632012-05-04 19:23:20 +01002845 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.4"),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002846 /* "v-mmc" changed to "vcore" in the mainline kernel */
2847 REGULATOR_SUPPLY("vcore", "sdi0"),
2848 REGULATOR_SUPPLY("vcore", "sdi1"),
2849 REGULATOR_SUPPLY("vcore", "sdi2"),
2850 REGULATOR_SUPPLY("vcore", "sdi3"),
2851 REGULATOR_SUPPLY("vcore", "sdi4"),
2852 REGULATOR_SUPPLY("v-dma", "dma40.0"),
2853 REGULATOR_SUPPLY("v-ape", "ab8500-usb.0"),
2854 /* "v-uart" changed to "vcore" in the mainline kernel */
2855 REGULATOR_SUPPLY("vcore", "uart0"),
2856 REGULATOR_SUPPLY("vcore", "uart1"),
2857 REGULATOR_SUPPLY("vcore", "uart2"),
2858 REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"),
Bengt Jonsson992b1332012-01-13 16:20:36 +01002859 REGULATOR_SUPPLY("v-hsi", "ste_hsi.0"),
Lee Jonesbc367482012-05-03 11:23:47 +01002860 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002861};
2862
2863static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002864 REGULATOR_SUPPLY("musb_1v8", "ab8500-usb.0"),
2865 /* AV8100 regulator */
2866 REGULATOR_SUPPLY("hdmi_1v8", "0-0070"),
2867};
2868
2869static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01002870 REGULATOR_SUPPLY("vsupply", "b2r2_bus"),
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002871 REGULATOR_SUPPLY("vsupply", "mcde"),
2872};
2873
2874/* SVA MMDSP regulator switch */
2875static struct regulator_consumer_supply db8500_svammdsp_consumers[] = {
2876 REGULATOR_SUPPLY("sva-mmdsp", "cm_control"),
2877};
2878
2879/* SVA pipe regulator switch */
2880static struct regulator_consumer_supply db8500_svapipe_consumers[] = {
2881 REGULATOR_SUPPLY("sva-pipe", "cm_control"),
2882};
2883
2884/* SIA MMDSP regulator switch */
2885static struct regulator_consumer_supply db8500_siammdsp_consumers[] = {
2886 REGULATOR_SUPPLY("sia-mmdsp", "cm_control"),
2887};
2888
2889/* SIA pipe regulator switch */
2890static struct regulator_consumer_supply db8500_siapipe_consumers[] = {
2891 REGULATOR_SUPPLY("sia-pipe", "cm_control"),
2892};
2893
2894static struct regulator_consumer_supply db8500_sga_consumers[] = {
2895 REGULATOR_SUPPLY("v-mali", NULL),
2896};
2897
2898/* ESRAM1 and 2 regulator switch */
2899static struct regulator_consumer_supply db8500_esram12_consumers[] = {
2900 REGULATOR_SUPPLY("esram12", "cm_control"),
2901};
2902
2903/* ESRAM3 and 4 regulator switch */
2904static struct regulator_consumer_supply db8500_esram34_consumers[] = {
2905 REGULATOR_SUPPLY("v-esram34", "mcde"),
2906 REGULATOR_SUPPLY("esram34", "cm_control"),
Bengt Jonsson992b1332012-01-13 16:20:36 +01002907 REGULATOR_SUPPLY("lcla_esram", "dma40.0"),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002908};
2909
2910static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
2911 [DB8500_REGULATOR_VAPE] = {
2912 .constraints = {
2913 .name = "db8500-vape",
2914 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
Mark Brown1e458602012-04-13 13:11:50 +01002915 .always_on = true,
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002916 },
2917 .consumer_supplies = db8500_vape_consumers,
2918 .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers),
2919 },
2920 [DB8500_REGULATOR_VARM] = {
2921 .constraints = {
2922 .name = "db8500-varm",
2923 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2924 },
2925 },
2926 [DB8500_REGULATOR_VMODEM] = {
2927 .constraints = {
2928 .name = "db8500-vmodem",
2929 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2930 },
2931 },
2932 [DB8500_REGULATOR_VPLL] = {
2933 .constraints = {
2934 .name = "db8500-vpll",
2935 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2936 },
2937 },
2938 [DB8500_REGULATOR_VSMPS1] = {
2939 .constraints = {
2940 .name = "db8500-vsmps1",
2941 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2942 },
2943 },
2944 [DB8500_REGULATOR_VSMPS2] = {
2945 .constraints = {
2946 .name = "db8500-vsmps2",
2947 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2948 },
2949 .consumer_supplies = db8500_vsmps2_consumers,
2950 .num_consumer_supplies = ARRAY_SIZE(db8500_vsmps2_consumers),
2951 },
2952 [DB8500_REGULATOR_VSMPS3] = {
2953 .constraints = {
2954 .name = "db8500-vsmps3",
2955 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2956 },
2957 },
2958 [DB8500_REGULATOR_VRF1] = {
2959 .constraints = {
2960 .name = "db8500-vrf1",
2961 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2962 },
2963 },
2964 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01002965 /* dependency to u8500-vape is handled outside regulator framework */
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002966 .constraints = {
2967 .name = "db8500-sva-mmdsp",
2968 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2969 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002970 .consumer_supplies = db8500_svammdsp_consumers,
2971 .num_consumer_supplies = ARRAY_SIZE(db8500_svammdsp_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002972 },
2973 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
2974 .constraints = {
2975 /* "ret" means "retention" */
2976 .name = "db8500-sva-mmdsp-ret",
2977 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2978 },
2979 },
2980 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01002981 /* dependency to u8500-vape is handled outside regulator framework */
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002982 .constraints = {
2983 .name = "db8500-sva-pipe",
2984 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2985 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002986 .consumer_supplies = db8500_svapipe_consumers,
2987 .num_consumer_supplies = ARRAY_SIZE(db8500_svapipe_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002988 },
2989 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01002990 /* dependency to u8500-vape is handled outside regulator framework */
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002991 .constraints = {
2992 .name = "db8500-sia-mmdsp",
2993 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2994 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002995 .consumer_supplies = db8500_siammdsp_consumers,
2996 .num_consumer_supplies = ARRAY_SIZE(db8500_siammdsp_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002997 },
2998 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
2999 .constraints = {
3000 .name = "db8500-sia-mmdsp-ret",
3001 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3002 },
3003 },
3004 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01003005 /* dependency to u8500-vape is handled outside regulator framework */
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003006 .constraints = {
3007 .name = "db8500-sia-pipe",
3008 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3009 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02003010 .consumer_supplies = db8500_siapipe_consumers,
3011 .num_consumer_supplies = ARRAY_SIZE(db8500_siapipe_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003012 },
3013 [DB8500_REGULATOR_SWITCH_SGA] = {
3014 .supply_regulator = "db8500-vape",
3015 .constraints = {
3016 .name = "db8500-sga",
3017 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3018 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02003019 .consumer_supplies = db8500_sga_consumers,
3020 .num_consumer_supplies = ARRAY_SIZE(db8500_sga_consumers),
3021
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003022 },
3023 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
3024 .supply_regulator = "db8500-vape",
3025 .constraints = {
3026 .name = "db8500-b2r2-mcde",
3027 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3028 },
3029 .consumer_supplies = db8500_b2r2_mcde_consumers,
3030 .num_consumer_supplies = ARRAY_SIZE(db8500_b2r2_mcde_consumers),
3031 },
3032 [DB8500_REGULATOR_SWITCH_ESRAM12] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01003033 /*
3034 * esram12 is set in retention and supplied by Vsafe when Vape is off,
3035 * no need to hold Vape
3036 */
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003037 .constraints = {
3038 .name = "db8500-esram12",
3039 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3040 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02003041 .consumer_supplies = db8500_esram12_consumers,
3042 .num_consumer_supplies = ARRAY_SIZE(db8500_esram12_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003043 },
3044 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
3045 .constraints = {
3046 .name = "db8500-esram12-ret",
3047 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3048 },
3049 },
3050 [DB8500_REGULATOR_SWITCH_ESRAM34] = {
Bengt Jonsson992b1332012-01-13 16:20:36 +01003051 /*
3052 * esram34 is set in retention and supplied by Vsafe when Vape is off,
3053 * no need to hold Vape
3054 */
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003055 .constraints = {
3056 .name = "db8500-esram34",
3057 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3058 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02003059 .consumer_supplies = db8500_esram34_consumers,
3060 .num_consumer_supplies = ARRAY_SIZE(db8500_esram34_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02003061 },
3062 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
3063 .constraints = {
3064 .name = "db8500-esram34-ret",
3065 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
3066 },
3067 },
3068};
3069
Lee Jones6d11d132012-06-29 17:13:35 +02003070static struct resource ab8500_resources[] = {
3071 [0] = {
3072 .start = IRQ_DB8500_AB8500,
3073 .end = IRQ_DB8500_AB8500,
3074 .flags = IORESOURCE_IRQ
3075 }
3076};
3077
Fabio Baltierib3aac622013-01-18 12:40:14 +01003078static struct ux500_wdt_data db8500_wdt_pdata = {
3079 .timeout = 600, /* 10 minutes */
3080 .has_28_bits_resolution = true,
3081};
3082
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003083static struct mfd_cell db8500_prcmu_devs[] = {
3084 {
3085 .name = "db8500-prcmu-regulators",
Lee Jones5d903222012-06-20 13:56:41 +01003086 .of_compatible = "stericsson,db8500-prcmu-regulator",
Mattias Wallin1ed78912011-05-27 11:49:43 +02003087 .platform_data = &db8500_regulators,
3088 .pdata_size = sizeof(db8500_regulators),
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003089 },
3090 {
3091 .name = "cpufreq-u8500",
Lee Jones5d903222012-06-20 13:56:41 +01003092 .of_compatible = "stericsson,cpufreq-u8500",
Ulf Hanssonc280f452012-10-10 13:42:23 +02003093 .platform_data = &db8500_cpufreq_table,
3094 .pdata_size = sizeof(db8500_cpufreq_table),
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003095 },
Lee Jones6d11d132012-06-29 17:13:35 +02003096 {
Fabio Baltierib3aac622013-01-18 12:40:14 +01003097 .name = "ux500_wdt",
3098 .platform_data = &db8500_wdt_pdata,
3099 .pdata_size = sizeof(db8500_wdt_pdata),
3100 .id = -1,
3101 },
3102 {
Lee Jones6d11d132012-06-29 17:13:35 +02003103 .name = "ab8500-core",
3104 .of_compatible = "stericsson,ab8500",
3105 .num_resources = ARRAY_SIZE(ab8500_resources),
3106 .resources = ab8500_resources,
3107 .id = AB8500_VERSION_AB8500,
3108 },
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003109};
3110
Ulf Hanssonc280f452012-10-10 13:42:23 +02003111static void db8500_prcmu_update_cpufreq(void)
3112{
3113 if (prcmu_has_arm_maxopp()) {
3114 db8500_cpufreq_table[3].frequency = 1000000;
3115 db8500_cpufreq_table[3].index = ARM_MAX_OPP;
3116 }
3117}
3118
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003119/**
3120 * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic
3121 *
3122 */
Bill Pembertonf791be42012-11-19 13:23:04 -05003123static int db8500_prcmu_probe(struct platform_device *pdev)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003124{
Lee Jones3a8e39c2012-07-06 12:46:23 +02003125 struct ab8500_platform_data *ab8500_platdata = pdev->dev.platform_data;
Lee Jonesca7edd12012-05-09 17:19:25 +02003126 struct device_node *np = pdev->dev.of_node;
Lee Jones3a8e39c2012-07-06 12:46:23 +02003127 int irq = 0, err = 0, i;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003128
3129 if (ux500_is_svp())
3130 return -ENODEV;
3131
Mattias Nilsson05089012012-01-13 16:20:20 +01003132 init_prcm_registers();
Mattias Nilssond65e12d2011-08-12 10:27:50 +02003133
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003134 /* Clean up the mailbox interrupts after pre-kernel code. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02003135 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003136
Lee Jonesca7edd12012-05-09 17:19:25 +02003137 if (np)
3138 irq = platform_get_irq(pdev, 0);
3139
3140 if (!np || irq <= 0)
3141 irq = IRQ_DB8500_PRCMU1;
3142
3143 err = request_threaded_irq(irq, prcmu_irq_handler,
3144 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003145 if (err < 0) {
3146 pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
3147 err = -EBUSY;
3148 goto no_irq_return;
3149 }
3150
Lee Jonesf3f1f0a2012-09-24 09:11:46 +01003151 db8500_irq_init(np);
3152
Lee Jones3a8e39c2012-07-06 12:46:23 +02003153 for (i = 0; i < ARRAY_SIZE(db8500_prcmu_devs); i++) {
3154 if (!strcmp(db8500_prcmu_devs[i].name, "ab8500-core")) {
3155 db8500_prcmu_devs[i].platform_data = ab8500_platdata;
Lee Jones3c1534c2012-07-27 13:38:50 +01003156 db8500_prcmu_devs[i].pdata_size = sizeof(struct ab8500_platform_data);
Lee Jones3a8e39c2012-07-06 12:46:23 +02003157 }
3158 }
3159
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003160 if (cpu_is_u8500v20_or_later())
3161 prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
3162
Ulf Hanssonc280f452012-10-10 13:42:23 +02003163 db8500_prcmu_update_cpufreq();
3164
Lee Jones5d903222012-06-20 13:56:41 +01003165 err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
Mark Brown0848c942012-09-11 15:16:36 +08003166 ARRAY_SIZE(db8500_prcmu_devs), NULL, 0, NULL);
Lee Jones5d903222012-06-20 13:56:41 +01003167 if (err) {
3168 pr_err("prcmu: Failed to add subdevices\n");
3169 return err;
Lee Jonesca7edd12012-05-09 17:19:25 +02003170 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003171
Lee Jonesca7edd12012-05-09 17:19:25 +02003172 pr_info("DB8500 PRCMU initialized\n");
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003173
3174no_irq_return:
3175 return err;
3176}
Lee Jones3c144762012-06-29 15:41:38 +02003177static const struct of_device_id db8500_prcmu_match[] = {
3178 { .compatible = "stericsson,db8500-prcmu"},
3179 { },
3180};
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003181
3182static struct platform_driver db8500_prcmu_driver = {
3183 .driver = {
3184 .name = "db8500-prcmu",
3185 .owner = THIS_MODULE,
Lee Jones3c144762012-06-29 15:41:38 +02003186 .of_match_table = db8500_prcmu_match,
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003187 },
Lee Jones9fc63f62012-04-19 21:36:41 +01003188 .probe = db8500_prcmu_probe,
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003189};
3190
3191static int __init db8500_prcmu_init(void)
3192{
Lee Jones9fc63f62012-04-19 21:36:41 +01003193 return platform_driver_register(&db8500_prcmu_driver);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003194}
3195
Lee Jonesa661aca2012-06-11 16:24:59 +01003196core_initcall(db8500_prcmu_init);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02003197
3198MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>");
3199MODULE_DESCRIPTION("DB8500 PRCM Unit driver");
3200MODULE_LICENSE("GPL v2");