Andrew F. Davis | b1c52b7 | 2017-11-29 15:32:42 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 2 | /* |
Andrew F. Davis | b1c52b7 | 2017-11-29 15:32:42 -0600 | [diff] [blame] | 3 | * ALSA SoC TLV320AIC31xx CODEC Driver |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 4 | * |
Alexander A. Klimov | 5856d8b | 2020-07-19 17:38:22 +0200 | [diff] [blame] | 5 | * Copyright (C) 2014-2017 Texas Instruments Incorporated - https://www.ti.com/ |
Andrew F. Davis | b1c52b7 | 2017-11-29 15:32:42 -0600 | [diff] [blame] | 6 | * Jyri Sarha <jsarha@ti.com> |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 7 | * |
| 8 | * Based on ground work by: Ajit Kulkarni <x0175765@ti.com> |
| 9 | * |
Andrew F. Davis | b1c52b7 | 2017-11-29 15:32:42 -0600 | [diff] [blame] | 10 | * The TLV320AIC31xx series of audio codecs are low-power, highly integrated |
| 11 | * high performance codecs which provides a stereo DAC, a mono ADC, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 12 | * and mono/stereo Class-D speaker driver. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/init.h> |
Ariel D'Alessandro | c5d22d5 | 2021-11-19 12:32:47 -0300 | [diff] [blame] | 18 | #include <linux/clk.h> |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/pm.h> |
| 21 | #include <linux/i2c.h> |
Andrew F. Davis | 283c350 | 2017-12-07 09:38:51 -0600 | [diff] [blame] | 22 | #include <linux/gpio/consumer.h> |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 23 | #include <linux/regulator/consumer.h> |
Bastien Nocera | f5cc177 | 2016-04-19 18:00:20 +0200 | [diff] [blame] | 24 | #include <linux/acpi.h> |
Sachin Kamat | 0faabc4 | 2014-04-04 11:29:12 +0530 | [diff] [blame] | 25 | #include <linux/of.h> |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 26 | #include <linux/of_gpio.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <sound/core.h> |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 29 | #include <sound/jack.h> |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 30 | #include <sound/pcm.h> |
| 31 | #include <sound/pcm_params.h> |
| 32 | #include <sound/soc.h> |
| 33 | #include <sound/initval.h> |
| 34 | #include <sound/tlv.h> |
| 35 | #include <dt-bindings/sound/tlv320aic31xx-micbias.h> |
| 36 | |
| 37 | #include "tlv320aic31xx.h" |
| 38 | |
Mark Brown | 2c39ca6 | 2021-07-23 19:02:00 +0100 | [diff] [blame] | 39 | static int aic31xx_set_jack(struct snd_soc_component *component, |
| 40 | struct snd_soc_jack *jack, void *data); |
| 41 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 42 | static const struct reg_default aic31xx_reg_defaults[] = { |
| 43 | { AIC31XX_CLKMUX, 0x00 }, |
| 44 | { AIC31XX_PLLPR, 0x11 }, |
| 45 | { AIC31XX_PLLJ, 0x04 }, |
| 46 | { AIC31XX_PLLDMSB, 0x00 }, |
| 47 | { AIC31XX_PLLDLSB, 0x00 }, |
| 48 | { AIC31XX_NDAC, 0x01 }, |
| 49 | { AIC31XX_MDAC, 0x01 }, |
| 50 | { AIC31XX_DOSRMSB, 0x00 }, |
| 51 | { AIC31XX_DOSRLSB, 0x80 }, |
| 52 | { AIC31XX_NADC, 0x01 }, |
| 53 | { AIC31XX_MADC, 0x01 }, |
| 54 | { AIC31XX_AOSR, 0x80 }, |
| 55 | { AIC31XX_IFACE1, 0x00 }, |
| 56 | { AIC31XX_DATA_OFFSET, 0x00 }, |
| 57 | { AIC31XX_IFACE2, 0x00 }, |
| 58 | { AIC31XX_BCLKN, 0x01 }, |
| 59 | { AIC31XX_DACSETUP, 0x14 }, |
| 60 | { AIC31XX_DACMUTE, 0x0c }, |
| 61 | { AIC31XX_LDACVOL, 0x00 }, |
| 62 | { AIC31XX_RDACVOL, 0x00 }, |
| 63 | { AIC31XX_ADCSETUP, 0x00 }, |
| 64 | { AIC31XX_ADCFGA, 0x80 }, |
| 65 | { AIC31XX_ADCVOL, 0x00 }, |
| 66 | { AIC31XX_HPDRIVER, 0x04 }, |
| 67 | { AIC31XX_SPKAMP, 0x06 }, |
| 68 | { AIC31XX_DACMIXERROUTE, 0x00 }, |
| 69 | { AIC31XX_LANALOGHPL, 0x7f }, |
| 70 | { AIC31XX_RANALOGHPR, 0x7f }, |
| 71 | { AIC31XX_LANALOGSPL, 0x7f }, |
| 72 | { AIC31XX_RANALOGSPR, 0x7f }, |
| 73 | { AIC31XX_HPLGAIN, 0x02 }, |
| 74 | { AIC31XX_HPRGAIN, 0x02 }, |
| 75 | { AIC31XX_SPLGAIN, 0x00 }, |
| 76 | { AIC31XX_SPRGAIN, 0x00 }, |
| 77 | { AIC31XX_MICBIAS, 0x00 }, |
| 78 | { AIC31XX_MICPGA, 0x80 }, |
| 79 | { AIC31XX_MICPGAPI, 0x00 }, |
| 80 | { AIC31XX_MICPGAMI, 0x00 }, |
| 81 | }; |
| 82 | |
| 83 | static bool aic31xx_volatile(struct device *dev, unsigned int reg) |
| 84 | { |
| 85 | switch (reg) { |
| 86 | case AIC31XX_PAGECTL: /* regmap implementation requires this */ |
| 87 | case AIC31XX_RESET: /* always clears after write */ |
| 88 | case AIC31XX_OT_FLAG: |
| 89 | case AIC31XX_ADCFLAG: |
| 90 | case AIC31XX_DACFLAG1: |
| 91 | case AIC31XX_DACFLAG2: |
| 92 | case AIC31XX_OFFLAG: /* Sticky interrupt flags */ |
| 93 | case AIC31XX_INTRDACFLAG: /* Sticky interrupt flags */ |
| 94 | case AIC31XX_INTRADCFLAG: /* Sticky interrupt flags */ |
| 95 | case AIC31XX_INTRDACFLAG2: |
| 96 | case AIC31XX_INTRADCFLAG2: |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 97 | case AIC31XX_HSDETECT: |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 98 | return true; |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | static bool aic31xx_writeable(struct device *dev, unsigned int reg) |
| 104 | { |
| 105 | switch (reg) { |
| 106 | case AIC31XX_OT_FLAG: |
| 107 | case AIC31XX_ADCFLAG: |
| 108 | case AIC31XX_DACFLAG1: |
| 109 | case AIC31XX_DACFLAG2: |
| 110 | case AIC31XX_OFFLAG: /* Sticky interrupt flags */ |
| 111 | case AIC31XX_INTRDACFLAG: /* Sticky interrupt flags */ |
| 112 | case AIC31XX_INTRADCFLAG: /* Sticky interrupt flags */ |
| 113 | case AIC31XX_INTRDACFLAG2: |
| 114 | case AIC31XX_INTRADCFLAG2: |
| 115 | return false; |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | static const struct regmap_range_cfg aic31xx_ranges[] = { |
| 121 | { |
| 122 | .range_min = 0, |
| 123 | .range_max = 12 * 128, |
| 124 | .selector_reg = AIC31XX_PAGECTL, |
| 125 | .selector_mask = 0xff, |
| 126 | .selector_shift = 0, |
| 127 | .window_start = 0, |
| 128 | .window_len = 128, |
| 129 | }, |
| 130 | }; |
| 131 | |
Mark Brown | 9296f4d | 2014-03-13 17:44:22 +0000 | [diff] [blame] | 132 | static const struct regmap_config aic31xx_i2c_regmap = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 133 | .reg_bits = 8, |
| 134 | .val_bits = 8, |
| 135 | .writeable_reg = aic31xx_writeable, |
| 136 | .volatile_reg = aic31xx_volatile, |
| 137 | .reg_defaults = aic31xx_reg_defaults, |
| 138 | .num_reg_defaults = ARRAY_SIZE(aic31xx_reg_defaults), |
| 139 | .cache_type = REGCACHE_RBTREE, |
| 140 | .ranges = aic31xx_ranges, |
| 141 | .num_ranges = ARRAY_SIZE(aic31xx_ranges), |
| 142 | .max_register = 12 * 128, |
| 143 | }; |
| 144 | |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 145 | static const char * const aic31xx_supply_names[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 146 | "HPVDD", |
| 147 | "SPRVDD", |
| 148 | "SPLVDD", |
| 149 | "AVDD", |
| 150 | "IOVDD", |
| 151 | "DVDD", |
| 152 | }; |
| 153 | |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 154 | #define AIC31XX_NUM_SUPPLIES ARRAY_SIZE(aic31xx_supply_names) |
| 155 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 156 | struct aic31xx_disable_nb { |
| 157 | struct notifier_block nb; |
| 158 | struct aic31xx_priv *aic31xx; |
| 159 | }; |
| 160 | |
| 161 | struct aic31xx_priv { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 162 | struct snd_soc_component *component; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 163 | u8 i2c_regs_status; |
| 164 | struct device *dev; |
| 165 | struct regmap *regmap; |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 166 | enum aic31xx_type codec_type; |
Andrew F. Davis | b6b247c | 2017-11-29 15:32:49 -0600 | [diff] [blame] | 167 | struct gpio_desc *gpio_reset; |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 168 | int micbias_vg; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 169 | struct aic31xx_pdata pdata; |
| 170 | struct regulator_bulk_data supplies[AIC31XX_NUM_SUPPLIES]; |
| 171 | struct aic31xx_disable_nb disable_nb[AIC31XX_NUM_SUPPLIES]; |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 172 | struct snd_soc_jack *jack; |
Ariel D'Alessandro | c5d22d5 | 2021-11-19 12:32:47 -0300 | [diff] [blame] | 173 | u32 sysclk_id; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 174 | unsigned int sysclk; |
Jyri Sarha | 7ed36e9 | 2014-09-03 15:52:34 +0300 | [diff] [blame] | 175 | u8 p_div; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 176 | int rate_div_line; |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 177 | bool master_dapm_route_applied; |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 178 | int irq; |
Lucas Stach | e48fdb5 | 2019-11-18 16:12:06 +0100 | [diff] [blame] | 179 | u8 ocmv; /* output common-mode voltage */ |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | struct aic31xx_rate_divs { |
Jyri Sarha | 7ed36e9 | 2014-09-03 15:52:34 +0300 | [diff] [blame] | 183 | u32 mclk_p; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 184 | u32 rate; |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 185 | u8 pll_r; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 186 | u8 pll_j; |
| 187 | u16 pll_d; |
| 188 | u16 dosr; |
| 189 | u8 ndac; |
| 190 | u8 mdac; |
| 191 | u8 aosr; |
| 192 | u8 nadc; |
| 193 | u8 madc; |
| 194 | }; |
| 195 | |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 196 | /* ADC dividers can be disabled by configuring them to 0 */ |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 197 | static const struct aic31xx_rate_divs aic31xx_divs[] = { |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 198 | /* mclk/p rate pll: r j d dosr ndac mdac aors nadc madc */ |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 199 | /* 8k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 200 | { 512000, 8000, 4, 48, 0, 128, 48, 2, 128, 48, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 201 | {12000000, 8000, 1, 8, 1920, 128, 48, 2, 128, 48, 2}, |
| 202 | {12000000, 8000, 1, 8, 1920, 128, 32, 3, 128, 32, 3}, |
| 203 | {12500000, 8000, 1, 7, 8643, 128, 48, 2, 128, 48, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 204 | /* 11.025k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 205 | { 705600, 11025, 3, 48, 0, 128, 24, 3, 128, 24, 3}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 206 | {12000000, 11025, 1, 7, 5264, 128, 32, 2, 128, 32, 2}, |
| 207 | {12000000, 11025, 1, 8, 4672, 128, 24, 3, 128, 24, 3}, |
| 208 | {12500000, 11025, 1, 7, 2253, 128, 32, 2, 128, 32, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 209 | /* 16k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 210 | { 512000, 16000, 4, 48, 0, 128, 16, 3, 128, 16, 3}, |
| 211 | { 1024000, 16000, 2, 48, 0, 128, 16, 3, 128, 16, 3}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 212 | {12000000, 16000, 1, 8, 1920, 128, 24, 2, 128, 24, 2}, |
| 213 | {12000000, 16000, 1, 8, 1920, 128, 16, 3, 128, 16, 3}, |
| 214 | {12500000, 16000, 1, 7, 8643, 128, 24, 2, 128, 24, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 215 | /* 22.05k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 216 | { 705600, 22050, 4, 36, 0, 128, 12, 3, 128, 12, 3}, |
| 217 | { 1411200, 22050, 2, 36, 0, 128, 12, 3, 128, 12, 3}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 218 | {12000000, 22050, 1, 7, 5264, 128, 16, 2, 128, 16, 2}, |
| 219 | {12000000, 22050, 1, 8, 4672, 128, 12, 3, 128, 12, 3}, |
| 220 | {12500000, 22050, 1, 7, 2253, 128, 16, 2, 128, 16, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 221 | /* 32k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 222 | { 1024000, 32000, 2, 48, 0, 128, 12, 2, 128, 12, 2}, |
| 223 | { 2048000, 32000, 1, 48, 0, 128, 12, 2, 128, 12, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 224 | {12000000, 32000, 1, 8, 1920, 128, 12, 2, 128, 12, 2}, |
| 225 | {12000000, 32000, 1, 8, 1920, 128, 8, 3, 128, 8, 3}, |
| 226 | {12500000, 32000, 1, 7, 8643, 128, 12, 2, 128, 12, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 227 | /* 44.1k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 228 | { 1411200, 44100, 2, 32, 0, 128, 8, 2, 128, 8, 2}, |
| 229 | { 2822400, 44100, 1, 32, 0, 128, 8, 2, 128, 8, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 230 | {12000000, 44100, 1, 7, 5264, 128, 8, 2, 128, 8, 2}, |
| 231 | {12000000, 44100, 1, 8, 4672, 128, 6, 3, 128, 6, 3}, |
| 232 | {12500000, 44100, 1, 7, 2253, 128, 8, 2, 128, 8, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 233 | /* 48k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 234 | { 1536000, 48000, 2, 32, 0, 128, 8, 2, 128, 8, 2}, |
| 235 | { 3072000, 48000, 1, 32, 0, 128, 8, 2, 128, 8, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 236 | {12000000, 48000, 1, 8, 1920, 128, 8, 2, 128, 8, 2}, |
| 237 | {12000000, 48000, 1, 7, 6800, 96, 5, 4, 96, 5, 4}, |
| 238 | {12500000, 48000, 1, 7, 8643, 128, 8, 2, 128, 8, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 239 | /* 88.2k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 240 | { 2822400, 88200, 2, 16, 0, 64, 8, 2, 64, 8, 2}, |
| 241 | { 5644800, 88200, 1, 16, 0, 64, 8, 2, 64, 8, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 242 | {12000000, 88200, 1, 7, 5264, 64, 8, 2, 64, 8, 2}, |
| 243 | {12000000, 88200, 1, 8, 4672, 64, 6, 3, 64, 6, 3}, |
| 244 | {12500000, 88200, 1, 7, 2253, 64, 8, 2, 64, 8, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 245 | /* 96k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 246 | { 3072000, 96000, 2, 16, 0, 64, 8, 2, 64, 8, 2}, |
| 247 | { 6144000, 96000, 1, 16, 0, 64, 8, 2, 64, 8, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 248 | {12000000, 96000, 1, 8, 1920, 64, 8, 2, 64, 8, 2}, |
| 249 | {12000000, 96000, 1, 7, 6800, 48, 5, 4, 48, 5, 4}, |
| 250 | {12500000, 96000, 1, 7, 8643, 64, 8, 2, 64, 8, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 251 | /* 176.4k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 252 | { 5644800, 176400, 2, 8, 0, 32, 8, 2, 32, 8, 2}, |
| 253 | {11289600, 176400, 1, 8, 0, 32, 8, 2, 32, 8, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 254 | {12000000, 176400, 1, 7, 5264, 32, 8, 2, 32, 8, 2}, |
| 255 | {12000000, 176400, 1, 8, 4672, 32, 6, 3, 32, 6, 3}, |
| 256 | {12500000, 176400, 1, 7, 2253, 32, 8, 2, 32, 8, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 257 | /* 192k rate */ |
Ariel D'Alessandro | 6e6752a | 2021-11-19 12:32:46 -0300 | [diff] [blame] | 258 | { 6144000, 192000, 2, 8, 0, 32, 8, 2, 32, 8, 2}, |
| 259 | {12288000, 192000, 1, 8, 0, 32, 8, 2, 32, 8, 2}, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 260 | {12000000, 192000, 1, 8, 1920, 32, 8, 2, 32, 8, 2}, |
| 261 | {12000000, 192000, 1, 7, 6800, 24, 5, 4, 24, 5, 4}, |
| 262 | {12500000, 192000, 1, 7, 8643, 32, 8, 2, 32, 8, 2}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | static const char * const ldac_in_text[] = { |
| 266 | "Off", "Left Data", "Right Data", "Mono" |
| 267 | }; |
| 268 | |
| 269 | static const char * const rdac_in_text[] = { |
| 270 | "Off", "Right Data", "Left Data", "Mono" |
| 271 | }; |
| 272 | |
| 273 | static SOC_ENUM_SINGLE_DECL(ldac_in_enum, AIC31XX_DACSETUP, 4, ldac_in_text); |
| 274 | |
| 275 | static SOC_ENUM_SINGLE_DECL(rdac_in_enum, AIC31XX_DACSETUP, 2, rdac_in_text); |
| 276 | |
| 277 | static const char * const mic_select_text[] = { |
| 278 | "Off", "FFR 10 Ohm", "FFR 20 Ohm", "FFR 40 Ohm" |
| 279 | }; |
| 280 | |
Lars-Peter Clausen | 914bc16 | 2014-06-19 09:40:27 +0200 | [diff] [blame] | 281 | static SOC_ENUM_SINGLE_DECL(mic1lp_p_enum, AIC31XX_MICPGAPI, 6, |
| 282 | mic_select_text); |
| 283 | static SOC_ENUM_SINGLE_DECL(mic1rp_p_enum, AIC31XX_MICPGAPI, 4, |
| 284 | mic_select_text); |
| 285 | static SOC_ENUM_SINGLE_DECL(mic1lm_p_enum, AIC31XX_MICPGAPI, 2, |
| 286 | mic_select_text); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 287 | |
Lars-Peter Clausen | 914bc16 | 2014-06-19 09:40:27 +0200 | [diff] [blame] | 288 | static SOC_ENUM_SINGLE_DECL(mic1lm_m_enum, AIC31XX_MICPGAMI, 4, |
| 289 | mic_select_text); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 290 | |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 291 | static const char * const hp_poweron_time_text[] = { |
| 292 | "0us", "15.3us", "153us", "1.53ms", "15.3ms", "76.2ms", |
| 293 | "153ms", "304ms", "610ms", "1.22s", "3.04s", "6.1s" }; |
| 294 | |
| 295 | static SOC_ENUM_SINGLE_DECL(hp_poweron_time_enum, AIC31XX_HPPOP, 3, |
| 296 | hp_poweron_time_text); |
| 297 | |
| 298 | static const char * const hp_rampup_step_text[] = { |
| 299 | "0ms", "0.98ms", "1.95ms", "3.9ms" }; |
| 300 | |
| 301 | static SOC_ENUM_SINGLE_DECL(hp_rampup_step_enum, AIC31XX_HPPOP, 1, |
| 302 | hp_rampup_step_text); |
| 303 | |
Nikita Yushchenko | 3176f94 | 2019-11-29 16:27:19 +0300 | [diff] [blame] | 304 | static const char * const vol_soft_step_mode_text[] = { |
| 305 | "fast", "slow", "disabled" }; |
| 306 | |
| 307 | static SOC_ENUM_SINGLE_DECL(vol_soft_step_mode_enum, AIC31XX_DACSETUP, 0, |
| 308 | vol_soft_step_mode_text); |
| 309 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 310 | static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6350, 50, 0); |
| 311 | static const DECLARE_TLV_DB_SCALE(adc_fgain_tlv, 0, 10, 0); |
| 312 | static const DECLARE_TLV_DB_SCALE(adc_cgain_tlv, -2000, 50, 0); |
| 313 | static const DECLARE_TLV_DB_SCALE(mic_pga_tlv, 0, 50, 0); |
| 314 | static const DECLARE_TLV_DB_SCALE(hp_drv_tlv, 0, 100, 0); |
| 315 | static const DECLARE_TLV_DB_SCALE(class_D_drv_tlv, 600, 600, 0); |
| 316 | static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -6350, 50, 0); |
| 317 | static const DECLARE_TLV_DB_SCALE(sp_vol_tlv, -6350, 50, 0); |
| 318 | |
| 319 | /* |
| 320 | * controls to be exported to the user space |
| 321 | */ |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 322 | static const struct snd_kcontrol_new common31xx_snd_controls[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 323 | SOC_DOUBLE_R_S_TLV("DAC Playback Volume", AIC31XX_LDACVOL, |
| 324 | AIC31XX_RDACVOL, 0, -127, 48, 7, 0, dac_vol_tlv), |
| 325 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 326 | SOC_DOUBLE_R("HP Driver Playback Switch", AIC31XX_HPLGAIN, |
| 327 | AIC31XX_HPRGAIN, 2, 1, 0), |
| 328 | SOC_DOUBLE_R_TLV("HP Driver Playback Volume", AIC31XX_HPLGAIN, |
| 329 | AIC31XX_HPRGAIN, 3, 0x09, 0, hp_drv_tlv), |
| 330 | |
| 331 | SOC_DOUBLE_R_TLV("HP Analog Playback Volume", AIC31XX_LANALOGHPL, |
| 332 | AIC31XX_RANALOGHPR, 0, 0x7F, 1, hp_vol_tlv), |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 333 | |
| 334 | /* HP de-pop control: apply power not immediately but via ramp |
| 335 | * function with these psarameters. Note that power up sequence |
| 336 | * has to wait for this to complete; this is implemented by |
| 337 | * polling HP driver status in aic31xx_dapm_power_event() |
| 338 | */ |
| 339 | SOC_ENUM("HP Output Driver Power-On time", hp_poweron_time_enum), |
| 340 | SOC_ENUM("HP Output Driver Ramp-up step", hp_rampup_step_enum), |
Nikita Yushchenko | 3176f94 | 2019-11-29 16:27:19 +0300 | [diff] [blame] | 341 | |
| 342 | SOC_ENUM("Volume Soft Stepping", vol_soft_step_mode_enum), |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | static const struct snd_kcontrol_new aic31xx_snd_controls[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 346 | SOC_SINGLE_TLV("ADC Fine Capture Volume", AIC31XX_ADCFGA, 4, 4, 1, |
| 347 | adc_fgain_tlv), |
| 348 | |
| 349 | SOC_SINGLE("ADC Capture Switch", AIC31XX_ADCFGA, 7, 1, 1), |
| 350 | SOC_DOUBLE_R_S_TLV("ADC Capture Volume", AIC31XX_ADCVOL, AIC31XX_ADCVOL, |
| 351 | 0, -24, 40, 6, 0, adc_cgain_tlv), |
| 352 | |
| 353 | SOC_SINGLE_TLV("Mic PGA Capture Volume", AIC31XX_MICPGA, 0, |
| 354 | 119, 0, mic_pga_tlv), |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | static const struct snd_kcontrol_new aic311x_snd_controls[] = { |
| 358 | SOC_DOUBLE_R("Speaker Driver Playback Switch", AIC31XX_SPLGAIN, |
| 359 | AIC31XX_SPRGAIN, 2, 1, 0), |
| 360 | SOC_DOUBLE_R_TLV("Speaker Driver Playback Volume", AIC31XX_SPLGAIN, |
| 361 | AIC31XX_SPRGAIN, 3, 3, 0, class_D_drv_tlv), |
| 362 | |
| 363 | SOC_DOUBLE_R_TLV("Speaker Analog Playback Volume", AIC31XX_LANALOGSPL, |
| 364 | AIC31XX_RANALOGSPR, 0, 0x7F, 1, sp_vol_tlv), |
| 365 | }; |
| 366 | |
| 367 | static const struct snd_kcontrol_new aic310x_snd_controls[] = { |
| 368 | SOC_SINGLE("Speaker Driver Playback Switch", AIC31XX_SPLGAIN, |
| 369 | 2, 1, 0), |
| 370 | SOC_SINGLE_TLV("Speaker Driver Playback Volume", AIC31XX_SPLGAIN, |
| 371 | 3, 3, 0, class_D_drv_tlv), |
| 372 | |
| 373 | SOC_SINGLE_TLV("Speaker Analog Playback Volume", AIC31XX_LANALOGSPL, |
| 374 | 0, 0x7F, 1, sp_vol_tlv), |
| 375 | }; |
| 376 | |
| 377 | static const struct snd_kcontrol_new ldac_in_control = |
| 378 | SOC_DAPM_ENUM("DAC Left Input", ldac_in_enum); |
| 379 | |
| 380 | static const struct snd_kcontrol_new rdac_in_control = |
| 381 | SOC_DAPM_ENUM("DAC Right Input", rdac_in_enum); |
| 382 | |
Mark Brown | 9296f4d | 2014-03-13 17:44:22 +0000 | [diff] [blame] | 383 | static int aic31xx_wait_bits(struct aic31xx_priv *aic31xx, unsigned int reg, |
| 384 | unsigned int mask, unsigned int wbits, int sleep, |
| 385 | int count) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 386 | { |
| 387 | unsigned int bits; |
| 388 | int counter = count; |
| 389 | int ret = regmap_read(aic31xx->regmap, reg, &bits); |
Shahina Shaik | 423ca88 | 2014-06-13 11:56:54 +0530 | [diff] [blame] | 390 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 391 | while ((bits & mask) != wbits && counter && !ret) { |
| 392 | usleep_range(sleep, sleep * 2); |
| 393 | ret = regmap_read(aic31xx->regmap, reg, &bits); |
| 394 | counter--; |
| 395 | } |
| 396 | if ((bits & mask) != wbits) { |
| 397 | dev_err(aic31xx->dev, |
| 398 | "%s: Failed! 0x%x was 0x%x expected 0x%x (%d, 0x%x, %d us)\n", |
| 399 | __func__, reg, bits, wbits, ret, mask, |
| 400 | (count - counter) * sleep); |
| 401 | ret = -1; |
| 402 | } |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | #define WIDGET_BIT(reg, shift) (((shift) << 8) | (reg)) |
| 407 | |
| 408 | static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w, |
| 409 | struct snd_kcontrol *kcontrol, int event) |
| 410 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 411 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 412 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 413 | unsigned int reg = AIC31XX_DACFLAG1; |
| 414 | unsigned int mask; |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 415 | unsigned int timeout = 500 * USEC_PER_MSEC; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 416 | |
| 417 | switch (WIDGET_BIT(w->reg, w->shift)) { |
| 418 | case WIDGET_BIT(AIC31XX_DACSETUP, 7): |
| 419 | mask = AIC31XX_LDACPWRSTATUS_MASK; |
| 420 | break; |
| 421 | case WIDGET_BIT(AIC31XX_DACSETUP, 6): |
| 422 | mask = AIC31XX_RDACPWRSTATUS_MASK; |
| 423 | break; |
| 424 | case WIDGET_BIT(AIC31XX_HPDRIVER, 7): |
| 425 | mask = AIC31XX_HPLDRVPWRSTATUS_MASK; |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 426 | if (event == SND_SOC_DAPM_POST_PMU) |
| 427 | timeout = 7 * USEC_PER_SEC; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 428 | break; |
| 429 | case WIDGET_BIT(AIC31XX_HPDRIVER, 6): |
| 430 | mask = AIC31XX_HPRDRVPWRSTATUS_MASK; |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 431 | if (event == SND_SOC_DAPM_POST_PMU) |
| 432 | timeout = 7 * USEC_PER_SEC; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 433 | break; |
| 434 | case WIDGET_BIT(AIC31XX_SPKAMP, 7): |
| 435 | mask = AIC31XX_SPLDRVPWRSTATUS_MASK; |
| 436 | break; |
| 437 | case WIDGET_BIT(AIC31XX_SPKAMP, 6): |
| 438 | mask = AIC31XX_SPRDRVPWRSTATUS_MASK; |
| 439 | break; |
| 440 | case WIDGET_BIT(AIC31XX_ADCSETUP, 7): |
| 441 | mask = AIC31XX_ADCPWRSTATUS_MASK; |
| 442 | reg = AIC31XX_ADCFLAG; |
| 443 | break; |
| 444 | default: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 445 | dev_err(component->dev, "Unknown widget '%s' calling %s\n", |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 446 | w->name, __func__); |
| 447 | return -EINVAL; |
| 448 | } |
| 449 | |
| 450 | switch (event) { |
| 451 | case SND_SOC_DAPM_POST_PMU: |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 452 | return aic31xx_wait_bits(aic31xx, reg, mask, mask, |
| 453 | 5000, timeout / 5000); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 454 | case SND_SOC_DAPM_POST_PMD: |
Nikita Yushchenko | 0bb1306 | 2019-11-28 16:54:47 +0300 | [diff] [blame] | 455 | return aic31xx_wait_bits(aic31xx, reg, mask, 0, |
| 456 | 5000, timeout / 5000); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 457 | default: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 458 | dev_dbg(component->dev, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 459 | "Unhandled dapm widget event %d from %s\n", |
| 460 | event, w->name); |
| 461 | } |
| 462 | return 0; |
| 463 | } |
| 464 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 465 | static const struct snd_kcontrol_new aic31xx_left_output_switches[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 466 | SOC_DAPM_SINGLE("From Left DAC", AIC31XX_DACMIXERROUTE, 6, 1, 0), |
| 467 | SOC_DAPM_SINGLE("From MIC1LP", AIC31XX_DACMIXERROUTE, 5, 1, 0), |
| 468 | SOC_DAPM_SINGLE("From MIC1RP", AIC31XX_DACMIXERROUTE, 4, 1, 0), |
| 469 | }; |
| 470 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 471 | static const struct snd_kcontrol_new aic31xx_right_output_switches[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 472 | SOC_DAPM_SINGLE("From Right DAC", AIC31XX_DACMIXERROUTE, 2, 1, 0), |
| 473 | SOC_DAPM_SINGLE("From MIC1RP", AIC31XX_DACMIXERROUTE, 1, 1, 0), |
| 474 | }; |
| 475 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 476 | static const struct snd_kcontrol_new dac31xx_left_output_switches[] = { |
| 477 | SOC_DAPM_SINGLE("From Left DAC", AIC31XX_DACMIXERROUTE, 6, 1, 0), |
| 478 | SOC_DAPM_SINGLE("From AIN1", AIC31XX_DACMIXERROUTE, 5, 1, 0), |
| 479 | SOC_DAPM_SINGLE("From AIN2", AIC31XX_DACMIXERROUTE, 4, 1, 0), |
| 480 | }; |
| 481 | |
| 482 | static const struct snd_kcontrol_new dac31xx_right_output_switches[] = { |
| 483 | SOC_DAPM_SINGLE("From Right DAC", AIC31XX_DACMIXERROUTE, 2, 1, 0), |
| 484 | SOC_DAPM_SINGLE("From AIN2", AIC31XX_DACMIXERROUTE, 1, 1, 0), |
| 485 | }; |
| 486 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 487 | static const struct snd_kcontrol_new p_term_mic1lp = |
| 488 | SOC_DAPM_ENUM("MIC1LP P-Terminal", mic1lp_p_enum); |
| 489 | |
| 490 | static const struct snd_kcontrol_new p_term_mic1rp = |
| 491 | SOC_DAPM_ENUM("MIC1RP P-Terminal", mic1rp_p_enum); |
| 492 | |
| 493 | static const struct snd_kcontrol_new p_term_mic1lm = |
| 494 | SOC_DAPM_ENUM("MIC1LM P-Terminal", mic1lm_p_enum); |
| 495 | |
| 496 | static const struct snd_kcontrol_new m_term_mic1lm = |
| 497 | SOC_DAPM_ENUM("MIC1LM M-Terminal", mic1lm_m_enum); |
| 498 | |
| 499 | static const struct snd_kcontrol_new aic31xx_dapm_hpl_switch = |
| 500 | SOC_DAPM_SINGLE("Switch", AIC31XX_LANALOGHPL, 7, 1, 0); |
| 501 | |
| 502 | static const struct snd_kcontrol_new aic31xx_dapm_hpr_switch = |
| 503 | SOC_DAPM_SINGLE("Switch", AIC31XX_RANALOGHPR, 7, 1, 0); |
| 504 | |
| 505 | static const struct snd_kcontrol_new aic31xx_dapm_spl_switch = |
| 506 | SOC_DAPM_SINGLE("Switch", AIC31XX_LANALOGSPL, 7, 1, 0); |
| 507 | |
| 508 | static const struct snd_kcontrol_new aic31xx_dapm_spr_switch = |
| 509 | SOC_DAPM_SINGLE("Switch", AIC31XX_RANALOGSPR, 7, 1, 0); |
| 510 | |
| 511 | static int mic_bias_event(struct snd_soc_dapm_widget *w, |
| 512 | struct snd_kcontrol *kcontrol, int event) |
| 513 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 514 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 515 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Shahina Shaik | 423ca88 | 2014-06-13 11:56:54 +0530 | [diff] [blame] | 516 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 517 | switch (event) { |
| 518 | case SND_SOC_DAPM_POST_PMU: |
| 519 | /* change mic bias voltage to user defined */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 520 | snd_soc_component_update_bits(component, AIC31XX_MICBIAS, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 521 | AIC31XX_MICBIAS_MASK, |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 522 | aic31xx->micbias_vg << |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 523 | AIC31XX_MICBIAS_SHIFT); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 524 | dev_dbg(component->dev, "%s: turned on\n", __func__); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 525 | break; |
| 526 | case SND_SOC_DAPM_PRE_PMD: |
| 527 | /* turn mic bias off */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 528 | snd_soc_component_update_bits(component, AIC31XX_MICBIAS, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 529 | AIC31XX_MICBIAS_MASK, 0); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 530 | dev_dbg(component->dev, "%s: turned off\n", __func__); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 531 | break; |
| 532 | } |
| 533 | return 0; |
| 534 | } |
| 535 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 536 | static const struct snd_soc_dapm_widget common31xx_dapm_widgets[] = { |
Peter Ujfalusi | 7d41bc2 | 2018-02-19 11:45:07 +0200 | [diff] [blame] | 537 | SND_SOC_DAPM_AIF_IN("AIF IN", "Playback", 0, SND_SOC_NOPM, 0, 0), |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 538 | |
| 539 | SND_SOC_DAPM_MUX("DAC Left Input", |
| 540 | SND_SOC_NOPM, 0, 0, &ldac_in_control), |
| 541 | SND_SOC_DAPM_MUX("DAC Right Input", |
| 542 | SND_SOC_NOPM, 0, 0, &rdac_in_control), |
| 543 | /* DACs */ |
| 544 | SND_SOC_DAPM_DAC_E("DAC Left", "Left Playback", |
| 545 | AIC31XX_DACSETUP, 7, 0, aic31xx_dapm_power_event, |
| 546 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 547 | |
| 548 | SND_SOC_DAPM_DAC_E("DAC Right", "Right Playback", |
| 549 | AIC31XX_DACSETUP, 6, 0, aic31xx_dapm_power_event, |
| 550 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 551 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 552 | /* HP */ |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 553 | SND_SOC_DAPM_SWITCH("HP Left", SND_SOC_NOPM, 0, 0, |
| 554 | &aic31xx_dapm_hpl_switch), |
| 555 | SND_SOC_DAPM_SWITCH("HP Right", SND_SOC_NOPM, 0, 0, |
| 556 | &aic31xx_dapm_hpr_switch), |
| 557 | |
| 558 | /* Output drivers */ |
| 559 | SND_SOC_DAPM_OUT_DRV_E("HPL Driver", AIC31XX_HPDRIVER, 7, 0, |
| 560 | NULL, 0, aic31xx_dapm_power_event, |
| 561 | SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU), |
| 562 | SND_SOC_DAPM_OUT_DRV_E("HPR Driver", AIC31XX_HPDRIVER, 6, 0, |
| 563 | NULL, 0, aic31xx_dapm_power_event, |
| 564 | SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU), |
| 565 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 566 | /* Mic Bias */ |
| 567 | SND_SOC_DAPM_SUPPLY("MICBIAS", SND_SOC_NOPM, 0, 0, mic_bias_event, |
| 568 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 569 | |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 570 | /* Keep BCLK/WCLK enabled even if DAC/ADC is powered down */ |
| 571 | SND_SOC_DAPM_SUPPLY("Activate I2S clocks", AIC31XX_IFACE2, 2, 0, |
| 572 | NULL, 0), |
| 573 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 574 | /* Outputs */ |
| 575 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 576 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 577 | }; |
| 578 | |
| 579 | static const struct snd_soc_dapm_widget dac31xx_dapm_widgets[] = { |
| 580 | /* Inputs */ |
| 581 | SND_SOC_DAPM_INPUT("AIN1"), |
| 582 | SND_SOC_DAPM_INPUT("AIN2"), |
| 583 | |
| 584 | /* Output Mixers */ |
| 585 | SND_SOC_DAPM_MIXER("Output Left", SND_SOC_NOPM, 0, 0, |
| 586 | dac31xx_left_output_switches, |
| 587 | ARRAY_SIZE(dac31xx_left_output_switches)), |
| 588 | SND_SOC_DAPM_MIXER("Output Right", SND_SOC_NOPM, 0, 0, |
| 589 | dac31xx_right_output_switches, |
| 590 | ARRAY_SIZE(dac31xx_right_output_switches)), |
| 591 | }; |
| 592 | |
| 593 | static const struct snd_soc_dapm_widget aic31xx_dapm_widgets[] = { |
| 594 | /* Inputs */ |
| 595 | SND_SOC_DAPM_INPUT("MIC1LP"), |
| 596 | SND_SOC_DAPM_INPUT("MIC1RP"), |
| 597 | SND_SOC_DAPM_INPUT("MIC1LM"), |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 598 | |
| 599 | /* Input Selection to MIC_PGA */ |
| 600 | SND_SOC_DAPM_MUX("MIC1LP P-Terminal", SND_SOC_NOPM, 0, 0, |
| 601 | &p_term_mic1lp), |
| 602 | SND_SOC_DAPM_MUX("MIC1RP P-Terminal", SND_SOC_NOPM, 0, 0, |
| 603 | &p_term_mic1rp), |
| 604 | SND_SOC_DAPM_MUX("MIC1LM P-Terminal", SND_SOC_NOPM, 0, 0, |
| 605 | &p_term_mic1lm), |
| 606 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 607 | /* ADC */ |
| 608 | SND_SOC_DAPM_ADC_E("ADC", "Capture", AIC31XX_ADCSETUP, 7, 0, |
| 609 | aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU | |
| 610 | SND_SOC_DAPM_POST_PMD), |
| 611 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 612 | SND_SOC_DAPM_MUX("MIC1LM M-Terminal", SND_SOC_NOPM, 0, 0, |
| 613 | &m_term_mic1lm), |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 614 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 615 | /* Enabling & Disabling MIC Gain Ctl */ |
| 616 | SND_SOC_DAPM_PGA("MIC_GAIN_CTL", AIC31XX_MICPGA, |
| 617 | 7, 1, NULL, 0), |
| 618 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 619 | /* Output Mixers */ |
| 620 | SND_SOC_DAPM_MIXER("Output Left", SND_SOC_NOPM, 0, 0, |
| 621 | aic31xx_left_output_switches, |
| 622 | ARRAY_SIZE(aic31xx_left_output_switches)), |
| 623 | SND_SOC_DAPM_MIXER("Output Right", SND_SOC_NOPM, 0, 0, |
| 624 | aic31xx_right_output_switches, |
| 625 | ARRAY_SIZE(aic31xx_right_output_switches)), |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 626 | |
| 627 | SND_SOC_DAPM_AIF_OUT("AIF OUT", "Capture", 0, SND_SOC_NOPM, 0, 0), |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 628 | }; |
| 629 | |
| 630 | static const struct snd_soc_dapm_widget aic311x_dapm_widgets[] = { |
| 631 | /* AIC3111 and AIC3110 have stereo class-D amplifier */ |
| 632 | SND_SOC_DAPM_OUT_DRV_E("SPL ClassD", AIC31XX_SPKAMP, 7, 0, NULL, 0, |
| 633 | aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU | |
| 634 | SND_SOC_DAPM_POST_PMD), |
| 635 | SND_SOC_DAPM_OUT_DRV_E("SPR ClassD", AIC31XX_SPKAMP, 6, 0, NULL, 0, |
| 636 | aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU | |
| 637 | SND_SOC_DAPM_POST_PMD), |
| 638 | SND_SOC_DAPM_SWITCH("Speaker Left", SND_SOC_NOPM, 0, 0, |
| 639 | &aic31xx_dapm_spl_switch), |
| 640 | SND_SOC_DAPM_SWITCH("Speaker Right", SND_SOC_NOPM, 0, 0, |
| 641 | &aic31xx_dapm_spr_switch), |
| 642 | SND_SOC_DAPM_OUTPUT("SPL"), |
| 643 | SND_SOC_DAPM_OUTPUT("SPR"), |
| 644 | }; |
| 645 | |
| 646 | /* AIC3100 and AIC3120 have only mono class-D amplifier */ |
| 647 | static const struct snd_soc_dapm_widget aic310x_dapm_widgets[] = { |
| 648 | SND_SOC_DAPM_OUT_DRV_E("SPK ClassD", AIC31XX_SPKAMP, 7, 0, NULL, 0, |
| 649 | aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU | |
| 650 | SND_SOC_DAPM_POST_PMD), |
| 651 | SND_SOC_DAPM_SWITCH("Speaker", SND_SOC_NOPM, 0, 0, |
| 652 | &aic31xx_dapm_spl_switch), |
| 653 | SND_SOC_DAPM_OUTPUT("SPK"), |
| 654 | }; |
| 655 | |
| 656 | static const struct snd_soc_dapm_route |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 657 | common31xx_audio_map[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 658 | /* DAC Input Routing */ |
Peter Ujfalusi | 7d41bc2 | 2018-02-19 11:45:07 +0200 | [diff] [blame] | 659 | {"DAC Left Input", "Left Data", "AIF IN"}, |
| 660 | {"DAC Left Input", "Right Data", "AIF IN"}, |
| 661 | {"DAC Left Input", "Mono", "AIF IN"}, |
| 662 | {"DAC Right Input", "Left Data", "AIF IN"}, |
| 663 | {"DAC Right Input", "Right Data", "AIF IN"}, |
| 664 | {"DAC Right Input", "Mono", "AIF IN"}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 665 | {"DAC Left", NULL, "DAC Left Input"}, |
| 666 | {"DAC Right", NULL, "DAC Right Input"}, |
| 667 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 668 | /* HPL path */ |
| 669 | {"HP Left", "Switch", "Output Left"}, |
| 670 | {"HPL Driver", NULL, "HP Left"}, |
| 671 | {"HPL", NULL, "HPL Driver"}, |
| 672 | |
| 673 | /* HPR path */ |
| 674 | {"HP Right", "Switch", "Output Right"}, |
| 675 | {"HPR Driver", NULL, "HP Right"}, |
| 676 | {"HPR", NULL, "HPR Driver"}, |
| 677 | }; |
| 678 | |
| 679 | static const struct snd_soc_dapm_route |
| 680 | dac31xx_audio_map[] = { |
| 681 | /* Left Output */ |
| 682 | {"Output Left", "From Left DAC", "DAC Left"}, |
| 683 | {"Output Left", "From AIN1", "AIN1"}, |
| 684 | {"Output Left", "From AIN2", "AIN2"}, |
| 685 | |
| 686 | /* Right Output */ |
| 687 | {"Output Right", "From Right DAC", "DAC Right"}, |
| 688 | {"Output Right", "From AIN2", "AIN2"}, |
| 689 | }; |
| 690 | |
| 691 | static const struct snd_soc_dapm_route |
| 692 | aic31xx_audio_map[] = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 693 | /* Mic input */ |
| 694 | {"MIC1LP P-Terminal", "FFR 10 Ohm", "MIC1LP"}, |
| 695 | {"MIC1LP P-Terminal", "FFR 20 Ohm", "MIC1LP"}, |
| 696 | {"MIC1LP P-Terminal", "FFR 40 Ohm", "MIC1LP"}, |
| 697 | {"MIC1RP P-Terminal", "FFR 10 Ohm", "MIC1RP"}, |
| 698 | {"MIC1RP P-Terminal", "FFR 20 Ohm", "MIC1RP"}, |
| 699 | {"MIC1RP P-Terminal", "FFR 40 Ohm", "MIC1RP"}, |
| 700 | {"MIC1LM P-Terminal", "FFR 10 Ohm", "MIC1LM"}, |
| 701 | {"MIC1LM P-Terminal", "FFR 20 Ohm", "MIC1LM"}, |
| 702 | {"MIC1LM P-Terminal", "FFR 40 Ohm", "MIC1LM"}, |
| 703 | |
| 704 | {"MIC1LM M-Terminal", "FFR 10 Ohm", "MIC1LM"}, |
| 705 | {"MIC1LM M-Terminal", "FFR 20 Ohm", "MIC1LM"}, |
| 706 | {"MIC1LM M-Terminal", "FFR 40 Ohm", "MIC1LM"}, |
| 707 | |
| 708 | {"MIC_GAIN_CTL", NULL, "MIC1LP P-Terminal"}, |
| 709 | {"MIC_GAIN_CTL", NULL, "MIC1RP P-Terminal"}, |
| 710 | {"MIC_GAIN_CTL", NULL, "MIC1LM P-Terminal"}, |
| 711 | {"MIC_GAIN_CTL", NULL, "MIC1LM M-Terminal"}, |
| 712 | |
| 713 | {"ADC", NULL, "MIC_GAIN_CTL"}, |
| 714 | |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 715 | {"AIF OUT", NULL, "ADC"}, |
| 716 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 717 | /* Left Output */ |
| 718 | {"Output Left", "From Left DAC", "DAC Left"}, |
| 719 | {"Output Left", "From MIC1LP", "MIC1LP"}, |
| 720 | {"Output Left", "From MIC1RP", "MIC1RP"}, |
| 721 | |
| 722 | /* Right Output */ |
| 723 | {"Output Right", "From Right DAC", "DAC Right"}, |
| 724 | {"Output Right", "From MIC1RP", "MIC1RP"}, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 725 | }; |
| 726 | |
| 727 | static const struct snd_soc_dapm_route |
| 728 | aic311x_audio_map[] = { |
| 729 | /* SP L path */ |
| 730 | {"Speaker Left", "Switch", "Output Left"}, |
| 731 | {"SPL ClassD", NULL, "Speaker Left"}, |
| 732 | {"SPL", NULL, "SPL ClassD"}, |
| 733 | |
| 734 | /* SP R path */ |
| 735 | {"Speaker Right", "Switch", "Output Right"}, |
| 736 | {"SPR ClassD", NULL, "Speaker Right"}, |
| 737 | {"SPR", NULL, "SPR ClassD"}, |
| 738 | }; |
| 739 | |
| 740 | static const struct snd_soc_dapm_route |
| 741 | aic310x_audio_map[] = { |
| 742 | /* SP L path */ |
| 743 | {"Speaker", "Switch", "Output Left"}, |
| 744 | {"SPK ClassD", NULL, "Speaker"}, |
| 745 | {"SPK", NULL, "SPK ClassD"}, |
| 746 | }; |
| 747 | |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 748 | /* |
| 749 | * Always connected DAPM routes for codec clock master modes. |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 750 | * If the codec is the master on the I2S bus, we need to power up components |
| 751 | * to have valid DAC_CLK. |
| 752 | * |
| 753 | * In order to have the I2S clocks on the bus either the DACs/ADC need to be |
| 754 | * enabled, or the P0/R29/D2 (Keep bclk/wclk in power down) need to be set. |
| 755 | * |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 756 | * Otherwise the codec will not generate clocks on the bus. |
| 757 | */ |
| 758 | static const struct snd_soc_dapm_route |
| 759 | common31xx_cm_audio_map[] = { |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 760 | {"HPL", NULL, "AIF IN"}, |
| 761 | {"HPR", NULL, "AIF IN"}, |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 762 | |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 763 | {"AIF IN", NULL, "Activate I2S clocks"}, |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | static const struct snd_soc_dapm_route |
| 767 | aic31xx_cm_audio_map[] = { |
Peter Ujfalusi | a16be2a | 2018-02-19 11:45:08 +0200 | [diff] [blame] | 768 | {"AIF OUT", NULL, "MIC1LP"}, |
| 769 | {"AIF OUT", NULL, "MIC1RP"}, |
| 770 | {"AIF OUT", NULL, "MIC1LM"}, |
| 771 | |
| 772 | {"AIF OUT", NULL, "Activate I2S clocks"}, |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 773 | }; |
| 774 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 775 | static int aic31xx_add_controls(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 776 | { |
| 777 | int ret = 0; |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 778 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 779 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 780 | if (!(aic31xx->codec_type & DAC31XX_BIT)) |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 781 | ret = snd_soc_add_component_controls( |
| 782 | component, aic31xx_snd_controls, |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 783 | ARRAY_SIZE(aic31xx_snd_controls)); |
| 784 | if (ret) |
| 785 | return ret; |
| 786 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 787 | if (aic31xx->codec_type & AIC31XX_STEREO_CLASS_D_BIT) |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 788 | ret = snd_soc_add_component_controls( |
| 789 | component, aic311x_snd_controls, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 790 | ARRAY_SIZE(aic311x_snd_controls)); |
| 791 | else |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 792 | ret = snd_soc_add_component_controls( |
| 793 | component, aic310x_snd_controls, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 794 | ARRAY_SIZE(aic310x_snd_controls)); |
| 795 | |
| 796 | return ret; |
| 797 | } |
| 798 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 799 | static int aic31xx_add_widgets(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 800 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 801 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
| 802 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 803 | int ret = 0; |
| 804 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 805 | if (aic31xx->codec_type & DAC31XX_BIT) { |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 806 | ret = snd_soc_dapm_new_controls( |
| 807 | dapm, dac31xx_dapm_widgets, |
| 808 | ARRAY_SIZE(dac31xx_dapm_widgets)); |
| 809 | if (ret) |
| 810 | return ret; |
| 811 | |
| 812 | ret = snd_soc_dapm_add_routes(dapm, dac31xx_audio_map, |
| 813 | ARRAY_SIZE(dac31xx_audio_map)); |
| 814 | if (ret) |
| 815 | return ret; |
| 816 | } else { |
| 817 | ret = snd_soc_dapm_new_controls( |
| 818 | dapm, aic31xx_dapm_widgets, |
| 819 | ARRAY_SIZE(aic31xx_dapm_widgets)); |
| 820 | if (ret) |
| 821 | return ret; |
| 822 | |
| 823 | ret = snd_soc_dapm_add_routes(dapm, aic31xx_audio_map, |
| 824 | ARRAY_SIZE(aic31xx_audio_map)); |
| 825 | if (ret) |
| 826 | return ret; |
| 827 | } |
| 828 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 829 | if (aic31xx->codec_type & AIC31XX_STEREO_CLASS_D_BIT) { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 830 | ret = snd_soc_dapm_new_controls( |
| 831 | dapm, aic311x_dapm_widgets, |
| 832 | ARRAY_SIZE(aic311x_dapm_widgets)); |
| 833 | if (ret) |
| 834 | return ret; |
| 835 | |
| 836 | ret = snd_soc_dapm_add_routes(dapm, aic311x_audio_map, |
| 837 | ARRAY_SIZE(aic311x_audio_map)); |
| 838 | if (ret) |
| 839 | return ret; |
| 840 | } else { |
| 841 | ret = snd_soc_dapm_new_controls( |
| 842 | dapm, aic310x_dapm_widgets, |
| 843 | ARRAY_SIZE(aic310x_dapm_widgets)); |
| 844 | if (ret) |
| 845 | return ret; |
| 846 | |
| 847 | ret = snd_soc_dapm_add_routes(dapm, aic310x_audio_map, |
| 848 | ARRAY_SIZE(aic310x_audio_map)); |
| 849 | if (ret) |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 856 | static int aic31xx_setup_pll(struct snd_soc_component *component, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 857 | struct snd_pcm_hw_params *params) |
| 858 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 859 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 860 | int bclk_score = snd_soc_params_to_frame_size(params); |
Andrew F. Davis | c6b8c77 | 2017-11-29 15:32:52 -0600 | [diff] [blame] | 861 | int mclk_p; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 862 | int bclk_n = 0; |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 863 | int match = -1; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 864 | int i; |
| 865 | |
Andrew F. Davis | c6b8c77 | 2017-11-29 15:32:52 -0600 | [diff] [blame] | 866 | if (!aic31xx->sysclk || !aic31xx->p_div) { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 867 | dev_err(component->dev, "Master clock not supplied\n"); |
Andrew F. Davis | c6b8c77 | 2017-11-29 15:32:52 -0600 | [diff] [blame] | 868 | return -EINVAL; |
| 869 | } |
| 870 | mclk_p = aic31xx->sysclk / aic31xx->p_div; |
| 871 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 872 | /* Use PLL as CODEC_CLKIN and DAC_CLK as BDIV_CLKIN */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 873 | snd_soc_component_update_bits(component, AIC31XX_CLKMUX, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 874 | AIC31XX_CODEC_CLKIN_MASK, AIC31XX_CODEC_CLKIN_PLL); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 875 | snd_soc_component_update_bits(component, AIC31XX_IFACE2, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 876 | AIC31XX_BDIVCLK_MASK, AIC31XX_DAC2BCLK); |
| 877 | |
| 878 | for (i = 0; i < ARRAY_SIZE(aic31xx_divs); i++) { |
| 879 | if (aic31xx_divs[i].rate == params_rate(params) && |
Jyri Sarha | 7ed36e9 | 2014-09-03 15:52:34 +0300 | [diff] [blame] | 880 | aic31xx_divs[i].mclk_p == mclk_p) { |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 881 | int s = (aic31xx_divs[i].dosr * aic31xx_divs[i].mdac) % |
| 882 | snd_soc_params_to_frame_size(params); |
| 883 | int bn = (aic31xx_divs[i].dosr * aic31xx_divs[i].mdac) / |
| 884 | snd_soc_params_to_frame_size(params); |
| 885 | if (s < bclk_score && bn > 0) { |
| 886 | match = i; |
| 887 | bclk_n = bn; |
| 888 | bclk_score = s; |
| 889 | } |
| 890 | } |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 891 | } |
| 892 | |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 893 | if (match == -1) { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 894 | dev_err(component->dev, |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 895 | "%s: Sample rate (%u) and format not supported\n", |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 896 | __func__, params_rate(params)); |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 897 | /* See bellow for details how fix this. */ |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 898 | return -EINVAL; |
| 899 | } |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 900 | if (bclk_score != 0) { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 901 | dev_warn(component->dev, "Can not produce exact bitclock"); |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 902 | /* This is fine if using dsp format, but if using i2s |
| 903 | there may be trouble. To fix the issue edit the |
| 904 | aic31xx_divs table for your mclk and sample |
| 905 | rate. Details can be found from: |
Alexander A. Klimov | 5856d8b | 2020-07-19 17:38:22 +0200 | [diff] [blame] | 906 | https://www.ti.com/lit/ds/symlink/tlv320aic3100.pdf |
Jyri Sarha | 03be88e | 2014-09-03 15:52:33 +0300 | [diff] [blame] | 907 | Section: 5.6 CLOCK Generation and PLL |
| 908 | */ |
| 909 | } |
| 910 | i = match; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 911 | |
| 912 | /* PLL configuration */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 913 | snd_soc_component_update_bits(component, AIC31XX_PLLPR, AIC31XX_PLL_MASK, |
Ariel D'Alessandro | 2664b24 | 2021-11-19 12:32:45 -0300 | [diff] [blame] | 914 | (aic31xx->p_div << 4) | aic31xx_divs[i].pll_r); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 915 | snd_soc_component_write(component, AIC31XX_PLLJ, aic31xx_divs[i].pll_j); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 916 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 917 | snd_soc_component_write(component, AIC31XX_PLLDMSB, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 918 | aic31xx_divs[i].pll_d >> 8); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 919 | snd_soc_component_write(component, AIC31XX_PLLDLSB, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 920 | aic31xx_divs[i].pll_d & 0xff); |
| 921 | |
| 922 | /* DAC dividers configuration */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 923 | snd_soc_component_update_bits(component, AIC31XX_NDAC, AIC31XX_PLL_MASK, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 924 | aic31xx_divs[i].ndac); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 925 | snd_soc_component_update_bits(component, AIC31XX_MDAC, AIC31XX_PLL_MASK, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 926 | aic31xx_divs[i].mdac); |
| 927 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 928 | snd_soc_component_write(component, AIC31XX_DOSRMSB, aic31xx_divs[i].dosr >> 8); |
| 929 | snd_soc_component_write(component, AIC31XX_DOSRLSB, aic31xx_divs[i].dosr & 0xff); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 930 | |
| 931 | /* ADC dividers configuration. Write reset value 1 if not used. */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 932 | snd_soc_component_update_bits(component, AIC31XX_NADC, AIC31XX_PLL_MASK, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 933 | aic31xx_divs[i].nadc ? aic31xx_divs[i].nadc : 1); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 934 | snd_soc_component_update_bits(component, AIC31XX_MADC, AIC31XX_PLL_MASK, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 935 | aic31xx_divs[i].madc ? aic31xx_divs[i].madc : 1); |
| 936 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 937 | snd_soc_component_write(component, AIC31XX_AOSR, aic31xx_divs[i].aosr); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 938 | |
| 939 | /* Bit clock divider configuration. */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 940 | snd_soc_component_update_bits(component, AIC31XX_BCLKN, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 941 | AIC31XX_PLL_MASK, bclk_n); |
| 942 | |
| 943 | aic31xx->rate_div_line = i; |
| 944 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 945 | dev_dbg(component->dev, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 946 | "pll %d.%04d/%d dosr %d n %d m %d aosr %d n %d m %d bclk_n %d\n", |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 947 | aic31xx_divs[i].pll_j, |
| 948 | aic31xx_divs[i].pll_d, |
| 949 | aic31xx->p_div, |
| 950 | aic31xx_divs[i].dosr, |
| 951 | aic31xx_divs[i].ndac, |
| 952 | aic31xx_divs[i].mdac, |
| 953 | aic31xx_divs[i].aosr, |
| 954 | aic31xx_divs[i].nadc, |
| 955 | aic31xx_divs[i].madc, |
| 956 | bclk_n |
| 957 | ); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | static int aic31xx_hw_params(struct snd_pcm_substream *substream, |
| 963 | struct snd_pcm_hw_params *params, |
Lars-Peter Clausen | ab64246 | 2014-03-13 21:24:54 +0100 | [diff] [blame] | 964 | struct snd_soc_dai *dai) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 965 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 966 | struct snd_soc_component *component = dai->component; |
Ariel D'Alessandro | c5d22d5 | 2021-11-19 12:32:47 -0300 | [diff] [blame] | 967 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 968 | u8 data = 0; |
| 969 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 970 | dev_dbg(component->dev, "## %s: width %d rate %d\n", |
Mark Brown | 88be681 | 2014-07-31 12:48:13 +0100 | [diff] [blame] | 971 | __func__, params_width(params), |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 972 | params_rate(params)); |
| 973 | |
| 974 | switch (params_width(params)) { |
| 975 | case 16: |
| 976 | break; |
| 977 | case 20: |
| 978 | data = (AIC31XX_WORD_LEN_20BITS << |
| 979 | AIC31XX_IFACE1_DATALEN_SHIFT); |
| 980 | break; |
| 981 | case 24: |
| 982 | data = (AIC31XX_WORD_LEN_24BITS << |
| 983 | AIC31XX_IFACE1_DATALEN_SHIFT); |
| 984 | break; |
| 985 | case 32: |
| 986 | data = (AIC31XX_WORD_LEN_32BITS << |
| 987 | AIC31XX_IFACE1_DATALEN_SHIFT); |
| 988 | break; |
| 989 | default: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 990 | dev_err(component->dev, "%s: Unsupported width %d\n", |
Mark Brown | 88be681 | 2014-07-31 12:48:13 +0100 | [diff] [blame] | 991 | __func__, params_width(params)); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 992 | return -EINVAL; |
| 993 | } |
| 994 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 995 | snd_soc_component_update_bits(component, AIC31XX_IFACE1, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 996 | AIC31XX_IFACE1_DATALEN_MASK, |
| 997 | data); |
| 998 | |
Ariel D'Alessandro | c5d22d5 | 2021-11-19 12:32:47 -0300 | [diff] [blame] | 999 | /* |
| 1000 | * If BCLK is used as PLL input, the sysclk is determined by the hw |
| 1001 | * params. So it must be updated here to match the input frequency. |
| 1002 | */ |
| 1003 | if (aic31xx->sysclk_id == AIC31XX_PLL_CLKIN_BCLK) { |
| 1004 | aic31xx->sysclk = params_rate(params) * params_width(params) * |
| 1005 | params_channels(params); |
| 1006 | aic31xx->p_div = 1; |
| 1007 | } |
| 1008 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1009 | return aic31xx_setup_pll(component, params); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1010 | } |
| 1011 | |
Kuninori Morimoto | 960af79 | 2020-07-09 10:56:25 +0900 | [diff] [blame] | 1012 | static int aic31xx_dac_mute(struct snd_soc_dai *codec_dai, int mute, |
| 1013 | int direction) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1014 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1015 | struct snd_soc_component *component = codec_dai->component; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1016 | |
| 1017 | if (mute) { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1018 | snd_soc_component_update_bits(component, AIC31XX_DACMUTE, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1019 | AIC31XX_DACMUTE_MASK, |
| 1020 | AIC31XX_DACMUTE_MASK); |
| 1021 | } else { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1022 | snd_soc_component_update_bits(component, AIC31XX_DACMUTE, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1023 | AIC31XX_DACMUTE_MASK, 0x0); |
| 1024 | } |
| 1025 | |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 1029 | static int aic31xx_clock_master_routes(struct snd_soc_component *component, |
| 1030 | unsigned int fmt) |
| 1031 | { |
| 1032 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
| 1033 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
| 1034 | int ret; |
| 1035 | |
| 1036 | fmt &= SND_SOC_DAIFMT_MASTER_MASK; |
| 1037 | if (fmt == SND_SOC_DAIFMT_CBS_CFS && |
| 1038 | aic31xx->master_dapm_route_applied) { |
| 1039 | /* |
| 1040 | * Remove the DAPM route(s) for codec clock master modes, |
| 1041 | * if applied |
| 1042 | */ |
| 1043 | ret = snd_soc_dapm_del_routes(dapm, common31xx_cm_audio_map, |
| 1044 | ARRAY_SIZE(common31xx_cm_audio_map)); |
| 1045 | if (!ret && !(aic31xx->codec_type & DAC31XX_BIT)) |
| 1046 | ret = snd_soc_dapm_del_routes(dapm, |
| 1047 | aic31xx_cm_audio_map, |
| 1048 | ARRAY_SIZE(aic31xx_cm_audio_map)); |
| 1049 | |
| 1050 | if (ret) |
| 1051 | return ret; |
| 1052 | |
| 1053 | aic31xx->master_dapm_route_applied = false; |
| 1054 | } else if (fmt != SND_SOC_DAIFMT_CBS_CFS && |
| 1055 | !aic31xx->master_dapm_route_applied) { |
| 1056 | /* |
| 1057 | * Add the needed DAPM route(s) for codec clock master modes, |
| 1058 | * if it is not done already |
| 1059 | */ |
| 1060 | ret = snd_soc_dapm_add_routes(dapm, common31xx_cm_audio_map, |
| 1061 | ARRAY_SIZE(common31xx_cm_audio_map)); |
| 1062 | if (!ret && !(aic31xx->codec_type & DAC31XX_BIT)) |
| 1063 | ret = snd_soc_dapm_add_routes(dapm, |
| 1064 | aic31xx_cm_audio_map, |
| 1065 | ARRAY_SIZE(aic31xx_cm_audio_map)); |
| 1066 | |
| 1067 | if (ret) |
| 1068 | return ret; |
| 1069 | |
| 1070 | aic31xx->master_dapm_route_applied = true; |
| 1071 | } |
| 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1076 | static int aic31xx_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 1077 | unsigned int fmt) |
| 1078 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1079 | struct snd_soc_component *component = codec_dai->component; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1080 | u8 iface_reg1 = 0; |
Peter Ujfalusi | 085f3ec | 2014-09-01 12:46:37 +0300 | [diff] [blame] | 1081 | u8 iface_reg2 = 0; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1082 | u8 dsp_a_val = 0; |
| 1083 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1084 | dev_dbg(component->dev, "## %s: fmt = 0x%x\n", __func__, fmt); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1085 | |
| 1086 | /* set master/slave audio interface */ |
| 1087 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1088 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1089 | iface_reg1 |= AIC31XX_BCLK_MASTER | AIC31XX_WCLK_MASTER; |
| 1090 | break; |
Andrew F. Davis | 77f8b3c | 2017-11-29 15:32:53 -0600 | [diff] [blame] | 1091 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1092 | iface_reg1 |= AIC31XX_WCLK_MASTER; |
| 1093 | break; |
| 1094 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1095 | iface_reg1 |= AIC31XX_BCLK_MASTER; |
| 1096 | break; |
| 1097 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1098 | break; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1099 | default: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1100 | dev_err(component->dev, "Invalid DAI master/slave interface\n"); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | |
Andrew F. Davis | dcb407b | 2017-11-29 15:32:54 -0600 | [diff] [blame] | 1104 | /* signal polarity */ |
| 1105 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1106 | case SND_SOC_DAIFMT_NB_NF: |
| 1107 | break; |
| 1108 | case SND_SOC_DAIFMT_IB_NF: |
| 1109 | iface_reg2 |= AIC31XX_BCLKINV_MASK; |
| 1110 | break; |
| 1111 | default: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1112 | dev_err(component->dev, "Invalid DAI clock signal polarity\n"); |
Andrew F. Davis | dcb407b | 2017-11-29 15:32:54 -0600 | [diff] [blame] | 1113 | return -EINVAL; |
| 1114 | } |
| 1115 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1116 | /* interface format */ |
| 1117 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1118 | case SND_SOC_DAIFMT_I2S: |
| 1119 | break; |
| 1120 | case SND_SOC_DAIFMT_DSP_A: |
Gustavo A. R. Silva | 3e146b5 | 2020-07-08 20:03:59 -0500 | [diff] [blame] | 1121 | dsp_a_val = 0x1; |
| 1122 | fallthrough; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1123 | case SND_SOC_DAIFMT_DSP_B: |
Andrew F. Davis | dcb407b | 2017-11-29 15:32:54 -0600 | [diff] [blame] | 1124 | /* |
| 1125 | * NOTE: This CODEC samples on the falling edge of BCLK in |
| 1126 | * DSP mode, this is inverted compared to what most DAIs |
| 1127 | * expect, so we invert for this mode |
| 1128 | */ |
| 1129 | iface_reg2 ^= AIC31XX_BCLKINV_MASK; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1130 | iface_reg1 |= (AIC31XX_DSP_MODE << |
| 1131 | AIC31XX_IFACE1_DATATYPE_SHIFT); |
| 1132 | break; |
| 1133 | case SND_SOC_DAIFMT_RIGHT_J: |
| 1134 | iface_reg1 |= (AIC31XX_RIGHT_JUSTIFIED_MODE << |
| 1135 | AIC31XX_IFACE1_DATATYPE_SHIFT); |
| 1136 | break; |
| 1137 | case SND_SOC_DAIFMT_LEFT_J: |
| 1138 | iface_reg1 |= (AIC31XX_LEFT_JUSTIFIED_MODE << |
| 1139 | AIC31XX_IFACE1_DATATYPE_SHIFT); |
| 1140 | break; |
| 1141 | default: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1142 | dev_err(component->dev, "Invalid DAI interface format\n"); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1143 | return -EINVAL; |
| 1144 | } |
| 1145 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1146 | snd_soc_component_update_bits(component, AIC31XX_IFACE1, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1147 | AIC31XX_IFACE1_DATATYPE_MASK | |
| 1148 | AIC31XX_IFACE1_MASTER_MASK, |
| 1149 | iface_reg1); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1150 | snd_soc_component_update_bits(component, AIC31XX_DATA_OFFSET, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1151 | AIC31XX_DATA_OFFSET_MASK, |
| 1152 | dsp_a_val); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1153 | snd_soc_component_update_bits(component, AIC31XX_IFACE2, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1154 | AIC31XX_BCLKINV_MASK, |
Peter Ujfalusi | 085f3ec | 2014-09-01 12:46:37 +0300 | [diff] [blame] | 1155 | iface_reg2); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1156 | |
Peter Ujfalusi | d460b3f | 2018-02-14 14:20:56 +0200 | [diff] [blame] | 1157 | return aic31xx_clock_master_routes(component, fmt); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static int aic31xx_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 1161 | int clk_id, unsigned int freq, int dir) |
| 1162 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1163 | struct snd_soc_component *component = codec_dai->component; |
| 1164 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1165 | int i; |
| 1166 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1167 | dev_dbg(component->dev, "## %s: clk_id = %d, freq = %d, dir = %d\n", |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1168 | __func__, clk_id, freq, dir); |
| 1169 | |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1170 | for (i = 1; i < 8; i++) |
| 1171 | if (freq / i <= 20000000) |
| 1172 | break; |
Jyri Sarha | 7ed36e9 | 2014-09-03 15:52:34 +0300 | [diff] [blame] | 1173 | if (freq/i > 20000000) { |
| 1174 | dev_err(aic31xx->dev, "%s: Too high mclk frequency %u\n", |
| 1175 | __func__, freq); |
Colin Ian King | 7806869 | 2018-11-16 15:06:33 +0000 | [diff] [blame] | 1176 | return -EINVAL; |
Jyri Sarha | 7ed36e9 | 2014-09-03 15:52:34 +0300 | [diff] [blame] | 1177 | } |
| 1178 | aic31xx->p_div = i; |
| 1179 | |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1180 | for (i = 0; i < ARRAY_SIZE(aic31xx_divs); i++) |
| 1181 | if (aic31xx_divs[i].mclk_p == freq / aic31xx->p_div) |
| 1182 | break; |
Jyri Sarha | bbc686b | 2014-11-24 20:37:12 +0200 | [diff] [blame] | 1183 | if (i == ARRAY_SIZE(aic31xx_divs)) { |
| 1184 | dev_err(aic31xx->dev, "%s: Unsupported frequency %d\n", |
| 1185 | __func__, freq); |
| 1186 | return -EINVAL; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /* set clock on MCLK, BCLK, or GPIO1 as PLL input */ |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1190 | snd_soc_component_update_bits(component, AIC31XX_CLKMUX, AIC31XX_PLL_CLKIN_MASK, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1191 | clk_id << AIC31XX_PLL_CLKIN_SHIFT); |
| 1192 | |
Ariel D'Alessandro | c5d22d5 | 2021-11-19 12:32:47 -0300 | [diff] [blame] | 1193 | aic31xx->sysclk_id = clk_id; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1194 | aic31xx->sysclk = freq; |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1195 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static int aic31xx_regulator_event(struct notifier_block *nb, |
| 1200 | unsigned long event, void *data) |
| 1201 | { |
| 1202 | struct aic31xx_disable_nb *disable_nb = |
| 1203 | container_of(nb, struct aic31xx_disable_nb, nb); |
| 1204 | struct aic31xx_priv *aic31xx = disable_nb->aic31xx; |
| 1205 | |
| 1206 | if (event & REGULATOR_EVENT_DISABLE) { |
| 1207 | /* |
| 1208 | * Put codec to reset and as at least one of the |
| 1209 | * supplies was disabled. |
| 1210 | */ |
Andrew F. Davis | b6b247c | 2017-11-29 15:32:49 -0600 | [diff] [blame] | 1211 | if (aic31xx->gpio_reset) |
| 1212 | gpiod_set_value(aic31xx->gpio_reset, 1); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1213 | |
| 1214 | regcache_mark_dirty(aic31xx->regmap); |
| 1215 | dev_dbg(aic31xx->dev, "## %s: DISABLE received\n", __func__); |
| 1216 | } |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Andrew F. Davis | 0ce918c | 2017-12-07 09:38:56 -0600 | [diff] [blame] | 1221 | static int aic31xx_reset(struct aic31xx_priv *aic31xx) |
| 1222 | { |
| 1223 | int ret = 0; |
| 1224 | |
| 1225 | if (aic31xx->gpio_reset) { |
| 1226 | gpiod_set_value(aic31xx->gpio_reset, 1); |
| 1227 | ndelay(10); /* At least 10ns */ |
| 1228 | gpiod_set_value(aic31xx->gpio_reset, 0); |
| 1229 | } else { |
| 1230 | ret = regmap_write(aic31xx->regmap, AIC31XX_RESET, 1); |
| 1231 | } |
| 1232 | mdelay(1); /* At least 1ms */ |
| 1233 | |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1237 | static void aic31xx_clk_on(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1238 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1239 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1240 | u8 mask = AIC31XX_PM_MASK; |
| 1241 | u8 on = AIC31XX_PM_MASK; |
| 1242 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1243 | dev_dbg(component->dev, "codec clock -> on (rate %d)\n", |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1244 | aic31xx_divs[aic31xx->rate_div_line].rate); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1245 | snd_soc_component_update_bits(component, AIC31XX_PLLPR, mask, on); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1246 | mdelay(10); |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1247 | snd_soc_component_update_bits(component, AIC31XX_NDAC, mask, on); |
| 1248 | snd_soc_component_update_bits(component, AIC31XX_MDAC, mask, on); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1249 | if (aic31xx_divs[aic31xx->rate_div_line].nadc) |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1250 | snd_soc_component_update_bits(component, AIC31XX_NADC, mask, on); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1251 | if (aic31xx_divs[aic31xx->rate_div_line].madc) |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1252 | snd_soc_component_update_bits(component, AIC31XX_MADC, mask, on); |
| 1253 | snd_soc_component_update_bits(component, AIC31XX_BCLKN, mask, on); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1254 | } |
| 1255 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1256 | static void aic31xx_clk_off(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1257 | { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1258 | u8 mask = AIC31XX_PM_MASK; |
| 1259 | u8 off = 0; |
| 1260 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1261 | dev_dbg(component->dev, "codec clock -> off\n"); |
| 1262 | snd_soc_component_update_bits(component, AIC31XX_BCLKN, mask, off); |
| 1263 | snd_soc_component_update_bits(component, AIC31XX_MADC, mask, off); |
| 1264 | snd_soc_component_update_bits(component, AIC31XX_NADC, mask, off); |
| 1265 | snd_soc_component_update_bits(component, AIC31XX_MDAC, mask, off); |
| 1266 | snd_soc_component_update_bits(component, AIC31XX_NDAC, mask, off); |
| 1267 | snd_soc_component_update_bits(component, AIC31XX_PLLPR, mask, off); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1270 | static int aic31xx_power_on(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1271 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1272 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1273 | int ret; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1274 | |
| 1275 | ret = regulator_bulk_enable(ARRAY_SIZE(aic31xx->supplies), |
| 1276 | aic31xx->supplies); |
| 1277 | if (ret) |
| 1278 | return ret; |
| 1279 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1280 | regcache_cache_only(aic31xx->regmap, false); |
Andrew F. Davis | 0ce918c | 2017-12-07 09:38:56 -0600 | [diff] [blame] | 1281 | |
| 1282 | /* Reset device registers for a consistent power-on like state */ |
| 1283 | ret = aic31xx_reset(aic31xx); |
| 1284 | if (ret < 0) |
| 1285 | dev_err(aic31xx->dev, "Could not reset device: %d\n", ret); |
| 1286 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1287 | ret = regcache_sync(aic31xx->regmap); |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1288 | if (ret) { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1289 | dev_err(component->dev, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1290 | "Failed to restore cache: %d\n", ret); |
| 1291 | regcache_cache_only(aic31xx->regmap, true); |
| 1292 | regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies), |
| 1293 | aic31xx->supplies); |
| 1294 | return ret; |
| 1295 | } |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1296 | |
Mark Brown | 2c39ca6 | 2021-07-23 19:02:00 +0100 | [diff] [blame] | 1297 | /* |
| 1298 | * The jack detection configuration is in the same register |
| 1299 | * that is used to report jack detect status so is volatile |
| 1300 | * and not covered by the cache sync, restore it separately. |
| 1301 | */ |
| 1302 | aic31xx_set_jack(component, aic31xx->jack, NULL); |
| 1303 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1304 | return 0; |
| 1305 | } |
| 1306 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1307 | static void aic31xx_power_off(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1308 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1309 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1310 | |
| 1311 | regcache_cache_only(aic31xx->regmap, true); |
Andrew F. Davis | c7734e8 | 2017-11-29 15:32:43 -0600 | [diff] [blame] | 1312 | regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies), |
| 1313 | aic31xx->supplies); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1314 | } |
| 1315 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1316 | static int aic31xx_set_bias_level(struct snd_soc_component *component, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1317 | enum snd_soc_bias_level level) |
| 1318 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1319 | dev_dbg(component->dev, "## %s: %d -> %d\n", __func__, |
| 1320 | snd_soc_component_get_bias_level(component), level); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1321 | |
| 1322 | switch (level) { |
| 1323 | case SND_SOC_BIAS_ON: |
| 1324 | break; |
| 1325 | case SND_SOC_BIAS_PREPARE: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1326 | if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) |
| 1327 | aic31xx_clk_on(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1328 | break; |
| 1329 | case SND_SOC_BIAS_STANDBY: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1330 | switch (snd_soc_component_get_bias_level(component)) { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1331 | case SND_SOC_BIAS_OFF: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1332 | aic31xx_power_on(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1333 | break; |
| 1334 | case SND_SOC_BIAS_PREPARE: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1335 | aic31xx_clk_off(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1336 | break; |
| 1337 | default: |
| 1338 | BUG(); |
| 1339 | } |
| 1340 | break; |
| 1341 | case SND_SOC_BIAS_OFF: |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1342 | if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) |
| 1343 | aic31xx_power_off(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1344 | break; |
| 1345 | } |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
kbuild test robot | 7742a5b | 2019-04-02 19:46:18 +0800 | [diff] [blame] | 1350 | static int aic31xx_set_jack(struct snd_soc_component *component, |
| 1351 | struct snd_soc_jack *jack, void *data) |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 1352 | { |
| 1353 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
| 1354 | |
| 1355 | aic31xx->jack = jack; |
| 1356 | |
| 1357 | /* Enable/Disable jack detection */ |
| 1358 | regmap_write(aic31xx->regmap, AIC31XX_HSDETECT, |
| 1359 | jack ? AIC31XX_HSD_ENABLE : 0); |
| 1360 | |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1364 | static int aic31xx_codec_probe(struct snd_soc_component *component) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1365 | { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1366 | struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1367 | int i, ret; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1368 | |
| 1369 | dev_dbg(aic31xx->dev, "## %s\n", __func__); |
| 1370 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1371 | aic31xx->component = component; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1372 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1373 | for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) { |
| 1374 | aic31xx->disable_nb[i].nb.notifier_call = |
| 1375 | aic31xx_regulator_event; |
| 1376 | aic31xx->disable_nb[i].aic31xx = aic31xx; |
Guennadi Liakhovetski | 0bb423f | 2019-02-08 14:45:20 +0100 | [diff] [blame] | 1377 | ret = devm_regulator_register_notifier( |
| 1378 | aic31xx->supplies[i].consumer, |
| 1379 | &aic31xx->disable_nb[i].nb); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1380 | if (ret) { |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1381 | dev_err(component->dev, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1382 | "Failed to request regulator notifier: %d\n", |
| 1383 | ret); |
| 1384 | return ret; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | regcache_cache_only(aic31xx->regmap, true); |
| 1389 | regcache_mark_dirty(aic31xx->regmap); |
| 1390 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1391 | ret = aic31xx_add_controls(component); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1392 | if (ret) |
| 1393 | return ret; |
| 1394 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1395 | ret = aic31xx_add_widgets(component); |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1396 | if (ret) |
| 1397 | return ret; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1398 | |
Lucas Stach | e48fdb5 | 2019-11-18 16:12:06 +0100 | [diff] [blame] | 1399 | /* set output common-mode voltage */ |
| 1400 | snd_soc_component_update_bits(component, AIC31XX_HPDRIVER, |
| 1401 | AIC31XX_HPD_OCMV_MASK, |
| 1402 | aic31xx->ocmv << AIC31XX_HPD_OCMV_SHIFT); |
| 1403 | |
Andrew F. Davis | ca7840f | 2017-11-29 15:32:45 -0600 | [diff] [blame] | 1404 | return 0; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1405 | } |
| 1406 | |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1407 | static const struct snd_soc_component_driver soc_codec_driver_aic31xx = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1408 | .probe = aic31xx_codec_probe, |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 1409 | .set_jack = aic31xx_set_jack, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1410 | .set_bias_level = aic31xx_set_bias_level, |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1411 | .controls = common31xx_snd_controls, |
| 1412 | .num_controls = ARRAY_SIZE(common31xx_snd_controls), |
| 1413 | .dapm_widgets = common31xx_dapm_widgets, |
| 1414 | .num_dapm_widgets = ARRAY_SIZE(common31xx_dapm_widgets), |
| 1415 | .dapm_routes = common31xx_audio_map, |
| 1416 | .num_dapm_routes = ARRAY_SIZE(common31xx_audio_map), |
| 1417 | .suspend_bias_off = 1, |
| 1418 | .idle_bias_on = 1, |
| 1419 | .use_pmdown_time = 1, |
| 1420 | .endianness = 1, |
| 1421 | .non_legacy_dai_naming = 1, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1422 | }; |
| 1423 | |
Axel Lin | 6479304 | 2015-07-15 15:38:14 +0800 | [diff] [blame] | 1424 | static const struct snd_soc_dai_ops aic31xx_dai_ops = { |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1425 | .hw_params = aic31xx_hw_params, |
| 1426 | .set_sysclk = aic31xx_set_dai_sysclk, |
| 1427 | .set_fmt = aic31xx_set_dai_fmt, |
Kuninori Morimoto | 960af79 | 2020-07-09 10:56:25 +0900 | [diff] [blame] | 1428 | .mute_stream = aic31xx_dac_mute, |
| 1429 | .no_capture_mute = 1, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1430 | }; |
| 1431 | |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1432 | static struct snd_soc_dai_driver dac31xx_dai_driver[] = { |
| 1433 | { |
Tomas Vilda | 51827c4 | 2017-05-13 00:29:37 +0300 | [diff] [blame] | 1434 | .name = "tlv320dac31xx-hifi", |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1435 | .playback = { |
| 1436 | .stream_name = "Playback", |
Nikita Yushchenko | 3520646 | 2016-09-27 11:30:15 +0300 | [diff] [blame] | 1437 | .channels_min = 2, |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1438 | .channels_max = 2, |
| 1439 | .rates = AIC31XX_RATES, |
| 1440 | .formats = AIC31XX_FORMATS, |
| 1441 | }, |
| 1442 | .ops = &aic31xx_dai_ops, |
Kuninori Morimoto | a9aef18 | 2021-01-15 13:54:17 +0900 | [diff] [blame] | 1443 | .symmetric_rate = 1, |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1444 | } |
| 1445 | }; |
| 1446 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1447 | static struct snd_soc_dai_driver aic31xx_dai_driver[] = { |
| 1448 | { |
| 1449 | .name = "tlv320aic31xx-hifi", |
| 1450 | .playback = { |
| 1451 | .stream_name = "Playback", |
Nikita Yushchenko | 3520646 | 2016-09-27 11:30:15 +0300 | [diff] [blame] | 1452 | .channels_min = 2, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1453 | .channels_max = 2, |
| 1454 | .rates = AIC31XX_RATES, |
| 1455 | .formats = AIC31XX_FORMATS, |
| 1456 | }, |
| 1457 | .capture = { |
| 1458 | .stream_name = "Capture", |
Nikita Yushchenko | 3520646 | 2016-09-27 11:30:15 +0300 | [diff] [blame] | 1459 | .channels_min = 2, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1460 | .channels_max = 2, |
| 1461 | .rates = AIC31XX_RATES, |
| 1462 | .formats = AIC31XX_FORMATS, |
| 1463 | }, |
| 1464 | .ops = &aic31xx_dai_ops, |
Kuninori Morimoto | a9aef18 | 2021-01-15 13:54:17 +0900 | [diff] [blame] | 1465 | .symmetric_rate = 1, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1466 | } |
| 1467 | }; |
| 1468 | |
| 1469 | #if defined(CONFIG_OF) |
| 1470 | static const struct of_device_id tlv320aic31xx_of_match[] = { |
| 1471 | { .compatible = "ti,tlv320aic310x" }, |
| 1472 | { .compatible = "ti,tlv320aic311x" }, |
| 1473 | { .compatible = "ti,tlv320aic3100" }, |
| 1474 | { .compatible = "ti,tlv320aic3110" }, |
| 1475 | { .compatible = "ti,tlv320aic3120" }, |
| 1476 | { .compatible = "ti,tlv320aic3111" }, |
Peter Ujfalusi | a4a1d79 | 2016-11-10 09:55:54 +0200 | [diff] [blame] | 1477 | { .compatible = "ti,tlv320dac3100" }, |
Peter Ujfalusi | 4e2cc81 | 2016-11-10 09:55:55 +0200 | [diff] [blame] | 1478 | { .compatible = "ti,tlv320dac3101" }, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1479 | {}, |
| 1480 | }; |
| 1481 | MODULE_DEVICE_TABLE(of, tlv320aic31xx_of_match); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1482 | #endif /* CONFIG_OF */ |
| 1483 | |
Andrew F. Davis | 0930360 | 2017-11-29 15:32:44 -0600 | [diff] [blame] | 1484 | #ifdef CONFIG_ACPI |
| 1485 | static const struct acpi_device_id aic31xx_acpi_match[] = { |
| 1486 | { "10TI3100", 0 }, |
| 1487 | { } |
| 1488 | }; |
| 1489 | MODULE_DEVICE_TABLE(acpi, aic31xx_acpi_match); |
| 1490 | #endif |
| 1491 | |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1492 | static irqreturn_t aic31xx_irq(int irq, void *data) |
| 1493 | { |
| 1494 | struct aic31xx_priv *aic31xx = data; |
| 1495 | struct device *dev = aic31xx->dev; |
| 1496 | unsigned int value; |
| 1497 | bool handled = false; |
| 1498 | int ret; |
| 1499 | |
| 1500 | ret = regmap_read(aic31xx->regmap, AIC31XX_INTRDACFLAG, &value); |
| 1501 | if (ret) { |
| 1502 | dev_err(dev, "Failed to read interrupt mask: %d\n", ret); |
| 1503 | goto exit; |
| 1504 | } |
| 1505 | |
| 1506 | if (value) |
| 1507 | handled = true; |
| 1508 | else |
Andrew F. Davis | 18d545b | 2018-09-04 10:36:17 -0500 | [diff] [blame] | 1509 | goto read_overflow; |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1510 | |
| 1511 | if (value & AIC31XX_HPLSCDETECT) |
| 1512 | dev_err(dev, "Short circuit on Left output is detected\n"); |
| 1513 | if (value & AIC31XX_HPRSCDETECT) |
| 1514 | dev_err(dev, "Short circuit on Right output is detected\n"); |
Andrew F. Davis | 90f0202 | 2019-04-01 10:13:29 -0500 | [diff] [blame] | 1515 | if (value & (AIC31XX_HSPLUG | AIC31XX_BUTTONPRESS)) { |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 1516 | unsigned int val; |
| 1517 | int status = 0; |
| 1518 | |
Andrew F. Davis | 90f0202 | 2019-04-01 10:13:29 -0500 | [diff] [blame] | 1519 | ret = regmap_read(aic31xx->regmap, AIC31XX_INTRDACFLAG2, |
| 1520 | &val); |
| 1521 | if (ret) { |
| 1522 | dev_err(dev, "Failed to read interrupt mask: %d\n", |
| 1523 | ret); |
| 1524 | goto exit; |
| 1525 | } |
| 1526 | |
| 1527 | if (val & AIC31XX_BUTTONPRESS) |
| 1528 | status |= SND_JACK_BTN_0; |
| 1529 | |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 1530 | ret = regmap_read(aic31xx->regmap, AIC31XX_HSDETECT, &val); |
| 1531 | if (ret) { |
| 1532 | dev_err(dev, "Failed to read headset type: %d\n", ret); |
| 1533 | goto exit; |
| 1534 | } |
| 1535 | |
| 1536 | switch ((val & AIC31XX_HSD_TYPE_MASK) >> |
| 1537 | AIC31XX_HSD_TYPE_SHIFT) { |
| 1538 | case AIC31XX_HSD_HP: |
| 1539 | status |= SND_JACK_HEADPHONE; |
| 1540 | break; |
| 1541 | case AIC31XX_HSD_HS: |
| 1542 | status |= SND_JACK_HEADSET; |
| 1543 | break; |
| 1544 | default: |
| 1545 | break; |
| 1546 | } |
| 1547 | |
| 1548 | if (aic31xx->jack) |
| 1549 | snd_soc_jack_report(aic31xx->jack, status, |
| 1550 | AIC31XX_JACK_MASK); |
| 1551 | } |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1552 | if (value & ~(AIC31XX_HPLSCDETECT | |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 1553 | AIC31XX_HPRSCDETECT | |
Andrew F. Davis | 90f0202 | 2019-04-01 10:13:29 -0500 | [diff] [blame] | 1554 | AIC31XX_HSPLUG | |
| 1555 | AIC31XX_BUTTONPRESS)) |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1556 | dev_err(dev, "Unknown DAC interrupt flags: 0x%08x\n", value); |
| 1557 | |
Andrew F. Davis | 18d545b | 2018-09-04 10:36:17 -0500 | [diff] [blame] | 1558 | read_overflow: |
| 1559 | ret = regmap_read(aic31xx->regmap, AIC31XX_OFFLAG, &value); |
| 1560 | if (ret) { |
| 1561 | dev_err(dev, "Failed to read overflow flag: %d\n", ret); |
| 1562 | goto exit; |
| 1563 | } |
| 1564 | |
| 1565 | if (value) |
| 1566 | handled = true; |
| 1567 | else |
| 1568 | goto exit; |
| 1569 | |
| 1570 | if (value & AIC31XX_DAC_OF_LEFT) |
| 1571 | dev_warn(dev, "Left-channel DAC overflow has occurred\n"); |
| 1572 | if (value & AIC31XX_DAC_OF_RIGHT) |
| 1573 | dev_warn(dev, "Right-channel DAC overflow has occurred\n"); |
| 1574 | if (value & AIC31XX_DAC_OF_SHIFTER) |
| 1575 | dev_warn(dev, "DAC barrel shifter overflow has occurred\n"); |
| 1576 | if (value & AIC31XX_ADC_OF) |
| 1577 | dev_warn(dev, "ADC overflow has occurred\n"); |
| 1578 | if (value & AIC31XX_ADC_OF_SHIFTER) |
| 1579 | dev_warn(dev, "ADC barrel shifter overflow has occurred\n"); |
| 1580 | if (value & ~(AIC31XX_DAC_OF_LEFT | |
| 1581 | AIC31XX_DAC_OF_RIGHT | |
| 1582 | AIC31XX_DAC_OF_SHIFTER | |
| 1583 | AIC31XX_ADC_OF | |
| 1584 | AIC31XX_ADC_OF_SHIFTER)) |
| 1585 | dev_warn(dev, "Unknown overflow interrupt flags: 0x%08x\n", value); |
| 1586 | |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1587 | exit: |
| 1588 | if (handled) |
| 1589 | return IRQ_HANDLED; |
| 1590 | else |
| 1591 | return IRQ_NONE; |
| 1592 | } |
| 1593 | |
Lucas Stach | e48fdb5 | 2019-11-18 16:12:06 +0100 | [diff] [blame] | 1594 | static void aic31xx_configure_ocmv(struct aic31xx_priv *priv) |
| 1595 | { |
| 1596 | struct device *dev = priv->dev; |
| 1597 | int dvdd, avdd; |
| 1598 | u32 value; |
| 1599 | |
| 1600 | if (dev->fwnode && |
| 1601 | fwnode_property_read_u32(dev->fwnode, "ai31xx-ocmv", &value)) { |
| 1602 | /* OCMV setting is forced by DT */ |
| 1603 | if (value <= 3) { |
| 1604 | priv->ocmv = value; |
| 1605 | return; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | avdd = regulator_get_voltage(priv->supplies[3].consumer); |
| 1610 | dvdd = regulator_get_voltage(priv->supplies[5].consumer); |
| 1611 | |
| 1612 | if (avdd > 3600000 || dvdd > 1950000) { |
| 1613 | dev_warn(dev, |
| 1614 | "Too high supply voltage(s) AVDD: %d, DVDD: %d\n", |
| 1615 | avdd, dvdd); |
| 1616 | } else if (avdd == 3600000 && dvdd == 1950000) { |
| 1617 | priv->ocmv = AIC31XX_HPD_OCMV_1_8V; |
| 1618 | } else if (avdd >= 3300000 && dvdd >= 1800000) { |
| 1619 | priv->ocmv = AIC31XX_HPD_OCMV_1_65V; |
| 1620 | } else if (avdd >= 3000000 && dvdd >= 1650000) { |
| 1621 | priv->ocmv = AIC31XX_HPD_OCMV_1_5V; |
| 1622 | } else if (avdd >= 2700000 && dvdd >= 1525000) { |
| 1623 | priv->ocmv = AIC31XX_HPD_OCMV_1_35V; |
| 1624 | } else { |
| 1625 | dev_warn(dev, |
| 1626 | "Invalid supply voltage(s) AVDD: %d, DVDD: %d\n", |
| 1627 | avdd, dvdd); |
| 1628 | } |
| 1629 | } |
| 1630 | |
Andrew F. Davis | e88c388 | 2017-11-29 15:32:48 -0600 | [diff] [blame] | 1631 | static int aic31xx_i2c_probe(struct i2c_client *i2c, |
| 1632 | const struct i2c_device_id *id) |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1633 | { |
Andrew F. Davis | e88c388 | 2017-11-29 15:32:48 -0600 | [diff] [blame] | 1634 | struct aic31xx_priv *aic31xx; |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 1635 | unsigned int micbias_value = MICBIAS_2_0V; |
Andrew F. Davis | e88c388 | 2017-11-29 15:32:48 -0600 | [diff] [blame] | 1636 | int i, ret; |
| 1637 | |
| 1638 | dev_dbg(&i2c->dev, "## %s: %s codec_type = %d\n", __func__, |
| 1639 | id->name, (int)id->driver_data); |
| 1640 | |
| 1641 | aic31xx = devm_kzalloc(&i2c->dev, sizeof(*aic31xx), GFP_KERNEL); |
| 1642 | if (!aic31xx) |
| 1643 | return -ENOMEM; |
| 1644 | |
| 1645 | aic31xx->regmap = devm_regmap_init_i2c(i2c, &aic31xx_i2c_regmap); |
| 1646 | if (IS_ERR(aic31xx->regmap)) { |
| 1647 | ret = PTR_ERR(aic31xx->regmap); |
| 1648 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
| 1649 | ret); |
| 1650 | return ret; |
| 1651 | } |
Mark Brown | 6c621b8 | 2021-07-07 17:02:34 +0100 | [diff] [blame] | 1652 | regcache_cache_only(aic31xx->regmap, true); |
| 1653 | |
Andrew F. Davis | e88c388 | 2017-11-29 15:32:48 -0600 | [diff] [blame] | 1654 | aic31xx->dev = &i2c->dev; |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1655 | aic31xx->irq = i2c->irq; |
Andrew F. Davis | e88c388 | 2017-11-29 15:32:48 -0600 | [diff] [blame] | 1656 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 1657 | aic31xx->codec_type = id->driver_data; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1658 | |
| 1659 | dev_set_drvdata(aic31xx->dev, aic31xx); |
| 1660 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 1661 | fwnode_property_read_u32(aic31xx->dev->fwnode, "ai31xx-micbias-vg", |
| 1662 | &micbias_value); |
| 1663 | switch (micbias_value) { |
| 1664 | case MICBIAS_2_0V: |
| 1665 | case MICBIAS_2_5V: |
| 1666 | case MICBIAS_AVDDV: |
| 1667 | aic31xx->micbias_vg = micbias_value; |
| 1668 | break; |
| 1669 | default: |
| 1670 | dev_err(aic31xx->dev, "Bad ai31xx-micbias-vg value %d\n", |
| 1671 | micbias_value); |
| 1672 | aic31xx->micbias_vg = MICBIAS_2_0V; |
| 1673 | } |
| 1674 | |
| 1675 | if (dev_get_platdata(aic31xx->dev)) { |
| 1676 | memcpy(&aic31xx->pdata, dev_get_platdata(aic31xx->dev), sizeof(aic31xx->pdata)); |
| 1677 | aic31xx->codec_type = aic31xx->pdata.codec_type; |
| 1678 | aic31xx->micbias_vg = aic31xx->pdata.micbias_vg; |
| 1679 | } |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1680 | |
Andrew F. Davis | b6b247c | 2017-11-29 15:32:49 -0600 | [diff] [blame] | 1681 | aic31xx->gpio_reset = devm_gpiod_get_optional(aic31xx->dev, "reset", |
| 1682 | GPIOD_OUT_LOW); |
Kuninori Morimoto | 7ff27fa | 2021-12-14 11:08:31 +0900 | [diff] [blame] | 1683 | if (IS_ERR(aic31xx->gpio_reset)) |
| 1684 | return dev_err_probe(aic31xx->dev, PTR_ERR(aic31xx->gpio_reset), |
| 1685 | "not able to acquire gpio\n"); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1686 | |
| 1687 | for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) |
| 1688 | aic31xx->supplies[i].supply = aic31xx_supply_names[i]; |
| 1689 | |
| 1690 | ret = devm_regulator_bulk_get(aic31xx->dev, |
| 1691 | ARRAY_SIZE(aic31xx->supplies), |
| 1692 | aic31xx->supplies); |
Kuninori Morimoto | 7ff27fa | 2021-12-14 11:08:31 +0900 | [diff] [blame] | 1693 | if (ret) |
| 1694 | return dev_err_probe(aic31xx->dev, ret, "Failed to request supplies\n"); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1695 | |
Lucas Stach | e48fdb5 | 2019-11-18 16:12:06 +0100 | [diff] [blame] | 1696 | aic31xx_configure_ocmv(aic31xx); |
| 1697 | |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1698 | if (aic31xx->irq > 0) { |
| 1699 | regmap_update_bits(aic31xx->regmap, AIC31XX_GPIO1, |
| 1700 | AIC31XX_GPIO1_FUNC_MASK, |
| 1701 | AIC31XX_GPIO1_INT1 << |
| 1702 | AIC31XX_GPIO1_FUNC_SHIFT); |
| 1703 | |
| 1704 | regmap_write(aic31xx->regmap, AIC31XX_INT1CTRL, |
Andrew F. Davis | ebf3326 | 2019-04-01 10:13:28 -0500 | [diff] [blame] | 1705 | AIC31XX_HSPLUGDET | |
Andrew F. Davis | 90f0202 | 2019-04-01 10:13:29 -0500 | [diff] [blame] | 1706 | AIC31XX_BUTTONPRESSDET | |
Andrew F. Davis | 18d545b | 2018-09-04 10:36:17 -0500 | [diff] [blame] | 1707 | AIC31XX_SC | |
| 1708 | AIC31XX_ENGINE); |
Andrew F. Davis | 80863ee | 2018-08-31 13:24:31 -0500 | [diff] [blame] | 1709 | |
| 1710 | ret = devm_request_threaded_irq(aic31xx->dev, aic31xx->irq, |
| 1711 | NULL, aic31xx_irq, |
| 1712 | IRQF_ONESHOT, "aic31xx-irq", |
| 1713 | aic31xx); |
| 1714 | if (ret) { |
| 1715 | dev_err(aic31xx->dev, "Unable to request IRQ\n"); |
| 1716 | return ret; |
| 1717 | } |
| 1718 | } |
| 1719 | |
Andrew F. Davis | cd15da8 | 2017-12-07 09:38:52 -0600 | [diff] [blame] | 1720 | if (aic31xx->codec_type & DAC31XX_BIT) |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1721 | return devm_snd_soc_register_component(&i2c->dev, |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1722 | &soc_codec_driver_aic31xx, |
| 1723 | dac31xx_dai_driver, |
| 1724 | ARRAY_SIZE(dac31xx_dai_driver)); |
| 1725 | else |
Kuninori Morimoto | f2e6f95b | 2018-01-29 04:15:27 +0000 | [diff] [blame] | 1726 | return devm_snd_soc_register_component(&i2c->dev, |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1727 | &soc_codec_driver_aic31xx, |
| 1728 | aic31xx_dai_driver, |
| 1729 | ARRAY_SIZE(aic31xx_dai_driver)); |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1732 | static const struct i2c_device_id aic31xx_i2c_id[] = { |
| 1733 | { "tlv320aic310x", AIC3100 }, |
| 1734 | { "tlv320aic311x", AIC3110 }, |
| 1735 | { "tlv320aic3100", AIC3100 }, |
| 1736 | { "tlv320aic3110", AIC3110 }, |
| 1737 | { "tlv320aic3120", AIC3120 }, |
| 1738 | { "tlv320aic3111", AIC3111 }, |
Nikita Yushchenko | ef9656b | 2016-09-23 14:52:52 +0300 | [diff] [blame] | 1739 | { "tlv320dac3100", DAC3100 }, |
Peter Ujfalusi | 4e2cc81 | 2016-11-10 09:55:55 +0200 | [diff] [blame] | 1740 | { "tlv320dac3101", DAC3101 }, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1741 | { } |
| 1742 | }; |
| 1743 | MODULE_DEVICE_TABLE(i2c, aic31xx_i2c_id); |
| 1744 | |
| 1745 | static struct i2c_driver aic31xx_i2c_driver = { |
| 1746 | .driver = { |
| 1747 | .name = "tlv320aic31xx-codec", |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1748 | .of_match_table = of_match_ptr(tlv320aic31xx_of_match), |
Bastien Nocera | f5cc177 | 2016-04-19 18:00:20 +0200 | [diff] [blame] | 1749 | .acpi_match_table = ACPI_PTR(aic31xx_acpi_match), |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1750 | }, |
| 1751 | .probe = aic31xx_i2c_probe, |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1752 | .id_table = aic31xx_i2c_id, |
| 1753 | }; |
Jyri Sarha | e00447f | 2014-03-11 12:57:32 +0200 | [diff] [blame] | 1754 | module_i2c_driver(aic31xx_i2c_driver); |
| 1755 | |
Andrew F. Davis | b1c52b7 | 2017-11-29 15:32:42 -0600 | [diff] [blame] | 1756 | MODULE_AUTHOR("Jyri Sarha <jsarha@ti.com>"); |
| 1757 | MODULE_DESCRIPTION("ASoC TLV320AIC31xx CODEC Driver"); |
| 1758 | MODULE_LICENSE("GPL v2"); |