0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/i2c.h>
0011 #include <linux/mfd/core.h>
0012 #include <linux/module.h>
0013 #include <linux/of_device.h>
0014 #include <linux/regmap.h>
0015
0016 static const struct mfd_cell act8945a_devs[] = {
0017 {
0018 .name = "act8945a-regulator",
0019 },
0020 {
0021 .name = "act8945a-charger",
0022 .of_compatible = "active-semi,act8945a-charger",
0023 },
0024 };
0025
0026 static const struct regmap_config act8945a_regmap_config = {
0027 .reg_bits = 8,
0028 .val_bits = 8,
0029 };
0030
0031 static int act8945a_i2c_probe(struct i2c_client *i2c,
0032 const struct i2c_device_id *id)
0033 {
0034 int ret;
0035 struct regmap *regmap;
0036
0037 regmap = devm_regmap_init_i2c(i2c, &act8945a_regmap_config);
0038 if (IS_ERR(regmap)) {
0039 ret = PTR_ERR(regmap);
0040 dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
0041 return ret;
0042 }
0043
0044 i2c_set_clientdata(i2c, regmap);
0045
0046 ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE,
0047 act8945a_devs, ARRAY_SIZE(act8945a_devs),
0048 NULL, 0, NULL);
0049 if (ret) {
0050 dev_err(&i2c->dev, "Failed to add sub devices\n");
0051 return ret;
0052 }
0053
0054 return 0;
0055 }
0056
0057 static const struct i2c_device_id act8945a_i2c_id[] = {
0058 { "act8945a", 0 },
0059 {}
0060 };
0061 MODULE_DEVICE_TABLE(i2c, act8945a_i2c_id);
0062
0063 static const struct of_device_id act8945a_of_match[] = {
0064 { .compatible = "active-semi,act8945a", },
0065 {},
0066 };
0067 MODULE_DEVICE_TABLE(of, act8945a_of_match);
0068
0069 static struct i2c_driver act8945a_i2c_driver = {
0070 .driver = {
0071 .name = "act8945a",
0072 .of_match_table = of_match_ptr(act8945a_of_match),
0073 },
0074 .probe = act8945a_i2c_probe,
0075 .id_table = act8945a_i2c_id,
0076 };
0077
0078 static int __init act8945a_i2c_init(void)
0079 {
0080 return i2c_add_driver(&act8945a_i2c_driver);
0081 }
0082 subsys_initcall(act8945a_i2c_init);
0083
0084 static void __exit act8945a_i2c_exit(void)
0085 {
0086 i2c_del_driver(&act8945a_i2c_driver);
0087 }
0088 module_exit(act8945a_i2c_exit);
0089
0090 MODULE_DESCRIPTION("ACT8945A PMIC multi-function driver");
0091 MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>");
0092 MODULE_LICENSE("GPL");