soundwire: Add stream support
Subsystems (4)
cover soundwire: Add stream support
This series adds support in SoundWire subsystem for:
- Documentation for stream support
- stream management
- data port management
- DAI ops in cadence and Intel drivers
- ASoC API to propagate SDW stream
Sanyog Kale (5):
soundwire: Add more documentation
soundwire: Add support for SoundWire stream management
soundwire: Add Master and Slave port programming
soundwire: Add helpers for ports operations
soundwire: Add bank switch routine
Shreyas NC (2):
ASoC: Add SoundWire stream programming interface
soundwire: Remove cdns_master_ops
Vinod Koul (6):
soundwire: Add support for port management
soundwire: Add stream configuration APIs
soundwire: cdns: Add port routines
soundwire: cdns: Add stream routines
soundwire: intel: Add stream initialization
soundwire: intel: Add audio DAI ops
.../driver-api/soundwire/error_handling.rst | 65 ++ Documentation/driver-api/soundwire/index.rst | 3 + Documentation/driver-api/soundwire/locking.rst | 106 +++ Documentation/driver-api/soundwire/stream.rst | 369 +++++++++ drivers/soundwire/Kconfig | 2 +- drivers/soundwire/Makefile | 3 +- drivers/soundwire/bus.c | 44 + drivers/soundwire/bus.h | 81 ++ drivers/soundwire/cadence_master.c | 449 +++++++++- drivers/soundwire/cadence_master.h | 151 ++++ drivers/soundwire/intel.c | 589 ++++++++++++- drivers/soundwire/intel.h | 4 + drivers/soundwire/intel_init.c | 3 + drivers/soundwire/runtime.c | 907 +++++++++++++++++++++ drivers/soundwire/stream.c | 678 +++++++++++++++ include/linux/soundwire/sdw.h | 337 +++++++- include/linux/soundwire/sdw_intel.h | 14 + include/sound/soc-dai.h | 5 + sound/soc/soc-core.c | 20 + 19 files changed, 3816 insertions(+), 14 deletions(-) create mode 100644 Documentation/driver-api/soundwire/error_handling.rst create mode 100644 Documentation/driver-api/soundwire/locking.rst create mode 100644 Documentation/driver-api/soundwire/stream.rst create mode 100644 drivers/soundwire/runtime.c create mode 100644 drivers/soundwire/stream.c
Signature · 1 line
2.7.4
PATCH 1/13 soundwire: Add more documentation
From: Sanyog Kale <[email protected]>
This adds documentation for error handling, locking and streams.
--- .../driver-api/soundwire/error_handling.rst | 65 ++++ Documentation/driver-api/soundwire/index.rst | 3 + Documentation/driver-api/soundwire/locking.rst | 106 ++++++ Documentation/driver-api/soundwire/stream.rst | 369 +++++++++++++++++++++ 4 files changed, 543 insertions(+) create mode 100644 Documentation/driver-api/soundwire/error_handling.rst create mode 100644 Documentation/driver-api/soundwire/locking.rst create mode 100644 Documentation/driver-api/soundwire/stream.rst
Documentation/driver-api/soundwire/error_handling.rst new file +65 -0
@@ -0,0 +1,65 @@ +======================== +SoundWire Error Handling +======================== + +The SoundWire PHY was designed with care and errors on the bus are going to +be very unlikely, and if they happen it should be limited to single bit +errors. Examples of this design can be found in the synchronization +mechanism (sync loss after two errors) and short CRCs used for the Bulk +Register Access. + +The errors can be detected with multiple mechanisms: + +1. Bus clash or parity errors: This mechanism relies on low-level detectors + that are independent of the payload and usages, and they cover both control + and audio data. The current implementation only logs such errors. + Improvements could be invalidating an entire programming sequence and + restarting from a known position. In the case of such errors outside of a + control/command sequence, there is no concealment or recovery for audio + data enabled by the SoundWire protocol, the location of the error will also + impact its audibility (most-significant bits will be more impacted in PCM), + and after a number of such errors are detected the bus might be reset. Note + that bus clashes due to programming errors (two streams using the same bit + slots) or electrical issues during the transmit/receive transition cannot + be distinguished, although a recurring bus clash when audio is enabled is a + indication of a bus allocation issue. The interrupt mechanism can also help + identify Slaves which detected a Bus Clash or a Parity Error, but they may + not be responsible for the errors so resetting them individually is not a + viable recovery strategy. + +2. Command status: Each command is associated with a status, which only + covers transmission of the data between devices. The ACK status indicates + that the command was received and will be executed by the end of the + current frame. A NAK indicates that the command was in error and will not + be applied. In case of a bad programming (command sent to non-existent + Slave or to a non-implemented register) or electrical issue, no response + signals the command was ignored. Some Master implementations allow for a + command to be retransmitted several times. If the retransmission fails, + backtracking and restarting the entire programming sequence might be a + solution. Alternatively some implementations might directly issue a bus + reset and re-enumerate all devices. + +3. Timeouts: In a number of cases such as ChannelPrepare or + ClockStopPrepare, the bus driver is supposed to poll a register field until + it transitions to a NotFinished value of zero. The MIPI SoundWire spec 1.1 + does not define timeouts but the MIPI SoundWire DisCo document adds + recommendation on timeouts. If such configurations do not complete, the + driver will return a -ETIMEOUT. Such timeouts are symptoms of a faulty + Slave device and are likely impossible to recover from. + +Errors during global reconfiguration sequences are extremely difficult to +handle: + +1. BankSwitch: An error during the last command issuing a BankSwitch is + difficult to backtrack from. Retransmitting the Bank Switch command may be + possible in a single segment setup, but this can lead to synchronization + problems when enabling multiple bus segments (a command with side effects + such as frame reconfiguration would be handled at different times). A global + hard-reset might be the best solution. + +Note that SoundWire does not provide a mechanism to detect illegal values +written in valid registers. In a number of cases the standard even mentions +that the Slave might behave in implementation-defined ways. The bus +implementation does not provide a recovery mechanism for such errors, Slave +or Master driver implementers are responsible for writing valid values in +valid registers and implement additional range checking if needed.
Documentation/driver-api/soundwire/index.rst +3 -0
@@ -6,6 +6,9 @@ SoundWire Documentation :maxdepth: 1 summary + stream + error_handling + locking .. only:: subproject
Documentation/driver-api/soundwire/locking.rst new file +106 -0
106 lines not on this page · raw message
Documentation/driver-api/soundwire/stream.rst new file +369 -0
369 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 01/13] soundwire: Add more documentation
Quoted 352 lines · Vinod Koul
From: Sanyog Kale <[email protected]>
This adds documentation for error handling, locking and streams.
Signed-off-by Pierre-Louis Bossart <[email protected]>Signed-off-by Sanyog Kale <[email protected]>Signed-off-by Shreyas NC <[email protected]>Signed-off-by Vinod Koul <[email protected]>--- .../driver-api/soundwire/error_handling.rst | 65 ++++ Documentation/driver-api/soundwire/index.rst | 3 + Documentation/driver-api/soundwire/locking.rst | 106 ++++++ Documentation/driver-api/soundwire/stream.rst | 369 +++++++++++++++++++++ 4 files changed, 543 insertions(+)create mode 100644
Documentation/driver-api/soundwire/error_handling.rstcreate mode 100644Documentation/driver-api/soundwire/locking.rstcreate mode 100644Documentation/driver-api/soundwire/stream.rstDocumentation/driver-api/soundwire/error_handling.rst new file +65
-0@@ -0,0 +1,65 @@ +======================== +SoundWire Error Handling +======================== + +The SoundWire PHY was designed with care and errors on the bus are going to +be very unlikely, and if they happen it should be limited to single bit +errors. Examples of this design can be found in the synchronization +mechanism (sync loss after two errors) and short CRCs used for the Bulk +Register Access. + +The errors can be detected with multiple mechanisms: + +1. Bus clash or parity errors: This mechanism relies on low-level detectors + that are independent of the payload and usages, and they cover both control + and audio data. The current implementation only logs such errors. + Improvements could be invalidating an entire programming sequence and + restarting from a known position. In the case of such errors outside of a + control/command sequence, there is no concealment or recovery for audio + data enabled by the SoundWire protocol, the location of the error will also + impact its audibility (most-significant bits will be more impacted in PCM), + and after a number of such errors are detected the bus might be reset. Note + that bus clashes due to programming errors (two streams using the same bit + slots) or electrical issues during the transmit/receive transition cannot + be distinguished, although a recurring bus clash when audio is enabled is a + indication of a bus allocation issue. The interrupt mechanism can also help + identify Slaves which detected a Bus Clash or a Parity Error, but they may + not be responsible for the errors so resetting them individually is not a + viable recovery strategy. + +2. Command status: Each command is associated with a status, which only + covers transmission of the data between devices. The ACK status indicates + that the command was received and will be executed by the end of the + current frame. A NAK indicates that the command was in error and will not + be applied. In case of a bad programming (command sent to non-existent + Slave or to a non-implemented register) or electrical issue, no response + signals the command was ignored. Some Master implementations allow for a + command to be retransmitted several times. If the retransmission fails, + backtracking and restarting the entire programming sequence might be a + solution. Alternatively some implementations might directly issue a bus + reset and re-enumerate all devices. + +3. Timeouts: In a number of cases such as ChannelPrepare or + ClockStopPrepare, the bus driver is supposed to poll a register field until + it transitions to a NotFinished value of zero. The MIPI SoundWire spec 1.1 + does not define timeouts but the MIPI SoundWire DisCo document adds + recommendation on timeouts. If such configurations do not complete, the + driver will return a -ETIMEOUT. Such timeouts are symptoms of a faulty + Slave device and are likely impossible to recover from. + +Errors during global reconfiguration sequences are extremely difficult to +handle: + +1. BankSwitch: An error during the last command issuing a BankSwitch is + difficult to backtrack from. Retransmitting the Bank Switch command may be + possible in a single segment setup, but this can lead to synchronization + problems when enabling multiple bus segments (a command with side effects + such as frame reconfiguration would be handled at different times). A global + hard-reset might be the best solution. + +Note that SoundWire does not provide a mechanism to detect illegal values +written in valid registers. In a number of cases the standard even mentions +that the Slave might behave in implementation-defined ways. The bus +implementation does not provide a recovery mechanism for such errors, Slave +or Master driver implementers are responsible for writing valid values in +valid registers and implement additional range checking if needed.Documentation/driver-api/soundwire/index.rst +3
-0@@ -6,6 +6,9 @@ SoundWire Documentation :maxdepth: 1 summary + stream + error_handling + locking .. only:: subprojectDocumentation/driver-api/soundwire/locking.rst new file +106
-0@@ -0,0 +1,106 @@ +================= +SoundWire Locking +================= + +This document explains locking mechanism of the SoundWire Bus. Bus uses +following locks in order to avoid race conditions in Bus operations on +shared resources. + + - Bus lock + + - Message lock + +Bus lock +======== + +SoundWire Bus lock is a mutex and is part of Bus data structure +(sdw_bus) which is used for every Bus instance. This lock is used to +serialize each of the following operations(s) within SoundWire Bus instance. + + - Addition and removal of Slave(s), changing Slave status. + + - Prepare, Enable, Disable and De-prepare stream operations. + + - Access of Stream data structure. + +Message lock +============ + +SoundWire message transfer lock. This mutex is part of +Bus data structure (sdw_bus). This lock is used to serialize the message +transfers (read/write) within a SoundWire Bus instance. + +Below examples show how locks are acquired. + +Example 1 +--------- + +Message transfer. + + 1. For every message transfer + + a. Acquire Message lock. + + b. Transfer message (Read/Write) to Slave1 or broadcast message on + Bus in case of bank switch. + + c. Release Message lock :: + + +----------+ +---------+ + | | | | + | Bus | | Master | + | | | Driver | + | | | | + +----+-----+ +----+----+ + | | + | bus->ops->xfer_msg() | + +-------------------------------> a. Acquire Message lock + | | b. Transfer message + | | + <-------------------------------+ c. Release Message lock + | return success/error | d. Return success/error + | | + + + + +Example 2 +--------- + +Prepare operation. + + 1. Acquire lock for Bus instance associated with Master 1. + + 2. For every message transfer in Prepare operation + + a. Acquire Message lock. + + b. Transfer message (Read/Write) to Slave1 or broadcast message on + Bus in case of bank switch. + + c. Release Message lock. + + 3. Release lock for Bus instance associated with Master 1 :: + + +----------+ +---------+ + | | | | + | Bus | | Master | + | | | Driver | + | | | | + +----+-----+ +----+----+ + | | + | sdw_prepare_stream() | + +-------------------------------> 1. Acquire bus lock + | | 2. Perform stream prepare + | | + | | + | bus->ops->xfer_msg() | + +-------------------------------> a. Acquire Message lock + | | b. Transfer message + | | + <-------------------------------+ c. Release Message lock + | return success/error | d. Return success/error + | | + | | + | return success/error | 3. Release bus lock + <-------------------------------+ 4. Return success/error + | | + + +Documentation/driver-api/soundwire/stream.rst new file +131
-0@@ -0,0 +1,369 @@ +========================= +Audio Stream in SoundWire +========================= + +An audio stream is a logical or virtual connection created between + + (1) System memory buffer(s) and Codec(s) + + (2) DSP memory buffer(s) and Codec(s) + + (3) FIFO(s) and Codec(s) + + (4) Codec(s) and Codec(s) + +which is typically driven by a DMA(s) channel through the data link. An +audio stream contains one or more channels of data. All channels within +stream must have same sample rate and same sample size. + +Assume a stream with two channels (Left & Right) is opened using SoundWire +interface. Below are some ways a stream can be represented in SoundWire. + +Stream Sample in memory (System memory, DSP memory or FIFOs) :: + + ------------------------- + | L | R | L | R | L | R | + ------------------------- + +Example 1: Stereo Stream with L and R channels is rendered from Master to +Slave. Both Master and Slave is using single port. :: + + +---------------+ Clock Signal +---------------+ + | Master +----------------------------------+ Slave | + | Interface | | Interface | + | | | 1 | + | | Data Signal | | + | L + R +----------------------------------+ L + R | + | (Data) | Data Direction | (Data) | + +---------------+ +-----------------------> +---------------+ + + +Example 2: Stereo Stream with L and R channels is captured from Slave to +Master. Both Master and Slave is using single port. :: + + + +---------------+ Clock Signal +---------------+ + | Master +----------------------------------+ Slave | + | Interface | | Interface | + | | | 1 | + | | Data Signal | | + | L + R +----------------------------------+ L + R | + | (Data) | Data Direction | (Data) | + +---------------+ <-----------------------+ +---------------+ + + +Example 3: Stereo Stream with L and R channels is rendered by Master. Each +of the L and R channel is received by two different Slaves. Master and both +Slaves are using single port. :: + + +---------------+ Clock Signal +---------------+ + | Master +---------+------------------------+ Slave | + | Interface | | | Interface | + | | | | 1 | + | | | Data Signal | | + | L + R +---+------------------------------+ L | + | (Data) | | | Data Direction | (Data) | + +---------------+ | | +-------------> +---------------+ + | | + | | + | | +---------------+ + | +----------------------> | Slave | + | | Interface | + | | 2 | + | | | + +----------------------------> | R | + | (Data) | + +---------------+ + + +Example 4: Stereo Stream with L and R channel is rendered by two different +Ports of the Master and is received by only single Port of the Slave +interface. :: + + +--------------------+ + | | + | +--------------+ +----------------+ + | | || | | + | | Data Port || L Channel | | + | | 1 |------------+ | | + | | L Channel || | +-----+----+ | + | | (Data) || | L + R Channel || Data | | + | Master +----------+ | +---+---------> || Port | | + | Interface | | || 1 | | + | +--------------+ | || | | + | | || | +----------+ | + | | Data Port |------------+ | | + | | 2 || R Channel | Slave | + | | R Channel || | Interface | + | | (Data) || | 1 | + | +--------------+ Clock Signal | L + R | + | +---------------------------> | (Data) | + +--------------------+ | | + +----------------+ + +SoundWire Stream Management flow +================================ + +Stream definitions +------------------ + + (1) Current stream: This is classified as the stream on which operation has + to be performed like prepare, enable, disable, de-prepare etc. + + (2) Active stream: This is classified as the stream which is already active + on Bus other than current stream. There can be multiple active streams + on the Bus. + +SoundWire Bus manages stream operations for each stream getting +rendered/captured on the SoundWire Bus. This section explains Bus operations +done for each of the stream allocated/released on Bus. Following are the +stream states maintained by the Bus for each of the audio stream. + + +SoundWire stream states +----------------------- + +Below shows the SoundWire stream states and state transition diagram. :: + + +---------+ +----------+ +----------+ +----------+ + | ALLOC +---->| CONFIG +---->| PREPARE +---->| ENABLE | + | STATE | | STATE | | STATE | | STATE | + +---------+ +----------+ +----------+ +----+-----+
Documentation/driver-api/soundwire/stream.rst line 141
Quoted 10 lines
Documentation/driver-api/soundwire/stream.rst new file +10
-0+ ^ + | + | + v + +----------+ +-----------+ +----+-----+ + | RELEASE |<----------+ DEPREPARE |<----+ DISABLE | + | STATE | | STATE | | STATE | + +----------+ +-----------+ +----------+ + +NOTE: All stream transitions in MIPI Spec are NOT supported by software.
specifically that there are not transitions between prepare and deprepare.
While I am at it, didn't I provide feedback that the documentation and code confuse states and transitions between the states? Also there is a connection between released and allocated, this state machine isn't really working or representative of what the code does initially.
See my feedback dated February 26 on the previous version.
"the name of the states are equivalent to an action. It would be more consistent to e.g. have an ENABLED state reached after an sdw_stream_enable() function.
same with sdw_stream_prepared leading to the PREPARED state. I think it's how most standards or state machine designs are defined (and how English grammar works as well)." ALSA also uses OPEN, PREPARED, PAUSED, see asound.h
Quoted 229 lines
Documentation/driver-api/soundwire/stream.rst new file +228
-0+ +Stream State Operations +----------------------- + +Below section explains the operations done by the Bus on Master(s) and +Slave(s) as part of stream state transitions. + +SDW_STREAM_ALLOC +~~~~~~~~~~~~~~~~ + +Allocation state for stream. This is the entry state +of the stream. Operations performed before entering in this state: + + (1) A stream runtime is allocated for the stream. This stream + runtime is used as a reference for all the operations performed + on the stream. + + (2) The resources required for holding stream runtime information are + allocated and initialized. This holds all stream related information + such as stream type (PCM/PDM) and parameters, Master and Slave + interface associated with the stream, reference counting, stream + state etc. + +After all above operations are successful, stream state is set to +``SDW_STREAM_ALLOC``. + +Bus implements below API for allocate a stream which needs to be called once +per stream. From ASoC DPCM framework, this stream state maybe linked to +.startup() operation. + + .. code-block:: c + int sdw_alloc_stream(char * stream_name); + + +SDW_STREAM_CONFIG +~~~~~~~~~~~~~~~~~ + +Configuration state of stream. Operations performed before entering in +this state: + + (1) The resources allocated for stream information in SDW_STREAM_ALLOC + state are updated here. This includes stream parameters, Master(s) + and Slave(s) runtime information associated with current stream. + + (2) All the Master(s) and Slave(s) associated with current stream provide + the port information to Bus which includes port numbers allocated by + Master(s) and Slave(s) for current stream and their channel mask. + +After all above operations are successful, stream state is set to +``SDW_STREAM_CONFIG``. + +Bus implements below APIs for CONFIG state which needs to be called by +the respective Master(s) and Slave(s) associated with stream. These APIs can +only be invoked once by respective Master(s) and Slave(s). From ASoC DPCM +framework, this stream state is linked to .hw_params() operation. + + .. code-block:: c + int sdw_stream_add_master(struct sdw_bus * bus, + struct sdw_stream_config * stream_config, + struct sdw_ports_config * ports_config, + struct sdw_stream_runtime * stream); + + int sdw_stream_add_slave(struct sdw_slave * slave, + struct sdw_stream_config * stream_config, + struct sdw_ports_config * ports_config, + struct sdw_stream_runtime * stream); + + +SDW_STREAM_PREPARE +~~~~~~~~~~~~~~~~~~ + +Prepare state of stream. Operations performed before entering in this state: + + (1) Bus parameters such as bandwidth, frame shape, clock frequency, + are computed based on current stream as well as already active + stream(s) on Bus. Re-computation is required to accommodate current + stream on the Bus. + + (2) Transport and port parameters of all Master(s) and Slave(s) port(s) are + computed for the current as well as already active stream based on frame + shape and clock frequency computed in step 1. + + (3) Computed Bus and transport parameters are programmed in Master(s) and + Slave(s) registers. The banked registers programming is done on the + alternate bank (bank currently unused). Port(s) are enabled for the + already active stream(s) on the alternate bank (bank currently unused). + This is done in order to not disrupt already active stream(s). + + (4) Once all the values are programmed, Bus initiates switch to alternate + bank where all new values programmed gets into effect. + + (5) Ports of Master(s) and Slave(s) for current stream are prepared by + programming PrepareCtrl register. + +After all above operations are successful, stream state is set to +``SDW_STREAM_PREPARE``. + +Bus implements below API for PREPARE state which needs to be called once per +stream. From ASoC DPCM framework, this stream state is linked to +.prepare() operation. + + .. code-block:: c + int sdw_prepare_stream(struct sdw_stream_runtime * stream); + + +SDW_STREAM_ENABLE +~~~~~~~~~~~~~~~~~ + +Enable state of stream. The data port(s) are enabled upon entering this state. +Operations performed before entering in this state: + + (1) All the values computed in SDW_STREAM_PREPARE state are programmed + in alternate bank (bank currently unused). It includes programming of + already active stream(s) as well. + + (2) All the Master(s) and Slave(s) port(s) for the current stream are + enabled on alternate bank (bank currently unused) by programming + ChannelEn register. + + (3) Once all the values are programmed, Bus initiates switch to alternate + bank where all new values programmed gets into effect and port(s) + associated with current stream are enabled. + +After all above operations are successful, stream state is set to +``SDW_STREAM_ENABLE``. + +Bus implements below API for ENABLE state which needs to be called once per +stream. From ASoC DPCM framework, this stream state is linked to +.trigger() start operation. + + .. code-block:: c + int sdw_enable_stream(struct sdw_stream_runtime * stream); + +SDW_STREAM_DISABLE +~~~~~~~~~~~~~~~~~~ + +Disable state of stream. The data port(s) are disabled upon exiting this state. +Operations performed before entering in this state: + + (1) All the Master(s) and Slave(s) port(s) for the current stream are + disabled on alternate bank (bank currently unused) by programming + ChannelEn register. + + (2) All the current configuration of Bus and active stream(s) are programmed + into alternate bank (bank currently unused). + + (3) Once all the values are programmed, Bus initiates switch to alternate + bank where all new values programmed gets into effect and port(s) associated + with current stream are disabled. + +After all above operations are successful, stream state is set to +``SDW_STREAM_DISABLE``. + +Bus implements below API for DISABLE state which needs to be called once +per stream. From ASoC DPCM framework, this stream state is linked to +.trigger() stop operation. + + .. code-block:: c + int sdw_disable_stream(struct sdw_stream_runtime * stream); + + +SDW_STREAM_DEPREPARE +~~~~~~~~~~~~~~~~~~~~ + +De-prepare state of stream. Operations performed before entering in this +state: + + (1) All the port(s) of Master(s) and Slave(s) for current stream are + de-prepared by programming PrepareCtrl register. + + (2) The payload bandwidth of current stream is reduce from the total + bandwidth requirement of bus. + +After all above operations are successful, stream state is set to +``SDW_STREAM_DEPREPARE``. + +Bus implements below API for DEPREPARE state which needs to be called once +per stream. From ASoC DPCM framework, this stream state is linked to +.trigger() stop operation. + + .. code-block:: c + int sdw_deprepare_stream(struct sdw_stream_runtime * stream); + + +SDW_STREAM_RELEASE +~~~~~~~~~~~~~~~~~~ + +Release state of stream. Operations performed before entering in this state: + + (1) Release port resources for all Master(s) and Slave(s) port(s) + associated with current stream. + + (2) Release Master(s) and Slave(s) runtime resources associated with + current stream. + + (3) Release stream runtime resources associated with current stream. + +After all above operations are successful, stream state is set to +``SDW_STREAM_RELEASE``. + +Bus implements below APIs for RELEASE state which needs to be called by +all the Master(s) and Slave(s) associated with stream. From ASoC DPCM +framework, this stream state is linked to .hw_free() operation. + + .. code-block:: c + int sdw_stream_remove_master(struct sdw_bus * bus, + struct sdw_stream_runtime * stream); + int sdw_stream_remove_slave(struct sdw_slave * slave, + struct sdw_stream_runtime * stream); + + +The .shutdown() ASoC DPCM operation calls below Bus API to release +stream assigned as part of ALLOC state. free sdw_stream_runtime +> data structure. + + +In .shutdown() the data structure maintaining stream state are freed up. + + .. code-block:: c + void sdw_release_stream(struct sdw_stream_runtime * stream); + +Not Supported +============= + +1. A single port with multiple channels supported cannot be used between two +streams or across stream. For example a port with 4 channels cannot be used +to handle 2 independent stereo streams even though it's possible in theory +in SoundWire.
Re: [PATCH 01/13] soundwire: Add more documentation
Just a note, it helps to trim the context. Pls do so in replies.
Quoted 15 lines · Pierre-Louis Bossart
Quoted 13 lines · Vinod Koul
Documentation/driver-api/soundwire/stream.rst new file +13
-0+SoundWire stream states +----------------------- + +Below shows the SoundWire stream states and state transition diagram. :: + + +---------+ +----------+ +----------+ +----------+ + | ALLOC +---->| CONFIG +---->| PREPARE +---->| ENABLE | + | STATE | | STATE | | STATE | | STATE | + +---------+ +----------+ +----------+ +----+-----+ + ^ + | + | + v
Quoted 8 lines
Documentation/driver-api/soundwire/stream.rst line 141
Quoted 6 lines
Documentation/driver-api/soundwire/stream.rst new file +6
-0+ +----------+ +-----------+ +----+-----+ + | RELEASE |<----------+ DEPREPARE |<----+ DISABLE | + | STATE | | STATE | | STATE | + +----------+ +-----------+ +----------+ + +NOTE: All stream transitions in MIPI Spec are NOT supported by software.specifically that there are not transitions between prepare and deprepare.
Okay we can add that.
Quoted 6 lines
While I am at it, didn't I provide feedback that the documentation and code confuse states and transitions between the states?
Also there is a
connection between released and allocated, this state machine isn't really working or representative of what the code does initially.
When we allocate sdw_stream_runtime, the initial state of the stream would be garbage/NULL. It is initialized to ALLOC at that time.
stream = kzalloc(sizeof(*stream), GFP_KERNEL);
if (!stream)
return NULL;
stream->name = stream_name;
stream->state = SDW_STREAM_ALLOC;One can argue that we use kzalloc so we are in RELEASE, but I think that is bike shedding. The lifetime of stream starts with ALLOC and ends at RELEASE and we freeup the data structure. So I don't think there is a relation between ALLOC and RELEASE. Any attempt to make such a relation would confuse folks!
Quoted 9 lines
See my feedback dated February 26 on the previous version.
"the name of the states are equivalent to an action. It would be more consistent to e.g. have an ENABLED state reached after an
sdw_stream_enable()function.same with
sdw_stream_preparedleading to the PREPARED state. I think it's how most standards or state machine designs are defined (and how English grammar works as well)." ALSA also uses OPEN, PREPARED, PAUSED, seeasound.h
Hmmm after immersing in bunch of English literature we finally figured that wrapped logic here that out stream states shall be named as not action. Well that could have possibly be communicated in plain speak too :D
No worries, will change the state names aptly.
Signature · 1 line
~Vinod
PATCH 2/13 soundwire: Add support for SoundWire stream management
In reply to Vinod KoulFrom: Sanyog Kale <[email protected]>
This patch adds APIs and relevant stream data structures for initialization and release of stream.
--- drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.c | 1 + drivers/soundwire/bus.h | 32 ++++ drivers/soundwire/stream.c | 337 ++++++++++++++++++++++++++++++++++++++++++ include/linux/soundwire/sdw.h | 112 ++++++++++++++ 5 files changed, 483 insertions(+), 1 deletion(-) create mode 100644 drivers/soundwire/stream.c
drivers/soundwire/Makefile +1 -1
@@ -3,7 +3,7 @@ # #Bus Objs -soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o +soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o #Cadence Objs
drivers/soundwire/bus.c +1 -0
@@ -32,6 +32,7 @@ int sdw_add_bus_master(struct sdw_bus *bus)mutex_init (&bus->msg_lock);mutex_init (&bus->bus_lock);INIT_LIST_HEAD (&bus->slaves); +INIT_LIST_HEAD (&bus->m_rt_list);if (bus->ops->read_prop) { ret = bus->ops->read_prop (bus);
drivers/soundwire/bus.h +32 -0
@@ -45,6 +45,38 @@ struct sdw_msg {bool page; }; +/** +* sdw_slave_runtime: Runtime Stream parameters for Slave +* +* @slave: Slave handle +* @direction: Data direction w.r.t Slave +* @ch_count: Channel count of the Slave w.r.t stream +* @m_rt_node: sdw_master_runtime list node +*/ +struct sdw_slave_runtime { +struct sdw_slave *slave; +enum sdw_data_direction direction; +unsigned int ch_count; +struct list_head m_rt_node; +}; + +/** +* sdw_master_runtime: Runtime stream parameters for Master +* +* @bus: Bus handle +* @stream: Stream runtime handle +* @ch_count: Master channel count +* @slave_rt_list: Slave runtime list +* @bus_node: sdw_bus m_rt_list node +*/ +struct sdw_master_runtime { +struct sdw_bus *bus; +struct sdw_stream_runtime *stream; +unsigned int ch_count; +struct list_head slave_rt_list; +struct list_head bus_node; +}; +int sdw_transfer (struct sdw_bus *bus,struct sdw_msg *msg);int sdw_transfer_defer (struct sdw_bus *bus,struct sdw_msg *msg,struct sdw_defer *defer);
drivers/soundwire/stream.c new file +337 -0
337 lines not on this page · raw message
include/linux/soundwire/sdw.h +112 -0
136 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 02/13] soundwire: Add support for SoundWire stream management
Quoted 48 lines · Vinod Koul
From: Sanyog Kale <[email protected]>
This patch adds APIs and relevant stream data structures for initialization and release of stream.
Signed-off-by Hardik T Shah <[email protected]>Signed-off-by Sanyog Kale <[email protected]>Signed-off-by Shreyas NC <[email protected]>Signed-off-by Vinod Koul <[email protected]>--- drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.c | 1 + drivers/soundwire/bus.h | 32 ++++ drivers/soundwire/stream.c | 337 ++++++++++++++++++++++++++++++++++++++++++ include/linux/soundwire/sdw.h | 112 ++++++++++++++ 5 files changed, 483 insertions(+), 1 deletion(-)create mode 100644
drivers/soundwire/stream.cdrivers/soundwire/Makefile +1
-1@@ -3,7 +3,7 @@ # #Bus Objs -soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o +soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o #Cadence Objsdrivers/soundwire/bus.c +1
-0@@ -32,6 +32,7 @@ int sdw_add_bus_master(struct sdw_bus *bus)mutex_init (&bus->msg_lock);mutex_init (&bus->bus_lock);INIT_LIST_HEAD (&bus->slaves); +INIT_LIST_HEAD (&bus->m_rt_list);if (bus->ops->read_prop) { ret = bus->ops->read_prop (bus);drivers/soundwire/bus.h +0
-0
drivers/soundwire/bus.h struct sdw_msg { · line 53
Quoted 9 lines
drivers/soundwire/bus.h +6
-0@@ -45,6 +45,38 @@ struct sdw_msg {bool page; }; +/** +* sdw_slave_runtime: Runtime Stream parameters for Slave +* +* @slave: Slave handle +* @direction: Data direction w.r.t Slave +* @ch_count: Channel count of the Slave w.r.t stream
same here, I flagged all this already as needing to be fixed. Something's not right here, looks to me like you send the wrong version of the patches...
Quoted 15 lines
drivers/soundwire/bus.h +15
-0+* @m_rt_node: sdw_master_runtime list node +*/ +struct sdw_slave_runtime { +struct sdw_slave *slave; +enum sdw_data_direction direction; +unsigned int ch_count; +struct list_head m_rt_node; +}; + +/** +* sdw_master_runtime: Runtime stream parameters for Master +* +* @bus: Bus handle +* @stream: Stream runtime handle +* @ch_count: Master channel count
drivers/soundwire/bus.h struct sdw_msg { · line 78
Quoted 10 lines
drivers/soundwire/bus.h +10
-0+* @slave_rt_list: Slave runtime list +* @bus_node: sdw_bus m_rt_list node +*/ +struct sdw_master_runtime { +struct sdw_bus *bus; +struct sdw_stream_runtime *stream; +unsigned int ch_count; +struct list_head slave_rt_list; +struct list_head bus_node; +};
no direction?
I will stop here, this series is not ready for further review. Not going to rehash the same comments twice on a public mailing list after providing direct feedback.
Quoted 371 lines
drivers/soundwire/bus.h +1
-0+int sdw_transfer (struct sdw_bus *bus,struct sdw_msg *msg);int sdw_transfer_defer (struct sdw_bus *bus,struct sdw_msg *msg,struct sdw_defer *defer);drivers/soundwire/stream.c new file +337
-0@@ -0,0 +1,337 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// Copyright(c) 2015-18 Intel Corporation. + +/* +* stream.c - SoundWire Bus stream operations. +*/ + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/slab.h> +#include <linux/soundwire/sdw.h> +#include "bus.h" + +/** +* sdw_release_stream: Free the assigned stream runtime +* +* @stream: SoundWire stream runtime +* +* sdw_release_stream should be called only once per stream +*/ +void sdw_release_stream (struct sdw_stream_runtime *stream) +{ +kfree (stream); +} +EXPORT_SYMBOL (sdw_release_stream); + +/** +* sdw_alloc_stream: Allocate and return stream runtime +* +* @stream_name: SoundWire stream name +* +* Allocates a SoundWire stream runtime instance. +* sdw_alloc_stream should be called only once per stream +*/ +struct sdw_stream_runtime *sdw_alloc_stream (char *stream_name) +{ +struct sdw_stream_runtime *stream; + + stream =kzalloc (sizeof (*stream),GFP_KERNEL ); +if (!stream) +return NULL ; + + stream->name = stream_name; + stream->state =SDW_STREAM_ALLOC ; + +return stream; +} +EXPORT_SYMBOL (sdw_alloc_stream); + +/** +* sdw_alloc_master_rt: Allocates and initialize Master runtime handle +* +* @bus: SDW bus instance +* @stream_config: Stream configuration +* @stream: Stream runtime handle. +* +* This function is to be called with bus_lock held. +*/ +static struct sdw_master_runtime +*sdw_alloc_master_rt (struct sdw_bus *bus, +struct sdw_stream_config *stream_config, +struct sdw_stream_runtime *stream) +{ +struct sdw_master_runtime *m_rt; + + m_rt = stream->m_rt; +if (m_rt) + goto stream_config; + + m_rt =kzalloc (sizeof (*m_rt),GFP_KERNEL ); +if (!m_rt) +return NULL ; + +/* Initialization of Master runtime handle */ +INIT_LIST_HEAD (&m_rt->slave_rt_list); + stream->m_rt = m_rt; + +list_add_tail (&m_rt->bus_node, &bus->m_rt_list); + +stream_config: + m_rt->ch_count = stream_config->ch_count; + m_rt->bus = bus; + m_rt->stream = stream; + +return m_rt; +} + +/** +* sdw_alloc_slave_rt: Allocate and initialize Slave runtime handle. +* +* @slave: Slave handle +* @stream_config: Stream configuration +* @stream: Stream runtime handle +* +* This function is to be called with bus_lock held. +*/ +static struct sdw_slave_runtime +*sdw_alloc_slave_rt (struct sdw_slave *slave, +struct sdw_stream_config *stream_config, +struct sdw_stream_runtime *stream) +{ +struct sdw_slave_runtime *s_rt =NULL ; + + s_rt =kzalloc (sizeof (*s_rt),GFP_KERNEL ); +if (!s_rt) +return NULL ; + + + s_rt->ch_count = stream_config->ch_count; + s_rt->direction = stream_config->direction; + s_rt->slave = slave; + +return s_rt; +} + +/** +* sdw_release_slave_stream: Free Slave(s) runtime handle +* +* @slave: Slave handle. +* @stream: Stream runtime handle. +* +* This function is to be called with bus_lock held. +*/ +static void sdw_release_slave_stream (struct sdw_slave *slave, +struct sdw_stream_runtime *stream) +{ +struct sdw_slave_runtime *s_rt, *_s_rt; +struct sdw_master_runtime *m_rt = stream->m_rt; + +/* Retrieve Slave runtime handle */ +list_for_each_entry_safe (s_rt, _s_rt, + &m_rt->slave_rt_list, m_rt_node) { + +if (s_rt->slave == slave) { +list_del (&s_rt->m_rt_node); +kfree (s_rt); +return ; + } + } +} + +static void sdw_release_master_stream (struct sdw_stream_runtime *stream) +{ +struct sdw_master_runtime *m_rt = stream->m_rt; +struct sdw_slave_runtime *s_rt, *_s_rt; + +list_for_each_entry_safe (s_rt, _s_rt, + &m_rt->slave_rt_list, m_rt_node) +sdw_release_slave_stream (s_rt->slave, stream); + +list_del (&m_rt->bus_node); +} + +/** +* sdw_stream_remove_master: Remove master from sdw_stream +* +* @bus: SDW Bus instance +* @stream: Soundwire stream +* +* This removes and frees master_rt from a stream +*/ + +int sdw_stream_remove_master (struct sdw_bus *bus, +struct sdw_stream_runtime *stream) +{ +mutex_lock (&bus->bus_lock); + +sdw_release_master_stream (stream); + stream->state =SDW_STREAM_RELEASE ; +kfree (stream->m_rt); + stream->m_rt =NULL ; + +mutex_unlock (&bus->bus_lock); + +return 0 ; +} +EXPORT_SYMBOL (sdw_stream_remove_master); + +/** +* sdw_stream_remove_slave: Remove slave from sdw_stream +* +* @slave: SDW Slave instance +* @stream: Soundwire stream +* +* This removes and frees slave_rt from a stream +*/ + +int sdw_stream_remove_slave (struct sdw_slave *slave, +struct sdw_stream_runtime *stream) +{ +mutex_lock (&slave->bus->bus_lock); + +sdw_release_slave_stream (slave, stream); + +mutex_unlock (&slave->bus->bus_lock); + +return 0 ; +} +EXPORT_SYMBOL (sdw_stream_remove_slave); + +static int sdw_config_stream (struct device *dev, +struct sdw_stream_runtime *stream, +struct sdw_stream_config *stream_config) +{ + +/* +* Update the stream rate, channel and bps based on data +* transmitter. For more than one transmitter (multilink), +* match the rate, bps and increment number of channels. +*/ +if ((stream->params.rate) && + (stream->params.rate != stream_config->frame_rate)) { +dev_err (dev,"rate for multilink not matching, stream:%s" , + stream->name); +return -EINVAL ; + } + +if ((stream->params.bps) && + (stream->params.bps != stream_config->bps)) { +dev_err (dev,"bps for multilink not matching, stream:%s" , + stream->name); +return -EINVAL ; + } + + stream->params.rate = stream_config->frame_rate; + stream->params.bps = stream_config->bps; + stream->params.ch_count += stream_config->ch_count; + stream->type = stream_config->type; + +return 0 ; +} + +/** +* sdw_stream_add_master: Allocate and add master runtime to a stream +* +* @bus: SDW Bus instance +* @stream_config: Stream configuration for audio stream +* @stream: Soundwire stream +*/ +int sdw_stream_add_master (struct sdw_bus *bus, +struct sdw_stream_config *stream_config, +struct sdw_stream_runtime *stream) +{ +struct sdw_master_runtime *m_rt =NULL ; +int ret; + +if (stream->state !=SDW_STREAM_ALLOC && + stream->state !=SDW_STREAM_CONFIG ) { +dev_err (bus->dev, +"Invalid stream state %d" , stream->state); +return -EINVAL ; + } + +mutex_lock (&bus->bus_lock); + + m_rt =sdw_alloc_master_rt (bus, stream_config, stream); +if (!m_rt) { +dev_err (bus->dev, +"Master runtime config failed for stream:%s" , + stream->name); + ret = -ENOMEM ; + goto error; + } + +if (!list_empty (&m_rt->slave_rt_list) && + stream->state ==SDW_STREAM_ALLOC ) + stream->state =SDW_STREAM_CONFIG ; + +error: +mutex_unlock (&bus->bus_lock); +return ret; + +} +EXPORT_SYMBOL (sdw_stream_add_master); + +/** +* sdw_stream_add_slave: Allocate and add master/slave runtime to a stream +* +* @slave: SDW Slave instance +* @stream_config: Stream configuration for audio stream +* @stream: Soundwire stream +*/ +int sdw_stream_add_slave (struct sdw_slave *slave, +struct sdw_stream_config *stream_config, +struct sdw_stream_runtime *stream) +{ +struct sdw_slave_runtime *s_rt; +struct sdw_master_runtime *m_rt; +int ret; + +if (stream->state !=SDW_STREAM_ALLOC && + stream->state !=SDW_STREAM_CONFIG ) { +dev_err (&slave->dev, +"Invalid stream state %d" , stream->state); +return -EINVAL ; + } + +mutex_lock (&slave->bus->bus_lock); + +/* +* If this API is invoked by slave first then m_rt is not valid. +* So, allocate that and add the slave to it. +*/ + m_rt =sdw_alloc_master_rt (slave->bus, stream_config, stream); +if (!m_rt) { +dev_err (&slave->dev, +"alloc master runtime failed for stream:%s" , + stream->name); + ret = -ENOMEM ; + goto error; + } + + s_rt =sdw_alloc_slave_rt (slave, stream_config, stream); +if (!s_rt) { +dev_err (&slave->dev, +"Slave runtime config failed for stream:%s" , + stream->name); + ret = -ENOMEM ; + goto error; + } + + ret =sdw_config_stream (&slave->dev, stream, stream_config); +if (ret) + goto error; + +list_add_tail (&s_rt->m_rt_node, &m_rt->slave_rt_list); + + stream->state =SDW_STREAM_CONFIG ; + +error: +mutex_unlock (&slave->bus->bus_lock); +return ret; +} +EXPORT_SYMBOL (sdw_stream_add_slave);include/linux/soundwire/sdw.h +16
-0@@ -61,6 +61,33 @@ enum sdw_command_response { SDW_CMD_FAIL_OTHER = 4, }; +/** +* enum sdw_stream_type: data stream type +* +* @SDW_STREAM_PCM: PCM data stream +* @SDW_STREAM_PDM: PDM data stream +* +* spec doesn't define this, but is used in implementation +*/ +enum sdw_stream_type { +SDW_STREAM_PCM =0 , +SDW_STREAM_PDM =1 , +}; + +/** +* enum sdw_data_direction: Data direction +*
include/linux/soundwire/sdw.h enum sdw_command_response { · line 89
Quoted 10 lines
include/linux/soundwire/sdw.h +10
-0+* @SDW_DATA_DIR_IN: Data into Port +* @SDW_DATA_DIR_OUT: Data out of Port +* +* For TX it would refer to SDW_DATA_DIR_OUT. For RX it would be +* SDW_DATA_DIR_IN +*/ +enum sdw_data_direction { +SDW_DATA_DIR_IN =0 , +SDW_DATA_DIR_OUT =1 , +};
WTH? Didn't we agree that we would use SoundWire concepts instead of redefining new concepts.
Looks like all my previous feedback was ignored...
Quoted 111 lines
include/linux/soundwire/sdw.h +86
-0+/* * SDW properties, defined in MIPI DisCo spec v1.0 */ @@ -450,6 +477,9 @@ struct sdw_master_ops {* @msg_lock: message lock * @ops: Master callback ops * @prop: Master properti +* @m_rt_list: List of Master instance of all stream(s) running on Bus. This +* is used to compute and program bus bandwidth, clock, frame shape, +* transport and port parameters * @defer_msg: Defer message * @clk_stop_timeout: Clock stop timeout computed */ @@ -462,6 +492,7 @@ struct sdw_bus {struct mutex msg_lock;const struct sdw_master_ops *ops;struct sdw_master_prop prop; +struct list_head m_rt_list;struct sdw_defer defer_msg;unsigned int clk_stop_timeout; };@@ -469,6 +500,87 @@ struct sdw_bus {int sdw_add_bus_master (struct sdw_bus *bus);void sdw_delete_bus_master (struct sdw_bus *bus); +/** +* sdw_stream_config: Master or Slave stream configuration +* +* @frame_rate: Audio frame rate of the stream, in Hz +* @ch_count: Channel count of the stream +* @bps: Number of bits per audio sample +* @direction: Data direction +* @type: Stream type PCM or PDM +*/ +struct sdw_stream_config { +unsigned int frame_rate; +unsigned int ch_count; +unsigned int bps; +enum sdw_data_direction direction; +enum sdw_stream_type type; +}; + +/** +* sdw_stream_state: Stream states +* +* @SDW_STREAM_RELEASE: Stream released +* @SDW_STREAM_ALLOC: New stream allocated. +* @SDW_STREAM_CONFIG: Stream configured +* @SDW_STREAM_PREPARE: Stream prepared +* @SDW_STREAM_ENABLE: Stream enabled +* @SDW_STREAM_DISABLE: Stream disabled +* @SDW_STREAM_DEPREPARE: Stream de-prepared +*/ +enum sdw_stream_state { +SDW_STREAM_RELEASE =0 , +SDW_STREAM_ALLOC =1 , +SDW_STREAM_CONFIG =2 , +SDW_STREAM_PREPARE =3 , +SDW_STREAM_ENABLE =4 , +SDW_STREAM_DISABLE =5 , +SDW_STREAM_DEPREPARE =6 , +}; + +/** +* sdw_stream_params: Stream parameters +* +* @rate: Sampling frequency, in Hz +* @ch_count: Number of channels +* @bps: bits per channel sample +*/ +struct sdw_stream_params { +unsigned int rate; +unsigned int ch_count; +unsigned int bps; +}; + +/** +* sdw_stream_runtime: Runtime stream parameters +* +* @name: SoundWire stream name +* @params: Stream parameters +* @state: Current state of the stream +* @type: Stream type PCM or PDM +* @m_rt: Master runtime +*/ +struct sdw_stream_runtime { +char *name; +struct sdw_stream_params params; +enum sdw_stream_state state; +enum sdw_stream_type type; +struct sdw_master_runtime *m_rt; +}; + +struct sdw_stream_runtime *sdw_alloc_stream (char *stream_name); +void sdw_release_stream (struct sdw_stream_runtime *stream); +int sdw_stream_add_master (struct sdw_bus *bus, +struct sdw_stream_config *stream_config, +struct sdw_stream_runtime *stream); +int sdw_stream_add_slave (struct sdw_slave *slave, +struct sdw_stream_config *stream_config, +struct sdw_stream_runtime *stream); +int sdw_stream_remove_master (struct sdw_bus *bus, +struct sdw_stream_runtime *stream); +int sdw_stream_remove_slave (struct sdw_slave *slave, +struct sdw_stream_runtime *stream); +/* messaging and data APIs */ int sdw_read (struct sdw_slave *slave,u32 addr);
Re: [PATCH 02/13] soundwire: Add support for SoundWire stream management
Quoted 9 lines · Pierre-Louis Bossart
Quoted 6 lines · Vinod Koul
+/**
+ *sdw_slave_runtime: Runtime Stream parameters for Slave
+ *
+ * @slave: Slave handle
+ * @direction: Data direction w.r.t Slave
+ * @ch_count: Channel count of the Slave w.r.t stream
Quoted 3 lines
same here, I flagged all this already as needing to be fixed. Something's not right here, looks to me like you send the wrong version of the patches...
Somehow missed this bit will fix
Quoted 9 lines
drivers/soundwire/bus.h struct sdw_msg { · line 78
Quoted 7 lines
drivers/soundwire/bus.h +7
-0+struct sdw_master_runtime { +struct sdw_bus *bus; +struct sdw_stream_runtime *stream; +unsigned int ch_count; +struct list_head slave_rt_list; +struct list_head bus_node; +};no direction?
Yes no direction here. Why would sdw_master_runtime need direction.
If you look closely we do have direction but in data ports.
One can argue we can move direction up here and remove from data ports, that seems logical, is that something you would like to see?
Quoted 7 lines
include/linux/soundwire/sdw.h enum sdw_command_response { · line 89
Quoted 4 lines
include/linux/soundwire/sdw.h +4
-0+enum sdw_data_direction { +SDW_DATA_DIR_IN =0 , +SDW_DATA_DIR_OUT =1 , +};WTH? Didn't we agree that we would use SoundWire concepts instead of redefining new concepts.
So we will make this TX/RX as discussed.
Signature · 1 line
~Vinod
Re: [PATCH 02/13] soundwire: Add support for SoundWire stream management
Quoted 10 lines · Vinod Koul
Quoted 9 lines · Pierre-Louis Bossart
Quoted 6 lines · Vinod Koul
+/**
+ *sdw_slave_runtime: Runtime Stream parameters for Slave
+ *
+ * @slave: Slave handle
+ * @direction: Data direction w.r.t Slave
+ * @ch_count: Channel count of the Slave w.r.t stream
Quoted 5 lines
Quoted 3 lines
same here, I flagged all this already as needing to be fixed. Something's not right here, looks to me like you send the wrong version of the patches...
Somehow missed this bit will fix
On this one, I think i need more help.
SO is your question on direction right, we are thinking of making it:
enum sdw_data_direction {
SDW_DATA_TX,
SDW_DATA_RX,
}
and then use it is SDW. Is that okay for you or not..
For ch_count, we will update the comment.
Quoted 30 lines
Quoted 10 lines
drivers/soundwire/bus.h struct sdw_msg { · line 78
Quoted 8 lines
drivers/soundwire/bus.h +7
-0+struct sdw_master_runtime { +struct sdw_bus *bus; +struct sdw_stream_runtime *stream; +unsigned int ch_count; +struct list_head slave_rt_list; +struct list_head bus_node; +};no direction?
Yes no direction here. Why would
sdw_master_runtimeneed direction.If you look closely we do have direction but in data ports.
One can argue we can move direction up here and remove from data ports, that seems logical, is that something you would like to see?
Quoted 7 lines
include/linux/soundwire/sdw.h enum sdw_command_response { · line 89
Quoted 4 lines
include/linux/soundwire/sdw.h +4
-0+enum sdw_data_direction { +SDW_DATA_DIR_IN =0 , +SDW_DATA_DIR_OUT =1 , +};WTH? Didn't we agree that we would use SoundWire concepts instead of redefining new concepts.
So we will make this TX/RX as discussed.
Signature · 1 line
~Vinod
Signature · 1 line
~Vinod
PATCH 3/13 soundwire: Add support for port management
In reply to Vinod KoulAdd Soundwire port data structures and APIS for initialization and release of ports.
--- drivers/soundwire/bus.h | 32 +++++++++ drivers/soundwire/stream.c | 163 +++++++++++++++++++++++++++++++++++++++++- include/linux/soundwire/sdw.h | 67 +++++++++++++++++ 3 files changed, 259 insertions(+), 3 deletions(-)
drivers/soundwire/bus.h +32 -0
@@ -46,18 +46,45 @@ struct sdw_msg { };/** +* sdw_port_runtime: Runtime port parameters for Master or Slave +* +* @num: Port number. For audio streams, valid port number ranges from +* [1,14] +* @ch_mask: Channel mask +* @transport_params: Transport parameters +* @port_params: Port parameters +* @port_node: List node for Master or Slave port_list +* +* SoundWire spec has no mention of ports for Master interface but the +* concept is logically extended. +*/ +struct sdw_port_runtime { +int num; +int ch_mask; +struct sdw_transport_params transport_params; +struct sdw_port_params port_params; +struct list_head port_node; +}; + +/** * sdw_slave_runtime: Runtime Stream parameters for Slave * * @slave: Slave handle * @direction: Data direction w.r.t Slave * @ch_count: Channel count of the Slave w.r.t stream * @m_rt_node: sdw_master_runtime list node +* @port_list: List of Slave Ports for this Stream. This list is +* used for computing and programming transport parameters, port +* parameters, prepare, enable, disable and de-prepare of Slave port +* maintains list of Slave runtime associated with Master runtime for +* this stream */ struct sdw_slave_runtime {struct sdw_slave *slave;enum sdw_data_direction direction;unsigned int ch_count;struct list_head m_rt_node; +struct list_head port_list; };/**
@@ -67,6 +94,10 @@ struct sdw_slave_runtime {* @stream: Stream runtime handle * @ch_count: Master channel count * @slave_rt_list: Slave runtime list +* @port_list: List of Master Ports for this Stream. This list is +* used for computing and programming transport parameters, port +* parameters of Master port +* @slave_list: Slave runtime list * @bus_node: sdw_bus m_rt_list node */ struct sdw_master_runtime {
@@ -74,6 +105,7 @@ struct sdw_master_runtime {struct sdw_stream_runtime *stream;unsigned int ch_count;struct list_head slave_rt_list; +struct list_head port_list;struct list_head bus_node; };
drivers/soundwire/stream.c +160 -3
251 lines not on this page · raw message
include/linux/soundwire/sdw.h +67 -0
94 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 4/13 soundwire: Add Master and Slave port programming
In reply to Vinod KoulFrom: Sanyog Kale <[email protected]>
Master and Slave port registers need to be programmed for each port used in a stream. Add the helpers for port register programming.
--- drivers/soundwire/Makefile | 3 +- drivers/soundwire/bus.h | 4 + drivers/soundwire/runtime.c | 243 ++++++++++++++++++++++++++++++++++++++++++ drivers/soundwire/stream.c | 33 ++++++ include/linux/soundwire/sdw.h | 47 +++++++- 5 files changed, 328 insertions(+), 2 deletions(-) create mode 100644 drivers/soundwire/runtime.c
drivers/soundwire/Makefile +2 -1
@@ -3,7 +3,8 @@ # #Bus Objs -soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o +soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o \ + runtime.o obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o #Cadence Objs
drivers/soundwire/bus.h +4 -0
@@ -109,6 +109,10 @@ struct sdw_master_runtime {struct list_head bus_node; }; +struct sdw_dpn_prop *sdw_get_slave_dpn_prop (struct sdw_slave *slave, +enum sdw_data_direction direction, +unsigned int port_num); +int sdw_transfer (struct sdw_bus *bus,struct sdw_msg *msg);int sdw_transfer_defer (struct sdw_bus *bus,struct sdw_msg *msg,struct sdw_defer *defer);
drivers/soundwire/runtime.c new file +243 -0
243 lines not on this page · raw message
drivers/soundwire/stream.c +33 -0
@@ -492,3 +492,36 @@ int sdw_stream_add_slave(struct sdw_slave *slave,return ret; }EXPORT_SYMBOL (sdw_stream_add_slave); + +/** +* sdw_get_slave_dpn_prop: Get Slave port capabilities +* +* @slave: Slave handle +* @direction: Data direction. +* @port_num: Port number +*/ +struct sdw_dpn_prop *sdw_get_slave_dpn_prop (struct sdw_slave *slave, +enum sdw_data_direction direction, +unsigned int port_num) +{ +struct sdw_dpn_prop *dpn_prop; +u8 num_ports; +int i; + +if (direction ==SDW_DATA_DIR_OUT ) { + num_ports =hweight32 (slave->prop.source_ports); + dpn_prop = slave->prop.src_dpn_prop; + }else { + num_ports =hweight32 (slave->prop.sink_ports); + dpn_prop = slave->prop.sink_dpn_prop; + } + +for (i =0 ; i < num_ports; i++) { + dpn_prop = &dpn_prop[i]; + +if (dpn_prop->num == port_num) +return &dpn_prop[i]; + } + +return NULL ; +}
include/linux/soundwire/sdw.h +46 -1
71 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 5/13 soundwire: Add helpers for ports operations
In reply to Vinod KoulFrom: Sanyog Kale <[email protected]>
Add helpers to configure, prepare, enable, disable and de-prepare ports.
--- drivers/soundwire/bus.c | 26 +++++ drivers/soundwire/bus.h | 2 + drivers/soundwire/runtime.c | 259 ++++++++++++++++++++++++++++++++++++++++++ include/linux/soundwire/sdw.h | 54 +++++++++ 4 files changed, 341 insertions(+)
drivers/soundwire/bus.c +26 -0
@@ -577,6 +577,32 @@ static void sdw_modify_slave_status(struct sdw_slave *slave,mutex_unlock (&slave->bus->bus_lock); } +int sdw_configure_dpn_intr (struct sdw_slave *slave, +int port,bool enable,int mask) +{ +u32 addr; +int ret; +u8 val =0 ; + + addr =SDW_DPN_INTMASK (port); + +/* Set/Clear port ready interrupt mask */ +if (enable) { + val |= mask; + val |=SDW_DPN_INT_PORT_READY ; + }else { + val &= ~(mask); + val &= ~SDW_DPN_INT_PORT_READY ; + } + + ret =sdw_update (slave, addr, (mask |SDW_DPN_INT_PORT_READY ), val); +if (ret <0 ) +dev_err (slave->bus->dev, +"SDW_DPN_INTMASK write failed:%d" , val); + +return ret; +} +static int sdw_initialize_slave (struct sdw_slave *slave) {struct sdw_slave_prop *prop = &slave->prop;
drivers/soundwire/bus.h +2 -0
@@ -112,6 +112,8 @@ struct sdw_master_runtime {struct sdw_dpn_prop *sdw_get_slave_dpn_prop (struct sdw_slave *slave,enum sdw_data_direction direction,unsigned int port_num); +int sdw_configure_dpn_intr (struct sdw_slave *slave,int port, +bool enable,int mask);int sdw_transfer (struct sdw_bus *bus,struct sdw_msg *msg); int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg,
drivers/soundwire/runtime.c +259 -0
262 lines not on this page · raw message
include/linux/soundwire/sdw.h +54 -0
90 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 6/13 soundwire: Add bank switch routine
In reply to Vinod KoulFrom: Sanyog Kale <[email protected]>
SoundWire supports two registers banks. So, program the alternate bank with new configuration and then perfoms bank switch.
--- drivers/soundwire/bus.c | 3 + drivers/soundwire/bus.h | 5 + drivers/soundwire/runtime.c | 241 ++++++++++++++++++++++++++++++++++++++++++ include/linux/soundwire/sdw.h | 50 +++++++++ 4 files changed, 299 insertions(+)
drivers/soundwire/bus.c +3 -0
@@ -78,6 +78,9 @@ int sdw_add_bus_master(struct sdw_bus *bus)return ret; } + bus->params.curr_bank =SDW_BANK0 ; + bus->params.next_bank =SDW_BANK1 ; +return 0 ; }EXPORT_SYMBOL (sdw_add_bus_master);
drivers/soundwire/bus.h +5 -0
@@ -45,6 +45,11 @@ struct sdw_msg {bool page; }; +#define SDW_DOUBLE_RATE_FACTOR 2 + +extern int rows[SDW_FRAME_ROWS ]; +extern int cols[SDW_FRAME_COLS ]; +/** * sdw_port_runtime: Runtime port parameters for Master or Slave *
drivers/soundwire/runtime.c +241 -0
250 lines not on this page · raw message
include/linux/soundwire/sdw.h +50 -0
113 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 7/13 soundwire: Add stream configuration APIs
In reply to Vinod KoulAdd APIs for prepare, enable, disable and de-prepare stream.
--- drivers/soundwire/bus.c | 14 ++++ drivers/soundwire/bus.h | 6 ++ drivers/soundwire/runtime.c | 164 ++++++++++++++++++++++++++++++++++++++++++ drivers/soundwire/stream.c | 151 ++++++++++++++++++++++++++++++++++++++ include/linux/soundwire/sdw.h | 4 ++ 5 files changed, 339 insertions(+)
drivers/soundwire/bus.c +14 -0
@@ -17,6 +17,7 @@*/ int sdw_add_bus_master (struct sdw_bus *bus) { +struct sdw_master_prop *prop =NULL ;int ret;if (!bus->dev) {
@@ -78,6 +79,19 @@ int sdw_add_bus_master(struct sdw_bus *bus)return ret; } +/* +* Initialize clock values based on Master properties. The max +* frequency is read from max_freq property. Current assumption +* is that the bus will start at highest clock frequency when +* powered on. +* +* Default active bank will be 0 as out of reset the Slaves have to +* start with bank 0 (Table 40 of Spec) +*/ + + prop = &bus->prop; + bus->params.max_dr_freq = prop->max_freq *SDW_DOUBLE_RATE_FACTOR ; + bus->params.curr_dr_freq = bus->params.max_dr_freq; bus->params.curr_bank =SDW_BANK0 ; bus->params.next_bank =SDW_BANK1 ;
drivers/soundwire/bus.h +6 -0
@@ -46,6 +46,7 @@ struct sdw_msg { };#define SDW_DOUBLE_RATE_FACTOR 2 +#define SDW_FREQ_MOD_FACTOR 3000extern int rows[SDW_FRAME_ROWS ];extern int cols[SDW_FRAME_COLS ];
@@ -114,6 +115,11 @@ struct sdw_master_runtime {struct list_head bus_node; }; +int _sdw_prepare_stream (struct sdw_stream_runtime *stream); +int _sdw_enable_stream (struct sdw_stream_runtime *stream); +int _sdw_deprepare_stream (struct sdw_stream_runtime *stream); +int _sdw_disable_stream (struct sdw_stream_runtime *stream); +struct sdw_dpn_prop *sdw_get_slave_dpn_prop (struct sdw_slave *slave,enum sdw_data_direction direction,unsigned int port_num);
drivers/soundwire/runtime.c +164 -0
167 lines not on this page · raw message
drivers/soundwire/stream.c +151 -0
154 lines not on this page · raw message
include/linux/soundwire/sdw.h +4 -0
@@ -796,6 +796,10 @@ int sdw_stream_remove_master(struct sdw_bus *bus, struct sdw_stream_runtime *stream);int sdw_stream_remove_slave (struct sdw_slave *slave,struct sdw_stream_runtime *stream); +int sdw_prepare_stream (struct sdw_stream_runtime *stream); +int sdw_enable_stream (struct sdw_stream_runtime *stream); +int sdw_disable_stream (struct sdw_stream_runtime *stream); +int sdw_deprepare_stream (struct sdw_stream_runtime *stream);/* messaging and data APIs */
Signature · 1 line
2.7.4
PATCH 8/13 ASoC: Add SoundWire stream programming interface
In reply to Vinod KoulFrom: Shreyas NC <[email protected]>
SoundWire stream needs to be propagated to all the DAIs(cpu, codec). So, add a snd_soc_dai_set_sdw_stream() API for the same.
--- include/sound/soc-dai.h | 5 +++++ sound/soc/soc-core.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+)
include/sound/soc-dai.h +5 -0
@@ -129,6 +129,9 @@ int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);int snd_soc_dai_set_tdm_slot (struct snd_soc_dai *dai,unsigned int tx_mask,unsigned int rx_mask,int slots,int slot_width); +int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,int direction); +int snd_soc_dai_set_channel_map (struct snd_soc_dai *dai,unsigned int tx_num,unsigned int *tx_slot,unsigned int rx_num,unsigned int *rx_slot);
@@ -168,6 +171,8 @@ struct snd_soc_dai_ops { unsigned int rx_num, unsigned int *rx_slot);int (*set_tristate)(struct snd_soc_dai *dai,int tristate); +int (*set_sdw_stream)(struct snd_soc_dai *dai, +void *stream,int direction);/* * DAI digital mute - optional. * Called by soc-core to minimise any pops.
sound/soc/soc-core.c +20 -0
@@ -2882,6 +2882,26 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,EXPORT_SYMBOL_GPL (snd_soc_dai_set_tdm_slot);/** +* snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation +* @dai: DAI +* @stream: STREAM +* @direction: Stream direction(Playback/Capture) +* SoundWire subsystem doesn't have a notion of direction and we reuse +* the ASoC stream direction to configure sink/source ports. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,int direction) +{ +if (dai->driver->ops->set_sdw_stream) +return dai->driver->ops->set_sdw_stream (dai, stream, direction); +else +return -ENOTSUPP ; +} +EXPORT_SYMBOL_GPL (snd_soc_dai_set_sdw_stream); + +/** * snd_soc_dai_set_channel_map - configure DAI audio channel map * @dai: DAI * @tx_num: how many TX channels
Signature · 1 line
2.7.4
Re: [PATCH 08/13] ASoC: Add SoundWire stream programming interface
Hi,
Quoted 16 lines · Vinod Koul
sound/soc/soc-core.c +8
-0@@ -2882,6 +2882,26 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,EXPORT_SYMBOL_GPL (snd_soc_dai_set_tdm_slot);/** +* snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation +* @dai: DAI +* @stream: STREAM +* @direction: Stream direction(Playback/Capture) +* SoundWire subsystem doesn't have a notion of direction and we reuse +* the ASoC stream direction to configure sink/source ports. +* +* Returns 0 on success, a negative error code otherwise.
sound/soc/soc-core.c int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, · line 2902
Quoted 10 lines
sound/soc/soc-core.c +10
-0+*/ +int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,int direction) +{ +if (dai->driver->ops->set_sdw_stream) +return dai->driver->ops->set_sdw_stream (dai, stream, direction); +else +return -ENOTSUPP ; +} +EXPORT_SYMBOL_GPL (snd_soc_dai_set_sdw_stream);
It's better for this kind of code to be incline function in any header. In general, new symbols increase maintenance cost of binary of kernel-related stuffs. It's preferable to avoid the addition if possible, IMO.
Regards
Takashi Sakamoto
Re: [PATCH 08/13] ASoC: Add SoundWire stream programming interface
Quoted 24 lines · Takashi Sakamoto
Hi,
Quoted 21 lines · Vinod Koul
sound/soc/soc-core.c +14
-0@@ -2882,6 +2882,26 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,EXPORT_SYMBOL_GPL (snd_soc_dai_set_tdm_slot);/** +* snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation +* @dai: DAI +* @stream: STREAM +* @direction: Stream direction(Playback/Capture) +* SoundWire subsystem doesn't have a notion of direction and we reuse +* the ASoC stream direction to configure sink/source ports. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,int direction) +{ +if (dai->driver->ops->set_sdw_stream) +return dai->driver->ops->set_sdw_stream (dai, stream, direction);
Quoted 8 lines
sound/soc/soc-core.c int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, · line 2902
Quoted 4 lines
sound/soc/soc-core.c +4
-0+else +return -ENOTSUPP ; +} +EXPORT_SYMBOL_GPL (snd_soc_dai_set_sdw_stream);It's better for this kind of code to be incline function in any header. In general, new symbols increase maintenance cost of binary of kernel-related stuffs. It's preferable to avoid the addition if possible, IMO.
I don't understand, functionally it's the same, there should not be any increased maintenance either way. Please explain how this makes things "harder"?
thanks,
greg k-h
Re: [PATCH 08/13] ASoC: Add SoundWire stream programming interface
Hi Greg,
I'm sorry for delay but I had a short trip.
Quoted 34 lines · Greg KH
Quoted 24 lines · Takashi Sakamoto
Hi,
Quoted 21 lines · Vinod Koul
sound/soc/soc-core.c +14
-0@@ -2882,6 +2882,26 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,EXPORT_SYMBOL_GPL (snd_soc_dai_set_tdm_slot);/** +* snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation +* @dai: DAI +* @stream: STREAM +* @direction: Stream direction(Playback/Capture) +* SoundWire subsystem doesn't have a notion of direction and we reuse +* the ASoC stream direction to configure sink/source ports. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,int direction) +{ +if (dai->driver->ops->set_sdw_stream) +return dai->driver->ops->set_sdw_stream (dai, stream, direction);Quoted 8 lines
sound/soc/soc-core.c int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, · line 2902
Quoted 4 lines
sound/soc/soc-core.c +4
-0+else +return -ENOTSUPP ; +} +EXPORT_SYMBOL_GPL (snd_soc_dai_set_sdw_stream);It's better for this kind of code to be incline function in any header. In general, new symbols increase maintenance cost of binary of kernel-related stuffs. It's preferable to avoid the addition if possible, IMO.
Quoted 3 lines
I don't understand, functionally it's the same, there should not be any increased maintenance either way. Please explain how this makes things "harder"?
Hm, if so it might be my misunderstanding to reasons for typical usage of inline functions in kernel source, sorry.
In my understanding, exported symbols are put into some sections of ELF binary. Addition of new symbols increases size of the section. Additionally, after linking vmlinux, kbuild scans built-in symbols and make a file with entries of them. The addition increases time of this step. Furthermore, at the end of building kernel, kmod is called to generate some map files for exported symbols in loadable module. In a view of distributors, these files are maintained by binary packages of any type carefully because some incompatibilities can be delivered such as version mismatch.
For these reasons, I think thing goes harder when people carelessly add new symbols for functions with a few codes; e.g. accessing to a member of structure, then simply check an return it. Actually I can see some examples in upstreamed headers.
Thanks
Takashi Sakamoto
Re: [PATCH 08/13] ASoC: Add SoundWire stream programming interface
Quoted 57 lines · Takashi Sakamoto
Hi Greg,
I'm sorry for delay but I had a short trip.
Quoted 34 lines · Greg KH
Quoted 24 lines · Takashi Sakamoto
Hi,
Quoted 21 lines · Vinod Koul
sound/soc/soc-core.c +14
-0@@ -2882,6 +2882,26 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,EXPORT_SYMBOL_GPL (snd_soc_dai_set_tdm_slot);/** +* snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation +* @dai: DAI +* @stream: STREAM +* @direction: Stream direction(Playback/Capture) +* SoundWire subsystem doesn't have a notion of direction and we reuse +* the ASoC stream direction to configure sink/source ports. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int snd_soc_dai_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,int direction) +{ +if (dai->driver->ops->set_sdw_stream) +return dai->driver->ops->set_sdw_stream (dai, stream, direction);Quoted 8 lines
sound/soc/soc-core.c int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, · line 2902
Quoted 4 lines
sound/soc/soc-core.c +4
-0+else +return -ENOTSUPP ; +} +EXPORT_SYMBOL_GPL (snd_soc_dai_set_sdw_stream);It's better for this kind of code to be incline function in any header. In general, new symbols increase maintenance cost of binary of kernel-related stuffs. It's preferable to avoid the addition if possible, IMO.
Quoted 3 lines
I don't understand, functionally it's the same, there should not be any increased maintenance either way. Please explain how this makes things "harder"?
Hm, if so it might be my misunderstanding to reasons for typical usage of inline functions in kernel source, sorry.
In my understanding, exported symbols are put into some sections of ELF binary. Addition of new symbols increases size of the section. Additionally, after linking vmlinux, kbuild scans built-in symbols and make a file with entries of them. The addition increases time of this step. Furthermore, at the end of building kernel, kmod is called to generate some map files for exported symbols in loadable module. In a view of distributors, these files are maintained by binary packages of any type carefully because some incompatibilities can be delivered such as version mismatch.
Quoted 4 lines
For these reasons, I think thing goes harder when people carelessly add new symbols for functions with a few codes; e.g. accessing to a member of structure, then simply check an return it. Actually I can see some examples in upstreamed headers.
The advantage of inline function isn't about the maintenance cost. It's mostly for performance, as well as the binary size reduction.
Actually, when a kernel live-patching comes into play, an inline function is worse from the maintenance POV. Then we'd have to patch every place that is expanded instead of a single place.
However, this doesn't discourage the use of inline function, either. Overall, the performance is still the most important factor for major cases. So I agree with that this particular case can be well inlined, supposing that no complex code is planned to be added in future.
thanks,
Takashi
Re: [PATCH 08/13] ASoC: Add SoundWire stream programming interface
Hi,
Quoted 26 lines · Takashi Iwai
Quoted 21 lines
Quoted 7 lines
Quoted 3 lines
It's better for this kind of code to be incline function in any header. In general, new symbols increase maintenance cost of binary of kernel-related stuffs. It's preferable to avoid the addition if possible, IMO.
I don't understand, functionally it's the same, there should not be any increased maintenance either way. Please explain how this makes things "harder"?
Hm, if so it might be my misunderstanding to reasons for typical usage of inline functions in kernel source, sorry.
In my understanding, exported symbols are put into some sections of ELF binary. Addition of new symbols increases size of the section. Additionally, after linking vmlinux, kbuild scans built-in symbols and make a file with entries of them. The addition increases time of this step. Furthermore, at the end of building kernel, kmod is called to generate some map files for exported symbols in loadable module. In a view of distributors, these files are maintained by binary packages of any type carefully because some incompatibilities can be delivered such as version mismatch.
Quoted 4 lines
For these reasons, I think thing goes harder when people carelessly add new symbols for functions with a few codes; e.g. accessing to a member of structure, then simply check an return it. Actually I can see some examples in upstreamed headers.
Quoted 8 lines
The advantage of inline function isn't about the maintenance cost. It's mostly for performance, as well as the binary size reduction.
Actually, when a kernel live-patching comes into play, an inline function is worse from the maintenance POV. Then we'd have to patch every place that is expanded instead of a single place.
However, this doesn't discourage the use of inline function, either.
I'm OK for this view, and let me add it to my criteria for my daily reviewing work. Thanks for sharing the view.
Quoted 3 lines
Overall, the performance is still the most important factor for major cases. So I agree with that this particular case can be well inlined, supposing that no complex code is planned to be added in future.
I agree with it as well. When developers add more complexity to content of the inline function, then let them convert it to exported symbols.
Thanks
Takashi Sakamoto
Re: [PATCH 08/13] ASoC: Add SoundWire stream programming interface
Quoted 32 lines · Takashi Sakamoto
Hi,
Quoted 29 lines · Takashi Iwai
Quoted 21 lines
Quoted 7 lines
Quoted 3 lines
It's better for this kind of code to be incline function in any header. In general, new symbols increase maintenance cost of binary of kernel-related stuffs. It's preferable to avoid the addition if possible, IMO.
I don't understand, functionally it's the same, there should not be any increased maintenance either way. Please explain how this makes things "harder"?
Hm, if so it might be my misunderstanding to reasons for typical usage of inline functions in kernel source, sorry.
In my understanding, exported symbols are put into some sections of ELF binary. Addition of new symbols increases size of the section. Additionally, after linking vmlinux, kbuild scans built-in symbols and make a file with entries of them. The addition increases time of this step. Furthermore, at the end of building kernel, kmod is called to generate some map files for exported symbols in loadable module. In a view of distributors, these files are maintained by binary packages of any type carefully because some incompatibilities can be delivered such as version mismatch.
Quoted 4 lines
For these reasons, I think thing goes harder when people carelessly add new symbols for functions with a few codes; e.g. accessing to a member of structure, then simply check an return it. Actually I can see some examples in upstreamed headers.
The advantage of inline function isn't about the maintenance cost. It's mostly for performance, as well as the binary size reduction.
Quoted 8 lines
Quoted 5 lines
Actually, when a kernel live-patching comes into play, an inline function is worse from the maintenance POV. Then we'd have to patch every place that is expanded instead of a single place.
However, this doesn't discourage the use of inline function, either.
I'm OK for this view, and let me add it to my criteria for my daily reviewing work. Thanks for sharing the view.
For us the motivation to keep as proposed was prior art. Currently all of the snd_soc_dai_set_* APIs are doing similar functionally of setting something on DAIs and not inlined.
Said that I agree this can be inlined so we shall do so.
Quoted 11 lines
Quoted 3 lines
Overall, the performance is still the most important factor for major cases. So I agree with that this particular case can be well inlined, supposing that no complex code is planned to be added in future.
I agree with it as well. When developers add more complexity to content of the inline function, then let them convert it to exported symbols.
Thanks
Takashi Sakamoto
Signature · 1 line
~Vinod
PATCH 9/13 soundwire: Remove cdns_master_ops
In reply to Vinod KoulFrom: Shreyas NC <[email protected]>
There can be instances where drivers using Cadence IP might want to set sdw_master_ops differently per instance of it's use, so remove the cdns_master_ops and export the APIs.
--- drivers/soundwire/cadence_master.c | 17 ++++++----------- drivers/soundwire/cadence_master.h | 8 ++++++++ drivers/soundwire/intel.c | 11 +++++++++-- 3 files changed, 23 insertions(+), 13 deletions(-)
drivers/soundwire/cadence_master.c +6 -11
@@ -396,7 +396,7 @@ static int cdns_prep_msg(struct sdw_cdns *cdns, struct sdw_msg *msg, int *cmd)return 0 ; } -static enum sdw_command_response +enum sdw_command_response cdns_xfer_msg (struct sdw_bus *bus,struct sdw_msg *msg) {struct sdw_cdns *cdns =bus_to_cdns (bus);
@@ -422,8 +422,9 @@ cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg) exit:return ret; } +EXPORT_SYMBOL (cdns_xfer_msg); -static enum sdw_command_response +enum sdw_command_response cdns_xfer_msg_defer (struct sdw_bus *bus,struct sdw_msg *msg,struct sdw_defer *defer) {
@@ -443,8 +444,9 @@ cdns_xfer_msg_defer(struct sdw_bus *bus,return _cdns_xfer_msg (cdns, msg, cmd,0 , msg->len, true); } +EXPORT_SYMBOL (cdns_xfer_msg_defer); -static enum sdw_command_response +enum sdw_command_response cdns_reset_page_addr (struct sdw_bus *bus,unsigned int dev_num) {struct sdw_cdns *cdns =bus_to_cdns (bus);
@@ -456,6 +458,7 @@ cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num)return cdns_program_scp_addr (cdns, &msg); } +EXPORT_SYMBOL (cdns_reset_page_addr);/* * IRQ handling
@@ -727,14 +730,6 @@ int sdw_cdns_init(struct sdw_cdns *cdns) }EXPORT_SYMBOL (sdw_cdns_init); -struct sdw_master_ops sdw_cdns_master_ops = { - .read_prop = sdw_master_read_prop, - .xfer_msg = cdns_xfer_msg, - .xfer_msg_defer = cdns_xfer_msg_defer, - .reset_page_addr = cdns_reset_page_addr, -}; -EXPORT_SYMBOL (sdw_cdns_master_ops); -/** * sdw_cdns_probe() - Cadence probe routine * @cdns: Cadence instance
drivers/soundwire/cadence_master.h +8 -0
@@ -44,5 +44,13 @@ irqreturn_t sdw_cdns_thread(int irq, void *dev_id);int sdw_cdns_init (struct sdw_cdns *cdns);int sdw_cdns_enable_interrupt (struct sdw_cdns *cdns); +enum sdw_command_response +cdns_xfer_msg (struct sdw_bus *bus,struct sdw_msg *msg); +enum sdw_command_response +cdns_xfer_msg_defer (struct sdw_bus *bus, +struct sdw_msg *msg,struct sdw_defer *defer); + +enum sdw_command_response +cdns_reset_page_addr (struct sdw_bus *bus,unsigned int dev_num);#endif /* __SDW_CADENCE_H */
drivers/soundwire/intel.c +9 -2
@@ -252,6 +252,13 @@ static int intel_prop_read(struct sdw_bus *bus)return 0 ; } +static struct sdw_master_ops sdw_intel_ops = { + .read_prop = sdw_master_read_prop, + .xfer_msg = cdns_xfer_msg, + .xfer_msg_defer = cdns_xfer_msg_defer, + .reset_page_addr = cdns_reset_page_addr, +}; +/* * probe and init */
@@ -276,8 +283,8 @@ static int intel_probe(struct platform_device *pdev)sdw_cdns_probe (&sdw->cdns);/* Set property read ops */ - sdw_cdns_master_ops.read_prop = intel_prop_read; - sdw->cdns.bus.ops = &sdw_cdns_master_ops; + sdw_intel_ops.read_prop = intel_prop_read; + sdw->cdns.bus.ops = &sdw_intel_ops;platform_set_drvdata (pdev, sdw);
Signature · 1 line
2.7.4
PATCH 10/13 soundwire: cdns: Add port routines
In reply to Vinod KoulAdd support for Cadence port management and implement master port ops.
--- drivers/soundwire/cadence_master.c | 256 +++++++++++++++++++++++++++++++++++++ drivers/soundwire/cadence_master.h | 100 +++++++++++++++ drivers/soundwire/intel.c | 1 + 3 files changed, 357 insertions(+)
drivers/soundwire/cadence_master.c +256 -0
@@ -669,6 +669,133 @@ int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns) }EXPORT_SYMBOL (sdw_cdns_enable_interrupt); +static int cdns_allocate_pdi (struct sdw_cdns *cdns, +struct sdw_cdns_pdi **stream, +u32 start,u32 num,u32 pdi_offset) +{ +struct sdw_cdns_pdi *pdi; +int i; + +if (!num) +return 0 ; + + pdi =devm_kcalloc (cdns->dev, num,sizeof (*pdi),GFP_KERNEL ); +if (!pdi) +return -ENOMEM ; + +for (i =0 ; i < num; i++) { + pdi[i].num = i + pdi_offset; + pdi[i].assigned = false; + } + + *stream = pdi; +return 0 ; +} + +/** +* sdw_cdns_pdi_init: PDI initialization routine +* +* @cdns: Cadence instance +* @config: Stream configurations +*/ +int sdw_cdns_pdi_init (struct sdw_cdns *cdns, +struct sdw_cdns_stream_config config) +{ +struct sdw_cdns_streams *stream; +int offset, i, ret; + + cdns->pcm.num_bd = config.pcm_bd; + cdns->pcm.num_in = config.pcm_in; + cdns->pcm.num_out = config.pcm_out; + cdns->pdm.num_bd = config.pdm_bd; + cdns->pdm.num_in = config.pdm_in; + cdns->pdm.num_out = config.pdm_out; + +/* Allocate PDIs for PCMs */ + stream = &cdns->pcm; + +/* First two PDIs are reserved for bulk transfers */ + stream->num_bd -=CDNS_PCM_PDI_OFFSET ; + offset =CDNS_PCM_PDI_OFFSET ; + + ret =cdns_allocate_pdi (cdns, &stream->bd,0 , + stream->num_bd, offset); +if (ret) + goto pcm_error; + + offset += stream->num_bd; + + ret =cdns_allocate_pdi (cdns, &stream->in,0 , + stream->num_in, offset); +if (ret) + goto pcm_error; + + + offset += stream->num_in; + + ret =cdns_allocate_pdi (cdns, &stream->out,0 , + stream->num_out, offset); +if (ret) + goto pcm_error; + +/* Update total number of PCM PDIs */ + stream->num_pdi = stream->num_bd + stream->num_in + stream->num_out; + cdns->num_ports = stream->num_pdi; + +/* Allocate PDIs for PDMs */ + stream = &cdns->pdm; + offset =CDNS_PDM_PDI_OFFSET ; + ret =cdns_allocate_pdi (cdns, &stream->bd,0 , + stream->num_bd, offset); +if (ret) + goto pdm_error; + + offset += stream->num_bd; + + ret =cdns_allocate_pdi (cdns, &stream->in,0 , + stream->num_in, offset); +if (ret) + goto pdm_error; + + offset += stream->num_in; + + ret =cdns_allocate_pdi (cdns, &stream->out,0 , + stream->num_out, offset); +if (ret) + goto pdm_error; + +/* Update total number of PDM PDIs */ + stream->num_pdi = stream->num_bd + stream->num_in + stream->num_out; + cdns->num_ports += stream->num_pdi; + + cdns->ports =devm_kcalloc (cdns->dev, cdns->num_ports, +sizeof (*cdns->ports),GFP_KERNEL ); +if (!cdns->ports) { + ret = -ENOMEM ; + goto pdm_error; + } + +for (i =0 ; i < cdns->num_ports; i++) { + cdns->ports[i].assigned = false; + cdns->ports[i].num = i +1 ;/* Port 0 reserved for bulk */ + } + +return 0 ; + +pdm_error: +kfree (stream->bd); +kfree (stream->in); +kfree (stream->out); + +pcm_error: + stream = &cdns->pcm; +kfree (stream->bd); +kfree (stream->in); +kfree (stream->out); +return ret; +} +EXPORT_SYMBOL (sdw_cdns_pdi_init); +/** * sdw_cdns_init() - Cadence initialization * @cdns: Cadence instance
@@ -730,6 +857,134 @@ int sdw_cdns_init(struct sdw_cdns *cdns) }EXPORT_SYMBOL (sdw_cdns_init); +int cdns_bus_conf (struct sdw_bus *bus,struct sdw_bus_params *params) +{ +struct sdw_cdns *cdns =bus_to_cdns (bus); +int mcp_clkctrl_off, mcp_clkctrl; +int divider; + +if (!params->curr_dr_freq) { +dev_err (cdns->dev,"NULL curr_dr_freq" ); +return -EINVAL ; + } + + divider = (params->max_dr_freq / params->curr_dr_freq) -1 ; + +if (params->next_bank) + mcp_clkctrl_off =CDNS_MCP_CLK_CTRL1 ; +else + mcp_clkctrl_off =CDNS_MCP_CLK_CTRL0 ; + + mcp_clkctrl =cdns_readl (cdns, mcp_clkctrl_off); + mcp_clkctrl |= divider; +cdns_writel (cdns, mcp_clkctrl_off, mcp_clkctrl); + +return 0 ; +} +EXPORT_SYMBOL (cdns_bus_conf); + +static int cdns_port_params (struct sdw_bus *bus, +struct sdw_port_params *p_params,unsigned int bank) +{ +struct sdw_cdns *cdns =bus_to_cdns (bus); +int dpn_config =0 , dpn_config_off; + +if (bank) + dpn_config_off =CDNS_DPN_B1_CONFIG (p_params->num); +else + dpn_config_off =CDNS_DPN_B0_CONFIG (p_params->num); + + dpn_config =cdns_readl (cdns, dpn_config_off); + + dpn_config |= ((p_params->bps -1 ) << +SDW_REG_SHIFT (CDNS_DPN_CONFIG_WL )); + dpn_config |= (p_params->flow_mode << +SDW_REG_SHIFT (CDNS_DPN_CONFIG_PORT_FLOW )); + dpn_config |= (p_params->data_mode << +SDW_REG_SHIFT (CDNS_DPN_CONFIG_PORT_DAT )); + +cdns_writel (cdns, dpn_config_off, dpn_config); + +return 0 ; +} + +static int cdns_transport_params (struct sdw_bus *bus, +struct sdw_transport_params *t_params, +enum sdw_reg_bank bank) +{ +struct sdw_cdns *cdns =bus_to_cdns (bus); +int dpn_offsetctrl =0 , dpn_offsetctrl_off; +int dpn_config =0 , dpn_config_off; +int dpn_hctrl =0 , dpn_hctrl_off; +int num = t_params->port_num; +int dpn_samplectrl_off; + +/* +* Note: Only full data port is supported on the Master side for +* both PCM and PDM ports. +*/ + +if (bank) { + dpn_config_off =CDNS_DPN_B1_CONFIG (num); + dpn_samplectrl_off =CDNS_DPN_B1_SAMPLE_CTRL (num); + dpn_hctrl_off =CDNS_DPN_B1_HCTRL (num); + dpn_offsetctrl_off =CDNS_DPN_B1_OFFSET_CTRL (num); + }else { + dpn_config_off =CDNS_DPN_B0_CONFIG (num); + dpn_samplectrl_off =CDNS_DPN_B0_SAMPLE_CTRL (num); + dpn_hctrl_off =CDNS_DPN_B0_HCTRL (num); + dpn_offsetctrl_off =CDNS_DPN_B0_OFFSET_CTRL (num); + } + + dpn_config =cdns_readl (cdns, dpn_config_off); + + dpn_config |= (t_params->blk_grp_ctrl << +SDW_REG_SHIFT (CDNS_DPN_CONFIG_BGC )); + dpn_config |= (t_params->blk_pkg_mode << +SDW_REG_SHIFT (CDNS_DPN_CONFIG_BPM )); +cdns_writel (cdns, dpn_config_off, dpn_config); + + dpn_offsetctrl |= (t_params->offset1 << +SDW_REG_SHIFT (CDNS_DPN_OFFSET_CTRL_1 )); + dpn_offsetctrl |= (t_params->offset2 << +SDW_REG_SHIFT (CDNS_DPN_OFFSET_CTRL_2 )); +cdns_writel (cdns, dpn_offsetctrl_off, dpn_offsetctrl); + + dpn_hctrl |= (t_params->hstart << +SDW_REG_SHIFT (CDNS_DPN_HCTRL_HSTART )); + dpn_hctrl |= (t_params->hstop <<SDW_REG_SHIFT (CDNS_DPN_HCTRL_HSTOP )); + dpn_hctrl |= (t_params->lane_ctrl << +SDW_REG_SHIFT (CDNS_DPN_HCTRL_LCTRL )); + +cdns_writel (cdns, dpn_hctrl_off, dpn_hctrl); +cdns_writel (cdns, dpn_samplectrl_off, (t_params->sample_interval -1 )); + +return 0 ; +} + +static int cdns_port_enable (struct sdw_bus *bus, +struct sdw_enable_ch *enable_ch,unsigned int bank) +{ +struct sdw_cdns *cdns =bus_to_cdns (bus); +int dpn_chnen_off, ch_mask; + +if (bank) + dpn_chnen_off =CDNS_DPN_B1_CH_EN (enable_ch->num); +else + dpn_chnen_off =CDNS_DPN_B0_CH_EN (enable_ch->num); + + ch_mask = enable_ch->ch_mask * enable_ch->enable; +cdns_writel (cdns, dpn_chnen_off, ch_mask); + +return 0 ; +} + +static const struct sdw_master_port_ops cdns_port_ops = { + .dpn_set_port_params = cdns_port_params, + .dpn_set_port_transport_params = cdns_transport_params, + .dpn_port_enable_ch = cdns_port_enable, +}; +/** * sdw_cdns_probe() - Cadence probe routine * @cdns: Cadence instance
@@ -737,6 +992,7 @@ EXPORT_SYMBOL(sdw_cdns_init);int sdw_cdns_probe (struct sdw_cdns *cdns) {init_completion (&cdns->tx_complete); + cdns->bus.port_ops = &cdns_port_ops;return 0 ; }
drivers/soundwire/cadence_master.h +100 -0
128 lines not on this page · raw message
drivers/soundwire/intel.c +1 -0
@@ -257,6 +257,7 @@ static struct sdw_master_ops sdw_intel_ops = { .xfer_msg = cdns_xfer_msg, .xfer_msg_defer = cdns_xfer_msg_defer, .reset_page_addr = cdns_reset_page_addr, + .set_bus_conf = cdns_bus_conf, };/*
Signature · 1 line
2.7.4
PATCH 11/13 soundwire: cdns: Add stream routines
In reply to Vinod KoulAdd support for Cadence stream initialization and implement stream APIs.
--- drivers/soundwire/cadence_master.c | 180 +++++++++++++++++++++++++++++++++++++ drivers/soundwire/cadence_master.h | 43 +++++++++ 2 files changed, 223 insertions(+)
drivers/soundwire/cadence_master.c +180 -0
@@ -13,6 +13,8 @@#include <linux/mod_devicetable.h> #include <linux/soundwire/sdw_registers.h> #include <linux/soundwire/sdw.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> #include "bus.h" #include "cadence_master.h"
@@ -998,5 +1000,183 @@ int sdw_cdns_probe(struct sdw_cdns *cdns) }EXPORT_SYMBOL (sdw_cdns_probe); +int cdns_set_sdw_stream (struct snd_soc_dai *dai, +void *stream,bool pcm,int direction) +{ +struct sdw_cdns *cdns =snd_soc_dai_get_drvdata (dai); +struct sdw_cdns_dma_data *dma; + + dma =kzalloc (sizeof (*dma),GFP_KERNEL ); +if (!dma) +return -ENOMEM ; + +if (pcm) + dma->stream_type =SDW_STREAM_PCM ; +else + dma->stream_type =SDW_STREAM_PDM ; + + dma->bus = &cdns->bus; + dma->link_id = cdns->instance; + + dma->stream = stream; + +if (direction ==SNDRV_PCM_STREAM_PLAYBACK ) + dai->playback_dma_data = dma; +else + dai->capture_dma_data = dma; + +return 0 ; + +} +EXPORT_SYMBOL (cdns_set_sdw_stream); + +static struct sdw_cdns_pdi *cdns_find_pdi (struct sdw_cdns *cdns, +unsigned int num,struct sdw_cdns_pdi *pdi) +{ +int i; + +for (i =0 ; i < num; i++) { +if (pdi[i].assigned == true) +continue ; + pdi[i].assigned = true; +return &pdi[i]; + } + +return NULL ; +} + +/** +* sdw_cdns_config_stream: Configure a stream +* +* @cdns: Cadence instance +* @port: Cadence data port +* @ch: Channel count +* @dir: Data direction +* @pdi: PDI to be used +*/ +void sdw_cdns_config_stream (struct sdw_cdns *cdns, +struct sdw_cdns_port *port, +u32 ch,u32 dir,struct sdw_cdns_pdi *pdi) +{ +u32 offset, val =0 ; + +if (dir ==SDW_DATA_DIR_IN ) + val =CDNS_PORTCTRL_DIRN ; + + offset =CDNS_PORTCTRL + port->num *CDNS_PORT_OFFSET ; +cdns_updatel (cdns, offset,CDNS_PORTCTRL_DIRN , val); + + val = port->num; + val |= ((1 << ch) -1 ) <<SDW_REG_SHIFT (CDNS_PDI_CONFIG_CHANNEL ); +cdns_writel (cdns,CDNS_PDI_CONFIG (pdi->num), val); +} +EXPORT_SYMBOL (sdw_cdns_config_stream); + +static int cdns_get_pdi (struct sdw_cdns *cdns, +struct sdw_cdns_pdi *pdi, +unsigned int num,u32 ch) +{ +int i, pdis =0 ; +u32 ch_count = ch; + +for (i =0 ; i < num; i++) { +if (pdi[i].assigned == true) +continue ; + +if (pdi[i].ch_count < ch_count) + ch_count -= pdi[i].ch_count; +else + ch_count =0 ; + + pdis++; + +if (!ch_count) +break ; + } + +if (ch_count) +return 0 ; + +return pdis; +} + +/** +* sdw_cdns_get_stream: Get stream information +* +* @cdns: Cadence instance +* @stream: Stream to be allocated +* @ch: Channel count +* @dir: Data direction +*/ +int sdw_cdns_get_stream (struct sdw_cdns *cdns, +struct sdw_cdns_streams *stream, +u32 ch,u32 dir) +{ +int pdis =0 ; + +if (dir ==SDW_DATA_DIR_IN ) + pdis =cdns_get_pdi (cdns, stream->in, stream->num_in, ch); +else + pdis =cdns_get_pdi (cdns, stream->out, stream->num_out, ch); + +/* check if we found PDI, else find in bi-directional */ +if (!pdis) + pdis =cdns_get_pdi (cdns, stream->bd, stream->num_bd, ch); + +return pdis; +} +EXPORT_SYMBOL (sdw_cdns_get_stream); + +/** +* sdw_cdns_alloc_stream: Allocate a stream +* +* @cdns: Cadence instance +* @stream: Stream to be allocated +* @port: Cadence data port +* @ch: Channel count +* @dir: Data direction +*/ +int sdw_cdns_alloc_stream (struct sdw_cdns *cdns, +struct sdw_cdns_streams *stream, +struct sdw_cdns_port *port,u32 ch,u32 dir) +{ +struct sdw_cdns_pdi *pdi =NULL ; + +if (dir ==SDW_DATA_DIR_IN ) + pdi =cdns_find_pdi (cdns, stream->num_in, stream->in); +else + pdi =cdns_find_pdi (cdns, stream->num_out, stream->out); + +/* check if we found a PDI, else find in bi-directional */ +if (!pdi) + pdi =cdns_find_pdi (cdns, stream->num_bd, stream->bd); + +if (!pdi) +return -EIO ; + + port->pdi = pdi; + pdi->l_ch_num =0 ; + pdi->h_ch_num = ch -1 ; + pdi->dir = dir; + pdi->ch_count = ch; + +return 0 ; +} +EXPORT_SYMBOL (sdw_cdns_alloc_stream); + +void sdw_cdns_shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct sdw_cdns_dma_data *dma; + + dma =snd_soc_dai_get_dma_data (dai, substream); +if (!dma) +return ; + +snd_soc_dai_set_dma_data (dai, substream,NULL ); +kfree (dma); +} +EXPORT_SYMBOL (sdw_cdns_shutdown); +MODULE_LICENSE ("Dual BSD/GPL" );MODULE_DESCRIPTION ("Cadence Soundwire Library" );
drivers/soundwire/cadence_master.h +43 -0
64 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 12/13 soundwire: intel: Add stream initialization
In reply to Vinod KoulAdd Intel stream init routines which initialize the Physical Data Interface (PDI), Audio Link Hub (ALH) and Audio shim. Also add bank switch routines.
--- drivers/soundwire/intel.c | 217 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+)
drivers/soundwire/intel.c +217 -0
@@ -9,6 +9,8 @@#include <linux/delay.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> #include <linux/soundwire/sdw_registers.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_intel.h>
@@ -234,6 +236,209 @@ static int intel_shim_init(struct sdw_intel *sdw)return ret; } +/* +* PDI routines +*/ +static void intel_pdi_init (struct sdw_intel *sdw, +struct sdw_cdns_stream_config *config) +{ +void __iomem *shim = sdw->res->shim; +unsigned int link_id = sdw->instance; +int pcm_cap, pdm_cap; + +/* PCM Stream Capability */ + pcm_cap =intel_readw (shim,SDW_SHIM_PCMSCAP (link_id)); + + config->pcm_bd = (pcm_cap &SDW_SHIM_PCMSCAP_BSS ) >> +SDW_REG_SHIFT (SDW_SHIM_PCMSCAP_BSS ); + config->pcm_in = (pcm_cap &SDW_SHIM_PCMSCAP_ISS ) >> +SDW_REG_SHIFT (SDW_SHIM_PCMSCAP_ISS ); + config->pcm_out = (pcm_cap &SDW_SHIM_PCMSCAP_OSS ) >> +SDW_REG_SHIFT (SDW_SHIM_PCMSCAP_OSS ); + +/* PDM Stream Capability */ + pdm_cap =intel_readw (shim,SDW_SHIM_PDMSCAP (link_id)); + + config->pdm_bd = (pdm_cap &SDW_SHIM_PDMSCAP_BSS ) >> +SDW_REG_SHIFT (SDW_SHIM_PDMSCAP_BSS ); + config->pdm_in = (pdm_cap &SDW_SHIM_PDMSCAP_ISS ) >> +SDW_REG_SHIFT (SDW_SHIM_PDMSCAP_ISS ); + config->pdm_out = (pdm_cap &SDW_SHIM_PDMSCAP_OSS ) >> +SDW_REG_SHIFT (SDW_SHIM_PDMSCAP_OSS ); +} + +static int +intel_pdi_get_ch_cap (struct sdw_intel *sdw,unsigned int pdi_num,bool pcm) +{ +void __iomem *shim = sdw->res->shim; +unsigned int link_id = sdw->instance; +int count; + +if (pcm) { + + count =intel_readw (shim,SDW_SHIM_PCMSYCHC (link_id, pdi_num)); + +/* +* TODO: pdi number 2 reports channel count as 1 even though +* it supports 8 channel. Performing hardcoding for pdi +* number 2. +*/ +if (pdi_num ==2 ) + count =7 ; + + }else { + count =intel_readw (shim,SDW_SHIM_PDMSCAP (link_id)); + count = ((count &SDW_SHIM_PDMSCAP_CPSS ) >> +SDW_REG_SHIFT (SDW_SHIM_PDMSCAP_CPSS )); + } + +/* zero based values for channel count in register */ + count++; + +return count; +} + +static int intel_pdi_get_ch_update (struct sdw_intel *sdw, +struct sdw_cdns_pdi *pdi, +unsigned int num_pdi, +unsigned int *num_ch,bool pcm) +{ +int i, ch_count =0 ; + +for (i =0 ; i < num_pdi; i++) { + pdi->ch_count =intel_pdi_get_ch_cap (sdw, pdi->num, pcm); + ch_count += pdi->ch_count; + pdi++; + } + + *num_ch = ch_count; +return 0 ; +} + +static int intel_pdi_stream_ch_update (struct sdw_intel *sdw, +struct sdw_cdns_streams *stream,bool pcm) +{ +intel_pdi_get_ch_update (sdw, stream->bd, stream->num_bd, + &stream->num_ch_bd, pcm); + +intel_pdi_get_ch_update (sdw, stream->in, stream->num_in, + &stream->num_ch_in, pcm); + +intel_pdi_get_ch_update (sdw, stream->out, stream->num_out, + &stream->num_ch_out, pcm); + +return 0 ; +} + +static int intel_pdi_ch_update (struct sdw_intel *sdw) +{ +/* First update PCM streams followed by PDM streams */ +intel_pdi_stream_ch_update (sdw, &sdw->cdns.pcm, true); +intel_pdi_stream_ch_update (sdw, &sdw->cdns.pdm, false); + +return 0 ; +} + +static void +intel_pdi_shim_configure (struct sdw_intel *sdw,struct sdw_cdns_pdi *pdi) +{ +void __iomem *shim = sdw->res->shim; +unsigned int link_id = sdw->instance; +int pdi_conf =0 ; + + pdi->intel_alh_id = (link_id *16 ) + pdi->num +5 ; + +/* +* Program stream parameters to stream SHIM register +* This is applicable for PCM stream only. +*/ +if (pdi->type !=SDW_STREAM_PCM ) +return ; + +if (pdi->dir ==SDW_DATA_DIR_IN ) + pdi_conf |=SDW_SHIM_PCMSYCM_DIR ; +else + pdi_conf &= ~(SDW_SHIM_PCMSYCM_DIR ); + + pdi_conf |= (pdi->intel_alh_id << +SDW_REG_SHIFT (SDW_SHIM_PCMSYCM_STREAM )); + pdi_conf |= (pdi->l_ch_num <<SDW_REG_SHIFT (SDW_SHIM_PCMSYCM_LCHN )); + pdi_conf |= (pdi->h_ch_num <<SDW_REG_SHIFT (SDW_SHIM_PCMSYCM_HCHN )); + +intel_writew (shim,SDW_SHIM_PCMSYCHM (link_id, pdi->num), pdi_conf); +} + +static void +intel_pdi_alh_configure (struct sdw_intel *sdw,struct sdw_cdns_pdi *pdi) +{ +void __iomem *alh = sdw->res->alh; +unsigned int link_id = sdw->instance; +unsigned int conf; + + pdi->intel_alh_id = (link_id *16 ) + pdi->num +5 ; + +/* Program Stream config ALH register */ + conf =intel_readl (alh,SDW_ALH_STRMZCFG (pdi->intel_alh_id)); + + conf |= (SDW_ALH_STRMZCFG_DMAT_VAL << +SDW_REG_SHIFT (SDW_ALH_STRMZCFG_DMAT )); + + conf |= ((pdi->ch_count -1 ) << +SDW_REG_SHIFT (SDW_ALH_STRMZCFG_CHN )); + +intel_writel (alh,SDW_ALH_STRMZCFG (pdi->intel_alh_id), conf); +} + +/* +* bank switch routines +*/ + +static int intel_pre_bank_switch (struct sdw_bus *bus) +{ +struct sdw_cdns *cdns =bus_to_cdns (bus); +struct sdw_intel *sdw =cdns_to_intel (cdns); +void __iomem *shim = sdw->res->shim; +int sync_reg; + +if (!bus->multi_link) +return 0 ; + +/* Read SYNC register */ + sync_reg =intel_readl (shim,SDW_SHIM_SYNC ); + sync_reg |=SDW_SHIM_SYNC_CMDSYNC << sdw->instance; +intel_writel (shim,SDW_SHIM_SYNC , sync_reg); + +return 0 ; +} + +static int intel_post_bank_switch (struct sdw_bus *bus) +{ +struct sdw_cdns *cdns =bus_to_cdns (bus); +struct sdw_intel *sdw =cdns_to_intel (cdns); +void __iomem *shim = sdw->res->shim; +int sync_reg, ret; + +if (!bus->multi_link) +return 0 ; + +/* Read SYNC register */ + sync_reg =intel_readl (shim,SDW_SHIM_SYNC ); + +/* Check CMDSYNC bit set for any Master */ +if (!(sync_reg &SDW_SHIM_SYNC_CMDSYNC_MASK )) +return 0 ; + +/* Set SyncGO bit */ + sync_reg |=SDW_SHIM_SYNC_SYNCGO ; + + ret =intel_clear_bit (shim,SDW_SHIM_SYNC , sync_reg, +SDW_SHIM_SYNC_SYNCGO ); +if (ret <0 ) +dev_err (sdw->cdns.dev,"Post bank switch failed: %d" , ret); + +return ret; +} +static int intel_prop_read (struct sdw_bus *bus) {/* Initialize with default handler to read all DisCo properties */
@@ -265,6 +470,7 @@ static struct sdw_master_ops sdw_intel_ops = {*/ static int intel_probe (struct platform_device *pdev) { +struct sdw_cdns_stream_config config;struct sdw_intel *sdw;int ret;
@@ -287,6 +493,11 @@ static int intel_probe(struct platform_device *pdev) sdw_intel_ops.read_prop = intel_prop_read; sdw->cdns.bus.ops = &sdw_intel_ops; + sdw_intel_ops.pre_bank_switch = intel_pre_bank_switch; + sdw_intel_ops.post_bank_switch = intel_post_bank_switch; + sdw_intel_ops.read_prop = intel_prop_read; + sdw->cdns.bus.ops = &sdw_intel_ops; +platform_set_drvdata (pdev, sdw); ret =sdw_add_bus_master (&sdw->cdns.bus);
@@ -304,9 +515,15 @@ static int intel_probe(struct platform_device *pdev) goto err_init; ret =sdw_cdns_enable_interrupt (&sdw->cdns); + +/* Read the PDI config and initialize cadence PDI */ +intel_pdi_init (sdw, &config); + ret =sdw_cdns_pdi_init (&sdw->cdns, config);if (ret) goto err_init; +intel_pdi_ch_update (sdw); +/* Acquire IRQ */ ret = request_threaded_irq(sdw->res->irq, sdw_cdns_irq, sdw_cdns_thread, IRQF_SHARED, KBUILD_MODNAME,
Signature · 1 line
2.7.4
PATCH 13/13 soundwire: intel: Add audio DAI ops
In reply to Vinod KoulAdd DAI registration and DAI ops for the Intel driver along with callback for topology configuration.
--- drivers/soundwire/Kconfig | 2 +- drivers/soundwire/intel.c | 360 ++++++++++++++++++++++++++++++++++++ drivers/soundwire/intel.h | 4 + drivers/soundwire/intel_init.c | 3 + include/linux/soundwire/sdw.h | 3 + include/linux/soundwire/sdw_intel.h | 14 ++ 6 files changed, 385 insertions(+), 1 deletion(-)
drivers/soundwire/Kconfig +1 -1
@@ -27,7 +27,7 @@ config SOUNDWIRE_INTEL tristate "Intel SoundWire Master driver" select SOUNDWIRE_CADENCE select SOUNDWIRE_BUS - depends on X86 && ACPI + depends on X86 && ACPI && SND_SOC ---help--- SoundWire Intel Master driver. If you have an Intel platform which has a SoundWire Master then
drivers/soundwire/intel.c +360 -0
392 lines not on this page · raw message
drivers/soundwire/intel.h +4 -0
@@ -10,6 +10,8 @@* @shim: Audio shim pointer * @alh: ALH (Audio Link Hub) pointer * @irq: Interrupt line +* @ops: Shim callback ops +* @arg: Shim callback ops argument * * This is set as pdata for each link instance. */
@@ -18,6 +20,8 @@ struct sdw_intel_link_res {void __iomem *shim;void __iomem *alh;int irq; +const struct sdw_intel_ops *ops; + void *arg; };#endif /* __SDW_INTEL_LOCAL_H */
drivers/soundwire/intel_init.c +3 -0
@@ -111,6 +111,9 @@ static struct sdw_intel_ctx link->res.shim = res->mmio_base +SDW_SHIM_BASE ; link->res.alh = res->mmio_base +SDW_ALH_BASE ; + link->res.ops = res->ops; + link->res.arg = res->arg; +memset (&pdevinfo,0 ,sizeof (pdevinfo)); pdevinfo.parent = res->parent;
include/linux/soundwire/sdw.h +3 -0
@@ -38,6 +38,9 @@ struct sdw_slave;#define SDW_VALID_PORT_RANGE (n) (n <= 14 && n >= 1) +#define SDW_DAI_ID_RANGE_START 100 +#define SDW_DAI_ID_RANGE_END 200 +/** * enum sdw_slave_status - Slave status * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
include/linux/soundwire/sdw_intel.h +14 -0
@@ -5,17 +5,31 @@#define __SDW_INTEL_H/** +* struct sdw_intel_ops: Intel audio driver callback ops +* +* @config_stream: configure the stream with the hw_params +*/ +struct sdw_intel_ops { +int (*config_stream)(void *arg,void *substream, +void *dai,void *hw_params,int stream_num); +}; + +/** * struct sdw_intel_res - Soundwire Intel resource structure * @mmio_base: mmio base of SoundWire registers * @irq: interrupt number * @handle: ACPI parent handle * @parent: parent device +* @ops: callback ops +* @arg: callback arg */ struct sdw_intel_res {void __iomem *mmio_base;int irq;acpi_handle handle;struct device *parent; +const struct sdw_intel_ops *ops; +void *arg; };void *sdw_intel_init (acpi_handle *parent_handle,struct sdw_intel_res *res);
Signature · 1 line
2.7.4