2019-05-27 13:55:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-01-09 07:49:01 +07:00
|
|
|
/* NXP PCF50633 Power Management Unit (PMU) driver
|
|
|
|
*
|
|
|
|
* (C) 2006-2008 by Openmoko, Inc.
|
|
|
|
* Author: Harald Welte <laforge@openmoko.org>
|
|
|
|
* Balaji Rao <balajirrao@openmoko.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/i2c.h>
|
2011-01-21 04:52:42 +07:00
|
|
|
#include <linux/pm.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2011-08-08 15:04:40 +07:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/err.h>
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
#include <linux/mfd/pcf50633/core.h>
|
|
|
|
|
2011-03-31 08:57:33 +07:00
|
|
|
/* Read a block of up to 32 regs */
|
2009-01-09 07:49:01 +07:00
|
|
|
int pcf50633_read_block(struct pcf50633 *pcf, u8 reg,
|
|
|
|
int nr_regs, u8 *data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-08-08 15:04:40 +07:00
|
|
|
ret = regmap_raw_read(pcf->regmap, reg, data, nr_regs);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2009-01-09 07:49:01 +07:00
|
|
|
|
2011-08-08 15:04:40 +07:00
|
|
|
return nr_regs;
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcf50633_read_block);
|
|
|
|
|
2011-03-31 08:57:33 +07:00
|
|
|
/* Write a block of up to 32 regs */
|
2009-01-09 07:49:01 +07:00
|
|
|
int pcf50633_write_block(struct pcf50633 *pcf , u8 reg,
|
|
|
|
int nr_regs, u8 *data)
|
|
|
|
{
|
2012-02-14 10:30:31 +07:00
|
|
|
return regmap_raw_write(pcf->regmap, reg, data, nr_regs);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcf50633_write_block);
|
|
|
|
|
|
|
|
u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg)
|
|
|
|
{
|
2011-08-08 15:04:40 +07:00
|
|
|
unsigned int val;
|
|
|
|
int ret;
|
2009-01-09 07:49:01 +07:00
|
|
|
|
2011-08-08 15:04:40 +07:00
|
|
|
ret = regmap_read(pcf->regmap, reg, &val);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcf50633_reg_read);
|
|
|
|
|
|
|
|
int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val)
|
|
|
|
{
|
2011-08-08 15:04:40 +07:00
|
|
|
return regmap_write(pcf->regmap, reg, val);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcf50633_reg_write);
|
|
|
|
|
|
|
|
int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val)
|
|
|
|
{
|
2011-08-08 15:04:40 +07:00
|
|
|
return regmap_update_bits(pcf->regmap, reg, mask, val);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcf50633_reg_set_bit_mask);
|
|
|
|
|
|
|
|
int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val)
|
|
|
|
{
|
2011-08-08 15:04:40 +07:00
|
|
|
return regmap_update_bits(pcf->regmap, reg, val, 0);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcf50633_reg_clear_bits);
|
|
|
|
|
|
|
|
/* sysfs attributes */
|
|
|
|
static ssize_t show_dump_regs(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct pcf50633 *pcf = dev_get_drvdata(dev);
|
|
|
|
u8 dump[16];
|
|
|
|
int n, n1, idx = 0;
|
|
|
|
char *buf1 = buf;
|
|
|
|
static u8 address_no_read[] = { /* must be ascending */
|
|
|
|
PCF50633_REG_INT1,
|
|
|
|
PCF50633_REG_INT2,
|
|
|
|
PCF50633_REG_INT3,
|
|
|
|
PCF50633_REG_INT4,
|
|
|
|
PCF50633_REG_INT5,
|
|
|
|
0 /* terminator */
|
|
|
|
};
|
|
|
|
|
|
|
|
for (n = 0; n < 256; n += sizeof(dump)) {
|
|
|
|
for (n1 = 0; n1 < sizeof(dump); n1++)
|
|
|
|
if (n == address_no_read[idx]) {
|
|
|
|
idx++;
|
|
|
|
dump[n1] = 0x00;
|
|
|
|
} else
|
|
|
|
dump[n1] = pcf50633_reg_read(pcf, n + n1);
|
|
|
|
|
2014-09-04 16:32:12 +07:00
|
|
|
buf1 += sprintf(buf1, "%*ph\n", (int)sizeof(dump), dump);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return buf1 - buf;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(dump_regs, 0400, show_dump_regs, NULL);
|
|
|
|
|
|
|
|
static ssize_t show_resume_reason(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct pcf50633 *pcf = dev_get_drvdata(dev);
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = sprintf(buf, "%02x%02x%02x%02x%02x\n",
|
|
|
|
pcf->resume_reason[0],
|
|
|
|
pcf->resume_reason[1],
|
|
|
|
pcf->resume_reason[2],
|
|
|
|
pcf->resume_reason[3],
|
|
|
|
pcf->resume_reason[4]);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(resume_reason, 0400, show_resume_reason, NULL);
|
|
|
|
|
|
|
|
static struct attribute *pcf_sysfs_entries[] = {
|
|
|
|
&dev_attr_dump_regs.attr,
|
|
|
|
&dev_attr_resume_reason.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group pcf_attr_group = {
|
|
|
|
.name = NULL, /* put in device directory */
|
|
|
|
.attrs = pcf_sysfs_entries,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
pcf50633_client_dev_register(struct pcf50633 *pcf, const char *name,
|
|
|
|
struct platform_device **pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*pdev = platform_device_alloc(name, -1);
|
|
|
|
if (!*pdev) {
|
2017-10-29 13:01:23 +07:00
|
|
|
dev_err(pcf->dev, "Failed to allocate %s\n", name);
|
2009-01-09 07:49:01 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*pdev)->dev.parent = pcf->dev;
|
|
|
|
|
|
|
|
ret = platform_device_add(*pdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(pcf->dev, "Failed to register %s: %d\n", name, ret);
|
|
|
|
platform_device_put(*pdev);
|
|
|
|
*pdev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-21 04:52:42 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int pcf50633_suspend(struct device *dev)
|
2009-01-09 07:49:01 +07:00
|
|
|
{
|
2011-01-21 04:52:42 +07:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct pcf50633 *pcf = i2c_get_clientdata(client);
|
2009-01-09 07:49:01 +07:00
|
|
|
|
2010-05-12 07:10:56 +07:00
|
|
|
return pcf50633_irq_suspend(pcf);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
|
2011-01-21 04:52:42 +07:00
|
|
|
static int pcf50633_resume(struct device *dev)
|
2009-01-09 07:49:01 +07:00
|
|
|
{
|
2011-01-21 04:52:42 +07:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct pcf50633 *pcf = i2c_get_clientdata(client);
|
2009-01-09 07:49:01 +07:00
|
|
|
|
2010-05-12 07:10:56 +07:00
|
|
|
return pcf50633_irq_resume(pcf);
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-21 04:52:42 +07:00
|
|
|
static SIMPLE_DEV_PM_OPS(pcf50633_pm, pcf50633_suspend, pcf50633_resume);
|
|
|
|
|
2015-01-05 16:01:27 +07:00
|
|
|
static const struct regmap_config pcf50633_regmap_config = {
|
2011-08-08 15:04:40 +07:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
};
|
|
|
|
|
2012-11-20 01:23:04 +07:00
|
|
|
static int pcf50633_probe(struct i2c_client *client,
|
2009-01-09 07:49:01 +07:00
|
|
|
const struct i2c_device_id *ids)
|
|
|
|
{
|
|
|
|
struct pcf50633 *pcf;
|
2014-08-18 21:54:06 +07:00
|
|
|
struct platform_device *pdev;
|
2013-07-30 15:10:05 +07:00
|
|
|
struct pcf50633_platform_data *pdata = dev_get_platdata(&client->dev);
|
2014-08-18 21:54:06 +07:00
|
|
|
int i, j, ret;
|
2009-01-09 07:49:01 +07:00
|
|
|
int version, variant;
|
|
|
|
|
2009-10-08 05:24:54 +07:00
|
|
|
if (!client->irq) {
|
|
|
|
dev_err(&client->dev, "Missing IRQ\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2012-05-11 08:31:29 +07:00
|
|
|
pcf = devm_kzalloc(&client->dev, sizeof(*pcf), GFP_KERNEL);
|
2009-01-09 07:49:01 +07:00
|
|
|
if (!pcf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-12-25 09:52:49 +07:00
|
|
|
i2c_set_clientdata(client, pcf);
|
|
|
|
pcf->dev = &client->dev;
|
2009-01-09 07:49:01 +07:00
|
|
|
pcf->pdata = pdata;
|
|
|
|
|
|
|
|
mutex_init(&pcf->lock);
|
|
|
|
|
2012-05-11 08:31:29 +07:00
|
|
|
pcf->regmap = devm_regmap_init_i2c(client, &pcf50633_regmap_config);
|
2011-08-08 15:04:40 +07:00
|
|
|
if (IS_ERR(pcf->regmap)) {
|
|
|
|
ret = PTR_ERR(pcf->regmap);
|
2012-05-11 08:31:29 +07:00
|
|
|
dev_err(pcf->dev, "Failed to allocate register map: %d\n", ret);
|
|
|
|
return ret;
|
2011-08-08 15:04:40 +07:00
|
|
|
}
|
|
|
|
|
2009-01-09 07:49:01 +07:00
|
|
|
version = pcf50633_reg_read(pcf, 0);
|
|
|
|
variant = pcf50633_reg_read(pcf, 1);
|
|
|
|
if (version < 0 || variant < 0) {
|
|
|
|
dev_err(pcf->dev, "Unable to probe pcf50633\n");
|
|
|
|
ret = -ENODEV;
|
2012-05-11 08:31:29 +07:00
|
|
|
return ret;
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(pcf->dev, "Probed device version %d variant %d\n",
|
|
|
|
version, variant);
|
|
|
|
|
2010-05-12 07:10:56 +07:00
|
|
|
pcf50633_irq_init(pcf, client->irq);
|
2009-10-08 05:24:54 +07:00
|
|
|
|
2009-01-09 07:49:01 +07:00
|
|
|
/* Create sub devices */
|
2012-05-11 08:31:29 +07:00
|
|
|
pcf50633_client_dev_register(pcf, "pcf50633-input", &pcf->input_pdev);
|
|
|
|
pcf50633_client_dev_register(pcf, "pcf50633-rtc", &pcf->rtc_pdev);
|
|
|
|
pcf50633_client_dev_register(pcf, "pcf50633-mbc", &pcf->mbc_pdev);
|
|
|
|
pcf50633_client_dev_register(pcf, "pcf50633-adc", &pcf->adc_pdev);
|
|
|
|
pcf50633_client_dev_register(pcf, "pcf50633-backlight", &pcf->bl_pdev);
|
2010-05-12 07:44:33 +07:00
|
|
|
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
for (i = 0; i < PCF50633_NUM_REGULATORS; i++) {
|
2013-11-30 11:21:03 +07:00
|
|
|
pdev = platform_device_alloc("pcf50633-regulator", i);
|
2018-03-15 04:47:55 +07:00
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err2;
|
|
|
|
}
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
pdev->dev.parent = pcf->dev;
|
2014-07-01 18:57:36 +07:00
|
|
|
ret = platform_device_add_data(pdev, &pdata->reg_init_data[i],
|
|
|
|
sizeof(pdata->reg_init_data[i]));
|
2014-08-18 21:54:06 +07:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = platform_device_add(pdev);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2009-01-09 07:49:01 +07:00
|
|
|
|
2014-08-18 21:54:06 +07:00
|
|
|
pcf->regulator_pdev[i] = pdev;
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group);
|
|
|
|
if (ret)
|
2014-08-18 21:54:06 +07:00
|
|
|
dev_warn(pcf->dev, "error creating sysfs entries\n");
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
if (pdata->probe_done)
|
|
|
|
pdata->probe_done(pcf);
|
|
|
|
|
|
|
|
return 0;
|
2014-08-18 21:54:06 +07:00
|
|
|
|
|
|
|
err:
|
|
|
|
platform_device_put(pdev);
|
2018-03-15 04:47:55 +07:00
|
|
|
err2:
|
2014-08-18 21:54:06 +07:00
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
platform_device_put(pcf->regulator_pdev[j]);
|
|
|
|
|
|
|
|
return ret;
|
2009-01-09 07:49:01 +07:00
|
|
|
}
|
|
|
|
|
2012-11-20 01:26:01 +07:00
|
|
|
static int pcf50633_remove(struct i2c_client *client)
|
2009-01-09 07:49:01 +07:00
|
|
|
{
|
|
|
|
struct pcf50633 *pcf = i2c_get_clientdata(client);
|
|
|
|
int i;
|
|
|
|
|
2010-10-20 15:56:59 +07:00
|
|
|
sysfs_remove_group(&client->dev.kobj, &pcf_attr_group);
|
2010-05-12 07:10:56 +07:00
|
|
|
pcf50633_irq_free(pcf);
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
platform_device_unregister(pcf->input_pdev);
|
|
|
|
platform_device_unregister(pcf->rtc_pdev);
|
|
|
|
platform_device_unregister(pcf->mbc_pdev);
|
|
|
|
platform_device_unregister(pcf->adc_pdev);
|
2010-10-20 15:56:59 +07:00
|
|
|
platform_device_unregister(pcf->bl_pdev);
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
for (i = 0; i < PCF50633_NUM_REGULATORS; i++)
|
|
|
|
platform_device_unregister(pcf->regulator_pdev[i]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-23 19:54:17 +07:00
|
|
|
static const struct i2c_device_id pcf50633_id_table[] = {
|
2009-01-09 07:49:01 +07:00
|
|
|
{"pcf50633", 0x73},
|
2009-02-17 15:07:02 +07:00
|
|
|
{/* end of list */}
|
2009-01-09 07:49:01 +07:00
|
|
|
};
|
2011-02-28 13:33:12 +07:00
|
|
|
MODULE_DEVICE_TABLE(i2c, pcf50633_id_table);
|
2009-01-09 07:49:01 +07:00
|
|
|
|
|
|
|
static struct i2c_driver pcf50633_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "pcf50633",
|
2011-01-21 04:52:42 +07:00
|
|
|
.pm = &pcf50633_pm,
|
2009-01-09 07:49:01 +07:00
|
|
|
},
|
|
|
|
.id_table = pcf50633_id_table,
|
|
|
|
.probe = pcf50633_probe,
|
2012-11-20 01:20:24 +07:00
|
|
|
.remove = pcf50633_remove,
|
2009-01-09 07:49:01 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pcf50633_init(void)
|
|
|
|
{
|
|
|
|
return i2c_add_driver(&pcf50633_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit pcf50633_exit(void)
|
|
|
|
{
|
|
|
|
i2c_del_driver(&pcf50633_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("I2C chip driver for NXP PCF50633 PMU");
|
|
|
|
MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-06-15 23:04:54 +07:00
|
|
|
subsys_initcall(pcf50633_init);
|
2009-01-09 07:49:01 +07:00
|
|
|
module_exit(pcf50633_exit);
|