1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
24fd41151SChen-Yu Tsai /*
34fd41151SChen-Yu Tsai * I2C driver for the X-Powers' Power Management ICs
44fd41151SChen-Yu Tsai *
54fd41151SChen-Yu Tsai * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
64fd41151SChen-Yu Tsai * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
74fd41151SChen-Yu Tsai * as well as configurable GPIOs.
84fd41151SChen-Yu Tsai *
94fd41151SChen-Yu Tsai * This driver supports the I2C variants.
104fd41151SChen-Yu Tsai *
114fd41151SChen-Yu Tsai * Copyright (C) 2014 Carlo Caione
124fd41151SChen-Yu Tsai *
134fd41151SChen-Yu Tsai * Author: Carlo Caione <carlo@caione.org>
144fd41151SChen-Yu Tsai */
154fd41151SChen-Yu Tsai
164fd41151SChen-Yu Tsai #include <linux/acpi.h>
174fd41151SChen-Yu Tsai #include <linux/err.h>
184fd41151SChen-Yu Tsai #include <linux/i2c.h>
194fd41151SChen-Yu Tsai #include <linux/module.h>
204fd41151SChen-Yu Tsai #include <linux/mfd/axp20x.h>
214fd41151SChen-Yu Tsai #include <linux/of.h>
224fd41151SChen-Yu Tsai #include <linux/regmap.h>
234fd41151SChen-Yu Tsai #include <linux/slab.h>
244fd41151SChen-Yu Tsai
axp20x_i2c_probe(struct i2c_client * i2c)252f2455dbSUwe Kleine-König static int axp20x_i2c_probe(struct i2c_client *i2c)
264fd41151SChen-Yu Tsai {
274fd41151SChen-Yu Tsai struct axp20x_dev *axp20x;
284fd41151SChen-Yu Tsai int ret;
294fd41151SChen-Yu Tsai
304fd41151SChen-Yu Tsai axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
314fd41151SChen-Yu Tsai if (!axp20x)
324fd41151SChen-Yu Tsai return -ENOMEM;
334fd41151SChen-Yu Tsai
344fd41151SChen-Yu Tsai axp20x->dev = &i2c->dev;
354fd41151SChen-Yu Tsai axp20x->irq = i2c->irq;
364fd41151SChen-Yu Tsai dev_set_drvdata(axp20x->dev, axp20x);
374fd41151SChen-Yu Tsai
384fd41151SChen-Yu Tsai ret = axp20x_match_device(axp20x);
394fd41151SChen-Yu Tsai if (ret)
404fd41151SChen-Yu Tsai return ret;
414fd41151SChen-Yu Tsai
424fd41151SChen-Yu Tsai axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
434fd41151SChen-Yu Tsai if (IS_ERR(axp20x->regmap)) {
444fd41151SChen-Yu Tsai ret = PTR_ERR(axp20x->regmap);
454fd41151SChen-Yu Tsai dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
464fd41151SChen-Yu Tsai return ret;
474fd41151SChen-Yu Tsai }
484fd41151SChen-Yu Tsai
494fd41151SChen-Yu Tsai return axp20x_device_probe(axp20x);
504fd41151SChen-Yu Tsai }
514fd41151SChen-Yu Tsai
axp20x_i2c_remove(struct i2c_client * i2c)52ed5c2f5fSUwe Kleine-König static void axp20x_i2c_remove(struct i2c_client *i2c)
534fd41151SChen-Yu Tsai {
544fd41151SChen-Yu Tsai struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);
554fd41151SChen-Yu Tsai
563c15e00eSUwe Kleine-König axp20x_device_remove(axp20x);
574fd41151SChen-Yu Tsai }
584fd41151SChen-Yu Tsai
5906b324fcSKrzysztof Kozlowski #ifdef CONFIG_OF
604fd41151SChen-Yu Tsai static const struct of_device_id axp20x_i2c_of_match[] = {
614fd41151SChen-Yu Tsai { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID },
624fd41151SChen-Yu Tsai { .compatible = "x-powers,axp192", .data = (void *)AXP192_ID },
634fd41151SChen-Yu Tsai { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID },
644fd41151SChen-Yu Tsai { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
654f799e47SMaxime Ripard { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
6685c30785SFrank Lee { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
6799e19b7cSChen-Yu Tsai { .compatible = "x-powers,axp313a", .data = (void *)AXP313A_ID },
68*e0f8ad2aSShengyu Qu { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
694fd41151SChen-Yu Tsai { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
704fd41151SChen-Yu Tsai { .compatible = "x-powers,axp15060", .data = (void *)AXP15060_ID },
714fd41151SChen-Yu Tsai { },
7206b324fcSKrzysztof Kozlowski };
734fd41151SChen-Yu Tsai MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match);
744fd41151SChen-Yu Tsai #endif
7541751b03SHans de Goede
7641751b03SHans de Goede static const struct i2c_device_id axp20x_i2c_id[] = {
7741751b03SHans de Goede { "axp152", 0 },
7841751b03SHans de Goede { "axp192", 0 },
794f799e47SMaxime Ripard { "axp202", 0 },
8085c30785SFrank Lee { "axp209", 0 },
8199e19b7cSChen-Yu Tsai { "axp221", 0 },
82*e0f8ad2aSShengyu Qu { "axp223", 0 },
834fd41151SChen-Yu Tsai { "axp313a", 0 },
844fd41151SChen-Yu Tsai { "axp803", 0 },
854fd41151SChen-Yu Tsai { "axp806", 0 },
864fd41151SChen-Yu Tsai { "axp15060", 0 },
8721b2998dSLee Jones { },
884fd41151SChen-Yu Tsai };
894fd41151SChen-Yu Tsai MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
904fd41151SChen-Yu Tsai
914fd41151SChen-Yu Tsai #ifdef CONFIG_ACPI
924fd41151SChen-Yu Tsai static const struct acpi_device_id axp20x_i2c_acpi_match[] = {
934fd41151SChen-Yu Tsai {
944fd41151SChen-Yu Tsai .id = "INT33F4",
954fd41151SChen-Yu Tsai .driver_data = AXP288_ID,
9621b2998dSLee Jones },
974fd41151SChen-Yu Tsai { },
984fd41151SChen-Yu Tsai };
994fd41151SChen-Yu Tsai MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match);
1004fd41151SChen-Yu Tsai #endif
1014fd41151SChen-Yu Tsai
1024fd41151SChen-Yu Tsai static struct i2c_driver axp20x_i2c_driver = {
1034fd41151SChen-Yu Tsai .driver = {
1042f2455dbSUwe Kleine-König .name = "axp20x-i2c",
1054fd41151SChen-Yu Tsai .of_match_table = of_match_ptr(axp20x_i2c_of_match),
1064fd41151SChen-Yu Tsai .acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match),
1074fd41151SChen-Yu Tsai },
1084fd41151SChen-Yu Tsai .probe = axp20x_i2c_probe,
1094fd41151SChen-Yu Tsai .remove = axp20x_i2c_remove,
1104fd41151SChen-Yu Tsai .id_table = axp20x_i2c_id,
1114fd41151SChen-Yu Tsai };
1124fd41151SChen-Yu Tsai
1134fd41151SChen-Yu Tsai module_i2c_driver(axp20x_i2c_driver);
114
115 MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X");
116 MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
117 MODULE_LICENSE("GPL");
118