public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Maxime Ripard <maxime.ripard@free-electrons.com>,
	linux-kernel@vger.kernel.org, rjendra@qti.qualcomm.com
Subject: Re: [PATCH v1 3/3] nvmem: core: fix regmap accessor usage
Date: Thu, 14 Apr 2016 07:42:29 +0100	[thread overview]
Message-ID: <20160414064229.GC18024@sirena.org.uk> (raw)
In-Reply-To: <1460569154-25030-4-git-send-email-srinivas.kandagatla@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2752 bytes --]

On Wed, Apr 13, 2016 at 06:39:14PM +0100, Srinivas Kandagatla wrote:
> With the recent patch of removing the raw accessors form regmap-mmio,
> broke the qfprom support. This patch attempts to fix that regression
> by adding check before calling regmap raw accessors functions.
> 
> Without this patch nvmem providers based on regmap mmio would not work.

Ugh, this seems incredibly confused.  Why is this even using regmap?  It
doesn't seem to use anything from the framework - it only ever accesses
the device with raw accessors which bypass pretty much everything the
framework has to offer.  The raw accessors are there for things like
copying preformatted images to devices where we have a specific need to
do a subset of operations where the framework doesn't add anything, they
shouldn't be the only thing a driver ever does.  If they are then all
regmap is doing is adding a bunch of overhead and making the code more
complex.

Looking at the regmap_bus implementations in the subsystem is very
worrying too, there's lots of dummy functions in there which are never a
good sign and pretty much every bus looks like it really should be using
reg_read() and reg_write() operations but is contorting itself to do
bytestream access instead - things like parsing data out of the buffers
are not good signs as they indicate that the buses are hooking in at the
wrong abstraction layer.

> +	if (regmap_can_raw_read(map))
> +		return regmap_raw_read(map, reg, val, bytes);
> +
> +	for (i = 0; i < word_count; i++) {
> +		ret = regmap_read(map, reg + i * nvmem->stride, &ival);
> +		if (ret != 0)
> +			return ret;
> +
> +		switch (nvmem->word_size) {
> +		case 4:
> +			u32_buf[i] = ival;
> +			break;

This is clearly an abstraction failure and probably broken for systems
where the device endianness does not match the CPU endianness (like most
big endian systems, the device hardware normally stays in little endian
mode).

We need to figure out what this stuff is trying to do before we go any
further, I'm honestly not entirely clear.  I *think* that if regmap is a
good fit then it probably wants to use the bulk operations rather than
the raw operations (the bulk operations are AFAICT what is being open
coded above) but bulk I/O still does endianness handling and I'm not
sure if that's desired or not.  If the nvmem code really is just trying
to get bytestreams then regmap really isn't what it should be using,
it's all about dealing with registers and trying to force bytestreams
through it seems like it's just going to lead to fragility.  Either
whatever is happening should be abstracted within regmap or we shouldn't
be using regmap.

I'll try to have another look at this later.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2016-04-14  6:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13 17:39 [PATCH v1 0/3] nvmem: core: fix regmap accessor usage Srinivas Kandagatla
2016-04-13 17:39 ` [PATCH v1 1/3] regmap: add regmap_can_raw_read() api Srinivas Kandagatla
2016-04-14  5:58   ` Mark Brown
2016-04-13 17:39 ` [PATCH v1 2/3] regmap: add dummy regmap_can_raw_write() to header Srinivas Kandagatla
2016-04-14  6:45   ` Mark Brown
2016-04-13 17:39 ` [PATCH v1 3/3] nvmem: core: fix regmap accessor usage Srinivas Kandagatla
2016-04-14  6:42   ` Mark Brown [this message]
2016-04-14 12:35     ` Srinivas Kandagatla
2016-04-14 15:18       ` Mark Brown
2016-04-14 16:48         ` Srinivas Kandagatla

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=20160414064229.GC18024@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.ripard@free-electrons.com \
    --cc=rjendra@qti.qualcomm.com \
    --cc=srinivas.kandagatla@linaro.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