blob: 3ec6085d5fc061cd0c42fdeac507b51c6e53cd64 [file] [log] [blame]
Mark Browne5b48682010-10-19 23:57:56 +02001/*
2 * wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs
3 *
4 * Copyright 2009,2010 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/i2c.h>
18#include <linux/delay.h>
19#include <linux/mfd/core.h>
20#include <linux/slab.h>
Mark Brown1df59812011-06-10 19:28:10 +010021#include <linux/err.h>
22#include <linux/regmap.h>
Mark Browne5b48682010-10-19 23:57:56 +020023
24#include <linux/mfd/wm831x/core.h>
25#include <linux/mfd/wm831x/pdata.h>
26
Mark Browne5b48682010-10-19 23:57:56 +020027static int wm831x_i2c_probe(struct i2c_client *i2c,
28 const struct i2c_device_id *id)
29{
30 struct wm831x *wm831x;
Mark Brown1df59812011-06-10 19:28:10 +010031 int ret;
Mark Browne5b48682010-10-19 23:57:56 +020032
33 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
34 if (wm831x == NULL)
35 return -ENOMEM;
36
37 i2c_set_clientdata(i2c, wm831x);
38 wm831x->dev = &i2c->dev;
Mark Brown1df59812011-06-10 19:28:10 +010039
40 wm831x->regmap = regmap_init_i2c(i2c, &wm831x_regmap_config);
41 if (IS_ERR(wm831x->regmap)) {
42 ret = PTR_ERR(wm831x->regmap);
43 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
44 ret);
45 kfree(wm831x);
46 return ret;
47 }
Mark Browne5b48682010-10-19 23:57:56 +020048
49 return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
50}
51
52static int wm831x_i2c_remove(struct i2c_client *i2c)
53{
54 struct wm831x *wm831x = i2c_get_clientdata(i2c);
55
56 wm831x_device_exit(wm831x);
57
58 return 0;
59}
60
Mark Brownc538ddb2011-01-05 15:12:39 +000061static int wm831x_i2c_suspend(struct device *dev)
Mark Browne5b48682010-10-19 23:57:56 +020062{
Mark Brownc538ddb2011-01-05 15:12:39 +000063 struct wm831x *wm831x = dev_get_drvdata(dev);
Mark Browne5b48682010-10-19 23:57:56 +020064
65 return wm831x_device_suspend(wm831x);
66}
67
68static const struct i2c_device_id wm831x_i2c_id[] = {
69 { "wm8310", WM8310 },
70 { "wm8311", WM8311 },
71 { "wm8312", WM8312 },
72 { "wm8320", WM8320 },
73 { "wm8321", WM8321 },
74 { "wm8325", WM8325 },
Mark Brown412dc112010-11-24 18:01:41 +000075 { "wm8326", WM8326 },
Mark Browne5b48682010-10-19 23:57:56 +020076 { }
77};
78MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
79
Mark Brownc538ddb2011-01-05 15:12:39 +000080static const struct dev_pm_ops wm831x_pm_ops = {
81 .suspend = wm831x_i2c_suspend,
82};
Mark Browne5b48682010-10-19 23:57:56 +020083
84static struct i2c_driver wm831x_i2c_driver = {
85 .driver = {
Mark Brownc538ddb2011-01-05 15:12:39 +000086 .name = "wm831x",
87 .owner = THIS_MODULE,
88 .pm = &wm831x_pm_ops,
Mark Browne5b48682010-10-19 23:57:56 +020089 },
90 .probe = wm831x_i2c_probe,
91 .remove = wm831x_i2c_remove,
Mark Browne5b48682010-10-19 23:57:56 +020092 .id_table = wm831x_i2c_id,
93};
94
95static int __init wm831x_i2c_init(void)
96{
97 int ret;
98
99 ret = i2c_add_driver(&wm831x_i2c_driver);
100 if (ret != 0)
101 pr_err("Failed to register wm831x I2C driver: %d\n", ret);
102
103 return ret;
104}
105subsys_initcall(wm831x_i2c_init);
106
107static void __exit wm831x_i2c_exit(void)
108{
109 i2c_del_driver(&wm831x_i2c_driver);
110}
111module_exit(wm831x_i2c_exit);