Skip to contentSkip to conversation

Introduce framework for SLIMbus device drivers

PATCH Superseded Sagar Dharia 5 participants 16 messages Jun 17, 2015 – Jun 28, 2015

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce framework for SLIMbus device drivers

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.
Framework is introduced to support multiple instances of the bus (1 controller per bus), and multiple slave devices per controller. SPI and I2C frameworks, and comments from last time when I submitted the patches were referred-to while working on this framework.

These patchsets introduce device-management, OF helpers, and messaging APIs, and clock-pause feature for entering/exiting low-power mode for SLIMbus. Framework patches to do channel, port and bandwidth management are work-in-progress and will be sent out soon.

These patchsets were tested on Qualcomm Snapdragon processor board using a controller driver.

Changes from V1 to V2:
* Addressed inline-code review comments from Joe and Mark Brown.
* Added initial binding document for slimbus
* Added initial version of Qualcomm controller driver and initial binding document for it.
* Added clock-pause feature for entering/exiting low power mode
* Added runtime-pm to Qualcomm controller driver

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  |   34 +
 .../devicetree/bindings/slimbus/slim-qcom-ctrl.txt |   45 +
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    1 +
 drivers/slimbus/Kconfig                            |   19 +
 drivers/slimbus/Makefile                           |    6 +
 drivers/slimbus/slim-qcom-ctrl.c                   |  852 ++++++++++++++
 drivers/slimbus/slim-qcom.c                        |   96 ++
 drivers/slimbus/slim-qcom.h                        |   90 ++
 drivers/slimbus/slimbus.c                          | 1174 ++++++++++++++++++++
 include/linux/mod_devicetable.h                    |   13 +
 include/linux/slimbus.h                            |  589 ++++++++++
 12 files changed, 2921 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-qcom-ctrl.c
 create mode 100644 drivers/slimbus/slim-qcom.c
 create mode 100644 drivers/slimbus/slim-qcom.h
 create mode 100644 drivers/slimbus/slimbus.c
 create mode 100644 include/linux/slimbus.h
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v2 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.

---
 drivers/Kconfig                 |   2 +
 drivers/Makefile                |   1 +
 drivers/slimbus/Kconfig         |   9 +
 drivers/slimbus/Makefile        |   4 +
 drivers/slimbus/slimbus.c       | 714 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mod_devicetable.h |  13 +
 include/linux/slimbus.h         | 396 ++++++++++++++++++++++
 7 files changed, 1139 insertions(+)
 create mode 100644 drivers/slimbus/Kconfig
 create mode 100644 drivers/slimbus/Makefile
 create mode 100644 drivers/slimbus/slimbus.c
 create mode 100644 include/linux/slimbus.h
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 +9 -0
new file mode 100644
index 0000000..fb30497
@@ -0,0 +1,9 @@
+#
+# SLIMBUS driver configuration
+#
+menuconfig SLIMBUS
+	tristate "Slimbus support"
+	help
+	  Slimbus is standard interface between baseband and audio codec,
+	  and other peripheral components in mobile terminals.
+
drivers/slimbus/Makefile new file +4 -0
new file mode 100644
index 0000000..05f53bc
@@ -0,0 +1,4 @@
+#
+# Makefile for kernel slimbus framework.
+#
+obj-$(CONFIG_SLIMBUS)			+= slimbus.o
drivers/slimbus/slimbus.c new file +714 -0

714 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 +396 -0

396 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#2 lore raw

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

Quoted 4 lines · Sagar Dharia

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.

[]

drivers/slimbus/slimbus.c

Quoted 1 line
drivers/slimbus/slimbus.c +0 -0

[]

Quoted 24 lines
drivers/slimbus/slimbus.c +24 -0
+static bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b)
+{
+	return (a->manf_id == b->manf_id &&
+		a->prod_code == b->prod_code &&
+		a->dev_index == b->dev_index &&
+		a->instance == b->instance);
+}
+
+static const struct slim_device_id *
+slim_match(const struct slim_device_id *id, const struct slim_device *slim_dev)
+{
+	while (id->manf_id != 0 || id->prod_code != 0) {
+		if (id->manf_id == slim_dev->e_addr.manf_id &&
+		    id->prod_code == slim_dev->e_addr.prod_code &&
+		    id->dev_index == slim_dev->e_addr.dev_index)
+			return id;
+		id++;
+	}
+	return NULL;
+}
+
+static int slim_device_match(struct device *dev, struct device_driver *driver)
+{
+	struct slim_device *slim_dev;

drivers/slimbus/slimbus.c line 61

Quoted 10 lines
drivers/slimbus/slimbus.c +10 -0
+	struct slim_driver *drv = to_slim_driver(driver);
+
+	if (dev->type != &slim_dev_type)
+		return 0;
+
+	slim_dev = to_slim_device(dev);
+	if (drv->id_table)
+		return slim_match(drv->id_table, slim_dev) != NULL;
+	return 0;
+}

This should probably be a bool function return.

Maybe this:

static bool slim_device_match(struct device *dev, struct device_driver *driver)

{
	struct slim_driver *drv = to_slim_driver(driver);

	if (dev->type != &slim_dev_type || !drv->id_table)
		return false;

	return slim_match(drv->id_table, to_slim_device(dev));
}
#3 lore raw

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

In reply to Sagar Dharia

drivers/slimbus/slimbus.c line 87

Quoted 6 lines · Sagar Dharia
drivers/slimbus/slimbus.c new file +6 -0
+	if (status) {
+		slim_dev->driver = NULL;
+	} else if (driver->device_up) {
+		ctrl = slim_dev->ctrl;
+		queue_work(ctrl->wq, &slim_dev->wd);
+	}

Nothing ever cleans this work up if it didn't manage to run or complete.

drivers/slimbus/slimbus.c line 207

