Commit | Line | Data |
---|---|---|
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 MB |
21 | #include <linux/err.h> |
22 | #include <linux/regmap.h> | |
e5b48684 MB |
23 | |
24 | #include <linux/mfd/wm831x/core.h> | |
25 | #include <linux/mfd/wm831x/pdata.h> | |
26 | ||
e5b48684 MB |
27 | static int wm831x_i2c_probe(struct i2c_client *i2c, |
28 | const struct i2c_device_id *id) | |
29 | { | |
30 | struct wm831x *wm831x; | |
1df5981b | 31 | int ret; |
e5b48684 | 32 | |
d48cbb74 | 33 | wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL); |
e5b48684 MB |
34 | if (wm831x == NULL) |
35 | return -ENOMEM; | |
36 | ||
37 | i2c_set_clientdata(i2c, wm831x); | |
38 | wm831x->dev = &i2c->dev; | |
1df5981b | 39 | |
130a7032 | 40 | wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config); |
1df5981b MB |
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); | |
1df5981b MB |
45 | return ret; |
46 | } | |
e5b48684 MB |
47 | |
48 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); | |
49 | } | |
50 | ||
51 | static int wm831x_i2c_remove(struct i2c_client *i2c) | |
52 | { | |
53 | struct wm831x *wm831x = i2c_get_clientdata(i2c); | |
54 | ||
55 | wm831x_device_exit(wm831x); | |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
c538ddbe | 60 | static int wm831x_i2c_suspend(struct device *dev) |
e5b48684 | 61 | { |
c538ddbe | 62 | struct wm831x *wm831x = dev_get_drvdata(dev); |
e5b48684 MB |
63 | |
64 | return wm831x_device_suspend(wm831x); | |
65 | } | |
66 | ||
b9736a16 | 67 | static int wm831x_i2c_poweroff(struct device *dev) |
523d9cfb | 68 | { |
b9736a16 | 69 | struct wm831x *wm831x = dev_get_drvdata(dev); |
523d9cfb MB |
70 | |
71 | wm831x_device_shutdown(wm831x); | |
b9736a16 MB |
72 | |
73 | return 0; | |
523d9cfb MB |
74 | } |
75 | ||
e5b48684 MB |
76 | static const struct i2c_device_id wm831x_i2c_id[] = { |
77 | { "wm8310", WM8310 }, | |
78 | { "wm8311", WM8311 }, | |
79 | { "wm8312", WM8312 }, | |
80 | { "wm8320", WM8320 }, | |
81 | { "wm8321", WM8321 }, | |
82 | { "wm8325", WM8325 }, | |
412dc11d | 83 | { "wm8326", WM8326 }, |
e5b48684 MB |
84 | { } |
85 | }; | |
86 | MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); | |
87 | ||
c538ddbe MB |
88 | static const struct dev_pm_ops wm831x_pm_ops = { |
89 | .suspend = wm831x_i2c_suspend, | |
b9736a16 | 90 | .poweroff = wm831x_i2c_poweroff, |
c538ddbe | 91 | }; |
e5b48684 MB |
92 | |
93 | static struct i2c_driver wm831x_i2c_driver = { | |
94 | .driver = { | |
c538ddbe MB |
95 | .name = "wm831x", |
96 | .owner = THIS_MODULE, | |
97 | .pm = &wm831x_pm_ops, | |
e5b48684 MB |
98 | }, |
99 | .probe = wm831x_i2c_probe, | |
100 | .remove = wm831x_i2c_remove, | |
e5b48684 MB |
101 | .id_table = wm831x_i2c_id, |
102 | }; | |
103 | ||
104 | static int __init wm831x_i2c_init(void) | |
105 | { | |
106 | int ret; | |
107 | ||
108 | ret = i2c_add_driver(&wm831x_i2c_driver); | |
109 | if (ret != 0) | |
110 | pr_err("Failed to register wm831x I2C driver: %d\n", ret); | |
111 | ||
112 | return ret; | |
113 | } | |
114 | subsys_initcall(wm831x_i2c_init); | |
115 | ||
116 | static void __exit wm831x_i2c_exit(void) | |
117 | { | |
118 | i2c_del_driver(&wm831x_i2c_driver); | |
119 | } | |
120 | module_exit(wm831x_i2c_exit); |