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()
273 struct device_node *np = i2c_client->dev.of_node; in cs35l32_handle_of_data()
276 if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0) in cs35l32_handle_of_data()
277 pdata->sdout_share = val; in cs35l32_handle_of_data()
279 if (of_property_read_u32(np, "cirrus,boost-manager", &val)) in cs35l32_handle_of_data()
280 val = -1u; in cs35l32_handle_of_data()
287 pdata->boost_mng = val; in cs35l32_handle_of_data()
289 case -1u: in cs35l32_handle_of_data()
291 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
292 "Wrong cirrus,boost-manager DT value %d\n", val); in cs35l32_handle_of_data()
293 pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS; in cs35l32_handle_of_data()
296 if (of_property_read_u32(np, "cirrus,sdout-datacfg", &val)) in cs35l32_handle_of_data()
297 val = -1u; in cs35l32_handle_of_data()
303 pdata->sdout_datacfg = val; in cs35l32_handle_of_data()
305 case -1u: in cs35l32_handle_of_data()
307 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
308 "Wrong cirrus,sdout-datacfg DT value %d\n", val); in cs35l32_handle_of_data()
309 pdata->sdout_datacfg = CS35L32_DATA_CFG_LR; in cs35l32_handle_of_data()
312 if (of_property_read_u32(np, "cirrus,battery-threshold", &val)) in cs35l32_handle_of_data()
313 val = -1u; in cs35l32_handle_of_data()
319 pdata->batt_thresh = val; in cs35l32_handle_of_data()
321 case -1u: in cs35l32_handle_of_data()
323 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
324 "Wrong cirrus,battery-threshold DT value %d\n", val); in cs35l32_handle_of_data()
325 pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V; in cs35l32_handle_of_data()
328 if (of_property_read_u32(np, "cirrus,battery-recovery", &val)) in cs35l32_handle_of_data()
329 val = -1u; in cs35l32_handle_of_data()
337 pdata->batt_recov = val; in cs35l32_handle_of_data()
339 case -1u: in cs35l32_handle_of_data()
341 dev_err(&i2c_client->dev, in cs35l32_handle_of_data()
342 "Wrong cirrus,battery-recovery DT value %d\n", val); in cs35l32_handle_of_data()
343 pdata->batt_recov = CS35L32_BATT_RECOV_3_4V; in cs35l32_handle_of_data()
354 dev_get_platdata(&i2c_client->dev); in cs35l32_i2c_probe()
358 cs35l32 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l32), GFP_KERNEL); in cs35l32_i2c_probe()
360 return -ENOMEM; in cs35l32_i2c_probe()
364 cs35l32->regmap = devm_regmap_init_i2c(i2c_client, &cs35l32_regmap); in cs35l32_i2c_probe()
365 if (IS_ERR(cs35l32->regmap)) { in cs35l32_i2c_probe()
366 ret = PTR_ERR(cs35l32->regmap); in cs35l32_i2c_probe()
367 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs35l32_i2c_probe()
372 cs35l32->pdata = *pdata; in cs35l32_i2c_probe()
374 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), in cs35l32_i2c_probe()
377 return -ENOMEM; in cs35l32_i2c_probe()
379 if (i2c_client->dev.of_node) { in cs35l32_i2c_probe()
381 &cs35l32->pdata); in cs35l32_i2c_probe()
387 for (i = 0; i < ARRAY_SIZE(cs35l32->supplies); i++) in cs35l32_i2c_probe()
388 cs35l32->supplies[i].supply = cs35l32_supply_names[i]; in cs35l32_i2c_probe()
390 ret = devm_regulator_bulk_get(&i2c_client->dev, in cs35l32_i2c_probe()
391 ARRAY_SIZE(cs35l32->supplies), in cs35l32_i2c_probe()
392 cs35l32->supplies); in cs35l32_i2c_probe()
394 dev_err(&i2c_client->dev, in cs35l32_i2c_probe()
395 "Failed to request supplies: %d\n", ret); in cs35l32_i2c_probe()
399 ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_i2c_probe()
400 cs35l32->supplies); in cs35l32_i2c_probe()
402 dev_err(&i2c_client->dev, in cs35l32_i2c_probe()
403 "Failed to enable supplies: %d\n", ret); in cs35l32_i2c_probe()
408 cs35l32->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs35l32_i2c_probe()
410 if (IS_ERR(cs35l32->reset_gpio)) { in cs35l32_i2c_probe()
411 ret = PTR_ERR(cs35l32->reset_gpio); in cs35l32_i2c_probe()
415 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); in cs35l32_i2c_probe()
418 devid = cirrus_read_device_id(cs35l32->regmap, CS35L32_DEVID_AB); in cs35l32_i2c_probe()
421 dev_err(&i2c_client->dev, "Failed to read device ID: %d\n", ret); in cs35l32_i2c_probe()
426 ret = -ENODEV; in cs35l32_i2c_probe()
427 dev_err(&i2c_client->dev, in cs35l32_i2c_probe()
433 ret = regmap_read(cs35l32->regmap, CS35L32_REV_ID, &reg); in cs35l32_i2c_probe()
435 dev_err(&i2c_client->dev, "Get Revision ID failed\n"); in cs35l32_i2c_probe()
439 ret = regmap_register_patch(cs35l32->regmap, cs35l32_monitor_patch, in cs35l32_i2c_probe()
442 dev_err(&i2c_client->dev, "Failed to apply errata patch\n"); in cs35l32_i2c_probe()
446 dev_info(&i2c_client->dev, in cs35l32_i2c_probe()
450 if (cs35l32->pdata.boost_mng) in cs35l32_i2c_probe()
451 regmap_update_bits(cs35l32->regmap, CS35L32_AUDIO_LED_MNGR, in cs35l32_i2c_probe()
453 cs35l32->pdata.boost_mng); in cs35l32_i2c_probe()
456 if (cs35l32->pdata.sdout_share) in cs35l32_i2c_probe()
457 regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, in cs35l32_i2c_probe()
459 cs35l32->pdata.sdout_share << 3); in cs35l32_i2c_probe()
462 if (cs35l32->pdata.sdout_datacfg) in cs35l32_i2c_probe()
463 regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, in cs35l32_i2c_probe()
465 cs35l32->pdata.sdout_datacfg << 4); in cs35l32_i2c_probe()
468 if (cs35l32->pdata.batt_recov) in cs35l32_i2c_probe()
469 regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, in cs35l32_i2c_probe()
471 cs35l32->pdata.batt_recov << 1); in cs35l32_i2c_probe()
474 if (cs35l32->pdata.batt_thresh) in cs35l32_i2c_probe()
475 regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, in cs35l32_i2c_probe()
477 cs35l32->pdata.batt_thresh << 4); in cs35l32_i2c_probe()
479 /* Power down the AMP */ in cs35l32_i2c_probe()
480 regmap_update_bits(cs35l32->regmap, CS35L32_PWRCTL1, CS35L32_PDN_AMP, in cs35l32_i2c_probe()
484 regmap_read(cs35l32->regmap, CS35L32_INT_STATUS_1, &reg); in cs35l32_i2c_probe()
486 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs35l32_i2c_probe()
495 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); in cs35l32_i2c_probe()
497 regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_i2c_probe()
498 cs35l32->supplies); in cs35l32_i2c_probe()
507 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); in cs35l32_i2c_remove()
517 regcache_cache_only(cs35l32->regmap, true); in cs35l32_runtime_suspend()
518 regcache_mark_dirty(cs35l32->regmap); in cs35l32_runtime_suspend()
521 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); in cs35l32_runtime_suspend()
523 /* remove power */ in cs35l32_runtime_suspend()
524 regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_runtime_suspend()
525 cs35l32->supplies); in cs35l32_runtime_suspend()
535 /* Enable power */ in cs35l32_runtime_resume()
536 ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), in cs35l32_runtime_resume()
537 cs35l32->supplies); in cs35l32_runtime_resume()
539 dev_err(dev, "Failed to enable supplies: %d\n", in cs35l32_runtime_resume()
544 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); in cs35l32_runtime_resume()
546 regcache_cache_only(cs35l32->regmap, false); in cs35l32_runtime_resume()
547 regcache_sync(cs35l32->regmap); in cs35l32_runtime_resume()