Skip to contentSkip to conversation

Add support for the System Power Management Interface (SPMI)

RFC PATCH Superseded Josh Cartwright 5 participants 18 messages Dec 10, 2012 – Oct 7, 2013

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for the System Power Management Interface (SPMI)

The System Power Management Interface (SPMI) is a high-speed, low-latency, bi-directional, two-wire serial bus suitable for real-time control of voltage and frequency scaled multi-core application processors and its power management of auxiliary components. SPMI obsoletes a number of legacy, custom point-to-point interfaces and provides a low pin count, high-speed control bus for up to 4 Master and 16 Slave devices.

SPMI is specified by the MIPI (Mobile Industry Process Interface) Alliance [1].

Introduced in this patchset are the core SPMI bus components, as well an implementation of an SPMI controller, the "PMIC arbiter", which is used on the Qualcomm Snapdragon 800 series of SoCs to communicate with off-chip Power Management ICs (PMICs). Notably missing from this patchset is an implementation of an SPMI device/slave driver, which is still forthcoming. With this patchset in it's current state, it is possible to perform register accesses to a slave via debugfs.

Changes from v1[2]:
- Adopted patch (1/5) to #define for_each_available_node() shim in the !CONFIG_OF case
- Moved device tree logic out of drivers/of and into spmi.c core (this mirrors what SPI is doing, and what i2c will soon be doing)
- Move of_spmi_add_devices() call into spmi_device_add(), so drivers don't have to call it explicitly
- Unconditionally build in debugfs code (rely on the underlying CONFIG_DEBUG_FS switch to throw unused code away)
- Change pr_* print functions to their dev_* equivalents
- Fix copy_{to,from}_user error handling
- Renamed "board_lock" to "ctrl_idr_lock" to better describe it's purpose
- Rework device object lifetime management
- Rename PMIC arb binding document, add description of PMIC arb
- Add generic SPMI device tree bindings

[1]: http://www.mipi.org/specifications/system-power-management-interface
[2]: http://thread.gmane.org/gmane.linux.ports.arm.msm/4886

Josh Cartwright (2):
spmi: add generic SPMI controller binding documentation
spmi: document the PMIC arbiter SPMI bindings

Kenneth Heitke (2):
spmi: Linux driver framework for SPMI
spmi: Add MSM PMIC Arbiter SPMI controller

Sylwester Nawrocki (1):
of: Add empty for_each_available_child_of_node() macro definition

 .../bindings/spmi/qcom,spmi-pmic-arb.txt           |  36 ++
 Documentation/devicetree/bindings/spmi/spmi.txt    |  36 ++
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/spmi/Kconfig                               |  24 +
 drivers/spmi/Makefile                              |   6 +
 drivers/spmi/spmi-dbgfs.c                          | 580 +++++++++++++++++++++
 drivers/spmi/spmi-dbgfs.h                          |  25 +
 drivers/spmi/spmi-pmic-arb.c                       | 416 +++++++++++++++
 drivers/spmi/spmi.c                                | 491 +++++++++++++++++
 include/linux/mod_devicetable.h                    |   8 +
 include/linux/of.h                                 |   3 +
 include/linux/spmi.h                               | 355 +++++++++++++
 13 files changed, 1983 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt
 create mode 100644 Documentation/devicetree/bindings/spmi/spmi.txt
 create mode 100644 drivers/spmi/Kconfig
 create mode 100644 drivers/spmi/Makefile
 create mode 100644 drivers/spmi/spmi-dbgfs.c
 create mode 100644 drivers/spmi/spmi-dbgfs.h
 create mode 100644 drivers/spmi/spmi-pmic-arb.c
 create mode 100644 drivers/spmi/spmi.c
 create mode 100644 include/linux/spmi.h
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#1 lore raw

RFC PATCH v2 1/5 of: Add empty for_each_available_child_of_node() macro definition

From: Sylwester Nawrocki <[email protected]>

Add this empty macro definition so users can be compiled without excluding this macro call with preprocessor directives when CONFIG_OF is disabled.

---
This patch was first introduced in December @
http://thread.gmane.org/gmane.linux.drivers.devicetree/26315

 include/linux/of.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/of.h +3 -0
index 1fd08ca..fefffb3 100644
@@ -369,6 +369,9 @@ static inline bool of_have_populated_dt(void)
 #define for_each_child_of_node(parent, child) \
 	while (0)
 
+#define for_each_available_child_of_node(parent, child) \
+	while (0)
+
 static inline struct device_node *of_get_child_by_name(
 					const struct device_node *node,
 					const char *name)
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#2 lore raw

RFC PATCH v2 2/5 spmi: Linux driver framework for SPMI

In reply to Josh Cartwright

From: Kenneth Heitke <[email protected]>

System Power Management Interface (SPMI) is a specification developed by the MIPI (Mobile Industry Process Interface) Alliance optimized for the real time control of Power Management ICs (PMIC).

SPMI is a two-wire serial interface that supports up to 4 master devices and up to 16 logical slaves.

The framework supports message APIs, multiple busses (1 controller per bus) and multiple clients/slave devices per controller.

