From patchwork Sun Jan 21 01:40:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 189785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1878677dyb; Sat, 20 Jan 2024 17:45:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhMU6tUYTg03aZehe8UcXIC+Q4YJiYvZGQZDpnjgf7GdPNrgwK6Y8l00PXrygFjPUsyjfN X-Received: by 2002:a05:6e02:523:b0:361:9509:27b6 with SMTP id h3-20020a056e02052300b00361950927b6mr3187886ils.41.1705801513132; Sat, 20 Jan 2024 17:45:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705801513; cv=pass; d=google.com; s=arc-20160816; b=Pqt6IcIjg/4zKg7ufYpc+aHW8awumP94jIy3dQavIJ977xnF9law7efFrYq1trgwBH ZNmM8mmI/n5lNbR1sAJ/uSETge6u6G3A9OPDQCMZwNYA3ojLrTDpTVmYC93wDeH4Bvz6 T7SRjWFq05Rwrs+sM3f0Qf+KMFz+uJuOnyypkOyw4SrZ9FCO5uZeTJcA2SnytF56Zeti MjckV+OprqL1S12jTtT1uFsd/TYtAnxuajUeCltV3ChajMFpxectVw292nJr/hXox/ZI Z3lvCuK6HF09lpTV6hEK7WruW3sNZNBllymj670sCL3ycLJkyG78I1RSGNhu8cliwgNo yvUQ== 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=1Ryn10C70a9eu2vzgWK/233iIVPb5X5KUoLMJ9eT+QI=; fh=eFCTS4Ca+qpaFRwPKpEidZ8XXzB0gM774/68c0nALYA=; b=yelPtFFSIY1DfSkbgAFf8EJWUFe29vOYRmG3YzAojiyyDJY2vMGwNAoBYXWnzWhMga hOCy8wDc3XWL2E4SwszB672L5SJPlUwUH41aUKUkyPjfU3NfE3ngCUsBe+rdaDs2CyiD d+UyQUJfSkdXTYHs6Hnqp2fWRqqW5HJSzMd04H1B5QZiDn4C5P1QT6Z5Bj2MRAXiOwPW x6SEzQKJOhuH+MHmowW6E6ixuW7FY7AufKXoXvD94IAXhfMneyPd4BaVjysxkLGh5DqM gY9NX9/pY/bmOXM+IopC5UDzTWbGN7Nux6yw/ZM+yRQCIAh2DCMgKZucDf59dnHVClVS G9/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=bY6eYvsB; 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-31948-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31948-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k17-20020a170902c41100b001d51f3acb68si6028949plk.280.2024.01.20.17.45.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 17:45:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31948-ouuuleilei=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=bY6eYvsB; 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-31948-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31948-ouuuleilei=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 D5BD32831C0 for ; Sun, 21 Jan 2024 01:45:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D86B63529F; Sun, 21 Jan 2024 01:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="bY6eYvsB" 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 B279134180; Sun, 21 Jan 2024 01:44:53 +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=1705801495; cv=none; b=t28BSom9w3FvXnGJYNhwVAmCMUoQSaQzwNqfGDgdj9koJUNkR4Qs2YSXjZhq0QVorH3fT4Fto2HqcpFSJBeAVAuxIaI0ts5dBRa0tRVu5Y0w0O1K4A+0/7/qQgRcNQ4bABwl9gTsu36t7dEd8grebmmJaJdE/lAD/l7+VrsBfTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801495; c=relaxed/simple; bh=uXkUwCYq0H2JtLAC7JcuuDcFZ0QN3QO/RdNy0mw0xvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJ5HZC1zRhMtJ6gXMcB3uV70j3kusff6CKT7bE95jxzG8Nr+vROGXcbAyV/elcypHcJVr0POzT4HKZIJsT1RJKjXZ4hGpkA6/uTjaVS1gj3gU2cL92UvHfL94MFthtneg2oenfnCqaf6t6JxNQF+h/d6J9ynHH2lT+KAstlZZig= 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=bY6eYvsB; 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 8560743C8C; Sun, 21 Jan 2024 01:44:52 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?utf-8?q?Ond=C5=99ej_Ji?= =?utf-8?q?rman?= , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH 2/3] power: supply: axp20x_usb_power: enable usb_type reporting Date: Sat, 20 Jan 2024 20:40:02 -0500 Message-ID: <20240121014057.1042466-5-aren@peacevolution.org> In-Reply-To: <20240121014057.1042466-1-aren@peacevolution.org> References: <20240121014057.1042466-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1705801493; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=1Ryn10C70a9eu2vzgWK/233iIVPb5X5KUoLMJ9eT+QI=; b=bY6eYvsBWw7PD/Q1sl8IgYA0nY9CiwfYHPli59OymCdke/XL10mFB3Nt3C5EPOg0fMfS8B TUfHmMXrWbbP0RvNqZLcvMul3Nysk4SYW9TgT+Z0JtqjCU0vEkDMvmF0BAwKrVCSGTRpDm +oiKXDRhR3D4hqOs0rh4yqn2DFxfkA8= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788662527384485114 X-GMAIL-MSGID: 1788662527384485114 Axp803 and axp813 can report the detected usb bc mode. SDP, CDP, and DCP are supported. Signed-off-by: Aren Moynihan --- drivers/power/supply/axp20x_usb_power.c | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 8c0c2c25565f..5656f6e57d54 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -57,6 +57,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; }; @@ -69,6 +70,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; @@ -197,6 +199,37 @@ axp20x_usb_power_get_input_current_limit(struct axp20x_usb_power *power, return 0; } +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) { @@ -266,6 +299,8 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: return axp20x_usb_power_get_input_current_limit(power, &val->intval); + case POWER_SUPPLY_PROP_USB_TYPE: + return axp20x_get_usb_type(power, val); default: break; } @@ -423,6 +458,14 @@ static enum power_supply_property axp813_usb_power_properties[] = { POWER_SUPPLY_PROP_VOLTAGE_MIN, POWER_SUPPLY_PROP_CURRENT_MAX, 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 = { @@ -453,6 +496,8 @@ static const struct power_supply_desc axp813_usb_power_desc = { .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[] = { @@ -555,6 +600,7 @@ static const struct axp_data axp813_data = { .input_curr_lim_table = axp_813_usb_input_curr_lim_table, .input_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, }; @@ -708,6 +754,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);