Skip to content

Commit

Permalink
ASoC: wm8731: Factor out the I2C and SPI bus code into separate modules
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Charles Keepax <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
broonie committed Apr 4, 2022
1 parent 8875d10 commit 9dc15f8
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 142 deletions.
4 changes: 2 additions & 2 deletions sound/soc/atmel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ config SND_ATMEL_SOC_SSC_DMA
config SND_AT91_SOC_SAM9G20_WM8731
tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board"
depends on ARCH_AT91 || COMPILE_TEST
depends on ATMEL_SSC && SND_SOC_I2C_AND_SPI
depends on ATMEL_SSC && I2C
select SND_ATMEL_SOC_SSC_PDC
select SND_SOC_WM8731
select SND_SOC_WM8731_I2C
help
Say Y if you want to add support for SoC audio on WM8731-based
AT91sam9g20 evaluation board.
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/au1x/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ config SND_SOC_DB1200
select SND_SOC_AC97_CODEC
select SND_SOC_WM9712
select SND_SOC_AU1XPSC_I2S
select SND_SOC_WM8731
select SND_SOC_WM8731_I2C
help
Select this option to enable audio (AC97 and I2S) on the
Alchemy/AMD/RMI/NetLogic Db1200, Db1550 and Db1300 evaluation boards.
Expand Down
18 changes: 15 additions & 3 deletions sound/soc/codecs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ config SND_SOC_ALL_CODECS
imply SND_SOC_WM8711
imply SND_SOC_WM8727
imply SND_SOC_WM8728
imply SND_SOC_WM8731
imply SND_SOC_WM8731_I2C
imply SND_SOC_WM8731_SPI
imply SND_SOC_WM8737
imply SND_SOC_WM8741
imply SND_SOC_WM8750
Expand Down Expand Up @@ -1753,8 +1754,19 @@ config SND_SOC_WM8728
depends on SND_SOC_I2C_AND_SPI

config SND_SOC_WM8731
tristate "Wolfson Microelectronics WM8731 CODEC"
depends on SND_SOC_I2C_AND_SPI
tristate

config SND_SOC_WM8731_I2C
tristate "Wolfson Microelectronics WM8731 CODEC with I2C"
depends on I2C
select REGMAP
select SND_SOC_WM8731

config SND_SOC_WM8731_SPI
tristate "Wolfson Microelectronics WM8731 CODEC with SPI"
depends on SPI
select REGMAP
select SND_SOC_WM8731

config SND_SOC_WM8737
tristate "Wolfson Microelectronics WM8737 ADC"
Expand Down
4 changes: 4 additions & 0 deletions sound/soc/codecs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ snd-soc-wm8711-objs := wm8711.o
snd-soc-wm8727-objs := wm8727.o
snd-soc-wm8728-objs := wm8728.o
snd-soc-wm8731-objs := wm8731.o
snd-soc-wm8731-i2c-objs := wm8731-i2c.o
snd-soc-wm8731-spi-objs := wm8731-spi.o
snd-soc-wm8737-objs := wm8737.o
snd-soc-wm8741-objs := wm8741.o
snd-soc-wm8750-objs := wm8750.o
Expand Down Expand Up @@ -632,6 +634,8 @@ obj-$(CONFIG_SND_SOC_WM8711) += snd-soc-wm8711.o
obj-$(CONFIG_SND_SOC_WM8727) += snd-soc-wm8727.o
obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o
obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
obj-$(CONFIG_SND_SOC_WM8731_I2C) += snd-soc-wm8731-i2c.o
obj-$(CONFIG_SND_SOC_WM8731_SPI) += snd-soc-wm8731-spi.o
obj-$(CONFIG_SND_SOC_WM8737) += snd-soc-wm8737.o
obj-$(CONFIG_SND_SOC_WM8741) += snd-soc-wm8741.o
obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
Expand Down
69 changes: 69 additions & 0 deletions sound/soc/codecs/wm8731-i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* wm8731-i2c.c -- WM8731 ALSA SoC Audio driver I2C code
*
* Copyright 2005 Openedhand Ltd.
* Copyright 2006-12 Wolfson Microelectronics, plc
*
* Author: Richard Purdie <[email protected]>
*
* Based on wm8753.c by Liam Girdwood
*/

