2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-01-25 23:24:09 +08:00
|
|
|
/*
|
|
|
|
* Regulators driver for Maxim max8649
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2010 Marvell International Ltd.
|
|
|
|
* Haojian Zhuang <haojian.zhuang@marvell.com>
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regulator/driver.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-01-25 23:24:09 +08:00
|
|
|
#include <linux/regulator/max8649.h>
|
2011-10-24 21:26:26 +08:00
|
|
|
#include <linux/regmap.h>
|
2010-01-25 23:24:09 +08:00
|
|
|
|
|
|
|
#define MAX8649_DCDC_VMIN 750000 /* uV */
|
|
|
|
#define MAX8649_DCDC_VMAX 1380000 /* uV */
|
|
|
|
#define MAX8649_DCDC_STEP 10000 /* uV */
|
|
|
|
#define MAX8649_VOL_MASK 0x3f
|
|
|
|
|
|
|
|
/* Registers */
|
|
|
|
#define MAX8649_MODE0 0x00
|
|
|
|
#define MAX8649_MODE1 0x01
|
|
|
|
#define MAX8649_MODE2 0x02
|
|
|
|
#define MAX8649_MODE3 0x03
|
|
|
|
#define MAX8649_CONTROL 0x04
|
|
|
|
#define MAX8649_SYNC 0x05
|
|
|
|
#define MAX8649_RAMP 0x06
|
|
|
|
#define MAX8649_CHIP_ID1 0x08
|
|
|
|
#define MAX8649_CHIP_ID2 0x09
|
|
|
|
|
|
|
|
/* Bits */
|
|
|
|
#define MAX8649_EN_PD (1 << 7)
|
|
|
|
#define MAX8649_VID0_PD (1 << 6)
|
|
|
|
#define MAX8649_VID1_PD (1 << 5)
|
|
|
|
#define MAX8649_VID_MASK (3 << 5)
|
|
|
|
|
|
|
|
#define MAX8649_FORCE_PWM (1 << 7)
|
|
|
|
#define MAX8649_SYNC_EXTCLK (1 << 6)
|
|
|
|
|
|
|
|
#define MAX8649_EXT_MASK (3 << 6)
|
|
|
|
|
|
|
|
#define MAX8649_RAMP_MASK (7 << 5)
|
|
|
|
#define MAX8649_RAMP_DOWN (1 << 1)
|
|
|
|
|
|
|
|
struct max8649_regulator_info {
|
|
|
|
struct device *dev;
|
2011-10-24 21:26:26 +08:00
|
|
|
struct regmap *regmap;
|
2010-01-25 23:24:09 +08:00
|
|
|
|
|
|
|
unsigned mode:2; /* bit[1:0] = VID1, VID0 */
|
|
|
|
unsigned extclk_freq:2;
|
|
|
|
unsigned extclk:1;
|
|
|
|
unsigned ramp_timing:3;
|
|
|
|
unsigned ramp_down:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int max8649_enable_time(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
|
|
|
|
int voltage, rate, ret;
|
2011-10-24 21:26:26 +08:00
|
|
|
unsigned int val;
|
2010-01-25 23:24:09 +08:00
|
|
|
|
|
|
|
/* get voltage */
|
2012-05-15 00:13:10 +08:00
|
|
|
ret = regmap_read(info->regmap, rdev->desc->vsel_reg, &val);
|
2011-10-24 21:26:26 +08:00
|
|
|
if (ret != 0)
|
2010-01-25 23:24:09 +08:00
|
|
|
return ret;
|
2011-10-24 21:26:26 +08:00
|
|
|
val &= MAX8649_VOL_MASK;
|
2012-05-15 00:14:05 +08:00
|
|
|
voltage = regulator_list_voltage_linear(rdev, (unsigned char)val);
|
2010-01-25 23:24:09 +08:00
|
|
|
|
|
|
|
/* get rate */
|
2011-10-24 21:26:26 +08:00
|
|
|
ret = regmap_read(info->regmap, MAX8649_RAMP, &val);
|
|
|
|
if (ret != 0)
|
2010-01-25 23:24:09 +08:00
|
|
|
return ret;
|
2011-10-24 21:26:26 +08:00
|
|
|
ret = (val & MAX8649_RAMP_MASK) >> 5;
|
2010-01-25 23:24:09 +08:00
|
|
|
rate = (32 * 1000) >> ret; /* uV/uS */
|
|
|
|
|
2011-08-02 12:54:56 +08:00
|
|
|
return DIV_ROUND_UP(voltage, rate);
|
2010-01-25 23:24:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int max8649_set_mode(struct regulator_dev *rdev, unsigned int mode)
|
|
|
|
{
|
|
|
|
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case REGULATOR_MODE_FAST:
|
2012-05-15 00:13:10 +08:00
|
|
|
regmap_update_bits(info->regmap, rdev->desc->vsel_reg,
|
|
|
|
MAX8649_FORCE_PWM, MAX8649_FORCE_PWM);
|
2010-01-25 23:24:09 +08:00
|
|
|
break;
|
|
|
|
case REGULATOR_MODE_NORMAL:
|
2012-05-15 00:13:10 +08:00
|
|
|
regmap_update_bits(info->regmap, rdev->desc->vsel_reg,
|
2011-10-24 21:26:26 +08:00
|
|
|
MAX8649_FORCE_PWM, 0);
|
2010-01-25 23:24:09 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int max8649_get_mode(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
|
2011-10-24 21:26:26 +08:00
|
|
|
unsigned int val;
|
2010-01-25 23:24:09 +08:00
|
|
|
int ret;
|
|
|
|
|
2012-05-15 00:13:10 +08:00
|
|
|
ret = regmap_read(info->regmap, rdev->desc->vsel_reg, &val);
|
2011-10-24 21:26:26 +08:00
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
if (val & MAX8649_FORCE_PWM)
|
2010-01-25 23:24:09 +08:00
|
|
|
return REGULATOR_MODE_FAST;
|
|
|
|
return REGULATOR_MODE_NORMAL;
|
|
|
|
}
|
|
|
|
|
2015-01-05 17:05:47 +08:00
|
|
|
static const struct regulator_ops max8649_dcdc_ops = {
|
2012-05-15 00:15:11 +08:00
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
2012-05-15 00:13:10 +08:00
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
2012-05-15 00:14:05 +08:00
|
|
|
.list_voltage = regulator_list_voltage_linear,
|
2012-05-15 00:15:11 +08:00
|
|
|
.map_voltage = regulator_map_voltage_linear,
|
2013-03-05 14:17:57 +08:00
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
2010-01-25 23:24:09 +08:00
|
|
|
.enable_time = max8649_enable_time,
|
|
|
|
.set_mode = max8649_set_mode,
|
|
|
|
.get_mode = max8649_get_mode,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-05-15 00:13:10 +08:00
|
|
|
static struct regulator_desc dcdc_desc = {
|
2010-01-25 23:24:09 +08:00
|
|
|
.name = "max8649",
|
|
|
|
.ops = &max8649_dcdc_ops,
|
|
|
|
.type = REGULATOR_VOLTAGE,
|
|
|
|
.n_voltages = 1 << 6,
|
|
|
|
.owner = THIS_MODULE,
|
2012-05-15 00:13:10 +08:00
|
|
|
.vsel_mask = MAX8649_VOL_MASK,
|
2012-05-15 00:14:05 +08:00
|
|
|
.min_uV = MAX8649_DCDC_VMIN,
|
|
|
|
.uV_step = MAX8649_DCDC_STEP,
|
2013-03-05 14:17:57 +08:00
|
|
|
.enable_reg = MAX8649_CONTROL,
|
|
|
|
.enable_mask = MAX8649_EN_PD,
|
|
|
|
.enable_is_inverted = true,
|
2010-01-25 23:24:09 +08:00
|
|
|
};
|
|
|
|
|
2015-01-05 17:05:47 +08:00
|
|
|
static const struct regmap_config max8649_regmap_config = {
|
2011-10-24 21:26:26 +08:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
};
|
|
|
|
|
2012-11-20 02:22:22 +08:00
|
|
|
static int max8649_regulator_probe(struct i2c_client *client,
|
2010-01-25 23:24:09 +08:00
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2013-07-30 16:20:47 +08:00
|
|
|
struct max8649_platform_data *pdata = dev_get_platdata(&client->dev);
|
2010-01-25 23:24:09 +08:00
|
|
|
struct max8649_regulator_info *info = NULL;
|
2014-03-10 16:32:47 +08:00
|
|
|
struct regulator_dev *regulator;
|
2012-04-04 07:50:22 +08:00
|
|
|
struct regulator_config config = { };
|
2011-10-24 21:26:26 +08:00
|
|
|
unsigned int val;
|
2010-01-25 23:24:09 +08:00
|
|
|
unsigned char data;
|
|
|
|
int ret;
|
|
|
|
|
2012-04-07 23:28:28 +08:00
|
|
|
info = devm_kzalloc(&client->dev, sizeof(struct max8649_regulator_info),
|
|
|
|
GFP_KERNEL);
|
2014-06-02 14:29:57 +08:00
|
|
|
if (!info)
|
2010-01-25 23:24:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-04-07 23:28:28 +08:00
|
|
|
info->regmap = devm_regmap_init_i2c(client, &max8649_regmap_config);
|
2011-10-24 21:26:26 +08:00
|
|
|
if (IS_ERR(info->regmap)) {
|
|
|
|
ret = PTR_ERR(info->regmap);
|
|
|
|
dev_err(&client->dev, "Failed to allocate register map: %d\n", ret);
|
2012-04-07 23:28:28 +08:00
|
|
|
return ret;
|
2011-10-24 21:26:26 +08:00
|
|
|
}
|
|
|
|
|
2010-01-25 23:24:09 +08:00
|
|
|
info->dev = &client->dev;
|
|
|
|
i2c_set_clientdata(client, info);
|
|
|
|
|
|
|
|
info->mode = pdata->mode;
|
|
|
|
switch (info->mode) {
|
|
|
|
case 0:
|
2012-05-15 00:13:10 +08:00
|
|
|
dcdc_desc.vsel_reg = MAX8649_MODE0;
|
2010-01-25 23:24:09 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-05-15 00:13:10 +08:00
|
|
|
dcdc_desc.vsel_reg = MAX8649_MODE1;
|
2010-01-25 23:24:09 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-05-15 00:13:10 +08:00
|
|
|
dcdc_desc.vsel_reg = MAX8649_MODE2;
|
2010-01-25 23:24:09 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-05-15 00:13:10 +08:00
|
|
|
dcdc_desc.vsel_reg = MAX8649_MODE3;
|
2010-01-25 23:24:09 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-24 21:26:26 +08:00
|
|
|
ret = regmap_read(info->regmap, MAX8649_CHIP_ID1, &val);
|
|
|
|
if (ret != 0) {
|
2010-01-25 23:24:09 +08:00
|
|
|
dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n",
|
|
|
|
ret);
|
2012-04-07 23:28:28 +08:00
|
|
|
return ret;
|
2010-01-25 23:24:09 +08:00
|
|
|
}
|
2012-02-06 20:37:46 +08:00
|
|
|
dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", val);
|
2010-01-25 23:24:09 +08:00
|
|
|
|
|
|
|
/* enable VID0 & VID1 */
|
2011-10-24 21:26:26 +08:00
|
|
|
regmap_update_bits(info->regmap, MAX8649_CONTROL, MAX8649_VID_MASK, 0);
|
2010-01-25 23:24:09 +08:00
|
|
|
|
|
|
|
/* enable/disable external clock synchronization */
|
|
|
|
info->extclk = pdata->extclk;
|
|
|
|
data = (info->extclk) ? MAX8649_SYNC_EXTCLK : 0;
|
2012-05-15 00:13:10 +08:00
|
|
|
regmap_update_bits(info->regmap, dcdc_desc.vsel_reg,
|
|
|
|
MAX8649_SYNC_EXTCLK, data);
|
2010-01-25 23:24:09 +08:00
|
|
|
if (info->extclk) {
|
|
|
|
/* set external clock frequency */
|
|
|
|
info->extclk_freq = pdata->extclk_freq;
|
2011-10-24 21:26:26 +08:00
|
|
|
regmap_update_bits(info->regmap, MAX8649_SYNC, MAX8649_EXT_MASK,
|
|
|
|
info->extclk_freq << 6);
|
2010-01-25 23:24:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->ramp_timing) {
|
|
|
|
info->ramp_timing = pdata->ramp_timing;
|
2011-10-24 21:26:26 +08:00
|
|
|
regmap_update_bits(info->regmap, MAX8649_RAMP, MAX8649_RAMP_MASK,
|
|
|
|
info->ramp_timing << 5);
|
2010-01-25 23:24:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
info->ramp_down = pdata->ramp_down;
|
|
|
|
if (info->ramp_down) {
|
2011-10-24 21:26:26 +08:00
|
|
|
regmap_update_bits(info->regmap, MAX8649_RAMP, MAX8649_RAMP_DOWN,
|
|
|
|
MAX8649_RAMP_DOWN);
|
2010-01-25 23:24:09 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 07:50:22 +08:00
|
|
|
config.dev = &client->dev;
|
|
|
|
config.init_data = pdata->regulator;
|
|
|
|
config.driver_data = info;
|
2012-06-05 18:10:10 +08:00
|
|
|
config.regmap = info->regmap;
|
2012-04-04 07:50:22 +08:00
|
|
|
|
2014-03-10 16:32:47 +08:00
|
|
|
regulator = devm_regulator_register(&client->dev, &dcdc_desc,
|
2013-09-04 13:37:57 +08:00
|
|
|
&config);
|
2014-03-10 16:32:47 +08:00
|
|
|
if (IS_ERR(regulator)) {
|
2010-01-25 23:24:09 +08:00
|
|
|
dev_err(info->dev, "failed to register regulator %s\n",
|
|
|
|
dcdc_desc.name);
|
2014-03-10 16:32:47 +08:00
|
|
|
return PTR_ERR(regulator);
|
2010-01-25 23:24:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id max8649_id[] = {
|
|
|
|
{ "max8649", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, max8649_id);
|
|
|
|
|
|
|
|
static struct i2c_driver max8649_driver = {
|
|
|
|
.probe = max8649_regulator_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "max8649",
|
|
|
|
},
|
|
|
|
.id_table = max8649_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init max8649_init(void)
|
|
|
|
{
|
|
|
|
return i2c_add_driver(&max8649_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(max8649_init);
|
|
|
|
|
|
|
|
static void __exit max8649_exit(void)
|
|
|
|
{
|
|
|
|
i2c_del_driver(&max8649_driver);
|
|
|
|
}
|
|
|
|
module_exit(max8649_exit);
|
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_DESCRIPTION("MAXIM 8649 voltage regulator driver");
|
|
|
|
MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|