forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/es7202.c
....@@ -21,6 +21,7 @@
2121 #include <linux/delay.h>
2222 #include <linux/pm.h>
2323 #include <linux/i2c.h>
24
+#include <linux/regulator/consumer.h>
2425 #include <linux/spi/spi.h>
2526 #include <linux/platform_device.h>
2627 #include <linux/slab.h>
....@@ -50,6 +51,7 @@
5051 struct i2c_client *i2c;
5152
5253 unsigned int pwr_vdd_voltage;
54
+ struct regulator *vdd;
5355 int reset_gpio;
5456 bool reset_active_level;
5557 };
....@@ -72,8 +74,8 @@
7274 read_cmd[0] = reg;
7375 cmd_len = 1;
7476
75
- if (client->adapter == NULL)
76
- printk("es7202_read client->adapter==NULL\n");
77
+ if (!client || !client->adapter)
78
+ return -1;
7779
7880 ret = i2c_master_send(client, read_cmd, cmd_len);
7981 if (ret != cmd_len) {
....@@ -94,6 +96,9 @@
9496 {
9597 int ret = 0;
9698 u8 write_cmd[2] = { 0 };
99
+
100
+ if (!client || !client->adapter)
101
+ return -1;
97102
98103 write_cmd[0] = reg;
99104 write_cmd[1] = value;
....@@ -533,20 +538,24 @@
533538 #endif
534539 };
535540
536
-static int es7202_mute(struct snd_soc_dai *dai, int mute)
541
+static int es7202_mute(struct snd_soc_dai *dai, int mute, int stream)
537542 {
543
+ if (stream == SNDRV_PCM_STREAM_PLAYBACK)
544
+ return 0;
545
+
538546 if (mute) {
539547 es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
540
- } else if (dai->playback_active) {
541
- es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00);
548
+ } else {
549
+ es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00);
542550 }
551
+
543552 return 0;
544553 }
545554
546555 #define es7202_RATES SNDRV_PCM_RATE_8000_96000
547556
548557 static struct snd_soc_dai_ops es7202_ops = {
549
- .digital_mute = es7202_mute,
558
+ .mute_stream = es7202_mute,
550559 };
551560 #if ES7202_CHANNELS_MAX > 0
552561 static struct snd_soc_dai_driver es7202_dai0 = {
....@@ -554,7 +563,7 @@
554563 .capture = {
555564 .stream_name = "Capture",
556565 .channels_min = 1,
557
- .channels_max = 2,
566
+ .channels_max = 8,
558567 .rates = es7202_RATES,
559568 .formats = SNDRV_PCM_FMTBIT_S16_LE,
560569 },
....@@ -568,7 +577,7 @@
568577 .capture = {
569578 .stream_name = "Capture",
570579 .channels_min = 1,
571
- .channels_max = 4,
580
+ .channels_max = 8,
572581 .rates = es7202_RATES,
573582 .formats = SNDRV_PCM_FMTBIT_S16_LE,
574583 },
....@@ -582,7 +591,7 @@
582591 .capture = {
583592 .stream_name = "Capture",
584593 .channels_min = 1,
585
- .channels_max = 6,
594
+ .channels_max = 8,
586595 .rates = es7202_RATES,
587596 .formats = SNDRV_PCM_FMTBIT_S16_LE,
588597 },
....@@ -835,66 +844,43 @@
835844 const struct i2c_device_id *id)
836845 {
837846 struct es7202_priv *es7202;
847
+ int uV;
838848 int ret = -1;
839
- //enum of_gpio_flags flags;
840
- //struct device_node *np = i2c->dev.of_node;
841
-
842
- printk("enter into %s()\n", __func__);
843
-
849
+
850
+ dev_info(&i2c->dev, "probe\n");
844851 es7202 = devm_kzalloc(&i2c->dev, sizeof(*es7202), GFP_KERNEL);
845852 if (!es7202)
846853 return -ENOMEM;
847
-
848854 es7202->i2c = i2c;
849
- es7202->pwr_vdd_voltage = ES7202_VDD_VOLTAGE;
850
-
855
+ es7202->vdd = devm_regulator_get_optional(&i2c->dev, "power");
856
+ if (IS_ERR(es7202->vdd)) {
857
+ if (PTR_ERR(es7202->vdd) == -EPROBE_DEFER)
858
+ return -EPROBE_DEFER;
859
+ dev_warn(&i2c->dev, "power-supply get fail, use 3v3 as default\n");
860
+ es7202->pwr_vdd_voltage = VDD_3V3;
861
+ } else {
862
+ uV = regulator_get_voltage(es7202->vdd);
863
+ dev_info(&i2c->dev, "probe power-supply %duV\n", uV);
864
+ if (uV <= MAX_VOLTAGE_1_8)
865
+ es7202->pwr_vdd_voltage = VDD_1V8;
866
+ else
867
+ es7202->pwr_vdd_voltage = VDD_3V3;
868
+ }
851869 dev_set_drvdata(&i2c->dev, es7202);
852870 if (id->driver_data < ADC_DEV_MAXNUM) {
853871 i2c_ctl[id->driver_data] = i2c;
854
- #if 0
855
- if(id->driver_data == 0) {
856
- es7202->reset_gpio = of_get_named_gpio_flags(np,
857
- "es7202-reset-gpio",
858
- 0,
859
- &flags);
860
- if (es7202->reset_gpio < 0) {
861
- dev_info(&i2c->dev,
862
- "Can not read property spk_ctl_gpio\n");
863
- es7202->reset_gpio = -1;
864
- } else {
865
- es7202->reset_active_level =
866
- !(flags & OF_GPIO_ACTIVE_LOW);
867
- ret = devm_gpio_request_one(&i2c->dev,
868
- es7202->reset_gpio,
869
- GPIOF_DIR_OUT,
870
- NULL);
871
- if (ret) {
872
- dev_err(&i2c->dev,
873
- "Failed to request spk_ctl_gpio\n");
874
- //return ret;
875
- } else {
876
- gpio_set_value(es7202->reset_gpio,
877
- es7202->reset_active_level);
878
- msleep(50);
879
- gpio_set_value(es7202->reset_gpio,
880
- !es7202->reset_active_level);
881
- }
882
- }
883
- }
884
-#endif
885
- printk("%s()-----1\n", __func__);
872
+ dev_info(&i2c->dev, "probe reigister es7202 dai(%s) component\n",
873
+ es7202_dai[id->driver_data]->name);
886874 ret = devm_snd_soc_register_component(&i2c->dev, &soc_codec_dev_es7202,
887
- es7202_dai[id->driver_data],
888
- 1);
875
+ es7202_dai[id->driver_data], 1);
889876 if (ret < 0) {
890877 return ret;
891
- }
878
+ }
892879 }
893880 ret = sysfs_create_group(&i2c->dev.kobj, &es7202_debug_attr_group);
894881 if (ret) {
895
- pr_err("failed to create attr group\n");
896
- }
897
-
882
+ dev_err(&i2c->dev, "failed to create attr group\n");
883
+ }
898884 return ret;
899885 }
900886