diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2008-10-10 10:58:11 -0400 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2008-10-13 16:51:55 -0400 |
commit | c661a0b92d487ac20cc9cddbb8f4d40e4dcdbec1 (patch) | |
tree | 9970f064cceac8a7cbe7b265305c49412a1e13a5 /drivers/mfd | |
parent | 89b4012befb1abca5e86d232bc0e2a797b0d9825 (diff) |
mfd: Add I2C control support for WM8350
Implement the I2C control interface for the WM8350. This code was
originally written by Liam Girdwood and has been updated for submission
by Mark Brown.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Samuel Ortiz <sameo@openedhand.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/Kconfig | 11 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 1 | ||||
-rw-r--r-- | drivers/mfd/wm8350-i2c.c | 120 |
3 files changed, 132 insertions, 0 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 5d7bbf45cae0..5eff8ad834d6 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -114,6 +114,17 @@ config MFD_WM8350_CONFIG_MODE_3 | |||
114 | bool | 114 | bool |
115 | depends on MFD_WM8350 | 115 | depends on MFD_WM8350 |
116 | 116 | ||
117 | config MFD_WM8350_I2C | ||
118 | tristate "Support Wolfson Microelectronics WM8350 with I2C" | ||
119 | select MFD_WM8350 | ||
120 | depends on I2C | ||
121 | help | ||
122 | The WM8350 is an integrated audio and power management | ||
123 | subsystem with watchdog and RTC functionality for embedded | ||
124 | systems. This option enables core support for the WM8350 with | ||
125 | I2C as the control interface. Additional options must be | ||
126 | selected to enable support for the functionality of the chip. | ||
127 | |||
117 | endmenu | 128 | endmenu |
118 | 129 | ||
119 | menu "Multimedia Capabilities Port drivers" | 130 | menu "Multimedia Capabilities Port drivers" |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index bec1e92d37ba..45038aed2d31 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -15,6 +15,7 @@ obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o | |||
15 | obj-$(CONFIG_MFD_WM8400) += wm8400-core.o | 15 | obj-$(CONFIG_MFD_WM8400) += wm8400-core.o |
16 | wm8350-objs := wm8350-core.o wm8350-regmap.o | 16 | wm8350-objs := wm8350-core.o wm8350-regmap.o |
17 | obj-$(CONFIG_MFD_WM8350) += wm8350.o | 17 | obj-$(CONFIG_MFD_WM8350) += wm8350.o |
18 | obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o | ||
18 | 19 | ||
19 | obj-$(CONFIG_MFD_CORE) += mfd-core.o | 20 | obj-$(CONFIG_MFD_CORE) += mfd-core.o |
20 | 21 | ||
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c new file mode 100644 index 000000000000..2b0569cf9512 --- /dev/null +++ b/drivers/mfd/wm8350-i2c.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC | ||
3 | * | ||
4 | * This driver defines and configures the WM8350 for the Freescale i.MX32ADS. | ||
5 | * | ||
6 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
7 | * | ||
8 | * Author: Liam Girdwood | ||
9 | * linux@wolfsonmicro.com | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the | ||
13 | * Free Software Foundation; either version 2 of the License, or (at your | ||
14 | * option) any later version. | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/moduleparam.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/mfd/wm8350/core.h> | ||
24 | |||
25 | static int wm8350_i2c_read_device(struct wm8350 *wm8350, char reg, | ||
26 | int bytes, void *dest) | ||
27 | { | ||
28 | int ret; | ||
29 | |||
30 | ret = i2c_master_send(wm8350->i2c_client, ®, 1); | ||
31 | if (ret < 0) | ||
32 | return ret; | ||
33 | return i2c_master_recv(wm8350->i2c_client, dest, bytes); | ||
34 | } | ||
35 | |||
36 | static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg, | ||
37 | int bytes, void *src) | ||
38 | { | ||
39 | /* we add 1 byte for device register */ | ||
40 | u8 msg[(WM8350_MAX_REGISTER << 1) + 1]; | ||
41 | |||
42 | if (bytes > ((WM8350_MAX_REGISTER << 1) + 1)) | ||
43 | return -EINVAL; | ||
44 | |||
45 | msg[0] = reg; | ||
46 | memcpy(&msg[1], src, bytes); | ||
47 | return i2c_master_send(wm8350->i2c_client, msg, bytes + 1); | ||
48 | } | ||
49 | |||
50 | static int wm8350_i2c_probe(struct i2c_client *i2c, | ||
51 | const struct i2c_device_id *id) | ||
52 | { | ||
53 | struct wm8350 *wm8350; | ||
54 | int ret = 0; | ||
55 | |||
56 | wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL); | ||
57 | if (wm8350 == NULL) { | ||
58 | kfree(i2c); | ||
59 | return -ENOMEM; | ||
60 | } | ||
61 | |||
62 | i2c_set_clientdata(i2c, wm8350); | ||
63 | wm8350->dev = &i2c->dev; | ||
64 | wm8350->i2c_client = i2c; | ||
65 | wm8350->read_dev = wm8350_i2c_read_device; | ||
66 | wm8350->write_dev = wm8350_i2c_write_device; | ||
67 | |||
68 | ret = wm8350_device_init(wm8350); | ||
69 | if (ret < 0) | ||
70 | goto err; | ||
71 | |||
72 | return ret; | ||
73 | |||
74 | err: | ||
75 | kfree(wm8350); | ||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | static int wm8350_i2c_remove(struct i2c_client *i2c) | ||
80 | { | ||
81 | struct wm8350 *wm8350 = i2c_get_clientdata(i2c); | ||
82 | |||
83 | wm8350_device_exit(wm8350); | ||
84 | kfree(wm8350); | ||
85 | |||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static const struct i2c_device_id wm8350_i2c_id[] = { | ||
90 | { "wm8350", 0 }, | ||
91 | { } | ||
92 | }; | ||
93 | MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id); | ||
94 | |||
95 | |||
96 | static struct i2c_driver wm8350_i2c_driver = { | ||
97 | .driver = { | ||
98 | .name = "wm8350", | ||
99 | .owner = THIS_MODULE, | ||
100 | }, | ||
101 | .probe = wm8350_i2c_probe, | ||
102 | .remove = wm8350_i2c_remove, | ||
103 | .id_table = wm8350_i2c_id, | ||
104 | }; | ||
105 | |||
106 | static int __init wm8350_i2c_init(void) | ||
107 | { | ||
108 | return i2c_add_driver(&wm8350_i2c_driver); | ||
109 | } | ||
110 | /* init early so consumer devices can complete system boot */ | ||
111 | subsys_initcall(wm8350_i2c_init); | ||
112 | |||
113 | static void __exit wm8350_i2c_exit(void) | ||
114 | { | ||
115 | i2c_del_driver(&wm8350_i2c_driver); | ||
116 | } | ||
117 | module_exit(wm8350_i2c_exit); | ||
118 | |||
119 | MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC"); | ||
120 | MODULE_LICENSE("GPL"); | ||