From patchwork Fri Mar 19 18:28:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Ciocaltea X-Patchwork-Id: 12151705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0045DC433C1 for ; Fri, 19 Mar 2021 18:30:18 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76A6661977 for ; Fri, 19 Mar 2021 18:30:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76A6661977 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MKFgBwZa00eJZKwhPNWDLXE+bu3Zj9R4onxXLZn4y2Y=; b=WNy+iW6IV1E7+lt2RBwGB8jOY xj8KojRYvjgawHOLoZahyQCuKLR06t3kOOed8Ju/FS4KOCriu2p+waUykaxTrTVPwCwWU9rftEvmf Mz4VGPabsqqf714/jWtze0yFsaxmp06zJJiV19Cqm6VT/fuCVvDb+Rm3n5TdcSPgsOzEE5rciJK4g LmtYfmCjZwIQGALRsc1lRN59dSFuGSW01ZUNfwo/FcSi4xoDW3FJ6jcXU83xMuLhvHg2Opwqwi1hP L+MzfhK//2ltqSRUc5+wURMAI6wfflngDah5ZO0gmVMOAQBnvFo7x0iTxVfEK6y6yB96pue9EQj8S suCvE28hA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNJrI-007wU2-BK; Fri, 19 Mar 2021 18:28:28 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNJqx-007wPY-63; Fri, 19 Mar 2021 18:28:10 +0000 Received: by mail-ej1-x630.google.com with SMTP id r12so11255194ejr.5; Fri, 19 Mar 2021 11:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cZBBDJ1FYBuLzTfmz7EUovF4qIbRheJGENzZ7NQocvg=; b=ukK++JiWXUeKWcS2kFG9nVTaLPu7x6pZ3UMq0svLLaS+3FTyrzKqCnndHIFRZxuadi VNpUN4CkKHOAm+bBgDjr455s8OcA3LQuDCoYcoWo4m959nfn2za9EibFgNf5bCWUFgNs mP6X3Ft3KI8UdhrKi6wZFJW/WIpqezbx6PUyZVqLIpOlawoos9y/p3b40KMvZ0vV5kJd 7raxRDa7mndvET+r18p+wv2GKO+g0ko6qZfR8gTrtGa6CJEhTm5InASv4i4xHM/87ZkV W779FZo7pHH/lDGZBe3ONgxvyKD9DbcxG26BJdoWrxqqdMj+UVoQMI9MNhMzXZ/8IjaM uZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cZBBDJ1FYBuLzTfmz7EUovF4qIbRheJGENzZ7NQocvg=; b=cdcAAilGUy+/urAQfp/lRRuytB0JuLV3f+LO22ucFse8+Yx8Utu1x31pZC/q3ZB6R5 r12/xs9Xfh1VGAY4FNGwJV9A/vsKSS6xV9kXqysHyeTZuWz7ef6jv8Y2kaTcU02jT6Yg EecRHD7vPaIUbGHfyedTTRo/waTEYPdG0kNwpmyB/Cm3ritFvW7MROVEZ/6+X+1k32JI M/xGi+/cj6OoorLZT1A+TudA2mXZA0r+UFu4N4J79nHZVYuR8heRLSN+dXIhZbUwIzAK w+uapI4nl9OPDlcfbT5rPOHg39bRhWWIpdXpH7PPc1ZsRqS1kpRVCDYNvD0xq9XF1oIf wzqg== X-Gm-Message-State: AOAM530xJ1dfXksyRb3IK+YHnqZn0b2JMqQLTGqFqgx/9mefXytduVjb I549omMSYfLJjYFw8uv2BaU= X-Google-Smtp-Source: ABdhPJxZ+DjF+mjHOyt66qKD6psO9+8MEQ9Ru6wJZz8I1fGYNb2USAhzAjmAHky8vbU7LvVpzoVluQ== X-Received: by 2002:a17:907:76ed:: with SMTP id kg13mr5581385ejc.99.1616178486624; Fri, 19 Mar 2021 11:28:06 -0700 (PDT) Received: from localhost.localdomain ([188.24.140.160]) by smtp.gmail.com with ESMTPSA id gb22sm3951070ejc.78.2021.03.19.11.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 11:28:06 -0700 (PDT) From: Cristian Ciocaltea To: Rob Herring , =?utf-8?q?Andreas_F=C3=A4rber?= , Manivannan Sadhasivam Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-actions@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] soc: actions: Add Actions Semi Owl socinfo driver Date: Fri, 19 Mar 2021 20:28:00 +0200 Message-Id: <76e07f19e60c037a6ff24a34f5704809cdbfd368.1616178258.git.cristian.ciocaltea@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_182807_305089_5C325F2A X-CRM114-Status: GOOD ( 20.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver provides information about the Action Semi Owl family of SoCs (S500, S700 and S900) to user space via sysfs: machine, family, soc_id, serial_number. Note the serial number is currently provided only for the S500 SoC variant. Signed-off-by: Cristian Ciocaltea --- drivers/soc/actions/Kconfig | 8 ++ drivers/soc/actions/Makefile | 1 + drivers/soc/actions/owl-socinfo.c | 133 ++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 drivers/soc/actions/owl-socinfo.c diff --git a/drivers/soc/actions/Kconfig b/drivers/soc/actions/Kconfig index 1aca2058a40c..15faade9282d 100644 --- a/drivers/soc/actions/Kconfig +++ b/drivers/soc/actions/Kconfig @@ -14,4 +14,12 @@ config OWL_PM_DOMAINS power-gating on Actions Semiconductor S500, S700 and S900 SoCs. If unsure, say 'n'. +config OWL_SOCINFO + bool "Actions Semi Owl SoC info driver" + default ARCH_ACTIONS + select SOC_BUS + help + Say 'y' here to support the Action Semiconductor Owl socinfo + driver, providing information about the SoC to user space. + endif diff --git a/drivers/soc/actions/Makefile b/drivers/soc/actions/Makefile index 4db9e7b050e5..4b2591d3089f 100644 --- a/drivers/soc/actions/Makefile +++ b/drivers/soc/actions/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_OWL_PM_DOMAINS_HELPER) += owl-sps-helper.o obj-$(CONFIG_OWL_PM_DOMAINS) += owl-sps.o +obj-$(CONFIG_OWL_SOCINFO) += owl-socinfo.o diff --git a/drivers/soc/actions/owl-socinfo.c b/drivers/soc/actions/owl-socinfo.c new file mode 100644 index 000000000000..2786c4fd261c --- /dev/null +++ b/drivers/soc/actions/owl-socinfo.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Actions Semi Owl SoC information driver + * + * Copyright (c) 2021 Cristian Ciocaltea + */ + +#include +#include +#include +#include +#include + +#include + +struct owl_soc_info { + char *name; + int (*get_system_serial)(struct device *dev); +}; + +static int __init owl_read_sn_from_mem(struct device *dev) +{ + int paddrs[2] = {0}; + char *vaddr; + int ret; + + ret = device_property_read_u32_array(dev, + "actions,serial-number-addrs", + paddrs, 2); + if (ret) { + dev_err(dev, "failed to read SoC S/N addresses: %d\n", ret); + return ret; + } + + if (PHYS_PFN(paddrs[0]) != PHYS_PFN(paddrs[1])) { + dev_err(dev, "invalid SoC S/N addresses\n"); + return -EINVAL; + } + + vaddr = kmap_local_pfn(PHYS_PFN(paddrs[0])); + + memcpy(&system_serial_low, vaddr + (paddrs[0] & (PAGE_SIZE - 1)), + sizeof(system_serial_low)); + memcpy(&system_serial_high, vaddr + (paddrs[1] & (PAGE_SIZE - 1)), + sizeof(system_serial_high)); + + kunmap_local(vaddr); + + return 0; +} + +static int owl_socinfo_probe(struct platform_device *pdev) +{ + const struct owl_soc_info *soc_info; + struct soc_device_attribute *soc_dev_attr; + struct soc_device *soc_dev; + int ret; + + soc_info = of_device_get_match_data(&pdev->dev); + if (!soc_info) + return -ENODEV; + + soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), + GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine); + if (ret) + return ret; + + soc_dev_attr->family = "Actions Semi Owl"; + soc_dev_attr->soc_id = soc_info->name; + + if (soc_info->get_system_serial) { + ret = soc_info->get_system_serial(&pdev->dev); + if (!ret) { + soc_dev_attr->serial_number = devm_kasprintf(&pdev->dev, + GFP_KERNEL, "%08x%08x", + system_serial_high, + system_serial_low); + /* Feed the SoC unique data into entropy pool. */ + add_device_randomness(soc_dev_attr->serial_number, 16); + } + } + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) + return dev_err_probe(&pdev->dev, PTR_ERR(soc_dev), + "failed to register soc device"); + + dev_info(soc_device_to_device(soc_dev), + "SoC: %s %s\n", + soc_dev_attr->family, soc_dev_attr->soc_id); + + return 0; +} + +static const struct owl_soc_info s500_soc_info = { + .name = "S500", + .get_system_serial = owl_read_sn_from_mem, +}; + +static const struct owl_soc_info s700_soc_info = { + .name = "S700", + /* FIXME: provide get_system_serial */ +}; + +static const struct owl_soc_info s900_soc_info = { + .name = "S900", + /* FIXME: provide get_system_serial */ +}; + +static const struct of_device_id owl_soc_of_match[] = { + { .compatible = "actions,s500-soc", .data = &s500_soc_info, }, + { .compatible = "actions,s700-soc", .data = &s700_soc_info, }, + { .compatible = "actions,s900-soc", .data = &s900_soc_info, }, + { } +}; + +static struct platform_driver owl_socinfo_platform_driver = { + .probe = owl_socinfo_probe, + .driver = { + .name = "owl-socinfo", + .of_match_table = owl_soc_of_match, + }, +}; + +static int __init owl_socinfo_init(void) +{ + return platform_driver_register(&owl_socinfo_platform_driver); +} +subsys_initcall(owl_socinfo_init);