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