Commit b61401ad authored by Stepan Moskovchenko's avatar Stepan Moskovchenko Committed by David Brown

msm: iommu: Rework clock logic and add IOMMU bus clock control

Clean up the clock control code in the probe calls, and add
support for controlling the clock for the IOMMU bus
interconnect. With the (proper) clock driver in place, the
clock control logic in the probe function can be made much
cleaner since it does not have to deal with the placeholder
driver anymore.
Signed-off-by: default avatarStepan Moskovchenko <stepanm@codeaurora.org>
Reviewed-by: default avatarTrilok Soni <tsoni@codeaurora.org>
Signed-off-by: default avatarDavid Brown <davidb@codeaurora.org>
parent 41f3f513
...@@ -280,7 +280,6 @@ static struct platform_device msm_root_iommu_dev = { ...@@ -280,7 +280,6 @@ static struct platform_device msm_root_iommu_dev = {
static struct msm_iommu_dev jpegd_iommu = { static struct msm_iommu_dev jpegd_iommu = {
.name = "jpegd", .name = "jpegd",
.clk_rate = -1
}; };
static struct msm_iommu_dev vpe_iommu = { static struct msm_iommu_dev vpe_iommu = {
...@@ -305,7 +304,6 @@ static struct msm_iommu_dev ijpeg_iommu = { ...@@ -305,7 +304,6 @@ static struct msm_iommu_dev ijpeg_iommu = {
static struct msm_iommu_dev vfe_iommu = { static struct msm_iommu_dev vfe_iommu = {
.name = "vfe", .name = "vfe",
.clk_rate = -1
}; };
static struct msm_iommu_dev vcodec_a_iommu = { static struct msm_iommu_dev vcodec_a_iommu = {
...@@ -318,17 +316,14 @@ static struct msm_iommu_dev vcodec_b_iommu = { ...@@ -318,17 +316,14 @@ static struct msm_iommu_dev vcodec_b_iommu = {
static struct msm_iommu_dev gfx3d_iommu = { static struct msm_iommu_dev gfx3d_iommu = {
.name = "gfx3d", .name = "gfx3d",
.clk_rate = 27000000
}; };
static struct msm_iommu_dev gfx2d0_iommu = { static struct msm_iommu_dev gfx2d0_iommu = {
.name = "gfx2d0", .name = "gfx2d0",
.clk_rate = 27000000
}; };
static struct msm_iommu_dev gfx2d1_iommu = { static struct msm_iommu_dev gfx2d1_iommu = {
.name = "gfx2d1", .name = "gfx2d1",
.clk_rate = 27000000
}; };
static struct platform_device msm_device_iommu_jpegd = { static struct platform_device msm_device_iommu_jpegd = {
......
...@@ -45,14 +45,9 @@ ...@@ -45,14 +45,9 @@
/** /**
* struct msm_iommu_dev - a single IOMMU hardware instance * struct msm_iommu_dev - a single IOMMU hardware instance
* name Human-readable name given to this IOMMU HW instance * name Human-readable name given to this IOMMU HW instance
* clk_rate Rate to set for this IOMMU's clock, if applicable to this
* particular IOMMU. 0 means don't set a rate.
* -1 means it is an AXI clock with no valid rate
*
*/ */
struct msm_iommu_dev { struct msm_iommu_dev {
const char *name; const char *name;
int clk_rate;
}; };
/** /**
......
/* Copyright (c) 2010, Code Aurora Forum. All rights reserved. /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and * it under the terms of the GNU General Public License version 2 and
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <mach/iommu_hw-8xxx.h> #include <mach/iommu_hw-8xxx.h>
#include <mach/iommu.h> #include <mach/iommu.h>
#include <mach/clk.h>
struct iommu_ctx_iter_data { struct iommu_ctx_iter_data {
/* input */ /* input */
...@@ -130,117 +131,134 @@ static int msm_iommu_probe(struct platform_device *pdev) ...@@ -130,117 +131,134 @@ static int msm_iommu_probe(struct platform_device *pdev)
{ {
struct resource *r, *r2; struct resource *r, *r2;
struct clk *iommu_clk; struct clk *iommu_clk;
struct clk *iommu_pclk;
struct msm_iommu_drvdata *drvdata; struct msm_iommu_drvdata *drvdata;
struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data; struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data;
void __iomem *regs_base; void __iomem *regs_base;
resource_size_t len; resource_size_t len;
int ret = 0, ncb, nm2v, irq; int ret, ncb, nm2v, irq;
if (pdev->id != -1) { if (pdev->id == -1) {
drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); msm_iommu_root_dev = pdev;
return 0;
}
if (!drvdata) { drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
ret = -ENOMEM;
goto fail;
}
if (!iommu_dev) { if (!drvdata) {
ret = -ENODEV; ret = -ENOMEM;
goto fail; goto fail;
} }
if (!iommu_dev) {
ret = -ENODEV;
goto fail;
}
if (iommu_dev->clk_rate != 0) { iommu_pclk = clk_get(NULL, "smmu_pclk");
iommu_clk = clk_get(&pdev->dev, "iommu_clk"); if (IS_ERR(iommu_pclk)) {
ret = -ENODEV;
if (IS_ERR(iommu_clk)) { goto fail;
ret = -ENODEV; }
goto fail;
} ret = clk_enable(iommu_pclk);
if (ret)
if (iommu_dev->clk_rate > 0) { goto fail_enable;
ret = clk_set_rate(iommu_clk,
iommu_dev->clk_rate); iommu_clk = clk_get(&pdev->dev, "iommu_clk");
if (ret) {
clk_put(iommu_clk); if (!IS_ERR(iommu_clk)) {
goto fail; if (clk_get_rate(iommu_clk) == 0)
} clk_set_min_rate(iommu_clk, 1);
}
ret = clk_enable(iommu_clk);
ret = clk_enable(iommu_clk); if (ret) {
if (ret) {
clk_put(iommu_clk);
goto fail;
}
clk_put(iommu_clk); clk_put(iommu_clk);
goto fail_pclk;
} }
} else
iommu_clk = NULL;
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "physbase");
"physbase");
if (!r) {
ret = -ENODEV;
goto fail;
}
len = r->end - r->start + 1; if (!r) {
ret = -ENODEV;
goto fail_clk;
}
r2 = request_mem_region(r->start, len, r->name); len = resource_size(r);
if (!r2) {
pr_err("Could not request memory region: "
"start=%p, len=%d\n", (void *) r->start, len);
ret = -EBUSY;
goto fail;
}
regs_base = ioremap(r2->start, len); r2 = request_mem_region(r->start, len, r->name);
if (!r2) {
pr_err("Could not request memory region: start=%p, len=%d\n",
(void *) r->start, len);
ret = -EBUSY;
goto fail_clk;
}
if (!regs_base) { regs_base = ioremap(r2->start, len);
pr_err("Could not ioremap: start=%p, len=%d\n",
(void *) r2->start, len);
ret = -EBUSY;
goto fail_mem;
}
irq = platform_get_irq_byname(pdev, "secure_irq"); if (!regs_base) {
if (irq < 0) { pr_err("Could not ioremap: start=%p, len=%d\n",
ret = -ENODEV; (void *) r2->start, len);
goto fail_io; ret = -EBUSY;
} goto fail_mem;
}
irq = platform_get_irq_byname(pdev, "secure_irq");
if (irq < 0) {
ret = -ENODEV;
goto fail_io;
}
mb(); mb();
if (GET_IDR(regs_base) == 0) { if (GET_IDR(regs_base) == 0) {
pr_err("Invalid IDR value detected\n"); pr_err("Invalid IDR value detected\n");
ret = -ENODEV; ret = -ENODEV;
goto fail_io; goto fail_io;
} }
ret = request_irq(irq, msm_iommu_fault_handler, 0, ret = request_irq(irq, msm_iommu_fault_handler, 0,
"msm_iommu_secure_irpt_handler", drvdata); "msm_iommu_secure_irpt_handler", drvdata);
if (ret) { if (ret) {
pr_err("Request IRQ %d failed with ret=%d\n", irq, ret); pr_err("Request IRQ %d failed with ret=%d\n", irq, ret);
goto fail_io; goto fail_io;
} }
msm_iommu_reset(regs_base); msm_iommu_reset(regs_base);
drvdata->base = regs_base; drvdata->pclk = iommu_pclk;
drvdata->irq = irq; drvdata->clk = iommu_clk;
drvdata->base = regs_base;
drvdata->irq = irq;
nm2v = GET_NM2VCBMT((unsigned long) regs_base); nm2v = GET_NM2VCBMT((unsigned long) regs_base);
ncb = GET_NCB((unsigned long) regs_base); ncb = GET_NCB((unsigned long) regs_base);
pr_info("device %s mapped at %p, irq %d with %d ctx banks\n", pr_info("device %s mapped at %p, irq %d with %d ctx banks\n",
iommu_dev->name, regs_base, irq, ncb+1); iommu_dev->name, regs_base, irq, ncb+1);
platform_set_drvdata(pdev, drvdata); platform_set_drvdata(pdev, drvdata);
} else
msm_iommu_root_dev = pdev;
return 0; if (iommu_clk)
clk_disable(iommu_clk);
clk_disable(iommu_pclk);
return 0;
fail_io: fail_io:
iounmap(regs_base); iounmap(regs_base);
fail_mem: fail_mem:
release_mem_region(r->start, len); release_mem_region(r->start, len);
fail_clk:
if (iommu_clk) {
clk_disable(iommu_clk);
clk_put(iommu_clk);
}
fail_pclk:
clk_disable(iommu_pclk);
fail_enable:
clk_put(iommu_pclk);
fail: fail:
kfree(drvdata); kfree(drvdata);
return ret; return ret;
...@@ -252,7 +270,10 @@ static int msm_iommu_remove(struct platform_device *pdev) ...@@ -252,7 +270,10 @@ static int msm_iommu_remove(struct platform_device *pdev)
drv = platform_get_drvdata(pdev); drv = platform_get_drvdata(pdev);
if (drv) { if (drv) {
memset(drv, 0, sizeof(struct msm_iommu_drvdata)); if (drv->clk)
clk_put(drv->clk);
clk_put(drv->pclk);
memset(drv, 0, sizeof(*drv));
kfree(drv); kfree(drv);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
} }
...@@ -264,7 +285,7 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev) ...@@ -264,7 +285,7 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
struct msm_iommu_ctx_dev *c = pdev->dev.platform_data; struct msm_iommu_ctx_dev *c = pdev->dev.platform_data;
struct msm_iommu_drvdata *drvdata; struct msm_iommu_drvdata *drvdata;
struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL; struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL;
int i, ret = 0; int i, ret;
if (!c || !pdev->dev.parent) { if (!c || !pdev->dev.parent) {
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
...@@ -288,6 +309,18 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev) ...@@ -288,6 +309,18 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
INIT_LIST_HEAD(&ctx_drvdata->attached_elm); INIT_LIST_HEAD(&ctx_drvdata->attached_elm);
platform_set_drvdata(pdev, ctx_drvdata); platform_set_drvdata(pdev, ctx_drvdata);
ret = clk_enable(drvdata->pclk);
if (ret)
goto fail;
if (drvdata->clk) {
ret = clk_enable(drvdata->clk);
if (ret) {
clk_disable(drvdata->pclk);
goto fail;
}
}
/* Program the M2V tables for this context */ /* Program the M2V tables for this context */
for (i = 0; i < MAX_NUM_MIDS; i++) { for (i = 0; i < MAX_NUM_MIDS; i++) {
int mid = c->mids[i]; int mid = c->mids[i];
...@@ -310,8 +343,11 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev) ...@@ -310,8 +343,11 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
SET_NSCFG(drvdata->base, mid, 3); SET_NSCFG(drvdata->base, mid, 3);
} }
pr_info("context device %s with bank index %d\n", c->name, c->num); if (drvdata->clk)
clk_disable(drvdata->clk);
clk_disable(drvdata->pclk);
dev_info(&pdev->dev, "context %s using bank %d\n", c->name, c->num);
return 0; return 0;
fail: fail:
kfree(ctx_drvdata); kfree(ctx_drvdata);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment