blob: 5179abf94729d8af978f2a2b74666f63e36250d8 [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>
Bengt Jonsson1032fbf2011-04-01 14:43:33 +020031#include <linux/regulator/db8500-prcmu.h>
32#include <linux/regulator/machine.h>
Linus Walleije3726fc2010-08-19 12:36:01 +010033#include <mach/hardware.h>
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020034#include <mach/irqs.h>
35#include <mach/db8500-regs.h>
36#include <mach/id.h>
Mattias Nilsson73180f82011-08-12 10:28:10 +020037#include "dbx500-prcmu-regs.h"
Linus Walleije3726fc2010-08-19 12:36:01 +010038
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020039/* Offset for the firmware version within the TCPM */
40#define PRCMU_FW_VERSION_OFFSET 0xA4
Linus Walleije3726fc2010-08-19 12:36:01 +010041
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020042/* Index of different voltages to be used when accessing AVSData */
43#define PRCM_AVS_BASE 0x2FC
44#define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
45#define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
46#define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
47#define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
48#define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
49#define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
50#define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
51#define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
52#define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
53#define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
54#define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
55#define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
56#define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
Martin Perssone0befb22010-12-08 15:13:28 +010057
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020058#define PRCM_AVS_VOLTAGE 0
59#define PRCM_AVS_VOLTAGE_MASK 0x3f
60#define PRCM_AVS_ISSLOWSTARTUP 6
61#define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
Martin Perssone0befb22010-12-08 15:13:28 +010062#define PRCM_AVS_ISMODEENABLE 7
63#define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
64
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020065#define PRCM_BOOT_STATUS 0xFFF
66#define PRCM_ROMCODE_A2P 0xFFE
67#define PRCM_ROMCODE_P2A 0xFFD
68#define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */
Linus Walleije3726fc2010-08-19 12:36:01 +010069
Mattias Nilsson3df57bc2011-05-16 00:15:05 +020070#define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */
71
72#define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */
73#define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
74#define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
75#define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
76#define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
77#define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
78#define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
79#define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
80
81/* Req Mailboxes */
82#define PRCM_REQ_MB0 0xFDC /* 12 bytes */
83#define PRCM_REQ_MB1 0xFD0 /* 12 bytes */
84#define PRCM_REQ_MB2 0xFC0 /* 16 bytes */
85#define PRCM_REQ_MB3 0xE4C /* 372 bytes */
86#define PRCM_REQ_MB4 0xE48 /* 4 bytes */
87#define PRCM_REQ_MB5 0xE44 /* 4 bytes */
88
89/* Ack Mailboxes */
90#define PRCM_ACK_MB0 0xE08 /* 52 bytes */
91#define PRCM_ACK_MB1 0xE04 /* 4 bytes */
92#define PRCM_ACK_MB2 0xE00 /* 4 bytes */
93#define PRCM_ACK_MB3 0xDFC /* 4 bytes */
94#define PRCM_ACK_MB4 0xDF8 /* 4 bytes */
95#define PRCM_ACK_MB5 0xDF4 /* 4 bytes */
96
97/* Mailbox 0 headers */
98#define MB0H_POWER_STATE_TRANS 0
99#define MB0H_CONFIG_WAKEUPS_EXE 1
100#define MB0H_READ_WAKEUP_ACK 3
101#define MB0H_CONFIG_WAKEUPS_SLEEP 4
102
103#define MB0H_WAKEUP_EXE 2
104#define MB0H_WAKEUP_SLEEP 5
105
106/* Mailbox 0 REQs */
107#define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
108#define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
109#define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
110#define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
111#define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
112#define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
113
114/* Mailbox 0 ACKs */
115#define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
116#define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
117#define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
118#define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
119#define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
120#define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
121#define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
122
123/* Mailbox 1 headers */
124#define MB1H_ARM_APE_OPP 0x0
125#define MB1H_RESET_MODEM 0x2
126#define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
127#define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
128#define MB1H_RELEASE_USB_WAKEUP 0x5
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200129#define MB1H_PLL_ON_OFF 0x6
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200130
131/* Mailbox 1 Requests */
132#define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
133#define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200134#define PRCM_REQ_MB1_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4)
135#define PLL_SOC1_OFF 0x4
136#define PLL_SOC1_ON 0x8
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200137
138/* Mailbox 1 ACKs */
139#define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0)
140#define PRCM_ACK_MB1_CURRENT_APE_OPP (PRCM_ACK_MB1 + 0x1)
141#define PRCM_ACK_MB1_APE_VOLTAGE_STATUS (PRCM_ACK_MB1 + 0x2)
142#define PRCM_ACK_MB1_DVFS_STATUS (PRCM_ACK_MB1 + 0x3)
143
144/* Mailbox 2 headers */
145#define MB2H_DPS 0x0
146#define MB2H_AUTO_PWR 0x1
147
148/* Mailbox 2 REQs */
149#define PRCM_REQ_MB2_SVA_MMDSP (PRCM_REQ_MB2 + 0x0)
150#define PRCM_REQ_MB2_SVA_PIPE (PRCM_REQ_MB2 + 0x1)
151#define PRCM_REQ_MB2_SIA_MMDSP (PRCM_REQ_MB2 + 0x2)
152#define PRCM_REQ_MB2_SIA_PIPE (PRCM_REQ_MB2 + 0x3)
153#define PRCM_REQ_MB2_SGA (PRCM_REQ_MB2 + 0x4)
154#define PRCM_REQ_MB2_B2R2_MCDE (PRCM_REQ_MB2 + 0x5)
155#define PRCM_REQ_MB2_ESRAM12 (PRCM_REQ_MB2 + 0x6)
156#define PRCM_REQ_MB2_ESRAM34 (PRCM_REQ_MB2 + 0x7)
157#define PRCM_REQ_MB2_AUTO_PM_SLEEP (PRCM_REQ_MB2 + 0x8)
158#define PRCM_REQ_MB2_AUTO_PM_IDLE (PRCM_REQ_MB2 + 0xC)
159
160/* Mailbox 2 ACKs */
161#define PRCM_ACK_MB2_DPS_STATUS (PRCM_ACK_MB2 + 0x0)
162#define HWACC_PWR_ST_OK 0xFE
163
164/* Mailbox 3 headers */
165#define MB3H_ANC 0x0
166#define MB3H_SIDETONE 0x1
167#define MB3H_SYSCLK 0xE
168
169/* Mailbox 3 Requests */
170#define PRCM_REQ_MB3_ANC_FIR_COEFF (PRCM_REQ_MB3 + 0x0)
171#define PRCM_REQ_MB3_ANC_IIR_COEFF (PRCM_REQ_MB3 + 0x20)
172#define PRCM_REQ_MB3_ANC_SHIFTER (PRCM_REQ_MB3 + 0x60)
173#define PRCM_REQ_MB3_ANC_WARP (PRCM_REQ_MB3 + 0x64)
174#define PRCM_REQ_MB3_SIDETONE_FIR_GAIN (PRCM_REQ_MB3 + 0x68)
175#define PRCM_REQ_MB3_SIDETONE_FIR_COEFF (PRCM_REQ_MB3 + 0x6C)
176#define PRCM_REQ_MB3_SYSCLK_MGT (PRCM_REQ_MB3 + 0x16C)
177
178/* Mailbox 4 headers */
179#define MB4H_DDR_INIT 0x0
180#define MB4H_MEM_ST 0x1
181#define MB4H_HOTDOG 0x12
182#define MB4H_HOTMON 0x13
183#define MB4H_HOT_PERIOD 0x14
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200184#define MB4H_A9WDOG_CONF 0x16
185#define MB4H_A9WDOG_EN 0x17
186#define MB4H_A9WDOG_DIS 0x18
187#define MB4H_A9WDOG_LOAD 0x19
188#define MB4H_A9WDOG_KICK 0x20
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200189
190/* Mailbox 4 Requests */
191#define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
192#define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
193#define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
194#define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
195#define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
196#define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
197#define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
198#define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
199#define HOTMON_CONFIG_LOW BIT(0)
200#define HOTMON_CONFIG_HIGH BIT(1)
Mattias Nilssona592c2e2011-08-12 10:27:41 +0200201#define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0)
202#define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1)
203#define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2)
204#define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3)
205#define A9WDOG_AUTO_OFF_EN BIT(7)
206#define A9WDOG_AUTO_OFF_DIS 0
207#define A9WDOG_ID_MASK 0xf
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200208
209/* Mailbox 5 Requests */
210#define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
211#define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
212#define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
213#define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
214#define PRCMU_I2C_WRITE(slave) \
215 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0))
216#define PRCMU_I2C_READ(slave) \
217 (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0))
218#define PRCMU_I2C_STOP_EN BIT(3)
219
220/* Mailbox 5 ACKs */
221#define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
222#define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
223#define I2C_WR_OK 0x1
224#define I2C_RD_OK 0x2
225
226#define NUM_MB 8
227#define MBOX_BIT BIT
228#define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
229
230/*
231 * Wakeups/IRQs
232 */
233
234#define WAKEUP_BIT_RTC BIT(0)
235#define WAKEUP_BIT_RTT0 BIT(1)
236#define WAKEUP_BIT_RTT1 BIT(2)
237#define WAKEUP_BIT_HSI0 BIT(3)
238#define WAKEUP_BIT_HSI1 BIT(4)
239#define WAKEUP_BIT_CA_WAKE BIT(5)
240#define WAKEUP_BIT_USB BIT(6)
241#define WAKEUP_BIT_ABB BIT(7)
242#define WAKEUP_BIT_ABB_FIFO BIT(8)
243#define WAKEUP_BIT_SYSCLK_OK BIT(9)
244#define WAKEUP_BIT_CA_SLEEP BIT(10)
245#define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
246#define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
247#define WAKEUP_BIT_ANC_OK BIT(13)
248#define WAKEUP_BIT_SW_ERROR BIT(14)
249#define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
250#define WAKEUP_BIT_ARM BIT(17)
251#define WAKEUP_BIT_HOTMON_LOW BIT(18)
252#define WAKEUP_BIT_HOTMON_HIGH BIT(19)
253#define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
254#define WAKEUP_BIT_GPIO0 BIT(23)
255#define WAKEUP_BIT_GPIO1 BIT(24)
256#define WAKEUP_BIT_GPIO2 BIT(25)
257#define WAKEUP_BIT_GPIO3 BIT(26)
258#define WAKEUP_BIT_GPIO4 BIT(27)
259#define WAKEUP_BIT_GPIO5 BIT(28)
260#define WAKEUP_BIT_GPIO6 BIT(29)
261#define WAKEUP_BIT_GPIO7 BIT(30)
262#define WAKEUP_BIT_GPIO8 BIT(31)
263
Mattias Nilssonb58d12f2012-01-13 16:20:10 +0100264static struct {
265 bool valid;
266 struct prcmu_fw_version version;
267} fw_info;
268
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200269/*
270 * This vector maps irq numbers to the bits in the bit field used in
271 * communication with the PRCMU firmware.
272 *
273 * The reason for having this is to keep the irq numbers contiguous even though
274 * the bits in the bit field are not. (The bits also have a tendency to move
275 * around, to further complicate matters.)
276 */
277#define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE)
278#define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
279static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
280 IRQ_ENTRY(RTC),
281 IRQ_ENTRY(RTT0),
282 IRQ_ENTRY(RTT1),
283 IRQ_ENTRY(HSI0),
284 IRQ_ENTRY(HSI1),
285 IRQ_ENTRY(CA_WAKE),
286 IRQ_ENTRY(USB),
287 IRQ_ENTRY(ABB),
288 IRQ_ENTRY(ABB_FIFO),
289 IRQ_ENTRY(CA_SLEEP),
290 IRQ_ENTRY(ARM),
291 IRQ_ENTRY(HOTMON_LOW),
292 IRQ_ENTRY(HOTMON_HIGH),
293 IRQ_ENTRY(MODEM_SW_RESET_REQ),
294 IRQ_ENTRY(GPIO0),
295 IRQ_ENTRY(GPIO1),
296 IRQ_ENTRY(GPIO2),
297 IRQ_ENTRY(GPIO3),
298 IRQ_ENTRY(GPIO4),
299 IRQ_ENTRY(GPIO5),
300 IRQ_ENTRY(GPIO6),
301 IRQ_ENTRY(GPIO7),
302 IRQ_ENTRY(GPIO8)
Martin Perssone0befb22010-12-08 15:13:28 +0100303};
304
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200305#define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
306#define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
307static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = {
308 WAKEUP_ENTRY(RTC),
309 WAKEUP_ENTRY(RTT0),
310 WAKEUP_ENTRY(RTT1),
311 WAKEUP_ENTRY(HSI0),
312 WAKEUP_ENTRY(HSI1),
313 WAKEUP_ENTRY(USB),
314 WAKEUP_ENTRY(ABB),
315 WAKEUP_ENTRY(ABB_FIFO),
316 WAKEUP_ENTRY(ARM)
317};
318
319/*
320 * mb0_transfer - state needed for mailbox 0 communication.
321 * @lock: The transaction lock.
322 * @dbb_events_lock: A lock used to handle concurrent access to (parts of)
323 * the request data.
324 * @mask_work: Work structure used for (un)masking wakeup interrupts.
325 * @req: Request data that need to persist between requests.
326 */
327static struct {
328 spinlock_t lock;
329 spinlock_t dbb_irqs_lock;
330 struct work_struct mask_work;
331 struct mutex ac_wake_lock;
332 struct completion ac_wake_work;
333 struct {
334 u32 dbb_irqs;
335 u32 dbb_wakeups;
336 u32 abb_events;
337 } req;
338} mb0_transfer;
339
340/*
341 * mb1_transfer - state needed for mailbox 1 communication.
342 * @lock: The transaction lock.
343 * @work: The transaction completion structure.
344 * @ack: Reply ("acknowledge") data.
345 */
Martin Perssone0befb22010-12-08 15:13:28 +0100346static struct {
347 struct mutex lock;
348 struct completion work;
349 struct {
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200350 u8 header;
Martin Perssone0befb22010-12-08 15:13:28 +0100351 u8 arm_opp;
352 u8 ape_opp;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200353 u8 ape_voltage_status;
Martin Perssone0befb22010-12-08 15:13:28 +0100354 } ack;
355} mb1_transfer;
356
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200357/*
358 * mb2_transfer - state needed for mailbox 2 communication.
359 * @lock: The transaction lock.
360 * @work: The transaction completion structure.
361 * @auto_pm_lock: The autonomous power management configuration lock.
362 * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled.
363 * @req: Request data that need to persist between requests.
364 * @ack: Reply ("acknowledge") data.
365 */
Linus Walleije3726fc2010-08-19 12:36:01 +0100366static struct {
367 struct mutex lock;
368 struct completion work;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200369 spinlock_t auto_pm_lock;
370 bool auto_pm_enabled;
371 struct {
372 u8 status;
373 } ack;
374} mb2_transfer;
375
376/*
377 * mb3_transfer - state needed for mailbox 3 communication.
378 * @lock: The request lock.
379 * @sysclk_lock: A lock used to handle concurrent sysclk requests.
380 * @sysclk_work: Work structure used for sysclk requests.
381 */
382static struct {
383 spinlock_t lock;
384 struct mutex sysclk_lock;
385 struct completion sysclk_work;
386} mb3_transfer;
387
388/*
389 * mb4_transfer - state needed for mailbox 4 communication.
390 * @lock: The transaction lock.
391 * @work: The transaction completion structure.
392 */
393static struct {
394 struct mutex lock;
395 struct completion work;
396} mb4_transfer;
397
398/*
399 * mb5_transfer - state needed for mailbox 5 communication.
400 * @lock: The transaction lock.
401 * @work: The transaction completion structure.
402 * @ack: Reply ("acknowledge") data.
403 */
404static struct {
405 struct mutex lock;
406 struct completion work;
Linus Walleije3726fc2010-08-19 12:36:01 +0100407 struct {
408 u8 status;
409 u8 value;
410 } ack;
411} mb5_transfer;
412
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200413static atomic_t ac_wake_req_state = ATOMIC_INIT(0);
414
415/* Spinlocks */
416static DEFINE_SPINLOCK(clkout_lock);
417static DEFINE_SPINLOCK(gpiocr_lock);
418
419/* Global var to runtime determine TCDM base for v2 or v1 */
420static __iomem void *tcdm_base;
421
422struct clk_mgt {
423 unsigned int offset;
424 u32 pllsw;
425};
426
427static DEFINE_SPINLOCK(clk_mgt_lock);
428
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200429#define CLK_MGT_ENTRY(_name)[PRCMU_##_name] = { (PRCM_##_name##_MGT_OFF), 0 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200430struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
431 CLK_MGT_ENTRY(SGACLK),
432 CLK_MGT_ENTRY(UARTCLK),
433 CLK_MGT_ENTRY(MSP02CLK),
434 CLK_MGT_ENTRY(MSP1CLK),
435 CLK_MGT_ENTRY(I2CCLK),
436 CLK_MGT_ENTRY(SDMMCCLK),
437 CLK_MGT_ENTRY(SLIMCLK),
438 CLK_MGT_ENTRY(PER1CLK),
439 CLK_MGT_ENTRY(PER2CLK),
440 CLK_MGT_ENTRY(PER3CLK),
441 CLK_MGT_ENTRY(PER5CLK),
442 CLK_MGT_ENTRY(PER6CLK),
443 CLK_MGT_ENTRY(PER7CLK),
444 CLK_MGT_ENTRY(LCDCLK),
445 CLK_MGT_ENTRY(BMLCLK),
446 CLK_MGT_ENTRY(HSITXCLK),
447 CLK_MGT_ENTRY(HSIRXCLK),
448 CLK_MGT_ENTRY(HDMICLK),
449 CLK_MGT_ENTRY(APEATCLK),
450 CLK_MGT_ENTRY(APETRACECLK),
451 CLK_MGT_ENTRY(MCDECLK),
452 CLK_MGT_ENTRY(IPI2CCLK),
453 CLK_MGT_ENTRY(DSIALTCLK),
454 CLK_MGT_ENTRY(DMACLK),
455 CLK_MGT_ENTRY(B2R2CLK),
456 CLK_MGT_ENTRY(TVCLK),
457 CLK_MGT_ENTRY(SSPCLK),
458 CLK_MGT_ENTRY(RNGCLK),
459 CLK_MGT_ENTRY(UICCCLK),
460};
461
Mattias Nilsson0837bb72011-08-12 10:28:18 +0200462static struct regulator *hwacc_regulator[NUM_HW_ACC];
463static struct regulator *hwacc_ret_regulator[NUM_HW_ACC];
464
465static bool hwacc_enabled[NUM_HW_ACC];
466static bool hwacc_ret_enabled[NUM_HW_ACC];
467
468static const char *hwacc_regulator_name[NUM_HW_ACC] = {
469 [HW_ACC_SVAMMDSP] = "hwacc-sva-mmdsp",
470 [HW_ACC_SVAPIPE] = "hwacc-sva-pipe",
471 [HW_ACC_SIAMMDSP] = "hwacc-sia-mmdsp",
472 [HW_ACC_SIAPIPE] = "hwacc-sia-pipe",
473 [HW_ACC_SGA] = "hwacc-sga",
474 [HW_ACC_B2R2] = "hwacc-b2r2",
475 [HW_ACC_MCDE] = "hwacc-mcde",
476 [HW_ACC_ESRAM1] = "hwacc-esram1",
477 [HW_ACC_ESRAM2] = "hwacc-esram2",
478 [HW_ACC_ESRAM3] = "hwacc-esram3",
479 [HW_ACC_ESRAM4] = "hwacc-esram4",
480};
481
482static const char *hwacc_ret_regulator_name[NUM_HW_ACC] = {
483 [HW_ACC_SVAMMDSP] = "hwacc-sva-mmdsp-ret",
484 [HW_ACC_SIAMMDSP] = "hwacc-sia-mmdsp-ret",
485 [HW_ACC_ESRAM1] = "hwacc-esram1-ret",
486 [HW_ACC_ESRAM2] = "hwacc-esram2-ret",
487 [HW_ACC_ESRAM3] = "hwacc-esram3-ret",
488 [HW_ACC_ESRAM4] = "hwacc-esram4-ret",
489};
490
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200491/*
492* Used by MCDE to setup all necessary PRCMU registers
493*/
494#define PRCMU_RESET_DSIPLL 0x00004000
495#define PRCMU_UNCLAMP_DSIPLL 0x00400800
496
497#define PRCMU_CLK_PLL_DIV_SHIFT 0
498#define PRCMU_CLK_PLL_SW_SHIFT 5
499#define PRCMU_CLK_38 (1 << 9)
500#define PRCMU_CLK_38_SRC (1 << 10)
501#define PRCMU_CLK_38_DIV (1 << 11)
502
503/* PLLDIV=12, PLLSW=4 (PLLDDR) */
504#define PRCMU_DSI_CLOCK_SETTING 0x0000008C
505
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200506/* DPI 50000000 Hz */
507#define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
508 (16 << PRCMU_CLK_PLL_DIV_SHIFT))
509#define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
510
511/* D=101, N=1, R=4, SELDIV2=0 */
512#define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
513
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200514#define PRCMU_ENABLE_PLLDSI 0x00000001
515#define PRCMU_DISABLE_PLLDSI 0x00000000
516#define PRCMU_RELEASE_RESET_DSS 0x0000400C
517#define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
518/* ESC clk, div0=1, div1=1, div2=3 */
519#define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
520#define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
521#define PRCMU_DSI_RESET_SW 0x00000007
522
523#define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
524
Mattias Nilsson73180f82011-08-12 10:28:10 +0200525int db8500_prcmu_enable_dsipll(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200526{
527 int i;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200528
529 /* Clear DSIPLL_RESETN */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200530 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200531 /* Unclamp DSIPLL in/out */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200532 writel(PRCMU_UNCLAMP_DSIPLL, PRCM_MMIP_LS_CLAMP_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200533
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200534 /* Set DSI PLL FREQ */
Daniel Willerudc72fe852012-01-13 16:20:03 +0100535 writel(PRCMU_PLLDSI_FREQ_SETTING, PRCM_PLLDSI_FREQ);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200536 writel(PRCMU_DSI_PLLOUT_SEL_SETTING, PRCM_DSI_PLLOUT_SEL);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200537 /* Enable Escape clocks */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200538 writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200539
540 /* Start DSI PLL */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200541 writel(PRCMU_ENABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200542 /* Reset DSI PLL */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200543 writel(PRCMU_DSI_RESET_SW, PRCM_DSI_SW_RESET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200544 for (i = 0; i < 10; i++) {
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200545 if ((readl(PRCM_PLLDSI_LOCKP) & PRCMU_PLLDSI_LOCKP_LOCKED)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200546 == PRCMU_PLLDSI_LOCKP_LOCKED)
547 break;
548 udelay(100);
549 }
550 /* Set DSIPLL_RESETN */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200551 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200552 return 0;
553}
554
Mattias Nilsson73180f82011-08-12 10:28:10 +0200555int db8500_prcmu_disable_dsipll(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200556{
557 /* Disable dsi pll */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200558 writel(PRCMU_DISABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200559 /* Disable escapeclock */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200560 writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200561 return 0;
562}
563
Mattias Nilsson73180f82011-08-12 10:28:10 +0200564int db8500_prcmu_set_display_clocks(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200565{
566 unsigned long flags;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200567
568 spin_lock_irqsave(&clk_mgt_lock, flags);
569
570 /* Grab the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200571 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200572 cpu_relax();
573
Daniel Willerudc72fe852012-01-13 16:20:03 +0100574 writel(PRCMU_DSI_CLOCK_SETTING, PRCM_HDMICLK_MGT);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200575 writel(PRCMU_DSI_LP_CLOCK_SETTING, PRCM_TVCLK_MGT);
576 writel(PRCMU_DPI_CLOCK_SETTING, PRCM_LCDCLK_MGT);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200577
578 /* Release the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200579 writel(0, PRCM_SEM);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200580
581 spin_unlock_irqrestore(&clk_mgt_lock, flags);
582
583 return 0;
584}
585
586/**
587 * prcmu_enable_spi2 - Enables pin muxing for SPI2 on OtherAlternateC1.
588 */
589void prcmu_enable_spi2(void)
590{
591 u32 reg;
592 unsigned long flags;
593
594 spin_lock_irqsave(&gpiocr_lock, flags);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200595 reg = readl(PRCM_GPIOCR);
596 writel(reg | PRCM_GPIOCR_SPI2_SELECT, PRCM_GPIOCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200597 spin_unlock_irqrestore(&gpiocr_lock, flags);
598}
599
600/**
601 * prcmu_disable_spi2 - Disables pin muxing for SPI2 on OtherAlternateC1.
602 */
603void prcmu_disable_spi2(void)
604{
605 u32 reg;
606 unsigned long flags;
607
608 spin_lock_irqsave(&gpiocr_lock, flags);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200609 reg = readl(PRCM_GPIOCR);
610 writel(reg & ~PRCM_GPIOCR_SPI2_SELECT, PRCM_GPIOCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200611 spin_unlock_irqrestore(&gpiocr_lock, flags);
612}
613
Mattias Nilssonb58d12f2012-01-13 16:20:10 +0100614struct prcmu_fw_version *prcmu_get_fw_version(void)
615{
616 return fw_info.valid ? &fw_info.version : NULL;
617}
618
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200619bool prcmu_has_arm_maxopp(void)
620{
621 return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) &
622 PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK;
623}
624
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200625/**
626 * prcmu_get_boot_status - PRCMU boot status checking
627 * Returns: the current PRCMU boot status
628 */
629int prcmu_get_boot_status(void)
630{
631 return readb(tcdm_base + PRCM_BOOT_STATUS);
632}
633
634/**
635 * prcmu_set_rc_a2p - This function is used to run few power state sequences
636 * @val: Value to be set, i.e. transition requested
637 * Returns: 0 on success, -EINVAL on invalid argument
638 *
639 * This function is used to run the following power state sequences -
640 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
641 */
642int prcmu_set_rc_a2p(enum romcode_write val)
643{
644 if (val < RDY_2_DS || val > RDY_2_XP70_RST)
645 return -EINVAL;
646 writeb(val, (tcdm_base + PRCM_ROMCODE_A2P));
647 return 0;
648}
649
650/**
651 * prcmu_get_rc_p2a - This function is used to get power state sequences
652 * Returns: the power transition that has last happened
653 *
654 * This function can return the following transitions-
655 * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
656 */
657enum romcode_read prcmu_get_rc_p2a(void)
658{
659 return readb(tcdm_base + PRCM_ROMCODE_P2A);
660}
661
662/**
663 * prcmu_get_current_mode - Return the current XP70 power mode
664 * Returns: Returns the current AP(ARM) power mode: init,
665 * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset
666 */
667enum ap_pwrst prcmu_get_xp70_current_state(void)
668{
669 return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE);
670}
671
672/**
673 * prcmu_config_clkout - Configure one of the programmable clock outputs.
674 * @clkout: The CLKOUT number (0 or 1).
675 * @source: The clock to be used (one of the PRCMU_CLKSRC_*).
676 * @div: The divider to be applied.
677 *
678 * Configures one of the programmable clock outputs (CLKOUTs).
679 * @div should be in the range [1,63] to request a configuration, or 0 to
680 * inform that the configuration is no longer requested.
681 */
682int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
683{
684 static int requests[2];
685 int r = 0;
686 unsigned long flags;
687 u32 val;
688 u32 bits;
689 u32 mask;
690 u32 div_mask;
691
692 BUG_ON(clkout > 1);
693 BUG_ON(div > 63);
694 BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009));
695
696 if (!div && !requests[clkout])
697 return -EINVAL;
698
699 switch (clkout) {
700 case 0:
701 div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
702 mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
703 bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
704 (div << PRCM_CLKOCR_CLKODIV0_SHIFT));
705 break;
706 case 1:
707 div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
708 mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
709 PRCM_CLKOCR_CLK1TYPE);
710 bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
711 (div << PRCM_CLKOCR_CLKODIV1_SHIFT));
712 break;
713 }
714 bits &= mask;
715
716 spin_lock_irqsave(&clkout_lock, flags);
717
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200718 val = readl(PRCM_CLKOCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200719 if (val & div_mask) {
720 if (div) {
721 if ((val & mask) != bits) {
722 r = -EBUSY;
723 goto unlock_and_return;
724 }
725 } else {
726 if ((val & mask & ~div_mask) != bits) {
727 r = -EINVAL;
728 goto unlock_and_return;
729 }
730 }
731 }
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200732 writel((bits | (val & ~mask)), PRCM_CLKOCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200733 requests[clkout] += (div ? 1 : -1);
734
735unlock_and_return:
736 spin_unlock_irqrestore(&clkout_lock, flags);
737
738 return r;
739}
740
Mattias Nilsson73180f82011-08-12 10:28:10 +0200741int db8500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200742{
743 unsigned long flags;
744
745 BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state));
746
747 spin_lock_irqsave(&mb0_transfer.lock, flags);
748
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200749 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200750 cpu_relax();
751
752 writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
753 writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE));
754 writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE));
755 writeb((keep_ulp_clk ? 1 : 0),
756 (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
757 writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200758 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200759
760 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
761
762 return 0;
763}
764
765/* This function should only be called while mb0_transfer.lock is held. */
766static void config_wakeups(void)
767{
768 const u8 header[2] = {
769 MB0H_CONFIG_WAKEUPS_EXE,
770 MB0H_CONFIG_WAKEUPS_SLEEP
771 };
772 static u32 last_dbb_events;
773 static u32 last_abb_events;
774 u32 dbb_events;
775 u32 abb_events;
776 unsigned int i;
777
778 dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
779 dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK);
780
781 abb_events = mb0_transfer.req.abb_events;
782
783 if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
784 return;
785
786 for (i = 0; i < 2; i++) {
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200787 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200788 cpu_relax();
789 writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
790 writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
791 writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200792 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200793 }
794 last_dbb_events = dbb_events;
795 last_abb_events = abb_events;
796}
797
Mattias Nilsson73180f82011-08-12 10:28:10 +0200798void db8500_prcmu_enable_wakeups(u32 wakeups)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200799{
800 unsigned long flags;
801 u32 bits;
802 int i;
803
804 BUG_ON(wakeups != (wakeups & VALID_WAKEUPS));
805
806 for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) {
807 if (wakeups & BIT(i))
808 bits |= prcmu_wakeup_bit[i];
809 }
810
811 spin_lock_irqsave(&mb0_transfer.lock, flags);
812
813 mb0_transfer.req.dbb_wakeups = bits;
814 config_wakeups();
815
816 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
817}
818
Mattias Nilsson73180f82011-08-12 10:28:10 +0200819void db8500_prcmu_config_abb_event_readout(u32 abb_events)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200820{
821 unsigned long flags;
822
823 spin_lock_irqsave(&mb0_transfer.lock, flags);
824
825 mb0_transfer.req.abb_events = abb_events;
826 config_wakeups();
827
828 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
829}
830
Mattias Nilsson73180f82011-08-12 10:28:10 +0200831void db8500_prcmu_get_abb_event_buffer(void __iomem **buf)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200832{
833 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
834 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
835 else
836 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500);
837}
838
839/**
Mattias Nilsson73180f82011-08-12 10:28:10 +0200840 * db8500_prcmu_set_arm_opp - set the appropriate ARM OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200841 * @opp: The new ARM operating point to which transition is to be made
842 * Returns: 0 on success, non-zero on failure
843 *
844 * This function sets the the operating point of the ARM.
845 */
Mattias Nilsson73180f82011-08-12 10:28:10 +0200846int db8500_prcmu_set_arm_opp(u8 opp)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200847{
848 int r;
849
850 if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK)
851 return -EINVAL;
852
853 r = 0;
854
855 mutex_lock(&mb1_transfer.lock);
856
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200857 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200858 cpu_relax();
859
860 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
861 writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
862 writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
863
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200864 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200865 wait_for_completion(&mb1_transfer.work);
866
867 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
868 (mb1_transfer.ack.arm_opp != opp))
869 r = -EIO;
870
871 mutex_unlock(&mb1_transfer.lock);
872
873 return r;
874}
875
876/**
Mattias Nilsson73180f82011-08-12 10:28:10 +0200877 * db8500_prcmu_get_arm_opp - get the current ARM OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200878 *
879 * Returns: the current ARM OPP
880 */
Mattias Nilsson73180f82011-08-12 10:28:10 +0200881int db8500_prcmu_get_arm_opp(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200882{
883 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
884}
885
886/**
Mattias Nilsson05089012012-01-13 16:20:20 +0100887 * db8500_prcmu_get_ddr_opp - get the current DDR OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200888 *
889 * Returns: the current DDR OPP
890 */
Mattias Nilsson05089012012-01-13 16:20:20 +0100891int db8500_prcmu_get_ddr_opp(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200892{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200893 return readb(PRCM_DDR_SUBSYS_APE_MINBW);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200894}
895
896/**
Mattias Nilsson05089012012-01-13 16:20:20 +0100897 * db8500_set_ddr_opp - set the appropriate DDR OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200898 * @opp: The new DDR operating point to which transition is to be made
899 * Returns: 0 on success, non-zero on failure
900 *
901 * This function sets the operating point of the DDR.
902 */
Mattias Nilsson05089012012-01-13 16:20:20 +0100903int db8500_prcmu_set_ddr_opp(u8 opp)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200904{
905 if (opp < DDR_100_OPP || opp > DDR_25_OPP)
906 return -EINVAL;
907 /* Changing the DDR OPP can hang the hardware pre-v21 */
908 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200909 writeb(opp, PRCM_DDR_SUBSYS_APE_MINBW);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200910
911 return 0;
912}
913/**
Mattias Nilsson05089012012-01-13 16:20:20 +0100914 * db8500_set_ape_opp - set the appropriate APE OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200915 * @opp: The new APE operating point to which transition is to be made
916 * Returns: 0 on success, non-zero on failure
917 *
918 * This function sets the operating point of the APE.
919 */
Mattias Nilsson05089012012-01-13 16:20:20 +0100920int db8500_prcmu_set_ape_opp(u8 opp)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200921{
922 int r = 0;
923
924 mutex_lock(&mb1_transfer.lock);
925
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200926 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200927 cpu_relax();
928
929 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
930 writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
931 writeb(opp, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
932
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200933 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200934 wait_for_completion(&mb1_transfer.work);
935
936 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
937 (mb1_transfer.ack.ape_opp != opp))
938 r = -EIO;
939
940 mutex_unlock(&mb1_transfer.lock);
941
942 return r;
943}
944
945/**
Mattias Nilsson05089012012-01-13 16:20:20 +0100946 * db8500_prcmu_get_ape_opp - get the current APE OPP
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200947 *
948 * Returns: the current APE OPP
949 */
Mattias Nilsson05089012012-01-13 16:20:20 +0100950int db8500_prcmu_get_ape_opp(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200951{
952 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP);
953}
954
955/**
956 * prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage
957 * @enable: true to request the higher voltage, false to drop a request.
958 *
959 * Calls to this function to enable and disable requests must be balanced.
960 */
961int prcmu_request_ape_opp_100_voltage(bool enable)
962{
963 int r = 0;
964 u8 header;
965 static unsigned int requests;
966
967 mutex_lock(&mb1_transfer.lock);
968
969 if (enable) {
970 if (0 != requests++)
971 goto unlock_and_return;
972 header = MB1H_REQUEST_APE_OPP_100_VOLT;
973 } else {
974 if (requests == 0) {
975 r = -EIO;
976 goto unlock_and_return;
977 } else if (1 != requests--) {
978 goto unlock_and_return;
979 }
980 header = MB1H_RELEASE_APE_OPP_100_VOLT;
981 }
982
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200983 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200984 cpu_relax();
985
986 writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
987
Mattias Nilssonc553b3c2011-08-12 10:27:20 +0200988 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +0200989 wait_for_completion(&mb1_transfer.work);
990
991 if ((mb1_transfer.ack.header != header) ||
992 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
993 r = -EIO;
994
995unlock_and_return:
996 mutex_unlock(&mb1_transfer.lock);
997
998 return r;
999}
1000
1001/**
1002 * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup
1003 *
1004 * This function releases the power state requirements of a USB wakeup.
1005 */
1006int prcmu_release_usb_wakeup_state(void)
1007{
1008 int r = 0;
1009
1010 mutex_lock(&mb1_transfer.lock);
1011
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001012 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001013 cpu_relax();
1014
1015 writeb(MB1H_RELEASE_USB_WAKEUP,
1016 (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1017
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001018 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001019 wait_for_completion(&mb1_transfer.work);
1020
1021 if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
1022 ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
1023 r = -EIO;
1024
1025 mutex_unlock(&mb1_transfer.lock);
1026
1027 return r;
1028}
1029
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001030static int request_pll(u8 clock, bool enable)
1031{
1032 int r = 0;
1033
1034 if (clock == PRCMU_PLLSOC1)
1035 clock = (enable ? PLL_SOC1_ON : PLL_SOC1_OFF);
1036 else
1037 return -EINVAL;
1038
1039 mutex_lock(&mb1_transfer.lock);
1040
1041 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1042 cpu_relax();
1043
1044 writeb(MB1H_PLL_ON_OFF, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1045 writeb(clock, (tcdm_base + PRCM_REQ_MB1_PLL_ON_OFF));
1046
1047 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1048 wait_for_completion(&mb1_transfer.work);
1049
1050 if (mb1_transfer.ack.header != MB1H_PLL_ON_OFF)
1051 r = -EIO;
1052
1053 mutex_unlock(&mb1_transfer.lock);
1054
1055 return r;
1056}
1057
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001058/**
Bengt Jonsson0b9199e2011-08-12 10:28:25 +02001059 * prcmu_set_hwacc - set the power state of a h/w accelerator
1060 * @hwacc_dev: The hardware accelerator (enum hw_acc_dev).
1061 * @state: The new power state (enum hw_acc_state).
1062 *
1063 * This function sets the power state of a hardware accelerator.
1064 * This function should not be called from interrupt context.
1065 *
1066 * NOTE! Deprecated, to be removed when all users switched over to use the
1067 * regulator framework API.
1068 */
1069int prcmu_set_hwacc(u16 hwacc_dev, u8 state)
1070{
1071 int r = 0;
1072 bool ram_retention = false;
1073 bool enable, enable_ret;
1074
1075 /* check argument */
1076 BUG_ON(hwacc_dev >= NUM_HW_ACC);
1077
1078 /* get state of switches */
1079 enable = hwacc_enabled[hwacc_dev];
1080 enable_ret = hwacc_ret_enabled[hwacc_dev];
1081
1082 /* set flag if retention is possible */
1083 switch (hwacc_dev) {
1084 case HW_ACC_SVAMMDSP:
1085 case HW_ACC_SIAMMDSP:
1086 case HW_ACC_ESRAM1:
1087 case HW_ACC_ESRAM2:
1088 case HW_ACC_ESRAM3:
1089 case HW_ACC_ESRAM4:
1090 ram_retention = true;
1091 break;
1092 }
1093
1094 /* check argument */
1095 BUG_ON(state > HW_ON);
1096 BUG_ON(state == HW_OFF_RAMRET && !ram_retention);
1097
1098 /* modify enable flags */
1099 switch (state) {
1100 case HW_OFF:
1101 enable_ret = false;
1102 enable = false;
1103 break;
1104 case HW_ON:
1105 enable = true;
1106 break;
1107 case HW_OFF_RAMRET:
1108 enable_ret = true;
1109 enable = false;
1110 break;
1111 }
1112
1113 /* get regulator (lazy) */
1114 if (hwacc_regulator[hwacc_dev] == NULL) {
1115 hwacc_regulator[hwacc_dev] = regulator_get(NULL,
1116 hwacc_regulator_name[hwacc_dev]);
1117 if (IS_ERR(hwacc_regulator[hwacc_dev])) {
1118 pr_err("prcmu: failed to get supply %s\n",
1119 hwacc_regulator_name[hwacc_dev]);
1120 r = PTR_ERR(hwacc_regulator[hwacc_dev]);
1121 goto out;
1122 }
1123 }
1124
1125 if (ram_retention) {
1126 if (hwacc_ret_regulator[hwacc_dev] == NULL) {
1127 hwacc_ret_regulator[hwacc_dev] = regulator_get(NULL,
1128 hwacc_ret_regulator_name[hwacc_dev]);
1129 if (IS_ERR(hwacc_ret_regulator[hwacc_dev])) {
1130 pr_err("prcmu: failed to get supply %s\n",
1131 hwacc_ret_regulator_name[hwacc_dev]);
1132 r = PTR_ERR(hwacc_ret_regulator[hwacc_dev]);
1133 goto out;
1134 }
1135 }
1136 }
1137
1138 /* set regulators */
1139 if (ram_retention) {
1140 if (enable_ret && !hwacc_ret_enabled[hwacc_dev]) {
1141 r = regulator_enable(hwacc_ret_regulator[hwacc_dev]);
1142 if (r < 0) {
1143 pr_err("prcmu_set_hwacc: ret enable failed\n");
1144 goto out;
1145 }
1146 hwacc_ret_enabled[hwacc_dev] = true;
1147 }
1148 }
1149
1150 if (enable && !hwacc_enabled[hwacc_dev]) {
1151 r = regulator_enable(hwacc_regulator[hwacc_dev]);
1152 if (r < 0) {
1153 pr_err("prcmu_set_hwacc: enable failed\n");
1154 goto out;
1155 }
1156 hwacc_enabled[hwacc_dev] = true;
1157 }
1158
1159 if (!enable && hwacc_enabled[hwacc_dev]) {
1160 r = regulator_disable(hwacc_regulator[hwacc_dev]);
1161 if (r < 0) {
1162 pr_err("prcmu_set_hwacc: disable failed\n");
1163 goto out;
1164 }
1165 hwacc_enabled[hwacc_dev] = false;
1166 }
1167
1168 if (ram_retention) {
1169 if (!enable_ret && hwacc_ret_enabled[hwacc_dev]) {
1170 r = regulator_disable(hwacc_ret_regulator[hwacc_dev]);
1171 if (r < 0) {
1172 pr_err("prcmu_set_hwacc: ret disable failed\n");
1173 goto out;
1174 }
1175 hwacc_ret_enabled[hwacc_dev] = false;
1176 }
1177 }
1178
1179out:
1180 return r;
1181}
1182EXPORT_SYMBOL(prcmu_set_hwacc);
1183
1184/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02001185 * db8500_prcmu_set_epod - set the state of a EPOD (power domain)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001186 * @epod_id: The EPOD to set
1187 * @epod_state: The new EPOD state
1188 *
1189 * This function sets the state of a EPOD (power domain). It may not be called
1190 * from interrupt context.
1191 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02001192int db8500_prcmu_set_epod(u16 epod_id, u8 epod_state)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001193{
1194 int r = 0;
1195 bool ram_retention = false;
1196 int i;
1197
1198 /* check argument */
1199 BUG_ON(epod_id >= NUM_EPOD_ID);
1200
1201 /* set flag if retention is possible */
1202 switch (epod_id) {
1203 case EPOD_ID_SVAMMDSP:
1204 case EPOD_ID_SIAMMDSP:
1205 case EPOD_ID_ESRAM12:
1206 case EPOD_ID_ESRAM34:
1207 ram_retention = true;
1208 break;
1209 }
1210
1211 /* check argument */
1212 BUG_ON(epod_state > EPOD_STATE_ON);
1213 BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention);
1214
1215 /* get lock */
1216 mutex_lock(&mb2_transfer.lock);
1217
1218 /* wait for mailbox */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001219 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001220 cpu_relax();
1221
1222 /* fill in mailbox */
1223 for (i = 0; i < NUM_EPOD_ID; i++)
1224 writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i));
1225 writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id));
1226
1227 writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
1228
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001229 writel(MBOX_BIT(2), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001230
1231 /*
1232 * The current firmware version does not handle errors correctly,
1233 * and we cannot recover if there is an error.
1234 * This is expected to change when the firmware is updated.
1235 */
1236 if (!wait_for_completion_timeout(&mb2_transfer.work,
1237 msecs_to_jiffies(20000))) {
1238 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1239 __func__);
1240 r = -EIO;
1241 goto unlock_and_return;
1242 }
1243
1244 if (mb2_transfer.ack.status != HWACC_PWR_ST_OK)
1245 r = -EIO;
1246
1247unlock_and_return:
1248 mutex_unlock(&mb2_transfer.lock);
1249 return r;
1250}
1251
1252/**
1253 * prcmu_configure_auto_pm - Configure autonomous power management.
1254 * @sleep: Configuration for ApSleep.
1255 * @idle: Configuration for ApIdle.
1256 */
1257void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
1258 struct prcmu_auto_pm_config *idle)
1259{
1260 u32 sleep_cfg;
1261 u32 idle_cfg;
1262 unsigned long flags;
1263
1264 BUG_ON((sleep == NULL) || (idle == NULL));
1265
1266 sleep_cfg = (sleep->sva_auto_pm_enable & 0xF);
1267 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF));
1268 sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF));
1269 sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF));
1270 sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF));
1271 sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF));
1272
1273 idle_cfg = (idle->sva_auto_pm_enable & 0xF);
1274 idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF));
1275 idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF));
1276 idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF));
1277 idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF));
1278 idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF));
1279
1280 spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags);
1281
1282 /*
1283 * The autonomous power management configuration is done through
1284 * fields in mailbox 2, but these fields are only used as shared
1285 * variables - i.e. there is no need to send a message.
1286 */
1287 writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP));
1288 writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE));
1289
1290 mb2_transfer.auto_pm_enabled =
1291 ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1292 (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1293 (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
1294 (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON));
1295
1296 spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
1297}
1298EXPORT_SYMBOL(prcmu_configure_auto_pm);
1299
1300bool prcmu_is_auto_pm_enabled(void)
1301{
1302 return mb2_transfer.auto_pm_enabled;
1303}
1304
1305static int request_sysclk(bool enable)
1306{
1307 int r;
1308 unsigned long flags;
1309
1310 r = 0;
1311
1312 mutex_lock(&mb3_transfer.sysclk_lock);
1313
1314 spin_lock_irqsave(&mb3_transfer.lock, flags);
1315
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001316 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001317 cpu_relax();
1318
1319 writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
1320
1321 writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001322 writel(MBOX_BIT(3), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001323
1324 spin_unlock_irqrestore(&mb3_transfer.lock, flags);
1325
1326 /*
1327 * The firmware only sends an ACK if we want to enable the
1328 * SysClk, and it succeeds.
1329 */
1330 if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work,
1331 msecs_to_jiffies(20000))) {
1332 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1333 __func__);
1334 r = -EIO;
1335 }
1336
1337 mutex_unlock(&mb3_transfer.sysclk_lock);
1338
1339 return r;
1340}
1341
1342static int request_timclk(bool enable)
1343{
1344 u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK);
1345
1346 if (!enable)
1347 val |= PRCM_TCR_STOP_TIMERS;
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001348 writel(val, PRCM_TCR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001349
1350 return 0;
1351}
1352
1353static int request_reg_clock(u8 clock, bool enable)
1354{
1355 u32 val;
1356 unsigned long flags;
1357
1358 spin_lock_irqsave(&clk_mgt_lock, flags);
1359
1360 /* Grab the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001361 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001362 cpu_relax();
1363
1364 val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
1365 if (enable) {
1366 val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw);
1367 } else {
1368 clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
1369 val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK);
1370 }
1371 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
1372
1373 /* Release the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001374 writel(0, PRCM_SEM);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001375
1376 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1377
1378 return 0;
1379}
1380
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001381static int request_sga_clock(u8 clock, bool enable)
1382{
1383 u32 val;
1384 int ret;
1385
1386 if (enable) {
1387 val = readl(PRCM_CGATING_BYPASS);
1388 writel(val | PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1389 }
1390
1391 ret = request_reg_clock(clock, enable);
1392
1393 if (!ret && !enable) {
1394 val = readl(PRCM_CGATING_BYPASS);
1395 writel(val & ~PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1396 }
1397
1398 return ret;
1399}
1400
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001401/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02001402 * db8500_prcmu_request_clock() - Request for a clock to be enabled or disabled.
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001403 * @clock: The clock for which the request is made.
1404 * @enable: Whether the clock should be enabled (true) or disabled (false).
1405 *
1406 * This function should only be used by the clock implementation.
1407 * Do not use it from any other place!
1408 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02001409int db8500_prcmu_request_clock(u8 clock, bool enable)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001410{
Linus Walleije62ccf32011-10-10 12:14:14 +02001411 switch(clock) {
1412 case PRCMU_SGACLK:
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001413 return request_sga_clock(clock, enable);
Linus Walleije62ccf32011-10-10 12:14:14 +02001414 case PRCMU_TIMCLK:
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001415 return request_timclk(enable);
Linus Walleije62ccf32011-10-10 12:14:14 +02001416 case PRCMU_SYSCLK:
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001417 return request_sysclk(enable);
Linus Walleije62ccf32011-10-10 12:14:14 +02001418 case PRCMU_PLLSOC1:
Mattias Nilsson0837bb72011-08-12 10:28:18 +02001419 return request_pll(clock, enable);
Linus Walleije62ccf32011-10-10 12:14:14 +02001420 default:
1421 break;
1422 }
1423 if (clock < PRCMU_NUM_REG_CLOCKS)
1424 return request_reg_clock(clock, enable);
1425 return -EINVAL;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001426}
1427
Mattias Nilsson73180f82011-08-12 10:28:10 +02001428int db8500_prcmu_config_esram0_deep_sleep(u8 state)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001429{
1430 if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
1431 (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
1432 return -EINVAL;
1433
1434 mutex_lock(&mb4_transfer.lock);
1435
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001436 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001437 cpu_relax();
1438
1439 writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1440 writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON),
1441 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE));
1442 writeb(DDR_PWR_STATE_ON,
1443 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
1444 writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
1445
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001446 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001447 wait_for_completion(&mb4_transfer.work);
1448
1449 mutex_unlock(&mb4_transfer.lock);
1450
1451 return 0;
1452}
1453
Mattias Nilsson05089012012-01-13 16:20:20 +01001454int db8500_prcmu_config_hotdog(u8 threshold)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001455{
1456 mutex_lock(&mb4_transfer.lock);
1457
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001458 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001459 cpu_relax();
1460
1461 writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
1462 writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1463
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001464 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001465 wait_for_completion(&mb4_transfer.work);
1466
1467 mutex_unlock(&mb4_transfer.lock);
1468
1469 return 0;
1470}
1471
Mattias Nilsson05089012012-01-13 16:20:20 +01001472int db8500_prcmu_config_hotmon(u8 low, u8 high)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001473{
1474 mutex_lock(&mb4_transfer.lock);
1475
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001476 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001477 cpu_relax();
1478
1479 writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
1480 writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH));
1481 writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH),
1482 (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
1483 writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1484
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001485 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001486 wait_for_completion(&mb4_transfer.work);
1487
1488 mutex_unlock(&mb4_transfer.lock);
1489
1490 return 0;
1491}
1492
1493static int config_hot_period(u16 val)
1494{
1495 mutex_lock(&mb4_transfer.lock);
1496
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001497 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001498 cpu_relax();
1499
1500 writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
1501 writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1502
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001503 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001504 wait_for_completion(&mb4_transfer.work);
1505
1506 mutex_unlock(&mb4_transfer.lock);
1507
1508 return 0;
1509}
1510
Mattias Nilsson05089012012-01-13 16:20:20 +01001511int db8500_prcmu_start_temp_sense(u16 cycles32k)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001512{
1513 if (cycles32k == 0xFFFF)
1514 return -EINVAL;
1515
1516 return config_hot_period(cycles32k);
1517}
1518
Mattias Nilsson05089012012-01-13 16:20:20 +01001519int db8500_prcmu_stop_temp_sense(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001520{
1521 return config_hot_period(0xFFFF);
1522}
1523
Jonas Aberg84165b82011-08-12 10:28:33 +02001524static int prcmu_a9wdog(u8 cmd, u8 d0, u8 d1, u8 d2, u8 d3)
1525{
1526
1527 mutex_lock(&mb4_transfer.lock);
1528
1529 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1530 cpu_relax();
1531
1532 writeb(d0, (tcdm_base + PRCM_REQ_MB4_A9WDOG_0));
1533 writeb(d1, (tcdm_base + PRCM_REQ_MB4_A9WDOG_1));
1534 writeb(d2, (tcdm_base + PRCM_REQ_MB4_A9WDOG_2));
1535 writeb(d3, (tcdm_base + PRCM_REQ_MB4_A9WDOG_3));
1536
1537 writeb(cmd, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1538
1539 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
1540 wait_for_completion(&mb4_transfer.work);
1541
1542 mutex_unlock(&mb4_transfer.lock);
1543
1544 return 0;
1545
1546}
1547
Mattias Nilsson05089012012-01-13 16:20:20 +01001548int db8500_prcmu_config_a9wdog(u8 num, bool sleep_auto_off)
Jonas Aberg84165b82011-08-12 10:28:33 +02001549{
1550 BUG_ON(num == 0 || num > 0xf);
1551 return prcmu_a9wdog(MB4H_A9WDOG_CONF, num, 0, 0,
1552 sleep_auto_off ? A9WDOG_AUTO_OFF_EN :
1553 A9WDOG_AUTO_OFF_DIS);
1554}
1555
Mattias Nilsson05089012012-01-13 16:20:20 +01001556int db8500_prcmu_enable_a9wdog(u8 id)
Jonas Aberg84165b82011-08-12 10:28:33 +02001557{
1558 return prcmu_a9wdog(MB4H_A9WDOG_EN, id, 0, 0, 0);
1559}
1560
Mattias Nilsson05089012012-01-13 16:20:20 +01001561int db8500_prcmu_disable_a9wdog(u8 id)
Jonas Aberg84165b82011-08-12 10:28:33 +02001562{
1563 return prcmu_a9wdog(MB4H_A9WDOG_DIS, id, 0, 0, 0);
1564}
1565
Mattias Nilsson05089012012-01-13 16:20:20 +01001566int db8500_prcmu_kick_a9wdog(u8 id)
Jonas Aberg84165b82011-08-12 10:28:33 +02001567{
1568 return prcmu_a9wdog(MB4H_A9WDOG_KICK, id, 0, 0, 0);
1569}
1570
1571/*
1572 * timeout is 28 bit, in ms.
1573 */
1574#define MAX_WATCHDOG_TIMEOUT 131000
Mattias Nilsson05089012012-01-13 16:20:20 +01001575int db8500_prcmu_load_a9wdog(u8 id, u32 timeout)
Jonas Aberg84165b82011-08-12 10:28:33 +02001576{
1577 if (timeout > MAX_WATCHDOG_TIMEOUT)
1578 /*
1579 * Due to calculation bug in prcmu fw, timeouts
1580 * can't be bigger than 131 seconds.
1581 */
1582 return -EINVAL;
1583
1584 return prcmu_a9wdog(MB4H_A9WDOG_LOAD,
1585 (id & A9WDOG_ID_MASK) |
1586 /*
1587 * Put the lowest 28 bits of timeout at
1588 * offset 4. Four first bits are used for id.
1589 */
1590 (u8)((timeout << 4) & 0xf0),
1591 (u8)((timeout >> 4) & 0xff),
1592 (u8)((timeout >> 12) & 0xff),
1593 (u8)((timeout >> 20) & 0xff));
1594}
1595
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001596/**
1597 * prcmu_set_clock_divider() - Configure the clock divider.
1598 * @clock: The clock for which the request is made.
1599 * @divider: The clock divider. (< 32)
1600 *
1601 * This function should only be used by the clock implementation.
1602 * Do not use it from any other place!
1603 */
1604int prcmu_set_clock_divider(u8 clock, u8 divider)
1605{
1606 u32 val;
1607 unsigned long flags;
1608
1609 if ((clock >= PRCMU_NUM_REG_CLOCKS) || (divider < 1) || (31 < divider))
1610 return -EINVAL;
1611
1612 spin_lock_irqsave(&clk_mgt_lock, flags);
1613
1614 /* Grab the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001615 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001616 cpu_relax();
1617
1618 val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
1619 val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK);
1620 val |= (u32)divider;
1621 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
1622
1623 /* Release the HW semaphore. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001624 writel(0, PRCM_SEM);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001625
1626 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1627
1628 return 0;
1629}
1630
Linus Walleije3726fc2010-08-19 12:36:01 +01001631/**
1632 * prcmu_abb_read() - Read register value(s) from the ABB.
1633 * @slave: The I2C slave address.
1634 * @reg: The (start) register address.
1635 * @value: The read out value(s).
1636 * @size: The number of registers to read.
1637 *
1638 * Reads register value(s) from the ABB.
1639 * @size has to be 1 for the current firmware version.
1640 */
1641int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
1642{
1643 int r;
1644
1645 if (size != 1)
1646 return -EINVAL;
1647
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001648 mutex_lock(&mb5_transfer.lock);
Linus Walleije3726fc2010-08-19 12:36:01 +01001649
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001650 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
Linus Walleije3726fc2010-08-19 12:36:01 +01001651 cpu_relax();
1652
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001653 writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
1654 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
1655 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
1656 writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
Linus Walleije3726fc2010-08-19 12:36:01 +01001657
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001658 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001659
Linus Walleije3726fc2010-08-19 12:36:01 +01001660 if (!wait_for_completion_timeout(&mb5_transfer.work,
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001661 msecs_to_jiffies(20000))) {
1662 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1663 __func__);
Linus Walleije3726fc2010-08-19 12:36:01 +01001664 r = -EIO;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001665 } else {
1666 r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO);
Linus Walleije3726fc2010-08-19 12:36:01 +01001667 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001668
Linus Walleije3726fc2010-08-19 12:36:01 +01001669 if (!r)
1670 *value = mb5_transfer.ack.value;
1671
Linus Walleije3726fc2010-08-19 12:36:01 +01001672 mutex_unlock(&mb5_transfer.lock);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001673
Linus Walleije3726fc2010-08-19 12:36:01 +01001674 return r;
1675}
Linus Walleije3726fc2010-08-19 12:36:01 +01001676
1677/**
1678 * prcmu_abb_write() - Write register value(s) to the ABB.
1679 * @slave: The I2C slave address.
1680 * @reg: The (start) register address.
1681 * @value: The value(s) to write.
1682 * @size: The number of registers to write.
1683 *
1684 * Reads register value(s) from the ABB.
1685 * @size has to be 1 for the current firmware version.
1686 */
1687int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
1688{
1689 int r;
1690
1691 if (size != 1)
1692 return -EINVAL;
1693
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001694 mutex_lock(&mb5_transfer.lock);
Linus Walleije3726fc2010-08-19 12:36:01 +01001695
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001696 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
Linus Walleije3726fc2010-08-19 12:36:01 +01001697 cpu_relax();
1698
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001699 writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
1700 writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
1701 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
1702 writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
Linus Walleije3726fc2010-08-19 12:36:01 +01001703
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001704 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001705
Linus Walleije3726fc2010-08-19 12:36:01 +01001706 if (!wait_for_completion_timeout(&mb5_transfer.work,
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001707 msecs_to_jiffies(20000))) {
1708 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
1709 __func__);
Linus Walleije3726fc2010-08-19 12:36:01 +01001710 r = -EIO;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001711 } else {
1712 r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
Linus Walleije3726fc2010-08-19 12:36:01 +01001713 }
Linus Walleije3726fc2010-08-19 12:36:01 +01001714
Linus Walleije3726fc2010-08-19 12:36:01 +01001715 mutex_unlock(&mb5_transfer.lock);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001716
Linus Walleije3726fc2010-08-19 12:36:01 +01001717 return r;
1718}
Linus Walleije3726fc2010-08-19 12:36:01 +01001719
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001720/**
1721 * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem
1722 */
1723void prcmu_ac_wake_req(void)
Martin Perssone0befb22010-12-08 15:13:28 +01001724{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001725 u32 val;
Mattias Nilssond6e30022011-08-12 10:28:43 +02001726 u32 status;
Martin Perssone0befb22010-12-08 15:13:28 +01001727
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001728 mutex_lock(&mb0_transfer.ac_wake_lock);
Martin Perssone0befb22010-12-08 15:13:28 +01001729
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001730 val = readl(PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001731 if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
1732 goto unlock_and_return;
1733
1734 atomic_set(&ac_wake_req_state, 1);
1735
Mattias Nilssond6e30022011-08-12 10:28:43 +02001736retry:
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001737 writel((val | PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ), PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001738
1739 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
Mattias Nilssond6e30022011-08-12 10:28:43 +02001740 msecs_to_jiffies(5000))) {
Linus Walleij57265bc2011-10-10 13:04:44 +02001741 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
Mattias Nilssond6e30022011-08-12 10:28:43 +02001742 __func__);
1743 goto unlock_and_return;
1744 }
1745
1746 /*
1747 * The modem can generate an AC_WAKE_ACK, and then still go to sleep.
1748 * As a workaround, we wait, and then check that the modem is indeed
1749 * awake (in terms of the value of the PRCM_MOD_AWAKE_STATUS
1750 * register, which may not be the whole truth).
1751 */
1752 udelay(400);
1753 status = (readl(PRCM_MOD_AWAKE_STATUS) & BITS(0, 2));
1754 if (status != (PRCM_MOD_AWAKE_STATUS_PRCM_MOD_AAPD_AWAKE |
1755 PRCM_MOD_AWAKE_STATUS_PRCM_MOD_COREPD_AWAKE)) {
1756 pr_err("prcmu: %s received ack, but modem not awake (0x%X).\n",
1757 __func__, status);
1758 udelay(1200);
1759 writel(val, PRCM_HOSTACCESS_REQ);
1760 if (wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
1761 msecs_to_jiffies(5000)))
1762 goto retry;
Linus Walleij57265bc2011-10-10 13:04:44 +02001763 pr_crit("prcmu: %s timed out (5 s) waiting for AC_SLEEP_ACK.\n",
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001764 __func__);
1765 }
1766
1767unlock_and_return:
1768 mutex_unlock(&mb0_transfer.ac_wake_lock);
1769}
1770
1771/**
1772 * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem
1773 */
1774void prcmu_ac_sleep_req()
1775{
1776 u32 val;
1777
1778 mutex_lock(&mb0_transfer.ac_wake_lock);
1779
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001780 val = readl(PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001781 if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
1782 goto unlock_and_return;
1783
1784 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001785 PRCM_HOSTACCESS_REQ);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001786
1787 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
Mattias Nilssond6e30022011-08-12 10:28:43 +02001788 msecs_to_jiffies(5000))) {
Linus Walleij57265bc2011-10-10 13:04:44 +02001789 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001790 __func__);
1791 }
1792
1793 atomic_set(&ac_wake_req_state, 0);
1794
1795unlock_and_return:
1796 mutex_unlock(&mb0_transfer.ac_wake_lock);
1797}
1798
Mattias Nilsson73180f82011-08-12 10:28:10 +02001799bool db8500_prcmu_is_ac_wake_requested(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001800{
1801 return (atomic_read(&ac_wake_req_state) != 0);
1802}
1803
1804/**
Mattias Nilsson73180f82011-08-12 10:28:10 +02001805 * db8500_prcmu_system_reset - System reset
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001806 *
Mattias Nilsson73180f82011-08-12 10:28:10 +02001807 * Saves the reset reason code and then sets the APE_SOFTRST register which
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001808 * fires interrupt to fw
1809 */
Mattias Nilsson73180f82011-08-12 10:28:10 +02001810void db8500_prcmu_system_reset(u16 reset_code)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001811{
1812 writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001813 writel(1, PRCM_APE_SOFTRST);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001814}
1815
1816/**
Sebastian Rasmussen597045d2011-08-12 10:28:53 +02001817 * db8500_prcmu_get_reset_code - Retrieve SW reset reason code
1818 *
1819 * Retrieves the reset reason code stored by prcmu_system_reset() before
1820 * last restart.
1821 */
1822u16 db8500_prcmu_get_reset_code(void)
1823{
1824 return readw(tcdm_base + PRCM_SW_RST_REASON);
1825}
1826
1827/**
Mattias Nilsson05089012012-01-13 16:20:20 +01001828 * db8500_prcmu_reset_modem - ask the PRCMU to reset modem
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001829 */
Mattias Nilsson05089012012-01-13 16:20:20 +01001830void db8500_prcmu_modem_reset(void)
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001831{
Martin Perssone0befb22010-12-08 15:13:28 +01001832 mutex_lock(&mb1_transfer.lock);
1833
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001834 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
Martin Perssone0befb22010-12-08 15:13:28 +01001835 cpu_relax();
1836
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001837 writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001838 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
Martin Perssone0befb22010-12-08 15:13:28 +01001839 wait_for_completion(&mb1_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001840
1841 /*
1842 * No need to check return from PRCMU as modem should go in reset state
1843 * This state is already managed by upper layer
1844 */
Martin Perssone0befb22010-12-08 15:13:28 +01001845
1846 mutex_unlock(&mb1_transfer.lock);
Martin Perssone0befb22010-12-08 15:13:28 +01001847}
1848
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001849static void ack_dbb_wakeup(void)
Martin Perssone0befb22010-12-08 15:13:28 +01001850{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001851 unsigned long flags;
Martin Perssone0befb22010-12-08 15:13:28 +01001852
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001853 spin_lock_irqsave(&mb0_transfer.lock, flags);
Martin Perssone0befb22010-12-08 15:13:28 +01001854
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001855 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001856 cpu_relax();
Martin Perssone0befb22010-12-08 15:13:28 +01001857
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001858 writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001859 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
Martin Perssone0befb22010-12-08 15:13:28 +01001860
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001861 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
Martin Perssone0befb22010-12-08 15:13:28 +01001862}
1863
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001864static inline void print_unknown_header_warning(u8 n, u8 header)
Linus Walleije3726fc2010-08-19 12:36:01 +01001865{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001866 pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n",
1867 header, n);
Linus Walleije3726fc2010-08-19 12:36:01 +01001868}
1869
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001870static bool read_mailbox_0(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001871{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001872 bool r;
1873 u32 ev;
1874 unsigned int n;
1875 u8 header;
1876
1877 header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0);
1878 switch (header) {
1879 case MB0H_WAKEUP_EXE:
1880 case MB0H_WAKEUP_SLEEP:
1881 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
1882 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500);
1883 else
1884 ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500);
1885
1886 if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK))
1887 complete(&mb0_transfer.ac_wake_work);
1888 if (ev & WAKEUP_BIT_SYSCLK_OK)
1889 complete(&mb3_transfer.sysclk_work);
1890
1891 ev &= mb0_transfer.req.dbb_irqs;
1892
1893 for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
1894 if (ev & prcmu_irq_bit[n])
1895 generic_handle_irq(IRQ_PRCMU_BASE + n);
1896 }
1897 r = true;
1898 break;
1899 default:
1900 print_unknown_header_warning(0, header);
1901 r = false;
1902 break;
1903 }
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001904 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001905 return r;
1906}
1907
1908static bool read_mailbox_1(void)
1909{
1910 mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1);
1911 mb1_transfer.ack.arm_opp = readb(tcdm_base +
1912 PRCM_ACK_MB1_CURRENT_ARM_OPP);
1913 mb1_transfer.ack.ape_opp = readb(tcdm_base +
1914 PRCM_ACK_MB1_CURRENT_APE_OPP);
1915 mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
1916 PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001917 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR);
Martin Perssone0befb22010-12-08 15:13:28 +01001918 complete(&mb1_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001919 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001920}
1921
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001922static bool read_mailbox_2(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001923{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001924 mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001925 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001926 complete(&mb2_transfer.work);
1927 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001928}
1929
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001930static bool read_mailbox_3(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001931{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001932 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001933 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001934}
1935
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001936static bool read_mailbox_4(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001937{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001938 u8 header;
1939 bool do_complete = true;
1940
1941 header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4);
1942 switch (header) {
1943 case MB4H_MEM_ST:
1944 case MB4H_HOTDOG:
1945 case MB4H_HOTMON:
1946 case MB4H_HOT_PERIOD:
Mattias Nilssona592c2e2011-08-12 10:27:41 +02001947 case MB4H_A9WDOG_CONF:
1948 case MB4H_A9WDOG_EN:
1949 case MB4H_A9WDOG_DIS:
1950 case MB4H_A9WDOG_LOAD:
1951 case MB4H_A9WDOG_KICK:
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001952 break;
1953 default:
1954 print_unknown_header_warning(4, header);
1955 do_complete = false;
1956 break;
1957 }
1958
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001959 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001960
1961 if (do_complete)
1962 complete(&mb4_transfer.work);
1963
1964 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001965}
1966
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001967static bool read_mailbox_5(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001968{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001969 mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
1970 mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001971 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR);
Linus Walleije3726fc2010-08-19 12:36:01 +01001972 complete(&mb5_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001973 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001974}
1975
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001976static bool read_mailbox_6(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001977{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001978 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001979 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001980}
1981
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001982static bool read_mailbox_7(void)
Linus Walleije3726fc2010-08-19 12:36:01 +01001983{
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02001984 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001985 return false;
Linus Walleije3726fc2010-08-19 12:36:01 +01001986}
1987
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02001988static bool (* const read_mailbox[NUM_MB])(void) = {
Linus Walleije3726fc2010-08-19 12:36:01 +01001989 read_mailbox_0,
1990 read_mailbox_1,
1991 read_mailbox_2,
1992 read_mailbox_3,
1993 read_mailbox_4,
1994 read_mailbox_5,
1995 read_mailbox_6,
1996 read_mailbox_7
1997};
1998
1999static irqreturn_t prcmu_irq_handler(int irq, void *data)
2000{
2001 u32 bits;
2002 u8 n;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002003 irqreturn_t r;
Linus Walleije3726fc2010-08-19 12:36:01 +01002004
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002005 bits = (readl(PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
Linus Walleije3726fc2010-08-19 12:36:01 +01002006 if (unlikely(!bits))
2007 return IRQ_NONE;
2008
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002009 r = IRQ_HANDLED;
Linus Walleije3726fc2010-08-19 12:36:01 +01002010 for (n = 0; bits; n++) {
2011 if (bits & MBOX_BIT(n)) {
2012 bits -= MBOX_BIT(n);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002013 if (read_mailbox[n]())
2014 r = IRQ_WAKE_THREAD;
Linus Walleije3726fc2010-08-19 12:36:01 +01002015 }
2016 }
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002017 return r;
2018}
2019
2020static irqreturn_t prcmu_irq_thread_fn(int irq, void *data)
2021{
2022 ack_dbb_wakeup();
Linus Walleije3726fc2010-08-19 12:36:01 +01002023 return IRQ_HANDLED;
2024}
2025
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002026static void prcmu_mask_work(struct work_struct *work)
2027{
2028 unsigned long flags;
2029
2030 spin_lock_irqsave(&mb0_transfer.lock, flags);
2031
2032 config_wakeups();
2033
2034 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
2035}
2036
2037static void prcmu_irq_mask(struct irq_data *d)
2038{
2039 unsigned long flags;
2040
2041 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
2042
2043 mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
2044
2045 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2046
2047 if (d->irq != IRQ_PRCMU_CA_SLEEP)
2048 schedule_work(&mb0_transfer.mask_work);
2049}
2050
2051static void prcmu_irq_unmask(struct irq_data *d)
2052{
2053 unsigned long flags;
2054
2055 spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
2056
2057 mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
2058
2059 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2060
2061 if (d->irq != IRQ_PRCMU_CA_SLEEP)
2062 schedule_work(&mb0_transfer.mask_work);
2063}
2064
2065static void noop(struct irq_data *d)
2066{
2067}
2068
2069static struct irq_chip prcmu_irq_chip = {
2070 .name = "prcmu",
2071 .irq_disable = prcmu_irq_mask,
2072 .irq_ack = noop,
2073 .irq_mask = prcmu_irq_mask,
2074 .irq_unmask = prcmu_irq_unmask,
2075};
2076
Mattias Nilssonb58d12f2012-01-13 16:20:10 +01002077static char *fw_project_name(u8 project)
2078{
2079 switch (project) {
2080 case PRCMU_FW_PROJECT_U8500:
2081 return "U8500";
2082 case PRCMU_FW_PROJECT_U8500_C2:
2083 return "U8500 C2";
2084 case PRCMU_FW_PROJECT_U9500:
2085 return "U9500";
2086 case PRCMU_FW_PROJECT_U9500_C2:
2087 return "U9500 C2";
2088 default:
2089 return "Unknown";
2090 }
2091}
2092
Mattias Nilsson73180f82011-08-12 10:28:10 +02002093void __init db8500_prcmu_early_init(void)
Mattias Wallinfcbd4582010-12-02 16:20:42 +01002094{
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002095 unsigned int i;
Linus Walleij3e2762c2012-01-02 14:17:40 +01002096 if (cpu_is_u8500v2()) {
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002097 void *tcpm_base = ioremap_nocache(U8500_PRCMU_TCPM_BASE, SZ_4K);
2098
2099 if (tcpm_base != NULL) {
Linus Walleij3e2762c2012-01-02 14:17:40 +01002100 u32 version;
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002101 version = readl(tcpm_base + PRCMU_FW_VERSION_OFFSET);
Mattias Nilssonb58d12f2012-01-13 16:20:10 +01002102 fw_info.version.project = version & 0xFF;
2103 fw_info.version.api_version = (version >> 8) & 0xFF;
2104 fw_info.version.func_version = (version >> 16) & 0xFF;
2105 fw_info.version.errata = (version >> 24) & 0xFF;
2106 fw_info.valid = true;
2107 pr_info("PRCMU firmware: %s, version %d.%d.%d\n",
2108 fw_project_name(fw_info.version.project),
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002109 (version >> 8) & 0xFF, (version >> 16) & 0xFF,
2110 (version >> 24) & 0xFF);
2111 iounmap(tcpm_base);
2112 }
2113
Mattias Wallinfcbd4582010-12-02 16:20:42 +01002114 tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE);
2115 } else {
2116 pr_err("prcmu: Unsupported chip version\n");
2117 BUG();
2118 }
Mattias Wallinfcbd4582010-12-02 16:20:42 +01002119
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002120 spin_lock_init(&mb0_transfer.lock);
2121 spin_lock_init(&mb0_transfer.dbb_irqs_lock);
2122 mutex_init(&mb0_transfer.ac_wake_lock);
2123 init_completion(&mb0_transfer.ac_wake_work);
Martin Perssone0befb22010-12-08 15:13:28 +01002124 mutex_init(&mb1_transfer.lock);
2125 init_completion(&mb1_transfer.work);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002126 mutex_init(&mb2_transfer.lock);
2127 init_completion(&mb2_transfer.work);
2128 spin_lock_init(&mb2_transfer.auto_pm_lock);
2129 spin_lock_init(&mb3_transfer.lock);
2130 mutex_init(&mb3_transfer.sysclk_lock);
2131 init_completion(&mb3_transfer.sysclk_work);
2132 mutex_init(&mb4_transfer.lock);
2133 init_completion(&mb4_transfer.work);
Linus Walleije3726fc2010-08-19 12:36:01 +01002134 mutex_init(&mb5_transfer.lock);
2135 init_completion(&mb5_transfer.work);
2136
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002137 INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
Linus Walleije3726fc2010-08-19 12:36:01 +01002138
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002139 /* Initalize irqs. */
2140 for (i = 0; i < NUM_PRCMU_WAKEUPS; i++) {
2141 unsigned int irq;
2142
2143 irq = IRQ_PRCMU_BASE + i;
2144 irq_set_chip_and_handler(irq, &prcmu_irq_chip,
2145 handle_simple_irq);
2146 set_irq_flags(irq, IRQF_VALID);
2147 }
Linus Walleije3726fc2010-08-19 12:36:01 +01002148}
2149
Mattias Nilsson05089012012-01-13 16:20:20 +01002150static void __init init_prcm_registers(void)
Mattias Nilssond65e12d2011-08-12 10:27:50 +02002151{
2152 u32 val;
2153
2154 val = readl(PRCM_A9PL_FORCE_CLKEN);
2155 val &= ~(PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN |
2156 PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN);
2157 writel(val, (PRCM_A9PL_FORCE_CLKEN));
2158}
2159
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002160/*
2161 * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC
2162 */
2163static struct regulator_consumer_supply db8500_vape_consumers[] = {
2164 REGULATOR_SUPPLY("v-ape", NULL),
2165 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.0"),
2166 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.1"),
2167 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.2"),
2168 REGULATOR_SUPPLY("v-i2c", "nmk-i2c.3"),
2169 /* "v-mmc" changed to "vcore" in the mainline kernel */
2170 REGULATOR_SUPPLY("vcore", "sdi0"),
2171 REGULATOR_SUPPLY("vcore", "sdi1"),
2172 REGULATOR_SUPPLY("vcore", "sdi2"),
2173 REGULATOR_SUPPLY("vcore", "sdi3"),
2174 REGULATOR_SUPPLY("vcore", "sdi4"),
2175 REGULATOR_SUPPLY("v-dma", "dma40.0"),
2176 REGULATOR_SUPPLY("v-ape", "ab8500-usb.0"),
2177 /* "v-uart" changed to "vcore" in the mainline kernel */
2178 REGULATOR_SUPPLY("vcore", "uart0"),
2179 REGULATOR_SUPPLY("vcore", "uart1"),
2180 REGULATOR_SUPPLY("vcore", "uart2"),
2181 REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"),
2182};
2183
2184static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
2185 /* CG2900 and CW1200 power to off-chip peripherals */
2186 REGULATOR_SUPPLY("gbf_1v8", "cg2900-uart.0"),
2187 REGULATOR_SUPPLY("wlan_1v8", "cw1200.0"),
2188 REGULATOR_SUPPLY("musb_1v8", "ab8500-usb.0"),
2189 /* AV8100 regulator */
2190 REGULATOR_SUPPLY("hdmi_1v8", "0-0070"),
2191};
2192
2193static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = {
2194 REGULATOR_SUPPLY("vsupply", "b2r2.0"),
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002195 REGULATOR_SUPPLY("vsupply", "mcde"),
2196};
2197
2198/* SVA MMDSP regulator switch */
2199static struct regulator_consumer_supply db8500_svammdsp_consumers[] = {
2200 REGULATOR_SUPPLY("sva-mmdsp", "cm_control"),
2201};
2202
2203/* SVA pipe regulator switch */
2204static struct regulator_consumer_supply db8500_svapipe_consumers[] = {
2205 REGULATOR_SUPPLY("sva-pipe", "cm_control"),
2206};
2207
2208/* SIA MMDSP regulator switch */
2209static struct regulator_consumer_supply db8500_siammdsp_consumers[] = {
2210 REGULATOR_SUPPLY("sia-mmdsp", "cm_control"),
2211};
2212
2213/* SIA pipe regulator switch */
2214static struct regulator_consumer_supply db8500_siapipe_consumers[] = {
2215 REGULATOR_SUPPLY("sia-pipe", "cm_control"),
2216};
2217
2218static struct regulator_consumer_supply db8500_sga_consumers[] = {
2219 REGULATOR_SUPPLY("v-mali", NULL),
2220};
2221
2222/* ESRAM1 and 2 regulator switch */
2223static struct regulator_consumer_supply db8500_esram12_consumers[] = {
2224 REGULATOR_SUPPLY("esram12", "cm_control"),
2225};
2226
2227/* ESRAM3 and 4 regulator switch */
2228static struct regulator_consumer_supply db8500_esram34_consumers[] = {
2229 REGULATOR_SUPPLY("v-esram34", "mcde"),
2230 REGULATOR_SUPPLY("esram34", "cm_control"),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002231};
2232
2233static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
2234 [DB8500_REGULATOR_VAPE] = {
2235 .constraints = {
2236 .name = "db8500-vape",
2237 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2238 },
2239 .consumer_supplies = db8500_vape_consumers,
2240 .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers),
2241 },
2242 [DB8500_REGULATOR_VARM] = {
2243 .constraints = {
2244 .name = "db8500-varm",
2245 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2246 },
2247 },
2248 [DB8500_REGULATOR_VMODEM] = {
2249 .constraints = {
2250 .name = "db8500-vmodem",
2251 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2252 },
2253 },
2254 [DB8500_REGULATOR_VPLL] = {
2255 .constraints = {
2256 .name = "db8500-vpll",
2257 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2258 },
2259 },
2260 [DB8500_REGULATOR_VSMPS1] = {
2261 .constraints = {
2262 .name = "db8500-vsmps1",
2263 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2264 },
2265 },
2266 [DB8500_REGULATOR_VSMPS2] = {
2267 .constraints = {
2268 .name = "db8500-vsmps2",
2269 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2270 },
2271 .consumer_supplies = db8500_vsmps2_consumers,
2272 .num_consumer_supplies = ARRAY_SIZE(db8500_vsmps2_consumers),
2273 },
2274 [DB8500_REGULATOR_VSMPS3] = {
2275 .constraints = {
2276 .name = "db8500-vsmps3",
2277 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2278 },
2279 },
2280 [DB8500_REGULATOR_VRF1] = {
2281 .constraints = {
2282 .name = "db8500-vrf1",
2283 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2284 },
2285 },
2286 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
2287 .supply_regulator = "db8500-vape",
2288 .constraints = {
2289 .name = "db8500-sva-mmdsp",
2290 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2291 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002292 .consumer_supplies = db8500_svammdsp_consumers,
2293 .num_consumer_supplies = ARRAY_SIZE(db8500_svammdsp_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002294 },
2295 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
2296 .constraints = {
2297 /* "ret" means "retention" */
2298 .name = "db8500-sva-mmdsp-ret",
2299 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2300 },
2301 },
2302 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
2303 .supply_regulator = "db8500-vape",
2304 .constraints = {
2305 .name = "db8500-sva-pipe",
2306 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2307 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002308 .consumer_supplies = db8500_svapipe_consumers,
2309 .num_consumer_supplies = ARRAY_SIZE(db8500_svapipe_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002310 },
2311 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
2312 .supply_regulator = "db8500-vape",
2313 .constraints = {
2314 .name = "db8500-sia-mmdsp",
2315 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2316 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002317 .consumer_supplies = db8500_siammdsp_consumers,
2318 .num_consumer_supplies = ARRAY_SIZE(db8500_siammdsp_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002319 },
2320 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
2321 .constraints = {
2322 .name = "db8500-sia-mmdsp-ret",
2323 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2324 },
2325 },
2326 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
2327 .supply_regulator = "db8500-vape",
2328 .constraints = {
2329 .name = "db8500-sia-pipe",
2330 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2331 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002332 .consumer_supplies = db8500_siapipe_consumers,
2333 .num_consumer_supplies = ARRAY_SIZE(db8500_siapipe_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002334 },
2335 [DB8500_REGULATOR_SWITCH_SGA] = {
2336 .supply_regulator = "db8500-vape",
2337 .constraints = {
2338 .name = "db8500-sga",
2339 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2340 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002341 .consumer_supplies = db8500_sga_consumers,
2342 .num_consumer_supplies = ARRAY_SIZE(db8500_sga_consumers),
2343
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002344 },
2345 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
2346 .supply_regulator = "db8500-vape",
2347 .constraints = {
2348 .name = "db8500-b2r2-mcde",
2349 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2350 },
2351 .consumer_supplies = db8500_b2r2_mcde_consumers,
2352 .num_consumer_supplies = ARRAY_SIZE(db8500_b2r2_mcde_consumers),
2353 },
2354 [DB8500_REGULATOR_SWITCH_ESRAM12] = {
2355 .supply_regulator = "db8500-vape",
2356 .constraints = {
2357 .name = "db8500-esram12",
2358 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2359 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002360 .consumer_supplies = db8500_esram12_consumers,
2361 .num_consumer_supplies = ARRAY_SIZE(db8500_esram12_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002362 },
2363 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
2364 .constraints = {
2365 .name = "db8500-esram12-ret",
2366 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2367 },
2368 },
2369 [DB8500_REGULATOR_SWITCH_ESRAM34] = {
2370 .supply_regulator = "db8500-vape",
2371 .constraints = {
2372 .name = "db8500-esram34",
2373 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2374 },
Bengt Jonsson624e87c2011-08-12 10:29:02 +02002375 .consumer_supplies = db8500_esram34_consumers,
2376 .num_consumer_supplies = ARRAY_SIZE(db8500_esram34_consumers),
Bengt Jonsson1032fbf2011-04-01 14:43:33 +02002377 },
2378 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
2379 .constraints = {
2380 .name = "db8500-esram34-ret",
2381 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2382 },
2383 },
2384};
2385
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002386static struct mfd_cell db8500_prcmu_devs[] = {
2387 {
2388 .name = "db8500-prcmu-regulators",
Mattias Wallin1ed78912011-05-27 11:49:43 +02002389 .platform_data = &db8500_regulators,
2390 .pdata_size = sizeof(db8500_regulators),
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002391 },
2392 {
2393 .name = "cpufreq-u8500",
2394 },
2395};
2396
2397/**
2398 * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic
2399 *
2400 */
2401static int __init db8500_prcmu_probe(struct platform_device *pdev)
2402{
2403 int err = 0;
2404
2405 if (ux500_is_svp())
2406 return -ENODEV;
2407
Mattias Nilsson05089012012-01-13 16:20:20 +01002408 init_prcm_registers();
Mattias Nilssond65e12d2011-08-12 10:27:50 +02002409
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002410 /* Clean up the mailbox interrupts after pre-kernel code. */
Mattias Nilssonc553b3c2011-08-12 10:27:20 +02002411 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
Mattias Nilsson3df57bc2011-05-16 00:15:05 +02002412
2413 err = request_threaded_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler,
2414 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
2415 if (err < 0) {
2416 pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
2417 err = -EBUSY;
2418 goto no_irq_return;
2419 }
2420
2421 if (cpu_is_u8500v20_or_later())
2422 prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
2423
2424 err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
2425 ARRAY_SIZE(db8500_prcmu_devs), NULL,
2426 0);
2427
2428 if (err)
2429 pr_err("prcmu: Failed to add subdevices\n");
2430 else
2431 pr_info("DB8500 PRCMU initialized\n");
2432
2433no_irq_return:
2434 return err;
2435}
2436
2437static struct platform_driver db8500_prcmu_driver = {
2438 .driver = {
2439 .name = "db8500-prcmu",
2440 .owner = THIS_MODULE,
2441 },
2442};
2443
2444static int __init db8500_prcmu_init(void)
2445{
2446 return platform_driver_probe(&db8500_prcmu_driver, db8500_prcmu_probe);
2447}
2448
2449arch_initcall(db8500_prcmu_init);
2450
2451MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>");
2452MODULE_DESCRIPTION("DB8500 PRCM Unit driver");
2453MODULE_LICENSE("GPL v2");