blob: 00ab48018d8d2e4dcf934ded988f89c960c92e7d [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +08002/*
3 * I2C 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 I2C variants.
10 *
11 * Copyright (C) 2014 Carlo Caione
12 *
13 * Author: Carlo Caione <carlo@caione.org>
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080014 */
15
16#include <linux/acpi.h>
17#include <linux/err.h>
18#include <linux/i2c.h>
19#include <linux/module.h>
20#include <linux/mfd/axp20x.h>
21#include <linux/of.h>
22#include <linux/regmap.h>
23#include <linux/slab.h>
24
25static int axp20x_i2c_probe(struct i2c_client *i2c,
26 const struct i2c_device_id *id)
27{
28 struct axp20x_dev *axp20x;
29 int ret;
30
31 axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
32 if (!axp20x)
33 return -ENOMEM;
34
35 axp20x->dev = &i2c->dev;
36 axp20x->irq = i2c->irq;
37 dev_set_drvdata(axp20x->dev, axp20x);
38
39 ret = axp20x_match_device(axp20x);
40 if (ret)
41 return ret;
42
43 axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
44 if (IS_ERR(axp20x->regmap)) {
45 ret = PTR_ERR(axp20x->regmap);
46 dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
47 return ret;
48 }
49
50 return axp20x_device_probe(axp20x);
51}
52
53static int axp20x_i2c_remove(struct i2c_client *i2c)
54{
55 struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);
56
Uwe Kleine-König3c15e002020-11-26 11:41:42 +010057 axp20x_device_remove(axp20x);
58
59 return 0;
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080060}
61
Krzysztof Kozlowski06b324f2020-11-20 17:21:32 +010062#ifdef CONFIG_OF
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080063static const struct of_device_id axp20x_i2c_of_match[] = {
64 { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID },
65 { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID },
66 { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
67 { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
Maxime Ripard4f799e42019-03-18 13:55:48 +010068 { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
Frank Lee85c30782020-07-08 15:19:36 +080069 { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
Chen-Yu Tsai99e19b72018-07-13 00:04:50 +080070 { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080071 { },
72};
73MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match);
Krzysztof Kozlowski06b324f2020-11-20 17:21:32 +010074#endif
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080075
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080076static const struct i2c_device_id axp20x_i2c_id[] = {
Hans de Goede41751b02016-10-05 17:51:12 +020077 { "axp152", 0 },
78 { "axp202", 0 },
79 { "axp209", 0 },
80 { "axp221", 0 },
Maxime Ripard4f799e42019-03-18 13:55:48 +010081 { "axp223", 0 },
Frank Lee85c30782020-07-08 15:19:36 +080082 { "axp803", 0 },
Chen-Yu Tsai99e19b72018-07-13 00:04:50 +080083 { "axp806", 0 },
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080084 { },
85};
86MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
87
Lee Jones21b29982020-06-25 10:03:55 +010088#ifdef CONFIG_ACPI
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080089static const struct acpi_device_id axp20x_i2c_acpi_match[] = {
90 {
91 .id = "INT33F4",
92 .driver_data = AXP288_ID,
93 },
94 { },
95};
96MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match);
Lee Jones21b29982020-06-25 10:03:55 +010097#endif
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +080098
99static struct i2c_driver axp20x_i2c_driver = {
100 .driver = {
101 .name = "axp20x-i2c",
102 .of_match_table = of_match_ptr(axp20x_i2c_of_match),
103 .acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match),
104 },
105 .probe = axp20x_i2c_probe,
106 .remove = axp20x_i2c_remove,
107 .id_table = axp20x_i2c_id,
108};
109
110module_i2c_driver(axp20x_i2c_driver);
111
112MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X");
113MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
114MODULE_LICENSE("GPL");