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