1d6e65bb7SShuming Fan // SPDX-License-Identifier: GPL-2.0 2d6e65bb7SShuming Fan /* 3d6e65bb7SShuming Fan * rt1011.c -- rt1011 ALSA SoC amplifier component driver 4d6e65bb7SShuming Fan * 5d6e65bb7SShuming Fan * Copyright(c) 2019 Realtek Semiconductor Corp. 6d6e65bb7SShuming Fan * 7d6e65bb7SShuming Fan * Author: Shuming Fan <shumingf@realtek.com> 8d6e65bb7SShuming Fan * 9d6e65bb7SShuming Fan */ 10d6e65bb7SShuming Fan 11d6e65bb7SShuming Fan #include <linux/module.h> 12d6e65bb7SShuming Fan #include <linux/moduleparam.h> 13d6e65bb7SShuming Fan #include <linux/init.h> 14d6e65bb7SShuming Fan #include <linux/delay.h> 15d6e65bb7SShuming Fan #include <linux/pm.h> 16d6e65bb7SShuming Fan #include <linux/gpio.h> 17d6e65bb7SShuming Fan #include <linux/i2c.h> 18d6e65bb7SShuming Fan #include <linux/acpi.h> 19d6e65bb7SShuming Fan #include <linux/regmap.h> 20d6e65bb7SShuming Fan #include <linux/of_gpio.h> 21d6e65bb7SShuming Fan #include <linux/platform_device.h> 22d6e65bb7SShuming Fan #include <linux/firmware.h> 23d6e65bb7SShuming Fan #include <sound/core.h> 24d6e65bb7SShuming Fan #include <sound/pcm.h> 25d6e65bb7SShuming Fan #include <sound/pcm_params.h> 26d6e65bb7SShuming Fan #include <sound/soc.h> 27d6e65bb7SShuming Fan #include <sound/soc-dapm.h> 28d6e65bb7SShuming Fan #include <sound/initval.h> 29d6e65bb7SShuming Fan #include <sound/tlv.h> 30d6e65bb7SShuming Fan 31d6e65bb7SShuming Fan #include "rl6231.h" 32d6e65bb7SShuming Fan #include "rt1011.h" 33d6e65bb7SShuming Fan 34d6e65bb7SShuming Fan static int rt1011_calibrate(struct rt1011_priv *rt1011, 35d6e65bb7SShuming Fan unsigned char cali_flag); 36d6e65bb7SShuming Fan 37d6e65bb7SShuming Fan static const struct reg_sequence init_list[] = { 38d6e65bb7SShuming Fan 39d6e65bb7SShuming Fan { RT1011_POWER_9, 0xa840 }, 40d6e65bb7SShuming Fan 41d6e65bb7SShuming Fan { RT1011_ADC_SET_5, 0x0a20 }, 4209297c2fSShuming Fan { RT1011_DAC_SET_2, 0xa032 }, 43d6e65bb7SShuming Fan 44d6e65bb7SShuming Fan { RT1011_SPK_PRO_DC_DET_1, 0xb00c }, 45d6e65bb7SShuming Fan { RT1011_SPK_PRO_DC_DET_2, 0xcccc }, 46d6e65bb7SShuming Fan 47d6e65bb7SShuming Fan { RT1011_A_TIMING_1, 0x6054 }, 48d6e65bb7SShuming Fan 49d6e65bb7SShuming Fan { RT1011_POWER_7, 0x3e55 }, 50d6e65bb7SShuming Fan { RT1011_POWER_8, 0x0520 }, 51d6e65bb7SShuming Fan { RT1011_BOOST_CON_1, 0xe188 }, 52d6e65bb7SShuming Fan { RT1011_POWER_4, 0x16f2 }, 53d6e65bb7SShuming Fan 54d6e65bb7SShuming Fan { RT1011_CROSS_BQ_SET_1, 0x0004 }, 55d6e65bb7SShuming Fan { RT1011_SIL_DET, 0xc313 }, 56d6e65bb7SShuming Fan { RT1011_SINE_GEN_REG_1, 0x0707 }, 57d6e65bb7SShuming Fan 58d6e65bb7SShuming Fan { RT1011_DC_CALIB_CLASSD_3, 0xcb00 }, 59d6e65bb7SShuming Fan 60d6e65bb7SShuming Fan { RT1011_DAC_SET_1, 0xe702 }, 61d6e65bb7SShuming Fan { RT1011_DAC_SET_3, 0x2004 }, 62d6e65bb7SShuming Fan }; 63d6e65bb7SShuming Fan 64d6e65bb7SShuming Fan static const struct reg_default rt1011_reg[] = { 65d6e65bb7SShuming Fan {0x0000, 0x0000}, 66d6e65bb7SShuming Fan {0x0002, 0x0000}, 67d6e65bb7SShuming Fan {0x0004, 0xa000}, 68d6e65bb7SShuming Fan {0x0006, 0x0000}, 69d6e65bb7SShuming Fan {0x0008, 0x0003}, 70d6e65bb7SShuming Fan {0x000a, 0x087e}, 71d6e65bb7SShuming Fan {0x000c, 0x0020}, 72d6e65bb7SShuming Fan {0x000e, 0x9002}, 73d6e65bb7SShuming Fan {0x0010, 0x0000}, 74d6e65bb7SShuming Fan {0x0012, 0x0000}, 75d6e65bb7SShuming Fan {0x0020, 0x0c40}, 76d6e65bb7SShuming Fan {0x0022, 0x4313}, 77d6e65bb7SShuming Fan {0x0076, 0x0000}, 78d6e65bb7SShuming Fan {0x0078, 0x0000}, 79d6e65bb7SShuming Fan {0x007a, 0x0000}, 80d6e65bb7SShuming Fan {0x007c, 0x10ec}, 81d6e65bb7SShuming Fan {0x007d, 0x1011}, 82d6e65bb7SShuming Fan {0x00f0, 0x5000}, 83d6e65bb7SShuming Fan {0x00f2, 0x0374}, 84d6e65bb7SShuming Fan {0x00f3, 0x0000}, 85d6e65bb7SShuming Fan {0x00f4, 0x0000}, 86d6e65bb7SShuming Fan {0x0100, 0x0038}, 87d6e65bb7SShuming Fan {0x0102, 0xff02}, 88d6e65bb7SShuming Fan {0x0104, 0x0232}, 89d6e65bb7SShuming Fan {0x0106, 0x200c}, 90d6e65bb7SShuming Fan {0x0107, 0x0000}, 91d6e65bb7SShuming Fan {0x0108, 0x2f2f}, 92d6e65bb7SShuming Fan {0x010a, 0x2f2f}, 93d6e65bb7SShuming Fan {0x010c, 0x002f}, 94d6e65bb7SShuming Fan {0x010e, 0xe000}, 95d6e65bb7SShuming Fan {0x0110, 0x0820}, 96d6e65bb7SShuming Fan {0x0111, 0x4010}, 97d6e65bb7SShuming Fan {0x0112, 0x0000}, 98d6e65bb7SShuming Fan {0x0114, 0x0000}, 99d6e65bb7SShuming Fan {0x0116, 0x0000}, 100d6e65bb7SShuming Fan {0x0118, 0x0000}, 101d6e65bb7SShuming Fan {0x011a, 0x0101}, 102d6e65bb7SShuming Fan {0x011c, 0x4567}, 103d6e65bb7SShuming Fan {0x011e, 0x0000}, 104d6e65bb7SShuming Fan {0x0120, 0x0000}, 105d6e65bb7SShuming Fan {0x0122, 0x0000}, 106d6e65bb7SShuming Fan {0x0124, 0x0123}, 107d6e65bb7SShuming Fan {0x0126, 0x4567}, 108d6e65bb7SShuming Fan {0x0200, 0x0000}, 109d6e65bb7SShuming Fan {0x0300, 0xffdd}, 110d6e65bb7SShuming Fan {0x0302, 0x001e}, 111d6e65bb7SShuming Fan {0x0311, 0x0000}, 112d6e65bb7SShuming Fan {0x0313, 0x5254}, 113d6e65bb7SShuming Fan {0x0314, 0x0062}, 114d6e65bb7SShuming Fan {0x0316, 0x7f40}, 115d6e65bb7SShuming Fan {0x0319, 0x000f}, 116d6e65bb7SShuming Fan {0x031a, 0xffff}, 117d6e65bb7SShuming Fan {0x031b, 0x0000}, 118d6e65bb7SShuming Fan {0x031c, 0x009f}, 119d6e65bb7SShuming Fan {0x031d, 0xffff}, 120d6e65bb7SShuming Fan {0x031e, 0x0000}, 121d6e65bb7SShuming Fan {0x031f, 0x0000}, 122d6e65bb7SShuming Fan {0x0320, 0xe31c}, 123d6e65bb7SShuming Fan {0x0321, 0x0000}, 124d6e65bb7SShuming Fan {0x0322, 0x0000}, 125d6e65bb7SShuming Fan {0x0324, 0x0000}, 126d6e65bb7SShuming Fan {0x0326, 0x0002}, 127d6e65bb7SShuming Fan {0x0328, 0x20b2}, 128d6e65bb7SShuming Fan {0x0329, 0x0175}, 129d6e65bb7SShuming Fan {0x032a, 0x32ad}, 130d6e65bb7SShuming Fan {0x032b, 0x3455}, 131d6e65bb7SShuming Fan {0x032c, 0x0528}, 132d6e65bb7SShuming Fan {0x032d, 0xa800}, 133d6e65bb7SShuming Fan {0x032e, 0x030e}, 134d6e65bb7SShuming Fan {0x0330, 0x2080}, 135d6e65bb7SShuming Fan {0x0332, 0x0034}, 136d6e65bb7SShuming Fan {0x0334, 0x0000}, 137d6e65bb7SShuming Fan {0x0508, 0x0010}, 138d6e65bb7SShuming Fan {0x050a, 0x0018}, 139d6e65bb7SShuming Fan {0x050c, 0x0000}, 140d6e65bb7SShuming Fan {0x050d, 0xffff}, 141d6e65bb7SShuming Fan {0x050e, 0x1f1f}, 142d6e65bb7SShuming Fan {0x050f, 0x04ff}, 143d6e65bb7SShuming Fan {0x0510, 0x4020}, 144d6e65bb7SShuming Fan {0x0511, 0x01f0}, 145d6e65bb7SShuming Fan {0x0512, 0x0702}, 146d6e65bb7SShuming Fan {0x0516, 0xbb80}, 147d6e65bb7SShuming Fan {0x0517, 0xffff}, 148d6e65bb7SShuming Fan {0x0518, 0xffff}, 149d6e65bb7SShuming Fan {0x0519, 0x307f}, 150d6e65bb7SShuming Fan {0x051a, 0xffff}, 151d6e65bb7SShuming Fan {0x051b, 0x0000}, 152d6e65bb7SShuming Fan {0x051c, 0x0000}, 153d6e65bb7SShuming Fan {0x051d, 0x2000}, 154d6e65bb7SShuming Fan {0x051e, 0x0000}, 155d6e65bb7SShuming Fan {0x051f, 0x0000}, 156d6e65bb7SShuming Fan {0x0520, 0x0000}, 157d6e65bb7SShuming Fan {0x0521, 0x1001}, 158d6e65bb7SShuming Fan {0x0522, 0x7fff}, 159d6e65bb7SShuming Fan {0x0524, 0x7fff}, 160d6e65bb7SShuming Fan {0x0526, 0x0000}, 161d6e65bb7SShuming Fan {0x0528, 0x0000}, 162d6e65bb7SShuming Fan {0x052a, 0x0000}, 163d6e65bb7SShuming Fan {0x0530, 0x0401}, 164d6e65bb7SShuming Fan {0x0532, 0x3000}, 165d6e65bb7SShuming Fan {0x0534, 0x0000}, 166d6e65bb7SShuming Fan {0x0535, 0xffff}, 167d6e65bb7SShuming Fan {0x0536, 0x101c}, 168d6e65bb7SShuming Fan {0x0538, 0x1814}, 169d6e65bb7SShuming Fan {0x053a, 0x100c}, 170d6e65bb7SShuming Fan {0x053c, 0x0804}, 171d6e65bb7SShuming Fan {0x053d, 0x0000}, 172d6e65bb7SShuming Fan {0x053e, 0x0000}, 173d6e65bb7SShuming Fan {0x053f, 0x0000}, 174d6e65bb7SShuming Fan {0x0540, 0x0000}, 175d6e65bb7SShuming Fan {0x0541, 0x0000}, 176d6e65bb7SShuming Fan {0x0542, 0x0000}, 177d6e65bb7SShuming Fan {0x0543, 0x0000}, 178d6e65bb7SShuming Fan {0x0544, 0x001c}, 179d6e65bb7SShuming Fan {0x0545, 0x1814}, 180d6e65bb7SShuming Fan {0x0546, 0x100c}, 181d6e65bb7SShuming Fan {0x0547, 0x0804}, 182d6e65bb7SShuming Fan {0x0548, 0x0000}, 183d6e65bb7SShuming Fan {0x0549, 0x0000}, 184d6e65bb7SShuming Fan {0x054a, 0x0000}, 185d6e65bb7SShuming Fan {0x054b, 0x0000}, 186d6e65bb7SShuming Fan {0x054c, 0x0000}, 187d6e65bb7SShuming Fan {0x054d, 0x0000}, 188d6e65bb7SShuming Fan {0x054e, 0x0000}, 189d6e65bb7SShuming Fan {0x054f, 0x0000}, 190d6e65bb7SShuming Fan {0x0566, 0x0000}, 191d6e65bb7SShuming Fan {0x0568, 0x20f1}, 192d6e65bb7SShuming Fan {0x056a, 0x0007}, 193d6e65bb7SShuming Fan {0x0600, 0x9d00}, 194d6e65bb7SShuming Fan {0x0611, 0x2000}, 195d6e65bb7SShuming Fan {0x0612, 0x505f}, 196d6e65bb7SShuming Fan {0x0613, 0x0444}, 197d6e65bb7SShuming Fan {0x0614, 0x4000}, 198d6e65bb7SShuming Fan {0x0615, 0x4004}, 199d6e65bb7SShuming Fan {0x0616, 0x0606}, 200d6e65bb7SShuming Fan {0x0617, 0x8904}, 201d6e65bb7SShuming Fan {0x0618, 0xe021}, 202d6e65bb7SShuming Fan {0x0621, 0x2000}, 203d6e65bb7SShuming Fan {0x0622, 0x505f}, 204d6e65bb7SShuming Fan {0x0623, 0x0444}, 205d6e65bb7SShuming Fan {0x0624, 0x4000}, 206d6e65bb7SShuming Fan {0x0625, 0x4004}, 207d6e65bb7SShuming Fan {0x0626, 0x0606}, 208d6e65bb7SShuming Fan {0x0627, 0x8704}, 209d6e65bb7SShuming Fan {0x0628, 0xe021}, 210d6e65bb7SShuming Fan {0x0631, 0x2000}, 211d6e65bb7SShuming Fan {0x0632, 0x517f}, 212d6e65bb7SShuming Fan {0x0633, 0x0440}, 213d6e65bb7SShuming Fan {0x0634, 0x4000}, 214d6e65bb7SShuming Fan {0x0635, 0x4104}, 215d6e65bb7SShuming Fan {0x0636, 0x0306}, 216d6e65bb7SShuming Fan {0x0637, 0x8904}, 217d6e65bb7SShuming Fan {0x0638, 0xe021}, 218d6e65bb7SShuming Fan {0x0702, 0x0014}, 219d6e65bb7SShuming Fan {0x0704, 0x0000}, 220d6e65bb7SShuming Fan {0x0706, 0x0014}, 221d6e65bb7SShuming Fan {0x0708, 0x0000}, 222d6e65bb7SShuming Fan {0x070a, 0x0000}, 223d6e65bb7SShuming Fan {0x0710, 0x0200}, 224d6e65bb7SShuming Fan {0x0711, 0x0000}, 225d6e65bb7SShuming Fan {0x0712, 0x0200}, 226d6e65bb7SShuming Fan {0x0713, 0x0000}, 227d6e65bb7SShuming Fan {0x0720, 0x0200}, 228d6e65bb7SShuming Fan {0x0721, 0x0000}, 229d6e65bb7SShuming Fan {0x0722, 0x0000}, 230d6e65bb7SShuming Fan {0x0723, 0x0000}, 231d6e65bb7SShuming Fan {0x0724, 0x0000}, 232d6e65bb7SShuming Fan {0x0725, 0x0000}, 233d6e65bb7SShuming Fan {0x0726, 0x0000}, 234d6e65bb7SShuming Fan {0x0727, 0x0000}, 235d6e65bb7SShuming Fan {0x0728, 0x0000}, 236d6e65bb7SShuming Fan {0x0729, 0x0000}, 237d6e65bb7SShuming Fan {0x0730, 0x0200}, 238d6e65bb7SShuming Fan {0x0731, 0x0000}, 239d6e65bb7SShuming Fan {0x0732, 0x0000}, 240d6e65bb7SShuming Fan {0x0733, 0x0000}, 241d6e65bb7SShuming Fan {0x0734, 0x0000}, 242d6e65bb7SShuming Fan {0x0735, 0x0000}, 243d6e65bb7SShuming Fan {0x0736, 0x0000}, 244d6e65bb7SShuming Fan {0x0737, 0x0000}, 245d6e65bb7SShuming Fan {0x0738, 0x0000}, 246d6e65bb7SShuming Fan {0x0739, 0x0000}, 247d6e65bb7SShuming Fan {0x0740, 0x0200}, 248d6e65bb7SShuming Fan {0x0741, 0x0000}, 249d6e65bb7SShuming Fan {0x0742, 0x0000}, 250d6e65bb7SShuming Fan {0x0743, 0x0000}, 251d6e65bb7SShuming Fan {0x0744, 0x0000}, 252d6e65bb7SShuming Fan {0x0745, 0x0000}, 253d6e65bb7SShuming Fan {0x0746, 0x0000}, 254d6e65bb7SShuming Fan {0x0747, 0x0000}, 255d6e65bb7SShuming Fan {0x0748, 0x0000}, 256d6e65bb7SShuming Fan {0x0749, 0x0000}, 257d6e65bb7SShuming Fan {0x0750, 0x0200}, 258d6e65bb7SShuming Fan {0x0751, 0x0000}, 259d6e65bb7SShuming Fan {0x0752, 0x0000}, 260d6e65bb7SShuming Fan {0x0753, 0x0000}, 261d6e65bb7SShuming Fan {0x0754, 0x0000}, 262d6e65bb7SShuming Fan {0x0755, 0x0000}, 263d6e65bb7SShuming Fan {0x0756, 0x0000}, 264d6e65bb7SShuming Fan {0x0757, 0x0000}, 265d6e65bb7SShuming Fan {0x0758, 0x0000}, 266d6e65bb7SShuming Fan {0x0759, 0x0000}, 267d6e65bb7SShuming Fan {0x0760, 0x0200}, 268d6e65bb7SShuming Fan {0x0761, 0x0000}, 269d6e65bb7SShuming Fan {0x0762, 0x0000}, 270d6e65bb7SShuming Fan {0x0763, 0x0000}, 271d6e65bb7SShuming Fan {0x0764, 0x0000}, 272d6e65bb7SShuming Fan {0x0765, 0x0000}, 273d6e65bb7SShuming Fan {0x0766, 0x0000}, 274d6e65bb7SShuming Fan {0x0767, 0x0000}, 275d6e65bb7SShuming Fan {0x0768, 0x0000}, 276d6e65bb7SShuming Fan {0x0769, 0x0000}, 277d6e65bb7SShuming Fan {0x0770, 0x0200}, 278d6e65bb7SShuming Fan {0x0771, 0x0000}, 279d6e65bb7SShuming Fan {0x0772, 0x0000}, 280d6e65bb7SShuming Fan {0x0773, 0x0000}, 281d6e65bb7SShuming Fan {0x0774, 0x0000}, 282d6e65bb7SShuming Fan {0x0775, 0x0000}, 283d6e65bb7SShuming Fan {0x0776, 0x0000}, 284d6e65bb7SShuming Fan {0x0777, 0x0000}, 285d6e65bb7SShuming Fan {0x0778, 0x0000}, 286d6e65bb7SShuming Fan {0x0779, 0x0000}, 287d6e65bb7SShuming Fan {0x0780, 0x0200}, 288d6e65bb7SShuming Fan {0x0781, 0x0000}, 289d6e65bb7SShuming Fan {0x0782, 0x0000}, 290d6e65bb7SShuming Fan {0x0783, 0x0000}, 291d6e65bb7SShuming Fan {0x0784, 0x0000}, 292d6e65bb7SShuming Fan {0x0785, 0x0000}, 293d6e65bb7SShuming Fan {0x0786, 0x0000}, 294d6e65bb7SShuming Fan {0x0787, 0x0000}, 295d6e65bb7SShuming Fan {0x0788, 0x0000}, 296d6e65bb7SShuming Fan {0x0789, 0x0000}, 297d6e65bb7SShuming Fan {0x0790, 0x0200}, 298d6e65bb7SShuming Fan {0x0791, 0x0000}, 299d6e65bb7SShuming Fan {0x0792, 0x0000}, 300d6e65bb7SShuming Fan {0x0793, 0x0000}, 301d6e65bb7SShuming Fan {0x0794, 0x0000}, 302d6e65bb7SShuming Fan {0x0795, 0x0000}, 303d6e65bb7SShuming Fan {0x0796, 0x0000}, 304d6e65bb7SShuming Fan {0x0797, 0x0000}, 305d6e65bb7SShuming Fan {0x0798, 0x0000}, 306d6e65bb7SShuming Fan {0x0799, 0x0000}, 307d6e65bb7SShuming Fan {0x07a0, 0x0200}, 308d6e65bb7SShuming Fan {0x07a1, 0x0000}, 309d6e65bb7SShuming Fan {0x07a2, 0x0000}, 310d6e65bb7SShuming Fan {0x07a3, 0x0000}, 311d6e65bb7SShuming Fan {0x07a4, 0x0000}, 312d6e65bb7SShuming Fan {0x07a5, 0x0000}, 313d6e65bb7SShuming Fan {0x07a6, 0x0000}, 314d6e65bb7SShuming Fan {0x07a7, 0x0000}, 315d6e65bb7SShuming Fan {0x07a8, 0x0000}, 316d6e65bb7SShuming Fan {0x07a9, 0x0000}, 317d6e65bb7SShuming Fan {0x07b0, 0x0200}, 318d6e65bb7SShuming Fan {0x07b1, 0x0000}, 319d6e65bb7SShuming Fan {0x07b2, 0x0000}, 320d6e65bb7SShuming Fan {0x07b3, 0x0000}, 321d6e65bb7SShuming Fan {0x07b4, 0x0000}, 322d6e65bb7SShuming Fan {0x07b5, 0x0000}, 323d6e65bb7SShuming Fan {0x07b6, 0x0000}, 324d6e65bb7SShuming Fan {0x07b7, 0x0000}, 325d6e65bb7SShuming Fan {0x07b8, 0x0000}, 326d6e65bb7SShuming Fan {0x07b9, 0x0000}, 327d6e65bb7SShuming Fan {0x07c0, 0x0200}, 328d6e65bb7SShuming Fan {0x07c1, 0x0000}, 329d6e65bb7SShuming Fan {0x07c2, 0x0000}, 330d6e65bb7SShuming Fan {0x07c3, 0x0000}, 331d6e65bb7SShuming Fan {0x07c4, 0x0000}, 332d6e65bb7SShuming Fan {0x07c5, 0x0000}, 333d6e65bb7SShuming Fan {0x07c6, 0x0000}, 334d6e65bb7SShuming Fan {0x07c7, 0x0000}, 335d6e65bb7SShuming Fan {0x07c8, 0x0000}, 336d6e65bb7SShuming Fan {0x07c9, 0x0000}, 337d6e65bb7SShuming Fan {0x1000, 0x4040}, 338d6e65bb7SShuming Fan {0x1002, 0x6505}, 339d6e65bb7SShuming Fan {0x1004, 0x5405}, 340d6e65bb7SShuming Fan {0x1006, 0x5555}, 341d6e65bb7SShuming Fan {0x1007, 0x003f}, 342d6e65bb7SShuming Fan {0x1008, 0x7fd7}, 343d6e65bb7SShuming Fan {0x1009, 0x770f}, 344d6e65bb7SShuming Fan {0x100a, 0xfffe}, 345d6e65bb7SShuming Fan {0x100b, 0xe000}, 346d6e65bb7SShuming Fan {0x100c, 0x0000}, 347d6e65bb7SShuming Fan {0x100d, 0x0007}, 348d6e65bb7SShuming Fan {0x1010, 0xa433}, 349d6e65bb7SShuming Fan {0x1020, 0x0000}, 350d6e65bb7SShuming Fan {0x1022, 0x0000}, 351d6e65bb7SShuming Fan {0x1024, 0x0000}, 352d6e65bb7SShuming Fan {0x1200, 0x5a01}, 353d6e65bb7SShuming Fan {0x1202, 0x6324}, 354d6e65bb7SShuming Fan {0x1204, 0x0b00}, 355d6e65bb7SShuming Fan {0x1206, 0x0000}, 356d6e65bb7SShuming Fan {0x1208, 0x0000}, 357d6e65bb7SShuming Fan {0x120a, 0x0024}, 358d6e65bb7SShuming Fan {0x120c, 0x0000}, 359d6e65bb7SShuming Fan {0x120e, 0x000e}, 360d6e65bb7SShuming Fan {0x1210, 0x0000}, 361d6e65bb7SShuming Fan {0x1212, 0x0000}, 362d6e65bb7SShuming Fan {0x1300, 0x0701}, 363d6e65bb7SShuming Fan {0x1302, 0x12f9}, 364d6e65bb7SShuming Fan {0x1304, 0x3405}, 365d6e65bb7SShuming Fan {0x1305, 0x0844}, 366d6e65bb7SShuming Fan {0x1306, 0x5611}, 367d6e65bb7SShuming Fan {0x1308, 0x555e}, 368d6e65bb7SShuming Fan {0x130a, 0xa605}, 369d6e65bb7SShuming Fan {0x130c, 0x2000}, 370d6e65bb7SShuming Fan {0x130e, 0x0000}, 371d6e65bb7SShuming Fan {0x130f, 0x0001}, 372d6e65bb7SShuming Fan {0x1310, 0xaa48}, 373d6e65bb7SShuming Fan {0x1312, 0x0285}, 374d6e65bb7SShuming Fan {0x1314, 0xaaaa}, 375d6e65bb7SShuming Fan {0x1316, 0xaaa0}, 376d6e65bb7SShuming Fan {0x1318, 0x2aaa}, 377d6e65bb7SShuming Fan {0x131a, 0xaa07}, 378d6e65bb7SShuming Fan {0x1322, 0x0029}, 379d6e65bb7SShuming Fan {0x1323, 0x4a52}, 380d6e65bb7SShuming Fan {0x1324, 0x002c}, 381d6e65bb7SShuming Fan {0x1325, 0x0b02}, 382d6e65bb7SShuming Fan {0x1326, 0x002d}, 383d6e65bb7SShuming Fan {0x1327, 0x6b5a}, 384d6e65bb7SShuming Fan {0x1328, 0x002e}, 385d6e65bb7SShuming Fan {0x1329, 0xcbb2}, 386d6e65bb7SShuming Fan {0x132a, 0x0030}, 387d6e65bb7SShuming Fan {0x132b, 0x2c0b}, 388d6e65bb7SShuming Fan {0x1330, 0x0031}, 389d6e65bb7SShuming Fan {0x1331, 0x8c63}, 390d6e65bb7SShuming Fan {0x1332, 0x0032}, 391d6e65bb7SShuming Fan {0x1333, 0xecbb}, 392d6e65bb7SShuming Fan {0x1334, 0x0034}, 393d6e65bb7SShuming Fan {0x1335, 0x4d13}, 394d6e65bb7SShuming Fan {0x1336, 0x0037}, 395d6e65bb7SShuming Fan {0x1337, 0x0dc3}, 396d6e65bb7SShuming Fan {0x1338, 0x003d}, 397d6e65bb7SShuming Fan {0x1339, 0xef7b}, 398d6e65bb7SShuming Fan {0x133a, 0x0044}, 399d6e65bb7SShuming Fan {0x133b, 0xd134}, 400d6e65bb7SShuming Fan {0x133c, 0x0047}, 401d6e65bb7SShuming Fan {0x133d, 0x91e4}, 402d6e65bb7SShuming Fan {0x133e, 0x004d}, 403d6e65bb7SShuming Fan {0x133f, 0xc370}, 404d6e65bb7SShuming Fan {0x1340, 0x0053}, 405d6e65bb7SShuming Fan {0x1341, 0xf4fd}, 406d6e65bb7SShuming Fan {0x1342, 0x0060}, 407d6e65bb7SShuming Fan {0x1343, 0x5816}, 408d6e65bb7SShuming Fan {0x1344, 0x006c}, 409d6e65bb7SShuming Fan {0x1345, 0xbb2e}, 410d6e65bb7SShuming Fan {0x1346, 0x0072}, 411d6e65bb7SShuming Fan {0x1347, 0xecbb}, 412d6e65bb7SShuming Fan {0x1348, 0x0076}, 413d6e65bb7SShuming Fan {0x1349, 0x5d97}, 414d6e65bb7SShuming Fan {0x1500, 0x0702}, 415d6e65bb7SShuming Fan {0x1502, 0x002f}, 416d6e65bb7SShuming Fan {0x1504, 0x0000}, 417d6e65bb7SShuming Fan {0x1510, 0x0064}, 418d6e65bb7SShuming Fan {0x1512, 0x0000}, 419d6e65bb7SShuming Fan {0x1514, 0xdf47}, 420d6e65bb7SShuming Fan {0x1516, 0x079c}, 421d6e65bb7SShuming Fan {0x1518, 0xfbf5}, 422d6e65bb7SShuming Fan {0x151a, 0x00bc}, 423d6e65bb7SShuming Fan {0x151c, 0x3b85}, 424d6e65bb7SShuming Fan {0x151e, 0x02b3}, 425d6e65bb7SShuming Fan {0x1520, 0x3333}, 426d6e65bb7SShuming Fan {0x1522, 0x0000}, 427d6e65bb7SShuming Fan {0x1524, 0x4000}, 428d6e65bb7SShuming Fan {0x1528, 0x0064}, 429d6e65bb7SShuming Fan {0x152a, 0x0000}, 430d6e65bb7SShuming Fan {0x152c, 0x0000}, 431d6e65bb7SShuming Fan {0x152e, 0x0000}, 432d6e65bb7SShuming Fan {0x1530, 0x0000}, 433d6e65bb7SShuming Fan {0x1532, 0x0000}, 434d6e65bb7SShuming Fan {0x1534, 0x0000}, 435d6e65bb7SShuming Fan {0x1536, 0x0000}, 436d6e65bb7SShuming Fan {0x1538, 0x0040}, 437d6e65bb7SShuming Fan {0x1539, 0x0000}, 438d6e65bb7SShuming Fan {0x153a, 0x0040}, 439d6e65bb7SShuming Fan {0x153b, 0x0000}, 440d6e65bb7SShuming Fan {0x153c, 0x0064}, 441d6e65bb7SShuming Fan {0x153e, 0x0bf9}, 442d6e65bb7SShuming Fan {0x1540, 0xb2a9}, 443d6e65bb7SShuming Fan {0x1544, 0x0200}, 444d6e65bb7SShuming Fan {0x1546, 0x0000}, 445d6e65bb7SShuming Fan {0x1548, 0x00ca}, 446d6e65bb7SShuming Fan {0x1552, 0x03ff}, 447d6e65bb7SShuming Fan {0x1554, 0x017f}, 448d6e65bb7SShuming Fan {0x1556, 0x017f}, 449d6e65bb7SShuming Fan {0x155a, 0x0000}, 450d6e65bb7SShuming Fan {0x155c, 0x0000}, 451d6e65bb7SShuming Fan {0x1560, 0x0040}, 452d6e65bb7SShuming Fan {0x1562, 0x0000}, 453d6e65bb7SShuming Fan {0x1570, 0x03ff}, 454d6e65bb7SShuming Fan {0x1571, 0xdcff}, 455d6e65bb7SShuming Fan {0x1572, 0x1e00}, 456d6e65bb7SShuming Fan {0x1573, 0x224f}, 457d6e65bb7SShuming Fan {0x1574, 0x0000}, 458d6e65bb7SShuming Fan {0x1575, 0x0000}, 459d6e65bb7SShuming Fan {0x1576, 0x1e00}, 460d6e65bb7SShuming Fan {0x1577, 0x0000}, 461d6e65bb7SShuming Fan {0x1578, 0x0000}, 462d6e65bb7SShuming Fan {0x1579, 0x1128}, 463d6e65bb7SShuming Fan {0x157a, 0x03ff}, 464d6e65bb7SShuming Fan {0x157b, 0xdcff}, 465d6e65bb7SShuming Fan {0x157c, 0x1e00}, 466d6e65bb7SShuming Fan {0x157d, 0x224f}, 467d6e65bb7SShuming Fan {0x157e, 0x0000}, 468d6e65bb7SShuming Fan {0x157f, 0x0000}, 469d6e65bb7SShuming Fan {0x1580, 0x1e00}, 470d6e65bb7SShuming Fan {0x1581, 0x0000}, 471d6e65bb7SShuming Fan {0x1582, 0x0000}, 472d6e65bb7SShuming Fan {0x1583, 0x1128}, 473d6e65bb7SShuming Fan {0x1590, 0x03ff}, 474d6e65bb7SShuming Fan {0x1591, 0xdcff}, 475d6e65bb7SShuming Fan {0x1592, 0x1e00}, 476d6e65bb7SShuming Fan {0x1593, 0x224f}, 477d6e65bb7SShuming Fan {0x1594, 0x0000}, 478d6e65bb7SShuming Fan {0x1595, 0x0000}, 479d6e65bb7SShuming Fan {0x1596, 0x1e00}, 480d6e65bb7SShuming Fan {0x1597, 0x0000}, 481d6e65bb7SShuming Fan {0x1598, 0x0000}, 482d6e65bb7SShuming Fan {0x1599, 0x1128}, 483d6e65bb7SShuming Fan {0x159a, 0x03ff}, 484d6e65bb7SShuming Fan {0x159b, 0xdcff}, 485d6e65bb7SShuming Fan {0x159c, 0x1e00}, 486d6e65bb7SShuming Fan {0x159d, 0x224f}, 487d6e65bb7SShuming Fan {0x159e, 0x0000}, 488d6e65bb7SShuming Fan {0x159f, 0x0000}, 489d6e65bb7SShuming Fan {0x15a0, 0x1e00}, 490d6e65bb7SShuming Fan {0x15a1, 0x0000}, 491d6e65bb7SShuming Fan {0x15a2, 0x0000}, 492d6e65bb7SShuming Fan {0x15a3, 0x1128}, 493d6e65bb7SShuming Fan {0x15b0, 0x007f}, 494d6e65bb7SShuming Fan {0x15b1, 0xffff}, 495d6e65bb7SShuming Fan {0x15b2, 0x007f}, 496d6e65bb7SShuming Fan {0x15b3, 0xffff}, 497d6e65bb7SShuming Fan {0x15b4, 0x007f}, 498d6e65bb7SShuming Fan {0x15b5, 0xffff}, 499d6e65bb7SShuming Fan {0x15b8, 0x007f}, 500d6e65bb7SShuming Fan {0x15b9, 0xffff}, 501d6e65bb7SShuming Fan {0x15bc, 0x0000}, 502d6e65bb7SShuming Fan {0x15bd, 0x0000}, 503d6e65bb7SShuming Fan {0x15be, 0xff00}, 504d6e65bb7SShuming Fan {0x15bf, 0x0000}, 505d6e65bb7SShuming Fan {0x15c0, 0xff00}, 506d6e65bb7SShuming Fan {0x15c1, 0x0000}, 507d6e65bb7SShuming Fan {0x15c3, 0xfc00}, 508d6e65bb7SShuming Fan {0x15c4, 0xbb80}, 509d6e65bb7SShuming Fan {0x15d0, 0x0000}, 510d6e65bb7SShuming Fan {0x15d1, 0x0000}, 511d6e65bb7SShuming Fan {0x15d2, 0x0000}, 512d6e65bb7SShuming Fan {0x15d3, 0x0000}, 513d6e65bb7SShuming Fan {0x15d4, 0x0000}, 514d6e65bb7SShuming Fan {0x15d5, 0x0000}, 515d6e65bb7SShuming Fan {0x15d6, 0x0000}, 516d6e65bb7SShuming Fan {0x15d7, 0x0000}, 517d6e65bb7SShuming Fan {0x15d8, 0x0200}, 518d6e65bb7SShuming Fan {0x15d9, 0x0000}, 519d6e65bb7SShuming Fan {0x15da, 0x0000}, 520d6e65bb7SShuming Fan {0x15db, 0x0000}, 521d6e65bb7SShuming Fan {0x15dc, 0x0000}, 522d6e65bb7SShuming Fan {0x15dd, 0x0000}, 523d6e65bb7SShuming Fan {0x15de, 0x0000}, 524d6e65bb7SShuming Fan {0x15df, 0x0000}, 525d6e65bb7SShuming Fan {0x15e0, 0x0000}, 526d6e65bb7SShuming Fan {0x15e1, 0x0000}, 527d6e65bb7SShuming Fan {0x15e2, 0x0200}, 528d6e65bb7SShuming Fan {0x15e3, 0x0000}, 529d6e65bb7SShuming Fan {0x15e4, 0x0000}, 530d6e65bb7SShuming Fan {0x15e5, 0x0000}, 531d6e65bb7SShuming Fan {0x15e6, 0x0000}, 532d6e65bb7SShuming Fan {0x15e7, 0x0000}, 533d6e65bb7SShuming Fan {0x15e8, 0x0000}, 534d6e65bb7SShuming Fan {0x15e9, 0x0000}, 535d6e65bb7SShuming Fan {0x15ea, 0x0000}, 536d6e65bb7SShuming Fan {0x15eb, 0x0000}, 537d6e65bb7SShuming Fan {0x15ec, 0x0200}, 538d6e65bb7SShuming Fan {0x15ed, 0x0000}, 539d6e65bb7SShuming Fan {0x15ee, 0x0000}, 540d6e65bb7SShuming Fan {0x15ef, 0x0000}, 541d6e65bb7SShuming Fan {0x15f0, 0x0000}, 542d6e65bb7SShuming Fan {0x15f1, 0x0000}, 543d6e65bb7SShuming Fan {0x15f2, 0x0000}, 544d6e65bb7SShuming Fan {0x15f3, 0x0000}, 545d6e65bb7SShuming Fan {0x15f4, 0x0000}, 546d6e65bb7SShuming Fan {0x15f5, 0x0000}, 547d6e65bb7SShuming Fan {0x15f6, 0x0200}, 548d6e65bb7SShuming Fan {0x15f7, 0x0200}, 549d6e65bb7SShuming Fan {0x15f8, 0x8200}, 550d6e65bb7SShuming Fan {0x15f9, 0x0000}, 551d6e65bb7SShuming Fan {0x1600, 0x007d}, 552d6e65bb7SShuming Fan {0x1601, 0xa178}, 553d6e65bb7SShuming Fan {0x1602, 0x00c2}, 554d6e65bb7SShuming Fan {0x1603, 0x5383}, 555d6e65bb7SShuming Fan {0x1604, 0x0000}, 556d6e65bb7SShuming Fan {0x1605, 0x02c1}, 557d6e65bb7SShuming Fan {0x1606, 0x007d}, 558d6e65bb7SShuming Fan {0x1607, 0xa178}, 559d6e65bb7SShuming Fan {0x1608, 0x00c2}, 560d6e65bb7SShuming Fan {0x1609, 0x5383}, 561d6e65bb7SShuming Fan {0x160a, 0x003e}, 562d6e65bb7SShuming Fan {0x160b, 0xd37d}, 563d6e65bb7SShuming Fan {0x1611, 0x3210}, 564d6e65bb7SShuming Fan {0x1612, 0x7418}, 565d6e65bb7SShuming Fan {0x1613, 0xc0ff}, 566d6e65bb7SShuming Fan {0x1614, 0x0000}, 567d6e65bb7SShuming Fan {0x1615, 0x00ff}, 568d6e65bb7SShuming Fan {0x1616, 0x0000}, 569d6e65bb7SShuming Fan {0x1617, 0x0000}, 570d6e65bb7SShuming Fan {0x1621, 0x6210}, 571d6e65bb7SShuming Fan {0x1622, 0x7418}, 572d6e65bb7SShuming Fan {0x1623, 0xc0ff}, 573d6e65bb7SShuming Fan {0x1624, 0x0000}, 574d6e65bb7SShuming Fan {0x1625, 0x00ff}, 575d6e65bb7SShuming Fan {0x1626, 0x0000}, 576d6e65bb7SShuming Fan {0x1627, 0x0000}, 577d6e65bb7SShuming Fan {0x1631, 0x3a14}, 578d6e65bb7SShuming Fan {0x1632, 0x7418}, 579d6e65bb7SShuming Fan {0x1633, 0xc3ff}, 580d6e65bb7SShuming Fan {0x1634, 0x0000}, 581d6e65bb7SShuming Fan {0x1635, 0x00ff}, 582d6e65bb7SShuming Fan {0x1636, 0x0000}, 583d6e65bb7SShuming Fan {0x1637, 0x0000}, 584d6e65bb7SShuming Fan {0x1638, 0x0000}, 585d6e65bb7SShuming Fan {0x163a, 0x0000}, 586d6e65bb7SShuming Fan {0x163c, 0x0000}, 587d6e65bb7SShuming Fan {0x163e, 0x0000}, 588d6e65bb7SShuming Fan {0x1640, 0x0000}, 589d6e65bb7SShuming Fan {0x1642, 0x0000}, 590d6e65bb7SShuming Fan {0x1644, 0x0000}, 591d6e65bb7SShuming Fan {0x1646, 0x0000}, 592d6e65bb7SShuming Fan {0x1648, 0x0000}, 593d6e65bb7SShuming Fan {0x1650, 0x0000}, 594d6e65bb7SShuming Fan {0x1652, 0x0000}, 595d6e65bb7SShuming Fan {0x1654, 0x0000}, 596d6e65bb7SShuming Fan {0x1656, 0x0000}, 597d6e65bb7SShuming Fan {0x1658, 0x0000}, 598d6e65bb7SShuming Fan {0x1660, 0x0000}, 599d6e65bb7SShuming Fan {0x1662, 0x0000}, 600d6e65bb7SShuming Fan {0x1664, 0x0000}, 601d6e65bb7SShuming Fan {0x1666, 0x0000}, 602d6e65bb7SShuming Fan {0x1668, 0x0000}, 603d6e65bb7SShuming Fan {0x1670, 0x0000}, 604d6e65bb7SShuming Fan {0x1672, 0x0000}, 605d6e65bb7SShuming Fan {0x1674, 0x0000}, 606d6e65bb7SShuming Fan {0x1676, 0x0000}, 607d6e65bb7SShuming Fan {0x1678, 0x0000}, 608d6e65bb7SShuming Fan {0x1680, 0x0000}, 609d6e65bb7SShuming Fan {0x1682, 0x0000}, 610d6e65bb7SShuming Fan {0x1684, 0x0000}, 611d6e65bb7SShuming Fan {0x1686, 0x0000}, 612d6e65bb7SShuming Fan {0x1688, 0x0000}, 613d6e65bb7SShuming Fan {0x1690, 0x0000}, 614d6e65bb7SShuming Fan {0x1692, 0x0000}, 615d6e65bb7SShuming Fan {0x1694, 0x0000}, 616d6e65bb7SShuming Fan {0x1696, 0x0000}, 617d6e65bb7SShuming Fan {0x1698, 0x0000}, 618d6e65bb7SShuming Fan {0x1700, 0x0000}, 619d6e65bb7SShuming Fan {0x1702, 0x0000}, 620d6e65bb7SShuming Fan {0x1704, 0x0000}, 621d6e65bb7SShuming Fan {0x1706, 0x0000}, 622d6e65bb7SShuming Fan {0x1708, 0x0000}, 623d6e65bb7SShuming Fan {0x1710, 0x0000}, 624d6e65bb7SShuming Fan {0x1712, 0x0000}, 625d6e65bb7SShuming Fan {0x1714, 0x0000}, 626d6e65bb7SShuming Fan {0x1716, 0x0000}, 627d6e65bb7SShuming Fan {0x1718, 0x0000}, 628d6e65bb7SShuming Fan {0x1720, 0x0000}, 629d6e65bb7SShuming Fan {0x1722, 0x0000}, 630d6e65bb7SShuming Fan {0x1724, 0x0000}, 631d6e65bb7SShuming Fan {0x1726, 0x0000}, 632d6e65bb7SShuming Fan {0x1728, 0x0000}, 633d6e65bb7SShuming Fan {0x1730, 0x0000}, 634d6e65bb7SShuming Fan {0x1732, 0x0000}, 635d6e65bb7SShuming Fan {0x1734, 0x0000}, 636d6e65bb7SShuming Fan {0x1736, 0x0000}, 637d6e65bb7SShuming Fan {0x1738, 0x0000}, 638d6e65bb7SShuming Fan {0x173a, 0x0000}, 639d6e65bb7SShuming Fan {0x173c, 0x0000}, 640d6e65bb7SShuming Fan {0x173e, 0x0000}, 641d6e65bb7SShuming Fan {0x17bb, 0x0500}, 642d6e65bb7SShuming Fan {0x17bd, 0x0004}, 643d6e65bb7SShuming Fan {0x17bf, 0x0004}, 644d6e65bb7SShuming Fan {0x17c1, 0x0004}, 645d6e65bb7SShuming Fan {0x17c2, 0x7fff}, 646d6e65bb7SShuming Fan {0x17c3, 0x0000}, 647d6e65bb7SShuming Fan {0x17c5, 0x0000}, 648d6e65bb7SShuming Fan {0x17c7, 0x0000}, 649d6e65bb7SShuming Fan {0x17c9, 0x0000}, 650d6e65bb7SShuming Fan {0x17cb, 0x2010}, 651d6e65bb7SShuming Fan {0x17cd, 0x0000}, 652d6e65bb7SShuming Fan {0x17cf, 0x0000}, 653d6e65bb7SShuming Fan {0x17d1, 0x0000}, 654d6e65bb7SShuming Fan {0x17d3, 0x0000}, 655d6e65bb7SShuming Fan {0x17d5, 0x0000}, 656d6e65bb7SShuming Fan {0x17d7, 0x0000}, 657d6e65bb7SShuming Fan {0x17d9, 0x0000}, 658d6e65bb7SShuming Fan {0x17db, 0x0000}, 659d6e65bb7SShuming Fan {0x17dd, 0x0000}, 660d6e65bb7SShuming Fan {0x17df, 0x0000}, 661d6e65bb7SShuming Fan {0x17e1, 0x0000}, 662d6e65bb7SShuming Fan {0x17e3, 0x0000}, 663d6e65bb7SShuming Fan {0x17e5, 0x0000}, 664d6e65bb7SShuming Fan {0x17e7, 0x0000}, 665d6e65bb7SShuming Fan {0x17e9, 0x0000}, 666d6e65bb7SShuming Fan {0x17eb, 0x0000}, 667d6e65bb7SShuming Fan {0x17ed, 0x0000}, 668d6e65bb7SShuming Fan {0x17ef, 0x0000}, 669d6e65bb7SShuming Fan {0x17f1, 0x0000}, 670d6e65bb7SShuming Fan {0x17f3, 0x0000}, 671d6e65bb7SShuming Fan {0x17f5, 0x0000}, 672d6e65bb7SShuming Fan {0x17f7, 0x0000}, 673d6e65bb7SShuming Fan {0x17f9, 0x0000}, 674d6e65bb7SShuming Fan {0x17fb, 0x0000}, 675d6e65bb7SShuming Fan {0x17fd, 0x0000}, 676d6e65bb7SShuming Fan {0x17ff, 0x0000}, 677d6e65bb7SShuming Fan {0x1801, 0x0000}, 678d6e65bb7SShuming Fan {0x1803, 0x0000}, 679d6e65bb7SShuming Fan }; 680d6e65bb7SShuming Fan 681d6e65bb7SShuming Fan static int rt1011_reg_init(struct snd_soc_component *component) 682d6e65bb7SShuming Fan { 683d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 684d6e65bb7SShuming Fan 685683b8515SShuming Fan regmap_multi_reg_write(rt1011->regmap, 686683b8515SShuming Fan init_list, ARRAY_SIZE(init_list)); 687d6e65bb7SShuming Fan return 0; 688d6e65bb7SShuming Fan } 689d6e65bb7SShuming Fan 690d6e65bb7SShuming Fan static bool rt1011_volatile_register(struct device *dev, unsigned int reg) 691d6e65bb7SShuming Fan { 692d6e65bb7SShuming Fan switch (reg) { 693d6e65bb7SShuming Fan case RT1011_RESET: 694d6e65bb7SShuming Fan case RT1011_SRC_2: 695d6e65bb7SShuming Fan case RT1011_CLK_DET: 696d6e65bb7SShuming Fan case RT1011_SIL_DET: 697d6e65bb7SShuming Fan case RT1011_VERSION_ID: 698d6e65bb7SShuming Fan case RT1011_VENDOR_ID: 699d6e65bb7SShuming Fan case RT1011_DEVICE_ID: 700d6e65bb7SShuming Fan case RT1011_DUM_RO: 701d6e65bb7SShuming Fan case RT1011_DAC_SET_3: 702d6e65bb7SShuming Fan case RT1011_PWM_CAL: 703d6e65bb7SShuming Fan case RT1011_SPK_VOL_TEST_OUT: 704d6e65bb7SShuming Fan case RT1011_VBAT_VOL_DET_1: 705d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_1: 706d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_2: 707d6e65bb7SShuming Fan case RT1011_VBAT_PROTECTION: 708d6e65bb7SShuming Fan case RT1011_VBAT_DET: 709d6e65bb7SShuming Fan case RT1011_BOOST_CON_1: 710d6e65bb7SShuming Fan case RT1011_SHORT_CIRCUIT_DET_1: 711d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_3: 712d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_6: 713d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_3: 714d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_7: 715d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_8: 716d6e65bb7SShuming Fan case RT1011_SPL_1: 717d6e65bb7SShuming Fan case RT1011_SPL_4: 718d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_1: 719d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_1: 720d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_2: 721d6e65bb7SShuming Fan case RT1011_BQ_SET_0: 722d6e65bb7SShuming Fan case RT1011_BQ_SET_1: 723d6e65bb7SShuming Fan case RT1011_BQ_SET_2: 724d6e65bb7SShuming Fan case RT1011_TEST_PAD_STATUS: 725d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_1: 726d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_5: 727d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_6: 728d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_7: 729d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_8: 730d6e65bb7SShuming Fan case RT1011_SINE_GEN_REG_2: 731d6e65bb7SShuming Fan case RT1011_STP_CALIB_RS_TEMP: 732d6e65bb7SShuming Fan case RT1011_SPK_RESISTANCE_1: 733d6e65bb7SShuming Fan case RT1011_SPK_RESISTANCE_2: 734d6e65bb7SShuming Fan case RT1011_SPK_THERMAL: 735d6e65bb7SShuming Fan case RT1011_ALC_BK_GAIN_O: 736d6e65bb7SShuming Fan case RT1011_ALC_BK_GAIN_O_PRE: 737d6e65bb7SShuming Fan case RT1011_SPK_DC_O_23_16: 738d6e65bb7SShuming Fan case RT1011_SPK_DC_O_15_0: 739d6e65bb7SShuming Fan case RT1011_INIT_RECIPROCAL_SYN_24_16: 740d6e65bb7SShuming Fan case RT1011_INIT_RECIPROCAL_SYN_15_0: 741d6e65bb7SShuming Fan case RT1011_SPK_EXCURSION_23_16: 742d6e65bb7SShuming Fan case RT1011_SPK_EXCURSION_15_0: 743d6e65bb7SShuming Fan case RT1011_SEP_MAIN_OUT_23_16: 744d6e65bb7SShuming Fan case RT1011_SEP_MAIN_OUT_15_0: 745d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_5: 746d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_6: 747d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_7: 748d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_5: 749d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_6: 750d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_7: 751d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_5: 752d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_6: 753d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_7: 754d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_8: 755d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_9: 756d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_10: 757d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_11: 758d6e65bb7SShuming Fan case RT1011_IRQ_1: 759d6e65bb7SShuming Fan case RT1011_EFUSE_CONTROL_1: 760d6e65bb7SShuming Fan case RT1011_EFUSE_CONTROL_2: 761d6e65bb7SShuming Fan case RT1011_EFUSE_MATCH_DONE ... RT1011_EFUSE_READ_R0_3_15_0: 762d6e65bb7SShuming Fan return true; 763d6e65bb7SShuming Fan 764d6e65bb7SShuming Fan default: 765d6e65bb7SShuming Fan return false; 766d6e65bb7SShuming Fan } 767d6e65bb7SShuming Fan } 768d6e65bb7SShuming Fan 769d6e65bb7SShuming Fan static bool rt1011_readable_register(struct device *dev, unsigned int reg) 770d6e65bb7SShuming Fan { 771d6e65bb7SShuming Fan switch (reg) { 772d6e65bb7SShuming Fan case RT1011_RESET: 773d6e65bb7SShuming Fan case RT1011_CLK_1: 774d6e65bb7SShuming Fan case RT1011_CLK_2: 775d6e65bb7SShuming Fan case RT1011_CLK_3: 776d6e65bb7SShuming Fan case RT1011_CLK_4: 777d6e65bb7SShuming Fan case RT1011_PLL_1: 778d6e65bb7SShuming Fan case RT1011_PLL_2: 779d6e65bb7SShuming Fan case RT1011_SRC_1: 780d6e65bb7SShuming Fan case RT1011_SRC_2: 781d6e65bb7SShuming Fan case RT1011_SRC_3: 782d6e65bb7SShuming Fan case RT1011_CLK_DET: 783d6e65bb7SShuming Fan case RT1011_SIL_DET: 784d6e65bb7SShuming Fan case RT1011_PRIV_INDEX: 785d6e65bb7SShuming Fan case RT1011_PRIV_DATA: 786d6e65bb7SShuming Fan case RT1011_CUSTOMER_ID: 787d6e65bb7SShuming Fan case RT1011_FM_VER: 788d6e65bb7SShuming Fan case RT1011_VERSION_ID: 789d6e65bb7SShuming Fan case RT1011_VENDOR_ID: 790d6e65bb7SShuming Fan case RT1011_DEVICE_ID: 791d6e65bb7SShuming Fan case RT1011_DUM_RW_0: 792d6e65bb7SShuming Fan case RT1011_DUM_YUN: 793d6e65bb7SShuming Fan case RT1011_DUM_RW_1: 794d6e65bb7SShuming Fan case RT1011_DUM_RO: 795d6e65bb7SShuming Fan case RT1011_MAN_I2C_DEV: 796d6e65bb7SShuming Fan case RT1011_DAC_SET_1: 797d6e65bb7SShuming Fan case RT1011_DAC_SET_2: 798d6e65bb7SShuming Fan case RT1011_DAC_SET_3: 799d6e65bb7SShuming Fan case RT1011_ADC_SET: 800d6e65bb7SShuming Fan case RT1011_ADC_SET_1: 801d6e65bb7SShuming Fan case RT1011_ADC_SET_2: 802d6e65bb7SShuming Fan case RT1011_ADC_SET_3: 803d6e65bb7SShuming Fan case RT1011_ADC_SET_4: 804d6e65bb7SShuming Fan case RT1011_ADC_SET_5: 805d6e65bb7SShuming Fan case RT1011_TDM_TOTAL_SET: 806d6e65bb7SShuming Fan case RT1011_TDM1_SET_TCON: 807d6e65bb7SShuming Fan case RT1011_TDM1_SET_1: 808d6e65bb7SShuming Fan case RT1011_TDM1_SET_2: 809d6e65bb7SShuming Fan case RT1011_TDM1_SET_3: 810d6e65bb7SShuming Fan case RT1011_TDM1_SET_4: 811d6e65bb7SShuming Fan case RT1011_TDM1_SET_5: 812d6e65bb7SShuming Fan case RT1011_TDM2_SET_1: 813d6e65bb7SShuming Fan case RT1011_TDM2_SET_2: 814d6e65bb7SShuming Fan case RT1011_TDM2_SET_3: 815d6e65bb7SShuming Fan case RT1011_TDM2_SET_4: 816d6e65bb7SShuming Fan case RT1011_TDM2_SET_5: 817d6e65bb7SShuming Fan case RT1011_PWM_CAL: 818d6e65bb7SShuming Fan case RT1011_MIXER_1: 819d6e65bb7SShuming Fan case RT1011_MIXER_2: 820d6e65bb7SShuming Fan case RT1011_ADRC_LIMIT: 821d6e65bb7SShuming Fan case RT1011_A_PRO: 822d6e65bb7SShuming Fan case RT1011_A_TIMING_1: 823d6e65bb7SShuming Fan case RT1011_A_TIMING_2: 824d6e65bb7SShuming Fan case RT1011_A_TEMP_SEN: 825d6e65bb7SShuming Fan case RT1011_SPK_VOL_DET_1: 826d6e65bb7SShuming Fan case RT1011_SPK_VOL_DET_2: 827d6e65bb7SShuming Fan case RT1011_SPK_VOL_TEST_OUT: 828d6e65bb7SShuming Fan case RT1011_VBAT_VOL_DET_1: 829d6e65bb7SShuming Fan case RT1011_VBAT_VOL_DET_2: 830d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_1: 831d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_2: 832d6e65bb7SShuming Fan case RT1011_VBAT_PROTECTION: 833d6e65bb7SShuming Fan case RT1011_VBAT_DET: 834d6e65bb7SShuming Fan case RT1011_POWER_1: 835d6e65bb7SShuming Fan case RT1011_POWER_2: 836d6e65bb7SShuming Fan case RT1011_POWER_3: 837d6e65bb7SShuming Fan case RT1011_POWER_4: 838d6e65bb7SShuming Fan case RT1011_POWER_5: 839d6e65bb7SShuming Fan case RT1011_POWER_6: 840d6e65bb7SShuming Fan case RT1011_POWER_7: 841d6e65bb7SShuming Fan case RT1011_POWER_8: 842d6e65bb7SShuming Fan case RT1011_POWER_9: 843d6e65bb7SShuming Fan case RT1011_CLASS_D_POS: 844d6e65bb7SShuming Fan case RT1011_BOOST_CON_1: 845d6e65bb7SShuming Fan case RT1011_BOOST_CON_2: 846d6e65bb7SShuming Fan case RT1011_ANALOG_CTRL: 847d6e65bb7SShuming Fan case RT1011_POWER_SEQ: 848d6e65bb7SShuming Fan case RT1011_SHORT_CIRCUIT_DET_1: 849d6e65bb7SShuming Fan case RT1011_SHORT_CIRCUIT_DET_2: 850d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_0: 851d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_1: 852d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_2: 853d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_3: 854d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_4: 855d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_5: 856d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_6: 857d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_7: 858d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_8: 859d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_9: 860d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_1: 861d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_2: 862d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_3: 863d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_4: 864d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_5: 865d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_6: 866d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_7: 867d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_8: 868d6e65bb7SShuming Fan case RT1011_SPL_1: 869d6e65bb7SShuming Fan case RT1011_SPL_2: 870d6e65bb7SShuming Fan case RT1011_SPL_3: 871d6e65bb7SShuming Fan case RT1011_SPL_4: 872d6e65bb7SShuming Fan case RT1011_THER_FOLD_BACK_1: 873d6e65bb7SShuming Fan case RT1011_THER_FOLD_BACK_2: 874d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_1: 875d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_2: 876d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_3: 877d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_4: 878d6e65bb7SShuming Fan case RT1011_BAT_GAIN_1: 879d6e65bb7SShuming Fan case RT1011_BAT_GAIN_2: 880d6e65bb7SShuming Fan case RT1011_BAT_GAIN_3: 881d6e65bb7SShuming Fan case RT1011_BAT_GAIN_4: 882d6e65bb7SShuming Fan case RT1011_BAT_GAIN_5: 883d6e65bb7SShuming Fan case RT1011_BAT_GAIN_6: 884d6e65bb7SShuming Fan case RT1011_BAT_GAIN_7: 885d6e65bb7SShuming Fan case RT1011_BAT_GAIN_8: 886d6e65bb7SShuming Fan case RT1011_BAT_GAIN_9: 887d6e65bb7SShuming Fan case RT1011_BAT_GAIN_10: 888d6e65bb7SShuming Fan case RT1011_BAT_GAIN_11: 889d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_1: 890d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_2: 891d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_3: 892d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_4: 893d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_5: 894d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_6: 895d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_7: 896d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_8: 897d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_9: 898d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_10: 899d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_11: 900d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_12: 901d6e65bb7SShuming Fan case RT1011_SPREAD_SPECTURM: 902d6e65bb7SShuming Fan case RT1011_PRO_GAIN_MODE: 903d6e65bb7SShuming Fan case RT1011_RT_DRC_CROSS: 904d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_1: 905d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_2: 906d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_3: 907d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_4: 908d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_5: 909d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_6: 910d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_7: 911d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_8: 912d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_1: 913d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_2: 914d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_3: 915d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_4: 916d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_5: 917d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_6: 918d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_7: 919d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_8: 920d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_1: 921d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_2: 922d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_3: 923d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_4: 924d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_5: 925d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_6: 926d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_7: 927d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_8: 928d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_1: 929d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_2: 930d6e65bb7SShuming Fan case RT1011_BQ_SET_0: 931d6e65bb7SShuming Fan case RT1011_BQ_SET_1: 932d6e65bb7SShuming Fan case RT1011_BQ_SET_2: 933d6e65bb7SShuming Fan case RT1011_BQ_PRE_GAIN_28_16: 934d6e65bb7SShuming Fan case RT1011_BQ_PRE_GAIN_15_0: 935d6e65bb7SShuming Fan case RT1011_BQ_POST_GAIN_28_16: 936d6e65bb7SShuming Fan case RT1011_BQ_POST_GAIN_15_0: 937d6e65bb7SShuming Fan case RT1011_BQ_H0_28_16 ... RT1011_BQ_A2_15_0: 938d6e65bb7SShuming Fan case RT1011_BQ_1_H0_28_16 ... RT1011_BQ_1_A2_15_0: 939d6e65bb7SShuming Fan case RT1011_BQ_2_H0_28_16 ... RT1011_BQ_2_A2_15_0: 940d6e65bb7SShuming Fan case RT1011_BQ_3_H0_28_16 ... RT1011_BQ_3_A2_15_0: 941d6e65bb7SShuming Fan case RT1011_BQ_4_H0_28_16 ... RT1011_BQ_4_A2_15_0: 942d6e65bb7SShuming Fan case RT1011_BQ_5_H0_28_16 ... RT1011_BQ_5_A2_15_0: 943d6e65bb7SShuming Fan case RT1011_BQ_6_H0_28_16 ... RT1011_BQ_6_A2_15_0: 944d6e65bb7SShuming Fan case RT1011_BQ_7_H0_28_16 ... RT1011_BQ_7_A2_15_0: 945d6e65bb7SShuming Fan case RT1011_BQ_8_H0_28_16 ... RT1011_BQ_8_A2_15_0: 946d6e65bb7SShuming Fan case RT1011_BQ_9_H0_28_16 ... RT1011_BQ_9_A2_15_0: 947d6e65bb7SShuming Fan case RT1011_BQ_10_H0_28_16 ... RT1011_BQ_10_A2_15_0: 948d6e65bb7SShuming Fan case RT1011_TEST_PAD_STATUS ... RT1011_PLL_INTERNAL_SET: 949d6e65bb7SShuming Fan case RT1011_TEST_OUT_1 ... RT1011_TEST_OUT_3: 950d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_1 ... RT1011_DC_CALIB_CLASSD_10: 951d6e65bb7SShuming Fan case RT1011_CLASSD_INTERNAL_SET_1 ... RT1011_VREF_LV_1: 952d6e65bb7SShuming Fan case RT1011_SMART_BOOST_TIMING_1 ... RT1011_SMART_BOOST_TIMING_36: 953d6e65bb7SShuming Fan case RT1011_SINE_GEN_REG_1 ... RT1011_SINE_GEN_REG_3: 954d6e65bb7SShuming Fan case RT1011_STP_INITIAL_RS_TEMP ... RT1011_SPK_THERMAL: 955d6e65bb7SShuming Fan case RT1011_STP_OTP_TH ... RT1011_INIT_RECIPROCAL_SYN_15_0: 956d6e65bb7SShuming Fan case RT1011_STP_BQ_1_A1_L_28_16 ... RT1011_STP_BQ_1_H0_R_15_0: 957d6e65bb7SShuming Fan case RT1011_STP_BQ_2_A1_L_28_16 ... RT1011_SEP_RE_REG_15_0: 958d6e65bb7SShuming Fan case RT1011_DRC_CF_PARAMS_1 ... RT1011_DRC_CF_PARAMS_12: 959d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_1 ... RT1011_ALC_DRC_HB_INTERNAL_7: 960d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_1 ... RT1011_ALC_DRC_BB_INTERNAL_7: 961d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_1 ... RT1011_ALC_DRC_POS_INTERNAL_8: 962d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_9 ... RT1011_BQ_1_PARAMS_CHECK_5: 963d6e65bb7SShuming Fan case RT1011_BQ_2_PARAMS_CHECK_1 ... RT1011_BQ_2_PARAMS_CHECK_5: 964d6e65bb7SShuming Fan case RT1011_BQ_3_PARAMS_CHECK_1 ... RT1011_BQ_3_PARAMS_CHECK_5: 965d6e65bb7SShuming Fan case RT1011_BQ_4_PARAMS_CHECK_1 ... RT1011_BQ_4_PARAMS_CHECK_5: 966d6e65bb7SShuming Fan case RT1011_BQ_5_PARAMS_CHECK_1 ... RT1011_BQ_5_PARAMS_CHECK_5: 967d6e65bb7SShuming Fan case RT1011_BQ_6_PARAMS_CHECK_1 ... RT1011_BQ_6_PARAMS_CHECK_5: 968d6e65bb7SShuming Fan case RT1011_BQ_7_PARAMS_CHECK_1 ... RT1011_BQ_7_PARAMS_CHECK_5: 969d6e65bb7SShuming Fan case RT1011_BQ_8_PARAMS_CHECK_1 ... RT1011_BQ_8_PARAMS_CHECK_5: 970d6e65bb7SShuming Fan case RT1011_BQ_9_PARAMS_CHECK_1 ... RT1011_BQ_9_PARAMS_CHECK_5: 971d6e65bb7SShuming Fan case RT1011_BQ_10_PARAMS_CHECK_1 ... RT1011_BQ_10_PARAMS_CHECK_5: 972d6e65bb7SShuming Fan case RT1011_IRQ_1 ... RT1011_PART_NUMBER_EFUSE: 973d6e65bb7SShuming Fan case RT1011_EFUSE_CONTROL_1 ... RT1011_EFUSE_READ_R0_3_15_0: 974d6e65bb7SShuming Fan return true; 975d6e65bb7SShuming Fan default: 976d6e65bb7SShuming Fan return false; 977d6e65bb7SShuming Fan } 978d6e65bb7SShuming Fan } 979d6e65bb7SShuming Fan 980d6e65bb7SShuming Fan static const char * const rt1011_din_source_select[] = { 981d6e65bb7SShuming Fan "Left", 982d6e65bb7SShuming Fan "Right", 983d6e65bb7SShuming Fan "Left + Right average", 984d6e65bb7SShuming Fan }; 985d6e65bb7SShuming Fan 986d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_din_source_enum, RT1011_CROSS_BQ_SET_1, 5, 987d6e65bb7SShuming Fan rt1011_din_source_select); 988d6e65bb7SShuming Fan 989d6e65bb7SShuming Fan static const char * const rt1011_tdm_data_out_select[] = { 990d6e65bb7SShuming Fan "TDM_O_LR", "BQ1", "DVOL", "BQ10", "ALC", "DMIX", "ADC_SRC_LR", 991d6e65bb7SShuming Fan "ADC_O_LR", "ADC_MONO", "RSPK_BPF_LR", "DMIX_ADD", "ENVELOPE_FS", 992d6e65bb7SShuming Fan "SEP_O_GAIN", "ALC_BK_GAIN", "STP_V_C", "DMIX_ABST" 993d6e65bb7SShuming Fan }; 994d6e65bb7SShuming Fan 995d6e65bb7SShuming Fan static const char * const rt1011_tdm_l_ch_data_select[] = { 996d6e65bb7SShuming Fan "Slot0", "Slot1", "Slot2", "Slot3", "Slot4", "Slot5", "Slot6", "Slot7" 997d6e65bb7SShuming Fan }; 998d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_l_dac1_enum, RT1011_TDM1_SET_4, 12, 999d6e65bb7SShuming Fan rt1011_tdm_l_ch_data_select); 1000d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm2_l_dac1_enum, RT1011_TDM2_SET_4, 12, 1001d6e65bb7SShuming Fan rt1011_tdm_l_ch_data_select); 1002d6e65bb7SShuming Fan 1003d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_adc1_dat_enum, 1004d6e65bb7SShuming Fan RT1011_ADCDAT_OUT_SOURCE, 0, rt1011_tdm_data_out_select); 1005d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_adc1_loc_enum, RT1011_TDM1_SET_2, 0, 1006d6e65bb7SShuming Fan rt1011_tdm_l_ch_data_select); 1007d6e65bb7SShuming Fan 1008d6e65bb7SShuming Fan static const char * const rt1011_adc_data_mode_select[] = { 1009d6e65bb7SShuming Fan "Stereo", "Mono" 1010d6e65bb7SShuming Fan }; 1011d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_adc_dout_mode_enum, RT1011_TDM1_SET_1, 12, 1012d6e65bb7SShuming Fan rt1011_adc_data_mode_select); 1013d6e65bb7SShuming Fan 1014d6e65bb7SShuming Fan static const char * const rt1011_tdm_adc_data_len_control[] = { 1015d6e65bb7SShuming Fan "1CH", "2CH", "3CH", "4CH", "5CH", "6CH", "7CH", "8CH" 1016d6e65bb7SShuming Fan }; 1017d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_dout_len_enum, RT1011_TDM1_SET_2, 13, 1018d6e65bb7SShuming Fan rt1011_tdm_adc_data_len_control); 1019d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm2_dout_len_enum, RT1011_TDM2_SET_2, 13, 1020d6e65bb7SShuming Fan rt1011_tdm_adc_data_len_control); 1021d6e65bb7SShuming Fan 1022d6e65bb7SShuming Fan static const char * const rt1011_tdm_adc_swap_select[] = { 1023d6e65bb7SShuming Fan "L/R", "R/L", "L/L", "R/R" 1024d6e65bb7SShuming Fan }; 1025d6e65bb7SShuming Fan 1026d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm_adc1_1_enum, RT1011_TDM1_SET_3, 6, 1027d6e65bb7SShuming Fan rt1011_tdm_adc_swap_select); 10283403b808SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm_adc2_1_enum, RT1011_TDM1_SET_3, 4, 10293403b808SShuming Fan rt1011_tdm_adc_swap_select); 1030d6e65bb7SShuming Fan 1031d6e65bb7SShuming Fan static void rt1011_reset(struct regmap *regmap) 1032d6e65bb7SShuming Fan { 1033d6e65bb7SShuming Fan regmap_write(regmap, RT1011_RESET, 0); 1034d6e65bb7SShuming Fan } 1035d6e65bb7SShuming Fan 1036d6e65bb7SShuming Fan static int rt1011_recv_spk_mode_get(struct snd_kcontrol *kcontrol, 1037d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1038d6e65bb7SShuming Fan { 1039d6e65bb7SShuming Fan struct snd_soc_component *component = 1040d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol); 1041d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = 1042d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component); 1043d6e65bb7SShuming Fan 1044d6e65bb7SShuming Fan ucontrol->value.integer.value[0] = rt1011->recv_spk_mode; 1045d6e65bb7SShuming Fan 1046d6e65bb7SShuming Fan return 0; 1047d6e65bb7SShuming Fan } 1048d6e65bb7SShuming Fan 1049d6e65bb7SShuming Fan static int rt1011_recv_spk_mode_put(struct snd_kcontrol *kcontrol, 1050d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1051d6e65bb7SShuming Fan { 1052d6e65bb7SShuming Fan struct snd_soc_component *component = 1053d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol); 1054d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = 1055d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component); 1056d6e65bb7SShuming Fan 1057d6e65bb7SShuming Fan if (ucontrol->value.integer.value[0] == rt1011->recv_spk_mode) 1058d6e65bb7SShuming Fan return 0; 1059d6e65bb7SShuming Fan 1060d6e65bb7SShuming Fan if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { 1061d6e65bb7SShuming Fan rt1011->recv_spk_mode = ucontrol->value.integer.value[0]; 1062d6e65bb7SShuming Fan 1063d6e65bb7SShuming Fan if (rt1011->recv_spk_mode) { 1064d6e65bb7SShuming Fan 1065d6e65bb7SShuming Fan /* 1: recevier mode on */ 1066d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1067d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_3, 1068d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_SPK_MASK, 1069d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_410K); 1070d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1071d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1, 1072d6e65bb7SShuming Fan RT1011_RECV_MODE_SPK_MASK, 1073d6e65bb7SShuming Fan RT1011_RECV_MODE); 1074d6e65bb7SShuming Fan } else { 1075d6e65bb7SShuming Fan /* 0: speaker mode on */ 1076d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1077d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_3, 1078d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_SPK_MASK, 1079d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_72P5K); 1080d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1081d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1, 1082d6e65bb7SShuming Fan RT1011_RECV_MODE_SPK_MASK, 1083d6e65bb7SShuming Fan RT1011_SPK_MODE); 1084d6e65bb7SShuming Fan } 1085d6e65bb7SShuming Fan } 1086d6e65bb7SShuming Fan 1087d6e65bb7SShuming Fan return 0; 1088d6e65bb7SShuming Fan } 1089d6e65bb7SShuming Fan 1090d6e65bb7SShuming Fan static bool rt1011_validate_bq_drc_coeff(unsigned short reg) 1091d6e65bb7SShuming Fan { 1092f7c5c168SPierre-Louis Bossart if ((reg == RT1011_DAC_SET_1) || 1093f7c5c168SPierre-Louis Bossart (reg >= RT1011_ADC_SET && reg <= RT1011_ADC_SET_1) || 1094f7c5c168SPierre-Louis Bossart (reg == RT1011_ADC_SET_4) || (reg == RT1011_ADC_SET_5) || 1095f7c5c168SPierre-Louis Bossart (reg == RT1011_MIXER_1) || 1096f7c5c168SPierre-Louis Bossart (reg == RT1011_A_TIMING_1) || 1097f7c5c168SPierre-Louis Bossart (reg >= RT1011_POWER_7 && reg <= RT1011_POWER_8) || 1098f7c5c168SPierre-Louis Bossart (reg == RT1011_CLASS_D_POS) || (reg == RT1011_ANALOG_CTRL) || 1099f7c5c168SPierre-Louis Bossart (reg >= RT1011_SPK_TEMP_PROTECT_0 && reg <= RT1011_SPK_TEMP_PROTECT_6) || 1100f7c5c168SPierre-Louis Bossart (reg >= RT1011_SPK_PRO_DC_DET_5 && reg <= RT1011_BAT_GAIN_1) || 1101f7c5c168SPierre-Louis Bossart (reg >= RT1011_RT_DRC_CROSS && reg <= RT1011_RT_DRC_POS_8) || 1102f7c5c168SPierre-Louis Bossart (reg >= RT1011_CROSS_BQ_SET_1 && reg <= RT1011_BQ_10_A2_15_0) || 1103f7c5c168SPierre-Louis Bossart (reg >= RT1011_SMART_BOOST_TIMING_1 && reg <= RT1011_SMART_BOOST_TIMING_36) || 1104f7c5c168SPierre-Louis Bossart (reg == RT1011_SINE_GEN_REG_1) || 1105f7c5c168SPierre-Louis Bossart (reg >= RT1011_STP_ALPHA_RECIPROCAL_MSB && reg <= RT1011_BQ_6_PARAMS_CHECK_5) || 1106f7c5c168SPierre-Louis Bossart (reg >= RT1011_BQ_7_PARAMS_CHECK_1 && reg <= RT1011_BQ_10_PARAMS_CHECK_5)) 1107d6e65bb7SShuming Fan return true; 1108d6e65bb7SShuming Fan 1109d6e65bb7SShuming Fan return false; 1110d6e65bb7SShuming Fan } 1111d6e65bb7SShuming Fan 1112d6e65bb7SShuming Fan static int rt1011_bq_drc_coeff_get(struct snd_kcontrol *kcontrol, 1113d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1114d6e65bb7SShuming Fan { 1115d6e65bb7SShuming Fan struct snd_soc_component *component = 1116d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol); 1117d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = 1118d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component); 1119d6e65bb7SShuming Fan struct rt1011_bq_drc_params *bq_drc_info; 1120d6e65bb7SShuming Fan struct rt1011_bq_drc_params *params = 1121d6e65bb7SShuming Fan (struct rt1011_bq_drc_params *)ucontrol->value.integer.value; 1122d6e65bb7SShuming Fan unsigned int i, mode_idx = 0; 1123d6e65bb7SShuming Fan 1124d6e65bb7SShuming Fan if (strstr(ucontrol->id.name, "AdvanceMode Initial Set")) 1125d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_INITIAL_SET; 1126d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff")) 1127d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SEP_BQ_COEFF; 1128d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff")) 1129d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_EQ_BQ_COEFF; 1130d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff")) 1131d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_BQ_UI_COEFF; 1132d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff")) 1133d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SMARTBOOST_COEFF; 1134d6e65bb7SShuming Fan else 1135d6e65bb7SShuming Fan return -EINVAL; 1136d6e65bb7SShuming Fan 1137d6e65bb7SShuming Fan pr_info("%s, id.name=%s, mode_idx=%d\n", __func__, 1138d6e65bb7SShuming Fan ucontrol->id.name, mode_idx); 1139d6e65bb7SShuming Fan bq_drc_info = rt1011->bq_drc_params[mode_idx]; 1140d6e65bb7SShuming Fan 1141d6e65bb7SShuming Fan for (i = 0; i < RT1011_BQ_DRC_NUM; i++) { 114264429a87SShuming Fan params[i].reg = bq_drc_info[i].reg; 114364429a87SShuming Fan params[i].val = bq_drc_info[i].val; 1144d6e65bb7SShuming Fan } 1145d6e65bb7SShuming Fan 1146d6e65bb7SShuming Fan return 0; 1147d6e65bb7SShuming Fan } 1148d6e65bb7SShuming Fan 1149d6e65bb7SShuming Fan static int rt1011_bq_drc_coeff_put(struct snd_kcontrol *kcontrol, 1150d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1151d6e65bb7SShuming Fan { 1152d6e65bb7SShuming Fan struct snd_soc_component *component = 1153d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol); 1154d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = 1155d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component); 1156d6e65bb7SShuming Fan struct rt1011_bq_drc_params *bq_drc_info; 1157d6e65bb7SShuming Fan struct rt1011_bq_drc_params *params = 1158d6e65bb7SShuming Fan (struct rt1011_bq_drc_params *)ucontrol->value.integer.value; 1159d6e65bb7SShuming Fan unsigned int i, mode_idx = 0; 1160d6e65bb7SShuming Fan 1161d6e65bb7SShuming Fan if (strstr(ucontrol->id.name, "AdvanceMode Initial Set")) 1162d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_INITIAL_SET; 1163d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff")) 1164d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SEP_BQ_COEFF; 1165d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff")) 1166d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_EQ_BQ_COEFF; 1167d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff")) 1168d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_BQ_UI_COEFF; 1169d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff")) 1170d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SMARTBOOST_COEFF; 1171d6e65bb7SShuming Fan else 1172d6e65bb7SShuming Fan return -EINVAL; 1173d6e65bb7SShuming Fan 1174d6e65bb7SShuming Fan bq_drc_info = rt1011->bq_drc_params[mode_idx]; 1175d6e65bb7SShuming Fan memset(bq_drc_info, 0, 1176d6e65bb7SShuming Fan sizeof(struct rt1011_bq_drc_params) * RT1011_BQ_DRC_NUM); 1177d6e65bb7SShuming Fan 1178d6e65bb7SShuming Fan pr_info("%s, id.name=%s, mode_idx=%d\n", __func__, 1179d6e65bb7SShuming Fan ucontrol->id.name, mode_idx); 1180d6e65bb7SShuming Fan for (i = 0; i < RT1011_BQ_DRC_NUM; i++) { 118164429a87SShuming Fan bq_drc_info[i].reg = params[i].reg; 118264429a87SShuming Fan bq_drc_info[i].val = params[i].val; 1183d6e65bb7SShuming Fan } 1184d6e65bb7SShuming Fan 1185d6e65bb7SShuming Fan for (i = 0; i < RT1011_BQ_DRC_NUM; i++) { 1186d6e65bb7SShuming Fan if (bq_drc_info[i].reg == 0) 1187d6e65bb7SShuming Fan break; 1188d6e65bb7SShuming Fan else if (rt1011_validate_bq_drc_coeff(bq_drc_info[i].reg)) { 1189d6e65bb7SShuming Fan snd_soc_component_write(component, bq_drc_info[i].reg, 1190d6e65bb7SShuming Fan bq_drc_info[i].val); 1191d6e65bb7SShuming Fan } 1192d6e65bb7SShuming Fan } 1193d6e65bb7SShuming Fan 1194d6e65bb7SShuming Fan return 0; 1195d6e65bb7SShuming Fan } 1196d6e65bb7SShuming Fan 1197d6e65bb7SShuming Fan static int rt1011_bq_drc_info(struct snd_kcontrol *kcontrol, 1198d6e65bb7SShuming Fan struct snd_ctl_elem_info *uinfo) 1199d6e65bb7SShuming Fan { 1200d6e65bb7SShuming Fan uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1201d6e65bb7SShuming Fan uinfo->count = 128; 1202d6e65bb7SShuming Fan uinfo->value.integer.max = 0x17ffffff; 1203d6e65bb7SShuming Fan 1204d6e65bb7SShuming Fan return 0; 1205d6e65bb7SShuming Fan } 1206d6e65bb7SShuming Fan 1207d6e65bb7SShuming Fan #define RT1011_BQ_DRC(xname) \ 1208d6e65bb7SShuming Fan { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 1209d6e65bb7SShuming Fan .info = rt1011_bq_drc_info, \ 1210d6e65bb7SShuming Fan .get = rt1011_bq_drc_coeff_get, \ 1211d6e65bb7SShuming Fan .put = rt1011_bq_drc_coeff_put \ 1212d6e65bb7SShuming Fan } 1213d6e65bb7SShuming Fan 1214d6e65bb7SShuming Fan static int rt1011_r0_cali_get(struct snd_kcontrol *kcontrol, 1215d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1216d6e65bb7SShuming Fan { 12170922c7a5SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 12180922c7a5SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 12190922c7a5SShuming Fan 12200922c7a5SShuming Fan ucontrol->value.integer.value[0] = rt1011->cali_done; 1221d6e65bb7SShuming Fan 1222d6e65bb7SShuming Fan return 0; 1223d6e65bb7SShuming Fan } 1224d6e65bb7SShuming Fan 1225d6e65bb7SShuming Fan static int rt1011_r0_cali_put(struct snd_kcontrol *kcontrol, 1226d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1227d6e65bb7SShuming Fan { 1228d6e65bb7SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 1229d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1230d6e65bb7SShuming Fan 12310922c7a5SShuming Fan rt1011->cali_done = 0; 1232d6e65bb7SShuming Fan if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF && 1233d6e65bb7SShuming Fan ucontrol->value.integer.value[0]) 1234d6e65bb7SShuming Fan rt1011_calibrate(rt1011, 1); 1235d6e65bb7SShuming Fan 1236d6e65bb7SShuming Fan return 0; 1237d6e65bb7SShuming Fan } 1238d6e65bb7SShuming Fan 1239d6e65bb7SShuming Fan static int rt1011_r0_load(struct rt1011_priv *rt1011) 1240d6e65bb7SShuming Fan { 1241d6e65bb7SShuming Fan if (!rt1011->r0_reg) 1242d6e65bb7SShuming Fan return -EINVAL; 1243d6e65bb7SShuming Fan 1244d6e65bb7SShuming Fan /* write R0 to register */ 1245d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_24_16, 1246d6e65bb7SShuming Fan ((rt1011->r0_reg>>16) & 0x1ff)); 1247d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_15_0, 1248d6e65bb7SShuming Fan (rt1011->r0_reg & 0xffff)); 1249d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4080); 1250d6e65bb7SShuming Fan 1251d6e65bb7SShuming Fan return 0; 1252d6e65bb7SShuming Fan } 1253d6e65bb7SShuming Fan 1254d6e65bb7SShuming Fan static int rt1011_r0_load_mode_get(struct snd_kcontrol *kcontrol, 1255d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1256d6e65bb7SShuming Fan { 1257d6e65bb7SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 1258d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1259d6e65bb7SShuming Fan 1260d6e65bb7SShuming Fan ucontrol->value.integer.value[0] = rt1011->r0_reg; 1261d6e65bb7SShuming Fan 1262d6e65bb7SShuming Fan return 0; 1263d6e65bb7SShuming Fan } 1264d6e65bb7SShuming Fan 1265d6e65bb7SShuming Fan static int rt1011_r0_load_mode_put(struct snd_kcontrol *kcontrol, 1266d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol) 1267d6e65bb7SShuming Fan { 1268d6e65bb7SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 1269d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1270d6e65bb7SShuming Fan struct device *dev; 1271d6e65bb7SShuming Fan unsigned int r0_integer, r0_factor, format; 1272d6e65bb7SShuming Fan 1273d6e65bb7SShuming Fan if (ucontrol->value.integer.value[0] == rt1011->r0_reg) 1274d6e65bb7SShuming Fan return 0; 1275d6e65bb7SShuming Fan 127664429a87SShuming Fan if (ucontrol->value.integer.value[0] == 0) 127764429a87SShuming Fan return -EINVAL; 127864429a87SShuming Fan 1279d6e65bb7SShuming Fan dev = regmap_get_device(rt1011->regmap); 1280d6e65bb7SShuming Fan if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { 1281d6e65bb7SShuming Fan rt1011->r0_reg = ucontrol->value.integer.value[0]; 1282d6e65bb7SShuming Fan 128383a6edbbSNathan Chancellor format = 2147483648U; /* 2^24 * 128 */ 1284d6e65bb7SShuming Fan r0_integer = format / rt1011->r0_reg / 128; 1285d6e65bb7SShuming Fan r0_factor = ((format / rt1011->r0_reg * 100) / 128) 1286d6e65bb7SShuming Fan - (r0_integer * 100); 1287d6e65bb7SShuming Fan dev_info(dev, "New r0 resistance about %d.%02d ohm, reg=0x%X\n", 1288d6e65bb7SShuming Fan r0_integer, r0_factor, rt1011->r0_reg); 1289d6e65bb7SShuming Fan 1290d6e65bb7SShuming Fan if (rt1011->r0_reg) 1291d6e65bb7SShuming Fan rt1011_r0_load(rt1011); 1292d6e65bb7SShuming Fan } 1293d6e65bb7SShuming Fan 1294d6e65bb7SShuming Fan return 0; 1295d6e65bb7SShuming Fan } 1296d6e65bb7SShuming Fan 1297d6e65bb7SShuming Fan static int rt1011_r0_load_info(struct snd_kcontrol *kcontrol, 1298d6e65bb7SShuming Fan struct snd_ctl_elem_info *uinfo) 1299d6e65bb7SShuming Fan { 1300d6e65bb7SShuming Fan uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1301d6e65bb7SShuming Fan uinfo->count = 1; 1302d6e65bb7SShuming Fan uinfo->value.integer.max = 0x1ffffff; 1303d6e65bb7SShuming Fan 1304d6e65bb7SShuming Fan return 0; 1305d6e65bb7SShuming Fan } 1306d6e65bb7SShuming Fan 1307d6e65bb7SShuming Fan #define RT1011_R0_LOAD(xname) \ 1308d6e65bb7SShuming Fan { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 1309d6e65bb7SShuming Fan .info = rt1011_r0_load_info, \ 1310d6e65bb7SShuming Fan .get = rt1011_r0_load_mode_get, \ 1311d6e65bb7SShuming Fan .put = rt1011_r0_load_mode_put \ 1312d6e65bb7SShuming Fan } 1313d6e65bb7SShuming Fan 1314d6e65bb7SShuming Fan static const struct snd_kcontrol_new rt1011_snd_controls[] = { 1315d6e65bb7SShuming Fan /* I2S Data In Selection */ 1316d6e65bb7SShuming Fan SOC_ENUM("DIN Source", rt1011_din_source_enum), 1317d6e65bb7SShuming Fan 1318d6e65bb7SShuming Fan /* TDM Data In Selection */ 1319d6e65bb7SShuming Fan SOC_ENUM("TDM1 DIN Source", rt1011_tdm1_l_dac1_enum), 1320d6e65bb7SShuming Fan SOC_ENUM("TDM2 DIN Source", rt1011_tdm2_l_dac1_enum), 1321d6e65bb7SShuming Fan 1322d6e65bb7SShuming Fan /* TDM1 Data Out Selection */ 1323d6e65bb7SShuming Fan SOC_ENUM("TDM1 DOUT Source", rt1011_tdm1_adc1_dat_enum), 1324d6e65bb7SShuming Fan SOC_ENUM("TDM1 DOUT Location", rt1011_tdm1_adc1_loc_enum), 13253403b808SShuming Fan SOC_ENUM("TDM1 ADC1DAT Swap Select", rt1011_tdm_adc1_1_enum), 13263403b808SShuming Fan SOC_ENUM("TDM1 ADC2DAT Swap Select", rt1011_tdm_adc2_1_enum), 1327d6e65bb7SShuming Fan 1328d6e65bb7SShuming Fan /* Data Out Mode */ 1329d6e65bb7SShuming Fan SOC_ENUM("I2S ADC DOUT Mode", rt1011_adc_dout_mode_enum), 1330d6e65bb7SShuming Fan SOC_ENUM("TDM1 DOUT Length", rt1011_tdm1_dout_len_enum), 1331d6e65bb7SShuming Fan SOC_ENUM("TDM2 DOUT Length", rt1011_tdm2_dout_len_enum), 1332d6e65bb7SShuming Fan 1333d6e65bb7SShuming Fan /* Speaker/Receiver Mode */ 1334d6e65bb7SShuming Fan SOC_SINGLE_EXT("RECV SPK Mode", SND_SOC_NOPM, 0, 1, 0, 1335d6e65bb7SShuming Fan rt1011_recv_spk_mode_get, rt1011_recv_spk_mode_put), 1336d6e65bb7SShuming Fan 1337d6e65bb7SShuming Fan /* BiQuad/DRC/SmartBoost Settings */ 1338d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode Initial Set"), 1339d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode SEP BQ Coeff"), 1340d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode EQ BQ Coeff"), 1341d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode BQ UI Coeff"), 1342d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode SmartBoost Coeff"), 1343d6e65bb7SShuming Fan 1344d6e65bb7SShuming Fan /* R0 */ 1345d6e65bb7SShuming Fan SOC_SINGLE_EXT("R0 Calibration", SND_SOC_NOPM, 0, 1, 0, 1346d6e65bb7SShuming Fan rt1011_r0_cali_get, rt1011_r0_cali_put), 1347d6e65bb7SShuming Fan RT1011_R0_LOAD("R0 Load Mode"), 13483403b808SShuming Fan 13493403b808SShuming Fan /* R0 temperature */ 13503403b808SShuming Fan SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP, 13513403b808SShuming Fan 2, 255, 0), 1352d6e65bb7SShuming Fan }; 1353d6e65bb7SShuming Fan 1354d6e65bb7SShuming Fan static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 1355d6e65bb7SShuming Fan struct snd_soc_dapm_widget *sink) 1356d6e65bb7SShuming Fan { 1357d6e65bb7SShuming Fan struct snd_soc_component *component = 1358d6e65bb7SShuming Fan snd_soc_dapm_to_component(source->dapm); 1359d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1360d6e65bb7SShuming Fan 1361d6e65bb7SShuming Fan if (rt1011->sysclk_src == RT1011_FS_SYS_PRE_S_PLL1) 1362d6e65bb7SShuming Fan return 1; 1363d6e65bb7SShuming Fan else 1364d6e65bb7SShuming Fan return 0; 1365d6e65bb7SShuming Fan } 1366d6e65bb7SShuming Fan 1367d6e65bb7SShuming Fan static int rt1011_dac_event(struct snd_soc_dapm_widget *w, 1368d6e65bb7SShuming Fan struct snd_kcontrol *kcontrol, int event) 1369d6e65bb7SShuming Fan { 1370d6e65bb7SShuming Fan struct snd_soc_component *component = 1371d6e65bb7SShuming Fan snd_soc_dapm_to_component(w->dapm); 1372d6e65bb7SShuming Fan 1373d6e65bb7SShuming Fan switch (event) { 1374d6e65bb7SShuming Fan case SND_SOC_DAPM_POST_PMU: 1375d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1376d6e65bb7SShuming Fan RT1011_SPK_TEMP_PROTECT_0, 1377d6e65bb7SShuming Fan RT1011_STP_EN_MASK | RT1011_STP_RS_CLB_EN_MASK, 1378d6e65bb7SShuming Fan RT1011_STP_EN | RT1011_STP_RS_CLB_EN); 1379d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_POWER_9, 1380d6e65bb7SShuming Fan RT1011_POW_MNL_SDB_MASK, RT1011_POW_MNL_SDB); 1381d6e65bb7SShuming Fan msleep(50); 1382d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1383d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1, 1384d6e65bb7SShuming Fan RT1011_DRIVER_READY_SPK, RT1011_DRIVER_READY_SPK); 1385d6e65bb7SShuming Fan break; 1386d6e65bb7SShuming Fan case SND_SOC_DAPM_PRE_PMD: 1387d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_POWER_9, 1388d6e65bb7SShuming Fan RT1011_POW_MNL_SDB_MASK, 0); 1389d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1390d6e65bb7SShuming Fan RT1011_SPK_TEMP_PROTECT_0, 1391d6e65bb7SShuming Fan RT1011_STP_EN_MASK | RT1011_STP_RS_CLB_EN_MASK, 0); 1392d6e65bb7SShuming Fan msleep(200); 1393d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1394d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1, 1395d6e65bb7SShuming Fan RT1011_DRIVER_READY_SPK, 0); 1396d6e65bb7SShuming Fan break; 1397d6e65bb7SShuming Fan 1398d6e65bb7SShuming Fan default: 1399d6e65bb7SShuming Fan return 0; 1400d6e65bb7SShuming Fan } 1401d6e65bb7SShuming Fan 1402d6e65bb7SShuming Fan return 0; 1403d6e65bb7SShuming Fan } 1404d6e65bb7SShuming Fan 1405d6e65bb7SShuming Fan 1406d6e65bb7SShuming Fan static const struct snd_soc_dapm_widget rt1011_dapm_widgets[] = { 1407d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("LDO2", RT1011_POWER_1, 1408d6e65bb7SShuming Fan RT1011_POW_LDO2_BIT, 0, NULL, 0), 1409d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ISENSE SPK", RT1011_POWER_1, 1410d6e65bb7SShuming Fan RT1011_POW_ISENSE_SPK_BIT, 0, NULL, 0), 1411d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("VSENSE SPK", RT1011_POWER_1, 1412d6e65bb7SShuming Fan RT1011_POW_VSENSE_SPK_BIT, 0, NULL, 0), 1413d6e65bb7SShuming Fan 1414d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("PLL", RT1011_POWER_2, 1415d6e65bb7SShuming Fan RT1011_PLLEN_BIT, 0, NULL, 0), 1416d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BG", RT1011_POWER_2, 1417d6e65bb7SShuming Fan RT1011_POW_BG_BIT, 0, NULL, 0), 1418d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BG MBIAS", RT1011_POWER_2, 1419d6e65bb7SShuming Fan RT1011_POW_BG_MBIAS_LV_BIT, 0, NULL, 0), 1420d6e65bb7SShuming Fan 1421d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("DET VBAT", RT1011_POWER_3, 1422d6e65bb7SShuming Fan RT1011_POW_DET_VBAT_BIT, 0, NULL, 0), 1423d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MBIAS", RT1011_POWER_3, 1424d6e65bb7SShuming Fan RT1011_POW_MBIAS_LV_BIT, 0, NULL, 0), 1425d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ADC I", RT1011_POWER_3, 1426d6e65bb7SShuming Fan RT1011_POW_ADC_I_BIT, 0, NULL, 0), 1427d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ADC V", RT1011_POWER_3, 1428d6e65bb7SShuming Fan RT1011_POW_ADC_V_BIT, 0, NULL, 0), 1429d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ADC T", RT1011_POWER_3, 1430d6e65bb7SShuming Fan RT1011_POW_ADC_T_BIT, 0, NULL, 0), 1431d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("DITHER ADC T", RT1011_POWER_3, 1432d6e65bb7SShuming Fan RT1011_POWD_ADC_T_BIT, 0, NULL, 0), 1433d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MIX I", RT1011_POWER_3, 1434d6e65bb7SShuming Fan RT1011_POW_MIX_I_BIT, 0, NULL, 0), 1435d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MIX V", RT1011_POWER_3, 1436d6e65bb7SShuming Fan RT1011_POW_MIX_V_BIT, 0, NULL, 0), 1437d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("SUM I", RT1011_POWER_3, 1438d6e65bb7SShuming Fan RT1011_POW_SUM_I_BIT, 0, NULL, 0), 1439d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("SUM V", RT1011_POWER_3, 1440d6e65bb7SShuming Fan RT1011_POW_SUM_V_BIT, 0, NULL, 0), 1441d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MIX T", RT1011_POWER_3, 1442d6e65bb7SShuming Fan RT1011_POW_MIX_T_BIT, 0, NULL, 0), 1443d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("VREF", RT1011_POWER_3, 1444d6e65bb7SShuming Fan RT1011_POW_VREF_LV_BIT, 0, NULL, 0), 1445d6e65bb7SShuming Fan 1446d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BOOST SWR", RT1011_POWER_4, 1447d6e65bb7SShuming Fan RT1011_POW_EN_SWR_BIT, 0, NULL, 0), 1448d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BGOK SWR", RT1011_POWER_4, 1449d6e65bb7SShuming Fan RT1011_POW_EN_PASS_BGOK_SWR_BIT, 0, NULL, 0), 1450d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("VPOK SWR", RT1011_POWER_4, 1451d6e65bb7SShuming Fan RT1011_POW_EN_PASS_VPOK_SWR_BIT, 0, NULL, 0), 1452d6e65bb7SShuming Fan 1453d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("TEMP REG", RT1011_A_TEMP_SEN, 1454d6e65bb7SShuming Fan RT1011_POW_TEMP_REG_BIT, 0, NULL, 0), 1455d6e65bb7SShuming Fan 1456d6e65bb7SShuming Fan /* Audio Interface */ 1457d6e65bb7SShuming Fan SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 1458d6e65bb7SShuming Fan /* Digital Interface */ 1459d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("DAC Power", RT1011_POWER_1, 1460d6e65bb7SShuming Fan RT1011_POW_DAC_BIT, 0, NULL, 0), 1461d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("CLK12M", RT1011_POWER_1, 1462d6e65bb7SShuming Fan RT1011_POW_CLK12M_BIT, 0, NULL, 0), 1463d6e65bb7SShuming Fan SND_SOC_DAPM_DAC_E("DAC", NULL, RT1011_DAC_SET_3, 1464d6e65bb7SShuming Fan RT1011_DA_MUTE_EN_SFT, 1, rt1011_dac_event, 1465d6e65bb7SShuming Fan SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1466d6e65bb7SShuming Fan 1467d6e65bb7SShuming Fan /* Output Lines */ 1468d6e65bb7SShuming Fan SND_SOC_DAPM_OUTPUT("SPO"), 1469d6e65bb7SShuming Fan }; 1470d6e65bb7SShuming Fan 1471d6e65bb7SShuming Fan static const struct snd_soc_dapm_route rt1011_dapm_routes[] = { 1472d6e65bb7SShuming Fan 1473d6e65bb7SShuming Fan { "DAC", NULL, "AIF1RX" }, 1474d6e65bb7SShuming Fan { "DAC", NULL, "DAC Power" }, 1475d6e65bb7SShuming Fan { "DAC", NULL, "LDO2" }, 1476d6e65bb7SShuming Fan { "DAC", NULL, "ISENSE SPK" }, 1477d6e65bb7SShuming Fan { "DAC", NULL, "VSENSE SPK" }, 1478d6e65bb7SShuming Fan { "DAC", NULL, "CLK12M" }, 1479d6e65bb7SShuming Fan 1480d6e65bb7SShuming Fan { "DAC", NULL, "PLL", rt1011_is_sys_clk_from_pll }, 1481d6e65bb7SShuming Fan { "DAC", NULL, "BG" }, 1482d6e65bb7SShuming Fan { "DAC", NULL, "BG MBIAS" }, 1483d6e65bb7SShuming Fan 1484d6e65bb7SShuming Fan { "DAC", NULL, "BOOST SWR" }, 1485d6e65bb7SShuming Fan { "DAC", NULL, "BGOK SWR" }, 1486d6e65bb7SShuming Fan { "DAC", NULL, "VPOK SWR" }, 1487d6e65bb7SShuming Fan 1488d6e65bb7SShuming Fan { "DAC", NULL, "DET VBAT" }, 1489d6e65bb7SShuming Fan { "DAC", NULL, "MBIAS" }, 1490d6e65bb7SShuming Fan { "DAC", NULL, "VREF" }, 1491d6e65bb7SShuming Fan { "DAC", NULL, "ADC I" }, 1492d6e65bb7SShuming Fan { "DAC", NULL, "ADC V" }, 1493d6e65bb7SShuming Fan { "DAC", NULL, "ADC T" }, 1494d6e65bb7SShuming Fan { "DAC", NULL, "DITHER ADC T" }, 1495d6e65bb7SShuming Fan { "DAC", NULL, "MIX I" }, 1496d6e65bb7SShuming Fan { "DAC", NULL, "MIX V" }, 1497d6e65bb7SShuming Fan { "DAC", NULL, "SUM I" }, 1498d6e65bb7SShuming Fan { "DAC", NULL, "SUM V" }, 1499d6e65bb7SShuming Fan { "DAC", NULL, "MIX T" }, 1500d6e65bb7SShuming Fan 1501d6e65bb7SShuming Fan { "DAC", NULL, "TEMP REG" }, 1502d6e65bb7SShuming Fan 1503d6e65bb7SShuming Fan { "SPO", NULL, "DAC" }, 1504d6e65bb7SShuming Fan }; 1505d6e65bb7SShuming Fan 1506d6e65bb7SShuming Fan static int rt1011_get_clk_info(int sclk, int rate) 1507d6e65bb7SShuming Fan { 15082b70d577SColin Ian King int i; 15092b70d577SColin Ian King static const int pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; 1510d6e65bb7SShuming Fan 1511d6e65bb7SShuming Fan if (sclk <= 0 || rate <= 0) 1512d6e65bb7SShuming Fan return -EINVAL; 1513d6e65bb7SShuming Fan 1514d6e65bb7SShuming Fan rate = rate << 8; 1515d6e65bb7SShuming Fan for (i = 0; i < ARRAY_SIZE(pd); i++) 1516d6e65bb7SShuming Fan if (sclk == rate * pd[i]) 1517d6e65bb7SShuming Fan return i; 1518d6e65bb7SShuming Fan 1519d6e65bb7SShuming Fan return -EINVAL; 1520d6e65bb7SShuming Fan } 1521d6e65bb7SShuming Fan 1522d6e65bb7SShuming Fan static int rt1011_hw_params(struct snd_pcm_substream *substream, 1523d6e65bb7SShuming Fan struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 1524d6e65bb7SShuming Fan { 1525d6e65bb7SShuming Fan struct snd_soc_component *component = dai->component; 1526d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1527d6e65bb7SShuming Fan unsigned int val_len = 0, ch_len = 0, val_clk, mask_clk; 1528d6e65bb7SShuming Fan int pre_div, bclk_ms, frame_size; 1529d6e65bb7SShuming Fan 1530d6e65bb7SShuming Fan rt1011->lrck = params_rate(params); 1531d6e65bb7SShuming Fan pre_div = rt1011_get_clk_info(rt1011->sysclk, rt1011->lrck); 1532d6e65bb7SShuming Fan if (pre_div < 0) { 1533d6e65bb7SShuming Fan dev_warn(component->dev, "Force using PLL "); 1534d6e65bb7SShuming Fan snd_soc_dai_set_pll(dai, 0, RT1011_PLL1_S_BCLK, 1535d6e65bb7SShuming Fan rt1011->lrck * 64, rt1011->lrck * 256); 1536d6e65bb7SShuming Fan snd_soc_dai_set_sysclk(dai, RT1011_FS_SYS_PRE_S_PLL1, 1537d6e65bb7SShuming Fan rt1011->lrck * 256, SND_SOC_CLOCK_IN); 1538d6e65bb7SShuming Fan pre_div = 0; 1539d6e65bb7SShuming Fan } 1540d6e65bb7SShuming Fan frame_size = snd_soc_params_to_frame_size(params); 1541d6e65bb7SShuming Fan if (frame_size < 0) { 1542d6e65bb7SShuming Fan dev_err(component->dev, "Unsupported frame size: %d\n", 1543d6e65bb7SShuming Fan frame_size); 1544d6e65bb7SShuming Fan return -EINVAL; 1545d6e65bb7SShuming Fan } 1546d6e65bb7SShuming Fan 1547d6e65bb7SShuming Fan bclk_ms = frame_size > 32; 1548d6e65bb7SShuming Fan rt1011->bclk = rt1011->lrck * (32 << bclk_ms); 1549d6e65bb7SShuming Fan 1550d6e65bb7SShuming Fan dev_dbg(component->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", 1551d6e65bb7SShuming Fan bclk_ms, pre_div, dai->id); 1552d6e65bb7SShuming Fan 1553d6e65bb7SShuming Fan dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d\n", 1554d6e65bb7SShuming Fan rt1011->lrck, pre_div, dai->id); 1555d6e65bb7SShuming Fan 1556d6e65bb7SShuming Fan switch (params_width(params)) { 1557d6e65bb7SShuming Fan case 16: 1558d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_16B; 1559d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_16B; 1560d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_16B; 1561d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_16B; 1562d6e65bb7SShuming Fan break; 1563d6e65bb7SShuming Fan case 20: 1564d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_20B; 1565d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_20B; 1566d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_20B; 1567d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_20B; 1568d6e65bb7SShuming Fan break; 1569d6e65bb7SShuming Fan case 24: 1570d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_24B; 1571d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_24B; 1572d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_24B; 1573d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_24B; 1574d6e65bb7SShuming Fan break; 1575d6e65bb7SShuming Fan case 32: 1576d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_32B; 1577d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_32B; 1578d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_32B; 1579d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_32B; 1580d6e65bb7SShuming Fan break; 1581d6e65bb7SShuming Fan case 8: 1582d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_8B; 1583d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_8B; 1584d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_8B; 1585d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_8B; 1586d6e65bb7SShuming Fan break; 1587d6e65bb7SShuming Fan default: 1588d6e65bb7SShuming Fan return -EINVAL; 1589d6e65bb7SShuming Fan } 1590d6e65bb7SShuming Fan 1591d6e65bb7SShuming Fan switch (dai->id) { 1592d6e65bb7SShuming Fan case RT1011_AIF1: 1593d6e65bb7SShuming Fan mask_clk = RT1011_FS_SYS_DIV_MASK; 1594d6e65bb7SShuming Fan val_clk = pre_div << RT1011_FS_SYS_DIV_SFT; 1595d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET, 1596d6e65bb7SShuming Fan RT1011_I2S_TX_DL_MASK | RT1011_I2S_RX_DL_MASK, 1597d6e65bb7SShuming Fan val_len); 1598d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_1, 1599d6e65bb7SShuming Fan RT1011_I2S_CH_TX_LEN_MASK | 1600d6e65bb7SShuming Fan RT1011_I2S_CH_RX_LEN_MASK, 1601d6e65bb7SShuming Fan ch_len); 1602d6e65bb7SShuming Fan break; 1603d6e65bb7SShuming Fan default: 1604d6e65bb7SShuming Fan dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 1605d6e65bb7SShuming Fan return -EINVAL; 1606d6e65bb7SShuming Fan } 1607d6e65bb7SShuming Fan 1608d6e65bb7SShuming Fan snd_soc_component_update_bits(component, 1609d6e65bb7SShuming Fan RT1011_CLK_2, mask_clk, val_clk); 1610d6e65bb7SShuming Fan 1611d6e65bb7SShuming Fan return 0; 1612d6e65bb7SShuming Fan } 1613d6e65bb7SShuming Fan 1614d6e65bb7SShuming Fan static int rt1011_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 1615d6e65bb7SShuming Fan { 1616d6e65bb7SShuming Fan struct snd_soc_component *component = dai->component; 1617e9e897d5SShuming Fan struct snd_soc_dapm_context *dapm = 1618e9e897d5SShuming Fan snd_soc_component_get_dapm(component); 1619d6e65bb7SShuming Fan unsigned int reg_val = 0, reg_bclk_inv = 0; 1620e9e897d5SShuming Fan int ret = 0; 1621d6e65bb7SShuming Fan 1622e9e897d5SShuming Fan snd_soc_dapm_mutex_lock(dapm); 1623d6e65bb7SShuming Fan switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1624d6e65bb7SShuming Fan case SND_SOC_DAIFMT_CBS_CFS: 1625d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_MS_S; 1626d6e65bb7SShuming Fan break; 1627d6e65bb7SShuming Fan default: 1628e9e897d5SShuming Fan ret = -EINVAL; 16295cf93491SShuming Fan goto _set_fmt_err_; 1630d6e65bb7SShuming Fan } 1631d6e65bb7SShuming Fan 1632d6e65bb7SShuming Fan switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 1633d6e65bb7SShuming Fan case SND_SOC_DAIFMT_NB_NF: 1634d6e65bb7SShuming Fan break; 1635d6e65bb7SShuming Fan case SND_SOC_DAIFMT_IB_NF: 1636d6e65bb7SShuming Fan reg_bclk_inv |= RT1011_TDM_INV_BCLK; 1637d6e65bb7SShuming Fan break; 1638d6e65bb7SShuming Fan default: 1639e9e897d5SShuming Fan ret = -EINVAL; 16405cf93491SShuming Fan goto _set_fmt_err_; 1641d6e65bb7SShuming Fan } 1642d6e65bb7SShuming Fan 1643d6e65bb7SShuming Fan switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 1644d6e65bb7SShuming Fan case SND_SOC_DAIFMT_I2S: 1645d6e65bb7SShuming Fan break; 1646d6e65bb7SShuming Fan case SND_SOC_DAIFMT_LEFT_J: 1647d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_DF_LEFT; 1648d6e65bb7SShuming Fan break; 1649d6e65bb7SShuming Fan case SND_SOC_DAIFMT_DSP_A: 1650d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_DF_PCM_A; 1651d6e65bb7SShuming Fan break; 1652d6e65bb7SShuming Fan case SND_SOC_DAIFMT_DSP_B: 1653d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_DF_PCM_B; 1654d6e65bb7SShuming Fan break; 1655d6e65bb7SShuming Fan default: 1656e9e897d5SShuming Fan ret = -EINVAL; 16575cf93491SShuming Fan goto _set_fmt_err_; 1658d6e65bb7SShuming Fan } 1659d6e65bb7SShuming Fan 1660d6e65bb7SShuming Fan switch (dai->id) { 1661d6e65bb7SShuming Fan case RT1011_AIF1: 1662d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET, 1663d6e65bb7SShuming Fan RT1011_I2S_TDM_MS_MASK | RT1011_I2S_TDM_DF_MASK, 1664d6e65bb7SShuming Fan reg_val); 1665d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_1, 1666d6e65bb7SShuming Fan RT1011_TDM_INV_BCLK_MASK, reg_bclk_inv); 1667d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM2_SET_1, 1668d6e65bb7SShuming Fan RT1011_TDM_INV_BCLK_MASK, reg_bclk_inv); 1669d6e65bb7SShuming Fan break; 1670d6e65bb7SShuming Fan default: 1671d6e65bb7SShuming Fan dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 1672e9e897d5SShuming Fan ret = -EINVAL; 1673d6e65bb7SShuming Fan } 1674e9e897d5SShuming Fan 16755cf93491SShuming Fan _set_fmt_err_: 1676e9e897d5SShuming Fan snd_soc_dapm_mutex_unlock(dapm); 1677e9e897d5SShuming Fan return ret; 1678d6e65bb7SShuming Fan } 1679d6e65bb7SShuming Fan 1680d6e65bb7SShuming Fan static int rt1011_set_component_sysclk(struct snd_soc_component *component, 1681d6e65bb7SShuming Fan int clk_id, int source, unsigned int freq, int dir) 1682d6e65bb7SShuming Fan { 1683d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1684d6e65bb7SShuming Fan unsigned int reg_val = 0; 1685d6e65bb7SShuming Fan 1686d6e65bb7SShuming Fan if (freq == rt1011->sysclk && clk_id == rt1011->sysclk_src) 1687d6e65bb7SShuming Fan return 0; 1688d6e65bb7SShuming Fan 1689d6e65bb7SShuming Fan /* disable MCLK detect in default */ 1690d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_DET, 1691d6e65bb7SShuming Fan RT1011_EN_MCLK_DET_MASK, 0); 1692d6e65bb7SShuming Fan 1693d6e65bb7SShuming Fan switch (clk_id) { 1694d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_MCLK: 1695d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_MCLK; 1696d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_DET, 1697d6e65bb7SShuming Fan RT1011_EN_MCLK_DET_MASK, RT1011_EN_MCLK_DET); 1698d6e65bb7SShuming Fan break; 1699d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_BCLK: 1700d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_BCLK; 1701d6e65bb7SShuming Fan break; 1702d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_PLL1: 1703d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_PLL1; 1704d6e65bb7SShuming Fan break; 1705d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_RCCLK: 1706d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_RCCLK; 1707d6e65bb7SShuming Fan break; 1708d6e65bb7SShuming Fan default: 1709d6e65bb7SShuming Fan dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); 1710d6e65bb7SShuming Fan return -EINVAL; 1711d6e65bb7SShuming Fan } 1712d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1713d6e65bb7SShuming Fan RT1011_FS_SYS_PRE_MASK, reg_val); 1714d6e65bb7SShuming Fan rt1011->sysclk = freq; 1715d6e65bb7SShuming Fan rt1011->sysclk_src = clk_id; 1716d6e65bb7SShuming Fan 1717d6e65bb7SShuming Fan dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", 1718d6e65bb7SShuming Fan freq, clk_id); 1719d6e65bb7SShuming Fan 1720d6e65bb7SShuming Fan return 0; 1721d6e65bb7SShuming Fan } 1722d6e65bb7SShuming Fan 1723d6e65bb7SShuming Fan static int rt1011_set_component_pll(struct snd_soc_component *component, 1724d6e65bb7SShuming Fan int pll_id, int source, unsigned int freq_in, 1725d6e65bb7SShuming Fan unsigned int freq_out) 1726d6e65bb7SShuming Fan { 1727d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 1728d6e65bb7SShuming Fan struct rl6231_pll_code pll_code; 1729d6e65bb7SShuming Fan int ret; 1730d6e65bb7SShuming Fan 1731d6e65bb7SShuming Fan if (source == rt1011->pll_src && freq_in == rt1011->pll_in && 1732d6e65bb7SShuming Fan freq_out == rt1011->pll_out) 1733d6e65bb7SShuming Fan return 0; 1734d6e65bb7SShuming Fan 1735d6e65bb7SShuming Fan if (!freq_in || !freq_out) { 1736d6e65bb7SShuming Fan dev_dbg(component->dev, "PLL disabled\n"); 1737d6e65bb7SShuming Fan 1738d6e65bb7SShuming Fan rt1011->pll_in = 0; 1739d6e65bb7SShuming Fan rt1011->pll_out = 0; 1740d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1741d6e65bb7SShuming Fan RT1011_FS_SYS_PRE_MASK, RT1011_FS_SYS_PRE_BCLK); 1742d6e65bb7SShuming Fan return 0; 1743d6e65bb7SShuming Fan } 1744d6e65bb7SShuming Fan 1745d6e65bb7SShuming Fan switch (source) { 1746d6e65bb7SShuming Fan case RT1011_PLL2_S_MCLK: 1747d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1748d6e65bb7SShuming Fan RT1011_PLL2_SRC_MASK, RT1011_PLL2_SRC_MCLK); 1749d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1750d6e65bb7SShuming Fan RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_PLL2); 1751d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_DET, 1752d6e65bb7SShuming Fan RT1011_EN_MCLK_DET_MASK, RT1011_EN_MCLK_DET); 1753d6e65bb7SShuming Fan break; 1754d6e65bb7SShuming Fan case RT1011_PLL1_S_BCLK: 1755d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1756d6e65bb7SShuming Fan RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_BCLK); 1757d6e65bb7SShuming Fan break; 1758d6e65bb7SShuming Fan case RT1011_PLL2_S_RCCLK: 1759d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1760d6e65bb7SShuming Fan RT1011_PLL2_SRC_MASK, RT1011_PLL2_SRC_RCCLK); 1761d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2, 1762d6e65bb7SShuming Fan RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_PLL2); 1763d6e65bb7SShuming Fan break; 1764d6e65bb7SShuming Fan default: 1765d6e65bb7SShuming Fan dev_err(component->dev, "Unknown PLL Source %d\n", source); 1766d6e65bb7SShuming Fan return -EINVAL; 1767d6e65bb7SShuming Fan } 1768d6e65bb7SShuming Fan 1769d6e65bb7SShuming Fan ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 1770d6e65bb7SShuming Fan if (ret < 0) { 1771683b8515SShuming Fan dev_err(component->dev, "Unsupported input clock %d\n", 1772683b8515SShuming Fan freq_in); 1773d6e65bb7SShuming Fan return ret; 1774d6e65bb7SShuming Fan } 1775d6e65bb7SShuming Fan 1776d6e65bb7SShuming Fan dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", 1777d6e65bb7SShuming Fan pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 1778d6e65bb7SShuming Fan pll_code.n_code, pll_code.k_code); 1779d6e65bb7SShuming Fan 1780d6e65bb7SShuming Fan snd_soc_component_write(component, RT1011_PLL_1, 1781*5a242992SPierre-Louis Bossart ((pll_code.m_bp ? 0 : pll_code.m_code) << RT1011_PLL1_QM_SFT) | 1782*5a242992SPierre-Louis Bossart (pll_code.m_bp << RT1011_PLL1_BPM_SFT) | 1783*5a242992SPierre-Louis Bossart pll_code.n_code); 1784d6e65bb7SShuming Fan snd_soc_component_write(component, RT1011_PLL_2, 1785d6e65bb7SShuming Fan pll_code.k_code); 1786d6e65bb7SShuming Fan 1787d6e65bb7SShuming Fan rt1011->pll_in = freq_in; 1788d6e65bb7SShuming Fan rt1011->pll_out = freq_out; 1789d6e65bb7SShuming Fan rt1011->pll_src = source; 1790d6e65bb7SShuming Fan 1791d6e65bb7SShuming Fan return 0; 1792d6e65bb7SShuming Fan } 1793d6e65bb7SShuming Fan 1794d6e65bb7SShuming Fan static int rt1011_set_tdm_slot(struct snd_soc_dai *dai, 1795d6e65bb7SShuming Fan unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 1796d6e65bb7SShuming Fan { 1797d6e65bb7SShuming Fan struct snd_soc_component *component = dai->component; 1798e9e897d5SShuming Fan struct snd_soc_dapm_context *dapm = 1799e9e897d5SShuming Fan snd_soc_component_get_dapm(component); 180081bd644fSShuming Fan unsigned int val = 0, tdm_en = 0, rx_slotnum, tx_slotnum; 180181bd644fSShuming Fan int ret = 0, first_bit, last_bit; 1802d6e65bb7SShuming Fan 1803e9e897d5SShuming Fan snd_soc_dapm_mutex_lock(dapm); 1804d6e65bb7SShuming Fan if (rx_mask || tx_mask) 1805d6e65bb7SShuming Fan tdm_en = RT1011_TDM_I2S_DOCK_EN_1; 1806d6e65bb7SShuming Fan 1807d6e65bb7SShuming Fan switch (slots) { 1808d6e65bb7SShuming Fan case 4: 1809d6e65bb7SShuming Fan val |= RT1011_I2S_TX_4CH; 1810d6e65bb7SShuming Fan val |= RT1011_I2S_RX_4CH; 1811d6e65bb7SShuming Fan break; 1812d6e65bb7SShuming Fan case 6: 1813d6e65bb7SShuming Fan val |= RT1011_I2S_TX_6CH; 1814d6e65bb7SShuming Fan val |= RT1011_I2S_RX_6CH; 1815d6e65bb7SShuming Fan break; 1816d6e65bb7SShuming Fan case 8: 1817d6e65bb7SShuming Fan val |= RT1011_I2S_TX_8CH; 1818d6e65bb7SShuming Fan val |= RT1011_I2S_RX_8CH; 1819d6e65bb7SShuming Fan break; 1820d6e65bb7SShuming Fan case 2: 1821d6e65bb7SShuming Fan break; 1822d6e65bb7SShuming Fan default: 1823e9e897d5SShuming Fan ret = -EINVAL; 182481bd644fSShuming Fan goto _set_tdm_err_; 1825d6e65bb7SShuming Fan } 1826d6e65bb7SShuming Fan 1827d6e65bb7SShuming Fan switch (slot_width) { 1828d6e65bb7SShuming Fan case 20: 1829d6e65bb7SShuming Fan val |= RT1011_I2S_CH_TX_LEN_20B; 1830d6e65bb7SShuming Fan val |= RT1011_I2S_CH_RX_LEN_20B; 1831d6e65bb7SShuming Fan break; 1832d6e65bb7SShuming Fan case 24: 1833d6e65bb7SShuming Fan val |= RT1011_I2S_CH_TX_LEN_24B; 1834d6e65bb7SShuming Fan val |= RT1011_I2S_CH_RX_LEN_24B; 1835d6e65bb7SShuming Fan break; 1836d6e65bb7SShuming Fan case 32: 1837d6e65bb7SShuming Fan val |= RT1011_I2S_CH_TX_LEN_32B; 1838d6e65bb7SShuming Fan val |= RT1011_I2S_CH_RX_LEN_32B; 1839d6e65bb7SShuming Fan break; 1840d6e65bb7SShuming Fan case 16: 1841d6e65bb7SShuming Fan break; 1842d6e65bb7SShuming Fan default: 1843e9e897d5SShuming Fan ret = -EINVAL; 184481bd644fSShuming Fan goto _set_tdm_err_; 184581bd644fSShuming Fan } 184681bd644fSShuming Fan 184781bd644fSShuming Fan /* Rx slot configuration */ 184881bd644fSShuming Fan rx_slotnum = hweight_long(rx_mask); 1849ee8a41cdSFred Oh if (rx_slotnum > 1 || !rx_slotnum) { 185081bd644fSShuming Fan ret = -EINVAL; 1851ee8a41cdSFred Oh dev_err(component->dev, "too many rx slots or zero slot\n"); 185281bd644fSShuming Fan goto _set_tdm_err_; 185381bd644fSShuming Fan } 185481bd644fSShuming Fan 1855ee8a41cdSFred Oh first_bit = __ffs(rx_mask); 185681bd644fSShuming Fan switch (first_bit) { 185781bd644fSShuming Fan case 0: 185881bd644fSShuming Fan case 2: 185981bd644fSShuming Fan case 4: 186081bd644fSShuming Fan case 6: 186181bd644fSShuming Fan snd_soc_component_update_bits(component, 186281bd644fSShuming Fan RT1011_CROSS_BQ_SET_1, RT1011_MONO_LR_SEL_MASK, 186381bd644fSShuming Fan RT1011_MONO_L_CHANNEL); 186481bd644fSShuming Fan snd_soc_component_update_bits(component, 186581bd644fSShuming Fan RT1011_TDM1_SET_4, 186681bd644fSShuming Fan RT1011_TDM_I2S_TX_L_DAC1_1_MASK | 186781bd644fSShuming Fan RT1011_TDM_I2S_TX_R_DAC1_1_MASK, 186881bd644fSShuming Fan (first_bit << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) | 186981bd644fSShuming Fan ((first_bit+1) << RT1011_TDM_I2S_TX_R_DAC1_1_SFT)); 187081bd644fSShuming Fan break; 187181bd644fSShuming Fan case 1: 187281bd644fSShuming Fan case 3: 187381bd644fSShuming Fan case 5: 187481bd644fSShuming Fan case 7: 187581bd644fSShuming Fan snd_soc_component_update_bits(component, 187681bd644fSShuming Fan RT1011_CROSS_BQ_SET_1, RT1011_MONO_LR_SEL_MASK, 187781bd644fSShuming Fan RT1011_MONO_R_CHANNEL); 187881bd644fSShuming Fan snd_soc_component_update_bits(component, 187981bd644fSShuming Fan RT1011_TDM1_SET_4, 188081bd644fSShuming Fan RT1011_TDM_I2S_TX_L_DAC1_1_MASK | 188181bd644fSShuming Fan RT1011_TDM_I2S_TX_R_DAC1_1_MASK, 188281bd644fSShuming Fan ((first_bit-1) << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) | 188381bd644fSShuming Fan (first_bit << RT1011_TDM_I2S_TX_R_DAC1_1_SFT)); 188481bd644fSShuming Fan break; 188581bd644fSShuming Fan default: 188681bd644fSShuming Fan ret = -EINVAL; 188781bd644fSShuming Fan goto _set_tdm_err_; 188881bd644fSShuming Fan } 188981bd644fSShuming Fan 189081bd644fSShuming Fan /* Tx slot configuration */ 189181bd644fSShuming Fan tx_slotnum = hweight_long(tx_mask); 1892ee8a41cdSFred Oh if (tx_slotnum > 2 || !tx_slotnum) { 189381bd644fSShuming Fan ret = -EINVAL; 1894ee8a41cdSFred Oh dev_err(component->dev, "too many tx slots or zero slot\n"); 1895ee8a41cdSFred Oh goto _set_tdm_err_; 1896ee8a41cdSFred Oh } 1897ee8a41cdSFred Oh 1898ee8a41cdSFred Oh first_bit = __ffs(tx_mask); 1899ee8a41cdSFred Oh last_bit = __fls(tx_mask); 1900ee8a41cdSFred Oh if (last_bit - first_bit > 1) { 1901ee8a41cdSFred Oh ret = -EINVAL; 1902ee8a41cdSFred Oh dev_err(component->dev, "tx slot location error\n"); 190381bd644fSShuming Fan goto _set_tdm_err_; 190481bd644fSShuming Fan } 190581bd644fSShuming Fan 190681bd644fSShuming Fan if (tx_slotnum == 1) { 190781bd644fSShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_2, 190881bd644fSShuming Fan RT1011_TDM_I2S_DOCK_ADCDAT_LEN_1_MASK | 190981bd644fSShuming Fan RT1011_TDM_ADCDAT1_DATA_LOCATION, first_bit); 191081bd644fSShuming Fan switch (first_bit) { 191181bd644fSShuming Fan case 1: 191281bd644fSShuming Fan snd_soc_component_update_bits(component, 191381bd644fSShuming Fan RT1011_TDM1_SET_3, 191481bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC1_1_MASK, 191581bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC1_1_LL); 191681bd644fSShuming Fan break; 191781bd644fSShuming Fan case 3: 191881bd644fSShuming Fan snd_soc_component_update_bits(component, 191981bd644fSShuming Fan RT1011_TDM1_SET_3, 192081bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC2_1_MASK, 192181bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC2_1_LL); 192281bd644fSShuming Fan break; 192381bd644fSShuming Fan case 5: 192481bd644fSShuming Fan snd_soc_component_update_bits(component, 192581bd644fSShuming Fan RT1011_TDM1_SET_3, 192681bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC3_1_MASK, 192781bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC3_1_LL); 192881bd644fSShuming Fan break; 192981bd644fSShuming Fan case 7: 193081bd644fSShuming Fan snd_soc_component_update_bits(component, 193181bd644fSShuming Fan RT1011_TDM1_SET_3, 193281bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC4_1_MASK, 193381bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC4_1_LL); 193481bd644fSShuming Fan break; 193581bd644fSShuming Fan case 0: 193681bd644fSShuming Fan snd_soc_component_update_bits(component, 193781bd644fSShuming Fan RT1011_TDM1_SET_3, 193881bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC1_1_MASK, 0); 193981bd644fSShuming Fan break; 194081bd644fSShuming Fan case 2: 194181bd644fSShuming Fan snd_soc_component_update_bits(component, 194281bd644fSShuming Fan RT1011_TDM1_SET_3, 194381bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC2_1_MASK, 0); 194481bd644fSShuming Fan break; 194581bd644fSShuming Fan case 4: 194681bd644fSShuming Fan snd_soc_component_update_bits(component, 194781bd644fSShuming Fan RT1011_TDM1_SET_3, 194881bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC3_1_MASK, 0); 194981bd644fSShuming Fan break; 195081bd644fSShuming Fan case 6: 195181bd644fSShuming Fan snd_soc_component_update_bits(component, 195281bd644fSShuming Fan RT1011_TDM1_SET_3, 195381bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC4_1_MASK, 0); 195481bd644fSShuming Fan break; 195581bd644fSShuming Fan default: 195681bd644fSShuming Fan ret = -EINVAL; 195781bd644fSShuming Fan dev_dbg(component->dev, 195881bd644fSShuming Fan "tx slot location error\n"); 195981bd644fSShuming Fan goto _set_tdm_err_; 196081bd644fSShuming Fan } 196181bd644fSShuming Fan } else if (tx_slotnum == 2) { 196281bd644fSShuming Fan switch (first_bit) { 196381bd644fSShuming Fan case 0: 196481bd644fSShuming Fan case 2: 196581bd644fSShuming Fan case 4: 196681bd644fSShuming Fan case 6: 196781bd644fSShuming Fan snd_soc_component_update_bits(component, 196881bd644fSShuming Fan RT1011_TDM1_SET_2, 196981bd644fSShuming Fan RT1011_TDM_I2S_DOCK_ADCDAT_LEN_1_MASK | 197081bd644fSShuming Fan RT1011_TDM_ADCDAT1_DATA_LOCATION, 197181bd644fSShuming Fan RT1011_TDM_I2S_DOCK_ADCDAT_2CH | first_bit); 197281bd644fSShuming Fan break; 197381bd644fSShuming Fan default: 197481bd644fSShuming Fan ret = -EINVAL; 197581bd644fSShuming Fan dev_dbg(component->dev, 197681bd644fSShuming Fan "tx slot location should be paired and start from slot0/2/4/6\n"); 197781bd644fSShuming Fan goto _set_tdm_err_; 197881bd644fSShuming Fan } 1979d6e65bb7SShuming Fan } 1980d6e65bb7SShuming Fan 1981d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_1, 1982d6e65bb7SShuming Fan RT1011_I2S_CH_TX_MASK | RT1011_I2S_CH_RX_MASK | 1983d6e65bb7SShuming Fan RT1011_I2S_CH_TX_LEN_MASK | RT1011_I2S_CH_RX_LEN_MASK, val); 1984d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM2_SET_1, 1985d6e65bb7SShuming Fan RT1011_I2S_CH_TX_MASK | RT1011_I2S_CH_RX_MASK | 1986d6e65bb7SShuming Fan RT1011_I2S_CH_TX_LEN_MASK | RT1011_I2S_CH_RX_LEN_MASK, val); 1987d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_2, 1988d6e65bb7SShuming Fan RT1011_TDM_I2S_DOCK_EN_1_MASK, tdm_en); 1989d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM2_SET_2, 1990d6e65bb7SShuming Fan RT1011_TDM_I2S_DOCK_EN_2_MASK, tdm_en); 19917e66f162SPierre-Louis Bossart 1992d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET, 1993d6e65bb7SShuming Fan RT1011_ADCDAT1_PIN_CONFIG | RT1011_ADCDAT2_PIN_CONFIG, 1994d6e65bb7SShuming Fan RT1011_ADCDAT1_OUTPUT | RT1011_ADCDAT2_OUTPUT); 1995d6e65bb7SShuming Fan 199681bd644fSShuming Fan _set_tdm_err_: 1997e9e897d5SShuming Fan snd_soc_dapm_mutex_unlock(dapm); 1998e9e897d5SShuming Fan return ret; 1999d6e65bb7SShuming Fan } 2000d6e65bb7SShuming Fan 2001d6e65bb7SShuming Fan static int rt1011_probe(struct snd_soc_component *component) 2002d6e65bb7SShuming Fan { 2003d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 2004d6e65bb7SShuming Fan int i; 2005d6e65bb7SShuming Fan 2006d6e65bb7SShuming Fan rt1011->component = component; 2007d6e65bb7SShuming Fan 2008d6e65bb7SShuming Fan schedule_work(&rt1011->cali_work); 2009d6e65bb7SShuming Fan 2010d6e65bb7SShuming Fan rt1011->bq_drc_params = devm_kcalloc(component->dev, 2011d6e65bb7SShuming Fan RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *), 2012d6e65bb7SShuming Fan GFP_KERNEL); 2013d6e65bb7SShuming Fan if (!rt1011->bq_drc_params) 2014d6e65bb7SShuming Fan return -ENOMEM; 2015d6e65bb7SShuming Fan 2016d6e65bb7SShuming Fan for (i = 0; i < RT1011_ADVMODE_NUM; i++) { 2017d6e65bb7SShuming Fan rt1011->bq_drc_params[i] = devm_kcalloc(component->dev, 2018d6e65bb7SShuming Fan RT1011_BQ_DRC_NUM, sizeof(struct rt1011_bq_drc_params), 2019d6e65bb7SShuming Fan GFP_KERNEL); 2020d6e65bb7SShuming Fan if (!rt1011->bq_drc_params[i]) 2021d6e65bb7SShuming Fan return -ENOMEM; 2022d6e65bb7SShuming Fan } 2023d6e65bb7SShuming Fan 2024d6e65bb7SShuming Fan return 0; 2025d6e65bb7SShuming Fan } 2026d6e65bb7SShuming Fan 2027d6e65bb7SShuming Fan static void rt1011_remove(struct snd_soc_component *component) 2028d6e65bb7SShuming Fan { 2029d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 2030d6e65bb7SShuming Fan 2031d6e65bb7SShuming Fan cancel_work_sync(&rt1011->cali_work); 2032d6e65bb7SShuming Fan rt1011_reset(rt1011->regmap); 2033d6e65bb7SShuming Fan } 2034d6e65bb7SShuming Fan 2035d6e65bb7SShuming Fan #ifdef CONFIG_PM 2036d6e65bb7SShuming Fan static int rt1011_suspend(struct snd_soc_component *component) 2037d6e65bb7SShuming Fan { 2038d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 2039d6e65bb7SShuming Fan 2040d6e65bb7SShuming Fan regcache_cache_only(rt1011->regmap, true); 2041d6e65bb7SShuming Fan regcache_mark_dirty(rt1011->regmap); 2042d6e65bb7SShuming Fan 2043d6e65bb7SShuming Fan return 0; 2044d6e65bb7SShuming Fan } 2045d6e65bb7SShuming Fan 2046d6e65bb7SShuming Fan static int rt1011_resume(struct snd_soc_component *component) 2047d6e65bb7SShuming Fan { 2048d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component); 2049d6e65bb7SShuming Fan 2050d6e65bb7SShuming Fan regcache_cache_only(rt1011->regmap, false); 2051d6e65bb7SShuming Fan regcache_sync(rt1011->regmap); 2052d6e65bb7SShuming Fan 2053d6e65bb7SShuming Fan return 0; 2054d6e65bb7SShuming Fan } 2055d6e65bb7SShuming Fan #else 2056d6e65bb7SShuming Fan #define rt1011_suspend NULL 2057d6e65bb7SShuming Fan #define rt1011_resume NULL 2058d6e65bb7SShuming Fan #endif 2059d6e65bb7SShuming Fan 2060d6e65bb7SShuming Fan static int rt1011_set_bias_level(struct snd_soc_component *component, 2061d6e65bb7SShuming Fan enum snd_soc_bias_level level) 2062d6e65bb7SShuming Fan { 2063d6e65bb7SShuming Fan switch (level) { 2064d6e65bb7SShuming Fan case SND_SOC_BIAS_OFF: 2065d6e65bb7SShuming Fan snd_soc_component_write(component, 2066d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_1, 0x0000); 2067d6e65bb7SShuming Fan snd_soc_component_write(component, 2068d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_2, 0x0000); 2069d6e65bb7SShuming Fan snd_soc_component_write(component, 207009297c2fSShuming Fan RT1011_SYSTEM_RESET_3, 0x0001); 2071d6e65bb7SShuming Fan snd_soc_component_write(component, 2072d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_1, 0x003f); 2073d6e65bb7SShuming Fan snd_soc_component_write(component, 2074d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_2, 0x7fd7); 2075d6e65bb7SShuming Fan snd_soc_component_write(component, 2076d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_3, 0x770f); 2077d6e65bb7SShuming Fan break; 2078d6e65bb7SShuming Fan default: 2079d6e65bb7SShuming Fan break; 2080d6e65bb7SShuming Fan } 2081d6e65bb7SShuming Fan 2082d6e65bb7SShuming Fan return 0; 2083d6e65bb7SShuming Fan } 2084d6e65bb7SShuming Fan 2085d6e65bb7SShuming Fan #define RT1011_STEREO_RATES SNDRV_PCM_RATE_8000_192000 2086d6e65bb7SShuming Fan #define RT1011_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ 2087d6e65bb7SShuming Fan SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE | \ 2088d6e65bb7SShuming Fan SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 2089d6e65bb7SShuming Fan 2090d6e65bb7SShuming Fan static const struct snd_soc_dai_ops rt1011_aif_dai_ops = { 2091d6e65bb7SShuming Fan .hw_params = rt1011_hw_params, 2092d6e65bb7SShuming Fan .set_fmt = rt1011_set_dai_fmt, 2093d6e65bb7SShuming Fan .set_tdm_slot = rt1011_set_tdm_slot, 2094d6e65bb7SShuming Fan }; 2095d6e65bb7SShuming Fan 2096d6e65bb7SShuming Fan static struct snd_soc_dai_driver rt1011_dai[] = { 2097d6e65bb7SShuming Fan { 2098d6e65bb7SShuming Fan .name = "rt1011-aif", 2099d6e65bb7SShuming Fan .playback = { 2100d6e65bb7SShuming Fan .stream_name = "AIF1 Playback", 2101d6e65bb7SShuming Fan .channels_min = 1, 2102d6e65bb7SShuming Fan .channels_max = 2, 2103d6e65bb7SShuming Fan .rates = RT1011_STEREO_RATES, 2104d6e65bb7SShuming Fan .formats = RT1011_FORMATS, 2105d6e65bb7SShuming Fan }, 2106d6e65bb7SShuming Fan .ops = &rt1011_aif_dai_ops, 2107d6e65bb7SShuming Fan }, 2108d6e65bb7SShuming Fan }; 2109d6e65bb7SShuming Fan 2110d6e65bb7SShuming Fan static const struct snd_soc_component_driver soc_component_dev_rt1011 = { 2111d6e65bb7SShuming Fan .probe = rt1011_probe, 2112d6e65bb7SShuming Fan .remove = rt1011_remove, 2113d6e65bb7SShuming Fan .suspend = rt1011_suspend, 2114d6e65bb7SShuming Fan .resume = rt1011_resume, 2115d6e65bb7SShuming Fan .set_bias_level = rt1011_set_bias_level, 2116d6e65bb7SShuming Fan .controls = rt1011_snd_controls, 2117d6e65bb7SShuming Fan .num_controls = ARRAY_SIZE(rt1011_snd_controls), 2118d6e65bb7SShuming Fan .dapm_widgets = rt1011_dapm_widgets, 2119d6e65bb7SShuming Fan .num_dapm_widgets = ARRAY_SIZE(rt1011_dapm_widgets), 2120d6e65bb7SShuming Fan .dapm_routes = rt1011_dapm_routes, 2121d6e65bb7SShuming Fan .num_dapm_routes = ARRAY_SIZE(rt1011_dapm_routes), 2122d6e65bb7SShuming Fan .set_sysclk = rt1011_set_component_sysclk, 2123d6e65bb7SShuming Fan .set_pll = rt1011_set_component_pll, 2124d6e65bb7SShuming Fan .use_pmdown_time = 1, 2125d6e65bb7SShuming Fan .endianness = 1, 2126d6e65bb7SShuming Fan .non_legacy_dai_naming = 1, 2127d6e65bb7SShuming Fan }; 2128d6e65bb7SShuming Fan 2129d6e65bb7SShuming Fan static const struct regmap_config rt1011_regmap = { 2130d6e65bb7SShuming Fan .reg_bits = 16, 2131d6e65bb7SShuming Fan .val_bits = 16, 2132d6e65bb7SShuming Fan .max_register = RT1011_MAX_REG + 1, 2133d6e65bb7SShuming Fan .volatile_reg = rt1011_volatile_register, 2134d6e65bb7SShuming Fan .readable_reg = rt1011_readable_register, 2135d6e65bb7SShuming Fan .cache_type = REGCACHE_RBTREE, 2136d6e65bb7SShuming Fan .reg_defaults = rt1011_reg, 2137d6e65bb7SShuming Fan .num_reg_defaults = ARRAY_SIZE(rt1011_reg), 2138d6e65bb7SShuming Fan .use_single_read = true, 2139d6e65bb7SShuming Fan .use_single_write = true, 2140d6e65bb7SShuming Fan }; 2141d6e65bb7SShuming Fan 2142d6e65bb7SShuming Fan #if defined(CONFIG_OF) 2143d6e65bb7SShuming Fan static const struct of_device_id rt1011_of_match[] = { 2144d6e65bb7SShuming Fan { .compatible = "realtek,rt1011", }, 2145d6e65bb7SShuming Fan {}, 2146d6e65bb7SShuming Fan }; 2147d6e65bb7SShuming Fan MODULE_DEVICE_TABLE(of, rt1011_of_match); 2148d6e65bb7SShuming Fan #endif 2149d6e65bb7SShuming Fan 2150d6e65bb7SShuming Fan #ifdef CONFIG_ACPI 21513084e5f7SRikard Falkeborn static const struct acpi_device_id rt1011_acpi_match[] = { 2152d6e65bb7SShuming Fan {"10EC1011", 0,}, 2153d6e65bb7SShuming Fan {}, 2154d6e65bb7SShuming Fan }; 2155d6e65bb7SShuming Fan MODULE_DEVICE_TABLE(acpi, rt1011_acpi_match); 2156d6e65bb7SShuming Fan #endif 2157d6e65bb7SShuming Fan 2158d6e65bb7SShuming Fan static const struct i2c_device_id rt1011_i2c_id[] = { 2159d6e65bb7SShuming Fan { "rt1011", 0 }, 2160d6e65bb7SShuming Fan { } 2161d6e65bb7SShuming Fan }; 2162d6e65bb7SShuming Fan MODULE_DEVICE_TABLE(i2c, rt1011_i2c_id); 2163d6e65bb7SShuming Fan 2164d6e65bb7SShuming Fan static int rt1011_calibrate(struct rt1011_priv *rt1011, unsigned char cali_flag) 2165d6e65bb7SShuming Fan { 2166d6e65bb7SShuming Fan unsigned int value, count = 0, r0[3]; 2167d6e65bb7SShuming Fan unsigned int chk_cnt = 50; /* DONT change this */ 2168d6e65bb7SShuming Fan unsigned int dc_offset; 2169d6e65bb7SShuming Fan unsigned int r0_integer, r0_factor, format; 2170d6e65bb7SShuming Fan struct device *dev = regmap_get_device(rt1011->regmap); 2171d6e65bb7SShuming Fan struct snd_soc_dapm_context *dapm = 2172d6e65bb7SShuming Fan snd_soc_component_get_dapm(rt1011->component); 2173d6e65bb7SShuming Fan int ret = 0; 2174d6e65bb7SShuming Fan 2175d6e65bb7SShuming Fan snd_soc_dapm_mutex_lock(dapm); 2176d6e65bb7SShuming Fan regcache_cache_bypass(rt1011->regmap, true); 2177d6e65bb7SShuming Fan 2178d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_RESET, 0x0000); 2179d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x740f); 2180d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x770f); 2181d6e65bb7SShuming Fan 2182d6e65bb7SShuming Fan /* RC clock */ 2183d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLK_2, 0x9400); 2184d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_PLL_1, 0x0800); 2185d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_PLL_2, 0x0020); 2186d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLK_DET, 0x0800); 2187d6e65bb7SShuming Fan 2188d6e65bb7SShuming Fan /* ADC/DAC setting */ 2189d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_5, 0x0a20); 2190d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xe232); 2191d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_4, 0xc000); 2192d6e65bb7SShuming Fan 2193d6e65bb7SShuming Fan /* DC detection */ 2194d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_1, 0xb00c); 2195d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_2, 0xcccc); 2196d6e65bb7SShuming Fan 2197d6e65bb7SShuming Fan /* Power */ 2198d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_1, 0xe0e0); 2199d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5003); 2200d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa860); 2201d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xa032); 2202d6e65bb7SShuming Fan 2203d6e65bb7SShuming Fan /* POW_PLL / POW_BG / POW_BG_MBIAS_LV / POW_V/I */ 2204d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0007); 2205d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5ff7); 2206d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f44); 2207d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_A_TIMING_1, 0x4054); 2208d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_BAT_GAIN_1, 0x309c); 2209d6e65bb7SShuming Fan 2210d6e65bb7SShuming Fan /* DC offset from EFUSE */ 2211d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DC_CALIB_CLASSD_3, 0xcb00); 2212d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_BOOST_CON_1, 0xe080); 2213d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_4, 0x16f2); 2214d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_6, 0x36ad); 2215d6e65bb7SShuming Fan 2216d6e65bb7SShuming Fan /* mixer */ 2217d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_MIXER_1, 0x3f1d); 2218d6e65bb7SShuming Fan 2219d6e65bb7SShuming Fan /* EFUSE read */ 2220d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_EFUSE_CONTROL_1, 0x0d0a); 2221d6e65bb7SShuming Fan msleep(30); 2222d6e65bb7SShuming Fan 2223d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_18_16, &value); 2224d6e65bb7SShuming Fan dc_offset = value << 16; 2225d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_15_0, &value); 2226d6e65bb7SShuming Fan dc_offset |= (value & 0xffff); 2227d6e65bb7SShuming Fan dev_info(dev, "ADC offset=0x%x\n", dc_offset); 2228d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_20_16, &value); 2229d6e65bb7SShuming Fan dc_offset = value << 16; 2230d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_15_0, &value); 2231d6e65bb7SShuming Fan dc_offset |= (value & 0xffff); 2232d6e65bb7SShuming Fan dev_info(dev, "Gain0 offset=0x%x\n", dc_offset); 2233d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_20_16, &value); 2234d6e65bb7SShuming Fan dc_offset = value << 16; 2235d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_15_0, &value); 2236d6e65bb7SShuming Fan dc_offset |= (value & 0xffff); 2237d6e65bb7SShuming Fan dev_info(dev, "Gain1 offset=0x%x\n", dc_offset); 2238d6e65bb7SShuming Fan 22390e4ba029SShuming Fan /* check the package info. */ 22400e4ba029SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_MATCH_DONE, &value); 22410e4ba029SShuming Fan if (value & 0x4) 22420e4ba029SShuming Fan rt1011->pack_id = 1; 2243d6e65bb7SShuming Fan 2244d6e65bb7SShuming Fan if (cali_flag) { 22450e4ba029SShuming Fan 22460e4ba029SShuming Fan if (rt1011->pack_id) 22470e4ba029SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_1, 0x292c); 22480e4ba029SShuming Fan else 22490e4ba029SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_1, 0x2925); 22500e4ba029SShuming Fan 2251d6e65bb7SShuming Fan /* Class D on */ 2252d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLASS_D_POS, 0x010e); 2253d6e65bb7SShuming Fan regmap_write(rt1011->regmap, 2254d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1, 0x1701); 2255d6e65bb7SShuming Fan 2256d6e65bb7SShuming Fan /* STP enable */ 2257d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x8000); 2258d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_7, 0xf000); 2259d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4040); 2260d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0xc000); 2261d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x07c2); 2262d6e65bb7SShuming Fan 2263d6e65bb7SShuming Fan r0[0] = r0[1] = r0[2] = count = 0; 2264d6e65bb7SShuming Fan while (count < chk_cnt) { 2265d6e65bb7SShuming Fan msleep(100); 2266d6e65bb7SShuming Fan regmap_read(rt1011->regmap, 2267d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_SYN_24_16, &value); 2268d6e65bb7SShuming Fan r0[count%3] = value << 16; 2269d6e65bb7SShuming Fan regmap_read(rt1011->regmap, 2270d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_SYN_15_0, &value); 2271d6e65bb7SShuming Fan r0[count%3] |= value; 2272d6e65bb7SShuming Fan 2273d6e65bb7SShuming Fan if (r0[count%3] == 0) 2274d6e65bb7SShuming Fan continue; 2275d6e65bb7SShuming Fan 2276d6e65bb7SShuming Fan count++; 2277d6e65bb7SShuming Fan 2278d6e65bb7SShuming Fan if (r0[0] == r0[1] && r0[1] == r0[2]) 2279d6e65bb7SShuming Fan break; 2280d6e65bb7SShuming Fan } 2281d6e65bb7SShuming Fan if (count > chk_cnt) { 2282d6e65bb7SShuming Fan dev_err(dev, "Calibrate R0 Failure\n"); 2283d6e65bb7SShuming Fan ret = -EAGAIN; 2284d6e65bb7SShuming Fan } else { 228583a6edbbSNathan Chancellor format = 2147483648U; /* 2^24 * 128 */ 2286d6e65bb7SShuming Fan r0_integer = format / r0[0] / 128; 2287d6e65bb7SShuming Fan r0_factor = ((format / r0[0] * 100) / 128) 2288d6e65bb7SShuming Fan - (r0_integer * 100); 2289d6e65bb7SShuming Fan rt1011->r0_reg = r0[0]; 22900922c7a5SShuming Fan rt1011->cali_done = 1; 2291d6e65bb7SShuming Fan dev_info(dev, "r0 resistance about %d.%02d ohm, reg=0x%X\n", 2292d6e65bb7SShuming Fan r0_integer, r0_factor, r0[0]); 2293d6e65bb7SShuming Fan } 2294d6e65bb7SShuming Fan } 2295d6e65bb7SShuming Fan 2296d6e65bb7SShuming Fan /* depop */ 2297d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x0000); 2298d6e65bb7SShuming Fan msleep(400); 2299d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa840); 2300d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x0702); 2301d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_MIXER_1, 0xffdd); 2302d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLASSD_INTERNAL_SET_1, 0x0701); 2303d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DAC_SET_3, 0xe004); 2304d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f40); 2305d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_1, 0x0000); 2306d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0000); 2307d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_3, 0x0002); 2308d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_4, 0x00f2); 2309d6e65bb7SShuming Fan 2310d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_RESET, 0x0000); 2311d6e65bb7SShuming Fan 2312d6e65bb7SShuming Fan if (cali_flag) { 2313d6e65bb7SShuming Fan if (count <= chk_cnt) { 2314d6e65bb7SShuming Fan regmap_write(rt1011->regmap, 2315d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_REG_24_16, 2316d6e65bb7SShuming Fan ((r0[0]>>16) & 0x1ff)); 2317d6e65bb7SShuming Fan regmap_write(rt1011->regmap, 2318d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_REG_15_0, 2319d6e65bb7SShuming Fan (r0[0] & 0xffff)); 2320d6e65bb7SShuming Fan regmap_write(rt1011->regmap, 2321d6e65bb7SShuming Fan RT1011_SPK_TEMP_PROTECT_4, 0x4080); 2322d6e65bb7SShuming Fan } 2323d6e65bb7SShuming Fan } 2324d6e65bb7SShuming Fan 2325d6e65bb7SShuming Fan regcache_cache_bypass(rt1011->regmap, false); 2326d6e65bb7SShuming Fan regcache_mark_dirty(rt1011->regmap); 2327d6e65bb7SShuming Fan regcache_sync(rt1011->regmap); 2328d6e65bb7SShuming Fan snd_soc_dapm_mutex_unlock(dapm); 2329d6e65bb7SShuming Fan 2330d6e65bb7SShuming Fan return ret; 2331d6e65bb7SShuming Fan } 2332d6e65bb7SShuming Fan 2333d6e65bb7SShuming Fan static void rt1011_calibration_work(struct work_struct *work) 2334d6e65bb7SShuming Fan { 2335d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = 2336d6e65bb7SShuming Fan container_of(work, struct rt1011_priv, cali_work); 2337d6e65bb7SShuming Fan struct snd_soc_component *component = rt1011->component; 23388de6e755SShuming Fan unsigned int r0_integer, r0_factor, format; 2339d6e65bb7SShuming Fan 23408de6e755SShuming Fan if (rt1011->r0_calib) 23418de6e755SShuming Fan rt1011_calibrate(rt1011, 0); 23428de6e755SShuming Fan else 2343d6e65bb7SShuming Fan rt1011_calibrate(rt1011, 1); 2344d6e65bb7SShuming Fan 23450922c7a5SShuming Fan /* 23460922c7a5SShuming Fan * This flag should reset after booting. 23470922c7a5SShuming Fan * The factory test will do calibration again and use this flag to check 23480922c7a5SShuming Fan * whether the calibration completed 23490922c7a5SShuming Fan */ 23500922c7a5SShuming Fan rt1011->cali_done = 0; 23510922c7a5SShuming Fan 2352d6e65bb7SShuming Fan /* initial */ 2353d6e65bb7SShuming Fan rt1011_reg_init(component); 23548de6e755SShuming Fan 23558de6e755SShuming Fan /* Apply temperature and calibration data from device property */ 235698b6b8dfSShuming Fan if (rt1011->temperature_calib <= 0xff && 235798b6b8dfSShuming Fan rt1011->temperature_calib > 0) { 23588de6e755SShuming Fan snd_soc_component_update_bits(component, 23598de6e755SShuming Fan RT1011_STP_INITIAL_RESISTANCE_TEMP, 0x3ff, 23608de6e755SShuming Fan (rt1011->temperature_calib << 2)); 23618de6e755SShuming Fan } 23628de6e755SShuming Fan 23638de6e755SShuming Fan if (rt1011->r0_calib) { 23648de6e755SShuming Fan rt1011->r0_reg = rt1011->r0_calib; 23658de6e755SShuming Fan 23668de6e755SShuming Fan format = 2147483648U; /* 2^24 * 128 */ 23678de6e755SShuming Fan r0_integer = format / rt1011->r0_reg / 128; 23688de6e755SShuming Fan r0_factor = ((format / rt1011->r0_reg * 100) / 128) 23698de6e755SShuming Fan - (r0_integer * 100); 23708de6e755SShuming Fan dev_info(component->dev, "DP r0 resistance about %d.%02d ohm, reg=0x%X\n", 23718de6e755SShuming Fan r0_integer, r0_factor, rt1011->r0_reg); 23728de6e755SShuming Fan 23738de6e755SShuming Fan rt1011_r0_load(rt1011); 23748de6e755SShuming Fan } 23750e4ba029SShuming Fan 23760e4ba029SShuming Fan if (rt1011->pack_id) 23770e4ba029SShuming Fan snd_soc_component_write(component, RT1011_ADC_SET_1, 0x292c); 23780e4ba029SShuming Fan else 23790e4ba029SShuming Fan snd_soc_component_write(component, RT1011_ADC_SET_1, 0x2925); 23808de6e755SShuming Fan } 23818de6e755SShuming Fan 23828de6e755SShuming Fan static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev) 23838de6e755SShuming Fan { 23848de6e755SShuming Fan device_property_read_u32(dev, "realtek,temperature_calib", 23858de6e755SShuming Fan &rt1011->temperature_calib); 23868de6e755SShuming Fan device_property_read_u32(dev, "realtek,r0_calib", 23878de6e755SShuming Fan &rt1011->r0_calib); 23888de6e755SShuming Fan 2389349959a9SColin Ian King dev_dbg(dev, "%s: r0_calib: 0x%x, temperature_calib: 0x%x", 23908de6e755SShuming Fan __func__, rt1011->r0_calib, rt1011->temperature_calib); 23918de6e755SShuming Fan 23928de6e755SShuming Fan return 0; 2393d6e65bb7SShuming Fan } 2394d6e65bb7SShuming Fan 2395d6e65bb7SShuming Fan static int rt1011_i2c_probe(struct i2c_client *i2c, 2396d6e65bb7SShuming Fan const struct i2c_device_id *id) 2397d6e65bb7SShuming Fan { 2398d6e65bb7SShuming Fan struct rt1011_priv *rt1011; 2399d6e65bb7SShuming Fan int ret; 2400d6e65bb7SShuming Fan unsigned int val; 2401d6e65bb7SShuming Fan 2402d6e65bb7SShuming Fan rt1011 = devm_kzalloc(&i2c->dev, sizeof(struct rt1011_priv), 2403d6e65bb7SShuming Fan GFP_KERNEL); 2404683b8515SShuming Fan if (!rt1011) 2405d6e65bb7SShuming Fan return -ENOMEM; 2406d6e65bb7SShuming Fan 2407d6e65bb7SShuming Fan i2c_set_clientdata(i2c, rt1011); 2408d6e65bb7SShuming Fan 24098de6e755SShuming Fan rt1011_parse_dp(rt1011, &i2c->dev); 24108de6e755SShuming Fan 2411d6e65bb7SShuming Fan rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap); 2412d6e65bb7SShuming Fan if (IS_ERR(rt1011->regmap)) { 2413d6e65bb7SShuming Fan ret = PTR_ERR(rt1011->regmap); 2414d6e65bb7SShuming Fan dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 2415d6e65bb7SShuming Fan ret); 2416d6e65bb7SShuming Fan return ret; 2417d6e65bb7SShuming Fan } 2418d6e65bb7SShuming Fan 2419d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_DEVICE_ID, &val); 2420d6e65bb7SShuming Fan if (val != RT1011_DEVICE_ID_NUM) { 2421d6e65bb7SShuming Fan dev_err(&i2c->dev, 2422d6e65bb7SShuming Fan "Device with ID register %x is not rt1011\n", val); 2423d6e65bb7SShuming Fan return -ENODEV; 2424d6e65bb7SShuming Fan } 2425d6e65bb7SShuming Fan 2426d6e65bb7SShuming Fan INIT_WORK(&rt1011->cali_work, rt1011_calibration_work); 2427d6e65bb7SShuming Fan 2428d6e65bb7SShuming Fan return devm_snd_soc_register_component(&i2c->dev, 2429d6e65bb7SShuming Fan &soc_component_dev_rt1011, 2430d6e65bb7SShuming Fan rt1011_dai, ARRAY_SIZE(rt1011_dai)); 2431d6e65bb7SShuming Fan 2432d6e65bb7SShuming Fan } 2433d6e65bb7SShuming Fan 2434d6e65bb7SShuming Fan static void rt1011_i2c_shutdown(struct i2c_client *client) 2435d6e65bb7SShuming Fan { 2436d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = i2c_get_clientdata(client); 2437d6e65bb7SShuming Fan 2438d6e65bb7SShuming Fan rt1011_reset(rt1011->regmap); 2439d6e65bb7SShuming Fan } 2440d6e65bb7SShuming Fan 2441d6e65bb7SShuming Fan static struct i2c_driver rt1011_i2c_driver = { 2442d6e65bb7SShuming Fan .driver = { 2443d6e65bb7SShuming Fan .name = "rt1011", 2444d6e65bb7SShuming Fan .of_match_table = of_match_ptr(rt1011_of_match), 2445d6e65bb7SShuming Fan .acpi_match_table = ACPI_PTR(rt1011_acpi_match) 2446d6e65bb7SShuming Fan }, 2447d6e65bb7SShuming Fan .probe = rt1011_i2c_probe, 2448d6e65bb7SShuming Fan .shutdown = rt1011_i2c_shutdown, 2449d6e65bb7SShuming Fan .id_table = rt1011_i2c_id, 2450d6e65bb7SShuming Fan }; 2451d6e65bb7SShuming Fan module_i2c_driver(rt1011_i2c_driver); 2452d6e65bb7SShuming Fan 2453d6e65bb7SShuming Fan MODULE_DESCRIPTION("ASoC RT1011 amplifier driver"); 2454d6e65bb7SShuming Fan MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>"); 2455d6e65bb7SShuming Fan MODULE_LICENSE("GPL"); 2456