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