blob: 2b5adb346f49a9db7addf2fa83003c365ac0c408 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _LINUX_SLIMBUS_H
14#define _LINUX_SLIMBUS_H
15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/mutex.h>
18#include <linux/mod_devicetable.h>
19
20/* Interfaces between SLIMbus manager drivers and SLIMbus infrastructure. */
21
22extern struct bus_type slimbus_type;
23
24/* Standard values per SLIMbus spec needed by controllers and devices */
25#define SLIM_CL_PER_SUPERFRAME 6144
26#define SLIM_CL_PER_SUPERFRAME_DIV8 (SLIM_CL_PER_SUPERFRAME >> 3)
27#define SLIM_MAX_CLK_GEAR 10
Sagar Dharia98a7ecb2011-07-25 15:25:35 -060028#define SLIM_MIN_CLK_GEAR 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029#define SLIM_CL_PER_SL 4
30#define SLIM_SL_PER_SUPERFRAME (SLIM_CL_PER_SUPERFRAME >> 2)
31#define SLIM_FRM_SLOTS_PER_SUPERFRAME 16
32#define SLIM_GDE_SLOTS_PER_SUPERFRAME 2
33
34/*
35 * SLIMbus message types. Related to interpretation of message code.
36 * Values are defined in Table 32 (slimbus spec 1.01.01)
37 */
38#define SLIM_MSG_MT_CORE 0x0
39#define SLIM_MSG_MT_DEST_REFERRED_CLASS 0x1
40#define SLIM_MSG_MT_DEST_REFERRED_USER 0x2
41#define SLIM_MSG_MT_SRC_REFERRED_CLASS 0x5
42#define SLIM_MSG_MT_SRC_REFERRED_USER 0x6
43
44/*
45 * SLIMbus core type Message Codes.
46 * Values are defined in Table 65 (slimbus spec 1.01.01)
47 */
48/* Device management messages */
49#define SLIM_MSG_MC_REPORT_PRESENT 0x1
50#define SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS 0x2
51#define SLIM_MSG_MC_RESET_DEVICE 0x4
52#define SLIM_MSG_MC_CHANGE_LOGICAL_ADDRESS 0x8
53#define SLIM_MSG_MC_CHANGE_ARBITRATION_PRIORITY 0x9
54#define SLIM_MSG_MC_REQUEST_SELF_ANNOUNCEMENT 0xC
55#define SLIM_MSG_MC_REPORT_ABSENT 0xF
56
57/* Data channel management messages */
58#define SLIM_MSG_MC_CONNECT_SOURCE 0x10
59#define SLIM_MSG_MC_CONNECT_SINK 0x11
60#define SLIM_MSG_MC_DISCONNECT_PORT 0x14
61#define SLIM_MSG_MC_CHANGE_CONTENT 0x18
62
63/* Information management messages */
64#define SLIM_MSG_MC_REQUEST_INFORMATION 0x20
65#define SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION 0x21
66#define SLIM_MSG_MC_REPLY_INFORMATION 0x24
67#define SLIM_MSG_MC_CLEAR_INFORMATION 0x28
68#define SLIM_MSG_MC_REPORT_INFORMATION 0x29
69
70/* Reconfiguration messages */
71#define SLIM_MSG_MC_BEGIN_RECONFIGURATION 0x40
72#define SLIM_MSG_MC_NEXT_ACTIVE_FRAMER 0x44
73#define SLIM_MSG_MC_NEXT_SUBFRAME_MODE 0x45
74#define SLIM_MSG_MC_NEXT_CLOCK_GEAR 0x46
75#define SLIM_MSG_MC_NEXT_ROOT_FREQUENCY 0x47
76#define SLIM_MSG_MC_NEXT_PAUSE_CLOCK 0x4A
77#define SLIM_MSG_MC_NEXT_RESET_BUS 0x4B
78#define SLIM_MSG_MC_NEXT_SHUTDOWN_BUS 0x4C
79#define SLIM_MSG_MC_NEXT_DEFINE_CHANNEL 0x50
80#define SLIM_MSG_MC_NEXT_DEFINE_CONTENT 0x51
81#define SLIM_MSG_MC_NEXT_ACTIVATE_CHANNEL 0x54
82#define SLIM_MSG_MC_NEXT_DEACTIVATE_CHANNEL 0x55
83#define SLIM_MSG_MC_NEXT_REMOVE_CHANNEL 0x58
84#define SLIM_MSG_MC_RECONFIGURE_NOW 0x5F
85
Sagar Dharia45ee38a2011-08-03 17:01:31 -060086/*
87 * Clock pause flag to indicate that the reconfig message
88 * corresponds to clock pause sequence
89 */
90#define SLIM_MSG_CLK_PAUSE_SEQ_FLG (1U << 8)
91
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092/* Value management messages */
93#define SLIM_MSG_MC_REQUEST_VALUE 0x60
94#define SLIM_MSG_MC_REQUEST_CHANGE_VALUE 0x61
95#define SLIM_MSG_MC_REPLY_VALUE 0x64
96#define SLIM_MSG_MC_CHANGE_VALUE 0x68
97
Sagar Dharia33f34442011-08-08 16:22:03 -060098/* Clock pause values defined in Table 66 (slimbus spec 1.01.01) */
99#define SLIM_CLK_FAST 0
100#define SLIM_CLK_CONST_PHASE 1
101#define SLIM_CLK_UNSPECIFIED 2
102
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103struct slim_controller;
104struct slim_device;
105
106/* Destination type Values defined in Table 33 (slimbus spec 1.01.01) */
107#define SLIM_MSG_DEST_LOGICALADDR 0
108#define SLIM_MSG_DEST_ENUMADDR 1
109#define SLIM_MSG_DEST_BROADCAST 3
110
111/*
112 * @start_offset: Specifies starting offset in information/value element map
113 * @num_bytes: Can be 1, 2, 3, 4, 6, 8, 12, 16 per spec. This ensures that the
114 * message will fit in the 40-byte message limit and the slicesize can be
115 * compatible with values in table 21 (slimbus spec 1.01.01)
116 * @comp: Completion to indicate end of message-transfer. Used if client wishes
117 * to use the API asynchronously.
118 */
119struct slim_ele_access {
120 u16 start_offset;
121 u8 num_bytes;
122 struct completion *comp;
123};
124
125/*
126 * struct slim_framer - Represents Slimbus framer.
127 * Every controller may have multiple framers.
128 * Manager is responsible for framer hand-over.
129 * @e_addr: 6 byte Elemental address of the framer.
130 * @rootfreq: Root Frequency at which the framer can run. This is maximum
131 * frequency (clock gear 10 per slimbus spec) at which the bus can operate.
132 * @superfreq: Superframes per root frequency. Every frame is 6144 cells (bits)
133 * per slimbus specification.
134 */
135struct slim_framer {
136 u8 e_addr[6];
137 int rootfreq;
138 int superfreq;
139};
140#define to_slim_framer(d) container_of(d, struct slim_framer, dev);
141
142/*
143 * struct slim_addrt: slimbus address used internally by the slimbus framework.
144 * @valid: If the device is still there or if the address can be reused.
145 * @eaddr: 6-bytes-long elemental address
146 */
147struct slim_addrt {
148 bool valid;
149 u8 eaddr[6];
150};
151
152/*
153 * struct slim_msg_txn: Message to be sent by the controller.
154 * Linux framework uses this structure with drivers implementing controller.
155 * This structure has packet header, payload and buffer to be filled (if any)
156 * For the header information, refer to Table 34-36.
157 * @rl: Header field. remaining length.
158 * @mt: Header field. Message type.
Sagar Dharia45ee38a2011-08-03 17:01:31 -0600159 * @mc: Header field. LSB is message code for type mt. Framework will set MSB to
160 * SLIM_MSG_CLK_PAUSE_SEQ_FLG in case "mc" in the reconfiguration sequence
161 * is for pausing the clock.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162 * @dt: Header field. Destination type.
163 * @ec: Element size. Used for elemental access APIs.
164 * @len: Length of payload. (excludes ec)
165 * @tid: Transaction ID. Used for messages expecting response.
166 * (e.g. relevant for mc = SLIM_MSG_MC_REQUEST_INFORMATION)
167 * @la: Logical address of the device this message is going to.
168 * (Not used when destination type is broadcast.)
169 * @rbuf: Buffer to be populated by controller when response is received.
170 * @wbuf: Payload of the message. (e.g. channel number for DATA channel APIs)
171 * @comp: Completion structure. Used by controller to notify response.
172 * (Field is relevant when tid is used)
173 */
174struct slim_msg_txn {
175 u8 rl;
176 u8 mt;
Sagar Dharia45ee38a2011-08-03 17:01:31 -0600177 u16 mc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 u8 dt;
179 u16 ec;
180 u8 len;
181 u8 tid;
182 u8 la;
183 u8 *rbuf;
184 const u8 *wbuf;
185 struct completion *comp;
186};
187
188/* Internal port state used by slimbus framework to manage data-ports */
189enum slim_port_state {
190 SLIM_P_FREE,
191 SLIM_P_UNCFG,
192 SLIM_P_CFG,
193};
194
195/*
196 * enum slim_port_req: Request port type by user through APIs to manage ports
197 * User can request default, half-duplex or port to be used in multi-channel
198 * configuration. Default indicates a simplex port.
199 */
200enum slim_port_req {
201 SLIM_REQ_DEFAULT,
202 SLIM_REQ_HALF_DUP,
203 SLIM_REQ_MULTI_CH,
204};
205
206/*
207 * enum slim_port_cfg: Port configuration parameters requested.
208 * User can request no configuration, packed data, or MSB aligned data port
209 */
210enum slim_port_cfg {
211 SLIM_CFG_NONE,
212 SLIM_CFG_PACKED,
213 SLIM_CFG_ALIGN_MSB,
214};
215
216/* enum slim_port_flow: Port flow type (inbound/outbound). */
217enum slim_port_flow {
218 SLIM_SRC,
219 SLIM_SINK,
220};
221
222/* enum slim_port_err: Port errors */
223enum slim_port_err {
224 SLIM_P_INPROGRESS,
225 SLIM_P_OVERFLOW,
226 SLIM_P_UNDERFLOW,
227 SLIM_P_DISCONNECT,
228 SLIM_P_NOT_OWNED,
229};
230
231/*
232 * struct slim_port: Internal structure used by framework to manage ports
233 * @err: Port error if any for this port. Refer to enum above.
234 * @state: Port state. Refer to enum above.
235 * @req: Port request for this port.
236 * @cfg: Port configuration for this port.
237 * @flow: Flow type of this port.
238 * @ch: Channel association of this port.
239 * @xcomp: Completion to indicate error, data transfer done event.
240 * @ctrl: Controller to which this port belongs to. This is useful to associate
241 * port with the SW since port hardware interrupts may only contain port
242 * information.
243 */
244struct slim_port {
245 enum slim_port_err err;
246 enum slim_port_state state;
247 enum slim_port_req req;
248 enum slim_port_cfg cfg;
249 enum slim_port_flow flow;
250 struct slim_ch *ch;
251 struct completion *xcomp;
252 struct slim_controller *ctrl;
253};
254
255/*
256 * enum slim_ch_state: Channel state of a channel.
257 * Channel transition happens from free-to-allocated-to-defined-to-pending-
258 * active-to-active.
259 * Once active, channel can be removed or suspended. Suspended channels are
260 * still scheduled, but data transfer doesn't happen.
261 * Removed channels are not deallocated until dealloc_ch API is used.
262 * Deallocation reset channel state back to free.
263 * Removed channels can be defined with different parameters.
264 */
265enum slim_ch_state {
266 SLIM_CH_FREE,
267 SLIM_CH_ALLOCATED,
268 SLIM_CH_DEFINED,
269 SLIM_CH_PENDING_ACTIVE,
270 SLIM_CH_ACTIVE,
271 SLIM_CH_SUSPENDED,
272 SLIM_CH_PENDING_REMOVAL,
273};
274
275/*
276 * enum slim_ch_proto: Channel protocol used by the channel.
277 * Hard Isochronous channel is not scheduled if current frequency doesn't allow
278 * the channel to be run without flow-control.
279 * Auto isochronous channel will be scheduled as hard-isochronous or push-pull
280 * depending on current bus frequency.
281 * Currently, Push-pull or async or extended channels are not supported.
282 * For more details, refer to slimbus spec
283 */
284enum slim_ch_proto {
285 SLIM_HARD_ISO,
286 SLIM_AUTO_ISO,
287 SLIM_PUSH,
288 SLIM_PULL,
289 SLIM_ASYNC_SMPLX,
290 SLIM_ASYNC_HALF_DUP,
291 SLIM_EXT_SMPLX,
292 SLIM_EXT_HALF_DUP,
293};
294
295/*
296 * enum slim_ch_rate: Most commonly used frequency rate families.
297 * Use 1HZ for push-pull transport.
298 * 4KHz and 11.025KHz are most commonly used in audio applications.
299 * Typically, slimbus runs at frequencies to support channels running at 4KHz
300 * and/or 11.025KHz isochronously.
301 */
302enum slim_ch_rate {
303 SLIM_RATE_1HZ,
304 SLIM_RATE_4000HZ,
305 SLIM_RATE_11025HZ,
306};
307
308/*
309 * enum slim_ch_coeff: Coefficient of a channel used internally by framework.
310 * Coefficient is applicable to channels running isochronously.
311 * Coefficient is calculated based on channel rate multiplier.
312 * (If rate multiplier is power of 2, it's coeff.1 channel. Otherwise it's
313 * coeff.3 channel.
314 */
315enum slim_ch_coeff {
316 SLIM_COEFF_1,
317 SLIM_COEFF_3,
318};
319
320/*
321 * enum slim_ch_control: Channel control.
322 * Activate will schedule channel and/or group of channels in the TDM frame.
323 * Suspend will keep the schedule but data-transfer won't happen.
324 * Remove will remove the channel/group from the TDM frame.
325 */
326enum slim_ch_control {
327 SLIM_CH_ACTIVATE,
328 SLIM_CH_SUSPEND,
329 SLIM_CH_REMOVE,
330};
331
332/* enum slim_ch_dataf: Data format per table 60 from slimbus spec 1.01.01 */
333enum slim_ch_dataf {
334 SLIM_CH_DATAF_NOT_DEFINED = 0,
335 SLIM_CH_DATAF_LPCM_AUDIO = 1,
336 SLIM_CH_DATAF_IEC61937_COMP_AUDIO = 2,
337 SLIM_CH_DATAF_PACKED_PDM_AUDIO = 3,
338};
339
340/* enum slim_ch_auxf: Auxiliary field format per table 59 from slimbus spec */
341enum slim_ch_auxf {
342 SLIM_CH_AUXF_NOT_APPLICABLE = 0,
343 SLIM_CH_AUXF_ZCUV_TUNNEL_IEC60958 = 1,
344 SLIM_CH_USER_DEFINED = 0xF,
345};
346
347/*
348 * struct slim_ch: Channel structure used externally by users of channel APIs.
349 * @prot: Desired slimbus protocol.
350 * @baser: Desired base rate. (Typical isochronous rates are: 4KHz, or 11.025KHz
351 * @dataf: Data format.
352 * @auxf: Auxiliary format.
353 * @ratem: Channel rate multiplier. (e.g. 48KHz channel will have 4KHz base rate
354 * and 12 as rate multiplier.
355 * @sampleszbits: Sample size in bits.
356 */
357struct slim_ch {
358 enum slim_ch_proto prot;
359 enum slim_ch_rate baser;
360 enum slim_ch_dataf dataf;
361 enum slim_ch_auxf auxf;
362 u32 ratem;
363 u32 sampleszbits;
364};
365
366/*
367 * struct slim_ich: Internal channel structure used by slimbus framework.
368 * @prop: structure passed by the client.
369 * @coeff: Coefficient of this channel.
370 * @state: Current state of the channel.
371 * @nextgrp: If this channel is part of group, next channel in this group.
372 * @prrate: Presence rate of this channel (per table 62 of the spec)
373 * @offset: Offset of this channel in the superframe.
374 * @newoff: Used during scheduling to hold temporary new offset until the offset
375 * is accepted/rejected by slimbus reconfiguration.
376 * @interval: Interval of this channel per superframe.
377 * @newintr: Used during scheduling to new interval temporarily.
378 * @seglen: Segment length of this channel.
379 * @rootexp: root exponent of this channel. Rate can be found using rootexp and
380 * coefficient. Used during scheduling.
381 * @srch: Source ports used by this channel.
382 * @nsrc: number of source ports used by this channel.
383 * @sinkh: Sink port used by this channel.
384 */
385struct slim_ich {
386 struct slim_ch prop;
387 enum slim_ch_coeff coeff;
388 enum slim_ch_state state;
389 u16 nextgrp;
390 u32 prrate;
391 u32 offset;
392 u32 newoff;
393 u32 interval;
394 u32 newintr;
395 u32 seglen;
396 u8 rootexp;
397 u32 *srch;
398 int nsrc;
399 u32 sinkh;
400};
401
402/*
403 * struct slim_sched: Framework uses this structure internally for scheduling.
404 * @chc3: Array of all active coeffient 3 channels.
405 * @num_cc3: Number of active coeffient 3 channels.
406 * @chc1: Array of all active coeffient 1 channels.
407 * @num_cc1: Number of active coeffient 1 channels.
408 * @subfrmcode: Current subframe-code used by TDM. This is decided based on
409 * requested message bandwidth and current channels scheduled.
410 * @usedslots: Slots used by all active channels.
411 * @msgsl: Slots used by message-bandwidth.
412 * @pending_msgsl: Used to store pending request of message bandwidth (in slots)
413 * until the scheduling is accepted by reconfiguration.
414 * @m_reconf: This mutex is held until current reconfiguration (data channel
415 * scheduling, message bandwidth reservation) is done. Message APIs can
416 * use the bus concurrently when this mutex is held since elemental access
417 * messages can be sent on the bus when reconfiguration is in progress.
418 * @slots: Used for debugging purposes to debug/verify current schedule in TDM.
419 */
420struct slim_sched {
421 struct slim_ich **chc3;
422 int num_cc3;
423 struct slim_ich **chc1;
424 int num_cc1;
425 u32 subfrmcode;
426 u32 usedslots;
427 u32 msgsl;
428 u32 pending_msgsl;
429 struct mutex m_reconf;
430 u8 *slots;
431};
432
433/*
Sagar Dharia33f34442011-08-08 16:22:03 -0600434 * enum slim_clk_state: Slimbus controller's clock state used internally for
435 * maintaining current clock state.
436 * @SLIM_CLK_ACTIVE: Slimbus clock is active
437 * @SLIM_CLK_PAUSE_FAILED: Slimbus controlled failed to go in clock pause.
438 * Hardware-wise, this state is same as active but controller will wait on
439 * completion before making transition to SLIM_CLK_ACTIVE in framework
440 * @SLIM_CLK_ENTERING_PAUSE: Slimbus clock pause sequence is being sent on the
441 * bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the
442 * transition fails, state changes to SLIM_CLK_PAUSE_FAILED
443 * @SLIM_CLK_PAUSED: Slimbus controller clock has paused.
444 */
445enum slim_clk_state {
446 SLIM_CLK_ACTIVE,
447 SLIM_CLK_ENTERING_PAUSE,
448 SLIM_CLK_PAUSE_FAILED,
449 SLIM_CLK_PAUSED,
450};
451/*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700452 * struct slim_controller: Represents manager for a SlimBUS
453 * (similar to 'master' on I2C)
454 * @dev: Device interface to this driver
455 * @nr: Board-specific number identifier for this controller/bus
456 * @list: Link with other slimbus controllers
457 * @name: Name for this controller
458 * @clkgear: Current clock gear in which this bus is running
Sagar Dharia98a7ecb2011-07-25 15:25:35 -0600459 * @min_cg: Minimum clock gear supported by this controller (default value: 1)
460 * @max_cg: Maximum clock gear supported by this controller (default value: 10)
Sagar Dharia33f34442011-08-08 16:22:03 -0600461 * @clk_state: Controller's clock state from enum slim_clk_state
462 * @pause_comp: Signals completion of clock pause sequence. This is useful when
463 * client tries to call slimbus transaction when controller may be entering
464 * clock pause.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465 * @a_framer: Active framer which is clocking the bus managed by this controller
466 * @m_ctrl: Mutex protecting controller data structures (ports, channels etc)
467 * @addrt: Logical address table
468 * @num_dev: Number of active slimbus slaves on this bus
469 * @txnt: Table of transactions having transaction ID
470 * @last_tid: size of the table txnt (can't grow beyond 256 since TID is 8-bits)
471 * @ports: Ports associated with this controller
472 * @nports: Number of ports supported by the controller
473 * @chans: Channels associated with this controller
474 * @nchans: Number of channels supported
475 * @sched: scheduler structure used by the controller
476 * @dev_released: completion used to signal when sysfs has released this
477 * controller so that it can be deleted during shutdown
478 * @xfer_msg: Transfer a message on this controller (this can be a broadcast
479 * control/status message like data channel setup, or a unicast message
480 * like value element read/write.
481 * @set_laddr: Setup logical address at laddr for the slave with elemental
482 * address e_addr. Drivers implementing controller will be expected to
483 * send unicast message to this device with its logical address.
Sagar Dharia33f34442011-08-08 16:22:03 -0600484 * @wakeup: This function pointer implements controller-specific procedure
485 * to wake it up from clock-pause. Framework will call this to bring
486 * the controller out of clock pause.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 * @config_port: Configure a port and make it ready for data transfer. This is
488 * called by framework after connect_port message is sent successfully.
489 * @framer_handover: If this controller has multiple framers, this API will
490 * be called to switch between framers if controller desires to change
491 * the active framer.
492 * @port_xfer: Called to schedule a transfer on port pn. iobuf is physical
493 * address and the buffer may have to be DMA friendly since data channels
494 * will be using data from this buffers without SW intervention.
495 * @port_xfer_status: Called by framework when client calls get_xfer_status
496 * API. Returns how much buffer is actually processed and the port
497 * errors (e.g. overflow/underflow) if any.
498 */
499struct slim_controller {
500 struct device dev;
501 unsigned int nr;
502 struct list_head list;
503 char name[SLIMBUS_NAME_SIZE];
504 int clkgear;
Sagar Dharia98a7ecb2011-07-25 15:25:35 -0600505 int min_cg;
506 int max_cg;
Sagar Dharia33f34442011-08-08 16:22:03 -0600507 enum slim_clk_state clk_state;
508 struct completion pause_comp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700509 struct slim_framer *a_framer;
510 struct mutex m_ctrl;
511 struct slim_addrt *addrt;
512 u8 num_dev;
513 struct slim_msg_txn **txnt;
514 u8 last_tid;
515 struct slim_port *ports;
516 int nports;
517 struct slim_ich *chans;
518 int nchans;
519 struct slim_sched sched;
520 struct completion dev_released;
521 int (*xfer_msg)(struct slim_controller *ctrl,
522 struct slim_msg_txn *txn);
523 int (*set_laddr)(struct slim_controller *ctrl,
524 const u8 *ea, u8 elen, u8 laddr);
Sagar Dharia33f34442011-08-08 16:22:03 -0600525 int (*wakeup)(struct slim_controller *ctrl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700526 int (*config_port)(struct slim_controller *ctrl,
527 u8 port);
528 int (*framer_handover)(struct slim_controller *ctrl,
529 struct slim_framer *new_framer);
530 int (*port_xfer)(struct slim_controller *ctrl,
531 u8 pn, u8 *iobuf, u32 len,
532 struct completion *comp);
533 enum slim_port_err (*port_xfer_status)(struct slim_controller *ctr,
534 u8 pn, u8 **done_buf, u32 *done_len);
535};
536#define to_slim_controller(d) container_of(d, struct slim_controller, dev)
537
538/*
539 * struct slim_driver: Manage Slimbus generic/slave device driver
540 * @probe: Binds this driver to a slimbus device.
541 * @remove: Unbinds this driver from the slimbus device.
542 * @shutdown: Standard shutdown callback used during powerdown/halt.
543 * @suspend: Standard suspend callback used during system suspend
544 * @resume: Standard resume callback used during system resume
545 * @driver: Slimbus device drivers should initialize name and owner field of
546 * this structure
547 * @id_table: List of slimbus devices supported by this driver
548 */
549struct slim_driver {
550 int (*probe)(struct slim_device *sldev);
551 int (*remove)(struct slim_device *sldev);
552 void (*shutdown)(struct slim_device *sldev);
553 int (*suspend)(struct slim_device *sldev,
554 pm_message_t pmesg);
555 int (*resume)(struct slim_device *sldev);
556
557 struct device_driver driver;
558 const struct slim_device_id *id_table;
559};
560#define to_slim_driver(d) container_of(d, struct slim_driver, driver)
561
562/*
563 * struct slim_pending_ch: List of pending channels used by framework.
564 * @chan: Channel number
565 * @pending: list of channels
566 */
567struct slim_pending_ch {
568 u8 chan;
569 struct list_head pending;
570};
571
572/*
573 * Client/device handle (struct slim_device):
574 * ------------------------------------------
575 * This is the client/device handle returned when a slimbus
576 * device is registered with a controller. This structure can be provided
577 * during register_board_info, or can be allocated using slim_add_device API.
578 * Pointer to this structure is used by client-driver as a handle.
579 * @dev: Driver model representation of the device.
580 * @name: Name of driver to use with this device.
581 * @e_addr: 6-byte elemental address of this device.
582 * @driver: Device's driver. Pointer to access routines.
583 * @ctrl: Slimbus controller managing the bus hosting this device.
584 * @laddr: 1-byte Logical address of this device.
585 * @mark_define: List of channels pending definition/activation.
586 * @mark_suspend: List of channels pending suspend.
587 * @mark_removal: List of channels pending removal.
588 * @sldev_reconf: Mutex to protect the pending data-channel lists.
589 * @pending_msgsl: Message bandwidth reservation request by this client in
590 * slots that's pending reconfiguration.
591 * @cur_msgsl: Message bandwidth reserved by this client in slots.
592 * These 3 lists are managed by framework. Lists are populated when client
593 * calls channel control API without reconfig-flag set and the lists are
594 * emptied when the reconfiguration is done by this client.
595 */
596struct slim_device {
597 struct device dev;
598 const char *name;
599 u8 e_addr[6];
600 struct slim_driver *driver;
601 struct slim_controller *ctrl;
602 u8 laddr;
603 struct list_head mark_define;
604 struct list_head mark_suspend;
605 struct list_head mark_removal;
606 struct mutex sldev_reconf;
607 u32 pending_msgsl;
608 u32 cur_msgsl;
609};
610#define to_slim_device(d) container_of(d, struct slim_device, dev)
611
612/*
613 * struct slim_boardinfo: Declare board info for Slimbus device bringup.
614 * @bus_num: Controller number (bus) on which this device will sit.
615 * @slim_slave: Device to be registered with slimbus.
616 */
617struct slim_boardinfo {
618 int bus_num;
619 struct slim_device *slim_slave;
620};
621
622/*
623 * slim_get_logical_addr: Return the logical address of a slimbus device.
624 * @sb: client handle requesting the adddress.
625 * @e_addr: Elemental address of the device.
626 * @e_len: Length of e_addr
627 * @laddr: output buffer to store the address
628 * context: can sleep
629 * -EINVAL is returned in case of invalid parameters, and -ENXIO is returned if
630 * the device with this elemental address is not found.
631 */
632
633extern int slim_get_logical_addr(struct slim_device *sb, const u8 *e_addr,
634 u8 e_len, u8 *laddr);
635
636
637/* Message APIs Unicast message APIs used by slimbus slave drivers */
638
639/*
640 * Message API access routines.
641 * @sb: client handle requesting elemental message reads, writes.
642 * @msg: Input structure for start-offset, number of bytes to read.
643 * @rbuf: data buffer to be filled with values read.
644 * @len: data buffer size
645 * @wbuf: data buffer containing value/information to be written
646 * context: can sleep
647 * Returns:
648 * -EINVAL: Invalid parameters
649 * -ETIMEDOUT: If controller could not complete the request. This may happen if
650 * the bus lines are not clocked, controller is not powered-on, slave with
651 * given address is not enumerated/responding.
652 */
653extern int slim_request_val_element(struct slim_device *sb,
654 struct slim_ele_access *msg, u8 *buf,
655 u8 len);
656extern int slim_request_inf_element(struct slim_device *sb,
657 struct slim_ele_access *msg, u8 *buf,
658 u8 len);
659extern int slim_change_val_element(struct slim_device *sb,
660 struct slim_ele_access *msg,
661 const u8 *buf, u8 len);
662extern int slim_clear_inf_element(struct slim_device *sb,
663 struct slim_ele_access *msg, u8 *buf,
664 u8 len);
665extern int slim_request_change_val_element(struct slim_device *sb,
666 struct slim_ele_access *msg, u8 *rbuf,
667 const u8 *wbuf, u8 len);
668extern int slim_request_clear_inf_element(struct slim_device *sb,
669 struct slim_ele_access *msg, u8 *rbuf,
670 const u8 *wbuf, u8 len);
671
672/*
673 * Broadcast message API:
674 * call this API directly with sbdev = NULL.
675 * For broadcast reads, make sure that buffers are big-enough to incorporate
676 * replies from all logical addresses.
677 * All controllers may not support broadcast
678 */
679extern int slim_xfer_msg(struct slim_controller *ctrl,
680 struct slim_device *sbdev, struct slim_ele_access *msg,
Sagar Dharia45ee38a2011-08-03 17:01:31 -0600681 u16 mc, u8 *rbuf, const u8 *wbuf, u8 len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682/* end of message apis */
683
684/* Port management for manager device APIs */
685
686/*
687 * slim_alloc_mgrports: Allocate port on manager side.
688 * @sb: device/client handle.
689 * @req: Port request type.
690 * @nports: Number of ports requested
691 * @rh: output buffer to store the port handles
692 * @hsz: size of buffer storing handles
693 * context: can sleep
694 * This port will be typically used by SW. e.g. client driver wants to receive
695 * some data from audio codec HW using a data channel.
696 * Port allocated using this API will be used to receive the data.
697 * If half-duplex ports are requested, two adjacent ports are allocated for
698 * 1 half-duplex port. So the handle-buffer size should be twice the number
699 * of half-duplex ports to be allocated.
700 * -EDQUOT is returned if all ports are in use.
701 */
702extern int slim_alloc_mgrports(struct slim_device *sb, enum slim_port_req req,
703 int nports, u32 *rh, int hsz);
704
705/* Deallocate the port(s) allocated using the API above */
706extern int slim_dealloc_mgrports(struct slim_device *sb, u32 *hdl, int hsz);
707
708/*
709 * slim_port_xfer: Schedule buffer to be transferred/received using port-handle.
710 * @sb: client handle
711 * @ph: port-handle
712 * @iobuf: buffer to be transferred or populated
713 * @len: buffer size.
714 * @comp: completion signal to indicate transfer done or error.
715 * context: can sleep
716 * Returns number of bytes transferred/received if used synchronously.
717 * Will return 0 if used asynchronously.
718 * Client will call slim_port_get_xfer_status to get error and/or number of
719 * bytes transferred if used asynchronously.
720 */
721extern int slim_port_xfer(struct slim_device *sb, u32 ph, u8 *iobuf, u32 len,
722 struct completion *comp);
723
724/*
725 * slim_port_get_xfer_status: Poll for port transfers, or get transfer status
726 * after completion is done.
727 * @sb: client handle
728 * @ph: port-handle
729 * @done_buf: return pointer (iobuf from slim_port_xfer) which is processed.
730 * @done_len: Number of bytes transferred.
731 * This can be called when port_xfer complition is signalled.
732 * The API will return port transfer error (underflow/overflow/disconnect)
733 * and/or done_len will reflect number of bytes transferred. Note that
734 * done_len may be valid even if port error (overflow/underflow) has happened.
735 * e.g. If the transfer was scheduled with a few bytes to be transferred and
736 * client has not supplied more data to be transferred, done_len will indicate
737 * number of bytes transferred with underflow error. To avoid frequent underflow
738 * errors, multiple transfers can be queued (e.g. ping-pong buffers) so that
739 * channel has data to be transferred even if client is not ready to transfer
740 * data all the time. done_buf will indicate address of the last buffer
741 * processed from the multiple transfers.
742 */
743extern enum slim_port_err slim_port_get_xfer_status(struct slim_device *sb,
744 u32 ph, u8 **done_buf, u32 *done_len);
745
746/*
747 * slim_connect_ports: Connect port(s) to channel.
748 * @sb: client handle
749 * @srch: source handles to be connected to this channel
750 * @nrsc: number of source ports
751 * @sinkh: sink handle to be connected to this channel
752 * @chanh: Channel with which the ports need to be associated with.
753 * Per slimbus specification, a channel may have multiple source-ports and 1
754 * sink port.Channel specified in chanh needs to be allocated first.
755 */
756extern int slim_connect_ports(struct slim_device *sb, u32 *srch, int nsrc,
757 u32 sinkh, u16 chanh);
758
759/*
760 * slim_disconnect_ports: Disconnect port(s) from channel
761 * @sb: client handle
762 * @ph: ports to be disconnected
763 * @nph: number of ports.
764 * Disconnects ports from a channel.
765 */
766extern int slim_disconnect_ports(struct slim_device *sb, u32 *ph, int nph);
767
768/*
769 * slim_get_slaveport: Get slave port handle
770 * @la: slave device logical address.
771 * @idx: port index at slave
772 * @rh: return handle
773 * @flw: Flow type (source or destination)
774 * This API only returns a slave port's representation as expected by slimbus
775 * driver. This port is not managed by the slimbus driver. Caller is expected
776 * to have visibility of this port since it's a device-port.
777 */
778extern int slim_get_slaveport(u8 la, int idx, u32 *rh, enum slim_port_flow flw);
779
780
781/* Channel functions. */
782
783/*
784 * slim_alloc_ch: Allocate a slimbus channel and return its handle.
785 * @sb: client handle.
786 * @chanh: return channel handle
787 * Slimbus channels are limited to 256 per specification. LSB of the handle
788 * indicates channel number and MSB of the handle is used by the slimbus
789 * framework. -EXFULL is returned if all channels are in use.
790 * Although slimbus specification supports 256 channels, a controller may not
791 * support that many channels.
792 */
793extern int slim_alloc_ch(struct slim_device *sb, u16 *chanh);
794
795/*
796 * slim_dealloc_ch: Deallocate channel allocated using the API above
797 * -EISCONN is returned if the channel is tried to be deallocated without
798 * being removed first.
799 */
800extern int slim_dealloc_ch(struct slim_device *sb, u16 chanh);
801
802
803/*
804 * slim_define_ch: Define a channel.This API defines channel parameters for a
805 * given channel.
806 * @sb: client handle.
807 * @prop: slim_ch structure with channel parameters desired to be used.
808 * @chanh: list of channels to be defined.
809 * @nchan: number of channels in a group (1 if grp is false)
810 * @grp: Are the channels grouped
811 * @grph: return group handle if grouping of channels is desired.
812 * Channels can be grouped if multiple channels use same parameters
813 * (e.g. 5.1 audio has 6 channels with same parameters. They will all be
814 * grouped and given 1 handle for simplicity and avoid repeatedly calling
815 * the API)
816 * -EISCONN is returned if the channel is already connected. -EBUSY is
817 * returned if the channel is already allocated to some other client.
818 */
819extern int slim_define_ch(struct slim_device *sb, struct slim_ch *prop,
820 u16 *chanh, u8 nchan, bool grp, u16 *grph);
821
822/*
823 * slim_control_ch: Channel control API.
824 * @sb: client handle
825 * @grpchanh: group or channel handle to be controlled
826 * @chctrl: Control command (activate/suspend/remove)
827 * @commit: flag to indicate whether the control should take effect right-away.
828 * This API activates, removes or suspends a channel (or group of channels)
829 * grpchanh indicates the channel or group handle (returned by the define_ch
830 * API). Reconfiguration may be time-consuming since it can change all other
831 * active channel allocations on the bus, change in clock gear used by the
832 * slimbus, and change in the control space width used for messaging.
833 * commit makes sure that multiple channels can be activated/deactivated before
834 * reconfiguration is started.
835 * -EXFULL is returned if there is no space in TDM to reserve the bandwidth.
836 * -EISCONN/-ENOTCONN is returned if the channel is already connected or not
837 * yet defined.
838 */
839extern int slim_control_ch(struct slim_device *sb, u16 grpchanh,
840 enum slim_ch_control chctrl, bool commit);
841
842/*
843 * slim_get_ch_state: Channel state.
844 * This API returns the channel's state (active, suspended, inactive etc)
845 */
846extern enum slim_ch_state slim_get_ch_state(struct slim_device *sb,
847 u16 chanh);
848
849/*
850 * slim_reservemsg_bw: Request to reserve bandwidth for messages.
851 * @sb: client handle
852 * @bw_bps: message bandwidth in bits per second to be requested
853 * @commit: indicates whether the reconfiguration needs to be acted upon.
854 * This API call can be grouped with slim_control_ch API call with only one of
855 * the APIs specifying the commit flag to avoid reconfiguration being called too
856 * frequently. -EXFULL is returned if there is no space in TDM to reserve the
857 * bandwidth. -EBUSY is returned if reconfiguration is requested, but a request
858 * is already in progress.
859 */
860extern int slim_reservemsg_bw(struct slim_device *sb, u32 bw_bps, bool commit);
861
862/*
863 * slim_reconfigure_now: Request reconfiguration now.
864 * @sb: client handle
865 * This API does what commit flag in other scheduling APIs do.
866 * -EXFULL is returned if there is no space in TDM to reserve the
867 * bandwidth. -EBUSY is returned if reconfiguration request is already in
868 * progress.
869 */
870extern int slim_reconfigure_now(struct slim_device *sb);
871
872/*
Sagar Dharia33f34442011-08-08 16:22:03 -0600873 * slim_ctrl_clk_pause: Called by slimbus controller to request clock to be
874 * paused or woken up out of clock pause
875 * @ctrl: controller requesting bus to be paused or woken up
876 * @wakeup: Wakeup this controller from clock pause.
877 * @restart: Restart time value per spec used for clock pause. This value
878 * isn't used when controller is to be woken up.
879 * This API executes clock pause reconfiguration sequence if wakeup is false.
880 * If wakeup is true, controller's wakeup is called
881 * Slimbus clock is idle and can be disabled by the controller later.
882 */
883extern int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup,
884 u8 restart);
885
886/*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 * slim_driver_register: Client driver registration with slimbus
888 * @drv:Client driver to be associated with client-device.
889 * This API will register the client driver with the slimbus
890 * It is called from the driver's module-init function.
891 */
892extern int slim_driver_register(struct slim_driver *drv);
893
894/*
895 * slim_add_numbered_controller: Controller bring-up.
896 * @ctrl: Controller to be registered.
897 * A controller is registered with the framework using this API. ctrl->nr is the
898 * desired number with which slimbus framework registers the controller.
899 * Function will return -EBUSY if the number is in use.
900 */
901extern int slim_add_numbered_controller(struct slim_controller *ctrl);
902
903/*
904 * slim_del_controller: Controller tear-down.
905 * Controller added with the above API is teared down using this API.
906 */
907extern int slim_del_controller(struct slim_controller *ctrl);
908
909/*
910 * slim_add_device: Add a new device without register board info.
911 * @ctrl: Controller to which this device is to be added to.
912 * Called when device doesn't have an explicit client-driver to be probed, or
913 * the client-driver is a module installed dynamically.
914 */
915extern int slim_add_device(struct slim_controller *ctrl,
916 struct slim_device *sbdev);
917
918/* slim_remove_device: Remove the effect of slim_add_device() */
919extern void slim_remove_device(struct slim_device *sbdev);
920
921/*
922 * slim_assign_laddr: Assign logical address to a device enumerated.
923 * @ctrl: Controller with which device is enumerated.
924 * @e_addr: 6-byte elemental address of the device.
925 * @e_len: buffer length for e_addr
926 * @laddr: Return logical address.
927 * Called by controller in response to REPORT_PRESENT. Framework will assign
928 * a logical address to this enumeration address.
929 * Function returns -EXFULL to indicate that all logical addresses are already
930 * taken.
931 */
932extern int slim_assign_laddr(struct slim_controller *ctrl, const u8 *e_addr,
933 u8 e_len, u8 *laddr);
934
935/*
936 * slim_msg_response: Deliver Message response received from a device to the
937 * framework.
938 * @ctrl: Controller handle
939 * @reply: Reply received from the device
940 * @len: Length of the reply
941 * @tid: Transaction ID received with which framework can associate reply.
942 * Called by controller to inform framework about the response received.
943 * This helps in making the API asynchronous, and controller-driver doesn't need
944 * to manage 1 more table other than the one managed by framework mapping TID
945 * with buffers
946 */
947extern void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid,
948 u8 len);
949
950/*
951 * slim_busnum_to_ctrl: Map bus number to controller
952 * @busnum: Bus number
953 * Returns controller representing this bus number
954 */
955extern struct slim_controller *slim_busnum_to_ctrl(u32 busnum);
956
957/*
958 * slim_register_board_info: Board-initialization routine.
959 * @info: List of all devices on all controllers present on the board.
960 * @n: number of entries.
961 * API enumerates respective devices on corresponding controller.
962 * Called from board-init function.
963 */
964#ifdef CONFIG_SLIMBUS
965extern int slim_register_board_info(struct slim_boardinfo const *info,
966 unsigned n);
967#else
968int slim_register_board_info(struct slim_boardinfo const *info,
969 unsigned n)
970{
971 return 0;
972}
973#endif
974
975static inline void *slim_get_ctrldata(const struct slim_controller *dev)
976{
977 return dev_get_drvdata(&dev->dev);
978}
979
980static inline void slim_set_ctrldata(struct slim_controller *dev, void *data)
981{
982 dev_set_drvdata(&dev->dev, data);
983}
984
985static inline void *slim_get_devicedata(const struct slim_device *dev)
986{
987 return dev_get_drvdata(&dev->dev);
988}
989
990static inline void slim_set_clientdata(struct slim_device *dev, void *data)
991{
992 dev_set_drvdata(&dev->dev, data);
993}
994#endif /* _LINUX_SLIMBUS_H */