From patchwork Tue Mar 31 23:55:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 46606 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1EEE92159A for ; Tue, 31 Mar 2015 23:55:47 +0000 (UTC) Received: by lbbug6 with SMTP id ug6sf6853887lbb.3 for ; Tue, 31 Mar 2015 16:55:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=oMVzIrcVLVTfA9Rv9eI06TFRwYqmZ+YW+3dwK/E9NDs=; b=CIJ12apShk0Q2HrdUfP5gMHzpRrt3/9CEKjNmDws9e1CHYrLEvaEcWq3+Sa/m/p21k fF3CQRvw1DLwMemSFT+GRJrgQC7ussLZwRzU1aoSSw7j3N0Kn//aZgAEYKy1cTiZix4R s7wFR34EIECbvJSUnSYVKB95kcaDXiigzpNEPD0T/8S92Syp8kHy0EUBqMBvmhUhHXRF 994F5vlFPQup1ZLwcVk3rUMm23Mf7iacJcW6mG5KwUe2VUCGwE8xF3d5oHTdMQp1UdxO SZ6MOC9ISReOguWqYgaNU3QObnO2JshIS0JNPvfNXH7sAp62kMHZohgg5t6uDEJaMJkD +ZAg== X-Gm-Message-State: ALoCoQnJ6Bk68JzMtUTlCuRwV0SF4fmdXvs7D2bOst+d8VTkaRHUrxXv7LrM+0LIKeMBCCGC7TNt X-Received: by 10.152.8.108 with SMTP id q12mr4808371laa.6.1427846145983; Tue, 31 Mar 2015 16:55:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.4 with SMTP id ls4ls4337lac.73.gmail; Tue, 31 Mar 2015 16:55:45 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr32517380lak.111.1427846145565; Tue, 31 Mar 2015 16:55:45 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id r11si96166lal.168.2015.03.31.16.55.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Mar 2015 16:55:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by lagg8 with SMTP id g8so24677870lag.1 for ; Tue, 31 Mar 2015 16:55:45 -0700 (PDT) X-Received: by 10.152.36.169 with SMTP id r9mr10026634laj.29.1427846145201; Tue, 31 Mar 2015 16:55:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.57.201 with SMTP id k9csp306968lbq; Tue, 31 Mar 2015 16:55:44 -0700 (PDT) X-Received: by 10.67.4.132 with SMTP id ce4mr36254601pad.37.1427846143381; Tue, 31 Mar 2015 16:55:43 -0700 (PDT) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com. [209.85.220.46]) by mx.google.com with ESMTPS id rw5si163056pab.215.2015.03.31.16.55.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Mar 2015 16:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.46 as permitted sender) client-ip=209.85.220.46; Received: by patj18 with SMTP id j18so34306378pat.2 for ; Tue, 31 Mar 2015 16:55:42 -0700 (PDT) X-Received: by 10.66.169.137 with SMTP id ae9mr72325575pac.7.1427846142406; Tue, 31 Mar 2015 16:55:42 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id d12sm91159pbu.4.2015.03.31.16.55.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Mar 2015 16:55:41 -0700 (PDT) From: John Stultz To: projectara-software-dev Cc: John Stultz , Alex Elder , Greg Kroah-Hartman , mark greer Subject: [PATCH] gbsim: Add initial i2s support. Date: Tue, 31 Mar 2015 16:55:38 -0700 Message-Id: <1427846138-19824-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add initial i2s support. This only supports I2S SEND_DATA and some simple I2S mgmt calls. More interesting mgmt calls that actually provide data will be implemented in later patches. Cc: Alex Elder Cc: Greg Kroah-Hartman Cc: mark greer Signed-off-by: John Stultz --- Makefile | 2 +- cport.c | 13 +++++ gbsim.h | 4 ++ i2s.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 1 + 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 i2s.c diff --git a/Makefile b/Makefile index 122530b..14f468f 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ INCS = -I$(GBDIR) LFLAGS = LIBS = -lpthread -lusbg -lsoc -SRCS = main.c gadget.c functionfs.c inotify.c manifest.c cport.c i2c.c gpio.c pwm.c +SRCS = main.c gadget.c functionfs.c inotify.c manifest.c cport.c i2c.c gpio.c pwm.c i2s.c OBJS = $(SRCS:.c=.o) MAIN = gbsim diff --git a/cport.c b/cport.c index 71dbcdb..f63a9c1 100644 --- a/cport.c +++ b/cport.c @@ -31,6 +31,12 @@ static char *get_protocol(__le16 id) return "I2C"; case GREYBUS_PROTOCOL_PWM: return "PWM"; + case GREYBUS_PROTOCOL_I2S_MGMT: + return "I2S_MGMT"; + case GREYBUS_PROTOCOL_I2S_RECEIVER: + return "I2S_RECEIVER"; + case GREYBUS_PROTOCOL_I2S_TRANSMITTER: + return "I2S_TRANSMITTER"; } } } @@ -53,6 +59,13 @@ static void exec_subdev_handler(__le16 id, __u8 *rbuf, size_t size) case GREYBUS_PROTOCOL_PWM: pwm_handler(rbuf, size); break; + case GREYBUS_PROTOCOL_I2S_MGMT: + i2s_mgmt_handler(rbuf, size); + break; + case GREYBUS_PROTOCOL_I2S_RECEIVER: + case GREYBUS_PROTOCOL_I2S_TRANSMITTER: + i2s_data_handler(rbuf, size); + break; default: gbsim_error("subdev handler not found for cport %d\n", id); diff --git a/gbsim.h b/gbsim.h index ef9c33c..1751fb8 100644 --- a/gbsim.h +++ b/gbsim.h @@ -286,4 +286,8 @@ void i2c_init(void); void pwm_handler(__u8 *, size_t); void pwm_init(void); +void i2s_mgmt_handler(__u8 *, size_t); +void i2s_data_handler(__u8 *, size_t); +void i2s_init(void); + bool manifest_parse(void *data, size_t size); diff --git a/i2s.c b/i2s.c new file mode 100644 index 0000000..d4d3ce9 --- /dev/null +++ b/i2s.c @@ -0,0 +1,177 @@ +/* + * Greybus Simulator + * + * Copyright 2014, 2015 Google Inc. + * Copyright 2014, 2015 Linaro Ltd. + * + * Provided under the three clause BSD license found in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gbsim.h" + +#define GB_I2S_MGMT_TYPE_PROTOCOL_VERSION 0x01 +#define GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS 0x02 +#define GB_I2S_MGMT_TYPE_SET_CONFIGURATION 0x03 +#define GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE 0x04 +#define GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY 0x05 +#define GB_I2S_MGMT_TYPE_SET_START_DELAY 0x06 +#define GB_I2S_MGMT_TYPE_ACTIVATE_CPORT 0x07 +#define GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT 0x08 +#define GB_I2S_MGMT_TYPE_REPORT_EVENT 0x09 + +#define GB_I2S_DATA_TYPE_SEND_DATA 0x02 + +void i2s_mgmt_handler(__u8 *rbuf, size_t size) +{ + struct op_header *oph; + char *tbuf; + struct op_msg *op_req, *op_rsp; + struct cport_msg *cport_req, *cport_rsp; + size_t sz; + + tbuf = malloc(4 * 1024); + if (!tbuf) { + gbsim_error("failed to allocate i2s handler tx buf\n"); + return; + } + cport_req = (struct cport_msg *)rbuf; + op_req = (struct op_msg *)cport_req->data; + cport_rsp = (struct cport_msg *)tbuf; + cport_rsp->cport = cport_req->cport; + op_rsp = (struct op_msg *)cport_rsp->data; + oph = (struct op_header *)&op_req->header; + + switch (oph->type) { + case GB_I2S_MGMT_TYPE_SET_CONFIGURATION: + sz = sizeof(struct op_header); + op_rsp->header.size = htole16((__u16)sz); + op_rsp->header.id = oph->id; + + op_rsp->header.type = OP_RESPONSE | GB_I2S_MGMT_TYPE_SET_CONFIGURATION; + op_rsp->header.result = PROTOCOL_STATUS_SUCCESS; + + gbsim_debug("Module %d -> AP CPort %d I2S SET_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_SAMPLES_PER_MESSAGE: + sz = sizeof(struct op_header); + op_rsp->header.size = htole16((__u16)sz); + op_rsp->header.id = oph->id; + + op_rsp->header.type = OP_RESPONSE | GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE; + op_rsp->header.result = PROTOCOL_STATUS_SUCCESS; + + gbsim_debug("Module %d -> AP CPort %d I2S SET_SAMPLES_PER_MESSAGE 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_START_DELAY: + sz = sizeof(struct op_header); + op_rsp->header.size = htole16((__u16)sz); + op_rsp->header.id = oph->id; + + op_rsp->header.type = OP_RESPONSE | GB_I2S_MGMT_TYPE_SET_START_DELAY; + op_rsp->header.result = PROTOCOL_STATUS_SUCCESS; + + gbsim_debug("Module %d -> AP CPort %d I2S SET_START_DELAY 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_ACTIVATE_CPORT: + sz = sizeof(struct op_header); + op_rsp->header.size = htole16((__u16)sz); + op_rsp->header.id = oph->id; + + op_rsp->header.type = OP_RESPONSE | GB_I2S_MGMT_TYPE_ACTIVATE_CPORT; + op_rsp->header.result = PROTOCOL_STATUS_SUCCESS; + + gbsim_debug("Module %d -> AP CPort %d I2S ACTIVATE_CPORT 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_DEACTIVATE_CPORT: + sz = sizeof(struct op_header); + op_rsp->header.size = htole16((__u16)sz); + op_rsp->header.id = oph->id; + + op_rsp->header.type = OP_RESPONSE | GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT; + op_rsp->header.result = PROTOCOL_STATUS_SUCCESS; + + gbsim_debug("Module %d -> AP CPort %d I2S DEACTIVATE_CPORT 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; + default: + gbsim_error("i2s mgmt operation type %02x not supported\n", oph->type); + } + + free(tbuf); +} + + +void i2s_data_handler(__u8 *rbuf, size_t size) +{ + struct op_header *oph; + char *tbuf; + struct op_msg *op_req, *op_rsp; + struct cport_msg *cport_req, *cport_rsp; + size_t sz; + + tbuf = malloc(4 * 1024); + if (!tbuf) { + gbsim_error("failed to allocate i2s handler tx buf\n"); + return; + } + cport_req = (struct cport_msg *)rbuf; + op_req = (struct op_msg *)cport_req->data; + cport_rsp = (struct cport_msg *)tbuf; + cport_rsp->cport = cport_req->cport; + op_rsp = (struct op_msg *)cport_rsp->data; + oph = (struct op_header *)&op_req->header; + + switch (oph->type) { + case GB_I2S_DATA_TYPE_SEND_DATA: + sz = sizeof(struct op_header); + op_rsp->header.size = htole16((__u16)sz); + op_rsp->header.id = oph->id; + + op_rsp->header.type = OP_RESPONSE | GB_I2S_DATA_TYPE_SEND_DATA; + op_rsp->header.result = PROTOCOL_STATUS_SUCCESS; + + gbsim_debug("Module %d -> AP CPort %d I2S SEND_DATA 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; + default: + gbsim_error("i2s data operation type %02x not supported\n", oph->type); + } + + free(tbuf); +} + +void i2s_init(void) +{ + +} diff --git a/main.c b/main.c index b876421..e078332 100644 --- a/main.c +++ b/main.c @@ -111,6 +111,7 @@ int main(int argc, char *argv[]) /* Protocol handlers */ gpio_init(); i2c_init(); + i2s_init(); ret = functionfs_loop();