Commit | Line | Data |
---|---|---|
b25c6b7d WY |
1 | /* |
2 | * MFD driver for Active-semi ACT8945a PMIC | |
3 | * | |
4 | * Copyright (C) 2015 Atmel Corporation. | |
5 | * | |
6 | * Author: Wenyou Yang <wenyou.yang@atmel.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2 of the License, or (at your | |
11 | * option) any later version. | |
12 | */ | |
13 | ||
14 | #include <linux/i2c.h> | |
15 | #include <linux/mfd/core.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/of_device.h> | |
18 | #include <linux/regmap.h> | |
19 | ||
20 | static const struct mfd_cell act8945a_devs[] = { | |
21 | { | |
22 | .name = "act8945a-regulator", | |
23 | }, | |
24 | { | |
25 | .name = "act8945a-charger", | |
26 | }, | |
27 | }; | |
28 | ||
29 | static const struct regmap_config act8945a_regmap_config = { | |
30 | .reg_bits = 8, | |
31 | .val_bits = 8, | |
32 | }; | |
33 | ||
34 | static int act8945a_i2c_probe(struct i2c_client *i2c, | |
35 | const struct i2c_device_id *id) | |
36 | { | |
37 | int ret; | |
38 | struct regmap *regmap; | |
39 | ||
40 | regmap = devm_regmap_init_i2c(i2c, &act8945a_regmap_config); | |
41 | if (IS_ERR(regmap)) { | |
42 | ret = PTR_ERR(regmap); | |
43 | dev_err(&i2c->dev, "regmap init failed: %d\n", ret); | |
44 | return ret; | |
45 | } | |
46 | ||
47 | i2c_set_clientdata(i2c, regmap); | |
48 | ||
f9932c6e LD |
49 | ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE, |
50 | act8945a_devs, ARRAY_SIZE(act8945a_devs), | |
51 | NULL, 0, NULL); | |
b25c6b7d WY |
52 | if (ret) { |
53 | dev_err(&i2c->dev, "Failed to add sub devices\n"); | |
54 | return ret; | |
55 | } | |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
b25c6b7d WY |
60 | static const struct i2c_device_id act8945a_i2c_id[] = { |
61 | { "act8945a", 0 }, | |
62 | {} | |
63 | }; | |
64 | MODULE_DEVICE_TABLE(i2c, act8945a_i2c_id); | |
65 | ||
66 | static const struct of_device_id act8945a_of_match[] = { | |
67 | { .compatible = "active-semi,act8945a", }, | |
68 | {}, | |
69 | }; | |
70 | MODULE_DEVICE_TABLE(of, act8945a_of_match); | |
71 | ||
72 | static struct i2c_driver act8945a_i2c_driver = { | |
73 | .driver = { | |
74 | .name = "act8945a", | |
75 | .of_match_table = of_match_ptr(act8945a_of_match), | |
76 | }, | |
77 | .probe = act8945a_i2c_probe, | |
b25c6b7d WY |
78 | .id_table = act8945a_i2c_id, |
79 | }; | |
80 | ||
81 | static int __init act8945a_i2c_init(void) | |
82 | { | |
83 | return i2c_add_driver(&act8945a_i2c_driver); | |
84 | } | |
85 | subsys_initcall(act8945a_i2c_init); | |
86 | ||
87 | static void __exit act8945a_i2c_exit(void) | |
88 | { | |
89 | i2c_del_driver(&act8945a_i2c_driver); | |
90 | } | |
91 | module_exit(act8945a_i2c_exit); | |
92 | ||
93 | MODULE_DESCRIPTION("ACT8945A PMIC multi-function driver"); | |
94 | MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>"); | |
95 | MODULE_LICENSE("GPL"); |