/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2011-2017, The Linux Foundation */ #ifndef _DRIVERS_SLIMBUS_H #define _DRIVERS_SLIMBUS_H #include <linux/module.h> #include <linux/device.h> #include <linux/mutex.h> #include <linux/completion.h> #include <linux/slimbus.h> /* Standard values per SLIMbus spec needed by controllers and devices */ #define SLIM_CL_PER_SUPERFRAME … #define SLIM_CL_PER_SUPERFRAME_DIV8 … /* SLIMbus message types. Related to interpretation of message code. */ #define SLIM_MSG_MT_CORE … #define SLIM_MSG_MT_DEST_REFERRED_USER … #define SLIM_MSG_MT_SRC_REFERRED_USER … /* * SLIM Broadcast header format * BYTE 0: MT[7:5] RL[4:0] * BYTE 1: RSVD[7] MC[6:0] * BYTE 2: RSVD[7:6] DT[5:4] PI[3:0] */ #define SLIM_MSG_MT_MASK … #define SLIM_MSG_MT_SHIFT … #define SLIM_MSG_RL_MASK … #define SLIM_MSG_RL_SHIFT … #define SLIM_MSG_MC_MASK … #define SLIM_MSG_MC_SHIFT … #define SLIM_MSG_DT_MASK … #define SLIM_MSG_DT_SHIFT … #define SLIM_HEADER_GET_MT(b) … #define SLIM_HEADER_GET_RL(b) … #define SLIM_HEADER_GET_MC(b) … #define SLIM_HEADER_GET_DT(b) … /* Device management messages used by this framework */ #define SLIM_MSG_MC_REPORT_PRESENT … #define SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS … #define SLIM_MSG_MC_REPORT_ABSENT … /* Data channel management messages */ #define SLIM_MSG_MC_CONNECT_SOURCE … #define SLIM_MSG_MC_CONNECT_SINK … #define SLIM_MSG_MC_DISCONNECT_PORT … #define SLIM_MSG_MC_CHANGE_CONTENT … /* Clock pause Reconfiguration messages */ #define SLIM_MSG_MC_BEGIN_RECONFIGURATION … #define SLIM_MSG_MC_NEXT_PAUSE_CLOCK … #define SLIM_MSG_MC_NEXT_DEFINE_CHANNEL … #define SLIM_MSG_MC_NEXT_DEFINE_CONTENT … #define SLIM_MSG_MC_NEXT_ACTIVATE_CHANNEL … #define SLIM_MSG_MC_NEXT_DEACTIVATE_CHANNEL … #define SLIM_MSG_MC_NEXT_REMOVE_CHANNEL … #define SLIM_MSG_MC_RECONFIGURE_NOW … /* Clock pause values per SLIMbus spec */ #define SLIM_CLK_FAST … #define SLIM_CLK_CONST_PHASE … #define SLIM_CLK_UNSPECIFIED … /* Destination type Values */ #define SLIM_MSG_DEST_LOGICALADDR … #define SLIM_MSG_DEST_ENUMADDR … #define SLIM_MSG_DEST_BROADCAST … /* Standard values per SLIMbus spec needed by controllers and devices */ #define SLIM_MAX_CLK_GEAR … #define SLIM_MIN_CLK_GEAR … #define SLIM_SLOT_LEN_BITS … /* Indicate that the frequency of the flow and the bus frequency are locked */ #define SLIM_CHANNEL_CONTENT_FL … /* Standard values per SLIMbus spec needed by controllers and devices */ #define SLIM_CL_PER_SUPERFRAME … #define SLIM_SLOTS_PER_SUPERFRAME … #define SLIM_SL_PER_SUPERFRAME … /* Manager's logical address is set to 0xFF per spec */ #define SLIM_LA_MANAGER … #define SLIM_MAX_TIDS … /** * struct slim_framer - Represents SLIMbus framer. * Every controller may have multiple framers. There is 1 active framer device * responsible for clocking the bus. * Manager is responsible for framer hand-over. * @dev: Driver model representation of the device. * @e_addr: Enumeration address of the framer. * @rootfreq: Root Frequency at which the framer can run. This is maximum * frequency ('clock gear 10') at which the bus can operate. * @superfreq: Superframes per root frequency. Every frame is 6144 bits. */ struct slim_framer { … }; #define to_slim_framer(d) … /** * struct slim_msg_txn - Message to be sent by the controller. * This structure has packet header, * payload and buffer to be filled (if any) * @rl: Header field. remaining length. * @mt: Header field. Message type. * @mc: Header field. LSB is message code for type mt. * @dt: Header field. Destination type. * @ec: Element code. Used for elemental access APIs. * @tid: Transaction ID. Used for messages expecting response. * (relevant for message-codes involving read operation) * @la: Logical address of the device this message is going to. * (Not used when destination type is broadcast.) * @msg: Elemental access message to be read/written * @comp: completion if read/write is synchronous, used internally * for tid based transactions. */ struct slim_msg_txn { … }; /* Frequently used message transaction structures */ #define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) … #define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) … #define DEFINE_SLIM_EDEST_TXN(name, mc, rl, la, msg) … /** * enum slim_clk_state: SLIMbus controller's clock state used internally for * maintaining current clock state. * @SLIM_CLK_ACTIVE: SLIMbus clock is active * @SLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the * bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the * transition fails, state changes back to SLIM_CLK_ACTIVE * @SLIM_CLK_PAUSED: SLIMbus controller clock has paused. */ enum slim_clk_state { … }; /** * struct slim_sched: Framework uses this structure internally for scheduling. * @clk_state: Controller's clock state from enum slim_clk_state * @pause_comp: Signals completion of clock pause sequence. This is useful when * client tries to call SLIMbus transaction when controller is entering * clock pause. * @m_reconf: This mutex is held until current reconfiguration (data channel * scheduling, message bandwidth reservation) is done. Message APIs can * use the bus concurrently when this mutex is held since elemental access * messages can be sent on the bus when reconfiguration is in progress. */ struct slim_sched { … }; /** * enum slim_port_direction: SLIMbus port direction * * @SLIM_PORT_SINK: SLIMbus port is a sink * @SLIM_PORT_SOURCE: SLIMbus port is a source */ enum slim_port_direction { … }; /** * enum slim_port_state: SLIMbus Port/Endpoint state machine * according to SLIMbus Spec 2.0 * @SLIM_PORT_DISCONNECTED: SLIMbus port is disconnected * entered from Unconfigure/configured state after * DISCONNECT_PORT or REMOVE_CHANNEL core command * @SLIM_PORT_UNCONFIGURED: SLIMbus port is in unconfigured state. * entered from disconnect state after CONNECT_SOURCE/SINK core command * @SLIM_PORT_CONFIGURED: SLIMbus port is in configured state. * entered from unconfigured state after DEFINE_CHANNEL, DEFINE_CONTENT * and ACTIVATE_CHANNEL core commands. Ready for data transmission. */ enum slim_port_state { … }; /** * enum slim_channel_state: SLIMbus channel state machine used by core. * @SLIM_CH_STATE_DISCONNECTED: SLIMbus channel is disconnected * @SLIM_CH_STATE_ALLOCATED: SLIMbus channel is allocated * @SLIM_CH_STATE_ASSOCIATED: SLIMbus channel is associated with port * @SLIM_CH_STATE_DEFINED: SLIMbus channel parameters are defined * @SLIM_CH_STATE_CONTENT_DEFINED: SLIMbus channel content is defined * @SLIM_CH_STATE_ACTIVE: SLIMbus channel is active and ready for data * @SLIM_CH_STATE_REMOVED: SLIMbus channel is inactive and removed */ enum slim_channel_state { … }; /** * enum slim_ch_data_fmt: SLIMbus channel data Type identifiers according to * Table 60 of SLIMbus Spec 1.01.01 * @SLIM_CH_DATA_FMT_NOT_DEFINED: Undefined * @SLIM_CH_DATA_FMT_LPCM_AUDIO: LPCM audio * @SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO: IEC61937 Compressed audio * @SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO: Packed PDM audio */ enum slim_ch_data_fmt { … }; /** * enum slim_ch_aux_bit_fmt: SLIMbus channel Aux Field format IDs according to * Table 63 of SLIMbus Spec 2.0 * @SLIM_CH_AUX_FMT_NOT_APPLICABLE: Undefined * @SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958: ZCUV for tunneling IEC60958 * @SLIM_CH_AUX_FMT_USER_DEFINED: User defined */ enum slim_ch_aux_bit_fmt { … }; /** * struct slim_channel - SLIMbus channel, used for state machine * * @id: ID of channel * @prrate: Presense rate of channel from Table 66 of SLIMbus 2.0 Specs * @seg_dist: segment distribution code from Table 20 of SLIMbus 2.0 Specs * @data_fmt: Data format of channel. * @aux_fmt: Aux format for this channel. * @state: channel state machine */ struct slim_channel { … }; /** * struct slim_port - SLIMbus port * * @id: Port id * @direction: Port direction, Source or Sink. * @state: state machine of port. * @ch: channel associated with this port. */ struct slim_port { … }; /** * enum slim_transport_protocol: SLIMbus Transport protocol list from * Table 47 of SLIMbus 2.0 specs. * @SLIM_PROTO_ISO: Isochronous Protocol, no flow control as data rate match * channel rate flow control embedded in the data. * @SLIM_PROTO_PUSH: Pushed Protocol, includes flow control, Used to carry * data whose rate is equal to, or lower than the channel rate. * @SLIM_PROTO_PULL: Pulled Protocol, similar usage as pushed protocol * but pull is a unicast. * @SLIM_PROTO_LOCKED: Locked Protocol * @SLIM_PROTO_ASYNC_SMPLX: Asynchronous Protocol-Simplex * @SLIM_PROTO_ASYNC_HALF_DUP: Asynchronous Protocol-Half-duplex * @SLIM_PROTO_EXT_SMPLX: Extended Asynchronous Protocol-Simplex * @SLIM_PROTO_EXT_HALF_DUP: Extended Asynchronous Protocol-Half-duplex */ enum slim_transport_protocol { … }; /** * struct slim_stream_runtime - SLIMbus stream runtime instance * * @name: Name of the stream * @dev: SLIM Device instance associated with this stream * @direction: direction of stream * @prot: Transport protocol used in this stream * @rate: Data rate of samples * * @bps: bits per sample * @ratem: rate multipler which is super frame rate/data rate * @num_ports: number of ports * @ports: pointer to instance of ports * @node: list head for stream associated with slim device. */ struct slim_stream_runtime { … }; /** * struct slim_controller - Controls every instance of SLIMbus * (similar to 'master' on SPI) * @dev: Device interface to this driver * @id: Board-specific number identifier for this controller/bus * @name: Name for this controller * @min_cg: Minimum clock gear supported by this controller (default value: 1) * @max_cg: Maximum clock gear supported by this controller (default value: 10) * @clkgear: Current clock gear in which this bus is running * @laddr_ida: logical address id allocator * @a_framer: Active framer which is clocking the bus managed by this controller * @lock: Mutex protecting controller data structures * @devices: Slim device list * @tid_idr: tid id allocator * @txn_lock: Lock to protect table of transactions * @sched: scheduler structure used by the controller * @xfer_msg: Transfer a message on this controller (this can be a broadcast * control/status message like data channel setup, or a unicast message * like value element read/write. * @set_laddr: Setup logical address at laddr for the slave with elemental * address e_addr. Drivers implementing controller will be expected to * send unicast message to this device with its logical address. * @get_laddr: It is possible that controller needs to set fixed logical * address table and get_laddr can be used in that case so that controller * can do this assignment. Use case is when the master is on the remote * processor side, who is resposible for allocating laddr. * @wakeup: This function pointer implements controller-specific procedure * to wake it up from clock-pause. Framework will call this to bring * the controller out of clock pause. * @enable_stream: This function pointer implements controller-specific procedure * to enable a stream. * @disable_stream: This function pointer implements controller-specific procedure * to disable stream. * * 'Manager device' is responsible for device management, bandwidth * allocation, channel setup, and port associations per channel. * Device management means Logical address assignment/removal based on * enumeration (report-present, report-absent) of a device. * Bandwidth allocation is done dynamically by the manager based on active * channels on the bus, message-bandwidth requests made by SLIMbus devices. * Based on current bandwidth usage, manager chooses a frequency to run * the bus at (in steps of 'clock-gear', 1 through 10, each clock gear * representing twice the frequency than the previous gear). * Manager is also responsible for entering (and exiting) low-power-mode * (known as 'clock pause'). * Manager can do handover of framer if there are multiple framers on the * bus and a certain usecase warrants using certain framer to avoid keeping * previous framer being powered-on. * * Controller here performs duties of the manager device, and 'interface * device'. Interface device is responsible for monitoring the bus and * reporting information such as loss-of-synchronization, data * slot-collision. */ struct slim_controller { … }; int slim_device_report_present(struct slim_controller *ctrl, struct slim_eaddr *e_addr, u8 *laddr); void slim_report_absent(struct slim_device *sbdev); int slim_register_controller(struct slim_controller *ctrl); int slim_unregister_controller(struct slim_controller *ctrl); void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l); int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn); int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart); int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn); void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn); static inline bool slim_tid_txn(u8 mt, u8 mc) { … } static inline bool slim_ec_txn(u8 mt, u8 mc) { … } #endif /* _LINUX_SLIMBUS_H */