2019-05-27 09:55:01 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-01-29 21:20:29 +03:00
|
|
|
/*
|
|
|
|
* wm8994-core.c -- Device access for Wolfson WM8994
|
|
|
|
*
|
|
|
|
* Copyright 2009 Wolfson Microelectronics PLC.
|
|
|
|
*
|
|
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2010-01-29 21:20:29 +03:00
|
|
|
#include <linux/i2c.h>
|
2011-06-17 16:02:27 +04:00
|
|
|
#include <linux/err.h>
|
2010-01-29 21:20:29 +03:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mfd/core.h>
|
2013-04-11 21:11:51 +04:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2010-11-26 20:19:35 +03:00
|
|
|
#include <linux/pm_runtime.h>
|
2011-06-17 16:02:27 +04:00
|
|
|
#include <linux/regmap.h>
|
2010-01-29 21:20:29 +03:00
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
|
|
|
|
#include <linux/mfd/wm8994/core.h>
|
|
|
|
#include <linux/mfd/wm8994/pdata.h>
|
|
|
|
#include <linux/mfd/wm8994/registers.h>
|
|
|
|
|
2011-10-25 16:23:53 +04:00
|
|
|
#include "wm8994.h"
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2013-11-18 17:33:04 +04:00
|
|
|
static const struct mfd_cell wm8994_regulator_devs[] = {
|
2010-11-26 20:19:35 +03:00
|
|
|
{
|
|
|
|
.name = "wm8994-ldo",
|
2015-01-08 04:04:33 +03:00
|
|
|
.id = 0,
|
2010-11-26 20:19:35 +03:00
|
|
|
.pm_runtime_no_callbacks = true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "wm8994-ldo",
|
2015-01-08 04:04:33 +03:00
|
|
|
.id = 1,
|
2010-11-26 20:19:35 +03:00
|
|
|
.pm_runtime_no_callbacks = true,
|
|
|
|
},
|
2010-01-29 21:20:29 +03:00
|
|
|
};
|
|
|
|
|
2020-09-22 22:26:55 +03:00
|
|
|
static const struct resource wm8994_codec_resources[] = {
|
2010-03-26 19:49:15 +03:00
|
|
|
{
|
|
|
|
.start = WM8994_IRQ_TEMP_SHUT,
|
|
|
|
.end = WM8994_IRQ_TEMP_WARN,
|
|
|
|
.flags = IORESOURCE_IRQ,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-09-22 22:26:55 +03:00
|
|
|
static const struct resource wm8994_gpio_resources[] = {
|
2010-03-26 19:49:15 +03:00
|
|
|
{
|
|
|
|
.start = WM8994_IRQ_GPIO(1),
|
|
|
|
.end = WM8994_IRQ_GPIO(11),
|
|
|
|
.flags = IORESOURCE_IRQ,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-11-18 17:33:04 +04:00
|
|
|
static const struct mfd_cell wm8994_devs[] = {
|
2010-03-26 19:49:15 +03:00
|
|
|
{
|
|
|
|
.name = "wm8994-codec",
|
|
|
|
.num_resources = ARRAY_SIZE(wm8994_codec_resources),
|
|
|
|
.resources = wm8994_codec_resources,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "wm8994-gpio",
|
|
|
|
.num_resources = ARRAY_SIZE(wm8994_gpio_resources),
|
|
|
|
.resources = wm8994_gpio_resources,
|
2010-11-26 20:19:35 +03:00
|
|
|
.pm_runtime_no_callbacks = true,
|
2010-03-26 19:49:15 +03:00
|
|
|
},
|
2010-01-29 21:20:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supplies for the main bulk of CODEC; the LDO supplies are ignored
|
|
|
|
* and should be handled via the standard regulator API supply
|
|
|
|
* management.
|
|
|
|
*/
|
2011-05-24 13:35:40 +04:00
|
|
|
static const char *wm1811_main_supplies[] = {
|
|
|
|
"DBVDD1",
|
|
|
|
"DBVDD2",
|
|
|
|
"DBVDD3",
|
|
|
|
"DCVDD",
|
|
|
|
"AVDD1",
|
|
|
|
"AVDD2",
|
|
|
|
"CPVDD",
|
|
|
|
"SPKVDD1",
|
|
|
|
"SPKVDD2",
|
|
|
|
};
|
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
static const char *wm8994_main_supplies[] = {
|
|
|
|
"DBVDD",
|
|
|
|
"DCVDD",
|
|
|
|
"AVDD1",
|
|
|
|
"AVDD2",
|
|
|
|
"CPVDD",
|
|
|
|
"SPKVDD1",
|
|
|
|
"SPKVDD2",
|
|
|
|
};
|
|
|
|
|
2010-08-31 22:25:12 +04:00
|
|
|
static const char *wm8958_main_supplies[] = {
|
|
|
|
"DBVDD1",
|
|
|
|
"DBVDD2",
|
|
|
|
"DBVDD3",
|
|
|
|
"DCVDD",
|
|
|
|
"AVDD1",
|
|
|
|
"AVDD2",
|
|
|
|
"CPVDD",
|
|
|
|
"SPKVDD1",
|
|
|
|
"SPKVDD2",
|
|
|
|
};
|
|
|
|
|
2014-12-05 05:04:12 +03:00
|
|
|
#ifdef CONFIG_PM
|
2010-11-26 20:19:35 +03:00
|
|
|
static int wm8994_suspend(struct device *dev)
|
2010-01-29 21:20:29 +03:00
|
|
|
{
|
|
|
|
struct wm8994 *wm8994 = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
2011-02-04 17:57:43 +03:00
|
|
|
/* Don't actually go through with the suspend if the CODEC is
|
2013-07-17 16:16:09 +04:00
|
|
|
* still active for accessory detect. */
|
2011-08-13 09:37:48 +04:00
|
|
|
switch (wm8994->type) {
|
|
|
|
case WM8958:
|
2011-11-05 03:14:46 +04:00
|
|
|
case WM1811:
|
2011-08-13 09:37:48 +04:00
|
|
|
ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "Failed to read power status: %d\n", ret);
|
|
|
|
} else if (ret & WM8958_MICD_ENA) {
|
|
|
|
dev_dbg(dev, "CODEC still active, ignoring suspend\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-22 17:43:55 +04:00
|
|
|
/* Disable LDO pulldowns while the device is suspended if we
|
|
|
|
* don't know that something will be driving them. */
|
|
|
|
if (!wm8994->ldo_ena_always_driven)
|
|
|
|
wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
|
|
|
|
WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
|
|
|
|
WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD);
|
|
|
|
|
2011-02-21 21:30:31 +03:00
|
|
|
/* Explicitly put the device into reset in case regulators
|
|
|
|
* don't get disabled in order to ensure consistent restart.
|
|
|
|
*/
|
2011-10-25 15:25:43 +04:00
|
|
|
wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
|
|
|
|
wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
|
2011-02-21 21:30:31 +03:00
|
|
|
|
2012-06-29 17:55:39 +04:00
|
|
|
regcache_mark_dirty(wm8994->regmap);
|
|
|
|
|
2012-06-11 20:43:35 +04:00
|
|
|
/* Restore GPIO registers to prevent problems with mismatched
|
|
|
|
* pin configurations.
|
|
|
|
*/
|
2012-06-29 17:55:39 +04:00
|
|
|
ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1,
|
|
|
|
WM8994_GPIO_11);
|
2012-06-11 20:43:35 +04:00
|
|
|
if (ret != 0)
|
|
|
|
dev_err(dev, "Failed to restore GPIO registers: %d\n", ret);
|
|
|
|
|
2012-06-29 17:55:40 +04:00
|
|
|
/* In case one of the GPIOs is used as a wake input. */
|
|
|
|
ret = regcache_sync_region(wm8994->regmap,
|
|
|
|
WM8994_INTERRUPT_STATUS_1_MASK,
|
|
|
|
WM8994_INTERRUPT_STATUS_1_MASK);
|
|
|
|
if (ret != 0)
|
|
|
|
dev_err(dev, "Failed to restore interrupt mask: %d\n", ret);
|
|
|
|
|
2012-01-09 12:36:42 +04:00
|
|
|
regcache_cache_only(wm8994->regmap, true);
|
2011-02-04 17:57:43 +03:00
|
|
|
wm8994->suspended = true;
|
|
|
|
|
2010-08-31 22:25:12 +04:00
|
|
|
ret = regulator_bulk_disable(wm8994->num_supplies,
|
2010-01-29 21:20:29 +03:00
|
|
|
wm8994->supplies);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(dev, "Failed to disable supplies: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-26 20:19:35 +03:00
|
|
|
static int wm8994_resume(struct device *dev)
|
2010-01-29 21:20:29 +03:00
|
|
|
{
|
|
|
|
struct wm8994 *wm8994 = dev_get_drvdata(dev);
|
2011-10-25 16:23:53 +04:00
|
|
|
int ret;
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2011-02-04 17:57:43 +03:00
|
|
|
/* We may have lied to the PM core about suspending */
|
|
|
|
if (!wm8994->suspended)
|
|
|
|
return 0;
|
|
|
|
|
2010-08-31 22:25:12 +04:00
|
|
|
ret = regulator_bulk_enable(wm8994->num_supplies,
|
2010-01-29 21:20:29 +03:00
|
|
|
wm8994->supplies);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(dev, "Failed to enable supplies: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-09 12:36:42 +04:00
|
|
|
regcache_cache_only(wm8994->regmap, false);
|
2011-10-25 16:23:53 +04:00
|
|
|
ret = regcache_sync(wm8994->regmap);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(dev, "Failed to restore register map: %d\n", ret);
|
|
|
|
goto err_enable;
|
2011-06-07 14:49:42 +04:00
|
|
|
}
|
2010-03-26 19:49:15 +03:00
|
|
|
|
2011-08-22 17:43:55 +04:00
|
|
|
/* Disable LDO pulldowns while the device is active */
|
|
|
|
wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
|
|
|
|
WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
|
|
|
|
0);
|
|
|
|
|
2011-02-04 17:57:43 +03:00
|
|
|
wm8994->suspended = false;
|
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
return 0;
|
2011-10-25 16:23:53 +04:00
|
|
|
|
|
|
|
err_enable:
|
|
|
|
regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
|
|
|
|
|
|
|
|
return ret;
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_REGULATOR
|
|
|
|
static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
|
|
|
|
{
|
|
|
|
struct wm8994_ldo_pdata *ldo_pdata;
|
|
|
|
|
|
|
|
if (!pdata)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ldo_pdata = &pdata->ldo[ldo];
|
|
|
|
|
|
|
|
if (!ldo_pdata->init_data)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ldo_pdata->init_data->num_consumer_supplies != 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-16 18:36:21 +03:00
|
|
|
static const struct reg_sequence wm8994_revc_patch[] = {
|
2012-01-21 16:11:53 +04:00
|
|
|
{ 0x102, 0x3 },
|
|
|
|
{ 0x56, 0x3 },
|
|
|
|
{ 0x817, 0x0 },
|
|
|
|
{ 0x102, 0x0 },
|
|
|
|
};
|
|
|
|
|
2015-07-16 18:36:21 +03:00
|
|
|
static const struct reg_sequence wm8958_reva_patch[] = {
|
2012-01-21 16:11:53 +04:00
|
|
|
{ 0x102, 0x3 },
|
|
|
|
{ 0xcb, 0x81 },
|
|
|
|
{ 0x817, 0x0 },
|
|
|
|
{ 0x102, 0x0 },
|
|
|
|
};
|
|
|
|
|
2015-07-16 18:36:21 +03:00
|
|
|
static const struct reg_sequence wm1811_reva_patch[] = {
|
2012-01-21 16:11:53 +04:00
|
|
|
{ 0x102, 0x3 },
|
2012-08-23 19:10:29 +04:00
|
|
|
{ 0x56, 0xc07 },
|
2012-01-21 16:11:53 +04:00
|
|
|
{ 0x5d, 0x7e },
|
|
|
|
{ 0x5e, 0x0 },
|
|
|
|
{ 0x102, 0x0 },
|
|
|
|
};
|
|
|
|
|
2013-04-11 21:11:51 +04:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
|
|
|
|
{
|
|
|
|
struct device_node *np = wm8994->dev->of_node;
|
|
|
|
struct wm8994_pdata *pdata = &wm8994->pdata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!np)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults,
|
|
|
|
ARRAY_SIZE(pdata->gpio_defaults)) >= 0) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
|
|
|
|
if (wm8994->pdata.gpio_defaults[i] == 0)
|
|
|
|
pdata->gpio_defaults[i]
|
|
|
|
= WM8994_CONFIGURE_GPIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias,
|
|
|
|
ARRAY_SIZE(pdata->micbias));
|
|
|
|
|
|
|
|
pdata->lineout1_diff = true;
|
|
|
|
pdata->lineout2_diff = true;
|
|
|
|
if (of_find_property(np, "wlf,lineout1-se", NULL))
|
|
|
|
pdata->lineout1_diff = false;
|
|
|
|
if (of_find_property(np, "wlf,lineout2-se", NULL))
|
|
|
|
pdata->lineout2_diff = false;
|
|
|
|
|
|
|
|
if (of_find_property(np, "wlf,lineout1-feedback", NULL))
|
|
|
|
pdata->lineout1fb = true;
|
|
|
|
if (of_find_property(np, "wlf,lineout2-feedback", NULL))
|
|
|
|
pdata->lineout2fb = true;
|
|
|
|
|
|
|
|
if (of_find_property(np, "wlf,ldoena-always-driven", NULL))
|
|
|
|
pdata->lineout2fb = true;
|
|
|
|
|
2018-07-09 20:46:44 +03:00
|
|
|
pdata->spkmode_pu = of_property_read_bool(np, "wlf,spkmode-pu");
|
|
|
|
|
2018-07-09 20:46:46 +03:00
|
|
|
pdata->csnaddr_pd = of_property_read_bool(np, "wlf,csnaddr-pd");
|
|
|
|
|
2013-04-11 21:11:51 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
/*
|
|
|
|
* Instantiate the generic non-control parts of the device.
|
|
|
|
*/
|
2012-11-19 22:23:04 +04:00
|
|
|
static int wm8994_device_init(struct wm8994 *wm8994, int irq)
|
2010-01-29 21:20:29 +03:00
|
|
|
{
|
2012-10-08 06:21:09 +04:00
|
|
|
struct wm8994_pdata *pdata;
|
2011-12-03 21:10:32 +04:00
|
|
|
struct regmap_config *regmap_config;
|
2015-07-16 18:36:21 +03:00
|
|
|
const struct reg_sequence *regmap_patch = NULL;
|
2010-08-31 22:25:12 +04:00
|
|
|
const char *devname;
|
2013-02-20 06:53:36 +04:00
|
|
|
int ret, i, patch_regs = 0;
|
2011-11-03 17:20:38 +04:00
|
|
|
int pulls = 0;
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2012-10-08 06:21:09 +04:00
|
|
|
if (dev_get_platdata(wm8994->dev)) {
|
|
|
|
pdata = dev_get_platdata(wm8994->dev);
|
|
|
|
wm8994->pdata = *pdata;
|
|
|
|
}
|
|
|
|
pdata = &wm8994->pdata;
|
|
|
|
|
2013-04-11 21:11:51 +04:00
|
|
|
ret = wm8994_set_pdata_from_of(wm8994);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
dev_set_drvdata(wm8994->dev, wm8994);
|
|
|
|
|
|
|
|
/* Add the on-chip regulators first for bootstrapping */
|
2015-01-08 04:04:33 +03:00
|
|
|
ret = mfd_add_devices(wm8994->dev, 0,
|
2010-01-29 21:20:29 +03:00
|
|
|
wm8994_regulator_devs,
|
|
|
|
ARRAY_SIZE(wm8994_regulator_devs),
|
2012-09-11 11:16:36 +04:00
|
|
|
NULL, 0, NULL);
|
2010-01-29 21:20:29 +03:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
|
2012-01-31 00:06:05 +04:00
|
|
|
goto err;
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
|
2010-08-31 22:25:12 +04:00
|
|
|
switch (wm8994->type) {
|
2011-05-24 13:35:40 +04:00
|
|
|
case WM1811:
|
|
|
|
wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies);
|
|
|
|
break;
|
2010-08-31 22:25:12 +04:00
|
|
|
case WM8994:
|
|
|
|
wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
|
|
|
|
break;
|
|
|
|
case WM8958:
|
|
|
|
wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
2012-01-31 00:06:05 +04:00
|
|
|
goto err;
|
2010-08-31 22:25:12 +04:00
|
|
|
}
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 00:07:58 +03:00
|
|
|
wm8994->supplies = devm_kcalloc(wm8994->dev,
|
|
|
|
wm8994->num_supplies,
|
|
|
|
sizeof(struct regulator_bulk_data),
|
|
|
|
GFP_KERNEL);
|
2010-08-04 05:44:47 +04:00
|
|
|
if (!wm8994->supplies) {
|
|
|
|
ret = -ENOMEM;
|
2012-01-31 00:06:05 +04:00
|
|
|
goto err;
|
2010-08-04 05:44:47 +04:00
|
|
|
}
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2010-08-31 22:25:12 +04:00
|
|
|
switch (wm8994->type) {
|
2011-05-24 13:35:40 +04:00
|
|
|
case WM1811:
|
|
|
|
for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++)
|
|
|
|
wm8994->supplies[i].supply = wm1811_main_supplies[i];
|
|
|
|
break;
|
2010-08-31 22:25:12 +04:00
|
|
|
case WM8994:
|
|
|
|
for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
|
|
|
|
wm8994->supplies[i].supply = wm8994_main_supplies[i];
|
|
|
|
break;
|
|
|
|
case WM8958:
|
|
|
|
for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++)
|
|
|
|
wm8994->supplies[i].supply = wm8958_main_supplies[i];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
2012-01-31 00:06:05 +04:00
|
|
|
goto err;
|
2010-08-31 22:25:12 +04:00
|
|
|
}
|
2016-10-27 13:20:18 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Can't use devres helper here as some of the supplies are provided by
|
|
|
|
* wm8994->dev's children (regulators) and those regulators are
|
|
|
|
* unregistered by the devres core before the supplies are freed.
|
|
|
|
*/
|
|
|
|
ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
|
2010-01-29 21:20:29 +03:00
|
|
|
wm8994->supplies);
|
|
|
|
if (ret != 0) {
|
2020-04-27 10:48:31 +03:00
|
|
|
if (ret != -EPROBE_DEFER)
|
|
|
|
dev_err(wm8994->dev, "Failed to get supplies: %d\n",
|
|
|
|
ret);
|
2012-01-31 00:06:05 +04:00
|
|
|
goto err;
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
|
2016-09-16 06:26:58 +03:00
|
|
|
ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies);
|
2010-01-29 21:20:29 +03:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
|
2016-10-27 13:20:18 +03:00
|
|
|
goto err_regulator_free;
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to read ID register\n");
|
|
|
|
goto err_enable;
|
|
|
|
}
|
2010-08-31 22:25:12 +04:00
|
|
|
switch (ret) {
|
2011-05-24 13:35:40 +04:00
|
|
|
case 0x1811:
|
|
|
|
devname = "WM1811";
|
|
|
|
if (wm8994->type != WM1811)
|
|
|
|
dev_warn(wm8994->dev, "Device registered as type %d\n",
|
|
|
|
wm8994->type);
|
|
|
|
wm8994->type = WM1811;
|
|
|
|
break;
|
2010-08-31 22:25:12 +04:00
|
|
|
case 0x8994:
|
|
|
|
devname = "WM8994";
|
|
|
|
if (wm8994->type != WM8994)
|
|
|
|
dev_warn(wm8994->dev, "Device registered as type %d\n",
|
|
|
|
wm8994->type);
|
|
|
|
wm8994->type = WM8994;
|
|
|
|
break;
|
|
|
|
case 0x8958:
|
|
|
|
devname = "WM8958";
|
|
|
|
if (wm8994->type != WM8958)
|
|
|
|
dev_warn(wm8994->dev, "Device registered as type %d\n",
|
|
|
|
wm8994->type);
|
|
|
|
wm8994->type = WM8958;
|
|
|
|
break;
|
|
|
|
default:
|
2010-01-29 21:20:29 +03:00
|
|
|
dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
|
|
|
|
ret);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to read revision register: %d\n",
|
|
|
|
ret);
|
|
|
|
goto err_enable;
|
|
|
|
}
|
2012-05-07 13:03:22 +04:00
|
|
|
wm8994->revision = ret & WM8994_CHIP_REV_MASK;
|
|
|
|
wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT;
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2011-06-02 22:18:55 +04:00
|
|
|
switch (wm8994->type) {
|
|
|
|
case WM8994:
|
2011-12-01 17:55:49 +04:00
|
|
|
switch (wm8994->revision) {
|
2011-06-02 22:18:55 +04:00
|
|
|
case 0:
|
|
|
|
case 1:
|
2010-08-31 22:25:12 +04:00
|
|
|
dev_warn(wm8994->dev,
|
|
|
|
"revision %c not fully supported\n",
|
2011-12-01 17:55:49 +04:00
|
|
|
'A' + wm8994->revision);
|
2011-06-02 22:18:55 +04:00
|
|
|
break;
|
2012-01-21 16:11:53 +04:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2012-11-27 19:23:30 +04:00
|
|
|
default:
|
2012-01-21 16:11:53 +04:00
|
|
|
regmap_patch = wm8994_revc_patch;
|
|
|
|
patch_regs = ARRAY_SIZE(wm8994_revc_patch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8958:
|
|
|
|
switch (wm8994->revision) {
|
|
|
|
case 0:
|
|
|
|
regmap_patch = wm8958_reva_patch;
|
|
|
|
patch_regs = ARRAY_SIZE(wm8958_reva_patch);
|
|
|
|
break;
|
2011-06-02 22:18:55 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-01-29 21:20:29 +03:00
|
|
|
break;
|
2012-01-21 16:11:53 +04:00
|
|
|
|
2011-11-30 20:51:04 +04:00
|
|
|
case WM1811:
|
|
|
|
/* Revision C did not change the relevant layer */
|
2011-12-01 17:55:49 +04:00
|
|
|
if (wm8994->revision > 1)
|
|
|
|
wm8994->revision++;
|
2012-11-27 19:23:30 +04:00
|
|
|
|
|
|
|
regmap_patch = wm1811_reva_patch;
|
|
|
|
patch_regs = ARRAY_SIZE(wm1811_reva_patch);
|
2011-11-30 20:51:04 +04:00
|
|
|
break;
|
2012-01-21 16:11:53 +04:00
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-07 13:03:22 +04:00
|
|
|
dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname,
|
|
|
|
'A' + wm8994->revision, wm8994->cust_id);
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2011-12-03 21:10:32 +04:00
|
|
|
switch (wm8994->type) {
|
|
|
|
case WM1811:
|
|
|
|
regmap_config = &wm1811_regmap_config;
|
|
|
|
break;
|
|
|
|
case WM8994:
|
|
|
|
regmap_config = &wm8994_regmap_config;
|
|
|
|
break;
|
|
|
|
case WM8958:
|
|
|
|
regmap_config = &wm8958_regmap_config;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type);
|
2018-06-14 14:57:14 +03:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_enable;
|
2011-12-03 21:10:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_reinit_cache(wm8994->regmap, regmap_config);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to reinit register cache: %d\n",
|
|
|
|
ret);
|
2018-06-14 14:57:14 +03:00
|
|
|
goto err_enable;
|
2011-12-03 21:10:32 +04:00
|
|
|
}
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2013-05-17 16:25:21 +04:00
|
|
|
/* Explicitly put the device into reset in case regulators
|
|
|
|
* don't get disabled in order to ensure we know the device
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
|
|
|
|
wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to reset device: %d\n", ret);
|
2018-06-14 14:57:14 +03:00
|
|
|
goto err_enable;
|
2013-05-17 16:25:21 +04:00
|
|
|
}
|
|
|
|
|
2012-01-21 16:11:53 +04:00
|
|
|
if (regmap_patch) {
|
|
|
|
ret = regmap_register_patch(wm8994->regmap, regmap_patch,
|
|
|
|
patch_regs);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to register patch: %d\n",
|
|
|
|
ret);
|
2018-06-14 14:57:14 +03:00
|
|
|
goto err_enable;
|
2012-01-21 16:11:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 06:21:09 +04:00
|
|
|
wm8994->irq_base = pdata->irq_base;
|
|
|
|
wm8994->gpio_base = pdata->gpio_base;
|
|
|
|
|
|
|
|
/* GPIO configuration is only applied if it's non-zero */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
|
|
|
|
if (pdata->gpio_defaults[i]) {
|
|
|
|
wm8994_set_bits(wm8994, WM8994_GPIO_1 + i,
|
|
|
|
0xffff, pdata->gpio_defaults[i]);
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
2012-10-08 06:21:09 +04:00
|
|
|
}
|
2011-08-22 17:43:55 +04:00
|
|
|
|
2012-10-08 06:21:09 +04:00
|
|
|
wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven;
|
2011-11-03 17:20:38 +04:00
|
|
|
|
2012-10-08 06:21:09 +04:00
|
|
|
if (pdata->spkmode_pu)
|
|
|
|
pulls |= WM8994_SPKMODE_PU;
|
2018-07-09 20:46:46 +03:00
|
|
|
if (pdata->csnaddr_pd)
|
|
|
|
pulls |= WM8994_CSNADDR_PD;
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2011-11-03 17:20:38 +04:00
|
|
|
/* Disable unneeded pulls */
|
2011-08-22 17:43:55 +04:00
|
|
|
wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
|
2011-11-03 17:20:38 +04:00
|
|
|
WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD |
|
|
|
|
WM8994_SPKMODE_PU | WM8994_CSNADDR_PD,
|
|
|
|
pulls);
|
2011-08-22 17:43:55 +04:00
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
/* In some system designs where the regulators are not in use,
|
|
|
|
* we can achieve a small reduction in leakage currents by
|
|
|
|
* floating LDO outputs. This bit makes no difference if the
|
|
|
|
* LDOs are enabled, it only affects cases where the LDOs were
|
|
|
|
* in operation and are then disabled.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < WM8994_NUM_LDO_REGS; i++) {
|
|
|
|
if (wm8994_ldo_in_use(pdata, i))
|
|
|
|
wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
|
|
|
|
WM8994_LDO1_DISCH, WM8994_LDO1_DISCH);
|
|
|
|
else
|
|
|
|
wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
|
|
|
|
WM8994_LDO1_DISCH, 0);
|
|
|
|
}
|
|
|
|
|
2010-03-26 19:49:15 +03:00
|
|
|
wm8994_irq_init(wm8994);
|
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
ret = mfd_add_devices(wm8994->dev, -1,
|
|
|
|
wm8994_devs, ARRAY_SIZE(wm8994_devs),
|
2012-09-11 11:16:36 +04:00
|
|
|
NULL, 0, NULL);
|
2010-01-29 21:20:29 +03:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
|
2010-03-26 19:49:15 +03:00
|
|
|
goto err_irq;
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
|
2020-04-27 10:48:30 +03:00
|
|
|
pm_runtime_set_active(wm8994->dev);
|
2010-11-26 20:19:35 +03:00
|
|
|
pm_runtime_enable(wm8994->dev);
|
2012-02-06 22:47:37 +04:00
|
|
|
pm_runtime_idle(wm8994->dev);
|
2010-11-26 20:19:35 +03:00
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
return 0;
|
|
|
|
|
2010-03-26 19:49:15 +03:00
|
|
|
err_irq:
|
|
|
|
wm8994_irq_exit(wm8994);
|
2010-01-29 21:20:29 +03:00
|
|
|
err_enable:
|
2010-08-31 22:25:12 +04:00
|
|
|
regulator_bulk_disable(wm8994->num_supplies,
|
2010-01-29 21:20:29 +03:00
|
|
|
wm8994->supplies);
|
2016-10-27 13:20:18 +03:00
|
|
|
err_regulator_free:
|
|
|
|
regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
|
2012-01-31 00:06:05 +04:00
|
|
|
err:
|
2010-01-29 21:20:29 +03:00
|
|
|
mfd_remove_devices(wm8994->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 22:26:01 +04:00
|
|
|
static void wm8994_device_exit(struct wm8994 *wm8994)
|
2010-01-29 21:20:29 +03:00
|
|
|
{
|
2020-04-27 10:48:30 +03:00
|
|
|
pm_runtime_get_sync(wm8994->dev);
|
2010-11-26 20:19:35 +03:00
|
|
|
pm_runtime_disable(wm8994->dev);
|
2020-04-27 10:48:30 +03:00
|
|
|
pm_runtime_put_noidle(wm8994->dev);
|
2010-03-26 19:49:15 +03:00
|
|
|
wm8994_irq_exit(wm8994);
|
2016-09-16 06:26:58 +03:00
|
|
|
regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
|
2016-10-27 13:20:18 +03:00
|
|
|
regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
|
2016-09-16 06:26:59 +03:00
|
|
|
mfd_remove_devices(wm8994->dev);
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
|
2011-11-22 22:22:29 +04:00
|
|
|
static const struct of_device_id wm8994_of_match[] = {
|
2013-04-11 21:11:50 +04:00
|
|
|
{ .compatible = "wlf,wm1811", .data = (void *)WM1811 },
|
|
|
|
{ .compatible = "wlf,wm8994", .data = (void *)WM8994 },
|
|
|
|
{ .compatible = "wlf,wm8958", .data = (void *)WM8958 },
|
2011-11-22 22:22:29 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, wm8994_of_match);
|
|
|
|
|
2012-11-19 22:23:04 +04:00
|
|
|
static int wm8994_i2c_probe(struct i2c_client *i2c,
|
2012-02-18 03:57:01 +04:00
|
|
|
const struct i2c_device_id *id)
|
2010-01-29 21:20:29 +03:00
|
|
|
{
|
2013-04-11 21:11:51 +04:00
|
|
|
const struct of_device_id *of_id;
|
2010-01-29 21:20:29 +03:00
|
|
|
struct wm8994 *wm8994;
|
2011-06-17 16:02:27 +04:00
|
|
|
int ret;
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2011-10-25 15:45:40 +04:00
|
|
|
wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL);
|
2010-08-09 10:52:16 +04:00
|
|
|
if (wm8994 == NULL)
|
2010-01-29 21:20:29 +03:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
i2c_set_clientdata(i2c, wm8994);
|
|
|
|
wm8994->dev = &i2c->dev;
|
2010-03-26 19:49:15 +03:00
|
|
|
wm8994->irq = i2c->irq;
|
2013-04-11 21:11:51 +04:00
|
|
|
|
|
|
|
if (i2c->dev.of_node) {
|
|
|
|
of_id = of_match_device(wm8994_of_match, &i2c->dev);
|
|
|
|
if (of_id)
|
2014-01-23 18:47:13 +04:00
|
|
|
wm8994->type = (enum wm8994_type)of_id->data;
|
2013-04-11 21:11:51 +04:00
|
|
|
} else {
|
|
|
|
wm8994->type = id->driver_data;
|
|
|
|
}
|
2010-01-29 21:20:29 +03:00
|
|
|
|
2012-01-31 00:06:05 +04:00
|
|
|
wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config);
|
2011-06-17 16:02:27 +04:00
|
|
|
if (IS_ERR(wm8994->regmap)) {
|
|
|
|
ret = PTR_ERR(wm8994->regmap);
|
|
|
|
dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-31 22:25:12 +04:00
|
|
|
return wm8994_device_init(wm8994, i2c->irq);
|
2010-01-29 21:20:29 +03:00
|
|
|
}
|
|
|
|
|
2022-08-15 11:02:30 +03:00
|
|
|
static void wm8994_i2c_remove(struct i2c_client *i2c)
|
2010-01-29 21:20:29 +03:00
|
|
|
{
|
|
|
|
struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
|
|
|
|
|
|
|
|
wm8994_device_exit(wm8994);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id wm8994_i2c_id[] = {
|
2011-05-24 13:35:40 +04:00
|
|
|
{ "wm1811", WM1811 },
|
2011-12-01 00:16:42 +04:00
|
|
|
{ "wm1811a", WM1811 },
|
2010-08-31 22:25:12 +04:00
|
|
|
{ "wm8994", WM8994 },
|
|
|
|
{ "wm8958", WM8958 },
|
2010-01-29 21:20:29 +03:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);
|
|
|
|
|
2013-03-22 15:40:22 +04:00
|
|
|
static const struct dev_pm_ops wm8994_pm_ops = {
|
|
|
|
SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL)
|
|
|
|
};
|
2010-11-26 20:19:35 +03:00
|
|
|
|
2010-01-29 21:20:29 +03:00
|
|
|
static struct i2c_driver wm8994_i2c_driver = {
|
|
|
|
.driver = {
|
2010-11-26 20:19:35 +03:00
|
|
|
.name = "wm8994",
|
|
|
|
.pm = &wm8994_pm_ops,
|
2020-11-20 19:21:31 +03:00
|
|
|
.of_match_table = wm8994_of_match,
|
2010-01-29 21:20:29 +03:00
|
|
|
},
|
|
|
|
.probe = wm8994_i2c_probe,
|
2012-11-19 22:20:24 +04:00
|
|
|
.remove = wm8994_i2c_remove,
|
2010-01-29 21:20:29 +03:00
|
|
|
.id_table = wm8994_i2c_id,
|
|
|
|
};
|
|
|
|
|
2012-05-07 13:03:23 +04:00
|
|
|
module_i2c_driver(wm8994_i2c_driver);
|
2010-01-29 21:20:29 +03:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
|
2020-04-27 10:48:29 +03:00
|
|
|
MODULE_SOFTDEP("pre: wm8994_regulator");
|