Lines Matching +full:power +full:- +full:supplies
1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs35l32.c -- CS35L32 ALSA SoC audio driver
27 #include <sound/soc-dapm.h>
30 #include <dt-bindings/sound/cs35l32.h>
44 struct regulator_bulk_data supplies[CS35L32_NUM_SUPPLIES]; member
51 { 0x06, 0x04 }, /* Power Ctl 1 */
52 { 0x07, 0xE8 }, /* Power Ctl 2 */
154 struct snd_soc_component *component = codec_dai->component; in cs35l32_set_dai_fmt()
167 return -EINVAL; in cs35l32_set_dai_fmt()
175 struct snd_soc_component *component = dai->component; in cs35l32_set_tristate()
188 .name = "cs35l32-monitor",
221 return -EINVAL; in cs35l32_component_set_sysclk()
272 struct device_node *np = i2c_client->dev.of_node; in cs35l32_handle_of_data()
275 if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0) in cs35l32_handle_of_data()
276 pdata->sdout_share = val; in cs35l32_handle_of_data()
278 if (of_property_read_u32(np, "cirrus,boost-manager", &val)) in cs35l32_handle_of_data()
279 val = -1u; in cs35l32_handle_of_data()
286 pdata->boost_mng = val; in cs35l32_handle_of_data()
288 case -1u: in cs35l32_handle_of_data()
290 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
291 "Wrong cirrus,boost-manager DT value %d\n", val); in cs35l32_handle_of_data()
292 pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS; in cs35l32_handle_of_data()
295 if (of_property_read_u32(np, "cirrus,sdout-datacfg", &val)) in cs35l32_handle_of_data()
296 val = -1u; in cs35l32_handle_of_data()
302 pdata->sdout_datacfg = val; in cs35l32_handle_of_data()
304 case -1u: in cs35l32_handle_of_data()
306 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
307 "Wrong cirrus,sdout-datacfg DT value %d\n", val); in cs35l32_handle_of_data()
308 pdata->sdout_datacfg = CS35L32_DATA_CFG_LR; in cs35l32_handle_of_data()
311 if (of_property_read_u32(np, "cirrus,battery-threshold", &val)) in cs35l32_handle_of_data()
312 val = -1u; in cs35l32_handle_of_data()
318 pdata->batt_thresh = val; in cs35l32_handle_of_data()
320 case -1u: in cs35l32_handle_of_data()
322 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
323 "Wrong cirrus,battery-threshold DT value %d\n", val); in cs35l32_handle_of_data()
324 pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V; in cs35l32_handle_of_data()
327 if (of_property_read_u32(np, "cirrus,battery-recovery", &val)) in cs35l32_handle_of_data()
328 val = -1u; in cs35l32_handle_of_data()
336 pdata->batt_recov = val; in cs35l32_handle_of_data()
338 case -1u: in cs35l32_handle_of_data()
340 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
341 "Wrong cirrus,battery-recovery DT value %d\n", val); in cs35l32_handle_of_data()
342 pdata->batt_recov = CS35L32_BATT_RECOV_3_4V; in cs35l32_handle_of_data()
352 dev_get_platdata(&i2c_client->dev); in cs35l32_i2c_probe()
356 cs35l32 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l32), GFP_KERNEL); in cs35l32_i2c_probe()
358 return -ENOMEM; in cs35l32_i2c_probe()
362 cs35l32->regmap = devm_regmap_init_i2c(i2c_client, &cs35l32_regmap); in cs35l32_i2c_probe()
363 if (IS_ERR(cs35l32->regmap)) { in cs35l32_i2c_probe()
364 ret = PTR_ERR(cs35l32->regmap); in cs35l32_i2c_probe()
365 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs35l32_i2c_probe()
370 cs35l32->pdata = *pdata; in cs35l32_i2c_probe()
372 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), in cs35l32_i2c_probe()
375 return -ENOMEM; in cs35l32_i2c_probe()
377 if (i2c_client->dev.of_node) { in cs35l32_i2c_probe()
379 &cs35l32->pdata); in cs35l32_i2c_probe()
385 for (i = 0; i < ARRAY_SIZE(cs35l32->supplies); i++) in cs35l32_i2c_probe()
386 cs35l32->supplies[i].supply = cs35l32_supply_names[i]; in cs35l32_i2c_probe()
388 ret = devm_regulator_bulk_get(&i2c_client->dev, in cs35l32_i2c_probe()
389 ARRAY_SIZE(cs35l32->supplies), in cs35l32_i2c_probe()
390 cs35l32->supplies); in cs35l32_i2c_probe()
392 dev_err(&i2c_client->dev, in cs35l32_i2c_probe()
393 "Failed to request supplies: %d\n", ret); in cs35l32_i2c_probe()
397 ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_i2c_probe()
398 cs35l32->supplies); in cs35l32_i2c_probe()
400 dev_err(&i2c_client->dev, in cs35l32_i2c_probe()
401 "Failed to enable supplies: %d\n", ret); in cs35l32_i2c_probe()
406 cs35l32->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs35l32_i2c_probe()
408 if (IS_ERR(cs35l32->reset_gpio)) { in cs35l32_i2c_probe()
409 ret = PTR_ERR(cs35l32->reset_gpio); in cs35l32_i2c_probe()
413 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); in cs35l32_i2c_probe()
416 devid = cirrus_read_device_id(cs35l32->regmap, CS35L32_DEVID_AB); in cs35l32_i2c_probe()
419 dev_err(&i2c_client->dev, "Failed to read device ID: %d\n", ret); in cs35l32_i2c_probe()
424 ret = -ENODEV; in cs35l32_i2c_probe()
425 dev_err(&i2c_client->dev, in cs35l32_i2c_probe()
431 ret = regmap_read(cs35l32->regmap, CS35L32_REV_ID, ®); in cs35l32_i2c_probe()
433 dev_err(&i2c_client->dev, "Get Revision ID failed\n"); in cs35l32_i2c_probe()
437 ret = regmap_register_patch(cs35l32->regmap, cs35l32_monitor_patch, in cs35l32_i2c_probe()
440 dev_err(&i2c_client->dev, "Failed to apply errata patch\n"); in cs35l32_i2c_probe()
444 dev_info(&i2c_client->dev, in cs35l32_i2c_probe()
448 if (cs35l32->pdata.boost_mng) in cs35l32_i2c_probe()
449 regmap_update_bits(cs35l32->regmap, CS35L32_AUDIO_LED_MNGR, in cs35l32_i2c_probe()
451 cs35l32->pdata.boost_mng); in cs35l32_i2c_probe()
454 if (cs35l32->pdata.sdout_share) in cs35l32_i2c_probe()
455 regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, in cs35l32_i2c_probe()
457 cs35l32->pdata.sdout_share << 3); in cs35l32_i2c_probe()
460 if (cs35l32->pdata.sdout_datacfg) in cs35l32_i2c_probe()
461 regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, in cs35l32_i2c_probe()
463 cs35l32->pdata.sdout_datacfg << 4); in cs35l32_i2c_probe()
466 if (cs35l32->pdata.batt_recov) in cs35l32_i2c_probe()
467 regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, in cs35l32_i2c_probe()
469 cs35l32->pdata.batt_recov << 1); in cs35l32_i2c_probe()
472 if (cs35l32->pdata.batt_thresh) in cs35l32_i2c_probe()
473 regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, in cs35l32_i2c_probe()
475 cs35l32->pdata.batt_thresh << 4); in cs35l32_i2c_probe()
477 /* Power down the AMP */ in cs35l32_i2c_probe()
478 regmap_update_bits(cs35l32->regmap, CS35L32_PWRCTL1, CS35L32_PDN_AMP, in cs35l32_i2c_probe()
482 regmap_read(cs35l32->regmap, CS35L32_INT_STATUS_1, ®); in cs35l32_i2c_probe()
484 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs35l32_i2c_probe()
493 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); in cs35l32_i2c_probe()
495 regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_i2c_probe()
496 cs35l32->supplies); in cs35l32_i2c_probe()
505 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); in cs35l32_i2c_remove()
513 regcache_cache_only(cs35l32->regmap, true); in cs35l32_runtime_suspend()
514 regcache_mark_dirty(cs35l32->regmap); in cs35l32_runtime_suspend()
517 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); in cs35l32_runtime_suspend()
519 /* remove power */ in cs35l32_runtime_suspend()
520 regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_runtime_suspend()
521 cs35l32->supplies); in cs35l32_runtime_suspend()
531 /* Enable power */ in cs35l32_runtime_resume()
532 ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_runtime_resume()
533 cs35l32->supplies); in cs35l32_runtime_resume()
535 dev_err(dev, "Failed to enable supplies: %d\n", in cs35l32_runtime_resume()
540 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); in cs35l32_runtime_resume()
542 regcache_cache_only(cs35l32->regmap, false); in cs35l32_runtime_resume()
543 regcache_sync(cs35l32->regmap); in cs35l32_runtime_resume()