Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC |
| 3 | * |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
| 5 | * |
| 6 | * Author: Liam Girdwood |
| 7 | * linux@wolfsonmicro.com |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/moduleparam.h> |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 18 | #include <linux/err.h> |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/i2c.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/mfd/wm8350/core.h> |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 23 | #include <linux/regmap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 25 | |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 26 | static const struct regmap_config wm8350_regmap = { |
| 27 | .reg_bits = 8, |
| 28 | .val_bits = 16, |
| 29 | }; |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 30 | |
| 31 | static int wm8350_i2c_probe(struct i2c_client *i2c, |
| 32 | const struct i2c_device_id *id) |
| 33 | { |
| 34 | struct wm8350 *wm8350; |
| 35 | int ret = 0; |
| 36 | |
Mark Brown | 55ee29d | 2011-12-08 10:55:22 +0800 | [diff] [blame] | 37 | wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL); |
Rabin Vincent | e47a3bb | 2010-04-21 21:06:05 +0530 | [diff] [blame] | 38 | if (wm8350 == NULL) |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 39 | return -ENOMEM; |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 40 | |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 41 | wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap); |
| 42 | if (IS_ERR(wm8350->regmap)) { |
| 43 | ret = PTR_ERR(wm8350->regmap); |
| 44 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
| 45 | ret); |
| 46 | return ret; |
| 47 | } |
| 48 | |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 49 | i2c_set_clientdata(i2c, wm8350); |
| 50 | wm8350->dev = &i2c->dev; |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 51 | |
Johan Hovold | 65ee362 | 2012-05-15 19:45:40 +0200 | [diff] [blame] | 52 | return wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data); |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static int wm8350_i2c_remove(struct i2c_client *i2c) |
| 56 | { |
| 57 | struct wm8350 *wm8350 = i2c_get_clientdata(i2c); |
| 58 | |
| 59 | wm8350_device_exit(wm8350); |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static const struct i2c_device_id wm8350_i2c_id[] = { |
| 65 | { "wm8350", 0 }, |
Mark Brown | ca23f8c | 2008-12-18 23:12:28 +0100 | [diff] [blame] | 66 | { "wm8351", 0 }, |
Mark Brown | 9692063 | 2008-12-18 23:09:50 +0100 | [diff] [blame] | 67 | { "wm8352", 0 }, |
Mark Brown | c661a0b | 2008-10-10 15:58:11 +0100 | [diff] [blame] | 68 | { } |
| 69 | }; |
| 70 | MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id); |
| 71 | |
| 72 | |
| 73 | static struct i2c_driver wm8350_i2c_driver = { |
| 74 | .driver = { |
| 75 | .name = "wm8350", |
| 76 | .owner = THIS_MODULE, |
| 77 | }, |
| 78 | .probe = wm8350_i2c_probe, |
| 79 | .remove = wm8350_i2c_remove, |
| 80 | .id_table = wm8350_i2c_id, |
| 81 | }; |
| 82 | |
| 83 | static int __init wm8350_i2c_init(void) |
| 84 | { |
| 85 | return i2c_add_driver(&wm8350_i2c_driver); |
| 86 | } |
| 87 | /* init early so consumer devices can complete system boot */ |
| 88 | subsys_initcall(wm8350_i2c_init); |
| 89 | |
| 90 | static void __exit wm8350_i2c_exit(void) |
| 91 | { |
| 92 | i2c_del_driver(&wm8350_i2c_driver); |
| 93 | } |
| 94 | module_exit(wm8350_i2c_exit); |
| 95 | |
| 96 | MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC"); |
| 97 | MODULE_LICENSE("GPL"); |