From patchwork Thu Jul 11 17:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 812536 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0283742AB5; Thu, 11 Jul 2024 17:27:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718851; cv=none; b=BJN3Bnup8rYbXXitlQlf5w4o7Yn79hYVo8KQraMt2lokHyjDqS+/wHxZYACmpF/6AqqFJhhcRrvuKk9PjhcShJSy16mDeSl3KGOI8Ndx/ZN0sjN8P3eJMUhpjJ8QGtH+0lClKJHuawHtdYRQEaXqLYYJ6YJ40o8zY5Bb+RvaOGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718851; c=relaxed/simple; bh=tmeS6r0tPRTtdX3sTg3GrfedzXoARJiD6p/6ctXsE68=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tyRb/b/oXnQUwMFhKoiDJ/JtBJ0fHDoF40KpzytaC5yrHsyO78uZt+uJVZ25u8S+2LQLMA9FuxuHdildDFc4IXVmytg+uyAAbFi5KGJNbgO4/LPWVIdyS/ce5pmS7DpUEUVA0QCTwwXgbTrRBLdX/UY0Rt33YJIsUkpTDkSwg2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SFa4YiO7; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SFa4YiO7" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fbc09ef46aso9936865ad.3; Thu, 11 Jul 2024 10:27:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720718849; x=1721323649; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=o4p0tg8Xj5vTmnTobwa3zRdSV9mSn2dUw2iMbgYCWTU=; b=SFa4YiO7gkCSZoq/vJVjffloT5UC9jxMyABtTh4prbgAyUdFSAy1ftpWdA/BbKKSGa OtyBRn+bKcDjFphmWVRjm6/8IYJjH/My19tu8zESZ/tEHcr+9d7MHXPSMQXWR7TRPQlE gpL4UXo292u0djC0nV2BL7kFf21kMsD/DX2o54AuxqmToEaVr34CXEMSrbYHT9PmPGBX mqjUE+eWuBmM8y6WSczqE1Hxf2Dw29DiM7eNZiJMraTGkSR1mp35omFQpJ8RRkO3vwC2 610dmHw6oo5TRu1ZX0DjfAVTDthcwg6+g/YfMQ4Raq07E/4hTCKMlB4knwaNgjB3Io0B DGww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720718849; x=1721323649; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o4p0tg8Xj5vTmnTobwa3zRdSV9mSn2dUw2iMbgYCWTU=; b=dWR1etSKATA+AzSHvX7jcrGwFGYSL433v6kkbvURl9ZmY26b71oMc1W+Uj93vxkjv1 vJ4Y+2P186Ponc07+lU/+GO/YNHkJPODUph4cawuPcE9W2qucWEBbQx9PkjrTSTWNxeu jIFyyfQW61qMG7dpvabnNTKmQlQ+0omkuXkOfTmIz4q/q9282tOaPz50v09TTUEnIIzt Y86HgSxRmA8XrsoUdLfOSyp3yYz2GdFeAbgoFGfCzieVdjsjhE3p5oq9G09OWMnDF7Xs JhniM8azO+HZycZPKMObgFX1K/j6V7zoH45iJL5/oXY9ZAMWd4xa86qhSJ9Q6agwE7b3 +LVw== X-Gm-Message-State: AOJu0YxwXiyQcD+ywuYb4P5uC5l9kLmOz3FJXgFQBirGsnEOQVVD+xYI fw2FyzQzMM20EPptG4apKtMH3H7ib5I1xVjnTfwisAJx8EbkkUP/lHae6Q== X-Google-Smtp-Source: AGHT+IG8xOqYAWac8mg3FJ7juQmgejtaceCpbzOexT+nLRwvHvRX/bZomNoDUpb7mrkR2afaLSZSJw== X-Received: by 2002:a17:902:6bcb:b0:1fb:55d6:bdfb with SMTP id d9443c01a7336-1fbb6d90d98mr56780175ad.67.1720718848997; Thu, 11 Jul 2024 10:27:28 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4761:5ea8:2da4:8299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac0c47sm52976845ad.192.2024.07.11.10.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:27:28 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Sebastian Reichel Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/6] Input: tsc2004/5 - fix handling of VIO power supply Date: Thu, 11 Jul 2024 10:27:12 -0700 Message-ID: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The chip needs to be powered up before calling tsc200x_stop_scan() which communicates with it; move the call to enable the regulator earlier in tsc200x_probe(). At the same time switch to using devm_regulator_get_enable() to simplify error handling. This also makes sure that regulator is not shut off too early when unbinding the driver. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc2004.c | 6 ------ drivers/input/touchscreen/tsc2005.c | 6 ------ drivers/input/touchscreen/tsc200x-core.c | 27 ++++-------------------- drivers/input/touchscreen/tsc200x-core.h | 1 - 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/drivers/input/touchscreen/tsc2004.c b/drivers/input/touchscreen/tsc2004.c index b673098535ad..787f2caf4f73 100644 --- a/drivers/input/touchscreen/tsc2004.c +++ b/drivers/input/touchscreen/tsc2004.c @@ -42,11 +42,6 @@ static int tsc2004_probe(struct i2c_client *i2c) tsc2004_cmd); } -static void tsc2004_remove(struct i2c_client *i2c) -{ - tsc200x_remove(&i2c->dev); -} - static const struct i2c_device_id tsc2004_idtable[] = { { "tsc2004" }, { } @@ -70,7 +65,6 @@ static struct i2c_driver tsc2004_driver = { }, .id_table = tsc2004_idtable, .probe = tsc2004_probe, - .remove = tsc2004_remove, }; module_i2c_driver(tsc2004_driver); diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c index 1b40ce0ca1b9..6fe8b41b3ecc 100644 --- a/drivers/input/touchscreen/tsc2005.c +++ b/drivers/input/touchscreen/tsc2005.c @@ -64,11 +64,6 @@ static int tsc2005_probe(struct spi_device *spi) tsc2005_cmd); } -static void tsc2005_remove(struct spi_device *spi) -{ - tsc200x_remove(&spi->dev); -} - #ifdef CONFIG_OF static const struct of_device_id tsc2005_of_match[] = { { .compatible = "ti,tsc2005" }, @@ -85,7 +80,6 @@ static struct spi_driver tsc2005_driver = { .pm = pm_sleep_ptr(&tsc200x_pm_ops), }, .probe = tsc2005_probe, - .remove = tsc2005_remove, }; module_spi_driver(tsc2005_driver); diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index a4c0e9db9bb9..39789a27f65b 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -104,8 +104,6 @@ struct tsc200x { bool pen_down; - struct regulator *vio; - struct gpio_desc *reset_gpio; int (*tsc200x_cmd)(struct device *dev, u8 cmd); int irq; @@ -495,10 +493,9 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - ts->vio = devm_regulator_get(dev, "vio"); - if (IS_ERR(ts->vio)) { - error = PTR_ERR(ts->vio); - dev_err(dev, "error acquiring vio regulator: %d", error); + error = devm_regulator_get_enable(dev, "vio"); + if (error) { + dev_err(dev, "error acquiring vio regulator: %d\n", error); return error; } @@ -554,36 +551,20 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - error = regulator_enable(ts->vio); - if (error) - return error; - dev_set_drvdata(dev, ts); error = input_register_device(ts->idev); if (error) { dev_err(dev, "Failed to register input device, err: %d\n", error); - goto disable_regulator; + return error; } irq_set_irq_wake(irq, 1); return 0; - -disable_regulator: - regulator_disable(ts->vio); - return error; } EXPORT_SYMBOL_GPL(tsc200x_probe); -void tsc200x_remove(struct device *dev) -{ - struct tsc200x *ts = dev_get_drvdata(dev); - - regulator_disable(ts->vio); -} -EXPORT_SYMBOL_GPL(tsc200x_remove); - static int tsc200x_suspend(struct device *dev) { struct tsc200x *ts = dev_get_drvdata(dev); diff --git a/drivers/input/touchscreen/tsc200x-core.h b/drivers/input/touchscreen/tsc200x-core.h index 37de91efd78e..e76ba7a889dd 100644 --- a/drivers/input/touchscreen/tsc200x-core.h +++ b/drivers/input/touchscreen/tsc200x-core.h @@ -75,6 +75,5 @@ extern const struct attribute_group *tsc200x_groups[]; int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, struct regmap *regmap, int (*tsc200x_cmd)(struct device *dev, u8 cmd)); -void tsc200x_remove(struct device *dev); #endif From patchwork Thu Jul 11 17:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 812165 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DFCB15ECCA; Thu, 11 Jul 2024 17:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718852; cv=none; b=dTwZci87Tcq8a7lF67ukCsthQlyn+z4G0G6YQNcEgk3KwfOJJUmPqX06e7bMp3yahdyh+98myduXtzXhF9bO7BSlEYJhvezkPmtj+g/ZmA6w0/qXO4Am3ZnTQm+OU65ed1bW1bTjQlsoH4B2N5s0Oa7Zcf2JIRsILhwsma35DTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718852; c=relaxed/simple; bh=WpUZ4910FAKCZbHx5BKBePk11aG3Y1+CuAT+yvV1tTY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hcvdBhXP91wOgw8xqJvd8lV2sJYXHADScprGcvWXCVKEoN4Ku8g6QpKWYB5/9HFiwaJhKjOiOG/5YoNaVwibcCqBAWLrI/X2Nt65nB6Bt4ULj74gqD++oRBYy1qfhIOZAugpbcSY6U6VWigM9iVuutpAlQabBjes4ABKpdBiP8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LBwyQwjb; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LBwyQwjb" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fb4a332622so6981855ad.2; Thu, 11 Jul 2024 10:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720718850; x=1721323650; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pDdRinobJraWOj70a5x24jnbjy/LGvPgJQQBc3lXSlk=; b=LBwyQwjbz59BsmgIw/WKfHH+Fa9MYnll7oJDO4N58cFqk6eJVW0espuxouUy1lYvC2 j3YId1wWRNNaRubdCLpksDgFxCTRSjnm1J57fPQ8/hwIp9LJ0hRIPvm25H0Lf6YI+YPp YqVRHZwnWb3zP+z2q1Qg5krMZOD/crXfVAx4zCcKrE+j62lT2TD9RySl1A63IEH3NFF3 sbam+CFnPjuieVo0PYzMfgBxbutMz9xDOhD09OHUeS+bzmQaG/5REFasYyJLx8tINN+h kZHiw9PqFczayl8qFrRqDTV+sIB/pMrwsfyanpwvNI68ig/Wjd+za7mkbnDjJ+XjqgOq c8mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720718850; x=1721323650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pDdRinobJraWOj70a5x24jnbjy/LGvPgJQQBc3lXSlk=; b=UECSrZMjQzOlzCTdq2nWoTmpB8ac+KJ5jJoRI2Vy08KQKcsiDkHSz/MqkI5BpX2XzL VYOjhjltksENxiDcFyqQs9JJu19DfFsnnvJUzkhQBkoh9nHtjFhRDpAMJh0HCXp5Yy2U FXVIB1VI2QdoJsqcDrk4l1uAhB88UlFC3XoErxuuom7bC/rHSx/at8ylS2bXME/2H7Qi PmYWUpFdzKQHv/OMhX8SFhQeHbKSfxbBlablx6sSRuFox/5Ffey494LfLl2G8dkAqxKr 8Fv2i3iICYAJa40Wc7SJ/F0TeWWyHWQifipWX6FNzKyWb1gJPm5sJoAt6sxaEQDB9/a0 JCxw== X-Gm-Message-State: AOJu0YyG80BWdjxGG13ImOWp6wcmjD+9TvrDDmUtEEhEeBQzov38Akur PTJMC7IFvbJ1zX8YEwuBZa7GpfHkv9IsMjoojABEfI4bLxM/H6qBGFad/Q== X-Google-Smtp-Source: AGHT+IFZWm8ly54xvFNUuXX4lAEG19DGbsHPbEj9X/NenbaT9aM8VulqguSxGafjOmyfqKhv/hHapA== X-Received: by 2002:a17:902:e745:b0:1fb:19d1:707 with SMTP id d9443c01a7336-1fbb6d2519amr80738875ad.11.1720718850147; Thu, 11 Jul 2024 10:27:30 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4761:5ea8:2da4:8299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac0c47sm52976845ad.192.2024.07.11.10.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:27:29 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Sebastian Reichel Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/6] Input: tsc2004/5 - do not hard code interrupt trigger Date: Thu, 11 Jul 2024 10:27:13 -0700 Message-ID: <20240711172719.1248373-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> References: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of hard-coding interrupt trigger rely on ACPI/DT/board code to set it up appropriately. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index 39789a27f65b..cd539a2a1dd5 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -542,10 +542,8 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, /* Ensure the touchscreen is off */ tsc200x_stop_scan(ts); - error = devm_request_threaded_irq(dev, irq, NULL, - tsc200x_irq_thread, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - "tsc200x", ts); + error = devm_request_threaded_irq(dev, irq, NULL, tsc200x_irq_thread, + IRQF_ONESHOT, "tsc200x", ts); if (error) { dev_err(dev, "Failed to request irq, err: %d\n", error); return error; From patchwork Thu Jul 11 17:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 812535 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D6DA16D9C4; Thu, 11 Jul 2024 17:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718853; cv=none; b=vEQu/mZ0C/xRGhBUtzT0Zz6geB9xQ3HjUD9CezXxuXoDqhlcyoGSS+QP929LXaOcjD2viF0UAqanW7G4e58i5MMsTe4QWxE0dxP0+1CC8oSR/G1X8wjjhfF9NllEIo05E4DnFB1EXMaoWZlIzkkq2NfEBvqp4vHrXXN8rthNin8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718853; c=relaxed/simple; bh=LV2qkLwVkLu0UyvYvKa5w4mGcnJWYXxH4Pynyzbgdw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XLwB9fVjFVeZduHSIyBfqOC1jVzw57Db9qzTL8+Z5vfhTJD9txBd6d+7dYH9LfltGLtHYEKqydASF0boNFhIFL1bM1QiPm0PqM2a8NVEqf6r0I/6rBt/UfhPAdtWPk6X5VsbodvpVLau0xf5mqInjSA8YNDi2X8YKmx8/IOx3zg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m2ESpU2A; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m2ESpU2A" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1fb05ac6b77so8143425ad.0; Thu, 11 Jul 2024 10:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720718851; x=1721323651; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F1HlQyJZEZSdBP2lJm/bVCfQMFgVDPH4QbUxllsdPXs=; b=m2ESpU2AWr/SwEDNk5aHKri5Zq7x0Sy2o9eR9dIZp6Kjq3Qw0NbILYcGy618bL5lQs iXsTEWort066smUBP3E4+GcwA89+Yg9DeebChJpLSbd3Ibd4zMhhDWNTCm6v0BrzVPbw 57BOg83Ce3dR5uQagAdTYg1hxyGDIi3zXxq88SRwyBWCuZw5J0BMagasKdftSXPqBjJu 6AtFYgXnbWPKc7QzDLdOovu1KiKcde9/+zY6zofH86OvdEdp9JBHV9o6CQ+d+56xpvLp K8fuYwT3Nfw+0PVDezVSAJy+5ZMKqeQn5ss5cq1vO9bECvUxgJMkpedvxD1qdStcCw5J +Sbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720718851; x=1721323651; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F1HlQyJZEZSdBP2lJm/bVCfQMFgVDPH4QbUxllsdPXs=; b=fwua5mvujzG9Z+4nsNEOzzyMm+5cILEwYeLC9YQttbz9+1uKKfjx/D3Zv23NQZ77X/ 5O7d/jZF++cv77ATDiEiyewwF9SFOXC5eGJtgQborOj6tvdXi4O6mOmv5TY4/n4+sVFk FbVQbdpub0oNKrm42FQs5wN7W4FP87r5fgv0cz8Tu/BNu6LLfVo5Y8+35ClU6j0QUJIe LCzMYzwd2rdLs+pZKhqmGvF5ST3QaOZplbvappbAH0GrKQFGxTUhByicwSFHUb2513fG 85mNuKshosqiL4biedG/Disvz4DnIU2gW99zK+3bK/1iEIAwdpYKWWSx9PzL2YNh0lE8 Um8g== X-Gm-Message-State: AOJu0Yw+8XyejkkzVU5IGHFuDn7CZ2l3XAACYKrBSVrsoL2wQiK/N1fY rUV7IEupkfdIrF11abYNI8SG/FyiZofotJgHgjFXNPz6xmljcJmIyvvbzQ== X-Google-Smtp-Source: AGHT+IHT7fMeIaUUZxL/1MFKinxvV1RLGJFuukwC+TxrAA6s15NCPpTLUzX/7nP/BCxgRvVwh2ODWQ== X-Received: by 2002:a17:902:d4c6:b0:1fb:3474:9500 with SMTP id d9443c01a7336-1fbb6d4b98fmr80587975ad.27.1720718851150; Thu, 11 Jul 2024 10:27:31 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4761:5ea8:2da4:8299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac0c47sm52976845ad.192.2024.07.11.10.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:27:30 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Sebastian Reichel Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/6] Input: tsc2004/5 - fix reset handling on probe Date: Thu, 11 Jul 2024 10:27:14 -0700 Message-ID: <20240711172719.1248373-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> References: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When the driver has been converted to use gpiod API it was requesting and asserting the reset on probe, but never deasserted it. However because of incorrect annotations in device tree marking reset line as active high whereas in reality it is active low, the end result was that the chip was never reset on probe. With polarity of the reset line now corrected this became a problem. Fix this by calling tsc200x_reset() from tsc200x_probe() to properly complete the reset sequence and move requesting the reset GPIO and VIO supply closer to the point where we need to start talking to the hardware. Fixes: d257f2980feb ("Input: tsc2005 - convert to gpiod") Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 28 +++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index cd539a2a1dd5..87e6839c60fa 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -486,19 +486,6 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, &esd_timeout); ts->esd_timeout = error ? 0 : esd_timeout; - ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(ts->reset_gpio)) { - error = PTR_ERR(ts->reset_gpio); - dev_err(dev, "error acquiring reset gpio: %d\n", error); - return error; - } - - error = devm_regulator_get_enable(dev, "vio"); - if (error) { - dev_err(dev, "error acquiring vio regulator: %d\n", error); - return error; - } - mutex_init(&ts->mutex); spin_lock_init(&ts->lock); @@ -539,6 +526,21 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, touchscreen_parse_properties(input_dev, false, &ts->prop); + ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + error = PTR_ERR_OR_ZERO(ts->reset_gpio); + if (error) { + dev_err(dev, "error acquiring reset gpio: %d\n", error); + return error; + } + + error = devm_regulator_get_enable(dev, "vio"); + if (error) { + dev_err(dev, "error acquiring vio regulator: %d\n", error); + return error; + } + + tsc200x_reset(ts); + /* Ensure the touchscreen is off */ tsc200x_stop_scan(ts); From patchwork Thu Jul 11 17:27:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 812164 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A194016DEA4; Thu, 11 Jul 2024 17:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718855; cv=none; b=imaEaYB6zUmPvq7BFP9cGXbmdMvDhKlc4wSu0YcH0o1z2pEVj+2ASeo03Ir2V3YiMy4L5XK52bYzwFZqUrhFT2m2ju1AobLapxc/igUZ2HtZROKojJz0qUHipWk4aH3ZxrVzi6Yowbw06ywmInNfoBVAcTyZGT2RG0bLvthg0Yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718855; c=relaxed/simple; bh=g6RvsJvEBelZQYRBsDfESiSGLCnzJsuJi47mQGX69tI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ds3+SYaM22jZfbN+7H9QlklCWMasWFDJFHC4UbenRk9+vTDGnuQfCbGduE3bAkdSmwrbVgjW0IuCvw+oqq1qIGBnMx5VFr5+g/R4U6V0RFXFEOVrjeDADl//KkPFooskh3II4HFAvn/bDKLmjNa2xV2LDaf9emWuIRFgKMhehuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lAbgFgw+; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lAbgFgw+" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fbe6f83957so5802685ad.3; Thu, 11 Jul 2024 10:27:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720718853; x=1721323653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+BOesuwkLEFmcZ7ZJT5jxAmqXAgpT28qhJPsL9e5Gek=; b=lAbgFgw+kQhPAToJqgpuQq/YDUhp29NiwG4c17aqsTt8vNNg10kVTEOJpvDPF1eOJv vyoen5tTDlwquWmIBsANwHHYH+PptCuDl/dQGJR+nKfMOqLIHhPanIhlZnuTL4KTXxBa xP7FXMNEoisIQkyqAU9t1WjCMPVCi55VyarD+iQu+98cJu/LTyrXt1tBfpHKVRpIg/xK CFwbGOzKZFBHwJcGCy8dq7OAi6YUgMg3C+kw0jr1FV0WgDKx3PO0karyVdal8WL54P7J tNtQdJA/A9t2kim3zwkMcoMejKSNXVVV4Tu6NyMeCh9fI55AY1UbynMW19JRKFCTEBuQ MmPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720718853; x=1721323653; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+BOesuwkLEFmcZ7ZJT5jxAmqXAgpT28qhJPsL9e5Gek=; b=wrlnBIKBhN6oWpLwYvCEWtNOR9P+z3cDxGkdMcRAaZDp1FOh5Jt3EXC+7rOp8ws+8s XdRd1XqcJ/W89beqQg26OQtBwX4L3JOyqO57yY3veOjyVAIx7WCNe8hPFSBBOaClZxb2 3o/93fZtZqx0GNJxRBzi6LNdH+MP2juOVySDC80ScwczKyTdKCRKU+j9xYoglrwA7Vr4 3wZHBnN77KgPTM2afFrdP6G7RcC/OaBp6c/sxkYOPk9Nkds6H9vCwQQqugn6jzfVBYZh fe0+xRecbE6v0RGqk3E+CbUPBllVvX94kgdrz/G3FoqklQ6fszGyo9KTrff3XTFHhx3L B6TQ== X-Gm-Message-State: AOJu0Yx2IQNphTudWLagxi8hTnzHUgCCwv9lL134OZ3xuN0HSFauplqB mp0GbPeiOvTaANifOwqKmwuO0LaLt9rO7c3n9uwxn6yeEgCyMAsGcYk2bQ== X-Google-Smtp-Source: AGHT+IHZo1R3wkEolk/aOQEV88/4xoSeprWRPeZYVx1grAOHtqrRU82RG481zF+vOAOMw5dtx3mGmg== X-Received: by 2002:a17:903:283:b0:1fb:8a0e:7730 with SMTP id d9443c01a7336-1fbb6d4b03cmr78219085ad.26.1720718852429; Thu, 11 Jul 2024 10:27:32 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4761:5ea8:2da4:8299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac0c47sm52976845ad.192.2024.07.11.10.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:27:31 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Sebastian Reichel Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/6] Input: tsc2004/5 - do not use irq_set_irq_wake() directly Date: Thu, 11 Jul 2024 10:27:15 -0700 Message-ID: <20240711172719.1248373-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> References: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of setting irq_set_irq_wake() directly in probe(), mark the device as wakeup-capable, and use enable_irq_wake() and disable_irq_wake() in suspend/resume path. This also allows changing the wakeup setting dynamically at runtime using /sys/devices/.../tsc2005/power/wakeup. Reviewed-By: Sebastian Reichel Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index 87e6839c60fa..cd60bba11c56 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -106,7 +106,9 @@ struct tsc200x { struct gpio_desc *reset_gpio; int (*tsc200x_cmd)(struct device *dev, u8 cmd); + int irq; + bool wake_irq_enabled; }; static void tsc200x_update_pen_state(struct tsc200x *ts, @@ -560,7 +562,8 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - irq_set_irq_wake(irq, 1); + device_init_wakeup(dev, true); + return 0; } EXPORT_SYMBOL_GPL(tsc200x_probe); @@ -576,6 +579,9 @@ static int tsc200x_suspend(struct device *dev) ts->suspended = true; + if (device_may_wakeup(dev)) + ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0; + mutex_unlock(&ts->mutex); return 0; @@ -587,6 +593,11 @@ static int tsc200x_resume(struct device *dev) mutex_lock(&ts->mutex); + if (ts->wake_irq_enabled) { + disable_irq_wake(ts->irq); + ts->wake_irq_enabled = false; + } + if (ts->suspended && ts->opened) __tsc200x_enable(ts); From patchwork Thu Jul 11 17:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 812534 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C9BC16DECA; Thu, 11 Jul 2024 17:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718855; cv=none; b=GN5sIOPrpLIHcgDXtBiWFY+b2zRJ22JpidOHB9l4/TXW1PwA52rj4/yd6CoQndYZbeWhX2doZl7WckY3MmbjufXjBN8uYBOsmhqyRue6LGQr42u1gIc8Ua39S0L/rKgovKcquJBJjTLtpcEbjpzxoBO4Krs6MwKrU46kc/6innM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718855; c=relaxed/simple; bh=S0B2HbygtW78j59qAIn8nvGwDPiM05kQbGtLwRcc+Ng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oQA1IGGSFfb9CdZK6syNFJ3I+hsiKvGQC1fkRYVBG7hbEL/28UPvorNc0EC5xq4+N6UrbStM9JRRgfr119tXEXj8n8mfOm2Rqsl8Cfl0WzgKl+g7MH+/BJeCnUBkORoKfr4njWFgb71DrfQCz+tWriavzXQAMzhgcvKjRJjyyMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QsGpIvJD; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QsGpIvJD" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fb222a8eaeso8535545ad.3; Thu, 11 Jul 2024 10:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720718854; x=1721323654; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rA2/faQDE8NDG1pdgSxWKLM3H2RgF90oPqOM5cxk59Q=; b=QsGpIvJDzD6k6pUkIvRGc8+xE53w+m2JcSzFe/qXtAd/ZUvx1aHAgAnxZP0xfgqflo Mbc/rDBoIbrpJd9FyPrgB46o5fEvEIR+Boh0ySF4/XTvlFFsgQ9Ciq6Vwg4QGOYfrrBZ +D/xGuHG64LmJdTurAR18tcTGTkOWhJzjOi4E2KDq/yCg++iiIh7jKWr9hY5jJhjm69E UMaFnFdW7H9JdR9LSWg+uPG2NS7J7VhNNZIEojDQnfbbd7GPM4sLlqqBjRy8SuZcnFWp bHUEcnU1Ap6qRPaMFgO8KVyAP8pO75XHXAB3AbmMz2lR5fKsA7LQCyTg0H7oQI4tML6E +4ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720718854; x=1721323654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rA2/faQDE8NDG1pdgSxWKLM3H2RgF90oPqOM5cxk59Q=; b=STJlVIVmtGOdmUFnpionX480ghZJiDw6U2tjpBXydZcfCSaR/MYH9UH9dDQ5K3j8da uZRECdxnptKe1CJJ4vA+yCwUstjZz7I6LWgsJ7E8t/GkIRUS9p2Z6pHBAvV+csqKSTxB XaDHBpGSYihvm8bHpupXIhj1YJclJ0ZkANAofLlbHBD6pRYpsbbRSlxMdZBa4A7jtfYd oCvSr6HlQo0RwKOGzcY9mS23LztJn15pSFEV++XmpHT/OFskJKD+UPhMl34RWOyZqzyU JgMDNK2EeVrIKbv9zhrWKnKLNjoowBIRBaCywmyuj/73MG9WCE8b9b+/l8DgkCYm4eMS ga/A== X-Gm-Message-State: AOJu0YyDSJCo8XBNE0WTaDXrV4ucnNRND9e2JCXCaeOduTDmMDvjByH2 74mFHPiB5XfnI1ZZEskjz0XODAhbIyPEWS6i0eTaivFEtduoYfm61Tp74w== X-Google-Smtp-Source: AGHT+IFRFDfW48GcKZ8xYZ6jsK4EZZDrETjnpEkIBvBlDJ2oUJIgQLdk1hl7yqY6SIyVrozQokZZ7A== X-Received: by 2002:a17:903:1249:b0:1fb:9115:bb4a with SMTP id d9443c01a7336-1fbb6d03e81mr83917075ad.25.1720718853671; Thu, 11 Jul 2024 10:27:33 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4761:5ea8:2da4:8299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac0c47sm52976845ad.192.2024.07.11.10.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:27:33 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Sebastian Reichel Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/6] Input: tsc2004/5 - respect "wakeup-source" property Date: Thu, 11 Jul 2024 10:27:16 -0700 Message-ID: <20240711172719.1248373-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> References: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not mark the device as wakeup-enabled by default, respect the standard "wakeup-source" property. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index cd60bba11c56..90a4ace22395 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -562,7 +562,8 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - device_init_wakeup(dev, true); + device_init_wakeup(dev, + device_property_read_bool(dev, "wakeup-source")); return 0; } From patchwork Thu Jul 11 17:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 812163 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9312616E878; Thu, 11 Jul 2024 17:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718857; cv=none; b=MoaqaNvihLja1s4EAnSH/Sz4nWKycTfjV+dBrTo3Ng5M+PRv3Bmqc2QVRhSoxEH3A2T0PC/YojAxsIL/f7nzUwXO40kxTZ4l7ubsXOFtD72cWGQi28X1Wd0rHnQcRM9dd8bHIgMNq1lU929EEuUkmmBHuc7ZAoc6jVDGYMwOUE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720718857; c=relaxed/simple; bh=vilKhUUp1F+MZIj0uO7zSq7oX8Zcara/icd/g4/7Kxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XR7Cxfoydk9t5RY7ndZdt5iPI8kzOVGaeqiPXEZP+ebwfQQrK4v/o1YZ/jY/bDMi5edX0zzBheRYC4AJfNeZhl1JKSQVuw2eLLR4zdaAlBxFsu4Lcu6YdN4YcjjEVxKVZD3znZjB9v5vu4UvAQSUa8vHf9OthYz+81rXLYz4BU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pi2ZbDAM; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pi2ZbDAM" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fb3b7d0d3aso7407575ad.2; Thu, 11 Jul 2024 10:27:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720718855; x=1721323655; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x4mDefsZgBQ378aN495JR7WYtld5yrNiQ6vTJoNaTSI=; b=Pi2ZbDAMWCSJVwnlG+UOXtIoDc/U14W97bnG+Me2vUXOWuIHHGcxS7I2qLNB9HYrCh hzFmvg+iMz8cmnRbcKjFodXSvXndtxCHEyBbD0kW+hGcObFnh/fyB4P4SNluuT/El7eM fS3yrFRopLOANHTX7++snBpTvYp646FKI4EbByb+JvMB492TLKcA7mfLezC/KUgqLcaY M1N8c/mSoL6YUB2JatHuX9QC8sxeC9awRsxag+yipfSyDogdstobUnS9ZOI782US1z/u ctFChaLkB6B6ZeQBG+Hp4cCX/MZWiivpbVqT8EIrxjZgr8+ig+j5MTVFoJt4AJrzkzxo G2Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720718855; x=1721323655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x4mDefsZgBQ378aN495JR7WYtld5yrNiQ6vTJoNaTSI=; b=r/aNEUAp3YIRjekfDDLiQABuEkSIRDYgT/C2sb+5RCf6hndfVZMq5qUkc7xh23Dj4P 81G9byYLMRqwvwHKNnGT5uiQxHYmd5eFUZghLGOOmGuToaCWQYB0KsacH+LgGLgkgzOv qyASYNh9mbr/9DFCWdXSWelqKXsvDFuFZfPThsAzYn2AkD29zVKXNX2K40fEYJC19hqJ RNcqUqqzziNCmuOmIjQIrIAAj+aLqSs/3wjKMjpWyxYBhf1e91aOJTet7OY6LSoRKpxZ XTfRAViKQ0dBjVHko5vJZ5sxCjNkhWdodtOd2r1AuqmpJyYnRq2M6MHenfo5YUEIxCQf VLnw== X-Gm-Message-State: AOJu0YzzoAwzSG3r2kC7w7MTG1Xkl0Ptz1Yrd/lrmOsAURaJW79jbhAc ZCr3wBgngzohVy+1SGzbZBVdVJedAa4LTHoYBBSOqmpJi09picvqJordDQ== X-Google-Smtp-Source: AGHT+IEMZS/+bfL3E/AK+mXvX5H71jbxTYFuRFI2y7uRAbgJRaA8A6XKdaeXhbn/oYqMPYMNzc8fBA== X-Received: by 2002:a17:902:d646:b0:1fb:3d7:1cfc with SMTP id d9443c01a7336-1fbb6d03e06mr54400055ad.20.1720718854522; Thu, 11 Jul 2024 10:27:34 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4761:5ea8:2da4:8299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac0c47sm52976845ad.192.2024.07.11.10.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:27:34 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Sebastian Reichel Cc: linux-kernel@vger.kernel.org Subject: [PATCH 6/6] Input: tsc2004/5 - use guard notation when acquiring mutexes/locks Date: Thu, 11 Jul 2024 10:27:17 -0700 Message-ID: <20240711172719.1248373-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> References: <20240711172719.1248373-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This makes the code more compact and error handling more robust. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 182 ++++++++++------------- 1 file changed, 81 insertions(+), 101 deletions(-) diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index 90a4ace22395..df39dee13e1c 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -136,7 +136,6 @@ static void tsc200x_update_pen_state(struct tsc200x *ts, static irqreturn_t tsc200x_irq_thread(int irq, void *_ts) { struct tsc200x *ts = _ts; - unsigned long flags; unsigned int pressure; struct tsc200x_data tsdata; int error; @@ -182,13 +181,11 @@ static irqreturn_t tsc200x_irq_thread(int irq, void *_ts) if (unlikely(pressure > MAX_12BIT)) goto out; - spin_lock_irqsave(&ts->lock, flags); - - tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); - mod_timer(&ts->penup_timer, - jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS)); - - spin_unlock_irqrestore(&ts->lock, flags); + scoped_guard(spinlock_irqsave, &ts->lock) { + tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); + mod_timer(&ts->penup_timer, + jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS)); + } ts->last_valid_interrupt = jiffies; out: @@ -198,11 +195,9 @@ static irqreturn_t tsc200x_irq_thread(int irq, void *_ts) static void tsc200x_penup_timer(struct timer_list *t) { struct tsc200x *ts = from_timer(ts, t, penup_timer); - unsigned long flags; - spin_lock_irqsave(&ts->lock, flags); + guard(spinlock_irqsave)(&ts->lock); tsc200x_update_pen_state(ts, 0, 0, 0); - spin_unlock_irqrestore(&ts->lock, flags); } static void tsc200x_start_scan(struct tsc200x *ts) @@ -232,12 +227,10 @@ static void __tsc200x_disable(struct tsc200x *ts) { tsc200x_stop_scan(ts); - disable_irq(ts->irq); - del_timer_sync(&ts->penup_timer); + guard(disable_irq)(&ts->irq); + del_timer_sync(&ts->penup_timer); cancel_delayed_work_sync(&ts->esd_work); - - enable_irq(ts->irq); } /* must be called with ts->mutex held */ @@ -253,80 +246,79 @@ static void __tsc200x_enable(struct tsc200x *ts) } } -static ssize_t tsc200x_selftest_show(struct device *dev, - struct device_attribute *attr, - char *buf) +/* + * Test TSC200X communications via temp high register. + */ +static int tsc200x_do_selftest(struct tsc200x *ts) { - struct tsc200x *ts = dev_get_drvdata(dev); - unsigned int temp_high; unsigned int temp_high_orig; unsigned int temp_high_test; - bool success = true; + unsigned int temp_high; int error; - mutex_lock(&ts->mutex); - - /* - * Test TSC200X communications via temp high register. - */ - __tsc200x_disable(ts); - error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); if (error) { - dev_warn(dev, "selftest failed: read error %d\n", error); - success = false; - goto out; + dev_warn(ts->dev, "selftest failed: read error %d\n", error); + return error; } temp_high_test = (temp_high_orig - 1) & MAX_12BIT; error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); if (error) { - dev_warn(dev, "selftest failed: write error %d\n", error); - success = false; - goto out; + dev_warn(ts->dev, "selftest failed: write error %d\n", error); + return error; } error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); if (error) { - dev_warn(dev, "selftest failed: read error %d after write\n", - error); - success = false; - goto out; - } - - if (temp_high != temp_high_test) { - dev_warn(dev, "selftest failed: %d != %d\n", - temp_high, temp_high_test); - success = false; + dev_warn(ts->dev, + "selftest failed: read error %d after write\n", error); + return error; } /* hardware reset */ tsc200x_reset(ts); - if (!success) - goto out; + if (temp_high != temp_high_test) { + dev_warn(ts->dev, "selftest failed: %d != %d\n", + temp_high, temp_high_test); + return -EINVAL; + } /* test that the reset really happened */ error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); if (error) { - dev_warn(dev, "selftest failed: read error %d after reset\n", - error); - success = false; - goto out; + dev_warn(ts->dev, + "selftest failed: read error %d after reset\n", error); + return error; } if (temp_high != temp_high_orig) { - dev_warn(dev, "selftest failed after reset: %d != %d\n", + dev_warn(ts->dev, "selftest failed after reset: %d != %d\n", temp_high, temp_high_orig); - success = false; + return -EINVAL; } -out: - __tsc200x_enable(ts); - mutex_unlock(&ts->mutex); + return 0; +} - return sprintf(buf, "%d\n", success); +static ssize_t tsc200x_selftest_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct tsc200x *ts = dev_get_drvdata(dev); + int error; + + scoped_guard(mutex, &ts->mutex) { + __tsc200x_disable(ts); + + error = tsc200x_do_selftest(ts); + + __tsc200x_enable(ts); + } + + return sprintf(buf, "%d\n", !error); } static DEVICE_ATTR(selftest, S_IRUGO, tsc200x_selftest_show, NULL); @@ -368,46 +360,42 @@ static void tsc200x_esd_work(struct work_struct *work) int error; unsigned int r; - if (!mutex_trylock(&ts->mutex)) { - /* - * If the mutex is taken, it means that disable or enable is in - * progress. In that case just reschedule the work. If the work - * is not needed, it will be canceled by disable. - */ - goto reschedule; - } - - if (time_is_after_jiffies(ts->last_valid_interrupt + - msecs_to_jiffies(ts->esd_timeout))) - goto out; - - /* We should be able to read register without disabling interrupts. */ - error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); - if (!error && - !((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) { - goto out; - } - /* - * If we could not read our known value from configuration register 0 - * then we should reset the controller as if from power-up and start - * scanning again. + * If the mutex is taken, it means that disable or enable is in + * progress. In that case just reschedule the work. If the work + * is not needed, it will be canceled by disable. */ - dev_info(ts->dev, "TSC200X not responding - resetting\n"); + scoped_guard(mutex_try, &ts->mutex) { + if (time_is_after_jiffies(ts->last_valid_interrupt + + msecs_to_jiffies(ts->esd_timeout))) + break; - disable_irq(ts->irq); - del_timer_sync(&ts->penup_timer); + /* + * We should be able to read register without disabling + * interrupts. + */ + error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); + if (!error && + !((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) { + break; + } - tsc200x_update_pen_state(ts, 0, 0, 0); + /* + * If we could not read our known value from configuration + * register 0 then we should reset the controller as if from + * power-up and start scanning again. + */ + dev_info(ts->dev, "TSC200X not responding - resetting\n"); - tsc200x_reset(ts); + scoped_guard(disable_irq, &ts->irq) { + del_timer_sync(&ts->penup_timer); + tsc200x_update_pen_state(ts, 0, 0, 0); + tsc200x_reset(ts); + } - enable_irq(ts->irq); - tsc200x_start_scan(ts); + tsc200x_start_scan(ts); + } -out: - mutex_unlock(&ts->mutex); -reschedule: /* re-arm the watchdog */ schedule_delayed_work(&ts->esd_work, round_jiffies_relative( @@ -418,15 +406,13 @@ static int tsc200x_open(struct input_dev *input) { struct tsc200x *ts = input_get_drvdata(input); - mutex_lock(&ts->mutex); + guard(mutex)(&ts->mutex); if (!ts->suspended) __tsc200x_enable(ts); ts->opened = true; - mutex_unlock(&ts->mutex); - return 0; } @@ -434,14 +420,12 @@ static void tsc200x_close(struct input_dev *input) { struct tsc200x *ts = input_get_drvdata(input); - mutex_lock(&ts->mutex); + guard(mutex)(&ts->mutex); if (!ts->suspended) __tsc200x_disable(ts); ts->opened = false; - - mutex_unlock(&ts->mutex); } int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, @@ -573,7 +557,7 @@ static int tsc200x_suspend(struct device *dev) { struct tsc200x *ts = dev_get_drvdata(dev); - mutex_lock(&ts->mutex); + guard(mutex)(&ts->mutex); if (!ts->suspended && ts->opened) __tsc200x_disable(ts); @@ -583,8 +567,6 @@ static int tsc200x_suspend(struct device *dev) if (device_may_wakeup(dev)) ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0; - mutex_unlock(&ts->mutex); - return 0; } @@ -592,7 +574,7 @@ static int tsc200x_resume(struct device *dev) { struct tsc200x *ts = dev_get_drvdata(dev); - mutex_lock(&ts->mutex); + guard(mutex)(&ts->mutex); if (ts->wake_irq_enabled) { disable_irq_wake(ts->irq); @@ -604,8 +586,6 @@ static int tsc200x_resume(struct device *dev) ts->suspended = false; - mutex_unlock(&ts->mutex); - return 0; }