Chen-Yu Tsai | 4fd4115 | 2016-02-12 10:02:42 +0800 | [diff] [blame] | 1 | /* |
| 2 | * I2C driver for the X-Powers' Power Management ICs |
| 3 | * |
| 4 | * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC |
| 5 | * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature |
| 6 | * as well as configurable GPIOs. |
| 7 | * |
| 8 | * This driver supports the I2C variants. |
| 9 | * |
| 10 | * Copyright (C) 2014 Carlo Caione |
| 11 | * |
| 12 | * Author: Carlo Caione <carlo@caione.org> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License version 2 as |
| 16 | * published by the Free Software Foundation. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/acpi.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/i2c.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/mfd/axp20x.h> |
| 24 | #include <linux/of.h> |
| 25 | #include <linux/regmap.h> |
| 26 | #include <linux/slab.h> |
| 27 | |
| 28 | static int axp20x_i2c_probe(struct i2c_client *i2c, |
| 29 | const struct i2c_device_id *id) |
| 30 | { |
| 31 | struct axp20x_dev *axp20x; |
| 32 | int ret; |
| 33 | |
| 34 | axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL); |
| 35 | if (!axp20x) |
| 36 | return -ENOMEM; |
| 37 | |
| 38 | axp20x->dev = &i2c->dev; |
| 39 | axp20x->irq = i2c->irq; |
| 40 | dev_set_drvdata(axp20x->dev, axp20x); |
| 41 | |
| 42 | ret = axp20x_match_device(axp20x); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | |
| 46 | axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg); |
| 47 | if (IS_ERR(axp20x->regmap)) { |
| 48 | ret = PTR_ERR(axp20x->regmap); |
| 49 | dev_err(&i2c->dev, "regmap init failed: %d\n", ret); |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | return axp20x_device_probe(axp20x); |
| 54 | } |
| 55 | |
| 56 | static int axp20x_i2c_remove(struct i2c_client *i2c) |
| 57 | { |
| 58 | struct axp20x_dev *axp20x = i2c_get_clientdata(i2c); |
| 59 | |
| 60 | return axp20x_device_remove(axp20x); |
| 61 | } |
| 62 | |
| 63 | static 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 }, |
| 68 | { }, |
| 69 | }; |
| 70 | MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match); |
| 71 | |
Chen-Yu Tsai | 4fd4115 | 2016-02-12 10:02:42 +0800 | [diff] [blame] | 72 | static const struct i2c_device_id axp20x_i2c_id[] = { |
Hans de Goede | 41751b0 | 2016-10-05 17:51:12 +0200 | [diff] [blame] | 73 | { "axp152", 0 }, |
| 74 | { "axp202", 0 }, |
| 75 | { "axp209", 0 }, |
| 76 | { "axp221", 0 }, |
Chen-Yu Tsai | 4fd4115 | 2016-02-12 10:02:42 +0800 | [diff] [blame] | 77 | { }, |
| 78 | }; |
| 79 | MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id); |
| 80 | |
| 81 | static const struct acpi_device_id axp20x_i2c_acpi_match[] = { |
| 82 | { |
| 83 | .id = "INT33F4", |
| 84 | .driver_data = AXP288_ID, |
| 85 | }, |
| 86 | { }, |
| 87 | }; |
| 88 | MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match); |
| 89 | |
| 90 | static struct i2c_driver axp20x_i2c_driver = { |
| 91 | .driver = { |
| 92 | .name = "axp20x-i2c", |
| 93 | .of_match_table = of_match_ptr(axp20x_i2c_of_match), |
| 94 | .acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match), |
| 95 | }, |
| 96 | .probe = axp20x_i2c_probe, |
| 97 | .remove = axp20x_i2c_remove, |
| 98 | .id_table = axp20x_i2c_id, |
| 99 | }; |
| 100 | |
| 101 | module_i2c_driver(axp20x_i2c_driver); |
| 102 | |
| 103 | MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X"); |
| 104 | MODULE_AUTHOR("Carlo Caione <carlo@caione.org>"); |
| 105 | MODULE_LICENSE("GPL"); |