Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp245654pxb; Thu, 30 Sep 2021 05:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydDx7c4YwBNUEXLzumZVI8kl0WNqAoGzYyCZxWo2ucpppKQpwjJtMGijTSmwA5RduRItx1 X-Received: by 2002:a62:7b04:0:b0:44b:e076:ad5e with SMTP id w4-20020a627b04000000b0044be076ad5emr4188255pfc.69.1633004341580; Thu, 30 Sep 2021 05:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633004341; cv=none; d=google.com; s=arc-20160816; b=rKn3snFNaEWvHlz3xKQJLUJyB7zxN2N4ECBUAlWdudVJeKSNmwq6Rpo1iDEH6MaTD1 td/VFRa4YGze+allrHqNEUHBEE51vYYbg4+VmKCrwzH6qBBYmC3XfNASXDctO0dbZfmc 4mWxzd0cfrDPzyFlrRO2Y/ZgCoCESWuo0F4vcP1ATzHyVvpoNnGPZ+Gh+DClTKZyiOOU XTAQUSDdWTiJlUBUvzZmQIYlQQr0RVQhjG9jlegGeX3lJzH4IF1PiGDJiOE+cCsjpYI6 +vWzLhVKFCqenXE4U4Y+wMrKCUoNLvOB1RiVpEh+CZOS4O6l67fp/0HE9bdBhgF1Dqq4 E3dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=YLrYMz3N9iCgPGPFKW6ZkXTatzLsiPeYMk4v4bWde7A=; b=dSVJJd9joWSWxt6/gdggp4zy7buP2P61zWJSNddCESDjKPGpC4fXRqYGIUPLGJyGN2 Vc6Wjewmqod4lav2Hebc2FAoLUesb/pDvsMAF3ZRaLONUGNehgVsFcs71paG7SsF8TMo otuxwKFZhX7pYpbaQGaP7144UVmG2FZmI1SQavP7CNWpsI9ga8yN3X6fmULzLlaorlcm 6JQkkJqpFtJmqEi4HJpSzgY+jJ1SFlFf/eEs9Kt+CY83vppo5Hr76D1pt6CyrvEfwNjE QfbSMeRBbNAZgpRWwAIzH3H/CXyMkQR6A3XnpnUijU2K4tf6syKjjpQVodhxCXLYRlnq 88ag== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si4177820pgu.485.2021.09.30.05.18.36; Thu, 30 Sep 2021 05:19:01 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349767AbhI3KKr (ORCPT + 99 others); Thu, 30 Sep 2021 06:10:47 -0400 Received: from mga18.intel.com ([134.134.136.126]:48013 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238316AbhI3KKq (ORCPT ); Thu, 30 Sep 2021 06:10:46 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10122"; a="212230851" X-IronPort-AV: E=Sophos;i="5.85,335,1624345200"; d="scan'208";a="212230851" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2021 03:09:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,335,1624345200"; d="scan'208";a="618056924" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 30 Sep 2021 03:08:59 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 30 Sep 2021 13:08:58 +0300 Date: Thu, 30 Sep 2021 13:08:58 +0300 From: Heikki Krogerus To: Sven Peter Cc: Greg Kroah-Hartman , Guido =?iso-8859-1?Q?G=FCnther?= , 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: Re: [PATCH v3 2/6] usb: typec: tipd: Split interrupt handler Message-ID: References: <20210928155502.71372-1-sven@svenpeter.dev> <20210928155502.71372-3-sven@svenpeter.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210928155502.71372-3-sven@svenpeter.dev> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 28, 2021 at 05:54:58PM +0200, Sven Peter wrote: > 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 Reviewed-by: Heikki Krogerus > --- > 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 thanks, -- heikki