blob: d251cc29f72780eef75edaae3e189fa0a09718c7 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/err.h>
15#include <linux/io.h>
16#include <linux/elf.h>
17#include <linux/delay.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/regulator/consumer.h>
Stephen Boyd9802ca92011-05-25 15:09:59 -070021
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include <asm/mach-types.h>
23
Stephen Boyd9802ca92011-05-25 15:09:59 -070024#include <mach/msm_iomap.h>
25#include <mach/scm.h>
26
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#include "peripheral-loader.h"
28
29#define MSM_FW_QDSP6SS_PHYS 0x08800000
30#define MSM_SW_QDSP6SS_PHYS 0x08900000
31#define MSM_LPASS_QDSP6SS_PHYS 0x28800000
32#define MSM_MSS_ENABLE_PHYS 0x08B00000
33
34#define QDSP6SS_RST_EVB 0x0
35#define QDSP6SS_RESET 0x04
36#define QDSP6SS_CGC_OVERRIDE 0x18
37#define QDSP6SS_STRAP_TCM 0x1C
38#define QDSP6SS_STRAP_AHB 0x20
39#define QDSP6SS_GFMUX_CTL 0x30
40#define QDSP6SS_PWR_CTL 0x38
41
42#define MSS_S_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2C70)
43#define MSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60)
44#define SFAB_MSS_M_ACLK_CTL (MSM_CLK_CTL_BASE + 0x2340)
45#define SFAB_MSS_S_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2C00)
46#define SFAB_MSS_Q6_FW_ACLK_CTL (MSM_CLK_CTL_BASE + 0x2044)
47#define SFAB_MSS_Q6_SW_ACLK_CTL (MSM_CLK_CTL_BASE + 0x2040)
48#define SFAB_LPASS_Q6_ACLK_CTL (MSM_CLK_CTL_BASE + 0x23A0)
49#define MSS_Q6FW_JTAG_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C6C)
50#define MSS_Q6SW_JTAG_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C68)
51#define MSS_RESET (MSM_CLK_CTL_BASE + 0x2C64)
52
53#define Q6SS_SS_ARES BIT(0)
54#define Q6SS_CORE_ARES BIT(1)
55#define Q6SS_ISDB_ARES BIT(2)
56#define Q6SS_ETM_ARES BIT(3)
57#define Q6SS_STOP_CORE_ARES BIT(4)
58#define Q6SS_PRIV_ARES BIT(5)
59
60#define Q6SS_L2DATA_SLP_NRET_N BIT(0)
61#define Q6SS_SLP_RET_N BIT(1)
62#define Q6SS_L1TCM_SLP_NRET_N BIT(2)
63#define Q6SS_L2TAG_SLP_NRET_N BIT(3)
64#define Q6SS_ETB_SLEEP_NRET_N BIT(4)
65#define Q6SS_ARR_STBY_N BIT(5)
66#define Q6SS_CLAMP_IO BIT(6)
67
68#define Q6SS_CLK_ENA BIT(1)
69#define Q6SS_SRC_SWITCH_CLK_OVR BIT(8)
70#define Q6SS_AXIS_ACLK_EN BIT(9)
71
72#define MSM_RIVA_PHYS 0x03204000
73#define RIVA_PMU_A2XB_CFG (msm_riva_base + 0xB8)
74#define RIVA_PMU_A2XB_CFG_EN BIT(0)
75
76#define RIVA_PMU_CFG (msm_riva_base + 0x28)
77#define RIVA_PMU_CFG_WARM_BOOT BIT(0)
78#define RIVA_PMU_CFG_IRIS_XO_MODE 0x6
79#define RIVA_PMU_CFG_IRIS_XO_MODE_48 (3 << 1)
80
81#define RIVA_PMU_OVRD_VAL (msm_riva_base + 0x30)
82#define RIVA_PMU_OVRD_VAL_CCPU_RESET BIT(0)
83#define RIVA_PMU_OVRD_VAL_CCPU_CLK BIT(1)
84
85#define RIVA_PMU_CCPU_CTL (msm_riva_base + 0x9C)
86#define RIVA_PMU_CCPU_CTL_HIGH_IVT BIT(0)
87#define RIVA_PMU_CCPU_CTL_REMAP_EN BIT(2)
88
89#define RIVA_PMU_CCPU_BOOT_REMAP_ADDR (msm_riva_base + 0xA0)
90
91#define RIVA_PLL_MODE (MSM_CLK_CTL_BASE + 0x31A0)
92#define PLL_MODE_OUTCTRL BIT(0)
93#define PLL_MODE_BYPASSNL BIT(1)
94#define PLL_MODE_RESET_N BIT(2)
95#define PLL_MODE_REF_XO_SEL 0x30
96#define PLL_MODE_REF_XO_SEL_CXO (2 << 4)
97#define PLL_MODE_REF_XO_SEL_RF (3 << 4)
98#define RIVA_PLL_L_VAL (MSM_CLK_CTL_BASE + 0x31A4)
99#define RIVA_PLL_M_VAL (MSM_CLK_CTL_BASE + 0x31A8)
100#define RIVA_PLL_N_VAL (MSM_CLK_CTL_BASE + 0x31Ac)
101#define RIVA_PLL_CONFIG (MSM_CLK_CTL_BASE + 0x31B4)
102#define RIVA_PLL_STATUS (MSM_CLK_CTL_BASE + 0x31B8)
103
104#define RIVA_PMU_ROOT_CLK_SEL (msm_riva_base + 0xC8)
105#define RIVA_PMU_ROOT_CLK_SEL_3 BIT(2)
106
107#define RIVA_PMU_CLK_ROOT3 (msm_riva_base + 0x78)
108#define RIVA_PMU_CLK_ROOT3_ENA BIT(0)
109#define RIVA_PMU_CLK_ROOT3_SRC0_DIV 0x3C
110#define RIVA_PMU_CLK_ROOT3_SRC0_DIV_2 (1 << 2)
111#define RIVA_PMU_CLK_ROOT3_SRC0_SEL 0x1C0
112#define RIVA_PMU_CLK_ROOT3_SRC0_SEL_RIVA (1 << 6)
113#define RIVA_PMU_CLK_ROOT3_SRC1_DIV 0x1E00
114#define RIVA_PMU_CLK_ROOT3_SRC1_DIV_2 (1 << 9)
115#define RIVA_PMU_CLK_ROOT3_SRC1_SEL 0xE000
116#define RIVA_PMU_CLK_ROOT3_SRC1_SEL_RIVA (1 << 13)
117
118#define PPSS_RESET (MSM_CLK_CTL_BASE + 0x2594)
119#define PPSS_PROC_CLK_CTL (MSM_CLK_CTL_BASE + 0x2588)
120#define PPSS_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2580)
121
Stephen Boyd9802ca92011-05-25 15:09:59 -0700122#define PAS_Q6 1
123#define PAS_DSPS 2
124#define PAS_MODEM_SW 4
125#define PAS_MODEM_FW 5
Stephen Boydcc724232011-08-17 17:56:00 -0700126#define PAS_RIVA 6
Stephen Boyd9802ca92011-05-25 15:09:59 -0700127
128#define PAS_INIT_IMAGE_CMD 1
129#define PAS_MEM_CMD 2
130#define PAS_AUTH_AND_RESET_CMD 5
131#define PAS_SHUTDOWN_CMD 6
Saravana Kannan76cc49b2011-09-07 19:59:04 -0700132#define PAS_IS_SUPPORTED_CMD 7
Stephen Boyd9802ca92011-05-25 15:09:59 -0700133
134struct pas_init_image_req {
135 u32 proc;
136 u32 image_addr;
137};
138
139struct pas_init_image_resp {
140 u32 image_valid;
141};
142
143struct pas_auth_image_req {
144 u32 proc;
145};
146
147struct pas_auth_image_resp {
148 u32 reset_initiated;
149};
150
151struct pas_shutdown_req {
152 u32 proc;
153};
154
155struct pas_shutdown_resp {
156 u32 success;
157};
158
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159struct q6_data {
160 const unsigned strap_tcm_base;
161 const unsigned strap_ahb_upper;
162 const unsigned strap_ahb_lower;
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700163 const unsigned reg_base_phys;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164 void __iomem *reg_base;
165 void __iomem *aclk_reg;
166 void __iomem *jtag_clk_reg;
167 int start_addr;
168 struct regulator *vreg;
169 bool vreg_enabled;
170 const char *name;
171};
172
173static struct q6_data q6_lpass = {
174 .strap_tcm_base = (0x146 << 16),
175 .strap_ahb_upper = (0x029 << 16),
176 .strap_ahb_lower = (0x028 << 4),
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700177 .reg_base_phys = MSM_LPASS_QDSP6SS_PHYS,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 .aclk_reg = SFAB_LPASS_Q6_ACLK_CTL,
179 .name = "q6_lpass",
180};
181
182static struct q6_data q6_modem_fw = {
183 .strap_tcm_base = (0x40 << 16),
184 .strap_ahb_upper = (0x09 << 16),
185 .strap_ahb_lower = (0x08 << 4),
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700186 .reg_base_phys = MSM_FW_QDSP6SS_PHYS,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 .aclk_reg = SFAB_MSS_Q6_FW_ACLK_CTL,
188 .jtag_clk_reg = MSS_Q6FW_JTAG_CLK_CTL,
189 .name = "q6_modem_fw",
190};
191
192static struct q6_data q6_modem_sw = {
193 .strap_tcm_base = (0x42 << 16),
194 .strap_ahb_upper = (0x09 << 16),
195 .strap_ahb_lower = (0x08 << 4),
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700196 .reg_base_phys = MSM_SW_QDSP6SS_PHYS,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197 .aclk_reg = SFAB_MSS_Q6_SW_ACLK_CTL,
198 .jtag_clk_reg = MSS_Q6SW_JTAG_CLK_CTL,
199 .name = "q6_modem_sw",
200};
201
202static void __iomem *mss_enable_reg;
203static void __iomem *msm_riva_base;
204static unsigned long riva_start;
205
Stephen Boyd9802ca92011-05-25 15:09:59 -0700206static int init_image_trusted(int id, const u8 *metadata, size_t size)
207{
208 int ret;
209 struct pas_init_image_req request;
210 struct pas_init_image_resp resp = {0};
211 void *mdata_buf;
212
213 /* Make memory physically contiguous */
214 mdata_buf = kmemdup(metadata, size, GFP_KERNEL);
215 if (!mdata_buf)
216 return -ENOMEM;
217
218 request.proc = id;
219 request.image_addr = virt_to_phys(mdata_buf);
220
221 ret = scm_call(SCM_SVC_PIL, PAS_INIT_IMAGE_CMD, &request,
222 sizeof(request), &resp, sizeof(resp));
223 kfree(mdata_buf);
224
225 if (ret)
226 return ret;
227 return resp.image_valid;
228}
229
230static int init_image_lpass_q6_trusted(const u8 *metadata, size_t size)
231{
232 return init_image_trusted(PAS_Q6, metadata, size);
233}
234
235static int init_image_modem_fw_q6_trusted(const u8 *metadata, size_t size)
236{
237 return init_image_trusted(PAS_MODEM_FW, metadata, size);
238}
239
240static int init_image_modem_sw_q6_trusted(const u8 *metadata, size_t size)
241{
242 return init_image_trusted(PAS_MODEM_SW, metadata, size);
243}
244
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245static int init_image_lpass_q6_untrusted(const u8 *metadata, size_t size)
246{
247 const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata;
248 q6_lpass.start_addr = ehdr->e_entry;
249 return 0;
250}
251
252static int init_image_modem_fw_q6_untrusted(const u8 *metadata, size_t size)
253{
254 const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata;
255 q6_modem_fw.start_addr = ehdr->e_entry;
256 return 0;
257}
258
259static int init_image_modem_sw_q6_untrusted(const u8 *metadata, size_t size)
260{
261 const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata;
262 q6_modem_sw.start_addr = ehdr->e_entry;
263 return 0;
264}
265
266static int verify_blob(u32 phy_addr, size_t size)
267{
268 return 0;
269}
270
Stephen Boyd9802ca92011-05-25 15:09:59 -0700271static int auth_and_reset_trusted(int id)
272{
273 int ret;
274 struct pas_auth_image_req request;
275 struct pas_auth_image_resp resp = {0};
276
277 request.proc = id;
278 ret = scm_call(SCM_SVC_PIL, PAS_AUTH_AND_RESET_CMD, &request,
279 sizeof(request), &resp, sizeof(resp));
280 if (ret)
281 return ret;
282
283 return resp.reset_initiated;
284}
285
Stephen Boydb6b54852011-08-16 14:16:27 -0700286static int power_up_q6(struct q6_data *q6)
Stephen Boyd9802ca92011-05-25 15:09:59 -0700287{
288 int err;
289
290 err = regulator_set_voltage(q6->vreg, 1050000, 1050000);
291 if (err) {
292 pr_err("Failed to set %s regulator's voltage.\n", q6->name);
293 return err;
294 }
Stephen Boydb6b54852011-08-16 14:16:27 -0700295 err = regulator_set_optimum_mode(q6->vreg, 100000);
296 if (err < 0) {
297 pr_err("Failed to set %s regulator's mode.\n", q6->name);
298 return err;
299 }
Stephen Boyd9802ca92011-05-25 15:09:59 -0700300 err = regulator_enable(q6->vreg);
301 if (err) {
302 pr_err("Failed to enable %s's regulator.\n", q6->name);
303 return err;
304 }
305 q6->vreg_enabled = true;
Stephen Boydb6b54852011-08-16 14:16:27 -0700306 return 0;
Stephen Boyd9802ca92011-05-25 15:09:59 -0700307}
308
Stephen Boydb6b54852011-08-16 14:16:27 -0700309static int reset_q6_trusted(int id, struct q6_data *q6)
310{
311 int err = power_up_q6(q6);
312 if (err)
313 return err;
314 return auth_and_reset_trusted(id);
315}
Stephen Boyd9802ca92011-05-25 15:09:59 -0700316
317static int reset_lpass_q6_trusted(void)
318{
319 return reset_q6_trusted(PAS_Q6, &q6_lpass);
320}
321
322static int reset_modem_fw_q6_trusted(void)
323{
324 return reset_q6_trusted(PAS_MODEM_FW, &q6_modem_fw);
325}
326
327static int reset_modem_sw_q6_trusted(void)
328{
329 return reset_q6_trusted(PAS_MODEM_SW, &q6_modem_sw);
330}
331
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700332static int reset_q6_untrusted(struct q6_data *q6)
333{
334 u32 reg, err = 0;
335
Stephen Boydb6b54852011-08-16 14:16:27 -0700336 err = power_up_q6(q6);
337 if (err)
338 return err;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700339 /* Enable Q6 ACLK */
340 writel_relaxed(0x10, q6->aclk_reg);
341
342 if (q6 == &q6_modem_fw || q6 == &q6_modem_sw) {
343 /* Enable MSS clocks */
344 writel_relaxed(0x10, SFAB_MSS_M_ACLK_CTL);
345 writel_relaxed(0x10, SFAB_MSS_S_HCLK_CTL);
346 writel_relaxed(0x10, MSS_S_HCLK_CTL);
347 writel_relaxed(0x10, MSS_SLP_CLK_CTL);
348 /* Wait for clocks to enable */
349 mb();
350 udelay(10);
351
352 /* Enable JTAG clocks */
353 /* TODO: Remove if/when Q6 software enables them? */
354 writel_relaxed(0x10, q6->jtag_clk_reg);
355
356 /* De-assert MSS reset */
357 writel_relaxed(0x0, MSS_RESET);
358 mb();
359 udelay(10);
360
361 /* Enable MSS */
362 writel_relaxed(0x7, mss_enable_reg);
363 }
364
365 /*
366 * Assert AXIS_ACLK_EN override to allow for correct updating of the
367 * QDSP6_CORE_STATE status bit. This is mandatory only for the SW Q6
368 * in 8960v1 and optional elsewhere.
369 */
370 reg = readl_relaxed(q6->reg_base + QDSP6SS_CGC_OVERRIDE);
371 reg |= Q6SS_AXIS_ACLK_EN;
372 writel_relaxed(reg, q6->reg_base + QDSP6SS_CGC_OVERRIDE);
373
374 /* Deassert Q6SS_SS_ARES */
375 reg = readl_relaxed(q6->reg_base + QDSP6SS_RESET);
376 reg &= ~(Q6SS_SS_ARES);
377 writel_relaxed(reg, q6->reg_base + QDSP6SS_RESET);
378
379 /* Program boot address */
380 writel_relaxed((q6->start_addr >> 8) & 0xFFFFFF,
381 q6->reg_base + QDSP6SS_RST_EVB);
382
383 /* Program TCM and AHB address ranges */
384 writel_relaxed(q6->strap_tcm_base, q6->reg_base + QDSP6SS_STRAP_TCM);
385 writel_relaxed(q6->strap_ahb_upper | q6->strap_ahb_lower,
386 q6->reg_base + QDSP6SS_STRAP_AHB);
387
388 /* Turn off Q6 core clock */
389 writel_relaxed(Q6SS_SRC_SWITCH_CLK_OVR,
390 q6->reg_base + QDSP6SS_GFMUX_CTL);
391
392 /* Put memories to sleep */
393 writel_relaxed(Q6SS_CLAMP_IO, q6->reg_base + QDSP6SS_PWR_CTL);
394
395 /* Assert resets */
396 reg = readl_relaxed(q6->reg_base + QDSP6SS_RESET);
397 reg |= (Q6SS_CORE_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES
398 | Q6SS_STOP_CORE_ARES);
399 writel_relaxed(reg, q6->reg_base + QDSP6SS_RESET);
400
401 /* Wait 8 AHB cycles for Q6 to be fully reset (AHB = 1.5Mhz) */
402 mb();
403 usleep_range(20, 30);
404
405 /* Turn on Q6 memories */
406 reg = Q6SS_L2DATA_SLP_NRET_N | Q6SS_SLP_RET_N | Q6SS_L1TCM_SLP_NRET_N
407 | Q6SS_L2TAG_SLP_NRET_N | Q6SS_ETB_SLEEP_NRET_N | Q6SS_ARR_STBY_N
408 | Q6SS_CLAMP_IO;
409 writel_relaxed(reg, q6->reg_base + QDSP6SS_PWR_CTL);
410
411 /* Turn on Q6 core clock */
412 reg = Q6SS_CLK_ENA | Q6SS_SRC_SWITCH_CLK_OVR;
413 writel_relaxed(reg, q6->reg_base + QDSP6SS_GFMUX_CTL);
414
415 /* Remove Q6SS_CLAMP_IO */
416 reg = readl_relaxed(q6->reg_base + QDSP6SS_PWR_CTL);
417 reg &= ~Q6SS_CLAMP_IO;
418 writel_relaxed(reg, q6->reg_base + QDSP6SS_PWR_CTL);
419
420 /* Bring Q6 core out of reset and start execution. */
421 writel_relaxed(0x0, q6->reg_base + QDSP6SS_RESET);
422
423 /*
424 * Re-enable auto-gating of AXIS_ACLK at lease one AXI clock cycle
425 * after resets are de-asserted.
426 */
427 mb();
428 usleep_range(1, 10);
429 reg = readl_relaxed(q6->reg_base + QDSP6SS_CGC_OVERRIDE);
430 reg &= ~Q6SS_AXIS_ACLK_EN;
431 writel_relaxed(reg, q6->reg_base + QDSP6SS_CGC_OVERRIDE);
432
Stephen Boydb6b54852011-08-16 14:16:27 -0700433 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700434}
435
436static int reset_lpass_q6_untrusted(void)
437{
438 return reset_q6_untrusted(&q6_lpass);
439}
440
441static int reset_modem_fw_q6_untrusted(void)
442{
443 return reset_q6_untrusted(&q6_modem_fw);
444}
445
446static int reset_modem_sw_q6_untrusted(void)
447{
448 return reset_q6_untrusted(&q6_modem_sw);
449}
450
Stephen Boyd9802ca92011-05-25 15:09:59 -0700451static int shutdown_trusted(int id)
452{
453 int ret;
454 struct pas_shutdown_req request;
455 struct pas_shutdown_resp resp = {0};
456
457 request.proc = id;
458 ret = scm_call(SCM_SVC_PIL, PAS_SHUTDOWN_CMD, &request, sizeof(request),
459 &resp, sizeof(resp));
460 if (ret)
461 return ret;
462
463 return resp.success;
464}
465
466static int shutdown_q6_trusted(int id, struct q6_data *q6)
467{
468 int ret;
469
470 ret = shutdown_trusted(id);
Matt Wagantalldafcd3d2011-08-02 20:27:59 -0700471 if (ret)
472 return ret;
473
Stephen Boyd9802ca92011-05-25 15:09:59 -0700474 if (q6->vreg_enabled) {
475 regulator_disable(q6->vreg);
476 q6->vreg_enabled = false;
477 }
478
479 return ret;
480}
481
482static int shutdown_lpass_q6_trusted(void)
483{
484 return shutdown_q6_trusted(PAS_Q6, &q6_lpass);
485}
486
487static int shutdown_modem_fw_q6_trusted(void)
488{
489 return shutdown_q6_trusted(PAS_MODEM_FW, &q6_modem_fw);
490}
491
492static int shutdown_modem_sw_q6_trusted(void)
493{
494 return shutdown_q6_trusted(PAS_MODEM_SW, &q6_modem_sw);
495}
496
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700497static int shutdown_q6_untrusted(struct q6_data *q6)
498{
499 u32 reg;
500
501 /* Turn off Q6 core clock */
502 writel_relaxed(Q6SS_SRC_SWITCH_CLK_OVR,
503 q6->reg_base + QDSP6SS_GFMUX_CTL);
504
505 /* Assert resets */
506 reg = (Q6SS_SS_ARES | Q6SS_CORE_ARES | Q6SS_ISDB_ARES
507 | Q6SS_ETM_ARES | Q6SS_STOP_CORE_ARES | Q6SS_PRIV_ARES);
508 writel_relaxed(reg, q6->reg_base + QDSP6SS_RESET);
509
510 /* Turn off Q6 memories */
511 writel_relaxed(Q6SS_CLAMP_IO, q6->reg_base + QDSP6SS_PWR_CTL);
512
513 /* Put Modem Subsystem back into reset when shutting down FWQ6 */
514 if (q6 == &q6_modem_fw)
515 writel_relaxed(0x1, MSS_RESET);
516
517 if (q6->vreg_enabled) {
518 regulator_disable(q6->vreg);
519 q6->vreg_enabled = false;
520 }
521
522 return 0;
523}
524
525static int shutdown_lpass_q6_untrusted(void)
526{
527 return shutdown_q6_untrusted(&q6_lpass);
528}
529
530static int shutdown_modem_fw_q6_untrusted(void)
531{
532 return shutdown_q6_untrusted(&q6_modem_fw);
533}
534
535static int shutdown_modem_sw_q6_untrusted(void)
536{
537 return shutdown_q6_untrusted(&q6_modem_sw);
538}
539
540static int init_image_riva_untrusted(const u8 *metadata, size_t size)
541{
542 const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata;
543 riva_start = ehdr->e_entry;
544 return 0;
545}
546
547static int reset_riva_untrusted(void)
548{
549 u32 reg;
550 bool xo;
551
552 /* Enable A2XB bridge */
553 reg = readl(RIVA_PMU_A2XB_CFG);
554 reg |= RIVA_PMU_A2XB_CFG_EN;
555 writel(reg, RIVA_PMU_A2XB_CFG);
556
557 /* Determine which XO to use */
558 reg = readl(RIVA_PMU_CFG);
559 xo = (reg & RIVA_PMU_CFG_IRIS_XO_MODE) == RIVA_PMU_CFG_IRIS_XO_MODE_48;
560
561 /* Program PLL 13 to 960 MHz */
562 reg = readl(RIVA_PLL_MODE);
563 reg &= ~(PLL_MODE_BYPASSNL | PLL_MODE_OUTCTRL | PLL_MODE_RESET_N);
564 writel(reg, RIVA_PLL_MODE);
565
566 if (xo)
567 writel(0x40000C00 | 40, RIVA_PLL_L_VAL);
568 else
569 writel(0x40000C00 | 50, RIVA_PLL_L_VAL);
570 writel(0, RIVA_PLL_M_VAL);
571 writel(1, RIVA_PLL_N_VAL);
572 writel_relaxed(0x01495227, RIVA_PLL_CONFIG);
573
574 reg = readl(RIVA_PLL_MODE);
575 reg &= ~(PLL_MODE_REF_XO_SEL);
576 reg |= xo ? PLL_MODE_REF_XO_SEL_RF : PLL_MODE_REF_XO_SEL_CXO;
577 writel(reg, RIVA_PLL_MODE);
578
579 /* Enable PLL 13 */
580 reg |= PLL_MODE_BYPASSNL;
581 writel(reg, RIVA_PLL_MODE);
582
583 usleep_range(10, 20);
584
585 reg |= PLL_MODE_RESET_N;
586 writel(reg, RIVA_PLL_MODE);
587 reg |= PLL_MODE_OUTCTRL;
588 writel(reg, RIVA_PLL_MODE);
589
590 /* Wait for PLL to settle */
591 usleep_range(50, 100);
592
593 /* Configure cCPU for 240 MHz */
594 reg = readl(RIVA_PMU_CLK_ROOT3);
595 if (readl(RIVA_PMU_ROOT_CLK_SEL) & RIVA_PMU_ROOT_CLK_SEL_3) {
596 reg &= ~(RIVA_PMU_CLK_ROOT3_SRC0_SEL |
597 RIVA_PMU_CLK_ROOT3_SRC0_DIV);
598 reg |= RIVA_PMU_CLK_ROOT3_SRC0_SEL_RIVA |
599 RIVA_PMU_CLK_ROOT3_SRC0_DIV_2;
600 } else {
601 reg &= ~(RIVA_PMU_CLK_ROOT3_SRC1_SEL |
602 RIVA_PMU_CLK_ROOT3_SRC1_DIV);
603 reg |= RIVA_PMU_CLK_ROOT3_SRC1_SEL_RIVA |
604 RIVA_PMU_CLK_ROOT3_SRC1_DIV_2;
605 }
606 writel(reg, RIVA_PMU_CLK_ROOT3);
607 reg |= RIVA_PMU_CLK_ROOT3_ENA;
608 writel(reg, RIVA_PMU_CLK_ROOT3);
609 reg = readl(RIVA_PMU_ROOT_CLK_SEL);
610 reg ^= RIVA_PMU_ROOT_CLK_SEL_3;
611 writel(reg, RIVA_PMU_ROOT_CLK_SEL);
612
613 /* Use the high vector table */
614 reg = readl(RIVA_PMU_CCPU_CTL);
615 reg |= RIVA_PMU_CCPU_CTL_HIGH_IVT | RIVA_PMU_CCPU_CTL_REMAP_EN;
616 writel(reg, RIVA_PMU_CCPU_CTL);
617
618 /* Set base memory address */
619 writel_relaxed(riva_start >> 16, RIVA_PMU_CCPU_BOOT_REMAP_ADDR);
620
621 /* Clear warmboot bit indicating this is a cold boot */
622 reg = readl(RIVA_PMU_CFG);
623 reg &= ~(RIVA_PMU_CFG_WARM_BOOT);
624 writel(reg, RIVA_PMU_CFG);
625
626 /* Enable the cCPU clock */
627 reg = readl(RIVA_PMU_OVRD_VAL);
628 reg |= RIVA_PMU_OVRD_VAL_CCPU_CLK;
629 writel(reg, RIVA_PMU_OVRD_VAL);
630
631 /* Take cCPU out of reset */
632 reg |= RIVA_PMU_OVRD_VAL_CCPU_RESET;
633 writel(reg, RIVA_PMU_OVRD_VAL);
634
635 return 0;
636}
637
638static int shutdown_riva_untrusted(void)
639{
640 u32 reg;
641 /* Put riva into reset */
642 reg = readl(RIVA_PMU_OVRD_VAL);
643 reg &= ~(RIVA_PMU_OVRD_VAL_CCPU_RESET | RIVA_PMU_OVRD_VAL_CCPU_CLK);
644 writel(reg, RIVA_PMU_OVRD_VAL);
645 return 0;
646}
647
Stephen Boydcc724232011-08-17 17:56:00 -0700648static int init_image_riva_trusted(const u8 *metadata, size_t size)
649{
650 return init_image_trusted(PAS_RIVA, metadata, size);
651}
652
653static int reset_riva_trusted(void)
654{
655 return auth_and_reset_trusted(PAS_RIVA);
656}
657
658static int shutdown_riva_trusted(void)
659{
660 return shutdown_trusted(PAS_RIVA);
661}
662
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700663static int init_image_dsps_untrusted(const u8 *metadata, size_t size)
664{
665 /* Bring memory and bus interface out of reset */
666 writel_relaxed(0x2, PPSS_RESET);
667 writel_relaxed(0x10, PPSS_HCLK_CTL);
668 return 0;
669}
670
671static int reset_dsps_untrusted(void)
672{
673 writel_relaxed(0x10, PPSS_PROC_CLK_CTL);
674 /* Bring DSPS out of reset */
675 writel_relaxed(0x0, PPSS_RESET);
676 return 0;
677}
678
679static int shutdown_dsps_untrusted(void)
680{
681 writel_relaxed(0x2, PPSS_RESET);
682 writel_relaxed(0x0, PPSS_PROC_CLK_CTL);
683 return 0;
684}
685
Stephen Boyd9802ca92011-05-25 15:09:59 -0700686static int init_image_dsps_trusted(const u8 *metadata, size_t size)
687{
688 return init_image_trusted(PAS_DSPS, metadata, size);
689}
690
691static int reset_dsps_trusted(void)
692{
693 return auth_and_reset_trusted(PAS_DSPS);
694}
695
696static int shutdown_dsps_trusted(void)
697{
698 return shutdown_trusted(PAS_DSPS);
699}
700
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700701static struct pil_reset_ops pil_modem_fw_q6_ops = {
702 .init_image = init_image_modem_fw_q6_untrusted,
703 .verify_blob = verify_blob,
704 .auth_and_reset = reset_modem_fw_q6_untrusted,
705 .shutdown = shutdown_modem_fw_q6_untrusted,
706};
707
708static struct pil_reset_ops pil_modem_sw_q6_ops = {
709 .init_image = init_image_modem_sw_q6_untrusted,
710 .verify_blob = verify_blob,
711 .auth_and_reset = reset_modem_sw_q6_untrusted,
712 .shutdown = shutdown_modem_sw_q6_untrusted,
713};
714
715static struct pil_reset_ops pil_lpass_q6_ops = {
716 .init_image = init_image_lpass_q6_untrusted,
717 .verify_blob = verify_blob,
718 .auth_and_reset = reset_lpass_q6_untrusted,
719 .shutdown = shutdown_lpass_q6_untrusted,
720};
721
722static struct pil_reset_ops pil_riva_ops = {
723 .init_image = init_image_riva_untrusted,
724 .verify_blob = verify_blob,
725 .auth_and_reset = reset_riva_untrusted,
726 .shutdown = shutdown_riva_untrusted,
727};
728
729struct pil_reset_ops pil_dsps_ops = {
730 .init_image = init_image_dsps_untrusted,
731 .verify_blob = verify_blob,
732 .auth_and_reset = reset_dsps_untrusted,
733 .shutdown = shutdown_dsps_untrusted,
734};
735
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700736static struct pil_device pil_lpass_q6 = {
737 .name = "q6",
738 .pdev = {
739 .name = "pil_lpass_q6",
740 .id = -1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700741 },
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700742 .ops = &pil_lpass_q6_ops,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700743};
744
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700745static struct pil_device pil_modem_fw_q6 = {
746 .name = "modem_fw",
747 .depends_on = "q6",
748 .pdev = {
749 .name = "pil_modem_fw_q6",
750 .id = -1,
751 },
752 .ops = &pil_modem_fw_q6_ops,
753};
754
755static struct pil_device pil_modem_sw_q6 = {
756 .name = "modem",
757 .depends_on = "modem_fw",
758 .pdev = {
759 .name = "pil_modem_sw_q6",
760 .id = -1,
761 },
762 .ops = &pil_modem_sw_q6_ops,
763};
764
765static struct pil_device pil_riva = {
766 .name = "wcnss",
767 .pdev = {
768 .name = "pil_riva",
769 .id = -1,
770 },
771 .ops = &pil_riva_ops,
772};
773
774static struct pil_device pil_dsps = {
775 .name = "dsps",
776 .pdev = {
777 .name = "pil_dsps",
778 .id = -1,
779 },
780 .ops = &pil_dsps_ops,
781};
782
783static int __init q6_reset_init(struct q6_data *q6)
784{
785 int err;
786
787 q6->reg_base = ioremap(q6->reg_base_phys, SZ_256);
788 if (!q6->reg_base) {
789 err = -ENOMEM;
790 goto err_map;
791 }
792
793 q6->vreg = regulator_get(NULL, q6->name);
794 if (IS_ERR(q6->vreg)) {
795 err = PTR_ERR(q6->vreg);
796 goto err_vreg;
797 }
798
799 return 0;
800
801err_vreg:
802 iounmap(q6->reg_base);
803err_map:
804 return err;
805}
806
Saravana Kannan76cc49b2011-09-07 19:59:04 -0700807static int __init can_secure_boot(int id)
808{
809 int ret;
810 u32 periph = id;
811 u32 ret_val = 0;
812
813 ret = scm_call(SCM_SVC_PIL, PAS_IS_SUPPORTED_CMD, &periph,
814 sizeof(periph), &ret_val, sizeof(ret_val));
815 if (ret)
816 return ret;
817
818 return ret_val;
819}
820
Stephen Boyd9802ca92011-05-25 15:09:59 -0700821static bool secure_pil = true;
Saravana Kannan76cc49b2011-09-07 19:59:04 -0700822
823static void __init use_secure_pil(void)
824{
825
826 if (scm_is_call_available(SCM_SVC_PIL, PAS_IS_SUPPORTED_CMD) <= 0)
827 return;
828
829 if (can_secure_boot(PAS_Q6) > 0) {
830 pil_lpass_q6_ops.init_image = init_image_lpass_q6_trusted;
831 pil_lpass_q6_ops.auth_and_reset = reset_lpass_q6_trusted;
832 pil_lpass_q6_ops.shutdown = shutdown_lpass_q6_trusted;
833 }
834
835 if (can_secure_boot(PAS_MODEM_FW) > 0) {
836 pil_modem_fw_q6_ops.init_image = init_image_modem_fw_q6_trusted;
837 pil_modem_fw_q6_ops.auth_and_reset = reset_modem_fw_q6_trusted;
838 pil_modem_fw_q6_ops.shutdown = shutdown_modem_fw_q6_trusted;
839 }
840
841 if (can_secure_boot(PAS_MODEM_SW) > 0) {
842 pil_modem_sw_q6_ops.init_image = init_image_modem_sw_q6_trusted;
843 pil_modem_sw_q6_ops.auth_and_reset = reset_modem_sw_q6_trusted;
844 pil_modem_sw_q6_ops.shutdown = shutdown_modem_sw_q6_trusted;
845 }
846
847 if (can_secure_boot(PAS_DSPS) > 0) {
848 pil_dsps_ops.init_image = init_image_dsps_trusted;
849 pil_dsps_ops.auth_and_reset = reset_dsps_trusted;
850 pil_dsps_ops.shutdown = shutdown_dsps_trusted;
851 }
852
853 if (can_secure_boot(PAS_RIVA) > 0) {
854 pil_riva_ops.init_image = init_image_riva_trusted;
855 pil_riva_ops.auth_and_reset = reset_riva_trusted;
856 pil_riva_ops.shutdown = shutdown_riva_trusted;
857 }
858}
Stephen Boyd9802ca92011-05-25 15:09:59 -0700859
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860static int __init msm_peripheral_reset_init(void)
861{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 int err;
863
864 /*
865 * Don't initialize PIL on simulated targets, as some
866 * subsystems may not be emulated on them.
867 */
868 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3())
869 return 0;
870
Saravana Kannan76cc49b2011-09-07 19:59:04 -0700871 if (secure_pil)
872 use_secure_pil();
Stephen Boyd9802ca92011-05-25 15:09:59 -0700873
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700874 err = q6_reset_init(&q6_lpass);
875 if (err)
876 return err;
877 msm_pil_add_device(&pil_lpass_q6);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700879 mss_enable_reg = ioremap(MSM_MSS_ENABLE_PHYS, 4);
880 if (!mss_enable_reg)
881 return -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700882
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700883 err = q6_reset_init(&q6_modem_fw);
884 if (err) {
885 iounmap(mss_enable_reg);
886 return err;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 }
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700888 msm_pil_add_device(&pil_modem_fw_q6);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700890 err = q6_reset_init(&q6_modem_sw);
891 if (err)
892 return err;
893 msm_pil_add_device(&pil_modem_sw_q6);
894
895 msm_pil_add_device(&pil_dsps);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700896
897 msm_riva_base = ioremap(MSM_RIVA_PHYS, SZ_256);
Matt Wagantall0b2f9822011-07-12 20:11:28 -0700898 if (!msm_riva_base)
899 return -ENOMEM;
900 msm_pil_add_device(&pil_riva);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901
902 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903}
904arch_initcall(msm_peripheral_reset_init);
Stephen Boyd9802ca92011-05-25 15:09:59 -0700905module_param(secure_pil, bool, S_IRUGO);
906MODULE_PARM_DESC(secure_pil, "Use Secure PIL");