From nobody Sun Feb 8 16:05:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 6FA9D1DDD1 for ; Sat, 31 Aug 2024 14:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114065; cv=none; b=uwqAuCXKsoNMOOMZi/cgt/hXGrBwc6hyV+PcAQ8/F4rt7/wxUBpVUQC7ZNHk+0i+GH3yKvPBrjaKgnJ/DKq4stBdufRl9RCIYuy7oqTn9YxvZPIMXMg2bcvmU5NoxIOp/kMa7yaY6j9onTQJB5Yd9AaQGE/USGB9hjEGa8BIHdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114065; c=relaxed/simple; bh=wxAqhT4ylvXwfHeaFXx2m6qv7+IPXABabJmxntIS9rA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wqj+i9G6Ebb2nNOdAaf096W7H8ZXqyGMd5W0XZl+s5DXw2smLkBaE7uMBgqoZBFTGTikfVU0yuu9GSKw2n1eN68JmYt/KX3b5WCXgqU/CIXGt6FopmsJi1Kkv4hm+6TZH1r5Yq7Spz6pst3qrAhKGt6dfthFioruMohrKjuBJHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IRbpa1Fq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IRbpa1Fq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725114063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/lkCNG9OGHuMCZ2ifhRy12eWeNAdzUD42d8uAz9aRXo=; b=IRbpa1FqTSi/wKJUrccbZrik+lAsrggp0BJWvRvkWmdExouOAq2RlKTbZO5OcGmF43V/KA /wQWcMWSjjYEKWfRw/vLiwwaekHGGjWq9xLuZcIiBxwrUfF6ew5YdhB9hZriQbReSLkES6 0+e81vPhLskyFn6tmFbLhI5fYunJieQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-QNnOJ3KPMVKqjF4lldj5AA-1; Sat, 31 Aug 2024 10:20:58 -0400 X-MC-Unique: QNnOJ3KPMVKqjF4lldj5AA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84F821955D47; Sat, 31 Aug 2024 14:20:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B9053001FE8; Sat, 31 Aug 2024 14:20:50 +0000 (UTC) From: Hans de Goede To: Sebastian Reichel , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , MyungJoo Ham , Chanwoo Choi , Greg Kroah-Hartman , Heikki Krogerus , Vinod Koul , Kishon Vijay Abraham I Cc: Hans de Goede , Enric Balletbo Serra , Andrey Smirnov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH 1/6] power: supply: "usb_type" property may be written to Date: Sat, 31 Aug 2024 16:20:34 +0200 Message-ID: <20240831142039.28830-2-hdegoede@redhat.com> In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com> References: <20240831142039.28830-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" According to Documentation/ABI/testing/sysfs-class-power the "usb_type" property is Read-Only. For power-supplies which consume USB power such as battery charger chips, this is correct. But the UCS1002 USB Port Power Controller driver which is a driver for a chip which is a power-source for USB-A charging ports "usb_type" is actually writable to configure the type of USB charger emulated by the USB-A port. Adjust the docs and the power_supply_sysfs.c code to adjust for this new writeable use of "usb_type": 1. Update Documentation/ABI/testing/sysfs-class-power to document that "usb_type" may be writable 2. Change the power_supply_attr type in power_supply_sysfs.c from POWER_SUPPLY_ATTR() into POWER_SUPPLY_ENUM_ATTR() so that the various usb_type string values from POWER_SUPPLY_TYPE_TEXT[] such as e.g. "SDP" and "USB_PD" can be written to the "usb_type" attribute instead of only accepting integer values. Cc: Enric Balletbo Serra Cc: Andrey Smirnov Signed-off-by: Hans de Goede Reviewed-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-class-power | 7 ++++++- drivers/power/supply/power_supply_sysfs.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/AB= I/testing/sysfs-class-power index 84973f66b42c..45180b62d426 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -608,7 +608,12 @@ Description: the supply, for example it can show if USB-PD capable source is attached. =20 - Access: Read-Only + Access: For power-supplies which consume USB power such + as battery charger chips, this indicates the type of + the connected USB power source and is Read-Only. + + For power-supplies which act as a USB power-source such as + e.g. the UCS1002 USB Port Power Controller this is writable. =20 Valid values: "Unknown", "SDP", "DCP", "CDP", "ACA", "C", "PD", diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supp= ly/power_supply_sysfs.c index 3e63d165b2f7..ff7e423edd57 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -209,7 +209,7 @@ static struct power_supply_attr power_supply_attrs[] = =3D { POWER_SUPPLY_ATTR(TIME_TO_FULL_NOW), POWER_SUPPLY_ATTR(TIME_TO_FULL_AVG), POWER_SUPPLY_ENUM_ATTR(TYPE), - POWER_SUPPLY_ATTR(USB_TYPE), + POWER_SUPPLY_ENUM_ATTR(USB_TYPE), POWER_SUPPLY_ENUM_ATTR(SCOPE), POWER_SUPPLY_ATTR(PRECHARGE_CURRENT), POWER_SUPPLY_ATTR(CHARGE_TERM_CURRENT), --=20 2.46.0 From nobody Sun Feb 8 16:05:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 0250D2B9D6 for ; Sat, 31 Aug 2024 14:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114070; cv=none; b=pMMJqIqg/mJN+kV7GiUKpordDwTF931BSAssXLoW3PfA4d3aPR2FVAo1JxtB/TVEiwbEWfkxXcZErUXSFFjse4bebyrkoILrBesGr0byIHW0sERDc2snfspsa9/hSQOMMSzIH3xPncOTZxiIpaUbXrQyZPP9tkpEn6zzdHEo9wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114070; c=relaxed/simple; bh=zINAiPqxol2jf7n95zfSwjCFNPHHesldhpOGxFwbcGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BnHnaxZwHI3o2W0ZFpx+B2bICLon8YvEKlCQ9nbrU4wzgUr/kEhq0KIdduFLCDxbnSzI6mYoY8Y3CntcitIscfc8iqx1+v00CeJkeGbeav6pQ1T4zESXenYfCBSUqGAuP4QJpS/HVhFmJj29QM/NnQ38MSTu8UlrWk5/Goi661A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fEZve2Oe; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fEZve2Oe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725114067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y5O3GspAeKQ3pneZEdcCy+Sw5OHilzaQkJasxbh7z3U=; b=fEZve2OeorTK7NMm3EejtESaekEC1D8/AW99yHc8DH+krZW/JaZuYl3+EfI+r0fo4F5iIi s/cfQy4nC1OR3H5MkxSHaCT2JGDd+dQ0rw7XsPCEelJFyjBQr34vgBGWGEjTvhXATvnKXX qXShm36Ii3IJvGAbamfx5zEzYIEmX0w= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-UNIRLRDgMwesO4-JeuSJWA-1; Sat, 31 Aug 2024 10:21:03 -0400 X-MC-Unique: UNIRLRDgMwesO4-JeuSJWA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 26D1A19560AD; Sat, 31 Aug 2024 14:21:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC60130001A4; Sat, 31 Aug 2024 14:20:55 +0000 (UTC) From: Hans de Goede To: Sebastian Reichel , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , MyungJoo Ham , Chanwoo Choi , Greg Kroah-Hartman , Heikki Krogerus , Vinod Koul , Kishon Vijay Abraham I Cc: Hans de Goede , Enric Balletbo Serra , Andrey Smirnov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH 2/6] power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string values Date: Sat, 31 Aug 2024 16:20:35 +0200 Message-ID: <20240831142039.28830-3-hdegoede@redhat.com> In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com> References: <20240831142039.28830-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" power_supply_sysfs.c accept wrrites of strings to "usb_type" for strings values matching an entry in POWER_SUPPLY_USB_TYPE_TEXT[]. If such a string value is written then the int value passed to ucs1002_set_property() will be an enum power_supply_usb_type value. Before this change ucs1002_set_usb_type() expected the value to be an index into ucs1002_usb_types[]. Adjust ucs1002_set_usb_type() to use the enum value directly so that writing string values works. The list of supported types in ucs1002_usb_types[] is: PD, SDP, DCP, CDP. The [POWER_SUPPLY_USB_TYPE_]SDP, DCP and CDP enum labels have a value of 1, 2 and 3. So userspace selecting SDP, DCP or CDP by writing 1, 2 or 3 will keep working. POWER_SUPPLY_USB_TYPE_PD which is mapped to the ucs1002 dedicated mode however has a value of 6. Before this change writing 0 would select the dedicated mode. To preserve userspace API compatibility also map POWER_SUPPLY_USB_TYPE_UNKNOWN (which is 0) to the dedicated mode. Cc: Enric Balletbo Serra Cc: Andrey Smirnov Signed-off-by: Hans de Goede --- drivers/power/supply/ucs1002_power.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/ucs1002_power.c b/drivers/power/supply/uc= s1002_power.c index 7970843a4f48..b67d5b03d93e 100644 --- a/drivers/power/supply/ucs1002_power.c +++ b/drivers/power/supply/ucs1002_power.c @@ -308,10 +308,13 @@ static int ucs1002_set_usb_type(struct ucs1002_info *= info, int val) { unsigned int mode; =20 - if (val < 0 || val >=3D ARRAY_SIZE(ucs1002_usb_types)) - return -EINVAL; - - switch (ucs1002_usb_types[val]) { + switch (val) { + /* + * POWER_SUPPLY_USB_TYPE_UNKNOWN =3D=3D 0, map this to dedicated for + * userspace API compatibility with older versions of this driver + * which mapped 0 to dedicated. + */ + case POWER_SUPPLY_USB_TYPE_UNKNOWN: case POWER_SUPPLY_USB_TYPE_PD: mode =3D V_SET_ACTIVE_MODE_DEDICATED; break; --=20 2.46.0 From nobody Sun Feb 8 16:05:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 20F9742077 for ; Sat, 31 Aug 2024 14:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114074; cv=none; b=lUUCD/0YyOZgKPGmMGRijg+FaLChFAvjaNEysIJx8ybM36E6MLHKIiTyLmeI3KAurxU02XPDVv8dQbNqyb87nD3IWdE+wNplZDyGjcM1JSGI88JGIjY9b0gIW8BWvB/lyjDuYzhhOV7BtkvXWO5MSXCPRqQ619aoUEVh8oPX8gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114074; c=relaxed/simple; bh=Q1ksihjpVfuP+VRWxZRsYugofz9jYU44EY/sBMoBMEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NhLZGUUeyonZXs0K2Dx88WIc2tJd9qT3XgU4LQICxFtkEYijjbN+0vPwDCNR9CZwLfcKR8FAhtBmOnld1Rj0nU5413BbIu2exnosjw1l1/Fy9n88nv4aQFjxi8kRgI5eDxJNr+jf1QNiLp2WLcIm2Poyux7/kEfY3bT5l2zseRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d4mdBa9F; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d4mdBa9F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725114072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a+YaXcuOLFlVp84HCFFSCXL1mJivlfEZlF6lzWx9g7c=; b=d4mdBa9FTPK31LbGYLEhmkKYySw8edlAkRYTcmhCqBvM7FL5vo+WsBbZRgehfEBcFDejA8 LeImx47ytQ5pWSvfib7aQ6iwosfgOqLW6mHmHKcTkT+3hav3kWRmRWkYtWNLTMGCeuhc9g OkuJHQ3qy2IwVK8If2qJj5lkfz76CVc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-zT7G6qIhP6O32hWBOUjMtA-1; Sat, 31 Aug 2024 10:21:07 -0400 X-MC-Unique: zT7G6qIhP6O32hWBOUjMtA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 49E4A19560B7; Sat, 31 Aug 2024 14:21:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 323B13001FE8; Sat, 31 Aug 2024 14:21:00 +0000 (UTC) From: Hans de Goede To: Sebastian Reichel , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , MyungJoo Ham , Chanwoo Choi , Greg Kroah-Hartman , Heikki Krogerus , Vinod Koul , Kishon Vijay Abraham I Cc: Hans de Goede , Enric Balletbo Serra , Andrey Smirnov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH 3/6] power: supply: rt9467-charger: Remove "usb_type" property write support Date: Sat, 31 Aug 2024 16:20:36 +0200 Message-ID: <20240831142039.28830-4-hdegoede@redhat.com> In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com> References: <20240831142039.28830-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" The "usb_type" property must be read-only for charger power-supply devices, see: Documentation/ABI/testing/sysfs-class-power. But the rt9467 driver allows writing 0/1 to it to disable/enable charging. Other charger drivers use the "status" property for this and the rt9467 code also allows writing 0/1 to its "status" property and this does the exact same thing as writing 0/1 to its "usb_type" property. Drop write support for the "usb_type" property making it readonly to match the ABI documentation. If userspace wants to disable/enable charging it can use the "status" property for this. Signed-off-by: Hans de Goede --- drivers/power/supply/rt9467-charger.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/power/supply/rt9467-charger.c b/drivers/power/supply/r= t9467-charger.c index fdfdc83ab045..f935bd761ac1 100644 --- a/drivers/power/supply/rt9467-charger.c +++ b/drivers/power/supply/rt9467-charger.c @@ -745,8 +745,6 @@ static int rt9467_psy_set_property(struct power_supply = *psy, RT9467_RANGE_IPREC, val->intval); case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: return rt9467_psy_set_ieoc(data, val->intval); - case POWER_SUPPLY_PROP_USB_TYPE: - return regmap_field_write(data->rm_field[F_USBCHGEN], val->intval); default: return -EINVAL; } @@ -764,7 +762,6 @@ static int rt9467_chg_prop_is_writeable(struct power_su= pply *psy, case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT: case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: - case POWER_SUPPLY_PROP_USB_TYPE: return 1; default: return 0; --=20 2.46.0 From nobody Sun Feb 8 16:05:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 B3AE44D9FB for ; Sat, 31 Aug 2024 14:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114079; cv=none; b=CAsuuYA83D/DVSMnvRuibJe4wsmYvvTRiq6RxRGfkDLqz2lJJqE0Vo6aQpYGzF7Ki0vF0JUnaFZsGLzn37GbqIiGH70PM0fl/yCjNpdLM0lj2fkze0alDsf+o20Nk16lOLf9XNdxQLcgcFOAxNFZe8+WRwG7hr05GSSovl7cuMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114079; c=relaxed/simple; bh=ZqS5hmbkX87g2QZf8WNV6gJzNhOiPZ8vLhBTDyNoaZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SXExeQf+5WNwyfVmAVnRjFHk59uLh5obi6Sy5JB/tuxFlyg32WyNQHibON6dAbRLAqMaXU/cSRjMhPm+6p32q9VCdZprVy4hInclq9zjg8RAJpadK513NE5Nq5sPzM35tjuVuyyiw3/cAZdrG+rujOFRAEWNk1Er8dc1IYfuGC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EUboylTP; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EUboylTP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725114076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FF++cKBP8Z5pJxXGjkdRcYsFMQ1dJi1+OYKZbD3H9KE=; b=EUboylTPAo1YyDXwZtH/Jq+v65DTMBc8QEQfbVKkntkt9jIxMzf5JMEOD1vI/SuGLo6tgp 5rD7IvCZf/3Gio43ne9izHj7TixyXhedmbIio1kxkbTepGIZ0xWGdtiXrl6ARDM36gUHaZ JsmdBdv3ABjxFz7D8J/htjdwHD9KBYw= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-w9ZPOsfIMLit7EGphexvFg-1; Sat, 31 Aug 2024 10:21:12 -0400 X-MC-Unique: w9ZPOsfIMLit7EGphexvFg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B79BD1955D50; Sat, 31 Aug 2024 14:21:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8A30230001A4; Sat, 31 Aug 2024 14:21:05 +0000 (UTC) From: Hans de Goede To: Sebastian Reichel , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , MyungJoo Ham , Chanwoo Choi , Greg Kroah-Hartman , Heikki Krogerus , Vinod Koul , Kishon Vijay Abraham I Cc: Hans de Goede , Enric Balletbo Serra , Andrey Smirnov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH 4/6] power: supply: sysfs: Add power_supply_show_enum_with_available() helper Date: Sat, 31 Aug 2024 16:20:37 +0200 Message-ID: <20240831142039.28830-5-hdegoede@redhat.com> In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com> References: <20240831142039.28830-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Turn power_supply_charge_behaviour_show() into a generic function for showing enum values with their available (for writing) values shown and the current value shown surrounded by sqaure-brackets like the show() output for "usb_type" and "charge_behaviour". This is a preparation patch for refactoring the "usb_type" property handling to use a bitmask indicating available usb-types + this new generic function. Signed-off-by: Hans de Goede --- drivers/power/supply/power_supply_sysfs.c | 32 ++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supp= ly/power_supply_sysfs.c index ff7e423edd57..9f21b0b54caf 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -518,31 +518,28 @@ int power_supply_uevent(const struct device *dev, str= uct kobj_uevent_env *env) return ret; } =20 -ssize_t power_supply_charge_behaviour_show(struct device *dev, - unsigned int available_behaviours, - enum power_supply_charge_behaviour current_behaviour, - char *buf) +static ssize_t power_supply_show_enum_with_available( + struct device *dev, const char * const labels[], int label_count, + unsigned int available_values, int value, char *buf) { bool match =3D false, available, active; ssize_t count =3D 0; int i; =20 - for (i =3D 0; i < ARRAY_SIZE(POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT); i++) { - available =3D available_behaviours & BIT(i); - active =3D i =3D=3D current_behaviour; + for (i =3D 0; i < label_count; i++) { + available =3D available_values & BIT(i); + active =3D i =3D=3D value; =20 if (available && active) { - count +=3D sysfs_emit_at(buf, count, "[%s] ", - POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT[i]); + count +=3D sysfs_emit_at(buf, count, "[%s] ", labels[i]); match =3D true; } else if (available) { - count +=3D sysfs_emit_at(buf, count, "%s ", - POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT[i]); + count +=3D sysfs_emit_at(buf, count, "%s ", labels[i]); } } =20 if (!match) { - dev_warn(dev, "driver reporting unsupported charge behaviour\n"); + dev_warn(dev, "driver reporting unavailable enum value %d\n", value); return -EINVAL; } =20 @@ -551,6 +548,17 @@ ssize_t power_supply_charge_behaviour_show(struct devi= ce *dev, =20 return count; } + +ssize_t power_supply_charge_behaviour_show(struct device *dev, + unsigned int available_behaviours, + enum power_supply_charge_behaviour current_behaviour, + char *buf) +{ + return power_supply_show_enum_with_available( + dev, POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT, + ARRAY_SIZE(POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT), + available_behaviours, current_behaviour, buf); +} EXPORT_SYMBOL_GPL(power_supply_charge_behaviour_show); =20 int power_supply_charge_behaviour_parse(unsigned int available_behaviours,= const char *buf) --=20 2.46.0 From nobody Sun Feb 8 16:05:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 8548D1CFBE for ; Sat, 31 Aug 2024 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114086; cv=none; b=f8EMDGY6hOagDEaVqika887o0UcbDykgyYR02ax8DhFBjs65ldrE+GuzYt0PJyFVJZnwaCZwq6O3xUBcDx/DiRrDmAcgA+LaXqPdzm1H+bTtBn8vRYVj7uOJYA4qYnElPijwyDEq/08SQaDVjzuDVS6v0Q47GXqlJQY6dG3IaDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114086; c=relaxed/simple; bh=kvlpVhOfdVYqzYjygZ62VId+u5GFqaC2KnLUoFZwwg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=teevY8gUx/wspbC0/NVyG2xAWW7AKVR6DjflZGhuljpo1mmIe9IVnQW9y+ykhLYby39Okj1ePk26nb0ovDVdwUXieip3qx+L0/+N5i9ULjc839gjPN8CoUvJ/0tGv4PNa8QuOI0BN9foHuGH0VEB00kRGGLGq+bZJkS2dqMHAu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=K0H8YVVc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="K0H8YVVc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725114083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0QIaDwiuzjwwdhdGYGN9s12CC0QR4D1zMEIQpGYdueU=; b=K0H8YVVcwK3tI7+vATfBUaqnsxs5wYInPYuQ15tsH92GtEC8rOEP+MyRBOWCM+0pyTlCZN LwXLvt+xMcM1lEZemYoV0FZXcCF5DZ52tknh6Q7tPr/CTCzTzgm8XP1g4aXC7RIt5lXpNG 022EIsiCv4PebJ0vGgdjUk7aN21mA9E= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-fgYXGaqhNH24_hgJ54PJEg-1; Sat, 31 Aug 2024 10:21:16 -0400 X-MC-Unique: fgYXGaqhNH24_hgJ54PJEg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6A611955F40; Sat, 31 Aug 2024 14:21:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF4913001FEF; Sat, 31 Aug 2024 14:21:09 +0000 (UTC) From: Hans de Goede To: Sebastian Reichel , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , MyungJoo Ham , Chanwoo Choi , Greg Kroah-Hartman , Heikki Krogerus , Vinod Koul , Kishon Vijay Abraham I Cc: Hans de Goede , Enric Balletbo Serra , Andrey Smirnov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH 5/6] power: supply: sysfs: Move power_supply_show_enum_with_available() up Date: Sat, 31 Aug 2024 16:20:38 +0200 Message-ID: <20240831142039.28830-6-hdegoede@redhat.com> In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com> References: <20240831142039.28830-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Move power_supply_show_enum_with_available() higher up in the power_supply_sysfs.c file. This is a preparation patch to avoid needing a forward declaration when replacing power_supply_show_usb_type() with it later on. This commit only moves the function, there are no changes to it. Signed-off-by: Hans de Goede --- drivers/power/supply/power_supply_sysfs.c | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supp= ly/power_supply_sysfs.c index 9f21b0b54caf..c98a6de59d3b 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -237,6 +237,37 @@ static enum power_supply_property dev_attr_psp(struct = device_attribute *attr) return to_ps_attr(attr) - power_supply_attrs; } =20 +static ssize_t power_supply_show_enum_with_available( + struct device *dev, const char * const labels[], int label_count, + unsigned int available_values, int value, char *buf) +{ + bool match =3D false, available, active; + ssize_t count =3D 0; + int i; + + for (i =3D 0; i < label_count; i++) { + available =3D available_values & BIT(i); + active =3D i =3D=3D value; + + if (available && active) { + count +=3D sysfs_emit_at(buf, count, "[%s] ", labels[i]); + match =3D true; + } else if (available) { + count +=3D sysfs_emit_at(buf, count, "%s ", labels[i]); + } + } + + if (!match) { + dev_warn(dev, "driver reporting unavailable enum value %d\n", value); + return -EINVAL; + } + + if (count) + buf[count - 1] =3D '\n'; + + return count; +} + static ssize_t power_supply_show_usb_type(struct device *dev, const struct power_supply_desc *desc, union power_supply_propval *value, @@ -518,37 +549,6 @@ int power_supply_uevent(const struct device *dev, stru= ct kobj_uevent_env *env) return ret; } =20 -static ssize_t power_supply_show_enum_with_available( - struct device *dev, const char * const labels[], int label_count, - unsigned int available_values, int value, char *buf) -{ - bool match =3D false, available, active; - ssize_t count =3D 0; - int i; - - for (i =3D 0; i < label_count; i++) { - available =3D available_values & BIT(i); - active =3D i =3D=3D value; - - if (available && active) { - count +=3D sysfs_emit_at(buf, count, "[%s] ", labels[i]); - match =3D true; - } else if (available) { - count +=3D sysfs_emit_at(buf, count, "%s ", labels[i]); - } - } - - if (!match) { - dev_warn(dev, "driver reporting unavailable enum value %d\n", value); - return -EINVAL; - } - - if (count) - buf[count - 1] =3D '\n'; - - return count; -} - ssize_t power_supply_charge_behaviour_show(struct device *dev, unsigned int available_behaviours, enum power_supply_charge_behaviour current_behaviour, --=20 2.46.0 From nobody Sun Feb 8 16:05:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 1948314B949 for ; Sat, 31 Aug 2024 14:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114086; cv=none; b=g/2feVShOBZJHHYeEJAX31j4J/IcVhhyCJ6bF0dBJNfgrz6HcAf70KhiwwF+YRsyQUwkuzhfDM5jshNriPuCVyWwmkW350Tg0nPP0tLlROZfMIC1+I4xT/wyy0KJbK0SjdFgomulfebJB/5kTrhVFavD2zLlDXh7AEy+fqJLTLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725114086; c=relaxed/simple; bh=MoQfVPPSri47OxiryUK8FhlNWVXFwbIPcathpNHwoPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kGCqA/ohHGfijuWI8i3slf/0XvI7vzK5zPB6GerYgfGOCWblyzF0+Qz/2c4XsRezqikzrrJj727cupTAx30z8+7IdhNOwp5ZkT1ApzXnjyVBitaGUHeuPgadYdpqGMVGMdNK/tafL6uPXOP6zWSAMLyItmDxwiiABj05jA8r1ls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cOhoXisV; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cOhoXisV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725114083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KnZoYL2d+p7AwIZZPmMmbvjdXDJ16rJ3VReMdEA9e+k=; b=cOhoXisVLdQUSyPBgBewuYePAVoj2Z+G7ZqB1wYsWcE3e3NnFMjXBDcJz58Oy+bBPWavdB XrDtSH8TnlmKDFVM56rDnEJWLIZPjdADp3DIfQly6cMB4da+5BmRz8bsVdyxFWMoehIG7t R6UJOoZlcETrXMEoCO4/82EPiU2mCUk= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-421-zc_pK1DFMn6UEVJ23jPwBw-1; Sat, 31 Aug 2024 10:21:20 -0400 X-MC-Unique: zc_pK1DFMn6UEVJ23jPwBw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B14521956048; Sat, 31 Aug 2024 14:21:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4701030001A4; Sat, 31 Aug 2024 14:21:14 +0000 (UTC) From: Hans de Goede To: Sebastian Reichel , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , MyungJoo Ham , Chanwoo Choi , Greg Kroah-Hartman , Heikki Krogerus , Vinod Koul , Kishon Vijay Abraham I Cc: Hans de Goede , Enric Balletbo Serra , Andrey Smirnov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH 6/6] power: supply: Change usb_types from an array into a bitmask Date: Sat, 31 Aug 2024 16:20:39 +0200 Message-ID: <20240831142039.28830-7-hdegoede@redhat.com> In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com> References: <20240831142039.28830-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" The bit_types array just hold a list of valid enum power_supply_usb_type values which map to 0 - 9. This can easily be represented as a bitmap. This reduces the size of struct power_supply_desc and further reduces the data section size by drivers no longer needing to store the array. This also unifies how usb_types are handled with charge_behaviours, which allows power_supply_show_usb_type() to be removed. Signed-off-by: Hans de Goede Reviewed-by: Greg Kroah-Hartman --- drivers/extcon/extcon-intel-cht-wc.c | 15 +++---- drivers/phy/ti/phy-tusb1210.c | 11 ++--- drivers/power/supply/axp20x_usb_power.c | 13 ++---- drivers/power/supply/bq256xx_charger.c | 15 +++---- drivers/power/supply/cros_usbpd-charger.c | 22 ++++------ .../power/supply/lenovo_yoga_c630_battery.c | 7 +--- drivers/power/supply/mp2629_charger.c | 15 +++---- drivers/power/supply/mt6360_charger.c | 13 ++---- drivers/power/supply/mt6370-charger.c | 13 ++---- drivers/power/supply/power_supply_core.c | 4 -- drivers/power/supply/power_supply_sysfs.c | 40 ++----------------- drivers/power/supply/qcom_battmgr.c | 37 +++++++++-------- drivers/power/supply/qcom_pmi8998_charger.c | 13 ++---- drivers/power/supply/rk817_charger.c | 9 +---- drivers/power/supply/rn5t618_power.c | 13 ++---- drivers/power/supply/rt9467-charger.c | 13 ++---- drivers/power/supply/rt9471.c | 15 +++---- drivers/power/supply/ucs1002_power.c | 15 +++---- drivers/usb/typec/anx7411.c | 11 ++--- drivers/usb/typec/rt1719.c | 11 ++--- drivers/usb/typec/tcpm/tcpm.c | 11 ++--- drivers/usb/typec/tipd/core.c | 9 +---- drivers/usb/typec/ucsi/psy.c | 11 ++--- include/linux/power_supply.h | 3 +- 24 files changed, 102 insertions(+), 237 deletions(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-i= ntel-cht-wc.c index 733c470c3102..93552dc3c895 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -461,14 +461,6 @@ static int cht_wc_extcon_psy_get_prop(struct power_sup= ply *psy, return 0; } =20 -static const enum power_supply_usb_type cht_wc_extcon_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_ACA, - POWER_SUPPLY_USB_TYPE_UNKNOWN, -}; - static const enum power_supply_property cht_wc_extcon_psy_props[] =3D { POWER_SUPPLY_PROP_USB_TYPE, POWER_SUPPLY_PROP_ONLINE, @@ -477,8 +469,11 @@ static const enum power_supply_property cht_wc_extcon_= psy_props[] =3D { static const struct power_supply_desc cht_wc_extcon_psy_desc =3D { .name =3D "cht_wcove_pwrsrc", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D cht_wc_extcon_psy_usb_types, - .num_usb_types =3D ARRAY_SIZE(cht_wc_extcon_psy_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_ACA) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D cht_wc_extcon_psy_props, .num_properties =3D ARRAY_SIZE(cht_wc_extcon_psy_props), .get_property =3D cht_wc_extcon_psy_get_prop, diff --git a/drivers/phy/ti/phy-tusb1210.c b/drivers/phy/ti/phy-tusb1210.c index 751fecd466e3..c3ae9d7948d7 100644 --- a/drivers/phy/ti/phy-tusb1210.c +++ b/drivers/phy/ti/phy-tusb1210.c @@ -411,12 +411,6 @@ static int tusb1210_psy_get_prop(struct power_supply *= psy, return 0; } =20 -static const enum power_supply_usb_type tusb1210_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_UNKNOWN, -}; - static const enum power_supply_property tusb1210_psy_props[] =3D { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_USB_TYPE, @@ -426,8 +420,9 @@ static const enum power_supply_property tusb1210_psy_pr= ops[] =3D { static const struct power_supply_desc tusb1210_psy_desc =3D { .name =3D "tusb1211-charger-detect", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D tusb1210_psy_usb_types, - .num_usb_types =3D ARRAY_SIZE(tusb1210_psy_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D tusb1210_psy_props, .num_properties =3D ARRAY_SIZE(tusb1210_psy_props), .get_property =3D tusb1210_psy_get_prop, diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply= /axp20x_usb_power.c index 69fbb5861934..7b1bf6766ff7 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -456,13 +456,6 @@ static enum power_supply_property axp813_usb_power_pro= perties[] =3D { POWER_SUPPLY_PROP_USB_TYPE, }; =20 -static enum power_supply_usb_type axp813_usb_types[] =3D { - 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 =3D { .name =3D "axp20x-usb", .type =3D POWER_SUPPLY_TYPE_USB, @@ -491,8 +484,10 @@ static const struct power_supply_desc axp813_usb_power= _desc =3D { .property_is_writeable =3D axp20x_usb_power_prop_writeable, .get_property =3D axp20x_usb_power_get_property, .set_property =3D axp20x_usb_power_set_property, - .usb_types =3D axp813_usb_types, - .num_usb_types =3D ARRAY_SIZE(axp813_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), }; =20 static const char * const axp20x_irq_names[] =3D { diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/= bq256xx_charger.c index 1a935bc88510..5514d1896bb8 100644 --- a/drivers/power/supply/bq256xx_charger.c +++ b/drivers/power/supply/bq256xx_charger.c @@ -334,14 +334,6 @@ static const int bq25618_619_ichg_values[] =3D { 1290000, 1360000, 1430000, 1500000 }; =20 -static enum power_supply_usb_type bq256xx_usb_type[] =3D { - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_ACA, -}; - static int bq256xx_array_parse(int array_size, int val, const int array[]) { int i =3D 0; @@ -1252,8 +1244,11 @@ static int bq256xx_property_is_writeable(struct powe= r_supply *psy, static const struct power_supply_desc bq256xx_power_supply_desc =3D { .name =3D "bq256xx-charger", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D bq256xx_usb_type, - .num_usb_types =3D ARRAY_SIZE(bq256xx_usb_type), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_ACA) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D bq256xx_power_supply_props, .num_properties =3D ARRAY_SIZE(bq256xx_power_supply_props), .get_property =3D bq256xx_get_charger_property, diff --git a/drivers/power/supply/cros_usbpd-charger.c b/drivers/power/supp= ly/cros_usbpd-charger.c index 8008e31c0c09..bed3e2e9bfea 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -73,17 +73,6 @@ static enum power_supply_property cros_usbpd_dedicated_c= harger_props[] =3D { POWER_SUPPLY_PROP_VOLTAGE_NOW, }; =20 -static enum power_supply_usb_type cros_usbpd_charger_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_PD_DRP, - POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID -}; - /* Input voltage/current limit in mV/mA. Default to none. */ static u16 input_voltage_limit =3D EC_POWER_LIMIT_NONE; static u16 input_current_limit =3D EC_POWER_LIMIT_NONE; @@ -643,9 +632,14 @@ static int cros_usbpd_charger_probe(struct platform_de= vice *pd) psy_desc->properties =3D cros_usbpd_charger_props; psy_desc->num_properties =3D ARRAY_SIZE(cros_usbpd_charger_props); - psy_desc->usb_types =3D cros_usbpd_charger_usb_types; - psy_desc->num_usb_types =3D - ARRAY_SIZE(cros_usbpd_charger_usb_types); + psy_desc->usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) | + BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID); } =20 psy_desc->name =3D port->name; diff --git a/drivers/power/supply/lenovo_yoga_c630_battery.c b/drivers/powe= r/supply/lenovo_yoga_c630_battery.c index d4d422cc5353..f98f65e00831 100644 --- a/drivers/power/supply/lenovo_yoga_c630_battery.c +++ b/drivers/power/supply/lenovo_yoga_c630_battery.c @@ -353,15 +353,10 @@ static enum power_supply_property yoga_c630_psy_adpt_= properties[] =3D { POWER_SUPPLY_PROP_USB_TYPE, }; =20 -static const enum power_supply_usb_type yoga_c630_psy_adpt_usb_type[] =3D { - POWER_SUPPLY_USB_TYPE_C, -}; - static const struct power_supply_desc yoga_c630_psy_adpt_psy_desc =3D { .name =3D "yoga-c630-adapter", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D yoga_c630_psy_adpt_usb_type, - .num_usb_types =3D ARRAY_SIZE(yoga_c630_psy_adpt_usb_type), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_C), .properties =3D yoga_c630_psy_adpt_properties, .num_properties =3D ARRAY_SIZE(yoga_c630_psy_adpt_properties), .get_property =3D yoga_c630_psy_adpt_get_property, diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/m= p2629_charger.c index 3a2a28fbba73..d281c1059629 100644 --- a/drivers/power/supply/mp2629_charger.c +++ b/drivers/power/supply/mp2629_charger.c @@ -94,14 +94,6 @@ struct mp2629_prop { int shift; }; =20 -static enum power_supply_usb_type mp2629_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_PD_DRP, - POWER_SUPPLY_USB_TYPE_UNKNOWN -}; - static enum power_supply_property mp2629_charger_usb_props[] =3D { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_USB_TYPE, @@ -487,8 +479,11 @@ static irqreturn_t mp2629_irq_handler(int irq, void *d= ev_id) static const struct power_supply_desc mp2629_usb_desc =3D { .name =3D "mp2629_usb", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D mp2629_usb_types, - .num_usb_types =3D ARRAY_SIZE(mp2629_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D mp2629_charger_usb_props, .num_properties =3D ARRAY_SIZE(mp2629_charger_usb_props), .get_property =3D mp2629_charger_usb_get_prop, diff --git a/drivers/power/supply/mt6360_charger.c b/drivers/power/supply/m= t6360_charger.c index aca123783efc..e99e55148976 100644 --- a/drivers/power/supply/mt6360_charger.c +++ b/drivers/power/supply/mt6360_charger.c @@ -154,13 +154,6 @@ enum mt6360_pmu_chg_type { MT6360_CHG_TYPE_MAX, }; =20 -static enum power_supply_usb_type mt6360_charger_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, -}; - static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci, bool *pwr_rdy) { @@ -574,8 +567,10 @@ static const struct power_supply_desc mt6360_charger_d= esc =3D { .get_property =3D mt6360_charger_get_property, .set_property =3D mt6360_charger_set_property, .property_is_writeable =3D mt6360_charger_property_is_writeable, - .usb_types =3D mt6360_charger_usb_types, - .num_usb_types =3D ARRAY_SIZE(mt6360_charger_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), }; =20 static const struct regulator_ops mt6360_chg_otg_ops =3D { diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/m= t6370-charger.c index e24fce087d80..ad8793bf997e 100644 --- a/drivers/power/supply/mt6370-charger.c +++ b/drivers/power/supply/mt6370-charger.c @@ -624,13 +624,6 @@ static enum power_supply_property mt6370_chg_propertie= s[] =3D { POWER_SUPPLY_PROP_USB_TYPE, }; =20 -static enum power_supply_usb_type mt6370_chg_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_DCP, -}; - static const struct power_supply_desc mt6370_chg_psy_desc =3D { .name =3D "mt6370-charger", .type =3D POWER_SUPPLY_TYPE_USB, @@ -639,8 +632,10 @@ static const struct power_supply_desc mt6370_chg_psy_d= esc =3D { .get_property =3D mt6370_chg_get_property, .set_property =3D mt6370_chg_set_property, .property_is_writeable =3D mt6370_chg_property_is_writeable, - .usb_types =3D mt6370_chg_usb_types, - .num_usb_types =3D ARRAY_SIZE(mt6370_chg_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), }; =20 static const struct regulator_ops mt6370_chg_otg_ops =3D { diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/suppl= y/power_supply_core.c index 3614d263ddad..0417fb34e846 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -1360,10 +1360,6 @@ __power_supply_register(struct device *parent, pr_warn("%s: Expected proper parent device for '%s'\n", __func__, desc->name); =20 - if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) && - (!desc->usb_types || !desc->num_usb_types)) - return ERR_PTR(-EINVAL); - psy =3D kzalloc(sizeof(*psy), GFP_KERNEL); if (!psy) return ERR_PTR(-ENOMEM); diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supp= ly/power_supply_sysfs.c index c98a6de59d3b..16b3c5880cd8 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -268,40 +268,6 @@ static ssize_t power_supply_show_enum_with_available( return count; } =20 -static ssize_t power_supply_show_usb_type(struct device *dev, - const struct power_supply_desc *desc, - union power_supply_propval *value, - char *buf) -{ - enum power_supply_usb_type usb_type; - ssize_t count =3D 0; - bool match =3D false; - int i; - - for (i =3D 0; i < desc->num_usb_types; ++i) { - usb_type =3D desc->usb_types[i]; - - if (value->intval =3D=3D usb_type) { - count +=3D sysfs_emit_at(buf, count, "[%s] ", - POWER_SUPPLY_USB_TYPE_TEXT[usb_type]); - match =3D true; - } else { - count +=3D sysfs_emit_at(buf, count, "%s ", - POWER_SUPPLY_USB_TYPE_TEXT[usb_type]); - } - } - - if (!match) { - dev_warn(dev, "driver reporting unsupported connected type\n"); - return -EINVAL; - } - - if (count) - buf[count - 1] =3D '\n'; - - return count; -} - static ssize_t power_supply_show_property(struct device *dev, struct device_attribute *attr, char *buf) { @@ -331,8 +297,10 @@ static ssize_t power_supply_show_property(struct devic= e *dev, =20 switch (psp) { case POWER_SUPPLY_PROP_USB_TYPE: - ret =3D power_supply_show_usb_type(dev, psy->desc, - &value, buf); + ret =3D power_supply_show_enum_with_available( + dev, POWER_SUPPLY_USB_TYPE_TEXT, + ARRAY_SIZE(POWER_SUPPLY_USB_TYPE_TEXT), + psy->desc->usb_types, value.intval, buf); break; case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR: ret =3D power_supply_charge_behaviour_show(dev, psy->desc->charge_behavi= ours, diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qco= m_battmgr.c index 46f36dcb185c..56c8021383da 100644 --- a/drivers/power/supply/qcom_battmgr.c +++ b/drivers/power/supply/qcom_battmgr.c @@ -786,19 +786,6 @@ static int qcom_battmgr_usb_get_property(struct power_= supply *psy, return 0; } =20 -static const enum power_supply_usb_type usb_psy_supported_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_ACA, - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_PD_DRP, - POWER_SUPPLY_USB_TYPE_PD_PPS, - POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, -}; - static const enum power_supply_property sc8280xp_usb_props[] =3D { POWER_SUPPLY_PROP_ONLINE, }; @@ -809,8 +796,16 @@ static const struct power_supply_desc sc8280xp_usb_psy= _desc =3D { .properties =3D sc8280xp_usb_props, .num_properties =3D ARRAY_SIZE(sc8280xp_usb_props), .get_property =3D qcom_battmgr_usb_get_property, - .usb_types =3D usb_psy_supported_types, - .num_usb_types =3D ARRAY_SIZE(usb_psy_supported_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) | + BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_ACA) | + BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS) | + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID), }; =20 static const enum power_supply_property sm8350_usb_props[] =3D { @@ -829,8 +824,16 @@ static const struct power_supply_desc sm8350_usb_psy_d= esc =3D { .properties =3D sm8350_usb_props, .num_properties =3D ARRAY_SIZE(sm8350_usb_props), .get_property =3D qcom_battmgr_usb_get_property, - .usb_types =3D usb_psy_supported_types, - .num_usb_types =3D ARRAY_SIZE(usb_psy_supported_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) | + BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_ACA) | + BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS) | + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID), }; =20 static const u8 sm8350_wls_prop_map[] =3D { diff --git a/drivers/power/supply/qcom_pmi8998_charger.c b/drivers/power/su= pply/qcom_pmi8998_charger.c index 9bb777406013..81acbd8b2169 100644 --- a/drivers/power/supply/qcom_pmi8998_charger.c +++ b/drivers/power/supply/qcom_pmi8998_charger.c @@ -411,13 +411,6 @@ static enum power_supply_property smb2_properties[] = =3D { POWER_SUPPLY_PROP_USB_TYPE, }; =20 -static enum power_supply_usb_type smb2_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, -}; - static int smb2_get_prop_usb_online(struct smb2_chip *chip, int *val) { unsigned int stat; @@ -775,8 +768,10 @@ static irqreturn_t smb2_handle_wdog_bark(int irq, void= *data) static const struct power_supply_desc smb2_psy_desc =3D { .name =3D "pmi8998_charger", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D smb2_usb_types, - .num_usb_types =3D ARRAY_SIZE(smb2_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D smb2_properties, .num_properties =3D ARRAY_SIZE(smb2_properties), .get_property =3D smb2_get_property, diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk= 817_charger.c index 7ca91739c6cc..a3d377a32b49 100644 --- a/drivers/power/supply/rk817_charger.c +++ b/drivers/power/supply/rk817_charger.c @@ -673,11 +673,6 @@ static enum power_supply_property rk817_chg_props[] = =3D { POWER_SUPPLY_PROP_VOLTAGE_AVG, }; =20 -static enum power_supply_usb_type rk817_usb_type[] =3D { - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_UNKNOWN, -}; - static const struct power_supply_desc rk817_bat_desc =3D { .name =3D "rk817-battery", .type =3D POWER_SUPPLY_TYPE_BATTERY, @@ -689,8 +684,8 @@ static const struct power_supply_desc rk817_bat_desc = =3D { static const struct power_supply_desc rk817_chg_desc =3D { .name =3D "rk817-charger", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D rk817_usb_type, - .num_usb_types =3D ARRAY_SIZE(rk817_usb_type), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D rk817_chg_props, .num_properties =3D ARRAY_SIZE(rk817_chg_props), .get_property =3D rk817_chg_get_prop, diff --git a/drivers/power/supply/rn5t618_power.c b/drivers/power/supply/rn= 5t618_power.c index ebea3522a2ac..40dec55a9f73 100644 --- a/drivers/power/supply/rn5t618_power.c +++ b/drivers/power/supply/rn5t618_power.c @@ -70,13 +70,6 @@ struct rn5t618_power_info { int irq; }; =20 -static enum power_supply_usb_type rn5t618_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_UNKNOWN -}; - static enum power_supply_property rn5t618_usb_props[] =3D { /* input current limit is not very accurate */ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, @@ -681,8 +674,10 @@ static const struct power_supply_desc rn5t618_adp_desc= =3D { static const struct power_supply_desc rn5t618_usb_desc =3D { .name =3D "rn5t618-usb", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D rn5t618_usb_types, - .num_usb_types =3D ARRAY_SIZE(rn5t618_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D rn5t618_usb_props, .num_properties =3D ARRAY_SIZE(rn5t618_usb_props), .get_property =3D rn5t618_usb_get_property, diff --git a/drivers/power/supply/rt9467-charger.c b/drivers/power/supply/r= t9467-charger.c index f935bd761ac1..235169c85c5d 100644 --- a/drivers/power/supply/rt9467-charger.c +++ b/drivers/power/supply/rt9467-charger.c @@ -630,13 +630,6 @@ static int rt9467_psy_set_ieoc(struct rt9467_chg_data = *data, int microamp) return ret; } =20 -static const enum power_supply_usb_type rt9467_chg_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, -}; - static const enum power_supply_property rt9467_chg_properties[] =3D { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, @@ -771,8 +764,10 @@ static int rt9467_chg_prop_is_writeable(struct power_s= upply *psy, static const struct power_supply_desc rt9467_chg_psy_desc =3D { .name =3D "rt9467-charger", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D rt9467_chg_usb_types, - .num_usb_types =3D ARRAY_SIZE(rt9467_chg_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .properties =3D rt9467_chg_properties, .num_properties =3D ARRAY_SIZE(rt9467_chg_properties), .property_is_writeable =3D rt9467_chg_prop_is_writeable, diff --git a/drivers/power/supply/rt9471.c b/drivers/power/supply/rt9471.c index 868b0703d15c..c04af1ee89c6 100644 --- a/drivers/power/supply/rt9471.c +++ b/drivers/power/supply/rt9471.c @@ -333,14 +333,6 @@ static enum power_supply_property rt9471_charger_prope= rties[] =3D { POWER_SUPPLY_PROP_MANUFACTURER, }; =20 -static enum power_supply_usb_type rt9471_charger_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_UNKNOWN, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, -}; - static int rt9471_charger_property_is_writeable(struct power_supply *psy, enum power_supply_property psp) { @@ -726,8 +718,11 @@ static int rt9471_register_psy(struct rt9471_chip *chi= p) =20 desc->name =3D psy_name; desc->type =3D POWER_SUPPLY_TYPE_USB; - desc->usb_types =3D rt9471_charger_usb_types; - desc->num_usb_types =3D ARRAY_SIZE(rt9471_charger_usb_types); + desc->usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN); desc->properties =3D rt9471_charger_properties; desc->num_properties =3D ARRAY_SIZE(rt9471_charger_properties); desc->get_property =3D rt9471_charger_get_property; diff --git a/drivers/power/supply/ucs1002_power.c b/drivers/power/supply/uc= s1002_power.c index b67d5b03d93e..7382bec6a43c 100644 --- a/drivers/power/supply/ucs1002_power.c +++ b/drivers/power/supply/ucs1002_power.c @@ -296,14 +296,6 @@ static int ucs1002_set_max_current(struct ucs1002_info= *info, u32 val) return 0; } =20 -static enum power_supply_usb_type ucs1002_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_SDP, - POWER_SUPPLY_USB_TYPE_DCP, - POWER_SUPPLY_USB_TYPE_CDP, - POWER_SUPPLY_USB_TYPE_UNKNOWN, -}; - static int ucs1002_set_usb_type(struct ucs1002_info *info, int val) { unsigned int mode; @@ -431,8 +423,11 @@ static int ucs1002_property_is_writeable(struct power_= supply *psy, static const struct power_supply_desc ucs1002_charger_desc =3D { .name =3D "ucs1002", .type =3D POWER_SUPPLY_TYPE_USB, - .usb_types =3D ucs1002_usb_types, - .num_usb_types =3D ARRAY_SIZE(ucs1002_usb_types), + .usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_SDP) | + BIT(POWER_SUPPLY_USB_TYPE_CDP) | + BIT(POWER_SUPPLY_USB_TYPE_DCP) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), .get_property =3D ucs1002_get_property, .set_property =3D ucs1002_set_property, .property_is_writeable =3D ucs1002_property_is_writeable, diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c index 5a5bf3532ad7..31e3e9544bc0 100644 --- a/drivers/usb/typec/anx7411.c +++ b/drivers/usb/typec/anx7411.c @@ -1339,12 +1339,6 @@ static void anx7411_get_gpio_irq(struct anx7411_data= *ctx) dev_err(dev, "failed to get GPIO IRQ\n"); } =20 -static enum power_supply_usb_type anx7411_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_PD_PPS, -}; - static enum power_supply_property anx7411_psy_props[] =3D { POWER_SUPPLY_PROP_USB_TYPE, POWER_SUPPLY_PROP_ONLINE, @@ -1422,8 +1416,9 @@ static int anx7411_psy_register(struct anx7411_data *= ctx) =20 psy_desc->name =3D psy_name; psy_desc->type =3D POWER_SUPPLY_TYPE_USB; - psy_desc->usb_types =3D anx7411_psy_usb_types; - psy_desc->num_usb_types =3D ARRAY_SIZE(anx7411_psy_usb_types); + psy_desc->usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); psy_desc->properties =3D anx7411_psy_props; psy_desc->num_properties =3D ARRAY_SIZE(anx7411_psy_props); =20 diff --git a/drivers/usb/typec/rt1719.c b/drivers/usb/typec/rt1719.c index be02d420920e..0b0c23a0b014 100644 --- a/drivers/usb/typec/rt1719.c +++ b/drivers/usb/typec/rt1719.c @@ -109,12 +109,6 @@ struct rt1719_data { u16 conn_stat; }; =20 -static const enum power_supply_usb_type rt1719_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_PD_PPS -}; - static const enum power_supply_property rt1719_psy_properties[] =3D { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_USB_TYPE, @@ -572,8 +566,9 @@ static int devm_rt1719_psy_register(struct rt1719_data = *data) =20 data->psy_desc.name =3D psy_name; data->psy_desc.type =3D POWER_SUPPLY_TYPE_USB; - data->psy_desc.usb_types =3D rt1719_psy_usb_types; - data->psy_desc.num_usb_types =3D ARRAY_SIZE(rt1719_psy_usb_types); + data->psy_desc.usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); data->psy_desc.properties =3D rt1719_psy_properties; data->psy_desc.num_properties =3D ARRAY_SIZE(rt1719_psy_properties); data->psy_desc.get_property =3D rt1719_psy_get_property; diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 26f9006e95e1..0bd9c9569fb7 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -7484,12 +7484,6 @@ static int tcpm_psy_prop_writeable(struct power_supp= ly *psy, } } =20 -static enum power_supply_usb_type tcpm_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_PD_PPS, -}; - static const char *tcpm_psy_name_prefix =3D "tcpm-source-psy-"; =20 static int devm_tcpm_psy_register(struct tcpm_port *port) @@ -7510,8 +7504,9 @@ static int devm_tcpm_psy_register(struct tcpm_port *p= ort) port_dev_name); port->psy_desc.name =3D psy_name; port->psy_desc.type =3D POWER_SUPPLY_TYPE_USB; - port->psy_desc.usb_types =3D tcpm_psy_usb_types; - port->psy_desc.num_usb_types =3D ARRAY_SIZE(tcpm_psy_usb_types); + port->psy_desc.usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); port->psy_desc.properties =3D tcpm_psy_props; port->psy_desc.num_properties =3D ARRAY_SIZE(tcpm_psy_props); port->psy_desc.get_property =3D tcpm_psy_get_prop; diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index ea768b19a7f1..7512f0c3f6cb 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -150,11 +150,6 @@ static enum power_supply_property tps6598x_psy_props[]= =3D { POWER_SUPPLY_PROP_ONLINE, }; =20 -static enum power_supply_usb_type tps6598x_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, -}; - static const char *tps6598x_psy_name_prefix =3D "tps6598x-source-psy-"; =20 /* @@ -827,8 +822,8 @@ static int devm_tps6598_psy_register(struct tps6598x *t= ps) =20 tps->psy_desc.name =3D psy_name; tps->psy_desc.type =3D POWER_SUPPLY_TYPE_USB; - tps->psy_desc.usb_types =3D tps6598x_psy_usb_types; - tps->psy_desc.num_usb_types =3D ARRAY_SIZE(tps6598x_psy_usb_types); + tps->psy_desc.usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD); tps->psy_desc.properties =3D tps6598x_psy_props; tps->psy_desc.num_properties =3D ARRAY_SIZE(tps6598x_psy_props); tps->psy_desc.get_property =3D tps6598x_psy_get_prop; diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index e623d80e177c..1c631c7855a9 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -254,12 +254,6 @@ static int ucsi_psy_get_prop(struct power_supply *psy, } } =20 -static enum power_supply_usb_type ucsi_psy_usb_types[] =3D { - POWER_SUPPLY_USB_TYPE_C, - POWER_SUPPLY_USB_TYPE_PD, - POWER_SUPPLY_USB_TYPE_PD_PPS, -}; - int ucsi_register_port_psy(struct ucsi_connector *con) { struct power_supply_config psy_cfg =3D {}; @@ -276,8 +270,9 @@ int ucsi_register_port_psy(struct ucsi_connector *con) =20 con->psy_desc.name =3D psy_name; con->psy_desc.type =3D POWER_SUPPLY_TYPE_USB; - con->psy_desc.usb_types =3D ucsi_psy_usb_types; - con->psy_desc.num_usb_types =3D ARRAY_SIZE(ucsi_psy_usb_types); + con->psy_desc.usb_types =3D BIT(POWER_SUPPLY_USB_TYPE_C) | + BIT(POWER_SUPPLY_USB_TYPE_PD) | + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); con->psy_desc.properties =3D ucsi_psy_props; con->psy_desc.num_properties =3D ARRAY_SIZE(ucsi_psy_props); con->psy_desc.get_property =3D ucsi_psy_get_prop; diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 72dc7e45c90c..910d407ebe63 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -243,8 +243,7 @@ struct power_supply_desc { const char *name; enum power_supply_type type; u8 charge_behaviours; - const enum power_supply_usb_type *usb_types; - size_t num_usb_types; + u32 usb_types; const enum power_supply_property *properties; size_t num_properties; =20 --=20 2.46.0