Linux kernel SLIMbus support
Overview #
What is SLIMbus? #
SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance. The bus uses master/slave configuration, and is a 2-wire multi-drop implementation (clock, and data).
Currently, SLIMbus is used to interface between application processors of SoCs (System-on-Chip) and peripheral components (typically codec). SLIMbus uses Time-Division-Multiplexing to accommodate multiple data channels, and a control channel.
The control channel is used for various control functions such as bus management, configuration and status updates. These messages can be unicast (e.g. reading/writing device specific values), or multicast (e.g. data channel reconfiguration sequence is a broadcast message announced to all devices)
A data channel is used for data-transfer between 2 SLIMbus devices. Data channel uses dedicated ports on the device.
Hardware description: #
SLIMbus specification has different types of device classifications based on their capabilities. A manager device is responsible for enumeration, configuration, and dynamic channel allocation. Every bus has 1 active manager.
A generic device is a device providing application functionality (e.g. codec).
Framer device is responsible for clocking the bus, and transmitting frame-sync and framing information on the bus.
Each SLIMbus component has an interface device for monitoring physical layer.
Typically each SoC contains SLIMbus component having 1 manager, 1 framer device, 1 generic device (for data channel support), and 1 interface device. External peripheral SLIMbus component usually has 1 generic device (for functionality/data channel support), and an associated interface device. The generic device's registers are mapped as 'value elements' so that they can be written/read using SLIMbus control channel exchanging control/status type of information. In case there are multiple framer devices on the same bus, manager device is responsible to select the active-framer for clocking the bus.
Per specification, SLIMbus uses "clock gears" to do power management based on current frequency and bandwidth requirements. There are 10 clock gears and each gear changes the SLIMbus frequency to be twice its previous gear.
Each device has a 6-byte enumeration-address and the manager assigns every device with a 1-byte logical address after the devices report presence on the bus.
Software description: #
There are 2 types of SLIMbus drivers:
slim_controller represents a 'controller' for SLIMbus. This driver should implement duties needed by the SoC (manager device, associated interface device for monitoring the layers and reporting errors, default framer device).
slim_device represents the 'generic device/component' for SLIMbus, and a slim_driver should implement driver for that slim_device.
Device notifications to the driver: #
Since SLIMbus devices have mechanisms for reporting their presence, the framework allows drivers to bind when corresponding devices report their presence on the bus. However, it is possible that the driver needs to be probed first so that it can enable corresponding SLIMbus device (e.g. power it up and/or take it out of reset). To support that behavior, the framework allows drivers to probe first as well (e.g. using standard DeviceTree compatibility field). This creates the necessity for the driver to know when the device is functional (i.e. reported present). device_up callback is used for that reason when the device reports present and is assigned a logical address by the controller.
Similarly, SLIMbus devices 'report absent' when they go down. A 'device_down' callback notifies the driver when the device reports absent and its logical address assignment is invalidated by the controller.
Another notification "boot_device" is used to notify the slim_driver when controller resets the bus. This notification allows the driver to take necessary steps to boot the device so that it's functional after the bus has been reset.
Driver and Controller APIs: #
struct slim_eaddr #
Enumeration address for a SLIMbus device
Definition
;
Members
instance: Instance valuedev_index: Device indexprod_code: Product codemanf_id: Manufacturer Id for the device
enum slim_device_status #
slim device status
Constants
SLIM_DEVICE_STATUS_DOWN: Slim device is absent or not reported yet.SLIM_DEVICE_STATUS_UP: Slim device is announced on the bus.SLIM_DEVICE_STATUS_RESERVED: Reserved for future use.
struct slim_device #
Slim device handle.
Definition
;
Members
dev: Driver model representation of the device.e_addr: Enumeration address of this device.ctrl: slim controller instance.status: slim device statusladdr: 1-byte Logical address of this device.is_laddr_valid: indicates if the laddr is valid or notstream_list: List of streams on this devicestream_list_lock: lock to protect the stream list
Description
This is the client/device handle returned when a SLIMbus device is registered with a controller. Pointer to this structure is used by client-driver as a handle.
struct slim_driver #
SLIMbus 'generic device' (slave) device driver (similar to 'spi_device' on SPI)
Definition
;
Members
probe: Binds this driver to a SLIMbus device.remove: Unbinds this driver from the SLIMbus device.shutdown: Standard shutdown callback used during powerdown/halt.device_status: This callback is called when- The device reports present and gets a laddr assigned
- The device reports absent, or the bus goes down.
driver: SLIMbus device drivers should initialize name and owner field of this structureid_table: List of SLIMbus devices supported by this driver
struct slim_val_inf #
Slimbus value or information element
Definition
;
Members
start_offset: Specifies starting offset in information/value element mapnum_bytes: upto 16. This ensures that the message will fit the slicesize per SLIMbus specrbuf: buffer to read the valueswbuf: buffer to writecomp: completion for asynchronous operations, valid only if TID is required for transaction, like REQUEST operations. Rest of the transactions are synchronous anyway.
struct slim_stream_config #
SLIMbus stream configuration Configuring a stream is done at hw_params or prepare call from audio drivers where they have all the required information regarding rate, number of channels and so on. There is a 1:1 mapping of channel and ports.
Definition
;
Members
rate: data ratebps: bits per data samplech_count: number of channelschs: pointer to list of channel numbersport_mask: port mask of ports to use for this streamdirection: direction of the stream, SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE.
module_slim_driver() #
Helper macro for registering a SLIMbus driver
Parameters
__slim_driver: slimbus_driver struct
Description
Helper macro for SLIMbus drivers which do not do anything special in module
init/exit. This eliminates a lot of boilerplate. Each module may only
use this macro once, and calling it replaces module_init() and module_exit()
struct slim_framer #
Represents SLIMbus framer. Every controller may have multiple framers. There is 1 active framer device responsible for clocking the bus. Manager is responsible for framer hand-over.
Definition
;
Members
dev: Driver model representation of the device.e_addr: Enumeration address of the framer.rootfreq: Root Frequency at which the framer can run. This is maximum frequency ('clock gear 10') at which the bus can operate.superfreq: Superframes per root frequency. Every frame is 6144 bits.
struct slim_msg_txn #
Message to be sent by the controller. This structure has packet header, payload and buffer to be filled (if any)
Definition
;
Members
rl: Header field. remaining length.mt: Header field. Message type.mc: Header field. LSB is message code for type mt.dt: Header field. Destination type.ec: Element code. Used for elemental access APIs.tid: Transaction ID. Used for messages expecting response. (relevant for message-codes involving read operation)la: Logical address of the device this message is going to. (Not used when destination type is broadcast.)msg: Elemental access message to be read/writtencomp: completion if read/write is synchronous, used internally for tid based transactions.
enum slim_clk_state #
SLIMbus controller's clock state used internally for maintaining current clock state.
Constants
SLIM_CLK_ACTIVE: SLIMbus clock is activeSLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the transition fails, state changes back to SLIM_CLK_ACTIVESLIM_CLK_PAUSED: SLIMbus controller clock has paused.
struct slim_sched #
Framework uses this structure internally for scheduling.
Definition
;
Members
clk_state: Controller's clock state from enum slim_clk_statepause_comp: Signals completion of clock pause sequence. This is useful when client tries to call SLIMbus transaction when controller is entering clock pause.m_reconf: This mutex is held until current reconfiguration (data channel scheduling, message bandwidth reservation) is done. Message APIs can use the bus concurrently when this mutex is held since elemental access messages can be sent on the bus when reconfiguration is in progress.
enum slim_port_direction #
SLIMbus port direction
Constants
SLIM_PORT_SINK: SLIMbus port is a sinkSLIM_PORT_SOURCE: SLIMbus port is a source
enum slim_port_state #
SLIMbus Port/Endpoint state machine according to SLIMbus Spec 2.0
Constants
SLIM_PORT_DISCONNECTED: SLIMbus port is disconnected entered from Unconfigure/configured state after DISCONNECT_PORT or REMOVE_CHANNEL core commandSLIM_PORT_UNCONFIGURED: SLIMbus port is in unconfigured state. entered from disconnect state after CONNECT_SOURCE/SINK core commandSLIM_PORT_CONFIGURED: SLIMbus port is in configured state. entered from unconfigured state after DEFINE_CHANNEL, DEFINE_CONTENT and ACTIVATE_CHANNEL core commands. Ready for data transmission.
enum slim_channel_state #
SLIMbus channel state machine used by core.
Constants
SLIM_CH_STATE_DISCONNECTED: SLIMbus channel is disconnectedSLIM_CH_STATE_ALLOCATED: SLIMbus channel is allocatedSLIM_CH_STATE_ASSOCIATED: SLIMbus channel is associated with portSLIM_CH_STATE_DEFINED: SLIMbus channel parameters are definedSLIM_CH_STATE_CONTENT_DEFINED: SLIMbus channel content is definedSLIM_CH_STATE_ACTIVE: SLIMbus channel is active and ready for dataSLIM_CH_STATE_REMOVED: SLIMbus channel is inactive and removed
enum slim_ch_data_fmt #
SLIMbus channel data Type identifiers according to Table 60 of SLIMbus Spec 1.01.01
Constants
SLIM_CH_DATA_FMT_NOT_DEFINED: UndefinedSLIM_CH_DATA_FMT_LPCM_AUDIO: LPCM audioSLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO: IEC61937 Compressed audioSLIM_CH_DATA_FMT_PACKED_PDM_AUDIO: Packed PDM audio
enum slim_ch_aux_bit_fmt #
SLIMbus channel Aux Field format IDs according to Table 63 of SLIMbus Spec 2.0
Constants
SLIM_CH_AUX_FMT_NOT_APPLICABLE: UndefinedSLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958: ZCUV for tunneling IEC60958SLIM_CH_AUX_FMT_USER_DEFINED: User defined
struct slim_channel #
SLIMbus channel, used for state machine
Definition
;
Members
id: ID of channelprrate: Presense rate of channel from Table 66 of SLIMbus 2.0 Specsseg_dist: segment distribution code from Table 20 of SLIMbus 2.0 Specsdata_fmt: Data format of channel.aux_fmt: Aux format for this channel.state: channel state machine
struct slim_port #
SLIMbus port
Definition
;
Members
id: Port iddirection: Port direction, Source or Sink.state: state machine of port.ch: channel associated with this port.
enum slim_transport_protocol #
SLIMbus Transport protocol list from Table 47 of SLIMbus 2.0 specs.
Constants
SLIM_PROTO_ISO: Isochronous Protocol, no flow control as data rate match channel rate flow control embedded in the data.SLIM_PROTO_PUSH: Pushed Protocol, includes flow control, Used to carry data whose rate is equal to, or lower than the channel rate.SLIM_PROTO_PULL: Pulled Protocol, similar usage as pushed protocol but pull is a unicast.SLIM_PROTO_LOCKED: Locked ProtocolSLIM_PROTO_ASYNC_SMPLX: Asynchronous Protocol-SimplexSLIM_PROTO_ASYNC_HALF_DUP: Asynchronous Protocol-Half-duplexSLIM_PROTO_EXT_SMPLX: Extended Asynchronous Protocol-SimplexSLIM_PROTO_EXT_HALF_DUP: Extended Asynchronous Protocol-Half-duplex
struct slim_stream_runtime #
SLIMbus stream runtime instance
Definition
;
Members
name: Name of the streamdev: SLIM Device instance associated with this streamdirection: direction of streamprot: Transport protocol used in this streamrate: Data rate of samples *bps: bits per sampleratem: rate multipler which is super frame rate/data ratenum_ports: number of portsports: pointer to instance of portsnode: list head for stream associated with slim device.
struct slim_controller #
Controls every instance of SLIMbus (similar to 'master' on SPI)
Definition
;
Members
dev: Device interface to this driverid: Board-specific number identifier for this controller/busname: Name for this controllermin_cg: Minimum clock gear supported by this controller (default value: 1)max_cg: Maximum clock gear supported by this controller (default value: 10)clkgear: Current clock gear in which this bus is runningladdr_ida: logical address id allocatora_framer: Active framer which is clocking the bus managed by this controllerlock: Mutex protecting controller data structuresdevices: Slim device listtid_idr: tid id allocatortxn_lock: Lock to protect table of transactionssched: scheduler structure used by the controllerxfer_msg: Transfer a message on this controller (this can be a broadcast control/status message like data channel setup, or a unicast message like value element read/write.set_laddr: Setup logical address at laddr for the slave with elemental address e_addr. Drivers implementing controller will be expected to send unicast message to this device with its logical address.get_laddr: It is possible that controller needs to set fixed logical address table and get_laddr can be used in that case so that controller can do this assignment. Use case is when the master is on the remote processor side, who is resposible for allocating laddr.enable_stream: This function pointer implements controller-specific procedure to enable a stream.disable_stream: This function pointer implements controller-specific procedure to disable stream.wakeup: This function pointer implements controller-specific procedure to wake it up from clock-pause. Framework will call this to bring the controller out of clock pause.
Description
'Manager device' is responsible for device management, bandwidth allocation, channel setup, and port associations per channel. Device management means Logical address assignment/removal based on enumeration (report-present, report-absent) of a device. Bandwidth allocation is done dynamically by the manager based on active channels on the bus, message-bandwidth requests made by SLIMbus devices. Based on current bandwidth usage, manager chooses a frequency to run the bus at (in steps of 'clock-gear', 1 through 10, each clock gear representing twice the frequency than the previous gear). Manager is also responsible for entering (and exiting) low-power-mode (known as 'clock pause'). Manager can do handover of framer if there are multiple framers on the bus and a certain usecase warrants using certain framer to avoid keeping previous framer being powered-on.
Controller here performs duties of the manager device, and 'interface device'. Interface device is responsible for monitoring the bus and reporting information such as loss-of-synchronization, data slot-collision.
slim_unregister_controller() #
int Controller tear-down.
Parameters
struct slim_controller *ctrl: Controller to tear-down.
slim_report_absent() #
void Controller calls this function when a device reports absent, OR when the device cannot be communicated with
Parameters
struct slim_device *sbdev: Device that cannot be reached, or sent report absent
slim_get_device() #
struct slim_device * get handle to a device.
Parameters
struct slim_controller *ctrl: Controller on which this device will be added/queriedstruct slim_eaddr *e_addr: Enumeration address of the device to be queried
Description
Takes a reference to the embedded struct device which needs to be dropped after use.
Return
pointer to a device if it has already reported. Creates a new device and returns pointer to it if the device has not yet enumerated.
of_slim_get_device() #
struct slim_device * get handle to a device using dt node.
Parameters
struct slim_controller *ctrl: Controller on which this device will be queriedstruct device_node *np: node pointer to device
Description
Takes a reference to the embedded struct device which needs to be dropped after use.
Return
pointer to a device if it has been registered, otherwise NULL.
slim_device_report_present() #
int Report enumerated device.
Parameters
struct slim_controller *ctrl: Controller with which device is enumerated.struct slim_eaddr *e_addr: Enumeration address of the device.u8 *laddr: Return logical address (if valid flag is false)
Description
Called by controller in response to REPORT_PRESENT. Framework will assign a logical address to this enumeration address. Function returns -EXFULL to indicate that all logical addresses are already taken.
slim_get_logical_addr() #
int get/allocate logical address of a SLIMbus device.
Parameters
struct slim_device *sbdev: client handle requesting the address.
Return
zero if a logical address is valid or a new logical address has been assigned. error code in case of error.
Clock-pause: #
SLIMbus mandates that a reconfiguration sequence (known as clock-pause) be broadcast to all active devices on the bus before the bus can enter low-power mode. Controller uses this sequence when it decides to enter low-power mode so that corresponding clocks and/or power-rails can be turned off to save power. Clock-pause is exited by waking up framer device (if controller driver initiates exiting low power mode), or by toggling the data line (if a slave device wants to initiate it).
Clock-pause APIs: #
slim_ctrl_clk_pause() #
int Called by slimbus controller to enter/exit 'clock pause'
Parameters
struct slim_controller *ctrl: controller requesting bus to be paused or woken upbool wakeup: Wakeup this controller from clock pause.u8 restart: Restart time value per spec used for clock pause. This value isn't used when controller is to be woken up.
Description
Slimbus specification needs this sequence to turn-off clocks for the bus. The sequence involves sending 3 broadcast messages (reconfiguration sequence) to inform all devices on the bus. To exit clock-pause, controller typically wakes up active framer device. This API executes clock pause reconfiguration sequence if wakeup is false. If wakeup is true, controller's wakeup is called. For entering clock-pause, -EBUSY is returned if a message txn in pending.
Messaging: #
The framework supports regmap and read/write apis to exchange control-information with a SLIMbus device. APIs can be synchronous or asynchronous. The header file <linux/slimbus.h> has more documentation about messaging APIs.
Messaging APIs: #
slim_msg_response() #
void Deliver Message response received from a device to the framework.
Parameters
struct slim_controller *ctrl: Controller handleu8 *reply: Reply received from the deviceu8 tid: Transaction ID received with which framework can associate reply.u8 len: Length of the reply
Description
Called by controller to inform framework about the response received. This helps in making the API asynchronous, and controller-driver doesn't need to manage 1 more table other than the one managed by framework mapping TID with buffers
slim_alloc_txn_tid() #
int Allocate a tid to txn
Parameters
struct slim_controller *ctrl: Controller handlestruct slim_msg_txn *txn: transaction to be allocated with tid.
Return
zero on success with valid txn->tid and error code on failures.
slim_free_txn_tid() #
void Free tid of txn
Parameters
struct slim_controller *ctrl: Controller handlestruct slim_msg_txn *txn: transaction whose tid should be freed
slim_do_transfer() #
int Process a SLIMbus-messaging transaction
Parameters
struct slim_controller *ctrl: Controller handlestruct slim_msg_txn *txn: Transaction to be sent over SLIMbus
Description
Called by controller to transmit messaging transactions not dealing with Interface/Value elements. (e.g. transmitting a message to assign logical address to a slave device
Return
-ETIMEDOUT: If transmission of this message timed out (e.g. due to bus lines not being clocked or driven by controller)
slim_xfer_msg() #
int Transfer a value info message on slim device
Parameters
struct slim_device *sbdev: slim device to which this msg has to be transferredstruct slim_val_inf *msg: value info message pointeru8 mc: message code of the message
Description
Called by drivers which want to transfer a vlaue or info elements.
Return
-ETIMEDOUT: If transmission of this message timed out
slim_read() #
int Read SLIMbus value element
Parameters
struct slim_device *sdev: client handle.u32 addr: address of value element to read.size_t count: number of bytes to read. Maximum bytes allowed are 16.u8 *val: will return what the value element value was
Return
-EINVAL for Invalid parameters, -ETIMEDOUT If transmission of this message timed out (e.g. due to bus lines not being clocked or driven by controller)
slim_readb() #
int Read byte from SLIMbus value element
Parameters
struct slim_device *sdev: client handle.u32 addr: address in the value element to read.
Return
byte value of value element.
slim_write() #
int Write SLIMbus value element
Parameters
struct slim_device *sdev: client handle.u32 addr: address in the value element to write.size_t count: number of bytes to write. Maximum bytes allowed are 16.u8 *val: value to write to value element
Return
-EINVAL for Invalid parameters, -ETIMEDOUT If transmission of this message timed out (e.g. due to bus lines not being clocked or driven by controller)
slim_writeb() #
int Write byte to SLIMbus value element
Parameters
struct slim_device *sdev: client handle.u32 addr: address of value element to write.u8 value: value to write to value element
Return
-EINVAL for Invalid parameters, -ETIMEDOUT If transmission of this message timed out (e.g. due to bus lines not being clocked or driven by controller)
Streaming APIs: #
slim_stream_allocate() #
struct slim_stream_runtime * Allocate a new SLIMbus Stream
Parameters
struct slim_device *dev: Slim device to be associated withconst char *name: name of the stream
Description
This is very first call for SLIMbus streaming, this API will allocate a new SLIMbus stream and return a valid stream runtime pointer for client to use it in subsequent stream apis. state of stream is set to ALLOCATED
Return
valid pointer on success and error code on failure.
From ASoC DPCM framework, this state is linked to startup() operation.
slim_stream_prepare() #
int Prepare a SLIMbus Stream
Parameters
struct slim_stream_runtime *rt: instance of slim stream runtime to configurestruct slim_stream_config *cfg: new configuration for the stream
Description
This API will configure SLIMbus stream with config parameters from cfg.
return zero on success and error code on failure. From ASoC DPCM framework,
this state is linked to hw_params() operation.
slim_stream_enable() #
int Enable a prepared SLIMbus Stream
Parameters
struct slim_stream_runtime *stream: instance of slim stream runtime to enable
Description
This API will enable all the ports and channels associated with SLIMbus stream
Return
zero on success and error code on failure. From ASoC DPCM framework,
this state is linked to trigger() start operation.
slim_stream_disable() #
int Disable a SLIMbus Stream
Parameters
struct slim_stream_runtime *stream: instance of slim stream runtime to disable
Description
This API will disable all the ports and channels associated with SLIMbus stream
Return
zero on success and error code on failure. From ASoC DPCM framework,
this state is linked to trigger() pause operation.
slim_stream_unprepare() #
int Un-prepare a SLIMbus Stream
Parameters
struct slim_stream_runtime *stream: instance of slim stream runtime to unprepare
Description
This API will un allocate all the ports and channels associated with SLIMbus stream
Return
zero on success and error code on failure. From ASoC DPCM framework,
this state is linked to trigger() stop operation.
slim_stream_free() #
int Free a SLIMbus Stream
Parameters
struct slim_stream_runtime *stream: instance of slim stream runtime to free
Description
This API will un allocate all the memory associated with slim stream runtime, user is not allowed to make an dereference to stream after this call.
Return
zero on success and error code on failure. From ASoC DPCM framework,
this state is linked to shutdown() operation.