]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/mfd/wm831x-i2c.c
drm/i915/cnp: Backlight support for CNP.
[mirror_ubuntu-artful-kernel.git] / drivers / mfd / wm831x-i2c.c
CommitLineData
e5b48684
MB
1/*
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>
1df5981b 21#include <linux/err.h>
f6dd8449
CK
22#include <linux/of.h>
23#include <linux/of_device.h>
1df5981b 24#include <linux/regmap.h>
e5b48684
MB
25
26#include <linux/mfd/wm831x/core.h>
27#include <linux/mfd/wm831x/pdata.h>
28
e5b48684
MB
29static int wm831x_i2c_probe(struct i2c_client *i2c,
30 const struct i2c_device_id *id)
31{
f6dd8449
CK
32 struct wm831x_pdata *pdata = dev_get_platdata(&i2c->dev);
33 const struct of_device_id *of_id;
e5b48684 34 struct wm831x *wm831x;
f6dd8449 35 enum wm831x_parent type;
1df5981b 36 int ret;
e5b48684 37
f6dd8449
CK
38 if (i2c->dev.of_node) {
39 of_id = of_match_device(wm831x_of_match, &i2c->dev);
40 type = (enum wm831x_parent)of_id->data;
41 } else {
42 type = (enum wm831x_parent)id->driver_data;
43 }
44
d48cbb74 45 wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
e5b48684
MB
46 if (wm831x == NULL)
47 return -ENOMEM;
48
49 i2c_set_clientdata(i2c, wm831x);
50 wm831x->dev = &i2c->dev;
f6dd8449 51 wm831x->type = type;
1df5981b 52
130a7032 53 wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
1df5981b
MB
54 if (IS_ERR(wm831x->regmap)) {
55 ret = PTR_ERR(wm831x->regmap);
56 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
57 ret);
1df5981b
MB
58 return ret;
59 }
e5b48684 60
f6dd8449
CK
61 if (pdata)
62 memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
63
64 return wm831x_device_init(wm831x, i2c->irq);
e5b48684
MB
65}
66
67static int wm831x_i2c_remove(struct i2c_client *i2c)
68{
69 struct wm831x *wm831x = i2c_get_clientdata(i2c);
70
71 wm831x_device_exit(wm831x);
72
73 return 0;
74}
75
c538ddbe 76static int wm831x_i2c_suspend(struct device *dev)
e5b48684 77{
c538ddbe 78 struct wm831x *wm831x = dev_get_drvdata(dev);
e5b48684
MB
79
80 return wm831x_device_suspend(wm831x);
81}
82
b9736a16 83static int wm831x_i2c_poweroff(struct device *dev)
523d9cfb 84{
b9736a16 85 struct wm831x *wm831x = dev_get_drvdata(dev);
523d9cfb
MB
86
87 wm831x_device_shutdown(wm831x);
b9736a16
MB
88
89 return 0;
523d9cfb
MB
90}
91
e5b48684
MB
92static const struct i2c_device_id wm831x_i2c_id[] = {
93 { "wm8310", WM8310 },
94 { "wm8311", WM8311 },
95 { "wm8312", WM8312 },
96 { "wm8320", WM8320 },
97 { "wm8321", WM8321 },
98 { "wm8325", WM8325 },
412dc11d 99 { "wm8326", WM8326 },
e5b48684
MB
100 { }
101};
102MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
103
c538ddbe
MB
104static const struct dev_pm_ops wm831x_pm_ops = {
105 .suspend = wm831x_i2c_suspend,
b9736a16 106 .poweroff = wm831x_i2c_poweroff,
c538ddbe 107};
e5b48684
MB
108
109static struct i2c_driver wm831x_i2c_driver = {
110 .driver = {
c538ddbe 111 .name = "wm831x",
c538ddbe 112 .pm = &wm831x_pm_ops,
f6dd8449 113 .of_match_table = of_match_ptr(wm831x_of_match),
e5b48684
MB
114 },
115 .probe = wm831x_i2c_probe,
116 .remove = wm831x_i2c_remove,
e5b48684
MB
117 .id_table = wm831x_i2c_id,
118};
119
120static int __init wm831x_i2c_init(void)
121{
122 int ret;
123
124 ret = i2c_add_driver(&wm831x_i2c_driver);
125 if (ret != 0)
126 pr_err("Failed to register wm831x I2C driver: %d\n", ret);
127
128 return ret;
129}
130subsys_initcall(wm831x_i2c_init);
131
132static void __exit wm831x_i2c_exit(void)
133{
134 i2c_del_driver(&wm831x_i2c_driver);
135}
136module_exit(wm831x_i2c_exit);