blob: 4802ab170fe51a57fb83f962bbf6f8a4b7936717 [file] [log] [blame]
Thomas Gleixner97fb5e82019-05-29 07:17:58 -07001// SPDX-License-Identifier: GPL-2.0-only
Paul Gortmakerdea852422016-07-04 11:01:56 -04002/*
3 * Qualcomm SCM driver
4 *
5 * Copyright (c) 2010,2015, The Linux Foundation. All rights reserved.
Lina Iyer2ce76a62015-03-02 16:30:29 -07006 * Copyright (C) 2015 Linaro Ltd.
Stephen Boyd2a1eb582010-08-27 10:01:23 -07007 */
Andy Grossd0f6fa72016-06-03 18:25:22 -05008#include <linux/platform_device.h>
Paul Gortmakerdea852422016-07-04 11:01:56 -04009#include <linux/init.h>
Kumar Galab6a1dfb2015-03-11 16:28:10 -050010#include <linux/cpumask.h>
11#include <linux/export.h>
Stephen Boyd6e37ccf2019-05-17 14:09:21 -070012#include <linux/dma-direct.h>
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -070013#include <linux/dma-mapping.h>
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -070014#include <linux/module.h>
Kumar Galab6a1dfb2015-03-11 16:28:10 -050015#include <linux/types.h>
Kumar Gala916f7432015-02-26 15:49:09 -060016#include <linux/qcom_scm.h>
Andy Grossd0f6fa72016-06-03 18:25:22 -050017#include <linux/of.h>
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -070018#include <linux/of_address.h>
Andy Grossd0f6fa72016-06-03 18:25:22 -050019#include <linux/of_platform.h>
20#include <linux/clk.h>
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -070021#include <linux/reset-controller.h>
Stephen Boyd2a1eb582010-08-27 10:01:23 -070022
Kumar Galab6a1dfb2015-03-11 16:28:10 -050023#include "qcom_scm.h"
Lina Iyera353e4a2015-03-02 16:30:28 -070024
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -070025static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT);
26module_param(download_mode, bool, 0);
27
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -080028#define SCM_HAS_CORE_CLK BIT(0)
29#define SCM_HAS_IFACE_CLK BIT(1)
30#define SCM_HAS_BUS_CLK BIT(2)
31
Andy Grossd0f6fa72016-06-03 18:25:22 -050032struct qcom_scm {
33 struct device *dev;
34 struct clk *core_clk;
35 struct clk *iface_clk;
36 struct clk *bus_clk;
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -070037 struct reset_controller_dev reset;
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -070038
39 u64 dload_mode_addr;
Andy Grossd0f6fa72016-06-03 18:25:22 -050040};
41
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +053042struct qcom_scm_current_perm_info {
43 __le32 vmid;
44 __le32 perm;
45 __le64 ctx;
46 __le32 ctx_size;
47 __le32 unused;
48};
49
50struct qcom_scm_mem_map_info {
51 __le64 mem_addr;
52 __le64 mem_size;
53};
54
Andy Grossd0f6fa72016-06-03 18:25:22 -050055static struct qcom_scm *__scm;
56
57static int qcom_scm_clk_enable(void)
58{
59 int ret;
60
61 ret = clk_prepare_enable(__scm->core_clk);
62 if (ret)
63 goto bail;
64
65 ret = clk_prepare_enable(__scm->iface_clk);
66 if (ret)
67 goto disable_core;
68
69 ret = clk_prepare_enable(__scm->bus_clk);
70 if (ret)
71 goto disable_iface;
72
73 return 0;
74
75disable_iface:
76 clk_disable_unprepare(__scm->iface_clk);
77disable_core:
78 clk_disable_unprepare(__scm->core_clk);
79bail:
80 return ret;
81}
82
83static void qcom_scm_clk_disable(void)
84{
85 clk_disable_unprepare(__scm->core_clk);
86 clk_disable_unprepare(__scm->iface_clk);
87 clk_disable_unprepare(__scm->bus_clk);
88}
89
Lina Iyera353e4a2015-03-02 16:30:28 -070090/**
91 * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus
92 * @entry: Entry point function for the cpus
93 * @cpus: The cpumask of cpus that will use the entry point
94 *
95 * Set the cold boot address of the cpus. Any cpu outside the supported
96 * range would be removed from the cpu present mask.
97 */
98int qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus)
99{
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500100 return __qcom_scm_set_cold_boot_addr(entry, cpus);
Lina Iyera353e4a2015-03-02 16:30:28 -0700101}
102EXPORT_SYMBOL(qcom_scm_set_cold_boot_addr);
Lina Iyer2ce76a62015-03-02 16:30:29 -0700103
104/**
105 * qcom_scm_set_warm_boot_addr() - Set the warm boot address for cpus
106 * @entry: Entry point function for the cpus
107 * @cpus: The cpumask of cpus that will use the entry point
108 *
109 * Set the Linux entry point for the SCM to transfer control to when coming
110 * out of a power down. CPU power down may be executed on cpuidle or hotplug.
111 */
112int qcom_scm_set_warm_boot_addr(void *entry, const cpumask_t *cpus)
113{
Andy Gross16e59462016-06-03 18:25:25 -0500114 return __qcom_scm_set_warm_boot_addr(__scm->dev, entry, cpus);
Lina Iyer2ce76a62015-03-02 16:30:29 -0700115}
116EXPORT_SYMBOL(qcom_scm_set_warm_boot_addr);
Lina Iyer767b0232015-03-02 16:30:30 -0700117
Lina Iyer767b0232015-03-02 16:30:30 -0700118/**
119 * qcom_scm_cpu_power_down() - Power down the cpu
120 * @flags - Flags to flush cache
121 *
122 * This is an end point to power down cpu. If there was a pending interrupt,
123 * the control would return from this function, otherwise, the cpu jumps to the
124 * warm boot entry point set for this cpu upon reset.
125 */
126void qcom_scm_cpu_power_down(u32 flags)
127{
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500128 __qcom_scm_cpu_power_down(flags);
Lina Iyer767b0232015-03-02 16:30:30 -0700129}
130EXPORT_SYMBOL(qcom_scm_cpu_power_down);
jilai wang9626b692015-04-10 16:15:59 -0400131
132/**
133 * qcom_scm_hdcp_available() - Check if secure environment supports HDCP.
134 *
135 * Return true if HDCP is supported, false if not.
136 */
137bool qcom_scm_hdcp_available(void)
138{
Andy Grossd0f6fa72016-06-03 18:25:22 -0500139 int ret = qcom_scm_clk_enable();
140
141 if (ret)
142 return ret;
jilai wang9626b692015-04-10 16:15:59 -0400143
Andy Gross16e59462016-06-03 18:25:25 -0500144 ret = __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_HDCP,
Andy Grossd0f6fa72016-06-03 18:25:22 -0500145 QCOM_SCM_CMD_HDCP);
jilai wang9626b692015-04-10 16:15:59 -0400146
Andy Grossd0f6fa72016-06-03 18:25:22 -0500147 qcom_scm_clk_disable();
148
149 return ret > 0 ? true : false;
jilai wang9626b692015-04-10 16:15:59 -0400150}
151EXPORT_SYMBOL(qcom_scm_hdcp_available);
152
153/**
154 * qcom_scm_hdcp_req() - Send HDCP request.
155 * @req: HDCP request array
156 * @req_cnt: HDCP request array count
157 * @resp: response buffer passed to SCM
158 *
159 * Write HDCP register(s) through SCM.
160 */
161int qcom_scm_hdcp_req(struct qcom_scm_hdcp_req *req, u32 req_cnt, u32 *resp)
162{
Andy Grossd0f6fa72016-06-03 18:25:22 -0500163 int ret = qcom_scm_clk_enable();
164
165 if (ret)
166 return ret;
167
Andy Gross16e59462016-06-03 18:25:25 -0500168 ret = __qcom_scm_hdcp_req(__scm->dev, req, req_cnt, resp);
Andy Grossd0f6fa72016-06-03 18:25:22 -0500169 qcom_scm_clk_disable();
170 return ret;
jilai wang9626b692015-04-10 16:15:59 -0400171}
172EXPORT_SYMBOL(qcom_scm_hdcp_req);
Andy Grossd0f6fa72016-06-03 18:25:22 -0500173
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700174/**
175 * qcom_scm_pas_supported() - Check if the peripheral authentication service is
176 * available for the given peripherial
177 * @peripheral: peripheral id
178 *
179 * Returns true if PAS is supported for this peripheral, otherwise false.
180 */
181bool qcom_scm_pas_supported(u32 peripheral)
182{
183 int ret;
184
185 ret = __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_PIL,
186 QCOM_SCM_PAS_IS_SUPPORTED_CMD);
187 if (ret <= 0)
188 return false;
189
190 return __qcom_scm_pas_supported(__scm->dev, peripheral);
191}
192EXPORT_SYMBOL(qcom_scm_pas_supported);
193
194/**
195 * qcom_scm_pas_init_image() - Initialize peripheral authentication service
196 * state machine for a given peripheral, using the
197 * metadata
198 * @peripheral: peripheral id
199 * @metadata: pointer to memory containing ELF header, program header table
200 * and optional blob of data used for authenticating the metadata
201 * and the rest of the firmware
202 * @size: size of the metadata
203 *
204 * Returns 0 on success.
205 */
206int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size)
207{
208 dma_addr_t mdata_phys;
209 void *mdata_buf;
210 int ret;
211
212 /*
213 * During the scm call memory protection will be enabled for the meta
214 * data blob, so make sure it's physically contiguous, 4K aligned and
215 * non-cachable to avoid XPU violations.
216 */
217 mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys,
218 GFP_KERNEL);
219 if (!mdata_buf) {
220 dev_err(__scm->dev, "Allocation of metadata buffer failed.\n");
221 return -ENOMEM;
222 }
223 memcpy(mdata_buf, metadata, size);
224
225 ret = qcom_scm_clk_enable();
226 if (ret)
227 goto free_metadata;
228
229 ret = __qcom_scm_pas_init_image(__scm->dev, peripheral, mdata_phys);
230
231 qcom_scm_clk_disable();
232
233free_metadata:
234 dma_free_coherent(__scm->dev, size, mdata_buf, mdata_phys);
235
236 return ret;
237}
238EXPORT_SYMBOL(qcom_scm_pas_init_image);
239
240/**
241 * qcom_scm_pas_mem_setup() - Prepare the memory related to a given peripheral
242 * for firmware loading
243 * @peripheral: peripheral id
244 * @addr: start address of memory area to prepare
245 * @size: size of the memory area to prepare
246 *
247 * Returns 0 on success.
248 */
249int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, phys_addr_t size)
250{
251 int ret;
252
253 ret = qcom_scm_clk_enable();
254 if (ret)
255 return ret;
256
257 ret = __qcom_scm_pas_mem_setup(__scm->dev, peripheral, addr, size);
258 qcom_scm_clk_disable();
259
260 return ret;
261}
262EXPORT_SYMBOL(qcom_scm_pas_mem_setup);
263
264/**
265 * qcom_scm_pas_auth_and_reset() - Authenticate the given peripheral firmware
266 * and reset the remote processor
267 * @peripheral: peripheral id
268 *
269 * Return 0 on success.
270 */
271int qcom_scm_pas_auth_and_reset(u32 peripheral)
272{
273 int ret;
274
275 ret = qcom_scm_clk_enable();
276 if (ret)
277 return ret;
278
279 ret = __qcom_scm_pas_auth_and_reset(__scm->dev, peripheral);
280 qcom_scm_clk_disable();
281
282 return ret;
283}
284EXPORT_SYMBOL(qcom_scm_pas_auth_and_reset);
285
286/**
287 * qcom_scm_pas_shutdown() - Shut down the remote processor
288 * @peripheral: peripheral id
289 *
290 * Returns 0 on success.
291 */
292int qcom_scm_pas_shutdown(u32 peripheral)
293{
294 int ret;
295
296 ret = qcom_scm_clk_enable();
297 if (ret)
298 return ret;
299
300 ret = __qcom_scm_pas_shutdown(__scm->dev, peripheral);
301 qcom_scm_clk_disable();
302
303 return ret;
304}
305EXPORT_SYMBOL(qcom_scm_pas_shutdown);
306
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700307static int qcom_scm_pas_reset_assert(struct reset_controller_dev *rcdev,
308 unsigned long idx)
309{
310 if (idx != 0)
311 return -EINVAL;
312
313 return __qcom_scm_pas_mss_reset(__scm->dev, 1);
314}
315
316static int qcom_scm_pas_reset_deassert(struct reset_controller_dev *rcdev,
317 unsigned long idx)
318{
319 if (idx != 0)
320 return -EINVAL;
321
322 return __qcom_scm_pas_mss_reset(__scm->dev, 0);
323}
324
325static const struct reset_control_ops qcom_scm_pas_reset_ops = {
326 .assert = qcom_scm_pas_reset_assert,
327 .deassert = qcom_scm_pas_reset_deassert,
328};
329
Rob Clarka2c680c2017-03-14 11:18:03 -0400330int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare)
331{
332 return __qcom_scm_restore_sec_cfg(__scm->dev, device_id, spare);
333}
334EXPORT_SYMBOL(qcom_scm_restore_sec_cfg);
335
Stanimir Varbanovb182cc42017-03-14 11:18:04 -0400336int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size)
337{
338 return __qcom_scm_iommu_secure_ptbl_size(__scm->dev, spare, size);
339}
340EXPORT_SYMBOL(qcom_scm_iommu_secure_ptbl_size);
341
342int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare)
343{
344 return __qcom_scm_iommu_secure_ptbl_init(__scm->dev, addr, size, spare);
345}
346EXPORT_SYMBOL(qcom_scm_iommu_secure_ptbl_init);
347
Bjorn Andersson4e659db2017-08-14 15:46:17 -0700348int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val)
349{
350 return __qcom_scm_io_readl(__scm->dev, addr, val);
351}
352EXPORT_SYMBOL(qcom_scm_io_readl);
353
354int qcom_scm_io_writel(phys_addr_t addr, unsigned int val)
355{
356 return __qcom_scm_io_writel(__scm->dev, addr, val);
357}
358EXPORT_SYMBOL(qcom_scm_io_writel);
359
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700360static void qcom_scm_set_download_mode(bool enable)
361{
362 bool avail;
363 int ret = 0;
364
365 avail = __qcom_scm_is_call_available(__scm->dev,
366 QCOM_SCM_SVC_BOOT,
367 QCOM_SCM_SET_DLOAD_MODE);
368 if (avail) {
369 ret = __qcom_scm_set_dload_mode(__scm->dev, enable);
370 } else if (__scm->dload_mode_addr) {
371 ret = __qcom_scm_io_writel(__scm->dev, __scm->dload_mode_addr,
372 enable ? QCOM_SCM_SET_DLOAD_MODE : 0);
373 } else {
374 dev_err(__scm->dev,
375 "No available mechanism for setting download mode\n");
376 }
377
378 if (ret)
379 dev_err(__scm->dev, "failed to set download mode: %d\n", ret);
380}
381
382static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
383{
384 struct device_node *tcsr;
385 struct device_node *np = dev->of_node;
386 struct resource res;
387 u32 offset;
388 int ret;
389
390 tcsr = of_parse_phandle(np, "qcom,dload-mode", 0);
391 if (!tcsr)
392 return 0;
393
394 ret = of_address_to_resource(tcsr, 0, &res);
395 of_node_put(tcsr);
396 if (ret)
397 return ret;
398
399 ret = of_property_read_u32_index(np, "qcom,dload-mode", 1, &offset);
400 if (ret < 0)
401 return ret;
402
403 *addr = res.start + offset;
404
405 return 0;
406}
407
Andy Gross72d43412016-06-29 15:28:29 -0500408/**
409 * qcom_scm_is_available() - Checks if SCM is available
410 */
411bool qcom_scm_is_available(void)
412{
413 return !!__scm;
414}
415EXPORT_SYMBOL(qcom_scm_is_available);
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700416
Andy Grossa811b422017-01-16 23:24:15 -0600417int qcom_scm_set_remote_state(u32 state, u32 id)
418{
419 return __qcom_scm_set_remote_state(__scm->dev, state, id);
420}
421EXPORT_SYMBOL(qcom_scm_set_remote_state);
422
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530423/**
424 * qcom_scm_assign_mem() - Make a secure call to reassign memory ownership
425 * @mem_addr: mem region whose ownership need to be reassigned
426 * @mem_sz: size of the region.
427 * @srcvm: vmid for current set of owners, each set bit in
428 * flag indicate a unique owner
Stephen Boydc8b08fc2019-05-17 14:09:23 -0700429 * @newvm: array having new owners and corresponding permission
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530430 * flags
431 * @dest_cnt: number of owners in next set.
432 *
Stephen Boydc8b08fc2019-05-17 14:09:23 -0700433 * Return negative errno on failure or 0 on success with @srcvm updated.
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530434 */
435int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,
436 unsigned int *srcvm,
Stephen Boydaf311ff2019-05-17 14:09:22 -0700437 const struct qcom_scm_vmperm *newvm,
438 unsigned int dest_cnt)
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530439{
440 struct qcom_scm_current_perm_info *destvm;
441 struct qcom_scm_mem_map_info *mem_to_map;
442 phys_addr_t mem_to_map_phys;
443 phys_addr_t dest_phys;
444 phys_addr_t ptr_phys;
Stephen Boyd6e37ccf2019-05-17 14:09:21 -0700445 dma_addr_t ptr_dma;
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530446 size_t mem_to_map_sz;
447 size_t dest_sz;
448 size_t src_sz;
449 size_t ptr_sz;
450 int next_vm;
451 __le32 *src;
452 void *ptr;
Stephen Boydaf311ff2019-05-17 14:09:22 -0700453 int ret, i, b;
454 unsigned long srcvm_bits = *srcvm;
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530455
Stephen Boydaf311ff2019-05-17 14:09:22 -0700456 src_sz = hweight_long(srcvm_bits) * sizeof(*src);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530457 mem_to_map_sz = sizeof(*mem_to_map);
458 dest_sz = dest_cnt * sizeof(*destvm);
459 ptr_sz = ALIGN(src_sz, SZ_64) + ALIGN(mem_to_map_sz, SZ_64) +
460 ALIGN(dest_sz, SZ_64);
461
Stephen Boyd6e37ccf2019-05-17 14:09:21 -0700462 ptr = dma_alloc_coherent(__scm->dev, ptr_sz, &ptr_dma, GFP_KERNEL);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530463 if (!ptr)
464 return -ENOMEM;
Stephen Boyd6e37ccf2019-05-17 14:09:21 -0700465 ptr_phys = dma_to_phys(__scm->dev, ptr_dma);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530466
467 /* Fill source vmid detail */
468 src = ptr;
Stephen Boydaf311ff2019-05-17 14:09:22 -0700469 i = 0;
470 for_each_set_bit(b, &srcvm_bits, BITS_PER_LONG)
471 src[i++] = cpu_to_le32(b);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530472
473 /* Fill details of mem buff to map */
474 mem_to_map = ptr + ALIGN(src_sz, SZ_64);
475 mem_to_map_phys = ptr_phys + ALIGN(src_sz, SZ_64);
Stephen Boydaf311ff2019-05-17 14:09:22 -0700476 mem_to_map->mem_addr = cpu_to_le64(mem_addr);
477 mem_to_map->mem_size = cpu_to_le64(mem_sz);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530478
479 next_vm = 0;
480 /* Fill details of next vmid detail */
481 destvm = ptr + ALIGN(mem_to_map_sz, SZ_64) + ALIGN(src_sz, SZ_64);
482 dest_phys = ptr_phys + ALIGN(mem_to_map_sz, SZ_64) + ALIGN(src_sz, SZ_64);
Stephen Boydaf311ff2019-05-17 14:09:22 -0700483 for (i = 0; i < dest_cnt; i++, destvm++, newvm++) {
484 destvm->vmid = cpu_to_le32(newvm->vmid);
485 destvm->perm = cpu_to_le32(newvm->perm);
486 destvm->ctx = 0;
487 destvm->ctx_size = 0;
488 next_vm |= BIT(newvm->vmid);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530489 }
490
491 ret = __qcom_scm_assign_mem(__scm->dev, mem_to_map_phys, mem_to_map_sz,
492 ptr_phys, src_sz, dest_phys, dest_sz);
Stephen Boyd6e37ccf2019-05-17 14:09:21 -0700493 dma_free_coherent(__scm->dev, ptr_sz, ptr, ptr_dma);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530494 if (ret) {
495 dev_err(__scm->dev,
Stephen Boydc8b08fc2019-05-17 14:09:23 -0700496 "Assign memory protection call failed %d\n", ret);
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530497 return -EINVAL;
498 }
499
500 *srcvm = next_vm;
501 return 0;
502}
503EXPORT_SYMBOL(qcom_scm_assign_mem);
504
Andy Grossd0f6fa72016-06-03 18:25:22 -0500505static int qcom_scm_probe(struct platform_device *pdev)
506{
507 struct qcom_scm *scm;
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800508 unsigned long clks;
Andy Grossd0f6fa72016-06-03 18:25:22 -0500509 int ret;
510
511 scm = devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL);
512 if (!scm)
513 return -ENOMEM;
514
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700515 ret = qcom_scm_find_dload_address(&pdev->dev, &scm->dload_mode_addr);
516 if (ret < 0)
517 return ret;
518
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800519 clks = (unsigned long)of_device_get_match_data(&pdev->dev);
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700520
521 scm->core_clk = devm_clk_get(&pdev->dev, "core");
522 if (IS_ERR(scm->core_clk)) {
523 if (PTR_ERR(scm->core_clk) == -EPROBE_DEFER)
524 return PTR_ERR(scm->core_clk);
525
526 if (clks & SCM_HAS_CORE_CLK) {
527 dev_err(&pdev->dev, "failed to acquire core clk\n");
spjoshi@codeaurora.orged19b862016-11-15 17:19:25 -0800528 return PTR_ERR(scm->core_clk);
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800529 }
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700530
531 scm->core_clk = NULL;
Andy Grossd0f6fa72016-06-03 18:25:22 -0500532 }
533
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700534 scm->iface_clk = devm_clk_get(&pdev->dev, "iface");
535 if (IS_ERR(scm->iface_clk)) {
536 if (PTR_ERR(scm->iface_clk) == -EPROBE_DEFER)
537 return PTR_ERR(scm->iface_clk);
538
539 if (clks & SCM_HAS_IFACE_CLK) {
540 dev_err(&pdev->dev, "failed to acquire iface clk\n");
Andy Grossd0f6fa72016-06-03 18:25:22 -0500541 return PTR_ERR(scm->iface_clk);
542 }
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700543
544 scm->iface_clk = NULL;
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800545 }
Andy Grossd0f6fa72016-06-03 18:25:22 -0500546
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700547 scm->bus_clk = devm_clk_get(&pdev->dev, "bus");
548 if (IS_ERR(scm->bus_clk)) {
549 if (PTR_ERR(scm->bus_clk) == -EPROBE_DEFER)
550 return PTR_ERR(scm->bus_clk);
551
552 if (clks & SCM_HAS_BUS_CLK) {
553 dev_err(&pdev->dev, "failed to acquire bus clk\n");
Andy Grossd0f6fa72016-06-03 18:25:22 -0500554 return PTR_ERR(scm->bus_clk);
555 }
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700556
557 scm->bus_clk = NULL;
Andy Grossd0f6fa72016-06-03 18:25:22 -0500558 }
559
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700560 scm->reset.ops = &qcom_scm_pas_reset_ops;
561 scm->reset.nr_resets = 1;
562 scm->reset.of_node = pdev->dev.of_node;
Wei Yongjunbd4760c2016-08-28 16:29:10 +0000563 ret = devm_reset_controller_register(&pdev->dev, &scm->reset);
564 if (ret)
565 return ret;
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700566
Andy Grossd0f6fa72016-06-03 18:25:22 -0500567 /* vote for max clk rate for highest performance */
568 ret = clk_set_rate(scm->core_clk, INT_MAX);
569 if (ret)
570 return ret;
571
572 __scm = scm;
573 __scm->dev = &pdev->dev;
574
Kumar Gala6b1751a2016-06-03 18:25:26 -0500575 __qcom_scm_init();
576
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700577 /*
578 * If requested enable "download mode", from this point on warmboot
579 * will cause the the boot stages to enter download mode, unless
580 * disabled below by a clean shutdown/reboot.
581 */
582 if (download_mode)
583 qcom_scm_set_download_mode(true);
584
Andy Grossd0f6fa72016-06-03 18:25:22 -0500585 return 0;
586}
587
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700588static void qcom_scm_shutdown(struct platform_device *pdev)
589{
590 /* Clean shutdown, disable download mode to allow normal restart */
591 if (download_mode)
592 qcom_scm_set_download_mode(false);
593}
594
Andy Grossd0f6fa72016-06-03 18:25:22 -0500595static const struct of_device_id qcom_scm_dt_match[] = {
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800596 { .compatible = "qcom,scm-apq8064",
Andy Grossb58a2d32017-01-11 16:58:03 -0600597 /* FIXME: This should have .data = (void *) SCM_HAS_CORE_CLK */
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800598 },
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700599 { .compatible = "qcom,scm-apq8084", .data = (void *)(SCM_HAS_CORE_CLK |
600 SCM_HAS_IFACE_CLK |
601 SCM_HAS_BUS_CLK)
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800602 },
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700603 { .compatible = "qcom,scm-ipq4019" },
604 { .compatible = "qcom,scm-msm8660", .data = (void *) SCM_HAS_CORE_CLK },
605 { .compatible = "qcom,scm-msm8960", .data = (void *) SCM_HAS_CORE_CLK },
606 { .compatible = "qcom,scm-msm8916", .data = (void *)(SCM_HAS_CORE_CLK |
607 SCM_HAS_IFACE_CLK |
608 SCM_HAS_BUS_CLK)
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800609 },
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700610 { .compatible = "qcom,scm-msm8974", .data = (void *)(SCM_HAS_CORE_CLK |
611 SCM_HAS_IFACE_CLK |
612 SCM_HAS_BUS_CLK)
spjoshi@codeaurora.orgab0822d2016-11-15 17:19:24 -0800613 },
Bjorn Andersson60cd4202018-08-29 16:15:04 -0700614 { .compatible = "qcom,scm-msm8996" },
615 { .compatible = "qcom,scm" },
Andy Grossd0f6fa72016-06-03 18:25:22 -0500616 {}
617};
618
Andy Grossd0f6fa72016-06-03 18:25:22 -0500619static struct platform_driver qcom_scm_driver = {
620 .driver = {
621 .name = "qcom_scm",
622 .of_match_table = qcom_scm_dt_match,
623 },
624 .probe = qcom_scm_probe,
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700625 .shutdown = qcom_scm_shutdown,
Andy Grossd0f6fa72016-06-03 18:25:22 -0500626};
627
628static int __init qcom_scm_init(void)
629{
Andy Grossd0f6fa72016-06-03 18:25:22 -0500630 return platform_driver_register(&qcom_scm_driver);
631}
Andy Gross6c8e99d2016-07-01 23:04:03 -0500632subsys_initcall(qcom_scm_init);