mbox series

[0/6] power: supply: Change usb_types from an array into a bitmask

Message ID 20240831142039.28830-1-hdegoede@redhat.com (mailing list archive)
Headers show
Series power: supply: Change usb_types from an array into a bitmask | expand

Message

Hans de Goede Aug. 31, 2024, 2:20 p.m. UTC
Hi All,

When support for the "charge_behaviour" property was added the list of
available values was made a bitmask in power_supply_desc.

"usb_types" is very similar in that:
1. It is an enum
2. The list of available values is stored in power_supply_desc
3. When shown it shows all available values, with the active one surrounded
   by square brackets.

But "usb_types" uses an array with valid enum values instead of a bitmask.
This uses more memory then the bitmap approach and it makes it impossible
to have a shared generic show() function for properties which show
available values, with the active one surrounded by square brackets.

This patch-set moves "usb_types" over to a bitmask in power_supply_desc
to indicate the available values.

Patches 1 - 3:

It turns out that the ucs1002-power driver contained a surprise in that
it supports writing to "usb_type" even though the ABI doc says it is
read-only. Since we cannot break shipped userspace API, the ship has sailed
on this one. The first patch documents that writing "usb_type" is allowed,
but only for power-supply devices which provide USB power rather then
consume it.

Enum properties accept writing the FOO_TEXT[] string values, passing
the enum value matching the FOO_TEXT entry to set_property(), the second
patch adjusts ucs1002_set_usb_type() to directly accept enum values.

The rt9467 driver was another driver which allowed writing to "usb_type"
but there the use made no sense, so it is simply dropped.

Patches 4 - 6:

These patches implement the actual moving of usb_types to a bitmask.

Patch 6 is a bit of a bigbang patch moving all drivers over in one go,
touching a couple of drivers outside drivers/power/supply: 1 in
drivers/extcon/ 1 in drivers/phy/ and 5 in drivers/usb/typec/ since
the changes outside of drivers/power/supply are small I've chosen to
make all the changes in one go rather then have some sort of
intermediate state where both ways are supported.

For merging this I believe it would be best for an immutable branch / tag
to be created on the linux-power-supply tree and then send a pull-request
to the extcon, phy and usb-typec maintainers to merge the tag.

extcon, phy and typec maintainers can you please give your Acked-by for
patch 6/6 for merging these changes through the linux-power-supply tree?

This set is based on top of the latest linux-power-supply/for-next.

Regards,

Hans


Hans de Goede (6):
  power: supply: "usb_type" property may be written to
  power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string
    values
  power: supply: rt9467-charger: Remove "usb_type" property write
    support
  power: supply: sysfs: Add power_supply_show_enum_with_available()
    helper
  power: supply: sysfs: Move power_supply_show_enum_with_available() up
  power: supply: Change usb_types from an array into a bitmask

 Documentation/ABI/testing/sysfs-class-power   |  7 +-
 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     | 66 ++++++-------------
 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         | 16 ++---
 drivers/power/supply/rt9471.c                 | 15 ++---
 drivers/power/supply/ucs1002_power.c          | 26 ++++----
 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 +-
 25 files changed, 132 insertions(+), 254 deletions(-)

Comments

Sebastian Reichel Sept. 3, 2024, 9:57 p.m. UTC | #1
On Sat, 31 Aug 2024 16:20:33 +0200, Hans de Goede wrote:
> When support for the "charge_behaviour" property was added the list of
> available values was made a bitmask in power_supply_desc.
> 
> "usb_types" is very similar in that:
> 1. It is an enum
> 2. The list of available values is stored in power_supply_desc
> 3. When shown it shows all available values, with the active one surrounded
>    by square brackets.
> 
> [...]

Applied, thanks!

[1/6] power: supply: "usb_type" property may be written to
      commit: 0d9af1e1c93b6a89f3fb6dcbafa5bc78892cb94f
[2/6] power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string values
      commit: 83a4c42df75e8f6ff671fa9fbe7d4c79b98626de
[3/6] power: supply: rt9467-charger: Remove "usb_type" property write support
      commit: 03ec41c1670aedfbd126f541c4acbb8e69d4cd0c
[4/6] power: supply: sysfs: Add power_supply_show_enum_with_available() helper
      commit: a6456d43e9abebb5d7866e5edae3024188273306
[5/6] power: supply: sysfs: Move power_supply_show_enum_with_available() up
      commit: 322900ac7d82be0475466f81946b6484cd1936bd
