Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 1 | /* |
Matt Wagantall | f5c44bd | 2012-10-29 12:20:07 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -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> |
| 18 | #include <linux/iopoll.h> |
| 19 | #include <linux/ioport.h> |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/of.h> |
| 25 | #include <linux/regulator/consumer.h> |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 27 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 28 | #include <mach/subsystem_restart.h> |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 29 | #include <mach/clk.h> |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 30 | #include <mach/msm_smsm.h> |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 31 | |
| 32 | #include "peripheral-loader.h" |
| 33 | #include "pil-q6v5.h" |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 34 | #include "ramdump.h" |
Vikram Mulukutla | 896d058 | 2012-10-17 16:57:46 -0700 | [diff] [blame] | 35 | #include "sysmon.h" |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 36 | |
| 37 | /* Q6 Register Offsets */ |
| 38 | #define QDSP6SS_RST_EVB 0x010 |
| 39 | |
| 40 | /* AXI Halting Registers */ |
| 41 | #define MSS_Q6_HALT_BASE 0x180 |
| 42 | #define MSS_MODEM_HALT_BASE 0x200 |
| 43 | #define MSS_NC_HALT_BASE 0x280 |
| 44 | |
| 45 | /* RMB Status Register Values */ |
| 46 | #define STATUS_PBL_SUCCESS 0x1 |
| 47 | #define STATUS_XPU_UNLOCKED 0x1 |
| 48 | #define STATUS_XPU_UNLOCKED_SCRIBBLED 0x2 |
| 49 | |
| 50 | /* PBL/MBA interface registers */ |
| 51 | #define RMB_MBA_IMAGE 0x00 |
| 52 | #define RMB_PBL_STATUS 0x04 |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 53 | #define RMB_MBA_COMMAND 0x08 |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 54 | #define RMB_MBA_STATUS 0x0C |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 55 | #define RMB_PMI_META_DATA 0x10 |
| 56 | #define RMB_PMI_CODE_START 0x14 |
| 57 | #define RMB_PMI_CODE_LENGTH 0x18 |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 58 | |
Matt Wagantall | 70315fb | 2012-12-03 16:33:28 -0800 | [diff] [blame] | 59 | #define VDD_MSS_UV 1050000 |
| 60 | #define MAX_VDD_MX_UV 1050000 |
| 61 | |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 62 | #define PROXY_TIMEOUT_MS 10000 |
| 63 | #define POLL_INTERVAL_US 50 |
| 64 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 65 | #define CMD_META_DATA_READY 0x1 |
| 66 | #define CMD_LOAD_READY 0x2 |
| 67 | |
| 68 | #define STATUS_META_DATA_AUTH_SUCCESS 0x3 |
| 69 | #define STATUS_AUTH_COMPLETE 0x4 |
| 70 | |
| 71 | #define MAX_SSR_REASON_LEN 81U |
| 72 | |
| 73 | struct mba_data { |
| 74 | void __iomem *metadata_base; |
| 75 | void __iomem *rmb_base; |
| 76 | void __iomem *io_clamp_reg; |
| 77 | unsigned long metadata_phys; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 78 | struct pil_desc desc; |
| 79 | struct subsys_device *subsys; |
| 80 | struct subsys_desc subsys_desc; |
Vikram Mulukutla | 896d058 | 2012-10-17 16:57:46 -0700 | [diff] [blame] | 81 | void *adsp_state_notifier; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 82 | u32 img_length; |
| 83 | struct q6v5_data *q6; |
| 84 | int self_auth; |
| 85 | void *ramdump_dev; |
| 86 | void *smem_ramdump_dev; |
| 87 | bool crash_shutdown; |
| 88 | bool ignore_errors; |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 89 | int is_loadable; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Matt Wagantall | d251d8e | 2012-08-16 18:53:53 -0700 | [diff] [blame] | 92 | static int pbl_mba_boot_timeout_ms = 100; |
| 93 | module_param(pbl_mba_boot_timeout_ms, int, S_IRUGO | S_IWUSR); |
| 94 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 95 | static int modem_auth_timeout_ms = 10000; |
| 96 | module_param(modem_auth_timeout_ms, int, S_IRUGO | S_IWUSR); |
| 97 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 98 | static int pil_mss_power_up(struct q6v5_data *drv) |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 99 | { |
| 100 | int ret; |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 101 | struct device *dev = drv->desc.dev; |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 102 | |
| 103 | ret = regulator_enable(drv->vreg); |
| 104 | if (ret) |
Matt Wagantall | 70315fb | 2012-12-03 16:33:28 -0800 | [diff] [blame] | 105 | dev_err(dev, "Failed to enable modem regulator.\n"); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 106 | |
| 107 | return ret; |
| 108 | } |
| 109 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 110 | static int pil_mss_power_down(struct q6v5_data *drv) |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 111 | { |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 112 | return regulator_disable(drv->vreg); |
| 113 | } |
| 114 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 115 | static int pil_mss_enable_clks(struct q6v5_data *drv) |
| 116 | { |
| 117 | int ret; |
| 118 | |
| 119 | ret = clk_prepare_enable(drv->ahb_clk); |
| 120 | if (ret) |
| 121 | goto err_ahb_clk; |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 122 | ret = clk_prepare_enable(drv->axi_clk); |
| 123 | if (ret) |
| 124 | goto err_axi_clk; |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 125 | ret = clk_prepare_enable(drv->rom_clk); |
| 126 | if (ret) |
| 127 | goto err_rom_clk; |
| 128 | |
| 129 | return 0; |
| 130 | |
| 131 | err_rom_clk: |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 132 | clk_disable_unprepare(drv->axi_clk); |
| 133 | err_axi_clk: |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 134 | clk_disable_unprepare(drv->ahb_clk); |
| 135 | err_ahb_clk: |
| 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | static void pil_mss_disable_clks(struct q6v5_data *drv) |
| 140 | { |
| 141 | clk_disable_unprepare(drv->rom_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 142 | clk_disable_unprepare(drv->axi_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 143 | clk_disable_unprepare(drv->ahb_clk); |
| 144 | } |
| 145 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 146 | static int wait_for_mba_ready(struct q6v5_data *drv) |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 147 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 148 | struct device *dev = drv->desc.dev; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 149 | struct mba_data *mba = platform_get_drvdata(to_platform_device(dev)); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 150 | int ret; |
| 151 | u32 status; |
| 152 | |
| 153 | /* Wait for PBL completion. */ |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 154 | ret = readl_poll_timeout(mba->rmb_base + RMB_PBL_STATUS, status, |
Matt Wagantall | d251d8e | 2012-08-16 18:53:53 -0700 | [diff] [blame] | 155 | status != 0, POLL_INTERVAL_US, pbl_mba_boot_timeout_ms * 1000); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 156 | if (ret) { |
| 157 | dev_err(dev, "PBL boot timed out\n"); |
| 158 | return ret; |
| 159 | } |
| 160 | if (status != STATUS_PBL_SUCCESS) { |
| 161 | dev_err(dev, "PBL returned unexpected status %d\n", status); |
| 162 | return -EINVAL; |
| 163 | } |
| 164 | |
| 165 | /* Wait for MBA completion. */ |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 166 | ret = readl_poll_timeout(mba->rmb_base + RMB_MBA_STATUS, status, |
Matt Wagantall | d251d8e | 2012-08-16 18:53:53 -0700 | [diff] [blame] | 167 | status != 0, POLL_INTERVAL_US, pbl_mba_boot_timeout_ms * 1000); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 168 | if (ret) { |
| 169 | dev_err(dev, "MBA boot timed out\n"); |
| 170 | return ret; |
| 171 | } |
| 172 | if (status != STATUS_XPU_UNLOCKED && |
| 173 | status != STATUS_XPU_UNLOCKED_SCRIBBLED) { |
| 174 | dev_err(dev, "MBA returned unexpected status %d\n", status); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static int pil_mss_shutdown(struct pil_desc *pil) |
| 182 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 183 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 184 | |
| 185 | pil_q6v5_halt_axi_port(pil, drv->axi_halt_base + MSS_Q6_HALT_BASE); |
| 186 | pil_q6v5_halt_axi_port(pil, drv->axi_halt_base + MSS_MODEM_HALT_BASE); |
| 187 | pil_q6v5_halt_axi_port(pil, drv->axi_halt_base + MSS_NC_HALT_BASE); |
| 188 | |
| 189 | /* |
| 190 | * If the shutdown function is called before the reset function, clocks |
| 191 | * and power will not be enabled yet. Enable them here so that register |
| 192 | * writes performed during the shutdown succeed. |
| 193 | */ |
| 194 | if (drv->is_booted == false) { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 195 | pil_mss_power_up(drv); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 196 | pil_mss_enable_clks(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 197 | } |
| 198 | pil_q6v5_shutdown(pil); |
| 199 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 200 | pil_mss_disable_clks(drv); |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 201 | pil_mss_power_down(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 202 | |
| 203 | writel_relaxed(1, drv->restart_reg); |
| 204 | |
| 205 | drv->is_booted = false; |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static int pil_mss_reset(struct pil_desc *pil) |
| 211 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 212 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 213 | struct platform_device *pdev = to_platform_device(pil->dev); |
| 214 | struct mba_data *mba = platform_get_drvdata(pdev); |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 215 | unsigned long start_addr = pil_get_entry_addr(pil); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 216 | int ret; |
| 217 | |
Matt Wagantall | 33c2ec7 | 2012-07-26 20:26:57 -0700 | [diff] [blame] | 218 | /* Deassert reset to subsystem and wait for propagation */ |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 219 | writel_relaxed(0, drv->restart_reg); |
| 220 | mb(); |
Matt Wagantall | 33c2ec7 | 2012-07-26 20:26:57 -0700 | [diff] [blame] | 221 | udelay(2); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * Bring subsystem out of reset and enable required |
| 225 | * regulators and clocks. |
| 226 | */ |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 227 | ret = pil_mss_power_up(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 228 | if (ret) |
| 229 | goto err_power; |
| 230 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 231 | ret = pil_mss_enable_clks(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 232 | if (ret) |
| 233 | goto err_clks; |
| 234 | |
| 235 | /* Program Image Address */ |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 236 | if (mba->self_auth) { |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 237 | writel_relaxed(start_addr, mba->rmb_base + RMB_MBA_IMAGE); |
Matt Wagantall | f11928a | 2012-07-27 15:47:59 -0700 | [diff] [blame] | 238 | /* Ensure write to RMB base occurs before reset is released. */ |
| 239 | mb(); |
| 240 | } else { |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 241 | writel_relaxed((start_addr >> 4) & 0x0FFFFFF0, |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 242 | drv->reg_base + QDSP6SS_RST_EVB); |
Matt Wagantall | f11928a | 2012-07-27 15:47:59 -0700 | [diff] [blame] | 243 | } |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 244 | |
| 245 | ret = pil_q6v5_reset(pil); |
| 246 | if (ret) |
| 247 | goto err_q6v5_reset; |
| 248 | |
| 249 | /* Wait for MBA to start. Check for PBL and MBA errors while waiting. */ |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 250 | if (mba->self_auth) { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 251 | ret = wait_for_mba_ready(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 252 | if (ret) |
| 253 | goto err_auth; |
| 254 | } |
| 255 | |
| 256 | drv->is_booted = true; |
| 257 | |
| 258 | return 0; |
| 259 | |
| 260 | err_auth: |
| 261 | pil_q6v5_shutdown(pil); |
| 262 | err_q6v5_reset: |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 263 | pil_mss_disable_clks(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 264 | err_clks: |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 265 | pil_mss_power_down(drv); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 266 | err_power: |
| 267 | return ret; |
| 268 | } |
| 269 | |
Matt Wagantall | 70315fb | 2012-12-03 16:33:28 -0800 | [diff] [blame] | 270 | static int pil_q6v5_mss_make_proxy_votes(struct pil_desc *pil) |
| 271 | { |
| 272 | int ret; |
| 273 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
| 274 | |
| 275 | ret = regulator_set_voltage(drv->vreg_mx, VDD_MSS_UV, MAX_VDD_MX_UV); |
| 276 | if (ret) { |
| 277 | dev_err(pil->dev, "Failed to request vreg_mx voltage\n"); |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | ret = regulator_enable(drv->vreg_mx); |
| 282 | if (ret) { |
| 283 | dev_err(pil->dev, "Failed to enable vreg_mx\n"); |
| 284 | regulator_set_voltage(drv->vreg_mx, 0, MAX_VDD_MX_UV); |
| 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | ret = pil_q6v5_make_proxy_votes(pil); |
| 289 | if (ret) { |
| 290 | regulator_disable(drv->vreg_mx); |
| 291 | regulator_set_voltage(drv->vreg_mx, 0, MAX_VDD_MX_UV); |
| 292 | } |
| 293 | |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static void pil_q6v5_mss_remove_proxy_votes(struct pil_desc *pil) |
| 298 | { |
| 299 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
| 300 | pil_q6v5_remove_proxy_votes(pil); |
| 301 | regulator_disable(drv->vreg_mx); |
| 302 | regulator_set_voltage(drv->vreg_mx, 0, MAX_VDD_MX_UV); |
| 303 | } |
| 304 | |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 305 | static struct pil_reset_ops pil_mss_ops = { |
Matt Wagantall | 70315fb | 2012-12-03 16:33:28 -0800 | [diff] [blame] | 306 | .proxy_vote = pil_q6v5_mss_make_proxy_votes, |
| 307 | .proxy_unvote = pil_q6v5_mss_remove_proxy_votes, |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 308 | .auth_and_reset = pil_mss_reset, |
| 309 | .shutdown = pil_mss_shutdown, |
| 310 | }; |
| 311 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 312 | static int pil_mba_make_proxy_votes(struct pil_desc *pil) |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 313 | { |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 314 | int ret; |
| 315 | struct mba_data *drv = dev_get_drvdata(pil->dev); |
| 316 | |
| 317 | ret = clk_prepare_enable(drv->q6->xo); |
| 318 | if (ret) { |
| 319 | dev_err(pil->dev, "Failed to enable XO\n"); |
| 320 | return ret; |
| 321 | } |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static void pil_mba_remove_proxy_votes(struct pil_desc *pil) |
| 326 | { |
| 327 | struct mba_data *drv = dev_get_drvdata(pil->dev); |
| 328 | clk_disable_unprepare(drv->q6->xo); |
| 329 | } |
| 330 | |
| 331 | static int pil_mba_init_image(struct pil_desc *pil, |
| 332 | const u8 *metadata, size_t size) |
| 333 | { |
| 334 | struct mba_data *drv = dev_get_drvdata(pil->dev); |
| 335 | s32 status; |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 336 | int ret; |
| 337 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 338 | /* Copy metadata to assigned shared buffer location */ |
| 339 | memcpy(drv->metadata_base, metadata, size); |
| 340 | |
| 341 | /* Initialize length counter to 0 */ |
| 342 | writel_relaxed(0, drv->rmb_base + RMB_PMI_CODE_LENGTH); |
| 343 | drv->img_length = 0; |
| 344 | |
| 345 | /* Pass address of meta-data to the MBA and perform authentication */ |
| 346 | writel_relaxed(drv->metadata_phys, drv->rmb_base + RMB_PMI_META_DATA); |
| 347 | writel_relaxed(CMD_META_DATA_READY, drv->rmb_base + RMB_MBA_COMMAND); |
| 348 | ret = readl_poll_timeout(drv->rmb_base + RMB_MBA_STATUS, status, |
| 349 | status == STATUS_META_DATA_AUTH_SUCCESS || status < 0, |
| 350 | POLL_INTERVAL_US, modem_auth_timeout_ms * 1000); |
| 351 | if (ret) { |
| 352 | dev_err(pil->dev, "MBA authentication of headers timed out\n"); |
| 353 | } else if (status < 0) { |
| 354 | dev_err(pil->dev, "MBA returned error %d for headers\n", |
| 355 | status); |
| 356 | ret = -EINVAL; |
| 357 | } |
| 358 | |
| 359 | return ret; |
| 360 | } |
| 361 | |
| 362 | static int pil_mba_verify_blob(struct pil_desc *pil, u32 phy_addr, |
| 363 | size_t size) |
| 364 | { |
| 365 | struct mba_data *drv = dev_get_drvdata(pil->dev); |
| 366 | s32 status; |
| 367 | |
| 368 | /* Begin image authentication */ |
| 369 | if (drv->img_length == 0) { |
| 370 | writel_relaxed(phy_addr, drv->rmb_base + RMB_PMI_CODE_START); |
| 371 | writel_relaxed(CMD_LOAD_READY, drv->rmb_base + RMB_MBA_COMMAND); |
| 372 | } |
| 373 | /* Increment length counter */ |
| 374 | drv->img_length += size; |
| 375 | writel_relaxed(drv->img_length, drv->rmb_base + RMB_PMI_CODE_LENGTH); |
| 376 | |
| 377 | status = readl_relaxed(drv->rmb_base + RMB_MBA_STATUS); |
| 378 | if (status < 0) { |
| 379 | dev_err(pil->dev, "MBA returned error %d\n", status); |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int pil_mba_auth(struct pil_desc *pil) |
| 387 | { |
| 388 | struct mba_data *drv = dev_get_drvdata(pil->dev); |
| 389 | int ret; |
| 390 | s32 status; |
| 391 | |
| 392 | /* Wait for all segments to be authenticated or an error to occur */ |
| 393 | ret = readl_poll_timeout(drv->rmb_base + RMB_MBA_STATUS, status, |
| 394 | status == STATUS_AUTH_COMPLETE || status < 0, |
| 395 | 50, modem_auth_timeout_ms * 1000); |
| 396 | if (ret) { |
| 397 | dev_err(pil->dev, "MBA authentication of image timed out\n"); |
| 398 | } else if (status < 0) { |
| 399 | dev_err(pil->dev, "MBA returned error %d for image\n", status); |
| 400 | ret = -EINVAL; |
| 401 | } |
| 402 | |
| 403 | return ret; |
| 404 | } |
| 405 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 406 | static struct pil_reset_ops pil_mba_ops = { |
| 407 | .init_image = pil_mba_init_image, |
| 408 | .proxy_vote = pil_mba_make_proxy_votes, |
| 409 | .proxy_unvote = pil_mba_remove_proxy_votes, |
| 410 | .verify_blob = pil_mba_verify_blob, |
| 411 | .auth_and_reset = pil_mba_auth, |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | #define subsys_to_drv(d) container_of(d, struct mba_data, subsys_desc) |
| 415 | |
| 416 | static void log_modem_sfr(void) |
| 417 | { |
| 418 | u32 size; |
| 419 | char *smem_reason, reason[MAX_SSR_REASON_LEN]; |
| 420 | |
| 421 | smem_reason = smem_get_entry(SMEM_SSR_REASON_MSS0, &size); |
| 422 | if (!smem_reason || !size) { |
| 423 | pr_err("modem subsystem failure reason: (unknown, smem_get_entry failed).\n"); |
| 424 | return; |
| 425 | } |
| 426 | if (!smem_reason[0]) { |
| 427 | pr_err("modem subsystem failure reason: (unknown, empty string found).\n"); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | strlcpy(reason, smem_reason, min(size, sizeof(reason))); |
| 432 | pr_err("modem subsystem failure reason: %s.\n", reason); |
| 433 | |
| 434 | smem_reason[0] = '\0'; |
| 435 | wmb(); |
| 436 | } |
| 437 | |
| 438 | static void restart_modem(struct mba_data *drv) |
| 439 | { |
| 440 | log_modem_sfr(); |
| 441 | drv->ignore_errors = true; |
| 442 | subsystem_restart_dev(drv->subsys); |
| 443 | } |
| 444 | |
| 445 | static void smsm_state_cb(void *data, uint32_t old_state, uint32_t new_state) |
| 446 | { |
| 447 | struct mba_data *drv = data; |
| 448 | |
| 449 | /* Ignore if we're the one that set SMSM_RESET */ |
| 450 | if (drv->crash_shutdown) |
| 451 | return; |
| 452 | |
| 453 | if (new_state & SMSM_RESET) { |
| 454 | pr_err("Probable fatal error on the modem.\n"); |
| 455 | restart_modem(drv); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | static int modem_shutdown(const struct subsys_desc *subsys) |
| 460 | { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 461 | struct mba_data *drv = subsys_to_drv(subsys); |
| 462 | |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 463 | if (!drv->is_loadable) |
Vikram Mulukutla | 1d958af | 2012-11-20 14:06:12 -0800 | [diff] [blame] | 464 | return 0; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 465 | /* MBA doesn't support shutdown */ |
| 466 | pil_shutdown(&drv->q6->desc); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int modem_powerup(const struct subsys_desc *subsys) |
| 471 | { |
| 472 | struct mba_data *drv = subsys_to_drv(subsys); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 473 | int ret; |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 474 | |
| 475 | if (!drv->is_loadable) |
Vikram Mulukutla | 1d958af | 2012-11-20 14:06:12 -0800 | [diff] [blame] | 476 | return 0; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 477 | /* |
| 478 | * At this time, the modem is shutdown. Therefore this function cannot |
| 479 | * run concurrently with either the watchdog bite error handler or the |
| 480 | * SMSM callback, making it safe to unset the flag below. |
| 481 | */ |
| 482 | drv->ignore_errors = false; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 483 | ret = pil_boot(&drv->q6->desc); |
| 484 | if (ret) |
| 485 | return ret; |
| 486 | ret = pil_boot(&drv->desc); |
| 487 | if (ret) |
| 488 | pil_shutdown(&drv->q6->desc); |
| 489 | return ret; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static void modem_crash_shutdown(const struct subsys_desc *subsys) |
| 493 | { |
| 494 | struct mba_data *drv = subsys_to_drv(subsys); |
| 495 | drv->crash_shutdown = true; |
| 496 | smsm_reset_modem(SMSM_RESET); |
| 497 | } |
| 498 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 499 | static struct ramdump_segment smem_segments[] = { |
| 500 | {0x0FA00000, 0x0FC00000 - 0x0FA00000}, |
| 501 | }; |
| 502 | |
| 503 | static int modem_ramdump(int enable, const struct subsys_desc *subsys) |
| 504 | { |
| 505 | struct mba_data *drv = subsys_to_drv(subsys); |
| 506 | int ret; |
| 507 | |
| 508 | if (!enable) |
| 509 | return 0; |
| 510 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 511 | ret = pil_boot(&drv->q6->desc); |
| 512 | if (ret) |
| 513 | return ret; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 514 | |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 515 | ret = pil_do_ramdump(&drv->q6->desc, drv->ramdump_dev); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 516 | if (ret < 0) { |
| 517 | pr_err("Unable to dump modem fw memory (rc = %d).\n", ret); |
| 518 | goto out; |
| 519 | } |
| 520 | |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 521 | ret = do_elf_ramdump(drv->smem_ramdump_dev, smem_segments, |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 522 | ARRAY_SIZE(smem_segments)); |
| 523 | if (ret < 0) { |
| 524 | pr_err("Unable to dump smem memory (rc = %d).\n", ret); |
| 525 | goto out; |
| 526 | } |
| 527 | |
| 528 | out: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 529 | pil_shutdown(&drv->q6->desc); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 530 | return ret; |
| 531 | } |
| 532 | |
Vikram Mulukutla | 896d058 | 2012-10-17 16:57:46 -0700 | [diff] [blame] | 533 | static int adsp_state_notifier_fn(struct notifier_block *this, |
| 534 | unsigned long code, void *ss_handle) |
| 535 | { |
| 536 | int ret; |
| 537 | ret = sysmon_send_event(SYSMON_SS_MODEM, "adsp", code); |
| 538 | if (ret < 0) |
| 539 | pr_err("%s: sysmon_send_event failed (%d).", __func__, ret); |
| 540 | return NOTIFY_DONE; |
| 541 | } |
| 542 | |
| 543 | static struct notifier_block adsp_state_notifier_block = { |
| 544 | .notifier_call = adsp_state_notifier_fn, |
| 545 | }; |
| 546 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 547 | static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id) |
| 548 | { |
| 549 | struct mba_data *drv = dev_id; |
| 550 | if (drv->ignore_errors) |
| 551 | return IRQ_HANDLED; |
| 552 | pr_err("Watchdog bite received from modem software!\n"); |
| 553 | restart_modem(drv); |
| 554 | return IRQ_HANDLED; |
| 555 | } |
| 556 | |
| 557 | static int mss_start(const struct subsys_desc *desc) |
| 558 | { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 559 | int ret; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 560 | struct mba_data *drv = subsys_to_drv(desc); |
| 561 | |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 562 | if (!drv->is_loadable) |
Vikram Mulukutla | 1d958af | 2012-11-20 14:06:12 -0800 | [diff] [blame] | 563 | return 0; |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 564 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 565 | ret = pil_boot(&drv->q6->desc); |
| 566 | if (ret) |
| 567 | return ret; |
| 568 | ret = pil_boot(&drv->desc); |
| 569 | if (ret) |
| 570 | pil_shutdown(&drv->q6->desc); |
| 571 | return ret; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | static void mss_stop(const struct subsys_desc *desc) |
| 575 | { |
| 576 | struct mba_data *drv = subsys_to_drv(desc); |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 577 | |
| 578 | if (!drv->is_loadable) |
| 579 | return; |
| 580 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 581 | /* MBA doesn't support shutdown */ |
| 582 | pil_shutdown(&drv->q6->desc); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 585 | static int __devinit pil_subsys_init(struct mba_data *drv, |
| 586 | struct platform_device *pdev) |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 587 | { |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 588 | int irq, ret; |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 589 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 590 | irq = platform_get_irq(pdev, 0); |
| 591 | if (irq < 0) |
| 592 | return irq; |
| 593 | |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 594 | drv->subsys_desc.name = "modem"; |
| 595 | drv->subsys_desc.dev = &pdev->dev; |
| 596 | drv->subsys_desc.owner = THIS_MODULE; |
| 597 | drv->subsys_desc.shutdown = modem_shutdown; |
| 598 | drv->subsys_desc.powerup = modem_powerup; |
| 599 | drv->subsys_desc.ramdump = modem_ramdump; |
| 600 | drv->subsys_desc.crash_shutdown = modem_crash_shutdown; |
| 601 | drv->subsys_desc.start = mss_start; |
| 602 | drv->subsys_desc.stop = mss_stop; |
| 603 | |
| 604 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 605 | if (IS_ERR(drv->subsys)) { |
| 606 | ret = PTR_ERR(drv->subsys); |
| 607 | goto err_subsys; |
| 608 | } |
| 609 | |
| 610 | drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev); |
| 611 | if (!drv->ramdump_dev) { |
| 612 | pr_err("%s: Unable to create a modem ramdump device.\n", |
| 613 | __func__); |
| 614 | ret = -ENOMEM; |
| 615 | goto err_ramdump; |
| 616 | } |
| 617 | |
| 618 | drv->smem_ramdump_dev = create_ramdump_device("smem-modem", &pdev->dev); |
| 619 | if (!drv->smem_ramdump_dev) { |
| 620 | pr_err("%s: Unable to create an smem ramdump device.\n", |
| 621 | __func__); |
| 622 | ret = -ENOMEM; |
| 623 | goto err_ramdump_smem; |
| 624 | } |
| 625 | |
| 626 | ret = devm_request_irq(&pdev->dev, irq, modem_wdog_bite_irq, |
| 627 | IRQF_TRIGGER_RISING, "modem_wdog", drv); |
| 628 | if (ret < 0) { |
| 629 | dev_err(&pdev->dev, "Unable to request watchdog IRQ.\n"); |
| 630 | goto err_irq; |
| 631 | } |
| 632 | |
| 633 | ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET, |
| 634 | smsm_state_cb, drv); |
| 635 | if (ret < 0) { |
| 636 | dev_err(&pdev->dev, "Unable to register SMSM callback!\n"); |
| 637 | goto err_irq; |
| 638 | } |
| 639 | |
| 640 | drv->adsp_state_notifier = subsys_notif_register_notifier("adsp", |
| 641 | &adsp_state_notifier_block); |
| 642 | if (IS_ERR(drv->adsp_state_notifier)) { |
| 643 | ret = PTR_ERR(drv->adsp_state_notifier); |
| 644 | dev_err(&pdev->dev, "%s: Registration with the SSR notification driver failed (%d)", |
| 645 | __func__, ret); |
| 646 | goto err_smsm; |
| 647 | } |
| 648 | |
| 649 | return 0; |
| 650 | |
| 651 | err_smsm: |
| 652 | smsm_state_cb_deregister(SMSM_MODEM_STATE, SMSM_RESET, smsm_state_cb, |
| 653 | drv); |
| 654 | err_irq: |
| 655 | destroy_ramdump_device(drv->smem_ramdump_dev); |
| 656 | err_ramdump_smem: |
| 657 | destroy_ramdump_device(drv->ramdump_dev); |
| 658 | err_ramdump: |
| 659 | subsys_unregister(drv->subsys); |
| 660 | err_subsys: |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | static int __devinit pil_mss_loadable_init(struct mba_data *drv, |
| 665 | struct platform_device *pdev) |
| 666 | { |
| 667 | struct q6v5_data *q6; |
| 668 | struct pil_desc *q6_desc, *mba_desc; |
| 669 | struct resource *res; |
| 670 | int ret; |
| 671 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 672 | q6 = pil_q6v5_init(pdev); |
| 673 | if (IS_ERR(q6)) |
| 674 | return PTR_ERR(q6); |
| 675 | drv->q6 = q6; |
| 676 | |
| 677 | q6_desc = &q6->desc; |
| 678 | q6_desc->ops = &pil_mss_ops; |
| 679 | q6_desc->owner = THIS_MODULE; |
| 680 | q6_desc->proxy_timeout = PROXY_TIMEOUT_MS; |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 681 | |
| 682 | of_property_read_u32(pdev->dev.of_node, "qcom,pil-self-auth", |
| 683 | &drv->self_auth); |
| 684 | if (drv->self_auth) { |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 685 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 686 | "rmb_base"); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 687 | drv->rmb_base = devm_request_and_ioremap(&pdev->dev, res); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 688 | if (!drv->rmb_base) |
| 689 | return -ENOMEM; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 690 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 691 | "metadata_base"); |
| 692 | if (res) { |
| 693 | drv->metadata_base = devm_ioremap(&pdev->dev, |
| 694 | res->start, resource_size(res)); |
| 695 | if (!drv->metadata_base) |
| 696 | return -ENOMEM; |
| 697 | drv->metadata_phys = res->start; |
| 698 | } |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 701 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg"); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 702 | q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 703 | if (!q6->restart_reg) |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 704 | return -ENOMEM; |
| 705 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 706 | q6->vreg = devm_regulator_get(&pdev->dev, "vdd_mss"); |
| 707 | if (IS_ERR(q6->vreg)) |
| 708 | return PTR_ERR(q6->vreg); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 709 | |
Matt Wagantall | 70315fb | 2012-12-03 16:33:28 -0800 | [diff] [blame] | 710 | q6->vreg_mx = devm_regulator_get(&pdev->dev, "vdd_mx"); |
| 711 | if (IS_ERR(q6->vreg_mx)) |
| 712 | return PTR_ERR(q6->vreg_mx); |
| 713 | |
| 714 | ret = regulator_set_voltage(q6->vreg, VDD_MSS_UV, VDD_MSS_UV); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 715 | if (ret) |
| 716 | dev_err(&pdev->dev, "Failed to set regulator's voltage.\n"); |
| 717 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 718 | ret = regulator_set_optimum_mode(q6->vreg, 100000); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 719 | if (ret < 0) { |
| 720 | dev_err(&pdev->dev, "Failed to set regulator's mode.\n"); |
| 721 | return ret; |
| 722 | } |
| 723 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 724 | q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk"); |
| 725 | if (IS_ERR(q6->ahb_clk)) |
| 726 | return PTR_ERR(q6->ahb_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 727 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 728 | q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk"); |
| 729 | if (IS_ERR(q6->axi_clk)) |
| 730 | return PTR_ERR(q6->axi_clk); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 731 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 732 | q6->rom_clk = devm_clk_get(&pdev->dev, "mem_clk"); |
| 733 | if (IS_ERR(q6->rom_clk)) |
| 734 | return PTR_ERR(q6->rom_clk); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 735 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 736 | ret = pil_desc_init(q6_desc); |
| 737 | if (ret) |
| 738 | return ret; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 739 | |
| 740 | mba_desc = &drv->desc; |
| 741 | mba_desc->name = "modem"; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 742 | mba_desc->dev = &pdev->dev; |
| 743 | mba_desc->ops = &pil_mba_ops; |
| 744 | mba_desc->owner = THIS_MODULE; |
| 745 | mba_desc->proxy_timeout = PROXY_TIMEOUT_MS; |
| 746 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 747 | ret = pil_desc_init(mba_desc); |
| 748 | if (ret) |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 749 | goto err_mba_desc; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 750 | |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 751 | return 0; |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 752 | |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 753 | err_mba_desc: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 754 | pil_desc_release(q6_desc); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 755 | return ret; |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 756 | |
| 757 | } |
| 758 | |
| 759 | static int __devinit pil_mss_driver_probe(struct platform_device *pdev) |
| 760 | { |
| 761 | struct mba_data *drv; |
| 762 | int ret; |
| 763 | |
| 764 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 765 | if (!drv) |
| 766 | return -ENOMEM; |
| 767 | platform_set_drvdata(pdev, drv); |
| 768 | |
Vikram Mulukutla | 2d4f086 | 2012-11-16 11:57:34 -0800 | [diff] [blame] | 769 | drv->is_loadable = of_property_read_bool(pdev->dev.of_node, |
| 770 | "qcom,is-loadable"); |
Vikram Mulukutla | 7dc2d4e | 2012-11-12 13:04:50 -0800 | [diff] [blame] | 771 | if (drv->is_loadable) { |
| 772 | ret = pil_mss_loadable_init(drv, pdev); |
| 773 | if (ret) |
| 774 | return ret; |
| 775 | } |
| 776 | |
| 777 | return pil_subsys_init(drv, pdev); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static int __devexit pil_mss_driver_exit(struct platform_device *pdev) |
| 781 | { |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 782 | struct mba_data *drv = platform_get_drvdata(pdev); |
Vikram Mulukutla | 896d058 | 2012-10-17 16:57:46 -0700 | [diff] [blame] | 783 | |
| 784 | subsys_notif_unregister_notifier(drv->adsp_state_notifier, |
| 785 | &adsp_state_notifier_block); |
Stephen Boyd | 3da4fd0 | 2012-07-06 10:00:12 -0700 | [diff] [blame] | 786 | smsm_state_cb_deregister(SMSM_MODEM_STATE, SMSM_RESET, |
| 787 | smsm_state_cb, drv); |
| 788 | subsys_unregister(drv->subsys); |
| 789 | destroy_ramdump_device(drv->smem_ramdump_dev); |
| 790 | destroy_ramdump_device(drv->ramdump_dev); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 791 | pil_desc_release(&drv->desc); |
| 792 | pil_desc_release(&drv->q6->desc); |
Matt Wagantall | 4e2599e | 2012-03-21 22:31:35 -0700 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static struct of_device_id mss_match_table[] = { |
| 797 | { .compatible = "qcom,pil-q6v5-mss" }, |
| 798 | {} |
| 799 | }; |
| 800 | |
| 801 | static struct platform_driver pil_mss_driver = { |
| 802 | .probe = pil_mss_driver_probe, |
| 803 | .remove = __devexit_p(pil_mss_driver_exit), |
| 804 | .driver = { |
| 805 | .name = "pil-q6v5-mss", |
| 806 | .of_match_table = mss_match_table, |
| 807 | .owner = THIS_MODULE, |
| 808 | }, |
| 809 | }; |
| 810 | |
| 811 | static int __init pil_mss_init(void) |
| 812 | { |
| 813 | return platform_driver_register(&pil_mss_driver); |
| 814 | } |
| 815 | module_init(pil_mss_init); |
| 816 | |
| 817 | static void __exit pil_mss_exit(void) |
| 818 | { |
| 819 | platform_driver_unregister(&pil_mss_driver); |
| 820 | } |
| 821 | module_exit(pil_mss_exit); |
| 822 | |
| 823 | MODULE_DESCRIPTION("Support for booting modem subsystems with QDSP6v5 Hexagon processors"); |
| 824 | MODULE_LICENSE("GPL v2"); |