Skip to content

Commit 0608164

Browse files
ssekar15Lee Jones
authored andcommitted
mfd: mp2629: Add support for mps battery charger
mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery. Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 25c8c45 commit 0608164

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

‎drivers/mfd/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ config MFD_MC13XXX_I2C
434434
help
435435
Select this if your MC13xxx is connected via an I2C bus.
436436

437+
config MFD_MP2629
438+
tristate "Monolithic Power Systems MP2629 ADC and Battery charger"
439+
depends on I2C
440+
select REGMAP_I2C
441+
help
442+
Select this option to enable support for Monolithic Power Systems
443+
battery charger. This provides ADC, thermal and battery charger power
444+
management functions.
445+
437446
config MFD_MXS_LRADC
438447
tristate "Freescale i.MX23/i.MX28 LRADC"
439448
depends on ARCH_MXS || COMPILE_TEST

‎drivers/mfd/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ obj-$(CONFIG_MFD_MAX8925) += max8925.o
170170
obj-$(CONFIG_MFD_MAX8997) += max8997.o max8997-irq.o
171171
obj-$(CONFIG_MFD_MAX8998) += max8998.o max8998-irq.o
172172

173+
obj-$(CONFIG_MFD_MP2629) += mp2629.o
174+
173175
pcf50633-objs := pcf50633-core.o pcf50633-irq.o
174176
obj-$(CONFIG_MFD_PCF50633) += pcf50633.o
175177
obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o

‎drivers/mfd/mp2629.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* MP2629 parent driver for ADC and battery charger
4+
*
5+
* Copyright 2020 Monolithic Power Systems, Inc
6+
*
7+
* Author: Saravanan Sekar <sravanhome@gmail.com>
8+
*/
9+
10+
#include <linux/i2c.h>
11+
#include <linux/kernel.h>
12+
#include <linux/mfd/core.h>
13+
#include <linux/mfd/mp2629.h>
14+
#include <linux/module.h>
15+
#include <linux/platform_device.h>
16+
#include <linux/regmap.h>
17+
#include <linux/slab.h>
18+
19+
static const struct mfd_cell mp2629_cell[] = {
20+
{
21+
.name = "mp2629_adc",
22+
.of_compatible = "mps,mp2629_adc",
23+
},
24+
{
25+
.name = "mp2629_charger",
26+
.of_compatible = "mps,mp2629_charger",
27+
}
28+
};
29+
30+
static const struct regmap_config mp2629_regmap_config = {
31+
.reg_bits = 8,
32+
.val_bits = 8,
33+
.max_register = 0x17,
34+
};
35+
36+
static int mp2629_probe(struct i2c_client *client)
37+
{
38+
struct mp2629_data *ddata;
39+
int ret;
40+
41+
ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
42+
if (!ddata)
43+
return -ENOMEM;
44+
45+
ddata->dev = &client->dev;
46+
i2c_set_clientdata(client, ddata);
47+
48+
ddata->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config);
49+
if (IS_ERR(ddata->regmap)) {
50+
dev_err(ddata->dev, "Failed to allocate regmap\n");
51+
return PTR_ERR(ddata->regmap);
52+
}
53+
54+
ret = devm_mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, mp2629_cell,
55+
ARRAY_SIZE(mp2629_cell), NULL, 0, NULL);
56+
if (ret)
57+
dev_err(ddata->dev, "Failed to register sub-devices %d\n", ret);
58+
59+
return ret;
60+
}
61+
62+
static const struct of_device_id mp2629_of_match[] = {
63+
{ .compatible = "mps,mp2629"},
64+
{ }
65+
};
66+
MODULE_DEVICE_TABLE(of, mp2629_of_match);
67+
68+
static struct i2c_driver mp2629_driver = {
69+
.driver = {
70+
.name = "mp2629",
71+
.of_match_table = mp2629_of_match,
72+
},
73+
.probe_new = mp2629_probe,
74+
};
75+
module_i2c_driver(mp2629_driver);
76+
77+
MODULE_AUTHOR("Saravanan Sekar <sravanhome@gmail.com>");
78+
MODULE_DESCRIPTION("MP2629 Battery charger parent driver");
79+
MODULE_LICENSE("GPL");

‎include/linux/mfd/mp2629.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* Copyright 2020 Monolithic Power Systems, Inc
4+
*/
5+
6+
#ifndef __MP2629_H__
7+
#define __MP2629_H__
8+
9+
#include <linux/device.h>
10+
#include <linux/regmap.h>
11+
12+
struct mp2629_data {
13+
struct device *dev;
14+
struct regmap *regmap;
15+
};
16+
17+
#endif

0 commit comments

Comments
 (0)