Linux Watchdog driver development
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org,
	Wim Van Sebroeck <wim@iguana.be>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	Gregory Clement <gregory.clement@free-electrons.com>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Lior Amsalem <alior@marvell.com>,
	Tawfik Bayouk <tawfik@marvell.com>
Subject: Re: [PATCH v2 4/7] watchdog: orion: Add Armada 375/380 SoC support
Date: Tue, 11 Mar 2014 17:16:24 -0300	[thread overview]
Message-ID: <20140311201624.GC8506@arch.cereza> (raw)
In-Reply-To: <531D1F9B.8090804@roeck-us.net>

On Mar 09, Guenter Roeck wrote:
> On 03/04/2014 08:07 AM, Ezequiel Garcia wrote:
[..]
> >  MODULE_DEVICE_TABLE(of, orion_wdt_of_match_table);
> >@@ -396,6 +475,25 @@ static int orion_wdt_probe(struct platform_device *pdev)
> >  		if (!dev->rstout)
> >  			return -ENOMEM;
> >
> >+	} else if (of_device_is_compatible(node, "marvell,armada-375-wdt") ||
> >+		   of_device_is_compatible(node, "marvell,armada-380-wdt")) {
> >+
> >+		res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> 
> Looks like each supported watchdog needs this call. Might as well do it earlier
> and just once, unless you have a good reason for doing it this way.
> To me this just looks like a lot of code replication.
> 

Well... it seemed to me as cleaner to have one 'if' block per compatible
group and do all the ioremap'ing in it.

Otherwise, it would be like this (seudo-code):

rstout = foo_request_ioremap();
if (!rsout)
	if (compatible(1)) {
		/* Missing RSTOUT! Do backwards compatibility hack */
		rstout = fw_bug_fallback();
		if (!rstout)
			return -ENODEV;
	} else
		return -ENODEV;

if (compatible(3))
	rstout_mask = foo_request_ioremap();
	if (!rstout_mask)
		return -ENODEV;

Maybe it's a matter of taste, but I think this looks better:

if (compatible(1))
	request_ioremap all registers ...
else if (compatible(2))
	request_ioremap all registers ...
else if (compatible(3))
	request_ioremap all registers ...
else
	return -ENODEV;

At the price of a little code duplication.

> It might also possibly make sense to move all the memory initializations
> into a separate function; the probe function gets a bit large.
> 
> >+		if (!res)
> >+			return -ENODEV;
> >+		dev->rstout = devm_ioremap(&pdev->dev, res->start,
> >+					   resource_size(res));
> >+		if (!dev->rstout)
> >+			return -ENOMEM;
> >+
> >+		res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
> >+		if (!res)
> >+			return -ENODEV;
> >+		dev->rstout_mask = devm_ioremap(&pdev->dev, res->start,
> >+						resource_size(res));
> 
> devm_ioremap_resource() is better here.
> 

True. We are currently confusing the shared and non-shared registers,
and treating them all as shared. I'll fix that.

Thanks for the review,
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-03-11 20:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04 16:07 [PATCH v2 0/7] Watchdog support for Armada 375/38x SoC Ezequiel Garcia
2014-03-04 16:07 ` [PATCH v2 1/7] watchdog: orion: Introduce a SoC-specific RSTOUT mapping Ezequiel Garcia
2014-03-10  2:09   ` Guenter Roeck
2014-03-11 20:06     ` Ezequiel Garcia
2014-03-04 16:07 ` [PATCH v2 2/7] watchdog: orion: Introduce per-SoC stop() function Ezequiel Garcia
2014-03-10  2:30   ` Guenter Roeck
2014-03-04 16:07 ` [PATCH v2 3/7] watchdog: orion: Introduce per-SoC enabled() function Ezequiel Garcia
2014-03-10  2:30   ` Guenter Roeck
2014-03-04 16:07 ` [PATCH v2 4/7] watchdog: orion: Add Armada 375/380 SoC support Ezequiel Garcia
2014-03-10  2:12   ` Guenter Roeck
2014-03-11 20:16     ` Ezequiel Garcia [this message]
2014-03-04 16:07 ` [PATCH v2 5/7] ARM: mvebu: Enable Armada 375 watchdog in the devicetree Ezequiel Garcia
2014-03-04 16:07 ` [PATCH v2 6/7] ARM: mvebu: Enable Armada 380/385 " Ezequiel Garcia
2014-03-04 16:07 ` [PATCH v2 7/7] ARM: mvebu: Add A375/A380 watchdog binding documentation Ezequiel Garcia
2014-03-04 17:53 ` [PATCH v2 0/7] Watchdog support for Armada 375/38x SoC Jason Cooper
2014-03-04 20:03   ` Ezequiel Garcia
2014-03-07  0:13 ` Ezequiel Garcia
2014-03-11 21:45   ` Jason Gunthorpe
2014-03-12 21:12     ` Ezequiel Garcia

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=20140311201624.GC8506@arch.cereza \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=alior@marvell.com \
    --cc=andrew@lunn.ch \
    --cc=devicetree@vger.kernel.org \
    --cc=gregory.clement@free-electrons.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=tawfik@marvell.com \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=wim@iguana.be \
    /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