jilai wang | 9626b69 | 2015-04-10 16:15:59 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2010,2015, The Linux Foundation. All rights reserved. |
Lina Iyer | 2ce76a6 | 2015-03-02 16:30:29 -0700 | [diff] [blame] | 2 | * Copyright (C) 2015 Linaro Ltd. |
Stephen Boyd | 2a1eb58 | 2010-08-27 10:01:23 -0700 | [diff] [blame] | 3 | * |
| 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 | * |
Stephen Boyd | 2a1eb58 | 2010-08-27 10:01:23 -0700 | [diff] [blame] | 13 | */ |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/module.h> |
Kumar Gala | b6a1dfb | 2015-03-11 16:28:10 -0500 | [diff] [blame] | 16 | #include <linux/cpumask.h> |
| 17 | #include <linux/export.h> |
| 18 | #include <linux/types.h> |
Kumar Gala | 916f743 | 2015-02-26 15:49:09 -0600 | [diff] [blame] | 19 | #include <linux/qcom_scm.h> |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/clk.h> |
Stephen Boyd | 2a1eb58 | 2010-08-27 10:01:23 -0700 | [diff] [blame] | 23 | |
Kumar Gala | b6a1dfb | 2015-03-11 16:28:10 -0500 | [diff] [blame] | 24 | #include "qcom_scm.h" |
Lina Iyer | a353e4a | 2015-03-02 16:30:28 -0700 | [diff] [blame] | 25 | |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 26 | struct qcom_scm { |
| 27 | struct device *dev; |
| 28 | struct clk *core_clk; |
| 29 | struct clk *iface_clk; |
| 30 | struct clk *bus_clk; |
| 31 | }; |
| 32 | |
| 33 | static struct qcom_scm *__scm; |
| 34 | |
| 35 | static int qcom_scm_clk_enable(void) |
| 36 | { |
| 37 | int ret; |
| 38 | |
| 39 | ret = clk_prepare_enable(__scm->core_clk); |
| 40 | if (ret) |
| 41 | goto bail; |
| 42 | |
| 43 | ret = clk_prepare_enable(__scm->iface_clk); |
| 44 | if (ret) |
| 45 | goto disable_core; |
| 46 | |
| 47 | ret = clk_prepare_enable(__scm->bus_clk); |
| 48 | if (ret) |
| 49 | goto disable_iface; |
| 50 | |
| 51 | return 0; |
| 52 | |
| 53 | disable_iface: |
| 54 | clk_disable_unprepare(__scm->iface_clk); |
| 55 | disable_core: |
| 56 | clk_disable_unprepare(__scm->core_clk); |
| 57 | bail: |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | static void qcom_scm_clk_disable(void) |
| 62 | { |
| 63 | clk_disable_unprepare(__scm->core_clk); |
| 64 | clk_disable_unprepare(__scm->iface_clk); |
| 65 | clk_disable_unprepare(__scm->bus_clk); |
| 66 | } |
| 67 | |
Lina Iyer | a353e4a | 2015-03-02 16:30:28 -0700 | [diff] [blame] | 68 | /** |
| 69 | * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus |
| 70 | * @entry: Entry point function for the cpus |
| 71 | * @cpus: The cpumask of cpus that will use the entry point |
| 72 | * |
| 73 | * Set the cold boot address of the cpus. Any cpu outside the supported |
| 74 | * range would be removed from the cpu present mask. |
| 75 | */ |
| 76 | int qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus) |
| 77 | { |
Kumar Gala | b6a1dfb | 2015-03-11 16:28:10 -0500 | [diff] [blame] | 78 | return __qcom_scm_set_cold_boot_addr(entry, cpus); |
Lina Iyer | a353e4a | 2015-03-02 16:30:28 -0700 | [diff] [blame] | 79 | } |
| 80 | EXPORT_SYMBOL(qcom_scm_set_cold_boot_addr); |
Lina Iyer | 2ce76a6 | 2015-03-02 16:30:29 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * qcom_scm_set_warm_boot_addr() - Set the warm boot address for cpus |
| 84 | * @entry: Entry point function for the cpus |
| 85 | * @cpus: The cpumask of cpus that will use the entry point |
| 86 | * |
| 87 | * Set the Linux entry point for the SCM to transfer control to when coming |
| 88 | * out of a power down. CPU power down may be executed on cpuidle or hotplug. |
| 89 | */ |
| 90 | int qcom_scm_set_warm_boot_addr(void *entry, const cpumask_t *cpus) |
| 91 | { |
Kumar Gala | b6a1dfb | 2015-03-11 16:28:10 -0500 | [diff] [blame] | 92 | return __qcom_scm_set_warm_boot_addr(entry, cpus); |
Lina Iyer | 2ce76a6 | 2015-03-02 16:30:29 -0700 | [diff] [blame] | 93 | } |
| 94 | EXPORT_SYMBOL(qcom_scm_set_warm_boot_addr); |
Lina Iyer | 767b023 | 2015-03-02 16:30:30 -0700 | [diff] [blame] | 95 | |
Lina Iyer | 767b023 | 2015-03-02 16:30:30 -0700 | [diff] [blame] | 96 | /** |
| 97 | * qcom_scm_cpu_power_down() - Power down the cpu |
| 98 | * @flags - Flags to flush cache |
| 99 | * |
| 100 | * This is an end point to power down cpu. If there was a pending interrupt, |
| 101 | * the control would return from this function, otherwise, the cpu jumps to the |
| 102 | * warm boot entry point set for this cpu upon reset. |
| 103 | */ |
| 104 | void qcom_scm_cpu_power_down(u32 flags) |
| 105 | { |
Kumar Gala | b6a1dfb | 2015-03-11 16:28:10 -0500 | [diff] [blame] | 106 | __qcom_scm_cpu_power_down(flags); |
Lina Iyer | 767b023 | 2015-03-02 16:30:30 -0700 | [diff] [blame] | 107 | } |
| 108 | EXPORT_SYMBOL(qcom_scm_cpu_power_down); |
jilai wang | 9626b69 | 2015-04-10 16:15:59 -0400 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * qcom_scm_hdcp_available() - Check if secure environment supports HDCP. |
| 112 | * |
| 113 | * Return true if HDCP is supported, false if not. |
| 114 | */ |
| 115 | bool qcom_scm_hdcp_available(void) |
| 116 | { |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 117 | int ret = qcom_scm_clk_enable(); |
| 118 | |
| 119 | if (ret) |
| 120 | return ret; |
jilai wang | 9626b69 | 2015-04-10 16:15:59 -0400 | [diff] [blame] | 121 | |
| 122 | ret = __qcom_scm_is_call_available(QCOM_SCM_SVC_HDCP, |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 123 | QCOM_SCM_CMD_HDCP); |
jilai wang | 9626b69 | 2015-04-10 16:15:59 -0400 | [diff] [blame] | 124 | |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 125 | qcom_scm_clk_disable(); |
| 126 | |
| 127 | return ret > 0 ? true : false; |
jilai wang | 9626b69 | 2015-04-10 16:15:59 -0400 | [diff] [blame] | 128 | } |
| 129 | EXPORT_SYMBOL(qcom_scm_hdcp_available); |
| 130 | |
| 131 | /** |
| 132 | * qcom_scm_hdcp_req() - Send HDCP request. |
| 133 | * @req: HDCP request array |
| 134 | * @req_cnt: HDCP request array count |
| 135 | * @resp: response buffer passed to SCM |
| 136 | * |
| 137 | * Write HDCP register(s) through SCM. |
| 138 | */ |
| 139 | int qcom_scm_hdcp_req(struct qcom_scm_hdcp_req *req, u32 req_cnt, u32 *resp) |
| 140 | { |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 141 | int ret = qcom_scm_clk_enable(); |
| 142 | |
| 143 | if (ret) |
| 144 | return ret; |
| 145 | |
| 146 | ret = __qcom_scm_hdcp_req(req, req_cnt, resp); |
| 147 | qcom_scm_clk_disable(); |
| 148 | return ret; |
jilai wang | 9626b69 | 2015-04-10 16:15:59 -0400 | [diff] [blame] | 149 | } |
| 150 | EXPORT_SYMBOL(qcom_scm_hdcp_req); |
Andy Gross | d0f6fa7 | 2016-06-03 18:25:22 -0500 | [diff] [blame^] | 151 | |
| 152 | static int qcom_scm_probe(struct platform_device *pdev) |
| 153 | { |
| 154 | struct qcom_scm *scm; |
| 155 | int ret; |
| 156 | |
| 157 | scm = devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL); |
| 158 | if (!scm) |
| 159 | return -ENOMEM; |
| 160 | |
| 161 | scm->core_clk = devm_clk_get(&pdev->dev, "core"); |
| 162 | if (IS_ERR(scm->core_clk)) { |
| 163 | if (PTR_ERR(scm->core_clk) == -EPROBE_DEFER) |
| 164 | return PTR_ERR(scm->core_clk); |
| 165 | |
| 166 | scm->core_clk = NULL; |
| 167 | } |
| 168 | |
| 169 | if (of_device_is_compatible(pdev->dev.of_node, "qcom,scm")) { |
| 170 | scm->iface_clk = devm_clk_get(&pdev->dev, "iface"); |
| 171 | if (IS_ERR(scm->iface_clk)) { |
| 172 | if (PTR_ERR(scm->iface_clk) != -EPROBE_DEFER) |
| 173 | dev_err(&pdev->dev, "failed to acquire iface clk\n"); |
| 174 | return PTR_ERR(scm->iface_clk); |
| 175 | } |
| 176 | |
| 177 | scm->bus_clk = devm_clk_get(&pdev->dev, "bus"); |
| 178 | if (IS_ERR(scm->bus_clk)) { |
| 179 | if (PTR_ERR(scm->bus_clk) != -EPROBE_DEFER) |
| 180 | dev_err(&pdev->dev, "failed to acquire bus clk\n"); |
| 181 | return PTR_ERR(scm->bus_clk); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* vote for max clk rate for highest performance */ |
| 186 | ret = clk_set_rate(scm->core_clk, INT_MAX); |
| 187 | if (ret) |
| 188 | return ret; |
| 189 | |
| 190 | __scm = scm; |
| 191 | __scm->dev = &pdev->dev; |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static const struct of_device_id qcom_scm_dt_match[] = { |
| 197 | { .compatible = "qcom,scm-apq8064",}, |
| 198 | { .compatible = "qcom,scm-msm8660",}, |
| 199 | { .compatible = "qcom,scm-msm8960",}, |
| 200 | { .compatible = "qcom,scm",}, |
| 201 | {} |
| 202 | }; |
| 203 | |
| 204 | MODULE_DEVICE_TABLE(of, qcom_scm_dt_match); |
| 205 | |
| 206 | static struct platform_driver qcom_scm_driver = { |
| 207 | .driver = { |
| 208 | .name = "qcom_scm", |
| 209 | .of_match_table = qcom_scm_dt_match, |
| 210 | }, |
| 211 | .probe = qcom_scm_probe, |
| 212 | }; |
| 213 | |
| 214 | static int __init qcom_scm_init(void) |
| 215 | { |
| 216 | struct device_node *np, *fw_np; |
| 217 | int ret; |
| 218 | |
| 219 | fw_np = of_find_node_by_name(NULL, "firmware"); |
| 220 | |
| 221 | if (!fw_np) |
| 222 | return -ENODEV; |
| 223 | |
| 224 | np = of_find_matching_node(fw_np, qcom_scm_dt_match); |
| 225 | |
| 226 | if (!np) { |
| 227 | of_node_put(fw_np); |
| 228 | return -ENODEV; |
| 229 | } |
| 230 | |
| 231 | of_node_put(np); |
| 232 | |
| 233 | ret = of_platform_populate(fw_np, qcom_scm_dt_match, NULL, NULL); |
| 234 | |
| 235 | of_node_put(fw_np); |
| 236 | |
| 237 | if (ret) |
| 238 | return ret; |
| 239 | |
| 240 | return platform_driver_register(&qcom_scm_driver); |
| 241 | } |
| 242 | |
| 243 | arch_initcall(qcom_scm_init); |
| 244 | |
| 245 | static void __exit qcom_scm_exit(void) |
| 246 | { |
| 247 | platform_driver_unregister(&qcom_scm_driver); |
| 248 | } |
| 249 | module_exit(qcom_scm_exit); |
| 250 | |
| 251 | MODULE_DESCRIPTION("Qualcomm SCM driver"); |
| 252 | MODULE_LICENSE("GPL v2"); |