Skip to contentSkip to conversation

Introduce framework for SLIMbus device drivers

PATCH Superseded Sagar Dharia 3 participants 19 messages Aug 3, 2015 – Aug 17, 2015

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce framework for SLIMbus device drivers

Changes since V2:
* Multiple files to represent corresponding functionality of the framework per Srini's suggestion
* Documentation/slimbus/summary to capture documentation
* register_controller now adds slave devices as well for that controller (rather than additional step) per Mark's suggestion
* Changed framework to make sure synchronous transactions are waited- for in framework itself per Mark's suggestion
* Addressed other inline comments.

Sagar Dharia (6):
SLIMbus: Device management on SLIMbus
of/slimbus: OF helper for SLIMbus
slimbus: Add messaging APIs to slimbus framework
slim: qcom: Add Qualcomm Slimbus controller driver
slimbus: Add support for 'clock-pause' feature
slim: qcom: Add runtime-pm support using clock-pause feature

 Documentation/devicetree/bindings/slimbus/bus.txt  |  46 ++
 .../devicetree/bindings/slimbus/slim-qcom-ctrl.txt |  42 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/slimbus/Kconfig                            |  21 +
 drivers/slimbus/Makefile                           |   5 +
 drivers/slimbus/slim-core.c                        | 855 +++++++++++++++++++++
 drivers/slimbus/slim-messaging.c                   | 378 +++++++++
 drivers/slimbus/slim-qcom-ctrl.c                   | 734 ++++++++++++++++++
 drivers/slimbus/slim-qcom.h                        |  66 ++
 drivers/slimbus/slim-sched.c                       | 121 +++
 include/linux/mod_devicetable.h                    |  13 +
 include/linux/slimbus.h                            | 678 ++++++++++++++++
 13 files changed, 2962 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
 create mode 100644 Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt
 create mode 100644 drivers/slimbus/Kconfig
 create mode 100644 drivers/slimbus/Makefile
 create mode 100644 drivers/slimbus/slim-core.c
 create mode 100644 drivers/slimbus/slim-messaging.c
 create mode 100644 drivers/slimbus/slim-qcom-ctrl.c
 create mode 100644 drivers/slimbus/slim-qcom.h
 create mode 100644 drivers/slimbus/slim-sched.c
 create mode 100644 include/linux/slimbus.h
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v3 1/6 SLIMbus: Device management on SLIMbus

SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance. SLIMbus is a 2-wire implementation, which is used to communicate with peripheral components like audio-codec.
SLIMbus uses Time-Division-Multiplexing to accommodate multiple data channels, and control channel. Control channel has messages to do device-enumeration, messages to send/receive control-data to/from slimbus devices, messages for port/channel management, and messages to do bandwidth allocation.
The framework supports multiple instances of the bus (1 controller per bus), and multiple slave devices per controller.

This patch does device enumeration, logical address assignment, informing device when the device reports present/absent etc. Reporting present may need the driver to do the needful (e.g. turning on voltage regulators powering the device). So probe is called if the device is added to board-info list for a controller. Additionally device is probed when it reports present if that device doesn't need any such steps mentioned above.

---
 Documentation/slimbus/summary   | 109 ++++++
 drivers/Kconfig                 |   2 +
 drivers/Makefile                |   1 +
 drivers/slimbus/Kconfig         |  11 +
 drivers/slimbus/Makefile        |   4 +
 drivers/slimbus/slim-core.c     | 734 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mod_devicetable.h |  13 +
 include/linux/slimbus.h         | 389 +++++++++++++++++++++
 8 files changed, 1263 insertions(+)
 create mode 100644 Documentation/slimbus/summary
 create mode 100644 drivers/slimbus/Kconfig
 create mode 100644 drivers/slimbus/Makefile
 create mode 100644 drivers/slimbus/slim-core.c
 create mode 100644 include/linux/slimbus.h
Documentation/slimbus/summary new file +109 -0
new file mode 100644
index 0000000..73d86e9
@@ -0,0 +1,109 @@
+Overview of Linux kernel SLIMbus support
+========================================
+
+What is SLIMbus?
+----------------
+SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by
+MIPI (Mobile Industry Processor Interface) alliance. The bus uses master/slave
+configuration, and is a 2-wire multi-drop implementation (clock, and data).
+
+Currently, SLIMbus is used to interface between application processors of SoCs
+(System-on-Chip) and peripheral components (typically codec).SLIMbus uses
+Time-Division-Multiplexing to accommodate multiple data channels, and
+a control channel.
+
+The control channel is used for various control functions such as bus
+management, configuration and status updates.These messages can be unicast (e.g.
+reading/writing device specific values), or multicast (e.g. data channel
+reconfiguration sequence is a broadcast message announced to all devices)
+
+A data channel is used for data-transfer between 2 Slimbus devices. Data
+channel uses dedicated ports on the device.
+
+Hardware description:
+---------------------
+Slimbus specification has different types of device classifications based on
+their capabilities.
+A manager device is responsible for enumeration, configuration, and dynamic
+channel allocation. Every bus has 1 active manager.
+
+A generic device is a device providing application functionality (e.g. codec).
+
+Framer device is responsible for clocking the bus, and transmitting frame-sync
+and framing information on the bus.
+
+Each SLIMbus component has an interface device for monitoring physical layer.
+
+Typically each SoC contains SLIMbus component having 1 manager, 1 framer device,
+1 generic device (for data channel support), and 1 interface device.
+External peripheral SLIMbus component usually has 1 generic device (for
+functionality/data channel support), and an associated interface device.
+The generic device's registers are mapped as 'value elements' so that they can
+be written/read using Slimbus control channel exchanging control/status type of
+information.
+In case there are multiple framer devices on the same bus, manager device is
+responsible to select the active-framer for clocking the bus.
+
+Per specification, Slimbus uses "clock gears" to do power management based on
+current frequency and bandwidth requirements. There are 10 clock gears and each
+gear changes the Slimbus frequency to be twice its previous gear.
+
+Each device has a 6-byte enumeration-address and the manager assigns every
+device with a 1-byte logical address after the devices report presence on the
+bus.
+
+Software description:
+---------------------
+There are 2 types of SLIMbus drivers:
+
+slim_controller represents a 'controller' for SLIMbus. This driver should
+implement duties needed by the SoC (manager device, associated
+interface device for monitoring the layers and reporting errors, default
+framer device).
+
+slim_device represents the 'generic device/component' for SLIMbus, and a
+slim_driver should implement driver for that slim_device.
+
+Device notifications to the driver:
+-----------------------------------
+Since SLIMbus devices have mechanisms for reporting their presence, the
+framework allows drivers to bind when corresponding devices report their
+presence on the bus.
+However, it is possible that the driver needs to be probed
+first so that it can enable corresponding SLIMbus devie (e.g. power it up and/or
+take it out of reset). To support that behavior, the framework allows drivers
+to probe first as well  (e.g. using standard DeviceTree compatbility field).
+This creates the necessity for the driver to know when the device is functional
+(i.e. reported present). device_up callback is used for that reason when the
+device reports present and is assigned a logical address by the contoller.
+
+Similarly, SLIMbus devices 'report absent' when they go down. A 'device_down'
+callback notifies the driver when the device reports absent and its logical
+address assignment is invalidated by the controller.
+
+Another notification "boot_device" is used to notify the slim_driver when
+controller resets the bus. This notification allows the driver to take necessary
+steps to boot the device so that it's functional after the bus has been reset.
+
+Clock-pause:
+------------
+SLIMbus mandates that a reconfiguration sequence (known as clock-pause) be
+broadcast to all active devices on the bus before the bus can enter low-power
+mode. Controller uses this sequence when it decides to enter low-power mode so
+that corresponding clocks and/or power-rails can be turned off to save power.
+Clock-pause is exited by waking up framer device (if controller driver initiates
+exiting low power mode), or by toggling the data line (if a slave device wants
+to initiate it).
+
+Messaging APIs:
+---------------
+The framework supports APIs to exchange control-information with a SLIMbus
+device. APIs can be synchronous or asynchronous.
+From controller's perspective, multiple buffers can be queued to/from
+hardware for sending/receiving data using slim_ctrl_buf circular buffer.
+The header file <linux/slimbus.h> has more documentation about messaging APIs.
+
+-----------------------------------------------------------------
+<Sections will be added to this document when port/channel bandwidth management
+support, multi-xfer APIs are added to the framework>
+------------------------------------------------------------------
drivers/Kconfig +2 -0
index c0cc96b..e39c969 100644
@@ -182,4 +182,6 @@ source "drivers/thunderbolt/Kconfig"
 
 source "drivers/android/Kconfig"
 
