aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/da7210.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/da7210.c')
-rw-r--r--sound/soc/codecs/da7210.c146
1 files changed, 108 insertions, 38 deletions
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
index ab38e93c3543..7843711729bc 100644
--- a/sound/soc/codecs/da7210.c
+++ b/sound/soc/codecs/da7210.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/regmap.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
@@ -626,41 +627,82 @@ static const struct snd_soc_dapm_route da7210_audio_map[] = {
626 627
627/* Codec private data */ 628/* Codec private data */
628struct da7210_priv { 629struct da7210_priv {
629 enum snd_soc_control_type control_type; 630 struct regmap *regmap;
630}; 631};
631 632
632/* 633static struct reg_default da7210_reg_defaults[] = {
633 * Register cache 634 { 0x01, 0x11 },
634 */ 635 { 0x03, 0x00 },
635static const u8 da7210_reg[] = { 636 { 0x04, 0x00 },
636 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */ 637 { 0x05, 0x00 },
637 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */ 638 { 0x06, 0x00 },
638 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */ 639 { 0x07, 0x00 },
639 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */ 640 { 0x08, 0x00 },
640 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */ 641 { 0x09, 0x00 },
641 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */ 642 { 0x0a, 0x00 },
642 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */ 643 { 0x0b, 0x00 },
643 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */ 644 { 0x0c, 0x00 },
644 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */ 645 { 0x0d, 0x00 },
645 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */ 646 { 0x0e, 0x00 },
646 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */ 647 { 0x0f, 0x08 },
647 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */ 648 { 0x10, 0x00 },
648 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */ 649 { 0x11, 0x00 },
649 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */ 650 { 0x12, 0x00 },
650 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */ 651 { 0x13, 0x00 },
651 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */ 652 { 0x14, 0x08 },
652 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */ 653 { 0x15, 0x10 },
653 0x00, /* R88 */ 654 { 0x16, 0x10 },
655 { 0x17, 0x54 },
656 { 0x18, 0x40 },
657 { 0x19, 0x00 },
658 { 0x1a, 0x00 },
659 { 0x1b, 0x00 },
660 { 0x1c, 0x00 },
661 { 0x1d, 0x00 },
662 { 0x1e, 0x00 },
663 { 0x1f, 0x00 },
664 { 0x20, 0x00 },
665 { 0x21, 0x00 },
666 { 0x22, 0x00 },
667 { 0x23, 0x02 },
668 { 0x24, 0x00 },
669 { 0x25, 0x76 },
670 { 0x26, 0x00 },
671 { 0x27, 0x00 },
672 { 0x28, 0x04 },
673 { 0x29, 0x00 },
674 { 0x2a, 0x00 },
675 { 0x2b, 0x30 },
676 { 0x2c, 0x2A },
677 { 0x83, 0x00 },
678 { 0x84, 0x00 },
679 { 0x85, 0x00 },
680 { 0x86, 0x00 },
681 { 0x87, 0x00 },
682 { 0x88, 0x00 },
654}; 683};
655 684
656static int da7210_volatile_register(struct snd_soc_codec *codec, 685static bool da7210_readable_register(struct device *dev, unsigned int reg)
686{
687 switch (reg) {
688 case DA7210_A_HID_UNLOCK:
689 case DA7210_A_TEST_UNLOCK:
690 case DA7210_A_PLL1:
691 case DA7210_A_CP_MODE:
692 return false;
693 default:
694 return true;
695 }
696}
697
698static bool da7210_volatile_register(struct device *dev,
657 unsigned int reg) 699 unsigned int reg)
658{ 700{
659 switch (reg) { 701 switch (reg) {
660 case DA7210_STATUS: 702 case DA7210_STATUS:
661 return 1; 703 return true;
662 default: 704 default:
663 return 0; 705 return false;
664 } 706 }
665} 707}
666 708
@@ -866,7 +908,8 @@ static int da7210_probe(struct snd_soc_codec *codec)
866 908
867 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); 909 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
868 910
869 ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type); 911 codec->control_data = da7210->regmap;
912 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
870 if (ret < 0) { 913 if (ret < 0) {
871 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 914 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
872 return ret; 915 return ret;
@@ -983,12 +1026,14 @@ static int da7210_probe(struct snd_soc_codec *codec)
983 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); 1026 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
984 1027
985 /* As suggested by Dialog */ 1028 /* As suggested by Dialog */
986 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ 1029 /* unlock */
987 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); 1030 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x8B);
988 snd_soc_write(codec, DA7210_A_PLL1, 0x01); 1031 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0xB4);
989 snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C); 1032 regmap_write(da7210->regmap, DA7210_A_PLL1, 0x01);
990 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ 1033 regmap_write(da7210->regmap, DA7210_A_CP_MODE, 0x7C);
991 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00); 1034 /* re-lock */
1035 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x00);
1036 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0x00);
992 1037
993 /* Activate all enabled subsystem */ 1038 /* Activate all enabled subsystem */
994 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); 1039 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
@@ -1000,10 +1045,6 @@ static int da7210_probe(struct snd_soc_codec *codec)
1000 1045
1001static struct snd_soc_codec_driver soc_codec_dev_da7210 = { 1046static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
1002 .probe = da7210_probe, 1047 .probe = da7210_probe,
1003 .reg_cache_size = ARRAY_SIZE(da7210_reg),
1004 .reg_word_size = sizeof(u8),
1005 .reg_cache_default = da7210_reg,
1006 .volatile_register = da7210_volatile_register,
1007 1048
1008 .controls = da7210_snd_controls, 1049 .controls = da7210_snd_controls,
1009 .num_controls = ARRAY_SIZE(da7210_snd_controls), 1050 .num_controls = ARRAY_SIZE(da7210_snd_controls),
@@ -1014,6 +1055,17 @@ static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
1014 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), 1055 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
1015}; 1056};
1016 1057
1058static struct regmap_config da7210_regmap = {
1059 .reg_bits = 8,
1060 .val_bits = 8,
1061
1062 .reg_defaults = da7210_reg_defaults,
1063 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1064 .volatile_reg = da7210_volatile_register,
1065 .readable_reg = da7210_readable_register,
1066 .cache_type = REGCACHE_RBTREE,
1067};
1068
1017#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1069#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1018static int __devinit da7210_i2c_probe(struct i2c_client *i2c, 1070static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1019 const struct i2c_device_id *id) 1071 const struct i2c_device_id *id)
@@ -1027,16 +1079,34 @@ static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1027 return -ENOMEM; 1079 return -ENOMEM;
1028 1080
1029 i2c_set_clientdata(i2c, da7210); 1081 i2c_set_clientdata(i2c, da7210);
1030 da7210->control_type = SND_SOC_I2C; 1082
1083 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap);
1084 if (IS_ERR(da7210->regmap)) {
1085 ret = PTR_ERR(da7210->regmap);
1086 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1087 return ret;
1088 }
1031 1089
1032 ret = snd_soc_register_codec(&i2c->dev, 1090 ret = snd_soc_register_codec(&i2c->dev,
1033 &soc_codec_dev_da7210, &da7210_dai, 1); 1091 &soc_codec_dev_da7210, &da7210_dai, 1);
1092 if (ret < 0) {
1093 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1094 goto err_regmap;
1095 }
1096 return ret;
1097
1098err_regmap:
1099 regmap_exit(da7210->regmap);
1100
1034 return ret; 1101 return ret;
1035} 1102}
1036 1103
1037static int __devexit da7210_i2c_remove(struct i2c_client *client) 1104static int __devexit da7210_i2c_remove(struct i2c_client *client)
1038{ 1105{
1106 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1107
1039 snd_soc_unregister_codec(&client->dev); 1108 snd_soc_unregister_codec(&client->dev);
1109 regmap_exit(da7210->regmap);
1040 return 0; 1110 return 0;
1041} 1111}
1042 1112