Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs |
| 3 | * |
| 4 | * Copyright 2009,2010 Wolfson Microelectronics PLC. |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/i2c.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/mfd/core.h> |
| 20 | #include <linux/slab.h> |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 21 | #include <linux/err.h> |
| 22 | #include <linux/regmap.h> |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 23 | |
| 24 | #include <linux/mfd/wm831x/core.h> |
| 25 | #include <linux/mfd/wm831x/pdata.h> |
| 26 | |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 27 | static int wm831x_i2c_probe(struct i2c_client *i2c, |
| 28 | const struct i2c_device_id *id) |
| 29 | { |
| 30 | struct wm831x *wm831x; |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 31 | int ret; |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 32 | |
| 33 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); |
| 34 | if (wm831x == NULL) |
| 35 | return -ENOMEM; |
| 36 | |
| 37 | i2c_set_clientdata(i2c, wm831x); |
| 38 | wm831x->dev = &i2c->dev; |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 39 | |
| 40 | wm831x->regmap = regmap_init_i2c(i2c, &wm831x_regmap_config); |
| 41 | if (IS_ERR(wm831x->regmap)) { |
| 42 | ret = PTR_ERR(wm831x->regmap); |
| 43 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", |
| 44 | ret); |
| 45 | kfree(wm831x); |
| 46 | return ret; |
| 47 | } |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 48 | |
| 49 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); |
| 50 | } |
| 51 | |
| 52 | static int wm831x_i2c_remove(struct i2c_client *i2c) |
| 53 | { |
| 54 | struct wm831x *wm831x = i2c_get_clientdata(i2c); |
| 55 | |
| 56 | wm831x_device_exit(wm831x); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Mark Brown | c538ddb | 2011-01-05 15:12:39 +0000 | [diff] [blame] | 61 | static int wm831x_i2c_suspend(struct device *dev) |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 62 | { |
Mark Brown | c538ddb | 2011-01-05 15:12:39 +0000 | [diff] [blame] | 63 | struct wm831x *wm831x = dev_get_drvdata(dev); |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 64 | |
| 65 | return wm831x_device_suspend(wm831x); |
| 66 | } |
| 67 | |
Mark Brown | 523d9cf | 2011-09-15 18:54:53 +0200 | [diff] [blame] | 68 | static void wm831x_i2c_shutdown(struct i2c_client *i2c) |
| 69 | { |
| 70 | struct wm831x *wm831x = i2c_get_clientdata(i2c); |
| 71 | |
| 72 | wm831x_device_shutdown(wm831x); |
| 73 | } |
| 74 | |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 75 | static const struct i2c_device_id wm831x_i2c_id[] = { |
| 76 | { "wm8310", WM8310 }, |
| 77 | { "wm8311", WM8311 }, |
| 78 | { "wm8312", WM8312 }, |
| 79 | { "wm8320", WM8320 }, |
| 80 | { "wm8321", WM8321 }, |
| 81 | { "wm8325", WM8325 }, |
Mark Brown | 412dc11 | 2010-11-24 18:01:41 +0000 | [diff] [blame] | 82 | { "wm8326", WM8326 }, |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 83 | { } |
| 84 | }; |
| 85 | MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); |
| 86 | |
Mark Brown | c538ddb | 2011-01-05 15:12:39 +0000 | [diff] [blame] | 87 | static const struct dev_pm_ops wm831x_pm_ops = { |
| 88 | .suspend = wm831x_i2c_suspend, |
| 89 | }; |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 90 | |
| 91 | static struct i2c_driver wm831x_i2c_driver = { |
| 92 | .driver = { |
Mark Brown | c538ddb | 2011-01-05 15:12:39 +0000 | [diff] [blame] | 93 | .name = "wm831x", |
| 94 | .owner = THIS_MODULE, |
| 95 | .pm = &wm831x_pm_ops, |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 96 | }, |
| 97 | .probe = wm831x_i2c_probe, |
| 98 | .remove = wm831x_i2c_remove, |
Mark Brown | 523d9cf | 2011-09-15 18:54:53 +0200 | [diff] [blame] | 99 | .shutdown = wm831x_i2c_shutdown, |
Mark Brown | e5b4868 | 2010-10-19 23:57:56 +0200 | [diff] [blame] | 100 | .id_table = wm831x_i2c_id, |
| 101 | }; |
| 102 | |
| 103 | static int __init wm831x_i2c_init(void) |
| 104 | { |
| 105 | int ret; |
| 106 | |
| 107 | ret = i2c_add_driver(&wm831x_i2c_driver); |
| 108 | if (ret != 0) |
| 109 | pr_err("Failed to register wm831x I2C driver: %d\n", ret); |
| 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | subsys_initcall(wm831x_i2c_init); |
| 114 | |
| 115 | static void __exit wm831x_i2c_exit(void) |
| 116 | { |
| 117 | i2c_del_driver(&wm831x_i2c_driver); |
| 118 | } |
| 119 | module_exit(wm831x_i2c_exit); |