From patchwork Fri Mar 24 13:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 74535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp622705vqo; Fri, 24 Mar 2023 06:24:53 -0700 (PDT) X-Google-Smtp-Source: AKy350ZnOEeX6FaxjGF/LQP4V5B0+x8VbXg7TTUzU1V9DrYny43/t0b9l7kGyQAYPgUwyRtXswIE X-Received: by 2002:aa7:c490:0:b0:4fa:315a:cb55 with SMTP id m16-20020aa7c490000000b004fa315acb55mr3336717edq.21.1679664293444; Fri, 24 Mar 2023 06:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679664293; cv=none; d=google.com; s=arc-20160816; b=mkrdWGEte7ZiPedGEuIUT9ywfKAg6gGx/1LuheiMZbTJ+ktlJqvWUfX9sfd9QKqlEh +RRZwu7y18N3pK+RMZHmYYpLAfGhQOCYwhlwVFnSUqbN+wlXr2vEpMgD5Qq6AgqncAjW mDDekZdrYOMvz42RYYWYXK5KtxgiGcQMmdBtRSsVa7VVWrGCOd5pkS6c5iRkYeAFWj8U j/w8AtRotLpOp/tcidy7tku/mn/BYMDUanWK0iTJa3f5+mMcF/JArbWhqg3zkQF8aUE/ XUoy205+rZTG8QbP/o+Out2R6uJJKg4DrH350P9Ztf1s4S09Jt0t7phkyjndJaHuJyKH icHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ayee0An8Gihg+W8T0fUwvvI5g0cIKVgzrmuK/vzNz6Y=; b=X4RZuJxRmBT+4Qw1CEjQztte+DYkDNq/3SAEYpeu1ni1zFX9zdgoHVbIh9eFmbFoTS FTrA9q9HMG4PWmbGeGPvojE/j6GJV0CO7R5AvnE3Qiy577cfhEn3T2D6sB2DbW5NXudj vkOoM41SIRbC0dcXwlcFCdooCzlij6dDeNWYjW1aBAkIOOSDMM90kfo3zu8RKpezAZZl oltq6skGva6OctToHlRqOBUGdXDdYMp8t9MouUYhUIy+OM47m7jUnSndHFATKPB8xqK0 GUj9TIyv/TQxGQXFWC0H0g9W27sFZ4V2m9cfGrA6NeUj/EMXN/WfYH1Ml0afZ4UoJPts a7BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iqx7xVtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be14-20020a0564021a2e00b004aab2fed3e7si22215476edb.275.2023.03.24.06.24.29; Fri, 24 Mar 2023 06:24:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iqx7xVtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231902AbjCXNTF (ORCPT + 99 others); Fri, 24 Mar 2023 09:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjCXNTE (ORCPT ); Fri, 24 Mar 2023 09:19:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAEA712860; Fri, 24 Mar 2023 06:19:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A3B9EB82303; Fri, 24 Mar 2023 13:19:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F985C4339C; Fri, 24 Mar 2023 13:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679663940; bh=n5azJT38PvOIS9z98MuhiQgqA+N6UCY/FD9OPf2roSQ=; h=From:To:Cc:Subject:Date:From; b=iqx7xVtMtD8mPE+WbN/St84YFBtuaTHqFUyMKVBUCd3aEwUgX8JIecbiann+8L4Ty O5rD1RaBK0WBfya9CwIB4fJBWNjSS+yqHw+gTG+pcip1s4b8PQG7J7v036NxdG3EUN k+CFjUFkcFVunTIMlsnjfa2Cgi4lvEj19lCvTqNBkhu1hSj4at5htyhxDpYGqAOlnT 3A/OArQMOHSZ4zpy9RP/+Kk8I3+bPbVQiQsFA8SYOunc65q8Owlo/u/evCG9H7Mxap /n+g66NqWo6ltnaKMet5xsom/9V/4ET3Tmb+2tIxIy24z6NjNmV/BlcOTyhgSYC1GY g07MvLDjUCYiA== From: Roger Quadros To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: vigneshr@ti.com, srk@ti.com, r-gunasekaran@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Aswath Govindraju , Roger Quadros Subject: [PATCH] usb: typec: tps6598x: Add support for polling interrupts status Date: Fri, 24 Mar 2023 15:18:53 +0200 Message-Id: <20230324131853.41102-1-rogerq@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761255666136739069?= X-GMAIL-MSGID: =?utf-8?q?1761255666136739069?= From: Aswath Govindraju Some development boards don't have the interrupt line connected. In such cases we can resort to polling the interrupt status. Signed-off-by: Aswath Govindraju Signed-off-by: Roger Quadros Reviewed-by: Heikki Krogerus --- drivers/usb/typec/tipd/core.c | 41 ++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 485b90c13078..d28ffa10a122 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "tps6598x.h" #include "trace.h" @@ -97,6 +98,8 @@ struct tps6598x { int wakeup; u16 pwr_status; + struct delayed_work wq_poll; + irq_handler_t irq_handler; }; static enum power_supply_property tps6598x_psy_props[] = { @@ -568,6 +571,18 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) return IRQ_NONE; } +/* Time interval for Polling */ +#define POLL_INTERVAL 500 /* msecs */ +static void tps6598x_poll_work(struct work_struct *work) +{ + struct tps6598x *tps = container_of(to_delayed_work(work), + struct tps6598x, wq_poll); + + tps->irq_handler(0, tps); + queue_delayed_work(system_power_efficient_wq, + &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL)); +} + static int tps6598x_check_mode(struct tps6598x *tps) { char mode[5] = { }; @@ -746,6 +761,7 @@ static int tps6598x_probe(struct i2c_client *client) TPS_REG_INT_PLUG_EVENT; } + tps->irq_handler = irq_handler; /* Make sure the controller has application firmware running */ ret = tps6598x_check_mode(tps); if (ret) @@ -837,10 +853,18 @@ static int tps6598x_probe(struct i2c_client *client) dev_err(&client->dev, "failed to register partner\n"); } - ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, - irq_handler, - IRQF_SHARED | IRQF_ONESHOT, - dev_name(&client->dev), tps); + if (client->irq) { + ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, + irq_handler, + IRQF_SHARED | IRQF_ONESHOT, + dev_name(&client->dev), tps); + } else { + dev_warn(tps->dev, "Unable to find the interrupt, switching to polling\n"); + INIT_DELAYED_WORK(&tps->wq_poll, tps6598x_poll_work); + queue_delayed_work(system_power_efficient_wq, &tps->wq_poll, + msecs_to_jiffies(POLL_INTERVAL)); + } + if (ret) goto err_disconnect; @@ -848,7 +872,7 @@ static int tps6598x_probe(struct i2c_client *client) fwnode_handle_put(fwnode); tps->wakeup = device_property_read_bool(tps->dev, "wakeup-source"); - if (tps->wakeup) { + if (tps->wakeup && client->irq) { device_init_wakeup(&client->dev, true); enable_irq_wake(client->irq); } @@ -887,6 +911,9 @@ static int __maybe_unused tps6598x_suspend(struct device *dev) enable_irq_wake(client->irq); } + if (!client->irq) + cancel_delayed_work_sync(&tps->wq_poll); + return 0; } @@ -900,6 +927,10 @@ static int __maybe_unused tps6598x_resume(struct device *dev) enable_irq(client->irq); } + if (client->irq) + queue_delayed_work(system_power_efficient_wq, &tps->wq_poll, + msecs_to_jiffies(POLL_INTERVAL)); + return 0; }