Lines Matching full:wm8994

3  * wm8994-core.c  --  Device access for Wolfson WM8994
23 #include <linux/mfd/wm8994/core.h>
24 #include <linux/mfd/wm8994/pdata.h>
25 #include <linux/mfd/wm8994/registers.h>
27 #include "wm8994.h"
31 .name = "wm8994-ldo",
36 .name = "wm8994-ldo",
60 .name = "wm8994-codec",
66 .name = "wm8994-gpio",
114 struct wm8994 *wm8994 = dev_get_drvdata(dev); in wm8994_suspend() local
119 switch (wm8994->type) { in wm8994_suspend()
122 ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1); in wm8994_suspend()
136 if (!wm8994->ldo_ena_always_driven) in wm8994_suspend()
137 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, in wm8994_suspend()
144 wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, in wm8994_suspend()
145 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); in wm8994_suspend()
147 regcache_mark_dirty(wm8994->regmap); in wm8994_suspend()
152 ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1, in wm8994_suspend()
158 ret = regcache_sync_region(wm8994->regmap, in wm8994_suspend()
164 regcache_cache_only(wm8994->regmap, true); in wm8994_suspend()
165 wm8994->suspended = true; in wm8994_suspend()
167 ret = regulator_bulk_disable(wm8994->num_supplies, in wm8994_suspend()
168 wm8994->supplies); in wm8994_suspend()
179 struct wm8994 *wm8994 = dev_get_drvdata(dev); in wm8994_resume() local
183 if (!wm8994->suspended) in wm8994_resume()
186 ret = regulator_bulk_enable(wm8994->num_supplies, in wm8994_resume()
187 wm8994->supplies); in wm8994_resume()
193 regcache_cache_only(wm8994->regmap, false); in wm8994_resume()
194 ret = regcache_sync(wm8994->regmap); in wm8994_resume()
201 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, in wm8994_resume()
205 wm8994->suspended = false; in wm8994_resume()
210 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); in wm8994_resume()
260 static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) in wm8994_set_pdata_from_of() argument
262 struct device_node *np = wm8994->dev->of_node; in wm8994_set_pdata_from_of()
263 struct wm8994_pdata *pdata = &wm8994->pdata; in wm8994_set_pdata_from_of()
272 if (wm8994->pdata.gpio_defaults[i] == 0) in wm8994_set_pdata_from_of()
294 static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) in wm8994_set_pdata_from_of() argument
303 static int wm8994_device_init(struct wm8994 *wm8994, int irq) in wm8994_device_init() argument
312 if (dev_get_platdata(wm8994->dev)) { in wm8994_device_init()
313 pdata = dev_get_platdata(wm8994->dev); in wm8994_device_init()
314 wm8994->pdata = *pdata; in wm8994_device_init()
316 pdata = &wm8994->pdata; in wm8994_device_init()
318 ret = wm8994_set_pdata_from_of(wm8994); in wm8994_device_init()
323 ret = mfd_add_devices(wm8994->dev, 0, in wm8994_device_init()
328 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); in wm8994_device_init()
332 switch (wm8994->type) { in wm8994_device_init()
334 wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); in wm8994_device_init()
336 case WM8994: in wm8994_device_init()
337 wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); in wm8994_device_init()
340 wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); in wm8994_device_init()
347 wm8994->supplies = devm_kcalloc(wm8994->dev, in wm8994_device_init()
348 wm8994->num_supplies, in wm8994_device_init()
351 if (!wm8994->supplies) { in wm8994_device_init()
356 switch (wm8994->type) { in wm8994_device_init()
359 wm8994->supplies[i].supply = wm1811_main_supplies[i]; in wm8994_device_init()
361 case WM8994: in wm8994_device_init()
363 wm8994->supplies[i].supply = wm8994_main_supplies[i]; in wm8994_device_init()
367 wm8994->supplies[i].supply = wm8958_main_supplies[i]; in wm8994_device_init()
376 * wm8994->dev's children (regulators) and those regulators are in wm8994_device_init()
379 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, in wm8994_device_init()
380 wm8994->supplies); in wm8994_device_init()
383 dev_err(wm8994->dev, "Failed to get supplies: %d\n", in wm8994_device_init()
388 ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies); in wm8994_device_init()
390 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); in wm8994_device_init()
394 ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); in wm8994_device_init()
396 dev_err(wm8994->dev, "Failed to read ID register\n"); in wm8994_device_init()
402 if (wm8994->type != WM1811) in wm8994_device_init()
403 dev_warn(wm8994->dev, "Device registered as type %d\n", in wm8994_device_init()
404 wm8994->type); in wm8994_device_init()
405 wm8994->type = WM1811; in wm8994_device_init()
408 devname = "WM8994"; in wm8994_device_init()
409 if (wm8994->type != WM8994) in wm8994_device_init()
410 dev_warn(wm8994->dev, "Device registered as type %d\n", in wm8994_device_init()
411 wm8994->type); in wm8994_device_init()
412 wm8994->type = WM8994; in wm8994_device_init()
416 if (wm8994->type != WM8958) 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 = WM8958; in wm8994_device_init()
422 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", in wm8994_device_init()
428 ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); in wm8994_device_init()
430 dev_err(wm8994->dev, "Failed to read revision register: %d\n", in wm8994_device_init()
434 wm8994->revision = ret & WM8994_CHIP_REV_MASK; in wm8994_device_init()
435 wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT; in wm8994_device_init()
437 switch (wm8994->type) { in wm8994_device_init()
438 case WM8994: in wm8994_device_init()
439 switch (wm8994->revision) { in wm8994_device_init()
442 dev_warn(wm8994->dev, in wm8994_device_init()
444 'A' + wm8994->revision); in wm8994_device_init()
456 switch (wm8994->revision) { in wm8994_device_init()
468 if (wm8994->revision > 1) in wm8994_device_init()
469 wm8994->revision++; in wm8994_device_init()
479 dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, in wm8994_device_init()
480 'A' + wm8994->revision, wm8994->cust_id); in wm8994_device_init()
482 switch (wm8994->type) { in wm8994_device_init()
486 case WM8994: in wm8994_device_init()
493 dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); in wm8994_device_init()
498 ret = regmap_reinit_cache(wm8994->regmap, regmap_config); in wm8994_device_init()
500 dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", in wm8994_device_init()
509 ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, in wm8994_device_init()
510 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); in wm8994_device_init()
512 dev_err(wm8994->dev, "Failed to reset device: %d\n", ret); in wm8994_device_init()
517 ret = regmap_register_patch(wm8994->regmap, regmap_patch, in wm8994_device_init()
520 dev_err(wm8994->dev, "Failed to register patch: %d\n", in wm8994_device_init()
526 wm8994->irq_base = pdata->irq_base; in wm8994_device_init()
527 wm8994->gpio_base = pdata->gpio_base; in wm8994_device_init()
532 wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, in wm8994_device_init()
537 wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; in wm8994_device_init()
545 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, in wm8994_device_init()
558 wm8994_set_bits(wm8994, WM8994_LDO_1 + i, in wm8994_device_init()
561 wm8994_set_bits(wm8994, WM8994_LDO_1 + i, in wm8994_device_init()
565 wm8994_irq_init(wm8994); in wm8994_device_init()
567 ret = mfd_add_devices(wm8994->dev, -1, in wm8994_device_init()
571 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); in wm8994_device_init()
575 pm_runtime_set_active(wm8994->dev); in wm8994_device_init()
576 pm_runtime_enable(wm8994->dev); in wm8994_device_init()
577 pm_runtime_idle(wm8994->dev); in wm8994_device_init()
582 wm8994_irq_exit(wm8994); in wm8994_device_init()
584 regulator_bulk_disable(wm8994->num_supplies, in wm8994_device_init()
585 wm8994->supplies); in wm8994_device_init()
587 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); in wm8994_device_init()
589 mfd_remove_devices(wm8994->dev); in wm8994_device_init()
593 static void wm8994_device_exit(struct wm8994 *wm8994) in wm8994_device_exit() argument
595 pm_runtime_get_sync(wm8994->dev); in wm8994_device_exit()
596 pm_runtime_disable(wm8994->dev); in wm8994_device_exit()
597 pm_runtime_put_noidle(wm8994->dev); in wm8994_device_exit()
598 wm8994_irq_exit(wm8994); in wm8994_device_exit()
599 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); in wm8994_device_exit()
600 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); in wm8994_device_exit()
601 mfd_remove_devices(wm8994->dev); in wm8994_device_exit()
606 { .compatible = "wlf,wm8994", .data = (void *)WM8994 },
614 struct wm8994 *wm8994; in wm8994_i2c_probe() local
617 wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL); in wm8994_i2c_probe()
618 if (wm8994 == NULL) in wm8994_i2c_probe()
621 i2c_set_clientdata(i2c, wm8994); in wm8994_i2c_probe()
622 wm8994->dev = &i2c->dev; in wm8994_i2c_probe()
623 wm8994->irq = i2c->irq; in wm8994_i2c_probe()
625 wm8994->type = (kernel_ulong_t)i2c_get_match_data(i2c); in wm8994_i2c_probe()
627 wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config); in wm8994_i2c_probe()
628 if (IS_ERR(wm8994->regmap)) { in wm8994_i2c_probe()
629 ret = PTR_ERR(wm8994->regmap); in wm8994_i2c_probe()
630 dev_err(wm8994->dev, "Failed to allocate register map: %d\n", in wm8994_i2c_probe()
635 return wm8994_device_init(wm8994, i2c->irq); in wm8994_i2c_probe()
640 struct wm8994 *wm8994 = i2c_get_clientdata(i2c); in wm8994_i2c_remove() local
642 wm8994_device_exit(wm8994); in wm8994_i2c_remove()
648 { "wm8994", WM8994 },
660 .name = "wm8994",
671 MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC");