2 * wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs
4 * Copyright 2009,2010 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
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>
21 #include <linux/err.h>
22 #include <linux/regmap.h>
24 #include <linux/mfd/wm831x/core.h>
25 #include <linux/mfd/wm831x/pdata.h>
27 static int wm831x_i2c_probe(struct i2c_client
*i2c
,
28 const struct i2c_device_id
*id
)
30 struct wm831x
*wm831x
;
33 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
37 i2c_set_clientdata(i2c
, wm831x
);
38 wm831x
->dev
= &i2c
->dev
;
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",
49 return wm831x_device_init(wm831x
, id
->driver_data
, i2c
->irq
);
52 static int wm831x_i2c_remove(struct i2c_client
*i2c
)
54 struct wm831x
*wm831x
= i2c_get_clientdata(i2c
);
56 wm831x_device_exit(wm831x
);
61 static int wm831x_i2c_suspend(struct device
*dev
)
63 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
65 return wm831x_device_suspend(wm831x
);
68 static void wm831x_i2c_shutdown(struct i2c_client
*i2c
)
70 struct wm831x
*wm831x
= i2c_get_clientdata(i2c
);
72 wm831x_device_shutdown(wm831x
);
75 static const struct i2c_device_id wm831x_i2c_id
[] = {
85 MODULE_DEVICE_TABLE(i2c
, wm831x_i2c_id
);
87 static const struct dev_pm_ops wm831x_pm_ops
= {
88 .suspend
= wm831x_i2c_suspend
,
91 static struct i2c_driver wm831x_i2c_driver
= {
97 .probe
= wm831x_i2c_probe
,
98 .remove
= wm831x_i2c_remove
,
99 .shutdown
= wm831x_i2c_shutdown
,
100 .id_table
= wm831x_i2c_id
,
103 static int __init
wm831x_i2c_init(void)
107 ret
= i2c_add_driver(&wm831x_i2c_driver
);
109 pr_err("Failed to register wm831x I2C driver: %d\n", ret
);
113 subsys_initcall(wm831x_i2c_init
);
115 static void __exit
wm831x_i2c_exit(void)
117 i2c_del_driver(&wm831x_i2c_driver
);
119 module_exit(wm831x_i2c_exit
);