forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/cs4270.c
....@@ -29,8 +29,8 @@
2929 #include <linux/i2c.h>
3030 #include <linux/delay.h>
3131 #include <linux/regulator/consumer.h>
32
+#include <linux/gpio/consumer.h>
3233 #include <linux/of_device.h>
33
-#include <linux/of_gpio.h>
3434
3535 /*
3636 * The codec isn't really big-endian or little-endian, since the I2S
....@@ -137,6 +137,9 @@
137137
138138 /* power domain regulators */
139139 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
140
+
141
+ /* reset gpio */
142
+ struct gpio_desc *reset_gpio;
140143 };
141144
142145 static const struct snd_soc_dapm_widget cs4270_dapm_widgets[] = {
....@@ -352,7 +355,7 @@
352355
353356 /* Set the sample rate */
354357
355
- reg = snd_soc_component_read32(component, CS4270_MODE);
358
+ reg = snd_soc_component_read(component, CS4270_MODE);
356359 reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
357360 reg |= cs4270_mode_ratios[i].mclk;
358361
....@@ -369,7 +372,7 @@
369372
370373 /* Set the DAI format */
371374
372
- reg = snd_soc_component_read32(component, CS4270_FORMAT);
375
+ reg = snd_soc_component_read(component, CS4270_FORMAT);
373376 reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
374377
375378 switch (cs4270->mode) {
....@@ -403,13 +406,13 @@
403406 * board does not have the MUTEA or MUTEB pins connected to such circuitry,
404407 * then this function will do nothing.
405408 */
406
-static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute)
409
+static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute, int direction)
407410 {
408411 struct snd_soc_component *component = dai->component;
409412 struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component);
410413 int reg6;
411414
412
- reg6 = snd_soc_component_read32(component, CS4270_MUTE);
415
+ reg6 = snd_soc_component_read(component, CS4270_MUTE);
413416
414417 if (mute)
415418 reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
....@@ -468,7 +471,8 @@
468471 .hw_params = cs4270_hw_params,
469472 .set_sysclk = cs4270_set_dai_sysclk,
470473 .set_fmt = cs4270_set_dai_fmt,
471
- .digital_mute = cs4270_dai_mute,
474
+ .mute_stream = cs4270_dai_mute,
475
+ .no_capture_mute = 1,
472476 };
473477
474478 static struct snd_soc_dai_driver cs4270_dai = {
....@@ -496,7 +500,7 @@
496500
497501 /**
498502 * cs4270_probe - ASoC probe function
499
- * @pdev: platform device
503
+ * @component: ASoC component
500504 *
501505 * This function is called when ASoC has all the pieces it needs to
502506 * instantiate a sound driver.
....@@ -537,7 +541,7 @@
537541
538542 /**
539543 * cs4270_remove - ASoC remove function
540
- * @pdev: platform device
544
+ * @component: ASoC component
541545 *
542546 * This function is the counterpart to cs4270_probe().
543547 */
....@@ -564,7 +568,7 @@
564568 struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component);
565569 int reg, ret;
566570
567
- reg = snd_soc_component_read32(component, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL;
571
+ reg = snd_soc_component_read(component, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL;
568572 if (reg < 0)
569573 return reg;
570574
....@@ -596,7 +600,7 @@
596600 regcache_sync(cs4270->regmap);
597601
598602 /* ... then disable the power-down bits */
599
- reg = snd_soc_component_read32(component, CS4270_PWRCTL);
603
+ reg = snd_soc_component_read(component, CS4270_PWRCTL);
600604 reg &= ~CS4270_PWRCTL_PDN_ALL;
601605
602606 return snd_soc_component_write(component, CS4270_PWRCTL, reg);
....@@ -649,6 +653,22 @@
649653 };
650654
651655 /**
656
+ * cs4270_i2c_remove - deinitialize the I2C interface of the CS4270
657
+ * @i2c_client: the I2C client object
658
+ *
659
+ * This function puts the chip into low power mode when the i2c device
660
+ * is removed.
661
+ */
662
+static int cs4270_i2c_remove(struct i2c_client *i2c_client)
663
+{
664
+ struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client);
665
+
666
+ gpiod_set_value_cansleep(cs4270->reset_gpio, 0);
667
+
668
+ return 0;
669
+}
670
+
671
+/**
652672 * cs4270_i2c_probe - initialize the I2C interface of the CS4270
653673 * @i2c_client: the I2C client object
654674 * @id: the I2C device ID (ignored)
....@@ -659,7 +679,6 @@
659679 static int cs4270_i2c_probe(struct i2c_client *i2c_client,
660680 const struct i2c_device_id *id)
661681 {
662
- struct device_node *np = i2c_client->dev.of_node;
663682 struct cs4270_private *cs4270;
664683 unsigned int val;
665684 int ret, i;
....@@ -679,20 +698,21 @@
679698 if (ret < 0)
680699 return ret;
681700
682
- /* See if we have a way to bring the codec out of reset */
683
- if (np) {
684
- enum of_gpio_flags flags;
685
- int gpio = of_get_named_gpio_flags(np, "reset-gpio", 0, &flags);
686
-
687
- if (gpio_is_valid(gpio)) {
688
- ret = devm_gpio_request_one(&i2c_client->dev, gpio,
689
- flags & OF_GPIO_ACTIVE_LOW ?
690
- GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
691
- "cs4270 reset");
692
- if (ret < 0)
693
- return ret;
694
- }
701
+ /* reset the device */
702
+ cs4270->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, "reset",
703
+ GPIOD_OUT_LOW);
704
+ if (IS_ERR(cs4270->reset_gpio)) {
705
+ dev_dbg(&i2c_client->dev, "Error getting CS4270 reset GPIO\n");
706
+ return PTR_ERR(cs4270->reset_gpio);
695707 }
708
+
709
+ if (cs4270->reset_gpio) {
710
+ dev_dbg(&i2c_client->dev, "Found reset GPIO\n");
711
+ gpiod_set_value_cansleep(cs4270->reset_gpio, 1);
712
+ }
713
+
714
+ /* Sleep 500ns before i2c communications */
715
+ ndelay(500);
696716
697717 cs4270->regmap = devm_regmap_init_i2c(i2c_client, &cs4270_regmap);
698718 if (IS_ERR(cs4270->regmap))
....@@ -745,6 +765,7 @@
745765 },
746766 .id_table = cs4270_id,
747767 .probe = cs4270_i2c_probe,
768
+ .remove = cs4270_i2c_remove,
748769 };
749770
750771 module_i2c_driver(cs4270_i2c_driver);