Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: wm8731: Factor out the I2C and SPI bus code into separate modules

Placing both the I2C and SPI code in the same module causes problems with
mixes of modular and non-modular builds of the buses so it's generally bad
practice. As with other drivers split the bus code out of the WM8731 driver
into separate modules.

Signed-off-by: Mark Brown <broonie@kernel.org>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220325153121.1598494-6-broonie@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>

+183 -142
+2 -2
sound/soc/atmel/Kconfig
··· 42 42 config SND_AT91_SOC_SAM9G20_WM8731 43 43 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" 44 44 depends on ARCH_AT91 || COMPILE_TEST 45 - depends on ATMEL_SSC && SND_SOC_I2C_AND_SPI 45 + depends on ATMEL_SSC && I2C 46 46 select SND_ATMEL_SOC_SSC_PDC 47 - select SND_SOC_WM8731 47 + select SND_SOC_WM8731_I2C 48 48 help 49 49 Say Y if you want to add support for SoC audio on WM8731-based 50 50 AT91sam9g20 evaluation board.
+1 -1
sound/soc/au1x/Kconfig
··· 58 58 select SND_SOC_AC97_CODEC 59 59 select SND_SOC_WM9712 60 60 select SND_SOC_AU1XPSC_I2S 61 - select SND_SOC_WM8731 61 + select SND_SOC_WM8731_I2C 62 62 help 63 63 Select this option to enable audio (AC97 and I2S) on the 64 64 Alchemy/AMD/RMI/NetLogic Db1200, Db1550 and Db1300 evaluation boards.
+15 -3
sound/soc/codecs/Kconfig
··· 265 265 imply SND_SOC_WM8711 266 266 imply SND_SOC_WM8727 267 267 imply SND_SOC_WM8728 268 - imply SND_SOC_WM8731 268 + imply SND_SOC_WM8731_I2C 269 + imply SND_SOC_WM8731_SPI 269 270 imply SND_SOC_WM8737 270 271 imply SND_SOC_WM8741 271 272 imply SND_SOC_WM8750 ··· 1754 1753 depends on SND_SOC_I2C_AND_SPI 1755 1754 1756 1755 config SND_SOC_WM8731 1757 - tristate "Wolfson Microelectronics WM8731 CODEC" 1758 - depends on SND_SOC_I2C_AND_SPI 1756 + tristate 1757 + 1758 + config SND_SOC_WM8731_I2C 1759 + tristate "Wolfson Microelectronics WM8731 CODEC with I2C" 1760 + depends on I2C 1761 + select REGMAP 1762 + select SND_SOC_WM8731 1763 + 1764 + config SND_SOC_WM8731_SPI 1765 + tristate "Wolfson Microelectronics WM8731 CODEC with SPI" 1766 + depends on SPI 1767 + select REGMAP 1768 + select SND_SOC_WM8731 1759 1769 1760 1770 config SND_SOC_WM8737 1761 1771 tristate "Wolfson Microelectronics WM8737 ADC"
+4
sound/soc/codecs/Makefile
··· 290 290 snd-soc-wm8727-objs := wm8727.o 291 291 snd-soc-wm8728-objs := wm8728.o 292 292 snd-soc-wm8731-objs := wm8731.o 293 + snd-soc-wm8731-i2c-objs := wm8731-i2c.o 294 + snd-soc-wm8731-spi-objs := wm8731-spi.o 293 295 snd-soc-wm8737-objs := wm8737.o 294 296 snd-soc-wm8741-objs := wm8741.o 295 297 snd-soc-wm8750-objs := wm8750.o ··· 634 632 obj-$(CONFIG_SND_SOC_WM8727) += snd-soc-wm8727.o 635 633 obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o 636 634 obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o 635 + obj-$(CONFIG_SND_SOC_WM8731_I2C) += snd-soc-wm8731-i2c.o 636 + obj-$(CONFIG_SND_SOC_WM8731_SPI) += snd-soc-wm8731-spi.o 637 637 obj-$(CONFIG_SND_SOC_WM8737) += snd-soc-wm8737.o 638 638 obj-$(CONFIG_SND_SOC_WM8741) += snd-soc-wm8741.o 639 639 obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
+69
sound/soc/codecs/wm8731-i2c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * wm8731-i2c.c -- WM8731 ALSA SoC Audio driver I2C code 4 + * 5 + * Copyright 2005 Openedhand Ltd. 6 + * Copyright 2006-12 Wolfson Microelectronics, plc 7 + * 8 + * Author: Richard Purdie <richard@openedhand.com> 9 + * 10 + * Based on wm8753.c by Liam Girdwood 11 + */ 12 + 13 + #include <linux/i2c.h> 14 + #include <linux/module.h> 15 + #include <linux/of_device.h> 16 + 17 + #include "wm8731.h" 18 + 19 + 20 + static const struct of_device_id wm8731_of_match[] = { 21 + { .compatible = "wlf,wm8731", }, 22 + { } 23 + }; 24 + MODULE_DEVICE_TABLE(of, wm8731_of_match); 25 + 26 + static int wm8731_i2c_probe(struct i2c_client *i2c, 27 + const struct i2c_device_id *id) 28 + { 29 + struct wm8731_priv *wm8731; 30 + int ret; 31 + 32 + wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), 33 + GFP_KERNEL); 34 + if (wm8731 == NULL) 35 + return -ENOMEM; 36 + 37 + i2c_set_clientdata(i2c, wm8731); 38 + 39 + wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 40 + if (IS_ERR(wm8731->regmap)) { 41 + ret = PTR_ERR(wm8731->regmap); 42 + dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 43 + ret); 44 + return ret; 45 + } 46 + 47 + return wm8731_init(&i2c->dev, wm8731); 48 + } 49 + 50 + static const struct i2c_device_id wm8731_i2c_id[] = { 51 + { "wm8731", 0 }, 52 + { } 53 + }; 54 + MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); 55 + 56 + static struct i2c_driver wm8731_i2c_driver = { 57 + .driver = { 58 + .name = "wm8731", 59 + .of_match_table = wm8731_of_match, 60 + }, 61 + .probe = wm8731_i2c_probe, 62 + .id_table = wm8731_i2c_id, 63 + }; 64 + 65 + module_i2c_driver(wm8731_i2c_driver); 66 + 67 + MODULE_DESCRIPTION("ASoC WM8731 driver - I2C"); 68 + MODULE_AUTHOR("Richard Purdie"); 69 + MODULE_LICENSE("GPL");
+59
sound/soc/codecs/wm8731-spi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * wm8731.c -- WM8731 ALSA SoC Audio driver 4 + * 5 + * Copyright 2005 Openedhand Ltd. 6 + * Copyright 2006-12 Wolfson Microelectronics, plc 7 + * 8 + * Author: Richard Purdie <richard@openedhand.com> 9 + * 10 + * Based on wm8753.c by Liam Girdwood 11 + */ 12 + 13 + #include <linux/spi/spi.h> 14 + #include <linux/module.h> 15 + #include <linux/of_device.h> 16 + 17 + #include "wm8731.h" 18 + 19 + static const struct of_device_id wm8731_of_match[] = { 20 + { .compatible = "wlf,wm8731", }, 21 + { } 22 + }; 23 + MODULE_DEVICE_TABLE(of, wm8731_of_match); 24 + 25 + static int wm8731_spi_probe(struct spi_device *spi) 26 + { 27 + struct wm8731_priv *wm8731; 28 + int ret; 29 + 30 + wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); 31 + if (wm8731 == NULL) 32 + return -ENOMEM; 33 + 34 + spi_set_drvdata(spi, wm8731); 35 + 36 + wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 37 + if (IS_ERR(wm8731->regmap)) { 38 + ret = PTR_ERR(wm8731->regmap); 39 + dev_err(&spi->dev, "Failed to allocate register map: %d\n", 40 + ret); 41 + return ret; 42 + } 43 + 44 + return wm8731_init(&spi->dev, wm8731); 45 + } 46 + 47 + static struct spi_driver wm8731_spi_driver = { 48 + .driver = { 49 + .name = "wm8731", 50 + .of_match_table = wm8731_of_match, 51 + }, 52 + .probe = wm8731_spi_probe, 53 + }; 54 + 55 + module_spi_driver(wm8731_spi_driver); 56 + 57 + MODULE_DESCRIPTION("ASoC WM8731 driver - SPI"); 58 + MODULE_AUTHOR("Richard Purdie"); 59 + MODULE_LICENSE("GPL");
+4 -134
sound/soc/codecs/wm8731.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/delay.h> 17 17 #include <linux/pm.h> 18 - #include <linux/i2c.h> 19 18 #include <linux/slab.h> 20 19 #include <linux/regmap.h> 21 20 #include <linux/regulator/consumer.h> 22 - #include <linux/spi/spi.h> 23 - #include <linux/of_device.h> 24 - #include <linux/mutex.h> 25 21 #include <linux/clk.h> 26 22 #include <sound/core.h> 27 23 #include <sound/pcm.h> ··· 28 32 29 33 #include "wm8731.h" 30 34 31 - #define WM8731_NUM_SUPPLIES 4 32 35 static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { 33 36 "AVDD", 34 37 "HPVDD", 35 38 "DCVDD", 36 39 "DBVDD", 37 40 }; 38 - 39 - /* codec private data */ 40 - struct wm8731_priv { 41 - struct regmap *regmap; 42 - struct clk *mclk; 43 - struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 44 - const struct snd_pcm_hw_constraint_list *constraints; 45 - unsigned int sysclk; 46 - int sysclk_type; 47 - int playback_fs; 48 - bool deemph; 49 - 50 - struct mutex lock; 51 - }; 52 - 53 41 54 42 /* 55 43 * wm8731 register cache ··· 564 584 .non_legacy_dai_naming = 1, 565 585 }; 566 586 567 - static int wm8731_init(struct device *dev, struct wm8731_priv *wm8731) 587 + int wm8731_init(struct device *dev, struct wm8731_priv *wm8731) 568 588 { 569 589 int ret = 0, i; 570 590 ··· 634 654 635 655 return ret; 636 656 } 657 + EXPORT_SYMBOL_GPL(wm8731_init); 637 658 638 - static const struct of_device_id wm8731_of_match[] = { 639 - { .compatible = "wlf,wm8731", }, 640 - { } 641 - }; 642 - 643 - MODULE_DEVICE_TABLE(of, wm8731_of_match); 644 - 645 - static const struct regmap_config wm8731_regmap = { 659 + const struct regmap_config wm8731_regmap = { 646 660 .reg_bits = 7, 647 661 .val_bits = 9, 648 662 ··· 647 673 .reg_defaults = wm8731_reg_defaults, 648 674 .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults), 649 675 }; 650 - 651 - #if defined(CONFIG_SPI_MASTER) 652 - static int wm8731_spi_probe(struct spi_device *spi) 653 - { 654 - struct wm8731_priv *wm8731; 655 - int ret; 656 - 657 - wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); 658 - if (wm8731 == NULL) 659 - return -ENOMEM; 660 - 661 - spi_set_drvdata(spi, wm8731); 662 - 663 - wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 664 - if (IS_ERR(wm8731->regmap)) { 665 - ret = PTR_ERR(wm8731->regmap); 666 - dev_err(&spi->dev, "Failed to allocate register map: %d\n", 667 - ret); 668 - return ret; 669 - } 670 - 671 - return wm8731_init(&spi->dev, wm8731); 672 - } 673 - 674 - static struct spi_driver wm8731_spi_driver = { 675 - .driver = { 676 - .name = "wm8731", 677 - .of_match_table = wm8731_of_match, 678 - }, 679 - .probe = wm8731_spi_probe, 680 - }; 681 - #endif /* CONFIG_SPI_MASTER */ 682 - 683 - #if IS_ENABLED(CONFIG_I2C) 684 - static int wm8731_i2c_probe(struct i2c_client *i2c, 685 - const struct i2c_device_id *id) 686 - { 687 - struct wm8731_priv *wm8731; 688 - int ret; 689 - 690 - wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), 691 - GFP_KERNEL); 692 - if (wm8731 == NULL) 693 - return -ENOMEM; 694 - 695 - i2c_set_clientdata(i2c, wm8731); 696 - 697 - wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 698 - if (IS_ERR(wm8731->regmap)) { 699 - ret = PTR_ERR(wm8731->regmap); 700 - dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 701 - ret); 702 - return ret; 703 - } 704 - 705 - return wm8731_init(&i2c->dev, wm8731); 706 - } 707 - 708 - static const struct i2c_device_id wm8731_i2c_id[] = { 709 - { "wm8731", 0 }, 710 - { } 711 - }; 712 - MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); 713 - 714 - static struct i2c_driver wm8731_i2c_driver = { 715 - .driver = { 716 - .name = "wm8731", 717 - .of_match_table = wm8731_of_match, 718 - }, 719 - .probe = wm8731_i2c_probe, 720 - .id_table = wm8731_i2c_id, 721 - }; 722 - #endif 723 - 724 - static int __init wm8731_modinit(void) 725 - { 726 - int ret = 0; 727 - #if IS_ENABLED(CONFIG_I2C) 728 - ret = i2c_add_driver(&wm8731_i2c_driver); 729 - if (ret != 0) { 730 - printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n", 731 - ret); 732 - } 733 - #endif 734 - #if defined(CONFIG_SPI_MASTER) 735 - ret = spi_register_driver(&wm8731_spi_driver); 736 - if (ret != 0) { 737 - printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n", 738 - ret); 739 - } 740 - #endif 741 - return ret; 742 - } 743 - module_init(wm8731_modinit); 744 - 745 - static void __exit wm8731_exit(void) 746 - { 747 - #if IS_ENABLED(CONFIG_I2C) 748 - i2c_del_driver(&wm8731_i2c_driver); 749 - #endif 750 - #if defined(CONFIG_SPI_MASTER) 751 - spi_unregister_driver(&wm8731_spi_driver); 752 - #endif 753 - } 754 - module_exit(wm8731_exit); 676 + EXPORT_SYMBOL_GPL(wm8731_regmap); 755 677 756 678 MODULE_DESCRIPTION("ASoC WM8731 driver"); 757 679 MODULE_AUTHOR("Richard Purdie");
+27
sound/soc/codecs/wm8731.h
··· 12 12 #ifndef _WM8731_H 13 13 #define _WM8731_H 14 14 15 + #include <linux/mutex.h> 16 + #include <linux/regmap.h> 17 + #include <linux/regulator/consumer.h> 18 + 19 + struct clk; 20 + struct snd_pcm_hw_constraint_list; 21 + 15 22 /* WM8731 register space */ 16 23 17 24 #define WM8731_LINVOL 0x00 ··· 39 32 #define WM8731_SYSCLK_XTAL 1 40 33 41 34 #define WM8731_DAI 0 35 + 36 + #define WM8731_NUM_SUPPLIES 4 37 + 38 + /* codec private data */ 39 + struct wm8731_priv { 40 + struct regmap *regmap; 41 + struct clk *mclk; 42 + struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 43 + const struct snd_pcm_hw_constraint_list *constraints; 44 + unsigned int sysclk; 45 + int sysclk_type; 46 + int playback_fs; 47 + bool deemph; 48 + 49 + struct mutex lock; 50 + }; 51 + 52 + extern const struct regmap_config wm8731_regmap; 53 + 54 + int wm8731_init(struct device *dev, struct wm8731_priv *wm8731); 42 55 43 56 #endif
+2 -2
sound/soc/pxa/Kconfig
··· 45 45 tristate "SoC Audio support for Sharp Zaurus SL-C7x0" 46 46 depends on SND_PXA2XX_SOC && PXA_SHARP_C7xx && I2C 47 47 select SND_PXA2XX_SOC_I2S 48 - select SND_SOC_WM8731 48 + select SND_SOC_WM8731_I2C 49 49 help 50 50 Say Y if you want to add support for SoC audio on Sharp 51 51 Zaurus SL-C7x0 models (Corgi, Shepherd, Husky). ··· 71 71 tristate "SoC Audio support for Poodle" 72 72 depends on SND_PXA2XX_SOC && MACH_POODLE && I2C 73 73 select SND_PXA2XX_SOC_I2S 74 - select SND_SOC_WM8731 74 + select SND_SOC_WM8731_I2C 75 75 help 76 76 Say Y if you want to add support for SoC audio on Sharp 77 77 Zaurus SL-5600 model (Poodle).