Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 2 | /* |
| 3 | * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC |
| 4 | * |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 5 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
| 6 | * |
| 7 | * Author: Liam Girdwood |
| 8 | * linux@wolfsonmicro.com |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 11 | #include <linux/err.h> |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/i2c.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/mfd/wm8350/core.h> |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 16 | #include <linux/regmap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 18 | |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 19 | static int wm8350_i2c_probe(struct i2c_client *i2c, |
| 20 | const struct i2c_device_id *id) |
| 21 | { |
| 22 | struct wm8350 *wm8350; |
Jingoo Han | 334a41ce | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 23 | struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev); |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 24 | int ret = 0; |
| 25 | |
Mark Brown | 55ee29d | 2011-12-08 10:55:22 +0800 | [diff] [blame] | 26 | wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL); |
Rabin Vincent | e47a3bb | 2010-04-21 21:06:05 +0530 | [diff] [blame] | 27 | if (wm8350 == NULL) |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 28 | return -ENOMEM; |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 29 | |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 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 | |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 38 | i2c_set_clientdata(i2c, wm8350); |
| 39 | wm8350->dev = &i2c->dev; |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 40 | |
Jingoo Han | 334a41ce | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 41 | return wm8350_device_init(wm8350, i2c->irq, pdata); |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 44 | static const struct i2c_device_id wm8350_i2c_id[] = { |
Lee Jones | 6db1c9b | 2014-07-21 15:04:10 +0100 | [diff] [blame] | 45 | { "wm8350", 0 }, |
| 46 | { "wm8351", 0 }, |
| 47 | { "wm8352", 0 }, |
| 48 | { } |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 49 | }; |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 50 | |
| 51 | static struct i2c_driver wm8350_i2c_driver = { |
| 52 | .driver = { |
| 53 | .name = "wm8350", |
Paul Gortmaker | fc64306 | 2019-01-13 13:36:47 -0500 | [diff] [blame] | 54 | .suppress_bind_attrs = true, |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 55 | }, |
| 56 | .probe = wm8350_i2c_probe, |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 57 | .id_table = wm8350_i2c_id, |
| 58 | }; |
| 59 | |
| 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); |