+source "drivers/slimbus/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index 46d2554..37c1c88 100644
@@ -74,6 +74,7 @@ obj-$(CONFIG_TARGET_CORE)	+= target/
 obj-$(CONFIG_MTD)		+= mtd/
 obj-$(CONFIG_SPI)		+= spi/
 obj-$(CONFIG_SPMI)		+= spmi/
+obj-$(CONFIG_SLIMBUS)		+= slimbus/
 obj-y				+= hsi/
 obj-y				+= net/
 obj-$(CONFIG_ATM)		+= atm/
drivers/slimbus/Kconfig new file +11 -0
new file mode 100644
index 0000000..f0b118a
@@ -0,0 +1,11 @@
+#
+# SLIMBUS driver configuration
+#
+menuconfig SLIMBUS
+	tristate "Slimbus support"
+	help
+	  Slimbus is standard interface between System-on-Chip and audio codec,
+	  and other peripheral components in typical embedded systems.
+
+	  If unsure, choose N.
+
drivers/slimbus/Makefile new file +4 -0
new file mode 100644
index 0000000..aa9c147
@@ -0,0 +1,4 @@
+#
+# Makefile for kernel slimbus framework.
+#
+obj-$(CONFIG_SLIMBUS)			+= slim-core.o
drivers/slimbus/slim-core.c new file +734 -0

734 lines not on this page · raw message

include/linux/mod_devicetable.h +13 -0
index 3bfd567..94abc09 100644
@@ -427,6 +427,19 @@ struct spi_device_id {
 	kernel_ulong_t driver_data;	/* Data private to the driver */
 };
 
+/* SLIMbus */
+
+#define SLIMBUS_NAME_SIZE	32
+#define SLIMBUS_MODULE_PREFIX	"slim:"
+
+struct slim_device_id {
+	__u16 manf_id, prod_code;
+	__u8 dev_index, instance;
+
+	/* Data private to the driver */
+	kernel_ulong_t driver_data;
+};
+
 #define SPMI_NAME_SIZE	32
 #define SPMI_MODULE_PREFIX "spmi:"
 
include/linux/slimbus.h new file +389 -0

389 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#2 lore raw

Re: [PATCH V3 1/6] SLIMbus: Device management on SLIMbus

drivers/slimbus/slim-core.c line 117

Quoted 5 lines · Sagar Dharia
drivers/slimbus/slim-core.c new file +5 -0
+	INIT_WORK(&sbw->wd, slim_report);
+	sbw->sb = sb;
+	sbw->report = report;
+	if (!queue_work(ctrl->wq, &sbw->wd))
+		kfree(sbw);

Should we not complain if we fail to schedule the work?

drivers/slimbus/slim-core.c line 245

Quoted 6 lines
drivers/slimbus/slim-core.c new file +6 -0
+#define slim_device_attr_gr NULL
+#define slim_device_uevent NULL
+
+static struct device_type slim_dev_type = {
+	.groups		= slim_device_attr_gr,
+	.uevent		= slim_device_uevent,

Why these NULL defines? Just add the struct members as definitions are added.

drivers/slimbus/slim-core.c line 276

Quoted 4 lines
drivers/slimbus/slim-core.c new file +4 -0
+	dev_set_name(&sbdev->dev, "%s", sbdev->name);
+	mutex_lock(&ctrl->m_ctrl);
+	list_add_tail(&sbdev->dev_list, &ctrl->devs);
+	mutex_unlock(&ctrl->m_ctrl);

Doesn't the driver model list of children of the controller give you a list of devices connected to the controller?

drivers/slimbus/slim-core.c line 372

Quoted 5 lines
drivers/slimbus/slim-core.c new file +5 -0
+	/* Can't register until after driver model init */
+	if (WARN_ON(!slimbus_type.p)) {
+		ret = -EAGAIN;
+		goto out_list;
+	}

Shouldn't the core code handle this for us?

#3 lore raw

PATCH v3 2/6 of/slimbus: OF helper for SLIMbus

In reply to Sagar Dharia

OF helper routine scans the SLIMbus DeviceTree, allocates resources, and creates slim_devices according to the hierarchy.

---
 Documentation/devicetree/bindings/slimbus/bus.txt | 46 ++++++++++++++
 drivers/slimbus/slim-core.c                       | 75 +++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
Documentation/devicetree/bindings/slimbus/bus.txt new file +46 -0
new file mode 100644
index 0000000..a79ed7a
@@ -0,0 +1,46 @@
+SLIM(Serial Low Power Interchip Media Bus) bus
+
+SLIMbus is a 2-wire bus, and is used to communicate with peripheral
+components like audio-codec.
+
+Controller is a normal device using binding for whatever bus it is
+on (e.g. platform bus).
+Required property for SLIMbus controller node:
+- compatible	- name of SLIMbus controller following generic names
+		recommended practice.
+- #address-cells - should be 6 (number of cells required to define
+		enumeration address of the device on SLIMbus)
+- #size-cells	- should be 0
+
+No other properties are required in the SLIMbus controller bus node.
+
+Child nodes:
+Every SLIMbus controller node can contain zero or more child nodes
+representing slave devices on the bus. Every SLIMbus slave device is
+uniquely determined by the 6 byte enumeration address.
+
+Required property for SLIMbus child node:
+- reg		- 6 byte enumeration address of the slave
+
+Optional:
+- compatible	- Slave devices can use compatible field to have a name.
+		If this field is missing, name of the device will be
+		determined using slave's enumeration address.
+		(e.g. in the example below, slave's name will be:
+		0x217:0x60:0x1:0x0)
+
+SLIMbus example for Qualcomm's slimbus manager compoent:
+
+	slim@28080000 {
+		compatible = "qcom,slim-msm";
+		reg = <0x28080000 0x2000>,
+		reg-names = "slimbus_physical";
+		interrupts = <0 33 0>;
+		interrupt-names = "slimbus_irq";
+		clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+		clock-names = "iface_clk", "core_clk";
+
+		slim_codec_slave {
+			reg = <00 01 60 00 17 02>;
+		};
+	};
drivers/slimbus/slim-core.c +75 -0

93 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#4 lore raw

Re: [PATCH V3 2/6] of/slimbus: OF helper for SLIMbus

Quoted 29 lines · Sagar Dharia

OF helper routine scans the SLIMbus DeviceTree, allocates resources, and creates slim_devices according to the hierarchy.

---
 Documentation/devicetree/bindings/slimbus/bus.txt | 46 ++++++++++++++
 drivers/slimbus/slim-core.c                       | 75 +++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
