greybus: es2: fix cport-count error handling
[cascardo/linux.git] / drivers / staging / greybus / audio_apbridgea.h
1 /**
2  * Copyright (c) 2015-2016 Google Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 /*
29  * This is a special protocol for configuring communication over the
30  * I2S bus between the DSP on the MSM8994 and APBridgeA.  Therefore,
31  * we can predefine several low-level attributes of the communication
32  * because we know that they are supported.  In particular, the following
33  * assumptions are made:
34  *      - there are two channels (i.e., stereo)
35  *      - the low-level protocol is I2S as defined by Philips/NXP
36  *      - the DSP on the MSM8994 is the clock master for MCLK, BCLK, and WCLK
37  *      - WCLK changes on the falling edge of BCLK
38  *      - WCLK low for left channel; high for right channel
39  *      - TX data is sent on the falling edge of BCLK
40  *      - RX data is received/latched on the rising edge of BCLK
41  */
42
43 #ifndef __AUDIO_APBRIDGEA_H
44 #define __AUDIO_APBRIDGEA_H
45
46 #define AUDIO_APBRIDGEA_TYPE_SET_CONFIG                 0x01
47 #define AUDIO_APBRIDGEA_TYPE_REGISTER_CPORT             0x02
48 #define AUDIO_APBRIDGEA_TYPE_UNREGISTER_CPORT           0x03
49 #define AUDIO_APBRIDGEA_TYPE_SET_TX_DATA_SIZE           0x04
50 #define AUDIO_APBRIDGEA_TYPE_GET_TX_DELAY               0x05
51 #define AUDIO_APBRIDGEA_TYPE_START_TX                   0x06
52 #define AUDIO_APBRIDGEA_TYPE_STOP_TX                    0x07
53 #define AUDIO_APBRIDGEA_TYPE_SET_RX_DATA_SIZE           0x08
54 #define AUDIO_APBRIDGEA_TYPE_GET_RX_DELAY               0x09
55 #define AUDIO_APBRIDGEA_TYPE_START_RX                   0x0a
56 #define AUDIO_APBRIDGEA_TYPE_STOP_RX                    0x0b
57
58 #define AUDIO_APBRIDGEA_PCM_FMT_8                       BIT(0)
59 #define AUDIO_APBRIDGEA_PCM_FMT_16                      BIT(1)
60 #define AUDIO_APBRIDGEA_PCM_FMT_24                      BIT(2)
61 #define AUDIO_APBRIDGEA_PCM_FMT_32                      BIT(3)
62 #define AUDIO_APBRIDGEA_PCM_FMT_64                      BIT(4)
63
64 #define AUDIO_APBRIDGEA_PCM_RATE_5512                   BIT(0)
65 #define AUDIO_APBRIDGEA_PCM_RATE_8000                   BIT(1)
66 #define AUDIO_APBRIDGEA_PCM_RATE_11025                  BIT(2)
67 #define AUDIO_APBRIDGEA_PCM_RATE_16000                  BIT(3)
68 #define AUDIO_APBRIDGEA_PCM_RATE_22050                  BIT(4)
69 #define AUDIO_APBRIDGEA_PCM_RATE_32000                  BIT(5)
70 #define AUDIO_APBRIDGEA_PCM_RATE_44100                  BIT(6)
71 #define AUDIO_APBRIDGEA_PCM_RATE_48000                  BIT(7)
72 #define AUDIO_APBRIDGEA_PCM_RATE_64000                  BIT(8)
73 #define AUDIO_APBRIDGEA_PCM_RATE_88200                  BIT(9)
74 #define AUDIO_APBRIDGEA_PCM_RATE_96000                  BIT(10)
75 #define AUDIO_APBRIDGEA_PCM_RATE_176400                 BIT(11)
76 #define AUDIO_APBRIDGEA_PCM_RATE_192000                 BIT(12)
77
78 /* The I2S port is passed in the 'index' parameter of the USB request */
79 /* The CPort is passed in the 'value' parameter of the USB request */
80
81 struct audio_apbridgea_hdr {
82         __u8    type;
83         __le16  i2s_port;
84         __u8    data[0];
85 } __packed;
86
87 struct audio_apbridgea_set_config_request {
88         struct audio_apbridgea_hdr      hdr;
89         __le32                          format; /* AUDIO_APBRIDGEA_PCM_FMT_* */
90         __le32                          rate;   /* AUDIO_APBRIDGEA_PCM_RATE_* */
91         __le32                          mclk_freq; /* XXX Remove? */
92 } __packed;
93
94 struct audio_apbridgea_register_cport_request {
95         struct audio_apbridgea_hdr      hdr;
96         __le16                          cport;
97 } __packed;
98
99 struct audio_apbridgea_unregister_cport_request {
100         struct audio_apbridgea_hdr      hdr;
101         __le16                          cport;
102 } __packed;
103
104 struct audio_apbridgea_set_tx_data_size_request {
105         struct audio_apbridgea_hdr      hdr;
106         __le16                          size;
107 } __packed;
108
109 struct audio_apbridgea_get_tx_delay_request {
110         struct audio_apbridgea_hdr      hdr;
111 } __packed;
112
113 struct audio_apbridgea_get_tx_delay_response {
114         struct audio_apbridgea_hdr      hdr;
115         __le16                          delay;
116 } __packed;
117
118 struct audio_apbridgea_start_tx_request {
119         struct audio_apbridgea_hdr      hdr;
120         __le64                          timestamp;
121 } __packed;
122
123 struct audio_apbridgea_stop_tx_request {
124         struct audio_apbridgea_hdr      hdr;
125 } __packed;
126
127 struct audio_apbridgea_set_rx_data_size_request {
128         struct audio_apbridgea_hdr      hdr;
129         __le16                          size;
130 } __packed;
131
132 struct audio_apbridgea_get_rx_delay_request {
133         struct audio_apbridgea_hdr      hdr;
134 } __packed;
135
136 struct audio_apbridgea_get_rx_delay_response {
137         struct audio_apbridgea_hdr      hdr;
138         __le16                          delay;
139 } __packed;
140
141 struct audio_apbridgea_start_rx_request {
142         struct audio_apbridgea_hdr      hdr;
143 } __packed;
144
145 struct audio_apbridgea_stop_rx_request {
146         struct audio_apbridgea_hdr      hdr;
147 } __packed;
148
149 #endif /*__AUDIO_APBRIDGEA_H */