aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/88pm860x-i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd/88pm860x-i2c.c')
-rw-r--r--drivers/mfd/88pm860x-i2c.c174
1 files changed, 12 insertions, 162 deletions
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c
index b2cfdc458561..ff8f803ce833 100644
--- a/drivers/mfd/88pm860x-i2c.c
+++ b/drivers/mfd/88pm860x-i2c.c
@@ -10,12 +10,9 @@
10 */ 10 */
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/i2c.h> 13#include <linux/i2c.h>
15#include <linux/err.h>
16#include <linux/regmap.h> 14#include <linux/regmap.h>
17#include <linux/mfd/88pm860x.h> 15#include <linux/mfd/88pm860x.h>
18#include <linux/slab.h>
19 16
20int pm860x_reg_read(struct i2c_client *i2c, int reg) 17int pm860x_reg_read(struct i2c_client *i2c, int reg)
21{ 18{
@@ -91,8 +88,18 @@ static int read_device(struct i2c_client *i2c, int reg,
91 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX + 3]; 88 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX + 3];
92 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX + 2]; 89 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX + 2];
93 struct i2c_adapter *adap = i2c->adapter; 90 struct i2c_adapter *adap = i2c->adapter;
94 struct i2c_msg msg[2] = {{i2c->addr, 0, 1, msgbuf0}, 91 struct i2c_msg msg[2] = {
95 {i2c->addr, I2C_M_RD, 0, msgbuf1}, 92 {
93 .addr = i2c->addr,
94 .flags = 0,
95 .len = 1,
96 .buf = msgbuf0
97 },
98 { .addr = i2c->addr,
99 .flags = I2C_M_RD,
100 .len = 0,
101 .buf = msgbuf1
102 },
96 }; 103 };
97 int num = 1, ret = 0; 104 int num = 1, ret = 0;
98 105
@@ -231,160 +238,3 @@ out:
231 return ret; 238 return ret;
232} 239}
233EXPORT_SYMBOL(pm860x_page_set_bits); 240EXPORT_SYMBOL(pm860x_page_set_bits);
234
235static const struct i2c_device_id pm860x_id_table[] = {
236 { "88PM860x", 0 },
237 {}
238};
239MODULE_DEVICE_TABLE(i2c, pm860x_id_table);
240
241static int verify_addr(struct i2c_client *i2c)
242{
243 unsigned short addr_8607[] = {0x30, 0x34};
244 unsigned short addr_8606[] = {0x10, 0x11};
245 int size, i;
246
247 if (i2c == NULL)
248 return 0;
249 size = ARRAY_SIZE(addr_8606);
250 for (i = 0; i < size; i++) {
251 if (i2c->addr == *(addr_8606 + i))
252 return CHIP_PM8606;
253 }
254 size = ARRAY_SIZE(addr_8607);
255 for (i = 0; i < size; i++) {
256 if (i2c->addr == *(addr_8607 + i))
257 return CHIP_PM8607;
258 }
259 return 0;
260}
261
262static struct regmap_config pm860x_regmap_config = {
263 .reg_bits = 8,
264 .val_bits = 8,
265};
266
267static int __devinit pm860x_probe(struct i2c_client *client,
268 const struct i2c_device_id *id)
269{
270 struct pm860x_platform_data *pdata = client->dev.platform_data;
271 struct pm860x_chip *chip;
272 int ret;
273
274 if (!pdata) {
275 pr_info("No platform data in %s!\n", __func__);
276 return -EINVAL;
277 }
278
279 chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
280 if (chip == NULL)
281 return -ENOMEM;
282
283 chip->id = verify_addr(client);
284 chip->regmap = regmap_init_i2c(client, &pm860x_regmap_config);
285 if (IS_ERR(chip->regmap)) {
286 ret = PTR_ERR(chip->regmap);
287 dev_err(&client->dev, "Failed to allocate register map: %d\n",
288 ret);
289 kfree(chip);
290 return ret;
291 }
292 chip->client = client;
293 i2c_set_clientdata(client, chip);
294 chip->dev = &client->dev;
295 dev_set_drvdata(chip->dev, chip);
296
297 /*
298 * Both client and companion client shares same platform driver.
299 * Driver distinguishes them by pdata->companion_addr.
300 * pdata->companion_addr is only assigned if companion chip exists.
301 * At the same time, the companion_addr shouldn't equal to client
302 * address.
303 */
304 if (pdata->companion_addr && (pdata->companion_addr != client->addr)) {
305 chip->companion_addr = pdata->companion_addr;
306 chip->companion = i2c_new_dummy(chip->client->adapter,
307 chip->companion_addr);
308 chip->regmap_companion = regmap_init_i2c(chip->companion,
309 &pm860x_regmap_config);
310 if (IS_ERR(chip->regmap_companion)) {
311 ret = PTR_ERR(chip->regmap_companion);
312 dev_err(&chip->companion->dev,
313 "Failed to allocate register map: %d\n", ret);
314 return ret;
315 }
316 i2c_set_clientdata(chip->companion, chip);
317 }
318
319 pm860x_device_init(chip, pdata);
320 return 0;
321}
322
323static int __devexit pm860x_remove(struct i2c_client *client)
324{
325 struct pm860x_chip *chip = i2c_get_clientdata(client);
326
327 pm860x_device_exit(chip);
328 if (chip->companion) {
329 regmap_exit(chip->regmap_companion);
330 i2c_unregister_device(chip->companion);
331 }
332 regmap_exit(chip->regmap);
333 kfree(chip);
334 return 0;
335}
336
337#ifdef CONFIG_PM_SLEEP
338static int pm860x_suspend(struct device *dev)
339{
340 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
341 struct pm860x_chip *chip = i2c_get_clientdata(client);
342
343 if (device_may_wakeup(dev) && chip->wakeup_flag)
344 enable_irq_wake(chip->core_irq);
345 return 0;
346}
347
348static int pm860x_resume(struct device *dev)
349{
350 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
351 struct pm860x_chip *chip = i2c_get_clientdata(client);
352
353 if (device_may_wakeup(dev) && chip->wakeup_flag)
354 disable_irq_wake(chip->core_irq);
355 return 0;
356}
357#endif
358
359static SIMPLE_DEV_PM_OPS(pm860x_pm_ops, pm860x_suspend, pm860x_resume);
360
361static struct i2c_driver pm860x_driver = {
362 .driver = {
363 .name = "88PM860x",
364 .owner = THIS_MODULE,
365 .pm = &pm860x_pm_ops,
366 },
367 .probe = pm860x_probe,
368 .remove = __devexit_p(pm860x_remove),
369 .id_table = pm860x_id_table,
370};
371
372static int __init pm860x_i2c_init(void)
373{
374 int ret;
375 ret = i2c_add_driver(&pm860x_driver);
376 if (ret != 0)
377 pr_err("Failed to register 88PM860x I2C driver: %d\n", ret);
378 return ret;
379}
380subsys_initcall(pm860x_i2c_init);
381
382static void __exit pm860x_i2c_exit(void)
383{
384 i2c_del_driver(&pm860x_driver);
385}
386module_exit(pm860x_i2c_exit);
387
388MODULE_DESCRIPTION("I2C Driver for Marvell 88PM860x");
389MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
390MODULE_LICENSE("GPL");