diff mbox

gbsim: Add GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS support

Message ID 1428020544-16453-1-git-send-email-john.stultz@linaro.org
State New
Headers show

Commit Message

John Stultz April 3, 2015, 12:22 a.m. UTC
Add I2S support for GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS
messages.

(This applies on top of the previous patches I sent out)
Cc: Alex Elder <alex.elder@linaro.org>
Cc: Greg Kroah-Hartman <greg@kroah.com>
Cc: mark greer <mark.greer@animalcreek.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 gbsim.h |   33 ++++++++++++++++++++++++
 i2s.c   |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)
diff mbox

Patch

diff --git a/gbsim.h b/gbsim.h
index 1751fb8..715d9cb 100644
--- a/gbsim.h
+++ b/gbsim.h
@@ -198,6 +198,37 @@  struct pwm_disable_req {
 	__u8	which;
 };
 
+struct gb_i2s_mgmt_configuration {
+        __le32  sample_frequency;
+        __u8    num_channels;
+        __u8    bytes_per_channel;
+        __u8    byte_order;
+        __u8    pad;
+        __le32  spatial_locations;
+        __le32  ll_protocol;
+        __u8    ll_bclk_role;
+        __u8    ll_wclk_role;
+        __u8    ll_wclk_polarity;
+        __u8    ll_wclk_change_edge;
+        __u8    ll_wclk_tx_edge;
+        __u8    ll_wclk_rx_edge;
+        __u8    ll_data_offset;
+        __u8    ll_pad;
+};
+
+struct gb_i2s_mgmt_get_supported_configurations_response {
+        __u8                                    config_count;
+        __u8                                    pad[3];
+        struct gb_i2s_mgmt_configuration        config[0];
+};
+
+/* get processing request delay has no payload */
+struct gb_i2s_mgmt_get_processing_delay_response {
+        __le32  microseconds;
+};
+
+
+
 /* Ops */
 struct op_msg {
 	struct op_header	header;
@@ -229,6 +260,8 @@  struct op_msg {
                 struct pwm_polarity_req			pwm_pol_req;
                 struct pwm_enable_req			pwm_enb_req;
                 struct pwm_disable_req			pwm_dis_req;
+		struct gb_i2s_mgmt_get_supported_configurations_response i2s_mgmt_get_supported_conf_resp;
+		struct gb_i2s_mgmt_get_processing_delay_response i2s_mgmt_get_processing_delay_res;
 	};
 };
 
diff --git a/i2s.c b/i2s.c
index d4d3ce9..77a220a 100644
--- a/i2s.c
+++ b/i2s.c
@@ -28,6 +28,58 @@ 
 #define GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT               0x08
 #define GB_I2S_MGMT_TYPE_REPORT_EVENT                   0x09
 
+#ifndef BIT
+#define BIT(n) (1UL << (n))
+#endif
+#define GB_I2S_MGMT_BYTE_ORDER_NA                       BIT(0)
+#define GB_I2S_MGMT_BYTE_ORDER_BE                       BIT(1)
+#define GB_I2S_MGMT_BYTE_ORDER_LE                       BIT(2)
+
+#define GB_I2S_MGMT_SPATIAL_LOCATION_FL                 BIT(0)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_FR                 BIT(1)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_FC                 BIT(2)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_LFE                BIT(3)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_BL                 BIT(4)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_BR                 BIT(5)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_FLC                BIT(6)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_FRC                BIT(7)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_C                  BIT(8) /* BC in USB */
+#define GB_I2S_MGMT_SPATIAL_LOCATION_SL                 BIT(9)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_SR                 BIT(10)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TC                 BIT(11)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TFL                BIT(12)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TFC                BIT(13)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TFR                BIT(14)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TBL                BIT(15)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TBC                BIT(16)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TBR                BIT(17)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TFLC               BIT(18)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TFRC               BIT(19)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_LLFE               BIT(20)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_RLFE               BIT(21)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TSL                BIT(22)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_TSR                BIT(23)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_BC                 BIT(24)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_BLC                BIT(25)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_BRC                BIT(26)
+#define GB_I2S_MGMT_SPATIAL_LOCATION_RD                 BIT(31)
+
+#define GB_I2S_MGMT_PROTOCOL_PCM                        BIT(0)
+#define GB_I2S_MGMT_PROTOCOL_I2S                        BIT(1)
+#define GB_I2S_MGMT_PROTOCOL_LR_STEREO                  BIT(2)
+
+#define GB_I2S_MGMT_ROLE_MASTER                         BIT(0)
+#define GB_I2S_MGMT_ROLE_SLAVE                          BIT(1)
+
+#define GB_I2S_MGMT_POLARITY_NORMAL                     BIT(0)
+#define GB_I2S_MGMT_POLARITY_REVERSED                   BIT(1)
+
+#define GB_I2S_MGMT_EDGE_RISING                         BIT(0)
+#define GB_I2S_MGMT_EDGE_FALLING                        BIT(1)
+
+#define CONFIG_COUNT_MAX 32
+
+
 #define GB_I2S_DATA_TYPE_SEND_DATA			0x02
 
 void i2s_mgmt_handler(__u8 *rbuf, size_t size)
@@ -51,6 +103,42 @@  void i2s_mgmt_handler(__u8 *rbuf, size_t size)
 	oph = (struct op_header *)&op_req->header;
 
 	switch (oph->type) {
+	case GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS:
+		sz = sizeof(struct op_header) +
+			sizeof(struct gb_i2s_mgmt_get_supported_configurations_response) +
+			sizeof(struct gb_i2s_mgmt_configuration) * CONFIG_COUNT_MAX;
+
+		printf("JDB: sz=%i\n", sz);
+		op_rsp->header.size = htole16((__u16)sz);
+		op_rsp->header.id = oph->id;
+
+		op_rsp->header.type = OP_RESPONSE | GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS;
+		op_rsp->header.result = PROTOCOL_STATUS_SUCCESS;
+		
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config_count = 1;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].sample_frequency = 48000; 
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].num_channels = 2;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].bytes_per_channel = 2;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].byte_order = GB_I2S_MGMT_BYTE_ORDER_LE;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].spatial_locations = GB_I2S_MGMT_SPATIAL_LOCATION_FL |
+											GB_I2S_MGMT_SPATIAL_LOCATION_FR;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_protocol = GB_I2S_MGMT_PROTOCOL_I2S;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_bclk_role = GB_I2S_MGMT_ROLE_MASTER;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_wclk_role = GB_I2S_MGMT_ROLE_MASTER;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_wclk_polarity = GB_I2S_MGMT_POLARITY_NORMAL;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_wclk_change_edge = GB_I2S_MGMT_EDGE_FALLING;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_wclk_tx_edge = GB_I2S_MGMT_EDGE_FALLING;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_wclk_rx_edge = GB_I2S_MGMT_EDGE_RISING;
+		op_rsp->i2s_mgmt_get_supported_conf_resp.config[0].ll_data_offset = 1;
+
+
+
+		gbsim_debug("Module %d -> AP CPort %d I2S GET_CONFIGURATION response\n  ",
+			    cport_to_module_id(cport_req->cport), cport_rsp->cport);
+		if (verbose)
+			gbsim_dump((__u8 *)op_rsp, op_rsp->header.size);
+		write(cport_in, cport_rsp, op_rsp->header.size + 1);
+		break;
 	case GB_I2S_MGMT_TYPE_SET_CONFIGURATION:
 		sz = sizeof(struct op_header);
 		op_rsp->header.size = htole16((__u16)sz);