From: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
Cc: linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
Hans Verkuil
<hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCHv4 3/4] tegra-cec: add Tegra HDMI CEC driver
Date: Thu, 19 Oct 2017 11:37:00 +0200 [thread overview]
Message-ID: <20171019093700.GF9005@ulmo> (raw)
In-Reply-To: <20170911122952.33980-4-hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 3679 bytes --]
On Mon, Sep 11, 2017 at 02:29:51PM +0200, Hans Verkuil wrote:
[...]
> diff --git a/drivers/media/platform/tegra-cec/tegra_cec.c b/drivers/media/platform/tegra-cec/tegra_cec.c
[...]
> +static int tegra_cec_probe(struct platform_device *pdev)
> +{
> + struct platform_device *hdmi_dev;
> + struct device_node *np;
> + struct tegra_cec *cec;
> + struct resource *res;
> + int ret = 0;
> +
> + np = of_parse_phandle(pdev->dev.of_node, "hdmi-phandle", 0);
> +
> + if (!np) {
> + dev_err(&pdev->dev, "Failed to find hdmi node in device tree\n");
> + return -ENODEV;
> + }
> + hdmi_dev = of_find_device_by_node(np);
> + if (hdmi_dev == NULL)
> + return -EPROBE_DEFER;
This seems a little awkward. Why exactly do we need to defer probe here?
It seems to me like cec_notifier_get() should be able to deal with HDMI
appearing at a later point.
> +
> + cec = devm_kzalloc(&pdev->dev, sizeof(struct tegra_cec), GFP_KERNEL);
> +
> + if (!cec)
> + return -ENOMEM;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +
> + if (!res) {
> + dev_err(&pdev->dev,
> + "Unable to allocate resources for device\n");
> + ret = -EBUSY;
> + goto cec_error;
> + }
> +
> + if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
> + pdev->name)) {
> + dev_err(&pdev->dev,
> + "Unable to request mem region for device\n");
> + ret = -EBUSY;
> + goto cec_error;
> + }
> +
> + cec->tegra_cec_irq = platform_get_irq(pdev, 0);
> +
> + if (cec->tegra_cec_irq <= 0) {
> + ret = -EBUSY;
> + goto cec_error;
> + }
> +
> + cec->cec_base = devm_ioremap_nocache(&pdev->dev, res->start,
> + resource_size(res));
> +
> + if (!cec->cec_base) {
> + dev_err(&pdev->dev, "Unable to grab IOs for device\n");
> + ret = -EBUSY;
> + goto cec_error;
> + }
> +
> + cec->clk = devm_clk_get(&pdev->dev, "cec");
> +
> + if (IS_ERR_OR_NULL(cec->clk)) {
> + dev_err(&pdev->dev, "Can't get clock for CEC\n");
> + ret = -ENOENT;
> + goto clk_error;
> + }
> +
> + clk_prepare_enable(cec->clk);
> +
> + /* set context info. */
> + cec->dev = &pdev->dev;
> +
> + platform_set_drvdata(pdev, cec);
> +
> + ret = devm_request_threaded_irq(&pdev->dev, cec->tegra_cec_irq,
> + tegra_cec_irq_handler, tegra_cec_irq_thread_handler,
> + 0, "cec_irq", &pdev->dev);
> +
> + if (ret) {
> + dev_err(&pdev->dev,
> + "Unable to request interrupt for device\n");
> + goto cec_error;
> + }
> +
> + cec->notifier = cec_notifier_get(&hdmi_dev->dev);
> + if (!cec->notifier) {
> + ret = -ENOMEM;
> + goto cec_error;
> + }
Ah... I see why we need the HDMI device right away. This seems a little
brittle to me, for two reasons: what if the HDMI controller goes away?
Will we be hanging on to a stale device? I mean, the device doesn't
necessarily have to go away, but what's the effect on CEC if the driver
unbinds from the HDMI controller?
Secondly, this creates a circular dependency. It seems to me like it'd
actually be simpler if the CEC controller was a "service provider" that
HDMI could use and "request/release" as appropriate.
In that case, the DT would look somewhat like this:
hdmi@... {
cec = <&cec>;
};
cec: cec@... {
...
};
And then the HDMI driver could do something like:
cec = cec_get(&pdev->dev);
/* register notifier, ... */
That way the dependency becomes unidirectional and it seems to me like
that would allow interactions between HDMI and CEC would become simpler
overall.
Anyway, this is something that could always be changed after the fact
(except maybe for some bits needed for backwards-compatibility with old
device trees), and this seems to work well enough as it is, so:
Acked-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-10-19 9:37 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 12:29 [PATCHv4 0/4] tegra-cec: add Tegra HDMI CEC support Hans Verkuil
2017-09-11 12:29 ` [PATCHv4 2/4] ARM: tegra: add CEC support to tegra124.dtsi Hans Verkuil
[not found] ` <20170911122952.33980-3-hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-10-19 9:23 ` Thierry Reding
[not found] ` <20170911122952.33980-1-hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-09-11 12:29 ` [PATCHv4 1/4] dt-bindings: document the tegra CEC bindings Hans Verkuil
[not found] ` <20170911122952.33980-2-hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-10-19 9:22 ` Thierry Reding
2017-09-11 12:29 ` [PATCHv4 3/4] tegra-cec: add Tegra HDMI CEC driver Hans Verkuil
[not found] ` <20170911122952.33980-4-hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-10-19 9:37 ` Thierry Reding [this message]
2017-09-11 12:29 ` [PATCHv4 4/4] drm/tegra: add cec-notifier support Hans Verkuil
[not found] ` <20170911122952.33980-5-hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-10-19 9:38 ` Thierry Reding
2017-10-19 13:17 ` Thierry Reding
2017-10-19 13:30 ` Thierry Reding
2017-10-19 13:37 ` Hans Verkuil
[not found] ` <7e1fcffd-76dc-c4f2-942c-b9872f73fff0-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2017-10-19 14:01 ` Thierry Reding
2017-10-19 9:20 ` [PATCHv4 0/4] tegra-cec: add Tegra HDMI CEC support Thierry Reding
2017-10-19 9:36 ` Hans Verkuil
[not found] ` <0f43276f-0a89-8caa-6522-253458e3ad08-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-10-19 9:39 ` Thierry Reding
2017-10-14 12:08 ` Hans Verkuil
[not found] ` <9314614a-446d-b76d-640b-033cc74e3879-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2017-10-14 13:34 ` Thierry Reding
2017-10-14 13:48 ` Hans Verkuil
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=20171019093700.GF9005@ulmo \
--to=thierry.reding-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org \
--cc=hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org \
--cc=linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).