drm/komeda: Add DT parsing
authorjames qian wang (Arm Technology China) <james.qian.wang@arm.com>
Thu, 3 Jan 2019 11:40:38 +0000 (11:40 +0000)
committerLiviu Dudau <Liviu.Dudau@arm.com>
Mon, 14 Jan 2019 11:09:37 +0000 (11:09 +0000)
Parse DT and initialize corresponding dev/pipeline attributes.

Changes in v4:
- Rebase.

Changes in v3:
- Fixed style problem found by checkpatch.pl --strict.

Changes in v2:
- Unified abbreviation of "pipeline" to "pipe".

Signed-off-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Liviu Dudau <liviu.dudau@arm.com>
drivers/gpu/drm/arm/display/komeda/komeda_dev.c
drivers/gpu/drm/arm/display/komeda/komeda_dev.h
drivers/gpu/drm/arm/display/komeda/komeda_pipeline.c
drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h

index 4dec259..7257248 100644 (file)
@@ -9,6 +9,76 @@
 #include <linux/of_graph.h>
 #include "komeda_dev.h"
 
+static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_node *np)
+{
+       struct komeda_pipeline *pipe;
+       struct clk *clk;
+       u32 pipe_id;
+       int ret = 0;
+
+       ret = of_property_read_u32(np, "reg", &pipe_id);
+       if (ret != 0 || pipe_id >= mdev->n_pipelines)
+               return -EINVAL;
+
+       pipe = mdev->pipelines[pipe_id];
+
+       clk = of_clk_get_by_name(np, "aclk");
+       if (IS_ERR(clk)) {
+               DRM_ERROR("get aclk for pipeline %d failed!\n", pipe_id);
+               return PTR_ERR(clk);
+       }
+       pipe->aclk = clk;
+
+       clk = of_clk_get_by_name(np, "pxclk");
+       if (IS_ERR(clk)) {
+               DRM_ERROR("get pxclk for pipeline %d failed!\n", pipe_id);
+               return PTR_ERR(clk);
+       }
+       pipe->pxlclk = clk;
+
+       /* enum ports */
+       pipe->of_output_dev =
+               of_graph_get_remote_node(np, KOMEDA_OF_PORT_OUTPUT, 0);
+       pipe->of_output_port =
+               of_graph_get_port_by_id(np, KOMEDA_OF_PORT_OUTPUT);
+
+       pipe->of_node = np;
+
+       return 0;
+}
+
+static int komeda_parse_dt(struct device *dev, struct komeda_dev *mdev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct device_node *child, *np = dev->of_node;
+       struct clk *clk;
+       int ret;
+
+       clk = devm_clk_get(dev, "mclk");
+       if (IS_ERR(clk))
+               return PTR_ERR(clk);
+
+       mdev->mclk = clk;
+       mdev->irq  = platform_get_irq(pdev, 0);
+       if (mdev->irq < 0) {
+               DRM_ERROR("could not get IRQ number.\n");
+               return mdev->irq;
+       }
+
+       for_each_available_child_of_node(np, child) {
+               if (of_node_cmp(child->name, "pipeline") == 0) {
+                       ret = komeda_parse_pipe_dt(mdev, child);
+                       if (ret) {
+                               DRM_ERROR("parse pipeline dt error!\n");
+                               of_node_put(child);
+                               break;
+                       }
+               }
+       }
+
+       return ret;
+}
+
 struct komeda_dev *komeda_dev_create(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
@@ -71,6 +141,12 @@ struct komeda_dev *komeda_dev_create(struct device *dev)
                goto err_cleanup;
        }
 
+       err = komeda_parse_dt(dev, mdev);
+       if (err) {
+               DRM_ERROR("parse device tree failed.\n");
+               goto err_cleanup;
+       }
+
        return mdev;
 
 err_cleanup:
index b48d711..9c43565 100644 (file)
@@ -72,6 +72,9 @@ struct komeda_dev {
        /** @mck: HW main engine clk */
        struct clk *mclk;
 
+       /** @irq: irq number */
+       u32 irq;
+
        int n_pipelines;
        struct komeda_pipeline *pipelines[KOMEDA_MAX_PIPELINES];
 
index 179122f..edb1cd7 100644 (file)
@@ -53,6 +53,10 @@ void komeda_pipeline_destroy(struct komeda_dev *mdev,
        clk_put(pipe->pxlclk);
        clk_put(pipe->aclk);
 
+       of_node_put(pipe->of_output_dev);
+       of_node_put(pipe->of_output_port);
+       of_node_put(pipe->of_node);
+
        devm_kfree(mdev->dev, pipe);
 }
 
index 7daba0e..d2222e4 100644 (file)
@@ -288,6 +288,13 @@ struct komeda_pipeline {
        struct komeda_improc *improc;
        struct komeda_timing_ctrlr *ctrlr;
        struct komeda_pipeline_funcs *funcs; /* private pipeline functions */
+
+       /** @of_node: pipeline dt node */
+       struct device_node *of_node;
+       /** @of_output_port: pipeline output port */
+       struct device_node *of_output_port;
+       /** @of_output_dev: output connector device node */
+       struct device_node *of_output_dev;
 };
 
 /**