| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 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 <[email protected]> |
| 14 |
*/ |
| 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 |
|
| 25 |
static int axp20x_i2c_probe(struct i2c_client *i2c) |
| 26 |
{ |
| 27 |
struct axp20x_dev *axp20x; |
| 28 |
int ret; |
| 29 |
|
| 30 |
axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL); |
| 31 |
if (!axp20x) |
| 32 |
return -ENOMEM; |
| 33 |
|
| 34 |
axp20x->dev = &i2c->dev; |
| 35 |
axp20x->irq = i2c->irq; |
| 36 |
dev_set_drvdata(axp20x->dev, axp20x); |
| 37 |
|
| 38 |
ret = axp20x_match_device(axp20x); |
| 39 |
if (ret) |
| 40 |
return ret; |
| 41 |
|
| 42 |
axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg); |
| 43 |
if (IS_ERR(axp20x->regmap)) { |
| 44 |
ret = PTR_ERR(axp20x->regmap); |
| 45 |
dev_err(&i2c->dev, "regmap init failed: %d\n", ret); |
| 46 |
return ret; |
| 47 |
} |
| 48 |
|
| 49 |
return axp20x_device_probe(axp20x); |
| 50 |
} |
| 51 |
|
| 52 |
static void axp20x_i2c_remove(struct i2c_client *i2c) |
| 53 |
{ |
| 54 |
struct axp20x_dev *axp20x = i2c_get_clientdata(i2c); |
| 55 |
|
| 56 |
axp20x_device_remove(axp20x); |
| 57 |
} |
| 58 |
|
| 59 |
#ifdef CONFIG_OF |
| 60 |
static const struct of_device_id axp20x_i2c_of_match[] = { |
| 61 |
{ .compatible = "x-powers,axp152", .data = (void *)AXP152_ID }, |
| 62 |
{ .compatible = "x-powers,axp192", .data = (void *)AXP192_ID }, |
| 63 |
{ .compatible = "x-powers,axp202", .data = (void *)AXP202_ID }, |
| 64 |
{ .compatible = "x-powers,axp209", .data = (void *)AXP209_ID }, |
| 65 |
{ .compatible = "x-powers,axp221", .data = (void *)AXP221_ID }, |
| 66 |
{ .compatible = "x-powers,axp223", .data = (void *)AXP223_ID }, |
| 67 |
{ .compatible = "x-powers,axp313a", .data = (void *)AXP313A_ID }, |
| 68 |
{ .compatible = "x-powers,axp323", .data = (void *)AXP323_ID }, |
| 69 |
{ .compatible = "x-powers,axp717", .data = (void *)AXP717_ID }, |
| 70 |
{ .compatible = "x-powers,axp803", .data = (void *)AXP803_ID }, |
| 71 |
{ .compatible = "x-powers,axp806", .data = (void *)AXP806_ID }, |
| 72 |
{ .compatible = "x-powers,axp15060", .data = (void *)AXP15060_ID }, |
| 73 |
{ }, |
| 74 |
}; |
| 75 |
MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match); |
| 76 |
#endif |
| 77 |
|
| 78 |
static const struct i2c_device_id axp20x_i2c_id[] = { |
| 79 |
{ "axp152" }, |
| 80 |
{ "axp192" }, |
| 81 |
{ "axp202" }, |
| 82 |
{ "axp209" }, |
| 83 |
{ "axp221" }, |
| 84 |
{ "axp223" }, |
| 85 |
{ "axp313a" }, |
| 86 |
{ "axp717" }, |
| 87 |
{ "axp803" }, |
| 88 |
{ "axp806" }, |
| 89 |
{ "axp15060" }, |
| 90 |
{ } |
| 91 |
}; |
| 92 |
MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id); |
| 93 |
|
| 94 |
#ifdef CONFIG_ACPI |
| 95 |
static const struct acpi_device_id axp20x_i2c_acpi_match[] = { |
| 96 |
{ |
| 97 |
.id = "INT33F4", |
| 98 |
.driver_data = AXP288_ID, |
| 99 |
}, |
| 100 |
{ }, |
| 101 |
}; |
| 102 |
MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match); |
| 103 |
#endif |
| 104 |
|
| 105 |
static struct i2c_driver axp20x_i2c_driver = { |
| 106 |
.driver = { |
| 107 |
.name = "axp20x-i2c", |
| 108 |
.of_match_table = of_match_ptr(axp20x_i2c_of_match), |
| 109 |
.acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match), |
| 110 |
}, |
| 111 |
.probe = axp20x_i2c_probe, |
| 112 |
.remove = axp20x_i2c_remove, |
| 113 |
.id_table = axp20x_i2c_id, |
| 114 |
}; |
| 115 |
|
| 116 |
module_i2c_driver(axp20x_i2c_driver); |
| 117 |
|
| 118 |
MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X"); |
| 119 |
MODULE_AUTHOR("Carlo Caione <[email protected]>"); |
| 120 |
MODULE_LICENSE("GPL"); |