Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1255588rdb; Tue, 30 Jan 2024 12:39:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IERvyd/JC676AhLHBWQjALO3GxpvZOcP5IQTlPuLhgEsw3TSXJ7M7seibh09n1lhvzBjmpw X-Received: by 2002:a17:90b:400f:b0:295:ae0c:24c3 with SMTP id ie15-20020a17090b400f00b00295ae0c24c3mr2475960pjb.44.1706647169968; Tue, 30 Jan 2024 12:39:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647169; cv=pass; d=google.com; s=arc-20160816; b=GYDIesplJglrfIMXqXr+iK/22nqFH5CR/7UUSpa3FxuqIl0NMPBmijtk3vwaj2fw38 jb2Knu+O+Bip5MTXLvmsbkCDzMeYVqPv5g4zKktvnJToovHZyYN48bILl/TB0fkuy+cg eqprSRhJRLD7ypK8bgSAc2g/3rh3czVYDWJC4jqtjatfUkLYSbQvZtjDnFdtxQocL25t H6TZKAiw+wbUuQzION+TbPFXpQXRC/fv+tRT0qXE0+I9vRuKOq6axc3GYPbBGNG5TMAx 7byhlplJQ4w2S1s/zym4297+PJITQzoUK8i5z5IXo/YmwhV8SbOR9CZ8m/Of5CYkO9Pg UGLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=6G0YmOD50/3sb0eb05V/Ra/p+656o7Ad1EWSfIxoCZI=; fh=sI67x+ipElJed0sOOYzyBdcuxcM6IP/SOkMgKk0PWRk=; b=hUaXUip7HVGdi+C1JIAYxoeQpHH/4lEry8C+m3CRexV5iUCQI9FGjfwWiKJYE2Tcyz o6dVocV6qWX8zKMiXhu/dc69lxmf1jMoLYvLlp4deSZ1/7KR7e9dV4vRLBYoolc0Wku3 QHlr12/0aeE3DmGoOXtE+r3OnOVu16Z/ECVwLGP8oiLLAWn7Es4KVBF2XkdRNWqFDdVl 7nM1aqyHJHqAIGCGugE8KIy2o6fsRCXs1DYzfedvWDrt3m1pCs55g6iW+iuXqzGS+glt wDgsIsxbXcIa+4DF1oQ5fsj9snSx3IL3kC5bZU9iTF/gqWDEFOyjEZ6k8+U8kgCMSiJT DOZg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=RdZPi4ul; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-45279-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45279-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z7-20020a17090abd8700b00290cf479691si9801943pjr.93.2024.01.30.12.39.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:39:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45279-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=RdZPi4ul; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-45279-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45279-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CE60C285866 for ; Tue, 30 Jan 2024 20:38:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 491B478B68; Tue, 30 Jan 2024 20:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="RdZPi4ul" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA02762EE; Tue, 30 Jan 2024 20:38:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647082; cv=none; b=Q0NP8BhjHThBBxFGE0scZv6Qkf1JKb0rn2XOSL9jCXgKb8rQ0tOEwyJpTrU8lHbwcFMLwxLf+h1mo+0QLiGuj07VeRs63RWtZCG2e/CncHW+xFDeFTr9x0abC7zgnh1w5pWLY9gty7BzeOFiABwA5dk/nYU56cdD5V4Mr72/paM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647082; c=relaxed/simple; bh=zXXGsJFbgiYzogwaULyPk2kphg0Ch0Uphvq2gjdcWj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAmqZXpsxL3Ei1wKw9b0staiwk6HVozx6Sm6XHA07Z7DeYgjC7KQ+T/rzXiYxI4uhkWQDAQgNwUrOgNYA+1xL3OHC+8/JEWaWxUsriOzn0pjk3+JfQeGCqyuKISa7u1tK+AMmP4BF/d5yXKnOnRGKD7KTOiFtNhqudlp5SlPecs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=RdZPi4ul; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 2EA8046B74; Tue, 30 Jan 2024 20:37:59 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ond=C5=99ej=20Jirman?= , Hans de Goede , Aidan MacDonald , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH v2 4/5] power: supply: axp20x_usb_power: enable usb_type reporting Date: Tue, 30 Jan 2024 15:28:00 -0500 Message-ID: <20240130203714.3020464-5-aren@peacevolution.org> In-Reply-To: <20240130203714.3020464-1-aren@peacevolution.org> References: <20240130203714.3020464-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: *** X-Spamd-Bar: +++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1706647079; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=6G0YmOD50/3sb0eb05V/Ra/p+656o7Ad1EWSfIxoCZI=; b=RdZPi4ul39i/V1pJazsVpkPeFOvR3+beShpiRU91OnRSd+nbRXbU2OYXRw/0MrUjD5TZ9+ Qk6gvexMDXB+HIAp73g+/9Zsll64rkCaDMYD60kWRN8MkMorrj9J7sJj1ktlveT36DRvZ+ VbgZPODoGJrA9lrmOvGmfjBzPvT6Hos= The axp803 and axp813 chips can report the detected USB BC mode. SDP, CDP, and DCP are supported. Signed-off-by: Aren Moynihan --- (no changes since v1) drivers/power/supply/axp20x_usb_power.c | 73 ++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index ac5a3f126df6..dae7e5cfc54e 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -55,6 +55,7 @@ struct axp_data { struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; struct reg_field usb_bc_en_bit; + struct reg_field usb_bc_det_fld; struct reg_field vbus_disable_bit; bool vbus_needs_polling: 1; }; @@ -66,6 +67,7 @@ struct axp20x_usb_power { struct regmap_field *vbus_valid_bit; struct regmap_field *vbus_mon_bit; struct regmap_field *usb_bc_en_bit; + struct regmap_field *usb_bc_det_fld; struct regmap_field *vbus_disable_bit; struct power_supply *supply; const struct axp_data *axp_data; @@ -134,6 +136,37 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work) mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); } +static int axp20x_get_usb_type(struct axp20x_usb_power *power, + union power_supply_propval *val) +{ + unsigned int reg; + int ret; + + if (!power->usb_bc_det_fld) + return -EINVAL; + + ret = regmap_field_read(power->usb_bc_det_fld, ®); + if (ret) + return ret; + + switch (reg) { + case 1: + val->intval = POWER_SUPPLY_USB_TYPE_SDP; + break; + case 2: + val->intval = POWER_SUPPLY_USB_TYPE_CDP; + break; + case 3: + val->intval = POWER_SUPPLY_USB_TYPE_DCP; + break; + default: + val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; + break; + } + + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -204,6 +237,9 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = ret * 375; /* 1 step = 0.375 mA */ return 0; + + case POWER_SUPPLY_PROP_USB_TYPE: + return axp20x_get_usb_type(power, val); default: break; } @@ -367,6 +403,22 @@ static enum power_supply_property axp22x_usb_power_properties[] = { POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, }; +static enum power_supply_property axp813_usb_power_properties[] = { + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_USB_TYPE, +}; + +static enum power_supply_usb_type axp813_usb_types[] = { + POWER_SUPPLY_USB_TYPE_SDP, + POWER_SUPPLY_USB_TYPE_DCP, + POWER_SUPPLY_USB_TYPE_CDP, + POWER_SUPPLY_USB_TYPE_UNKNOWN, +}; + static const struct power_supply_desc axp20x_usb_power_desc = { .name = "axp20x-usb", .type = POWER_SUPPLY_TYPE_USB, @@ -387,6 +439,18 @@ static const struct power_supply_desc axp22x_usb_power_desc = { .set_property = axp20x_usb_power_set_property, }; +static const struct power_supply_desc axp813_usb_power_desc = { + .name = "axp20x-usb", + .type = POWER_SUPPLY_TYPE_USB, + .properties = axp813_usb_power_properties, + .num_properties = ARRAY_SIZE(axp813_usb_power_properties), + .property_is_writeable = axp20x_usb_power_prop_writeable, + .get_property = axp20x_usb_power_get_property, + .set_property = axp20x_usb_power_set_property, + .usb_types = axp813_usb_types, + .num_usb_types = ARRAY_SIZE(axp813_usb_types), +}; + static const char * const axp20x_irq_names[] = { "VBUS_PLUGIN", "VBUS_REMOVAL", @@ -475,13 +539,14 @@ static const struct axp_data axp223_data = { }; static const struct axp_data axp813_data = { - .power_desc = &axp22x_usb_power_desc, + .power_desc = &axp813_usb_power_desc, .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), + .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), .vbus_needs_polling = true, }; @@ -629,6 +694,12 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (ret) return ret; + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->usb_bc_det_fld, + &power->usb_bc_det_fld); + if (ret) + return ret; + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_disable_bit, &power->vbus_disable_bit); -- 2.43.0