Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-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/clk.h> |
| 21 | #include <linux/timer.h> |
| 22 | #include <linux/jiffies.h> |
| 23 | |
| 24 | #include <mach/scm.h> |
| 25 | #include <mach/msm_iomap.h> |
| 26 | #include <mach/msm_xo.h> |
| 27 | |
| 28 | #include "peripheral-loader.h" |
| 29 | |
| 30 | #define PROXY_VOTE_TIMEOUT 10000 |
| 31 | |
| 32 | #define MSM_MMS_REGS_BASE 0x10200000 |
| 33 | #define MSM_LPASS_QDSP6SS_BASE 0x28800000 |
| 34 | |
| 35 | #define MARM_RESET (MSM_CLK_CTL_BASE + 0x2BD4) |
| 36 | #define MARM_BOOT_CONTROL (msm_mms_regs_base + 0x0010) |
| 37 | #define MAHB0_SFAB_PORT_RESET (MSM_CLK_CTL_BASE + 0x2304) |
| 38 | #define MARM_CLK_BRANCH_ENA_VOTE (MSM_CLK_CTL_BASE + 0x3000) |
| 39 | #define MARM_CLK_SRC0_NS (MSM_CLK_CTL_BASE + 0x2BC0) |
| 40 | #define MARM_CLK_SRC1_NS (MSM_CLK_CTL_BASE + 0x2BC4) |
| 41 | #define MARM_CLK_SRC_CTL (MSM_CLK_CTL_BASE + 0x2BC8) |
| 42 | #define MARM_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BCC) |
| 43 | #define SFAB_MSS_S_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2C00) |
| 44 | #define MSS_MODEM_CXO_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C44) |
| 45 | #define MSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60) |
| 46 | #define MSS_MARM_SYS_REF_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C64) |
| 47 | #define MAHB0_CLK_CTL (MSM_CLK_CTL_BASE + 0x2300) |
| 48 | #define MAHB1_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BE4) |
| 49 | #define MAHB2_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C20) |
| 50 | #define MAHB1_NS (MSM_CLK_CTL_BASE + 0x2BE0) |
| 51 | #define MARM_CLK_FS (MSM_CLK_CTL_BASE + 0x2BD0) |
| 52 | #define MAHB2_CLK_FS (MSM_CLK_CTL_BASE + 0x2C24) |
| 53 | #define PLL_ENA_MARM (MSM_CLK_CTL_BASE + 0x3500) |
| 54 | #define PLL8_STATUS (MSM_CLK_CTL_BASE + 0x3158) |
| 55 | #define CLK_HALT_MSS_SMPSS_MISC_STATE (MSM_CLK_CTL_BASE + 0x2FDC) |
| 56 | |
| 57 | #define LCC_Q6_FUNC (MSM_LPASS_CLK_CTL_BASE + 0x001C) |
| 58 | #define QDSP6SS_RST_EVB (msm_lpass_qdsp6ss_base + 0x0000) |
| 59 | #define QDSP6SS_STRAP_TCM (msm_lpass_qdsp6ss_base + 0x001C) |
| 60 | #define QDSP6SS_STRAP_AHB (msm_lpass_qdsp6ss_base + 0x0020) |
| 61 | |
| 62 | #define PPSS_RESET (MSM_CLK_CTL_BASE + 0x2594) |
| 63 | #define PPSS_PROC_CLK_CTL (MSM_CLK_CTL_BASE + 0x2588) |
| 64 | #define CLK_HALT_DFAB_STATE (MSM_CLK_CTL_BASE + 0x2FC8) |
| 65 | |
| 66 | #define PAS_MODEM 0 |
| 67 | #define PAS_Q6 1 |
| 68 | #define PAS_DSPS 2 |
| 69 | #define PAS_PLAYREADY 3 |
| 70 | |
| 71 | #define PAS_INIT_IMAGE_CMD 1 |
| 72 | #define PAS_MEM_CMD 2 |
| 73 | #define PAS_AUTH_AND_RESET_CMD 5 |
| 74 | #define PAS_SHUTDOWN_CMD 6 |
| 75 | |
| 76 | struct pas_init_image_req { |
| 77 | u32 proc; |
| 78 | u32 image_addr; |
| 79 | }; |
| 80 | |
| 81 | struct pas_init_image_resp { |
| 82 | u32 image_valid; |
| 83 | }; |
| 84 | |
| 85 | struct pas_auth_image_req { |
| 86 | u32 proc; |
| 87 | }; |
| 88 | |
| 89 | struct pas_auth_image_resp { |
| 90 | u32 reset_initiated; |
| 91 | }; |
| 92 | |
| 93 | struct pas_shutdown_req { |
| 94 | u32 proc; |
| 95 | }; |
| 96 | |
| 97 | struct pas_shutdown_resp { |
| 98 | u32 success; |
| 99 | }; |
| 100 | |
| 101 | static int modem_start, q6_start, dsps_start; |
| 102 | static void __iomem *msm_mms_regs_base; |
| 103 | static void __iomem *msm_lpass_qdsp6ss_base; |
| 104 | |
| 105 | static int init_image_trusted(int id, const u8 *metadata, size_t size) |
| 106 | { |
| 107 | int ret; |
| 108 | struct pas_init_image_req request; |
| 109 | struct pas_init_image_resp resp = {0}; |
| 110 | void *mdata_buf; |
| 111 | |
| 112 | /* Make memory physically contiguous */ |
| 113 | mdata_buf = kmemdup(metadata, size, GFP_KERNEL); |
| 114 | if (!mdata_buf) |
| 115 | return -ENOMEM; |
| 116 | |
| 117 | request.proc = id; |
| 118 | request.image_addr = virt_to_phys(mdata_buf); |
| 119 | |
| 120 | ret = scm_call(SCM_SVC_PIL, PAS_INIT_IMAGE_CMD, &request, |
| 121 | sizeof(request), &resp, sizeof(resp)); |
| 122 | kfree(mdata_buf); |
| 123 | |
| 124 | if (ret) |
| 125 | return ret; |
| 126 | return resp.image_valid; |
| 127 | } |
| 128 | |
| 129 | static int init_image_modem_trusted(const u8 *metadata, size_t size) |
| 130 | { |
| 131 | return init_image_trusted(PAS_MODEM, metadata, size); |
| 132 | } |
| 133 | |
| 134 | static int init_image_modem_untrusted(const u8 *metadata, size_t size) |
| 135 | { |
| 136 | struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 137 | modem_start = ehdr->e_entry; |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static int init_image_q6_trusted(const u8 *metadata, size_t size) |
| 142 | { |
| 143 | return init_image_trusted(PAS_Q6, metadata, size); |
| 144 | } |
| 145 | |
| 146 | static int init_image_q6_untrusted(const u8 *metadata, size_t size) |
| 147 | { |
| 148 | struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 149 | q6_start = ehdr->e_entry; |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static int init_image_dsps_trusted(const u8 *metadata, size_t size) |
| 154 | { |
| 155 | return init_image_trusted(PAS_DSPS, metadata, size); |
| 156 | } |
| 157 | |
| 158 | static int init_image_dsps_untrusted(const u8 *metadata, size_t size) |
| 159 | { |
| 160 | struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 161 | dsps_start = ehdr->e_entry; |
| 162 | /* Bring memory and bus interface out of reset */ |
| 163 | __raw_writel(0x2, PPSS_RESET); |
| 164 | mb(); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int verify_blob(u32 phy_addr, size_t size) |
| 169 | { |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int auth_and_reset_trusted(int id) |
| 174 | { |
| 175 | int ret; |
| 176 | struct pas_auth_image_req request; |
| 177 | struct pas_auth_image_resp resp = {0}; |
| 178 | |
| 179 | request.proc = id; |
| 180 | ret = scm_call(SCM_SVC_PIL, PAS_AUTH_AND_RESET_CMD, &request, |
| 181 | sizeof(request), &resp, sizeof(resp)); |
| 182 | if (ret) |
| 183 | return ret; |
| 184 | |
| 185 | return resp.reset_initiated; |
| 186 | } |
| 187 | |
| 188 | static struct msm_xo_voter *pxo; |
| 189 | static void remove_modem_proxy_votes(unsigned long data) |
| 190 | { |
| 191 | msm_xo_mode_vote(pxo, MSM_XO_MODE_OFF); |
| 192 | } |
| 193 | static DEFINE_TIMER(modem_timer, remove_modem_proxy_votes, 0, 0); |
| 194 | |
| 195 | static void make_modem_proxy_votes(void) |
| 196 | { |
| 197 | /* Make proxy votes for modem and set up timer to disable it. */ |
| 198 | msm_xo_mode_vote(pxo, MSM_XO_MODE_ON); |
| 199 | mod_timer(&modem_timer, jiffies + msecs_to_jiffies(PROXY_VOTE_TIMEOUT)); |
| 200 | } |
| 201 | |
| 202 | static void remove_modem_proxy_votes_now(void) |
| 203 | { |
| 204 | /* |
| 205 | * If the modem proxy vote hasn't been removed yet, them remove the |
| 206 | * votes immediately. |
| 207 | */ |
| 208 | if (del_timer(&modem_timer)) |
| 209 | remove_modem_proxy_votes(0); |
| 210 | } |
| 211 | |
| 212 | static int reset_modem_untrusted(void) |
| 213 | { |
| 214 | u32 reg; |
| 215 | |
| 216 | make_modem_proxy_votes(); |
| 217 | |
| 218 | /* Put modem AHB0,1,2 clocks into reset */ |
| 219 | __raw_writel(BIT(0) | BIT(1), MAHB0_SFAB_PORT_RESET); |
| 220 | __raw_writel(BIT(7), MAHB1_CLK_CTL); |
| 221 | __raw_writel(BIT(7), MAHB2_CLK_CTL); |
| 222 | |
| 223 | /* Vote for pll8 on behalf of the modem */ |
| 224 | reg = __raw_readl(PLL_ENA_MARM); |
| 225 | reg |= BIT(8); |
| 226 | __raw_writel(reg, PLL_ENA_MARM); |
| 227 | |
| 228 | /* Wait for PLL8 to enable */ |
| 229 | while (!(__raw_readl(PLL8_STATUS) & BIT(16))) |
| 230 | cpu_relax(); |
| 231 | |
| 232 | /* Set MAHB1 divider to Div-5 to run MAHB1,2 and sfab at 79.8 Mhz*/ |
| 233 | __raw_writel(0x4, MAHB1_NS); |
| 234 | |
| 235 | /* Vote for modem AHB1 and 2 clocks to be on on behalf of the modem */ |
| 236 | reg = __raw_readl(MARM_CLK_BRANCH_ENA_VOTE); |
| 237 | reg |= BIT(0) | BIT(1); |
| 238 | __raw_writel(reg, MARM_CLK_BRANCH_ENA_VOTE); |
| 239 | |
| 240 | /* Source marm_clk off of PLL8 */ |
| 241 | reg = __raw_readl(MARM_CLK_SRC_CTL); |
| 242 | if ((reg & 0x1) == 0) { |
| 243 | __raw_writel(0x3, MARM_CLK_SRC1_NS); |
| 244 | reg |= 0x1; |
| 245 | } else { |
| 246 | __raw_writel(0x3, MARM_CLK_SRC0_NS); |
| 247 | reg &= ~0x1; |
| 248 | } |
| 249 | __raw_writel(reg | 0x2, MARM_CLK_SRC_CTL); |
| 250 | |
| 251 | /* |
| 252 | * Force core on and periph on signals to remain active during halt |
| 253 | * for marm_clk and mahb2_clk |
| 254 | */ |
| 255 | __raw_writel(0x6F, MARM_CLK_FS); |
| 256 | __raw_writel(0x6F, MAHB2_CLK_FS); |
| 257 | |
| 258 | /* |
| 259 | * Enable all of the marm_clk branches, cxo sourced marm branches, |
| 260 | * and sleep clock branches |
| 261 | */ |
| 262 | __raw_writel(0x10, MARM_CLK_CTL); |
| 263 | __raw_writel(0x10, MAHB0_CLK_CTL); |
| 264 | __raw_writel(0x10, SFAB_MSS_S_HCLK_CTL); |
| 265 | __raw_writel(0x10, MSS_MODEM_CXO_CLK_CTL); |
| 266 | __raw_writel(0x10, MSS_SLP_CLK_CTL); |
| 267 | __raw_writel(0x10, MSS_MARM_SYS_REF_CLK_CTL); |
| 268 | |
| 269 | /* Wait for above clocks to be turned on */ |
| 270 | while (__raw_readl(CLK_HALT_MSS_SMPSS_MISC_STATE) & (BIT(7) | BIT(8) | |
| 271 | BIT(9) | BIT(10) | BIT(4) | BIT(6))) |
| 272 | cpu_relax(); |
| 273 | |
| 274 | /* Take MAHB0,1,2 clocks out of reset */ |
| 275 | __raw_writel(0x0, MAHB2_CLK_CTL); |
| 276 | __raw_writel(0x0, MAHB1_CLK_CTL); |
| 277 | __raw_writel(0x0, MAHB0_SFAB_PORT_RESET); |
| 278 | |
| 279 | /* Setup exception vector table base address */ |
| 280 | __raw_writel(modem_start | 0x1, MARM_BOOT_CONTROL); |
| 281 | |
| 282 | /* Wait for vector table to be setup */ |
| 283 | mb(); |
| 284 | |
| 285 | /* Bring modem out of reset */ |
| 286 | __raw_writel(0x0, MARM_RESET); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static int reset_modem_trusted(void) |
| 292 | { |
| 293 | int ret; |
| 294 | |
| 295 | make_modem_proxy_votes(); |
| 296 | |
| 297 | ret = auth_and_reset_trusted(PAS_MODEM); |
| 298 | if (ret) |
| 299 | remove_modem_proxy_votes_now(); |
| 300 | |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | static int shutdown_trusted(int id) |
| 305 | { |
| 306 | int ret; |
| 307 | struct pas_shutdown_req request; |
| 308 | struct pas_shutdown_resp resp = {0}; |
| 309 | |
| 310 | request.proc = id; |
| 311 | ret = scm_call(SCM_SVC_PIL, PAS_SHUTDOWN_CMD, &request, sizeof(request), |
| 312 | &resp, sizeof(resp)); |
| 313 | if (ret) |
| 314 | return ret; |
| 315 | |
| 316 | return resp.success; |
| 317 | } |
| 318 | |
| 319 | static int shutdown_modem_untrusted(void) |
| 320 | { |
| 321 | u32 reg; |
| 322 | |
| 323 | /* Put modem into reset */ |
| 324 | __raw_writel(0x1, MARM_RESET); |
| 325 | mb(); |
| 326 | |
| 327 | /* Put modem AHB0,1,2 clocks into reset */ |
| 328 | __raw_writel(BIT(0) | BIT(1), MAHB0_SFAB_PORT_RESET); |
| 329 | __raw_writel(BIT(7), MAHB1_CLK_CTL); |
| 330 | __raw_writel(BIT(7), MAHB2_CLK_CTL); |
| 331 | mb(); |
| 332 | |
| 333 | /* |
| 334 | * Disable all of the marm_clk branches, cxo sourced marm branches, |
| 335 | * and sleep clock branches |
| 336 | */ |
| 337 | __raw_writel(0x0, MARM_CLK_CTL); |
| 338 | __raw_writel(0x0, MAHB0_CLK_CTL); |
| 339 | __raw_writel(0x0, SFAB_MSS_S_HCLK_CTL); |
| 340 | __raw_writel(0x0, MSS_MODEM_CXO_CLK_CTL); |
| 341 | __raw_writel(0x0, MSS_SLP_CLK_CTL); |
| 342 | __raw_writel(0x0, MSS_MARM_SYS_REF_CLK_CTL); |
| 343 | |
| 344 | /* Disable marm_clk */ |
| 345 | reg = __raw_readl(MARM_CLK_SRC_CTL); |
| 346 | reg &= ~0x2; |
| 347 | __raw_writel(reg, MARM_CLK_SRC_CTL); |
| 348 | |
| 349 | /* Clear modem's votes for ahb clocks */ |
| 350 | __raw_writel(0x0, MARM_CLK_BRANCH_ENA_VOTE); |
| 351 | |
| 352 | /* Clear modem's votes for PLLs */ |
| 353 | __raw_writel(0x0, PLL_ENA_MARM); |
| 354 | |
| 355 | remove_modem_proxy_votes_now(); |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static int shutdown_modem_trusted(void) |
| 361 | { |
| 362 | int ret; |
| 363 | |
| 364 | ret = shutdown_trusted(PAS_MODEM); |
| 365 | if (ret) |
| 366 | return ret; |
| 367 | |
| 368 | remove_modem_proxy_votes_now(); |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | #define LV_EN BIT(27) |
| 374 | #define STOP_CORE BIT(26) |
| 375 | #define CLAMP_IO BIT(25) |
| 376 | #define Q6SS_PRIV_ARES BIT(24) |
| 377 | #define Q6SS_SS_ARES BIT(23) |
| 378 | #define Q6SS_ISDB_ARES BIT(22) |
| 379 | #define Q6SS_ETM_ARES BIT(21) |
| 380 | #define Q6_JTAG_CRC_EN BIT(20) |
| 381 | #define Q6_JTAG_INV_EN BIT(19) |
| 382 | #define Q6_JTAG_CXC_EN BIT(18) |
| 383 | #define Q6_PXO_CRC_EN BIT(17) |
| 384 | #define Q6_PXO_INV_EN BIT(16) |
| 385 | #define Q6_PXO_CXC_EN BIT(15) |
| 386 | #define Q6_PXO_SLEEP_EN BIT(14) |
| 387 | #define Q6_SLP_CRC_EN BIT(13) |
| 388 | #define Q6_SLP_INV_EN BIT(12) |
| 389 | #define Q6_SLP_CXC_EN BIT(11) |
| 390 | #define CORE_ARES BIT(10) |
| 391 | #define CORE_L1_MEM_CORE_EN BIT(9) |
| 392 | #define CORE_TCM_MEM_CORE_EN BIT(8) |
| 393 | #define CORE_TCM_MEM_PERPH_EN BIT(7) |
| 394 | #define CORE_GFM4_CLK_EN BIT(2) |
| 395 | #define CORE_GFM4_RES BIT(1) |
| 396 | #define RAMP_PLL_SRC_SEL BIT(0) |
| 397 | |
| 398 | #define Q6_STRAP_AHB_UPPER (0x290 << 12) |
| 399 | #define Q6_STRAP_AHB_LOWER 0x280 |
| 400 | #define Q6_STRAP_TCM_BASE (0x28C << 15) |
| 401 | #define Q6_STRAP_TCM_CONFIG 0x28B |
| 402 | |
| 403 | static struct clk *pll4; |
| 404 | |
| 405 | static void remove_q6_proxy_votes(unsigned long data) |
| 406 | { |
| 407 | clk_disable(pll4); |
| 408 | } |
| 409 | static DEFINE_TIMER(q6_timer, remove_q6_proxy_votes, 0, 0); |
| 410 | |
| 411 | static void make_q6_proxy_votes(void) |
| 412 | { |
| 413 | /* Make proxy votes for Q6 and set up timer to disable it. */ |
| 414 | clk_enable(pll4); |
| 415 | mod_timer(&q6_timer, jiffies + msecs_to_jiffies(PROXY_VOTE_TIMEOUT)); |
| 416 | } |
| 417 | |
| 418 | static void remove_q6_proxy_votes_now(void) |
| 419 | { |
| 420 | /* |
| 421 | * If the Q6 proxy vote hasn't been removed yet, them remove the |
| 422 | * votes immediately. |
| 423 | */ |
| 424 | if (del_timer(&q6_timer)) |
| 425 | remove_q6_proxy_votes(0); |
| 426 | } |
| 427 | |
| 428 | static int reset_q6_untrusted(void) |
| 429 | { |
| 430 | u32 reg; |
| 431 | |
| 432 | make_q6_proxy_votes(); |
| 433 | |
| 434 | /* Put Q6 into reset */ |
| 435 | reg = __raw_readl(LCC_Q6_FUNC); |
| 436 | reg |= Q6SS_SS_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES | STOP_CORE | |
| 437 | CORE_ARES; |
| 438 | reg &= ~CORE_GFM4_CLK_EN; |
| 439 | __raw_writel(reg, LCC_Q6_FUNC); |
| 440 | |
| 441 | /* Wait 8 AHB cycles for Q6 to be fully reset (AHB = 1.5Mhz) */ |
| 442 | usleep_range(20, 30); |
| 443 | |
| 444 | /* Turn on Q6 memory */ |
| 445 | reg |= CORE_GFM4_CLK_EN | CORE_L1_MEM_CORE_EN | CORE_TCM_MEM_CORE_EN | |
| 446 | CORE_TCM_MEM_PERPH_EN; |
| 447 | __raw_writel(reg, LCC_Q6_FUNC); |
| 448 | |
| 449 | /* Turn on Q6 core clocks and take core out of reset */ |
| 450 | reg &= ~(CLAMP_IO | Q6SS_SS_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES | |
| 451 | CORE_ARES); |
| 452 | __raw_writel(reg, LCC_Q6_FUNC); |
| 453 | |
| 454 | /* Wait for clocks to be enabled */ |
| 455 | mb(); |
| 456 | /* Program boot address */ |
| 457 | __raw_writel((q6_start >> 12) & 0xFFFFF, QDSP6SS_RST_EVB); |
| 458 | |
| 459 | __raw_writel(Q6_STRAP_TCM_CONFIG | Q6_STRAP_TCM_BASE, |
| 460 | QDSP6SS_STRAP_TCM); |
| 461 | __raw_writel(Q6_STRAP_AHB_UPPER | Q6_STRAP_AHB_LOWER, |
| 462 | QDSP6SS_STRAP_AHB); |
| 463 | |
| 464 | /* Wait for addresses to be programmed before starting Q6 */ |
| 465 | mb(); |
| 466 | |
| 467 | /* Start Q6 instruction execution */ |
| 468 | reg &= ~STOP_CORE; |
| 469 | __raw_writel(reg, LCC_Q6_FUNC); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int reset_q6_trusted(void) |
| 475 | { |
| 476 | make_q6_proxy_votes(); |
| 477 | |
| 478 | return auth_and_reset_trusted(PAS_Q6); |
| 479 | } |
| 480 | |
| 481 | static int shutdown_q6_untrusted(void) |
| 482 | { |
| 483 | u32 reg; |
| 484 | |
| 485 | /* Put Q6 into reset */ |
| 486 | reg = __raw_readl(LCC_Q6_FUNC); |
| 487 | reg |= Q6SS_SS_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES | STOP_CORE | |
| 488 | CORE_ARES; |
| 489 | reg &= ~CORE_GFM4_CLK_EN; |
| 490 | __raw_writel(reg, LCC_Q6_FUNC); |
| 491 | |
| 492 | /* Wait 8 AHB cycles for Q6 to be fully reset (AHB = 1.5Mhz) */ |
| 493 | usleep_range(20, 30); |
| 494 | |
| 495 | /* Turn off Q6 memory */ |
| 496 | reg &= ~(CORE_L1_MEM_CORE_EN | CORE_TCM_MEM_CORE_EN | |
| 497 | CORE_TCM_MEM_PERPH_EN); |
| 498 | __raw_writel(reg, LCC_Q6_FUNC); |
| 499 | |
| 500 | reg |= CLAMP_IO; |
| 501 | __raw_writel(reg, LCC_Q6_FUNC); |
| 502 | |
| 503 | remove_q6_proxy_votes_now(); |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static int shutdown_q6_trusted(void) |
| 509 | { |
| 510 | int ret; |
| 511 | |
| 512 | ret = shutdown_trusted(PAS_Q6); |
| 513 | if (ret) |
| 514 | return ret; |
| 515 | |
| 516 | remove_q6_proxy_votes_now(); |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | static int reset_dsps_untrusted(void) |
| 522 | { |
| 523 | __raw_writel(0x10, PPSS_PROC_CLK_CTL); |
| 524 | while (__raw_readl(CLK_HALT_DFAB_STATE) & BIT(18)) |
| 525 | cpu_relax(); |
| 526 | |
| 527 | /* Bring DSPS out of reset */ |
| 528 | __raw_writel(0x0, PPSS_RESET); |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int reset_dsps_trusted(void) |
| 533 | { |
| 534 | return auth_and_reset_trusted(PAS_DSPS); |
| 535 | } |
| 536 | |
| 537 | static int shutdown_dsps_trusted(void) |
| 538 | { |
| 539 | return shutdown_trusted(PAS_DSPS); |
| 540 | } |
| 541 | |
| 542 | static int shutdown_dsps_untrusted(void) |
| 543 | { |
| 544 | __raw_writel(0x2, PPSS_RESET); |
| 545 | __raw_writel(0x0, PPSS_PROC_CLK_CTL); |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | static int init_image_playready(const u8 *metadata, size_t size) |
| 550 | { |
| 551 | return init_image_trusted(PAS_PLAYREADY, metadata, size); |
| 552 | } |
| 553 | |
| 554 | static int reset_playready(void) |
| 555 | { |
| 556 | return auth_and_reset_trusted(PAS_PLAYREADY); |
| 557 | } |
| 558 | |
| 559 | static int shutdown_playready(void) |
| 560 | { |
| 561 | return shutdown_trusted(PAS_PLAYREADY); |
| 562 | } |
| 563 | |
| 564 | struct pil_reset_ops pil_modem_ops = { |
| 565 | .init_image = init_image_modem_untrusted, |
| 566 | .verify_blob = verify_blob, |
| 567 | .auth_and_reset = reset_modem_untrusted, |
| 568 | .shutdown = shutdown_modem_untrusted, |
| 569 | }; |
| 570 | |
| 571 | struct pil_reset_ops pil_q6_ops = { |
| 572 | .init_image = init_image_q6_untrusted, |
| 573 | .verify_blob = verify_blob, |
| 574 | .auth_and_reset = reset_q6_untrusted, |
| 575 | .shutdown = shutdown_q6_untrusted, |
| 576 | }; |
| 577 | |
| 578 | struct pil_reset_ops pil_dsps_ops = { |
| 579 | .init_image = init_image_dsps_untrusted, |
| 580 | .verify_blob = verify_blob, |
| 581 | .auth_and_reset = reset_dsps_untrusted, |
| 582 | .shutdown = shutdown_dsps_untrusted, |
| 583 | }; |
| 584 | |
| 585 | struct pil_reset_ops pil_playready_ops = { |
| 586 | .init_image = init_image_playready, |
| 587 | .verify_blob = verify_blob, |
| 588 | .auth_and_reset = reset_playready, |
| 589 | .shutdown = shutdown_playready, |
| 590 | }; |
| 591 | |
| 592 | static struct pil_device peripherals[] = { |
| 593 | { |
| 594 | .name = "modem", |
| 595 | .depends_on = "q6", |
| 596 | .pdev = { |
| 597 | .name = "pil_modem", |
| 598 | .id = -1, |
| 599 | }, |
| 600 | .ops = &pil_modem_ops, |
| 601 | }, |
| 602 | { |
| 603 | .name = "q6", |
| 604 | .pdev = { |
| 605 | .name = "pil_q6", |
| 606 | .id = -1, |
| 607 | }, |
| 608 | .ops = &pil_q6_ops, |
| 609 | }, |
| 610 | { |
| 611 | .name = "playrdy", |
| 612 | .pdev = { |
| 613 | .name = "pil_playready", |
| 614 | .id = -1, |
| 615 | }, |
| 616 | .ops = &pil_playready_ops, |
| 617 | }, |
| 618 | }; |
| 619 | |
| 620 | struct pil_device peripheral_dsps = { |
| 621 | .name = "dsps", |
| 622 | .pdev = { |
| 623 | .name = "pil_dsps", |
| 624 | .id = -1, |
| 625 | }, |
| 626 | .ops = &pil_dsps_ops, |
| 627 | }; |
| 628 | |
| 629 | #ifdef CONFIG_MSM_SECURE_PIL |
| 630 | #define SECURE_PIL 1 |
| 631 | #else |
| 632 | #define SECURE_PIL 0 |
| 633 | #endif |
| 634 | |
| 635 | static int __init msm_peripheral_reset_init(void) |
| 636 | { |
| 637 | unsigned i; |
| 638 | |
| 639 | msm_mms_regs_base = ioremap(MSM_MMS_REGS_BASE, SZ_256); |
| 640 | if (!msm_mms_regs_base) |
| 641 | goto err; |
| 642 | |
| 643 | msm_lpass_qdsp6ss_base = ioremap(MSM_LPASS_QDSP6SS_BASE, SZ_256); |
| 644 | if (!msm_lpass_qdsp6ss_base) |
| 645 | goto err_lpass; |
| 646 | |
| 647 | pxo = msm_xo_get(MSM_XO_PXO, "pil"); |
| 648 | if (IS_ERR(pxo)) |
| 649 | goto err_pxo; |
| 650 | |
| 651 | pll4 = clk_get_sys("peripheral-reset", "pll4"); |
| 652 | if (IS_ERR(pll4)) |
| 653 | goto err_clk; |
| 654 | |
| 655 | if (SECURE_PIL) { |
| 656 | pil_modem_ops.init_image = init_image_modem_trusted; |
| 657 | pil_modem_ops.auth_and_reset = reset_modem_trusted; |
| 658 | pil_modem_ops.shutdown = shutdown_modem_trusted; |
| 659 | |
| 660 | pil_q6_ops.init_image = init_image_q6_trusted; |
| 661 | pil_q6_ops.auth_and_reset = reset_q6_trusted; |
| 662 | pil_q6_ops.shutdown = shutdown_q6_trusted; |
| 663 | |
| 664 | pil_dsps_ops.init_image = init_image_dsps_trusted; |
| 665 | pil_dsps_ops.auth_and_reset = reset_dsps_trusted; |
| 666 | pil_dsps_ops.shutdown = shutdown_dsps_trusted; |
| 667 | } |
| 668 | |
| 669 | for (i = 0; i < ARRAY_SIZE(peripherals); i++) |
| 670 | msm_pil_add_device(&peripherals[i]); |
| 671 | |
| 672 | return 0; |
| 673 | |
| 674 | err_clk: |
| 675 | msm_xo_put(pxo); |
| 676 | err_pxo: |
| 677 | iounmap(msm_lpass_qdsp6ss_base); |
| 678 | err_lpass: |
| 679 | iounmap(msm_mms_regs_base); |
| 680 | err: |
| 681 | return -ENOMEM; |
| 682 | } |
| 683 | |
| 684 | static void __exit msm_peripheral_reset_exit(void) |
| 685 | { |
| 686 | iounmap(msm_mms_regs_base); |
| 687 | iounmap(msm_lpass_qdsp6ss_base); |
| 688 | } |
| 689 | |
| 690 | arch_initcall(msm_peripheral_reset_init); |
| 691 | module_exit(msm_peripheral_reset_exit); |
| 692 | |
| 693 | MODULE_LICENSE("GPL v2"); |
| 694 | MODULE_DESCRIPTION("Validate and bring peripherals out of reset"); |