Commit 56d4fe31 authored by Vinod Koul's avatar Vinod Koul Committed by Greg Kroah-Hartman

soundwire: Add MIPI DisCo property helpers

MIPI Discovery And Configuration (DisCo) Specification for SoundWire
specifies properties to be implemented for SoundWire Masters and
Slaves. The DisCo spec doesn't mandate these properties. However,
SDW bus cannot work without knowing these values.

The helper functions read the Master and Slave properties.
Implementers of Master or Slave drivers can use any of the below
three mechanisms:
   a) Use these APIs here as .read_prop() callback for Master
      and Slave
   b) Implement own methods and set those as .read_prop(), but invoke
      APIs in this file for generic read and override the values with
      platform specific data
   c) Implement ones own methods which do not use anything provided
      here
Signed-off-by: default avatarSanyog Kale <sanyog.r.kale@intel.com>
Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
Acked-By: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7c3cd189
......@@ -3,5 +3,5 @@
#
#Bus Objs
soundwire-bus-objs := bus_type.o bus.o slave.o
soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o
obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
......@@ -25,6 +25,14 @@ int sdw_add_bus_master(struct sdw_bus *bus)
mutex_init(&bus->bus_lock);
INIT_LIST_HEAD(&bus->slaves);
if (bus->ops->read_prop) {
ret = bus->ops->read_prop(bus);
if (ret < 0) {
dev_err(bus->dev, "Bus read properties failed:%d", ret);
return ret;
}
}
/*
* Device numbers in SoundWire are 0 thru 15. Enumeration device
* number (0), Broadcast device number (15), Group numbers (12 and
......
......@@ -77,6 +77,8 @@ static int sdw_drv_probe(struct device *dev)
if (!id)
return -ENODEV;
slave->ops = drv->ops;
/*
* attach to power domain but don't turn on (last arg)
*/
......@@ -89,7 +91,26 @@ static int sdw_drv_probe(struct device *dev)
}
}
if (ret)
return ret;
/* device is probed so let's read the properties now */
if (slave->ops && slave->ops->read_prop)
slave->ops->read_prop(slave);
/*
* Check for valid clk_stop_timeout, use DisCo worst case value of
* 300ms
*
* TODO: check the timeouts and driver removal case
*/
if (slave->prop.clk_stop_timeout == 0)
slave->prop.clk_stop_timeout = 300;
slave->bus->clk_stop_timeout = max_t(u32, slave->bus->clk_stop_timeout,
slave->prop.clk_stop_timeout);
return 0;
}
static int sdw_drv_remove(struct device *dev)
......
This diff is collapsed.
......@@ -38,6 +38,252 @@ enum sdw_slave_status {
SDW_SLAVE_RESERVED = 3,
};
/*
* SDW properties, defined in MIPI DisCo spec v1.0
*/
enum sdw_clk_stop_reset_behave {
SDW_CLK_STOP_KEEP_STATUS = 1,
};
/**
* enum sdw_p15_behave - Slave Port 15 behaviour when the Master attempts a
* read
* @SDW_P15_READ_IGNORED: Read is ignored
* @SDW_P15_CMD_OK: Command is ok
*/
enum sdw_p15_behave {
SDW_P15_READ_IGNORED = 0,
SDW_P15_CMD_OK = 1,
};
/**
* enum sdw_dpn_type - Data port types
* @SDW_DPN_FULL: Full Data Port is supported
* @SDW_DPN_SIMPLE: Simplified Data Port as defined in spec.
* DPN_SampleCtrl2, DPN_OffsetCtrl2, DPN_HCtrl and DPN_BlockCtrl3
* are not implemented.
* @SDW_DPN_REDUCED: Reduced Data Port as defined in spec.
* DPN_SampleCtrl2, DPN_HCtrl are not implemented.
*/
enum sdw_dpn_type {
SDW_DPN_FULL = 0,
SDW_DPN_SIMPLE = 1,
SDW_DPN_REDUCED = 2,
};
/**
* enum sdw_clk_stop_mode - Clock Stop modes
* @SDW_CLK_STOP_MODE0: Slave can continue operation seamlessly on clock
* restart
* @SDW_CLK_STOP_MODE1: Slave may have entered a deeper power-saving mode,
* not capable of continuing operation seamlessly when the clock restarts
*/
enum sdw_clk_stop_mode {
SDW_CLK_STOP_MODE0 = 0,
SDW_CLK_STOP_MODE1 = 1,
};
/**
* struct sdw_dp0_prop - DP0 properties
* @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
* (inclusive)
* @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
* (inclusive)
* @num_words: number of wordlengths supported
* @words: wordlengths supported
* @flow_controlled: Slave implementation results in an OK_NotReady
* response
* @simple_ch_prep_sm: If channel prepare sequence is required
* @device_interrupts: If implementation-defined interrupts are supported
*
* The wordlengths are specified by Spec as max, min AND number of
* discrete values, implementation can define based on the wordlengths they
* support
*/
struct sdw_dp0_prop {
u32 max_word;
u32 min_word;
u32 num_words;
u32 *words;
bool flow_controlled;
bool simple_ch_prep_sm;
bool device_interrupts;
};
/**
* struct sdw_dpn_audio_mode - Audio mode properties for DPn
* @bus_min_freq: Minimum bus frequency, in Hz
* @bus_max_freq: Maximum bus frequency, in Hz
* @bus_num_freq: Number of discrete frequencies supported
* @bus_freq: Discrete bus frequencies, in Hz
* @min_freq: Minimum sampling frequency, in Hz
* @max_freq: Maximum sampling bus frequency, in Hz
* @num_freq: Number of discrete sampling frequency supported
* @freq: Discrete sampling frequencies, in Hz
* @prep_ch_behave: Specifies the dependencies between Channel Prepare
* sequence and bus clock configuration
* If 0, Channel Prepare can happen at any Bus clock rate
* If 1, Channel Prepare sequence shall happen only after Bus clock is
* changed to a frequency supported by this mode or compatible modes
* described by the next field
* @glitchless: Bitmap describing possible glitchless transitions from this
* Audio Mode to other Audio Modes
*/
struct sdw_dpn_audio_mode {
u32 bus_min_freq;
u32 bus_max_freq;
u32 bus_num_freq;
u32 *bus_freq;
u32 max_freq;
u32 min_freq;
u32 num_freq;
u32 *freq;
u32 prep_ch_behave;
u32 glitchless;
};
/**
* struct sdw_dpn_prop - Data Port DPn properties
* @num: port number
* @max_word: Maximum number of bits in a Payload Channel Sample, 1 to 64
* (inclusive)
* @min_word: Minimum number of bits in a Payload Channel Sample, 1 to 64
* (inclusive)
* @num_words: Number of discrete supported wordlengths
* @words: Discrete supported wordlength
* @type: Data port type. Full, Simplified or Reduced
* @max_grouping: Maximum number of samples that can be grouped together for
* a full data port
* @simple_ch_prep_sm: If the port supports simplified channel prepare state
* machine
* @ch_prep_timeout: Port-specific timeout value, in milliseconds
* @device_interrupts: If set, each bit corresponds to support for
* implementation-defined interrupts
* @max_ch: Maximum channels supported
* @min_ch: Minimum channels supported
* @num_ch: Number of discrete channels supported
* @ch: Discrete channels supported
* @num_ch_combinations: Number of channel combinations supported
* @ch_combinations: Channel combinations supported
* @modes: SDW mode supported
* @max_async_buffer: Number of samples that this port can buffer in
* asynchronous modes
* @block_pack_mode: Type of block port mode supported
* @port_encoding: Payload Channel Sample encoding schemes supported
* @audio_modes: Audio modes supported
*/
struct sdw_dpn_prop {
u32 num;
u32 max_word;
u32 min_word;
u32 num_words;
u32 *words;
enum sdw_dpn_type type;
u32 max_grouping;
bool simple_ch_prep_sm;
u32 ch_prep_timeout;
u32 device_interrupts;
u32 max_ch;
u32 min_ch;
u32 num_ch;
u32 *ch;
u32 num_ch_combinations;
u32 *ch_combinations;
u32 modes;
u32 max_async_buffer;
bool block_pack_mode;
u32 port_encoding;
struct sdw_dpn_audio_mode *audio_modes;
};
/**
* struct sdw_slave_prop - SoundWire Slave properties
* @mipi_revision: Spec version of the implementation
* @wake_capable: Wake-up events are supported
* @test_mode_capable: If test mode is supported
* @clk_stop_mode1: Clock-Stop Mode 1 is supported
* @simple_clk_stop_capable: Simple clock mode is supported
* @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State
* Machine transitions, in milliseconds
* @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine
* transitions, in milliseconds
* @reset_behave: Slave keeps the status of the SlaveStopClockPrepare
* state machine (P=1 SCSP_SM) after exit from clock-stop mode1
* @high_PHY_capable: Slave is HighPHY capable
* @paging_support: Slave implements paging registers SCP_AddrPage1 and
* SCP_AddrPage2
* @bank_delay_support: Slave implements bank delay/bridge support registers
* SCP_BankDelay and SCP_NextFrame
* @p15_behave: Slave behavior when the Master attempts a read to the Port15
* alias
* @lane_control_support: Slave supports lane control
* @master_count: Number of Masters present on this Slave
* @source_ports: Bitmap identifying source ports
* @sink_ports: Bitmap identifying sink ports
* @dp0_prop: Data Port 0 properties
* @src_dpn_prop: Source Data Port N properties
* @sink_dpn_prop: Sink Data Port N properties
*/
struct sdw_slave_prop {
u32 mipi_revision;
bool wake_capable;
bool test_mode_capable;
bool clk_stop_mode1;
bool simple_clk_stop_capable;
u32 clk_stop_timeout;
u32 ch_prep_timeout;
enum sdw_clk_stop_reset_behave reset_behave;
bool high_PHY_capable;
bool paging_support;
bool bank_delay_support;
enum sdw_p15_behave p15_behave;
bool lane_control_support;
u32 master_count;
u32 source_ports;
u32 sink_ports;
struct sdw_dp0_prop *dp0_prop;
struct sdw_dpn_prop *src_dpn_prop;
struct sdw_dpn_prop *sink_dpn_prop;
};
/**
* struct sdw_master_prop - Master properties
* @revision: MIPI spec version of the implementation
* @master_count: Number of masters
* @clk_stop_mode: Bitmap for Clock Stop modes supported
* @max_freq: Maximum Bus clock frequency, in Hz
* @num_clk_gears: Number of clock gears supported
* @clk_gears: Clock gears supported
* @num_freq: Number of clock frequencies supported, in Hz
* @freq: Clock frequencies supported, in Hz
* @default_frame_rate: Controller default Frame rate, in Hz
* @default_row: Number of rows
* @default_col: Number of columns
* @dynamic_frame: Dynamic frame supported
* @err_threshold: Number of times that software may retry sending a single
* command
* @dpn_prop: Data Port N properties
*/
struct sdw_master_prop {
u32 revision;
u32 master_count;
enum sdw_clk_stop_mode clk_stop_mode;
u32 max_freq;
u32 num_clk_gears;
u32 *clk_gears;
u32 num_freq;
u32 *freq;
u32 default_frame_rate;
u32 default_row;
u32 default_col;
bool dynamic_frame;
u32 err_threshold;
struct sdw_dpn_prop *dpn_prop;
};
int sdw_master_read_prop(struct sdw_bus *bus);
int sdw_slave_read_prop(struct sdw_slave *slave);
/*
* SDW Slave Structures and APIs
*/
......@@ -61,13 +307,24 @@ struct sdw_slave_id {
__u8 sdw_version:4;
};
/**
* struct sdw_slave_ops - Slave driver callback ops
* @read_prop: Read Slave properties
*/
struct sdw_slave_ops {
int (*read_prop)(struct sdw_slave *sdw);
};
/**
* struct sdw_slave - SoundWire Slave
* @id: MIPI device ID
* @dev: Linux device
* @status: Status reported by the Slave
* @bus: Bus handle
* @ops: Slave callback ops
* @prop: Slave properties
* @node: node for bus list
* @port_ready: Port ready completion flag for each Slave port
* @dev_num: Device Number assigned by Bus
*/
struct sdw_slave {
......@@ -75,7 +332,10 @@ struct sdw_slave {
struct device dev;
enum sdw_slave_status status;
struct sdw_bus *bus;
const struct sdw_slave_ops *ops;
struct sdw_slave_prop prop;
struct list_head node;
struct completion *port_ready;
u16 dev_num;
};
......@@ -103,6 +363,14 @@ struct sdw_driver {
* SDW master structures and APIs
*/
/**
* struct sdw_master_ops - Master driver ops
* @read_prop: Read Master properties
*/
struct sdw_master_ops {
int (*read_prop)(struct sdw_bus *bus);
};
/**
* struct sdw_bus - SoundWire bus
* @dev: Master linux device
......@@ -111,6 +379,9 @@ struct sdw_driver {
* @assigned: Bitmap for Slave device numbers.
* Bit set implies used number, bit clear implies unused number.
* @bus_lock: bus lock
* @ops: Master callback ops
* @prop: Master properties
* @clk_stop_timeout: Clock stop timeout computed
*/
struct sdw_bus {
struct device *dev;
......@@ -118,6 +389,9 @@ struct sdw_bus {
struct list_head slaves;
DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
struct mutex bus_lock;
const struct sdw_master_ops *ops;
struct sdw_master_prop prop;
unsigned int clk_stop_timeout;
};
int sdw_add_bus_master(struct sdw_bus *bus);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment