1 /* Copyright (c) 2010,2015, The Linux Foundation. All rights reserved.
2 * Copyright (C) 2015 Linaro Ltd.
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.
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.
14 #include <linux/platform_device.h>
15 #include <linux/module.h>
16 #include <linux/cpumask.h>
17 #include <linux/export.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/types.h>
20 #include <linux/qcom_scm.h>
22 #include <linux/of_platform.h>
23 #include <linux/clk.h>
24 #include <linux/reset-controller.h>
31 struct clk
*iface_clk
;
33 struct reset_controller_dev reset
;
36 static struct qcom_scm
*__scm
;
38 static int qcom_scm_clk_enable(void)
42 ret
= clk_prepare_enable(__scm
->core_clk
);
46 ret
= clk_prepare_enable(__scm
->iface_clk
);
50 ret
= clk_prepare_enable(__scm
->bus_clk
);
57 clk_disable_unprepare(__scm
->iface_clk
);
59 clk_disable_unprepare(__scm
->core_clk
);
64 static void qcom_scm_clk_disable(void)
66 clk_disable_unprepare(__scm
->core_clk
);
67 clk_disable_unprepare(__scm
->iface_clk
);
68 clk_disable_unprepare(__scm
->bus_clk
);
72 * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus
73 * @entry: Entry point function for the cpus
74 * @cpus: The cpumask of cpus that will use the entry point
76 * Set the cold boot address of the cpus. Any cpu outside the supported
77 * range would be removed from the cpu present mask.
79 int qcom_scm_set_cold_boot_addr(void *entry
, const cpumask_t
*cpus
)
81 return __qcom_scm_set_cold_boot_addr(entry
, cpus
);
83 EXPORT_SYMBOL(qcom_scm_set_cold_boot_addr
);
86 * qcom_scm_set_warm_boot_addr() - Set the warm boot address for cpus
87 * @entry: Entry point function for the cpus
88 * @cpus: The cpumask of cpus that will use the entry point
90 * Set the Linux entry point for the SCM to transfer control to when coming
91 * out of a power down. CPU power down may be executed on cpuidle or hotplug.
93 int qcom_scm_set_warm_boot_addr(void *entry
, const cpumask_t
*cpus
)
95 return __qcom_scm_set_warm_boot_addr(__scm
->dev
, entry
, cpus
);
97 EXPORT_SYMBOL(qcom_scm_set_warm_boot_addr
);
100 * qcom_scm_cpu_power_down() - Power down the cpu
101 * @flags - Flags to flush cache
103 * This is an end point to power down cpu. If there was a pending interrupt,
104 * the control would return from this function, otherwise, the cpu jumps to the
105 * warm boot entry point set for this cpu upon reset.
107 void qcom_scm_cpu_power_down(u32 flags
)
109 __qcom_scm_cpu_power_down(flags
);
111 EXPORT_SYMBOL(qcom_scm_cpu_power_down
);
114 * qcom_scm_hdcp_available() - Check if secure environment supports HDCP.
116 * Return true if HDCP is supported, false if not.
118 bool qcom_scm_hdcp_available(void)
120 int ret
= qcom_scm_clk_enable();
125 ret
= __qcom_scm_is_call_available(__scm
->dev
, QCOM_SCM_SVC_HDCP
,
128 qcom_scm_clk_disable();
130 return ret
> 0 ? true : false;
132 EXPORT_SYMBOL(qcom_scm_hdcp_available
);
135 * qcom_scm_hdcp_req() - Send HDCP request.
136 * @req: HDCP request array
137 * @req_cnt: HDCP request array count
138 * @resp: response buffer passed to SCM
140 * Write HDCP register(s) through SCM.
142 int qcom_scm_hdcp_req(struct qcom_scm_hdcp_req
*req
, u32 req_cnt
, u32
*resp
)
144 int ret
= qcom_scm_clk_enable();
149 ret
= __qcom_scm_hdcp_req(__scm
->dev
, req
, req_cnt
, resp
);
150 qcom_scm_clk_disable();
153 EXPORT_SYMBOL(qcom_scm_hdcp_req
);
156 * qcom_scm_pas_supported() - Check if the peripheral authentication service is
157 * available for the given peripherial
158 * @peripheral: peripheral id
160 * Returns true if PAS is supported for this peripheral, otherwise false.
162 bool qcom_scm_pas_supported(u32 peripheral
)
166 ret
= __qcom_scm_is_call_available(__scm
->dev
, QCOM_SCM_SVC_PIL
,
167 QCOM_SCM_PAS_IS_SUPPORTED_CMD
);
171 return __qcom_scm_pas_supported(__scm
->dev
, peripheral
);
173 EXPORT_SYMBOL(qcom_scm_pas_supported
);
176 * qcom_scm_pas_init_image() - Initialize peripheral authentication service
177 * state machine for a given peripheral, using the
179 * @peripheral: peripheral id
180 * @metadata: pointer to memory containing ELF header, program header table
181 * and optional blob of data used for authenticating the metadata
182 * and the rest of the firmware
183 * @size: size of the metadata
185 * Returns 0 on success.
187 int qcom_scm_pas_init_image(u32 peripheral
, const void *metadata
, size_t size
)
189 dma_addr_t mdata_phys
;
194 * During the scm call memory protection will be enabled for the meta
195 * data blob, so make sure it's physically contiguous, 4K aligned and
196 * non-cachable to avoid XPU violations.
198 mdata_buf
= dma_alloc_coherent(__scm
->dev
, size
, &mdata_phys
,
201 dev_err(__scm
->dev
, "Allocation of metadata buffer failed.\n");
204 memcpy(mdata_buf
, metadata
, size
);
206 ret
= qcom_scm_clk_enable();
210 ret
= __qcom_scm_pas_init_image(__scm
->dev
, peripheral
, mdata_phys
);
212 qcom_scm_clk_disable();
215 dma_free_coherent(__scm
->dev
, size
, mdata_buf
, mdata_phys
);
219 EXPORT_SYMBOL(qcom_scm_pas_init_image
);
222 * qcom_scm_pas_mem_setup() - Prepare the memory related to a given peripheral
223 * for firmware loading
224 * @peripheral: peripheral id
225 * @addr: start address of memory area to prepare
226 * @size: size of the memory area to prepare
228 * Returns 0 on success.
230 int qcom_scm_pas_mem_setup(u32 peripheral
, phys_addr_t addr
, phys_addr_t size
)
234 ret
= qcom_scm_clk_enable();
238 ret
= __qcom_scm_pas_mem_setup(__scm
->dev
, peripheral
, addr
, size
);
239 qcom_scm_clk_disable();
243 EXPORT_SYMBOL(qcom_scm_pas_mem_setup
);
246 * qcom_scm_pas_auth_and_reset() - Authenticate the given peripheral firmware
247 * and reset the remote processor
248 * @peripheral: peripheral id
250 * Return 0 on success.
252 int qcom_scm_pas_auth_and_reset(u32 peripheral
)
256 ret
= qcom_scm_clk_enable();
260 ret
= __qcom_scm_pas_auth_and_reset(__scm
->dev
, peripheral
);
261 qcom_scm_clk_disable();
265 EXPORT_SYMBOL(qcom_scm_pas_auth_and_reset
);
268 * qcom_scm_pas_shutdown() - Shut down the remote processor
269 * @peripheral: peripheral id
271 * Returns 0 on success.
273 int qcom_scm_pas_shutdown(u32 peripheral
)
277 ret
= qcom_scm_clk_enable();
281 ret
= __qcom_scm_pas_shutdown(__scm
->dev
, peripheral
);
282 qcom_scm_clk_disable();
286 EXPORT_SYMBOL(qcom_scm_pas_shutdown
);
288 static int qcom_scm_pas_reset_assert(struct reset_controller_dev
*rcdev
,
294 return __qcom_scm_pas_mss_reset(__scm
->dev
, 1);
297 static int qcom_scm_pas_reset_deassert(struct reset_controller_dev
*rcdev
,
303 return __qcom_scm_pas_mss_reset(__scm
->dev
, 0);
306 static const struct reset_control_ops qcom_scm_pas_reset_ops
= {
307 .assert = qcom_scm_pas_reset_assert
,
308 .deassert
= qcom_scm_pas_reset_deassert
,
312 * qcom_scm_is_available() - Checks if SCM is available
314 bool qcom_scm_is_available(void)
318 EXPORT_SYMBOL(qcom_scm_is_available
);
320 static int qcom_scm_probe(struct platform_device
*pdev
)
322 struct qcom_scm
*scm
;
325 scm
= devm_kzalloc(&pdev
->dev
, sizeof(*scm
), GFP_KERNEL
);
329 scm
->core_clk
= devm_clk_get(&pdev
->dev
, "core");
330 if (IS_ERR(scm
->core_clk
)) {
331 if (PTR_ERR(scm
->core_clk
) == -EPROBE_DEFER
)
332 return PTR_ERR(scm
->core_clk
);
334 scm
->core_clk
= NULL
;
337 if (of_device_is_compatible(pdev
->dev
.of_node
, "qcom,scm")) {
338 scm
->iface_clk
= devm_clk_get(&pdev
->dev
, "iface");
339 if (IS_ERR(scm
->iface_clk
)) {
340 if (PTR_ERR(scm
->iface_clk
) != -EPROBE_DEFER
)
341 dev_err(&pdev
->dev
, "failed to acquire iface clk\n");
342 return PTR_ERR(scm
->iface_clk
);
345 scm
->bus_clk
= devm_clk_get(&pdev
->dev
, "bus");
346 if (IS_ERR(scm
->bus_clk
)) {
347 if (PTR_ERR(scm
->bus_clk
) != -EPROBE_DEFER
)
348 dev_err(&pdev
->dev
, "failed to acquire bus clk\n");
349 return PTR_ERR(scm
->bus_clk
);
353 scm
->reset
.ops
= &qcom_scm_pas_reset_ops
;
354 scm
->reset
.nr_resets
= 1;
355 scm
->reset
.of_node
= pdev
->dev
.of_node
;
356 reset_controller_register(&scm
->reset
);
358 /* vote for max clk rate for highest performance */
359 ret
= clk_set_rate(scm
->core_clk
, INT_MAX
);
364 __scm
->dev
= &pdev
->dev
;
371 static const struct of_device_id qcom_scm_dt_match
[] = {
372 { .compatible
= "qcom,scm-apq8064",},
373 { .compatible
= "qcom,scm-msm8660",},
374 { .compatible
= "qcom,scm-msm8960",},
375 { .compatible
= "qcom,scm",},
379 MODULE_DEVICE_TABLE(of
, qcom_scm_dt_match
);
381 static struct platform_driver qcom_scm_driver
= {
384 .of_match_table
= qcom_scm_dt_match
,
386 .probe
= qcom_scm_probe
,
389 static int __init
qcom_scm_init(void)
391 struct device_node
*np
, *fw_np
;
394 fw_np
= of_find_node_by_name(NULL
, "firmware");
399 np
= of_find_matching_node(fw_np
, qcom_scm_dt_match
);
408 ret
= of_platform_populate(fw_np
, qcom_scm_dt_match
, NULL
, NULL
);
415 return platform_driver_register(&qcom_scm_driver
);
418 subsys_initcall(qcom_scm_init
);
420 static void __exit
qcom_scm_exit(void)
422 platform_driver_unregister(&qcom_scm_driver
);
424 module_exit(qcom_scm_exit
);
426 MODULE_DESCRIPTION("Qualcomm SCM driver");
427 MODULE_LICENSE("GPL v2");