Skip to contentSkip to conversation

Introduce framework for SLIMbus device drivers

PATCH Superseded Sagar Dharia 3 participants 17 messages Feb 6, 2016 – Apr 18, 2016

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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, controller driver for Qualcomm's slimbus controller, 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 the controller driver, and a test slave device.

Changes from V3 to V4:
* Addressed inline-code review comments from Mark Brown and Rob Herring.
* Use existing device-model to get list of children of the controller.
* Use 4 cells to represent 4 components of the enumeration address.
* Commit-text and comments to document performance arguments in using coherently mapped buffers for transaction buffer management.
* Tried to address clock-pause management suggestion by making sure bus-framework votes/unvotes for runtime-PM while handling transfers.

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  |  54 ++
 .../devicetree/bindings/slimbus/slim-qcom-ctrl.txt |  43 ++
 Documentation/slimbus/summary                      | 109 +++
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/slimbus/Kconfig                            |  21 +
 drivers/slimbus/Makefile                           |   5 +
 drivers/slimbus/slim-core.c                        | 852 +++++++++++++++++++++
 drivers/slimbus/slim-messaging.c                   | 415 ++++++++++
 drivers/slimbus/slim-qcom-ctrl.c                   | 678 ++++++++++++++++
 drivers/slimbus/slim-qcom.h                        |  64 ++
 drivers/slimbus/slim-sched.c                       | 122 +++
 include/linux/mod_devicetable.h                    |  13 +
 include/linux/slimbus.h                            | 678 ++++++++++++++++
 14 files changed, 3057 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
 create mode 100644 Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt
 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 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 · 6 lines
1.8.2.1

--
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
#1 lore raw

PATCH v4 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     | 720 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mod_devicetable.h |  13 +
 include/linux/slimbus.h         | 387 +++++++++++++++++++++
 8 files changed, 1247 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 +720 -0

720 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 +387 -0

387 lines not on this page · raw message

Signature · 6 lines
1.8.2.1

--
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
#3 lore raw

PATCH v4 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 | 54 ++++++++++++++++
 drivers/slimbus/slim-core.c                       | 75 +++++++++++++++++++++++
 2 files changed, 129 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
Documentation/devicetree/bindings/slimbus/bus.txt new file +54 -0
new file mode 100644
index 0000000..71c769d
@@ -0,0 +1,54 @@
+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 4 (number of cells required to define
+		4 fields of the enumeration address for the SLIMbus
+		slave device)
+- #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 enumeration address containing 4 fields:
+Manufacturer ID, Product code, Device index, and Instance value for
+the device.
+
+Required property for SLIMbus child node:
+- reg		- enumeration address fields of the device
+
+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)
+		Note that the property is listed as optional since the
+		devices are discoverable when they are functional.
+		However, the device may need additional non-standard
+		way to power it up so that it can start functioning.
+		In that case, compatible property will be
+		needed for the corresponding driver to probe and
+		perform the required procedure to make it functional.
+
+SLIMbus example for Qualcomm's slimbus manager component:
+
+	slim@28080000 {
+		compatible = "qcom,slim-msm";
+		reg = <0x28080000 0x2000>,
+		interrupts = <0 33 0>;
+		clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+		clock-names = "iface_clk", "core_clk";
+
+		[email protected] {
+			reg = <0x217 0x60 0x1 0x0>;
+		};
+	};
drivers/slimbus/slim-core.c +75 -0

93 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#5 lore raw

PATCH v4 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.
TX and RX circular rings are used to allow queuing of multiple transfers per controller. Controller can choose size of these rings based of controller HW implementation. The buffers are coerently mapped so that controller can utilize DMA operations for the transactions without remapping every transaction buffer. Statically allocated rings help to improve performance by avoiding overhead of dynamically allocating transactions on need basis.

---
 drivers/slimbus/Makefile         |   2 +-
 drivers/slimbus/slim-core.c      |  44 +++++
 drivers/slimbus/slim-messaging.c | 377 +++++++++++++++++++++++++++++++++++++++
 include/linux/slimbus.h          | 224 +++++++++++++++++++++++
 4 files changed, 646 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

72 lines not on this page · raw message

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

377 lines not on this page · raw message

include/linux/slimbus.h +224 -0

265 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#7 lore raw

PATCH v4 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 |  43 ++
 drivers/slimbus/Kconfig                            |  10 +
 drivers/slimbus/Makefile                           |   1 +
 drivers/slimbus/slim-qcom-ctrl.c                   | 556 +++++++++++++++++++++
 drivers/slimbus/slim-qcom.h                        |  63 +++
 5 files changed, 673 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 +43 -0
