From patchwork Tue Aug 9 10:29:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9270805 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 27D7260871 for ; Tue, 9 Aug 2016 10:30:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 132DE27F80 for ; Tue, 9 Aug 2016 10:30:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0793E27F9C; Tue, 9 Aug 2016 10:30:40 +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 6D69227F80 for ; Tue, 9 Aug 2016 10:30:39 +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 1bX4Iq-0006MQ-Ql; Tue, 09 Aug 2016 10:30:32 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bX4II-0004yB-1g for linux-amlogic@lists.infradead.org; Tue, 09 Aug 2016 10:30:02 +0000 Received: by mail-wm0-x22b.google.com with SMTP id i5so24969986wmg.0 for ; Tue, 09 Aug 2016 03:29:37 -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=PgwJbAR3gPeQXNvSLv88iCxbk3JZCznirPL7mSg0CEc=; b=FGk1NM14emZl2KZtSjjVxfxG6xG3DxaKv0TBzlOFY7O4lWfW0nez7EcYhUG2snBGXu n47c97A5WTP9zTYnoTdoQ2bcSQw6YgBRwRMOxx6z/8bdgNoP1Sauype0dDGZQSkjw8zw Zk8SSSpZf4v60MAiS4EBw0dj8UQZEC2SCnWL3ACGW+s8+ZK8DsYI4mfkxZxBAI/w2a7N hi8gmMo+KfN1l5JLqGF1LpBpeq1+HzKlEGSbYukOHnkzqE/hJCzM0tO/tjP6CaHzeayl 5g2+0ErOGuPtOgqK62/T/rCJWBnlwWz/lHmjfZGqJeKQnoM3EC/H5Hz6ZzsiG7SHn628 QMoA== 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=PgwJbAR3gPeQXNvSLv88iCxbk3JZCznirPL7mSg0CEc=; b=mv723hilbig/wQ3ppYoW8eTCGfsRbufkZbC5zBpZkYFEI9RYS+l5EhgoaiLkuL7/gJ TWenJspsz5RrsjNfkKTDIn0/VFBgjjgg6PnL9noxq0hH34TtM6+w/EFUqGyoG16A4Axf eLQi1RwJAvxioO4JNDhojcwbfRTa2C8cKNeQYqTc6MagH/MT8v4GxeDzmUu+QYVSkUON dgCWCDuUw1SaJHuonRxJSRhiCYHHyhG/Xq7taklJssqI9C1sfsDd1GANxQGqiyim3dur /wzoa1VZyPDGoTIdcmui7bXGrD+8bcejv4CZrWuklj3PPN+L+VFLWowR9ipdedzA8zrV vCug== X-Gm-Message-State: AEkooutJoBxJ/oT3/a8xejMPIHJYAmMPMpFN/2zDN/BuzlWg7jPwFe1vywQW2/i5fu/7mrh6 X-Received: by 10.194.106.200 with SMTP id gw8mr13473991wjb.147.1470738576261; Tue, 09 Aug 2016 03:29:36 -0700 (PDT) Received: from zoidberg.home (LFbn-1-1885-126.w90-73.abo.wanadoo.fr. [90.73.182.126]) by smtp.gmail.com with ESMTPSA id c139sm2624994wme.4.2016.08.09.03.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Aug 2016 03:29:35 -0700 (PDT) From: Neil Armstrong To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sudeep.holla@arm.com Subject: [RFC PATCH v3 1/8] firmware: Add a SCPI registry to handle multiple implementations Date: Tue, 9 Aug 2016 12:29:15 +0200 Message-Id: <1470738562-20026-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470738562-20026-1-git-send-email-narmstrong@baylibre.com> References: <1470738562-20026-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160809_032958_429720_6B8B7321 X-CRM114-Status: GOOD ( 18.55 ) 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 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 0e22f24..ff85511 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 MAILBOX + 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 44a59dc..968197f 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_ARM_SCPI_POWER_DOMAIN) += scpi_pm_domain.o obj-$(CONFIG_DMI) += dmi_scan.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 dc5f989..8e21e3a 100644 --- a/include/linux/scpi_protocol.h +++ b/include/linux/scpi_protocol.h @@ -74,8 +74,21 @@ struct scpi_ops { int (*device_set_power_state)(u16, u8); }; -#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