From patchwork Mon Jan 28 15:54:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 156759 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3581877jaa; Mon, 28 Jan 2019 07:55:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN7mXBghDXmMt28+k1VflGWw5LX4DLRSqOilbKWQJkN46IkoCONucCFEZcqLCOsHZdn2eQl4 X-Received: by 2002:a17:902:704b:: with SMTP id h11mr22437528plt.157.1548690915944; Mon, 28 Jan 2019 07:55:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548690915; cv=none; d=google.com; s=arc-20160816; b=ooFcrDsdvM3Zkgj+IoirFW7G16HhXU+eEC5idRZzaSfnJg1C1d1KLTyci8LjNFhX36 rQJCFCJ58CW5gfq+d5T1YBFxOfwjcoelY/RlQVdROkAq0gpiM8tHaSnTzRYLbsAzXd1X BrXHebnGzMtiE8ZxzONLaXnp4UZIa4AdYjQe7ZZKjFV8hTN3KI/u9pzLqsMspfDKvoFM aDq1uBRMOn+GDXP6x6jW2SYYv3u9s8fsdBr14bQJHX0NuBc2eVLy90mASNCGCn+PZTeD Y+277e+iw4N551NFx8w1RGNrAF6J4vkGktg168m5X9jNigMvaLYrwSUXMk0C4I/uAw9C BimA== 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 :dkim-signature; bh=4uJKpLWM6aPmr+zhJuvVuuv2Ucq9pVDA4S2r+Yn6Xzk=; b=zGXpMZVNDL8J/cCJZQOrMDRIZflbLh8AuJLznwAP8RyJq1DCV3jDIQLhDnU9jwnPGu HEzv6oObVUkxKUprxdo5mc0/R/aYow4BdOPlvuyHZcSe5/Ub1Bf7RASNHzSLypJVPUpZ eH9bv9ppzZKRNa82hnDEjrKPZ3DZhMYVeEGs6IChlJqs0cKesjd1gh6pewnbTX1g6o2A dBwsd2u+lEkRAV9FwnzDjspVVKUx7/32XJEhMehIudpAuw+Gvmlk/gsf5otJEoxqDWgR Y8wsJhEJ7G2tvDcQSUJvhN3qZiEiLBkLgBPgVfq8QKBeuq5S9YIGGDuQBnK+rE4uaUL5 cy5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jVOUnK34; 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 y8si19733220pfn.26.2019.01.28.07.55.15; Mon, 28 Jan 2019 07:55:15 -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=jVOUnK34; 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 S1727986AbfA1PzN (ORCPT + 31 others); Mon, 28 Jan 2019 10:55:13 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42642 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729835AbfA1PzL (ORCPT ); Mon, 28 Jan 2019 10:55:11 -0500 Received: by mail-wr1-f68.google.com with SMTP id q18so18605864wrx.9 for ; Mon, 28 Jan 2019 07:55:10 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=4uJKpLWM6aPmr+zhJuvVuuv2Ucq9pVDA4S2r+Yn6Xzk=; b=jVOUnK34SgCGU4+niCiHTbiLCK6fH4+xrDwa49Pd9qknCFh2xEyLTDDip2x6TUUVKO CH/13tx2t7q53C4haDiFitiVzy33h50K4LYkgrEmya/NkZxwg6HqKyIu4zeH9QMK8im7 voxeWxUNRisqGBz66XcUeZ2VhtgiAX+FSkoQc= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4uJKpLWM6aPmr+zhJuvVuuv2Ucq9pVDA4S2r+Yn6Xzk=; b=rTMM2cDrgZ9KT3vXuJJkAZqdcozzOUIqWhDky5JWZH63vgyzSz2f/6HsNRzS/vuWal wv62C6pjDxBoGi/5MfWhh9xhHIZ5pREKsOhV77fyt4bIjxiKlNgh+axSvCakhNjCf9Ln 50Vr69cdBIiUFbxVqMcQFH+YBu/M+g6kJVxVmInz1Njz4fwChIIYH228eRYAwaiS1NG1 2XEGNn0hLEE4dIy054uKNqwvYirmdjqoXq0xqx40zc0SYog+pMX9poWyhuXYxf8nObs1 i2Z/+0VovBjW4o/IECevH1gUE5LsprPUctQ8u3ghsAYo5WYqWWb+xgkfm2OYYsMG3aeI z93g== X-Gm-Message-State: AJcUukfW8EfCVKnTU78PATRyCfGP73THuKhsSHs1/kO7K7q7h6gavFip TZdf5JkBmzTSiqxTyDZHn6lpxpQAadw= X-Received: by 2002:adf:bb8d:: with SMTP id q13mr22085966wrg.183.1548690909803; Mon, 28 Jan 2019 07:55:09 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id p6sm145140485wrx.50.2019.01.28.07.55.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 07:55:08 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 01/13] nvmem: sc27xx: Convert nvmem offset to block index Date: Mon, 28 Jan 2019 15:54:54 +0000 Message-Id: <20190128155506.25566-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128155506.25566-1-srinivas.kandagatla@linaro.org> References: <20190128155506.25566-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 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 Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/sc27xx-efuse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c index 33185d8d82cf..c6ee21018d80 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; }