Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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 | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 21 | |
| 22 | #include "peripheral-loader.h" |
| 23 | #include "pil-q6v5.h" |
| 24 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 25 | #define QDSP6SS_RST_EVB 0x010 |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 26 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 27 | static int pil_lpass_shutdown(struct pil_desc *pil) |
| 28 | { |
| 29 | struct q6v5_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 30 | |
Matt Wagantall | b774799 | 2012-05-11 19:37:51 -0700 | [diff] [blame] | 31 | pil_q6v5_halt_axi_port(pil, drv->axi_halt_base); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 32 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 33 | /* |
| 34 | * If the shutdown function is called before the reset function, clocks |
| 35 | * will not be enabled yet. Enable them here so that register writes |
| 36 | * performed during the shutdown succeed. |
| 37 | */ |
| 38 | if (drv->is_booted == false) |
| 39 | pil_q6v5_enable_clks(pil); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 40 | |
| 41 | pil_q6v5_shutdown(pil); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 42 | pil_q6v5_disable_clks(pil); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 43 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 44 | drv->is_booted = false; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int pil_lpass_reset(struct pil_desc *pil) |
| 50 | { |
| 51 | struct q6v5_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 52 | int ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 53 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 54 | ret = pil_q6v5_enable_clks(pil); |
| 55 | if (ret) |
| 56 | return ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 57 | |
| 58 | /* Program Image Address */ |
| 59 | writel_relaxed(((drv->start_addr >> 4) & 0x0FFFFFF0), |
| 60 | drv->reg_base + QDSP6SS_RST_EVB); |
| 61 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame] | 62 | ret = pil_q6v5_reset(pil); |
| 63 | if (ret) { |
| 64 | pil_q6v5_disable_clks(pil); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | drv->is_booted = true; |
| 69 | |
| 70 | return 0; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static struct pil_reset_ops pil_lpass_ops = { |
| 74 | .init_image = pil_q6v5_init_image, |
| 75 | .proxy_vote = pil_q6v5_make_proxy_votes, |
| 76 | .proxy_unvote = pil_q6v5_remove_proxy_votes, |
| 77 | .auth_and_reset = pil_lpass_reset, |
| 78 | .shutdown = pil_lpass_shutdown, |
| 79 | }; |
| 80 | |
| 81 | static int __devinit pil_lpass_driver_probe(struct platform_device *pdev) |
| 82 | { |
| 83 | struct q6v5_data *drv; |
| 84 | struct pil_desc *desc; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 85 | |
| 86 | desc = pil_q6v5_init(pdev); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 87 | if (IS_ERR(desc)) |
| 88 | return PTR_ERR(desc); |
| 89 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 90 | drv = platform_get_drvdata(pdev); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 91 | if (drv == NULL) |
| 92 | return -ENODEV; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 93 | |
| 94 | desc->ops = &pil_lpass_ops; |
| 95 | desc->owner = THIS_MODULE; |
| 96 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 97 | drv->pil = msm_pil_register(desc); |
| 98 | if (IS_ERR(drv->pil)) |
| 99 | return PTR_ERR(drv->pil); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int __devexit pil_lpass_driver_exit(struct platform_device *pdev) |
| 105 | { |
| 106 | struct q6v5_data *drv = platform_get_drvdata(pdev); |
| 107 | msm_pil_unregister(drv->pil); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static struct of_device_id lpass_match_table[] = { |
| 112 | { .compatible = "qcom,pil-q6v5-lpass" }, |
| 113 | {} |
| 114 | }; |
| 115 | |
| 116 | static struct platform_driver pil_lpass_driver = { |
| 117 | .probe = pil_lpass_driver_probe, |
| 118 | .remove = __devexit_p(pil_lpass_driver_exit), |
| 119 | .driver = { |
| 120 | .name = "pil-q6v5-lpass", |
| 121 | .of_match_table = lpass_match_table, |
| 122 | .owner = THIS_MODULE, |
| 123 | }, |
| 124 | }; |
| 125 | |
| 126 | static int __init pil_lpass_init(void) |
| 127 | { |
| 128 | return platform_driver_register(&pil_lpass_driver); |
| 129 | } |
| 130 | module_init(pil_lpass_init); |
| 131 | |
| 132 | static void __exit pil_lpass_exit(void) |
| 133 | { |
| 134 | platform_driver_unregister(&pil_lpass_driver); |
| 135 | } |
| 136 | module_exit(pil_lpass_exit); |
| 137 | |
| 138 | MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors"); |
| 139 | MODULE_LICENSE("GPL v2"); |