From patchwork Wed Dec 11 03:10:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Heiny X-Patchwork-Id: 3321911 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 6F698C0D4A for ; Wed, 11 Dec 2013 03:10:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6C8E92064F for ; Wed, 11 Dec 2013 03:10:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4529C20720 for ; Wed, 11 Dec 2013 03:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751442Ab3LKDKp (ORCPT ); Tue, 10 Dec 2013 22:10:45 -0500 Received: from us-mx2.synaptics.com ([192.147.44.131]:9563 "EHLO us-mx2.synaptics.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980Ab3LKDKo (ORCPT ); Tue, 10 Dec 2013 22:10:44 -0500 Received: from unknown (HELO securemail.synaptics.com) ([172.20.21.135]) by us-mx2.synaptics.com with ESMTP; 10 Dec 2013 19:10:44 -0800 Received: from USW-OWA1.synaptics-inc.local ([10.20.24.16]) by securemail.synaptics.com (PGP Universal service); Tue, 10 Dec 2013 19:01:53 -0800 X-PGP-Universal: processed; by securemail.synaptics.com on Tue, 10 Dec 2013 19:01:53 -0800 Received: from brontomerus.synaptics-inc.local (10.3.20.103) by USW-OWA1.synaptics-inc.local (10.20.24.15) with Microsoft SMTP Server (TLS) id 14.3.123.3; Tue, 10 Dec 2013 19:10:44 -0800 From: Christopher Heiny To: Dmitry Torokhov CC: Linux Input , Christopher Heiny , Andrew Duggan , Vincent Huang , Vivian Ly , Daniel Rosenberg , Jean Delvare , Joerie de Gram , Linus Walleij , Benjamin Tissoires Subject: [PATCH] input synaptics-rmi4: Eliminate packed structs in PDT handling Date: Tue, 10 Dec 2013 19:10:42 -0800 Message-ID: <1386731442-31146-1-git-send-email-cheiny@synaptics.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-Originating-IP: [10.3.20.103] X-Brightmail-Tracker: AAAAAQAAAWE= 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.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 This converts the PDT handling routines from using bitfields in packed structs, converting to bitmasks and shifts to parse out bitfields, nibbles, and so on. Signed-off-by: Christopher Heiny Cc: Dmitry Torokhov Cc: Jean Delvare Cc: Linus Walleij Cc: Joerie de Gram Cc: Benjamin Tissoires --- This patch implements changes to the synaptics-rmi4 branch of Dmitry's input tree. The base for the patch is commit f154022b208a59b048f52b7b5d58a5ec1949b96e. drivers/input/rmi4/rmi_driver.c | 45 +++++++++++++++++++++++++++------------- drivers/input/rmi4/rmi_driver.h | 46 +++++++++++++++-------------------------- 2 files changed, 48 insertions(+), 43 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index dffbfa0..a30c7d3 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -483,6 +483,31 @@ int rmi_driver_irq_get_mask(struct rmi_device *rmi_dev, return -ENOMEM; } +int rmi_read_pdt_entry(struct rmi_device *rmi_dev, struct pdt_entry *entry, + u16 pdt_address) +{ + u8 buf[RMI_PDT_ENTRY_SIZE]; + int error; + + error = rmi_read_block(rmi_dev, pdt_address, buf, RMI_PDT_ENTRY_SIZE); + if (error < 0) { + dev_err(&rmi_dev->dev, "Read PDT entry at %#06x failed, code: %d.\n", + pdt_address, error); + return error; + } + + entry->query_base_addr = buf[0]; + entry->command_base_addr = buf[1]; + entry->control_base_addr = buf[2]; + entry->data_base_addr = buf[3]; + entry->interrupt_source_count = buf[4] & RMI_PDT_INT_SOURCE_COUNT_MASK; + entry->function_version = (buf[4] & RMI_PDT_FUNCTION_VERSION_MASK) >> 5; + entry->function_number = buf[5]; + + return 0; +} +EXPORT_SYMBOL_GPL(rmi_read_pdt_entry); + static void rmi_driver_copy_pdt_to_fd(struct pdt_entry *pdt, struct rmi_function_descriptor *fd, u16 page_start) @@ -572,14 +597,10 @@ static int reset_and_reflash(struct rmi_device *rmi_dev) u16 pdt_end = page_start + PDT_END_SCAN_LOCATION; done = true; - for (i = pdt_start; i >= pdt_end; i -= sizeof(pdt_entry)) { - retval = rmi_read_block(rmi_dev, i, &pdt_entry, - sizeof(pdt_entry)); - if (retval != sizeof(pdt_entry)) { - dev_err(dev, "Read PDT entry at %#06x failed, code = %d.\n", - i, retval); + for (i = pdt_start; i >= pdt_end; i -= RMI_PDT_ENTRY_SIZE) { + retval = rmi_read_pdt_entry(rmi_dev, &pdt_entry, i); + if (retval < 0) return retval; - } if (RMI4_END_OF_PDT(pdt_entry.function_number)) break; @@ -634,14 +655,10 @@ static int rmi_scan_pdt(struct rmi_device *rmi_dev) u16 pdt_end = page_start + PDT_END_SCAN_LOCATION; done = true; - for (i = pdt_start; i >= pdt_end; i -= sizeof(pdt_entry)) { - retval = rmi_read_block(rmi_dev, i, &pdt_entry, - sizeof(pdt_entry)); - if (retval != sizeof(pdt_entry)) { - dev_err(dev, "Read of PDT entry at %#06x failed.\n", - i); + for (i = pdt_start; i >= pdt_end; i -= RMI_PDT_ENTRY_SIZE) { + retval = rmi_read_pdt_entry(rmi_dev, &pdt_entry, i); + if (retval < 0) goto error_exit; - } if (RMI4_END_OF_PDT(pdt_entry.function_number)) break; diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index f8d87e9..5e3c4d4 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -29,11 +29,7 @@ #define PDT_PROPERTIES_LOCATION 0x00EF #define BSR_LOCATION 0x00FE -struct pdt_properties { - u8 reserved_1:6; - u8 has_bsr:1; - u8 reserved_2:1; -} __attribute__((__packed__)); +#define RMI_PDT_PROPS_HAS_BSR 0x02 struct rmi_driver_data { struct list_head function_list; @@ -61,7 +57,7 @@ struct rmi_driver_data { ktime_t poll_interval; struct mutex pdt_mutex; - struct pdt_properties pdt_props; + u8 pdt_props; u8 bsr; bool enabled; @@ -90,34 +86,26 @@ struct rmi_driver_data { void *data; }; +#define RMI_PDT_ENTRY_SIZE 6 +#define RMI_PDT_FUNCTION_VERSION_MASK 0x60 +#define RMI_PDT_INT_SOURCE_COUNT_MASK 0x07 + #define PDT_START_SCAN_LOCATION 0x00e9 #define PDT_END_SCAN_LOCATION 0x0005 #define RMI4_END_OF_PDT(id) ((id) == 0x00 || (id) == 0xff) struct pdt_entry { - u8 query_base_addr:8; - u8 command_base_addr:8; - u8 control_base_addr:8; - u8 data_base_addr:8; - u8 interrupt_source_count:3; - u8 bits3and4:2; - u8 function_version:2; - u8 bit7:1; - u8 function_number:8; -} __attribute__((__packed__)); - -static inline void copy_pdt_entry_to_fd(struct pdt_entry *pdt, - struct rmi_function_descriptor *fd, - u16 page_start) -{ - fd->query_base_addr = pdt->query_base_addr + page_start; - fd->command_base_addr = pdt->command_base_addr + page_start; - fd->control_base_addr = pdt->control_base_addr + page_start; - fd->data_base_addr = pdt->data_base_addr + page_start; - fd->function_number = pdt->function_number; - fd->interrupt_source_count = pdt->interrupt_source_count; - fd->function_version = pdt->function_version; -} + u8 query_base_addr; + u8 command_base_addr; + u8 control_base_addr; + u8 data_base_addr; + u8 interrupt_source_count; + u8 function_version; + u8 function_number; +}; + +int rmi_read_pdt_entry(struct rmi_device *rmi_dev, struct pdt_entry *entry, + u16 pdt_address); bool rmi_is_physical_driver(struct device_driver *); int rmi_register_physical_driver(void);