1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
/* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/elf.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <mach/msm_iomap.h>
#include "peripheral-loader.h"
#include "scm-pas.h"
#define MARM_BOOT_CONTROL 0x0010
#define MARM_RESET (MSM_CLK_CTL_BASE + 0x2BD4)
#define MAHB0_SFAB_PORT_RESET (MSM_CLK_CTL_BASE + 0x2304)
#define MARM_CLK_BRANCH_ENA_VOTE (MSM_CLK_CTL_BASE + 0x3000)
#define MARM_CLK_SRC0_NS (MSM_CLK_CTL_BASE + 0x2BC0)
#define MARM_CLK_SRC1_NS (MSM_CLK_CTL_BASE + 0x2BC4)
#define MARM_CLK_SRC_CTL (MSM_CLK_CTL_BASE + 0x2BC8)
#define MARM_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BCC)
#define SFAB_MSS_S_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2C00)
#define MSS_MODEM_CXO_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C44)
#define MSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60)
#define MSS_MARM_SYS_REF_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C64)
#define MAHB0_CLK_CTL (MSM_CLK_CTL_BASE + 0x2300)
#define MAHB1_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BE4)
#define MAHB2_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C20)
#define MAHB1_NS (MSM_CLK_CTL_BASE + 0x2BE0)
#define MARM_CLK_FS (MSM_CLK_CTL_BASE + 0x2BD0)
#define MAHB2_CLK_FS (MSM_CLK_CTL_BASE + 0x2C24)
#define PLL_ENA_MARM (MSM_CLK_CTL_BASE + 0x3500)
#define PLL8_STATUS (MSM_CLK_CTL_BASE + 0x3158)
#define CLK_HALT_MSS_SMPSS_MISC_STATE (MSM_CLK_CTL_BASE + 0x2FDC)
struct modem_data {
void __iomem *base;
unsigned long start_addr;
struct pil_device *pil;
struct clk *xo;
};
static int make_modem_proxy_votes(struct pil_desc *pil)
{
int ret;
struct modem_data *drv = dev_get_drvdata(pil->dev);
ret = clk_prepare_enable(drv->xo);
if (ret) {
dev_err(pil->dev, "Failed to enable XO\n");
return ret;
}
return 0;
}
static void remove_modem_proxy_votes(struct pil_desc *pil)
{
struct modem_data *drv = dev_get_drvdata(pil->dev);
clk_disable_unprepare(drv->xo);
}
static int modem_init_image(struct pil_desc *pil, const u8 *metadata,
size_t size)
{
const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata;
struct modem_data *drv = dev_get_drvdata(pil->dev);
drv->start_addr = ehdr->e_entry;
return 0;
}
static int modem_reset(struct pil_desc *pil)
{
u32 reg;
const struct modem_data *drv = dev_get_drvdata(pil->dev);
/* Put modem AHB0,1,2 clocks into reset */
writel_relaxed(BIT(0) | BIT(1), MAHB0_SFAB_PORT_RESET);
writel_relaxed(BIT(7), MAHB1_CLK_CTL);
writel_relaxed(BIT(7), MAHB2_CLK_CTL);
/* Vote for pll8 on behalf of the modem */
reg = readl_relaxed(PLL_ENA_MARM);
reg |= BIT(8);
writel_relaxed(reg, PLL_ENA_MARM);
/* Wait for PLL8 to enable */
while (!(readl_relaxed(PLL8_STATUS) & BIT(16)))
cpu_relax();
/* Set MAHB1 divider to Div-5 to run MAHB1,2 and sfab at 79.8 Mhz*/
writel_relaxed(0x4, MAHB1_NS);
/* Vote for modem AHB1 and 2 clocks to be on on behalf of the modem */
reg = readl_relaxed(MARM_CLK_BRANCH_ENA_VOTE);
reg |= BIT(0) | BIT(1);
writel_relaxed(reg, MARM_CLK_BRANCH_ENA_VOTE);
/* Source marm_clk off of PLL8 */
reg = readl_relaxed(MARM_CLK_SRC_CTL);
if ((reg & 0x1) == 0) {
writel_relaxed(0x3, MARM_CLK_SRC1_NS);
reg |= 0x1;
} else {
writel_relaxed(0x3, MARM_CLK_SRC0_NS);
reg &= ~0x1;
}
writel_relaxed(reg | 0x2, MARM_CLK_SRC_CTL);
/*
* Force core on and periph on signals to remain active during halt
* for marm_clk and mahb2_clk
*/
writel_relaxed(0x6F, MARM_CLK_FS);
writel_relaxed(0x6F, MAHB2_CLK_FS);
/*
* Enable all of the marm_clk branches, cxo sourced marm branches,
* and sleep clock branches
*/
writel_relaxed(0x10, MARM_CLK_CTL);
writel_relaxed(0x10, MAHB0_CLK_CTL);
writel_relaxed(0x10, SFAB_MSS_S_HCLK_CTL);
writel_relaxed(0x10, MSS_MODEM_CXO_CLK_CTL);
writel_relaxed(0x10, MSS_SLP_CLK_CTL);
writel_relaxed(0x10, MSS_MARM_SYS_REF_CLK_CTL);
/* Wait for above clocks to be turned on */
while (readl_relaxed(CLK_HALT_MSS_SMPSS_MISC_STATE) & (BIT(7) | BIT(8) |
BIT(9) | BIT(10) | BIT(4) | BIT(6)))
cpu_relax();
/* Take MAHB0,1,2 clocks out of reset */
writel_relaxed(0x0, MAHB2_CLK_CTL);
writel_relaxed(0x0, MAHB1_CLK_CTL);
writel_relaxed(0x0, MAHB0_SFAB_PORT_RESET);
mb();
/* Setup exception vector table base address */
writel_relaxed(drv->start_addr | 0x1, drv->base + MARM_BOOT_CONTROL);
/* Wait for vector table to be setup */
mb();
/* Bring modem out of reset */
writel_relaxed(0x0, MARM_RESET);
return 0;
}
static int modem_shutdown(struct pil_desc *pil)
{
u32 reg;
/* Put modem into reset */
writel_relaxed(0x1, MARM_RESET);
mb();
/* Put modem AHB0,1,2 clocks into reset */
writel_relaxed(BIT(0) | BIT(1), MAHB0_SFAB_PORT_RESET);
writel_relaxed(BIT(7), MAHB1_CLK_CTL);
writel_relaxed(BIT(7), MAHB2_CLK_CTL);
mb();
/*
* Disable all of the marm_clk branches, cxo sourced marm branches,
* and sleep clock branches
*/
writel_relaxed(0x0, MARM_CLK_CTL);
writel_relaxed(0x0, MAHB0_CLK_CTL);
writel_relaxed(0x0, SFAB_MSS_S_HCLK_CTL);
writel_relaxed(0x0, MSS_MODEM_CXO_CLK_CTL);
writel_relaxed(0x0, MSS_SLP_CLK_CTL);
writel_relaxed(0x0, MSS_MARM_SYS_REF_CLK_CTL);
/* Disable marm_clk */
reg = readl_relaxed(MARM_CLK_SRC_CTL);
reg &= ~0x2;
writel_relaxed(reg, MARM_CLK_SRC_CTL);
/* Clear modem's votes for ahb clocks */
writel_relaxed(0x0, MARM_CLK_BRANCH_ENA_VOTE);
/* Clear modem's votes for PLLs */
writel_relaxed(0x0, PLL_ENA_MARM);
return 0;
}
static struct pil_reset_ops pil_modem_ops = {
.init_image = modem_init_image,
.auth_and_reset = modem_reset,
.shutdown = modem_shutdown,
.proxy_vote = make_modem_proxy_votes,
.proxy_unvote = remove_modem_proxy_votes,
};
static int modem_init_image_trusted(struct pil_desc *pil, const u8 *metadata,
size_t size)
{
return pas_init_image(PAS_MODEM, metadata, size);
}
static int modem_reset_trusted(struct pil_desc *pil)
{
return pas_auth_and_reset(PAS_MODEM);
}
static int modem_shutdown_trusted(struct pil_desc *pil)
{
return pas_shutdown(PAS_MODEM);
}
static struct pil_reset_ops pil_modem_ops_trusted = {
.init_image = modem_init_image_trusted,
.auth_and_reset = modem_reset_trusted,
.shutdown = modem_shutdown_trusted,
.proxy_vote = make_modem_proxy_votes,
.proxy_unvote = remove_modem_proxy_votes,
};
static int __devinit pil_modem_driver_probe(struct platform_device *pdev)
{
struct modem_data *drv;
struct resource *res;
struct pil_desc *desc;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -EINVAL;
drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
if (!drv)
return -ENOMEM;
platform_set_drvdata(pdev, drv);
drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
if (!drv->base)
return -ENOMEM;
drv->xo = devm_clk_get(&pdev->dev, "xo");
if (IS_ERR(drv->xo))
return PTR_ERR(drv->xo);
desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
if (!desc)
return -ENOMEM;
desc->name = "modem";
desc->depends_on = "q6";
desc->dev = &pdev->dev;
desc->owner = THIS_MODULE;
desc->proxy_timeout = 10000;
if (pas_supported(PAS_MODEM) > 0) {
desc->ops = &pil_modem_ops_trusted;
dev_info(&pdev->dev, "using secure boot\n");
} else {
desc->ops = &pil_modem_ops;
dev_info(&pdev->dev, "using non-secure boot\n");
}
drv->pil = msm_pil_register(desc);
if (IS_ERR(drv->pil)) {
return PTR_ERR(drv->pil);
}
return 0;
}
static int __devexit pil_modem_driver_exit(struct platform_device *pdev)
{
struct modem_data *drv = platform_get_drvdata(pdev);
msm_pil_unregister(drv->pil);
return 0;
}
static struct platform_driver pil_modem_driver = {
.probe = pil_modem_driver_probe,
.remove = __devexit_p(pil_modem_driver_exit),
.driver = {
.name = "pil_modem",
.owner = THIS_MODULE,
},
};
static int __init pil_modem_init(void)
{
return platform_driver_register(&pil_modem_driver);
}
module_init(pil_modem_init);
static void __exit pil_modem_exit(void)
{
platform_driver_unregister(&pil_modem_driver);
}
module_exit(pil_modem_exit);
MODULE_DESCRIPTION("Support for booting modem processors");
MODULE_LICENSE("GPL v2");
|