new file mode 100644
index 0000000..7b6c366
@@ -0,0 +1,43 @@
+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:
+
+- #address-cells - should be 4 (number of cells required to define
+		4 fields of the enumeration address for the SLIMbus
+		slave device)
+- #size-cells	- should be 0
+ - 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
+ - compatible : should be "qcom,slim-msm" if this is master component driver
+ - interrupts : Interrupt number used by this controller
+ - 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";
+		#address-cells = <4>;
+		#size-cells = <0>;
+		reg = <0x28080000 0x2000>, <0x80207C 4>;
+		reg-names = "slimbus_physical", "slimbus_slew_reg";
+		interrupts = <0 33 0>;
+		clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+		clock-names = "iface_clk", "core_clk";
+
+		[email protected] {
+			reg = <0x217 0x60 0x1 0x0>;
+		};
+	};
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 +556 -0

556 lines not on this page · raw message

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

63 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#13 lore raw

PATCH v4 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      |  13 +++++
 drivers/slimbus/slim-messaging.c |  50 ++++++++++++++--
 drivers/slimbus/slim-sched.c     | 122 +++++++++++++++++++++++++++++++++++++++
 include/linux/slimbus.h          |  69 +++++++++++++++++++++-
 5 files changed, 248 insertions(+), 8 deletions(-)
 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 +13 -0
index 27c7dec..5d67e53 100644
@@ -443,6 +443,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),
@@ -715,6 +717,14 @@ int slim_assign_laddr(struct slim_controller *ctrl, struct slim_eaddr *e_addr,
 	struct slim_device *slim;
 	struct slim_addrt *temp;
 
+	ret = pm_runtime_get_sync(ctrl->dev.parent);
+
+	if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) {
+		dev_err(&ctrl->dev, "slim ctrl not active,state:%d, ret:%d\n",
+				    ctrl->sched.clk_state, ret);
+		goto slimbus_not_active;
+	}
+
 	mutex_lock(&ctrl->m_ctrl);
 	/* already assigned */
 	if (ctrl_getaddr_entry(ctrl, e_addr, &i) == 0) {
@@ -783,6 +793,9 @@ ret_assigned_laddr:
 		}
 		mutex_unlock(&slim->report_lock);
 	}
+slimbus_not_active:
+	pm_runtime_mark_last_busy(ctrl->dev.parent);
+	pm_runtime_put_autosuspend(ctrl->dev.parent);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(slim_assign_laddr);
drivers/slimbus/slim-messaging.c +44 -6

114 lines not on this page · raw message

drivers/slimbus/slim-sched.c new file +122 -0

122 lines not on this page · raw message

include/linux/slimbus.h +68 -1

125 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#14 lore raw

PATCH v4 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 | 124 ++++++++++++++++++++++++++++++++++++++-
 drivers/slimbus/slim-qcom.h      |   1 +
 2 files changed, 124 insertions(+), 1 deletion(-)
drivers/slimbus/slim-qcom-ctrl.c +123 -1
index df20fb4..9cadcea 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"
@@ -217,6 +218,28 @@ rx_ret_irq:
 	return IRQ_HANDLED;
 }
 
+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)
 {
@@ -253,6 +276,7 @@ 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);
 
+
 	return msm_slim_queue_tx(dev, head, txn->rl, MGR_TX_MSG);
 }
 
