Blame view
drivers/mfd/wm831x-i2c.c
2.64 KB
2874c5fd2
|
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
e5b486841
|
2 3 4 5 6 7 |
/* * wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs * * Copyright 2009,2010 Wolfson Microelectronics PLC. * * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
e5b486841
|
8 9 10 |
*/ #include <linux/kernel.h> |
af5db808a
|
11 |
#include <linux/init.h> |
e5b486841
|
12 13 14 15 |
#include <linux/i2c.h> #include <linux/delay.h> #include <linux/mfd/core.h> #include <linux/slab.h> |
1df5981b8
|
16 |
#include <linux/err.h> |
f6dd8449c
|
17 18 |
#include <linux/of.h> #include <linux/of_device.h> |
1df5981b8
|
19 |
#include <linux/regmap.h> |
e5b486841
|
20 21 22 |
#include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/pdata.h> |
e5b486841
|
23 24 25 |
static int wm831x_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { |
f6dd8449c
|
26 27 |
struct wm831x_pdata *pdata = dev_get_platdata(&i2c->dev); const struct of_device_id *of_id; |
e5b486841
|
28 |
struct wm831x *wm831x; |
f6dd8449c
|
29 |
enum wm831x_parent type; |
1df5981b8
|
30 |
int ret; |
e5b486841
|
31 |
|
f6dd8449c
|
32 33 |
if (i2c->dev.of_node) { of_id = of_match_device(wm831x_of_match, &i2c->dev); |
800e54558
|
34 35 36 37 38 |
if (!of_id) { dev_err(&i2c->dev, "Failed to match device "); return -ENODEV; } |
f6dd8449c
|
39 40 41 42 |
type = (enum wm831x_parent)of_id->data; } else { type = (enum wm831x_parent)id->driver_data; } |
d48cbb743
|
43 |
wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL); |
e5b486841
|
44 45 46 47 48 |
if (wm831x == NULL) return -ENOMEM; i2c_set_clientdata(i2c, wm831x); wm831x->dev = &i2c->dev; |
f6dd8449c
|
49 |
wm831x->type = type; |
1df5981b8
|
50 |
|
130a70323
|
51 |
wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config); |
1df5981b8
|
52 53 54 55 56 |
if (IS_ERR(wm831x->regmap)) { ret = PTR_ERR(wm831x->regmap); dev_err(wm831x->dev, "Failed to allocate register map: %d ", ret); |
1df5981b8
|
57 58 |
return ret; } |
e5b486841
|
59 |
|
f6dd8449c
|
60 61 62 63 |
if (pdata) memcpy(&wm831x->pdata, pdata, sizeof(*pdata)); return wm831x_device_init(wm831x, i2c->irq); |
e5b486841
|
64 |
} |
c538ddbe4
|
65 |
static int wm831x_i2c_suspend(struct device *dev) |
e5b486841
|
66 |
{ |
c538ddbe4
|
67 |
struct wm831x *wm831x = dev_get_drvdata(dev); |
e5b486841
|
68 69 70 |
return wm831x_device_suspend(wm831x); } |
b9736a16a
|
71 |
static int wm831x_i2c_poweroff(struct device *dev) |
523d9cfbb
|
72 |
{ |
b9736a16a
|
73 |
struct wm831x *wm831x = dev_get_drvdata(dev); |
523d9cfbb
|
74 75 |
wm831x_device_shutdown(wm831x); |
b9736a16a
|
76 77 |
return 0; |
523d9cfbb
|
78 |
} |
e5b486841
|
79 80 81 82 83 84 85 |
static const struct i2c_device_id wm831x_i2c_id[] = { { "wm8310", WM8310 }, { "wm8311", WM8311 }, { "wm8312", WM8312 }, { "wm8320", WM8320 }, { "wm8321", WM8321 }, { "wm8325", WM8325 }, |
412dc11d3
|
86 |
{ "wm8326", WM8326 }, |
e5b486841
|
87 88 |
{ } }; |
e5b486841
|
89 |
|
c538ddbe4
|
90 91 |
static const struct dev_pm_ops wm831x_pm_ops = { .suspend = wm831x_i2c_suspend, |
b9736a16a
|
92 |
.poweroff = wm831x_i2c_poweroff, |
c538ddbe4
|
93 |
}; |
e5b486841
|
94 95 96 |
static struct i2c_driver wm831x_i2c_driver = { .driver = { |
c538ddbe4
|
97 |
.name = "wm831x", |
c538ddbe4
|
98 |
.pm = &wm831x_pm_ops, |
f6dd8449c
|
99 |
.of_match_table = of_match_ptr(wm831x_of_match), |
af5db808a
|
100 |
.suppress_bind_attrs = true, |
e5b486841
|
101 102 |
}, .probe = wm831x_i2c_probe, |
e5b486841
|
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
.id_table = wm831x_i2c_id, }; static int __init wm831x_i2c_init(void) { int ret; ret = i2c_add_driver(&wm831x_i2c_driver); if (ret != 0) pr_err("Failed to register wm831x I2C driver: %d ", ret); return ret; } subsys_initcall(wm831x_i2c_init); |