Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3366693ybb; Tue, 31 Mar 2020 03:55:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsnFhqCUTiMSlhTutwW8157cXLtEqxs1NJXCnbZuWrFwM9RQSpUDOxUtfxsX0NdER39icde X-Received: by 2002:a05:6830:1dfb:: with SMTP id b27mr11763332otj.89.1585652108684; Tue, 31 Mar 2020 03:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585652108; cv=none; d=google.com; s=arc-20160816; b=EJ/g+2/BsGbrbAoPWxBdoP5w0udBZqmpEtUwguEh8UxBavfltaEvhFsSdmB7ymVa7v wU/oOMJ0AtIV7cxwx+2BeaOi3nE3loRZTYuMCLZd4qO/R6LuhF7hvbmUdxTWl288eHQp ksY/RUpoF1Rs5OkXKchtfAZ4EH1tpaEZZxJjb8lNe1FiU6MXUiiHgOVXyrkCeVuUULIL LFknVqau0gUcMqOSt5RkPXQDbGapstMM5+NY+z3ap1CNnKstMou6ElRzS26GUJeDvWue TvbIA1p7R6HuG6KhlXQEUzLx9SkWIF9I27ekJISCURaM599vSAzyffpR6lFZKesuGnEw ZoHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=1fq48FaMeiuvYAZDVw34PvSVBOUhP2MdFuKFJZlulwg=; b=d/ZWjXiqB2sHUIQpesk75+mTQvtQM4gMs4PGgU95TM6mUJNXFknrOfWcAmpme1NaiJ fQUKzvk8tdpvJ7n38j3sbBQq+/iIr07wKb3u0nX4kFZeVlljSU3cHUPi9l1GISxz8Yb0 eLrheI6Q+etOyAUD3FyjJGQZq1xkGij+0EHceCtaiKp0bcnuI7K2kyk/frEbls9c2Mh+ JnwwBDO0rtgb/0p3pXZ7EOgcqio3qLaHh6Qq8YU+C1G60Ml/LbGiMUX6Q7NU3sZMFXV4 /gRijlTQopVgwbC852BiLwXlBw2CnOO+7EmUWsntbJiKEfbqLo202quvOGtEynr/F0Im 0pTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x63si6785131oia.101.2020.03.31.03.54.56; Tue, 31 Mar 2020 03:55:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730926AbgCaKxd (ORCPT + 99 others); Tue, 31 Mar 2020 06:53:33 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730922AbgCaKxc (ORCPT ); Tue, 31 Mar 2020 06:53:32 -0400 IronPort-SDR: gACpHvx8AF09s5oBgrpHixyEMGCDTmi6bfT6xCB1mCW+wkC6UgTXffcpWqa0wow79cETnaalbh IMr8/fUCtTYrXb7nXXo3kd6wtEOBx1TvB4qLg5AjwovVPhiqi0SpCDo4xSg3f04T0BoLFdllBt wnhYiYmoE3NIYqq3m7KuN0Jaz3g0R8oCwxEEPGPzvVlyo4Lyt3CG+/UQfaQmQRrFIF9F1XOD7u 1mhcZYNuq66KJerE8Yx7YJjbkFuUJ7VCheOpPIcLc7saaEBTFuGHJRdm+mjAaBO6/bBJcrqStd v2o= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330829" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:31 -0800 IronPort-SDR: HdUupt5FmIYReew7TVjcfq8faoFEISBln0DQn2ResxPtE5QaIk1WPlXtK8A5MQe/LGnJtYnNv3 HKUt1u3vyL+QwwrSMfnUuLq2xyHW8PrO2HGdrQupzUHCUdgHAYl4JUX7AVpCxtaXeap3qzia4o RE6et8Ph8n6xxJpD81eU6tvXTc0WBqqr03U90hc14piTzsJxslpEiw8H9Zi2/dJyDEcgJJgK+b VNRJk/v2hCdAgsMLX2iK13g4dGQldjkUcamyTn55YjmcmDkSBV5SoLwOhGO/BIyAZ631CUDhcr 8XI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 41/55] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Tue, 31 Mar 2020 03:50:37 -0700 Message-ID: <20200331105051.58896-42-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-1-jiada_wang@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikhil Ravindran The self test object T25 runs self test routines in device to find faults Sysfs entry add to start self test routine and read back the test results for atmel touchcontrollers.The feature will be used for A-IVI and CAF projects. Signed-off-by: Nikhil Ravindran Signed-off-by: George G. Davis [jiada: Rename mxt_t25_selftest_show to t25_selftest_show Rename mxt_t25_selftest_store to t25_selftest_show Rename attr t25 to t25_selftest Replace DEVICE_ATTR with DEVICE_ATTR_RW] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index fb7cd06cab53..54cd6219cbaa 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -336,6 +336,9 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + u16 T25_address; + u8 T25_reportid; + u8 t25_msg[6]; bool debug_enabled; bool debug_v2_enabled; u8 *debug_msg_data; @@ -413,6 +416,8 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + + bool t25_status; }; struct mxt_vb2_buffer { @@ -1356,6 +1361,24 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) dev_info(dev, "T93 report double tap %d\n", status); } +static void mxt_proc_t25_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + /* Output debug if status has changed */ + dev_dbg(dev, "T25 Status 0x%x Info: %x %x %x %x %x\n", + msg[1], + msg[2], + msg[3], + msg[4], + msg[5], + msg[6]); + + /* Save current status */ + memcpy(&data->t25_msg[0], &msg[1], sizeof(data->t25_msg)); + data->t25_status = false; +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1386,6 +1409,8 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T19_reportid) { mxt_input_button(data, message); data->update_input = true; + } else if (report_id == data->T25_reportid) { + mxt_proc_t25_messages(data, message); } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); @@ -1610,6 +1635,86 @@ static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, return 0; } +static int mxt_t25_command(struct mxt_data *data, u8 cmd, bool wait) +{ + u16 reg; + int timeout_counter = 0; + int ret; + u8 val[2]; + + reg = data->T25_address; + val[0] = 0x3; + val[1] = cmd; + + data->t25_status = true; + ret = __mxt_write_reg(data->client, reg, sizeof(val), val); + if (ret) { + data->t25_status = false; + return ret; + } + + if (!wait) + return 0; + + do { + msleep(MXT_WAKEUP_TIME); + ret = __mxt_read_reg(data->client, reg + 1, 1, &val[1]); + if (ret) + return ret; + } while ((val[1] != 0) && (timeout_counter++ <= 100)); + + if (timeout_counter > 100) { + dev_err(&data->client->dev, "Command failed!\n"); + data->t25_status = false; + return -EIO; + } + return 0; +} + +/* Firmware Version is returned as Major.Minor.Build */ +static ssize_t t25_selftest_show(struct device *dev, struct + device_attribute * attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + ssize_t offset = 0; + + if (data->t25_status) + return -EAGAIN; + + if (data->t25_msg[0] == 0xFE) + offset += scnprintf(buf, PAGE_SIZE, "PASS\n"); + else + offset += scnprintf(buf, PAGE_SIZE, "FAILED\n"); + + offset += scnprintf(buf + offset, PAGE_SIZE, "%x %x %x %x %x %x\n", + data->t25_msg[0], + data->t25_msg[1], + data->t25_msg[2], + data->t25_msg[3], + data->t25_msg[4], + data->t25_msg[5]); + return offset; +} + +static ssize_t t25_selftest_store(struct device *dev, struct + device_attribute * attr, const char *buf, + size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u32 cmd; + int ret; + + ret = kstrtou32(buf, 0, &cmd); + if (ret) + return ret; + + if (mxt_t25_command(data, (u8)cmd, 1) == 0) + return count; + + dev_dbg(dev, "mxt_t25_cmd_store write cmd %x error\n", cmd); + return -EINVAL; +} + static int mxt_acquire_irq(struct mxt_data *data) { int error; @@ -2088,6 +2193,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T15_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T25_address = 0; + data->T25_reportid = 0; data->T42_reportid_min = 0; data->T42_reportid_max = 0; data->T44_address = 0; @@ -2175,6 +2282,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_SPT_SELFTEST_T25: + data->T25_address = object->start_address; + data->T25_reportid = min_id; + break; case MXT_PROCI_TOUCHSUPPRESSION_T42: data->T42_reportid_min = min_id; data->T42_reportid_max = max_id; @@ -3769,6 +3880,7 @@ static DEVICE_ATTR_RO(config_crc); static DEVICE_ATTR_RW(debug_enable); static DEVICE_ATTR_RW(debug_v2_enable); static DEVICE_ATTR_RO(debug_notify); +static DEVICE_ATTR_RW(t25_selftest); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3779,6 +3891,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_enable.attr, &dev_attr_debug_v2_enable.attr, &dev_attr_debug_notify.attr, + &dev_attr_t25_selftest.attr, NULL }; -- 2.17.1