All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Subject: [PATCH v3 41/61] drm/omap: dss: hdmi4: Move initialization code from bind to probe
Date: Mon,  6 Aug 2018 03:27:21 +0300	[thread overview]
Message-ID: <20180806002741.30929-42-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20180806002741.30929-1-laurent.pinchart@ideasonboard.com>

There's no reason to delay initialization of most of the driver (such as
mapping memory I/O or enabling runtime PM) to the component bind
handler. Perform as much of the initialization as possible at probe
time, initializing at bind time only the parts that depends on the DSS.
The cleanup code is moved from unbind to remove in a similar way.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
---
 drivers/gpu/drm/omapdrm/dss/hdmi4.c | 218 +++++++++++++++++++-----------------
 1 file changed, 117 insertions(+), 101 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index 1d1f2e0b2b2a..89fdce02278c 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -553,53 +553,10 @@ static const struct omap_dss_device_ops hdmi_ops = {
 	},
 };
 
-static void hdmi_init_output(struct omap_hdmi *hdmi)
-{
-	struct omap_dss_device *out = &hdmi->output;
-
-	out->dev = &hdmi->pdev->dev;
-	out->id = OMAP_DSS_OUTPUT_HDMI;
-	out->output_type = OMAP_DISPLAY_TYPE_HDMI;
-	out->name = "hdmi.0";
-	out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
-	out->ops = &hdmi_ops;
-	out->owner = THIS_MODULE;
-	out->of_ports = BIT(0);
-
-	omapdss_device_register(out);
-}
-
-static void hdmi_uninit_output(struct omap_hdmi *hdmi)
-{
-	struct omap_dss_device *out = &hdmi->output;
-
-	omapdss_device_unregister(out);
-}
-
-static int hdmi_probe_of(struct omap_hdmi *hdmi)
-{
-	struct platform_device *pdev = hdmi->pdev;
-	struct device_node *node = pdev->dev.of_node;
-	struct device_node *ep;
-	int r;
-
-	ep = of_graph_get_endpoint_by_regs(node, 0, 0);
-	if (!ep)
-		return 0;
-
-	r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
-	if (r)
-		goto err;
-
-	of_node_put(ep);
-	return 0;
-
-err:
-	of_node_put(ep);
-	return r;
-}
+/* -----------------------------------------------------------------------------
+ * Audio Callbacks
+ */
 
-/* Audio callbacks */
 static int hdmi_audio_startup(struct device *dev,
 			      void (*abort_cb)(struct device *dev))
 {
@@ -714,27 +671,123 @@ static int hdmi_audio_register(struct omap_hdmi *hdmi)
 	return 0;
 }
 
