xref: /openbmc/linux/drivers/mfd/mp2629.c (revision c4c3c32d)
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		= 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");
80