blob: 48fd46800c2814f8f757e68f55c307ce83fae55b [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Mark Brownc661a0b2008-10-10 15:58:11 +01002/*
3 * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
4 *
Mark Brownc661a0b2008-10-10 15:58:11 +01005 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 *
7 * Author: Liam Girdwood
8 * linux@wolfsonmicro.com
Mark Brownc661a0b2008-10-10 15:58:11 +01009 */
10
Mark Brownb7b142d2012-05-07 10:03:21 +010011#include <linux/err.h>
Mark Brownc661a0b2008-10-10 15:58:11 +010012#include <linux/init.h>
13#include <linux/i2c.h>
14#include <linux/platform_device.h>
15#include <linux/mfd/wm8350/core.h>
Mark Brownb7b142d2012-05-07 10:03:21 +010016#include <linux/regmap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Mark Brownc661a0b2008-10-10 15:58:11 +010018
Mark Brownc661a0b2008-10-10 15:58:11 +010019static int wm8350_i2c_probe(struct i2c_client *i2c,
20 const struct i2c_device_id *id)
21{
22 struct wm8350 *wm8350;
Jingoo Han334a41ce2013-07-30 17:10:05 +090023 struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev);
Mark Brownc661a0b2008-10-10 15:58:11 +010024 int ret = 0;
25
Mark Brown55ee29d2011-12-08 10:55:22 +080026 wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
Rabin Vincente47a3bb2010-04-21 21:06:05 +053027 if (wm8350 == NULL)
Mark Brownc661a0b2008-10-10 15:58:11 +010028 return -ENOMEM;
Mark Brownc661a0b2008-10-10 15:58:11 +010029
Mark Brownb7b142d2012-05-07 10:03:21 +010030 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
Mark Brownc661a0b2008-10-10 15:58:11 +010038 i2c_set_clientdata(i2c, wm8350);
39 wm8350->dev = &i2c->dev;
Mark Brownc661a0b2008-10-10 15:58:11 +010040
Jingoo Han334a41ce2013-07-30 17:10:05 +090041 return wm8350_device_init(wm8350, i2c->irq, pdata);
Mark Brownc661a0b2008-10-10 15:58:11 +010042}
43
Mark Brownc661a0b2008-10-10 15:58:11 +010044static const struct i2c_device_id wm8350_i2c_id[] = {
Lee Jones6db1c9b2014-07-21 15:04:10 +010045 { "wm8350", 0 },
46 { "wm8351", 0 },
47 { "wm8352", 0 },
48 { }
Mark Brownc661a0b2008-10-10 15:58:11 +010049};
Mark Brownc661a0b2008-10-10 15:58:11 +010050
51static struct i2c_driver wm8350_i2c_driver = {
52 .driver = {
53 .name = "wm8350",
Paul Gortmakerfc643062019-01-13 13:36:47 -050054 .suppress_bind_attrs = true,
Mark Brownc661a0b2008-10-10 15:58:11 +010055 },
56 .probe = wm8350_i2c_probe,
Mark Brownc661a0b2008-10-10 15:58:11 +010057 .id_table = wm8350_i2c_id,
58};
59
60static 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 */
65subsys_initcall(wm8350_i2c_init);