1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
4 *
5 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 *
7 * Author: Liam Girdwood
8 * linux@wolfsonmicro.com
9 */
10
11 #include <linux/err.h>
12 #include <linux/init.h>
13 #include <linux/i2c.h>
14 #include <linux/platform_device.h>
15 #include <linux/mfd/wm8350/core.h>
16 #include <linux/regmap.h>
17 #include <linux/slab.h>
18
wm8350_i2c_probe(struct i2c_client * i2c)19 static int wm8350_i2c_probe(struct i2c_client *i2c)
20 {
21 struct wm8350 *wm8350;
22 struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev);
23 int ret = 0;
24
25 wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
26 if (wm8350 == NULL)
27 return -ENOMEM;
28
29 wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
30 if (IS_ERR(wm8350->regmap)) {
31 ret = PTR_ERR(wm8350->regmap);
32 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
33 ret);
34 return ret;
35 }
36
37 i2c_set_clientdata(i2c, wm8350);
38 wm8350->dev = &i2c->dev;
39
40 return wm8350_device_init(wm8350, i2c->irq, pdata);
41 }
42
43 static const struct i2c_device_id wm8350_i2c_id[] = {
44 { "wm8350" },
45 { "wm8351" },
46 { "wm8352" },
47 { }
48 };
49
50 static struct i2c_driver wm8350_i2c_driver = {
51 .driver = {
52 .name = "wm8350",
53 .suppress_bind_attrs = true,
54 },
55 .probe = wm8350_i2c_probe,
56 .id_table = wm8350_i2c_id,
57 };
58
wm8350_i2c_init(void)59 static int __init wm8350_i2c_init(void)
60 {
61 return i2c_add_driver(&wm8350_i2c_driver);
62 }
63 /* init early so consumer devices can complete system boot */
64 subsys_initcall(wm8350_i2c_init);
65