blob: c6add8fbf75053b5f04af182c2dcc96f20329014 [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 Wagantalld4aaa152013-04-18 20:31:47 -070049#define Q6SS_L2DATA_SLP_NRET_N_0 BIT(0)
50#define Q6SS_L2DATA_SLP_NRET_N_1 BIT(1)
51#define Q6SS_L2DATA_SLP_NRET_N_2 BIT(2)
Matt Wagantallb3fe8992011-12-07 19:26:55 -080052#define Q6SS_L2TAG_SLP_NRET_N BIT(16)
53#define Q6SS_ETB_SLP_NRET_N BIT(17)
54#define Q6SS_L2DATA_STBY_N BIT(18)
55#define Q6SS_SLP_RET_N BIT(19)
56#define Q6SS_CLAMP_IO BIT(20)
57#define QDSS_BHS_ON BIT(21)
Matt Wagantall3bc2fe52013-01-15 13:34:55 -080058#define QDSS_LDO_BYP BIT(22)
Matt Wagantallb3fe8992011-12-07 19:26:55 -080059
60int pil_q6v5_make_proxy_votes(struct pil_desc *pil)
61{
62 int ret;
Stephen Boyd3826cd42012-07-05 17:37:53 -070063 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -080064
65 ret = clk_prepare_enable(drv->xo);
66 if (ret) {
Matt Wagantall6c515982013-01-29 14:58:43 -080067 dev_err(pil->dev, "Failed to vote for XO\n");
68 goto out;
Matt Wagantallb3fe8992011-12-07 19:26:55 -080069 }
Matt Wagantall6c515982013-01-29 14:58:43 -080070
Matt Wagantall9a8dde42013-02-11 16:18:33 -080071 ret = regulator_set_voltage(drv->vreg_cx,
72 RPM_REGULATOR_CORNER_SUPER_TURBO,
73 RPM_REGULATOR_CORNER_SUPER_TURBO);
74 if (ret) {
75 dev_err(pil->dev, "Failed to request vdd_cx voltage.\n");
76 goto err_cx_voltage;
77 }
78
79 ret = regulator_set_optimum_mode(drv->vreg_cx, 100000);
80 if (ret < 0) {
81 dev_err(pil->dev, "Failed to set vdd_cx mode.\n");
82 goto err_cx_mode;
83 }
84
Matt Wagantall6c515982013-01-29 14:58:43 -080085 ret = regulator_enable(drv->vreg_cx);
86 if (ret) {
87 dev_err(pil->dev, "Failed to vote for vdd_cx\n");
Matt Wagantall9a8dde42013-02-11 16:18:33 -080088 goto err_cx_enable;
Matt Wagantall6c515982013-01-29 14:58:43 -080089 }
90
91 if (drv->vreg_pll) {
92 ret = regulator_enable(drv->vreg_pll);
93 if (ret) {
94 dev_err(pil->dev, "Failed to vote for vdd_pll\n");
Matt Wagantall9a8dde42013-02-11 16:18:33 -080095 goto err_vreg_pll;
Matt Wagantall6c515982013-01-29 14:58:43 -080096 }
97 }
98
Matt Wagantall9a8dde42013-02-11 16:18:33 -080099 return 0;
100
101err_vreg_pll:
102 regulator_disable(drv->vreg_cx);
103err_cx_enable:
104 regulator_set_optimum_mode(drv->vreg_cx, 0);
105err_cx_mode:
106 regulator_set_voltage(drv->vreg_cx, RPM_REGULATOR_CORNER_NONE,
107 RPM_REGULATOR_CORNER_SUPER_TURBO);
108err_cx_voltage:
109 clk_disable_unprepare(drv->xo);
Matt Wagantall6c515982013-01-29 14:58:43 -0800110out:
111 return ret;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800112}
113EXPORT_SYMBOL(pil_q6v5_make_proxy_votes);
114
115void pil_q6v5_remove_proxy_votes(struct pil_desc *pil)
116{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700117 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantall6c515982013-01-29 14:58:43 -0800118 if (drv->vreg_pll)
119 regulator_disable(drv->vreg_pll);
120 regulator_disable(drv->vreg_cx);
Matt Wagantall9a8dde42013-02-11 16:18:33 -0800121 regulator_set_optimum_mode(drv->vreg_cx, 0);
122 regulator_set_voltage(drv->vreg_cx, RPM_REGULATOR_CORNER_NONE,
123 RPM_REGULATOR_CORNER_SUPER_TURBO);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800124 clk_disable_unprepare(drv->xo);
125}
126EXPORT_SYMBOL(pil_q6v5_remove_proxy_votes);
127
Matt Wagantallb7747992012-05-11 19:37:51 -0700128void pil_q6v5_halt_axi_port(struct pil_desc *pil, void __iomem *halt_base)
129{
130 int ret;
131 u32 status;
132
133 /* Assert halt request */
134 writel_relaxed(1, halt_base + AXI_HALTREQ);
135
136 /* Wait for halt */
137 ret = readl_poll_timeout(halt_base + AXI_HALTACK,
138 status, status != 0, 50, HALT_ACK_TIMEOUT_US);
139 if (ret)
140 dev_warn(pil->dev, "Port %p halt timeout\n", halt_base);
141 else if (!readl_relaxed(halt_base + AXI_IDLE))
142 dev_warn(pil->dev, "Port %p halt failed\n", halt_base);
143
144 /* Clear halt request (port will remain halted until reset) */
145 writel_relaxed(0, halt_base + AXI_HALTREQ);
146}
147EXPORT_SYMBOL(pil_q6v5_halt_axi_port);
148
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800149void pil_q6v5_shutdown(struct pil_desc *pil)
150{
151 u32 val;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700152 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800153
154 /* Turn off core clock */
155 val = readl_relaxed(drv->reg_base + QDSP6SS_GFMUX_CTL);
156 val &= ~Q6SS_CLK_ENA;
157 writel_relaxed(val, drv->reg_base + QDSP6SS_GFMUX_CTL);
158
159 /* Clamp IO */
160 val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL);
161 val |= Q6SS_CLAMP_IO;
162 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
163
164 /* Turn off Q6 memories */
Matt Wagantalld4aaa152013-04-18 20:31:47 -0700165 val &= ~(Q6SS_L2DATA_SLP_NRET_N_0 | Q6SS_L2DATA_SLP_NRET_N_1 |
166 Q6SS_L2DATA_SLP_NRET_N_2 | Q6SS_SLP_RET_N |
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800167 Q6SS_L2TAG_SLP_NRET_N | Q6SS_ETB_SLP_NRET_N |
168 Q6SS_L2DATA_STBY_N);
Matt Wagantallf15e5a32012-12-19 14:41:17 -0800169 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800170
171 /* Assert Q6 resets */
172 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
Matt Wagantall75d17402013-02-21 15:00:48 -0800173 val |= (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800174 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
175
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800176 /* Kill power at block headswitch */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800177 val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL);
178 val &= ~QDSS_BHS_ON;
179 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
180}
181EXPORT_SYMBOL(pil_q6v5_shutdown);
182
183int pil_q6v5_reset(struct pil_desc *pil)
184{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700185 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800186 u32 val;
187
188 /* Assert resets, stop core */
189 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
Matt Wagantall11c07e22012-08-09 16:14:07 -0700190 val |= (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA | Q6SS_STOP_CORE);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800191 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
192
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800193 /* Enable power block headswitch, and wait for it to stabilize */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800194 val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800195 val |= QDSS_BHS_ON | QDSS_LDO_BYP;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800196 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800197 mb();
198 udelay(1);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800199
Matt Wagantalld4aaa152013-04-18 20:31:47 -0700200 /*
201 * Turn on memories. L2 banks should be done individually
202 * to minimize inrush current.
203 */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800204 val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantalld4aaa152013-04-18 20:31:47 -0700205 val |= Q6SS_SLP_RET_N | Q6SS_L2TAG_SLP_NRET_N |
206 Q6SS_ETB_SLP_NRET_N | Q6SS_L2DATA_STBY_N;
207 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
208 val |= Q6SS_L2DATA_SLP_NRET_N_2;
209 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
210 val |= Q6SS_L2DATA_SLP_NRET_N_1;
211 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
212 val |= Q6SS_L2DATA_SLP_NRET_N_0;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800213 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
214
215 /* Remove IO clamp */
216 val &= ~Q6SS_CLAMP_IO;
217 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
218
219 /* Bring core out of reset */
Matt Wagantall11c07e22012-08-09 16:14:07 -0700220 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
221 val &= ~Q6SS_CORE_ARES;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800222 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
223
224 /* Turn on core clock */
225 val = readl_relaxed(drv->reg_base + QDSP6SS_GFMUX_CTL);
226 val |= Q6SS_CLK_ENA;
227 writel_relaxed(val, drv->reg_base + QDSP6SS_GFMUX_CTL);
228
229 /* Start core execution */
230 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
231 val &= ~Q6SS_STOP_CORE;
232 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
233
234 return 0;
235}
236EXPORT_SYMBOL(pil_q6v5_reset);
237
Stephen Boyd3826cd42012-07-05 17:37:53 -0700238struct q6v5_data __devinit *pil_q6v5_init(struct platform_device *pdev)
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800239{
240 struct q6v5_data *drv;
241 struct resource *res;
242 struct pil_desc *desc;
243 int ret;
244
245 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
246 if (!drv)
247 return ERR_PTR(-ENOMEM);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800248
Matt Wagantall1f168152012-09-25 13:26:47 -0700249 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6_base");
Stephen Boydf8f89282012-07-16 18:05:48 -0700250 drv->reg_base = devm_request_and_ioremap(&pdev->dev, res);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800251 if (!drv->reg_base)
252 return ERR_PTR(-ENOMEM);
Stephen Boydf8f89282012-07-16 18:05:48 -0700253
Matt Wagantall1f168152012-09-25 13:26:47 -0700254 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "halt_base");
Matt Wagantallb7747992012-05-11 19:37:51 -0700255 drv->axi_halt_base = devm_ioremap(&pdev->dev, res->start,
256 resource_size(res));
257 if (!drv->axi_halt_base)
258 return ERR_PTR(-ENOMEM);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800259
Stephen Boyd633eb622012-06-13 12:05:35 -0700260 desc = &drv->desc;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800261 ret = of_property_read_string(pdev->dev.of_node, "qcom,firmware-name",
262 &desc->name);
263 if (ret)
264 return ERR_PTR(ret);
265
266 drv->xo = devm_clk_get(&pdev->dev, "xo");
267 if (IS_ERR(drv->xo))
268 return ERR_CAST(drv->xo);
269
Matt Wagantall6c515982013-01-29 14:58:43 -0800270 drv->vreg_cx = devm_regulator_get(&pdev->dev, "vdd_cx");
271 if (IS_ERR(drv->vreg_cx))
272 return ERR_CAST(drv->vreg_cx);
273
Matt Wagantall6c515982013-01-29 14:58:43 -0800274 drv->vreg_pll = devm_regulator_get(&pdev->dev, "vdd_pll");
275 if (!IS_ERR(drv->vreg_pll)) {
276 int voltage;
277 ret = of_property_read_u32(pdev->dev.of_node, "qcom,vdd_pll",
278 &voltage);
279 if (ret) {
280 dev_err(&pdev->dev, "Failed to find vdd_pll voltage.\n");
281 return ERR_PTR(ret);
282 }
283
284 ret = regulator_set_voltage(drv->vreg_pll, voltage, voltage);
285 if (ret) {
286 dev_err(&pdev->dev, "Failed to request vdd_pll voltage.\n");
287 return ERR_PTR(ret);
288 }
289
290 ret = regulator_set_optimum_mode(drv->vreg_pll, 10000);
291 if (ret < 0) {
292 dev_err(&pdev->dev, "Failed to set vdd_pll mode.\n");
293 return ERR_PTR(ret);
294 }
295 } else {
296 drv->vreg_pll = NULL;
297 }
298
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800299 desc->dev = &pdev->dev;
300
Stephen Boyd3826cd42012-07-05 17:37:53 -0700301 return drv;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800302}
303EXPORT_SYMBOL(pil_q6v5_init);