#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/of_device.h>

#include "wm8731.h"


static const struct of_device_id wm8731_of_match[] = {
{ .compatible = "wlf,wm8731", },
{ }
};
MODULE_DEVICE_TABLE(of, wm8731_of_match);

static int wm8731_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct wm8731_priv *wm8731;
int ret;

wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv),
GFP_KERNEL);
if (wm8731 == NULL)
return -ENOMEM;

i2c_set_clientdata(i2c, wm8731);

wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
if (IS_ERR(wm8731->regmap)) {
ret = PTR_ERR(wm8731->regmap);
dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
ret);
return ret;
}

return wm8731_init(&i2c->dev, wm8731);
}

static const struct i2c_device_id wm8731_i2c_id[] = {
{ "wm8731", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);

static struct i2c_driver wm8731_i2c_driver = {
.driver = {
.name = "wm8731",
.of_match_table = wm8731_of_match,
},
.probe = wm8731_i2c_probe,
.id_table = wm8731_i2c_id,
};

module_i2c_driver(wm8731_i2c_driver);

MODULE_DESCRIPTION("ASoC WM8731 driver - I2C");
MODULE_AUTHOR("Richard Purdie");
MODULE_LICENSE("GPL");
59 changes: 59 additions & 0 deletions sound/soc/codecs/wm8731-spi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* wm8731.c -- WM8731 ALSA SoC Audio driver
*
* Copyright 2005 Openedhand Ltd.
* Copyright 2006-12 Wolfson Microelectronics, plc
*
* Author: Richard Purdie <[email protected]>
*
* Based on wm8753.c by Liam Girdwood
*/

#include <linux/spi/spi.h>
#include <linux/module.h>
#include <linux/of_device.h>

#include "wm8731.h"

static const struct of_device_id wm8731_of_match[] = {
{ .compatible = "wlf,wm8731", },
{ }
};
MODULE_DEVICE_TABLE(of, wm8731_of_match);

static int wm8731_spi_probe(struct spi_device *spi)
{
struct wm8731_priv *wm8731;
int ret;

wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL);
if (wm8731 == NULL)
return -ENOMEM;

spi_set_drvdata(spi, wm8731);

wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
if (IS_ERR(wm8731->regmap)) {
ret = PTR_ERR(wm8731->regmap);
dev_err(&spi->dev, "Failed to allocate register map: %d\n",
ret);
return ret;
}

return wm8731_init(&spi->dev, wm8731);
}

static struct spi_driver wm8731_spi_driver = {
.driver = {
.name = "wm8731",
.of_match_table = wm8731_of_match,
},
.probe = wm8731_spi_probe,
};

module_spi_driver(wm8731_spi_driver);

MODULE_DESCRIPTION("ASoC WM8731 driver - SPI");
MODULE_AUTHOR("Richard Purdie");
MODULE_LICENSE("GPL");
138 changes: 4 additions & 134 deletions sound/soc/codecs/wm8731.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
#include <linux/of_device.h>
#include <linux/mutex.h>
#include <linux/clk.h>
#include <sound/core.h>
#include <sound/pcm.h>
Expand All @@ -32,29 +28,13 @@

#include "wm8731.h"

#define WM8731_NUM_SUPPLIES 4
static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
"AVDD",
"HPVDD",
"DCVDD",
"DBVDD",
};

/* codec private data */
struct wm8731_priv {
struct regmap *regmap;
struct clk *mclk;
struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
const struct snd_pcm_hw_constraint_list *constraints;
unsigned int sysclk;
int sysclk_type;
int playback_fs;
bool deemph;

struct mutex lock;
};


