From patchwork Tue Mar 31 05:06:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 46566 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2A1532159A for ; Tue, 31 Mar 2015 05:06:40 +0000 (UTC) Received: by wibgr10 with SMTP id gr10sf1656200wib.2 for ; Mon, 30 Mar 2015 22:06:39 -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=134xO/Fkp4H2NLZ/mCBCYOwRIFJznrG7c7EP7g8Qbac=; b=dZ3YZ3l60EiIWx5SarZgMWGs/813XH6fO4Vdwsha9MjJVDCxqdQz/QpWkLom+8rfC0 qEcsxndLuHvdlSDqjVsdnWvXJ/eDWadlkFso/4b0X5eLSt/b0/eKAYH1FgwgX+Uik3tS Dubjxxwe8LgYCzTPwYst97sPLM5yQZo3cgIygANuwyHnu4mAdWoMdOWZ6RU7MefHmmHS GXB8p+iQ6xCGJP/lvzHMD6Rngh7ZKCXGq9hj7Gqd7EkCwrwa+nCRGgfuTDEiRZHor5i/ l85sR66i4sdRGrJC0Ha0v562ssfT37uMeYduQRisWEK3VcHHtLWvwT+PgCRdDY7Q2FK5 weBA== X-Gm-Message-State: ALoCoQkSnSlaYyGAleYvJhu87PxM7xCORjnjnxQgrbjEf4fEYw68C3AHry7KXaM0oHLmeBhAV92S X-Received: by 10.180.97.200 with SMTP id ec8mr242412wib.5.1427778399340; Mon, 30 Mar 2015 22:06:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.179.131 with SMTP id dg3ls639795lac.74.gmail; Mon, 30 Mar 2015 22:06:39 -0700 (PDT) X-Received: by 10.152.234.42 with SMTP id ub10mr9004791lac.55.1427778399116; Mon, 30 Mar 2015 22:06:39 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id o1si1856940lao.102.2015.03.30.22.06.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Mar 2015 22:06:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbdc10 with SMTP id c10so4128828lbd.2 for ; Mon, 30 Mar 2015 22:06:38 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr29606552lba.19.1427778398808; Mon, 30 Mar 2015 22:06:38 -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 k9csp1568229lbq; Mon, 30 Mar 2015 22:06:36 -0700 (PDT) X-Received: by 10.70.9.131 with SMTP id z3mr38840449pda.156.1427778395647; Mon, 30 Mar 2015 22:06:35 -0700 (PDT) Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com. [209.85.192.178]) by mx.google.com with ESMTPS id uv6si17695534pbc.34.2015.03.30.22.06.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Mar 2015 22:06:35 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.178 as permitted sender) client-ip=209.85.192.178; Received: by pddn5 with SMTP id n5so8609213pdd.2 for ; Mon, 30 Mar 2015 22:06:34 -0700 (PDT) X-Received: by 10.69.16.1 with SMTP id fs1mr64616555pbd.125.1427778394611; Mon, 30 Mar 2015 22:06:34 -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 u4sm12400136pbs.29.2015.03.30.22.06.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Mar 2015 22:06:33 -0700 (PDT) From: John Stultz To: projectara-software-dev Cc: John Stultz , Alex Elder , Greg Kroah-Hartman , mark greer Subject: [RFC][PATCH v2] gbsim: Add initial i2s support. Date: Mon, 30 Mar 2015 22:06:31 -0700 Message-Id: <1427778391-10053-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.217.180 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. I'll be working to add the mgmt calls that actually provide data in responses tomorrow. v2: Just a quick resend to fix some issues pointed out and add basic support for trivial I2S mgmt calls. 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 18ab71e..8b45988 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,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();