From patchwork Fri Dec 15 14:06:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 122104 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp520121qgn; Fri, 15 Dec 2017 06:09:52 -0800 (PST) X-Google-Smtp-Source: ACJfBou5M93rw9WYK0svMWGoLUVMNrwiHl1/LuWPr50O3mKbeoV6/JycFhXHfftJ7hMiohqSUVq1 X-Received: by 10.98.193.1 with SMTP id i1mr13626508pfg.29.1513346992157; Fri, 15 Dec 2017 06:09:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513346992; cv=none; d=google.com; s=arc-20160816; b=rpy8nGirrIzGhxXlDG0OS9GW3bso0V7Ju63+Fh20YO1pyqA6wo4G2eqv4MkM1s5r7Z bYxnQ7nQP8e36xJwdlZzKFCDQhD1BcaIicR8DBhJarOle9csCMshs1Xz1NqhMOdsir03 e+CToyzlSmo6lSjr7e2RQrnWcYDlS3efpAPT1N4dNQrMfjQk14MCVDZVTocRgzQOxyOZ plAy5vQ4T61D0HcD8kbbmvHIFIzR/Ka7GKWPqsAQUYy0i9EfYfhgvX1BCjG+TvHV8lQA pwmQ8AtsnRirzJhQcfKhU1DL6Z9GDqE2PZvgicQFvZIUSiBIuzYtPuxuCI4ZRaJt/ZMV wpAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=HmtC2StzD1ap2D/EobXJ7zpidOmA2wdoX1ZQVQC3zmo=; b=w1OW4w1dGq1v6OAAvTMlGL8ihLzXNNGCNrkJy9GULYrsOQsS/ll95eC4KpVCD3yFWk 4Ou8uUFSKAWPhWQOSMh1FUOwug0y3GJtWUcLcNBeRCq0QAQ1bEfWSFFzZXZtAntUamrD jV9za7bV+wgSVf1lihLZkOU8pDZ+6eT3p6YRcfe0Am7cs8ZAv+yiyYheV/gc3UzQw1FF vM+9//A9smAe5hYoKSK9IPbVQAeuKMNIAwWCzolf3KfrPXXsgfAjXygV+zfmDYDSqJf1 hWRSSeYfxWgTVGvW7/JUUCvpvD+dIICujEchjhElh6cUN7EHN+//xDuVlr+hh+htMedk seQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ynx3iLbN; 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 f1si5112879plb.58.2017.12.15.06.09.51; Fri, 15 Dec 2017 06:09:52 -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=Ynx3iLbN; 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 S1756587AbdLOOJt (ORCPT + 20 others); Fri, 15 Dec 2017 09:09:49 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35274 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756563AbdLOOJi (ORCPT ); Fri, 15 Dec 2017 09:09:38 -0500 Received: by mail-wm0-f67.google.com with SMTP id f9so17955457wmh.0 for ; Fri, 15 Dec 2017 06:09:38 -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; bh=HmtC2StzD1ap2D/EobXJ7zpidOmA2wdoX1ZQVQC3zmo=; b=Ynx3iLbNeZ6nkBpAikVPuW98pSk8njU/CJVXQCV67oX1u/CTcZFwcKFlAYyVreVqeE 6nTyZPJLtLO68GgruHVLAfYN3TodmOuxmxj6uIVm7P2JWvE+1OMcD7u8RMhVc3rPHMH/ +/HsiyQuhWWQ1JZAkZ3YHOxthO0epycUx+g8U= 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; bh=HmtC2StzD1ap2D/EobXJ7zpidOmA2wdoX1ZQVQC3zmo=; b=VQ9Ffo6delyc7t+iGwRedoQ0kNKHrGHfc+JgShYeswZ/KvTCIShnHEjsUVrlldtW2R QGb4GBJoujuCjkm6//l2AF1ZszU1+LnjCkKCDEfU3P6wenJ6B4rVleDIPujHgP7Sanli LmVB06ohNscBPSeAPvj9tybr9IM3PHwwmK5JyXL/jRSjvkNYtGaG5QmNjbTILVblr54N rwHU8ErMaieR19h32XJ17+xn11mUIQA/V//chrIgnpStmCuMO7J7mgccE+uwd8xWZFOb IQ3rbrfpymbu5Bi3ESvvCL3NOOZP/O1D8nFTz1m2lJ4CCcfCHe+rkNAerzRUDfI2bpNx 53RA== X-Gm-Message-State: AKGB3mJvKFoczYeZAETIUvQA0J/2Ef1nKLTzWgrvBBAEYXyTJxua6mfU hseFBrPoCzpc317RInmcucsDjg== X-Received: by 10.28.1.196 with SMTP id 187mr5343754wmb.151.1513346977318; Fri, 15 Dec 2017 06:09:37 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id n7sm6295034wra.23.2017.12.15.06.09.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Dec 2017 06:09:36 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, srinivas.kandagatla@linaro.org, Finley Xiao , Heiko Stuebner Subject: [PATCH 6/6] nvmem: rockchip-efuse: add support for rk3328-efuse Date: Fri, 15 Dec 2017 14:06:09 +0000 Message-Id: <20171215140609.17193-7-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171215140609.17193-1-srinivas.kandagatla@linaro.org> References: <20171215140609.17193-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Finley Xiao This adds the necessary data for handling eFuse on the rk3328. Signed-off-by: Finley Xiao Acked-by: Rob Herring Signed-off-by: Heiko Stuebner Signed-off-by: Srinivas Kandagatla --- .../devicetree/bindings/nvmem/rockchip-efuse.txt | 1 + drivers/nvmem/rockchip-efuse.c | 66 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) -- 2.15.0 diff --git a/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt b/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt index a6ef46dd1283..265bdb7dc8aa 100644 --- a/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt +++ b/Documentation/devicetree/bindings/nvmem/rockchip-efuse.txt @@ -6,6 +6,7 @@ Required properties: - "rockchip,rk3188-efuse" - for RK3188 SoCs. - "rockchip,rk3228-efuse" - for RK3228 SoCs. - "rockchip,rk3288-efuse" - for RK3288 SoCs. + - "rockchip,rk3328-efuse" - for RK3328 SoCs. - "rockchip,rk3368-efuse" - for RK3368 SoCs. - "rockchip,rk3399-efuse" - for RK3399 SoCs. - reg: Should contain the registers location and exact eFuse size diff --git a/drivers/nvmem/rockchip-efuse.c b/drivers/nvmem/rockchip-efuse.c index a91372816c0a..f13a8335f364 100644 --- a/drivers/nvmem/rockchip-efuse.c +++ b/drivers/nvmem/rockchip-efuse.c @@ -32,6 +32,14 @@ #define RK3288_STROBE BIT(1) #define RK3288_CSB BIT(0) +#define RK3328_SECURE_SIZES 96 +#define RK3328_INT_STATUS 0x0018 +#define RK3328_DOUT 0x0020 +#define RK3328_AUTO_CTRL 0x0024 +#define RK3328_INT_FINISH BIT(0) +#define RK3328_AUTO_ENB BIT(0) +#define RK3328_AUTO_RD BIT(1) + #define RK3399_A_SHIFT 16 #define RK3399_A_MASK 0x3ff #define RK3399_NBYTES 4 @@ -92,6 +100,60 @@ static int rockchip_rk3288_efuse_read(void *context, unsigned int offset, return 0; } +static int rockchip_rk3328_efuse_read(void *context, unsigned int offset, + void *val, size_t bytes) +{ + struct rockchip_efuse_chip *efuse = context; + unsigned int addr_start, addr_end, addr_offset, addr_len; + u32 out_value, status; + u8 *buf; + int ret, i = 0; + + ret = clk_prepare_enable(efuse->clk); + if (ret < 0) { + dev_err(efuse->dev, "failed to prepare/enable efuse clk\n"); + return ret; + } + + /* 128 Byte efuse, 96 Byte for secure, 32 Byte for non-secure */ + offset += RK3328_SECURE_SIZES; + addr_start = rounddown(offset, RK3399_NBYTES) / RK3399_NBYTES; + addr_end = roundup(offset + bytes, RK3399_NBYTES) / RK3399_NBYTES; + addr_offset = offset % RK3399_NBYTES; + addr_len = addr_end - addr_start; + + buf = kzalloc(sizeof(*buf) * addr_len * RK3399_NBYTES, GFP_KERNEL); + if (!buf) { + ret = -ENOMEM; + goto nomem; + } + + while (addr_len--) { + writel(RK3328_AUTO_RD | RK3328_AUTO_ENB | + ((addr_start++ & RK3399_A_MASK) << RK3399_A_SHIFT), + efuse->base + RK3328_AUTO_CTRL); + udelay(4); + status = readl(efuse->base + RK3328_INT_STATUS); + if (!(status & RK3328_INT_FINISH)) { + ret = -EIO; + goto err; + } + out_value = readl(efuse->base + RK3328_DOUT); + writel(RK3328_INT_FINISH, efuse->base + RK3328_INT_STATUS); + + memcpy(&buf[i], &out_value, RK3399_NBYTES); + i += RK3399_NBYTES; + } + + memcpy(val, buf + addr_offset, bytes); +err: + kfree(buf); +nomem: + clk_disable_unprepare(efuse->clk); + + return ret; +} + static int rockchip_rk3399_efuse_read(void *context, unsigned int offset, void *val, size_t bytes) { @@ -180,6 +242,10 @@ static const struct of_device_id rockchip_efuse_match[] = { .compatible = "rockchip,rk3368-efuse", .data = (void *)&rockchip_rk3288_efuse_read, }, + { + .compatible = "rockchip,rk3328-efuse", + .data = (void *)&rockchip_rk3328_efuse_read, + }, { .compatible = "rockchip,rk3399-efuse", .data = (void *)&rockchip_rk3399_efuse_read,