Skip to contentSkip to conversation

mfd: intel_soc_pmic_bxtwc: A few cleanups

PATCH Applied Andy Shevchenko 2 participants 6 messages Oct 16, 2024 – Oct 31, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mfd: intel_soc_pmic_bxtwc: A few cleanups

While working on the fixes series against the driver I have noticed some places that can be improved using better APIs or approaches. Hence this mini-series. The plus statistics is due to the patch 2 that brought missed inclusions to the code (instead of using a proxy header).

Have been tested on Intel Joule device.

Andy Shevchenko (4):
mfd: intel_soc_pmic_bxtwc: Switch to use ATTRIBUTE_GROUPS()
mfd: intel_soc_pmic_bxtwc: Don't use "proxy" headers
mfd: intel_soc_pmic_bxtwc: Use temporary variable for struct device
mfd: intel_soc_pmic_bxtwc: Deduplicate error messages

 drivers/mfd/intel_soc_pmic_bxtwc.c | 45 +++++++++++++++++-------------
 1 file changed, 26 insertions(+), 19 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH 1/4 mfd: intel_soc_pmic_bxtwc: Switch to use ATTRIBUTE_GROUPS()

Embrace ATTRIBUTE_GROUPS() to avoid boiler plate code. While at it, move DEVICE_ATTR_ADMIN_RW() closer to the callbacks.

This should not introduce any functional changes.

---
 drivers/mfd/intel_soc_pmic_bxtwc.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/mfd/intel_soc_pmic_bxtwc.c +3 -11
index b7204072e93e..c130734f308e 100644
@@ -364,6 +364,7 @@ static ssize_t addr_store(struct device *dev,
 
 	return count;
 }
+static DEVICE_ATTR_ADMIN_RW(addr);
 
 static ssize_t val_show(struct device *dev,
 			struct device_attribute *attr, char *buf)
@@ -400,23 +401,14 @@ static ssize_t val_store(struct device *dev,
 	}
 	return count;
 }
-
-static DEVICE_ATTR_ADMIN_RW(addr);
 static DEVICE_ATTR_ADMIN_RW(val);
+
 static struct attribute *bxtwc_attrs[] = {
 	&dev_attr_addr.attr,
 	&dev_attr_val.attr,
 	NULL
 };