@@ -276,13 +300,13 @@ static int msm_set_laddr(struct slim_controller *ctrl,
 	buf[5] = ead->instance;
 	/* Logical address for this EA */
 	buf[6] = laddr;
+
 	/**
 	 * Retries are needed since bus may lose sync when multiple devices
 	 * are coming up and reporting present
 	 */
 	msg.wbuf = buf;
 	msg.num_bytes = 7;
-
 	ret = slim_processtxn(&dev->ctrl, &txn);
 
 	if (ret)
@@ -413,6 +437,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;
@@ -510,6 +536,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;
 
@@ -527,11 +559,100 @@ 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.
+		* (e.g. modem usecase 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",
@@ -546,6 +667,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 0ad59c3..8b1d649 100644
@@ -23,6 +23,7 @@
 		((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16))
 
 #define SLIM_ROOT_FREQ 24576000
+#define MSM_SLIM_AUTOSUSPEND 1000
 
 /* MAX message size over control channel */
 #define SLIM_MSGQ_BUF_LEN	40
Signature · 1 line
1.8.2.1
maintainer
#4 lore raw

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

In reply to Sagar Dharia
Quoted 39 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 | 54 ++++++++++++++++
 drivers/slimbus/slim-core.c                       | 75 +++++++++++++++++++++++
 2 files changed, 129 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
Documentation/devicetree/bindings/slimbus/bus.txt new file +23 -0
new file mode 100644
index 0000000..71c769d
@@ -0,0 +1,54 @@
+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 4 (number of cells required to define
+		4 fields of the enumeration address for the SLIMbus
+		slave device)
+- #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 enumeration address containing 4 fields:
+Manufacturer ID, Product code, Device index, and Instance value for
+the device.

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

Quoted 10 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +10 -0
+
+Required property for SLIMbus child node:
+- reg		- enumeration address fields of the device
+
+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)

The compatible string should follow other discoverable buses like PCI and USB and use the enumeration data for the compatible string. Something like "slim<manuID>,<product code>".

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

Quoted 7 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +7 -0
+		Note that the property is listed as optional since the
+		devices are discoverable when they are functional.
+		However, the device may need additional non-standard
+		way to power it up so that it can start functioning.
+		In that case, compatible property will be
+		needed for the corresponding driver to probe and
+		perform the required procedure to make it functional.

I think the node being present should be optional, but the compatible should be required if node is present.

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

Quoted 11 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +11 -0
+
+SLIMbus example for Qualcomm's slimbus manager component:
+
+	slim@28080000 {
+		compatible = "qcom,slim-msm";
+		reg = <0x28080000 0x2000>,
+		interrupts = <0 33 0>;
+		clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+		clock-names = "iface_clk", "core_clk";
+
+		[email protected] {

Unique fields should be separated by commas.

Probably should just be "codec@..."

Quoted 3 lines
Documentation/devicetree/bindings/slimbus/bus.txt new file +3 -0
+			reg = <0x217 0x60 0x1 0x0>;
+		};
+	};
maintainer
#8 lore raw

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

In reply to Sagar Dharia
Quoted 26 lines · 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 |  43 ++
 drivers/slimbus/Kconfig                            |  10 +
 drivers/slimbus/Makefile                           |   1 +
 drivers/slimbus/slim-qcom-ctrl.c                   | 556 +++++++++++++++++++++
 drivers/slimbus/slim-qcom.h                        |  63 +++
 5 files changed, 673 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 +0 -0
new file mode 100644
index 0000000..7b6c366

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

Quoted 2 lines
Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file +2 -0
@@ -0,0 +1,43 @@
+Qualcomm SLIMBUS controller
+"qcom,slim-msm": This controller is used if applications processor

This should be more specific and include the soc name(s).

Quoted 4 lines
Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file +4 -0
+	driver is controlling slimbus master component. This driver is
+	responsible for communicating with slave HW directly using
+	messaging interface, and doing data channel management.
+
#2 lore raw

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

In reply to Sagar Dharia
Quoted 10 lines · Sagar Dharia
drivers/slimbus/slim-core.c new file +10 -0
+static void schedule_slim_report(struct slim_controller *ctrl,
+				 struct slim_device *sb, bool report)
+{
+	struct sb_report_wd *sbw;
+
+	dev_dbg(&ctrl->dev, "report:%d for slave:%s\n", report, sb->name);
+
+	sbw = kmalloc(sizeof(*sbw), GFP_KERNEL);
+	if (!sbw)
+		return;

drivers/slimbus/slim-core.c line 120

Quoted 10 lines
drivers/slimbus/slim-core.c new file +10 -0
+
+	INIT_WORK(&sbw->wd, slim_report);
+	sbw->sb = sb;
+	sbw->report = report;
+	if (!queue_work(ctrl->wq, &sbw->wd)) {
+		dev_err(&ctrl->dev, "failed to queue report:%d slave:%s\n",
+				    report, sb->name);
+		kfree(sbw);
+	}
+}

I'm not 100% clear why we're scheduling this into a workqueue, it'd probably help to at least explain what's going on in the code for future reference.

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+/**

There's an awful lot of places in this which look like they're missing blank lines.

drivers/slimbus/slim-core.c line 646

Quoted 8 lines
drivers/slimbus/slim-core.c new file +8 -0
+ret_assigned_laddr:
+	mutex_unlock(&ctrl->m_ctrl);
+	if (exists || ret)
+		return ret;
+
+	pr_info("setting slimbus l-addr:%x, ea:%x,%x,%x,%x\n",
+		*laddr, e_addr->manf_id, e_addr->prod_code,
+		e_addr->dev_index, e_addr->instance);

Not a dev_ print?

drivers/slimbus/slim-core.c line 653

Quoted 3 lines
drivers/slimbus/slim-core.c new file +3 -0
+	slim = slim_query_device(ctrl, e_addr);
+	if (!slim) {
+		ret = -ENOMEM;

-ENOMEM?

drivers/slimbus/slim-core.c line 715

Quoted 11 lines
drivers/slimbus/slim-core.c new file +11 -0
+static void __exit slimbus_exit(void)
+{
+	bus_unregister(&slimbus_type);
+}
+
+static int __init slimbus_init(void)
+{
+	return bus_register(&slimbus_type);
+}
+postcore_initcall(slimbus_init);
+module_exit(slimbus_exit);

Put the annotatations next to their functions.

drivers/slimbus/slim-core.c line 720

Quoted 2 lines
drivers/slimbus/slim-core.c new file +2 -0
+MODULE_DESCRIPTION("Slimbus module");
+MODULE_ALIAS("platform:slimbus");

This isn't a platform driver, it shouldn't have this alias.

include/linux/slimbus.h

Quoted 5 lines
include/linux/slimbus.h new file +0 -0
new file mode 100644
index 0000000..2a78f79

Probably good to add a module_slimbus_device() macro like other buses have.

#6 lore raw

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

In reply to Sagar Dharia

drivers/slimbus/slim-messaging.c line 44

Quoted 13 lines · Sagar Dharia
drivers/slimbus/slim-messaging.c new file +13 -0
+	spin_lock_irqsave(&ctrl->txn_lock, flags);
+	msg = ctrl->tid_tbl[tid];
+	if (msg == NULL || msg->rbuf == NULL) {
+		spin_unlock_irqrestore(&ctrl->txn_lock, flags);
+		dev_err(&ctrl->dev, "Got response to invalid TID:%d, len:%d\n",
+				tid, len);
+		return;
+	}
+	memcpy(msg->rbuf, reply, len);
+	ctrl->tid_tbl[tid] = NULL;
+	if (msg->comp_cb)
+		msg->comp_cb(msg->ctx, 0);
+	spin_unlock_irqrestore(&ctrl->txn_lock, flags);

Do we need to hold the lock for so long (especially with things like the memcpy())? As far as I can tell we only need the lock for this:

drivers/slimbus/slim-messaging.c line 209

Quoted 8 lines
drivers/slimbus/slim-messaging.c new file +7 -0
+	msg = ctrl->tid_tbl[tid];
+	ctrl->tid_tbl[tid] = NULL;
 
+	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;

A switch statement might be nicer here.

#9 lore raw

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

In reply to Sagar Dharia

drivers/slimbus/Kconfig menuconfig SLIMBUS · line 17

Quoted 7 lines · Sagar Dharia
drivers/slimbus/Kconfig +6 -0
+if SLIMBUS
+config SLIM_QCOM_CTRL
+	tristate "Qualcomm Slimbus Manager Component"
+	depends on SLIMBUS
+	default n
+	help

n is the default.

Quoted 7 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+static irqreturn_t msm_slim_interrupt(int irq, void *d)
+{
+	struct msm_slim_ctrl *dev = d;
+	u32 stat = readl_relaxed(dev->base + MGR_INT_STAT);
+	int err = 0;
 
+	if (stat & MGR_INT_TX_MSG_SENT || stat & MGR_INT_TX_NACKED_2) {

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

Quoted 10 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
 
+	if (stat & MGR_INT_RX_MSG_RCVD) {
 
+	}
 
+	/**
+	 * All interrupts are handled: complex RX messages requiring more work
+	 * are queued to work-queue, others are handled above
+	 */
+	return IRQ_HANDLED;

This unconditionally returns IRQ_HANDLED even if no interrupts were flagged. This will break if the interrupt gets shared in some hardware design or if something goes wrong with the hardware.

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+	ret = devm_request_irq(&pdev->dev, dev->irq, msm_slim_interrupt,
+				IRQF_TRIGGER_HIGH, "msm_slim_irq", dev);
+	if (ret) {
+		dev_err(&pdev->dev, "request IRQ failed\n");
+		goto err_request_irq_failed;
+	}

Are you sure this is safe and we don't deallocate things the interrupt handler uses before we disable the interrupt?

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

Quoted 7 lines
drivers/slimbus/slim-qcom-ctrl.c new file +7 -0
+	ret = clk_prepare_enable(hclk);
+	if (ret)
+		goto err_hclk_enable_failed;
+
+	ret = clk_prepare_enable(rclk);
+	if (ret)
+		goto err_rclk_enable_failed;

The remove path doesn't disable these.

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

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

Should we have a devm_ version of slim_register_controller()? I'd also expect this to be the last thing we do in probe, things may start using the device before we've finished initializing it.

#15 lore raw

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

In reply to Sagar Dharia

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

Quoted 8 lines · Sagar Dharia
drivers/slimbus/slim-qcom-ctrl.c +1 -0
@@ -253,6 +276,7 @@ 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);
 
