From patchwork Thu Jan 25 13:37:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 767052 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D136857317; Thu, 25 Jan 2024 13:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706189872; cv=none; b=dUjGL5CPrVLYHskw9+4G4KZ8d2hl7WwupNJF4G/dAxrOI0ejwjY3Tt9+hoOeeonzwff3GkfxapeRC+cMZ7V8CSrBcAYNa+xZosC6DvqzIahwpy+yetDM73NJbBrpnkLv+4heRy/X0w8tIkZkcVymo1Ox1ccRSTI4NxhuDqymc3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706189872; c=relaxed/simple; bh=aecc4VtS3J2A+wtS8gtU/czKhW9ts0HJzNfn1FTkt3Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WBaQKNnumiuIpkv0peBbTDYGpOLG0UhKEVV2JY/vINbzbRaW/aOfcvBWUKXIl4N6mRUxXTpAvc8ogdF3O0kcRJl+yngWyZum7gSCNXz7IQ6fc418Nt17Cihsu1b3HMdzELNa4NjIB5GGRDxB87eSlw1XD1Gy8lGN0YY6l26jSqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.05,216,1701097200"; d="scan'208";a="191712565" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 25 Jan 2024 22:37:42 +0900 Received: from localhost.localdomain (unknown [10.226.92.215]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id D718A42C93B0; Thu, 25 Jan 2024 22:37:39 +0900 (JST) From: Biju Das To: Dmitry Torokhov Cc: Biju Das , Support Opensource , linux-input@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 1/3] Input: da9063_onkey - Add da9063_onkey_report_key() Date: Thu, 25 Jan 2024 13:37:31 +0000 Message-Id: <20240125133733.95081-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240125133733.95081-1-biju.das.jz@bp.renesas.com> References: <20240125133733.95081-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adding da9063_onkey_report_key() for reporting key events makes the code simpler. So, simplify it. While at it, update multiline code that can fit to single line. Signed-off-by: Biju Das --- v3: * New patch. --- drivers/input/misc/da9063_onkey.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c index c338765e0ecd..06ad9d09ada8 100644 --- a/drivers/input/misc/da9063_onkey.c +++ b/drivers/input/misc/da9063_onkey.c @@ -75,6 +75,13 @@ static const struct da906x_chip_config da9062_regs = { .name = "da9062-onkey", }; +static void da9063_onkey_report_key(struct da9063_onkey *onkey, + unsigned int code, int value) +{ + input_report_key(onkey->input, code, value); + input_sync(onkey->input); +} + static void da9063_poll_on(struct work_struct *work) { struct da9063_onkey *onkey = container_of(work, @@ -87,12 +94,9 @@ static void da9063_poll_on(struct work_struct *work) int error; /* Poll to see when the pin is released */ - error = regmap_read(onkey->regmap, - config->onkey_status, - &val); + error = regmap_read(onkey->regmap, config->onkey_status, &val); if (error) { - dev_err(onkey->dev, - "Failed to read ON status: %d\n", error); + dev_err(onkey->dev, "Failed to read ON status: %d\n", error); goto err_poll; } @@ -107,8 +111,7 @@ static void da9063_poll_on(struct work_struct *work) goto err_poll; } - input_report_key(onkey->input, KEY_POWER, 0); - input_sync(onkey->input); + da9063_onkey_report_key(onkey, KEY_POWER, 0); poll = false; } @@ -159,19 +162,13 @@ static irqreturn_t da9063_onkey_irq_handler(int irq, void *data) unsigned int val; int error; - error = regmap_read(onkey->regmap, - config->onkey_status, - &val); + error = regmap_read(onkey->regmap, config->onkey_status, &val); + da9063_onkey_report_key(onkey, KEY_POWER, 1); if (onkey->key_power && !error && (val & config->onkey_nonkey_mask)) { - input_report_key(onkey->input, KEY_POWER, 1); - input_sync(onkey->input); schedule_delayed_work(&onkey->work, 0); dev_dbg(onkey->dev, "KEY_POWER long press.\n"); } else { - input_report_key(onkey->input, KEY_POWER, 1); - input_sync(onkey->input); - input_report_key(onkey->input, KEY_POWER, 0); - input_sync(onkey->input); + da9063_onkey_report_key(onkey, KEY_POWER, 0); dev_dbg(onkey->dev, "KEY_POWER short press.\n"); } From patchwork Thu Jan 25 13:37:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 766191 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 844EF57317; Thu, 25 Jan 2024 13:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706189874; cv=none; b=QmGejuHgjbbjNvWTyF97Rkfimfq5z90qOVfysx+XADzD9XMZdoL/fZHqVKPdaQHyx3b1arTI5AoZRkHMU0a3JSUhchLRP2Dy+L+Q+ev1LXoXyJ/B6Hc9lFaeOaawzBvdX0DZSs6jEuYLTjWn3Uz/ZLyH/rz/6xBRJGiekEBUuHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706189874; c=relaxed/simple; bh=uwWvPBBLizGvEQ452Or9FXvr01UgQnxipDT2WEbzpqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ELcfXhtWOordSxnLVV3Tvmye6iiL+NbfozllLO2cnx65M0+zlSvPWtZV0qu0QoVufUAmHYl0bAUqsQo4aOZNmQwMP929wgczje1C6qx+9py5rcefTqb/FvP5qFEm2hvy//NFtxaGD5Ms8h008hSc8JIsjA4zxfIHqDEjSrdJCUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.05,216,1701097200"; d="scan'208";a="195621352" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 25 Jan 2024 22:37:45 +0900 Received: from localhost.localdomain (unknown [10.226.92.215]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 047BC42C93AB; Thu, 25 Jan 2024 22:37:42 +0900 (JST) From: Biju Das To: Dmitry Torokhov Cc: Biju Das , Support Opensource , linux-input@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 2/3] Input: da9063_onkey - Drop scheduling work Date: Thu, 25 Jan 2024 13:37:32 +0000 Message-Id: <20240125133733.95081-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240125133733.95081-1-biju.das.jz@bp.renesas.com> References: <20240125133733.95081-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On threaded case it might be cleaner to avoid scheduling work and simply loop in the interrupt thread as it can sleep. Suggested-by: Dmitry Torokhov Signed-off-by: Biju Das --- drivers/input/misc/da9063_onkey.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c index 06ad9d09ada8..e5256bf31140 100644 --- a/drivers/input/misc/da9063_onkey.c +++ b/drivers/input/misc/da9063_onkey.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -36,7 +35,6 @@ struct da906x_chip_config { }; struct da9063_onkey { - struct delayed_work work; struct input_dev *input; struct device *dev; struct regmap *regmap; @@ -82,11 +80,8 @@ static void da9063_onkey_report_key(struct da9063_onkey *onkey, input_sync(onkey->input); } -static void da9063_poll_on(struct work_struct *work) +static bool da9063_poll_on(struct da9063_onkey *onkey) { - struct da9063_onkey *onkey = container_of(work, - struct da9063_onkey, - work.work); const struct da906x_chip_config *config = onkey->config; unsigned int val; int fault_log = 0; @@ -151,8 +146,7 @@ static void da9063_poll_on(struct work_struct *work) } err_poll: - if (poll) - schedule_delayed_work(&onkey->work, msecs_to_jiffies(50)); + return poll; } static irqreturn_t da9063_onkey_irq_handler(int irq, void *data) @@ -165,7 +159,8 @@ static irqreturn_t da9063_onkey_irq_handler(int irq, void *data) error = regmap_read(onkey->regmap, config->onkey_status, &val); da9063_onkey_report_key(onkey, KEY_POWER, 1); if (onkey->key_power && !error && (val & config->onkey_nonkey_mask)) { - schedule_delayed_work(&onkey->work, 0); + while (da9063_poll_on(onkey)) + msleep(50); dev_dbg(onkey->dev, "KEY_POWER long press.\n"); } else { da9063_onkey_report_key(onkey, KEY_POWER, 0); @@ -211,11 +206,6 @@ static int da9063_onkey_probe(struct platform_device *pdev) input_set_capability(onkey->input, EV_KEY, KEY_POWER); - error = devm_delayed_work_autocancel(&pdev->dev, &onkey->work, - da9063_poll_on); - if (error) - return error; - irq = platform_get_irq_byname(pdev, "ONKEY"); if (irq < 0) return irq; From patchwork Thu Jan 25 13:37:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 766192 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DEE356B75; Thu, 25 Jan 2024 13:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706189871; cv=none; b=dvjoXFVzwmCGJqWliCS7GiEeFO0RwF4ZKsl1b8VUMbnM2JBTTS0ZD9lhrW7s4UHC0r5IB0qJqJBOZseYcNrk1ofayTFQJDjWhyaemAdjLjeQDkzMM/UW6tuYBmC/89hv7bciSWk0kx9QCsbMZQgmu7MaZ610WShyOkOlbDRecFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706189871; c=relaxed/simple; bh=tDakhK7MuPp1CjIbCF97eY1KYSROvJFeTa/X8T74ivw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ib73HDSgCFpFC+qHnp2YBPy5ukHd+40ZiZZW9p5w0F3LnfEufrQ5oUTjjhO5c9X722NuEa0Nt2II1YadSzXx4Z1mAzpKTALt3KDy81bWpCtuK9PrJ6ySfFc3ByOEcRnwRNqzlkI8Epnxqlq/5LzUE5faXlvJelGAo/kgPKPGRvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.05,216,1701097200"; d="scan'208";a="191712569" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 25 Jan 2024 22:37:48 +0900 Received: from localhost.localdomain (unknown [10.226.92.215]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 2661842C93B0; Thu, 25 Jan 2024 22:37:45 +0900 (JST) From: Biju Das To: Dmitry Torokhov Cc: Biju Das , Support Opensource , linux-input@vger.kernel.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 3/3] Input: da9063_onkey - Add polling support Date: Thu, 25 Jan 2024 13:37:33 +0000 Message-Id: <20240125133733.95081-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240125133733.95081-1-biju.das.jz@bp.renesas.com> References: <20240125133733.95081-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some platforms (eg: RZ/{G2UL,Five} SMARC EVK), there is no onkey IRQ populated by default. Add polling support. Signed-off-by: Biju Das --- v2->v3: * Updated commit description as cleanup is done in patch#1 * Dropped scheduling work instead start using polling as in the polling * case scheduling any additional works will create confused state for * driver if we repeatedly open and close input device. v1->v2: * Updated commit description * Fixed the logical mistake for optional IRQ handling. --- drivers/input/misc/da9063_onkey.c | 83 ++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c index e5256bf31140..71f1325b309b 100644 --- a/drivers/input/misc/da9063_onkey.c +++ b/drivers/input/misc/da9063_onkey.c @@ -19,6 +19,8 @@ #include #include +#define DA9062_KEY_THRESHOLD_MSEC (200) + struct da906x_chip_config { /* REGS */ int onkey_status; @@ -41,6 +43,8 @@ struct da9063_onkey { const struct da906x_chip_config *config; char phys[32]; bool key_power; + unsigned int poll_interval; + unsigned int key_threshold_release_time; }; static const struct da906x_chip_config da9063_regs = { @@ -95,6 +99,22 @@ static bool da9063_poll_on(struct da9063_onkey *onkey) goto err_poll; } + if (onkey->poll_interval && + onkey->key_threshold_release_time <= DA9062_KEY_THRESHOLD_MSEC) { + bool ret = true; + + /* detect short or long key press */ + if (!(val & config->onkey_nonkey_mask)) { + da9063_onkey_report_key(onkey, KEY_POWER, 0); + onkey->key_threshold_release_time = 0; + dev_dbg(onkey->dev, "KEY_POWER short press.\n"); + ret = false; + } else { + onkey->key_threshold_release_time += 50; + } + return ret; + } + if (!(val & config->onkey_nonkey_mask)) { error = regmap_update_bits(onkey->regmap, config->onkey_pwr_signalling, @@ -170,6 +190,21 @@ static irqreturn_t da9063_onkey_irq_handler(int irq, void *data) return IRQ_HANDLED; } +static void da9063_onkey_polled_poll(struct input_dev *input) +{ + struct da9063_onkey *onkey = input_get_drvdata(input); + const struct da906x_chip_config *config = onkey->config; + unsigned int val; + int error; + + error = regmap_read(onkey->regmap, config->onkey_status, &val); + if (onkey->key_power && !error && (val & config->onkey_nonkey_mask)) { + da9063_onkey_report_key(onkey, KEY_POWER, 1); + while (da9063_poll_on(onkey)) + msleep(50); + } +} + static int da9063_onkey_probe(struct platform_device *pdev) { struct da9063_onkey *onkey; @@ -206,25 +241,37 @@ static int da9063_onkey_probe(struct platform_device *pdev) input_set_capability(onkey->input, EV_KEY, KEY_POWER); - irq = platform_get_irq_byname(pdev, "ONKEY"); - if (irq < 0) + irq = platform_get_irq_byname_optional(pdev, "ONKEY"); + if (irq >= 0) { + error = devm_request_threaded_irq(&pdev->dev, irq, + NULL, da9063_onkey_irq_handler, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "ONKEY", onkey); + if (error) + return dev_err_probe(&pdev->dev, error, + "Failed to allocate onkey irq\n"); + + error = dev_pm_set_wake_irq(&pdev->dev, irq); + if (error) + dev_warn(&pdev->dev, + "Failed to set IRQ %d as a wake IRQ: %d\n", + irq, error); + else + device_init_wakeup(&pdev->dev, true); + } else if (irq != -ENXIO) { return irq; - - error = devm_request_threaded_irq(&pdev->dev, irq, - NULL, da9063_onkey_irq_handler, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, - "ONKEY", onkey); - if (error) - return dev_err_probe(&pdev->dev, error, - "Failed to allocate onkey IRQ\n"); - - error = dev_pm_set_wake_irq(&pdev->dev, irq); - if (error) - dev_warn(&pdev->dev, - "Failed to set IRQ %d as a wake IRQ: %d\n", - irq, error); - else - device_init_wakeup(&pdev->dev, true); + } else { + input_set_drvdata(onkey->input, onkey); + device_property_read_u32(&pdev->dev, "poll-interval", + &onkey->poll_interval); + error = input_setup_polling(onkey->input, + da9063_onkey_polled_poll); + if (error) + return dev_err_probe(&pdev->dev, error, + "unable to set up polling\n"); + + input_set_poll_interval(onkey->input, onkey->poll_interval); + } error = input_register_device(onkey->input); if (error)