Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp225964rdb; Mon, 22 Jan 2024 18:51:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEIfV0dVfEO32VTIMxDOXs8dNdRv1csxF3zNLEfjLv4GHADzNUFQUF3p54d3gONW0Vyfbc X-Received: by 2002:a17:907:a78c:b0:a23:4dc0:97eb with SMTP id vx12-20020a170907a78c00b00a234dc097ebmr3040664ejc.14.1705978275453; Mon, 22 Jan 2024 18:51:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705978275; cv=pass; d=google.com; s=arc-20160816; b=MYrQIf81XrGZVzmXoy/eI64c45BC1szHf/3OHLyzQP57mUzHQqMLkAoSm7KU9h4QeA B0XfOMI1skYSBu6lQxJyqdynk9ebEjML/ebEm8el8pVq/6l4r4TmFUylLxqo3ADvVEZw e8MV69qFva4Uv0NbzYbg7iL2KGnV/5MX8e3rlkqvOPvr44fyxWbFe6wiJGR2EizVW+0s aZs6vpH6dSDcGWT0GTYWra2uDQppSjGp7uLLGiE/bziOrnvqVfny9eDpoDhl0ENo17tv vexHQtk7Sb6CaceHqfJuUh8AstHXdnarfRHYe3Vebh5Fm0bIT5mYrfID0Cw4rWyJdrhX VN6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:to:from:date; bh=K6YQbP62dv7PqeMoua4cZkGTK4uQWle4Ke5iT1tdknQ=; fh=AW3p1fMMgYfBwIUeJnldo/X9QRVQfzhPKYY1Oxoj5/o=; b=u6GFzDNM9tv8QRUHdrnw9og9CRhwgzLEnRwMIBm/RdQG2VOkwgYD+RqmsXKZCML68w rH22Jghbzc/7zA+xC6AlBX0AO1ew5C+iLpMDwf9teLKc6A13gSooCcMc/2INtRAArFzp HHaYOhBaZVJEgo5Is3E7sxyrftkFDF1UZ38pZO8yrfXNQP0QBBO6sw95j6lTueaRLDj0 gEgzldIVuu/IBFj5C0USxoFxUZjNYOlEJF4gS+KoCNX9gQNsYgpn22bomX9yklqVZOin KAJmLXYG25NKlj3T9JcyEMLHTRl+otpWiHtiUalXc6wAAt3SsouCp+TNFWqUE0xdOY+h wFPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=fQQ5yhGW; 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-34646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t5-20020a170906178500b00a2ce2a3642bsi9714871eje.896.2024.01.22.18.51.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 18:51:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=fQQ5yhGW; 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-34646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34646-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B427A1F2A60A for ; Tue, 23 Jan 2024 02:46:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF7541FD1; Tue, 23 Jan 2024 02:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="fQQ5yhGW" 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 E3E48184; Tue, 23 Jan 2024 02:41:11 +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=1705977673; cv=none; b=ZQtRqVYDlYioaYtCsiyRHyglPvUCScMnbsO19TLxFfX7HrYGb0kKQSnJO78Af73j3HYXzDQm2XGX8WDtg8cbH+QS2s1MoNL8gjcGizFBO9DfI2/0aQhoyLuGKOua8T+PUg5lj//IIJFUK2wdbZX6LsVUaLAIGDv3HMYR/6iLWo4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705977673; c=relaxed/simple; bh=kLp8meRYf6WAyXXCjrEl3NJH0W1GjlZ5PFKii4fgdFE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jxFw3smPU1nuNxPWBmPVLyuT0d4x5kHvaaBHMJCiTCbul3ohUI3y/mGC73NMKNWFGEJ8TJMygKkpr9m/E1Gt577p3zcLMQnWozYafaNogpcX0YmtcC4Ze6om+o5U4tlZVYvxjuWJFwFHV7YEN7xQXUWfK8SABn/bRL4b0XJtOlQ= 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=fQQ5yhGW; 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 DD29746341; Tue, 23 Jan 2024 02:41:09 +0000 (UTC) Date: Mon, 22 Jan 2024 21:41:07 -0500 From: Aren To: =?utf-8?Q?Ond=C5=99ej?= Jirman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Aidan MacDonald , Chen-Yu Tsai , Sebastian Reichel Subject: Re: [PATCH 2/3] power: supply: axp20x_usb_power: enable usb_type reporting Message-ID: References: <20240121014057.1042466-1-aren@peacevolution.org> <20240121014057.1042466-5-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spamd-Bar: / Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1705977670; h=from:subject:date:message-id:to:mime-version:content-type:content-transfer-encoding:in-reply-to:references; bh=K6YQbP62dv7PqeMoua4cZkGTK4uQWle4Ke5iT1tdknQ=; b=fQQ5yhGWWTr4IwtJzOtx4F/LlI9/tvsVMBUxC3NnhLqsdUC/tSkNdSd86IdTjMIBSRjbaU DE9smiSBCRiZavPpIXrF2XauZtVhOtGwZFj8ZLlgMGBVSB/iXX6Go4D1u7rbNo9ccFUp1K esWAk1hQ7vGg7qv0EnbVa3C3XNuF21Y= On Sun, Jan 21, 2024 at 12:55:43PM +0100, OndÅ™ej Jirman wrote: > Hello Aren, > > On Sat, Jan 20, 2024 at 08:40:02PM -0500, Aren Moynihan wrote: > > 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; > > What if detection is disabled becase custom input current limit was set by the > user? Does the HW keep the result of previous detection in the register? In that case the result appears to be USB_TYPE_UNKNOWN. I don't expect that would cause problems, but I guess we could cache the value when disabling usb bc detection if necessary. > Kind regards, > Ondrej > > > + 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 > >