From patchwork Sun Jun 19 12:39:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 9186133 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 8B01460465 for ; Sun, 19 Jun 2016 12:40:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 789A525404 for ; Sun, 19 Jun 2016 12:40:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D4032821F; Sun, 19 Jun 2016 12:40:42 +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=ham 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 CA4D625404 for ; Sun, 19 Jun 2016 12:40:41 +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 1bEc1m-0004cy-O8; Sun, 19 Jun 2016 12:40:38 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bEc0r-0002sO-LE; Sun, 19 Jun 2016 12:39:46 +0000 Received: by mail-wm0-x243.google.com with SMTP id c82so4948178wme.3; Sun, 19 Jun 2016 05:39:21 -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=kUUxvAOUyYrUFrYyd2eer5/uMLqHtdSAUQlqGZ70fcQ=; b=FMoex6t1Xextm+q1Io7qQ4ghpF8IybxYR9bB/u+mamMX89RGSqbjiWEdJXOGyuIkOL VYCXCvC/BMKZnYc21W/svKT2YOK008o5XDRTMXXIEJb6uTEopVzcriqUIIys2MUrgQqR Aid28Vs7r9vbd/iAejZRFSkRA92HfccyHVs2KDeB83KV8Ku2rZjHfy/aom+Q/hn5dpmq +gvab9wFmlNdvprZk4rykgpd6RFWHLjKu43Y3N3mRE6sEWgNDEfdBZ7hYtLl7wzuVt0W 7BQf+tZDjRtXRQ6tVKnL5KdK8mwWTrcxjPSzWk7MzQCLuivk++6LwbrzTBmCP36jR1ZZ 09og== 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=kUUxvAOUyYrUFrYyd2eer5/uMLqHtdSAUQlqGZ70fcQ=; b=MpIJ4x2scVQupKbdECj18ZQqKRlIOtiYYWoV05gQv9mjVknAd2+qr3Rs8zBvEffxK0 Ma6I3lr+FHhZH5mPs+XT5GXMMIgf0pmwF/goMTzUEC5HHLFxWKeuMylk74SUrPGPf/E2 5gK8qO6sAP9R5rVBSNUTnlR//l+/E9tcLUSYy7594KgH/mC9GFi8Y5BFREor3tqpg+qp 6u3OnFMj+AYMwBGcNuNLNxW02VTOyfRJCPaoaXw7O8WY+YH3XmBjMoVQktLApxz2fvVI 1WbzT2of0FfnhJ/m8nLZStTXvJ3yV2pCH2qqS+D82pyTSGmzOJC6OklCws3qpxD1tuGD rcuA== X-Gm-Message-State: ALyK8tJ1wKZ+zRKTZ71eagBA5cp9ebrDYd5TgYz82vz/TRkIfWy/A0nQoZYkxisL/DLcBw== X-Received: by 10.194.133.98 with SMTP id pb2mr9984517wjb.144.1466339959907; Sun, 19 Jun 2016 05:39:19 -0700 (PDT) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id b187sm6683639wmg.15.2016.06.19.05.39.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 Jun 2016 05:39:19 -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 4/6] nvmem: amlogic: Add Amlogic Meson EFUSE driver Date: Sun, 19 Jun 2016 14:39:02 +0200 Message-Id: <1466339944-602-5-git-send-email-carlo@caione.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466339944-602-1-git-send-email-carlo@caione.org> References: <1466339944-602-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160619_053942_140135_46701670 X-CRM114-Status: GOOD ( 19.57 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=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 --- drivers/nvmem/Kconfig | 11 ++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/meson-efuse.c | 130 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 drivers/nvmem/meson-efuse.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index ca52952..ef17bc9 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -102,4 +102,15 @@ 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 + select REGMAP_MMIO + 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..7c80e1c --- /dev/null +++ b/drivers/nvmem/meson-efuse.c @@ -0,0 +1,130 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include + +static struct meson_sm_firmware *fw; + +static int meson_efuse_write(void *context, const void *data, size_t count) +{ + /* Nothing TBD, Read-Only */ + return 0; +} + +static int meson_efuse_read(void *context, + const void *reg, size_t reg_size, + void *val, size_t val_size) +{ + unsigned int offset = *(u32 *)reg; + u8 *buf = val; + int ret; + + ret = meson_sm_call_read(fw, buf, SM_EFUSE_READ, offset, + val_size, 0, 0, 0); + if (ret < 0) + return ret; + + return 0; +} + +static struct nvmem_config econfig = { + .name = "meson-efuse", + .owner = THIS_MODULE, + .read_only = true, +}; + +static struct regmap_bus meson_efuse_bus = { + .read = meson_efuse_read, + .write = meson_efuse_write, + .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, + .val_format_endian_default = REGMAP_ENDIAN_NATIVE, +}; + +static struct regmap_config meson_efuse_regmap_config = { + .reg_bits = 32, + .reg_stride = 1, + .val_bits = 8, +}; + +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; + struct regmap *regmap; + unsigned int size; + + fw = meson_sm_get_fw(); + if (!fw) + return -EPROBE_DEFER; + + if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) + return -EINVAL; + meson_efuse_regmap_config.max_register = size - 1; + + regmap = devm_regmap_init(&pdev->dev, &meson_efuse_bus, + NULL, &meson_efuse_regmap_config); + if (IS_ERR(regmap)) { + dev_err(&pdev->dev, "regmap init failed\n"); + return PTR_ERR(regmap); + } + + econfig.dev = &pdev->dev; + 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");