From patchwork Wed Jul 17 00:49:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13735014 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D91C33D8 for ; Wed, 17 Jul 2024 00:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177485; cv=none; b=BSYG4wv/n9G4I43spm6P/mcsp/6PtWDNDQoKoP5uWi5VsDuh3XURoLfYQeFZH67bRH6RaExr7JAFOpyYcT6L9CgF7Zlnyn9JGfIdcf9GI4U7bi28wxrrX2gn2QxuPlxMRgWaS1iUDHEOWOn+emKeiRDa3vs7J+dZ5MYkj1gnw5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177485; c=relaxed/simple; bh=rtFrRQ4rFy9iHSqIJgEhQebrOvlDgtJBnPfjcOkYxIU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dPDLjS+wXWTbmumQ6hhYNXVYfk4yHtaLhycu/WbkPnsyPdjhawfYer2eVTYYGMqFrdDvAOn+IFOkvk85bfhqH048jDrvaSGiQczPRQFG+Ei5kqpyL7aDWAcW6dqR+rd7jHMk7jeIuNR5CGYHYEt2M1x0COi7F3Q4u6hzEGiWm8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=b3Iz29rY; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="b3Iz29rY" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dfa73db88dcso11102401276.0 for ; Tue, 16 Jul 2024 17:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177483; x=1721782283; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lZfO2IpnB7bc3YW/PTDqptNxNpOawD6JRjU0h2mR8Jg=; b=b3Iz29rYEG1T3ucw5yrRRO3ZZ9BlbBwUaCzS50QP2Ff2OTwc/ljrJShW+bvIPyF5+v Xjz8koT9uQ6VBJzA5zLw/YNQ9GYGT5yStvWrBlu2SQb6xFJPntPTVi8eaOTPgUac5/AC N7p20o3EycGCoYYuGTchdzFBMuzdIV4dldsg+Ib9GFdJuY6VmqiwXN0ABTFmIJ6efpjm PU6ijdOz326eaPNCRbvp2ZVxD58KhQ+1y22N2vod89gr0jrtLuopx/pBM+gzD2Xg/ulF P44wXEz7KYY1NB3KUzkBn9G+HNKDH2Wm0uhH43qWDu/R4Bqyb6A0BydwzyBCpOjD8Bxv BGUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177483; x=1721782283; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lZfO2IpnB7bc3YW/PTDqptNxNpOawD6JRjU0h2mR8Jg=; b=CNwAkeDdNkH4EonjOFbYpeozllB7rT3Uxh7VSt7vMPP7L9zAuvpEaRCM6JCRmtFGhy naqDFKsuEnw/9lVqlrmbnf8bBO6QnWw/txfjjIXeSJttFoirDHiTyvMMArOdGNPeny5E f6kBPu+QTeXdaZg+qvr1Y7As/xAIa36qKZa363fglW9bLdy4xLBT/iVCSV62JwUaIi0o vXqMphUZAS8pEvIsT7cnyIDVHbNGqz8AkXfWt0ZbhQG0Kx7MnrCnSvJz7LH3tjM4tHhQ bb6RC/cnDJYonLO8Rm0yshpnYGl+fcKuiSGMxMJEQM9IZruQ20Q/90taKyGIVILD+EWh 0TrA== X-Forwarded-Encrypted: i=1; AJvYcCUPGjGWh2DUoROUusxBiXsLLT/X2bfkAvCYYNVKKXLYbYj/8lmRgZL1hFmJrDmAGUK6zRlqvKZEZsvvbJPIM6kOyT9/2tE/YYLj X-Gm-Message-State: AOJu0Yzw38VjOQOGx78UwhA4vVtn1Gj2eHdmmPe141WH8Xb+LvVOmcmJ apQGQ9qe29D3TlXu3Q1TQFOLhq2ncJlTZUQ+RwbH+Pfa2UQ9FNcprtkqiqZqnDCNXTgJXBBFIHn QeA== X-Google-Smtp-Source: AGHT+IHn69xVfaZrAZa13CCuMoUt0BnnEiwyRbQOQS68ztFEUUQVny+N76Q4ts71rDSaIim5mgpGHu6Hias= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:140a:b0:e03:5312:c053 with SMTP id 3f1490d57ef6-e05ed6fdc1bmr322276.7.1721177483369; Tue, 16 Jul 2024 17:51:23 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:46 +0000 In-Reply-To: <20240717004949.3638557-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-2-jthies@google.com> Subject: [PATCH v1 1/4] usb: typec: ucsi: Add status to UCSI power supply driver From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Add status to UCSI power supply driver properties based on the port's connection and power direction states. Signed-off-by: Jameson Thies --- drivers/usb/typec/ucsi/psy.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index e623d80e177c..d0b52cee41d2 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -29,6 +29,7 @@ static enum power_supply_property ucsi_psy_props[] = { POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_SCOPE, + POWER_SUPPLY_PROP_STATUS, }; static int ucsi_psy_get_scope(struct ucsi_connector *con, @@ -51,6 +52,20 @@ static int ucsi_psy_get_scope(struct ucsi_connector *con, return 0; } +static int ucsi_psy_get_status(struct ucsi_connector *con, + union power_supply_propval *val) +{ + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + if (con->status.flags & UCSI_CONSTAT_CONNECTED) { + if ((con->status.flags & UCSI_CONSTAT_PWR_DIR) == TYPEC_SINK) + val->intval = POWER_SUPPLY_STATUS_CHARGING; + else + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + } + + return 0; +} + static int ucsi_psy_get_online(struct ucsi_connector *con, union power_supply_propval *val) { @@ -249,6 +264,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy, return ucsi_psy_get_current_now(con, val); case POWER_SUPPLY_PROP_SCOPE: return ucsi_psy_get_scope(con, val); + case POWER_SUPPLY_PROP_STATUS: + return ucsi_psy_get_status(con, val); default: return -EINVAL; } From patchwork Wed Jul 17 00:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13735015 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A0CD848C for ; Wed, 17 Jul 2024 00:51:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177489; cv=none; b=P5m2nac+T+G/EC+iB2j5pN1yf818a0ETvJBiWr5NTz9TyzblrxK058Rpr6Kb4AJun7txMZU/pX+N50h4ka7b7LsTqbUc+ikrz421TiJRarSwb60hoGqr70r8xYsLsvuROMGIB7n5GoPtOGDBKaKut/9lJpgUxgH9irqCD1sBwxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177489; c=relaxed/simple; bh=imrdTBKFl9/ler02ONXWrJRcIjmutDnfzz+XiKEiY3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HqEJrO05+t0tSWV3akTbGPXehMobyr1MPdxOkHLvRFMOJVsUKGDNrrdRcO/UDNy+iGGP88+caiVkYEQekhdfL6HHOvUKROkqf7n9e7BFIJ2yjjS8j59qqIUFtacTcrjkPOxM9kLf3JkG4DFagA3Gyqiz47uTNDv9QC2tJlizsC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uyEn5/QS; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uyEn5/QS" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6511c587946so127333097b3.1 for ; Tue, 16 Jul 2024 17:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177487; x=1721782287; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ssDYc+w2ZBOTZEW4SaOXob+zs6JJwedZnb8idSmatOU=; b=uyEn5/QS8n3nHDLDaN/Do694H85t8KqwVDP0WL9KiSf7eUfr8HuGb8GzasWKojQD56 wqIu2tshIeHy5U9x+ass+kgnv2vhwOTbqGxNlUSggrOBi7P+2YmOgLkxU+8nEty/INg/ hZ7rz5G8amu7n4axw51bI6EkslGvSQRHBmlSEO+FlBw0qyBok+nfNTyNZ8NCI1f37IXe qSuJ4b7+GkNCn5FWqgAbGZVBLmSTA62bmFmrdtfr5RSylYInMIrxISoHiGt2JL/+S5pT iey4mQWEFGXWxKnjBaAAxjNJlWfAkGpx0Cyt78cgb2TDleUCVUYXgmOLfciQna+Z6n51 PmNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177487; x=1721782287; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ssDYc+w2ZBOTZEW4SaOXob+zs6JJwedZnb8idSmatOU=; b=VlYiDI/Xp7O5ciRUoKxedPDp8FWuouEkb1jDfYl3RAjAsL+U/9FAz+GPgg3JF4vUSp zQ19lMkEWnBkdvAtfVFiz7IErRyYUfLd3Uad/NvvYINWGUolIx30OZ6WaSz41U/asTBP /17OjQ+Vf0w325uEByoPix7WgV/JnVnHaq50UhqTDOU1vOH22YdFGR5PB38xFd1O1zCf 1CkcSI4kj7brpQ7NkeX9cwBXkpUQMIXfDv2u0FASMP32+4CJL05xL9Y0csJ9ErIlfMLe QkgNrdZJSoaEXwm8rQe1zLDLZq7uPd1C2vyO/XTX9SOkBuJb8c33mP4LSmNANdw/kxRg xsRg== X-Forwarded-Encrypted: i=1; AJvYcCUrfJjyhF2btxAXB3E5XWmUofwPpFkiV+YYgePcUIBrw+fL3duJJFnOJSnDOEW8n9Xu33wXeLC95Rl42jp6fUIiziafj/+B6J9q X-Gm-Message-State: AOJu0Yw8+kRgOYgiZJ3Bt/pdVYgasRog7iVZyk9unWMygDkSQ/dF+a86 XHgvtE8K+UkfhxrHxiFcY9tSeQcUP5cgROQ18Cv5WsrTpu3aJyr2CqVjug5Y3eL00dODaT1qphj laA== X-Google-Smtp-Source: AGHT+IGfziVk8mk/t5qqLgrjh2nAuQB6H4AHqRgQ9isrB7miUbLCHuZyYh4XWKyG4GLGSr/PpOKF+I1vupI= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:660f:b0:62a:2a39:ccd9 with SMTP id 00721157ae682-66500955504mr5567b3.6.1721177487061; Tue, 16 Jul 2024 17:51:27 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:47 +0000 In-Reply-To: <20240717004949.3638557-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-3-jthies@google.com> Subject: [PATCH v1 2/4] usb: typec: ucsi: Add USB PD DRP to USB type From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Add POWER_SUPPLY_USB_TYPE_PD_DRP as a USB type in the UCSI power supply driver. The DRP type is set when the partner supports USB PD and offers both source and sink PDOs. Signed-off-by: Jameson Thies --- drivers/usb/typec/ucsi/psy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index d0b52cee41d2..45113e013696 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -204,8 +204,12 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con, val->intval = POWER_SUPPLY_USB_TYPE_C; if (flags & UCSI_CONSTAT_CONNECTED && - UCSI_CONSTAT_PWR_OPMODE(flags) == UCSI_CONSTAT_PWR_OPMODE_PD) - val->intval = POWER_SUPPLY_USB_TYPE_PD; + UCSI_CONSTAT_PWR_OPMODE(flags) == UCSI_CONSTAT_PWR_OPMODE_PD) { + if (!con->partner_source_caps || !con->partner_sink_caps) + val->intval = POWER_SUPPLY_USB_TYPE_PD; + else + val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP; + } return 0; } @@ -275,6 +279,7 @@ static enum power_supply_usb_type ucsi_psy_usb_types[] = { POWER_SUPPLY_USB_TYPE_C, POWER_SUPPLY_USB_TYPE_PD, POWER_SUPPLY_USB_TYPE_PD_PPS, + POWER_SUPPLY_USB_TYPE_PD_DRP, }; int ucsi_register_port_psy(struct ucsi_connector *con) From patchwork Wed Jul 17 00:49:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13735016 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B42EBA53 for ; Wed, 17 Jul 2024 00:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177495; cv=none; b=i/v3TUTFJSz+Y2alkYYw82F+mtTklKxuUjdyBOhDFPC4I3goIXnMf1+59kCBYxXI/PAn7s6AXYAPln8Yw+81AppSlWXrQr2F2xRmTxvJ0/540TSEjQ4xUjz3ELwARm2ubvFLvKwmBIKcTKr1u69I22ak6ZuedfhVQDoQHfkasnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177495; c=relaxed/simple; bh=wj9RriCI5ML0LRKiteJKsLnz30K8rwhCkEtXmY/ViPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GGjaAOgLwwU34VpoFx3Uy5HZZuavPxXdFIskqpUH3v/idXlIQAQeeeEEOcHMSJYtrfFyYf7U5hxjDgB9iaWx90ihhyTOWqMbaLCcnYs1QeIxcInFel66+HhLgogT8C2We4z9h0mlH5wP4zXLDeOs14QZNO80JSgAmA5ECDYYlwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yPxj65C2; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yPxj65C2" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-65fe57ed70dso74960137b3.2 for ; Tue, 16 Jul 2024 17:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177493; x=1721782293; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KQ9sG390GoUWxGLhfPgzLiAx3nRxfoIGsKOr9STNfgY=; b=yPxj65C2aErZD54SikuxNB2HNoHY6vG1zf9wy+xZgQVTOennpZv2FIzSOYiuePBQwY CjeRpBLat6DBOF8SiSuuqJgSwX48SvfNlUQNsnQrmFTULj8Sa9i93hxJbzft5UBqSeiZ qZ8nTVBMjhTs2pz7rnWctwoZCvh5rifHvt/97ogpclYM0EBxSUeEcr+mpyM+wgal7LpI J4k3PyKl2E12dWZaB1cM8tDcR82QFGFqtoFfqYiG1DpoPqyyxnN42d1wnwhh/B0dWDNZ h6nbJBKrhsdRmIbaQf7dFs4cRcZwl38NFlgCZmC87HSSCglAg9I2m4sqrRYdevGHBMoQ 8ThA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177493; x=1721782293; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KQ9sG390GoUWxGLhfPgzLiAx3nRxfoIGsKOr9STNfgY=; b=pY+muthmZx1vrwmxOybzBTke9IXfd53GWnRyS1FQLGizP/QaahcEmtiVlktYEyaF0H JNI3SyGXZo1EPw9mjegOp3cqDSO6CEPXkhj0TWPuyFdpFKz5GL/SLkP6GdNNFCfBvSii qKUj3hjT0EPTMKVf0CgsfMeIvHXc4kfd68okClO5rhSbeR5vxn8miXqv+yY5Nr7bblWV oLSRnK5nzno237iMUnfyh473oDQ3vB+Q7AlAvsVpggQ0d3aVd2/0i8U3T+l0CMIt+JwG MQcQbVvXGxPOie6oik51xFzt9K3wnQH3UtmjWjD1+vnati0EYNdgcdYtZnNSS4Vj2CAj c9lQ== X-Forwarded-Encrypted: i=1; AJvYcCUgtGCfJdUnPpXWkjowwA7/L7/tF54+ZDHIzC1VY/hGFSmAxaEQ9GuUujnsBsKLvLodfRvLiOiHDg6pgGvztBl3z4SiMXvaGvHP X-Gm-Message-State: AOJu0Yw3jBxnutbx0QVbGDLGyD0sezRRFTGaW2loH1m9dkTyf7Rl4Da5 xTNxVMZCtqjxsF9yqi4YWJPkakH9GpHTu14/EOsgxS2+niR6h3YTOc63RTUkNOhwk5wgkCKPLUQ UTw== X-Google-Smtp-Source: AGHT+IGs8b8XsKNxd1HsfadHottnqrJ+jqGljW+4HqL2Fv8S5g+1p7Dy4x97Rn7ZN/+IhNZ+4wWiwJpUb7o= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:4:b0:648:3f93:68e0 with SMTP id 00721157ae682-6650066ad75mr9087b3.6.1721177492971; Tue, 16 Jul 2024 17:51:32 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:48 +0000 In-Reply-To: <20240717004949.3638557-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-4-jthies@google.com> Subject: [PATCH v1 3/4] usb: typec: ucsi: Set power role based on UCSI charge control From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Add POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX as a property to the UCSI power supply driver. When set to a negative value, set power role to TYPEC_SOURCE, otherwise set the power role to TYPEC_SINK. Signed-off-by: Jameson Thies --- drivers/usb/typec/ucsi/psy.c | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index 45113e013696..feb344cb7ac8 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -30,6 +30,7 @@ static enum power_supply_property ucsi_psy_props[] = { POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, }; static int ucsi_psy_get_scope(struct ucsi_connector *con, @@ -270,11 +271,54 @@ static int ucsi_psy_get_prop(struct power_supply *psy, return ucsi_psy_get_scope(con, val); case POWER_SUPPLY_PROP_STATUS: return ucsi_psy_get_status(con, val); + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX: + val->intval = 0; + return 0; + default: + return -EINVAL; + } +} + +static int ucsi_psy_set_charge_control_limit_max(struct ucsi_connector *con, + const union power_supply_propval *val) +{ + enum typec_role role; + /* + * Writing a negative value to the charge control limit max implies the + * port should not accept charge. Set the power role to source for a + * negative charge control limit, and sink otherwise. + */ + if (val->intval < 0) + role = TYPEC_SOURCE; + else + role = TYPEC_SINK; + + if (!con->typec_cap.ops || !con->typec_cap.ops->pr_set) + return -EINVAL; + + return con->typec_cap.ops->pr_set(con->port, role); +} + +static int ucsi_psy_set_prop(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct ucsi_connector *con = power_supply_get_drvdata(psy); + + switch (psp) { + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX: + return ucsi_psy_set_charge_control_limit_max(con, val); default: return -EINVAL; } } +static int ucsi_psy_prop_is_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX; +} + static enum power_supply_usb_type ucsi_psy_usb_types[] = { POWER_SUPPLY_USB_TYPE_C, POWER_SUPPLY_USB_TYPE_PD, @@ -303,6 +347,8 @@ int ucsi_register_port_psy(struct ucsi_connector *con) con->psy_desc.properties = ucsi_psy_props; con->psy_desc.num_properties = ARRAY_SIZE(ucsi_psy_props); con->psy_desc.get_property = ucsi_psy_get_prop; + con->psy_desc.set_property = ucsi_psy_set_prop; + con->psy_desc.property_is_writeable = ucsi_psy_prop_is_writeable; con->psy = power_supply_register(dev, &con->psy_desc, &psy_cfg); From patchwork Wed Jul 17 00:49:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13735017 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84B36BA53 for ; Wed, 17 Jul 2024 00:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177498; cv=none; b=Lwy8kznUjP/aHlb0Se9fGjz+j+RCi2IF+tZL6hX6OgsHkTWfjo0awfRNKEAYx5K3hqm//zeLSS4y388plWq0awiOTRVf/eQtQADL1wbczaWAkMnBfaXKDDm8O4PfXjXX0cK3uSfLpUdHTMRUDz/C1c8SH6cT7EhC6orHcDD1YDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177498; c=relaxed/simple; bh=TxBuHJK85vkREbw0WLP5ADupaB4b16I7uMojTYknRa8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hdOVLF+wof0QWQoI+e8ywyEy6tjTD1Rc1A8yC+wFgjx9B7jnJjHSqEpMKct4yjj1+vYhT/7BP3flicmkHeDGmVkp8PaqGnnAgJOcO36RXpFoAisuKrr+svRzFsR7j8doIEXjkhTBvzuF4rXX4alt2hJdkYMkZQNa1ks/w+kRetc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IQEtIZwq; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IQEtIZwq" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6511c587946so127336067b3.1 for ; Tue, 16 Jul 2024 17:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177495; x=1721782295; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HTO1tsJpanrsIXuREfXU+lZcoE2mxE9RW1fzcKxRuPY=; b=IQEtIZwqThfL2tkpbppOAJIWrEBFeGp3JwQsUjLtFGvkKsUrCT2pEDg7MyBBoxyUGt ZxUx4caN1wQfl7C4IqBbD0err8tciyYKAN+fRjlQ0V/0ez+9/DnETUu1YAOkrXOXH/jn 8Fg/+yy7AAraMqKS8laXtfRbjiMdBgWsZFn2+DHpJwlmnc74Uav7A8q5+WLs2m4RAkl3 88+Y5ECH4bCBGSqBtID+FiQsBaAyskBiKCFBst4Gxzw4Rds1vSrfTNk89/5aUCg0q0eR EX4d0r7RJkPtjJH+KAZNbiq2sN/C6DjhZ1HCSjTmKSkzSlxirdTo/f/gihcOZOuDeMHf M//w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177495; x=1721782295; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HTO1tsJpanrsIXuREfXU+lZcoE2mxE9RW1fzcKxRuPY=; b=t0qyUomhNsLy72zKt2yeDA+xJs7vBm9a8b2ucvirATZOu00Z97bChpiG9ZetTUm+eB oTAEEOWu6ZY06SgCT0je6FCUeHOhtjZb+5/S6NCQiPQzIpsH5uXycP+1CrJ5b3zU7OKa Ii0ir3adEW+WrO3mogBVFW/6l401j/s1g5WlPGXXAWrdNruBgLEonCcCEZyQTGeObdSZ OfzU+dyHELp7IqUWPHlkZZQJSG8pT6UOEavD98ff3i4dSGYN15uBQdEspYiBhxaNwVaG 7YNWh/qa70YZlJq3EwZ41g6mT4+Le+O+9oGI0Akmigzu5nfjcL36H73tHoYnR/F1Etv8 ouig== X-Forwarded-Encrypted: i=1; AJvYcCVsJ4neF5hJFSaHy2xK2u1aBtVCPVy6KqEVyRG8XMYwjnDfeBmZsNZadCEkXXHZMA+uj5XGXMu4OCjjx5r9OiF5904W73/O+FqO X-Gm-Message-State: AOJu0YxzaF5J09Vwjjkvq8+t4gfNzDXtmEEwY//PEtkpDgwTIr3l0qGy ng6E9kjVnehYTI2gIr3LPcetY9gHNg2RoauGeAvD7bnIW3D4UbHRzhGusvYg1oR2irYnxmG9Vnq VpQ== X-Google-Smtp-Source: AGHT+IGg09Ayrrw6aRkughQryryAOlXFSVSJLvjMGLhBlG76jIsoZGI0TJ101PkcfAxrh48DyXAxTN6wUSc= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:289:b0:65c:4528:d8ee with SMTP id 00721157ae682-664ff0079f7mr6537b3.4.1721177495402; Tue, 16 Jul 2024 17:51:35 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:49 +0000 In-Reply-To: <20240717004949.3638557-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-5-jthies@google.com> Subject: [PATCH v1 4/4] usb: typec: ucsi: Fix SET_PDR typo in UCSI header file From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Fix SET_PDR typo in UCSI header file. Signed-off-by: Jameson Thies Reviewed-by: Neil Armstrong --- drivers/usb/typec/ucsi/ucsi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 57129f3c0814..375f1881c1e2 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -152,7 +152,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_SET_UOR_ROLE(_r_) (((_r_) == TYPEC_HOST ? 1 : 2) << 23) #define UCSI_SET_UOR_ACCEPT_ROLE_SWAPS BIT(25) -/* SET_PDF command bits */ +/* SET_PDR command bits */ #define UCSI_SET_PDR_ROLE(_r_) (((_r_) == TYPEC_SOURCE ? 1 : 2) << 23) #define UCSI_SET_PDR_ACCEPT_ROLE_SWAPS BIT(25)