Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3326511pxb; Mon, 1 Mar 2021 07:19:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0cHIJGML1pOh4yia/vHEtdvDeZwqIT711y2Lvf1DyPZdvfNP6K7rhwQDvMc62Z0ynuB3t X-Received: by 2002:a17:906:30da:: with SMTP id b26mr16210706ejb.376.1614611973528; Mon, 01 Mar 2021 07:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614611973; cv=none; d=google.com; s=arc-20160816; b=OopZuTCRtdT+W3XwfEFhtvIkvanXot6q00H8uMy6ptDQeKyTtoUEm61zgP7Q2DNz0W cGWAn17fIqu7baaCUItRYYW2PBnLUMZeyjWbBGo4ZG71P93WoqZRxTyKxdAQ8OPyb/No IhSKo2Yhxu9+EZqFrapEI2Qq3GsrZ+8rZWUJpxzT9cCqE6eurO4QsUZMAMtP4fLpJ8Jp QuizDhWgiaJ6EcsN86iJ/ewsAFHRTvltWcKzT+gCHZv8cgJ8ijZtHaKll+dALSAS96a1 k9pBylpM0dHpWpgQxwgZ2dWIocsvgLVo+LDEy5wTpOJHDbPF+y53pUrRlikx4ssGJXpO TLGw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=u/CyI2PUyqmBD4D7AGgl/jtSVVpXFARFpVMYzciSyVs=; b=yvNBEH5lL8VZPakXUeaEzuumoU21gXybzjpTZ/GCVm782MQCFX6MN6F+rCW66903oT KWdLR1DgLPFAzvLvJqE8aoSmkakDjWBAbmArUmbxeIkJzssUmms500DDnwosg2goNb+0 4lK1gg46r9PEXt4KOsk9JlPBsZ0cybvwGM/WH6yuPVzhM/JdaFjiAaqQRfwdn5TXbxgF 8UDTP0juBZSRBArr1mHlL6TQFp6KC8hp1JthHuvjnDEGKGdiKz9fdBLxr8sUDOdlBjch 4+Zfl2GsF2ekZB5VQOJz3GOAsZRhbg4Z6glnhsShN7hpB9PPb1voqw+qXrqo2GBva2qV ERWQ== 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 p23si11448960edw.196.2021.03.01.07.19.07; Mon, 01 Mar 2021 07:19:33 -0800 (PST) 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 S237059AbhCAPPe (ORCPT + 99 others); Mon, 1 Mar 2021 10:15:34 -0500 Received: from mga05.intel.com ([192.55.52.43]:11688 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237005AbhCAPNh (ORCPT ); Mon, 1 Mar 2021 10:13:37 -0500 IronPort-SDR: 9CXvj1kHUne/OWow7i7QlHtuNzprtVoZ+7XilGgDdlfDOWGeE2yHcGdqHcBjouQaHCgoRn/e/1 ivd9kVYAhAcQ== X-IronPort-AV: E=McAfee;i="6000,8403,9910"; a="271492211" X-IronPort-AV: E=Sophos;i="5.81,215,1610438400"; d="scan'208";a="271492211" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 07:11:39 -0800 IronPort-SDR: eHYGJX2N6GrV7cRrPR6fkNqmkAdfugoBl4f96ePcvGHf8Wob5wR2v+pMTn2E9cqmsd7fxxkkC2 obSOiKqqFcPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,215,1610438400"; d="scan'208";a="505098954" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 01 Mar 2021 07:11:36 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Mon, 01 Mar 2021 17:11:35 +0200 Date: Mon, 1 Mar 2021 17:11:35 +0200 From: Heikki Krogerus To: Guido =?iso-8859-1?Q?G=FCnther?= Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH v3 3/4] usb: typec: tps6598x: Add trace event for power status register Message-ID: References: <3c92da489fa03d6fe67ac18443c48dccb1bf048a.1613389531.git.agx@sigxcpu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3c92da489fa03d6fe67ac18443c48dccb1bf048a.1613389531.git.agx@sigxcpu.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 15, 2021 at 12:46:44PM +0100, Guido G?nther wrote: > Together with the PD status register this is vital for debugging power > negotiations at runtime. > > Signed-off-by: Guido G?nther Reviewed-by: Heikki Krogerus > --- > drivers/usb/typec/tps6598x.c | 19 +++++++++------ > drivers/usb/typec/tps6598x.h | 19 +++++++++++++++ > drivers/usb/typec/tps6598x_trace.h | 38 ++++++++++++++++++++++++++++++ > 3 files changed, 69 insertions(+), 7 deletions(-) > > diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c > index 559aa175f948..3e6ad3ba7fc8 100644 > --- a/drivers/usb/typec/tps6598x.c > +++ b/drivers/usb/typec/tps6598x.c > @@ -50,11 +50,6 @@ enum { > TPS_PORTINFO_SOURCE, > }; > > -/* TPS_REG_POWER_STATUS bits */ > -#define TPS_POWER_STATUS_CONNECTION BIT(0) > -#define TPS_POWER_STATUS_SOURCESINK BIT(1) > -#define TPS_POWER_STATUS_PWROPMODE(p) (((p) & GENMASK(3, 2)) >> 2) > - > /* TPS_REG_RX_IDENTITY_SOP */ > struct tps6598x_rx_identity_reg { > u8 status; > @@ -414,6 +409,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) > u64 event1; > u64 event2; > u32 status; > + u16 pwr_status; > int ret; > > mutex_lock(&tps->lock); > @@ -433,6 +429,15 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) > } > 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); > + goto err_clear_ints; > + } > + trace_tps6598x_power_status(pwr_status); > + } > + > /* Handle plug insert or removal */ > if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) { > if (status & TPS_STATUS_PLUG_PRESENT) { > @@ -497,8 +502,8 @@ static int tps6598x_psy_get_online(struct tps6598x *tps, > if (ret < 0) > return ret; > > - if ((pwr_status & TPS_POWER_STATUS_CONNECTION) && > - (pwr_status & TPS_POWER_STATUS_SOURCESINK)) { > + if (TPS_POWER_STATUS_CONNECTION(pwr_status) && > + TPS_POWER_STATUS_SOURCESINK(pwr_status)) { > val->intval = 1; > } else { > val->intval = 0; > diff --git a/drivers/usb/typec/tps6598x.h b/drivers/usb/typec/tps6598x.h > index 621fb336c15d..9a34c020f3e5 100644 > --- a/drivers/usb/typec/tps6598x.h > +++ b/drivers/usb/typec/tps6598x.h > @@ -129,4 +129,23 @@ > #define TPS_REG_INT_HARD_RESET BIT(1) > #define TPS_REG_INT_PD_SOFT_RESET BIT(0) > > +/* TPS_REG_POWER_STATUS bits */ > +#define TPS_POWER_STATUS_CONNECTION(x) TPS_FIELD_GET(BIT(0), (x)) > +#define TPS_POWER_STATUS_SOURCESINK(x) TPS_FIELD_GET(BIT(1), (x)) > +#define TPS_POWER_STATUS_BC12_DET(x) TPS_FIELD_GET(BIT(2), (x)) > + > +#define TPS_POWER_STATUS_TYPEC_CURRENT_MASK GENMASK(3, 2) > +#define TPS_POWER_STATUS_PWROPMODE(p) TPS_FIELD_GET(TPS_POWER_STATUS_TYPEC_CURRENT_MASK, (p)) > +#define TPS_POWER_STATUS_BC12_STATUS_MASK GENMASK(6, 5) > +#define TPS_POWER_STATUS_BC12_STATUS(p) TPS_FIELD_GET(TPS_POWER_STATUS_BC12_STATUS_MASK, (p)) > + > +#define TPS_POWER_STATUS_TYPEC_CURRENT_USB 0 > +#define TPS_POWER_STATUS_TYPEC_CURRENT_1A5 1 > +#define TPS_POWER_STATUS_TYPEC_CURRENT_3A0 2 > +#define TPS_POWER_STATUS_TYPEC_CURRENT_PD 3 > + > +#define TPS_POWER_STATUS_BC12_STATUS_SDP 0 > +#define TPS_POWER_STATUS_BC12_STATUS_CDP 2 > +#define TPS_POWER_STATUS_BC12_STATUS_DCP 3 > + > #endif /* __TPS6598X_H__ */ > diff --git a/drivers/usb/typec/tps6598x_trace.h b/drivers/usb/typec/tps6598x_trace.h > index e0677b9c5c53..78a5a6ca337b 100644 > --- a/drivers/usb/typec/tps6598x_trace.h > +++ b/drivers/usb/typec/tps6598x_trace.h > @@ -134,6 +134,24 @@ > { TPS_STATUS_HIGH_VOLAGE_WARNING, "HIGH_VOLAGE_WARNING" }, \ > { TPS_STATUS_HIGH_LOW_VOLTAGE_WARNING, "HIGH_LOW_VOLTAGE_WARNING" }) > > +#define show_power_status_source_sink(power_status) \ > + __print_symbolic(TPS_POWER_STATUS_SOURCESINK(power_status), \ > + { 1, "sink" }, \ > + { 0, "source" }) > + > +#define show_power_status_typec_status(power_status) \ > + __print_symbolic(TPS_POWER_STATUS_PWROPMODE(power_status), \ > + { TPS_POWER_STATUS_TYPEC_CURRENT_PD, "pd" }, \ > + { TPS_POWER_STATUS_TYPEC_CURRENT_3A0, "3.0A" }, \ > + { TPS_POWER_STATUS_TYPEC_CURRENT_1A5, "1.5A" }, \ > + { TPS_POWER_STATUS_TYPEC_CURRENT_USB, "usb" }) > + > +#define show_power_status_bc12_status(power_status) \ > + __print_symbolic(TPS_POWER_STATUS_BC12_STATUS(power_status), \ > + { TPS_POWER_STATUS_BC12_STATUS_DCP, "dcp" }, \ > + { TPS_POWER_STATUS_BC12_STATUS_CDP, "cdp" }, \ > + { TPS_POWER_STATUS_BC12_STATUS_SDP, "sdp" }) > + > TRACE_EVENT(tps6598x_irq, > TP_PROTO(u64 event1, > u64 event2), > @@ -181,6 +199,26 @@ TRACE_EVENT(tps6598x_status, > ) > ); > > +TRACE_EVENT(tps6598x_power_status, > + TP_PROTO(u16 power_status), > + TP_ARGS(power_status), > + > + TP_STRUCT__entry( > + __field(u16, power_status) > + ), > + > + TP_fast_assign( > + __entry->power_status = power_status; > + ), > + > + TP_printk("conn: %d, pwr-role: %s, typec: %s, bc: %s", > + !!TPS_POWER_STATUS_CONNECTION(__entry->power_status), > + show_power_status_source_sink(__entry->power_status), > + show_power_status_typec_status(__entry->power_status), > + show_power_status_bc12_status(__entry->power_status) > + ) > +); > + > #endif /* _TPS6598X_TRACE_H_ */ > > /* This part must be outside protection */ > -- > 2.30.0 thanks, -- heikki