forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/codecs/cs42l42.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * cs42l42.c -- CS42L42 ALSA SoC audio driver
34 *
....@@ -6,11 +7,6 @@
67 * Author: James Schulman <james.schulman@cirrus.com>
78 * Author: Brian Austin <brian.austin@cirrus.com>
89 * Author: Michael White <michael.white@cirrus.com>
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License version 2 as
12
- * published by the Free Software Foundation.
13
- *
1410 */
1511
1612 #include <linux/module.h>
....@@ -24,10 +20,9 @@
2420 #include <linux/regmap.h>
2521 #include <linux/slab.h>
2622 #include <linux/platform_device.h>
23
+#include <linux/property.h>
2724 #include <linux/regulator/consumer.h>
2825 #include <linux/gpio/consumer.h>
29
-#include <linux/of.h>
30
-#include <linux/of_gpio.h>
3126 #include <linux/of_device.h>
3227 #include <sound/core.h>
3328 #include <sound/pcm.h>
....@@ -402,6 +397,9 @@
402397 .reg_defaults = cs42l42_reg_defaults,
403398 .num_reg_defaults = ARRAY_SIZE(cs42l42_reg_defaults),
404399 .cache_type = REGCACHE_RBTREE,
400
+
401
+ .use_single_read = true,
402
+ .use_single_write = true,
405403 };
406404
407405 static DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 100, true);
....@@ -837,7 +835,7 @@
837835 return 0;
838836 }
839837
840
-static int cs42l42_digital_mute(struct snd_soc_dai *dai, int mute)
838
+static int cs42l42_mute(struct snd_soc_dai *dai, int mute, int direction)
841839 {
842840 struct snd_soc_component *component = dai->component;
843841 unsigned int regval;
....@@ -865,7 +863,7 @@
865863 CS42L42_PLL_START_MASK,
866864 1 << CS42L42_PLL_START_SHIFT);
867865 /* Read the headphone load */
868
- regval = snd_soc_component_read32(component, CS42L42_LOAD_DET_RCSTAT);
866
+ regval = snd_soc_component_read(component, CS42L42_LOAD_DET_RCSTAT);
869867 if (((regval & CS42L42_RLA_STAT_MASK) >>
870868 CS42L42_RLA_STAT_SHIFT) == CS42L42_RLA_STAT_15_OHM) {
871869 fullScaleVol = CS42L42_HP_FULL_SCALE_VOL_MASK;
....@@ -897,7 +895,8 @@
897895 .hw_params = cs42l42_pcm_hw_params,
898896 .set_fmt = cs42l42_set_dai_fmt,
899897 .set_sysclk = cs42l42_set_sysclk,
900
- .digital_mute = cs42l42_digital_mute
898
+ .mute_stream = cs42l42_mute,
899
+ .no_capture_mute = 1,
901900 };
902901
903902 static struct snd_soc_dai_driver cs42l42_dai = {
....@@ -1530,12 +1529,15 @@
15301529 (1 << CS42L42_HS_CLAMP_DISABLE_SHIFT));
15311530
15321531 /* Enable the tip sense circuit */
1532
+ regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL,
1533
+ CS42L42_TS_INV_MASK, CS42L42_TS_INV_MASK);
1534
+
15331535 regmap_update_bits(cs42l42->regmap, CS42L42_TIPSENSE_CTL,
15341536 CS42L42_TIP_SENSE_CTRL_MASK |
15351537 CS42L42_TIP_SENSE_INV_MASK |
15361538 CS42L42_TIP_SENSE_DEBOUNCE_MASK,
15371539 (3 << CS42L42_TIP_SENSE_CTRL_SHIFT) |
1538
- (0 << CS42L42_TIP_SENSE_INV_SHIFT) |
1540
+ (!cs42l42->ts_inv << CS42L42_TIP_SENSE_INV_SHIFT) |
15391541 (2 << CS42L42_TIP_SENSE_DEBOUNCE_SHIFT));
15401542
15411543 /* Save the initial status of the tip sense */
....@@ -1554,17 +1556,15 @@
15541556 CS42L42_HS_DET_LEVEL_1
15551557 };
15561558
1557
-static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
1559
+static int cs42l42_handle_device_data(struct device *dev,
15581560 struct cs42l42_private *cs42l42)
15591561 {
1560
- struct device_node *np = i2c_client->dev.of_node;
15611562 unsigned int val;
1562
- unsigned int thresholds[CS42L42_NUM_BIASES];
1563
+ u32 thresholds[CS42L42_NUM_BIASES];
15631564 int ret;
15641565 int i;
15651566
1566
- ret = of_property_read_u32(np, "cirrus,ts-inv", &val);
1567
-
1567
+ ret = device_property_read_u32(dev, "cirrus,ts-inv", &val);
15681568 if (!ret) {
15691569 switch (val) {
15701570 case CS42L42_TS_INV_EN:
....@@ -1572,7 +1572,7 @@
15721572 cs42l42->ts_inv = val;
15731573 break;
15741574 default:
1575
- dev_err(&i2c_client->dev,
1575
+ dev_err(dev,
15761576 "Wrong cirrus,ts-inv DT value %d\n",
15771577 val);
15781578 cs42l42->ts_inv = CS42L42_TS_INV_DIS;
....@@ -1581,12 +1581,7 @@
15811581 cs42l42->ts_inv = CS42L42_TS_INV_DIS;
15821582 }
15831583
1584
- regmap_update_bits(cs42l42->regmap, CS42L42_TSENSE_CTL,
1585
- CS42L42_TS_INV_MASK,
1586
- (cs42l42->ts_inv << CS42L42_TS_INV_SHIFT));
1587
-
1588
- ret = of_property_read_u32(np, "cirrus,ts-dbnc-rise", &val);
1589
-
1584
+ ret = device_property_read_u32(dev, "cirrus,ts-dbnc-rise", &val);
15901585 if (!ret) {
15911586 switch (val) {
15921587 case CS42L42_TS_DBNCE_0:
....@@ -1600,7 +1595,7 @@
16001595 cs42l42->ts_dbnc_rise = val;
16011596 break;
16021597 default:
1603
- dev_err(&i2c_client->dev,
1598
+ dev_err(dev,
16041599 "Wrong cirrus,ts-dbnc-rise DT value %d\n",
16051600 val);
16061601 cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000;
....@@ -1614,8 +1609,7 @@
16141609 (cs42l42->ts_dbnc_rise <<
16151610 CS42L42_TS_RISE_DBNCE_TIME_SHIFT));
16161611
1617
- ret = of_property_read_u32(np, "cirrus,ts-dbnc-fall", &val);
1618
-
1612
+ ret = device_property_read_u32(dev, "cirrus,ts-dbnc-fall", &val);
16191613 if (!ret) {
16201614 switch (val) {
16211615 case CS42L42_TS_DBNCE_0:
....@@ -1629,7 +1623,7 @@
16291623 cs42l42->ts_dbnc_fall = val;
16301624 break;
16311625 default:
1632
- dev_err(&i2c_client->dev,
1626
+ dev_err(dev,
16331627 "Wrong cirrus,ts-dbnc-fall DT value %d\n",
16341628 val);
16351629 cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0;
....@@ -1643,14 +1637,12 @@
16431637 (cs42l42->ts_dbnc_fall <<
16441638 CS42L42_TS_FALL_DBNCE_TIME_SHIFT));
16451639
1646
- ret = of_property_read_u32(np, "cirrus,btn-det-init-dbnce", &val);
1647
-
1640
+ ret = device_property_read_u32(dev, "cirrus,btn-det-init-dbnce", &val);
16481641 if (!ret) {
1649
- if ((val >= CS42L42_BTN_DET_INIT_DBNCE_MIN) &&
1650
- (val <= CS42L42_BTN_DET_INIT_DBNCE_MAX))
1642
+ if (val <= CS42L42_BTN_DET_INIT_DBNCE_MAX)
16511643 cs42l42->btn_det_init_dbnce = val;
16521644 else {
1653
- dev_err(&i2c_client->dev,
1645
+ dev_err(dev,
16541646 "Wrong cirrus,btn-det-init-dbnce DT value %d\n",
16551647 val);
16561648 cs42l42->btn_det_init_dbnce =
....@@ -1661,15 +1653,13 @@
16611653 CS42L42_BTN_DET_INIT_DBNCE_DEFAULT;
16621654 }
16631655
1664
- ret = of_property_read_u32(np, "cirrus,btn-det-event-dbnce", &val);
1665
-
1656
+ ret = device_property_read_u32(dev, "cirrus,btn-det-event-dbnce", &val);
16661657 if (!ret) {
1667
- if ((val >= CS42L42_BTN_DET_EVENT_DBNCE_MIN) &&
1668
- (val <= CS42L42_BTN_DET_EVENT_DBNCE_MAX))
1658
+ if (val <= CS42L42_BTN_DET_EVENT_DBNCE_MAX)
16691659 cs42l42->btn_det_event_dbnce = val;
16701660 else {
1671
- dev_err(&i2c_client->dev,
1672
- "Wrong cirrus,btn-det-event-dbnce DT value %d\n", val);
1661
+ dev_err(dev,
1662
+ "Wrong cirrus,btn-det-event-dbnce DT value %d\n", val);
16731663 cs42l42->btn_det_event_dbnce =
16741664 CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
16751665 }
....@@ -1678,20 +1668,17 @@
16781668 CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
16791669 }
16801670
1681
- ret = of_property_read_u32_array(np, "cirrus,bias-lvls",
1682
- (u32 *)thresholds, CS42L42_NUM_BIASES);
1683
-
1671
+ ret = device_property_read_u32_array(dev, "cirrus,bias-lvls",
1672
+ thresholds, ARRAY_SIZE(thresholds));
16841673 if (!ret) {
16851674 for (i = 0; i < CS42L42_NUM_BIASES; i++) {
1686
- if ((thresholds[i] >= CS42L42_HS_DET_LEVEL_MIN) &&
1687
- (thresholds[i] <= CS42L42_HS_DET_LEVEL_MAX))
1675
+ if (thresholds[i] <= CS42L42_HS_DET_LEVEL_MAX)
16881676 cs42l42->bias_thresholds[i] = thresholds[i];
16891677 else {
1690
- dev_err(&i2c_client->dev,
1691
- "Wrong cirrus,bias-lvls[%d] DT value %d\n", i,
1678
+ dev_err(dev,
1679
+ "Wrong cirrus,bias-lvls[%d] DT value %d\n", i,
16921680 thresholds[i]);
1693
- cs42l42->bias_thresholds[i] =
1694
- threshold_defaults[i];
1681
+ cs42l42->bias_thresholds[i] = threshold_defaults[i];
16951682 }
16961683 }
16971684 } else {
....@@ -1699,8 +1686,7 @@
16991686 cs42l42->bias_thresholds[i] = threshold_defaults[i];
17001687 }
17011688
1702
- ret = of_property_read_u32(np, "cirrus,hs-bias-ramp-rate", &val);
1703
-
1689
+ ret = device_property_read_u32(dev, "cirrus,hs-bias-ramp-rate", &val);
17041690 if (!ret) {
17051691 switch (val) {
17061692 case CS42L42_HSBIAS_RAMP_FAST_RISE_SLOW_FALL:
....@@ -1720,7 +1706,7 @@
17201706 cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3;
17211707 break;
17221708 default:
1723
- dev_err(&i2c_client->dev,
1709
+ dev_err(dev,
17241710 "Wrong cirrus,hs-bias-ramp-rate DT value %d\n",
17251711 val);
17261712 cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW;
....@@ -1784,8 +1770,10 @@
17841770 /* Reset the Device */
17851771 cs42l42->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
17861772 "reset", GPIOD_OUT_LOW);
1787
- if (IS_ERR(cs42l42->reset_gpio))
1788
- return PTR_ERR(cs42l42->reset_gpio);
1773
+ if (IS_ERR(cs42l42->reset_gpio)) {
1774
+ ret = PTR_ERR(cs42l42->reset_gpio);
1775
+ goto err_disable;
1776
+ }
17891777
17901778 if (cs42l42->reset_gpio) {
17911779 dev_dbg(&i2c_client->dev, "Found reset GPIO\n");
....@@ -1820,13 +1808,13 @@
18201808 dev_err(&i2c_client->dev,
18211809 "CS42L42 Device ID (%X). Expected %X\n",
18221810 devid, CS42L42_CHIP_ID);
1823
- return ret;
1811
+ goto err_disable;
18241812 }
18251813
18261814 ret = regmap_read(cs42l42->regmap, CS42L42_REVID, &reg);
18271815 if (ret < 0) {
18281816 dev_err(&i2c_client->dev, "Get Revision ID failed\n");
1829
- return ret;
1817
+ goto err_disable;
18301818 }
18311819
18321820 dev_info(&i2c_client->dev,
....@@ -1849,11 +1837,9 @@
18491837 (1 << CS42L42_ADC_PDN_SHIFT) |
18501838 (0 << CS42L42_PDN_ALL_SHIFT));
18511839
1852
- if (i2c_client->dev.of_node) {
1853
- ret = cs42l42_handle_device_data(i2c_client, cs42l42);
1854
- if (ret != 0)
1855
- return ret;
1856
- }
1840
+ ret = cs42l42_handle_device_data(&i2c_client->dev, cs42l42);
1841
+ if (ret != 0)
1842
+ goto err_disable;
18571843
18581844 /* Setup headset detection */
18591845 cs42l42_setup_hs_type_detect(cs42l42);