Sameer Thalappil | 4ca0d0f | 2013-02-16 07:12:36 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 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> |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/iopoll.h> |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/regulator/consumer.h> |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/workqueue.h> |
| 27 | #include <linux/wcnss_wlan.h> |
Sameer Thalappil | cbabf07 | 2013-03-28 13:51:41 -0700 | [diff] [blame] | 28 | #include <linux/of_gpio.h> |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 29 | |
| 30 | #include <mach/subsystem_restart.h> |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 31 | #include <mach/msm_smsm.h> |
Seemanta Dutta | 4e2d49c | 2013-04-05 16:28:11 -0700 | [diff] [blame] | 32 | #include <mach/ramdump.h> |
Jeff Hugo | 5ba15fe | 2013-05-06 14:24:24 -0600 | [diff] [blame] | 33 | #include <mach/msm_smem.h> |
Deepak Katragadda | 4118ccc | 2013-07-05 10:01:19 -0700 | [diff] [blame] | 34 | #include <mach/msm_bus_board.h> |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 35 | |
| 36 | #include "peripheral-loader.h" |
| 37 | #include "scm-pas.h" |
| 38 | |
| 39 | #define PRONTO_PMU_COMMON_GDSCR 0x24 |
| 40 | #define PRONTO_PMU_COMMON_GDSCR_SW_COLLAPSE BIT(0) |
| 41 | #define CLK_DIS_WAIT 12 |
| 42 | #define EN_FEW_WAIT 16 |
| 43 | #define EN_REST_WAIT 20 |
| 44 | |
| 45 | #define PRONTO_PMU_COMMON_CPU_CBCR 0x30 |
| 46 | #define PRONTO_PMU_COMMON_CPU_CBCR_CLK_EN BIT(0) |
| 47 | #define PRONTO_PMU_COMMON_CPU_CLK_OFF BIT(31) |
| 48 | |
| 49 | #define PRONTO_PMU_COMMON_AHB_CBCR 0x34 |
| 50 | #define PRONTO_PMU_COMMON_AHB_CBCR_CLK_EN BIT(0) |
| 51 | #define PRONTO_PMU_COMMON_AHB_CLK_OFF BIT(31) |
| 52 | |
| 53 | #define PRONTO_PMU_COMMON_CSR 0x1040 |
| 54 | #define PRONTO_PMU_COMMON_CSR_A2XB_CFG_EN BIT(0) |
| 55 | |
| 56 | #define PRONTO_PMU_SOFT_RESET 0x104C |
| 57 | #define PRONTO_PMU_SOFT_RESET_CRCM_CCPU_SOFT_RESET BIT(10) |
| 58 | |
| 59 | #define PRONTO_PMU_CCPU_CTL 0x2000 |
| 60 | #define PRONTO_PMU_CCPU_CTL_REMAP_EN BIT(2) |
| 61 | #define PRONTO_PMU_CCPU_CTL_HIGH_IVT BIT(0) |
| 62 | |
| 63 | #define PRONTO_PMU_CCPU_BOOT_REMAP_ADDR 0x2004 |
| 64 | |
| 65 | #define CLK_CTL_WCNSS_RESTART_BIT BIT(0) |
| 66 | |
| 67 | #define AXI_HALTREQ 0x0 |
| 68 | #define AXI_HALTACK 0x4 |
| 69 | #define AXI_IDLE 0x8 |
| 70 | |
| 71 | #define HALT_ACK_TIMEOUT_US 500000 |
| 72 | #define CLK_UPDATE_TIMEOUT_US 500000 |
| 73 | |
| 74 | struct pronto_data { |
| 75 | void __iomem *base; |
| 76 | void __iomem *reset_base; |
| 77 | void __iomem *axi_halt_base; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 78 | struct pil_device *pil; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 79 | struct pil_desc desc; |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 80 | struct subsys_device *subsys; |
| 81 | struct subsys_desc subsys_desc; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 82 | struct clk *cxo; |
| 83 | struct regulator *vreg; |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 84 | bool restart_inprogress; |
| 85 | bool crash; |
| 86 | struct delayed_work cancel_vote_work; |
Sameer Thalappil | b7488b2 | 2012-11-09 16:40:12 -0800 | [diff] [blame] | 87 | struct ramdump_device *ramdump_dev; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static int pil_pronto_make_proxy_vote(struct pil_desc *pil) |
| 91 | { |
| 92 | struct pronto_data *drv = dev_get_drvdata(pil->dev); |
| 93 | int ret; |
| 94 | |
| 95 | ret = regulator_enable(drv->vreg); |
| 96 | if (ret) { |
| 97 | dev_err(pil->dev, "failed to enable pll supply\n"); |
| 98 | goto err; |
| 99 | } |
| 100 | ret = clk_prepare_enable(drv->cxo); |
| 101 | if (ret) { |
| 102 | dev_err(pil->dev, "failed to enable cxo\n"); |
| 103 | goto err_clk; |
| 104 | } |
| 105 | return 0; |
| 106 | err_clk: |
| 107 | regulator_disable(drv->vreg); |
| 108 | err: |
| 109 | return ret; |
| 110 | } |
| 111 | |
| 112 | static void pil_pronto_remove_proxy_vote(struct pil_desc *pil) |
| 113 | { |
| 114 | struct pronto_data *drv = dev_get_drvdata(pil->dev); |
| 115 | regulator_disable(drv->vreg); |
| 116 | clk_disable_unprepare(drv->cxo); |
| 117 | } |
| 118 | |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 119 | static int pil_pronto_reset(struct pil_desc *pil) |
| 120 | { |
| 121 | u32 reg; |
| 122 | int rc; |
| 123 | struct pronto_data *drv = dev_get_drvdata(pil->dev); |
| 124 | void __iomem *base = drv->base; |
Tianyi Gou | 819851e | 2013-04-16 16:05:56 -0700 | [diff] [blame] | 125 | phys_addr_t start_addr = pil_get_entry_addr(pil); |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 126 | |
Matt Wagantall | 33c2ec7 | 2012-07-26 20:26:57 -0700 | [diff] [blame] | 127 | /* Deassert reset to subsystem and wait for propagation */ |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 128 | reg = readl_relaxed(drv->reset_base); |
| 129 | reg &= ~CLK_CTL_WCNSS_RESTART_BIT; |
| 130 | writel_relaxed(reg, drv->reset_base); |
| 131 | mb(); |
Matt Wagantall | 33c2ec7 | 2012-07-26 20:26:57 -0700 | [diff] [blame] | 132 | udelay(2); |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 133 | |
| 134 | /* Configure boot address */ |
| 135 | writel_relaxed(start_addr >> 16, base + |
| 136 | PRONTO_PMU_CCPU_BOOT_REMAP_ADDR); |
| 137 | |
| 138 | /* Use the high vector table */ |
| 139 | reg = readl_relaxed(base + PRONTO_PMU_CCPU_CTL); |
| 140 | reg |= PRONTO_PMU_CCPU_CTL_REMAP_EN | PRONTO_PMU_CCPU_CTL_HIGH_IVT; |
| 141 | writel_relaxed(reg, base + PRONTO_PMU_CCPU_CTL); |
| 142 | |
| 143 | /* Turn on AHB clock of common_ss */ |
| 144 | reg = readl_relaxed(base + PRONTO_PMU_COMMON_AHB_CBCR); |
| 145 | reg |= PRONTO_PMU_COMMON_AHB_CBCR_CLK_EN; |
| 146 | writel_relaxed(reg, base + PRONTO_PMU_COMMON_AHB_CBCR); |
| 147 | |
| 148 | /* Turn on CPU clock of common_ss */ |
| 149 | reg = readl_relaxed(base + PRONTO_PMU_COMMON_CPU_CBCR); |
| 150 | reg |= PRONTO_PMU_COMMON_CPU_CBCR_CLK_EN; |
| 151 | writel_relaxed(reg, base + PRONTO_PMU_COMMON_CPU_CBCR); |
| 152 | |
| 153 | /* Enable A2XB bridge */ |
| 154 | reg = readl_relaxed(base + PRONTO_PMU_COMMON_CSR); |
| 155 | reg |= PRONTO_PMU_COMMON_CSR_A2XB_CFG_EN; |
| 156 | writel_relaxed(reg, base + PRONTO_PMU_COMMON_CSR); |
| 157 | |
| 158 | /* Enable common_ss power */ |
| 159 | reg = readl_relaxed(base + PRONTO_PMU_COMMON_GDSCR); |
| 160 | reg &= ~PRONTO_PMU_COMMON_GDSCR_SW_COLLAPSE; |
| 161 | writel_relaxed(reg, base + PRONTO_PMU_COMMON_GDSCR); |
| 162 | |
| 163 | /* Wait for AHB clock to be on */ |
| 164 | rc = readl_tight_poll_timeout(base + PRONTO_PMU_COMMON_AHB_CBCR, |
| 165 | reg, |
| 166 | !(reg & PRONTO_PMU_COMMON_AHB_CLK_OFF), |
| 167 | CLK_UPDATE_TIMEOUT_US); |
| 168 | if (rc) { |
| 169 | dev_err(pil->dev, "pronto common ahb clk enable timeout\n"); |
| 170 | return rc; |
| 171 | } |
| 172 | |
| 173 | /* Wait for CPU clock to be on */ |
| 174 | rc = readl_tight_poll_timeout(base + PRONTO_PMU_COMMON_CPU_CBCR, |
| 175 | reg, |
| 176 | !(reg & PRONTO_PMU_COMMON_CPU_CLK_OFF), |
| 177 | CLK_UPDATE_TIMEOUT_US); |
| 178 | if (rc) { |
| 179 | dev_err(pil->dev, "pronto common cpu clk enable timeout\n"); |
| 180 | return rc; |
| 181 | } |
| 182 | |
| 183 | /* Deassert ARM9 software reset */ |
| 184 | reg = readl_relaxed(base + PRONTO_PMU_SOFT_RESET); |
| 185 | reg &= ~PRONTO_PMU_SOFT_RESET_CRCM_CCPU_SOFT_RESET; |
| 186 | writel_relaxed(reg, base + PRONTO_PMU_SOFT_RESET); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static int pil_pronto_shutdown(struct pil_desc *pil) |
| 192 | { |
| 193 | struct pronto_data *drv = dev_get_drvdata(pil->dev); |
| 194 | int ret; |
| 195 | u32 reg, status; |
| 196 | |
| 197 | /* Halt A2XB */ |
| 198 | writel_relaxed(1, drv->axi_halt_base + AXI_HALTREQ); |
| 199 | ret = readl_poll_timeout(drv->axi_halt_base + AXI_HALTACK, |
| 200 | status, status, 50, HALT_ACK_TIMEOUT_US); |
| 201 | if (ret) |
| 202 | dev_err(pil->dev, "Port halt timeout\n"); |
| 203 | else if (!readl_relaxed(drv->axi_halt_base + AXI_IDLE)) |
| 204 | dev_err(pil->dev, "Port halt failed\n"); |
| 205 | |
| 206 | writel_relaxed(0, drv->axi_halt_base + AXI_HALTREQ); |
| 207 | |
| 208 | /* Assert reset to Pronto */ |
| 209 | reg = readl_relaxed(drv->reset_base); |
| 210 | reg |= CLK_CTL_WCNSS_RESTART_BIT; |
| 211 | writel_relaxed(reg, drv->reset_base); |
| 212 | |
| 213 | /* Wait for reset to complete */ |
| 214 | mb(); |
| 215 | usleep_range(1000, 2000); |
| 216 | |
Matt Wagantall | 44131df | 2012-08-03 18:29:47 -0700 | [diff] [blame] | 217 | /* Deassert reset to subsystem and wait for propagation */ |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 218 | reg = readl_relaxed(drv->reset_base); |
| 219 | reg &= ~CLK_CTL_WCNSS_RESTART_BIT; |
| 220 | writel_relaxed(reg, drv->reset_base); |
| 221 | mb(); |
Matt Wagantall | 44131df | 2012-08-03 18:29:47 -0700 | [diff] [blame] | 222 | udelay(2); |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static struct pil_reset_ops pil_pronto_ops = { |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 228 | .auth_and_reset = pil_pronto_reset, |
| 229 | .shutdown = pil_pronto_shutdown, |
| 230 | .proxy_vote = pil_pronto_make_proxy_vote, |
| 231 | .proxy_unvote = pil_pronto_remove_proxy_vote, |
| 232 | }; |
| 233 | |
Tianyi Gou | 13d85b9 | 2012-11-12 18:04:07 -0800 | [diff] [blame] | 234 | static int pil_pronto_init_image_trusted(struct pil_desc *pil, |
| 235 | const u8 *metadata, size_t size) |
| 236 | { |
| 237 | return pas_init_image(PAS_WCNSS, metadata, size); |
| 238 | } |
| 239 | |
Stephen Boyd | c8c5db9 | 2012-12-03 11:13:20 -0800 | [diff] [blame] | 240 | static int pil_pronto_mem_setup_trusted(struct pil_desc *pil, phys_addr_t addr, |
| 241 | size_t size) |
| 242 | { |
| 243 | return pas_mem_setup(PAS_WCNSS, addr, size); |
| 244 | } |
| 245 | |
Tianyi Gou | 13d85b9 | 2012-11-12 18:04:07 -0800 | [diff] [blame] | 246 | static int pil_pronto_reset_trusted(struct pil_desc *pil) |
| 247 | { |
| 248 | return pas_auth_and_reset(PAS_WCNSS); |
| 249 | } |
| 250 | |
| 251 | static int pil_pronto_shutdown_trusted(struct pil_desc *pil) |
| 252 | { |
| 253 | return pas_shutdown(PAS_WCNSS); |
| 254 | } |
| 255 | |
| 256 | static struct pil_reset_ops pil_pronto_ops_trusted = { |
| 257 | .init_image = pil_pronto_init_image_trusted, |
Stephen Boyd | c8c5db9 | 2012-12-03 11:13:20 -0800 | [diff] [blame] | 258 | .mem_setup = pil_pronto_mem_setup_trusted, |
Tianyi Gou | 13d85b9 | 2012-11-12 18:04:07 -0800 | [diff] [blame] | 259 | .auth_and_reset = pil_pronto_reset_trusted, |
| 260 | .shutdown = pil_pronto_shutdown_trusted, |
| 261 | .proxy_vote = pil_pronto_make_proxy_vote, |
| 262 | .proxy_unvote = pil_pronto_remove_proxy_vote, |
| 263 | }; |
| 264 | |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 265 | #define subsys_to_drv(d) container_of(d, struct pronto_data, subsys_desc) |
| 266 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 267 | static int pronto_start(const struct subsys_desc *desc) |
| 268 | { |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 269 | struct pronto_data *drv = subsys_to_drv(desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 270 | return pil_boot(&drv->desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static void pronto_stop(const struct subsys_desc *desc) |
| 274 | { |
| 275 | struct pronto_data *drv = subsys_to_drv(desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 276 | pil_shutdown(&drv->desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 279 | static void log_wcnss_sfr(void) |
| 280 | { |
| 281 | char *smem_reset_reason; |
| 282 | unsigned smem_reset_size; |
| 283 | |
| 284 | smem_reset_reason = smem_get_entry(SMEM_SSR_REASON_WCNSS0, |
| 285 | &smem_reset_size); |
| 286 | |
| 287 | if (!smem_reset_reason || !smem_reset_size) { |
| 288 | pr_err("wcnss subsystem failure reason:\n" |
| 289 | "(unknown, smem_get_entry failed)"); |
| 290 | } else if (!smem_reset_reason[0]) { |
| 291 | pr_err("wcnss subsystem failure reason:\n" |
| 292 | "(unknown, init string found)"); |
| 293 | } else { |
| 294 | pr_err("wcnss subsystem failure reason: %.81s\n", |
| 295 | smem_reset_reason); |
| 296 | memset(smem_reset_reason, 0, smem_reset_size); |
| 297 | wmb(); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | static void restart_wcnss(struct pronto_data *drv) |
| 302 | { |
| 303 | log_wcnss_sfr(); |
| 304 | subsystem_restart_dev(drv->subsys); |
| 305 | } |
| 306 | |
Sameer Thalappil | cbabf07 | 2013-03-28 13:51:41 -0700 | [diff] [blame] | 307 | static irqreturn_t wcnss_err_fatal_intr_handler(int irq, void *dev_id) |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 308 | { |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 309 | struct pronto_data *drv = subsys_to_drv(dev_id); |
Sameer Thalappil | cbabf07 | 2013-03-28 13:51:41 -0700 | [diff] [blame] | 310 | |
| 311 | pr_err("Fatal error on the wcnss.\n"); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 312 | |
| 313 | drv->crash = true; |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 314 | if (drv->restart_inprogress) { |
Sameer Thalappil | cbabf07 | 2013-03-28 13:51:41 -0700 | [diff] [blame] | 315 | pr_err("wcnss: Ignoring error fatal, restart in progress\n"); |
| 316 | return IRQ_HANDLED; |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | drv->restart_inprogress = true; |
| 320 | restart_wcnss(drv); |
Sameer Thalappil | cbabf07 | 2013-03-28 13:51:41 -0700 | [diff] [blame] | 321 | |
| 322 | return IRQ_HANDLED; |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static irqreturn_t wcnss_wdog_bite_irq_hdlr(int irq, void *dev_id) |
| 326 | { |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 327 | struct pronto_data *drv = subsys_to_drv(dev_id); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 328 | |
| 329 | drv->crash = true; |
| 330 | |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 331 | disable_irq_nosync(drv->subsys_desc.wdog_bite_irq); |
Sameer Thalappil | 6287b56 | 2013-05-14 09:23:08 -0700 | [diff] [blame] | 332 | |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 333 | if (drv->restart_inprogress) { |
| 334 | pr_err("Ignoring wcnss bite irq, restart in progress\n"); |
| 335 | return IRQ_HANDLED; |
| 336 | } |
Sameer Thalappil | 36f7a1a | 2013-10-09 18:32:38 -0700 | [diff] [blame] | 337 | wcnss_log_debug_regs_on_bite(); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 338 | |
| 339 | drv->restart_inprogress = true; |
| 340 | restart_wcnss(drv); |
| 341 | |
| 342 | return IRQ_HANDLED; |
| 343 | } |
| 344 | |
| 345 | static void wcnss_post_bootup(struct work_struct *work) |
| 346 | { |
| 347 | struct platform_device *pdev = wcnss_get_platform_device(); |
| 348 | struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config(); |
| 349 | |
Sameer Thalappil | 1d69b802 | 2013-06-10 19:10:07 -0700 | [diff] [blame] | 350 | wcnss_wlan_power(&pdev->dev, pwlanconfig, WCNSS_WLAN_SWITCH_OFF, NULL); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static int wcnss_shutdown(const struct subsys_desc *subsys) |
| 354 | { |
| 355 | struct pronto_data *drv = subsys_to_drv(subsys); |
| 356 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 357 | pil_shutdown(&drv->desc); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 358 | flush_delayed_work(&drv->cancel_vote_work); |
| 359 | wcnss_flush_delayed_boot_votes(); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static int wcnss_powerup(const struct subsys_desc *subsys) |
| 365 | { |
| 366 | struct pronto_data *drv = subsys_to_drv(subsys); |
| 367 | struct platform_device *pdev = wcnss_get_platform_device(); |
| 368 | struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config(); |
| 369 | int ret = -1; |
| 370 | |
| 371 | if (pdev && pwlanconfig) |
| 372 | ret = wcnss_wlan_power(&pdev->dev, pwlanconfig, |
Sameer Thalappil | 1d69b802 | 2013-06-10 19:10:07 -0700 | [diff] [blame] | 373 | WCNSS_WLAN_SWITCH_ON, NULL); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 374 | if (!ret) { |
| 375 | msleep(1000); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 376 | ret = pil_boot(&drv->desc); |
| 377 | if (ret) |
| 378 | return ret; |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 379 | } |
| 380 | drv->restart_inprogress = false; |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 381 | enable_irq(drv->subsys_desc.wdog_bite_irq); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 382 | schedule_delayed_work(&drv->cancel_vote_work, msecs_to_jiffies(5000)); |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static void crash_shutdown(const struct subsys_desc *subsys) |
| 388 | { |
| 389 | struct pronto_data *drv = subsys_to_drv(subsys); |
| 390 | |
| 391 | pr_err("wcnss crash shutdown %d\n", drv->crash); |
| 392 | if (!drv->crash) |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 393 | gpio_set_value(subsys->force_stop_gpio, 1); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Sameer Thalappil | b7488b2 | 2012-11-09 16:40:12 -0800 | [diff] [blame] | 396 | static int wcnss_ramdump(int enable, const struct subsys_desc *subsys) |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 397 | { |
Sameer Thalappil | b7488b2 | 2012-11-09 16:40:12 -0800 | [diff] [blame] | 398 | struct pronto_data *drv = subsys_to_drv(subsys); |
| 399 | |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 400 | if (!enable) |
Sameer Thalappil | b7488b2 | 2012-11-09 16:40:12 -0800 | [diff] [blame] | 401 | return 0; |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 402 | |
| 403 | return pil_do_ramdump(&drv->desc, drv->ramdump_dev); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 406 | static int __devinit pil_pronto_probe(struct platform_device *pdev) |
| 407 | { |
| 408 | struct pronto_data *drv; |
| 409 | struct resource *res; |
| 410 | struct pil_desc *desc; |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 411 | int ret; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 412 | uint32_t regval; |
| 413 | |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 414 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 415 | if (!drv) |
| 416 | return -ENOMEM; |
| 417 | platform_set_drvdata(pdev, drv); |
| 418 | |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 419 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pmu_base"); |
| 420 | drv->base = devm_request_and_ioremap(&pdev->dev, res); |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 421 | if (!drv->base) |
| 422 | return -ENOMEM; |
| 423 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 424 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "clk_base"); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 425 | drv->reset_base = devm_request_and_ioremap(&pdev->dev, res); |
| 426 | if (!drv->reset_base) |
| 427 | return -ENOMEM; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 428 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 429 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "halt_base"); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 430 | drv->axi_halt_base = devm_request_and_ioremap(&pdev->dev, res); |
| 431 | if (!drv->axi_halt_base) |
| 432 | return -ENOMEM; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 433 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 434 | desc = &drv->desc; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 435 | ret = of_property_read_string(pdev->dev.of_node, "qcom,firmware-name", |
| 436 | &desc->name); |
| 437 | if (ret) |
| 438 | return ret; |
| 439 | |
| 440 | desc->dev = &pdev->dev; |
| 441 | desc->owner = THIS_MODULE; |
| 442 | desc->proxy_timeout = 10000; |
| 443 | |
Tianyi Gou | 13d85b9 | 2012-11-12 18:04:07 -0800 | [diff] [blame] | 444 | if (pas_supported(PAS_WCNSS) > 0) { |
| 445 | desc->ops = &pil_pronto_ops_trusted; |
| 446 | dev_info(&pdev->dev, "using secure boot\n"); |
| 447 | } else { |
| 448 | desc->ops = &pil_pronto_ops; |
| 449 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 450 | } |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 451 | |
| 452 | drv->vreg = devm_regulator_get(&pdev->dev, "vdd_pronto_pll"); |
| 453 | if (IS_ERR(drv->vreg)) { |
| 454 | dev_err(&pdev->dev, "failed to get pronto pll supply"); |
| 455 | return PTR_ERR(drv->vreg); |
| 456 | } |
| 457 | |
| 458 | ret = regulator_set_voltage(drv->vreg, 1800000, 1800000); |
| 459 | if (ret) { |
| 460 | dev_err(&pdev->dev, "failed to set pll supply voltage\n"); |
| 461 | return ret; |
| 462 | } |
| 463 | |
| 464 | ret = regulator_set_optimum_mode(drv->vreg, 18000); |
| 465 | if (ret < 0) { |
| 466 | dev_err(&pdev->dev, "failed to set pll supply mode\n"); |
| 467 | return ret; |
| 468 | } |
| 469 | |
| 470 | drv->cxo = devm_clk_get(&pdev->dev, "xo"); |
| 471 | if (IS_ERR(drv->cxo)) |
| 472 | return PTR_ERR(drv->cxo); |
| 473 | |
Deepak Katragadda | 4118ccc | 2013-07-05 10:01:19 -0700 | [diff] [blame] | 474 | scm_pas_init(MSM_BUS_MASTER_CRYPTO_CORE0); |
| 475 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 476 | ret = pil_desc_init(desc); |
| 477 | if (ret) |
| 478 | return ret; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 479 | |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 480 | drv->subsys_desc.name = desc->name; |
| 481 | drv->subsys_desc.dev = &pdev->dev; |
| 482 | drv->subsys_desc.owner = THIS_MODULE; |
| 483 | drv->subsys_desc.shutdown = wcnss_shutdown; |
| 484 | drv->subsys_desc.powerup = wcnss_powerup; |
| 485 | drv->subsys_desc.ramdump = wcnss_ramdump; |
| 486 | drv->subsys_desc.crash_shutdown = crash_shutdown; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 487 | drv->subsys_desc.start = pronto_start; |
| 488 | drv->subsys_desc.stop = pronto_stop; |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 489 | drv->subsys_desc.err_fatal_handler = wcnss_err_fatal_intr_handler; |
| 490 | drv->subsys_desc.wdog_bite_handler = wcnss_wdog_bite_irq_hdlr; |
Sameer Thalappil | b1e03c0 | 2013-04-29 14:52:00 -0700 | [diff] [blame] | 491 | |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 492 | INIT_DELAYED_WORK(&drv->cancel_vote_work, wcnss_post_bootup); |
| 493 | |
| 494 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 495 | if (IS_ERR(drv->subsys)) { |
| 496 | ret = PTR_ERR(drv->subsys); |
| 497 | goto err_subsys; |
| 498 | } |
| 499 | |
Sameer Thalappil | b7488b2 | 2012-11-09 16:40:12 -0800 | [diff] [blame] | 500 | drv->ramdump_dev = create_ramdump_device("pronto", &pdev->dev); |
| 501 | if (!drv->ramdump_dev) { |
| 502 | ret = -ENOMEM; |
| 503 | goto err_irq; |
| 504 | } |
| 505 | |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 506 | /* Initialize common_ss GDSCR to wait 4 cycles between states */ |
| 507 | regval = readl_relaxed(drv->base + PRONTO_PMU_COMMON_GDSCR) |
| 508 | & PRONTO_PMU_COMMON_GDSCR_SW_COLLAPSE; |
| 509 | regval |= (2 << EN_REST_WAIT) | (2 << EN_FEW_WAIT) |
| 510 | | (2 << CLK_DIS_WAIT); |
| 511 | writel_relaxed(regval, drv->base + PRONTO_PMU_COMMON_GDSCR); |
| 512 | |
| 513 | return 0; |
Sameer Thalappil | cbabf07 | 2013-03-28 13:51:41 -0700 | [diff] [blame] | 514 | |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 515 | err_irq: |
| 516 | subsys_unregister(drv->subsys); |
| 517 | err_subsys: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 518 | pil_desc_release(desc); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 519 | return ret; |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static int __devexit pil_pronto_remove(struct platform_device *pdev) |
| 523 | { |
| 524 | struct pronto_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 581fe85 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 525 | subsys_unregister(drv->subsys); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 526 | pil_desc_release(&drv->desc); |
Sameer Thalappil | b7488b2 | 2012-11-09 16:40:12 -0800 | [diff] [blame] | 527 | destroy_ramdump_device(drv->ramdump_dev); |
Tianyi Gou | c1e049f8 | 2011-11-23 14:20:16 -0800 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static struct of_device_id msm_pil_pronto_match[] = { |
| 532 | {.compatible = "qcom,pil-pronto"}, |
| 533 | {} |
| 534 | }; |
| 535 | |
| 536 | static struct platform_driver pil_pronto_driver = { |
| 537 | .probe = pil_pronto_probe, |
| 538 | .remove = __devexit_p(pil_pronto_remove), |
| 539 | .driver = { |
| 540 | .name = "pil_pronto", |
| 541 | .owner = THIS_MODULE, |
| 542 | .of_match_table = msm_pil_pronto_match, |
| 543 | }, |
| 544 | }; |
| 545 | |
| 546 | static int __init pil_pronto_init(void) |
| 547 | { |
| 548 | return platform_driver_register(&pil_pronto_driver); |
| 549 | } |
| 550 | module_init(pil_pronto_init); |
| 551 | |
| 552 | static void __exit pil_pronto_exit(void) |
| 553 | { |
| 554 | platform_driver_unregister(&pil_pronto_driver); |
| 555 | } |
| 556 | module_exit(pil_pronto_exit); |
| 557 | |
| 558 | MODULE_DESCRIPTION("Support for booting PRONTO (WCNSS) processors"); |
| 559 | MODULE_LICENSE("GPL v2"); |