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> |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | |
| 25 | #include <asm/mach-types.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | |
| 27 | #include <mach/scm.h> |
| 28 | #include <mach/msm_iomap.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | |
| 30 | #include "peripheral-loader.h" |
Stephen Boyd | e44ec39 | 2011-08-29 12:03:24 -0700 | [diff] [blame] | 31 | #include "scm-pas.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | #define PPSS_RESET (MSM_CLK_CTL_BASE + 0x2594) |
| 34 | #define PPSS_PROC_CLK_CTL (MSM_CLK_CTL_BASE + 0x2588) |
| 35 | #define CLK_HALT_DFAB_STATE (MSM_CLK_CTL_BASE + 0x2FC8) |
| 36 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame^] | 37 | static int dsps_start; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 39 | static int init_image_dsps_trusted(struct pil_desc *pil, const u8 *metadata, |
Stephen Boyd | 5bd999a | 2011-08-02 18:50:57 -0700 | [diff] [blame] | 40 | size_t size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | { |
Stephen Boyd | e44ec39 | 2011-08-29 12:03:24 -0700 | [diff] [blame] | 42 | return pas_init_image(PAS_DSPS, metadata, size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 45 | static int init_image_dsps_untrusted(struct pil_desc *pil, const u8 *metadata, |
Stephen Boyd | 5bd999a | 2011-08-02 18:50:57 -0700 | [diff] [blame] | 46 | size_t size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | { |
| 48 | struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 49 | dsps_start = ehdr->e_entry; |
| 50 | /* Bring memory and bus interface out of reset */ |
| 51 | __raw_writel(0x2, PPSS_RESET); |
| 52 | mb(); |
| 53 | return 0; |
| 54 | } |
| 55 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 56 | static int verify_blob(struct pil_desc *pil, u32 phy_addr, size_t size) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 61 | static int reset_dsps_untrusted(struct pil_desc *pil) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | { |
| 63 | __raw_writel(0x10, PPSS_PROC_CLK_CTL); |
| 64 | while (__raw_readl(CLK_HALT_DFAB_STATE) & BIT(18)) |
| 65 | cpu_relax(); |
| 66 | |
| 67 | /* Bring DSPS out of reset */ |
| 68 | __raw_writel(0x0, PPSS_RESET); |
| 69 | return 0; |
| 70 | } |
| 71 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 72 | static int reset_dsps_trusted(struct pil_desc *pil) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | { |
Stephen Boyd | e44ec39 | 2011-08-29 12:03:24 -0700 | [diff] [blame] | 74 | return pas_auth_and_reset(PAS_DSPS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 77 | static int shutdown_dsps_trusted(struct pil_desc *pil) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | { |
Stephen Boyd | e44ec39 | 2011-08-29 12:03:24 -0700 | [diff] [blame] | 79 | return pas_shutdown(PAS_DSPS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 82 | static int shutdown_dsps_untrusted(struct pil_desc *pil) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 83 | { |
| 84 | __raw_writel(0x2, PPSS_RESET); |
| 85 | __raw_writel(0x0, PPSS_PROC_CLK_CTL); |
| 86 | return 0; |
| 87 | } |
| 88 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 89 | struct pil_reset_ops pil_dsps_ops = { |
| 90 | .init_image = init_image_dsps_untrusted, |
| 91 | .verify_blob = verify_blob, |
| 92 | .auth_and_reset = reset_dsps_untrusted, |
| 93 | .shutdown = shutdown_dsps_untrusted, |
| 94 | }; |
| 95 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 96 | static struct platform_device pil_dsps = { |
| 97 | .name = "pil_dsps", |
| 98 | }; |
| 99 | |
| 100 | static struct pil_desc pil_dsps_desc = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 101 | .name = "dsps", |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 102 | .dev = &pil_dsps.dev, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | .ops = &pil_dsps_ops, |
| 104 | }; |
| 105 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 106 | static int __init msm_peripheral_reset_init(void) |
| 107 | { |
Stephen Boyd | e44ec39 | 2011-08-29 12:03:24 -0700 | [diff] [blame] | 108 | if (pas_supported(PAS_DSPS) > 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 109 | pil_dsps_ops.init_image = init_image_dsps_trusted; |
| 110 | pil_dsps_ops.auth_and_reset = reset_dsps_trusted; |
| 111 | pil_dsps_ops.shutdown = shutdown_dsps_trusted; |
| 112 | } |
| 113 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 114 | if (machine_is_msm8x60_fluid()) |
| 115 | pil_dsps_desc.name = "dsps_fluid"; |
| 116 | BUG_ON(platform_device_register(&pil_dsps)); |
| 117 | BUG_ON(msm_pil_register(&pil_dsps_desc)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 118 | |
| 119 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | arch_initcall(msm_peripheral_reset_init); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 123 | |
| 124 | MODULE_LICENSE("GPL v2"); |
| 125 | MODULE_DESCRIPTION("Validate and bring peripherals out of reset"); |