Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mfd / mp2629.c
blob16840ec5fd1cde407e1748fc88a1d474c786c925
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * MP2629 parent driver for ADC and battery charger
5 * Copyright 2020 Monolithic Power Systems, Inc
7 * Author: Saravanan Sekar <sravanhome@gmail.com>
8 */
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>
19 static const struct mfd_cell mp2629_cell[] = {
21 .name = "mp2629_adc",
22 .of_compatible = "mps,mp2629_adc",
25 .name = "mp2629_charger",
26 .of_compatible = "mps,mp2629_charger",
30 static const struct regmap_config mp2629_regmap_config = {
31 .reg_bits = 8,
32 .val_bits = 8,
33 .max_register = 0x17,
36 static int mp2629_probe(struct i2c_client *client)
38 struct mp2629_data *ddata;
39 int ret;
41 ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
42 if (!ddata)
43 return -ENOMEM;
45 ddata->dev = &client->dev;
46 i2c_set_clientdata(client, ddata);
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);
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);
59 return ret;
62 static const struct of_device_id mp2629_of_match[] = {
63 { .compatible = "mps,mp2629"},
64 { }
66 MODULE_DEVICE_TABLE(of, mp2629_of_match);
68 static struct i2c_driver mp2629_driver = {
69 .driver = {
70 .name = "mp2629",
71 .of_match_table = mp2629_of_match,
73 .probe_new = mp2629_probe,
75 module_i2c_driver(mp2629_driver);
77 MODULE_AUTHOR("Saravanan Sekar <sravanhome@gmail.com>");
78 MODULE_DESCRIPTION("MP2629 Battery charger parent driver");
79 MODULE_LICENSE("GPL");