Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1611211pxp; Thu, 17 Mar 2022 12:40:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzo0yG76oF1ZGwO4a1kUzxvd5fx/XJfZ2W50N0gAc4OnUvQrDt5WBAwebfA3yMjblYSL1OS X-Received: by 2002:a17:90a:a58e:b0:1bd:4752:90cf with SMTP id b14-20020a17090aa58e00b001bd475290cfmr7191644pjq.54.1647546043234; Thu, 17 Mar 2022 12:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546043; cv=none; d=google.com; s=arc-20160816; b=LKaFNZEiLR2scg4dlbDA1I5QT42+9L3pVW6xJinPaI7x35zsPhfpyWHlniJdvL71eC ZjTrT9K6uGMIdzNiKorRCsLSP6Uz51bCmZJVKIqW4GyErNckIeOQzBrLnNtzw21ZS7xo irowTDdJNyxQqB2DKLDq9tulpNDNKnjbpDFtC+lJxojuNIti7N1USRRSk1M0PvBMSNN4 m+B2v+hGsjgciFIEe1oQROhj7Tc24tXQ2ZnnRntWFiDpSMGHM34RQ8kZmtmuCTuK47S5 BGyX9PXCjD4VqX8eap4NA44980jF28LJUjHPpUFzTiF/gOulDfXDtFwQ2nV468iH34WU ztbw== 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; bh=JV8iQI3WpCbVam2WtwEWzwXiqUeh9ak+GxYx8IDviZY=; b=chw18T3ZFoWwCWHn9W77ORqs4MlymqFny6uEe9jDtS1EV6UthDFmI0r++uZ9/WrSia IfZSMWkbmIWaENmmcWStZh85hm7IqKSu7hMI7cpSgIg6CDSVTwYSn7zL66J/bmwz2Vvm d+yx7HOSqqk2XPrUK7ALZ3ujHDEoAi8PnZPpFz3uf8PZx8dFBC9QEBNWfJZAMhbq6We0 6bL77m43FSbuWVEqHT/h4UGaF9ouLt7MfrRTSpwITYIp2TbRAHcXznsjsC4oDTVQr4JD f1337V4kmPVuGR668GJOL91BGEZMtYJNGsDIjlZAfkzRJP+TtMmVCQG363LZmt2ImSD4 jrHw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=puri.sm Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u6-20020a170903124600b0014fcd144fddsi6198279plh.212.2022.03.17.12.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:40:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=puri.sm Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 318A522FD8E; Thu, 17 Mar 2022 12:39:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236104AbiCQPtV (ORCPT + 99 others); Thu, 17 Mar 2022 11:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236092AbiCQPtR (ORCPT ); Thu, 17 Mar 2022 11:49:17 -0400 Received: from comms.puri.sm (comms.puri.sm [159.203.221.185]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6CD639BA2; Thu, 17 Mar 2022 08:47:57 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id A71A4E013C; Thu, 17 Mar 2022 08:47:57 -0700 (PDT) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JcpyOJZtPPGy; Thu, 17 Mar 2022 08:47:57 -0700 (PDT) From: Sebastian Krzyszkowiak To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: Sebastian Krzyszkowiak , Greg Kroah-Hartman , Sven Peter , =?UTF-8?q?Guido=20G=C3=BCnther?= , Angus Ainslie , Hector Martin , "Bryan O'Donoghue" , linux-kernel@vger.kernel.org, kernel@puri.sm Subject: [PATCH 2/7] usb: typec: tipd: set the data role on tps IRQ Date: Thu, 17 Mar 2022 16:45:13 +0100 Message-Id: <20220317154518.4082046-3-sebastian.krzyszkowiak@puri.sm> In-Reply-To: <20220317154518.4082046-1-sebastian.krzyszkowiak@puri.sm> References: <20220317154518.4082046-1-sebastian.krzyszkowiak@puri.sm> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Angus Ainslie Don't immediately set the data role, only set it in response to the negotiated value notification from the tps6589x. Otherwise data role switch fails for DRP. We only use values cached from the IRQ instead of poking I2C all the time. The update is moved in a function that will become more useful in later commits. Fixes: 18a6c866bb19 ("usb: typec: tps6598x: Add USB role switching logic") Signed-off-by: Angus Ainslie Signed-off-by: Sebastian Krzyszkowiak --- drivers/usb/typec/tipd/core.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index dfbba5ae9487..f387786ff95e 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -94,6 +94,7 @@ struct tps6598x { struct power_supply_desc psy_desc; enum power_supply_usb_type usb_type; + u32 data_status; u16 pwr_status; }; @@ -271,6 +272,15 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status) return 0; } +static int +tps6598x_update_data_status(struct tps6598x *tps, u32 status) +{ + tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), + !!(tps->data_status & TPS_DATA_STATUS_DATA_CONNECTION)); + trace_tps6598x_data_status(tps->data_status); + return 0; +} + static void tps6598x_disconnect(struct tps6598x *tps, u32 status) { if (!IS_ERR(tps->partner)) @@ -370,8 +380,6 @@ static int tps6598x_dr_set(struct typec_port *port, enum typec_data_role role) goto out_unlock; } - tps6598x_set_data_role(tps, role, true); - out_unlock: mutex_unlock(&tps->lock); @@ -437,6 +445,7 @@ static bool tps6598x_read_data_status(struct tps6598x *tps) dev_err(tps->dev, "failed to read data status: %d\n", ret); return false; } + tps->data_status = data_status; trace_tps6598x_data_status(data_status); return true; @@ -497,10 +506,13 @@ static irqreturn_t cd321x_interrupt(int irq, void *data) if (!tps6598x_read_power_status(tps)) goto err_clear_ints; - if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE) + if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE) { if (!tps6598x_read_data_status(tps)) goto err_clear_ints; + tps6598x_update_data_status(tps, status); + } + /* Handle plug insert or removal */ if (event & APPLE_CD_REG_INT_PLUG_EVENT) tps6598x_handle_plug_event(tps, status); @@ -544,10 +556,13 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) if (!tps6598x_read_power_status(tps)) goto err_clear_ints; - if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) + if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) { if (!tps6598x_read_data_status(tps)) goto err_clear_ints; + tps6598x_update_data_status(tps, status); + } + /* Handle plug insert or removal */ if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) tps6598x_handle_plug_event(tps, status); -- 2.35.1