1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 2015-2016 Google Inc.
4  */
5 /*
6  * This is a special protocol for configuring communication over the
7  * I2S bus between the DSP on the MSM8994 and APBridgeA.  Therefore,
8  * we can predefine several low-level attributes of the communication
9  * because we know that they are supported.  In particular, the following
10  * assumptions are made:
11  *	- there are two channels (i.e., stereo)
12  *	- the low-level protocol is I2S as defined by Philips/NXP
13  *	- the DSP on the MSM8994 is the clock master for MCLK, BCLK, and WCLK
14  *	- WCLK changes on the falling edge of BCLK
15  *	- WCLK low for left channel; high for right channel
16  *	- TX data is sent on the falling edge of BCLK
17  *	- RX data is received/latched on the rising edge of BCLK
18  */
19 
20 #ifndef __AUDIO_APBRIDGEA_H
21 #define __AUDIO_APBRIDGEA_H
22 
23 #define AUDIO_APBRIDGEA_TYPE_SET_CONFIG			0x01
24 #define AUDIO_APBRIDGEA_TYPE_REGISTER_CPORT		0x02
25 #define AUDIO_APBRIDGEA_TYPE_UNREGISTER_CPORT		0x03
26 #define AUDIO_APBRIDGEA_TYPE_SET_TX_DATA_SIZE		0x04
27 							/* 0x05 unused */
28 #define AUDIO_APBRIDGEA_TYPE_PREPARE_TX			0x06
29 #define AUDIO_APBRIDGEA_TYPE_START_TX			0x07
30 #define AUDIO_APBRIDGEA_TYPE_STOP_TX			0x08
31 #define AUDIO_APBRIDGEA_TYPE_SHUTDOWN_TX		0x09
32 #define AUDIO_APBRIDGEA_TYPE_SET_RX_DATA_SIZE		0x0a
33 							/* 0x0b unused */
34 #define AUDIO_APBRIDGEA_TYPE_PREPARE_RX			0x0c
35 #define AUDIO_APBRIDGEA_TYPE_START_RX			0x0d
36 #define AUDIO_APBRIDGEA_TYPE_STOP_RX			0x0e
37 #define AUDIO_APBRIDGEA_TYPE_SHUTDOWN_RX		0x0f
38 
39 #define AUDIO_APBRIDGEA_PCM_FMT_8			BIT(0)
40 #define AUDIO_APBRIDGEA_PCM_FMT_16			BIT(1)
41 #define AUDIO_APBRIDGEA_PCM_FMT_24			BIT(2)
42 #define AUDIO_APBRIDGEA_PCM_FMT_32			BIT(3)
43 #define AUDIO_APBRIDGEA_PCM_FMT_64			BIT(4)
44 
45 #define AUDIO_APBRIDGEA_PCM_RATE_5512			BIT(0)
46 #define AUDIO_APBRIDGEA_PCM_RATE_8000			BIT(1)
47 #define AUDIO_APBRIDGEA_PCM_RATE_11025			BIT(2)
48 #define AUDIO_APBRIDGEA_PCM_RATE_16000			BIT(3)
49 #define AUDIO_APBRIDGEA_PCM_RATE_22050			BIT(4)
50 #define AUDIO_APBRIDGEA_PCM_RATE_32000			BIT(5)
51 #define AUDIO_APBRIDGEA_PCM_RATE_44100			BIT(6)
52 #define AUDIO_APBRIDGEA_PCM_RATE_48000			BIT(7)
53 #define AUDIO_APBRIDGEA_PCM_RATE_64000			BIT(8)
54 #define AUDIO_APBRIDGEA_PCM_RATE_88200			BIT(9)
55 #define AUDIO_APBRIDGEA_PCM_RATE_96000			BIT(10)
56 #define AUDIO_APBRIDGEA_PCM_RATE_176400			BIT(11)
57 #define AUDIO_APBRIDGEA_PCM_RATE_192000			BIT(12)
58 
59 #define AUDIO_APBRIDGEA_DIRECTION_TX			BIT(0)
60 #define AUDIO_APBRIDGEA_DIRECTION_RX			BIT(1)
61 
62 /* The I2S port is passed in the 'index' parameter of the USB request */
63 /* The CPort is passed in the 'value' parameter of the USB request */
64 
65 struct audio_apbridgea_hdr {
66 	__u8	type;
67 	__le16	i2s_port;
68 } __packed;
69 
70 struct audio_apbridgea_set_config_request {
71 	struct audio_apbridgea_hdr	hdr;
72 	__le32				format;	/* AUDIO_APBRIDGEA_PCM_FMT_* */
73 	__le32				rate;	/* AUDIO_APBRIDGEA_PCM_RATE_* */
74 	__le32				mclk_freq; /* XXX Remove? */
75 } __packed;
76 
77 struct audio_apbridgea_register_cport_request {
78 	struct audio_apbridgea_hdr	hdr;
79 	__le16				cport;
80 	__u8				direction;
81 } __packed;
82 
83 struct audio_apbridgea_unregister_cport_request {
84 	struct audio_apbridgea_hdr	hdr;
85 	__le16				cport;
86 	__u8				direction;
87 } __packed;
88 
89 struct audio_apbridgea_set_tx_data_size_request {
90 	struct audio_apbridgea_hdr	hdr;
91 	__le16				size;
92 } __packed;
93 
94 struct audio_apbridgea_prepare_tx_request {
95 	struct audio_apbridgea_hdr	hdr;
96 } __packed;
97 
98 struct audio_apbridgea_start_tx_request {
99 	struct audio_apbridgea_hdr	hdr;
100 	__le64				timestamp;
101 } __packed;
102 
103 struct audio_apbridgea_stop_tx_request {
104 	struct audio_apbridgea_hdr	hdr;
105 } __packed;
106 
107 struct audio_apbridgea_shutdown_tx_request {
108 	struct audio_apbridgea_hdr	hdr;
109 } __packed;
110 
111 struct audio_apbridgea_set_rx_data_size_request {
112 	struct audio_apbridgea_hdr	hdr;
113 	__le16				size;
114 } __packed;
115 
116 struct audio_apbridgea_prepare_rx_request {
117 	struct audio_apbridgea_hdr	hdr;
118 } __packed;
119 
120 struct audio_apbridgea_start_rx_request {
121 	struct audio_apbridgea_hdr	hdr;
122 } __packed;
123 
124 struct audio_apbridgea_stop_rx_request {
125 	struct audio_apbridgea_hdr	hdr;
126 } __packed;
127 
128 struct audio_apbridgea_shutdown_rx_request {
129 	struct audio_apbridgea_hdr	hdr;
130 } __packed;
131 
132 #endif /*__AUDIO_APBRIDGEA_H */
133