Documentation/devicetree/bindings/slimbus/bus.txt new file +13 -0
new file mode 100644
index 0000000..a79ed7a
@@ -0,0 +1,46 @@
+SLIM(Serial Low Power Interchip Media Bus) bus
+
+SLIMbus is a 2-wire bus, and is used to communicate with peripheral
+components like audio-codec.
+
+Controller is a normal device using binding for whatever bus it is
+on (e.g. platform bus).
+Required property for SLIMbus controller node:
+- compatible   - name of SLIMbus controller following generic names
+               recommended practice.
+- #address-cells - should be 6 (number of cells required to define
+               enumeration address of the device on SLIMbus)
+- #size-cells  - should be 0

Documentation/devicetree/bindings/slimbus/bus.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +10 -0
+
+No other properties are required in the SLIMbus controller bus node.
+
+Child nodes:
+Every SLIMbus controller node can contain zero or more child nodes
+representing slave devices on the bus. Every SLIMbus slave device is
+uniquely determined by the 6 byte enumeration address.
+
+Required property for SLIMbus child node:
+- reg          - 6 byte enumeration address of the slave

6 cell... I don't think it is a big deal to use 6 words to store 6 bytes, but is there some reason not to pack the address into 2 cells?

Documentation/devicetree/bindings/slimbus/bus.txt line 30

Quoted 7 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +7 -0
+
+Optional:
+- compatible   - Slave devices can use compatible field to have a name.
+               If this field is missing, name of the device will be
+               determined using slave's enumeration address.
+               (e.g. in the example below, slave's name will be:
+               0x217:0x60:0x1:0x0)

Are devices discoverable and uniquely identifiable? This would be something like a VID/PID which can be read in a generic way. It looks like the address contains this info, but can you discover the addresses of devices on the bus? If not compatible should not be optional.

Documentation/devicetree/bindings/slimbus/bus.txt line 32

Quoted 2 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +2 -0
+
+SLIMbus example for Qualcomm's slimbus manager compoent:

typo.

Documentation/devicetree/bindings/slimbus/bus.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +5 -0
+
+       slim@28080000 {
+               compatible = "qcom,slim-msm";
+               reg = <0x28080000 0x2000>,
+               reg-names = "slimbus_physical";

Pretty pointless to have names with a single element.

Documentation/devicetree/bindings/slimbus/bus.txt line 43

Quoted 6 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +6 -0
+               interrupts = <0 33 0>;
+               interrupt-names = "slimbus_irq";
+               clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+               clock-names = "iface_clk", "core_clk";
+
+               slim_codec_slave {

You should have unit address here. Probably with "." in between fields of the address that have defined meaning. So that may be something like "0217.0060.01.00" based on what you do with the address bytes below.

Quoted 106 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +3 -0
+                       reg = <00 01 60 00 17 02>;
+               };
+       };
drivers/slimbus/slim-core.c +75 -1
index ee80c1b..d3fa28b 100644
@@ -18,6 +18,7 @@
 #include <linux/idr.h>
 #include <linux/pm_runtime.h>
 #include <linux/slimbus.h>
+#include <linux/of.h>
 
 static DEFINE_MUTEX(slim_lock);
 static DEFINE_IDR(ctrl_idr);
@@ -289,6 +290,79 @@ static LIST_HEAD(board_list);
 static LIST_HEAD(slim_ctrl_list);
 static DEFINE_MUTEX(board_lock);
 
+#if IS_ENABLED(CONFIG_OF)
+/* OF helpers for SLIMbus */
+static void of_register_slim_devices(struct slim_controller *ctrl)
+{
+       struct device_node *node;
+       struct slim_boardinfo *temp, *binfo = NULL;
+       int n = 0;
+
+       if (!ctrl->dev.of_node)
+               return;
+
+       for_each_child_of_node(ctrl->dev.of_node, node) {
+               int ret;
+               u32 ea[6];
+               struct slim_device *slim;
+               char *name;
+
+               ret = of_property_read_u32_array(node, "reg", ea, 6);
+               if (ret) {
+                       dev_err(&ctrl->dev, "of_slim: E-addr err:%d\n", ret);
+                       continue;
+               }
+               name = kcalloc(SLIMBUS_NAME_SIZE, sizeof(char), GFP_KERNEL);
+               if (!name)
+                       goto of_slim_err;
+
+               slim = kzalloc(sizeof(struct slim_device), GFP_KERNEL);
+               if (!slim) {
+                       kfree(name);
+                       goto of_slim_err;
+               }
+               slim->e_addr.manf_id = (u16)((ea[5] << 8) | ea[4]);
+               slim->e_addr.prod_code = (u16)((ea[3] << 8) | ea[2]);
+               slim->e_addr.dev_index = (u8)ea[1];
+               slim->e_addr.instance = (u8)ea[0];
+
+               ret = of_modalias_node(node, name, SLIMBUS_NAME_SIZE);
+               if (ret < 0) {
+                       /* use device address for name, if not specified */
+                       snprintf(name, SLIMBUS_NAME_SIZE, "0x%x:0x%x:0x%x:0x%x",
+                                slim->e_addr.manf_id, slim->e_addr.prod_code,
+                                slim->e_addr.dev_index, slim->e_addr.instance);
+               }
+
+               temp = krealloc(binfo, (n + 1) * sizeof(struct slim_boardinfo),
+                                       GFP_KERNEL);
+               if (!temp) {
+                       kfree(name);
+                       kfree(slim);
+                       goto of_slim_err;
+               }
+               binfo = temp;
+               slim->dev.of_node = of_node_get(node);
+               slim->name = name;
+               binfo[n].bus_num = ctrl->nr;
+               binfo[n].slim_slave = slim;
+               n++;
+       }
+       slim_register_board_info(binfo, n);
+       return;
+
+of_slim_err:
+       n--;
+       while (n >= 0) {
+               kfree(binfo[n].slim_slave->name);
+               kfree(binfo[n].slim_slave);
+       }
+       kfree(binfo);
+}
+#else
+static void of_register_slim_devices(struct slim_controller *ctrl) { }
+#endif
+
 /* If controller is not present, only add to boards list */
 static void slim_match_ctrl_to_boardinfo(struct slim_controller *ctrl,
                                         struct slim_boardinfo *bi)
@@ -338,6 +412,7 @@ static void slim_ctrl_add_boarddevs(struct slim_controller *ctrl)
 {
        struct sbi_boardinfo *bi;
 
+       of_register_slim_devices(ctrl);
        mutex_lock(&board_lock);
        list_add_tail(&ctrl->list, &slim_ctrl_list);
        list_for_each_entry(bi, &board_list, list)
--

1.8.2.1

#5 lore raw

Re: [PATCH V3 2/6] of/slimbus: OF helper for SLIMbus

Quoted 9 lines · Rob Herring

Documentation/devicetree/bindings/slimbus/bus.txt line 30

Quoted 6 lines · Sagar Dharia
Documentation/devicetree/bindings/slimbus/bus.txt new file +6 -0
+Optional:
+- compatible   - Slave devices can use compatible field to have a name.
+               If this field is missing, name of the device will be
+               determined using slave's enumeration address.
+               (e.g. in the example below, slave's name will be:
+               0x217:0x60:0x1:0x0)
Quoted 5 lines

Are devices discoverable and uniquely identifiable? This would be something like a VID/PID which can be read in a generic way. It looks like the address contains this info, but can you discover the addresses of devices on the bus? If not compatible should not be optional.

Yes, the bus is enumerable. However in essentially all implementations devices won't enumerate without some additional non-standard work being done to power them on since applications tend to be extremely power sensitive relative to the basic operating cost of the bus. Which is entertaining.

This probably means that the binding needs to say that the compatible is optional but that for all practical purposes Linux requires it until such time as someone decides it's worth supporting systems that can usefully enumerate.

#6 lore raw

Re: [PATCH V3 2/6] of/slimbus: OF helper for SLIMbus

In reply to Rob Herring

Hello Rob,

Quoted 34 lines · Rob Herring
Quoted 33 lines · Sagar Dharia

OF helper routine scans the SLIMbus DeviceTree, allocates resources, and creates slim_devices according to the hierarchy.

---
  Documentation/devicetree/bindings/slimbus/bus.txt | 46 ++++++++++++++
  drivers/slimbus/slim-core.c                       | 75 +++++++++++++++++++++++
  2 files changed, 121 insertions(+)

create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt

Documentation/devicetree/bindings/slimbus/bus.txt new file +17 -0
new file mode 100644
index 0000000..a79ed7a
@@ -0,0 +1,46 @@
+SLIM(Serial Low Power Interchip Media Bus) bus
+
+SLIMbus is a 2-wire bus, and is used to communicate with peripheral
+components like audio-codec.
+
+Controller is a normal device using binding for whatever bus it is
+on (e.g. platform bus).
+Required property for SLIMbus controller node:
+- compatible   - name of SLIMbus controller following generic names
+               recommended practice.
+- #address-cells - should be 6 (number of cells required to define
+               enumeration address of the device on SLIMbus)
+- #size-cells  - should be 0
+
+No other properties are required in the SLIMbus controller bus node.
+
+Child nodes:
Quoted 8 lines

