linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: alexandre.belloni@free-electrons.com (Alexandre Belloni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] power: reset: at91-shdwc: add new shutdown controller driver
Date: Thu, 24 Sep 2015 13:06:52 +0200	[thread overview]
Message-ID: <20150924110652.GW4287@piout.net> (raw)
In-Reply-To: <1442937472-5481-1-git-send-email-nicolas.ferre@atmel.com>

On 22/09/2015 at 17:57:52 +0200, Nicolas Ferre wrote :
> +config POWER_RESET_AT91_SHDWC

Maybe we should start numbering, at91-poweroff is already a driver for
an shdwc.

> +#define SLOW_CLOCK_FREQ	32768
> +

The slow clock is an input to the shdwc, then you have to get it,
prepare and enable it. The you could use clk_get_rate.
By duplicating the driver, you are repeating mistakes from the past ;)


> +static void at91_poweroff(void)
> +{
> +	BUG_ON(!at91_shdwc);

Is that condition even possible?

> +
> +	writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
> +			at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);

This is not properly aligned.

> +}
> +
> +static u32 at91_shdwc_debouncer_value(struct platform_device *pdev,
> +				      u32 in_period_us)
> +{
> +	int i;
> +	int max_idx = ARRAY_SIZE(sdwc_dbc_period) - 1;
> +	unsigned long long period_us;
> +	unsigned long long max_period_us = DBC_PERIOD_US(sdwc_dbc_period[max_idx]);
> +
> +	if (in_period_us > max_period_us) {
> +		dev_warn(&pdev->dev,
> +			 "debouncer period %u too big, reduced to %llu us\n",
> +			 in_period_us, max_period_us);
> +		return max_idx;
> +	}
> +
> +	for (i = max_idx - 1; i > 0; i--) {
> +		period_us = DBC_PERIOD_US(sdwc_dbc_period[i]);
> +		dev_dbg(&pdev->dev, "%s: ref[%d] = %llu\n",
> +						__func__, i, period_us);
ditto


> +		if (in_period_us > period_us)
> +			break;
> +	}
> +
> +	return i + 1;
> +}
> +
> +static u32 at91_shdwc_get_wakeup_input(struct platform_device *pdev,
> +				       struct device_node *np)
> +{
> +	struct device_node *cnp;
> +	const char *pm;
> +	u32 wk_input_mask;
> +	u32 wuir = 0;
> +	u32 wk_input;
> +
> +	for_each_child_of_node(np, cnp) {
> +		if (of_property_read_u32(cnp, "reg", &wk_input)) {
> +			dev_warn(&pdev->dev, "reg property is missing for %s\n",
> +				 cnp->full_name);
> +			continue;
> +		}
> +
> +		wk_input_mask = 1 << wk_input;
> +		if (!(wk_input_mask & AT91_SHDW_WKUPEN_MASK)) {
> +			dev_warn(&pdev->dev,
> +				 "wake-up input %d out of bounds ignore\n",
> +				 wk_input);
> +			continue;
> +		}
> +		wuir |= wk_input_mask;
> +
> +		if (!of_property_read_string(cnp, "atmel,wakeup-type", &pm)) {
> +			if (!strcasecmp(pm, "high"))
> +				/*
> +				 * only add a type if "high" is specified. Low
> +				 * is the default.
> +				 */
> +				wuir |= AT91_SHDW_WKUPT(wk_input);
> +		}
> +		dev_dbg(&pdev->dev, "%s: (child %d) wuir = %#x\n",
> +						__func__, wk_input, wuir);

ditto

> +static int at91_shdwc_probe(struct platform_device *pdev)
> +{
> +	struct resource *res;
> +	const struct of_device_id *match;
> +
> +	if (!pdev->dev.of_node)
> +		return -ENODEV;
> +
> +	at91_shdwc = devm_kzalloc(&pdev->dev, sizeof(*at91_shdwc), GFP_KERNEL);
> +	if (!at91_shdwc)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, at91_shdwc);
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	at91_shdwc->at91_shdwc_base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(at91_shdwc->at91_shdwc_base)) {
> +		dev_err(&pdev->dev, "Could not map reset controller address\n");
> +		return PTR_ERR(at91_shdwc->at91_shdwc_base);
> +	}
> +
> +	match = of_match_node(at91_shdwc_of_match, pdev->dev.of_node);
> +	if (match != NULL)

match will never be NULL, else you wouldn't be probed. You can remove that test.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

  reply	other threads:[~2015-09-24 11:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10 10:35 [PATCH 1/3] power: reset: at91-reset/trivial: driver applies to SAMA5 family as well Nicolas Ferre
2015-09-10 10:39 ` [PATCH 2/3] ARM: at91/dt: shdwc binding: add new shutdown controller documentation Nicolas Ferre
2015-09-10 10:39 ` [PATCH 3/3] power: reset: at91-shdwc: add new shutdown controller driver Nicolas Ferre
2015-09-22 13:59   ` Sebastian Reichel
2015-09-22 15:57     ` [PATCH v2] " Nicolas Ferre
2015-09-24 11:06       ` Alexandre Belloni [this message]
2015-09-28  9:44         ` Nicolas Ferre
2015-09-22 13:46 ` [PATCH 1/3] power: reset: at91-reset/trivial: driver applies to SAMA5 family as well Sebastian Reichel

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=20150924110652.GW4287@piout.net \
    --to=alexandre.belloni@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.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).