forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/rt5645.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * rt5645.c -- RT5645 ALSA SoC audio codec driver
34 *
45 * Copyright 2013 Realtek Semiconductor Corp.
56 * Author: Bard Liao <bardliao@realtek.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118
129 #include <linux/module.h>
....@@ -401,6 +398,11 @@
401398 unsigned short val;
402399 };
403400
401
+struct rt5645_eq_param_s_be16 {
402
+ __be16 reg;
403
+ __be16 val;
404
+};
405
+
404406 static const char *const rt5645_supply_names[] = {
405407 "avdd",
406408 "cpvdd",
....@@ -672,8 +674,8 @@
672674 {
673675 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
674676 struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
675
- struct rt5645_eq_param_s *eq_param =
676
- (struct rt5645_eq_param_s *)ucontrol->value.bytes.data;
677
+ struct rt5645_eq_param_s_be16 *eq_param =
678
+ (struct rt5645_eq_param_s_be16 *)ucontrol->value.bytes.data;
677679 int i;
678680
679681 for (i = 0; i < RT5645_HWEQ_NUM; i++) {
....@@ -698,35 +700,32 @@
698700 {
699701 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
700702 struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
701
- struct rt5645_eq_param_s *eq_param =
702
- (struct rt5645_eq_param_s *)ucontrol->value.bytes.data;
703
+ struct rt5645_eq_param_s_be16 *eq_param =
704
+ (struct rt5645_eq_param_s_be16 *)ucontrol->value.bytes.data;
703705 int i;
704706
705707 for (i = 0; i < RT5645_HWEQ_NUM; i++) {
706
- eq_param[i].reg = be16_to_cpu(eq_param[i].reg);
707
- eq_param[i].val = be16_to_cpu(eq_param[i].val);
708
+ rt5645->eq_param[i].reg = be16_to_cpu(eq_param[i].reg);
709
+ rt5645->eq_param[i].val = be16_to_cpu(eq_param[i].val);
708710 }
709711
710712 /* The final setting of the table should be RT5645_EQ_CTRL2 */
711713 for (i = RT5645_HWEQ_NUM - 1; i >= 0; i--) {
712
- if (eq_param[i].reg == 0)
714
+ if (rt5645->eq_param[i].reg == 0)
713715 continue;
714
- else if (eq_param[i].reg != RT5645_EQ_CTRL2)
716
+ else if (rt5645->eq_param[i].reg != RT5645_EQ_CTRL2)
715717 return 0;
716718 else
717719 break;
718720 }
719721
720722 for (i = 0; i < RT5645_HWEQ_NUM; i++) {
721
- if (!rt5645_validate_hweq(eq_param[i].reg) &&
722
- eq_param[i].reg != 0)
723
+ if (!rt5645_validate_hweq(rt5645->eq_param[i].reg) &&
724
+ rt5645->eq_param[i].reg != 0)
723725 return 0;
724
- else if (eq_param[i].reg == 0)
726
+ else if (rt5645->eq_param[i].reg == 0)
725727 break;
726728 }
727
-
728
- memcpy(rt5645->eq_param, eq_param,
729
- RT5645_HWEQ_NUM * sizeof(struct rt5645_eq_param_s));
730729
731730 return 0;
732731 }
....@@ -867,7 +866,7 @@
867866 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
868867 unsigned int val;
869868
870
- val = snd_soc_component_read32(component, RT5645_GLB_CLK);
869
+ val = snd_soc_component_read(component, RT5645_GLB_CLK);
871870 val &= RT5645_SCLK_SRC_MASK;
872871 if (val == RT5645_SCLK_SRC_PLL1)
873872 return 1;
....@@ -910,7 +909,7 @@
910909 return 0;
911910 }
912911
913
- val = (snd_soc_component_read32(component, reg) >> shift) & 0xf;
912
+ val = (snd_soc_component_read(component, reg) >> shift) & 0xf;
914913 switch (val) {
915914 case 1:
916915 case 2:
....@@ -1288,30 +1287,6 @@
12881287 static const struct snd_kcontrol_new rt5645_dac_r2_mux =
12891288 SOC_DAPM_ENUM("DAC2 R source", rt5645_dac2r_enum);
12901289
1291
-
1292
-/* INL/R source */
1293
-static const char * const rt5645_inl_src[] = {
1294
- "IN2P", "MonoP"
1295
-};
1296
-
1297
-static SOC_ENUM_SINGLE_DECL(
1298
- rt5645_inl_enum, RT5645_INL1_INR1_VOL,
1299
- RT5645_INL_SEL_SFT, rt5645_inl_src);
1300
-
1301
-static const struct snd_kcontrol_new rt5645_inl_mux =
1302
- SOC_DAPM_ENUM("INL source", rt5645_inl_enum);
1303
-
1304
-static const char * const rt5645_inr_src[] = {
1305
- "IN2N", "MonoN"
1306
-};
1307
-
1308
-static SOC_ENUM_SINGLE_DECL(
1309
- rt5645_inr_enum, RT5645_INL1_INR1_VOL,
1310
- RT5645_INR_SEL_SFT, rt5645_inr_src);
1311
-
1312
-static const struct snd_kcontrol_new rt5645_inr_mux =
1313
- SOC_DAPM_ENUM("INR source", rt5645_inr_enum);
1314
-
13151290 /* Stereo1 ADC source */
13161291 /* MX-27 [12] */
13171292 static const char * const rt5645_stereo_adc1_src[] = {
....@@ -1610,18 +1585,6 @@
16101585
16111586 static const struct snd_kcontrol_new rt5645_if2_adc_in_mux =
16121587 SOC_DAPM_ENUM("IF2 ADC IN source", rt5645_if2_adc_in_enum);
1613
-
1614
-/* MX-2F [1:0] */
1615
-static const char * const rt5645_if3_adc_in_src[] = {
1616
- "IF_ADC1", "IF_ADC2", "VAD_ADC"
1617
-};
1618
-
1619
-static SOC_ENUM_SINGLE_DECL(
1620
- rt5645_if3_adc_in_enum, RT5645_DIG_INF1_DATA,
1621
- RT5645_IF3_ADC_IN_SFT, rt5645_if3_adc_in_src);
1622
-
1623
-static const struct snd_kcontrol_new rt5645_if3_adc_in_mux =
1624
- SOC_DAPM_ENUM("IF3 ADC IN source", rt5645_if3_adc_in_enum);
16251588
16261589 /* MX-31 [15] [13] [11] [9] */
16271590 static const char * const rt5645_pdm_src[] = {
....@@ -3158,9 +3121,9 @@
31583121 RT5645_INT_IRQ_ST, 0x8, 0x8);
31593122 snd_soc_component_update_bits(component,
31603123 RT5650_4BTN_IL_CMD2, 0x8000, 0x8000);
3161
- snd_soc_component_read32(component, RT5650_4BTN_IL_CMD1);
3124
+ snd_soc_component_read(component, RT5650_4BTN_IL_CMD1);
31623125 pr_debug("%s read %x = %x\n", __func__, RT5650_4BTN_IL_CMD1,
3163
- snd_soc_component_read32(component, RT5650_4BTN_IL_CMD1));
3126
+ snd_soc_component_read(component, RT5650_4BTN_IL_CMD1));
31643127 } else {
31653128 snd_soc_component_update_bits(component, RT5650_4BTN_IL_CMD2, 0x8000, 0x0);
31663129 snd_soc_component_update_bits(component, RT5645_INT_IRQ_ST, 0x8, 0x0);
....@@ -3253,7 +3216,7 @@
32533216 {
32543217 int btn_type, val;
32553218
3256
- val = snd_soc_component_read32(component, RT5650_4BTN_IL_CMD1);
3219
+ val = snd_soc_component_read(component, RT5650_4BTN_IL_CMD1);
32573220 pr_debug("val=0x%x\n", val);
32583221 btn_type = val & 0xfff0;
32593222 snd_soc_component_write(component, RT5650_4BTN_IL_CMD1, val);
....@@ -3308,10 +3271,10 @@
33083271 report, SND_JACK_MICROPHONE);
33093272 return;
33103273 case 4:
3311
- val = snd_soc_component_read32(rt5645->component, RT5645_A_JD_CTRL1) & 0x0020;
3274
+ val = snd_soc_component_read(rt5645->component, RT5645_A_JD_CTRL1) & 0x0020;
33123275 break;
33133276 default: /* read rt5645 jd1_1 status */
3314
- val = snd_soc_component_read32(rt5645->component, RT5645_INT_IRQ_ST) & 0x1000;
3277
+ val = snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x1000;
33153278 break;
33163279
33173280 }
....@@ -3321,7 +3284,7 @@
33213284 } else if (!val && rt5645->jack_type != 0) {
33223285 /* for push button and jack out */
33233286 btn_type = 0;
3324
- if (snd_soc_component_read32(rt5645->component, RT5645_INT_IRQ_ST) & 0x4) {
3287
+ if (snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x4) {
33253288 /* button pressed */
33263289 report = SND_JACK_HEADSET;
33273290 btn_type = rt5645_button_detect(rt5645->component);
....@@ -3456,6 +3419,9 @@
34563419 RT5645_HWEQ_NUM, sizeof(struct rt5645_eq_param_s),
34573420 GFP_KERNEL);
34583421
3422
+ if (!rt5645->eq_param)
3423
+ return -ENOMEM;
3424
+
34593425 return 0;
34603426 }
34613427
....@@ -3562,7 +3528,8 @@
35623528 static const struct regmap_config rt5645_regmap = {
35633529 .reg_bits = 8,
35643530 .val_bits = 16,
3565
- .use_single_rw = true,
3531
+ .use_single_read = true,
3532
+ .use_single_write = true,
35663533 .max_register = RT5645_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5645_ranges) *
35673534 RT5645_PR_SPACING),
35683535 .volatile_reg = rt5645_volatile_register,
....@@ -3578,7 +3545,8 @@
35783545 static const struct regmap_config rt5650_regmap = {
35793546 .reg_bits = 8,
35803547 .val_bits = 16,
3581
- .use_single_rw = true,
3548
+ .use_single_read = true,
3549
+ .use_single_write = true,
35823550 .max_register = RT5645_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5645_ranges) *
35833551 RT5645_PR_SPACING),
35843552 .volatile_reg = rt5645_volatile_register,
....@@ -3595,7 +3563,8 @@
35953563 .name="nocache",
35963564 .reg_bits = 8,
35973565 .val_bits = 16,
3598
- .use_single_rw = true,
3566
+ .use_single_read = true,
3567
+ .use_single_write = true,
35993568 .max_register = RT5645_VENDOR_ID2 + 1,
36003569 .cache_type = REGCACHE_NONE,
36013570 };
....@@ -3674,6 +3643,12 @@
36743643 static const struct rt5645_platform_data lattepanda_board_platform_data = {
36753644 .jd_mode = 2,
36763645 .inv_jd1_1 = true
3646
+};
3647
+
3648
+static const struct rt5645_platform_data kahlee_platform_data = {
3649
+ .dmic1_data_pin = RT5645_DMIC_DATA_GPIO5,
3650
+ .dmic2_data_pin = RT5645_DMIC_DATA_IN2P,
3651
+ .jd_mode = 3,
36773652 };
36783653
36793654 static const struct dmi_system_id dmi_platform_data[] = {
....@@ -3789,6 +3764,21 @@
37893764 DMI_EXACT_MATCH(DMI_BOARD_VERSION, "Default string"),
37903765 },
37913766 .driver_data = (void *)&lattepanda_board_platform_data,
3767
+ },
3768
+ {
3769
+ .ident = "Chrome Kahlee",
3770
+ .matches = {
3771
+ DMI_MATCH(DMI_PRODUCT_NAME, "Kahlee"),
3772
+ },
3773
+ .driver_data = (void *)&kahlee_platform_data,
3774
+ },
3775
+ {
3776
+ .ident = "Medion E1239T",
3777
+ .matches = {
3778
+ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MEDION"),
3779
+ DMI_MATCH(DMI_PRODUCT_NAME, "E1239T MD60568"),
3780
+ },
3781
+ .driver_data = (void *)&intel_braswell_platform_data,
37923782 },
37933783 { }
37943784 };
....@@ -4105,9 +4095,14 @@
41054095 if (i2c->irq)
41064096 free_irq(i2c->irq, rt5645);
41074097
4098
+ /*
4099
+ * Since the rt5645_btn_check_callback() can queue jack_detect_work,
4100
+ * the timer need to be delted first
4101
+ */
4102
+ del_timer_sync(&rt5645->btn_check_timer);
4103
+
41084104 cancel_delayed_work_sync(&rt5645->jack_detect_work);
41094105 cancel_delayed_work_sync(&rt5645->rcclock_work);
4110
- del_timer_sync(&rt5645->btn_check_timer);
41114106
41124107 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
41134108