-
-static const struct attribute_group bxtwc_group = {
-	.attrs = bxtwc_attrs,
-};
-
-static const struct attribute_group *bxtwc_groups[] = {
-	&bxtwc_group,
-	NULL
-};
+ATTRIBUTE_GROUPS(bxtwc);
 
 static const struct regmap_config bxtwc_regmap_config = {
 	.reg_bits = 16,
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw

PATCH 2/4 mfd: intel_soc_pmic_bxtwc: Don't use "proxy" headers

In reply to Andy Shevchenko

Update header inclusions to follow IWYU (Include What You Use) principle.

---
 drivers/mfd/intel_soc_pmic_bxtwc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mfd/intel_soc_pmic_bxtwc.c +12 -1
index c130734f308e..1469e89b88ce 100644
@@ -6,16 +6,27 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/array_size.h>
 #include <linux/bits.h>
 #include <linux/delay.h>
+#include <linux/device.h>
 #include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/gfp_types.h>
 #include <linux/interrupt.h>
-#include <linux/kernel.h>
+#include <linux/ioport.h>
+#include <linux/kstrtox.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/intel_soc_pmic.h>
 #include <linux/mfd/intel_soc_pmic_bxtwc.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/platform_data/x86/intel_scu_ipc.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
 
 /* PMIC device registers */
 #define REG_ADDR_MASK		GENMASK(15, 8)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#3 lore raw

PATCH 3/4 mfd: intel_soc_pmic_bxtwc: Use temporary variable for struct device

In reply to Andy Shevchenko

Use a temporary variable for the struct device pointers to avoid dereferencing. This makes code a bit neater.

---
 drivers/mfd/intel_soc_pmic_bxtwc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mfd/intel_soc_pmic_bxtwc.c +3 -3
index 1469e89b88ce..5e6cffb162a0 100644
@@ -434,15 +434,15 @@ static int bxtwc_add_chained_irq_chip(struct intel_soc_pmic *pmic,
 				const struct regmap_irq_chip *chip,
 				struct regmap_irq_chip_data **data)
 {
+	struct device *dev = pmic->dev;
 	int irq;
 
 	irq = regmap_irq_get_virq(pdata, pirq);
 	if (irq < 0)
-		return dev_err_probe(pmic->dev, irq, "Failed to get parent vIRQ(%d) for chip %s\n",
+		return dev_err_probe(dev, irq, "Failed to get parent vIRQ(%d) for chip %s\n",
 				     pirq, chip->name);
 
-	return devm_regmap_add_irq_chip(pmic->dev, pmic->regmap, irq, irq_flags,
-					0, chip, data);
+	return devm_regmap_add_irq_chip(dev, pmic->regmap, irq, irq_flags, 0, chip, data);
 }
 
 static int bxtwc_add_chained_devices(struct intel_soc_pmic *pmic,
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#4 lore raw

PATCH 4/4 mfd: intel_soc_pmic_bxtwc: Deduplicate error messages

In reply to Andy Shevchenko

Move the individual error messages inside bxtwc_add_chained_irq_chip() in order to deduplicate them.

---
 drivers/mfd/intel_soc_pmic_bxtwc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/mfd/intel_soc_pmic_bxtwc.c +9 -5
index 5e6cffb162a0..cc4056a64dbd 100644
@@ -435,14 +435,18 @@ static int bxtwc_add_chained_irq_chip(struct intel_soc_pmic *pmic,
 				struct regmap_irq_chip_data **data)
 {
 	struct device *dev = pmic->dev;
-	int irq;
+	int irq, ret;
 
 	irq = regmap_irq_get_virq(pdata, pirq);
 	if (irq < 0)
 		return dev_err_probe(dev, irq, "Failed to get parent vIRQ(%d) for chip %s\n",
 				     pirq, chip->name);
 
-	return devm_regmap_add_irq_chip(dev, pmic->regmap, irq, irq_flags, 0, chip, data);
+	ret = devm_regmap_add_irq_chip(dev, pmic->regmap, irq, irq_flags, 0, chip, data);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to add %s IRQ chip\n", chip->name);
+
+	return 0;
 }
 
 static int bxtwc_add_chained_devices(struct intel_soc_pmic *pmic,
@@ -458,7 +462,7 @@ static int bxtwc_add_chained_devices(struct intel_soc_pmic *pmic,
 
 	ret = bxtwc_add_chained_irq_chip(pmic, pdata, pirq, irq_flags, chip, data);
 	if (ret)
-		return dev_err_probe(dev, ret, "Failed to add %s IRQ chip\n", chip->name);
+		return ret;
 
 	domain = regmap_irq_get_domain(*data);
 
@@ -521,7 +525,7 @@ static int bxtwc_probe(struct platform_device *pdev)
 					 &bxtwc_regmap_irq_chip_pwrbtn,
 					 &pmic->irq_chip_data_pwrbtn);
 	if (ret)
-		return dev_err_probe(dev, ret, "Failed to add PWRBTN IRQ chip\n");
+		return ret;
 
 	ret = bxtwc_add_chained_devices(pmic, bxt_wc_bcu_dev, ARRAY_SIZE(bxt_wc_bcu_dev),
 					pmic->irq_chip_data,
@@ -557,7 +561,7 @@ static int bxtwc_probe(struct platform_device *pdev)
 					 &bxtwc_regmap_irq_chip_crit,
 					 &pmic->irq_chip_data_crit);
 	if (ret)
-		return dev_err_probe(dev, ret, "Failed to add CRIT IRQ chip\n");
+		return ret;
 
 	ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, bxt_wc_dev, ARRAY_SIZE(bxt_wc_dev),
 				   NULL, 0, NULL);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Applied
#5 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

While working on the fixes series against the driver I have noticed some places that can be improved using better APIs or approaches. Hence this mini-series. The plus statistics is due to the patch 2 that brought missed inclusions to the code (instead of using a proxy header).

Have been tested on Intel Joule device.

[...]

Applied, thanks!

[1/4] mfd: intel_soc_pmic_bxtwc: Switch to use ATTRIBUTE_GROUPS()

      commit: 1f9e418aafc6ee52aad25b85f1e799f031f8de67
[2/4] mfd: intel_soc_pmic_bxtwc: Don't use "proxy" headers
      commit: d2e77347ce9a4d70165f4e97d6a4133e48e678cc
[3/4] mfd: intel_soc_pmic_bxtwc: Use temporary variable for struct device
      commit: 3d6b7374f0d8b5f8945185e901a6f5e7ae887a16
[4/4] mfd: intel_soc_pmic_bxtwc: Deduplicate error messages
      commit: 4a8b3d48dad2ddbbb150602606c65bef3c2b3f8e

--
Lee Jones [李琼斯]