xref: /OK3568_Linux_fs/kernel/drivers/slimbus/slimbus.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2011-2017, The Linux Foundation
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #ifndef _DRIVERS_SLIMBUS_H
7*4882a593Smuzhiyun #define _DRIVERS_SLIMBUS_H
8*4882a593Smuzhiyun #include <linux/module.h>
9*4882a593Smuzhiyun #include <linux/device.h>
10*4882a593Smuzhiyun #include <linux/mutex.h>
11*4882a593Smuzhiyun #include <linux/completion.h>
12*4882a593Smuzhiyun #include <linux/slimbus.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /* Standard values per SLIMbus spec needed by controllers and devices */
15*4882a593Smuzhiyun #define SLIM_CL_PER_SUPERFRAME		6144
16*4882a593Smuzhiyun #define SLIM_CL_PER_SUPERFRAME_DIV8	(SLIM_CL_PER_SUPERFRAME >> 3)
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* SLIMbus message types. Related to interpretation of message code. */
19*4882a593Smuzhiyun #define SLIM_MSG_MT_CORE			0x0
20*4882a593Smuzhiyun #define SLIM_MSG_MT_DEST_REFERRED_USER		0x2
21*4882a593Smuzhiyun #define SLIM_MSG_MT_SRC_REFERRED_USER		0x6
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun  * SLIM Broadcast header format
25*4882a593Smuzhiyun  * BYTE 0: MT[7:5] RL[4:0]
26*4882a593Smuzhiyun  * BYTE 1: RSVD[7] MC[6:0]
27*4882a593Smuzhiyun  * BYTE 2: RSVD[7:6] DT[5:4] PI[3:0]
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun #define SLIM_MSG_MT_MASK	GENMASK(2, 0)
30*4882a593Smuzhiyun #define SLIM_MSG_MT_SHIFT	5
31*4882a593Smuzhiyun #define SLIM_MSG_RL_MASK	GENMASK(4, 0)
32*4882a593Smuzhiyun #define SLIM_MSG_RL_SHIFT	0
33*4882a593Smuzhiyun #define SLIM_MSG_MC_MASK	GENMASK(6, 0)
34*4882a593Smuzhiyun #define SLIM_MSG_MC_SHIFT	0
35*4882a593Smuzhiyun #define SLIM_MSG_DT_MASK	GENMASK(1, 0)
36*4882a593Smuzhiyun #define SLIM_MSG_DT_SHIFT	4
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #define SLIM_HEADER_GET_MT(b)	((b >> SLIM_MSG_MT_SHIFT) & SLIM_MSG_MT_MASK)
39*4882a593Smuzhiyun #define SLIM_HEADER_GET_RL(b)	((b >> SLIM_MSG_RL_SHIFT) & SLIM_MSG_RL_MASK)
40*4882a593Smuzhiyun #define SLIM_HEADER_GET_MC(b)	((b >> SLIM_MSG_MC_SHIFT) & SLIM_MSG_MC_MASK)
41*4882a593Smuzhiyun #define SLIM_HEADER_GET_DT(b)	((b >> SLIM_MSG_DT_SHIFT) & SLIM_MSG_DT_MASK)
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /* Device management messages used by this framework */
44*4882a593Smuzhiyun #define SLIM_MSG_MC_REPORT_PRESENT               0x1
45*4882a593Smuzhiyun #define SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS       0x2
46*4882a593Smuzhiyun #define SLIM_MSG_MC_REPORT_ABSENT                0xF
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* Data channel management messages */
49*4882a593Smuzhiyun #define SLIM_MSG_MC_CONNECT_SOURCE		0x10
50*4882a593Smuzhiyun #define SLIM_MSG_MC_CONNECT_SINK		0x11
51*4882a593Smuzhiyun #define SLIM_MSG_MC_DISCONNECT_PORT		0x14
52*4882a593Smuzhiyun #define SLIM_MSG_MC_CHANGE_CONTENT		0x18
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /* Clock pause Reconfiguration messages */
55*4882a593Smuzhiyun #define SLIM_MSG_MC_BEGIN_RECONFIGURATION        0x40
56*4882a593Smuzhiyun #define SLIM_MSG_MC_NEXT_PAUSE_CLOCK             0x4A
57*4882a593Smuzhiyun #define SLIM_MSG_MC_NEXT_DEFINE_CHANNEL          0x50
58*4882a593Smuzhiyun #define SLIM_MSG_MC_NEXT_DEFINE_CONTENT          0x51
59*4882a593Smuzhiyun #define SLIM_MSG_MC_NEXT_ACTIVATE_CHANNEL        0x54
60*4882a593Smuzhiyun #define SLIM_MSG_MC_NEXT_DEACTIVATE_CHANNEL      0x55
61*4882a593Smuzhiyun #define SLIM_MSG_MC_NEXT_REMOVE_CHANNEL          0x58
62*4882a593Smuzhiyun #define SLIM_MSG_MC_RECONFIGURE_NOW              0x5F
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /* Clock pause values per SLIMbus spec */
65*4882a593Smuzhiyun #define SLIM_CLK_FAST				0
66*4882a593Smuzhiyun #define SLIM_CLK_CONST_PHASE			1
67*4882a593Smuzhiyun #define SLIM_CLK_UNSPECIFIED			2
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /* Destination type Values */
70*4882a593Smuzhiyun #define SLIM_MSG_DEST_LOGICALADDR	0
71*4882a593Smuzhiyun #define SLIM_MSG_DEST_ENUMADDR		1
72*4882a593Smuzhiyun #define	SLIM_MSG_DEST_BROADCAST		3
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /* Standard values per SLIMbus spec needed by controllers and devices */
75*4882a593Smuzhiyun #define SLIM_MAX_CLK_GEAR		10
76*4882a593Smuzhiyun #define SLIM_MIN_CLK_GEAR		1
77*4882a593Smuzhiyun #define SLIM_SLOT_LEN_BITS		4
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* Indicate that the frequency of the flow and the bus frequency are locked */
80*4882a593Smuzhiyun #define SLIM_CHANNEL_CONTENT_FL		BIT(7)
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /* Standard values per SLIMbus spec needed by controllers and devices */
83*4882a593Smuzhiyun #define SLIM_CL_PER_SUPERFRAME		6144
84*4882a593Smuzhiyun #define SLIM_SLOTS_PER_SUPERFRAME	(SLIM_CL_PER_SUPERFRAME >> 2)
85*4882a593Smuzhiyun #define SLIM_SL_PER_SUPERFRAME		(SLIM_CL_PER_SUPERFRAME >> 2)
86*4882a593Smuzhiyun /* Manager's logical address is set to 0xFF per spec */
87*4882a593Smuzhiyun #define SLIM_LA_MANAGER 0xFF
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define SLIM_MAX_TIDS			256
90*4882a593Smuzhiyun /**
91*4882a593Smuzhiyun  * struct slim_framer - Represents SLIMbus framer.
92*4882a593Smuzhiyun  * Every controller may have multiple framers. There is 1 active framer device
93*4882a593Smuzhiyun  * responsible for clocking the bus.
94*4882a593Smuzhiyun  * Manager is responsible for framer hand-over.
95*4882a593Smuzhiyun  * @dev: Driver model representation of the device.
96*4882a593Smuzhiyun  * @e_addr: Enumeration address of the framer.
97*4882a593Smuzhiyun  * @rootfreq: Root Frequency at which the framer can run. This is maximum
98*4882a593Smuzhiyun  *	frequency ('clock gear 10') at which the bus can operate.
99*4882a593Smuzhiyun  * @superfreq: Superframes per root frequency. Every frame is 6144 bits.
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun struct slim_framer {
102*4882a593Smuzhiyun 	struct device		dev;
103*4882a593Smuzhiyun 	struct slim_eaddr	e_addr;
104*4882a593Smuzhiyun 	int			rootfreq;
105*4882a593Smuzhiyun 	int			superfreq;
106*4882a593Smuzhiyun };
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun #define to_slim_framer(d) container_of(d, struct slim_framer, dev)
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun /**
111*4882a593Smuzhiyun  * struct slim_msg_txn - Message to be sent by the controller.
112*4882a593Smuzhiyun  *			This structure has packet header,
113*4882a593Smuzhiyun  *			payload and buffer to be filled (if any)
114*4882a593Smuzhiyun  * @rl: Header field. remaining length.
115*4882a593Smuzhiyun  * @mt: Header field. Message type.
116*4882a593Smuzhiyun  * @mc: Header field. LSB is message code for type mt.
117*4882a593Smuzhiyun  * @dt: Header field. Destination type.
118*4882a593Smuzhiyun  * @ec: Element code. Used for elemental access APIs.
119*4882a593Smuzhiyun  * @tid: Transaction ID. Used for messages expecting response.
120*4882a593Smuzhiyun  *	(relevant for message-codes involving read operation)
121*4882a593Smuzhiyun  * @la: Logical address of the device this message is going to.
122*4882a593Smuzhiyun  *	(Not used when destination type is broadcast.)
123*4882a593Smuzhiyun  * @msg: Elemental access message to be read/written
124*4882a593Smuzhiyun  * @comp: completion if read/write is synchronous, used internally
125*4882a593Smuzhiyun  *	for tid based transactions.
126*4882a593Smuzhiyun  */
127*4882a593Smuzhiyun struct slim_msg_txn {
128*4882a593Smuzhiyun 	u8			rl;
129*4882a593Smuzhiyun 	u8			mt;
130*4882a593Smuzhiyun 	u8			mc;
131*4882a593Smuzhiyun 	u8			dt;
132*4882a593Smuzhiyun 	u16			ec;
133*4882a593Smuzhiyun 	u8			tid;
134*4882a593Smuzhiyun 	u8			la;
135*4882a593Smuzhiyun 	struct slim_val_inf	*msg;
136*4882a593Smuzhiyun 	struct	completion	*comp;
137*4882a593Smuzhiyun };
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /* Frequently used message transaction structures */
140*4882a593Smuzhiyun #define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) \
141*4882a593Smuzhiyun 	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_LOGICALADDR, 0,\
142*4882a593Smuzhiyun 					0, la, msg, }
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun #define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) \
145*4882a593Smuzhiyun 	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_BROADCAST, 0,\
146*4882a593Smuzhiyun 					0, la, msg, }
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun #define DEFINE_SLIM_EDEST_TXN(name, mc, rl, la, msg) \
149*4882a593Smuzhiyun 	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_ENUMADDR, 0,\
150*4882a593Smuzhiyun 					0, la, msg, }
151*4882a593Smuzhiyun /**
152*4882a593Smuzhiyun  * enum slim_clk_state: SLIMbus controller's clock state used internally for
153*4882a593Smuzhiyun  *	maintaining current clock state.
154*4882a593Smuzhiyun  * @SLIM_CLK_ACTIVE: SLIMbus clock is active
155*4882a593Smuzhiyun  * @SLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the
156*4882a593Smuzhiyun  *	bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the
157*4882a593Smuzhiyun  *	transition fails, state changes back to SLIM_CLK_ACTIVE
158*4882a593Smuzhiyun  * @SLIM_CLK_PAUSED: SLIMbus controller clock has paused.
159*4882a593Smuzhiyun  */
160*4882a593Smuzhiyun enum slim_clk_state {
161*4882a593Smuzhiyun 	SLIM_CLK_ACTIVE,
162*4882a593Smuzhiyun 	SLIM_CLK_ENTERING_PAUSE,
163*4882a593Smuzhiyun 	SLIM_CLK_PAUSED,
164*4882a593Smuzhiyun };
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun /**
167*4882a593Smuzhiyun  * struct slim_sched: Framework uses this structure internally for scheduling.
168*4882a593Smuzhiyun  * @clk_state: Controller's clock state from enum slim_clk_state
169*4882a593Smuzhiyun  * @pause_comp: Signals completion of clock pause sequence. This is useful when
170*4882a593Smuzhiyun  *	client tries to call SLIMbus transaction when controller is entering
171*4882a593Smuzhiyun  *	clock pause.
172*4882a593Smuzhiyun  * @m_reconf: This mutex is held until current reconfiguration (data channel
173*4882a593Smuzhiyun  *	scheduling, message bandwidth reservation) is done. Message APIs can
174*4882a593Smuzhiyun  *	use the bus concurrently when this mutex is held since elemental access
175*4882a593Smuzhiyun  *	messages can be sent on the bus when reconfiguration is in progress.
176*4882a593Smuzhiyun  */
177*4882a593Smuzhiyun struct slim_sched {
178*4882a593Smuzhiyun 	enum slim_clk_state	clk_state;
179*4882a593Smuzhiyun 	struct completion	pause_comp;
180*4882a593Smuzhiyun 	struct mutex		m_reconf;
181*4882a593Smuzhiyun };
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /**
184*4882a593Smuzhiyun  * enum slim_port_direction: SLIMbus port direction
185*4882a593Smuzhiyun  *
186*4882a593Smuzhiyun  * @SLIM_PORT_SINK: SLIMbus port is a sink
187*4882a593Smuzhiyun  * @SLIM_PORT_SOURCE: SLIMbus port is a source
188*4882a593Smuzhiyun  */
189*4882a593Smuzhiyun enum slim_port_direction {
190*4882a593Smuzhiyun 	SLIM_PORT_SINK = 0,
191*4882a593Smuzhiyun 	SLIM_PORT_SOURCE,
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun /**
194*4882a593Smuzhiyun  * enum slim_port_state: SLIMbus Port/Endpoint state machine
195*4882a593Smuzhiyun  *	according to SLIMbus Spec 2.0
196*4882a593Smuzhiyun  * @SLIM_PORT_DISCONNECTED: SLIMbus port is disconnected
197*4882a593Smuzhiyun  *	entered from Unconfigure/configured state after
198*4882a593Smuzhiyun  *	DISCONNECT_PORT or REMOVE_CHANNEL core command
199*4882a593Smuzhiyun  * @SLIM_PORT_UNCONFIGURED: SLIMbus port is in unconfigured state.
200*4882a593Smuzhiyun  *	entered from disconnect state after CONNECT_SOURCE/SINK core command
201*4882a593Smuzhiyun  * @SLIM_PORT_CONFIGURED: SLIMbus port is in configured state.
202*4882a593Smuzhiyun  *	entered from unconfigured state after DEFINE_CHANNEL, DEFINE_CONTENT
203*4882a593Smuzhiyun  *	and ACTIVATE_CHANNEL core commands. Ready for data transmission.
204*4882a593Smuzhiyun  */
205*4882a593Smuzhiyun enum slim_port_state {
206*4882a593Smuzhiyun 	SLIM_PORT_DISCONNECTED = 0,
207*4882a593Smuzhiyun 	SLIM_PORT_UNCONFIGURED,
208*4882a593Smuzhiyun 	SLIM_PORT_CONFIGURED,
209*4882a593Smuzhiyun };
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun /**
212*4882a593Smuzhiyun  * enum slim_channel_state: SLIMbus channel state machine used by core.
213*4882a593Smuzhiyun  * @SLIM_CH_STATE_DISCONNECTED: SLIMbus channel is disconnected
214*4882a593Smuzhiyun  * @SLIM_CH_STATE_ALLOCATED: SLIMbus channel is allocated
215*4882a593Smuzhiyun  * @SLIM_CH_STATE_ASSOCIATED: SLIMbus channel is associated with port
216*4882a593Smuzhiyun  * @SLIM_CH_STATE_DEFINED: SLIMbus channel parameters are defined
217*4882a593Smuzhiyun  * @SLIM_CH_STATE_CONTENT_DEFINED: SLIMbus channel content is defined
218*4882a593Smuzhiyun  * @SLIM_CH_STATE_ACTIVE: SLIMbus channel is active and ready for data
219*4882a593Smuzhiyun  * @SLIM_CH_STATE_REMOVED: SLIMbus channel is inactive and removed
220*4882a593Smuzhiyun  */
221*4882a593Smuzhiyun enum slim_channel_state {
222*4882a593Smuzhiyun 	SLIM_CH_STATE_DISCONNECTED = 0,
223*4882a593Smuzhiyun 	SLIM_CH_STATE_ALLOCATED,
224*4882a593Smuzhiyun 	SLIM_CH_STATE_ASSOCIATED,
225*4882a593Smuzhiyun 	SLIM_CH_STATE_DEFINED,
226*4882a593Smuzhiyun 	SLIM_CH_STATE_CONTENT_DEFINED,
227*4882a593Smuzhiyun 	SLIM_CH_STATE_ACTIVE,
228*4882a593Smuzhiyun 	SLIM_CH_STATE_REMOVED,
229*4882a593Smuzhiyun };
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun /**
232*4882a593Smuzhiyun  * enum slim_ch_data_fmt: SLIMbus channel data Type identifiers according to
233*4882a593Smuzhiyun  *	Table 60 of SLIMbus Spec 1.01.01
234*4882a593Smuzhiyun  * @SLIM_CH_DATA_FMT_NOT_DEFINED: Undefined
235*4882a593Smuzhiyun  * @SLIM_CH_DATA_FMT_LPCM_AUDIO: LPCM audio
236*4882a593Smuzhiyun  * @SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO: IEC61937 Compressed audio
237*4882a593Smuzhiyun  * @SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO: Packed PDM audio
238*4882a593Smuzhiyun  */
239*4882a593Smuzhiyun enum slim_ch_data_fmt {
240*4882a593Smuzhiyun 	SLIM_CH_DATA_FMT_NOT_DEFINED = 0,
241*4882a593Smuzhiyun 	SLIM_CH_DATA_FMT_LPCM_AUDIO = 1,
242*4882a593Smuzhiyun 	SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO = 2,
243*4882a593Smuzhiyun 	SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO = 3,
244*4882a593Smuzhiyun };
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun /**
247*4882a593Smuzhiyun  * enum slim_ch_aux_fmt: SLIMbus channel Aux Field format IDs according to
248*4882a593Smuzhiyun  *	Table 63 of SLIMbus Spec 2.0
249*4882a593Smuzhiyun  * @SLIM_CH_AUX_FMT_NOT_APPLICABLE: Undefined
250*4882a593Smuzhiyun  * @SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958: ZCUV for tunneling IEC60958
251*4882a593Smuzhiyun  * @SLIM_CH_AUX_FMT_USER_DEFINED: User defined
252*4882a593Smuzhiyun  */
253*4882a593Smuzhiyun enum slim_ch_aux_bit_fmt {
254*4882a593Smuzhiyun 	SLIM_CH_AUX_FMT_NOT_APPLICABLE = 0,
255*4882a593Smuzhiyun 	SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958 = 1,
256*4882a593Smuzhiyun 	SLIM_CH_AUX_FMT_USER_DEFINED = 0xF,
257*4882a593Smuzhiyun };
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun /**
260*4882a593Smuzhiyun  * struct slim_channel  - SLIMbus channel, used for state machine
261*4882a593Smuzhiyun  *
262*4882a593Smuzhiyun  * @id: ID of channel
263*4882a593Smuzhiyun  * @prrate: Presense rate of channel from Table 66 of SLIMbus 2.0 Specs
264*4882a593Smuzhiyun  * @seg_dist: segment distribution code from Table 20 of SLIMbus 2.0 Specs
265*4882a593Smuzhiyun  * @data_fmt: Data format of channel.
266*4882a593Smuzhiyun  * @aux_fmt: Aux format for this channel.
267*4882a593Smuzhiyun  * @state: channel state machine
268*4882a593Smuzhiyun  */
269*4882a593Smuzhiyun struct slim_channel {
270*4882a593Smuzhiyun 	int id;
271*4882a593Smuzhiyun 	int prrate;
272*4882a593Smuzhiyun 	int seg_dist;
273*4882a593Smuzhiyun 	enum slim_ch_data_fmt data_fmt;
274*4882a593Smuzhiyun 	enum slim_ch_aux_bit_fmt aux_fmt;
275*4882a593Smuzhiyun 	enum slim_channel_state state;
276*4882a593Smuzhiyun };
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun /**
279*4882a593Smuzhiyun  * struct slim_port  - SLIMbus port
280*4882a593Smuzhiyun  *
281*4882a593Smuzhiyun  * @id: Port id
282*4882a593Smuzhiyun  * @direction: Port direction, Source or Sink.
283*4882a593Smuzhiyun  * @state: state machine of port.
284*4882a593Smuzhiyun  * @ch: channel associated with this port.
285*4882a593Smuzhiyun  */
286*4882a593Smuzhiyun struct slim_port {
287*4882a593Smuzhiyun 	int id;
288*4882a593Smuzhiyun 	enum slim_port_direction direction;
289*4882a593Smuzhiyun 	enum slim_port_state state;
290*4882a593Smuzhiyun 	struct slim_channel ch;
291*4882a593Smuzhiyun };
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun /**
294*4882a593Smuzhiyun  * enum slim_transport_protocol: SLIMbus Transport protocol list from
295*4882a593Smuzhiyun  *	Table 47 of SLIMbus 2.0 specs.
296*4882a593Smuzhiyun  * @SLIM_PROTO_ISO: Isochronous Protocol, no flow control as data rate match
297*4882a593Smuzhiyun  *		channel rate flow control embedded in the data.
298*4882a593Smuzhiyun  * @SLIM_PROTO_PUSH: Pushed Protocol, includes flow control, Used to carry
299*4882a593Smuzhiyun  *		data whose rate	is equal to, or lower than the channel rate.
300*4882a593Smuzhiyun  * @SLIM_PROTO_PULL: Pulled Protocol, similar usage as pushed protocol
301*4882a593Smuzhiyun  *		but pull is a unicast.
302*4882a593Smuzhiyun  * @SLIM_PROTO_LOCKED: Locked Protocol
303*4882a593Smuzhiyun  * @SLIM_PROTO_ASYNC_SMPLX: Asynchronous Protocol-Simplex
304*4882a593Smuzhiyun  * @SLIM_PROTO_ASYNC_HALF_DUP: Asynchronous Protocol-Half-duplex
305*4882a593Smuzhiyun  * @SLIM_PROTO_EXT_SMPLX: Extended Asynchronous Protocol-Simplex
306*4882a593Smuzhiyun  * @SLIM_PROTO_EXT_HALF_DUP: Extended Asynchronous Protocol-Half-duplex
307*4882a593Smuzhiyun  */
308*4882a593Smuzhiyun enum slim_transport_protocol {
309*4882a593Smuzhiyun 	SLIM_PROTO_ISO = 0,
310*4882a593Smuzhiyun 	SLIM_PROTO_PUSH,
311*4882a593Smuzhiyun 	SLIM_PROTO_PULL,
312*4882a593Smuzhiyun 	SLIM_PROTO_LOCKED,
313*4882a593Smuzhiyun 	SLIM_PROTO_ASYNC_SMPLX,
314*4882a593Smuzhiyun 	SLIM_PROTO_ASYNC_HALF_DUP,
315*4882a593Smuzhiyun 	SLIM_PROTO_EXT_SMPLX,
316*4882a593Smuzhiyun 	SLIM_PROTO_EXT_HALF_DUP,
317*4882a593Smuzhiyun };
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun /**
320*4882a593Smuzhiyun  * struct slim_stream_runtime  - SLIMbus stream runtime instance
321*4882a593Smuzhiyun  *
322*4882a593Smuzhiyun  * @name: Name of the stream
323*4882a593Smuzhiyun  * @dev: SLIM Device instance associated with this stream
324*4882a593Smuzhiyun  * @direction: direction of stream
325*4882a593Smuzhiyun  * @prot: Transport protocol used in this stream
326*4882a593Smuzhiyun  * @rate: Data rate of samples *
327*4882a593Smuzhiyun  * @bps: bits per sample
328*4882a593Smuzhiyun  * @ratem: rate multipler which is super frame rate/data rate
329*4882a593Smuzhiyun  * @num_ports: number of ports
330*4882a593Smuzhiyun  * @ports: pointer to instance of ports
331*4882a593Smuzhiyun  * @node: list head for stream associated with slim device.
332*4882a593Smuzhiyun  */
333*4882a593Smuzhiyun struct slim_stream_runtime {
334*4882a593Smuzhiyun 	const char *name;
335*4882a593Smuzhiyun 	struct slim_device *dev;
336*4882a593Smuzhiyun 	int direction;
337*4882a593Smuzhiyun 	enum slim_transport_protocol prot;
338*4882a593Smuzhiyun 	unsigned int rate;
339*4882a593Smuzhiyun 	unsigned int bps;
340*4882a593Smuzhiyun 	unsigned int ratem;
341*4882a593Smuzhiyun 	int num_ports;
342*4882a593Smuzhiyun 	struct slim_port *ports;
343*4882a593Smuzhiyun 	struct list_head node;
344*4882a593Smuzhiyun };
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /**
347*4882a593Smuzhiyun  * struct slim_controller  - Controls every instance of SLIMbus
348*4882a593Smuzhiyun  *				(similar to 'master' on SPI)
349*4882a593Smuzhiyun  * @dev: Device interface to this driver
350*4882a593Smuzhiyun  * @id: Board-specific number identifier for this controller/bus
351*4882a593Smuzhiyun  * @name: Name for this controller
352*4882a593Smuzhiyun  * @min_cg: Minimum clock gear supported by this controller (default value: 1)
353*4882a593Smuzhiyun  * @max_cg: Maximum clock gear supported by this controller (default value: 10)
354*4882a593Smuzhiyun  * @clkgear: Current clock gear in which this bus is running
355*4882a593Smuzhiyun  * @laddr_ida: logical address id allocator
356*4882a593Smuzhiyun  * @a_framer: Active framer which is clocking the bus managed by this controller
357*4882a593Smuzhiyun  * @lock: Mutex protecting controller data structures
358*4882a593Smuzhiyun  * @devices: Slim device list
359*4882a593Smuzhiyun  * @tid_idr: tid id allocator
360*4882a593Smuzhiyun  * @txn_lock: Lock to protect table of transactions
361*4882a593Smuzhiyun  * @sched: scheduler structure used by the controller
362*4882a593Smuzhiyun  * @xfer_msg: Transfer a message on this controller (this can be a broadcast
363*4882a593Smuzhiyun  *	control/status message like data channel setup, or a unicast message
364*4882a593Smuzhiyun  *	like value element read/write.
365*4882a593Smuzhiyun  * @set_laddr: Setup logical address at laddr for the slave with elemental
366*4882a593Smuzhiyun  *	address e_addr. Drivers implementing controller will be expected to
367*4882a593Smuzhiyun  *	send unicast message to this device with its logical address.
368*4882a593Smuzhiyun  * @get_laddr: It is possible that controller needs to set fixed logical
369*4882a593Smuzhiyun  *	address table and get_laddr can be used in that case so that controller
370*4882a593Smuzhiyun  *	can do this assignment. Use case is when the master is on the remote
371*4882a593Smuzhiyun  *	processor side, who is resposible for allocating laddr.
372*4882a593Smuzhiyun  * @wakeup: This function pointer implements controller-specific procedure
373*4882a593Smuzhiyun  *	to wake it up from clock-pause. Framework will call this to bring
374*4882a593Smuzhiyun  *	the controller out of clock pause.
375*4882a593Smuzhiyun  * @enable_stream: This function pointer implements controller-specific procedure
376*4882a593Smuzhiyun  *	to enable a stream.
377*4882a593Smuzhiyun  * @disable_stream: This function pointer implements controller-specific procedure
378*4882a593Smuzhiyun  *	to disable stream.
379*4882a593Smuzhiyun  *
380*4882a593Smuzhiyun  *	'Manager device' is responsible for  device management, bandwidth
381*4882a593Smuzhiyun  *	allocation, channel setup, and port associations per channel.
382*4882a593Smuzhiyun  *	Device management means Logical address assignment/removal based on
383*4882a593Smuzhiyun  *	enumeration (report-present, report-absent) of a device.
384*4882a593Smuzhiyun  *	Bandwidth allocation is done dynamically by the manager based on active
385*4882a593Smuzhiyun  *	channels on the bus, message-bandwidth requests made by SLIMbus devices.
386*4882a593Smuzhiyun  *	Based on current bandwidth usage, manager chooses a frequency to run
387*4882a593Smuzhiyun  *	the bus at (in steps of 'clock-gear', 1 through 10, each clock gear
388*4882a593Smuzhiyun  *	representing twice the frequency than the previous gear).
389*4882a593Smuzhiyun  *	Manager is also responsible for entering (and exiting) low-power-mode
390*4882a593Smuzhiyun  *	(known as 'clock pause').
391*4882a593Smuzhiyun  *	Manager can do handover of framer if there are multiple framers on the
392*4882a593Smuzhiyun  *	bus and a certain usecase warrants using certain framer to avoid keeping
393*4882a593Smuzhiyun  *	previous framer being powered-on.
394*4882a593Smuzhiyun  *
395*4882a593Smuzhiyun  *	Controller here performs duties of the manager device, and 'interface
396*4882a593Smuzhiyun  *	device'. Interface device is responsible for monitoring the bus and
397*4882a593Smuzhiyun  *	reporting information such as loss-of-synchronization, data
398*4882a593Smuzhiyun  *	slot-collision.
399*4882a593Smuzhiyun  */
400*4882a593Smuzhiyun struct slim_controller {
401*4882a593Smuzhiyun 	struct device		*dev;
402*4882a593Smuzhiyun 	unsigned int		id;
403*4882a593Smuzhiyun 	char			name[SLIMBUS_NAME_SIZE];
404*4882a593Smuzhiyun 	int			min_cg;
405*4882a593Smuzhiyun 	int			max_cg;
406*4882a593Smuzhiyun 	int			clkgear;
407*4882a593Smuzhiyun 	struct ida		laddr_ida;
408*4882a593Smuzhiyun 	struct slim_framer	*a_framer;
409*4882a593Smuzhiyun 	struct mutex		lock;
410*4882a593Smuzhiyun 	struct list_head	devices;
411*4882a593Smuzhiyun 	struct idr		tid_idr;
412*4882a593Smuzhiyun 	spinlock_t		txn_lock;
413*4882a593Smuzhiyun 	struct slim_sched	sched;
414*4882a593Smuzhiyun 	int			(*xfer_msg)(struct slim_controller *ctrl,
415*4882a593Smuzhiyun 					    struct slim_msg_txn *tx);
416*4882a593Smuzhiyun 	int			(*set_laddr)(struct slim_controller *ctrl,
417*4882a593Smuzhiyun 					     struct slim_eaddr *ea, u8 laddr);
418*4882a593Smuzhiyun 	int			(*get_laddr)(struct slim_controller *ctrl,
419*4882a593Smuzhiyun 					     struct slim_eaddr *ea, u8 *laddr);
420*4882a593Smuzhiyun 	int		(*enable_stream)(struct slim_stream_runtime *rt);
421*4882a593Smuzhiyun 	int		(*disable_stream)(struct slim_stream_runtime *rt);
422*4882a593Smuzhiyun 	int			(*wakeup)(struct slim_controller *ctrl);
423*4882a593Smuzhiyun };
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun int slim_device_report_present(struct slim_controller *ctrl,
426*4882a593Smuzhiyun 			       struct slim_eaddr *e_addr, u8 *laddr);
427*4882a593Smuzhiyun void slim_report_absent(struct slim_device *sbdev);
428*4882a593Smuzhiyun int slim_register_controller(struct slim_controller *ctrl);
429*4882a593Smuzhiyun int slim_unregister_controller(struct slim_controller *ctrl);
430*4882a593Smuzhiyun void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l);
431*4882a593Smuzhiyun int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn);
432*4882a593Smuzhiyun int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart);
433*4882a593Smuzhiyun int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);
434*4882a593Smuzhiyun void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);
435*4882a593Smuzhiyun 
slim_tid_txn(u8 mt,u8 mc)436*4882a593Smuzhiyun static inline bool slim_tid_txn(u8 mt, u8 mc)
437*4882a593Smuzhiyun {
438*4882a593Smuzhiyun 	return (mt == SLIM_MSG_MT_CORE &&
439*4882a593Smuzhiyun 		(mc == SLIM_MSG_MC_REQUEST_INFORMATION ||
440*4882a593Smuzhiyun 		 mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION ||
441*4882a593Smuzhiyun 		 mc == SLIM_MSG_MC_REQUEST_VALUE ||
442*4882a593Smuzhiyun 		 mc == SLIM_MSG_MC_REQUEST_CHANGE_VALUE));
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun 
slim_ec_txn(u8 mt,u8 mc)445*4882a593Smuzhiyun static inline bool slim_ec_txn(u8 mt, u8 mc)
446*4882a593Smuzhiyun {
447*4882a593Smuzhiyun 	return (mt == SLIM_MSG_MT_CORE &&
448*4882a593Smuzhiyun 		((mc >= SLIM_MSG_MC_REQUEST_INFORMATION &&
449*4882a593Smuzhiyun 		  mc <= SLIM_MSG_MC_REPORT_INFORMATION) ||
450*4882a593Smuzhiyun 		 (mc >= SLIM_MSG_MC_REQUEST_VALUE &&
451*4882a593Smuzhiyun 		  mc <= SLIM_MSG_MC_CHANGE_VALUE)));
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun #endif /* _LINUX_SLIMBUS_H */
454