Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4316812ybc; Fri, 22 Nov 2019 00:30:30 -0800 (PST) X-Google-Smtp-Source: APXvYqzjpM2GjXPQVgf/vf2l/u6MV7Qm4TJJWCsPuEBh2OI34IAm6836D8kNwa6Phtj1bkgv2kDB X-Received: by 2002:a17:906:b6c3:: with SMTP id ec3mr21215501ejb.27.1574411430131; Fri, 22 Nov 2019 00:30:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574411430; cv=none; d=google.com; s=arc-20160816; b=Lf2kERsb9PZBCWTqgZP/waFWBIsyMKfY8kuzXROPQyuxqOmTjEZEMqrUrGgP56+JcU Vc9pFQuzQJ1zyoIb1kvN6wEvHbqIaJXVTIjeLBTyi/cyb1L54twEvEXtTtWLf42vM6MJ vHHqKk3PQxFzcR/eQZXxcfuAedcyKmZ3AuH/+12WaiWVMhYoZobKuYfSeqgFwDsArYxN iexmTjIGLLJPsjeR4cxkiP7ZxWQ8pUSy0E6owaLAo3EebwP6AmBNQalHPgRBIQM1yy6U VR1IB44U2rqDB1/gH3ibXSHpHm+cIh0RNzKepO6hOuMix3n/+Kzhj0m7HsAbWnhQq4AZ gv2w== 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=DWyx8uBGbk+XcbB4HmiYMhSCeSgh0f08YG+2p2/KR0s=; b=JRqXrBPJuS2LEI3xZ3R0zSzbn5hMeWARErrCe8Kxv97pl0dqn4YWxgFCFU+GIHgGfP z8nnI+PWgQp0HF8kks+B0TG9rE0oDnO243WGy5kiyvit3W7AtzUObQGhK7tHY0pToGRF JJvqYv948Yvn/yCP3SQMBiFLVgDuLw+9j7sYudtEDchicYxH80j293JPzTluLNpMdZZ6 tztO3ZMrQPdxyBoPeFUjBE9FtNVahMd4dhkKOYQ5zmpRV394B2l7QGs6WQTZl6J9aYE3 aCqeH4VK2PYR57weUEiMD4Jfxmf7bNGzL1RMIn59bGyrFMVXdvTwq0KqfuK9Qo0R6Mp2 sxbA== 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 m10si3765180ejo.243.2019.11.22.00.30.06; Fri, 22 Nov 2019 00:30:30 -0800 (PST) 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 S1727662AbfKVI0T (ORCPT + 99 others); Fri, 22 Nov 2019 03:26:19 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:23065 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbfKVI0R (ORCPT ); Fri, 22 Nov 2019 03:26:17 -0500 IronPort-SDR: nvcvKgWq2RkXSypJPTbaRnCmoaJIP4UtSGlMHVl1fMwfpDWGKbmx3AYBtdCkCf4w7VE2MyY596 XE8Pb34L/BRbviVK1z+Jcb2x91EeNISeRJTvIxp59Ay30pwd1C2rhvJ8XGFp7jpBcFH7h681Zh lzYqFX8dhHzOkrnlbhVanO2XCK214rvLQwdyzdpRkoG98EcR+YKYWHZvNHtR+Vc439whdGp5A3 MtKjpaovoV5hm25wMniZPvBtR3zkYoeB8KBDGjB95o5ZR6QHDVBoa4hxRctmQLmUsos49FyvVj Bg8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291170" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:16 -0800 IronPort-SDR: Kis2qeohNWaflC5V6fBg+LsY8V4rTrV0g5d8yWnPUnTPEGxq1ktOT+EMhm4s5C/GqV+wzKf96U Nhj/GwjBdHpXL8K3LRnf3mUVWi8YiHB3rSzwJwrv1X+PTnLYTXTURoea5BtY4Fdinx2BeCB281 TzQvgonNn1z1lmvozVa/jNFiz8spP1ddFA6WqyEA64jgmsZv6XFZvpWOSjLpYO7NZLGEn40Rwt A8x1PihWKHJaQKW/h3ZjLfKm+dZ6uqWg1jBRfJrLIDhxTjWUHOBv8aYfssfM3XpjQRGbX56eoE X90= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 35/48] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Fri, 22 Nov 2019 17:23:49 +0900 Message-ID: <20191122082402.18173-36-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 111 +++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 835cc7a29c2f..74866015572f 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 { @@ -1359,6 +1364,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]; @@ -1389,6 +1412,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); @@ -1613,6 +1638,84 @@ 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 mxt_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 mxt_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; + + if (sscanf(buf, "%x", &cmd) == 1) { + 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; + } + return 0; +} + static int mxt_acquire_irq(struct mxt_data *data) { int error; @@ -2091,6 +2194,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; @@ -2178,6 +2283,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; @@ -3764,6 +3873,7 @@ static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); +static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3774,6 +3884,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.attr, NULL }; -- 2.17.1