Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/elf.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/platform_device.h> |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 22 | #include <linux/clk.h> |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 23 | #include <linux/smp.h> |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 24 | #include <linux/miscdevice.h> |
| 25 | #include <linux/reboot.h> |
| 26 | #include <linux/interrupt.h> |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 27 | |
| 28 | #include <mach/msm_iomap.h> |
| 29 | #include <mach/msm_xo.h> |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 30 | #include <mach/socinfo.h> |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 31 | #include <mach/msm_bus_board.h> |
| 32 | #include <mach/msm_bus.h> |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 33 | #include <mach/subsystem_restart.h> |
| 34 | #include <mach/peripheral-loader.h> |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 35 | |
| 36 | #include "peripheral-loader.h" |
| 37 | #include "scm-pas.h" |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 38 | #include "smd_private.h" |
| 39 | #include "ramdump.h" |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 40 | |
| 41 | #define GSS_CSR_AHB_CLK_SEL 0x0 |
| 42 | #define GSS_CSR_RESET 0x4 |
| 43 | #define GSS_CSR_CLK_BLK_CONFIG 0x8 |
| 44 | #define GSS_CSR_CLK_ENABLE 0xC |
| 45 | #define GSS_CSR_BOOT_REMAP 0x14 |
| 46 | #define GSS_CSR_POWER_UP_DOWN 0x18 |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 47 | #define GSS_CSR_CFG_HID 0x2C |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 48 | |
| 49 | #define GSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60) |
| 50 | #define GSS_RESET (MSM_CLK_CTL_BASE + 0x2C64) |
| 51 | #define GSS_CLAMP_ENA (MSM_CLK_CTL_BASE + 0x2C68) |
| 52 | #define GSS_CXO_SRC_CTL (MSM_CLK_CTL_BASE + 0x2C74) |
| 53 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 54 | #define PLL5_STATUS (MSM_CLK_CTL_BASE + 0x30F8) |
| 55 | #define PLL_ENA_GSS (MSM_CLK_CTL_BASE + 0x3480) |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 56 | |
| 57 | #define PLL5_VOTE BIT(5) |
| 58 | #define PLL_STATUS BIT(16) |
| 59 | #define REMAP_ENABLE BIT(16) |
| 60 | #define A5_POWER_STATUS BIT(4) |
| 61 | #define A5_POWER_ENA BIT(0) |
| 62 | #define NAV_POWER_ENA BIT(1) |
| 63 | #define XO_CLK_BRANCH_ENA BIT(0) |
| 64 | #define SLP_CLK_BRANCH_ENA BIT(4) |
| 65 | #define A5_RESET BIT(0) |
| 66 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 67 | struct gss_data { |
| 68 | void __iomem *base; |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 69 | void __iomem *qgic2_base; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 70 | unsigned long start_addr; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 71 | struct clk *xo; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 72 | struct pil_device *pil; |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 73 | struct miscdevice misc_dev; |
| 74 | struct subsys_device *subsys; |
| 75 | struct subsys_desc subsys_desc; |
| 76 | int crash_shutdown; |
| 77 | int irq; |
Stephen Boyd | 4684add | 2012-06-27 12:57:18 -0700 | [diff] [blame^] | 78 | void *subsys_handle; |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 79 | struct ramdump_device *ramdump_dev; |
| 80 | struct ramdump_device *smem_ramdump_dev; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 83 | static int pil_gss_init_image(struct pil_desc *pil, const u8 *metadata, |
| 84 | size_t size) |
| 85 | { |
| 86 | const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 87 | struct gss_data *drv = dev_get_drvdata(pil->dev); |
| 88 | drv->start_addr = ehdr->e_entry; |
| 89 | return 0; |
| 90 | } |
| 91 | |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 92 | static int make_gss_proxy_votes(struct pil_desc *pil) |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 93 | { |
| 94 | int ret; |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 95 | struct gss_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 96 | |
| 97 | ret = clk_prepare_enable(drv->xo); |
| 98 | if (ret) { |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 99 | dev_err(pil->dev, "Failed to enable XO\n"); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 100 | return ret; |
| 101 | } |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 105 | static void remove_gss_proxy_votes(struct pil_desc *pil) |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 106 | { |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 107 | struct gss_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 108 | clk_disable_unprepare(drv->xo); |
| 109 | } |
| 110 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 111 | static void gss_init(struct gss_data *drv) |
| 112 | { |
| 113 | void __iomem *base = drv->base; |
| 114 | |
| 115 | /* Supply clocks to GSS. */ |
| 116 | writel_relaxed(XO_CLK_BRANCH_ENA, GSS_CXO_SRC_CTL); |
| 117 | writel_relaxed(SLP_CLK_BRANCH_ENA, GSS_SLP_CLK_CTL); |
| 118 | |
| 119 | /* Deassert GSS reset and clamps. */ |
| 120 | writel_relaxed(0x0, GSS_RESET); |
| 121 | writel_relaxed(0x0, GSS_CLAMP_ENA); |
| 122 | mb(); |
| 123 | |
| 124 | /* |
| 125 | * Configure clock source and dividers for 288MHz core, 144MHz AXI and |
| 126 | * 72MHz AHB, all derived from the 288MHz PLL. |
| 127 | */ |
| 128 | writel_relaxed(0x341, base + GSS_CSR_CLK_BLK_CONFIG); |
| 129 | writel_relaxed(0x1, base + GSS_CSR_AHB_CLK_SEL); |
| 130 | |
| 131 | /* Assert all GSS resets. */ |
| 132 | writel_relaxed(0x7F, base + GSS_CSR_RESET); |
| 133 | |
| 134 | /* Enable all bus clocks and wait for resets to propagate. */ |
| 135 | writel_relaxed(0x1F, base + GSS_CSR_CLK_ENABLE); |
| 136 | mb(); |
| 137 | udelay(1); |
| 138 | |
| 139 | /* Release subsystem from reset, but leave A5 in reset. */ |
| 140 | writel_relaxed(A5_RESET, base + GSS_CSR_RESET); |
| 141 | } |
| 142 | |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 143 | static void cfg_qgic2_bus_access(void *data) |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 144 | { |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 145 | struct gss_data *drv = data; |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 146 | int i; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 147 | |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 148 | /* |
| 149 | * Apply a 8064 v1.0 workaround to configure QGIC bus access. |
| 150 | * This must be done from Krait 0 to configure the Master ID |
| 151 | * correctly. |
| 152 | */ |
| 153 | writel_relaxed(0x2, drv->base + GSS_CSR_CFG_HID); |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 154 | for (i = 0; i <= 3; i++) |
| 155 | readl_relaxed(drv->qgic2_base); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static int pil_gss_shutdown(struct pil_desc *pil) |
| 159 | { |
| 160 | struct gss_data *drv = dev_get_drvdata(pil->dev); |
| 161 | void __iomem *base = drv->base; |
| 162 | u32 regval; |
| 163 | int ret; |
| 164 | |
| 165 | ret = clk_prepare_enable(drv->xo); |
| 166 | if (ret) { |
| 167 | dev_err(pil->dev, "Failed to enable XO\n"); |
| 168 | return ret; |
| 169 | } |
| 170 | |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 171 | /* Make sure bus port is halted. */ |
| 172 | msm_bus_axi_porthalt(MSM_BUS_MASTER_GSS_NAV); |
| 173 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 174 | /* |
| 175 | * Vote PLL on in GSS's voting register and wait for it to enable. |
| 176 | * The PLL must be enable to switch the GFMUX to a low-power source. |
| 177 | */ |
| 178 | writel_relaxed(PLL5_VOTE, PLL_ENA_GSS); |
| 179 | while ((readl_relaxed(PLL5_STATUS) & PLL_STATUS) == 0) |
| 180 | cpu_relax(); |
| 181 | |
| 182 | /* Perform one-time GSS initialization. */ |
| 183 | gss_init(drv); |
| 184 | |
| 185 | /* Assert A5 reset. */ |
| 186 | regval = readl_relaxed(base + GSS_CSR_RESET); |
| 187 | regval |= A5_RESET; |
| 188 | writel_relaxed(regval, base + GSS_CSR_RESET); |
| 189 | |
| 190 | /* Power down A5 and NAV. */ |
| 191 | regval = readl_relaxed(base + GSS_CSR_POWER_UP_DOWN); |
| 192 | regval &= ~(A5_POWER_ENA|NAV_POWER_ENA); |
| 193 | writel_relaxed(regval, base + GSS_CSR_POWER_UP_DOWN); |
| 194 | |
| 195 | /* Select XO clock source and increase dividers to save power. */ |
| 196 | regval = readl_relaxed(base + GSS_CSR_CLK_BLK_CONFIG); |
| 197 | regval |= 0x3FF; |
| 198 | writel_relaxed(regval, base + GSS_CSR_CLK_BLK_CONFIG); |
| 199 | |
| 200 | /* Disable bus clocks. */ |
| 201 | writel_relaxed(0x1F, base + GSS_CSR_CLK_ENABLE); |
| 202 | |
| 203 | /* Clear GSS PLL votes. */ |
| 204 | writel_relaxed(0, PLL_ENA_GSS); |
| 205 | mb(); |
| 206 | |
| 207 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 212 | static int pil_gss_reset(struct pil_desc *pil) |
| 213 | { |
| 214 | struct gss_data *drv = dev_get_drvdata(pil->dev); |
| 215 | void __iomem *base = drv->base; |
| 216 | unsigned long start_addr = drv->start_addr; |
| 217 | int ret; |
| 218 | |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 219 | /* Unhalt bus port. */ |
| 220 | ret = msm_bus_axi_portunhalt(MSM_BUS_MASTER_GSS_NAV); |
| 221 | if (ret) { |
| 222 | dev_err(pil->dev, "Failed to unhalt bus port\n"); |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 223 | return ret; |
| 224 | } |
| 225 | |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 226 | /* Vote PLL on in GSS's voting register and wait for it to enable. */ |
| 227 | writel_relaxed(PLL5_VOTE, PLL_ENA_GSS); |
| 228 | while ((readl_relaxed(PLL5_STATUS) & PLL_STATUS) == 0) |
| 229 | cpu_relax(); |
| 230 | |
| 231 | /* Perform GSS initialization. */ |
| 232 | gss_init(drv); |
| 233 | |
| 234 | /* Configure boot address and enable remap. */ |
| 235 | writel_relaxed(REMAP_ENABLE | (start_addr >> 16), |
| 236 | base + GSS_CSR_BOOT_REMAP); |
| 237 | |
| 238 | /* Power up A5 core. */ |
| 239 | writel_relaxed(A5_POWER_ENA, base + GSS_CSR_POWER_UP_DOWN); |
| 240 | while (!(readl_relaxed(base + GSS_CSR_POWER_UP_DOWN) & A5_POWER_STATUS)) |
| 241 | cpu_relax(); |
| 242 | |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 243 | if (cpu_is_apq8064() && |
| 244 | ((SOCINFO_VERSION_MAJOR(socinfo_get_version()) == 1) && |
| 245 | (SOCINFO_VERSION_MINOR(socinfo_get_version()) == 0))) { |
| 246 | ret = smp_call_function_single(0, cfg_qgic2_bus_access, drv, 1); |
| 247 | if (ret) { |
| 248 | pr_err("Failed to configure QGIC2 bus access\n"); |
| 249 | pil_gss_shutdown(pil); |
| 250 | return ret; |
| 251 | } |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* Release A5 from reset. */ |
| 255 | writel_relaxed(0x0, base + GSS_CSR_RESET); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 260 | static struct pil_reset_ops pil_gss_ops = { |
| 261 | .init_image = pil_gss_init_image, |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 262 | .auth_and_reset = pil_gss_reset, |
| 263 | .shutdown = pil_gss_shutdown, |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 264 | .proxy_vote = make_gss_proxy_votes, |
| 265 | .proxy_unvote = remove_gss_proxy_votes, |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 266 | }; |
| 267 | |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 268 | static int pil_gss_init_image_trusted(struct pil_desc *pil, |
| 269 | const u8 *metadata, size_t size) |
| 270 | { |
| 271 | return pas_init_image(PAS_GSS, metadata, size); |
| 272 | } |
| 273 | |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 274 | static int pil_gss_shutdown_trusted(struct pil_desc *pil) |
| 275 | { |
| 276 | struct gss_data *drv = dev_get_drvdata(pil->dev); |
| 277 | int ret; |
| 278 | |
Stephen Boyd | 7663ccc | 2012-02-21 19:34:55 -0800 | [diff] [blame] | 279 | /* |
| 280 | * CXO is used in the secure shutdown code to configure the processor |
| 281 | * for low power mode. |
| 282 | */ |
| 283 | ret = clk_prepare_enable(drv->xo); |
| 284 | if (ret) { |
| 285 | dev_err(pil->dev, "Failed to enable XO\n"); |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 286 | return ret; |
Stephen Boyd | 7663ccc | 2012-02-21 19:34:55 -0800 | [diff] [blame] | 287 | } |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 288 | |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 289 | msm_bus_axi_porthalt(MSM_BUS_MASTER_GSS_NAV); |
Stephen Boyd | 7663ccc | 2012-02-21 19:34:55 -0800 | [diff] [blame] | 290 | ret = pas_shutdown(PAS_GSS); |
| 291 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 292 | |
| 293 | return ret; |
| 294 | } |
| 295 | |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 296 | static int pil_gss_reset_trusted(struct pil_desc *pil) |
| 297 | { |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 298 | int err; |
| 299 | |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 300 | err = msm_bus_axi_portunhalt(MSM_BUS_MASTER_GSS_NAV); |
| 301 | if (err) { |
| 302 | dev_err(pil->dev, "Failed to unhalt bus port\n"); |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 303 | goto out; |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 304 | } |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 305 | |
| 306 | err = pas_auth_and_reset(PAS_GSS); |
| 307 | if (err) |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 308 | goto halt_port; |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 309 | |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 310 | return 0; |
Matt Wagantall | 556d3f7 | 2012-02-16 17:36:29 -0800 | [diff] [blame] | 311 | |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 312 | halt_port: |
| 313 | msm_bus_axi_porthalt(MSM_BUS_MASTER_GSS_NAV); |
Matt Wagantall | f3471ef | 2012-03-09 14:21:54 -0800 | [diff] [blame] | 314 | out: |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 315 | return err; |
| 316 | } |
| 317 | |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 318 | static struct pil_reset_ops pil_gss_ops_trusted = { |
| 319 | .init_image = pil_gss_init_image_trusted, |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 320 | .auth_and_reset = pil_gss_reset_trusted, |
| 321 | .shutdown = pil_gss_shutdown_trusted, |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 322 | .proxy_vote = make_gss_proxy_votes, |
| 323 | .proxy_unvote = remove_gss_proxy_votes, |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 324 | }; |
| 325 | |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 326 | #define MAX_SSR_REASON_LEN 81U |
| 327 | |
| 328 | static void log_gss_sfr(void) |
| 329 | { |
| 330 | u32 size; |
| 331 | char *smem_reason, reason[MAX_SSR_REASON_LEN]; |
| 332 | |
| 333 | smem_reason = smem_get_entry(SMEM_SSR_REASON_MSS0, &size); |
| 334 | if (!smem_reason || !size) { |
| 335 | pr_err("GSS subsystem failure reason: (unknown, smem_get_entry failed).\n"); |
| 336 | return; |
| 337 | } |
| 338 | if (!smem_reason[0]) { |
| 339 | pr_err("GSS subsystem failure reason: (unknown, init string found).\n"); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | size = min(size, MAX_SSR_REASON_LEN-1); |
| 344 | memcpy(reason, smem_reason, size); |
| 345 | reason[size] = '\0'; |
| 346 | pr_err("GSS subsystem failure reason: %s.\n", reason); |
| 347 | |
| 348 | smem_reason[0] = '\0'; |
| 349 | wmb(); |
| 350 | } |
| 351 | |
| 352 | static void restart_gss(struct gss_data *drv) |
| 353 | { |
| 354 | log_gss_sfr(); |
| 355 | subsystem_restart_dev(drv->subsys); |
| 356 | } |
| 357 | |
| 358 | static void smsm_state_cb(void *data, uint32_t old_state, uint32_t new_state) |
| 359 | { |
| 360 | struct gss_data *drv = data; |
| 361 | |
| 362 | /* Ignore if we're the one that set SMSM_RESET */ |
| 363 | if (drv->crash_shutdown) |
| 364 | return; |
| 365 | |
| 366 | if (new_state & SMSM_RESET) { |
| 367 | pr_err("GSS SMSM state changed to SMSM_RESET.\n" |
| 368 | "Probable err_fatal on the GSS. " |
| 369 | "Calling subsystem restart...\n"); |
| 370 | restart_gss(drv); |
| 371 | } |
| 372 | } |
| 373 | |
Stephen Boyd | 4684add | 2012-06-27 12:57:18 -0700 | [diff] [blame^] | 374 | static int gss_start(const struct subsys_desc *desc) |
| 375 | { |
| 376 | void *ret; |
| 377 | struct gss_data *drv; |
| 378 | |
| 379 | drv = container_of(desc, struct gss_data, subsys_desc); |
| 380 | ret = pil_get("gss"); |
| 381 | if (IS_ERR(ret)) |
| 382 | return PTR_ERR(ret); |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static void gss_stop(const struct subsys_desc *desc) |
| 387 | { |
| 388 | struct gss_data *drv; |
| 389 | |
| 390 | drv = container_of(desc, struct gss_data, subsys_desc); |
| 391 | pil_put(drv->pil); |
| 392 | } |
| 393 | |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 394 | static int gss_shutdown(const struct subsys_desc *desc) |
| 395 | { |
| 396 | struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc); |
| 397 | |
| 398 | pil_force_shutdown("gss"); |
| 399 | disable_irq_nosync(drv->irq); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int gss_powerup(const struct subsys_desc *desc) |
| 405 | { |
| 406 | struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc); |
| 407 | |
| 408 | pil_force_boot("gss"); |
| 409 | enable_irq(drv->irq); |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | void gss_crash_shutdown(const struct subsys_desc *desc) |
| 414 | { |
| 415 | struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc); |
| 416 | |
| 417 | drv->crash_shutdown = 1; |
| 418 | smsm_reset_modem(SMSM_RESET); |
| 419 | } |
| 420 | |
| 421 | /* FIXME: Get address, size from PIL */ |
| 422 | static struct ramdump_segment gss_segments[] = { |
| 423 | {0x89000000, 0x00D00000} |
| 424 | }; |
| 425 | |
| 426 | static struct ramdump_segment smem_segments[] = { |
| 427 | {0x80000000, 0x00200000}, |
| 428 | }; |
| 429 | |
| 430 | static int gss_ramdump(int enable, const struct subsys_desc *desc) |
| 431 | { |
| 432 | int ret; |
| 433 | struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc); |
| 434 | |
| 435 | if (enable) { |
| 436 | ret = do_ramdump(drv->ramdump_dev, gss_segments, |
| 437 | ARRAY_SIZE(gss_segments)); |
| 438 | if (ret < 0) { |
| 439 | pr_err("Unable to dump gss memory\n"); |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | ret = do_ramdump(drv->smem_ramdump_dev, smem_segments, |
| 444 | ARRAY_SIZE(smem_segments)); |
| 445 | if (ret < 0) { |
| 446 | pr_err("Unable to dump smem memory (rc = %d).\n", ret); |
| 447 | return ret; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static irqreturn_t gss_wdog_bite_irq(int irq, void *dev_id) |
| 455 | { |
| 456 | struct gss_data *drv = dev_id; |
| 457 | |
| 458 | pr_err("Watchdog bite received from GSS!\n"); |
| 459 | restart_gss(drv); |
| 460 | |
| 461 | return IRQ_HANDLED; |
| 462 | } |
| 463 | |
| 464 | static int gss_open(struct inode *inode, struct file *filp) |
| 465 | { |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 466 | struct miscdevice *c = filp->private_data; |
| 467 | struct gss_data *drv = container_of(c, struct gss_data, misc_dev); |
| 468 | |
Stephen Boyd | 4684add | 2012-06-27 12:57:18 -0700 | [diff] [blame^] | 469 | drv->subsys_handle = subsystem_get("gss"); |
| 470 | if (!drv->subsys_handle) |
| 471 | pr_debug("%s - subsystem_get returned NULL\n", __func__); |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | static int gss_release(struct inode *inode, struct file *filp) |
| 477 | { |
| 478 | struct miscdevice *c = filp->private_data; |
| 479 | struct gss_data *drv = container_of(c, struct gss_data, misc_dev); |
| 480 | |
Stephen Boyd | 4684add | 2012-06-27 12:57:18 -0700 | [diff] [blame^] | 481 | subsystem_put(drv->subsys_handle); |
| 482 | pr_debug("%s subsystem_put called on GSS\n", __func__); |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | const struct file_operations gss_file_ops = { |
| 488 | .open = gss_open, |
| 489 | .release = gss_release, |
| 490 | .owner = THIS_MODULE, |
| 491 | }; |
| 492 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 493 | static int __devinit pil_gss_probe(struct platform_device *pdev) |
| 494 | { |
| 495 | struct gss_data *drv; |
| 496 | struct resource *res; |
| 497 | struct pil_desc *desc; |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 498 | int ret; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 499 | |
| 500 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 501 | if (!res) |
| 502 | return -EINVAL; |
| 503 | |
| 504 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 505 | if (!drv) |
| 506 | return -ENOMEM; |
| 507 | platform_set_drvdata(pdev, drv); |
| 508 | |
| 509 | drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 510 | if (!drv->base) |
| 511 | return -ENOMEM; |
| 512 | |
| 513 | desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); |
| 514 | if (!desc) |
| 515 | return -ENOMEM; |
| 516 | |
Matt Wagantall | 19ac4fd | 2012-02-03 20:18:23 -0800 | [diff] [blame] | 517 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 518 | if (!res) |
| 519 | return -EINVAL; |
| 520 | |
| 521 | drv->qgic2_base = devm_ioremap(&pdev->dev, res->start, |
| 522 | resource_size(res)); |
| 523 | if (!drv->qgic2_base) |
| 524 | return -ENOMEM; |
| 525 | |
Stephen Boyd | 22b0447 | 2012-03-23 15:23:10 -0700 | [diff] [blame] | 526 | drv->xo = devm_clk_get(&pdev->dev, "xo"); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 527 | if (IS_ERR(drv->xo)) |
| 528 | return PTR_ERR(drv->xo); |
| 529 | |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 530 | drv->irq = platform_get_irq(pdev, 0); |
| 531 | if (drv->irq < 0) |
| 532 | return drv->irq; |
| 533 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 534 | desc->name = "gss"; |
| 535 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 536 | desc->owner = THIS_MODULE; |
Stephen Boyd | ab2b907 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 537 | desc->proxy_timeout = 10000; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 538 | |
Matt Wagantall | 11afeee | 2012-02-07 18:38:59 -0800 | [diff] [blame] | 539 | if (pas_supported(PAS_GSS) > 0) { |
| 540 | desc->ops = &pil_gss_ops_trusted; |
| 541 | dev_info(&pdev->dev, "using secure boot\n"); |
| 542 | } else { |
| 543 | desc->ops = &pil_gss_ops; |
| 544 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 545 | } |
Stephen Boyd | 95a1c54 | 2012-06-21 12:45:11 -0700 | [diff] [blame] | 546 | /* Force into low power mode because hardware doesn't do this */ |
| 547 | desc->ops->shutdown(desc); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 548 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 549 | drv->pil = msm_pil_register(desc); |
| 550 | if (IS_ERR(drv->pil)) { |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 551 | return PTR_ERR(drv->pil); |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 552 | } |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 553 | |
| 554 | ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET, |
| 555 | smsm_state_cb, drv); |
| 556 | if (ret < 0) |
| 557 | dev_warn(&pdev->dev, "Unable to register SMSM callback\n"); |
| 558 | |
| 559 | drv->subsys_desc.name = "gss"; |
Stephen Boyd | 4684add | 2012-06-27 12:57:18 -0700 | [diff] [blame^] | 560 | drv->subsys_desc.dev = &pdev->dev; |
| 561 | drv->subsys_desc.owner = THIS_MODULE; |
| 562 | drv->subsys_desc.start = gss_start; |
| 563 | drv->subsys_desc.stop = gss_stop; |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 564 | drv->subsys_desc.shutdown = gss_shutdown; |
| 565 | drv->subsys_desc.powerup = gss_powerup; |
| 566 | drv->subsys_desc.ramdump = gss_ramdump; |
| 567 | drv->subsys_desc.crash_shutdown = gss_crash_shutdown; |
| 568 | |
| 569 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 570 | if (IS_ERR(drv->subsys)) { |
| 571 | ret = PTR_ERR(drv->subsys); |
| 572 | goto err_subsys; |
| 573 | } |
| 574 | |
| 575 | drv->misc_dev.minor = MISC_DYNAMIC_MINOR; |
| 576 | drv->misc_dev.name = "gss"; |
| 577 | drv->misc_dev.fops = &gss_file_ops; |
| 578 | ret = misc_register(&drv->misc_dev); |
| 579 | if (ret) |
| 580 | goto err_misc; |
| 581 | |
| 582 | drv->ramdump_dev = create_ramdump_device("gss"); |
| 583 | if (!drv->ramdump_dev) { |
| 584 | ret = -ENOMEM; |
| 585 | goto err_ramdump; |
| 586 | } |
| 587 | |
| 588 | drv->smem_ramdump_dev = create_ramdump_device("smem-gss"); |
| 589 | if (!drv->smem_ramdump_dev) { |
| 590 | ret = -ENOMEM; |
| 591 | goto err_smem; |
| 592 | } |
| 593 | |
| 594 | ret = devm_request_irq(&pdev->dev, drv->irq, gss_wdog_bite_irq, |
| 595 | IRQF_TRIGGER_RISING, "gss_a5_wdog", drv); |
| 596 | if (ret < 0) |
| 597 | goto err; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 598 | return 0; |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 599 | err: |
| 600 | destroy_ramdump_device(drv->smem_ramdump_dev); |
| 601 | err_smem: |
| 602 | destroy_ramdump_device(drv->ramdump_dev); |
| 603 | err_ramdump: |
| 604 | misc_deregister(&drv->misc_dev); |
| 605 | err_misc: |
| 606 | subsys_unregister(drv->subsys); |
| 607 | err_subsys: |
| 608 | msm_pil_unregister(drv->pil); |
| 609 | return ret; |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static int __devexit pil_gss_remove(struct platform_device *pdev) |
| 613 | { |
| 614 | struct gss_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 615 | |
| 616 | destroy_ramdump_device(drv->smem_ramdump_dev); |
| 617 | destroy_ramdump_device(drv->ramdump_dev); |
| 618 | misc_deregister(&drv->misc_dev); |
| 619 | subsys_unregister(drv->subsys); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 620 | msm_pil_unregister(drv->pil); |
Stephen Boyd | d86214b | 2012-05-10 15:26:35 -0700 | [diff] [blame] | 621 | |
Matt Wagantall | 292aace | 2012-01-26 19:12:34 -0800 | [diff] [blame] | 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | static struct platform_driver pil_gss_driver = { |
| 626 | .probe = pil_gss_probe, |
| 627 | .remove = __devexit_p(pil_gss_remove), |
| 628 | .driver = { |
| 629 | .name = "pil_gss", |
| 630 | .owner = THIS_MODULE, |
| 631 | }, |
| 632 | }; |
| 633 | |
| 634 | static int __init pil_gss_init(void) |
| 635 | { |
| 636 | return platform_driver_register(&pil_gss_driver); |
| 637 | } |
| 638 | module_init(pil_gss_init); |
| 639 | |
| 640 | static void __exit pil_gss_exit(void) |
| 641 | { |
| 642 | platform_driver_unregister(&pil_gss_driver); |
| 643 | } |
| 644 | module_exit(pil_gss_exit); |
| 645 | |
| 646 | MODULE_DESCRIPTION("Support for booting the GSS processor"); |
| 647 | MODULE_LICENSE("GPL v2"); |