Skip to contentSkip to conversation

ASoC: rt5677: Refactor to use device_get_match_data()

PATCH Superseded Andy Shevchenko 3 participants 8 messages Jun 29, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: rt5677: Refactor to use device_get_match_data()

The code can be simplified with device_get_match_data(). Besides that couple of additional changes, one for maintenance (patch 3) and one for making IRQ domain agnostic (not pinned to OF).

Andy Shevchenko (3):
ASoC: rt5677: Use agnostic irq_domain_create_linear()
ASoC: rt5677: Use device_get_match_data()
ASoC: rt5677: Sort headers alphabetically

 sound/soc/codecs/rt5677.c | 41 +++++++++++++--------------------------
 sound/soc/codecs/rt5677.h |  4 ++--
 2 files changed, 16 insertions(+), 29 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

PATCH 1/3 ASoC: rt5677: Use agnostic irq_domain_create_linear()

Instead of irq_domain_add_linear() that requires of_node, use irq_domain_create_linear() that works outside of OF world.

---
 sound/soc/codecs/rt5677.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt5677.c +1 -1
index ad14d18860fc..4ef9c88cb20a 100644
@@ -5539,7 +5539,7 @@ static int rt5677_init_irq(struct i2c_client *i2c)
 			RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_IRQ);
 
 	/* Ready to listen for interrupts */
