From: Chen-Yu Tsai <wens@kernel.org>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Maxime Ripard <maxime.ripard@bootlin.com>
Cc: devicetree@vger.kernel.org, linux-sunxi@googlegroups.com,
Chen-Yu Tsai <wens@csie.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/6] nvmem: sunxi_sid: Optimize register read-out method
Date: Mon, 18 Mar 2019 15:33:50 +0800 [thread overview]
Message-ID: <20190318073354.12151-3-wens@kernel.org> (raw)
In-Reply-To: <20190318073354.12151-1-wens@kernel.org>
From: Chen-Yu Tsai <wens@csie.org>
SID cells are 32-bit aligned, and a multiple of 32 bits in length. The
only outlier is the thermal sensor calibration data, which is 16 bits
per sensor. However a whole 64 bits is allocated for this purpose, so
we could consider it conforming to the rule above.
Also, the register read-out method assumes native endian, unlike the
direct MMIO method, which assumes big endian. Thus no endian conversion
is involved.
Under these assumptions, the register read-out method can be slightly
optimized. Instead of reading one word then discarding 3 bytes, read
the whole word directly into the buffer. However, for reads under 4
bytes or trailing bytes, we still use a scratch buffer to extract the
requested bytes.
We could go one step further if .word_size was 4, but changing that
would affect the sysfs interface's behavior.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
drivers/nvmem/sunxi_sid.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index 704c35edf796..15fbfab62595 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -115,36 +115,34 @@ static int sun8i_sid_register_readout(const struct sunxi_sid *sid,
* to be not reliable at all.
* Read by the registers instead.
*/
-static int sun8i_sid_read_byte_by_reg(const struct sunxi_sid *sid,
- const unsigned int offset,
- u8 *out)
-{
- u32 word;
- int ret;
-
- ret = sun8i_sid_register_readout(sid, offset & ~0x03, &word);
-
- if (ret)
- return ret;
-
- *out = (word >> ((offset & 0x3) * 8)) & 0xff;
-
- return 0;
-}
-
static int sun8i_sid_read_by_reg(void *context, unsigned int offset,
void *val, size_t bytes)
{
struct sunxi_sid *sid = context;
- u8 *buf = val;
+ u32 word;
int ret;
- while (bytes--) {
- ret = sun8i_sid_read_byte_by_reg(sid, offset++, buf++);
+ /* .stride = 4 so offset is guaranteed to be aligned */
+ while (bytes >= 4) {
+ ret = sun8i_sid_register_readout(sid, offset, val);
if (ret)
return ret;
+
+ val += 4;
+ offset += 4;
+ bytes -= 4;
}
+ if (!bytes)
+ return 0;
+
+ /* Handle any trailing bytes */
+ ret = sun8i_sid_register_readout(sid, offset, &word);
+ if (ret)
+ return ret;
+
+ memcpy(val, &word, bytes);
+
return 0;
}
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-03-18 7:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-18 7:33 [PATCH 0/6] nvmem: sunxi_sid: native format and A83T/H5 support Chen-Yu Tsai
2019-03-18 7:33 ` [PATCH 1/6] nvmem: sunxi_sid: Read out SID for randomness without looping Chen-Yu Tsai
2019-03-18 7:33 ` Chen-Yu Tsai [this message]
2019-03-18 7:33 ` [PATCH 3/6] nvmem: sunxi_sid: Dynamically allocate nvmem_config structure Chen-Yu Tsai
2019-03-18 7:33 ` [PATCH 4/6] nvmem: sunxi_sid: Read out data in native format Chen-Yu Tsai
2019-03-18 8:42 ` Maxime Ripard
2019-03-18 8:45 ` Chen-Yu Tsai
2019-03-18 8:57 ` Maxime Ripard
2019-03-18 9:09 ` Chen-Yu Tsai
2019-03-18 9:25 ` Maxime Ripard
2019-03-18 7:33 ` [PATCH 5/6] nvmem: sunxi_sid: Support SID on A83T and H5 Chen-Yu Tsai
2019-03-18 7:33 ` [PATCH 6/6] ARM: dts: sunxi: h3/h5: Add device node for SID Chen-Yu Tsai
2019-03-19 1:55 ` [linux-sunxi] " Samuel Holland
2019-03-19 3:17 ` Chen-Yu Tsai
2019-03-20 14:25 ` [PATCH 0/6] nvmem: sunxi_sid: native format and A83T/H5 support Srinivas Kandagatla
2019-03-21 9:06 ` Chen-Yu Tsai
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=20190318073354.12151-3-wens@kernel.org \
--to=wens@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=maxime.ripard@bootlin.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=wens@csie.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).