From patchwork Sat Aug 27 13:43:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 9302409 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 647CD601C0 for ; Sat, 27 Aug 2016 13:49:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53CB32891B for ; Sat, 27 Aug 2016 13:49:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48CCA28921; Sat, 27 Aug 2016 13:49: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 D9F5E2891B for ; Sat, 27 Aug 2016 13:49: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 1bddxo-0003xY-Ss; Sat, 27 Aug 2016 13:48:00 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bdduH-0008IB-9b; Sat, 27 Aug 2016 13:44:25 +0000 Received: by mail-wm0-x243.google.com with SMTP id q128so3218949wma.1; Sat, 27 Aug 2016 06:44:03 -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=JVMNS6b7nvK+JMZbc3Y/rCEWsnNWcPOOOjybsGLWw2w=; b=iLoiBfJt7qIJVfo5+rCwSkAmNdTVex/LKvuybPhyAWJGcQe33gKmyxTsAn6tXdoRTi ic759EyDbNntcZiJmsK75M7A3gH4IVccyJDmKVLgLIgJC0F3sl0skaW9u2DHmhbY+uYA 2dolsn2cCjRxaFyBkk995t7iSgUKsUC3m4fL8AaYAFcmDPFQIQMBSmiADSWUcwuRoJLS QU8zlY/7OiKa3Q7tbmdvIYQ2Xe0NdkdH/NXr/YnMSm2gmZdZSucZWYZnAc65QSLl5UIN nehSGqGi4vWTJQlfsHr908sWppZB78izn1q4I1G4WifmN/cbf1rj4miKhIfimcjvYe38 gxzA== 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=JVMNS6b7nvK+JMZbc3Y/rCEWsnNWcPOOOjybsGLWw2w=; b=d9Vtxh5JGcRUBuPw1//H/0ZdI66tZEgj5DIc6wxnRaR8+X9m+3eSOjCdS+cklbinC8 rVAhMwme33eJpgxkm+ahMCmT8feWIwOsvI7QnEr/xfsxnpM+tgZIJFzjxMElcyO8QnkF WtGSL/nSsa8zYH1dkGGqDIHYMDo5onwZiXd8+bLJ8ePSze7myMbCH4/ZMjlfdIHuwK7o YLXleB66q+LF0ikeUK8Q2/g5iLEPk15mY1Syu/NQd3IiZLRpyrh5UiYyI0gdsK0g0qOg frfPLKvDfLDJJXal1nLAo4poS3ZejEL4u79jB10csIa13vmjk+gB68u8H7dmQDolp8fp 2nQg== X-Gm-Message-State: AE9vXwM6e7+pMPnJsrl/BgBaCf7mX2Jf+JmI0YbbZiK7kIzkETB9tjOtH82aqZ2PFFfYgA== X-Received: by 10.194.184.148 with SMTP id eu20mr9378145wjc.137.1472305442231; Sat, 27 Aug 2016 06:44:02 -0700 (PDT) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id d7sm24769353wjg.13.2016.08.27.06.44.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 27 Aug 2016 06:44:01 -0700 (PDT) From: Carlo Caione To: linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux@endlessm.com, khilman@baylibre.com, mark.rutland@arm.com, matthias.bgg@gmail.com, narmstrong@baylibre.com, bjdooks@googlemail.com, srinivas.kandagatla@linaro.org Subject: [PATCH v3 4/6] nvmem: amlogic: Add Amlogic Meson EFUSE driver Date: Sat, 27 Aug 2016 15:43:46 +0200 Message-Id: <1472305428-16874-5-git-send-email-carlo@caione.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472305428-16874-1-git-send-email-carlo@caione.org> References: <1472305428-16874-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160827_064421_609312_010D67F1 X-CRM114-Status: GOOD ( 17.66 ) 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. Acked-by: Srinivas Kandagatla Signed-off-by: Carlo Caione --- 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 f550c45..ba140ea 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");