-	rt5677->domain = irq_domain_add_linear(i2c->dev.of_node,
+	rt5677->domain = irq_domain_create_linear(dev_fwnode(i2c->dev),
 			RT5677_IRQ_NUM, &rt5677_domain_ops, rt5677);
 	if (!rt5677->domain) {
 		dev_err(&i2c->dev, "Failed to create IRQ domain\n");
Signature · 1 line
2.40.0.1.gaa8946217a0b
#2 lore raw

Re: [PATCH v1 1/3] ASoC: rt5677: Use agnostic irq_domain_create_linear()

Quoted 2 lines · Andy Shevchenko

Instead of irq_domain_add_linear() that requires of_node, use irq_domain_create_linear() that works outside of OF world.

...

sound/soc/codecs/rt5677.c static int rt5677_init_irq(struct i2c_client *i2c) · line 5543

Quoted 3 lines
sound/soc/codecs/rt5677.c +1 -1
-	rt5677->domain = irq_domain_add_linear(i2c->dev.of_node,
+	rt5677->domain = irq_domain_create_linear(dev_fwnode(i2c->dev),
 			RT5677_IRQ_NUM, &rt5677_domain_ops, rt5677);

Oops, this won't compile :-(
Seems I tried in another branch that has this module disabled.

Quoted 2 lines
sound/soc/codecs/rt5677.c +0 -0
 	if (!rt5677->domain) {
 		dev_err(&i2c->dev, "Failed to create IRQ domain\n");
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH v1 1/3] ASoC: rt5677: Use agnostic irq_domain_create_linear()

In reply to Andy Shevchenko
kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on linus/master v6.4 next-20230629] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/ASoC-rt5677-Use-agnostic-irq_domain_create_linear/20230629-184911
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20230629104603.88612-2-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/3] ASoC: rt5677: Use agnostic irq_domain_create_linear()
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230630/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230630/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/linux/acpi.h:16,

                    from sound/soc/codecs/rt5677.c:9:
   sound/soc/codecs/rt5677.c: In function 'rt5677_init_irq':
>> include/linux/property.h:38:18: error: '_Generic' selector of type 'struct device' is not compatible with any association
      38 |         _Generic((dev),                                                 \
         |                  ^
   sound/soc/codecs/rt5677.c:5542:51: note: in expansion of macro 'dev_fwnode'
    5542 |         rt5677->domain = irq_domain_create_linear(dev_fwnode(i2c->dev),
         |                                                   ^~~~~~~~~~

vim +38 include/linux/property.h

1b9863c6aa56d9 Suthikulpanit, Suravee 2015-10-28  34  
b295d484b97081 Andy Shevchenko        2022-10-04  35  const struct fwnode_handle *__dev_fwnode_const(const struct device *dev);
b295d484b97081 Andy Shevchenko        2022-10-04  36  struct fwnode_handle *__dev_fwnode(struct device *dev);
b295d484b97081 Andy Shevchenko        2022-10-04  37  #define dev_fwnode(dev)							\
b295d484b97081 Andy Shevchenko        2022-10-04 @38  	_Generic((dev),							\
b295d484b97081 Andy Shevchenko        2022-10-04  39  		 const struct device *: __dev_fwnode_const,	\
b295d484b97081 Andy Shevchenko        2022-10-04  40  		 struct device *: __dev_fwnode)(dev)
e44bb0cbdc8868 Sakari Ailus           2017-03-28  41  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

PATCH 2/3 ASoC: rt5677: Use device_get_match_data()

In reply to Andy Shevchenko

Use device_get_match_data() to simplify the code.

---
 sound/soc/codecs/rt5677.c | 21 ++++-----------------
 sound/soc/codecs/rt5677.h |  4 ++--
 2 files changed, 6 insertions(+), 19 deletions(-)
sound/soc/codecs/rt5677.c +4 -17
index 4ef9c88cb20a..4d09eb2a0755 100644
@@ -6,7 +6,6 @@
  * Author: Oder Chiou <[email protected]>
  */
 
-#include <linux/acpi.h>
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
@@ -18,7 +17,6 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/firmware.h>
-#include <linux/of_device.h>
 #include <linux/property.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
@@ -5559,6 +5557,7 @@ static int rt5677_init_irq(struct i2c_client *i2c)
 
 static int rt5677_i2c_probe(struct i2c_client *i2c)
 {
+	struct device *dev = &i2c->dev;
 	struct rt5677_priv *rt5677;
 	int ret;
 	unsigned int val;
@@ -5573,21 +5572,9 @@ static int rt5677_i2c_probe(struct i2c_client *i2c)
 	INIT_DELAYED_WORK(&rt5677->dsp_work, rt5677_dsp_work);
 	i2c_set_clientdata(i2c, rt5677);
 
-	if (i2c->dev.of_node) {
-		const struct of_device_id *match_id;
-
-		match_id = of_match_device(rt5677_of_match, &i2c->dev);
-		if (match_id)
-			rt5677->type = (enum rt5677_type)match_id->data;
-	} else if (ACPI_HANDLE(&i2c->dev)) {
-		const struct acpi_device_id *acpi_id;
-
-		acpi_id = acpi_match_device(rt5677_acpi_match, &i2c->dev);
-		if (acpi_id)
-			rt5677->type = (enum rt5677_type)acpi_id->driver_data;
-	} else {
+	rt5677->type = (enum rt5677_type)(uintptr_t)device_get_match_data(dev);
+	if (rt5677->type == 0)
 		return -EINVAL;
-	}
 
 	rt5677_read_device_properties(rt5677, &i2c->dev);
 
@@ -5702,7 +5689,7 @@ static struct i2c_driver rt5677_i2c_driver = {
 	.driver = {
 		.name = RT5677_DRV_NAME,
 		.of_match_table = rt5677_of_match,
-		.acpi_match_table = ACPI_PTR(rt5677_acpi_match),
+		.acpi_match_table = rt5677_acpi_match,
 	},
 	.probe    = rt5677_i2c_probe,
 	.remove   = rt5677_i2c_remove,
sound/soc/codecs/rt5677.h +2 -2
index 944ae02aafc2..5ccdf1ba613a 100644
@@ -1753,8 +1753,8 @@ enum {
 };
 
 enum rt5677_type {
-	RT5677,
-	RT5676,
+	RT5677 = 1,
+	RT5676 = 2,
 };
 
 /* ASRC clock source selection */
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer
#5 lore raw

Re: [PATCH v1 2/3] ASoC: rt5677: Use device_get_match_data()

sound/soc/codecs/rt5677.c static int rt5677_i2c_probe(struct i2c_client *i2c) · line 5575

Quoted 1 line · Andy Shevchenko
sound/soc/codecs/rt5677.c +1 -0
+	rt5677->type = (enum rt5677_type)(uintptr_t)device_get_match_data(dev);

Double casts, always a sign of a successful simplification! :P

Quoted 33 lines
sound/soc/codecs/rt5677.c +2 -2
+	if (rt5677->type == 0)
 		return -EINVAL;
-	}
 
 	rt5677_read_device_properties(rt5677, &i2c->dev);
@@ -5702,7 +5689,7 @@ static struct i2c_driver rt5677_i2c_driver = {
 	.driver = {
 		.name = RT5677_DRV_NAME,
 		.of_match_table = rt5677_of_match,
-		.acpi_match_table = ACPI_PTR(rt5677_acpi_match),
+		.acpi_match_table = rt5677_acpi_match,
 	},
 	.probe    = rt5677_i2c_probe,
 	.remove   = rt5677_i2c_remove,
sound/soc/codecs/rt5677.h +2 -2
index 944ae02aafc2..5ccdf1ba613a 100644
@@ -1753,8 +1753,8 @@ enum {
 };
 
 enum rt5677_type {
-	RT5677,
-	RT5676,
+	RT5677 = 1,
+	RT5676 = 2,
 };
 
 /* ASRC clock source selection */
Signature · 1 line
2.40.0.1.gaa8946217a0b
#6 lore raw

Re: [PATCH v1 2/3] ASoC: rt5677: Use device_get_match_data()

Quoted 1 line · Mark Brown

On Thu, Jun 29, 2023 at 01:46:02PM +0300, Andy Shevchenko wrote:

...

Quoted 3 lines

sound/soc/codecs/rt5677.c static int rt5677_i2c_probe(struct i2c_client *i2c) · line 5575

Quoted 1 line
sound/soc/codecs/rt5677.c +1 -0
+	rt5677->type = (enum rt5677_type)(uintptr_t)device_get_match_data(dev);

Double casts, always a sign of a successful simplification! :P

Unfortunate of the C language and use of plain numbers when pointers are required. :-( I feel your pain.

Quoted 3 lines

sound/soc/codecs/rt5677.c static int rt5677_i2c_probe(struct i2c_client *i2c) · line 5590

Quoted 3 lines
sound/soc/codecs/rt5677.c +1 -1
+	if (rt5677->type == 0)
 		return -EINVAL;
-	}

I would prefer to see in the ID table something like

	.compatible = "foo", .data = &codec[RT5677],

but in this driver it seems it will require quite a refactoring.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

PATCH 3/3 ASoC: rt5677: Sort headers alphabetically

In reply to Andy Shevchenko

It's hard to see what's included and what's not on the glance. Sort headers alphabetically to improve maintenance.

---
 sound/soc/codecs/rt5677.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
sound/soc/codecs/rt5677.c +9 -9
index 4d09eb2a0755..01595205c1d9 100644
@@ -6,21 +6,21 @@
  * Author: Oder Chiou <[email protected]>
  */
 
+#include <linux/delay.h>
+#include <linux/firmware.h>
 #include <linux/fs.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irqdomain.h>
+#include <linux/irq.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
-#include <linux/init.h>
-#include <linux/delay.h>
+#include <linux/platform_device.h>
 #include <linux/pm.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
-#include <linux/i2c.h>
-#include <linux/platform_device.h>
 #include <linux/spi/spi.h>
-#include <linux/firmware.h>
-#include <linux/property.h>
-#include <linux/irq.h>
-#include <linux/interrupt.h>
-#include <linux/irqdomain.h>
 #include <linux/workqueue.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
Signature · 1 line
2.40.0.1.gaa8946217a0b