+
 	return msm_slim_queue_tx(dev, head, txn->rl, MGR_TX_MSG);
 }
 

This change for some reason seems to have a few of these random whitespace only changes here.

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

Quoted 8 lines
drivers/slimbus/slim-qcom-ctrl.c +8 -0
+	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;

Coding style, {} should be on both sides. It's also a bit odd that we don't ever reenable these clocks.

#16 lore raw
In reply to Sagar Dharia
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.

I've sent replies with some comments but they're all fairly low level and specific, overall this is looking pretty good though.

#10 lore raw

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

In reply to Mark Brown

Hello Mark
Apologies for a late reply. I will incorporate most of your comments. Please see inline response for 2 comments:

Quoted 8 lines

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+	ret = devm_request_irq(&pdev->dev, dev->irq, msm_slim_interrupt,
+				IRQF_TRIGGER_HIGH, "msm_slim_irq", dev);
+	if (ret) {
+		dev_err(&pdev->dev, "request IRQ failed\n");
+		goto err_request_irq_failed;
+	}

Are you sure this is safe and we don't deallocate things the interrupt handler uses before we disable the interrupt?

Since clock is not enabled before this step, we won't be getting any interrupts from HW at this stage.

Quoted 9 lines

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

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

Should we have a devm_ version of slim_register_controller()? I'd also expect this to be the last thing we do in probe, things may start using the device before we've finished initializing it.

