Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4035765imm; Tue, 29 May 2018 20:19:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIVj+yOMh2MitVrI4TOS4Ga2BMKjnLXCqhNiNh4tiKlhO//iUySxiCseqqrfGrEZ5cQDloW X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr1128203plb.24.1527650351899; Tue, 29 May 2018 20:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527650351; cv=none; d=google.com; s=arc-20160816; b=av9szSz0/FpsonYqOIM9fL8bRz6Yqhn68uK6xZJpUBXC9gFnV6nIe5Ju4+NDj2f+j+ WrNUAEIu7yqMR+JF8fdhTjyssW1QN2clkOfsdppylf1fVcG6U0DNFizQ4N7x/H+PoEL8 LBeb2EQxQy8oPQz/AFLAaQOwPy3hUv5pSIN/asV/BliZ63adUrVPSiewGK0Jhx2AzHmD rthRUetkMEbfnoIREOKBq+n3QumnUYSl0EgnEu6V46ra56FFA4zpRjazEnrPa8KZzKHC JkoVFJNPWb1/mnVPYcA7qjxNuXW8boi4bVRB0TeRtPGoVQe6UH4S85jr6HRpWUNmbCbW kKCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=VjzMlxqHAEv/rahoegqaBNo1I4eTKXjd2zEDOI4agog=; b=iJ3Cx81ruTCdTYMCj7Gfm/g3gxYEOmorGmmYZHg2jA/cuH5hR6iWjA62ssOSEO40mJ tVJ23JCIgmIBIC/BI8HuZkYBFzQKPVYNf1JxcXmIyi8i9wRhXaMs4qI6XbvEeK2Z8vPS gPqZIrDKERRnReomV8xFWyVQhFjKYAgvIfFHlQTcLd8BDfAiBDCVC1/Y1UiodRzKtr/G BWWQE6ItydxeFMQpNxLhVFdrzQGqIpF/VqWk3ph9XGrWZHNK19xknc850rRoJeuZbhC+ X5TpRKpBUNagLZp1o6KpmfrITLqKLzppVGkKBLbNUu343UB2kHtkoLKdQ3MplLRv2Orl Fj6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=rtgGQq3N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1-v6si33800318plb.549.2018.05.29.20.18.58; Tue, 29 May 2018 20:19:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=rtgGQq3N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968608AbeE3DSL (ORCPT + 99 others); Tue, 29 May 2018 23:18:11 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35744 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937030AbeE3DRz (ORCPT ); Tue, 29 May 2018 23:17:55 -0400 Received: by mail-pf0-f193.google.com with SMTP id x9-v6so8269507pfm.2 for ; Tue, 29 May 2018 20:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VjzMlxqHAEv/rahoegqaBNo1I4eTKXjd2zEDOI4agog=; b=rtgGQq3Na8mt+aivM8rS3v/LbvzxzmMbsKBgHpdMzCpZMbtKy7jcZyQumsYzhlxjj7 Uhc8/f/4DojoHYUHfXL4wkum3pRvvdLP1Not8rC9eu86mLbc9ATGfp93HYXWH0CqW5QM gzGYa+z/Cg15WYrVJtp4lzKopxUxDHbdQDl2czDB+hlBSKlSt2J2tfQUH173mrjo78ch CrEO/GrTpE2z5q/6CCBHtXpQGJOGwqmrQFvoTafIzGbW+fq6LCi4DZhskMx1+LhckLV4 K3awnELQ7OjlXg1St7/qxXvIPYmPE2c92vtZ1n1L2BQGx9lJMW8RLyNHZdx5+glCJtdo GOEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VjzMlxqHAEv/rahoegqaBNo1I4eTKXjd2zEDOI4agog=; b=YGLZ8K+RRv9KnSzfkFNRcXv3sNqSaWylm1HRmyOPudvnIiCPfVT6hSyBSrz6Kgjcjp 6HUKSEq43A6dA3Tl1tN6cJC9rizUs0UuKXrvFrsfIUkmtBJlSW8TO1pVlkJRjEe7w1Se 0Go/DBV1bCGU6ASuiJVmi60CUJPk1aTZBBCYRln/L0HPlewZgS5oCOmVKHop6sQhj+Wa I/JiPH6c95cvYs/g4zciRiCGkJ5rzTl2XybMi1xSrOaeaK4gbSvjkq3+78ljWBtbPQwo 6NNAvzyOS2ZGTUMBE9to9bpG1zOvA/GEn7gwylNgFMd4Pps9F4N1Qgiv8vI21knUFKhf Mg0g== X-Gm-Message-State: ALKqPwc3bACiqWME4dDEtKibjLkMC7OZGprIEV3G2yvYa51hYCxiYbeX vDUh7P+0o52Urd4DrVeT4dxGyA== X-Received: by 2002:a63:66c3:: with SMTP id a186-v6mr805805pgc.408.1527650274134; Tue, 29 May 2018 20:17:54 -0700 (PDT) Received: from localhost.localdomain (c-69-181-66-249.hsd1.ca.comcast.net. [69.181.66.249]) by smtp.gmail.com with ESMTPSA id k73-v6sm12372784pfb.31.2018.05.29.20.17.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 20:17:53 -0700 (PDT) From: Fabien Parent To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, eballetbo@gmail.com, gpain@baylibre.com, Fabien Parent Subject: [PATCH 3/3] power: supply: cros: add property to detect connected ports Date: Tue, 29 May 2018 20:17:04 -0700 Message-Id: <20180530031704.18597-4-fparent@baylibre.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180530031704.18597-1-fparent@baylibre.com> References: <20180530031704.18597-1-fparent@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a port is connected but acting as a source, its 'online' and 'status' properties are identical to a port that is not connected. This makes it tedious for userspace to know for sure whether a port is connected or not. This commit adds a new property 'present' to reflect whether a port is connected or not. Signed-off-by: Fabien Parent --- drivers/power/supply/cros_usbpd-charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/power/supply/cros_usbpd-charger.c b/drivers/power/supply/cros_usbpd-charger.c index 808688a6586c..d44ab35670ab 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -32,6 +32,7 @@ struct port_data { struct power_supply_desc psy_desc; int psy_usb_type; int psy_online; + int psy_present; int psy_status; int psy_current_max; int psy_voltage_max_design; @@ -54,6 +55,7 @@ struct charger_data { static enum power_supply_property cros_usbpd_charger_props[] = { POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, @@ -65,6 +67,7 @@ static enum power_supply_property cros_usbpd_charger_props[] = { static enum power_supply_property cros_usbpd_dedicated_charger_props[] = { POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_VOLTAGE_NOW, }; @@ -205,18 +208,22 @@ static int cros_usbpd_charger_get_power_info(struct port_data *port) case USB_PD_PORT_POWER_DISCONNECTED: port->psy_status = POWER_SUPPLY_STATUS_NOT_CHARGING; port->psy_online = 0; + port->psy_present = 0; break; case USB_PD_PORT_POWER_SOURCE: port->psy_status = POWER_SUPPLY_STATUS_NOT_CHARGING; port->psy_online = 0; + port->psy_present = 1; break; case USB_PD_PORT_POWER_SINK: port->psy_status = POWER_SUPPLY_STATUS_CHARGING; port->psy_online = 1; + port->psy_present = 1; break; case USB_PD_PORT_POWER_SINK_NOT_CHARGING: port->psy_status = POWER_SUPPLY_STATUS_NOT_CHARGING; port->psy_online = 1; + port->psy_present = 1; break; default: dev_err(dev, "Unknown role %d\n", resp.role); @@ -362,6 +369,7 @@ static int cros_usbpd_charger_get_prop(struct power_supply *psy, */ if (ec_device->mkbp_event_supported || port->psy_online) break; + case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_CURRENT_MAX: case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: case POWER_SUPPLY_PROP_VOLTAGE_NOW: @@ -380,6 +388,9 @@ static int cros_usbpd_charger_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_ONLINE: val->intval = port->psy_online; break; + case POWER_SUPPLY_PROP_PRESENT: + val->intval = port->psy_present; + break; case POWER_SUPPLY_PROP_STATUS: val->intval = port->psy_status; break; -- 2.17.0