Quoted 7 lines
drivers/slimbus/slimbus.c new file +7 -0
+static void slim_report(struct work_struct *work)
+{
+	struct slim_driver *sbdrv;
+	struct slim_device *sbdev = container_of(work, struct slim_device, wd);
+
+	if (!sbdev->dev.driver)
+		return;

So we just forget about the device if we don't have a driver for it?

drivers/slimbus/slimbus.c line 211

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+	/* check if device-up or down needs to be called */
+	if ((!sbdev->reported && !sbdev->notified) ||
+	    (sbdev->reported && sbdev->notified))
+		return;

No locking here?

drivers/slimbus/slimbus.c line 325

Quoted 8 lines
drivers/slimbus/slimbus.c new file +8 -0
+/**
+ * slim_ctrl_add_boarddevs: Add devices registered by board-info
+ * @ctrl: Controller to which these devices are to be added to.
+ * This API is called by controller when it is up and running.
+ * If devices on a controller were registered before controller,
+ * this will make sure that they get probed when controller is up.
+ */
+void slim_ctrl_add_boarddevs(struct slim_controller *ctrl)

My concerns about the split here still remain.

#4 lore raw

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

Quoted 11 lines · Mark Brown

drivers/slimbus/slimbus.c line 87

Quoted 6 lines · Sagar Dharia
drivers/slimbus/slimbus.c new file +6 -0
+	if (status) {
+		slim_dev->driver = NULL;
+	} else if (driver->device_up) {
+		ctrl = slim_dev->ctrl;
+		queue_work(ctrl->wq, &slim_dev->wd);
+	}

Nothing ever cleans this work up if it didn't manage to run or complete.

Quoted 8 lines

drivers/slimbus/slimbus.c line 207

Quoted 7 lines
drivers/slimbus/slimbus.c new file +7 -0
+static void slim_report(struct work_struct *work)
+{
+	struct slim_driver *sbdrv;
+	struct slim_device *sbdev = container_of(work, struct slim_device, wd);
+
+	if (!sbdev->dev.driver)
+		return;

So we just forget about the device if we don't have a driver for it?

If device comes up before driver (e.g. dynamic module driver, or late-init driver), then to begin with: this doesn't do anything. But once the driver-binding happens and probe succeeds, we queue device_up again.

Quoted 6 lines

drivers/slimbus/slimbus.c line 211

Quoted 5 lines
drivers/slimbus/slimbus.c new file +4 -0
+	/* check if device-up or down needs to be called */
+	if ((!sbdev->reported && !sbdev->notified) ||
+	    (sbdev->reported && sbdev->notified))
+		return;

No locking here?

You are right, first I thought this was only touched in workqueue (singlethreaded), but this is also touched from logical-address assignment, driver removal etc. I will add device-level lock for these.
Thanks
Sagar

Quoted 10 lines

drivers/slimbus/slimbus.c line 325

Quoted 9 lines
drivers/slimbus/slimbus.c new file +8 -0
+/**
+ * slim_ctrl_add_boarddevs: Add devices registered by board-info
+ * @ctrl: Controller to which these devices are to be added to.
+ * This API is called by controller when it is up and running.
+ * If devices on a controller were registered before controller,
+ * this will make sure that they get probed when controller is up.
+ */
+void slim_ctrl_add_boarddevs(struct slim_controller *ctrl)

My concerns about the split here still remain.

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

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

In reply to Sagar Dharia
Quoted 20 lines · Sagar Dharia

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.

Quoted 1 line

I think I was not as fast as you sent the v2 :-)
However my comments on v1 patcset mostly still applies to v2 as well.

--srini

#6 lore raw

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

In reply to Sagar Dharia

drivers/slimbus/Kconfig line 8

Quoted 11 lines · Sagar Dharia
drivers/slimbus/Kconfig new file +8 -0
@@ -0,0 +1,9 @@
+#
+# SLIMBUS driver configuration
+#
+menuconfig SLIMBUS
+	tristate "Slimbus support"
+	help
+	  Slimbus is standard interface between baseband and audio codec,
+	  and other peripheral components in mobile terminals.

Perhaps this is a fussy comment but this description of slimbus makes pretty heavy use of mobile phone jargon. Admittedly it is jargon from the slimbus spec which, as standards go, seems rather myopic about its potential user base.

However, even the standards own self-description doesn't limit its role to baseband <-> peripherals. What happened to the application processor/main-SoC?

Also would an "If unsure, choose N." be useful? It could be quite a long time before someone who doesn't know they need slimbus actually finds that they do.

Daniel.

#7 lore raw

PATCH v2 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 | 34 ++++++++++
 drivers/slimbus/slimbus.c                         | 76 +++++++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
Documentation/devicetree/bindings/slimbus/bus.txt new file +34 -0
new file mode 100644
index 0000000..a7a36aa
@@ -0,0 +1,34 @@
+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.
+
+Required property for SLIMbus controller node:
+- compatible	- name of SLIMbus controller.
+
+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:
+enumeration-addr	- 6 byte enumeration address of the slave
+
+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 {
+			enumeration-addr = [00 01 60 00 17 02];
+		};
+	};
drivers/slimbus/slimbus.c +76 -0

94 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#8 lore raw

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

Quoted 2 lines · Sagar Dharia

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

You've not CCed any of the DT maintainers on this, for a completely new bus it seems like we really ought to get their input.

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

Quoted 10 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +9 -0
@@ -0,0 +1,34 @@
+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.
+
+Required property for SLIMbus controller node:
+- compatible	- name of SLIMbus controller.
+
+No other properties are required in the SLIMbus controller bus node.

It seems better to just say that the controller is a normal device using the binding for whatever bus it is on and that the binding is for the bus which is a child node of the controller device? Also, do we need #address-cells or #size-cells here?

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

Quoted 2 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +2 -0
+Required property for SLIMbus child node:
+enumeration-addr	- 6 byte enumeration address of the slave

The idiom for DT seems to be that we define the bus address using the reg property. Should we not be following that pattern here too? I'd also expect to see the ability to define a compatible for the slaves.

#9 lore raw

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

Quoted 5 lines · Mark Brown
Quoted 2 lines · Sagar Dharia

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

You've not CCed any of the DT maintainers on this, for a completely new bus it seems like we really ought to get their input.

Will do.

Quoted 15 lines

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

Quoted 11 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +9 -0
@@ -0,0 +1,34 @@
+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.
+
+Required property for SLIMbus controller node:
+- compatible	- name of SLIMbus controller.
+
+No other properties are required in the SLIMbus controller bus node.

It seems better to just say that the controller is a normal device using the binding for whatever bus it is on and that the binding is for the bus which is a child node of the controller device? Also, do we need #address-cells or #size-cells here?

It will be required if we use 'reg' property for enumeration address per my understanding (address-cells: 6, size-cells: 0) I thought about using 'reg' and it seemed to work as well. Only reason for using 'enumeration-addr' was to be closer to what HW calls it. Looking at other device-trees, (that 'reg' was used for other buses to represent slave address), I will document the 'reg' property and document it. Thanks
Sagar

