blob: fa2cd627c91d1c39953c3f394e6c829495e6de34 [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/* Copyright (c) 2011-2014, The Linux Foundation. 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 __Q6_USM_H__
14#define __Q6_USM_H__
15
Laxminath Kasam605b42f2017-08-01 22:02:15 +053016#include <ipc/apr_us.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053017
18#define Q6USM_EVENT_UNDEF 0
19#define Q6USM_EVENT_READ_DONE 1
20#define Q6USM_EVENT_WRITE_DONE 2
21#define Q6USM_EVENT_SIGNAL_DETECT_RESULT 3
22
23/* cyclic buffer with 1 gap support */
24#define USM_MIN_BUF_CNT 3
25
26#define FORMAT_USPS_EPOS 0x00000000
27#define FORMAT_USRAW 0x00000001
28#define FORMAT_USPROX 0x00000002
29#define FORMAT_USGES_SYNC 0x00000003
30#define FORMAT_USRAW_SYNC 0x00000004
31#define INVALID_FORMAT 0xffffffff
32
33#define IN 0x000
34#define OUT 0x001
35
36#define USM_WRONG_TOKEN 0xffffffff
37#define USM_UNDEF_TOKEN 0xfffffffe
38
39#define CMD_CLOSE 0x0004
40
41/* bit 0:1 represents priority of stream */
42#define STREAM_PRIORITY_NORMAL 0x0000
43#define STREAM_PRIORITY_LOW 0x0001
44#define STREAM_PRIORITY_HIGH 0x0002
45
46/* bit 4 represents META enable of encoded data buffer */
47#define BUFFER_META_ENABLE 0x0010
48
49struct us_port_data {
50 dma_addr_t phys;
51 /* cyclic region of buffers with 1 gap */
52 void *data;
53 /* number of buffers in the region */
54 uint32_t buf_cnt;
55 /* size of buffer */
56 size_t buf_size;
57 /* write index */
58 uint32_t dsp_buf;
59 /* read index */
60 uint32_t cpu_buf;
61 /* expected token from dsp */
62 uint32_t expected_token;
63 /* read or write locks */
64 struct mutex lock;
65 spinlock_t dsp_lock;
66 /* ION memory handle */
67 struct ion_handle *handle;
68 /* ION memory client */
69 struct ion_client *client;
70 /* extended parameters, related to q6 variants */
71 void *ext;
72 /* physical address of parameter buffer */
73 dma_addr_t param_phys;
74 /* buffer which stores the parameter data */
75 void *param_buf;
76 /* size of parameter buffer */
77 uint32_t param_buf_size;
78 /* parameter buffer memory handle */
79 void *param_buf_mem_handle;
80 /* ION memory handle for parameter buffer */
81 struct ion_handle *param_handle;
82 /* ION memory client for parameter buffer */
83 struct ion_client *param_client;
84};
85
86struct us_client {
87 int session;
88 /* idx:1 out port, 0: in port*/
89 struct us_port_data port[2];
90
91 struct apr_svc *apr;
92 struct mutex cmd_lock;
93
94 atomic_t cmd_state;
95 atomic_t eos_state;
96 wait_queue_head_t cmd_wait;
97
98 void (*cb)(uint32_t, uint32_t, uint32_t *, void *);
99 void *priv;
100};
101
102int q6usm_run(struct us_client *usc, uint32_t flags,
103 uint32_t msw_ts, uint32_t lsw_ts);
104int q6usm_cmd(struct us_client *usc, int cmd);
105int q6usm_us_client_buf_alloc(unsigned int dir, struct us_client *usc,
106 unsigned int bufsz, unsigned int bufcnt);
107int q6usm_us_param_buf_alloc(unsigned int dir, struct us_client *usc,
108 unsigned int bufsz);
109int q6usm_enc_cfg_blk(struct us_client *usc, struct us_encdec_cfg *us_cfg);
110int q6usm_dec_cfg_blk(struct us_client *usc, struct us_encdec_cfg *us_cfg);
111int q6usm_read(struct us_client *usc, uint32_t read_ind);
112struct us_client *q6usm_us_client_alloc(
113 void (*cb)(uint32_t, uint32_t, uint32_t *, void *),
114 void *priv);
115int q6usm_open_read(struct us_client *usc, uint32_t format);
116void q6usm_us_client_free(struct us_client *usc);
117uint32_t q6usm_get_virtual_address(int dir, struct us_client *usc,
118 struct vm_area_struct *vms);
119int q6usm_open_write(struct us_client *usc, uint32_t format);
120int q6usm_write(struct us_client *usc, uint32_t write_ind);
121bool q6usm_is_write_buf_full(struct us_client *usc, uint32_t *free_region);
122int q6usm_set_us_detection(struct us_client *usc,
123 struct usm_session_cmd_detect_info *detect_info,
124 uint16_t detect_info_size);
125int q6usm_set_us_stream_param(int dir, struct us_client *usc,
126 uint32_t module_id, uint32_t param_id, uint32_t buf_size);
127int q6usm_get_us_stream_param(int dir, struct us_client *usc,
128 uint32_t module_id, uint32_t param_id, uint32_t buf_size);
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530129int q6usm_init(void);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530130
131#endif /* __Q6_USM_H__ */