From patchwork Sat Jan 27 15:20:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 126051 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp1096959ljd; Sat, 27 Jan 2018 07:20:47 -0800 (PST) X-Google-Smtp-Source: AH8x224xeg/HqLlKx+w8Vb8Hf4ijhGp9/KD7hNscbhSdpRhBRP63Wg7A0uVssHyIwp2JgcNcPuiJ X-Received: by 10.80.189.200 with SMTP id z8mr27994576edh.46.1517066447651; Sat, 27 Jan 2018 07:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517066447; cv=none; d=google.com; s=arc-20160816; b=iTB8WKn4KrDyWkU9fFC3QZ4DDnznkLf5uxgjW34PiCpNRcZY9uBVYvBVa62xZy+RAO SBJ24WQl7Sk+c/Gpx3drwH1od4hjCm2EXKfqZhl34LXeQ6YdZtn4LCE7iD8aBbSsHqmM WYF0dxcxxH1fkv5gQBiDcUBgeCa9Todn252IVpdAgVEMVg/XQwV5o8g9R6wMrsApxqiO t4t4jwVBAi+fcVM4M0vpZrntKmMls49siwqXcQPd//HEyHAqoI/OPEFy7yfuc6C2Y94N ZjFB/HeMDv8g9wUQsZMjTAuOTqB2PVcpccqQ43dq0pkjnX+/4xQ7fbSfxUFTZ+tLdJDp sk3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=1VEDolJzBo1jausoqTxQElKY7j7rgyk37L1a2H9Lfq0=; b=0+95uQ8DhMrVdcIFzFWsBP6IJE1s1KXuNugp1aFcK4l0u0OeXe+n10cdTqiLUo9o66 3gzlgD5fhWi6/U8sMzfgIWKmhYu8mya3gpSgFhR657UxnqXKRsG547e32R7pDDeWYyz7 gqPTRFXetqP8hHeOBbJ9S8S2UYaXH9y255fcKnqkkf+JgXnH1maKFEY99l34NWYxcBvy j4jgN/3eDw6FG2KfZJxllBAdKG3kcTqDJsA8/8/j66T2hJ1/dKdS6Gl0TmpeDoD9mlkS 6UPCqKTC9csz3vuHPOdGevvSR9tL9/NBHYNC6tCRFSqhT1pT9ylz+GbsBClehRJ1c0uz GIzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ejIiJ4CY; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id p4si5749165edm.328.2018.01.27.07.20.46; Sat, 27 Jan 2018 07:20:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ejIiJ4CY; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 82C31C21E68; Sat, 27 Jan 2018 15:20:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3AC20C21E30; Sat, 27 Jan 2018 15:20:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 12F8CC21E68; Sat, 27 Jan 2018 15:20:38 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by lists.denx.de (Postfix) with ESMTPS id 704DEC21E26 for ; Sat, 27 Jan 2018 15:20:37 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id n17so1770395pgf.10 for ; Sat, 27 Jan 2018 07:20:37 -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=UUTGC2JXFqahzNrEJbwXVwL0bBhmHk2/gEyaZOiI2CQ=; b=ejIiJ4CYZsD+g9lsmpOnDP162oA2O4AMtI9SEKt8C0RbNuCWJvy8eXTSqrDKdSTD7I paajtyW3cDPzMQf/kSGNGxMvnWhVZ7QKnHfuCeaxfTX8phgqseoKlG1XSVSN8zdErjpt +GaXVs0e4oCpo2VCNfFqdkFuYI9/b6yZiXoCU= 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=UUTGC2JXFqahzNrEJbwXVwL0bBhmHk2/gEyaZOiI2CQ=; b=izA5c2w3UDTuMXduRyDX/w++2/VTaEmWzZJW7OXJdcta3T8aGIULou1Pb3x7jng+hZ XvS3JhZGsBqBW2yhjS63jSlf7tLE5dphhzwS1jATjMAZ6b5gOxP/dvR8b4DN+TalWxo5 FymjAkkldvAII82NqCMcl7PjQr/5iAfABbape6yjmwKjQwteh9jaAgoBIYJdnSHcFiE8 DapyZq9aiXwl82sNGKWXWBENH3LEFhvMwuY87rpih4ZwL2gdQ/770epg3047Rf1MWLTX e1Z3zajJytwOAXaaCk3yfnttR22PrZ8LLwFMCKdQcWl1aWKxl5ogxx5zR3S3VRlq28SF Lm2A== X-Gm-Message-State: AKwxytebABMu7dxIN3js+KBYgUoVMTepTU/O4QfRkoQdfpiuNpiV6GLC AZOh8yNYtnGZl3C9UgI3CxKAeA== X-Received: by 10.99.172.25 with SMTP id v25mr17895827pge.148.1517066435711; Sat, 27 Jan 2018 07:20:35 -0800 (PST) Received: from localhost.localdomain (61-216-91-114.HINET-IP.hinet.net. [61.216.91.114]) by smtp.gmail.com with ESMTPSA id f3sm3886180pgn.9.2018.01.27.07.20.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 27 Jan 2018 07:20:34 -0800 (PST) From: Jun Nie To: icenowy@aosc.xyz, andre.przywara@arm.com, siarhei.siamashka@gmail.com, wens@csie.org, 370719159@qq.com Date: Sat, 27 Jan 2018 23:20:27 +0800 Message-Id: <1517066427-19157-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] sunxi: support fuse cmd to read/write fuse X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Support fuse cmd to read/write fuse. Power supply for fuse should be ready, name is VDD_EFUSE in some schematic. Signed-off-by: Jun Nie --- arch/arm/mach-sunxi/cpu_info.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/arch/arm/mach-sunxi/cpu_info.c b/arch/arm/mach-sunxi/cpu_info.c index 25a5ec2..30bc2bf 100644 --- a/arch/arm/mach-sunxi/cpu_info.c +++ b/arch/arm/mach-sunxi/cpu_info.c @@ -133,6 +133,30 @@ uint32_t sun8i_efuse_read(uint32_t offset) reg_val = readl(SUNXI_SIDC_BASE + SIDC_RDKEY); return reg_val; } + +uint32_t sun8i_efuse_write(u32 offset, u32 val) +{ + u32 reg_val; + + writel(val, SUNXI_SIDC_BASE + SIDC_RDKEY); + + reg_val = readl(SUNXI_SIDC_BASE + SIDC_PRCTL); + reg_val &= ~(((0x1ff) << 16) | 0x3); + reg_val |= (offset << 16); + writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL); + + reg_val &= ~(((0xff) << 8) | 0x3); + reg_val |= (SIDC_OP_LOCK << 8) | 0x1; + writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL); + + while (readl(SUNXI_SIDC_BASE + SIDC_PRCTL) & 0x1) + ; + + reg_val &= ~(((0x1ff) << 16) | ((0xff) << 8) | 0x3); + writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL); + + return 0; +} #endif int sunxi_get_sid(unsigned int *sid) @@ -164,3 +188,39 @@ int sunxi_get_sid(unsigned int *sid) return -ENODEV; #endif } + +int fuse_read(u32 bank, u32 word, u32 *sid) +{ +#ifdef CONFIG_MACH_SUN8I_H3 + *sid = sun8i_efuse_read(word); +#elif defined SUNXI_SID_BASE + *sid = readl((ulong)SUNXI_SID_BASE + word); +#else + return -ENODEV; +#endif + return 0; +} + +int fuse_prog(u32 bank, u32 word, u32 val) +{ +#ifdef CONFIG_MACH_SUN8I_H3 + return sun8i_efuse_write(word, val); +#elif defined SUNXI_SID_BASE + writel(val, (ulong)SUNXI_SID_BASE + word); +#else + return -ENODEV; +#endif + return 0; +} + +int fuse_sense(u32 bank, u32 word, u32 *val) +{ + /* We do not support sensing :-( */ + return -EINVAL; +} + +int fuse_override(u32 bank, u32 word, u32 val) +{ + /* We do not support overriding :-( */ + return -EINVAL; +}