Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: sma1307: Add driver for Iron Device SMA1307

The Iron Device SMA1307 is a boosted digital speaker amplifier

Signed-off-by: Kiseok Jo <kiseok.jo@irondevice.com>
Link: https://patch.msgid.link/20241106005800.7520-3-kiseok.jo@irondevice.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kiseok Jo and committed by
Mark Brown
576c57e6 82a1ccdf

+2508
+10
sound/soc/codecs/Kconfig
··· 240 240 imply SND_SOC_SIMPLE_AMPLIFIER 241 241 imply SND_SOC_SIMPLE_MUX 242 242 imply SND_SOC_SMA1303 243 + imply SND_SOC_SMA1307 243 244 imply SND_SOC_SPDIF 244 245 imply SND_SOC_SRC4XXX_I2C 245 246 imply SND_SOC_SSM2305 ··· 1873 1872 depends on I2C 1874 1873 help 1875 1874 Enable support for Iron Device SMA1303 Boosted Class-D amplifier 1875 + 1876 + config SND_SOC_SMA1307 1877 + tristate "Iron Device SMA1307 Audio Amplifier" 1878 + depends on I2C 1879 + help 1880 + Enable support for Iron Device SMA1307 boosted digital speaker 1881 + amplifier with feedback-loop. 1882 + If you are using a system with an SMA1307 amplifier connected 1883 + via I2C, enable this option. 1876 1884 1877 1885 config SND_SOC_SPDIF 1878 1886 tristate "S/PDIF CODEC"
+2
sound/soc/codecs/Makefile
··· 279 279 snd-soc-sigmadsp-regmap-y := sigmadsp-regmap.o 280 280 snd-soc-si476x-y := si476x.o 281 281 snd-soc-sma1303-y := sma1303.o 282 + snd-soc-sma1307-y := sma1307.o 282 283 snd-soc-spdif-tx-y := spdif_transmitter.o 283 284 snd-soc-spdif-rx-y := spdif_receiver.o 284 285 snd-soc-src4xxx-y := src4xxx.o ··· 690 689 obj-$(CONFIG_SND_SOC_SIGMADSP_REGMAP) += snd-soc-sigmadsp-regmap.o 691 690 obj-$(CONFIG_SND_SOC_SI476X) += snd-soc-si476x.o 692 691 obj-$(CONFIG_SND_SOC_SMA1303) += snd-soc-sma1303.o 692 + obj-$(CONFIG_SND_SOC_SMA1307) += snd-soc-sma1307.o 693 693 obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o 694 694 obj-$(CONFIG_SND_SOC_SRC4XXX) += snd-soc-src4xxx.o 695 695 obj-$(CONFIG_SND_SOC_SRC4XXX_I2C) += snd-soc-src4xxx-i2c.o
+2052
sound/soc/codecs/sma1307.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + // sma1307.c -- sma1307 ALSA SoC Audio driver 3 + // 4 + // Copyright 2024 Iron Device Corporation 5 + // 6 + // Auther: Gyuhwa Park <gyuwha.park@irondevice.com> 7 + // Auther: Kiseok Jo <kiseok.jo@irondevice.com> 8 + 9 + #include <linux/firmware.h> 10 + #include <linux/i2c.h> 11 + #include <linux/of_gpio.h> 12 + #include <linux/regmap.h> 13 + #include <sound/pcm_params.h> 14 + #include <sound/tlv.h> 15 + #include "sma1307.h" 16 + 17 + #define CHECK_PERIOD_TIME 1 /* sec per HZ */ 18 + #define PLL_MATCH(_input_clk_name, _output_clk_name, _input_clk,\ 19 + _post_n, _n, _vco, _p_cp)\ 20 + {\ 21 + .input_clk_name = _input_clk_name,\ 22 + .output_clk_name = _output_clk_name,\ 23 + .input_clk = _input_clk,\ 24 + .post_n = _post_n,\ 25 + .n = _n,\ 26 + .vco = _vco,\ 27 + .p_cp = _p_cp,\ 28 + } 29 + 30 + static const char *setting_file = "sma1307_setting.bin"; 31 + #define SMA1307_SETTING_CHECKSUM 0x100000 32 + 33 + /* PLL clock setting Table */ 34 + struct sma1307_pll_match { 35 + char *input_clk_name; 36 + char *output_clk_name; 37 + unsigned int input_clk; 38 + unsigned int post_n; 39 + unsigned int n; 40 + unsigned int vco; 41 + unsigned int p_cp; 42 + }; 43 + 44 + struct sma1307_data { 45 + char *name; 46 + void (*init)(struct regmap *regmap); 47 + }; 48 + 49 + struct sma1307_priv { 50 + bool check_fault_status; 51 + bool force_mute_status; 52 + bool sw_ot1_prot; 53 + char *name; 54 + enum sma1307_mode amp_mode; 55 + int binary_mode; 56 + int dapm_aif_in; 57 + int dapm_aif_out0; 58 + int dapm_aif_out1; 59 + int dapm_sdo_en; 60 + int dapm_sdo_setting; 61 + int num_of_pll_matches; 62 + int check_fault_period; 63 + struct delayed_work check_fault_work; 64 + struct device *dev; 65 + struct kobject *kobj; 66 + struct mutex default_lock; 67 + struct regmap *regmap; 68 + struct sma1307_setting_file set; 69 + const struct sma1307_pll_match *pll_matches; 70 + const struct sma1307_data *data; 71 + unsigned int cur_vol; 72 + unsigned int format; 73 + unsigned int frame_size; 74 + unsigned int init_vol; 75 + unsigned int last_bclk; 76 + unsigned int otp_trm2; 77 + unsigned int otp_trm3; 78 + unsigned int rev_num; 79 + unsigned int sys_clk_id; 80 + unsigned int tdm_slot0_rx; 81 + unsigned int tdm_slot1_rx; 82 + unsigned int tdm_slot0_tx; 83 + unsigned int tdm_slot1_tx; 84 + unsigned int tsdw_cnt; 85 + }; 86 + 87 + static const struct sma1307_pll_match sma1307_pll_matches[] = { 88 + /* in_clk_name, out_clk_name, input_clk post_n, n, vco, p_cp */ 89 + PLL_MATCH("1.411MHz", "24.554MHz", 90 + 1411200, 0x06, 0xD1, 0x88, 0x00), 91 + PLL_MATCH("1.536MHz", "24.576MHz", 92 + 1536000, 0x06, 0xC0, 0x88, 0x00), 93 + PLL_MATCH("2.822MHz", "24.554MHz", 94 + 2822400, 0x06, 0xD1, 0x88, 0x04), 95 + PLL_MATCH("3.072MHz", "24.576MHz", 96 + 3072000, 0x06, 0x60, 0x88, 0x00), 97 + PLL_MATCH("6.144MHz", "24.576MHz", 98 + 6144000, 0x06, 0x60, 0x88, 0x04), 99 + PLL_MATCH("12.288MHz", "24.576MHz", 100 + 12288000, 0x06, 0x60, 0x88, 0x08), 101 + PLL_MATCH("19.2MHz", "24.48MHz", 102 + 19200000, 0x06, 0x7B, 0x88, 0x0C), 103 + PLL_MATCH("24.576MHz", "24.576MHz", 104 + 24576000, 0x06, 0x60, 0x88, 0x0C), 105 + }; 106 + 107 + static struct snd_soc_component *sma1307_amp_component; 108 + 109 + static void sma1307_startup(struct snd_soc_component *); 110 + static void sma1307_shutdown(struct snd_soc_component *); 111 + static void sma1307_reset(struct snd_soc_component *); 112 + static void sma1307_set_binary(struct snd_soc_component *); 113 + static void sma1307_set_default(struct snd_soc_component *); 114 + 115 + /* Initial register value - 6.0W SPK (8ohm load) */ 116 + static const struct reg_default sma1307_reg_def[] = { 117 + { 0x00, 0x80 }, 118 + { 0x01, 0x00 }, 119 + { 0x02, 0x52 }, 120 + { 0x03, 0x4C }, 121 + { 0x04, 0x47 }, 122 + { 0x05, 0x42 }, 123 + { 0x06, 0x40 }, 124 + { 0x07, 0x40 }, 125 + { 0x08, 0x3C }, 126 + { 0x09, 0x2F }, 127 + { 0x0A, 0x32 }, 128 + { 0x0B, 0x50 }, 129 + { 0x0C, 0x8C }, 130 + { 0x0D, 0x00 }, 131 + { 0x0E, 0x3F }, 132 + { 0x0F, 0x00 }, 133 + { 0x10, 0x00 }, 134 + { 0x11, 0x00 }, 135 + { 0x12, 0x00 }, 136 + { 0x13, 0x09 }, 137 + { 0x14, 0x12 }, 138 + { 0x1C, 0x00 }, 139 + { 0x1D, 0x85 }, 140 + { 0x1E, 0xA1 }, 141 + { 0x1F, 0x67 }, 142 + { 0x22, 0x00 }, 143 + { 0x23, 0x1F }, 144 + { 0x24, 0x7A }, 145 + { 0x25, 0x00 }, 146 + { 0x26, 0xFF }, 147 + { 0x27, 0x39 }, 148 + { 0x28, 0x54 }, 149 + { 0x29, 0x92 }, 150 + { 0x2A, 0xB0 }, 151 + { 0x2B, 0xED }, 152 + { 0x2C, 0xED }, 153 + { 0x2D, 0xFF }, 154 + { 0x2E, 0xFF }, 155 + { 0x2F, 0xFF }, 156 + { 0x30, 0xFF }, 157 + { 0x31, 0xFF }, 158 + { 0x32, 0xFF }, 159 + { 0x34, 0x01 }, 160 + { 0x35, 0x17 }, 161 + { 0x36, 0x92 }, 162 + { 0x37, 0x00 }, 163 + { 0x38, 0x01 }, 164 + { 0x39, 0x10 }, 165 + { 0x3E, 0x01 }, 166 + { 0x3F, 0x08 }, 167 + { 0x8B, 0x05 }, 168 + { 0x8C, 0x50 }, 169 + { 0x8D, 0x80 }, 170 + { 0x8E, 0x10 }, 171 + { 0x8F, 0x02 }, 172 + { 0x90, 0x02 }, 173 + { 0x91, 0x83 }, 174 + { 0x92, 0xC0 }, 175 + { 0x93, 0x00 }, 176 + { 0x94, 0xA4 }, 177 + { 0x95, 0x74 }, 178 + { 0x96, 0x57 }, 179 + { 0xA2, 0xCC }, 180 + { 0xA3, 0x28 }, 181 + { 0xA4, 0x40 }, 182 + { 0xA5, 0x01 }, 183 + { 0xA6, 0x41 }, 184 + { 0xA7, 0x08 }, 185 + { 0xA8, 0x04 }, 186 + { 0xA9, 0x27 }, 187 + { 0xAA, 0x10 }, 188 + { 0xAB, 0x10 }, 189 + { 0xAC, 0x10 }, 190 + { 0xAD, 0x0F }, 191 + { 0xAE, 0xCD }, 192 + { 0xAF, 0x70 }, 193 + { 0xB0, 0x03 }, 194 + { 0xB1, 0xEF }, 195 + { 0xB2, 0x03 }, 196 + { 0xB3, 0xEF }, 197 + { 0xB4, 0xF3 }, 198 + { 0xB5, 0x3D }, 199 + }; 200 + 201 + static bool sma1307_readable_register(struct device *dev, unsigned int reg) 202 + { 203 + if (reg > SMA1307_FF_DEVICE_INDEX) 204 + return false; 205 + 206 + switch (reg) { 207 + case SMA1307_00_SYSTEM_CTRL ... SMA1307_1F_TONE_FINE_VOLUME: 208 + case SMA1307_22_COMP_HYS_SEL ... SMA1307_32_BROWN_OUT_PROT19: 209 + case SMA1307_34_OCP_SPK ... SMA1307_39_PMT_NZ_VAL: 210 + case SMA1307_3B_TEST1 ... SMA1307_3F_ATEST2: 211 + case SMA1307_8B_PLL_POST_N ... SMA1307_9A_OTP_TRM3: 212 + case SMA1307_A0_PAD_CTRL0 ... SMA1307_BE_MCBS_CTRL2: 213 + case SMA1307_F5_READY_FOR_V_SAR: 214 + case SMA1307_F7_READY_FOR_T_SAR ... SMA1307_FF_DEVICE_INDEX: 215 + break; 216 + default: 217 + return false; 218 + } 219 + return true; 220 + } 221 + 222 + static bool sma1307_writeable_register(struct device *dev, unsigned int reg) 223 + { 224 + if (reg > SMA1307_FF_DEVICE_INDEX) 225 + return false; 226 + 227 + switch (reg) { 228 + case SMA1307_00_SYSTEM_CTRL ... SMA1307_1F_TONE_FINE_VOLUME: 229 + case SMA1307_22_COMP_HYS_SEL ... SMA1307_32_BROWN_OUT_PROT19: 230 + case SMA1307_34_OCP_SPK ... SMA1307_39_PMT_NZ_VAL: 231 + case SMA1307_3B_TEST1 ... SMA1307_3F_ATEST2: 232 + case SMA1307_8B_PLL_POST_N ... SMA1307_9A_OTP_TRM3: 233 + case SMA1307_A0_PAD_CTRL0 ... SMA1307_BE_MCBS_CTRL2: 234 + break; 235 + default: 236 + return false; 237 + } 238 + return true; 239 + } 240 + 241 + static bool sma1307_volatile_register(struct device *dev, unsigned int reg) 242 + { 243 + if (reg > SMA1307_FF_DEVICE_INDEX) 244 + return false; 245 + 246 + switch (reg) { 247 + case SMA1307_F8_STATUS_T1 ... SMA1307_FF_DEVICE_INDEX: 248 + break; 249 + default: 250 + return false; 251 + } 252 + return true; 253 + } 254 + 255 + /* DB scale conversion of speaker volume */ 256 + static const DECLARE_TLV_DB_SCALE(sma1307_spk_tlv, -6000, 50, 0); 257 + 258 + static const char *const sma1307_aif_in_source_text[] = { 259 + "Mono", "Left", "Right" 260 + }; 261 + 262 + static const char *const sma1307_sdo_setting_text[] = { 263 + "Data_One_48k", "Data_Two_48k", "Data_Two_24k", 264 + "Clk_PLL", "Clk_OSC" 265 + }; 266 + 267 + static const char *const sma1307_aif_out_source_text[] = { 268 + "Disable", "After_FmtC", "After_Mixer", "After_DSP", 269 + "Vrms2_Avg", "Battery", "Temperature", "After_Delay" 270 + }; 271 + 272 + static const char *const sma1307_tdm_slot_text[] = { 273 + "Slot0", "Slot1", "Slot2", "Slot3", 274 + "Slot4", "Slot5", "Slot6", "Slot7" 275 + }; 276 + 277 + static const char *const sma1307_binary_mode_text[] = { 278 + "Mode0", "Mode1", "Mode2", "Mode3", "Mode4" 279 + }; 280 + 281 + static const char *const sma1307_reset_text[] = { 282 + "Reset" 283 + }; 284 + 285 + static const struct soc_enum sma1307_aif_in_source_enum = 286 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1307_aif_in_source_text), 287 + sma1307_aif_in_source_text); 288 + static const struct soc_enum sma1307_sdo_setting_enum = 289 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1307_sdo_setting_text), 290 + sma1307_sdo_setting_text); 291 + static const struct soc_enum sma1307_aif_out_source_enum = 292 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1307_aif_out_source_text), 293 + sma1307_aif_out_source_text); 294 + static const struct soc_enum sma1307_tdm_slot_enum = 295 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1307_tdm_slot_text), 296 + sma1307_tdm_slot_text); 297 + static const struct soc_enum sma1307_binary_mode_enum = 298 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1307_binary_mode_text), 299 + sma1307_binary_mode_text); 300 + static const struct soc_enum sma1307_reset_enum = 301 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1307_reset_text), 302 + sma1307_reset_text); 303 + 304 + static int sma1307_force_mute_get(struct snd_kcontrol *kcontrol, 305 + struct snd_ctl_elem_value *ucontrol) 306 + { 307 + struct snd_soc_component *component = 308 + snd_soc_kcontrol_component(kcontrol); 309 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 310 + 311 + ucontrol->value.integer.value[0] = (int)sma1307->force_mute_status; 312 + 313 + return 0; 314 + } 315 + 316 + static int sma1307_force_mute_put(struct snd_kcontrol *kcontrol, 317 + struct snd_ctl_elem_value *ucontrol) 318 + { 319 + struct snd_soc_component *component = 320 + snd_soc_kcontrol_component(kcontrol); 321 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 322 + bool change = false, val = (bool)ucontrol->value.integer.value[0]; 323 + 324 + if (sma1307->force_mute_status == val) { 325 + change = false; 326 + } else { 327 + change = true; 328 + sma1307->force_mute_status = val; 329 + } 330 + 331 + return change; 332 + } 333 + 334 + static int sma1307_tdm_slot_get(struct snd_kcontrol *kcontrol, 335 + struct snd_ctl_elem_value *ucontrol) 336 + { 337 + struct snd_soc_component *component = 338 + snd_soc_kcontrol_component(kcontrol); 339 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 340 + int val1, val2; 341 + 342 + regmap_read(sma1307->regmap, SMA1307_A5_TDM1, &val1); 343 + regmap_read(sma1307->regmap, SMA1307_A6_TDM2, &val2); 344 + 345 + if (!strcmp(kcontrol->id.name, SMA1307_TDM_RX0_POS_NAME)) { 346 + ucontrol->value.integer.value[0] 347 + = (val1 & SMA1307_TDM_SLOT0_RX_POS_MASK) >> 3; 348 + sma1307->tdm_slot0_rx = ucontrol->value.integer.value[0]; 349 + } else if (!strcmp(kcontrol->id.name, SMA1307_TDM_RX1_POS_NAME)) { 350 + ucontrol->value.integer.value[0] 351 + = val1 & SMA1307_TDM_SLOT1_RX_POS_MASK; 352 + sma1307->tdm_slot1_rx = ucontrol->value.integer.value[0]; 353 + } else if (!strcmp(kcontrol->id.name, SMA1307_TDM_TX0_POS_NAME)) { 354 + ucontrol->value.integer.value[0] 355 + = (val2 & SMA1307_TDM_SLOT0_TX_POS_MASK) >> 3; 356 + sma1307->tdm_slot0_tx = ucontrol->value.integer.value[0]; 357 + } else if (!strcmp(kcontrol->id.name, SMA1307_TDM_TX1_POS_NAME)) { 358 + ucontrol->value.integer.value[0] 359 + = val2 & SMA1307_TDM_SLOT1_TX_POS_MASK; 360 + sma1307->tdm_slot1_tx = ucontrol->value.integer.value[0]; 361 + } else { 362 + return -EINVAL; 363 + } 364 + 365 + return 0; 366 + } 367 + 368 + static int sma1307_tdm_slot_put(struct snd_kcontrol *kcontrol, 369 + struct snd_ctl_elem_value *ucontrol) 370 + { 371 + struct snd_soc_component *component = 372 + snd_soc_kcontrol_component(kcontrol); 373 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 374 + int val = (int)ucontrol->value.integer.value[0]; 375 + bool change; 376 + 377 + if (!strcmp(kcontrol->id.name, SMA1307_TDM_RX0_POS_NAME)) { 378 + if (sma1307->tdm_slot0_rx == val) 379 + change = false; 380 + else { 381 + change = true; 382 + sma1307->tdm_slot0_rx = val; 383 + regmap_update_bits(sma1307->regmap, SMA1307_A5_TDM1, 384 + SMA1307_TDM_SLOT0_RX_POS_MASK, val << 3); 385 + } 386 + } else if (!strcmp(kcontrol->id.name, SMA1307_TDM_RX1_POS_NAME)) { 387 + if (sma1307->tdm_slot1_rx == val) 388 + change = false; 389 + else { 390 + change = true; 391 + sma1307->tdm_slot1_rx = val; 392 + regmap_update_bits(sma1307->regmap, SMA1307_A5_TDM1, 393 + SMA1307_TDM_SLOT1_RX_POS_MASK, val); 394 + } 395 + } else if (!strcmp(kcontrol->id.name, SMA1307_TDM_TX0_POS_NAME)) { 396 + if (sma1307->tdm_slot0_tx == val) 397 + change = false; 398 + else { 399 + change = true; 400 + sma1307->tdm_slot0_tx = val; 401 + regmap_update_bits(sma1307->regmap, SMA1307_A6_TDM2, 402 + SMA1307_TDM_SLOT0_TX_POS_MASK, val << 3); 403 + } 404 + } else if (!strcmp(kcontrol->id.name, SMA1307_TDM_TX1_POS_NAME)) { 405 + if (sma1307->tdm_slot1_tx == val) 406 + change = false; 407 + else { 408 + change = true; 409 + sma1307->tdm_slot1_tx = val; 410 + regmap_update_bits(sma1307->regmap, SMA1307_A6_TDM2, 411 + SMA1307_TDM_SLOT1_TX_POS_MASK, val); 412 + } 413 + } else { 414 + dev_err(sma1307->dev, "%s: Invalid Control ID - %s\n", 415 + __func__, kcontrol->id.name); 416 + return -EINVAL; 417 + } 418 + 419 + return change; 420 + } 421 + 422 + static int sma1307_sw_ot1_prot_get(struct snd_kcontrol *kcontrol, 423 + struct snd_ctl_elem_value *ucontrol) 424 + { 425 + struct snd_soc_component *component = 426 + snd_soc_kcontrol_component(kcontrol); 427 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 428 + 429 + ucontrol->value.integer.value[0] = (int)sma1307->sw_ot1_prot; 430 + 431 + return 0; 432 + } 433 + 434 + static int sma1307_sw_ot1_prot_put(struct snd_kcontrol *kcontrol, 435 + struct snd_ctl_elem_value *ucontrol) 436 + { 437 + struct snd_soc_component *component = 438 + snd_soc_kcontrol_component(kcontrol); 439 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 440 + bool change = false, val = (bool)ucontrol->value.integer.value[0]; 441 + 442 + if (sma1307->sw_ot1_prot == val) 443 + change = false; 444 + else { 445 + change = true; 446 + sma1307->sw_ot1_prot = val; 447 + } 448 + 449 + return change; 450 + } 451 + 452 + static int sma1307_check_fault_status_get(struct snd_kcontrol *kcontrol, 453 + struct snd_ctl_elem_value *ucontrol) 454 + { 455 + struct snd_soc_component *component = 456 + snd_soc_kcontrol_component(kcontrol); 457 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 458 + 459 + ucontrol->value.integer.value[0] = (int)sma1307->check_fault_status; 460 + 461 + return 0; 462 + } 463 + 464 + static int sma1307_check_fault_status_put(struct snd_kcontrol *kcontrol, 465 + struct snd_ctl_elem_value *ucontrol) 466 + { 467 + struct snd_soc_component *component = 468 + snd_soc_kcontrol_component(kcontrol); 469 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 470 + bool change = false, val = (bool)ucontrol->value.integer.value[0]; 471 + 472 + if (sma1307->check_fault_status == val) { 473 + change = false; 474 + } else { 475 + change = true; 476 + sma1307->check_fault_status = val; 477 + } 478 + 479 + return change; 480 + } 481 + 482 + static int sma1307_check_fault_period_get(struct snd_kcontrol *kcontrol, 483 + struct snd_ctl_elem_value *ucontrol) 484 + { 485 + struct snd_soc_component *component = 486 + snd_soc_kcontrol_component(kcontrol); 487 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 488 + 489 + ucontrol->value.integer.value[0] = sma1307->check_fault_period; 490 + 491 + return 0; 492 + } 493 + 494 + static int sma1307_check_fault_period_put(struct snd_kcontrol *kcontrol, 495 + struct snd_ctl_elem_value *ucontrol) 496 + { 497 + struct snd_soc_component *component = 498 + snd_soc_kcontrol_component(kcontrol); 499 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 500 + struct soc_mixer_control *mc = 501 + (struct soc_mixer_control *)kcontrol->private_value; 502 + bool change = false; 503 + int val = ucontrol->value.integer.value[0]; 504 + 505 + if (val < mc->min || val > mc->max) 506 + return -EINVAL; 507 + if (sma1307->check_fault_period == val) { 508 + change = false; 509 + } else { 510 + change = true; 511 + sma1307->check_fault_period = val; 512 + } 513 + 514 + return change; 515 + } 516 + 517 + static int sma1307_reset_put(struct snd_kcontrol *kcontrol, 518 + struct snd_ctl_elem_value *ucontrol) 519 + { 520 + struct snd_soc_component *component = 521 + snd_soc_kcontrol_component(kcontrol); 522 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 523 + 524 + regmap_update_bits(sma1307->regmap, SMA1307_00_SYSTEM_CTRL, 525 + SMA1307_RESET_MASK, SMA1307_RESET_ON); 526 + sma1307_reset(component); 527 + 528 + snd_ctl_notify(component->card->snd_card, SNDRV_CTL_EVENT_MASK_VALUE, 529 + &kcontrol->id); 530 + 531 + return true; 532 + } 533 + 534 + static int sma1307_binary_mode_put(struct snd_kcontrol *kcontrol, 535 + struct snd_ctl_elem_value *ucontrol) 536 + { 537 + struct snd_soc_component *component = 538 + snd_soc_kcontrol_component(kcontrol); 539 + struct sma1307_priv *sma1307 = snd_kcontrol_chip(kcontrol); 540 + 541 + sma1307->binary_mode = (int)ucontrol->value.enumerated.item[0]; 542 + if (sma1307->set.status) 543 + sma1307_set_binary(component); 544 + 545 + return snd_soc_put_enum_double(kcontrol, ucontrol); 546 + } 547 + 548 + static void sma1307_startup(struct snd_soc_component *component) 549 + { 550 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 551 + 552 + regmap_update_bits(sma1307->regmap, SMA1307_A2_TOP_MAN1, 553 + SMA1307_PLL_MASK, SMA1307_PLL_ON); 554 + regmap_update_bits(sma1307->regmap, SMA1307_00_SYSTEM_CTRL, 555 + SMA1307_POWER_MASK, SMA1307_POWER_ON); 556 + 557 + if (sma1307->amp_mode == SMA1307_MONO_MODE) { 558 + regmap_update_bits(sma1307->regmap, 559 + SMA1307_10_SYSTEM_CTRL1, 560 + SMA1307_SPK_MODE_MASK, 561 + SMA1307_SPK_MONO); 562 + } else { 563 + regmap_update_bits(sma1307->regmap, 564 + SMA1307_10_SYSTEM_CTRL1, 565 + SMA1307_SPK_MODE_MASK, 566 + SMA1307_SPK_STEREO); 567 + } 568 + 569 + if (sma1307->check_fault_status) { 570 + if (sma1307->check_fault_period > 0) 571 + queue_delayed_work(system_freezable_wq, 572 + &sma1307->check_fault_work, 573 + sma1307->check_fault_period * HZ); 574 + else 575 + queue_delayed_work(system_freezable_wq, 576 + &sma1307->check_fault_work, 577 + CHECK_PERIOD_TIME * HZ); 578 + } 579 + } 580 + 581 + static void sma1307_shutdown(struct snd_soc_component *component) 582 + { 583 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 584 + 585 + /* for SMA1307A */ 586 + cancel_delayed_work_sync(&sma1307->check_fault_work); 587 + 588 + regmap_update_bits(sma1307->regmap, SMA1307_0E_MUTE_VOL_CTRL, 589 + SMA1307_SPK_MUTE_MASK, SMA1307_SPK_MUTE); 590 + /* Need to wait time for mute slope */ 591 + msleep(55); 592 + 593 + regmap_update_bits(sma1307->regmap, SMA1307_10_SYSTEM_CTRL1, 594 + SMA1307_SPK_MODE_MASK, SMA1307_SPK_OFF); 595 + regmap_update_bits(sma1307->regmap, SMA1307_A2_TOP_MAN1, 596 + SMA1307_PLL_MASK, SMA1307_PLL_OFF); 597 + regmap_update_bits(sma1307->regmap, SMA1307_00_SYSTEM_CTRL, 598 + SMA1307_POWER_MASK, SMA1307_POWER_OFF); 599 + } 600 + 601 + static int sma1307_aif_in_event(struct snd_soc_dapm_widget *w, 602 + struct snd_kcontrol *kcontrol, int event) 603 + { 604 + struct snd_soc_component *component = 605 + snd_soc_dapm_to_component(w->dapm); 606 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 607 + unsigned int mux = sma1307->dapm_aif_in; 608 + 609 + switch (event) { 610 + case SND_SOC_DAPM_PRE_PMU: 611 + switch (mux) { 612 + case SMA1307_MONO_MODE: 613 + regmap_update_bits(sma1307->regmap, 614 + SMA1307_11_SYSTEM_CTRL2, 615 + SMA1307_MONOMIX_MASK, 616 + SMA1307_MONOMIX_ON); 617 + break; 618 + case SMA1307_LEFT_MODE: 619 + regmap_update_bits(sma1307->regmap, 620 + SMA1307_11_SYSTEM_CTRL2, 621 + SMA1307_MONOMIX_MASK, 622 + SMA1307_MONOMIX_OFF); 623 + regmap_update_bits(sma1307->regmap, 624 + SMA1307_11_SYSTEM_CTRL2, 625 + SMA1307_LR_DATA_SW_MASK, 626 + SMA1307_LR_DATA_SW_NORMAL); 627 + break; 628 + case SMA1307_RIGHT_MODE: 629 + regmap_update_bits(sma1307->regmap, 630 + SMA1307_11_SYSTEM_CTRL2, 631 + SMA1307_MONOMIX_MASK, 632 + SMA1307_MONOMIX_OFF); 633 + regmap_update_bits(sma1307->regmap, 634 + SMA1307_11_SYSTEM_CTRL2, 635 + SMA1307_LR_DATA_SW_MASK, 636 + SMA1307_LR_DATA_SW_SWAP); 637 + break; 638 + default: 639 + 640 + dev_err(sma1307->dev, "%s: Invalid value (%d)\n", 641 + __func__, mux); 642 + return -EINVAL; 643 + } 644 + sma1307->amp_mode = mux; 645 + break; 646 + } 647 + return 0; 648 + } 649 + 650 + static int sma1307_sdo_setting_event(struct snd_soc_dapm_widget *w, 651 + struct snd_kcontrol *kcontrol, int event) 652 + { 653 + struct snd_soc_component *component = 654 + snd_soc_dapm_to_component(w->dapm); 655 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 656 + unsigned int mux = sma1307->dapm_sdo_setting; 657 + 658 + switch (event) { 659 + case SND_SOC_DAPM_PRE_PMU: 660 + switch (mux) { 661 + case SMA1307_OUT_DATA_ONE_48K: 662 + regmap_update_bits(sma1307->regmap, 663 + SMA1307_A2_TOP_MAN1, 664 + SMA1307_SDO_OUTPUT2_MASK, 665 + SMA1307_ONE_SDO_PER_CH); 666 + regmap_update_bits(sma1307->regmap, 667 + SMA1307_A3_TOP_MAN2, 668 + SMA1307_SDO_OUTPUT3_MASK 669 + | 670 + SMA1307_DATA_CLK_SEL_MASK, 671 + SMA1307_SDO_OUTPUT3_DIS 672 + | SMA1307_SDO_DATA); 673 + break; 674 + case SMA1307_OUT_DATA_TWO_48K: 675 + regmap_update_bits(sma1307->regmap, 676 + SMA1307_A2_TOP_MAN1, 677 + SMA1307_SDO_OUTPUT2_MASK, 678 + SMA1307_TWO_SDO_PER_CH); 679 + regmap_update_bits(sma1307->regmap, 680 + SMA1307_A3_TOP_MAN2, 681 + SMA1307_SDO_OUTPUT3_MASK 682 + | 683 + SMA1307_DATA_CLK_SEL_MASK, 684 + SMA1307_SDO_OUTPUT3_DIS 685 + | SMA1307_SDO_DATA); 686 + break; 687 + case SMA1307_OUT_DATA_TWO_24K: 688 + regmap_update_bits(sma1307->regmap, 689 + SMA1307_A2_TOP_MAN1, 690 + SMA1307_SDO_OUTPUT2_MASK, 691 + SMA1307_TWO_SDO_PER_CH); 692 + regmap_update_bits(sma1307->regmap, 693 + SMA1307_A3_TOP_MAN2, 694 + SMA1307_SDO_OUTPUT3_MASK 695 + | 696 + SMA1307_DATA_CLK_SEL_MASK, 697 + SMA1307_TWO_SDO_PER_CH_24K 698 + | SMA1307_SDO_DATA); 699 + break; 700 + case SMA1307_OUT_CLK_PLL: 701 + regmap_update_bits(sma1307->regmap, 702 + SMA1307_A3_TOP_MAN2, 703 + SMA1307_DATA_CLK_SEL_MASK, 704 + SMA1307_SDO_CLK_PLL); 705 + 706 + break; 707 + case SMA1307_OUT_CLK_OSC: 708 + regmap_update_bits(sma1307->regmap, 709 + SMA1307_A3_TOP_MAN2, 710 + SMA1307_DATA_CLK_SEL_MASK, 711 + SMA1307_SDO_CLK_OSC); 712 + 713 + break; 714 + default: 715 + dev_err(sma1307->dev, "%s: Invalid value (%d)\n", 716 + __func__, mux); 717 + return -EINVAL; 718 + } 719 + break; 720 + } 721 + return 0; 722 + } 723 + 724 + static int sma1307_aif_out_event(struct snd_soc_dapm_widget *w, 725 + struct snd_kcontrol *kcontrol, int event) 726 + { 727 + struct snd_soc_component *component = 728 + snd_soc_dapm_to_component(w->dapm); 729 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 730 + unsigned int mux = 0, val = 0, mask = 0; 731 + 732 + if (!strcmp(w->name, SMA1307_AIF_OUT0_NAME)) { 733 + mux = sma1307->dapm_aif_out0; 734 + val = mux; 735 + mask = SMA1307_SDO_OUT0_SEL_MASK; 736 + } else if (!strcmp(w->name, SMA1307_AIF_OUT1_NAME)) { 737 + mux = sma1307->dapm_aif_out1; 738 + val = mux << 3; 739 + mask = SMA1307_SDO_OUT1_SEL_MASK; 740 + } else { 741 + dev_err(sma1307->dev, "%s: Invalid widget - %s\n", 742 + __func__, w->name); 743 + return -EINVAL; 744 + } 745 + switch (event) { 746 + case SND_SOC_DAPM_PRE_PMU: 747 + regmap_update_bits(sma1307->regmap, SMA1307_09_OUTPUT_CTRL, 748 + mask, val); 749 + break; 750 + } 751 + return 0; 752 + } 753 + 754 + static int sma1307_sdo_event(struct snd_soc_dapm_widget *w, 755 + struct snd_kcontrol *kcontrol, int event) 756 + { 757 + struct snd_soc_component *component = 758 + snd_soc_dapm_to_component(w->dapm); 759 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 760 + 761 + switch (event) { 762 + case SND_SOC_DAPM_PRE_PMU: 763 + regmap_update_bits(sma1307->regmap, 764 + SMA1307_09_OUTPUT_CTRL, 765 + SMA1307_PORT_CONFIG_MASK, 766 + SMA1307_OUTPUT_PORT_ENABLE); 767 + regmap_update_bits(sma1307->regmap, 768 + SMA1307_A3_TOP_MAN2, 769 + SMA1307_SDO_OUTPUT_MASK, 770 + SMA1307_LOGIC_OUTPUT); 771 + break; 772 + case SND_SOC_DAPM_POST_PMD: 773 + regmap_update_bits(sma1307->regmap, 774 + SMA1307_09_OUTPUT_CTRL, 775 + SMA1307_PORT_CONFIG_MASK, 776 + SMA1307_INPUT_PORT_ONLY); 777 + regmap_update_bits(sma1307->regmap, 778 + SMA1307_A3_TOP_MAN2, 779 + SMA1307_SDO_OUTPUT_MASK, 780 + SMA1307_HIGH_Z_OUTPUT); 781 + break; 782 + } 783 + return 0; 784 + } 785 + 786 + static int sma1307_power_event(struct snd_soc_dapm_widget *w, 787 + struct snd_kcontrol *kcontrol, int event) 788 + { 789 + struct snd_soc_component *component = 790 + snd_soc_dapm_to_component(w->dapm); 791 + 792 + switch (event) { 793 + case SND_SOC_DAPM_POST_PMU: 794 + sma1307_startup(component); 795 + break; 796 + case SND_SOC_DAPM_PRE_PMD: 797 + sma1307_shutdown(component); 798 + break; 799 + } 800 + return 0; 801 + } 802 + 803 + static int sma1307_dapm_aif_in_get(struct snd_kcontrol *kcontrol, 804 + struct snd_ctl_elem_value *ucontrol) 805 + { 806 + struct snd_soc_dapm_context *dapm = 807 + snd_soc_dapm_kcontrol_dapm(kcontrol); 808 + struct sma1307_priv *sma1307 = 809 + snd_soc_component_get_drvdata(dapm->component); 810 + 811 + ucontrol->value.enumerated.item[0] = (unsigned int)sma1307->dapm_aif_in; 812 + snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 813 + 814 + return 0; 815 + } 816 + 817 + static int sma1307_dapm_aif_in_put(struct snd_kcontrol *kcontrol, 818 + struct snd_ctl_elem_value *ucontrol) 819 + { 820 + struct snd_soc_dapm_context *dapm = 821 + snd_soc_dapm_kcontrol_dapm(kcontrol); 822 + struct sma1307_priv *sma1307 = 823 + snd_soc_component_get_drvdata(dapm->component); 824 + int val = (int)ucontrol->value.enumerated.item[0]; 825 + bool change; 826 + 827 + if ((val < 0) || (val >= ARRAY_SIZE(sma1307_aif_in_source_text))) { 828 + dev_err(sma1307->dev, "%s: Out of range\n", __func__); 829 + return -EINVAL; 830 + } 831 + 832 + if (sma1307->dapm_aif_in != val) { 833 + change = true; 834 + sma1307->dapm_aif_in = val; 835 + } else 836 + change = false; 837 + 838 + snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 839 + 840 + return change; 841 + } 842 + 843 + static int sma1307_dapm_sdo_setting_get(struct snd_kcontrol *kcontrol, 844 + struct snd_ctl_elem_value *ucontrol) 845 + { 846 + struct snd_soc_dapm_context *dapm = 847 + snd_soc_dapm_kcontrol_dapm(kcontrol); 848 + struct sma1307_priv *sma1307 = 849 + snd_soc_component_get_drvdata(dapm->component); 850 + 851 + ucontrol->value.enumerated.item[0] = 852 + (unsigned int)sma1307->dapm_sdo_setting; 853 + snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 854 + 855 + return 0; 856 + } 857 + 858 + static int sma1307_dapm_sdo_setting_put(struct snd_kcontrol *kcontrol, 859 + struct snd_ctl_elem_value *ucontrol) 860 + { 861 + struct snd_soc_dapm_context *dapm = 862 + snd_soc_dapm_kcontrol_dapm(kcontrol); 863 + struct sma1307_priv *sma1307 = 864 + snd_soc_component_get_drvdata(dapm->component); 865 + int val = (int)ucontrol->value.enumerated.item[0]; 866 + bool change; 867 + 868 + if ((val < 0) || (val >= ARRAY_SIZE(sma1307_sdo_setting_text))) { 869 + dev_err(sma1307->dev, "%s: Out of range\n", __func__); 870 + return -EINVAL; 871 + } 872 + 873 + if (sma1307->dapm_sdo_setting != val) { 874 + change = true; 875 + sma1307->dapm_sdo_setting = val; 876 + } else 877 + change = false; 878 + 879 + snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 880 + 881 + return change; 882 + } 883 + 884 + static int sma1307_dapm_aif_out_get(struct snd_kcontrol *kcontrol, 885 + struct snd_ctl_elem_value *ucontrol) 886 + { 887 + struct snd_soc_dapm_context *dapm = 888 + snd_soc_dapm_kcontrol_dapm(kcontrol); 889 + struct sma1307_priv *sma1307 = 890 + snd_soc_component_get_drvdata(dapm->component); 891 + unsigned int val = 0; 892 + 893 + if (!strcmp(kcontrol->id.name, SMA1307_AIF_OUT0_NAME)) { 894 + val = (unsigned int)sma1307->dapm_aif_out0; 895 + } else if (!strcmp(kcontrol->id.name, SMA1307_AIF_OUT1_NAME)) { 896 + val = (unsigned int)sma1307->dapm_aif_out1; 897 + } else { 898 + dev_err(sma1307->dev, "%s: Invalid Control ID - %s\n", 899 + __func__, kcontrol->id.name); 900 + return -EINVAL; 901 + } 902 + ucontrol->value.enumerated.item[0] = val; 903 + snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 904 + 905 + return 0; 906 + } 907 + 908 + static int sma1307_dapm_aif_out_put(struct snd_kcontrol *kcontrol, 909 + struct snd_ctl_elem_value *ucontrol) 910 + { 911 + struct snd_soc_dapm_context *dapm = 912 + snd_soc_dapm_kcontrol_dapm(kcontrol); 913 + struct sma1307_priv *sma1307 = 914 + snd_soc_component_get_drvdata(dapm->component); 915 + int val = (int)ucontrol->value.enumerated.item[0]; 916 + bool change; 917 + 918 + if ((val < 0) || (val >= ARRAY_SIZE(sma1307_aif_out_source_text))) { 919 + dev_err(sma1307->dev, "%s: Out of range\n", __func__); 920 + return -EINVAL; 921 + } 922 + 923 + if (!strcmp(kcontrol->id.name, SMA1307_AIF_OUT0_NAME)) { 924 + if (sma1307->dapm_aif_out0 != val) { 925 + change = true; 926 + sma1307->dapm_aif_out0 = val; 927 + } else 928 + change = false; 929 + } else if (!strcmp(kcontrol->id.name, SMA1307_AIF_OUT1_NAME)) { 930 + if (sma1307->dapm_aif_out1 != val) { 931 + change = true; 932 + sma1307->dapm_aif_out1 = val; 933 + } else 934 + change = false; 935 + } else { 936 + dev_err(sma1307->dev, "%s: Invalid Control ID - %s\n", 937 + __func__, kcontrol->id.name); 938 + return -EINVAL; 939 + } 940 + 941 + snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 942 + 943 + return change; 944 + } 945 + 946 + static int sma1307_dapm_sdo_enable_get(struct snd_kcontrol *kcontrol, 947 + struct snd_ctl_elem_value *ucontrol) 948 + { 949 + struct snd_soc_dapm_context *dapm = 950 + snd_soc_dapm_kcontrol_dapm(kcontrol); 951 + struct sma1307_priv *sma1307 = 952 + snd_soc_component_get_drvdata(dapm->component); 953 + 954 + ucontrol->value.integer.value[0] = (long)sma1307->dapm_sdo_en; 955 + snd_soc_dapm_put_volsw(kcontrol, ucontrol); 956 + 957 + return 0; 958 + } 959 + 960 + static int sma1307_dapm_sdo_enable_put(struct snd_kcontrol *kcontrol, 961 + struct snd_ctl_elem_value *ucontrol) 962 + { 963 + struct snd_soc_dapm_context *dapm = 964 + snd_soc_dapm_kcontrol_dapm(kcontrol); 965 + struct sma1307_priv *sma1307 = 966 + snd_soc_component_get_drvdata(dapm->component); 967 + int val = (int)ucontrol->value.integer.value[0]; 968 + bool change; 969 + 970 + if ((val < 0) || (val > 1)) { 971 + dev_err(sma1307->dev, "%s: Out of range\n", __func__); 972 + return -EINVAL; 973 + } 974 + 975 + if (sma1307->dapm_sdo_en != val) { 976 + change = true; 977 + sma1307->dapm_sdo_en = val; 978 + } else 979 + change = false; 980 + 981 + snd_soc_dapm_put_volsw(kcontrol, ucontrol); 982 + 983 + return change; 984 + } 985 + 986 + static const struct snd_kcontrol_new sma1307_aif_in_source_control = { 987 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 988 + .name = SMA1307_AIF_IN_NAME, 989 + .info = snd_soc_info_enum_double, 990 + .get = sma1307_dapm_aif_in_get, 991 + .put = sma1307_dapm_aif_in_put, 992 + .private_value = (unsigned long)&sma1307_aif_in_source_enum 993 + }; 994 + 995 + static const struct snd_kcontrol_new sma1307_sdo_setting_control = { 996 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 997 + .name = "SDO Setting", 998 + .info = snd_soc_info_enum_double, 999 + .get = sma1307_dapm_sdo_setting_get, 1000 + .put = sma1307_dapm_sdo_setting_put, 1001 + .private_value = (unsigned long)&sma1307_sdo_setting_enum 1002 + }; 1003 + 1004 + static const struct snd_kcontrol_new sma1307_aif_out0_source_control = { 1005 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1006 + .name = SMA1307_AIF_OUT0_NAME, 1007 + .info = snd_soc_info_enum_double, 1008 + .get = sma1307_dapm_aif_out_get, 1009 + .put = sma1307_dapm_aif_out_put, 1010 + .private_value = (unsigned long)&sma1307_aif_out_source_enum 1011 + }; 1012 + 1013 + static const struct snd_kcontrol_new sma1307_aif_out1_source_control = { 1014 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1015 + .name = SMA1307_AIF_OUT1_NAME, 1016 + .info = snd_soc_info_enum_double, 1017 + .get = sma1307_dapm_aif_out_get, 1018 + .put = sma1307_dapm_aif_out_put, 1019 + .private_value = (unsigned long)&sma1307_aif_out_source_enum 1020 + }; 1021 + 1022 + static const struct snd_kcontrol_new sma1307_sdo_control = { 1023 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1024 + .name = "Switch", 1025 + .info = snd_soc_info_volsw, 1026 + .get = sma1307_dapm_sdo_enable_get, 1027 + .put = sma1307_dapm_sdo_enable_put, 1028 + .private_value = SOC_SINGLE_VALUE(SND_SOC_NOPM, 0, 1, 0, 0) 1029 + }; 1030 + 1031 + static const struct snd_kcontrol_new sma1307_enable_control = 1032 + SOC_DAPM_SINGLE("Switch", SMA1307_00_SYSTEM_CTRL, 0, 1, 0); 1033 + 1034 + static const struct snd_kcontrol_new sma1307_binary_mode_control[] = { 1035 + SOC_ENUM_EXT("Binary Mode", sma1307_binary_mode_enum, 1036 + snd_soc_get_enum_double, sma1307_binary_mode_put), 1037 + }; 1038 + 1039 + static const struct snd_kcontrol_new sma1307_snd_controls[] = { 1040 + SOC_SINGLE_TLV(SMA1307_VOL_CTRL_NAME, SMA1307_0A_SPK_VOL, 1041 + 0, 167, 1, sma1307_spk_tlv), 1042 + SOC_ENUM_EXT(SMA1307_TDM_RX0_POS_NAME, sma1307_tdm_slot_enum, 1043 + sma1307_tdm_slot_get, sma1307_tdm_slot_put), 1044 + SOC_ENUM_EXT(SMA1307_TDM_RX1_POS_NAME, sma1307_tdm_slot_enum, 1045 + sma1307_tdm_slot_get, sma1307_tdm_slot_put), 1046 + SOC_ENUM_EXT(SMA1307_TDM_TX0_POS_NAME, sma1307_tdm_slot_enum, 1047 + sma1307_tdm_slot_get, sma1307_tdm_slot_put), 1048 + SOC_ENUM_EXT(SMA1307_TDM_TX1_POS_NAME, sma1307_tdm_slot_enum, 1049 + sma1307_tdm_slot_get, sma1307_tdm_slot_put), 1050 + SOC_ENUM_EXT(SMA1307_RESET_CTRL_NAME, sma1307_reset_enum, 1051 + snd_soc_get_enum_double, sma1307_reset_put), 1052 + SOC_SINGLE_BOOL_EXT(SMA1307_FORCE_MUTE_CTRL_NAME, 0, 1053 + sma1307_force_mute_get, sma1307_force_mute_put), 1054 + SOC_SINGLE_BOOL_EXT(SMA1307_OT1_SW_PROT_CTRL_NAME, 0, 1055 + sma1307_sw_ot1_prot_get, sma1307_sw_ot1_prot_put), 1056 + SOC_SINGLE_BOOL_EXT(SMA1307_CHECK_FAULT_STATUS_NAME, 0, 1057 + sma1307_check_fault_status_get, 1058 + sma1307_check_fault_status_put), 1059 + SOC_SINGLE_EXT(SMA1307_CHECK_FAULT_PERIOD_NAME, SND_SOC_NOPM, 0, 600, 0, 1060 + sma1307_check_fault_period_get, 1061 + sma1307_check_fault_period_put), 1062 + }; 1063 + 1064 + static const struct snd_soc_dapm_widget sma1307_dapm_widgets[] = { 1065 + /* platform domain */ 1066 + SND_SOC_DAPM_OUTPUT("SPK"), 1067 + SND_SOC_DAPM_INPUT("SDO"), 1068 + 1069 + /* path domain */ 1070 + SND_SOC_DAPM_MUX_E(SMA1307_AIF_IN_NAME, SND_SOC_NOPM, 0, 0, 1071 + &sma1307_aif_in_source_control, 1072 + sma1307_aif_in_event, 1073 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 1074 + SND_SOC_DAPM_MUX_E("SDO Setting", SND_SOC_NOPM, 0, 0, 1075 + &sma1307_sdo_setting_control, 1076 + sma1307_sdo_setting_event, 1077 + SND_SOC_DAPM_PRE_PMU), 1078 + SND_SOC_DAPM_MUX_E(SMA1307_AIF_OUT0_NAME, SND_SOC_NOPM, 0, 0, 1079 + &sma1307_aif_out0_source_control, 1080 + sma1307_aif_out_event, 1081 + SND_SOC_DAPM_PRE_PMU), 1082 + SND_SOC_DAPM_MUX_E(SMA1307_AIF_OUT1_NAME, SND_SOC_NOPM, 0, 0, 1083 + &sma1307_aif_out1_source_control, 1084 + sma1307_aif_out_event, 1085 + SND_SOC_DAPM_PRE_PMU), 1086 + SND_SOC_DAPM_SWITCH_E("SDO Enable", SND_SOC_NOPM, 0, 0, 1087 + &sma1307_sdo_control, 1088 + sma1307_sdo_event, 1089 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 1090 + SND_SOC_DAPM_MIXER("Entry", SND_SOC_NOPM, 0, 0, NULL, 0), 1091 + SND_SOC_DAPM_OUT_DRV_E("AMP Power", SND_SOC_NOPM, 0, 0, NULL, 0, 1092 + sma1307_power_event, 1093 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD | 1094 + SND_SOC_DAPM_POST_PMU), 1095 + SND_SOC_DAPM_SWITCH("AMP Enable", SND_SOC_NOPM, 0, 0, 1096 + &sma1307_enable_control), 1097 + 1098 + /* stream domain */ 1099 + SND_SOC_DAPM_AIF_IN("AIF IN", "Playback", 0, SND_SOC_NOPM, 0, 0), 1100 + SND_SOC_DAPM_AIF_OUT("AIF OUT", "Capture", 0, SND_SOC_NOPM, 0, 0), 1101 + }; 1102 + 1103 + static const struct snd_soc_dapm_route sma1307_audio_map[] = { 1104 + /* Playback */ 1105 + { "AIF IN Source", "Mono", "AIF IN" }, 1106 + { "AIF IN Source", "Left", "AIF IN" }, 1107 + { "AIF IN Source", "Right", "AIF IN" }, 1108 + 1109 + { "SDO Enable", "Switch", "AIF IN" }, 1110 + 1111 + { "SDO Setting", "Data_One_48k", "SDO Enable" }, 1112 + { "SDO Setting", "Data_Two_48k", "SDO Enable" }, 1113 + { "SDO Setting", "Data_Two_24k", "SDO Enable" }, 1114 + { "SDO Setting", "Clk_PLL", "SDO Enable" }, 1115 + { "SDO Setting", "Clk_OSC", "SDO Enable" }, 1116 + 1117 + { "AIF OUT0 Source", "Disable", "SDO Setting" }, 1118 + { "AIF OUT0 Source", "After_FmtC", "SDO Setting" }, 1119 + { "AIF OUT0 Source", "After_Mixer", "SDO Setting" }, 1120 + { "AIF OUT0 Source", "After_DSP", "SDO Setting" }, 1121 + { "AIF OUT0 Source", "Vrms2_Avg", "SDO Setting" }, 1122 + { "AIF OUT0 Source", "Battery", "SDO Setting" }, 1123 + { "AIF OUT0 Source", "Temperature", "SDO Setting" }, 1124 + { "AIF OUT0 Source", "After_Delay", "SDO Setting" }, 1125 + 1126 + { "AIF OUT1 Source", "Disable", "SDO Setting" }, 1127 + { "AIF OUT1 Source", "After_FmtC", "SDO Setting" }, 1128 + { "AIF OUT1 Source", "After_Mixer", "SDO Setting" }, 1129 + { "AIF OUT1 Source", "After_DSP", "SDO Setting" }, 1130 + { "AIF OUT1 Source", "Vrms2_Avg", "SDO Setting" }, 1131 + { "AIF OUT1 Source", "Battery", "SDO Setting" }, 1132 + { "AIF OUT1 Source", "Temperature", "SDO Setting" }, 1133 + { "AIF OUT1 Source", "After_Delay", "SDO Setting" }, 1134 + 1135 + { "Entry", NULL, "AIF OUT0 Source" }, 1136 + { "Entry", NULL, "AIF OUT1 Source" }, 1137 + { "Entry", NULL, "AIF IN Source" }, 1138 + 1139 + { "AMP Power", NULL, "Entry" }, 1140 + 1141 + { "AMP Enable", "Switch", "AMP Power" }, 1142 + { "SPK", NULL, "AMP Enable" }, 1143 + 1144 + /* Capture */ 1145 + { "AIF OUT", NULL, "AMP Enable" }, 1146 + }; 1147 + 1148 + static void sma1307_setup_pll(struct snd_soc_component *component, 1149 + unsigned int bclk) 1150 + { 1151 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1152 + 1153 + int i = 0; 1154 + 1155 + dev_dbg(component->dev, "%s: BCLK = %dHz\n", __func__, bclk); 1156 + 1157 + if (sma1307->sys_clk_id == SMA1307_PLL_CLKIN_MCLK) { 1158 + dev_warn(component->dev, "%s: MCLK is not supported\n", 1159 + __func__); 1160 + } else if (sma1307->sys_clk_id == SMA1307_PLL_CLKIN_BCLK) { 1161 + for (i = 0; i < sma1307->num_of_pll_matches; i++) { 1162 + if (sma1307->pll_matches[i].input_clk == bclk) 1163 + break; 1164 + } 1165 + if (i == sma1307->num_of_pll_matches) { 1166 + dev_warn(component->dev, 1167 + "%s: No matching value between pll table and SCK\n", 1168 + __func__); 1169 + return; 1170 + } 1171 + 1172 + regmap_update_bits(sma1307->regmap, 1173 + SMA1307_A2_TOP_MAN1, 1174 + SMA1307_PLL_MASK, SMA1307_PLL_ON); 1175 + } 1176 + 1177 + regmap_write(sma1307->regmap, SMA1307_8B_PLL_POST_N, 1178 + sma1307->pll_matches[i].post_n); 1179 + regmap_write(sma1307->regmap, SMA1307_8C_PLL_N, 1180 + sma1307->pll_matches[i].n); 1181 + regmap_write(sma1307->regmap, SMA1307_8D_PLL_A_SETTING, 1182 + sma1307->pll_matches[i].vco); 1183 + regmap_write(sma1307->regmap, SMA1307_8E_PLL_P_CP, 1184 + sma1307->pll_matches[i].p_cp); 1185 + } 1186 + 1187 + static int sma1307_dai_hw_params_amp(struct snd_pcm_substream *substream, 1188 + struct snd_pcm_hw_params *params, 1189 + struct snd_soc_dai *dai) 1190 + { 1191 + struct snd_soc_component *component = dai->component; 1192 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1193 + unsigned int bclk = 0; 1194 + int ret = 0; 1195 + 1196 + if (sma1307->format == SND_SOC_DAIFMT_DSP_A) 1197 + bclk = params_rate(params) * sma1307->frame_size; 1198 + else 1199 + bclk = params_rate(params) * params_physical_width(params) 1200 + * params_channels(params); 1201 + 1202 + dev_dbg(component->dev, 1203 + "%s: rate = %d : bit size = %d : channel = %d\n", 1204 + __func__, params_rate(params), params_width(params), 1205 + params_channels(params)); 1206 + 1207 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 1208 + if (sma1307->sys_clk_id == SMA1307_PLL_CLKIN_BCLK) { 1209 + if (sma1307->last_bclk != bclk) { 1210 + sma1307_setup_pll(component, bclk); 1211 + sma1307->last_bclk = bclk; 1212 + } 1213 + } 1214 + 1215 + switch (params_rate(params)) { 1216 + case 8000: 1217 + case 12000: 1218 + case 16000: 1219 + case 24000: 1220 + case 32000: 1221 + case 44100: 1222 + case 48000: 1223 + break; 1224 + 1225 + case 96000: 1226 + dev_warn(component->dev, 1227 + "%s: %d rate not support SDO\n", __func__, 1228 + params_rate(params)); 1229 + break; 1230 + 1231 + default: 1232 + dev_err(component->dev, "%s: not support rate : %d\n", 1233 + __func__, params_rate(params)); 1234 + 1235 + return -EINVAL; 1236 + } 1237 + 1238 + /* substream->stream is SNDRV_PCM_STREAM_CAPTURE */ 1239 + } else { 1240 + 1241 + switch (params_format(params)) { 1242 + case SNDRV_PCM_FORMAT_S16_LE: 1243 + regmap_update_bits(sma1307->regmap, 1244 + SMA1307_A4_TOP_MAN3, 1245 + SMA1307_SCK_RATE_MASK 1246 + | 1247 + SMA1307_DATA_WIDTH_MASK, 1248 + SMA1307_SCK_32FS | 1249 + SMA1307_DATA_16BIT); 1250 + break; 1251 + 1252 + case SNDRV_PCM_FORMAT_S24_LE: 1253 + regmap_update_bits(sma1307->regmap, 1254 + SMA1307_A4_TOP_MAN3, 1255 + SMA1307_SCK_RATE_MASK 1256 + | 1257 + SMA1307_DATA_WIDTH_MASK, 1258 + SMA1307_SCK_64FS | 1259 + SMA1307_DATA_24BIT); 1260 + break; 1261 + 1262 + case SNDRV_PCM_FORMAT_S32_LE: 1263 + regmap_update_bits(sma1307->regmap, 1264 + SMA1307_A4_TOP_MAN3, 1265 + SMA1307_SCK_RATE_MASK 1266 + | 1267 + SMA1307_DATA_WIDTH_MASK, 1268 + SMA1307_SCK_64FS | 1269 + SMA1307_DATA_24BIT); 1270 + break; 1271 + default: 1272 + dev_err(component->dev, 1273 + "%s: not support data bit : %d\n", __func__, 1274 + params_format(params)); 1275 + return -EINVAL; 1276 + } 1277 + } 1278 + 1279 + switch (sma1307->format) { 1280 + case SND_SOC_DAIFMT_I2S: 1281 + regmap_update_bits(sma1307->regmap, 1282 + SMA1307_01_INPUT_CTRL1, 1283 + SMA1307_I2S_MODE_MASK, 1284 + SMA1307_STANDARD_I2S); 1285 + regmap_update_bits(sma1307->regmap, 1286 + SMA1307_A4_TOP_MAN3, 1287 + SMA1307_INTERFACE_MASK, 1288 + SMA1307_I2S_FORMAT); 1289 + break; 1290 + case SND_SOC_DAIFMT_LEFT_J: 1291 + regmap_update_bits(sma1307->regmap, 1292 + SMA1307_01_INPUT_CTRL1, 1293 + SMA1307_I2S_MODE_MASK, SMA1307_LJ); 1294 + regmap_update_bits(sma1307->regmap, 1295 + SMA1307_A4_TOP_MAN3, 1296 + SMA1307_INTERFACE_MASK, 1297 + SMA1307_LJ_FORMAT); 1298 + break; 1299 + case SND_SOC_DAIFMT_RIGHT_J: 1300 + switch (params_width(params)) { 1301 + case 16: 1302 + regmap_update_bits(sma1307->regmap, 1303 + SMA1307_01_INPUT_CTRL1, 1304 + SMA1307_I2S_MODE_MASK, 1305 + SMA1307_RJ_16BIT); 1306 + break; 1307 + case 24: 1308 + case 32: 1309 + regmap_update_bits(sma1307->regmap, 1310 + SMA1307_01_INPUT_CTRL1, 1311 + SMA1307_I2S_MODE_MASK, 1312 + SMA1307_RJ_24BIT); 1313 + break; 1314 + } 1315 + break; 1316 + case SND_SOC_DAIFMT_DSP_A: 1317 + regmap_update_bits(sma1307->regmap, 1318 + SMA1307_01_INPUT_CTRL1, 1319 + SMA1307_I2S_MODE_MASK, 1320 + SMA1307_STANDARD_I2S); 1321 + regmap_update_bits(sma1307->regmap, 1322 + SMA1307_A4_TOP_MAN3, 1323 + SMA1307_INTERFACE_MASK, 1324 + SMA1307_TDM_FORMAT); 1325 + break; 1326 + } 1327 + 1328 + switch (params_width(params)) { 1329 + case 16: 1330 + case 24: 1331 + case 32: 1332 + break; 1333 + default: 1334 + dev_err(component->dev, 1335 + "%s: not support data bit : %d\n", __func__, 1336 + params_format(params)); 1337 + return -EINVAL; 1338 + } 1339 + if (ret < 0) 1340 + return -EINVAL; 1341 + 1342 + return 0; 1343 + } 1344 + 1345 + static int sma1307_dai_set_sysclk_amp(struct snd_soc_dai *dai, 1346 + int clk_id, unsigned int freq, int dir) 1347 + { 1348 + struct snd_soc_component *component = dai->component; 1349 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1350 + 1351 + switch (clk_id) { 1352 + case SMA1307_EXTERNAL_CLOCK_19_2: 1353 + case SMA1307_EXTERNAL_CLOCK_24_576: 1354 + case SMA1307_PLL_CLKIN_MCLK: 1355 + case SMA1307_PLL_CLKIN_BCLK: 1356 + break; 1357 + default: 1358 + dev_err(component->dev, "%s: Invalid clk id: %d\n", 1359 + __func__, clk_id); 1360 + return -EINVAL; 1361 + } 1362 + sma1307->sys_clk_id = clk_id; 1363 + 1364 + return 0; 1365 + } 1366 + 1367 + static int sma1307_dai_set_fmt_amp(struct snd_soc_dai *dai, unsigned int fmt) 1368 + { 1369 + struct snd_soc_component *component = dai->component; 1370 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1371 + 1372 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1373 + 1374 + case SND_SOC_DAIFMT_CBC_CFC: 1375 + dev_dbg(component->dev, 1376 + "%s: %s\n", __func__, "I2S/TDM Device mode"); 1377 + regmap_update_bits(sma1307->regmap, 1378 + SMA1307_01_INPUT_CTRL1, 1379 + SMA1307_CONTROLLER_DEVICE_MASK, 1380 + SMA1307_DEVICE_MODE); 1381 + break; 1382 + 1383 + case SND_SOC_DAIFMT_CBP_CFP: 1384 + dev_dbg(component->dev, 1385 + "%s: %s\n", __func__, "I2S/TDM Controller mode"); 1386 + regmap_update_bits(sma1307->regmap, 1387 + SMA1307_01_INPUT_CTRL1, 1388 + SMA1307_CONTROLLER_DEVICE_MASK, 1389 + SMA1307_CONTROLLER_MODE); 1390 + break; 1391 + 1392 + default: 1393 + dev_err(component->dev, 1394 + "%s: Unsupported Controller/Device : 0x%x\n", 1395 + __func__, fmt); 1396 + return -EINVAL; 1397 + } 1398 + 1399 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 1400 + case SND_SOC_DAIFMT_I2S: 1401 + case SND_SOC_DAIFMT_RIGHT_J: 1402 + case SND_SOC_DAIFMT_LEFT_J: 1403 + case SND_SOC_DAIFMT_DSP_A: 1404 + case SND_SOC_DAIFMT_DSP_B: 1405 + sma1307->format = fmt & SND_SOC_DAIFMT_FORMAT_MASK; 1406 + break; 1407 + default: 1408 + dev_err(component->dev, 1409 + "%s: Unsupported Audio Interface Format : 0x%x\n", 1410 + __func__, fmt); 1411 + return -EINVAL; 1412 + } 1413 + 1414 + switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 1415 + 1416 + case SND_SOC_DAIFMT_IB_NF: 1417 + dev_dbg(component->dev, "%s: %s\n", 1418 + __func__, "Invert BCLK + Normal Frame"); 1419 + regmap_update_bits(sma1307->regmap, 1420 + SMA1307_01_INPUT_CTRL1, 1421 + SMA1307_SCK_RISING_MASK, 1422 + SMA1307_SCK_RISING_EDGE); 1423 + break; 1424 + case SND_SOC_DAIFMT_IB_IF: 1425 + dev_dbg(component->dev, "%s: %s\n", 1426 + __func__, "Invert BCLK + Invert Frame"); 1427 + regmap_update_bits(sma1307->regmap, 1428 + SMA1307_01_INPUT_CTRL1, 1429 + SMA1307_LEFTPOL_MASK 1430 + | SMA1307_SCK_RISING_MASK, 1431 + SMA1307_HIGH_FIRST_CH 1432 + | SMA1307_SCK_RISING_EDGE); 1433 + break; 1434 + case SND_SOC_DAIFMT_NB_IF: 1435 + dev_dbg(component->dev, "%s: %s\n", 1436 + __func__, "Normal BCLK + Invert Frame"); 1437 + regmap_update_bits(sma1307->regmap, 1438 + SMA1307_01_INPUT_CTRL1, 1439 + SMA1307_LEFTPOL_MASK, 1440 + SMA1307_HIGH_FIRST_CH); 1441 + break; 1442 + case SND_SOC_DAIFMT_NB_NF: 1443 + dev_dbg(component->dev, "%s: %s\n", 1444 + __func__, "Normal BCLK + Normal Frame"); 1445 + break; 1446 + default: 1447 + dev_err(component->dev, 1448 + "%s: Unsupported Bit & Frameclock : 0x%x\n", 1449 + __func__, fmt); 1450 + return -EINVAL; 1451 + } 1452 + 1453 + return 0; 1454 + } 1455 + 1456 + static int sma1307_dai_set_tdm_slot(struct snd_soc_dai *dai, 1457 + unsigned int tx_mask, unsigned int rx_mask, 1458 + int slots, int slot_width) 1459 + { 1460 + struct snd_soc_component *component = dai->component; 1461 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1462 + 1463 + dev_dbg(component->dev, "%s: slots = %d, slot_width - %d\n", 1464 + __func__, slots, slot_width); 1465 + 1466 + sma1307->frame_size = slot_width * slots; 1467 + 1468 + regmap_update_bits(sma1307->regmap, 1469 + SMA1307_A4_TOP_MAN3, 1470 + SMA1307_INTERFACE_MASK, SMA1307_TDM_FORMAT); 1471 + 1472 + regmap_update_bits(sma1307->regmap, 1473 + SMA1307_A5_TDM1, 1474 + SMA1307_TDM_TX_MODE_MASK, 1475 + SMA1307_TDM_TX_MONO); 1476 + 1477 + switch (slot_width) { 1478 + case 16: 1479 + regmap_update_bits(sma1307->regmap, 1480 + SMA1307_A6_TDM2, 1481 + SMA1307_TDM_DL_MASK, 1482 + SMA1307_TDM_DL_16); 1483 + break; 1484 + case 32: 1485 + regmap_update_bits(sma1307->regmap, 1486 + SMA1307_A6_TDM2, 1487 + SMA1307_TDM_DL_MASK, 1488 + SMA1307_TDM_DL_32); 1489 + break; 1490 + default: 1491 + dev_err(component->dev, "%s: not support TDM %d slot_width\n", 1492 + __func__, slot_width); 1493 + return -EINVAL; 1494 + } 1495 + 1496 + switch (slots) { 1497 + case 4: 1498 + regmap_update_bits(sma1307->regmap, 1499 + SMA1307_A6_TDM2, 1500 + SMA1307_TDM_N_SLOT_MASK, 1501 + SMA1307_TDM_N_SLOT_4); 1502 + break; 1503 + case 8: 1504 + regmap_update_bits(sma1307->regmap, 1505 + SMA1307_A6_TDM2, 1506 + SMA1307_TDM_N_SLOT_MASK, 1507 + SMA1307_TDM_N_SLOT_8); 1508 + break; 1509 + default: 1510 + dev_err(component->dev, "%s: not support TDM %d slots\n", 1511 + __func__, slots); 1512 + return -EINVAL; 1513 + } 1514 + 1515 + if (sma1307->tdm_slot0_rx < slots) 1516 + regmap_update_bits(sma1307->regmap, 1517 + SMA1307_A5_TDM1, 1518 + SMA1307_TDM_SLOT0_RX_POS_MASK, 1519 + sma1307->tdm_slot0_rx << 3); 1520 + else 1521 + dev_err(component->dev, "%s: Incorrect tdm-slot0-rx %d set\n", 1522 + __func__, sma1307->tdm_slot0_rx); 1523 + 1524 + if (sma1307->tdm_slot1_rx < slots) 1525 + regmap_update_bits(sma1307->regmap, 1526 + SMA1307_A5_TDM1, 1527 + SMA1307_TDM_SLOT1_RX_POS_MASK, 1528 + sma1307->tdm_slot1_rx); 1529 + else 1530 + dev_err(component->dev, "%s: Incorrect tdm-slot1-rx %d set\n", 1531 + __func__, sma1307->tdm_slot1_rx); 1532 + 1533 + if (sma1307->tdm_slot0_tx < slots) 1534 + regmap_update_bits(sma1307->regmap, 1535 + SMA1307_A6_TDM2, 1536 + SMA1307_TDM_SLOT0_TX_POS_MASK, 1537 + sma1307->tdm_slot0_tx << 3); 1538 + else 1539 + dev_err(component->dev, "%s: Incorrect tdm-slot0-tx %d set\n", 1540 + __func__, sma1307->tdm_slot0_tx); 1541 + 1542 + if (sma1307->tdm_slot1_tx < slots) 1543 + regmap_update_bits(sma1307->regmap, 1544 + SMA1307_A6_TDM2, 1545 + SMA1307_TDM_SLOT1_TX_POS_MASK, 1546 + sma1307->tdm_slot1_tx); 1547 + else 1548 + dev_err(component->dev, "%s: Incorrect tdm-slot1-tx %d set\n", 1549 + __func__, sma1307->tdm_slot1_tx); 1550 + 1551 + return 0; 1552 + } 1553 + 1554 + static int sma1307_dai_mute_stream(struct snd_soc_dai *dai, int mute, 1555 + int stream) 1556 + { 1557 + struct snd_soc_component *component = dai->component; 1558 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1559 + 1560 + if (stream == SNDRV_PCM_STREAM_CAPTURE) 1561 + return 0; 1562 + if (mute) { 1563 + dev_dbg(component->dev, "%s: %s\n", __func__, "MUTE"); 1564 + regmap_update_bits(sma1307->regmap, 1565 + SMA1307_0E_MUTE_VOL_CTRL, 1566 + SMA1307_SPK_MUTE_MASK, 1567 + SMA1307_SPK_MUTE); 1568 + } else { 1569 + if (!sma1307->force_mute_status) { 1570 + dev_dbg(component->dev, "%s: %s\n", __func__, 1571 + "UNMUTE"); 1572 + regmap_update_bits(sma1307->regmap, 1573 + SMA1307_0E_MUTE_VOL_CTRL, 1574 + SMA1307_SPK_MUTE_MASK, 1575 + SMA1307_SPK_UNMUTE); 1576 + } else { 1577 + dev_dbg(sma1307->dev, "%s: FORCE MUTE!!!\n", __func__); 1578 + } 1579 + } 1580 + 1581 + return 0; 1582 + } 1583 + 1584 + static const struct snd_soc_dai_ops sma1307_dai_ops_amp = { 1585 + .hw_params = sma1307_dai_hw_params_amp, 1586 + .set_fmt = sma1307_dai_set_fmt_amp, 1587 + .set_sysclk = sma1307_dai_set_sysclk_amp, 1588 + .set_tdm_slot = sma1307_dai_set_tdm_slot, 1589 + .mute_stream = sma1307_dai_mute_stream, 1590 + }; 1591 + 1592 + #define SMA1307_RATES_PLAYBACK SNDRV_PCM_RATE_8000_96000 1593 + #define SMA1307_RATES_CAPTURE SNDRV_PCM_RATE_8000_48000 1594 + #define SMA1307_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ 1595 + SNDRV_PCM_FMTBIT_S32_LE) 1596 + 1597 + static struct snd_soc_dai_driver sma1307_dai[] = { 1598 + { 1599 + .name = "sma1307-amplifier", 1600 + .id = 0, 1601 + .playback = { 1602 + .stream_name = "Playback", 1603 + .channels_min = 1, 1604 + .channels_max = 2, 1605 + .rates = SMA1307_RATES_PLAYBACK, 1606 + .formats = SMA1307_FORMATS, 1607 + }, 1608 + .capture = { 1609 + .stream_name = "Capture", 1610 + .channels_min = 1, 1611 + .channels_max = 2, 1612 + .rates = SMA1307_RATES_CAPTURE, 1613 + .formats = SMA1307_FORMATS, 1614 + }, 1615 + .ops = &sma1307_dai_ops_amp, 1616 + }, 1617 + }; 1618 + 1619 + static void sma1307_check_fault_worker(struct work_struct *work) 1620 + { 1621 + struct sma1307_priv *sma1307 = 1622 + container_of(work, struct sma1307_priv, check_fault_work.work); 1623 + unsigned int status1_val, status2_val; 1624 + char *envp[3] = { NULL, NULL, NULL }; 1625 + 1626 + if (sma1307->tsdw_cnt) 1627 + regmap_read(sma1307->regmap, 1628 + SMA1307_0A_SPK_VOL, &sma1307->cur_vol); 1629 + else 1630 + regmap_read(sma1307->regmap, 1631 + SMA1307_0A_SPK_VOL, &sma1307->init_vol); 1632 + 1633 + regmap_read(sma1307->regmap, SMA1307_FA_STATUS1, &status1_val); 1634 + regmap_read(sma1307->regmap, SMA1307_FB_STATUS2, &status2_val); 1635 + 1636 + if (~status1_val & SMA1307_OT1_OK_STATUS) { 1637 + dev_crit(sma1307->dev, 1638 + "%s: OT1(Over Temperature Level 1)\n", __func__); 1639 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=OT1"); 1640 + if (sma1307->sw_ot1_prot) { 1641 + /* Volume control (Current Volume -3dB) */ 1642 + if ((sma1307->cur_vol + 6) <= 0xFA) { 1643 + sma1307->cur_vol += 6; 1644 + regmap_write(sma1307->regmap, 1645 + SMA1307_0A_SPK_VOL, 1646 + sma1307->cur_vol); 1647 + envp[1] = kasprintf(GFP_KERNEL, 1648 + "VOLUME=0x%02X", sma1307->cur_vol); 1649 + } 1650 + } 1651 + sma1307->tsdw_cnt++; 1652 + } else if (sma1307->tsdw_cnt) { 1653 + regmap_write(sma1307->regmap, 1654 + SMA1307_0A_SPK_VOL, sma1307->init_vol); 1655 + sma1307->tsdw_cnt = 0; 1656 + sma1307->cur_vol = sma1307->init_vol; 1657 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=OT1_CLEAR"); 1658 + envp[1] = kasprintf(GFP_KERNEL, 1659 + "VOLUME=0x%02X", sma1307->cur_vol); 1660 + } 1661 + 1662 + if (~status1_val & SMA1307_OT2_OK_STATUS) { 1663 + dev_crit(sma1307->dev, 1664 + "%s: OT2(Over Temperature Level 2)\n", __func__); 1665 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=OT2"); 1666 + } 1667 + if (status1_val & SMA1307_UVLO_STATUS) { 1668 + dev_crit(sma1307->dev, 1669 + "%s: UVLO(Under Voltage Lock Out)\n", __func__); 1670 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=UVLO"); 1671 + } 1672 + if (status1_val & SMA1307_OVP_BST_STATUS) { 1673 + dev_crit(sma1307->dev, 1674 + "%s: OVP_BST(Over Voltage Protection)\n", __func__); 1675 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=OVP_BST"); 1676 + } 1677 + if (status2_val & SMA1307_OCP_SPK_STATUS) { 1678 + dev_crit(sma1307->dev, 1679 + "%s: OCP_SPK(Over Current Protect SPK)\n", __func__); 1680 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=OCP_SPK"); 1681 + } 1682 + if (status2_val & SMA1307_OCP_BST_STATUS) { 1683 + dev_crit(sma1307->dev, 1684 + "%s: OCP_BST(Over Current Protect Boost)\n", __func__); 1685 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=OCP_BST"); 1686 + } 1687 + if (status2_val & SMA1307_CLK_MON_STATUS) { 1688 + dev_crit(sma1307->dev, 1689 + "%s: CLK_FAULT(No clock input)\n", __func__); 1690 + envp[0] = kasprintf(GFP_KERNEL, "STATUS=CLK_FAULT"); 1691 + } 1692 + 1693 + if (envp[0] != NULL) { 1694 + if (kobject_uevent_env(sma1307->kobj, KOBJ_CHANGE, envp)) 1695 + dev_err(sma1307->dev, 1696 + "%s: Error sending uevent\n", __func__); 1697 + kfree(envp[0]); 1698 + kfree(envp[1]); 1699 + } 1700 + 1701 + if (sma1307->check_fault_status) { 1702 + if (sma1307->check_fault_period > 0) 1703 + queue_delayed_work(system_freezable_wq, 1704 + &sma1307->check_fault_work, 1705 + sma1307->check_fault_period * HZ); 1706 + else 1707 + queue_delayed_work(system_freezable_wq, 1708 + &sma1307->check_fault_work, 1709 + CHECK_PERIOD_TIME * HZ); 1710 + } 1711 + } 1712 + 1713 + static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *file) 1714 + { 1715 + const struct firmware *fw; 1716 + int *data, size, offset, num_mode; 1717 + 1718 + request_firmware(&fw, file, sma1307->dev); 1719 + 1720 + if (!fw) { 1721 + dev_err(sma1307->dev, "%s: failed to read \"%s\"\n", 1722 + __func__, setting_file); 1723 + release_firmware(fw); 1724 + sma1307->set.status = false; 1725 + return; 1726 + } else if ((fw->size) < SMA1307_SETTING_HEADER_SIZE) { 1727 + dev_err(sma1307->dev, "%s: Invalid file\n", __func__); 1728 + release_firmware(fw); 1729 + sma1307->set.status = false; 1730 + return; 1731 + } 1732 + 1733 + data = kzalloc(fw->size, GFP_KERNEL); 1734 + size = fw->size >> 2; 1735 + memcpy(data, fw->data, fw->size); 1736 + 1737 + release_firmware(fw); 1738 + 1739 + /* HEADER */ 1740 + sma1307->set.header_size = SMA1307_SETTING_HEADER_SIZE; 1741 + sma1307->set.checksum = data[sma1307->set.header_size - 2]; 1742 + sma1307->set.num_mode = data[sma1307->set.header_size - 1]; 1743 + num_mode = sma1307->set.num_mode; 1744 + sma1307->set.header = devm_kzalloc(sma1307->dev, 1745 + sma1307->set.header_size, 1746 + GFP_KERNEL); 1747 + memcpy(sma1307->set.header, data, 1748 + sma1307->set.header_size * sizeof(int)); 1749 + 1750 + if ((sma1307->set.checksum >> 8) != SMA1307_SETTING_CHECKSUM) { 1751 + dev_err(sma1307->dev, "%s: failed by dismatch \"%s\"\n", 1752 + __func__, setting_file); 1753 + sma1307->set.status = false; 1754 + return; 1755 + } 1756 + 1757 + /* DEFAULT */ 1758 + sma1307->set.def_size = SMA1307_SETTING_DEFAULT_SIZE; 1759 + sma1307->set.def 1760 + = devm_kzalloc(sma1307->dev, 1761 + sma1307->set.def_size * sizeof(int), GFP_KERNEL); 1762 + memcpy(sma1307->set.def, 1763 + &data[sma1307->set.header_size], 1764 + sma1307->set.def_size * sizeof(int)); 1765 + 1766 + /* MODE */ 1767 + offset = sma1307->set.header_size + sma1307->set.def_size; 1768 + sma1307->set.mode_size = DIV_ROUND_CLOSEST(size - offset, num_mode + 1); 1769 + for (int i = 0; i < num_mode; i++) { 1770 + sma1307->set.mode_set[i] 1771 + = devm_kzalloc(sma1307->dev, 1772 + sma1307->set.mode_size * 2 * sizeof(int), 1773 + GFP_KERNEL); 1774 + for (int j = 0; j < sma1307->set.mode_size; j++) { 1775 + sma1307->set.mode_set[i][2 * j] 1776 + = data[offset + ((num_mode + 1) * j)]; 1777 + sma1307->set.mode_set[i][2 * j + 1] 1778 + = data[offset + ((num_mode + 1) * j + i + 1)]; 1779 + } 1780 + } 1781 + 1782 + kfree(data); 1783 + sma1307->set.status = true; 1784 + 1785 + } 1786 + 1787 + static void sma1307_reset(struct snd_soc_component *component) 1788 + { 1789 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1790 + unsigned int status = 0; 1791 + 1792 + regmap_read(sma1307->regmap, SMA1307_FF_DEVICE_INDEX, &status); 1793 + 1794 + sma1307->rev_num = status & SMA1307_REV_NUM_STATUS; 1795 + dev_dbg(component->dev, "%s: SMA1307 Revision %d\n", 1796 + __func__, sma1307->rev_num); 1797 + regmap_read(sma1307->regmap, SMA1307_99_OTP_TRM2, &sma1307->otp_trm2); 1798 + regmap_read(sma1307->regmap, SMA1307_9A_OTP_TRM3, &sma1307->otp_trm3); 1799 + 1800 + if ((sma1307->otp_trm2 & SMA1307_OTP_STAT_MASK) != SMA1307_OTP_STAT_1) 1801 + dev_warn(component->dev, "%s: SMA1307 OTP Status Fail\n", 1802 + __func__); 1803 + 1804 + /* Register Initial Value Setting */ 1805 + sma1307_setting_loaded(sma1307, setting_file); 1806 + if (sma1307->set.status) 1807 + sma1307_set_binary(component); 1808 + else 1809 + sma1307_set_default(component); 1810 + 1811 + regmap_update_bits(sma1307->regmap, 1812 + SMA1307_93_INT_CTRL, 1813 + SMA1307_DIS_INT_MASK, SMA1307_HIGH_Z_INT); 1814 + regmap_write(sma1307->regmap, SMA1307_0A_SPK_VOL, sma1307->init_vol); 1815 + } 1816 + 1817 + static void sma1307_set_binary(struct snd_soc_component *component) 1818 + { 1819 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1820 + int i = 0, mode = 0; 1821 + 1822 + for (i = 0; i < (sma1307->set.def_size); i++) { 1823 + if (sma1307_writeable_register(sma1307->dev, i) 1824 + && ((i < SMA1307_97_OTP_TRM0) 1825 + || (i > SMA1307_9A_OTP_TRM3))) { 1826 + regmap_write(sma1307->regmap, i, sma1307->set.def[i]); 1827 + 1828 + } 1829 + } 1830 + for (i = 0; i < (sma1307->set.mode_size); i++) { 1831 + if (sma1307_writeable_register(sma1307->dev, i) 1832 + && ((i < SMA1307_97_OTP_TRM0) 1833 + || (i > SMA1307_9A_OTP_TRM3))) { 1834 + mode = sma1307->binary_mode; 1835 + regmap_write(sma1307->regmap, 1836 + sma1307->set.mode_set[mode][2 * i], 1837 + sma1307->set.mode_set[mode][2 * i + 1838 + 1]); 1839 + } 1840 + } 1841 + } 1842 + 1843 + static void sma1307_set_default(struct snd_soc_component *component) 1844 + { 1845 + struct sma1307_priv *sma1307 = snd_soc_component_get_drvdata(component); 1846 + int i = 0; 1847 + 1848 + for (i = 0; i < (unsigned int)ARRAY_SIZE(sma1307_reg_def); i++) 1849 + regmap_write(sma1307->regmap, 1850 + sma1307_reg_def[i].reg, 1851 + sma1307_reg_def[i].def); 1852 + 1853 + if (!strcmp(sma1307->name, DEVICE_NAME_SMA1307AQ)) 1854 + sma1307->data->init(sma1307->regmap); 1855 + } 1856 + 1857 + static int sma1307_probe(struct snd_soc_component *component) 1858 + { 1859 + struct snd_soc_dapm_context *dapm = 1860 + snd_soc_component_get_dapm(component); 1861 + 1862 + snd_soc_dapm_sync(dapm); 1863 + 1864 + sma1307_amp_component = component; 1865 + 1866 + snd_soc_add_component_controls(component, sma1307_binary_mode_control, 1867 + ARRAY_SIZE(sma1307_binary_mode_control)); 1868 + sma1307_reset(component); 1869 + 1870 + return 0; 1871 + } 1872 + 1873 + static const struct snd_soc_component_driver sma1307_component = { 1874 + .probe = sma1307_probe, 1875 + .controls = sma1307_snd_controls, 1876 + .num_controls = ARRAY_SIZE(sma1307_snd_controls), 1877 + .dapm_widgets = sma1307_dapm_widgets, 1878 + .num_dapm_widgets = ARRAY_SIZE(sma1307_dapm_widgets), 1879 + .dapm_routes = sma1307_audio_map, 1880 + .num_dapm_routes = ARRAY_SIZE(sma1307_audio_map), 1881 + }; 1882 + 1883 + static const struct regmap_config sma_i2c_regmap = { 1884 + .reg_bits = 8, 1885 + .val_bits = 8, 1886 + 1887 + .max_register = SMA1307_FF_DEVICE_INDEX, 1888 + .readable_reg = sma1307_readable_register, 1889 + .writeable_reg = sma1307_writeable_register, 1890 + .volatile_reg = sma1307_volatile_register, 1891 + 1892 + .reg_defaults = sma1307_reg_def, 1893 + .num_reg_defaults = ARRAY_SIZE(sma1307_reg_def), 1894 + }; 1895 + 1896 + static void sma1307aq_init(struct regmap *regmap) 1897 + { 1898 + /* Guidelines for driving 4ohm load */ 1899 + /* Brown Out Protection */ 1900 + regmap_write(regmap, SMA1307_02_BROWN_OUT_PROT1, 0x62); 1901 + regmap_write(regmap, SMA1307_03_BROWN_OUT_PROT2, 0x5D); 1902 + regmap_write(regmap, SMA1307_04_BROWN_OUT_PROT3, 0x57); 1903 + regmap_write(regmap, SMA1307_05_BROWN_OUT_PROT8, 0x54); 1904 + regmap_write(regmap, SMA1307_06_BROWN_OUT_PROT9, 0x51); 1905 + regmap_write(regmap, 1906 + SMA1307_07_BROWN_OUT_PROT10, 0x4D); 1907 + regmap_write(regmap, 1908 + SMA1307_08_BROWN_OUT_PROT11, 0x4B); 1909 + regmap_write(regmap, SMA1307_27_BROWN_OUT_PROT4, 0x3C); 1910 + regmap_write(regmap, SMA1307_28_BROWN_OUT_PROT5, 0x5B); 1911 + regmap_write(regmap, 1912 + SMA1307_29_BROWN_OUT_PROT12, 0x78); 1913 + regmap_write(regmap, 1914 + SMA1307_2A_BROWN_OUT_PROT13, 0x96); 1915 + regmap_write(regmap, 1916 + SMA1307_2B_BROWN_OUT_PROT14, 0xB4); 1917 + regmap_write(regmap, 1918 + SMA1307_2C_BROWN_OUT_PROT15, 0xD3); 1919 + /* FDPEC Gain */ 1920 + regmap_write(regmap, SMA1307_35_FDPEC_CTRL0, 0x16); 1921 + /* FLT Vdd */ 1922 + regmap_write(regmap, SMA1307_92_FDPEC_CTRL1, 0xA0); 1923 + /* Boost Max */ 1924 + regmap_write(regmap, SMA1307_AB_BOOST_CTRL4, 0x0F); 1925 + } 1926 + 1927 + static const struct sma1307_data sma1307aq_data = { 1928 + .name = DEVICE_NAME_SMA1307AQ, 1929 + .init = sma1307aq_init, 1930 + }; 1931 + 1932 + static int sma1307_i2c_probe(struct i2c_client *client) 1933 + { 1934 + struct sma1307_priv *sma1307; 1935 + const struct sma1307_data *data; 1936 + int ret = 0; 1937 + unsigned int device_info; 1938 + 1939 + sma1307 = devm_kzalloc(&client->dev, 1940 + sizeof(*sma1307), GFP_KERNEL); 1941 + if (!sma1307) 1942 + return -ENOMEM; 1943 + 1944 + sma1307->regmap = devm_regmap_init_i2c(client, &sma_i2c_regmap); 1945 + if (IS_ERR(sma1307->regmap)) { 1946 + return dev_err_probe(&client->dev, PTR_ERR(sma1307->regmap), 1947 + "%s: failed to allocate register map\n", __func__); 1948 + } 1949 + 1950 + data = device_get_match_data(&client->dev); 1951 + if (!data) 1952 + return -ENODEV; 1953 + 1954 + sma1307->data = data; 1955 + 1956 + /* set initial value as normal AMP IC status */ 1957 + sma1307->name = client->name; 1958 + sma1307->format = SND_SOC_DAIFMT_I2S; 1959 + sma1307->sys_clk_id = SMA1307_PLL_CLKIN_BCLK; 1960 + sma1307->num_of_pll_matches = ARRAY_SIZE(sma1307_pll_matches); 1961 + 1962 + sma1307->check_fault_period = CHECK_PERIOD_TIME; 1963 + sma1307->check_fault_status = true; 1964 + sma1307->init_vol = 0x32; 1965 + sma1307->cur_vol = sma1307->init_vol; 1966 + sma1307->sw_ot1_prot = true; 1967 + 1968 + mutex_init(&sma1307->default_lock); 1969 + 1970 + INIT_DELAYED_WORK(&sma1307->check_fault_work, 1971 + sma1307_check_fault_worker); 1972 + 1973 + sma1307->dev = &client->dev; 1974 + sma1307->kobj = &client->dev.kobj; 1975 + 1976 + i2c_set_clientdata(client, sma1307); 1977 + 1978 + sma1307->pll_matches = sma1307_pll_matches; 1979 + 1980 + regmap_read(sma1307->regmap, 1981 + SMA1307_FF_DEVICE_INDEX, &device_info); 1982 + 1983 + if ((device_info & 0xF8) != SMA1307_DEVICE_ID) { 1984 + dev_err(&client->dev, 1985 + "%s: device initialization error (0x%02X)", 1986 + __func__, device_info); 1987 + return -ENODEV; 1988 + } 1989 + dev_dbg(&client->dev, "%s: chip version 0x%02X\n", 1990 + __func__, device_info); 1991 + 1992 + i2c_set_clientdata(client, sma1307); 1993 + 1994 + ret = devm_snd_soc_register_component(&client->dev, 1995 + &sma1307_component, sma1307_dai, 1996 + 1); 1997 + 1998 + if (ret) { 1999 + dev_err(&client->dev, "%s: failed to register component\n", 2000 + __func__); 2001 + 2002 + return ret; 2003 + } 2004 + 2005 + return ret; 2006 + } 2007 + 2008 + static void sma1307_i2c_remove(struct i2c_client *client) 2009 + { 2010 + struct sma1307_priv *sma1307 = 2011 + (struct sma1307_priv *)i2c_get_clientdata(client); 2012 + 2013 + cancel_delayed_work_sync(&sma1307->check_fault_work); 2014 + } 2015 + 2016 + static const struct i2c_device_id sma1307_i2c_id[] = { 2017 + { "sma1307a", 0 }, 2018 + { "sma1307aq", 0 }, 2019 + { } 2020 + }; 2021 + 2022 + MODULE_DEVICE_TABLE(i2c, sma1307_i2c_id); 2023 + 2024 + static const struct of_device_id sma1307_of_match[] = { 2025 + { 2026 + .compatible = "irondevice,sma1307a", 2027 + }, 2028 + { 2029 + .compatible = "irondevice,sma1307aq", 2030 + .data = &sma1307aq_data //AEC-Q100 Qualificated 2031 + }, 2032 + { } 2033 + }; 2034 + 2035 + MODULE_DEVICE_TABLE(of, sma1307_of_match); 2036 + 2037 + static struct i2c_driver sma1307_i2c_driver = { 2038 + .driver = { 2039 + .name = "sma1307", 2040 + .of_match_table = sma1307_of_match, 2041 + }, 2042 + .probe = sma1307_i2c_probe, 2043 + .remove = sma1307_i2c_remove, 2044 + .id_table = sma1307_i2c_id, 2045 + }; 2046 + 2047 + module_i2c_driver(sma1307_i2c_driver); 2048 + 2049 + MODULE_DESCRIPTION("ALSA SoC SMA1307 driver"); 2050 + MODULE_AUTHOR("Gyuhwa Park, <gyuhwa.park@irondevice.com>"); 2051 + MODULE_AUTHOR("KS Jo, <kiseok.jo@irondevice.com>"); 2052 + MODULE_LICENSE("GPL");
+444
sound/soc/codecs/sma1307.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later 2 + * sma1307.h -- sma1307 ALSA SoC Audio driver 3 + * 4 + * Copyright 2024 Iron Device Corporation 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #ifndef _SMA1307_H 12 + #define _SMA1307_H 13 + 14 + #include <sound/soc.h> 15 + 16 + enum sma1307_fault { 17 + SMA1307_FAULT_OT1, 18 + SMA1307_FAULT_OT2, 19 + SMA1307_FAULT_UVLO, 20 + SMA1307_FAULT_OVP_BST, 21 + SMA1307_FAULT_OCP_SPK, 22 + SMA1307_FAULT_OCP_BST, 23 + SMA1307_FAULT_CLK 24 + }; 25 + 26 + enum sma1307_mode { 27 + SMA1307_MONO_MODE, 28 + SMA1307_LEFT_MODE, 29 + SMA1307_RIGHT_MODE, 30 + }; 31 + 32 + enum sma1307_sdo_mode { 33 + SMA1307_OUT_DATA_ONE_48K, 34 + SMA1307_OUT_DATA_TWO_48K, 35 + SMA1307_OUT_DATA_TWO_24K, 36 + SMA1307_OUT_CLK_PLL, 37 + SMA1307_OUT_CLK_OSC 38 + }; 39 + 40 + enum sma1307_sdo_source { 41 + SMA1307_OUT_DISABLE, 42 + SMA1307_OUT_FORMAT_C, 43 + SMA1307_OUT_MIXER_OUT, 44 + SMA1307_OUT_AFTER_DSP, 45 + SMA1307_OUT_VRMS2_AVG, 46 + SMA1307_OUT_BATTERY, 47 + SMA1307_OUT_TEMP, 48 + SMA1307_OUT_AFTER_DELAY 49 + }; 50 + 51 + struct sma1307_setting_file { 52 + bool status; 53 + char *header; 54 + int *def; 55 + int *mode_set[5]; 56 + int checksum; 57 + int num_mode; 58 + size_t header_size; 59 + size_t def_size; 60 + size_t mode_size; 61 + }; 62 + 63 + #define SMA1307_I2C_ADDR_00 0x1e 64 + #define SMA1307_I2C_ADDR_01 0x3e 65 + #define SMA1307_I2C_ADDR_10 0x5e 66 + #define SMA1307_I2C_ADDR_11 0x7e 67 + 68 + #define DEVICE_NAME_SMA1307A "sma1307a" 69 + #define DEVICE_NAME_SMA1307AQ "sma1307aq" 70 + 71 + #define SMA1307_EXTERNAL_CLOCK_19_2 0x00 72 + #define SMA1307_EXTERNAL_CLOCK_24_576 0x01 73 + #define SMA1307_PLL_CLKIN_MCLK 0x02 74 + #define SMA1307_PLL_CLKIN_BCLK 0x03 75 + 76 + #define SMA1307_OFFSET_DEFAULT_MODE 0x00 77 + #define SMA1307_OFFSET_BURNING_MODE 0x01 78 + 79 + #define SMA1307_SETTING_HEADER_SIZE 0x08 80 + #define SMA1307_SETTING_DEFAULT_SIZE 0xC0 81 + 82 + #define SMA1307_DEFAULT_SET 0x00 83 + #define SMA1307_BINARY_FILE_SET 0x01 84 + 85 + /* Controls Name */ 86 + #define SMA1307_REG_CTRL_NAME "Register Byte Control" 87 + #define SMA1307_VOL_CTRL_NAME "Speaker Volume" 88 + #define SMA1307_FORCE_MUTE_CTRL_NAME "Force Mute Switch" 89 + #define SMA1307_TDM_RX0_POS_NAME "TDM RX Slot0 Position" 90 + #define SMA1307_TDM_RX1_POS_NAME "TDM RX Slot1 Position" 91 + #define SMA1307_TDM_TX0_POS_NAME "TDM TX Slot0 Position" 92 + #define SMA1307_TDM_TX1_POS_NAME "TDM TX Slot1 Position" 93 + #define SMA1307_OT1_SW_PROT_CTRL_NAME "OT1 SW Protection Switch" 94 + #define SMA1307_RESET_CTRL_NAME "Reset Switch" 95 + #define SMA1307_CHECK_FAULT_STATUS_NAME "Check Fault Status" 96 + #define SMA1307_CHECK_FAULT_PERIOD_NAME "Check Fault Period" 97 + 98 + /* DAPM Name */ 99 + #define SMA1307_AIF_IN_NAME "AIF IN Source" 100 + #define SMA1307_AIF_OUT0_NAME "AIF OUT0 Source" 101 + #define SMA1307_AIF_OUT1_NAME "AIF OUT1 Source" 102 + 103 + /* 104 + * SMA1307 Register Definition 105 + */ 106 + 107 + /* SMA1307 Register Addresses */ 108 + #define SMA1307_00_SYSTEM_CTRL 0x00 109 + #define SMA1307_01_INPUT_CTRL1 0x01 110 + #define SMA1307_02_BROWN_OUT_PROT1 0x02 111 + #define SMA1307_03_BROWN_OUT_PROT2 0x03 112 + #define SMA1307_04_BROWN_OUT_PROT3 0x04 113 + #define SMA1307_05_BROWN_OUT_PROT8 0x05 114 + #define SMA1307_06_BROWN_OUT_PROT9 0x06 115 + #define SMA1307_07_BROWN_OUT_PROT10 0x07 116 + #define SMA1307_08_BROWN_OUT_PROT11 0x08 117 + #define SMA1307_09_OUTPUT_CTRL 0x09 118 + #define SMA1307_0A_SPK_VOL 0x0A 119 + #define SMA1307_0B_BST_TEST 0x0B 120 + #define SMA1307_0C_BOOST_CTRL8 0x0C 121 + #define SMA1307_0D_SPK_TEST 0x0D 122 + #define SMA1307_0E_MUTE_VOL_CTRL 0x0E 123 + #define SMA1307_0F_VBAT_TEMP_SENSING 0x0F 124 + 125 + #define SMA1307_10_SYSTEM_CTRL1 0x10 126 + #define SMA1307_11_SYSTEM_CTRL2 0x11 127 + #define SMA1307_12_SYSTEM_CTRL3 0x12 128 + #define SMA1307_13_DELAY 0x13 129 + #define SMA1307_14_MODULATOR 0x14 130 + #define SMA1307_15_BASS_SPK1 0x15 131 + #define SMA1307_16_BASS_SPK2 0x16 132 + #define SMA1307_17_BASS_SPK3 0x17 133 + #define SMA1307_18_BASS_SPK4 0x18 134 + #define SMA1307_19_BASS_SPK5 0x19 135 + #define SMA1307_1A_BASS_SPK6 0x1A 136 + #define SMA1307_1B_BASS_SPK7 0x1B 137 + #define SMA1307_1C_BROWN_OUT_PROT20 0x1C 138 + #define SMA1307_1D_BROWN_OUT_PROT0 0x1D 139 + #define SMA1307_1E_TONE_GENERATOR 0x1E 140 + #define SMA1307_1F_TONE_FINE_VOLUME 0x1F 141 + 142 + #define SMA1307_22_COMP_HYS_SEL 0x22 143 + #define SMA1307_23_COMPLIM1 0x23 144 + #define SMA1307_24_COMPLIM2 0x24 145 + #define SMA1307_25_COMPLIM3 0x25 146 + #define SMA1307_26_COMPLIM4 0x26 147 + #define SMA1307_27_BROWN_OUT_PROT4 0x27 148 + #define SMA1307_28_BROWN_OUT_PROT5 0x28 149 + #define SMA1307_29_BROWN_OUT_PROT12 0x29 150 + #define SMA1307_2A_BROWN_OUT_PROT13 0x2A 151 + #define SMA1307_2B_BROWN_OUT_PROT14 0x2B 152 + #define SMA1307_2C_BROWN_OUT_PROT15 0x2C 153 + #define SMA1307_2D_BROWN_OUT_PROT6 0x2D 154 + #define SMA1307_2E_BROWN_OUT_PROT7 0x2E 155 + #define SMA1307_2F_BROWN_OUT_PROT16 0x2F 156 + 157 + #define SMA1307_30_BROWN_OUT_PROT17 0x30 158 + #define SMA1307_31_BROWN_OUT_PROT18 0x31 159 + #define SMA1307_32_BROWN_OUT_PROT19 0x32 160 + #define SMA1307_34_OCP_SPK 0x34 161 + #define SMA1307_35_FDPEC_CTRL0 0x35 162 + #define SMA1307_36_PROTECTION 0x36 163 + #define SMA1307_37_SLOPECTRL 0x37 164 + #define SMA1307_38_POWER_METER 0x38 165 + #define SMA1307_39_PMT_NZ_VAL 0x39 166 + #define SMA1307_3B_TEST1 0x3B 167 + #define SMA1307_3C_TEST2 0x3C 168 + #define SMA1307_3D_TEST3 0x3D 169 + #define SMA1307_3E_IDLE_MODE_CTRL 0x3E 170 + #define SMA1307_3F_ATEST2 0x3F 171 + #define SMA1307_8B_PLL_POST_N 0x8B 172 + #define SMA1307_8C_PLL_N 0x8C 173 + #define SMA1307_8D_PLL_A_SETTING 0x8D 174 + #define SMA1307_8E_PLL_P_CP 0x8E 175 + #define SMA1307_8F_ANALOG_TEST 0x8F 176 + 177 + #define SMA1307_90_CRESTLIM1 0x90 178 + #define SMA1307_91_CRESTLIM2 0x91 179 + #define SMA1307_92_FDPEC_CTRL1 0x92 180 + #define SMA1307_93_INT_CTRL 0x93 181 + #define SMA1307_94_BOOST_CTRL9 0x94 182 + #define SMA1307_95_BOOST_CTRL10 0x95 183 + #define SMA1307_96_BOOST_CTRL11 0x96 184 + #define SMA1307_97_OTP_TRM0 0x97 185 + #define SMA1307_98_OTP_TRM1 0x98 186 + #define SMA1307_99_OTP_TRM2 0x99 187 + #define SMA1307_9A_OTP_TRM3 0x9A 188 + 189 + #define SMA1307_A0_PAD_CTRL0 0xA0 190 + #define SMA1307_A1_PAD_CTRL1 0xA1 191 + #define SMA1307_A2_TOP_MAN1 0xA2 192 + #define SMA1307_A3_TOP_MAN2 0xA3 193 + #define SMA1307_A4_TOP_MAN3 0xA4 194 + #define SMA1307_A5_TDM1 0xA5 195 + #define SMA1307_A6_TDM2 0xA6 196 + #define SMA1307_A7_CLK_MON 0xA7 197 + #define SMA1307_A8_BOOST_CTRL1 0xA8 198 + #define SMA1307_A9_BOOST_CTRL2 0xA9 199 + #define SMA1307_AA_BOOST_CTRL3 0xAA 200 + #define SMA1307_AB_BOOST_CTRL4 0xAB 201 + #define SMA1307_AC_BOOST_CTRL5 0xAC 202 + #define SMA1307_AD_BOOST_CTRL6 0xAD 203 + #define SMA1307_AE_BOOST_CTRL7 0xAE 204 + #define SMA1307_AF_LPF 0xAF 205 + 206 + #define SMA1307_B0_RMS_TC1 0xB0 207 + #define SMA1307_B1_RMS_TC2 0xB1 208 + #define SMA1307_B2_AVG_TC1 0xB2 209 + #define SMA1307_B3_AVG_TC2 0xB3 210 + #define SMA1307_B4_PRVALUE1 0xB4 211 + #define SMA1307_B5_PRVALUE2 0xB5 212 + #define SMA1307_B8_SPK_NG_CTRL1 0xB8 213 + #define SMA1307_B9_SPK_NG_CTRL2 0xB9 214 + #define SMA1307_BA_DGC1 0xBA 215 + #define SMA1307_BB_DGC2 0xBB 216 + #define SMA1307_BC_DGC3 0xBC 217 + #define SMA1307_BD_MCBS_CTRL1 0xBD 218 + #define SMA1307_BE_MCBS_CTRL2 0xBE 219 + 220 + /* Status Register Read Only */ 221 + #define SMA1307_F5_READY_FOR_V_SAR 0xF5 222 + #define SMA1307_F7_READY_FOR_T_SAR 0xF7 223 + #define SMA1307_F8_STATUS_T1 0xF8 224 + #define SMA1307_F9_STATUS_T2 0xF9 225 + #define SMA1307_FA_STATUS1 0xFA 226 + #define SMA1307_FB_STATUS2 0xFB 227 + #define SMA1307_FC_STATUS3 0xFC 228 + #define SMA1307_FD_STATUS4 0xFD 229 + #define SMA1307_FE_STATUS5 0xFE 230 + #define SMA1307_FF_DEVICE_INDEX 0xFF 231 + 232 + /* SMA1307 Registers Bit Fields */ 233 + /* Power On/Off */ 234 + #define SMA1307_POWER_MASK BIT(0) 235 + #define SMA1307_POWER_OFF 0 236 + #define SMA1307_POWER_ON BIT(0) 237 + 238 + /* Reset */ 239 + #define SMA1307_RESET_MASK BIT(1) 240 + #define SMA1307_RESET_ON BIT(1) 241 + 242 + /* Left Polarity */ 243 + #define SMA1307_LEFTPOL_MASK BIT(3) 244 + #define SMA1307_LOW_FIRST_CH 0 245 + #define SMA1307_HIGH_FIRST_CH BIT(3) 246 + 247 + /* SCK Falling/Rising */ 248 + #define SMA1307_SCK_RISING_MASK BIT(2) 249 + #define SMA1307_SCK_FALLING_EDGE 0 250 + #define SMA1307_SCK_RISING_EDGE BIT(2) 251 + 252 + /* SPK Mute */ 253 + #define SMA1307_SPK_MUTE_MASK BIT(0) 254 + #define SMA1307_SPK_UNMUTE 0 255 + #define SMA1307_SPK_MUTE BIT(0) 256 + 257 + /* SPK Mode */ 258 + #define SMA1307_SPK_MODE_MASK (BIT(2)|BIT(3)|BIT(4)) 259 + #define SMA1307_SPK_OFF 0 260 + #define SMA1307_SPK_MONO BIT(2) 261 + #define SMA1307_SPK_STEREO BIT(4) 262 + 263 + /* Mono Mix */ 264 + #define SMA1307_MONOMIX_MASK BIT(0) 265 + #define SMA1307_MONOMIX_OFF 0 266 + #define SMA1307_MONOMIX_ON BIT(0) 267 + 268 + /* LR Data Swap */ 269 + #define SMA1307_LR_DATA_SW_MASK BIT(4) 270 + #define SMA1307_LR_DATA_SW_NORMAL 0 271 + #define SMA1307_LR_DATA_SW_SWAP BIT(4) 272 + 273 + /* PLL On/Off */ 274 + #define SMA1307_PLL_MASK BIT(6) 275 + #define SMA1307_PLL_ON 0 276 + #define SMA1307_PLL_OFF BIT(6) 277 + 278 + /* Input Format */ 279 + #define SMA1307_I2S_MODE_MASK (BIT(4)|BIT(5)|BIT(6)) 280 + #define SMA1307_STANDARD_I2S 0 281 + #define SMA1307_LJ BIT(4) 282 + #define SMA1307_RJ_16BIT BIT(6) 283 + #define SMA1307_RJ_18BIT (BIT(4)|BIT(6)) 284 + #define SMA1307_RJ_20BIT (BIT(5)|BIT(6)) 285 + #define SMA1307_RJ_24BIT (BIT(4)|BIT(5)|BIT(6)) 286 + 287 + /* Controller / Device Setting */ 288 + #define SMA1307_CONTROLLER_DEVICE_MASK BIT(7) 289 + #define SMA1307_DEVICE_MODE 0 290 + #define SMA1307_CONTROLLER_MODE BIT(7) 291 + 292 + /* Port Config */ 293 + #define SMA1307_PORT_CONFIG_MASK (BIT(6)|BIT(7)) 294 + #define SMA1307_INPUT_PORT_ONLY 0 295 + #define SMA1307_OUTPUT_PORT_ENABLE BIT(7) 296 + 297 + /* SDO Output */ 298 + #define SMA1307_SDO_OUTPUT_MASK BIT(3) 299 + #define SMA1307_LOGIC_OUTPUT 0 300 + #define SMA1307_HIGH_Z_OUTPUT BIT(3) 301 + 302 + #define SMA1307_DATA_CLK_SEL_MASK (BIT(6)|BIT(7)) 303 + #define SMA1307_SDO_DATA 0 304 + #define SMA1307_SDO_CLK_PLL BIT(6) 305 + #define SMA1307_SDO_CLK_OSC (BIT(6)|BIT(7)) 306 + 307 + /* SDO Output2 */ 308 + #define SMA1307_SDO_OUTPUT2_MASK BIT(0) 309 + #define SMA1307_ONE_SDO_PER_CH 0 310 + #define SMA1307_TWO_SDO_PER_CH BIT(0) 311 + 312 + /* SDO Output3 */ 313 + #define SMA1307_SDO_OUTPUT3_MASK BIT(2) 314 + #define SMA1307_SDO_OUTPUT3_DIS 0 315 + #define SMA1307_TWO_SDO_PER_CH_24K BIT(2) 316 + 317 + /* SDO OUT1 Select*/ 318 + #define SMA1307_SDO_OUT1_SEL_MASK (BIT(3)|BIT(4)|BIT(5)) 319 + #define SMA1307_SDO1_DISABLE 0 320 + #define SMA1307_SDO1_FORMAT_C BIT(3) 321 + #define SMA1307_SDO1_MONO_MIX BIT(4) 322 + #define SMA1307_SDO1_AFTER_DSP (BIT(3)|BIT(4)) 323 + #define SMA1307_SDO1_VRMS2_AVG BIT(5) 324 + #define SMA1307_SDO1_VBAT_MON (BIT(3)|BIT(5)) 325 + #define SMA1307_SDO1_TEMP_MON (BIT(4)|BIT(5)) 326 + #define SMA1307_SDO1_AFTER_DELAY (BIT(3)|BIT(4)|BIT(5)) 327 + 328 + /* SDO OUT0 Select*/ 329 + #define SMA1307_SDO_OUT0_SEL_MASK (BIT(0)|BIT(1)|BIT(2)) 330 + #define SMA1307_SDO0_DISABLE 0 331 + #define SMA1307_SDO0_FORMAT_C BIT(0) 332 + #define SMA1307_SDO0_MONO_MIX BIT(1) 333 + #define SMA1307_SDO0_AFTER_DSP (BIT(0)|BIT(1)) 334 + #define SMA1307_SDO0_VRMS2_AVG BIT(2) 335 + #define SMA1307_SDO0_VBAT_MON (BIT(0)|BIT(2)) 336 + #define SMA1307_SDO0_TEMP_MON (BIT(1)|BIT(2)) 337 + #define SMA1307_SDO0_AFTER_DELAY (BIT(0)|BIT(1)|BIT(2)) 338 + 339 + /* INTERRUPT Operation */ 340 + #define SMA1307_SEL_INT_MASK BIT(2) 341 + #define SMA1307_INT_CLEAR_AUTO 0 342 + #define SMA1307_INT_CLEAR_MANUAL BIT(2) 343 + 344 + /* INTERRUPT CLEAR */ 345 + #define SMA1307_CLR_INT_MASK BIT(1) 346 + #define SMA1307_INT_READY 0 347 + #define SMA1307_INT_CLEAR BIT(1) 348 + 349 + /* INTERRUPT Disable */ 350 + #define SMA1307_DIS_INT_MASK BIT(0) 351 + #define SMA1307_NORMAL_INT 0 352 + #define SMA1307_HIGH_Z_INT BIT(0) 353 + 354 + /* Interface Control */ 355 + #define SMA1307_INTERFACE_MASK (BIT(5)|BIT(6)|BIT(7)) 356 + #define SMA1307_LJ_FORMAT BIT(5) 357 + #define SMA1307_I2S_FORMAT (BIT(5)|BIT(6)) 358 + #define SMA1307_TDM_FORMAT BIT(7) 359 + 360 + #define SMA1307_SCK_RATE_MASK (BIT(3)|BIT(4)) 361 + #define SMA1307_SCK_64FS 0 362 + #define SMA1307_SCK_32FS BIT(4) 363 + 364 + #define SMA1307_DATA_WIDTH_MASK (BIT(1)|BIT(2)) 365 + #define SMA1307_DATA_24BIT 0 366 + #define SMA1307_DATA_16BIT (BIT(1)|BIT(2)) 367 + 368 + #define SMA1307_TDM_TX_MODE_MASK BIT(6) 369 + #define SMA1307_TDM_TX_MONO 0 370 + #define SMA1307_TDM_TX_STEREO BIT(6) 371 + 372 + #define SMA1307_TDM_SLOT0_RX_POS_MASK (BIT(3)|BIT(4)|BIT(5)) 373 + #define SMA1307_TDM_SLOT0_RX_POS_0 0 374 + #define SMA1307_TDM_SLOT0_RX_POS_1 BIT(3) 375 + #define SMA1307_TDM_SLOT0_RX_POS_2 BIT(4) 376 + #define SMA1307_TDM_SLOT0_RX_POS_3 (BIT(3)|BIT(4)) 377 + #define SMA1307_TDM_SLOT0_RX_POS_4 BIT(5) 378 + #define SMA1307_TDM_SLOT0_RX_POS_5 (BIT(3)|BIT(5)) 379 + #define SMA1307_TDM_SLOT0_RX_POS_6 (BIT(4)|BIT(5)) 380 + #define SMA1307_TDM_SLOT0_RX_POS_7 (BIT(3)|BIT(4)|BIT(5)) 381 + 382 + #define SMA1307_TDM_SLOT1_RX_POS_MASK (BIT(0)|BIT(1)|BIT(2)) 383 + #define SMA1307_TDM_SLOT1_RX_POS_0 0 384 + #define SMA1307_TDM_SLOT1_RX_POS_1 BIT(0) 385 + #define SMA1307_TDM_SLOT1_RX_POS_2 BIT(1) 386 + #define SMA1307_TDM_SLOT1_RX_POS_3 (BIT(0)|BIT(1)) 387 + #define SMA1307_TDM_SLOT1_RX_POS_4 BIT(2) 388 + #define SMA1307_TDM_SLOT1_RX_POS_5 (BIT(0)|BIT(2)) 389 + #define SMA1307_TDM_SLOT1_RX_POS_6 (BIT(1)|BIT(2)) 390 + #define SMA1307_TDM_SLOT1_RX_POS_7 (BIT(0)|BIT(1)|BIT(2)) 391 + 392 + /* TDM2 FORMAT : 0xA6 */ 393 + #define SMA1307_TDM_DL_MASK BIT(7) 394 + #define SMA1307_TDM_DL_16 0 395 + #define SMA1307_TDM_DL_32 BIT(7) 396 + 397 + #define SMA1307_TDM_N_SLOT_MASK BIT(6) 398 + #define SMA1307_TDM_N_SLOT_4 0 399 + #define SMA1307_TDM_N_SLOT_8 BIT(6) 400 + 401 + #define SMA1307_TDM_SLOT0_TX_POS_MASK (BIT(3)|BIT(4)|BIT(5)) 402 + #define SMA1307_TDM_SLOT0_TX_POS_0 0 403 + #define SMA1307_TDM_SLOT0_TX_POS_1 BIT(3) 404 + #define SMA1307_TDM_SLOT0_TX_POS_2 BIT(4) 405 + #define SMA1307_TDM_SLOT0_TX_POS_3 (BIT(3)|BIT(4)) 406 + #define SMA1307_TDM_SLOT0_TX_POS_4 BIT(5) 407 + #define SMA1307_TDM_SLOT0_TX_POS_5 (BIT(3)|BIT(5)) 408 + #define SMA1307_TDM_SLOT0_TX_POS_6 (BIT(4)|BIT(5)) 409 + #define SMA1307_TDM_SLOT0_TX_POS_7 (BIT(3)|BIT(4)|BIT(5)) 410 + 411 + #define SMA1307_TDM_SLOT1_TX_POS_MASK (BIT(0)|BIT(1)|BIT(2)) 412 + #define SMA1307_TDM_SLOT1_TX_POS_0 0 413 + #define SMA1307_TDM_SLOT1_TX_POS_1 BIT(0) 414 + #define SMA1307_TDM_SLOT1_TX_POS_2 BIT(1) 415 + #define SMA1307_TDM_SLOT1_TX_POS_3 (BIT(0)|BIT(1)) 416 + #define SMA1307_TDM_SLOT1_TX_POS_4 BIT(2) 417 + #define SMA1307_TDM_SLOT1_TX_POS_5 (BIT(0)|BIT(2)) 418 + #define SMA1307_TDM_SLOT1_TX_POS_6 (BIT(1)|BIT(2)) 419 + #define SMA1307_TDM_SLOT1_TX_POS_7 (BIT(0)|BIT(1)|BIT(2)) 420 + 421 + /* OTP STATUS */ 422 + #define SMA1307_OTP_STAT_MASK BIT(6) 423 + #define SMA1307_OTP_STAT_0 0 424 + #define SMA1307_OTP_STAT_1 BIT(6) 425 + 426 + /* STATUS */ 427 + #define SMA1307_OT1_OK_STATUS BIT(7) 428 + #define SMA1307_OT2_OK_STATUS BIT(6) 429 + #define SMA1307_UVLO_STATUS BIT(5) 430 + #define SMA1307_OVP_BST_STATUS BIT(4) 431 + #define SMA1307_POWER_FLAG BIT(3) 432 + 433 + #define SMA1307_SCAN_CHK BIT(7) 434 + #define SMA1307_OCP_SPK_STATUS BIT(5) 435 + #define SMA1307_OCP_BST_STATUS BIT(4) 436 + #define SMA1307_BOP_STATE (BIT(1)|BIT(2)|BIT(3)) 437 + #define SMA1307_CLK_MON_STATUS BIT(0) 438 + 439 + #define SMA1307_DEVICE_ID (BIT(3)|BIT(4)) 440 + #define SMA1307_REV_NUM_STATUS (BIT(0)|BIT(1)) 441 + #define SMA1307_REV_NUM_REV0 0 442 + #define SMA1307_REV_NUM_REV1 BIT(0) 443 + 444 + #endif