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> |
| 18 | #include <linux/iopoll.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/of.h> |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 21 | #include <linux/clk.h> |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 22 | |
| 23 | #include "peripheral-loader.h" |
| 24 | #include "pil-q6v5.h" |
| 25 | |
| 26 | /* Register Offsets */ |
| 27 | #define QDSP6SS_RST_EVB 0x010 |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 28 | #define AXI_HALTREQ 0x0 |
| 29 | #define AXI_HALTACK 0x4 |
| 30 | #define AXI_IDLE 0x8 |
| 31 | |
| 32 | #define HALT_ACK_TIMEOUT_US 100000 |
| 33 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 34 | static int pil_lpass_shutdown(struct pil_desc *pil) |
| 35 | { |
| 36 | struct q6v5_data *drv = dev_get_drvdata(pil->dev); |
| 37 | int ret; |
| 38 | u32 status; |
| 39 | |
| 40 | writel_relaxed(1, drv->axi_halt_base + AXI_HALTREQ); |
| 41 | ret = readl_poll_timeout(drv->axi_halt_base + AXI_HALTACK, |
| 42 | status, status, 50, HALT_ACK_TIMEOUT_US); |
| 43 | if (ret) |
| 44 | dev_err(pil->dev, "Port halt timeout\n"); |
| 45 | else if (!readl_relaxed(drv->axi_halt_base + AXI_IDLE)) |
| 46 | dev_err(pil->dev, "Port halt failed\n"); |
| 47 | writel_relaxed(0, drv->axi_halt_base + AXI_HALTREQ); |
| 48 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 49 | /* |
| 50 | * If the shutdown function is called before the reset function, clocks |
| 51 | * will not be enabled yet. Enable them here so that register writes |
| 52 | * performed during the shutdown succeed. |
| 53 | */ |
| 54 | if (drv->is_booted == false) |
| 55 | pil_q6v5_enable_clks(pil); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 56 | |
| 57 | pil_q6v5_shutdown(pil); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 58 | pil_q6v5_disable_clks(pil); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 59 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 60 | drv->is_booted = false; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int pil_lpass_reset(struct pil_desc *pil) |
| 66 | { |
| 67 | struct q6v5_data *drv = dev_get_drvdata(pil->dev); |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 68 | int ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 69 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 70 | ret = pil_q6v5_enable_clks(pil); |
| 71 | if (ret) |
| 72 | return ret; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 73 | |
| 74 | /* Program Image Address */ |
| 75 | writel_relaxed(((drv->start_addr >> 4) & 0x0FFFFFF0), |
| 76 | drv->reg_base + QDSP6SS_RST_EVB); |
| 77 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 78 | ret = pil_q6v5_reset(pil); |
| 79 | if (ret) { |
| 80 | pil_q6v5_disable_clks(pil); |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | drv->is_booted = true; |
| 85 | |
| 86 | return 0; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static struct pil_reset_ops pil_lpass_ops = { |
| 90 | .init_image = pil_q6v5_init_image, |
| 91 | .proxy_vote = pil_q6v5_make_proxy_votes, |
| 92 | .proxy_unvote = pil_q6v5_remove_proxy_votes, |
| 93 | .auth_and_reset = pil_lpass_reset, |
| 94 | .shutdown = pil_lpass_shutdown, |
| 95 | }; |
| 96 | |
| 97 | static int __devinit pil_lpass_driver_probe(struct platform_device *pdev) |
| 98 | { |
| 99 | struct q6v5_data *drv; |
| 100 | struct pil_desc *desc; |
| 101 | struct resource *res; |
| 102 | |
| 103 | desc = pil_q6v5_init(pdev); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 104 | if (IS_ERR(desc)) |
| 105 | return PTR_ERR(desc); |
| 106 | |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 107 | drv = platform_get_drvdata(pdev); |
Matt Wagantall | 55252f1 | 2012-05-02 18:02:54 -0700 | [diff] [blame] | 108 | if (drv == NULL) |
| 109 | return -ENODEV; |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 110 | |
| 111 | desc->ops = &pil_lpass_ops; |
| 112 | desc->owner = THIS_MODULE; |
| 113 | |
Matt Wagantall | d41ce77 | 2012-05-10 23:16:41 -0700 | [diff] [blame^] | 114 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Matt Wagantall | c2bbdc3 | 2012-03-21 19:44:50 -0700 | [diff] [blame] | 115 | drv->axi_halt_base = devm_ioremap(&pdev->dev, res->start, |
| 116 | resource_size(res)); |
| 117 | if (!drv->axi_halt_base) |
| 118 | return -ENOMEM; |
| 119 | |
| 120 | drv->pil = msm_pil_register(desc); |
| 121 | if (IS_ERR(drv->pil)) |
| 122 | return PTR_ERR(drv->pil); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static int __devexit pil_lpass_driver_exit(struct platform_device *pdev) |
| 128 | { |
| 129 | struct q6v5_data *drv = platform_get_drvdata(pdev); |
| 130 | msm_pil_unregister(drv->pil); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static struct of_device_id lpass_match_table[] = { |
| 135 | { .compatible = "qcom,pil-q6v5-lpass" }, |
| 136 | {} |
| 137 | }; |
| 138 | |
| 139 | static struct platform_driver pil_lpass_driver = { |
| 140 | .probe = pil_lpass_driver_probe, |
| 141 | .remove = __devexit_p(pil_lpass_driver_exit), |
| 142 | .driver = { |
| 143 | .name = "pil-q6v5-lpass", |
| 144 | .of_match_table = lpass_match_table, |
| 145 | .owner = THIS_MODULE, |
| 146 | }, |
| 147 | }; |
| 148 | |
| 149 | static int __init pil_lpass_init(void) |
| 150 | { |
| 151 | return platform_driver_register(&pil_lpass_driver); |
| 152 | } |
| 153 | module_init(pil_lpass_init); |
| 154 | |
| 155 | static void __exit pil_lpass_exit(void) |
| 156 | { |
| 157 | platform_driver_unregister(&pil_lpass_driver); |
| 158 | } |
| 159 | module_exit(pil_lpass_exit); |
| 160 | |
| 161 | MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors"); |
| 162 | MODULE_LICENSE("GPL v2"); |