From patchwork Fri Oct 14 07:53:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9376157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F01C660779 for ; Fri, 14 Oct 2016 07:57:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4F2B2A4E5 for ; Fri, 14 Oct 2016 07:57:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8E092A4E7; Fri, 14 Oct 2016 07:57:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CAECF2A4E5 for ; Fri, 14 Oct 2016 07:57:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1buxLR-0004F9-5A; Fri, 14 Oct 2016 07:55:57 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1buxK3-0002Em-8R for linux-arm-kernel@lists.infradead.org; Fri, 14 Oct 2016 07:54:33 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39AEA7AE85; Fri, 14 Oct 2016 07:54:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9E7rdoO016706; Fri, 14 Oct 2016 03:54:05 -0400 From: Hans de Goede To: Rob Herring , Mark Rutland , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH 5/6] misc: q8-hardwaremgr: Better touchscreen defaults based on heuristics Date: Fri, 14 Oct 2016 09:53:36 +0200 Message-Id: <20161014075337.10452-6-hdegoede@redhat.com> In-Reply-To: <20161014075337.10452-1-hdegoede@redhat.com> References: <20161014075337.10452-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Oct 2016 07:54:12 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161014_005431_445959_885FB06D X-CRM114-Status: GOOD ( 16.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree , Maxime Ripard , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, Hans de Goede MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some q8s with gsl1680 touchscreens need to use an alterternative firmware file and/or need their x/y axis inverted. This commit adds some heuristics to pick defaults based on other detected tablet properties (mostly which accelerometer is detected) and sets defaults based on this. Although there is not necessarily any relationship between these settings, this does give us the right defaults on all known model q8 tablets, making the touchscreen work out of the box without requiring any kernel commandline options to be set. Signed-off-by: Hans de Goede --- drivers/misc/q8-hardwaremgr.c | 81 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/drivers/misc/q8-hardwaremgr.c b/drivers/misc/q8-hardwaremgr.c index 21754f5..95cdaf2 100644 --- a/drivers/misc/q8-hardwaremgr.c +++ b/drivers/misc/q8-hardwaremgr.c @@ -84,7 +84,12 @@ enum { }; #define DA280_REG_CHIP_ID 0x01 +#define DA280_REG_ACC_Z_LSB 0x06 +#define DA280_REG_MODE_BW 0x11 #define DA280_CHIP_ID 0x13 +#define DA280_MODE_ENABLE 0x1e +#define DA280_MODE_DISABLE 0x9e + #define DA311_REG_CHIP_ID 0x0f #define DA311_CHIP_ID 0x13 @@ -112,6 +117,7 @@ enum { enum { accel_unknown, + da226, da280, da311, dmard05, @@ -313,8 +319,23 @@ static int q8_hardwaremgr_probe_touchscreen(struct q8_hardwaremgr_data *data, static void q8_hardwaremgr_apply_gsl1680_a082_variant( struct q8_hardwaremgr_data *data) { - if (touchscreen_variant != -1) + if (touchscreen_variant != -1) { data->touchscreen_variant = touchscreen_variant; + } else { + /* + * These accelerometer based heuristics select the best + * default based on known q8 tablets. + */ + switch (data->accelerometer.model) { + case mc3230: + data->touchscreen_invert_x = 1; + break; + case dmard10: + case mxc6225: + data->touchscreen_variant = 1; + break; + } + } switch (data->touchscreen_variant) { default: @@ -338,8 +359,30 @@ static void q8_hardwaremgr_apply_gsl1680_a082_variant( static void q8_hardwaremgr_apply_gsl1680_b482_variant( struct q8_hardwaremgr_data *data) { - if (touchscreen_variant != -1) + if (touchscreen_variant != -1) { data->touchscreen_variant = touchscreen_variant; + } else { + /* + * These accelerometer based heuristics select the best + * default based on known q8 tablets. + */ + switch (data->accelerometer.model) { + case da280: + if (data->accelerometer.addr == 0x27) + ; /* No-op */ + else if (data->has_rda599x) + data->touchscreen_invert_x = 1; + else + data->touchscreen_invert_y = 1; + break; + case dmard09: + data->touchscreen_invert_x = 1; + break; + case mxc6225: + data->touchscreen_variant = 1; + break; + } + } switch (data->touchscreen_variant) { default: @@ -587,16 +630,39 @@ static int q8_hardwaremgr_probe_dmard10(struct q8_hardwaremgr_data *data, static int q8_hardwaremgr_probe_da280(struct q8_hardwaremgr_data *data, struct i2c_client *client) { - int id; + int ret; + + ret = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID); + if (ret != DA280_CHIP_ID) + return ret == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; - id = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID); - if (id == DA280_CHIP_ID) { + /* da226 (2-axis) or da280 (3-axis) ? measure once to detect */ + ret = i2c_smbus_write_byte_data(client, DA280_REG_MODE_BW, + DA280_MODE_ENABLE); + if (ret) + return ret == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; + + msleep(10); + + ret = i2c_smbus_read_word_data(client, DA280_REG_ACC_Z_LSB); + if (ret < 0) + return ret == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; + + /* If not present Z reports max pos value (14 bits, 2 low bits 0) */ + if (ret == 32764) { + data->accelerometer.compatible = "miramems,da226"; + data->accelerometer.model = da226; + } else { data->accelerometer.compatible = "miramems,da280"; data->accelerometer.model = da280; - return 0; } - return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; + ret = i2c_smbus_write_byte_data(client, DA280_REG_MODE_BW, + DA280_MODE_DISABLE); + if (ret) + return ret == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; + + return 0; } static int q8_hardwaremgr_probe_da311(struct q8_hardwaremgr_data *data, @@ -625,6 +691,7 @@ static int q8_hardwaremgr_probe_accelerometer(struct q8_hardwaremgr_data *data, PROBE_CLIENT(&data->accelerometer, 0x1d, q8_hardwaremgr_probe_dmard09); PROBE_CLIENT(&data->accelerometer, 0x18, q8_hardwaremgr_probe_dmard10); PROBE_CLIENT(&data->accelerometer, 0x26, q8_hardwaremgr_probe_da280); + PROBE_CLIENT(&data->accelerometer, 0x27, q8_hardwaremgr_probe_da280); PROBE_CLIENT(&data->accelerometer, 0x27, q8_hardwaremgr_probe_da311); return -ENODEV;