video: tegra: host: move resources to devices
Mayuresh Kulkarni [Wed, 18 Apr 2012 05:04:34 +0000 (10:04 +0530)]
- as of now the resources needed by all the host1x
modules are part of resource list of host1x device
- now that each module is a nvhost_device of its own,
so it should hold the resources it needs instead of
host1x device holding it for them
- each device that needs its resources gets it in its
_probe() using a helper API in bus_client.c

Bug 871237

Change-Id: Ia7c63fcf40cbc5db76d4d8339294a0e9ce75e352
Signed-off-by: Mayuresh Kulkarni <mkulkarni@nvidia.com>
Reviewed-on: http://git-master/r/94166
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

Conflicts:

drivers/video/tegra/host/isp/isp.c
drivers/video/tegra/host/mpe/mpe.c
drivers/video/tegra/host/vi/vi.c

Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>

Rebase-Id: R6409d9819b334064f24036251958a12a10db10d6

drivers/video/tegra/host/bus_client.c
drivers/video/tegra/host/bus_client.h
drivers/video/tegra/host/dev.c
drivers/video/tegra/host/isp/isp.c
drivers/video/tegra/host/mpe/mpe.c
drivers/video/tegra/host/nvhost_channel.c
drivers/video/tegra/host/vi/vi.c

index ff23ed1..9202120 100644 (file)
@@ -603,3 +603,37 @@ int nvhost_client_device_suspend(struct nvhost_device *dev)
 
        return ret;
 }
+
+int nvhost_client_device_get_resources(struct nvhost_device *dev)
+{
+       struct resource *r = NULL;
+       void __iomem *regs = NULL;
+       struct resource *reg_mem = NULL;
+
+       r = nvhost_get_resource(dev, IORESOURCE_MEM, 0);
+       if (!r)
+               goto fail;
+
+       reg_mem = request_mem_region(r->start, resource_size(r), dev->name);
+       if (!reg_mem)
+               goto fail;
+
+       regs = ioremap(r->start, resource_size(r));
+       if (!regs)
+               goto fail;
+
+       dev->reg_mem = reg_mem;
+       dev->aperture = regs;
+
+       return 0;
+
+fail:
+       if (reg_mem)
+               release_mem_region(r->start, resource_size(r));
+       if (regs)
+               iounmap(regs);
+
+       dev_err(&dev->dev, "failed to get register memory\n");
+
+       return -ENXIO;
+}
index 4e47071..adc3a70 100644 (file)
@@ -36,4 +36,6 @@ int nvhost_client_device_init(struct nvhost_device *dev);
 
 int nvhost_client_device_suspend(struct nvhost_device *dev);
 
+int nvhost_client_device_get_resources(struct nvhost_device *dev);
+
 #endif
