Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -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/kernel.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/io.h> |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/platform_device.h> |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 20 | #include <linux/regulator/consumer.h> |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 21 | #include <linux/clk.h> |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/wcnss_wlan.h> |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 24 | |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 25 | #include <mach/subsystem_restart.h> |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 26 | |
| 27 | #include "peripheral-loader.h" |
| 28 | #include "scm-pas.h" |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 29 | #include "ramdump.h" |
| 30 | #include "smd_private.h" |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 31 | |
| 32 | #define RIVA_PMU_A2XB_CFG 0xB8 |
| 33 | #define RIVA_PMU_A2XB_CFG_EN BIT(0) |
| 34 | |
| 35 | #define RIVA_PMU_CFG 0x28 |
| 36 | #define RIVA_PMU_CFG_WARM_BOOT BIT(0) |
| 37 | #define RIVA_PMU_CFG_IRIS_XO_MODE 0x6 |
| 38 | #define RIVA_PMU_CFG_IRIS_XO_MODE_48 (3 << 1) |
| 39 | |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 40 | #define RIVA_PMU_OVRD_EN 0x2C |
| 41 | #define RIVA_PMU_OVRD_EN_CCPU_RESET BIT(0) |
| 42 | #define RIVA_PMU_OVRD_EN_CCPU_CLK BIT(1) |
| 43 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 44 | #define RIVA_PMU_OVRD_VAL 0x30 |
| 45 | #define RIVA_PMU_OVRD_VAL_CCPU_RESET BIT(0) |
| 46 | #define RIVA_PMU_OVRD_VAL_CCPU_CLK BIT(1) |
| 47 | |
| 48 | #define RIVA_PMU_CCPU_CTL 0x9C |
| 49 | #define RIVA_PMU_CCPU_CTL_HIGH_IVT BIT(0) |
| 50 | #define RIVA_PMU_CCPU_CTL_REMAP_EN BIT(2) |
| 51 | |
| 52 | #define RIVA_PMU_CCPU_BOOT_REMAP_ADDR 0xA0 |
| 53 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 54 | #define RIVA_PLL_MODE 0x31A0 |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 55 | #define PLL_MODE_OUTCTRL BIT(0) |
| 56 | #define PLL_MODE_BYPASSNL BIT(1) |
| 57 | #define PLL_MODE_RESET_N BIT(2) |
| 58 | #define PLL_MODE_REF_XO_SEL 0x30 |
| 59 | #define PLL_MODE_REF_XO_SEL_CXO (2 << 4) |
| 60 | #define PLL_MODE_REF_XO_SEL_RF (3 << 4) |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 61 | #define RIVA_PLL_L_VAL 0x31A4 |
| 62 | #define RIVA_PLL_M_VAL 0x31A8 |
| 63 | #define RIVA_PLL_N_VAL 0x31Ac |
| 64 | #define RIVA_PLL_CONFIG 0x31B4 |
| 65 | #define RIVA_RESET 0x35E0 |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 66 | |
| 67 | #define RIVA_PMU_ROOT_CLK_SEL 0xC8 |
| 68 | #define RIVA_PMU_ROOT_CLK_SEL_3 BIT(2) |
| 69 | |
| 70 | #define RIVA_PMU_CLK_ROOT3 0x78 |
| 71 | #define RIVA_PMU_CLK_ROOT3_ENA BIT(0) |
| 72 | #define RIVA_PMU_CLK_ROOT3_SRC0_DIV 0x3C |
| 73 | #define RIVA_PMU_CLK_ROOT3_SRC0_DIV_2 (1 << 2) |
| 74 | #define RIVA_PMU_CLK_ROOT3_SRC0_SEL 0x1C0 |
| 75 | #define RIVA_PMU_CLK_ROOT3_SRC0_SEL_RIVA (1 << 6) |
| 76 | #define RIVA_PMU_CLK_ROOT3_SRC1_DIV 0x1E00 |
| 77 | #define RIVA_PMU_CLK_ROOT3_SRC1_DIV_2 (1 << 9) |
| 78 | #define RIVA_PMU_CLK_ROOT3_SRC1_SEL 0xE000 |
| 79 | #define RIVA_PMU_CLK_ROOT3_SRC1_SEL_RIVA (1 << 13) |
| 80 | |
| 81 | struct riva_data { |
| 82 | void __iomem *base; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 83 | void __iomem *cbase; |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 84 | struct clk *xo; |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 85 | struct regulator *pll_supply; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 86 | struct pil_desc pil_desc; |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 87 | int irq; |
| 88 | int crash; |
| 89 | int rst_in_progress; |
| 90 | struct subsys_device *subsys; |
| 91 | struct subsys_desc subsys_desc; |
| 92 | struct delayed_work cancel_work; |
| 93 | struct ramdump_device *ramdump_dev; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 96 | static bool cxo_is_needed(struct riva_data *drv) |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 97 | { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 98 | u32 reg = readl_relaxed(drv->base + RIVA_PMU_CFG); |
| 99 | return (reg & RIVA_PMU_CFG_IRIS_XO_MODE) |
| 100 | != RIVA_PMU_CFG_IRIS_XO_MODE_48; |
| 101 | } |
| 102 | |
| 103 | static int pil_riva_make_proxy_vote(struct pil_desc *pil) |
| 104 | { |
| 105 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 106 | int ret; |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 107 | |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 108 | ret = regulator_enable(drv->pll_supply); |
| 109 | if (ret) { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 110 | dev_err(pil->dev, "failed to enable pll supply\n"); |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 111 | goto err; |
| 112 | } |
Stephen Boyd | a74acd6 | 2012-04-03 17:41:33 -0700 | [diff] [blame] | 113 | ret = clk_prepare_enable(drv->xo); |
| 114 | if (ret) { |
| 115 | dev_err(pil->dev, "failed to enable xo\n"); |
| 116 | goto err_clk; |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 117 | } |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 118 | return 0; |
| 119 | err_clk: |
| 120 | regulator_disable(drv->pll_supply); |
| 121 | err: |
| 122 | return ret; |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 125 | static void pil_riva_remove_proxy_vote(struct pil_desc *pil) |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 126 | { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 127 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 128 | regulator_disable(drv->pll_supply); |
Stephen Boyd | a74acd6 | 2012-04-03 17:41:33 -0700 | [diff] [blame] | 129 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 132 | static int pil_riva_reset(struct pil_desc *pil) |
| 133 | { |
| 134 | u32 reg, sel; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 135 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
| 136 | void __iomem *base = drv->base; |
Stephen Boyd | 3030c25 | 2012-08-08 17:24:05 -0700 | [diff] [blame] | 137 | unsigned long start_addr = pil_get_entry_addr(pil); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 138 | void __iomem *cbase = drv->cbase; |
Stephen Boyd | a74acd6 | 2012-04-03 17:41:33 -0700 | [diff] [blame] | 139 | bool use_cxo = cxo_is_needed(drv); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 140 | |
| 141 | /* Enable A2XB bridge */ |
| 142 | reg = readl_relaxed(base + RIVA_PMU_A2XB_CFG); |
| 143 | reg |= RIVA_PMU_A2XB_CFG_EN; |
| 144 | writel_relaxed(reg, base + RIVA_PMU_A2XB_CFG); |
| 145 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 146 | /* Program PLL 13 to 960 MHz */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 147 | reg = readl_relaxed(cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 148 | reg &= ~(PLL_MODE_BYPASSNL | PLL_MODE_OUTCTRL | PLL_MODE_RESET_N); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 149 | writel_relaxed(reg, cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 150 | |
Stephen Boyd | a74acd6 | 2012-04-03 17:41:33 -0700 | [diff] [blame] | 151 | if (use_cxo) |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 152 | writel_relaxed(0x40000C00 | 50, cbase + RIVA_PLL_L_VAL); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 153 | else |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 154 | writel_relaxed(0x40000C00 | 40, cbase + RIVA_PLL_L_VAL); |
| 155 | writel_relaxed(0, cbase + RIVA_PLL_M_VAL); |
| 156 | writel_relaxed(1, cbase + RIVA_PLL_N_VAL); |
| 157 | writel_relaxed(0x01495227, cbase + RIVA_PLL_CONFIG); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 158 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 159 | reg = readl_relaxed(cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 160 | reg &= ~(PLL_MODE_REF_XO_SEL); |
Stephen Boyd | a74acd6 | 2012-04-03 17:41:33 -0700 | [diff] [blame] | 161 | reg |= use_cxo ? PLL_MODE_REF_XO_SEL_CXO : PLL_MODE_REF_XO_SEL_RF; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 162 | writel_relaxed(reg, cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 163 | |
| 164 | /* Enable PLL 13 */ |
| 165 | reg |= PLL_MODE_BYPASSNL; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 166 | writel_relaxed(reg, cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * H/W requires a 5us delay between disabling the bypass and |
| 170 | * de-asserting the reset. Delay 10us just to be safe. |
| 171 | */ |
| 172 | mb(); |
| 173 | usleep_range(10, 20); |
| 174 | |
| 175 | reg |= PLL_MODE_RESET_N; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 176 | writel_relaxed(reg, cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 177 | reg |= PLL_MODE_OUTCTRL; |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 178 | writel_relaxed(reg, cbase + RIVA_PLL_MODE); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 179 | |
| 180 | /* Wait for PLL to settle */ |
| 181 | mb(); |
| 182 | usleep_range(50, 100); |
| 183 | |
| 184 | /* Configure cCPU for 240 MHz */ |
| 185 | sel = readl_relaxed(base + RIVA_PMU_ROOT_CLK_SEL); |
| 186 | reg = readl_relaxed(base + RIVA_PMU_CLK_ROOT3); |
| 187 | if (sel & RIVA_PMU_ROOT_CLK_SEL_3) { |
| 188 | reg &= ~(RIVA_PMU_CLK_ROOT3_SRC0_SEL | |
| 189 | RIVA_PMU_CLK_ROOT3_SRC0_DIV); |
| 190 | reg |= RIVA_PMU_CLK_ROOT3_SRC0_SEL_RIVA | |
| 191 | RIVA_PMU_CLK_ROOT3_SRC0_DIV_2; |
| 192 | } else { |
| 193 | reg &= ~(RIVA_PMU_CLK_ROOT3_SRC1_SEL | |
| 194 | RIVA_PMU_CLK_ROOT3_SRC1_DIV); |
| 195 | reg |= RIVA_PMU_CLK_ROOT3_SRC1_SEL_RIVA | |
| 196 | RIVA_PMU_CLK_ROOT3_SRC1_DIV_2; |
| 197 | } |
| 198 | writel_relaxed(reg, base + RIVA_PMU_CLK_ROOT3); |
| 199 | reg |= RIVA_PMU_CLK_ROOT3_ENA; |
| 200 | writel_relaxed(reg, base + RIVA_PMU_CLK_ROOT3); |
| 201 | reg = readl_relaxed(base + RIVA_PMU_ROOT_CLK_SEL); |
| 202 | reg ^= RIVA_PMU_ROOT_CLK_SEL_3; |
| 203 | writel_relaxed(reg, base + RIVA_PMU_ROOT_CLK_SEL); |
| 204 | |
| 205 | /* Use the high vector table */ |
| 206 | reg = readl_relaxed(base + RIVA_PMU_CCPU_CTL); |
| 207 | reg |= RIVA_PMU_CCPU_CTL_HIGH_IVT | RIVA_PMU_CCPU_CTL_REMAP_EN; |
| 208 | writel_relaxed(reg, base + RIVA_PMU_CCPU_CTL); |
| 209 | |
| 210 | /* Set base memory address */ |
| 211 | writel_relaxed(start_addr >> 16, base + RIVA_PMU_CCPU_BOOT_REMAP_ADDR); |
| 212 | |
| 213 | /* Clear warmboot bit indicating this is a cold boot */ |
| 214 | reg = readl_relaxed(base + RIVA_PMU_CFG); |
| 215 | reg &= ~(RIVA_PMU_CFG_WARM_BOOT); |
| 216 | writel_relaxed(reg, base + RIVA_PMU_CFG); |
| 217 | |
| 218 | /* Enable the cCPU clock */ |
| 219 | reg = readl_relaxed(base + RIVA_PMU_OVRD_VAL); |
| 220 | reg |= RIVA_PMU_OVRD_VAL_CCPU_CLK; |
| 221 | writel_relaxed(reg, base + RIVA_PMU_OVRD_VAL); |
| 222 | |
| 223 | /* Take cCPU out of reset */ |
| 224 | reg |= RIVA_PMU_OVRD_VAL_CCPU_RESET; |
| 225 | writel_relaxed(reg, base + RIVA_PMU_OVRD_VAL); |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static int pil_riva_shutdown(struct pil_desc *pil) |
| 231 | { |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 232 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
| 233 | void __iomem *cbase = drv->cbase; |
| 234 | |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 235 | /* Assert reset to Riva */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 236 | writel_relaxed(1, cbase + RIVA_RESET); |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 237 | mb(); |
| 238 | usleep_range(1000, 2000); |
| 239 | |
| 240 | /* Deassert reset to Riva */ |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 241 | writel_relaxed(0, cbase + RIVA_RESET); |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 242 | mb(); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static struct pil_reset_ops pil_riva_ops = { |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 248 | .auth_and_reset = pil_riva_reset, |
| 249 | .shutdown = pil_riva_shutdown, |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 250 | .proxy_vote = pil_riva_make_proxy_vote, |
| 251 | .proxy_unvote = pil_riva_remove_proxy_vote, |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | static int pil_riva_init_image_trusted(struct pil_desc *pil, |
| 255 | const u8 *metadata, size_t size) |
| 256 | { |
Tianyi Gou | ca0aaac | 2012-07-27 14:13:29 -0700 | [diff] [blame] | 257 | return pas_init_image(PAS_WCNSS, metadata, size); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static int pil_riva_reset_trusted(struct pil_desc *pil) |
| 261 | { |
Tianyi Gou | ca0aaac | 2012-07-27 14:13:29 -0700 | [diff] [blame] | 262 | return pas_auth_and_reset(PAS_WCNSS); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static int pil_riva_shutdown_trusted(struct pil_desc *pil) |
| 266 | { |
Tianyi Gou | ca0aaac | 2012-07-27 14:13:29 -0700 | [diff] [blame] | 267 | return pas_shutdown(PAS_WCNSS); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static struct pil_reset_ops pil_riva_ops_trusted = { |
| 271 | .init_image = pil_riva_init_image_trusted, |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 272 | .auth_and_reset = pil_riva_reset_trusted, |
| 273 | .shutdown = pil_riva_shutdown_trusted, |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 274 | .proxy_vote = pil_riva_make_proxy_vote, |
| 275 | .proxy_unvote = pil_riva_remove_proxy_vote, |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 278 | static int enable_riva_ssr; |
| 279 | |
| 280 | static int enable_riva_ssr_set(const char *val, struct kernel_param *kp) |
| 281 | { |
| 282 | int ret; |
| 283 | |
| 284 | ret = param_set_int(val, kp); |
| 285 | if (ret) |
| 286 | return ret; |
| 287 | |
| 288 | if (enable_riva_ssr) |
| 289 | pr_info("Subsystem restart activated for riva.\n"); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | module_param_call(enable_riva_ssr, enable_riva_ssr_set, param_get_int, |
| 294 | &enable_riva_ssr, S_IRUGO | S_IWUSR); |
| 295 | |
| 296 | static void smsm_state_cb_hdlr(void *data, uint32_t old_state, |
| 297 | uint32_t new_state) |
| 298 | { |
| 299 | struct riva_data *drv = data; |
| 300 | char *smem_reset_reason; |
| 301 | char buffer[81]; |
| 302 | unsigned smem_reset_size; |
| 303 | unsigned size; |
| 304 | |
| 305 | drv->crash = true; |
| 306 | if (!(new_state & SMSM_RESET)) |
| 307 | return; |
| 308 | |
| 309 | if (drv->rst_in_progress) { |
| 310 | pr_err("riva: Ignoring smsm reset req, restart in progress\n"); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | pr_err("riva: smsm state changed to smsm reset\n"); |
| 315 | |
| 316 | smem_reset_reason = smem_get_entry(SMEM_SSR_REASON_WCNSS0, |
| 317 | &smem_reset_size); |
| 318 | |
| 319 | if (!smem_reset_reason || !smem_reset_size) { |
| 320 | pr_err("wcnss subsystem failure reason:\n" |
| 321 | "(unknown, smem_get_entry failed)"); |
| 322 | } else if (!smem_reset_reason[0]) { |
| 323 | pr_err("wcnss subsystem failure reason:\n" |
| 324 | "(unknown, init string found)"); |
| 325 | } else { |
| 326 | size = smem_reset_size < sizeof(buffer) ? smem_reset_size : |
| 327 | (sizeof(buffer) - 1); |
| 328 | memcpy(buffer, smem_reset_reason, size); |
| 329 | buffer[size] = '\0'; |
| 330 | pr_err("wcnss subsystem failure reason: %s\n", buffer); |
| 331 | memset(smem_reset_reason, 0, smem_reset_size); |
| 332 | wmb(); |
| 333 | } |
| 334 | |
| 335 | drv->rst_in_progress = 1; |
| 336 | subsystem_restart_dev(drv->subsys); |
| 337 | } |
| 338 | |
| 339 | static irqreturn_t riva_wdog_bite_irq_hdlr(int irq, void *dev_id) |
| 340 | { |
| 341 | struct riva_data *drv = dev_id; |
| 342 | |
| 343 | drv->crash = true; |
| 344 | if (drv->rst_in_progress) { |
| 345 | pr_err("Ignoring riva bite irq, restart in progress\n"); |
| 346 | return IRQ_HANDLED; |
| 347 | } |
| 348 | if (!enable_riva_ssr) |
| 349 | panic("Watchdog bite received from Riva"); |
| 350 | |
| 351 | drv->rst_in_progress = 1; |
| 352 | subsystem_restart_dev(drv->subsys); |
| 353 | |
| 354 | return IRQ_HANDLED; |
| 355 | } |
| 356 | |
| 357 | static void riva_post_bootup(struct work_struct *work) |
| 358 | { |
| 359 | struct platform_device *pdev = wcnss_get_platform_device(); |
| 360 | struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config(); |
| 361 | |
| 362 | wcnss_wlan_power(&pdev->dev, pwlanconfig, WCNSS_WLAN_SWITCH_OFF); |
| 363 | } |
| 364 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 365 | static int riva_start(const struct subsys_desc *desc) |
| 366 | { |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 367 | struct riva_data *drv; |
| 368 | |
| 369 | drv = container_of(desc, struct riva_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 370 | return pil_boot(&drv->pil_desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void riva_stop(const struct subsys_desc *desc) |
| 374 | { |
| 375 | struct riva_data *drv; |
| 376 | |
| 377 | drv = container_of(desc, struct riva_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 378 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 381 | static int riva_shutdown(const struct subsys_desc *desc) |
| 382 | { |
| 383 | struct riva_data *drv; |
| 384 | |
| 385 | drv = container_of(desc, struct riva_data, subsys_desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 386 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 387 | flush_delayed_work(&drv->cancel_work); |
| 388 | wcnss_flush_delayed_boot_votes(); |
| 389 | disable_irq_nosync(drv->irq); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static int riva_powerup(const struct subsys_desc *desc) |
| 395 | { |
| 396 | struct riva_data *drv; |
| 397 | struct platform_device *pdev = wcnss_get_platform_device(); |
| 398 | struct wcnss_wlan_config *pwlanconfig = wcnss_get_wlan_config(); |
| 399 | int ret = 0; |
| 400 | |
| 401 | drv = container_of(desc, struct riva_data, subsys_desc); |
| 402 | if (pdev && pwlanconfig) { |
| 403 | ret = wcnss_wlan_power(&pdev->dev, pwlanconfig, |
| 404 | WCNSS_WLAN_SWITCH_ON); |
| 405 | if (!ret) |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 406 | pil_boot(&drv->pil_desc); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 407 | } |
| 408 | drv->rst_in_progress = 0; |
| 409 | enable_irq(drv->irq); |
| 410 | schedule_delayed_work(&drv->cancel_work, msecs_to_jiffies(5000)); |
| 411 | |
| 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * 7MB RAM segments for Riva SS; |
| 417 | * Riva 1.1 0x8f000000 - 0x8f700000 |
| 418 | * Riva 1.0 0x8f200000 - 0x8f700000 |
| 419 | */ |
| 420 | static struct ramdump_segment riva_segments[] = { |
| 421 | {0x8f000000, 0x8f700000 - 0x8f000000} |
| 422 | }; |
| 423 | |
| 424 | static int riva_ramdump(int enable, const struct subsys_desc *desc) |
| 425 | { |
| 426 | struct riva_data *drv; |
| 427 | |
| 428 | drv = container_of(desc, struct riva_data, subsys_desc); |
| 429 | |
| 430 | if (enable) |
| 431 | return do_ramdump(drv->ramdump_dev, riva_segments, |
| 432 | ARRAY_SIZE(riva_segments)); |
| 433 | else |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | /* Riva crash handler */ |
| 438 | static void riva_crash_shutdown(const struct subsys_desc *desc) |
| 439 | { |
| 440 | struct riva_data *drv; |
| 441 | |
| 442 | drv = container_of(desc, struct riva_data, subsys_desc); |
| 443 | pr_err("riva crash shutdown %d\n", drv->crash); |
| 444 | if (drv->crash != true) |
| 445 | smsm_change_state(SMSM_APPS_STATE, SMSM_RESET, SMSM_RESET); |
| 446 | } |
| 447 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 448 | static int __devinit pil_riva_probe(struct platform_device *pdev) |
| 449 | { |
| 450 | struct riva_data *drv; |
| 451 | struct resource *res; |
| 452 | struct pil_desc *desc; |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 453 | int ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 454 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 455 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 456 | if (!drv) |
| 457 | return -ENOMEM; |
| 458 | platform_set_drvdata(pdev, drv); |
| 459 | |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame^] | 460 | |
| 461 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 462 | drv->base = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 463 | if (!drv->base) |
| 464 | return -ENOMEM; |
| 465 | |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 466 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame^] | 467 | drv->cbase = devm_request_and_ioremap(&pdev->dev, res); |
Stephen Boyd | e24edf5 | 2012-07-12 17:46:19 -0700 | [diff] [blame] | 468 | if (!drv->cbase) |
| 469 | return -ENOMEM; |
| 470 | |
Stephen Boyd | 83e5eae | 2012-03-23 15:04:46 -0700 | [diff] [blame] | 471 | drv->pll_supply = devm_regulator_get(&pdev->dev, "pll_vdd"); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 472 | if (IS_ERR(drv->pll_supply)) { |
| 473 | dev_err(&pdev->dev, "failed to get pll supply\n"); |
| 474 | return PTR_ERR(drv->pll_supply); |
| 475 | } |
Matt Wagantall | 52dd062 | 2012-02-02 18:26:16 -0800 | [diff] [blame] | 476 | if (regulator_count_voltages(drv->pll_supply) > 0) { |
| 477 | ret = regulator_set_voltage(drv->pll_supply, 1800000, 1800000); |
| 478 | if (ret) { |
| 479 | dev_err(&pdev->dev, |
| 480 | "failed to set pll supply voltage\n"); |
Stephen Boyd | 93528ea | 2012-03-23 15:23:10 -0700 | [diff] [blame] | 481 | return ret; |
Matt Wagantall | 52dd062 | 2012-02-02 18:26:16 -0800 | [diff] [blame] | 482 | } |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 483 | |
Matt Wagantall | 52dd062 | 2012-02-02 18:26:16 -0800 | [diff] [blame] | 484 | ret = regulator_set_optimum_mode(drv->pll_supply, 100000); |
| 485 | if (ret < 0) { |
| 486 | dev_err(&pdev->dev, |
| 487 | "failed to set pll supply optimum mode\n"); |
Stephen Boyd | 93528ea | 2012-03-23 15:23:10 -0700 | [diff] [blame] | 488 | return ret; |
Matt Wagantall | 52dd062 | 2012-02-02 18:26:16 -0800 | [diff] [blame] | 489 | } |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 492 | drv->irq = platform_get_irq(pdev, 0); |
| 493 | if (drv->irq < 0) |
| 494 | return drv->irq; |
| 495 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 496 | drv->xo = devm_clk_get(&pdev->dev, "cxo"); |
| 497 | if (IS_ERR(drv->xo)) |
| 498 | return PTR_ERR(drv->xo); |
| 499 | |
| 500 | desc = &drv->pil_desc; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 501 | desc->name = "wcnss"; |
| 502 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 503 | desc->owner = THIS_MODULE; |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 504 | desc->proxy_timeout = 10000; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 505 | |
Tianyi Gou | ca0aaac | 2012-07-27 14:13:29 -0700 | [diff] [blame] | 506 | if (pas_supported(PAS_WCNSS) > 0) { |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 507 | desc->ops = &pil_riva_ops_trusted; |
| 508 | dev_info(&pdev->dev, "using secure boot\n"); |
| 509 | } else { |
| 510 | desc->ops = &pil_riva_ops; |
| 511 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 512 | } |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 513 | ret = pil_desc_init(desc); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 514 | |
| 515 | ret = smsm_state_cb_register(SMSM_WCNSS_STATE, SMSM_RESET, |
| 516 | smsm_state_cb_hdlr, drv); |
| 517 | if (ret < 0) |
| 518 | goto err_smsm; |
| 519 | |
| 520 | drv->subsys_desc.name = "wcnss"; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame] | 521 | drv->subsys_desc.dev = &pdev->dev; |
| 522 | drv->subsys_desc.owner = THIS_MODULE; |
| 523 | drv->subsys_desc.start = riva_start; |
| 524 | drv->subsys_desc.stop = riva_stop; |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 525 | drv->subsys_desc.shutdown = riva_shutdown; |
| 526 | drv->subsys_desc.powerup = riva_powerup; |
| 527 | drv->subsys_desc.ramdump = riva_ramdump; |
| 528 | drv->subsys_desc.crash_shutdown = riva_crash_shutdown; |
| 529 | |
| 530 | INIT_DELAYED_WORK(&drv->cancel_work, riva_post_bootup); |
| 531 | |
Stephen Boyd | c1a7261 | 2012-07-05 14:07:35 -0700 | [diff] [blame] | 532 | drv->ramdump_dev = create_ramdump_device("riva", &pdev->dev); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 533 | if (!drv->ramdump_dev) { |
| 534 | ret = -ENOMEM; |
| 535 | goto err_ramdump; |
| 536 | } |
| 537 | |
| 538 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 539 | if (IS_ERR(drv->subsys)) { |
| 540 | ret = PTR_ERR(drv->subsys); |
| 541 | goto err_subsys; |
| 542 | } |
| 543 | |
| 544 | ret = devm_request_irq(&pdev->dev, drv->irq, riva_wdog_bite_irq_hdlr, |
| 545 | IRQF_TRIGGER_HIGH, "riva_wdog", drv); |
| 546 | if (ret < 0) |
| 547 | goto err; |
| 548 | |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 549 | return 0; |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 550 | err: |
| 551 | subsys_unregister(drv->subsys); |
| 552 | err_subsys: |
| 553 | destroy_ramdump_device(drv->ramdump_dev); |
| 554 | err_ramdump: |
| 555 | smsm_state_cb_deregister(SMSM_WCNSS_STATE, SMSM_RESET, |
| 556 | smsm_state_cb_hdlr, drv); |
| 557 | err_smsm: |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 558 | pil_desc_release(desc); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 559 | return ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static int __devexit pil_riva_remove(struct platform_device *pdev) |
| 563 | { |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 564 | struct riva_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 565 | |
| 566 | subsys_unregister(drv->subsys); |
| 567 | destroy_ramdump_device(drv->ramdump_dev); |
| 568 | smsm_state_cb_deregister(SMSM_WCNSS_STATE, SMSM_RESET, |
| 569 | smsm_state_cb_hdlr, drv); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 570 | pil_desc_release(&drv->pil_desc); |
Stephen Boyd | fdec00d | 2012-05-10 17:04:49 -0700 | [diff] [blame] | 571 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static struct platform_driver pil_riva_driver = { |
| 576 | .probe = pil_riva_probe, |
| 577 | .remove = __devexit_p(pil_riva_remove), |
| 578 | .driver = { |
| 579 | .name = "pil_riva", |
| 580 | .owner = THIS_MODULE, |
| 581 | }, |
| 582 | }; |
| 583 | |
| 584 | static int __init pil_riva_init(void) |
| 585 | { |
| 586 | return platform_driver_register(&pil_riva_driver); |
| 587 | } |
| 588 | module_init(pil_riva_init); |
| 589 | |
| 590 | static void __exit pil_riva_exit(void) |
| 591 | { |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 592 | platform_driver_unregister(&pil_riva_driver); |
| 593 | } |
| 594 | module_exit(pil_riva_exit); |
| 595 | |
| 596 | MODULE_DESCRIPTION("Support for booting RIVA (WCNSS) processors"); |
| 597 | MODULE_LICENSE("GPL v2"); |