Quoted 6 lines

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

Quoted 3 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +2 -0
+Required property for SLIMbus child node:
+enumeration-addr	- 6 byte enumeration address of the slave

The idiom for DT seems to be that we define the bus address using the reg property. Should we not be following that pattern here too? I'd also expect to see the ability to define a compatible for the slaves.

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

PATCH v2 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 can be called from atomic context.

---
 drivers/slimbus/slimbus.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/slimbus.h   | 128 +++++++++++++++++++++
 2 files changed, 403 insertions(+)
drivers/slimbus/slimbus.c +275 -0
index 0295a06..d74dfec 100644
@@ -26,6 +26,14 @@ static DEFINE_IDR(ctrl_idr);
 static struct device_type slim_dev_type;
 static struct device_type slim_ctrl_type;
 
+#define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) \
+	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_LOGICALADDR, 0,\
+					0, la, msg, }
+
+#define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) \
+	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_BROADCAST, 0,\
+					0, la, msg, }
+
 static bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b)
 {
 	return (a->manf_id == b->manf_id &&
@@ -784,6 +792,273 @@ int slim_get_logical_addr(struct slim_device *sb, struct slim_eaddr *e_addr,
 }
 EXPORT_SYMBOL(slim_get_logical_addr);
 
+/**
+ * slim_msg_response: Deliver Message response received from a device to the
+ *	framework.
+ * @ctrl: Controller handle
+ * @reply: Reply received from the device
+ * @len: Length of the reply
+ * @tid: Transaction ID received with which framework can associate reply.
+ * Called by controller to inform framework about the response received.
+ * This helps in making the API asynchronous, and controller-driver doesn't need
+ * to manage 1 more table other than the one managed by framework mapping TID
+ * with buffers
+ */
+void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len)
+{
+	struct slim_val_inf *msg;
+
+	spin_lock(&ctrl->txn_lock);
+	msg = ctrl->txnt[tid];
+	if (msg == NULL || msg->rbuf == NULL) {
+		spin_unlock(&ctrl->txn_lock);
+		dev_err(&ctrl->dev, "Got response to invalid TID:%d, len:%d\n",
+				tid, len);
+		return;
+	}
+	memcpy(msg->rbuf, reply, len);
+	ctrl->txnt[tid] = NULL;
+	if (msg->comp_cb)
+		msg->comp_cb(msg->ctx, 0);
+	spin_unlock(&ctrl->txn_lock);
+}
+EXPORT_SYMBOL(slim_msg_response);
+
+static int slim_processtxn(struct slim_controller *ctrl,
+				struct slim_msg_txn *txn)
+{
+	int i = 0;
+	unsigned long flags;
+
+	if (slim_tid_txn(txn->mt, txn->mc)) {
+		spin_lock_irqsave(&ctrl->txn_lock, flags);
+		for (i = 0; i < ctrl->last_tid; i++) {
+			if (ctrl->txnt[i] == NULL)
+				break;
+		}
+		if (i >= ctrl->last_tid) {
+			if (ctrl->last_tid == 255) {
+				spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+				return -ENOMEM;
+			}
+			ctrl->last_tid++;
+		}
+		ctrl->txnt[i] = txn->msg;
+		txn->tid = i;
+		spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+	}
+
+	return ctrl->xfer_msg(ctrl, txn);
+}
+
+static int slim_val_inf_sanity(struct slim_controller *ctrl,
+			       struct slim_val_inf *msg, u8 mc)
+{
+	if (!msg || msg->num_bytes > 16 ||
+	    (msg->start_offset + msg->num_bytes) > 0xC00)
+		goto reterr;
+	switch (mc) {
+	case SLIM_MSG_MC_REQUEST_VALUE:
+	case SLIM_MSG_MC_REQUEST_INFORMATION:
+		if (msg->rbuf != NULL)
+			return 0;
+		break;
+	case SLIM_MSG_MC_CHANGE_VALUE:
+	case SLIM_MSG_MC_CLEAR_INFORMATION:
+		if (msg->wbuf != NULL)
+			return 0;
+		break;
+	case SLIM_MSG_MC_REQUEST_CHANGE_VALUE:
+	case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION:
+		if (msg->rbuf != NULL && msg->wbuf != NULL)
+			return 0;
+		break;
+	default:
+		break;
+	}
+reterr:
+	dev_err(&ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n",
+		msg->start_offset, mc);
+	return -EINVAL;
+}
+
+static u16 slim_slicecodefromsize(u16 req)
+{
+	static const u8 codetosize[8] = {1, 2, 3, 4, 6, 8, 12, 16};
+
+	if (req >= ARRAY_SIZE(codetosize))
+		return 0;
+	else
+		return codetosize[req];
+}
+
+static u16 slim_slicesize(int code)
+{
+	static const u8 sizetocode[16] = {
+		0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7
+	};
+
+	clamp(code, 1, (int)ARRAY_SIZE(sizetocode));
+	return sizetocode[code - 1];
+}
+
+static void slim_sync_default_cb(void *ctx, int err)
+{
+	struct completion *comp = ctx;
+
+	complete(comp);
+}
+
+static int slim_xfer_msg(struct slim_controller *ctrl,
+			struct slim_device *sbdev, struct slim_val_inf *msg,
+			u8 mc)
+{
+	DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg);
+	struct slim_msg_txn *txn = &txn_stack;
+	int ret;
+	unsigned long flags;
+	u16 sl, cur;
+	bool tid_txn, async = false;
+	DECLARE_COMPLETION_ONSTACK(complete);
+
+	ret = slim_val_inf_sanity(ctrl, msg, mc);
+	if (ret)
+		return ret;
+
+	tid_txn = slim_tid_txn(txn->mt, txn->mc);
+
+	sl = slim_slicesize(msg->num_bytes);
+	dev_err(&ctrl->dev, "SB xfer msg:os:%x, len:%d, MC:%x, sl:%x\n",
+		msg->start_offset, msg->num_bytes, mc, sl);
+
+	cur = slim_slicecodefromsize(sl);
+	txn->ec = ((sl | (1 << 3)) | ((msg->start_offset & 0xFFF) << 4));
+
+	if (!msg->comp_cb && tid_txn) {
+		msg->comp_cb = slim_sync_default_cb;
+		msg->ctx = &complete;
+	} else {
+		async = true;
+	}
+
+	if (mc == SLIM_MSG_MC_REQUEST_CHANGE_VALUE ||
+		mc == SLIM_MSG_MC_CHANGE_VALUE ||
+		mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION ||
+		mc == SLIM_MSG_MC_CLEAR_INFORMATION)
+		txn->rl += msg->num_bytes;
+	if (tid_txn)
+		txn->rl++;
+
+	ret = slim_processtxn(ctrl, txn);
+
+	/* sync read */
+	if (!ret && tid_txn && !async) {
+		/* Fine-tune calculation after bandwidth management */
+		unsigned long ms = txn->rl + 100;
+
+		ret = wait_for_completion_timeout(&complete,
+						  msecs_to_jiffies(ms));
+		if (!ret)
+			ret = -ETIMEDOUT;
+		else
+			ret = 0;
+	}
+
+	if (ret && tid_txn) {
+		spin_lock_irqsave(&ctrl->txn_lock, flags);
+		/* Invalidate the transaction */
+		ctrl->txnt[txn->tid] = NULL;
+		spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+	}
+	if (ret)
+		dev_err(&ctrl->dev, "xfer err:%d:offset:0x%x, MC:%d\n", ret,
+			msg->start_offset, mc);
+	if (!async && tid_txn) {
+		msg->comp_cb = NULL;
+		msg->ctx = NULL;
+	}
+	return ret;
+}
+EXPORT_SYMBOL(slim_xfer_msg);
+
+/* Message APIs Unicast message APIs used by slimbus slave drivers */
+
+/*
+ * Message API access routines.
+ * @sb: client handle requesting elemental message reads, writes.
+ * @msg: Input structure for start-offset, number of bytes to read.
+ * context: can sleep
+ * Returns:
+ * -EINVAL: Invalid parameters
+ * -ETIMEDOUT: If controller could not complete the request. This may happen if
+ *  the bus lines are not clocked, controller is not powered-on, slave with
+ *  given address is not enumerated/responding.
+ */
+int slim_request_val_element(struct slim_device *sb,
+				struct slim_val_inf *msg)
+{
+	struct slim_controller *ctrl = sb->ctrl;
+
+	if (!ctrl)
+		return -EINVAL;
+	return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_REQUEST_VALUE);
+}
+EXPORT_SYMBOL(slim_request_val_element);
+
+int slim_request_inf_element(struct slim_device *sb,
+				struct slim_val_inf *msg)
+{
+	struct slim_controller *ctrl = sb->ctrl;
+
+	if (!ctrl)
+		return -EINVAL;
+	return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_REQUEST_INFORMATION);
+}
+EXPORT_SYMBOL(slim_request_inf_element);
+
+int slim_change_val_element(struct slim_device *sb, struct slim_val_inf *msg)
+{
+	struct slim_controller *ctrl = sb->ctrl;
+
+	if (!ctrl)
+		return -EINVAL;
+	return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_CHANGE_VALUE);
+}
+EXPORT_SYMBOL(slim_change_val_element);
+
+int slim_clear_inf_element(struct slim_device *sb, struct slim_val_inf *msg)
+{
+	struct slim_controller *ctrl = sb->ctrl;
+
+	if (!ctrl)
+		return -EINVAL;
+	return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_CLEAR_INFORMATION);
+}
+EXPORT_SYMBOL(slim_clear_inf_element);
+
+int slim_request_change_val_element(struct slim_device *sb,
+					struct slim_val_inf *msg)
+{
+	struct slim_controller *ctrl = sb->ctrl;
+
+	if (!ctrl)
+		return -EINVAL;
+	return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_REQUEST_CHANGE_VALUE);
+}
+EXPORT_SYMBOL(slim_request_change_val_element);
+
+int slim_request_clear_inf_element(struct slim_device *sb,
+					struct slim_val_inf *msg)
+{
+	struct slim_controller *ctrl = sb->ctrl;
+
+	if (!ctrl)
+		return -EINVAL;
+	return slim_xfer_msg(ctrl, sb, msg,
+					SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION);
+}
+EXPORT_SYMBOL(slim_request_clear_inf_element);
+
 MODULE_LICENSE("GPL v2");
 MODULE_VERSION("0.1");
 MODULE_DESCRIPTION("Slimbus module");
