All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lubomir Rintel <lkundrak@v3.sk>
To: Sebastian Reichel <sre@kernel.org>
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,
	Lubomir Rintel <lkundrak@v3.sk>,
	Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: [PATCH v7 10/10] power: supply: olpc_battery: Have the framework register sysfs files for us
Date: Thu, 18 Apr 2019 16:46:55 +0200	[thread overview]
Message-ID: <20190418144655.18758-11-lkundrak@v3.sk> (raw)
In-Reply-To: <20190418144655.18758-1-lkundrak@v3.sk>

The power framework gained ability to register groups of sysfs
attributes in commit cef8fe6a382c ("power: supply: core: add support for
custom sysfs attributes").

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Suggested-by: Sebastian Reichel <sre@kernel.org>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>

---
Changes since v6:
- Collect review tag from Sebastian Reichel

Changes since v5:
- Added this patch

 drivers/power/supply/olpc_battery.c | 64 ++++++++++++++++-------------
 1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c
index 0d67158c13d6..c628d3a47e14 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -551,7 +551,7 @@ static ssize_t olpc_bat_eeprom_read(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static const struct bin_attribute olpc_bat_eeprom = {
+static struct bin_attribute olpc_bat_eeprom = {
 	.attr = {
 		.name = "eeprom",
 		.mode = S_IRUGO,
@@ -575,7 +575,7 @@ static ssize_t olpc_bat_error_read(struct device *dev,
 	return sprintf(buf, "%d\n", ec_byte);
 }
 
-static const struct device_attribute olpc_bat_error = {
+static struct device_attribute olpc_bat_error = {
 	.attr = {
 		.name = "error",
 		.mode = S_IRUGO,
@@ -583,6 +583,27 @@ static const struct device_attribute olpc_bat_error = {
 	.show = olpc_bat_error_read,
 };
 
+static struct attribute *olpc_bat_sysfs_attrs[] = {
+	&olpc_bat_error.attr,
+	NULL
+};
+
+static struct bin_attribute *olpc_bat_sysfs_bin_attrs[] = {
+	&olpc_bat_eeprom,
+	NULL
+};
+
+static const struct attribute_group olpc_bat_sysfs_group = {
+	.attrs = olpc_bat_sysfs_attrs,
+	.bin_attrs = olpc_bat_sysfs_bin_attrs,
+
+};
+
+static const struct attribute_group *olpc_bat_sysfs_groups[] = {
+	&olpc_bat_sysfs_group,
+	NULL
+};
+
 /*********************************************************************
  *		Initialisation
  *********************************************************************/
@@ -615,7 +636,8 @@ static int olpc_battery_suspend(struct platform_device *pdev,
 
 static int olpc_battery_probe(struct platform_device *pdev)
 {
-	struct power_supply_config psy_cfg = {};
+	struct power_supply_config bat_psy_cfg = {};
+	struct power_supply_config ac_psy_cfg = {};
 	struct olpc_battery_data *data;
 	uint8_t status;
 	uint8_t ecver;
@@ -654,10 +676,11 @@ static int olpc_battery_probe(struct platform_device *pdev)
 
 	/* Ignore the status. It doesn't actually matter */
 
-	psy_cfg.of_node = pdev->dev.of_node;
-	psy_cfg.drv_data = data;
+	ac_psy_cfg.of_node = pdev->dev.of_node;
+	ac_psy_cfg.drv_data = data;
 
-	data->olpc_ac = devm_power_supply_register(&pdev->dev, &olpc_ac_desc, &psy_cfg);
+	data->olpc_ac = devm_power_supply_register(&pdev->dev, &olpc_ac_desc,
+								&ac_psy_cfg);
 	if (IS_ERR(data->olpc_ac))
 		return PTR_ERR(data->olpc_ac);
 
@@ -671,37 +694,21 @@ static int olpc_battery_probe(struct platform_device *pdev)
 		olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
 	}
 
-	data->olpc_bat = devm_power_supply_register(&pdev->dev, &olpc_bat_desc, &psy_cfg);
+	bat_psy_cfg.of_node = pdev->dev.of_node;
+	bat_psy_cfg.drv_data = data;
+	bat_psy_cfg.attr_grp = olpc_bat_sysfs_groups;
+
+	data->olpc_bat = devm_power_supply_register(&pdev->dev, &olpc_bat_desc,
+								&bat_psy_cfg);
 	if (IS_ERR(data->olpc_bat))
 		return PTR_ERR(data->olpc_bat);
 
-	ret = device_create_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
-	if (ret)
-		return ret;
-
-	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(&data->olpc_ac->dev, true);
 		device_set_wakeup_capable(&data->olpc_bat->dev, true);
 	}
 
 	return 0;
-
-error_failed:
-	device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
-	return ret;
-}
-
-static int olpc_battery_remove(struct platform_device *pdev)
-{
-	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);
-	return 0;
 }
 
 static const struct of_device_id olpc_battery_ids[] = {
@@ -717,7 +724,6 @@ static struct platform_driver olpc_battery_driver = {
 		.of_match_table = olpc_battery_ids,
 	},
 	.probe = olpc_battery_probe,
-	.remove = olpc_battery_remove,
 	.suspend = olpc_battery_suspend,
 };
 
-- 
2.21.0


  parent reply	other threads:[~2019-04-18 14:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 14:46 [PATCH v7 00/10] Add support for XO 1.75 to OLPC battery driver Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 01/10] dt-bindings: olpc_battery: Add XO-1.5 battery Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 02/10] x86/platform/olpc: Don't split string literals when fixing up the DT Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 03/10] x86/platform/olpc: Trivial code move in DT fixup Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 04/10] x86/platform/olpc: Use a correct version when making up a battery node Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 05/10] power: supply: olpc_battery: Use DT to get battery version Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 06/10] power: supply: olpc_battery: Move priv data to a struct Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 07/10] power: supply: olpc_battery: Use devm_power_supply_register() Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 08/10] power: supply: olpc_battery: Avoid using platform_info Lubomir Rintel
2019-04-18 14:46 ` [PATCH v7 09/10] power: supply: olpc_battery: Add OLPC XO 1.75 support Lubomir Rintel
2019-04-18 14:46 ` Lubomir Rintel [this message]
2019-04-18 20:20 ` [PATCH v7 00/10] Add support for XO 1.75 to OLPC battery driver Sebastian Reichel
2019-04-19  7:57   ` Ingo Molnar
2019-04-19 12:42     ` 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=20190418144655.18758-11-lkundrak@v3.sk \
    --to=lkundrak@v3.sk \
    --cc=devicetree@vger.kernel.org \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=sre@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.