Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp883343pxb; Wed, 27 Oct 2021 14:25:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOUEgIV3tdvu6ESkrfsPH2z+rmrBqoayLCJw+/Fuevj6zDqkie624SoOW4bVVTrNHDFOyu X-Received: by 2002:a05:6402:2034:: with SMTP id ay20mr472890edb.320.1635369921931; Wed, 27 Oct 2021 14:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369921; cv=none; d=google.com; s=arc-20160816; b=XCJmjuMkgQaAh0yMIQsSq12ftTbSo+l859qcHiXD5r3UR0L8HhAK9F5qQ3NyF9zK7u NW5LsHn/gb6vlgd2K/ccEVTnb+K5fdSoaBNdRLeRkMiGN1Cy3ZPk+r1zQVT9l4uohSnj hshsFU2dKErqOz+0y/aWXfoi/Fmbnfde/0ks3bFNsCZGJ79GUYpq5hXkt8zBmlqfpIn5 cnw6nDS+qzY7arUPQkm23zhTcmGjP/7h7LrdiTHK9IGmAliFXXIgREYYsgT1lhEOMqSx 3346uAN27QNrlugmJJdZa8LaPXHM4HFcrjpNwDm8JnkPVxG0joasm7ks1j2rbraNV6bD Tucw== 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=vo/LDmpjzEZR2h1cRXRQW9rIaYtST5weDaaOjNIdp2U=; b=iiDvQ+7KqRM3EqZbYtFKh+fuLWEu9N/gR+nZWnQe0Jrwax/fzeJrdAq3jvFKLgb2Ew ja2jTHfEhGlcBRduFVQImucqJVPlGwHs1pfRZrc8YSdxv/ElePFy8SUUp5eV4Kj72OUJ hLVzNc2+WB7cUDo40Y3hiZeg9E0bLSGmymT+n2/BafapLPJesuwali+MgcYtAjLyhjIu 8anwn5EfdygGsvkewbSvCggb7GKj5BeeeGoJI4xCD7nfmxsGJGJC0i18RT748dnw3l8G vCMTI6Nkdz5XNuMYScWq8NAha/Duk/KTMnDAhdb5M3ReuBmqeyjmz3KntnJ4bA1A/8D6 9nbg== 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 js20si1888459ejc.159.2021.10.27.14.24.57; Wed, 27 Oct 2021 14:25:21 -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 S241585AbhJ0LMp (ORCPT + 97 others); Wed, 27 Oct 2021 07:12:45 -0400 Received: from mga14.intel.com ([192.55.52.115]:51870 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239506AbhJ0LMo (ORCPT ); Wed, 27 Oct 2021 07:12:44 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10149"; a="230409327" X-IronPort-AV: E=Sophos;i="5.87,186,1631602800"; d="scan'208";a="230409327" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2021 04:10:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,186,1631602800"; d="scan'208";a="635683209" Received: from kuha.fi.intel.com ([10.237.72.166]) by fmsmga001.fm.intel.com with SMTP; 27 Oct 2021 04:10:16 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Wed, 27 Oct 2021 14:10:15 +0300 Date: Wed, 27 Oct 2021 14:10:15 +0300 From: Heikki Krogerus To: Jack Pham Cc: Prashant Malani , Benson Leung , Adam Thomson , Guenter Roeck , Badhri Jagan Sridharan , "Gopal, Saranya" , "Regupathy, Rajaram" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 3/4] usb: typec: ucsi: Add support for PD cdev Message-ID: References: <20211026143352.78387-1-heikki.krogerus@linux.intel.com> <20211026143352.78387-4-heikki.krogerus@linux.intel.com> <20211027010035.GA13345@jackp-linux.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211027010035.GA13345@jackp-linux.qualcomm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 06:00:35PM -0700, Jack Pham wrote: > On Tue, Oct 26, 2021 at 05:33:51PM +0300, Heikki Krogerus wrote: > > > > -static int ucsi_get_src_pdos(struct ucsi_connector *con) > > +int ucsi_read_pdos(struct ucsi_connector *con, int partner, int source, u32 *pdos) > > { > > + u32 pdo[PDO_MAX_OBJECTS]; > > + int num_pdos; > > int ret; > > > > /* UCSI max payload means only getting at most 4 PDOs at a time */ > > - ret = ucsi_get_pdos(con, 1, con->src_pdos, 0, UCSI_MAX_PDOS); > > + ret = ucsi_get_pdos(con, partner, source, pdo, 0, UCSI_MAX_PDOS); > > if (ret < 0) > > return ret; > > > > - con->num_pdos = ret / sizeof(u32); /* number of bytes to 32-bit PDOs */ > > - if (con->num_pdos < UCSI_MAX_PDOS) > > - return 0; > > + num_pdos = ret / sizeof(u32); /* number of bytes to 32-bit PDOs */ > > + if (num_pdos < UCSI_MAX_PDOS) > > + goto done; > > > > /* get the remaining PDOs, if any */ > > - ret = ucsi_get_pdos(con, 1, con->src_pdos, UCSI_MAX_PDOS, > > + ret = ucsi_get_pdos(con, partner, source, pdo, UCSI_MAX_PDOS, > > PDO_MAX_OBJECTS - UCSI_MAX_PDOS); > > if (ret < 0) > > return ret; > > > > - con->num_pdos += ret / sizeof(u32); > > + num_pdos += ret / sizeof(u32); > > +done: > > + memcpy(pdos, pdo, num_pdos * sizeof(pdo)); > > + > > + return num_pdos; > > +} > > + > > +static int ucsi_get_src_pdos(struct ucsi_connector *con) > > +{ > > + int ret; > > + > > + ret = ucsi_read_pdos(con, 0, 1, con->src_pdos); > > Second parameter should be 1 right? Original intent of get_src_pdos() > is to retrieve the partner's source capabilities in order to populate > the power_supply. Passing 0 as the partner param here changes the > behavior to retrieve the source PDOs of the port. Sounds like there is a bug in the existing code. I'm not changing the behviour in this patch. > (BTW I'm going to send a quick patch for this to since this assumes that > port is sink and partner is source; when it's the other way around we > end up calling GET_PDOS on the sink partner when it might not even be > source capable). I'll check it... thanks, -- heikki