register_controller also allocates controller's TX/RX ring buffers. These rings are needed when devices start reporting present on the bus once they are enabled.
So register_controller needs to be done before enabling any devices.
All steps after register_controller in this function are related to enabling various internal component devices (e.g. framer, interface, manager devices) of this slimbus controller.

Thank you for your comments
Sagar

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

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

On Fri, Apr 15, 2016 at 10:17:36AM -0600, Sagar Dharia wrote:

Please leave blank lines between paragraphs, it makes things much easier to read than a wall of uninterrupted text.

Quoted 10 lines
Quoted 9 lines

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+	ret = devm_request_irq(&pdev->dev, dev->irq, msm_slim_interrupt,
+				IRQF_TRIGGER_HIGH, "msm_slim_irq", dev);
+	if (ret) {
+		dev_err(&pdev->dev, "request IRQ failed\n");
+		goto err_request_irq_failed;
+	}

Are you sure this is safe and we don't deallocate things the interrupt handler uses before we disable the interrupt?

Quoted 2 lines

Since clock is not enabled before this step, we won't be getting any interrupts from HW at this stage.

No, that's not what I'm saying - I'm asking about the *disable* path on remove.

#12 lore raw

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

Quoted 13 lines · Mark Brown

On Fri, Apr 15, 2016 at 10:17:36AM -0600, Sagar Dharia wrote:

Please leave blank lines between paragraphs, it makes things much easier to read than a wall of uninterrupted text.

Quoted 8 lines
Quoted 8 lines

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

Quoted 6 lines
drivers/slimbus/slim-qcom-ctrl.c new file +6 -0
+	ret = devm_request_irq(&pdev->dev, dev->irq, msm_slim_interrupt,
+				IRQF_TRIGGER_HIGH, "msm_slim_irq", dev);
+	if (ret) {
+		dev_err(&pdev->dev, "request IRQ failed\n");
+		goto err_request_irq_failed;
+	}

Are you sure this is safe and we don't deallocate things the interrupt handler uses before we disable the interrupt?

Quoted 4 lines
Quoted 2 lines

Since clock is not enabled before this step, we won't be getting any interrupts from HW at this stage.

No, that's not what I'm saying - I'm asking about the *disable* path on remove.

Good point, I will change the del_controller as well to enter clock-pause, and the controller's remove function to disable interrupt.

Thanks
Sagar

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