Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp5018754pxb; Tue, 28 Sep 2021 08:57:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKtnHOyrnSja2JkZxouoD0r/F3JmAs9AOkXY2F2LplIm4E5rAUp7ZI3yESMLwqXDRD+L1x X-Received: by 2002:a17:906:29d0:: with SMTP id y16mr7952124eje.477.1632844646258; Tue, 28 Sep 2021 08:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632844646; cv=none; d=google.com; s=arc-20160816; b=Mi8R/mR+Ph5ZLE3Rqdmm4cv7OARsU3HncmqtBYYddXtNwUIxpyGWv9+1zOH76iAVOL wz9NNpHpqhLIEuXaW69EYkyuLD8wQswzVXiWYlPJhEZqOvA8h+bxJk5DAV5KtFe7vo+Y 10zF6gFHfIeoEqKE81HpsX8nsCyBgetCPz+Y4W6YiO/OUD0nTZ620rw+vJP7imK3Upoz Fp7wlsZqTW2pz05CUtEm6RwvoikKpLaBpD2rafPWSe5+B7x3WPiMMdEYFUspeAvGCs9p 1d4nrvVWzAr3a0qk8SPus49pWluiFRl8NB5CjOWHIW2nXMisZt8hX9PTA6kCouQuWOnU 7fQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=7k99brYKXgcXOk4IW+ax4xDIyMEk6c+A5uHjFIDw/WY=; b=IX2jn4tVWrv4+v3OLr/VHghnKxhp9xcO7anA0ZZnhCEnFSQmbGOVmIPV6eA5V5/eXr TlMkeP2ADcXK1fA2foWP8+XouXiO7qerK5Df1OtL7zi1h53CAolg03bzXY4l7Kj/yhLb a6HEgojUxwp/vGGyBp+Xxs88tpq3qO/8lEpwDOotTRTNl3Uckt7ZJhmruPBDprmA2tcg +lCpScdUnwt//tpmISsXclC2vNI4ydhthIEpqnC1jW7MSfGRa5nddA5WM2nU/+TAvo41 nR6A6uxTg+JuIDd/3SfWxYd9vNEgk9fJR1ktxmrk37eTlvLBUCPUTPh50YpSWg3O8X6C G79g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm2 header.b=R6Og6Mxo; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=T3Se15m9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m24si22657794ejd.38.2021.09.28.08.57.01; Tue, 28 Sep 2021 08:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm2 header.b=R6Og6Mxo; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=T3Se15m9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241736AbhI1P5H (ORCPT + 99 others); Tue, 28 Sep 2021 11:57:07 -0400 Received: from new3-smtp.messagingengine.com ([66.111.4.229]:45115 "EHLO new3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241707AbhI1P5D (ORCPT ); Tue, 28 Sep 2021 11:57:03 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 95EEF580C25; Tue, 28 Sep 2021 11:55:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 28 Sep 2021 11:55:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=7k99brYKXgcXO k4IW+ax4xDIyMEk6c+A5uHjFIDw/WY=; b=R6Og6MxoACYgoi1Dgevqz7tNurMFY PmWF4if7NR1vuffnn411k3qJCoty6BRBrKm0DB4sDATlQ0q0p6XNw4fu6+vusFNV 6cXOkmwhtXSqDo88V7W3OULwn+6TozRswrgrJ94Ck4689j4TdzvLhRKH21xlTa6/ 5kJSXGdCxRk3ALfHyNfm00NaPdUDwCe30QW16nbU/J+hmyNQJb9wqhnhutX2hnwk cUgp5h3KNe5hvVh1VGZ9wQqtUre+O4lwbTBJiJQyvAW4A7C6LPiMTU+oWgofUqBW XcdMFrFu0/Igf1gJaaWPo1GxGvqKVa64umI8DwZLCjIdn3W/peg5cC20Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=7k99brYKXgcXOk4IW+ax4xDIyMEk6c+A5uHjFIDw/WY=; b=T3Se15m9 TfjdsglZi38E+ki1N9RrKqPEr943fIj0ts1Tb7o7pkvwyg4IR3Y7T4pmA2qFUbEz leOdBXj6LrrjsQ4esmtAf1vgcCZAw+rGG7jHF5COz7AP2eVf2GAPjy4nCGpx+CRA ESDNN6Z0Sl2CmwPriCs2pJ0imsHUi++371FQPcCc4Ko5E2TGR2BSGcquq3gCgdHP ySvpPk0OiZ+F8JzuC1s9AYwNIGZPKM5S4+d7aWp5o+rak8AAO1sww+DKSOuSYyo+ FOSg8wtKpnjFC31bCBRaISSPBPC1oxViNeRYMhZyFrxH/Wy+qi1Xd+NZ1suwDtEb 3xm9MW+mx1p10g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudektddgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcu rfgvthgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvg hrnheptedvkeetleeuffffhfekteetffeggffgveehieelueefvddtueffveevlefhfeej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvg hnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Sep 2021 11:55:21 -0400 (EDT) From: Sven Peter To: Heikki Krogerus Cc: Sven Peter , Greg Kroah-Hartman , =?UTF-8?q?Guido=20G=C3=BCnther?= , "Bryan O'Donoghue" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Hector Martin , Mohamed Mediouni , Stan Skowronek , Mark Kettenis , Alexander Graf , Alyssa Rosenzweig Subject: [PATCH v3 2/6] usb: typec: tipd: Split interrupt handler Date: Tue, 28 Sep 2021 17:54:58 +0200 Message-Id: <20210928155502.71372-3-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210928155502.71372-1-sven@svenpeter.dev> References: <20210928155502.71372-1-sven@svenpeter.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split the handlers for the individual interrupts into their own functions to prepare for adding a second interrupt handler for the Apple CD321x chips Signed-off-by: Sven Peter --- no changes since v2 changes since v1: - new commit since Heikki suggested to add a separate irq handler for the cd321x variant drivers/usb/typec/tipd/core.c | 96 ++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 93e56291f0cf..172715c6c238 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -404,13 +404,69 @@ static const struct typec_operations tps6598x_ops = { .pr_set = tps6598x_pr_set, }; +static bool tps6598x_read_status(struct tps6598x *tps, u32 *status) +{ + int ret; + + ret = tps6598x_read32(tps, TPS_REG_STATUS, status); + if (ret) { + dev_err(tps->dev, "%s: failed to read status\n", __func__); + return false; + } + trace_tps6598x_status(*status); + + return true; +} + +static bool tps6598x_read_data_status(struct tps6598x *tps) +{ + u32 data_status; + int ret; + + ret = tps6598x_read32(tps, TPS_REG_DATA_STATUS, &data_status); + if (ret < 0) { + dev_err(tps->dev, "failed to read data status: %d\n", ret); + return false; + } + trace_tps6598x_data_status(data_status); + + return true; +} + +static bool tps6598x_read_power_status(struct tps6598x *tps) +{ + u16 pwr_status; + int ret; + + ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status); + if (ret < 0) { + dev_err(tps->dev, "failed to read power status: %d\n", ret); + return false; + } + trace_tps6598x_power_status(pwr_status); + + return true; +} + +static void tps6598x_handle_plug_event(struct tps6598x *tps, u32 status) +{ + int ret; + + if (status & TPS_STATUS_PLUG_PRESENT) { + ret = tps6598x_connect(tps, status); + if (ret) + dev_err(tps->dev, "failed to register partner\n"); + } else { + tps6598x_disconnect(tps, status); + } +} + static irqreturn_t tps6598x_interrupt(int irq, void *data) { struct tps6598x *tps = data; u64 event1; u64 event2; - u32 status, data_status; - u16 pwr_status; + u32 status; int ret; mutex_lock(&tps->lock); @@ -423,42 +479,20 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) } trace_tps6598x_irq(event1, event2); - ret = tps6598x_read32(tps, TPS_REG_STATUS, &status); - if (ret) { - dev_err(tps->dev, "%s: failed to read status\n", __func__); + if (!tps6598x_read_status(tps, &status)) goto err_clear_ints; - } - trace_tps6598x_status(status); - if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) { - ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status); - if (ret < 0) { - dev_err(tps->dev, "failed to read power status: %d\n", ret); + if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) + if (!tps6598x_read_power_status(tps)) goto err_clear_ints; - } - trace_tps6598x_power_status(pwr_status); - } - if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) { - ret = tps6598x_read32(tps, TPS_REG_DATA_STATUS, &data_status); - if (ret < 0) { - dev_err(tps->dev, "failed to read data status: %d\n", ret); + if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) + if (!tps6598x_read_data_status(tps)) goto err_clear_ints; - } - trace_tps6598x_data_status(data_status); - } /* Handle plug insert or removal */ - if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) { - if (status & TPS_STATUS_PLUG_PRESENT) { - ret = tps6598x_connect(tps, status); - if (ret) - dev_err(tps->dev, - "failed to register partner\n"); - } else { - tps6598x_disconnect(tps, status); - } - } + if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) + tps6598x_handle_plug_event(tps, status); err_clear_ints: tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1); -- 2.25.1