mfd: max77693: Remove unnecessary wrapper functions
[deliverable/linux.git] / drivers / mfd / max77693.c
CommitLineData
83871c00
CC
1/*
2 * max77693.c - mfd core driver for the MAX 77693
3 *
4 * Copyright (C) 2012 Samsung Electronics
5 * SangYoung Son <hello.son@smasung.com>
6 *
7 * This program is not provided / owned by Maxim Integrated Products.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * This driver is based on max8997.c
24 */
25
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/i2c.h>
29#include <linux/err.h>
30#include <linux/interrupt.h>
71c7f93e 31#include <linux/of.h>
83871c00
CC
32#include <linux/pm_runtime.h>
33#include <linux/mutex.h>
34#include <linux/mfd/core.h>
35#include <linux/mfd/max77693.h>
36#include <linux/mfd/max77693-private.h>
37#include <linux/regulator/machine.h>
38#include <linux/regmap.h>
39
40#define I2C_ADDR_PMIC (0xCC >> 1) /* Charger, Flash LED */
41#define I2C_ADDR_MUIC (0x4A >> 1)
42#define I2C_ADDR_HAPTIC (0x90 >> 1)
43
7c0517b1 44static const struct mfd_cell max77693_devs[] = {
83871c00
CC
45 { .name = "max77693-pmic", },
46 { .name = "max77693-charger", },
47 { .name = "max77693-flash", },
48 { .name = "max77693-muic", },
49 { .name = "max77693-haptic", },
50};
51
83871c00
CC
52static const struct regmap_config max77693_regmap_config = {
53 .reg_bits = 8,
54 .val_bits = 8,
55 .max_register = MAX77693_PMIC_REG_END,
56};
57
75ad1327
KK
58static const struct regmap_config max77693_regmap_muic_config = {
59 .reg_bits = 8,
60 .val_bits = 8,
61 .max_register = MAX77693_MUIC_REG_END,
62};
63
83871c00
CC
64static int max77693_i2c_probe(struct i2c_client *i2c,
65 const struct i2c_device_id *id)
66{
67 struct max77693_dev *max77693;
d0540f91 68 unsigned int reg_data;
83871c00
CC
69 int ret = 0;
70
71 max77693 = devm_kzalloc(&i2c->dev,
72 sizeof(struct max77693_dev), GFP_KERNEL);
73 if (max77693 == NULL)
74 return -ENOMEM;
75
83871c00
CC
76 i2c_set_clientdata(i2c, max77693);
77 max77693->dev = &i2c->dev;
78 max77693->i2c = i2c;
79 max77693->irq = i2c->irq;
80 max77693->type = id->driver_data;
81
2429d863
AL
82 max77693->regmap = devm_regmap_init_i2c(i2c, &max77693_regmap_config);
83 if (IS_ERR(max77693->regmap)) {
84 ret = PTR_ERR(max77693->regmap);
85 dev_err(max77693->dev, "failed to allocate register map: %d\n",
86 ret);
87 return ret;
88 }
83871c00 89
d0540f91 90 ret = regmap_read(max77693->regmap, MAX77693_PMIC_REG_PMIC_ID2,
2429d863
AL
91 &reg_data);
92 if (ret < 0) {
83871c00 93 dev_err(max77693->dev, "device not found on this channel\n");
2429d863 94 return ret;
83871c00
CC
95 } else
96 dev_info(max77693->dev, "device ID: 0x%x\n", reg_data);
97
98 max77693->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC);
ad09dd6a
KK
99 if (!max77693->muic) {
100 dev_err(max77693->dev, "Failed to allocate I2C device for MUIC\n");
101 return -ENODEV;
102 }
83871c00
CC
103 i2c_set_clientdata(max77693->muic, max77693);
104
105 max77693->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
ad09dd6a
KK
106 if (!max77693->haptic) {
107 dev_err(max77693->dev, "Failed to allocate I2C device for Haptic\n");
108 ret = -ENODEV;
109 goto err_i2c_haptic;
110 }
83871c00
CC
111 i2c_set_clientdata(max77693->haptic, max77693);
112
b186b124
CC
113 /*
114 * Initialize register map for MUIC device because use regmap-muic
115 * instance of MUIC device when irq of max77693 is initialized
116 * before call max77693-muic probe() function.
117 */
118 max77693->regmap_muic = devm_regmap_init_i2c(max77693->muic,
75ad1327 119 &max77693_regmap_muic_config);
b186b124
CC
120 if (IS_ERR(max77693->regmap_muic)) {
121 ret = PTR_ERR(max77693->regmap_muic);
122 dev_err(max77693->dev,
123 "failed to allocate register map: %d\n", ret);
2429d863 124 goto err_regmap_muic;
b186b124
CC
125 }
126
6592ebb3
CC
127 ret = max77693_irq_init(max77693);
128 if (ret < 0)
ff2b7ac6 129 goto err_irq;
6592ebb3 130
83871c00
CC
131 pm_runtime_set_active(max77693->dev);
132
133 ret = mfd_add_devices(max77693->dev, -1, max77693_devs,
0848c94f 134 ARRAY_SIZE(max77693_devs), NULL, 0, NULL);
83871c00
CC
135 if (ret < 0)
136 goto err_mfd;
137
138 return ret;
139
140err_mfd:
ff2b7ac6
AL
141 max77693_irq_exit(max77693);
142err_irq:
2429d863 143err_regmap_muic:
83871c00 144 i2c_unregister_device(max77693->haptic);
ad09dd6a
KK
145err_i2c_haptic:
146 i2c_unregister_device(max77693->muic);
83871c00
CC
147 return ret;
148}
149
150static int max77693_i2c_remove(struct i2c_client *i2c)
151{
152 struct max77693_dev *max77693 = i2c_get_clientdata(i2c);
153
154 mfd_remove_devices(max77693->dev);
ff2b7ac6 155 max77693_irq_exit(max77693);
83871c00
CC
156 i2c_unregister_device(max77693->muic);
157 i2c_unregister_device(max77693->haptic);
158
159 return 0;
160}
161
162static const struct i2c_device_id max77693_i2c_id[] = {
163 { "max77693", TYPE_MAX77693 },
164 { }
165};
166MODULE_DEVICE_TABLE(i2c, max77693_i2c_id);
167
6592ebb3
CC
168static int max77693_suspend(struct device *dev)
169{
170 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
171 struct max77693_dev *max77693 = i2c_get_clientdata(i2c);
172
173 if (device_may_wakeup(dev))
174 irq_set_irq_wake(max77693->irq, 1);
175 return 0;
176}
177
178static int max77693_resume(struct device *dev)
179{
180 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
181 struct max77693_dev *max77693 = i2c_get_clientdata(i2c);
182
183 if (device_may_wakeup(dev))
184 irq_set_irq_wake(max77693->irq, 0);
185 return max77693_irq_resume(max77693);
186}
187
12477a32 188static const struct dev_pm_ops max77693_pm = {
6592ebb3
CC
189 .suspend = max77693_suspend,
190 .resume = max77693_resume,
191};
192
4657185c 193#ifdef CONFIG_OF
5ce9a55b 194static const struct of_device_id max77693_dt_match[] = {
4657185c
AH
195 { .compatible = "maxim,max77693" },
196 {},
197};
198#endif
199
83871c00
CC
200static struct i2c_driver max77693_i2c_driver = {
201 .driver = {
202 .name = "max77693",
203 .owner = THIS_MODULE,
6592ebb3 204 .pm = &max77693_pm,
4657185c 205 .of_match_table = of_match_ptr(max77693_dt_match),
83871c00
CC
206 },
207 .probe = max77693_i2c_probe,
208 .remove = max77693_i2c_remove,
209 .id_table = max77693_i2c_id,
210};
211
212static int __init max77693_i2c_init(void)
213{
214 return i2c_add_driver(&max77693_i2c_driver);
215}
216/* init early so consumer devices can complete system boot */
217subsys_initcall(max77693_i2c_init);
218
219static void __exit max77693_i2c_exit(void)
220{
221 i2c_del_driver(&max77693_i2c_driver);
222}
223module_exit(max77693_i2c_exit);
224
225MODULE_DESCRIPTION("MAXIM 77693 multi-function core driver");
226MODULE_AUTHOR("SangYoung, Son <hello.son@samsung.com>");
227MODULE_LICENSE("GPL");
This page took 0.162982 seconds and 5 git commands to generate.