include/linux/slimbus.h +128 -0

163 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#11 lore raw

PATCH v2 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 |  45 ++
 drivers/slimbus/Kconfig                            |  10 +
 drivers/slimbus/Makefile                           |   2 +
 drivers/slimbus/slim-qcom-ctrl.c                   | 723 +++++++++++++++++++++
 drivers/slimbus/slim-qcom.c                        |  96 +++
 drivers/slimbus/slim-qcom.h                        |  89 +++
 6 files changed, 965 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.c
 create mode 100644 drivers/slimbus/slim-qcom.h
Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file +45 -0
new file mode 100644
index 0000000..25c9609
@@ -0,0 +1,45 @@
+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
+ - cell-index : SLIMBUS number used for this controller
+ - 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"
+ - dmaengine, and pipes used to communicate between controller and memory if
+	sps-BAM HW is used
+
+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 fb30497..ce988c2 100644
@@ -7,3 +7,13 @@ menuconfig SLIMBUS
 	  Slimbus is standard interface between baseband and audio codec,
 	  and other peripheral components in mobile terminals.
 
+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 +2 -0
index 05f53bc..efc3db4 100644
@@ -2,3 +2,5 @@
 # Makefile for kernel slimbus framework.
 #
 obj-$(CONFIG_SLIMBUS)			+= slimbus.o
+
+obj-$(CONFIG_SLIM_QCOM_CTRL)		+= slim-qcom.o slim-qcom-ctrl.o
drivers/slimbus/slim-qcom-ctrl.c new file +723 -0

723 lines not on this page · raw message

drivers/slimbus/slim-qcom.c new file +96 -0

96 lines not on this page · raw message

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

89 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#12 lore raw

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

Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt line 30

Quoted 2 lines · Sagar Dharia

+ - dmaengine, and pipes used to communicate between controller and memory if

Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file +1 -0
+	sps-BAM HW is used

This needs more detail.

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+		 */
+		mb();
+		if (notify_rx)
+			complete(&dev->rx_msgq_notify);
+	}
+	return IRQ_HANDLED;

This interrupt handler unconditionally returns IRQ_HANDLED regardless of if that's true or not.

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+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 212

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);
+}

