From patchwork Wed Jun 29 12:34:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 9205039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6602F607D8 for ; Wed, 29 Jun 2016 12:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 560ED28633 for ; Wed, 29 Jun 2016 12:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AD4A28662; Wed, 29 Jun 2016 12:38:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB6F328633 for ; Wed, 29 Jun 2016 12:38:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIEjz-0005Bt-CD; Wed, 29 Jun 2016 12:37:15 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIEih-0004LZ-8L; Wed, 29 Jun 2016 12:35:59 +0000 Received: by mail-wm0-x244.google.com with SMTP id r201so14015114wme.0; Wed, 29 Jun 2016 05:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=SpA8nlgUty24uPZ0mR9QK32mUqR5BOJfICiZK+k59xQ=; b=sGpJCFSDq3CT4wa4uczg8Xjrb7BTVBpQXM0WNAMkwN1zBKIZ9DnfamBOvySn93dqVw 9a2BYSR6Z6ujHIanmtzrkhOLQXCk7ezB+WGFGKXBe6/a+gOs9vj/T9fR9N41yv7M97Pt GfTAhz01dwZKd0IDYcESbbhEVSj5sV4R/00o7oN/d4x5VjPoyNFfu4XxJsl4OaB0K1Kd ceQJQkwpQ6owc6mjPucZ2cKz4NhaQHiev/CpihnTfi4s8xJslh/+o2GvsKn/xpjHEkFQ sjF6cyYoakzqLXxRDCNbCrMCT6m0ZQC3XxqtYTIURQUuT4vgt0MAaP64jYEqqDBsM/UT Mdag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=SpA8nlgUty24uPZ0mR9QK32mUqR5BOJfICiZK+k59xQ=; b=MykkmAVk0/KcfF9Ont9zcVoWQmGMFdGq4/faWwGZxRvW2WN4xMonA63RFaBcN2oNpw Npw5EPK9E+6Bzep0F0CTTBJvJIezdo3Cl9Uo9eiRBlWextZJ/6MacHQnqHYMFDUJka+t /YsFKOpxJB8WSQYTVHjBI8ncvU1ocqHXhOP8uaMuF7k0+pMyTNcaLkSEB8AL8eaM/68H IHEYzrDkm7HYnpaBgP0M931ck+M8wrVWDtJrHajFcnZsqFoDRIKZjcZ6FGykolrAT3YD rdSOImR/E61QnL+7vXSgIOTAo0S2E0gbN2kKJjfMRhR3nC484wzx5ZfXoehMlXDAA2ye eAwA== X-Gm-Message-State: ALyK8tKnnDIZYwEfPl16X2dsuA37aCuwpHI7KDbAsvXxcmS6mcAkSp5ldLn13/3wWKz7OQ== X-Received: by 10.28.130.15 with SMTP id e15mr15860018wmd.19.1467203736009; Wed, 29 Jun 2016 05:35:36 -0700 (PDT) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id k3sm3512653wju.29.2016.06.29.05.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jun 2016 05:35:34 -0700 (PDT) From: Carlo Caione To: linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux@endlessm.com, devicetree@vger.kernel.org, khilman@baylibre.com, mark.rutland@arm.com, robh+dt@kernel.org, matthias.bgg@gmail.com, narmstrong@baylibre.com, bjdooks@googlemail.com, srinivas.kandagatla@linaro.org, maxime.ripard@free-electrons.com Subject: [PATCH v2 4/6] nvmem: amlogic: Add Amlogic Meson EFUSE driver Date: Wed, 29 Jun 2016 14:34:14 +0200 Message-Id: <1467203656-14381-5-git-send-email-carlo@caione.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467203656-14381-1-git-send-email-carlo@caione.org> References: <1467203656-14381-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160629_053555_478462_CB58F37A X-CRM114-Status: GOOD ( 18.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlo Caione MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Carlo Caione Add Amlogic EFUSE driver to access hardware data like ethernet address, serial number or IDs. Signed-off-by: Carlo Caione Acked-by: Srinivas Kandagatla --- drivers/nvmem/Kconfig | 10 +++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/meson-efuse.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 drivers/nvmem/meson-efuse.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 3041d48..87900d3 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -101,4 +101,14 @@ config NVMEM_VF610_OCOTP This driver can also be build as a module. If so, the module will be called nvmem-vf610-ocotp. +config MESON_EFUSE + tristate "Amlogic eFuse Support" + depends on (ARCH_MESON || COMPILE_TEST) && MESON_SM + help + This is a driver to retrieve specific values from the eFuse found on + the Amlogic Meson SoCs. + + This driver can also be built as a module. If so, the module + will be called nvmem_meson_efuse. + endif diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 45ab1ae..8f942a0 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -22,3 +22,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o nvmem_sunxi_sid-y := sunxi_sid.o obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o nvmem-vf610-ocotp-y := vf610-ocotp.o +obj-$(CONFIG_MESON_EFUSE) += nvmem_meson_efuse.o +nvmem_meson_efuse-y := meson-efuse.o diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c new file mode 100644 index 0000000..f207c3b --- /dev/null +++ b/drivers/nvmem/meson-efuse.c @@ -0,0 +1,93 @@ +/* + * Amlogic eFuse Driver + * + * Copyright (c) 2016 Endless Computers, Inc. + * Author: Carlo Caione + * + * This 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. + * + * This 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. + */ + +#include +#include +#include +#include + +#include + +static int meson_efuse_read(void *context, unsigned int offset, + void *val, size_t bytes) +{ + u8 *buf = val; + int ret; + + ret = meson_sm_call_read(buf, SM_EFUSE_READ, offset, + bytes, 0, 0, 0); + if (ret < 0) + return ret; + + return 0; +} + +static struct nvmem_config econfig = { + .name = "meson-efuse", + .owner = THIS_MODULE, + .stride = 1, + .word_size = 1, + .read_only = true, +}; + +static const struct of_device_id meson_efuse_match[] = { + { .compatible = "amlogic,meson-gxbb-efuse", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, meson_efuse_match); + +static int meson_efuse_probe(struct platform_device *pdev) +{ + struct nvmem_device *nvmem; + unsigned int size; + + if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) + return -EINVAL; + + econfig.dev = &pdev->dev; + econfig.reg_read = meson_efuse_read; + econfig.size = size; + + nvmem = nvmem_register(&econfig); + if (IS_ERR(nvmem)) + return PTR_ERR(nvmem); + + platform_set_drvdata(pdev, nvmem); + + return 0; +} + +static int meson_efuse_remove(struct platform_device *pdev) +{ + struct nvmem_device *nvmem = platform_get_drvdata(pdev); + + return nvmem_unregister(nvmem); +} + +static struct platform_driver meson_efuse_driver = { + .probe = meson_efuse_probe, + .remove = meson_efuse_remove, + .driver = { + .name = "meson-efuse", + .of_match_table = meson_efuse_match, + }, +}; + +module_platform_driver(meson_efuse_driver); + +MODULE_AUTHOR("Carlo Caione "); +MODULE_DESCRIPTION("Amlogic Meson NVMEM driver"); +MODULE_LICENSE("GPL v2");