blob: fd5c7267b136c4b127286687154373a1eea3213e [file] [log] [blame]
Chen-Yu Tsai02071f02016-02-12 10:02:44 +08001/*
2 * RSB driver for the X-Powers' Power Management ICs
3 *
4 * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
5 * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
6 * as well as configurable GPIOs.
7 *
8 * This driver supports the RSB variants.
9 *
10 * Copyright (C) 2015 Chen-Yu Tsai
11 *
12 * Author: Chen-Yu Tsai <wens@csie.org>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/acpi.h>
20#include <linux/err.h>
21#include <linux/mfd/axp20x.h>
22#include <linux/module.h>
23#include <linux/of.h>
24#include <linux/regmap.h>
25#include <linux/slab.h>
26#include <linux/sunxi-rsb.h>
27
28static int axp20x_rsb_probe(struct sunxi_rsb_device *rdev)
29{
30 struct axp20x_dev *axp20x;
31 int ret;
32
33 axp20x = devm_kzalloc(&rdev->dev, sizeof(*axp20x), GFP_KERNEL);
34 if (!axp20x)
35 return -ENOMEM;
36
37 axp20x->dev = &rdev->dev;
38 axp20x->irq = rdev->irq;
39 dev_set_drvdata(&rdev->dev, axp20x);
40
41 ret = axp20x_match_device(axp20x);
42 if (ret)
43 return ret;
44
45 axp20x->regmap = devm_regmap_init_sunxi_rsb(rdev, axp20x->regmap_cfg);
46 if (IS_ERR(axp20x->regmap)) {
47 ret = PTR_ERR(axp20x->regmap);
48 dev_err(&rdev->dev, "regmap init failed: %d\n", ret);
49 return ret;
50 }
51
52 return axp20x_device_probe(axp20x);
53}
54
55static int axp20x_rsb_remove(struct sunxi_rsb_device *rdev)
56{
57 struct axp20x_dev *axp20x = sunxi_rsb_device_get_drvdata(rdev);
58
59 return axp20x_device_remove(axp20x);
60}
61
62static const struct of_device_id axp20x_rsb_of_match[] = {
63 { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
Icenowy Zheng15783532017-04-17 19:57:40 +080064 { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +080065 { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
Chen-Yu Tsai20147f02016-03-29 17:22:26 +080066 { .compatible = "x-powers,axp809", .data = (void *)AXP809_ID },
Chen-Yu Tsai02071f02016-02-12 10:02:44 +080067 { },
68};
69MODULE_DEVICE_TABLE(of, axp20x_rsb_of_match);
70
71static struct sunxi_rsb_driver axp20x_rsb_driver = {
72 .driver = {
73 .name = "axp20x-rsb",
74 .of_match_table = of_match_ptr(axp20x_rsb_of_match),
75 },
76 .probe = axp20x_rsb_probe,
77 .remove = axp20x_rsb_remove,
78};
79module_sunxi_rsb_driver(axp20x_rsb_driver);
80
81MODULE_DESCRIPTION("PMIC MFD sunXi RSB driver for AXP20X");
82MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
83MODULE_LICENSE("GPL v2");