---
 drivers/Kconfig                 |   2 +
 drivers/Makefile                |   1 +
 drivers/spmi/Kconfig            |   9 +
 drivers/spmi/Makefile           |   4 +
 drivers/spmi/spmi-dbgfs.c       | 580 ++++++++++++++++++++++++++++++++++++++++
 drivers/spmi/spmi-dbgfs.h       |  25 ++
 drivers/spmi/spmi.c             | 491 ++++++++++++++++++++++++++++++++++
 include/linux/mod_devicetable.h |   8 +
 include/linux/spmi.h            | 355 ++++++++++++++++++++++++
 9 files changed, 1475 insertions(+)
 create mode 100644 drivers/spmi/Kconfig
 create mode 100644 drivers/spmi/Makefile
 create mode 100644 drivers/spmi/spmi-dbgfs.c
 create mode 100644 drivers/spmi/spmi-dbgfs.h
 create mode 100644 drivers/spmi/spmi.c
 create mode 100644 include/linux/spmi.h
drivers/Kconfig +2 -0
index aa43b91..2b35420 100644
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig"
 
 source "drivers/spi/Kconfig"
 
+source "drivers/spmi/Kconfig"
+
 source "drivers/hsi/Kconfig"
 
 source "drivers/pps/Kconfig"
drivers/Makefile +1 -0
index ab93de8..5c250df 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_ATA)		+= ata/
 obj-$(CONFIG_TARGET_CORE)	+= target/
 obj-$(CONFIG_MTD)		+= mtd/
 obj-$(CONFIG_SPI)		+= spi/
+obj-$(CONFIG_SPMI)		+= spmi/
 obj-y				+= hsi/
 obj-y				+= net/
 obj-$(CONFIG_ATM)		+= atm/
drivers/spmi/Kconfig new file +9 -0
new file mode 100644
index 0000000..a03835f
@@ -0,0 +1,9 @@
+#
+# SPMI driver configuration
+#
+menuconfig SPMI
+	bool "SPMI support"
+	help
+	  SPMI (System Power Management Interface) is a two-wire
+	  serial interface between baseband and application processors
+	  and Power Management Integrated Circuits (PMIC).
drivers/spmi/Makefile new file +4 -0
new file mode 100644
index 0000000..9d78ec9
@@ -0,0 +1,4 @@
+#
+# Makefile for kernel SPMI framework.
+#
+obj-$(CONFIG_SPMI)	+= spmi.o spmi-dbgfs.o
drivers/spmi/spmi-dbgfs.c new file +580 -0

580 lines not on this page · raw message

drivers/spmi/spmi-dbgfs.h new file +25 -0
new file mode 100644
index 0000000..d3162fb
@@ -0,0 +1,25 @@
+/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ */
+#ifndef _SPMI_DBGFS_H
+#define _SPMI_DBGFS_H
+
+struct spmi_controller;
+struct spmi_device;
+
+void __init spmi_dfs_init(void);
+void __exit spmi_dfs_exit(void);
+void spmi_dfs_controller_add(struct spmi_controller *ctrl);
+void spmi_dfs_controller_remove(struct spmi_controller *ctrl);
+void spmi_dfs_device_add(struct spmi_device *sdev);
+void spmi_dfs_device_remove(struct spmi_device *sdev);
+
+#endif /* _SPMI_DBGFS_H */
drivers/spmi/spmi.c new file +491 -0

491 lines not on this page · raw message

include/linux/mod_devicetable.h +8 -0
index 45e9214..677e474 100644
@@ -432,6 +432,14 @@ struct spi_device_id {
 	kernel_ulong_t driver_data;	/* Data private to the driver */
 };
 
+#define SPMI_NAME_SIZE	32
+#define SPMI_MODULE_PREFIX "spmi:"
+
+struct spmi_device_id {
+	char name[SPMI_NAME_SIZE];
+	kernel_ulong_t driver_data;	/* Data private to the driver */
+};
+
 /* dmi */
 enum dmi_field {
 	DMI_NONE,
include/linux/spmi.h new file +355 -0

355 lines not on this page · raw message

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#3 lore raw

Re: [PATCH RFC v2 2/5] spmi: Linux driver framework for SPMI

Quoted 34 lines · Josh Cartwright
drivers/spmi/spmi-dbgfs.c new file +34 -0
+static char dbgfs_help[] =
+	"SPMI Debug-FS support\n"
+	"\n"
+	"Hierarchy schema:\n"
+	"/sys/kernel/debug/spmi\n"
+	"       /help                -- Static help text\n"
+	"       /spmi-0              -- Directory for SPMI bus 0\n"
+	"       /spmi-0/0-1          -- Directory for SPMI device '0-1'\n"
+	"       /spmi-0/0-1/address  -- Starting register for reads or writes\n"
+	"       /spmi-0/0-1/count    -- Number of registers to read (only used for reads)\n"
+	"       /spmi-0/0-1/data     -- Initiates the SPMI read (formatted output)\n"
+	"       /spmi-0/0-1/data_raw -- Initiates the SPMI raw read or write\n"
+	"       /spmi-n              -- Directory for SPMI bus n\n"
+	"\n"
+	"To perform SPMI read or write transactions, you need to first write the\n"
+	"address of the slave device register to the 'address' file.  For read\n"
+	"transactions, the number of bytes to be read needs to be written to the\n"
+	"'count' file.\n"
+	"\n"
+	"The 'address' file specifies the 20-bit address of a slave device register.\n"
+	"The upper 4 bits 'address[19..16]' specify the slave identifier (SID) for\n"
+	"the slave device.  The lower 16 bits specify the slave register address.\n"
+	"\n"
+	"Reading from the 'data' file will initiate a SPMI read transaction starting\n"
+	"from slave register 'address' for 'count' number of bytes.\n"
+	"\n"
+	"Writing to the 'data' file will initiate a SPMI write transaction starting\n"
+	"from slave register 'address'.  The number of registers written to will\n"
+	"match the number of bytes written to the 'data' file.\n"
+	"\n"
+	"Example: Read 4 bytes starting at register address 0x1234 for SID 2\n"
+	"\n"
+	"echo 0x21234 > address\n"
+	"echo 4 > count\n"

drivers/spmi/spmi-dbgfs.c line 94

Quoted 10 lines
drivers/spmi/spmi-dbgfs.c new file +10 -0
+	"cat data\n"
+	"\n"
+	"Example: Write 3 bytes starting at register address 0x1008 for SID 1\n"
+	"\n"
+	"echo 0x11008 > address\n"
+	"echo 0x01 0x02 0x03 > data\n"
+	"\n"
+	"Note that the count file is not used for writes.  Since 3 bytes are\n"
+	"written to the 'data' file, then 3 bytes will be written across the\n"
+	"SPMI bus.\n\n";

The help file within the kernel is a nice touch :)

