All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Oliveira <Luis.Oliveira@synopsys.com>
To: mchehab@kernel.org, davem@davemloft.net,
	gregkh@linuxfoundation.org, Jonathan.Cameron@huawei.com,
	robh@kernel.org, nicolas.ferre@microchip.com,
	paulmck@linux.ibm.com, mark.rutland@arm.com, kishon@ti.com,
	devicetree@vger.kernel.org, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Joao.Pinto@synopsys.com, Luis Oliveira <Luis.Oliveira@synopsys.com>
Subject: [v4 3/6] media: platform: dwc: Add MIPI CSI-2 platform data
Date: Tue, 11 Jun 2019 21:20:52 +0200	[thread overview]
Message-ID: <1560280855-18085-4-git-send-email-luis.oliveira@synopsys.com> (raw)
In-Reply-To: <1560280855-18085-1-git-send-email-luis.oliveira@synopsys.com>

This allows the driver loading via platform data which makes the driver
not device tree dependent.

Signed-off-by: Luis Oliveira <luis.oliveira@synopsys.com>
---
Changelog
v3-v4
- not present on v3, allows configuration using pdata

 MAINTAINERS                              |   1 +
 drivers/media/platform/dwc/dw-csi-plat.c | 105 +++++++++++++++++++++----------
 include/media/dwc/dw-csi-data.h          |  26 ++++++++
 3 files changed, 100 insertions(+), 32 deletions(-)
 create mode 100644 include/media/dwc/dw-csi-data.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 6ffe4fd..2df1f7c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15193,6 +15193,7 @@ L:	linux-media@vger.kernel.org
 T:	git git://linuxtv.org/media_tree.git
 S:	Maintained
 F:	drivers/media/platform/dwc
+F:	include/media/dwc/dw-csi-data.h
 F:	Documentation/devicetree/bindings/media/snps,dw-csi.txt
 
 SYNOPSYS DESIGNWARE DMAC DRIVER
diff --git a/drivers/media/platform/dwc/dw-csi-plat.c b/drivers/media/platform/dwc/dw-csi-plat.c
index 9828d55..c7117c6 100644
--- a/drivers/media/platform/dwc/dw-csi-plat.c
+++ b/drivers/media/platform/dwc/dw-csi-plat.c
@@ -8,6 +8,7 @@
  * Author: Luis Oliveira <luis.oliveira@synopsys.com>
  */
 
+#include <media/dwc/dw-csi-data.h>
 #include <media/dwc/dw-dphy-data.h>
 
 #include "dw-csi-plat.h"
@@ -312,12 +313,16 @@ static const struct of_device_id dw_mipi_csi_of_match[];
 static int dw_csi_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *of_id = NULL;
+	struct dw_csih_pdata *pdata;
 	struct device *dev = &pdev->dev;
 	struct resource *res = NULL;
 	struct dw_csi *csi;
 	struct v4l2_subdev *sd;
 	int ret;
 
+	if (!IS_ENABLED(CONFIG_OF))
+		pdata = pdev->dev.platform_data;
+
 	dev_vdbg(dev, "Probing started\n");
 
 	/* Resource allocation */
@@ -329,18 +334,29 @@ static int dw_csi_probe(struct platform_device *pdev)
 	spin_lock_init(&csi->slock);
 	csi->dev = dev;
 
-	of_id = of_match_node(dw_mipi_csi_of_match, dev->of_node);
-	if (!of_id)
-		return -EINVAL;
+	if (dev->of_node) {
+		of_id = of_match_node(dw_mipi_csi_of_match, dev->of_node);
+		if (!of_id)
+			return -EINVAL;
 
-	ret = dw_mipi_csi_parse_dt(pdev, csi);
-	if (ret < 0)
-		return ret;
+		ret = dw_mipi_csi_parse_dt(pdev, csi);
+		if (ret < 0)
+			return ret;
 
-	csi->phy = devm_of_phy_get(dev, dev->of_node, NULL);
-	if (IS_ERR(csi->phy)) {
-		dev_err(dev, "No DPHY available\n");
-		return PTR_ERR(csi->phy);
+		csi->phy = devm_of_phy_get(dev, dev->of_node, NULL);
+		if (IS_ERR(csi->phy)) {
+			dev_err(dev, "No DPHY available\n");
+			return PTR_ERR(csi->phy);
+		}
+	} else {
+		csi->phy = devm_phy_get(dev, phys[pdata->id].name);
+		if (IS_ERR(csi->phy)) {
+			dev_err(dev, "No '%s' DPHY available\n",
+				phys[pdata->id].name);
+			return PTR_ERR(csi->phy);
+		}
+		dev_vdbg(dev, "got D-PHY %s with id %d\n", phys[pdata->id].name,
+			 csi->phy->id);
 	}
 	/* Registers mapping */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -370,7 +386,10 @@ static int dw_csi_probe(struct platform_device *pdev)
 			       dw_mipi_csi_irq1, IRQF_SHARED,
 			       dev_name(dev), csi);
 	if (ret) {
-		dev_err(dev, "irq csi %s failed\n", of_id->name);
+		if (dev->of_node)
+			dev_err(dev, "irq csi %s failed\n", of_id->name);
+	else
+		dev_err(dev, "irq csi %d failed\n", pdata->id);
 
 		goto end;
 	}