-/* HDMI HW IP initialisation */
+/* -----------------------------------------------------------------------------
+ * Component Bind & Unbind
+ */
+
 static int hdmi4_bind(struct device *dev, struct device *master, void *data)
 {
-	struct platform_device *pdev = to_platform_device(dev);
 	struct dss_device *dss = dss_get_device(master);
-	struct omap_hdmi *hdmi;
+	struct omap_hdmi *hdmi = dev_get_drvdata(dev);
 	int r;
+
+	hdmi->dss = dss;
+
+	r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp);
+	if (r)
+		return r;
+
+	r = hdmi4_cec_init(hdmi->pdev, &hdmi->core, &hdmi->wp);
+	if (r)
+		goto err_pll_uninit;
+
+	r = hdmi_audio_register(hdmi);
+	if (r) {
+		DSSERR("Registering HDMI audio failed\n");
+		goto err_cec_uninit;
+	}
+
+	hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
+					       hdmi);
+
+	return 0;
+
+err_cec_uninit:
+	hdmi4_cec_uninit(&hdmi->core);
+err_pll_uninit:
+	hdmi_pll_uninit(&hdmi->pll);
+	return r;
+}
+
+static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
+{
+	struct omap_hdmi *hdmi = dev_get_drvdata(dev);
+
+	dss_debugfs_remove_file(hdmi->debugfs);
+
+	if (hdmi->audio_pdev)
+		platform_device_unregister(hdmi->audio_pdev);
+
+	hdmi4_cec_uninit(&hdmi->core);
+	hdmi_pll_uninit(&hdmi->pll);
+}
+
+static const struct component_ops hdmi4_component_ops = {
+	.bind	= hdmi4_bind,
+	.unbind	= hdmi4_unbind,
+};
+
+/* -----------------------------------------------------------------------------
+ * Probe & Remove, Suspend & Resume
+ */
+
+static void hdmi4_init_output(struct omap_hdmi *hdmi)
+{
+	struct omap_dss_device *out = &hdmi->output;
+
+	out->dev = &hdmi->pdev->dev;
+	out->id = OMAP_DSS_OUTPUT_HDMI;
+	out->output_type = OMAP_DISPLAY_TYPE_HDMI;
+	out->name = "hdmi.0";
+	out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
+	out->ops = &hdmi_ops;
+	out->owner = THIS_MODULE;
+	out->of_ports = BIT(0);
+
+	omapdss_device_register(out);
+}
+
+static void hdmi4_uninit_output(struct omap_hdmi *hdmi)
+{
+	struct omap_dss_device *out = &hdmi->output;
+
+	omapdss_device_unregister(out);
+}
+
+static int hdmi4_probe_of(struct omap_hdmi *hdmi)
+{
+	struct platform_device *pdev = hdmi->pdev;
+	struct device_node *node = pdev->dev.of_node;
+	struct device_node *ep;
+	int r;
+
+	ep = of_graph_get_endpoint_by_regs(node, 0, 0);
+	if (!ep)
+		return 0;
+
+	r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
+	of_node_put(ep);
+	return r;
+}
+
+static int hdmi4_probe(struct platform_device *pdev)
+{
+	struct omap_hdmi *hdmi;
 	int irq;
+	int r;
 
 	hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
 	if (!hdmi)
 		return -ENOMEM;
 
 	hdmi->pdev = pdev;
-	hdmi->dss = dss;
+
 	dev_set_drvdata(&pdev->dev, hdmi);
 
 	mutex_init(&hdmi->lock);
 	spin_lock_init(&hdmi->audio_playing_lock);
 
-	r = hdmi_probe_of(hdmi);
+	r = hdmi4_probe_of(hdmi);
 	if (r)
 		goto err_free;
 
@@ -742,27 +795,19 @@ static int hdmi4_bind(struct device *dev, struct device *master, void *data)
 	if (r)
 		goto err_free;
 
-	r = hdmi_pll_init(dss, pdev, &hdmi->pll, &hdmi->wp);
-	if (r)
-		goto err_free;
-
 	r = hdmi_phy_init(pdev, &hdmi->phy, 4);
 	if (r)
-		goto err_pll;
+		goto err_free;
 
 	r = hdmi4_core_init(pdev, &hdmi->core);
 	if (r)
-		goto err_pll;
-
-	r = hdmi4_cec_init(pdev, &hdmi->core, &hdmi->wp);
-	if (r)
-		goto err_pll;
+		goto err_free;
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
 		DSSERR("platform_get_irq failed\n");
 		r = -ENODEV;
-		goto err_pll;
+		goto err_free;
 	}
 
 	r = devm_request_threaded_irq(&pdev->dev, irq,
@@ -770,67 +815,38 @@ static int hdmi4_bind(struct device *dev, struct device *master, void *data)
 			IRQF_ONESHOT, "OMAP HDMI", hdmi);
 	if (r) {
 		DSSERR("HDMI IRQ request failed\n");
-		goto err_pll;
+		goto err_free;
 	}
 
 	pm_runtime_enable(&pdev->dev);
 
-	hdmi_init_output(hdmi);
+	hdmi4_init_output(hdmi);
 
-	r = hdmi_audio_register(hdmi);
-	if (r) {
-		DSSERR("Registering HDMI audio failed\n");
+	r = component_add(&pdev->dev, &hdmi4_component_ops);
+	if (r)
 		goto err_uninit_output;
-	}
-
-	hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
-					       hdmi);
 
 	return 0;
 
 err_uninit_output:
-	hdmi_uninit_output(hdmi);
+	hdmi4_uninit_output(hdmi);
 	pm_runtime_disable(&pdev->dev);
-err_pll:
-	hdmi_pll_uninit(&hdmi->pll);
 err_free:
 	kfree(hdmi);
 	return r;
 }
 
