Skip to contentSkip to conversation

slimbus: Linux driver framework for SLIMbus.

RFC PATCH In review Kenneth Heitke 10 participants 43 messages Aug 10, 2011 – Aug 25, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 slimbus: Linux driver framework for SLIMbus.

From: Sagar Dharia <[email protected]>

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. Commonly used digital audio interfaces such as I2S, PCM are intended for point-to-point connection between application processor and single audio device and support one or two channels. Adding more channels or functions is difficult without increasing number of bus structures and hence pin count. In parallel to audio channels, control buses such as I2C are typically used for low-bandwidth control tasks.
SLIMbus replaces many digital audio buses and control buses by providing flexible and dynamic bus-bandwidth between data-functions and control-functions.

The framework supports message APIs, channel scheduling for SLIMbus. Message APIs are used for status/control type of communication with a device. Data Channel APIs are used for setting data channels between SLIMbus devices.

Framework supports multiple busses (1 controller per bus) and multiple clients/slave devices per controller.

---
 Documentation/slimbus/slimbus-framework.txt |  282 +++
 drivers/Kconfig                             |    2 +
 drivers/Makefile                            |    1 +
 drivers/slimbus/Kconfig                     |   10 +
 drivers/slimbus/Makefile                    |    4 +
 drivers/slimbus/slimbus.c                   | 2629 +++++++++++++++++++++++++++
 include/linux/mod_devicetable.h             |    9 +
 include/linux/slimbus/slimbus.h             |  939 ++++++++++
 8 files changed, 3876 insertions(+), 0 deletions(-)
 create mode 100755 Documentation/slimbus/slimbus-framework.txt
 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/slimbus.h
Documentation/slimbus/slimbus-framework.txt new file +282 -0
new file mode 100755
index 0000000..a091417
@@ -0,0 +1,282 @@
+Introduction
+============
+
+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. Commonly used digital audio interfaces such as I2S, PCM are intended for
+point-to-point connection between application processor and single audio device
+and support one or two channels. Adding more channels or functions is difficult
+without increasing number of bus structures and hence pin count. In parallel to
+audio channels, control buses such as I2C are typically used for low-bandwidth
+control tasks.
+
+Slimbus replaces many digital audio buses and control buses by providing
+flexible and dynamic bus-bandwidth between data-functions and control-functions.
+
+
+
+Hardware Description
+====================
+
+Slimbus is a 2-wire multi-drop interface and uses TDM frame structure.
+The devices communicate over a shared bus using predefined transport protocols.
+There are 2 different type of transports.
+
+The message transport is used for various control functions such as bus
+management, configuration and status updates. Messages are seen by all devices
+and the messages can be of unicast and broadcast type. e.g. Reading/writing
+device specific values is typically a unicast message. A data channel
+reconfiguration sequence is announced to all devices using broadcast message.
+
+A data transport is used for data-transfer between 2 Slimbus devices. Data
+transport uses dedicated ports on the device. This data-transfer is not seen
+by all devices.
+
+Slimbus specification has different types of device classifications based on
+their capabilities. Manager device is responsible for enumeration,
+configuration, and dynamic channel allocation. Every bus has 1 active manager.
+Framer device is responsible for driving clock line and placing information on
+data line. Multiple framers may exist on a bus and manager is responsible for
+doing framer-handoffs. (Not supported in the SW driver right now).
+
+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 of its previous gear.
+
+Generic device is a device providing Slimbus functionality and typically has
+ports for data-channel support. Its registers are mapped as 'value elements'
+so that they can be written/read using Slimbus message transport for
+exchanging control/status type of information. Generic devices are also referred
+to as 'clients' in this document from here-onwards.
+
+Each device has a 6-byte elemental-address and the manager assigns every device
+with a 1-byte logical address after the devices report present on the bus.
+
+Slimbus uses TDM framing at the physical layer and has variable number of
+frames used for messaging and data-channels. The TDM framing is out of scope
+of this document since clients can not directly access or interfere with it.
+
+
+
+Software Description:
+====================
+
+Initialization/Bringup:
+-----------------------
+Each bus has one active manager and that is represented by slim_controller
+data structure. The controller is probed during initial kernel bring-up and it
+is responsible to probe other "Generic Devices" and "Framer Devices". All
+devices report present (Broadcast message) after they are probed and
+manager stores their elemental addresses and assigns logical addresses. Clients
+get their logical address by calling a public API in case they don't get
+interrupt after receiving the message.
+
+Clients are added using similar logic to I2C. (There is one controller per
+Slimbus who does active-manager duties. Each controller has a bus-number and
+the clients are populated in boards file on that controller). This way, it is
+more target-independent. In addition, clients can be added to the controller
+using add_device API. This is useful if the client is to be added later
+(as a module). It is also useful if each slave can have multiple elemental
+generic devices but only one driver. The generic device (slave) driver can then
+add more devices per its capability and still have 1 driver.
+
+Framers are also added per numbered controller and they are expected to
+initialize/enable clock related hardware in their probe. It may be common to
+have 1 driver for manager (controller) and framer. In that case, separate framer
+device and/or driver is not needed. Framer handover can be used by controller to
+change framer per Slimbus spec, but the capability is not currently implemented
+in this framework yet.
+
+Message-based APIs:
+-------------------
+As described earlier, control and status information can be exchanged on
+Slimbus. Slimbus client device driver can write/read control registers using the
+message-based APIs for doing elemental accesses. Per Slimbus specification,
+there are two type of elements in every device. Value based (values can be
+read/written) and information based (bit-wise information can be set/cleared).
+Slimbus slave device driver can call these APIs. This typically replaces I2C
+type of control/status transaction. Framework makes sanity checks based on
+Slimbus specification and then calls controller specific message transfer
+function pointer. The sanity checks make sure that accesses to reserved-address
+space are not allowed, or the size of message isn't out-of-bounds per the
+specification.
+
+Messages are queued in a work-queue (per controller). Slimbus specification has
+transaction identification number (TID) for each transaction expecting response.
+The transaction message is kept per controller until response is received, or
+write-acknowledgement is received.
+
+Client can request to reserve certain bandwidth for messaging if it anticipates
+heavy messaging-traffic on the bus. Slimbus framework tries to reserve the
+messaging bandwidth and may decide to change clock frequency (clock gear)
+based on existing data-channels on the bus and current frequency (clock gear),
+and pre-existing reserved-message bandwidth. Reserving bandwidth will fail if
+clock gear is already maximum and pre-existing data channels and the newly
+requested reserved bandwidth cannot be satisfied.
+
+Data Channel based APIs:
+------------------------
+Data channels can be setup between 2 devices using their data ports. Per
+Slimbus specification, there can be multiple sources and one sink per one data
+channel. Each data channel is uniquely defined by its location in the TDM frame.
+Every manager device also typically has many ports and they are used for data
+transfer between software and the device. Ports have different configuration and
+request types. For each half-duplex port, 2 adjacent physical ports are located.
+
+A port can have source or sink flow. Port has events/errors associated with it.
+Typically, client requests ports on manager and slave devices. That causes a
+Slimbus specification message to be sent to the device (connect-source or
+connect-sink). Once the port allocation is done, client requests for channel to
+be allocated using the ports it has. Data channel has different protocols
+(such as isochronous, soft-isochronous, asynchronous) based on the clock at
+which Slimbus runs and the channel bandwidth requirements. Clients specify rate
+and the protocol to allocate channel. Clients then call transfer on the port
+with the input/output vectors and specify completion structure to be notified.
+Clients then call channel activation API to activate the channel.
+
+Channels with common parameters can benefit from grouping. Grouping channels
+helps to schedule/deactive a set of channels at the same time. (e.g. 5.1 audio).
+Framework signals completion when the buffers are done and it's upto client to
+supply more buffers and/or deactivate the channel. Completion signal is also
+used to communicate port errors to the client. It's upto the client to act
+according to the error.  Activation/Deactivation can be done on a pre-existing
+channels. Clients can call deallocation APIs on channels and/or ports when they
+no longer need the resources.
+
+Clients use "commit" flag in the control channel APIs to group their requests.
+This avoids sending the expensive reconfiguration sequence on the bus too
+frequently. Once the "commit" flag is set, all channel-requests pending on that
+client are acted upon (active-channels are scheduled, remove-channels are
+removed from scheduling etc.)
+
+Scheduling of channels: Controller and/or framework will call API to reschedule
+TDM framing as it is deemed necessary. This is internally implemented by the
+framework based on current data-channel and message bandwidth requirements.
+Controller may also change scheduling of already active-channels to use TDM
+effectively.
+
+
+
+Design
+======
+Bus-type:
+---------
+Slimbus is represented as a bus and different type of devices listed above hang
+on it. The bus registers with Linux kernel in early stages of kernel bringup.
+Every Slimbus typically has one manager device, one framer device, and multiple
+generic devices (clients). When a device is added/registered, Slimbus matches a
+driver (registered earlier) and calls the driver probe.
+
+Message transactions:
+---------------------
+For faster and efficient transaction management, Linux framework uses tid for
+every transaction irrespective of whether it expects a response. This helps in
+O(1) search of the transaction when it's complete, or its response is received,
+or it needs to be resent due to collision/NACK. Once transaction is complete,
+its resources are just marked unused and not deleted. A transaction is allocated
+if an unused transaction is not found. Per Slimbus specification, TID is 8-bit
+long and cannot exceed 256. So this won't cause a lot of memory usage and
+allocation for transactions won't be required to be done too often.
+
+Ports and channels:
+-------------------
+Manager-ports and channels are allocated as arrays. This helps faster access
+based on channel/port number. Typically number of ports and channels are limited
+and having this as a list won't gain significant memory advantage.
+
+For effective scheduling, 2 most commonly used frequency-channels (4KHz and
+12KHz) are grouped in 2 sorted lists. The lists only have pointers (to channel
+elements allocated above).
+
+
+Power Management
+================
+Slimbus hardware uses only 2 wires for managing multiple devices, multiple
+channels and control/status messaging. This is power efficient. In addition,
+clock gears are used to go to lower clock gears when low-bandwidth messaging
+is used and/or limited data channels are used. Controller will call clock-pause
+API to pause the slimbus clock if no channels are active.
+
+Runtime suspend/resume will be used from Linux kernel power management
+framework to implement power management functionality.
+
+
+
+SMP/multi-core
+==============
+Board initialization list for listing devices, framers use a board-specific
+mutex. This mutex is common to all controllers.
+
+Controllers are listed in the framework using idr list. The list is protected by
+a common mutex.
+
+Controller data structures (channel, port, address-table, transaction-id table)
+are protected using a controller mutex.
+
+Reconfiguration mutex per controller is used to make sure that only one
+reconfiguration sequence is in progress per controller.
+
+Client structure has a mutex to protect the pending data channel request-lists
+per client.
+
+
+
+Security
+========
+None at this point.
+
+
+
+Interface
+=========
+There is no plan of exporting slimbus functionality to user space right now.
+
+Kernel space APIs:
+include/linux/slimbus/slimbus.h
+-----------------------
+
+
+
+Driver parameters
+=================
+None.
+
+
+
+Config options
+==============
+Slimbus in drivers/Kconfig
+
+
+
+Dependencies
+============
+None.
+
+
+
+User space utilities
+====================
+None at this point. No user space access is expected for Slimbus at this point.
+If need be, a client can be implemented to manage all use-space accesses
+using ioctl.
+
+
+
+Known issues
+============
+None.
+
+
+
+To do
+=====
+Framer handoff is not supported right now. This is required when a bus has
+multiple framers and active framer needs to be decided on the fly.
+
+Specific logical address request is not supported right now. Client drivers may
+request for specific logical address and that may change logical addresses of
+other preexisting devices on the bus.
+
+Debugfs will be used to debug channel management and bandwidth usage in future.
drivers/Kconfig +2 -0
index 3bb154d..8083490 100644
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig"
 
 source "drivers/spi/Kconfig"
 
+source "drivers/slimbus/Kconfig"
+
 source "drivers/pps/Kconfig"
 
 source "drivers/ptp/Kconfig"
drivers/Makefile +1 -0
index 09f3232..5ba22a0 100644
@@ -51,6 +51,7 @@ obj-$(CONFIG_ATA)		+= ata/
 obj-$(CONFIG_TARGET_CORE)	+= target/
 obj-$(CONFIG_MTD)		+= mtd/
 obj-$(CONFIG_SPI)		+= spi/
