Seemanta Dutta | 4e2d49c | 2013-04-05 16:28:11 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/ioport.h> |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 18 | #include <linux/delay.h> |
| 19 | #include <linux/err.h> |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 20 | #include <linux/clk.h> |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 21 | #include <linux/irq.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/reboot.h> |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 24 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 25 | #include <mach/subsystem_restart.h> |
| 26 | #include <mach/msm_smsm.h> |
Seemanta Dutta | 4e2d49c | 2013-04-05 16:28:11 -0700 | [diff] [blame] | 27 | #include <mach/ramdump.h> |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 28 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 29 | #include "modem_notifier.h" |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 30 | #include "peripheral-loader.h" |
| 31 | #include "scm-pas.h" |
| 32 | |
| 33 | #define MARM_BOOT_CONTROL 0x0010 |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 34 | #define MARM_RESET 0x2BD4 |
| 35 | #define MAHB0_SFAB_PORT_RESET 0x2304 |
| 36 | #define MARM_CLK_BRANCH_ENA_VOTE 0x3000 |
| 37 | #define MARM_CLK_SRC0_NS 0x2BC0 |
| 38 | #define MARM_CLK_SRC1_NS 0x2BC4 |
| 39 | #define MARM_CLK_SRC_CTL 0x2BC8 |
| 40 | #define MARM_CLK_CTL 0x2BCC |
| 41 | #define SFAB_MSS_S_HCLK_CTL 0x2C00 |
| 42 | #define MSS_MODEM_CXO_CLK_CTL 0x2C44 |
| 43 | #define MSS_SLP_CLK_CTL 0x2C60 |
| 44 | #define MSS_MARM_SYS_REF_CLK_CTL 0x2C64 |
| 45 | #define MAHB0_CLK_CTL 0x2300 |
| 46 | #define MAHB1_CLK_CTL 0x2BE4 |
| 47 | #define MAHB2_CLK_CTL 0x2C20 |
| 48 | #define MAHB1_NS 0x2BE0 |
| 49 | #define MARM_CLK_FS 0x2BD0 |
| 50 | #define MAHB2_CLK_FS 0x2C24 |
| 51 | #define PLL_ENA_MARM 0x3500 |
| 52 | #define PLL8_STATUS 0x3158 |
| 53 | #define CLK_HALT_MSS_SMPSS_MISC_STATE 0x2FDC |
| 54 | #define MSS_MODEM_RESET 0x2C48 |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 55 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 56 | struct modem_data { |
| 57 | void __iomem *base; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 58 | void __iomem *wdog; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 59 | void __iomem *cbase; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 60 | struct pil_device *pil; |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 61 | struct clk *xo; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 62 | struct notifier_block notifier; |
| 63 | int ignore_smsm_ack; |
| 64 | int irq; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 65 | struct pil_desc pil_desc; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 66 | struct subsys_device *subsys; |
| 67 | struct subsys_desc subsys_desc; |
| 68 | struct delayed_work unlock_work; |
| 69 | struct work_struct fatal_work; |
| 70 | struct ramdump_device *ramdump_dev; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 73 | static int make_modem_proxy_votes(struct pil_desc *pil) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 74 | { |
| 75 | int ret; |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 76 | struct modem_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 77 | |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 78 | ret = clk_prepare_enable(drv->xo); |
| 79 | if (ret) { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 80 | dev_err(pil->dev, "Failed to enable XO\n"); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 81 | return ret; |
| 82 | } |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 86 | static void remove_modem_proxy_votes(struct pil_desc *pil) |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 87 | { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 88 | struct modem_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 89 | clk_disable_unprepare(drv->xo); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 92 | static int modem_reset(struct pil_desc *pil) |
| 93 | { |
| 94 | u32 reg; |
| 95 | const struct modem_data *drv = dev_get_drvdata(pil->dev); |
Tianyi Gou | 819851e | 2013-04-16 16:05:56 -0700 | [diff] [blame] | 96 | phys_addr_t start_addr = pil_get_entry_addr(pil); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 97 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 98 | /* Put modem AHB0,1,2 clocks into reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 99 | writel_relaxed(BIT(0) | BIT(1), drv->cbase + MAHB0_SFAB_PORT_RESET); |
| 100 | writel_relaxed(BIT(7), drv->cbase + MAHB1_CLK_CTL); |
| 101 | writel_relaxed(BIT(7), drv->cbase + MAHB2_CLK_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 102 | |
| 103 | /* Vote for pll8 on behalf of the modem */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 104 | reg = readl_relaxed(drv->cbase + PLL_ENA_MARM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 105 | reg |= BIT(8); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 106 | writel_relaxed(reg, drv->cbase + PLL_ENA_MARM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 107 | |
| 108 | /* Wait for PLL8 to enable */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 109 | while (!(readl_relaxed(drv->cbase + PLL8_STATUS) & BIT(16))) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 110 | cpu_relax(); |
| 111 | |
| 112 | /* Set MAHB1 divider to Div-5 to run MAHB1,2 and sfab at 79.8 Mhz*/ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 113 | writel_relaxed(0x4, drv->cbase + MAHB1_NS); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 114 | |
| 115 | /* Vote for modem AHB1 and 2 clocks to be on on behalf of the modem */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 116 | reg = readl_relaxed(drv->cbase + MARM_CLK_BRANCH_ENA_VOTE); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 117 | reg |= BIT(0) | BIT(1); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 118 | writel_relaxed(reg, drv->cbase + MARM_CLK_BRANCH_ENA_VOTE); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 119 | |
| 120 | /* Source marm_clk off of PLL8 */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 121 | reg = readl_relaxed(drv->cbase + MARM_CLK_SRC_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 122 | if ((reg & 0x1) == 0) { |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 123 | writel_relaxed(0x3, drv->cbase + MARM_CLK_SRC1_NS); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 124 | reg |= 0x1; |
| 125 | } else { |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 126 | writel_relaxed(0x3, drv->cbase + MARM_CLK_SRC0_NS); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 127 | reg &= ~0x1; |
| 128 | } |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 129 | writel_relaxed(reg | 0x2, drv->cbase + MARM_CLK_SRC_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * Force core on and periph on signals to remain active during halt |
| 133 | * for marm_clk and mahb2_clk |
| 134 | */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 135 | writel_relaxed(0x6F, drv->cbase + MARM_CLK_FS); |
| 136 | writel_relaxed(0x6F, drv->cbase + MAHB2_CLK_FS); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * Enable all of the marm_clk branches, cxo sourced marm branches, |
| 140 | * and sleep clock branches |
| 141 | */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 142 | writel_relaxed(0x10, drv->cbase + MARM_CLK_CTL); |
| 143 | writel_relaxed(0x10, drv->cbase + MAHB0_CLK_CTL); |
| 144 | writel_relaxed(0x10, drv->cbase + SFAB_MSS_S_HCLK_CTL); |
| 145 | writel_relaxed(0x10, drv->cbase + MSS_MODEM_CXO_CLK_CTL); |
| 146 | writel_relaxed(0x10, drv->cbase + MSS_SLP_CLK_CTL); |
| 147 | writel_relaxed(0x10, drv->cbase + MSS_MARM_SYS_REF_CLK_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 148 | |
| 149 | /* Wait for above clocks to be turned on */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 150 | while (readl_relaxed(drv->cbase + CLK_HALT_MSS_SMPSS_MISC_STATE) & |
| 151 | (BIT(7) | BIT(8) | BIT(9) | BIT(10) | BIT(4) | BIT(6))) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 152 | cpu_relax(); |
| 153 | |
| 154 | /* Take MAHB0,1,2 clocks out of reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 155 | writel_relaxed(0x0, drv->cbase + MAHB2_CLK_CTL); |
| 156 | writel_relaxed(0x0, drv->cbase + MAHB1_CLK_CTL); |
| 157 | writel_relaxed(0x0, drv->cbase + MAHB0_SFAB_PORT_RESET); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 158 | mb(); |
| 159 | |
| 160 | /* Setup exception vector table base address */ |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 161 | writel_relaxed(start_addr | 0x1, drv->base + MARM_BOOT_CONTROL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 162 | |
| 163 | /* Wait for vector table to be setup */ |
| 164 | mb(); |
| 165 | |
| 166 | /* Bring modem out of reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 167 | writel_relaxed(0x0, drv->cbase + MARM_RESET); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 172 | static int modem_pil_shutdown(struct pil_desc *pil) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 173 | { |
| 174 | u32 reg; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 175 | const struct modem_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 176 | |
| 177 | /* Put modem into reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 178 | writel_relaxed(0x1, drv->cbase + MARM_RESET); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 179 | mb(); |
| 180 | |
| 181 | /* Put modem AHB0,1,2 clocks into reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 182 | writel_relaxed(BIT(0) | BIT(1), drv->cbase + MAHB0_SFAB_PORT_RESET); |
| 183 | writel_relaxed(BIT(7), drv->cbase + MAHB1_CLK_CTL); |
| 184 | writel_relaxed(BIT(7), drv->cbase + MAHB2_CLK_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 185 | mb(); |
| 186 | |
| 187 | /* |
| 188 | * Disable all of the marm_clk branches, cxo sourced marm branches, |
| 189 | * and sleep clock branches |
| 190 | */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 191 | writel_relaxed(0x0, drv->cbase + MARM_CLK_CTL); |
| 192 | writel_relaxed(0x0, drv->cbase + MAHB0_CLK_CTL); |
| 193 | writel_relaxed(0x0, drv->cbase + SFAB_MSS_S_HCLK_CTL); |
| 194 | writel_relaxed(0x0, drv->cbase + MSS_MODEM_CXO_CLK_CTL); |
| 195 | writel_relaxed(0x0, drv->cbase + MSS_SLP_CLK_CTL); |
| 196 | writel_relaxed(0x0, drv->cbase + MSS_MARM_SYS_REF_CLK_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 197 | |
| 198 | /* Disable marm_clk */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 199 | reg = readl_relaxed(drv->cbase + MARM_CLK_SRC_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 200 | reg &= ~0x2; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 201 | writel_relaxed(reg, drv->cbase + MARM_CLK_SRC_CTL); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 202 | |
| 203 | /* Clear modem's votes for ahb clocks */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 204 | writel_relaxed(0x0, drv->cbase + MARM_CLK_BRANCH_ENA_VOTE); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 205 | |
| 206 | /* Clear modem's votes for PLLs */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 207 | writel_relaxed(0x0, drv->cbase + PLL_ENA_MARM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 208 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static struct pil_reset_ops pil_modem_ops = { |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 213 | .auth_and_reset = modem_reset, |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 214 | .shutdown = modem_pil_shutdown, |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 215 | .proxy_vote = make_modem_proxy_votes, |
| 216 | .proxy_unvote = remove_modem_proxy_votes, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | static int modem_init_image_trusted(struct pil_desc *pil, const u8 *metadata, |
| 220 | size_t size) |
| 221 | { |
| 222 | return pas_init_image(PAS_MODEM, metadata, size); |
| 223 | } |
| 224 | |
| 225 | static int modem_reset_trusted(struct pil_desc *pil) |
| 226 | { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 227 | return pas_auth_and_reset(PAS_MODEM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int modem_shutdown_trusted(struct pil_desc *pil) |
| 231 | { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 232 | return pas_shutdown(PAS_MODEM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static struct pil_reset_ops pil_modem_ops_trusted = { |
| 236 | .init_image = modem_init_image_trusted, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 237 | .auth_and_reset = modem_reset_trusted, |
| 238 | .shutdown = modem_shutdown_trusted, |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 239 | .proxy_vote = make_modem_proxy_votes, |
| 240 | .proxy_unvote = remove_modem_proxy_votes, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 241 | }; |
| 242 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 243 | static void modem_crash_shutdown(const struct subsys_desc *subsys) |
| 244 | { |
| 245 | struct modem_data *drv; |
| 246 | |
| 247 | /* If modem hasn't already crashed, send SMSM_RESET. */ |
| 248 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 249 | if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) { |
| 250 | modem_unregister_notifier(&drv->notifier); |
| 251 | smsm_reset_modem(SMSM_RESET); |
| 252 | } |
| 253 | |
| 254 | /* Wait to allow the modem to clean up caches etc. */ |
| 255 | mdelay(5); |
| 256 | } |
| 257 | |
| 258 | static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id) |
| 259 | { |
| 260 | struct modem_data *drv = dev_id; |
| 261 | |
| 262 | schedule_work(&drv->fatal_work); |
| 263 | disable_irq_nosync(drv->irq); |
| 264 | |
| 265 | return IRQ_HANDLED; |
| 266 | } |
| 267 | |
| 268 | static void modem_unlock_timeout(struct work_struct *work) |
| 269 | { |
| 270 | struct modem_data *drv; |
| 271 | struct delayed_work *dwork = to_delayed_work(work); |
| 272 | |
| 273 | pr_crit("Timeout waiting for modem to unlock.\n"); |
| 274 | |
| 275 | drv = container_of(dwork, struct modem_data, unlock_work); |
| 276 | /* The unlock didn't work, clear the reset */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 277 | writel_relaxed(0x0, drv->cbase + MSS_MODEM_RESET); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 278 | mb(); |
| 279 | |
| 280 | subsystem_restart_dev(drv->subsys); |
| 281 | enable_irq(drv->irq); |
| 282 | } |
| 283 | |
| 284 | static void modem_fatal_fn(struct work_struct *work) |
| 285 | { |
| 286 | u32 modem_state; |
| 287 | u32 panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD; |
| 288 | u32 reset_smsm_states = SMSM_SYSTEM_REBOOT_USR | SMSM_SYSTEM_PWRDWN_USR; |
| 289 | struct modem_data *drv; |
| 290 | |
| 291 | drv = container_of(work, struct modem_data, fatal_work); |
| 292 | |
| 293 | pr_err("Watchdog bite received from modem!\n"); |
| 294 | |
| 295 | modem_state = smsm_get_state(SMSM_MODEM_STATE); |
| 296 | pr_err("Modem SMSM state = 0x%x!\n", modem_state); |
| 297 | |
| 298 | if (modem_state == 0 || modem_state & panic_smsm_states) { |
| 299 | subsystem_restart_dev(drv->subsys); |
| 300 | enable_irq(drv->irq); |
| 301 | } else if (modem_state & reset_smsm_states) { |
| 302 | pr_err("User-invoked system reset/powerdown."); |
| 303 | kernel_restart(NULL); |
| 304 | } else { |
| 305 | unsigned long timeout = msecs_to_jiffies(6000); |
| 306 | |
| 307 | pr_err("Modem AHB locked up. Trying to free up modem!\n"); |
| 308 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 309 | writel_relaxed(0x3, drv->cbase + MSS_MODEM_RESET); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 310 | /* |
| 311 | * If we are still alive (allowing for the 5 second |
| 312 | * delayed-panic-reboot), the modem is either still wedged or |
| 313 | * SMSM didn't come through. Force panic in that case. |
| 314 | */ |
| 315 | schedule_delayed_work(&drv->unlock_work, timeout); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | static int modem_notif_handler(struct notifier_block *nb, unsigned long code, |
| 320 | void *p) |
| 321 | { |
| 322 | struct modem_data *drv = container_of(nb, struct modem_data, notifier); |
| 323 | |
| 324 | if (code == MODEM_NOTIFIER_START_RESET) { |
| 325 | if (drv->ignore_smsm_ack) { |
| 326 | drv->ignore_smsm_ack = 0; |
| 327 | } else { |
| 328 | pr_err("Modem error fatal'ed."); |
| 329 | subsystem_restart_dev(drv->subsys); |
| 330 | } |
| 331 | } |
| 332 | return NOTIFY_DONE; |
| 333 | } |
| 334 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 335 | static int modem_start(const struct subsys_desc *subsys) |
| 336 | { |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 337 | struct modem_data *drv; |
| 338 | |
| 339 | drv = container_of(subsys, struct modem_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 340 | return pil_boot(&drv->pil_desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static void modem_stop(const struct subsys_desc *subsys) |
| 344 | { |
| 345 | struct modem_data *drv; |
| 346 | |
| 347 | drv = container_of(subsys, struct modem_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 348 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 351 | static int modem_shutdown(const struct subsys_desc *subsys) |
| 352 | { |
| 353 | struct modem_data *drv; |
| 354 | |
| 355 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 356 | /* |
| 357 | * If the modem didn't already crash, setting SMSM_RESET here will help |
| 358 | * flush caches etc. The ignore_smsm_ack flag is set to ignore the |
| 359 | * SMSM_RESET notification that is generated due to the modem settings |
| 360 | * its own SMSM_RESET bit in response to the apps setting the apps |
| 361 | * SMSM_RESET bit. |
| 362 | */ |
| 363 | if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) { |
| 364 | drv->ignore_smsm_ack = 1; |
| 365 | smsm_reset_modem(SMSM_RESET); |
| 366 | } |
| 367 | |
| 368 | /* Disable the modem watchdog to allow clean modem bootup */ |
| 369 | writel_relaxed(0x0, drv->wdog + 0x8); |
| 370 | /* |
| 371 | * The write above needs to go through before the modem is powered up |
| 372 | * again. |
| 373 | */ |
| 374 | mb(); |
| 375 | /* Wait here to allow the modem to clean up caches, etc. */ |
| 376 | msleep(20); |
| 377 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 378 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 379 | disable_irq_nosync(drv->irq); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static int modem_powerup(const struct subsys_desc *subsys) |
| 385 | { |
| 386 | struct modem_data *drv; |
| 387 | int ret; |
| 388 | |
| 389 | drv = container_of(subsys, struct modem_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 390 | ret = pil_boot(&drv->pil_desc); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 391 | enable_irq(drv->irq); |
| 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 396 | static int modem_ramdump(int enable, const struct subsys_desc *subsys) |
| 397 | { |
| 398 | struct modem_data *drv; |
| 399 | |
| 400 | drv = container_of(subsys, struct modem_data, subsys_desc); |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 401 | if (!enable) |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 402 | return 0; |
Stephen Boyd | 5eb17ce | 2012-11-29 15:34:21 -0800 | [diff] [blame] | 403 | |
| 404 | return pil_do_ramdump(&drv->pil_desc, drv->ramdump_dev); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 407 | static int __devinit pil_modem_driver_probe(struct platform_device *pdev) |
| 408 | { |
| 409 | struct modem_data *drv; |
| 410 | struct resource *res; |
| 411 | struct pil_desc *desc; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 412 | int ret; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 413 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 414 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 415 | if (!drv) |
| 416 | return -ENOMEM; |
| 417 | platform_set_drvdata(pdev, drv); |
| 418 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 419 | drv->irq = platform_get_irq(pdev, 0); |
| 420 | if (drv->irq < 0) |
| 421 | return drv->irq; |
| 422 | |
Stephen Boyd | b089569 | 2012-03-23 15:23:10 -0700 | [diff] [blame] | 423 | drv->xo = devm_clk_get(&pdev->dev, "xo"); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 424 | if (IS_ERR(drv->xo)) |
| 425 | return PTR_ERR(drv->xo); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 426 | |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 427 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 428 | drv->base = devm_request_and_ioremap(&pdev->dev, res); |
| 429 | if (!drv->base) |
| 430 | return -ENOMEM; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 431 | |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 432 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 433 | drv->wdog = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 434 | if (!drv->wdog) |
| 435 | return -ENOMEM; |
| 436 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 437 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
| 438 | if (!res) |
| 439 | return -EINVAL; |
| 440 | |
| 441 | drv->cbase = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 442 | if (!drv->cbase) |
| 443 | return -ENOMEM; |
| 444 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 445 | desc = &drv->pil_desc; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 446 | desc->name = "modem"; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 447 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 448 | desc->owner = THIS_MODULE; |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 449 | desc->proxy_timeout = 10000; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 450 | |
| 451 | if (pas_supported(PAS_MODEM) > 0) { |
| 452 | desc->ops = &pil_modem_ops_trusted; |
| 453 | dev_info(&pdev->dev, "using secure boot\n"); |
| 454 | } else { |
| 455 | desc->ops = &pil_modem_ops; |
| 456 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 457 | } |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 458 | ret = pil_desc_init(desc); |
| 459 | if (ret) |
| 460 | return ret; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 461 | |
| 462 | drv->notifier.notifier_call = modem_notif_handler, |
| 463 | ret = modem_register_notifier(&drv->notifier); |
| 464 | if (ret) |
| 465 | goto err_notify; |
| 466 | |
| 467 | drv->subsys_desc.name = "modem"; |
Stephen Boyd | 77db8bb | 2012-06-27 15:15:16 -0700 | [diff] [blame] | 468 | drv->subsys_desc.depends_on = "adsp"; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 469 | drv->subsys_desc.dev = &pdev->dev; |
| 470 | drv->subsys_desc.owner = THIS_MODULE; |
| 471 | drv->subsys_desc.start = modem_start; |
| 472 | drv->subsys_desc.stop = modem_stop; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 473 | drv->subsys_desc.shutdown = modem_shutdown; |
| 474 | drv->subsys_desc.powerup = modem_powerup; |
| 475 | drv->subsys_desc.ramdump = modem_ramdump; |
| 476 | drv->subsys_desc.crash_shutdown = modem_crash_shutdown; |
| 477 | |
| 478 | INIT_WORK(&drv->fatal_work, modem_fatal_fn); |
| 479 | INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout); |
| 480 | |
| 481 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 482 | if (IS_ERR(drv->subsys)) { |
| 483 | ret = PTR_ERR(drv->subsys); |
| 484 | goto err_subsys; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 485 | } |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 486 | |
Stephen Boyd | c1a7261 | 2012-07-05 14:07:35 -0700 | [diff] [blame] | 487 | drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 488 | if (!drv->ramdump_dev) { |
| 489 | ret = -ENOMEM; |
| 490 | goto err_ramdump; |
| 491 | } |
| 492 | |
| 493 | ret = devm_request_irq(&pdev->dev, drv->irq, modem_wdog_bite_irq, |
| 494 | IRQF_TRIGGER_RISING, "modem_watchdog", drv); |
| 495 | if (ret) |
| 496 | goto err_irq; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 497 | return 0; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 498 | |
| 499 | err_irq: |
| 500 | destroy_ramdump_device(drv->ramdump_dev); |
| 501 | err_ramdump: |
| 502 | subsys_unregister(drv->subsys); |
| 503 | err_subsys: |
| 504 | modem_unregister_notifier(&drv->notifier); |
| 505 | err_notify: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 506 | pil_desc_release(desc); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 507 | return ret; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | static int __devexit pil_modem_driver_exit(struct platform_device *pdev) |
| 511 | { |
| 512 | struct modem_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 513 | |
| 514 | destroy_ramdump_device(drv->ramdump_dev); |
| 515 | subsys_unregister(drv->subsys); |
| 516 | modem_unregister_notifier(&drv->notifier); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 517 | pil_desc_release(&drv->pil_desc); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 518 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static struct platform_driver pil_modem_driver = { |
| 523 | .probe = pil_modem_driver_probe, |
| 524 | .remove = __devexit_p(pil_modem_driver_exit), |
| 525 | .driver = { |
| 526 | .name = "pil_modem", |
| 527 | .owner = THIS_MODULE, |
| 528 | }, |
| 529 | }; |
| 530 | |
| 531 | static int __init pil_modem_init(void) |
| 532 | { |
| 533 | return platform_driver_register(&pil_modem_driver); |
| 534 | } |
| 535 | module_init(pil_modem_init); |
| 536 | |
| 537 | static void __exit pil_modem_exit(void) |
| 538 | { |
| 539 | platform_driver_unregister(&pil_modem_driver); |
| 540 | } |
| 541 | module_exit(pil_modem_exit); |
| 542 | |
| 543 | MODULE_DESCRIPTION("Support for booting modem processors"); |
| 544 | MODULE_LICENSE("GPL v2"); |