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> |
| 16 | #include <linux/elf.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/platform_device.h> |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 21 | #include <linux/regulator/consumer.h> |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 22 | #include <linux/clk.h> |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 23 | |
| 24 | #include <mach/msm_iomap.h> |
| 25 | |
| 26 | #include "peripheral-loader.h" |
| 27 | #include "scm-pas.h" |
| 28 | |
| 29 | #define RIVA_PMU_A2XB_CFG 0xB8 |
| 30 | #define RIVA_PMU_A2XB_CFG_EN BIT(0) |
| 31 | |
| 32 | #define RIVA_PMU_CFG 0x28 |
| 33 | #define RIVA_PMU_CFG_WARM_BOOT BIT(0) |
| 34 | #define RIVA_PMU_CFG_IRIS_XO_MODE 0x6 |
| 35 | #define RIVA_PMU_CFG_IRIS_XO_MODE_48 (3 << 1) |
| 36 | |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 37 | #define RIVA_PMU_OVRD_EN 0x2C |
| 38 | #define RIVA_PMU_OVRD_EN_CCPU_RESET BIT(0) |
| 39 | #define RIVA_PMU_OVRD_EN_CCPU_CLK BIT(1) |
| 40 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 41 | #define RIVA_PMU_OVRD_VAL 0x30 |
| 42 | #define RIVA_PMU_OVRD_VAL_CCPU_RESET BIT(0) |
| 43 | #define RIVA_PMU_OVRD_VAL_CCPU_CLK BIT(1) |
| 44 | |
| 45 | #define RIVA_PMU_CCPU_CTL 0x9C |
| 46 | #define RIVA_PMU_CCPU_CTL_HIGH_IVT BIT(0) |
| 47 | #define RIVA_PMU_CCPU_CTL_REMAP_EN BIT(2) |
| 48 | |
| 49 | #define RIVA_PMU_CCPU_BOOT_REMAP_ADDR 0xA0 |
| 50 | |
| 51 | #define RIVA_PLL_MODE (MSM_CLK_CTL_BASE + 0x31A0) |
| 52 | #define PLL_MODE_OUTCTRL BIT(0) |
| 53 | #define PLL_MODE_BYPASSNL BIT(1) |
| 54 | #define PLL_MODE_RESET_N BIT(2) |
| 55 | #define PLL_MODE_REF_XO_SEL 0x30 |
| 56 | #define PLL_MODE_REF_XO_SEL_CXO (2 << 4) |
| 57 | #define PLL_MODE_REF_XO_SEL_RF (3 << 4) |
| 58 | #define RIVA_PLL_L_VAL (MSM_CLK_CTL_BASE + 0x31A4) |
| 59 | #define RIVA_PLL_M_VAL (MSM_CLK_CTL_BASE + 0x31A8) |
| 60 | #define RIVA_PLL_N_VAL (MSM_CLK_CTL_BASE + 0x31Ac) |
| 61 | #define RIVA_PLL_CONFIG (MSM_CLK_CTL_BASE + 0x31B4) |
| 62 | #define RIVA_PLL_STATUS (MSM_CLK_CTL_BASE + 0x31B8) |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 63 | #define RIVA_RESET (MSM_CLK_CTL_BASE + 0x35E0) |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 64 | |
| 65 | #define RIVA_PMU_ROOT_CLK_SEL 0xC8 |
| 66 | #define RIVA_PMU_ROOT_CLK_SEL_3 BIT(2) |
| 67 | |
| 68 | #define RIVA_PMU_CLK_ROOT3 0x78 |
| 69 | #define RIVA_PMU_CLK_ROOT3_ENA BIT(0) |
| 70 | #define RIVA_PMU_CLK_ROOT3_SRC0_DIV 0x3C |
| 71 | #define RIVA_PMU_CLK_ROOT3_SRC0_DIV_2 (1 << 2) |
| 72 | #define RIVA_PMU_CLK_ROOT3_SRC0_SEL 0x1C0 |
| 73 | #define RIVA_PMU_CLK_ROOT3_SRC0_SEL_RIVA (1 << 6) |
| 74 | #define RIVA_PMU_CLK_ROOT3_SRC1_DIV 0x1E00 |
| 75 | #define RIVA_PMU_CLK_ROOT3_SRC1_DIV_2 (1 << 9) |
| 76 | #define RIVA_PMU_CLK_ROOT3_SRC1_SEL 0xE000 |
| 77 | #define RIVA_PMU_CLK_ROOT3_SRC1_SEL_RIVA (1 << 13) |
| 78 | |
| 79 | struct riva_data { |
| 80 | void __iomem *base; |
| 81 | unsigned long start_addr; |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 82 | struct clk *xo; |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 83 | bool use_cxo; |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 84 | struct regulator *pll_supply; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 85 | struct pil_device *pil; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 88 | static bool cxo_is_needed(struct riva_data *drv) |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 89 | { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 90 | u32 reg = readl_relaxed(drv->base + RIVA_PMU_CFG); |
| 91 | return (reg & RIVA_PMU_CFG_IRIS_XO_MODE) |
| 92 | != RIVA_PMU_CFG_IRIS_XO_MODE_48; |
| 93 | } |
| 94 | |
| 95 | static int pil_riva_make_proxy_vote(struct pil_desc *pil) |
| 96 | { |
| 97 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 98 | int ret; |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 99 | |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 100 | drv->use_cxo = cxo_is_needed(drv); |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 101 | ret = regulator_enable(drv->pll_supply); |
| 102 | if (ret) { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 103 | dev_err(pil->dev, "failed to enable pll supply\n"); |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 104 | goto err; |
| 105 | } |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 106 | if (drv->use_cxo) { |
| 107 | ret = clk_prepare_enable(drv->xo); |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 108 | if (ret) { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 109 | dev_err(pil->dev, "failed to enable xo\n"); |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 110 | goto err_clk; |
| 111 | } |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 112 | } |
Stephen Boyd | d0b993a | 2012-01-30 11:59:31 -0800 | [diff] [blame] | 113 | return 0; |
| 114 | err_clk: |
| 115 | regulator_disable(drv->pll_supply); |
| 116 | err: |
| 117 | return ret; |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 120 | static void pil_riva_remove_proxy_vote(struct pil_desc *pil) |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 121 | { |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 122 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 123 | regulator_disable(drv->pll_supply); |
| 124 | if (drv->use_cxo) |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 125 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 128 | static int pil_riva_init_image(struct pil_desc *pil, const u8 *metadata, |
| 129 | size_t size) |
| 130 | { |
| 131 | const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 132 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
| 133 | drv->start_addr = ehdr->e_entry; |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static int pil_riva_reset(struct pil_desc *pil) |
| 138 | { |
| 139 | u32 reg, sel; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 140 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
| 141 | void __iomem *base = drv->base; |
| 142 | unsigned long start_addr = drv->start_addr; |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 143 | int ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 144 | |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 145 | ret = clk_prepare_enable(drv->xo); |
| 146 | if (ret) |
| 147 | return ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 148 | /* Enable A2XB bridge */ |
| 149 | reg = readl_relaxed(base + RIVA_PMU_A2XB_CFG); |
| 150 | reg |= RIVA_PMU_A2XB_CFG_EN; |
| 151 | writel_relaxed(reg, base + RIVA_PMU_A2XB_CFG); |
| 152 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 153 | /* Program PLL 13 to 960 MHz */ |
| 154 | reg = readl_relaxed(RIVA_PLL_MODE); |
| 155 | reg &= ~(PLL_MODE_BYPASSNL | PLL_MODE_OUTCTRL | PLL_MODE_RESET_N); |
| 156 | writel_relaxed(reg, RIVA_PLL_MODE); |
| 157 | |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 158 | if (drv->use_cxo) |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 159 | writel_relaxed(0x40000C00 | 50, RIVA_PLL_L_VAL); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 160 | else |
| 161 | writel_relaxed(0x40000C00 | 40, RIVA_PLL_L_VAL); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 162 | writel_relaxed(0, RIVA_PLL_M_VAL); |
| 163 | writel_relaxed(1, RIVA_PLL_N_VAL); |
| 164 | writel_relaxed(0x01495227, RIVA_PLL_CONFIG); |
| 165 | |
| 166 | reg = readl_relaxed(RIVA_PLL_MODE); |
| 167 | reg &= ~(PLL_MODE_REF_XO_SEL); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 168 | reg |= drv->use_cxo ? PLL_MODE_REF_XO_SEL_CXO : PLL_MODE_REF_XO_SEL_RF; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 169 | writel_relaxed(reg, RIVA_PLL_MODE); |
| 170 | |
| 171 | /* Enable PLL 13 */ |
| 172 | reg |= PLL_MODE_BYPASSNL; |
| 173 | writel_relaxed(reg, RIVA_PLL_MODE); |
| 174 | |
| 175 | /* |
| 176 | * H/W requires a 5us delay between disabling the bypass and |
| 177 | * de-asserting the reset. Delay 10us just to be safe. |
| 178 | */ |
| 179 | mb(); |
| 180 | usleep_range(10, 20); |
| 181 | |
| 182 | reg |= PLL_MODE_RESET_N; |
| 183 | writel_relaxed(reg, RIVA_PLL_MODE); |
| 184 | reg |= PLL_MODE_OUTCTRL; |
| 185 | writel_relaxed(reg, RIVA_PLL_MODE); |
| 186 | |
| 187 | /* Wait for PLL to settle */ |
| 188 | mb(); |
| 189 | usleep_range(50, 100); |
| 190 | |
| 191 | /* Configure cCPU for 240 MHz */ |
| 192 | sel = readl_relaxed(base + RIVA_PMU_ROOT_CLK_SEL); |
| 193 | reg = readl_relaxed(base + RIVA_PMU_CLK_ROOT3); |
| 194 | if (sel & RIVA_PMU_ROOT_CLK_SEL_3) { |
| 195 | reg &= ~(RIVA_PMU_CLK_ROOT3_SRC0_SEL | |
| 196 | RIVA_PMU_CLK_ROOT3_SRC0_DIV); |
| 197 | reg |= RIVA_PMU_CLK_ROOT3_SRC0_SEL_RIVA | |
| 198 | RIVA_PMU_CLK_ROOT3_SRC0_DIV_2; |
| 199 | } else { |
| 200 | reg &= ~(RIVA_PMU_CLK_ROOT3_SRC1_SEL | |
| 201 | RIVA_PMU_CLK_ROOT3_SRC1_DIV); |
| 202 | reg |= RIVA_PMU_CLK_ROOT3_SRC1_SEL_RIVA | |
| 203 | RIVA_PMU_CLK_ROOT3_SRC1_DIV_2; |
| 204 | } |
| 205 | writel_relaxed(reg, base + RIVA_PMU_CLK_ROOT3); |
| 206 | reg |= RIVA_PMU_CLK_ROOT3_ENA; |
| 207 | writel_relaxed(reg, base + RIVA_PMU_CLK_ROOT3); |
| 208 | reg = readl_relaxed(base + RIVA_PMU_ROOT_CLK_SEL); |
| 209 | reg ^= RIVA_PMU_ROOT_CLK_SEL_3; |
| 210 | writel_relaxed(reg, base + RIVA_PMU_ROOT_CLK_SEL); |
| 211 | |
| 212 | /* Use the high vector table */ |
| 213 | reg = readl_relaxed(base + RIVA_PMU_CCPU_CTL); |
| 214 | reg |= RIVA_PMU_CCPU_CTL_HIGH_IVT | RIVA_PMU_CCPU_CTL_REMAP_EN; |
| 215 | writel_relaxed(reg, base + RIVA_PMU_CCPU_CTL); |
| 216 | |
| 217 | /* Set base memory address */ |
| 218 | writel_relaxed(start_addr >> 16, base + RIVA_PMU_CCPU_BOOT_REMAP_ADDR); |
| 219 | |
| 220 | /* Clear warmboot bit indicating this is a cold boot */ |
| 221 | reg = readl_relaxed(base + RIVA_PMU_CFG); |
| 222 | reg &= ~(RIVA_PMU_CFG_WARM_BOOT); |
| 223 | writel_relaxed(reg, base + RIVA_PMU_CFG); |
| 224 | |
| 225 | /* Enable the cCPU clock */ |
| 226 | reg = readl_relaxed(base + RIVA_PMU_OVRD_VAL); |
| 227 | reg |= RIVA_PMU_OVRD_VAL_CCPU_CLK; |
| 228 | writel_relaxed(reg, base + RIVA_PMU_OVRD_VAL); |
| 229 | |
| 230 | /* Take cCPU out of reset */ |
| 231 | reg |= RIVA_PMU_OVRD_VAL_CCPU_RESET; |
| 232 | writel_relaxed(reg, base + RIVA_PMU_OVRD_VAL); |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 233 | clk_disable_unprepare(drv->xo); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int pil_riva_shutdown(struct pil_desc *pil) |
| 239 | { |
| 240 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
| 241 | u32 reg; |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 242 | int ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 243 | |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 244 | ret = clk_prepare_enable(drv->xo); |
| 245 | if (ret) |
| 246 | return ret; |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 247 | /* Put cCPU and cCPU clock into reset */ |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 248 | reg = readl_relaxed(drv->base + RIVA_PMU_OVRD_VAL); |
| 249 | reg &= ~(RIVA_PMU_OVRD_VAL_CCPU_RESET | RIVA_PMU_OVRD_VAL_CCPU_CLK); |
| 250 | writel_relaxed(reg, drv->base + RIVA_PMU_OVRD_VAL); |
Stephen Boyd | 1233257 | 2011-12-06 16:00:51 -0800 | [diff] [blame] | 251 | reg = readl_relaxed(drv->base + RIVA_PMU_OVRD_EN); |
| 252 | reg |= RIVA_PMU_OVRD_EN_CCPU_RESET | RIVA_PMU_OVRD_EN_CCPU_CLK; |
| 253 | writel_relaxed(reg, drv->base + RIVA_PMU_OVRD_EN); |
| 254 | mb(); |
| 255 | |
| 256 | /* Assert reset to Riva */ |
| 257 | writel_relaxed(1, RIVA_RESET); |
| 258 | mb(); |
| 259 | usleep_range(1000, 2000); |
| 260 | |
| 261 | /* Deassert reset to Riva */ |
| 262 | writel_relaxed(0, RIVA_RESET); |
| 263 | mb(); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 264 | |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 265 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 266 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static struct pil_reset_ops pil_riva_ops = { |
| 271 | .init_image = pil_riva_init_image, |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 272 | .auth_and_reset = pil_riva_reset, |
| 273 | .shutdown = pil_riva_shutdown, |
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 | |
| 278 | static int pil_riva_init_image_trusted(struct pil_desc *pil, |
| 279 | const u8 *metadata, size_t size) |
| 280 | { |
| 281 | return pas_init_image(PAS_RIVA, metadata, size); |
| 282 | } |
| 283 | |
| 284 | static int pil_riva_reset_trusted(struct pil_desc *pil) |
| 285 | { |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 286 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
| 287 | int ret; |
| 288 | |
| 289 | ret = clk_prepare_enable(drv->xo); |
| 290 | if (ret) |
| 291 | return ret; |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 292 | /* Proxy-vote for resources RIVA needs */ |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 293 | ret = pas_auth_and_reset(PAS_RIVA); |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 294 | clk_disable_unprepare(drv->xo); |
| 295 | return ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static int pil_riva_shutdown_trusted(struct pil_desc *pil) |
| 299 | { |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 300 | int ret; |
| 301 | struct riva_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 302 | |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 303 | ret = clk_prepare_enable(drv->xo); |
| 304 | if (ret) |
| 305 | return ret; |
| 306 | ret = pas_shutdown(PAS_RIVA); |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 307 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 308 | |
| 309 | return ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static struct pil_reset_ops pil_riva_ops_trusted = { |
| 313 | .init_image = pil_riva_init_image_trusted, |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 314 | .auth_and_reset = pil_riva_reset_trusted, |
| 315 | .shutdown = pil_riva_shutdown_trusted, |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 316 | .proxy_vote = pil_riva_make_proxy_vote, |
| 317 | .proxy_unvote = pil_riva_remove_proxy_vote, |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | static int __devinit pil_riva_probe(struct platform_device *pdev) |
| 321 | { |
| 322 | struct riva_data *drv; |
| 323 | struct resource *res; |
| 324 | struct pil_desc *desc; |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 325 | int ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 326 | |
| 327 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 328 | if (!res) |
| 329 | return -EINVAL; |
| 330 | |
| 331 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 332 | if (!drv) |
| 333 | return -ENOMEM; |
| 334 | platform_set_drvdata(pdev, drv); |
| 335 | |
| 336 | drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 337 | if (!drv->base) |
| 338 | return -ENOMEM; |
| 339 | |
| 340 | desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); |
| 341 | if (!desc) |
| 342 | return -ENOMEM; |
| 343 | |
Stephen Boyd | 83e5eae | 2012-03-23 15:04:46 -0700 | [diff] [blame^] | 344 | drv->pll_supply = devm_regulator_get(&pdev->dev, "pll_vdd"); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 345 | if (IS_ERR(drv->pll_supply)) { |
| 346 | dev_err(&pdev->dev, "failed to get pll supply\n"); |
| 347 | return PTR_ERR(drv->pll_supply); |
| 348 | } |
Matt Wagantall | 52dd062 | 2012-02-02 18:26:16 -0800 | [diff] [blame] | 349 | if (regulator_count_voltages(drv->pll_supply) > 0) { |
| 350 | ret = regulator_set_voltage(drv->pll_supply, 1800000, 1800000); |
| 351 | if (ret) { |
| 352 | dev_err(&pdev->dev, |
| 353 | "failed to set pll supply voltage\n"); |
| 354 | goto err; |
| 355 | } |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 356 | |
Matt Wagantall | 52dd062 | 2012-02-02 18:26:16 -0800 | [diff] [blame] | 357 | ret = regulator_set_optimum_mode(drv->pll_supply, 100000); |
| 358 | if (ret < 0) { |
| 359 | dev_err(&pdev->dev, |
| 360 | "failed to set pll supply optimum mode\n"); |
| 361 | goto err; |
| 362 | } |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 365 | desc->name = "wcnss"; |
| 366 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 367 | desc->owner = THIS_MODULE; |
Stephen Boyd | 86f4a09 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 368 | desc->proxy_timeout = 10000; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 369 | |
| 370 | if (pas_supported(PAS_RIVA) > 0) { |
| 371 | desc->ops = &pil_riva_ops_trusted; |
| 372 | dev_info(&pdev->dev, "using secure boot\n"); |
| 373 | } else { |
| 374 | desc->ops = &pil_riva_ops; |
| 375 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 376 | } |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 377 | |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 378 | drv->xo = clk_get(&pdev->dev, "cxo"); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 379 | if (IS_ERR(drv->xo)) { |
| 380 | ret = PTR_ERR(drv->xo); |
| 381 | goto err; |
| 382 | } |
Matt Wagantall | 04b7cc7 | 2011-12-09 18:52:26 -0800 | [diff] [blame] | 383 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 384 | drv->pil = msm_pil_register(desc); |
| 385 | if (IS_ERR(drv->pil)) { |
| 386 | ret = PTR_ERR(drv->pil); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 387 | goto err_register; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 388 | } |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 389 | return 0; |
| 390 | err_register: |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 391 | clk_put(drv->xo); |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 392 | err: |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 393 | return ret; |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static int __devexit pil_riva_remove(struct platform_device *pdev) |
| 397 | { |
Stephen Boyd | 3bbdf6c | 2011-12-21 16:02:26 -0800 | [diff] [blame] | 398 | struct riva_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 399 | msm_pil_unregister(drv->pil); |
Stephen Boyd | 86f2e65 | 2012-01-11 18:25:44 -0800 | [diff] [blame] | 400 | clk_put(drv->xo); |
Stephen Boyd | 322a992 | 2011-09-20 01:05:54 -0700 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static struct platform_driver pil_riva_driver = { |
| 405 | .probe = pil_riva_probe, |
| 406 | .remove = __devexit_p(pil_riva_remove), |
| 407 | .driver = { |
| 408 | .name = "pil_riva", |
| 409 | .owner = THIS_MODULE, |
| 410 | }, |
| 411 | }; |
| 412 | |
| 413 | static int __init pil_riva_init(void) |
| 414 | { |
| 415 | return platform_driver_register(&pil_riva_driver); |
| 416 | } |
| 417 | module_init(pil_riva_init); |
| 418 | |
| 419 | static void __exit pil_riva_exit(void) |
| 420 | { |
| 421 | platform_driver_unregister(&pil_riva_driver); |
| 422 | } |
| 423 | module_exit(pil_riva_exit); |
| 424 | |
| 425 | MODULE_DESCRIPTION("Support for booting RIVA (WCNSS) processors"); |
| 426 | MODULE_LICENSE("GPL v2"); |