From patchwork Fri Jun 6 07:29:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 4310451 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 CB1CEBEEAA for ; Fri, 6 Jun 2014 07:31:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 24E88201D5 for ; Fri, 6 Jun 2014 07:31:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 526AD201BC for ; Fri, 6 Jun 2014 07:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751390AbaFFHbj (ORCPT ); Fri, 6 Jun 2014 03:31:39 -0400 Received: from relay-s04-hub006.domainlocalhost.com ([74.115.207.217]:38435 "EHLO relay-S04-HUB006.domainlocalhost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752522AbaFFH3N (ORCPT ); Fri, 6 Jun 2014 03:29:13 -0400 Received: from S04-MBX01-01.s04.local ([169.254.1.126]) by S04-HUB006.s04.local ([10.30.13.44]) with mapi id 14.03.0174.001; Fri, 6 Jun 2014 03:29:11 -0400 From: Dudley Du To: Dmitry Torokhov , "Rafael J. Wysocki" , Alan Stern CC: Benson Leung , Lily Rui , "Daniel Kurtz" , "linux-kernel@vger.kernel.org" , "linux-input@vger.kernel.org" Subject: [PATCH v2 9/14] input: cyapa: add gen3 trackpad device read firmware image function supported Thread-Topic: [PATCH v2 9/14] input: cyapa: add gen3 trackpad device read firmware image function supported Thread-Index: Ac+BWOzJPIh1Vy0uRvy9B48DS0G8TQ== Date: Fri, 6 Jun 2014 07:29:11 +0000 Message-ID: <77BC725C9062764F874D79F51E1F1A8F4406C8E4@S04-MBX01-01.s04.local> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: <77BC725C9062764F874D79F51E1F1A8F4406C8E4@S04-MBX01-01.s04.local> x-originating-ip: [10.30.12.146] MIME-Version: 1.0 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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, 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, which its function is supplied through cyapa core read_fw interface. TEST=test on Chomebooks. Signed-off-by: Du, Dudley --- This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message. diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c index 9ffdbc1..e903e62 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -689,6 +689,35 @@ 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, 0, 1, 2, 3, 4, 5, 6, 7, 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_do_fw_update(struct cyapa *cyapa, const struct firmware *fw) { @@ -724,6 +753,47 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa, return 0; } +/* + * Read the entire firmware image into ->read_fw_image. + * If the ->read_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, ->read_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) + goto err; + + cyapa->read_fw_image = kmalloc(CYAPA_FW_SIZE, GFP_KERNEL); + if (!cyapa->read_fw_image) { + ret = -ENOMEM; + goto err; + } + + 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->read_fw_image[addr]); + if (ret) { + kfree(cyapa->read_fw_image); + cyapa->read_fw_image = NULL; + break; + } + } + +err: + if (cyapa->read_fw_image) + cyapa->read_fw_image_size = CYAPA_FW_SIZE; + return ret; +} + static ssize_t cyapa_gen3_do_calibrate(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -1122,7 +1192,7 @@ const struct cyapa_dev_ops cyapa_gen3_ops = { cyapa_gen3_show_baseline, cyapa_gen3_do_calibrate, - NULL, + cyapa_gen3_read_fw, NULL, NULL,