From patchwork Wed Nov 21 13:11:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 10692553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C621B16B1 for ; Wed, 21 Nov 2018 13:14:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF92A2B6AD for ; Wed, 21 Nov 2018 13:14:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A07972B6B3; Wed, 21 Nov 2018 13:14:50 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2DE392B6AD for ; Wed, 21 Nov 2018 13:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ufu/e7rUuTJ3b+pqkMCpKxTyMM0A3r/PatnPjtJP2kU=; b=GxThaFTI1Ss8uKswTEml9I828C jfHs3NAe3aQb/ehmec32Qo4DnKjFrTp5qBebuqbWve0SbsqTac+sbZbhtmIfhCu1fEBylM/NuLw70 nJmt/Lx/m4t5qbF9WfMdAiBuEEbX3M5BBTeSKusV9SA9ZQVIOSiEoipdMAe1c8pfXxXpEQM/IOf6s ZUlbiwOefbCXq41/e9f9xXUjhXB5jCc+ddMC8Qwfd3DtuCOoG7d653UssOY7yEo52dotzjVH7KsKG Y1tEAnswbGrPHNhsJTtKebQIrXIl8u4OJ+7jLwxHlVBTMVLaUuoYqtQVvMuq1l8S2Pzw6CEInFHoW KafLcwLw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPSLA-0005M4-Qs; Wed, 21 Nov 2018 13:14:48 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPSJD-0003d8-1R; Wed, 21 Nov 2018 13:12:50 +0000 Received: from localhost.localdomain ([37.4.249.153]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MOiLp-1g4k7Q3iut-00Q9xj; Wed, 21 Nov 2018 14:12:28 +0100 From: Stefan Wahren To: Srinivas Kandagatla , Rob Herring , Mark Rutland , Florian Fainelli , Ray Jui , Scott Branden , Eric Anholt , Arnd Bergmann , gregkh@linuxfoundation.org Subject: [PATCH 2/5] nvmem: add driver for Raspberry Pi OTP Date: Wed, 21 Nov 2018 14:11:41 +0100 Message-Id: <1542805904-6446-3-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542805904-6446-1-git-send-email-stefan.wahren@i2se.com> References: <1542805904-6446-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:oLqF21a5OP4mEzch0fraRBzRWqbLA2paHUsnNvo+6XgcLi8gMTl bi6y6CYUfrY8Qfgs2jLY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-CRM114-CacheID: sfid-20181121_051247_401615_2C252CB9 X-CRM114-Status: GOOD ( 23.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , devicetree@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org 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 This patch brings read-only support for the Raspberry Pi Customer OTP, which consists of 8 cells a 32 bits. The driver accesses the OTP via the mailbox property interface provided by the VPU firmware. Signed-off-by: Stefan Wahren Reviewed-by: Eric Anholt --- drivers/nvmem/Kconfig | 10 ++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/raspberrypi-otp.c | 113 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 drivers/nvmem/raspberrypi-otp.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 0a7a470e..12106fe 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -192,4 +192,14 @@ config SC27XX_EFUSE This driver can also be built as a module. If so, the module will be called nvmem-sc27xx-efuse. +config NVMEM_RASPBERRYPI_OTP + tristate "Raspberry Pi Customer OTP support" + depends on (ARCH_BCM2835 && RASPBERRYPI_FIRMWARE) || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE) + help + This is a driver for access to the Customer OTP block + (8 cells * 32 bits) on the Raspberry Pi. + + This driver can also be built as a module. If so, the module + will be called nvmem-raspberrypi-otp. + endif diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 4e8c616..dd043bd 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -41,3 +41,5 @@ obj-$(CONFIG_RAVE_SP_EEPROM) += nvmem-rave-sp-eeprom.o nvmem-rave-sp-eeprom-y := rave-sp-eeprom.o obj-$(CONFIG_SC27XX_EFUSE) += nvmem-sc27xx-efuse.o nvmem-sc27xx-efuse-y := sc27xx-efuse.o +obj-$(CONFIG_NVMEM_RASPBERRYPI_OTP) += nvmem-raspberrypi-otp.o +nvmem-raspberrypi-otp-y := raspberrypi-otp.o diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c new file mode 100644 index 0000000..af6b228 --- /dev/null +++ b/drivers/nvmem/raspberrypi-otp.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Raspberry Pi Customer OTP driver + * + * Copyright (C) 2018 Stefan Wahren + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define CUSTOMER_CELLS 8 + +struct rpi_otp { + struct nvmem_device *nvmem; + struct rpi_firmware *fw; +}; + +/* + * Packet definition used by RPI_FIRMWARE_GET_CUSTOMER_OTP + */ +struct rpi_customer_otp_packet { + u32 index; + u32 length; + u8 cells[CUSTOMER_CELLS * 4]; +}; + +static int rpi_otp_read(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct rpi_customer_otp_packet packet; + struct rpi_otp *otp = context; + int ret; + + packet.index = 0; + packet.length = CUSTOMER_CELLS; + memset(packet.cells, 0xff, sizeof(packet.cells)); + + ret = rpi_firmware_property(otp->fw, RPI_FIRMWARE_GET_CUSTOMER_OTP, + &packet, sizeof(packet)); + + if (ret) + return ret; + + /* Request rejected by firmware */ + if (packet.index) + return -EIO; + + memcpy(val, &packet.cells[offset], bytes); + + return 0; +} + +static struct nvmem_config ocotp_config = { + .name = "rpi-customer-otp", + .read_only = true, + .type = NVMEM_TYPE_OTP, + .size = CUSTOMER_CELLS * 4, + .stride = 4, + .word_size = 4, + .reg_read = rpi_otp_read, +}; + +static int rpi_otp_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *fw_node; + struct rpi_otp *otp; + + otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL); + if (!otp) + return -ENOMEM; + + fw_node = of_get_parent(dev->of_node); + if (!fw_node) { + dev_err(dev, "Missing firmware node\n"); + return -ENOENT; + } + + otp->fw = rpi_firmware_get(fw_node); + of_node_put(fw_node); + if (!otp->fw) + return -EPROBE_DEFER; + + ocotp_config.priv = otp; + ocotp_config.dev = dev; + otp->nvmem = devm_nvmem_register(dev, &ocotp_config); + + return PTR_ERR_OR_ZERO(otp->nvmem); +} + +static const struct of_device_id rpi_otp_of_match[] = { + { .compatible = "raspberrypi,bcm2835-customer-otp", }, + { /* sentinel */}, +}; +MODULE_DEVICE_TABLE(of, rpi_otp_of_match); + +static struct platform_driver rpi_otp_driver = { + .probe = rpi_otp_probe, + .driver = { + .name = "rpi-customer-otp", + .of_match_table = rpi_otp_of_match, + }, +}; +module_platform_driver(rpi_otp_driver); + +MODULE_AUTHOR("Stefan Wahren "); +MODULE_DESCRIPTION("Raspberry Pi Customer OTP driver"); +MODULE_LICENSE("GPL");