blob: fc4d20b1fa6bac520f9121c24d815e1092ca36db [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/**
2 * TSIF driver
3 *
4 * Kernel API
5 *
6 * Copyright (c) 2009-2010, Code Aurora Forum. All rights
7 * reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 and
11 * only version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19#ifndef _TSIF_API_H_
20#define _TSIF_API_H_
21/**
22 * Theory of operation
23 *
24 * TSIF driver maintains internal cyclic data buffer where
25 * received TSIF packets are stored. Size of buffer, in packets,
26 * and its address, may be obtained by tsif_get_info().
27 *
28 * TSIF stream delivered to the client that should register with
29 * TSIF driver using tsif_attach()
30 *
31 * Producer-consumer pattern used. TSIF driver act as producer,
32 * writing data to the buffer; clientis consumer.
33 * 2 indexes maintained by the TSIF driver:
34 * - wi (write index) points to the next item to be written by
35 * TSIF
36 * - ri (read index) points to the next item available for read
37 * by the client.
38 * Write index advanced by the TSIF driver when new data
39 * received;
40 * Read index advanced only when client tell so to the TSIF
41 * driver by tsif_reclaim_packets()
42 *
43 * Consumer may directly access data TSIF buffer between ri and
44 * wi. When ri==wi, buffer is empty.
45 *
46 * TSIF driver notifies client about any change by calling
47 * notify function. Client should use tsif_get_state() to query
48 * new state.
49 */
50
51/* bytes in TSIF packet. not customizable */
52#define TSIF_PKT_SIZE (192)
53
54/**
55 * tsif_pkt_status - get TSIF packet status
56 *
57 * @pkt: TSIF packet location
58 *
59 * Return last DWORD of packet, containing status.
60 * Status dword consists of:
61 * - 3 low bytes TTS
62 * - 1 byte (last byte of packet) with status bits
63 */
64static inline u32 tsif_pkt_status(void *pkt)
65{
66 u32 *x = pkt;
67 return x[TSIF_PKT_SIZE / sizeof(u32) - 1];
68}
69
70/**
71 * Status dword parts for status returned by @tsif_pkt_status
72 */
73#define TSIF_STATUS_TTS(x) ((x) & 0xffffff)
74#define TSIF_STATUS_VALID(x) ((x) & (1<<24))
75#define TSIF_STATUS_FIRST(x) ((x) & (1<<25))
76#define TSIF_STATUS_OVFLW(x) ((x) & (1<<26))
77#define TSIF_STATUS_ERROR(x) ((x) & (1<<27))
78#define TSIF_STATUS_NULL(x) ((x) & (1<<28))
79#define TSIF_STATUS_TIMEO(x) ((x) & (1<<30))
80
81/**
82 * enum tsif_state - TSIF device state
83 * @tsif_state_stopped: Idle state, data acquisition not running
84 * @tsif_state_running: Data acquisition in progress
85 * @tsif_state_flushing: Device is flushing
86 *
87 * State transition diagram:
88 *
89 * init -> tsif_state_stopped
90 *
91 * tsif_state_stopped:
92 * - open -> tsif_state_running
93 *
94 * tsif_state_running:
95 * - close -> tsif_state_flushing
96 *
97 * tsif_state_flushing:
98 * - flushed -> tsif_state_stopped
99 */
100enum tsif_state {
101 tsif_state_stopped = 0,
102 tsif_state_running = 1,
103 tsif_state_flushing = 2,
104 tsif_state_error = 3,
105};
106
107/**
Joel Nider5578bdb2011-08-12 09:37:11 +0300108 * tsif_get_active - return active tsif hardware instance
109 *
110 * Return TSIF instance to use (selected by CONFIG_MSM_USE_TSIF1)
111 */
112int tsif_get_active(void);
113
114/**
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700115 * tsif_attach - Attach to the device.
116 * @id: TSIF device ID, used to identify TSIF instance.
117 * @notify: client callback, called when
118 * any client visible TSIF state changed.
119 * This includes new data available and device state change
120 * @data: client data, will be passed to @notify
121 *
122 * Return TSIF cookie or error code
123 *
124 * Should be called prior to any other tsif_XXX function.
125 */
126void *tsif_attach(int id, void (*notify)(void *client_data), void *client_data);
127/**
128 * tsif_detach - detach from device
129 * @cookie: TSIF cookie previously obtained with tsif_attach()
130 */
131void tsif_detach(void *cookie);
132/**
133 * tsif_get_info - get data buffer info
134 * @cookie: TSIF cookie previously obtained with tsif_attach()
135 * @pdata: if not NULL, TSIF data buffer will be stored there
136 * @psize: if not NULL, TSIF data buffer size, in packets,
137 * will be stored there
138 *
139 * Data buffer information should be queried after each tsif_start() before
140 * using data; since data buffer will be re-allocated on tsif_start()
141 */
142void tsif_get_info(void *cookie, void **pdata, int *psize);
143/**
144 * tsif_set_mode - set TSIF mode
145 * @cookie: TSIF cookie previously obtained with tsif_attach()
146 * @mode: desired mode of operation
147 *
148 * Return error code
149 *
150 * Mode may be changed only when TSIF device is stopped.
151 */
152int tsif_set_mode(void *cookie, int mode);
153/**
154 * tsif_set_time_limit - set TSIF time limit
155 * @cookie: TSIF cookie previously obtained with tsif_attach()
156 * @value: desired time limit, 0 to disable
157 *
158 * Return error code
159 *
160 * Time limit may be changed only when TSIF device is stopped.
161 */
162int tsif_set_time_limit(void *cookie, u32 value);
163/**
164 * tsif_set_buf_config - configure data buffer
165 *
166 * @cookie: TSIF cookie previously obtained with tsif_attach()
167 * @pkts_in_chunk: requested number of packets per chunk
168 * @chunks_in_buf: requested number of chunks in buffer
169 *
170 * Return error code
171 *
172 * Parameter selection criteria:
173 *
174 * - @pkts_in_chunk defines size of DMA transfer and, in turn, time between
175 * consecutive DMA transfers. Increase @pkts_in_chunk reduces chance for
176 * hardware overflow. If TSIF stats reports overflows, increase it.
177 *
178 * - @chunks_in_buf * @pkts_in_chunk defines total buffer size. Increase this
179 * parameter if client latency is large and TSIF reports "soft drop" in its
180 * stats
181 */
182int tsif_set_buf_config(void *cookie, u32 pkts_in_chunk, u32 chunks_in_buf);
183/**
184 * tsif_get_state - query current data buffer information
185 * @cookie: TSIF cookie previously obtained with tsif_attach()
186 * @ri: if not NULL, read index will be stored here
187 * @wi: if not NULL, write index will be stored here
188 * @state: if not NULL, state will be stored here
189 */
190void tsif_get_state(void *cookie, int *ri, int *wi, enum tsif_state *state);
191/**
192 * tsif_start - start data acquisition
193 * @cookie: TSIF cookie previously obtained with tsif_attach()
194 *
195 * Return error code
196 */
197int tsif_start(void *cookie);
198/**
199 * tsif_stop - stop data acquisition
200 * @cookie: TSIF cookie previously obtained with tsif_attach()
201 *
202 * Data buffer allocated during this function call; thus client should
203 * query data buffer info using tsif_get_info() and reset its data pointers.
204 */
205void tsif_stop(void *cookie);
206/**
207 * tsif_reclaim_packets - inform that buffer space may be reclaimed
208 * @cookie: TSIF cookie previously obtained with tsif_attach()
209 * @ri: new value for read index
210 */
211void tsif_reclaim_packets(void *cookie, int ri);
212
213#endif /* _TSIF_API_H_ */
214