Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 1 | /* |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 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/init.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/io.h> |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/of.h> |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 20 | #include <linux/clk.h> |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 21 | #include <linux/workqueue.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/delay.h> |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 24 | #include <linux/sysfs.h> |
Ravishankar Sarawadi | 28a33ce | 2013-03-28 14:36:49 -0700 | [diff] [blame] | 25 | #include <linux/of_gpio.h> |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 26 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 27 | #include <mach/clk.h> |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 28 | #include <mach/subsystem_restart.h> |
| 29 | #include <mach/subsystem_notif.h> |
| 30 | #include <mach/scm.h> |
Seemanta Dutta | 4e2d49c | 2013-04-05 16:28:11 -0700 | [diff] [blame] | 31 | #include <mach/ramdump.h> |
Jeff Hugo | 5ba15fe | 2013-05-06 14:24:24 -0600 | [diff] [blame] | 32 | #include <mach/msm_smem.h> |
Deepak Katragadda | 4118ccc | 2013-07-05 10:01:19 -0700 | [diff] [blame] | 33 | #include <mach/msm_bus_board.h> |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 34 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 35 | #include "peripheral-loader.h" |
| 36 | #include "pil-q6v5.h" |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 37 | #include "scm-pas.h" |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 38 | #include "sysmon.h" |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 39 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 40 | #define QDSP6SS_RST_EVB 0x010 |
Matt Wagantall | 4d89c2e | 2012-05-25 19:28:34 -0700 | [diff] [blame] | 41 | #define PROXY_TIMEOUT_MS 10000 |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 42 | |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 43 | static struct kobject *lpass_status; |
| 44 | static char status[32]; |
| 45 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 46 | struct lpass_data { |
| 47 | struct q6v5_data *q6; |
| 48 | struct subsys_device *subsys; |
| 49 | struct subsys_desc subsys_desc; |
| 50 | void *ramdump_dev; |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 51 | struct work_struct work; |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 52 | void *wcnss_notif_hdle; |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 53 | void *modem_notif_hdle; |
| 54 | int crash_shutdown; |
| 55 | }; |
| 56 | |
| 57 | #define subsys_to_drv(d) container_of(d, struct lpass_data, subsys_desc) |
| 58 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 59 | static int pil_lpass_enable_clks(struct q6v5_data *drv) |
| 60 | { |
| 61 | int ret; |
| 62 | |
| 63 | ret = clk_reset(drv->core_clk, CLK_RESET_DEASSERT); |
| 64 | if (ret) |
| 65 | goto err_reset; |
| 66 | ret = clk_prepare_enable(drv->core_clk); |
| 67 | if (ret) |
| 68 | goto err_core_clk; |
| 69 | ret = clk_prepare_enable(drv->ahb_clk); |
| 70 | if (ret) |
| 71 | goto err_ahb_clk; |
| 72 | ret = clk_prepare_enable(drv->axi_clk); |
| 73 | if (ret) |
| 74 | goto err_axi_clk; |
| 75 | ret = clk_prepare_enable(drv->reg_clk); |
| 76 | if (ret) |
| 77 | goto err_reg_clk; |
| 78 | |
| 79 | return 0; |
| 80 | |
| 81 | err_reg_clk: |
| 82 | clk_disable_unprepare(drv->axi_clk); |
| 83 | err_axi_clk: |
| 84 | clk_disable_unprepare(drv->ahb_clk); |
| 85 | err_ahb_clk: |
| 86 | clk_disable_unprepare(drv->core_clk); |
| 87 | err_core_clk: |
| 88 | clk_reset(drv->core_clk, CLK_RESET_ASSERT); |
| 89 | err_reset: |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | static void pil_lpass_disable_clks(struct q6v5_data *drv) |
| 94 | { |
| 95 | clk_disable_unprepare(drv->reg_clk); |
| 96 | clk_disable_unprepare(drv->axi_clk); |
| 97 | clk_disable_unprepare(drv->ahb_clk); |
| 98 | clk_disable_unprepare(drv->core_clk); |
| 99 | clk_reset(drv->core_clk, CLK_RESET_ASSERT); |
| 100 | } |
| 101 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 102 | static int pil_lpass_shutdown(struct pil_desc *pil) |
| 103 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 104 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 105 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 106 | pil_q6v5_halt_axi_port(pil, drv->axi_halt_base); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 107 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 108 | /* |
| 109 | * If the shutdown function is called before the reset function, clocks |
| 110 | * will not be enabled yet. Enable them here so that register writes |
| 111 | * performed during the shutdown succeed. |
| 112 | */ |
| 113 | if (drv->is_booted == false) |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 114 | pil_lpass_enable_clks(drv); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 115 | |
| 116 | pil_q6v5_shutdown(pil); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 117 | pil_lpass_disable_clks(drv); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 118 | |
Matt Wagantall | 015b50af | 2013-03-05 18:51:16 -0800 | [diff] [blame] | 119 | writel_relaxed(1, drv->restart_reg); |
| 120 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 121 | drv->is_booted = false; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int pil_lpass_reset(struct pil_desc *pil) |
| 127 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 128 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Tianyi Gou | 819851e | 2013-04-16 16:05:56 -0700 | [diff] [blame] | 129 | phys_addr_t start_addr = pil_get_entry_addr(pil); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 130 | int ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 131 | |
Matt Wagantall | 015b50af | 2013-03-05 18:51:16 -0800 | [diff] [blame] | 132 | /* Deassert reset to subsystem and wait for propagation */ |
| 133 | writel_relaxed(0, drv->restart_reg); |
| 134 | mb(); |
| 135 | udelay(2); |
| 136 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 137 | ret = pil_lpass_enable_clks(drv); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 138 | if (ret) |
| 139 | return ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 140 | |
| 141 | /* Program Image Address */ |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 142 | writel_relaxed((start_addr >> 4) & 0x0FFFFFF0, |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 143 | drv->reg_base + QDSP6SS_RST_EVB); |
| 144 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 145 | ret = pil_q6v5_reset(pil); |
| 146 | if (ret) { |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 147 | pil_lpass_disable_clks(drv); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | drv->is_booted = true; |
| 152 | |
| 153 | return 0; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static struct pil_reset_ops pil_lpass_ops = { |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 157 | .proxy_vote = pil_q6v5_make_proxy_votes, |
| 158 | .proxy_unvote = pil_q6v5_remove_proxy_votes, |
| 159 | .auth_and_reset = pil_lpass_reset, |
| 160 | .shutdown = pil_lpass_shutdown, |
| 161 | }; |
| 162 | |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 163 | static int pil_lpass_init_image_trusted(struct pil_desc *pil, |
| 164 | const u8 *metadata, size_t size) |
| 165 | { |
| 166 | return pas_init_image(PAS_Q6, metadata, size); |
| 167 | } |
| 168 | |
Stephen Boyd | c8c5db9 | 2012-12-03 11:13:20 -0800 | [diff] [blame] | 169 | static int pil_lpass_mem_setup_trusted(struct pil_desc *pil, phys_addr_t addr, |
| 170 | size_t size) |
| 171 | { |
| 172 | return pas_mem_setup(PAS_Q6, addr, size); |
| 173 | } |
| 174 | |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 175 | static int pil_lpass_reset_trusted(struct pil_desc *pil) |
| 176 | { |
Vikram Mulukutla | a30b53a | 2013-05-28 15:47:22 -0700 | [diff] [blame] | 177 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
| 178 | int ret; |
| 179 | |
| 180 | ret = clk_prepare_enable(drv->axi_clk); |
| 181 | if (ret) |
| 182 | return ret; |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 183 | return pas_auth_and_reset(PAS_Q6); |
| 184 | } |
| 185 | |
| 186 | static int pil_lpass_shutdown_trusted(struct pil_desc *pil) |
| 187 | { |
Vikram Mulukutla | a30b53a | 2013-05-28 15:47:22 -0700 | [diff] [blame] | 188 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
| 189 | int ret; |
| 190 | |
| 191 | ret = pas_shutdown(PAS_Q6); |
| 192 | if (ret) |
| 193 | return ret; |
| 194 | clk_disable_unprepare(drv->axi_clk); |
| 195 | return 0; |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static struct pil_reset_ops pil_lpass_ops_trusted = { |
| 199 | .init_image = pil_lpass_init_image_trusted, |
Stephen Boyd | c8c5db9 | 2012-12-03 11:13:20 -0800 | [diff] [blame] | 200 | .mem_setup = pil_lpass_mem_setup_trusted, |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 201 | .proxy_vote = pil_q6v5_make_proxy_votes, |
| 202 | .proxy_unvote = pil_q6v5_remove_proxy_votes, |
| 203 | .auth_and_reset = pil_lpass_reset_trusted, |
| 204 | .shutdown = pil_lpass_shutdown_trusted, |
| 205 | }; |
| 206 | |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 207 | static int wcnss_notifier_cb(struct notifier_block *this, unsigned long code, |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 208 | void *ss_handle) |
| 209 | { |
| 210 | int ret; |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 211 | pr_debug("%s: W-Notify: event %lu\n", __func__, code); |
| 212 | ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss", code); |
| 213 | if (ret < 0) |
| 214 | pr_err("%s: sysmon_send_event error %d", __func__, ret); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 215 | return NOTIFY_DONE; |
| 216 | } |
| 217 | |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 218 | static struct notifier_block wnb = { |
| 219 | .notifier_call = wcnss_notifier_cb, |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | static int modem_notifier_cb(struct notifier_block *this, unsigned long code, |
| 223 | void *ss_handle) |
| 224 | { |
| 225 | int ret; |
Ravishankar Sarawadi | fadfe3b | 2012-10-12 11:28:24 -0700 | [diff] [blame] | 226 | pr_debug("%s: M-Notify: event %lu\n", __func__, code); |
| 227 | ret = sysmon_send_event(SYSMON_SS_LPASS, "modem", code); |
| 228 | if (ret < 0) |
| 229 | pr_err("%s: sysmon_send_event error %d", __func__, ret); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 230 | return NOTIFY_DONE; |
| 231 | } |
| 232 | |
| 233 | static struct notifier_block mnb = { |
| 234 | .notifier_call = modem_notifier_cb, |
| 235 | }; |
| 236 | |
| 237 | static void adsp_log_failure_reason(void) |
| 238 | { |
| 239 | char *reason; |
| 240 | char buffer[81]; |
| 241 | unsigned size; |
| 242 | |
| 243 | reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size); |
| 244 | |
| 245 | if (!reason) { |
| 246 | pr_err("ADSP subsystem failure reason: (unknown, smem_get_entry failed)."); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | if (reason[0] == '\0') { |
| 251 | pr_err("ADSP subsystem failure reason: (unknown, init value found)"); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | size = min(size, sizeof(buffer) - 1); |
| 256 | memcpy(buffer, reason, size); |
| 257 | buffer[size] = '\0'; |
| 258 | pr_err("ADSP subsystem failure reason: %s", buffer); |
| 259 | memset((void *)reason, 0x0, size); |
| 260 | wmb(); |
| 261 | } |
| 262 | |
| 263 | static void restart_adsp(struct lpass_data *drv) |
| 264 | { |
| 265 | adsp_log_failure_reason(); |
| 266 | subsystem_restart_dev(drv->subsys); |
| 267 | } |
| 268 | |
| 269 | static void adsp_fatal_fn(struct work_struct *work) |
| 270 | { |
| 271 | struct lpass_data *drv = container_of(work, struct lpass_data, work); |
| 272 | |
| 273 | pr_err("Watchdog bite received from ADSP!\n"); |
| 274 | restart_adsp(drv); |
| 275 | } |
| 276 | |
Ravishankar Sarawadi | 28a33ce | 2013-03-28 14:36:49 -0700 | [diff] [blame] | 277 | static irqreturn_t adsp_err_fatal_intr_handler (int irq, void *dev_id) |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 278 | { |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 279 | struct lpass_data *drv = subsys_to_drv(dev_id); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 280 | |
Ravishankar Sarawadi | 28a33ce | 2013-03-28 14:36:49 -0700 | [diff] [blame] | 281 | /* Ignore if we're the one that set the force stop bit in the outbound |
| 282 | * entry |
| 283 | */ |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 284 | if (drv->crash_shutdown) |
Ravishankar Sarawadi | 28a33ce | 2013-03-28 14:36:49 -0700 | [diff] [blame] | 285 | return IRQ_HANDLED; |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 286 | |
Ravishankar Sarawadi | 28a33ce | 2013-03-28 14:36:49 -0700 | [diff] [blame] | 287 | pr_err("Fatal error on the ADSP!\n"); |
| 288 | restart_adsp(drv); |
| 289 | return IRQ_HANDLED; |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | #define SCM_Q6_NMI_CMD 0x1 |
| 293 | |
| 294 | static void send_q6_nmi(void) |
| 295 | { |
| 296 | /* Send NMI to QDSP6 via an SCM call. */ |
| 297 | scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1); |
| 298 | pr_debug("%s: Q6 NMI was sent.\n", __func__); |
| 299 | } |
| 300 | |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 301 | /* |
| 302 | * The "status" file where a static variable is read from and written to. |
| 303 | */ |
| 304 | static ssize_t adsp_state_show(struct kobject *kobj, |
| 305 | struct kobj_attribute *attr, |
| 306 | char *buf) |
| 307 | { |
| 308 | return snprintf(buf, sizeof(status), "%s\n", status); |
| 309 | } |
| 310 | |
| 311 | static struct kobj_attribute adsp_state_attribute = |
| 312 | __ATTR(status, 0444, adsp_state_show, NULL); |
| 313 | |
| 314 | static struct attribute *attrs[] = { |
| 315 | &adsp_state_attribute.attr, |
| 316 | NULL, /* need to NULL terminate the list of attributes */ |
| 317 | }; |
| 318 | |
| 319 | static struct attribute_group attr_group = { |
| 320 | .attrs = attrs, |
| 321 | }; |
| 322 | |
| 323 | static void adsp_set_state(char *state) |
| 324 | { |
| 325 | strlcpy(status, state, sizeof(status)); |
| 326 | sysfs_notify(lpass_status, NULL, "status"); |
| 327 | } |
| 328 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 329 | #define subsys_to_lpass(d) container_of(d, struct lpass_data, subsys_desc) |
| 330 | |
| 331 | static int adsp_shutdown(const struct subsys_desc *subsys) |
| 332 | { |
| 333 | struct lpass_data *drv = subsys_to_lpass(subsys); |
| 334 | |
| 335 | send_q6_nmi(); |
| 336 | /* The write needs to go through before the q6 is shutdown. */ |
| 337 | mb(); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 338 | pil_shutdown(&drv->q6->desc); |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 339 | disable_irq_nosync(drv->subsys_desc.wdog_bite_irq); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 340 | |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 341 | pr_debug("ADSP is Down\n"); |
| 342 | adsp_set_state("OFFLINE"); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static int adsp_powerup(const struct subsys_desc *subsys) |
| 347 | { |
| 348 | struct lpass_data *drv = subsys_to_lpass(subsys); |
| 349 | int ret = 0; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 350 | ret = pil_boot(&drv->q6->desc); |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 351 | enable_irq(drv->subsys_desc.wdog_bite_irq); |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 352 | |
| 353 | pr_debug("ADSP is back online\n"); |
| 354 | adsp_set_state("ONLINE"); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 355 | return ret; |
| 356 | } |
| 357 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 358 | static int adsp_ramdump(int enable, const struct subsys_desc *subsys) |
| 359 | { |
| 360 | struct lpass_data *drv = subsys_to_lpass(subsys); |
| 361 | |
| 362 | if (!enable) |
| 363 | return 0; |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 364 | |
| 365 | return pil_do_ramdump(&drv->q6->desc, drv->ramdump_dev); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static void adsp_crash_shutdown(const struct subsys_desc *subsys) |
| 369 | { |
| 370 | struct lpass_data *drv = subsys_to_lpass(subsys); |
| 371 | |
| 372 | drv->crash_shutdown = 1; |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 373 | gpio_set_value(subsys->force_stop_gpio, 1); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 374 | send_q6_nmi(); |
| 375 | } |
| 376 | |
| 377 | static irqreturn_t adsp_wdog_bite_irq(int irq, void *dev_id) |
| 378 | { |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 379 | struct lpass_data *drv = subsys_to_drv(dev_id); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 380 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 381 | schedule_work(&drv->work); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 382 | return IRQ_HANDLED; |
| 383 | } |
| 384 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 385 | static int lpass_start(const struct subsys_desc *desc) |
| 386 | { |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 387 | struct lpass_data *drv = subsys_to_drv(desc); |
| 388 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 389 | return pil_boot(&drv->q6->desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void lpass_stop(const struct subsys_desc *desc) |
| 393 | { |
| 394 | struct lpass_data *drv = subsys_to_drv(desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 395 | pil_shutdown(&drv->q6->desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 398 | static int __devinit pil_lpass_driver_probe(struct platform_device *pdev) |
| 399 | { |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 400 | struct lpass_data *drv; |
| 401 | struct q6v5_data *q6; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 402 | struct pil_desc *desc; |
Matt Wagantall | 015b50af | 2013-03-05 18:51:16 -0800 | [diff] [blame] | 403 | struct resource *res; |
Seemanta Dutta | d99446c | 2013-06-17 18:05:18 -0700 | [diff] [blame] | 404 | int ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 405 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 406 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 407 | if (!drv) |
| 408 | return -ENOMEM; |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 409 | platform_set_drvdata(pdev, drv); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 410 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 411 | q6 = pil_q6v5_init(pdev); |
| 412 | if (IS_ERR(q6)) |
| 413 | return PTR_ERR(q6); |
| 414 | drv->q6 = q6; |
| 415 | |
| 416 | desc = &q6->desc; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 417 | desc->owner = THIS_MODULE; |
Matt Wagantall | 4d89c2e | 2012-05-25 19:28:34 -0700 | [diff] [blame] | 418 | desc->proxy_timeout = PROXY_TIMEOUT_MS; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 419 | |
Matt Wagantall | 015b50af | 2013-03-05 18:51:16 -0800 | [diff] [blame] | 420 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg"); |
| 421 | q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res); |
| 422 | if (!q6->restart_reg) |
| 423 | return -ENOMEM; |
| 424 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 425 | q6->core_clk = devm_clk_get(&pdev->dev, "core_clk"); |
| 426 | if (IS_ERR(q6->core_clk)) |
| 427 | return PTR_ERR(q6->core_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 428 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 429 | q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk"); |
| 430 | if (IS_ERR(q6->ahb_clk)) |
| 431 | return PTR_ERR(q6->ahb_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 432 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 433 | q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk"); |
| 434 | if (IS_ERR(q6->axi_clk)) |
| 435 | return PTR_ERR(q6->axi_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 436 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 437 | q6->reg_clk = devm_clk_get(&pdev->dev, "reg_clk"); |
| 438 | if (IS_ERR(q6->reg_clk)) |
| 439 | return PTR_ERR(q6->reg_clk); |
Matt Wagantall | 56865f0 | 2012-08-09 15:03:36 -0700 | [diff] [blame] | 440 | |
Matt Wagantall | 10a5967 | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 441 | if (pas_supported(PAS_Q6) > 0) { |
| 442 | desc->ops = &pil_lpass_ops_trusted; |
| 443 | dev_info(&pdev->dev, "using secure boot\n"); |
| 444 | } else { |
| 445 | desc->ops = &pil_lpass_ops; |
| 446 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 447 | } |
| 448 | |
Deepak Katragadda | 4118ccc | 2013-07-05 10:01:19 -0700 | [diff] [blame] | 449 | scm_pas_init(MSM_BUS_MASTER_CRYPTO_CORE0); |
| 450 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 451 | ret = pil_desc_init(desc); |
| 452 | if (ret) |
| 453 | return ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 454 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 455 | drv->subsys_desc.name = desc->name; |
| 456 | drv->subsys_desc.owner = THIS_MODULE; |
| 457 | drv->subsys_desc.dev = &pdev->dev; |
| 458 | drv->subsys_desc.shutdown = adsp_shutdown; |
| 459 | drv->subsys_desc.powerup = adsp_powerup; |
| 460 | drv->subsys_desc.ramdump = adsp_ramdump; |
| 461 | drv->subsys_desc.crash_shutdown = adsp_crash_shutdown; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 462 | drv->subsys_desc.start = lpass_start; |
| 463 | drv->subsys_desc.stop = lpass_stop; |
Seemanta Dutta | 076d00e | 2013-06-17 17:58:18 -0700 | [diff] [blame] | 464 | drv->subsys_desc.err_fatal_handler = adsp_err_fatal_intr_handler; |
| 465 | drv->subsys_desc.wdog_bite_handler = adsp_wdog_bite_irq; |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 466 | |
| 467 | INIT_WORK(&drv->work, adsp_fatal_fn); |
| 468 | |
Stephen Boyd | c1a7261 | 2012-07-05 14:07:35 -0700 | [diff] [blame] | 469 | drv->ramdump_dev = create_ramdump_device("adsp", &pdev->dev); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 470 | if (!drv->ramdump_dev) { |
| 471 | ret = -ENOMEM; |
| 472 | goto err_ramdump; |
| 473 | } |
| 474 | |
| 475 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 476 | if (IS_ERR(drv->subsys)) { |
| 477 | ret = PTR_ERR(drv->subsys); |
| 478 | goto err_subsys; |
| 479 | } |
| 480 | |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 481 | drv->wcnss_notif_hdle = subsys_notif_register_notifier("wcnss", &wnb); |
| 482 | if (IS_ERR(drv->wcnss_notif_hdle)) { |
| 483 | ret = PTR_ERR(drv->wcnss_notif_hdle); |
| 484 | goto err_notif_wcnss; |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | drv->modem_notif_hdle = subsys_notif_register_notifier("modem", &mnb); |
| 488 | if (IS_ERR(drv->modem_notif_hdle)) { |
| 489 | ret = PTR_ERR(drv->modem_notif_hdle); |
| 490 | goto err_notif_modem; |
| 491 | } |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 492 | lpass_status = kobject_create_and_add("audio_voice_service", |
| 493 | kernel_kobj); |
| 494 | if (!lpass_status) { |
| 495 | pr_err("%s: kobject create failed\n", __func__); |
| 496 | ret = -ENOMEM; |
Deepak Katragadda | 7b9cc48 | 2013-10-16 16:19:09 -0700 | [diff] [blame] | 497 | goto err_create_kobj; |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | ret = sysfs_create_group(lpass_status, &attr_group); |
| 501 | if (ret) { |
| 502 | pr_err("%s: sysfs create group failed\n", __func__); |
| 503 | goto err_kobj; |
| 504 | } |
| 505 | |
| 506 | adsp_set_state("ONLINE"); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 507 | return 0; |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 508 | err_kobj: |
| 509 | kobject_put(lpass_status); |
Deepak Katragadda | 7b9cc48 | 2013-10-16 16:19:09 -0700 | [diff] [blame] | 510 | err_create_kobj: |
| 511 | subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 512 | err_notif_modem: |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 513 | subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb); |
| 514 | err_notif_wcnss: |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 515 | subsys_unregister(drv->subsys); |
| 516 | err_subsys: |
| 517 | destroy_ramdump_device(drv->ramdump_dev); |
| 518 | err_ramdump: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 519 | pil_desc_release(desc); |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 520 | return ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static int __devexit pil_lpass_driver_exit(struct platform_device *pdev) |
| 524 | { |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 525 | struct lpass_data *drv = platform_get_drvdata(pdev); |
Ravishankar Sarawadi | c14fb5e | 2013-04-03 17:39:46 -0700 | [diff] [blame] | 526 | subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 527 | subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb); |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 528 | subsys_unregister(drv->subsys); |
| 529 | destroy_ramdump_device(drv->ramdump_dev); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 530 | pil_desc_release(&drv->q6->desc); |
Phani Kumar Uppalapati | 598a1da | 2013-01-24 12:29:54 -0800 | [diff] [blame] | 531 | sysfs_remove_group(lpass_status, &attr_group); |
| 532 | kobject_del(lpass_status); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static struct of_device_id lpass_match_table[] = { |
| 537 | { .compatible = "qcom,pil-q6v5-lpass" }, |
| 538 | {} |
| 539 | }; |
| 540 | |
| 541 | static struct platform_driver pil_lpass_driver = { |
| 542 | .probe = pil_lpass_driver_probe, |
| 543 | .remove = __devexit_p(pil_lpass_driver_exit), |
| 544 | .driver = { |
| 545 | .name = "pil-q6v5-lpass", |
| 546 | .of_match_table = lpass_match_table, |
| 547 | .owner = THIS_MODULE, |
| 548 | }, |
| 549 | }; |
| 550 | |
| 551 | static int __init pil_lpass_init(void) |
| 552 | { |
| 553 | return platform_driver_register(&pil_lpass_driver); |
| 554 | } |
| 555 | module_init(pil_lpass_init); |
| 556 | |
| 557 | static void __exit pil_lpass_exit(void) |
| 558 | { |
| 559 | platform_driver_unregister(&pil_lpass_driver); |
| 560 | } |
| 561 | module_exit(pil_lpass_exit); |
| 562 | |
| 563 | MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors"); |
| 564 | MODULE_LICENSE("GPL v2"); |