Skip to content

Commit 4574cd9

Browse files
committed
ASoC: ak4642: Convert to direct regmap API usage
This moves us towards being able to remove the ASoC level I/O code which duplicates regmap functionality. Currently the only difference between the supported devices in the driver is the regmap so we can replace the CODEC driver selections with regmap selection instead. Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent a8ca52b commit 4574cd9

1 file changed

Lines changed: 59 additions & 54 deletions

File tree

‎sound/soc/codecs/ak4642.c‎

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/slab.h>
2929
#include <linux/of_device.h>
3030
#include <linux/module.h>
31+
#include <linux/regmap.h>
3132
#include <sound/soc.h>
3233
#include <sound/initval.h>
3334
#include <sound/tlv.h>
@@ -198,30 +199,30 @@ static const struct snd_soc_dapm_route ak4642_intercon[] = {
198199
/*
199200
* ak4642 register cache
200201
*/
201-
static const u8 ak4642_reg[] = {
202-
0x00, 0x00, 0x01, 0x00,
203-
0x02, 0x00, 0x00, 0x00,
204-
0xe1, 0xe1, 0x18, 0x00,
205-
0xe1, 0x18, 0x11, 0x08,
206-
0x00, 0x00, 0x00, 0x00,
207-
0x00, 0x00, 0x00, 0x00,
208-
0x00, 0x00, 0x00, 0x00,
209-
0x00, 0x00, 0x00, 0x00,
210-
0x00, 0x00, 0x00, 0x00,
211-
0x00,
202+
static const struct reg_default ak4642_reg[] = {
203+
{ 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 },
204+
{ 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
205+
{ 8, 0xe1 }, { 9, 0xe1 }, { 10, 0x18 }, { 11, 0x00 },
206+
{ 12, 0xe1 }, { 13, 0x18 }, { 14, 0x11 }, { 15, 0x08 },
207+
{ 16, 0x00 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x00 },
208+
{ 20, 0x00 }, { 21, 0x00 }, { 22, 0x00 }, { 23, 0x00 },
209+
{ 24, 0x00 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0x00 },
210+
{ 28, 0x00 }, { 29, 0x00 }, { 30, 0x00 }, { 31, 0x00 },
211+
{ 32, 0x00 }, { 33, 0x00 }, { 34, 0x00 }, { 35, 0x00 },
212+
{ 36, 0x00 },
212213
};
213214

214-
static const u8 ak4648_reg[] = {
215-
0x00, 0x00, 0x01, 0x00,
216-
0x02, 0x00, 0x00, 0x00,
217-
0xe1, 0xe1, 0x18, 0x00,
218-
0xe1, 0x18, 0x11, 0xb8,
219-
0x00, 0x00, 0x00, 0x00,
220-
0x00, 0x00, 0x00, 0x00,
221-
0x00, 0x00, 0x00, 0x00,
222-
0x00, 0x00, 0x00, 0x00,
223-
0x00, 0x00, 0x00, 0x00,
224-
0x00, 0x88, 0x88, 0x08,
215+
static const struct reg_default ak4648_reg[] = {
216+
{ 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 },
217+
{ 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
218+
{ 8, 0xe1 }, { 9, 0xe1 }, { 10, 0x18 }, { 11, 0x00 },
219+
{ 12, 0xe1 }, { 13, 0x18 }, { 14, 0x11 }, { 15, 0xb8 },
220+
{ 16, 0x00 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x00 },
221+
{ 20, 0x00 }, { 21, 0x00 }, { 22, 0x00 }, { 23, 0x00 },
222+
{ 24, 0x00 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0x00 },
223+
{ 28, 0x00 }, { 29, 0x00 }, { 30, 0x00 }, { 31, 0x00 },
224+
{ 32, 0x00 }, { 33, 0x00 }, { 34, 0x00 }, { 35, 0x00 },
225+
{ 36, 0x00 }, { 37, 0x88 }, { 38, 0x88 }, { 39, 0x08 },
225226
};
226227

227228
static int ak4642_dai_startup(struct snd_pcm_substream *substream,
@@ -454,7 +455,10 @@ static struct snd_soc_dai_driver ak4642_dai = {
454455

455456
static int ak4642_resume(struct snd_soc_codec *codec)
456457
{
457-
snd_soc_cache_sync(codec);
458+
struct regmap *regmap = dev_get_regmap(codec->dev, NULL);
459+
460+
regcache_mark_dirty(regmap);
461+
regcache_sync(regmap);
458462
return 0;
459463
}
460464

@@ -463,7 +467,7 @@ static int ak4642_probe(struct snd_soc_codec *codec)
463467
{
464468
int ret;
465469

466-
ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
470+
ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
467471
if (ret < 0) {
468472
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
469473
return ret;
@@ -485,9 +489,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
485489
.remove = ak4642_remove,
486490
.resume = ak4642_resume,
487491
.set_bias_level = ak4642_set_bias_level,
488-
.reg_cache_default = ak4642_reg, /* ak4642 reg */
489-
.reg_cache_size = ARRAY_SIZE(ak4642_reg), /* ak4642 reg */
490-
.reg_word_size = sizeof(u8),
491492
.controls = ak4642_snd_controls,
492493
.num_controls = ARRAY_SIZE(ak4642_snd_controls),
493494
.dapm_widgets = ak4642_dapm_widgets,
@@ -496,20 +497,20 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
496497
.num_dapm_routes = ARRAY_SIZE(ak4642_intercon),
497498
};
498499

499-
static struct snd_soc_codec_driver soc_codec_dev_ak4648 = {
500-
.probe = ak4642_probe,
501-
.remove = ak4642_remove,
502-
.resume = ak4642_resume,
503-
.set_bias_level = ak4642_set_bias_level,
504-
.reg_cache_default = ak4648_reg, /* ak4648 reg */
505-
.reg_cache_size = ARRAY_SIZE(ak4648_reg), /* ak4648 reg */
506-
.reg_word_size = sizeof(u8),
507-
.controls = ak4642_snd_controls,
508-
.num_controls = ARRAY_SIZE(ak4642_snd_controls),
509-
.dapm_widgets = ak4642_dapm_widgets,
510-
.num_dapm_widgets = ARRAY_SIZE(ak4642_dapm_widgets),
511-
.dapm_routes = ak4642_intercon,
512-
.num_dapm_routes = ARRAY_SIZE(ak4642_intercon),
500+
static const struct regmap_config ak4642_regmap = {
501+
.reg_bits = 8,
502+
.val_bits = 8,
503+
.max_register = ARRAY_SIZE(ak4642_reg) + 1,
504+
.reg_defaults = ak4642_reg,
505+
.num_reg_defaults = ARRAY_SIZE(ak4642_reg),
506+
};
507+
508+
static const struct regmap_config ak4648_regmap = {
509+
.reg_bits = 8,
510+
.val_bits = 8,
511+
.max_register = ARRAY_SIZE(ak4648_reg) + 1,
512+
.reg_defaults = ak4648_reg,
513+
.num_reg_defaults = ARRAY_SIZE(ak4648_reg),
513514
};
514515

515516
#if IS_ENABLED(CONFIG_I2C)
@@ -518,26 +519,30 @@ static int ak4642_i2c_probe(struct i2c_client *i2c,
518519
const struct i2c_device_id *id)
519520
{
520521
struct device_node *np = i2c->dev.of_node;
521-
const struct snd_soc_codec_driver *driver;
522+
const struct regmap_config *regmap_config = NULL;
523+
struct regmap *regmap;
522524

523-
driver = NULL;
524525
if (np) {
525526
const struct of_device_id *of_id;
526527

527528
of_id = of_match_device(ak4642_of_match, &i2c->dev);
528529
if (of_id)
529-
driver = of_id->data;
530+
regmap_config = of_id->data;
530531
} else {
531-
driver = (struct snd_soc_codec_driver *)id->driver_data;
532+
regmap_config = (const struct regmap_config *)id->driver_data;
532533
}
533534

534-
if (!driver) {
535-
dev_err(&i2c->dev, "no driver\n");
535+
if (!regmap_config) {
536+
dev_err(&i2c->dev, "Unknown device type\n");
536537
return -EINVAL;
537538
}
538539

540+
regmap = devm_regmap_init_i2c(i2c, regmap_config);
541+
if (IS_ERR(regmap))
542+
return PTR_ERR(regmap);
543+
539544
return snd_soc_register_codec(&i2c->dev,
540-
driver, &ak4642_dai, 1);
545+
&soc_codec_dev_ak4642, &ak4642_dai, 1);
541546
}
542547

543548
static int ak4642_i2c_remove(struct i2c_client *client)
@@ -547,17 +552,17 @@ static int ak4642_i2c_remove(struct i2c_client *client)
547552
}
548553

549554
static struct of_device_id ak4642_of_match[] = {
550-
{ .compatible = "asahi-kasei,ak4642", .data = &soc_codec_dev_ak4642},
551-
{ .compatible = "asahi-kasei,ak4643", .data = &soc_codec_dev_ak4642},
552-
{ .compatible = "asahi-kasei,ak4648", .data = &soc_codec_dev_ak4648},
555+
{ .compatible = "asahi-kasei,ak4642", .data = &ak4642_regmap},
556+
{ .compatible = "asahi-kasei,ak4643", .data = &ak4642_regmap},
557+
{ .compatible = "asahi-kasei,ak4648", .data = &ak4648_regmap},
553558
{},
554559
};
555560
MODULE_DEVICE_TABLE(of, ak4642_of_match);
556561

557562
static const struct i2c_device_id ak4642_i2c_id[] = {
558-
{ "ak4642", (kernel_ulong_t)&soc_codec_dev_ak4642 },
559-
{ "ak4643", (kernel_ulong_t)&soc_codec_dev_ak4642 },
560-
{ "ak4648", (kernel_ulong_t)&soc_codec_dev_ak4648 },
563+
{ "ak4642", (kernel_ulong_t)&ak4642_regmap },
564+
{ "ak4643", (kernel_ulong_t)&ak4642_regmap },
565+
{ "ak4648", (kernel_ulong_t)&ak4648_regmap },
561566
{ }
562567
};
563568
MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id);

0 commit comments

Comments
 (0)