diff options
author | Lee Jones <lee.jones@linaro.org> | 2012-05-19 11:21:37 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-05-20 11:27:10 -0400 |
commit | d28f1db8187dd1ddc1fa6f380ff0402cf8e4d44d (patch) | |
tree | e736cddf25b387da59b3a8d0a65c257f87e158c6 | |
parent | 1cb3642a68c983ada0f4090a4dac1d70a96126ca (diff) |
mfd: Remove confusing ab8500-i2c file and merge into ab8500-core
ab8500-i2c is used as core code to register the ab8500 device.
After allocating ab8500 memory, it immediately calls into
ab8500-core where the real initialisation takes place. This
patch moves all core registration and memory allocation into
the true ab8500-core file and removes ab8500-i2c completely.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r-- | arch/arm/mach-ux500/board-mop500.c | 2 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 5 | ||||
-rw-r--r-- | drivers/mfd/ab8500-core.c | 105 | ||||
-rw-r--r-- | drivers/mfd/ab8500-i2c.c | 160 |
4 files changed, 103 insertions, 169 deletions
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c index 77d03c1fbd04..6dd632d8a809 100644 --- a/arch/arm/mach-ux500/board-mop500.c +++ b/arch/arm/mach-ux500/board-mop500.c | |||
@@ -205,7 +205,7 @@ static struct resource ab8500_resources[] = { | |||
205 | }; | 205 | }; |
206 | 206 | ||
207 | struct platform_device ab8500_device = { | 207 | struct platform_device ab8500_device = { |
208 | .name = "ab8500-i2c", | 208 | .name = "ab8500-core", |
209 | .id = 0, | 209 | .id = 0, |
210 | .dev = { | 210 | .dev = { |
211 | .platform_data = &ab8500_platdata, | 211 | .platform_data = &ab8500_platdata, |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index d7138510c880..afe96b2e95e4 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -93,12 +93,11 @@ obj-$(CONFIG_AB3100_CORE) += ab3100-core.o | |||
93 | obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o | 93 | obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o |
94 | obj-$(CONFIG_AB5500_CORE) += ab5500-core.o | 94 | obj-$(CONFIG_AB5500_CORE) += ab5500-core.o |
95 | obj-$(CONFIG_AB5500_DEBUG) += ab5500-debugfs.o | 95 | obj-$(CONFIG_AB5500_DEBUG) += ab5500-debugfs.o |
96 | obj-$(CONFIG_AB8500_CORE) += ab8500-core.o ab8500-sysctrl.o | ||
97 | obj-$(CONFIG_AB8500_DEBUG) += ab8500-debugfs.o | 96 | obj-$(CONFIG_AB8500_DEBUG) += ab8500-debugfs.o |
98 | obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o | 97 | obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o |
99 | obj-$(CONFIG_MFD_DB8500_PRCMU) += db8500-prcmu.o | 98 | obj-$(CONFIG_MFD_DB8500_PRCMU) += db8500-prcmu.o |
100 | # ab8500-i2c need to come after db8500-prcmu (which provides the channel) | 99 | # ab8500-core need to come after db8500-prcmu (which provides the channel) |
101 | obj-$(CONFIG_AB8500_I2C_CORE) += ab8500-i2c.o | 100 | obj-$(CONFIG_AB8500_CORE) += ab8500-core.o ab8500-sysctrl.o |
102 | obj-$(CONFIG_MFD_DB5500_PRCMU) += db5500-prcmu.o | 101 | obj-$(CONFIG_MFD_DB5500_PRCMU) += db5500-prcmu.o |
103 | obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o | 102 | obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o |
104 | obj-$(CONFIG_PMIC_ADP5520) += adp5520.o | 103 | obj-$(CONFIG_PMIC_ADP5520) += adp5520.o |
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c index 6a59919fc331..fb807ab8a2c7 100644 --- a/drivers/mfd/ab8500-core.c +++ b/drivers/mfd/ab8500-core.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/mfd/core.h> | 18 | #include <linux/mfd/core.h> |
19 | #include <linux/mfd/abx500.h> | 19 | #include <linux/mfd/abx500.h> |
20 | #include <linux/mfd/abx500/ab8500.h> | 20 | #include <linux/mfd/abx500/ab8500.h> |
21 | #include <linux/mfd/dbx500-prcmu.h> | ||
21 | #include <linux/regulator/ab8500.h> | 22 | #include <linux/regulator/ab8500.h> |
22 | 23 | ||
23 | /* | 24 | /* |
@@ -137,6 +138,41 @@ static const char ab8500_version_str[][7] = { | |||
137 | [AB8500_VERSION_AB8540] = "AB8540", | 138 | [AB8500_VERSION_AB8540] = "AB8540", |
138 | }; | 139 | }; |
139 | 140 | ||
141 | static int ab8500_i2c_write(struct ab8500 *ab8500, u16 addr, u8 data) | ||
142 | { | ||
143 | int ret; | ||
144 | |||
145 | ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1); | ||
146 | if (ret < 0) | ||
147 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | static int ab8500_i2c_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask, | ||
152 | u8 data) | ||
153 | { | ||
154 | int ret; | ||
155 | |||
156 | ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data, | ||
157 | &mask, 1); | ||
158 | if (ret < 0) | ||
159 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); | ||
160 | return ret; | ||
161 | } | ||
162 | |||
163 | static int ab8500_i2c_read(struct ab8500 *ab8500, u16 addr) | ||
164 | { | ||
165 | int ret; | ||
166 | u8 data; | ||
167 | |||
168 | ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1); | ||
169 | if (ret < 0) { | ||
170 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); | ||
171 | return ret; | ||
172 | } | ||
173 | return (int)data; | ||
174 | } | ||
175 | |||
140 | static int ab8500_get_chip_id(struct device *dev) | 176 | static int ab8500_get_chip_id(struct device *dev) |
141 | { | 177 | { |
142 | struct ab8500 *ab8500; | 178 | struct ab8500 *ab8500; |
@@ -1169,27 +1205,51 @@ static struct attribute_group ab9540_attr_group = { | |||
1169 | .attrs = ab9540_sysfs_entries, | 1205 | .attrs = ab9540_sysfs_entries, |
1170 | }; | 1206 | }; |
1171 | 1207 | ||
1172 | int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version) | 1208 | static int __devinit ab8500_probe(struct platform_device *pdev) |
1173 | { | 1209 | { |
1174 | struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev); | 1210 | struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev); |
1211 | const struct platform_device_id *platid = platform_get_device_id(pdev); | ||
1212 | enum ab8500_version version = platid->driver_data; | ||
1213 | struct ab8500 *ab8500; | ||
1214 | struct resource *resource; | ||
1175 | int ret; | 1215 | int ret; |
1176 | int i; | 1216 | int i; |
1177 | u8 value; | 1217 | u8 value; |
1178 | 1218 | ||
1219 | ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL); | ||
1220 | if (!ab8500) | ||
1221 | return -ENOMEM; | ||
1222 | |||
1179 | if (plat) | 1223 | if (plat) |
1180 | ab8500->irq_base = plat->irq_base; | 1224 | ab8500->irq_base = plat->irq_base; |
1181 | 1225 | ||
1226 | ab8500->dev = &pdev->dev; | ||
1227 | |||
1228 | resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
1229 | if (!resource) { | ||
1230 | ret = -ENODEV; | ||
1231 | goto out_free_ab8500; | ||
1232 | } | ||
1233 | |||
1234 | ab8500->irq = resource->start; | ||
1235 | |||
1236 | ab8500->read = ab8500_i2c_read; | ||
1237 | ab8500->write = ab8500_i2c_write; | ||
1238 | ab8500->write_masked = ab8500_i2c_write_masked; | ||
1239 | |||
1182 | mutex_init(&ab8500->lock); | 1240 | mutex_init(&ab8500->lock); |
1183 | mutex_init(&ab8500->irq_lock); | 1241 | mutex_init(&ab8500->irq_lock); |
1184 | atomic_set(&ab8500->transfer_ongoing, 0); | 1242 | atomic_set(&ab8500->transfer_ongoing, 0); |
1185 | 1243 | ||
1244 | platform_set_drvdata(pdev, ab8500); | ||
1245 | |||
1186 | if (version != AB8500_VERSION_UNDEFINED) | 1246 | if (version != AB8500_VERSION_UNDEFINED) |
1187 | ab8500->version = version; | 1247 | ab8500->version = version; |
1188 | else { | 1248 | else { |
1189 | ret = get_register_interruptible(ab8500, AB8500_MISC, | 1249 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
1190 | AB8500_IC_NAME_REG, &value); | 1250 | AB8500_IC_NAME_REG, &value); |
1191 | if (ret < 0) | 1251 | if (ret < 0) |
1192 | return ret; | 1252 | goto out_free_ab8500; |
1193 | 1253 | ||
1194 | ab8500->version = value; | 1254 | ab8500->version = value; |
1195 | } | 1255 | } |
@@ -1197,7 +1257,7 @@ int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version) | |||
1197 | ret = get_register_interruptible(ab8500, AB8500_MISC, | 1257 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
1198 | AB8500_REV_REG, &value); | 1258 | AB8500_REV_REG, &value); |
1199 | if (ret < 0) | 1259 | if (ret < 0) |
1200 | return ret; | 1260 | goto out_free_ab8500; |
1201 | 1261 | ||
1202 | ab8500->chip_id = value; | 1262 | ab8500->chip_id = value; |
1203 | 1263 | ||
@@ -1342,12 +1402,16 @@ out_freeoldmask: | |||
1342 | kfree(ab8500->oldmask); | 1402 | kfree(ab8500->oldmask); |
1343 | out_freemask: | 1403 | out_freemask: |
1344 | kfree(ab8500->mask); | 1404 | kfree(ab8500->mask); |
1405 | out_free_ab8500: | ||
1406 | kfree(ab8500); | ||
1345 | 1407 | ||
1346 | return ret; | 1408 | return ret; |
1347 | } | 1409 | } |
1348 | 1410 | ||
1349 | int __devexit ab8500_exit(struct ab8500 *ab8500) | 1411 | static int __devexit ab8500_remove(struct platform_device *pdev) |
1350 | { | 1412 | { |
1413 | struct ab8500 *ab8500 = platform_get_drvdata(pdev); | ||
1414 | |||
1351 | if (is_ab9540(ab8500)) | 1415 | if (is_ab9540(ab8500)) |
1352 | sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); | 1416 | sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); |
1353 | else | 1417 | else |
@@ -1359,10 +1423,41 @@ int __devexit ab8500_exit(struct ab8500 *ab8500) | |||
1359 | } | 1423 | } |
1360 | kfree(ab8500->oldmask); | 1424 | kfree(ab8500->oldmask); |
1361 | kfree(ab8500->mask); | 1425 | kfree(ab8500->mask); |
1426 | kfree(ab8500); | ||
1362 | 1427 | ||
1363 | return 0; | 1428 | return 0; |
1364 | } | 1429 | } |
1365 | 1430 | ||
1431 | static const struct platform_device_id ab8500_id[] = { | ||
1432 | { "ab8500-core", AB8500_VERSION_AB8500 }, | ||
1433 | { "ab8505-i2c", AB8500_VERSION_AB8505 }, | ||
1434 | { "ab9540-i2c", AB8500_VERSION_AB9540 }, | ||
1435 | { "ab8540-i2c", AB8500_VERSION_AB8540 }, | ||
1436 | { } | ||
1437 | }; | ||
1438 | |||
1439 | static struct platform_driver ab8500_core_driver = { | ||
1440 | .driver = { | ||
1441 | .name = "ab8500-core", | ||
1442 | .owner = THIS_MODULE, | ||
1443 | }, | ||
1444 | .probe = ab8500_probe, | ||
1445 | .remove = __devexit_p(ab8500_remove), | ||
1446 | .id_table = ab8500_id, | ||
1447 | }; | ||
1448 | |||
1449 | static int __init ab8500_core_init(void) | ||
1450 | { | ||
1451 | return platform_driver_register(&ab8500_core_driver); | ||
1452 | } | ||
1453 | |||
1454 | static void __exit ab8500_core_exit(void) | ||
1455 | { | ||
1456 | platform_driver_unregister(&ab8500_core_driver); | ||
1457 | } | ||
1458 | arch_initcall(ab8500_core_init); | ||
1459 | module_exit(ab8500_core_exit); | ||
1460 | |||
1366 | MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent"); | 1461 | MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent"); |
1367 | MODULE_DESCRIPTION("AB8500 MFD core"); | 1462 | MODULE_DESCRIPTION("AB8500 MFD core"); |
1368 | MODULE_LICENSE("GPL v2"); | 1463 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/mfd/ab8500-i2c.c b/drivers/mfd/ab8500-i2c.c deleted file mode 100644 index 89b31a3409cd..000000000000 --- a/drivers/mfd/ab8500-i2c.c +++ /dev/null | |||
@@ -1,160 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2010 | ||
3 | * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson. | ||
4 | * License Terms: GNU General Public License v2 | ||
5 | * This file was based on drivers/mfd/ab8500-spi.c | ||
6 | */ | ||
7 | |||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/mfd/abx500/ab8500.h> | ||
14 | #include <linux/mfd/dbx500-prcmu.h> | ||
15 | |||
16 | static int ab8500_i2c_write(struct ab8500 *ab8500, u16 addr, u8 data) | ||
17 | { | ||
18 | int ret; | ||
19 | |||
20 | ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1); | ||
21 | if (ret < 0) | ||
22 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); | ||
23 | return ret; | ||
24 | } | ||
25 | |||
26 | static int ab8500_i2c_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask, | ||
27 | u8 data) | ||
28 | { | ||
29 | int ret; | ||
30 | |||
31 | ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data, | ||
32 | &mask, 1); | ||
33 | if (ret < 0) | ||
34 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); | ||
35 | return ret; | ||
36 | } | ||
37 | |||
38 | static int ab8500_i2c_read(struct ab8500 *ab8500, u16 addr) | ||
39 | { | ||
40 | int ret; | ||
41 | u8 data; | ||
42 | |||
43 | ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1); | ||
44 | if (ret < 0) { | ||
45 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); | ||
46 | return ret; | ||
47 | } | ||
48 | return (int)data; | ||
49 | } | ||
50 | |||
51 | static int __devinit ab8500_i2c_probe(struct platform_device *plf) | ||
52 | { | ||
53 | const struct platform_device_id *platid = platform_get_device_id(plf); | ||
54 | struct ab8500 *ab8500; | ||
55 | struct resource *resource; | ||
56 | int ret; | ||
57 | |||
58 | ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL); | ||
59 | if (!ab8500) | ||
60 | return -ENOMEM; | ||
61 | |||
62 | ab8500->dev = &plf->dev; | ||
63 | |||
64 | resource = platform_get_resource(plf, IORESOURCE_IRQ, 0); | ||
65 | if (!resource) { | ||
66 | kfree(ab8500); | ||
67 | return -ENODEV; | ||
68 | } | ||
69 | |||
70 | ab8500->irq = resource->start; | ||
71 | |||
72 | ab8500->read = ab8500_i2c_read; | ||
73 | ab8500->write = ab8500_i2c_write; | ||
74 | ab8500->write_masked = ab8500_i2c_write_masked; | ||
75 | |||
76 | platform_set_drvdata(plf, ab8500); | ||
77 | |||
78 | ret = ab8500_init(ab8500, platid->driver_data); | ||
79 | if (ret) | ||
80 | kfree(ab8500); | ||
81 | |||
82 | |||
83 | return ret; | ||
84 | } | ||
85 | |||
86 | static int __devexit ab8500_i2c_remove(struct platform_device *plf) | ||
87 | { | ||
88 | struct ab8500 *ab8500 = platform_get_drvdata(plf); | ||
89 | |||
90 | ab8500_exit(ab8500); | ||
91 | kfree(ab8500); | ||
92 | |||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | static const struct platform_device_id ab8500_id[] = { | ||
97 | { "ab8500-i2c", AB8500_VERSION_AB8500 }, | ||
98 | { "ab8505-i2c", AB8500_VERSION_AB8505 }, | ||
99 | { "ab9540-i2c", AB8500_VERSION_AB9540 }, | ||
100 | { "ab8540-i2c", AB8500_VERSION_AB8540 }, | ||
101 | { } | ||
102 | }; | ||
103 | |||
104 | #ifdef CONFIG_PM | ||
105 | static int ab8500_i2c_suspend(struct device *dev) | ||
106 | { | ||
107 | struct ab8500 *ab = dev_get_drvdata(dev); | ||
108 | |||
109 | disable_irq(ab->irq); | ||
110 | enable_irq_wake(ab->irq); | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int ab8500_i2c_resume(struct device *dev) | ||
116 | { | ||
117 | struct ab8500 *ab = dev_get_drvdata(dev); | ||
118 | |||
119 | disable_irq_wake(ab->irq); | ||
120 | enable_irq(ab->irq); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static const struct dev_pm_ops ab8500_i2c_pm_ops = { | ||
126 | .suspend = ab8500_i2c_suspend, | ||
127 | .resume = ab8500_i2c_resume, | ||
128 | }; | ||
129 | |||
130 | #define AB8500_I2C_PM_OPS (&ab8500_i2c_pm_ops) | ||
131 | #else | ||
132 | #define AB8500_I2C_PM_OPS NULL | ||
133 | #endif | ||
134 | |||
135 | static struct platform_driver ab8500_i2c_driver = { | ||
136 | .driver = { | ||
137 | .name = "ab8500-i2c", | ||
138 | .owner = THIS_MODULE, | ||
139 | .pm = AB8500_I2C_PM_OPS, | ||
140 | }, | ||
141 | .probe = ab8500_i2c_probe, | ||
142 | .remove = __devexit_p(ab8500_i2c_remove), | ||
143 | .id_table = ab8500_id, | ||
144 | }; | ||
145 | |||
146 | static int __init ab8500_i2c_init(void) | ||
147 | { | ||
148 | return platform_driver_register(&ab8500_i2c_driver); | ||
149 | } | ||
150 | |||
151 | static void __exit ab8500_i2c_exit(void) | ||
152 | { | ||
153 | platform_driver_unregister(&ab8500_i2c_driver); | ||
154 | } | ||
155 | arch_initcall(ab8500_i2c_init); | ||
156 | module_exit(ab8500_i2c_exit); | ||
157 | |||
158 | MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com"); | ||
159 | MODULE_DESCRIPTION("AB8500 Core access via PRCMU I2C"); | ||
160 | MODULE_LICENSE("GPL v2"); | ||