~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/tfa989x.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/codecs/tfa989x.c (Version linux-6.12-rc7) and /sound/soc/codecs/tfa989x.c (Version linux-5.14.21)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * Copyright (C) 2021 Stephan Gerhold               3  * Copyright (C) 2021 Stephan Gerhold
  4  *                                                  4  *
  5  * Register definitions/sequences taken from v      5  * Register definitions/sequences taken from various tfa98xx kernel drivers:
  6  * Copyright (C) 2014-2020 NXP Semiconductors,      6  * Copyright (C) 2014-2020 NXP Semiconductors, All Rights Reserved.
  7  * Copyright (C) 2013 Sony Mobile Communicatio      7  * Copyright (C) 2013 Sony Mobile Communications Inc.
  8  */                                                 8  */
  9                                                     9 
 10 #include <linux/gpio/consumer.h>               << 
 11 #include <linux/i2c.h>                             10 #include <linux/i2c.h>
 12 #include <linux/module.h>                          11 #include <linux/module.h>
 13 #include <linux/regmap.h>                          12 #include <linux/regmap.h>
 14 #include <linux/regulator/consumer.h>              13 #include <linux/regulator/consumer.h>
 15 #include <sound/soc.h>                             14 #include <sound/soc.h>
 16                                                    15 
 17 #define TFA989X_STATUSREG               0x00       16 #define TFA989X_STATUSREG               0x00
 18 #define TFA989X_BATTERYVOLTAGE          0x01       17 #define TFA989X_BATTERYVOLTAGE          0x01
 19 #define TFA989X_TEMPERATURE             0x02       18 #define TFA989X_TEMPERATURE             0x02
 20 #define TFA989X_REVISIONNUMBER          0x03       19 #define TFA989X_REVISIONNUMBER          0x03
 21 #define TFA989X_REVISIONNUMBER_REV_MSK  GENMAS     20 #define TFA989X_REVISIONNUMBER_REV_MSK  GENMASK(7, 0)   /* device revision */
 22 #define TFA989X_I2SREG                  0x04       21 #define TFA989X_I2SREG                  0x04
 23 #define TFA989X_I2SREG_RCV              2      << 
 24 #define TFA989X_I2SREG_CHSA             6          22 #define TFA989X_I2SREG_CHSA             6       /* amplifier input select */
 25 #define TFA989X_I2SREG_CHSA_MSK         GENMAS     23 #define TFA989X_I2SREG_CHSA_MSK         GENMASK(7, 6)
 26 #define TFA989X_I2SREG_I2SSR            12         24 #define TFA989X_I2SREG_I2SSR            12      /* sample rate */
 27 #define TFA989X_I2SREG_I2SSR_MSK        GENMAS     25 #define TFA989X_I2SREG_I2SSR_MSK        GENMASK(15, 12)
 28 #define TFA989X_BAT_PROT                0x05       26 #define TFA989X_BAT_PROT                0x05
 29 #define TFA989X_AUDIO_CTR               0x06       27 #define TFA989X_AUDIO_CTR               0x06
 30 #define TFA989X_DCDCBOOST               0x07       28 #define TFA989X_DCDCBOOST               0x07
 31 #define TFA989X_SPKR_CALIBRATION        0x08       29 #define TFA989X_SPKR_CALIBRATION        0x08
 32 #define TFA989X_SYS_CTRL                0x09       30 #define TFA989X_SYS_CTRL                0x09
 33 #define TFA989X_SYS_CTRL_PWDN           0          31 #define TFA989X_SYS_CTRL_PWDN           0       /* power down */
 34 #define TFA989X_SYS_CTRL_I2CR           1          32 #define TFA989X_SYS_CTRL_I2CR           1       /* I2C reset */
 35 #define TFA989X_SYS_CTRL_CFE            2          33 #define TFA989X_SYS_CTRL_CFE            2       /* enable CoolFlux DSP */
 36 #define TFA989X_SYS_CTRL_AMPE           3          34 #define TFA989X_SYS_CTRL_AMPE           3       /* enable amplifier */
 37 #define TFA989X_SYS_CTRL_DCA            4          35 #define TFA989X_SYS_CTRL_DCA            4       /* enable boost */
 38 #define TFA989X_SYS_CTRL_SBSL           5          36 #define TFA989X_SYS_CTRL_SBSL           5       /* DSP configured */
 39 #define TFA989X_SYS_CTRL_AMPC           6          37 #define TFA989X_SYS_CTRL_AMPC           6       /* amplifier enabled by DSP */
 40 #define TFA989X_I2S_SEL_REG             0x0a       38 #define TFA989X_I2S_SEL_REG             0x0a
 41 #define TFA989X_I2S_SEL_REG_SPKR_MSK    GENMAS     39 #define TFA989X_I2S_SEL_REG_SPKR_MSK    GENMASK(10, 9)  /* speaker impedance */
 42 #define TFA989X_I2S_SEL_REG_DCFG_MSK    GENMAS     40 #define TFA989X_I2S_SEL_REG_DCFG_MSK    GENMASK(14, 11) /* DCDC compensation */
 43 #define TFA989X_HIDE_UNHIDE_KEY 0x40           << 
 44 #define TFA989X_PWM_CONTROL             0x41       41 #define TFA989X_PWM_CONTROL             0x41
 45 #define TFA989X_CURRENTSENSE1           0x46       42 #define TFA989X_CURRENTSENSE1           0x46
 46 #define TFA989X_CURRENTSENSE2           0x47       43 #define TFA989X_CURRENTSENSE2           0x47
 47 #define TFA989X_CURRENTSENSE3           0x48       44 #define TFA989X_CURRENTSENSE3           0x48
 48 #define TFA989X_CURRENTSENSE4           0x49       45 #define TFA989X_CURRENTSENSE4           0x49
 49                                                    46 
 50 #define TFA9890_REVISION                0x80   << 
 51 #define TFA9895_REVISION                0x12       47 #define TFA9895_REVISION                0x12
 52 #define TFA9897_REVISION                0x97       48 #define TFA9897_REVISION                0x97
 53                                                    49 
 54 struct tfa989x_rev {                               50 struct tfa989x_rev {
 55         unsigned int rev;                          51         unsigned int rev;
 56         int (*init)(struct regmap *regmap);        52         int (*init)(struct regmap *regmap);
 57 };                                                 53 };
 58                                                    54 
 59 struct tfa989x {                                   55 struct tfa989x {
 60         const struct tfa989x_rev *rev;         << 
 61         struct regulator *vddd_supply;             56         struct regulator *vddd_supply;
 62         struct gpio_desc *rcv_gpiod;           << 
 63 };                                                 57 };
 64                                                    58 
 65 static bool tfa989x_writeable_reg(struct devic     59 static bool tfa989x_writeable_reg(struct device *dev, unsigned int reg)
 66 {                                                  60 {
 67         return reg > TFA989X_REVISIONNUMBER;       61         return reg > TFA989X_REVISIONNUMBER;
 68 }                                                  62 }
 69                                                    63 
 70 static bool tfa989x_volatile_reg(struct device     64 static bool tfa989x_volatile_reg(struct device *dev, unsigned int reg)
 71 {                                                  65 {
 72         return reg < TFA989X_REVISIONNUMBER;       66         return reg < TFA989X_REVISIONNUMBER;
 73 }                                                  67 }
 74                                                    68 
 75 static const struct regmap_config tfa989x_regm     69 static const struct regmap_config tfa989x_regmap = {
 76         .reg_bits = 8,                             70         .reg_bits = 8,
 77         .val_bits = 16,                            71         .val_bits = 16,
 78                                                    72 
 79         .writeable_reg  = tfa989x_writeable_re     73         .writeable_reg  = tfa989x_writeable_reg,
 80         .volatile_reg   = tfa989x_volatile_reg     74         .volatile_reg   = tfa989x_volatile_reg,
 81         .cache_type     = REGCACHE_RBTREE,         75         .cache_type     = REGCACHE_RBTREE,
 82 };                                                 76 };
 83                                                    77 
 84 static const char * const chsa_text[] = { "Lef     78 static const char * const chsa_text[] = { "Left", "Right", /* "DSP" */ };
 85 static SOC_ENUM_SINGLE_DECL(chsa_enum, TFA989X     79 static SOC_ENUM_SINGLE_DECL(chsa_enum, TFA989X_I2SREG, TFA989X_I2SREG_CHSA, chsa_text);
 86 static const struct snd_kcontrol_new chsa_mux      80 static const struct snd_kcontrol_new chsa_mux = SOC_DAPM_ENUM("Amp Input", chsa_enum);
 87                                                    81 
 88 static const struct snd_soc_dapm_widget tfa989     82 static const struct snd_soc_dapm_widget tfa989x_dapm_widgets[] = {
 89         SND_SOC_DAPM_OUTPUT("OUT"),                83         SND_SOC_DAPM_OUTPUT("OUT"),
 90         SND_SOC_DAPM_SUPPLY("POWER", TFA989X_S     84         SND_SOC_DAPM_SUPPLY("POWER", TFA989X_SYS_CTRL, TFA989X_SYS_CTRL_PWDN, 1, NULL, 0),
 91         SND_SOC_DAPM_OUT_DRV("AMPE", TFA989X_S     85         SND_SOC_DAPM_OUT_DRV("AMPE", TFA989X_SYS_CTRL, TFA989X_SYS_CTRL_AMPE, 0, NULL, 0),
 92                                                    86 
 93         SND_SOC_DAPM_MUX("Amp Input", SND_SOC_     87         SND_SOC_DAPM_MUX("Amp Input", SND_SOC_NOPM, 0, 0, &chsa_mux),
 94         SND_SOC_DAPM_AIF_IN("AIFINL", "HiFi Pl     88         SND_SOC_DAPM_AIF_IN("AIFINL", "HiFi Playback", 0, SND_SOC_NOPM, 0, 0),
 95         SND_SOC_DAPM_AIF_IN("AIFINR", "HiFi Pl     89         SND_SOC_DAPM_AIF_IN("AIFINR", "HiFi Playback", 1, SND_SOC_NOPM, 0, 0),
 96 };                                                 90 };
 97                                                    91 
 98 static const struct snd_soc_dapm_route tfa989x     92 static const struct snd_soc_dapm_route tfa989x_dapm_routes[] = {
 99         {"OUT", NULL, "AMPE"},                     93         {"OUT", NULL, "AMPE"},
100         {"AMPE", NULL, "POWER"},                   94         {"AMPE", NULL, "POWER"},
101         {"AMPE", NULL, "Amp Input"},               95         {"AMPE", NULL, "Amp Input"},
102         {"Amp Input", "Left", "AIFINL"},           96         {"Amp Input", "Left", "AIFINL"},
103         {"Amp Input", "Right", "AIFINR"},          97         {"Amp Input", "Right", "AIFINR"},
104 };                                                 98 };
105                                                    99 
106 static int tfa989x_put_mode(struct snd_kcontro << 
107 {                                              << 
108         struct snd_soc_component *component =  << 
109         struct tfa989x *tfa989x = snd_soc_comp << 
110                                                << 
111         gpiod_set_value_cansleep(tfa989x->rcv_ << 
112                                                << 
113         return snd_soc_put_enum_double(kcontro << 
114 }                                              << 
115                                                << 
116 static const char * const mode_text[] = { "Spe << 
117 static SOC_ENUM_SINGLE_DECL(mode_enum, TFA989X << 
118 static const struct snd_kcontrol_new tfa989x_m << 
119         SOC_ENUM_EXT("Mode", mode_enum, snd_so << 
120 };                                             << 
121                                                << 
122 static int tfa989x_probe(struct snd_soc_compon << 
123 {                                              << 
124         struct tfa989x *tfa989x = snd_soc_comp << 
125                                                << 
126         if (tfa989x->rev->rev == TFA9897_REVIS << 
127                 return snd_soc_add_component_c << 
128                                                << 
129                                                << 
130         return 0;                              << 
131 }                                              << 
132                                                << 
133 static const struct snd_soc_component_driver t    100 static const struct snd_soc_component_driver tfa989x_component = {
134         .probe                  = tfa989x_prob << 
135         .dapm_widgets           = tfa989x_dapm    101         .dapm_widgets           = tfa989x_dapm_widgets,
136         .num_dapm_widgets       = ARRAY_SIZE(t    102         .num_dapm_widgets       = ARRAY_SIZE(tfa989x_dapm_widgets),
137         .dapm_routes            = tfa989x_dapm    103         .dapm_routes            = tfa989x_dapm_routes,
138         .num_dapm_routes        = ARRAY_SIZE(t    104         .num_dapm_routes        = ARRAY_SIZE(tfa989x_dapm_routes),
139         .use_pmdown_time        = 1,              105         .use_pmdown_time        = 1,
140         .endianness             = 1,              106         .endianness             = 1,
                                                   >> 107         .non_legacy_dai_naming  = 1,
141 };                                                108 };
142                                                   109 
143 static const unsigned int tfa989x_rates[] = {     110 static const unsigned int tfa989x_rates[] = {
144         8000, 11025, 12000, 16000, 22050, 2400    111         8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
145 };                                                112 };
146                                                   113 
147 static int tfa989x_find_sample_rate(unsigned i    114 static int tfa989x_find_sample_rate(unsigned int rate)
148 {                                                 115 {
149         int i;                                    116         int i;
150                                                   117 
151         for (i = 0; i < ARRAY_SIZE(tfa989x_rat    118         for (i = 0; i < ARRAY_SIZE(tfa989x_rates); ++i)
152                 if (tfa989x_rates[i] == rate)     119                 if (tfa989x_rates[i] == rate)
153                         return i;                 120                         return i;
154                                                   121 
155         return -EINVAL;                           122         return -EINVAL;
156 }                                                 123 }
157                                                   124 
158 static int tfa989x_hw_params(struct snd_pcm_su    125 static int tfa989x_hw_params(struct snd_pcm_substream *substream,
159                              struct snd_pcm_hw    126                              struct snd_pcm_hw_params *params,
160                              struct snd_soc_da    127                              struct snd_soc_dai *dai)
161 {                                                 128 {
162         struct snd_soc_component *component =     129         struct snd_soc_component *component = dai->component;
163         int sr;                                   130         int sr;
164                                                   131 
165         sr = tfa989x_find_sample_rate(params_r    132         sr = tfa989x_find_sample_rate(params_rate(params));
166         if (sr < 0)                               133         if (sr < 0)
167                 return sr;                        134                 return sr;
168                                                   135 
169         return snd_soc_component_update_bits(c    136         return snd_soc_component_update_bits(component, TFA989X_I2SREG,
170                                              T    137                                              TFA989X_I2SREG_I2SSR_MSK,
171                                              s    138                                              sr << TFA989X_I2SREG_I2SSR);
172 }                                                 139 }
173                                                   140 
174 static const struct snd_soc_dai_ops tfa989x_da    141 static const struct snd_soc_dai_ops tfa989x_dai_ops = {
175         .hw_params = tfa989x_hw_params,           142         .hw_params = tfa989x_hw_params,
176 };                                                143 };
177                                                   144 
178 static struct snd_soc_dai_driver tfa989x_dai =    145 static struct snd_soc_dai_driver tfa989x_dai = {
179         .name = "tfa989x-hifi",                   146         .name = "tfa989x-hifi",
180         .playback = {                             147         .playback = {
181                 .stream_name    = "HiFi Playba    148                 .stream_name    = "HiFi Playback",
182                 .formats        = SNDRV_PCM_FM    149                 .formats        = SNDRV_PCM_FMTBIT_S16_LE,
183                 .rates          = SNDRV_PCM_RA    150                 .rates          = SNDRV_PCM_RATE_8000_48000,
184                 .rate_min       = 8000,           151                 .rate_min       = 8000,
185                 .rate_max       = 48000,          152                 .rate_max       = 48000,
186                 .channels_min   = 1,              153                 .channels_min   = 1,
187                 .channels_max   = 2,              154                 .channels_max   = 2,
188         },                                        155         },
189         .ops = &tfa989x_dai_ops,                  156         .ops = &tfa989x_dai_ops,
190 };                                                157 };
191                                                   158 
192 static int tfa9890_init(struct regmap *regmap) << 
193 {                                              << 
194         int ret;                               << 
195                                                << 
196         /* temporarily allow access to hidden  << 
197         ret = regmap_write(regmap, TFA989X_HID << 
198         if (ret)                               << 
199                 return ret;                    << 
200                                                << 
201         /* update PLL registers */             << 
202         ret = regmap_set_bits(regmap, 0x59, 0x << 
203         if (ret)                               << 
204                 return ret;                    << 
205                                                << 
206         /* hide registers again */             << 
207         ret = regmap_write(regmap, TFA989X_HID << 
208         if (ret)                               << 
209                 return ret;                    << 
210                                                << 
211         return regmap_write(regmap, TFA989X_CU << 
212 }                                              << 
213                                                << 
214 static const struct tfa989x_rev tfa9890_rev =  << 
215         .rev    = TFA9890_REVISION,            << 
216         .init   = tfa9890_init,                << 
217 };                                             << 
218                                                << 
219 static const struct reg_sequence tfa9895_reg_i    159 static const struct reg_sequence tfa9895_reg_init[] = {
220         /* some other registers must be set fo    160         /* some other registers must be set for optimal amplifier behaviour */
221         { TFA989X_BAT_PROT, 0x13ab },             161         { TFA989X_BAT_PROT, 0x13ab },
222         { TFA989X_AUDIO_CTR, 0x001f },            162         { TFA989X_AUDIO_CTR, 0x001f },
223                                                   163 
224         /* peak voltage protection is always o    164         /* peak voltage protection is always on, but may be written */
225         { TFA989X_SPKR_CALIBRATION, 0x3c4e },     165         { TFA989X_SPKR_CALIBRATION, 0x3c4e },
226                                                   166 
227         /* TFA989X_SYSCTRL_DCA = 0 */             167         /* TFA989X_SYSCTRL_DCA = 0 */
228         { TFA989X_SYS_CTRL, 0x024d },             168         { TFA989X_SYS_CTRL, 0x024d },
229         { TFA989X_PWM_CONTROL, 0x0308 },          169         { TFA989X_PWM_CONTROL, 0x0308 },
230         { TFA989X_CURRENTSENSE4, 0x0e82 },        170         { TFA989X_CURRENTSENSE4, 0x0e82 },
231 };                                                171 };
232                                                   172 
233 static int tfa9895_init(struct regmap *regmap)    173 static int tfa9895_init(struct regmap *regmap)
234 {                                                 174 {
235         return regmap_multi_reg_write(regmap,     175         return regmap_multi_reg_write(regmap, tfa9895_reg_init,
236                                       ARRAY_SI    176                                       ARRAY_SIZE(tfa9895_reg_init));
237 }                                                 177 }
238                                                   178 
239 static const struct tfa989x_rev tfa9895_rev =     179 static const struct tfa989x_rev tfa9895_rev = {
240         .rev    = TFA9895_REVISION,               180         .rev    = TFA9895_REVISION,
241         .init   = tfa9895_init,                   181         .init   = tfa9895_init,
242 };                                                182 };
243                                                   183 
244 static int tfa9897_init(struct regmap *regmap)    184 static int tfa9897_init(struct regmap *regmap)
245 {                                                 185 {
246         int ret;                                  186         int ret;
247                                                   187 
248         /* Reduce slewrate by clearing iddqtes    188         /* Reduce slewrate by clearing iddqtestbst to avoid booster damage */
249         ret = regmap_write(regmap, TFA989X_CUR    189         ret = regmap_write(regmap, TFA989X_CURRENTSENSE3, 0x0300);
250         if (ret)                                  190         if (ret)
251                 return ret;                       191                 return ret;
252                                                   192 
253         /* Enable clipping */                     193         /* Enable clipping */
254         ret = regmap_clear_bits(regmap, TFA989    194         ret = regmap_clear_bits(regmap, TFA989X_CURRENTSENSE4, 0x1);
255         if (ret)                                  195         if (ret)
256                 return ret;                       196                 return ret;
257                                                   197 
258         /* Set required TDM configuration */      198         /* Set required TDM configuration */
259         return regmap_write(regmap, 0x14, 0x0)    199         return regmap_write(regmap, 0x14, 0x0);
260 }                                                 200 }
261                                                   201 
262 static const struct tfa989x_rev tfa9897_rev =     202 static const struct tfa989x_rev tfa9897_rev = {
263         .rev    = TFA9897_REVISION,               203         .rev    = TFA9897_REVISION,
264         .init   = tfa9897_init,                   204         .init   = tfa9897_init,
265 };                                                205 };
266                                                   206 
267 /*                                                207 /*
268  * Note: At the moment this driver bypasses th    208  * Note: At the moment this driver bypasses the "CoolFlux DSP" built into the
269  * TFA989X amplifiers. Unfortunately, there se    209  * TFA989X amplifiers. Unfortunately, there seems to be absolutely
270  * no documentation for it - the public "short    210  * no documentation for it - the public "short datasheets" do not provide
271  * any information about the DSP or available     211  * any information about the DSP or available registers.
272  *                                                212  *
273  * Usually the TFA989X amplifiers are configur    213  * Usually the TFA989X amplifiers are configured through proprietary userspace
274  * libraries. There are also some (rather comp    214  * libraries. There are also some (rather complex) kernel drivers but even those
275  * rely on obscure firmware blobs for configur    215  * rely on obscure firmware blobs for configuration (so-called "containers").
276  * They seem to contain different "profiles" w    216  * They seem to contain different "profiles" with tuned speaker settings, sample
277  * rates and volume steps (which would be bett    217  * rates and volume steps (which would be better exposed as separate ALSA mixers).
278  *                                                218  *
279  * Bypassing the DSP disables volume control (    219  * Bypassing the DSP disables volume control (and perhaps some speaker
280  * optimization?), but at least allows using t    220  * optimization?), but at least allows using the speaker without obscure
281  * kernel drivers and firmware.                   221  * kernel drivers and firmware.
282  *                                                222  *
283  * Ideally NXP (or now Goodix) should release     223  * Ideally NXP (or now Goodix) should release proper documentation for these
284  * amplifiers so that support for the "CoolFlu    224  * amplifiers so that support for the "CoolFlux DSP" can be implemented properly.
285  */                                               225  */
286 static int tfa989x_dsp_bypass(struct regmap *r    226 static int tfa989x_dsp_bypass(struct regmap *regmap)
287 {                                                 227 {
288         int ret;                                  228         int ret;
289                                                   229 
290         /* Clear CHSA to bypass DSP and take i    230         /* Clear CHSA to bypass DSP and take input from I2S 1 left channel */
291         ret = regmap_clear_bits(regmap, TFA989    231         ret = regmap_clear_bits(regmap, TFA989X_I2SREG, TFA989X_I2SREG_CHSA_MSK);
292         if (ret)                                  232         if (ret)
293                 return ret;                       233                 return ret;
294                                                   234 
295         /* Set DCDC compensation to off and sp    235         /* Set DCDC compensation to off and speaker impedance to 8 ohm */
296         ret = regmap_update_bits(regmap, TFA98    236         ret = regmap_update_bits(regmap, TFA989X_I2S_SEL_REG,
297                                  TFA989X_I2S_S    237                                  TFA989X_I2S_SEL_REG_DCFG_MSK |
298                                  TFA989X_I2S_S    238                                  TFA989X_I2S_SEL_REG_SPKR_MSK,
299                                  TFA989X_I2S_S    239                                  TFA989X_I2S_SEL_REG_SPKR_MSK);
300         if (ret)                                  240         if (ret)
301                 return ret;                       241                 return ret;
302                                                   242 
303         /* Set DCDC to follower mode and disab    243         /* Set DCDC to follower mode and disable CoolFlux DSP */
304         return regmap_clear_bits(regmap, TFA98    244         return regmap_clear_bits(regmap, TFA989X_SYS_CTRL,
305                                  BIT(TFA989X_S    245                                  BIT(TFA989X_SYS_CTRL_DCA) |
306                                  BIT(TFA989X_S    246                                  BIT(TFA989X_SYS_CTRL_CFE) |
307                                  BIT(TFA989X_S    247                                  BIT(TFA989X_SYS_CTRL_AMPC));
308 }                                                 248 }
309                                                   249 
310 static void tfa989x_regulator_disable(void *da    250 static void tfa989x_regulator_disable(void *data)
311 {                                                 251 {
312         struct tfa989x *tfa989x = data;           252         struct tfa989x *tfa989x = data;
313                                                   253 
314         regulator_disable(tfa989x->vddd_supply    254         regulator_disable(tfa989x->vddd_supply);
315 }                                                 255 }
316                                                   256 
317 static int tfa989x_i2c_probe(struct i2c_client    257 static int tfa989x_i2c_probe(struct i2c_client *i2c)
318 {                                                 258 {
319         struct device *dev = &i2c->dev;           259         struct device *dev = &i2c->dev;
320         const struct tfa989x_rev *rev;            260         const struct tfa989x_rev *rev;
321         struct tfa989x *tfa989x;                  261         struct tfa989x *tfa989x;
322         struct regmap *regmap;                    262         struct regmap *regmap;
323         unsigned int val;                         263         unsigned int val;
324         int ret;                                  264         int ret;
325                                                   265 
326         rev = device_get_match_data(dev);         266         rev = device_get_match_data(dev);
327         if (!rev) {                               267         if (!rev) {
328                 dev_err(dev, "unknown device r    268                 dev_err(dev, "unknown device revision\n");
329                 return -ENODEV;                   269                 return -ENODEV;
330         }                                         270         }
331                                                   271 
332         tfa989x = devm_kzalloc(dev, sizeof(*tf    272         tfa989x = devm_kzalloc(dev, sizeof(*tfa989x), GFP_KERNEL);
333         if (!tfa989x)                             273         if (!tfa989x)
334                 return -ENOMEM;                   274                 return -ENOMEM;
335                                                   275 
336         tfa989x->rev = rev;                    << 
337         i2c_set_clientdata(i2c, tfa989x);         276         i2c_set_clientdata(i2c, tfa989x);
338                                                   277 
339         tfa989x->vddd_supply = devm_regulator_    278         tfa989x->vddd_supply = devm_regulator_get(dev, "vddd");
340         if (IS_ERR(tfa989x->vddd_supply))         279         if (IS_ERR(tfa989x->vddd_supply))
341                 return dev_err_probe(dev, PTR_    280                 return dev_err_probe(dev, PTR_ERR(tfa989x->vddd_supply),
342                                      "Failed t    281                                      "Failed to get vddd regulator\n");
343                                                   282 
344         if (tfa989x->rev->rev == TFA9897_REVIS << 
345                 tfa989x->rcv_gpiod = devm_gpio << 
346                 if (IS_ERR(tfa989x->rcv_gpiod) << 
347                         return PTR_ERR(tfa989x << 
348         }                                      << 
349                                                << 
350         regmap = devm_regmap_init_i2c(i2c, &tf    283         regmap = devm_regmap_init_i2c(i2c, &tfa989x_regmap);
351         if (IS_ERR(regmap))                       284         if (IS_ERR(regmap))
352                 return PTR_ERR(regmap);           285                 return PTR_ERR(regmap);
353                                                   286 
354         ret = regulator_enable(tfa989x->vddd_s    287         ret = regulator_enable(tfa989x->vddd_supply);
355         if (ret) {                                288         if (ret) {
356                 dev_err(dev, "Failed to enable    289                 dev_err(dev, "Failed to enable vddd regulator: %d\n", ret);
357                 return ret;                       290                 return ret;
358         }                                         291         }
359                                                   292 
360         ret = devm_add_action_or_reset(dev, tf    293         ret = devm_add_action_or_reset(dev, tfa989x_regulator_disable, tfa989x);
361         if (ret)                                  294         if (ret)
362                 return ret;                       295                 return ret;
363                                                   296 
364         /* Bypass regcache for reset and init     297         /* Bypass regcache for reset and init sequence */
365         regcache_cache_bypass(regmap, true);      298         regcache_cache_bypass(regmap, true);
366                                                   299 
367         /* Dummy read to generate i2c clocks,     300         /* Dummy read to generate i2c clocks, required on some devices */
368         regmap_read(regmap, TFA989X_REVISIONNU    301         regmap_read(regmap, TFA989X_REVISIONNUMBER, &val);
369                                                   302 
370         ret = regmap_read(regmap, TFA989X_REVI    303         ret = regmap_read(regmap, TFA989X_REVISIONNUMBER, &val);
371         if (ret) {                                304         if (ret) {
372                 dev_err(dev, "failed to read r    305                 dev_err(dev, "failed to read revision number: %d\n", ret);
373                 return ret;                       306                 return ret;
374         }                                         307         }
375                                                   308 
376         val &= TFA989X_REVISIONNUMBER_REV_MSK;    309         val &= TFA989X_REVISIONNUMBER_REV_MSK;
377         if (val != rev->rev) {                    310         if (val != rev->rev) {
378                 dev_err(dev, "invalid revision    311                 dev_err(dev, "invalid revision number, expected %#x, got %#x\n",
379                         rev->rev, val);           312                         rev->rev, val);
380                 return -ENODEV;                   313                 return -ENODEV;
381         }                                         314         }
382                                                   315 
383         ret = regmap_write(regmap, TFA989X_SYS    316         ret = regmap_write(regmap, TFA989X_SYS_CTRL, BIT(TFA989X_SYS_CTRL_I2CR));
384         if (ret) {                                317         if (ret) {
385                 dev_err(dev, "failed to reset     318                 dev_err(dev, "failed to reset I2C registers: %d\n", ret);
386                 return ret;                       319                 return ret;
387         }                                         320         }
388                                                   321 
389         ret = rev->init(regmap);                  322         ret = rev->init(regmap);
390         if (ret) {                                323         if (ret) {
391                 dev_err(dev, "failed to initia    324                 dev_err(dev, "failed to initialize registers: %d\n", ret);
392                 return ret;                       325                 return ret;
393         }                                         326         }
394                                                   327 
395         ret = tfa989x_dsp_bypass(regmap);         328         ret = tfa989x_dsp_bypass(regmap);
396         if (ret) {                                329         if (ret) {
397                 dev_err(dev, "failed to enable    330                 dev_err(dev, "failed to enable DSP bypass: %d\n", ret);
398                 return ret;                       331                 return ret;
399         }                                         332         }
400         regcache_cache_bypass(regmap, false);     333         regcache_cache_bypass(regmap, false);
401                                                   334 
402         return devm_snd_soc_register_component    335         return devm_snd_soc_register_component(dev, &tfa989x_component,
403                                                   336                                                &tfa989x_dai, 1);
404 }                                                 337 }
405                                                   338 
406 static const struct of_device_id tfa989x_of_ma    339 static const struct of_device_id tfa989x_of_match[] = {
407         { .compatible = "nxp,tfa9890", .data = << 
408         { .compatible = "nxp,tfa9895", .data =    340         { .compatible = "nxp,tfa9895", .data = &tfa9895_rev },
409         { .compatible = "nxp,tfa9897", .data =    341         { .compatible = "nxp,tfa9897", .data = &tfa9897_rev },
410         { }                                       342         { }
411 };                                                343 };
412 MODULE_DEVICE_TABLE(of, tfa989x_of_match);        344 MODULE_DEVICE_TABLE(of, tfa989x_of_match);
413                                                   345 
414 static struct i2c_driver tfa989x_i2c_driver =     346 static struct i2c_driver tfa989x_i2c_driver = {
415         .driver = {                               347         .driver = {
416                 .name = "tfa989x",                348                 .name = "tfa989x",
417                 .of_match_table = tfa989x_of_m    349                 .of_match_table = tfa989x_of_match,
418         },                                        350         },
419         .probe = tfa989x_i2c_probe,            !! 351         .probe_new = tfa989x_i2c_probe,
420 };                                                352 };
421 module_i2c_driver(tfa989x_i2c_driver);            353 module_i2c_driver(tfa989x_i2c_driver);
422                                                   354 
423 MODULE_DESCRIPTION("ASoC NXP/Goodix TFA989X (T    355 MODULE_DESCRIPTION("ASoC NXP/Goodix TFA989X (TFA1) driver");
424 MODULE_AUTHOR("Stephan Gerhold <stephan@gerhol    356 MODULE_AUTHOR("Stephan Gerhold <stephan@gerhold.net>");
425 MODULE_LICENSE("GPL");                            357 MODULE_LICENSE("GPL");
426                                                   358 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php