[6/6] power: supply: Change usb_types from an array into a bitmask
      commit: 364ea7ccaef917a3068236a19a4b31a0623b561a

Best regards,
Sebastian Reichel Sept. 3, 2024, 10:04 p.m. UTC | #2
Hi,

On Sat, Aug 31, 2024 at 04:20:33PM GMT, Hans de Goede wrote:
> When support for the "charge_behaviour" property was added the list of
> available values was made a bitmask in power_supply_desc.
> 
> "usb_types" is very similar in that:
> 1. It is an enum
> 2. The list of available values is stored in power_supply_desc
> 3. When shown it shows all available values, with the active one surrounded
>    by square brackets.
> 
> But "usb_types" uses an array with valid enum values instead of a bitmask.
> This uses more memory then the bitmap approach and it makes it impossible
> to have a shared generic show() function for properties which show
> available values, with the active one surrounded by square brackets.
> 
> This patch-set moves "usb_types" over to a bitmask in power_supply_desc
> to indicate the available values.
> 
> Patches 1 - 3:
> 
> It turns out that the ucs1002-power driver contained a surprise in that
> it supports writing to "usb_type" even though the ABI doc says it is
> read-only. Since we cannot break shipped userspace API, the ship has sailed
> on this one. The first patch documents that writing "usb_type" is allowed,
> but only for power-supply devices which provide USB power rather then
> consume it.
> 
> Enum properties accept writing the FOO_TEXT[] string values, passing
> the enum value matching the FOO_TEXT entry to set_property(), the second
> patch adjusts ucs1002_set_usb_type() to directly accept enum values.
> 
> The rt9467 driver was another driver which allowed writing to "usb_type"
> but there the use made no sense, so it is simply dropped.
> 
> Patches 4 - 6:
> 
> These patches implement the actual moving of usb_types to a bitmask.
> 
> Patch 6 is a bit of a bigbang patch moving all drivers over in one go,
> touching a couple of drivers outside drivers/power/supply: 1 in
> drivers/extcon/ 1 in drivers/phy/ and 5 in drivers/usb/typec/ since
> the changes outside of drivers/power/supply are small I've chosen to
> make all the changes in one go rather then have some sort of
> intermediate state where both ways are supported.
> 
> For merging this I believe it would be best for an immutable branch / tag
> to be created on the linux-power-supply tree and then send a pull-request
> to the extcon, phy and usb-typec maintainers to merge the tag.
> 
> extcon, phy and typec maintainers can you please give your Acked-by for
> patch 6/6 for merging these changes through the linux-power-supply tree?
> 
> This set is based on top of the latest linux-power-supply/for-next.

As we are quite close before the merge window I just took it with
just the Ack from Greg. The changes in PHY and Extcon are quite
small. I did prepare an immutable branch in case it is needed by
any of the other involved trees:

The following changes since commit 8400291e289ee6b2bf9779ff1c83a291501f017b:

  Linux 6.11-rc1 (2024-07-28 14:19:55 -0700)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git tags/ib-psy-usb-types-signed

for you to fetch changes up to 364ea7ccaef917a3068236a19a4b31a0623b561a:

  power: supply: Change usb_types from an array into a bitmask (2024-09-03 23:20:28 +0200)

----------------------------------------------------------------
Immutable branch for usb_types change for v6.12

Changing usb_types type from array to bitmap in the power_supply_desc
struct requires updating power-supply drivers living in different
subsystem, so it is handled via an immutable branch.

----------------------------------------------------------------
Hans de Goede (6):
      power: supply: "usb_type" property may be written to
      power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string values
      power: supply: rt9467-charger: Remove "usb_type" property write support
      power: supply: sysfs: Add power_supply_show_enum_with_available() helper
      power: supply: sysfs: Move power_supply_show_enum_with_available() up
      power: supply: Change usb_types from an array into a bitmask

 Documentation/ABI/testing/sysfs-class-power     |  7 ++-
 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 +++------
 drivers/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       | 66 ++++++++-----------------
 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           | 16 ++----
 drivers/power/supply/rt9471.c                   | 15 ++----
 drivers/power/supply/ucs1002_power.c            | 26 +++++-----
 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 +-
 25 files changed, 132 insertions(+), 254 deletions(-)

-- Sebastian
Hans de Goede Sept. 4, 2024, 9:26 a.m. UTC | #3
Hi,

