xref: /openbmc/linux/drivers/slimbus/slimbus.h (revision cdd38c5f1ce4398ec58fec95904b75824daab7b5)
16da1dfb7SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
246a2bb5aSSagar Dharia /*
346a2bb5aSSagar Dharia  * Copyright (c) 2011-2017, The Linux Foundation
446a2bb5aSSagar Dharia  */
546a2bb5aSSagar Dharia 
646a2bb5aSSagar Dharia #ifndef _DRIVERS_SLIMBUS_H
746a2bb5aSSagar Dharia #define _DRIVERS_SLIMBUS_H
846a2bb5aSSagar Dharia #include <linux/module.h>
946a2bb5aSSagar Dharia #include <linux/device.h>
1046a2bb5aSSagar Dharia #include <linux/mutex.h>
11afbdcc7cSSagar Dharia #include <linux/completion.h>
1246a2bb5aSSagar Dharia #include <linux/slimbus.h>
1346a2bb5aSSagar Dharia 
14ce96188bSSrinivas Kandagatla /* Standard values per SLIMbus spec needed by controllers and devices */
15ce96188bSSrinivas Kandagatla #define SLIM_CL_PER_SUPERFRAME		6144
16ce96188bSSrinivas Kandagatla #define SLIM_CL_PER_SUPERFRAME_DIV8	(SLIM_CL_PER_SUPERFRAME >> 3)
17ce96188bSSrinivas Kandagatla 
18afbdcc7cSSagar Dharia /* SLIMbus message types. Related to interpretation of message code. */
19afbdcc7cSSagar Dharia #define SLIM_MSG_MT_CORE			0x0
20917809e2SSrinivas Kandagatla #define SLIM_MSG_MT_DEST_REFERRED_USER		0x2
21917809e2SSrinivas Kandagatla #define SLIM_MSG_MT_SRC_REFERRED_USER		0x6
22afbdcc7cSSagar Dharia 
23ce96188bSSrinivas Kandagatla /*
24ce96188bSSrinivas Kandagatla  * SLIM Broadcast header format
25ce96188bSSrinivas Kandagatla  * BYTE 0: MT[7:5] RL[4:0]
26ce96188bSSrinivas Kandagatla  * BYTE 1: RSVD[7] MC[6:0]
27ce96188bSSrinivas Kandagatla  * BYTE 2: RSVD[7:6] DT[5:4] PI[3:0]
28ce96188bSSrinivas Kandagatla  */
29ce96188bSSrinivas Kandagatla #define SLIM_MSG_MT_MASK	GENMASK(2, 0)
30ce96188bSSrinivas Kandagatla #define SLIM_MSG_MT_SHIFT	5
31ce96188bSSrinivas Kandagatla #define SLIM_MSG_RL_MASK	GENMASK(4, 0)
32ce96188bSSrinivas Kandagatla #define SLIM_MSG_RL_SHIFT	0
33ce96188bSSrinivas Kandagatla #define SLIM_MSG_MC_MASK	GENMASK(6, 0)
34ce96188bSSrinivas Kandagatla #define SLIM_MSG_MC_SHIFT	0
35ce96188bSSrinivas Kandagatla #define SLIM_MSG_DT_MASK	GENMASK(1, 0)
36ce96188bSSrinivas Kandagatla #define SLIM_MSG_DT_SHIFT	4
37ce96188bSSrinivas Kandagatla 
38ce96188bSSrinivas Kandagatla #define SLIM_HEADER_GET_MT(b)	((b >> SLIM_MSG_MT_SHIFT) & SLIM_MSG_MT_MASK)
39ce96188bSSrinivas Kandagatla #define SLIM_HEADER_GET_RL(b)	((b >> SLIM_MSG_RL_SHIFT) & SLIM_MSG_RL_MASK)
40ce96188bSSrinivas Kandagatla #define SLIM_HEADER_GET_MC(b)	((b >> SLIM_MSG_MC_SHIFT) & SLIM_MSG_MC_MASK)
41ce96188bSSrinivas Kandagatla #define SLIM_HEADER_GET_DT(b)	((b >> SLIM_MSG_DT_SHIFT) & SLIM_MSG_DT_MASK)
42ce96188bSSrinivas Kandagatla 
43ce96188bSSrinivas Kandagatla /* Device management messages used by this framework */
44ce96188bSSrinivas Kandagatla #define SLIM_MSG_MC_REPORT_PRESENT               0x1
45ce96188bSSrinivas Kandagatla #define SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS       0x2
46ce96188bSSrinivas Kandagatla #define SLIM_MSG_MC_REPORT_ABSENT                0xF
47ce96188bSSrinivas Kandagatla 
48abb9c9b8SSrinivas Kandagatla /* Data channel management messages */
49abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_CONNECT_SOURCE		0x10
50abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_CONNECT_SINK		0x11
51abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_DISCONNECT_PORT		0x14
52abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_CHANGE_CONTENT		0x18
53abb9c9b8SSrinivas Kandagatla 
544b14e62aSSagar Dharia /* Clock pause Reconfiguration messages */
554b14e62aSSagar Dharia #define SLIM_MSG_MC_BEGIN_RECONFIGURATION        0x40
564b14e62aSSagar Dharia #define SLIM_MSG_MC_NEXT_PAUSE_CLOCK             0x4A
57abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_NEXT_DEFINE_CHANNEL          0x50
58abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_NEXT_DEFINE_CONTENT          0x51
59abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_NEXT_ACTIVATE_CHANNEL        0x54
60abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_NEXT_DEACTIVATE_CHANNEL      0x55
61abb9c9b8SSrinivas Kandagatla #define SLIM_MSG_MC_NEXT_REMOVE_CHANNEL          0x58
624b14e62aSSagar Dharia #define SLIM_MSG_MC_RECONFIGURE_NOW              0x5F
634b14e62aSSagar Dharia 
644b14e62aSSagar Dharia /* Clock pause values per SLIMbus spec */
654b14e62aSSagar Dharia #define SLIM_CLK_FAST				0
664b14e62aSSagar Dharia #define SLIM_CLK_CONST_PHASE			1
674b14e62aSSagar Dharia #define SLIM_CLK_UNSPECIFIED			2
684b14e62aSSagar Dharia 
69afbdcc7cSSagar Dharia /* Destination type Values */
70afbdcc7cSSagar Dharia #define SLIM_MSG_DEST_LOGICALADDR	0
71afbdcc7cSSagar Dharia #define SLIM_MSG_DEST_ENUMADDR		1
72afbdcc7cSSagar Dharia #define	SLIM_MSG_DEST_BROADCAST		3
73afbdcc7cSSagar Dharia 
7446a2bb5aSSagar Dharia /* Standard values per SLIMbus spec needed by controllers and devices */
7546a2bb5aSSagar Dharia #define SLIM_MAX_CLK_GEAR		10
7646a2bb5aSSagar Dharia #define SLIM_MIN_CLK_GEAR		1
77abb9c9b8SSrinivas Kandagatla #define SLIM_SLOT_LEN_BITS		4
7846a2bb5aSSagar Dharia 
79abb9c9b8SSrinivas Kandagatla /* Indicate that the frequency of the flow and the bus frequency are locked */
80abb9c9b8SSrinivas Kandagatla #define SLIM_CHANNEL_CONTENT_FL		BIT(7)
81abb9c9b8SSrinivas Kandagatla 
82abb9c9b8SSrinivas Kandagatla /* Standard values per SLIMbus spec needed by controllers and devices */
83abb9c9b8SSrinivas Kandagatla #define SLIM_CL_PER_SUPERFRAME		6144
84abb9c9b8SSrinivas Kandagatla #define SLIM_SLOTS_PER_SUPERFRAME	(SLIM_CL_PER_SUPERFRAME >> 2)
85abb9c9b8SSrinivas Kandagatla #define SLIM_SL_PER_SUPERFRAME		(SLIM_CL_PER_SUPERFRAME >> 2)
8646a2bb5aSSagar Dharia /* Manager's logical address is set to 0xFF per spec */
8746a2bb5aSSagar Dharia #define SLIM_LA_MANAGER 0xFF
8846a2bb5aSSagar Dharia 
89afbdcc7cSSagar Dharia #define SLIM_MAX_TIDS			256
9046a2bb5aSSagar Dharia /**
9146a2bb5aSSagar Dharia  * struct slim_framer - Represents SLIMbus framer.
9246a2bb5aSSagar Dharia  * Every controller may have multiple framers. There is 1 active framer device
9346a2bb5aSSagar Dharia  * responsible for clocking the bus.
9446a2bb5aSSagar Dharia  * Manager is responsible for framer hand-over.
9546a2bb5aSSagar Dharia  * @dev: Driver model representation of the device.
9646a2bb5aSSagar Dharia  * @e_addr: Enumeration address of the framer.
9746a2bb5aSSagar Dharia  * @rootfreq: Root Frequency at which the framer can run. This is maximum
9846a2bb5aSSagar Dharia  *	frequency ('clock gear 10') at which the bus can operate.
9946a2bb5aSSagar Dharia  * @superfreq: Superframes per root frequency. Every frame is 6144 bits.
10046a2bb5aSSagar Dharia  */
10146a2bb5aSSagar Dharia struct slim_framer {
10246a2bb5aSSagar Dharia 	struct device		dev;
10346a2bb5aSSagar Dharia 	struct slim_eaddr	e_addr;
10446a2bb5aSSagar Dharia 	int			rootfreq;
10546a2bb5aSSagar Dharia 	int			superfreq;
10646a2bb5aSSagar Dharia };
10746a2bb5aSSagar Dharia 
10846a2bb5aSSagar Dharia #define to_slim_framer(d) container_of(d, struct slim_framer, dev)
10946a2bb5aSSagar Dharia 
11046a2bb5aSSagar Dharia /**
111afbdcc7cSSagar Dharia  * struct slim_msg_txn - Message to be sent by the controller.
112afbdcc7cSSagar Dharia  *			This structure has packet header,
113afbdcc7cSSagar Dharia  *			payload and buffer to be filled (if any)
114afbdcc7cSSagar Dharia  * @rl: Header field. remaining length.
115afbdcc7cSSagar Dharia  * @mt: Header field. Message type.
116afbdcc7cSSagar Dharia  * @mc: Header field. LSB is message code for type mt.
117afbdcc7cSSagar Dharia  * @dt: Header field. Destination type.
118afbdcc7cSSagar Dharia  * @ec: Element code. Used for elemental access APIs.
119afbdcc7cSSagar Dharia  * @tid: Transaction ID. Used for messages expecting response.
120afbdcc7cSSagar Dharia  *	(relevant for message-codes involving read operation)
121afbdcc7cSSagar Dharia  * @la: Logical address of the device this message is going to.
122afbdcc7cSSagar Dharia  *	(Not used when destination type is broadcast.)
123afbdcc7cSSagar Dharia  * @msg: Elemental access message to be read/written
124afbdcc7cSSagar Dharia  * @comp: completion if read/write is synchronous, used internally
125afbdcc7cSSagar Dharia  *	for tid based transactions.
126afbdcc7cSSagar Dharia  */
127afbdcc7cSSagar Dharia struct slim_msg_txn {
128afbdcc7cSSagar Dharia 	u8			rl;
129afbdcc7cSSagar Dharia 	u8			mt;
130afbdcc7cSSagar Dharia 	u8			mc;
131afbdcc7cSSagar Dharia 	u8			dt;
132afbdcc7cSSagar Dharia 	u16			ec;
133afbdcc7cSSagar Dharia 	u8			tid;
134afbdcc7cSSagar Dharia 	u8			la;
135afbdcc7cSSagar Dharia 	struct slim_val_inf	*msg;
136afbdcc7cSSagar Dharia 	struct	completion	*comp;
137afbdcc7cSSagar Dharia };
138afbdcc7cSSagar Dharia 
139afbdcc7cSSagar Dharia /* Frequently used message transaction structures */
140afbdcc7cSSagar Dharia #define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) \
141afbdcc7cSSagar Dharia 	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_LOGICALADDR, 0,\
142afbdcc7cSSagar Dharia 					0, la, msg, }
1434b14e62aSSagar Dharia 
1444b14e62aSSagar Dharia #define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) \
1454b14e62aSSagar Dharia 	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_BROADCAST, 0,\
1464b14e62aSSagar Dharia 					0, la, msg, }
147ce96188bSSrinivas Kandagatla 
148ce96188bSSrinivas Kandagatla #define DEFINE_SLIM_EDEST_TXN(name, mc, rl, la, msg) \
149ce96188bSSrinivas Kandagatla 	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_ENUMADDR, 0,\
150ce96188bSSrinivas Kandagatla 					0, la, msg, }
1514b14e62aSSagar Dharia /**
1524b14e62aSSagar Dharia  * enum slim_clk_state: SLIMbus controller's clock state used internally for
1534b14e62aSSagar Dharia  *	maintaining current clock state.
1544b14e62aSSagar Dharia  * @SLIM_CLK_ACTIVE: SLIMbus clock is active
1554b14e62aSSagar Dharia  * @SLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the
1564b14e62aSSagar Dharia  *	bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the
1574b14e62aSSagar Dharia  *	transition fails, state changes back to SLIM_CLK_ACTIVE
1584b14e62aSSagar Dharia  * @SLIM_CLK_PAUSED: SLIMbus controller clock has paused.
1594b14e62aSSagar Dharia  */
1604b14e62aSSagar Dharia enum slim_clk_state {
1614b14e62aSSagar Dharia 	SLIM_CLK_ACTIVE,
1624b14e62aSSagar Dharia 	SLIM_CLK_ENTERING_PAUSE,
1634b14e62aSSagar Dharia 	SLIM_CLK_PAUSED,
1644b14e62aSSagar Dharia };
1654b14e62aSSagar Dharia 
1664b14e62aSSagar Dharia /**
1674b14e62aSSagar Dharia  * struct slim_sched: Framework uses this structure internally for scheduling.
1684b14e62aSSagar Dharia  * @clk_state: Controller's clock state from enum slim_clk_state
1694b14e62aSSagar Dharia  * @pause_comp: Signals completion of clock pause sequence. This is useful when
1704b14e62aSSagar Dharia  *	client tries to call SLIMbus transaction when controller is entering
1714b14e62aSSagar Dharia  *	clock pause.
1724b14e62aSSagar Dharia  * @m_reconf: This mutex is held until current reconfiguration (data channel
1734b14e62aSSagar Dharia  *	scheduling, message bandwidth reservation) is done. Message APIs can
1744b14e62aSSagar Dharia  *	use the bus concurrently when this mutex is held since elemental access
1754b14e62aSSagar Dharia  *	messages can be sent on the bus when reconfiguration is in progress.
1764b14e62aSSagar Dharia  */
1774b14e62aSSagar Dharia struct slim_sched {
1784b14e62aSSagar Dharia 	enum slim_clk_state	clk_state;
1794b14e62aSSagar Dharia 	struct completion	pause_comp;
1804b14e62aSSagar Dharia 	struct mutex		m_reconf;
1814b14e62aSSagar Dharia };
1824b14e62aSSagar Dharia 
183afbdcc7cSSagar Dharia /**
184abb9c9b8SSrinivas Kandagatla  * enum slim_port_direction: SLIMbus port direction
185abb9c9b8SSrinivas Kandagatla  *
186abb9c9b8SSrinivas Kandagatla  * @SLIM_PORT_SINK: SLIMbus port is a sink
187abb9c9b8SSrinivas Kandagatla  * @SLIM_PORT_SOURCE: SLIMbus port is a source
188abb9c9b8SSrinivas Kandagatla  */
189abb9c9b8SSrinivas Kandagatla enum slim_port_direction {
190abb9c9b8SSrinivas Kandagatla 	SLIM_PORT_SINK = 0,
191abb9c9b8SSrinivas Kandagatla 	SLIM_PORT_SOURCE,
192abb9c9b8SSrinivas Kandagatla };
193abb9c9b8SSrinivas Kandagatla /**
194abb9c9b8SSrinivas Kandagatla  * enum slim_port_state: SLIMbus Port/Endpoint state machine
195abb9c9b8SSrinivas Kandagatla  *	according to SLIMbus Spec 2.0
196abb9c9b8SSrinivas Kandagatla  * @SLIM_PORT_DISCONNECTED: SLIMbus port is disconnected
197abb9c9b8SSrinivas Kandagatla  *	entered from Unconfigure/configured state after
198abb9c9b8SSrinivas Kandagatla  *	DISCONNECT_PORT or REMOVE_CHANNEL core command
199abb9c9b8SSrinivas Kandagatla  * @SLIM_PORT_UNCONFIGURED: SLIMbus port is in unconfigured state.
200abb9c9b8SSrinivas Kandagatla  *	entered from disconnect state after CONNECT_SOURCE/SINK core command
201abb9c9b8SSrinivas Kandagatla  * @SLIM_PORT_CONFIGURED: SLIMbus port is in configured state.
202abb9c9b8SSrinivas Kandagatla  *	entered from unconfigured state after DEFINE_CHANNEL, DEFINE_CONTENT
203abb9c9b8SSrinivas Kandagatla  *	and ACTIVATE_CHANNEL core commands. Ready for data transmission.
204abb9c9b8SSrinivas Kandagatla  */
205abb9c9b8SSrinivas Kandagatla enum slim_port_state {
206abb9c9b8SSrinivas Kandagatla 	SLIM_PORT_DISCONNECTED = 0,
207abb9c9b8SSrinivas Kandagatla 	SLIM_PORT_UNCONFIGURED,
208abb9c9b8SSrinivas Kandagatla 	SLIM_PORT_CONFIGURED,
209abb9c9b8SSrinivas Kandagatla };
210abb9c9b8SSrinivas Kandagatla 
211abb9c9b8SSrinivas Kandagatla /**
212abb9c9b8SSrinivas Kandagatla  * enum slim_channel_state: SLIMbus channel state machine used by core.
213abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_DISCONNECTED: SLIMbus channel is disconnected
214abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_ALLOCATED: SLIMbus channel is allocated
215abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_ASSOCIATED: SLIMbus channel is associated with port
216abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_DEFINED: SLIMbus channel parameters are defined
217abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_CONTENT_DEFINED: SLIMbus channel content is defined
218abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_ACTIVE: SLIMbus channel is active and ready for data
219abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_STATE_REMOVED: SLIMbus channel is inactive and removed
220abb9c9b8SSrinivas Kandagatla  */
221abb9c9b8SSrinivas Kandagatla enum slim_channel_state {
222abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_DISCONNECTED = 0,
223abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_ALLOCATED,
224abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_ASSOCIATED,
225abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_DEFINED,
226abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_CONTENT_DEFINED,
227abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_ACTIVE,
228abb9c9b8SSrinivas Kandagatla 	SLIM_CH_STATE_REMOVED,
229abb9c9b8SSrinivas Kandagatla };
230abb9c9b8SSrinivas Kandagatla 
231abb9c9b8SSrinivas Kandagatla /**
232abb9c9b8SSrinivas Kandagatla  * enum slim_ch_data_fmt: SLIMbus channel data Type identifiers according to
233abb9c9b8SSrinivas Kandagatla  *	Table 60 of SLIMbus Spec 1.01.01
234abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_DATA_FMT_NOT_DEFINED: Undefined
235abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_DATA_FMT_LPCM_AUDIO: LPCM audio
236abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO: IEC61937 Compressed audio
237abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO: Packed PDM audio
238abb9c9b8SSrinivas Kandagatla  */
239abb9c9b8SSrinivas Kandagatla enum slim_ch_data_fmt {
240abb9c9b8SSrinivas Kandagatla 	SLIM_CH_DATA_FMT_NOT_DEFINED = 0,
241abb9c9b8SSrinivas Kandagatla 	SLIM_CH_DATA_FMT_LPCM_AUDIO = 1,
242abb9c9b8SSrinivas Kandagatla 	SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO = 2,
243abb9c9b8SSrinivas Kandagatla 	SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO = 3,
244abb9c9b8SSrinivas Kandagatla };
245abb9c9b8SSrinivas Kandagatla 
246abb9c9b8SSrinivas Kandagatla /**
247*abe9af53SMauro Carvalho Chehab  * enum slim_ch_aux_bit_fmt: SLIMbus channel Aux Field format IDs according to
248abb9c9b8SSrinivas Kandagatla  *	Table 63 of SLIMbus Spec 2.0
249abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_AUX_FMT_NOT_APPLICABLE: Undefined
250abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958: ZCUV for tunneling IEC60958
251abb9c9b8SSrinivas Kandagatla  * @SLIM_CH_AUX_FMT_USER_DEFINED: User defined
252abb9c9b8SSrinivas Kandagatla  */
253abb9c9b8SSrinivas Kandagatla enum slim_ch_aux_bit_fmt {
254abb9c9b8SSrinivas Kandagatla 	SLIM_CH_AUX_FMT_NOT_APPLICABLE = 0,
255abb9c9b8SSrinivas Kandagatla 	SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958 = 1,
256abb9c9b8SSrinivas Kandagatla 	SLIM_CH_AUX_FMT_USER_DEFINED = 0xF,
257abb9c9b8SSrinivas Kandagatla };
258abb9c9b8SSrinivas Kandagatla 
259abb9c9b8SSrinivas Kandagatla /**
260abb9c9b8SSrinivas Kandagatla  * struct slim_channel  - SLIMbus channel, used for state machine
261abb9c9b8SSrinivas Kandagatla  *
262abb9c9b8SSrinivas Kandagatla  * @id: ID of channel
263abb9c9b8SSrinivas Kandagatla  * @prrate: Presense rate of channel from Table 66 of SLIMbus 2.0 Specs
264abb9c9b8SSrinivas Kandagatla  * @seg_dist: segment distribution code from Table 20 of SLIMbus 2.0 Specs
265abb9c9b8SSrinivas Kandagatla  * @data_fmt: Data format of channel.
266abb9c9b8SSrinivas Kandagatla  * @aux_fmt: Aux format for this channel.
267abb9c9b8SSrinivas Kandagatla  * @state: channel state machine
268abb9c9b8SSrinivas Kandagatla  */
269abb9c9b8SSrinivas Kandagatla struct slim_channel {
270abb9c9b8SSrinivas Kandagatla 	int id;
271abb9c9b8SSrinivas Kandagatla 	int prrate;
272abb9c9b8SSrinivas Kandagatla 	int seg_dist;
273abb9c9b8SSrinivas Kandagatla 	enum slim_ch_data_fmt data_fmt;
274abb9c9b8SSrinivas Kandagatla 	enum slim_ch_aux_bit_fmt aux_fmt;
275abb9c9b8SSrinivas Kandagatla 	enum slim_channel_state state;
276abb9c9b8SSrinivas Kandagatla };
277abb9c9b8SSrinivas Kandagatla 
278abb9c9b8SSrinivas Kandagatla /**
279abb9c9b8SSrinivas Kandagatla  * struct slim_port  - SLIMbus port
280abb9c9b8SSrinivas Kandagatla  *
281abb9c9b8SSrinivas Kandagatla  * @id: Port id
282abb9c9b8SSrinivas Kandagatla  * @direction: Port direction, Source or Sink.
283abb9c9b8SSrinivas Kandagatla  * @state: state machine of port.
284abb9c9b8SSrinivas Kandagatla  * @ch: channel associated with this port.
285abb9c9b8SSrinivas Kandagatla  */
286abb9c9b8SSrinivas Kandagatla struct slim_port {
287abb9c9b8SSrinivas Kandagatla 	int id;
288abb9c9b8SSrinivas Kandagatla 	enum slim_port_direction direction;
289abb9c9b8SSrinivas Kandagatla 	enum slim_port_state state;
290abb9c9b8SSrinivas Kandagatla 	struct slim_channel ch;
291abb9c9b8SSrinivas Kandagatla };
292abb9c9b8SSrinivas Kandagatla 
293abb9c9b8SSrinivas Kandagatla /**
294abb9c9b8SSrinivas Kandagatla  * enum slim_transport_protocol: SLIMbus Transport protocol list from
295abb9c9b8SSrinivas Kandagatla  *	Table 47 of SLIMbus 2.0 specs.
296abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_ISO: Isochronous Protocol, no flow control as data rate match
297abb9c9b8SSrinivas Kandagatla  *		channel rate flow control embedded in the data.
298abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_PUSH: Pushed Protocol, includes flow control, Used to carry
299abb9c9b8SSrinivas Kandagatla  *		data whose rate	is equal to, or lower than the channel rate.
300abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_PULL: Pulled Protocol, similar usage as pushed protocol
301abb9c9b8SSrinivas Kandagatla  *		but pull is a unicast.
302abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_LOCKED: Locked Protocol
303abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_ASYNC_SMPLX: Asynchronous Protocol-Simplex
304abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_ASYNC_HALF_DUP: Asynchronous Protocol-Half-duplex
305abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_EXT_SMPLX: Extended Asynchronous Protocol-Simplex
306abb9c9b8SSrinivas Kandagatla  * @SLIM_PROTO_EXT_HALF_DUP: Extended Asynchronous Protocol-Half-duplex
307abb9c9b8SSrinivas Kandagatla  */
308abb9c9b8SSrinivas Kandagatla enum slim_transport_protocol {
309abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_ISO = 0,
310abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_PUSH,
311abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_PULL,
312abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_LOCKED,
313abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_ASYNC_SMPLX,
314abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_ASYNC_HALF_DUP,
315abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_EXT_SMPLX,
316abb9c9b8SSrinivas Kandagatla 	SLIM_PROTO_EXT_HALF_DUP,
317abb9c9b8SSrinivas Kandagatla };
318abb9c9b8SSrinivas Kandagatla 
319abb9c9b8SSrinivas Kandagatla /**
320abb9c9b8SSrinivas Kandagatla  * struct slim_stream_runtime  - SLIMbus stream runtime instance
321abb9c9b8SSrinivas Kandagatla  *
322e464d282SSrinivas Kandagatla  * @name: Name of the stream
323abb9c9b8SSrinivas Kandagatla  * @dev: SLIM Device instance associated with this stream
324abb9c9b8SSrinivas Kandagatla  * @direction: direction of stream
325abb9c9b8SSrinivas Kandagatla  * @prot: Transport protocol used in this stream
326abb9c9b8SSrinivas Kandagatla  * @rate: Data rate of samples *
327abb9c9b8SSrinivas Kandagatla  * @bps: bits per sample
328abb9c9b8SSrinivas Kandagatla  * @ratem: rate multipler which is super frame rate/data rate
329abb9c9b8SSrinivas Kandagatla  * @num_ports: number of ports
330abb9c9b8SSrinivas Kandagatla  * @ports: pointer to instance of ports
331abb9c9b8SSrinivas Kandagatla  * @node: list head for stream associated with slim device.
332abb9c9b8SSrinivas Kandagatla  */
333abb9c9b8SSrinivas Kandagatla struct slim_stream_runtime {
334abb9c9b8SSrinivas Kandagatla 	const char *name;
335abb9c9b8SSrinivas Kandagatla 	struct slim_device *dev;
336abb9c9b8SSrinivas Kandagatla 	int direction;
337abb9c9b8SSrinivas Kandagatla 	enum slim_transport_protocol prot;
338abb9c9b8SSrinivas Kandagatla 	unsigned int rate;
339abb9c9b8SSrinivas Kandagatla 	unsigned int bps;
340abb9c9b8SSrinivas Kandagatla 	unsigned int ratem;
341abb9c9b8SSrinivas Kandagatla 	int num_ports;
342abb9c9b8SSrinivas Kandagatla 	struct slim_port *ports;
343abb9c9b8SSrinivas Kandagatla 	struct list_head node;
344abb9c9b8SSrinivas Kandagatla };
345abb9c9b8SSrinivas Kandagatla 
346abb9c9b8SSrinivas Kandagatla /**
34746a2bb5aSSagar Dharia  * struct slim_controller  - Controls every instance of SLIMbus
34846a2bb5aSSagar Dharia  *				(similar to 'master' on SPI)
34946a2bb5aSSagar Dharia  * @dev: Device interface to this driver
35046a2bb5aSSagar Dharia  * @id: Board-specific number identifier for this controller/bus
35146a2bb5aSSagar Dharia  * @name: Name for this controller
35246a2bb5aSSagar Dharia  * @min_cg: Minimum clock gear supported by this controller (default value: 1)
35346a2bb5aSSagar Dharia  * @max_cg: Maximum clock gear supported by this controller (default value: 10)
35446a2bb5aSSagar Dharia  * @clkgear: Current clock gear in which this bus is running
35546a2bb5aSSagar Dharia  * @laddr_ida: logical address id allocator
35646a2bb5aSSagar Dharia  * @a_framer: Active framer which is clocking the bus managed by this controller
35746a2bb5aSSagar Dharia  * @lock: Mutex protecting controller data structures
35846a2bb5aSSagar Dharia  * @devices: Slim device list
35946a2bb5aSSagar Dharia  * @tid_idr: tid id allocator
36046a2bb5aSSagar Dharia  * @txn_lock: Lock to protect table of transactions
3614b14e62aSSagar Dharia  * @sched: scheduler structure used by the controller
362afbdcc7cSSagar Dharia  * @xfer_msg: Transfer a message on this controller (this can be a broadcast
363afbdcc7cSSagar Dharia  *	control/status message like data channel setup, or a unicast message
364afbdcc7cSSagar Dharia  *	like value element read/write.
36546a2bb5aSSagar Dharia  * @set_laddr: Setup logical address at laddr for the slave with elemental
36646a2bb5aSSagar Dharia  *	address e_addr. Drivers implementing controller will be expected to
36746a2bb5aSSagar Dharia  *	send unicast message to this device with its logical address.
36846a2bb5aSSagar Dharia  * @get_laddr: It is possible that controller needs to set fixed logical
36946a2bb5aSSagar Dharia  *	address table and get_laddr can be used in that case so that controller
37046a2bb5aSSagar Dharia  *	can do this assignment. Use case is when the master is on the remote
37146a2bb5aSSagar Dharia  *	processor side, who is resposible for allocating laddr.
3724b14e62aSSagar Dharia  * @wakeup: This function pointer implements controller-specific procedure
3734b14e62aSSagar Dharia  *	to wake it up from clock-pause. Framework will call this to bring
3744b14e62aSSagar Dharia  *	the controller out of clock pause.
375abb9c9b8SSrinivas Kandagatla  * @enable_stream: This function pointer implements controller-specific procedure
376abb9c9b8SSrinivas Kandagatla  *	to enable a stream.
377abb9c9b8SSrinivas Kandagatla  * @disable_stream: This function pointer implements controller-specific procedure
378abb9c9b8SSrinivas Kandagatla  *	to disable stream.
37946a2bb5aSSagar Dharia  *
38046a2bb5aSSagar Dharia  *	'Manager device' is responsible for  device management, bandwidth
38146a2bb5aSSagar Dharia  *	allocation, channel setup, and port associations per channel.
38246a2bb5aSSagar Dharia  *	Device management means Logical address assignment/removal based on
38346a2bb5aSSagar Dharia  *	enumeration (report-present, report-absent) of a device.
38446a2bb5aSSagar Dharia  *	Bandwidth allocation is done dynamically by the manager based on active
38546a2bb5aSSagar Dharia  *	channels on the bus, message-bandwidth requests made by SLIMbus devices.
38646a2bb5aSSagar Dharia  *	Based on current bandwidth usage, manager chooses a frequency to run
38746a2bb5aSSagar Dharia  *	the bus at (in steps of 'clock-gear', 1 through 10, each clock gear
38846a2bb5aSSagar Dharia  *	representing twice the frequency than the previous gear).
38946a2bb5aSSagar Dharia  *	Manager is also responsible for entering (and exiting) low-power-mode
39046a2bb5aSSagar Dharia  *	(known as 'clock pause').
39146a2bb5aSSagar Dharia  *	Manager can do handover of framer if there are multiple framers on the
39246a2bb5aSSagar Dharia  *	bus and a certain usecase warrants using certain framer to avoid keeping
39346a2bb5aSSagar Dharia  *	previous framer being powered-on.
39446a2bb5aSSagar Dharia  *
39546a2bb5aSSagar Dharia  *	Controller here performs duties of the manager device, and 'interface
39646a2bb5aSSagar Dharia  *	device'. Interface device is responsible for monitoring the bus and
39746a2bb5aSSagar Dharia  *	reporting information such as loss-of-synchronization, data
39846a2bb5aSSagar Dharia  *	slot-collision.
39946a2bb5aSSagar Dharia  */
40046a2bb5aSSagar Dharia struct slim_controller {
40146a2bb5aSSagar Dharia 	struct device		*dev;
40246a2bb5aSSagar Dharia 	unsigned int		id;
40346a2bb5aSSagar Dharia 	char			name[SLIMBUS_NAME_SIZE];
40446a2bb5aSSagar Dharia 	int			min_cg;
40546a2bb5aSSagar Dharia 	int			max_cg;
40646a2bb5aSSagar Dharia 	int			clkgear;
40746a2bb5aSSagar Dharia 	struct ida		laddr_ida;
40846a2bb5aSSagar Dharia 	struct slim_framer	*a_framer;
40946a2bb5aSSagar Dharia 	struct mutex		lock;
41046a2bb5aSSagar Dharia 	struct list_head	devices;
41146a2bb5aSSagar Dharia 	struct idr		tid_idr;
41246a2bb5aSSagar Dharia 	spinlock_t		txn_lock;
4134b14e62aSSagar Dharia 	struct slim_sched	sched;
414afbdcc7cSSagar Dharia 	int			(*xfer_msg)(struct slim_controller *ctrl,
415afbdcc7cSSagar Dharia 					    struct slim_msg_txn *tx);
41646a2bb5aSSagar Dharia 	int			(*set_laddr)(struct slim_controller *ctrl,
41746a2bb5aSSagar Dharia 					     struct slim_eaddr *ea, u8 laddr);
41846a2bb5aSSagar Dharia 	int			(*get_laddr)(struct slim_controller *ctrl,
41946a2bb5aSSagar Dharia 					     struct slim_eaddr *ea, u8 *laddr);
420abb9c9b8SSrinivas Kandagatla 	int		(*enable_stream)(struct slim_stream_runtime *rt);
421abb9c9b8SSrinivas Kandagatla 	int		(*disable_stream)(struct slim_stream_runtime *rt);
4224b14e62aSSagar Dharia 	int			(*wakeup)(struct slim_controller *ctrl);
42346a2bb5aSSagar Dharia };
42446a2bb5aSSagar Dharia 
42546a2bb5aSSagar Dharia int slim_device_report_present(struct slim_controller *ctrl,
42646a2bb5aSSagar Dharia 			       struct slim_eaddr *e_addr, u8 *laddr);
42746a2bb5aSSagar Dharia void slim_report_absent(struct slim_device *sbdev);
42846a2bb5aSSagar Dharia int slim_register_controller(struct slim_controller *ctrl);
42946a2bb5aSSagar Dharia int slim_unregister_controller(struct slim_controller *ctrl);
430afbdcc7cSSagar Dharia void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l);
431afbdcc7cSSagar Dharia int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn);
4324b14e62aSSagar Dharia int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart);
433d3062a21SSrinivas Kandagatla int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);
434d3062a21SSrinivas Kandagatla void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);
43546a2bb5aSSagar Dharia 
slim_tid_txn(u8 mt,u8 mc)436afbdcc7cSSagar Dharia static inline bool slim_tid_txn(u8 mt, u8 mc)
437afbdcc7cSSagar Dharia {
438afbdcc7cSSagar Dharia 	return (mt == SLIM_MSG_MT_CORE &&
439afbdcc7cSSagar Dharia 		(mc == SLIM_MSG_MC_REQUEST_INFORMATION ||
440afbdcc7cSSagar Dharia 		 mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION ||
441afbdcc7cSSagar Dharia 		 mc == SLIM_MSG_MC_REQUEST_VALUE ||
442fcaf3d93SSrinivas Kandagatla 		 mc == SLIM_MSG_MC_REQUEST_CHANGE_VALUE));
443afbdcc7cSSagar Dharia }
444afbdcc7cSSagar Dharia 
slim_ec_txn(u8 mt,u8 mc)445afbdcc7cSSagar Dharia static inline bool slim_ec_txn(u8 mt, u8 mc)
446afbdcc7cSSagar Dharia {
447afbdcc7cSSagar Dharia 	return (mt == SLIM_MSG_MT_CORE &&
448afbdcc7cSSagar Dharia 		((mc >= SLIM_MSG_MC_REQUEST_INFORMATION &&
449afbdcc7cSSagar Dharia 		  mc <= SLIM_MSG_MC_REPORT_INFORMATION) ||
450afbdcc7cSSagar Dharia 		 (mc >= SLIM_MSG_MC_REQUEST_VALUE &&
451afbdcc7cSSagar Dharia 		  mc <= SLIM_MSG_MC_CHANGE_VALUE)));
452afbdcc7cSSagar Dharia }
45346a2bb5aSSagar Dharia #endif /* _LINUX_SLIMBUS_H */
454