diff options
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/88pm8607.c | 302 | ||||
-rw-r--r-- | drivers/mfd/88pm860x-core.c | 740 | ||||
-rw-r--r-- | drivers/mfd/88pm860x-i2c.c | 236 | ||||
-rw-r--r-- | drivers/mfd/Kconfig | 84 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 11 | ||||
-rw-r--r-- | drivers/mfd/ab3100-core.c | 54 | ||||
-rw-r--r-- | drivers/mfd/ab3100-otp.c | 13 | ||||
-rw-r--r-- | drivers/mfd/htc-egpio.c | 2 | ||||
-rw-r--r-- | drivers/mfd/htc-i2cpld.c | 710 | ||||
-rw-r--r-- | drivers/mfd/lpc_sch.c | 133 | ||||
-rw-r--r-- | drivers/mfd/max8925-core.c | 656 | ||||
-rw-r--r-- | drivers/mfd/max8925-i2c.c | 211 | ||||
-rw-r--r-- | drivers/mfd/mc13783-core.c | 73 | ||||
-rw-r--r-- | drivers/mfd/mfd-core.c | 5 | ||||
-rw-r--r-- | drivers/mfd/sh_mobile_sdhi.c | 6 | ||||
-rw-r--r-- | drivers/mfd/sm501.c | 7 | ||||
-rw-r--r-- | drivers/mfd/t7l66xb.c | 4 | ||||
-rw-r--r-- | drivers/mfd/tc6393xb.c | 2 | ||||
-rw-r--r-- | drivers/mfd/timberdale.c | 727 | ||||
-rw-r--r-- | drivers/mfd/timberdale.h | 130 | ||||
-rw-r--r-- | drivers/mfd/twl-core.c | 59 | ||||
-rw-r--r-- | drivers/mfd/twl4030-power.c | 52 | ||||
-rw-r--r-- | drivers/mfd/ucb1x00-core.c | 1 | ||||
-rw-r--r-- | drivers/mfd/wm831x-core.c | 51 | ||||
-rw-r--r-- | drivers/mfd/wm8350-core.c | 35 | ||||
-rw-r--r-- | drivers/mfd/wm8350-irq.c | 155 | ||||
-rw-r--r-- | drivers/mfd/wm8994-core.c | 537 |
27 files changed, 4497 insertions, 499 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..6a14d2b1ccf0 --- /dev/null +++ b/drivers/mfd/88pm860x-core.c | |||
@@ -0,0 +1,740 @@ | |||
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/i2c.h> | ||
15 | #include <linux/irq.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/mfd/core.h> | ||
19 | #include <linux/mfd/88pm860x.h> | ||
20 | |||
21 | #define INT_STATUS_NUM 3 | ||
22 | |||
23 | char pm860x_backlight_name[][MFD_NAME_SIZE] = { | ||
24 | "backlight-0", | ||
25 | "backlight-1", | ||
26 | "backlight-2", | ||
27 | }; | ||
28 | EXPORT_SYMBOL(pm860x_backlight_name); | ||
29 | |||
30 | char pm860x_led_name[][MFD_NAME_SIZE] = { | ||
31 | "led0-red", | ||
32 | "led0-green", | ||
33 | "led0-blue", | ||
34 | "led1-red", | ||
35 | "led1-green", | ||
36 | "led1-blue", | ||
37 | }; | ||
38 | EXPORT_SYMBOL(pm860x_led_name); | ||
39 | |||
40 | #define PM8606_BACKLIGHT_RESOURCE(_i, _x) \ | ||
41 | { \ | ||
42 | .name = pm860x_backlight_name[_i], \ | ||
43 | .start = PM8606_##_x, \ | ||
44 | .end = PM8606_##_x, \ | ||
45 | .flags = IORESOURCE_IO, \ | ||
46 | } | ||
47 | |||
48 | static struct resource backlight_resources[] = { | ||
49 | PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT1, WLED1A), | ||
50 | PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT2, WLED2A), | ||
51 | PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT3, WLED3A), | ||
52 | }; | ||
53 | |||
54 | #define PM8606_BACKLIGHT_DEVS(_i) \ | ||
55 | { \ | ||
56 | .name = "88pm860x-backlight", \ | ||
57 | .num_resources = 1, \ | ||
58 | .resources = &backlight_resources[_i], \ | ||
59 | .id = _i, \ | ||
60 | } | ||
61 | |||
62 | static struct mfd_cell backlight_devs[] = { | ||
63 | PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT1), | ||
64 | PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT2), | ||
65 | PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT3), | ||
66 | }; | ||
67 | |||
68 | #define PM8606_LED_RESOURCE(_i, _x) \ | ||
69 | { \ | ||
70 | .name = pm860x_led_name[_i], \ | ||
71 | .start = PM8606_##_x, \ | ||
72 | .end = PM8606_##_x, \ | ||
73 | .flags = IORESOURCE_IO, \ | ||
74 | } | ||
75 | |||
76 | static struct resource led_resources[] = { | ||
77 | PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB2B), | ||
78 | PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB2C), | ||
79 | PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB2D), | ||
80 | PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB1B), | ||
81 | PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB1C), | ||
82 | PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB1D), | ||
83 | }; | ||
84 | |||
85 | #define PM8606_LED_DEVS(_i) \ | ||
86 | { \ | ||
87 | .name = "88pm860x-led", \ | ||
88 | .num_resources = 1, \ | ||
89 | .resources = &led_resources[_i], \ | ||
90 | .id = _i, \ | ||
91 | } | ||
92 | |||
93 | static struct mfd_cell led_devs[] = { | ||
94 | PM8606_LED_DEVS(PM8606_LED1_RED), | ||
95 | PM8606_LED_DEVS(PM8606_LED1_GREEN), | ||
96 | PM8606_LED_DEVS(PM8606_LED1_BLUE), | ||
97 | PM8606_LED_DEVS(PM8606_LED2_RED), | ||
98 | PM8606_LED_DEVS(PM8606_LED2_GREEN), | ||
99 | PM8606_LED_DEVS(PM8606_LED2_BLUE), | ||
100 | }; | ||
101 | |||
102 | static struct resource touch_resources[] = { | ||
103 | { | ||
104 | .start = PM8607_IRQ_PEN, | ||
105 | .end = PM8607_IRQ_PEN, | ||
106 | .flags = IORESOURCE_IRQ, | ||
107 | }, | ||
108 | }; | ||
109 | |||
110 | static struct mfd_cell touch_devs[] = { | ||
111 | { | ||
112 | .name = "88pm860x-touch", | ||
113 | .num_resources = 1, | ||
114 | .resources = &touch_resources[0], | ||
115 | }, | ||
116 | }; | ||
117 | |||
118 | #define PM8607_REG_RESOURCE(_start, _end) \ | ||
119 | { \ | ||
120 | .start = PM8607_##_start, \ | ||
121 | .end = PM8607_##_end, \ | ||
122 | .flags = IORESOURCE_IO, \ | ||
123 | } | ||
124 | |||
125 | static struct resource power_supply_resources[] = { | ||
126 | { | ||
127 | .name = "88pm860x-power", | ||
128 | .start = PM8607_IRQ_CHG, | ||
129 | .end = PM8607_IRQ_CHG, | ||
130 | .flags = IORESOURCE_IRQ, | ||
131 | }, | ||
132 | }; | ||
133 | |||
134 | static struct mfd_cell power_devs[] = { | ||
135 | { | ||
136 | .name = "88pm860x-power", | ||
137 | .num_resources = 1, | ||
138 | .resources = &power_supply_resources[0], | ||
139 | .id = -1, | ||
140 | }, | ||
141 | }; | ||
142 | |||
143 | static struct resource onkey_resources[] = { | ||
144 | { | ||
145 | .name = "88pm860x-onkey", | ||
146 | .start = PM8607_IRQ_ONKEY, | ||
147 | .end = PM8607_IRQ_ONKEY, | ||
148 | .flags = IORESOURCE_IRQ, | ||
149 | }, | ||
150 | }; | ||
151 | |||
152 | static struct mfd_cell onkey_devs[] = { | ||
153 | { | ||
154 | .name = "88pm860x-onkey", | ||
155 | .num_resources = 1, | ||
156 | .resources = &onkey_resources[0], | ||
157 | .id = -1, | ||
158 | }, | ||
159 | }; | ||
160 | |||
161 | static struct resource regulator_resources[] = { | ||
162 | PM8607_REG_RESOURCE(BUCK1, BUCK1), | ||
163 | PM8607_REG_RESOURCE(BUCK2, BUCK2), | ||
164 | PM8607_REG_RESOURCE(BUCK3, BUCK3), | ||
165 | PM8607_REG_RESOURCE(LDO1, LDO1), | ||
166 | PM8607_REG_RESOURCE(LDO2, LDO2), | ||
167 | PM8607_REG_RESOURCE(LDO3, LDO3), | ||
168 | PM8607_REG_RESOURCE(LDO4, LDO4), | ||
169 | PM8607_REG_RESOURCE(LDO5, LDO5), | ||
170 | PM8607_REG_RESOURCE(LDO6, LDO6), | ||
171 | PM8607_REG_RESOURCE(LDO7, LDO7), | ||
172 | PM8607_REG_RESOURCE(LDO8, LDO8), | ||
173 | PM8607_REG_RESOURCE(LDO9, LDO9), | ||
174 | PM8607_REG_RESOURCE(LDO10, LDO10), | ||
175 | PM8607_REG_RESOURCE(LDO12, LDO12), | ||
176 | PM8607_REG_RESOURCE(LDO14, LDO14), | ||
177 | }; | ||
178 | |||
179 | #define PM8607_REG_DEVS(_name, _id) \ | ||
180 | { \ | ||
181 | .name = "88pm8607-" #_name, \ | ||
182 | .num_resources = 1, \ | ||
183 | .resources = ®ulator_resources[PM8607_ID_##_id], \ | ||
184 | .id = PM8607_ID_##_id, \ | ||
185 | } | ||
186 | |||
187 | static struct mfd_cell regulator_devs[] = { | ||
188 | PM8607_REG_DEVS(buck1, BUCK1), | ||
189 | PM8607_REG_DEVS(buck2, BUCK2), | ||
190 | PM8607_REG_DEVS(buck3, BUCK3), | ||
191 | PM8607_REG_DEVS(ldo1, LDO1), | ||
192 | PM8607_REG_DEVS(ldo2, LDO2), | ||
193 | PM8607_REG_DEVS(ldo3, LDO3), | ||
194 | PM8607_REG_DEVS(ldo4, LDO4), | ||
195 | PM8607_REG_DEVS(ldo5, LDO5), | ||
196 | PM8607_REG_DEVS(ldo6, LDO6), | ||
197 | PM8607_REG_DEVS(ldo7, LDO7), | ||
198 | PM8607_REG_DEVS(ldo8, LDO8), | ||
199 | PM8607_REG_DEVS(ldo9, LDO9), | ||
200 | PM8607_REG_DEVS(ldo10, LDO10), | ||
201 | PM8607_REG_DEVS(ldo12, LDO12), | ||
202 | PM8607_REG_DEVS(ldo14, LDO14), | ||
203 | }; | ||
204 | |||
205 | struct pm860x_irq_data { | ||
206 | int reg; | ||
207 | int mask_reg; | ||
208 | int enable; /* enable or not */ | ||
209 | int offs; /* bit offset in mask register */ | ||
210 | }; | ||
211 | |||
212 | static struct pm860x_irq_data pm860x_irqs[] = { | ||
213 | [PM8607_IRQ_ONKEY] = { | ||
214 | .reg = PM8607_INT_STATUS1, | ||
215 | .mask_reg = PM8607_INT_MASK_1, | ||
216 | .offs = 1 << 0, | ||
217 | }, | ||
218 | [PM8607_IRQ_EXTON] = { | ||
219 | .reg = PM8607_INT_STATUS1, | ||
220 | .mask_reg = PM8607_INT_MASK_1, | ||
221 | .offs = 1 << 1, | ||
222 | }, | ||
223 | [PM8607_IRQ_CHG] = { | ||
224 | .reg = PM8607_INT_STATUS1, | ||
225 | .mask_reg = PM8607_INT_MASK_1, | ||
226 | .offs = 1 << 2, | ||
227 | }, | ||
228 | [PM8607_IRQ_BAT] = { | ||
229 | .reg = PM8607_INT_STATUS1, | ||
230 | .mask_reg = PM8607_INT_MASK_1, | ||
231 | .offs = 1 << 3, | ||
232 | }, | ||
233 | [PM8607_IRQ_RTC] = { | ||
234 | .reg = PM8607_INT_STATUS1, | ||
235 | .mask_reg = PM8607_INT_MASK_1, | ||
236 | .offs = 1 << 4, | ||
237 | }, | ||
238 | [PM8607_IRQ_CC] = { | ||
239 | .reg = PM8607_INT_STATUS1, | ||
240 | .mask_reg = PM8607_INT_MASK_1, | ||
241 | .offs = 1 << 5, | ||
242 | }, | ||
243 | [PM8607_IRQ_VBAT] = { | ||
244 | .reg = PM8607_INT_STATUS2, | ||
245 | .mask_reg = PM8607_INT_MASK_2, | ||
246 | .offs = 1 << 0, | ||
247 | }, | ||
248 | [PM8607_IRQ_VCHG] = { | ||
249 | .reg = PM8607_INT_STATUS2, | ||
250 | .mask_reg = PM8607_INT_MASK_2, | ||
251 | .offs = 1 << 1, | ||
252 | }, | ||
253 | [PM8607_IRQ_VSYS] = { | ||
254 | .reg = PM8607_INT_STATUS2, | ||
255 | .mask_reg = PM8607_INT_MASK_2, | ||
256 | .offs = 1 << 2, | ||
257 | }, | ||
258 | [PM8607_IRQ_TINT] = { | ||
259 | .reg = PM8607_INT_STATUS2, | ||
260 | .mask_reg = PM8607_INT_MASK_2, | ||
261 | .offs = 1 << 3, | ||
262 | }, | ||
263 | [PM8607_IRQ_GPADC0] = { | ||
264 | .reg = PM8607_INT_STATUS2, | ||
265 | .mask_reg = PM8607_INT_MASK_2, | ||
266 | .offs = 1 << 4, | ||
267 | }, | ||
268 | [PM8607_IRQ_GPADC1] = { | ||
269 | .reg = PM8607_INT_STATUS2, | ||
270 | .mask_reg = PM8607_INT_MASK_2, | ||
271 | .offs = 1 << 5, | ||
272 | }, | ||
273 | [PM8607_IRQ_GPADC2] = { | ||
274 | .reg = PM8607_INT_STATUS2, | ||
275 | .mask_reg = PM8607_INT_MASK_2, | ||
276 | .offs = 1 << 6, | ||
277 | }, | ||
278 | [PM8607_IRQ_GPADC3] = { | ||
279 | .reg = PM8607_INT_STATUS2, | ||
280 | .mask_reg = PM8607_INT_MASK_2, | ||
281 | .offs = 1 << 7, | ||
282 | }, | ||
283 | [PM8607_IRQ_AUDIO_SHORT] = { | ||
284 | .reg = PM8607_INT_STATUS3, | ||
285 | .mask_reg = PM8607_INT_MASK_3, | ||
286 | .offs = 1 << 0, | ||
287 | }, | ||
288 | [PM8607_IRQ_PEN] = { | ||
289 | .reg = PM8607_INT_STATUS3, | ||
290 | .mask_reg = PM8607_INT_MASK_3, | ||
291 | .offs = 1 << 1, | ||
292 | }, | ||
293 | [PM8607_IRQ_HEADSET] = { | ||
294 | .reg = PM8607_INT_STATUS3, | ||
295 | .mask_reg = PM8607_INT_MASK_3, | ||
296 | .offs = 1 << 2, | ||
297 | }, | ||
298 | [PM8607_IRQ_HOOK] = { | ||
299 | .reg = PM8607_INT_STATUS3, | ||
300 | .mask_reg = PM8607_INT_MASK_3, | ||
301 | .offs = 1 << 3, | ||
302 | }, | ||
303 | [PM8607_IRQ_MICIN] = { | ||
304 | .reg = PM8607_INT_STATUS3, | ||
305 | .mask_reg = PM8607_INT_MASK_3, | ||
306 | .offs = 1 << 4, | ||
307 | }, | ||
308 | [PM8607_IRQ_CHG_FAIL] = { | ||
309 | .reg = PM8607_INT_STATUS3, | ||
310 | .mask_reg = PM8607_INT_MASK_3, | ||
311 | .offs = 1 << 5, | ||
312 | }, | ||
313 | [PM8607_IRQ_CHG_DONE] = { | ||
314 | .reg = PM8607_INT_STATUS3, | ||
315 | .mask_reg = PM8607_INT_MASK_3, | ||
316 | .offs = 1 << 6, | ||
317 | }, | ||
318 | [PM8607_IRQ_CHG_FAULT] = { | ||
319 | .reg = PM8607_INT_STATUS3, | ||
320 | .mask_reg = PM8607_INT_MASK_3, | ||
321 | .offs = 1 << 7, | ||
322 | }, | ||
323 | }; | ||
324 | |||
325 | static inline struct pm860x_irq_data *irq_to_pm860x(struct pm860x_chip *chip, | ||
326 | int irq) | ||
327 | { | ||
328 | return &pm860x_irqs[irq - chip->irq_base]; | ||
329 | } | ||
330 | |||
331 | static irqreturn_t pm860x_irq(int irq, void *data) | ||
332 | { | ||
333 | struct pm860x_chip *chip = data; | ||
334 | struct pm860x_irq_data *irq_data; | ||
335 | struct i2c_client *i2c; | ||
336 | int read_reg = -1, value = 0; | ||
337 | int i; | ||
338 | |||
339 | i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; | ||
340 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { | ||
341 | irq_data = &pm860x_irqs[i]; | ||
342 | if (read_reg != irq_data->reg) { | ||
343 | read_reg = irq_data->reg; | ||
344 | value = pm860x_reg_read(i2c, irq_data->reg); | ||
345 | } | ||
346 | if (value & irq_data->enable) | ||
347 | handle_nested_irq(chip->irq_base + i); | ||
348 | } | ||
349 | return IRQ_HANDLED; | ||
350 | } | ||
351 | |||
352 | static void pm860x_irq_lock(unsigned int irq) | ||
353 | { | ||
354 | struct pm860x_chip *chip = get_irq_chip_data(irq); | ||
355 | |||
356 | mutex_lock(&chip->irq_lock); | ||
357 | } | ||
358 | |||
359 | static void pm860x_irq_sync_unlock(unsigned int irq) | ||
360 | { | ||
361 | struct pm860x_chip *chip = get_irq_chip_data(irq); | ||
362 | struct pm860x_irq_data *irq_data; | ||
363 | struct i2c_client *i2c; | ||
364 | static unsigned char cached[3] = {0x0, 0x0, 0x0}; | ||
365 | unsigned char mask[3]; | ||
366 | int i; | ||
367 | |||
368 | i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; | ||
369 | /* Load cached value. In initial, all IRQs are masked */ | ||
370 | for (i = 0; i < 3; i++) | ||
371 | mask[i] = cached[i]; | ||
372 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { | ||
373 | irq_data = &pm860x_irqs[i]; | ||
374 | switch (irq_data->mask_reg) { | ||
375 | case PM8607_INT_MASK_1: | ||
376 | mask[0] &= ~irq_data->offs; | ||
377 | mask[0] |= irq_data->enable; | ||
378 | break; | ||
379 | case PM8607_INT_MASK_2: | ||
380 | mask[1] &= ~irq_data->offs; | ||
381 | mask[1] |= irq_data->enable; | ||
382 | break; | ||
383 | case PM8607_INT_MASK_3: | ||
384 | mask[2] &= ~irq_data->offs; | ||
385 | mask[2] |= irq_data->enable; | ||
386 | break; | ||
387 | default: | ||
388 | dev_err(chip->dev, "wrong IRQ\n"); | ||
389 | break; | ||
390 | } | ||
391 | } | ||
392 | /* update mask into registers */ | ||
393 | for (i = 0; i < 3; i++) { | ||
394 | if (mask[i] != cached[i]) { | ||
395 | cached[i] = mask[i]; | ||
396 | pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]); | ||
397 | } | ||
398 | } | ||
399 | |||
400 | mutex_unlock(&chip->irq_lock); | ||
401 | } | ||
402 | |||
403 | static void pm860x_irq_enable(unsigned int irq) | ||
404 | { | ||
405 | struct pm860x_chip *chip = get_irq_chip_data(irq); | ||
406 | pm860x_irqs[irq - chip->irq_base].enable | ||
407 | = pm860x_irqs[irq - chip->irq_base].offs; | ||
408 | } | ||
409 | |||
410 | static void pm860x_irq_disable(unsigned int irq) | ||
411 | { | ||
412 | struct pm860x_chip *chip = get_irq_chip_data(irq); | ||
413 | pm860x_irqs[irq - chip->irq_base].enable = 0; | ||
414 | } | ||
415 | |||
416 | static struct irq_chip pm860x_irq_chip = { | ||
417 | .name = "88pm860x", | ||
418 | .bus_lock = pm860x_irq_lock, | ||
419 | .bus_sync_unlock = pm860x_irq_sync_unlock, | ||
420 | .enable = pm860x_irq_enable, | ||
421 | .disable = pm860x_irq_disable, | ||
422 | }; | ||
423 | |||
424 | static int __devinit device_gpadc_init(struct pm860x_chip *chip, | ||
425 | struct pm860x_platform_data *pdata) | ||
426 | { | ||
427 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ | ||
428 | : chip->companion; | ||
429 | int use_gpadc = 0, data, ret; | ||
430 | |||
431 | /* initialize GPADC without activating it */ | ||
432 | |||
433 | if (pdata && pdata->touch) { | ||
434 | /* set GPADC MISC1 register */ | ||
435 | data = 0; | ||
436 | data |= (pdata->touch->gpadc_prebias << 1) | ||
437 | & PM8607_GPADC_PREBIAS_MASK; | ||
438 | data |= (pdata->touch->slot_cycle << 3) | ||
439 | & PM8607_GPADC_SLOT_CYCLE_MASK; | ||
440 | data |= (pdata->touch->off_scale << 5) | ||
441 | & PM8607_GPADC_OFF_SCALE_MASK; | ||
442 | data |= (pdata->touch->sw_cal << 7) | ||
443 | & PM8607_GPADC_SW_CAL_MASK; | ||
444 | if (data) { | ||
445 | ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); | ||
446 | if (ret < 0) | ||
447 | goto out; | ||
448 | } | ||
449 | /* set tsi prebias time */ | ||
450 | if (pdata->touch->tsi_prebias) { | ||
451 | data = pdata->touch->tsi_prebias; | ||
452 | ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); | ||
453 | if (ret < 0) | ||
454 | goto out; | ||
455 | } | ||
456 | /* set prebias & prechg time of pen detect */ | ||
457 | data = 0; | ||
458 | data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK; | ||
459 | data |= (pdata->touch->pen_prechg << 5) | ||
460 | & PM8607_PD_PRECHG_MASK; | ||
461 | if (data) { | ||
462 | ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); | ||
463 | if (ret < 0) | ||
464 | goto out; | ||
465 | } | ||
466 | |||
467 | use_gpadc = 1; | ||
468 | } | ||
469 | |||
470 | /* turn on GPADC */ | ||
471 | if (use_gpadc) { | ||
472 | ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1, | ||
473 | PM8607_GPADC_EN, PM8607_GPADC_EN); | ||
474 | } | ||
475 | out: | ||
476 | return ret; | ||
477 | } | ||
478 | |||
479 | static int __devinit device_irq_init(struct pm860x_chip *chip, | ||
480 | struct pm860x_platform_data *pdata) | ||
481 | { | ||
482 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ | ||
483 | : chip->companion; | ||
484 | unsigned char status_buf[INT_STATUS_NUM]; | ||
485 | unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; | ||
486 | struct irq_desc *desc; | ||
487 | int i, data, mask, ret = -EINVAL; | ||
488 | int __irq; | ||
489 | |||
490 | if (!pdata || !pdata->irq_base) { | ||
491 | dev_warn(chip->dev, "No interrupt support on IRQ base\n"); | ||
492 | return -EINVAL; | ||
493 | } | ||
494 | |||
495 | mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR | ||
496 | | PM8607_B0_MISC1_INT_MASK; | ||
497 | data = 0; | ||
498 | chip->irq_mode = 0; | ||
499 | if (pdata && pdata->irq_mode) { | ||
500 | /* | ||
501 | * irq_mode defines the way of clearing interrupt. If it's 1, | ||
502 | * clear IRQ by write. Otherwise, clear it by read. | ||
503 | * This control bit is valid from 88PM8607 B0 steping. | ||
504 | */ | ||
505 | data |= PM8607_B0_MISC1_INT_CLEAR; | ||
506 | chip->irq_mode = 1; | ||
507 | } | ||
508 | ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data); | ||
509 | if (ret < 0) | ||
510 | goto out; | ||
511 | |||
512 | /* mask all IRQs */ | ||
513 | memset(status_buf, 0, INT_STATUS_NUM); | ||
514 | ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1, | ||
515 | INT_STATUS_NUM, status_buf); | ||
516 | if (ret < 0) | ||
517 | goto out; | ||
518 | |||
519 | if (chip->irq_mode) { | ||
520 | /* clear interrupt status by write */ | ||
521 | memset(status_buf, 0xFF, INT_STATUS_NUM); | ||
522 | ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1, | ||
523 | INT_STATUS_NUM, status_buf); | ||
524 | } else { | ||
525 | /* clear interrupt status by read */ | ||
526 | ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1, | ||
527 | INT_STATUS_NUM, status_buf); | ||
528 | } | ||
529 | if (ret < 0) | ||
530 | goto out; | ||
531 | |||
532 | mutex_init(&chip->irq_lock); | ||
533 | chip->irq_base = pdata->irq_base; | ||
534 | chip->core_irq = i2c->irq; | ||
535 | if (!chip->core_irq) | ||
536 | goto out; | ||
537 | |||
538 | desc = irq_to_desc(chip->core_irq); | ||
539 | |||
540 | /* register IRQ by genirq */ | ||
541 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { | ||
542 | __irq = i + chip->irq_base; | ||
543 | set_irq_chip_data(__irq, chip); | ||
544 | set_irq_chip_and_handler(__irq, &pm860x_irq_chip, | ||
545 | handle_edge_irq); | ||
546 | set_irq_nested_thread(__irq, 1); | ||
547 | #ifdef CONFIG_ARM | ||
548 | set_irq_flags(__irq, IRQF_VALID); | ||
549 | #else | ||
550 | set_irq_noprobe(__irq); | ||
551 | #endif | ||
552 | } | ||
553 | |||
554 | ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags, | ||
555 | "88pm860x", chip); | ||
556 | if (ret) { | ||
557 | dev_err(chip->dev, "Failed to request IRQ: %d\n", ret); | ||
558 | chip->core_irq = 0; | ||
559 | } | ||
560 | |||
561 | return 0; | ||
562 | out: | ||
563 | chip->core_irq = 0; | ||
564 | return ret; | ||
565 | } | ||
566 | |||
567 | static void __devexit device_irq_exit(struct pm860x_chip *chip) | ||
568 | { | ||
569 | if (chip->core_irq) | ||
570 | free_irq(chip->core_irq, chip); | ||
571 | } | ||
572 | |||
573 | static void __devinit device_8606_init(struct pm860x_chip *chip, | ||
574 | struct i2c_client *i2c, | ||
575 | struct pm860x_platform_data *pdata) | ||
576 | { | ||
577 | int ret; | ||
578 | |||
579 | if (pdata && pdata->backlight) { | ||
580 | ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0], | ||
581 | ARRAY_SIZE(backlight_devs), | ||
582 | &backlight_resources[0], 0); | ||
583 | if (ret < 0) { | ||
584 | dev_err(chip->dev, "Failed to add backlight " | ||
585 | "subdev\n"); | ||
586 | goto out_dev; | ||
587 | } | ||
588 | } | ||
589 | |||
590 | if (pdata && pdata->led) { | ||
591 | ret = mfd_add_devices(chip->dev, 0, &led_devs[0], | ||
592 | ARRAY_SIZE(led_devs), | ||
593 | &led_resources[0], 0); | ||
594 | if (ret < 0) { | ||
595 | dev_err(chip->dev, "Failed to add led " | ||
596 | "subdev\n"); | ||
597 | goto out_dev; | ||
598 | } | ||
599 | } | ||
600 | return; | ||
601 | out_dev: | ||
602 | mfd_remove_devices(chip->dev); | ||
603 | device_irq_exit(chip); | ||
604 | } | ||
605 | |||
606 | static void __devinit device_8607_init(struct pm860x_chip *chip, | ||
607 | struct i2c_client *i2c, | ||
608 | struct pm860x_platform_data *pdata) | ||
609 | { | ||
610 | int data, ret; | ||
611 | |||
612 | ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); | ||
613 | if (ret < 0) { | ||
614 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); | ||
615 | goto out; | ||
616 | } | ||
617 | if ((ret & PM8607_VERSION_MASK) == PM8607_VERSION) | ||
618 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", | ||
619 | ret); | ||
620 | else { | ||
621 | dev_err(chip->dev, "Failed to detect Marvell 88PM8607. " | ||
622 | "Chip ID: %02x\n", ret); | ||
623 | goto out; | ||
624 | } | ||
625 | |||
626 | ret = pm860x_reg_read(i2c, PM8607_BUCK3); | ||
627 | if (ret < 0) { | ||
628 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); | ||
629 | goto out; | ||
630 | } | ||
631 | if (ret & PM8607_BUCK3_DOUBLE) | ||
632 | chip->buck3_double = 1; | ||
633 | |||
634 | ret = pm860x_reg_read(i2c, PM8607_B0_MISC1); | ||
635 | if (ret < 0) { | ||
636 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); | ||
637 | goto out; | ||
638 | } | ||
639 | |||
640 | if (pdata && (pdata->i2c_port == PI2C_PORT)) | ||
641 | data = PM8607_B0_MISC1_PI2C; | ||
642 | else | ||
643 | data = 0; | ||
644 | ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data); | ||
645 | if (ret < 0) { | ||
646 | dev_err(chip->dev, "Failed to access MISC1:%d\n", ret); | ||
647 | goto out; | ||
648 | } | ||
649 | |||
650 | ret = device_gpadc_init(chip, pdata); | ||
651 | if (ret < 0) | ||
652 | goto out; | ||
653 | |||
654 | ret = device_irq_init(chip, pdata); | ||
655 | if (ret < 0) | ||
656 | goto out; | ||
657 | |||
658 | ret = mfd_add_devices(chip->dev, 0, ®ulator_devs[0], | ||
659 | ARRAY_SIZE(regulator_devs), | ||
660 | ®ulator_resources[0], 0); | ||
661 | if (ret < 0) { | ||
662 | dev_err(chip->dev, "Failed to add regulator subdev\n"); | ||
663 | goto out_dev; | ||
664 | } | ||
665 | |||
666 | if (pdata && pdata->touch) { | ||
667 | ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], | ||
668 | ARRAY_SIZE(touch_devs), | ||
669 | &touch_resources[0], 0); | ||
670 | if (ret < 0) { | ||
671 | dev_err(chip->dev, "Failed to add touch " | ||
672 | "subdev\n"); | ||
673 | goto out_dev; | ||
674 | } | ||
675 | } | ||
676 | |||
677 | if (pdata && pdata->power) { | ||
678 | ret = mfd_add_devices(chip->dev, 0, &power_devs[0], | ||
679 | ARRAY_SIZE(power_devs), | ||
680 | &power_supply_resources[0], 0); | ||
681 | if (ret < 0) { | ||
682 | dev_err(chip->dev, "Failed to add power supply " | ||
683 | "subdev\n"); | ||
684 | goto out_dev; | ||
685 | } | ||
686 | } | ||
687 | |||
688 | ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], | ||
689 | ARRAY_SIZE(onkey_devs), | ||
690 | &onkey_resources[0], 0); | ||
691 | if (ret < 0) { | ||
692 | dev_err(chip->dev, "Failed to add onkey subdev\n"); | ||
693 | goto out_dev; | ||
694 | } | ||
695 | |||
696 | return; | ||
697 | out_dev: | ||
698 | mfd_remove_devices(chip->dev); | ||
699 | device_irq_exit(chip); | ||
700 | out: | ||
701 | return; | ||
702 | } | ||
703 | |||
704 | int pm860x_device_init(struct pm860x_chip *chip, | ||
705 | struct pm860x_platform_data *pdata) | ||
706 | { | ||
707 | chip->core_irq = 0; | ||
708 | |||
709 | switch (chip->id) { | ||
710 | case CHIP_PM8606: | ||
711 | device_8606_init(chip, chip->client, pdata); | ||
712 | break; | ||
713 | case CHIP_PM8607: | ||
714 | device_8607_init(chip, chip->client, pdata); | ||
715 | break; | ||
716 | } | ||
717 | |||
718 | if (chip->companion) { | ||
719 | switch (chip->id) { | ||
720 | case CHIP_PM8607: | ||
721 | device_8606_init(chip, chip->companion, pdata); | ||
722 | break; | ||
723 | case CHIP_PM8606: | ||
724 | device_8607_init(chip, chip->companion, pdata); | ||
725 | break; | ||
726 | } | ||
727 | } | ||
728 | |||
729 | return 0; | ||
730 | } | ||
731 | |||
732 | void pm860x_device_exit(struct pm860x_chip *chip) | ||
733 | { | ||
734 | device_irq_exit(chip); | ||
735 | mfd_remove_devices(chip->dev); | ||
736 | } | ||
737 | |||
738 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x"); | ||
739 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
740 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c new file mode 100644 index 000000000000..c37e12bf3004 --- /dev/null +++ b/drivers/mfd/88pm860x-i2c.c | |||
@@ -0,0 +1,236 @@ | |||
1 | /* | ||
2 | * I2C driver for Marvell 88PM860x | ||
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/88pm860x.h> | ||
16 | |||
17 | static inline int pm860x_read_device(struct i2c_client *i2c, | ||
18 | int reg, int bytes, void *dest) | ||
19 | { | ||
20 | unsigned char data; | ||
21 | int ret; | ||
22 | |||
23 | data = (unsigned char)reg; | ||
24 | ret = i2c_master_send(i2c, &data, 1); | ||
25 | if (ret < 0) | ||
26 | return ret; | ||
27 | |||
28 | ret = i2c_master_recv(i2c, dest, bytes); | ||
29 | if (ret < 0) | ||
30 | return ret; | ||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | static inline int pm860x_write_device(struct i2c_client *i2c, | ||
35 | int reg, int bytes, void *src) | ||
36 | { | ||
37 | unsigned char buf[bytes + 1]; | ||
38 | int ret; | ||
39 | |||
40 | buf[0] = (unsigned char)reg; | ||
41 | memcpy(&buf[1], src, bytes); | ||
42 | |||
43 | ret = i2c_master_send(i2c, buf, bytes + 1); | ||
44 | if (ret < 0) | ||
45 | return ret; | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | int pm860x_reg_read(struct i2c_client *i2c, int reg) | ||
50 | { | ||
51 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
52 | unsigned char data; | ||
53 | int ret; | ||
54 | |||
55 | mutex_lock(&chip->io_lock); | ||
56 | ret = pm860x_read_device(i2c, reg, 1, &data); | ||
57 | mutex_unlock(&chip->io_lock); | ||
58 | |||
59 | if (ret < 0) | ||
60 | return ret; | ||
61 | else | ||
62 | return (int)data; | ||
63 | } | ||
64 | EXPORT_SYMBOL(pm860x_reg_read); | ||
65 | |||
66 | int pm860x_reg_write(struct i2c_client *i2c, int reg, | ||
67 | unsigned char data) | ||
68 | { | ||
69 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
70 | int ret; | ||
71 | |||
72 | mutex_lock(&chip->io_lock); | ||
73 | ret = pm860x_write_device(i2c, reg, 1, &data); | ||
74 | mutex_unlock(&chip->io_lock); | ||
75 | |||
76 | return ret; | ||
77 | } | ||
78 | EXPORT_SYMBOL(pm860x_reg_write); | ||
79 | |||
80 | int pm860x_bulk_read(struct i2c_client *i2c, int reg, | ||
81 | int count, unsigned char *buf) | ||
82 | { | ||
83 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
84 | int ret; | ||
85 | |||
86 | mutex_lock(&chip->io_lock); | ||
87 | ret = pm860x_read_device(i2c, reg, count, buf); | ||
88 | mutex_unlock(&chip->io_lock); | ||
89 | |||
90 | return ret; | ||
91 | } | ||
92 | EXPORT_SYMBOL(pm860x_bulk_read); | ||
93 | |||
94 | int pm860x_bulk_write(struct i2c_client *i2c, int reg, | ||
95 | int count, unsigned char *buf) | ||
96 | { | ||
97 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
98 | int ret; | ||
99 | |||
100 | mutex_lock(&chip->io_lock); | ||
101 | ret = pm860x_write_device(i2c, reg, count, buf); | ||
102 | mutex_unlock(&chip->io_lock); | ||
103 | |||
104 | return ret; | ||
105 | } | ||
106 | EXPORT_SYMBOL(pm860x_bulk_write); | ||
107 | |||
108 | int pm860x_set_bits(struct i2c_client *i2c, int reg, | ||
109 | unsigned char mask, unsigned char data) | ||
110 | { | ||
111 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
112 | unsigned char value; | ||
113 | int ret; | ||
114 | |||
115 | mutex_lock(&chip->io_lock); | ||
116 | ret = pm860x_read_device(i2c, reg, 1, &value); | ||
117 | if (ret < 0) | ||
118 | goto out; | ||
119 | value &= ~mask; | ||
120 | value |= data; | ||
121 | ret = pm860x_write_device(i2c, reg, 1, &value); | ||
122 | out: | ||
123 | mutex_unlock(&chip->io_lock); | ||
124 | return ret; | ||
125 | } | ||
126 | EXPORT_SYMBOL(pm860x_set_bits); | ||
127 | |||
128 | |||
129 | static const struct i2c_device_id pm860x_id_table[] = { | ||
130 | { "88PM860x", 0 }, | ||
131 | {} | ||
132 | }; | ||
133 | MODULE_DEVICE_TABLE(i2c, pm860x_id_table); | ||
134 | |||
135 | static int verify_addr(struct i2c_client *i2c) | ||
136 | { | ||
137 | unsigned short addr_8607[] = {0x30, 0x34}; | ||
138 | unsigned short addr_8606[] = {0x10, 0x11}; | ||
139 | int size, i; | ||
140 | |||
141 | if (i2c == NULL) | ||
142 | return 0; | ||
143 | size = ARRAY_SIZE(addr_8606); | ||
144 | for (i = 0; i < size; i++) { | ||
145 | if (i2c->addr == *(addr_8606 + i)) | ||
146 | return CHIP_PM8606; | ||
147 | } | ||
148 | size = ARRAY_SIZE(addr_8607); | ||
149 | for (i = 0; i < size; i++) { | ||
150 | if (i2c->addr == *(addr_8607 + i)) | ||
151 | return CHIP_PM8607; | ||
152 | } | ||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | static int __devinit pm860x_probe(struct i2c_client *client, | ||
157 | const struct i2c_device_id *id) | ||
158 | { | ||
159 | struct pm860x_platform_data *pdata = client->dev.platform_data; | ||
160 | struct pm860x_chip *chip; | ||
161 | |||
162 | if (!pdata) { | ||
163 | pr_info("No platform data in %s!\n", __func__); | ||
164 | return -EINVAL; | ||
165 | } | ||
166 | |||
167 | chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL); | ||
168 | if (chip == NULL) | ||
169 | return -ENOMEM; | ||
170 | |||
171 | chip->id = verify_addr(client); | ||
172 | chip->client = client; | ||
173 | i2c_set_clientdata(client, chip); | ||
174 | chip->dev = &client->dev; | ||
175 | mutex_init(&chip->io_lock); | ||
176 | dev_set_drvdata(chip->dev, chip); | ||
177 | |||
178 | /* | ||
179 | * Both client and companion client shares same platform driver. | ||
180 | * Driver distinguishes them by pdata->companion_addr. | ||
181 | * pdata->companion_addr is only assigned if companion chip exists. | ||
182 | * At the same time, the companion_addr shouldn't equal to client | ||
183 | * address. | ||
184 | */ | ||
185 | if (pdata->companion_addr && (pdata->companion_addr != client->addr)) { | ||
186 | chip->companion_addr = pdata->companion_addr; | ||
187 | chip->companion = i2c_new_dummy(chip->client->adapter, | ||
188 | chip->companion_addr); | ||
189 | i2c_set_clientdata(chip->companion, chip); | ||
190 | } | ||
191 | |||
192 | pm860x_device_init(chip, pdata); | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static int __devexit pm860x_remove(struct i2c_client *client) | ||
197 | { | ||
198 | struct pm860x_chip *chip = i2c_get_clientdata(client); | ||
199 | |||
200 | pm860x_device_exit(chip); | ||
201 | i2c_unregister_device(chip->companion); | ||
202 | i2c_set_clientdata(chip->companion, NULL); | ||
203 | i2c_set_clientdata(chip->client, NULL); | ||
204 | kfree(chip); | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static struct i2c_driver pm860x_driver = { | ||
209 | .driver = { | ||
210 | .name = "88PM860x", | ||
211 | .owner = THIS_MODULE, | ||
212 | }, | ||
213 | .probe = pm860x_probe, | ||
214 | .remove = __devexit_p(pm860x_remove), | ||
215 | .id_table = pm860x_id_table, | ||
216 | }; | ||
217 | |||
218 | static int __init pm860x_i2c_init(void) | ||
219 | { | ||
220 | int ret; | ||
221 | ret = i2c_add_driver(&pm860x_driver); | ||
222 | if (ret != 0) | ||
223 | pr_err("Failed to register 88PM860x I2C driver: %d\n", ret); | ||
224 | return ret; | ||
225 | } | ||
226 | subsys_initcall(pm860x_i2c_init); | ||
227 | |||
228 | static void __exit pm860x_i2c_exit(void) | ||
229 | { | ||
230 | i2c_del_driver(&pm860x_driver); | ||
231 | } | ||
232 | module_exit(pm860x_i2c_exit); | ||
233 | |||
234 | MODULE_DESCRIPTION("I2C Driver for Marvell 88PM860x"); | ||
235 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
236 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 87829789243e..951fa9b93fbe 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -9,6 +9,16 @@ config MFD_CORE | |||
9 | tristate | 9 | tristate |
10 | default n | 10 | default n |
11 | 11 | ||
12 | config MFD_88PM860X | ||
13 | bool "Support Marvell 88PM8606/88PM8607" | ||
14 | depends on I2C=y | ||
15 | select MFD_CORE | ||
16 | help | ||
17 | This supports for Marvell 88PM8606/88PM8607 Power Management IC. | ||
18 | This includes the I2C driver and the core APIs _only_, you have to | ||
19 | select individual components like voltage regulators, RTC and | ||
20 | battery-charger under the corresponding menus. | ||
21 | |||
12 | config MFD_SM501 | 22 | config MFD_SM501 |
13 | tristate "Support for Silicon Motion SM501" | 23 | tristate "Support for Silicon Motion SM501" |
14 | ---help--- | 24 | ---help--- |
@@ -37,7 +47,7 @@ config MFD_ASIC3 | |||
37 | 47 | ||
38 | config MFD_SH_MOBILE_SDHI | 48 | config MFD_SH_MOBILE_SDHI |
39 | bool "Support for SuperH Mobile SDHI" | 49 | bool "Support for SuperH Mobile SDHI" |
40 | depends on SUPERH | 50 | depends on SUPERH || ARCH_SHMOBILE |
41 | select MFD_CORE | 51 | select MFD_CORE |
42 | ---help--- | 52 | ---help--- |
43 | This driver supports the SDHI hardware block found in many | 53 | This driver supports the SDHI hardware block found in many |
@@ -68,6 +78,15 @@ config HTC_PASIC3 | |||
68 | HTC Magician devices, respectively. Actual functionality is | 78 | HTC Magician devices, respectively. Actual functionality is |
69 | handled by the leds-pasic3 and ds1wm drivers. | 79 | handled by the leds-pasic3 and ds1wm drivers. |
70 | 80 | ||
81 | config HTC_I2CPLD | ||
82 | bool "HTC I2C PLD chip support" | ||
83 | depends on I2C=y && GPIOLIB | ||
84 | help | ||
85 | If you say yes here you get support for the supposed CPLD | ||
86 | found on omap850 HTC devices like the HTC Wizard and HTC Herald. | ||
87 | This device provides input and output GPIOs through an I2C | ||
88 | interface to one or more sub-chips. | ||
89 | |||
71 | config UCB1400_CORE | 90 | config UCB1400_CORE |
72 | tristate "Philips UCB1400 Core driver" | 91 | tristate "Philips UCB1400 Core driver" |
73 | depends on AC97_BUS | 92 | depends on AC97_BUS |
@@ -94,7 +113,7 @@ config TPS65010 | |||
94 | 113 | ||
95 | config MENELAUS | 114 | config MENELAUS |
96 | bool "Texas Instruments TWL92330/Menelaus PM chip" | 115 | bool "Texas Instruments TWL92330/Menelaus PM chip" |
97 | depends on I2C=y && ARCH_OMAP24XX | 116 | depends on I2C=y && ARCH_OMAP2 |
98 | help | 117 | help |
99 | If you say yes here you get support for the Texas Instruments | 118 | If you say yes here you get support for the Texas Instruments |
100 | TWL92330/Menelaus Power Management chip. This include voltage | 119 | TWL92330/Menelaus Power Management chip. This include voltage |
@@ -184,6 +203,16 @@ config PMIC_ADP5520 | |||
184 | individual components like LCD backlight, LEDs, GPIOs and Kepad | 203 | individual components like LCD backlight, LEDs, GPIOs and Kepad |
185 | under the corresponding menus. | 204 | under the corresponding menus. |
186 | 205 | ||
206 | config MFD_MAX8925 | ||
207 | bool "Maxim Semiconductor MAX8925 PMIC Support" | ||
208 | depends on I2C=y | ||
209 | select MFD_CORE | ||
210 | help | ||
211 | Say yes here to support for Maxim Semiconductor MAX8925. This is | ||
212 | a Power Management IC. This driver provies common support for | ||
213 | accessing the device, additional drivers must be enabled in order | ||
214 | to use the functionality of the device. | ||
215 | |||
187 | config MFD_WM8400 | 216 | config MFD_WM8400 |
188 | tristate "Support Wolfson Microelectronics WM8400" | 217 | tristate "Support Wolfson Microelectronics WM8400" |
189 | select MFD_CORE | 218 | select MFD_CORE |
@@ -205,7 +234,7 @@ config MFD_WM831X | |||
205 | functionality of the device. | 234 | functionality of the device. |
206 | 235 | ||
207 | config MFD_WM8350 | 236 | config MFD_WM8350 |
208 | tristate | 237 | bool |
209 | 238 | ||
210 | config MFD_WM8350_CONFIG_MODE_0 | 239 | config MFD_WM8350_CONFIG_MODE_0 |
211 | bool | 240 | bool |
@@ -256,9 +285,9 @@ config MFD_WM8352_CONFIG_MODE_3 | |||
256 | depends on MFD_WM8350 | 285 | depends on MFD_WM8350 |
257 | 286 | ||
258 | config MFD_WM8350_I2C | 287 | config MFD_WM8350_I2C |
259 | tristate "Support Wolfson Microelectronics WM8350 with I2C" | 288 | bool "Support Wolfson Microelectronics WM8350 with I2C" |
260 | select MFD_WM8350 | 289 | select MFD_WM8350 |
261 | depends on I2C | 290 | depends on I2C=y |
262 | help | 291 | help |
263 | The WM8350 is an integrated audio and power management | 292 | The WM8350 is an integrated audio and power management |
264 | subsystem with watchdog and RTC functionality for embedded | 293 | subsystem with watchdog and RTC functionality for embedded |
@@ -266,6 +295,18 @@ config MFD_WM8350_I2C | |||
266 | I2C as the control interface. Additional options must be | 295 | I2C as the control interface. Additional options must be |
267 | selected to enable support for the functionality of the chip. | 296 | selected to enable support for the functionality of the chip. |
268 | 297 | ||
298 | config MFD_WM8994 | ||
299 | tristate "Support Wolfson Microelectronics WM8994" | ||
300 | select MFD_CORE | ||
301 | depends on I2C | ||
302 | help | ||
303 | The WM8994 is a highly integrated hi-fi CODEC designed for | ||
304 | smartphone applicatiosn. As well as audio functionality it | ||
305 | has on board GPIO and regulator functionality which is | ||
306 | supported via the relevant subsystems. This driver provides | ||
307 | core support for the WM8994, in order to use the actual | ||
308 | functionaltiy of the device other drivers must be enabled. | ||
309 | |||
269 | config MFD_PCF50633 | 310 | config MFD_PCF50633 |
270 | tristate "Support for NXP PCF50633" | 311 | tristate "Support for NXP PCF50633" |
271 | depends on I2C | 312 | depends on I2C |
@@ -300,8 +341,8 @@ config PCF50633_GPIO | |||
300 | the PCF50633 chip. | 341 | the PCF50633 chip. |
301 | 342 | ||
302 | config AB3100_CORE | 343 | config AB3100_CORE |
303 | tristate "ST-Ericsson AB3100 Mixed Signal Circuit core functions" | 344 | bool "ST-Ericsson AB3100 Mixed Signal Circuit core functions" |
304 | depends on I2C | 345 | depends on I2C=y |
305 | default y if ARCH_U300 | 346 | default y if ARCH_U300 |
306 | help | 347 | help |
307 | Select this to enable the AB3100 Mixed Signal IC core | 348 | Select this to enable the AB3100 Mixed Signal IC core |
@@ -329,16 +370,6 @@ config EZX_PCAP | |||
329 | This enables the PCAP ASIC present on EZX Phones. This is | 370 | This enables the PCAP ASIC present on EZX Phones. This is |
330 | needed for MMC, TouchScreen, Sound, USB, etc.. | 371 | needed for MMC, TouchScreen, Sound, USB, etc.. |
331 | 372 | ||
332 | config MFD_88PM8607 | ||
333 | bool "Support Marvell 88PM8607" | ||
334 | depends on I2C=y | ||
335 | select MFD_CORE | ||
336 | help | ||
337 | This supports for Marvell 88PM8607 Power Management IC. This includes | ||
338 | the I2C driver and the core APIs _only_, you have to select | ||
339 | individual components like voltage regulators, RTC and | ||
340 | battery-charger under the corresponding menus. | ||
341 | |||
342 | config AB4500_CORE | 373 | config AB4500_CORE |
343 | tristate "ST-Ericsson's AB4500 Mixed Signal Power management chip" | 374 | tristate "ST-Ericsson's AB4500 Mixed Signal Power management chip" |
344 | depends on SPI | 375 | depends on SPI |
@@ -348,6 +379,25 @@ config AB4500_CORE | |||
348 | read/write functions for the devices to get access to this chip. | 379 | read/write functions for the devices to get access to this chip. |
349 | This chip embeds various other multimedia funtionalities as well. | 380 | This chip embeds various other multimedia funtionalities as well. |
350 | 381 | ||
382 | config MFD_TIMBERDALE | ||
383 | tristate "Support for the Timberdale FPGA" | ||
384 | select MFD_CORE | ||
385 | depends on PCI && GPIOLIB | ||
386 | ---help--- | ||
387 | This is the core driver for the timberdale FPGA. This device is a | ||
388 | multifunction device which exposes numerous platform devices. | ||
389 | |||
390 | The timberdale FPGA can be found on the Intel Atom development board | ||
391 | for in-vehicle infontainment, called Russellville. | ||
392 | |||
393 | config LPC_SCH | ||
394 | tristate "Intel SCH LPC" | ||
395 | depends on PCI | ||
396 | select MFD_CORE | ||
397 | help | ||
398 | LPC bridge function of the Intel SCH provides support for | ||
399 | System Management Bus and General Purpose I/O. | ||
400 | |||
351 | endmenu | 401 | endmenu |
352 | 402 | ||
353 | menu "Multimedia Capabilities Port drivers" | 403 | menu "Multimedia Capabilities Port drivers" |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index e09eb4870db6..22715add99a7 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -2,12 +2,15 @@ | |||
2 | # Makefile for multifunction miscellaneous devices | 2 | # Makefile for multifunction miscellaneous devices |
3 | # | 3 | # |
4 | 4 | ||
5 | 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o | ||
6 | obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o | ||
5 | obj-$(CONFIG_MFD_SM501) += sm501.o | 7 | obj-$(CONFIG_MFD_SM501) += sm501.o |
6 | obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o | 8 | obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o |
7 | obj-$(CONFIG_MFD_SH_MOBILE_SDHI) += sh_mobile_sdhi.o | 9 | obj-$(CONFIG_MFD_SH_MOBILE_SDHI) += sh_mobile_sdhi.o |
8 | 10 | ||
9 | obj-$(CONFIG_HTC_EGPIO) += htc-egpio.o | 11 | obj-$(CONFIG_HTC_EGPIO) += htc-egpio.o |
10 | obj-$(CONFIG_HTC_PASIC3) += htc-pasic3.o | 12 | obj-$(CONFIG_HTC_PASIC3) += htc-pasic3.o |
13 | obj-$(CONFIG_HTC_I2CPLD) += htc-i2cpld.o | ||
11 | 14 | ||
12 | obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o | 15 | obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o |
13 | 16 | ||
@@ -22,6 +25,7 @@ wm8350-objs := wm8350-core.o wm8350-regmap.o wm8350-gpio.o | |||
22 | wm8350-objs += wm8350-irq.o | 25 | wm8350-objs += wm8350-irq.o |
23 | obj-$(CONFIG_MFD_WM8350) += wm8350.o | 26 | obj-$(CONFIG_MFD_WM8350) += wm8350.o |
24 | obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o | 27 | obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o |
28 | obj-$(CONFIG_MFD_WM8994) += wm8994-core.o | ||
25 | 29 | ||
26 | obj-$(CONFIG_TPS65010) += tps65010.o | 30 | obj-$(CONFIG_TPS65010) += tps65010.o |
27 | obj-$(CONFIG_MENELAUS) += menelaus.o | 31 | obj-$(CONFIG_MENELAUS) += menelaus.o |
@@ -47,6 +51,8 @@ endif | |||
47 | obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o | 51 | obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o |
48 | 52 | ||
49 | obj-$(CONFIG_PMIC_DA903X) += da903x.o | 53 | obj-$(CONFIG_PMIC_DA903X) += da903x.o |
54 | max8925-objs := max8925-core.o max8925-i2c.o | ||
55 | obj-$(CONFIG_MFD_MAX8925) += max8925.o | ||
50 | 56 | ||
51 | obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o | 57 | obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o |
52 | obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o | 58 | obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o |
@@ -54,5 +60,6 @@ obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o | |||
54 | obj-$(CONFIG_AB3100_CORE) += ab3100-core.o | 60 | obj-$(CONFIG_AB3100_CORE) += ab3100-core.o |
55 | obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o | 61 | obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o |
56 | obj-$(CONFIG_AB4500_CORE) += ab4500-core.o | 62 | obj-$(CONFIG_AB4500_CORE) += ab4500-core.o |
57 | obj-$(CONFIG_MFD_88PM8607) += 88pm8607.o | 63 | obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o |
58 | obj-$(CONFIG_PMIC_ADP5520) += adp5520.o \ No newline at end of file | 64 | obj-$(CONFIG_PMIC_ADP5520) += adp5520.o |
65 | obj-$(CONFIG_LPC_SCH) += lpc_sch.o \ No newline at end of file | ||
diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c index fd42a80e7bf9..a2ce3b6af4a2 100644 --- a/drivers/mfd/ab3100-core.c +++ b/drivers/mfd/ab3100-core.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2007-2009 ST-Ericsson | 2 | * Copyright (C) 2007-2010 ST-Ericsson |
3 | * License terms: GNU General Public License (GPL) version 2 | 3 | * License terms: GNU General Public License (GPL) version 2 |
4 | * Low-level core for exclusive access to the AB3100 IC on the I2C bus | 4 | * Low-level core for exclusive access to the AB3100 IC on the I2C bus |
5 | * and some basic chip-configuration. | 5 | * and some basic chip-configuration. |
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/device.h> | 15 | #include <linux/device.h> |
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/random.h> | ||
17 | #include <linux/debugfs.h> | 18 | #include <linux/debugfs.h> |
18 | #include <linux/seq_file.h> | 19 | #include <linux/seq_file.h> |
19 | #include <linux/uaccess.h> | 20 | #include <linux/uaccess.h> |
@@ -365,18 +366,23 @@ int ab3100_event_registers_startup_state_get(struct ab3100 *ab3100, | |||
365 | } | 366 | } |
366 | EXPORT_SYMBOL(ab3100_event_registers_startup_state_get); | 367 | EXPORT_SYMBOL(ab3100_event_registers_startup_state_get); |
367 | 368 | ||
368 | /* Interrupt handling worker */ | 369 | /* |
369 | static void ab3100_work(struct work_struct *work) | 370 | * This is a threaded interrupt handler so we can make some |
371 | * I2C calls etc. | ||
372 | */ | ||
373 | static irqreturn_t ab3100_irq_handler(int irq, void *data) | ||
370 | { | 374 | { |
371 | struct ab3100 *ab3100 = container_of(work, struct ab3100, work); | 375 | struct ab3100 *ab3100 = data; |
372 | u8 event_regs[3]; | 376 | u8 event_regs[3]; |
373 | u32 fatevent; | 377 | u32 fatevent; |
374 | int err; | 378 | int err; |
375 | 379 | ||
380 | add_interrupt_randomness(irq); | ||
381 | |||
376 | err = ab3100_get_register_page_interruptible(ab3100, AB3100_EVENTA1, | 382 | err = ab3100_get_register_page_interruptible(ab3100, AB3100_EVENTA1, |
377 | event_regs, 3); | 383 | event_regs, 3); |
378 | if (err) | 384 | if (err) |
379 | goto err_event_wq; | 385 | goto err_event; |
380 | 386 | ||
381 | fatevent = (event_regs[0] << 16) | | 387 | fatevent = (event_regs[0] << 16) | |
382 | (event_regs[1] << 8) | | 388 | (event_regs[1] << 8) | |
@@ -398,29 +404,11 @@ static void ab3100_work(struct work_struct *work) | |||
398 | dev_dbg(ab3100->dev, | 404 | dev_dbg(ab3100->dev, |
399 | "IRQ Event: 0x%08x\n", fatevent); | 405 | "IRQ Event: 0x%08x\n", fatevent); |
400 | 406 | ||
401 | /* By now the IRQ should be acked and deasserted so enable it again */ | 407 | return IRQ_HANDLED; |
402 | enable_irq(ab3100->i2c_client->irq); | ||
403 | return; | ||
404 | 408 | ||
405 | err_event_wq: | 409 | err_event: |
406 | dev_dbg(ab3100->dev, | 410 | dev_dbg(ab3100->dev, |
407 | "error in event workqueue\n"); | 411 | "error reading event status\n"); |
408 | /* Enable the IRQ anyway, what choice do we have? */ | ||
409 | enable_irq(ab3100->i2c_client->irq); | ||
410 | return; | ||
411 | } | ||
412 | |||
413 | static irqreturn_t ab3100_irq_handler(int irq, void *data) | ||
414 | { | ||
415 | struct ab3100 *ab3100 = data; | ||
416 | /* | ||
417 | * Disable the IRQ and dispatch a worker to handle the | ||
418 | * event. Since the chip resides on I2C this is slow | ||
419 | * stuff and we will re-enable the interrupts once th | ||
420 | * worker has finished. | ||
421 | */ | ||
422 | disable_irq_nosync(irq); | ||
423 | schedule_work(&ab3100->work); | ||
424 | return IRQ_HANDLED; | 412 | return IRQ_HANDLED; |
425 | } | 413 | } |
426 | 414 | ||
@@ -735,10 +723,7 @@ static struct platform_device ab3100_##devname##_device = { \ | |||
735 | .id = -1, \ | 723 | .id = -1, \ |
736 | } | 724 | } |
737 | 725 | ||
738 | /* | 726 | /* This lists all the subdevices */ |
739 | * This lists all the subdevices and corresponding register | ||
740 | * ranges. | ||
741 | */ | ||
742 | AB3100_DEVICE(dac, "ab3100-dac"); | 727 | AB3100_DEVICE(dac, "ab3100-dac"); |
743 | AB3100_DEVICE(leds, "ab3100-leds"); | 728 | AB3100_DEVICE(leds, "ab3100-leds"); |
744 | AB3100_DEVICE(power, "ab3100-power"); | 729 | AB3100_DEVICE(power, "ab3100-power"); |
@@ -904,12 +889,11 @@ static int __init ab3100_probe(struct i2c_client *client, | |||
904 | if (err) | 889 | if (err) |
905 | goto exit_no_setup; | 890 | goto exit_no_setup; |
906 | 891 | ||
907 | INIT_WORK(&ab3100->work, ab3100_work); | 892 | err = request_threaded_irq(client->irq, NULL, ab3100_irq_handler, |
908 | 893 | IRQF_ONESHOT, "ab3100-core", ab3100); | |
909 | /* This real unpredictable IRQ is of course sampled for entropy */ | 894 | /* This real unpredictable IRQ is of course sampled for entropy */ |
910 | err = request_irq(client->irq, ab3100_irq_handler, | 895 | rand_initialize_irq(client->irq); |
911 | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, | 896 | |
912 | "AB3100 IRQ", ab3100); | ||
913 | if (err) | 897 | if (err) |
914 | goto exit_no_irq; | 898 | goto exit_no_irq; |
915 | 899 | ||
diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c index 0499b2031a2c..b603469dff69 100644 --- a/drivers/mfd/ab3100-otp.c +++ b/drivers/mfd/ab3100-otp.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
14 | #include <linux/mfd/ab3100.h> | 14 | #include <linux/mfd/ab3100.h> |
15 | #include <linux/debugfs.h> | 15 | #include <linux/debugfs.h> |
16 | #include <linux/seq_file.h> | ||
16 | 17 | ||
17 | /* The OTP registers */ | 18 | /* The OTP registers */ |
18 | #define AB3100_OTP0 0xb0 | 19 | #define AB3100_OTP0 0xb0 |
@@ -95,11 +96,10 @@ static int __init ab3100_otp_read(struct ab3100_otp *otp) | |||
95 | * This is a simple debugfs human-readable file that dumps out | 96 | * This is a simple debugfs human-readable file that dumps out |
96 | * the contents of the OTP. | 97 | * the contents of the OTP. |
97 | */ | 98 | */ |
98 | #ifdef CONFIG_DEBUGFS | 99 | #ifdef CONFIG_DEBUG_FS |
99 | static int show_otp(struct seq_file *s, void *v) | 100 | static int ab3100_show_otp(struct seq_file *s, void *v) |
100 | { | 101 | { |
101 | struct ab3100_otp *otp = s->private; | 102 | struct ab3100_otp *otp = s->private; |
102 | int err; | ||
103 | 103 | ||
104 | seq_printf(s, "OTP is %s\n", otp->locked ? "LOCKED" : "UNLOCKED"); | 104 | seq_printf(s, "OTP is %s\n", otp->locked ? "LOCKED" : "UNLOCKED"); |
105 | seq_printf(s, "OTP clock switch startup is %uHz\n", otp->freq); | 105 | seq_printf(s, "OTP clock switch startup is %uHz\n", otp->freq); |
@@ -113,7 +113,7 @@ static int show_otp(struct seq_file *s, void *v) | |||
113 | 113 | ||
114 | static int ab3100_otp_open(struct inode *inode, struct file *file) | 114 | static int ab3100_otp_open(struct inode *inode, struct file *file) |
115 | { | 115 | { |
116 | return single_open(file, ab3100_otp_show, inode->i_private); | 116 | return single_open(file, ab3100_show_otp, inode->i_private); |
117 | } | 117 | } |
118 | 118 | ||
119 | static const struct file_operations ab3100_otp_operations = { | 119 | static const struct file_operations ab3100_otp_operations = { |
@@ -131,13 +131,14 @@ static int __init ab3100_otp_init_debugfs(struct device *dev, | |||
131 | &ab3100_otp_operations); | 131 | &ab3100_otp_operations); |
132 | if (!otp->debugfs) { | 132 | if (!otp->debugfs) { |
133 | dev_err(dev, "AB3100 debugfs OTP file registration failed!\n"); | 133 | dev_err(dev, "AB3100 debugfs OTP file registration failed!\n"); |
134 | return err; | 134 | return -ENOENT; |
135 | } | 135 | } |
136 | return 0; | ||
136 | } | 137 | } |
137 | 138 | ||
138 | static void __exit ab3100_otp_exit_debugfs(struct ab3100_otp *otp) | 139 | static void __exit ab3100_otp_exit_debugfs(struct ab3100_otp *otp) |
139 | { | 140 | { |
140 | debugfs_remove_file(otp->debugfs); | 141 | debugfs_remove(otp->debugfs); |
141 | } | 142 | } |
142 | #else | 143 | #else |
143 | /* Compile this out if debugfs not selected */ | 144 | /* Compile this out if debugfs not selected */ |
diff --git a/drivers/mfd/htc-egpio.c b/drivers/mfd/htc-egpio.c index aa266e1f69b2..addb846c1e34 100644 --- a/drivers/mfd/htc-egpio.c +++ b/drivers/mfd/htc-egpio.c | |||
@@ -108,7 +108,7 @@ static void egpio_handler(unsigned int irq, struct irq_desc *desc) | |||
108 | ack_irqs(ei); | 108 | ack_irqs(ei); |
109 | /* Process all set pins. */ | 109 | /* Process all set pins. */ |
110 | readval &= ei->irqs_enabled; | 110 | readval &= ei->irqs_enabled; |
111 | for_each_bit(irqpin, &readval, ei->nirqs) { | 111 | for_each_set_bit(irqpin, &readval, ei->nirqs) { |
112 | /* Run irq handler */ | 112 | /* Run irq handler */ |
113 | pr_debug("got IRQ %d\n", irqpin); | 113 | pr_debug("got IRQ %d\n", irqpin); |
114 | irq = ei->irq_start + irqpin; | 114 | irq = ei->irq_start + irqpin; |
diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c new file mode 100644 index 000000000000..37b9fdab4f36 --- /dev/null +++ b/drivers/mfd/htc-i2cpld.c | |||
@@ -0,0 +1,710 @@ | |||
1 | /* | ||
2 | * htc-i2cpld.c | ||
3 | * Chip driver for an unknown CPLD chip found on omap850 HTC devices like | ||
4 | * the HTC Wizard and HTC Herald. | ||
5 | * The cpld is located on the i2c bus and acts as an input/output GPIO | ||
6 | * extender. | ||
7 | * | ||
8 | * Copyright (C) 2009 Cory Maccarrone <darkstar6262@gmail.com> | ||
9 | * | ||
10 | * Based on work done in the linwizard project | ||
11 | * Copyright (C) 2008-2009 Angelo Arrifano <miknix@gmail.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/platform_device.h> | ||
33 | #include <linux/i2c.h> | ||
34 | #include <linux/irq.h> | ||
35 | #include <linux/spinlock.h> | ||
36 | #include <linux/htcpld.h> | ||
37 | #include <linux/gpio.h> | ||
38 | |||
39 | struct htcpld_chip { | ||
40 | spinlock_t lock; | ||
41 | |||
42 | /* chip info */ | ||
43 | u8 reset; | ||
44 | u8 addr; | ||
45 | struct device *dev; | ||
46 | struct i2c_client *client; | ||
47 | |||
48 | /* Output details */ | ||
49 | u8 cache_out; | ||
50 | struct gpio_chip chip_out; | ||
51 | |||
52 | /* Input details */ | ||
53 | u8 cache_in; | ||
54 | struct gpio_chip chip_in; | ||
55 | |||
56 | u16 irqs_enabled; | ||
57 | uint irq_start; | ||
58 | int nirqs; | ||
59 | |||
60 | /* | ||
61 | * Work structure to allow for setting values outside of any | ||
62 | * possible interrupt context | ||
63 | */ | ||
64 | struct work_struct set_val_work; | ||
65 | }; | ||
66 | |||
67 | struct htcpld_data { | ||
68 | /* irq info */ | ||
69 | u16 irqs_enabled; | ||
70 | uint irq_start; | ||
71 | int nirqs; | ||
72 | uint chained_irq; | ||
73 | unsigned int int_reset_gpio_hi; | ||
74 | unsigned int int_reset_gpio_lo; | ||
75 | |||
76 | /* htcpld info */ | ||
77 | struct htcpld_chip *chip; | ||
78 | unsigned int nchips; | ||
79 | }; | ||
80 | |||
81 | /* There does not appear to be a way to proactively mask interrupts | ||
82 | * on the htcpld chip itself. So, we simply ignore interrupts that | ||
83 | * aren't desired. */ | ||
84 | static void htcpld_mask(unsigned int irq) | ||
85 | { | ||
86 | struct htcpld_chip *chip = get_irq_chip_data(irq); | ||
87 | chip->irqs_enabled &= ~(1 << (irq - chip->irq_start)); | ||
88 | pr_debug("HTCPLD mask %d %04x\n", irq, chip->irqs_enabled); | ||
89 | } | ||
90 | static void htcpld_unmask(unsigned int irq) | ||
91 | { | ||
92 | struct htcpld_chip *chip = get_irq_chip_data(irq); | ||
93 | chip->irqs_enabled |= 1 << (irq - chip->irq_start); | ||
94 | pr_debug("HTCPLD unmask %d %04x\n", irq, chip->irqs_enabled); | ||
95 | } | ||
96 | |||
97 | static int htcpld_set_type(unsigned int irq, unsigned int flags) | ||
98 | { | ||
99 | struct irq_desc *d = irq_to_desc(irq); | ||
100 | |||
101 | if (!d) { | ||
102 | pr_err("HTCPLD invalid IRQ: %d\n", irq); | ||
103 | return -EINVAL; | ||
104 | } | ||
105 | |||
106 | if (flags & ~IRQ_TYPE_SENSE_MASK) | ||
107 | return -EINVAL; | ||
108 | |||
109 | /* We only allow edge triggering */ | ||
110 | if (flags & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)) | ||
111 | return -EINVAL; | ||
112 | |||
113 | d->status &= ~IRQ_TYPE_SENSE_MASK; | ||
114 | d->status |= flags; | ||
115 | |||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static struct irq_chip htcpld_muxed_chip = { | ||
120 | .name = "htcpld", | ||
121 | .mask = htcpld_mask, | ||
122 | .unmask = htcpld_unmask, | ||
123 | .set_type = htcpld_set_type, | ||
124 | }; | ||
125 | |||
126 | /* To properly dispatch IRQ events, we need to read from the | ||
127 | * chip. This is an I2C action that could possibly sleep | ||
128 | * (which is bad in interrupt context) -- so we use a threaded | ||
129 | * interrupt handler to get around that. | ||
130 | */ | ||
131 | static irqreturn_t htcpld_handler(int irq, void *dev) | ||
132 | { | ||
133 | struct htcpld_data *htcpld = dev; | ||
134 | unsigned int i; | ||
135 | unsigned long flags; | ||
136 | int irqpin; | ||
137 | struct irq_desc *desc; | ||
138 | |||
139 | if (!htcpld) { | ||
140 | pr_debug("htcpld is null in ISR\n"); | ||
141 | return IRQ_HANDLED; | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * For each chip, do a read of the chip and trigger any interrupts | ||
146 | * desired. The interrupts will be triggered from LSB to MSB (i.e. | ||
147 | * bit 0 first, then bit 1, etc.) | ||
148 | * | ||
149 | * For chips that have no interrupt range specified, just skip 'em. | ||
150 | */ | ||
151 | for (i = 0; i < htcpld->nchips; i++) { | ||
152 | struct htcpld_chip *chip = &htcpld->chip[i]; | ||
153 | struct i2c_client *client; | ||
154 | int val; | ||
155 | unsigned long uval, old_val; | ||
156 | |||
157 | if (!chip) { | ||
158 | pr_debug("chip %d is null in ISR\n", i); | ||
159 | continue; | ||
160 | } | ||
161 | |||
162 | if (chip->nirqs == 0) | ||
163 | continue; | ||
164 | |||
165 | client = chip->client; | ||
166 | if (!client) { | ||
167 | pr_debug("client %d is null in ISR\n", i); | ||
168 | continue; | ||
169 | } | ||
170 | |||
171 | /* Scan the chip */ | ||
172 | val = i2c_smbus_read_byte_data(client, chip->cache_out); | ||
173 | if (val < 0) { | ||
174 | /* Throw a warning and skip this chip */ | ||
175 | dev_warn(chip->dev, "Unable to read from chip: %d\n", | ||
176 | val); | ||
177 | continue; | ||
178 | } | ||
179 | |||
180 | uval = (unsigned long)val; | ||
181 | |||
182 | spin_lock_irqsave(&chip->lock, flags); | ||
183 | |||
184 | /* Save away the old value so we can compare it */ | ||
185 | old_val = chip->cache_in; | ||
186 | |||
187 | /* Write the new value */ | ||
188 | chip->cache_in = uval; | ||
189 | |||
190 | spin_unlock_irqrestore(&chip->lock, flags); | ||
191 | |||
192 | /* | ||
193 | * For each bit in the data (starting at bit 0), trigger | ||
194 | * associated interrupts. | ||
195 | */ | ||
196 | for (irqpin = 0; irqpin < chip->nirqs; irqpin++) { | ||
197 | unsigned oldb, newb; | ||
198 | int flags; | ||
199 | |||
200 | irq = chip->irq_start + irqpin; | ||
201 | desc = irq_to_desc(irq); | ||
202 | flags = desc->status; | ||
203 | |||
204 | /* Run the IRQ handler, but only if the bit value | ||
205 | * changed, and the proper flags are set */ | ||
206 | oldb = (old_val >> irqpin) & 1; | ||
207 | newb = (uval >> irqpin) & 1; | ||
208 | |||
209 | if ((!oldb && newb && (flags & IRQ_TYPE_EDGE_RISING)) || | ||
210 | (oldb && !newb && | ||
211 | (flags & IRQ_TYPE_EDGE_FALLING))) { | ||
212 | pr_debug("fire IRQ %d\n", irqpin); | ||
213 | desc->handle_irq(irq, desc); | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * In order to continue receiving interrupts, the int_reset_gpio must | ||
220 | * be asserted. | ||
221 | */ | ||
222 | if (htcpld->int_reset_gpio_hi) | ||
223 | gpio_set_value(htcpld->int_reset_gpio_hi, 1); | ||
224 | if (htcpld->int_reset_gpio_lo) | ||
225 | gpio_set_value(htcpld->int_reset_gpio_lo, 0); | ||
226 | |||
227 | return IRQ_HANDLED; | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * The GPIO set routines can be called from interrupt context, especially if, | ||
232 | * for example they're attached to the led-gpio framework and a trigger is | ||
233 | * enabled. As such, we declared work above in the htcpld_chip structure, | ||
234 | * and that work is scheduled in the set routine. The kernel can then run | ||
235 | * the I2C functions, which will sleep, in process context. | ||
236 | */ | ||
237 | void htcpld_chip_set(struct gpio_chip *chip, unsigned offset, int val) | ||
238 | { | ||
239 | struct i2c_client *client; | ||
240 | struct htcpld_chip *chip_data; | ||
241 | unsigned long flags; | ||
242 | |||
243 | chip_data = container_of(chip, struct htcpld_chip, chip_out); | ||
244 | if (!chip_data) | ||
245 | return; | ||
246 | |||
247 | client = chip_data->client; | ||
248 | if (client == NULL) | ||
249 | return; | ||
250 | |||
251 | spin_lock_irqsave(&chip_data->lock, flags); | ||
252 | if (val) | ||
253 | chip_data->cache_out |= (1 << offset); | ||
254 | else | ||
255 | chip_data->cache_out &= ~(1 << offset); | ||
256 | spin_unlock_irqrestore(&chip_data->lock, flags); | ||
257 | |||
258 | schedule_work(&(chip_data->set_val_work)); | ||
259 | } | ||
260 | |||
261 | void htcpld_chip_set_ni(struct work_struct *work) | ||
262 | { | ||
263 | struct htcpld_chip *chip_data; | ||
264 | struct i2c_client *client; | ||
265 | |||
266 | chip_data = container_of(work, struct htcpld_chip, set_val_work); | ||
267 | client = chip_data->client; | ||
268 | i2c_smbus_read_byte_data(client, chip_data->cache_out); | ||
269 | } | ||
270 | |||
271 | int htcpld_chip_get(struct gpio_chip *chip, unsigned offset) | ||
272 | { | ||
273 | struct htcpld_chip *chip_data; | ||
274 | int val = 0; | ||
275 | int is_input = 0; | ||
276 | |||
277 | /* Try out first */ | ||
278 | chip_data = container_of(chip, struct htcpld_chip, chip_out); | ||
279 | if (!chip_data) { | ||
280 | /* Try in */ | ||
281 | is_input = 1; | ||
282 | chip_data = container_of(chip, struct htcpld_chip, chip_in); | ||
283 | if (!chip_data) | ||
284 | return -EINVAL; | ||
285 | } | ||
286 | |||
287 | /* Determine if this is an input or output GPIO */ | ||
288 | if (!is_input) | ||
289 | /* Use the output cache */ | ||
290 | val = (chip_data->cache_out >> offset) & 1; | ||
291 | else | ||
292 | /* Use the input cache */ | ||
293 | val = (chip_data->cache_in >> offset) & 1; | ||
294 | |||
295 | if (val) | ||
296 | return 1; | ||
297 | else | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static int htcpld_direction_output(struct gpio_chip *chip, | ||
302 | unsigned offset, int value) | ||
303 | { | ||
304 | htcpld_chip_set(chip, offset, value); | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | static int htcpld_direction_input(struct gpio_chip *chip, | ||
309 | unsigned offset) | ||
310 | { | ||
311 | /* | ||
312 | * No-op: this function can only be called on the input chip. | ||
313 | * We do however make sure the offset is within range. | ||
314 | */ | ||
315 | return (offset < chip->ngpio) ? 0 : -EINVAL; | ||
316 | } | ||
317 | |||
318 | int htcpld_chip_to_irq(struct gpio_chip *chip, unsigned offset) | ||
319 | { | ||
320 | struct htcpld_chip *chip_data; | ||
321 | |||
322 | chip_data = container_of(chip, struct htcpld_chip, chip_in); | ||
323 | |||
324 | if (offset < chip_data->nirqs) | ||
325 | return chip_data->irq_start + offset; | ||
326 | else | ||
327 | return -EINVAL; | ||
328 | } | ||
329 | |||
330 | void htcpld_chip_reset(struct i2c_client *client) | ||
331 | { | ||
332 | struct htcpld_chip *chip_data = i2c_get_clientdata(client); | ||
333 | if (!chip_data) | ||
334 | return; | ||
335 | |||
336 | i2c_smbus_read_byte_data( | ||
337 | client, (chip_data->cache_out = chip_data->reset)); | ||
338 | } | ||
339 | |||
340 | static int __devinit htcpld_setup_chip_irq( | ||
341 | struct platform_device *pdev, | ||
342 | int chip_index) | ||
343 | { | ||
344 | struct htcpld_data *htcpld; | ||
345 | struct device *dev = &pdev->dev; | ||
346 | struct htcpld_core_platform_data *pdata; | ||
347 | struct htcpld_chip *chip; | ||
348 | struct htcpld_chip_platform_data *plat_chip_data; | ||
349 | unsigned int irq, irq_end; | ||
350 | int ret = 0; | ||
351 | |||
352 | /* Get the platform and driver data */ | ||
353 | pdata = dev->platform_data; | ||
354 | htcpld = platform_get_drvdata(pdev); | ||
355 | chip = &htcpld->chip[chip_index]; | ||
356 | plat_chip_data = &pdata->chip[chip_index]; | ||
357 | |||
358 | /* Setup irq handlers */ | ||
359 | irq_end = chip->irq_start + chip->nirqs; | ||
360 | for (irq = chip->irq_start; irq < irq_end; irq++) { | ||
361 | set_irq_chip(irq, &htcpld_muxed_chip); | ||
362 | set_irq_chip_data(irq, chip); | ||
363 | set_irq_handler(irq, handle_simple_irq); | ||
364 | #ifdef CONFIG_ARM | ||
365 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
366 | #else | ||
367 | set_irq_probe(irq); | ||
368 | #endif | ||
369 | } | ||
370 | |||
371 | return ret; | ||
372 | } | ||
373 | |||
374 | static int __devinit htcpld_register_chip_i2c( | ||
375 | struct platform_device *pdev, | ||
376 | int chip_index) | ||
377 | { | ||
378 | struct htcpld_data *htcpld; | ||
379 | struct device *dev = &pdev->dev; | ||
380 | struct htcpld_core_platform_data *pdata; | ||
381 | struct htcpld_chip *chip; | ||
382 | struct htcpld_chip_platform_data *plat_chip_data; | ||
383 | struct i2c_adapter *adapter; | ||
384 | struct i2c_client *client; | ||
385 | struct i2c_board_info info; | ||
386 | |||
387 | /* Get the platform and driver data */ | ||
388 | pdata = dev->platform_data; | ||
389 | htcpld = platform_get_drvdata(pdev); | ||
390 | chip = &htcpld->chip[chip_index]; | ||
391 | plat_chip_data = &pdata->chip[chip_index]; | ||
392 | |||
393 | adapter = i2c_get_adapter(pdata->i2c_adapter_id); | ||
394 | if (adapter == NULL) { | ||
395 | /* Eek, no such I2C adapter! Bail out. */ | ||
396 | dev_warn(dev, "Chip at i2c address 0x%x: Invalid i2c adapter %d\n", | ||
397 | plat_chip_data->addr, pdata->i2c_adapter_id); | ||
398 | return -ENODEV; | ||
399 | } | ||
400 | |||
401 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { | ||
402 | dev_warn(dev, "i2c adapter %d non-functional\n", | ||
403 | pdata->i2c_adapter_id); | ||
404 | return -EINVAL; | ||
405 | } | ||
406 | |||
407 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
408 | info.addr = plat_chip_data->addr; | ||
409 | strlcpy(info.type, "htcpld-chip", I2C_NAME_SIZE); | ||
410 | info.platform_data = chip; | ||
411 | |||
412 | /* Add the I2C device. This calls the probe() function. */ | ||
413 | client = i2c_new_device(adapter, &info); | ||
414 | if (!client) { | ||
415 | /* I2C device registration failed, contineu with the next */ | ||
416 | dev_warn(dev, "Unable to add I2C device for 0x%x\n", | ||
417 | plat_chip_data->addr); | ||
418 | return -ENODEV; | ||
419 | } | ||
420 | |||
421 | i2c_set_clientdata(client, chip); | ||
422 | snprintf(client->name, I2C_NAME_SIZE, "Chip_0x%d", client->addr); | ||
423 | chip->client = client; | ||
424 | |||
425 | /* Reset the chip */ | ||
426 | htcpld_chip_reset(client); | ||
427 | chip->cache_in = i2c_smbus_read_byte_data(client, chip->cache_out); | ||
428 | |||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | static void __devinit htcpld_unregister_chip_i2c( | ||
433 | struct platform_device *pdev, | ||
434 | int chip_index) | ||
435 | { | ||
436 | struct htcpld_data *htcpld; | ||
437 | struct htcpld_chip *chip; | ||
438 | |||
439 | /* Get the platform and driver data */ | ||
440 | htcpld = platform_get_drvdata(pdev); | ||
441 | chip = &htcpld->chip[chip_index]; | ||
442 | |||
443 | if (chip->client) | ||
444 | i2c_unregister_device(chip->client); | ||
445 | } | ||
446 | |||
447 | static int __devinit htcpld_register_chip_gpio( | ||
448 | struct platform_device *pdev, | ||
449 | int chip_index) | ||
450 | { | ||
451 | struct htcpld_data *htcpld; | ||
452 | struct device *dev = &pdev->dev; | ||
453 | struct htcpld_core_platform_data *pdata; | ||
454 | struct htcpld_chip *chip; | ||
455 | struct htcpld_chip_platform_data *plat_chip_data; | ||
456 | struct gpio_chip *gpio_chip; | ||
457 | int ret = 0; | ||
458 | |||
459 | /* Get the platform and driver data */ | ||
460 | pdata = dev->platform_data; | ||
461 | htcpld = platform_get_drvdata(pdev); | ||
462 | chip = &htcpld->chip[chip_index]; | ||
463 | plat_chip_data = &pdata->chip[chip_index]; | ||
464 | |||
465 | /* Setup the GPIO chips */ | ||
466 | gpio_chip = &(chip->chip_out); | ||
467 | gpio_chip->label = "htcpld-out"; | ||
468 | gpio_chip->dev = dev; | ||
469 | gpio_chip->owner = THIS_MODULE; | ||
470 | gpio_chip->get = htcpld_chip_get; | ||
471 | gpio_chip->set = htcpld_chip_set; | ||
472 | gpio_chip->direction_input = NULL; | ||
473 | gpio_chip->direction_output = htcpld_direction_output; | ||
474 | gpio_chip->base = plat_chip_data->gpio_out_base; | ||
475 | gpio_chip->ngpio = plat_chip_data->num_gpios; | ||
476 | |||
477 | gpio_chip = &(chip->chip_in); | ||
478 | gpio_chip->label = "htcpld-in"; | ||
479 | gpio_chip->dev = dev; | ||
480 | gpio_chip->owner = THIS_MODULE; | ||
481 | gpio_chip->get = htcpld_chip_get; | ||
482 | gpio_chip->set = NULL; | ||
483 | gpio_chip->direction_input = htcpld_direction_input; | ||
484 | gpio_chip->direction_output = NULL; | ||
485 | gpio_chip->to_irq = htcpld_chip_to_irq; | ||
486 | gpio_chip->base = plat_chip_data->gpio_in_base; | ||
487 | gpio_chip->ngpio = plat_chip_data->num_gpios; | ||
488 | |||
489 | /* Add the GPIO chips */ | ||
490 | ret = gpiochip_add(&(chip->chip_out)); | ||
491 | if (ret) { | ||
492 | dev_warn(dev, "Unable to register output GPIOs for 0x%x: %d\n", | ||
493 | plat_chip_data->addr, ret); | ||
494 | return ret; | ||
495 | } | ||
496 | |||
497 | ret = gpiochip_add(&(chip->chip_in)); | ||
498 | if (ret) { | ||
499 | int error; | ||
500 | |||
501 | dev_warn(dev, "Unable to register input GPIOs for 0x%x: %d\n", | ||
502 | plat_chip_data->addr, ret); | ||
503 | |||
504 | error = gpiochip_remove(&(chip->chip_out)); | ||
505 | if (error) | ||
506 | dev_warn(dev, "Error while trying to unregister gpio chip: %d\n", error); | ||
507 | |||
508 | return ret; | ||
509 | } | ||
510 | |||
511 | return 0; | ||
512 | } | ||
513 | |||
514 | static int __devinit htcpld_setup_chips(struct platform_device *pdev) | ||
515 | { | ||
516 | struct htcpld_data *htcpld; | ||
517 | struct device *dev = &pdev->dev; | ||
518 | struct htcpld_core_platform_data *pdata; | ||
519 | int i; | ||
520 | |||
521 | /* Get the platform and driver data */ | ||
522 | pdata = dev->platform_data; | ||
523 | htcpld = platform_get_drvdata(pdev); | ||
524 | |||
525 | /* Setup each chip's output GPIOs */ | ||
526 | htcpld->nchips = pdata->num_chip; | ||
527 | htcpld->chip = kzalloc(sizeof(struct htcpld_chip) * htcpld->nchips, | ||
528 | GFP_KERNEL); | ||
529 | if (!htcpld->chip) { | ||
530 | dev_warn(dev, "Unable to allocate memory for chips\n"); | ||
531 | return -ENOMEM; | ||
532 | } | ||
533 | |||
534 | /* Add the chips as best we can */ | ||
535 | for (i = 0; i < htcpld->nchips; i++) { | ||
536 | int ret; | ||
537 | |||
538 | /* Setup the HTCPLD chips */ | ||
539 | htcpld->chip[i].reset = pdata->chip[i].reset; | ||
540 | htcpld->chip[i].cache_out = pdata->chip[i].reset; | ||
541 | htcpld->chip[i].cache_in = 0; | ||
542 | htcpld->chip[i].dev = dev; | ||
543 | htcpld->chip[i].irq_start = pdata->chip[i].irq_base; | ||
544 | htcpld->chip[i].nirqs = pdata->chip[i].num_irqs; | ||
545 | |||
546 | INIT_WORK(&(htcpld->chip[i].set_val_work), &htcpld_chip_set_ni); | ||
547 | spin_lock_init(&(htcpld->chip[i].lock)); | ||
548 | |||
549 | /* Setup the interrupts for the chip */ | ||
550 | if (htcpld->chained_irq) { | ||
551 | ret = htcpld_setup_chip_irq(pdev, i); | ||
552 | if (ret) | ||
553 | continue; | ||
554 | } | ||
555 | |||
556 | /* Register the chip with I2C */ | ||
557 | ret = htcpld_register_chip_i2c(pdev, i); | ||
558 | if (ret) | ||
559 | continue; | ||
560 | |||
561 | |||
562 | /* Register the chips with the GPIO subsystem */ | ||
563 | ret = htcpld_register_chip_gpio(pdev, i); | ||
564 | if (ret) { | ||
565 | /* Unregister the chip from i2c and continue */ | ||
566 | htcpld_unregister_chip_i2c(pdev, i); | ||
567 | continue; | ||
568 | } | ||
569 | |||
570 | dev_info(dev, "Registered chip at 0x%x\n", pdata->chip[i].addr); | ||
571 | } | ||
572 | |||
573 | return 0; | ||
574 | } | ||
575 | |||
576 | static int __devinit htcpld_core_probe(struct platform_device *pdev) | ||
577 | { | ||
578 | struct htcpld_data *htcpld; | ||
579 | struct device *dev = &pdev->dev; | ||
580 | struct htcpld_core_platform_data *pdata; | ||
581 | struct resource *res; | ||
582 | int ret = 0; | ||
583 | |||
584 | if (!dev) | ||
585 | return -ENODEV; | ||
586 | |||
587 | pdata = dev->platform_data; | ||
588 | if (!pdata) { | ||
589 | dev_warn(dev, "Platform data not found for htcpld core!\n"); | ||
590 | return -ENXIO; | ||
591 | } | ||
592 | |||
593 | htcpld = kzalloc(sizeof(struct htcpld_data), GFP_KERNEL); | ||
594 | if (!htcpld) | ||
595 | return -ENOMEM; | ||
596 | |||
597 | /* Find chained irq */ | ||
598 | ret = -EINVAL; | ||
599 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
600 | if (res) { | ||
601 | int flags; | ||
602 | htcpld->chained_irq = res->start; | ||
603 | |||
604 | /* Setup the chained interrupt handler */ | ||
605 | flags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING; | ||
606 | ret = request_threaded_irq(htcpld->chained_irq, | ||
607 | NULL, htcpld_handler, | ||
608 | flags, pdev->name, htcpld); | ||
609 | if (ret) { | ||
610 | dev_warn(dev, "Unable to setup chained irq handler: %d\n", ret); | ||
611 | goto fail; | ||
612 | } else | ||
613 | device_init_wakeup(dev, 0); | ||
614 | } | ||
615 | |||
616 | /* Set the driver data */ | ||
617 | platform_set_drvdata(pdev, htcpld); | ||
618 | |||
619 | /* Setup the htcpld chips */ | ||
620 | ret = htcpld_setup_chips(pdev); | ||
621 | if (ret) | ||
622 | goto fail; | ||
623 | |||
624 | /* Request the GPIO(s) for the int reset and set them up */ | ||
625 | if (pdata->int_reset_gpio_hi) { | ||
626 | ret = gpio_request(pdata->int_reset_gpio_hi, "htcpld-core"); | ||
627 | if (ret) { | ||
628 | /* | ||
629 | * If it failed, that sucks, but we can probably | ||
630 | * continue on without it. | ||
631 | */ | ||
632 | dev_warn(dev, "Unable to request int_reset_gpio_hi -- interrupts may not work\n"); | ||
633 | htcpld->int_reset_gpio_hi = 0; | ||
634 | } else { | ||
635 | htcpld->int_reset_gpio_hi = pdata->int_reset_gpio_hi; | ||
636 | gpio_set_value(htcpld->int_reset_gpio_hi, 1); | ||
637 | } | ||
638 | } | ||
639 | |||
640 | if (pdata->int_reset_gpio_lo) { | ||
641 | ret = gpio_request(pdata->int_reset_gpio_lo, "htcpld-core"); | ||
642 | if (ret) { | ||
643 | /* | ||
644 | * If it failed, that sucks, but we can probably | ||
645 | * continue on without it. | ||
646 | */ | ||
647 | dev_warn(dev, "Unable to request int_reset_gpio_lo -- interrupts may not work\n"); | ||
648 | htcpld->int_reset_gpio_lo = 0; | ||
649 | } else { | ||
650 | htcpld->int_reset_gpio_lo = pdata->int_reset_gpio_lo; | ||
651 | gpio_set_value(htcpld->int_reset_gpio_lo, 0); | ||
652 | } | ||
653 | } | ||
654 | |||
655 | dev_info(dev, "Initialized successfully\n"); | ||
656 | return 0; | ||
657 | |||
658 | fail: | ||
659 | kfree(htcpld); | ||
660 | return ret; | ||
661 | } | ||
662 | |||
663 | /* The I2C Driver -- used internally */ | ||
664 | static const struct i2c_device_id htcpld_chip_id[] = { | ||
665 | { "htcpld-chip", 0 }, | ||
666 | { } | ||
667 | }; | ||
668 | MODULE_DEVICE_TABLE(i2c, htcpld_chip_id); | ||
669 | |||
670 | |||
671 | static struct i2c_driver htcpld_chip_driver = { | ||
672 | .driver = { | ||
673 | .name = "htcpld-chip", | ||
674 | }, | ||
675 | .id_table = htcpld_chip_id, | ||
676 | }; | ||
677 | |||
678 | /* The Core Driver */ | ||
679 | static struct platform_driver htcpld_core_driver = { | ||
680 | .driver = { | ||
681 | .name = "i2c-htcpld", | ||
682 | }, | ||
683 | }; | ||
684 | |||
685 | static int __init htcpld_core_init(void) | ||
686 | { | ||
687 | int ret; | ||
688 | |||
689 | /* Register the I2C Chip driver */ | ||
690 | ret = i2c_add_driver(&htcpld_chip_driver); | ||
691 | if (ret) | ||
692 | return ret; | ||
693 | |||
694 | /* Probe for our chips */ | ||
695 | return platform_driver_probe(&htcpld_core_driver, htcpld_core_probe); | ||
696 | } | ||
697 | |||
698 | static void __exit htcpld_core_exit(void) | ||
699 | { | ||
700 | i2c_del_driver(&htcpld_chip_driver); | ||
701 | platform_driver_unregister(&htcpld_core_driver); | ||
702 | } | ||
703 | |||
704 | module_init(htcpld_core_init); | ||
705 | module_exit(htcpld_core_exit); | ||
706 | |||
707 | MODULE_AUTHOR("Cory Maccarrone <darkstar6262@gmail.com>"); | ||
708 | MODULE_DESCRIPTION("I2C HTC PLD Driver"); | ||
709 | MODULE_LICENSE("GPL"); | ||
710 | |||
diff --git a/drivers/mfd/lpc_sch.c b/drivers/mfd/lpc_sch.c new file mode 100644 index 000000000000..51b2f6065a0b --- /dev/null +++ b/drivers/mfd/lpc_sch.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * lpc_sch.c - LPC interface for Intel Poulsbo SCH | ||
3 | * | ||
4 | * LPC bridge function of the Intel SCH contains many other | ||
5 | * functional units, such as Interrupt controllers, Timers, | ||
6 | * Power Management, System Management, GPIO, RTC, and LPC | ||
7 | * Configuration Registers. | ||
8 | * | ||
9 | * Copyright (c) 2010 CompuLab Ltd | ||
10 | * Author: Denis Turischev <denis@compulab.co.il> | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License 2 as published | ||
14 | * by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; see the file COPYING. If not, write to | ||
23 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | #include <linux/init.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/errno.h> | ||
30 | #include <linux/acpi.h> | ||
31 | #include <linux/pci.h> | ||
32 | #include <linux/mfd/core.h> | ||
33 | |||
34 | #define SMBASE 0x40 | ||
35 | #define SMBUS_IO_SIZE 64 | ||
36 | |||
37 | #define GPIOBASE 0x44 | ||
38 | #define GPIO_IO_SIZE 64 | ||
39 | |||
40 | static struct resource smbus_sch_resource = { | ||
41 | .flags = IORESOURCE_IO, | ||
42 | }; | ||
43 | |||
44 | |||
45 | static struct resource gpio_sch_resource = { | ||
46 | .flags = IORESOURCE_IO, | ||
47 | }; | ||
48 | |||
49 | static struct mfd_cell lpc_sch_cells[] = { | ||
50 | { | ||
51 | .name = "isch_smbus", | ||
52 | .num_resources = 1, | ||
53 | .resources = &smbus_sch_resource, | ||
54 | }, | ||
55 | { | ||
56 | .name = "sch_gpio", | ||
57 | .num_resources = 1, | ||
58 | .resources = &gpio_sch_resource, | ||
59 | }, | ||
60 | }; | ||
61 | |||
62 | static struct pci_device_id lpc_sch_ids[] = { | ||
63 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC) }, | ||
64 | { 0, } | ||
65 | }; | ||
66 | MODULE_DEVICE_TABLE(pci, lpc_sch_ids); | ||
67 | |||
68 | static int __devinit lpc_sch_probe(struct pci_dev *dev, | ||
69 | const struct pci_device_id *id) | ||
70 | { | ||
71 | unsigned int base_addr_cfg; | ||
72 | unsigned short base_addr; | ||
73 | |||
74 | pci_read_config_dword(dev, SMBASE, &base_addr_cfg); | ||
75 | if (!(base_addr_cfg & (1 << 31))) { | ||
76 | dev_err(&dev->dev, "Decode of the SMBus I/O range disabled\n"); | ||
77 | return -ENODEV; | ||
78 | } | ||
79 | base_addr = (unsigned short)base_addr_cfg; | ||
80 | if (base_addr == 0) { | ||
81 | dev_err(&dev->dev, "I/O space for SMBus uninitialized\n"); | ||
82 | return -ENODEV; | ||
83 | } | ||
84 | |||
85 | smbus_sch_resource.start = base_addr; | ||
86 | smbus_sch_resource.end = base_addr + SMBUS_IO_SIZE - 1; | ||
87 | |||
88 | pci_read_config_dword(dev, GPIOBASE, &base_addr_cfg); | ||
89 | if (!(base_addr_cfg & (1 << 31))) { | ||
90 | dev_err(&dev->dev, "Decode of the GPIO I/O range disabled\n"); | ||
91 | return -ENODEV; | ||
92 | } | ||
93 | base_addr = (unsigned short)base_addr_cfg; | ||
94 | if (base_addr == 0) { | ||
95 | dev_err(&dev->dev, "I/O space for GPIO uninitialized\n"); | ||
96 | return -ENODEV; | ||
97 | } | ||
98 | |||
99 | gpio_sch_resource.start = base_addr; | ||
100 | gpio_sch_resource.end = base_addr + GPIO_IO_SIZE - 1; | ||
101 | |||
102 | return mfd_add_devices(&dev->dev, -1, | ||
103 | lpc_sch_cells, ARRAY_SIZE(lpc_sch_cells), NULL, 0); | ||
104 | } | ||
105 | |||
106 | static void __devexit lpc_sch_remove(struct pci_dev *dev) | ||
107 | { | ||
108 | mfd_remove_devices(&dev->dev); | ||
109 | } | ||
110 | |||
111 | static struct pci_driver lpc_sch_driver = { | ||
112 | .name = "lpc_sch", | ||
113 | .id_table = lpc_sch_ids, | ||
114 | .probe = lpc_sch_probe, | ||
115 | .remove = __devexit_p(lpc_sch_remove), | ||
116 | }; | ||
117 | |||
118 | static int __init lpc_sch_init(void) | ||
119 | { | ||
120 | return pci_register_driver(&lpc_sch_driver); | ||
121 | } | ||
122 | |||
123 | static void __exit lpc_sch_exit(void) | ||
124 | { | ||
125 | pci_unregister_driver(&lpc_sch_driver); | ||
126 | } | ||
127 | |||
128 | module_init(lpc_sch_init); | ||
129 | module_exit(lpc_sch_exit); | ||
130 | |||
131 | MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); | ||
132 | MODULE_DESCRIPTION("LPC interface for Intel Poulsbo SCH"); | ||
133 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c new file mode 100644 index 000000000000..85d63c04749b --- /dev/null +++ b/drivers/mfd/max8925-core.c | |||
@@ -0,0 +1,656 @@ | |||
1 | /* | ||
2 | * Base driver for Maxim MAX8925 | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 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/i2c.h> | ||
15 | #include <linux/irq.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/mfd/core.h> | ||
19 | #include <linux/mfd/max8925.h> | ||
20 | |||
21 | static struct resource backlight_resources[] = { | ||
22 | { | ||
23 | .name = "max8925-backlight", | ||
24 | .start = MAX8925_WLED_MODE_CNTL, | ||
25 | .end = MAX8925_WLED_CNTL, | ||
26 | .flags = IORESOURCE_IO, | ||
27 | }, | ||
28 | }; | ||
29 | |||
30 | static struct mfd_cell backlight_devs[] = { | ||
31 | { | ||
32 | .name = "max8925-backlight", | ||
33 | .num_resources = 1, | ||
34 | .resources = &backlight_resources[0], | ||
35 | .id = -1, | ||
36 | }, | ||
37 | }; | ||
38 | |||
39 | static struct resource touch_resources[] = { | ||
40 | { | ||
41 | .name = "max8925-tsc", | ||
42 | .start = MAX8925_TSC_IRQ, | ||
43 | .end = MAX8925_ADC_RES_END, | ||
44 | .flags = IORESOURCE_IO, | ||
45 | }, | ||
46 | }; | ||
47 | |||
48 | static struct mfd_cell touch_devs[] = { | ||
49 | { | ||
50 | .name = "max8925-touch", | ||
51 | .num_resources = 1, | ||
52 | .resources = &touch_resources[0], | ||
53 | .id = -1, | ||
54 | }, | ||
55 | }; | ||
56 | |||
57 | static struct resource power_supply_resources[] = { | ||
58 | { | ||
59 | .name = "max8925-power", | ||
60 | .start = MAX8925_CHG_IRQ1, | ||
61 | .end = MAX8925_CHG_IRQ1_MASK, | ||
62 | .flags = IORESOURCE_IO, | ||
63 | }, | ||
64 | }; | ||
65 | |||
66 | static struct mfd_cell power_devs[] = { | ||
67 | { | ||
68 | .name = "max8925-power", | ||
69 | .num_resources = 1, | ||
70 | .resources = &power_supply_resources[0], | ||
71 | .id = -1, | ||
72 | }, | ||
73 | }; | ||
74 | |||
75 | static struct resource rtc_resources[] = { | ||
76 | { | ||
77 | .name = "max8925-rtc", | ||
78 | .start = MAX8925_RTC_IRQ, | ||
79 | .end = MAX8925_RTC_IRQ_MASK, | ||
80 | .flags = IORESOURCE_IO, | ||
81 | }, | ||
82 | }; | ||
83 | |||
84 | static struct mfd_cell rtc_devs[] = { | ||
85 | { | ||
86 | .name = "max8925-rtc", | ||
87 | .num_resources = 1, | ||
88 | .resources = &rtc_resources[0], | ||
89 | .id = -1, | ||
90 | }, | ||
91 | }; | ||
92 | |||
93 | #define MAX8925_REG_RESOURCE(_start, _end) \ | ||
94 | { \ | ||
95 | .start = MAX8925_##_start, \ | ||
96 | .end = MAX8925_##_end, \ | ||
97 | .flags = IORESOURCE_IO, \ | ||
98 | } | ||
99 | |||
100 | static struct resource regulator_resources[] = { | ||
101 | MAX8925_REG_RESOURCE(SDCTL1, SDCTL1), | ||
102 | MAX8925_REG_RESOURCE(SDCTL2, SDCTL2), | ||
103 | MAX8925_REG_RESOURCE(SDCTL3, SDCTL3), | ||
104 | MAX8925_REG_RESOURCE(LDOCTL1, LDOCTL1), | ||
105 | MAX8925_REG_RESOURCE(LDOCTL2, LDOCTL2), | ||
106 | MAX8925_REG_RESOURCE(LDOCTL3, LDOCTL3), | ||
107 | MAX8925_REG_RESOURCE(LDOCTL4, LDOCTL4), | ||
108 | MAX8925_REG_RESOURCE(LDOCTL5, LDOCTL5), | ||
109 | MAX8925_REG_RESOURCE(LDOCTL6, LDOCTL6), | ||
110 | MAX8925_REG_RESOURCE(LDOCTL7, LDOCTL7), | ||
111 | MAX8925_REG_RESOURCE(LDOCTL8, LDOCTL8), | ||
112 | MAX8925_REG_RESOURCE(LDOCTL9, LDOCTL9), | ||
113 | MAX8925_REG_RESOURCE(LDOCTL10, LDOCTL10), | ||
114 | MAX8925_REG_RESOURCE(LDOCTL11, LDOCTL11), | ||
115 | MAX8925_REG_RESOURCE(LDOCTL12, LDOCTL12), | ||
116 | MAX8925_REG_RESOURCE(LDOCTL13, LDOCTL13), | ||
117 | MAX8925_REG_RESOURCE(LDOCTL14, LDOCTL14), | ||
118 | MAX8925_REG_RESOURCE(LDOCTL15, LDOCTL15), | ||
119 | MAX8925_REG_RESOURCE(LDOCTL16, LDOCTL16), | ||
120 | MAX8925_REG_RESOURCE(LDOCTL17, LDOCTL17), | ||
121 | MAX8925_REG_RESOURCE(LDOCTL18, LDOCTL18), | ||
122 | MAX8925_REG_RESOURCE(LDOCTL19, LDOCTL19), | ||
123 | MAX8925_REG_RESOURCE(LDOCTL20, LDOCTL20), | ||
124 | }; | ||
125 | |||
126 | #define MAX8925_REG_DEVS(_id) \ | ||
127 | { \ | ||
128 | .name = "max8925-regulator", \ | ||
129 | .num_resources = 1, \ | ||
130 | .resources = ®ulator_resources[MAX8925_ID_##_id], \ | ||
131 | .id = MAX8925_ID_##_id, \ | ||
132 | } | ||
133 | |||
134 | static struct mfd_cell regulator_devs[] = { | ||
135 | MAX8925_REG_DEVS(SD1), | ||
136 | MAX8925_REG_DEVS(SD2), | ||
137 | MAX8925_REG_DEVS(SD3), | ||
138 | MAX8925_REG_DEVS(LDO1), | ||
139 | MAX8925_REG_DEVS(LDO2), | ||
140 | MAX8925_REG_DEVS(LDO3), | ||
141 | MAX8925_REG_DEVS(LDO4), | ||
142 | MAX8925_REG_DEVS(LDO5), | ||
143 | MAX8925_REG_DEVS(LDO6), | ||
144 | MAX8925_REG_DEVS(LDO7), | ||
145 | MAX8925_REG_DEVS(LDO8), | ||
146 | MAX8925_REG_DEVS(LDO9), | ||
147 | MAX8925_REG_DEVS(LDO10), | ||
148 | MAX8925_REG_DEVS(LDO11), | ||
149 | MAX8925_REG_DEVS(LDO12), | ||
150 | MAX8925_REG_DEVS(LDO13), | ||
151 | MAX8925_REG_DEVS(LDO14), | ||
152 | MAX8925_REG_DEVS(LDO15), | ||
153 | MAX8925_REG_DEVS(LDO16), | ||
154 | MAX8925_REG_DEVS(LDO17), | ||
155 | MAX8925_REG_DEVS(LDO18), | ||
156 | MAX8925_REG_DEVS(LDO19), | ||
157 | MAX8925_REG_DEVS(LDO20), | ||
158 | }; | ||
159 | |||
160 | enum { | ||
161 | FLAGS_ADC = 1, /* register in ADC component */ | ||
162 | FLAGS_RTC, /* register in RTC component */ | ||
163 | }; | ||
164 | |||
165 | struct max8925_irq_data { | ||
166 | int reg; | ||
167 | int mask_reg; | ||
168 | int enable; /* enable or not */ | ||
169 | int offs; /* bit offset in mask register */ | ||
170 | int flags; | ||
171 | int tsc_irq; | ||
172 | }; | ||
173 | |||
174 | static struct max8925_irq_data max8925_irqs[] = { | ||
175 | [MAX8925_IRQ_VCHG_DC_OVP] = { | ||
176 | .reg = MAX8925_CHG_IRQ1, | ||
177 | .mask_reg = MAX8925_CHG_IRQ1_MASK, | ||
178 | .offs = 1 << 0, | ||
179 | }, | ||
180 | [MAX8925_IRQ_VCHG_DC_F] = { | ||
181 | .reg = MAX8925_CHG_IRQ1, | ||
182 | .mask_reg = MAX8925_CHG_IRQ1_MASK, | ||
183 | .offs = 1 << 1, | ||
184 | }, | ||
185 | [MAX8925_IRQ_VCHG_DC_R] = { | ||
186 | .reg = MAX8925_CHG_IRQ1, | ||
187 | .mask_reg = MAX8925_CHG_IRQ1_MASK, | ||
188 | .offs = 1 << 2, | ||
189 | }, | ||
190 | [MAX8925_IRQ_VCHG_USB_OVP] = { | ||
191 | .reg = MAX8925_CHG_IRQ1, | ||
192 | .mask_reg = MAX8925_CHG_IRQ1_MASK, | ||
193 | .offs = 1 << 3, | ||
194 | }, | ||
195 | [MAX8925_IRQ_VCHG_USB_F] = { | ||
196 | .reg = MAX8925_CHG_IRQ1, | ||
197 | .mask_reg = MAX8925_CHG_IRQ1_MASK, | ||
198 | .offs = 1 << 4, | ||
199 | }, | ||
200 | [MAX8925_IRQ_VCHG_USB_R] = { | ||
201 | .reg = MAX8925_CHG_IRQ1, | ||
202 | .mask_reg = MAX8925_CHG_IRQ1_MASK, | ||
203 | .offs = 1 << 5, | ||
204 | }, | ||
205 | [MAX8925_IRQ_VCHG_THM_OK_R] = { | ||
206 | .reg = MAX8925_CHG_IRQ2, | ||
207 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
208 | .offs = 1 << 0, | ||
209 | }, | ||
210 | [MAX8925_IRQ_VCHG_THM_OK_F] = { | ||
211 | .reg = MAX8925_CHG_IRQ2, | ||
212 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
213 | .offs = 1 << 1, | ||
214 | }, | ||
215 | [MAX8925_IRQ_VCHG_SYSLOW_F] = { | ||
216 | .reg = MAX8925_CHG_IRQ2, | ||
217 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
218 | .offs = 1 << 2, | ||
219 | }, | ||
220 | [MAX8925_IRQ_VCHG_SYSLOW_R] = { | ||
221 | .reg = MAX8925_CHG_IRQ2, | ||
222 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
223 | .offs = 1 << 3, | ||
224 | }, | ||
225 | [MAX8925_IRQ_VCHG_RST] = { | ||
226 | .reg = MAX8925_CHG_IRQ2, | ||
227 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
228 | .offs = 1 << 4, | ||
229 | }, | ||
230 | [MAX8925_IRQ_VCHG_DONE] = { | ||
231 | .reg = MAX8925_CHG_IRQ2, | ||
232 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
233 | .offs = 1 << 5, | ||
234 | }, | ||
235 | [MAX8925_IRQ_VCHG_TOPOFF] = { | ||
236 | .reg = MAX8925_CHG_IRQ2, | ||
237 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
238 | .offs = 1 << 6, | ||
239 | }, | ||
240 | [MAX8925_IRQ_VCHG_TMR_FAULT] = { | ||
241 | .reg = MAX8925_CHG_IRQ2, | ||
242 | .mask_reg = MAX8925_CHG_IRQ2_MASK, | ||
243 | .offs = 1 << 7, | ||
244 | }, | ||
245 | [MAX8925_IRQ_GPM_RSTIN] = { | ||
246 | .reg = MAX8925_ON_OFF_IRQ1, | ||
247 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
248 | .offs = 1 << 0, | ||
249 | }, | ||
250 | [MAX8925_IRQ_GPM_MPL] = { | ||
251 | .reg = MAX8925_ON_OFF_IRQ1, | ||
252 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
253 | .offs = 1 << 1, | ||
254 | }, | ||
255 | [MAX8925_IRQ_GPM_SW_3SEC] = { | ||
256 | .reg = MAX8925_ON_OFF_IRQ1, | ||
257 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
258 | .offs = 1 << 2, | ||
259 | }, | ||
260 | [MAX8925_IRQ_GPM_EXTON_F] = { | ||
261 | .reg = MAX8925_ON_OFF_IRQ1, | ||
262 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
263 | .offs = 1 << 3, | ||
264 | }, | ||
265 | [MAX8925_IRQ_GPM_EXTON_R] = { | ||
266 | .reg = MAX8925_ON_OFF_IRQ1, | ||
267 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
268 | .offs = 1 << 4, | ||
269 | }, | ||
270 | [MAX8925_IRQ_GPM_SW_1SEC] = { | ||
271 | .reg = MAX8925_ON_OFF_IRQ1, | ||
272 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
273 | .offs = 1 << 5, | ||
274 | }, | ||
275 | [MAX8925_IRQ_GPM_SW_F] = { | ||
276 | .reg = MAX8925_ON_OFF_IRQ1, | ||
277 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
278 | .offs = 1 << 6, | ||
279 | }, | ||
280 | [MAX8925_IRQ_GPM_SW_R] = { | ||
281 | .reg = MAX8925_ON_OFF_IRQ1, | ||
282 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, | ||
283 | .offs = 1 << 7, | ||
284 | }, | ||
285 | [MAX8925_IRQ_GPM_SYSCKEN_F] = { | ||
286 | .reg = MAX8925_ON_OFF_IRQ2, | ||
287 | .mask_reg = MAX8925_ON_OFF_IRQ2_MASK, | ||
288 | .offs = 1 << 0, | ||
289 | }, | ||
290 | [MAX8925_IRQ_GPM_SYSCKEN_R] = { | ||
291 | .reg = MAX8925_ON_OFF_IRQ2, | ||
292 | .mask_reg = MAX8925_ON_OFF_IRQ2_MASK, | ||
293 | .offs = 1 << 1, | ||
294 | }, | ||
295 | [MAX8925_IRQ_RTC_ALARM1] = { | ||
296 | .reg = MAX8925_RTC_IRQ, | ||
297 | .mask_reg = MAX8925_RTC_IRQ_MASK, | ||
298 | .offs = 1 << 2, | ||
299 | .flags = FLAGS_RTC, | ||
300 | }, | ||
301 | [MAX8925_IRQ_RTC_ALARM0] = { | ||
302 | .reg = MAX8925_RTC_IRQ, | ||
303 | .mask_reg = MAX8925_RTC_IRQ_MASK, | ||
304 | .offs = 1 << 3, | ||
305 | .flags = FLAGS_RTC, | ||
306 | }, | ||
307 | [MAX8925_IRQ_TSC_STICK] = { | ||
308 | .reg = MAX8925_TSC_IRQ, | ||
309 | .mask_reg = MAX8925_TSC_IRQ_MASK, | ||
310 | .offs = 1 << 0, | ||
311 | .flags = FLAGS_ADC, | ||
312 | .tsc_irq = 1, | ||
313 | }, | ||
314 | [MAX8925_IRQ_TSC_NSTICK] = { | ||
315 | .reg = MAX8925_TSC_IRQ, | ||
316 | .mask_reg = MAX8925_TSC_IRQ_MASK, | ||
317 | .offs = 1 << 1, | ||
318 | .flags = FLAGS_ADC, | ||
319 | .tsc_irq = 1, | ||
320 | }, | ||
321 | }; | ||
322 | |||
323 | static inline struct max8925_irq_data *irq_to_max8925(struct max8925_chip *chip, | ||
324 | int irq) | ||
325 | { | ||
326 | return &max8925_irqs[irq - chip->irq_base]; | ||
327 | } | ||
328 | |||
329 | static irqreturn_t max8925_irq(int irq, void *data) | ||
330 | { | ||
331 | struct max8925_chip *chip = data; | ||
332 | struct max8925_irq_data *irq_data; | ||
333 | struct i2c_client *i2c; | ||
334 | int read_reg = -1, value = 0; | ||
335 | int i; | ||
336 | |||
337 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { | ||
338 | irq_data = &max8925_irqs[i]; | ||
339 | /* TSC IRQ should be serviced in max8925_tsc_irq() */ | ||
340 | if (irq_data->tsc_irq) | ||
341 | continue; | ||
342 | if (irq_data->flags == FLAGS_RTC) | ||
343 | i2c = chip->rtc; | ||
344 | else if (irq_data->flags == FLAGS_ADC) | ||
345 | i2c = chip->adc; | ||
346 | else | ||
347 | i2c = chip->i2c; | ||
348 | if (read_reg != irq_data->reg) { | ||
349 | read_reg = irq_data->reg; | ||
350 | value = max8925_reg_read(i2c, irq_data->reg); | ||
351 | } | ||
352 | if (value & irq_data->enable) | ||
353 | handle_nested_irq(chip->irq_base + i); | ||
354 | } | ||
355 | return IRQ_HANDLED; | ||
356 | } | ||
357 | |||
358 | static irqreturn_t max8925_tsc_irq(int irq, void *data) | ||
359 | { | ||
360 | struct max8925_chip *chip = data; | ||
361 | struct max8925_irq_data *irq_data; | ||
362 | struct i2c_client *i2c; | ||
363 | int read_reg = -1, value = 0; | ||
364 | int i; | ||
365 | |||
366 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { | ||
367 | irq_data = &max8925_irqs[i]; | ||
368 | /* non TSC IRQ should be serviced in max8925_irq() */ | ||
369 | if (!irq_data->tsc_irq) | ||
370 | continue; | ||
371 | if (irq_data->flags == FLAGS_RTC) | ||
372 | i2c = chip->rtc; | ||
373 | else if (irq_data->flags == FLAGS_ADC) | ||
374 | i2c = chip->adc; | ||
375 | else | ||
376 | i2c = chip->i2c; | ||
377 | if (read_reg != irq_data->reg) { | ||
378 | read_reg = irq_data->reg; | ||
379 | value = max8925_reg_read(i2c, irq_data->reg); | ||
380 | } | ||
381 | if (value & irq_data->enable) | ||
382 | handle_nested_irq(chip->irq_base + i); | ||
383 | } | ||
384 | return IRQ_HANDLED; | ||
385 | } | ||
386 | |||
387 | static void max8925_irq_lock(unsigned int irq) | ||
388 | { | ||
389 | struct max8925_chip *chip = get_irq_chip_data(irq); | ||
390 | |||
391 | mutex_lock(&chip->irq_lock); | ||
392 | } | ||
393 | |||
394 | static void max8925_irq_sync_unlock(unsigned int irq) | ||
395 | { | ||
396 | struct max8925_chip *chip = get_irq_chip_data(irq); | ||
397 | struct max8925_irq_data *irq_data; | ||
398 | static unsigned char cache_chg[2] = {0xff, 0xff}; | ||
399 | static unsigned char cache_on[2] = {0xff, 0xff}; | ||
400 | static unsigned char cache_rtc = 0xff, cache_tsc = 0xff; | ||
401 | unsigned char irq_chg[2], irq_on[2]; | ||
402 | unsigned char irq_rtc, irq_tsc; | ||
403 | int i; | ||
404 | |||
405 | /* Load cached value. In initial, all IRQs are masked */ | ||
406 | irq_chg[0] = cache_chg[0]; | ||
407 | irq_chg[1] = cache_chg[1]; | ||
408 | irq_on[0] = cache_on[0]; | ||
409 | irq_on[1] = cache_on[1]; | ||
410 | irq_rtc = cache_rtc; | ||
411 | irq_tsc = cache_tsc; | ||
412 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { | ||
413 | irq_data = &max8925_irqs[i]; | ||
414 | switch (irq_data->mask_reg) { | ||
415 | case MAX8925_CHG_IRQ1_MASK: | ||
416 | irq_chg[0] &= irq_data->enable; | ||
417 | break; | ||
418 | case MAX8925_CHG_IRQ2_MASK: | ||
419 | irq_chg[1] &= irq_data->enable; | ||
420 | break; | ||
421 | case MAX8925_ON_OFF_IRQ1_MASK: | ||
422 | irq_on[0] &= irq_data->enable; | ||
423 | break; | ||
424 | case MAX8925_ON_OFF_IRQ2_MASK: | ||
425 | irq_on[1] &= irq_data->enable; | ||
426 | break; | ||
427 | case MAX8925_RTC_IRQ_MASK: | ||
428 | irq_rtc &= irq_data->enable; | ||
429 | break; | ||
430 | case MAX8925_TSC_IRQ_MASK: | ||
431 | irq_tsc &= irq_data->enable; | ||
432 | break; | ||
433 | default: | ||
434 | dev_err(chip->dev, "wrong IRQ\n"); | ||
435 | break; | ||
436 | } | ||
437 | } | ||
438 | /* update mask into registers */ | ||
439 | if (cache_chg[0] != irq_chg[0]) { | ||
440 | cache_chg[0] = irq_chg[0]; | ||
441 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, | ||
442 | irq_chg[0]); | ||
443 | } | ||
444 | if (cache_chg[1] != irq_chg[1]) { | ||
445 | cache_chg[1] = irq_chg[1]; | ||
446 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ2_MASK, | ||
447 | irq_chg[1]); | ||
448 | } | ||
449 | if (cache_on[0] != irq_on[0]) { | ||
450 | cache_on[0] = irq_on[0]; | ||
451 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, | ||
452 | irq_on[0]); | ||
453 | } | ||
454 | if (cache_on[1] != irq_on[1]) { | ||
455 | cache_on[1] = irq_on[1]; | ||
456 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, | ||
457 | irq_on[1]); | ||
458 | } | ||
459 | if (cache_rtc != irq_rtc) { | ||
460 | cache_rtc = irq_rtc; | ||
461 | max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, irq_rtc); | ||
462 | } | ||
463 | if (cache_tsc != irq_tsc) { | ||
464 | cache_tsc = irq_tsc; | ||
465 | max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, irq_tsc); | ||
466 | } | ||
467 | |||
468 | mutex_unlock(&chip->irq_lock); | ||
469 | } | ||
470 | |||
471 | static void max8925_irq_enable(unsigned int irq) | ||
472 | { | ||
473 | struct max8925_chip *chip = get_irq_chip_data(irq); | ||
474 | max8925_irqs[irq - chip->irq_base].enable | ||
475 | = max8925_irqs[irq - chip->irq_base].offs; | ||
476 | } | ||
477 | |||
478 | static void max8925_irq_disable(unsigned int irq) | ||
479 | { | ||
480 | struct max8925_chip *chip = get_irq_chip_data(irq); | ||
481 | max8925_irqs[irq - chip->irq_base].enable = 0; | ||
482 | } | ||
483 | |||
484 | static struct irq_chip max8925_irq_chip = { | ||
485 | .name = "max8925", | ||
486 | .bus_lock = max8925_irq_lock, | ||
487 | .bus_sync_unlock = max8925_irq_sync_unlock, | ||
488 | .enable = max8925_irq_enable, | ||
489 | .disable = max8925_irq_disable, | ||
490 | }; | ||
491 | |||
492 | static int max8925_irq_init(struct max8925_chip *chip, int irq, | ||
493 | struct max8925_platform_data *pdata) | ||
494 | { | ||
495 | unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; | ||
496 | struct irq_desc *desc; | ||
497 | int i, ret; | ||
498 | int __irq; | ||
499 | |||
500 | if (!pdata || !pdata->irq_base) { | ||
501 | dev_warn(chip->dev, "No interrupt support on IRQ base\n"); | ||
502 | return -EINVAL; | ||
503 | } | ||
504 | /* clear all interrupts */ | ||
505 | max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ1); | ||
506 | max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ2); | ||
507 | max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ1); | ||
508 | max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ2); | ||
509 | max8925_reg_read(chip->rtc, MAX8925_RTC_IRQ); | ||
510 | max8925_reg_read(chip->adc, MAX8925_TSC_IRQ); | ||
511 | /* mask all interrupts */ | ||
512 | max8925_reg_write(chip->rtc, MAX8925_ALARM0_CNTL, 0); | ||
513 | max8925_reg_write(chip->rtc, MAX8925_ALARM1_CNTL, 0); | ||
514 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, 0xff); | ||
515 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ2_MASK, 0xff); | ||
516 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, 0xff); | ||
517 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, 0xff); | ||
518 | max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, 0xff); | ||
519 | max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, 0xff); | ||
520 | |||
521 | mutex_init(&chip->irq_lock); | ||
522 | chip->core_irq = irq; | ||
523 | chip->irq_base = pdata->irq_base; | ||
524 | desc = irq_to_desc(chip->core_irq); | ||
525 | |||
526 | /* register with genirq */ | ||
527 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { | ||
528 | __irq = i + chip->irq_base; | ||
529 | set_irq_chip_data(__irq, chip); | ||
530 | set_irq_chip_and_handler(__irq, &max8925_irq_chip, | ||
531 | handle_edge_irq); | ||
532 | set_irq_nested_thread(__irq, 1); | ||
533 | #ifdef CONFIG_ARM | ||
534 | set_irq_flags(__irq, IRQF_VALID); | ||
535 | #else | ||
536 | set_irq_noprobe(__irq); | ||
537 | #endif | ||
538 | } | ||
539 | if (!irq) { | ||
540 | dev_warn(chip->dev, "No interrupt support on core IRQ\n"); | ||
541 | goto tsc_irq; | ||
542 | } | ||
543 | |||
544 | ret = request_threaded_irq(irq, NULL, max8925_irq, flags, | ||
545 | "max8925", chip); | ||
546 | if (ret) { | ||
547 | dev_err(chip->dev, "Failed to request core IRQ: %d\n", ret); | ||
548 | chip->core_irq = 0; | ||
549 | } | ||
550 | tsc_irq: | ||
551 | if (!pdata->tsc_irq) { | ||
552 | dev_warn(chip->dev, "No interrupt support on TSC IRQ\n"); | ||
553 | return 0; | ||
554 | } | ||
555 | chip->tsc_irq = pdata->tsc_irq; | ||
556 | |||
557 | ret = request_threaded_irq(chip->tsc_irq, NULL, max8925_tsc_irq, | ||
558 | flags, "max8925-tsc", chip); | ||
559 | if (ret) { | ||
560 | dev_err(chip->dev, "Failed to request TSC IRQ: %d\n", ret); | ||
561 | chip->tsc_irq = 0; | ||
562 | } | ||
563 | return 0; | ||
564 | } | ||
565 | |||
566 | int __devinit max8925_device_init(struct max8925_chip *chip, | ||
567 | struct max8925_platform_data *pdata) | ||
568 | { | ||
569 | int ret; | ||
570 | |||
571 | max8925_irq_init(chip, chip->i2c->irq, pdata); | ||
572 | |||
573 | if (pdata && (pdata->power || pdata->touch)) { | ||
574 | /* enable ADC to control internal reference */ | ||
575 | max8925_set_bits(chip->i2c, MAX8925_RESET_CNFG, 1, 1); | ||
576 | /* enable internal reference for ADC */ | ||
577 | max8925_set_bits(chip->adc, MAX8925_TSC_CNFG1, 3, 2); | ||
578 | /* check for internal reference IRQ */ | ||
579 | do { | ||
580 | ret = max8925_reg_read(chip->adc, MAX8925_TSC_IRQ); | ||
581 | } while (ret & MAX8925_NREF_OK); | ||
582 | /* enaable ADC scheduler, interval is 1 second */ | ||
583 | max8925_set_bits(chip->adc, MAX8925_ADC_SCHED, 3, 2); | ||
584 | } | ||
585 | |||
586 | /* enable Momentary Power Loss */ | ||
587 | max8925_set_bits(chip->rtc, MAX8925_MPL_CNTL, 1 << 4, 1 << 4); | ||
588 | |||
589 | ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], | ||
590 | ARRAY_SIZE(rtc_devs), | ||
591 | &rtc_resources[0], 0); | ||
592 | if (ret < 0) { | ||
593 | dev_err(chip->dev, "Failed to add rtc subdev\n"); | ||
594 | goto out; | ||
595 | } | ||
596 | if (pdata && pdata->regulator[0]) { | ||
597 | ret = mfd_add_devices(chip->dev, 0, ®ulator_devs[0], | ||
598 | ARRAY_SIZE(regulator_devs), | ||
599 | ®ulator_resources[0], 0); | ||
600 | if (ret < 0) { | ||
601 | dev_err(chip->dev, "Failed to add regulator subdev\n"); | ||
602 | goto out_dev; | ||
603 | } | ||
604 | } | ||
605 | |||
606 | if (pdata && pdata->backlight) { | ||
607 | ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0], | ||
608 | ARRAY_SIZE(backlight_devs), | ||
609 | &backlight_resources[0], 0); | ||
610 | if (ret < 0) { | ||
611 | dev_err(chip->dev, "Failed to add backlight subdev\n"); | ||
612 | goto out_dev; | ||
613 | } | ||
614 | } | ||
615 | |||
616 | if (pdata && pdata->power) { | ||
617 | ret = mfd_add_devices(chip->dev, 0, &power_devs[0], | ||
618 | ARRAY_SIZE(power_devs), | ||
619 | &power_supply_resources[0], 0); | ||
620 | if (ret < 0) { | ||
621 | dev_err(chip->dev, "Failed to add power supply " | ||
622 | "subdev\n"); | ||
623 | goto out_dev; | ||
624 | } | ||
625 | } | ||
626 | |||
627 | if (pdata && pdata->touch) { | ||
628 | ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], | ||
629 | ARRAY_SIZE(touch_devs), | ||
630 | &touch_resources[0], 0); | ||
631 | if (ret < 0) { | ||
632 | dev_err(chip->dev, "Failed to add touch subdev\n"); | ||
633 | goto out_dev; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | return 0; | ||
638 | out_dev: | ||
639 | mfd_remove_devices(chip->dev); | ||
640 | out: | ||
641 | return ret; | ||
642 | } | ||
643 | |||
644 | void __devexit max8925_device_exit(struct max8925_chip *chip) | ||
645 | { | ||
646 | if (chip->core_irq) | ||
647 | free_irq(chip->core_irq, chip); | ||
648 | if (chip->tsc_irq) | ||
649 | free_irq(chip->tsc_irq, chip); | ||
650 | mfd_remove_devices(chip->dev); | ||
651 | } | ||
652 | |||
653 | |||
654 | MODULE_DESCRIPTION("PMIC Driver for Maxim MAX8925"); | ||
655 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com"); | ||
656 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c new file mode 100644 index 000000000000..c0b883c14f41 --- /dev/null +++ b/drivers/mfd/max8925-i2c.c | |||
@@ -0,0 +1,211 @@ | |||
1 | /* | ||
2 | * I2C driver for Maxim MAX8925 | ||
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/max8925.h> | ||
16 | |||
17 | #define RTC_I2C_ADDR 0x68 | ||
18 | #define ADC_I2C_ADDR 0x47 | ||
19 | |||
20 | static inline int max8925_read_device(struct i2c_client *i2c, | ||
21 | int reg, int bytes, void *dest) | ||
22 | { | ||
23 | int ret; | ||
24 | |||
25 | if (bytes > 1) | ||
26 | ret = i2c_smbus_read_i2c_block_data(i2c, reg, bytes, dest); | ||
27 | else { | ||
28 | ret = i2c_smbus_read_byte_data(i2c, reg); | ||
29 | if (ret < 0) | ||
30 | return ret; | ||
31 | *(unsigned char *)dest = (unsigned char)ret; | ||
32 | } | ||
33 | return ret; | ||
34 | } | ||
35 | |||
36 | static inline int max8925_write_device(struct i2c_client *i2c, | ||
37 | int reg, int bytes, void *src) | ||
38 | { | ||
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 max8925_reg_read(struct i2c_client *i2c, int reg) | ||
52 | { | ||
53 | struct max8925_chip *chip = i2c_get_clientdata(i2c); | ||
54 | unsigned char data = 0; | ||
55 | int ret; | ||
56 | |||
57 | mutex_lock(&chip->io_lock); | ||
58 | ret = max8925_read_device(i2c, reg, 1, &data); | ||
59 | mutex_unlock(&chip->io_lock); | ||
60 | |||
61 | if (ret < 0) | ||
62 | return ret; | ||
63 | else | ||
64 | return (int)data; | ||
65 | } | ||
66 | EXPORT_SYMBOL(max8925_reg_read); | ||
67 | |||
68 | int max8925_reg_write(struct i2c_client *i2c, int reg, | ||
69 | unsigned char data) | ||
70 | { | ||
71 | struct max8925_chip *chip = i2c_get_clientdata(i2c); | ||
72 | int ret; | ||
73 | |||
74 | mutex_lock(&chip->io_lock); | ||
75 | ret = max8925_write_device(i2c, reg, 1, &data); | ||
76 | mutex_unlock(&chip->io_lock); | ||
77 | |||
78 | return ret; | ||
79 | } | ||
80 | EXPORT_SYMBOL(max8925_reg_write); | ||
81 | |||
82 | int max8925_bulk_read(struct i2c_client *i2c, int reg, | ||
83 | int count, unsigned char *buf) | ||
84 | { | ||
85 | struct max8925_chip *chip = i2c_get_clientdata(i2c); | ||
86 | int ret; | ||
87 | |||
88 | mutex_lock(&chip->io_lock); | ||
89 | ret = max8925_read_device(i2c, reg, count, buf); | ||
90 | mutex_unlock(&chip->io_lock); | ||
91 | |||
92 | return ret; | ||
93 | } | ||
94 | EXPORT_SYMBOL(max8925_bulk_read); | ||
95 | |||
96 | int max8925_bulk_write(struct i2c_client *i2c, int reg, | ||
97 | int count, unsigned char *buf) | ||
98 | { | ||
99 | struct max8925_chip *chip = i2c_get_clientdata(i2c); | ||
100 | int ret; | ||
101 | |||
102 | mutex_lock(&chip->io_lock); | ||
103 | ret = max8925_write_device(i2c, reg, count, buf); | ||
104 | mutex_unlock(&chip->io_lock); | ||
105 | |||
106 | return ret; | ||
107 | } | ||
108 | EXPORT_SYMBOL(max8925_bulk_write); | ||
109 | |||
110 | int max8925_set_bits(struct i2c_client *i2c, int reg, | ||
111 | unsigned char mask, unsigned char data) | ||
112 | { | ||
113 | struct max8925_chip *chip = i2c_get_clientdata(i2c); | ||
114 | unsigned char value; | ||
115 | int ret; | ||
116 | |||
117 | mutex_lock(&chip->io_lock); | ||
118 | ret = max8925_read_device(i2c, reg, 1, &value); | ||
119 | if (ret < 0) | ||
120 | goto out; | ||
121 | value &= ~mask; | ||
122 | value |= data; | ||
123 | ret = max8925_write_device(i2c, reg, 1, &value); | ||
124 | out: | ||
125 | mutex_unlock(&chip->io_lock); | ||
126 | return ret; | ||
127 | } | ||
128 | EXPORT_SYMBOL(max8925_set_bits); | ||
129 | |||
130 | |||
131 | static const struct i2c_device_id max8925_id_table[] = { | ||
132 | { "max8925", 0 }, | ||
133 | { }, | ||
134 | }; | ||
135 | MODULE_DEVICE_TABLE(i2c, max8925_id_table); | ||
136 | |||
137 | static int __devinit max8925_probe(struct i2c_client *client, | ||
138 | const struct i2c_device_id *id) | ||
139 | { | ||
140 | struct max8925_platform_data *pdata = client->dev.platform_data; | ||
141 | static struct max8925_chip *chip; | ||
142 | |||
143 | if (!pdata) { | ||
144 | pr_info("%s: platform data is missing\n", __func__); | ||
145 | return -EINVAL; | ||
146 | } | ||
147 | |||
148 | chip = kzalloc(sizeof(struct max8925_chip), GFP_KERNEL); | ||
149 | if (chip == NULL) | ||
150 | return -ENOMEM; | ||
151 | chip->i2c = client; | ||
152 | chip->dev = &client->dev; | ||
153 | i2c_set_clientdata(client, chip); | ||
154 | dev_set_drvdata(chip->dev, chip); | ||
155 | mutex_init(&chip->io_lock); | ||
156 | |||
157 | chip->rtc = i2c_new_dummy(chip->i2c->adapter, RTC_I2C_ADDR); | ||
158 | i2c_set_clientdata(chip->rtc, chip); | ||
159 | |||
160 | chip->adc = i2c_new_dummy(chip->i2c->adapter, ADC_I2C_ADDR); | ||
161 | i2c_set_clientdata(chip->adc, chip); | ||
162 | |||
163 | max8925_device_init(chip, pdata); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int __devexit max8925_remove(struct i2c_client *client) | ||
169 | { | ||
170 | struct max8925_chip *chip = i2c_get_clientdata(client); | ||
171 | |||
172 | max8925_device_exit(chip); | ||
173 | i2c_unregister_device(chip->adc); | ||
174 | i2c_unregister_device(chip->rtc); | ||
175 | i2c_set_clientdata(chip->adc, NULL); | ||
176 | i2c_set_clientdata(chip->rtc, NULL); | ||
177 | i2c_set_clientdata(chip->i2c, NULL); | ||
178 | kfree(chip); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static struct i2c_driver max8925_driver = { | ||
183 | .driver = { | ||
184 | .name = "max8925", | ||
185 | .owner = THIS_MODULE, | ||
186 | }, | ||
187 | .probe = max8925_probe, | ||
188 | .remove = __devexit_p(max8925_remove), | ||
189 | .id_table = max8925_id_table, | ||
190 | }; | ||
191 | |||
192 | static int __init max8925_i2c_init(void) | ||
193 | { | ||
194 | int ret; | ||
195 | |||
196 | ret = i2c_add_driver(&max8925_driver); | ||
197 | if (ret != 0) | ||
198 | pr_err("Failed to register MAX8925 I2C driver: %d\n", ret); | ||
199 | return ret; | ||
200 | } | ||
201 | subsys_initcall(max8925_i2c_init); | ||
202 | |||
203 | static void __exit max8925_i2c_exit(void) | ||
204 | { | ||
205 | i2c_del_driver(&max8925_driver); | ||
206 | } | ||
207 | module_exit(max8925_i2c_exit); | ||
208 | |||
209 | MODULE_DESCRIPTION("I2C Driver for Maxim 8925"); | ||
210 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
211 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c index 735c8a4d164f..62a847e4c2d8 100644 --- a/drivers/mfd/mc13783-core.c +++ b/drivers/mfd/mc13783-core.c | |||
@@ -225,7 +225,7 @@ int mc13783_reg_rmw(struct mc13783 *mc13783, unsigned int offset, | |||
225 | } | 225 | } |
226 | EXPORT_SYMBOL(mc13783_reg_rmw); | 226 | EXPORT_SYMBOL(mc13783_reg_rmw); |
227 | 227 | ||
228 | int mc13783_mask(struct mc13783 *mc13783, int irq) | 228 | int mc13783_irq_mask(struct mc13783 *mc13783, int irq) |
229 | { | 229 | { |
230 | int ret; | 230 | int ret; |
231 | unsigned int offmask = irq < 24 ? MC13783_IRQMASK0 : MC13783_IRQMASK1; | 231 | unsigned int offmask = irq < 24 ? MC13783_IRQMASK0 : MC13783_IRQMASK1; |
@@ -245,9 +245,9 @@ int mc13783_mask(struct mc13783 *mc13783, int irq) | |||
245 | 245 | ||
246 | return mc13783_reg_write(mc13783, offmask, mask | irqbit); | 246 | return mc13783_reg_write(mc13783, offmask, mask | irqbit); |
247 | } | 247 | } |
248 | EXPORT_SYMBOL(mc13783_mask); | 248 | EXPORT_SYMBOL(mc13783_irq_mask); |
249 | 249 | ||
250 | int mc13783_unmask(struct mc13783 *mc13783, int irq) | 250 | int mc13783_irq_unmask(struct mc13783 *mc13783, int irq) |
251 | { | 251 | { |
252 | int ret; | 252 | int ret; |
253 | unsigned int offmask = irq < 24 ? MC13783_IRQMASK0 : MC13783_IRQMASK1; | 253 | unsigned int offmask = irq < 24 ? MC13783_IRQMASK0 : MC13783_IRQMASK1; |
@@ -267,7 +267,53 @@ int mc13783_unmask(struct mc13783 *mc13783, int irq) | |||
267 | 267 | ||
268 | return mc13783_reg_write(mc13783, offmask, mask & ~irqbit); | 268 | return mc13783_reg_write(mc13783, offmask, mask & ~irqbit); |
269 | } | 269 | } |
270 | EXPORT_SYMBOL(mc13783_unmask); | 270 | EXPORT_SYMBOL(mc13783_irq_unmask); |
271 | |||
272 | int mc13783_irq_status(struct mc13783 *mc13783, int irq, | ||
273 | int *enabled, int *pending) | ||
274 | { | ||
275 | int ret; | ||
276 | unsigned int offmask = irq < 24 ? MC13783_IRQMASK0 : MC13783_IRQMASK1; | ||
277 | unsigned int offstat = irq < 24 ? MC13783_IRQSTAT0 : MC13783_IRQSTAT1; | ||
278 | u32 irqbit = 1 << (irq < 24 ? irq : irq - 24); | ||
279 | |||
280 | if (irq < 0 || irq >= MC13783_NUM_IRQ) | ||
281 | return -EINVAL; | ||
282 | |||
283 | if (enabled) { | ||
284 | u32 mask; | ||
285 | |||
286 | ret = mc13783_reg_read(mc13783, offmask, &mask); | ||
287 | if (ret) | ||
288 | return ret; | ||
289 | |||
290 | *enabled = mask & irqbit; | ||
291 | } | ||
292 | |||
293 | if (pending) { | ||
294 | u32 stat; | ||
295 | |||
296 | ret = mc13783_reg_read(mc13783, offstat, &stat); | ||
297 | if (ret) | ||
298 | return ret; | ||
299 | |||
300 | *pending = stat & irqbit; | ||
301 | } | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | EXPORT_SYMBOL(mc13783_irq_status); | ||
306 | |||
307 | int mc13783_irq_ack(struct mc13783 *mc13783, int irq) | ||
308 | { | ||
309 | unsigned int offstat = irq < 24 ? MC13783_IRQSTAT0 : MC13783_IRQSTAT1; | ||
310 | unsigned int val = 1 << (irq < 24 ? irq : irq - 24); | ||
311 | |||
312 | BUG_ON(irq < 0 || irq >= MC13783_NUM_IRQ); | ||
313 | |||
314 | return mc13783_reg_write(mc13783, offstat, val); | ||
315 | } | ||
316 | EXPORT_SYMBOL(mc13783_irq_ack); | ||
271 | 317 | ||
272 | int mc13783_irq_request_nounmask(struct mc13783 *mc13783, int irq, | 318 | int mc13783_irq_request_nounmask(struct mc13783 *mc13783, int irq, |
273 | irq_handler_t handler, const char *name, void *dev) | 319 | irq_handler_t handler, const char *name, void *dev) |
@@ -297,7 +343,7 @@ int mc13783_irq_request(struct mc13783 *mc13783, int irq, | |||
297 | if (ret) | 343 | if (ret) |
298 | return ret; | 344 | return ret; |
299 | 345 | ||
300 | ret = mc13783_unmask(mc13783, irq); | 346 | ret = mc13783_irq_unmask(mc13783, irq); |
301 | if (ret) { | 347 | if (ret) { |
302 | mc13783->irqhandler[irq] = NULL; | 348 | mc13783->irqhandler[irq] = NULL; |
303 | mc13783->irqdata[irq] = NULL; | 349 | mc13783->irqdata[irq] = NULL; |
@@ -317,7 +363,7 @@ int mc13783_irq_free(struct mc13783 *mc13783, int irq, void *dev) | |||
317 | mc13783->irqdata[irq] != dev) | 363 | mc13783->irqdata[irq] != dev) |
318 | return -EINVAL; | 364 | return -EINVAL; |
319 | 365 | ||
320 | ret = mc13783_mask(mc13783, irq); | 366 | ret = mc13783_irq_mask(mc13783, irq); |
321 | if (ret) | 367 | if (ret) |
322 | return ret; | 368 | return ret; |
323 | 369 | ||
@@ -333,17 +379,6 @@ static inline irqreturn_t mc13783_irqhandler(struct mc13783 *mc13783, int irq) | |||
333 | return mc13783->irqhandler[irq](irq, mc13783->irqdata[irq]); | 379 | return mc13783->irqhandler[irq](irq, mc13783->irqdata[irq]); |
334 | } | 380 | } |
335 | 381 | ||
336 | int mc13783_ackirq(struct mc13783 *mc13783, int irq) | ||
337 | { | ||
338 | unsigned int offstat = irq < 24 ? MC13783_IRQSTAT0 : MC13783_IRQSTAT1; | ||
339 | unsigned int val = 1 << (irq < 24 ? irq : irq - 24); | ||
340 | |||
341 | BUG_ON(irq < 0 || irq >= MC13783_NUM_IRQ); | ||
342 | |||
343 | return mc13783_reg_write(mc13783, offstat, val); | ||
344 | } | ||
345 | EXPORT_SYMBOL(mc13783_ackirq); | ||
346 | |||
347 | /* | 382 | /* |
348 | * returns: number of handled irqs or negative error | 383 | * returns: number of handled irqs or negative error |
349 | * locking: holds mc13783->lock | 384 | * locking: holds mc13783->lock |
@@ -422,7 +457,7 @@ static irqreturn_t mc13783_handler_adcdone(int irq, void *data) | |||
422 | { | 457 | { |
423 | struct mc13783_adcdone_data *adcdone_data = data; | 458 | struct mc13783_adcdone_data *adcdone_data = data; |
424 | 459 | ||
425 | mc13783_ackirq(adcdone_data->mc13783, irq); | 460 | mc13783_irq_ack(adcdone_data->mc13783, irq); |
426 | 461 | ||
427 | complete_all(&adcdone_data->done); | 462 | complete_all(&adcdone_data->done); |
428 | 463 | ||
@@ -486,7 +521,7 @@ int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode, | |||
486 | dev_dbg(&mc13783->spidev->dev, "%s: request irq\n", __func__); | 521 | dev_dbg(&mc13783->spidev->dev, "%s: request irq\n", __func__); |
487 | mc13783_irq_request(mc13783, MC13783_IRQ_ADCDONE, | 522 | mc13783_irq_request(mc13783, MC13783_IRQ_ADCDONE, |
488 | mc13783_handler_adcdone, __func__, &adcdone_data); | 523 | mc13783_handler_adcdone, __func__, &adcdone_data); |
489 | mc13783_ackirq(mc13783, MC13783_IRQ_ADCDONE); | 524 | mc13783_irq_ack(mc13783, MC13783_IRQ_ADCDONE); |
490 | 525 | ||
491 | mc13783_reg_write(mc13783, MC13783_REG_ADC_0, adc0); | 526 | mc13783_reg_write(mc13783, MC13783_REG_ADC_0, adc0); |
492 | mc13783_reg_write(mc13783, MC13783_REG_ADC_1, adc1); | 527 | mc13783_reg_write(mc13783, MC13783_REG_ADC_1, adc1); |
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index ae15e495e20e..aa17f4bddc56 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
16 | #include <linux/acpi.h> | ||
16 | #include <linux/mfd/core.h> | 17 | #include <linux/mfd/core.h> |
17 | 18 | ||
18 | static int mfd_add_device(struct device *parent, int id, | 19 | static int mfd_add_device(struct device *parent, int id, |
@@ -62,6 +63,10 @@ static int mfd_add_device(struct device *parent, int id, | |||
62 | res[r].start = cell->resources[r].start; | 63 | res[r].start = cell->resources[r].start; |
63 | res[r].end = cell->resources[r].end; | 64 | res[r].end = cell->resources[r].end; |
64 | } | 65 | } |
66 | |||
67 | ret = acpi_check_resource_conflict(res); | ||
68 | if (ret) | ||
69 | goto fail_res; | ||
65 | } | 70 | } |
66 | 71 | ||
67 | platform_device_add_resources(pdev, res, cell->num_resources); | 72 | platform_device_add_resources(pdev, res, cell->num_resources); |
diff --git a/drivers/mfd/sh_mobile_sdhi.c b/drivers/mfd/sh_mobile_sdhi.c index 03efae8041ab..468fd366d4da 100644 --- a/drivers/mfd/sh_mobile_sdhi.c +++ b/drivers/mfd/sh_mobile_sdhi.c | |||
@@ -21,7 +21,7 @@ | |||
21 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
22 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
24 | 24 | #include <linux/mmc/host.h> | |
25 | #include <linux/mfd/core.h> | 25 | #include <linux/mfd/core.h> |
26 | #include <linux/mfd/tmio.h> | 26 | #include <linux/mfd/tmio.h> |
27 | #include <linux/mfd/sh_mobile_sdhi.h> | 27 | #include <linux/mfd/sh_mobile_sdhi.h> |
@@ -95,9 +95,9 @@ static int __init sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
95 | 95 | ||
96 | clk_enable(priv->clk); | 96 | clk_enable(priv->clk); |
97 | 97 | ||
98 | /* FIXME: silly const unsigned int hclk */ | 98 | priv->mmc_data.hclk = clk_get_rate(priv->clk); |
99 | *(unsigned int *)&priv->mmc_data.hclk = clk_get_rate(priv->clk); | ||
100 | priv->mmc_data.set_pwr = sh_mobile_sdhi_set_pwr; | 99 | priv->mmc_data.set_pwr = sh_mobile_sdhi_set_pwr; |
100 | priv->mmc_data.capabilities = MMC_CAP_MMC_HIGHSPEED; | ||
101 | 101 | ||
102 | memcpy(&priv->cell_mmc, &sh_mobile_sdhi_cell, sizeof(priv->cell_mmc)); | 102 | memcpy(&priv->cell_mmc, &sh_mobile_sdhi_cell, sizeof(priv->cell_mmc)); |
103 | priv->cell_mmc.driver_data = &priv->mmc_data; | 103 | priv->cell_mmc.driver_data = &priv->mmc_data; |
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c index 10491e4e305d..ff0718efb0ae 100644 --- a/drivers/mfd/sm501.c +++ b/drivers/mfd/sm501.c | |||
@@ -1430,7 +1430,7 @@ static int __devinit sm501_plat_probe(struct platform_device *dev) | |||
1430 | } | 1430 | } |
1431 | 1431 | ||
1432 | sm->regs_claim = request_mem_region(sm->io_res->start, | 1432 | sm->regs_claim = request_mem_region(sm->io_res->start, |
1433 | 0x100, "sm501"); | 1433 | resource_size(sm->io_res), "sm501"); |
1434 | 1434 | ||
1435 | if (sm->regs_claim == NULL) { | 1435 | if (sm->regs_claim == NULL) { |
1436 | dev_err(&dev->dev, "cannot claim registers\n"); | 1436 | dev_err(&dev->dev, "cannot claim registers\n"); |
@@ -1440,8 +1440,7 @@ static int __devinit sm501_plat_probe(struct platform_device *dev) | |||
1440 | 1440 | ||
1441 | platform_set_drvdata(dev, sm); | 1441 | platform_set_drvdata(dev, sm); |
1442 | 1442 | ||
1443 | sm->regs = ioremap(sm->io_res->start, | 1443 | sm->regs = ioremap(sm->io_res->start, resource_size(sm->io_res)); |
1444 | (sm->io_res->end - sm->io_res->start) - 1); | ||
1445 | 1444 | ||
1446 | if (sm->regs == NULL) { | 1445 | if (sm->regs == NULL) { |
1447 | dev_err(&dev->dev, "cannot remap registers\n"); | 1446 | dev_err(&dev->dev, "cannot remap registers\n"); |
@@ -1645,7 +1644,7 @@ static int __devinit sm501_pci_probe(struct pci_dev *dev, | |||
1645 | sm->mem_res = &dev->resource[0]; | 1644 | sm->mem_res = &dev->resource[0]; |
1646 | 1645 | ||
1647 | sm->regs_claim = request_mem_region(sm->io_res->start, | 1646 | sm->regs_claim = request_mem_region(sm->io_res->start, |
1648 | 0x100, "sm501"); | 1647 | resource_size(sm->io_res), "sm501"); |
1649 | if (sm->regs_claim == NULL) { | 1648 | if (sm->regs_claim == NULL) { |
1650 | dev_err(&dev->dev, "cannot claim registers\n"); | 1649 | dev_err(&dev->dev, "cannot claim registers\n"); |
1651 | err= -EBUSY; | 1650 | err= -EBUSY; |
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c index bcf4687d4af5..26d9176fca91 100644 --- a/drivers/mfd/t7l66xb.c +++ b/drivers/mfd/t7l66xb.c | |||
@@ -360,7 +360,7 @@ static int t7l66xb_probe(struct platform_device *dev) | |||
360 | if (ret) | 360 | if (ret) |
361 | goto err_request_scr; | 361 | goto err_request_scr; |
362 | 362 | ||
363 | t7l66xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1); | 363 | t7l66xb->scr = ioremap(rscr->start, resource_size(rscr)); |
364 | if (!t7l66xb->scr) { | 364 | if (!t7l66xb->scr) { |
365 | ret = -ENOMEM; | 365 | ret = -ENOMEM; |
366 | goto err_ioremap; | 366 | goto err_ioremap; |
@@ -403,12 +403,12 @@ static int t7l66xb_probe(struct platform_device *dev) | |||
403 | err_ioremap: | 403 | err_ioremap: |
404 | release_resource(&t7l66xb->rscr); | 404 | release_resource(&t7l66xb->rscr); |
405 | err_request_scr: | 405 | err_request_scr: |
406 | kfree(t7l66xb); | ||
407 | clk_put(t7l66xb->clk48m); | 406 | clk_put(t7l66xb->clk48m); |
408 | err_clk48m_get: | 407 | err_clk48m_get: |
409 | clk_put(t7l66xb->clk32k); | 408 | clk_put(t7l66xb->clk32k); |
410 | err_clk32k_get: | 409 | err_clk32k_get: |
411 | err_noirq: | 410 | err_noirq: |
411 | kfree(t7l66xb); | ||
412 | return ret; | 412 | return ret; |
413 | } | 413 | } |
414 | 414 | ||
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c index 4bc5a08a2b09..c59e5c5737d0 100644 --- a/drivers/mfd/tc6393xb.c +++ b/drivers/mfd/tc6393xb.c | |||
@@ -647,7 +647,7 @@ static int __devinit tc6393xb_probe(struct platform_device *dev) | |||
647 | if (ret) | 647 | if (ret) |
648 | goto err_request_scr; | 648 | goto err_request_scr; |
649 | 649 | ||
650 | tc6393xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1); | 650 | tc6393xb->scr = ioremap(rscr->start, resource_size(rscr)); |
651 | if (!tc6393xb->scr) { | 651 | if (!tc6393xb->scr) { |
652 | ret = -ENOMEM; | 652 | ret = -ENOMEM; |
653 | goto err_ioremap; | 653 | goto err_ioremap; |
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c new file mode 100644 index 000000000000..1ed44d283803 --- /dev/null +++ b/drivers/mfd/timberdale.c | |||
@@ -0,0 +1,727 @@ | |||
1 | /* | ||
2 | * timberdale.c timberdale FPGA MFD driver | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | /* Supports: | ||
20 | * Timberdale FPGA | ||
21 | */ | ||
22 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/msi.h> | ||
27 | #include <linux/mfd/core.h> | ||
28 | |||
29 | #include <linux/timb_gpio.h> | ||
30 | |||
31 | #include <linux/i2c.h> | ||
32 | #include <linux/i2c-ocores.h> | ||
33 | #include <linux/i2c/tsc2007.h> | ||
34 | |||
35 | #include <linux/spi/spi.h> | ||
36 | #include <linux/spi/xilinx_spi.h> | ||
37 | #include <linux/spi/max7301.h> | ||
38 | #include <linux/spi/mc33880.h> | ||
39 | |||
40 | #include <media/timb_radio.h> | ||
41 | |||
42 | #include "timberdale.h" | ||
43 | |||
44 | #define DRIVER_NAME "timberdale" | ||
45 | |||
46 | struct timberdale_device { | ||
47 | resource_size_t ctl_mapbase; | ||
48 | unsigned char __iomem *ctl_membase; | ||
49 | struct { | ||
50 | u32 major; | ||
51 | u32 minor; | ||
52 | u32 config; | ||
53 | } fw; | ||
54 | }; | ||
55 | |||
56 | /*--------------------------------------------------------------------------*/ | ||
57 | |||
58 | static struct tsc2007_platform_data timberdale_tsc2007_platform_data = { | ||
59 | .model = 2003, | ||
60 | .x_plate_ohms = 100 | ||
61 | }; | ||
62 | |||
63 | static struct i2c_board_info timberdale_i2c_board_info[] = { | ||
64 | { | ||
65 | I2C_BOARD_INFO("tsc2007", 0x48), | ||
66 | .platform_data = &timberdale_tsc2007_platform_data, | ||
67 | .irq = IRQ_TIMBERDALE_TSC_INT | ||
68 | }, | ||
69 | }; | ||
70 | |||
71 | static __devinitdata struct ocores_i2c_platform_data | ||
72 | timberdale_ocores_platform_data = { | ||
73 | .regstep = 4, | ||
74 | .clock_khz = 62500, | ||
75 | .devices = timberdale_i2c_board_info, | ||
76 | .num_devices = ARRAY_SIZE(timberdale_i2c_board_info) | ||
77 | }; | ||
78 | |||
79 | const static __devinitconst struct resource timberdale_ocores_resources[] = { | ||
80 | { | ||
81 | .start = OCORESOFFSET, | ||
82 | .end = OCORESEND, | ||
83 | .flags = IORESOURCE_MEM, | ||
84 | }, | ||
85 | { | ||
86 | .start = IRQ_TIMBERDALE_I2C, | ||
87 | .end = IRQ_TIMBERDALE_I2C, | ||
88 | .flags = IORESOURCE_IRQ, | ||
89 | }, | ||
90 | }; | ||
91 | |||
92 | const struct max7301_platform_data timberdale_max7301_platform_data = { | ||
93 | .base = 200 | ||
94 | }; | ||
95 | |||
96 | const struct mc33880_platform_data timberdale_mc33880_platform_data = { | ||
97 | .base = 100 | ||
98 | }; | ||
99 | |||
100 | static struct spi_board_info timberdale_spi_16bit_board_info[] = { | ||
101 | { | ||
102 | .modalias = "max7301", | ||
103 | .max_speed_hz = 26000, | ||
104 | .chip_select = 2, | ||
105 | .mode = SPI_MODE_0, | ||
106 | .platform_data = &timberdale_max7301_platform_data | ||
107 | }, | ||
108 | }; | ||
109 | |||
110 | static struct spi_board_info timberdale_spi_8bit_board_info[] = { | ||
111 | { | ||
112 | .modalias = "mc33880", | ||
113 | .max_speed_hz = 4000, | ||
114 | .chip_select = 1, | ||
115 | .mode = SPI_MODE_1, | ||
116 | .platform_data = &timberdale_mc33880_platform_data | ||
117 | }, | ||
118 | }; | ||
119 | |||
120 | static __devinitdata struct xspi_platform_data timberdale_xspi_platform_data = { | ||
121 | .num_chipselect = 3, | ||
122 | .little_endian = true, | ||
123 | /* bits per word and devices will be filled in runtime depending | ||
124 | * on the HW config | ||
125 | */ | ||
126 | }; | ||
127 | |||
128 | const static __devinitconst struct resource timberdale_spi_resources[] = { | ||
129 | { | ||
130 | .start = SPIOFFSET, | ||
131 | .end = SPIEND, | ||
132 | .flags = IORESOURCE_MEM, | ||
133 | }, | ||
134 | { | ||
135 | .start = IRQ_TIMBERDALE_SPI, | ||
136 | .end = IRQ_TIMBERDALE_SPI, | ||
137 | .flags = IORESOURCE_IRQ, | ||
138 | }, | ||
139 | }; | ||
140 | |||
141 | const static __devinitconst struct resource timberdale_eth_resources[] = { | ||
142 | { | ||
143 | .start = ETHOFFSET, | ||
144 | .end = ETHEND, | ||
145 | .flags = IORESOURCE_MEM, | ||
146 | }, | ||
147 | { | ||
148 | .start = IRQ_TIMBERDALE_ETHSW_IF, | ||
149 | .end = IRQ_TIMBERDALE_ETHSW_IF, | ||
150 | .flags = IORESOURCE_IRQ, | ||
151 | }, | ||
152 | }; | ||
153 | |||
154 | static __devinitdata struct timbgpio_platform_data | ||
155 | timberdale_gpio_platform_data = { | ||
156 | .gpio_base = 0, | ||
157 | .nr_pins = GPIO_NR_PINS, | ||
158 | .irq_base = 200, | ||
159 | }; | ||
160 | |||
161 | const static __devinitconst struct resource timberdale_gpio_resources[] = { | ||
162 | { | ||
163 | .start = GPIOOFFSET, | ||
164 | .end = GPIOEND, | ||
165 | .flags = IORESOURCE_MEM, | ||
166 | }, | ||
167 | { | ||
168 | .start = IRQ_TIMBERDALE_GPIO, | ||
169 | .end = IRQ_TIMBERDALE_GPIO, | ||
170 | .flags = IORESOURCE_IRQ, | ||
171 | }, | ||
172 | }; | ||
173 | |||
174 | const static __devinitconst struct resource timberdale_mlogicore_resources[] = { | ||
175 | { | ||
176 | .start = MLCOREOFFSET, | ||
177 | .end = MLCOREEND, | ||
178 | .flags = IORESOURCE_MEM, | ||
179 | }, | ||
180 | { | ||
181 | .start = IRQ_TIMBERDALE_MLCORE, | ||
182 | .end = IRQ_TIMBERDALE_MLCORE, | ||
183 | .flags = IORESOURCE_IRQ, | ||
184 | }, | ||
185 | { | ||
186 | .start = IRQ_TIMBERDALE_MLCORE_BUF, | ||
187 | .end = IRQ_TIMBERDALE_MLCORE_BUF, | ||
188 | .flags = IORESOURCE_IRQ, | ||
189 | }, | ||
190 | }; | ||
191 | |||
192 | const static __devinitconst struct resource timberdale_uart_resources[] = { | ||
193 | { | ||
194 | .start = UARTOFFSET, | ||
195 | .end = UARTEND, | ||
196 | .flags = IORESOURCE_MEM, | ||
197 | }, | ||
198 | { | ||
199 | .start = IRQ_TIMBERDALE_UART, | ||
200 | .end = IRQ_TIMBERDALE_UART, | ||
201 | .flags = IORESOURCE_IRQ, | ||
202 | }, | ||
203 | }; | ||
204 | |||
205 | const static __devinitconst struct resource timberdale_uartlite_resources[] = { | ||
206 | { | ||
207 | .start = UARTLITEOFFSET, | ||
208 | .end = UARTLITEEND, | ||
209 | .flags = IORESOURCE_MEM, | ||
210 | }, | ||
211 | { | ||
212 | .start = IRQ_TIMBERDALE_UARTLITE, | ||
213 | .end = IRQ_TIMBERDALE_UARTLITE, | ||
214 | .flags = IORESOURCE_IRQ, | ||
215 | }, | ||
216 | }; | ||
217 | |||
218 | const static __devinitconst struct resource timberdale_radio_resources[] = { | ||
219 | { | ||
220 | .start = RDSOFFSET, | ||
221 | .end = RDSEND, | ||
222 | .flags = IORESOURCE_MEM, | ||
223 | }, | ||
224 | { | ||
225 | .start = IRQ_TIMBERDALE_RDS, | ||
226 | .end = IRQ_TIMBERDALE_RDS, | ||
227 | .flags = IORESOURCE_IRQ, | ||
228 | }, | ||
229 | }; | ||
230 | |||
231 | static __devinitdata struct i2c_board_info timberdale_tef6868_i2c_board_info = { | ||
232 | I2C_BOARD_INFO("tef6862", 0x60) | ||
233 | }; | ||
234 | |||
235 | static __devinitdata struct i2c_board_info timberdale_saa7706_i2c_board_info = { | ||
236 | I2C_BOARD_INFO("saa7706h", 0x1C) | ||
237 | }; | ||
238 | |||
239 | static __devinitdata struct timb_radio_platform_data | ||
240 | timberdale_radio_platform_data = { | ||
241 | .i2c_adapter = 0, | ||
242 | .tuner = { | ||
243 | .module_name = "tef6862", | ||
244 | .info = &timberdale_tef6868_i2c_board_info | ||
245 | }, | ||
246 | .dsp = { | ||
247 | .module_name = "saa7706h", | ||
248 | .info = &timberdale_saa7706_i2c_board_info | ||
249 | } | ||
250 | }; | ||
251 | |||
252 | const static __devinitconst struct resource timberdale_dma_resources[] = { | ||
253 | { | ||
254 | .start = DMAOFFSET, | ||
255 | .end = DMAEND, | ||
256 | .flags = IORESOURCE_MEM, | ||
257 | }, | ||
258 | { | ||
259 | .start = IRQ_TIMBERDALE_DMA, | ||
260 | .end = IRQ_TIMBERDALE_DMA, | ||
261 | .flags = IORESOURCE_IRQ, | ||
262 | }, | ||
263 | }; | ||
264 | |||
265 | static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = { | ||
266 | { | ||
267 | .name = "timb-uart", | ||
268 | .num_resources = ARRAY_SIZE(timberdale_uart_resources), | ||
269 | .resources = timberdale_uart_resources, | ||
270 | }, | ||
271 | { | ||
272 | .name = "timb-gpio", | ||
273 | .num_resources = ARRAY_SIZE(timberdale_gpio_resources), | ||
274 | .resources = timberdale_gpio_resources, | ||
275 | .platform_data = &timberdale_gpio_platform_data, | ||
276 | .data_size = sizeof(timberdale_gpio_platform_data), | ||
277 | }, | ||
278 | { | ||
279 | .name = "timb-radio", | ||
280 | .num_resources = ARRAY_SIZE(timberdale_radio_resources), | ||
281 | .resources = timberdale_radio_resources, | ||
282 | .platform_data = &timberdale_radio_platform_data, | ||
283 | .data_size = sizeof(timberdale_radio_platform_data), | ||
284 | }, | ||
285 | { | ||
286 | .name = "xilinx_spi", | ||
287 | .num_resources = ARRAY_SIZE(timberdale_spi_resources), | ||
288 | .resources = timberdale_spi_resources, | ||
289 | .platform_data = &timberdale_xspi_platform_data, | ||
290 | .data_size = sizeof(timberdale_xspi_platform_data), | ||
291 | }, | ||
292 | { | ||
293 | .name = "ks8842", | ||
294 | .num_resources = ARRAY_SIZE(timberdale_eth_resources), | ||
295 | .resources = timberdale_eth_resources, | ||
296 | }, | ||
297 | { | ||
298 | .name = "timb-dma", | ||
299 | .num_resources = ARRAY_SIZE(timberdale_dma_resources), | ||
300 | .resources = timberdale_dma_resources, | ||
301 | }, | ||
302 | }; | ||
303 | |||
304 | static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = { | ||
305 | { | ||
306 | .name = "timb-uart", | ||
307 | .num_resources = ARRAY_SIZE(timberdale_uart_resources), | ||
308 | .resources = timberdale_uart_resources, | ||
309 | }, | ||
310 | { | ||
311 | .name = "uartlite", | ||
312 | .num_resources = ARRAY_SIZE(timberdale_uartlite_resources), | ||
313 | .resources = timberdale_uartlite_resources, | ||
314 | }, | ||
315 | { | ||
316 | .name = "timb-gpio", | ||
317 | .num_resources = ARRAY_SIZE(timberdale_gpio_resources), | ||
318 | .resources = timberdale_gpio_resources, | ||
319 | .platform_data = &timberdale_gpio_platform_data, | ||
320 | .data_size = sizeof(timberdale_gpio_platform_data), | ||
321 | }, | ||
322 | { | ||
323 | .name = "timb-mlogicore", | ||
324 | .num_resources = ARRAY_SIZE(timberdale_mlogicore_resources), | ||
325 | .resources = timberdale_mlogicore_resources, | ||
326 | }, | ||
327 | { | ||
328 | .name = "timb-radio", | ||
329 | .num_resources = ARRAY_SIZE(timberdale_radio_resources), | ||
330 | .resources = timberdale_radio_resources, | ||
331 | .platform_data = &timberdale_radio_platform_data, | ||
332 | .data_size = sizeof(timberdale_radio_platform_data), | ||
333 | }, | ||
334 | { | ||
335 | .name = "xilinx_spi", | ||
336 | .num_resources = ARRAY_SIZE(timberdale_spi_resources), | ||
337 | .resources = timberdale_spi_resources, | ||
338 | .platform_data = &timberdale_xspi_platform_data, | ||
339 | .data_size = sizeof(timberdale_xspi_platform_data), | ||
340 | }, | ||
341 | { | ||
342 | .name = "ks8842", | ||
343 | .num_resources = ARRAY_SIZE(timberdale_eth_resources), | ||
344 | .resources = timberdale_eth_resources, | ||
345 | }, | ||
346 | { | ||
347 | .name = "timb-dma", | ||
348 | .num_resources = ARRAY_SIZE(timberdale_dma_resources), | ||
349 | .resources = timberdale_dma_resources, | ||
350 | }, | ||
351 | }; | ||
352 | |||
353 | static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = { | ||
354 | { | ||
355 | .name = "timb-uart", | ||
356 | .num_resources = ARRAY_SIZE(timberdale_uart_resources), | ||
357 | .resources = timberdale_uart_resources, | ||
358 | }, | ||
359 | { | ||
360 | .name = "timb-gpio", | ||
361 | .num_resources = ARRAY_SIZE(timberdale_gpio_resources), | ||
362 | .resources = timberdale_gpio_resources, | ||
363 | .platform_data = &timberdale_gpio_platform_data, | ||
364 | .data_size = sizeof(timberdale_gpio_platform_data), | ||
365 | }, | ||
366 | { | ||
367 | .name = "timb-radio", | ||
368 | .num_resources = ARRAY_SIZE(timberdale_radio_resources), | ||
369 | .resources = timberdale_radio_resources, | ||
370 | .platform_data = &timberdale_radio_platform_data, | ||
371 | .data_size = sizeof(timberdale_radio_platform_data), | ||
372 | }, | ||
373 | { | ||
374 | .name = "xilinx_spi", | ||
375 | .num_resources = ARRAY_SIZE(timberdale_spi_resources), | ||
376 | .resources = timberdale_spi_resources, | ||
377 | .platform_data = &timberdale_xspi_platform_data, | ||
378 | .data_size = sizeof(timberdale_xspi_platform_data), | ||
379 | }, | ||
380 | { | ||
381 | .name = "timb-dma", | ||
382 | .num_resources = ARRAY_SIZE(timberdale_dma_resources), | ||
383 | .resources = timberdale_dma_resources, | ||
384 | }, | ||
385 | }; | ||
386 | |||
387 | static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = { | ||
388 | { | ||
389 | .name = "timb-uart", | ||
390 | .num_resources = ARRAY_SIZE(timberdale_uart_resources), | ||
391 | .resources = timberdale_uart_resources, | ||
392 | }, | ||
393 | { | ||
394 | .name = "ocores-i2c", | ||
395 | .num_resources = ARRAY_SIZE(timberdale_ocores_resources), | ||
396 | .resources = timberdale_ocores_resources, | ||
397 | .platform_data = &timberdale_ocores_platform_data, | ||
398 | .data_size = sizeof(timberdale_ocores_platform_data), | ||
399 | }, | ||
400 | { | ||
401 | .name = "timb-gpio", | ||
402 | .num_resources = ARRAY_SIZE(timberdale_gpio_resources), | ||
403 | .resources = timberdale_gpio_resources, | ||
404 | .platform_data = &timberdale_gpio_platform_data, | ||
405 | .data_size = sizeof(timberdale_gpio_platform_data), | ||
406 | }, | ||
407 | { | ||
408 | .name = "timb-radio", | ||
409 | .num_resources = ARRAY_SIZE(timberdale_radio_resources), | ||
410 | .resources = timberdale_radio_resources, | ||
411 | .platform_data = &timberdale_radio_platform_data, | ||
412 | .data_size = sizeof(timberdale_radio_platform_data), | ||
413 | }, | ||
414 | { | ||
415 | .name = "xilinx_spi", | ||
416 | .num_resources = ARRAY_SIZE(timberdale_spi_resources), | ||
417 | .resources = timberdale_spi_resources, | ||
418 | .platform_data = &timberdale_xspi_platform_data, | ||
419 | .data_size = sizeof(timberdale_xspi_platform_data), | ||
420 | }, | ||
421 | { | ||
422 | .name = "ks8842", | ||
423 | .num_resources = ARRAY_SIZE(timberdale_eth_resources), | ||
424 | .resources = timberdale_eth_resources, | ||
425 | }, | ||
426 | { | ||
427 | .name = "timb-dma", | ||
428 | .num_resources = ARRAY_SIZE(timberdale_dma_resources), | ||
429 | .resources = timberdale_dma_resources, | ||
430 | }, | ||
431 | }; | ||
432 | |||
433 | static const __devinitconst struct resource timberdale_sdhc_resources[] = { | ||
434 | /* located in bar 1 and bar 2 */ | ||
435 | { | ||
436 | .start = SDHC0OFFSET, | ||
437 | .end = SDHC0END, | ||
438 | .flags = IORESOURCE_MEM, | ||
439 | }, | ||
440 | { | ||
441 | .start = IRQ_TIMBERDALE_SDHC, | ||
442 | .end = IRQ_TIMBERDALE_SDHC, | ||
443 | .flags = IORESOURCE_IRQ, | ||
444 | }, | ||
445 | }; | ||
446 | |||
447 | static __devinitdata struct mfd_cell timberdale_cells_bar1[] = { | ||
448 | { | ||
449 | .name = "sdhci", | ||
450 | .num_resources = ARRAY_SIZE(timberdale_sdhc_resources), | ||
451 | .resources = timberdale_sdhc_resources, | ||
452 | }, | ||
453 | }; | ||
454 | |||
455 | static __devinitdata struct mfd_cell timberdale_cells_bar2[] = { | ||
456 | { | ||
457 | .name = "sdhci", | ||
458 | .num_resources = ARRAY_SIZE(timberdale_sdhc_resources), | ||
459 | .resources = timberdale_sdhc_resources, | ||
460 | }, | ||
461 | }; | ||
462 | |||
463 | static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr, | ||
464 | char *buf) | ||
465 | { | ||
466 | struct pci_dev *pdev = to_pci_dev(dev); | ||
467 | struct timberdale_device *priv = pci_get_drvdata(pdev); | ||
468 | |||
469 | return sprintf(buf, "%d.%d.%d\n", priv->fw.major, priv->fw.minor, | ||
470 | priv->fw.config); | ||
471 | } | ||
472 | |||
473 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); | ||
474 | |||
475 | /*--------------------------------------------------------------------------*/ | ||
476 | |||
477 | static int __devinit timb_probe(struct pci_dev *dev, | ||
478 | const struct pci_device_id *id) | ||
479 | { | ||
480 | struct timberdale_device *priv; | ||
481 | int err, i; | ||
482 | resource_size_t mapbase; | ||
483 | struct msix_entry *msix_entries = NULL; | ||
484 | u8 ip_setup; | ||
485 | |||
486 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
487 | if (!priv) | ||
488 | return -ENOMEM; | ||
489 | |||
490 | pci_set_drvdata(dev, priv); | ||
491 | |||
492 | err = pci_enable_device(dev); | ||
493 | if (err) | ||
494 | goto err_enable; | ||
495 | |||
496 | mapbase = pci_resource_start(dev, 0); | ||
497 | if (!mapbase) { | ||
498 | dev_err(&dev->dev, "No resource\n"); | ||
499 | goto err_start; | ||
500 | } | ||
501 | |||
502 | /* create a resource for the PCI master register */ | ||
503 | priv->ctl_mapbase = mapbase + CHIPCTLOFFSET; | ||
504 | if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) { | ||
505 | dev_err(&dev->dev, "Failed to request ctl mem\n"); | ||
506 | goto err_request; | ||
507 | } | ||
508 | |||
509 | priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE); | ||
510 | if (!priv->ctl_membase) { | ||
511 | dev_err(&dev->dev, "ioremap failed for ctl mem\n"); | ||
512 | goto err_ioremap; | ||
513 | } | ||
514 | |||
515 | /* read the HW config */ | ||
516 | priv->fw.major = ioread32(priv->ctl_membase + TIMB_REV_MAJOR); | ||
517 | priv->fw.minor = ioread32(priv->ctl_membase + TIMB_REV_MINOR); | ||
518 | priv->fw.config = ioread32(priv->ctl_membase + TIMB_HW_CONFIG); | ||
519 | |||
520 | if (priv->fw.major > TIMB_SUPPORTED_MAJOR) { | ||
521 | dev_err(&dev->dev, "The driver supports an older " | ||
522 | "version of the FPGA, please update the driver to " | ||
523 | "support %d.%d\n", priv->fw.major, priv->fw.minor); | ||
524 | goto err_ioremap; | ||
525 | } | ||
526 | if (priv->fw.major < TIMB_SUPPORTED_MAJOR || | ||
527 | priv->fw.minor < TIMB_REQUIRED_MINOR) { | ||
528 | dev_err(&dev->dev, "The FPGA image is too old (%d.%d), " | ||
529 | "please upgrade the FPGA to at least: %d.%d\n", | ||
530 | priv->fw.major, priv->fw.minor, | ||
531 | TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR); | ||
532 | goto err_ioremap; | ||
533 | } | ||
534 | |||
535 | msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries), | ||
536 | GFP_KERNEL); | ||
537 | if (!msix_entries) | ||
538 | goto err_ioremap; | ||
539 | |||
540 | for (i = 0; i < TIMBERDALE_NR_IRQS; i++) | ||
541 | msix_entries[i].entry = i; | ||
542 | |||
543 | err = pci_enable_msix(dev, msix_entries, TIMBERDALE_NR_IRQS); | ||
544 | if (err) { | ||
545 | dev_err(&dev->dev, | ||
546 | "MSI-X init failed: %d, expected entries: %d\n", | ||
547 | err, TIMBERDALE_NR_IRQS); | ||
548 | goto err_msix; | ||
549 | } | ||
550 | |||
551 | err = device_create_file(&dev->dev, &dev_attr_fw_ver); | ||
552 | if (err) | ||
553 | goto err_create_file; | ||
554 | |||
555 | /* Reset all FPGA PLB peripherals */ | ||
556 | iowrite32(0x1, priv->ctl_membase + TIMB_SW_RST); | ||
557 | |||
558 | /* update IRQ offsets in I2C board info */ | ||
559 | for (i = 0; i < ARRAY_SIZE(timberdale_i2c_board_info); i++) | ||
560 | timberdale_i2c_board_info[i].irq = | ||
561 | msix_entries[timberdale_i2c_board_info[i].irq].vector; | ||
562 | |||
563 | /* Update the SPI configuration depending on the HW (8 or 16 bit) */ | ||
564 | if (priv->fw.config & TIMB_HW_CONFIG_SPI_8BIT) { | ||
565 | timberdale_xspi_platform_data.bits_per_word = 8; | ||
566 | timberdale_xspi_platform_data.devices = | ||
567 | timberdale_spi_8bit_board_info; | ||
568 | timberdale_xspi_platform_data.num_devices = | ||
569 | ARRAY_SIZE(timberdale_spi_8bit_board_info); | ||
570 | } else { | ||
571 | timberdale_xspi_platform_data.bits_per_word = 16; | ||
572 | timberdale_xspi_platform_data.devices = | ||
573 | timberdale_spi_16bit_board_info; | ||
574 | timberdale_xspi_platform_data.num_devices = | ||
575 | ARRAY_SIZE(timberdale_spi_16bit_board_info); | ||
576 | } | ||
577 | |||
578 | ip_setup = priv->fw.config & TIMB_HW_VER_MASK; | ||
579 | switch (ip_setup) { | ||
580 | case TIMB_HW_VER0: | ||
581 | err = mfd_add_devices(&dev->dev, -1, | ||
582 | timberdale_cells_bar0_cfg0, | ||
583 | ARRAY_SIZE(timberdale_cells_bar0_cfg0), | ||
584 | &dev->resource[0], msix_entries[0].vector); | ||
585 | break; | ||
586 | case TIMB_HW_VER1: | ||
587 | err = mfd_add_devices(&dev->dev, -1, | ||
588 | timberdale_cells_bar0_cfg1, | ||
589 | ARRAY_SIZE(timberdale_cells_bar0_cfg1), | ||
590 | &dev->resource[0], msix_entries[0].vector); | ||
591 | break; | ||
592 | case TIMB_HW_VER2: | ||
593 | err = mfd_add_devices(&dev->dev, -1, | ||
594 | timberdale_cells_bar0_cfg2, | ||
595 | ARRAY_SIZE(timberdale_cells_bar0_cfg2), | ||
596 | &dev->resource[0], msix_entries[0].vector); | ||
597 | break; | ||
598 | case TIMB_HW_VER3: | ||
599 | err = mfd_add_devices(&dev->dev, -1, | ||
600 | timberdale_cells_bar0_cfg3, | ||
601 | ARRAY_SIZE(timberdale_cells_bar0_cfg3), | ||
602 | &dev->resource[0], msix_entries[0].vector); | ||
603 | break; | ||
604 | default: | ||
605 | dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n", | ||
606 | priv->fw.major, priv->fw.minor, ip_setup); | ||
607 | err = -ENODEV; | ||
608 | goto err_mfd; | ||
609 | break; | ||
610 | } | ||
611 | |||
612 | if (err) { | ||
613 | dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err); | ||
614 | goto err_mfd; | ||
615 | } | ||
616 | |||
617 | err = mfd_add_devices(&dev->dev, 0, | ||
618 | timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1), | ||
619 | &dev->resource[1], msix_entries[0].vector); | ||
620 | if (err) { | ||
621 | dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err); | ||
622 | goto err_mfd2; | ||
623 | } | ||
624 | |||
625 | /* only version 0 and 3 have the iNand routed to SDHCI */ | ||
626 | if (((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER0) || | ||
627 | ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) { | ||
628 | err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2, | ||
629 | ARRAY_SIZE(timberdale_cells_bar2), | ||
630 | &dev->resource[2], msix_entries[0].vector); | ||
631 | if (err) { | ||
632 | dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err); | ||
633 | goto err_mfd2; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | kfree(msix_entries); | ||
638 | |||
639 | dev_info(&dev->dev, | ||
640 | "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n", | ||
641 | priv->fw.major, priv->fw.minor, priv->fw.config); | ||
642 | |||
643 | return 0; | ||
644 | |||
645 | err_mfd2: | ||
646 | mfd_remove_devices(&dev->dev); | ||
647 | err_mfd: | ||
648 | device_remove_file(&dev->dev, &dev_attr_fw_ver); | ||
649 | err_create_file: | ||
650 | pci_disable_msix(dev); | ||
651 | err_msix: | ||
652 | iounmap(priv->ctl_membase); | ||
653 | err_ioremap: | ||
654 | release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE); | ||
655 | err_request: | ||
656 | pci_set_drvdata(dev, NULL); | ||
657 | err_start: | ||
658 | pci_disable_device(dev); | ||
659 | err_enable: | ||
660 | kfree(msix_entries); | ||
661 | kfree(priv); | ||
662 | pci_set_drvdata(dev, NULL); | ||
663 | return -ENODEV; | ||
664 | } | ||
665 | |||
666 | static void __devexit timb_remove(struct pci_dev *dev) | ||
667 | { | ||
668 | struct timberdale_device *priv = pci_get_drvdata(dev); | ||
669 | |||
670 | mfd_remove_devices(&dev->dev); | ||
671 | |||
672 | device_remove_file(&dev->dev, &dev_attr_fw_ver); | ||
673 | |||
674 | iounmap(priv->ctl_membase); | ||
675 | release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE); | ||
676 | |||
677 | pci_disable_msix(dev); | ||
678 | pci_disable_device(dev); | ||
679 | pci_set_drvdata(dev, NULL); | ||
680 | kfree(priv); | ||
681 | } | ||
682 | |||
683 | static struct pci_device_id timberdale_pci_tbl[] = { | ||
684 | { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) }, | ||
685 | { 0 } | ||
686 | }; | ||
687 | MODULE_DEVICE_TABLE(pci, timberdale_pci_tbl); | ||
688 | |||
689 | static struct pci_driver timberdale_pci_driver = { | ||
690 | .name = DRIVER_NAME, | ||
691 | .id_table = timberdale_pci_tbl, | ||
692 | .probe = timb_probe, | ||
693 | .remove = __devexit_p(timb_remove), | ||
694 | }; | ||
695 | |||
696 | static int __init timberdale_init(void) | ||
697 | { | ||
698 | int err; | ||
699 | |||
700 | err = pci_register_driver(&timberdale_pci_driver); | ||
701 | if (err < 0) { | ||
702 | printk(KERN_ERR | ||
703 | "Failed to register PCI driver for %s device.\n", | ||
704 | timberdale_pci_driver.name); | ||
705 | return -ENODEV; | ||
706 | } | ||
707 | |||
708 | printk(KERN_INFO "Driver for %s has been successfully registered.\n", | ||
709 | timberdale_pci_driver.name); | ||
710 | |||
711 | return 0; | ||
712 | } | ||
713 | |||
714 | static void __exit timberdale_exit(void) | ||
715 | { | ||
716 | pci_unregister_driver(&timberdale_pci_driver); | ||
717 | |||
718 | printk(KERN_INFO "Driver for %s has been successfully unregistered.\n", | ||
719 | timberdale_pci_driver.name); | ||
720 | } | ||
721 | |||
722 | module_init(timberdale_init); | ||
723 | module_exit(timberdale_exit); | ||
724 | |||
725 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); | ||
726 | MODULE_VERSION(DRV_VERSION); | ||
727 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/mfd/timberdale.h b/drivers/mfd/timberdale.h new file mode 100644 index 000000000000..8d27ffabc25d --- /dev/null +++ b/drivers/mfd/timberdale.h | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | * timberdale.h timberdale FPGA MFD driver defines | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | /* Supports: | ||
20 | * Timberdale FPGA | ||
21 | */ | ||
22 | |||
23 | #ifndef MFD_TIMBERDALE_H | ||
24 | #define MFD_TIMBERDALE_H | ||
25 | |||
26 | #define DRV_VERSION "0.1" | ||
27 | |||
28 | /* This driver only support versions >= 3.8 and < 4.0 */ | ||
29 | #define TIMB_SUPPORTED_MAJOR 3 | ||
30 | |||
31 | /* This driver only support minor >= 8 */ | ||
32 | #define TIMB_REQUIRED_MINOR 8 | ||
33 | |||
34 | /* Registers of the control area */ | ||
35 | #define TIMB_REV_MAJOR 0x00 | ||
36 | #define TIMB_REV_MINOR 0x04 | ||
37 | #define TIMB_HW_CONFIG 0x08 | ||
38 | #define TIMB_SW_RST 0x40 | ||
39 | |||
40 | /* bits in the TIMB_HW_CONFIG register */ | ||
41 | #define TIMB_HW_CONFIG_SPI_8BIT 0x80 | ||
42 | |||
43 | #define TIMB_HW_VER_MASK 0x0f | ||
44 | #define TIMB_HW_VER0 0x00 | ||
45 | #define TIMB_HW_VER1 0x01 | ||
46 | #define TIMB_HW_VER2 0x02 | ||
47 | #define TIMB_HW_VER3 0x03 | ||
48 | |||
49 | #define OCORESOFFSET 0x0 | ||
50 | #define OCORESEND 0x1f | ||
51 | |||
52 | #define SPIOFFSET 0x80 | ||
53 | #define SPIEND 0xff | ||
54 | |||
55 | #define UARTLITEOFFSET 0x100 | ||
56 | #define UARTLITEEND 0x10f | ||
57 | |||
58 | #define RDSOFFSET 0x180 | ||
59 | #define RDSEND 0x183 | ||
60 | |||
61 | #define ETHOFFSET 0x300 | ||
62 | #define ETHEND 0x3ff | ||
63 | |||
64 | #define GPIOOFFSET 0x400 | ||
65 | #define GPIOEND 0x7ff | ||
66 | |||
67 | #define CHIPCTLOFFSET 0x800 | ||
68 | #define CHIPCTLEND 0x8ff | ||
69 | #define CHIPCTLSIZE (CHIPCTLEND - CHIPCTLOFFSET) | ||
70 | |||
71 | #define INTCOFFSET 0xc00 | ||
72 | #define INTCEND 0xfff | ||
73 | #define INTCSIZE (INTCEND - INTCOFFSET) | ||
74 | |||
75 | #define MOSTOFFSET 0x1000 | ||
76 | #define MOSTEND 0x13ff | ||
77 | |||
78 | #define UARTOFFSET 0x1400 | ||
79 | #define UARTEND 0x17ff | ||
80 | |||
81 | #define XIICOFFSET 0x1800 | ||
82 | #define XIICEND 0x19ff | ||
83 | |||
84 | #define I2SOFFSET 0x1C00 | ||
85 | #define I2SEND 0x1fff | ||
86 | |||
87 | #define LOGIWOFFSET 0x30000 | ||
88 | #define LOGIWEND 0x37fff | ||
89 | |||
90 | #define MLCOREOFFSET 0x40000 | ||
91 | #define MLCOREEND 0x43fff | ||
92 | |||
93 | #define DMAOFFSET 0x01000000 | ||
94 | #define DMAEND 0x013fffff | ||
95 | |||
96 | /* SDHC0 is placed in PCI bar 1 */ | ||
97 | #define SDHC0OFFSET 0x00 | ||
98 | #define SDHC0END 0xff | ||
99 | |||
100 | /* SDHC1 is placed in PCI bar 2 */ | ||
101 | #define SDHC1OFFSET 0x00 | ||
102 | #define SDHC1END 0xff | ||
103 | |||
104 | #define PCI_VENDOR_ID_TIMB 0x10ee | ||
105 | #define PCI_DEVICE_ID_TIMB 0xa123 | ||
106 | |||
107 | #define IRQ_TIMBERDALE_INIC 0 | ||
108 | #define IRQ_TIMBERDALE_MLB 1 | ||
109 | #define IRQ_TIMBERDALE_GPIO 2 | ||
110 | #define IRQ_TIMBERDALE_I2C 3 | ||
111 | #define IRQ_TIMBERDALE_UART 4 | ||
112 | #define IRQ_TIMBERDALE_DMA 5 | ||
113 | #define IRQ_TIMBERDALE_I2S 6 | ||
114 | #define IRQ_TIMBERDALE_TSC_INT 7 | ||
115 | #define IRQ_TIMBERDALE_SDHC 8 | ||
116 | #define IRQ_TIMBERDALE_ADV7180 9 | ||
117 | #define IRQ_TIMBERDALE_ETHSW_IF 10 | ||
118 | #define IRQ_TIMBERDALE_SPI 11 | ||
119 | #define IRQ_TIMBERDALE_UARTLITE 12 | ||
120 | #define IRQ_TIMBERDALE_MLCORE 13 | ||
121 | #define IRQ_TIMBERDALE_MLCORE_BUF 14 | ||
122 | #define IRQ_TIMBERDALE_RDS 15 | ||
123 | #define TIMBERDALE_NR_IRQS 16 | ||
124 | |||
125 | #define GPIO_PIN_ASCB 8 | ||
126 | #define GPIO_PIN_INIC_RST 14 | ||
127 | #define GPIO_PIN_BT_RST 15 | ||
128 | #define GPIO_NR_PINS 16 | ||
129 | |||
130 | #endif | ||
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index 2a7606534196..562cd4935e17 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c | |||
@@ -58,13 +58,6 @@ | |||
58 | 58 | ||
59 | #define DRIVER_NAME "twl" | 59 | #define DRIVER_NAME "twl" |
60 | 60 | ||
61 | #if defined(CONFIG_TWL4030_BCI_BATTERY) || \ | ||
62 | defined(CONFIG_TWL4030_BCI_BATTERY_MODULE) | ||
63 | #define twl_has_bci() true | ||
64 | #else | ||
65 | #define twl_has_bci() false | ||
66 | #endif | ||
67 | |||
68 | #if defined(CONFIG_KEYBOARD_TWL4030) || defined(CONFIG_KEYBOARD_TWL4030_MODULE) | 61 | #if defined(CONFIG_KEYBOARD_TWL4030) || defined(CONFIG_KEYBOARD_TWL4030_MODULE) |
69 | #define twl_has_keypad() true | 62 | #define twl_has_keypad() true |
70 | #else | 63 | #else |
@@ -115,7 +108,8 @@ | |||
115 | #define twl_has_watchdog() false | 108 | #define twl_has_watchdog() false |
116 | #endif | 109 | #endif |
117 | 110 | ||
118 | #if defined(CONFIG_TWL4030_CODEC) || defined(CONFIG_TWL4030_CODEC_MODULE) | 111 | #if defined(CONFIG_TWL4030_CODEC) || defined(CONFIG_TWL4030_CODEC_MODULE) ||\ |
112 | defined(CONFIG_SND_SOC_TWL6030) || defined(CONFIG_SND_SOC_TWL6030_MODULE) | ||
119 | #define twl_has_codec() true | 113 | #define twl_has_codec() true |
120 | #else | 114 | #else |
121 | #define twl_has_codec() false | 115 | #define twl_has_codec() false |
@@ -129,7 +123,7 @@ | |||
129 | #define TWL_NUM_SLAVES 4 | 123 | #define TWL_NUM_SLAVES 4 |
130 | 124 | ||
131 | #if defined(CONFIG_INPUT_TWL4030_PWRBUTTON) \ | 125 | #if defined(CONFIG_INPUT_TWL4030_PWRBUTTON) \ |
132 | || defined(CONFIG_INPUT_TWL4030_PWBUTTON_MODULE) | 126 | || defined(CONFIG_INPUT_TWL4030_PWRBUTTON_MODULE) |
133 | #define twl_has_pwrbutton() true | 127 | #define twl_has_pwrbutton() true |
134 | #else | 128 | #else |
135 | #define twl_has_pwrbutton() false | 129 | #define twl_has_pwrbutton() false |
@@ -204,6 +198,7 @@ | |||
204 | /* subchip/slave 3 0x4B - AUDIO */ | 198 | /* subchip/slave 3 0x4B - AUDIO */ |
205 | #define TWL6030_BASEADD_AUDIO 0x0000 | 199 | #define TWL6030_BASEADD_AUDIO 0x0000 |
206 | #define TWL6030_BASEADD_RSV 0x0000 | 200 | #define TWL6030_BASEADD_RSV 0x0000 |
201 | #define TWL6030_BASEADD_ZERO 0x0000 | ||
207 | 202 | ||
208 | /* Few power values */ | 203 | /* Few power values */ |
209 | #define R_CFG_BOOT 0x05 | 204 | #define R_CFG_BOOT 0x05 |
@@ -319,9 +314,11 @@ static struct twl_mapping twl6030_map[] = { | |||
319 | { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER }, | 314 | { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER }, |
320 | { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE }, | 315 | { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE }, |
321 | { SUB_CHIP_ID1, TWL6030_BASEADD_PWM }, | 316 | { SUB_CHIP_ID1, TWL6030_BASEADD_PWM }, |
322 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 317 | { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO }, |
323 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 318 | { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO }, |
324 | 319 | ||
320 | { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, | ||
321 | { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, | ||
325 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 322 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, |
326 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 323 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, |
327 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 324 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, |
@@ -587,18 +584,6 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) | |||
587 | struct device *child; | 584 | struct device *child; |
588 | unsigned sub_chip_id; | 585 | unsigned sub_chip_id; |
589 | 586 | ||
590 | if (twl_has_bci() && pdata->bci && | ||
591 | !(features & (TPS_SUBSET | TWL5031))) { | ||
592 | child = add_child(3, "twl4030_bci", | ||
593 | pdata->bci, sizeof(*pdata->bci), | ||
594 | false, | ||
595 | /* irq0 = CHG_PRES, irq1 = BCI */ | ||
596 | pdata->irq_base + BCI_PRES_INTR_OFFSET, | ||
597 | pdata->irq_base + BCI_INTR_OFFSET); | ||
598 | if (IS_ERR(child)) | ||
599 | return PTR_ERR(child); | ||
600 | } | ||
601 | |||
602 | if (twl_has_gpio() && pdata->gpio) { | 587 | if (twl_has_gpio() && pdata->gpio) { |
603 | child = add_child(SUB_CHIP_ID1, "twl4030_gpio", | 588 | child = add_child(SUB_CHIP_ID1, "twl4030_gpio", |
604 | pdata->gpio, sizeof(*pdata->gpio), | 589 | pdata->gpio, sizeof(*pdata->gpio), |
@@ -711,8 +696,19 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) | |||
711 | return PTR_ERR(child); | 696 | return PTR_ERR(child); |
712 | } | 697 | } |
713 | 698 | ||
714 | if (twl_has_codec() && pdata->codec) { | 699 | if (twl_has_codec() && pdata->codec && twl_class_is_4030()) { |
715 | child = add_child(1, "twl4030_codec", | 700 | sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid; |
701 | child = add_child(sub_chip_id, "twl4030_codec", | ||
702 | pdata->codec, sizeof(*pdata->codec), | ||
703 | false, 0, 0); | ||
704 | if (IS_ERR(child)) | ||
705 | return PTR_ERR(child); | ||
706 | } | ||
707 | |||
708 | /* Phoenix*/ | ||
709 | if (twl_has_codec() && pdata->codec && twl_class_is_6030()) { | ||
710 | sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid; | ||
711 | child = add_child(sub_chip_id, "twl6030_codec", | ||
716 | pdata->codec, sizeof(*pdata->codec), | 712 | pdata->codec, sizeof(*pdata->codec), |
717 | false, 0, 0); | 713 | false, 0, 0); |
718 | if (IS_ERR(child)) | 714 | if (IS_ERR(child)) |
@@ -965,6 +961,7 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
965 | int status; | 961 | int status; |
966 | unsigned i; | 962 | unsigned i; |
967 | struct twl4030_platform_data *pdata = client->dev.platform_data; | 963 | struct twl4030_platform_data *pdata = client->dev.platform_data; |
964 | u8 temp; | ||
968 | 965 | ||
969 | if (!pdata) { | 966 | if (!pdata) { |
970 | dev_dbg(&client->dev, "no platform data?\n"); | 967 | dev_dbg(&client->dev, "no platform data?\n"); |
@@ -1032,6 +1029,18 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1032 | goto fail; | 1029 | goto fail; |
1033 | } | 1030 | } |
1034 | 1031 | ||
1032 | /* Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. | ||
1033 | * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0, | ||
1034 | * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0. | ||
1035 | */ | ||
1036 | |||
1037 | if (twl_class_is_4030()) { | ||
1038 | twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1); | ||
1039 | temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \ | ||
1040 | I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU); | ||
1041 | twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); | ||
1042 | } | ||
1043 | |||
1035 | status = add_children(pdata, id->driver_data); | 1044 | status = add_children(pdata, id->driver_data); |
1036 | fail: | 1045 | fail: |
1037 | if (status < 0) | 1046 | if (status < 0) |
diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c index 0815292fdafc..7efa8789a3a2 100644 --- a/drivers/mfd/twl4030-power.c +++ b/drivers/mfd/twl4030-power.c | |||
@@ -405,7 +405,7 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig) | |||
405 | 405 | ||
406 | if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) { | 406 | if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) { |
407 | remap &= ~SLEEP_STATE_MASK; | 407 | remap &= ~SLEEP_STATE_MASK; |
408 | remap |= rconfig->remap_off << SLEEP_STATE_SHIFT; | 408 | remap |= rconfig->remap_sleep << SLEEP_STATE_SHIFT; |
409 | } | 409 | } |
410 | 410 | ||
411 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, | 411 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, |
@@ -461,6 +461,56 @@ out: | |||
461 | return err; | 461 | return err; |
462 | } | 462 | } |
463 | 463 | ||
464 | int twl4030_remove_script(u8 flags) | ||
465 | { | ||
466 | int err = 0; | ||
467 | |||
468 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, R_KEY_1, | ||
469 | R_PROTECT_KEY); | ||
470 | if (err) { | ||
471 | pr_err("twl4030: unable to unlock PROTECT_KEY\n"); | ||
472 | return err; | ||
473 | } | ||
474 | |||
475 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, R_KEY_2, | ||
476 | R_PROTECT_KEY); | ||
477 | if (err) { | ||
478 | pr_err("twl4030: unable to unlock PROTECT_KEY\n"); | ||
479 | return err; | ||
480 | } | ||
481 | |||
482 | if (flags & TWL4030_WRST_SCRIPT) { | ||
483 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, END_OF_SCRIPT, | ||
484 | R_SEQ_ADD_WARM); | ||
485 | if (err) | ||
486 | return err; | ||
487 | } | ||
488 | if (flags & TWL4030_WAKEUP12_SCRIPT) { | ||
489 | if (err) | ||
490 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, END_OF_SCRIPT, | ||
491 | R_SEQ_ADD_S2A12); | ||
492 | return err; | ||
493 | } | ||
494 | if (flags & TWL4030_WAKEUP3_SCRIPT) { | ||
495 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, END_OF_SCRIPT, | ||
496 | R_SEQ_ADD_S2A3); | ||
497 | if (err) | ||
498 | return err; | ||
499 | } | ||
500 | if (flags & TWL4030_SLEEP_SCRIPT) { | ||
501 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, END_OF_SCRIPT, | ||
502 | R_SEQ_ADD_A2S); | ||
503 | if (err) | ||
504 | return err; | ||
505 | } | ||
506 | |||
507 | err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, R_PROTECT_KEY); | ||
508 | if (err) | ||
509 | pr_err("TWL4030 Unable to relock registers\n"); | ||
510 | |||
511 | return err; | ||
512 | } | ||
513 | |||
464 | void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts) | 514 | void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts) |
465 | { | 515 | { |
466 | int err = 0; | 516 | int err = 0; |
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c index 252b74188ec2..b281217334eb 100644 --- a/drivers/mfd/ucb1x00-core.c +++ b/drivers/mfd/ucb1x00-core.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
28 | #include <linux/mfd/ucb1x00.h> | 28 | #include <linux/mfd/ucb1x00.h> |
29 | #include <linux/gpio.h> | 29 | #include <linux/gpio.h> |
30 | #include <linux/semaphore.h> | ||
30 | 31 | ||
31 | #include <mach/dma.h> | 32 | #include <mach/dma.h> |
32 | #include <mach/hardware.h> | 33 | #include <mach/hardware.h> |
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c index 4b2021af1d96..07101e9e1cba 100644 --- a/drivers/mfd/wm831x-core.c +++ b/drivers/mfd/wm831x-core.c | |||
@@ -321,7 +321,6 @@ EXPORT_SYMBOL_GPL(wm831x_set_bits); | |||
321 | */ | 321 | */ |
322 | int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) | 322 | int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) |
323 | { | 323 | { |
324 | int tries = 10; | ||
325 | int ret, src; | 324 | int ret, src; |
326 | 325 | ||
327 | mutex_lock(&wm831x->auxadc_lock); | 326 | mutex_lock(&wm831x->auxadc_lock); |
@@ -349,13 +348,14 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) | |||
349 | goto disable; | 348 | goto disable; |
350 | } | 349 | } |
351 | 350 | ||
352 | do { | 351 | /* Ignore the result to allow us to soldier on without IRQ hookup */ |
353 | msleep(1); | 352 | wait_for_completion_timeout(&wm831x->auxadc_done, msecs_to_jiffies(5)); |
354 | 353 | ||
355 | ret = wm831x_reg_read(wm831x, WM831X_AUXADC_CONTROL); | 354 | ret = wm831x_reg_read(wm831x, WM831X_AUXADC_CONTROL); |
356 | if (ret < 0) | 355 | if (ret < 0) { |
357 | ret = WM831X_AUX_CVT_ENA; | 356 | dev_err(wm831x->dev, "AUXADC status read failed: %d\n", ret); |
358 | } while ((ret & WM831X_AUX_CVT_ENA) && --tries); | 357 | goto disable; |
358 | } | ||
359 | 359 | ||
360 | if (ret & WM831X_AUX_CVT_ENA) { | 360 | if (ret & WM831X_AUX_CVT_ENA) { |
361 | dev_err(wm831x->dev, "Timed out reading AUXADC\n"); | 361 | dev_err(wm831x->dev, "Timed out reading AUXADC\n"); |
@@ -390,6 +390,15 @@ out: | |||
390 | } | 390 | } |
391 | EXPORT_SYMBOL_GPL(wm831x_auxadc_read); | 391 | EXPORT_SYMBOL_GPL(wm831x_auxadc_read); |
392 | 392 | ||
393 | static irqreturn_t wm831x_auxadc_irq(int irq, void *irq_data) | ||
394 | { | ||
395 | struct wm831x *wm831x = irq_data; | ||
396 | |||
397 | complete(&wm831x->auxadc_done); | ||
398 | |||
399 | return IRQ_HANDLED; | ||
400 | } | ||
401 | |||
393 | /** | 402 | /** |
394 | * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC | 403 | * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC |
395 | * | 404 | * |
@@ -1411,6 +1420,7 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1411 | mutex_init(&wm831x->io_lock); | 1420 | mutex_init(&wm831x->io_lock); |
1412 | mutex_init(&wm831x->key_lock); | 1421 | mutex_init(&wm831x->key_lock); |
1413 | mutex_init(&wm831x->auxadc_lock); | 1422 | mutex_init(&wm831x->auxadc_lock); |
1423 | init_completion(&wm831x->auxadc_done); | ||
1414 | dev_set_drvdata(wm831x->dev, wm831x); | 1424 | dev_set_drvdata(wm831x->dev, wm831x); |
1415 | 1425 | ||
1416 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); | 1426 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); |
@@ -1449,18 +1459,33 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1449 | case WM8310: | 1459 | case WM8310: |
1450 | parent = WM8310; | 1460 | parent = WM8310; |
1451 | wm831x->num_gpio = 16; | 1461 | wm831x->num_gpio = 16; |
1462 | if (rev > 0) { | ||
1463 | wm831x->has_gpio_ena = 1; | ||
1464 | wm831x->has_cs_sts = 1; | ||
1465 | } | ||
1466 | |||
1452 | dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev); | 1467 | dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev); |
1453 | break; | 1468 | break; |
1454 | 1469 | ||
1455 | case WM8311: | 1470 | case WM8311: |
1456 | parent = WM8311; | 1471 | parent = WM8311; |
1457 | wm831x->num_gpio = 16; | 1472 | wm831x->num_gpio = 16; |
1473 | if (rev > 0) { | ||
1474 | wm831x->has_gpio_ena = 1; | ||
1475 | wm831x->has_cs_sts = 1; | ||
1476 | } | ||
1477 | |||
1458 | dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev); | 1478 | dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev); |
1459 | break; | 1479 | break; |
1460 | 1480 | ||
1461 | case WM8312: | 1481 | case WM8312: |
1462 | parent = WM8312; | 1482 | parent = WM8312; |
1463 | wm831x->num_gpio = 16; | 1483 | wm831x->num_gpio = 16; |
1484 | if (rev > 0) { | ||
1485 | wm831x->has_gpio_ena = 1; | ||
1486 | wm831x->has_cs_sts = 1; | ||
1487 | } | ||
1488 | |||
1464 | dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev); | 1489 | dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev); |
1465 | break; | 1490 | break; |
1466 | 1491 | ||
@@ -1508,6 +1533,16 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1508 | if (ret != 0) | 1533 | if (ret != 0) |
1509 | goto err; | 1534 | goto err; |
1510 | 1535 | ||
1536 | if (wm831x->irq_base) { | ||
1537 | ret = request_threaded_irq(wm831x->irq_base + | ||
1538 | WM831X_IRQ_AUXADC_DATA, | ||
1539 | NULL, wm831x_auxadc_irq, 0, | ||
1540 | "auxadc", wm831x); | ||
1541 | if (ret < 0) | ||
1542 | dev_err(wm831x->dev, "AUXADC IRQ request failed: %d\n", | ||
1543 | ret); | ||
1544 | } | ||
1545 | |||
1511 | /* The core device is up, instantiate the subdevices. */ | 1546 | /* The core device is up, instantiate the subdevices. */ |
1512 | switch (parent) { | 1547 | switch (parent) { |
1513 | case WM8310: | 1548 | case WM8310: |
@@ -1578,6 +1613,8 @@ static void wm831x_device_exit(struct wm831x *wm831x) | |||
1578 | { | 1613 | { |
1579 | wm831x_otp_exit(wm831x); | 1614 | wm831x_otp_exit(wm831x); |
1580 | mfd_remove_devices(wm831x->dev); | 1615 | mfd_remove_devices(wm831x->dev); |
1616 | if (wm831x->irq_base) | ||
1617 | free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); | ||
1581 | wm831x_irq_exit(wm831x); | 1618 | wm831x_irq_exit(wm831x); |
1582 | kfree(wm831x); | 1619 | kfree(wm831x); |
1583 | } | 1620 | } |
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c index 9a970bd68775..bd75807d5302 100644 --- a/drivers/mfd/wm8350-core.c +++ b/drivers/mfd/wm8350-core.c | |||
@@ -339,7 +339,6 @@ EXPORT_SYMBOL_GPL(wm8350_reg_unlock); | |||
339 | int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref) | 339 | int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref) |
340 | { | 340 | { |
341 | u16 reg, result = 0; | 341 | u16 reg, result = 0; |
342 | int tries = 5; | ||
343 | 342 | ||
344 | if (channel < WM8350_AUXADC_AUX1 || channel > WM8350_AUXADC_TEMP) | 343 | if (channel < WM8350_AUXADC_AUX1 || channel > WM8350_AUXADC_TEMP) |
345 | return -EINVAL; | 344 | return -EINVAL; |
@@ -363,12 +362,13 @@ int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref) | |||
363 | reg |= 1 << channel | WM8350_AUXADC_POLL; | 362 | reg |= 1 << channel | WM8350_AUXADC_POLL; |
364 | wm8350_reg_write(wm8350, WM8350_DIGITISER_CONTROL_1, reg); | 363 | wm8350_reg_write(wm8350, WM8350_DIGITISER_CONTROL_1, reg); |
365 | 364 | ||
366 | do { | 365 | /* We ignore the result of the completion and just check for a |
367 | schedule_timeout_interruptible(1); | 366 | * conversion result, allowing us to soldier on if the IRQ |
368 | reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1); | 367 | * infrastructure is not set up for the chip. */ |
369 | } while ((reg & WM8350_AUXADC_POLL) && --tries); | 368 | wait_for_completion_timeout(&wm8350->auxadc_done, msecs_to_jiffies(5)); |
370 | 369 | ||
371 | if (!tries) | 370 | reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1); |
371 | if (reg & WM8350_AUXADC_POLL) | ||
372 | dev_err(wm8350->dev, "adc chn %d read timeout\n", channel); | 372 | dev_err(wm8350->dev, "adc chn %d read timeout\n", channel); |
373 | else | 373 | else |
374 | result = wm8350_reg_read(wm8350, | 374 | result = wm8350_reg_read(wm8350, |
@@ -385,6 +385,15 @@ int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref) | |||
385 | } | 385 | } |
386 | EXPORT_SYMBOL_GPL(wm8350_read_auxadc); | 386 | EXPORT_SYMBOL_GPL(wm8350_read_auxadc); |
387 | 387 | ||
388 | static irqreturn_t wm8350_auxadc_irq(int irq, void *irq_data) | ||
389 | { | ||
390 | struct wm8350 *wm8350 = irq_data; | ||
391 | |||
392 | complete(&wm8350->auxadc_done); | ||
393 | |||
394 | return IRQ_HANDLED; | ||
395 | } | ||
396 | |||
388 | /* | 397 | /* |
389 | * Cache is always host endian. | 398 | * Cache is always host endian. |
390 | */ | 399 | */ |
@@ -682,11 +691,22 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq, | |||
682 | } | 691 | } |
683 | 692 | ||
684 | mutex_init(&wm8350->auxadc_mutex); | 693 | mutex_init(&wm8350->auxadc_mutex); |
694 | init_completion(&wm8350->auxadc_done); | ||
685 | 695 | ||
686 | ret = wm8350_irq_init(wm8350, irq, pdata); | 696 | ret = wm8350_irq_init(wm8350, irq, pdata); |
687 | if (ret < 0) | 697 | if (ret < 0) |
688 | goto err; | 698 | goto err; |
689 | 699 | ||
700 | if (wm8350->irq_base) { | ||
701 | ret = request_threaded_irq(wm8350->irq_base + | ||
702 | WM8350_IRQ_AUXADC_DATARDY, | ||
703 | NULL, wm8350_auxadc_irq, 0, | ||
704 | "auxadc", wm8350); | ||
705 | if (ret < 0) | ||
706 | dev_warn(wm8350->dev, | ||
707 | "Failed to request AUXADC IRQ: %d\n", ret); | ||
708 | } | ||
709 | |||
690 | if (pdata && pdata->init) { | 710 | if (pdata && pdata->init) { |
691 | ret = pdata->init(wm8350); | 711 | ret = pdata->init(wm8350); |
692 | if (ret != 0) { | 712 | if (ret != 0) { |
@@ -736,6 +756,9 @@ void wm8350_device_exit(struct wm8350 *wm8350) | |||
736 | platform_device_unregister(wm8350->gpio.pdev); | 756 | platform_device_unregister(wm8350->gpio.pdev); |
737 | platform_device_unregister(wm8350->codec.pdev); | 757 | platform_device_unregister(wm8350->codec.pdev); |
738 | 758 | ||
759 | if (wm8350->irq_base) | ||
760 | free_irq(wm8350->irq_base + WM8350_IRQ_AUXADC_DATARDY, wm8350); | ||
761 | |||
739 | wm8350_irq_exit(wm8350); | 762 | wm8350_irq_exit(wm8350); |
740 | 763 | ||
741 | kfree(wm8350->reg_cache); | 764 | kfree(wm8350->reg_cache); |
diff --git a/drivers/mfd/wm8350-irq.c b/drivers/mfd/wm8350-irq.c index 9025f29e2707..f56c9adf9493 100644 --- a/drivers/mfd/wm8350-irq.c +++ b/drivers/mfd/wm8350-irq.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/bug.h> | 18 | #include <linux/bug.h> |
19 | #include <linux/device.h> | 19 | #include <linux/device.h> |
20 | #include <linux/interrupt.h> | 20 | #include <linux/interrupt.h> |
21 | #include <linux/workqueue.h> | 21 | #include <linux/irq.h> |
22 | 22 | ||
23 | #include <linux/mfd/wm8350/core.h> | 23 | #include <linux/mfd/wm8350/core.h> |
24 | #include <linux/mfd/wm8350/audio.h> | 24 | #include <linux/mfd/wm8350/audio.h> |
@@ -29,8 +29,6 @@ | |||
29 | #include <linux/mfd/wm8350/supply.h> | 29 | #include <linux/mfd/wm8350/supply.h> |
30 | #include <linux/mfd/wm8350/wdt.h> | 30 | #include <linux/mfd/wm8350/wdt.h> |
31 | 31 | ||
32 | #define WM8350_NUM_IRQ_REGS 7 | ||
33 | |||
34 | #define WM8350_INT_OFFSET_1 0 | 32 | #define WM8350_INT_OFFSET_1 0 |
35 | #define WM8350_INT_OFFSET_2 1 | 33 | #define WM8350_INT_OFFSET_2 1 |
36 | #define WM8350_POWER_UP_INT_OFFSET 2 | 34 | #define WM8350_POWER_UP_INT_OFFSET 2 |
@@ -366,19 +364,10 @@ static struct wm8350_irq_data wm8350_irqs[] = { | |||
366 | }, | 364 | }, |
367 | }; | 365 | }; |
368 | 366 | ||
369 | static void wm8350_irq_call_handler(struct wm8350 *wm8350, int irq) | 367 | static inline struct wm8350_irq_data *irq_to_wm8350_irq(struct wm8350 *wm8350, |
368 | int irq) | ||
370 | { | 369 | { |
371 | mutex_lock(&wm8350->irq_mutex); | 370 | return &wm8350_irqs[irq - wm8350->irq_base]; |
372 | |||
373 | if (wm8350->irq[irq].handler) | ||
374 | wm8350->irq[irq].handler(irq, wm8350->irq[irq].data); | ||
375 | else { | ||
376 | dev_err(wm8350->dev, "irq %d nobody cared. now masked.\n", | ||
377 | irq); | ||
378 | wm8350_mask_irq(wm8350, irq); | ||
379 | } | ||
380 | |||
381 | mutex_unlock(&wm8350->irq_mutex); | ||
382 | } | 371 | } |
383 | 372 | ||
384 | /* | 373 | /* |
@@ -386,7 +375,9 @@ static void wm8350_irq_call_handler(struct wm8350 *wm8350, int irq) | |||
386 | * interrupts are clear on read the IRQ line will be reasserted and | 375 | * interrupts are clear on read the IRQ line will be reasserted and |
387 | * the physical IRQ will be handled again if another interrupt is | 376 | * the physical IRQ will be handled again if another interrupt is |
388 | * asserted while we run - in the normal course of events this is a | 377 | * asserted while we run - in the normal course of events this is a |
389 | * rare occurrence so we save I2C/SPI reads. | 378 | * rare occurrence so we save I2C/SPI reads. We're also assuming that |
379 | * it's rare to get lots of interrupts firing simultaneously so try to | ||
380 | * minimise I/O. | ||
390 | */ | 381 | */ |
391 | static irqreturn_t wm8350_irq(int irq, void *irq_data) | 382 | static irqreturn_t wm8350_irq(int irq, void *irq_data) |
392 | { | 383 | { |
@@ -397,7 +388,6 @@ static irqreturn_t wm8350_irq(int irq, void *irq_data) | |||
397 | struct wm8350_irq_data *data; | 388 | struct wm8350_irq_data *data; |
398 | int i; | 389 | int i; |
399 | 390 | ||
400 | /* TODO: Use block reads to improve performance? */ | ||
401 | level_one = wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS) | 391 | level_one = wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS) |
402 | & ~wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK); | 392 | & ~wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK); |
403 | 393 | ||
@@ -416,93 +406,101 @@ static irqreturn_t wm8350_irq(int irq, void *irq_data) | |||
416 | sub_reg[data->reg] = | 406 | sub_reg[data->reg] = |
417 | wm8350_reg_read(wm8350, WM8350_INT_STATUS_1 + | 407 | wm8350_reg_read(wm8350, WM8350_INT_STATUS_1 + |
418 | data->reg); | 408 | data->reg); |
419 | sub_reg[data->reg] &= | 409 | sub_reg[data->reg] &= ~wm8350->irq_masks[data->reg]; |
420 | ~wm8350_reg_read(wm8350, | ||
421 | WM8350_INT_STATUS_1_MASK + | ||
422 | data->reg); | ||
423 | read_done[data->reg] = 1; | 410 | read_done[data->reg] = 1; |
424 | } | 411 | } |
425 | 412 | ||
426 | if (sub_reg[data->reg] & data->mask) | 413 | if (sub_reg[data->reg] & data->mask) |
427 | wm8350_irq_call_handler(wm8350, i); | 414 | handle_nested_irq(wm8350->irq_base + i); |
428 | } | 415 | } |
429 | 416 | ||
430 | return IRQ_HANDLED; | 417 | return IRQ_HANDLED; |
431 | } | 418 | } |
432 | 419 | ||
433 | int wm8350_register_irq(struct wm8350 *wm8350, int irq, | 420 | static void wm8350_irq_lock(unsigned int irq) |
434 | irq_handler_t handler, unsigned long flags, | ||
435 | const char *name, void *data) | ||
436 | { | 421 | { |
437 | if (irq < 0 || irq >= WM8350_NUM_IRQ || !handler) | 422 | struct wm8350 *wm8350 = get_irq_chip_data(irq); |
438 | return -EINVAL; | ||
439 | |||
440 | if (wm8350->irq[irq].handler) | ||
441 | return -EBUSY; | ||
442 | |||
443 | mutex_lock(&wm8350->irq_mutex); | ||
444 | wm8350->irq[irq].handler = handler; | ||
445 | wm8350->irq[irq].data = data; | ||
446 | mutex_unlock(&wm8350->irq_mutex); | ||
447 | |||
448 | wm8350_unmask_irq(wm8350, irq); | ||
449 | 423 | ||
450 | return 0; | 424 | mutex_lock(&wm8350->irq_lock); |
451 | } | 425 | } |
452 | EXPORT_SYMBOL_GPL(wm8350_register_irq); | ||
453 | 426 | ||
454 | int wm8350_free_irq(struct wm8350 *wm8350, int irq) | 427 | static void wm8350_irq_sync_unlock(unsigned int irq) |
455 | { | 428 | { |
456 | if (irq < 0 || irq >= WM8350_NUM_IRQ) | 429 | struct wm8350 *wm8350 = get_irq_chip_data(irq); |
457 | return -EINVAL; | 430 | int i; |
458 | 431 | ||
459 | wm8350_mask_irq(wm8350, irq); | 432 | for (i = 0; i < ARRAY_SIZE(wm8350->irq_masks); i++) { |
433 | /* If there's been a change in the mask write it back | ||
434 | * to the hardware. */ | ||
435 | if (wm8350->irq_masks[i] != | ||
436 | wm8350->reg_cache[WM8350_INT_STATUS_1_MASK + i]) | ||
437 | WARN_ON(wm8350_reg_write(wm8350, | ||
438 | WM8350_INT_STATUS_1_MASK + i, | ||
439 | wm8350->irq_masks[i])); | ||
440 | } | ||
460 | 441 | ||
461 | mutex_lock(&wm8350->irq_mutex); | 442 | mutex_unlock(&wm8350->irq_lock); |
462 | wm8350->irq[irq].handler = NULL; | ||
463 | mutex_unlock(&wm8350->irq_mutex); | ||
464 | return 0; | ||
465 | } | 443 | } |
466 | EXPORT_SYMBOL_GPL(wm8350_free_irq); | ||
467 | 444 | ||
468 | int wm8350_mask_irq(struct wm8350 *wm8350, int irq) | 445 | static void wm8350_irq_enable(unsigned int irq) |
469 | { | 446 | { |
470 | return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK + | 447 | struct wm8350 *wm8350 = get_irq_chip_data(irq); |
471 | wm8350_irqs[irq].reg, | 448 | struct wm8350_irq_data *irq_data = irq_to_wm8350_irq(wm8350, irq); |
472 | wm8350_irqs[irq].mask); | 449 | |
450 | wm8350->irq_masks[irq_data->reg] &= ~irq_data->mask; | ||
473 | } | 451 | } |
474 | EXPORT_SYMBOL_GPL(wm8350_mask_irq); | ||
475 | 452 | ||
476 | int wm8350_unmask_irq(struct wm8350 *wm8350, int irq) | 453 | static void wm8350_irq_disable(unsigned int irq) |
477 | { | 454 | { |
478 | return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK + | 455 | struct wm8350 *wm8350 = get_irq_chip_data(irq); |
479 | wm8350_irqs[irq].reg, | 456 | struct wm8350_irq_data *irq_data = irq_to_wm8350_irq(wm8350, irq); |
480 | wm8350_irqs[irq].mask); | 457 | |
458 | wm8350->irq_masks[irq_data->reg] |= irq_data->mask; | ||
481 | } | 459 | } |
482 | EXPORT_SYMBOL_GPL(wm8350_unmask_irq); | 460 | |
461 | static struct irq_chip wm8350_irq_chip = { | ||
462 | .name = "wm8350", | ||
463 | .bus_lock = wm8350_irq_lock, | ||
464 | .bus_sync_unlock = wm8350_irq_sync_unlock, | ||
465 | .disable = wm8350_irq_disable, | ||
466 | .enable = wm8350_irq_enable, | ||
467 | }; | ||
483 | 468 | ||
484 | int wm8350_irq_init(struct wm8350 *wm8350, int irq, | 469 | int wm8350_irq_init(struct wm8350 *wm8350, int irq, |
485 | struct wm8350_platform_data *pdata) | 470 | struct wm8350_platform_data *pdata) |
486 | { | 471 | { |
487 | int ret; | 472 | int ret, cur_irq, i; |
488 | int flags = IRQF_ONESHOT; | 473 | int flags = IRQF_ONESHOT; |
489 | 474 | ||
490 | if (!irq) { | 475 | if (!irq) { |
491 | dev_err(wm8350->dev, "No IRQ configured\n"); | 476 | dev_warn(wm8350->dev, "No interrupt support, no core IRQ\n"); |
492 | return -EINVAL; | 477 | return 0; |
478 | } | ||
479 | |||
480 | if (!pdata || !pdata->irq_base) { | ||
481 | dev_warn(wm8350->dev, "No interrupt support, no IRQ base\n"); | ||
482 | return 0; | ||
493 | } | 483 | } |
494 | 484 | ||
485 | /* Mask top level interrupts */ | ||
495 | wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0xFFFF); | 486 | wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0xFFFF); |
496 | wm8350_reg_write(wm8350, WM8350_INT_STATUS_1_MASK, 0xFFFF); | ||
497 | wm8350_reg_write(wm8350, WM8350_INT_STATUS_2_MASK, 0xFFFF); | ||
498 | wm8350_reg_write(wm8350, WM8350_UNDER_VOLTAGE_INT_STATUS_MASK, 0xFFFF); | ||
499 | wm8350_reg_write(wm8350, WM8350_GPIO_INT_STATUS_MASK, 0xFFFF); | ||
500 | wm8350_reg_write(wm8350, WM8350_COMPARATOR_INT_STATUS_MASK, 0xFFFF); | ||
501 | 487 | ||
502 | mutex_init(&wm8350->irq_mutex); | 488 | /* Mask all individual interrupts by default and cache the |
489 | * masks. We read the masks back since there are unwritable | ||
490 | * bits in the mask registers. */ | ||
491 | for (i = 0; i < ARRAY_SIZE(wm8350->irq_masks); i++) { | ||
492 | wm8350_reg_write(wm8350, WM8350_INT_STATUS_1_MASK + i, | ||
493 | 0xFFFF); | ||
494 | wm8350->irq_masks[i] = | ||
495 | wm8350_reg_read(wm8350, | ||
496 | WM8350_INT_STATUS_1_MASK + i); | ||
497 | } | ||
498 | |||
499 | mutex_init(&wm8350->irq_lock); | ||
503 | wm8350->chip_irq = irq; | 500 | wm8350->chip_irq = irq; |
501 | wm8350->irq_base = pdata->irq_base; | ||
504 | 502 | ||
505 | if (pdata && pdata->irq_high) { | 503 | if (pdata->irq_high) { |
506 | flags |= IRQF_TRIGGER_HIGH; | 504 | flags |= IRQF_TRIGGER_HIGH; |
507 | 505 | ||
508 | wm8350_set_bits(wm8350, WM8350_SYSTEM_CONTROL_1, | 506 | wm8350_set_bits(wm8350, WM8350_SYSTEM_CONTROL_1, |
@@ -514,11 +512,32 @@ int wm8350_irq_init(struct wm8350 *wm8350, int irq, | |||
514 | WM8350_IRQ_POL); | 512 | WM8350_IRQ_POL); |
515 | } | 513 | } |
516 | 514 | ||
515 | /* Register with genirq */ | ||
516 | for (cur_irq = wm8350->irq_base; | ||
517 | cur_irq < ARRAY_SIZE(wm8350_irqs) + wm8350->irq_base; | ||
518 | cur_irq++) { | ||
519 | set_irq_chip_data(cur_irq, wm8350); | ||
520 | set_irq_chip_and_handler(cur_irq, &wm8350_irq_chip, | ||
521 | handle_edge_irq); | ||
522 | set_irq_nested_thread(cur_irq, 1); | ||
523 | |||
524 | /* ARM needs us to explicitly flag the IRQ as valid | ||
525 | * and will set them noprobe when we do so. */ | ||
526 | #ifdef CONFIG_ARM | ||
527 | set_irq_flags(cur_irq, IRQF_VALID); | ||
528 | #else | ||
529 | set_irq_noprobe(cur_irq); | ||
530 | #endif | ||
531 | } | ||
532 | |||
517 | ret = request_threaded_irq(irq, NULL, wm8350_irq, flags, | 533 | ret = request_threaded_irq(irq, NULL, wm8350_irq, flags, |
518 | "wm8350", wm8350); | 534 | "wm8350", wm8350); |
519 | if (ret != 0) | 535 | if (ret != 0) |
520 | dev_err(wm8350->dev, "Failed to request IRQ: %d\n", ret); | 536 | dev_err(wm8350->dev, "Failed to request IRQ: %d\n", ret); |
521 | 537 | ||
538 | /* Allow interrupts to fire */ | ||
539 | wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0); | ||
540 | |||
522 | return ret; | 541 | return ret; |
523 | } | 542 | } |
524 | 543 | ||
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c new file mode 100644 index 000000000000..844e1c1b7d90 --- /dev/null +++ b/drivers/mfd/wm8994-core.c | |||
@@ -0,0 +1,537 @@ | |||
1 | /* | ||
2 | * wm8994-core.c -- Device access for Wolfson WM8994 | ||
3 | * | ||
4 | * Copyright 2009 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
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. | ||
12 | * | ||
13 | */ | ||
14 | |||
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/regulator/consumer.h> | ||
21 | #include <linux/regulator/machine.h> | ||
22 | |||
23 | #include <linux/mfd/wm8994/core.h> | ||
24 | #include <linux/mfd/wm8994/pdata.h> | ||
25 | #include <linux/mfd/wm8994/registers.h> | ||
26 | |||
27 | static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, | ||
28 | int bytes, void *dest) | ||
29 | { | ||
30 | int ret, i; | ||
31 | u16 *buf = dest; | ||
32 | |||
33 | BUG_ON(bytes % 2); | ||
34 | BUG_ON(bytes <= 0); | ||
35 | |||
36 | ret = wm8994->read_dev(wm8994, reg, bytes, dest); | ||
37 | if (ret < 0) | ||
38 | return ret; | ||
39 | |||
40 | for (i = 0; i < bytes / 2; i++) { | ||
41 | buf[i] = be16_to_cpu(buf[i]); | ||
42 | |||
43 | dev_vdbg(wm8994->dev, "Read %04x from R%d(0x%x)\n", | ||
44 | buf[i], reg + i, reg + i); | ||
45 | } | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * wm8994_reg_read: Read a single WM8994 register. | ||
52 | * | ||
53 | * @wm8994: Device to read from. | ||
54 | * @reg: Register to read. | ||
55 | */ | ||
56 | int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) | ||
57 | { | ||
58 | unsigned short val; | ||
59 | int ret; | ||
60 | |||
61 | mutex_lock(&wm8994->io_lock); | ||
62 | |||
63 | ret = wm8994_read(wm8994, reg, 2, &val); | ||
64 | |||
65 | mutex_unlock(&wm8994->io_lock); | ||
66 | |||
67 | if (ret < 0) | ||
68 | return ret; | ||
69 | else | ||
70 | return val; | ||
71 | } | ||
72 | EXPORT_SYMBOL_GPL(wm8994_reg_read); | ||
73 | |||
74 | /** | ||
75 | * wm8994_bulk_read: Read multiple WM8994 registers | ||
76 | * | ||
77 | * @wm8994: Device to read from | ||
78 | * @reg: First register | ||
79 | * @count: Number of registers | ||
80 | * @buf: Buffer to fill. | ||
81 | */ | ||
82 | int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, | ||
83 | int count, u16 *buf) | ||
84 | { | ||
85 | int ret; | ||
86 | |||
87 | mutex_lock(&wm8994->io_lock); | ||
88 | |||
89 | ret = wm8994_read(wm8994, reg, count * 2, buf); | ||
90 | |||
91 | mutex_unlock(&wm8994->io_lock); | ||
92 | |||
93 | return ret; | ||
94 | } | ||
95 | EXPORT_SYMBOL_GPL(wm8994_bulk_read); | ||
96 | |||
97 | static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, | ||
98 | int bytes, void *src) | ||
99 | { | ||
100 | u16 *buf = src; | ||
101 | int i; | ||
102 | |||
103 | BUG_ON(bytes % 2); | ||
104 | BUG_ON(bytes <= 0); | ||
105 | |||
106 | for (i = 0; i < bytes / 2; i++) { | ||
107 | dev_vdbg(wm8994->dev, "Write %04x to R%d(0x%x)\n", | ||
108 | buf[i], reg + i, reg + i); | ||
109 | |||
110 | buf[i] = cpu_to_be16(buf[i]); | ||
111 | } | ||
112 | |||
113 | return wm8994->write_dev(wm8994, reg, bytes, src); | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * wm8994_reg_write: Write a single WM8994 register. | ||
118 | * | ||
119 | * @wm8994: Device to write to. | ||
120 | * @reg: Register to write to. | ||
121 | * @val: Value to write. | ||
122 | */ | ||
123 | int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, | ||
124 | unsigned short val) | ||
125 | { | ||
126 | int ret; | ||
127 | |||
128 | mutex_lock(&wm8994->io_lock); | ||
129 | |||
130 | ret = wm8994_write(wm8994, reg, 2, &val); | ||
131 | |||
132 | mutex_unlock(&wm8994->io_lock); | ||
133 | |||
134 | return ret; | ||
135 | } | ||
136 | EXPORT_SYMBOL_GPL(wm8994_reg_write); | ||
137 | |||
138 | /** | ||
139 | * wm8994_set_bits: Set the value of a bitfield in a WM8994 register | ||
140 | * | ||
141 | * @wm8994: Device to write to. | ||
142 | * @reg: Register to write to. | ||
143 | * @mask: Mask of bits to set. | ||
144 | * @val: Value to set (unshifted) | ||
145 | */ | ||
146 | int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, | ||
147 | unsigned short mask, unsigned short val) | ||
148 | { | ||
149 | int ret; | ||
150 | u16 r; | ||
151 | |||
152 | mutex_lock(&wm8994->io_lock); | ||
153 | |||
154 | ret = wm8994_read(wm8994, reg, 2, &r); | ||
155 | if (ret < 0) | ||
156 | goto out; | ||
157 | |||
158 | r &= ~mask; | ||
159 | r |= val; | ||
160 | |||
161 | ret = wm8994_write(wm8994, reg, 2, &r); | ||
162 | |||
163 | out: | ||
164 | mutex_unlock(&wm8994->io_lock); | ||
165 | |||
166 | return ret; | ||
167 | } | ||
168 | EXPORT_SYMBOL_GPL(wm8994_set_bits); | ||
169 | |||
170 | static struct mfd_cell wm8994_regulator_devs[] = { | ||
171 | { .name = "wm8994-ldo", .id = 1 }, | ||
172 | { .name = "wm8994-ldo", .id = 2 }, | ||
173 | }; | ||
174 | |||
175 | static struct mfd_cell wm8994_devs[] = { | ||
176 | { .name = "wm8994-codec" }, | ||
177 | { .name = "wm8994-gpio" }, | ||
178 | }; | ||
179 | |||
180 | /* | ||
181 | * Supplies for the main bulk of CODEC; the LDO supplies are ignored | ||
182 | * and should be handled via the standard regulator API supply | ||
183 | * management. | ||
184 | */ | ||
185 | static const char *wm8994_main_supplies[] = { | ||
186 | "DBVDD", | ||
187 | "DCVDD", | ||
188 | "AVDD1", | ||
189 | "AVDD2", | ||
190 | "CPVDD", | ||
191 | "SPKVDD1", | ||
192 | "SPKVDD2", | ||
193 | }; | ||
194 | |||
195 | #ifdef CONFIG_PM | ||
196 | static int wm8994_device_suspend(struct device *dev) | ||
197 | { | ||
198 | struct wm8994 *wm8994 = dev_get_drvdata(dev); | ||
199 | int ret; | ||
200 | |||
201 | /* GPIO configuration state is saved here since we may be configuring | ||
202 | * the GPIO alternate functions even if we're not using the gpiolib | ||
203 | * driver for them. | ||
204 | */ | ||
205 | ret = wm8994_read(wm8994, WM8994_GPIO_1, WM8994_NUM_GPIO_REGS * 2, | ||
206 | &wm8994->gpio_regs); | ||
207 | if (ret < 0) | ||
208 | dev_err(dev, "Failed to save GPIO registers: %d\n", ret); | ||
209 | |||
210 | /* For similar reasons we also stash the regulator states */ | ||
211 | ret = wm8994_read(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS * 2, | ||
212 | &wm8994->ldo_regs); | ||
213 | if (ret < 0) | ||
214 | dev_err(dev, "Failed to save LDO registers: %d\n", ret); | ||
215 | |||
216 | ret = regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), | ||
217 | wm8994->supplies); | ||
218 | if (ret != 0) { | ||
219 | dev_err(dev, "Failed to disable supplies: %d\n", ret); | ||
220 | return ret; | ||
221 | } | ||
222 | |||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | static int wm8994_device_resume(struct device *dev) | ||
227 | { | ||
228 | struct wm8994 *wm8994 = dev_get_drvdata(dev); | ||
229 | int ret; | ||
230 | |||
231 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8994_main_supplies), | ||
232 | wm8994->supplies); | ||
233 | if (ret != 0) { | ||
234 | dev_err(dev, "Failed to enable supplies: %d\n", ret); | ||
235 | return ret; | ||
236 | } | ||
237 | |||
238 | ret = wm8994_write(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS * 2, | ||
239 | &wm8994->ldo_regs); | ||
240 | if (ret < 0) | ||
241 | dev_err(dev, "Failed to restore LDO registers: %d\n", ret); | ||
242 | |||
243 | ret = wm8994_write(wm8994, WM8994_GPIO_1, WM8994_NUM_GPIO_REGS * 2, | ||
244 | &wm8994->gpio_regs); | ||
245 | if (ret < 0) | ||
246 | dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | #endif | ||
251 | |||
252 | #ifdef CONFIG_REGULATOR | ||
253 | static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) | ||
254 | { | ||
255 | struct wm8994_ldo_pdata *ldo_pdata; | ||
256 | |||
257 | if (!pdata) | ||
258 | return 0; | ||
259 | |||
260 | ldo_pdata = &pdata->ldo[ldo]; | ||
261 | |||
262 | if (!ldo_pdata->init_data) | ||
263 | return 0; | ||
264 | |||
265 | return ldo_pdata->init_data->num_consumer_supplies != 0; | ||
266 | } | ||
267 | #else | ||
268 | static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) | ||
269 | { | ||
270 | return 0; | ||
271 | } | ||
272 | #endif | ||
273 | |||
274 | /* | ||
275 | * Instantiate the generic non-control parts of the device. | ||
276 | */ | ||
277 | static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq) | ||
278 | { | ||
279 | struct wm8994_pdata *pdata = wm8994->dev->platform_data; | ||
280 | int ret, i; | ||
281 | |||
282 | mutex_init(&wm8994->io_lock); | ||
283 | dev_set_drvdata(wm8994->dev, wm8994); | ||
284 | |||
285 | /* Add the on-chip regulators first for bootstrapping */ | ||
286 | ret = mfd_add_devices(wm8994->dev, -1, | ||
287 | wm8994_regulator_devs, | ||
288 | ARRAY_SIZE(wm8994_regulator_devs), | ||
289 | NULL, 0); | ||
290 | if (ret != 0) { | ||
291 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); | ||
292 | goto err; | ||
293 | } | ||
294 | |||
295 | wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * | ||
296 | ARRAY_SIZE(wm8994_main_supplies), | ||
297 | GFP_KERNEL); | ||
298 | if (!wm8994->supplies) | ||
299 | goto err; | ||
300 | |||
301 | for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) | ||
302 | wm8994->supplies[i].supply = wm8994_main_supplies[i]; | ||
303 | |||
304 | ret = regulator_bulk_get(wm8994->dev, ARRAY_SIZE(wm8994_main_supplies), | ||
305 | wm8994->supplies); | ||
306 | if (ret != 0) { | ||
307 | dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); | ||
308 | goto err_supplies; | ||
309 | } | ||
310 | |||
311 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8994_main_supplies), | ||
312 | wm8994->supplies); | ||
313 | if (ret != 0) { | ||
314 | dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); | ||
315 | goto err_get; | ||
316 | } | ||
317 | |||
318 | ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); | ||
319 | if (ret < 0) { | ||
320 | dev_err(wm8994->dev, "Failed to read ID register\n"); | ||
321 | goto err_enable; | ||
322 | } | ||
323 | if (ret != 0x8994) { | ||
324 | dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", | ||
325 | ret); | ||
326 | ret = -EINVAL; | ||
327 | goto err_enable; | ||
328 | } | ||
329 | |||
330 | ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); | ||
331 | if (ret < 0) { | ||
332 | dev_err(wm8994->dev, "Failed to read revision register: %d\n", | ||
333 | ret); | ||
334 | goto err_enable; | ||
335 | } | ||
336 | |||
337 | switch (ret) { | ||
338 | case 0: | ||
339 | case 1: | ||
340 | dev_warn(wm8994->dev, "revision %c not fully supported\n", | ||
341 | 'A' + ret); | ||
342 | break; | ||
343 | default: | ||
344 | dev_info(wm8994->dev, "revision %c\n", 'A' + ret); | ||
345 | break; | ||
346 | } | ||
347 | |||
348 | |||
349 | if (pdata) { | ||
350 | wm8994->gpio_base = pdata->gpio_base; | ||
351 | |||
352 | /* GPIO configuration is only applied if it's non-zero */ | ||
353 | for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { | ||
354 | if (pdata->gpio_defaults[i]) { | ||
355 | wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, | ||
356 | 0xffff, | ||
357 | pdata->gpio_defaults[i]); | ||
358 | } | ||
359 | } | ||
360 | } | ||
361 | |||
362 | /* In some system designs where the regulators are not in use, | ||
363 | * we can achieve a small reduction in leakage currents by | ||
364 | * floating LDO outputs. This bit makes no difference if the | ||
365 | * LDOs are enabled, it only affects cases where the LDOs were | ||
366 | * in operation and are then disabled. | ||
367 | */ | ||
368 | for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { | ||
369 | if (wm8994_ldo_in_use(pdata, i)) | ||
370 | wm8994_set_bits(wm8994, WM8994_LDO_1 + i, | ||
371 | WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); | ||
372 | else | ||
373 | wm8994_set_bits(wm8994, WM8994_LDO_1 + i, | ||
374 | WM8994_LDO1_DISCH, 0); | ||
375 | } | ||
376 | |||
377 | ret = mfd_add_devices(wm8994->dev, -1, | ||
378 | wm8994_devs, ARRAY_SIZE(wm8994_devs), | ||
379 | NULL, 0); | ||
380 | if (ret != 0) { | ||
381 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); | ||
382 | goto err_enable; | ||
383 | } | ||
384 | |||
385 | return 0; | ||
386 | |||
387 | err_enable: | ||
388 | regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), | ||
389 | wm8994->supplies); | ||
390 | err_get: | ||
391 | regulator_bulk_free(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); | ||
392 | err_supplies: | ||
393 | kfree(wm8994->supplies); | ||
394 | err: | ||
395 | mfd_remove_devices(wm8994->dev); | ||
396 | kfree(wm8994); | ||
397 | return ret; | ||
398 | } | ||
399 | |||
400 | static void wm8994_device_exit(struct wm8994 *wm8994) | ||
401 | { | ||
402 | mfd_remove_devices(wm8994->dev); | ||
403 | regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), | ||
404 | wm8994->supplies); | ||
405 | regulator_bulk_free(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); | ||
406 | kfree(wm8994->supplies); | ||
407 | kfree(wm8994); | ||
408 | } | ||
409 | |||
410 | static int wm8994_i2c_read_device(struct wm8994 *wm8994, unsigned short reg, | ||
411 | int bytes, void *dest) | ||
412 | { | ||
413 | struct i2c_client *i2c = wm8994->control_data; | ||
414 | int ret; | ||
415 | u16 r = cpu_to_be16(reg); | ||
416 | |||
417 | ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | ||
418 | if (ret < 0) | ||
419 | return ret; | ||
420 | if (ret != 2) | ||
421 | return -EIO; | ||
422 | |||
423 | ret = i2c_master_recv(i2c, dest, bytes); | ||
424 | if (ret < 0) | ||
425 | return ret; | ||
426 | if (ret != bytes) | ||
427 | return -EIO; | ||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | /* Currently we allocate the write buffer on the stack; this is OK for | ||
432 | * small writes - if we need to do large writes this will need to be | ||
433 | * revised. | ||
434 | */ | ||
435 | static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg, | ||
436 | int bytes, void *src) | ||
437 | { | ||
438 | struct i2c_client *i2c = wm8994->control_data; | ||
439 | unsigned char msg[bytes + 2]; | ||
440 | int ret; | ||
441 | |||
442 | reg = cpu_to_be16(reg); | ||
443 | memcpy(&msg[0], ®, 2); | ||
444 | memcpy(&msg[2], src, bytes); | ||
445 | |||
446 | ret = i2c_master_send(i2c, msg, bytes + 2); | ||
447 | if (ret < 0) | ||
448 | return ret; | ||
449 | if (ret < bytes + 2) | ||
450 | return -EIO; | ||
451 | |||
452 | return 0; | ||
453 | } | ||
454 | |||
455 | static int wm8994_i2c_probe(struct i2c_client *i2c, | ||
456 | const struct i2c_device_id *id) | ||
457 | { | ||
458 | struct wm8994 *wm8994; | ||
459 | |||
460 | wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); | ||
461 | if (wm8994 == NULL) { | ||
462 | kfree(i2c); | ||
463 | return -ENOMEM; | ||
464 | } | ||
465 | |||
466 | i2c_set_clientdata(i2c, wm8994); | ||
467 | wm8994->dev = &i2c->dev; | ||
468 | wm8994->control_data = i2c; | ||
469 | wm8994->read_dev = wm8994_i2c_read_device; | ||
470 | wm8994->write_dev = wm8994_i2c_write_device; | ||
471 | |||
472 | return wm8994_device_init(wm8994, id->driver_data, i2c->irq); | ||
473 | } | ||
474 | |||
475 | static int wm8994_i2c_remove(struct i2c_client *i2c) | ||
476 | { | ||
477 | struct wm8994 *wm8994 = i2c_get_clientdata(i2c); | ||
478 | |||
479 | wm8994_device_exit(wm8994); | ||
480 | |||
481 | return 0; | ||
482 | } | ||
483 | |||
484 | #ifdef CONFIG_PM | ||
485 | static int wm8994_i2c_suspend(struct i2c_client *i2c, pm_message_t state) | ||
486 | { | ||
487 | return wm8994_device_suspend(&i2c->dev); | ||
488 | } | ||
489 | |||
490 | static int wm8994_i2c_resume(struct i2c_client *i2c) | ||
491 | { | ||
492 | return wm8994_device_resume(&i2c->dev); | ||
493 | } | ||
494 | #else | ||
495 | #define wm8994_i2c_suspend NULL | ||
496 | #define wm8994_i2c_resume NULL | ||
497 | #endif | ||
498 | |||
499 | static const struct i2c_device_id wm8994_i2c_id[] = { | ||
500 | { "wm8994", 0 }, | ||
501 | { } | ||
502 | }; | ||
503 | MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id); | ||
504 | |||
505 | static struct i2c_driver wm8994_i2c_driver = { | ||
506 | .driver = { | ||
507 | .name = "wm8994", | ||
508 | .owner = THIS_MODULE, | ||
509 | }, | ||
510 | .probe = wm8994_i2c_probe, | ||
511 | .remove = wm8994_i2c_remove, | ||
512 | .suspend = wm8994_i2c_suspend, | ||
513 | .resume = wm8994_i2c_resume, | ||
514 | .id_table = wm8994_i2c_id, | ||
515 | }; | ||
516 | |||
517 | static int __init wm8994_i2c_init(void) | ||
518 | { | ||
519 | int ret; | ||
520 | |||
521 | ret = i2c_add_driver(&wm8994_i2c_driver); | ||
522 | if (ret != 0) | ||
523 | pr_err("Failed to register wm8994 I2C driver: %d\n", ret); | ||
524 | |||
525 | return ret; | ||
526 | } | ||
527 | module_init(wm8994_i2c_init); | ||
528 | |||
529 | static void __exit wm8994_i2c_exit(void) | ||
530 | { | ||
531 | i2c_del_driver(&wm8994_i2c_driver); | ||
532 | } | ||
533 | module_exit(wm8994_i2c_exit); | ||
534 | |||
535 | MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC"); | ||
536 | MODULE_LICENSE("GPL"); | ||
537 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||