Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Chen-Yu Tsai | 02071f0 | 2016-02-12 10:02:44 +0800 | [diff] [blame] | 2 | /* |
| 3 | * RSB driver for the X-Powers' Power Management ICs |
| 4 | * |
| 5 | * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC |
| 6 | * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature |
| 7 | * as well as configurable GPIOs. |
| 8 | * |
| 9 | * This driver supports the RSB variants. |
| 10 | * |
| 11 | * Copyright (C) 2015 Chen-Yu Tsai |
| 12 | * |
| 13 | * Author: Chen-Yu Tsai <wens@csie.org> |
Chen-Yu Tsai | 02071f0 | 2016-02-12 10:02:44 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/acpi.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/mfd/axp20x.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/regmap.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/sunxi-rsb.h> |
| 24 | |
| 25 | static int axp20x_rsb_probe(struct sunxi_rsb_device *rdev) |
| 26 | { |
| 27 | struct axp20x_dev *axp20x; |
| 28 | int ret; |
| 29 | |
| 30 | axp20x = devm_kzalloc(&rdev->dev, sizeof(*axp20x), GFP_KERNEL); |
| 31 | if (!axp20x) |
| 32 | return -ENOMEM; |
| 33 | |
| 34 | axp20x->dev = &rdev->dev; |
| 35 | axp20x->irq = rdev->irq; |
| 36 | dev_set_drvdata(&rdev->dev, axp20x); |
| 37 | |
| 38 | ret = axp20x_match_device(axp20x); |
| 39 | if (ret) |
| 40 | return ret; |
| 41 | |
| 42 | axp20x->regmap = devm_regmap_init_sunxi_rsb(rdev, axp20x->regmap_cfg); |
| 43 | if (IS_ERR(axp20x->regmap)) { |
| 44 | ret = PTR_ERR(axp20x->regmap); |
| 45 | dev_err(&rdev->dev, "regmap init failed: %d\n", ret); |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | return axp20x_device_probe(axp20x); |
| 50 | } |
| 51 | |
Uwe Kleine-König | 3c15e00 | 2020-11-26 11:41:42 +0100 | [diff] [blame] | 52 | static void axp20x_rsb_remove(struct sunxi_rsb_device *rdev) |
Chen-Yu Tsai | 02071f0 | 2016-02-12 10:02:44 +0800 | [diff] [blame] | 53 | { |
| 54 | struct axp20x_dev *axp20x = sunxi_rsb_device_get_drvdata(rdev); |
| 55 | |
Uwe Kleine-König | 3c15e00 | 2020-11-26 11:41:42 +0100 | [diff] [blame] | 56 | axp20x_device_remove(axp20x); |
Chen-Yu Tsai | 02071f0 | 2016-02-12 10:02:44 +0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static const struct of_device_id axp20x_rsb_of_match[] = { |
| 60 | { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID }, |
Icenowy Zheng | 1578353 | 2017-04-17 19:57:40 +0800 | [diff] [blame] | 61 | { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID }, |
Chen-Yu Tsai | 8824ee8 | 2016-08-27 15:55:38 +0800 | [diff] [blame] | 62 | { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID }, |
Chen-Yu Tsai | 20147f0 | 2016-03-29 17:22:26 +0800 | [diff] [blame] | 63 | { .compatible = "x-powers,axp809", .data = (void *)AXP809_ID }, |
Chen-Yu Tsai | 7303733 | 2017-07-26 16:28:26 +0800 | [diff] [blame] | 64 | { .compatible = "x-powers,axp813", .data = (void *)AXP813_ID }, |
Chen-Yu Tsai | 02071f0 | 2016-02-12 10:02:44 +0800 | [diff] [blame] | 65 | { }, |
| 66 | }; |
| 67 | MODULE_DEVICE_TABLE(of, axp20x_rsb_of_match); |
| 68 | |
| 69 | static struct sunxi_rsb_driver axp20x_rsb_driver = { |
| 70 | .driver = { |
| 71 | .name = "axp20x-rsb", |
| 72 | .of_match_table = of_match_ptr(axp20x_rsb_of_match), |
| 73 | }, |
| 74 | .probe = axp20x_rsb_probe, |
| 75 | .remove = axp20x_rsb_remove, |
| 76 | }; |
| 77 | module_sunxi_rsb_driver(axp20x_rsb_driver); |
| 78 | |
| 79 | MODULE_DESCRIPTION("PMIC MFD sunXi RSB driver for AXP20X"); |
| 80 | MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>"); |
| 81 | MODULE_LICENSE("GPL v2"); |