Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 1 | /* |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/io.h> |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 18 | #include <linux/iopoll.h> |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 19 | #include <linux/err.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/clk.h> |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 22 | #include <linux/regulator/consumer.h> |
| 23 | #include <mach/rpm-regulator-smd.h> |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 24 | #include <mach/clk.h> |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 25 | #include "peripheral-loader.h" |
| 26 | #include "pil-q6v5.h" |
| 27 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 28 | /* QDSP6SS Register Offsets */ |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 29 | #define QDSP6SS_RESET 0x014 |
| 30 | #define QDSP6SS_GFMUX_CTL 0x020 |
| 31 | #define QDSP6SS_PWR_CTL 0x030 |
| 32 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 33 | /* AXI Halt Register Offsets */ |
| 34 | #define AXI_HALTREQ 0x0 |
| 35 | #define AXI_HALTACK 0x4 |
| 36 | #define AXI_IDLE 0x8 |
| 37 | |
| 38 | #define HALT_ACK_TIMEOUT_US 100000 |
| 39 | |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 40 | /* QDSP6SS_RESET */ |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 41 | #define Q6SS_STOP_CORE BIT(0) |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 42 | #define Q6SS_CORE_ARES BIT(1) |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 43 | #define Q6SS_BUS_ARES_ENA BIT(2) |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 44 | |
| 45 | /* QDSP6SS_GFMUX_CTL */ |
| 46 | #define Q6SS_CLK_ENA BIT(1) |
| 47 | |
| 48 | /* QDSP6SS_PWR_CTL */ |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 49 | #define Q6SS_L2DATA_SLP_NRET_N (BIT(0)|BIT(1)|BIT(2)) |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 50 | #define Q6SS_L2TAG_SLP_NRET_N BIT(16) |
| 51 | #define Q6SS_ETB_SLP_NRET_N BIT(17) |
| 52 | #define Q6SS_L2DATA_STBY_N BIT(18) |
| 53 | #define Q6SS_SLP_RET_N BIT(19) |
| 54 | #define Q6SS_CLAMP_IO BIT(20) |
| 55 | #define QDSS_BHS_ON BIT(21) |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 56 | #define QDSS_LDO_BYP BIT(22) |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 57 | |
| 58 | int pil_q6v5_make_proxy_votes(struct pil_desc *pil) |
| 59 | { |
| 60 | int ret; |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 61 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 62 | |
| 63 | ret = clk_prepare_enable(drv->xo); |
| 64 | if (ret) { |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 65 | dev_err(pil->dev, "Failed to vote for XO\n"); |
| 66 | goto out; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 67 | } |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 68 | |
| 69 | ret = regulator_enable(drv->vreg_cx); |
| 70 | if (ret) { |
| 71 | dev_err(pil->dev, "Failed to vote for vdd_cx\n"); |
| 72 | clk_disable_unprepare(drv->xo); |
| 73 | goto out; |
| 74 | } |
| 75 | |
| 76 | if (drv->vreg_pll) { |
| 77 | ret = regulator_enable(drv->vreg_pll); |
| 78 | if (ret) { |
| 79 | dev_err(pil->dev, "Failed to vote for vdd_pll\n"); |
| 80 | regulator_disable(drv->vreg_cx); |
| 81 | clk_disable_unprepare(drv->xo); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | out: |
| 86 | return ret; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 87 | } |
| 88 | EXPORT_SYMBOL(pil_q6v5_make_proxy_votes); |
| 89 | |
| 90 | void pil_q6v5_remove_proxy_votes(struct pil_desc *pil) |
| 91 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 92 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 93 | if (drv->vreg_pll) |
| 94 | regulator_disable(drv->vreg_pll); |
| 95 | regulator_disable(drv->vreg_cx); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 96 | clk_disable_unprepare(drv->xo); |
| 97 | } |
| 98 | EXPORT_SYMBOL(pil_q6v5_remove_proxy_votes); |
| 99 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 100 | void pil_q6v5_halt_axi_port(struct pil_desc *pil, void __iomem *halt_base) |
| 101 | { |
| 102 | int ret; |
| 103 | u32 status; |
| 104 | |
| 105 | /* Assert halt request */ |
| 106 | writel_relaxed(1, halt_base + AXI_HALTREQ); |
| 107 | |
| 108 | /* Wait for halt */ |
| 109 | ret = readl_poll_timeout(halt_base + AXI_HALTACK, |
| 110 | status, status != 0, 50, HALT_ACK_TIMEOUT_US); |
| 111 | if (ret) |
| 112 | dev_warn(pil->dev, "Port %p halt timeout\n", halt_base); |
| 113 | else if (!readl_relaxed(halt_base + AXI_IDLE)) |
| 114 | dev_warn(pil->dev, "Port %p halt failed\n", halt_base); |
| 115 | |
| 116 | /* Clear halt request (port will remain halted until reset) */ |
| 117 | writel_relaxed(0, halt_base + AXI_HALTREQ); |
| 118 | } |
| 119 | EXPORT_SYMBOL(pil_q6v5_halt_axi_port); |
| 120 | |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 121 | void pil_q6v5_shutdown(struct pil_desc *pil) |
| 122 | { |
| 123 | u32 val; |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 124 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 125 | |
| 126 | /* Turn off core clock */ |
| 127 | val = readl_relaxed(drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 128 | val &= ~Q6SS_CLK_ENA; |
| 129 | writel_relaxed(val, drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 130 | |
| 131 | /* Clamp IO */ |
| 132 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
| 133 | val |= Q6SS_CLAMP_IO; |
| 134 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 135 | |
| 136 | /* Turn off Q6 memories */ |
| 137 | val &= ~(Q6SS_L2DATA_SLP_NRET_N | Q6SS_SLP_RET_N | |
| 138 | Q6SS_L2TAG_SLP_NRET_N | Q6SS_ETB_SLP_NRET_N | |
| 139 | Q6SS_L2DATA_STBY_N); |
Matt Wagantall | f15e5a3 | 2012-12-19 14:41:17 -0800 | [diff] [blame] | 140 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 141 | |
| 142 | /* Assert Q6 resets */ |
| 143 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 144 | val = (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 145 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 146 | |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 147 | /* Kill power at block headswitch */ |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 148 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
| 149 | val &= ~QDSS_BHS_ON; |
| 150 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 151 | } |
| 152 | EXPORT_SYMBOL(pil_q6v5_shutdown); |
| 153 | |
| 154 | int pil_q6v5_reset(struct pil_desc *pil) |
| 155 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 156 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 157 | u32 val; |
| 158 | |
| 159 | /* Assert resets, stop core */ |
| 160 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 161 | val |= (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA | Q6SS_STOP_CORE); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 162 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 163 | |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 164 | /* Enable power block headswitch, and wait for it to stabilize */ |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 165 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 166 | val |= QDSS_BHS_ON | QDSS_LDO_BYP; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 167 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 168 | mb(); |
| 169 | udelay(1); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 170 | |
| 171 | /* Turn on memories */ |
| 172 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
| 173 | val |= Q6SS_L2DATA_SLP_NRET_N | Q6SS_SLP_RET_N | |
| 174 | Q6SS_L2TAG_SLP_NRET_N | Q6SS_ETB_SLP_NRET_N | |
| 175 | Q6SS_L2DATA_STBY_N; |
| 176 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 177 | |
| 178 | /* Remove IO clamp */ |
| 179 | val &= ~Q6SS_CLAMP_IO; |
| 180 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 181 | |
| 182 | /* Bring core out of reset */ |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 183 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
| 184 | val &= ~Q6SS_CORE_ARES; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 185 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 186 | |
| 187 | /* Turn on core clock */ |
| 188 | val = readl_relaxed(drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 189 | val |= Q6SS_CLK_ENA; |
| 190 | writel_relaxed(val, drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 191 | |
| 192 | /* Start core execution */ |
| 193 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
| 194 | val &= ~Q6SS_STOP_CORE; |
| 195 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | EXPORT_SYMBOL(pil_q6v5_reset); |
| 200 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 201 | struct q6v5_data __devinit *pil_q6v5_init(struct platform_device *pdev) |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 202 | { |
| 203 | struct q6v5_data *drv; |
| 204 | struct resource *res; |
| 205 | struct pil_desc *desc; |
| 206 | int ret; |
| 207 | |
| 208 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 209 | if (!drv) |
| 210 | return ERR_PTR(-ENOMEM); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 211 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 212 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6_base"); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 213 | drv->reg_base = devm_request_and_ioremap(&pdev->dev, res); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 214 | if (!drv->reg_base) |
| 215 | return ERR_PTR(-ENOMEM); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 216 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 217 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "halt_base"); |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 218 | drv->axi_halt_base = devm_ioremap(&pdev->dev, res->start, |
| 219 | resource_size(res)); |
| 220 | if (!drv->axi_halt_base) |
| 221 | return ERR_PTR(-ENOMEM); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 222 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 223 | desc = &drv->desc; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 224 | ret = of_property_read_string(pdev->dev.of_node, "qcom,firmware-name", |
| 225 | &desc->name); |
| 226 | if (ret) |
| 227 | return ERR_PTR(ret); |
| 228 | |
| 229 | drv->xo = devm_clk_get(&pdev->dev, "xo"); |
| 230 | if (IS_ERR(drv->xo)) |
| 231 | return ERR_CAST(drv->xo); |
| 232 | |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 233 | drv->vreg_cx = devm_regulator_get(&pdev->dev, "vdd_cx"); |
| 234 | if (IS_ERR(drv->vreg_cx)) |
| 235 | return ERR_CAST(drv->vreg_cx); |
| 236 | |
| 237 | ret = regulator_set_voltage(drv->vreg_cx, |
| 238 | RPM_REGULATOR_CORNER_SUPER_TURBO, |
| 239 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 240 | if (ret) { |
| 241 | dev_err(&pdev->dev, "Failed to request vdd_cx voltage.\n"); |
| 242 | return ERR_PTR(ret); |
| 243 | } |
| 244 | |
| 245 | ret = regulator_set_optimum_mode(drv->vreg_cx, 100000); |
| 246 | if (ret < 0) { |
| 247 | dev_err(&pdev->dev, "Failed to set vdd_cx mode.\n"); |
| 248 | return ERR_PTR(ret); |
| 249 | } |
| 250 | |
| 251 | drv->vreg_pll = devm_regulator_get(&pdev->dev, "vdd_pll"); |
| 252 | if (!IS_ERR(drv->vreg_pll)) { |
| 253 | int voltage; |
| 254 | ret = of_property_read_u32(pdev->dev.of_node, "qcom,vdd_pll", |
| 255 | &voltage); |
| 256 | if (ret) { |
| 257 | dev_err(&pdev->dev, "Failed to find vdd_pll voltage.\n"); |
| 258 | return ERR_PTR(ret); |
| 259 | } |
| 260 | |
| 261 | ret = regulator_set_voltage(drv->vreg_pll, voltage, voltage); |
| 262 | if (ret) { |
| 263 | dev_err(&pdev->dev, "Failed to request vdd_pll voltage.\n"); |
| 264 | return ERR_PTR(ret); |
| 265 | } |
| 266 | |
| 267 | ret = regulator_set_optimum_mode(drv->vreg_pll, 10000); |
| 268 | if (ret < 0) { |
| 269 | dev_err(&pdev->dev, "Failed to set vdd_pll mode.\n"); |
| 270 | return ERR_PTR(ret); |
| 271 | } |
| 272 | } else { |
| 273 | drv->vreg_pll = NULL; |
| 274 | } |
| 275 | |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 276 | desc->dev = &pdev->dev; |
| 277 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 278 | return drv; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 279 | } |
| 280 | EXPORT_SYMBOL(pil_q6v5_init); |