Is this device specific?

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

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+static void msm_slim_cb(void *ctx, int err)
+{
+	if (err)
+		pr_err("MSM-slim completion reported err:%d\n", err);

dev_err()?

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

Quoted 3 lines
drivers/slimbus/slim-qcom-ctrl.c new file +3 -0
+	else if (ctx)
+		complete(ctx);
+}

That's weird, if we get an error we don't signal whatever's waiting - won't it just time out at best then? Also, what happens if we get neither an error nor context?

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

Quoted 13 lines
drivers/slimbus/slim-qcom-ctrl.c new file +13 -0
+	if (txn->msg->wbuf)
+		memcpy(puc, txn->msg->wbuf, txn->msg->num_bytes);
+	msm_slim_queue_tx(dev, pbuf, txn->rl, MGR_TX_MSG);
+	timeout = wait_for_completion_timeout(&done,
+					      msecs_to_jiffies(txn->rl + 100));
+
+	if (!timeout)
+		dev_err(dev->dev, "TX timed out:MC:0x%x,mt:0x%x\n", txn->mc,
+			txn->mt);
+
+	mutex_unlock(&dev->txn_lock);
+	return timeout ? 0 : -ETIMEDOUT;
+}

Shouldn't we provide a route for error reports here (and might some of this timeout stuff go into the core)?

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

Quoted 7 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+
+	if ((msm_slim_put_rx(dev, (u8 *)buf)) != -ENODATA) {
+		len = buf[0] & 0x1F;
+		mt = (buf[0] >> 5) & 0x7;
+		mc = buf[1];
+		if (mt == SLIM_MSG_MT_CORE &&
+			mc == SLIM_MSG_MC_REPORT_PRESENT) {

Looks like a switch statement.

Quoted 8 lines
drivers/slimbus/slim-qcom-ctrl.c new file +8 -0
+static int msm_slim_rx_msgq_thread(void *data)
+{
+	struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)data;
+	struct completion *notify = &dev->rx_msgq_notify;
+	int ret;
+
+	while (!kthread_should_stop()) {
+		set_current_state(TASK_INTERRUPTIBLE);

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

Quoted 10 lines
drivers/slimbus/slim-qcom-ctrl.c new file +10 -0
+		ret = wait_for_completion_interruptible(notify);
+
+		if (ret)
+			dev_err(dev->dev, "rx thread wait error:%d\n", ret);
+		else
+			msm_slim_rxwq(dev);
+	}
+
+	return 0;
+}

It's not entirely clear to me why this is a kthread rather than a workqueue or something. I'm also unclear what happens if more than one piece of work is queued prior to msm_slim_rxwq() running, it looks like it only handles a single operation.

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

Quoted 7 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+	/* SLEW RATE register for this slimbus */
+	dev->slew_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						"slimbus_slew_reg");
+	if (!dev->slew_mem) {
+		dev_err(&pdev->dev, "no slimbus slew resource\n");
+		return;
+	}

Warning not an error isn't it?

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

Quoted 3 lines
drivers/slimbus/slim-qcom-ctrl.c new file +3 -0
+	hclk = clk_get(&pdev->dev, "iface_clk");
+	if (IS_ERR(hclk))
+		return PTR_ERR(hclk);

devm_clk_get()

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

Quoted 1 line
drivers/slimbus/slim-qcom-ctrl.c new file +1 -0
+	ret = clk_set_rate(rclk, SLIM_ROOT_FREQ);

You're ignoring this error in spite of assigning to ret.

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+	slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						"slimbus_physical");
+	if (!slim_mem) {
+		dev_err(&pdev->dev, "no slimbus physical memory resource\n");

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

Quoted 10 lines
drivers/slimbus/slim-qcom-ctrl.c new file +10 -0
+		ret = ENODEV;
+		goto err_get_mem_failed;
+	}
+	slim_io = request_mem_region(slim_mem->start, resource_size(slim_mem),
+					pdev->name);
+	if (!slim_io) {
+		dev_err(&pdev->dev, "slimbus memory already claimed\n");
+		ret = EBUSY;
+		goto err_get_mem_failed;
+	}

devm_ioremap_resource() and a lot of this starts looking simpler.

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

Quoted 1 line
drivers/slimbus/slim-qcom-ctrl.c new file +1 -0
+	dev = kzalloc(sizeof(struct msm_slim_ctrl), GFP_KERNEL);

devm_kzalloc()

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

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+	if (pdev->dev.of_node) {
+
+		ret = of_property_read_u32(pdev->dev.of_node, "cell-index",
+					&dev->ctrl.nr);

Was that in the binding?

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+	/* Register with framework before enabling frame, clock */
+	ret = slim_add_numbered_controller(&dev->ctrl);
+	if (ret) {
+		dev_err(dev->dev, "error adding controller\n");
+		goto err_ctrl_failed;
+	}

This is suspicious - why are you adding a numbered controller with DT? And looking at this interface why is it a separate call to add a numbered controller, why not just register the controller using the same API and handle any number that was set when doing that?

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

Quoted 7 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+	dev->ver = readl_relaxed(dev->base);
+	/* Version info in 16 MSbits */
+	dev->ver >>= 16;
+	/* Component register initialization */
+	writel_relaxed(1, dev->base + CFG_PORT(COMP_CFG, dev->ver));
+	writel_relaxed((EE_MGR_RSC_GRP | EE_NGD_2 | EE_NGD_1),
+				dev->base + CFG_PORT(COMP_TRUST_CFG, dev->ver));

You've registered the device with the core prior to initialising the hardware - I'd expect this means the generic code will start trying to register slaves immediately. The normal pattern would be to initialise the hardware then register it.

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

Quoted 11 lines
drivers/slimbus/slim-qcom-ctrl.c new file +11 -0
+#ifdef CONFIG_PM_SLEEP
+static int msm_slim_suspend(struct device *dev)
+{
+	return 0;
+}
+
+static int msm_slim_resume(struct device *dev)
+{
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */

Omit empty functions.

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

Quoted 5 lines
drivers/slimbus/slim-qcom-ctrl.c new file +5 -0
+static int msm_slim_init(void)
+{
+	return platform_driver_register(&msm_slim_driver);
+}
+module_init(msm_slim_init);

module_platform_driver().

Quoted 6 lines
drivers/slimbus/slim-qcom.c new file +6 -0
+u8 *msm_slim_get_tx(struct msm_slim_ctrl *dev, struct msm_wr_cb *cur)
+{
+	unsigned long flags;
+	int idx;
+
+	spin_lock_irqsave(&dev->tx.lock, flags);

drivers/slimbus/slim-qcom.c line 96

Quoted 10 lines
drivers/slimbus/slim-qcom.c new file +10 -0
+	if (((dev->tx.head + 1) % MSM_TX_MSGS) == dev->tx.tail) {
+		spin_unlock_irqrestore(&dev->tx.lock, flags);
+		return NULL;
+	}
+	idx = dev->tx.tail;
+	dev->tx.tail = (dev->tx.tail + 1) % MSM_TX_MSGS;
+	spin_unlock_irqrestore(&dev->tx.lock, flags);
+	dev->pending_wr[idx] = cur;
+	return dev->tx.base + (idx * SLIM_MSGQ_BUF_LEN);
+}

Would just using a regular list hurt?

#13 lore raw

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

Quoted 5 lines · Mark Brown

Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt line 30

Quoted 2 lines · Sagar Dharia

+ - dmaengine, and pipes used to communicate between controller and memory if

Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file +1 -0
+	sps-BAM HW is used

This needs more detail.

Quoted 8 lines

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+		 */
+		mb();
+		if (notify_rx)
+			complete(&dev->rx_msgq_notify);
+	}
+	return IRQ_HANDLED;

This interrupt handler unconditionally returns IRQ_HANDLED regardless of if that's true or not.

Some interrupt handling is done in ISR itself. RX-msgq thread notifier/workQ is only used for items that can sleep/operations that can take longer. (e.g. assignment of logical address based on report_present message) That's the reason IRQ_HANDLED is always true here.

Quoted 16 lines
Quoted 5 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+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 212

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);
+}

