Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/clk.h> |
| 20 | #include <linux/iommu.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/slab.h> |
| 24 | |
| 25 | #include <mach/iommu_hw-8xxx.h> |
| 26 | #include <mach/iommu.h> |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 27 | #include <mach/clk.h> |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 28 | |
| 29 | struct iommu_ctx_iter_data { |
| 30 | /* input */ |
| 31 | const char *name; |
| 32 | |
| 33 | /* output */ |
| 34 | struct device *dev; |
| 35 | }; |
| 36 | |
| 37 | static struct platform_device *msm_iommu_root_dev; |
| 38 | |
| 39 | static int each_iommu_ctx(struct device *dev, void *data) |
| 40 | { |
| 41 | struct iommu_ctx_iter_data *res = data; |
| 42 | struct msm_iommu_ctx_dev *c = dev->platform_data; |
| 43 | |
| 44 | if (!res || !c || !c->name || !res->name) |
| 45 | return -EINVAL; |
| 46 | |
| 47 | if (!strcmp(res->name, c->name)) { |
| 48 | res->dev = dev; |
| 49 | return 1; |
| 50 | } |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int each_iommu(struct device *dev, void *data) |
| 55 | { |
| 56 | return device_for_each_child(dev, data, each_iommu_ctx); |
| 57 | } |
| 58 | |
| 59 | struct device *msm_iommu_get_ctx(const char *ctx_name) |
| 60 | { |
| 61 | struct iommu_ctx_iter_data r; |
| 62 | int found; |
| 63 | |
| 64 | if (!msm_iommu_root_dev) { |
| 65 | pr_err("No root IOMMU device.\n"); |
| 66 | goto fail; |
| 67 | } |
| 68 | |
| 69 | r.name = ctx_name; |
| 70 | found = device_for_each_child(&msm_iommu_root_dev->dev, &r, each_iommu); |
| 71 | |
| 72 | if (!found) { |
| 73 | pr_err("Could not find context <%s>\n", ctx_name); |
| 74 | goto fail; |
| 75 | } |
| 76 | |
| 77 | return r.dev; |
| 78 | fail: |
| 79 | return NULL; |
| 80 | } |
| 81 | EXPORT_SYMBOL(msm_iommu_get_ctx); |
| 82 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 83 | static void msm_iommu_reset(void __iomem *base, int ncb) |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 84 | { |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 85 | int ctx; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 86 | |
| 87 | SET_RPUE(base, 0); |
| 88 | SET_RPUEIE(base, 0); |
| 89 | SET_ESRRESTORE(base, 0); |
| 90 | SET_TBE(base, 0); |
| 91 | SET_CR(base, 0); |
| 92 | SET_SPDMBE(base, 0); |
| 93 | SET_TESTBUSCR(base, 0); |
| 94 | SET_TLBRSW(base, 0); |
| 95 | SET_GLOBAL_TLBIALL(base, 0); |
| 96 | SET_RPU_ACR(base, 0); |
| 97 | SET_TLBLKCRWE(base, 1); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 98 | |
| 99 | for (ctx = 0; ctx < ncb; ctx++) { |
| 100 | SET_BPRCOSH(base, ctx, 0); |
| 101 | SET_BPRCISH(base, ctx, 0); |
| 102 | SET_BPRCNSH(base, ctx, 0); |
| 103 | SET_BPSHCFG(base, ctx, 0); |
| 104 | SET_BPMTCFG(base, ctx, 0); |
| 105 | SET_ACTLR(base, ctx, 0); |
| 106 | SET_SCTLR(base, ctx, 0); |
| 107 | SET_FSRRESTORE(base, ctx, 0); |
| 108 | SET_TTBR0(base, ctx, 0); |
| 109 | SET_TTBR1(base, ctx, 0); |
| 110 | SET_TTBCR(base, ctx, 0); |
| 111 | SET_BFBCR(base, ctx, 0); |
| 112 | SET_PAR(base, ctx, 0); |
| 113 | SET_FAR(base, ctx, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 114 | SET_TLBFLPTER(base, ctx, 0); |
| 115 | SET_TLBSLPTER(base, ctx, 0); |
| 116 | SET_TLBLKCR(base, ctx, 0); |
Stepan Moskovchenko | 0272fd6 | 2011-09-26 15:06:40 -0700 | [diff] [blame] | 117 | SET_CTX_TLBIALL(base, ctx, 0); |
| 118 | SET_TLBIVA(base, ctx, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 119 | SET_PRRR(base, ctx, 0); |
| 120 | SET_NMRR(base, ctx, 0); |
| 121 | SET_CONTEXTIDR(base, ctx, 0); |
| 122 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 123 | mb(); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static int msm_iommu_probe(struct platform_device *pdev) |
| 127 | { |
Vasiliy Kulikov | a86c44d | 2010-10-17 18:51:37 +0400 | [diff] [blame] | 128 | struct resource *r, *r2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 129 | struct clk *iommu_clk = NULL; |
| 130 | struct clk *iommu_pclk = NULL; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 131 | struct msm_iommu_drvdata *drvdata; |
| 132 | struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data; |
| 133 | void __iomem *regs_base; |
| 134 | resource_size_t len; |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 135 | int ret, irq, par; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 136 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 137 | if (pdev->id == -1) { |
| 138 | msm_iommu_root_dev = pdev; |
| 139 | return 0; |
| 140 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 141 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 142 | drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 143 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 144 | if (!drvdata) { |
| 145 | ret = -ENOMEM; |
| 146 | goto fail; |
| 147 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 148 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 149 | if (!iommu_dev) { |
| 150 | ret = -ENODEV; |
| 151 | goto fail; |
| 152 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 153 | |
Matt Wagantall | e604d71 | 2011-10-21 15:38:18 -0700 | [diff] [blame] | 154 | iommu_pclk = clk_get_sys("msm_iommu", "iface_clk"); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 155 | if (IS_ERR(iommu_pclk)) { |
| 156 | ret = -ENODEV; |
| 157 | goto fail; |
| 158 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 159 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 160 | ret = clk_enable(iommu_pclk); |
| 161 | if (ret) |
| 162 | goto fail_enable; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 163 | |
Matt Wagantall | e604d71 | 2011-10-21 15:38:18 -0700 | [diff] [blame] | 164 | iommu_clk = clk_get(&pdev->dev, "core_clk"); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 165 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 166 | if (!IS_ERR(iommu_clk)) { |
| 167 | if (clk_get_rate(iommu_clk) == 0) |
| 168 | clk_set_min_rate(iommu_clk, 1); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 169 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 170 | ret = clk_enable(iommu_clk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 171 | if (ret) { |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 172 | clk_put(iommu_clk); |
| 173 | goto fail_pclk; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 174 | } |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 175 | } else |
| 176 | iommu_clk = NULL; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 177 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 178 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "physbase"); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 179 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 180 | if (!r) { |
| 181 | ret = -ENODEV; |
| 182 | goto fail_clk; |
| 183 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 184 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 185 | len = resource_size(r); |
| 186 | |
| 187 | r2 = request_mem_region(r->start, len, r->name); |
| 188 | if (!r2) { |
| 189 | pr_err("Could not request memory region: start=%p, len=%d\n", |
| 190 | (void *) r->start, len); |
| 191 | ret = -EBUSY; |
| 192 | goto fail_clk; |
| 193 | } |
| 194 | |
| 195 | regs_base = ioremap(r2->start, len); |
| 196 | |
| 197 | if (!regs_base) { |
| 198 | pr_err("Could not ioremap: start=%p, len=%d\n", |
| 199 | (void *) r2->start, len); |
| 200 | ret = -EBUSY; |
| 201 | goto fail_mem; |
| 202 | } |
| 203 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 204 | irq = platform_get_irq_byname(pdev, "nonsecure_irq"); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 205 | if (irq < 0) { |
| 206 | ret = -ENODEV; |
| 207 | goto fail_io; |
| 208 | } |
| 209 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 210 | msm_iommu_reset(regs_base, iommu_dev->ncb); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 211 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 212 | SET_M(regs_base, 0, 1); |
| 213 | SET_PAR(regs_base, 0, 0); |
| 214 | SET_V2PCFG(regs_base, 0, 1); |
| 215 | SET_V2PPR(regs_base, 0, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 216 | mb(); |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 217 | par = GET_PAR(regs_base, 0); |
| 218 | SET_V2PCFG(regs_base, 0, 0); |
| 219 | SET_M(regs_base, 0, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 220 | mb(); |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 221 | |
| 222 | if (!par) { |
| 223 | pr_err("%s: Invalid PAR value detected\n", iommu_dev->name); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 224 | ret = -ENODEV; |
| 225 | goto fail_io; |
| 226 | } |
| 227 | |
| 228 | ret = request_irq(irq, msm_iommu_fault_handler, 0, |
| 229 | "msm_iommu_secure_irpt_handler", drvdata); |
| 230 | if (ret) { |
| 231 | pr_err("Request IRQ %d failed with ret=%d\n", irq, ret); |
| 232 | goto fail_io; |
| 233 | } |
| 234 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 235 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 236 | drvdata->pclk = iommu_pclk; |
| 237 | drvdata->clk = iommu_clk; |
| 238 | drvdata->base = regs_base; |
| 239 | drvdata->irq = irq; |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 240 | drvdata->ncb = iommu_dev->ncb; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 241 | drvdata->name = iommu_dev->name; |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 242 | |
| 243 | pr_info("device %s mapped at %p, irq %d with %d ctx banks\n", |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 244 | iommu_dev->name, regs_base, irq, iommu_dev->ncb); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 245 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 246 | platform_set_drvdata(pdev, drvdata); |
| 247 | |
| 248 | if (iommu_clk) |
| 249 | clk_disable(iommu_clk); |
| 250 | |
| 251 | clk_disable(iommu_pclk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 252 | |
| 253 | return 0; |
Vasiliy Kulikov | a86c44d | 2010-10-17 18:51:37 +0400 | [diff] [blame] | 254 | fail_io: |
| 255 | iounmap(regs_base); |
| 256 | fail_mem: |
| 257 | release_mem_region(r->start, len); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 258 | fail_clk: |
| 259 | if (iommu_clk) { |
| 260 | clk_disable(iommu_clk); |
| 261 | clk_put(iommu_clk); |
| 262 | } |
| 263 | fail_pclk: |
| 264 | clk_disable(iommu_pclk); |
| 265 | fail_enable: |
| 266 | clk_put(iommu_pclk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 267 | fail: |
| 268 | kfree(drvdata); |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | static int msm_iommu_remove(struct platform_device *pdev) |
| 273 | { |
| 274 | struct msm_iommu_drvdata *drv = NULL; |
| 275 | |
| 276 | drv = platform_get_drvdata(pdev); |
| 277 | if (drv) { |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 278 | if (drv->clk) |
| 279 | clk_put(drv->clk); |
| 280 | clk_put(drv->pclk); |
| 281 | memset(drv, 0, sizeof(*drv)); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 282 | kfree(drv); |
| 283 | platform_set_drvdata(pdev, NULL); |
| 284 | } |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | static int msm_iommu_ctx_probe(struct platform_device *pdev) |
| 289 | { |
| 290 | struct msm_iommu_ctx_dev *c = pdev->dev.platform_data; |
| 291 | struct msm_iommu_drvdata *drvdata; |
| 292 | struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL; |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 293 | int i, ret; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 294 | if (!c || !pdev->dev.parent) { |
| 295 | ret = -EINVAL; |
| 296 | goto fail; |
| 297 | } |
| 298 | |
| 299 | drvdata = dev_get_drvdata(pdev->dev.parent); |
| 300 | |
| 301 | if (!drvdata) { |
| 302 | ret = -ENODEV; |
| 303 | goto fail; |
| 304 | } |
| 305 | |
| 306 | ctx_drvdata = kzalloc(sizeof(*ctx_drvdata), GFP_KERNEL); |
| 307 | if (!ctx_drvdata) { |
| 308 | ret = -ENOMEM; |
| 309 | goto fail; |
| 310 | } |
| 311 | ctx_drvdata->num = c->num; |
| 312 | ctx_drvdata->pdev = pdev; |
| 313 | |
| 314 | INIT_LIST_HEAD(&ctx_drvdata->attached_elm); |
| 315 | platform_set_drvdata(pdev, ctx_drvdata); |
| 316 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 317 | ret = clk_enable(drvdata->pclk); |
| 318 | if (ret) |
| 319 | goto fail; |
| 320 | |
| 321 | if (drvdata->clk) { |
| 322 | ret = clk_enable(drvdata->clk); |
| 323 | if (ret) { |
| 324 | clk_disable(drvdata->pclk); |
| 325 | goto fail; |
| 326 | } |
| 327 | } |
| 328 | |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 329 | /* Program the M2V tables for this context */ |
| 330 | for (i = 0; i < MAX_NUM_MIDS; i++) { |
| 331 | int mid = c->mids[i]; |
| 332 | if (mid == -1) |
| 333 | break; |
| 334 | |
| 335 | SET_M2VCBR_N(drvdata->base, mid, 0); |
| 336 | SET_CBACR_N(drvdata->base, c->num, 0); |
| 337 | |
Stepan Moskovchenko | 01720e7 | 2011-10-21 14:27:29 -0700 | [diff] [blame] | 338 | /* Route page faults to the non-secure interrupt */ |
| 339 | SET_IRPTNDX(drvdata->base, c->num, 1); |
| 340 | |
Stepan Moskovchenko | 2e8c8ba | 2011-02-24 18:00:41 -0800 | [diff] [blame] | 341 | /* Set VMID = 0 */ |
| 342 | SET_VMID(drvdata->base, mid, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 343 | |
| 344 | /* Set the context number for that MID to this context */ |
| 345 | SET_CBNDX(drvdata->base, mid, c->num); |
| 346 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 347 | /* Set MID associated with this context bank to 0 */ |
Stepan Moskovchenko | 2e8c8ba | 2011-02-24 18:00:41 -0800 | [diff] [blame] | 348 | SET_CBVMID(drvdata->base, c->num, 0); |
| 349 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 350 | /* Set the ASID for TLB tagging for this context to 0 */ |
| 351 | SET_CONTEXTIDR_ASID(drvdata->base, c->num, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 352 | |
| 353 | /* Set security bit override to be Non-secure */ |
| 354 | SET_NSCFG(drvdata->base, mid, 3); |
| 355 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 356 | mb(); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 357 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 358 | if (drvdata->clk) |
| 359 | clk_disable(drvdata->clk); |
| 360 | clk_disable(drvdata->pclk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 361 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 362 | dev_info(&pdev->dev, "context %s using bank %d\n", c->name, c->num); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 363 | return 0; |
| 364 | fail: |
| 365 | kfree(ctx_drvdata); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | static int msm_iommu_ctx_remove(struct platform_device *pdev) |
| 370 | { |
| 371 | struct msm_iommu_ctx_drvdata *drv = NULL; |
| 372 | drv = platform_get_drvdata(pdev); |
| 373 | if (drv) { |
| 374 | memset(drv, 0, sizeof(struct msm_iommu_ctx_drvdata)); |
| 375 | kfree(drv); |
| 376 | platform_set_drvdata(pdev, NULL); |
| 377 | } |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static struct platform_driver msm_iommu_driver = { |
| 382 | .driver = { |
| 383 | .name = "msm_iommu", |
| 384 | }, |
| 385 | .probe = msm_iommu_probe, |
| 386 | .remove = msm_iommu_remove, |
| 387 | }; |
| 388 | |
| 389 | static struct platform_driver msm_iommu_ctx_driver = { |
| 390 | .driver = { |
| 391 | .name = "msm_iommu_ctx", |
| 392 | }, |
| 393 | .probe = msm_iommu_ctx_probe, |
| 394 | .remove = msm_iommu_ctx_remove, |
| 395 | }; |
| 396 | |
Stepan Moskovchenko | 516cbc7 | 2010-11-12 19:29:53 -0800 | [diff] [blame] | 397 | static int __init msm_iommu_driver_init(void) |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 398 | { |
| 399 | int ret; |
| 400 | ret = platform_driver_register(&msm_iommu_driver); |
| 401 | if (ret != 0) { |
| 402 | pr_err("Failed to register IOMMU driver\n"); |
| 403 | goto error; |
| 404 | } |
| 405 | |
| 406 | ret = platform_driver_register(&msm_iommu_ctx_driver); |
| 407 | if (ret != 0) { |
| 408 | pr_err("Failed to register IOMMU context driver\n"); |
| 409 | goto error; |
| 410 | } |
| 411 | |
| 412 | error: |
| 413 | return ret; |
| 414 | } |
| 415 | |
Stepan Moskovchenko | 516cbc7 | 2010-11-12 19:29:53 -0800 | [diff] [blame] | 416 | static void __exit msm_iommu_driver_exit(void) |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 417 | { |
| 418 | platform_driver_unregister(&msm_iommu_ctx_driver); |
| 419 | platform_driver_unregister(&msm_iommu_driver); |
| 420 | } |
| 421 | |
| 422 | subsys_initcall(msm_iommu_driver_init); |
| 423 | module_exit(msm_iommu_driver_exit); |
| 424 | |
| 425 | MODULE_LICENSE("GPL v2"); |
| 426 | MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>"); |