Lines Matching +full:dmic +full:- +full:init +full:- +full:delay +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-only
3 // rt5682.c -- RT5682 ALSA SoC audio component driver
11 #include <linux/init.h>
12 #include <linux/delay.h>
25 #include <sound/soc-dapm.h>
38 .dai_clk_names[RT5682_DAI_WCLK_IDX] = "rt5682-dai-wclk",
39 .dai_clk_names[RT5682_DAI_BCLK_IDX] = "rt5682-dai-bclk",
60 if (snd_soc_component_read(rt5682->component, RT5682_AJD1_CTRL) & RT5682_JDH_RS_MASK) in rt5682_jd_check_handler()
63 &rt5682->jack_detect_work, 0); in rt5682_jd_check_handler()
65 schedule_delayed_work(&rt5682->jd_check_work, 500); in rt5682_jd_check_handler()
73 &rt5682->jack_detect_work, msecs_to_jiffies(rt5682->irq_work_delay_time)); in rt5682_irq()
80 .name = "rt5682-aif1",
99 .name = "rt5682-aif2",
116 regulator_bulk_disable(ARRAY_SIZE(rt5682->supplies), rt5682->supplies); in rt5682_i2c_disable_regulators()
121 struct rt5682_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5682_i2c_probe()
126 rt5682 = devm_kzalloc(&i2c->dev, sizeof(struct rt5682_priv), in rt5682_i2c_probe()
129 return -ENOMEM; in rt5682_i2c_probe()
133 rt5682->i2c_dev = &i2c->dev; in rt5682_i2c_probe()
135 rt5682->pdata = i2s_default_platform_data; in rt5682_i2c_probe()
138 rt5682->pdata = *pdata; in rt5682_i2c_probe()
140 rt5682_parse_dt(rt5682, &i2c->dev); in rt5682_i2c_probe()
142 rt5682->regmap = devm_regmap_init_i2c(i2c, &rt5682_regmap); in rt5682_i2c_probe()
143 if (IS_ERR(rt5682->regmap)) { in rt5682_i2c_probe()
144 ret = PTR_ERR(rt5682->regmap); in rt5682_i2c_probe()
145 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5682_i2c_probe()
150 for (i = 0; i < ARRAY_SIZE(rt5682->supplies); i++) in rt5682_i2c_probe()
151 rt5682->supplies[i].supply = rt5682_supply_names[i]; in rt5682_i2c_probe()
153 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5682->supplies), in rt5682_i2c_probe()
154 rt5682->supplies); in rt5682_i2c_probe()
156 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in rt5682_i2c_probe()
160 ret = regulator_bulk_enable(ARRAY_SIZE(rt5682->supplies), in rt5682_i2c_probe()
161 rt5682->supplies); in rt5682_i2c_probe()
163 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in rt5682_i2c_probe()
167 ret = devm_add_action_or_reset(&i2c->dev, rt5682_i2c_disable_regulators, in rt5682_i2c_probe()
172 ret = rt5682_get_ldo1(rt5682, &i2c->dev); in rt5682_i2c_probe()
176 /* Sleep for 300 ms miniumum */ in rt5682_i2c_probe()
179 regmap_write(rt5682->regmap, RT5682_I2C_MODE, 0x1); in rt5682_i2c_probe()
182 regmap_read(rt5682->regmap, RT5682_DEVICE_ID, &val); in rt5682_i2c_probe()
184 dev_err(&i2c->dev, in rt5682_i2c_probe()
186 return -ENODEV; in rt5682_i2c_probe()
189 mutex_init(&rt5682->calibrate_mutex); in rt5682_i2c_probe()
192 rt5682_apply_patch_list(rt5682, &i2c->dev); in rt5682_i2c_probe()
194 regmap_write(rt5682->regmap, RT5682_DEPOP_1, 0x0000); in rt5682_i2c_probe()
196 /* DMIC pin*/ in rt5682_i2c_probe()
197 if (rt5682->pdata.dmic1_data_pin != RT5682_DMIC1_NULL) { in rt5682_i2c_probe()
198 switch (rt5682->pdata.dmic1_data_pin) { in rt5682_i2c_probe()
200 regmap_update_bits(rt5682->regmap, RT5682_DMIC_CTRL_1, in rt5682_i2c_probe()
202 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1, in rt5682_i2c_probe()
207 regmap_update_bits(rt5682->regmap, RT5682_DMIC_CTRL_1, in rt5682_i2c_probe()
209 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1, in rt5682_i2c_probe()
214 dev_warn(&i2c->dev, "invalid DMIC_DAT pin\n"); in rt5682_i2c_probe()
218 switch (rt5682->pdata.dmic1_clk_pin) { in rt5682_i2c_probe()
220 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1, in rt5682_i2c_probe()
225 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1, in rt5682_i2c_probe()
227 if (rt5682->pdata.dmic_clk_driving_high) in rt5682_i2c_probe()
228 regmap_update_bits(rt5682->regmap, in rt5682_i2c_probe()
235 dev_warn(&i2c->dev, "invalid DMIC_CLK pin\n"); in rt5682_i2c_probe()
240 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1, in rt5682_i2c_probe()
243 regmap_write(rt5682->regmap, RT5682_MICBIAS_2, 0x0080); in rt5682_i2c_probe()
244 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1, in rt5682_i2c_probe()
247 regmap_write(rt5682->regmap, RT5682_TEST_MODE_CTRL_1, 0x0000); in rt5682_i2c_probe()
248 regmap_update_bits(rt5682->regmap, RT5682_BIAS_CUR_CTRL_8, in rt5682_i2c_probe()
250 regmap_update_bits(rt5682->regmap, RT5682_CHARGE_PUMP_1, in rt5682_i2c_probe()
252 regmap_update_bits(rt5682->regmap, RT5682_HP_CHARGE_PUMP_1, in rt5682_i2c_probe()
254 regmap_update_bits(rt5682->regmap, RT5682_DMIC_CTRL_1, in rt5682_i2c_probe()
257 INIT_DELAYED_WORK(&rt5682->jack_detect_work, in rt5682_i2c_probe()
259 INIT_DELAYED_WORK(&rt5682->jd_check_work, in rt5682_i2c_probe()
262 if (i2c->irq) { in rt5682_i2c_probe()
263 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, in rt5682_i2c_probe()
267 rt5682->irq = i2c->irq; in rt5682_i2c_probe()
269 dev_err(&i2c->dev, "Failed to request IRQ: %d\n", ret); in rt5682_i2c_probe()
274 rt5682->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); in rt5682_i2c_probe()
275 if (IS_ERR(rt5682->mclk)) in rt5682_i2c_probe()
276 return PTR_ERR(rt5682->mclk); in rt5682_i2c_probe()
284 rt5682->lrck[RT5682_AIF1] = 48000; in rt5682_i2c_probe()
287 return devm_snd_soc_register_component(&i2c->dev, in rt5682_i2c_probe()
296 disable_irq(client->irq); in rt5682_i2c_shutdown()
297 cancel_delayed_work_sync(&rt5682->jack_detect_work); in rt5682_i2c_shutdown()
298 cancel_delayed_work_sync(&rt5682->jd_check_work); in rt5682_i2c_shutdown()