Is this device specific?

This is seen on most of the Qualcomm-controllers I've worked with, where retries in early initialization were needed to avoid issues due to noise.

Quoted 14 lines

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

Quoted 5 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+static void msm_slim_cb(void *ctx, int err)
+{
+	if (err)
+		pr_err("MSM-slim completion reported err:%d\n", err);

dev_err()?

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

Quoted 3 lines
drivers/slimbus/slim-qcom-ctrl.c new file +3 -0
+	else if (ctx)
+		complete(ctx);
+}

That's weird, if we get an error we don't signal whatever's waiting - won't it just time out at best then? Also, what happens if we get neither an error nor context?

Quoted 15 lines

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

Quoted 13 lines
drivers/slimbus/slim-qcom-ctrl.c new file +13 -0
+	if (txn->msg->wbuf)
+		memcpy(puc, txn->msg->wbuf, txn->msg->num_bytes);
+	msm_slim_queue_tx(dev, pbuf, txn->rl, MGR_TX_MSG);
+	timeout = wait_for_completion_timeout(&done,
+					      msecs_to_jiffies(txn->rl + 100));
+
+	if (!timeout)
+		dev_err(dev->dev, "TX timed out:MC:0x%x,mt:0x%x\n", txn->mc,
+			txn->mt);
+
+	mutex_unlock(&dev->txn_lock);
+	return timeout ? 0 : -ETIMEDOUT;
+}

Shouldn't we provide a route for error reports here (and might some of this timeout stuff go into the core)?

Sure, good point. If I move it to core, all controllers will be expected to have 'write-done' notification. If that's a fair assumption, I will move it to core. That will also mean the above callback/completion will move to framework.

Quoted 24 lines

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

Quoted 8 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+
+	if ((msm_slim_put_rx(dev, (u8 *)buf)) != -ENODATA) {
+		len = buf[0] & 0x1F;
+		mt = (buf[0] >> 5) & 0x7;
+		mc = buf[1];
+		if (mt == SLIM_MSG_MT_CORE &&
+			mc == SLIM_MSG_MC_REPORT_PRESENT) {

Looks like a switch statement.

Quoted 14 lines
drivers/slimbus/slim-qcom-ctrl.c new file +14 -0
+static int msm_slim_rx_msgq_thread(void *data)
+{
+	struct msm_slim_ctrl *dev = (struct msm_slim_ctrl *)data;
+	struct completion *notify = &dev->rx_msgq_notify;
+	int ret;
+
+	while (!kthread_should_stop()) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		ret = wait_for_completion_interruptible(notify);
+
+		if (ret)
+			dev_err(dev->dev, "rx thread wait error:%d\n", ret);
+		else
+			msm_slim_rxwq(dev);
Quoted 8 lines

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

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+	}
+
+	return 0;
+}

It's not entirely clear to me why this is a kthread rather than a workqueue or something. I'm also unclear what happens if more than one piece of work is queued prior to msm_slim_rxwq() running, it looks like it only handles a single operation.

Sure, I will change this to workqueue. That should not be a problem.

Quoted 43 lines

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

Quoted 8 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+	/* SLEW RATE register for this slimbus */
+	dev->slew_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						"slimbus_slew_reg");
+	if (!dev->slew_mem) {
+		dev_err(&pdev->dev, "no slimbus slew resource\n");
+		return;
+	}

Warning not an error isn't it?

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

Quoted 3 lines
drivers/slimbus/slim-qcom-ctrl.c new file +3 -0
+	hclk = clk_get(&pdev->dev, "iface_clk");
+	if (IS_ERR(hclk))
+		return PTR_ERR(hclk);

devm_clk_get()

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

Quoted 1 line
drivers/slimbus/slim-qcom-ctrl.c new file +1 -0
+	ret = clk_set_rate(rclk, SLIM_ROOT_FREQ);

You're ignoring this error in spite of assigning to ret.

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+	slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						"slimbus_physical");
+	if (!slim_mem) {
+		dev_err(&pdev->dev, "no slimbus physical memory resource\n");

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

Quoted 10 lines
drivers/slimbus/slim-qcom-ctrl.c new file +10 -0
+		ret = ENODEV;
+		goto err_get_mem_failed;
+	}
+	slim_io = request_mem_region(slim_mem->start, resource_size(slim_mem),
+					pdev->name);
+	if (!slim_io) {
+		dev_err(&pdev->dev, "slimbus memory already claimed\n");
+		ret = EBUSY;
+		goto err_get_mem_failed;
+	}

devm_ioremap_resource() and a lot of this starts looking simpler.

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

Quoted 1 line
drivers/slimbus/slim-qcom-ctrl.c new file +1 -0
+	dev = kzalloc(sizeof(struct msm_slim_ctrl), GFP_KERNEL);

devm_kzalloc()

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

