brintos

brintos / linux-shallow public Read only

0
0
Text · 16.3 KiB · 00a7f11 Raw
454 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Copyright (c) 2011-2017, The Linux Foundation4 */5 6#ifndef _DRIVERS_SLIMBUS_H7#define _DRIVERS_SLIMBUS_H8#include <linux/module.h>9#include <linux/device.h>10#include <linux/mutex.h>11#include <linux/completion.h>12#include <linux/slimbus.h>13 14/* Standard values per SLIMbus spec needed by controllers and devices */15#define SLIM_CL_PER_SUPERFRAME		614416#define SLIM_CL_PER_SUPERFRAME_DIV8	(SLIM_CL_PER_SUPERFRAME >> 3)17 18/* SLIMbus message types. Related to interpretation of message code. */19#define SLIM_MSG_MT_CORE			0x020#define SLIM_MSG_MT_DEST_REFERRED_USER		0x221#define SLIM_MSG_MT_SRC_REFERRED_USER		0x622 23/*24 * SLIM Broadcast header format25 * BYTE 0: MT[7:5] RL[4:0]26 * BYTE 1: RSVD[7] MC[6:0]27 * BYTE 2: RSVD[7:6] DT[5:4] PI[3:0]28 */29#define SLIM_MSG_MT_MASK	GENMASK(2, 0)30#define SLIM_MSG_MT_SHIFT	531#define SLIM_MSG_RL_MASK	GENMASK(4, 0)32#define SLIM_MSG_RL_SHIFT	033#define SLIM_MSG_MC_MASK	GENMASK(6, 0)34#define SLIM_MSG_MC_SHIFT	035#define SLIM_MSG_DT_MASK	GENMASK(1, 0)36#define SLIM_MSG_DT_SHIFT	437 38#define SLIM_HEADER_GET_MT(b)	((b >> SLIM_MSG_MT_SHIFT) & SLIM_MSG_MT_MASK)39#define SLIM_HEADER_GET_RL(b)	((b >> SLIM_MSG_RL_SHIFT) & SLIM_MSG_RL_MASK)40#define SLIM_HEADER_GET_MC(b)	((b >> SLIM_MSG_MC_SHIFT) & SLIM_MSG_MC_MASK)41#define SLIM_HEADER_GET_DT(b)	((b >> SLIM_MSG_DT_SHIFT) & SLIM_MSG_DT_MASK)42 43/* Device management messages used by this framework */44#define SLIM_MSG_MC_REPORT_PRESENT               0x145#define SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS       0x246#define SLIM_MSG_MC_REPORT_ABSENT                0xF47 48/* Data channel management messages */49#define SLIM_MSG_MC_CONNECT_SOURCE		0x1050#define SLIM_MSG_MC_CONNECT_SINK		0x1151#define SLIM_MSG_MC_DISCONNECT_PORT		0x1452#define SLIM_MSG_MC_CHANGE_CONTENT		0x1853 54/* Clock pause Reconfiguration messages */55#define SLIM_MSG_MC_BEGIN_RECONFIGURATION        0x4056#define SLIM_MSG_MC_NEXT_PAUSE_CLOCK             0x4A57#define SLIM_MSG_MC_NEXT_DEFINE_CHANNEL          0x5058#define SLIM_MSG_MC_NEXT_DEFINE_CONTENT          0x5159#define SLIM_MSG_MC_NEXT_ACTIVATE_CHANNEL        0x5460#define SLIM_MSG_MC_NEXT_DEACTIVATE_CHANNEL      0x5561#define SLIM_MSG_MC_NEXT_REMOVE_CHANNEL          0x5862#define SLIM_MSG_MC_RECONFIGURE_NOW              0x5F63 64/* Clock pause values per SLIMbus spec */65#define SLIM_CLK_FAST				066#define SLIM_CLK_CONST_PHASE			167#define SLIM_CLK_UNSPECIFIED			268 69/* Destination type Values */70#define SLIM_MSG_DEST_LOGICALADDR	071#define SLIM_MSG_DEST_ENUMADDR		172#define	SLIM_MSG_DEST_BROADCAST		373 74/* Standard values per SLIMbus spec needed by controllers and devices */75#define SLIM_MAX_CLK_GEAR		1076#define SLIM_MIN_CLK_GEAR		177#define SLIM_SLOT_LEN_BITS		478 79/* Indicate that the frequency of the flow and the bus frequency are locked */80#define SLIM_CHANNEL_CONTENT_FL		BIT(7)81 82/* Standard values per SLIMbus spec needed by controllers and devices */83#define SLIM_CL_PER_SUPERFRAME		614484#define SLIM_SLOTS_PER_SUPERFRAME	(SLIM_CL_PER_SUPERFRAME >> 2)85#define SLIM_SL_PER_SUPERFRAME		(SLIM_CL_PER_SUPERFRAME >> 2)86/* Manager's logical address is set to 0xFF per spec */87#define SLIM_LA_MANAGER 0xFF88 89#define SLIM_MAX_TIDS			25690/**91 * struct slim_framer - Represents SLIMbus framer.92 * Every controller may have multiple framers. There is 1 active framer device93 * responsible for clocking the bus.94 * Manager is responsible for framer hand-over.95 * @dev: Driver model representation of the device.96 * @e_addr: Enumeration address of the framer.97 * @rootfreq: Root Frequency at which the framer can run. This is maximum98 *	frequency ('clock gear 10') at which the bus can operate.99 * @superfreq: Superframes per root frequency. Every frame is 6144 bits.100 */101struct slim_framer {102	struct device		dev;103	struct slim_eaddr	e_addr;104	int			rootfreq;105	int			superfreq;106};107 108#define to_slim_framer(d) container_of(d, struct slim_framer, dev)109 110/**111 * struct slim_msg_txn - Message to be sent by the controller.112 *			This structure has packet header,113 *			payload and buffer to be filled (if any)114 * @rl: Header field. remaining length.115 * @mt: Header field. Message type.116 * @mc: Header field. LSB is message code for type mt.117 * @dt: Header field. Destination type.118 * @ec: Element code. Used for elemental access APIs.119 * @tid: Transaction ID. Used for messages expecting response.120 *	(relevant for message-codes involving read operation)121 * @la: Logical address of the device this message is going to.122 *	(Not used when destination type is broadcast.)123 * @msg: Elemental access message to be read/written124 * @comp: completion if read/write is synchronous, used internally125 *	for tid based transactions.126 */127struct slim_msg_txn {128	u8			rl;129	u8			mt;130	u8			mc;131	u8			dt;132	u16			ec;133	u8			tid;134	u8			la;135	struct slim_val_inf	*msg;136	struct	completion	*comp;137};138 139/* Frequently used message transaction structures */140#define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) \141	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_LOGICALADDR, 0,\142					0, la, msg, }143 144#define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) \145	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_BROADCAST, 0,\146					0, la, msg, }147 148#define DEFINE_SLIM_EDEST_TXN(name, mc, rl, la, msg) \149	struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_ENUMADDR, 0,\150					0, la, msg, }151/**152 * enum slim_clk_state: SLIMbus controller's clock state used internally for153 *	maintaining current clock state.154 * @SLIM_CLK_ACTIVE: SLIMbus clock is active155 * @SLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the156 *	bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the157 *	transition fails, state changes back to SLIM_CLK_ACTIVE158 * @SLIM_CLK_PAUSED: SLIMbus controller clock has paused.159 */160enum slim_clk_state {161	SLIM_CLK_ACTIVE,162	SLIM_CLK_ENTERING_PAUSE,163	SLIM_CLK_PAUSED,164};165 166/**167 * struct slim_sched: Framework uses this structure internally for scheduling.168 * @clk_state: Controller's clock state from enum slim_clk_state169 * @pause_comp: Signals completion of clock pause sequence. This is useful when170 *	client tries to call SLIMbus transaction when controller is entering171 *	clock pause.172 * @m_reconf: This mutex is held until current reconfiguration (data channel173 *	scheduling, message bandwidth reservation) is done. Message APIs can174 *	use the bus concurrently when this mutex is held since elemental access175 *	messages can be sent on the bus when reconfiguration is in progress.176 */177struct slim_sched {178	enum slim_clk_state	clk_state;179	struct completion	pause_comp;180	struct mutex		m_reconf;181};182 183/**184 * enum slim_port_direction: SLIMbus port direction185 *186 * @SLIM_PORT_SINK: SLIMbus port is a sink187 * @SLIM_PORT_SOURCE: SLIMbus port is a source188 */189enum slim_port_direction {190	SLIM_PORT_SINK = 0,191	SLIM_PORT_SOURCE,192};193/**194 * enum slim_port_state: SLIMbus Port/Endpoint state machine195 *	according to SLIMbus Spec 2.0196 * @SLIM_PORT_DISCONNECTED: SLIMbus port is disconnected197 *	entered from Unconfigure/configured state after198 *	DISCONNECT_PORT or REMOVE_CHANNEL core command199 * @SLIM_PORT_UNCONFIGURED: SLIMbus port is in unconfigured state.200 *	entered from disconnect state after CONNECT_SOURCE/SINK core command201 * @SLIM_PORT_CONFIGURED: SLIMbus port is in configured state.202 *	entered from unconfigured state after DEFINE_CHANNEL, DEFINE_CONTENT203 *	and ACTIVATE_CHANNEL core commands. Ready for data transmission.204 */205enum slim_port_state {206	SLIM_PORT_DISCONNECTED = 0,207	SLIM_PORT_UNCONFIGURED,208	SLIM_PORT_CONFIGURED,209};210 211/**212 * enum slim_channel_state: SLIMbus channel state machine used by core.213 * @SLIM_CH_STATE_DISCONNECTED: SLIMbus channel is disconnected214 * @SLIM_CH_STATE_ALLOCATED: SLIMbus channel is allocated215 * @SLIM_CH_STATE_ASSOCIATED: SLIMbus channel is associated with port216 * @SLIM_CH_STATE_DEFINED: SLIMbus channel parameters are defined217 * @SLIM_CH_STATE_CONTENT_DEFINED: SLIMbus channel content is defined218 * @SLIM_CH_STATE_ACTIVE: SLIMbus channel is active and ready for data219 * @SLIM_CH_STATE_REMOVED: SLIMbus channel is inactive and removed220 */221enum slim_channel_state {222	SLIM_CH_STATE_DISCONNECTED = 0,223	SLIM_CH_STATE_ALLOCATED,224	SLIM_CH_STATE_ASSOCIATED,225	SLIM_CH_STATE_DEFINED,226	SLIM_CH_STATE_CONTENT_DEFINED,227	SLIM_CH_STATE_ACTIVE,228	SLIM_CH_STATE_REMOVED,229};230 231/**232 * enum slim_ch_data_fmt: SLIMbus channel data Type identifiers according to233 *	Table 60 of SLIMbus Spec 1.01.01234 * @SLIM_CH_DATA_FMT_NOT_DEFINED: Undefined235 * @SLIM_CH_DATA_FMT_LPCM_AUDIO: LPCM audio236 * @SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO: IEC61937 Compressed audio237 * @SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO: Packed PDM audio238 */239enum slim_ch_data_fmt {240	SLIM_CH_DATA_FMT_NOT_DEFINED = 0,241	SLIM_CH_DATA_FMT_LPCM_AUDIO = 1,242	SLIM_CH_DATA_FMT_IEC61937_COMP_AUDIO = 2,243	SLIM_CH_DATA_FMT_PACKED_PDM_AUDIO = 3,244};245 246/**247 * enum slim_ch_aux_bit_fmt: SLIMbus channel Aux Field format IDs according to248 *	Table 63 of SLIMbus Spec 2.0249 * @SLIM_CH_AUX_FMT_NOT_APPLICABLE: Undefined250 * @SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958: ZCUV for tunneling IEC60958251 * @SLIM_CH_AUX_FMT_USER_DEFINED: User defined252 */253enum slim_ch_aux_bit_fmt {254	SLIM_CH_AUX_FMT_NOT_APPLICABLE = 0,255	SLIM_CH_AUX_FMT_ZCUV_TUNNEL_IEC60958 = 1,256	SLIM_CH_AUX_FMT_USER_DEFINED = 0xF,257};258 259/**260 * struct slim_channel  - SLIMbus channel, used for state machine261 *262 * @id: ID of channel263 * @prrate: Presense rate of channel from Table 66 of SLIMbus 2.0 Specs264 * @seg_dist: segment distribution code from Table 20 of SLIMbus 2.0 Specs265 * @data_fmt: Data format of channel.266 * @aux_fmt: Aux format for this channel.267 * @state: channel state machine268 */269struct slim_channel {270	int id;271	int prrate;272	int seg_dist;273	enum slim_ch_data_fmt data_fmt;274	enum slim_ch_aux_bit_fmt aux_fmt;275	enum slim_channel_state state;276};277 278/**279 * struct slim_port  - SLIMbus port280 *281 * @id: Port id282 * @direction: Port direction, Source or Sink.283 * @state: state machine of port.284 * @ch: channel associated with this port.285 */286struct slim_port {287	int id;288	enum slim_port_direction direction;289	enum slim_port_state state;290	struct slim_channel ch;291};292 293/**294 * enum slim_transport_protocol: SLIMbus Transport protocol list from295 *	Table 47 of SLIMbus 2.0 specs.296 * @SLIM_PROTO_ISO: Isochronous Protocol, no flow control as data rate match297 *		channel rate flow control embedded in the data.298 * @SLIM_PROTO_PUSH: Pushed Protocol, includes flow control, Used to carry299 *		data whose rate	is equal to, or lower than the channel rate.300 * @SLIM_PROTO_PULL: Pulled Protocol, similar usage as pushed protocol301 *		but pull is a unicast.302 * @SLIM_PROTO_LOCKED: Locked Protocol303 * @SLIM_PROTO_ASYNC_SMPLX: Asynchronous Protocol-Simplex304 * @SLIM_PROTO_ASYNC_HALF_DUP: Asynchronous Protocol-Half-duplex305 * @SLIM_PROTO_EXT_SMPLX: Extended Asynchronous Protocol-Simplex306 * @SLIM_PROTO_EXT_HALF_DUP: Extended Asynchronous Protocol-Half-duplex307 */308enum slim_transport_protocol {309	SLIM_PROTO_ISO = 0,310	SLIM_PROTO_PUSH,311	SLIM_PROTO_PULL,312	SLIM_PROTO_LOCKED,313	SLIM_PROTO_ASYNC_SMPLX,314	SLIM_PROTO_ASYNC_HALF_DUP,315	SLIM_PROTO_EXT_SMPLX,316	SLIM_PROTO_EXT_HALF_DUP,317};318 319/**320 * struct slim_stream_runtime  - SLIMbus stream runtime instance321 *322 * @name: Name of the stream323 * @dev: SLIM Device instance associated with this stream324 * @direction: direction of stream325 * @prot: Transport protocol used in this stream326 * @rate: Data rate of samples *327 * @bps: bits per sample328 * @ratem: rate multipler which is super frame rate/data rate329 * @num_ports: number of ports330 * @ports: pointer to instance of ports331 * @node: list head for stream associated with slim device.332 */333struct slim_stream_runtime {334	const char *name;335	struct slim_device *dev;336	int direction;337	enum slim_transport_protocol prot;338	unsigned int rate;339	unsigned int bps;340	unsigned int ratem;341	int num_ports;342	struct slim_port *ports;343	struct list_head node;344};345 346/**347 * struct slim_controller  - Controls every instance of SLIMbus348 *				(similar to 'master' on SPI)349 * @dev: Device interface to this driver350 * @id: Board-specific number identifier for this controller/bus351 * @name: Name for this controller352 * @min_cg: Minimum clock gear supported by this controller (default value: 1)353 * @max_cg: Maximum clock gear supported by this controller (default value: 10)354 * @clkgear: Current clock gear in which this bus is running355 * @laddr_ida: logical address id allocator356 * @a_framer: Active framer which is clocking the bus managed by this controller357 * @lock: Mutex protecting controller data structures358 * @devices: Slim device list359 * @tid_idr: tid id allocator360 * @txn_lock: Lock to protect table of transactions361 * @sched: scheduler structure used by the controller362 * @xfer_msg: Transfer a message on this controller (this can be a broadcast363 *	control/status message like data channel setup, or a unicast message364 *	like value element read/write.365 * @set_laddr: Setup logical address at laddr for the slave with elemental366 *	address e_addr. Drivers implementing controller will be expected to367 *	send unicast message to this device with its logical address.368 * @get_laddr: It is possible that controller needs to set fixed logical369 *	address table and get_laddr can be used in that case so that controller370 *	can do this assignment. Use case is when the master is on the remote371 *	processor side, who is resposible for allocating laddr.372 * @wakeup: This function pointer implements controller-specific procedure373 *	to wake it up from clock-pause. Framework will call this to bring374 *	the controller out of clock pause.375 * @enable_stream: This function pointer implements controller-specific procedure376 *	to enable a stream.377 * @disable_stream: This function pointer implements controller-specific procedure378 *	to disable stream.379 *380 *	'Manager device' is responsible for  device management, bandwidth381 *	allocation, channel setup, and port associations per channel.382 *	Device management means Logical address assignment/removal based on383 *	enumeration (report-present, report-absent) of a device.384 *	Bandwidth allocation is done dynamically by the manager based on active385 *	channels on the bus, message-bandwidth requests made by SLIMbus devices.386 *	Based on current bandwidth usage, manager chooses a frequency to run387 *	the bus at (in steps of 'clock-gear', 1 through 10, each clock gear388 *	representing twice the frequency than the previous gear).389 *	Manager is also responsible for entering (and exiting) low-power-mode390 *	(known as 'clock pause').391 *	Manager can do handover of framer if there are multiple framers on the392 *	bus and a certain usecase warrants using certain framer to avoid keeping393 *	previous framer being powered-on.394 *395 *	Controller here performs duties of the manager device, and 'interface396 *	device'. Interface device is responsible for monitoring the bus and397 *	reporting information such as loss-of-synchronization, data398 *	slot-collision.399 */400struct slim_controller {401	struct device		*dev;402	unsigned int		id;403	char			name[SLIMBUS_NAME_SIZE];404	int			min_cg;405	int			max_cg;406	int			clkgear;407	struct ida		laddr_ida;408	struct slim_framer	*a_framer;409	struct mutex		lock;410	struct list_head	devices;411	struct idr		tid_idr;412	spinlock_t		txn_lock;413	struct slim_sched	sched;414	int			(*xfer_msg)(struct slim_controller *ctrl,415					    struct slim_msg_txn *tx);416	int			(*set_laddr)(struct slim_controller *ctrl,417					     struct slim_eaddr *ea, u8 laddr);418	int			(*get_laddr)(struct slim_controller *ctrl,419					     struct slim_eaddr *ea, u8 *laddr);420	int		(*enable_stream)(struct slim_stream_runtime *rt);421	int		(*disable_stream)(struct slim_stream_runtime *rt);422	int			(*wakeup)(struct slim_controller *ctrl);423};424 425int slim_device_report_present(struct slim_controller *ctrl,426			       struct slim_eaddr *e_addr, u8 *laddr);427void slim_report_absent(struct slim_device *sbdev);428int slim_register_controller(struct slim_controller *ctrl);429int slim_unregister_controller(struct slim_controller *ctrl);430void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l);431int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn);432int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart);433int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);434void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn);435 436static inline bool slim_tid_txn(u8 mt, u8 mc)437{438	return (mt == SLIM_MSG_MT_CORE &&439		(mc == SLIM_MSG_MC_REQUEST_INFORMATION ||440		 mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION ||441		 mc == SLIM_MSG_MC_REQUEST_VALUE ||442		 mc == SLIM_MSG_MC_REQUEST_CHANGE_VALUE));443}444 445static inline bool slim_ec_txn(u8 mt, u8 mc)446{447	return (mt == SLIM_MSG_MT_CORE &&448		((mc >= SLIM_MSG_MC_REQUEST_INFORMATION &&449		  mc <= SLIM_MSG_MC_REPORT_INFORMATION) ||450		 (mc >= SLIM_MSG_MC_REQUEST_VALUE &&451		  mc <= SLIM_MSG_MC_CHANGE_VALUE)));452}453#endif /* _LINUX_SLIMBUS_H */454