Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp192945img; Mon, 18 Mar 2019 00:35:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyU50eXS8/sTp22hZcv195bKNpqcDrasqmHSUDRCzQFM5njRiN8AlSgx+bGEAbec44OVZ9u X-Received: by 2002:a17:902:1123:: with SMTP id d32mr17992316pla.16.1552894510448; Mon, 18 Mar 2019 00:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552894510; cv=none; d=google.com; s=arc-20160816; b=Y5Go4pqyPxP2Y8FnXsT2K1DXQMSURaErUciY2NkB1zWc5Xy39x7Q7IeMYCr7NuFJJl L1ktTqtCMD8gtP/awMWEjUDujsdbOxsJ8dDipQJ2jSHpvhIKvC/IjKDiM5YFdBgCCbPB 8xDPdgqIvNgL8S9LiDjTndxaSUlUh/ofaNERekPYC505jwEl39WW9TB+52YB+IxuoKRi KghYEqKrjTImRc4lpg6+/5nyq13y7cgnb2aYmg8ZBAEmX8loYKCPsp6lSAEnpyv8B/Ip K56Gr56htZk0D9J+6L+ommmKlM6vc51Ge2coXFZsW4qXGUPyuHkxJu1eg3V0S7Dmb6DL hgmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9Ap9XcFPUHOEb2zUmahHRT0Nao8iZwXRm1KhinKFGQ4=; b=zqKP15mzoKyQuRsGRqHuTXtEu3NEwn9HMI+ivkV7RgWSdQRCy91uIm2MLrzESokbzv yPA/rJP7iKBGT9/v1QvOlakWkSeY7j/Ox2meABUI3o1HMYpYDiyLK8llnFR+fQF2ijHX vpK+Kqh1pjItz3cujzW1R+66Ms2IM5vpM1CeTOU+HyRak1q9in5eU29ICjO0hj0In9QE OwiRTDQnkK/iRPviN0iAWQ3pqs3gMt+VU/4LOTlTY4dvmkm+/hwdD6A5PXthNGqZP69i yt9owJrd36CXUKJPp8wPUHYQSqg9R5hMGQqkmDLBa2Gn3L4R3abxE1PCAUuXFg4xSWo7 DiaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i20si4304788pfd.204.2019.03.18.00.34.55; Mon, 18 Mar 2019 00:35:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbfCRHeS (ORCPT + 99 others); Mon, 18 Mar 2019 03:34:18 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:40894 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726846AbfCRHeO (ORCPT ); Mon, 18 Mar 2019 03:34:14 -0400 Received: by wens.csie.org (Postfix, from userid 1000) id F3F3C5FD69; Mon, 18 Mar 2019 15:34:11 +0800 (CST) From: Chen-Yu Tsai To: Srinivas Kandagatla , Maxime Ripard Cc: linux-sunxi@googlegroups.com, Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.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 Message-Id: <20190318073354.12151-3-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190318073354.12151-1-wens@kernel.org> References: <20190318073354.12151-1-wens@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen-Yu Tsai 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 --- 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