1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * I2C access driver for TI TPS65912x PMICs
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
5*4882a593Smuzhiyun * Andrew F. Davis <afd@ti.com>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or
8*4882a593Smuzhiyun * modify it under the terms of the GNU General Public License version 2 as
9*4882a593Smuzhiyun * published by the Free Software Foundation.
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12*4882a593Smuzhiyun * kind, whether expressed or implied; without even the implied warranty
13*4882a593Smuzhiyun * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*4882a593Smuzhiyun * GNU General Public License version 2 for more details.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * Based on the TPS65218 driver and the previous TPS65912 driver by
17*4882a593Smuzhiyun * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
18*4882a593Smuzhiyun */
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <linux/i2c.h>
21*4882a593Smuzhiyun #include <linux/module.h>
22*4882a593Smuzhiyun #include <linux/regmap.h>
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #include <linux/mfd/tps65912.h>
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun static const struct of_device_id tps65912_i2c_of_match_table[] = {
27*4882a593Smuzhiyun { .compatible = "ti,tps65912", },
28*4882a593Smuzhiyun { /* sentinel */ }
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, tps65912_i2c_of_match_table);
31*4882a593Smuzhiyun
tps65912_i2c_probe(struct i2c_client * client,const struct i2c_device_id * ids)32*4882a593Smuzhiyun static int tps65912_i2c_probe(struct i2c_client *client,
33*4882a593Smuzhiyun const struct i2c_device_id *ids)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun struct tps65912 *tps;
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
38*4882a593Smuzhiyun if (!tps)
39*4882a593Smuzhiyun return -ENOMEM;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun i2c_set_clientdata(client, tps);
42*4882a593Smuzhiyun tps->dev = &client->dev;
43*4882a593Smuzhiyun tps->irq = client->irq;
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun tps->regmap = devm_regmap_init_i2c(client, &tps65912_regmap_config);
46*4882a593Smuzhiyun if (IS_ERR(tps->regmap)) {
47*4882a593Smuzhiyun dev_err(tps->dev, "Failed to initialize register map\n");
48*4882a593Smuzhiyun return PTR_ERR(tps->regmap);
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun return tps65912_device_init(tps);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
tps65912_i2c_remove(struct i2c_client * client)54*4882a593Smuzhiyun static int tps65912_i2c_remove(struct i2c_client *client)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun struct tps65912 *tps = i2c_get_clientdata(client);
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun return tps65912_device_exit(tps);
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun static const struct i2c_device_id tps65912_i2c_id_table[] = {
62*4882a593Smuzhiyun { "tps65912", 0 },
63*4882a593Smuzhiyun { /* sentinel */ }
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, tps65912_i2c_id_table);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun static struct i2c_driver tps65912_i2c_driver = {
68*4882a593Smuzhiyun .driver = {
69*4882a593Smuzhiyun .name = "tps65912",
70*4882a593Smuzhiyun .of_match_table = tps65912_i2c_of_match_table,
71*4882a593Smuzhiyun },
72*4882a593Smuzhiyun .probe = tps65912_i2c_probe,
73*4882a593Smuzhiyun .remove = tps65912_i2c_remove,
74*4882a593Smuzhiyun .id_table = tps65912_i2c_id_table,
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun module_i2c_driver(tps65912_i2c_driver);
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
79*4882a593Smuzhiyun MODULE_DESCRIPTION("TPS65912x I2C Interface Driver");
80*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
81