]> 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 25a4e2b580f428d93c86085531a0912d8dae5d3c..492663a8a29d49b09a9744e62654edf310ed4469 100644 (file)
@@ -17,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>
@@ -31,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;
@@ -142,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.
  */
@@ -155,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;
 }
 
@@ -195,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
@@ -313,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;
@@ -329,17 +329,29 @@ static int mmpcam_probe(struct platform_device *pdev)
        mcam->calc_dphy = mmpcam_calc_dphy;
        mcam->dev = &pdev->dev;
        mcam->use_smbus = 0;
-       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));
@@ -474,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,
@@ -484,6 +500,7 @@ static struct platform_driver mmpcam_driver = {
 #endif
        .driver = {
                .name   = "mmp-camera",
+               .of_match_table = of_match_ptr(mmpcam_of_match),
        }
 };