Quoted 4 lines
drivers/slimbus/slim-qcom-ctrl.c new file +4 -0
+	if (pdev->dev.of_node) {
+
+		ret = of_property_read_u32(pdev->dev.of_node, "cell-index",
+					&dev->ctrl.nr);

Was that in the binding?

Quoted 10 lines

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+	/* Register with framework before enabling frame, clock */
+	ret = slim_add_numbered_controller(&dev->ctrl);
+	if (ret) {
+		dev_err(dev->dev, "error adding controller\n");
+		goto err_ctrl_failed;
+	}

This is suspicious - why are you adding a numbered controller with DT? And looking at this interface why is it a separate call to add a numbered controller, why not just register the controller using the same API and handle any number that was set when doing that?

Agreed, I will change add_numbered_controller to register_controller. That will also mean the 'cell-index' property above is not needed.

Quoted 12 lines

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

Quoted 8 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+	dev->ver = readl_relaxed(dev->base);
+	/* Version info in 16 MSbits */
+	dev->ver >>= 16;
+	/* Component register initialization */
+	writel_relaxed(1, dev->base + CFG_PORT(COMP_CFG, dev->ver));
+	writel_relaxed((EE_MGR_RSC_GRP | EE_NGD_2 | EE_NGD_1),
+				dev->base + CFG_PORT(COMP_TRUST_CFG, dev->ver));

You've registered the device with the core prior to initialising the hardware - I'd expect this means the generic code will start trying to register slaves immediately. The normal pattern would be to initialise the hardware then register it.

This is for handling the logical-address assignment. That's only possible after registering controller.
The internal controller has 2 in-built slimbus devices (interface, framer) which will start to report-present right-away if I initialize the HW. Now if register_controller is not done, the logical-address assignment will not happen and as per spec, the devices will keep sending report_present until they get an assignment.

Registering slaves immediately is not an issue since that part will not be waiting on logical-address assignment (due to device_up callback)

Quoted 30 lines

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

Quoted 12 lines
drivers/slimbus/slim-qcom-ctrl.c new file +11 -0
+#ifdef CONFIG_PM_SLEEP
+static int msm_slim_suspend(struct device *dev)
+{
+	return 0;
+}
+
+static int msm_slim_resume(struct device *dev)
+{
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */

Omit empty functions.

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

Quoted 5 lines
drivers/slimbus/slim-qcom-ctrl.c new file +5 -0
+static int msm_slim_init(void)
+{
+	return platform_driver_register(&msm_slim_driver);
+}
+module_init(msm_slim_init);

module_platform_driver().

Quoted 9 lines
drivers/slimbus/slim-qcom.c new file +9 -0
+u8 *msm_slim_get_tx(struct msm_slim_ctrl *dev, struct msm_wr_cb *cur)
+{
+	unsigned long flags;
+	int idx;
+
+	spin_lock_irqsave(&dev->tx.lock, flags);
+	if (((dev->tx.head + 1) % MSM_TX_MSGS) == dev->tx.tail) {
+		spin_unlock_irqrestore(&dev->tx.lock, flags);
+		return NULL;
Quoted 8 lines

drivers/slimbus/slim-qcom.c line 96

Quoted 7 lines
drivers/slimbus/slim-qcom.c new file +7 -0
+	}
+	idx = dev->tx.tail;
+	dev->tx.tail = (dev->tx.tail + 1) % MSM_TX_MSGS;
+	spin_unlock_irqrestore(&dev->tx.lock, flags);
+	dev->pending_wr[idx] = cur;
+	return dev->tx.base + (idx * SLIM_MSGQ_BUF_LEN);
+}

Would just using a regular list hurt?

This provides O(1) circular buffer access rather than a list with O(n). I will address other comments and upload patch later today/tomorrow.

Thanks for your comments
Sagar

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

PATCH v2 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/slimbus.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/slimbus.h   |  65 +++++++++++++++++++++++++++
 2 files changed, 174 insertions(+)
drivers/slimbus/slimbus.c +109 -0
index d74dfec..3cfa414 100644
@@ -436,7 +436,9 @@ static int slim_register_controller(struct slim_controller *ctrl)
 		ctrl->min_cg = SLIM_MIN_CLK_GEAR;
 	if (!ctrl->max_cg)
 		ctrl->max_cg = SLIM_MAX_CLK_GEAR;
+	init_completion(&ctrl->sched.pause_comp);
 	mutex_init(&ctrl->m_ctrl);
+	mutex_init(&ctrl->sched.m_reconf);
 	ret = device_register(&ctrl->dev);
 	if (ret)
 		goto out_list;
@@ -1059,6 +1061,113 @@ int slim_request_clear_inf_element(struct slim_device *sb,
 }
 EXPORT_SYMBOL(slim_request_clear_inf_element);
 
+/**
+ * slim_ctrl_clk_pause: Called by slimbus controller to enter/exit 'clock pause'
+ * Slimbus specification needs this sequence to turn-off clocks for the bus.
+ * The sequence involves sending 3 broadcast messages (reconfiguration
+ * sequence) to inform all devices on the bus.
+ * To exit clock-pause, controller typically wakes up active framer device.
+ * @ctrl: controller requesting bus to be paused or woken up
+ * @wakeup: Wakeup this controller from clock pause.
+ * @restart: Restart time value per spec used for clock pause. This value
+ *	isn't used when controller is to be woken up.
+ * This API executes clock pause reconfiguration sequence if wakeup is false.
+ * If wakeup is true, controller's wakeup is called.
+ * For entering clock-pause, -EBUSY is returned if a message txn in pending.
+ */
+int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart)
+{
+	int i, ret = 0;
+	unsigned long flags;
+	struct slim_sched *sched = &ctrl->sched;
+	struct slim_val_inf msg = {0, 0, NULL, NULL, NULL, NULL};
+
+	DEFINE_SLIM_BCAST_TXN(txn, SLIM_MSG_MC_BEGIN_RECONFIGURATION,
+				3, SLIM_LA_MANAGER, &msg);
+
+	if (wakeup == false && restart > SLIM_CLK_UNSPECIFIED)
+		return -EINVAL;
+	mutex_lock(&sched->m_reconf);
+	if (wakeup) {
+		if (sched->clk_state == SLIM_CLK_ACTIVE) {
+			mutex_unlock(&sched->m_reconf);
+			return 0;
+		}
+		/**
+		 * Fine-tune calculation based on clock gear,
+		 * message-bandwidth after bandwidth management
+		 */
+		ret = wait_for_completion_timeout(&sched->pause_comp,
+				msecs_to_jiffies(100));
+		if (!ret) {
+			mutex_unlock(&sched->m_reconf);
+			pr_err("Previous clock pause did not finish");
+			return -ETIMEDOUT;
+		}
+		ret = 0;
+		/**
+		 * Slimbus framework will call controller wakeup
+		 * Controller should make sure that it sets active framer
+		 * out of clock pause
+		 */
+		if (sched->clk_state == SLIM_CLK_PAUSED && ctrl->wakeup)
+			ret = ctrl->wakeup(ctrl);
+		if (!ret)
+			sched->clk_state = SLIM_CLK_ACTIVE;
+		mutex_unlock(&sched->m_reconf);
+		return ret;
+	}
+
+	/* already paused */
+	if (ctrl->sched.clk_state == SLIM_CLK_PAUSED) {
+		mutex_unlock(&sched->m_reconf);
+		return 0;
+	}
+
+	spin_lock_irqsave(&ctrl->txn_lock, flags);
+	for (i = 0; i < ctrl->last_tid; i++) {
+		/* Pending response for a message */
+		if (ctrl->txnt[i]) {
+			spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+			mutex_unlock(&sched->m_reconf);
+			return -EBUSY;
+		}
+	}
+	spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+
+	sched->clk_state = SLIM_CLK_ENTERING_PAUSE;
+
+	/* clock pause sequence */
+	ret = slim_processtxn(ctrl, &txn);
+	if (ret)
+		goto clk_pause_ret;
+
+	txn.mc = SLIM_MSG_MC_NEXT_PAUSE_CLOCK;
+	txn.rl = 4;
+	msg.num_bytes = 1;
+	msg.wbuf = &restart;
+	ret = slim_processtxn(ctrl, &txn);
+	if (ret)
+		goto clk_pause_ret;
+
+	txn.mc = SLIM_MSG_MC_RECONFIGURE_NOW;
+	txn.rl = 3;
+	msg.num_bytes = 1;
+	msg.wbuf = NULL;
+	ret = slim_processtxn(ctrl, &txn);
+
+clk_pause_ret:
+	if (ret) {
+		sched->clk_state = SLIM_CLK_ACTIVE;
+	} else {
+		sched->clk_state = SLIM_CLK_PAUSED;
+		complete(&sched->pause_comp);
+	}
+	mutex_unlock(&sched->m_reconf);
+	return ret;
+}
+EXPORT_SYMBOL(slim_ctrl_clk_pause);
+
 MODULE_LICENSE("GPL v2");
 MODULE_VERSION("0.1");
 MODULE_DESCRIPTION("Slimbus module");
include/linux/slimbus.h +65 -0

110 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#15 lore raw

PATCH v2 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 | 133 ++++++++++++++++++++++++++++++++++++++-
 drivers/slimbus/slim-qcom.h      |   1 +
 2 files changed, 132 insertions(+), 2 deletions(-)
drivers/slimbus/slim-qcom-ctrl.c +131 -2
index feae9d1..ec8687d 100644
@@ -21,6 +21,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"
@@ -193,6 +194,7 @@ rx_ret_irq:
 		if (notify_rx)
 			complete(&dev->rx_msgq_notify);
 	}
