RISC-V: Canaan devicetree fixes
[linux-2.6-block.git] / drivers / mfd / tps65912-i2c.c
CommitLineData
abd46274 1// SPDX-License-Identifier: GPL-2.0-only
796f5692
AD
2/*
3 * I2C access driver for TI TPS65912x PMICs
4 *
4f4ed454 5 * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
796f5692
AD
6 * Andrew F. Davis <afd@ti.com>
7 *
796f5692
AD
8 * Based on the TPS65218 driver and the previous TPS65912 driver by
9 * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
10 */
11
12#include <linux/i2c.h>
13#include <linux/module.h>
14#include <linux/regmap.h>
15
16#include <linux/mfd/tps65912.h>
17
18static const struct of_device_id tps65912_i2c_of_match_table[] = {
19 { .compatible = "ti,tps65912", },
20 { /* sentinel */ }
21};
f8b03805 22MODULE_DEVICE_TABLE(of, tps65912_i2c_of_match_table);
796f5692
AD
23
24static int tps65912_i2c_probe(struct i2c_client *client,
25 const struct i2c_device_id *ids)
26{
27 struct tps65912 *tps;
28
29 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
30 if (!tps)
31 return -ENOMEM;
32
33 i2c_set_clientdata(client, tps);
34 tps->dev = &client->dev;
35 tps->irq = client->irq;
36
37 tps->regmap = devm_regmap_init_i2c(client, &tps65912_regmap_config);
38 if (IS_ERR(tps->regmap)) {
39 dev_err(tps->dev, "Failed to initialize register map\n");
40 return PTR_ERR(tps->regmap);
41 }
42
43 return tps65912_device_init(tps);
44}
45
46static int tps65912_i2c_remove(struct i2c_client *client)
47{
48 struct tps65912 *tps = i2c_get_clientdata(client);
49
ec14d90d
UKK
50 tps65912_device_exit(tps);
51
52 return 0;
796f5692
AD
53}
54
55static const struct i2c_device_id tps65912_i2c_id_table[] = {
56 { "tps65912", 0 },
57 { /* sentinel */ }
58};
59MODULE_DEVICE_TABLE(i2c, tps65912_i2c_id_table);
60
61static struct i2c_driver tps65912_i2c_driver = {
62 .driver = {
63 .name = "tps65912",
64 .of_match_table = tps65912_i2c_of_match_table,
65 },
66 .probe = tps65912_i2c_probe,
67 .remove = tps65912_i2c_remove,
68 .id_table = tps65912_i2c_id_table,
69};
70module_i2c_driver(tps65912_i2c_driver);
71
72MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
73MODULE_DESCRIPTION("TPS65912x I2C Interface Driver");
74MODULE_LICENSE("GPL v2");