I do know the only rule for debugfs is "There are no rules", but this looks like you are going to have the way to interact to this bus and devices as debugfs, is that correct?

Or is this only for "debugging"? If so, please document it as such.

drivers/spmi/spmi-dbgfs.c line 508

Quoted 5 lines
drivers/spmi/spmi-dbgfs.c new file +5 -0
+void spmi_dfs_controller_add(struct spmi_controller *ctrl)
+{
+	ctrl->dfs_dir = debugfs_create_dir(dev_name(&ctrl->dev),
+					   spmi_debug_root);
+	WARN_ON(!ctrl->dfs_dir);

Why? What is a user going to be able to do with something like this? You do this in a number of places, please provide "valid" error messages instead of just kernel stack tracebacks, failing to show the device for which the error occured (hint, use dev_err()).

Again, never use WARN_ON() as error handling, it's lazy, and wrong.

thanks,

greg k-h

#4 lore raw

Re: [PATCH RFC v2 2/5] spmi: Linux driver framework for SPMI

Quoted 48 lines · Greg Kroah-Hartman
Quoted 34 lines · Josh Cartwright
drivers/spmi/spmi-dbgfs.c new file +34 -0
+static char dbgfs_help[] =
+	"SPMI Debug-FS support\n"
+	"\n"
+	"Hierarchy schema:\n"
+	"/sys/kernel/debug/spmi\n"
+	"       /help                -- Static help text\n"
+	"       /spmi-0              -- Directory for SPMI bus 0\n"
+	"       /spmi-0/0-1          -- Directory for SPMI device '0-1'\n"
+	"       /spmi-0/0-1/address  -- Starting register for reads or writes\n"
+	"       /spmi-0/0-1/count    -- Number of registers to read (only used for reads)\n"
+	"       /spmi-0/0-1/data     -- Initiates the SPMI read (formatted output)\n"
+	"       /spmi-0/0-1/data_raw -- Initiates the SPMI raw read or write\n"
+	"       /spmi-n              -- Directory for SPMI bus n\n"
+	"\n"
+	"To perform SPMI read or write transactions, you need to first write the\n"
+	"address of the slave device register to the 'address' file.  For read\n"
+	"transactions, the number of bytes to be read needs to be written to the\n"
+	"'count' file.\n"
+	"\n"
+	"The 'address' file specifies the 20-bit address of a slave device register.\n"
+	"The upper 4 bits 'address[19..16]' specify the slave identifier (SID) for\n"
+	"the slave device.  The lower 16 bits specify the slave register address.\n"
+	"\n"
+	"Reading from the 'data' file will initiate a SPMI read transaction starting\n"
+	"from slave register 'address' for 'count' number of bytes.\n"
+	"\n"
+	"Writing to the 'data' file will initiate a SPMI write transaction starting\n"
+	"from slave register 'address'.  The number of registers written to will\n"
+	"match the number of bytes written to the 'data' file.\n"
+	"\n"
+	"Example: Read 4 bytes starting at register address 0x1234 for SID 2\n"
+	"\n"
+	"echo 0x21234 > address\n"
+	"echo 4 > count\n"

drivers/spmi/spmi-dbgfs.c line 94

Quoted 10 lines
drivers/spmi/spmi-dbgfs.c new file +10 -0
+	"cat data\n"
+	"\n"
+	"Example: Write 3 bytes starting at register address 0x1008 for SID 1\n"
+	"\n"
+	"echo 0x11008 > address\n"
+	"echo 0x01 0x02 0x03 > data\n"
+	"\n"
+	"Note that the count file is not used for writes.  Since 3 bytes are\n"
+	"written to the 'data' file, then 3 bytes will be written across the\n"
+	"SPMI bus.\n\n";

The help file within the kernel is a nice touch :)

Quoted 3 lines

I do know the only rule for debugfs is "There are no rules", but this looks like you are going to have the way to interact to this bus and devices as debugfs, is that correct?

Using debugfs is _a_ way to interact with the controller/slaves, however it is not _the_ way to do so. The primary interface is the in-kernel spmi_{read,write,...}_* functions called within the context of a proper slave driver.

Quoted 1 line

Or is this only for "debugging"? If so, please document it as such.

