diff options
-rw-r--r-- | drivers/mfd/88pm8607.c | 302 | ||||
-rw-r--r-- | drivers/mfd/88pm860x-core.c | 134 | ||||
-rw-r--r-- | drivers/mfd/88pm860x-i2c.c | 202 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 2 | ||||
-rw-r--r-- | include/linux/mfd/88pm8607.h | 12 |
5 files changed, 346 insertions, 306 deletions
diff --git a/drivers/mfd/88pm8607.c b/drivers/mfd/88pm8607.c deleted file mode 100644 index 7e3f65907993..000000000000 --- a/drivers/mfd/88pm8607.c +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | * Base driver for Marvell 88PM8607 | ||
3 | * | ||
4 | * Copyright (C) 2009 Marvell International Ltd. | ||
5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/mfd/core.h> | ||
18 | #include <linux/mfd/88pm8607.h> | ||
19 | |||
20 | |||
21 | #define PM8607_REG_RESOURCE(_start, _end) \ | ||
22 | { \ | ||
23 | .start = PM8607_##_start, \ | ||
24 | .end = PM8607_##_end, \ | ||
25 | .flags = IORESOURCE_IO, \ | ||
26 | } | ||
27 | |||
28 | static struct resource pm8607_regulator_resources[] = { | ||
29 | PM8607_REG_RESOURCE(BUCK1, BUCK1), | ||
30 | PM8607_REG_RESOURCE(BUCK2, BUCK2), | ||
31 | PM8607_REG_RESOURCE(BUCK3, BUCK3), | ||
32 | PM8607_REG_RESOURCE(LDO1, LDO1), | ||
33 | PM8607_REG_RESOURCE(LDO2, LDO2), | ||
34 | PM8607_REG_RESOURCE(LDO3, LDO3), | ||
35 | PM8607_REG_RESOURCE(LDO4, LDO4), | ||
36 | PM8607_REG_RESOURCE(LDO5, LDO5), | ||
37 | PM8607_REG_RESOURCE(LDO6, LDO6), | ||
38 | PM8607_REG_RESOURCE(LDO7, LDO7), | ||
39 | PM8607_REG_RESOURCE(LDO8, LDO8), | ||
40 | PM8607_REG_RESOURCE(LDO9, LDO9), | ||
41 | PM8607_REG_RESOURCE(LDO10, LDO10), | ||
42 | PM8607_REG_RESOURCE(LDO12, LDO12), | ||
43 | PM8607_REG_RESOURCE(LDO14, LDO14), | ||
44 | }; | ||
45 | |||
46 | #define PM8607_REG_DEVS(_name, _id) \ | ||
47 | { \ | ||
48 | .name = "88pm8607-" #_name, \ | ||
49 | .num_resources = 1, \ | ||
50 | .resources = &pm8607_regulator_resources[PM8607_ID_##_id], \ | ||
51 | } | ||
52 | |||
53 | static struct mfd_cell pm8607_devs[] = { | ||
54 | PM8607_REG_DEVS(buck1, BUCK1), | ||
55 | PM8607_REG_DEVS(buck2, BUCK2), | ||
56 | PM8607_REG_DEVS(buck3, BUCK3), | ||
57 | PM8607_REG_DEVS(ldo1, LDO1), | ||
58 | PM8607_REG_DEVS(ldo2, LDO2), | ||
59 | PM8607_REG_DEVS(ldo3, LDO3), | ||
60 | PM8607_REG_DEVS(ldo4, LDO4), | ||
61 | PM8607_REG_DEVS(ldo5, LDO5), | ||
62 | PM8607_REG_DEVS(ldo6, LDO6), | ||
63 | PM8607_REG_DEVS(ldo7, LDO7), | ||
64 | PM8607_REG_DEVS(ldo8, LDO8), | ||
65 | PM8607_REG_DEVS(ldo9, LDO9), | ||
66 | PM8607_REG_DEVS(ldo10, LDO10), | ||
67 | PM8607_REG_DEVS(ldo12, LDO12), | ||
68 | PM8607_REG_DEVS(ldo14, LDO14), | ||
69 | }; | ||
70 | |||
71 | static inline int pm8607_read_device(struct pm8607_chip *chip, | ||
72 | int reg, int bytes, void *dest) | ||
73 | { | ||
74 | struct i2c_client *i2c = chip->client; | ||
75 | unsigned char data; | ||
76 | int ret; | ||
77 | |||
78 | data = (unsigned char)reg; | ||
79 | ret = i2c_master_send(i2c, &data, 1); | ||
80 | if (ret < 0) | ||
81 | return ret; | ||
82 | |||
83 | ret = i2c_master_recv(i2c, dest, bytes); | ||
84 | if (ret < 0) | ||
85 | return ret; | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static inline int pm8607_write_device(struct pm8607_chip *chip, | ||
90 | int reg, int bytes, void *src) | ||
91 | { | ||
92 | struct i2c_client *i2c = chip->client; | ||
93 | unsigned char buf[bytes + 1]; | ||
94 | int ret; | ||
95 | |||
96 | buf[0] = (unsigned char)reg; | ||
97 | memcpy(&buf[1], src, bytes); | ||
98 | |||
99 | ret = i2c_master_send(i2c, buf, bytes + 1); | ||
100 | if (ret < 0) | ||
101 | return ret; | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | int pm8607_reg_read(struct pm8607_chip *chip, int reg) | ||
106 | { | ||
107 | unsigned char data; | ||
108 | int ret; | ||
109 | |||
110 | mutex_lock(&chip->io_lock); | ||
111 | ret = chip->read(chip, reg, 1, &data); | ||
112 | mutex_unlock(&chip->io_lock); | ||
113 | |||
114 | if (ret < 0) | ||
115 | return ret; | ||
116 | else | ||
117 | return (int)data; | ||
118 | } | ||
119 | EXPORT_SYMBOL(pm8607_reg_read); | ||
120 | |||
121 | int pm8607_reg_write(struct pm8607_chip *chip, int reg, | ||
122 | unsigned char data) | ||
123 | { | ||
124 | int ret; | ||
125 | |||
126 | mutex_lock(&chip->io_lock); | ||
127 | ret = chip->write(chip, reg, 1, &data); | ||
128 | mutex_unlock(&chip->io_lock); | ||
129 | |||
130 | return ret; | ||
131 | } | ||
132 | EXPORT_SYMBOL(pm8607_reg_write); | ||
133 | |||
134 | int pm8607_bulk_read(struct pm8607_chip *chip, int reg, | ||
135 | int count, unsigned char *buf) | ||
136 | { | ||
137 | int ret; | ||
138 | |||
139 | mutex_lock(&chip->io_lock); | ||
140 | ret = chip->read(chip, reg, count, buf); | ||
141 | mutex_unlock(&chip->io_lock); | ||
142 | |||
143 | return ret; | ||
144 | } | ||
145 | EXPORT_SYMBOL(pm8607_bulk_read); | ||
146 | |||
147 | int pm8607_bulk_write(struct pm8607_chip *chip, int reg, | ||
148 | int count, unsigned char *buf) | ||
149 | { | ||
150 | int ret; | ||
151 | |||
152 | mutex_lock(&chip->io_lock); | ||
153 | ret = chip->write(chip, reg, count, buf); | ||
154 | mutex_unlock(&chip->io_lock); | ||
155 | |||
156 | return ret; | ||
157 | } | ||
158 | EXPORT_SYMBOL(pm8607_bulk_write); | ||
159 | |||
160 | int pm8607_set_bits(struct pm8607_chip *chip, int reg, | ||
161 | unsigned char mask, unsigned char data) | ||
162 | { | ||
163 | unsigned char value; | ||
164 | int ret; | ||
165 | |||
166 | mutex_lock(&chip->io_lock); | ||
167 | ret = chip->read(chip, reg, 1, &value); | ||
168 | if (ret < 0) | ||
169 | goto out; | ||
170 | value &= ~mask; | ||
171 | value |= data; | ||
172 | ret = chip->write(chip, reg, 1, &value); | ||
173 | out: | ||
174 | mutex_unlock(&chip->io_lock); | ||
175 | return ret; | ||
176 | } | ||
177 | EXPORT_SYMBOL(pm8607_set_bits); | ||
178 | |||
179 | |||
180 | static const struct i2c_device_id pm8607_id_table[] = { | ||
181 | { "88PM8607", 0 }, | ||
182 | {} | ||
183 | }; | ||
184 | MODULE_DEVICE_TABLE(i2c, pm8607_id_table); | ||
185 | |||
186 | |||
187 | static int __devinit pm8607_probe(struct i2c_client *client, | ||
188 | const struct i2c_device_id *id) | ||
189 | { | ||
190 | struct pm8607_platform_data *pdata = client->dev.platform_data; | ||
191 | struct pm8607_chip *chip; | ||
192 | int i, count; | ||
193 | int ret; | ||
194 | |||
195 | chip = kzalloc(sizeof(struct pm8607_chip), GFP_KERNEL); | ||
196 | if (chip == NULL) | ||
197 | return -ENOMEM; | ||
198 | |||
199 | chip->client = client; | ||
200 | chip->dev = &client->dev; | ||
201 | chip->read = pm8607_read_device; | ||
202 | chip->write = pm8607_write_device; | ||
203 | i2c_set_clientdata(client, chip); | ||
204 | |||
205 | mutex_init(&chip->io_lock); | ||
206 | dev_set_drvdata(chip->dev, chip); | ||
207 | |||
208 | ret = pm8607_reg_read(chip, PM8607_CHIP_ID); | ||
209 | if (ret < 0) { | ||
210 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); | ||
211 | goto out; | ||
212 | } | ||
213 | if ((ret & CHIP_ID_MASK) == CHIP_ID) | ||
214 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", | ||
215 | ret); | ||
216 | else { | ||
217 | dev_err(chip->dev, "Failed to detect Marvell 88PM8607. " | ||
218 | "Chip ID: %02x\n", ret); | ||
219 | goto out; | ||
220 | } | ||
221 | chip->chip_id = ret; | ||
222 | |||
223 | ret = pm8607_reg_read(chip, PM8607_BUCK3); | ||
224 | if (ret < 0) { | ||
225 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); | ||
226 | goto out; | ||
227 | } | ||
228 | if (ret & PM8607_BUCK3_DOUBLE) | ||
229 | chip->buck3_double = 1; | ||
230 | |||
231 | ret = pm8607_reg_read(chip, PM8607_MISC1); | ||
232 | if (ret < 0) { | ||
233 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); | ||
234 | goto out; | ||
235 | } | ||
236 | if (pdata->i2c_port == PI2C_PORT) | ||
237 | ret |= PM8607_MISC1_PI2C; | ||
238 | else | ||
239 | ret &= ~PM8607_MISC1_PI2C; | ||
240 | ret = pm8607_reg_write(chip, PM8607_MISC1, ret); | ||
241 | if (ret < 0) { | ||
242 | dev_err(chip->dev, "Failed to write MISC1 register: %d\n", ret); | ||
243 | goto out; | ||
244 | } | ||
245 | |||
246 | |||
247 | count = ARRAY_SIZE(pm8607_devs); | ||
248 | for (i = 0; i < count; i++) { | ||
249 | ret = mfd_add_devices(chip->dev, i, &pm8607_devs[i], | ||
250 | 1, NULL, 0); | ||
251 | if (ret != 0) { | ||
252 | dev_err(chip->dev, "Failed to add subdevs\n"); | ||
253 | goto out; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | return 0; | ||
258 | |||
259 | out: | ||
260 | i2c_set_clientdata(client, NULL); | ||
261 | kfree(chip); | ||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | static int __devexit pm8607_remove(struct i2c_client *client) | ||
266 | { | ||
267 | struct pm8607_chip *chip = i2c_get_clientdata(client); | ||
268 | |||
269 | mfd_remove_devices(chip->dev); | ||
270 | kfree(chip); | ||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static struct i2c_driver pm8607_driver = { | ||
275 | .driver = { | ||
276 | .name = "88PM8607", | ||
277 | .owner = THIS_MODULE, | ||
278 | }, | ||
279 | .probe = pm8607_probe, | ||
280 | .remove = __devexit_p(pm8607_remove), | ||
281 | .id_table = pm8607_id_table, | ||
282 | }; | ||
283 | |||
284 | static int __init pm8607_init(void) | ||
285 | { | ||
286 | int ret; | ||
287 | ret = i2c_add_driver(&pm8607_driver); | ||
288 | if (ret != 0) | ||
289 | pr_err("Failed to register 88PM8607 I2C driver: %d\n", ret); | ||
290 | return ret; | ||
291 | } | ||
292 | subsys_initcall(pm8607_init); | ||
293 | |||
294 | static void __exit pm8607_exit(void) | ||
295 | { | ||
296 | i2c_del_driver(&pm8607_driver); | ||
297 | } | ||
298 | module_exit(pm8607_exit); | ||
299 | |||
300 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM8607"); | ||
301 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
302 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c new file mode 100644 index 000000000000..d1464e54e656 --- /dev/null +++ b/drivers/mfd/88pm860x-core.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | * Base driver for Marvell 88PM8607 | ||
3 | * | ||
4 | * Copyright (C) 2009 Marvell International Ltd. | ||
5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/mfd/core.h> | ||
17 | #include <linux/mfd/88pm8607.h> | ||
18 | |||
19 | |||
20 | #define PM8607_REG_RESOURCE(_start, _end) \ | ||
21 | { \ | ||
22 | .start = PM8607_##_start, \ | ||
23 | .end = PM8607_##_end, \ | ||
24 | .flags = IORESOURCE_IO, \ | ||
25 | } | ||
26 | |||
27 | static struct resource pm8607_regulator_resources[] = { | ||
28 | PM8607_REG_RESOURCE(BUCK1, BUCK1), | ||
29 | PM8607_REG_RESOURCE(BUCK2, BUCK2), | ||
30 | PM8607_REG_RESOURCE(BUCK3, BUCK3), | ||
31 | PM8607_REG_RESOURCE(LDO1, LDO1), | ||
32 | PM8607_REG_RESOURCE(LDO2, LDO2), | ||
33 | PM8607_REG_RESOURCE(LDO3, LDO3), | ||
34 | PM8607_REG_RESOURCE(LDO4, LDO4), | ||
35 | PM8607_REG_RESOURCE(LDO5, LDO5), | ||
36 | PM8607_REG_RESOURCE(LDO6, LDO6), | ||
37 | PM8607_REG_RESOURCE(LDO7, LDO7), | ||
38 | PM8607_REG_RESOURCE(LDO8, LDO8), | ||
39 | PM8607_REG_RESOURCE(LDO9, LDO9), | ||
40 | PM8607_REG_RESOURCE(LDO10, LDO10), | ||
41 | PM8607_REG_RESOURCE(LDO12, LDO12), | ||
42 | PM8607_REG_RESOURCE(LDO14, LDO14), | ||
43 | }; | ||
44 | |||
45 | #define PM8607_REG_DEVS(_name, _id) \ | ||
46 | { \ | ||
47 | .name = "88pm8607-" #_name, \ | ||
48 | .num_resources = 1, \ | ||
49 | .resources = &pm8607_regulator_resources[PM8607_ID_##_id], \ | ||
50 | } | ||
51 | |||
52 | static struct mfd_cell pm8607_devs[] = { | ||
53 | PM8607_REG_DEVS(buck1, BUCK1), | ||
54 | PM8607_REG_DEVS(buck2, BUCK2), | ||
55 | PM8607_REG_DEVS(buck3, BUCK3), | ||
56 | PM8607_REG_DEVS(ldo1, LDO1), | ||
57 | PM8607_REG_DEVS(ldo2, LDO2), | ||
58 | PM8607_REG_DEVS(ldo3, LDO3), | ||
59 | PM8607_REG_DEVS(ldo4, LDO4), | ||
60 | PM8607_REG_DEVS(ldo5, LDO5), | ||
61 | PM8607_REG_DEVS(ldo6, LDO6), | ||
62 | PM8607_REG_DEVS(ldo7, LDO7), | ||
63 | PM8607_REG_DEVS(ldo8, LDO8), | ||
64 | PM8607_REG_DEVS(ldo9, LDO9), | ||
65 | PM8607_REG_DEVS(ldo10, LDO10), | ||
66 | PM8607_REG_DEVS(ldo12, LDO12), | ||
67 | PM8607_REG_DEVS(ldo14, LDO14), | ||
68 | }; | ||
69 | |||
70 | int pm860x_device_init(struct pm8607_chip *chip, | ||
71 | struct pm8607_platform_data *pdata) | ||
72 | { | ||
73 | int i, count; | ||
74 | int ret; | ||
75 | |||
76 | ret = pm8607_reg_read(chip, PM8607_CHIP_ID); | ||
77 | if (ret < 0) { | ||
78 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); | ||
79 | goto out; | ||
80 | } | ||
81 | if ((ret & PM8607_ID_MASK) == PM8607_ID) | ||
82 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", | ||
83 | ret); | ||
84 | else { | ||
85 | dev_err(chip->dev, "Failed to detect Marvell 88PM8607. " | ||
86 | "Chip ID: %02x\n", ret); | ||
87 | goto out; | ||
88 | } | ||
89 | chip->chip_id = ret; | ||
90 | |||
91 | ret = pm8607_reg_read(chip, PM8607_BUCK3); | ||
92 | if (ret < 0) { | ||
93 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); | ||
94 | goto out; | ||
95 | } | ||
96 | if (ret & PM8607_BUCK3_DOUBLE) | ||
97 | chip->buck3_double = 1; | ||
98 | |||
99 | ret = pm8607_reg_read(chip, PM8607_MISC1); | ||
100 | if (ret < 0) { | ||
101 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); | ||
102 | goto out; | ||
103 | } | ||
104 | if (pdata->i2c_port == PI2C_PORT) | ||
105 | ret |= PM8607_MISC1_PI2C; | ||
106 | else | ||
107 | ret &= ~PM8607_MISC1_PI2C; | ||
108 | ret = pm8607_reg_write(chip, PM8607_MISC1, ret); | ||
109 | if (ret < 0) { | ||
110 | dev_err(chip->dev, "Failed to write MISC1 register: %d\n", ret); | ||
111 | goto out; | ||
112 | } | ||
113 | |||
114 | count = ARRAY_SIZE(pm8607_devs); | ||
115 | for (i = 0; i < count; i++) { | ||
116 | ret = mfd_add_devices(chip->dev, i, &pm8607_devs[i], | ||
117 | 1, NULL, 0); | ||
118 | if (ret != 0) { | ||
119 | dev_err(chip->dev, "Failed to add subdevs\n"); | ||
120 | goto out; | ||
121 | } | ||
122 | } | ||
123 | out: | ||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | void pm8607_device_exit(struct pm8607_chip *chip) | ||
128 | { | ||
129 | mfd_remove_devices(chip->dev); | ||
130 | } | ||
131 | |||
132 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM8607"); | ||
133 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
134 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c new file mode 100644 index 000000000000..dda23cbfe415 --- /dev/null +++ b/drivers/mfd/88pm860x-i2c.c | |||
@@ -0,0 +1,202 @@ | |||
1 | /* | ||
2 | * I2C driver for Marvell 88PM8607 | ||
3 | * | ||
4 | * Copyright (C) 2009 Marvell International Ltd. | ||
5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/i2c.h> | ||
15 | #include <linux/mfd/88pm8607.h> | ||
16 | |||
17 | static inline int pm8607_read_device(struct pm8607_chip *chip, | ||
18 | int reg, int bytes, void *dest) | ||
19 | { | ||
20 | struct i2c_client *i2c = chip->client; | ||
21 | unsigned char data; | ||
22 | int ret; | ||
23 | |||
24 | data = (unsigned char)reg; | ||
25 | ret = i2c_master_send(i2c, &data, 1); | ||
26 | if (ret < 0) | ||
27 | return ret; | ||
28 | |||
29 | ret = i2c_master_recv(i2c, dest, bytes); | ||
30 | if (ret < 0) | ||
31 | return ret; | ||
32 | return 0; | ||
33 | } | ||
34 | |||
35 | static inline int pm8607_write_device(struct pm8607_chip *chip, | ||
36 | int reg, int bytes, void *src) | ||
37 | { | ||
38 | struct i2c_client *i2c = chip->client; | ||
39 | unsigned char buf[bytes + 1]; | ||
40 | int ret; | ||
41 | |||
42 | buf[0] = (unsigned char)reg; | ||
43 | memcpy(&buf[1], src, bytes); | ||
44 | |||
45 | ret = i2c_master_send(i2c, buf, bytes + 1); | ||
46 | if (ret < 0) | ||
47 | return ret; | ||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | int pm8607_reg_read(struct pm8607_chip *chip, int reg) | ||
52 | { | ||
53 | unsigned char data; | ||
54 | int ret; | ||
55 | |||
56 | mutex_lock(&chip->io_lock); | ||
57 | ret = chip->read(chip, reg, 1, &data); | ||
58 | mutex_unlock(&chip->io_lock); | ||
59 | |||
60 | if (ret < 0) | ||
61 | return ret; | ||
62 | else | ||
63 | return (int)data; | ||
64 | } | ||
65 | EXPORT_SYMBOL(pm8607_reg_read); | ||
66 | |||
67 | int pm8607_reg_write(struct pm8607_chip *chip, int reg, | ||
68 | unsigned char data) | ||
69 | { | ||
70 | int ret; | ||
71 | |||
72 | mutex_lock(&chip->io_lock); | ||
73 | ret = chip->write(chip, reg, 1, &data); | ||
74 | mutex_unlock(&chip->io_lock); | ||
75 | |||
76 | return ret; | ||
77 | } | ||
78 | EXPORT_SYMBOL(pm8607_reg_write); | ||
79 | |||
80 | int pm8607_bulk_read(struct pm8607_chip *chip, int reg, | ||
81 | int count, unsigned char *buf) | ||
82 | { | ||
83 | int ret; | ||
84 | |||
85 | mutex_lock(&chip->io_lock); | ||
86 | ret = chip->read(chip, reg, count, buf); | ||
87 | mutex_unlock(&chip->io_lock); | ||
88 | |||
89 | return ret; | ||
90 | } | ||
91 | EXPORT_SYMBOL(pm8607_bulk_read); | ||
92 | |||
93 | int pm8607_bulk_write(struct pm8607_chip *chip, int reg, | ||
94 | int count, unsigned char *buf) | ||
95 | { | ||
96 | int ret; | ||
97 | |||
98 | mutex_lock(&chip->io_lock); | ||
99 | ret = chip->write(chip, reg, count, buf); | ||
100 | mutex_unlock(&chip->io_lock); | ||
101 | |||
102 | return ret; | ||
103 | } | ||
104 | EXPORT_SYMBOL(pm8607_bulk_write); | ||
105 | |||
106 | int pm8607_set_bits(struct pm8607_chip *chip, int reg, | ||
107 | unsigned char mask, unsigned char data) | ||
108 | { | ||
109 | unsigned char value; | ||
110 | int ret; | ||
111 | |||
112 | mutex_lock(&chip->io_lock); | ||
113 | ret = chip->read(chip, reg, 1, &value); | ||
114 | if (ret < 0) | ||
115 | goto out; | ||
116 | value &= ~mask; | ||
117 | value |= data; | ||
118 | ret = chip->write(chip, reg, 1, &value); | ||
119 | out: | ||
120 | mutex_unlock(&chip->io_lock); | ||
121 | return ret; | ||
122 | } | ||
123 | EXPORT_SYMBOL(pm8607_set_bits); | ||
124 | |||
125 | |||
126 | static const struct i2c_device_id pm860x_id_table[] = { | ||
127 | { "88PM8607", 0 }, | ||
128 | {} | ||
129 | }; | ||
130 | MODULE_DEVICE_TABLE(i2c, pm860x_id_table); | ||
131 | |||
132 | static int __devinit pm860x_probe(struct i2c_client *client, | ||
133 | const struct i2c_device_id *id) | ||
134 | { | ||
135 | struct pm8607_platform_data *pdata = client->dev.platform_data; | ||
136 | struct pm8607_chip *chip; | ||
137 | int ret; | ||
138 | |||
139 | chip = kzalloc(sizeof(struct pm8607_chip), GFP_KERNEL); | ||
140 | if (chip == NULL) | ||
141 | return -ENOMEM; | ||
142 | |||
143 | chip->client = client; | ||
144 | chip->dev = &client->dev; | ||
145 | chip->read = pm8607_read_device; | ||
146 | chip->write = pm8607_write_device; | ||
147 | memcpy(&chip->id, id, sizeof(struct i2c_device_id)); | ||
148 | i2c_set_clientdata(client, chip); | ||
149 | |||
150 | mutex_init(&chip->io_lock); | ||
151 | dev_set_drvdata(chip->dev, chip); | ||
152 | |||
153 | ret = pm860x_device_init(chip, pdata); | ||
154 | if (ret < 0) | ||
155 | goto out; | ||
156 | |||
157 | |||
158 | return 0; | ||
159 | |||
160 | out: | ||
161 | i2c_set_clientdata(client, NULL); | ||
162 | kfree(chip); | ||
163 | return ret; | ||
164 | } | ||
165 | |||
166 | static int __devexit pm860x_remove(struct i2c_client *client) | ||
167 | { | ||
168 | struct pm8607_chip *chip = i2c_get_clientdata(client); | ||
169 | |||
170 | kfree(chip); | ||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | static struct i2c_driver pm860x_driver = { | ||
175 | .driver = { | ||
176 | .name = "88PM860x", | ||
177 | .owner = THIS_MODULE, | ||
178 | }, | ||
179 | .probe = pm860x_probe, | ||
180 | .remove = __devexit_p(pm860x_remove), | ||
181 | .id_table = pm860x_id_table, | ||
182 | }; | ||
183 | |||
184 | static int __init pm860x_i2c_init(void) | ||
185 | { | ||
186 | int ret; | ||
187 | ret = i2c_add_driver(&pm860x_driver); | ||
188 | if (ret != 0) | ||
189 | pr_err("Failed to register 88PM860x I2C driver: %d\n", ret); | ||
190 | return ret; | ||
191 | } | ||
192 | subsys_initcall(pm860x_i2c_init); | ||
193 | |||
194 | static void __exit pm860x_i2c_exit(void) | ||
195 | { | ||
196 | i2c_del_driver(&pm860x_driver); | ||
197 | } | ||
198 | module_exit(pm860x_i2c_exit); | ||
199 | |||
200 | MODULE_DESCRIPTION("I2C Driver for Marvell 88PM860x"); | ||
201 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
202 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 78295d6a75f7..88fa200188cf 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -2,6 +2,7 @@ | |||
2 | # Makefile for multifunction miscellaneous devices | 2 | # Makefile for multifunction miscellaneous devices |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_MFD_88PM8607) += 88pm860x-core.o 88pm860x-i2c.o | ||
5 | obj-$(CONFIG_MFD_SM501) += sm501.o | 6 | obj-$(CONFIG_MFD_SM501) += sm501.o |
6 | obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o | 7 | obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o |
7 | obj-$(CONFIG_MFD_SH_MOBILE_SDHI) += sh_mobile_sdhi.o | 8 | obj-$(CONFIG_MFD_SH_MOBILE_SDHI) += sh_mobile_sdhi.o |
@@ -55,5 +56,4 @@ obj-$(CONFIG_AB3100_CORE) += ab3100-core.o | |||
55 | obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o | 56 | obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o |
56 | obj-$(CONFIG_AB4500_CORE) += ab4500-core.o | 57 | obj-$(CONFIG_AB4500_CORE) += ab4500-core.o |
57 | obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o | 58 | obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o |
58 | obj-$(CONFIG_MFD_88PM8607) += 88pm8607.o | ||
59 | obj-$(CONFIG_PMIC_ADP5520) += adp5520.o | 59 | obj-$(CONFIG_PMIC_ADP5520) += adp5520.o |
diff --git a/include/linux/mfd/88pm8607.h b/include/linux/mfd/88pm8607.h index f41b428d2cec..6e4dcdca02a8 100644 --- a/include/linux/mfd/88pm8607.h +++ b/include/linux/mfd/88pm8607.h | |||
@@ -33,8 +33,8 @@ enum { | |||
33 | PM8607_ID_RG_MAX, | 33 | PM8607_ID_RG_MAX, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | #define CHIP_ID (0x40) | 36 | #define PM8607_ID (0x40) /* 8607 chip ID */ |
37 | #define CHIP_ID_MASK (0xF8) | 37 | #define PM8607_ID_MASK (0xF8) /* 8607 chip ID mask */ |
38 | 38 | ||
39 | /* Interrupt Registers */ | 39 | /* Interrupt Registers */ |
40 | #define PM8607_STATUS_1 (0x01) | 40 | #define PM8607_STATUS_1 (0x01) |
@@ -185,6 +185,7 @@ struct pm8607_chip { | |||
185 | struct device *dev; | 185 | struct device *dev; |
186 | struct mutex io_lock; | 186 | struct mutex io_lock; |
187 | struct i2c_client *client; | 187 | struct i2c_client *client; |
188 | struct i2c_device_id id; | ||
188 | 189 | ||
189 | int (*read)(struct pm8607_chip *chip, int reg, int bytes, void *dest); | 190 | int (*read)(struct pm8607_chip *chip, int reg, int bytes, void *dest); |
190 | int (*write)(struct pm8607_chip *chip, int reg, int bytes, void *src); | 191 | int (*write)(struct pm8607_chip *chip, int reg, int bytes, void *src); |
@@ -214,4 +215,9 @@ extern int pm8607_bulk_write(struct pm8607_chip *, int, int, | |||
214 | unsigned char *); | 215 | unsigned char *); |
215 | extern int pm8607_set_bits(struct pm8607_chip *, int, unsigned char, | 216 | extern int pm8607_set_bits(struct pm8607_chip *, int, unsigned char, |
216 | unsigned char); | 217 | unsigned char); |
217 | #endif /* __LINUX_MFD_88PM8607_H */ | 218 | |
219 | extern int pm860x_device_init(struct pm8607_chip *chip, | ||
220 | struct pm8607_platform_data *pdata); | ||
221 | extern void pm860x_device_exit(struct pm8607_chip *chip); | ||
222 | |||
223 | #endif /* __LINUX_MFD_88PM860X_H */ | ||