Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * max98095.c -- MAX98095 ALSA SoC Audio driver |
| 3 | * |
| 4 | * Copyright 2011 Maxim Integrated Products |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/pm.h> |
| 17 | #include <linux/i2c.h> |
Tushar Behera | e3048c3 | 2014-05-26 13:58:22 +0530 | [diff] [blame] | 18 | #include <linux/clk.h> |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 19 | #include <linux/mutex.h> |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 20 | #include <sound/core.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/pcm_params.h> |
| 23 | #include <sound/soc.h> |
| 24 | #include <sound/initval.h> |
| 25 | #include <sound/tlv.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <asm/div64.h> |
| 28 | #include <sound/max98095.h> |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 29 | #include <sound/jack.h> |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 30 | #include "max98095.h" |
| 31 | |
| 32 | enum max98095_type { |
| 33 | MAX98095, |
| 34 | }; |
| 35 | |
| 36 | struct max98095_cdata { |
| 37 | unsigned int rate; |
| 38 | unsigned int fmt; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 39 | int eq_sel; |
| 40 | int bq_sel; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct max98095_priv { |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 44 | struct regmap *regmap; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 45 | enum max98095_type devtype; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 46 | struct max98095_pdata *pdata; |
Tushar Behera | e3048c3 | 2014-05-26 13:58:22 +0530 | [diff] [blame] | 47 | struct clk *mclk; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 48 | unsigned int sysclk; |
| 49 | struct max98095_cdata dai[3]; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 50 | const char **eq_texts; |
| 51 | const char **bq_texts; |
| 52 | struct soc_enum eq_enum; |
| 53 | struct soc_enum bq_enum; |
| 54 | int eq_textcnt; |
| 55 | int bq_textcnt; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 56 | u8 lin_state; |
| 57 | unsigned int mic1pre; |
| 58 | unsigned int mic2pre; |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 59 | struct snd_soc_jack *headphone_jack; |
| 60 | struct snd_soc_jack *mic_jack; |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 61 | struct mutex lock; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 64 | static const struct reg_default max98095_reg_def[] = { |
| 65 | { 0xf, 0x00 }, /* 0F */ |
| 66 | { 0x10, 0x00 }, /* 10 */ |
| 67 | { 0x11, 0x00 }, /* 11 */ |
| 68 | { 0x12, 0x00 }, /* 12 */ |
| 69 | { 0x13, 0x00 }, /* 13 */ |
| 70 | { 0x14, 0x00 }, /* 14 */ |
| 71 | { 0x15, 0x00 }, /* 15 */ |
| 72 | { 0x16, 0x00 }, /* 16 */ |
| 73 | { 0x17, 0x00 }, /* 17 */ |
| 74 | { 0x18, 0x00 }, /* 18 */ |
| 75 | { 0x19, 0x00 }, /* 19 */ |
| 76 | { 0x1a, 0x00 }, /* 1A */ |
| 77 | { 0x1b, 0x00 }, /* 1B */ |
| 78 | { 0x1c, 0x00 }, /* 1C */ |
| 79 | { 0x1d, 0x00 }, /* 1D */ |
| 80 | { 0x1e, 0x00 }, /* 1E */ |
| 81 | { 0x1f, 0x00 }, /* 1F */ |
| 82 | { 0x20, 0x00 }, /* 20 */ |
| 83 | { 0x21, 0x00 }, /* 21 */ |
| 84 | { 0x22, 0x00 }, /* 22 */ |
| 85 | { 0x23, 0x00 }, /* 23 */ |
| 86 | { 0x24, 0x00 }, /* 24 */ |
| 87 | { 0x25, 0x00 }, /* 25 */ |
| 88 | { 0x26, 0x00 }, /* 26 */ |
| 89 | { 0x27, 0x00 }, /* 27 */ |
| 90 | { 0x28, 0x00 }, /* 28 */ |
| 91 | { 0x29, 0x00 }, /* 29 */ |
| 92 | { 0x2a, 0x00 }, /* 2A */ |
| 93 | { 0x2b, 0x00 }, /* 2B */ |
| 94 | { 0x2c, 0x00 }, /* 2C */ |
| 95 | { 0x2d, 0x00 }, /* 2D */ |
| 96 | { 0x2e, 0x00 }, /* 2E */ |
| 97 | { 0x2f, 0x00 }, /* 2F */ |
| 98 | { 0x30, 0x00 }, /* 30 */ |
| 99 | { 0x31, 0x00 }, /* 31 */ |
| 100 | { 0x32, 0x00 }, /* 32 */ |
| 101 | { 0x33, 0x00 }, /* 33 */ |
| 102 | { 0x34, 0x00 }, /* 34 */ |
| 103 | { 0x35, 0x00 }, /* 35 */ |
| 104 | { 0x36, 0x00 }, /* 36 */ |
| 105 | { 0x37, 0x00 }, /* 37 */ |
| 106 | { 0x38, 0x00 }, /* 38 */ |
| 107 | { 0x39, 0x00 }, /* 39 */ |
| 108 | { 0x3a, 0x00 }, /* 3A */ |
| 109 | { 0x3b, 0x00 }, /* 3B */ |
| 110 | { 0x3c, 0x00 }, /* 3C */ |
| 111 | { 0x3d, 0x00 }, /* 3D */ |
| 112 | { 0x3e, 0x00 }, /* 3E */ |
| 113 | { 0x3f, 0x00 }, /* 3F */ |
| 114 | { 0x40, 0x00 }, /* 40 */ |
| 115 | { 0x41, 0x00 }, /* 41 */ |
| 116 | { 0x42, 0x00 }, /* 42 */ |
| 117 | { 0x43, 0x00 }, /* 43 */ |
| 118 | { 0x44, 0x00 }, /* 44 */ |
| 119 | { 0x45, 0x00 }, /* 45 */ |
| 120 | { 0x46, 0x00 }, /* 46 */ |
| 121 | { 0x47, 0x00 }, /* 47 */ |
| 122 | { 0x48, 0x00 }, /* 48 */ |
| 123 | { 0x49, 0x00 }, /* 49 */ |
| 124 | { 0x4a, 0x00 }, /* 4A */ |
| 125 | { 0x4b, 0x00 }, /* 4B */ |
| 126 | { 0x4c, 0x00 }, /* 4C */ |
| 127 | { 0x4d, 0x00 }, /* 4D */ |
| 128 | { 0x4e, 0x00 }, /* 4E */ |
| 129 | { 0x4f, 0x00 }, /* 4F */ |
| 130 | { 0x50, 0x00 }, /* 50 */ |
| 131 | { 0x51, 0x00 }, /* 51 */ |
| 132 | { 0x52, 0x00 }, /* 52 */ |
| 133 | { 0x53, 0x00 }, /* 53 */ |
| 134 | { 0x54, 0x00 }, /* 54 */ |
| 135 | { 0x55, 0x00 }, /* 55 */ |
| 136 | { 0x56, 0x00 }, /* 56 */ |
| 137 | { 0x57, 0x00 }, /* 57 */ |
| 138 | { 0x58, 0x00 }, /* 58 */ |
| 139 | { 0x59, 0x00 }, /* 59 */ |
| 140 | { 0x5a, 0x00 }, /* 5A */ |
| 141 | { 0x5b, 0x00 }, /* 5B */ |
| 142 | { 0x5c, 0x00 }, /* 5C */ |
| 143 | { 0x5d, 0x00 }, /* 5D */ |
| 144 | { 0x5e, 0x00 }, /* 5E */ |
| 145 | { 0x5f, 0x00 }, /* 5F */ |
| 146 | { 0x60, 0x00 }, /* 60 */ |
| 147 | { 0x61, 0x00 }, /* 61 */ |
| 148 | { 0x62, 0x00 }, /* 62 */ |
| 149 | { 0x63, 0x00 }, /* 63 */ |
| 150 | { 0x64, 0x00 }, /* 64 */ |
| 151 | { 0x65, 0x00 }, /* 65 */ |
| 152 | { 0x66, 0x00 }, /* 66 */ |
| 153 | { 0x67, 0x00 }, /* 67 */ |
| 154 | { 0x68, 0x00 }, /* 68 */ |
| 155 | { 0x69, 0x00 }, /* 69 */ |
| 156 | { 0x6a, 0x00 }, /* 6A */ |
| 157 | { 0x6b, 0x00 }, /* 6B */ |
| 158 | { 0x6c, 0x00 }, /* 6C */ |
| 159 | { 0x6d, 0x00 }, /* 6D */ |
| 160 | { 0x6e, 0x00 }, /* 6E */ |
| 161 | { 0x6f, 0x00 }, /* 6F */ |
| 162 | { 0x70, 0x00 }, /* 70 */ |
| 163 | { 0x71, 0x00 }, /* 71 */ |
| 164 | { 0x72, 0x00 }, /* 72 */ |
| 165 | { 0x73, 0x00 }, /* 73 */ |
| 166 | { 0x74, 0x00 }, /* 74 */ |
| 167 | { 0x75, 0x00 }, /* 75 */ |
| 168 | { 0x76, 0x00 }, /* 76 */ |
| 169 | { 0x77, 0x00 }, /* 77 */ |
| 170 | { 0x78, 0x00 }, /* 78 */ |
| 171 | { 0x79, 0x00 }, /* 79 */ |
| 172 | { 0x7a, 0x00 }, /* 7A */ |
| 173 | { 0x7b, 0x00 }, /* 7B */ |
| 174 | { 0x7c, 0x00 }, /* 7C */ |
| 175 | { 0x7d, 0x00 }, /* 7D */ |
| 176 | { 0x7e, 0x00 }, /* 7E */ |
| 177 | { 0x7f, 0x00 }, /* 7F */ |
| 178 | { 0x80, 0x00 }, /* 80 */ |
| 179 | { 0x81, 0x00 }, /* 81 */ |
| 180 | { 0x82, 0x00 }, /* 82 */ |
| 181 | { 0x83, 0x00 }, /* 83 */ |
| 182 | { 0x84, 0x00 }, /* 84 */ |
| 183 | { 0x85, 0x00 }, /* 85 */ |
| 184 | { 0x86, 0x00 }, /* 86 */ |
| 185 | { 0x87, 0x00 }, /* 87 */ |
| 186 | { 0x88, 0x00 }, /* 88 */ |
| 187 | { 0x89, 0x00 }, /* 89 */ |
| 188 | { 0x8a, 0x00 }, /* 8A */ |
| 189 | { 0x8b, 0x00 }, /* 8B */ |
| 190 | { 0x8c, 0x00 }, /* 8C */ |
| 191 | { 0x8d, 0x00 }, /* 8D */ |
| 192 | { 0x8e, 0x00 }, /* 8E */ |
| 193 | { 0x8f, 0x00 }, /* 8F */ |
| 194 | { 0x90, 0x00 }, /* 90 */ |
| 195 | { 0x91, 0x00 }, /* 91 */ |
| 196 | { 0x92, 0x30 }, /* 92 */ |
| 197 | { 0x93, 0xF0 }, /* 93 */ |
| 198 | { 0x94, 0x00 }, /* 94 */ |
| 199 | { 0x95, 0x00 }, /* 95 */ |
| 200 | { 0x96, 0x3F }, /* 96 */ |
| 201 | { 0x97, 0x00 }, /* 97 */ |
| 202 | { 0xff, 0x00 }, /* FF */ |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | static struct { |
| 206 | int readable; |
| 207 | int writable; |
| 208 | } max98095_access[M98095_REG_CNT] = { |
| 209 | { 0x00, 0x00 }, /* 00 */ |
| 210 | { 0xFF, 0x00 }, /* 01 */ |
| 211 | { 0xFF, 0x00 }, /* 02 */ |
| 212 | { 0xFF, 0x00 }, /* 03 */ |
| 213 | { 0xFF, 0x00 }, /* 04 */ |
| 214 | { 0xFF, 0x00 }, /* 05 */ |
| 215 | { 0xFF, 0x00 }, /* 06 */ |
| 216 | { 0xFF, 0x00 }, /* 07 */ |
| 217 | { 0xFF, 0x00 }, /* 08 */ |
| 218 | { 0xFF, 0x00 }, /* 09 */ |
| 219 | { 0xFF, 0x00 }, /* 0A */ |
| 220 | { 0xFF, 0x00 }, /* 0B */ |
| 221 | { 0xFF, 0x00 }, /* 0C */ |
| 222 | { 0xFF, 0x00 }, /* 0D */ |
| 223 | { 0xFF, 0x00 }, /* 0E */ |
| 224 | { 0xFF, 0x9F }, /* 0F */ |
| 225 | { 0xFF, 0xFF }, /* 10 */ |
| 226 | { 0xFF, 0xFF }, /* 11 */ |
| 227 | { 0xFF, 0xFF }, /* 12 */ |
| 228 | { 0xFF, 0xFF }, /* 13 */ |
| 229 | { 0xFF, 0xFF }, /* 14 */ |
| 230 | { 0xFF, 0xFF }, /* 15 */ |
| 231 | { 0xFF, 0xFF }, /* 16 */ |
| 232 | { 0xFF, 0xFF }, /* 17 */ |
| 233 | { 0xFF, 0xFF }, /* 18 */ |
| 234 | { 0xFF, 0xFF }, /* 19 */ |
| 235 | { 0xFF, 0xFF }, /* 1A */ |
| 236 | { 0xFF, 0xFF }, /* 1B */ |
| 237 | { 0xFF, 0xFF }, /* 1C */ |
| 238 | { 0xFF, 0xFF }, /* 1D */ |
| 239 | { 0xFF, 0x77 }, /* 1E */ |
| 240 | { 0xFF, 0x77 }, /* 1F */ |
| 241 | { 0xFF, 0x77 }, /* 20 */ |
| 242 | { 0xFF, 0x77 }, /* 21 */ |
| 243 | { 0xFF, 0x77 }, /* 22 */ |
| 244 | { 0xFF, 0x77 }, /* 23 */ |
| 245 | { 0xFF, 0xFF }, /* 24 */ |
| 246 | { 0xFF, 0x7F }, /* 25 */ |
| 247 | { 0xFF, 0x31 }, /* 26 */ |
| 248 | { 0xFF, 0xFF }, /* 27 */ |
| 249 | { 0xFF, 0xFF }, /* 28 */ |
| 250 | { 0xFF, 0xFF }, /* 29 */ |
| 251 | { 0xFF, 0xF7 }, /* 2A */ |
| 252 | { 0xFF, 0x2F }, /* 2B */ |
| 253 | { 0xFF, 0xEF }, /* 2C */ |
| 254 | { 0xFF, 0xFF }, /* 2D */ |
| 255 | { 0xFF, 0xFF }, /* 2E */ |
| 256 | { 0xFF, 0xFF }, /* 2F */ |
| 257 | { 0xFF, 0xFF }, /* 30 */ |
| 258 | { 0xFF, 0xFF }, /* 31 */ |
| 259 | { 0xFF, 0xFF }, /* 32 */ |
| 260 | { 0xFF, 0xFF }, /* 33 */ |
| 261 | { 0xFF, 0xF7 }, /* 34 */ |
| 262 | { 0xFF, 0x2F }, /* 35 */ |
| 263 | { 0xFF, 0xCF }, /* 36 */ |
| 264 | { 0xFF, 0xFF }, /* 37 */ |
| 265 | { 0xFF, 0xFF }, /* 38 */ |
| 266 | { 0xFF, 0xFF }, /* 39 */ |
| 267 | { 0xFF, 0xFF }, /* 3A */ |
| 268 | { 0xFF, 0xFF }, /* 3B */ |
| 269 | { 0xFF, 0xFF }, /* 3C */ |
| 270 | { 0xFF, 0xFF }, /* 3D */ |
| 271 | { 0xFF, 0xF7 }, /* 3E */ |
| 272 | { 0xFF, 0x2F }, /* 3F */ |
| 273 | { 0xFF, 0xCF }, /* 40 */ |
| 274 | { 0xFF, 0xFF }, /* 41 */ |
| 275 | { 0xFF, 0x77 }, /* 42 */ |
| 276 | { 0xFF, 0xFF }, /* 43 */ |
| 277 | { 0xFF, 0xFF }, /* 44 */ |
| 278 | { 0xFF, 0xFF }, /* 45 */ |
| 279 | { 0xFF, 0xFF }, /* 46 */ |
| 280 | { 0xFF, 0xFF }, /* 47 */ |
| 281 | { 0xFF, 0xFF }, /* 48 */ |
| 282 | { 0xFF, 0x0F }, /* 49 */ |
| 283 | { 0xFF, 0xFF }, /* 4A */ |
| 284 | { 0xFF, 0xFF }, /* 4B */ |
| 285 | { 0xFF, 0x3F }, /* 4C */ |
| 286 | { 0xFF, 0x3F }, /* 4D */ |
| 287 | { 0xFF, 0x3F }, /* 4E */ |
| 288 | { 0xFF, 0xFF }, /* 4F */ |
| 289 | { 0xFF, 0x7F }, /* 50 */ |
| 290 | { 0xFF, 0x7F }, /* 51 */ |
| 291 | { 0xFF, 0x0F }, /* 52 */ |
| 292 | { 0xFF, 0x3F }, /* 53 */ |
| 293 | { 0xFF, 0x3F }, /* 54 */ |
| 294 | { 0xFF, 0x3F }, /* 55 */ |
| 295 | { 0xFF, 0xFF }, /* 56 */ |
| 296 | { 0xFF, 0xFF }, /* 57 */ |
| 297 | { 0xFF, 0xBF }, /* 58 */ |
| 298 | { 0xFF, 0x1F }, /* 59 */ |
| 299 | { 0xFF, 0xBF }, /* 5A */ |
| 300 | { 0xFF, 0x1F }, /* 5B */ |
| 301 | { 0xFF, 0xBF }, /* 5C */ |
| 302 | { 0xFF, 0x3F }, /* 5D */ |
| 303 | { 0xFF, 0x3F }, /* 5E */ |
| 304 | { 0xFF, 0x7F }, /* 5F */ |
| 305 | { 0xFF, 0x7F }, /* 60 */ |
| 306 | { 0xFF, 0x47 }, /* 61 */ |
| 307 | { 0xFF, 0x9F }, /* 62 */ |
| 308 | { 0xFF, 0x9F }, /* 63 */ |
| 309 | { 0xFF, 0x9F }, /* 64 */ |
| 310 | { 0xFF, 0x9F }, /* 65 */ |
| 311 | { 0xFF, 0x9F }, /* 66 */ |
| 312 | { 0xFF, 0xBF }, /* 67 */ |
| 313 | { 0xFF, 0xBF }, /* 68 */ |
| 314 | { 0xFF, 0xFF }, /* 69 */ |
| 315 | { 0xFF, 0xFF }, /* 6A */ |
| 316 | { 0xFF, 0x7F }, /* 6B */ |
| 317 | { 0xFF, 0xF7 }, /* 6C */ |
| 318 | { 0xFF, 0xFF }, /* 6D */ |
| 319 | { 0xFF, 0xFF }, /* 6E */ |
| 320 | { 0xFF, 0x1F }, /* 6F */ |
| 321 | { 0xFF, 0xF7 }, /* 70 */ |
| 322 | { 0xFF, 0xFF }, /* 71 */ |
| 323 | { 0xFF, 0xFF }, /* 72 */ |
| 324 | { 0xFF, 0x1F }, /* 73 */ |
| 325 | { 0xFF, 0xF7 }, /* 74 */ |
| 326 | { 0xFF, 0xFF }, /* 75 */ |
| 327 | { 0xFF, 0xFF }, /* 76 */ |
| 328 | { 0xFF, 0x1F }, /* 77 */ |
| 329 | { 0xFF, 0xF7 }, /* 78 */ |
| 330 | { 0xFF, 0xFF }, /* 79 */ |
| 331 | { 0xFF, 0xFF }, /* 7A */ |
| 332 | { 0xFF, 0x1F }, /* 7B */ |
| 333 | { 0xFF, 0xF7 }, /* 7C */ |
| 334 | { 0xFF, 0xFF }, /* 7D */ |
| 335 | { 0xFF, 0xFF }, /* 7E */ |
| 336 | { 0xFF, 0x1F }, /* 7F */ |
| 337 | { 0xFF, 0xF7 }, /* 80 */ |
| 338 | { 0xFF, 0xFF }, /* 81 */ |
| 339 | { 0xFF, 0xFF }, /* 82 */ |
| 340 | { 0xFF, 0x1F }, /* 83 */ |
| 341 | { 0xFF, 0x7F }, /* 84 */ |
| 342 | { 0xFF, 0x0F }, /* 85 */ |
| 343 | { 0xFF, 0xD8 }, /* 86 */ |
| 344 | { 0xFF, 0xFF }, /* 87 */ |
| 345 | { 0xFF, 0xEF }, /* 88 */ |
| 346 | { 0xFF, 0xFE }, /* 89 */ |
| 347 | { 0xFF, 0xFE }, /* 8A */ |
| 348 | { 0xFF, 0xFF }, /* 8B */ |
| 349 | { 0xFF, 0xFF }, /* 8C */ |
| 350 | { 0xFF, 0x3F }, /* 8D */ |
| 351 | { 0xFF, 0xFF }, /* 8E */ |
| 352 | { 0xFF, 0x3F }, /* 8F */ |
| 353 | { 0xFF, 0x8F }, /* 90 */ |
| 354 | { 0xFF, 0xFF }, /* 91 */ |
| 355 | { 0xFF, 0x3F }, /* 92 */ |
| 356 | { 0xFF, 0xFF }, /* 93 */ |
| 357 | { 0xFF, 0xFF }, /* 94 */ |
| 358 | { 0xFF, 0x0F }, /* 95 */ |
| 359 | { 0xFF, 0x3F }, /* 96 */ |
| 360 | { 0xFF, 0x8C }, /* 97 */ |
| 361 | { 0x00, 0x00 }, /* 98 */ |
| 362 | { 0x00, 0x00 }, /* 99 */ |
| 363 | { 0x00, 0x00 }, /* 9A */ |
| 364 | { 0x00, 0x00 }, /* 9B */ |
| 365 | { 0x00, 0x00 }, /* 9C */ |
| 366 | { 0x00, 0x00 }, /* 9D */ |
| 367 | { 0x00, 0x00 }, /* 9E */ |
| 368 | { 0x00, 0x00 }, /* 9F */ |
| 369 | { 0x00, 0x00 }, /* A0 */ |
| 370 | { 0x00, 0x00 }, /* A1 */ |
| 371 | { 0x00, 0x00 }, /* A2 */ |
| 372 | { 0x00, 0x00 }, /* A3 */ |
| 373 | { 0x00, 0x00 }, /* A4 */ |
| 374 | { 0x00, 0x00 }, /* A5 */ |
| 375 | { 0x00, 0x00 }, /* A6 */ |
| 376 | { 0x00, 0x00 }, /* A7 */ |
| 377 | { 0x00, 0x00 }, /* A8 */ |
| 378 | { 0x00, 0x00 }, /* A9 */ |
| 379 | { 0x00, 0x00 }, /* AA */ |
| 380 | { 0x00, 0x00 }, /* AB */ |
| 381 | { 0x00, 0x00 }, /* AC */ |
| 382 | { 0x00, 0x00 }, /* AD */ |
| 383 | { 0x00, 0x00 }, /* AE */ |
| 384 | { 0x00, 0x00 }, /* AF */ |
| 385 | { 0x00, 0x00 }, /* B0 */ |
| 386 | { 0x00, 0x00 }, /* B1 */ |
| 387 | { 0x00, 0x00 }, /* B2 */ |
| 388 | { 0x00, 0x00 }, /* B3 */ |
| 389 | { 0x00, 0x00 }, /* B4 */ |
| 390 | { 0x00, 0x00 }, /* B5 */ |
| 391 | { 0x00, 0x00 }, /* B6 */ |
| 392 | { 0x00, 0x00 }, /* B7 */ |
| 393 | { 0x00, 0x00 }, /* B8 */ |
| 394 | { 0x00, 0x00 }, /* B9 */ |
| 395 | { 0x00, 0x00 }, /* BA */ |
| 396 | { 0x00, 0x00 }, /* BB */ |
| 397 | { 0x00, 0x00 }, /* BC */ |
| 398 | { 0x00, 0x00 }, /* BD */ |
| 399 | { 0x00, 0x00 }, /* BE */ |
| 400 | { 0x00, 0x00 }, /* BF */ |
| 401 | { 0x00, 0x00 }, /* C0 */ |
| 402 | { 0x00, 0x00 }, /* C1 */ |
| 403 | { 0x00, 0x00 }, /* C2 */ |
| 404 | { 0x00, 0x00 }, /* C3 */ |
| 405 | { 0x00, 0x00 }, /* C4 */ |
| 406 | { 0x00, 0x00 }, /* C5 */ |
| 407 | { 0x00, 0x00 }, /* C6 */ |
| 408 | { 0x00, 0x00 }, /* C7 */ |
| 409 | { 0x00, 0x00 }, /* C8 */ |
| 410 | { 0x00, 0x00 }, /* C9 */ |
| 411 | { 0x00, 0x00 }, /* CA */ |
| 412 | { 0x00, 0x00 }, /* CB */ |
| 413 | { 0x00, 0x00 }, /* CC */ |
| 414 | { 0x00, 0x00 }, /* CD */ |
| 415 | { 0x00, 0x00 }, /* CE */ |
| 416 | { 0x00, 0x00 }, /* CF */ |
| 417 | { 0x00, 0x00 }, /* D0 */ |
| 418 | { 0x00, 0x00 }, /* D1 */ |
| 419 | { 0x00, 0x00 }, /* D2 */ |
| 420 | { 0x00, 0x00 }, /* D3 */ |
| 421 | { 0x00, 0x00 }, /* D4 */ |
| 422 | { 0x00, 0x00 }, /* D5 */ |
| 423 | { 0x00, 0x00 }, /* D6 */ |
| 424 | { 0x00, 0x00 }, /* D7 */ |
| 425 | { 0x00, 0x00 }, /* D8 */ |
| 426 | { 0x00, 0x00 }, /* D9 */ |
| 427 | { 0x00, 0x00 }, /* DA */ |
| 428 | { 0x00, 0x00 }, /* DB */ |
| 429 | { 0x00, 0x00 }, /* DC */ |
| 430 | { 0x00, 0x00 }, /* DD */ |
| 431 | { 0x00, 0x00 }, /* DE */ |
| 432 | { 0x00, 0x00 }, /* DF */ |
| 433 | { 0x00, 0x00 }, /* E0 */ |
| 434 | { 0x00, 0x00 }, /* E1 */ |
| 435 | { 0x00, 0x00 }, /* E2 */ |
| 436 | { 0x00, 0x00 }, /* E3 */ |
| 437 | { 0x00, 0x00 }, /* E4 */ |
| 438 | { 0x00, 0x00 }, /* E5 */ |
| 439 | { 0x00, 0x00 }, /* E6 */ |
| 440 | { 0x00, 0x00 }, /* E7 */ |
| 441 | { 0x00, 0x00 }, /* E8 */ |
| 442 | { 0x00, 0x00 }, /* E9 */ |
| 443 | { 0x00, 0x00 }, /* EA */ |
| 444 | { 0x00, 0x00 }, /* EB */ |
| 445 | { 0x00, 0x00 }, /* EC */ |
| 446 | { 0x00, 0x00 }, /* ED */ |
| 447 | { 0x00, 0x00 }, /* EE */ |
| 448 | { 0x00, 0x00 }, /* EF */ |
| 449 | { 0x00, 0x00 }, /* F0 */ |
| 450 | { 0x00, 0x00 }, /* F1 */ |
| 451 | { 0x00, 0x00 }, /* F2 */ |
| 452 | { 0x00, 0x00 }, /* F3 */ |
| 453 | { 0x00, 0x00 }, /* F4 */ |
| 454 | { 0x00, 0x00 }, /* F5 */ |
| 455 | { 0x00, 0x00 }, /* F6 */ |
| 456 | { 0x00, 0x00 }, /* F7 */ |
| 457 | { 0x00, 0x00 }, /* F8 */ |
| 458 | { 0x00, 0x00 }, /* F9 */ |
| 459 | { 0x00, 0x00 }, /* FA */ |
| 460 | { 0x00, 0x00 }, /* FB */ |
| 461 | { 0x00, 0x00 }, /* FC */ |
| 462 | { 0x00, 0x00 }, /* FD */ |
| 463 | { 0x00, 0x00 }, /* FE */ |
| 464 | { 0xFF, 0x00 }, /* FF */ |
| 465 | }; |
| 466 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 467 | static bool max98095_readable(struct device *dev, unsigned int reg) |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 468 | { |
| 469 | if (reg >= M98095_REG_CNT) |
| 470 | return 0; |
| 471 | return max98095_access[reg].readable != 0; |
| 472 | } |
| 473 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 474 | static bool max98095_volatile(struct device *dev, unsigned int reg) |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 475 | { |
| 476 | if (reg > M98095_REG_MAX_CACHED) |
| 477 | return 1; |
| 478 | |
| 479 | switch (reg) { |
| 480 | case M98095_000_HOST_DATA: |
| 481 | case M98095_001_HOST_INT_STS: |
| 482 | case M98095_002_HOST_RSP_STS: |
| 483 | case M98095_003_HOST_CMD_STS: |
| 484 | case M98095_004_CODEC_STS: |
| 485 | case M98095_005_DAI1_ALC_STS: |
| 486 | case M98095_006_DAI2_ALC_STS: |
| 487 | case M98095_007_JACK_AUTO_STS: |
| 488 | case M98095_008_JACK_MANUAL_STS: |
| 489 | case M98095_009_JACK_VBAT_STS: |
| 490 | case M98095_00A_ACC_ADC_STS: |
| 491 | case M98095_00B_MIC_NG_AGC_STS: |
| 492 | case M98095_00C_SPK_L_VOLT_STS: |
| 493 | case M98095_00D_SPK_R_VOLT_STS: |
| 494 | case M98095_00E_TEMP_SENSOR_STS: |
| 495 | return 1; |
| 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 501 | static const struct regmap_config max98095_regmap = { |
| 502 | .reg_bits = 8, |
| 503 | .val_bits = 8, |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 504 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 505 | .reg_defaults = max98095_reg_def, |
| 506 | .num_reg_defaults = ARRAY_SIZE(max98095_reg_def), |
| 507 | .max_register = M98095_0FF_REV_ID, |
| 508 | .cache_type = REGCACHE_RBTREE, |
Axel Lin | 0d8d293 | 2011-10-15 11:46:02 +0800 | [diff] [blame] | 509 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 510 | .readable_reg = max98095_readable, |
| 511 | .volatile_reg = max98095_volatile, |
| 512 | }; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 513 | |
| 514 | /* |
| 515 | * Load equalizer DSP coefficient configurations registers |
| 516 | */ |
| 517 | static void m98095_eq_band(struct snd_soc_codec *codec, unsigned int dai, |
| 518 | unsigned int band, u16 *coefs) |
| 519 | { |
| 520 | unsigned int eq_reg; |
| 521 | unsigned int i; |
| 522 | |
Takashi Iwai | a922cd7 | 2013-11-05 18:39:50 +0100 | [diff] [blame] | 523 | if (WARN_ON(band > 4) || |
| 524 | WARN_ON(dai > 1)) |
| 525 | return; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 526 | |
| 527 | /* Load the base register address */ |
| 528 | eq_reg = dai ? M98095_142_DAI2_EQ_BASE : M98095_110_DAI1_EQ_BASE; |
| 529 | |
| 530 | /* Add the band address offset, note adjustment for word address */ |
| 531 | eq_reg += band * (M98095_COEFS_PER_BAND << 1); |
| 532 | |
| 533 | /* Step through the registers and coefs */ |
| 534 | for (i = 0; i < M98095_COEFS_PER_BAND; i++) { |
Mark Brown | d36126a | 2013-09-23 18:58:59 +0100 | [diff] [blame] | 535 | snd_soc_write(codec, eq_reg++, M98095_BYTE1(coefs[i])); |
| 536 | snd_soc_write(codec, eq_reg++, M98095_BYTE0(coefs[i])); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Load biquad filter coefficient configurations registers |
| 542 | */ |
| 543 | static void m98095_biquad_band(struct snd_soc_codec *codec, unsigned int dai, |
| 544 | unsigned int band, u16 *coefs) |
| 545 | { |
| 546 | unsigned int bq_reg; |
| 547 | unsigned int i; |
| 548 | |
Takashi Iwai | a922cd7 | 2013-11-05 18:39:50 +0100 | [diff] [blame] | 549 | if (WARN_ON(band > 1) || |
| 550 | WARN_ON(dai > 1)) |
| 551 | return; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 552 | |
| 553 | /* Load the base register address */ |
| 554 | bq_reg = dai ? M98095_17E_DAI2_BQ_BASE : M98095_174_DAI1_BQ_BASE; |
| 555 | |
| 556 | /* Add the band address offset, note adjustment for word address */ |
| 557 | bq_reg += band * (M98095_COEFS_PER_BAND << 1); |
| 558 | |
| 559 | /* Step through the registers and coefs */ |
| 560 | for (i = 0; i < M98095_COEFS_PER_BAND; i++) { |
Mark Brown | d36126a | 2013-09-23 18:58:59 +0100 | [diff] [blame] | 561 | snd_soc_write(codec, bq_reg++, M98095_BYTE1(coefs[i])); |
| 562 | snd_soc_write(codec, bq_reg++, M98095_BYTE0(coefs[i])); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 566 | static const char * const max98095_fltr_mode[] = { "Voice", "Music" }; |
Takashi Iwai | af1f0a5 | 2014-02-18 10:15:26 +0100 | [diff] [blame] | 567 | static SOC_ENUM_SINGLE_DECL(max98095_dai1_filter_mode_enum, |
| 568 | M98095_02E_DAI1_FILTERS, 7, |
| 569 | max98095_fltr_mode); |
| 570 | static SOC_ENUM_SINGLE_DECL(max98095_dai2_filter_mode_enum, |
| 571 | M98095_038_DAI2_FILTERS, 7, |
| 572 | max98095_fltr_mode); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 573 | |
| 574 | static const char * const max98095_extmic_text[] = { "None", "MIC1", "MIC2" }; |
| 575 | |
Takashi Iwai | af1f0a5 | 2014-02-18 10:15:26 +0100 | [diff] [blame] | 576 | static SOC_ENUM_SINGLE_DECL(max98095_extmic_enum, |
| 577 | M98095_087_CFG_MIC, 0, |
| 578 | max98095_extmic_text); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 579 | |
| 580 | static const struct snd_kcontrol_new max98095_extmic_mux = |
| 581 | SOC_DAPM_ENUM("External MIC Mux", max98095_extmic_enum); |
| 582 | |
| 583 | static const char * const max98095_linein_text[] = { "INA", "INB" }; |
| 584 | |
Takashi Iwai | af1f0a5 | 2014-02-18 10:15:26 +0100 | [diff] [blame] | 585 | static SOC_ENUM_SINGLE_DECL(max98095_linein_enum, |
| 586 | M98095_086_CFG_LINE, 6, |
| 587 | max98095_linein_text); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 588 | |
| 589 | static const struct snd_kcontrol_new max98095_linein_mux = |
| 590 | SOC_DAPM_ENUM("Linein Input Mux", max98095_linein_enum); |
| 591 | |
| 592 | static const char * const max98095_line_mode_text[] = { |
| 593 | "Stereo", "Differential"}; |
| 594 | |
Takashi Iwai | af1f0a5 | 2014-02-18 10:15:26 +0100 | [diff] [blame] | 595 | static SOC_ENUM_SINGLE_DECL(max98095_linein_mode_enum, |
| 596 | M98095_086_CFG_LINE, 7, |
| 597 | max98095_line_mode_text); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 598 | |
Takashi Iwai | af1f0a5 | 2014-02-18 10:15:26 +0100 | [diff] [blame] | 599 | static SOC_ENUM_SINGLE_DECL(max98095_lineout_mode_enum, |
| 600 | M98095_086_CFG_LINE, 4, |
| 601 | max98095_line_mode_text); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 602 | |
| 603 | static const char * const max98095_dai_fltr[] = { |
| 604 | "Off", "Elliptical-HPF-16k", "Butterworth-HPF-16k", |
| 605 | "Elliptical-HPF-8k", "Butterworth-HPF-8k", "Butterworth-HPF-Fs/240"}; |
Takashi Iwai | af1f0a5 | 2014-02-18 10:15:26 +0100 | [diff] [blame] | 606 | static SOC_ENUM_SINGLE_DECL(max98095_dai1_dac_filter_enum, |
| 607 | M98095_02E_DAI1_FILTERS, 0, |
| 608 | max98095_dai_fltr); |
| 609 | static SOC_ENUM_SINGLE_DECL(max98095_dai2_dac_filter_enum, |
| 610 | M98095_038_DAI2_FILTERS, 0, |
| 611 | max98095_dai_fltr); |
| 612 | static SOC_ENUM_SINGLE_DECL(max98095_dai3_dac_filter_enum, |
| 613 | M98095_042_DAI3_FILTERS, 0, |
| 614 | max98095_dai_fltr); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 615 | |
| 616 | static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol, |
| 617 | struct snd_ctl_elem_value *ucontrol) |
| 618 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 619 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 620 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 621 | unsigned int sel = ucontrol->value.integer.value[0]; |
| 622 | |
| 623 | max98095->mic1pre = sel; |
| 624 | snd_soc_update_bits(codec, M98095_05F_LVL_MIC1, M98095_MICPRE_MASK, |
| 625 | (1+sel)<<M98095_MICPRE_SHIFT); |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | static int max98095_mic1pre_get(struct snd_kcontrol *kcontrol, |
| 631 | struct snd_ctl_elem_value *ucontrol) |
| 632 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 633 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 634 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 635 | |
| 636 | ucontrol->value.integer.value[0] = max98095->mic1pre; |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | static int max98095_mic2pre_set(struct snd_kcontrol *kcontrol, |
| 641 | struct snd_ctl_elem_value *ucontrol) |
| 642 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 643 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 644 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 645 | unsigned int sel = ucontrol->value.integer.value[0]; |
| 646 | |
| 647 | max98095->mic2pre = sel; |
| 648 | snd_soc_update_bits(codec, M98095_060_LVL_MIC2, M98095_MICPRE_MASK, |
| 649 | (1+sel)<<M98095_MICPRE_SHIFT); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int max98095_mic2pre_get(struct snd_kcontrol *kcontrol, |
| 655 | struct snd_ctl_elem_value *ucontrol) |
| 656 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 657 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 658 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 659 | |
| 660 | ucontrol->value.integer.value[0] = max98095->mic2pre; |
| 661 | return 0; |
| 662 | } |
| 663 | |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 664 | static const DECLARE_TLV_DB_RANGE(max98095_micboost_tlv, |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 665 | 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0), |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 666 | 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0) |
| 667 | ); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 668 | |
| 669 | static const DECLARE_TLV_DB_SCALE(max98095_mic_tlv, 0, 100, 0); |
| 670 | static const DECLARE_TLV_DB_SCALE(max98095_adc_tlv, -1200, 100, 0); |
| 671 | static const DECLARE_TLV_DB_SCALE(max98095_adcboost_tlv, 0, 600, 0); |
| 672 | |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 673 | static const DECLARE_TLV_DB_RANGE(max98095_hp_tlv, |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 674 | 0, 6, TLV_DB_SCALE_ITEM(-6700, 400, 0), |
| 675 | 7, 14, TLV_DB_SCALE_ITEM(-4000, 300, 0), |
| 676 | 15, 21, TLV_DB_SCALE_ITEM(-1700, 200, 0), |
| 677 | 22, 27, TLV_DB_SCALE_ITEM(-400, 100, 0), |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 678 | 28, 31, TLV_DB_SCALE_ITEM(150, 50, 0) |
| 679 | ); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 680 | |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 681 | static const DECLARE_TLV_DB_RANGE(max98095_spk_tlv, |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 682 | 0, 10, TLV_DB_SCALE_ITEM(-5900, 400, 0), |
| 683 | 11, 18, TLV_DB_SCALE_ITEM(-1700, 200, 0), |
| 684 | 19, 27, TLV_DB_SCALE_ITEM(-200, 100, 0), |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 685 | 28, 39, TLV_DB_SCALE_ITEM(650, 50, 0) |
| 686 | ); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 687 | |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 688 | static const DECLARE_TLV_DB_RANGE(max98095_rcv_lout_tlv, |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 689 | 0, 6, TLV_DB_SCALE_ITEM(-6200, 400, 0), |
| 690 | 7, 14, TLV_DB_SCALE_ITEM(-3500, 300, 0), |
| 691 | 15, 21, TLV_DB_SCALE_ITEM(-1200, 200, 0), |
| 692 | 22, 27, TLV_DB_SCALE_ITEM(100, 100, 0), |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 693 | 28, 31, TLV_DB_SCALE_ITEM(650, 50, 0) |
| 694 | ); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 695 | |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 696 | static const DECLARE_TLV_DB_RANGE(max98095_lin_tlv, |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 697 | 0, 2, TLV_DB_SCALE_ITEM(-600, 300, 0), |
| 698 | 3, 3, TLV_DB_SCALE_ITEM(300, 1100, 0), |
Lars-Peter Clausen | 54c2011 | 2015-08-02 17:19:44 +0200 | [diff] [blame] | 699 | 4, 5, TLV_DB_SCALE_ITEM(1400, 600, 0) |
| 700 | ); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 701 | |
| 702 | static const struct snd_kcontrol_new max98095_snd_controls[] = { |
| 703 | |
| 704 | SOC_DOUBLE_R_TLV("Headphone Volume", M98095_064_LVL_HP_L, |
| 705 | M98095_065_LVL_HP_R, 0, 31, 0, max98095_hp_tlv), |
| 706 | |
| 707 | SOC_DOUBLE_R_TLV("Speaker Volume", M98095_067_LVL_SPK_L, |
| 708 | M98095_068_LVL_SPK_R, 0, 39, 0, max98095_spk_tlv), |
| 709 | |
| 710 | SOC_SINGLE_TLV("Receiver Volume", M98095_066_LVL_RCV, |
| 711 | 0, 31, 0, max98095_rcv_lout_tlv), |
| 712 | |
| 713 | SOC_DOUBLE_R_TLV("Lineout Volume", M98095_062_LVL_LINEOUT1, |
| 714 | M98095_063_LVL_LINEOUT2, 0, 31, 0, max98095_rcv_lout_tlv), |
| 715 | |
| 716 | SOC_DOUBLE_R("Headphone Switch", M98095_064_LVL_HP_L, |
| 717 | M98095_065_LVL_HP_R, 7, 1, 1), |
| 718 | |
| 719 | SOC_DOUBLE_R("Speaker Switch", M98095_067_LVL_SPK_L, |
| 720 | M98095_068_LVL_SPK_R, 7, 1, 1), |
| 721 | |
| 722 | SOC_SINGLE("Receiver Switch", M98095_066_LVL_RCV, 7, 1, 1), |
| 723 | |
| 724 | SOC_DOUBLE_R("Lineout Switch", M98095_062_LVL_LINEOUT1, |
| 725 | M98095_063_LVL_LINEOUT2, 7, 1, 1), |
| 726 | |
| 727 | SOC_SINGLE_TLV("MIC1 Volume", M98095_05F_LVL_MIC1, 0, 20, 1, |
| 728 | max98095_mic_tlv), |
| 729 | |
| 730 | SOC_SINGLE_TLV("MIC2 Volume", M98095_060_LVL_MIC2, 0, 20, 1, |
| 731 | max98095_mic_tlv), |
| 732 | |
| 733 | SOC_SINGLE_EXT_TLV("MIC1 Boost Volume", |
| 734 | M98095_05F_LVL_MIC1, 5, 2, 0, |
| 735 | max98095_mic1pre_get, max98095_mic1pre_set, |
| 736 | max98095_micboost_tlv), |
| 737 | SOC_SINGLE_EXT_TLV("MIC2 Boost Volume", |
| 738 | M98095_060_LVL_MIC2, 5, 2, 0, |
| 739 | max98095_mic2pre_get, max98095_mic2pre_set, |
| 740 | max98095_micboost_tlv), |
| 741 | |
| 742 | SOC_SINGLE_TLV("Linein Volume", M98095_061_LVL_LINEIN, 0, 5, 1, |
| 743 | max98095_lin_tlv), |
| 744 | |
| 745 | SOC_SINGLE_TLV("ADCL Volume", M98095_05D_LVL_ADC_L, 0, 15, 1, |
| 746 | max98095_adc_tlv), |
| 747 | SOC_SINGLE_TLV("ADCR Volume", M98095_05E_LVL_ADC_R, 0, 15, 1, |
| 748 | max98095_adc_tlv), |
| 749 | |
| 750 | SOC_SINGLE_TLV("ADCL Boost Volume", M98095_05D_LVL_ADC_L, 4, 3, 0, |
| 751 | max98095_adcboost_tlv), |
| 752 | SOC_SINGLE_TLV("ADCR Boost Volume", M98095_05E_LVL_ADC_R, 4, 3, 0, |
| 753 | max98095_adcboost_tlv), |
| 754 | |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 755 | SOC_SINGLE("EQ1 Switch", M98095_088_CFG_LEVEL, 0, 1, 0), |
| 756 | SOC_SINGLE("EQ2 Switch", M98095_088_CFG_LEVEL, 1, 1, 0), |
| 757 | |
| 758 | SOC_SINGLE("Biquad1 Switch", M98095_088_CFG_LEVEL, 2, 1, 0), |
| 759 | SOC_SINGLE("Biquad2 Switch", M98095_088_CFG_LEVEL, 3, 1, 0), |
| 760 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 761 | SOC_ENUM("DAI1 Filter Mode", max98095_dai1_filter_mode_enum), |
| 762 | SOC_ENUM("DAI2 Filter Mode", max98095_dai2_filter_mode_enum), |
| 763 | SOC_ENUM("DAI1 DAC Filter", max98095_dai1_dac_filter_enum), |
| 764 | SOC_ENUM("DAI2 DAC Filter", max98095_dai2_dac_filter_enum), |
| 765 | SOC_ENUM("DAI3 DAC Filter", max98095_dai3_dac_filter_enum), |
| 766 | |
| 767 | SOC_ENUM("Linein Mode", max98095_linein_mode_enum), |
| 768 | SOC_ENUM("Lineout Mode", max98095_lineout_mode_enum), |
| 769 | }; |
| 770 | |
| 771 | /* Left speaker mixer switch */ |
| 772 | static const struct snd_kcontrol_new max98095_left_speaker_mixer_controls[] = { |
| 773 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_050_MIX_SPK_LEFT, 0, 1, 0), |
| 774 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_050_MIX_SPK_LEFT, 6, 1, 0), |
| 775 | SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_050_MIX_SPK_LEFT, 3, 1, 0), |
| 776 | SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_050_MIX_SPK_LEFT, 3, 1, 0), |
| 777 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_050_MIX_SPK_LEFT, 4, 1, 0), |
| 778 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_050_MIX_SPK_LEFT, 5, 1, 0), |
| 779 | SOC_DAPM_SINGLE("IN1 Switch", M98095_050_MIX_SPK_LEFT, 1, 1, 0), |
| 780 | SOC_DAPM_SINGLE("IN2 Switch", M98095_050_MIX_SPK_LEFT, 2, 1, 0), |
| 781 | }; |
| 782 | |
| 783 | /* Right speaker mixer switch */ |
| 784 | static const struct snd_kcontrol_new max98095_right_speaker_mixer_controls[] = { |
| 785 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_051_MIX_SPK_RIGHT, 6, 1, 0), |
| 786 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_051_MIX_SPK_RIGHT, 0, 1, 0), |
| 787 | SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_051_MIX_SPK_RIGHT, 3, 1, 0), |
| 788 | SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_051_MIX_SPK_RIGHT, 3, 1, 0), |
| 789 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_051_MIX_SPK_RIGHT, 5, 1, 0), |
| 790 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_051_MIX_SPK_RIGHT, 4, 1, 0), |
| 791 | SOC_DAPM_SINGLE("IN1 Switch", M98095_051_MIX_SPK_RIGHT, 1, 1, 0), |
| 792 | SOC_DAPM_SINGLE("IN2 Switch", M98095_051_MIX_SPK_RIGHT, 2, 1, 0), |
| 793 | }; |
| 794 | |
| 795 | /* Left headphone mixer switch */ |
| 796 | static const struct snd_kcontrol_new max98095_left_hp_mixer_controls[] = { |
| 797 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04C_MIX_HP_LEFT, 0, 1, 0), |
| 798 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04C_MIX_HP_LEFT, 5, 1, 0), |
| 799 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_04C_MIX_HP_LEFT, 3, 1, 0), |
| 800 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_04C_MIX_HP_LEFT, 4, 1, 0), |
| 801 | SOC_DAPM_SINGLE("IN1 Switch", M98095_04C_MIX_HP_LEFT, 1, 1, 0), |
| 802 | SOC_DAPM_SINGLE("IN2 Switch", M98095_04C_MIX_HP_LEFT, 2, 1, 0), |
| 803 | }; |
| 804 | |
| 805 | /* Right headphone mixer switch */ |
| 806 | static const struct snd_kcontrol_new max98095_right_hp_mixer_controls[] = { |
| 807 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04D_MIX_HP_RIGHT, 5, 1, 0), |
| 808 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04D_MIX_HP_RIGHT, 0, 1, 0), |
| 809 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_04D_MIX_HP_RIGHT, 3, 1, 0), |
| 810 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_04D_MIX_HP_RIGHT, 4, 1, 0), |
| 811 | SOC_DAPM_SINGLE("IN1 Switch", M98095_04D_MIX_HP_RIGHT, 1, 1, 0), |
| 812 | SOC_DAPM_SINGLE("IN2 Switch", M98095_04D_MIX_HP_RIGHT, 2, 1, 0), |
| 813 | }; |
| 814 | |
| 815 | /* Receiver earpiece mixer switch */ |
| 816 | static const struct snd_kcontrol_new max98095_mono_rcv_mixer_controls[] = { |
| 817 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04F_MIX_RCV, 0, 1, 0), |
| 818 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04F_MIX_RCV, 5, 1, 0), |
| 819 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_04F_MIX_RCV, 3, 1, 0), |
| 820 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_04F_MIX_RCV, 4, 1, 0), |
| 821 | SOC_DAPM_SINGLE("IN1 Switch", M98095_04F_MIX_RCV, 1, 1, 0), |
| 822 | SOC_DAPM_SINGLE("IN2 Switch", M98095_04F_MIX_RCV, 2, 1, 0), |
| 823 | }; |
| 824 | |
| 825 | /* Left lineout mixer switch */ |
| 826 | static const struct snd_kcontrol_new max98095_left_lineout_mixer_controls[] = { |
| 827 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_053_MIX_LINEOUT1, 5, 1, 0), |
| 828 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_053_MIX_LINEOUT1, 0, 1, 0), |
| 829 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_053_MIX_LINEOUT1, 3, 1, 0), |
| 830 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_053_MIX_LINEOUT1, 4, 1, 0), |
| 831 | SOC_DAPM_SINGLE("IN1 Switch", M98095_053_MIX_LINEOUT1, 1, 1, 0), |
| 832 | SOC_DAPM_SINGLE("IN2 Switch", M98095_053_MIX_LINEOUT1, 2, 1, 0), |
| 833 | }; |
| 834 | |
| 835 | /* Right lineout mixer switch */ |
| 836 | static const struct snd_kcontrol_new max98095_right_lineout_mixer_controls[] = { |
| 837 | SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_054_MIX_LINEOUT2, 0, 1, 0), |
| 838 | SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_054_MIX_LINEOUT2, 5, 1, 0), |
| 839 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_054_MIX_LINEOUT2, 3, 1, 0), |
| 840 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_054_MIX_LINEOUT2, 4, 1, 0), |
| 841 | SOC_DAPM_SINGLE("IN1 Switch", M98095_054_MIX_LINEOUT2, 1, 1, 0), |
| 842 | SOC_DAPM_SINGLE("IN2 Switch", M98095_054_MIX_LINEOUT2, 2, 1, 0), |
| 843 | }; |
| 844 | |
| 845 | /* Left ADC mixer switch */ |
| 846 | static const struct snd_kcontrol_new max98095_left_ADC_mixer_controls[] = { |
| 847 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_04A_MIX_ADC_LEFT, 7, 1, 0), |
| 848 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_04A_MIX_ADC_LEFT, 6, 1, 0), |
| 849 | SOC_DAPM_SINGLE("IN1 Switch", M98095_04A_MIX_ADC_LEFT, 3, 1, 0), |
| 850 | SOC_DAPM_SINGLE("IN2 Switch", M98095_04A_MIX_ADC_LEFT, 2, 1, 0), |
| 851 | }; |
| 852 | |
| 853 | /* Right ADC mixer switch */ |
| 854 | static const struct snd_kcontrol_new max98095_right_ADC_mixer_controls[] = { |
| 855 | SOC_DAPM_SINGLE("MIC1 Switch", M98095_04B_MIX_ADC_RIGHT, 7, 1, 0), |
| 856 | SOC_DAPM_SINGLE("MIC2 Switch", M98095_04B_MIX_ADC_RIGHT, 6, 1, 0), |
| 857 | SOC_DAPM_SINGLE("IN1 Switch", M98095_04B_MIX_ADC_RIGHT, 3, 1, 0), |
| 858 | SOC_DAPM_SINGLE("IN2 Switch", M98095_04B_MIX_ADC_RIGHT, 2, 1, 0), |
| 859 | }; |
| 860 | |
| 861 | static int max98095_mic_event(struct snd_soc_dapm_widget *w, |
| 862 | struct snd_kcontrol *kcontrol, int event) |
| 863 | { |
Lars-Peter Clausen | 0db5dc9 | 2014-11-20 21:21:55 +0100 | [diff] [blame] | 864 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 865 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 866 | |
| 867 | switch (event) { |
| 868 | case SND_SOC_DAPM_POST_PMU: |
| 869 | if (w->reg == M98095_05F_LVL_MIC1) { |
| 870 | snd_soc_update_bits(codec, w->reg, M98095_MICPRE_MASK, |
| 871 | (1+max98095->mic1pre)<<M98095_MICPRE_SHIFT); |
| 872 | } else { |
| 873 | snd_soc_update_bits(codec, w->reg, M98095_MICPRE_MASK, |
| 874 | (1+max98095->mic2pre)<<M98095_MICPRE_SHIFT); |
| 875 | } |
| 876 | break; |
| 877 | case SND_SOC_DAPM_POST_PMD: |
| 878 | snd_soc_update_bits(codec, w->reg, M98095_MICPRE_MASK, 0); |
| 879 | break; |
| 880 | default: |
| 881 | return -EINVAL; |
| 882 | } |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * The line inputs are stereo inputs with the left and right |
| 889 | * channels sharing a common PGA power control signal. |
| 890 | */ |
| 891 | static int max98095_line_pga(struct snd_soc_dapm_widget *w, |
| 892 | int event, u8 channel) |
| 893 | { |
Lars-Peter Clausen | 0db5dc9 | 2014-11-20 21:21:55 +0100 | [diff] [blame] | 894 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 895 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 896 | u8 *state; |
| 897 | |
Takashi Iwai | a922cd7 | 2013-11-05 18:39:50 +0100 | [diff] [blame] | 898 | if (WARN_ON(!(channel == 1 || channel == 2))) |
| 899 | return -EINVAL; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 900 | |
| 901 | state = &max98095->lin_state; |
| 902 | |
| 903 | switch (event) { |
| 904 | case SND_SOC_DAPM_POST_PMU: |
| 905 | *state |= channel; |
| 906 | snd_soc_update_bits(codec, w->reg, |
| 907 | (1 << w->shift), (1 << w->shift)); |
| 908 | break; |
| 909 | case SND_SOC_DAPM_POST_PMD: |
| 910 | *state &= ~channel; |
| 911 | if (*state == 0) { |
| 912 | snd_soc_update_bits(codec, w->reg, |
| 913 | (1 << w->shift), 0); |
| 914 | } |
| 915 | break; |
| 916 | default: |
| 917 | return -EINVAL; |
| 918 | } |
| 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | static int max98095_pga_in1_event(struct snd_soc_dapm_widget *w, |
| 924 | struct snd_kcontrol *k, int event) |
| 925 | { |
| 926 | return max98095_line_pga(w, event, 1); |
| 927 | } |
| 928 | |
| 929 | static int max98095_pga_in2_event(struct snd_soc_dapm_widget *w, |
| 930 | struct snd_kcontrol *k, int event) |
| 931 | { |
| 932 | return max98095_line_pga(w, event, 2); |
| 933 | } |
| 934 | |
| 935 | /* |
| 936 | * The stereo line out mixer outputs to two stereo line outs. |
| 937 | * The 2nd pair has a separate set of enables. |
| 938 | */ |
| 939 | static int max98095_lineout_event(struct snd_soc_dapm_widget *w, |
| 940 | struct snd_kcontrol *kcontrol, int event) |
| 941 | { |
Lars-Peter Clausen | 0db5dc9 | 2014-11-20 21:21:55 +0100 | [diff] [blame] | 942 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 943 | |
| 944 | switch (event) { |
| 945 | case SND_SOC_DAPM_POST_PMU: |
| 946 | snd_soc_update_bits(codec, w->reg, |
| 947 | (1 << (w->shift+2)), (1 << (w->shift+2))); |
| 948 | break; |
| 949 | case SND_SOC_DAPM_POST_PMD: |
| 950 | snd_soc_update_bits(codec, w->reg, |
| 951 | (1 << (w->shift+2)), 0); |
| 952 | break; |
| 953 | default: |
| 954 | return -EINVAL; |
| 955 | } |
| 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | static const struct snd_soc_dapm_widget max98095_dapm_widgets[] = { |
| 961 | |
| 962 | SND_SOC_DAPM_ADC("ADCL", "HiFi Capture", M98095_090_PWR_EN_IN, 0, 0), |
| 963 | SND_SOC_DAPM_ADC("ADCR", "HiFi Capture", M98095_090_PWR_EN_IN, 1, 0), |
| 964 | |
| 965 | SND_SOC_DAPM_DAC("DACL1", "HiFi Playback", |
| 966 | M98095_091_PWR_EN_OUT, 0, 0), |
| 967 | SND_SOC_DAPM_DAC("DACR1", "HiFi Playback", |
| 968 | M98095_091_PWR_EN_OUT, 1, 0), |
| 969 | SND_SOC_DAPM_DAC("DACM2", "Aux Playback", |
| 970 | M98095_091_PWR_EN_OUT, 2, 0), |
| 971 | SND_SOC_DAPM_DAC("DACM3", "Voice Playback", |
| 972 | M98095_091_PWR_EN_OUT, 2, 0), |
| 973 | |
| 974 | SND_SOC_DAPM_PGA("HP Left Out", M98095_091_PWR_EN_OUT, |
| 975 | 6, 0, NULL, 0), |
| 976 | SND_SOC_DAPM_PGA("HP Right Out", M98095_091_PWR_EN_OUT, |
| 977 | 7, 0, NULL, 0), |
| 978 | |
| 979 | SND_SOC_DAPM_PGA("SPK Left Out", M98095_091_PWR_EN_OUT, |
| 980 | 4, 0, NULL, 0), |
| 981 | SND_SOC_DAPM_PGA("SPK Right Out", M98095_091_PWR_EN_OUT, |
| 982 | 5, 0, NULL, 0), |
| 983 | |
| 984 | SND_SOC_DAPM_PGA("RCV Mono Out", M98095_091_PWR_EN_OUT, |
| 985 | 3, 0, NULL, 0), |
| 986 | |
| 987 | SND_SOC_DAPM_PGA_E("LINE Left Out", M98095_092_PWR_EN_OUT, |
| 988 | 0, 0, NULL, 0, max98095_lineout_event, SND_SOC_DAPM_PRE_PMD), |
| 989 | SND_SOC_DAPM_PGA_E("LINE Right Out", M98095_092_PWR_EN_OUT, |
| 990 | 1, 0, NULL, 0, max98095_lineout_event, SND_SOC_DAPM_PRE_PMD), |
| 991 | |
| 992 | SND_SOC_DAPM_MUX("External MIC", SND_SOC_NOPM, 0, 0, |
| 993 | &max98095_extmic_mux), |
| 994 | |
| 995 | SND_SOC_DAPM_MUX("Linein Mux", SND_SOC_NOPM, 0, 0, |
| 996 | &max98095_linein_mux), |
| 997 | |
| 998 | SND_SOC_DAPM_MIXER("Left Headphone Mixer", SND_SOC_NOPM, 0, 0, |
| 999 | &max98095_left_hp_mixer_controls[0], |
| 1000 | ARRAY_SIZE(max98095_left_hp_mixer_controls)), |
| 1001 | |
| 1002 | SND_SOC_DAPM_MIXER("Right Headphone Mixer", SND_SOC_NOPM, 0, 0, |
| 1003 | &max98095_right_hp_mixer_controls[0], |
| 1004 | ARRAY_SIZE(max98095_right_hp_mixer_controls)), |
| 1005 | |
| 1006 | SND_SOC_DAPM_MIXER("Left Speaker Mixer", SND_SOC_NOPM, 0, 0, |
| 1007 | &max98095_left_speaker_mixer_controls[0], |
| 1008 | ARRAY_SIZE(max98095_left_speaker_mixer_controls)), |
| 1009 | |
| 1010 | SND_SOC_DAPM_MIXER("Right Speaker Mixer", SND_SOC_NOPM, 0, 0, |
| 1011 | &max98095_right_speaker_mixer_controls[0], |
| 1012 | ARRAY_SIZE(max98095_right_speaker_mixer_controls)), |
| 1013 | |
| 1014 | SND_SOC_DAPM_MIXER("Receiver Mixer", SND_SOC_NOPM, 0, 0, |
| 1015 | &max98095_mono_rcv_mixer_controls[0], |
| 1016 | ARRAY_SIZE(max98095_mono_rcv_mixer_controls)), |
| 1017 | |
| 1018 | SND_SOC_DAPM_MIXER("Left Lineout Mixer", SND_SOC_NOPM, 0, 0, |
| 1019 | &max98095_left_lineout_mixer_controls[0], |
| 1020 | ARRAY_SIZE(max98095_left_lineout_mixer_controls)), |
| 1021 | |
| 1022 | SND_SOC_DAPM_MIXER("Right Lineout Mixer", SND_SOC_NOPM, 0, 0, |
| 1023 | &max98095_right_lineout_mixer_controls[0], |
| 1024 | ARRAY_SIZE(max98095_right_lineout_mixer_controls)), |
| 1025 | |
| 1026 | SND_SOC_DAPM_MIXER("Left ADC Mixer", SND_SOC_NOPM, 0, 0, |
| 1027 | &max98095_left_ADC_mixer_controls[0], |
| 1028 | ARRAY_SIZE(max98095_left_ADC_mixer_controls)), |
| 1029 | |
| 1030 | SND_SOC_DAPM_MIXER("Right ADC Mixer", SND_SOC_NOPM, 0, 0, |
| 1031 | &max98095_right_ADC_mixer_controls[0], |
| 1032 | ARRAY_SIZE(max98095_right_ADC_mixer_controls)), |
| 1033 | |
| 1034 | SND_SOC_DAPM_PGA_E("MIC1 Input", M98095_05F_LVL_MIC1, |
| 1035 | 5, 0, NULL, 0, max98095_mic_event, |
| 1036 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1037 | |
| 1038 | SND_SOC_DAPM_PGA_E("MIC2 Input", M98095_060_LVL_MIC2, |
| 1039 | 5, 0, NULL, 0, max98095_mic_event, |
| 1040 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1041 | |
| 1042 | SND_SOC_DAPM_PGA_E("IN1 Input", M98095_090_PWR_EN_IN, |
| 1043 | 7, 0, NULL, 0, max98095_pga_in1_event, |
| 1044 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1045 | |
| 1046 | SND_SOC_DAPM_PGA_E("IN2 Input", M98095_090_PWR_EN_IN, |
| 1047 | 7, 0, NULL, 0, max98095_pga_in2_event, |
| 1048 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1049 | |
| 1050 | SND_SOC_DAPM_MICBIAS("MICBIAS1", M98095_090_PWR_EN_IN, 2, 0), |
| 1051 | SND_SOC_DAPM_MICBIAS("MICBIAS2", M98095_090_PWR_EN_IN, 3, 0), |
| 1052 | |
| 1053 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 1054 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 1055 | SND_SOC_DAPM_OUTPUT("SPKL"), |
| 1056 | SND_SOC_DAPM_OUTPUT("SPKR"), |
| 1057 | SND_SOC_DAPM_OUTPUT("RCV"), |
| 1058 | SND_SOC_DAPM_OUTPUT("OUT1"), |
| 1059 | SND_SOC_DAPM_OUTPUT("OUT2"), |
| 1060 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 1061 | SND_SOC_DAPM_OUTPUT("OUT4"), |
| 1062 | |
| 1063 | SND_SOC_DAPM_INPUT("MIC1"), |
| 1064 | SND_SOC_DAPM_INPUT("MIC2"), |
| 1065 | SND_SOC_DAPM_INPUT("INA1"), |
| 1066 | SND_SOC_DAPM_INPUT("INA2"), |
| 1067 | SND_SOC_DAPM_INPUT("INB1"), |
| 1068 | SND_SOC_DAPM_INPUT("INB2"), |
| 1069 | }; |
| 1070 | |
| 1071 | static const struct snd_soc_dapm_route max98095_audio_map[] = { |
| 1072 | /* Left headphone output mixer */ |
| 1073 | {"Left Headphone Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1074 | {"Left Headphone Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1075 | {"Left Headphone Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1076 | {"Left Headphone Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1077 | {"Left Headphone Mixer", "IN1 Switch", "IN1 Input"}, |
| 1078 | {"Left Headphone Mixer", "IN2 Switch", "IN2 Input"}, |
| 1079 | |
| 1080 | /* Right headphone output mixer */ |
| 1081 | {"Right Headphone Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1082 | {"Right Headphone Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1083 | {"Right Headphone Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1084 | {"Right Headphone Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1085 | {"Right Headphone Mixer", "IN1 Switch", "IN1 Input"}, |
| 1086 | {"Right Headphone Mixer", "IN2 Switch", "IN2 Input"}, |
| 1087 | |
| 1088 | /* Left speaker output mixer */ |
| 1089 | {"Left Speaker Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1090 | {"Left Speaker Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1091 | {"Left Speaker Mixer", "Mono DAC2 Switch", "DACM2"}, |
| 1092 | {"Left Speaker Mixer", "Mono DAC3 Switch", "DACM3"}, |
| 1093 | {"Left Speaker Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1094 | {"Left Speaker Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1095 | {"Left Speaker Mixer", "IN1 Switch", "IN1 Input"}, |
| 1096 | {"Left Speaker Mixer", "IN2 Switch", "IN2 Input"}, |
| 1097 | |
| 1098 | /* Right speaker output mixer */ |
| 1099 | {"Right Speaker Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1100 | {"Right Speaker Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1101 | {"Right Speaker Mixer", "Mono DAC2 Switch", "DACM2"}, |
| 1102 | {"Right Speaker Mixer", "Mono DAC3 Switch", "DACM3"}, |
| 1103 | {"Right Speaker Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1104 | {"Right Speaker Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1105 | {"Right Speaker Mixer", "IN1 Switch", "IN1 Input"}, |
| 1106 | {"Right Speaker Mixer", "IN2 Switch", "IN2 Input"}, |
| 1107 | |
| 1108 | /* Earpiece/Receiver output mixer */ |
| 1109 | {"Receiver Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1110 | {"Receiver Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1111 | {"Receiver Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1112 | {"Receiver Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1113 | {"Receiver Mixer", "IN1 Switch", "IN1 Input"}, |
| 1114 | {"Receiver Mixer", "IN2 Switch", "IN2 Input"}, |
| 1115 | |
| 1116 | /* Left Lineout output mixer */ |
| 1117 | {"Left Lineout Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1118 | {"Left Lineout Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1119 | {"Left Lineout Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1120 | {"Left Lineout Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1121 | {"Left Lineout Mixer", "IN1 Switch", "IN1 Input"}, |
| 1122 | {"Left Lineout Mixer", "IN2 Switch", "IN2 Input"}, |
| 1123 | |
| 1124 | /* Right lineout output mixer */ |
| 1125 | {"Right Lineout Mixer", "Left DAC1 Switch", "DACL1"}, |
| 1126 | {"Right Lineout Mixer", "Right DAC1 Switch", "DACR1"}, |
| 1127 | {"Right Lineout Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1128 | {"Right Lineout Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1129 | {"Right Lineout Mixer", "IN1 Switch", "IN1 Input"}, |
| 1130 | {"Right Lineout Mixer", "IN2 Switch", "IN2 Input"}, |
| 1131 | |
| 1132 | {"HP Left Out", NULL, "Left Headphone Mixer"}, |
| 1133 | {"HP Right Out", NULL, "Right Headphone Mixer"}, |
| 1134 | {"SPK Left Out", NULL, "Left Speaker Mixer"}, |
| 1135 | {"SPK Right Out", NULL, "Right Speaker Mixer"}, |
| 1136 | {"RCV Mono Out", NULL, "Receiver Mixer"}, |
| 1137 | {"LINE Left Out", NULL, "Left Lineout Mixer"}, |
| 1138 | {"LINE Right Out", NULL, "Right Lineout Mixer"}, |
| 1139 | |
| 1140 | {"HPL", NULL, "HP Left Out"}, |
| 1141 | {"HPR", NULL, "HP Right Out"}, |
| 1142 | {"SPKL", NULL, "SPK Left Out"}, |
| 1143 | {"SPKR", NULL, "SPK Right Out"}, |
| 1144 | {"RCV", NULL, "RCV Mono Out"}, |
| 1145 | {"OUT1", NULL, "LINE Left Out"}, |
| 1146 | {"OUT2", NULL, "LINE Right Out"}, |
| 1147 | {"OUT3", NULL, "LINE Left Out"}, |
| 1148 | {"OUT4", NULL, "LINE Right Out"}, |
| 1149 | |
| 1150 | /* Left ADC input mixer */ |
| 1151 | {"Left ADC Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1152 | {"Left ADC Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1153 | {"Left ADC Mixer", "IN1 Switch", "IN1 Input"}, |
| 1154 | {"Left ADC Mixer", "IN2 Switch", "IN2 Input"}, |
| 1155 | |
| 1156 | /* Right ADC input mixer */ |
| 1157 | {"Right ADC Mixer", "MIC1 Switch", "MIC1 Input"}, |
| 1158 | {"Right ADC Mixer", "MIC2 Switch", "MIC2 Input"}, |
| 1159 | {"Right ADC Mixer", "IN1 Switch", "IN1 Input"}, |
| 1160 | {"Right ADC Mixer", "IN2 Switch", "IN2 Input"}, |
| 1161 | |
| 1162 | /* Inputs */ |
| 1163 | {"ADCL", NULL, "Left ADC Mixer"}, |
| 1164 | {"ADCR", NULL, "Right ADC Mixer"}, |
| 1165 | |
| 1166 | {"IN1 Input", NULL, "INA1"}, |
| 1167 | {"IN2 Input", NULL, "INA2"}, |
| 1168 | |
| 1169 | {"MIC1 Input", NULL, "MIC1"}, |
| 1170 | {"MIC2 Input", NULL, "MIC2"}, |
| 1171 | }; |
| 1172 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1173 | /* codec mclk clock divider coefficients */ |
| 1174 | static const struct { |
| 1175 | u32 rate; |
| 1176 | u8 sr; |
| 1177 | } rate_table[] = { |
| 1178 | {8000, 0x01}, |
| 1179 | {11025, 0x02}, |
| 1180 | {16000, 0x03}, |
| 1181 | {22050, 0x04}, |
| 1182 | {24000, 0x05}, |
| 1183 | {32000, 0x06}, |
| 1184 | {44100, 0x07}, |
| 1185 | {48000, 0x08}, |
| 1186 | {88200, 0x09}, |
| 1187 | {96000, 0x0A}, |
| 1188 | }; |
| 1189 | |
| 1190 | static int rate_value(int rate, u8 *value) |
| 1191 | { |
| 1192 | int i; |
| 1193 | |
| 1194 | for (i = 0; i < ARRAY_SIZE(rate_table); i++) { |
| 1195 | if (rate_table[i].rate >= rate) { |
| 1196 | *value = rate_table[i].sr; |
| 1197 | return 0; |
| 1198 | } |
| 1199 | } |
| 1200 | *value = rate_table[0].sr; |
| 1201 | return -EINVAL; |
| 1202 | } |
| 1203 | |
| 1204 | static int max98095_dai1_hw_params(struct snd_pcm_substream *substream, |
| 1205 | struct snd_pcm_hw_params *params, |
| 1206 | struct snd_soc_dai *dai) |
| 1207 | { |
| 1208 | struct snd_soc_codec *codec = dai->codec; |
| 1209 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1210 | struct max98095_cdata *cdata; |
| 1211 | unsigned long long ni; |
| 1212 | unsigned int rate; |
| 1213 | u8 regval; |
| 1214 | |
| 1215 | cdata = &max98095->dai[0]; |
| 1216 | |
| 1217 | rate = params_rate(params); |
| 1218 | |
Mark Brown | 580ce08 | 2014-01-08 20:39:37 +0000 | [diff] [blame] | 1219 | switch (params_width(params)) { |
| 1220 | case 16: |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1221 | snd_soc_update_bits(codec, M98095_02A_DAI1_FORMAT, |
| 1222 | M98095_DAI_WS, 0); |
| 1223 | break; |
Mark Brown | 580ce08 | 2014-01-08 20:39:37 +0000 | [diff] [blame] | 1224 | case 24: |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1225 | snd_soc_update_bits(codec, M98095_02A_DAI1_FORMAT, |
| 1226 | M98095_DAI_WS, M98095_DAI_WS); |
| 1227 | break; |
| 1228 | default: |
| 1229 | return -EINVAL; |
| 1230 | } |
| 1231 | |
| 1232 | if (rate_value(rate, ®val)) |
| 1233 | return -EINVAL; |
| 1234 | |
| 1235 | snd_soc_update_bits(codec, M98095_027_DAI1_CLKMODE, |
| 1236 | M98095_CLKMODE_MASK, regval); |
| 1237 | cdata->rate = rate; |
| 1238 | |
| 1239 | /* Configure NI when operating as master */ |
| 1240 | if (snd_soc_read(codec, M98095_02A_DAI1_FORMAT) & M98095_DAI_MAS) { |
| 1241 | if (max98095->sysclk == 0) { |
| 1242 | dev_err(codec->dev, "Invalid system clock frequency\n"); |
| 1243 | return -EINVAL; |
| 1244 | } |
| 1245 | ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL) |
| 1246 | * (unsigned long long int)rate; |
| 1247 | do_div(ni, (unsigned long long int)max98095->sysclk); |
| 1248 | snd_soc_write(codec, M98095_028_DAI1_CLKCFG_HI, |
| 1249 | (ni >> 8) & 0x7F); |
| 1250 | snd_soc_write(codec, M98095_029_DAI1_CLKCFG_LO, |
| 1251 | ni & 0xFF); |
| 1252 | } |
| 1253 | |
| 1254 | /* Update sample rate mode */ |
| 1255 | if (rate < 50000) |
| 1256 | snd_soc_update_bits(codec, M98095_02E_DAI1_FILTERS, |
| 1257 | M98095_DAI_DHF, 0); |
| 1258 | else |
| 1259 | snd_soc_update_bits(codec, M98095_02E_DAI1_FILTERS, |
| 1260 | M98095_DAI_DHF, M98095_DAI_DHF); |
| 1261 | |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | static int max98095_dai2_hw_params(struct snd_pcm_substream *substream, |
| 1266 | struct snd_pcm_hw_params *params, |
| 1267 | struct snd_soc_dai *dai) |
| 1268 | { |
| 1269 | struct snd_soc_codec *codec = dai->codec; |
| 1270 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1271 | struct max98095_cdata *cdata; |
| 1272 | unsigned long long ni; |
| 1273 | unsigned int rate; |
| 1274 | u8 regval; |
| 1275 | |
| 1276 | cdata = &max98095->dai[1]; |
| 1277 | |
| 1278 | rate = params_rate(params); |
| 1279 | |
Mark Brown | 1ae1f3a | 2014-07-31 12:31:56 +0100 | [diff] [blame] | 1280 | switch (params_width(params)) { |
| 1281 | case 16: |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1282 | snd_soc_update_bits(codec, M98095_034_DAI2_FORMAT, |
| 1283 | M98095_DAI_WS, 0); |
| 1284 | break; |
Mark Brown | 1ae1f3a | 2014-07-31 12:31:56 +0100 | [diff] [blame] | 1285 | case 24: |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1286 | snd_soc_update_bits(codec, M98095_034_DAI2_FORMAT, |
| 1287 | M98095_DAI_WS, M98095_DAI_WS); |
| 1288 | break; |
| 1289 | default: |
| 1290 | return -EINVAL; |
| 1291 | } |
| 1292 | |
| 1293 | if (rate_value(rate, ®val)) |
| 1294 | return -EINVAL; |
| 1295 | |
| 1296 | snd_soc_update_bits(codec, M98095_031_DAI2_CLKMODE, |
| 1297 | M98095_CLKMODE_MASK, regval); |
| 1298 | cdata->rate = rate; |
| 1299 | |
| 1300 | /* Configure NI when operating as master */ |
| 1301 | if (snd_soc_read(codec, M98095_034_DAI2_FORMAT) & M98095_DAI_MAS) { |
| 1302 | if (max98095->sysclk == 0) { |
| 1303 | dev_err(codec->dev, "Invalid system clock frequency\n"); |
| 1304 | return -EINVAL; |
| 1305 | } |
| 1306 | ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL) |
| 1307 | * (unsigned long long int)rate; |
| 1308 | do_div(ni, (unsigned long long int)max98095->sysclk); |
| 1309 | snd_soc_write(codec, M98095_032_DAI2_CLKCFG_HI, |
| 1310 | (ni >> 8) & 0x7F); |
| 1311 | snd_soc_write(codec, M98095_033_DAI2_CLKCFG_LO, |
| 1312 | ni & 0xFF); |
| 1313 | } |
| 1314 | |
| 1315 | /* Update sample rate mode */ |
| 1316 | if (rate < 50000) |
| 1317 | snd_soc_update_bits(codec, M98095_038_DAI2_FILTERS, |
| 1318 | M98095_DAI_DHF, 0); |
| 1319 | else |
| 1320 | snd_soc_update_bits(codec, M98095_038_DAI2_FILTERS, |
| 1321 | M98095_DAI_DHF, M98095_DAI_DHF); |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | static int max98095_dai3_hw_params(struct snd_pcm_substream *substream, |
| 1327 | struct snd_pcm_hw_params *params, |
| 1328 | struct snd_soc_dai *dai) |
| 1329 | { |
| 1330 | struct snd_soc_codec *codec = dai->codec; |
| 1331 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1332 | struct max98095_cdata *cdata; |
| 1333 | unsigned long long ni; |
| 1334 | unsigned int rate; |
| 1335 | u8 regval; |
| 1336 | |
| 1337 | cdata = &max98095->dai[2]; |
| 1338 | |
| 1339 | rate = params_rate(params); |
| 1340 | |
Mark Brown | 1ae1f3a | 2014-07-31 12:31:56 +0100 | [diff] [blame] | 1341 | switch (params_width(params)) { |
| 1342 | case 16: |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1343 | snd_soc_update_bits(codec, M98095_03E_DAI3_FORMAT, |
| 1344 | M98095_DAI_WS, 0); |
| 1345 | break; |
Mark Brown | 1ae1f3a | 2014-07-31 12:31:56 +0100 | [diff] [blame] | 1346 | case 24: |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1347 | snd_soc_update_bits(codec, M98095_03E_DAI3_FORMAT, |
| 1348 | M98095_DAI_WS, M98095_DAI_WS); |
| 1349 | break; |
| 1350 | default: |
| 1351 | return -EINVAL; |
| 1352 | } |
| 1353 | |
| 1354 | if (rate_value(rate, ®val)) |
| 1355 | return -EINVAL; |
| 1356 | |
| 1357 | snd_soc_update_bits(codec, M98095_03B_DAI3_CLKMODE, |
| 1358 | M98095_CLKMODE_MASK, regval); |
| 1359 | cdata->rate = rate; |
| 1360 | |
| 1361 | /* Configure NI when operating as master */ |
| 1362 | if (snd_soc_read(codec, M98095_03E_DAI3_FORMAT) & M98095_DAI_MAS) { |
| 1363 | if (max98095->sysclk == 0) { |
| 1364 | dev_err(codec->dev, "Invalid system clock frequency\n"); |
| 1365 | return -EINVAL; |
| 1366 | } |
| 1367 | ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL) |
| 1368 | * (unsigned long long int)rate; |
| 1369 | do_div(ni, (unsigned long long int)max98095->sysclk); |
| 1370 | snd_soc_write(codec, M98095_03C_DAI3_CLKCFG_HI, |
| 1371 | (ni >> 8) & 0x7F); |
| 1372 | snd_soc_write(codec, M98095_03D_DAI3_CLKCFG_LO, |
| 1373 | ni & 0xFF); |
| 1374 | } |
| 1375 | |
| 1376 | /* Update sample rate mode */ |
| 1377 | if (rate < 50000) |
| 1378 | snd_soc_update_bits(codec, M98095_042_DAI3_FILTERS, |
| 1379 | M98095_DAI_DHF, 0); |
| 1380 | else |
| 1381 | snd_soc_update_bits(codec, M98095_042_DAI3_FILTERS, |
| 1382 | M98095_DAI_DHF, M98095_DAI_DHF); |
| 1383 | |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | static int max98095_dai_set_sysclk(struct snd_soc_dai *dai, |
| 1388 | int clk_id, unsigned int freq, int dir) |
| 1389 | { |
| 1390 | struct snd_soc_codec *codec = dai->codec; |
| 1391 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1392 | |
| 1393 | /* Requested clock frequency is already setup */ |
| 1394 | if (freq == max98095->sysclk) |
| 1395 | return 0; |
| 1396 | |
Tushar Behera | e3048c3 | 2014-05-26 13:58:22 +0530 | [diff] [blame] | 1397 | if (!IS_ERR(max98095->mclk)) { |
| 1398 | freq = clk_round_rate(max98095->mclk, freq); |
| 1399 | clk_set_rate(max98095->mclk, freq); |
| 1400 | } |
| 1401 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1402 | /* Setup clocks for slave mode, and using the PLL |
| 1403 | * PSCLK = 0x01 (when master clk is 10MHz to 20MHz) |
| 1404 | * 0x02 (when master clk is 20MHz to 40MHz).. |
| 1405 | * 0x03 (when master clk is 40MHz to 60MHz).. |
| 1406 | */ |
| 1407 | if ((freq >= 10000000) && (freq < 20000000)) { |
| 1408 | snd_soc_write(codec, M98095_026_SYS_CLK, 0x10); |
| 1409 | } else if ((freq >= 20000000) && (freq < 40000000)) { |
| 1410 | snd_soc_write(codec, M98095_026_SYS_CLK, 0x20); |
| 1411 | } else if ((freq >= 40000000) && (freq < 60000000)) { |
| 1412 | snd_soc_write(codec, M98095_026_SYS_CLK, 0x30); |
| 1413 | } else { |
| 1414 | dev_err(codec->dev, "Invalid master clock frequency\n"); |
| 1415 | return -EINVAL; |
| 1416 | } |
| 1417 | |
| 1418 | dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq); |
| 1419 | |
| 1420 | max98095->sysclk = freq; |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | static int max98095_dai1_set_fmt(struct snd_soc_dai *codec_dai, |
| 1425 | unsigned int fmt) |
| 1426 | { |
| 1427 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1428 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1429 | struct max98095_cdata *cdata; |
| 1430 | u8 regval = 0; |
| 1431 | |
| 1432 | cdata = &max98095->dai[0]; |
| 1433 | |
| 1434 | if (fmt != cdata->fmt) { |
| 1435 | cdata->fmt = fmt; |
| 1436 | |
| 1437 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1438 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1439 | /* Slave mode PLL */ |
| 1440 | snd_soc_write(codec, M98095_028_DAI1_CLKCFG_HI, |
| 1441 | 0x80); |
| 1442 | snd_soc_write(codec, M98095_029_DAI1_CLKCFG_LO, |
| 1443 | 0x00); |
| 1444 | break; |
| 1445 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1446 | /* Set to master mode */ |
| 1447 | regval |= M98095_DAI_MAS; |
| 1448 | break; |
| 1449 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1450 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1451 | default: |
| 1452 | dev_err(codec->dev, "Clock mode unsupported"); |
| 1453 | return -EINVAL; |
| 1454 | } |
| 1455 | |
| 1456 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1457 | case SND_SOC_DAIFMT_I2S: |
| 1458 | regval |= M98095_DAI_DLY; |
| 1459 | break; |
| 1460 | case SND_SOC_DAIFMT_LEFT_J: |
| 1461 | break; |
| 1462 | default: |
| 1463 | return -EINVAL; |
| 1464 | } |
| 1465 | |
| 1466 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1467 | case SND_SOC_DAIFMT_NB_NF: |
| 1468 | break; |
| 1469 | case SND_SOC_DAIFMT_NB_IF: |
| 1470 | regval |= M98095_DAI_WCI; |
| 1471 | break; |
| 1472 | case SND_SOC_DAIFMT_IB_NF: |
| 1473 | regval |= M98095_DAI_BCI; |
| 1474 | break; |
| 1475 | case SND_SOC_DAIFMT_IB_IF: |
| 1476 | regval |= M98095_DAI_BCI|M98095_DAI_WCI; |
| 1477 | break; |
| 1478 | default: |
| 1479 | return -EINVAL; |
| 1480 | } |
| 1481 | |
| 1482 | snd_soc_update_bits(codec, M98095_02A_DAI1_FORMAT, |
| 1483 | M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI | |
| 1484 | M98095_DAI_WCI, regval); |
| 1485 | |
| 1486 | snd_soc_write(codec, M98095_02B_DAI1_CLOCK, M98095_DAI_BSEL64); |
| 1487 | } |
| 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | static int max98095_dai2_set_fmt(struct snd_soc_dai *codec_dai, |
| 1493 | unsigned int fmt) |
| 1494 | { |
| 1495 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1496 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1497 | struct max98095_cdata *cdata; |
| 1498 | u8 regval = 0; |
| 1499 | |
| 1500 | cdata = &max98095->dai[1]; |
| 1501 | |
| 1502 | if (fmt != cdata->fmt) { |
| 1503 | cdata->fmt = fmt; |
| 1504 | |
| 1505 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1506 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1507 | /* Slave mode PLL */ |
| 1508 | snd_soc_write(codec, M98095_032_DAI2_CLKCFG_HI, |
| 1509 | 0x80); |
| 1510 | snd_soc_write(codec, M98095_033_DAI2_CLKCFG_LO, |
| 1511 | 0x00); |
| 1512 | break; |
| 1513 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1514 | /* Set to master mode */ |
| 1515 | regval |= M98095_DAI_MAS; |
| 1516 | break; |
| 1517 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1518 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1519 | default: |
| 1520 | dev_err(codec->dev, "Clock mode unsupported"); |
| 1521 | return -EINVAL; |
| 1522 | } |
| 1523 | |
| 1524 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1525 | case SND_SOC_DAIFMT_I2S: |
| 1526 | regval |= M98095_DAI_DLY; |
| 1527 | break; |
| 1528 | case SND_SOC_DAIFMT_LEFT_J: |
| 1529 | break; |
| 1530 | default: |
| 1531 | return -EINVAL; |
| 1532 | } |
| 1533 | |
| 1534 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1535 | case SND_SOC_DAIFMT_NB_NF: |
| 1536 | break; |
| 1537 | case SND_SOC_DAIFMT_NB_IF: |
| 1538 | regval |= M98095_DAI_WCI; |
| 1539 | break; |
| 1540 | case SND_SOC_DAIFMT_IB_NF: |
| 1541 | regval |= M98095_DAI_BCI; |
| 1542 | break; |
| 1543 | case SND_SOC_DAIFMT_IB_IF: |
| 1544 | regval |= M98095_DAI_BCI|M98095_DAI_WCI; |
| 1545 | break; |
| 1546 | default: |
| 1547 | return -EINVAL; |
| 1548 | } |
| 1549 | |
| 1550 | snd_soc_update_bits(codec, M98095_034_DAI2_FORMAT, |
| 1551 | M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI | |
| 1552 | M98095_DAI_WCI, regval); |
| 1553 | |
| 1554 | snd_soc_write(codec, M98095_035_DAI2_CLOCK, |
| 1555 | M98095_DAI_BSEL64); |
| 1556 | } |
| 1557 | |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | static int max98095_dai3_set_fmt(struct snd_soc_dai *codec_dai, |
| 1562 | unsigned int fmt) |
| 1563 | { |
| 1564 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1565 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1566 | struct max98095_cdata *cdata; |
| 1567 | u8 regval = 0; |
| 1568 | |
| 1569 | cdata = &max98095->dai[2]; |
| 1570 | |
| 1571 | if (fmt != cdata->fmt) { |
| 1572 | cdata->fmt = fmt; |
| 1573 | |
| 1574 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1575 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1576 | /* Slave mode PLL */ |
| 1577 | snd_soc_write(codec, M98095_03C_DAI3_CLKCFG_HI, |
| 1578 | 0x80); |
| 1579 | snd_soc_write(codec, M98095_03D_DAI3_CLKCFG_LO, |
| 1580 | 0x00); |
| 1581 | break; |
| 1582 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1583 | /* Set to master mode */ |
| 1584 | regval |= M98095_DAI_MAS; |
| 1585 | break; |
| 1586 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1587 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1588 | default: |
| 1589 | dev_err(codec->dev, "Clock mode unsupported"); |
| 1590 | return -EINVAL; |
| 1591 | } |
| 1592 | |
| 1593 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1594 | case SND_SOC_DAIFMT_I2S: |
| 1595 | regval |= M98095_DAI_DLY; |
| 1596 | break; |
| 1597 | case SND_SOC_DAIFMT_LEFT_J: |
| 1598 | break; |
| 1599 | default: |
| 1600 | return -EINVAL; |
| 1601 | } |
| 1602 | |
| 1603 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1604 | case SND_SOC_DAIFMT_NB_NF: |
| 1605 | break; |
| 1606 | case SND_SOC_DAIFMT_NB_IF: |
| 1607 | regval |= M98095_DAI_WCI; |
| 1608 | break; |
| 1609 | case SND_SOC_DAIFMT_IB_NF: |
| 1610 | regval |= M98095_DAI_BCI; |
| 1611 | break; |
| 1612 | case SND_SOC_DAIFMT_IB_IF: |
| 1613 | regval |= M98095_DAI_BCI|M98095_DAI_WCI; |
| 1614 | break; |
| 1615 | default: |
| 1616 | return -EINVAL; |
| 1617 | } |
| 1618 | |
| 1619 | snd_soc_update_bits(codec, M98095_03E_DAI3_FORMAT, |
| 1620 | M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI | |
| 1621 | M98095_DAI_WCI, regval); |
| 1622 | |
| 1623 | snd_soc_write(codec, M98095_03F_DAI3_CLOCK, |
| 1624 | M98095_DAI_BSEL64); |
| 1625 | } |
| 1626 | |
| 1627 | return 0; |
| 1628 | } |
| 1629 | |
| 1630 | static int max98095_set_bias_level(struct snd_soc_codec *codec, |
| 1631 | enum snd_soc_bias_level level) |
| 1632 | { |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 1633 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1634 | int ret; |
| 1635 | |
| 1636 | switch (level) { |
| 1637 | case SND_SOC_BIAS_ON: |
| 1638 | break; |
| 1639 | |
| 1640 | case SND_SOC_BIAS_PREPARE: |
Tushar Behera | e3048c3 | 2014-05-26 13:58:22 +0530 | [diff] [blame] | 1641 | /* |
| 1642 | * SND_SOC_BIAS_PREPARE is called while preparing for a |
| 1643 | * transition to ON or away from ON. If current bias_level |
| 1644 | * is SND_SOC_BIAS_ON, then it is preparing for a transition |
| 1645 | * away from ON. Disable the clock in that case, otherwise |
| 1646 | * enable it. |
| 1647 | */ |
Lars-Peter Clausen | 1179a36 | 2015-05-14 11:20:02 +0200 | [diff] [blame] | 1648 | if (IS_ERR(max98095->mclk)) |
| 1649 | break; |
| 1650 | |
| 1651 | if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) |
| 1652 | clk_disable_unprepare(max98095->mclk); |
| 1653 | else |
| 1654 | clk_prepare_enable(max98095->mclk); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1655 | break; |
| 1656 | |
| 1657 | case SND_SOC_BIAS_STANDBY: |
Lars-Peter Clausen | 1179a36 | 2015-05-14 11:20:02 +0200 | [diff] [blame] | 1658 | if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 1659 | ret = regcache_sync(max98095->regmap); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1660 | |
| 1661 | if (ret != 0) { |
| 1662 | dev_err(codec->dev, "Failed to sync cache: %d\n", ret); |
| 1663 | return ret; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | snd_soc_update_bits(codec, M98095_090_PWR_EN_IN, |
| 1668 | M98095_MBEN, M98095_MBEN); |
| 1669 | break; |
| 1670 | |
| 1671 | case SND_SOC_BIAS_OFF: |
| 1672 | snd_soc_update_bits(codec, M98095_090_PWR_EN_IN, |
| 1673 | M98095_MBEN, 0); |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 1674 | regcache_mark_dirty(max98095->regmap); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1675 | break; |
| 1676 | } |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1677 | return 0; |
| 1678 | } |
| 1679 | |
| 1680 | #define MAX98095_RATES SNDRV_PCM_RATE_8000_96000 |
| 1681 | #define MAX98095_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE) |
| 1682 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1683 | static const struct snd_soc_dai_ops max98095_dai1_ops = { |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1684 | .set_sysclk = max98095_dai_set_sysclk, |
| 1685 | .set_fmt = max98095_dai1_set_fmt, |
| 1686 | .hw_params = max98095_dai1_hw_params, |
| 1687 | }; |
| 1688 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1689 | static const struct snd_soc_dai_ops max98095_dai2_ops = { |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1690 | .set_sysclk = max98095_dai_set_sysclk, |
| 1691 | .set_fmt = max98095_dai2_set_fmt, |
| 1692 | .hw_params = max98095_dai2_hw_params, |
| 1693 | }; |
| 1694 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1695 | static const struct snd_soc_dai_ops max98095_dai3_ops = { |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 1696 | .set_sysclk = max98095_dai_set_sysclk, |
| 1697 | .set_fmt = max98095_dai3_set_fmt, |
| 1698 | .hw_params = max98095_dai3_hw_params, |
| 1699 | }; |
| 1700 | |
| 1701 | static struct snd_soc_dai_driver max98095_dai[] = { |
| 1702 | { |
| 1703 | .name = "HiFi", |
| 1704 | .playback = { |
| 1705 | .stream_name = "HiFi Playback", |
| 1706 | .channels_min = 1, |
| 1707 | .channels_max = 2, |
| 1708 | .rates = MAX98095_RATES, |
| 1709 | .formats = MAX98095_FORMATS, |
| 1710 | }, |
| 1711 | .capture = { |
| 1712 | .stream_name = "HiFi Capture", |
| 1713 | .channels_min = 1, |
| 1714 | .channels_max = 2, |
| 1715 | .rates = MAX98095_RATES, |
| 1716 | .formats = MAX98095_FORMATS, |
| 1717 | }, |
| 1718 | .ops = &max98095_dai1_ops, |
| 1719 | }, |
| 1720 | { |
| 1721 | .name = "Aux", |
| 1722 | .playback = { |
| 1723 | .stream_name = "Aux Playback", |
| 1724 | .channels_min = 1, |
| 1725 | .channels_max = 1, |
| 1726 | .rates = MAX98095_RATES, |
| 1727 | .formats = MAX98095_FORMATS, |
| 1728 | }, |
| 1729 | .ops = &max98095_dai2_ops, |
| 1730 | }, |
| 1731 | { |
| 1732 | .name = "Voice", |
| 1733 | .playback = { |
| 1734 | .stream_name = "Voice Playback", |
| 1735 | .channels_min = 1, |
| 1736 | .channels_max = 1, |
| 1737 | .rates = MAX98095_RATES, |
| 1738 | .formats = MAX98095_FORMATS, |
| 1739 | }, |
| 1740 | .ops = &max98095_dai3_ops, |
| 1741 | } |
| 1742 | |
| 1743 | }; |
| 1744 | |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1745 | static int max98095_get_eq_channel(const char *name) |
| 1746 | { |
| 1747 | if (strcmp(name, "EQ1 Mode") == 0) |
| 1748 | return 0; |
| 1749 | if (strcmp(name, "EQ2 Mode") == 0) |
| 1750 | return 1; |
| 1751 | return -EINVAL; |
| 1752 | } |
| 1753 | |
| 1754 | static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol, |
| 1755 | struct snd_ctl_elem_value *ucontrol) |
| 1756 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 1757 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1758 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1759 | struct max98095_pdata *pdata = max98095->pdata; |
| 1760 | int channel = max98095_get_eq_channel(kcontrol->id.name); |
| 1761 | struct max98095_cdata *cdata; |
Dan Carpenter | f8d7b13 | 2013-09-13 10:52:14 +0300 | [diff] [blame] | 1762 | unsigned int sel = ucontrol->value.integer.value[0]; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1763 | struct max98095_eq_cfg *coef_set; |
| 1764 | int fs, best, best_val, i; |
| 1765 | int regmask, regsave; |
| 1766 | |
Takashi Iwai | a922cd7 | 2013-11-05 18:39:50 +0100 | [diff] [blame] | 1767 | if (WARN_ON(channel > 1)) |
| 1768 | return -EINVAL; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1769 | |
Taylor Hutt | 5394942 | 2011-05-17 18:03:54 -0700 | [diff] [blame] | 1770 | if (!pdata || !max98095->eq_textcnt) |
| 1771 | return 0; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1772 | |
| 1773 | if (sel >= pdata->eq_cfgcnt) |
| 1774 | return -EINVAL; |
| 1775 | |
Taylor Hutt | 5394942 | 2011-05-17 18:03:54 -0700 | [diff] [blame] | 1776 | cdata = &max98095->dai[channel]; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1777 | cdata->eq_sel = sel; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1778 | fs = cdata->rate; |
| 1779 | |
| 1780 | /* Find the selected configuration with nearest sample rate */ |
| 1781 | best = 0; |
| 1782 | best_val = INT_MAX; |
| 1783 | for (i = 0; i < pdata->eq_cfgcnt; i++) { |
| 1784 | if (strcmp(pdata->eq_cfg[i].name, max98095->eq_texts[sel]) == 0 && |
| 1785 | abs(pdata->eq_cfg[i].rate - fs) < best_val) { |
| 1786 | best = i; |
| 1787 | best_val = abs(pdata->eq_cfg[i].rate - fs); |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | dev_dbg(codec->dev, "Selected %s/%dHz for %dHz sample rate\n", |
| 1792 | pdata->eq_cfg[best].name, |
| 1793 | pdata->eq_cfg[best].rate, fs); |
| 1794 | |
| 1795 | coef_set = &pdata->eq_cfg[best]; |
| 1796 | |
| 1797 | regmask = (channel == 0) ? M98095_EQ1EN : M98095_EQ2EN; |
| 1798 | |
| 1799 | /* Disable filter while configuring, and save current on/off state */ |
| 1800 | regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL); |
| 1801 | snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0); |
| 1802 | |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 1803 | mutex_lock(&max98095->lock); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1804 | snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG); |
| 1805 | m98095_eq_band(codec, channel, 0, coef_set->band1); |
| 1806 | m98095_eq_band(codec, channel, 1, coef_set->band2); |
| 1807 | m98095_eq_band(codec, channel, 2, coef_set->band3); |
| 1808 | m98095_eq_band(codec, channel, 3, coef_set->band4); |
| 1809 | m98095_eq_band(codec, channel, 4, coef_set->band5); |
| 1810 | snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0); |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 1811 | mutex_unlock(&max98095->lock); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1812 | |
| 1813 | /* Restore the original on/off state */ |
| 1814 | snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave); |
| 1815 | return 0; |
| 1816 | } |
| 1817 | |
| 1818 | static int max98095_get_eq_enum(struct snd_kcontrol *kcontrol, |
| 1819 | struct snd_ctl_elem_value *ucontrol) |
| 1820 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 1821 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1822 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1823 | int channel = max98095_get_eq_channel(kcontrol->id.name); |
| 1824 | struct max98095_cdata *cdata; |
| 1825 | |
| 1826 | cdata = &max98095->dai[channel]; |
| 1827 | ucontrol->value.enumerated.item[0] = cdata->eq_sel; |
| 1828 | |
| 1829 | return 0; |
| 1830 | } |
| 1831 | |
| 1832 | static void max98095_handle_eq_pdata(struct snd_soc_codec *codec) |
| 1833 | { |
| 1834 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1835 | struct max98095_pdata *pdata = max98095->pdata; |
| 1836 | struct max98095_eq_cfg *cfg; |
| 1837 | unsigned int cfgcnt; |
| 1838 | int i, j; |
| 1839 | const char **t; |
| 1840 | int ret; |
| 1841 | |
| 1842 | struct snd_kcontrol_new controls[] = { |
| 1843 | SOC_ENUM_EXT("EQ1 Mode", |
| 1844 | max98095->eq_enum, |
| 1845 | max98095_get_eq_enum, |
| 1846 | max98095_put_eq_enum), |
| 1847 | SOC_ENUM_EXT("EQ2 Mode", |
| 1848 | max98095->eq_enum, |
| 1849 | max98095_get_eq_enum, |
| 1850 | max98095_put_eq_enum), |
| 1851 | }; |
| 1852 | |
| 1853 | cfg = pdata->eq_cfg; |
| 1854 | cfgcnt = pdata->eq_cfgcnt; |
| 1855 | |
| 1856 | /* Setup an array of texts for the equalizer enum. |
| 1857 | * This is based on Mark Brown's equalizer driver code. |
| 1858 | */ |
| 1859 | max98095->eq_textcnt = 0; |
| 1860 | max98095->eq_texts = NULL; |
| 1861 | for (i = 0; i < cfgcnt; i++) { |
| 1862 | for (j = 0; j < max98095->eq_textcnt; j++) { |
| 1863 | if (strcmp(cfg[i].name, max98095->eq_texts[j]) == 0) |
| 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | if (j != max98095->eq_textcnt) |
| 1868 | continue; |
| 1869 | |
| 1870 | /* Expand the array */ |
| 1871 | t = krealloc(max98095->eq_texts, |
| 1872 | sizeof(char *) * (max98095->eq_textcnt + 1), |
| 1873 | GFP_KERNEL); |
| 1874 | if (t == NULL) |
| 1875 | continue; |
| 1876 | |
| 1877 | /* Store the new entry */ |
| 1878 | t[max98095->eq_textcnt] = cfg[i].name; |
| 1879 | max98095->eq_textcnt++; |
| 1880 | max98095->eq_texts = t; |
| 1881 | } |
| 1882 | |
| 1883 | /* Now point the soc_enum to .texts array items */ |
| 1884 | max98095->eq_enum.texts = max98095->eq_texts; |
Takashi Iwai | 9a8d38d | 2014-02-18 08:11:42 +0100 | [diff] [blame] | 1885 | max98095->eq_enum.items = max98095->eq_textcnt; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1886 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1887 | ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls)); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1888 | if (ret != 0) |
| 1889 | dev_err(codec->dev, "Failed to add EQ control: %d\n", ret); |
| 1890 | } |
| 1891 | |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1892 | static const char *bq_mode_name[] = {"Biquad1 Mode", "Biquad2 Mode"}; |
| 1893 | |
| 1894 | static int max98095_get_bq_channel(struct snd_soc_codec *codec, |
| 1895 | const char *name) |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1896 | { |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1897 | int i; |
| 1898 | |
| 1899 | for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++) |
| 1900 | if (strcmp(name, bq_mode_name[i]) == 0) |
| 1901 | return i; |
| 1902 | |
| 1903 | /* Shouldn't happen */ |
| 1904 | dev_err(codec->dev, "Bad biquad channel name '%s'\n", name); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1905 | return -EINVAL; |
| 1906 | } |
| 1907 | |
| 1908 | static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol, |
| 1909 | struct snd_ctl_elem_value *ucontrol) |
| 1910 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 1911 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1912 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1913 | struct max98095_pdata *pdata = max98095->pdata; |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1914 | int channel = max98095_get_bq_channel(codec, kcontrol->id.name); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1915 | struct max98095_cdata *cdata; |
Dan Carpenter | f8d7b13 | 2013-09-13 10:52:14 +0300 | [diff] [blame] | 1916 | unsigned int sel = ucontrol->value.integer.value[0]; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1917 | struct max98095_biquad_cfg *coef_set; |
| 1918 | int fs, best, best_val, i; |
| 1919 | int regmask, regsave; |
| 1920 | |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1921 | if (channel < 0) |
| 1922 | return channel; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1923 | |
Taylor Hutt | 5394942 | 2011-05-17 18:03:54 -0700 | [diff] [blame] | 1924 | if (!pdata || !max98095->bq_textcnt) |
| 1925 | return 0; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1926 | |
| 1927 | if (sel >= pdata->bq_cfgcnt) |
| 1928 | return -EINVAL; |
| 1929 | |
Taylor Hutt | 5394942 | 2011-05-17 18:03:54 -0700 | [diff] [blame] | 1930 | cdata = &max98095->dai[channel]; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1931 | cdata->bq_sel = sel; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1932 | fs = cdata->rate; |
| 1933 | |
| 1934 | /* Find the selected configuration with nearest sample rate */ |
| 1935 | best = 0; |
| 1936 | best_val = INT_MAX; |
| 1937 | for (i = 0; i < pdata->bq_cfgcnt; i++) { |
| 1938 | if (strcmp(pdata->bq_cfg[i].name, max98095->bq_texts[sel]) == 0 && |
| 1939 | abs(pdata->bq_cfg[i].rate - fs) < best_val) { |
| 1940 | best = i; |
| 1941 | best_val = abs(pdata->bq_cfg[i].rate - fs); |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | dev_dbg(codec->dev, "Selected %s/%dHz for %dHz sample rate\n", |
| 1946 | pdata->bq_cfg[best].name, |
| 1947 | pdata->bq_cfg[best].rate, fs); |
| 1948 | |
| 1949 | coef_set = &pdata->bq_cfg[best]; |
| 1950 | |
| 1951 | regmask = (channel == 0) ? M98095_BQ1EN : M98095_BQ2EN; |
| 1952 | |
| 1953 | /* Disable filter while configuring, and save current on/off state */ |
| 1954 | regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL); |
| 1955 | snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0); |
| 1956 | |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 1957 | mutex_lock(&max98095->lock); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1958 | snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG); |
| 1959 | m98095_biquad_band(codec, channel, 0, coef_set->band1); |
| 1960 | m98095_biquad_band(codec, channel, 1, coef_set->band2); |
| 1961 | snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0); |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 1962 | mutex_unlock(&max98095->lock); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1963 | |
| 1964 | /* Restore the original on/off state */ |
| 1965 | snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave); |
| 1966 | return 0; |
| 1967 | } |
| 1968 | |
| 1969 | static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol, |
| 1970 | struct snd_ctl_elem_value *ucontrol) |
| 1971 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 1972 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1973 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1974 | int channel = max98095_get_bq_channel(codec, kcontrol->id.name); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1975 | struct max98095_cdata *cdata; |
| 1976 | |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1977 | if (channel < 0) |
| 1978 | return channel; |
| 1979 | |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1980 | cdata = &max98095->dai[channel]; |
| 1981 | ucontrol->value.enumerated.item[0] = cdata->bq_sel; |
| 1982 | |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | static void max98095_handle_bq_pdata(struct snd_soc_codec *codec) |
| 1987 | { |
| 1988 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 1989 | struct max98095_pdata *pdata = max98095->pdata; |
| 1990 | struct max98095_biquad_cfg *cfg; |
| 1991 | unsigned int cfgcnt; |
| 1992 | int i, j; |
| 1993 | const char **t; |
| 1994 | int ret; |
| 1995 | |
| 1996 | struct snd_kcontrol_new controls[] = { |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 1997 | SOC_ENUM_EXT((char *)bq_mode_name[0], |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 1998 | max98095->bq_enum, |
| 1999 | max98095_get_bq_enum, |
| 2000 | max98095_put_bq_enum), |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 2001 | SOC_ENUM_EXT((char *)bq_mode_name[1], |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2002 | max98095->bq_enum, |
| 2003 | max98095_get_bq_enum, |
| 2004 | max98095_put_bq_enum), |
| 2005 | }; |
Ryan Mallon | c855a1a | 2011-10-04 09:55:41 +1100 | [diff] [blame] | 2006 | BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(bq_mode_name)); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2007 | |
| 2008 | cfg = pdata->bq_cfg; |
| 2009 | cfgcnt = pdata->bq_cfgcnt; |
| 2010 | |
| 2011 | /* Setup an array of texts for the biquad enum. |
| 2012 | * This is based on Mark Brown's equalizer driver code. |
| 2013 | */ |
| 2014 | max98095->bq_textcnt = 0; |
| 2015 | max98095->bq_texts = NULL; |
| 2016 | for (i = 0; i < cfgcnt; i++) { |
| 2017 | for (j = 0; j < max98095->bq_textcnt; j++) { |
| 2018 | if (strcmp(cfg[i].name, max98095->bq_texts[j]) == 0) |
| 2019 | break; |
| 2020 | } |
| 2021 | |
| 2022 | if (j != max98095->bq_textcnt) |
| 2023 | continue; |
| 2024 | |
| 2025 | /* Expand the array */ |
| 2026 | t = krealloc(max98095->bq_texts, |
| 2027 | sizeof(char *) * (max98095->bq_textcnt + 1), |
| 2028 | GFP_KERNEL); |
| 2029 | if (t == NULL) |
| 2030 | continue; |
| 2031 | |
| 2032 | /* Store the new entry */ |
| 2033 | t[max98095->bq_textcnt] = cfg[i].name; |
| 2034 | max98095->bq_textcnt++; |
| 2035 | max98095->bq_texts = t; |
| 2036 | } |
| 2037 | |
| 2038 | /* Now point the soc_enum to .texts array items */ |
| 2039 | max98095->bq_enum.texts = max98095->bq_texts; |
Takashi Iwai | 9a8d38d | 2014-02-18 08:11:42 +0100 | [diff] [blame] | 2040 | max98095->bq_enum.items = max98095->bq_textcnt; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2041 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2042 | ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls)); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2043 | if (ret != 0) |
| 2044 | dev_err(codec->dev, "Failed to add Biquad control: %d\n", ret); |
| 2045 | } |
| 2046 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2047 | static void max98095_handle_pdata(struct snd_soc_codec *codec) |
| 2048 | { |
| 2049 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2050 | struct max98095_pdata *pdata = max98095->pdata; |
| 2051 | u8 regval = 0; |
| 2052 | |
| 2053 | if (!pdata) { |
| 2054 | dev_dbg(codec->dev, "No platform data\n"); |
| 2055 | return; |
| 2056 | } |
| 2057 | |
| 2058 | /* Configure mic for analog/digital mic mode */ |
| 2059 | if (pdata->digmic_left_mode) |
| 2060 | regval |= M98095_DIGMIC_L; |
| 2061 | |
| 2062 | if (pdata->digmic_right_mode) |
| 2063 | regval |= M98095_DIGMIC_R; |
| 2064 | |
| 2065 | snd_soc_write(codec, M98095_087_CFG_MIC, regval); |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2066 | |
| 2067 | /* Configure equalizers */ |
| 2068 | if (pdata->eq_cfgcnt) |
| 2069 | max98095_handle_eq_pdata(codec); |
| 2070 | |
| 2071 | /* Configure bi-quad filters */ |
| 2072 | if (pdata->bq_cfgcnt) |
| 2073 | max98095_handle_bq_pdata(codec); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2076 | static irqreturn_t max98095_report_jack(int irq, void *data) |
| 2077 | { |
| 2078 | struct snd_soc_codec *codec = data; |
| 2079 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2080 | unsigned int value; |
| 2081 | int hp_report = 0; |
| 2082 | int mic_report = 0; |
| 2083 | |
| 2084 | /* Read the Jack Status Register */ |
| 2085 | value = snd_soc_read(codec, M98095_007_JACK_AUTO_STS); |
| 2086 | |
| 2087 | /* If ddone is not set, then detection isn't finished yet */ |
| 2088 | if ((value & M98095_DDONE) == 0) |
| 2089 | return IRQ_NONE; |
| 2090 | |
| 2091 | /* if hp, check its bit, and if set, clear it */ |
| 2092 | if ((value & M98095_HP_IN || value & M98095_LO_IN) && |
| 2093 | max98095->headphone_jack) |
| 2094 | hp_report |= SND_JACK_HEADPHONE; |
| 2095 | |
| 2096 | /* if mic, check its bit, and if set, clear it */ |
| 2097 | if ((value & M98095_MIC_IN) && max98095->mic_jack) |
| 2098 | mic_report |= SND_JACK_MICROPHONE; |
| 2099 | |
| 2100 | if (max98095->headphone_jack == max98095->mic_jack) { |
| 2101 | snd_soc_jack_report(max98095->headphone_jack, |
| 2102 | hp_report | mic_report, |
| 2103 | SND_JACK_HEADSET); |
| 2104 | } else { |
| 2105 | if (max98095->headphone_jack) |
| 2106 | snd_soc_jack_report(max98095->headphone_jack, |
| 2107 | hp_report, SND_JACK_HEADPHONE); |
| 2108 | if (max98095->mic_jack) |
| 2109 | snd_soc_jack_report(max98095->mic_jack, |
| 2110 | mic_report, SND_JACK_MICROPHONE); |
| 2111 | } |
| 2112 | |
| 2113 | return IRQ_HANDLED; |
| 2114 | } |
| 2115 | |
Mark Brown | a265367 | 2012-05-31 14:47:46 +0100 | [diff] [blame] | 2116 | static int max98095_jack_detect_enable(struct snd_soc_codec *codec) |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2117 | { |
| 2118 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2119 | int ret = 0; |
| 2120 | int detect_enable = M98095_JDEN; |
| 2121 | unsigned int slew = M98095_DEFAULT_SLEW_DELAY; |
| 2122 | |
| 2123 | if (max98095->pdata->jack_detect_pin5en) |
| 2124 | detect_enable |= M98095_PIN5EN; |
| 2125 | |
Mark Brown | 0841b04 | 2012-04-02 14:53:13 +0100 | [diff] [blame] | 2126 | if (max98095->pdata->jack_detect_delay) |
| 2127 | slew = max98095->pdata->jack_detect_delay; |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2128 | |
| 2129 | ret = snd_soc_write(codec, M98095_08E_JACK_DC_SLEW, slew); |
| 2130 | if (ret < 0) { |
| 2131 | dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret); |
| 2132 | return ret; |
| 2133 | } |
| 2134 | |
| 2135 | /* configure auto detection to be enabled */ |
| 2136 | ret = snd_soc_write(codec, M98095_089_JACK_DET_AUTO, detect_enable); |
| 2137 | if (ret < 0) { |
| 2138 | dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret); |
| 2139 | return ret; |
| 2140 | } |
| 2141 | |
| 2142 | return ret; |
| 2143 | } |
| 2144 | |
Mark Brown | a265367 | 2012-05-31 14:47:46 +0100 | [diff] [blame] | 2145 | static int max98095_jack_detect_disable(struct snd_soc_codec *codec) |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2146 | { |
| 2147 | int ret = 0; |
| 2148 | |
| 2149 | /* configure auto detection to be disabled */ |
| 2150 | ret = snd_soc_write(codec, M98095_089_JACK_DET_AUTO, 0x0); |
| 2151 | if (ret < 0) { |
| 2152 | dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret); |
| 2153 | return ret; |
| 2154 | } |
| 2155 | |
| 2156 | return ret; |
| 2157 | } |
| 2158 | |
| 2159 | int max98095_jack_detect(struct snd_soc_codec *codec, |
| 2160 | struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack) |
| 2161 | { |
| 2162 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2163 | struct i2c_client *client = to_i2c_client(codec->dev); |
| 2164 | int ret = 0; |
| 2165 | |
| 2166 | max98095->headphone_jack = hp_jack; |
| 2167 | max98095->mic_jack = mic_jack; |
| 2168 | |
| 2169 | /* only progress if we have at least 1 jack pointer */ |
| 2170 | if (!hp_jack && !mic_jack) |
| 2171 | return -EINVAL; |
| 2172 | |
| 2173 | max98095_jack_detect_enable(codec); |
| 2174 | |
| 2175 | /* enable interrupts for headphone jack detection */ |
| 2176 | ret = snd_soc_update_bits(codec, M98095_013_JACK_INT_EN, |
| 2177 | M98095_IDDONE, M98095_IDDONE); |
| 2178 | if (ret < 0) { |
| 2179 | dev_err(codec->dev, "Failed to cfg jack irqs %d\n", ret); |
| 2180 | return ret; |
| 2181 | } |
| 2182 | |
| 2183 | max98095_report_jack(client->irq, codec); |
| 2184 | return 0; |
| 2185 | } |
Mark Brown | a265367 | 2012-05-31 14:47:46 +0100 | [diff] [blame] | 2186 | EXPORT_SYMBOL_GPL(max98095_jack_detect); |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2187 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2188 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 2189 | static int max98095_suspend(struct snd_soc_codec *codec) |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2190 | { |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2191 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2192 | |
| 2193 | if (max98095->headphone_jack || max98095->mic_jack) |
| 2194 | max98095_jack_detect_disable(codec); |
| 2195 | |
Lars-Peter Clausen | bd1204c | 2015-04-27 22:13:24 +0200 | [diff] [blame] | 2196 | snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2197 | |
| 2198 | return 0; |
| 2199 | } |
| 2200 | |
| 2201 | static int max98095_resume(struct snd_soc_codec *codec) |
| 2202 | { |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2203 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2204 | struct i2c_client *client = to_i2c_client(codec->dev); |
| 2205 | |
Lars-Peter Clausen | bd1204c | 2015-04-27 22:13:24 +0200 | [diff] [blame] | 2206 | snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2207 | |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2208 | if (max98095->headphone_jack || max98095->mic_jack) { |
| 2209 | max98095_jack_detect_enable(codec); |
| 2210 | max98095_report_jack(client->irq, codec); |
| 2211 | } |
| 2212 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2213 | return 0; |
| 2214 | } |
| 2215 | #else |
| 2216 | #define max98095_suspend NULL |
| 2217 | #define max98095_resume NULL |
| 2218 | #endif |
| 2219 | |
| 2220 | static int max98095_reset(struct snd_soc_codec *codec) |
| 2221 | { |
| 2222 | int i, ret; |
| 2223 | |
| 2224 | /* Gracefully reset the DSP core and the codec hardware |
| 2225 | * in a proper sequence */ |
| 2226 | ret = snd_soc_write(codec, M98095_00F_HOST_CFG, 0); |
| 2227 | if (ret < 0) { |
| 2228 | dev_err(codec->dev, "Failed to reset DSP: %d\n", ret); |
| 2229 | return ret; |
| 2230 | } |
| 2231 | |
| 2232 | ret = snd_soc_write(codec, M98095_097_PWR_SYS, 0); |
| 2233 | if (ret < 0) { |
| 2234 | dev_err(codec->dev, "Failed to reset codec: %d\n", ret); |
| 2235 | return ret; |
| 2236 | } |
| 2237 | |
| 2238 | /* Reset to hardware default for registers, as there is not |
| 2239 | * a soft reset hardware control register */ |
| 2240 | for (i = M98095_010_HOST_INT_CFG; i < M98095_REG_MAX_CACHED; i++) { |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 2241 | ret = snd_soc_write(codec, i, snd_soc_read(codec, i)); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2242 | if (ret < 0) { |
| 2243 | dev_err(codec->dev, "Failed to reset: %d\n", ret); |
| 2244 | return ret; |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | return ret; |
| 2249 | } |
| 2250 | |
| 2251 | static int max98095_probe(struct snd_soc_codec *codec) |
| 2252 | { |
| 2253 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2254 | struct max98095_cdata *cdata; |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2255 | struct i2c_client *client; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2256 | int ret = 0; |
| 2257 | |
Tushar Behera | e3048c3 | 2014-05-26 13:58:22 +0530 | [diff] [blame] | 2258 | max98095->mclk = devm_clk_get(codec->dev, "mclk"); |
| 2259 | if (PTR_ERR(max98095->mclk) == -EPROBE_DEFER) |
| 2260 | return -EPROBE_DEFER; |
| 2261 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2262 | /* reset the codec, the DSP core, and disable all interrupts */ |
| 2263 | max98095_reset(codec); |
| 2264 | |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2265 | client = to_i2c_client(codec->dev); |
| 2266 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2267 | /* initialize private data */ |
| 2268 | |
| 2269 | max98095->sysclk = (unsigned)-1; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2270 | max98095->eq_textcnt = 0; |
| 2271 | max98095->bq_textcnt = 0; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2272 | |
| 2273 | cdata = &max98095->dai[0]; |
| 2274 | cdata->rate = (unsigned)-1; |
| 2275 | cdata->fmt = (unsigned)-1; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2276 | cdata->eq_sel = 0; |
| 2277 | cdata->bq_sel = 0; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2278 | |
| 2279 | cdata = &max98095->dai[1]; |
| 2280 | cdata->rate = (unsigned)-1; |
| 2281 | cdata->fmt = (unsigned)-1; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2282 | cdata->eq_sel = 0; |
| 2283 | cdata->bq_sel = 0; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2284 | |
| 2285 | cdata = &max98095->dai[2]; |
| 2286 | cdata->rate = (unsigned)-1; |
| 2287 | cdata->fmt = (unsigned)-1; |
Peter Hsiang | dad31ec | 2011-04-19 18:20:40 -0700 | [diff] [blame] | 2288 | cdata->eq_sel = 0; |
| 2289 | cdata->bq_sel = 0; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2290 | |
| 2291 | max98095->lin_state = 0; |
| 2292 | max98095->mic1pre = 0; |
| 2293 | max98095->mic2pre = 0; |
| 2294 | |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2295 | if (client->irq) { |
| 2296 | /* register an audio interrupt */ |
| 2297 | ret = request_threaded_irq(client->irq, NULL, |
| 2298 | max98095_report_jack, |
Fabio Estevam | 16f0acd | 2015-05-12 01:23:00 -0300 | [diff] [blame] | 2299 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | |
| 2300 | IRQF_ONESHOT, "max98095", codec); |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2301 | if (ret) { |
| 2302 | dev_err(codec->dev, "Failed to request IRQ: %d\n", ret); |
| 2303 | goto err_access; |
| 2304 | } |
| 2305 | } |
| 2306 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2307 | ret = snd_soc_read(codec, M98095_0FF_REV_ID); |
| 2308 | if (ret < 0) { |
Taylor Hutt | bab3b59 | 2011-06-20 11:54:32 -0700 | [diff] [blame] | 2309 | dev_err(codec->dev, "Failure reading hardware revision: %d\n", |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2310 | ret); |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2311 | goto err_irq; |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2312 | } |
Taylor Hutt | bab3b59 | 2011-06-20 11:54:32 -0700 | [diff] [blame] | 2313 | dev_info(codec->dev, "Hardware revision: %c\n", ret - 0x40 + 'A'); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2314 | |
| 2315 | snd_soc_write(codec, M98095_097_PWR_SYS, M98095_PWRSV); |
| 2316 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2317 | snd_soc_write(codec, M98095_048_MIX_DAC_LR, |
| 2318 | M98095_DAI1L_TO_DACL|M98095_DAI1R_TO_DACR); |
| 2319 | |
| 2320 | snd_soc_write(codec, M98095_049_MIX_DAC_M, |
| 2321 | M98095_DAI2M_TO_DACM|M98095_DAI3M_TO_DACM); |
| 2322 | |
| 2323 | snd_soc_write(codec, M98095_092_PWR_EN_OUT, M98095_SPK_SPREADSPECTRUM); |
| 2324 | snd_soc_write(codec, M98095_045_CFG_DSP, M98095_DSPNORMAL); |
| 2325 | snd_soc_write(codec, M98095_04E_CFG_HP, M98095_HPNORMAL); |
| 2326 | |
| 2327 | snd_soc_write(codec, M98095_02C_DAI1_IOCFG, |
| 2328 | M98095_S1NORMAL|M98095_SDATA); |
| 2329 | |
| 2330 | snd_soc_write(codec, M98095_036_DAI2_IOCFG, |
| 2331 | M98095_S2NORMAL|M98095_SDATA); |
| 2332 | |
| 2333 | snd_soc_write(codec, M98095_040_DAI3_IOCFG, |
| 2334 | M98095_S3NORMAL|M98095_SDATA); |
| 2335 | |
| 2336 | max98095_handle_pdata(codec); |
| 2337 | |
| 2338 | /* take the codec out of the shut down */ |
| 2339 | snd_soc_update_bits(codec, M98095_097_PWR_SYS, M98095_SHDNRUN, |
| 2340 | M98095_SHDNRUN); |
| 2341 | |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2342 | return 0; |
| 2343 | |
| 2344 | err_irq: |
| 2345 | if (client->irq) |
| 2346 | free_irq(client->irq, codec); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2347 | err_access: |
| 2348 | return ret; |
| 2349 | } |
| 2350 | |
| 2351 | static int max98095_remove(struct snd_soc_codec *codec) |
| 2352 | { |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2353 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
| 2354 | struct i2c_client *client = to_i2c_client(codec->dev); |
| 2355 | |
Rhyland Klein | 9dd90c5 | 2012-03-15 15:07:47 -0700 | [diff] [blame] | 2356 | if (max98095->headphone_jack || max98095->mic_jack) |
| 2357 | max98095_jack_detect_disable(codec); |
| 2358 | |
| 2359 | if (client->irq) |
| 2360 | free_irq(client->irq, codec); |
| 2361 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2362 | return 0; |
| 2363 | } |
| 2364 | |
| 2365 | static struct snd_soc_codec_driver soc_codec_dev_max98095 = { |
| 2366 | .probe = max98095_probe, |
| 2367 | .remove = max98095_remove, |
| 2368 | .suspend = max98095_suspend, |
| 2369 | .resume = max98095_resume, |
| 2370 | .set_bias_level = max98095_set_bias_level, |
Mark Brown | c6b3283 | 2013-09-23 19:05:16 +0100 | [diff] [blame] | 2371 | .controls = max98095_snd_controls, |
| 2372 | .num_controls = ARRAY_SIZE(max98095_snd_controls), |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2373 | .dapm_widgets = max98095_dapm_widgets, |
| 2374 | .num_dapm_widgets = ARRAY_SIZE(max98095_dapm_widgets), |
| 2375 | .dapm_routes = max98095_audio_map, |
| 2376 | .num_dapm_routes = ARRAY_SIZE(max98095_audio_map), |
| 2377 | }; |
| 2378 | |
| 2379 | static int max98095_i2c_probe(struct i2c_client *i2c, |
| 2380 | const struct i2c_device_id *id) |
| 2381 | { |
| 2382 | struct max98095_priv *max98095; |
| 2383 | int ret; |
| 2384 | |
Axel Lin | b1b5488 | 2011-12-29 12:02:21 +0800 | [diff] [blame] | 2385 | max98095 = devm_kzalloc(&i2c->dev, sizeof(struct max98095_priv), |
| 2386 | GFP_KERNEL); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2387 | if (max98095 == NULL) |
| 2388 | return -ENOMEM; |
| 2389 | |
Lars-Peter Clausen | 210a5fa | 2014-11-09 17:00:58 +0100 | [diff] [blame] | 2390 | mutex_init(&max98095->lock); |
| 2391 | |
Mark Brown | 14acbbb | 2013-09-23 19:08:35 +0100 | [diff] [blame] | 2392 | max98095->regmap = devm_regmap_init_i2c(i2c, &max98095_regmap); |
| 2393 | if (IS_ERR(max98095->regmap)) { |
| 2394 | ret = PTR_ERR(max98095->regmap); |
| 2395 | dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret); |
| 2396 | return ret; |
| 2397 | } |
| 2398 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2399 | max98095->devtype = id->driver_data; |
| 2400 | i2c_set_clientdata(i2c, max98095); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2401 | max98095->pdata = i2c->dev.platform_data; |
| 2402 | |
Taylor Hutt | bab3b59 | 2011-06-20 11:54:32 -0700 | [diff] [blame] | 2403 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98095, |
| 2404 | max98095_dai, ARRAY_SIZE(max98095_dai)); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2405 | return ret; |
| 2406 | } |
| 2407 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 2408 | static int max98095_i2c_remove(struct i2c_client *client) |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2409 | { |
| 2410 | snd_soc_unregister_codec(&client->dev); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2411 | return 0; |
| 2412 | } |
| 2413 | |
| 2414 | static const struct i2c_device_id max98095_i2c_id[] = { |
| 2415 | { "max98095", MAX98095 }, |
| 2416 | { } |
| 2417 | }; |
| 2418 | MODULE_DEVICE_TABLE(i2c, max98095_i2c_id); |
| 2419 | |
Tushar Behera | c4839c8 | 2014-04-23 14:43:58 +0530 | [diff] [blame] | 2420 | static const struct of_device_id max98095_of_match[] = { |
| 2421 | { .compatible = "maxim,max98095", }, |
| 2422 | { } |
| 2423 | }; |
| 2424 | MODULE_DEVICE_TABLE(of, max98095_of_match); |
| 2425 | |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2426 | static struct i2c_driver max98095_i2c_driver = { |
| 2427 | .driver = { |
| 2428 | .name = "max98095", |
| 2429 | .owner = THIS_MODULE, |
Tushar Behera | c4839c8 | 2014-04-23 14:43:58 +0530 | [diff] [blame] | 2430 | .of_match_table = of_match_ptr(max98095_of_match), |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2431 | }, |
| 2432 | .probe = max98095_i2c_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 2433 | .remove = max98095_i2c_remove, |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2434 | .id_table = max98095_i2c_id, |
| 2435 | }; |
| 2436 | |
Sachin Kamat | a8af02c | 2012-08-06 17:26:00 +0530 | [diff] [blame] | 2437 | module_i2c_driver(max98095_i2c_driver); |
Peter Hsiang | 82a5a93 | 2011-04-04 19:35:30 -0700 | [diff] [blame] | 2438 | |
| 2439 | MODULE_DESCRIPTION("ALSA SoC MAX98095 driver"); |
| 2440 | MODULE_AUTHOR("Peter Hsiang"); |
| 2441 | MODULE_LICENSE("GPL"); |