blob: 7f8d3b911ea0099890df0dd05268a42117275638 [file] [log] [blame]
Matt Wagantallb3fe8992011-12-07 19:26:55 -08001/*
Matt Wagantall3bc2fe52013-01-15 13:34:55 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Matt Wagantallb3fe8992011-12-07 19:26:55 -08003 *
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 Wagantallb7747992012-05-11 19:37:51 -070018#include <linux/iopoll.h>
Matt Wagantallb3fe8992011-12-07 19:26:55 -080019#include <linux/err.h>
20#include <linux/of.h>
21#include <linux/clk.h>
Matt Wagantall6c515982013-01-29 14:58:43 -080022#include <linux/regulator/consumer.h>
23#include <mach/rpm-regulator-smd.h>
Matt Wagantalld41ce772012-05-10 23:16:41 -070024#include <mach/clk.h>
Matt Wagantallb3fe8992011-12-07 19:26:55 -080025#include "peripheral-loader.h"
26#include "pil-q6v5.h"
27
Matt Wagantallb7747992012-05-11 19:37:51 -070028/* QDSP6SS Register Offsets */
Matt Wagantallb3fe8992011-12-07 19:26:55 -080029#define QDSP6SS_RESET 0x014
30#define QDSP6SS_GFMUX_CTL 0x020
31#define QDSP6SS_PWR_CTL 0x030
32
Matt Wagantallb7747992012-05-11 19:37:51 -070033/* 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 Wagantallb3fe8992011-12-07 19:26:55 -080040/* QDSP6SS_RESET */
Matt Wagantall11c07e22012-08-09 16:14:07 -070041#define Q6SS_STOP_CORE BIT(0)
Matt Wagantallb3fe8992011-12-07 19:26:55 -080042#define Q6SS_CORE_ARES BIT(1)
Matt Wagantall11c07e22012-08-09 16:14:07 -070043#define Q6SS_BUS_ARES_ENA BIT(2)
Matt Wagantallb3fe8992011-12-07 19:26:55 -080044
45/* QDSP6SS_GFMUX_CTL */
46#define Q6SS_CLK_ENA BIT(1)
47
48/* QDSP6SS_PWR_CTL */
Matt Wagantall11c07e22012-08-09 16:14:07 -070049#define Q6SS_L2DATA_SLP_NRET_N (BIT(0)|BIT(1)|BIT(2))
Matt Wagantallb3fe8992011-12-07 19:26:55 -080050#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 Wagantall3bc2fe52013-01-15 13:34:55 -080056#define QDSS_LDO_BYP BIT(22)
Matt Wagantallb3fe8992011-12-07 19:26:55 -080057
58int pil_q6v5_make_proxy_votes(struct pil_desc *pil)
59{
60 int ret;
Stephen Boyd3826cd42012-07-05 17:37:53 -070061 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -080062
63 ret = clk_prepare_enable(drv->xo);
64 if (ret) {
Matt Wagantall6c515982013-01-29 14:58:43 -080065 dev_err(pil->dev, "Failed to vote for XO\n");
66 goto out;
Matt Wagantallb3fe8992011-12-07 19:26:55 -080067 }
Matt Wagantall6c515982013-01-29 14:58:43 -080068
Matt Wagantall9a8dde42013-02-11 16:18:33 -080069 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 Wagantall6c515982013-01-29 14:58:43 -080083 ret = regulator_enable(drv->vreg_cx);
84 if (ret) {
85 dev_err(pil->dev, "Failed to vote for vdd_cx\n");
Matt Wagantall9a8dde42013-02-11 16:18:33 -080086 goto err_cx_enable;
Matt Wagantall6c515982013-01-29 14:58:43 -080087 }
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 Wagantall9a8dde42013-02-11 16:18:33 -080093 goto err_vreg_pll;
Matt Wagantall6c515982013-01-29 14:58:43 -080094 }
95 }
96
Matt Wagantall9a8dde42013-02-11 16:18:33 -080097 return 0;
98
99err_vreg_pll:
100 regulator_disable(drv->vreg_cx);
101err_cx_enable:
102 regulator_set_optimum_mode(drv->vreg_cx, 0);
103err_cx_mode:
104 regulator_set_voltage(drv->vreg_cx, RPM_REGULATOR_CORNER_NONE,
105 RPM_REGULATOR_CORNER_SUPER_TURBO);
106err_cx_voltage:
107 clk_disable_unprepare(drv->xo);
Matt Wagantall6c515982013-01-29 14:58:43 -0800108out:
109 return ret;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800110}
111EXPORT_SYMBOL(pil_q6v5_make_proxy_votes);
112
113void pil_q6v5_remove_proxy_votes(struct pil_desc *pil)
114{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700115 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantall6c515982013-01-29 14:58:43 -0800116 if (drv->vreg_pll)
117 regulator_disable(drv->vreg_pll);
118 regulator_disable(drv->vreg_cx);
Matt Wagantall9a8dde42013-02-11 16:18:33 -0800119 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 Wagantallb3fe8992011-12-07 19:26:55 -0800122 clk_disable_unprepare(drv->xo);
123}
124EXPORT_SYMBOL(pil_q6v5_remove_proxy_votes);
125
Matt Wagantallb7747992012-05-11 19:37:51 -0700126void 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}
145EXPORT_SYMBOL(pil_q6v5_halt_axi_port);
146
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800147void pil_q6v5_shutdown(struct pil_desc *pil)
148{
149 u32 val;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700150 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800151
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 Wagantallf15e5a32012-12-19 14:41:17 -0800166 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800167
168 /* Assert Q6 resets */
169 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
Matt Wagantall11c07e22012-08-09 16:14:07 -0700170 val = (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800171 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
172
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800173 /* Kill power at block headswitch */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800174 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}
178EXPORT_SYMBOL(pil_q6v5_shutdown);
179
180int pil_q6v5_reset(struct pil_desc *pil)
181{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700182 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800183 u32 val;
184
185 /* Assert resets, stop core */
186 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
Matt Wagantall11c07e22012-08-09 16:14:07 -0700187 val |= (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA | Q6SS_STOP_CORE);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800188 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
189
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800190 /* Enable power block headswitch, and wait for it to stabilize */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800191 val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800192 val |= QDSS_BHS_ON | QDSS_LDO_BYP;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800193 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800194 mb();
195 udelay(1);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800196
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 Wagantall11c07e22012-08-09 16:14:07 -0700209 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
210 val &= ~Q6SS_CORE_ARES;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800211 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}
225EXPORT_SYMBOL(pil_q6v5_reset);
226
Stephen Boyd3826cd42012-07-05 17:37:53 -0700227struct q6v5_data __devinit *pil_q6v5_init(struct platform_device *pdev)
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800228{
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 Wagantallb3fe8992011-12-07 19:26:55 -0800237
Matt Wagantall1f168152012-09-25 13:26:47 -0700238 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6_base");
Stephen Boydf8f89282012-07-16 18:05:48 -0700239 drv->reg_base = devm_request_and_ioremap(&pdev->dev, res);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800240 if (!drv->reg_base)
241 return ERR_PTR(-ENOMEM);
Stephen Boydf8f89282012-07-16 18:05:48 -0700242
Matt Wagantall1f168152012-09-25 13:26:47 -0700243 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "halt_base");
Matt Wagantallb7747992012-05-11 19:37:51 -0700244 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 Wagantallb3fe8992011-12-07 19:26:55 -0800248
Stephen Boyd633eb622012-06-13 12:05:35 -0700249 desc = &drv->desc;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800250 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 Wagantall6c515982013-01-29 14:58:43 -0800259 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 Wagantall6c515982013-01-29 14:58:43 -0800263 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 Wagantallb3fe8992011-12-07 19:26:55 -0800288 desc->dev = &pdev->dev;
289
Stephen Boyd3826cd42012-07-05 17:37:53 -0700290 return drv;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800291}
292EXPORT_SYMBOL(pil_q6v5_init);