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