@@ -379,25 +398,44 @@ static int dw_csi_probe(struct platform_device *pdev)
 	v4l2_subdev_init(sd, &dw_mipi_csi_subdev_ops);
 	csi->sd.owner = THIS_MODULE;
 
-	snprintf(sd->name, sizeof(sd->name), "%s.%d",
-		 "dw-csi", csi->index);
+	if (dev->of_node) {
+		snprintf(sd->name, sizeof(sd->name), "%s.%d",
+			 "dw-csi", csi->index);
 
-	csi->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+		csi->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	} else {
+		strlcpy(sd->name, dev_name(dev), sizeof(sd->name));
+		strlcpy(csi->v4l2_dev.name, dev_name(dev),
+			sizeof(csi->v4l2_dev.name));
+	}
 	csi->fmt = &dw_mipi_csi_formats[0];
 	csi->format.code = dw_mipi_csi_formats[0].mbus_code;
 
 	sd->entity.function = MEDIA_ENT_F_IO_V4L;
-	csi->pads[CSI_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
-	csi->pads[CSI_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_pads_init(&csi->sd.entity,
-				     CSI_PADS_NUM, csi->pads);
 
-	dev_vdbg(dev, "v4l2.name: %s\n", csi->v4l2_dev.name);
+	if (dev->of_node) {
+		csi->pads[CSI_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
+		csi->pads[CSI_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
 
-	if (ret < 0) {
-		dev_err(dev, "media entity init failed\n");
-		goto end;
+		ret = media_entity_pads_init(&csi->sd.entity,
+					     CSI_PADS_NUM, csi->pads);
+		if (ret < 0) {
+			dev_err(dev, "media entity init failed\n");
+			goto end;
+		}
+	} else {
+		csi->hw.num_lanes = pdata->lanes;
+		csi->hw.pclk = pdata->pclk;
+		csi->hw.fps = pdata->fps;
+		csi->hw.dphy_freq = pdata->hs_freq;
+
+		ret = v4l2_device_register(NULL, &csi->v4l2_dev);
+		if (ret) {
+			dev_err(dev, "failed to register v4l2 device\n");
+			goto end;
+		}
 	}
+	dev_vdbg(dev, "v4l2.name: %s\n", csi->v4l2_dev.name);
 
 	v4l2_set_subdevdata(&csi->sd, pdev);
 	platform_set_drvdata(pdev, &csi->sd);
@@ -405,6 +443,7 @@ static int dw_csi_probe(struct platform_device *pdev)
 
 	if (csi->rst)
 		reset_control_deassert(csi->rst);
+
 #if IS_ENABLED(CONFIG_DWC_MIPI_TC_DPHY_GEN3)
 	dw_csi_create_capabilities_sysfs(pdev);
 #endif
@@ -418,11 +457,12 @@ static int dw_csi_probe(struct platform_device *pdev)
 	phy_init(csi->phy);
 
 	return 0;
-
 end:
+#if IS_ENABLED(CONFIG_OF)
 	media_entity_cleanup(&csi->sd.entity);
+	return ret;
+#endif
 	v4l2_device_unregister(csi->vdev.v4l2_dev);
-
 	return ret;
 }
 
@@ -436,35 +476,36 @@ static int dw_csi_remove(struct platform_device *pdev)
 	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
 	struct dw_csi *mipi_csi = sd_to_mipi_csi_dev(sd);
 
-	dev_dbg(&pdev->dev, "Removing MIPI CSI-2 module\n");
+	dev_dbg(&pdev->dev, "Removing DW MIPI CSI-2 Host module\n");
 
 	if (mipi_csi->rst)
 		reset_control_assert(mipi_csi->rst);
+#if IS_ENABLED(CONFIG_OF)
 	media_entity_cleanup(&mipi_csi->sd.entity);
-
+#else
+	v4l2_device_unregister(mipi_csi->vdev.v4l2_dev);
+#endif
 	return 0;
 }
 
-/**
- * @short of_device_id structure
- */
+#if IS_ENABLED(CONFIG_OF)
 static const struct of_device_id dw_mipi_csi_of_match[] = {
 	{ .compatible = "snps,dw-csi" },
 	{},
 };
 
 MODULE_DEVICE_TABLE(of, dw_mipi_csi_of_match);
+#endif
 
-/**
- * @short Platform driver structure
- */
 static struct platform_driver dw_mipi_csi_driver = {
 	.remove = dw_csi_remove,
 	.probe = dw_csi_probe,
 	.driver = {
 		.name = "dw-csi",
 		.owner = THIS_MODULE,
+#if IS_ENABLED(CONFIG_OF)
 		.of_match_table = of_match_ptr(dw_mipi_csi_of_match),
+#endif
 	},
 };
 
diff --git a/include/media/dwc/dw-csi-data.h b/include/media/dwc/dw-csi-data.h
new file mode 100644
index 0000000..87942ab
--- /dev/null
+++ b/include/media/dwc/dw-csi-data.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018-2019 Synopsys, Inc. and/or its affiliates.
+ *
+ * Synopsys DesignWare MIPI CSI-2 platform data
+ *
+ * Author: Luis Oliveira <Luis.Oliveira@synopsys.com>
+ */
+
+#include <linux/kernel.h>
+#include <media/dwc/dw-mipi-csi-pltfrm.h>
+
+struct dw_csih_pdata {
+	u8 eotp_enabled;
+	u32 hs_freq;
+	u32 lanes;
+	u32 pclk;
+	u32 fps;
+	u32 bpp;
+	u8 id;
+};
+
+static const struct pdata_names csis[] = {
+	{ .name = "dw-csi.0", },
+	{ .name = "dw-csi.1", },
+};
-- 
2.7.4


  parent reply	other threads:[~2019-06-11 19:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 19:20 [v4 0/6] platform: dwc: Adding DesignWare MIPI CSI-2 Host and D-PHY Luis Oliveira
2019-06-11 19:20 ` [v4 1/6] dt-bindings: media: Document bindings for DW MIPI CSI-2 Host Luis Oliveira
2019-06-28 14:13   ` Sakari Ailus
2019-07-08 15:21     ` Luis de Oliveira
2019-07-09 18:25       ` Sakari Ailus
2019-07-10 10:20         ` Luis de Oliveira
2019-07-25 20:02           ` Sakari Ailus
2019-07-26  9:50             ` Luis de Oliveira
2019-07-26 11:13               ` Eugen.Hristev
2019-07-26 11:13                 ` Eugen.Hristev
2019-07-09 14:33   ` Eugen.Hristev
2019-07-09 14:33     ` Eugen.Hristev
2019-07-09 17:08     ` Luis de Oliveira
2019-07-10  6:53       ` Eugen.Hristev
2019-07-10  6:53         ` Eugen.Hristev
2019-07-10 10:23         ` Luis de Oliveira
2019-06-11 19:20 ` [v4 2/6] media: platform: dwc: Add MIPI CSI-2 controller driver Luis Oliveira
2019-07-10  8:59   ` Eugen.Hristev
2019-07-10  8:59     ` Eugen.Hristev
2019-07-10 14:21     ` Luis de Oliveira
2019-08-09 14:10   ` Sakari Ailus
2019-08-10 13:09     ` Andy Shevchenko
2019-08-12  9:45       ` Luis de Oliveira
2019-08-12 16:50         ` Andy Shevchenko
2019-06-11 19:20 ` Luis Oliveira [this message]
2019-08-09 14:39   ` [v4 3/6] media: platform: dwc: Add MIPI CSI-2 platform data Sakari Ailus
2019-06-11 19:20 ` [v4 4/6] dt-bindings: phy: Document the Synopsys MIPI DPHY Rx bindings Luis Oliveira
2019-07-09 14:20   ` Rob Herring
2019-07-09 16:28     ` Luis de Oliveira
2019-07-10 13:50       ` Rob Herring
2019-08-09 14:42   ` Sakari Ailus
2019-08-09 14:45     ` Sakari Ailus
2019-08-09 14:47     ` Sakari Ailus
2019-06-11 19:20 ` [v4 5/6] media: platform: dwc: Add DW MIPI DPHY Rx driver Luis Oliveira
2019-06-11 19:20 ` [v4 6/6] media: platform: dwc: Add platform data support to D-Phy Luis Oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1560280855-18085-4-git-send-email-luis.oliveira@synopsys.com \
    --to=luis.oliveira@synopsys.com \
    --cc=Joao.Pinto@synopsys.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=paulmck@linux.ibm.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.