blob: c824975e86d57c789a946be4c4a78f7da29c218e [file] [log] [blame]
Manoj Gangwaldfa84fe2012-11-22 12:11:49 +05301/*
2 * tlv320aic3xxx-i2c.c -- driver for TLV320AIC3XXX TODO
3 *
4 * Author: Mukund Navada <navada@ti.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/kernel.h>
23#include <linux/err.h>
24#include <linux/i2c.h>
25#include <linux/module.h>
26#include <linux/pm_runtime.h>
27#include <linux/regmap.h>
28#include <linux/regulator/consumer.h>
29#include <linux/slab.h>
30
31#include <linux/mfd/tlv320aic3xxx-core.h>
32
33struct regmap_config aicxxx_i2c_regmap = {
34 .reg_bits = 8,
35 .val_bits = 8,
36 .cache_type = REGCACHE_NONE,
37};
38
39#ifdef CONFIG_PM
40static int aic3xxx_suspend(struct device *dev)
41{
42 struct aic3xxx *aic3xxx = dev_get_drvdata(dev);
43
44 aic3xxx->suspended = true;
45
46 return 0;
47}
48
49static int aic3xxx_resume(struct device *dev)
50{
51 struct aic3xxx *aic3xxx = dev_get_drvdata(dev);
52
53 aic3xxx->suspended = false;
54
55 return 0;
56}
57#endif
58
59static __devinit int aic3xxx_i2c_probe(struct i2c_client *i2c,
60 const struct i2c_device_id *id)
61{
62 struct aic3xxx *aicxxx;
63 const struct regmap_config *regmap_config;
64 int ret;
65
66 switch (id->driver_data) {
67 case TLV320AIC3262:
68 regmap_config = &aicxxx_i2c_regmap;
69 break;
70#ifdef CONFIG_MFD_AIC3285
71 case TLV320AIC3285:
72 regmap_config = &aicxxx_i2c_regmap;
73 break;
74#endif
75 default:
76 dev_err(&i2c->dev, "Unknown device type %ld\n",
77 id->driver_data);
78 return -EINVAL;
79 }
80
81 aicxxx = devm_kzalloc(&i2c->dev, sizeof(*aicxxx), GFP_KERNEL);
82 if (aicxxx == NULL)
83 return -ENOMEM;
84
85 aicxxx->regmap = devm_regmap_init_i2c(i2c, regmap_config);
86
87 if (IS_ERR(aicxxx->regmap)) {
88 ret = PTR_ERR(aicxxx->regmap);
89 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
90 ret);
91 return ret;
92 }
93
94 aicxxx->type = id->driver_data;
95 aicxxx->dev = &i2c->dev;
96 aicxxx->irq = i2c->irq;
97
98 return aic3xxx_device_init(aicxxx, aicxxx->irq);
99}
100
101static int __devexit aic3xxx_i2c_remove(struct i2c_client *i2c)
102{
103 struct aic3xxx *aicxxx = dev_get_drvdata(&i2c->dev);
104 aic3xxx_device_exit(aicxxx);
105 return 0;
106}
107
Rahul Mittal73e0c042013-02-05 12:26:52 +0530108static void aic3xxx_i2c_shutdown(struct i2c_client *i2c)
109{
110 struct aic3xxx *aic3xxx = dev_get_drvdata(&i2c->dev);
111 mutex_lock(&aic3xxx->io_lock);
112 aic3xxx->shutdown_complete = 1;
113 mutex_unlock(&aic3xxx->io_lock);
114}
115
Manoj Gangwaldfa84fe2012-11-22 12:11:49 +0530116static const struct i2c_device_id aic3xxx_i2c_id[] = {
117 {"tlv320aic3262", TLV320AIC3262},
118 {"tlv320aic3285", TLV320AIC3285},
119 { }
120};
121MODULE_DEVICE_TABLE(i2c, aic3xxx_i2c_id);
122
123static UNIVERSAL_DEV_PM_OPS(aic3xxx_pm_ops, aic3xxx_suspend, aic3xxx_resume,
124 NULL);
125
126static struct i2c_driver aic3xxx_i2c_driver = {
127 .driver = {
128 .name = "tlv320aic3xxx",
129 .owner = THIS_MODULE,
130 .pm = &aic3xxx_pm_ops,
131 },
132 .probe = aic3xxx_i2c_probe,
133 .remove = __devexit_p(aic3xxx_i2c_remove),
134 .id_table = aic3xxx_i2c_id,
Rahul Mittal73e0c042013-02-05 12:26:52 +0530135 .shutdown = aic3xxx_i2c_shutdown,
Manoj Gangwaldfa84fe2012-11-22 12:11:49 +0530136};
137
138module_i2c_driver(aic3xxx_i2c_driver);
139
140MODULE_DESCRIPTION("TLV320AIC3XXX I2C bus interface");
141MODULE_AUTHOR("Mukund Navada <navada@ti.com>");
142MODULE_LICENSE("GPL");