]>
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> | |
af5db808 | 16 | #include <linux/init.h> |
e5b48684 MB |
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 |
29 | static 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); | |
800e5455 GS |
40 | if (!of_id) { |
41 | dev_err(&i2c->dev, "Failed to match device\n"); | |
42 | return -ENODEV; | |
43 | } | |
f6dd8449 CK |
44 | type = (enum wm831x_parent)of_id->data; |
45 | } else { | |
46 | type = (enum wm831x_parent)id->driver_data; | |
47 | } | |
48 | ||
d48cbb74 | 49 | wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL); |
e5b48684 MB |
50 | if (wm831x == NULL) |
51 | return -ENOMEM; | |
52 | ||
53 | i2c_set_clientdata(i2c, wm831x); | |
54 | wm831x->dev = &i2c->dev; | |
f6dd8449 | 55 | wm831x->type = type; |
1df5981b | 56 | |
130a7032 | 57 | wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config); |
1df5981b MB |
58 | if (IS_ERR(wm831x->regmap)) { |
59 | ret = PTR_ERR(wm831x->regmap); | |
60 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", | |
61 | ret); | |
1df5981b MB |
62 | return ret; |
63 | } | |
e5b48684 | 64 | |
f6dd8449 CK |
65 | if (pdata) |
66 | memcpy(&wm831x->pdata, pdata, sizeof(*pdata)); | |
67 | ||
68 | return wm831x_device_init(wm831x, i2c->irq); | |
e5b48684 MB |
69 | } |
70 | ||
c538ddbe | 71 | static int wm831x_i2c_suspend(struct device *dev) |
e5b48684 | 72 | { |
c538ddbe | 73 | struct wm831x *wm831x = dev_get_drvdata(dev); |
e5b48684 MB |
74 | |
75 | return wm831x_device_suspend(wm831x); | |
76 | } | |
77 | ||
b9736a16 | 78 | static int wm831x_i2c_poweroff(struct device *dev) |
523d9cfb | 79 | { |
b9736a16 | 80 | struct wm831x *wm831x = dev_get_drvdata(dev); |
523d9cfb MB |
81 | |
82 | wm831x_device_shutdown(wm831x); | |
b9736a16 MB |
83 | |
84 | return 0; | |
523d9cfb MB |
85 | } |
86 | ||
e5b48684 MB |
87 | static const struct i2c_device_id wm831x_i2c_id[] = { |
88 | { "wm8310", WM8310 }, | |
89 | { "wm8311", WM8311 }, | |
90 | { "wm8312", WM8312 }, | |
91 | { "wm8320", WM8320 }, | |
92 | { "wm8321", WM8321 }, | |
93 | { "wm8325", WM8325 }, | |
412dc11d | 94 | { "wm8326", WM8326 }, |
e5b48684 MB |
95 | { } |
96 | }; | |
e5b48684 | 97 | |
c538ddbe MB |
98 | static const struct dev_pm_ops wm831x_pm_ops = { |
99 | .suspend = wm831x_i2c_suspend, | |
b9736a16 | 100 | .poweroff = wm831x_i2c_poweroff, |
c538ddbe | 101 | }; |
e5b48684 MB |
102 | |
103 | static struct i2c_driver wm831x_i2c_driver = { | |
104 | .driver = { | |
c538ddbe | 105 | .name = "wm831x", |
c538ddbe | 106 | .pm = &wm831x_pm_ops, |
f6dd8449 | 107 | .of_match_table = of_match_ptr(wm831x_of_match), |
af5db808 | 108 | .suppress_bind_attrs = true, |
e5b48684 MB |
109 | }, |
110 | .probe = wm831x_i2c_probe, | |
e5b48684 MB |
111 | .id_table = wm831x_i2c_id, |
112 | }; | |
113 | ||
114 | static int __init wm831x_i2c_init(void) | |
115 | { | |
116 | int ret; | |
117 | ||
118 | ret = i2c_add_driver(&wm831x_i2c_driver); | |
119 | if (ret != 0) | |
120 | pr_err("Failed to register wm831x I2C driver: %d\n", ret); | |
121 | ||
122 | return ret; | |
123 | } | |
124 | subsys_initcall(wm831x_i2c_init); |