From patchwork Mon Nov 3 08:33:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5214941 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7CB9CC11AC for ; Mon, 3 Nov 2014 08:38:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A71FB20166 for ; Mon, 3 Nov 2014 08:38:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B9B072015E for ; Mon, 3 Nov 2014 08:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752473AbaKCIi1 (ORCPT ); Mon, 3 Nov 2014 03:38:27 -0500 Received: from mail-pd0-f173.google.com ([209.85.192.173]:33343 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752268AbaKCIhB (ORCPT ); Mon, 3 Nov 2014 03:37:01 -0500 Received: by mail-pd0-f173.google.com with SMTP id v10so11175801pde.32 for ; Mon, 03 Nov 2014 00:37:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bs+K7TfuhjI3CAfgWSuOi2aQrJr7Z+3jkyNfx9NEItg=; b=Pce7Z1jtZPyQ3UhrKq/U8gaDhpb9gXhNRxlDK6swnHOO8iaBhmLDGsvQe89/yyA2nU WZKG+PPSiwfZmLUn8FGKnZCeo7JuNYoh+iVDJV1V2k0o0RSZtQAoNTan1i0TaHOp30C7 754cUmyRS6YbVO+9WR/pfRMqHjhSMpH7zuwnGC7fSgrrHjEZxfTvJuMMnKKZM3FSLJKa sRFzSCNNK4/7qiJPfDlO1LqfmU3kDcwfUapc2QTRtWBPMwMY7+cAxJom2HrNsuqELtKX Lu92tsOwIHIKl5CIhhJo1Y3o3zKkzyuJwH3dC+Yysc+mCup1hnnuzulys3S1wXvwbnC8 uF5Q== X-Received: by 10.70.60.167 with SMTP id i7mr41503874pdr.86.1415003820768; Mon, 03 Nov 2014 00:37:00 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id gy5sm16437291pbc.68.2014.11.03.00.36.57 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Nov 2014 00:36:59 -0800 (PST) From: Dudley Du X-Google-Original-From: Dudley Du To: dmitry.torokhov@gmail.com, rydberg@euromail.se Cc: Dudley Du , bleung@google.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 15/18] input: cyapa: add gen3 trackpad device read firmware image function support Date: Mon, 3 Nov 2014 16:33:07 +0800 Message-Id: <1415003590-30485-16-git-send-email-dudl@cypress.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415003590-30485-1-git-send-email-dudl@cypress.com> References: <1415003590-30485-1-git-send-email-dudl@cypress.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add read firmware image function supported for gen3 trackpad device, it can be used through debugfs read_fw interface. TEST=test on Chromebooks. Signed-off-by: Dudley Du --- drivers/input/mouse/cyapa_gen3.c | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c index b477d67..f8aeb58 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -710,6 +710,36 @@ static int cyapa_gen3_write_fw_block(struct cyapa *cyapa, return ret; } +/* + * A firmware block read command reads 16 bytes of data from flash starting + * from a given address. The 12-byte block read command has the format: + * <0xff> + * + * <0xff> - every command starts with 0xff + * - the read command value is 0x3c + * - read commands include an 8-byte key: { 00 01 02 03 04 05 06 07 } + * - Memory address (16-bit, big-endian) + * + * The command is followed by an i2c block read to read the 16 bytes of data. + */ +static int cyapa_gen3_read_fw_bytes(struct cyapa *cyapa, u16 addr, u8 *data) +{ + int ret; + u8 cmd[] = { 0xff, 0x3c, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, addr >> 8, addr }; + + ret = cyapa_gen3_write_buffer(cyapa, cmd, sizeof(cmd)); + if (ret) + return ret; + + /* Read data buffer starting from offset 16 */ + ret = cyapa_i2c_reg_read_block(cyapa, 16, CYAPA_FW_READ_SIZE, data); + if (ret != CYAPA_FW_READ_SIZE) + return (ret < 0) ? ret : -EIO; + + return 0; +} + static int cyapa_gen3_write_blocks(struct cyapa *cyapa, size_t start_block, size_t block_count, const u8 *image_data) @@ -756,6 +786,41 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa, return 0; } +/* + * Read the entire firmware image into ->fw_image. + * If the ->fw_image has already been allocated, then this function + * doesn't do anything and just returns 0. + * If an error occurs while reading the image, ->fw_image is freed, and + * the error is returned. + * + * The firmware is a fixed size (CYAPA_FW_SIZE), and is read out in + * fixed length (CYAPA_FW_READ_SIZE) chunks. + */ +static int cyapa_gen3_read_fw(struct cyapa *cyapa) +{ + int ret; + int addr; + + ret = cyapa_gen3_bl_enter(cyapa); + if (ret) + return ret; + + cyapa->fw_image = cyapa->fw_image ? cyapa->fw_image : + devm_kzalloc(&cyapa->client->dev, CYAPA_FW_SIZE, GFP_KERNEL); + if (!cyapa->fw_image) + return -ENOMEM; + + for (addr = 0; addr < CYAPA_FW_SIZE; addr += CYAPA_FW_READ_SIZE) { + ret = cyapa_gen3_read_fw_bytes(cyapa, CYAPA_FW_HDR_START + addr, + &cyapa->fw_image[addr]); + if (ret) + return ret; + } + + cyapa->fw_image_size = CYAPA_FW_SIZE; + return 0; +} + static ssize_t cyapa_gen3_do_calibrate(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -1203,6 +1268,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = { .show_baseline = cyapa_gen3_show_baseline, .calibrate_store = cyapa_gen3_do_calibrate, + .read_fw = cyapa_gen3_read_fw, + .state_parse = cyapa_gen3_state_parse, .operational_check = cyapa_gen3_do_operational_check,