From patchwork Tue Jan 15 07:12:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 155631 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4560164jaa; Mon, 14 Jan 2019 23:14:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN4BzmEapZGj0dTDYHHeIOLTsooAZVQH7uz6IZD+tTEFfSCQQKfkq4vzUzCr7cxjqpLPN96L X-Received: by 2002:a63:82c6:: with SMTP id w189mr2531472pgd.344.1547536458269; Mon, 14 Jan 2019 23:14:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547536458; cv=none; d=google.com; s=arc-20160816; b=Bf/+NKDVRdTgcFIwxbqdVHo7GGvIomDet06r4Yv6qDmFOAGoMck++dsWQ2eaeyEoUD +IKFvI75en73+quVjsUUDipNjErNFlhEJD3h4nNIpFQcmf5zVN5IUXqnM5Z9BSBrDXkI rDxfx7oBalqtuW8iWYi/P6yfHiieUHOBqh/0m2dW1p99SukJzHenK5EFOsy16bbkph3j cNS1UJpstWrni/I3QAtSu9dtfJPAj/4hMdqmw9Et3XoMY+sgoROX7TORi3KGjzs9TthN 2Owf+hxrD5WblNLuWH1xCeiRxCx8de7L3U4Btq5g302yx2rz1HAyE4tNLRCjP+c4tEtD hKEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=XiObOYBMEnYUhtFYQFKhimRVBQlxUjJZmTDd1jp1WKQ=; b=ogZXFFwWduhcEw8xY93dm0OuTfaZeZcXJKXIiMmbbR/LMzKdn1FFOtEUwkTVV3voRU c7Mm8ngogsrW8MFmnA/hHlPiy2oqSRcQhmHzRhpya3YZIpAKbNwuwKBwg5ycA3N0WXCr EQDFuqqVE0BDfpHbnzyXvVua+k1UUkwapBOee+BzZMSGfET5iHyDcmMAzjf7F7MeWMTY L3KQNfaSC0j2OI+DHhO7c+hJZHH6tZMpHmptnFXCCVxgbFfzHErkk3TgK8kJuN2iWupQ kImLoV5R4xq35DBtgFzHLnTk2hvtaSnvo5a36oax9BtGL5pspJN3DxuUOelqwKxCO3f6 D+Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ehZpg7kq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k33si2557831pld.374.2019.01.14.23.14.18; Mon, 14 Jan 2019 23:14:18 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=ehZpg7kq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727878AbfAOHNh (ORCPT + 31 others); Tue, 15 Jan 2019 02:13:37 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40656 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725840AbfAOHNg (ORCPT ); Tue, 15 Jan 2019 02:13:36 -0500 Received: by mail-pl1-f195.google.com with SMTP id u18so855831plq.7 for ; Mon, 14 Jan 2019 23:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=XiObOYBMEnYUhtFYQFKhimRVBQlxUjJZmTDd1jp1WKQ=; b=ehZpg7kqnY1pucWToaGilTvYWNigZFMlF3T3qhUOYmMnLPzxg/jfWbqvK4LGjAdAvG IfCj6Hp8wGFLv690oXDNjqGztujSdO/vbCBmjEX75YyyCHTcopjpgOnvY8EXftFiTK/z 7BIef/aJq4dUVthQ/22FPqWpt0iQwPBq+Rgyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XiObOYBMEnYUhtFYQFKhimRVBQlxUjJZmTDd1jp1WKQ=; b=bI5RS1RCK+A/QqwMlkh2VUsWbLySTHHA4uSfErweVz+OI0qp4TyWvKDYAjlR7hrOY+ bOugAwHEvlthCyY48eQjr/2yEaEO/mm5nqUM0YAzB39de6mEvo1rOw5+vjyTk8uA/iYl IX+JpUQXn/7YienJMH96aMVcbhqdv4aBC6IJ+PvxlWTaVNb5w4M0mzDIFFLyNIN0X5Zz s3dma0HwQUBLxkbNzo+3qCJnWHAIlaCNFrcUl4nHAgPpfhwiJ4i9LQYfH17Rxov3Ix6J 5dwPs4/i/leVnBurxqIO0u/vx05H1VLvGkoZ8dayhzYNOwziI4WqSe36CvyDSSzvJuaR droQ== X-Gm-Message-State: AJcUukcX42+H21bRnqi6BEOJW6Bly2psS6sDRCbA4ucwcNXw+0tFRnXS tSoHnIfaT634byFu1MhB0o7AlTxG7dpIow== X-Received: by 2002:a17:902:2b8a:: with SMTP id l10mr2538561plb.70.1547536415828; Mon, 14 Jan 2019 23:13:35 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id t29sm3055019pfa.158.2019.01.14.23.13.33 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jan 2019 23:13:35 -0800 (PST) From: Baolin Wang To: srinivas.kandagatla@linaro.org Cc: broonie@kernel.org, freeman.liu@unisoc.com, baolin.wang@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvmem: sc27xx: Convert nvmem offset to block index Date: Tue, 15 Jan 2019 15:12:58 +0800 Message-Id: <915eacd1c2f05ec84ae50474feb94902bd790ec3.1547536224.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Freeman Liu The Spreadtrum SC27XX efuse data are organized by blocks and each block contains 2 bytes data. Moreover the nvmem core always pass the offset in byte to the controller, so we should change the offset in byte to the correct block index and block offset to read the data. Signed-off-by: Freeman Liu Signed-off-by: Baolin Wang --- drivers/nvmem/sc27xx-efuse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 1.7.9.5 diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c index 33185d8..c6ee210 100644 --- a/drivers/nvmem/sc27xx-efuse.c +++ b/drivers/nvmem/sc27xx-efuse.c @@ -106,10 +106,12 @@ static int sc27xx_efuse_poll_status(struct sc27xx_efuse *efuse, u32 bits) static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes) { struct sc27xx_efuse *efuse = context; - u32 buf; + u32 buf, blk_index = offset / SC27XX_EFUSE_BLOCK_WIDTH; + u32 blk_offset = (offset % SC27XX_EFUSE_BLOCK_WIDTH) * BITS_PER_BYTE; int ret; - if (offset > SC27XX_EFUSE_BLOCK_MAX || bytes > SC27XX_EFUSE_BLOCK_WIDTH) + if (blk_index > SC27XX_EFUSE_BLOCK_MAX || + bytes > SC27XX_EFUSE_BLOCK_WIDTH) return -EINVAL; ret = sc27xx_efuse_lock(efuse); @@ -133,7 +135,7 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes) /* Set the block address to be read. */ ret = regmap_write(efuse->regmap, efuse->base + SC27XX_EFUSE_BLOCK_INDEX, - offset & SC27XX_EFUSE_BLOCK_MASK); + blk_index & SC27XX_EFUSE_BLOCK_MASK); if (ret) goto disable_efuse; @@ -171,8 +173,10 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes) unlock_efuse: sc27xx_efuse_unlock(efuse); - if (!ret) + if (!ret) { + buf >>= blk_offset; memcpy(val, &buf, bytes); + } return ret; }