xref: /openbmc/linux/drivers/mfd/atc260x-i2c.c (revision 39f555fb)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * I2C bus interface for ATC260x PMICs
4  *
5  * Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
6  * Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
7  */
8 
9 #include <linux/i2c.h>
10 #include <linux/mfd/atc260x/core.h>
11 #include <linux/module.h>
12 #include <linux/of.h>
13 #include <linux/regmap.h>
14 
15 static int atc260x_i2c_probe(struct i2c_client *client)
16 {
17 	struct atc260x *atc260x;
18 	struct regmap_config regmap_cfg;
19 	int ret;
20 
21 	atc260x = devm_kzalloc(&client->dev, sizeof(*atc260x), GFP_KERNEL);
22 	if (!atc260x)
23 		return -ENOMEM;
24 
25 	atc260x->dev = &client->dev;
26 	atc260x->irq = client->irq;
27 
28 	ret = atc260x_match_device(atc260x, &regmap_cfg);
29 	if (ret)
30 		return ret;
31 
32 	i2c_set_clientdata(client, atc260x);
33 
34 	atc260x->regmap = devm_regmap_init_i2c(client, &regmap_cfg);
35 	if (IS_ERR(atc260x->regmap)) {
36 		ret = PTR_ERR(atc260x->regmap);
37 		dev_err(&client->dev, "failed to init regmap: %d\n", ret);
38 		return ret;
39 	}
40 
41 	return atc260x_device_probe(atc260x);
42 }
43 
44 static const struct of_device_id atc260x_i2c_of_match[] = {
45 	{ .compatible = "actions,atc2603c", .data = (void *)ATC2603C },
46 	{ .compatible = "actions,atc2609a", .data = (void *)ATC2609A },
47 	{ }
48 };
49 MODULE_DEVICE_TABLE(of, atc260x_i2c_of_match);
50 
51 static struct i2c_driver atc260x_i2c_driver = {
52 	.driver = {
53 		.name = "atc260x",
54 		.of_match_table	= atc260x_i2c_of_match,
55 	},
56 	.probe = atc260x_i2c_probe,
57 };
58 module_i2c_driver(atc260x_i2c_driver);
59 
60 MODULE_DESCRIPTION("ATC260x PMICs I2C bus interface");
61 MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
62 MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
63 MODULE_LICENSE("GPL");
64