Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wm8350-i2c.c
Go to the documentation of this file.
1 /*
2  * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
3  *
4  * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5  *
6  * Author: Liam Girdwood
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>
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/i2c.h>
21 #include <linux/platform_device.h>
22 #include <linux/mfd/wm8350/core.h>
23 #include <linux/regmap.h>
24 #include <linux/slab.h>
25 
26 static int wm8350_i2c_probe(struct i2c_client *i2c,
27  const struct i2c_device_id *id)
28 {
29  struct wm8350 *wm8350;
30  int ret = 0;
31 
32  wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
33  if (wm8350 == NULL)
34  return -ENOMEM;
35 
36  wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
37  if (IS_ERR(wm8350->regmap)) {
38  ret = PTR_ERR(wm8350->regmap);
39  dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
40  ret);
41  return ret;
42  }
43 
44  i2c_set_clientdata(i2c, wm8350);
45  wm8350->dev = &i2c->dev;
46 
47  return wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data);
48 }
49 
50 static int wm8350_i2c_remove(struct i2c_client *i2c)
51 {
52  struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
53 
54  wm8350_device_exit(wm8350);
55 
56  return 0;
57 }
58 
59 static const struct i2c_device_id wm8350_i2c_id[] = {
60  { "wm8350", 0 },
61  { "wm8351", 0 },
62  { "wm8352", 0 },
63  { }
64 };
65 MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
66 
67 
68 static struct i2c_driver wm8350_i2c_driver = {
69  .driver = {
70  .name = "wm8350",
71  .owner = THIS_MODULE,
72  },
73  .probe = wm8350_i2c_probe,
74  .remove = wm8350_i2c_remove,
75  .id_table = wm8350_i2c_id,
76 };
77 
78 static int __init wm8350_i2c_init(void)
79 {
80  return i2c_add_driver(&wm8350_i2c_driver);
81 }
82 /* init early so consumer devices can complete system boot */
83 subsys_initcall(wm8350_i2c_init);
84 
85 static void __exit wm8350_i2c_exit(void)
86 {
87  i2c_del_driver(&wm8350_i2c_driver);
88 }
89 module_exit(wm8350_i2c_exit);
90 
91 MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
92 MODULE_LICENSE("GPL");