Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * I2C driver for the X-Powers' Power Management ICs
0004  *
0005  * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
0006  * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
0007  * as well as configurable GPIOs.
0008  *
0009  * This driver supports the I2C variants.
0010  *
0011  * Copyright (C) 2014 Carlo Caione
0012  *
0013  * Author: Carlo Caione <carlo@caione.org>
0014  */
0015 
0016 #include <linux/acpi.h>
0017 #include <linux/err.h>
0018 #include <linux/i2c.h>
0019 #include <linux/module.h>
0020 #include <linux/mfd/axp20x.h>
0021 #include <linux/of.h>
0022 #include <linux/regmap.h>
0023 #include <linux/slab.h>
0024 
0025 static int axp20x_i2c_probe(struct i2c_client *i2c,
0026                 const struct i2c_device_id *id)
0027 {
0028     struct axp20x_dev *axp20x;
0029     int ret;
0030 
0031     axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
0032     if (!axp20x)
0033         return -ENOMEM;
0034 
0035     axp20x->dev = &i2c->dev;
0036     axp20x->irq = i2c->irq;
0037     dev_set_drvdata(axp20x->dev, axp20x);
0038 
0039     ret = axp20x_match_device(axp20x);
0040     if (ret)
0041         return ret;
0042 
0043     axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
0044     if (IS_ERR(axp20x->regmap)) {
0045         ret = PTR_ERR(axp20x->regmap);
0046         dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
0047         return ret;
0048     }
0049 
0050     return axp20x_device_probe(axp20x);
0051 }
0052 
0053 static int axp20x_i2c_remove(struct i2c_client *i2c)
0054 {
0055     struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);
0056 
0057     axp20x_device_remove(axp20x);
0058 
0059     return 0;
0060 }
0061 
0062 #ifdef CONFIG_OF
0063 static const struct of_device_id axp20x_i2c_of_match[] = {
0064     { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID },
0065     { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID },
0066     { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
0067     { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
0068     { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
0069     { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
0070     { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
0071     { },
0072 };
0073 MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match);
0074 #endif
0075 
0076 static const struct i2c_device_id axp20x_i2c_id[] = {
0077     { "axp152", 0 },
0078     { "axp202", 0 },
0079     { "axp209", 0 },
0080     { "axp221", 0 },
0081     { "axp223", 0 },
0082     { "axp803", 0 },
0083     { "axp806", 0 },
0084     { },
0085 };
0086 MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
0087 
0088 #ifdef CONFIG_ACPI
0089 static const struct acpi_device_id axp20x_i2c_acpi_match[] = {
0090     {
0091         .id = "INT33F4",
0092         .driver_data = AXP288_ID,
0093     },
0094     { },
0095 };
0096 MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match);
0097 #endif
0098 
0099 static struct i2c_driver axp20x_i2c_driver = {
0100     .driver = {
0101         .name   = "axp20x-i2c",
0102         .of_match_table = of_match_ptr(axp20x_i2c_of_match),
0103         .acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match),
0104     },
0105     .probe      = axp20x_i2c_probe,
0106     .remove     = axp20x_i2c_remove,
0107     .id_table   = axp20x_i2c_id,
0108 };
0109 
0110 module_i2c_driver(axp20x_i2c_driver);
0111 
0112 MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X");
0113 MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
0114 MODULE_LICENSE("GPL");