-static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
+static int hdmi4_remove(struct platform_device *pdev)
 {
-	struct omap_hdmi *hdmi = dev_get_drvdata(dev);
+	struct omap_hdmi *hdmi = platform_get_drvdata(pdev);
 
-	dss_debugfs_remove_file(hdmi->debugfs);
-
-	if (hdmi->audio_pdev)
-		platform_device_unregister(hdmi->audio_pdev);
-
-	hdmi_uninit_output(hdmi);
-
-	hdmi4_cec_uninit(&hdmi->core);
+	component_del(&pdev->dev, &hdmi4_component_ops);
 
-	hdmi_pll_uninit(&hdmi->pll);
+	hdmi4_uninit_output(hdmi);
 
-	pm_runtime_disable(dev);
+	pm_runtime_disable(&pdev->dev);
 
 	kfree(hdmi);
-}
-
-static const struct component_ops hdmi4_component_ops = {
-	.bind	= hdmi4_bind,
-	.unbind	= hdmi4_unbind,
-};
-
-static int hdmi4_probe(struct platform_device *pdev)
-{
-	return component_add(&pdev->dev, &hdmi4_component_ops);
-}
-
-static int hdmi4_remove(struct platform_device *pdev)
-{
-	component_del(&pdev->dev, &hdmi4_component_ops);
 	return 0;
 }
 
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2018-08-06  0:27 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-06  0:26 [PATCH v3 00/61] omapdrm: Reverse direction of DSS device (dis)connect operations Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 01/61] drm/omap: Allocate drm_device earlier and unref it as last step Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 02/61] drm/omap: Manage the usable omap_dss_device list within omap_drm_private Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 03/61] drm/omap: Do dss_device (display) ordering in omap_drv.c Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 04/61] drm/omap: dss: Remove display ordering from dss/display.c Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 05/61] drm/omap: dss: Gather OMAP DSS components at probe time Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 06/61] drm/omap: dss: Move platform_device_register from core.c to dss.c probe Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 07/61] drm/omap: dss: Handle DPI and SDI port initialization failures Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 08/61] drm/omap: dss: Remove omapdss_atv_ops get_wss and set_wss operations Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 09/61] drm/omap: dss: Remove DSS encoders get_timings operation Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 10/61] drm/omap: dss: Remove unused omapdss_default_get_timings() Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 11/61] drm/omap: dss: Constify omap_dss_driver operations structure Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 12/61] drm/omap: displays: Remove videomode from omap_dss_device structure Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 13/61] drm/omap: dss: Remove omap_dss_device panel fields Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 14/61] drm/omap: dss: Rename omap_dss_device list field to output_list Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 15/61] drm/omap: dss: Create global list of all omap_dss_device instances Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 16/61] drm/omap: dss: Create and use omapdss_device_is_registered() Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 17/61] drm/omap: dss: Rework output lookup by port node Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 18/61] drm/omap: dss: Allow looking up any device by port Laurent Pinchart
2018-08-06  0:26 ` [PATCH v3 19/61] drm/omap: dss: Move common device operations to common structure Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 20/61] drm/omap: dss: Add functions to connect and disconnect devices Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 21/61] drm/omap: dss: Move debug message and checks to connection handlers Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 22/61] drm/omap: displays: Don't call disconnect handlers directly Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 23/61] drm/omap: dss: Move src and dst check and set to connection handlers Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 24/61] drm/omap: displays: Remove input omap_dss_device from panel data Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 25/61] drm/omap: dsi: Simplify debugfs implementation Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 26/61] drm/omap: Move DSI debugfs clocks dump to dsi%u_clks files Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 27/61] drm/omap: dss: Remove output devices list Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 28/61] drm/omap: dss: Rename for_each_dss_dev macro to for_each_dss_display Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 29/61] drm/omap: dss: Make omap_dss_get_next_device() more generic Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 30/61] drm/omap: dss: Split omapdss_register_display() Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 31/61] drm/omap: dss: Remove panel devices list Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 32/61] drm/omap: dss: Move and rename omap_dss_(get|put)_device() Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 33/61] drm/omap: dss: Store dss_device pointer in omap_dss_device Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 34/61] drm/omap: dss: Move DSS mgr ops and private data to dss_device Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 35/61] drm/omap: dss: Modify omapdss_find_output_from_display() to return channel Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 36/61] drm/omap: dss: Replace omap_dss_device port number with bitmask Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 37/61] drm/omap: dss: Extend omapdss_of_find_source_for_first_ep() to sinks Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 38/61] drm/omap: displays: Don't cast dssdev to panel data unnecessarily Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 39/61] drm/omap: dss: Cleanup error paths in output init functions Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 40/61] drm/omap: dss: dsi: Move initialization code from bind to probe Laurent Pinchart
2018-08-06  0:27 ` Laurent Pinchart [this message]
2018-08-06  0:27 ` [PATCH v3 42/61] drm/omap: dss: hdmi5: " Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 43/61] drm/omap: dss: venc: " Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 44/61] drm/omap: dss: Acquire next dssdev at probe time Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 45/61] drm/omap: dss: Add for_each_dss_output() macro Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 46/61] drm/omap: dss: Add function to retrieve display for an output Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 47/61] drm/omap: dss: Remove duplicated parameter to dss_mgr_(dis)connect() Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 48/61] drm/omap: dss: Get regulators at probe time Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 49/61] drm/omap: Remove unneeded variable assignments in omap_modeset_init Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 50/61] drm/omap: Create all planes before CRTCs Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 51/61] drm/omap: Group CRTC, encoder, connector and dssdev in a structure Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 52/61] drm/omap: Reverse direction of DSS device (dis)connect operations Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 53/61] drm/omap: dss: Move connection checks to omapdss_device_(dis)connect Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 54/61] drm/omap: dss: Move display type validation to initialization time Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 55/61] drm/omap: dss: Merge two disconnection helpers Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 56/61] drm/omap: Pass pipe pointer to omap_crtc_init() Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 57/61] drm/omap: Store CRTC lookup by channel table in omap_drm_private Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 58/61] drm/omap: Remove omap_crtc_output global array Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 59/61] drm/omap: Remove supported output check in CRTC connect handler Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 60/61] drm/omap: Set dispc_channel_connect from DSS output connect handlers Laurent Pinchart
2018-08-06  0:27 ` [PATCH v3 61/61] drm/omap: dss: Remove the dss_mgr_(dis)connect() operations Laurent Pinchart

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=20180806002741.30929-42-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tomi.valkeinen@ti.com \
    /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.