From: Sebastian Reichel <sre@kernel.org>
To: Lubomir Rintel <lkundrak@v3.sk>
Cc: Darren Hart <dvhart@infradead.org>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
x86@kernel.org, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH 06/10] power: supply: olpc_battery: Move priv data to a struct
Date: Fri, 5 Apr 2019 15:45:53 +0200 [thread overview]
Message-ID: <20190405134553.ahntfz7aggzg7hdd@earth.universe> (raw)
In-Reply-To: <20190310162419.11861-7-lkundrak@v3.sk>
[-- Attachment #1: Type: text/plain, Size: 7050 bytes --]
Hi,
On Sun, Mar 10, 2019 at 05:24:15PM +0100, Lubomir Rintel wrote:
> The global variables for private data are not too nice. I'd like some
> more, and that would clutter the global name space even further.
>
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-- Sebastian
>
> ---
> Changes since v4:
> - Bring some more code that was misplaced here.
>
> Changes since v2:
> - Bring the allocaton of the priv data structure here
>
> Changes since v1:
> - Split out the move to devm_* into a separate patch
>
> drivers/power/supply/olpc_battery.c | 78 ++++++++++++++++++-----------
> 1 file changed, 48 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c
> index 3dcf5e19f329..f7bb9bedd893 100644
> --- a/drivers/power/supply/olpc_battery.c
> +++ b/drivers/power/supply/olpc_battery.c
> @@ -53,6 +53,12 @@
>
> #define BAT_ADDR_MFR_TYPE 0x5F
>
> +struct olpc_battery_data {
> + struct power_supply *olpc_ac;
> + struct power_supply *olpc_bat;
> + char bat_serial[17];
> +};
> +
> /*********************************************************************
> * Power
> *********************************************************************/
> @@ -91,11 +97,8 @@ static const struct power_supply_desc olpc_ac_desc = {
> .get_property = olpc_ac_get_prop,
> };
>
> -static struct power_supply *olpc_ac;
> -
> -static char bat_serial[17]; /* Ick */
> -
> -static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte)
> +static int olpc_bat_get_status(struct olpc_battery_data *data,
> + union power_supply_propval *val, uint8_t ec_byte)
> {
> if (olpc_platform_info.ecver > 0x44) {
> if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
> @@ -326,6 +329,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
> enum power_supply_property psp,
> union power_supply_propval *val)
> {
> + struct olpc_battery_data *data = power_supply_get_drvdata(psy);
> int ret = 0;
> __be16 ec_word;
> uint8_t ec_byte;
> @@ -347,7 +351,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
>
> switch (psp) {
> case POWER_SUPPLY_PROP_STATUS:
> - ret = olpc_bat_get_status(val, ec_byte);
> + ret = olpc_bat_get_status(data, val, ec_byte);
> if (ret)
> return ret;
> break;
> @@ -450,8 +454,8 @@ static int olpc_bat_get_property(struct power_supply *psy,
> if (ret)
> return ret;
>
> - sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
> - val->strval = bat_serial;
> + sprintf(data->bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
> + val->strval = data->bat_serial;
> break;
> case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
> ret = olpc_bat_get_voltage_max_design(val);
> @@ -579,17 +583,17 @@ static struct power_supply_desc olpc_bat_desc = {
> .use_for_apm = 1,
> };
>
> -static struct power_supply *olpc_bat;
> -
> static int olpc_battery_suspend(struct platform_device *pdev,
> pm_message_t state)
> {
> - if (device_may_wakeup(&olpc_ac->dev))
> + struct olpc_battery_data *data = platform_get_drvdata(pdev);
> +
> + if (device_may_wakeup(&data->olpc_ac->dev))
> olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
> else
> olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
>
> - if (device_may_wakeup(&olpc_bat->dev))
> + if (device_may_wakeup(&data->olpc_bat->dev))
> olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
> | EC_SCI_SRC_BATERR);
> else
> @@ -601,8 +605,15 @@ static int olpc_battery_suspend(struct platform_device *pdev,
>
> static int olpc_battery_probe(struct platform_device *pdev)
> {
> - int ret;
> + struct power_supply_config psy_cfg = {};
> + struct olpc_battery_data *data;
> uint8_t status;
> + int ret;
> +
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> + platform_set_drvdata(pdev, data);
>
> /*
> * We've seen a number of EC protocol changes; this driver requires
> @@ -620,9 +631,13 @@ static int olpc_battery_probe(struct platform_device *pdev)
>
> /* Ignore the status. It doesn't actually matter */
>
> - olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
> - if (IS_ERR(olpc_ac))
> - return PTR_ERR(olpc_ac);
> + psy_cfg.of_node = pdev->dev.of_node;
> + psy_cfg.drv_data = data;
> +
> + data->olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, &psy_cfg);
> + if (IS_ERR(data->olpc_ac))
> + return PTR_ERR(data->olpc_ac);
> +
> if (of_device_is_compatible(pdev->dev.of_node, "olpc,xo1.5-battery")) {
> /* XO-1.5 */
> olpc_bat_desc.properties = olpc_xo15_bat_props;
> @@ -633,42 +648,45 @@ static int olpc_battery_probe(struct platform_device *pdev)
> olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
> }
>
> - olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, NULL);
> - if (IS_ERR(olpc_bat)) {
> - ret = PTR_ERR(olpc_bat);
> + data->olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, &psy_cfg);
> + if (IS_ERR(data->olpc_bat)) {
> + ret = PTR_ERR(data->olpc_bat);
> goto battery_failed;
> }
>
> - ret = device_create_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> + ret = device_create_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> if (ret)
> goto eeprom_failed;
>
> - ret = device_create_file(&olpc_bat->dev, &olpc_bat_error);
> + ret = device_create_file(&data->olpc_bat->dev, &olpc_bat_error);
> if (ret)
> goto error_failed;
>
> if (olpc_ec_wakeup_available()) {
> - device_set_wakeup_capable(&olpc_ac->dev, true);
> - device_set_wakeup_capable(&olpc_bat->dev, true);
> + device_set_wakeup_capable(&data->olpc_ac->dev, true);
> + device_set_wakeup_capable(&data->olpc_bat->dev, true);
> }
>
> return 0;
>
> error_failed:
> - device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> + device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> eeprom_failed:
> - power_supply_unregister(olpc_bat);
> + power_supply_unregister(data->olpc_bat);
> battery_failed:
> - power_supply_unregister(olpc_ac);
> + power_supply_unregister(data->olpc_ac);
> return ret;
> }
>
> static int olpc_battery_remove(struct platform_device *pdev)
> {
> - device_remove_file(&olpc_bat->dev, &olpc_bat_error);
> - device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> - power_supply_unregister(olpc_bat);
> - power_supply_unregister(olpc_ac);
> + struct olpc_battery_data *data = platform_get_drvdata(pdev);
> +
> + device_remove_file(&data->olpc_bat->dev, &olpc_bat_error);
> + device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> + power_supply_unregister(data->olpc_bat);
> + power_supply_unregister(data->olpc_ac);
> +
> return 0;
> }
>
> --
> 2.20.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-04-05 13:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-10 16:24 [PATCH 00/10] Add support for XO 1.75 to OLPC battery driver Lubomir Rintel
2019-03-10 16:24 ` [PATCH 01/10] dt-bindings: olpc_battery: Add XO-1.5 battery Lubomir Rintel
2019-03-10 16:24 ` [PATCH 02/10] x86, olpc: Don't split string literals when fixing up the DT Lubomir Rintel
2019-03-22 23:18 ` Thomas Gleixner
2019-03-10 16:24 ` [PATCH 03/10] x86, olpc: Trivial code move in DT fixup Lubomir Rintel
2019-03-22 23:20 ` Thomas Gleixner
2019-03-10 16:24 ` [PATCH 04/10] x86, olpc: Use a correct version when making up a battery node Lubomir Rintel
2019-03-22 23:25 ` Thomas Gleixner
2019-04-05 13:59 ` Sebastian Reichel
2019-03-10 16:24 ` [PATCH 05/10] power: supply: olpc_battery: Use DT to get battery version Lubomir Rintel
2019-03-10 16:24 ` [PATCH 06/10] power: supply: olpc_battery: Move priv data to a struct Lubomir Rintel
2019-04-05 13:45 ` Sebastian Reichel [this message]
2019-03-10 16:24 ` [PATCH 07/10] power: supply: olpc_battery: Use devm_power_supply_register() Lubomir Rintel
2019-03-10 16:24 ` [PATCH 08/10] power: supply: olpc_battery: Avoid using platform_info Lubomir Rintel
2019-03-10 16:24 ` [PATCH 09/10] power: supply: olpc_battery: Add OLPC XO 1.75 support Lubomir Rintel
2019-04-05 13:50 ` Sebastian Reichel
2019-03-10 16:24 ` [PATCH 10/10] power: supply: olpc_battery: Have the framework register sysfs files for us Lubomir Rintel
2019-04-05 13:49 ` Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190405134553.ahntfz7aggzg7hdd@earth.universe \
--to=sre@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lkundrak@v3.sk \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).