+obj-$(CONFIG_SLIMBUS)		+= slimbus/
 obj-y				+= net/
 obj-$(CONFIG_ATM)		+= atm/
 obj-$(CONFIG_FUSION)		+= message/
drivers/slimbus/Kconfig new file +10 -0
new file mode 100644
index 0000000..78f8111
@@ -0,0 +1,10 @@
+#
+# SLIMBUS driver configuration
+#
+menuconfig SLIMBUS
+	bool "SLIMbus support"
+	depends on HAS_IOMEM
+	help
+	  SLIMbus is standard interface between baseband and
+	  application processors and 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 +2629 -0

2,629 lines not on this page · raw message

include/linux/mod_devicetable.h +9 -0
index ae28e93..18997d7 100644
@@ -427,6 +427,15 @@ struct spi_device_id {
 			__attribute__((aligned(sizeof(kernel_ulong_t))));
 };
 
+#define SLIMBUS_NAME_SIZE	32
+#define SLIMBUS_MODULE_PREFIX "slim:"
+
+struct slim_device_id {
+	char name[SLIMBUS_NAME_SIZE];
+	kernel_ulong_t driver_data	/* Data private to the driver */
+			__attribute__((aligned(sizeof(kernel_ulong_t))));
+};
+
 /* dmi */
 enum dmi_field {
 	DMI_NONE,
include/linux/slimbus/slimbus.h new file +939 -0

45 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 4 lines
1.7.3.3

Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 4 lines · Kenneth Heitke

From: Sagar Dharia <[email protected]>

SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance.

Hi Kenneth and Sagar,

On a very high level, I think the driver is in the right place here, and it's appropriate to have a new bus type along with similar existing bus_types like i2c. It's also good to see that you have a good documentation file for this bus.

My main issue with the driver is the device registration method that now looks a bit aged. More about this below.

Quoted 16 lines
drivers/slimbus/slimbus.c new file +16 -0
+
+struct device slimbus_dev = {
+	.init_name = "slimbus",
+};
+
+static void __exit slimbus_exit(void)
+{
+	device_unregister(&slimbus_dev);
+	bus_unregister(&slimbus_type);
+}
+
+static int __init slimbus_init(void)
+{
+	int retval;
+
+	retval = bus_register(&slimbus_type);

drivers/slimbus/slimbus.c line 172

Quoted 10 lines
drivers/slimbus/slimbus.c new file +10 -0
+	if (!retval)
+		retval = device_register(&slimbus_dev);
+
+	if (retval)
+		bus_unregister(&slimbus_type);
+
+	return retval;
+}
+postcore_initcall(slimbus_init);
+module_exit(slimbus_exit);

Why do you need slimbus_dev? I think it would be cleaner to set the parent of each controller to the device that actually acts as their physical parent, e.g. an SOC device or an AMBA bus.

Quoted 37 lines
drivers/slimbus/slimbus.c new file +37 -0
+static int slim_drv_probe(struct device *dev)
+{
+	const struct slim_driver *sdrv = to_slim_driver(dev->driver);
+
+	if (sdrv->probe)
+		return sdrv->probe(to_slim_device(dev));
+	return -ENODEV;
+}
+
+static int slim_drv_remove(struct device *dev)
+{
+	const struct slim_driver *sdrv = to_slim_driver(dev->driver);
+
+	if (sdrv->remove)
+		return sdrv->remove(to_slim_device(dev));
+	return -ENODEV;
+}
+
+static void slim_drv_shutdown(struct device *dev)
+{
+	const struct slim_driver *sdrv = to_slim_driver(dev->driver);
+
+	if (sdrv->shutdown)
+		sdrv->shutdown(to_slim_device(dev));
+}
+
+/*
+ * slim_driver_register: Client driver registration with slimbus
+ * @drv:Client driver to be associated with client-device.
+ * This API will register the client driver with the slimbus
+ * It is called from the driver's module-init function.
+ */
+int slim_driver_register(struct slim_driver *drv)
+{
+	drv->driver.bus = &slimbus_type;
+	if (drv->probe)
+		drv->driver.probe = slim_drv_probe;

drivers/slimbus/slimbus.c line 220

Quoted 10 lines
drivers/slimbus/slimbus.c new file +10 -0
+
+	if (drv->remove)
+		drv->driver.remove = slim_drv_remove;
+
+	if (drv->shutdown)
+		drv->driver.shutdown = slim_drv_shutdown;
+
+	return driver_register(&drv->driver);
+}
+EXPORT_SYMBOL_GPL(slim_driver_register);

No need to check the ->probe/->remove/->shutdown fields twice.

Quoted 19 lines
drivers/slimbus/slimbus.c new file +19 -0
+/*
+ * slim_add_device: Add a new device without register board info.
+ * @ctrl: Controller to which this device is to be added to.
+ * Called when device doesn't have an explicit client-driver to be probed, or
+ * the client-driver is a module installed dynamically.
+ */
+int slim_add_device(struct slim_controller *ctrl, struct slim_device *sbdev)
+{
+	int ret = 0;
+
+	sbdev->dev.bus = &slimbus_type;
+	sbdev->dev.parent = ctrl->dev.parent;
+	sbdev->dev.type = &slim_dev_type;
+	sbdev->ctrl = ctrl;
+	slim_ctrl_get(ctrl);
+	dev_set_name(&sbdev->dev, "%s", sbdev->name);
+	/* probe slave on this controller */
+	ret = device_register(&sbdev->dev);
+

drivers/slimbus/slimbus.c line 292

Quoted 10 lines
drivers/slimbus/slimbus.c new file +10 -0
+	if (ret)
+		return ret;
+
+	mutex_init(&sbdev->sldev_reconf);
+	INIT_LIST_HEAD(&sbdev->mark_define);
+	INIT_LIST_HEAD(&sbdev->mark_suspend);
+	INIT_LIST_HEAD(&sbdev->mark_removal);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(slim_add_device);

I don't think this should be exported: AFAICT, the set of slim_devices is a property of the platform, so I don't see how any other device driver would add another device.

Quoted 19 lines
drivers/slimbus/slimbus.c new file +19 -0
+/*
+ * slim_register_board_info: Board-initialization routine.
+ * @info: List of all devices on all controllers present on the board.
+ * @n: number of entries.
+ * API enumerates respective devices on corresponding controller.
+ * Called from board-init function.
+ */
+int slim_register_board_info(struct slim_boardinfo const *info, unsigned n)
+{
+	struct sbi_boardinfo *bi;
+	int i;
+
+	bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
+	if (!bi)
+		return -ENOMEM;
+
+	for (i = 0; i < n; i++, bi++, info++) {
+		struct slim_controller *ctrl;
+

drivers/slimbus/slimbus.c line 345

Quoted 10 lines
drivers/slimbus/slimbus.c new file +10 -0
+		memcpy(&bi->board_info, info, sizeof(*info));
+		mutex_lock(&board_lock);
+		list_add_tail(&bi->list, &board_list);
+		list_for_each_entry(ctrl, &slim_ctrl_list, list)
+			slim_match_ctrl_to_boardinfo(ctrl, &bi->board_info);
+		mutex_unlock(&board_lock);
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(slim_register_board_info);

We are trying to gradually convert platforms that have hardcoded device lists and cannot probe devices by looking at the hardware over to using device tree files that list all the devices.

I think that this would work well for slimbus and should be done right from the start. This means however that you should not register a "board_info" but instead change the slim_register_controller function so that it adds all devices listed as children of the controller in the device tree.

Quoted 8 lines
drivers/slimbus/slimbus.c new file +8 -0
+/*
+ * slim_busnum_to_ctrl: Map bus number to controller
+ * @busnum: Bus number
+ * Returns controller representing this bus number
+ */
+struct slim_controller *slim_busnum_to_ctrl(u32 bus_num)
+{
+	struct slim_controller *ctrl;

drivers/slimbus/slimbus.c line 364

Quoted 10 lines
drivers/slimbus/slimbus.c new file +10 -0
+	mutex_lock(&board_lock);
+	list_for_each_entry(ctrl, &slim_ctrl_list, list)
+		if (bus_num == ctrl->nr) {
+			mutex_unlock(&board_lock);
+			return ctrl;
+		}
+	mutex_unlock(&board_lock);
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(slim_busnum_to_ctrl);

What is this function used for? I would expect that no other driver should care about bus numbers if you get the probing right.

drivers/slimbus/slimbus.c line 520

Quoted 8 lines
drivers/slimbus/slimbus.c new file +8 -0
+/*
+ * slim_add_numbered_controller: Controller bring-up.
+ * @ctrl: Controller to be registered.
+ * A controller is registered with the framework using this API. ctrl->nr is the
+ * desired number with which slimbus framework registers the controller.
+ * Function will return -EBUSY if the number is in use.
+ */
+int slim_add_numbered_controller(struct slim_controller *ctrl)

Same for this one.

drivers/slimbus/slimbus.c line 1703

Quoted 2 lines
drivers/slimbus/slimbus.c new file +2 -0
+static int slim_sched_chans(struct slim_device *sb, u32 clkgear,
+			u32 *ctrlw, u32 *subfrml)

I don't understand what this function does, but I can see that it's too long to be readable. Please just split it into smaller functions.

Arnd

#2 lore raw
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · Kenneth Heitke

From: Sagar Dharia<[email protected]>

SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance.

Hi Kenneth and Sagar,

Quoted 8 lines

On a very high level, I think the driver is in the right place here, and it's appropriate to have a new bus type along with similar existing bus_types like i2c. It's also good to see that you have a good documentation file for this bus.

My main issue with the driver is the device registration method that now looks a bit aged. More about this below.

Arnd,

Thank you for taking the time to review the driver. I appreciate your comments and will roll them in to the next revision of the driver. I'll also try to follow up with any questions and concerns that you raised.

thanks,
Ken

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#3 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann
Quoted 1 line · Kenneth Heitke

+EXPORT_SYMBOL_GPL(slim_add_device);

I don't think this should be exported: AFAICT, the set of slim_devices is a property of the platform, so I don't see how any other device driver would add another device.

The platform may be comprised of multiple hardwaare modules with functionality on daughtercards which can be probed at runtime. You may also find someone constructing a PCI card or something with a slimbus controller on it at some point.

Quoted 11 lines
Quoted 1 line

+EXPORT_SYMBOL_GPL(slim_register_board_info);

We are trying to gradually convert platforms that have hardcoded device lists and cannot probe devices by looking at the hardware over to using device tree files that list all the devices.

I think that this would work well for slimbus and should be done right from the start. This means however that you should not register a "board_info" but instead change the slim_register_controller function so that it adds all devices listed as children of the controller in the device tree.

It seems a bit extreme to prevent anyone implementing a subsystem for their platform until they've converted it into device tree. Though with slimbus it should be at least somewhat probeable IIRC?

#4 lore raw
Quoted 5 lines · Mark Brown
Quoted 3 lines · Arnd Bergmann
Quoted 1 line · Kenneth Heitke

+EXPORT_SYMBOL_GPL(slim_add_device);

Quoted 8 lines
Quoted 3 lines

I don't think this should be exported: AFAICT, the set of slim_devices is a property of the platform, so I don't see how any other device driver would add another device.

The platform may be comprised of multiple hardwaare modules with functionality on daughtercards which can be probed at runtime. You may also find someone constructing a PCI card or something with a slimbus controller on it at some point.

This is theoretically true, but IIRC David mentioned that the bus is only present on few SoCs and has since been abandoned in favor of standard busses for new devices.

Quoted 12 lines
Quoted 11 lines
Quoted 1 line

+EXPORT_SYMBOL_GPL(slim_register_board_info);

We are trying to gradually convert platforms that have hardcoded device lists and cannot probe devices by looking at the hardware over to using device tree files that list all the devices.

I think that this would work well for slimbus and should be done right from the start. This means however that you should not register a "board_info" but instead change the slim_register_controller function so that it adds all devices listed as children of the controller in the device tree.

Quoted 5 lines

It seems a bit extreme to prevent anyone implementing a subsystem for their platform until they've converted it into device tree. Though with slimbus it should be at least somewhat probeable IIRC?

From what I've heard (and seen in the code), there is no support for

probing, just like in I2C.
The platform is in the process of getting converted to device tree already, the first patches were posted on Saturday. I don't know what the timeline is for this, or how many board with slimbus are supported in mainline or still waiting to get merged, but my guess is that the bulk is still out of tree. If that's true, it's definitely cleaner to convert it over to device tree before merging, instead of having to change all the board files again when doing the conversion.

Arnd

#5 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Mark Brown
Quoted 7 lines · Arnd Bergmann
Quoted 1 line · Kenneth Heitke

+EXPORT_SYMBOL_GPL(slim_add_device);

I don't think this should be exported: AFAICT, the set of slim_devices is a property of the platform, so I don't see how any other device driver would add another device.

Quoted 8 lines
Quoted 4 lines

The platform may be comprised of multiple hardwaare modules with functionality on daughtercards which can be probed at runtime. You may also find someone constructing a PCI card or something with a slimbus controller on it at some point.

This is theoretically true, but IIRC David mentioned that the bus is only present on few SoCs and has since been abandoned in favor of standard busses for new devices.

Actually, this is a different one than the one I was mentioning at the Linaro Connect. I believe SLIMbus is more active
http://en.wikipedia.org/wiki/SLIMbus

The other bus I was mentioning is called SSBI, which as far as I know is only used to communicate between MSMs and certain Qualcomm peripheral chips.

Kenneth would better be able to clarify how dynamic the SLIMbus is.

David

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#6 lore raw
Quoted 6 lines · David Brown
Quoted 3 lines · Arnd Bergmann

This is theoretically true, but IIRC David mentioned that the bus is only present on few SoCs and has since been abandoned in favor of standard busses for new devices.

Quoted 7 lines

Actually, this is a different one than the one I was mentioning at the Linaro Connect. I believe SLIMbus is more active
http://en.wikipedia.org/wiki/SLIMbus

The other bus I was mentioning is called SSBI, which as far as I know is only used to communicate between MSMs and certain Qualcomm peripheral chips.

Thanks for the clarification! I assumed these were the same thing because the patches were posted just after we had talked about the other one.

Quoted 1 line

Kenneth would better be able to clarify how dynamic the SLIMbus is.

That would definitely be helpful. Also, I'd be very interested to hear what kind of device probing is available on slimbus. If Mark was right about devices being discoverable, we need don't need any board description (dts or hardcoded) but instead a way to match the devices to drivers based on their HW ID.

Arnd

#7 lore raw
Quoted 5 lines · Arnd Bergmann

That would definitely be helpful. Also, I'd be very interested to hear what kind of device probing is available on slimbus. If Mark was right about devices being discoverable, we need don't need any board description (dts or hardcoded) but instead a way to match the devices to drivers based on their HW ID.

I wouldn't go that far - apart from anything else this is designed for deployment into cellphones and simlar high end systems where you've got external components to bolt on somehow, and as we're only just starting to see silicon coming onto the market we'll have to see exactly what things look like. This stuff is intended for markets where people bolt their systems together in very custom ways so automatic discovery is not a high priority.

#8 lore raw
In reply to Arnd Bergmann
Quoted 20 lines · Arnd Bergmann
Quoted 6 lines · David Brown
Quoted 3 lines · Arnd Bergmann

This is theoretically true, but IIRC David mentioned that the bus is only present on few SoCs and has since been abandoned in favor of standard busses for new devices.

Quoted 7 lines

Actually, this is a different one than the one I was mentioning at the Linaro Connect. I believe SLIMbus is more active
http://en.wikipedia.org/wiki/SLIMbus

The other bus I was mentioning is called SSBI, which as far as I know is only used to communicate between MSMs and certain Qualcomm peripheral chips.

Thanks for the clarification! I assumed these were the same thing because the patches were posted just after we had talked about the other one.

Quoted 1 line

Kenneth would better be able to clarify how dynamic the SLIMbus is.

Quoted 8 lines

That would definitely be helpful. Also, I'd be very interested to hear what kind of device probing is available on slimbus. If Mark was right about devices being discoverable, we need don't need any board description (dts or hardcoded) but instead a way to match the devices to drivers based on their HW ID.

Arnd

SLIMbus is a MIPI standard bus primarily used for digital audio devices.
The devices on the bus SLIMbus enumerate themselves by sending an
IDENTITY message. I'll let Sagar clarify further.

thanks,
Ken

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#10 lore raw
In reply to Kenneth Heitke
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

Kenneth would better be able to clarify how dynamic the SLIMbus is.

That would definitely be helpful. Also, I'd be very interested to hear what kind of device probing is available on slimbus. If Mark was right about devices being discoverable, we need don't need any board description (dts or hardcoded) but instead a way to match the devices to drivers based on their HW ID.

Quoted 6 lines
Quoted 2 lines

Arnd

SLIMbus is a MIPI standard bus primarily used for digital audio devices.
The devices on the bus SLIMbus enumerate themselves by sending an
IDENTITY message. I'll let Sagar clarify further.

Thanks everyone for taking your time to review the RFC. Regarding device discovery:
Every device sends a "PRESENT" message when it comes up. Every device has 48-bit address like Ethernet and spec lets upto 256 devices (each getting 8-bit logical address) on one bus.
The device can report anytime (when it's plugged in, when a dynamic module powers it on etc.)
Typical use case will be to have it board-specific but as Mark mentioned,we may have plug-in cards with slimbus devices so we want dynamic support as well.

Thanks-
-Sagar

Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

#11 lore raw
Quoted 5 lines · On Tuesday 16 August 2011 10:44:35 [email protected] wrote:
Quoted 4 lines

SLIMbus is a MIPI standard bus primarily used for digital audio devices.
The devices on the bus SLIMbus enumerate themselves by sending an
IDENTITY message. I'll let Sagar clarify further.

Quoted 10 lines

Thanks everyone for taking your time to review the RFC. Regarding device discovery:
Every device sends a "PRESENT" message when it comes up. Every device has 48-bit address like Ethernet and spec lets upto 256 devices (each getting 8-bit logical address) on one bus.
The device can report anytime (when it's plugged in, when a dynamic module powers it on etc.)
Typical use case will be to have it board-specific but as Mark mentioned,we may have plug-in cards with slimbus devices so we want dynamic support as well.

Thanks for the info. The part that I still don't understand is how the 48-bit address and the 8 bit address are chosen. Do you mean that the 8-bit address identifies the location on the bus and is used when talking to the device locally while the 48-bit address is globally unique and different for each individual board?

In that case, we would still not have any way to identify the type of device, other than using a look-up table of 8-bit addresses to device names (or numbers).

Or does the 48-bit number actually tell us something about what device we're talking to, e.g. 24 bit vendor plus 24 bit device type and revision or such. If that's the case, the number needs to be the primary key that gets used to identify the driver, just like we do it in case of USB or PCI devices.

Arnd

#12 lore raw
Quoted 27 lines · Arnd Bergmann
Quoted 5 lines · On Tuesday 16 August 2011 10:44:35 [email protected] wrote:
Quoted 4 lines

SLIMbus is a MIPI standard bus primarily used for digital audio devices.
The devices on the bus SLIMbus enumerate themselves by sending an
IDENTITY message. I'll let Sagar clarify further.

Quoted 10 lines

Thanks everyone for taking your time to review the RFC. Regarding device discovery:
Every device sends a "PRESENT" message when it comes up. Every device has 48-bit address like Ethernet and spec lets upto 256 devices (each getting 8-bit logical address) on one bus.
The device can report anytime (when it's plugged in, when a dynamic module powers it on etc.)
Typical use case will be to have it board-specific but as Mark mentioned,we may have plug-in cards with slimbus devices so we want dynamic support as well.

Thanks for the info. The part that I still don't understand is how the 48-bit address and the 8 bit address are chosen. Do you mean that the 8-bit address identifies the location on the bus and is used when talking to the device locally while the 48-bit address is globally unique and different for each individual board?

In that case, we would still not have any way to identify the type of device, other than using a look-up table of 8-bit addresses to device names (or numbers).

Quoted 8 lines

Or does the 48-bit number actually tell us something about what device we're talking to, e.g. 24 bit vendor plus 24 bit device type and revision or such. If that's the case, the number needs to be the primary key that gets used to identify the driver, just like we do it in case of USB or PCI devices.

Arnd

The 8-bit address is a logical address that is assigned by the SLIMbus framework. The framework maintains the mapping of logical addresses to the 48-bit Enumeration Address (EA). The 8-bit logical address is then used for any further SLIMbus device addressing.

The slim_get_logical_addr() API call is used by the client drivers to get the logical address that has been assigned to the device.

For the proposed implementation, the client drivers are probed before their devices are discovered because the client driver may need to power-up the device or pull it out of reset. Once the device is powered up, the call to get_logical_address() will let the client know whether or not their device has enumerated.

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#13 lore raw
Quoted 5 lines · Kenneth Heitke

For the proposed implementation, the client drivers are probed before their devices are discovered because the client driver may need to power-up the device or pull it out of reset. Once the device is powered up, the call to get_logical_address() will let the client know whether or not their device has enumerated.

There's a callback generated to left the client know when this has happened I'd expect?

#14 lore raw
Quoted 11 lines · Kenneth Heitke
Quoted 6 lines

For the proposed implementation, the client drivers are probed before their devices are discovered because the client driver may need to power-up the device or pull it out of reset. Once the device is powered up, the call to get_logical_address() will let the client know whether or not their device has enumerated.

There's a callback generated to left the client know when this has happened I'd expect?

As of now, there is no callback to notify them. They can either query it during 1st transaction, or retry with some delay in the probe itself. Callback is a good idea and we can definitely use it to inform clients that their device has come up.

Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

#15 lore raw
Quoted 9 lines · Sagar Dharia
Quoted 4 lines · Kenneth Heitke

There's a callback generated to left the client know when this has happened I'd expect?

As of now, there is no callback to notify them. They can either query it during 1st transaction, or retry with some delay in the probe itself. Callback is a good idea and we can definitely use it to inform clients that their device has come up.

It's pretty much essential, I'd expect slimbus devices will want to provide always on functionality like accessory detection which there's no reason to delay.

#16 lore raw
In reply to Kenneth Heitke
Quoted 12 lines · On Tuesday 16 August 2011 17:27:05 Kenneth Heitke wrote:
Quoted 5 lines · Arnd Bergmann

Or does the 48-bit number actually tell us something about what device we're talking to, e.g. 24 bit vendor plus 24 bit device type and revision or such. If that's the case, the number needs to be the primary key that gets used to identify the driver, just like we do it in case of USB or PCI devices.

The 8-bit address is a logical address that is assigned by the SLIMbus framework. The framework maintains the mapping of logical addresses to the 48-bit Enumeration Address (EA). The 8-bit logical address is then used for any further SLIMbus device addressing.

Quoted 8 lines

The slim_get_logical_addr() API call is used by the client drivers to get the logical address that has been assigned to the device.

For the proposed implementation, the client drivers are probed before their devices are discovered because the client driver may need to power-up the device or pull it out of reset. Once the device is powered up, the call to get_logical_address() will let the client know whether or not their device has enumerated.

Hmm, I looked at http://www.national.com/assets/en/other/intro_to_SLIMbus.pdf
which contains:

| SLIMbusTM uses a 48-bit Enumeration Addresses (EA) to
| uniquely identify Devices which can announce
| their presence on the bus. Each Device has an EA,
| which incorporates Manufacturer ID, Product Code,
| Device Index, and Instance Value for a Device. The
| Manufacturer ID code is supplied by the MIPI
| Alliance and uniquely identifies the manufacturer
| of the Device, similar to the manufacturer IDs used with
| PCI bus components. The Device Index code uniquely
| identifies multiple Devices within a single
| Component. The Instance Value code is for the case
| where multiple Devices of the same type or Class
| are attached to the bus.

Based on this, I would strongly suggest a different model to the one that you are suggesting:

* Make each device driver assume that the device is powered on when talking to it.
* Make the EA (minus the index/instance ID) the primary identifier for a device driver, not an arbitrary string.
* Move the logic for enabling and disabling devices into a host specific driver that takes care of powering the devices up initially, identifying them and putting them into run-time PM disabled state when no driver was found or the device is unused.

This will make it possible to reuse the same driver for multiple machines that have the same endpoint devices, while moving all the board specific clock and reset logic into a separate driver, which can be very small in many cases.

I would guess that in many cases, the logic for enabling the devices fits into the slimbus host driver. If that is not the case, e.g. when a lot of machines have the same host controller but each of them uses a different way to get the devices out of reset, you can turn the host driver into a library that contains the actual code accessing the host controller registers, but provide a per-machine platform_driver that known how to enable the individual devices and uses the library code from the main host driver to talk to the devices.

Arnd

#17 lore raw
Quoted 9 lines · Arnd Bergmann

* Move the logic for enabling and disabling devices into a host specific driver that takes care of powering the devices up initially, identifying them and putting them into run-time PM disabled state when no driver was found or the device is unused.

This will make it possible to reuse the same driver for multiple machines that have the same endpoint devices, while moving all the board specific clock and reset logic into a separate driver, which can be very small in many cases.

There should be no more need for this with slimbus than there is with any of our other buses - this sort of dynamic enable and disable is already standard practice for devices in embedded systems. There's some stuff it'd be good to do here but it shouldn't be driver specific, it should be a generic device model thing. The main problem cases right now are things like USB which currently assume there's no magic going on outside of the bus.

One thing I've wanted to do for a while but never quite got the time to look at yet is to add support for automatically enabling and disabling regulators along with the probe, remove, suspend and runtime suspend paths. If there's sufficient hooks for that they should also be usable for anything that is suitably board specific.

Quoted 4 lines

I would guess that in many cases, the logic for enabling the devices fits into the slimbus host driver. If that is not the case, e.g. when a lot of machines have the same host controller but each of them uses a different way to get the devices out of reset, you can turn the host

I'd expect that bringing the device out of reset is going to be largely unrelated to the host controller, it's going to be GPIOs, clocks and regulators. The individual drivers are going to want to manage this stuff dynamically at runtime too.

#18 lore raw
Quoted 12 lines · Mark Brown
Quoted 9 lines · Arnd Bergmann

* Move the logic for enabling and disabling devices into a host specific driver that takes care of powering the devices up initially, identifying them and putting them into run-time PM disabled state when no driver was found or the device is unused.

This will make it possible to reuse the same driver for multiple machines that have the same endpoint devices, while moving all the board specific clock and reset logic into a separate driver, which can be very small in many cases.

Quoted 7 lines

There should be no more need for this with slimbus than there is with any of our other buses - this sort of dynamic enable and disable is already standard practice for devices in embedded systems. There's some stuff it'd be good to do here but it shouldn't be driver specific, it should be a generic device model thing. The main problem cases right now are things like USB which currently assume there's no magic going on outside of the bus.

My main point here is not how the enable/disable is handled but how the bus is probed. It's a bit unfortunate that the initial slimbus code was modeled after i2c and spi, when it's really more like USB in the sense that devices can (and should) actually be discovered using methods provided by the bus spec.

Quoted 5 lines

One thing I've wanted to do for a while but never quite got the time to look at yet is to add support for automatically enabling and disabling regulators along with the probe, remove, suspend and runtime suspend paths. If there's sufficient hooks for that they should also be usable for anything that is suitably board specific.

Yes, that would be nice.

Quoted 9 lines
Quoted 4 lines

I would guess that in many cases, the logic for enabling the devices fits into the slimbus host driver. If that is not the case, e.g. when a lot of machines have the same host controller but each of them uses a different way to get the devices out of reset, you can turn the host

I'd expect that bringing the device out of reset is going to be largely unrelated to the host controller, it's going to be GPIOs, clocks and regulators. The individual drivers are going to want to manage this stuff dynamically at runtime too.

But it's even less related to the individual driver than to the host. Clearly, the code for starting up the device has to live somewhere, but I think that should not be the device driver that is responsible for talking to the slimbus device itself, because that each board will do that slightly differently and the slimbus_driver should not need to know about the device before it has been found on the bus.

The way I see this working is that something outside of the driver should provide a way to enable each device in order for it to get probed, and the driver's ->probe callback does a pm_runtime_get() call when it wants to keep the device enabled.

Arnd

#19 lore raw
Quoted 4 lines · Arnd Bergmann

the bus is probed. It's a bit unfortunate that the initial slimbus code was modeled after i2c and spi, when it's really more like USB in the sense that devices can (and should) actually be discovered using methods provided by the bus spec.

Yeah, though in reality it's somewhere in between.

Quoted 6 lines
Quoted 4 lines

I'd expect that bringing the device out of reset is going to be largely unrelated to the host controller, it's going to be GPIOs, clocks and regulators. The individual drivers are going to want to manage this stuff dynamically at runtime too.

But it's even less related to the individual driver than to the host.

No, not at all - all the bus specifies is the two wire control interface, if a device on the bus requires power or anything else that's not something the CPU Slimbus (I keep wanting to typo that as Slumbus...) controller has any idea about. In this respect Slimbus is much more like I2C than USB where there's a standard provision for power even if embedded systems routinely ignore it.

The device driver will know what power supplies and other signals the device has, and it will know how and when to use them. This can generally be done independently of the board with just some platform or device tree data to configure GPIOs.

Quoted 5 lines

Clearly, the code for starting up the device has to live somewhere, but I think that should not be the device driver that is responsible for talking to the slimbus device itself, because that each board will do that slightly differently and the slimbus_driver should not need to know about the device before it has been found on the bus.

If we're going to do that we should do the same thing for at least I2C and SPI also. In terms of the board differences they're generally not hard to abstract.

One thing to bear in mind here is that in these sort of systems it's not uncommon for devices to want to dynamically manage their power at runtime, both partially removing supplies and going to complete power down (we've got drivers in the kernel at present which are doing that) depending on usage. The full power off is fairly straightforward but partial power states will mean complication as we have to work out how to hand the resources from the pre-driver code to the driver and back again.

Quoted 4 lines

The way I see this working is that something outside of the driver should provide a way to enable each device in order for it to get probed, and the driver's ->probe callback does a pm_runtime_get() call when it wants to keep the device enabled.

Some pre-cooked off the shelf device wide power management is definitely useful for simple cases but I don't think that scales to high end devices - it's too binary. Like I said I really do want to have some transparent device model way of handling the simple cases but we need to leave room for devices which want to do more complicated things.

It also occurs to me that if we're supporting going down to cold with runtime PM anyway the kernel is going to have to be able to understand the idea that devices it already knows about are going to hotplug in and out while staying registered. If we're doing that then it seems like the bus is going to have pretty much all the concepts required for explicit registration anyway.

#20 lore raw
Quoted 2 lines · Mark Brown

The device driver will know what power supplies and other signals the device has, and it will know how and when to use them. (...)

And I guess there is nothing in the spec claiming that all devices be powered-on when you boot?

In that case the devices living on that bus will not respond to discovery messages until they are powered on, will they?

Or is there some ingenious self-powered shift register logic doing these responses?

Yours,
Linus Walleij

#21 lore raw
Quoted 8 lines · Linus Walleij
Quoted 2 lines · Mark Brown

The device driver will know what power supplies and other signals the device has, and it will know how and when to use them. (...)

And I guess there is nothing in the spec claiming that all devices be powered-on when you boot?

I don't believe so, and if there were I'd not expect anyone to pay a blind bit of notice to it.

Quoted 5 lines

In that case the devices living on that bus will not respond to discovery messages until they are powered on, will they?

Or is there some ingenious self-powered shift register logic doing these responses?

If my memory serves (I don't have access to the relevant documents right now) the device announces itself when it detects that the bus is alive. Slimbus is a relatively heavyweight interface so the extra cost of doing this won't be too bad.

#22 lore raw
Quoted 4 lines · Mark Brown
Quoted 2 lines · Linus Walleij

On Wed, Aug 17, 2011 at 3:04 PM, Mark Brown
<[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The device driver will know what power supplies and other signals the device has, and it will know how and when to use them. (...)

And I guess there is nothing in the spec claiming that all devices be powered-on when you boot?

I don't believe so, and if there were I'd not expect anyone to pay a blind bit of notice to it.

That means that the regulators handling the slimbus devices will need to be enabled before the drivers issue regulator_get() and regulator_enable() on them.

Does the regulator constraint .always_on have this semantic effect, so the regulator framework can power up the devices without their drivers claiming the regulators first?

Or would we need a new .boot_enable flag to handle that?

Quoted 4 lines

If my memory serves (I don't have access to the relevant documents right now) the device announces itself when it detects that the bus is alive. Slimbus is a relatively heavyweight interface so the extra cost of doing this won't be too bad.

OK so if we can just power the device the bus can probably autodetect all devices on it, it seems.

Thanks,
Linus Walleij

#23 lore raw
Quoted 6 lines · Linus Walleij

On Thu, Aug 18, 2011 at 5:00 AM, Mark Brown

Quoted 4 lines · Linus Walleij
Quoted 3 lines

And I guess there is nothing in the spec claiming that all devices be powered-on when you boot?

Quoted 6 lines
Quoted 2 lines

I don't believe so, and if there were I'd not expect anyone to pay a blind bit of notice to it.

That means that the regulators handling the slimbus devices will need to be enabled before the drivers issue regulator_get() and regulator_enable() on them.

What makes you say that? We've been discussing how we register Slimbus devices other than via hotplug.

Quoted 3 lines

Does the regulator constraint .always_on have this semantic effect, so the regulator framework can power up the devices without their drivers claiming the regulators first?

It does have that effect but it would (as one might expect) force the regulators to always be on which is unacceptable for actual systems.

Quoted 1 line

Or would we need a new .boot_enable flag to handle that?

There is such a flag already.

Quoted 7 lines
Quoted 4 lines

If my memory serves (I don't have access to the relevant documents right now) the device announces itself when it detects that the bus is alive. Slimbus is a relatively heavyweight interface so the extra cost of doing this won't be too bad.

OK so if we can just power the device the bus can probably autodetect all devices on it, it seems.

Should be able to, yes, though we'll still need to bind platform/OF data to them.

#24 lore raw
Quoted 8 lines · Mark Brown
Quoted 3 lines · Linus Walleij

That means that the regulators handling the slimbus devices will need to be enabled before the drivers issue regulator_get() and regulator_enable() on them.

What makes you say that?  We've been discussing how we register Slimbus devices other than via hotplug.

OK it's founded in Arnd's remarks that the "Linux model" is to use auto-detection as much as possible, which means hotplug *and* coldplug, i.e. auto-discovery at boot, by probing the bus for devices.

If the device is not powered on boot I understand that it cannot be auto-discovered.

So then you need platform data or device tree or similar to register the device. Which is frowned upon, if there exist other ways to detect the hardware.

Quoted 6 lines
Quoted 3 lines

Does the regulator constraint .always_on have this semantic effect, so the regulator framework can power up the devices without their drivers claiming the regulators first?

It does have that effect but it would (as one might expect) force the regulators to always be on which is unacceptable for actual systems.

Aha, no good. :-(

Quoted 3 lines
Quoted 1 line

Or would we need a new .boot_enable flag to handle that?

There is such a flag already.

I really mean .boot_enable, not .boot_on.

.boot_enable would turn on the regulator at boot no matter whether it was on or not at boot, and make it possible for devcie drivers to turn it off later by regulator disable. Probably by turning it on but leaving the use_count at zero so that it'd be disabled after the initlevels if no device claimed it and explictly enabled it before that.

This would power the device during init so the bus could be probed for devices (coldplugged).

But maybe this is a misunderstanding on my side: maybe slimbus devices can be hotplugged and discovered, so the bus driver will tell you that a new device arrived, whereas it cannot be coldplugged, i.e. you cannot ask the bus to enumerate and say deliver the addresses to the devices on it?

Quoted 5 lines
Quoted 2 lines

OK so if we can just power the device the bus can probably autodetect all devices on it, it seems.

Should be able to, yes, though we'll still need to bind platform/OF data to them.

OK so what you're saying is that it can never be made to have self-contained drivers without any accompanying platform data or device tree info?

Thanks,
Linus Walleij

#25 lore raw
Quoted 11 lines · Linus Walleij

OK it's founded in Arnd's remarks that the "Linux model" is to use auto-detection as much as possible, which means hotplug *and* coldplug, i.e. auto-discovery at boot, by probing the bus for devices.

If the device is not powered on boot I understand that it cannot be auto-discovered.

So then you need platform data or device tree or similar to register the device. Which is frowned upon, if there exist other ways to detect the hardware.

Two problems with that. One is that that'll only work for regulators, not for GPIOs (eg, reset signals). The other is that if we're going to be pulling power from devices at runtime we're going to have to cope with live devices hotplugging underneath an already registered device at runtime so we've already got all the software cost of being able to preregister everything anyway so we may as well use it.

Quoted 6 lines

But maybe this is a misunderstanding on my side: maybe slimbus devices can be hotplugged and discovered, so the bus driver will tell you that a new device arrived, whereas it cannot be coldplugged, i.e. you cannot ask the bus to enumerate and say deliver the addresses to the devices on it?

Coldplugging should work.

Quoted 6 lines
Quoted 2 lines

Should be able to, yes, though we'll still need to bind platform/OF data to them.

OK so what you're saying is that it can never be made to have self-contained drivers without any accompanying platform data or device tree info?

Well, some devices might be able to work with no platform data but that's not going to be true in the general case.

#26 lore raw
In reply to Mark Brown
Quoted 15 lines · Mark Brown
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines

I'd expect that bringing the device out of reset is going to be largely unrelated to the host controller, it's going to be GPIOs, clocks and regulators. The individual drivers are going to want to manage this stuff dynamically at runtime too.

But it's even less related to the individual driver than to the host.

No, not at all - all the bus specifies is the two wire control interface, if a device on the bus requires power or anything else that's not something the CPU Slimbus (I keep wanting to typo that as Slumbus...) controller has any idea about. In this respect Slimbus is much more like I2C than USB where there's a standard provision for power even if embedded systems routinely ignore it.

Quoted 4 lines

The device driver will know what power supplies and other signals the device has, and it will know how and when to use them. This can generally be done independently of the board with just some platform or device tree data to configure GPIOs.

Ok, I think you've managed to get through to me ;-)

Quoted 11 lines
Quoted 4 lines

The way I see this working is that something outside of the driver should provide a way to enable each device in order for it to get probed, and the driver's ->probe callback does a pm_runtime_get() call when it wants to keep the device enabled.

Some pre-cooked off the shelf device wide power management is definitely useful for simple cases but I don't think that scales to high end devices - it's too binary. Like I said I really do want to have some transparent device model way of handling the simple cases but we need to leave room for devices which want to do more complicated things.

Quoted 6 lines

It also occurs to me that if we're supporting going down to cold with runtime PM anyway the kernel is going to have to be able to understand the idea that devices it already knows about are going to hotplug in and out while staying registered. If we're doing that then it seems like the bus is going to have pretty much all the concepts required for explicit registration anyway.

How about a mixed model then?

I can see three relevant cases to consider:

1. A simple potentially hotplugged device that registers itself to the bus can be automatically matched to the driver.
2. A device tree representation for hardwired devices that require something to happen in order to register to the bus (clock, regulator, ...).
3. A hardcoded list of devices on a slimbus host for stuff that is known to be there, e.g. on a PCI card that has its own driver and that also need some special setup as in case 2.

I think in all three cases, we should identify the device by its EA and match that to the device driver. We create the slim_device and register it to the bus as soon as one of the three above is found, but in case 2 and 3, the driver is responsible for the device to actually become active on the bus before it's allowed to send any commands to it.

For the device tree binding, I would suggest defining a slimbus bus to have #address-cells=1, #size-cells=0 and just put the EA into the reg property. This is enough for the host driver to add create a slim_device and match a driver to it. The driver can access all the properties from the device_node (or platform_data in case of statically defined devices). When the physical device shows up on the bus, it is automatically associated with the existing slim_device.

Arnd

#27 lore raw
Quoted 13 lines · Arnd Bergmann

How about a mixed model then?

I can see three relevant cases to consider:

1. A simple potentially hotplugged device that registers itself to the bus can be automatically matched to the driver.
2. A device tree representation for hardwired devices that require something to happen in order to register to the bus (clock, regulator, ...).
3. A hardcoded list of devices on a slimbus host for stuff that is known to be there, e.g. on a PCI card that has its own driver and that also need some special setup as in case 2.

Quoted 5 lines

I think in all three cases, we should identify the device by its EA and match that to the device driver. We create the slim_device and register it to the bus as soon as one of the three above is found, but in case 2 and 3, the driver is responsible for the device to actually become active on the bus before it's allowed to send any commands to it.

Yes, I think that makes sense and it matches what we're doing with the other subsystems well. We should be able to make the drivers work with all cases. Probably the probe function should have a flag and/or query function to let the driver know if the device has actually appeared yet.

Quoted 7 lines

For the device tree binding, I would suggest defining a slimbus bus to have #address-cells=1, #size-cells=0 and just put the EA into the reg property. This is enough for the host driver to add create a slim_device and match a driver to it. The driver can access all the properties from the device_node (or platform_data in case of statically defined devices). When the physical device shows up on the bus, it is automatically associated with the existing slim_device.

Sounds reasonable I'd need to actually look at the specs again for the details.

#28 lore raw
Quoted 18 lines
Quoted 11 lines

1. A simple potentially hotplugged device that registers itself to the bus
can be automatically matched to the driver.
2. A device tree representation for hardwired devices that require something to happen in order to register to the bus (clock,
regulator,
...).
3. A hardcoded list of devices on a slimbus host for stuff that is known to be there, e.g. on a PCI card that has its own driver and that also need some special setup as in case 2.

Quoted 6 lines

I think in all three cases, we should identify the device by its EA and match that to the device driver. We create the slim_device and register it to the bus as soon as one of the three above is found, but in case 2 and 3, the driver is responsible for the device to actually become active
on the bus before it's allowed to send any commands to it.

Quoted 5 lines

Yes, I think that makes sense and it matches what we're doing with the other subsystems well. We should be able to make the drivers work with all cases. Probably the probe function should have a flag and/or query function to let the driver know if the device has actually appeared yet.

Thanks again everyone for your feedback.
I will make sure to use the fields of the 48-bit elemental address for device-to-driver-matching and will try to incorporate hot-plug capabilities for the device powering up without assistance from the driver's probe function. Other cases discussed in the mixed-approach will be supported as well.
Another suggestion about probe is having callback to notify when the device is ready-to-use after driver probe powers it up. I will change the framework accordingly to have this done.

Quoted 10 lines
Quoted 7 lines

For the device tree binding, I would suggest defining a slimbus bus to have #address-cells=1, #size-cells=0 and just put the EA into the reg property. This is enough for the host driver to add create a slim_device and match a driver to it. The driver can access all the properties from the device_node (or platform_data in case of statically defined devices). When the physical device shows up on the bus, it is automatically associated with the existing slim_device.

Sounds reasonable I'd need to actually look at the specs again for the details.

I will try to incorporate device-tree binding in the framework and put it up for review for more suggestions.

-Sagar

Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

#29 lore raw
Quoted 3 lines · Sagar Dharia

Another suggestion about probe is having callback to notify when the device is ready-to-use after driver probe powers it up. I will change the framework accordingly to have this done.

Is this actually needed? If the driver is responsible for powering up the device, maybe it's enough to have a simple exported function from the framework that blocks until the device has been probed, using a 'completion' or a similar wait_event() based primitive for waiting for the device:

1. The bus driver creates the struct slim_device in one of the three ways mentioned and does init_completion().
2. The probe function of the driver ensures that the regulators/clocks/... are set up correctly and then calls wait_for_completion()
3. When the device shows up on the bus, the slimbus layer calls complete().

Steps 2 and 3 can happen in any order.

Arnd

#30 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann
Quoted 3 lines · Mark Brown
Quoted 3 lines

I don't think this should be exported: AFAICT, the set of slim_devices is a property of the platform, so I don't see how any other device driver would add another device.

Quoted 8 lines
Quoted 4 lines

The platform may be comprised of multiple hardwaare modules with functionality on daughtercards which can be probed at runtime. You may also find someone constructing a PCI card or something with a slimbus controller on it at some point.

This is theoretically true, but IIRC David mentioned that the bus is only present on few SoCs and has since been abandoned in favor of standard busses for new devices.

No, that's not the case at all - I'm not sure what gave you that impression. This is new technology which is rolling out at the minute. It is a standard bus.

Quoted 6 lines
Quoted 3 lines

It seems a bit extreme to prevent anyone implementing a subsystem for their platform until they've converted it into device tree. Though with slimbus it should be at least somewhat probeable IIRC?

From what I've heard (and seen in the code), there is no support for probing, just like in I2C.

That's what the code does, yes. I'd need to recheck the spec but I do seem to recall some device IDs in there.

Quoted 7 lines

The platform is in the process of getting converted to device tree already, the first patches were posted on Saturday. I don't know what the timeline is for this, or how many board with slimbus are supported in mainline or still waiting to get merged, but my guess is that the bulk is still out of tree. If that's true, it's definitely cleaner to convert it over to device tree before merging, instead of having to change all the board files again when doing the conversion.

That's one platform, this is not at all constructive for other devices (or worse, architectures) implementing slimbus support. Insisting that new ARM platforms use device tree is one thing, insisting that new bus implementations only work with device tree is quite a different thing.

#31 lore raw
In reply to Kenneth Heitke
Quoted 2 lines · Kenneth Heitke

SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance.

Please CC me on any future spins of this patch.

Quoted 1 line

You ought to sign off the patch as well as you're part of the chain for it getting into the kernel.

drivers/slimbus/slimbus.c line 75

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+#ifdef CONFIG_PM_SLEEP
+static int slim_legacy_suspend(struct device *dev, pm_message_t mesg)
+{
+	struct slim_device *slim_dev = NULL;

Why have legacy stuff in a newly implemented subsystem?

drivers/slimbus/slimbus.c line 181

Quoted 8 lines
drivers/slimbus/slimbus.c new file +8 -0
+static int slim_drv_probe(struct device *dev)
+{
+	const struct slim_driver *sdrv = to_slim_driver(dev->driver);
+
+	if (sdrv->probe)
+		return sdrv->probe(to_slim_device(dev));
+	return -ENODEV;
+}

Why all the -ENODEVs if there's no function? I'd expect that if there's nothing to do it should be possible to omit functions from drivers.

drivers/slimbus/slimbus.c line 210

Quoted 5 lines
drivers/slimbus/slimbus.c new file +5 -0
+int slim_driver_register(struct slim_driver *drv)
+{
+	drv->driver.bus = &slimbus_type;
+	if (drv->probe)
+		drv->driver.probe = slim_drv_probe;

Modifying the driver structure seems icky, why is this needed? Other bus types appear to manage without.

drivers/slimbus/slimbus.c line 763

Quoted 5 lines
drivers/slimbus/slimbus.c new file +5 -0
+static u16 slim_slicecodefromsize(u32 req)
+{
+	u8 codetosize[8] = {1, 2, 3, 4, 6, 8, 12, 16};
+	if (req >= 8)
+		return 0;

ARRAY_SIZE()? I guess the table should be static too.

#32 lore raw
Quoted 7 lines · Mark Brown
Quoted 2 lines · Kenneth Heitke

SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance.

Please CC me on any future spins of this patch.

mark, thanks for reviewing the code. I will be sure to CC you in the future. I agree with your comments and will incorporate the changes in the next revision.

thanks,
Ken

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#33 lore raw
In reply to Kenneth Heitke
Quoted 16 lines · Kenneth Heitke

From: Sagar Dharia <[email protected]>

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. Commonly used digital audio interfaces such as I2S, PCM are intended for point-to-point connection between application processor and single audio device and support one or two channels. Adding more channels or functions is difficult without increasing number of bus structures and hence pin count. In parallel to audio channels, control buses such as I2C are typically used for low-bandwidth control tasks.
SLIMbus replaces many digital audio buses and control buses by providing flexible and dynamic bus-bandwidth between data-functions and control-functions.

Quoted 7 lines

The framework supports message APIs, channel scheduling for SLIMbus. Message APIs are used for status/control type of communication with a device. Data Channel APIs are used for setting data channels between SLIMbus devices.

Framework supports multiple busses (1 controller per bus) and multiple clients/slave devices per controller.

This looks like another bus doing the same thing as SPI and I2C.

We seem to be having a growing number of bus_types which:

1. Supply some kind of boardinfo array containing device names against a device.

struct i2c_board_info {
        char            type[I2C_NAME_SIZE];
        unsigned short  flags;
        unsigned short  addr;
        void            *platform_data;
        struct dev_archdata     *archdata;
        struct device_node *of_node;
        int             irq;
};
struct spi_board_info {
        char            modalias[SPI_NAME_SIZE];
        const void      *platform_data;
        void            *controller_data;
        int             irq;
        u32             max_speed_hz;
        u16             bus_num;
        u16             chip_select;
        u8              mode;
};

2. match drivers to this against (i2c) type (spi) modalias.

3. drivers contain essentially the same ID structure:
#define I2C_NAME_SIZE 20
#define I2C_MODULE_PREFIX "i2c:"

struct i2c_device_id {
        char name[I2C_NAME_SIZE];
        kernel_ulong_t driver_data      /* Data private to the driver */
                        __attribute__((aligned(sizeof(kernel_ulong_t))));
};
#define SPI_NAME_SIZE   32
#define SPI_MODULE_PREFIX "spi:"
struct spi_device_id {
        char name[SPI_NAME_SIZE];
        kernel_ulong_t driver_data      /* Data private to the driver */
                        __attribute__((aligned(sizeof(kernel_ulong_t))));
};

+#define SLIMBUS_NAME_SIZE 32
+#define SLIMBUS_MODULE_PREFIX "slim:"
+struct slim_device_id {
+ char name[SLIMBUS_NAME_SIZE];
+ kernel_ulong_t driver_data /* Data private to the driver */
+ __attribute__((aligned(sizeof(kernel_ulong_t))));
+};

I heard of another bus type at the recent Linaro conference which sounds like it's going to do yet again a similar thing. So it sounds like we're heading for about four of these things.

Is there any way to consolidate this before we end up with four ways of solving the same problem?

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#34 lore raw
Quoted 27 lines · Russell King
Quoted 16 lines · Kenneth Heitke

From: Sagar Dharia<[email protected]>

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. Commonly used digital audio interfaces such as I2S, PCM are intended for point-to-point connection between application processor and single audio device and support one or two channels. Adding more channels or functions is difficult without increasing number of bus structures and hence pin count. In parallel to audio channels, control buses such as I2C are typically used for low-bandwidth control tasks.
SLIMbus replaces many digital audio buses and control buses by providing flexible and dynamic bus-bandwidth between data-functions and control-functions.

Quoted 7 lines

The framework supports message APIs, channel scheduling for SLIMbus. Message APIs are used for status/control type of communication with a device. Data Channel APIs are used for setting data channels between SLIMbus devices.

Framework supports multiple busses (1 controller per bus) and multiple clients/slave devices per controller.

This looks like another bus doing the same thing as SPI and I2C.

...

Quoted 8 lines

I heard of another bus type at the recent Linaro conference which sounds like it's going to do yet again a similar thing. So it sounds like we're heading for about four of these things.

Is there any way to consolidate this before we end up with four ways of solving the same problem?

I agree and am certainly open to suggestions. SPMI is another MIPI standard bus that is likely going to fall into the same category.

thanks,
Ken

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#35 lore raw
In reply to Russell King

Hi Russell,

Quoted 68 lines · Russell King
Quoted 16 lines · Kenneth Heitke

From: Sagar Dharia <[email protected]>

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. Commonly used digital audio interfaces such as I2S, PCM are intended for point-to-point connection between application processor and single audio device and support one or two channels. Adding more channels or functions is difficult without increasing number of bus structures and hence pin count. In parallel to audio channels, control buses such as I2C are typically used for low-bandwidth control tasks.
SLIMbus replaces many digital audio buses and control buses by providing flexible and dynamic bus-bandwidth between data-functions and control-functions.

Quoted 7 lines

The framework supports message APIs, channel scheduling for SLIMbus. Message APIs are used for status/control type of communication with a device. Data Channel APIs are used for setting data channels between SLIMbus devices.

Framework supports multiple busses (1 controller per bus) and multiple clients/slave devices per controller.

This looks like another bus doing the same thing as SPI and I2C.

We seem to be having a growing number of bus_types which:

1. Supply some kind of boardinfo array containing device names against a device.

struct i2c_board_info {
        char            type[I2C_NAME_SIZE];
        unsigned short  flags;
        unsigned short  addr;
        void            *platform_data;
        struct dev_archdata     *archdata;
        struct device_node *of_node;
        int             irq;
};
struct spi_board_info {
        char            modalias[SPI_NAME_SIZE];
        const void      *platform_data;
        void            *controller_data;
        int             irq;
        u32             max_speed_hz;
        u16             bus_num;
        u16             chip_select;
        u8              mode;
};

2. match drivers to this against (i2c) type (spi) modalias.

3. drivers contain essentially the same ID structure:
#define I2C_NAME_SIZE 20
#define I2C_MODULE_PREFIX "i2c:"

struct i2c_device_id {
        char name[I2C_NAME_SIZE];
        kernel_ulong_t driver_data      /* Data private to the driver */
                        __attribute__((aligned(sizeof(kernel_ulong_t))));
};
#define SPI_NAME_SIZE   32
#define SPI_MODULE_PREFIX "spi:"
struct spi_device_id {
        char name[SPI_NAME_SIZE];
        kernel_ulong_t driver_data      /* Data private to the driver */
                        __attribute__((aligned(sizeof(kernel_ulong_t))));
};

include/linux/mod_devicetable.h struct spi_device_id { · line 437

Quoted 7 lines
include/linux/mod_devicetable.h +7 -0
+#define SLIMBUS_NAME_SIZE      32
+#define SLIMBUS_MODULE_PREFIX "slim:"
+struct slim_device_id {
+       char name[SLIMBUS_NAME_SIZE];
+       kernel_ulong_t driver_data      /* Data private to the driver */
+                       __attribute__((aligned(sizeof(kernel_ulong_t))));
+};

The similarities are certainly due to the fact that spi and i2c were designed by the same person (David Brownell), and slimbus most probably was originally cloned from either. I'm glad we don't reinvent the wheel each time.

Quoted 6 lines

I heard of another bus type at the recent Linaro conference which sounds like it's going to do yet again a similar thing. So it sounds like we're heading for about four of these things.

Is there any way to consolidate this before we end up with four ways of solving the same problem?

Each bus type has its own specificity, so I doubt we can make them all fit in a single model. Of course they have common points, but USB and PCI also do to some extent, still we don't have a common framework for these.

At this point I am unsure, what problem you are trying to solve exactly. The amount of code you refer to above is low, so I see very little room for improvement. But if you have a concrete proposal, I am ready to evaluate it.

Signature · 1 line
Jean Delvare
#36 lore raw
In reply to Russell King
Quoted 6 lines · Russell King
Quoted 2 lines · Kenneth Heitke

SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance.

This looks like another bus doing the same thing as SPI and I2C.

It's got some similarities with I2C and SPI but there's some important diffferences too, in terms of software it's got many of the features of things like USB - there's data channels, bus wide clocking and a probe mechanism.

Quoted 4 lines

3. drivers contain essentially the same ID structure:
#define I2C_NAME_SIZE 20
#define I2C_MODULE_PREFIX "i2c:"
struct i2c_device_id {

In this case the IDs should definitely be different as there's IDs in the hardware which drivers ought to be able to bind to (in theory the bus can be hotplugged).

I do agree that there's room for some code sharing with the non-probeable buses.

#37 lore raw
In reply to Kenneth Heitke
Quoted 47 lines · On Wed, 10 Aug 2011 17:31:28 -0600 Kenneth Heitke wrote:

From: Sagar Dharia <[email protected]>

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. Commonly used digital audio interfaces such as I2S, PCM are intended for point-to-point connection between application processor and single audio device and support one or two channels. Adding more channels or functions is difficult without increasing number of bus structures and hence pin count. In parallel to audio channels, control buses such as I2C are typically used for low-bandwidth control tasks.
SLIMbus replaces many digital audio buses and control buses by providing flexible and dynamic bus-bandwidth between data-functions and control-functions.

The framework supports message APIs, channel scheduling for SLIMbus. Message APIs are used for status/control type of communication with a device. Data Channel APIs are used for setting data channels between SLIMbus devices.

Framework supports multiple busses (1 controller per bus) and multiple clients/slave devices per controller.

---
 Documentation/slimbus/slimbus-framework.txt |  282 +++
 drivers/Kconfig                             |    2 +
 drivers/Makefile                            |    1 +
 drivers/slimbus/Kconfig                     |   10 +
 drivers/slimbus/Makefile                    |    4 +
 drivers/slimbus/slimbus.c                   | 2629 +++++++++++++++++++++++++++
 include/linux/mod_devicetable.h             |    9 +
 include/linux/slimbus/slimbus.h             |  939 ++++++++++
 8 files changed, 3876 insertions(+), 0 deletions(-)
 create mode 100755 Documentation/slimbus/slimbus-framework.txt
 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/slimbus.h
Documentation/slimbus/slimbus-framework.txt new file +0 -0
new file mode 100755
index 0000000..a091417

Documentation/slimbus/slimbus-framework.txt line 7

Quoted 7 lines
Documentation/slimbus/slimbus-framework.txt new file +7 -0
@@ -0,0 +1,282 @@
+Introduction
+============
+
+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. Commonly used digital audio interfaces such as I2S, PCM are intended for

I2S and PCM

Quoted 11 lines
Documentation/slimbus/slimbus-framework.txt new file +11 -0
+point-to-point connection between application processor and single audio device
+and support one or two channels. Adding more channels or functions is difficult
+without increasing number of bus structures and hence pin count. In parallel to
+audio channels, control buses such as I2C are typically used for low-bandwidth
+control tasks.
+
+Slimbus replaces many digital audio buses and control buses by providing
+flexible and dynamic bus-bandwidth between data-functions and control-functions.
+
+
+

Documentation/slimbus/slimbus-framework.txt line 28

Quoted 10 lines
Documentation/slimbus/slimbus-framework.txt new file +10 -0
+Hardware Description
+====================
+
+Slimbus is a 2-wire multi-drop interface and uses TDM frame structure.
+The devices communicate over a shared bus using predefined transport protocols.
+There are 2 different type of transports.
+
+The message transport is used for various control functions such as bus
+management, configuration and status updates. Messages are seen by all devices
+and the messages can be of unicast and broadcast type. e.g. Reading/writing

E.g., reading/writing

Documentation/slimbus/slimbus-framework.txt line 30

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+device specific values is typically a unicast message. A data channel
+reconfiguration sequence is announced to all devices using broadcast message.

using a broadcast message.

Documentation/slimbus/slimbus-framework.txt line 37

Quoted 7 lines
Documentation/slimbus/slimbus-framework.txt new file +7 -0
+
+A data transport is used for data-transfer between 2 Slimbus devices. Data
+transport uses dedicated ports on the device. This data-transfer is not seen
+by all devices.
+
+Slimbus specification has different types of device classifications based on
+their capabilities. Manager device is responsible for enumeration,

A manager device

Documentation/slimbus/slimbus-framework.txt line 39

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+configuration, and dynamic channel allocation. Every bus has 1 active manager.
+Framer device is responsible for driving clock line and placing information on

A framer device is responsible for driving the clock line

[There are lots of missing article adjectives here for some reason.]

Documentation/slimbus/slimbus-framework.txt line 40

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+data line. Multiple framers may exist on a bus and manager is responsible for

the data line. and a manager is

Documentation/slimbus/slimbus-framework.txt line 45

Quoted 5 lines
Documentation/slimbus/slimbus-framework.txt new file +5 -0
+doing framer-handoffs. (Not supported in the SW driver right now).
+
+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 of its previous gear.

to be twice its previous gear.

Documentation/slimbus/slimbus-framework.txt line 47

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+
+Generic device is a device providing Slimbus functionality and typically has

A generic device

Documentation/slimbus/slimbus-framework.txt line 51

Quoted 4 lines
Documentation/slimbus/slimbus-framework.txt new file +4 -0
+ports for data-channel support. Its registers are mapped as 'value elements'
+so that they can be written/read using Slimbus message transport for
+exchanging control/status type of information. Generic devices are also referred
+to as 'clients' in this document from here-onwards.

here onward.

Documentation/slimbus/slimbus-framework.txt line 56

Quoted 5 lines
Documentation/slimbus/slimbus-framework.txt new file +5 -0
+
+Each device has a 6-byte elemental-address and the manager assigns every device
+with a 1-byte logical address after the devices report present on the bus.
+
+Slimbus uses TDM framing at the physical layer and has variable number of

and has a variable

Documentation/slimbus/slimbus-framework.txt line 58

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+frames used for messaging and data-channels. The TDM framing is out of scope
+of this document since clients can not directly access or interfere with it.

cannot

Documentation/slimbus/slimbus-framework.txt line 71

Quoted 13 lines
Documentation/slimbus/slimbus-framework.txt new file +13 -0
+
+
+
+Software Description:
+====================
+
+Initialization/Bringup:
+-----------------------
+Each bus has one active manager and that is represented by slim_controller
+data structure. The controller is probed during initial kernel bring-up and it
+is responsible to probe other "Generic Devices" and "Framer Devices". All
+devices report present (Broadcast message) after they are probed and
+manager stores their elemental addresses and assigns logical addresses. Clients

the manager

Documentation/slimbus/slimbus-framework.txt line 73

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+get their logical address by calling a public API in case they don't get
+interrupt after receiving the message.

an interrupt

Documentation/slimbus/slimbus-framework.txt line 75

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+
+Clients are added using similar logic to I2C. (There is one controller per

using logic similar to I2C.

Documentation/slimbus/slimbus-framework.txt line 79

Quoted 4 lines
Documentation/slimbus/slimbus-framework.txt new file +4 -0
+Slimbus who does active-manager duties. Each controller has a bus-number and
+the clients are populated in boards file on that controller). This way, it is
+more target-independent. In addition, clients can be added to the controller
+using add_device API. This is useful if the client is to be added later

using the add_device API.

Documentation/slimbus/slimbus-framework.txt line 86

Quoted 7 lines
Documentation/slimbus/slimbus-framework.txt new file +7 -0
+(as a module). It is also useful if each slave can have multiple elemental
+generic devices but only one driver. The generic device (slave) driver can then
+add more devices per its capability and still have 1 driver.
+
+Framers are also added per numbered controller and they are expected to
+initialize/enable clock related hardware in their probe. It may be common to
+have 1 driver for manager (controller) and framer. In that case, separate framer

a separate

Documentation/slimbus/slimbus-framework.txt line 87

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+device and/or driver is not needed. Framer handover can be used by controller to

by {a | the} controller

Documentation/slimbus/slimbus-framework.txt line 88

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+change framer per Slimbus spec, but the capability is not currently implemented

change the framer

Documentation/slimbus/slimbus-framework.txt line 94

Quoted 6 lines
Documentation/slimbus/slimbus-framework.txt new file +6 -0
+in this framework yet.
+
+Message-based APIs:
+-------------------
+As described earlier, control and status information can be exchanged on
+Slimbus. Slimbus client device driver can write/read control registers using the

A Slimbus client

Documentation/slimbus/slimbus-framework.txt line 96

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+message-based APIs for doing elemental accesses. Per Slimbus specification,
+there are two type of elements in every device. Value based (values can be

in every device:

Documentation/slimbus/slimbus-framework.txt line 98

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+read/written) and information based (bit-wise information can be set/cleared).
+Slimbus slave device driver can call these APIs. This typically replaces I2C

A Slimbus slave

Documentation/slimbus/slimbus-framework.txt line 99

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+type of control/status transaction. Framework makes sanity checks based on

The framework

Documentation/slimbus/slimbus-framework.txt line 100

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+Slimbus specification and then calls controller specific message transfer

and then calls a controller-specific

Documentation/slimbus/slimbus-framework.txt line 105

Quoted 5 lines
Documentation/slimbus/slimbus-framework.txt new file +5 -0
+function pointer. The sanity checks make sure that accesses to reserved-address
+space are not allowed, or the size of message isn't out-of-bounds per the
+specification.
+
+Messages are queued in a work-queue (per controller). Slimbus specification has

The Slimbus specification has a

Documentation/slimbus/slimbus-framework.txt line 106

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+transaction identification number (TID) for each transaction expecting response.

expecting a response.

Documentation/slimbus/slimbus-framework.txt line 107

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+The transaction message is kept per controller until response is received, or

until a response

Documentation/slimbus/slimbus-framework.txt line 110

Quoted 3 lines
Documentation/slimbus/slimbus-framework.txt new file +3 -0
+write-acknowledgement is received.
+
+Client can request to reserve certain bandwidth for messaging if it anticipates

A client

Documentation/slimbus/slimbus-framework.txt line 111

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+heavy messaging-traffic on the bus. Slimbus framework tries to reserve the

The Slimbus framework

Documentation/slimbus/slimbus-framework.txt line 115

Quoted 4 lines
Documentation/slimbus/slimbus-framework.txt new file +4 -0
+messaging bandwidth and may decide to change clock frequency (clock gear)
+based on existing data-channels on the bus and current frequency (clock gear),
+and pre-existing reserved-message bandwidth. Reserving bandwidth will fail if
+clock gear is already maximum and pre-existing data channels and the newly

the clock gear

Documentation/slimbus/slimbus-framework.txt line 127

Quoted 12 lines
Documentation/slimbus/slimbus-framework.txt new file +12 -0
+requested reserved bandwidth cannot be satisfied.
+
+Data Channel based APIs:
+------------------------
+Data channels can be setup between 2 devices using their data ports. Per
+Slimbus specification, there can be multiple sources and one sink per one data
+channel. Each data channel is uniquely defined by its location in the TDM frame.
+Every manager device also typically has many ports and they are used for data
+transfer between software and the device. Ports have different configuration and
+request types. For each half-duplex port, 2 adjacent physical ports are located.
+
+A port can have source or sink flow. Port has events/errors associated with it.

A port

Documentation/slimbus/slimbus-framework.txt line 128

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+Typically, client requests ports on manager and slave devices. That causes a

a client

Documentation/slimbus/slimbus-framework.txt line 130

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+Slimbus specification message to be sent to the device (connect-source or
+connect-sink). Once the port allocation is done, client requests for channel to

the client requests

Documentation/slimbus/slimbus-framework.txt line 134

Quoted 4 lines
Documentation/slimbus/slimbus-framework.txt new file +4 -0
+be allocated using the ports it has. Data channel has different protocols
+(such as isochronous, soft-isochronous, asynchronous) based on the clock at
+which Slimbus runs and the channel bandwidth requirements. Clients specify rate
+and the protocol to allocate channel. Clients then call transfer on the port

to allocate a channel.

Documentation/slimbus/slimbus-framework.txt line 139

Quoted 5 lines
Documentation/slimbus/slimbus-framework.txt new file +5 -0
+with the input/output vectors and specify completion structure to be notified.
+Clients then call channel activation API to activate the channel.
+
+Channels with common parameters can benefit from grouping. Grouping channels
+helps to schedule/deactive a set of channels at the same time. (e.g. 5.1 audio).

deactivate at the same time (e.g., 5.1 audio).

Documentation/slimbus/slimbus-framework.txt line 140

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+Framework signals completion when the buffers are done and it's upto client to

The framework up to the client to

Documentation/slimbus/slimbus-framework.txt line 142

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+supply more buffers and/or deactivate the channel. Completion signal is also
+used to communicate port errors to the client. It's upto the client to act

up to

Documentation/slimbus/slimbus-framework.txt line 143

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+according to the error.  Activation/Deactivation can be done on a pre-existing

on pre-existing

Documentation/slimbus/slimbus-framework.txt line 151

Quoted 8 lines
Documentation/slimbus/slimbus-framework.txt new file +8 -0
+channels. Clients can call deallocation APIs on channels and/or ports when they
+no longer need the resources.
+
+Clients use "commit" flag in the control channel APIs to group their requests.
+This avoids sending the expensive reconfiguration sequence on the bus too
+frequently. Once the "commit" flag is set, all channel-requests pending on that
+client are acted upon (active-channels are scheduled, remove-channels are
+removed from scheduling etc.)

from scheduling, etc.).

Quoted 4 lines
Documentation/slimbus/slimbus-framework.txt new file +4 -0
+
+Scheduling of channels: Controller and/or framework will call API to reschedule
+TDM framing as it is deemed necessary. This is internally implemented by the
+framework based on current data-channel and message bandwidth requirements.

Documentation/slimbus/slimbus-framework.txt line 165

Quoted 10 lines
Documentation/slimbus/slimbus-framework.txt new file +10 -0
+Controller may also change scheduling of already active-channels to use TDM
+effectively.
+
+
+
+Design
+======
+Bus-type:
+---------
+Slimbus is represented as a bus and different type of devices listed above hang

types

Documentation/slimbus/slimbus-framework.txt line 176

Quoted 11 lines
Documentation/slimbus/slimbus-framework.txt new file +11 -0
+on it. The bus registers with Linux kernel in early stages of kernel bringup.
+Every Slimbus typically has one manager device, one framer device, and multiple
+generic devices (clients). When a device is added/registered, Slimbus matches a
+driver (registered earlier) and calls the driver probe.
+
+Message transactions:
+---------------------
+For faster and efficient transaction management, Linux framework uses tid for
+every transaction irrespective of whether it expects a response. This helps in
+O(1) search of the transaction when it's complete, or its response is received,
+or it needs to be resent due to collision/NACK. Once transaction is complete,

Once a transaction

Documentation/slimbus/slimbus-framework.txt line 178

Quoted 2 lines
Documentation/slimbus/slimbus-framework.txt new file +2 -0
+its resources are just marked unused and not deleted. A transaction is allocated
+if an unused transaction is not found. Per Slimbus specification, TID is 8-bit

8 bits

Documentation/slimbus/slimbus-framework.txt line 179

Quoted 1 line
Documentation/slimbus/slimbus-framework.txt new file +1 -0
+long and cannot exceed 256. So this won't cause a lot of memory usage and

cannot exceed 256, so

Documentation/slimbus/slimbus-framework.txt line 185

Quoted 6 lines
Documentation/slimbus/slimbus-framework.txt new file +6 -0
+allocation for transactions won't be required to be done too often.
+
+Ports and channels:
+-------------------
+Manager-ports and channels are allocated as arrays. This helps faster access
+based on channel/port number. Typically number of ports and channels are limited

Typically the number

Documentation/slimbus/slimbus-framework.txt line 188

Quoted 3 lines
Documentation/slimbus/slimbus-framework.txt new file +3 -0
+and having this as a list won't gain significant memory advantage.
+
+For effective scheduling, 2 most commonly used frequency-channels (4KHz and

the 2 most

Documentation/slimbus/slimbus-framework.txt line 199

Quoted 11 lines
Documentation/slimbus/slimbus-framework.txt new file +11 -0
+12KHz) are grouped in 2 sorted lists. The lists only have pointers (to channel
+elements allocated above).
+
+
+Power Management
+================
+Slimbus hardware uses only 2 wires for managing multiple devices, multiple
+channels and control/status messaging. This is power efficient. In addition,
+clock gears are used to go to lower clock gears when low-bandwidth messaging
+is used and/or limited data channels are used. Controller will call clock-pause
+API to pause the slimbus clock if no channels are active.

Slimbus

Quoted 53 lines
Documentation/slimbus/slimbus-framework.txt new file +53 -0
+
+Runtime suspend/resume will be used from Linux kernel power management
+framework to implement power management functionality.
+
+
+
+SMP/multi-core
+==============
+Board initialization list for listing devices, framers use a board-specific
+mutex. This mutex is common to all controllers.
+
+Controllers are listed in the framework using idr list. The list is protected by
+a common mutex.
+
+Controller data structures (channel, port, address-table, transaction-id table)
+are protected using a controller mutex.
+
+Reconfiguration mutex per controller is used to make sure that only one
+reconfiguration sequence is in progress per controller.
+
+Client structure has a mutex to protect the pending data channel request-lists
+per client.
+
+
+
+Security
+========
+None at this point.
+
+
+
+Interface
+=========
+There is no plan of exporting slimbus functionality to user space right now.
+
+Kernel space APIs:
+include/linux/slimbus/slimbus.h
+-----------------------
+
+
+
+Driver parameters
+=================
+None.
+
+
+
+Config options
+==============
+Slimbus in drivers/Kconfig
+
+
+

Documentation/slimbus/slimbus-framework.txt line 262

Quoted 10 lines
Documentation/slimbus/slimbus-framework.txt new file +10 -0
+Dependencies
+============
+None.
+
+
+
+User space utilities
+====================
+None at this point. No user space access is expected for Slimbus at this point.
+If need be, a client can be implemented to manage all use-space accesses

user-space

Quoted 4 lines
Documentation/slimbus/slimbus-framework.txt new file +4 -0
+using ioctl.
+
+
+

Documentation/slimbus/slimbus-framework.txt line 276

Quoted 10 lines
Documentation/slimbus/slimbus-framework.txt new file +10 -0
+Known issues
+============
+None.
+
+
+
+To do
+=====
+Framer handoff is not supported right now. This is required when a bus has
+multiple framers and active framer needs to be decided on the fly.

and the active

Quoted 14 lines
Documentation/slimbus/slimbus-framework.txt new file +6 -0
+
+Specific logical address request is not supported right now. Client drivers may
+request for specific logical address and that may change logical addresses of
+other preexisting devices on the bus.
+
+Debugfs will be used to debug channel management and bandwidth usage in future.
drivers/slimbus/slimbus.c new file +0 -0
new file mode 100644
index 0000000..313837a

drivers/slimbus/slimbus.c line 202

Quoted 5 lines
drivers/slimbus/slimbus.c new file +4 -0
@@ -0,0 +1,2629 @@
+/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
 
+/*
+ * slim_driver_register: Client driver registration with slimbus
+ * @drv:Client driver to be associated with client-device.

This is very close to kernel-doc notation. Can you just make it be kernel-doc, please? (same comment for many such cases in the source code)

Quoted 12 lines

+ * This API will register the client driver with the slimbus
+ * It is called from the driver's module-init function.
+ */

drivers/slimbus/slimbus.c new file +9 -0
+int slim_driver_register(struct slim_driver *drv)
+{
+	drv->driver.bus = &slimbus_type;
+	if (drv->probe)
+		drv->driver.probe = slim_drv_probe;
+
+	if (drv->remove)
+		drv->driver.remove = slim_drv_remove;
+

drivers/slimbus/slimbus.c line 266

Quoted 10 lines
drivers/slimbus/slimbus.c new file +9 -0
+	if (drv->shutdown)
+		drv->driver.shutdown = slim_drv_shutdown;
+
+	return driver_register(&drv->driver);
+}
+EXPORT_SYMBOL_GPL(slim_driver_register);
 
+/*
+ * slim_add_device: Add a new device without register board info.
+ * @ctrl: Controller to which this device is to be added to.

* @sbdev: <description>

Quoted 15 lines

+ * Called when device doesn't have an explicit client-driver to be probed, or
+ * the client-driver is a module installed dynamically.
+ */

drivers/slimbus/slimbus.c new file +2 -0
+int slim_add_device(struct slim_controller *ctrl, struct slim_device *sbdev)
+{
include/linux/slimbus/slimbus.h new file +1 -0
new file mode 100644
index 0000000..79dabce5
@@ -0,0 +1,939 @@
+/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.

include/linux/slimbus/slimbus.h line 11

Quoted 10 lines
include/linux/slimbus/slimbus.h new file +10 -0
+ */
+
+#ifndef _LINUX_SLIMBUS_H
+#define _LINUX_SLIMBUS_H
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/mod_devicetable.h>
+
+/*

/**
* struct slim_ele_access - <description>

Quoted 17 lines
include/linux/slimbus/slimbus.h new file +15 -0
+ * @start_offset: Specifies starting offset in information/value element map
+ * @num_bytes: Can be 1, 2, 3, 4, 6, 8, 12, 16 per spec. This ensures that the
+ *	message will fit in the 40-byte message limit and the slicesize can be
+ *	compatible with values in table 21 (slimbus spec 1.01.01)
+ * @comp: Completion to indicate end of message-transfer. Used if client wishes
+ *	to use the API asynchronously.
+ */
+struct slim_ele_access {
+	u16			start_offset;
+	u8			num_bytes;
+	struct completion	*comp;
+};
 
 
+/*
+ * slim_register_board_info: Board-initialization routine.
+ * @info: List of all devices on all controllers present on the board.

include/linux/slimbus/slimbus.h

Quoted 10 lines
include/linux/slimbus/slimbus.h new file +10 -0
+ * @n: number of entries.
+ * API enumerates respective devices on corresponding controller.
+ * Called from board-init function.
+ */
+#ifdef CONFIG_SLIMBUS
+extern int slim_register_board_info(struct slim_boardinfo const *info,
+					unsigned n);
+#else
+int slim_register_board_info(struct slim_boardinfo const *info,
+					unsigned n)

static inline ?

include/linux/slimbus/slimbus.h

Quoted 4 lines
include/linux/slimbus/slimbus.h new file +4 -0
+{
+	return 0;
+}
+#endif

[Sorry about my delayed comments.]

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#38 lore raw
Quoted 20 lines · Randy Dunlap
Quoted 16 lines · On Wed, 10 Aug 2011 17:31:28 -0600 Kenneth Heitke wrote:

From: Sagar Dharia<[email protected]>

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. Commonly used digital audio interfaces such as I2S, PCM are intended for point-to-point connection between application processor and single audio device and support one or two channels. Adding more channels or functions is difficult without increasing number of bus structures and hence pin count. In parallel to audio channels, control buses such as I2C are typically used for low-bandwidth control tasks.
SLIMbus replaces many digital audio buses and control buses by providing flexible and dynamic bus-bandwidth between data-functions and control-functions.

Quoted 7 lines

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code *** --
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Hi Randy,

Thank you for reviewing the code and documentation. We will incorporate your suggestions (especially appreciate the documentation comments).

thanks,
Ken

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#39 lore raw
In reply to Kenneth Heitke
Quoted 1 line · Kenneth Heitke

From: Sagar Dharia <[email protected]>

Just trivia:

Quoted 1 line
 create mode 100755 Documentation/slimbus/slimbus-framework.txt

644?

Review

Quoted 2 lines

+++ b/drivers/slimbus/slimbus.c

(quoted diff) +0 -0
@@ -0,0 +1,2629 @@

[]

drivers/slimbus/slimbus.c line 397

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+static int slim_register_controller(struct slim_controller *ctrl)
+	if (ctrl->nports) {
+		ctrl->ports = kzalloc(ctrl->nports * sizeof(struct slim_port),
+					GFP_KERNEL);

Many of these kzalloc with multiplies could be kcalloc.

Review line 6

Quoted 2 lines
(quoted diff) +2 -0
+		ctrl->chans = kzalloc(ctrl->nchans * sizeof(struct slim_ich),
+					GFP_KERNEL);

[]

Review line 8

Quoted 2 lines
(quoted diff) +2 -0
+void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len)
+{

[]

drivers/slimbus/slimbus.c line 569

Quoted 2 lines
drivers/slimbus/slimbus.c new file +2 -0
+		dev_err(&ctrl->dev, "Got response to invalid TID:%d, len:%d",
+				tid, len);

Many of the dev_<level> uses are missing terminating "\n".

It might be reasonable to have slim specific macros/functions for message logging. That might allow slim specific prefixes.

For functions, you could look at netdev_<level>:

slim_<level>(struct slim_controller *ctrl, const char *fmt, ...)

or macros like:

#define slim_printk(level, ctrl, fmt, ...)			\
	dev_printk(level, &(ctrl)->dev, fmt, ##__VA_ARGS__)
#define slim_<level>(level, ctrl, fmt, ...)				\
	slim_printk(KERN_<LEVEL>, ctrl, fmt, ##__VA_ARGS__)

etc.

[]

drivers/slimbus/slimbus.c line 586

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+static int slim_processtxn(struct slim_controller *ctrl, u8 dt, u8 mc, u16 ec,
+			u8 mt, u8 *rbuf, const u8 *wbuf, u8 len, u8 mlen,
+			struct completion *comp, u8 la, u8 *tid)
+{

[]

drivers/slimbus/slimbus.c line 607

Quoted 3 lines
drivers/slimbus/slimbus.c new file +3 -0
+			ctrl->txnt = krealloc(ctrl->txnt,
+					(i + 1) * sizeof(struct slim_msg_txn *),
+					GFP_KERNEL);

realloc's to the same var are generally unwise.

Is anything that was pointed to important?
If so, and the return was NULL, you just lost
the important stuff.

[]

Review line 19

Quoted 2 lines
(quoted diff) +2 -0
+int slim_assign_laddr(struct slim_controller *ctrl, const u8 *e_addr,
+				u8 e_len, u8 *laddr)

[]

drivers/slimbus/slimbus.c line 684

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+			ctrl->addrt = krealloc(ctrl->addrt,
+					(ctrl->num_dev + 1) *
+					sizeof(struct slim_addrt),
+					GFP_KERNEL);

Same potential realloc issue here too.

[]

drivers/slimbus/slimbus.c line 761

Quoted 3 lines
drivers/slimbus/slimbus.c new file +3 -0
+static u16 slim_slicecodefromsize(u32 req)
+{
+	u8 codetosize[8] = {1, 2, 3, 4, 6, 8, 12, 16};

static const

drivers/slimbus/slimbus.c line 765

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+	if (req >= 8)
+		return 0;
+	else
+		return codetosize[req];

Should this be u8 or u16? It's somewhat odd to
have the array a different size than the return.

drivers/slimbus/slimbus.c line 770

Quoted 3 lines
drivers/slimbus/slimbus.c new file +3 -0
+static u16 slim_slicesize(u32 code)
+{
+	u8 sizetocode[16] = {0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7};

static const

drivers/slimbus/slimbus.c line 774

Quoted 4 lines
drivers/slimbus/slimbus.c new file +4 -0
+	if (code == 0)
+		code = 1;
+	if (code > 16)
+		code = 16;

clamp

Quoted 1 line
drivers/slimbus/slimbus.c new file +1 -0
+	return sizetocode[code - 1];
#40 lore raw
Quoted 9 lines · Joe Perches
Quoted 1 line · Kenneth Heitke

From: Sagar Dharia<[email protected]>

Just trivia:

Quoted 1 line

create mode 100755 Documentation/slimbus/slimbus-framework.txt

644?

Hi Joe,

Thank you for taking the time to review the driver. We appreciate your comments. I always learn something new like the existence of clamp().

Ken

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#41 lore raw
In reply to Joe Perches
Quoted 7 lines · Joe Perches

It might be reasonable to have slim specific macros/functions for message logging. That might allow slim specific prefixes.

For functions, you could look at netdev_<level>:

slim_<level>(struct slim_controller *ctrl, const char *fmt, ...)

Quoted 7 lines

or macros like:

#define slim_printk(level, ctrl, fmt, ...)                      \
        dev_printk(level, &(ctrl)->dev, fmt, ##__VA_ARGS__)
#define slim_<level>(level, ctrl, fmt, ...)                             \
        slim_printk(KERN_<LEVEL>, ctrl, fmt, ##__VA_ARGS__)

etc.

Hi Joe,

My recommendation is always against such macros, and for using the dev_* and pr_* macros directly. The reason is mostly so that a causal reader with a kernel background can immediately understand what they do, rather than having to look up extra macro definition, e.g. to see if they add the newline character or not.

I agree with all your other comments though, thanks for taking a look as well.

Arnd

#42 lore raw
Quoted 12 lines · Arnd Bergmann
Quoted 10 lines · Joe Perches

It might be reasonable to have slim specific macros/functions for message logging. That might allow slim specific prefixes. For functions, you could look at netdev_<level>:
slim_<level>(struct slim_controller *ctrl, const char *fmt, ...) or macros like:

#define slim_printk(level, ctrl, fmt, ...)                      \
        dev_printk(level, &(ctrl)->dev, fmt, ##__VA_ARGS__)
#define slim_<level>(level, ctrl, fmt, ...)                             \
        slim_printk(KERN_<LEVEL>, ctrl, fmt, ##__VA_ARGS__)

etc.

Quoted 1 line

Hi Joe,

Hi again Arnd.

Quoted 5 lines

My recommendation is always against such macros, and for using the dev_* and pr_* macros directly. The reason is mostly so that a causal reader with a kernel background can immediately understand what they do, rather than having to look up extra macro definition, e.g. to see if they add the newline character or not.

Well, we have different opinions about this still.

Subsystem specific logging functions or macros are a very common style in kernel code.

Looking only for <foo>_warn(...) uses:

$ grep -rPi --include=*.[ch] \
	"^[\t ]*(#\s*define|(extern\s+|)(void|int))\s+[a-z0-9]+_warn(ing|)\s*\([^;}\)]*\.\.\." * | \
	wc -l
132

There are at least a few benefits to subsystem specific uses of <foo>_<level>.

When used as functions, they can reduce object size a considerable amount. They can also reduce the source code text when the dev pointer is a couple of structure indirections down. It's also easier to add/use/modify subsystem specific prefixes.

cheers, Joe