blob: f919def05e24778e53678385075b6fef440e1cf7 [file] [log] [blame]
Mark Brownc661a0b2008-10-10 15:58:11 +01001/*
2 * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
3 *
Mark Brownc661a0b2008-10-10 15:58:11 +01004 * 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 Brownb7b142d2012-05-07 10:03:21 +010018#include <linux/err.h>
Mark Brownc661a0b2008-10-10 15:58:11 +010019#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/platform_device.h>
22#include <linux/mfd/wm8350/core.h>
Mark Brownb7b142d2012-05-07 10:03:21 +010023#include <linux/regmap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Mark Brownc661a0b2008-10-10 15:58:11 +010025
Mark Brownc661a0b2008-10-10 15:58:11 +010026static int wm8350_i2c_probe(struct i2c_client *i2c,
27 const struct i2c_device_id *id)
28{
29 struct wm8350 *wm8350;
Jingoo Han334a41c2013-07-30 17:10:05 +090030 struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev);
Mark Brownc661a0b2008-10-10 15:58:11 +010031 int ret = 0;
32
Mark Brown55ee29d2011-12-08 10:55:22 +080033 wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
Rabin Vincente47a3bb2010-04-21 21:06:05 +053034 if (wm8350 == NULL)
Mark Brownc661a0b2008-10-10 15:58:11 +010035 return -ENOMEM;
Mark Brownc661a0b2008-10-10 15:58:11 +010036
Mark Brownb7b142d2012-05-07 10:03:21 +010037 wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
38 if (IS_ERR(wm8350->regmap)) {
39 ret = PTR_ERR(wm8350->regmap);
40 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
41 ret);
42 return ret;
43 }
44
Mark Brownc661a0b2008-10-10 15:58:11 +010045 i2c_set_clientdata(i2c, wm8350);
46 wm8350->dev = &i2c->dev;
Mark Brownc661a0b2008-10-10 15:58:11 +010047
Jingoo Han334a41c2013-07-30 17:10:05 +090048 return wm8350_device_init(wm8350, i2c->irq, pdata);
Mark Brownc661a0b2008-10-10 15:58:11 +010049}
50
51static int wm8350_i2c_remove(struct i2c_client *i2c)
52{
53 struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
54
55 wm8350_device_exit(wm8350);
Mark Brownc661a0b2008-10-10 15:58:11 +010056
57 return 0;
58}
59
60static const struct i2c_device_id wm8350_i2c_id[] = {
61 { "wm8350", 0 },
Mark Brownca23f8c2008-12-18 23:12:28 +010062 { "wm8351", 0 },
Mark Brown96920632008-12-18 23:09:50 +010063 { "wm8352", 0 },
Mark Brownc661a0b2008-10-10 15:58:11 +010064 { }
65};
66MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
67
68
69static struct i2c_driver wm8350_i2c_driver = {
70 .driver = {
71 .name = "wm8350",
72 .owner = THIS_MODULE,
73 },
74 .probe = wm8350_i2c_probe,
75 .remove = wm8350_i2c_remove,
76 .id_table = wm8350_i2c_id,
77};
78
79static int __init wm8350_i2c_init(void)
80{
81 return i2c_add_driver(&wm8350_i2c_driver);
82}
83/* init early so consumer devices can complete system boot */
84subsys_initcall(wm8350_i2c_init);
85
86static void __exit wm8350_i2c_exit(void)
87{
88 i2c_del_driver(&wm8350_i2c_driver);
89}
90module_exit(wm8350_i2c_exit);
91
92MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
93MODULE_LICENSE("GPL");