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,const struct i2c_device_id * id)19 static int wm8350_i2c_probe(struct i2c_client *i2c,
20 const struct i2c_device_id *id)
21 {
22 struct wm8350 *wm8350;
23 struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev);
24 int ret = 0;
25
26 wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
27 if (wm8350 == NULL)
28 return -ENOMEM;
29
30 wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
31 if (IS_ERR(wm8350->regmap)) {
32 ret = PTR_ERR(wm8350->regmap);
33 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
34 ret);
35 return ret;
36 }
37
38 i2c_set_clientdata(i2c, wm8350);
39 wm8350->dev = &i2c->dev;
40
41 return wm8350_device_init(wm8350, i2c->irq, pdata);
42 }
43
44 static const struct i2c_device_id wm8350_i2c_id[] = {
45 { "wm8350", 0 },
46 { "wm8351", 0 },
47 { "wm8352", 0 },
48 { }
49 };
50
51 static struct i2c_driver wm8350_i2c_driver = {
52 .driver = {
53 .name = "wm8350",
54 .suppress_bind_attrs = true,
55 },
56 .probe = wm8350_i2c_probe,
57 .id_table = wm8350_i2c_id,
58 };
59
wm8350_i2c_init(void)60 static int __init wm8350_i2c_init(void)
61 {
62 return i2c_add_driver(&wm8350_i2c_driver);
63 }
64 /* init early so consumer devices can complete system boot */
65 subsys_initcall(wm8350_i2c_init);
66