From: narmstrong@baylibre.com (Neil Armstrong)
To: linus-amlogic@lists.infradead.org
Subject: [RFC PATCH v2 4/9] firmware: Add a SCPI registry to handle multiple implementations
Date: Tue, 21 Jun 2016 12:02:49 +0200 [thread overview]
Message-ID: <1466503374-28841-5-git-send-email-narmstrong@baylibre.com> (raw)
In-Reply-To: <1466503374-28841-1-git-send-email-narmstrong@baylibre.com>
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 <narmstrong@baylibre.com>
---
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 <narmstrong@baylibre.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/of.h>
+#include <linux/scpi_protocol.h>
+#include <linux/spinlock.h>
+
+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
--
2.7.0
next prev parent reply other threads:[~2016-06-21 10:02 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-21 10:02 [RFC PATCH v2 0/9] scpi: Add SCPI registry to handle legacy protocol Neil Armstrong
2016-06-21 10:02 ` [RFC PATCH v2 1/9] mailbox: Add Amlogic Meson Message-Handling-Unit Neil Armstrong
2016-06-22 4:31 ` Jassi Brar
2016-06-23 12:50 ` Neil Armstrong
2016-06-23 15:46 ` Neil Armstrong
2016-06-25 17:50 ` Jassi Brar
2016-06-28 14:00 ` Neil Armstrong
2016-06-28 15:06 ` Jassi Brar
2016-07-04 15:25 ` Jassi Brar
2016-07-04 15:38 ` Jassi Brar
2016-07-06 13:17 ` Neil Armstrong
2016-07-07 4:27 ` Jassi Brar
2016-06-21 10:02 ` [RFC PATCH v2 2/9] dt-bindings: mailbox: Add Amlogic Meson MHU Bindings Neil Armstrong
2016-06-21 10:02 ` [RFC PATCH v2 3/9] ARM64: dts: meson-gxbb: Add Meson MHU Node Neil Armstrong
2016-06-21 10:02 ` Neil Armstrong [this message]
2016-06-21 10:02 ` [RFC PATCH v2 5/9] firmware: scpi: Switch arm_scpi to use new registry Neil Armstrong
2016-06-21 10:02 ` [RFC PATCH v2 6/9] firmware: Add legacy SCPI protocol driver Neil Armstrong
2016-06-30 10:53 ` Sudeep Holla
2016-07-19 9:17 ` Neil Armstrong
2016-06-21 10:02 ` [RFC PATCH v2 7/9] dt-bindings: arm: Update arm, scpi bindings with Meson GXBB SCPI Neil Armstrong
2016-06-21 10:02 ` [RFC PATCH v2 8/9] ARM64: dts: meson-gxbb: Add SRAM node Neil Armstrong
2016-06-21 10:02 ` [RFC PATCH v2 9/9] ARM64: dts: meson-gxbb: Add SCPI with cpufreq & sensors Nodes Neil Armstrong
2016-06-22 2:54 ` [RFC PATCH v2 0/9] scpi: Add SCPI registry to handle legacy protocol Frank Wang
2016-06-23 12:45 ` Neil Armstrong
2016-06-24 2:31 ` Frank Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466503374-28841-5-git-send-email-narmstrong@baylibre.com \
--to=narmstrong@baylibre.com \
--cc=linus-amlogic@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®