It's there because it provides a useful interface for debugging of the controller code, and for simple peek/poke of the slave registers without having a full driver in place. Will document this.

Quoted 10 lines

drivers/spmi/spmi-dbgfs.c line 508

Quoted 5 lines
drivers/spmi/spmi-dbgfs.c new file +5 -0
+void spmi_dfs_controller_add(struct spmi_controller *ctrl)
+{
+	ctrl->dfs_dir = debugfs_create_dir(dev_name(&ctrl->dev),
+					   spmi_debug_root);
+	WARN_ON(!ctrl->dfs_dir);

Why? What is a user going to be able to do with something like this? You do this in a number of places, please provide "valid" error messages instead of just kernel stack tracebacks, failing to show the device for which the error occured (hint, use dev_err()).

Will do. Thanks.

Quoted 1 line

Again, never use WARN_ON() as error handling, it's lazy, and wrong.

To be fair to the original author of this code, this was one of the 'cleanups' I implemented. So, I'll take full responsibility for the laziness. :)

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw

Re: [PATCH RFC v2 2/5] spmi: Linux driver framework for SPMI

Quoted 20 lines · Josh Cartwright
Quoted 18 lines · Greg Kroah-Hartman
Quoted 4 lines · Josh Cartwright
drivers/spmi/spmi-dbgfs.c new file +4 -0
+	"Example: Read 4 bytes starting at register address 0x1234 for SID 2\n"
+	"\n"
+	"echo 0x21234 > address\n"
+	"echo 4 > count\n"

drivers/spmi/spmi-dbgfs.c line 94

Quoted 10 lines
drivers/spmi/spmi-dbgfs.c new file +10 -0
+	"cat data\n"
+	"\n"
+	"Example: Write 3 bytes starting at register address 0x1008 for SID 1\n"
+	"\n"
+	"echo 0x11008 > address\n"
+	"echo 0x01 0x02 0x03 > data\n"
+	"\n"
+	"Note that the count file is not used for writes.  Since 3 bytes are\n"
+	"written to the 'data' file, then 3 bytes will be written across the\n"
+	"SPMI bus.\n\n";

The help file within the kernel is a nice touch :)

Quoted 5 lines
Quoted 1 line

Or is this only for "debugging"? If so, please document it as such.

It's there because it provides a useful interface for debugging of the controller code, and for simple peek/poke of the slave registers without having a full driver in place. Will document this.

This looks awfully like a version of the debugfs interfaces that regmap
provides, and indeed the entire bus sounds like something that could
idiomatically be supported via regmap. Have you considered doing that?
This would give access to standard tracepoints as well, plus the cache
infrastructure.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130909/f9e563f8/attachment-0001.sig>

#6 lore raw

Re: [PATCH RFC v2 2/5] spmi: Linux driver framework for SPMI

Hey Mark-

Thanks for the comments.

Quoted 27 lines · Mark Brown
Quoted 20 lines · Josh Cartwright
Quoted 18 lines · Greg Kroah-Hartman
Quoted 4 lines · Josh Cartwright
drivers/spmi/spmi-dbgfs.c new file +4 -0
+	"Example: Read 4 bytes starting at register address 0x1234 for SID 2\n"
+	"\n"
+	"echo 0x21234 > address\n"
+	"echo 4 > count\n"

drivers/spmi/spmi-dbgfs.c line 94

Quoted 10 lines
drivers/spmi/spmi-dbgfs.c new file +10 -0
+	"cat data\n"
+	"\n"
+	"Example: Write 3 bytes starting at register address 0x1008 for SID 1\n"
+	"\n"
+	"echo 0x11008 > address\n"
+	"echo 0x01 0x02 0x03 > data\n"
+	"\n"
+	"Note that the count file is not used for writes.  Since 3 bytes are\n"
+	"written to the 'data' file, then 3 bytes will be written across the\n"
+	"SPMI bus.\n\n";

The help file within the kernel is a nice touch :)

Quoted 5 lines
Quoted 1 line

Or is this only for "debugging"? If so, please document it as such.

It's there because it provides a useful interface for debugging of the controller code, and for simple peek/poke of the slave registers without having a full driver in place. Will document this.

Quoted 5 lines

This looks awfully like a version of the debugfs interfaces that regmap provides, and indeed the entire bus sounds like something that could idiomatically be supported via regmap. Have you considered doing that? This would give access to standard tracepoints as well, plus the cache infrastructure.

It does indeed look like regmap might work out nicely for SPMI. I hadn't seriously considered it just due to a lack of familiarity. I'll give it a shot and see if I run into any problems.

Thanks,
Josh

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#7 lore raw

RFC PATCH v2 3/5 spmi: add generic SPMI controller binding documentation

In reply to Josh Cartwright

---
I'm introducing this as an RFC, because there are set of assumptions made in this binding spec, that currently hold true for the supported controller/addressing scheme for the Snapdragon 800 series, but don't necessarily hold true for SPMI in general.