/*
* wm8731 register cache
*/
Expand Down Expand Up @@ -584,7 +564,7 @@ static const struct snd_soc_component_driver soc_component_dev_wm8731 = {
.non_legacy_dai_naming = 1,
};

static int wm8731_init(struct device *dev, struct wm8731_priv *wm8731)
int wm8731_init(struct device *dev, struct wm8731_priv *wm8731)
{
int ret = 0, i;

Expand Down Expand Up @@ -654,15 +634,9 @@ static int wm8731_init(struct device *dev, struct wm8731_priv *wm8731)

return ret;
}
EXPORT_SYMBOL_GPL(wm8731_init);

static const struct of_device_id wm8731_of_match[] = {
{ .compatible = "wlf,wm8731", },
{ }
};

MODULE_DEVICE_TABLE(of, wm8731_of_match);

static const struct regmap_config wm8731_regmap = {
const struct regmap_config wm8731_regmap = {
.reg_bits = 7,
.val_bits = 9,

Expand All @@ -673,111 +647,7 @@ static const struct regmap_config wm8731_regmap = {
.reg_defaults = wm8731_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults),
};

#if defined(CONFIG_SPI_MASTER)
static int wm8731_spi_probe(struct spi_device *spi)
{
struct wm8731_priv *wm8731;
int ret;

wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL);
if (wm8731 == NULL)
return -ENOMEM;

spi_set_drvdata(spi, wm8731);

wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
if (IS_ERR(wm8731->regmap)) {
ret = PTR_ERR(wm8731->regmap);
dev_err(&spi->dev, "Failed to allocate register map: %d\n",
ret);
return ret;
}

return wm8731_init(&spi->dev, wm8731);
}

static struct spi_driver wm8731_spi_driver = {
.driver = {
.name = "wm8731",
.of_match_table = wm8731_of_match,
},
.probe = wm8731_spi_probe,
};
#endif /* CONFIG_SPI_MASTER */

#if IS_ENABLED(CONFIG_I2C)
static int wm8731_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct wm8731_priv *wm8731;
int ret;

wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv),
GFP_KERNEL);
if (wm8731 == NULL)
return -ENOMEM;

i2c_set_clientdata(i2c, wm8731);

wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
if (IS_ERR(wm8731->regmap)) {
ret = PTR_ERR(wm8731->regmap);
dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
ret);
return ret;
}

return wm8731_init(&i2c->dev, wm8731);
}

static const struct i2c_device_id wm8731_i2c_id[] = {
{ "wm8731", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);

static struct i2c_driver wm8731_i2c_driver = {
.driver = {
.name = "wm8731",
.of_match_table = wm8731_of_match,
},
.probe = wm8731_i2c_probe,
.id_table = wm8731_i2c_id,
};
#endif

static int __init wm8731_modinit(void)
{
int ret = 0;
#if IS_ENABLED(CONFIG_I2C)
ret = i2c_add_driver(&wm8731_i2c_driver);
if (ret != 0) {
printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n",
ret);
}
#endif
#if defined(CONFIG_SPI_MASTER)
ret = spi_register_driver(&wm8731_spi_driver);
if (ret != 0) {
printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n",
ret);
}
#endif
return ret;
}
module_init(wm8731_modinit);

static void __exit wm8731_exit(void)
{
#if IS_ENABLED(CONFIG_I2C)
i2c_del_driver(&wm8731_i2c_driver);
#endif
#if defined(CONFIG_SPI_MASTER)
spi_unregister_driver(&wm8731_spi_driver);
#endif
}
module_exit(wm8731_exit);
EXPORT_SYMBOL_GPL(wm8731_regmap);

MODULE_DESCRIPTION("ASoC WM8731 driver");
MODULE_AUTHOR("Richard Purdie");
Expand Down
Loading

0 comments on commit 9dc15f8

Please sign in to comment.