Seemanta Dutta | 4e2d49c | 2013-04-05 16:28:11 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [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/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/delay.h> |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 19 | #include <linux/err.h> |
| 20 | #include <linux/clk.h> |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 21 | #include <linux/workqueue.h> |
| 22 | #include <linux/interrupt.h> |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 23 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 24 | #include <mach/subsystem_restart.h> |
| 25 | #include <mach/scm.h> |
Seemanta Dutta | 4e2d49c | 2013-04-05 16:28:11 -0700 | [diff] [blame] | 26 | #include <mach/ramdump.h> |
Deepak Katragadda | 4118ccc | 2013-07-05 10:01:19 -0700 | [diff] [blame] | 27 | #include <mach/msm_bus_board.h> |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 28 | |
| 29 | #include "peripheral-loader.h" |
| 30 | #include "scm-pas.h" |
| 31 | |
| 32 | #define QDSP6SS_RST_EVB 0x0000 |
| 33 | #define QDSP6SS_STRAP_TCM 0x001C |
| 34 | #define QDSP6SS_STRAP_AHB 0x0020 |
| 35 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 36 | #define LCC_Q6_FUNC 0x001C |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 37 | #define LV_EN BIT(27) |
| 38 | #define STOP_CORE BIT(26) |
| 39 | #define CLAMP_IO BIT(25) |
| 40 | #define Q6SS_PRIV_ARES BIT(24) |
| 41 | #define Q6SS_SS_ARES BIT(23) |
| 42 | #define Q6SS_ISDB_ARES BIT(22) |
| 43 | #define Q6SS_ETM_ARES BIT(21) |
| 44 | #define Q6_JTAG_CRC_EN BIT(20) |
| 45 | #define Q6_JTAG_INV_EN BIT(19) |
| 46 | #define Q6_JTAG_CXC_EN BIT(18) |
| 47 | #define Q6_PXO_CRC_EN BIT(17) |
| 48 | #define Q6_PXO_INV_EN BIT(16) |
| 49 | #define Q6_PXO_CXC_EN BIT(15) |
| 50 | #define Q6_PXO_SLEEP_EN BIT(14) |
| 51 | #define Q6_SLP_CRC_EN BIT(13) |
| 52 | #define Q6_SLP_INV_EN BIT(12) |
| 53 | #define Q6_SLP_CXC_EN BIT(11) |
| 54 | #define CORE_ARES BIT(10) |
| 55 | #define CORE_L1_MEM_CORE_EN BIT(9) |
| 56 | #define CORE_TCM_MEM_CORE_EN BIT(8) |
| 57 | #define CORE_TCM_MEM_PERPH_EN BIT(7) |
| 58 | #define CORE_GFM4_CLK_EN BIT(2) |
| 59 | #define CORE_GFM4_RES BIT(1) |
| 60 | #define RAMP_PLL_SRC_SEL BIT(0) |
| 61 | |
| 62 | #define Q6_STRAP_AHB_UPPER (0x290 << 12) |
| 63 | #define Q6_STRAP_AHB_LOWER 0x280 |
| 64 | #define Q6_STRAP_TCM_BASE (0x28C << 15) |
| 65 | #define Q6_STRAP_TCM_CONFIG 0x28B |
| 66 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 67 | #define SCM_Q6_NMI_CMD 0x1 |
| 68 | |
| 69 | /** |
| 70 | * struct q6v3_data - LPASS driver data |
| 71 | * @base: register base |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 72 | * @cbase: clock base |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 73 | * @wk_base: wakeup register base |
| 74 | * @wd_base: watchdog register base |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 75 | * @irq: watchdog irq |
| 76 | * @pil: peripheral handle |
| 77 | * @subsys: subsystem restart handle |
| 78 | * @subsys_desc: subsystem restart descriptor |
| 79 | * @fatal_wrk: fatal error workqueue |
| 80 | * @pll: pll clock handle |
| 81 | * @ramdump_dev: ramdump device |
| 82 | */ |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 83 | struct q6v3_data { |
| 84 | void __iomem *base; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 85 | void __iomem *cbase; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 86 | void __iomem *wk_base; |
| 87 | void __iomem *wd_base; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 88 | int irq; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 89 | struct pil_desc pil_desc; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 90 | struct subsys_device *subsys; |
| 91 | struct subsys_desc subsys_desc; |
| 92 | struct work_struct fatal_wrk; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 93 | struct clk *pll; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 94 | struct ramdump_device *ramdump_dev; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 97 | static void pil_q6v3_remove_proxy_votes(struct pil_desc *pil) |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 98 | { |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 99 | struct q6v3_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 4f8b7e2 | 2012-01-24 13:31:29 -0800 | [diff] [blame] | 100 | clk_disable_unprepare(drv->pll); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 103 | static int pil_q6v3_make_proxy_votes(struct pil_desc *pil) |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 104 | { |
| 105 | int ret; |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 106 | struct q6v3_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 107 | |
Stephen Boyd | 4f8b7e2 | 2012-01-24 13:31:29 -0800 | [diff] [blame] | 108 | ret = clk_prepare_enable(drv->pll); |
| 109 | if (ret) { |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 110 | dev_err(pil->dev, "Failed to enable PLL\n"); |
Stephen Boyd | 4f8b7e2 | 2012-01-24 13:31:29 -0800 | [diff] [blame] | 111 | return ret; |
| 112 | } |
Stephen Boyd | 4f8b7e2 | 2012-01-24 13:31:29 -0800 | [diff] [blame] | 113 | return 0; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 116 | static int pil_q6v3_reset(struct pil_desc *pil) |
| 117 | { |
| 118 | u32 reg; |
| 119 | struct q6v3_data *drv = dev_get_drvdata(pil->dev); |
Tianyi Gou | 819851e | 2013-04-16 16:05:56 -0700 | [diff] [blame] | 120 | phys_addr_t start_addr = pil_get_entry_addr(pil); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 121 | |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 122 | /* Put Q6 into reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 123 | reg = readl_relaxed(drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 124 | reg |= Q6SS_SS_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES | STOP_CORE | |
| 125 | CORE_ARES; |
| 126 | reg &= ~CORE_GFM4_CLK_EN; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 127 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 128 | |
| 129 | /* Wait 8 AHB cycles for Q6 to be fully reset (AHB = 1.5Mhz) */ |
| 130 | usleep_range(20, 30); |
| 131 | |
| 132 | /* Turn on Q6 memory */ |
| 133 | reg |= CORE_GFM4_CLK_EN | CORE_L1_MEM_CORE_EN | CORE_TCM_MEM_CORE_EN | |
| 134 | CORE_TCM_MEM_PERPH_EN; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 135 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 136 | |
| 137 | /* Turn on Q6 core clocks and take core out of reset */ |
| 138 | reg &= ~(CLAMP_IO | Q6SS_SS_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES | |
| 139 | CORE_ARES); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 140 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 141 | |
| 142 | /* Wait for clocks to be enabled */ |
| 143 | mb(); |
| 144 | /* Program boot address */ |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 145 | writel_relaxed((start_addr >> 12) & 0xFFFFF, |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 146 | drv->base + QDSP6SS_RST_EVB); |
| 147 | |
| 148 | writel_relaxed(Q6_STRAP_TCM_CONFIG | Q6_STRAP_TCM_BASE, |
| 149 | drv->base + QDSP6SS_STRAP_TCM); |
| 150 | writel_relaxed(Q6_STRAP_AHB_UPPER | Q6_STRAP_AHB_LOWER, |
| 151 | drv->base + QDSP6SS_STRAP_AHB); |
| 152 | |
| 153 | /* Wait for addresses to be programmed before starting Q6 */ |
| 154 | mb(); |
| 155 | |
| 156 | /* Start Q6 instruction execution */ |
| 157 | reg &= ~STOP_CORE; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 158 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int pil_q6v3_shutdown(struct pil_desc *pil) |
| 164 | { |
| 165 | u32 reg; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 166 | struct q6v3_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 167 | |
| 168 | /* Put Q6 into reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 169 | reg = readl_relaxed(drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 170 | reg |= Q6SS_SS_ARES | Q6SS_ISDB_ARES | Q6SS_ETM_ARES | STOP_CORE | |
| 171 | CORE_ARES; |
| 172 | reg &= ~CORE_GFM4_CLK_EN; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 173 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 174 | |
| 175 | /* Wait 8 AHB cycles for Q6 to be fully reset (AHB = 1.5Mhz) */ |
| 176 | usleep_range(20, 30); |
| 177 | |
| 178 | /* Turn off Q6 memory */ |
| 179 | reg &= ~(CORE_L1_MEM_CORE_EN | CORE_TCM_MEM_CORE_EN | |
| 180 | CORE_TCM_MEM_PERPH_EN); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 181 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 182 | |
| 183 | reg |= CLAMP_IO; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 184 | writel_relaxed(reg, drv->cbase + LCC_Q6_FUNC); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 185 | |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static struct pil_reset_ops pil_q6v3_ops = { |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 190 | .auth_and_reset = pil_q6v3_reset, |
| 191 | .shutdown = pil_q6v3_shutdown, |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 192 | .proxy_vote = pil_q6v3_make_proxy_votes, |
| 193 | .proxy_unvote = pil_q6v3_remove_proxy_votes, |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | static int pil_q6v3_init_image_trusted(struct pil_desc *pil, |
| 197 | const u8 *metadata, size_t size) |
| 198 | { |
| 199 | return pas_init_image(PAS_Q6, metadata, size); |
| 200 | } |
| 201 | |
| 202 | static int pil_q6v3_reset_trusted(struct pil_desc *pil) |
| 203 | { |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 204 | return pas_auth_and_reset(PAS_Q6); |
| 205 | } |
| 206 | |
| 207 | static int pil_q6v3_shutdown_trusted(struct pil_desc *pil) |
| 208 | { |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 209 | return pas_shutdown(PAS_Q6); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static struct pil_reset_ops pil_q6v3_ops_trusted = { |
| 213 | .init_image = pil_q6v3_init_image_trusted, |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 214 | .auth_and_reset = pil_q6v3_reset_trusted, |
| 215 | .shutdown = pil_q6v3_shutdown_trusted, |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 216 | .proxy_vote = pil_q6v3_make_proxy_votes, |
| 217 | .proxy_unvote = pil_q6v3_remove_proxy_votes, |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 220 | static void q6_fatal_fn(struct work_struct *work) |
| 221 | { |
| 222 | struct q6v3_data *drv = container_of(work, struct q6v3_data, fatal_wrk); |
| 223 | |
| 224 | pr_err("Watchdog bite received from Q6!\n"); |
| 225 | subsystem_restart_dev(drv->subsys); |
| 226 | enable_irq(drv->irq); |
| 227 | } |
| 228 | |
| 229 | static void send_q6_nmi(struct q6v3_data *drv) |
| 230 | { |
| 231 | /* Send NMI to QDSP6 via an SCM call. */ |
| 232 | scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1); |
| 233 | |
| 234 | /* Wakeup the Q6 */ |
| 235 | writel_relaxed(0x2000, drv->wk_base + 0x1c); |
| 236 | /* Q6 requires atleast 100ms to dump caches etc.*/ |
| 237 | mdelay(100); |
| 238 | pr_info("Q6 NMI was sent.\n"); |
| 239 | } |
| 240 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 241 | static int lpass_q6_start(const struct subsys_desc *subsys) |
| 242 | { |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 243 | struct q6v3_data *drv; |
| 244 | |
| 245 | drv = container_of(subsys, struct q6v3_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 246 | return pil_boot(&drv->pil_desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void lpass_q6_stop(const struct subsys_desc *subsys) |
| 250 | { |
| 251 | struct q6v3_data *drv; |
| 252 | |
| 253 | drv = container_of(subsys, struct q6v3_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 254 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 257 | static int lpass_q6_shutdown(const struct subsys_desc *subsys) |
| 258 | { |
| 259 | struct q6v3_data *drv; |
| 260 | |
| 261 | drv = container_of(subsys, struct q6v3_data, subsys_desc); |
| 262 | send_q6_nmi(drv); |
| 263 | writel_relaxed(0x0, drv->wd_base + 0x24); |
| 264 | mb(); |
| 265 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 266 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 267 | disable_irq_nosync(drv->irq); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static int lpass_q6_powerup(const struct subsys_desc *subsys) |
| 273 | { |
| 274 | struct q6v3_data *drv; |
| 275 | int ret; |
| 276 | |
| 277 | drv = container_of(subsys, struct q6v3_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 278 | ret = pil_boot(&drv->pil_desc); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 279 | enable_irq(drv->irq); |
| 280 | return ret; |
| 281 | } |
| 282 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 283 | static int lpass_q6_ramdump(int enable, const struct subsys_desc *subsys) |
| 284 | { |
| 285 | struct q6v3_data *drv; |
| 286 | |
| 287 | drv = container_of(subsys, struct q6v3_data, subsys_desc); |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 288 | if (!enable) |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 289 | return 0; |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 290 | |
| 291 | return pil_do_ramdump(&drv->pil_desc, drv->ramdump_dev); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void lpass_q6_crash_shutdown(const struct subsys_desc *subsys) |
| 295 | { |
| 296 | struct q6v3_data *drv; |
| 297 | |
| 298 | drv = container_of(subsys, struct q6v3_data, subsys_desc); |
| 299 | send_q6_nmi(drv); |
| 300 | } |
| 301 | |
| 302 | static irqreturn_t lpass_wdog_bite_irq(int irq, void *dev_id) |
| 303 | { |
| 304 | int ret; |
| 305 | struct q6v3_data *drv = dev_id; |
| 306 | |
| 307 | ret = schedule_work(&drv->fatal_wrk); |
| 308 | disable_irq_nosync(drv->irq); |
| 309 | |
| 310 | return IRQ_HANDLED; |
| 311 | } |
| 312 | |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 313 | static int __devinit pil_q6v3_driver_probe(struct platform_device *pdev) |
| 314 | { |
| 315 | struct q6v3_data *drv; |
| 316 | struct resource *res; |
| 317 | struct pil_desc *desc; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 318 | int ret; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 319 | |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 320 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 321 | if (!drv) |
| 322 | return -ENOMEM; |
| 323 | platform_set_drvdata(pdev, drv); |
| 324 | |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 325 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 326 | drv->base = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 327 | if (!drv->base) |
| 328 | return -ENOMEM; |
| 329 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 330 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 331 | drv->wk_base = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 332 | if (!drv->wk_base) |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 333 | return -ENOMEM; |
| 334 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 335 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 336 | drv->wd_base = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 337 | if (!drv->wd_base) |
| 338 | return -ENOMEM; |
| 339 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 340 | res = platform_get_resource(pdev, IORESOURCE_MEM, 3); |
| 341 | if (!res) |
| 342 | return -EINVAL; |
| 343 | drv->cbase = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 344 | if (!drv->cbase) |
| 345 | return -ENOMEM; |
| 346 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 347 | drv->irq = platform_get_irq(pdev, 0); |
| 348 | if (drv->irq < 0) |
| 349 | return drv->irq; |
| 350 | |
Stephen Boyd | f11bfb5 | 2012-03-23 15:30:48 -0700 | [diff] [blame] | 351 | drv->pll = devm_clk_get(&pdev->dev, "pll4"); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 352 | if (IS_ERR(drv->pll)) |
| 353 | return PTR_ERR(drv->pll); |
| 354 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 355 | desc = &drv->pil_desc; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 356 | desc->name = "q6"; |
| 357 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 358 | desc->owner = THIS_MODULE; |
Stephen Boyd | 32f7f2e | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 359 | desc->proxy_timeout = 10000; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 360 | |
| 361 | if (pas_supported(PAS_Q6) > 0) { |
| 362 | desc->ops = &pil_q6v3_ops_trusted; |
| 363 | dev_info(&pdev->dev, "using secure boot\n"); |
| 364 | } else { |
| 365 | desc->ops = &pil_q6v3_ops; |
| 366 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 367 | } |
| 368 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 369 | ret = pil_desc_init(desc); |
| 370 | if (ret) |
| 371 | return ret; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 372 | |
Stephen Boyd | 77db8bb | 2012-06-27 15:15:16 -0700 | [diff] [blame] | 373 | drv->subsys_desc.name = "adsp"; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 374 | drv->subsys_desc.dev = &pdev->dev; |
| 375 | drv->subsys_desc.owner = THIS_MODULE; |
| 376 | drv->subsys_desc.start = lpass_q6_start; |
| 377 | drv->subsys_desc.stop = lpass_q6_stop; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 378 | drv->subsys_desc.shutdown = lpass_q6_shutdown; |
| 379 | drv->subsys_desc.powerup = lpass_q6_powerup; |
| 380 | drv->subsys_desc.ramdump = lpass_q6_ramdump; |
| 381 | drv->subsys_desc.crash_shutdown = lpass_q6_crash_shutdown; |
| 382 | |
| 383 | INIT_WORK(&drv->fatal_wrk, q6_fatal_fn); |
| 384 | |
Stephen Boyd | c1a7261 | 2012-07-05 14:07:35 -0700 | [diff] [blame] | 385 | drv->ramdump_dev = create_ramdump_device("lpass", &pdev->dev); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 386 | if (!drv->ramdump_dev) { |
| 387 | ret = -ENOMEM; |
| 388 | goto err_ramdump; |
Stephen Boyd | 4f8b7e2 | 2012-01-24 13:31:29 -0800 | [diff] [blame] | 389 | } |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 390 | |
| 391 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 392 | if (IS_ERR(drv->subsys)) { |
| 393 | ret = PTR_ERR(drv->subsys); |
| 394 | goto err_subsys; |
| 395 | } |
| 396 | |
Deepak Katragadda | 4118ccc | 2013-07-05 10:01:19 -0700 | [diff] [blame] | 397 | scm_pas_init(MSM_BUS_MASTER_SPS); |
| 398 | |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 399 | ret = devm_request_irq(&pdev->dev, drv->irq, lpass_wdog_bite_irq, |
| 400 | IRQF_TRIGGER_RISING, "lpass_wdog", drv); |
| 401 | if (ret) { |
| 402 | dev_err(&pdev->dev, "Unable to request wdog irq.\n"); |
| 403 | goto err_irq; |
| 404 | } |
| 405 | |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 406 | return 0; |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 407 | err_irq: |
| 408 | subsys_unregister(drv->subsys); |
| 409 | err_subsys: |
| 410 | destroy_ramdump_device(drv->ramdump_dev); |
| 411 | err_ramdump: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 412 | pil_desc_release(desc); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 413 | return ret; |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static int __devexit pil_q6v3_driver_exit(struct platform_device *pdev) |
| 417 | { |
| 418 | struct q6v3_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 2e19d93 | 2012-05-09 17:36:04 -0700 | [diff] [blame] | 419 | subsys_unregister(drv->subsys); |
| 420 | destroy_ramdump_device(drv->ramdump_dev); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 421 | pil_desc_release(&drv->pil_desc); |
Stephen Boyd | 3acc9e4 | 2011-09-28 16:46:40 -0700 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static struct platform_driver pil_q6v3_driver = { |
| 426 | .probe = pil_q6v3_driver_probe, |
| 427 | .remove = __devexit_p(pil_q6v3_driver_exit), |
| 428 | .driver = { |
| 429 | .name = "pil_qdsp6v3", |
| 430 | .owner = THIS_MODULE, |
| 431 | }, |
| 432 | }; |
| 433 | |
| 434 | static int __init pil_q6v3_init(void) |
| 435 | { |
| 436 | return platform_driver_register(&pil_q6v3_driver); |
| 437 | } |
| 438 | module_init(pil_q6v3_init); |
| 439 | |
| 440 | static void __exit pil_q6v3_exit(void) |
| 441 | { |
| 442 | platform_driver_unregister(&pil_q6v3_driver); |
| 443 | } |
| 444 | module_exit(pil_q6v3_exit); |
| 445 | |
| 446 | MODULE_DESCRIPTION("Support for booting QDSP6v3 (Hexagon) processors"); |
| 447 | MODULE_LICENSE("GPL v2"); |