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