forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/sta32x.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Codec driver for ST STA32x 2.1-channel high-efficiency digital audio system
34 *
....@@ -9,11 +10,6 @@
910 * Mark Brown <broonie@opensource.wolfsonmicro.com>
1011 * Freescale Semiconductor, Inc.
1112 * Timur Tabi <timur@freescale.com>
12
- *
13
- * This program is free software; you can redistribute it and/or modify it
14
- * under the terms of the GNU General Public License as published by the
15
- * Free Software Foundation; either version 2 of the License, or (at your
16
- * option) any later version.
1713 */
1814
1915 #define pr_fmt(fmt) KBUILD_MODNAME ":%s:%d: " fmt, __func__, __LINE__
....@@ -21,6 +17,7 @@
2117 #include <linux/module.h>
2218 #include <linux/moduleparam.h>
2319 #include <linux/init.h>
20
+#include <linux/clk.h>
2421 #include <linux/delay.h>
2522 #include <linux/pm.h>
2623 #include <linux/i2c.h>
....@@ -142,6 +139,7 @@
142139 /* codec private data */
143140 struct sta32x_priv {
144141 struct regmap *regmap;
142
+ struct clk *xti_clk;
145143 struct regulator_bulk_data supplies[ARRAY_SIZE(sta32x_supply_names)];
146144 struct snd_soc_component *component;
147145 struct sta32x_platform_data *pdata;
....@@ -399,9 +397,9 @@
399397 unsigned int confa, confa_cached;
400398
401399 /* check if sta32x has reset itself */
402
- confa_cached = snd_soc_component_read32(component, STA32X_CONFA);
400
+ confa_cached = snd_soc_component_read(component, STA32X_CONFA);
403401 regcache_cache_bypass(sta32x->regmap, true);
404
- confa = snd_soc_component_read32(component, STA32X_CONFA);
402
+ confa = snd_soc_component_read(component, STA32X_CONFA);
405403 regcache_cache_bypass(sta32x->regmap, false);
406404 if (confa != confa_cached) {
407405 regcache_mark_dirty(sta32x->regmap);
....@@ -699,7 +697,7 @@
699697 switch (params_width(params)) {
700698 case 24:
701699 dev_dbg(component->dev, "24bit\n");
702
- /* fall through */
700
+ fallthrough;
703701 case 32:
704702 dev_dbg(component->dev, "24bit or 32bit\n");
705703 switch (sta32x->format) {
....@@ -882,17 +880,26 @@
882880
883881 sta32x->component = component;
884882
883
+ if (sta32x->xti_clk) {
884
+ ret = clk_prepare_enable(sta32x->xti_clk);
885
+ if (ret != 0) {
886
+ dev_err(component->dev,
887
+ "Failed to enable clock: %d\n", ret);
888
+ return ret;
889
+ }
890
+ }
891
+
885892 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies),
886893 sta32x->supplies);
887894 if (ret != 0) {
888895 dev_err(component->dev, "Failed to enable supplies: %d\n", ret);
889
- return ret;
896
+ goto err_clk_disable_unprepare;
890897 }
891898
892899 ret = sta32x_startup_sequence(sta32x);
893900 if (ret < 0) {
894901 dev_err(component->dev, "Failed to startup device\n");
895
- return ret;
902
+ goto err_regulator_bulk_disable;
896903 }
897904
898905 /* CONFA */
....@@ -976,6 +983,13 @@
976983 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
977984
978985 return 0;
986
+
987
+err_regulator_bulk_disable:
988
+ regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
989
+err_clk_disable_unprepare:
990
+ if (sta32x->xti_clk)
991
+ clk_disable_unprepare(sta32x->xti_clk);
992
+ return ret;
979993 }
980994
981995 static void sta32x_remove(struct snd_soc_component *component)
....@@ -984,6 +998,9 @@
984998
985999 sta32x_watchdog_stop(sta32x);
9861000 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
1001
+
1002
+ if (sta32x->xti_clk)
1003
+ clk_disable_unprepare(sta32x->xti_clk);
9871004 }
9881005
9891006 static const struct snd_soc_component_driver sta32x_component = {
....@@ -1041,6 +1058,8 @@
10411058 of_property_read_u8(np, "st,ch3-output-mapping",
10421059 &pdata->ch3_output_mapping);
10431060
1061
+ if (of_get_property(np, "st,fault-detect-recovery", NULL))
1062
+ pdata->fault_detect_recovery = 1;
10441063 if (of_get_property(np, "st,thermal-warning-recovery", NULL))
10451064 pdata->thermal_warning_recovery = 1;
10461065 if (of_get_property(np, "st,thermal-warning-adjustment", NULL))
....@@ -1098,6 +1117,17 @@
10981117 }
10991118 #endif
11001119
1120
+ /* Clock */
1121
+ sta32x->xti_clk = devm_clk_get(dev, "xti");
1122
+ if (IS_ERR(sta32x->xti_clk)) {
1123
+ ret = PTR_ERR(sta32x->xti_clk);
1124
+
1125
+ if (ret == -EPROBE_DEFER)
1126
+ return ret;
1127
+
1128
+ sta32x->xti_clk = NULL;
1129
+ }
1130
+
11011131 /* GPIOs */
11021132 sta32x->gpiod_nreset = devm_gpiod_get_optional(dev, "reset",
11031133 GPIOD_OUT_LOW);