From patchwork Mon Dec 1 07:34:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianqun Xu X-Patchwork-Id: 5410351 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E39C89F30B for ; Mon, 1 Dec 2014 07:39:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCA2320295 for ; Mon, 1 Dec 2014 07:39:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8A4620270 for ; Mon, 1 Dec 2014 07:39:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XvLaG-0007C8-8x; Mon, 01 Dec 2014 07:39:48 +0000 Received: from regular1.263xmail.com ([211.150.99.137]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XvLZr-00073W-3M; Mon, 01 Dec 2014 07:39:26 +0000 Received: from jay.xu?rock-chips.com (unknown [192.168.167.131]) by regular1.263xmail.com (Postfix) with SMTP id D569264FB; Mon, 1 Dec 2014 15:38:23 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 4FECD427; Mon, 1 Dec 2014 15:38:22 +0800 (CST) X-RL-SENDER: jay.xu@rock-chips.com X-SENDER-IP: 127.0.0.1 X-LOGIN-NAME: jay.xu@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: xjq@rock-chips.com X-DNS-TYPE: 0 Received: from unknown (unknown [127.0.0.1]) by smtp.263.net (Postfix) whith SMTP id 1686057ANQ5; Mon, 01 Dec 2014 15:38:23 +0800 (CST) From: Jianqun Xu To: heiko@sntech.de, linux@arm.linux.org.uk, grant.likely@linaro.org, robh+dt@kernel.org Subject: [PATCH 2/2] rockchip: efuse: add efuse driver for rk3288 efuse Date: Mon, 1 Dec 2014 15:34:41 +0800 Message-Id: <1417419281-9243-3-git-send-email-jay.xu@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417419281-9243-1-git-send-email-jay.xu@rock-chips.com> References: <1417419281-9243-1-git-send-email-jay.xu@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141130_233924_249831_14616FA5 X-CRM114-Status: GOOD ( 13.50 ) X-Spam-Score: -0.0 (/) Cc: linux-rockchip@lists.infradead.org, Jianqun Xu , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add driver for efuse found on rk3288 board based on rk3288 SoC. Driver will read fuse information of chip at the boot stage of kernel, this information new is for further usage. Signed-off-by: Jianqun Xu --- arch/arm/mach-rockchip/efuse.c | 165 +++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-rockchip/efuse.h | 15 ++++ 2 files changed, 180 insertions(+) create mode 100644 arch/arm/mach-rockchip/efuse.c create mode 100644 arch/arm/mach-rockchip/efuse.h diff --git a/arch/arm/mach-rockchip/efuse.c b/arch/arm/mach-rockchip/efuse.c new file mode 100644 index 0000000..326d81e --- /dev/null +++ b/arch/arm/mach-rockchip/efuse.c @@ -0,0 +1,165 @@ +/* mach-rockchip/efuse.c + * + * Copyright (c) 2014 Rockchip Electronics Co. Ltd. + * Author: Jianqun Xu + * + * Tmis program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * Tmis program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * tmis program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * Tme full GNU General Public License is included in this distribution in the + * file called LICENSE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "efuse.h" + +#define EFUSE_BUF_SIZE (32) +#define EFUSE_BUF_LKG_CPU (23) +#define EFUSE_BUF_LKG_GPU (24) +#define EFUSE_BUF_LKG_LOG (25) + +struct rk_efuse_info { + /* Platform device */ + struct device *dev; + + /* Hardware resources */ + void __iomem *regs; + + /* buffer to store registers' values */ + unsigned int buf[EFUSE_BUF_SIZE]; +}; + +static void efuse_writel(struct rk_efuse_info *efuse, + unsigned int value, + unsigned int offset) +{ + writel_relaxed(value, efuse->regs + offset); +} + +static unsigned int efuse_readl(struct rk_efuse_info *efuse, + unsigned int offset) +{ + return readl_relaxed(efuse->regs + offset); +} + +static unsigned int rockchip_efuse_leakage(struct rk_efuse_info *efuse, + int channel) +{ + switch (channel) { + case EFUSE_BUF_LKG_CPU: + case EFUSE_BUF_LKG_GPU: + case EFUSE_BUF_LKG_LOG: + return efuse->buf[channel]; + default: + dev_err(efuse->dev, "unknown channel\n"); + return -EINVAL; + } + + return 0; +} + +static void rockchip_efuse_info(struct rk_efuse_info *efuse) +{ + dev_info(efuse->dev, "leakage (%d %d %d)\n", + rockchip_efuse_leakage(efuse, EFUSE_BUF_LKG_CPU), + rockchip_efuse_leakage(efuse, EFUSE_BUF_LKG_GPU), + rockchip_efuse_leakage(efuse, EFUSE_BUF_LKG_LOG)); +} + +static int rockchip_efuse_init(struct rk_efuse_info *efuse) +{ + int start = 0; + int ret = 0; + + efuse_writel(efuse, EFUSE_CSB, REG_EFUSE_CTRL); + efuse_writel(efuse, EFUSE_LOAD | EFUSE_PGENB, REG_EFUSE_CTRL); + udelay(2); + + for (start = 0; start <= EFUSE_BUF_SIZE; start++) { + efuse_writel(efuse, efuse_readl(efuse, REG_EFUSE_CTRL) & + (~(EFUSE_A_MASK << EFUSE_A_SHIFT)), + REG_EFUSE_CTRL); + efuse_writel(efuse, efuse_readl(efuse, REG_EFUSE_CTRL) | + ((start & EFUSE_A_MASK) << EFUSE_A_SHIFT), + REG_EFUSE_CTRL); + udelay(2); + efuse_writel(efuse, efuse_readl(efuse, REG_EFUSE_CTRL) | + EFUSE_STROBE, REG_EFUSE_CTRL); + udelay(2); + + efuse->buf[start] = efuse_readl(efuse, REG_EFUSE_DOUT); + + efuse_writel(efuse, efuse_readl(efuse, REG_EFUSE_CTRL) & + (~EFUSE_STROBE), REG_EFUSE_CTRL); + udelay(2); + } + + udelay(2); + efuse_writel(efuse, efuse_readl(efuse, REG_EFUSE_CTRL) | + EFUSE_CSB, REG_EFUSE_CTRL); + udelay(2); + + return ret; +} + +static int rockchip_efuse_probe(struct platform_device *pdev) +{ + struct rk_efuse_info *efuse; + struct resource *mem; + int ret = 0; + + efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL); + if (!efuse) + return -ENOMEM; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + efuse->regs = devm_ioremap_resource(&pdev->dev, mem); + if (IS_ERR(efuse->regs)) + return PTR_ERR(efuse->regs); + + platform_set_drvdata(pdev, efuse); + efuse->dev = &pdev->dev; + + ret = rockchip_efuse_init(efuse); + if (!ret) + rockchip_efuse_info(efuse); + + return ret; +} + +static const struct of_device_id rockchip_efuse_match[] = { + { .compatible = "rockchip,rk3288-efuse", }, + {}, +}; + +static struct platform_driver rockchip_efuse_driver = { + .probe = rockchip_efuse_probe, + .driver = { + .name = "rk3288-efuse", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(rockchip_efuse_match), + }, +}; + +module_platform_driver(rockchip_efuse_driver); + +MODULE_DESCRIPTION("Rockchip eFuse Driver"); +MODULE_AUTHOR("Jianqun Xu "); +MODULE_LICENSE("GPL v2"); diff --git a/arch/arm/mach-rockchip/efuse.h b/arch/arm/mach-rockchip/efuse.h new file mode 100644 index 0000000..3fdcf6d --- /dev/null +++ b/arch/arm/mach-rockchip/efuse.h @@ -0,0 +1,15 @@ +#ifndef _ARCH_ROCKCHIP_EFUSE_H_ +#define _ARCH_ROCKCHIP_EFUSE_H_ + +/* Rockchip eFuse controller register */ +#define EFUSE_A_SHIFT (6) +#define EFUSE_A_MASK (0x3FF) +#define EFUSE_PGENB (1 << 3) +#define EFUSE_LOAD (1 << 2) +#define EFUSE_STROBE (1 << 1) +#define EFUSE_CSB (1 << 0) + +#define REG_EFUSE_CTRL (0x0000) +#define REG_EFUSE_DOUT (0x0004) + +#endif /* _ARCH_ROCKCHIP_EFUSE_H_ */