+	pm_runtime_mark_last_busy(dev->dev);
 	return IRQ_HANDLED;
 }
 
@@ -211,6 +213,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 void msm_slim_cb(void *ctx, int err)
 {
 	if (err)
@@ -225,14 +249,29 @@ static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn)
 	struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
 	u32 *pbuf;
 	u8 *puc;
-	int timeout;
+	int ret, timeout;
 	u8 la = txn->la;
+	enum slim_clk_state cur_clk_state = ctrl->sched.clk_state;
 	struct msm_wr_cb wr_cb = {msm_slim_cb, (void *)&done};
 
 	/* No support to send this dest-type of message */
 	if (txn->dt == SLIM_MSG_DEST_ENUMADDR)
 		return -EPROTONOSUPPORT;
 
+	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 {
+		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--;
 
@@ -276,6 +315,8 @@ static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn)
 			txn->mt);
 
 	mutex_unlock(&dev->txn_lock);
+	if (cur_clk_state != SLIM_CLK_ENTERING_PAUSE)
+		pm_runtime_put(dev->dev);
 	return timeout ? 0 : -ETIMEDOUT;
 }
 
@@ -295,6 +336,13 @@ static int msm_set_laddr(struct slim_controller *ctrl,
 	ea[2] = (u8) (ead->prod_code & 0xFF);
 	ea[1] = ead->dev_index;
 	ea[0] = ead->instance;
+
+	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;
+	}
 	mutex_lock(&dev->txn_lock);
 	/**
 	 * Retries are needed since bus may lose sync when multiple devices
@@ -305,6 +353,7 @@ retry_laddr:
 	buf = (u32 *)msm_slim_get_tx(dev, &wr_cb);
 	if (buf == NULL) {
 		mutex_unlock(&dev->txn_lock);
+		pm_runtime_put(dev->dev);
 		return -ENOMEM;
 	}
 
@@ -332,6 +381,7 @@ retry_laddr:
 		}
 	}
 	mutex_unlock(&dev->txn_lock);
+	pm_runtime_put(dev->dev);
 	return ret;
 }
 
@@ -512,6 +562,7 @@ 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;
 
 	mutex_init(&dev->txn_lock);
 	init_completion(&dev->rx_msgq_notify);
@@ -615,6 +666,12 @@ static int msm_slim_probe(struct platform_device *pdev)
 	/* Add devices registered with board-info now that controller is up */
 	slim_ctrl_add_boarddevs(&dev->ctrl);
 
+	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;
 
@@ -651,6 +708,7 @@ static int msm_slim_remove(struct platform_device *pdev)
 	struct resource *slim_mem;
 	struct resource *slew_mem = dev->slew_mem;
 
+	pm_runtime_disable(&pdev->dev);
 	free_irq(dev->irq, dev);
 	slim_del_controller(&dev->ctrl);
 	clk_put(dev->rclk);
@@ -671,20 +729,91 @@ static int msm_slim_remove(struct platform_device *pdev)
 	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)
 {
-	return 0;
+	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[] = {
drivers/slimbus/slim-qcom.h +1 -0
index 32073fc..f37a10a 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