]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/media/platform/marvell-ccic/mmp-driver.c
media: marvell-ccic/mmp: add devicetree support
[linux.git] / drivers / media / platform / marvell-ccic / mmp-driver.c
index bf4d4a47f1db70b8df46892d67638df82c1afd61..492663a8a29d49b09a9744e62654edf310ed4469 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
-#include <linux/platform_data/i2c-gpio.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
@@ -18,6 +17,8 @@
 #include <media/v4l2-device.h>
 #include <linux/platform_data/media/mmp-camera.h>
 #include <linux/device.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
 #include <linux/io.h>
@@ -32,7 +33,7 @@ MODULE_ALIAS("platform:mmp-camera");
 MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
 MODULE_LICENSE("GPL");
 
-static char *mcam_clks[] = {"CCICAXICLK", "CCICFUNCLK", "CCICPHYCLK"};
+static char *mcam_clks[] = {"axi", "func", "phy"};
 
 struct mmp_camera {
        void __iomem *power_regs;
@@ -103,7 +104,6 @@ static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev)
 #define CPU_SUBSYS_PMU_BASE    0xd4282800
 #define REG_CCIC_DCGCR         0x28    /* CCIC dyn clock gate ctrl reg */
 #define REG_CCIC_CRCR          0x50    /* CCIC clk reset ctrl reg      */
-#define REG_CCIC2_CRCR         0xf4    /* CCIC2 clk reset ctrl reg     */
 
 static void mcam_clk_enable(struct mcam_camera *mcam)
 {
@@ -144,6 +144,7 @@ static int mmpcam_power_up(struct mcam_camera *mcam)
  * Turn on power and clocks to the controller.
  */
        mmpcam_power_up_ctlr(cam);
+       mcam_clk_enable(mcam);
 /*
  * Provide power to the sensor.
  */
@@ -157,8 +158,6 @@ static int mmpcam_power_up(struct mcam_camera *mcam)
        gpio_set_value(pdata->sensor_reset_gpio, 1); /* reset is active low */
        mdelay(5);
 
-       mcam_clk_enable(mcam);
-
        return 0;
 }
 
@@ -181,28 +180,6 @@ static void mmpcam_power_down(struct mcam_camera *mcam)
        mcam_clk_disable(mcam);
 }
 
-static void mcam_ctlr_reset(struct mcam_camera *mcam)
-{
-       unsigned long val;
-       struct mmp_camera *cam = mcam_to_cam(mcam);
-
-       if (mcam->ccic_id) {
-               /*
-                * Using CCIC2
-                */
-               val = ioread32(cam->power_regs + REG_CCIC2_CRCR);
-               iowrite32(val & ~0x2, cam->power_regs + REG_CCIC2_CRCR);
-               iowrite32(val | 0x2, cam->power_regs + REG_CCIC2_CRCR);
-       } else {
-               /*
-                * Using CCIC1
-                */
-               val = ioread32(cam->power_regs + REG_CCIC_CRCR);
-               iowrite32(val & ~0x2, cam->power_regs + REG_CCIC_CRCR);
-               iowrite32(val | 0x2, cam->power_regs + REG_CCIC_CRCR);
-       }
-}
-
 /*
  * calc the dphy register values
  * There are three dphy registers being used.
@@ -219,6 +196,9 @@ static void mmpcam_calc_dphy(struct mcam_camera *mcam)
        struct device *dev = &cam->pdev->dev;
        unsigned long tx_clk_esc;
 
+       if (!pdata)
+               return;
+
        /*
         * If CSI2_DPHY3 is calculated dynamically,
         * pdata->lane_clk should be already set
@@ -337,10 +317,6 @@ static int mmpcam_probe(struct platform_device *pdev)
        struct mmp_camera_platform_data *pdata;
        int ret;
 
-       pdata = pdev->dev.platform_data;
-       if (!pdata)
-               return -ENODEV;
-
        cam = devm_kzalloc(&pdev->dev, sizeof(*cam), GFP_KERNEL);
        if (cam == NULL)
                return -ENOMEM;
@@ -350,23 +326,32 @@ static int mmpcam_probe(struct platform_device *pdev)
        mcam = &cam->mcam;
        mcam->plat_power_up = mmpcam_power_up;
        mcam->plat_power_down = mmpcam_power_down;
-       mcam->ctlr_reset = mcam_ctlr_reset;
        mcam->calc_dphy = mmpcam_calc_dphy;
        mcam->dev = &pdev->dev;
        mcam->use_smbus = 0;
-       mcam->ccic_id = pdev->id;
-       mcam->mclk_min = pdata->mclk_min;
-       mcam->mclk_src = pdata->mclk_src;
-       mcam->mclk_div = pdata->mclk_div;
-       mcam->bus_type = pdata->bus_type;
-       mcam->dphy = pdata->dphy;
+       pdata = pdev->dev.platform_data;
+       if (pdata) {
+               mcam->mclk_src = pdata->mclk_src;
+               mcam->mclk_div = pdata->mclk_div;
+               mcam->bus_type = pdata->bus_type;
+               mcam->dphy = pdata->dphy;
+               mcam->lane = pdata->lane;
+       } else {
+               /*
+                * These are values that used to be hardcoded in mcam-core and
+                * work well on a OLPC XO 1.75 with a parallel bus sensor.
+                * If it turns out other setups make sense, the values should
+                * be obtained from the device tree.
+                */
+               mcam->mclk_src = 3;
+               mcam->mclk_div = 2;
+       }
        if (mcam->bus_type == V4L2_MBUS_CSI2_DPHY) {
                cam->mipi_clk = devm_clk_get(mcam->dev, "mipi");
                if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0))
                        return PTR_ERR(cam->mipi_clk);
        }
        mcam->mipi_enabled = false;
-       mcam->lane = pdata->lane;
        mcam->chip_id = MCAM_ARMADA610;
        mcam->buffer_mode = B_DMA_sg;
        strscpy(mcam->bus_info, "platform:mmp-camera", sizeof(mcam->bus_info));
@@ -501,6 +486,10 @@ static int mmpcam_resume(struct platform_device *pdev)
 
 #endif
 
+static const struct of_device_id mmpcam_of_match[] = {
+       { .compatible = "marvell,mmp2-ccic", },
+       {},
+};
 
 static struct platform_driver mmpcam_driver = {
        .probe          = mmpcam_probe,
@@ -511,6 +500,7 @@ static struct platform_driver mmpcam_driver = {
 #endif
        .driver = {
                .name   = "mmp-camera",
+               .of_match_table = of_match_ptr(mmpcam_of_match),
        }
 };