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