blob: 31bb8115870dc16ead7de8861ab77b7292028ff2 [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
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
85out:
86 return ret;
Matt Wagantallb3fe8992011-12-07 19:26:55 -080087}
88EXPORT_SYMBOL(pil_q6v5_make_proxy_votes);
89
90void pil_q6v5_remove_proxy_votes(struct pil_desc *pil)
91{
Stephen Boyd3826cd42012-07-05 17:37:53 -070092 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantall6c515982013-01-29 14:58:43 -080093 if (drv->vreg_pll)
94 regulator_disable(drv->vreg_pll);
95 regulator_disable(drv->vreg_cx);
Matt Wagantallb3fe8992011-12-07 19:26:55 -080096 clk_disable_unprepare(drv->xo);
97}
98EXPORT_SYMBOL(pil_q6v5_remove_proxy_votes);
99
Matt Wagantallb7747992012-05-11 19:37:51 -0700100void 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}
119EXPORT_SYMBOL(pil_q6v5_halt_axi_port);
120
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800121void pil_q6v5_shutdown(struct pil_desc *pil)
122{
123 u32 val;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700124 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800125
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 Wagantallf15e5a32012-12-19 14:41:17 -0800140 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800141
142 /* Assert Q6 resets */
143 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
Matt Wagantall11c07e22012-08-09 16:14:07 -0700144 val = (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800145 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
146
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800147 /* Kill power at block headswitch */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800148 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}
152EXPORT_SYMBOL(pil_q6v5_shutdown);
153
154int pil_q6v5_reset(struct pil_desc *pil)
155{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700156 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800157 u32 val;
158
159 /* Assert resets, stop core */
160 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
Matt Wagantall11c07e22012-08-09 16:14:07 -0700161 val |= (Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENA | Q6SS_STOP_CORE);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800162 writel_relaxed(val, drv->reg_base + QDSP6SS_RESET);
163
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800164 /* Enable power block headswitch, and wait for it to stabilize */
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800165 val = readl_relaxed(drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800166 val |= QDSS_BHS_ON | QDSS_LDO_BYP;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800167 writel_relaxed(val, drv->reg_base + QDSP6SS_PWR_CTL);
Matt Wagantall3bc2fe52013-01-15 13:34:55 -0800168 mb();
169 udelay(1);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800170
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 Wagantall11c07e22012-08-09 16:14:07 -0700183 val = readl_relaxed(drv->reg_base + QDSP6SS_RESET);
184 val &= ~Q6SS_CORE_ARES;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800185 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}
199EXPORT_SYMBOL(pil_q6v5_reset);
200
Stephen Boyd3826cd42012-07-05 17:37:53 -0700201struct q6v5_data __devinit *pil_q6v5_init(struct platform_device *pdev)
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800202{
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 Wagantallb3fe8992011-12-07 19:26:55 -0800211
Matt Wagantall1f168152012-09-25 13:26:47 -0700212 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6_base");
Stephen Boydf8f89282012-07-16 18:05:48 -0700213 drv->reg_base = devm_request_and_ioremap(&pdev->dev, res);
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800214 if (!drv->reg_base)
215 return ERR_PTR(-ENOMEM);
Stephen Boydf8f89282012-07-16 18:05:48 -0700216
Matt Wagantall1f168152012-09-25 13:26:47 -0700217 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "halt_base");
Matt Wagantallb7747992012-05-11 19:37:51 -0700218 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 Wagantallb3fe8992011-12-07 19:26:55 -0800222
Stephen Boyd633eb622012-06-13 12:05:35 -0700223 desc = &drv->desc;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800224 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 Wagantall6c515982013-01-29 14:58:43 -0800233 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 Wagantallb3fe8992011-12-07 19:26:55 -0800276 desc->dev = &pdev->dev;
277
Stephen Boyd3826cd42012-07-05 17:37:53 -0700278 return drv;
Matt Wagantallb3fe8992011-12-07 19:26:55 -0800279}
280EXPORT_SYMBOL(pil_q6v5_init);