Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1856044rdb; Sat, 20 Jan 2024 17:45:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IG68RNkdAxh7PTkAMkRQrAd5XFBiQvlTSF0PBt1TKX3gWf5sk6bMkGsBefODGCPWyIlInpD X-Received: by 2002:a17:903:2352:b0:1d4:cb95:179d with SMTP id c18-20020a170903235200b001d4cb95179dmr1325124plh.100.1705801511870; Sat, 20 Jan 2024 17:45:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705801511; cv=pass; d=google.com; s=arc-20160816; b=FS7WzAAgRzFUKbvge83yXmXgj2M3nAl84uXwJZU8ow175leqsrU9P99CfBzZysLWOf v9Cu3qVjVsuviJmTnWlhXTQhP0k6jSiS31dIFzH0QTKWQd07dDDdn/K83w35BVQUPrIA FPHdh2swFWt0AHAfm7o0AzmpMg0maCskhXRDGglS3+O3vjLJfg/H53629CXG4WpasYXI evLyVXQ/LgrWcmb1tHEwJF9/pnaQ4CyBAbwJlBUOUajMRo8ZiVLsCML6VEQwn5WIUz5G NcxzXMHtiIFwUweVqVlKnvNjFyjJV1AmoXlRRufKazSCvQfYIJL+vtwg0UweOLJ761pl 9hYg== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y21-20020a1709027c9500b001d4b4daa27dsi5745042pll.19.2024.01.20.17.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 17:45:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31948-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3E88AB21AFD for ; Sun, 21 Jan 2024 01:45:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0385335286; Sun, 21 Jan 2024 01:44:56 +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=20Jirman?= , 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 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=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= 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); -- 2.43.0