From patchwork Tue Jun 21 10:02:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9190117 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 61D3C601C0 for ; Tue, 21 Jun 2016 10:04:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FEB427FAD for ; Tue, 21 Jun 2016 10:04:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 443772807B; Tue, 21 Jun 2016 10:04:19 +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 EB4BD27FAD for ; Tue, 21 Jun 2016 10:04:17 +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 1bFIXX-0002jn-KW; Tue, 21 Jun 2016 10:04:15 +0000 Received: from mail-lb0-x22f.google.com ([2a00:1450:4010:c04::22f]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFIWr-0001zR-UI for linux-amlogic@lists.infradead.org; Tue, 21 Jun 2016 10:03:36 +0000 Received: by mail-lb0-x22f.google.com with SMTP id xp5so7390204lbb.0 for ; Tue, 21 Jun 2016 03:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QJIOMUJiJSBCNg9FtpJq6eER6+REi0ZA6FdpgFKGlZ8=; b=a2Uxt6xJGZaKLnCV8ynEM0G/rJviAJJdDa9hEe9xV/mkuHswevROs4QzGQj9HsEpXm fVjXADFz/HwTrqHmuoLS0zWgVQWVLPT8l3UvOueZuWjmrqqk0vatwK3pD05ZWfurxdU4 zg/rm4e8g9o9VKaYNY4wQtFGFOF32ZnZd2P5cUMStSAgUkW/rN4jbEMBAGa4GV1JYuIy 1KXnagmy/bobRVHEnNq8cqZc0bYyu0I4HbVFG+BHLefSz2oGsvo1lpiSAARU8QQolPJ0 PNFvVXJdyqVQ7cvalN97AhxKaoTNVTZ0lBu5awYSEYH0eHZjHlUilab87ubUJ12x98lk 44Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QJIOMUJiJSBCNg9FtpJq6eER6+REi0ZA6FdpgFKGlZ8=; b=CdxcZ1hTYxhkI6gOEbbljjZQkPt98Wj8ogKaS+rxKOyBqyXBTSadK//qgtmThWXI73 ChgLHZH/IRfTO1MzgHIk+1J+r+C+hRiB+KY2uGYjaazCwx6MWezuAKmyZeRSbLYEwfhz KdQ5RlQ/B89ZIaF2sOJxmkunbs5ENvsc1UrTh6oG22SToR9nB58GSMmU2kLFayIv0Tck ngwsnSzySE3dxgkAUf+uu7S9VBjlUVKfYqcJq17QNM44FMG177qcUjMeh8ohnYL5P5d8 ORHuqxVcaSgzYH2eGlyVFFKMKtxaP3fVjkPNalQVu4nLUj2AQx+tFJMfX2IKITW8Q0I1 xHIQ== X-Gm-Message-State: ALyK8tIc/BsN2z7QGBTRF6Ogm1tKgcAO6mMhNOxPGiLx2HO5MYhkCU8kRQg0Xm+4FfA4kcfE X-Received: by 10.194.15.69 with SMTP id v5mr11245771wjc.108.1466503391995; Tue, 21 Jun 2016 03:03:11 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id q69sm2184821wmd.4.2016.06.21.03.03.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jun 2016 03:03:11 -0700 (PDT) From: Neil Armstrong To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sudeep.holla@arm.com Subject: [RFC PATCH v2 4/9] firmware: Add a SCPI registry to handle multiple implementations Date: Tue, 21 Jun 2016 12:02:49 +0200 Message-Id: <1466503374-28841-5-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466503374-28841-1-git-send-email-narmstrong@baylibre.com> References: <1466503374-28841-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160621_030334_607791_E1E00B7F X-CRM114-Status: GOOD ( 18.75 ) 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: heiko@sntech.de, Neil Armstrong , frank.wang@rock-chips.com, khilman@baylibre.com, linux-amlogic@lists.infradead.org, wxt@rock-chips.com 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 Add a thin registry layer to store the current scpi_ops pointer out of the arm_scpi.c location. Add a register/unregister and devres managed unregister calls, and their static inline disabled stubs. Add the SCPI_FW config to enable the registry layer build. Signed-off-by: Neil Armstrong --- drivers/firmware/Kconfig | 4 ++ drivers/firmware/Makefile | 1 + drivers/firmware/scpi.c | 94 +++++++++++++++++++++++++++++++++++++++++++ include/linux/scpi_protocol.h | 15 ++++++- 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/scpi.c diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 6664f11..95b01f4 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -8,9 +8,13 @@ menu "Firmware Drivers" config ARM_PSCI_FW bool +config SCPI_FW + bool + config ARM_SCPI_PROTOCOL tristate "ARM System Control and Power Interface (SCPI) Message Protocol" depends on ARM_MHU + select SCPI_FW help System Control and Power Interface (SCPI) Message Protocol is defined for the purpose of communication between the Application diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 474bada..b697462 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -2,6 +2,7 @@ # Makefile for the linux kernel. # obj-$(CONFIG_ARM_PSCI_FW) += psci.o +obj-$(CONFIG_SCPI_FW) += scpi.o obj-$(CONFIG_ARM_SCPI_PROTOCOL) += arm_scpi.o obj-$(CONFIG_DMI) += dmi_scan.o obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o diff --git a/drivers/firmware/scpi.c b/drivers/firmware/scpi.c new file mode 100644 index 0000000..87a559a --- /dev/null +++ b/drivers/firmware/scpi.c @@ -0,0 +1,94 @@ +/* + * System Control and Power Interface (SCPI) Message Protocol registry + * + * SCPI Message Protocol is used between the System Control Processor(SCP) + * and the Application Processors(AP). The Message Handling Unit(MHU) + * provides a mechanism for inter-processor communication between SCP's + * Cortex M3 and AP. + * + * SCP offers control and management of the core/cluster power states, + * various power domain DVFS including the core/cluster, certain system + * clocks configuration, thermal sensors and many others. + * + * Copyright (C) 2015 ARM Ltd. + * Copyright (C) 2016 BayLibre, SAS. + * Author: Neil Armstrong + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct scpi_ops *g_ops; + +struct scpi_ops *get_scpi_ops(void) +{ + return g_ops; +} +EXPORT_SYMBOL_GPL(get_scpi_ops); + +int scpi_ops_register(struct scpi_ops *ops) +{ + if (!ops) + return -EINVAL; + + if (g_ops) + return -EEXIST; + + g_ops = ops; + + return 0; +} +EXPORT_SYMBOL_GPL(scpi_ops_register); + +void scpi_ops_unregister(struct scpi_ops *ops) +{ + if (g_ops == ops) + g_ops = NULL; +} +EXPORT_SYMBOL_GPL(scpi_ops_unregister); + +static void devm_scpi_ops_unregister(struct device *dev, void *res) +{ + scpi_ops_unregister(*(struct scpi_ops **)res); +} + +int devm_scpi_ops_register(struct device *dev, + struct scpi_ops *ops) +{ + struct scpi_ops **rcops; + int ret; + + rcops = devres_alloc(devm_scpi_ops_unregister, sizeof(*ops), + GFP_KERNEL); + if (!rcops) + return -ENOMEM; + + ret = scpi_ops_register(ops); + if (!ret) { + *rcops = ops; + devres_add(dev, rcops); + } else + devres_free(rcops); + + return ret; +} +EXPORT_SYMBOL_GPL(devm_scpi_ops_register); diff --git a/include/linux/scpi_protocol.h b/include/linux/scpi_protocol.h index 35de50a..38c15d1 100644 --- a/include/linux/scpi_protocol.h +++ b/include/linux/scpi_protocol.h @@ -72,8 +72,21 @@ struct scpi_ops { int (*sensor_get_value)(u16, u64 *); }; -#if IS_REACHABLE(CONFIG_ARM_SCPI_PROTOCOL) +#if IS_REACHABLE(CONFIG_SCPI_FW) struct scpi_ops *get_scpi_ops(void); +int scpi_ops_register(struct scpi_ops *drv); +void scpi_ops_unregister(struct scpi_ops *drv); +int devm_scpi_ops_register(struct device *dev, struct scpi_ops *drv); #else static inline struct scpi_ops *get_scpi_ops(void) { return NULL; } + +static inline int scpi_ops_register(struct scpi_ops *drv) { return -ENOTSUPP; } + +static inline void scpi_ops_unregister(struct scpi_ops *drv) { } + +static inline int devm_scpi_ops_register(struct device *dev, + struct scpi_ops *drv) +{ + return -ENOTSUPP; +} #endif