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 | |
Matt Wagantall | 9a8dde4 | 2013-02-11 16:18:33 -0800 | [diff] [blame^] | 69 | ret = regulator_set_voltage(drv->vreg_cx, |
| 70 | RPM_REGULATOR_CORNER_SUPER_TURBO, |
| 71 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 72 | if (ret) { |
| 73 | dev_err(pil->dev, "Failed to request vdd_cx voltage.\n"); |
| 74 | goto err_cx_voltage; |
| 75 | } |
| 76 | |
| 77 | ret = regulator_set_optimum_mode(drv->vreg_cx, 100000); |
| 78 | if (ret < 0) { |
| 79 | dev_err(pil->dev, "Failed to set vdd_cx mode.\n"); |
| 80 | goto err_cx_mode; |
| 81 | } |
| 82 | |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 83 | ret = regulator_enable(drv->vreg_cx); |
| 84 | if (ret) { |
| 85 | dev_err(pil->dev, "Failed to vote for vdd_cx\n"); |
Matt Wagantall | 9a8dde4 | 2013-02-11 16:18:33 -0800 | [diff] [blame^] | 86 | goto err_cx_enable; |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | if (drv->vreg_pll) { |
| 90 | ret = regulator_enable(drv->vreg_pll); |
| 91 | if (ret) { |
| 92 | dev_err(pil->dev, "Failed to vote for vdd_pll\n"); |
Matt Wagantall | 9a8dde4 | 2013-02-11 16:18:33 -0800 | [diff] [blame^] | 93 | goto err_vreg_pll; |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Matt Wagantall | 9a8dde4 | 2013-02-11 16:18:33 -0800 | [diff] [blame^] | 97 | return 0; |
| 98 | |
| 99 | err_vreg_pll: |
| 100 | regulator_disable(drv->vreg_cx); |
| 101 | err_cx_enable: |
| 102 | regulator_set_optimum_mode(drv->vreg_cx, 0); |
| 103 | err_cx_mode: |
| 104 | regulator_set_voltage(drv->vreg_cx, RPM_REGULATOR_CORNER_NONE, |
| 105 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 106 | err_cx_voltage: |
| 107 | clk_disable_unprepare(drv->xo); |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 108 | out: |
| 109 | return ret; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 110 | } |
| 111 | EXPORT_SYMBOL(pil_q6v5_make_proxy_votes); |
| 112 | |
| 113 | void pil_q6v5_remove_proxy_votes(struct pil_desc *pil) |
| 114 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 115 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 116 | if (drv->vreg_pll) |
| 117 | regulator_disable(drv->vreg_pll); |
| 118 | regulator_disable(drv->vreg_cx); |
Matt Wagantall | 9a8dde4 | 2013-02-11 16:18:33 -0800 | [diff] [blame^] | 119 | regulator_set_optimum_mode(drv->vreg_cx, 0); |
| 120 | regulator_set_voltage(drv->vreg_cx, RPM_REGULATOR_CORNER_NONE, |
| 121 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 122 | clk_disable_unprepare(drv->xo); |
| 123 | } |
| 124 | EXPORT_SYMBOL(pil_q6v5_remove_proxy_votes); |
| 125 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 126 | void pil_q6v5_halt_axi_port(struct pil_desc *pil, void __iomem *halt_base) |
| 127 | { |
| 128 | int ret; |
| 129 | u32 status; |
| 130 | |
| 131 | /* Assert halt request */ |
| 132 | writel_relaxed(1, halt_base + AXI_HALTREQ); |
| 133 | |
| 134 | /* Wait for halt */ |
| 135 | ret = readl_poll_timeout(halt_base + AXI_HALTACK, |
| 136 | status, status != 0, 50, HALT_ACK_TIMEOUT_US); |
| 137 | if (ret) |
| 138 | dev_warn(pil->dev, "Port %p halt timeout\n", halt_base); |
| 139 | else if (!readl_relaxed(halt_base + AXI_IDLE)) |
| 140 | dev_warn(pil->dev, "Port %p halt failed\n", halt_base); |
| 141 | |
| 142 | /* Clear halt request (port will remain halted until reset) */ |
| 143 | writel_relaxed(0, halt_base + AXI_HALTREQ); |
| 144 | } |
| 145 | EXPORT_SYMBOL(pil_q6v5_halt_axi_port); |
| 146 | |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 147 | void pil_q6v5_shutdown(struct pil_desc *pil) |
| 148 | { |
| 149 | u32 val; |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 150 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 151 | |
| 152 | /* Turn off core clock */ |
| 153 | val = readl_relaxed(drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 154 | val &= ~Q6SS_CLK_ENA; |
| 155 | writel_relaxed(val, drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 156 | |
| 157 | /* Clamp IO */ |
| 158 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
| 159 | val |= Q6SS_CLAMP_IO; |
| 160 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 161 | |
| 162 | /* Turn off Q6 memories */ |
| 163 | val &= ~(Q6SS_L2DATA_SLP_NRET_N | Q6SS_SLP_RET_N | |
| 164 | Q6SS_L2TAG_SLP_NRET_N | Q6SS_ETB_SLP_NRET_N | |
| 165 | Q6SS_L2DATA_STBY_N); |
Matt Wagantall | f15e5a3 | 2012-12-19 14:41:17 -0800 | [diff] [blame] | 166 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 167 | |
| 168 | /* Assert Q6 resets */ |
| 169 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 170 | val = (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 171 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 172 | |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 173 | /* Kill power at block headswitch */ |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 174 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
| 175 | val &= ~QDSS_BHS_ON; |
| 176 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 177 | } |
| 178 | EXPORT_SYMBOL(pil_q6v5_shutdown); |
| 179 | |
| 180 | int pil_q6v5_reset(struct pil_desc *pil) |
| 181 | { |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 182 | struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 183 | u32 val; |
| 184 | |
| 185 | /* Assert resets, stop core */ |
| 186 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 187 | val |= (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA | Q6SS_STOP_CORE); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 188 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 189 | |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 190 | /* Enable power block headswitch, and wait for it to stabilize */ |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 191 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 192 | val |= QDSS_BHS_ON | QDSS_LDO_BYP; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 193 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
Matt Wagantall | 3bc2fe5 | 2013-01-15 13:34:55 -0800 | [diff] [blame] | 194 | mb(); |
| 195 | udelay(1); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 196 | |
| 197 | /* Turn on memories */ |
| 198 | val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL); |
| 199 | val |= Q6SS_L2DATA_SLP_NRET_N | Q6SS_SLP_RET_N | |
| 200 | Q6SS_L2TAG_SLP_NRET_N | Q6SS_ETB_SLP_NRET_N | |
| 201 | Q6SS_L2DATA_STBY_N; |
| 202 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 203 | |
| 204 | /* Remove IO clamp */ |
| 205 | val &= ~Q6SS_CLAMP_IO; |
| 206 | writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL); |
| 207 | |
| 208 | /* Bring core out of reset */ |
Matt Wagantall | 11c07e2 | 2012-08-09 16:14:07 -0700 | [diff] [blame] | 209 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
| 210 | val &= ~Q6SS_CORE_ARES; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 211 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 212 | |
| 213 | /* Turn on core clock */ |
| 214 | val = readl_relaxed(drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 215 | val |= Q6SS_CLK_ENA; |
| 216 | writel_relaxed(val, drv->reg_base + QDSP6SS_GFMUX_CTL); |
| 217 | |
| 218 | /* Start core execution */ |
| 219 | val = readl_relaxed(drv->reg_base + QDSP6SS_RESET); |
| 220 | val &= ~Q6SS_STOP_CORE; |
| 221 | writel_relaxed(val, drv->reg_base + QDSP6SS_RESET); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | EXPORT_SYMBOL(pil_q6v5_reset); |
| 226 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 227 | struct q6v5_data __devinit *pil_q6v5_init(struct platform_device *pdev) |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 228 | { |
| 229 | struct q6v5_data *drv; |
| 230 | struct resource *res; |
| 231 | struct pil_desc *desc; |
| 232 | int ret; |
| 233 | |
| 234 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 235 | if (!drv) |
| 236 | return ERR_PTR(-ENOMEM); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 237 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 238 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6_base"); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 239 | drv->reg_base = devm_request_and_ioremap(&pdev->dev, res); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 240 | if (!drv->reg_base) |
| 241 | return ERR_PTR(-ENOMEM); |
Stephen Boyd | f8f8928 | 2012-07-16 18:05:48 -0700 | [diff] [blame] | 242 | |
Matt Wagantall | 1f16815 | 2012-09-25 13:26:47 -0700 | [diff] [blame] | 243 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "halt_base"); |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 244 | drv->axi_halt_base = devm_ioremap(&pdev->dev, res->start, |
| 245 | resource_size(res)); |
| 246 | if (!drv->axi_halt_base) |
| 247 | return ERR_PTR(-ENOMEM); |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 248 | |
Stephen Boyd | 633eb62 | 2012-06-13 12:05:35 -0700 | [diff] [blame] | 249 | desc = &drv->desc; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 250 | ret = of_property_read_string(pdev->dev.of_node, "qcom,firmware-name", |
| 251 | &desc->name); |
| 252 | if (ret) |
| 253 | return ERR_PTR(ret); |
| 254 | |
| 255 | drv->xo = devm_clk_get(&pdev->dev, "xo"); |
| 256 | if (IS_ERR(drv->xo)) |
| 257 | return ERR_CAST(drv->xo); |
| 258 | |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 259 | drv->vreg_cx = devm_regulator_get(&pdev->dev, "vdd_cx"); |
| 260 | if (IS_ERR(drv->vreg_cx)) |
| 261 | return ERR_CAST(drv->vreg_cx); |
| 262 | |
Matt Wagantall | 6c51598 | 2013-01-29 14:58:43 -0800 | [diff] [blame] | 263 | drv->vreg_pll = devm_regulator_get(&pdev->dev, "vdd_pll"); |
| 264 | if (!IS_ERR(drv->vreg_pll)) { |
| 265 | int voltage; |
| 266 | ret = of_property_read_u32(pdev->dev.of_node, "qcom,vdd_pll", |
| 267 | &voltage); |
| 268 | if (ret) { |
| 269 | dev_err(&pdev->dev, "Failed to find vdd_pll voltage.\n"); |
| 270 | return ERR_PTR(ret); |
| 271 | } |
| 272 | |
| 273 | ret = regulator_set_voltage(drv->vreg_pll, voltage, voltage); |
| 274 | if (ret) { |
| 275 | dev_err(&pdev->dev, "Failed to request vdd_pll voltage.\n"); |
| 276 | return ERR_PTR(ret); |
| 277 | } |
| 278 | |
| 279 | ret = regulator_set_optimum_mode(drv->vreg_pll, 10000); |
| 280 | if (ret < 0) { |
| 281 | dev_err(&pdev->dev, "Failed to set vdd_pll mode.\n"); |
| 282 | return ERR_PTR(ret); |
| 283 | } |
| 284 | } else { |
| 285 | drv->vreg_pll = NULL; |
| 286 | } |
| 287 | |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 288 | desc->dev = &pdev->dev; |
| 289 | |
Stephen Boyd | 3826cd4 | 2012-07-05 17:37:53 -0700 | [diff] [blame] | 290 | return drv; |
Matt Wagantall | b3fe899 | 2011-12-07 19:26:55 -0800 | [diff] [blame] | 291 | } |
| 292 | EXPORT_SYMBOL(pil_q6v5_init); |