Lines Matching +full:spkvdd2 +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm8994-core.c -- Device access for Wolfson WM8994
32 .name = "wm8994-ldo",
37 .name = "wm8994-ldo",
61 .name = "wm8994-codec",
67 .name = "wm8994-gpio",
76 * and should be handled via the standard regulator API supply
88 "SPKVDD2",
98 "SPKVDD2",
110 "SPKVDD2",
121 switch (wm8994->type) { in wm8994_suspend()
138 if (!wm8994->ldo_ena_always_driven) in wm8994_suspend()
149 regcache_mark_dirty(wm8994->regmap); in wm8994_suspend()
154 ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1, in wm8994_suspend()
160 ret = regcache_sync_region(wm8994->regmap, in wm8994_suspend()
166 regcache_cache_only(wm8994->regmap, true); in wm8994_suspend()
167 wm8994->suspended = true; in wm8994_suspend()
169 ret = regulator_bulk_disable(wm8994->num_supplies, in wm8994_suspend()
170 wm8994->supplies); in wm8994_suspend()
185 if (!wm8994->suspended) in wm8994_resume()
188 ret = regulator_bulk_enable(wm8994->num_supplies, in wm8994_resume()
189 wm8994->supplies); in wm8994_resume()
195 regcache_cache_only(wm8994->regmap, false); in wm8994_resume()
196 ret = regcache_sync(wm8994->regmap); in wm8994_resume()
207 wm8994->suspended = false; in wm8994_resume()
212 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); in wm8994_resume()
226 ldo_pdata = &pdata->ldo[ldo]; in wm8994_ldo_in_use()
228 if (!ldo_pdata->init_data) in wm8994_ldo_in_use()
231 return ldo_pdata->init_data->num_consumer_supplies != 0; in wm8994_ldo_in_use()
265 struct device_node *np = wm8994->dev->of_node; in wm8994_set_pdata_from_of()
266 struct wm8994_pdata *pdata = &wm8994->pdata; in wm8994_set_pdata_from_of()
272 if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults, in wm8994_set_pdata_from_of()
273 ARRAY_SIZE(pdata->gpio_defaults)) >= 0) { in wm8994_set_pdata_from_of()
274 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { in wm8994_set_pdata_from_of()
275 if (wm8994->pdata.gpio_defaults[i] == 0) in wm8994_set_pdata_from_of()
276 pdata->gpio_defaults[i] in wm8994_set_pdata_from_of()
281 of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias, in wm8994_set_pdata_from_of()
282 ARRAY_SIZE(pdata->micbias)); in wm8994_set_pdata_from_of()
284 pdata->lineout1_diff = true; in wm8994_set_pdata_from_of()
285 pdata->lineout2_diff = true; in wm8994_set_pdata_from_of()
286 if (of_find_property(np, "wlf,lineout1-se", NULL)) in wm8994_set_pdata_from_of()
287 pdata->lineout1_diff = false; in wm8994_set_pdata_from_of()
288 if (of_find_property(np, "wlf,lineout2-se", NULL)) in wm8994_set_pdata_from_of()
289 pdata->lineout2_diff = false; in wm8994_set_pdata_from_of()
291 if (of_find_property(np, "wlf,lineout1-feedback", NULL)) in wm8994_set_pdata_from_of()
292 pdata->lineout1fb = true; in wm8994_set_pdata_from_of()
293 if (of_find_property(np, "wlf,lineout2-feedback", NULL)) in wm8994_set_pdata_from_of()
294 pdata->lineout2fb = true; in wm8994_set_pdata_from_of()
296 if (of_find_property(np, "wlf,ldoena-always-driven", NULL)) in wm8994_set_pdata_from_of()
297 pdata->lineout2fb = true; in wm8994_set_pdata_from_of()
299 pdata->spkmode_pu = of_property_read_bool(np, "wlf,spkmode-pu"); in wm8994_set_pdata_from_of()
301 pdata->csnaddr_pd = of_property_read_bool(np, "wlf,csnaddr-pd"); in wm8994_set_pdata_from_of()
313 * Instantiate the generic non-control parts of the device.
324 if (dev_get_platdata(wm8994->dev)) { in wm8994_device_init()
325 pdata = dev_get_platdata(wm8994->dev); in wm8994_device_init()
326 wm8994->pdata = *pdata; in wm8994_device_init()
328 pdata = &wm8994->pdata; in wm8994_device_init()
334 dev_set_drvdata(wm8994->dev, wm8994); in wm8994_device_init()
336 /* Add the on-chip regulators first for bootstrapping */ in wm8994_device_init()
337 ret = mfd_add_devices(wm8994->dev, 0, in wm8994_device_init()
342 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); in wm8994_device_init()
346 switch (wm8994->type) { in wm8994_device_init()
348 wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); in wm8994_device_init()
351 wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); in wm8994_device_init()
354 wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); in wm8994_device_init()
361 wm8994->supplies = devm_kcalloc(wm8994->dev, in wm8994_device_init()
362 wm8994->num_supplies, in wm8994_device_init()
365 if (!wm8994->supplies) { in wm8994_device_init()
366 ret = -ENOMEM; in wm8994_device_init()
370 switch (wm8994->type) { in wm8994_device_init()
373 wm8994->supplies[i].supply = wm1811_main_supplies[i]; in wm8994_device_init()
377 wm8994->supplies[i].supply = wm8994_main_supplies[i]; in wm8994_device_init()
381 wm8994->supplies[i].supply = wm8958_main_supplies[i]; in wm8994_device_init()
390 * wm8994->dev's children (regulators) and those regulators are in wm8994_device_init()
393 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, in wm8994_device_init()
394 wm8994->supplies); in wm8994_device_init()
396 if (ret != -EPROBE_DEFER) in wm8994_device_init()
397 dev_err(wm8994->dev, "Failed to get supplies: %d\n", in wm8994_device_init()
402 ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies); in wm8994_device_init()
404 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); in wm8994_device_init()
410 dev_err(wm8994->dev, "Failed to read ID register\n"); in wm8994_device_init()
416 if (wm8994->type != WM1811) in wm8994_device_init()
417 dev_warn(wm8994->dev, "Device registered as type %d\n", in wm8994_device_init()
418 wm8994->type); in wm8994_device_init()
419 wm8994->type = WM1811; in wm8994_device_init()
423 if (wm8994->type != WM8994) in wm8994_device_init()
424 dev_warn(wm8994->dev, "Device registered as type %d\n", in wm8994_device_init()
425 wm8994->type); in wm8994_device_init()
426 wm8994->type = WM8994; in wm8994_device_init()
430 if (wm8994->type != WM8958) in wm8994_device_init()
431 dev_warn(wm8994->dev, "Device registered as type %d\n", in wm8994_device_init()
432 wm8994->type); in wm8994_device_init()
433 wm8994->type = WM8958; in wm8994_device_init()
436 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", in wm8994_device_init()
438 ret = -EINVAL; in wm8994_device_init()
444 dev_err(wm8994->dev, "Failed to read revision register: %d\n", in wm8994_device_init()
448 wm8994->revision = ret & WM8994_CHIP_REV_MASK; in wm8994_device_init()
449 wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT; in wm8994_device_init()
451 switch (wm8994->type) { in wm8994_device_init()
453 switch (wm8994->revision) { in wm8994_device_init()
456 dev_warn(wm8994->dev, in wm8994_device_init()
458 'A' + wm8994->revision); in wm8994_device_init()
470 switch (wm8994->revision) { in wm8994_device_init()
482 if (wm8994->revision > 1) in wm8994_device_init()
483 wm8994->revision++; in wm8994_device_init()
493 dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, in wm8994_device_init()
494 'A' + wm8994->revision, wm8994->cust_id); in wm8994_device_init()
496 switch (wm8994->type) { in wm8994_device_init()
507 dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); in wm8994_device_init()
508 ret = -EINVAL; in wm8994_device_init()
512 ret = regmap_reinit_cache(wm8994->regmap, regmap_config); in wm8994_device_init()
514 dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", in wm8994_device_init()
526 dev_err(wm8994->dev, "Failed to reset device: %d\n", ret); in wm8994_device_init()
531 ret = regmap_register_patch(wm8994->regmap, regmap_patch, in wm8994_device_init()
534 dev_err(wm8994->dev, "Failed to register patch: %d\n", in wm8994_device_init()
540 wm8994->irq_base = pdata->irq_base; in wm8994_device_init()
541 wm8994->gpio_base = pdata->gpio_base; in wm8994_device_init()
543 /* GPIO configuration is only applied if it's non-zero */ in wm8994_device_init()
544 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { in wm8994_device_init()
545 if (pdata->gpio_defaults[i]) { in wm8994_device_init()
547 0xffff, pdata->gpio_defaults[i]); in wm8994_device_init()
551 wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; in wm8994_device_init()
553 if (pdata->spkmode_pu) in wm8994_device_init()
555 if (pdata->csnaddr_pd) in wm8994_device_init()
581 ret = mfd_add_devices(wm8994->dev, -1, in wm8994_device_init()
585 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); in wm8994_device_init()
589 pm_runtime_set_active(wm8994->dev); in wm8994_device_init()
590 pm_runtime_enable(wm8994->dev); in wm8994_device_init()
591 pm_runtime_idle(wm8994->dev); in wm8994_device_init()
598 regulator_bulk_disable(wm8994->num_supplies, in wm8994_device_init()
599 wm8994->supplies); in wm8994_device_init()
601 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); in wm8994_device_init()
603 mfd_remove_devices(wm8994->dev); in wm8994_device_init()
609 pm_runtime_get_sync(wm8994->dev); in wm8994_device_exit()
610 pm_runtime_disable(wm8994->dev); in wm8994_device_exit()
611 pm_runtime_put_noidle(wm8994->dev); in wm8994_device_exit()
613 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); in wm8994_device_exit()
614 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); in wm8994_device_exit()
615 mfd_remove_devices(wm8994->dev); in wm8994_device_exit()
633 wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL); in wm8994_i2c_probe()
635 return -ENOMEM; in wm8994_i2c_probe()
638 wm8994->dev = &i2c->dev; in wm8994_i2c_probe()
639 wm8994->irq = i2c->irq; in wm8994_i2c_probe()
641 if (i2c->dev.of_node) { in wm8994_i2c_probe()
642 of_id = of_match_device(wm8994_of_match, &i2c->dev); in wm8994_i2c_probe()
644 wm8994->type = (enum wm8994_type)of_id->data; in wm8994_i2c_probe()
646 wm8994->type = id->driver_data; in wm8994_i2c_probe()
649 wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config); in wm8994_i2c_probe()
650 if (IS_ERR(wm8994->regmap)) { in wm8994_i2c_probe()
651 ret = PTR_ERR(wm8994->regmap); in wm8994_i2c_probe()
652 dev_err(wm8994->dev, "Failed to allocate register map: %d\n", in wm8994_i2c_probe()
657 return wm8994_device_init(wm8994, i2c->irq); in wm8994_i2c_probe()