index 213fbd6..f3cd67a 100644 (file)
@@ -412,31 +412,6 @@ static struct resource nvhost_resources[] = {
                .flags = IORESOURCE_MEM,
        },
        {
-               .start = TEGRA_DISPLAY_BASE,
-               .end = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       {
-               .start = TEGRA_DISPLAY2_BASE,
-               .end = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       {
-               .start = TEGRA_VI_BASE,
-               .end = TEGRA_VI_BASE + TEGRA_VI_SIZE - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       {
-               .start = TEGRA_ISP_BASE,
-               .end = TEGRA_ISP_BASE + TEGRA_ISP_SIZE - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       {
-               .start = TEGRA_MPE_BASE,
-               .end = TEGRA_MPE_BASE + TEGRA_MPE_SIZE - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       {
                .start = INT_SYNCPT_THRESH_BASE,
                .end = INT_SYNCPT_THRESH_BASE + INT_SYNCPT_THRESH_NR - 1,
                .flags = IORESOURCE_IRQ,
index 9a2654e..c21077e 100644 (file)
  */
 
 #include <linux/module.h>
+#include <linux/resource.h>
+
+#include <mach/iomap.h>
+
 #include "dev.h"
 #include "bus_client.h"
 
 static int isp_probe(struct nvhost_device *dev)
 {
+       int err = 0;
+
+       err = nvhost_client_device_get_resources(dev);
+       if (err)
+               return err;
+
        return nvhost_client_device_init(dev);
 }
 
@@ -44,6 +54,13 @@ static int isp_resume(struct nvhost_device *dev)
        return 0;
 }
 
+static struct resource isp_resources = {
+       .name = "regs",
+       .start = TEGRA_ISP_BASE,
+       .end = TEGRA_ISP_BASE + TEGRA_ISP_SIZE - 1,
+       .flags = IORESOURCE_MEM,
+};
+
 struct nvhost_device *isp_device;
 
 static struct nvhost_driver isp_driver = {
@@ -67,6 +84,8 @@ static int __init isp_init(void)
        if (!isp_device)
                return -ENXIO;
 
+       isp_device->resource = &isp_resources;
+       isp_device->num_resources = 1;
        err = nvhost_device_register(isp_device);
        if (err)
                return err;
index fede1f3..31aca92 100644 (file)
 #include "host1x/host1x_syncpt.h"
 #include "host1x/host1x_hwctx.h"
 #include "t20/t20.h"
+
 #include <linux/slab.h>
+#include <linux/resource.h>
+
+#include <mach/iomap.h>
+
 #include "bus_client.h"
 
 enum {
@@ -128,7 +133,6 @@ struct mpe_save_info {
        u32 h264_mode;
 };
 
-
 /*** restore ***/
 
 static unsigned int restore_size;
@@ -202,8 +206,8 @@ static void setup_restore(struct host1x_hwctx_handler *h, u32 *ptr)
        wmb();
 }
 
-
 /*** save ***/
+
 struct save_info {
        u32 *ptr;
        unsigned int save_count;
@@ -358,7 +362,6 @@ static void __init setup_save(struct host1x_hwctx_handler *h, u32 *ptr)
        restore_size = info.restore_count + RESTORE_END_SIZE;
 }
 
-
 static u32 calculate_mpe(u32 word, struct mpe_save_info *msi)
 {
        u32 buffer_full_read = msi->in[0] & 0x01ffffff;
@@ -425,7 +428,6 @@ static u32 *save_ram(u32 *ptr, unsigned int *pending,
        return ptr + words;
 }
 
-
 /*** ctxmpe ***/
 
 static struct nvhost_hwctx *ctxmpe_alloc(struct nvhost_hwctx_handler *h,
@@ -580,6 +582,12 @@ int nvhost_mpe_prepare_power_off(struct nvhost_device *dev)
 
 static int mpe_probe(struct nvhost_device *dev)
 {
+       int err = 0;
+
+       err = nvhost_client_device_get_resources(dev);
+       if (err)
+               return err;
+
        return nvhost_client_device_init(dev);
 }
 
@@ -600,6 +608,13 @@ static int mpe_resume(struct nvhost_device *dev)
        return 0;
 }
 
+static struct resource mpe_resources = {
+       .name = "regs",
+       .start = TEGRA_MPE_BASE,
+       .end = TEGRA_MPE_BASE + TEGRA_MPE_SIZE - 1,
+       .flags = IORESOURCE_MEM,
+};
+
 struct nvhost_device *mpe_device;
 
 static struct nvhost_driver mpe_driver = {
@@ -623,6 +638,9 @@ static int __init mpe_init(void)
        if (!mpe_device)
                return -ENXIO;
 
+       /* use ARRAY_SIZE macro if resources are more than 1 */
+       mpe_device->resource = &mpe_resources;
+       mpe_device->num_resources = 1;
        err = nvhost_device_register(mpe_device);
        if (err)
                return err;
index a5a4bd4..afbac6f 100644 (file)
@@ -34,9 +34,6 @@ int nvhost_channel_init(struct nvhost_channel *ch,
 {
        int err;
        struct nvhost_device *ndev;
-       struct resource *r = NULL;
-       void __iomem *regs = NULL;
-       struct resource *reg_mem = NULL;
 
        /* Link nvhost_device to nvhost_channel */
        err = host_channel_op(dev).init(ch, dev, index);
@@ -48,36 +45,7 @@ int nvhost_channel_init(struct nvhost_channel *ch,
        ndev = ch->dev;
        ndev->channel = ch;
 
-       /* Map IO memory related to nvhost_device */
-       if (ndev->moduleid != NVHOST_MODULE_NONE) {
-               /* First one is host1x - skip that */
-               r = nvhost_get_resource(dev->dev,
-                               IORESOURCE_MEM, ndev->moduleid + 1);
-               if (!r)
-                       goto fail;
-
-               reg_mem = request_mem_region(r->start,
-                               resource_size(r), ndev->name);
-               if (!reg_mem)
-                       goto fail;
-
-               regs = ioremap(r->start, resource_size(r));
-               if (!regs)
-                       goto fail;
-
-               ndev->reg_mem = reg_mem;
-               ndev->aperture = regs;
-       }
        return 0;
-
-fail:
-       if (reg_mem)
-               release_mem_region(r->start, resource_size(r));
-       if (regs)
-               iounmap(regs);
-       dev_err(&ndev->dev, "failed to get register memory\n");
-       return -ENXIO;
-
 }
 
 int nvhost_channel_submit(struct nvhost_job *job)
index 8d63cab..aa9e3b4 100644 (file)
  */
 
 #include <linux/module.h>
+#include <linux/resource.h>
+
+#include <mach/iomap.h>
+
 #include "dev.h"
 #include "bus_client.h"
 
 static int vi_probe(struct nvhost_device *dev)
 {
+       int err = 0;
+
+       err = nvhost_client_device_get_resources(dev);
+       if (err)
+               return err;
+
        return nvhost_client_device_init(dev);
 }
 
@@ -44,6 +54,13 @@ static int vi_resume(struct nvhost_device *dev)
        return 0;
 }
 
+static struct resource vi_resources = {
+       .name = "regs",
+       .start = TEGRA_VI_BASE,
+       .end = TEGRA_VI_BASE + TEGRA_VI_SIZE - 1,
+       .flags = IORESOURCE_MEM,
+};
+
 struct nvhost_device *vi_device;
 
 static struct nvhost_driver vi_driver = {
@@ -67,6 +84,8 @@ static int __init vi_init(void)
        if (!vi_device)
                return -ENXIO;
 
+       vi_device->resource = &vi_resources;
+       vi_device->num_resources = 1;
        err = nvhost_device_register(vi_device);
        if (err)
                return err;