2008-09-10 19:58:42 +02:00
|
|
|
/*
|
|
|
|
* Core driver for WM8400.
|
|
|
|
*
|
|
|
|
* Copyright 2008 Wolfson Microelectronics PLC.
|
|
|
|
*
|
|
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-07-03 21:13:27 +02:00
|
|
|
#include <linux/module.h>
|
2008-09-10 19:58:42 +02:00
|
|
|
#include <linux/bug.h>
|
2011-08-09 09:34:29 +02:00
|
|
|
#include <linux/err.h>
|
2008-09-10 19:58:42 +02:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/kernel.h>
|
2008-12-18 10:54:22 +01:00
|
|
|
#include <linux/mfd/core.h>
|
2008-09-10 19:58:42 +02:00
|
|
|
#include <linux/mfd/wm8400-private.h>
|
|
|
|
#include <linux/mfd/wm8400-audio.h>
|
2011-08-09 09:34:29 +02:00
|
|
|
#include <linux/regmap.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2008-09-10 19:58:42 +02:00
|
|
|
|
2012-05-09 23:53:48 +02:00
|
|
|
static bool wm8400_volatile(struct device *dev, unsigned int reg)
|
2008-09-10 19:58:42 +02:00
|
|
|
{
|
2012-05-09 23:53:48 +02:00
|
|
|
switch (reg) {
|
|
|
|
case WM8400_INTERRUPT_STATUS_1:
|
|
|
|
case WM8400_INTERRUPT_LEVELS:
|
|
|
|
case WM8400_SHUTDOWN_REASON:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
2008-09-10 19:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wm8400_reg_read - Single register read
|
|
|
|
*
|
|
|
|
* @wm8400: Pointer to wm8400 control structure
|
|
|
|
* @reg: Register to read
|
|
|
|
*
|
|
|
|
* @return Read value
|
|
|
|
*/
|
|
|
|
u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg)
|
|
|
|
{
|
2012-05-09 23:53:48 +02:00
|
|
|
unsigned int val;
|
|
|
|
int ret;
|
2008-09-10 19:58:42 +02:00
|
|
|
|
2012-05-09 23:53:48 +02:00
|
|
|
ret = regmap_read(wm8400->regmap, reg, &val);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-09-10 19:58:42 +02:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(wm8400_reg_read);
|
|
|
|
|
|
|
|
int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data)
|
|
|
|
{
|
2012-05-09 23:53:48 +02:00
|
|
|
return regmap_bulk_read(wm8400->regmap, reg, data, count);
|
2008-09-10 19:58:42 +02:00
|
|
|
}
|
2012-05-14 11:13:16 +02:00
|
|
|
EXPORT_SYMBOL_GPL(wm8400_block_read);
|
2008-09-10 19:58:42 +02:00
|
|
|
|
2008-12-18 10:54:22 +01:00
|
|
|
static int wm8400_register_codec(struct wm8400 *wm8400)
|
|
|
|
{
|
|
|
|
struct mfd_cell cell = {
|
|
|
|
.name = "wm8400-codec",
|
2011-05-11 10:44:36 +02:00
|
|
|
.platform_data = wm8400,
|
|
|
|
.pdata_size = sizeof(*wm8400),
|
2008-12-18 10:54:22 +01:00
|
|
|
};
|
|
|
|
|
2012-09-11 09:16:36 +02:00
|
|
|
return mfd_add_devices(wm8400->dev, -1, &cell, 1, NULL, 0, NULL);
|
2008-12-18 10:54:22 +01:00
|
|
|
}
|
|
|
|
|
2008-09-10 19:58:42 +02:00
|
|
|
/*
|
|
|
|
* wm8400_init - Generic initialisation
|
|
|
|
*
|
|
|
|
* The WM8400 can be configured as either an I2C or SPI device. Probe
|
|
|
|
* functions for each bus set up the accessors then call into this to
|
|
|
|
* set up the device itself.
|
|
|
|
*/
|
|
|
|
static int wm8400_init(struct wm8400 *wm8400,
|
|
|
|
struct wm8400_platform_data *pdata)
|
|
|
|
{
|
2012-05-09 23:53:48 +02:00
|
|
|
unsigned int reg;
|
|
|
|
int ret;
|
2008-09-10 19:58:42 +02:00
|
|
|
|
2009-04-30 23:43:31 +02:00
|
|
|
dev_set_drvdata(wm8400->dev, wm8400);
|
2008-09-10 19:58:42 +02:00
|
|
|
|
|
|
|
/* Check that this is actually a WM8400 */
|
2012-05-09 23:53:48 +02:00
|
|
|
ret = regmap_read(wm8400->regmap, WM8400_RESET_ID, ®);
|
2008-09-10 19:58:42 +02:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8400->dev, "Chip ID register read failed\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2012-05-09 23:53:48 +02:00
|
|
|
if (reg != 0x6172) {
|
|
|
|
dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n",
|
|
|
|
reg);
|
2008-09-10 19:58:42 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2012-05-09 23:53:48 +02:00
|
|
|
ret = regmap_read(wm8400->regmap, WM8400_ID, ®);
|
2008-09-10 19:58:42 +02:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8400->dev, "ID register read failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
reg = (reg & WM8400_CHIP_REV_MASK) >> WM8400_CHIP_REV_SHIFT;
|
|
|
|
dev_info(wm8400->dev, "WM8400 revision %x\n", reg);
|
|
|
|
|
2008-12-18 10:54:22 +01:00
|
|
|
ret = wm8400_register_codec(wm8400);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(wm8400->dev, "Failed to register codec\n");
|
|
|
|
goto err_children;
|
|
|
|
}
|
|
|
|
|
2008-09-10 19:58:42 +02:00
|
|
|
if (pdata && pdata->platform_init) {
|
|
|
|
ret = pdata->platform_init(wm8400->dev);
|
2008-12-18 10:54:22 +01:00
|
|
|
if (ret != 0) {
|
2008-09-10 19:58:42 +02:00
|
|
|
dev_err(wm8400->dev, "Platform init failed: %d\n",
|
|
|
|
ret);
|
2008-12-18 10:54:22 +01:00
|
|
|
goto err_children;
|
|
|
|
}
|
2008-09-10 19:58:42 +02:00
|
|
|
} else
|
|
|
|
dev_warn(wm8400->dev, "No platform initialisation supplied\n");
|
|
|
|
|
2008-12-18 10:54:22 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_children:
|
|
|
|
mfd_remove_devices(wm8400->dev);
|
2008-09-10 19:58:42 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wm8400_release(struct wm8400 *wm8400)
|
|
|
|
{
|
2008-12-18 10:54:22 +01:00
|
|
|
mfd_remove_devices(wm8400->dev);
|
2008-09-10 19:58:42 +02:00
|
|
|
}
|
|
|
|
|
2011-08-09 09:34:29 +02:00
|
|
|
static const struct regmap_config wm8400_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 16,
|
|
|
|
.max_register = WM8400_REGISTER_COUNT - 1,
|
2012-05-09 23:53:48 +02:00
|
|
|
|
|
|
|
.volatile_reg = wm8400_volatile,
|
|
|
|
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
2011-08-09 09:34:29 +02:00
|
|
|
};
|
2008-09-10 19:58:42 +02:00
|
|
|
|
2012-05-09 23:53:48 +02:00
|
|
|
/**
|
|
|
|
* wm8400_reset_codec_reg_cache - Reset cached codec registers to
|
|
|
|
* their default values.
|
|
|
|
*/
|
|
|
|
void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400)
|
|
|
|
{
|
|
|
|
regmap_reinit_cache(wm8400->regmap, &wm8400_regmap_config);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(wm8400_reset_codec_reg_cache);
|
|
|
|
|
2011-08-09 09:34:29 +02:00
|
|
|
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
|
2008-09-10 19:58:42 +02:00
|
|
|
static int wm8400_i2c_probe(struct i2c_client *i2c,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct wm8400 *wm8400;
|
|
|
|
int ret;
|
|
|
|
|
2011-12-03 22:43:04 +01:00
|
|
|
wm8400 = devm_kzalloc(&i2c->dev, sizeof(struct wm8400), GFP_KERNEL);
|
2008-09-10 19:58:42 +02:00
|
|
|
if (wm8400 == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2012-01-30 22:18:01 +01:00
|
|
|
wm8400->regmap = devm_regmap_init_i2c(i2c, &wm8400_regmap_config);
|
2011-08-09 09:34:29 +02:00
|
|
|
if (IS_ERR(wm8400->regmap)) {
|
|
|
|
ret = PTR_ERR(wm8400->regmap);
|
2011-12-03 22:43:04 +01:00
|
|
|
goto err;
|
2011-08-09 09:34:29 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 19:58:42 +02:00
|
|
|
wm8400->dev = &i2c->dev;
|
|
|
|
i2c_set_clientdata(i2c, wm8400);
|
|
|
|
|
|
|
|
ret = wm8400_init(wm8400, i2c->dev.platform_data);
|
|
|
|
if (ret != 0)
|
2012-01-30 22:18:01 +01:00
|
|
|
goto err;
|
2008-09-10 19:58:42 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wm8400_i2c_remove(struct i2c_client *i2c)
|
|
|
|
{
|
|
|
|
struct wm8400 *wm8400 = i2c_get_clientdata(i2c);
|
|
|
|
|
|
|
|
wm8400_release(wm8400);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id wm8400_i2c_id[] = {
|
|
|
|
{ "wm8400", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, wm8400_i2c_id);
|
|
|
|
|
|
|
|
static struct i2c_driver wm8400_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "WM8400",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = wm8400_i2c_probe,
|
|
|
|
.remove = wm8400_i2c_remove,
|
|
|
|
.id_table = wm8400_i2c_id,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int __init wm8400_module_init(void)
|
|
|
|
{
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
|
|
|
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
|
|
|
|
ret = i2c_add_driver(&wm8400_i2c_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register I2C driver: %d\n", ret);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-06-15 18:04:54 +02:00
|
|
|
subsys_initcall(wm8400_module_init);
|
2008-09-10 19:58:42 +02:00
|
|
|
|
|
|
|
static void __exit wm8400_module_exit(void)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
|
|
|
|
i2c_del_driver(&wm8400_i2c_driver);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
module_exit(wm8400_module_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
|