]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - sound/soc/codecs/tas2552.c
ASoC: tas2552: Add TDM support
[karo-tx-linux.git] / sound / soc / codecs / tas2552.c
1 /*
2  * tas2552.c - ALSA SoC Texas Instruments TAS2552 Mono Audio Amplifier
3  *
4  * Copyright (C) 2014 Texas Instruments Incorporated -  http://www.ti.com
5  *
6  * Author: Dan Murphy <dmurphy@ti.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  */
17
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/device.h>
21 #include <linux/i2c.h>
22 #include <linux/gpio.h>
23 #include <linux/of_gpio.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/regmap.h>
26 #include <linux/slab.h>
27
28 #include <linux/gpio/consumer.h>
29 #include <linux/regulator/consumer.h>
30
31 #include <sound/pcm.h>
32 #include <sound/pcm_params.h>
33 #include <sound/soc.h>
34 #include <sound/soc-dapm.h>
35 #include <sound/tlv.h>
36 #include <sound/tas2552-plat.h>
37 #include <dt-bindings/sound/tas2552.h>
38
39 #include "tas2552.h"
40
41 static struct reg_default tas2552_reg_defs[] = {
42         {TAS2552_CFG_1, 0x22},
43         {TAS2552_CFG_3, 0x80},
44         {TAS2552_DOUT, 0x00},
45         {TAS2552_OUTPUT_DATA, 0xc0},
46         {TAS2552_PDM_CFG, 0x01},
47         {TAS2552_PGA_GAIN, 0x00},
48         {TAS2552_BOOST_PT_CTRL, 0x0f},
49         {TAS2552_RESERVED_0D, 0x00},
50         {TAS2552_LIMIT_RATE_HYS, 0x08},
51         {TAS2552_CFG_2, 0xef},
52         {TAS2552_SER_CTRL_1, 0x00},
53         {TAS2552_SER_CTRL_2, 0x00},
54         {TAS2552_PLL_CTRL_1, 0x10},
55         {TAS2552_PLL_CTRL_2, 0x00},
56         {TAS2552_PLL_CTRL_3, 0x00},
57         {TAS2552_BTIP, 0x8f},
58         {TAS2552_BTS_CTRL, 0x80},
59         {TAS2552_LIMIT_RELEASE, 0x04},
60         {TAS2552_LIMIT_INT_COUNT, 0x00},
61         {TAS2552_EDGE_RATE_CTRL, 0x40},
62         {TAS2552_VBAT_DATA, 0x00},
63 };
64
65 #define TAS2552_NUM_SUPPLIES    3
66 static const char *tas2552_supply_names[TAS2552_NUM_SUPPLIES] = {
67         "vbat",         /* vbat voltage */
68         "iovdd",        /* I/O Voltage */
69         "avdd",         /* Analog DAC Voltage */
70 };
71
72 struct tas2552_data {
73         struct snd_soc_codec *codec;
74         struct regmap *regmap;
75         struct i2c_client *tas2552_client;
76         struct regulator_bulk_data supplies[TAS2552_NUM_SUPPLIES];
77         struct gpio_desc *enable_gpio;
78         unsigned char regs[TAS2552_VBAT_DATA];
79         unsigned int pll_clkin;
80         unsigned int pdm_clk;
81
82         unsigned int dai_fmt;
83         unsigned int tdm_delay;
84 };
85
86 /* Input mux controls */
87 static const char *tas2552_input_texts[] = {
88         "Digital", "Analog"
89 };
90
91 static SOC_ENUM_SINGLE_DECL(tas2552_input_mux_enum, TAS2552_CFG_3, 7,
92                             tas2552_input_texts);
93
94 static const struct snd_kcontrol_new tas2552_input_mux_control[] = {
95         SOC_DAPM_ENUM("Input selection", tas2552_input_mux_enum)
96 };
97
98 static const struct snd_soc_dapm_widget tas2552_dapm_widgets[] =
99 {
100         SND_SOC_DAPM_INPUT("IN"),
101
102         /* MUX Controls */
103         SND_SOC_DAPM_MUX("Input selection", SND_SOC_NOPM, 0, 0,
104                                 tas2552_input_mux_control),
105
106         SND_SOC_DAPM_AIF_IN("DAC IN", "DAC Playback", 0, SND_SOC_NOPM, 0, 0),
107         SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
108         SND_SOC_DAPM_OUT_DRV("ClassD", TAS2552_CFG_2, 7, 0, NULL, 0),
109         SND_SOC_DAPM_SUPPLY("PLL", TAS2552_CFG_2, 3, 0, NULL, 0),
110
111         SND_SOC_DAPM_OUTPUT("OUT")
112 };
113
114 static const struct snd_soc_dapm_route tas2552_audio_map[] = {
115         {"DAC", NULL, "DAC IN"},
116         {"Input selection", "Digital", "DAC"},
117         {"Input selection", "Analog", "IN"},
118         {"ClassD", NULL, "Input selection"},
119         {"OUT", NULL, "ClassD"},
120         {"ClassD", NULL, "PLL"},
121 };
122
123 #ifdef CONFIG_PM
124 static void tas2552_sw_shutdown(struct tas2552_data *tas_data, int sw_shutdown)
125 {
126         u8 cfg1_reg = 0;
127
128         if (!tas_data->codec)
129                 return;
130
131         if (sw_shutdown)
132                 cfg1_reg = TAS2552_SWS;
133
134         snd_soc_update_bits(tas_data->codec, TAS2552_CFG_1, TAS2552_SWS,
135                             cfg1_reg);
136 }
137 #endif
138
139 static int tas2552_hw_params(struct snd_pcm_substream *substream,
140                              struct snd_pcm_hw_params *params,
141                              struct snd_soc_dai *dai)
142 {
143         struct snd_soc_codec *codec = dai->codec;
144         struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
145         int sample_rate, pll_clk;
146         int d;
147         u8 p, j;
148
149         if (!tas2552->pll_clkin)
150                 return -EINVAL;
151
152         snd_soc_update_bits(codec, TAS2552_CFG_2, TAS2552_PLL_ENABLE, 0);
153
154         if (tas2552->pll_clkin == TAS2552_245MHZ_CLK ||
155             tas2552->pll_clkin == TAS2552_225MHZ_CLK) {
156                 /* By pass the PLL configuration */
157                 snd_soc_update_bits(codec, TAS2552_PLL_CTRL_2,
158                                     TAS2552_PLL_BYPASS_MASK,
159                                     TAS2552_PLL_BYPASS);
160         } else {
161                 /* Fill in the PLL control registers for J & D
162                  * PLL_CLK = (.5 * freq * J.D) / 2^p
163                  * Need to fill in J and D here based on incoming freq
164                  */
165                 p = snd_soc_read(codec, TAS2552_PLL_CTRL_1);
166                 p = (p >> 7);
167                 sample_rate = params_rate(params);
168
169                 if (sample_rate == 48000)
170                         pll_clk = TAS2552_245MHZ_CLK;
171                 else if (sample_rate == 44100)
172                         pll_clk = TAS2552_225MHZ_CLK;
173                 else {
174                         dev_vdbg(codec->dev, "Substream sample rate is not found %i\n",
175                                         params_rate(params));
176                         return -EINVAL;
177                 }
178
179                 j = (pll_clk * 2 * (1 << p)) / tas2552->pll_clkin;
180                 d = (pll_clk * 2 * (1 << p)) % tas2552->pll_clkin;
181
182                 snd_soc_update_bits(codec, TAS2552_PLL_CTRL_1,
183                                 TAS2552_PLL_J_MASK, j);
184                 snd_soc_write(codec, TAS2552_PLL_CTRL_2,
185                                         (d >> 7) & TAS2552_PLL_D_UPPER_MASK);
186                 snd_soc_write(codec, TAS2552_PLL_CTRL_3,
187                                 d & TAS2552_PLL_D_LOWER_MASK);
188
189         }
190
191         return 0;
192 }
193
194 #define TAS2552_DAI_FMT_MASK    (TAS2552_BCLKDIR | \
195                                  TAS2552_WCLKDIR | \
196                                  TAS2552_DATAFORMAT_MASK)
197 static int tas2552_prepare(struct snd_pcm_substream *substream,
198                            struct snd_soc_dai *dai)
199 {
200         struct snd_soc_codec *codec = dai->codec;
201         struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
202         int delay = 0;
203
204         /* TDM slot selection only valid in DSP_A/_B mode */
205         if (tas2552->dai_fmt == SND_SOC_DAIFMT_DSP_A)
206                 delay += (tas2552->tdm_delay + 1);
207         else if (tas2552->dai_fmt == SND_SOC_DAIFMT_DSP_B)
208                 delay += tas2552->tdm_delay;
209
210         /* Configure data delay */
211         snd_soc_write(codec, TAS2552_SER_CTRL_2, delay);
212
213         return 0;
214 }
215
216 static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
217 {
218         struct snd_soc_codec *codec = dai->codec;
219         struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
220         u8 serial_format;
221
222         switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
223         case SND_SOC_DAIFMT_CBS_CFS:
224                 serial_format = 0x00;
225                 break;
226         case SND_SOC_DAIFMT_CBS_CFM:
227                 serial_format = TAS2552_WCLKDIR;
228                 break;
229         case SND_SOC_DAIFMT_CBM_CFS:
230                 serial_format = TAS2552_BCLKDIR;
231                 break;
232         case SND_SOC_DAIFMT_CBM_CFM:
233                 serial_format = (TAS2552_BCLKDIR | TAS2552_WCLKDIR);
234                 break;
235         default:
236                 dev_vdbg(codec->dev, "DAI Format master is not found\n");
237                 return -EINVAL;
238         }
239
240         switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
241                        SND_SOC_DAIFMT_INV_MASK)) {
242         case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
243                 break;
244         case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
245         case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
246                 serial_format |= TAS2552_DATAFORMAT_DSP;
247                 break;
248         case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
249                 serial_format |= TAS2552_DATAFORMAT_RIGHT_J;
250                 break;
251         case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
252                 serial_format |= TAS2552_DATAFORMAT_LEFT_J;
253                 break;
254         default:
255                 dev_vdbg(codec->dev, "DAI Format is not found\n");
256                 return -EINVAL;
257         }
258         tas2552->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
259
260         snd_soc_update_bits(codec, TAS2552_SER_CTRL_1, TAS2552_DAI_FMT_MASK,
261                             serial_format);
262         return 0;
263 }
264
265 static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
266                                   unsigned int freq, int dir)
267 {
268         struct snd_soc_codec *codec = dai->codec;
269         struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev);
270         u8 reg, mask, val;
271
272         switch (clk_id) {
273         case TAS2552_PLL_CLKIN_MCLK:
274         case TAS2552_PLL_CLKIN_BCLK:
275         case TAS2552_PLL_CLKIN_IVCLKIN:
276         case TAS2552_PLL_CLKIN_1_8_FIXED:
277                 mask = TAS2552_PLL_SRC_MASK;
278                 val = (clk_id << 3) & mask; /* bit 4:5 in the register */
279                 reg = TAS2552_CFG_1;
280                 tas2552->pll_clkin = freq;
281                 break;
282         case TAS2552_PDM_CLK_PLL:
283         case TAS2552_PDM_CLK_IVCLKIN:
284         case TAS2552_PDM_CLK_BCLK:
285         case TAS2552_PDM_CLK_MCLK:
286                 mask = TAS2552_PDM_CLK_SEL_MASK;
287                 val = (clk_id >> 1) & mask; /* bit 0:1 in the register */
288                 reg = TAS2552_PDM_CFG;
289                 tas2552->pdm_clk = freq;
290                 break;
291         default:
292                 dev_err(codec->dev, "Invalid clk id: %d\n", clk_id);
293                 return -EINVAL;
294         }
295
296         snd_soc_update_bits(codec, reg, mask, val);
297
298         return 0;
299 }
300
301 static int tas2552_set_dai_tdm_slot(struct snd_soc_dai *dai,
302                                     unsigned int tx_mask, unsigned int rx_mask,
303                                     int slots, int slot_width)
304 {
305         struct snd_soc_codec *codec = dai->codec;
306         struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
307         unsigned int lsb;
308
309         if (unlikely(!tx_mask)) {
310                 dev_err(codec->dev, "tx masks need to be non 0\n");
311                 return -EINVAL;
312         }
313
314         /* TDM based on DSP mode requires slots to be adjacent */
315         lsb = __ffs(tx_mask);
316         if ((lsb + 1) != __fls(tx_mask)) {
317                 dev_err(codec->dev, "Invalid mask, slots must be adjacent\n");
318                 return -EINVAL;
319         }
320
321         tas2552->tdm_delay = lsb * slot_width;
322
323         /* DOUT in high-impedance on inactive bit clocks */
324         snd_soc_update_bits(codec, TAS2552_DOUT,
325                             TAS2552_SDOUT_TRISTATE, TAS2552_SDOUT_TRISTATE);
326
327         return 0;
328 }
329
330 static int tas2552_mute(struct snd_soc_dai *dai, int mute)
331 {
332         u8 cfg1_reg = 0;
333         struct snd_soc_codec *codec = dai->codec;
334
335         if (mute)
336                 cfg1_reg |= TAS2552_MUTE;
337
338         snd_soc_update_bits(codec, TAS2552_CFG_1, TAS2552_MUTE, cfg1_reg);
339
340         return 0;
341 }
342
343 #ifdef CONFIG_PM
344 static int tas2552_runtime_suspend(struct device *dev)
345 {
346         struct tas2552_data *tas2552 = dev_get_drvdata(dev);
347
348         tas2552_sw_shutdown(tas2552, 1);
349
350         regcache_cache_only(tas2552->regmap, true);
351         regcache_mark_dirty(tas2552->regmap);
352
353         if (tas2552->enable_gpio)
354                 gpiod_set_value(tas2552->enable_gpio, 0);
355
356         return 0;
357 }
358
359 static int tas2552_runtime_resume(struct device *dev)
360 {
361         struct tas2552_data *tas2552 = dev_get_drvdata(dev);
362
363         if (tas2552->enable_gpio)
364                 gpiod_set_value(tas2552->enable_gpio, 1);
365
366         tas2552_sw_shutdown(tas2552, 0);
367
368         regcache_cache_only(tas2552->regmap, false);
369         regcache_sync(tas2552->regmap);
370
371         return 0;
372 }
373 #endif
374
375 static const struct dev_pm_ops tas2552_pm = {
376         SET_RUNTIME_PM_OPS(tas2552_runtime_suspend, tas2552_runtime_resume,
377                            NULL)
378 };
379
380 static struct snd_soc_dai_ops tas2552_speaker_dai_ops = {
381         .hw_params      = tas2552_hw_params,
382         .prepare        = tas2552_prepare,
383         .set_sysclk     = tas2552_set_dai_sysclk,
384         .set_fmt        = tas2552_set_dai_fmt,
385         .set_tdm_slot   = tas2552_set_dai_tdm_slot,
386         .digital_mute = tas2552_mute,
387 };
388
389 /* Formats supported by TAS2552 driver. */
390 #define TAS2552_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
391                          SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
392
393 /* TAS2552 dai structure. */
394 static struct snd_soc_dai_driver tas2552_dai[] = {
395         {
396                 .name = "tas2552-amplifier",
397                 .playback = {
398                         .stream_name = "Playback",
399                         .channels_min = 2,
400                         .channels_max = 2,
401                         .rates = SNDRV_PCM_RATE_8000_192000,
402                         .formats = TAS2552_FORMATS,
403                 },
404                 .ops = &tas2552_speaker_dai_ops,
405         },
406 };
407
408 /*
409  * DAC digital volumes. From -7 to 24 dB in 1 dB steps
410  */
411 static DECLARE_TLV_DB_SCALE(dac_tlv, -7, 100, 24);
412
413 static const struct snd_kcontrol_new tas2552_snd_controls[] = {
414         SOC_SINGLE_TLV("Speaker Driver Playback Volume",
415                          TAS2552_PGA_GAIN, 0, 0x1f, 1, dac_tlv),
416 };
417
418 static const struct reg_default tas2552_init_regs[] = {
419         { TAS2552_RESERVED_0D, 0xc0 },
420 };
421
422 static int tas2552_codec_probe(struct snd_soc_codec *codec)
423 {
424         struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
425         int ret;
426
427         tas2552->codec = codec;
428
429         ret = regulator_bulk_enable(ARRAY_SIZE(tas2552->supplies),
430                                     tas2552->supplies);
431
432         if (ret != 0) {
433                 dev_err(codec->dev, "Failed to enable supplies: %d\n",
434                         ret);
435                 return ret;
436         }
437
438         if (tas2552->enable_gpio)
439                 gpiod_set_value(tas2552->enable_gpio, 1);
440
441         ret = pm_runtime_get_sync(codec->dev);
442         if (ret < 0) {
443                 dev_err(codec->dev, "Enabling device failed: %d\n",
444                         ret);
445                 goto probe_fail;
446         }
447
448         snd_soc_write(codec, TAS2552_CFG_1, TAS2552_MUTE);
449         snd_soc_write(codec, TAS2552_CFG_3, TAS2552_I2S_OUT_SEL |
450                                 TAS2552_DIN_SRC_SEL_AVG_L_R | TAS2552_88_96KHZ);
451         snd_soc_write(codec, TAS2552_DOUT, TAS2552_PDM_DATA_I);
452         snd_soc_write(codec, TAS2552_OUTPUT_DATA, TAS2552_PDM_DATA_V_I | 0x8);
453         snd_soc_write(codec, TAS2552_BOOST_PT_CTRL, TAS2552_APT_DELAY_200 |
454                                 TAS2552_APT_THRESH_2_1_7);
455
456         ret = regmap_register_patch(tas2552->regmap, tas2552_init_regs,
457                                             ARRAY_SIZE(tas2552_init_regs));
458         if (ret != 0) {
459                 dev_err(codec->dev, "Failed to write init registers: %d\n",
460                         ret);
461                 goto patch_fail;
462         }
463
464         snd_soc_write(codec, TAS2552_CFG_2, TAS2552_BOOST_EN |
465                                   TAS2552_APT_EN | TAS2552_LIM_EN);
466
467         return 0;
468
469 patch_fail:
470         pm_runtime_put(codec->dev);
471 probe_fail:
472         if (tas2552->enable_gpio)
473                 gpiod_set_value(tas2552->enable_gpio, 0);
474
475         regulator_bulk_disable(ARRAY_SIZE(tas2552->supplies),
476                                         tas2552->supplies);
477         return -EIO;
478 }
479
480 static int tas2552_codec_remove(struct snd_soc_codec *codec)
481 {
482         struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
483
484         pm_runtime_put(codec->dev);
485
486         if (tas2552->enable_gpio)
487                 gpiod_set_value(tas2552->enable_gpio, 0);
488
489         return 0;
490 };
491
492 #ifdef CONFIG_PM
493 static int tas2552_suspend(struct snd_soc_codec *codec)
494 {
495         struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
496         int ret;
497
498         ret = regulator_bulk_disable(ARRAY_SIZE(tas2552->supplies),
499                                         tas2552->supplies);
500
501         if (ret != 0)
502                 dev_err(codec->dev, "Failed to disable supplies: %d\n",
503                         ret);
504         return 0;
505 }
506
507 static int tas2552_resume(struct snd_soc_codec *codec)
508 {
509         struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec);
510         int ret;
511
512         ret = regulator_bulk_enable(ARRAY_SIZE(tas2552->supplies),
513                                     tas2552->supplies);
514
515         if (ret != 0) {
516                 dev_err(codec->dev, "Failed to enable supplies: %d\n",
517                         ret);
518         }
519
520         return 0;
521 }
522 #else
523 #define tas2552_suspend NULL
524 #define tas2552_resume NULL
525 #endif
526
527 static struct snd_soc_codec_driver soc_codec_dev_tas2552 = {
528         .probe = tas2552_codec_probe,
529         .remove = tas2552_codec_remove,
530         .suspend =      tas2552_suspend,
531         .resume = tas2552_resume,
532         .controls = tas2552_snd_controls,
533         .num_controls = ARRAY_SIZE(tas2552_snd_controls),
534         .dapm_widgets = tas2552_dapm_widgets,
535         .num_dapm_widgets = ARRAY_SIZE(tas2552_dapm_widgets),
536         .dapm_routes = tas2552_audio_map,
537         .num_dapm_routes = ARRAY_SIZE(tas2552_audio_map),
538 };
539
540 static const struct regmap_config tas2552_regmap_config = {
541         .reg_bits = 8,
542         .val_bits = 8,
543
544         .max_register = TAS2552_MAX_REG,
545         .reg_defaults = tas2552_reg_defs,
546         .num_reg_defaults = ARRAY_SIZE(tas2552_reg_defs),
547         .cache_type = REGCACHE_RBTREE,
548 };
549
550 static int tas2552_probe(struct i2c_client *client,
551                            const struct i2c_device_id *id)
552 {
553         struct device *dev;
554         struct tas2552_data *data;
555         int ret;
556         int i;
557
558         dev = &client->dev;
559         data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
560         if (data == NULL)
561                 return -ENOMEM;
562
563         data->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
564         if (IS_ERR(data->enable_gpio)) {
565                 if (PTR_ERR(data->enable_gpio) == -EPROBE_DEFER)
566                         return -EPROBE_DEFER;
567
568                 data->enable_gpio = NULL;;
569         }
570
571         data->tas2552_client = client;
572         data->regmap = devm_regmap_init_i2c(client, &tas2552_regmap_config);
573         if (IS_ERR(data->regmap)) {
574                 ret = PTR_ERR(data->regmap);
575                 dev_err(&client->dev, "Failed to allocate register map: %d\n",
576                         ret);
577                 return ret;
578         }
579
580         for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
581                 data->supplies[i].supply = tas2552_supply_names[i];
582
583         ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
584                                       data->supplies);
585         if (ret != 0) {
586                 dev_err(dev, "Failed to request supplies: %d\n", ret);
587                 return ret;
588         }
589
590         pm_runtime_set_active(&client->dev);
591         pm_runtime_set_autosuspend_delay(&client->dev, 1000);
592         pm_runtime_use_autosuspend(&client->dev);
593         pm_runtime_enable(&client->dev);
594         pm_runtime_mark_last_busy(&client->dev);
595         pm_runtime_put_sync_autosuspend(&client->dev);
596
597         dev_set_drvdata(&client->dev, data);
598
599         ret = snd_soc_register_codec(&client->dev,
600                                       &soc_codec_dev_tas2552,
601                                       tas2552_dai, ARRAY_SIZE(tas2552_dai));
602         if (ret < 0)
603                 dev_err(&client->dev, "Failed to register codec: %d\n", ret);
604
605         return ret;
606 }
607
608 static int tas2552_i2c_remove(struct i2c_client *client)
609 {
610         snd_soc_unregister_codec(&client->dev);
611         return 0;
612 }
613
614 static const struct i2c_device_id tas2552_id[] = {
615         { "tas2552", 0 },
616         { }
617 };
618 MODULE_DEVICE_TABLE(i2c, tas2552_id);
619
620 #if IS_ENABLED(CONFIG_OF)
621 static const struct of_device_id tas2552_of_match[] = {
622         { .compatible = "ti,tas2552", },
623         {},
624 };
625 MODULE_DEVICE_TABLE(of, tas2552_of_match);
626 #endif
627
628 static struct i2c_driver tas2552_i2c_driver = {
629         .driver = {
630                 .name = "tas2552",
631                 .owner = THIS_MODULE,
632                 .of_match_table = of_match_ptr(tas2552_of_match),
633                 .pm = &tas2552_pm,
634         },
635         .probe = tas2552_probe,
636         .remove = tas2552_i2c_remove,
637         .id_table = tas2552_id,
638 };
639
640 module_i2c_driver(tas2552_i2c_driver);
641
642 MODULE_AUTHOR("Dan Muprhy <dmurphy@ti.com>");
643 MODULE_DESCRIPTION("TAS2552 Audio amplifier driver");
644 MODULE_LICENSE("GPL");