Lines Matching defs:wm8994
3 * wm8994-core.c -- Device access for Wolfson WM8994
24 #include <linux/mfd/wm8994/core.h>
25 #include <linux/mfd/wm8994/pdata.h>
26 #include <linux/mfd/wm8994/registers.h>
28 #include "wm8994.h"
32 .name = "wm8994-ldo",
37 .name = "wm8994-ldo",
61 .name = "wm8994-codec",
67 .name = "wm8994-gpio",
116 struct wm8994 *wm8994 = dev_get_drvdata(dev);
121 switch (wm8994->type) {
124 ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1);
138 if (!wm8994->ldo_ena_always_driven)
139 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
146 wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
147 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
149 regcache_mark_dirty(wm8994->regmap);
154 ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1,
160 ret = regcache_sync_region(wm8994->regmap,
166 regcache_cache_only(wm8994->regmap, true);
167 wm8994->suspended = true;
169 ret = regulator_bulk_disable(wm8994->num_supplies,
170 wm8994->supplies);
181 struct wm8994 *wm8994 = dev_get_drvdata(dev);
185 if (!wm8994->suspended)
188 ret = regulator_bulk_enable(wm8994->num_supplies,
189 wm8994->supplies);
195 regcache_cache_only(wm8994->regmap, false);
196 ret = regcache_sync(wm8994->regmap);
203 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
207 wm8994->suspended = false;
212 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
263 static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
265 struct device_node *np = wm8994->dev->of_node;
266 struct wm8994_pdata *pdata = &wm8994->pdata;
275 if (wm8994->pdata.gpio_defaults[i] == 0)
306 static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
315 static int wm8994_device_init(struct wm8994 *wm8994, int irq)
324 if (dev_get_platdata(wm8994->dev)) {
325 pdata = dev_get_platdata(wm8994->dev);
326 wm8994->pdata = *pdata;
328 pdata = &wm8994->pdata;
330 ret = wm8994_set_pdata_from_of(wm8994);
334 dev_set_drvdata(wm8994->dev, wm8994);
337 ret = mfd_add_devices(wm8994->dev, 0,
342 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
346 switch (wm8994->type) {
348 wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies);
351 wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
354 wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies);
361 wm8994->supplies = devm_kcalloc(wm8994->dev,
362 wm8994->num_supplies,
365 if (!wm8994->supplies) {
370 switch (wm8994->type) {
373 wm8994->supplies[i].supply = wm1811_main_supplies[i];
377 wm8994->supplies[i].supply = wm8994_main_supplies[i];
381 wm8994->supplies[i].supply = wm8958_main_supplies[i];
390 * wm8994->dev's children (regulators) and those regulators are
393 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
394 wm8994->supplies);
397 dev_err(wm8994->dev, "Failed to get supplies: %d\n",
402 ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies);
404 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
408 ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET);
410 dev_err(wm8994->dev, "Failed to read ID register\n");
416 if (wm8994->type != WM1811)
417 dev_warn(wm8994->dev, "Device registered as type %d\n",
418 wm8994->type);
419 wm8994->type = WM1811;
423 if (wm8994->type != WM8994)
424 dev_warn(wm8994->dev, "Device registered as type %d\n",
425 wm8994->type);
426 wm8994->type = WM8994;
430 if (wm8994->type != WM8958)
431 dev_warn(wm8994->dev, "Device registered as type %d\n",
432 wm8994->type);
433 wm8994->type = WM8958;
436 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
442 ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION);
444 dev_err(wm8994->dev, "Failed to read revision register: %d\n",
448 wm8994->revision = ret & WM8994_CHIP_REV_MASK;
449 wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT;
451 switch (wm8994->type) {
453 switch (wm8994->revision) {
456 dev_warn(wm8994->dev,
458 'A' + wm8994->revision);
470 switch (wm8994->revision) {
482 if (wm8994->revision > 1)
483 wm8994->revision++;
493 dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname,
494 'A' + wm8994->revision, wm8994->cust_id);
496 switch (wm8994->type) {
507 dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type);
512 ret = regmap_reinit_cache(wm8994->regmap, regmap_config);
514 dev_err(wm8994->dev, "Failed to reinit register cache: %d\n",
523 ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
524 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
526 dev_err(wm8994->dev, "Failed to reset device: %d\n", ret);
531 ret = regmap_register_patch(wm8994->regmap, regmap_patch,
534 dev_err(wm8994->dev, "Failed to register patch: %d\n",
540 wm8994->irq_base = pdata->irq_base;
541 wm8994->gpio_base = pdata->gpio_base;
546 wm8994_set_bits(wm8994, WM8994_GPIO_1 + i,
551 wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven;
559 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
572 wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
575 wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
579 wm8994_irq_init(wm8994);
581 ret = mfd_add_devices(wm8994->dev, -1,
585 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
589 pm_runtime_set_active(wm8994->dev);
590 pm_runtime_enable(wm8994->dev);
591 pm_runtime_idle(wm8994->dev);
596 wm8994_irq_exit(wm8994);
598 regulator_bulk_disable(wm8994->num_supplies,
599 wm8994->supplies);
601 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
603 mfd_remove_devices(wm8994->dev);
607 static void wm8994_device_exit(struct wm8994 *wm8994)
609 pm_runtime_get_sync(wm8994->dev);
610 pm_runtime_disable(wm8994->dev);
611 pm_runtime_put_noidle(wm8994->dev);
612 wm8994_irq_exit(wm8994);
613 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
614 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
615 mfd_remove_devices(wm8994->dev);
620 { .compatible = "wlf,wm8994", .data = (void *)WM8994 },
630 struct wm8994 *wm8994;
633 wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL);
634 if (wm8994 == NULL)
637 i2c_set_clientdata(i2c, wm8994);
638 wm8994->dev = &i2c->dev;
639 wm8994->irq = i2c->irq;
644 wm8994->type = (enum wm8994_type)of_id->data;
646 wm8994->type = id->driver_data;
649 wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config);
650 if (IS_ERR(wm8994->regmap)) {
651 ret = PTR_ERR(wm8994->regmap);
652 dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
657 return wm8994_device_init(wm8994, i2c->irq);
662 struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
664 wm8994_device_exit(wm8994);
672 { "wm8994", WM8994 },
684 .name = "wm8994",