Documentation/devicetree/bindings/slimbus/bus.txt line 23

Quoted 6 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +6 -0
+Every SLIMbus controller node can contain zero or more child nodes
+representing slave devices on the bus. Every SLIMbus slave device is
+uniquely determined by the 6 byte enumeration address.
+
+Required property for SLIMbus child node:
+- reg          - 6 byte enumeration address of the slave

6 cell... I don't think it is a big deal to use 6 words to store 6 bytes, but is there some reason not to pack the address into 2 cells?

Since the device-enumeration address has 4 logical components, I will split this in 4 cells if that's okay.

Quoted 13 lines

Documentation/devicetree/bindings/slimbus/bus.txt line 30

Quoted 8 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +7 -0
+
+Optional:
+- compatible   - Slave devices can use compatible field to have a name.
+               If this field is missing, name of the device will be
+               determined using slave's enumeration address.
+               (e.g. in the example below, slave's name will be:
+               0x217:0x60:0x1:0x0)

Are devices discoverable and uniquely identifiable? This would be something like a VID/PID which can be read in a generic way. It looks like the address contains this info, but can you discover the addresses of devices on the bus? If not compatible should not be optional.

Yes, as Mark pointed out in another thread, it's enumerable but more likely to need the compatible field for binding to make the device functional. I will word this accordingly.

Quoted 11 lines

Documentation/devicetree/bindings/slimbus/bus.txt line 32

Quoted 3 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +2 -0
+
+SLIMbus example for Qualcomm's slimbus manager compoent:

typo.

Documentation/devicetree/bindings/slimbus/bus.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +5 -0
+
+       slim@28080000 {
+               compatible = "qcom,slim-msm";
+               reg = <0x28080000 0x2000>,
+               reg-names = "slimbus_physical";

Pretty pointless to have names with a single element.

I missed 1 more name typically used by the controller in this example. Will update that.

Quoted 11 lines

Documentation/devicetree/bindings/slimbus/bus.txt line 43

Quoted 7 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +6 -0
+               interrupts = <0 33 0>;
+               interrupt-names = "slimbus_irq";
+               clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+               clock-names = "iface_clk", "core_clk";
+
+               slim_codec_slave {

You should have unit address here. Probably with "." in between fields of the address that have defined meaning. So that may be something like "0217.0060.01.00" based on what you do with the address bytes below.

Yes, that's a good idea and will go well when unit address and reg will have same 4 fields.

Thanks for the review-
Sagar

Quoted 107 lines
Quoted 107 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +3 -0
+                       reg = <00 01 60 00 17 02>;
+               };
+       };
drivers/slimbus/slim-core.c +75 -1
index ee80c1b..d3fa28b 100644
@@ -18,6 +18,7 @@
  #include <linux/idr.h>
  #include <linux/pm_runtime.h>
  #include <linux/slimbus.h>
+#include <linux/of.h>
 
  static DEFINE_MUTEX(slim_lock);
  static DEFINE_IDR(ctrl_idr);
@@ -289,6 +290,79 @@ static LIST_HEAD(board_list);
  static LIST_HEAD(slim_ctrl_list);
  static DEFINE_MUTEX(board_lock);
 
+#if IS_ENABLED(CONFIG_OF)
+/* OF helpers for SLIMbus */
+static void of_register_slim_devices(struct slim_controller *ctrl)
+{
+       struct device_node *node;
+       struct slim_boardinfo *temp, *binfo = NULL;
+       int n = 0;
+
+       if (!ctrl->dev.of_node)
+               return;
+
+       for_each_child_of_node(ctrl->dev.of_node, node) {
+               int ret;
+               u32 ea[6];
+               struct slim_device *slim;
+               char *name;
+
+               ret = of_property_read_u32_array(node, "reg", ea, 6);
+               if (ret) {
+                       dev_err(&ctrl->dev, "of_slim: E-addr err:%d\n", ret);
+                       continue;
+               }
+               name = kcalloc(SLIMBUS_NAME_SIZE, sizeof(char), GFP_KERNEL);
+               if (!name)
+                       goto of_slim_err;
+
+               slim = kzalloc(sizeof(struct slim_device), GFP_KERNEL);
+               if (!slim) {
+                       kfree(name);
+                       goto of_slim_err;
+               }
+               slim->e_addr.manf_id = (u16)((ea[5] << 8) | ea[4]);
+               slim->e_addr.prod_code = (u16)((ea[3] << 8) | ea[2]);
+               slim->e_addr.dev_index = (u8)ea[1];
+               slim->e_addr.instance = (u8)ea[0];
+
+               ret = of_modalias_node(node, name, SLIMBUS_NAME_SIZE);
+               if (ret < 0) {
+                       /* use device address for name, if not specified */
+                       snprintf(name, SLIMBUS_NAME_SIZE, "0x%x:0x%x:0x%x:0x%x",
+                                slim->e_addr.manf_id, slim->e_addr.prod_code,
+                                slim->e_addr.dev_index, slim->e_addr.instance);
+               }
+
+               temp = krealloc(binfo, (n + 1) * sizeof(struct slim_boardinfo),
+                                       GFP_KERNEL);
+               if (!temp) {
+                       kfree(name);
+                       kfree(slim);
+                       goto of_slim_err;
+               }
+               binfo = temp;
+               slim->dev.of_node = of_node_get(node);
+               slim->name = name;
+               binfo[n].bus_num = ctrl->nr;
+               binfo[n].slim_slave = slim;
+               n++;
+       }
+       slim_register_board_info(binfo, n);
+       return;
+
+of_slim_err:
+       n--;
+       while (n >= 0) {
+               kfree(binfo[n].slim_slave->name);
+               kfree(binfo[n].slim_slave);
+       }
+       kfree(binfo);
+}
+#else
+static void of_register_slim_devices(struct slim_controller *ctrl) { }
+#endif
+
  /* If controller is not present, only add to boards list */
  static void slim_match_ctrl_to_boardinfo(struct slim_controller *ctrl,
                                          struct slim_boardinfo *bi)
@@ -338,6 +412,7 @@ static void slim_ctrl_add_boarddevs(struct slim_controller *ctrl)
  {
         struct sbi_boardinfo *bi;
 
+       of_register_slim_devices(ctrl);
         mutex_lock(&board_lock);
         list_add_tail(&ctrl->list, &slim_ctrl_list);
         list_for_each_entry(bi, &board_list, list)
--

1.8.2.1

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

PATCH v3 3/6 slimbus: Add messaging APIs to slimbus framework

In reply to Sagar Dharia

Slimbus devices use value-element, and information elements to control device parameters (e.g. value element is used to represent gain for codec, information element is used to represent interrupt status for codec when codec interrupt fires).
Messaging APIs are used to set/get these value and information elements. Slimbus specification uses 8-bit "transaction IDs" for messages where a read-value is anticipated. Framework uses a table of pointers to store those TIDs and responds back to the caller in O(1).
Caller can opt to do synchronous, or asynchronous reads/writes. For asynchronous operations, the callback will be called from atomic context.

---
 drivers/slimbus/Makefile         |   2 +-
 drivers/slimbus/slim-core.c      |  44 +++++
 drivers/slimbus/slim-messaging.c | 378 +++++++++++++++++++++++++++++++++++++++
 include/linux/slimbus.h          | 226 +++++++++++++++++++++++
 4 files changed, 649 insertions(+), 1 deletion(-)
 create mode 100644 drivers/slimbus/slim-messaging.c
drivers/slimbus/Makefile +1 -1
index aa9c147..d95a0a2 100644
@@ -1,4 +1,4 @@
 #
 # Makefile for kernel slimbus framework.
 #
-obj-$(CONFIG_SLIMBUS)			+= slim-core.o
+obj-$(CONFIG_SLIMBUS)			+= slim-core.o slim-messaging.o
drivers/slimbus/slim-core.c +44 -0

73 lines not on this page · raw message

drivers/slimbus/slim-messaging.c new file +378 -0

378 lines not on this page · raw message

include/linux/slimbus.h +226 -0

267 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#8 lore raw

Re: [PATCH V3 3/6] slimbus: Add messaging APIs to slimbus framework

drivers/slimbus/slim-core.c int slim_register_controller(struct slim_controller *ctrl) · line 471

Quoted 1 line · Sagar Dharia
drivers/slimbus/slim-core.c +1 -0
+	sema_init(&ctrl->tx_sem, (ctrl->tx.n - 1));

This sempahore counts the number of free slots in the statically allocated list of transfers we have allocated. It would be good to see some discussion in the changelog as to why we've got this statically allocated pool rather than just dynamically allocating them as needed - I can see a performance argument there but it'd be good to have the thinking documented.

Quoted 4 lines
drivers/slimbus/slim-messaging.c new file +4 -0
+	buf = slim_get_tx(ctrl, txn, need_tid, async);
+	if (!buf)
+		return -ENOMEM;
+

drivers/slimbus/slim-messaging.c line 93

Quoted 10 lines
drivers/slimbus/slim-messaging.c new file +10 -0
+	if (need_tid) {
+		spin_lock_irqsave(&ctrl->txn_lock, flags);
+		for (i = 0; i < ctrl->last_tid; i++) {
+			if (ctrl->tid_tbl[i] == NULL)
+				break;
+		}
+		if (i >= ctrl->last_tid) {
+			if (ctrl->last_tid == (SLIM_MAX_TIDS - 1)) {
+				spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+				return -ENOMEM;

We don't undo slim_get_tx() here but the definition looks like we ought to be returning the buffer we allocated.

#9 lore raw

Re: [PATCH V3 3/6] slimbus: Add messaging APIs to slimbus framework

Quoted 10 lines · Mark Brown

drivers/slimbus/slim-core.c int slim_register_controller(struct slim_controller *ctrl) · line 471

Quoted 1 line · Sagar Dharia
drivers/slimbus/slim-core.c +1 -0
+	sema_init(&ctrl->tx_sem, (ctrl->tx.n - 1));

This sempahore counts the number of free slots in the statically allocated list of transfers we have allocated. It would be good to see some discussion in the changelog as to why we've got this statically allocated pool rather than just dynamically allocating them as needed - I can see a performance argument there but it'd be good to have the thinking documented.

One other related thing here: we're keeping the buffers permanently coherently mapped rather than only mapping them to the device as needed. Is this the best approach? On the one hand it increases the cost to the CPU when setting things up and reading data back, on the other hand it avoids mapping operations.

Since it's becoming part of the driver API with this it bears some thought, it will be a little annoying (and fiddly) to change later.

#10 lore raw

PATCH v3 4/6 slim: qcom: Add Qualcomm Slimbus controller driver

In reply to Sagar Dharia

This controller driver programs manager, interface, and framer devices for Qualcomm's slimbus HW block.
Manager component currently implements logical address setting, and messaging interface.
Interface device reports bus synchronization information, and framer device clocks the bus from the time it's woken up, until clock-pause is executed by the manager device.

---
 .../devicetree/bindings/slimbus/slim-qcom-ctrl.txt |  42 ++
 drivers/slimbus/Kconfig                            |  10 +
 drivers/slimbus/Makefile                           |   1 +
 drivers/slimbus/slim-qcom-ctrl.c                   | 587 +++++++++++++++++++++
 drivers/slimbus/slim-qcom.h                        |  65 +++
 5 files changed, 705 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt
 create mode 100644 drivers/slimbus/slim-qcom-ctrl.c
 create mode 100644 drivers/slimbus/slim-qcom.h
Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file +42 -0
new file mode 100644
index 0000000..5dd6e0f
@@ -0,0 +1,42 @@
+Qualcomm SLIMBUS controller
+"qcom,slim-msm": This controller is used if applications processor
+	driver is controlling slimbus master component. This driver is
+	responsible for communicating with slave HW directly using
+	messaging interface, and doing data channel management.
+
+Required properties:
+
+ - reg : Offset and length of the register region(s) for the device
+ - reg-names : Register region name(s) referenced in reg above
+	 Required register resource entries are:
+	 "slimbus_physical": Physical adderss of controller register blocks
+	 "slimbus_bam_physical": Physical address of Bus Access Module (BAM)
+				 for this controller
+ - compatible : should be "qcom,slim-msm" if this is master component driver
+ - interrupts : Interrupt numbers used by this controller
+ - interrupt-names : Required interrupt resource entries are:
+	"slimbus_irq" : Interrupt for SLIMBUS core
+ - clocks : Interface and core clocks used by this slimbus controller
+ - clock-names : Required clock-name entries are:
+	"iface_clk" : Interface clock for this controller
+	"core_clk" : Interrupt for controller core's BAM
+
+Optional property:
+ - reg entry for slew rate : If slew rate control register is provided, this
+	entry should be used.
+ - reg-name for slew rate: "slimbus_slew_reg"
+
+Example:
+	slim@28080000 {
+		compatible = "qcom,slim-msm";
+		reg = <0x28080000 0x2000>,
+		reg-names = "slimbus_physical";
+		interrupts = <0 33 0>;
+		interrupt-names = "slimbus_irq";
+		clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+		clock-names = "iface_clk", "core_clk";
+
+		slim_codec_slave {
+			enumeration-addr = [00 01 60 00 17 02];
+		};
+	};
drivers/slimbus/Kconfig +10 -0
index f0b118a..afe15b3 100644
@@ -9,3 +9,13 @@ menuconfig SLIMBUS
 
 	  If unsure, choose N.
 
+if SLIMBUS
+config SLIM_QCOM_CTRL
+	tristate "Qualcomm Slimbus Manager Component"
+	depends on SLIMBUS
+	default n
+	help
+	  Select driver if Qualcomm's Slimbus Manager Component is
+	  programmed using Linux kernel.
+
+endif
drivers/slimbus/Makefile +1 -0
index d95a0a2..574a892 100644
@@ -2,3 +2,4 @@
 # Makefile for kernel slimbus framework.
 #
 obj-$(CONFIG_SLIMBUS)			+= slim-core.o slim-messaging.o
+obj-$(CONFIG_SLIM_QCOM_CTRL)		+= slim-qcom-ctrl.o
drivers/slimbus/slim-qcom-ctrl.c new file +587 -0

587 lines not on this page · raw message

drivers/slimbus/slim-qcom.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#11 lore raw

Re: [PATCH V3 4/6] slim: qcom: Add Qualcomm Slimbus controller driver

Quoted 9 lines · Sagar Dharia
drivers/slimbus/slim-qcom-ctrl.c new file +9 -0
+/**
+ * Qualcomm slimbus controller may experience interference on the lines
+ * causing some early messages (e.g. logical-address assignment) to be
+ * NACKed. Retry after sometime (typically 1 superframe)
+ */
+static void msm_slim_wait_retry(struct msm_slim_ctrl *dev)
+{
+	int msec_per_frm = 0;
+	int sfr_per_sec;

drivers/slimbus/slim-qcom-ctrl.c line 238

Quoted 10 lines
drivers/slimbus/slim-qcom-ctrl.c new file +10 -0
+
+	/* Wait for 1 superframe, or default time and then retry */
+	sfr_per_sec = dev->framer.superfreq /
+			(1 << (SLIM_MAX_CLK_GEAR - dev->ctrl.clkgear));
+	if (sfr_per_sec)
+		msec_per_frm = MSEC_PER_SEC / sfr_per_sec;
+	if (msec_per_frm < DEF_RETRY_MS)
+		msec_per_frm = DEF_RETRY_MS;
+	msleep(msec_per_frm);
+}

This looks like logic which might be usefully pulled out to the framework - I bet this isn't an issue unique to your controller, the users (well, one user) look like cases where the bus might be destabilised by devices powering up and trying to enumerate under less than ideal electrical conditions which seems like something that's likely to affect other hardware.

drivers/slimbus/slim-qcom-ctrl.c line 404

Quoted 5 lines
drivers/slimbus/slim-qcom-ctrl.c new file +5 -0
+	rclk = devm_clk_get(&pdev->dev, "core_clk");
+	if (IS_ERR(rclk)) {
+		/* unlikely that this is probe-defer */
+		dev_err(&pdev->dev, "rclk get failed:%ld\n", PTR_ERR(rclk));
+		devm_clk_put(&pdev->dev, hclk);

No need to call devm_clk_put() explicitly in your probe function.

#12 lore raw

Re: [PATCH V3 4/6] slim: qcom: Add Qualcomm Slimbus controller driver

Quoted 19 lines · Mark Brown
Quoted 17 lines · Sagar Dharia
drivers/slimbus/slim-qcom-ctrl.c new file +17 -0
+/**
+ * Qualcomm slimbus controller may experience interference on the lines
+ * causing some early messages (e.g. logical-address assignment) to be
+ * NACKed. Retry after sometime (typically 1 superframe)
+ */
+static void msm_slim_wait_retry(struct msm_slim_ctrl *dev)
+{
+	int msec_per_frm = 0;
+	int sfr_per_sec;
+
+	/* Wait for 1 superframe, or default time and then retry */
+	sfr_per_sec = dev->framer.superfreq /
+			(1 << (SLIM_MAX_CLK_GEAR - dev->ctrl.clkgear));
+	if (sfr_per_sec)
+		msec_per_frm = MSEC_PER_SEC / sfr_per_sec;
+	if (msec_per_frm < DEF_RETRY_MS)
+		msec_per_frm = DEF_RETRY_MS;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	msleep(msec_per_frm);
+}

This looks like logic which might be usefully pulled out to the framework - I bet this isn't an issue unique to your controller, the users (well, one user) look like cases where the bus might be destabilised by devices powering up and trying to enumerate under less than ideal electrical conditions which seems like something that's likely to affect other hardware.

I agree, I will move this to the framework.

Thanks
Sagar

Quoted 7 lines

drivers/slimbus/slim-qcom-ctrl.c line 404

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +5 -0
+	rclk = devm_clk_get(&pdev->dev, "core_clk");
+	if (IS_ERR(rclk)) {
+		/* unlikely that this is probe-defer */
+		dev_err(&pdev->dev, "rclk get failed:%ld\n", PTR_ERR(rclk));
+		devm_clk_put(&pdev->dev, hclk);

No need to call devm_clk_put() explicitly in your probe function.

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

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

PATCH v3 5/6 slimbus: Add support for 'clock-pause' feature

In reply to Sagar Dharia

Per slimbus specification, a reconfiguration sequence known as 'clock pause' needs to be broadcast over the bus while entering low- power mode. Clock-pause is initiated by the controller driver. To exit clock-pause, controller typically wakes up the framer device. Since wakeup precedure is controller-specific, framework calls it via controller's function pointer to invoke it.

---
 drivers/slimbus/Makefile     |   2 +-
 drivers/slimbus/slim-core.c  |   2 +
 drivers/slimbus/slim-sched.c | 121 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/slimbus.h      |  65 +++++++++++++++++++++++
 4 files changed, 189 insertions(+), 1 deletion(-)
 create mode 100644 drivers/slimbus/slim-sched.c
drivers/slimbus/Makefile +1 -1
index 574a892..cc0d20a 100644
@@ -1,5 +1,5 @@
 #
 # Makefile for kernel slimbus framework.
 #
-obj-$(CONFIG_SLIMBUS)			+= slim-core.o slim-messaging.o
+obj-$(CONFIG_SLIMBUS)			+= slim-core.o slim-messaging.o slim-sched.o
 obj-$(CONFIG_SLIM_QCOM_CTRL)		+= slim-qcom-ctrl.o
drivers/slimbus/slim-core.c +2 -0
index 9d104ee..5d27ff2 100644
@@ -459,6 +459,8 @@ int slim_register_controller(struct slim_controller *ctrl)
 	mutex_init(&ctrl->m_ctrl);
 	spin_lock_init(&ctrl->tx.lock);
 	spin_lock_init(&ctrl->rx.lock);
+	mutex_init(&ctrl->sched.m_reconf);
+	init_completion(&ctrl->sched.pause_comp);
 
 	ctrl->pending_wr = kcalloc((ctrl->tx.n - 1),
 				   sizeof(struct slim_pending),
drivers/slimbus/slim-sched.c new file +121 -0

121 lines not on this page · raw message

include/linux/slimbus.h +65 -0

110 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#14 lore raw

Re: [PATCH V3 5/6] slimbus: Add support for 'clock-pause' feature

drivers/slimbus/slim-core.c int slim_register_controller(struct slim_controller *ctrl) · line 463

Quoted 6 lines · Sagar Dharia
drivers/slimbus/slim-core.c +2 -0
@@ -459,6 +459,8 @@ int slim_register_controller(struct slim_controller *ctrl)
 	mutex_init(&ctrl->m_ctrl);
 	spin_lock_init(&ctrl->tx.lock);
 	spin_lock_init(&ctrl->rx.lock);
+	mutex_init(&ctrl->sched.m_reconf);
+	init_completion(&ctrl->sched.pause_comp);

Should there not be more interaction with the rest of the framework on clock pauses - the bus will need to be started to do transfers for example?

Review int slim_register_controller(struct slim_controller *ctrl) · line 465

Quoted 2 lines
(quoted diff) +2 -0
+#include <linux/slimbus.h>
+/**

Missing blank line.

Review int slim_register_controller(struct slim_controller *ctrl) · line 466

Quoted 1 line
(quoted diff) +1 -0
+ * slim_ctrl_clk_pause: Called by slimbus controller to enter/exit 'clock pause'

Is the controller the best place to initiate bus pausing? It's surprising to me that it would be, the bus being idle isn't something that needs controller specific knowledge so I'd expect the framework to have standard support for this.

#15 lore raw

Re: [PATCH V3 5/6] slimbus: Add support for 'clock-pause' feature

Hi Mark,

Quoted 11 lines · Mark Brown

drivers/slimbus/slim-core.c int slim_register_controller(struct slim_controller *ctrl) · line 463

Quoted 6 lines · Sagar Dharia
drivers/slimbus/slim-core.c +2 -0
@@ -459,6 +459,8 @@ int slim_register_controller(struct slim_controller *ctrl)
  	mutex_init(&ctrl->m_ctrl);
  	spin_lock_init(&ctrl->tx.lock);
  	spin_lock_init(&ctrl->rx.lock);
+	mutex_init(&ctrl->sched.m_reconf);
+	init_completion(&ctrl->sched.pause_comp);

Should there not be more interaction with the rest of the framework on clock pauses - the bus will need to be started to do transfers for example?

I'm relying on controller's pm_runtime as you pointed out for entering/exiting clock-pause.
The reason to initiate clock-pause from controller was more on the lines of clock-pause sequence being expensive, and tight coupling between controller/framer-clocks and clock-pause. Three reconfiguration-transfer-commands have to be broadcast on the lines to enter clock-pause, and exiting it is needs 'wakeup' callback for controller.
Doing this per transfer will be a big overhead.
Using pm_runtime's autosuspend feature allows the controller-device to enter clock-pause after periods of inactivity to avoid thrashing.
As a trade-off, I am proposing that controller should initiate clock-pause from its pm_runtime callbacks, and framework should provide the means to do it.
Also, typically clocks of the controller are coupled with clock-pause and clocks cannot be turned off until the clock-pause sequence is sent on the bus since framer has to keep clocking the bus.

Thanks
Sagar

Quoted 10 lines

Review int slim_register_controller(struct slim_controller *ctrl) · line 465

Quoted 3 lines
(quoted diff) +2 -0
+#include <linux/slimbus.h>
+/**

Missing blank line.

Review int slim_register_controller(struct slim_controller *ctrl) · line 466

Quoted 1 line
(quoted diff) +1 -0
+ * slim_ctrl_clk_pause: Called by slimbus controller to enter/exit 'clock pause'

Is the controller the best place to initiate bus pausing? It's surprising to me that it would be, the bus being idle isn't something that needs controller specific knowledge so I'd expect the framework to have standard support for this.

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

PATCH v3 6/6 slim: qcom: Add runtime-pm support using clock-pause feature

In reply to Sagar Dharia

Slimbus HW mandates that clock-pause sequence has to be executed before disabling relevant interface and core clocks. Runtime-PM's autosuspend feature is used here to enter/exit low power mode for Qualcomm's Slimbus controller. Autosuspend feature enables driver to avoid changing power-modes too frequently since entering clock-pause is an expensive sequence

---
 drivers/slimbus/slim-qcom-ctrl.c | 149 ++++++++++++++++++++++++++++++++++++++-
 drivers/slimbus/slim-qcom.h      |   1 +
 2 files changed, 149 insertions(+), 1 deletion(-)
drivers/slimbus/slim-qcom-ctrl.c +148 -1
index 7ff0536..45023a6 100644
@@ -20,6 +20,7 @@
 #include <linux/clk.h>
 #include <linux/of.h>
 #include <linux/slimbus.h>
+#include <linux/pm_runtime.h>
 #include "slim-qcom.h"
 
 #define MSM_SLIM_NAME	"msm_slim_ctrl"
@@ -210,6 +211,7 @@ rx_ret_irq:
 		if (q_rx)
 			queue_work(dev->rxwq, &dev->wd);
 	}
+	pm_runtime_mark_last_busy(dev->dev);
 	/**
 	 * All interrupts are handled: complex RX messages requiring more work
 	 * are queued to work-queue, others are handled above
@@ -237,6 +239,28 @@ static void msm_slim_wait_retry(struct msm_slim_ctrl *dev)
 	msleep(msec_per_frm);
 }
 
+static int msm_clk_pause_wakeup(struct slim_controller *ctrl)
+{
+	struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
+
+	clk_prepare_enable(dev->hclk);
+	clk_prepare_enable(dev->rclk);
+	writel_relaxed(1, dev->base + FRM_WAKEUP);
+	/* Make sure framer wakeup write goes through before ISR fires */
+	mb();
+	/**
+	 * HW Workaround: Currently, slave is reporting lost-sync messages
+	 * after slimbus comes out of clock pause.
+	 * Transaction with slave fail before slave reports that message
+	 * Give some time for that report to come
+	 * Slimbus wakes up in clock gear 10 at 24.576MHz. With each superframe
+	 * being 250 usecs, we wait for 5-10 superframes here to ensure
+	 * we get the message
+	 */
+	usleep_range(1250, 2500);
+	return 0;
+}
+
 static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn,
 			void *pbuf)
 {
@@ -245,6 +269,22 @@ static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn,
 	u32 *head = (u32 *)pbuf;
 	u8 *puc = (u8 *)pbuf;
 	u8 la = txn->la;
+	enum slim_clk_state cur_clk_state = ctrl->sched.clk_state;
+
+	if (cur_clk_state == SLIM_CLK_ENTERING_PAUSE) {
+		if (txn->mc != SLIM_MSG_MC_BEGIN_RECONFIGURATION &&
+		    txn->mc != SLIM_MSG_MC_RECONFIGURE_NOW &&
+		    txn->mc != SLIM_MSG_MC_NEXT_PAUSE_CLOCK)
+			return -EBUSY;
+	} else {
+		int ret = pm_runtime_get_sync(dev->dev);
+
+		if (ret < 0) {
+			pm_runtime_set_suspended(dev->dev);
+			dev_err(dev->dev, "runtime-pm vote failed:%d\n", ret);
+			return ret;
+		}
+	}
 
 	/* HW expects length field to be excluded */
 	txn->rl--;
@@ -273,6 +313,9 @@ static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn,
 	if (txn->msg && txn->msg->wbuf)
 		memcpy(puc, txn->msg->wbuf, txn->msg->num_bytes);
 
+	if (cur_clk_state != SLIM_CLK_ENTERING_PAUSE)
+		pm_runtime_put(dev->dev);
+
 	return msm_slim_queue_tx(dev, head, txn->rl, MGR_TX_MSG);
 }
 
@@ -296,13 +339,19 @@ static int msm_set_laddr(struct slim_controller *ctrl,
 	buf[5] = ead->instance;
 	/* Logical address for this EA */
 	buf[6] = laddr;
+
+	ret = pm_runtime_get_sync(dev->dev);
+	if (ret < 0) {
+		pm_runtime_set_suspended(dev->dev);
+		dev_err(dev->dev, "runtime-pm vote failed:%d\n", ret);
+		return ret;
+	}
 	/**
 	 * Retries are needed since bus may lose sync when multiple devices
 	 * are coming up and reporting present
 	 */
 	msg.wbuf = buf;
 	msg.num_bytes = 7;
-
 retry_laddr:
 	ret = slim_processtxn(&dev->ctrl, &txn);
 
@@ -317,6 +366,7 @@ retry_laddr:
 			dev_err(dev->dev, "set LADDR failed:ret:%d\n", ret);
 		}
 	}
+	pm_runtime_put(dev->dev);
 	return ret;
 }
 
@@ -444,6 +494,8 @@ static int msm_slim_probe(struct platform_device *pdev)
 
 	dev->ctrl.set_laddr = msm_set_laddr;
 	dev->ctrl.xfer_msg = msm_xfer_msg;
+	dev->ctrl.wakeup =  msm_clk_pause_wakeup;
+
 	dev->ctrl.tx.n = MSM_TX_MSGS;
 	dev->ctrl.rx.n = MSM_RX_MSGS;
 	dev->ctrl.tx.sl_sz = SLIM_MSGQ_BUF_LEN;
@@ -541,6 +593,12 @@ static int msm_slim_probe(struct platform_device *pdev)
 	 */
 	mb();
 
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, MSM_SLIM_AUTOSUSPEND);
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_mark_last_busy(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
 	dev_dbg(dev->dev, "MSM SB controller is up:ver:0x%x!\n", dev->ver);
 	return 0;
 
@@ -558,11 +616,99 @@ static int msm_slim_remove(struct platform_device *pdev)
 {
 	struct msm_slim_ctrl *dev = platform_get_drvdata(pdev);
 
+	pm_runtime_disable(&pdev->dev);
 	slim_del_controller(&dev->ctrl);
 	destroy_workqueue(dev->rxwq);
 	return 0;
 }
 
+/**
+ * If PM_RUNTIME is not defined, these 2 functions become helper
+ * functions to be called from system suspend/resume.
+ */
+#ifdef CONFIG_PM
+static int msm_slim_runtime_suspend(struct device *device)
+{
+	struct platform_device *pdev = to_platform_device(device);
+	struct msm_slim_ctrl *dev = platform_get_drvdata(pdev);
+	int ret;
+
+	dev_dbg(device, "pm_runtime: suspending...\n");
+	ret = slim_ctrl_clk_pause(&dev->ctrl, false, SLIM_CLK_UNSPECIFIED);
+	if (ret)
+		dev_err(device, "clk pause not entered:%d", ret);
+	else {
+		clk_disable_unprepare(dev->hclk);
+		clk_disable_unprepare(dev->rclk);
+	}
+	return ret;
+}
+
+static int msm_slim_runtime_resume(struct device *device)
+{
+	struct platform_device *pdev = to_platform_device(device);
+	struct msm_slim_ctrl *dev = platform_get_drvdata(pdev);
+	int ret = 0;
+
+	dev_dbg(device, "pm_runtime: resuming...\n");
+	ret = slim_ctrl_clk_pause(&dev->ctrl, true, 0);
+	if (ret)
+		dev_err(device, "clk pause not exited:%d", ret);
+	return ret;
+}
+#endif
+
+#ifdef CONFIG_PM_SLEEP
+static int msm_slim_suspend(struct device *dev)
+{
+	int ret = 0;
+
+	if (!pm_runtime_enabled(dev) ||
+		(!pm_runtime_suspended(dev))) {
+		dev_dbg(dev, "system suspend");
+		ret = msm_slim_runtime_suspend(dev);
+	}
+	if (ret == -EISCONN) {
+		/**
+		* If the clock pause failed due to active channels, there is
+		* a possibility that some audio stream is active during suspend
+		* We dont want to return suspend failure in that case so that
+		* display and relevant components can still go to suspend.
+		* If there is some other error, then it should prevent
+		* system level suspend
+		*/
+		ret = 0;
+	}
+	return ret;
+}
+
+static int msm_slim_resume(struct device *dev)
+{
+	if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) {
+		int ret;
+
+		dev_dbg(dev, "system resume");
+		ret = msm_slim_runtime_resume(dev);
+		if (!ret) {
+			pm_runtime_mark_last_busy(dev);
+			pm_request_autosuspend(dev);
+		}
+		return ret;
+
+	}
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static const struct dev_pm_ops msm_slim_dev_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(msm_slim_suspend, msm_slim_resume)
+	SET_RUNTIME_PM_OPS(
+			   msm_slim_runtime_suspend,
+			   msm_slim_runtime_resume,
+			   NULL
+	)
+};
+
 static const struct of_device_id msm_slim_dt_match[] = {
 	{
 		.compatible = "qcom,slim-msm",
@@ -577,6 +723,7 @@ static struct platform_driver msm_slim_driver = {
 		.name = MSM_SLIM_NAME,
 		.owner = THIS_MODULE,
 		.of_match_table = msm_slim_dt_match,
+		.pm = &msm_slim_dev_pm_ops,
 	},
 };
 module_platform_driver(msm_slim_driver);
drivers/slimbus/slim-qcom.h +1 -0
index 115a8b8..b678c3a 100644
@@ -25,6 +25,7 @@
 #define SLIM_ROOT_FREQ 24576000
 #define INIT_MX_RETRIES 10
 #define DEF_RETRY_MS	10
+#define MSM_SLIM_AUTOSUSPEND 1000
 
 /* MAX message size over control channel */
 #define SLIM_MSGQ_BUF_LEN	40
Signature · 1 line
1.8.2.1
#17 lore raw

Re: [PATCH V3 6/6] slim: qcom: Add runtime-pm support using clock-pause feature

drivers/slimbus/slim-qcom-ctrl.c static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn, · line 282

Quoted 9 lines · Sagar Dharia
drivers/slimbus/slim-qcom-ctrl.c +9 -0
+	if (cur_clk_state == SLIM_CLK_ENTERING_PAUSE) {
+		if (txn->mc != SLIM_MSG_MC_BEGIN_RECONFIGURATION &&
+		    txn->mc != SLIM_MSG_MC_RECONFIGURE_NOW &&
+		    txn->mc != SLIM_MSG_MC_NEXT_PAUSE_CLOCK)
+			return -EBUSY;
+	} else {
+		int ret = pm_runtime_get_sync(dev->dev);
+
+		if (ret < 0) {

This is taking a runtime PM reference whenever we're about to start a transfer - this is the sort of thing I was talking about expecting the framework to do rather than individual drivers.

drivers/slimbus/slim-qcom-ctrl.c static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn, · line 285

Quoted 3 lines
drivers/slimbus/slim-qcom-ctrl.c +3 -0
+			pm_runtime_set_suspended(dev->dev);
+			dev_err(dev->dev, "runtime-pm vote failed:%d\n", ret);
+			return ret;

If the get failed there should be no need to suspend the device, the get() should leave us in a sensible state...

Quoted 8 lines
drivers/slimbus/slim-qcom-ctrl.c +8 -0
+static int msm_slim_suspend(struct device *dev)
+{
+	int ret = 0;
+
+	if (!pm_runtime_enabled(dev) ||
+		(!pm_runtime_suspended(dev))) {
+		dev_dbg(dev, "system suspend");
+		ret = msm_slim_runtime_suspend(dev);

drivers/slimbus/slim-qcom-ctrl.c static int msm_slim_remove(struct platform_device *pdev) · line 679

Quoted 10 lines
drivers/slimbus/slim-qcom-ctrl.c +10 -0
+	}
+	if (ret == -EISCONN) {
+		/**
+		* If the clock pause failed due to active channels, there is
+		* a possibility that some audio stream is active during suspend
+		* We dont want to return suspend failure in that case so that
+		* display and relevant components can still go to suspend.
+		* If there is some other error, then it should prevent
+		* system level suspend
+		*/

Best mention that this is for the modem use case for Android's suspend model since it's really surprising to see.

#18 lore raw
In reply to Sagar Dharia
Quoted 7 lines · Sagar Dharia

Sagar Dharia (6):
SLIMbus: Device management on SLIMbus
of/slimbus: OF helper for SLIMbus
slimbus: Add messaging APIs to slimbus framework
slim: qcom: Add Qualcomm Slimbus controller driver
slimbus: Add support for 'clock-pause' feature
slim: qcom: Add runtime-pm support using clock-pause feature

This looks pretty good overall but I did have a few fairly specific comments that I've sent on some bits. I see there are a number of users of this API onn the CC list, it'd be really nice to see some more participation from them on the review here - are you using this code, do you have testing reports or any more specific comments on the code?