Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 1 | /* |
Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -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 | */ |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/io.h> |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/of.h> |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 20 | #include <linux/clk.h> |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 21 | #include <mach/clk.h> |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 22 | #include "peripheral-loader.h" |
| 23 | #include "pil-q6v5.h" |
Matt Wagantall | c40e28f | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 24 | #include "scm-pas.h" |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 25 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 26 | #define QDSP6SS_RST_EVB 0x010 |
Matt Wagantall | 4d89c2e | 2012-05-25 19:28:34 -0700 | [diff] [blame] | 27 | #define PROXY_TIMEOUT_MS 10000 |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 28 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 29 | static int pil_lpass_enable_clks(struct q6v5_data *drv) |
| 30 | { |
| 31 | int ret; |
| 32 | |
| 33 | ret = clk_reset(drv->core_clk, CLK_RESET_DEASSERT); |
| 34 | if (ret) |
| 35 | goto err_reset; |
| 36 | ret = clk_prepare_enable(drv->core_clk); |
| 37 | if (ret) |
| 38 | goto err_core_clk; |
| 39 | ret = clk_prepare_enable(drv->ahb_clk); |
| 40 | if (ret) |
| 41 | goto err_ahb_clk; |
| 42 | ret = clk_prepare_enable(drv->axi_clk); |
| 43 | if (ret) |
| 44 | goto err_axi_clk; |
| 45 | ret = clk_prepare_enable(drv->reg_clk); |
| 46 | if (ret) |
| 47 | goto err_reg_clk; |
| 48 | |
| 49 | return 0; |
| 50 | |
| 51 | err_reg_clk: |
| 52 | clk_disable_unprepare(drv->axi_clk); |
| 53 | err_axi_clk: |
| 54 | clk_disable_unprepare(drv->ahb_clk); |
| 55 | err_ahb_clk: |
| 56 | clk_disable_unprepare(drv->core_clk); |
| 57 | err_core_clk: |
| 58 | clk_reset(drv->core_clk, CLK_RESET_ASSERT); |
| 59 | err_reset: |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | static void pil_lpass_disable_clks(struct q6v5_data *drv) |
| 64 | { |
| 65 | clk_disable_unprepare(drv->reg_clk); |
| 66 | clk_disable_unprepare(drv->axi_clk); |
| 67 | clk_disable_unprepare(drv->ahb_clk); |
| 68 | clk_disable_unprepare(drv->core_clk); |
| 69 | clk_reset(drv->core_clk, CLK_RESET_ASSERT); |
| 70 | } |
| 71 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 72 | static int pil_lpass_shutdown(struct pil_desc *pil) |
| 73 | { |
| 74 | struct q6v5_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 75 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 76 | pil_q6v5_halt_axi_port(pil, drv->axi_halt_base); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 77 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 78 | /* |
| 79 | * If the shutdown function is called before the reset function, clocks |
| 80 | * will not be enabled yet. Enable them here so that register writes |
| 81 | * performed during the shutdown succeed. |
| 82 | */ |
| 83 | if (drv->is_booted == false) |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 84 | pil_lpass_enable_clks(drv); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 85 | |
| 86 | pil_q6v5_shutdown(pil); |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 87 | pil_lpass_disable_clks(drv); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 88 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 89 | drv->is_booted = false; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int pil_lpass_reset(struct pil_desc *pil) |
| 95 | { |
| 96 | struct q6v5_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 97 | int ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 98 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 99 | ret = pil_lpass_enable_clks(drv); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 100 | if (ret) |
| 101 | return ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 102 | |
| 103 | /* Program Image Address */ |
| 104 | writel_relaxed(((drv->start_addr >> 4) & 0x0FFFFFF0), |
| 105 | drv->reg_base + QDSP6SS_RST_EVB); |
| 106 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 107 | ret = pil_q6v5_reset(pil); |
| 108 | if (ret) { |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 109 | pil_lpass_disable_clks(drv); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | drv->is_booted = true; |
| 114 | |
| 115 | return 0; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static struct pil_reset_ops pil_lpass_ops = { |
| 119 | .init_image = pil_q6v5_init_image, |
| 120 | .proxy_vote = pil_q6v5_make_proxy_votes, |
| 121 | .proxy_unvote = pil_q6v5_remove_proxy_votes, |
| 122 | .auth_and_reset = pil_lpass_reset, |
| 123 | .shutdown = pil_lpass_shutdown, |
| 124 | }; |
| 125 | |
Matt Wagantall | c40e28f | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 126 | static int pil_lpass_init_image_trusted(struct pil_desc *pil, |
| 127 | const u8 *metadata, size_t size) |
| 128 | { |
| 129 | return pas_init_image(PAS_Q6, metadata, size); |
| 130 | } |
| 131 | |
| 132 | static int pil_lpass_reset_trusted(struct pil_desc *pil) |
| 133 | { |
| 134 | return pas_auth_and_reset(PAS_Q6); |
| 135 | } |
| 136 | |
| 137 | static int pil_lpass_shutdown_trusted(struct pil_desc *pil) |
| 138 | { |
| 139 | return pas_shutdown(PAS_Q6); |
| 140 | } |
| 141 | |
| 142 | static struct pil_reset_ops pil_lpass_ops_trusted = { |
| 143 | .init_image = pil_lpass_init_image_trusted, |
| 144 | .proxy_vote = pil_q6v5_make_proxy_votes, |
| 145 | .proxy_unvote = pil_q6v5_remove_proxy_votes, |
| 146 | .auth_and_reset = pil_lpass_reset_trusted, |
| 147 | .shutdown = pil_lpass_shutdown_trusted, |
| 148 | }; |
| 149 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 150 | static int __devinit pil_lpass_driver_probe(struct platform_device *pdev) |
| 151 | { |
| 152 | struct q6v5_data *drv; |
| 153 | struct pil_desc *desc; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 154 | |
| 155 | desc = pil_q6v5_init(pdev); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 156 | if (IS_ERR(desc)) |
| 157 | return PTR_ERR(desc); |
| 158 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 159 | drv = platform_get_drvdata(pdev); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 160 | if (drv == NULL) |
| 161 | return -ENODEV; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 162 | |
| 163 | desc->ops = &pil_lpass_ops; |
| 164 | desc->owner = THIS_MODULE; |
Matt Wagantall | 4d89c2e | 2012-05-25 19:28:34 -0700 | [diff] [blame] | 165 | desc->proxy_timeout = PROXY_TIMEOUT_MS; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 166 | |
Matt Wagantall | 8c2246d | 2012-08-12 17:08:04 -0700 | [diff] [blame] | 167 | drv->core_clk = devm_clk_get(&pdev->dev, "core_clk"); |
| 168 | if (IS_ERR(drv->core_clk)) |
| 169 | return PTR_ERR(drv->core_clk); |
| 170 | |
| 171 | drv->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk"); |
| 172 | if (IS_ERR(drv->ahb_clk)) |
| 173 | return PTR_ERR(drv->ahb_clk); |
| 174 | |
| 175 | drv->axi_clk = devm_clk_get(&pdev->dev, "bus_clk"); |
| 176 | if (IS_ERR(drv->axi_clk)) |
| 177 | return PTR_ERR(drv->axi_clk); |
| 178 | |
| 179 | drv->reg_clk = devm_clk_get(&pdev->dev, "reg_clk"); |
| 180 | if (IS_ERR(drv->reg_clk)) |
| 181 | return PTR_ERR(drv->reg_clk); |
Matt Wagantall | 56865f0 | 2012-08-09 15:03:36 -0700 | [diff] [blame] | 182 | |
Matt Wagantall | c40e28f | 2012-07-26 11:52:02 -0700 | [diff] [blame] | 183 | if (pas_supported(PAS_Q6) > 0) { |
| 184 | desc->ops = &pil_lpass_ops_trusted; |
| 185 | dev_info(&pdev->dev, "using secure boot\n"); |
| 186 | } else { |
| 187 | desc->ops = &pil_lpass_ops; |
| 188 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 189 | } |
| 190 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 191 | drv->pil = msm_pil_register(desc); |
| 192 | if (IS_ERR(drv->pil)) |
| 193 | return PTR_ERR(drv->pil); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static int __devexit pil_lpass_driver_exit(struct platform_device *pdev) |
| 199 | { |
| 200 | struct q6v5_data *drv = platform_get_drvdata(pdev); |
| 201 | msm_pil_unregister(drv->pil); |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static struct of_device_id lpass_match_table[] = { |
| 206 | { .compatible = "qcom,pil-q6v5-lpass" }, |
| 207 | {} |
| 208 | }; |
| 209 | |
| 210 | static struct platform_driver pil_lpass_driver = { |
| 211 | .probe = pil_lpass_driver_probe, |
| 212 | .remove = __devexit_p(pil_lpass_driver_exit), |
| 213 | .driver = { |
| 214 | .name = "pil-q6v5-lpass", |
| 215 | .of_match_table = lpass_match_table, |
| 216 | .owner = THIS_MODULE, |
| 217 | }, |
| 218 | }; |
| 219 | |
| 220 | static int __init pil_lpass_init(void) |
| 221 | { |
| 222 | return platform_driver_register(&pil_lpass_driver); |
| 223 | } |
| 224 | module_init(pil_lpass_init); |
| 225 | |
| 226 | static void __exit pil_lpass_exit(void) |
| 227 | { |
| 228 | platform_driver_unregister(&pil_lpass_driver); |
| 229 | } |
| 230 | module_exit(pil_lpass_exit); |
| 231 | |
| 232 | MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors"); |
| 233 | MODULE_LICENSE("GPL v2"); |