Re: [PATCH v5 13/13] platform/x86: oxpec: Add charge threshold and behaviour to OneXPlayer

Thomas Weißschuh
2025-03-17T21:02:07Z

On 2025-03-17 19:20:46+0100, Antheas Kapenekakis wrote:
> On Mon, 17 Mar 2025 at 19:13, Thomas Weißschuh <linux@weissschuh.net> wrote:
> > On 2025-03-17 16:53:49+0100, Antheas Kapenekakis wrote:

> > > @@ -60,6 +61,7 @@ enum oxp_board {
> > > };
> > >
> > > static enum oxp_board board;
> > > +static struct device *oxp_dev;
> >
> > Using a global variable is ugly.
> > An explicit parameter passed through
> > battery_hook_register() -> add_battery()
> > would be nicer.
> > It would require changes to the core code and all its users, though.
>
> I debated doing this. Unfortunately, this driver uses a global
> variable already (see board), so introducing a struct here seemed a
> bit excessive.
>
> During a refactor, removing the board global variable would introduce
> a features struct, which can then be used for the battery hook.
>
> So I think they should be done together in a future series.

Fine by me.

<snip>

> > > +static int oxp_add_battery(struct power_supply *battery, struct acpi_battery_hook *hook)
> > > +{
> > > + /* OneXPlayer devices only have one battery. */
> > > + if (strcmp(battery->desc->name, "BAT0") != 0 &&
> > > + strcmp(battery->desc->name, "BAT1") != 0 &&
> > > + strcmp(battery->desc->name, "BATC") != 0 &&
> > > + strcmp(battery->desc->name, "BATT") != 0)
> > > + return -ENODEV;
> >
> > If they only have one battery, why is the check necessary?
>
> Leftover from when I modelled the battery hook from asus-wmi. If the
> battery hook only runs for system batteries and not e.g., for
> peripherals, I will remove this.

The battery hook runs for all batteries discovered through ACPI.
These should only be system batteries.

> > > +
> > > + return power_supply_register_extension(battery, &oxp_psy_ext, oxp_dev, NULL);
> > > +}
> > > +
> > > +static int oxp_remove_battery(struct power_supply *battery, struct acpi_battery_hook *hook)
> > > +{
> > > + power_supply_unregister_extension(battery, &oxp_psy_ext);
> > > + return 0;
> > > +}
> > > +
> > > +static struct acpi_battery_hook battery_hook = {
> > > + .add_battery = oxp_add_battery,
> > > + .remove_battery = oxp_remove_battery,
> > > + .name = "OneXPlayer Battery",
> >
> > This struct can also be aligned.
>
> Can you expand on that?

It is about lining up the "=" characters all in one vertical line.
Same as in oxp_psy_ext;

<snip>