All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Dahl <ada@thorsis.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Lee Jones <lee.jones@linaro.org>,
	Samuel Ortiz <sameo@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] memory: atmel-ebi: Simplify SMC config code
Date: Thu, 02 Mar 2017 13:02:16 +0100	[thread overview]
Message-ID: <16727676.CMj9rWYKWZ@ada> (raw)
In-Reply-To: <1487609701-10300-3-git-send-email-boris.brezillon@free-electrons.com>

Hei hei,

With 

#define ATMEL_SMC_MODE_TDF(x)           (((x) - 1) << 16)

from include/linux/mfd/syscon/atmel-smc.h you added this:

> +	ret = of_property_read_u32(np, "atmel,smc-tdf-ns", &val);
> +	if (!ret) {
> +		required = true;
> +		ncycles = DIV_ROUND_UP(val, clk_period_ns);
> +		if (ncycles > ATMEL_SMC_MODE_TDF_MAX) {
> +			ret = -EINVAL;
> +			goto out;
> +		}

[…]

> +		smcconf->mode |= ATMEL_SMC_MODE_TDF(ncycles);
> +	}

This was the same algorithm at some other location in atmel-ebi.c 
before:

	#define AT91_SMC_TDF_(x)		((((x) - 1) << 16) & AT91_SMC_TDF)

	val = DIV_ROUND_UP(timings->tdf_ns, clk_rate);
	if (val > AT91_SMC_TDF_MAX)
		val = AT91_SMC_TDF_MAX;
	regmap_fields_write(fields->mode, conf->cs,
			    config->mode | AT91_SMC_TDF_(val));

The hardware manual (AT91SAM9G20) says values from 0 to 15 (4bit, 0x0 to 
0xF) are possible and I guess the goal is to set it to a value 
corresponding to the value in ns from the dts or to 15 if it's greater 
(or -EINVAL in the new version).

However how can one set it to zero? Put in zero to the div you get zero 
for ncycles or val and that goes as x into (((x) - 1) << 16) which 
results in 0xF ending up as TDF_CYCLES in the mode register, right?

I can of course set a slightly greater value, which ends up in a 
calculated register value of zero, but that seems more a hack to me and 
is not obvious if I just look at the DTS.

If I'm right this might be topic of another bugfix patch, or should it 
be done right in a v2 of this one?

Greets
Alex

WARNING: multiple messages have this Message-ID (diff)
From: ada@thorsis.com (Alexander Dahl)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/7] memory: atmel-ebi: Simplify SMC config code
Date: Thu, 02 Mar 2017 13:02:16 +0100	[thread overview]
Message-ID: <16727676.CMj9rWYKWZ@ada> (raw)
In-Reply-To: <1487609701-10300-3-git-send-email-boris.brezillon@free-electrons.com>

Hei hei,

With 

#define ATMEL_SMC_MODE_TDF(x)           (((x) - 1) << 16)

from include/linux/mfd/syscon/atmel-smc.h you added this:

> +	ret = of_property_read_u32(np, "atmel,smc-tdf-ns", &val);
> +	if (!ret) {
> +		required = true;
> +		ncycles = DIV_ROUND_UP(val, clk_period_ns);
> +		if (ncycles > ATMEL_SMC_MODE_TDF_MAX) {
> +			ret = -EINVAL;
> +			goto out;
> +		}

[?]

> +		smcconf->mode |= ATMEL_SMC_MODE_TDF(ncycles);
> +	}

This was the same algorithm at some other location in atmel-ebi.c 
before:

	#define AT91_SMC_TDF_(x)		((((x) - 1) << 16) & AT91_SMC_TDF)

	val = DIV_ROUND_UP(timings->tdf_ns, clk_rate);
	if (val > AT91_SMC_TDF_MAX)
		val = AT91_SMC_TDF_MAX;
	regmap_fields_write(fields->mode, conf->cs,
			    config->mode | AT91_SMC_TDF_(val));

The hardware manual (AT91SAM9G20) says values from 0 to 15 (4bit, 0x0 to 
0xF) are possible and I guess the goal is to set it to a value 
corresponding to the value in ns from the dts or to 15 if it's greater 
(or -EINVAL in the new version).

However how can one set it to zero? Put in zero to the div you get zero 
for ncycles or val and that goes as x into (((x) - 1) << 16) which 
results in 0xF ending up as TDF_CYCLES in the mode register, right?

I can of course set a slightly greater value, which ends up in a 
calculated register value of zero, but that seems more a hack to me and 
is not obvious if I just look@the DTS.

If I'm right this might be topic of another bugfix patch, or should it 
be done right in a v2 of this one?

Greets
Alex

  reply	other threads:[~2017-03-02 12:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20 16:54 [PATCH 0/7] memory: atmel-ebi: Add PM ops Boris Brezillon
2017-02-20 16:54 ` Boris Brezillon
2017-02-20 16:54 ` [PATCH 1/7] mfd: syscon: atmel-smc: Add new helpers to ease SMC regs manipulation Boris Brezillon
2017-02-20 16:54   ` Boris Brezillon
2017-03-14 17:00   ` Lee Jones
2017-03-14 17:00     ` Lee Jones
2017-03-14 17:21     ` Boris Brezillon
2017-03-14 17:21       ` Boris Brezillon
2017-03-15 12:19       ` Lee Jones
2017-03-15 12:19         ` Lee Jones
2017-03-15 13:21         ` Boris Brezillon
2017-03-15 13:21           ` Boris Brezillon
2017-02-20 16:54 ` [PATCH 2/7] memory: atmel-ebi: Simplify SMC config code Boris Brezillon
2017-02-20 16:54   ` Boris Brezillon
2017-03-02 12:02   ` Alexander Dahl [this message]
2017-03-02 12:02     ` Alexander Dahl
2017-03-02 12:30     ` Boris Brezillon
2017-03-02 12:30       ` Boris Brezillon
2017-07-24  9:12       ` Alexander Dahl
2017-07-24  9:12         ` Alexander Dahl
2017-07-24 19:21         ` Boris Brezillon
2017-07-24 19:21           ` Boris Brezillon
2017-07-25 11:43           ` Alexander Dahl
2017-07-25 11:43             ` Alexander Dahl
2017-02-20 16:54 ` [PATCH 3/7] memory: atmel-ebi: Stop using reg_field objects for simple things Boris Brezillon
2017-02-20 16:54   ` Boris Brezillon
2017-02-20 16:54 ` [PATCH 4/7] mfd: syscon: atmel-smc: Remove unused helpers/macros Boris Brezillon
2017-02-20 16:54   ` Boris Brezillon
2017-02-20 16:54 ` [PATCH 5/7] memory: atmel-ebi: Change naming scheme Boris Brezillon
2017-02-20 16:54   ` Boris Brezillon
2017-02-20 16:55 ` [PATCH 6/7] memory: atmel-ebi: Add missing ->numcs assignment Boris Brezillon
2017-02-20 16:55   ` Boris Brezillon
2017-02-20 16:55 ` [PATCH 7/7] memory: atmel-ebi: Add PM ops Boris Brezillon
2017-02-20 16:55   ` Boris Brezillon

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=16727676.CMj9rWYKWZ@ada \
    --to=ada@thorsis.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    --cc=sameo@linux.intel.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.