On 9/4/24 12:04 AM, Sebastian Reichel wrote:
> Hi,
> 
> On Sat, Aug 31, 2024 at 04:20:33PM GMT, Hans de Goede wrote:
>> When support for the "charge_behaviour" property was added the list of
>> available values was made a bitmask in power_supply_desc.
>>
>> "usb_types" is very similar in that:
>> 1. It is an enum
>> 2. The list of available values is stored in power_supply_desc
>> 3. When shown it shows all available values, with the active one surrounded
>>    by square brackets.
>>
>> But "usb_types" uses an array with valid enum values instead of a bitmask.
>> This uses more memory then the bitmap approach and it makes it impossible
>> to have a shared generic show() function for properties which show
>> available values, with the active one surrounded by square brackets.
>>
>> This patch-set moves "usb_types" over to a bitmask in power_supply_desc
>> to indicate the available values.
>>
>> Patches 1 - 3:
>>
>> It turns out that the ucs1002-power driver contained a surprise in that
>> it supports writing to "usb_type" even though the ABI doc says it is
>> read-only. Since we cannot break shipped userspace API, the ship has sailed
>> on this one. The first patch documents that writing "usb_type" is allowed,
>> but only for power-supply devices which provide USB power rather then
>> consume it.
>>
>> Enum properties accept writing the FOO_TEXT[] string values, passing
>> the enum value matching the FOO_TEXT entry to set_property(), the second
>> patch adjusts ucs1002_set_usb_type() to directly accept enum values.
>>
>> The rt9467 driver was another driver which allowed writing to "usb_type"
>> but there the use made no sense, so it is simply dropped.
>>
>> Patches 4 - 6:
>>
>> These patches implement the actual moving of usb_types to a bitmask.
>>
>> Patch 6 is a bit of a bigbang patch moving all drivers over in one go,
>> touching a couple of drivers outside drivers/power/supply: 1 in
>> drivers/extcon/ 1 in drivers/phy/ and 5 in drivers/usb/typec/ since
>> the changes outside of drivers/power/supply are small I've chosen to
>> make all the changes in one go rather then have some sort of
>> intermediate state where both ways are supported.
>>
>> For merging this I believe it would be best for an immutable branch / tag
>> to be created on the linux-power-supply tree and then send a pull-request
>> to the extcon, phy and usb-typec maintainers to merge the tag.
>>
>> extcon, phy and typec maintainers can you please give your Acked-by for
>> patch 6/6 for merging these changes through the linux-power-supply tree?
>>
>> This set is based on top of the latest linux-power-supply/for-next.
> 
> As we are quite close before the merge window I just took it with
> just the Ack from Greg. The changes in PHY and Extcon are quite
> small.

Great, thank you.

Regards,

Hans




> I did prepare an immutable branch in case it is needed by
> any of the other involved trees:
> 
> The following changes since commit 8400291e289ee6b2bf9779ff1c83a291501f017b:
> 
>   Linux 6.11-rc1 (2024-07-28 14:19:55 -0700)
> 
> are available in the Git repository at:
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git tags/ib-psy-usb-types-signed
> 
> for you to fetch changes up to 364ea7ccaef917a3068236a19a4b31a0623b561a:
> 
>   power: supply: Change usb_types from an array into a bitmask (2024-09-03 23:20:28 +0200)
> 
> ----------------------------------------------------------------
> Immutable branch for usb_types change for v6.12
> 
> Changing usb_types type from array to bitmap in the power_supply_desc
> struct requires updating power-supply drivers living in different
> subsystem, so it is handled via an immutable branch.
> 
> ----------------------------------------------------------------
> Hans de Goede (6):
>       power: supply: "usb_type" property may be written to
>       power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string values
>       power: supply: rt9467-charger: Remove "usb_type" property write support
>       power: supply: sysfs: Add power_supply_show_enum_with_available() helper
>       power: supply: sysfs: Move power_supply_show_enum_with_available() up
>       power: supply: Change usb_types from an array into a bitmask
> 
>  Documentation/ABI/testing/sysfs-class-power     |  7 ++-
>  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 +++------
>  drivers/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       | 66 ++++++++-----------------
>  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           | 16 ++----
>  drivers/power/supply/rt9471.c                   | 15 ++----
>  drivers/power/supply/ucs1002_power.c            | 26 +++++-----
>  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 +-
>  25 files changed, 132 insertions(+), 254 deletions(-)
> 
> -- Sebastian