From patchwork Tue May 6 22:13:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 4124371 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 D03B1C0ACC for ; Tue, 6 May 2014 22:13:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E67A520254 for ; Tue, 6 May 2014 22:13:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F015A2018E for ; Tue, 6 May 2014 22:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752104AbaEFWN0 (ORCPT ); Tue, 6 May 2014 18:13:26 -0400 Received: from avon.wwwdotorg.org ([70.85.31.133]:52496 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751752AbaEFWNZ (ORCPT ); Tue, 6 May 2014 18:13:25 -0400 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 80F806358; Tue, 6 May 2014 16:13:25 -0600 (MDT) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id 532CAE40EB; Tue, 6 May 2014 16:13:24 -0600 (MDT) From: Stephen Warren To: Dmitry Torokhov Cc: Benson Leung , Yufeng Shen , Daniel Kurtz , linux-input@vger.kernel.org, Stephen Warren Subject: [PATCH 2/4] Input: atmel_mxt_ts - Read resolution from device memory Date: Tue, 6 May 2014 16:13:10 -0600 Message-Id: <1399414392-32572-3-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1399414392-32572-1-git-send-email-swarren@wwwdotorg.org> References: <1399414392-32572-1-git-send-email-swarren@wwwdotorg.org> X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.8 at avon.wwwdotorg.org X-Virus-Status: Clean 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, 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 From: Yufeng Shen Currently mxt_calc_resolution() computes device resolution from provided platform data. In order to support device tree, we would need a way to represent these values there too. To avoid that, we rework mxt_calc_resolution() so it reads the actual resolution from the configured device memory. And also move mxt_calc_resolution() into mxt_initialize() after the device is configured. Signed-off-by: Yufeng Shen Signed-off-by: Daniel Kurtz [swarren, augmented patch description to mention device tree] Signed-off-by: Stephen Warren --- drivers/input/touchscreen/atmel_mxt_ts.c | 71 ++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 9ba7e30c7894..c7ab14cf84b7 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -812,6 +812,44 @@ static void mxt_free_object_table(struct mxt_data *data) data->T19_reportid = 0; } +static int mxt_calc_resolution(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + struct mxt_object *T9; + u8 orient; + __le16 xyrange[2]; + unsigned int max_x, max_y; + int ret; + + T9 = mxt_get_object(data, MXT_TOUCH_MULTI_T9); + if (T9 == NULL) + return -EINVAL; + + /* Get touchscreen resolution */ + ret = __mxt_read_reg(client, T9->start_address + MXT_TOUCH_XRANGE_LSB, + 4, xyrange); + if (ret) + return ret; + + ret = __mxt_read_reg(client, T9->start_address + MXT_TOUCH_ORIENT, + 1, &orient); + if (ret) + return ret; + + max_x = le16_to_cpu(xyrange[0]); + max_y = le16_to_cpu(xyrange[1]); + + if (orient & MXT_XY_SWITCH) { + data->max_x = max_y; + data->max_y = max_x; + } else { + data->max_x = max_x; + data->max_y = max_y; + } + + return 0; +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -844,14 +882,17 @@ static int mxt_initialize(struct mxt_data *data) mxt_handle_pdata(data); /* Backup to memory */ - mxt_write_object(data, MXT_GEN_COMMAND_T6, - MXT_COMMAND_BACKUPNV, - MXT_BACKUP_VALUE); + error = mxt_write_object(data, MXT_GEN_COMMAND_T6, + MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE); + if (error) + return error; msleep(MXT_BACKUP_TIME); /* Soft reset */ - mxt_write_object(data, MXT_GEN_COMMAND_T6, - MXT_COMMAND_RESET, 1); + error = mxt_write_object(data, MXT_GEN_COMMAND_T6, + MXT_COMMAND_RESET, 1); + if (error) + return error; msleep(MXT_RESET_TIME); /* Update matrix size at info struct */ @@ -875,6 +916,10 @@ static int mxt_initialize(struct mxt_data *data) info->matrix_xsize, info->matrix_ysize, info->object_num); + error = mxt_calc_resolution(data); + if (error) + return error; + return 0; err_free_object_table: @@ -882,20 +927,6 @@ err_free_object_table: return error; } -static void mxt_calc_resolution(struct mxt_data *data) -{ - unsigned int max_x = data->pdata->x_size - 1; - unsigned int max_y = data->pdata->y_size - 1; - - if (data->pdata->orient & MXT_XY_SWITCH) { - data->max_x = max_y; - data->max_y = max_x; - } else { - data->max_x = max_x; - data->max_y = max_y; - } -} - /* Firmware Version is returned as Major.Minor.Build */ static ssize_t mxt_fw_version_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -1166,8 +1197,6 @@ static int mxt_probe(struct i2c_client *client, data->pdata = pdata; data->irq = client->irq; - mxt_calc_resolution(data); - error = mxt_initialize(data); if (error) goto err_free_mem;