1. No use of Group Slave Identifiers (GSIDs)
(SPMI allows for a slave to belong to zero or more groups specified by GSID, however this feature isn't currently implemented)

2. No specification of Master Identifier (MID)
(A "system integrator" allocates to each master a 2-bit MID, this currently isn't being specified, as it isn't needed by software for the PMIC Arb; not sure if this is of use to other SPMI controllers)

3. Single SPMI master per controller

Effectively, only a subset of possible SPMI configurations are specified in this document.

So, if it's considered necessary to provide a generic SPMI binding specification, is it acceptable to only define a subset at this time, expanding only when necessary, or shall I expand the definition to at least address 1 & 2, even though they are of no use in the current implementation?

 Documentation/devicetree/bindings/spmi/spmi.txt | 36 +++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spmi/spmi.txt
Documentation/devicetree/bindings/spmi/spmi.txt new file +36 -0
new file mode 100644
index 0000000..a01b064
@@ -0,0 +1,36 @@
+System Power Management Interface (SPMI) Controller
+
+This document defines a generic set of bindings for use by SPMI controllers.  A
+controller is modelled in device tree as a node with zero or more child nodes,
+each representing a unique slave on the bus.
+
+Required properties:
+- #address-cells : must be set to 1
+- #size-cells : must be set to 0
+
+Child nodes:
+
+An SPMI controller node can contain zero or more children.  Each child must
+have a reg property defining its 4-bit Unique Slave Identifier (USID) on the
+SPMI bus.  This is the ID that has been "statically assigned by the system
+integrator", as per the SPMI spec.
+
+Each child node represents a slave device on the bus.
+
+	controller at .. {
+		compatible = "...";
+		reg = <...>;
+
+		#address-cells = <1>;
+		#size-cells <0>;
+
+		child at 0 {
+			compatible = "...";
+			reg = <0>;
+		};
+
+		child at 7 {
+			compatible = "...";
+			reg = <7>;
+		};
+	};
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#8 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

Quoted 18 lines · Josh Cartwright

---
I'm introducing this as an RFC, because there are set of assumptions made in this binding spec, that currently hold true for the supported controller/addressing scheme for the Snapdragon 800 series, but don't necessarily hold true for SPMI in general.

1. No use of Group Slave Identifiers (GSIDs)
(SPMI allows for a slave to belong to zero or more groups specified by GSID, however this feature isn't currently implemented)

2. No specification of Master Identifier (MID)
(A "system integrator" allocates to each master a 2-bit MID, this currently isn't being specified, as it isn't needed by software for the PMIC Arb; not sure if this is of use to other SPMI controllers)

3. Single SPMI master per controller

Quoted 8 lines

Effectively, only a subset of possible SPMI configurations are specified in this document.

So, if it's considered necessary to provide a generic SPMI binding specification, is it acceptable to only define a subset at this time, expanding only when necessary, or shall I expand the definition to at least address 1 & 2, even though they are of no use in the current implementation?

It's best to define the whole thing from the start if possible. It's easier to ensure the whole binding is consistent, and nothing has been left out.

However, it's probably OK to define a subset binding initially and then expand it later, as long as some thought it put into how it can be expanded in a way that is 100% compatible: old DTs will still operate with new kernels and perhaps even new DTs will still operate with old kernels.

That said, if the thought is put in to ensure that's possible, it's probably just as easy to define the whole binding from the start.

#9 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

Hey Stephen-

Thanks for the comments.

Quoted 28 lines · Stephen Warren
Quoted 18 lines · Josh Cartwright

---
I'm introducing this as an RFC, because there are set of assumptions made in this binding spec, that currently hold true for the supported controller/addressing scheme for the Snapdragon 800 series, but don't necessarily hold true for SPMI in general.

1. No use of Group Slave Identifiers (GSIDs)
(SPMI allows for a slave to belong to zero or more groups specified by GSID, however this feature isn't currently implemented)

2. No specification of Master Identifier (MID)
(A "system integrator" allocates to each master a 2-bit MID, this currently isn't being specified, as it isn't needed by software for the PMIC Arb; not sure if this is of use to other SPMI controllers)

3. Single SPMI master per controller

Quoted 8 lines

Effectively, only a subset of possible SPMI configurations are specified in this document.

So, if it's considered necessary to provide a generic SPMI binding specification, is it acceptable to only define a subset at this time, expanding only when necessary, or shall I expand the definition to at least address 1 & 2, even though they are of no use in the current implementation?

Quoted 3 lines

It's best to define the whole thing from the start if possible. It's easier to ensure the whole binding is consistent, and nothing has been left out.

That makes sense. I think I'll go down this route for v3 of this patchset:

For #1 above, extend the 'reg' property of a slave node to include the group slave ID's in which the slave is a member. The first 'reg' entry will remain the slave's Unique Slave Identifier (USID) as before.

For #2, add additional required 'spmi-mid' property in the controller/master node that describes the 2-bit Master Identifier (MID).

For #3, rename the SPMI API's s/controller/master/. The current controller/master terminology difference is confusing and unnecessary.

Quoted 8 lines

However, it's probably OK to define a subset binding initially and then expand it later, as long as some thought it put into how it can be expanded in a way that is 100% compatible: old DTs will still operate with new kernels and perhaps even new DTs will still operate with old kernels.

That said, if the thought is put in to ensure that's possible, it's probably just as easy to define the whole binding from the start.

That all makes sense.

If we want to ensure for the generic bindings that we are fulling characterizing/describing the SPMI bus, then we'll additionally need to tackle an additional identified assumption:

4. One master per SPMI bus. (The SPMI spec allows for up to 4 masters)

On the Snapdragon 800 series, there exists only one software-controlled master, but it is conceivably possible to have a setup with two software-controlled masters on the same SPMI bus.

This necessarily means that the description of the slaves and the masters will need to be decoupled; I'm imagining a generic binding supporting multiple masters would look something like this:

	master0: master at 0 {
		compatible = "...";
		#spmi-master-cells = <0>;
		spmi-mid = <0>;

		...
	};

	master2: master at 2 {
		compatible = "...";
		#spmi-master-cells = <0>;
		spmi-mid = <2>;

		...
	};

	spmi_bus {
		compatible = "...";

		spmi-masters = <&master0 &master2>;

		foo at 0 {
			compatible = "...";
			reg = <0 ...>;
		};

		foo at 8 {
			compatible = "...";
			reg = <8 ...>;
		};
	};

(This will also necessitate a change in the underlying SPMI driver model, in the current implementation, a SPMI master 'owns' a particular device. This is not a valid assumption to make.)

Would this property-containing-phandle-vector be considered the canonical way of representing nodes with multiple parents in the device tree?

Thanks,
Josh

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#10 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

On 08/27/2013 11:01 AM, Josh Cartwright wrote:
...

Quoted 7 lines

If we want to ensure for the generic bindings that we are fulling characterizing/describing the SPMI bus, then we'll additionally need to tackle an additional identified assumption:

4. One master per SPMI bus. (The SPMI spec allows for up to 4 masters)

Quoted 7 lines

On the Snapdragon 800 series, there exists only one software-controlled master, but it is conceivably possible to have a setup with two software-controlled masters on the same SPMI bus.

This necessarily means that the description of the slaves and the masters will need to be decoupled; I'm imagining a generic binding supporting multiple masters would look something like this:

Is there a need to represent the other masters in the DT? Sure they're there in HW, but if there's no specific way for the CPU-to-which-the-DT-applies to actually interact with those other masters (except perhaps by experiencing some arbitration delays) then presumably there's no need to represent the other masters in DT?

Quoted 32 lines
	master0: master at 0 {
		compatible = "...";
		#spmi-master-cells = <0>;
		spmi-mid = <0>;

		...
	};

	master2: master at 2 {
		compatible = "...";
		#spmi-master-cells = <0>;
		spmi-mid = <2>;

		...
	};

	spmi_bus {
		compatible = "...";

		spmi-masters = <&master0 &master2>;

		foo at 0 {
			compatible = "...";
			reg = <0 ...>;
		};

		foo at 8 {
			compatible = "...";
			reg = <8 ...>;
		};
	};
Quoted 7 lines

(This will also necessitate a change in the underlying SPMI driver model, in the current implementation, a SPMI master 'owns' a particular device. This is not a valid assumption to make.)

Would this property-containing-phandle-vector be considered the canonical way of representing nodes with multiple parents in the device tree?

I don't think I've seen anything like this before, although that in-and-of-itself doesn't make it wrong.

Another approach might be to encode master-vs-slave into a cell in the reg property? Something like:

cell 0 - address type (0: master, 1: unique ID, 2: group ID, ...) cell 1 - address value

I haven't thought much about that; perhaps there are disadvantages doing that.

#11 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

Quoted 17 lines · Stephen Warren

On 08/27/2013 11:01 AM, Josh Cartwright wrote:
...

Quoted 7 lines

If we want to ensure for the generic bindings that we are fulling characterizing/describing the SPMI bus, then we'll additionally need to tackle an additional identified assumption:

4. One master per SPMI bus. (The SPMI spec allows for up to 4 masters)

Quoted 7 lines

On the Snapdragon 800 series, there exists only one software-controlled master, but it is conceivably possible to have a setup with two software-controlled masters on the same SPMI bus.

This necessarily means that the description of the slaves and the masters will need to be decoupled; I'm imagining a generic binding supporting multiple masters would look something like this:

Quoted 5 lines

Is there a need to represent the other masters in the DT? Sure they're there in HW, but if there's no specific way for the CPU-to-which-the-DT-applies to actually interact with those other masters (except perhaps by experiencing some arbitration delays) then presumably there's no need to represent the other masters in DT?

My example is contrived, but there is nothing in the SPMI spec preventing two masters from being controllable by the same CPU-to-which-the-DT-applies, sharing the same underlying bus.

I would also expect this configuration to be uncommon, I'm checking with some folks with more SPMI experience to make sure they agree.

Interestingly, i2c as far as I can tell has also made the same assumption. There doesn't appear to be any way to express a multi-master i2c setup where both masters are controlled by the same OS.

Quoted 51 lines
Quoted 32 lines
	master0: master at 0 {
		compatible = "...";
		#spmi-master-cells = <0>;
		spmi-mid = <0>;

		...
	};

	master2: master at 2 {
		compatible = "...";
		#spmi-master-cells = <0>;
		spmi-mid = <2>;

		...
	};

	spmi_bus {
		compatible = "...";

		spmi-masters = <&master0 &master2>;

		foo at 0 {
			compatible = "...";
			reg = <0 ...>;
		};

		foo at 8 {
			compatible = "...";
			reg = <8 ...>;
		};
	};
Quoted 7 lines

(This will also necessitate a change in the underlying SPMI driver model, in the current implementation, a SPMI master 'owns' a particular device. This is not a valid assumption to make.)

Would this property-containing-phandle-vector be considered the canonical way of representing nodes with multiple parents in the device tree?

I don't think I've seen anything like this before, although that in-and-of-itself doesn't make it wrong.

Another approach might be to encode master-vs-slave into a cell in the reg property? Something like:

cell 0 - address type (0: master, 1: unique ID, 2: group ID, ...) cell 1 - address value

I haven't thought much about that; perhaps there are disadvantages doing that.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#12 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

Quoted 24 lines · Josh Cartwright
Quoted 17 lines · Stephen Warren

On 08/27/2013 11:01 AM, Josh Cartwright wrote:
...

Quoted 7 lines

If we want to ensure for the generic bindings that we are fulling characterizing/describing the SPMI bus, then we'll additionally need to tackle an additional identified assumption:

4. One master per SPMI bus. (The SPMI spec allows for up to 4 masters)

Quoted 7 lines

On the Snapdragon 800 series, there exists only one software-controlled master, but it is conceivably possible to have a setup with two software-controlled masters on the same SPMI bus.

This necessarily means that the description of the slaves and the masters will need to be decoupled; I'm imagining a generic binding supporting multiple masters would look something like this:

Quoted 5 lines

Is there a need to represent the other masters in the DT? Sure they're there in HW, but if there's no specific way for the CPU-to-which-the-DT-applies to actually interact with those other masters (except perhaps by experiencing some arbitration delays) then presumably there's no need to represent the other masters in DT?

Quoted 3 lines

My example is contrived, but there is nothing in the SPMI spec preventing two masters from being controllable by the same CPU-to-which-the-DT-applies, sharing the same underlying bus.

That's true.

Quoted 6 lines

I would also expect this configuration to be uncommon, I'm checking with some folks with more SPMI experience to make sure they agree.

Interestingly, i2c as far as I can tell has also made the same assumption. There doesn't appear to be any way to express a multi-master i2c setup where both masters are controlled by the same OS.

Yes, I think it's a fair assumption that we don't need to represent that; I immediately thought about the I2C counter-example after reading your first paragraph.

#13 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

In reply to Stephen Warren
Quoted 3 lines · Stephen Warren

On 08/27/2013 11:01 AM, Josh Cartwright wrote:
...
cell 0 - address type (0: master, 1: unique ID, 2: group ID, ...)

I think it would make sense to have the master id as a property of the bus, as you could consider this to indicate different buses and then usid, gsid and base being part of the reg.

Quoted 1 line

cell 1 - address value

I did hack up Josh patchset to read a reg touple of <usid, base> instead of just usid. I stored the second value in the spmi_device struct for easy access, but maybe it should be done like on codeaurora; in a resource?
I believe this looks nice, but as I haven't read the mipi spec I wonder, will there be a case where you don't have an offset/base? Should it just be made optional?

Can we make the address <usid, [base]> and have the code populate a resource based on a reg-names property? That way it would be possible to extend it to support gsid in case we want to (would require reg-names though).

With the hack to Josh's patchset I quickly ported qpnp-revision and qpnp-vibrator, and it seems to work quite nicely.

Regards,
Bjorn

#14 lore raw

Re: [PATCH RFC v2 3/5] spmi: add generic SPMI controller binding documentation

Hey Bjorn-

Quoted 7 lines · Bjorn Andersson
Quoted 3 lines · Stephen Warren

On 08/27/2013 11:01 AM, Josh Cartwright wrote:
...
cell 0 - address type (0: master, 1: unique ID, 2: group ID, ...)

I think it would make sense to have the master id as a property of the bus,

Except that SPMI supports bus configurations with multiple masters. Unless by 'bus' you meant 'bus controller' here?

Quoted 5 lines

as you could consider this to indicate different buses and then usid, gsid and base being part of the reg.

Quoted 1 line

cell 1 - address value

Quoted 7 lines

I did hack up Josh patchset to read a reg touple of <usid, base> instead of just usid. I stored the second value in the spmi_device struct for easy access, but maybe it should be done like on codeaurora; in a resource?
I believe this looks nice, but as I haven't read the mipi spec I wonder, will there be a case where you don't have an offset/base? Should it just be made optional?

The SPMI spec says nothing about partitioning up the slave address to support multiple functions. AFAICT, this is a Qualcomm-created construct (QPNP) for the 8x41 PMICs. It's difficult to tell at this point whether or not other vendors might implement a similarly partitioned scheme.

I suspect the intent is that implementations make use of logical slave ID for each function in a multi-function device.

Quoted 4 lines

Can we make the address <usid, [base]> and have the code populate a resource based on a reg-names property? That way it would be possible to extend it to support gsid in case we want to (would require reg-names though).

It is certainly possible, and, as you've seen, is how the current codeaurora.org tree implements SPMI. But, I'm actually actively trying to avoid doing so, as it conflates Qualcomm-implementation details and what is actually in the spec (and not just the address space partitioning, but also the of_spmi.c[2] parsing must know about interrupts, which are _also_ completely outside the SPMI spec).

Instead what I hope to do for v3 is either:
A) Make QPNP its own bus type (for which I have a prototyped implementation). A PMIC driver sits on the SPMI bus and registers itself as a QPNP controller. QPNP controllers have very simple 8-bit register read/write operations used by QPNP devices.
B) Effectively the same as A, but gets rid of a special QPNP bus type and uses mfd/platform devices, similar to other in-tree PMIC drivers (currently working on prototyping this approach)

Quoted 2 lines

With the hack to Josh's patchset I quickly ported qpnp-revision and qpnp-vibrator, and it seems to work quite nicely.

Great! Thanks for testing.

Josh

1: https://www.codeaurora.org/cgit/quic/la/kernel/msm-3.10/tree/drivers/spmi
2: https://www.codeaurora.org/cgit/quic/la/kernel/msm-3.10/tree/drivers/of/of_spmi.c

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#15 lore raw

RFC PATCH v2 4/5 spmi: Add MSM PMIC Arbiter SPMI controller

In reply to Josh Cartwright

From: Kenneth Heitke <[email protected]>

Qualcomm's PMIC Arbiter SPMI controller functions as a bus master and is used to communication with one or more PMIC (slave) devices on the SPMI bus. The PMIC Arbiter is actually a hardware wrapper around the SPMI controller that provides concurrent and autonomous PMIC access to various entities that need to communicate with the PMIC.

The SPMI controller hardware handles all of the SPMI bus activity (bus arbitration, sequence start condition, transmission of frames, etc). This software driver uses the PMIC Arbiter register interface to initiate command sequences on the SPMI bus. The status register is read to determine when the command sequence has completed and whether or not it completed successfully.

---
 drivers/spmi/Kconfig         |  15 ++
 drivers/spmi/Makefile        |   2 +
 drivers/spmi/spmi-pmic-arb.c | 416 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 433 insertions(+)
 create mode 100644 drivers/spmi/spmi-pmic-arb.c
drivers/spmi/Kconfig +15 -0
index a03835f..056891d 100644
@@ -7,3 +7,18 @@ menuconfig SPMI
 	  SPMI (System Power Management Interface) is a two-wire
 	  serial interface between baseband and application processors
 	  and Power Management Integrated Circuits (PMIC).
+
+if SPMI
+
+config SPMI_MSM_PMIC_ARB
+	tristate "Qualcomm MSM SPMI Controller (PMIC Arbiter)"
+	depends on ARCH_MSM
+	help
+	  If you say yes to this option, support will be included for the
+	  built-in SPMI PMIC Arbiter interface on Qualcomm MSM family
+	  processors.
+
+	  This is required for communicating with Qualcomm PMICs and
+	  other devices that have the SPMI interface.
+
+endif
drivers/spmi/Makefile +2 -0
index 9d78ec9..e3cbd01 100644
@@ -2,3 +2,5 @@
 # Makefile for kernel SPMI framework.
 #
 obj-$(CONFIG_SPMI)	+= spmi.o spmi-dbgfs.o
+
+obj-$(CONFIG_SPMI_MSM_PMIC_ARB)	+= spmi-pmic-arb.o
drivers/spmi/spmi-pmic-arb.c new file +416 -0

416 lines not on this page · raw message

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#16 lore raw

RFC PATCH v2 5/5 spmi: document the PMIC arbiter SPMI bindings

In reply to Josh Cartwright
---
 .../bindings/spmi/qcom,spmi-pmic-arb.txt           | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt
Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt new file +36 -0
new file mode 100644
index 0000000..3965236
@@ -0,0 +1,36 @@
+Qualcomm SPMI Controller (PMIC Arbiter)
+
+The SPMI PMIC Arbiter is found on the Snapdragon 800 Series.  It is an SPMI
+controller with wrapping arbitration logic to allow for multiple on-chip
+devices to control a single SPMI master.
+
+See spmi.txt for the generic SPMI controller bindings.
+
+Required properties:
+- compatible : should be "qcom,spmi-pmic-arb".
+- reg-names  : should be "core", "intr", "cnfg"
+- reg : offset and length of the PMIC Arbiter Core register map.
+- reg : offset and length of the PMIC Arbiter Interrupt controller register map.
+- reg : offset and length of the PMIC Arbiter Configuration register map.
+- #address-cells : must be set to 1
+- #size-cells : must be set to 0
+
+Child nodes:
+
+Zero or more child nodes must be specified as per the spmi.txt document.
+
+Example:
+
+	qcom,spmi at fc4c0000 {
+		compatible = "qcom,spmi-pmic-arb";
+		reg-names = "core", "intr", "cnfg";
+		reg = <0xfc4cf000 0x1000>,
+		      <0Xfc4cb000 0x1000>,
+		      <0Xfc4ca000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		qcom,pm8841 at 4 {
+			reg = <0x4>;
+		};
+	};
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#17 lore raw

Re: [PATCH RFC v2 5/5] spmi: document the PMIC arbiter SPMI bindings

On 08/09/2013 02:37 PM, Josh Cartwright wrote:

Patch description?

Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt line 14

Quoted 9 lines
Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt +6 -0
 
+Required properties:
+- compatible : should be "qcom,spmi-pmic-arb".
+- reg-names  : should be "core", "intr", "cnfg"
 
+- reg : offset and length of the PMIC Arbiter Core register map.
+- reg : offset and length of the PMIC Arbiter Interrupt controller register map.
+- reg : offset and length of the PMIC Arbiter Configuration register map.

This seems like it's defining the "reg" property 3 times each with a different meaning. It'd be better to say something like:

reg : register specifier. Must contain 3 entries, in the following
order: core registers, interrupt register, configuration registers.

Quoted 1 line
Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt +1 -0
+	qcom,spmi at fc4c0000 {

...

Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt line 33

Quoted 1 line
Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt +1 -0
+		qcom,pm8841 at 4 {

Node names typically don't include a vendor prefix. For the first instance above, I think just "spmi at fc4c0000" or even just "spmi" would be appropriate here; the latter being best in the case where there's only 1 SPMI controller and hence no need to include the unit address for uniqueness.