driver: vi: tegra_camera: correct pdev->id for DT
Bryan Wu [Fri, 21 Feb 2014 18:45:03 +0000 (10:45 -0800)]
DT will initialize the pdev->id as -1 for both vi.0 and vi.1. This
will cause several subtle issues since checking pdev->id is used a
in VI and Tegra V4L2 camera drivers.

Set the pdev->id as the right value during probing for DT case. Then
no change is need for others

drivers/video/tegra/host/vi/vi.c change was cherry picked from commit
b9de88f6b2362532edbab617fd2d824b83fcf059

Bug 1463966

Change-Id: I8adf124c4d3489e9c06abbecb6d3587437954c50
Signed-off-by: Bryan Wu <pengw@nvidia.com>
Reviewed-on: http://git-master/r/373000
(cherry picked from commit 4ca388fb943d17c7f7e8992fba04aac38714fdb2)
Reviewed-on: http://git-master/r/378471
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>

drivers/media/platform/soc_camera/tegra_camera/common.c
drivers/media/platform/soc_camera/tegra_camera/vi2.c
drivers/video/tegra/host/vi/tegra_vi.c
drivers/video/tegra/host/vi/vi.c

index d257115..50ba778 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2013-2014, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -802,6 +802,12 @@ static int tegra_camera_probe(struct platform_device *pdev)
                match = of_match_device(tegra_vi_of_match, &pdev->dev);
                if (match)
                        ndata = (struct nvhost_device_data *) match->data;
+
+               /*
+                * Device Tree will initialize this ID as -1
+                * Set it to the right value for future usage
+                */
+               pdev->id = pdev->dev.id;
        } else
                ndata = pdev->dev.platform_data;
 
@@ -823,7 +829,7 @@ static int tegra_camera_probe(struct platform_device *pdev)
 
        cam->ici.priv = cam;
        cam->ici.v4l2_dev.dev = &pdev->dev;
-       cam->ici.nr = pdev->dev.id;
+       cam->ici.nr = pdev->id;
        cam->ici.drv_name = dev_name(&pdev->dev);
        cam->ici.ops = &tegra_soc_camera_host_ops;
 
index f58c03b..60bdaa4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2013-2014, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -329,20 +329,10 @@ static struct tegra_camera_clk vi2_clks1[] = {
 static int vi2_clks_init(struct tegra_camera_dev *cam)
 {
        struct platform_device *pdev = cam->ndev;
-       char devname[MAX_DEVID_LENGTH];
-       const char *pdev_name;
        struct tegra_camera_clk *clks;
-       int i, dev_id, ret;
-
-       pdev_name = dev_name(&pdev->dev);
-       ret = sscanf(pdev_name, "vi.%1d", &dev_id);
-       if (ret != 1) {
-               dev_err(&pdev->dev, "Read dev_id failed!\n");
-               return -ENODEV;
-       }
-       snprintf(devname, MAX_DEVID_LENGTH, "tegra_%s", pdev_name);
+       int i;
 
-       switch (dev_id) {
+       switch (pdev->id) {
        case 0:
                cam->num_clks = ARRAY_SIZE(vi2_clks0);
                cam->clks = vi2_clks0;
@@ -352,16 +342,19 @@ static int vi2_clks_init(struct tegra_camera_dev *cam)
                cam->clks = vi2_clks1;
                break;
        default:
-               dev_err(&pdev->dev, "Wrong device ID %d\n", dev_id);
+               dev_err(&pdev->dev, "Wrong device ID %d\n", pdev->id);
                return -ENODEV;
        }
 
        for (i = 0; i < cam->num_clks; i++) {
                clks = &cam->clks[i];
 
-               if (clks->use_devname)
+               if (clks->use_devname) {
+                       char devname[MAX_DEVID_LENGTH];
+                       snprintf(devname, MAX_DEVID_LENGTH,
+                                "tegra_%s", dev_name(&pdev->dev));
                        clks->clk = clk_get_sys(devname, clks->name);
-               else
+               } else
                        clks->clk = clk_get(&pdev->dev, clks->name);
                if (IS_ERR_OR_NULL(clks->clk)) {
                        dev_err(&pdev->dev, "Failed to get clock %s.\n",
index a31b23b..891dfed 100644 (file)
@@ -76,15 +76,8 @@ void nvhost_vi_deinit(struct platform_device *dev)
 
 int nvhost_vi_finalize_poweron(struct platform_device *dev)
 {
-       int ret = 0, dev_id;
+       int ret = 0;
        struct vi *tegra_vi;
-       const char *devname = dev_name(&dev->dev);
-
-       ret = sscanf(devname, "vi.%1d", &dev_id);
-       if (ret != 1) {
-               dev_err(&dev->dev, "Read dev_id failed!\n");
-               return -ENODEV;
-       }
 
        tegra_vi = (struct vi *)nvhost_get_private_data(dev);
        if (tegra_vi && tegra_vi->reg) {
@@ -98,7 +91,7 @@ int nvhost_vi_finalize_poweron(struct platform_device *dev)
        }
 
        /* Only do this for vi.0 not for slave device vi.1 */
-       if (dev_id == 0)
+       if (dev->id == 0)
                host1x_writel(dev, T12_VI_CFG_CG_CTRL, T12_CG_2ND_LEVEL_EN);
 
  fail:
index b78550f..1721c6c 100644 (file)
@@ -109,6 +109,11 @@ static int vi_probe(struct platform_device *dev)
                match = of_match_device(tegra_vi_of_match, &dev->dev);
                if (match)
                        pdata = (struct nvhost_device_data *)match->data;
+
+               /* DT initializes it to -1, use below WAR to set correct value.
+                * TODO: Once proper fix for dev-id goes in, remove it.
+                */
+               dev->id = dev->dev.id;
        } else
                pdata = (struct nvhost_device_data *)dev->dev.platform_data;