[PATCH v1 0/3] 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(-)
Instead of irq_domain_add_linear() that requires of_node, use irq_domain_create_linear() that works outside of OF world.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- sound/soc/codecs/rt5677.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index ad14d18860fc..4ef9c88cb20a 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -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");
On Thu, Jun 29, 2023 at 01:46:01PM +0300, Andy Shevchenko wrote:
Instead of irq_domain_add_linear() that requires of_node, use irq_domain_create_linear() that works outside of OF world.
...
- 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.
if (!rt5677->domain) { dev_err(&i2c->dev, "Failed to create IRQ domain\n");
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-U... 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.i... 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/202306300102.yMAJ3kZt-lkp@i...) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230630/202306300102.yMAJ3kZt-lkp@i...)
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 lkp@intel.com | Closes: https://lore.kernel.org/oe-kbuild-all/202306300102.yMAJ3kZt-lkp@intel.com/
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
Use device_get_match_data() to simplify the code.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- sound/soc/codecs/rt5677.c | 21 ++++----------------- sound/soc/codecs/rt5677.h | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-)
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 4ef9c88cb20a..4d09eb2a0755 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -6,7 +6,6 @@ * Author: Oder Chiou oder_chiou@realtek.com */
-#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, diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 944ae02aafc2..5ccdf1ba613a 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1753,8 +1753,8 @@ enum { };
enum rt5677_type { - RT5677, - RT5676, + RT5677 = 1, + RT5676 = 2, };
/* ASRC clock source selection */
On Thu, Jun 29, 2023 at 01:46:02PM +0300, Andy Shevchenko wrote:
- rt5677->type = (enum rt5677_type)(uintptr_t)device_get_match_data(dev);
Double casts, always a sign of a successful simplification! :P
- 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),
}, .probe = rt5677_i2c_probe, .remove = rt5677_i2c_remove,.acpi_match_table = rt5677_acpi_match,
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 944ae02aafc2..5ccdf1ba613a 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1753,8 +1753,8 @@ enum { };
enum rt5677_type {
- RT5677,
- RT5676,
- RT5677 = 1,
- RT5676 = 2,
};
/* ASRC clock source selection */
2.40.0.1.gaa8946217a0b
On Thu, Jun 29, 2023 at 11:56:10AM +0100, Mark Brown wrote:
On Thu, Jun 29, 2023 at 01:46:02PM +0300, Andy Shevchenko wrote:
...
- 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.
- 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.
It's hard to see what's included and what's not on the glance. Sort headers alphabetically to improve maintenance.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- sound/soc/codecs/rt5677.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 4d09eb2a0755..01595205c1d9 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -6,21 +6,21 @@ * Author: Oder Chiou oder_chiou@realtek.com */
+#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>
participants (3)
-
Andy Shevchenko
-
kernel test robot
-
Mark Brown