From patchwork Wed Dec 3 09:30:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5428561 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2A1FA9F1C5 for ; Wed, 3 Dec 2014 09:36:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 553932034F for ; Wed, 3 Dec 2014 09:36:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 648F12034E for ; Wed, 3 Dec 2014 09:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751925AbaLCJd7 (ORCPT ); Wed, 3 Dec 2014 04:33:59 -0500 Received: from mail-pd0-f173.google.com ([209.85.192.173]:34888 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751866AbaLCJd5 (ORCPT ); Wed, 3 Dec 2014 04:33:57 -0500 Received: by mail-pd0-f173.google.com with SMTP id ft15so15049175pdb.18 for ; Wed, 03 Dec 2014 01:33:56 -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=JTQTV7p8N3d7IYCCPDtRq/jbBh+HqaKL7EMvNfc97ew=; b=Wjn1F3/2ALLZNbbi/xjPflRSzQfT4z6aAXVrRIDNhWLSQzR+TbwAIggd2wBli1mXcn d0EukJNeOKxxFIJ6+HAy8GPaA7BrI5XaCSsHC9+O1KDxPPqQ/COzWNvkShh+c5t4kbW/ bNF5YVGk4mtSckWObpJDDXbCv7AA2lRvJlOVhq6DPMClaIQCW0uZe6SpP1M44GITuqYc OPvsytoMRGFWkzInzsgJfz/k6NxSZ5mpKxEiEa1exo+I4a7LWJBybCskzmpaiBXnH6FJ ORG/OgbWnwqbM1hlWyySWzvuvSLV+BGqm2OG/GWYTMXK6FpNgYla2DsiH1bDFCgoih9B PL+w== X-Received: by 10.68.203.226 with SMTP id kt2mr13461681pbc.141.1417599236474; Wed, 03 Dec 2014 01:33:56 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id bj11sm22634803pdb.1.2014.12.03.01.33.51 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 01:33:55 -0800 (PST) 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 v12 15/19] input: cyapa: add gen3 trackpad device read firmware image function support Date: Wed, 3 Dec 2014 17:30:21 +0800 Message-Id: <1417599025-21681-16-git-send-email-dudley.dulixin@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417599025-21681-1-git-send-email-dudley.dulixin@gmail.com> References: <1417599025-21681-1-git-send-email-dudley.dulixin@gmail.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=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 640b916..dd1313e 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -708,6 +708,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) +{ + u8 cmd[] = { 0xff, 0x3c, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, addr >> 8, addr }; + int ret, error; + + error = cyapa_gen3_write_buffer(cyapa, cmd, sizeof(cmd)); + if (error) + return error; + + /* 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) @@ -754,6 +784,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 error; + int addr; + + error = cyapa_gen3_bl_enter(cyapa); + if (error) + return error; + + 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) { + error = cyapa_gen3_read_fw_bytes(cyapa, + CYAPA_FW_HDR_START + addr, &cyapa->fw_image[addr]); + if (error) + return error; + } + + 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) @@ -1195,6 +1260,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,